diff --git a/app/Clientegm.php b/app/Clientegm.php index 907e1b5e..5685f337 100644 --- a/app/Clientegm.php +++ b/app/Clientegm.php @@ -6,8 +6,9 @@ use Illuminate\Database\Eloquent\Model; class Clientegm extends Model { - protected $primaryKey = null; - public $incrementing = false; + protected $primaryKey = 'CodClienteInternet'; // Imposta la chiave primaria corretta + public $incrementing = true; // Indica che รจ auto-incrementante + //protected $connection = 'mysql_test'; protected $connection = 'sqlsrv_test'; protected $table = 'T_WOO_Clienti'; diff --git a/routes/web.php b/routes/web.php index 452ce6bd..7a8ab84d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2325,12 +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 || $CodClienteInternet <= 0 || $CodClienteInternet === null) { - if ($cliente->CodClienteInternet) { - $CodClienteInternet = $cliente->CodClienteInternet; - $order->CodClienteInternet = $CodClienteInternet; + try { + // Se il Cliente era nuovo, allora estrai l'ID del Cliente appena salvato e passalo all'Ordine + if (!$CodClienteInternet || $CodClienteInternet <= 0 || $CodClienteInternet === null) { + if ($cliente->CodClienteInternet) { + $CodClienteInternet = $cliente->CodClienteInternet; + $order->CodClienteInternet = $CodClienteInternet; + } } + } catch (\Throwable $th) { + $productLogger->addLog('', 'Errore CodClienteInternet : ' . $th->getMessage()); } // SALVA L'ORDINE: