Skip to content

Commit 602a677

Browse files
committed
Tax on purchase order lines
1 parent 86f0fd6 commit 602a677

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

resources/views/purchase-order-lines/partials/fields.blade.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</tr>
7474
@endif
7575
<tr data-number="{{ $value }}" class="item-tr">
76-
<td colspan="3" class="border-0 pt-0">
76+
<td colspan="2" class="border-0 pt-0">
7777
@if($fromOrder)
7878
@include('laravel-crm::partials.form.text',[
7979
'name' => 'purchaseOrderLines['.$value.'][price]',
@@ -126,6 +126,19 @@
126126
])
127127
@endif
128128
</td>
129+
<td class="border-0 pt-0">
130+
@include('laravel-crm::partials.form.text',[
131+
'name' => 'purchaseOrderLines['.$value.'][tax_amount]',
132+
'label' => $taxName . ' (' . $tax_rate[$value] . '%)',
133+
'type' => 'number',
134+
'prepend' => '<span class="fa fa-dollar" aria-hidden="true"></span>',
135+
'attributes' => [
136+
'wire:model' => 'tax_amount.'.$value,
137+
'step' => .01,
138+
'readonly' => 'readonly'
139+
]
140+
])
141+
</td>
129142
<td class="border-0 pt-0">
130143
@include('laravel-crm::partials.form.text',[
131144
'name' => 'purchaseOrderLines['.$value.'][amount]',

src/Http/Livewire/LivePurchaseOrderLines.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class LivePurchaseOrderLines extends Component
3232

3333
public $quantity;
3434

35+
public $tax_amount;
36+
37+
public $tax_rate;
38+
3539
public $amount;
3640

3741
public $comments;
@@ -86,6 +90,7 @@ public function mount($purchaseOrder, $purchaseOrderLines, $old = null, $fromOrd
8690
}
8791

8892
$this->price[$this->i] = $old['price'] ?? null;
93+
$this->tax_amount[$this->i] = $old['tax_amount'] ?? null;
8994
$this->amount[$this->i] = $old['amount'] ?? null;
9095
$this->comments[$this->i] = $old['comments'] ?? null;
9196
}
@@ -111,6 +116,7 @@ public function mount($purchaseOrder, $purchaseOrderLines, $old = null, $fromOrd
111116
}
112117

113118
$this->price[$this->i] = $purchaseOrderLine->price / 100;
119+
$this->tax_amount[$this->i] = $purchaseOrderLine->tax_amount / 100;
114120
$this->amount[$this->i] = $purchaseOrderLine->amount / 100;
115121
$this->comments[$this->i] = $purchaseOrderLine->comments;
116122
}
@@ -127,6 +133,7 @@ public function add($i)
127133
$this->i = $i;
128134
$this->price[$i] = null;
129135
$this->quantity[$i] = null;
136+
$this->tax_rate[$i] = null;
130137
array_push($this->inputs, $i);
131138

132139
$this->dispatchBrowserEvent('addedItem', ['id' => $this->i]);
@@ -154,8 +161,12 @@ public function calculateAmounts()
154161

155162
for ($i = 1; $i <= $this->i; $i++) {
156163
if (isset($this->product_id[$i])) {
157-
if($product = \VentureDrake\LaravelCrm\Models\Product::find($this->product_id[$i])) {
158-
$taxRate = $product->taxRate->rate ?? $product->tax_rate ?? 0;
164+
$product = \VentureDrake\LaravelCrm\Models\Product::find($this->product_id[$i]);
165+
166+
if($product && $product->taxRate) {
167+
$taxRate = $product->taxRate->rate;
168+
} elseif($product && $product->tax_rate) {
169+
$taxRate = $product->tax_rate;
159170
} elseif($taxRate = TaxRate::where('default', 1)->first()) {
160171
$taxRate = $taxRate->rate;
161172
} elseif($taxRate = $this->settingService->get('tax_rate')) {
@@ -164,15 +175,18 @@ public function calculateAmounts()
164175
$taxRate = 0;
165176
}
166177

178+
$this->tax_rate[$i] = $taxRate;
179+
167180
if (is_numeric($this->price[$i]) && is_numeric($this->quantity[$i])) {
168181
$this->amount[$i] = $this->price[$i] * $this->quantity[$i];
169182
$this->price[$i] = $this->currencyFormat($this->price[$i]);
183+
$this->tax_amount[$i] = $this->currencyFormat($this->amount[$i] * ($taxRate / 100));
170184
} else {
171185
$this->amount[$i] = 0;
172186
}
173187

174-
$this->sub_total += $this->amount[$i];
175-
$this->tax += $this->amount[$i] * ($taxRate / 100);
188+
$this->sub_total += round($this->amount[$i], 2);
189+
$this->tax += round($this->amount[$i] * ($taxRate / 100), 2);
176190
$this->amount[$i] = $this->currencyFormat($this->amount[$i]);
177191
}
178192
}

0 commit comments

Comments
 (0)