Skip to content

Commit 30f2b8d

Browse files
committed
Reverted calc line items
1 parent a161441 commit 30f2b8d

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

src/Http/Livewire/LiveQuoteItems.php

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ public function loadItemDefault($id)
110110
$this->amount[$id] = null;
111111
}
112112

113-
$this->calculateLineAmounts($id);
114-
}
115-
116-
public function calculateLineAmounts($i)
117-
{
118-
$this->calculateLineItem($i);
113+
$this->calculateAmounts();
119114
}
120115

121116
public function calculateAmounts()
@@ -125,43 +120,32 @@ public function calculateAmounts()
125120
$this->total = 0;
126121

127122
for ($i = 1; $i <= $this->i; $i++) {
128-
$this->calculateLineItem($i);
129-
}
130-
131-
$this->calculateTotals();
132-
}
133-
134-
protected function calculateLineItem($i)
135-
{
136-
if (isset($this->product_id[$i])) {
137-
if($product = \VentureDrake\LaravelCrm\Models\Product::find($this->product_id[$i])) {
138-
$taxRate = $product->taxRate->rate ?? $product->tax_rate ?? 0;
139-
} elseif($taxRate = TaxRate::where('default', 1)->first()) {
140-
$taxRate = $taxRate->rate;
141-
} elseif($taxRate = $this->settingService->get('tax_rate')) {
142-
$taxRate = $taxRate->value;
143-
} else {
144-
$taxRate = 0;
145-
}
146-
147-
if (is_numeric($this->unit_price[$i]) && is_numeric($this->quantity[$i])) {
148-
$this->amount[$i] = $this->unit_price[$i] * $this->quantity[$i];
149-
$this->unit_price[$i] = $this->currencyFormat($this->unit_price[$i]);
150-
} else {
151-
$this->amount[$i] = 0;
123+
if (isset($this->product_id[$i])) {
124+
if($product = \VentureDrake\LaravelCrm\Models\Product::find($this->product_id[$i])) {
125+
$taxRate = $product->taxRate->rate ?? $product->tax_rate ?? 0;
126+
} elseif($taxRate = TaxRate::where('default', 1)->first()) {
127+
$taxRate = $taxRate->rate;
128+
} elseif($taxRate = $this->settingService->get('tax_rate')) {
129+
$taxRate = $taxRate->value;
130+
} else {
131+
$taxRate = 0;
132+
}
133+
134+
if (is_numeric($this->unit_price[$i]) && is_numeric($this->quantity[$i])) {
135+
$this->amount[$i] = $this->unit_price[$i] * $this->quantity[$i];
136+
$this->unit_price[$i] = $this->currencyFormat($this->unit_price[$i]);
137+
} else {
138+
$this->amount[$i] = 0;
139+
}
140+
141+
$this->sub_total += $this->amount[$i];
142+
$this->tax += $this->amount[$i] * ($taxRate / 100);
143+
$this->amount[$i] = $this->currencyFormat($this->amount[$i]);
152144
}
153-
154-
$this->sub_total += $this->amount[$i];
155-
$this->tax += $this->amount[$i] * ($taxRate / 100);
156-
$this->amount[$i] = $this->currencyFormat($this->amount[$i]);
157-
158-
$this->calculateTotals();
159145
}
160-
}
161146

162-
protected function calculateTotals()
163-
{
164147
$this->total = $this->sub_total + $this->tax;
148+
165149
$this->sub_total = $this->currencyFormat($this->sub_total);
166150
$this->tax = $this->currencyFormat($this->tax);
167151
$this->discount = $this->currencyFormat($this->discount);

0 commit comments

Comments
 (0)