@@ -110,12 +110,7 @@ public function loadItemDefault($id)
110
110
$ this ->amount [$ id ] = null ;
111
111
}
112
112
113
- $ this ->calculateLineAmounts ($ id );
114
- }
115
-
116
- public function calculateLineAmounts ($ i )
117
- {
118
- $ this ->calculateLineItem ($ i );
113
+ $ this ->calculateAmounts ();
119
114
}
120
115
121
116
public function calculateAmounts ()
@@ -125,43 +120,32 @@ public function calculateAmounts()
125
120
$ this ->total = 0 ;
126
121
127
122
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 ]);
152
144
}
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 ();
159
145
}
160
- }
161
146
162
- protected function calculateTotals ()
163
- {
164
147
$ this ->total = $ this ->sub_total + $ this ->tax ;
148
+
165
149
$ this ->sub_total = $ this ->currencyFormat ($ this ->sub_total );
166
150
$ this ->tax = $ this ->currencyFormat ($ this ->tax );
167
151
$ this ->discount = $ this ->currencyFormat ($ this ->discount );
0 commit comments