From a9749c92fe51af528fcfe3c5b5af02e280c8f639 Mon Sep 17 00:00:00 2001 From: paoloar77 Date: Fri, 26 Jul 2024 15:55:19 +0200 Subject: [PATCH] cliente nuovo, passagli l'ID --- app/CustomFuncPao.php | 90 ++++++++++++++++++++----------------------- routes/web.php | 16 ++++++-- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/app/CustomFuncPao.php b/app/CustomFuncPao.php index c9bf7cfb..135226c7 100644 --- a/app/CustomFuncPao.php +++ b/app/CustomFuncPao.php @@ -513,6 +513,7 @@ function showOrdini() if ($order->Descrizione) $str .= getvalstr("Descr", $order->Descrizione); + $str .= ' IMPOSTA IDSITO FDV' . $sep; $str .= ' ELIMINA!' . $sep; // $str .= getarraystr($product) . "
"; @@ -565,6 +566,7 @@ function showOrdiniWeb() $str .= getvalstr("Descr", $order->Descrizione); // $str .= ' ELIMINA!' . $sep; + $str .= ' IMPOSTA IDSITO FDV' . $sep; // $str .= getarraystr($product) . "
"; // $str .= $product; @@ -670,6 +672,17 @@ function setOrdine($idinternet, $mode) $deletedCount = Orderdetail::where('IdInternet', $idinternet)->delete(); $str .= "
Numero di record eliminati: " . $deletedCount . ""; } + if ($mode === 'idsito' && $ordine) { + $str .= "... CAMBIA ID SITO ..."; + + // Update field IdSito to "7" + $updatedCount = Orderdetail::where('IdInternet', $idinternet) + ->update([ + 'IdSito' => "7" + ]); + + $str .= "
record Aggiornati: " . $updatedCount . ""; + } } } catch (\Exception $e) { $str .= "Errore: " . $e->getMessage(); @@ -678,6 +691,30 @@ function setOrdine($idinternet, $mode) return $str; } +function showRecordOrder($orders) +{ + + try { + $str = ''; + + // Show the fields of the orders + foreach ($orders as $order) { + $str .= getvalstr("IdInternet", $order->IdInternet, true) . " "; + $str .= getvalstr("CodCliente", $order->CodClienteInternet, true); + $str .= getvalstr("IdSito", $order->IdSito, true); + $str .= getvalstr("Note", $order->Note, true); + $str .= getvalstr("Totale", $order->Totale, true); + $str .= getvalstr("DataOra", $order->DataOra, true); + $str .= getvalstr("DataSpedizione", $order->DataSpedizione, true); + $str .= '
'; + } + } catch (\Exception $e) { + return "Errore showDettOrdini: " . $e->getMessage(); + } + + return $str; +} + function showDettOrdini() { @@ -687,18 +724,7 @@ function showDettOrdini() // sort DataOra desc $orders = AppOrder::all()->sortByDesc('DataOra'); - // Show the fields of the orders - foreach ($orders as $order) { - $str .= getvalstr("IdInternet", $order->IdInternet, true) . " "; - $str .= getvalstr("CodCliente", $order->CodClienteInternet, true); - $str .= getvalstr("IdSito", $order->IdSito, true); - $str .= getvalstr("Note", $order->Note, true); - $str .= getvalstr("Totale", $order->Totale, true); - $str .= getvalstr("DataOra", $order->DataOra, true); - $str .= getvalstr("DataSpedizione", $order->DataSpedizione, true); - $str .= '
'; - } - + $str .= showRecordOrder($orders); } catch (\Exception $e) { return "Errore showDettOrdini: " . $e->getMessage(); } @@ -714,18 +740,7 @@ function showDettSingleOrdine($idordine) // sort DataOra desc $orders = AppOrder::where('IdInternet', $idordine)->get(); - // Show the fields of the orders - foreach ($orders as $order) { - $str .= getvalstr("IdInternet", $order->IdInternet, true) . " "; - $str .= getvalstr("CodCliente", $order->CodClienteInternet, true); - $str .= getvalstr("IdSito", $order->IdSito, true); - $str .= getvalstr("Note", $order->Note, true); - $str .= getvalstr("Totale", $order->Totale, true); - $str .= getvalstr("DataOra", $order->DataOra, true); - $str .= getvalstr("DataSpedizione", $order->DataSpedizione, true); - $str .= '
'; - } - + $str .= showRecordOrder($orders); } catch (\Exception $e) { return "Errore showDettOrdini: " . $e->getMessage(); } @@ -741,18 +756,7 @@ function showDettOrdiniWeb() $orders = AppOrderWeb::all()->sortByDesc('DataOra'); - // Show the fields of the orders - foreach ($orders as $order) { - $str .= "Ordine: "; - $str .= getvalstr("IdInternet", $order->IdInternet, true) . " "; - $str .= getvalstr("CodCliente", $order->CodClienteInternet, true); - $str .= getvalstr("IdSito", $order->IdSito, true); - $str .= getvalstr("Note", $order->Note, true); - $str .= getvalstr("Totale", $order->Totale, true); - $str .= getvalstr("DataOra", $order->DataOra, true); - $str .= getvalstr("DataSpedizione", $order->DataSpedizione, true); - $str .= '
'; - } + $str .= showRecordOrder($orders); } catch (\Exception $e) { return "Errore showDettOrdini: " . $e->getMessage(); } @@ -768,18 +772,8 @@ function showDettSingleOrdineWeb($idordine) $orders = AppOrderWeb::where('IdInternet', $idordine)->get(); - // Show the fields of the orders - foreach ($orders as $order) { - $str .= "Ordine: "; - $str .= getvalstr("IdInternet", $order->IdInternet, true) . " "; - $str .= getvalstr("CodCliente", $order->CodClienteInternet, true); - $str .= getvalstr("IdSito", $order->IdSito, true); - $str .= getvalstr("Note", $order->Note, true); - $str .= getvalstr("Totale", $order->Totale, true); - $str .= getvalstr("DataOra", $order->DataOra, true); - $str .= getvalstr("DataSpedizione", $order->DataSpedizione, true); - $str .= '
'; - } + $str .= showRecordOrder($orders); + } catch (\Exception $e) { return "Errore showDettOrdini: " . $e->getMessage(); } diff --git a/routes/web.php b/routes/web.php index 9f8d52e0..2cb07f42 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2222,8 +2222,6 @@ Route::post('/updatecreate', function (Request $request) { if ($changedest) { $order->CodDestInternet = $CodClienteInternet; } - $order->save(); - $productLogger->addLog('', 'Order:' . json_encode($order)); $prodotti = $request->line_items; @@ -2286,7 +2284,9 @@ Route::post('/updatecreate', function (Request $request) { $cliente = new Clientegm(); } - $cliente->CodClienteInternet = $CodClienteInternet; + if ($CodClienteInternet > 0) { + $cliente->CodClienteInternet = $CodClienteInternet; + } $cliente->Nominativo = $nome . " " . $cognome; $cliente->Indirizzo = $indirizzo1 . ($indirizzo2 ? (' ' . $indirizzo2) : ''); $cliente->Citta = $citta; @@ -2325,6 +2325,16 @@ Route::post('/updatecreate', function (Request $request) { $productLogger->addLog('', 'Errore nella fase di salvataggio: ' . $th->getMessage()); } + // Se il Cliente era nuovo, allora estrai l'ID del Cliente appena salvato e passalo all'Ordine + if ($CodClienteInternet <= 0) { + $CodClienteInternet = $cliente->CodClienteInternet; + $order->CodClienteInternet = $CodClienteInternet; + } + + // SALVA L'ORDINE: + $order->save(); + $productLogger->addLog('', 'Order:' . json_encode($order)); + if ($changedest) { $productLogger->addLog('', 'Change Destinazione:'); $clientedest = new Clientegmdest();