Changed to present reference number in Print Invoices/Credit Notes if global $print_i...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 3 Jun 2009 08:20:13 +0000 (08:20 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 3 Jun 2009 08:20:13 +0000 (08:20 +0000)
Deleting of Locations was too easy. Implemented much more checks
Report Stock Check Sheet and 'Inventory Item Status' was wrong when Locations were selected
When producing advanced manufacture there should be errors when insuffient qoh in items (if 'Allow Negative Stock' is not marked)

CHANGELOG.txt
includes/db/manufacturing_db.inc
inventory/manage/locations.php
manufacturing/work_order_add_finished.php
manufacturing/work_order_issue.php
reporting/includes/reports_classes.inc
reporting/rep302.php
reporting/rep303.php

index bcec00496a0a6566fc8adf7c5e830683a685c45c..426d90f76e61c774238d6abee411c92aa70f7c57 100644 (file)
@@ -19,6 +19,19 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+03-Jun-2009 Joe Hunt
+! Changed to present reference number in Print Invoices/Credit Notes if global $print_invoice_no = 0
+$ /reporting/includes/reports_classes.inc
+# Deleting of Locations was too easy. Implemented much more checks
+$ /inventory/manage/locations.php
+! Report Stock Check Sheet and 'Inventory Item Status' was wrong when Locations were selected.
+$ /reporting/rep302.php
+  /reporting/rep303.php
+  /includes/db/manufacturing_db.inc
+# When producing advanced manufacture there should be errors when insuffient qoh in items (if 'Allow Negative Stock' is not marked).
+$ /manufacturing/work_order_issue.php
+  /manufacturing/work_order_add_finished.php
+  
 27-May-2009 Joe Hunt
 # After heavy testing a new set of nested subtypes in COA, Monthly Breakdown, Balance Sheet and P&L Statement.
 $ /gl/includes/db/gl_db_accounts.inc
index 9592fdaa172efee0a5fd8afd7bbe8847fa5e7ed9..c2f34d9be21aac04c17bd4fcde878753313fe158 100644 (file)
@@ -22,6 +22,8 @@ function get_demand_qty($stock_id, $location)
 
     $result = db_query($sql,"No transactions were returned");
        $row = db_fetch($result);
+       if ($row === false)
+               return 0;
        return $row['QtyDemand'];
 }
 
@@ -34,7 +36,7 @@ function load_stock_levels($location)
        $date = date2sql(Today());
 
        $sql = "SELECT stock_id, SUM(qty) FROM ".TB_PREF."stock_moves WHERE tran_date <= '$date'";
-       if ($location != null) $sql .= " AND loc_code = '$location'";
+       if ($location != '') $sql .= " AND loc_code = '$location'";
        $sql .= " GROUP BY stock_id";
        $result = db_query($sql, "QOH calulcation failed");
        while ($row = db_fetch($result)) {
@@ -62,7 +64,7 @@ function stock_demand_manufacture($stock_id, $qty, $demand_id, $location, $level
        $bom = $bom_list[$stock_id];
        if ($bom == NULL) {
                $sql = "SELECT parent, component, quantity FROM ".TB_PREF."bom WHERE parent = '$stock_id'";
-               if ($location != '') $sql .= " AND loc_code = '$location'";
+               if ($location != "") $sql .= " AND loc_code = '$location'";
                $result = db_query($sql, "Could not search bom");
                $bom = array();
                // Even if we get no results, remember that fact 
index e0c3b1468183ce2e7b230992bab849f8a0460a58..47eedc64152b48b65fd6e838e8622b85f6876640 100644 (file)
@@ -98,6 +98,46 @@ function can_delete($selected_id)
                return false;
        }
        
+       $sql= "SELECT COUNT(*) FROM ".TB_PREF."bom WHERE loc_code='$selected_id'";
+       $result = db_query($sql, "could not query bom");
+       $myrow = db_fetch_row($result);
+       if ($myrow[0] > 0) 
+       {
+               display_error(_("Cannot delete this location because it is used by some related records in other tables."));
+               return false;
+       }
+       $sql= "SELECT COUNT(*) FROM ".TB_PREF."grn_batch WHERE loc_code='$selected_id'";
+       $result = db_query($sql, "could not query grn batch");
+       $myrow = db_fetch_row($result);
+       if ($myrow[0] > 0) 
+       {
+               display_error(_("Cannot delete this location because it is used by some related records in other tables."));
+               return false;
+       }
+       $sql= "SELECT COUNT(*) FROM ".TB_PREF."purch_orders WHERE into_stock_location='$selected_id'";
+       $result = db_query($sql, "could not query purch orders");
+       $myrow = db_fetch_row($result);
+       if ($myrow[0] > 0) 
+       {
+               display_error(_("Cannot delete this location because it is used by some related records in other tables."));
+               return false;
+       }
+       $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_orders WHERE from_stk_loc='$selected_id'";
+       $result = db_query($sql, "could not query sales orders");
+       $myrow = db_fetch_row($result);
+       if ($myrow[0] > 0) 
+       {
+               display_error(_("Cannot delete this location because it is used by some related records in other tables."));
+               return false;
+       }
+       $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_pos WHERE pos_location='$selected_id'";
+       $result = db_query($sql, "could not query sales pos");
+       $myrow = db_fetch_row($result);
+       if ($myrow[0] > 0) 
+       {
+               display_error(_("Cannot delete this location because it is used by some related records in other tables."));
+               return false;
+       }
        return true;
 }
 
index b8036c371446757c245dec45340822f4a4e036e8..6248ed866759c86f29505eed988033b523c0c311 100644 (file)
@@ -115,18 +115,38 @@ function can_process()
                }
        }
 
+       // if production we need to check the qoh of the wo requirements
+       if (($_POST['ProductionType'] == 1) && !sys_prefs::allow_negative_stock())
+       {
+       $err = false;
+       $result = get_wo_requirements($_POST['selected_id']);
+               while ($row = db_fetch($result))
+               {
+                       if ($row['mb_flag'] == 'D') // service, non stock
+                               continue;
+                       $qoh = get_qoh_on_date($row["stock_id"], $row["loc_code"], $date_);
+                       if ($qoh - $row['units_req'] * $_POST['quantity'] < 0)
+                       {
+                       display_error( _("The production cannot be processed because a required item would cause a negative inventory balance :") .
+                               " " . $row['stock_id'] . " - " .  $row['description']);
+                       $err = true;    
+                       }       
+               }
+               if ($err)
+               {
+                       set_focus('quantity');
+                       return false;
+               }       
+       }
        return true;
 }
 
 //--------------------------------------------------------------------------------------------------
 
-if (isset($_POST['Process']) || (isset($_POST['ProcessAndClose']) && can_process() == true))
+if (isset($_POST['ProcessAndClose']) && can_process() == true)
 {
 
-       $close_wo = 0;
-       if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
-               $close_wo = 1;
-
+       $close_wo = 1;
        // if unassembling, negate quantity
        if ($_POST['ProductionType'] == 0)
                $_POST['quantity'] = -$_POST['quantity'];
@@ -171,8 +191,7 @@ textarea_row(_("Memo:"), 'memo_', null, 40, 3);
 
 end_table(1);
 
-submit_center_first('Process', _("Process"), '', true);
-submit_center_last('ProcessAndClose', _("Process And Close Order"), '', true);
+submit_center('ProcessAndClose', _("Process And Close Order"), true, '', true);
 
 end_form();
 
index ee2b295015cee0ff5314a6b57a9f24de3186a833..452c821510e23362317636d9750b1ec5b7651065 100644 (file)
@@ -94,7 +94,7 @@ function can_process()
        }
 
        $failed_item = $_SESSION['issue_items']->check_qoh($_POST['Location'], $_POST['date_'], !$_POST['IssueType']);
-       if ($failed_item >= 0
+       if ($failed_item != -1
        {
        display_error( _("The issue cannot be processed because an entered item would cause a negative inventory balance :") .
                " " . $failed_item->stock_id . " - " .  $failed_item->item_description);
index d5e6afbe818dd5cf82086c64419bbc38e8e1518f..4ff56b6547b2ce9df6c0cff4229b6665b359fef6 100644 (file)
@@ -119,7 +119,7 @@ class Report
        
        function getDisplay()
        {
-               global $path_to_root, $use_date_picker, $pdf_debug;
+               global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
 
                $st = '';
                $dummy = "";
@@ -257,9 +257,14 @@ class Report
                                case 'INVOICE':
                                        $IV = _("IV");
                                        $CN = _("CN");
-                                       $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
-                                               ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       if ($print_invoice_no == 1)
+                                               $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
+                                                       ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
+                                                       FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       else            
+                                               $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
+                                                       ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.reference, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
+                                                       FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'DELIVERY':
index 6806e4c3931fabca11c49f040092b7d4a7e9b56f..e92c27c5ff4a5fc4249f40c28861e55c86f828b8 100644 (file)
@@ -46,7 +46,7 @@ function getTransactions($category, $location)
        if ($category != 0)
                $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
        if ($location != 'all')
-               $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
+               $sql .= " AND IF(".TB_PREF."stock_moves.stock_id IS NULL, '1=1',".TB_PREF."stock_moves.loc_code = '$location')";
        $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
                ".TB_PREF."stock_category.description,
                ".TB_PREF."stock_master.stock_id,
@@ -154,7 +154,7 @@ function print_inventory_planning()
                if ($location == 'all')
                        $loc_code = "";
                else
-                       $loc_code = $trans['loc_code'];
+                       $loc_code = $location;
                $custqty = get_demand_qty($trans['stock_id'], $loc_code);
                $custqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
                $suppqty = get_on_porder_qty($trans['stock_id'], $loc_code);
index 4b87d6b286c7209f6a4c105719e7529b216b6217..5cd686032face020576f5e320f4dd595e9036e41 100644 (file)
@@ -36,7 +36,7 @@ function getTransactions($category, $location)
                        ".TB_PREF."stock_master.stock_id,
                        ".TB_PREF."stock_master.description,
                        IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
-                       SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand
+                       SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS qty_on_hand
                FROM (".TB_PREF."stock_master,
                        ".TB_PREF."stock_category)
                LEFT JOIN ".TB_PREF."stock_moves ON
@@ -46,7 +46,7 @@ function getTransactions($category, $location)
        if ($category != 0)
                $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
        if ($location != 'all')
-               $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
+               $sql .= " AND IF(".TB_PREF."stock_moves.stock_id IS NULL, '1=1',".TB_PREF."stock_moves.loc_code = '$location')";
        $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
                ".TB_PREF."stock_category.description,
                ".TB_PREF."stock_master.stock_id,
@@ -132,6 +132,10 @@ function print_stock_check()
        $catt = '';
        while ($trans=db_fetch($res))
        {
+               if ($location == 'all')
+                       $loc_code = "";
+               else
+                       $loc_code = $location;
                $demandqty = get_demand_qty($trans['stock_id'], $loc_code);
                $demandqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
                $onorder = get_on_porder_qty($trans['stock_id'], $loc_code);
@@ -150,10 +154,6 @@ function print_stock_check()
                        $catt = $trans['cat_description'];
                        $rep->NewLine();
                }
-               if ($location == 'all')
-                       $loc_code = "";
-               else
-                       $loc_code = $trans['loc_code'];
                $rep->NewLine();
                $dec = get_qty_dec($trans['stock_id']);
                $rep->TextCol(0, 1, $trans['stock_id']);
@@ -192,4 +192,4 @@ function print_stock_check()
     $rep->End();
 }
 
-?>
\ No newline at end of file
+?>