X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fpurchasing_db.inc;h=89b7533e849fa6eda1da77c141d5b703af66c6a5;hb=2cb57633d2f3e27b0c2b2e7448564f467e21e1fd;hp=9ab331fe819bf33e0969f66eb4d0059013f1b0b0;hpb=da8311619dd73feae101d246a1957b972e00cbd2;p=fa-stable.git diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index 9ab331fe..89b7533e 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -1,5 +1,14 @@ . +***********************************************************************/ include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc"); include_once($path_to_root . "/includes/banking.inc"); @@ -23,14 +32,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="") + $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); + PT_SUPPLIER, $supplier_id, $err_msg, $rate); } //---------------------------------------------------------------------------------------- @@ -53,7 +62,55 @@ 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 = '" . $supplier_id . "' + AND stock_id = '". $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 . "'"; + $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved"); + + return db_fetch($result); +} + +function add_or_update_purchase_data($supplier_id, $stock_id, $price, $description="", $uom="") +{ + $data = get_purchase_data($supplier_id, $stock_id); + 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, ".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"; + if ($uom != "") + $sql .= ",suppliers_uom='$uom'"; + if ($description != "") + $sql .= ",supplier_description=".db_escape($description); + $sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'"; + db_query($sql,"The supplier purchasing details could not be updated"); + return true; +} ?> \ No newline at end of file