FabioFratini 8 месяцев назад
Родитель
Сommit
2a464d7d05
1 измененных файлов с 36 добавлено и 2 удалено
  1. 36 2
      app/Http/Livewire/RecordOUT.php

+ 36 - 2
app/Http/Livewire/RecordOUT.php

@@ -376,6 +376,13 @@ class RecordOUT extends Component
         // Option 1: Use current date and time as the invoice number
         $invoiceNumber = 'USC-' . date('YmdHis');
 
+        if (empty($this->data_pagamento) || $this->data_pagamento == '1970-01-01') {
+            $this->data_pagamento = null;
+            Log::info("Setting data_pagamento to NULL in store");
+        } else {
+            Log::info("Using data_pagamento: " . $this->data_pagamento);
+        }
+
         $this->validate();
         try {
             $record = \App\Models\Record::create([
@@ -384,7 +391,7 @@ class RecordOUT extends Component
                 //'causal_id' => $this->causal_id,
                 'payment_method_id' => $this->payment_method_id,
                 'date' => $this->date,
-                'data_pagamento' => date("Y-m-d", strtotime($this->data_pagamento)),
+                'data_pagamento' =>$this->data_pagamento,
                 //'month' => $this->month,
                 //'year' => $this->year,
                 //'note' => $this->note,
@@ -430,6 +437,26 @@ class RecordOUT extends Component
         }
     }
 
+    public function setDataPagamentoAttribute($value)
+    {
+        // Convert empty values to NULL
+        if (empty($value) || $value == '1970-01-01' || $value == '0000-00-00') {
+            $this->attributes['data_pagamento'] = null;
+        } else {
+            $this->attributes['data_pagamento'] = $value;
+        }
+    }
+
+    // Optional: Also add an accessor to prevent returning 1970-01-01
+    public function getDataPagamentoAttribute($value)
+    {
+        // Return null instead of Unix epoch date
+        if ($value == '1970-01-01' || $value == '0000-00-00') {
+            return null;
+        }
+        return $value;
+    }
+
     public function edit($id)
     {
         if (!isset($_GET["from"]) && $this->fromPage == '')
@@ -448,7 +475,7 @@ class RecordOUT extends Component
                 //$this->causal_id = $record->causal_id;
                 $this->payment_method_id = $record->payment_method_id;
                 $this->date = date("Y-m-d", strtotime($record->date));
-                $this->data_pagamento = date("Y-m-d", strtotime($record->data_pagamento));
+                $this->data_pagamento =  $record->data_pagamento;
                 //$this->month = $record->month;
                 //$this->year = $record->year;
                 //$this->note = $record->note;
@@ -496,6 +523,13 @@ class RecordOUT extends Component
         $this->emit('refresh');
         $this->validate();
 
+        if (empty($this->data_pagamento) || $this->data_pagamento == '') {
+            $this->data_pagamento = null;
+            Log::info("Data pagamento vuota, imposto a NULL in update");
+        } else {
+            Log::info("Data pagamento in update: " . $this->data_pagamento);
+        }
+
         try {
             \App\Models\Record::whereId($this->dataId)->update([
                 'member_id' => $this->member_id,