Index: admin_templates/orders/orders_edit_billing.tpl
===================================================================
--- admin_templates/orders/orders_edit_billing.tpl (revision 14879)
+++ admin_templates/orders/orders_edit_billing.tpl (working copy)
@@ -104,6 +104,7 @@
<inp2:m_RenderElement name="inp_edit_checkbox" prefix="ord" field="IsRecurringBilling" title="la_fld_IsRecurringBilling"/>
<inp2:m_RenderElement name="inp_edit_date_time" prefix="ord" field="NextCharge" title="la_fld_NextCharge"/>
+ <inp2:m_RenderElement name="inp_edit_checkbox" prefix="ord" field="VATIncluded" title="la_fld_VATIncluded"/>
<!--<inp2:m_RenderElement name="inp_gwresults" prefix="ord" display_field="score" field="VerificationResult" title="la_fld_VerificationResult" />-->
@@ -152,6 +153,7 @@
<inp2:m_RenderElement name="inp_edit_checkbox" prefix="ord" field="IsRecurringBilling" title="la_fld_IsRecurringBilling"/>
<inp2:m_RenderElement name="inp_edit_date_time" prefix="ord" field="NextCharge" title="la_fld_NextCharge"/>
+ <inp2:m_RenderElement name="inp_label" prefix="ord" field="VATIncluded" title="la_fld_VATIncluded"/>
<inp2:m_RenderElement name="inp_gwresults" prefix="ord" field="VerificationResult" display_field="score" title="la_fld_VerificationResult" />
Index: install/english.lang
===================================================================
--- install/english.lang (revision 14879)
+++ install/english.lang (working copy)
@@ -130,6 +130,7 @@
<PHRASE Label="la_comm_OrderContents" Module="In-Commerce" Type="1">T3JkZXIgQ29udGVudHM=</PHRASE>
<PHRASE Label="la_comm_ShippingBillingInfo" Module="In-Commerce" Type="1">U2hpcHBpbmcgJiBCaWxsaW5nIEluZm9ybWF0aW9u</PHRASE>
<PHRASE Label="la_comm_Timeframe" Module="In-Commerce" Type="1">VGltZWZyYW1l</PHRASE>
+ <PHRASE Label="la_config_OrderVATIncluded" Module="In-Commerce" Type="1">VkFUIEluY2x1ZGVk</PHRASE>
<PHRASE Label="la_config_ShowProductImagesInOrders" Module="In-Commerce" Type="1">U2hvdyBQcm9kdWN0IEltYWdlcyBpbiBPcmRlcnM=</PHRASE>
<PHRASE Label="la_conf_DaysToBeNew" Module="In-Commerce" Type="1">TnVtYmVyIG9mIGRheXMgZm9yIGEgcHJvZHVjdCB0byBiZSBOZXc=</PHRASE>
<PHRASE Label="la_conf_DefaultCouponDuration" Module="In-Commerce" Type="1">RGVmYXVsdCBjb3Vwb24gZHVyYXRpb24gKGRheXMp</PHRASE>
@@ -378,6 +379,7 @@
<PHRASE Label="la_fld_UnitsLimit" Module="In-Commerce" Type="1" Column="TGltaXQ=">TGluaXQ=</PHRASE>
<PHRASE Label="la_fld_UserComment" Module="In-Commerce" Type="1">VXNlciBDb21tZW50</PHRASE>
<PHRASE Label="la_fld_VAT" Module="In-Commerce" Type="1">U2FsZXMgVGF4L1ZBVA==</PHRASE>
+ <PHRASE Label="la_fld_VATIncluded" Module="In-Commerce" Type="1">VkFUIEluY2x1ZGVk</PHRASE>
<PHRASE Label="la_fld_VerificationResult" Module="In-Commerce" Type="1">VmVyaWZpY2F0aW9uIFJlc3VsdA==</PHRASE>
<PHRASE Label="la_fld_Weight" Module="In-Commerce" Type="1" Column="V2VpZ2h0">V2VpZ2h0</PHRASE>
<PHRASE Label="la_fld_WeightType" Module="In-Commerce" Type="1">V2VpZ2h0IE1vZGlmaWVyIFR5cGU=</PHRASE>
Index: install/install_data.sql
===================================================================
--- install/install_data.sql (revision 14879)
+++ install/install_data.sql (working copy)
@@ -31,6 +31,7 @@
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'Comm_AutoProcessRecurringOrders', '1', 'In-Commerce', 'in-commerce:general', 'la_Text_Orders', 'la_AutoProcessRecurringOrders', 'checkbox', NULL, NULL, 10.09, 0, 0, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'MaxAddresses', '0', 'In-Commerce', 'in-commerce:general', 'la_Text_Orders', 'la_MaxAddresses', 'text', NULL, NULL, 10.1, 0, 0, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'Comm_MaskProcessedCreditCards', '0', 'In-Commerce', 'in-commerce:general', 'la_Text_Orders', 'la_MaskProcessedCreditCards', 'checkbox', NULL, NULL, 10.11, 0, 0, NULL);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'OrderVATIncluded', '0', 'In-Commerce', 'in-commerce:general', 'la_Text_Orders', 'la_config_OrderVATIncluded', 'checkbox', NULL, NULL, 10.12, '0', '0', NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'Comm_AllowOrderingInNonPrimaryCurrency', '1', 'In-Commerce', 'in-commerce:general', 'la_Text_Currencies', 'la_AllowOrderingInNonPrimaryCurrency', 'checkbox', NULL, NULL, 20.01, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'Comm_ExchangeRateSource', '3', 'In-Commerce', 'in-commerce:general', 'la_Text_Currencies', 'la_ExchangeRateSource', 'select', NULL, '2=la_FederalReserveBank||3=la_EuropeanCentralBank||1=la_BankOfLatvia', 20.02, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'Comm_DefaultCouponDuration', '14', 'In-Commerce', 'in-commerce:general', 'la_Text_Coupons', 'la_conf_DefaultCouponDuration', 'text', NULL, NULL, 30.01, 0, 1, NULL);
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 14879)
+++ install/install_schema.sql (working copy)
@@ -194,6 +194,7 @@
GiftCertificateId int(11) DEFAULT NULL,
GiftCertificateDiscount decimal(20,4) NOT NULL DEFAULT '0.0000',
GoogleOrderNumber bigint(20) unsigned DEFAULT NULL,
+ VATIncluded tinyint(1) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (OrderId),
KEY AffiliateId (AffiliateId),
KEY VisitId (VisitId),
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 14879)
+++ install/upgrades.sql (working copy)
@@ -229,4 +229,6 @@
SET DisplayName = REPLACE(DisplayName, 'lu_', 'lc_')
WHERE DisplayName IN (
'lu_field_descriptionex', 'lu_field_manufacturer', 'lu_field_qtysold', 'lu_field_topseller'
-);
\ No newline at end of file
+);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'OrderVATIncluded', '0', 'In-Commerce', 'in-commerce:general', 'la_Text_Orders', 'la_config_OrderVATIncluded', 'checkbox', NULL, NULL, 10.12, '0', '0', NULL);
+ALTER TABLE Orders ADD VATIncluded TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
\ No newline at end of file
Index: units/orders/orders_config.php
===================================================================
--- units/orders/orders_config.php (revision 14879)
+++ units/orders/orders_config.php (working copy)
@@ -255,8 +255,8 @@
'OrderNumber' => 'CONCAT(LPAD(Number,6,"0"),\'-\',LPAD(SubNumber,3,"0") )',
'SubtotalWithoutDiscount' => '(SubTotal + DiscountTotal)',
'SubtotalWithDiscount' => '(SubTotal)',
- 'AmountWithoutVAT' => '(SubTotal+IF(ShippingTaxable=1, ShippingCost, 0)+IF(ProcessingTaxable=1, ProcessingFee, 0))',
- 'TotalAmount' => 'SubTotal+ShippingCost+VAT+ProcessingFee+InsuranceFee-GiftCertificateDiscount',
+ 'AmountWithoutVAT' => '(SubTotal+IF(ShippingTaxable=1, ShippingCost, 0)+IF(ProcessingTaxable=1, ProcessingFee, 0)-IF(VATIncluded=1,VAT,0))',
+ 'TotalAmount' => 'SubTotal+ShippingCost+IF(VATIncluded=1,0,VAT)+ProcessingFee+InsuranceFee-GiftCertificateDiscount',
'CouponCode' => 'pc.Code',
'CouponName' => 'pc.Name',
'AffiliateUser' => 'IF( LENGTH(au.Username),au.Username,\'!la_None!\')',
@@ -270,8 +270,8 @@
'OrderNumber' => 'CONCAT(LPAD(Number,6,"0"),\'-\',LPAD(SubNumber,3,"0") )',
'SubtotalWithoutDiscount' => '(SubTotal + DiscountTotal)',
'SubtotalWithDiscount' => '(SubTotal)',
- 'AmountWithoutVAT' => '(SubTotal+IF(ShippingTaxable=1, ShippingCost, 0)+IF(ProcessingTaxable=1, ProcessingFee, 0))',
- 'TotalAmount' => 'SubTotal+ShippingCost+VAT+ProcessingFee+InsuranceFee-GiftCertificateDiscount',
+ 'AmountWithoutVAT' => '(SubTotal+IF(ShippingTaxable=1, ShippingCost, 0)+IF(ProcessingTaxable=1, ProcessingFee, 0)-IF(VATIncluded=1,VAT,0))',
+ 'TotalAmount' => 'SubTotal+ShippingCost+IF(VATIncluded=1,0,VAT)+ProcessingFee+InsuranceFee-GiftCertificateDiscount',
/*'ItemsCount' => 'COUNT(%1$s.OrderId)',*/
'ShippingSubTotal' => '%1$s.ShippingCost + %1$s.InsuranceFee',
),
@@ -359,6 +359,12 @@
),
'VAT' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'not_null' =>1, 'default' => '0', 'format' => '%01.2f'),
'VATPercent' => Array ('type' => 'float', 'formatter' => 'kFormatter', 'not_null' =>1, 'default' => '0', 'format' => '%01.3f'),
+ 'VATIncluded' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter',
+ 'options' => Array (0 => 'la_No', 1 => 'la_Yes'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0,
+ ),
'PaymentType' => Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter',
Index: units/orders/orders_event_handler.php
===================================================================
--- units/orders/orders_event_handler.php (revision 14879)
+++ units/orders/orders_event_handler.php (working copy)
@@ -3089,6 +3089,10 @@
return;
}
+ if (!$this->Application->isAdminUser) {
+ $order->SetDBField('VATIncluded', $this->Application->ConfigValue('OrderVATIncluded'));
+ }
+
$manager =& $this->Application->recallObject('OrderManager');
/* @var $manager OrderManager */
Index: units/orders/orders_item.php
===================================================================
--- units/orders/orders_item.php (revision 14879)
+++ units/orders/orders_item.php (working copy)
@@ -157,17 +157,25 @@
$this->SetDBField( 'ProcessingTaxable', $tax['ApplyToProcessing']);
$this->UpdateTotals();
- $subtotal = $this->GetDBField('AmountWithoutVAT');
+ if (!$this->GetDBField('VATIncluded')) {
+ $subtotal = $this->GetDBField('AmountWithoutVAT');
+ $tax_exempt = $this->getTaxExempt();
+
+ if ($tax_exempt) $subtotal -= $tax_exempt;
+
+ $this->SetDBField( 'VAT', round($subtotal * $tax['TaxValue'] / 100, 2) );
+ $this->UpdateTotals();
+ }
+ }
+
+ function getTaxExempt()
+ {
$query = 'SELECT SUM(Quantity * Price) FROM '.TABLE_PREFIX.'OrderItems AS oi
LEFT JOIN '.TABLE_PREFIX.'Products AS p
ON p.ProductId = oi.ProductId
WHERE p.Type = 6 AND oi.OrderId = '.$this->GetDBField('OrderId');
- $tax_exempt = $this->Conn->GetOne($query);
- if ($tax_exempt) $subtotal -= $tax_exempt;
-
- $this->SetDBField( 'VAT', round($subtotal * $tax['TaxValue'] / 100, 2) );
- $this->UpdateTotals();
+ return $this->Conn->GetOne($query);
}
function UpdateTotals()
@@ -176,10 +184,18 @@
$total += $this->GetDBField('SubTotal');
if ($this->GetDBField('ShippingTaxable')) $total += $this->GetDBField('ShippingCost');
if ($this->GetDBField('ProcessingTaxable')) $total += $this->GetDBField('ProcessingFee');
- $this->SetDBField('AmountWithoutVAT', $total);
- $total += $this->GetDBField('VAT');
+ if ($this->GetDBField('VATIncluded')) {
+ $tax_exempt = $this->getTaxExempt();
+ $vat_percent = $this->GetDBField( 'VATPercent');
+ $this->SetDBField('VAT', round(($total - $tax_exempt) * $vat_percent / (100 + $vat_percent), 2));
+ $this->SetDBField('AmountWithoutVAT', $total - $this->GetDBField('VAT'));
+ } else {
+ $this->SetDBField('AmountWithoutVAT', $total);
+ $total += $this->GetDBField('VAT');
+ }
+
if (!$this->GetDBField('ShippingTaxable')) $total += $this->GetDBField('ShippingCost');
if (!$this->GetDBField('ProcessingTaxable')) $total += $this->GetDBField('ProcessingFee');
@@ -192,7 +208,7 @@
{
return $this->GetDBField('SubTotal') +
$this->GetDBField('ShippingCost') +
- $this->GetDBField('VAT') +
+ ($this->GetDBField('VATIncluded') ? 0 : $this->GetDBField('VAT')) +
$this->GetDBField('ProcessingFee') +
$this->GetDBField('InsuranceFee') -
$this->GetDBField('GiftCertificateDiscount');
Index: units/orders/orders_tag_processor.php
===================================================================
--- units/orders/orders_tag_processor.php (revision 14879)
+++ units/orders/orders_tag_processor.php (working copy)
@@ -239,7 +239,7 @@
$oi_table = $this->Application->getUnitOption('orditems', 'TableName');
if ( $object->IsTempTable() ) {
- $oi_table = $this->Application->GetTempName($oi_table, 'prefix' . $object->Prefix);
+ $oi_table = $this->Application->GetTempName($oi_table, 'prefix:' . $object->Prefix);
}
list ($split_shipments, $limit_types) = $this->GetShippingLimitations($ord_id);