if ($order_line->quantity + $order_line->qty_received > $order_line->qty_ordered)
$order_line->qty_ordered = $order_line->quantity + $order_line->qty_received;
- $grn_item = write_grn_item($grn, $order_line->po_detail_rec,
+ $grn_item = write_grn_item($grn, $order_line->po_item_id,
$order_line->stock_id, $order_line->item_description, $order_line->quantity, $order_line->grn_item_id);
$po->line_items[$line_no]->grn_item_id = $grn_item;
{
while ($myrow = db_fetch_assoc($result))
- {
+ {
if ($myrow['qty_recd'] == 0 && $myrow['quantity_inv'] == 0)
continue; // We will not have empty credited rows.
- if (is_null($myrow["units"]))
- {
- $units = "";
- }
- else
- {
- $units = $myrow["units"];
- }
-
- $order->add_to_order($order->lines_on_order, $myrow["item_code"],
- $myrow["qty_recd"],$myrow["description"], $myrow["unit_price"],$units,
+
+ $order->add_to_order($myrow["item_code"],
+ $myrow["qty_recd"],$myrow["description"], $myrow["unit_price"],
sql2date($myrow["req_del_date"]), $myrow["quantity_inv"],
- $myrow["quantity_received"], $myrow["quantity_ordered"], $myrow["id"]);
+ $myrow["quantity_received"], $myrow["quantity_ordered"], $myrow["id"], $myrow["po_detail_item"]);
- $order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"];
} /* line po from purchase order details */
} //end of checks on returned data set
}
db_escape($po_line->price) . ", " .
db_escape($po_line->quantity). ")";
db_query($sql, "One of the purchase order detail records could not be inserted");
- $po_obj->line_items[$line_no]->po_detail_rec = db_insert_id();
+ $po_obj->line_items[$line_no]->po_item_id = db_insert_id();
}
$Refs->save(ST_PURCHORDER, $po_obj->order_no, $po_obj->reference);
{
$sql = "INSERT INTO ".TB_PREF."purch_order_details (po_detail_item, order_no, item_code,
description, delivery_date, unit_price, quantity_ordered, quantity_received) VALUES ("
- .db_escape($po_line->po_detail_rec ? $po_line->po_detail_rec : 0). ","
+ .db_escape($po_line->po_item_id ? $po_line->po_item_id : 0). ","
.$po_obj->order_no . ","
.db_escape($po_line->stock_id). ","
.db_escape($po_line->item_description). ",'"
$sql = "SELECT poline.*, units
FROM ".TB_PREF."purch_order_details poline
LEFT JOIN ".TB_PREF."stock_master item ON poline.item_code=item.stock_id
- WHERE order_no =".db_escape($order_no);
+ WHERE order_no =".db_escape($order_no)
+ ." AND poline.quantity_ordered!=0";
if ($open_items_only)
$sql .= " AND (poline.quantity_ordered > poline.quantity_received) ";
if ($data['supplier_description'] != "")
$myrow['description'] = $data['supplier_description'];
}
- if (is_null($myrow["units"]))
- {
- $units = "";
- }
- else
- {
- $units = $myrow["units"];
- }
-
- if ($order->add_to_order($order->lines_on_order, $myrow["item_code"],
- $myrow["quantity_ordered"],$myrow["description"],
- $myrow["unit_price"],$units, sql2date($myrow["delivery_date"]),
- $myrow["qty_invoiced"], $myrow["quantity_received"], $myrow["quantity_ordered"])) {
- $order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"];
- }
+
+ $order->add_to_order($myrow["item_code"],
+ $myrow["quantity_ordered"],$myrow["description"],
+ $myrow["unit_price"], sql2date($myrow["delivery_date"]),
+ $myrow["qty_invoiced"], $myrow["quantity_received"],
+ $myrow["quantity_ordered"], 0, $myrow["po_detail_item"]);
} /* line po from purchase order details */
} //end of checks on returned data set
}
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-/* Definition of the purch_order class to hold all the information for a purchase order and delivery
+/*
+ This class serves as cart for PO or GRN.
*/
class purch_order
{
-
+ // db interface
var $trans_type; // order/grn/invoice (direct)
var $supplier_id;
var $Comments;
var $alloc; // sum of payments allocated
var $tax_included; // type of prices
+ var $due_date; // for grn this is delivery date
+ var $order_no; // for order modification, grn batch
+ var $ex_rate; // for grn
+
var $line_items;
+ //----
+
var $curr_code;
var $supplier_name;
- var $due_date;
- var $order_no; /*Only used for modification of existing orders otherwise only established when order committed */
- var $lines_on_order = 0;
var $credit;
var $tax_group_id;
var $terms;
- var $ex_rate;
var $cash_account;
var $dimension,
$dimension2;
var $prepayments = array();
var $fixed_asset = false;
- var $grn_id ; // grn batch id used in edition only
+ var $grn_id; // grn batch id used in edition only
function __construct()
{
$this->line_items = array();
- $this->lines_on_order = $this->order_no = $this->supplier_id = 0;
+ $this->order_no = $this->supplier_id = 0;
$this->tax_group_id = find_domestic_tax_group(); // prevent tax errors until supplier is selected
}
$this->tax_area = $tax_area;
}
- function add_to_order($line_no, $stock_id, $qty, $item_descr, $price, $uom, $req_del_date, $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=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)
{
- if (isset($qty) && $qty != 0)
- {
- $this->line_items[$line_no] = new po_line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom,
- $req_del_date, $qty_inv, $qty_recd, $qty_ordered, $grn_item_id);
- $this->lines_on_order++;
- return 1;
- }
- return 0;
+ $this->line_items[] = 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);
}
function update_order_item($line_no, $qty, $price, $req_del_date, $description="")
{
unset($this->line_items);
$this->line_items = array();
-
- $this->lines_on_order = 0;
$this->order_no = 0;
}
class po_line_details
{
-
- var $line_no;
- var $po_detail_rec;
+ //db interface
+ var $po_item_id;
var $grn_item_id;
var $stock_id;
var $item_description;
var $price;
var $units;
var $req_del_date;
-
- var $quantity; // this document line quantity
var $qty_inv; // quantity already invoiced against this line (all PIs)
var $qty_received; // quantity already received against this line (all GRNs)
var $qty_ordered; // quantity on order (not used on PO entry)
-
var $unit_cost;
+ var $quantity; // this document line quantity
+ //---
+
var $descr_editable;
var $vat_category;
+ var $gl_amounts; // splited line value (after call to split_line_value method)
- function __construct($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date,
- $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=0)
+ function __construct($stock_item, $item_descr, $qty, $prc, $req_del_date,
+ $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=0, $po_item_id=0)
{
- /* Constructor function to add a new LineDetail object with passed params */
- $this->line_no = $line_no;
$this->stock_id = $stock_item;
$item_row = get_item($stock_item);
if (!$item_row)
$this->quantity = $qty;
$this->req_del_date = $req_del_date;
$this->price = $prc;
-// $this->units = $uom;
$this->units = $item_row["units"];
$this->qty_received = $qty_recd;
$this->qty_inv = $qty_inv;
$this->grn_item_id = $grn_item_id;
$this->vat_category = $item_row["vat_category"];
$this->qty_ordered = $qty_ordered;
+ $this->po_item_id = $po_item_id;
}
//
$inv->ov_amount = $inv->ov_gst = $inv->ov_discount = 0;
$total = 0;
foreach($cart->line_items as $key => $line) {
- $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id,
+ $inv->add_grn_to_trans($line->grn_item_id, $line->po_item_id, $line->stock_id,
$line->item_description, $line->quantity, 0, $line->quantity,
$line->price, $line->price, true, get_unit_cost($line->stock_id), '');
$total += round2(($line->quantity * $line->price), user_price_dec());
}
$inv->tax_overrides = $cart->tax_overrides;
if (!$inv->tax_included) {
- $taxes = $inv->get_taxes($inv->tax_group_id, 0, false);
+ $taxes = $inv->get_taxes();
foreach( $taxes as $taxitem) {
$total += isset($taxitem['Override']) ? $taxitem['Override'] : $taxitem['Value'];
}
class supp_trans
{
+ //db interface
+ var $trans_no;
+ var $trans_type; // invoice or credit
+ var $supplier_id;
+ var $reference;
+ var $supp_reference;
+ var $tran_date;
+ var $due_date;
+ var $ov_amount;
+ var $ov_discount;
+ var $ov_gst;
+ var $ex_rate;
+
+ var $tax_included;
var $grn_items; /*array of objects of class grn_item using the id as the pointer */
var $gl_codes; /*array of objects of class gl_codes using a counter as the pointer */
- var $supplier_id;
+ var $Comments;
+ //---
+
var $supplier_name;
var $terms;
- var $ex_rate;
var $tax_description;
var $tax_group_id;
- var $tax_included;
-
- var $trans_type; // invoice or credit
- var $trans_no;
- var $Comments;
- var $tran_date;
- var $due_date;
var $src_docs = array(); // source invoice for this credit note (if any)
- var $supp_reference;
- var $reference;
- var $ov_amount;
- var $ov_discount;
- var $ov_gst;
var $credit = 0;
var $currency;
var $tax_overrides = array(); // array of taxes manually inserted during sales invoice entry
$this->gl_codes = array();
if ($trans_no) {
read_supp_invoice($trans_no, $trans_type, $this);
+
if ($trans_type == ST_SUPPCREDIT)
- {
$this->src_docs = find_src_invoices($trans_no);
- }
+
read_supplier_details_to_trans($this, $this->supplier_id);
}
}
$this->gl_codes = array();
}
- function get_taxes($tax_group_id=null, $shipping_cost=0, $gl_codes=true)
+ function get_taxes($gl_codes=true)
{
$items = array();
$prices = array();
- if ($tax_group_id == null)
- $tax_group_id = $this->tax_group_id;
-
- // preload the taxgroup
- $tax_group = get_tax_group_items_as_array($tax_group_id);
-
foreach ($this->grn_items as $ln_itm)
{
$items[] = $ln_itm->item_code;
- $prices[] =round( ($ln_itm->this_quantity_inv * $ln_itm->chg_price),
- user_price_dec());
+ $prices[] = round( $ln_itm->this_quantity_inv * $ln_itm->chg_price, user_price_dec());
}
- if ($tax_group_id == null)
- $tax_group_id = $this->tax_group_id;
- $taxes = get_tax_for_items($this->trans_type, $items, $prices, $shipping_cost, $tax_group_id,
+ $taxes = get_tax_for_items($this->trans_type, $items, $prices, 0, $this->tax_group_id,
$this->tax_included);
if (isset($this->tax_overrides))
}
// Taxes included in gl_codes table have exact value, but count to overrides as well.
- // Therefore when we want to now taxes only for items (gl_codes==false),
+ // Therefore when we want to know taxes only for items (gl_codes==false),
// we have to subtract gl_taxes from override values.
foreach ($this->gl_codes as $gl_code)
{
$taxes[$index]['Override'] -= $gl_code->amount;
}
}
-
return $taxes;
}
//
{
$total = 0;
- // preload the taxgroup !
- if ($tax_group_id != null)
- $tax_group = get_tax_group_items_as_array($tax_group_id);
- else
- $tax_group = null;
-
foreach ($this->grn_items as $ln_itm)
- $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)),
+ $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $this->trans_type)),
user_price_dec());
foreach ($this->gl_codes as $gl_line)
}
return $total;
}
+
//
// Returns transaction total
//
return $total;
}
+ /*
+ Split line value to cost and taxes.
+ Stores calculated amounts in $line->gl_amounts array.
+ */
function split_line_values()
{
// split nominal line values
all the info to do the necessary entries without looking up ie additional queries of the database again */
var $id;
+
+ var $gl_code;
+
var $po_detail_item;
var $item_code;
var $item_description;
+ var $this_quantity_inv;
+ var $chg_price;
+
var $qty_recd;
var $prev_quantity_inv;
- var $this_quantity_inv;
var $order_price;
- var $chg_price;
var $std_cost_unit;
- var $gl_code;
var $tax_included;
var $gl_amounts; // splited line value (after call to split_line_value method
var $vat_category;
$this->qty_recd = $qty_recd;
$this->prev_quantity_inv = $prev_quantity_inv;
$this->this_quantity_inv = $this_quantity_inv;
- $this->order_price =$order_price;
+ $this->order_price = $order_price; // price on order
$this->chg_price = $chg_price;
- $this->std_cost_unit = $std_cost_unit;
+ $this->std_cost_unit = $std_cost_unit; // provisional cost for clearing
$this->gl_code = $gl_code;
$this->tax_included = $tax_included;
$this->vat_category = $opts['vat_category'];
}
- function full_charge_price($tax_group_id, $trans_type=ST_PURCHORDER)
- {
- return get_full_price_for_item($trans_type, $this->item_code,
- $this->chg_price, $tax_group_id, $this->tax_included);
- }
+// function full_charge_price($tax_group_id, $trans_type=ST_PURCHORDER)
+// {
+// return get_full_price_for_item($trans_type, $this->item_code,
+// $this->chg_price, $tax_group_id, $this->tax_included);
+// }
function taxfree_charge_price($tax_group_id, $trans_type=ST_PURCHORDER)
{
$tax_group_id, $this->tax_included);
}
- function taxfree_value($tax_group_id, $trans_type=ST_PURCHORDER)
- {
- return get_tax_free_price_for_item($trans_type, $this->item_code, $this->this_quantity_inv * $this->chg_price,
- $tax_group_id, $this->tax_included, $tax_group);
- }
-
/*
Splits item value to parts posted to GL.
*/
start_table(TABLESTYLE, "width='95%'");
label_row(_("Sub-total:"), price_format( $supp_trans->ov_amount), "colspan=$colspan align=right", "align=right");
- $taxes = $supp_trans->get_taxes($supp_trans->tax_group_id);
+ $taxes = $supp_trans->get_taxes();
$tax_total = display_edit_tax_items($taxes, $colspan, $supp_trans->tax_included, 0, true);
$display_total = price_format($supp_trans->ov_amount + $tax_total);
if ($allow_update)
{
- $_SESSION['PO']->add_to_order (count($_SESSION['PO']->line_items), $_POST['stock_id'], input_num('qty'),
- get_post('stock_id_text'), //$myrow["description"],
- input_num('price'), '', // $myrow["units"], (retrived in cart)
+ $_SESSION['PO']->add_to_order($_POST['stock_id'], input_num('qty'),
+ get_post('stock_id_text'), input_num('price'),
$_SESSION['PO']->trans_type == ST_PURCHORDER ? $_POST['req_del_date'] : '', 0, 0);
unset_form_variables();
if (count($_SESSION['PO']->line_items) > 0 )
{
- foreach ($_SESSION['PO']->line_items as $ln_itm)
+ foreach ($_SESSION['PO']->line_items as $line_no => $ln_itm)
{
alt_table_row_color($k);
qty_cell($qty_outstanding, false, $dec);
if ($mod_grn || $qty_outstanding > 0)
- qty_cells(null, $ln_itm->line_no, number_format2($ln_itm->quantity, $dec), "align=right", null, $dec);
+ qty_cells(null, $line_no, number_format2($ln_itm->quantity, $dec), "align=right", null, $dec);
else
label_cell(number_format2($ln_itm->quantity, $dec), "align=right");
if (isset($_POST['Update']) || isset($_POST['ProcessGoodsReceived']))
{
- /* if update quantities button is hit page has been called and ${$line->line_no} would have be
+ /* if update quantities button is hit page has been called and ${$line_no} would have be
set from the post to the quantity to be received in this receival*/
- foreach ($_SESSION['PO']->line_items as $line)
+ foreach ($_SESSION['PO']->line_items as $line_no => $line)
{
if( ($line->qty_ordered - $line->qty_received) > 0) {
- $_POST[$line->line_no] = max($_POST[$line->line_no], 0);
- if (!check_num($line->line_no))
- $_POST[$line->line_no] = number_format2(0, get_qty_dec($line->stock_id));
+ $_POST[$line_no] = max($_POST[$line_no], 0);
+ if (!check_num($line_no))
+ $_POST[$line_no] = number_format2(0, get_qty_dec($line->stock_id));
if (!isset($_POST['tran_date']) || $_POST['tran_date'] == "")
$_POST['tran_date'] = new_doc_date();
- $_SESSION['PO']->line_items[$line->line_no]->quantity = input_num($line->line_no);
+ $_SESSION['PO']->line_items[$line_no]->quantity = input_num($line_no);
if (isset($_POST[$line->stock_id . "Desc"]) && strlen($_POST[$line->stock_id . "Desc"]) > 0)
{
- $_SESSION['PO']->line_items[$line->line_no]->item_description = $_POST[$line->stock_id . "Desc"];
+ $_SESSION['PO']->line_items[$line_no]->item_description = $_POST[$line->stock_id . "Desc"];
}
}
}
Returned array contains calculated values for GL postings and tax registration:
'Net' - value without tax,
'Tax' - tax sum,
- 'Cost' - cost value (can be higher then Net value) used in parallel postings,
+ 'Cost' - cost value (can be higher then Net value),
'vat_category' - stock tax category
- and detailed info for any tax applicable tax (any array with numeric key):
+
+ and (with numeric keys) detailed info for any applicable tax rate:
'tax_type_id' - tax type id
'Value' - charged tax value
'Deductible' - tax deductible (can be lower than Value for special goods)