@@ -32,6 +32,10 @@ class LivePurchaseOrderLines extends Component
32
32
33
33
public $ quantity ;
34
34
35
+ public $ tax_amount ;
36
+
37
+ public $ tax_rate ;
38
+
35
39
public $ amount ;
36
40
37
41
public $ comments ;
@@ -86,6 +90,7 @@ public function mount($purchaseOrder, $purchaseOrderLines, $old = null, $fromOrd
86
90
}
87
91
88
92
$ this ->price [$ this ->i ] = $ old ['price ' ] ?? null ;
93
+ $ this ->tax_amount [$ this ->i ] = $ old ['tax_amount ' ] ?? null ;
89
94
$ this ->amount [$ this ->i ] = $ old ['amount ' ] ?? null ;
90
95
$ this ->comments [$ this ->i ] = $ old ['comments ' ] ?? null ;
91
96
}
@@ -111,6 +116,7 @@ public function mount($purchaseOrder, $purchaseOrderLines, $old = null, $fromOrd
111
116
}
112
117
113
118
$ this ->price [$ this ->i ] = $ purchaseOrderLine ->price / 100 ;
119
+ $ this ->tax_amount [$ this ->i ] = $ purchaseOrderLine ->tax_amount / 100 ;
114
120
$ this ->amount [$ this ->i ] = $ purchaseOrderLine ->amount / 100 ;
115
121
$ this ->comments [$ this ->i ] = $ purchaseOrderLine ->comments ;
116
122
}
@@ -127,6 +133,7 @@ public function add($i)
127
133
$ this ->i = $ i ;
128
134
$ this ->price [$ i ] = null ;
129
135
$ this ->quantity [$ i ] = null ;
136
+ $ this ->tax_rate [$ i ] = null ;
130
137
array_push ($ this ->inputs , $ i );
131
138
132
139
$ this ->dispatchBrowserEvent ('addedItem ' , ['id ' => $ this ->i ]);
@@ -154,8 +161,12 @@ public function calculateAmounts()
154
161
155
162
for ($ i = 1 ; $ i <= $ this ->i ; $ i ++) {
156
163
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 ;
159
170
} elseif ($ taxRate = TaxRate::where ('default ' , 1 )->first ()) {
160
171
$ taxRate = $ taxRate ->rate ;
161
172
} elseif ($ taxRate = $ this ->settingService ->get ('tax_rate ' )) {
@@ -164,15 +175,18 @@ public function calculateAmounts()
164
175
$ taxRate = 0 ;
165
176
}
166
177
178
+ $ this ->tax_rate [$ i ] = $ taxRate ;
179
+
167
180
if (is_numeric ($ this ->price [$ i ]) && is_numeric ($ this ->quantity [$ i ])) {
168
181
$ this ->amount [$ i ] = $ this ->price [$ i ] * $ this ->quantity [$ i ];
169
182
$ this ->price [$ i ] = $ this ->currencyFormat ($ this ->price [$ i ]);
183
+ $ this ->tax_amount [$ i ] = $ this ->currencyFormat ($ this ->amount [$ i ] * ($ taxRate / 100 ));
170
184
} else {
171
185
$ this ->amount [$ i ] = 0 ;
172
186
}
173
187
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 );
176
190
$ this ->amount [$ i ] = $ this ->currencyFormat ($ this ->amount [$ i ]);
177
191
}
178
192
}
0 commit comments