X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fdb%2Fpo_db.inc;h=9f5a0cc299ad550ec072d3dafe1972d671fb9f7c;hb=17b390efcf904072b02ec866b2a427490471a260;hp=38703adf3e834dd3a9c26e05730734b278bce39e;hpb=22486f7826944e00937e7ccceab1a927c94d8f6a;p=fa-stable.git diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index 38703adf..9f5a0cc2 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -9,6 +9,38 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +// ------------------------------------------------------------------------------ + +function get_supplier_details_to_order(&$order, $supplier_id) +{ + $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm, + 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 + 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 + WHERE supp.supplier_id = ".db_escape($supplier_id)." + GROUP BY + supp.supp_name"; + + $result = db_query($sql, "The supplier details could not be retreived"); + $myrow = db_fetch($result); + + $order->credit = $myrow["cur_credit"]; + $order->terms = array( + 'description' => $myrow['terms'], + 'days_before_due' => $myrow['days_before_due'], + 'day_in_following_month' => $myrow['day_in_following_month'] ); + + $_POST['supplier_id'] = $supplier_id; + $_POST['supplier_name'] = $myrow["supp_name"]; + $_POST['curr_code'] = $myrow["curr_code"]; + + $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], + $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]); +} + //---------------------------------------------------------------------------------------- function delete_po($po) @@ -38,7 +70,7 @@ 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) VALUES("; + requisition_no, 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) . "', " . @@ -47,7 +79,8 @@ function add_po(&$po_obj) db_escape($po_obj->Location) . ", " . db_escape($po_obj->delivery_address) . ", " . db_escape($po_obj->get_trans_total()). ", " . - db_escape($po_obj->tax_included) . ")"; + db_escape($po_obj->tax_included). ", " . + db_escape($po_obj->prep_amount). ")"; db_query($sql, "The purchase order header record could not be inserted"); @@ -92,6 +125,7 @@ function update_po(&$po_obj) ord_date='" . date2sql($po_obj->orig_order_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).", tax_included=". db_escape($po_obj->tax_included); $sql .= " WHERE order_no = " . $po_obj->order_no; db_query($sql, "The purchase order could not be updated"); @@ -113,10 +147,15 @@ function update_po(&$po_obj) .db_escape($po_line->price) . ", " .db_escape($po_line->quantity) . ", " .db_escape($po_line->qty_received) . ")"; - 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); add_audit_trail($po_obj->trans_type, $po_obj->order_no, Today(), _("Updated.")); @@ -130,8 +169,9 @@ function update_po(&$po_obj) function read_po_header($order_no, &$order) { - $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.tax_group_id, - ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name + $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 @@ -146,9 +186,9 @@ function read_po_header($order_no, &$order) $order->trans_type = ST_PURCHORDER; $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_algorithm"]); $order->credit = get_current_supp_credit($order->supplier_id); @@ -158,6 +198,9 @@ function read_po_header($order_no, &$order) $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); return true; } @@ -253,10 +296,9 @@ function get_short_info($stock_id) return db_query($sql,"The stock details for " . $stock_id . " could not be retrieved"); } -function get_sql_for_po_search_completed($supplier_id=ALL_TEXT) +function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT, + $order_number = '', $stock_id = '') { - global $order_number, $selected_stock_item;; - $sql = "SELECT porder.order_no, porder.reference, @@ -275,42 +317,40 @@ function get_sql_for_po_search_completed($supplier_id=ALL_TEXT) AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location "; - if (isset($_GET['supplier_id'])) - $sql .= "AND supplier.supplier_id=".@$_GET['supplier_id']." "; - if (isset($order_number) && $order_number != "") + if ($supplier_id != ALL_TEXT) + $sql .= "AND supplier.supplier_id=".$supplier_id." "; + if ($order_number != "") { $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); } else { - $data_after = date2sql($_POST['OrdersAfterDate']); - $date_before = date2sql($_POST['OrdersToDate']); + $data_after = date2sql($from); + $date_before = date2sql($to); $sql .= " AND porder.ord_date >= '$data_after'"; $sql .= " AND porder.ord_date <= '$date_before'"; - if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT) + if ($location != ALL_TEXT) { - $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); + $sql .= " AND porder.into_stock_location = ".db_escape($location); } - if (isset($selected_stock_item)) + if ($stock_id !== '') { - $sql .= " AND line.item_code=".db_escape($selected_stock_item); + $sql .= " AND line.item_code=".db_escape($stock_id); } if ($supplier_id != ALL_TEXT) $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); - - } //end not order number selected + + } $sql .= " GROUP BY porder.order_no"; return $sql; -} +} -function get_sql_for_po_search($supplier_id=ALL_TEXT) +function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT, $order_number='', $stock_id='') { - global $all_items, $order_number, $selected_stock_item;; - $sql = "SELECT porder.order_no, porder.reference, @@ -332,26 +372,26 @@ function get_sql_for_po_search($supplier_id=ALL_TEXT) AND location.loc_code = porder.into_stock_location AND (line.quantity_ordered > line.quantity_received) "; - if (isset($order_number) && $order_number != "") + if ($order_number != "") { $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); } else { - $data_after = date2sql($_POST['OrdersAfterDate']); - $data_before = date2sql($_POST['OrdersToDate']); + $data_after = date2sql($from); + $data_before = date2sql($to); $sql .= " AND porder.ord_date >= '$data_after'"; $sql .= " AND porder.ord_date <= '$data_before'"; - if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) + if ($location != ALL_TEXT) { - $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); + $sql .= " AND porder.into_stock_location = ".db_escape($location); } - if (isset($selected_stock_item)) + if ($stock_id != '') { - $sql .= " AND line.item_code=".db_escape($selected_stock_item); + $sql .= " AND line.item_code=".db_escape($stock_id); } if ($supplier_id != ALL_TEXT) $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); @@ -360,4 +400,4 @@ function get_sql_for_po_search($supplier_id=ALL_TEXT) $sql .= " GROUP BY porder.order_no"; return $sql; } -?> \ No newline at end of file +