|
@@ -607,8 +607,7 @@ class RecordIN extends Component
|
|
|
$no_receipt_causal = true;
|
|
$no_receipt_causal = true;
|
|
|
|
|
|
|
|
if ($cau->money) {
|
|
if ($cau->money) {
|
|
|
- if ($rowNet >= env('MIN_MONEY', 100))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if ($rowNet >= env('MIN_MONEY', 100)) {
|
|
|
$money = new \App\Models\Money();
|
|
$money = new \App\Models\Money();
|
|
|
$money->member_id = $this->member_id;
|
|
$money->member_id = $this->member_id;
|
|
|
$money->record_id = $this->dataId;
|
|
$money->record_id = $this->dataId;
|
|
@@ -1000,6 +999,18 @@ class RecordIN extends Component
|
|
|
if ($exist != null)
|
|
if ($exist != null)
|
|
|
$number = $exist->number + 1;
|
|
$number = $exist->number + 1;
|
|
|
|
|
|
|
|
|
|
+ // Calculate totals for the receipt
|
|
|
|
|
+ $totalGross = 0;
|
|
|
|
|
+ $totalNet = 0;
|
|
|
|
|
+ foreach ($this->rows as $row) {
|
|
|
|
|
+ $rowAmount = $this->currencyToDouble($row["amount"]);
|
|
|
|
|
+ $rowSconto = isset($row['sconto']) ? $this->currencyToDouble($row['sconto']) : 0;
|
|
|
|
|
+ $rowNet = max(0, $rowAmount - $rowSconto);
|
|
|
|
|
+
|
|
|
|
|
+ $totalGross += $rowAmount;
|
|
|
|
|
+ $totalNet += $rowNet;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$receipt = \App\Models\Receipt::create([
|
|
$receipt = \App\Models\Receipt::create([
|
|
|
'record_id' => $this->dataId,
|
|
'record_id' => $this->dataId,
|
|
|
'member_id' => $this->member_id,
|
|
'member_id' => $this->member_id,
|
|
@@ -1012,14 +1023,22 @@ class RecordIN extends Component
|
|
|
'parent' => $this->parent,
|
|
'parent' => $this->parent,
|
|
|
'status' => 1,
|
|
'status' => 1,
|
|
|
]);
|
|
]);
|
|
|
|
|
+
|
|
|
foreach ($this->rows as $row) {
|
|
foreach ($this->rows as $row) {
|
|
|
- Log::info("Row - Gross: " . $row["amount"] . ", Sconto: " . $row["sconto"] . ", Net: " . $row["amount"]);
|
|
|
|
|
|
|
+ $rowAmount = $this->currencyToDouble($row["amount"]);
|
|
|
|
|
+ $rowSconto = isset($row['sconto']) ? $this->currencyToDouble($row['sconto']) : 0;
|
|
|
|
|
+ $rowNet = max(0, $rowAmount - $rowSconto);
|
|
|
|
|
+
|
|
|
|
|
+ Log::info("Receipt Row - Gross: " . $rowAmount . ", Sconto: " . $rowSconto . ", Net: " . $rowNet);
|
|
|
|
|
+
|
|
|
\App\Models\ReceiptRow::create([
|
|
\App\Models\ReceiptRow::create([
|
|
|
'receip_id' => $receipt->id,
|
|
'receip_id' => $receipt->id,
|
|
|
'causal_id' => $row["causal_id"],
|
|
'causal_id' => $row["causal_id"],
|
|
|
'note' => $row["note"],
|
|
'note' => $row["note"],
|
|
|
'vat_id' => $row["vat_id"],
|
|
'vat_id' => $row["vat_id"],
|
|
|
- 'amount' => $this->currencyToDouble($row["amount"]) - $this->currencyToDouble($row["sconto"]),
|
|
|
|
|
|
|
+ 'amount' => $rowNet,
|
|
|
|
|
+ 'prediscount_amount' => $rowAmount,
|
|
|
|
|
+ 'sconto' => $rowSconto,
|
|
|
'commercial' => $row["commercial"],
|
|
'commercial' => $row["commercial"],
|
|
|
'when' => json_encode($row["when"])
|
|
'when' => json_encode($row["when"])
|
|
|
]);
|
|
]);
|
|
@@ -1029,10 +1048,8 @@ class RecordIN extends Component
|
|
|
|
|
|
|
|
sendReceiptEmail($receipt);
|
|
sendReceiptEmail($receipt);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
session()->flash('receipt', "Ricevuta " . $number . "/" . date("Y") . " creata correttamente");
|
|
session()->flash('receipt', "Ricevuta " . $number . "/" . date("Y") . " creata correttamente");
|
|
|
|
|
|
|
|
- // Apro la ricevuta
|
|
|
|
|
$this->emit('showReceipt', $this->currentReceip->id);
|
|
$this->emit('showReceipt', $this->currentReceip->id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1087,15 +1104,12 @@ class RecordIN extends Component
|
|
|
|
|
|
|
|
foreach ($this->rows as $r) {
|
|
foreach ($this->rows as $r) {
|
|
|
if ($r["amount"] != null && $r["amount"] != "") {
|
|
if ($r["amount"] != null && $r["amount"] != "") {
|
|
|
- // Get the amount after discount
|
|
|
|
|
$rowAmount = $this->currencyToDouble($r["amount"]);
|
|
$rowAmount = $this->currencyToDouble($r["amount"]);
|
|
|
$rowSconto = isset($r['sconto']) ? $this->currencyToDouble($r['sconto']) : 0;
|
|
$rowSconto = isset($r['sconto']) ? $this->currencyToDouble($r['sconto']) : 0;
|
|
|
$netAmount = max(0, $rowAmount - $rowSconto);
|
|
$netAmount = max(0, $rowAmount - $rowSconto);
|
|
|
|
|
|
|
|
- // Add net amount to total
|
|
|
|
|
$total += $netAmount;
|
|
$total += $netAmount;
|
|
|
|
|
|
|
|
- // Add VAT if applicable (calculated on net amount)
|
|
|
|
|
if ($r["vat_id"] > 0)
|
|
if ($r["vat_id"] > 0)
|
|
|
$total += getVatValue($netAmount, $r["vat_id"]);
|
|
$total += getVatValue($netAmount, $r["vat_id"]);
|
|
|
}
|
|
}
|