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'),
);
{
/* 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 --------------------------------
$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 */
}
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="")
{
// 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
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)
//
// 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);
}
$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
//
// 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)
{
// 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
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)
// $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);
}
}
}
$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)
{
}
$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)
{
$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)
{
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
$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)
$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
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) {
}
$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') {
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
var $unit_cost;
var $descr_editable;
+ var $cart; // line context
var $valid; // validation in constructor
/*
Line quantity properties in various cart create modes:
{
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);
+ }
}
}
$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 */
$Refs->save(ST_CUSTCREDIT, $credit_no, $credit_note->reference);
}
hook_db_postwrite($credit_note, ST_CUSTCREDIT);
- commit_transaction();
+ commit_transaction();
return $credit_no;
}
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");
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
$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)
}
/* 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, "",
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);
}
}
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;
// 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,
$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 */
$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"],
$ret_tax_array[$tax_group_item['tax_type_id']] = $tax_group_item;
}
-
return $ret_tax_array;
}
/*
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
// 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;
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
/*
- 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