|
@@ -45,6 +45,7 @@ class RecordOUT extends Component
|
|
|
$causal_id,
|
|
$causal_id,
|
|
|
$payment_method_id,
|
|
$payment_method_id,
|
|
|
$date,
|
|
$date,
|
|
|
|
|
+ $data_pagamento,
|
|
|
$month,
|
|
$month,
|
|
|
$year,
|
|
$year,
|
|
|
$type,
|
|
$type,
|
|
@@ -116,6 +117,8 @@ class RecordOUT extends Component
|
|
|
//$this->causal_id = null;
|
|
//$this->causal_id = null;
|
|
|
$this->payment_method_id = null;
|
|
$this->payment_method_id = null;
|
|
|
$this->date = date("Y-m-d");
|
|
$this->date = date("Y-m-d");
|
|
|
|
|
+ $this->data_pagamento = date("Y-m-d");
|
|
|
|
|
+
|
|
|
//$this->month = date("n");
|
|
//$this->month = date("n");
|
|
|
//$this->year = date("Y");
|
|
//$this->year = date("Y");
|
|
|
$this->type = 'OUT';
|
|
$this->type = 'OUT';
|
|
@@ -345,6 +348,7 @@ class RecordOUT extends Component
|
|
|
//'causal_id' => $this->causal_id,
|
|
//'causal_id' => $this->causal_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,
|
|
|
//'month' => $this->month,
|
|
//'month' => $this->month,
|
|
|
//'year' => $this->year,
|
|
//'year' => $this->year,
|
|
|
//'note' => $this->note,
|
|
//'note' => $this->note,
|
|
@@ -399,6 +403,7 @@ class RecordOUT extends Component
|
|
|
//$this->causal_id = $record->causal_id;
|
|
//$this->causal_id = $record->causal_id;
|
|
|
$this->payment_method_id = $record->payment_method_id;
|
|
$this->payment_method_id = $record->payment_method_id;
|
|
|
$this->date = date("Y-m-d", strtotime($record->date));
|
|
$this->date = date("Y-m-d", strtotime($record->date));
|
|
|
|
|
+ $this->data_pagamento = date("Y-m-d", strtotime($record->data_pagamento));
|
|
|
//$this->month = $record->month;
|
|
//$this->month = $record->month;
|
|
|
//$this->year = $record->year;
|
|
//$this->year = $record->year;
|
|
|
//$this->note = $record->note;
|
|
//$this->note = $record->note;
|
|
@@ -431,6 +436,7 @@ class RecordOUT extends Component
|
|
|
//'causal_id' => $this->causal_id,
|
|
//'causal_id' => $this->causal_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,
|
|
|
//'month' => $this->month,
|
|
//'month' => $this->month,
|
|
|
//'year' => $this->year,
|
|
//'year' => $this->year,
|
|
|
//'note' => $this->note,
|
|
//'note' => $this->note,
|
|
@@ -676,10 +682,10 @@ class RecordOUT extends Component
|
|
|
$this->createRecordRow($record->id, $fatturaData);
|
|
$this->createRecordRow($record->id, $fatturaData);
|
|
|
|
|
|
|
|
// Crea la ricevuta
|
|
// Crea la ricevuta
|
|
|
- $receipt = $this->createReceipt($record->id, $supplier->id, $paymentMethodId, $fatturaData);
|
|
|
|
|
|
|
+ //$receipt = $this->createReceipt($record->id, $supplier->id, $paymentMethodId, $fatturaData);
|
|
|
|
|
|
|
|
// Crea le righe della ricevuta
|
|
// Crea le righe della ricevuta
|
|
|
- $this->createReceiptRows($receipt->id, $fatturaData);
|
|
|
|
|
|
|
+ // $this->createReceiptRows($receipt->id, $fatturaData);
|
|
|
|
|
|
|
|
$importCount++;
|
|
$importCount++;
|
|
|
Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$fatturaData['denominazione']}");
|
|
Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$fatturaData['denominazione']}");
|
|
@@ -915,12 +921,29 @@ class RecordOUT extends Component
|
|
|
$record->supplier_id = $supplierId;
|
|
$record->supplier_id = $supplierId;
|
|
|
$record->payment_method_id = $paymentMethodId;
|
|
$record->payment_method_id = $paymentMethodId;
|
|
|
$record->date = $fatturaData['dataDocumento'];
|
|
$record->date = $fatturaData['dataDocumento'];
|
|
|
|
|
+ $record->data_pagamento = $fatturaData['dataDocumento'];
|
|
|
|
|
+ $record->numero_fattura = $fatturaData['numeroFattura'];
|
|
|
$record->type = 'OUT';
|
|
$record->type = 'OUT';
|
|
|
$record->commercial = 1;
|
|
$record->commercial = 1;
|
|
|
$record->corrispettivo_fiscale = 0;
|
|
$record->corrispettivo_fiscale = 0;
|
|
|
$record->deleted = 0;
|
|
$record->deleted = 0;
|
|
|
$record->financial_movement = 1;
|
|
$record->financial_movement = 1;
|
|
|
$record->amount = $fatturaData['importoTotale'];
|
|
$record->amount = $fatturaData['importoTotale'];
|
|
|
|
|
+ $record->tipo_documento = $this->mapTipoDocumento($fatturaData['tipoDocumento']);
|
|
|
|
|
+
|
|
|
|
|
+ $record->is_ricevuta = true;
|
|
|
|
|
+ if (isset($fatturaData['condizioniPagamento']) && !empty($fatturaData['condizioniPagamento'])) {
|
|
|
|
|
+ $record->condizioni_pagamento = $this->mapCondizioniPagamento($fatturaData['condizioniPagamento']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($fatturaData['iban']) && !empty($fatturaData['iban'])) {
|
|
|
|
|
+ $record->IBAN = $fatturaData['iban'];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($fatturaData['bic']) && !empty($fatturaData['bic'])) {
|
|
|
|
|
+ $record->BIC = $fatturaData['bic'];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($fatturaData['dataScadenza']) && !empty($fatturaData['dataScadenza'])) {
|
|
|
|
|
+ $record->data_scadenza = $fatturaData['dataScadenza'];
|
|
|
|
|
+ }
|
|
|
$record->save();
|
|
$record->save();
|
|
|
|
|
|
|
|
Log::info("Record creato con ID: " . $record->id);
|
|
Log::info("Record creato con ID: " . $record->id);
|
|
@@ -935,10 +958,26 @@ class RecordOUT extends Component
|
|
|
{
|
|
{
|
|
|
Log::info("Inizio creazione RecordRow per Record ID: " . $recordId);
|
|
Log::info("Inizio creazione RecordRow per Record ID: " . $recordId);
|
|
|
|
|
|
|
|
|
|
+ if (!empty($fatturaData['linee'])) {
|
|
|
|
|
+ foreach ($fatturaData['linee'] as $linea) {
|
|
|
|
|
+ $this->createSingleRecordRow($recordId, $fatturaData, $linea);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ($fatturaData['riepilogo']) {
|
|
|
|
|
+ $this->createRecordRowFromRiepilogo($recordId, $fatturaData);
|
|
|
|
|
+ Log::info("Creata una riga di record dai dati di riepilogo");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->createDefaultRecordRow($recordId, $fatturaData);
|
|
|
|
|
+ Log::info("Creata una riga di record predefinita dall'importo totale");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function createSingleRecordRow($recordId, $fatturaData, $linea)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info("Inizio creazione riga record singola per Record ID: " . $recordId . ", Linea: " . json_encode($linea));
|
|
|
|
|
+
|
|
|
$dataObj = new \DateTime($fatturaData['dataDocumento']);
|
|
$dataObj = new \DateTime($fatturaData['dataDocumento']);
|
|
|
$month = $dataObj->format('n');
|
|
$month = $dataObj->format('n');
|
|
|
$year = $dataObj->format('Y');
|
|
$year = $dataObj->format('Y');
|
|
|
-
|
|
|
|
|
$period = "$month-$year";
|
|
$period = "$month-$year";
|
|
|
|
|
|
|
|
$whenData = [[
|
|
$whenData = [[
|
|
@@ -946,45 +985,129 @@ class RecordOUT extends Component
|
|
|
'year' => $year,
|
|
'year' => $year,
|
|
|
'period' => $period
|
|
'period' => $period
|
|
|
]];
|
|
]];
|
|
|
- Log::info("Dati whenData: " . json_encode($whenData));
|
|
|
|
|
|
|
|
|
|
$recordRow = new \App\Models\RecordRow();
|
|
$recordRow = new \App\Models\RecordRow();
|
|
|
$recordRow->record_id = $recordId;
|
|
$recordRow->record_id = $recordId;
|
|
|
$recordRow->causal_id = $this->selectedCausal;
|
|
$recordRow->causal_id = $this->selectedCausal;
|
|
|
|
|
+ $recordRow->amount = $linea['prezzoTotale'] + $linea['prezzoTotale'] * ($linea['aliquotaIva'] / 100);
|
|
|
|
|
+ $recordRow->note = $linea['descrizione'];
|
|
|
|
|
+ $recordRow->commercial = 1;
|
|
|
|
|
+
|
|
|
$recordRow->when = json_encode($whenData);
|
|
$recordRow->when = json_encode($whenData);
|
|
|
|
|
+ $recordRow->aliquota_iva = $linea['aliquotaIva'];
|
|
|
|
|
+ $recordRow->imponibile = $linea['prezzoTotale'];
|
|
|
|
|
+ $recordRow->imposta = $linea['prezzoTotale'] * ($linea['aliquotaIva'] / 100);
|
|
|
|
|
+ $recordRow->divisa = $fatturaData['divisa'];
|
|
|
|
|
+ $recordRow->numero_linea = $linea['numeroLinea'];
|
|
|
|
|
+ $recordRow->prezzo_unitario = $linea['prezzoUnitario'];
|
|
|
|
|
+ $recordRow->quantita = $linea['quantita'];
|
|
|
|
|
+
|
|
|
|
|
+ Log::info("Dati riga record prima del salvataggio: " . json_encode([
|
|
|
|
|
+ 'record_id' => $recordRow->record_id,
|
|
|
|
|
+ 'causal_id' => $recordRow->causal_id,
|
|
|
|
|
+ 'amount' => $recordRow->amount,
|
|
|
|
|
+ 'note' => $recordRow->note,
|
|
|
|
|
+ 'aliquota_iva' => $recordRow->aliquota_iva,
|
|
|
|
|
+ 'imponibile' => $recordRow->imponibile,
|
|
|
|
|
+ 'imposta' => $recordRow->imposta,
|
|
|
|
|
+ 'divisa' => $recordRow->divisa,
|
|
|
|
|
+ 'numero_linea' => $recordRow->numero_linea,
|
|
|
|
|
+ 'prezzo_unitario' => $recordRow->prezzo_unitario,
|
|
|
|
|
+ 'quantita' => $recordRow->quantita,
|
|
|
|
|
+ ]));
|
|
|
|
|
+
|
|
|
|
|
+ $recordRow->save();
|
|
|
|
|
+
|
|
|
|
|
+ Log::info("Riga record creata per linea {$linea['numeroLinea']}: {$linea['descrizione']} (€{$linea['prezzoTotale']})");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function createRecordRowFromRiepilogo($recordId, $fatturaData)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info("Inizio creazione riga record da riepilogo per Record ID: " . $recordId . ", Riepilogo: " . json_encode($fatturaData['riepilogo']));
|
|
|
|
|
+
|
|
|
|
|
+ $riepilogo = $fatturaData['riepilogo'];
|
|
|
|
|
+
|
|
|
|
|
+ $dataObj = new \DateTime($fatturaData['dataDocumento']);
|
|
|
|
|
+ $month = $dataObj->format('n');
|
|
|
|
|
+ $year = $dataObj->format('Y');
|
|
|
|
|
+ $period = "$month-$year";
|
|
|
|
|
+
|
|
|
|
|
+ $whenData = [[
|
|
|
|
|
+ 'month' => $month,
|
|
|
|
|
+ 'year' => $year,
|
|
|
|
|
+ 'period' => $period
|
|
|
|
|
+ ]];
|
|
|
|
|
+ $total_amount = $riepilogo['imponibile'] + $riepilogo['imposta'];
|
|
|
|
|
+ $recordRow = new \App\Models\RecordRow();
|
|
|
|
|
+ $recordRow->record_id = $recordId;
|
|
|
|
|
+ $recordRow->causal_id = $this->selectedCausal;
|
|
|
|
|
+ $recordRow->amount = $total_amount;
|
|
|
|
|
+ $recordRow->commercial = 1;
|
|
|
|
|
+
|
|
|
|
|
+ $recordRow->when = json_encode($whenData);
|
|
|
|
|
+ $recordRow->aliquota_iva = $riepilogo['aliquotaIva'];
|
|
|
|
|
+ $recordRow->imponibile = $riepilogo['imponibile'];
|
|
|
|
|
+ $recordRow->imposta = $riepilogo['imposta'];
|
|
|
|
|
+ $recordRow->divisa = $fatturaData['divisa'];
|
|
|
|
|
+ $recordRow->numero_linea = 1;
|
|
|
|
|
+ $recordRow->quantita = 1;
|
|
|
|
|
+
|
|
|
|
|
+ Log::info("Dati riga record da riepilogo prima del salvataggio: " . json_encode([
|
|
|
|
|
+ 'record_id' => $recordRow->record_id,
|
|
|
|
|
+ 'causal_id' => $recordRow->causal_id,
|
|
|
|
|
+ 'amount' => $recordRow->amount,
|
|
|
|
|
+ 'aliquota_iva' => $recordRow->aliquota_iva,
|
|
|
|
|
+ 'imponibile' => $recordRow->imponibile,
|
|
|
|
|
+ 'imposta' => $recordRow->imposta,
|
|
|
|
|
+ 'divisa' => $recordRow->divisa,
|
|
|
|
|
+ ]));
|
|
|
|
|
+
|
|
|
|
|
+ $recordRow->save();
|
|
|
|
|
+
|
|
|
|
|
+ Log::info("Riga record creata da riepilogo: Imponibile={$riepilogo['imponibile']}, IVA={$riepilogo['aliquotaIva']}%");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function createDefaultRecordRow($recordId, $fatturaData)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info("Inizio creazione riga record predefinita per Record ID: " . $recordId . ", Importo Totale: " . $fatturaData['importoTotale']);
|
|
|
|
|
+
|
|
|
|
|
+ $dataObj = new \DateTime($fatturaData['dataDocumento']);
|
|
|
|
|
+ $month = $dataObj->format('n');
|
|
|
|
|
+ $year = $dataObj->format('Y');
|
|
|
|
|
+ $period = "$month-$year";
|
|
|
|
|
+
|
|
|
|
|
+ $whenData = [[
|
|
|
|
|
+ 'month' => $month,
|
|
|
|
|
+ 'year' => $year,
|
|
|
|
|
+ 'period' => $period
|
|
|
|
|
+ ]];
|
|
|
|
|
+ $recordRow = new \App\Models\RecordRow();
|
|
|
|
|
+ $recordRow->record_id = $recordId;
|
|
|
|
|
+ $recordRow->causal_id = $this->selectedCausal;
|
|
|
$recordRow->amount = $fatturaData['importoTotale'];
|
|
$recordRow->amount = $fatturaData['importoTotale'];
|
|
|
$recordRow->commercial = 1;
|
|
$recordRow->commercial = 1;
|
|
|
|
|
|
|
|
- $noteData = '';
|
|
|
|
|
- if (isset($fatturaData['linee']) && is_array($fatturaData['linee'])) {
|
|
|
|
|
- $descriptions = array_map(function ($linea) {
|
|
|
|
|
- return $linea['descrizione'];
|
|
|
|
|
- }, $fatturaData['linee']);
|
|
|
|
|
- $noteData = implode(', ', $descriptions);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- $recordRow->note = $noteData;
|
|
|
|
|
|
|
+ $recordRow->when = json_encode($whenData);
|
|
|
|
|
+ $recordRow->divisa = $fatturaData['divisa'];
|
|
|
|
|
+ $recordRow->numero_linea = 1;
|
|
|
|
|
+ $recordRow->quantita = 1;
|
|
|
|
|
|
|
|
- Log::info("Dati RecordRow prima del salvataggio: " . json_encode([
|
|
|
|
|
|
|
+ Log::info("Dati riga record predefinita prima del salvataggio: " . json_encode([
|
|
|
'record_id' => $recordRow->record_id,
|
|
'record_id' => $recordRow->record_id,
|
|
|
'causal_id' => $recordRow->causal_id,
|
|
'causal_id' => $recordRow->causal_id,
|
|
|
- 'when' => $recordRow->when,
|
|
|
|
|
'amount' => $recordRow->amount,
|
|
'amount' => $recordRow->amount,
|
|
|
- 'commercial' => $recordRow->commercial,
|
|
|
|
|
- 'note' => $recordRow->note
|
|
|
|
|
|
|
+ 'divisa' => $recordRow->divisa,
|
|
|
]));
|
|
]));
|
|
|
|
|
|
|
|
$recordRow->save();
|
|
$recordRow->save();
|
|
|
|
|
|
|
|
- Log::info("RecordRow creato per il Record ID: " . $recordId);
|
|
|
|
|
-
|
|
|
|
|
- return $recordRow;
|
|
|
|
|
|
|
+ Log::info("Riga record predefinita creata con importo totale: {$fatturaData['importoTotale']}");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Crea una ricevuta collegata al record
|
|
* Crea una ricevuta collegata al record
|
|
|
*/
|
|
*/
|
|
|
- private function createReceipt($recordId, $supplierId, $paymentMethodId, $fatturaData)
|
|
|
|
|
|
|
+ /* private function createReceipt($recordId, $supplierId, $paymentMethodId, $fatturaData)
|
|
|
{
|
|
{
|
|
|
Log::info("Inizio creazione ricevuta per Record ID: " . $recordId);
|
|
Log::info("Inizio creazione ricevuta per Record ID: " . $recordId);
|
|
|
|
|
|
|
@@ -993,7 +1116,7 @@ class RecordOUT extends Component
|
|
|
$receipt->supplier_id = $supplierId;
|
|
$receipt->supplier_id = $supplierId;
|
|
|
$receipt->payment_method_id = $paymentMethodId;
|
|
$receipt->payment_method_id = $paymentMethodId;
|
|
|
$receipt->date = $fatturaData['dataDocumento'];
|
|
$receipt->date = $fatturaData['dataDocumento'];
|
|
|
- $receipt->data_documento = $fatturaData['dataDocumento'];
|
|
|
|
|
|
|
+ $receipt->data_pagamento = $fatturaData['dataDocumento'];
|
|
|
$receipt->numero_fattura = $fatturaData['numeroFattura'];
|
|
$receipt->numero_fattura = $fatturaData['numeroFattura'];
|
|
|
$receipt->number = preg_replace('/[^0-9]/', '', $fatturaData['numeroFattura']);
|
|
$receipt->number = preg_replace('/[^0-9]/', '', $fatturaData['numeroFattura']);
|
|
|
$receipt->tipo_documento = $this->mapTipoDocumento($fatturaData['tipoDocumento']);
|
|
$receipt->tipo_documento = $this->mapTipoDocumento($fatturaData['tipoDocumento']);
|
|
@@ -1068,7 +1191,7 @@ class RecordOUT extends Component
|
|
|
$receiptRow = new \App\Models\ReceiptRow();
|
|
$receiptRow = new \App\Models\ReceiptRow();
|
|
|
$receiptRow->receip_id = $receiptId;
|
|
$receiptRow->receip_id = $receiptId;
|
|
|
$receiptRow->causal_id = $this->selectedCausal;
|
|
$receiptRow->causal_id = $this->selectedCausal;
|
|
|
- $receiptRow->amount = $linea['prezzoTotale'];
|
|
|
|
|
|
|
+ $receiptRow->amount = $linea['prezzoTotale'] + $linea['prezzoTotale'] * ($linea['aliquotaIva'] / 100);
|
|
|
$receiptRow->note = $linea['descrizione'];
|
|
$receiptRow->note = $linea['descrizione'];
|
|
|
$receiptRow->commercial = 1;
|
|
$receiptRow->commercial = 1;
|
|
|
|
|
|
|
@@ -1116,10 +1239,11 @@ class RecordOUT extends Component
|
|
|
'year' => $year,
|
|
'year' => $year,
|
|
|
'period' => $period
|
|
'period' => $period
|
|
|
]];
|
|
]];
|
|
|
|
|
+ $total_amount = $riepilogo['imponibile'] + $riepilogo['imposta'];
|
|
|
$receiptRow = new \App\Models\ReceiptRow();
|
|
$receiptRow = new \App\Models\ReceiptRow();
|
|
|
$receiptRow->receip_id = $receiptId;
|
|
$receiptRow->receip_id = $receiptId;
|
|
|
$receiptRow->causal_id = $this->selectedCausal;
|
|
$receiptRow->causal_id = $this->selectedCausal;
|
|
|
- $receiptRow->amount = $riepilogo['imponibile'];
|
|
|
|
|
|
|
+ $receiptRow->amount = $total_amount;
|
|
|
$receiptRow->commercial = 1;
|
|
$receiptRow->commercial = 1;
|
|
|
|
|
|
|
|
$receiptRow->when = json_encode($whenData);
|
|
$receiptRow->when = json_encode($whenData);
|
|
@@ -1181,7 +1305,7 @@ class RecordOUT extends Component
|
|
|
|
|
|
|
|
Log::info("Riga ricevuta predefinita creata con importo totale: {$fatturaData['importoTotale']}");
|
|
Log::info("Riga ricevuta predefinita creata con importo totale: {$fatturaData['importoTotale']}");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ */
|
|
|
private function mapTipoDocumento($codice)
|
|
private function mapTipoDocumento($codice)
|
|
|
{
|
|
{
|
|
|
$tipiDocumento = [
|
|
$tipiDocumento = [
|