X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fdb%2Fpo_db.inc;h=eb26570f2cc4674c1652f6b40ff8db2e0b6ac806;hb=3178545262f658085cb8a250a2195246e05c8213;hp=0afbe1626292c98bac2236a586afdabf2948e650;hpb=192c58cc217a8cd8950c3fe983884a9d72f5746d;p=fa-stable.git diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index 0afbe162..eb26570f 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -15,10 +15,11 @@ function get_supplier_details_to_order(&$order, $supplier_id) { $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, dimension_id, dimension2_id, supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit, - terms.terms, terms.days_before_due, terms.day_in_following_month + terms.terms, terms.days_before_due, terms.day_in_following_month, tg.tax_area FROM ".TB_PREF."suppliers supp LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator + LEFT JOIN ".TB_PREF."tax_groups tg ON supp.tax_group_id=tg.id WHERE supp.supplier_id = ".db_escape($supplier_id)." GROUP BY supp.supp_name"; @@ -39,7 +40,7 @@ function get_supplier_details_to_order(&$order, $supplier_id) $_POST['dimension2'] = $myrow["dimension2_id"]; $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], - $myrow["tax_group_id"], $myrow["tax_included"]); + $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_area"]); } //---------------------------------------------------------------------------------------- @@ -71,10 +72,10 @@ function add_po(&$po_obj) /*Insert to purchase order header record */ $sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, - requisition_no, into_stock_location, delivery_address, total, tax_included, prep_amount) VALUES("; + supp_reference, into_stock_location, delivery_address, total, tax_included, prep_amount) VALUES("; $sql .= db_escape($po_obj->supplier_id) . "," . db_escape($po_obj->Comments) . ",'" . - date2sql($po_obj->orig_order_date) . "', " . + date2sql($po_obj->tran_date) . "', " . db_escape($po_obj->reference) . ", " . db_escape($po_obj->supp_ref) . ", " . db_escape($po_obj->Location) . ", " . @@ -103,7 +104,7 @@ function add_po(&$po_obj) $Refs->save(ST_PURCHORDER, $po_obj->order_no, $po_obj->reference); - add_audit_trail(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date); + add_audit_trail(ST_PURCHORDER, $po_obj->order_no, $po_obj->tran_date); hook_db_postwrite($po_obj, ST_PURCHORDER); commit_transaction(); @@ -119,9 +120,9 @@ function update_po(&$po_obj) /*Update the purchase order header with any changes */ $sql = "UPDATE ".TB_PREF."purch_orders SET Comments=" . db_escape($po_obj->Comments) . ", - requisition_no= ". db_escape( $po_obj->supp_ref). ", + supp_reference= ". db_escape( $po_obj->supp_ref). ", into_stock_location=" . db_escape($po_obj->Location). ", - ord_date='" . date2sql($po_obj->orig_order_date) . "', + ord_date='" . date2sql($po_obj->tran_date) . "', delivery_address=" . db_escape($po_obj->delivery_address).", total=". db_escape($po_obj->get_trans_total()).", prep_amount=". db_escape($po_obj->prep_amount).", @@ -149,7 +150,7 @@ function update_po(&$po_obj) db_query($sql, "One of the purchase order detail records could not be updated"); } - reallocate_payments($po_obj->order_no, ST_PURCHORDER, $po_obj->orig_order_date, $po_obj->get_trans_total(), $po_obj->prepayments, $po_obj->supplier_id); + reallocate_payments($po_obj->order_no, ST_PURCHORDER, $po_obj->tran_date, $po_obj->get_trans_total(), $po_obj->prepayments, $po_obj->supplier_id); add_audit_trail($po_obj->trans_type, $po_obj->order_no, Today(), _("Updated.")); hook_db_postwrite($po_obj, ST_PURCHORDER); @@ -162,9 +163,10 @@ function update_po(&$po_obj) function read_po_header($order_no, &$order) { - $sql = "SELECT po.*, supplier.*, loc.location_name + $sql = "SELECT po.*, tg.tax_area, supplier.*, loc.location_name FROM ".TB_PREF."purch_orders po," - .TB_PREF."suppliers supplier," + .TB_PREF."suppliers supplier + LEFT JOIN ".TB_PREF."tax_groups tg ON supplier.tax_group_id=tg.id," .TB_PREF."locations loc WHERE po.supplier_id = supplier.supplier_id AND loc.loc_code = into_stock_location @@ -181,14 +183,14 @@ function read_po_header($order_no, &$order) $order->order_no = $order_no; $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"], - $myrow['tax_group_id'], $myrow["tax_included"]); + $myrow['tax_group_id'], $myrow["tax_included"], $myrow["tax_area"]); $order->credit = get_current_supp_credit($order->supplier_id); - $order->orig_order_date = sql2date($myrow["ord_date"]); + $order->tran_date = sql2date($myrow["ord_date"]); $order->Comments = $myrow["comments"]; $order->Location = $myrow["into_stock_location"]; - $order->supp_ref = $myrow["requisition_no"]; + $order->supp_ref = $myrow["supp_reference"]; $order->reference = $myrow["reference"]; $order->delivery_address = $myrow["delivery_address"]; $order->alloc = $myrow["alloc"]; @@ -242,7 +244,7 @@ function read_po_items($order_no, &$order, $open_items_only=false) 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["qty_invoiced"], $myrow["quantity_received"], $myrow["quantity_ordered"])) { $order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"]; } } /* line po from purchase order details */ @@ -290,10 +292,12 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc porder.reference, supplier.supp_name, location.location_name, - porder.requisition_no, + porder.supp_reference, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue, + Sum(line.delivery_date < '". date2sql(Today()) ."' + AND (line.quantity_ordered > line.quantity_received)) As OverDue, porder.into_stock_location, chk.isopen FROM ".TB_PREF."purch_orders as porder @@ -350,7 +354,7 @@ function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_ porder.reference, supplier.supp_name, location.location_name, - porder.requisition_no, + porder.supp_reference, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue,