From: Joe Hunt Date: Fri, 4 Dec 2009 00:39:54 +0000 (+0000) Subject: Moved all SQL statements from PHP files into relevant *_db.inc files. X-Git-Tag: v2.4.2~19^2~1011 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=e2fa1c1b9543dedb3cd0a3a36dc539c86f7ff473;p=fa-stable.git Moved all SQL statements from PHP files into relevant *_db.inc files. Included purchasing folder --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 96990eb0..1d8e60ba 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,29 @@ Legend: ! -> Note $ -> Affected files +04-Dec-2009 Joe Hunt +! Moved all SQL statements from PHP files into relevant *_db.inc files. + Included purchasing folder +$ /includes/db/manufacturing_db.inc + /manufacturing/search_work_orders.php + /manufacturing/work_order_costs.php + /manufacturing/includes/db/work_orders_db.inc + /manufacturing/inquiry/where_used_inquiry.php + /manufacturing/manage/bom_edit.php + /manufacturing/manage/work_centres.php + /purchasing/po_entry_items.php + /purchasing/supplier_credit.php + /purchasing/supplier_invoice.php + /purchasing/includes/db/invoice_db.inc + /purchasing/includes/db/po_db.inc + /purchasing/includes/db/suppalloc_db.inc + /purchasing/includes/db/supp_trans_db.inc + /purchasing/inquiry/po_search.php + /purchasing/inquiry/po_search_completed.php + /purchasing/inquiry/supplier_allocations_inquiry.php + /purchasing/inquiry/supplier_inquiry.php + /purchasing/manage/suppliers.php + 03-Dec-2009 Joe Hunt ! Moved all SQL statements from PHP files into relevant *_db.inc files. Included inventory folder diff --git a/includes/db/manufacturing_db.inc b/includes/db/manufacturing_db.inc index 31fb3ece..14927475 100644 --- a/includes/db/manufacturing_db.inc +++ b/includes/db/manufacturing_db.inc @@ -191,6 +191,35 @@ function get_mb_flag($stock_id) //-------------------------------------------------------------------------------------- +function add_bom($selected_parent, $component, $workcentre_added, $loc_code, $quantity) +{ + $sql = "INSERT INTO ".TB_PREF."bom (parent, component, workcentre_added, loc_code, quantity) + VALUES (".db_escape($selected_parent).", ".db_escape($component) . "," + .db_escape($workcentre_added) . ", ".db_escape($loc_code) . ", " + . $quantity . ")"; + + db_query($sql,"check failed"); +} +//-------------------------------------------------------------------------------------- + +function update_bom($selected_parent, $selected_component, $work_centre_added, $loc_code, $quantity) +{ + $sql = "UPDATE ".TB_PREF."bom SET workcentre_added=".db_escape($workcentre_added) + . ",loc_code=".db_escape($loc_code) . ", + quantity= " . $quantity . " + WHERE parent=".db_escape($selected_parent) . " + AND id=".db_escape($selected_component); + check_db_error("Could not update this bom component", $sql); + + db_query($sql,"could not update bom"); +} + +function delete_bom($selected_id) +{ + $sql = "DELETE FROM ".TB_PREF."bom WHERE id=".db_escape($selected_id); + db_query($sql,"Could not delete this bom components"); +} + function get_bom($item) { $sql = "SELECT ".TB_PREF."bom.*, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreDescription, @@ -207,6 +236,18 @@ function get_bom($item) //-------------------------------------------------------------------------------------- +function get_component_from_bom($selected_id) +{ + $sql = "SELECT ".TB_PREF."bom.*,".TB_PREF."stock_master.description FROM " + .TB_PREF."bom,".TB_PREF."stock_master + WHERE id=".db_escape($selected_id)." + AND ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.component"; + + $result = db_query($sql, "could not get bom"); + return db_fetch($result); +} +//-------------------------------------------------------------------------------------- + function has_bom($item) { $result = get_bom($item); @@ -216,4 +257,46 @@ function has_bom($item) //-------------------------------------------------------------------------------------- +function is_component_already_on_bom($component, $workcentre_added, $loc_code, $selected_parent) +{ + $sql = "SELECT component FROM ".TB_PREF."bom + WHERE parent=".db_escape($selected_parent)." + AND component=".db_escape($component) . " + AND workcentre_added=".db_escape($workcentre_added) . " + AND loc_code=".db_escape($loc_code); + $result = db_query($sql,"check failed"); + + return (db_num_rows($result) > 0); +} + +//-------------------------------------------------------------------------------------- + +function check_for_recursive_bom($ultimate_parent, $component_to_check) +{ + + /* returns true ie 1 if the bom contains the parent part as a component + ie the bom is recursive otherwise false ie 0 */ + + $sql = "SELECT component FROM ".TB_PREF."bom WHERE parent=".db_escape($component_to_check); + $result = db_query($sql,"could not check recursive bom"); + + if ($result != 0) + { + while ($myrow = db_fetch_row($result)) + { + if ($myrow[0] == $ultimate_parent) + { + return 1; + } + + if (check_for_recursive_bom($ultimate_parent, $myrow[0])) + { + return 1; + } + } //(while loop) + } //end if $result is true + + return 0; +} //end of function check_for_recursive_bom + ?> diff --git a/manufacturing/includes/db/work_orders_db.inc b/manufacturing/includes/db/work_orders_db.inc index f97f87a5..7e8be648 100644 --- a/manufacturing/includes/db/work_orders_db.inc +++ b/manufacturing/includes/db/work_orders_db.inc @@ -309,6 +309,78 @@ function void_work_order($woid) } } +function get_sql_for_work_orders($outstanding_only, $all_items) +{ + $sql = "SELECT + workorder.id, + workorder.wo_ref, + workorder.type, + location.location_name, + item.description, + workorder.units_reqd, + workorder.units_issued, + workorder.date_, + workorder.required_by, + workorder.released_date, + workorder.closed, + workorder.released, + workorder.stock_id, + unit.decimals + FROM ".TB_PREF."workorders as workorder," + .TB_PREF."stock_master as item," + .TB_PREF."item_units as unit," + .TB_PREF."locations as location + WHERE workorder.stock_id=item.stock_id + AND workorder.loc_code=location.loc_code + AND item.units=unit.abbr"; + + if (check_value('OpenOnly') || $outstanding_only != 0) + { + $sql .= " AND workorder.closed=0"; + } + + if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) + { + $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']); + } + + if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "") + { + $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%'); + } + + if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items) + { + $sql .= " AND workorder.stock_id=".db_escape($_POST['SelectedStockItem']); + } + + if (check_value('OverdueOnly')) + { + $Today = date2sql(Today()); + + $sql .= " AND workorder.required_by < '$Today' "; + } + return $sql; +} + +function get_sql_for_where_used() +{ + $sql = "SELECT + bom.parent, + workcentre.name As WorkCentreName, + location.location_name, + bom.quantity, + parent.description + FROM ".TB_PREF."bom as bom, " + .TB_PREF."stock_master as parent, " + .TB_PREF."workcentres as workcentre, " + .TB_PREF."locations as location + WHERE bom.parent = parent.stock_id + AND bom.workcentre_added = workcentre.id + AND bom.loc_code = location.loc_code + AND bom.component=".db_escape($_POST['stock_id']); + return $sql; +} //-------------------------------------------------------------------------------------- ?> \ No newline at end of file diff --git a/manufacturing/inquiry/where_used_inquiry.php b/manufacturing/inquiry/where_used_inquiry.php index 14286c0a..10fce898 100644 --- a/manufacturing/inquiry/where_used_inquiry.php +++ b/manufacturing/inquiry/where_used_inquiry.php @@ -37,20 +37,7 @@ function select_link($row) "/manufacturing/manage/bom_edit.php?stock_id=" . $row["parent"]); } -$sql = "SELECT - bom.parent, - workcentre.name As WorkCentreName, - location.location_name, - bom.quantity, - parent.description - FROM ".TB_PREF."bom as bom, " - .TB_PREF."stock_master as parent, " - .TB_PREF."workcentres as workcentre, " - .TB_PREF."locations as location - WHERE bom.parent = parent.stock_id - AND bom.workcentre_added = workcentre.id - AND bom.loc_code = location.loc_code - AND bom.component=".db_escape($_POST['stock_id']); +$sql = get_sql_for_where_used(); $cols = array( _("Parent Item") => array('fun'=>'select_link'), diff --git a/manufacturing/manage/bom_edit.php b/manufacturing/manage/bom_edit.php index 742c2b1a..e963d563 100644 --- a/manufacturing/manage/bom_edit.php +++ b/manufacturing/manage/bom_edit.php @@ -62,43 +62,12 @@ else //-------------------------------------------------------------------------------------------------- -function check_for_recursive_bom($ultimate_parent, $component_to_check) -{ - - /* returns true ie 1 if the bom contains the parent part as a component - ie the bom is recursive otherwise false ie 0 */ - - $sql = "SELECT component FROM ".TB_PREF."bom WHERE parent=".db_escape($component_to_check); - $result = db_query($sql,"could not check recursive bom"); - - if ($result != 0) - { - while ($myrow = db_fetch_row($result)) - { - if ($myrow[0] == $ultimate_parent) - { - return 1; - } - - if (check_for_recursive_bom($ultimate_parent, $myrow[0])) - { - return 1; - } - } //(while loop) - } //end if $result is true - - return 0; - -} //end of function check_for_recursive_bom - -//-------------------------------------------------------------------------------------------------- - function display_bom_items($selected_parent) { global $table_style; $result = get_bom($selected_parent); -div_start('bom'); + div_start('bom'); start_table("$table_style width=60%"); $th = array(_("Code"), _("Description"), _("Location"), _("Work Centre"), _("Quantity"), _("Units"),'',''); @@ -122,7 +91,7 @@ div_start('bom'); } //END WHILE LIST LOOP end_table(); -div_end(); + div_end(); } //-------------------------------------------------------------------------------------------------- @@ -138,15 +107,8 @@ function on_submit($selected_parent, $selected_component=-1) if ($selected_component != -1) { - - $sql = "UPDATE ".TB_PREF."bom SET workcentre_added=".db_escape($_POST['workcentre_added']) - . ",loc_code=".db_escape($_POST['loc_code']) . ", - quantity= " . input_num('quantity') . " - WHERE parent=".db_escape($selected_parent) . " - AND id=".db_escape($selected_component); - check_db_error("Could not update this bom component", $sql); - - db_query($sql,"could not update bom"); + update_bom($selected_parent, $selected_component, $_POST['workcentre_added'], $_POST['loc_code'], + input_num('quantity')); display_notification(_('Selected component has been updated')); $Mode = 'RESET'; } @@ -162,21 +124,11 @@ function on_submit($selected_parent, $selected_component=-1) { /*Now check to see that the component is not already on the bom */ - $sql = "SELECT component FROM ".TB_PREF."bom - WHERE parent=".db_escape($selected_parent)." - AND component=".db_escape($_POST['component']) . " - AND workcentre_added=".db_escape($_POST['workcentre_added']) . " - AND loc_code=".db_escape($_POST['loc_code']); - $result = db_query($sql,"check failed"); - - if (db_num_rows($result) == 0) + if (!is_component_already_on_bom($_POST['component'], $_POST['workcentre_added'], + $_POST['loc_code'], $selected_parent)) { - $sql = "INSERT INTO ".TB_PREF."bom (parent, component, workcentre_added, loc_code, quantity) - VALUES (".db_escape($selected_parent).", ".db_escape($_POST['component']) . "," - .db_escape($_POST['workcentre_added']) . ", ".db_escape($_POST['loc_code']) . ", " - . input_num('quantity') . ")"; - - db_query($sql,"check failed"); + add_bom($selected_parent, $_POST['component'], $_POST['workcentre_added'], + $_POST['loc_code'], input_num('quantity')); display_notification(_("A new component part has been added to the bill of material for this item.")); $Mode = 'RESET'; } @@ -198,8 +150,7 @@ function on_submit($selected_parent, $selected_component=-1) if ($Mode == 'Delete') { - $sql = "DELETE FROM ".TB_PREF."bom WHERE id=".db_escape($selected_id); - db_query($sql,"Could not delete this bom components"); + delete_bom($selected_id); display_notification(_("The component item has been deleted from this bom")); $Mode = 'RESET'; @@ -244,19 +195,13 @@ start_form(); { if ($Mode == 'Edit') { //editing a selected component from the link to the line item - $sql = "SELECT ".TB_PREF."bom.*,".TB_PREF."stock_master.description FROM " - .TB_PREF."bom,".TB_PREF."stock_master - WHERE id=".db_escape($selected_id)." - AND ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.component"; - - $result = db_query($sql, "could not get bom"); - $myrow = db_fetch($result); + $myrow = get_component_from_bom($selected_id); $_POST['loc_code'] = $myrow["loc_code"]; $_POST['component'] = $myrow["component"]; // by Tom Moulton $_POST['workcentre_added'] = $myrow["workcentre_added"]; $_POST['quantity'] = number_format2($myrow["quantity"], get_qty_dec($myrow["component"])); - label_row(_("Component:"), $myrow["component"] . " - " . $myrow["description"]); + label_row(_("Component:"), $myrow["component"] . " - " . $myrow["description"]); } hidden('selected_id', $selected_id); } diff --git a/manufacturing/manage/work_centres.php b/manufacturing/manage/work_centres.php index 03014572..b9199690 100644 --- a/manufacturing/manage/work_centres.php +++ b/manufacturing/manage/work_centres.php @@ -56,19 +56,13 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') function can_delete($selected_id) { - $sql= "SELECT COUNT(*) FROM ".TB_PREF."bom WHERE workcentre_added=".db_escape($selected_id); - $result = db_query($sql, "check can delete work centre"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'bom', 'workcentre_added')) { display_error(_("Cannot delete this work centre because BOMs have been created referring to it.")); return false; } - - $sql= "SELECT COUNT(*) FROM ".TB_PREF."wo_requirements WHERE workcentre=".db_escape($selected_id); - $result = db_query($sql, "check can delete work centre"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + + if (key_in_foreign_table($selected_id, 'wo_requirements', 'workcentre')) { display_error(_("Cannot delete this work centre because work order requirements have been created referring to it.")); return false; diff --git a/manufacturing/search_work_orders.php b/manufacturing/search_work_orders.php index 3fdbf1df..f212a1a8 100644 --- a/manufacturing/search_work_orders.php +++ b/manufacturing/search_work_orders.php @@ -153,55 +153,7 @@ function dec_amount($row, $amount) return number_format2($amount, $row['decimals']); } -$sql = "SELECT - workorder.id, - workorder.wo_ref, - workorder.type, - location.location_name, - item.description, - workorder.units_reqd, - workorder.units_issued, - workorder.date_, - workorder.required_by, - workorder.released_date, - workorder.closed, - workorder.released, - workorder.stock_id, - unit.decimals - FROM ".TB_PREF."workorders as workorder," - .TB_PREF."stock_master as item," - .TB_PREF."item_units as unit," - .TB_PREF."locations as location - WHERE workorder.stock_id=item.stock_id - AND workorder.loc_code=location.loc_code - AND item.units=unit.abbr"; - -if (check_value('OpenOnly') || $outstanding_only != 0) -{ - $sql .= " AND workorder.closed=0"; -} - -if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) -{ - $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']); -} - -if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "") -{ - $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%'); -} - -if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items) -{ - $sql .= " AND workorder.stock_id=".db_escape($_POST['SelectedStockItem']); -} - -if (check_value('OverdueOnly')) -{ - $Today = date2sql(Today()); - - $sql .= " AND workorder.required_by < '$Today' "; -} +$sql = get_sql_for_work_orders($outstanding_only, $all_items); $cols = array( _("#") => array('fun'=>'view_link'), diff --git a/manufacturing/work_order_costs.php b/manufacturing/work_order_costs.php index 4e7f0537..2e72cf10 100644 --- a/manufacturing/work_order_costs.php +++ b/manufacturing/work_order_costs.php @@ -143,9 +143,7 @@ date_row(_("Date:"), 'date_'); $item_accounts = get_stock_gl_code($wo_details['stock_id']); $_POST['db_acc'] = $item_accounts['assembly_account']; -$sql = "SELECT DISTINCT account_code FROM ".TB_PREF."bank_accounts"; -$rs = db_query($sql,"could not get bank accounts"); -$r = db_fetch_row($rs); +$r = get_default_bank_account(get_company_pref('curr_default')); $_POST['cr_acc'] = $r[0]; amount_row(_("Additional Costs:"), 'costs'); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index ffdb8c17..ec3e14a8 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -505,6 +505,47 @@ function void_supp_invoice($type, $type_no) } //---------------------------------------------------------------------------------------- +function get_gl_account_info($acc) +{ + $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code=".db_escape($acc); + return db_query($sql,"get account information"); +} + +function is_reference_already_there($supplier_id, $supp_reference) +{ + $sql = "SELECT Count(*) FROM ".TB_PREF."supp_trans WHERE supplier_id=" + .db_escape($supplier_id) . " AND supp_reference=" + .db_escape($supp_reference) + . " AND ov_amount!=0"; // ignore voided invoice references + + $result=db_query($sql,"The sql to check for the previous entry of the same invoice failed"); + + $myrow = db_fetch_row($result); + return ($myrow[0] == 1); +} + +function remove_not_invoice_item($id) +{ + begin_transaction(); + + $myrow = get_grn_item_detail($id); + + $grn = get_grn_batch($myrow['grn_batch_id']); + $sql = "UPDATE ".TB_PREF."purch_order_details + SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"]; + db_query($sql, "The quantity invoiced of the purchase order line could not be updated"); + + $sql = "UPDATE ".TB_PREF."grn_items + SET qty_recd = quantity_inv WHERE id = ".$myrow["id"]; + db_query($sql, "The quantity invoiced off the items received record could not be updated"); + update_average_material_cost($grn["supplier_id"], $myrow["item_code"], + $myrow["unit_price"], -$myrow["QtyOstdg"], Today()); + + add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "", + -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']); + + commit_transaction(); +} ?> diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index ee2b7d8e..e89d9603 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -227,5 +227,126 @@ function read_po($order_no, &$order, $open_items_only=false) //---------------------------------------------------------------------------------------- +function get_po_items($order_no) +{ + $sql = "SELECT item_code, quantity_ordered, quantity_received, qty_invoiced + FROM ".TB_PREF."purch_order_details + WHERE order_no=".db_escape($order_no) + ." ORDER BY po_detail_item"; + + $result = db_query($sql, "could not query purch order details"); + check_db_error("Could not check that the details of the purchase order had not been changed by another user ", $sql); + return $result; +} +//---------------------------------------------------------------------------------------- + +function get_short_info($stock_id) +{ + $sql = "SELECT description, units, mb_flag + FROM ".TB_PREF."stock_master WHERE stock_id = ".db_escape($stock_id); + + return db_query($sql,"The stock details for " . $stock_id . " could not be retrieved"); +} + +function get_sql_for_po_search_completed() +{ + global $order_number, $selected_stock_item;; + + $sql = "SELECT + porder.order_no, + porder.reference, + supplier.supp_name, + location.location_name, + porder.requisition_no, + porder.ord_date, + supplier.curr_code, + Sum(line.unit_price*line.quantity_ordered) AS OrderValue, + porder.into_stock_location + FROM ".TB_PREF."purch_orders as porder, " + .TB_PREF."purch_order_details as line, " + .TB_PREF."suppliers as supplier, " + .TB_PREF."locations as location + WHERE porder.order_no = line.order_no + AND porder.supplier_id = supplier.supplier_id + AND location.loc_code = porder.into_stock_location "; + + if (isset($order_number) && $order_number != "") + { + $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); + } + else + { + + $data_after = date2sql($_POST['OrdersAfterDate']); + $date_before = date2sql($_POST['OrdersToDate']); + + $sql .= " AND porder.ord_date >= '$data_after'"; + $sql .= " AND porder.ord_date <= '$date_before'"; + + if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT) + { + $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); + } + if (isset($selected_stock_item)) + { + $sql .= " AND line.item_code=".db_escape($selected_stock_item); + } + + } //end not order number selected + + $sql .= " GROUP BY porder.order_no"; + return $sql; +} + +function get_sql_for_po_search() +{ + global $all_items, $order_number, $selected_stock_item;; + + $sql = "SELECT + porder.order_no, + porder.reference, + supplier.supp_name, + location.location_name, + porder.requisition_no, + 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 + FROM " + .TB_PREF."purch_orders as porder, " + .TB_PREF."purch_order_details as line, " + .TB_PREF."suppliers as supplier, " + .TB_PREF."locations as location + WHERE porder.order_no = line.order_no + AND porder.supplier_id = supplier.supplier_id + AND location.loc_code = porder.into_stock_location + AND (line.quantity_ordered > line.quantity_received) "; + + if (isset($order_number) && $order_number != "") + { + $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); + } + else + { + $data_after = date2sql($_POST['OrdersAfterDate']); + $data_before = date2sql($_POST['OrdersToDate']); + + $sql .= " AND porder.ord_date >= '$data_after'"; + $sql .= " AND porder.ord_date <= '$data_before'"; + + if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) + { + $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); + } + if (isset($selected_stock_item)) + { + $sql .= " AND line.item_code=".db_escape($selected_stock_item); + } + } //end not order number selected + + $sql .= " GROUP BY porder.order_no"; + return $sql; +} ?> \ No newline at end of file diff --git a/purchasing/includes/db/supp_trans_db.inc b/purchasing/includes/db/supp_trans_db.inc index 2aa6d0b4..b9624809 100644 --- a/purchasing/includes/db/supp_trans_db.inc +++ b/purchasing/includes/db/supp_trans_db.inc @@ -151,4 +151,55 @@ function post_void_supp_trans($type, $type_no) //---------------------------------------------------------------------------------------- +function get_sql_for_supplier_inquiry() +{ + $date_after = date2sql($_POST['TransAfterDate']); + $date_to = date2sql($_POST['TransToDate']); + + $sql = "SELECT trans.type, + trans.trans_no, + trans.reference, + supplier.supp_name, + trans.supp_reference, + trans.tran_date, + trans.due_date, + supplier.curr_code, + (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount, + trans.alloc AS Allocated, + ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue, + (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) <= 0.005) AS Settled + FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as supplier + WHERE supplier.supplier_id = trans.supplier_id + AND trans.tran_date >= '$date_after' + AND trans.tran_date <= '$date_to' + AND trans.ov_amount != 0"; // exclude voided transactions + if ($_POST['supplier_id'] != ALL_TEXT) + $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']); + if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT) + { + if (($_POST['filterType'] == '1')) + { + $sql .= " AND (trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_BANKDEPOSIT.")"; + } + elseif (($_POST['filterType'] == '2')) + { + $sql .= " AND trans.type = ".ST_SUPPINVOICE." "; + } + elseif ($_POST['filterType'] == '3') + { + $sql .= " AND (trans.type = ".ST_SUPPAYMENT." OR trans.type = ".ST_BANKPAYMENT.") "; + } + elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5')) + { + $sql .= " AND trans.type = ".ST_SUPPCREDIT." "; + } + + if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5')) + { + $today = date2sql(Today()); + $sql .= " AND trans.due_date < '$today' "; + } + } + return $sql; +} ?> \ No newline at end of file diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index 987a640d..a68c9cfe 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -176,5 +176,58 @@ function get_allocatable_to_supp_transactions($supplier_id, $trans_no=null, $typ return db_query($sql." ORDER BY trans_no", "Cannot retreive alloc to transactions"); } +function get_sql_for_supplier_allocation_inquiry() +{ + $date_after = date2sql($_POST['TransAfterDate']); + $date_to = date2sql($_POST['TransToDate']); + $sql = "SELECT + trans.type, + trans.trans_no, + trans.reference, + supplier.supp_name, + trans.supp_reference, + trans.tran_date, + trans.due_date, + supplier.curr_code, + (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount, + trans.alloc AS Allocated, + ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue + FROM " + .TB_PREF."supp_trans as trans, " + .TB_PREF."suppliers as supplier + WHERE supplier.supplier_id = trans.supplier_id + AND trans.tran_date >= '$date_after' + AND trans.tran_date <= '$date_to'"; + + if ($_POST['supplier_id'] != ALL_TEXT) + $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']); + if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT) + { + if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2')) + { + $sql .= " AND trans.type = ".ST_SUPPINVOICE." "; + } + elseif ($_POST['filterType'] == '3') + { + $sql .= " AND trans.type = ".ST_SUPPAYMENT." "; + } + elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5')) + { + $sql .= " AND trans.type = ".ST_SUPPCREDIT." "; + } + + if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5')) + { + $today = date2sql(Today()); + $sql .= " AND trans.due_date < '$today' "; + } + } + + if (!check_value('showSettled')) + { + $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) "; + } + return $sql; +} ?> \ No newline at end of file diff --git a/purchasing/includes/db/suppliers_db.inc b/purchasing/includes/db/suppliers_db.inc index dd72a6cf..305ce5df 100644 --- a/purchasing/includes/db/suppliers_db.inc +++ b/purchasing/includes/db/suppliers_db.inc @@ -9,6 +9,80 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ + +function add_supplier($supp_name, $supp_ref, $address, $supp_address, $phone, $phone2, $fax, $gst_no, $email, + $website, $contact, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id, + $curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account, + $notes, $tax_group_id) +{ + $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, phone, phone2, fax, gst_no, email, website, + contact, supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code, + payment_terms, payable_account, purchase_account, payment_discount_account, notes, tax_group_id) + VALUES (".db_escape($_POST['supp_name']). ", " + .db_escape($supp_ref). ", " + .db_escape($address) . ", " + .db_escape($supp_address) . ", " + .db_escape($phone). ", " + .db_escape($phone2). ", " + .db_escape($fax). ", " + .db_escape($gst_no). ", " + .db_escape($email). ", " + .db_escape($website). ", " + .db_escape($contact). ", " + .db_escape($supp_account_no). ", " + .db_escape($bank_account). ", " + .$credit_limit. ", " + .db_escape($dimension_id). ", " + .db_escape($dimension2_id). ", " + .db_escape($curr_code). ", " + .db_escape($payment_terms). ", " + .db_escape($payable_account). ", " + .db_escape($purchase_account). ", " + .db_escape($payment_discount_account). ", " + .db_escape($notes). ", " + .db_escape($tax_group_id). ")"; + + db_query($sql,"The supplier could not be added"); +} + +function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_address, $phone, $phone2, $fax, $gst_no, + $email, $website, $contact, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id, + $curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account, + $notes, $tax_group_id) +{ + $sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($supp_name) . ", + supp_ref=".db_escape($supp_ref) . ", + address=".db_escape($address) . ", + supp_address=".db_escape($supp_address) . ", + phone=".db_escape($phone) . ", + phone2=".db_escape($phone2) . ", + fax=".db_escape($fax) . ", + gst_no=".db_escape($gst_no) . ", + email=".db_escape($email) . ", + website=".db_escape($website) . ", + contact=".db_escape($contact) . ", + supp_account_no=".db_escape($supp_account_no) . ", + bank_account=".db_escape($bank_account) . ", + credit_limit=".$credit_limit . ", + dimension_id=".db_escape($dimension_id) . ", + dimension2_id=".db_escape($dimension2_id) . ", + curr_code=".db_escape($curr_code).", + payment_terms=".db_escape($payment_terms) . ", + payable_account=".db_escape($payable_account) . ", + purchase_account=".db_escape($purchase_account) . ", + payment_discount_account=".db_escape($payment_discount_account) . ", + notes=".db_escape($notes) . ", + tax_group_id=".db_escape($tax_group_id) . " WHERE supplier_id = ".db_escape($supplier_id); + + db_query($sql,"The supplier could not be updated"); +} + +function delete_supplier($supplier_id) +{ + $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($supplier_id); + db_query($sql,"check failed"); +} + function get_supplier_details($supplier_id, $to=null) { diff --git a/purchasing/inquiry/po_search.php b/purchasing/inquiry/po_search.php index b43a99ff..e0108a40 100644 --- a/purchasing/inquiry/po_search.php +++ b/purchasing/inquiry/po_search.php @@ -116,53 +116,9 @@ else } //figure out the sql required from the inputs available -$sql = "SELECT - porder.order_no, - porder.reference, - supplier.supp_name, - location.location_name, - porder.requisition_no, - 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 - FROM " - .TB_PREF."purch_orders as porder, " - .TB_PREF."purch_order_details as line, " - .TB_PREF."suppliers as supplier, " - .TB_PREF."locations as location - WHERE porder.order_no = line.order_no - AND porder.supplier_id = supplier.supplier_id - AND location.loc_code = porder.into_stock_location - AND (line.quantity_ordered > line.quantity_received) "; - -if (isset($order_number) && $order_number != "") -{ - $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); -} -else -{ - $data_after = date2sql($_POST['OrdersAfterDate']); - $data_before = date2sql($_POST['OrdersToDate']); - - $sql .= " AND porder.ord_date >= '$data_after'"; - $sql .= " AND porder.ord_date <= '$data_before'"; - - if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) - { - $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); - } - - if (isset($selected_stock_item)) - { - $sql .= " AND line.item_code=".db_escape($selected_stock_item); - } -} //end not order number selected - -$sql .= " GROUP BY porder.order_no"; +$sql = get_sql_for_po_search(); -$result = db_query($sql,"No orders were returned"); +//$result = db_query($sql,"No orders were returned"); /*show a table of the orders returned by the sql */ $cols = array( diff --git a/purchasing/inquiry/po_search_completed.php b/purchasing/inquiry/po_search_completed.php index 1632f5b4..fad27dc5 100644 --- a/purchasing/inquiry/po_search_completed.php +++ b/purchasing/inquiry/po_search_completed.php @@ -105,49 +105,7 @@ function prt_link($row) //--------------------------------------------------------------------------------------------- -$sql = "SELECT - porder.order_no, - porder.reference, - supplier.supp_name, - location.location_name, - porder.requisition_no, - porder.ord_date, - supplier.curr_code, - Sum(line.unit_price*line.quantity_ordered) AS OrderValue, - porder.into_stock_location - FROM ".TB_PREF."purch_orders as porder, " - .TB_PREF."purch_order_details as line, " - .TB_PREF."suppliers as supplier, " - .TB_PREF."locations as location - WHERE porder.order_no = line.order_no - AND porder.supplier_id = supplier.supplier_id - AND location.loc_code = porder.into_stock_location "; - -if (isset($order_number) && $order_number != "") -{ - $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%'); -} -else -{ - - $data_after = date2sql($_POST['OrdersAfterDate']); - $date_before = date2sql($_POST['OrdersToDate']); - - $sql .= " AND porder.ord_date >= '$data_after'"; - $sql .= " AND porder.ord_date <= '$date_before'"; - - if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT) - { - $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']); - } - if (isset($selected_stock_item)) - { - $sql .= " AND line.item_code=".db_escape($selected_stock_item); - } - -} //end not order number selected - -$sql .= " GROUP BY porder.order_no"; +$sql = get_sql_for_po_search_completed(); $cols = array( _("#") => array('fun'=>'trans_view', 'ord'=>''), diff --git a/purchasing/inquiry/supplier_allocation_inquiry.php b/purchasing/inquiry/supplier_allocation_inquiry.php index 850dfc30..14cb3290 100644 --- a/purchasing/inquiry/supplier_allocation_inquiry.php +++ b/purchasing/inquiry/supplier_allocation_inquiry.php @@ -119,57 +119,7 @@ function fmt_credit($row) } //------------------------------------------------------------------------------------------------ - $date_after = date2sql($_POST['TransAfterDate']); - $date_to = date2sql($_POST['TransToDate']); - - // Sherifoz 22.06.03 Also get the description - $sql = "SELECT - trans.type, - trans.trans_no, - trans.reference, - supplier.supp_name, - trans.supp_reference, - trans.tran_date, - trans.due_date, - supplier.curr_code, - (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount, - trans.alloc AS Allocated, - ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue - FROM " - .TB_PREF."supp_trans as trans, " - .TB_PREF."suppliers as supplier - WHERE supplier.supplier_id = trans.supplier_id - AND trans.tran_date >= '$date_after' - AND trans.tran_date <= '$date_to'"; - - if ($_POST['supplier_id'] != ALL_TEXT) - $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']); - if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT) - { - if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2')) - { - $sql .= " AND trans.type = ".ST_SUPPINVOICE." "; - } - elseif ($_POST['filterType'] == '3') - { - $sql .= " AND trans.type = ".ST_SUPPAYMENT." "; - } - elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5')) - { - $sql .= " AND trans.type = ".ST_SUPPCREDIT." "; - } - - if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5')) - { - $today = date2sql(Today()); - $sql .= " AND trans.due_date < '$today' "; - } - } - - if (!check_value('showSettled')) - { - $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) "; - } +$sql = get_sql_for_supplier_allocation_inquiry(); $cols = array( _("Type") => array('fun'=>'systype_name'), diff --git a/purchasing/inquiry/supplier_inquiry.php b/purchasing/inquiry/supplier_inquiry.php index 264b5518..7a012905 100644 --- a/purchasing/inquiry/supplier_inquiry.php +++ b/purchasing/inquiry/supplier_inquiry.php @@ -156,54 +156,7 @@ function check_overdue($row) } //------------------------------------------------------------------------------------------------ - $date_after = date2sql($_POST['TransAfterDate']); - $date_to = date2sql($_POST['TransToDate']); - - // Sherifoz 22.06.03 Also get the description - $sql = "SELECT trans.type, - trans.trans_no, - trans.reference, - supplier.supp_name, - trans.supp_reference, - trans.tran_date, - trans.due_date, - supplier.curr_code, - (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount, - trans.alloc AS Allocated, - ((trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_SUPPCREDIT.") AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue, - (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) <= 0.005) AS Settled - FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as supplier - WHERE supplier.supplier_id = trans.supplier_id - AND trans.tran_date >= '$date_after' - AND trans.tran_date <= '$date_to' - AND trans.ov_amount != 0"; // exclude voided transactions - if ($_POST['supplier_id'] != ALL_TEXT) - $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']); - if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT) - { - if (($_POST['filterType'] == '1')) - { - $sql .= " AND (trans.type = ".ST_SUPPINVOICE." OR trans.type = ".ST_BANKDEPOSIT.")"; - } - elseif (($_POST['filterType'] == '2')) - { - $sql .= " AND trans.type = ".ST_SUPPINVOICE." "; - } - elseif ($_POST['filterType'] == '3') - { - $sql .= " AND (trans.type = ".ST_SUPPAYMENT." OR trans.type = ".ST_BANKPAYMENT.") "; - } - elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5')) - { - $sql .= " AND trans.type = ".ST_SUPPCREDIT." "; - } - - if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5')) - { - $today = date2sql(Today()); - $sql .= " AND trans.due_date < '$today' "; - } - } +$sql = get_sql_for_supplier_inquiry(); $cols = array( _("Type") => array('fun'=>'systype_name', 'ord'=>''), diff --git a/purchasing/manage/suppliers.php b/purchasing/manage/suppliers.php index 0c94f251..f5f9445e 100644 --- a/purchasing/manage/suppliers.php +++ b/purchasing/manage/suppliers.php @@ -57,32 +57,12 @@ if (isset($_POST['submit'])) if (!$new_supplier) { - - $sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($_POST['supp_name']) . ", - supp_ref=".db_escape($_POST['supp_ref']) . ", - address=".db_escape($_POST['address']) . ", - supp_address=".db_escape($_POST['supp_address']) . ", - phone=".db_escape($_POST['phone']) . ", - phone2=".db_escape($_POST['phone2']) . ", - fax=".db_escape($_POST['fax']) . ", - gst_no=".db_escape($_POST['gst_no']) . ", - email=".db_escape($_POST['email']) . ", - website=".db_escape($_POST['website']) . ", - contact=".db_escape($_POST['contact']) . ", - supp_account_no=".db_escape($_POST['supp_account_no']) . ", - bank_account=".db_escape($_POST['bank_account']) . ", - credit_limit=".input_num('credit_limit', 0) . ", - dimension_id=".db_escape($_POST['dimension_id']) . ", - dimension2_id=".db_escape($_POST['dimension2_id']) . ", - curr_code=".db_escape($_POST['curr_code']).", - payment_terms=".db_escape($_POST['payment_terms']) . ", - payable_account=".db_escape($_POST['payable_account']) . ", - purchase_account=".db_escape($_POST['purchase_account']) . ", - payment_discount_account=".db_escape($_POST['payment_discount_account']) . ", - notes=".db_escape($_POST['notes']) . ", - tax_group_id=".db_escape($_POST['tax_group_id']) . " WHERE supplier_id = ".db_escape($_POST['supplier_id']); - - db_query($sql,"The supplier could not be updated"); + update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], + $_POST['supp_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'], + $_POST['email'], $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'], + input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'], + $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'], + $_POST['notes'], $_POST['tax_group_id']); update_record_status($_POST['supplier_id'], $_POST['inactive'], 'suppliers', 'supplier_id'); @@ -91,35 +71,13 @@ if (isset($_POST['submit'])) } else { + add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'], + $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['gst_no'], $_POST['email'], + $_POST['website'], $_POST['contact'], $_POST['supp_account_no'], $_POST['bank_account'], + input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'], + $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], + $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id']); - $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, phone, phone2, fax, gst_no, email, website, - contact, supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code, - payment_terms, payable_account, purchase_account, payment_discount_account, notes, tax_group_id) - VALUES (".db_escape($_POST['supp_name']). ", " - .db_escape($_POST['supp_ref']). ", " - .db_escape($_POST['address']) . ", " - .db_escape($_POST['supp_address']) . ", " - .db_escape($_POST['phone']). ", " - .db_escape($_POST['phone2']). ", " - .db_escape($_POST['fax']). ", " - .db_escape($_POST['gst_no']). ", " - .db_escape($_POST['email']). ", " - .db_escape($_POST['website']). ", " - .db_escape($_POST['contact']). ", " - .db_escape($_POST['supp_account_no']). ", " - .db_escape($_POST['bank_account']). ", " - .input_num('credit_limit',0). ", " - .db_escape($_POST['dimension_id']). ", " - .db_escape($_POST['dimension2_id']). ", " - .db_escape($_POST['curr_code']). ", " - .db_escape($_POST['payment_terms']). ", " - .db_escape($_POST['payable_account']). ", " - .db_escape($_POST['purchase_account']). ", " - .db_escape($_POST['payment_discount_account']). ", " - .db_escape($_POST['notes']). ", " - .db_escape($_POST['tax_group_id']). ")"; - - db_query($sql,"The supplier could not be added"); $_POST['supplier_id'] = db_insert_id(); $new_supplier = false; display_notification(_("A new supplier has been added.")); @@ -136,10 +94,7 @@ elseif (isset($_POST['delete']) && $_POST['delete'] != "") // PREVENT DELETES IF DEPENDENT RECORDS IN 'supp_trans' , purch_orders - $sql= "SELECT COUNT(*) FROM ".TB_PREF."supp_trans WHERE supplier_id=".db_escape($_POST['supplier_id']); - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id')) { $cancel_delete = 1; display_error(_("Cannot delete this supplier because there are transactions that refer to this supplier.")); @@ -147,10 +102,7 @@ elseif (isset($_POST['delete']) && $_POST['delete'] != "") } else { - $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE supplier_id=".db_escape($_POST['supplier_id']); - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id')) { $cancel_delete = 1; display_error(_("Cannot delete the supplier record because purchase orders have been created against this supplier.")); @@ -159,8 +111,7 @@ elseif (isset($_POST['delete']) && $_POST['delete'] != "") } if ($cancel_delete == 0) { - $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($_POST['supplier_id']); - db_query($sql,"check failed"); + delete_supplier($_POST['supplier_id']); unset($_SESSION['supplier_id']); $new_supplier = true; diff --git a/purchasing/po_entry_items.php b/purchasing/po_entry_items.php index 988c90fa..a09b2e14 100644 --- a/purchasing/po_entry_items.php +++ b/purchasing/po_entry_items.php @@ -227,10 +227,7 @@ function handle_add_new_item() if ($allow_update == true) { - $sql = "SELECT description, units, mb_flag - FROM ".TB_PREF."stock_master WHERE stock_id = ".db_escape($_POST['stock_id']); - - $result = db_query($sql,"The stock details for " . $_POST['stock_id'] . " could not be retrieved"); + $result = get_short_info($_POST['stock_id']); if (db_num_rows($result) == 0) { diff --git a/purchasing/po_receive_items.php b/purchasing/po_receive_items.php index bfb8371c..9ac5becd 100644 --- a/purchasing/po_receive_items.php +++ b/purchasing/po_receive_items.php @@ -119,13 +119,7 @@ function check_po_changed() /*Now need to check that the order details are the same as they were when they were read into the Items array. If they've changed then someone else must have altered them */ // Sherifoz 22.06.03 Compare against COMPLETED items only !! // Otherwise if you try to fullfill item quantities separately will give error. - $sql = "SELECT item_code, quantity_ordered, quantity_received, qty_invoiced - FROM ".TB_PREF."purch_order_details - WHERE order_no=".db_escape($_SESSION['PO']->order_no) - ." ORDER BY po_detail_item"; - - $result = db_query($sql, "could not query purch order details"); - check_db_error("Could not check that the details of the purchase order had not been changed by another user ", $sql); + $result = get_po_items($_SESSION['PO']->order_no); $line_no = 1; while ($myrow = db_fetch($result)) diff --git a/purchasing/supplier_credit.php b/purchasing/supplier_credit.php index 1a8d63e9..69ead86d 100644 --- a/purchasing/supplier_credit.php +++ b/purchasing/supplier_credit.php @@ -97,8 +97,7 @@ if (isset($_POST['AddGLCodeToTrans'])){ $Ajax->activate('gl_items'); $input_error = false; - $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code=".db_escape($_POST['gl_code']); - $result = db_query($sql,"get account information"); + $result = get_gl_account_info($_POST['gl_code']); if (db_num_rows($result) == 0) { display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction.")); diff --git a/purchasing/supplier_invoice.php b/purchasing/supplier_invoice.php index 34406781..6b24fe27 100644 --- a/purchasing/supplier_invoice.php +++ b/purchasing/supplier_invoice.php @@ -99,8 +99,7 @@ if (isset($_POST['AddGLCodeToTrans'])){ $Ajax->activate('gl_items'); $input_error = false; - $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code=".db_escape($_POST['gl_code']); - $result = db_query($sql,"get account information"); + $result = get_gl_account_info($_POST['gl_code']); if (db_num_rows($result) == 0) { display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction.")); @@ -186,15 +185,7 @@ function check_data() return false; } - $sql = "SELECT Count(*) FROM ".TB_PREF."supp_trans WHERE supplier_id=" - .db_escape($_SESSION['supp_trans']->supplier_id) . " AND supp_reference=" - .db_escape( $_POST['supp_reference']) - . " AND ov_amount!=0"; // ignore voided invoice references - - $result=db_query($sql,"The sql to check for the previous entry of the same invoice failed"); - - $myrow = db_fetch_row($result); - if ($myrow[0] == 1) + if (is_reference_already_there($_SESSION['supp_trans']->supplier_id, $_POST['supp_reference'])) { /*Transaction reference already entered */ display_error(_("This invoice number has already been entered. It cannot be entered again." . " (" . $_POST['supp_reference'] . ")")); return false; @@ -342,27 +333,7 @@ if ($_SESSION["wa_current_user"]->can_access('SA_GRNDELETE')) $id2 = find_submit('void_item_id'); if ($id2 != -1) { - begin_transaction(); - - $myrow = get_grn_item_detail($id2); - - $grn = get_grn_batch($myrow['grn_batch_id']); - - $sql = "UPDATE ".TB_PREF."purch_order_details - SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"]; - db_query($sql, "The quantity invoiced of the purchase order line could not be updated"); - - $sql = "UPDATE ".TB_PREF."grn_items - SET qty_recd = quantity_inv WHERE id = ".$myrow["id"]; - db_query($sql, "The quantity invoiced off the items received record could not be updated"); - - update_average_material_cost($grn["supplier_id"], $myrow["item_code"], - $myrow["unit_price"], -$myrow["QtyOstdg"], Today()); - - add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "", - -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']); - - commit_transaction(); + remove_not_invoice_item($id2); display_notification(sprintf(_('All yet non-invoiced items on delivery line # %d has been removed.'), $id2)); }