@@ -76,90 +76,104 @@ public function getIdAdvPaymentByIdProduct($id_product)
76
76
return false ;
77
77
}
78
78
79
-
80
- public function getProductMinAdvPaymentAmountByIdCart ($ id_cart , $ id_product , $ adv_global_percent = 0 , $ adv_global_tax_incl = 0 , $ with_taxes = 1 )
81
- {
82
- if (!$ adv_global_percent ) {
83
- $ adv_global_percent = Configuration::get ('WK_ADVANCED_PAYMENT_GLOBAL_MIN_AMOUNT ' );
79
+ /**
80
+ * Get the advance payment amount of the room type in the cart
81
+ * @param [int] $idCart : cart id
82
+ * @param [int] $idProduct : id_product of room type
83
+ * @param integer $advGlobalPercent
84
+ * @param integer $advGlobalTaxIncl
85
+ * @param integer $withTaxes : Amount with(1) or without tax (0)
86
+ * @return [float] advance payment amount of the room type in the cart
87
+ */
88
+ public function getProductMinAdvPaymentAmountByIdCart (
89
+ $ idCart ,
90
+ $ idProduct ,
91
+ $ advGlobalPercent = 0 ,
92
+ $ advGlobalTaxIncl = 0 ,
93
+ $ withTaxes = 1
94
+ ) {
95
+ if (!$ advGlobalPercent ) {
96
+ $ advGlobalPercent = Configuration::get ('WK_ADVANCED_PAYMENT_GLOBAL_MIN_AMOUNT ' );
84
97
}
85
-
86
- if (!$ adv_global_tax_incl ) {
87
- $ adv_global_tax_incl = Configuration::get ('WK_ADVANCED_PAYMENT_INC_TAX ' );
98
+ if (!$ advGlobalTaxIncl ) {
99
+ $ advGlobalTaxIncl = Configuration::get ('WK_ADVANCED_PAYMENT_INC_TAX ' );
88
100
}
89
- $ price_with_tax = Product::getPriceStatic ($ id_product , true , null , 6 , null , false , true );
90
- $ price_without_tax = Product::getPriceStatic ($ id_product , false , null , 6 , null , false , true );
91
- $ hotelCartBookingData = new HotelCartBookingData ();
92
- $ roomTypesByIdProduct = $ hotelCartBookingData ->getCartInfoIdCartIdProduct ((int ) $ id_cart , (int )$ id_product );
93
- $ totalPriceByProductTaxIncl = 0 ;
94
- $ totalPriceByProductTaxExcl = 0 ;
101
+
102
+ $ roomTypeTotalTI = 0 ;
103
+ $ roomTypeTotalTE = 0 ;
95
104
$ productCartQuantity = 0 ;
96
- foreach ($ roomTypesByIdProduct as $ key => $ cartRoomInfo ) {
97
- $ roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice ($ cartRoomInfo ['id_product ' ], $ cartRoomInfo ['date_from ' ], $ cartRoomInfo ['date_to ' ]);
98
- $ totalPriceByProductTaxIncl += $ roomTotalPrice ['total_price_tax_incl ' ];
99
- $ totalPriceByProductTaxExcl += $ roomTotalPrice ['total_price_tax_excl ' ];
100
- $ productCartQuantity += $ cartRoomInfo ['quantity ' ];
105
+ $ objHtlCartBook = new HotelCartBookingData ();
106
+ if ($ roomTypesByIdProduct = $ objHtlCartBook ->getCartInfoIdCartIdProduct ((int ) $ idCart , (int )$ idProduct )) {
107
+ foreach ($ roomTypesByIdProduct as $ cartRoomInfo ) {
108
+ $ roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice (
109
+ $ cartRoomInfo ['id_product ' ],
110
+ $ cartRoomInfo ['date_from ' ],
111
+ $ cartRoomInfo ['date_to ' ]
112
+ );
113
+
114
+ $ roomTypeTotalTI += $ roomTotalPrices ['total_price_tax_incl ' ];
115
+ $ roomTypeTotalTE += $ roomTotalPrices ['total_price_tax_excl ' ];
116
+ $ productCartQuantity += $ cartRoomInfo ['quantity ' ];
117
+ }
101
118
}
102
- $ prod_adv = $ this ->getIdAdvPaymentByIdProduct ($ id_product );
103
- if ($ prod_adv ) {
104
- if ($ prod_adv ['active ' ]) {
105
- if ($ prod_adv ['calculate_from ' ]) { // Advanced payment is calculated by product advanced payment setting
106
- if ($ prod_adv ['payment_type ' ] == self ::WK_ADVANCE_PAYMENT_TYPE_PERCENTAGE ) { // Percentage
107
- if ($ prod_adv ['tax_include ' ]) {
108
- $ prod_price = $ totalPriceByProductTaxIncl ;
109
- } else {
110
- $ prod_price = $ totalPriceByProductTaxExcl ;
111
- }
112
- $ adv_amount = ($ prod_price *$ prod_adv ['value ' ])/100 ;
119
+
120
+ $ advPaymentAmount = 0 ;
121
+ if ($ prodAdvPayInfo = $ this ->getIdAdvPaymentByIdProduct ($ idProduct )) {
122
+ if ($ prodAdvPayInfo ['active ' ]) {
123
+ // Advanced payment is calculated by product advanced payment setting
124
+ if ($ prodAdvPayInfo ['calculate_from ' ]) {
125
+ // room type original prices
126
+ $ prodRawPriceTI = Product::getPriceStatic ($ idProduct , true , null , 6 , null , false , true );
127
+ $ prodRawPriceTE = Product::getPriceStatic ($ idProduct , false , null , 6 , null , false , true );
128
+
129
+ if ($ prodAdvPayInfo ['payment_type ' ] == self ::WK_ADVANCE_PAYMENT_TYPE_PERCENTAGE ) { // Percentage
130
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ prodAdvPayInfo ['value ' ]) / 100 ;
113
131
} else {
114
- $ prod_adv ['value ' ] = Tools::convertPrice ($ prod_adv ['value ' ]);
132
+ $ prodAdvPayInfo ['value ' ] = Tools::convertPrice ($ prodAdvPayInfo ['value ' ]);
115
133
116
- if ($ prod_adv ['tax_include ' ]) { //Fixed
117
- if ($ price_with_tax < $ prod_adv ['value ' ]) {
118
- $ adv_amount = $ totalPriceByProductTaxIncl ;
119
- } else {
120
- $ adv_amount = $ prod_adv ['value ' ] * $ productCartQuantity ;
121
- }
134
+ if ($ prodRawPriceTE < $ prodAdvPayInfo ['value ' ]) {
135
+ $ advPaymentAmount = $ prodRawPriceTE * $ productCartQuantity ;
122
136
} else {
123
- if ($ price_without_tax < $ prod_adv ['value ' ]) {
124
- $ adv_amount = $ price_without_tax * $ productCartQuantity ;
125
- } else {
126
- $ adv_amount = $ prod_adv ['value ' ] * $ productCartQuantity ;
127
- }
137
+ $ advPaymentAmount = $ prodAdvPayInfo ['value ' ] * $ productCartQuantity ;
128
138
}
129
- if ($ with_taxes ) {
130
- if ($ price_without_tax ) {
131
- $ taxRate = (($ price_with_tax -$ price_without_tax )/$ price_without_tax )*100 ;
132
- } else {
133
- $ taxRate = 0 ;
134
- }
135
- $ taxRate = HotelRoomType::getRoomTypeTaxRate ($ id_product );
136
- $ taxPrice = ($ adv_amount * $ taxRate ) / 100 ;
137
- $ adv_amount += $ taxPrice ;
139
+ }
140
+
141
+ // add taxes to the advance room type price
142
+ if ($ withTaxes && $ prodAdvPayInfo ['tax_include ' ]) {
143
+ if ($ prodRawPriceTE ) {
144
+ $ taxRate = (($ prodRawPriceTI - $ prodRawPriceTE ) / $ prodRawPriceTE ) * 100 ;
145
+ } else {
146
+ $ taxRate = 0 ;
138
147
}
148
+ $ taxRate = HotelRoomType::getRoomTypeTaxRate ($ idProduct );
149
+ $ taxPrice = ($ advPaymentAmount * $ taxRate ) / 100 ;
150
+ $ advPaymentAmount += $ taxPrice ;
139
151
}
140
152
} else { // Advanced payment is calculated by Global advanced payment setting
141
- if ($ adv_global_tax_incl && $ with_taxes ) {
142
- $ adv_amount = ($ totalPriceByProductTaxIncl * $ adv_global_percent )/ 100 ;
153
+ if ($ advGlobalTaxIncl && $ withTaxes ) {
154
+ $ advPaymentAmount = ($ roomTypeTotalTI * $ advGlobalPercent ) / 100 ;
143
155
} else {
144
- $ adv_amount = ($ totalPriceByProductTaxExcl * $ adv_global_percent )/ 100 ;
156
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ advGlobalPercent ) / 100 ;
145
157
}
146
158
}
147
- } else {
148
- $ prod_price = $ totalPriceByProductTaxIncl ;
149
- $ adv_amount = $ prod_price ;
159
+ } else { // if advance payment is disabled for this room type then send the room type full price
160
+ if ($ withTaxes ) {
161
+ $ advPaymentAmount = $ roomTypeTotalTI ;
162
+ } else {
163
+ $ advPaymentAmount = $ roomTypeTotalTE ;
164
+ }
150
165
}
151
- } else {
152
- if ($ adv_global_tax_incl && $ with_taxes ) {
153
- $ adv_amount = ($ totalPriceByProductTaxIncl * $ adv_global_percent )/ 100 ;
166
+ } else { // if no advance payment info for the room type the calculate from Global settings
167
+ if ($ withTaxes && $ advGlobalTaxIncl ) {
168
+ $ advPaymentAmount = ($ roomTypeTotalTI * $ advGlobalPercent ) / 100 ;
154
169
} else {
155
- $ adv_amount = ($ totalPriceByProductTaxExcl * $ adv_global_percent )/ 100 ;
170
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ advGlobalPercent ) / 100 ;
156
171
}
157
172
}
158
173
159
- return $ adv_amount ;
174
+ return $ advPaymentAmount ;
160
175
}
161
176
162
-
163
177
/**
164
178
* [getProductMinAdvPaymentAmount :: To get minimum advance payment amount paid by the customer for a particular product for a given quantities product]
165
179
* @param [int] $id_product [ID of the product which minimum advance payment amount paid by the customer for given quantities you want]
@@ -297,74 +311,86 @@ public function _checkFreeAdvancePaymentOrder()
297
311
return false ;
298
312
}
299
313
300
- public function getRoomMinAdvPaymentAmount ($ id_product , $ date_from , $ date_to )
314
+ /**
315
+ * Get the advance payment amount of the room type booking in the cart
316
+ * @param [int] $idProduct : id_product of room type
317
+ * * @param [date] $dateFrom : date from of the booking
318
+ * * @param [date] $dateFrom : date to of the booking
319
+ * @param integer $withTaxes : Amount with(1) or without tax (0)
320
+ * @return [float] advance payment amount of the room type in the cart
321
+ */
322
+ public function getRoomMinAdvPaymentAmount ($ idProduct , $ dateFrom , $ dateTo , $ withTaxes = 1 )
301
323
{
302
- $ date_from = date ('Y-m-d ' , strtotime ($ date_from ));
303
- $ date_to = date ('Y-m-d ' , strtotime ($ date_to ));
304
- $ adv_global_percent = Configuration::get ('WK_ADVANCED_PAYMENT_GLOBAL_MIN_AMOUNT ' );
305
- $ adv_global_tax_incl = Configuration::get ('WK_ADVANCED_PAYMENT_INC_TAX ' );
324
+ $ dateFrom = date ('Y-m-d ' , strtotime ($ dateFrom ));
325
+ $ dateTo = date ('Y-m-d ' , strtotime ($ dateTo ));
326
+
327
+ // Advance payment information from global settings
328
+ $ advGlobalPercent = Configuration::get ('WK_ADVANCED_PAYMENT_GLOBAL_MIN_AMOUNT ' );
329
+ $ advGlobalTaxIncl = Configuration::get ('WK_ADVANCED_PAYMENT_INC_TAX ' );
330
+
331
+ $ roomTotalPrices = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice ($ idProduct , $ dateFrom , $ dateTo );
332
+ $ roomTypeTotalTI = $ roomTotalPrices ['total_price_tax_incl ' ];
333
+ $ roomTypeTotalTE = $ roomTotalPrices ['total_price_tax_excl ' ];
334
+
335
+ $ advPaymentAmount = 0 ;
336
+ if ($ prodAdvPayInfo = $ this ->getIdAdvPaymentByIdProduct ($ idProduct )) {
337
+ if ($ prodAdvPayInfo ['active ' ]) {
338
+ // Advanced payment is calculated by product advanced payment setting
339
+ if ($ prodAdvPayInfo ['calculate_from ' ]) {
340
+ // room type original prices
341
+ $ prodRawPriceTI = Product::getPriceStatic ($ idProduct , true , null , 6 , null , false , true );
342
+ $ prodRawPriceTE = Product::getPriceStatic ($ idProduct , false , null , 6 , null , false , true );
343
+
344
+ if ($ prodAdvPayInfo ['payment_type ' ] == self ::WK_ADVANCE_PAYMENT_TYPE_PERCENTAGE ) { // Percentage
345
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ prodAdvPayInfo ['value ' ]) / 100 ;
346
+ } else {
347
+ $ prodAdvPayInfo ['value ' ] = Tools::convertPrice ($ prodAdvPayInfo ['value ' ]);
306
348
307
- $ price_with_tax = Product::getPriceStatic ($ id_product , true , null , 6 , null , false , true );
308
- $ price_without_tax = Product::getPriceStatic ($ id_product , false , null , 6 , null , false , true );
309
- $ hotelCartBookingData = new HotelCartBookingData ();
310
- $ productCartQuantity = 0 ;
311
- $ roomTotalPrice = HotelRoomTypeFeaturePricing::getRoomTypeTotalPrice ($ id_product , $ date_from , $ date_to );
312
- $ totalPriceByProductTaxIncl = $ roomTotalPrice ['total_price_tax_incl ' ];
313
- $ totalPriceByProductTaxExcl = $ roomTotalPrice ['total_price_tax_excl ' ];
314
- $ obj_booking_detail = new HotelBookingDetail ();
315
- $ productCartQuantity = $ obj_booking_detail ->getNumberOfDays ($ date_from , $ date_to );
349
+ $ numdays = 0 ;
350
+ $ objBookingDtl = new HotelBookingDetail ();
351
+ $ numdays = $ objBookingDtl ->getNumberOfDays ($ dateFrom , $ dateTo );
316
352
317
- $ prod_adv = $ this ->getIdAdvPaymentByIdProduct ($ id_product );
318
- if ($ prod_adv ) {
319
- if ($ prod_adv ['active ' ]) {
320
- if ($ prod_adv ['calculate_from ' ]) { // Advanced payment is calculated by product advanced payment setting
321
- if ($ prod_adv ['payment_type ' ] == 1 ) { // Percentage
322
- if ($ prod_adv ['tax_include ' ]) {
323
- $ prod_price = $ totalPriceByProductTaxIncl ;
353
+ if ($ prodRawPriceTE < $ prodAdvPayInfo ['value ' ]) {
354
+ $ advPaymentAmount = $ prodRawPriceTE * $ numdays ;
324
355
} else {
325
- $ prod_price = $ totalPriceByProductTaxExcl ;
356
+ $ advPaymentAmount = $ prodAdvPayInfo [ ' value ' ] * $ numdays ;
326
357
}
327
- $ adv_amount = ($ prod_price * $ prod_adv ['value ' ]) / 100 ;
328
- } else {
329
- $ prod_adv ['value ' ] = Tools::convertPrice ($ prod_adv ['value ' ]);
358
+ }
330
359
331
- if ($ prod_adv ['tax_include ' ]) { //Fixed
332
- if ($ price_with_tax < $ prod_adv ['value ' ]) {
333
- $ adv_amount = $ totalPriceByProductTaxIncl ;
334
- } else {
335
- $ adv_amount = $ prod_adv ['value ' ] * $ productCartQuantity ;
336
- }
360
+ // add taxes to the advance room type price
361
+ if ($ withTaxes && $ prodAdvPayInfo ['tax_include ' ]) {
362
+ if ($ prodRawPriceTE ) {
363
+ $ taxRate = (($ prodRawPriceTI - $ prodRawPriceTE ) / $ prodRawPriceTE ) * 100 ;
337
364
} else {
338
- if ($ price_without_tax < $ prod_adv ['value ' ]) {
339
- $ adv_amount = $ price_without_tax * $ productCartQuantity ;
340
- } else {
341
- $ adv_amount = $ prod_adv ['value ' ] * $ productCartQuantity ;
342
- }
365
+ $ taxRate = 0 ;
343
366
}
367
+ $ taxRate = HotelRoomType::getRoomTypeTaxRate ($ idProduct );
368
+ $ taxPrice = ($ advPaymentAmount * $ taxRate ) / 100 ;
369
+ $ advPaymentAmount += $ taxPrice ;
344
370
}
345
371
} else { // Advanced payment is calculated by Global advanced payment setting
346
- if ($ adv_global_tax_incl ) {
347
- $ adv_amount = ($ totalPriceByProductTaxIncl * $ adv_global_percent ) / 100 ;
372
+ if ($ advGlobalTaxIncl && $ withTaxes ) {
373
+ $ advPaymentAmount = ($ roomTypeTotalTI * $ advGlobalPercent ) / 100 ;
348
374
} else {
349
- $ adv_amount = ($ totalPriceByProductTaxExcl * $ adv_global_percent ) / 100 ;
375
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ advGlobalPercent ) / 100 ;
350
376
}
351
377
}
352
- } else {
353
- if ($ with_taxes ) {
354
- $ adv_amount = $ totalPriceByProductTaxIncl ;
378
+ } else { // if advance payment is disabled for this room type then send the room type full price
379
+ if ($ withTaxes ) {
380
+ $ advPaymentAmount = $ roomTypeTotalTI ;
355
381
} else {
356
- $ adv_amount = $ totalPriceByProductTaxExcl ;
382
+ $ advPaymentAmount = $ roomTypeTotalTE ;
357
383
}
358
384
}
359
- } else {
360
- if ($ adv_global_tax_incl ) {
361
- $ adv_amount = ($ totalPriceByProductTaxIncl * $ adv_global_percent ) / 100 ;
385
+ } else { // if no advance payment info for the room type the calculate from Global settings
386
+ if ($ withTaxes && $ advGlobalTaxIncl ) {
387
+ $ advPaymentAmount = ($ roomTypeTotalTI * $ advGlobalPercent ) / 100 ;
362
388
} else {
363
- $ adv_amount = ($ totalPriceByProductTaxExcl * $ adv_global_percent ) / 100 ;
389
+ $ advPaymentAmount = ($ roomTypeTotalTE * $ advGlobalPercent ) / 100 ;
364
390
}
365
391
}
366
392
367
- return $ adv_amount ;
393
+ return $ advPaymentAmount ;
368
394
}
369
395
370
396
// check if advance payment is available for the current cart
0 commit comments