X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=purchasing%2Fincludes%2Fpurchasing_db.inc;h=2c480c7e52c8c3c7fb9dca4615d7ba3f9942af09;hb=1528943cad0e936781649f1dee6f7b778618eb60;hp=e98bd89a5d7b45884014f6b37d840b9a0b5e31ed;hpb=b76384515a4eca6456b6f045836e3c913244c78f;p=fa-stable.git diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index e98bd89a..2c480c7e 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -1,12 +1,20 @@ . +***********************************************************************/ include_once($path_to_root . "/includes/banking.inc"); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/db/inventory_db.inc"); +include_once($path_to_root . "/includes/db/allocations_db.inc"); include_once($path_to_root . "/purchasing/includes/db/supp_trans_db.inc"); include_once($path_to_root . "/purchasing/includes/db/po_db.inc"); @@ -23,14 +31,14 @@ include_once($path_to_root . "/purchasing/includes/db/suppliers_db.inc"); // $amount is in SUPPLIERS'S currency function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2, - $amount, $supplier_id, $err_msg="", $rate=0) + $amount, $supplier_id, $err_msg="", $rate=0, $memo="") { if ($err_msg == "") $err_msg = "The supplier GL transaction could not be inserted"; - return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, "", + return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, $memo, $amount, get_supplier_currency($supplier_id), - payment_person_types::supplier(), $supplier_id, $err_msg, $rate); + PT_SUPPLIER, $supplier_id, $err_msg, $rate); } //---------------------------------------------------------------------------------------- @@ -38,8 +46,8 @@ function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $d function get_purchase_price($supplier_id, $stock_id) { $sql = "SELECT price, conversion_factor FROM ".TB_PREF."purch_data - WHERE supplier_id = '" . $supplier_id . "' - AND stock_id = '". $stock_id . "'"; + WHERE supplier_id = ".db_escape($supplier_id) . " + AND stock_id = ".db_escape($stock_id); $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved"); if (db_num_rows($result) == 1) @@ -53,13 +61,30 @@ function get_purchase_price($supplier_id, $stock_id) } } +function get_purchase_conversion_factor($supplier_id, $stock_id) +{ + $sql = "SELECT conversion_factor FROM ".TB_PREF."purch_data + WHERE supplier_id = ".db_escape($supplier_id)." + AND stock_id = ".db_escape($stock_id); + $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved"); + + if (db_num_rows($result) == 1) + { + $myrow = db_fetch($result); + return $myrow['conversion_factor']; + } + else + { + return 1; + } +} //---------------------------------------------------------------------------------------- function get_purchase_data($supplier_id, $stock_id) { $sql = "SELECT * FROM ".TB_PREF."purch_data - WHERE supplier_id = '" . $supplier_id . "' - AND stock_id = '". $stock_id . "'"; + WHERE supplier_id = ".db_escape($supplier_id) . " + AND stock_id = ".db_escape($stock_id); $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved"); return db_fetch($result); @@ -71,20 +96,46 @@ function add_or_update_purchase_data($supplier_id, $stock_id, $price, $descripti if ($data === false) { $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom, - conversion_factor, supplier_description) VALUES ('$supplier_id', '$stock_id', - $price, '$uom', 1, '$description')"; + conversion_factor, supplier_description) VALUES (".db_escape($supplier_id) + .", ".db_escape($stock_id).", ".db_escape($price).", " + .db_escape($uom).", 1, ".db_escape($description).")"; db_query($sql,"The supplier purchasing details could not be added"); return; } - $price = round($price * $data['conversion_factor'], user_price_dec()); - $sql = "UPDATE ".TB_PREF."purch_data SET price=$price"; + $price = round($price * $data['conversion_factor'], user_price_dec()); + $sql = "UPDATE ".TB_PREF."purch_data SET price=".db_escape($price); if ($uom != "") - $sql .= ",suppliers_uom='$uom'"; + $sql .= ",suppliers_uom=".db_escape($uom); if ($description != "") - $sql .= ",supplier_description='$description'"; - $sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'"; + $sql .= ",supplier_description=".db_escape($description); + $sql .= " WHERE stock_id=".db_escape($stock_id)." AND supplier_id=".db_escape($supplier_id); db_query($sql,"The supplier purchasing details could not be updated"); return true; } +function get_po_prepayments($supp_trans) +{ + // collect purchase order line ids + $allocations = array(); + $line_ids = array(); + foreach($supp_trans->grn_items as $item) + $line_ids[] = $item->po_detail_item; + + if (!count($line_ids)) + return $allocations; + + $sql = "SELECT DISTINCT allocs.* + FROM ".TB_PREF."supp_allocations allocs + LEFT JOIN ".TB_PREF."purch_order_details line ON line.order_no=allocs.trans_no_to AND trans_type_to=".ST_PURCHORDER." + WHERE line.po_detail_item IN(".implode(',', array_values($line_ids)).")"; +//_vd($sql); + $result = db_query($sql, "Cannot retrieve po prepayments"); + + while($dat = db_fetch($result)) + { + $allocations[] = $dat; + } + + return $allocations; +} ?> \ No newline at end of file