Index: branches/5.2.x/install/install_schema.sql =================================================================== diff -u -N -r14582 -r14884 --- branches/5.2.x/install/install_schema.sql (.../install_schema.sql) (revision 14582) +++ branches/5.2.x/install/install_schema.sql (.../install_schema.sql) (revision 14884) @@ -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: branches/5.2.x/install/upgrades.sql =================================================================== diff -u -N -r14742 -r14884 --- branches/5.2.x/install/upgrades.sql (.../upgrades.sql) (revision 14742) +++ branches/5.2.x/install/upgrades.sql (.../upgrades.sql) (revision 14884) @@ -229,4 +229,8 @@ 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: branches/5.2.x/units/orders/orders_config.php =================================================================== diff -u -N -r14846 -r14884 --- branches/5.2.x/units/orders/orders_config.php (.../orders_config.php) (revision 14846) +++ branches/5.2.x/units/orders/orders_config.php (.../orders_config.php) (revision 14884) @@ -1,6 +1,6 @@ '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: branches/5.2.x/units/orders/orders_item.php =================================================================== diff -u -N -r14812 -r14884 --- branches/5.2.x/units/orders/orders_item.php (.../orders_item.php) (revision 14812) +++ branches/5.2.x/units/orders/orders_item.php (.../orders_item.php) (revision 14884) @@ -1,6 +1,6 @@ GetFieldOptions('PaymentCCExpDate'); - if( $this->GetDirtyField($options['month_field']) || $this->GetDirtyField($options['year_field']) ) - { + + if ( $this->GetDirtyField($options['month_field']) || $this->GetDirtyField($options['year_field']) ) { $this->SetDirtyField('PaymentCCExpDate', 0); $this->SetField('PaymentCCExpDate', 0); } @@ -152,37 +163,74 @@ function RecalculateTax() { $tax = $this->getTaxPercent(); - $this->SetDBField( 'VATPercent', $tax['TaxValue'] ); - $this->SetDBField( 'ShippingTaxable', $tax['ApplyToShipping']); - $this->SetDBField( 'ProcessingTaxable', $tax['ApplyToProcessing']); + $this->SetDBField('VATPercent', $tax['TaxValue']); + $this->SetDBField('ShippingTaxable', $tax['ApplyToShipping']); + $this->SetDBField('ProcessingTaxable', $tax['ApplyToProcessing']); $this->UpdateTotals(); - $subtotal = $this->GetDBField('AmountWithoutVAT'); + if ( !$this->GetDBField('VATIncluded') ) { + $subtotal = $this->GetDBField('AmountWithoutVAT'); - $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; + $tax_exempt = $this->getTaxExempt(); - $this->SetDBField( 'VAT', round($subtotal * $tax['TaxValue'] / 100, 2) ); - $this->UpdateTotals(); + if ( $tax_exempt ) { + $subtotal -= $tax_exempt; + } + + $this->SetDBField('VAT', round($subtotal * $tax['TaxValue'] / 100, 2)); + $this->UpdateTotals(); + } } + /** + * Returns order amount, that is excluded from tax calculations + * + * @return float + * @access protected + */ + protected function getTaxExempt() + { + $sql = 'SELECT SUM(oi.Quantity * oi.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'); + + return $this->Conn->GetOne($sql); + } + function UpdateTotals() { $total = 0; $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('ShippingTaxable') ) { + $total += $this->GetDBField('ShippingCost'); + } - if (!$this->GetDBField('ShippingTaxable')) $total += $this->GetDBField('ShippingCost'); - if (!$this->GetDBField('ProcessingTaxable')) $total += $this->GetDBField('ProcessingFee'); + if ( $this->GetDBField('ProcessingTaxable') ) { + $total += $this->GetDBField('ProcessingFee'); + } + 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'); + } + $total += $this->GetDBField('InsuranceFee'); $this->SetDBField('TotalAmount', $total); @@ -192,7 +240,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: branches/5.2.x/admin_templates/orders/orders_edit_billing.tpl =================================================================== diff -u -N -r14569 -r14884 --- branches/5.2.x/admin_templates/orders/orders_edit_billing.tpl (.../orders_edit_billing.tpl) (revision 14569) +++ branches/5.2.x/admin_templates/orders/orders_edit_billing.tpl (.../orders_edit_billing.tpl) (revision 14884) @@ -104,6 +104,7 @@ + @@ -152,6 +153,7 @@ + Index: branches/5.2.x/units/orders/orders_event_handler.php =================================================================== diff -u -N -r14876 -r14884 --- branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14876) +++ branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14884) @@ -1,6 +1,6 @@ SetDBField('PaymentType', $default_type); } + // vat setting + $object->SetDBField('VATIncluded', $this->Application->ConfigValue('OrderVATIncluded')); + $created = $object->Create(); if ( $created ) { Index: branches/5.2.x/install/english.lang =================================================================== diff -u -N -r14742 -r14884 --- branches/5.2.x/install/english.lang (.../english.lang) (revision 14742) +++ branches/5.2.x/install/english.lang (.../english.lang) (revision 14884) @@ -130,6 +130,7 @@ T3JkZXIgQ29udGVudHM= U2hpcHBpbmcgJiBCaWxsaW5nIEluZm9ybWF0aW9u VGltZWZyYW1l + VGF4ZXMgaW5jbHVkZWQgaW4gcHJvZHVjdCBwcmljZSwgc2hpcHBpbmcgY29zdCAmIHByb2Nlc3NpbmcgZmVl U2hvdyBQcm9kdWN0IEltYWdlcyBpbiBPcmRlcnM= TnVtYmVyIG9mIGRheXMgZm9yIGEgcHJvZHVjdCB0byBiZSBOZXc= RGVmYXVsdCBjb3Vwb24gZHVyYXRpb24gKGRheXMp @@ -378,6 +379,7 @@ TGluaXQ= VXNlciBDb21tZW50 U2FsZXMgVGF4L1ZBVA== + VkFUIEluY2x1ZGVk VmVyaWZpY2F0aW9uIFJlc3VsdA== V2VpZ2h0 V2VpZ2h0IE1vZGlmaWVyIFR5cGU= @@ -953,4 +955,4 @@ U3ViamVjdDogR2lmdCBDZXJ0aWZpY2F0ZSAtIEVtYWlsIENvbmZpcm1hdGlvbgoKVGhpcyBpcyBhbiBlbWFpbCBjb25maXJtYXRpb24gdGhhdCBHaWZ0IENlcnRpZmljYXRlICI8aW5wMjptX3BhcmFtIG5hbWU9ImdpZmNlcnRfaWQiLz4iIGhhcyBiZWVuIHN1Y2Nlc3NmdWxseSBlbWFpbGVkIHRvIDxpbnAyOm1fcGFyYW0gbmFtZT0idG9fbmFtZSIvPiAoPGEgaHJlZj0ibWFpbHRvOjxpbnAyOm1fcGFyYW0gbmFtZT0idG9fZW1haWwiLz4iPjxpbnAyOm1fcGFyYW0gbmFtZT0idG9fZW1haWwiLz48L2E+KSAu - \ No newline at end of file + Index: branches/5.2.x/install/install_data.sql =================================================================== diff -u -N -r14742 -r14884 --- branches/5.2.x/install/install_data.sql (.../install_data.sql) (revision 14742) +++ branches/5.2.x/install/install_data.sql (.../install_data.sql) (revision 14884) @@ -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);