From: Janusz Dobrowolski Date: Tue, 16 Jul 2019 19:37:13 +0000 (+0200) Subject: New tax system - sales side X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=1c01c6f19f3a1410814abb63e4143d080373aaba New tax system - sales side --- diff --git a/includes/types.inc b/includes/types.inc index 212de03a..f83f2022 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -261,7 +261,7 @@ $vat_categories = array( VC_ASSETS => _('Fixed assets'), VC_NONDEDUCT => _('No VAT deductible'), VC_SERVICES => _('Other services'), -// VC_PARTIAL => _('VAT partially deductible'), + VC_PARTIAL => _('VAT partially deductible'), VC_REVERSE => _('Reverse charge'), ); diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index c303933f..fbf231f4 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -126,7 +126,7 @@ function write_grn(&$po) { /* This must be the first receipt of goods against this PO line. */ /* Store provisional cost used in GL posting - inventory is updated to actual cost later when invoice is received */ - $order_line->unit_cost = round2($order_line->taxfree_charge_value($po) / $po->ex_rate / $order_line->quantity, user_price_dec()); + $order_line->unit_cost = round2($order_line->taxfree_charge_value() / $po->ex_rate / $order_line->quantity, user_price_dec()); } //------------------- update average material cost and clearing account -------------------------------- @@ -152,7 +152,7 @@ function write_grn(&$po) $po->line_items[$line_no]->grn_item_id = $grn_item; /* Update location stock records - NB a po cannot be entered for a service/kit parts done automatically */ add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "", - $order_line->quantity, $order_line->unit_cost, $order_line->taxfree_charge_value($po)/$order_line->quantity); + $order_line->quantity, $order_line->unit_cost, $order_line->taxfree_charge_value()/$order_line->quantity); } /* quantity received is != 0 */ } diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index 22a9274b..df485f00 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -71,8 +71,11 @@ class purch_order function add_to_order($stock_id, $qty, $item_descr, $price, $req_del_date, $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=0, $po_item_id=0, $unit_cost=0) { - $this->line_items[] = new po_line_details($stock_id, $item_descr, $qty, $price, + $line = new po_line_details($stock_id, $item_descr, $qty, $price, $req_del_date, $qty_inv, $qty_recd, $qty_ordered, $grn_item_id, $po_item_id, $unit_cost); + + $this->line_items[] = $line; + $line->cart = $this; } function update_order_item($line_no, $qty, $price, $req_del_date, $description="") @@ -193,7 +196,7 @@ class purch_order { // split nominal line values foreach($this->line_items as $line) - $line->split_item_value($this); + $line->split_item_value(); // Exact tax values are currently entered as tax totals, so we need to move the differences back on line level. // currently first item with given tax type will be fixed with the calculated difference @@ -242,6 +245,7 @@ class po_line_details var $quantity; // this document line quantity //--- + var $cart; // line context var $descr_editable; var $vat_category; var $gl_amounts; // splited line value (after call to split_line_value method) @@ -275,20 +279,20 @@ class po_line_details // // GRN line tax free value. // - function taxfree_charge_value($po) + function taxfree_charge_value() { - return get_tax_free_price_for_item($po->trans_type, $this->stock_id, $this->quantity*$this->price, - $po->tax_group_id, $po->tax_included); + $this->split_item_value(); + return $this->gl_amounts['Net']; } /* Splits item value to parts posted to GL. */ - function split_item_value($cart) + function split_item_value() { $vat_factor = 1; - return $this->gl_amounts = split_item_price($this->stock_id, $this->price*$this->quantity, $cart->tax_group_id, $cart->tax_included, + return $this->gl_amounts = split_item_price($this->stock_id, $this->price*$this->quantity, $this->cart->tax_group_id, $this->cart->tax_included, ST_SUPPINVOICE, $vat_factor); } diff --git a/purchasing/includes/supp_trans_class.inc b/purchasing/includes/supp_trans_class.inc index 59d0e5c2..ddb55681 100644 --- a/purchasing/includes/supp_trans_class.inc +++ b/purchasing/includes/supp_trans_class.inc @@ -78,10 +78,12 @@ class supp_trans $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $std_cost_unit=null, $gl_code='') { - $this->grn_items[$grn_item_id] = new grn_item($grn_item_id, $po_detail_item, + $line = new grn_item($grn_item_id, $po_detail_item, $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $std_cost_unit, $gl_code, $this->tax_included); + $line->cart = $this; + $this->grn_items[$grn_item_id] = $line; $this->src_docs = find_src_invoices($this); unset($this->tax_overrides); // cancel tax overrides after cart change @@ -161,12 +163,12 @@ class supp_trans // // Returns total invoice amount without taxes. // - function get_total_taxfree($tax_group_id=null) + function get_total_taxfree() { $total = 0; foreach ($this->grn_items as $ln_itm) - $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $this->trans_type)), + $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price()), user_price_dec()); foreach ($this->gl_codes as $gl_line) @@ -203,7 +205,7 @@ class supp_trans { // split nominal line values foreach($this->grn_items as $line) - $line->split_item_value($this); + $line->split_item_value(); // Exact tax values are currently entered as tax totals, so we need to move the differences back on line level. // currently first item with given tax type will be fixed with the calculated difference @@ -257,6 +259,8 @@ all the info to do the necessary entries without looking up ie additional querie var $gl_amounts; // splited line value (after call to split_line_value method var $vat_category; + var $cart; // line context + function __construct($id, $po_detail_item, $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $std_cost_unit, $gl_code, $tax_included) @@ -285,22 +289,22 @@ all the info to do the necessary entries without looking up ie additional querie // $this->chg_price, $tax_group_id, $this->tax_included); // } - function taxfree_charge_price($tax_group_id, $trans_type=ST_PURCHORDER) + function taxfree_charge_price() { - return get_tax_free_price_for_item($trans_type, $this->item_code, $this->chg_price, - $tax_group_id, $this->tax_included); + $this->split_item_value(); + return $this->gl_amounts['Net']; } /* Splits item value to parts posted to GL. */ - function split_item_value($cart) + function split_item_value() { $vat_factor = 1; - return $this->gl_amounts = split_item_price($this->item_code, $this->chg_price*$this->this_quantity_inv, $cart->tax_group_id, $cart->tax_included, - ST_SUPPINVOICE, $vat_factor); + return $this->gl_amounts = split_item_price($this->item_code, $this->chg_price*$this->this_quantity_inv, $this->cart->tax_group_id, $this->cart->tax_included, + $this->cart->trans_type, $vat_factor); } } diff --git a/reporting/rep109.php b/reporting/rep109.php index e96af1d4..06aecf08 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -169,7 +169,7 @@ function print_sales_orders() } $tax_items = get_tax_for_items(ST_SALESINVOICE, $items, $prices, $myrow["freight_cost"], - $myrow['tax_group_id'], $myrow['tax_included'], null); + $myrow['tax_group_id'], $myrow['tax_included']); $first = true; foreach($tax_items as $tax_item) { diff --git a/reporting/rep111.php b/reporting/rep111.php index 23ccc7f1..a8c77927 100644 --- a/reporting/rep111.php +++ b/reporting/rep111.php @@ -166,7 +166,7 @@ function print_sales_quotations() } $tax_items = get_tax_for_items(ST_SALESORDER, $items, $prices, $myrow["freight_cost"], - $myrow['tax_group_id'], $myrow['tax_included'], null); + $myrow['tax_group_id'], $myrow['tax_included']); $first = true; foreach($tax_items as $tax_item) { diff --git a/reporting/rep209.php b/reporting/rep209.php index 8b4decbd..7e990bae 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -168,7 +168,7 @@ function print_po() $rep->NewLine(); $tax_items = get_tax_for_items(ST_PURCHORDER, $items, $prices, 0, - $myrow['tax_group_id'], $myrow['tax_included'], null, TCA_LINES); + $myrow['tax_group_id'], $myrow['tax_included'], TCA_LINES); $first = true; foreach($tax_items as $tax_item) { diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 6a7b3853..e1f63d53 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -61,7 +61,6 @@ class Cart var $tax_group_id; var $tax_group_name; - var $tax_group_array = null; // saves db queries var $price_factor; // ditto for price calculations var $pos; // user assigned POS @@ -368,7 +367,6 @@ class Cart $this->phone = $phone; $this->email = $email; $this->tax_group_id = $tax_group_id; - $this->tax_group_array = get_tax_group_items_as_array($tax_group_id); } function set_sales_type($sales_type, $sales_name, $tax_included=0, $factor=0) @@ -401,6 +399,7 @@ class Cart $qty_done, $unit_cost, $description, $id, $src_no, $src_id); if ($line->valid) { + $line->cart = $this; $this->line_items[$line_no] = $line; return 1; } else @@ -503,11 +502,22 @@ class Cart return 0; } + /* + Split line value to cost and taxes. + Stores calculated amounts in $line->gl_amounts arrays. + */ + function split_line_values() + { + // split nominal line values + foreach ($this->line_items as $line) + $line->split_item_value(); + } + function get_taxes($shipping_cost=null) { $items = array(); $prices = array(); - if($shipping_cost==null) + if ($shipping_cost == null) $shipping_cost = $this->freight_cost; foreach ($this->line_items as $ln_itm) { @@ -518,7 +528,7 @@ class Cart } $taxes = get_tax_for_items($this->trans_type, $items, $prices, $shipping_cost, - $this->tax_group_id, $this->tax_included, $this->tax_group_array); + $this->tax_group_id, $this->tax_included); // Adjustment for swiss franken, we always have 5 rappen = 1/20 franken if ($this->customer_currency == 'CHF') { @@ -541,21 +551,9 @@ class Cart function get_shipping_tax() { + $freight = split_item_price(NULL, $this->freight_cost, $this->tax_group_id, $this->tax_included, $this->trans_type); - $tax_items = get_shipping_tax_as_array($this->tax_group_id); - $tax_rate = 0; - if ($tax_items != null) { - foreach ($tax_items as $item_tax) { - $index = $item_tax['tax_type_id']; - if (isset($this->tax_group_array[$index]['rate'])) { - $tax_rate += $item_tax['rate']; - } - } - } - if($this->tax_included) - return round($this->freight_cost*$tax_rate/($tax_rate+100), user_price_dec()); - else - return round($this->freight_cost*$tax_rate/100, user_price_dec()); + return $freight['Tax']; } /* Returns transaction value including all taxes @@ -672,6 +670,7 @@ class line_details var $unit_cost; var $descr_editable; + var $cart; // line context var $valid; // validation in constructor /* Line quantity properties in various cart create modes: @@ -737,5 +736,20 @@ class line_details { return $this->price; } + + function taxfree_charge_price() + { + $this->split_item_value(); + return $this->gl_amounts['Net']; + } + + /* + Splits item value to parts posted to GL. + */ + function split_item_value() + { + return $this->gl_amounts = split_item_price($this->stock_id, $this->price*$this->quantity, $this->cart->tax_group_id, $this->cart->tax_included, + $this->cart->trans_type); + } } diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 43b6e308..37e01577 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -101,31 +101,30 @@ function write_credit_note(&$credit_note, $write_off_acc) } $total = 0; - foreach ($credit_note->line_items as $credit_line) { + $credit_note->split_line_values(); + foreach ($credit_note->line_items as $line) { - if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) { - update_parent_line(ST_CUSTCREDIT, $credit_line->src_id,($credit_line->qty_dispatched - -$credit_line->qty_old)); + if ($credit_invoice && $line->qty_dispatched!=$line->qty_old ) { + update_parent_line(ST_CUSTCREDIT, $line->src_id,($line->qty_dispatched + -$line->qty_old)); } - $line_taxfree_price = get_tax_free_price_for_item(ST_CUSTCREDIT, $credit_line->stock_id, $credit_line->price, - 0, $credit_note->tax_included, $credit_note->tax_group_array); + $line_taxfree_price = $line->gl_amounts['Net']; - $line_tax = get_full_price_for_item(ST_CUSTCREDIT, $credit_line->stock_id, $credit_line->price, - 0, $credit_note->tax_included, $credit_note->tax_group_array) - $line_taxfree_price; + $line_tax = $line->gl_amounts['Net']; - $credit_line->unit_cost = get_unit_cost($credit_line->stock_id); + $line->unit_cost = get_unit_cost($line->stock_id); - write_customer_trans_detail_item(ST_CUSTCREDIT, $credit_no, $credit_line->stock_id, - $credit_line->item_description, $credit_line->qty_dispatched, - $credit_line->line_price(), $line_tax, $credit_line->discount_percent, - $credit_line->unit_cost, $credit_line->src_id, $trans_no==0 ? 0: $credit_line->id); + write_customer_trans_detail_item(ST_CUSTCREDIT, $credit_no, $line->stock_id, + $line->item_description, $line->qty_dispatched, + $line->line_price(), $line_tax, $line->discount_percent, + $line->unit_cost, $line->src_id, $trans_no==0 ? 0: $line->id); if ($credit_type == 'Return') - add_credit_movements_item($credit_note, $credit_line, - $credit_type, ($line_taxfree_price+$line_tax)*(1-$credit_line->discount_percent), $credit_invoice); + add_credit_movements_item($credit_note, $line, + $credit_type, ($line_taxfree_price+$line_tax)*(1-$line->discount_percent), $credit_invoice); - $total += add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no, + $total += add_gl_trans_credit_costs($credit_note, $line, $credit_no, $credit_date, $credit_type, $write_off_acc, $branch_data); } /*end of credit_line loop */ @@ -166,8 +165,8 @@ function write_credit_note(&$credit_note, $write_off_acc) $Refs->save(ST_CUSTCREDIT, $credit_no, $credit_note->reference); } hook_db_postwrite($credit_note, ST_CUSTCREDIT); - commit_transaction(); + commit_transaction(); return $credit_no; } @@ -178,7 +177,7 @@ function write_credit_note(&$credit_note, $write_off_acc) function add_credit_movements_item(&$credit_note, &$credit_line, $credit_type, $price, $credited_invoice=0) { - //Chaitanya : Stamp current cost in stock moves $credit_line does not fetch cost + //Chaitanya : Stamp current cost in stock moves $line does not fetch cost $curr_std_cost = get_unit_cost($credit_line->stock_id); $reference = _("Return"); @@ -231,12 +230,9 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, if ($order_line->line_price() != 0) { - $line_taxfree_price = - get_tax_free_price_for_item(ST_CUSTCREDIT, $order_line->stock_id, $order_line->price, - 0, $order->tax_included, $order->tax_group_array); + $line_taxfree_price = $order_line->gl_amounts['Net']; - $line_tax = get_full_price_for_item(ST_CUSTCREDIT, $order_line->stock_id, $order_line->price, - 0, $order->tax_included, $order->tax_group_array) - $line_taxfree_price; + $line_tax = $order_line->gl_amounts['Tax']; //Post sales transaction to GL credit sales diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 18faa0be..3c260a52 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -68,46 +68,46 @@ function write_sales_delivery(&$delivery,$bo_policy) $branch_data = get_branch_accounts($delivery->Branch); $total = 0; } - foreach ($delivery->line_items as $line_no => $delivery_line) { - $qty = $delivery_line->qty_dispatched; - $line_price = $delivery_line->line_price(); - $line_taxfree_price = get_tax_free_price_for_item(ST_CUSTDELIVERY, $delivery_line->stock_id, - $delivery_line->price*$qty, $delivery->tax_group_id, $delivery->tax_included, - $delivery->tax_group_array); + $delivery->split_line_values(); - $line_tax = get_full_price_for_item(ST_CUSTDELIVERY, $delivery_line->stock_id, - $delivery_line->price * $qty, 0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price; + foreach ($delivery->line_items as $line_no => $line) { - $delivery_line->unit_cost = get_unit_cost($delivery_line->stock_id); + $qty = $line->qty_dispatched; + $line_price = $line->line_price(); + $line_taxfree_price = $line->gl_amounts['Net']; + + $line_tax = $line->gl_amounts['Tax']; + + $line->unit_cost = get_unit_cost($line->stock_id); /* add delivery details for all lines */ - write_customer_trans_detail_item(ST_CUSTDELIVERY, $delivery_no, $delivery_line->stock_id, - $delivery_line->item_description, $delivery_line->qty_dispatched, - $delivery_line->line_price(), $qty ? $line_tax/$qty : 0, - $delivery_line->discount_percent, $delivery_line->unit_cost, $delivery_line->src_id, - $trans_no ? $delivery_line->id : 0); + write_customer_trans_detail_item(ST_CUSTDELIVERY, $delivery_no, $line->stock_id, + $line->item_description, $line->qty_dispatched, + $line->line_price(), $qty ? $line_tax/$qty : 0, + $line->discount_percent, $line->unit_cost, $line->src_id, + $trans_no ? $line->id : 0); // Now update sales_order_details for the quantity delivered - if ($delivery_line->qty_old != $delivery_line->qty_dispatched) - update_parent_line(ST_CUSTDELIVERY, $delivery_line->src_id, - $delivery_line->qty_dispatched-$delivery_line->qty_old); + if ($line->qty_old != $line->qty_dispatched) + update_parent_line(ST_CUSTDELIVERY, $line->src_id, + $line->qty_dispatched-$line->qty_old); - if ($delivery_line->qty_dispatched != 0) { - add_stock_move(ST_CUSTDELIVERY, $delivery_line->stock_id, $delivery_no, + if ($line->qty_dispatched != 0) { + add_stock_move(ST_CUSTDELIVERY, $line->stock_id, $delivery_no, $delivery->Location, $delivery->document_date, $delivery->reference, - -$delivery_line->qty_dispatched, $delivery_line->unit_cost, - $line_price*(1-$delivery_line->discount_percent)); + -$line->qty_dispatched, $line->unit_cost, + $line_price*(1-$line->discount_percent)); - $mb_flag = get_mb_flag($delivery_line->stock_id); + $mb_flag = get_mb_flag($line->stock_id); if (is_fixed_asset($mb_flag)) { $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1, material_cost=0 - WHERE stock_id=".db_escape($delivery_line->stock_id); + WHERE stock_id=".db_escape($line->stock_id); db_query($sql,"The cost details for the fixed asset could not be updated"); } - $stock_gl_code = get_stock_gl_code($delivery_line->stock_id); + $stock_gl_code = get_stock_gl_code($line->stock_id); // If there is a Customer Dimension, then override with this, // else take the Item Dimension (if any) @@ -124,11 +124,11 @@ function write_sales_delivery(&$delivery,$bo_policy) } /* insert gl_trans to credit stock and debit cost of sales at standard cost*/ - if (is_inventory_item($delivery_line->stock_id)) { + if (is_inventory_item($line->stock_id)) { // Fixed Assets if ($delivery->fixed_asset) { - $fa_purchase_cost = get_purchase_cost($delivery_line->stock_id); - $fa_depreciation = $fa_purchase_cost - $delivery_line->unit_cost; + $fa_purchase_cost = get_purchase_cost($line->stock_id); + $fa_depreciation = $fa_purchase_cost - $line->unit_cost; /*first remove depreciation*/ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, $stock_gl_code["adjustment_account"], $dim, $dim2, "", @@ -146,17 +146,17 @@ function write_sales_delivery(&$delivery,$bo_policy) PT_CUSTOMER, $delivery->customer_id); } // Invetory Items - else if ($delivery_line->unit_cost != 0) { + else if ($line->unit_cost != 0) { /*first the cost of sales entry*/ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "", - $delivery_line->unit_cost * $delivery_line->qty_dispatched, + $line->unit_cost * $line->qty_dispatched, PT_CUSTOMER, $delivery->customer_id); /*now the stock entry*/ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, $stock_gl_code["inventory_account"], 0, 0, "", - (-$delivery_line->unit_cost * $delivery_line->qty_dispatched), + (-$line->unit_cost * $line->qty_dispatched), PT_CUSTOMER, $delivery->customer_id); } diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 96ba23a6..1f79aa09 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -56,7 +56,7 @@ function write_sales_invoice(&$invoice) } if($invoice->tax_included==0) { - $items_added_tax = $ov_gst-$freight_tax; + $items_added_tax = $ov_gst - $freight_tax; $freight_added_tax = $freight_tax; } else { $items_added_tax = 0; @@ -102,34 +102,31 @@ function write_sales_invoice(&$invoice) // for prepayments use deferred income account if set $sales_account = $invoice->is_prepaid() ? get_company_pref('deferred_income_act') : 0; - foreach ($invoice->line_items as $line_no => $invoice_line) { - $qty = $invoice_line->qty_dispatched; - $line_taxfree_price = get_tax_free_price_for_item(ST_SALESINVOICE, $invoice_line->stock_id, - $invoice_line->price * $qty, $invoice->tax_group_id, $invoice->tax_included, - $invoice->tax_group_array); + $invoice->split_line_values(); + foreach ($invoice->line_items as $line_no => $line) { + $qty = $line->qty_dispatched; + $line_taxfree_price = $line->gl_amounts['Net']; - $line_tax = get_full_price_for_item(ST_SALESINVOICE, $invoice_line->stock_id, - $invoice_line->price * $qty, 0, $invoice->tax_included, - $invoice->tax_group_array) - $line_taxfree_price; + $line_tax = $line->gl_amounts['Tax']; - write_customer_trans_detail_item(ST_SALESINVOICE, $invoice_no, $invoice_line->stock_id, - $invoice_line->item_description, $invoice_line->qty_dispatched, - $invoice_line->line_price(), $qty ? $line_tax/$qty : 0, $invoice_line->discount_percent, - $invoice_line->unit_cost, $invoice_line->src_id, - $trans_no ? $invoice_line->id : 0); + write_customer_trans_detail_item(ST_SALESINVOICE, $invoice_no, $line->stock_id, + $line->item_description, $line->qty_dispatched, + $line->line_price(), $qty ? $line_tax/$qty : 0, $line->discount_percent, + $line->unit_cost, $line->src_id, + $trans_no ? $line->id : 0); // Update delivery items for the quantity invoiced - if ($invoice_line->qty_old != $invoice_line->qty_dispatched) + if ($line->qty_old != $line->qty_dispatched) { if ($invoice->is_prepaid()) - update_prepaid_so_line($invoice_line->src_id, $invoice_line->qty_dispatched-$invoice_line->qty_old); + update_prepaid_so_line($line->src_id, $line->qty_dispatched-$line->qty_old); else - update_parent_line(ST_SALESINVOICE, $invoice_line->src_id, ($invoice_line->qty_dispatched-$invoice_line->qty_old)); + update_parent_line(ST_SALESINVOICE, $line->src_id, ($line->qty_dispatched-$line->qty_old)); } - if ($invoice_line->qty_dispatched != 0) { - $stock_gl_code = get_stock_gl_code($invoice_line->stock_id); + if ($line->qty_dispatched != 0) { + $stock_gl_code = get_stock_gl_code($line->stock_id); - if ($invoice_line->line_price() != 0) { + if ($line->line_price() != 0) { //Post sales transaction to GL credit sales // If there is a Branch Sales Account, then override with this, @@ -145,11 +142,11 @@ function write_sales_invoice(&$invoice) $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $sales_account, $dim, $dim2, -$line_taxfree_price*$prepaid_factor, $invoice->customer_id); - if ($invoice_line->discount_percent != 0) { + if ($line->discount_percent != 0) { $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $branch_data["sales_discount_account"], $dim, $dim2, - ($line_taxfree_price * $invoice_line->discount_percent)*$prepaid_factor, $invoice->customer_id); + ($line_taxfree_price * $line->discount_percent)*$prepaid_factor, $invoice->customer_id); } /*end of if discount !=0 */ } } /*quantity dispatched is more than 0 */ diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 7f0a752f..26e92955 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -268,8 +268,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart) $result = get_customer_trans_details($doc_type,$trans_no); if (db_num_rows($result) > 0) { for($line_no=0; $myrow = db_fetch($result); $line_no++) { - $cart->line_items[$line_no] = new line_details( - $myrow["stock_id"],$myrow["quantity"], + $cart->add_to_cart($line_no, $myrow["stock_id"],$myrow["quantity"], $myrow["unit_price"], $myrow["discount_percent"], $myrow["qty_done"], $myrow["unit_cost"], $myrow["StockDescription"],$myrow["id"], $myrow["debtor_trans_no"], diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index dc269fdc..5e152855 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -121,7 +121,6 @@ function get_tax_group_items_as_array($id) $ret_tax_array[$tax_group_item['tax_type_id']] = $tax_group_item; } - return $ret_tax_array; } diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 84aa9ce6..004fcd33 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -91,7 +91,7 @@ function get_base_taxdata($stock_id, $group_id) /* Main tax procedure splitting transaction item value according to item tax rules applicable: - $stock_id - stock item code; special case is '' for shipping + $stock_id - stock item code; NULL for shipping $amount - price/value to be splitted $tax_group - entity tax group $tax_included - whether value includes all taxes @@ -230,7 +230,7 @@ function get_tax_for_items($trans_type, $items, $prices, $shipping_cost, $tax_gr // if shipping cost is passed, just add to the prices/items tables if ($shipping_cost != 0) { - $items[] = null; + $items[] = NULL; $prices[] = $shipping_cost; if ($vat_factors) $vat_factors[] = 1; diff --git a/taxes/tax_rules.inc b/taxes/tax_rules.inc index 9dd3519f..fa13419b 100644 --- a/taxes/tax_rules.inc +++ b/taxes/tax_rules.inc @@ -10,12 +10,7 @@ See the License here . ***********************************************************************/ /* - FA tax rules basic reimplementation. Final version would involve changes in database scheme, - and/or tax system class selection according to site requirements. - - TODO: - . changes in Sales module - . change all tax related methods in supp_trans to use split_item_price instead of other functions like get_taxes_for_item + FA tax basic rules. */ define('TAX_NONE', 0); // none option define('TQ_NONE', 0); // none option