|
@@ -392,20 +392,18 @@ class RecordOUT extends Component
|
|
|
$this->validate();
|
|
$this->validate();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // DEBUG: Check if we have an attachment
|
|
|
|
|
- Log::info("STORE DEBUG - Has attachment?: " . ($this->attachment ? 'YES' : 'NO'));
|
|
|
|
|
|
|
+
|
|
|
if ($this->attachment) {
|
|
if ($this->attachment) {
|
|
|
Log::info("STORE DEBUG - Attachment original name: " . $this->attachment->getClientOriginalName());
|
|
Log::info("STORE DEBUG - Attachment original name: " . $this->attachment->getClientOriginalName());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Create the record first WITHOUT attachment
|
|
|
|
|
$record = \App\Models\Record::create([
|
|
$record = \App\Models\Record::create([
|
|
|
'member_id' => $this->member_id,
|
|
'member_id' => $this->member_id,
|
|
|
'supplier_id' => $this->supplier_id,
|
|
'supplier_id' => $this->supplier_id,
|
|
|
'payment_method_id' => $this->payment_method_id,
|
|
'payment_method_id' => $this->payment_method_id,
|
|
|
'date' => $this->date,
|
|
'date' => $this->date,
|
|
|
'data_pagamento' => $this->data_pagamento,
|
|
'data_pagamento' => $this->data_pagamento,
|
|
|
- 'attachment' => '', // Empty initially
|
|
|
|
|
|
|
+ 'attachment' => '',
|
|
|
'type' => $this->type,
|
|
'type' => $this->type,
|
|
|
'amount' => $this->currencyToDouble($this->amount),
|
|
'amount' => $this->currencyToDouble($this->amount),
|
|
|
'commercial' => $this->commercial,
|
|
'commercial' => $this->commercial,
|
|
@@ -413,46 +411,30 @@ class RecordOUT extends Component
|
|
|
'is_paid' => $is_paid,
|
|
'is_paid' => $is_paid,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- Log::info("STORE DEBUG - Record created with ID: " . $record->id);
|
|
|
|
|
$this->dataId = $record->id;
|
|
$this->dataId = $record->id;
|
|
|
|
|
|
|
|
- // Create record folders after record is created
|
|
|
|
|
$this->recordFileService->createRecordFolders($record->id, 'OUT');
|
|
$this->recordFileService->createRecordFolders($record->id, 'OUT');
|
|
|
- Log::info("STORE DEBUG - Folders created for record ID: " . $record->id);
|
|
|
|
|
|
|
|
|
|
- // Now handle attachment upload if exists
|
|
|
|
|
if ($this->attachment) {
|
|
if ($this->attachment) {
|
|
|
try {
|
|
try {
|
|
|
- Log::info("STORE DEBUG - Starting attachment upload...");
|
|
|
|
|
$attachmentPath = $this->recordFileService->uploadAttachment($this->attachment, $record->id, 'OUT');
|
|
$attachmentPath = $this->recordFileService->uploadAttachment($this->attachment, $record->id, 'OUT');
|
|
|
- Log::info("STORE DEBUG - Attachment uploaded to path: " . $attachmentPath);
|
|
|
|
|
|
|
|
|
|
- // Use DB query builder instead of model update to ensure it works
|
|
|
|
|
$updateResult = \DB::table('records')
|
|
$updateResult = \DB::table('records')
|
|
|
->where('id', $record->id)
|
|
->where('id', $record->id)
|
|
|
->update(['attachment' => $attachmentPath]);
|
|
->update(['attachment' => $attachmentPath]);
|
|
|
|
|
|
|
|
- Log::info("STORE DEBUG - DB update result: " . ($updateResult ? 'SUCCESS' : 'FAILED'));
|
|
|
|
|
|
|
|
|
|
- // Verify the update worked by fetching fresh from database
|
|
|
|
|
$updatedRecord = \App\Models\Record::where('id', $record->id)->first();
|
|
$updatedRecord = \App\Models\Record::where('id', $record->id)->first();
|
|
|
- Log::info("STORE DEBUG - Verified attachment in DB: '" . $updatedRecord->attachment . "'");
|
|
|
|
|
|
|
|
|
|
- // Also refresh the model instance
|
|
|
|
|
$record->refresh();
|
|
$record->refresh();
|
|
|
- Log::info("STORE DEBUG - Model after refresh: '" . $record->attachment . "'");
|
|
|
|
|
|
|
|
|
|
- Log::info("Attachment uploaded and record updated: " . $attachmentPath);
|
|
|
|
|
} catch (\Exception $ex) {
|
|
} catch (\Exception $ex) {
|
|
|
- Log::error("STORE ERROR - Error uploading attachment: " . $ex->getMessage());
|
|
|
|
|
- Log::error("STORE ERROR - Exception trace: " . $ex->getTraceAsString());
|
|
|
|
|
session()->flash('warning', 'Record created but attachment upload failed: ' . $ex->getMessage());
|
|
session()->flash('warning', 'Record created but attachment upload failed: ' . $ex->getMessage());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
Log::info("STORE DEBUG - No attachment to upload");
|
|
Log::info("STORE DEBUG - No attachment to upload");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Create record rows
|
|
|
|
|
$tot = 0;
|
|
$tot = 0;
|
|
|
foreach ($this->rows as $row) {
|
|
foreach ($this->rows as $row) {
|
|
|
foreach ($row["when"] as $x => $y) {
|
|
foreach ($row["when"] as $x => $y) {
|
|
@@ -474,7 +456,6 @@ class RecordOUT extends Component
|
|
|
$tot += $this->currencyToDouble($row["amount"]);
|
|
$tot += $this->currencyToDouble($row["amount"]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Update final amount
|
|
|
|
|
$record->amount = $tot;
|
|
$record->amount = $tot;
|
|
|
$record->save();
|
|
$record->save();
|
|
|
|
|
|
|
@@ -519,12 +500,6 @@ class RecordOUT extends Component
|
|
|
if (!$record) {
|
|
if (!$record) {
|
|
|
$this->emit('flash-error', 'Movimento non trovato');
|
|
$this->emit('flash-error', 'Movimento non trovato');
|
|
|
} else {
|
|
} else {
|
|
|
- // DEBUG: Let's see what's in the database
|
|
|
|
|
- Log::info("EDIT DEBUG - Record ID: {$record->id}");
|
|
|
|
|
- Log::info("EDIT DEBUG - Database attachment value: '" . $record->attachment . "'");
|
|
|
|
|
- Log::info("EDIT DEBUG - Database attachment type: " . gettype($record->attachment));
|
|
|
|
|
- Log::info("EDIT DEBUG - Is attachment empty?: " . (empty($record->attachment) ? 'YES' : 'NO'));
|
|
|
|
|
- Log::info("EDIT DEBUG - Is attachment null?: " . (is_null($record->attachment) ? 'YES' : 'NO'));
|
|
|
|
|
|
|
|
|
|
$this->member_id = $record->member_id;
|
|
$this->member_id = $record->member_id;
|
|
|
$this->supplier_id = $record->supplier_id;
|
|
$this->supplier_id = $record->supplier_id;
|
|
@@ -534,16 +509,13 @@ class RecordOUT extends Component
|
|
|
$this->type = $record->type;
|
|
$this->type = $record->type;
|
|
|
$this->numero_fattura = $record->numero_fattura;
|
|
$this->numero_fattura = $record->numero_fattura;
|
|
|
|
|
|
|
|
- // Set attachment_old - handle different cases
|
|
|
|
|
if (!empty($record->attachment) && $record->attachment !== null && $record->attachment !== '') {
|
|
if (!empty($record->attachment) && $record->attachment !== null && $record->attachment !== '') {
|
|
|
$this->attachment_old = $record->attachment;
|
|
$this->attachment_old = $record->attachment;
|
|
|
- Log::info("EDIT DEBUG - Setting attachment_old to: '" . $this->attachment_old . "'");
|
|
|
|
|
} else {
|
|
} else {
|
|
|
$this->attachment_old = '';
|
|
$this->attachment_old = '';
|
|
|
- Log::info("EDIT DEBUG - Setting attachment_old to empty string");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $this->attachment = null; // Clear any temporary attachment
|
|
|
|
|
|
|
+ $this->attachment = null;
|
|
|
|
|
|
|
|
$this->commercial = $record->commercial;
|
|
$this->commercial = $record->commercial;
|
|
|
$this->dataId = $record->id;
|
|
$this->dataId = $record->id;
|
|
@@ -600,10 +572,8 @@ class RecordOUT extends Component
|
|
|
$this->rows[] = $rowData;
|
|
$this->rows[] = $rowData;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Final debug log
|
|
|
|
|
Log::info("EDIT DEBUG - Final attachment_old value: '" . $this->attachment_old . "'");
|
|
Log::info("EDIT DEBUG - Final attachment_old value: '" . $this->attachment_old . "'");
|
|
|
|
|
|
|
|
- // Force Livewire to re-render
|
|
|
|
|
$this->emit('refresh');
|
|
$this->emit('refresh');
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $ex) {
|
|
} catch (\Exception $ex) {
|
|
@@ -941,16 +911,10 @@ class RecordOUT extends Component
|
|
|
Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$supplier->name}");
|
|
Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$supplier->name}");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ← NOW $record exists! Create folder structure for the record
|
|
|
|
|
$this->recordFileService->createRecordFolders($record->id, 'OUT');
|
|
$this->recordFileService->createRecordFolders($record->id, 'OUT');
|
|
|
|
|
|
|
|
- // ← Store the XML file as an attachment to the record
|
|
|
|
|
try {
|
|
try {
|
|
|
$xmlAttachmentPath = $this->recordFileService->uploadXmlReceipt($receiptFile, $record->id, 'OUT');
|
|
$xmlAttachmentPath = $this->recordFileService->uploadXmlReceipt($receiptFile, $record->id, 'OUT');
|
|
|
-
|
|
|
|
|
- // ← Update the record with the XML attachment path (if you have a field for it)
|
|
|
|
|
- // If you want to store XML separately from regular attachments, you could add a xml_attachment field
|
|
|
|
|
- // Or if you want to overwrite the attachment field:
|
|
|
|
|
$record->update(['attachment' => $xmlAttachmentPath]);
|
|
$record->update(['attachment' => $xmlAttachmentPath]);
|
|
|
|
|
|
|
|
Log::info("XML receipt stored as attachment: " . $xmlAttachmentPath);
|
|
Log::info("XML receipt stored as attachment: " . $xmlAttachmentPath);
|