X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fdb%2Fpo_db.inc;h=a82eb9a584649c0b0d90f35441b1d09eacd40b27;hb=9ff22040ec9e77b56c71df9bd95f9b2c2d50bd7e;hp=aa705cd779fa5def2cda7659d35773c49831edc8;hpb=8ffddf50ffbe93672c769e2cf0501d0f9125e2a0;p=fa-stable.git diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index aa705cd7..a82eb9a5 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -13,7 +13,7 @@ function get_supplier_details_to_order(&$order, $supplier_id) { - $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, + $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, dimension_id, dimension2_id, supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) * (ov_amount + ov_gst + ov_discount),0)) as cur_credit, terms.terms, terms.days_before_due, terms.day_in_following_month @@ -36,6 +36,8 @@ function get_supplier_details_to_order(&$order, $supplier_id) $_POST['supplier_id'] = $supplier_id; $_POST['supplier_name'] = $myrow["supp_name"]; $_POST['curr_code'] = $myrow["curr_code"]; + $_POST['dimension'] = $myrow["dimension_id"]; + $_POST['dimension2'] = $myrow["dimension2_id"]; $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], $myrow["tax_group_id"], $myrow["tax_included"]); @@ -102,8 +104,6 @@ function add_po(&$po_obj) $Refs->save(ST_PURCHORDER, $po_obj->order_no, $po_obj->reference); - //add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments); - add_audit_trail(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date); hook_db_postwrite($po_obj, ST_PURCHORDER); commit_transaction(); @@ -150,13 +150,7 @@ function update_po(&$po_obj) db_query($sql, "One of the purchase order detail records could not be updated"); } -//_vd($po_obj->prepayments); - reallocate_payments($po_obj->order_no, ST_PURCHORDER, $po_obj->orig_order_date, $po_obj->get_trans_total(), $po_obj->prepayments); -//_vd($p = get_payments_for($po_obj->order_no, ST_PURCHORDER)); -//_vd(get_supp_trans($p[0]['trans_no_from'], $p[0]['trans_type_from'])); -//exit; - - // add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments); + 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); add_audit_trail($po_obj->trans_type, $po_obj->order_no, Today(), _("Updated.")); hook_db_postwrite($po_obj, ST_PURCHORDER); @@ -169,13 +163,13 @@ function update_po(&$po_obj) function read_po_header($order_no, &$order) { - $sql = "SELECT ".TB_PREF."purch_orders.*, " - .TB_PREF."suppliers.*, " - .TB_PREF."locations.location_name - FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations - WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id - AND ".TB_PREF."locations.loc_code = into_stock_location - AND ".TB_PREF."purch_orders.order_no = ".db_escape($order_no); + $sql = "SELECT po.*, supplier.*, loc.location_name + FROM ".TB_PREF."purch_orders po," + .TB_PREF."suppliers supplier," + .TB_PREF."locations loc + WHERE po.supplier_id = supplier.supplier_id + AND loc.loc_code = into_stock_location + AND po.order_no = ".db_escape($order_no); $result = db_query($sql, "The order cannot be retrieved"); @@ -193,14 +187,14 @@ function read_po_header($order_no, &$order) $order->credit = get_current_supp_credit($order->supplier_id); $order->orig_order_date = sql2date($myrow["ord_date"]); - $order->Comments = nl2br($myrow["comments"]); + $order->Comments = $myrow["comments"]; $order->Location = $myrow["into_stock_location"]; $order->supp_ref = $myrow["requisition_no"]; $order->reference = $myrow["reference"]; $order->delivery_address = $myrow["delivery_address"]; $order->alloc = $myrow["alloc"]; $order->prep_amount = $myrow["prep_amount"]; - $order->prepayments = get_payments_for($order_no, ST_PURCHORDER); + $order->prepayments = get_payments_for($order_no, ST_PURCHORDER, $myrow["supplier_id"]); return true; } @@ -215,14 +209,13 @@ function read_po_items($order_no, &$order, $open_items_only=false) { /*now populate the line po array with the purchase order details records */ - $sql = "SELECT ".TB_PREF."purch_order_details.*, units - FROM ".TB_PREF."purch_order_details - LEFT JOIN ".TB_PREF."stock_master - ON ".TB_PREF."purch_order_details.item_code=".TB_PREF."stock_master.stock_id + $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); if ($open_items_only) - $sql .= " AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) "; + $sql .= " AND (poline.quantity_ordered > poline.quantity_received) "; $sql .= " ORDER BY po_detail_item"; @@ -237,8 +230,6 @@ function read_po_items($order_no, &$order, $open_items_only=false) { if ($data['supplier_description'] != "") $myrow['description'] = $data['supplier_description']; - //if ($data['suppliers_uom'] != "") - // $myrow['units'] = $data['suppliers_uom']; } if (is_null($myrow["units"])) { @@ -253,11 +244,7 @@ function read_po_items($order_no, &$order, $open_items_only=false) $myrow["quantity_ordered"],$myrow["description"], $myrow["unit_price"],$units, sql2date($myrow["delivery_date"]), $myrow["qty_invoiced"], $myrow["quantity_received"])) { - $newline = &$order->line_items[$order->lines_on_order-1]; - $newline->po_detail_rec = $myrow["po_detail_item"]; - $newline->standard_cost = $myrow["std_cost_unit"]; /*Needed for receiving goods and GL interface */ - // set for later GRN edition -// $newline->receive_qty = $newline->quantity - $newline->qty_dispatched; + $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