Merge branch 'develop' into gli-1471

This commit is contained in:
Abhishek Kumar
2024-03-17 15:46:22 +05:30
496 changed files with 14988 additions and 11714 deletions

View File

@@ -181,9 +181,6 @@ abstract class PaymentModuleCore extends Module
ShopUrl::resetMainDomainCache();
$id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency;
$this->context->currency = new Currency((int)$id_currency, null, (int)$this->context->shop->id);
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$context_country = $this->context->country;
}
$order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id);
if (!Validate::isLoadedObject($order_status)) {
@@ -274,14 +271,6 @@ abstract class PaymentModuleCore extends Module
$order = new Order();
$order->product_list = $package['product_list'];
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$address = new Address((int)$id_address);
$this->context->country = new Country((int)$address->id_country, (int)$this->context->cart->id_lang);
if (!$this->context->country->active) {
throw new PrestaShopException('The delivery address country is not active.');
}
}
$carrier = null;
if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) {
$carrier = new Carrier((int)$package['id_carrier'], (int)$this->context->cart->id_lang);
@@ -464,15 +453,6 @@ abstract class PaymentModuleCore extends Module
}
}
// The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$this->context->country = $context_country;
}
if (!$this->context->country->active) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int)$id_cart, true);
throw new PrestaShopException('The order address country is not active.');
}
if (self::DEBUG_MODE) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int)$id_cart, true);
@@ -665,9 +645,13 @@ abstract class PaymentModuleCore extends Module
unset($voucher->id);
// Set a new voucher code
// For a customer, applying voucher ABCD will create partial vouchers ABCD-2, ABCD-3 and so on, and
// applying voucher ABCD-2 will create vouchers ABCD-2-2, ABCD-2-3 and so on
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule['obj']->id), 0, 16) : $voucher->code.'-2';
if (preg_match('/\-([0-9]{1,2})\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) {
$voucher->code = preg_replace('/'.$matches[0].'$/', '-'.(intval($matches[1]) + 1), $voucher->code);
while (CartRule::cartRuleExists($voucher->code, $order->id_customer)) {
if (preg_match('/\-([0-9]{1,2})$/', $voucher->code, $matches)) {
$voucher->code = preg_replace('/'.$matches[1].'$/', (intval($matches[1]) + 1), $voucher->code);
}
}
// Set the new voucher value
@@ -863,7 +847,11 @@ abstract class PaymentModuleCore extends Module
$objBookingDetail->total_paid_amount = $objAdvancedPayment->getRoomMinAdvPaymentAmount(
$idProduct,
$objCartBookingData->date_from,
$objCartBookingData->date_to
$objCartBookingData->date_to,
1,
$objCartBookingData->id_room,
$objCartBookingData->id_cart,
$objCartBookingData->id_guest
);
}
}
@@ -921,7 +909,6 @@ abstract class PaymentModuleCore extends Module
$objBookingDemand->tax_computation_method = (int)$taxCalc->computation_method;
if ($objBookingDemand->save()) {
$objBookingDemand->tax_calculator = $taxCalc;
$objBookingDemand->id_global_demand = $idGlobalDemand;
// Now save tax details of the extra demand
$objBookingDemand->setBookingDemandTaxDetails();
}
@@ -1006,11 +993,9 @@ abstract class PaymentModuleCore extends Module
// Set the order status
$new_history = new OrderHistory();
$new_history->id_order = (int)$order->id;
if ($order_status->logable && $order->is_advance_payment && $order->advance_paid_amount < $order->total_paid_tax_incl) {
$new_history->changeIdOrderState((int)Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED'), $order, true);
} else {
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
}
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
$new_history->addWithemail(true, $extra_vars);
// Switch to back order if needed
@@ -1045,47 +1030,19 @@ abstract class PaymentModuleCore extends Module
$normal_products_data_txt = $this->getEmailTemplateContent('hotel-service-product-data-text.tpl', Mail::TYPE_TEXT, $orderServiceProducts);
// total room price
$room_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, true);
$room_price_tax_incl = $order->getTotalProductsWithTaxes(false, true);
$room_tax = ($order->getTotalProductsWithTaxes(false, true) - $order->getTotalProductsWithoutTaxes(false, true));
$room_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, true) + $order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM);
$room_price_tax_incl = $order->getTotalProductsWithTaxes(false, true) + $order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM);
$room_tax = ($room_price_tax_incl - $room_price_tax_excl);
// extra services
$additional_service_price_tax_excl = ($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $cart_booking_data['total_extra_demands_te']);
$additional_service_price_tax_incl = ($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $cart_booking_data['total_extra_demands_ti']);
$additional_service_tax = (($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $cart_booking_data['total_extra_demands_ti']) - ($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE) + $cart_booking_data['total_extra_demands_te']));
$additional_service_price_tax_excl = ($order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $cart_booking_data['total_extra_demands_te']);
$additional_service_price_tax_incl = ($order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 0) + $cart_booking_data['total_extra_demands_ti']);
$additional_service_tax = ($additional_service_price_tax_incl - $additional_service_price_tax_excl);
// convenience fee price
$objRoomTypeServiceProductOrderDetail = new RoomTypeServiceProductOrderDetail();
$total_convenience_fee_ti = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$order->id,
0,
0,
0,
0,
0,
0,
1,
1,
1,
Product::PRICE_ADDITION_TYPE_INDEPENDENT
);
$total_convenience_fee_te = $objRoomTypeServiceProductOrderDetail->getroomTypeServiceProducts(
$order->id,
0,
0,
0,
0,
0,
0,
1,
0,
1,
Product::PRICE_ADDITION_TYPE_INDEPENDENT
);
$additional_service_price_tax_excl = $additional_service_price_tax_excl - $total_convenience_fee_te;
$additional_service_price_tax_incl = $additional_service_price_tax_incl - $total_convenience_fee_ti;
$room_price_tax_excl = $room_price_tax_excl + $additional_service_price_tax_excl;
$room_price_tax_incl = $room_price_tax_incl + $additional_service_price_tax_incl;
$total_convenience_fee_ti = $order->getTotalProductsWithTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
$total_convenience_fee_te = $order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITH_ROOMTYPE, 1, Product::PRICE_ADDITION_TYPE_INDEPENDENT);
// service products
// $service_products_price_tax_excl = $order->getTotalProductsWithoutTaxes(false, false, Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE);
@@ -1238,25 +1195,27 @@ abstract class PaymentModuleCore extends Module
}
if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN')){
// send superadmin information
if (Validate::isLoadedObject($superAdmin = new Employee(_PS_ADMIN_PROFILE_))) {
if (Validate::isEmail($superAdmin->email)) {
$data['{customer_name}'] = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$data['{customer_email}'] = $this->context->customer->email;
$data['{firstname}'] = $superAdmin->firstname;
$data['{lastname}'] = $superAdmin->lastname;
$data['{email}'] = $superAdmin->email;
Mail::Send(
(int)$order->id_lang,
'order_conf_admin',
Mail::l('Order confirmation', (int)$order->id_lang),
$data,
$superAdmin->email,
$superAdmin->firstname.' '.$superAdmin->lastname,
null,
null,
$file_attachement,
null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);
if ($superAdminEmployees = Employee::getEmployeesByProfile(_PS_ADMIN_PROFILE_, true)) {
foreach ($superAdminEmployees as $superAdminEmployee) {
if (Validate::isEmail($superAdminEmployee['email'])) {
$data['{customer_name}'] = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$data['{customer_email}'] = $this->context->customer->email;
$data['{firstname}'] = $superAdminEmployee['firstname'];
$data['{lastname}'] = $superAdminEmployee['lastname'];
$data['{email}'] = $superAdminEmployee['email'];
Mail::Send(
(int)$order->id_lang,
'order_conf_admin',
Mail::l('Order confirmation', (int)$order->id_lang),
$data,
$superAdminEmployee['email'],
$superAdminEmployee['firstname'].' '.$superAdminEmployee['lastname'],
null,
null,
$file_attachement,
null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);
}
}
}
}
@@ -1290,7 +1249,7 @@ abstract class PaymentModuleCore extends Module
$data['{customer_name}'] = $this->context->customer->firstname.' '.$this->context->customer->lastname;
$data['{customer_email}'] = $this->context->customer->email;
foreach ($htlAccesses as $access) {
if ($access['id_profile'] != _PS_ADMIN_PROFILE_) {
if ($access['access'] && $access['id_profile'] != _PS_ADMIN_PROFILE_) {
if ($htlEmployees = Employee::getEmployeesByProfile($access['id_profile'])) {
foreach ($htlEmployees as $empl) {
if (Validate::isEmail($empl['email'])) {
@@ -1660,8 +1619,11 @@ abstract class PaymentModuleCore extends Module
);
$cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] += ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] += ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['amount_tax_incl'] += ($data_v['total_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['amount_tax_excl'] += ($data_v['total_price_tax_excl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
} else {
$num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']);
@@ -1763,8 +1725,11 @@ abstract class PaymentModuleCore extends Module
);
$cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] = $data_v['total_price_tax_incl']/$num_days;
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = ($data_v['total_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] = $data_v['total_price_tax_excl']/$num_days;
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_incl'] = ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['avg_paid_unit_price_tax_excl'] = ($cart_htl_data[$type_key]['date_diff'][$date_join]['paid_unit_price_tax_excl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['amount_tax_incl'] = ($data_v['total_price_tax_incl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_ti']);
$cart_htl_data[$type_key]['date_diff'][$date_join]['amount_tax_excl'] = ($data_v['total_price_tax_excl'] + $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_auto_add_te']);
$result['total_extra_demands_te'] += $cart_htl_data[$type_key]['date_diff'][$date_join]['extra_demands_price_te'];
$result['total_extra_demands_ti'] += $cart_htl_data[$type_key]['date_diff'][$date_join]['extra_demands_price_ti'];
@@ -1772,10 +1737,10 @@ abstract class PaymentModuleCore extends Module
$result['total_additional_services_ti'] += $cart_htl_data[$type_key]['date_diff'][$date_join]['additional_services_price_ti'];
}
}
}
// calculate averages now
foreach ($cart_htl_data[$type_key]['date_diff'] as $key => &$value) {
$value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6);
// calculate averages now
foreach ($cart_htl_data[$type_key]['date_diff'] as $key => &$value) {
$value['avg_paid_unit_price_tax_incl'] = Tools::ps_round($value['avg_paid_unit_price_tax_incl'] / $value['num_rm'], 6);
}
}
}
}