|
|
@@ -126,7 +126,15 @@ class RecordOUT extends Component
|
|
|
//$this->amount = null;
|
|
|
$this->commercial = 1;
|
|
|
$this->rows = array();
|
|
|
- $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'note' => '', 'commercial' => 0);
|
|
|
+ $this->rows[] = array(
|
|
|
+ 'causal_id' => null,
|
|
|
+ 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),
|
|
|
+ 'amount' => null,
|
|
|
+ 'imponibile' => null,
|
|
|
+ 'aliquota_iva' => null,
|
|
|
+ 'note' => '',
|
|
|
+ 'commercial' => 0
|
|
|
+ );
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
@@ -363,11 +371,17 @@ class RecordOUT extends Component
|
|
|
foreach ($row["when"] as $x => $y) {
|
|
|
$row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
|
|
|
}
|
|
|
+ $imponibile = isset($row["imponibile"]) ? $this->currencyToDouble($row["imponibile"]) : null;
|
|
|
+ Log::info("Imponibile store: " . $imponibile);
|
|
|
+ $aliquota_iva = isset($row["aliquota_iva"]) ? floatval(str_replace('%', '', $row["aliquota_iva"])) : null;
|
|
|
+ Log::info("Aliquota IVA store: " . $aliquota_iva);
|
|
|
\App\Models\RecordRow::create([
|
|
|
'record_id' => $this->dataId,
|
|
|
'causal_id' => $row["causal_id"],
|
|
|
'note' => $row["note"],
|
|
|
'amount' => $this->currencyToDouble($row["amount"]),
|
|
|
+ 'imponibile' => $imponibile,
|
|
|
+ 'aliquota_iva' => $aliquota_iva,
|
|
|
'commercial' => $row["commercial"],
|
|
|
'when' => json_encode($row["when"])
|
|
|
]);
|
|
|
@@ -414,10 +428,30 @@ class RecordOUT extends Component
|
|
|
$this->update = true;
|
|
|
$this->add = false;
|
|
|
|
|
|
- $this->rows = \App\Models\RecordRow::where('record_id', $this->dataId)->select('causal_id', 'note', 'commercial', 'when', 'amount')->get()->toArray();
|
|
|
- foreach ($this->rows as $i => $r) {
|
|
|
- $this->rows[$i]['amount'] = formatPrice($this->rows[$i]['amount']);
|
|
|
- $this->rows[$i]['when'] = json_decode($this->rows[$i]['when']);
|
|
|
+ $this->rows = [];
|
|
|
+
|
|
|
+ $recordRows = \App\Models\RecordRow::where('record_id', $this->dataId)->get();
|
|
|
+
|
|
|
+ foreach ($recordRows as $recordRow) {
|
|
|
+ $rowData = [
|
|
|
+ 'causal_id' => $recordRow->causal_id,
|
|
|
+ 'note' => $recordRow->note,
|
|
|
+ 'commercial' => $recordRow->commercial,
|
|
|
+ 'when' => json_decode($recordRow->when),
|
|
|
+ 'amount' => formatPrice($recordRow->amount)
|
|
|
+ ];
|
|
|
+
|
|
|
+ // Add imponibile field if available in the database
|
|
|
+ if (isset($recordRow->imponibile)) {
|
|
|
+ $rowData['imponibile'] = formatPrice($recordRow->imponibile);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add aliquota_iva field if available in the database
|
|
|
+ if (isset($recordRow->aliquota_iva)) {
|
|
|
+ $rowData['aliquota_iva'] = $recordRow->aliquota_iva . '%';
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->rows[] = $rowData;
|
|
|
}
|
|
|
}
|
|
|
} catch (\Exception $ex) {
|
|
|
@@ -429,39 +463,79 @@ class RecordOUT extends Component
|
|
|
{
|
|
|
$this->emit('refresh');
|
|
|
$this->validate();
|
|
|
+ Log::info("Rows: pipo" );
|
|
|
+
|
|
|
try {
|
|
|
\App\Models\Record::whereId($this->dataId)->update([
|
|
|
'member_id' => $this->member_id,
|
|
|
'supplier_id' => $this->supplier_id,
|
|
|
- //'causal_id' => $this->causal_id,
|
|
|
'payment_method_id' => $this->payment_method_id,
|
|
|
'date' => $this->date,
|
|
|
'data_pagamento' => $this->data_pagamento,
|
|
|
- //'month' => $this->month,
|
|
|
- //'year' => $this->year,
|
|
|
- //'note' => $this->note,
|
|
|
'type' => $this->type,
|
|
|
- //'amount' => $this->currencyToDouble($this->amount),
|
|
|
'commercial' => $this->commercial,
|
|
|
]);
|
|
|
|
|
|
$tot = 0;
|
|
|
|
|
|
- // Elimino le righe
|
|
|
+ $existingRows = \App\Models\RecordRow::where('record_id', $this->dataId)
|
|
|
+ ->select('id', 'quantita', 'numero_linea')
|
|
|
+ ->get()
|
|
|
+ ->keyBy('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // Delete existing rows
|
|
|
\App\Models\RecordRow::where('record_id', $this->dataId)->delete();
|
|
|
- // Inserisco le righe
|
|
|
+
|
|
|
+ // Insert updated rows
|
|
|
foreach ($this->rows as $row) {
|
|
|
foreach ($row["when"] as $x => $y) {
|
|
|
$row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
|
|
|
}
|
|
|
- \App\Models\RecordRow::create([
|
|
|
+
|
|
|
+ // Get imponibile and aliquota_iva values if they exist
|
|
|
+ $imponibile = null;
|
|
|
+ if (isset($row["imponibile"]) && $row["imponibile"] !== null && $row["imponibile"] !== '') {
|
|
|
+ $imponibile = $this->currencyToDouble($row["imponibile"]);
|
|
|
+ Log::info("Imponibile: " . $imponibile);
|
|
|
+ }
|
|
|
+
|
|
|
+ $aliquota_iva = null;
|
|
|
+ if (isset($row["aliquota_iva"]) && $row["aliquota_iva"] !== null && $row["aliquota_iva"] !== '') {
|
|
|
+ $aliquota_iva = floatval(str_replace('%', '', $row["aliquota_iva"]));
|
|
|
+ Log::info("Aliquota IVA: " . $aliquota_iva);
|
|
|
+ }
|
|
|
+
|
|
|
+ $amount = $this->currencyToDouble($row["amount"]);
|
|
|
+
|
|
|
+ // Calculate imposta (amount - imponibile) if imponibile exists
|
|
|
+ $imposta = null;
|
|
|
+ if ($imponibile !== null) {
|
|
|
+ $imposta = $amount - $imponibile;
|
|
|
+ Log::info("Imposta calculated: " . $imposta);
|
|
|
+ }
|
|
|
+
|
|
|
+ $recordRowData = [
|
|
|
'record_id' => $this->dataId,
|
|
|
'causal_id' => $row["causal_id"],
|
|
|
'note' => $row["note"],
|
|
|
'amount' => $this->currencyToDouble($row["amount"]),
|
|
|
'commercial' => $row["commercial"],
|
|
|
- 'when' => json_encode($row["when"])
|
|
|
- ]);
|
|
|
+ 'when' => json_encode($row["when"]),
|
|
|
+ 'imponibile' => $imponibile,
|
|
|
+ 'aliquota_iva' => $aliquota_iva,
|
|
|
+ 'imposta' => $imposta,
|
|
|
+ 'divisa' => 'EUR', // Assuming the currency is always EUR
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (isset($row["id"]) && isset($existingRows[$row["id"]])) {
|
|
|
+ $existingRow = $existingRows[$row["id"]];
|
|
|
+ $recordRowData['quantita'] = $existingRow['quantita'];
|
|
|
+ $recordRowData['numero_linea'] = $existingRow['numero_linea'];
|
|
|
+ }
|
|
|
+
|
|
|
+ Log::info("RecordRowData: " . json_encode($recordRowData));
|
|
|
+ \App\Models\RecordRow::create($recordRowData);
|
|
|
$tot += $this->currencyToDouble($row["amount"]);
|
|
|
}
|
|
|
|
|
|
@@ -577,7 +651,15 @@ class RecordOUT extends Component
|
|
|
|
|
|
public function addRow()
|
|
|
{
|
|
|
- $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'note' => '', 'commercial' => 0);
|
|
|
+ $this->rows[] = array(
|
|
|
+ 'causal_id' => null,
|
|
|
+ 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')),
|
|
|
+ 'amount' => null,
|
|
|
+ 'imponibile' => null,
|
|
|
+ 'aliquota_iva' => null,
|
|
|
+ 'note' => '',
|
|
|
+ 'commercial' => 0
|
|
|
+ );
|
|
|
$this->emit('load-select');
|
|
|
}
|
|
|
|
|
|
@@ -685,7 +767,7 @@ class RecordOUT extends Component
|
|
|
//$receipt = $this->createReceipt($record->id, $supplier->id, $paymentMethodId, $fatturaData);
|
|
|
|
|
|
// Crea le righe della ricevuta
|
|
|
- // $this->createReceiptRows($receipt->id, $fatturaData);
|
|
|
+ // $this->createReceiptRows($receipt->id, $fatturaData);
|
|
|
|
|
|
$importCount++;
|
|
|
Log::info("Fattura importata con successo: {$fatturaData['numeroFattura']}, Fornitore: {$fatturaData['denominazione']}");
|