Cleanup: removed _GET/_POST references from business logic model.
[fa-stable.git] / manufacturing / work_order_add_finished.php
index acf67f73e197ef7e0621795772b40b17426a1893..ec2dca663d9ceb83500cbf084ce72a6fede8d00a 100644 (file)
@@ -24,7 +24,7 @@ include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
 $js = "";
 if ($use_popup_windows)
        $js .= get_js_open_window(900, 500);
-if ($use_date_picker)
+if (user_use_date_picker())
        $js .= get_js_date_picker();
 page(_($help_context = "Produce or Unassemble Finished Items From Work Order"), false, false, "", $js);
 
@@ -101,7 +101,7 @@ function can_process()
        }
        elseif (!is_date_in_fiscalyear($_POST['date_']))
        {
-               display_error(_("The entered date is not in fiscal year."));
+               display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
                set_focus('date_');
                return false;
        }
@@ -121,10 +121,7 @@ function can_process()
        // if unassembling we need to check the qoh
        if (($_POST['ProductionType'] == 0) && !$SysPrefs->allow_negative_stock())
        {
-               $wo_details = get_work_order($_POST['selected_id']);
-
-               $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $_POST['date_']);
-               if (-input_num('quantity') + $qoh < 0)
+               if (check_negative_stock($wo_details["stock_id"], -input_num('quantity'), $wo_details["loc_code"], $_POST['date_']))
                {
                        display_error(_("The unassembling cannot be processed because there is insufficient stock."));
                        set_focus('quantity');
@@ -141,13 +138,13 @@ function can_process()
                {
                        if ($row['mb_flag'] == 'D') // service, non stock
                                continue;
-                       $qoh = get_qoh_on_date($row["stock_id"], $row["loc_code"], $_POST['date_']);
-                       if ($qoh - $row['units_req'] * input_num('quantity') < 0)
+
+                       if (check_negative_stock($row["stock_id"], -$row['units_req'] * input_num('quantity'), $row["loc_code"], $_POST['date_']))
                        {
                        display_error( _("The production cannot be processed because a required item would cause a negative inventory balance :") .
                                " " . $row['stock_id'] . " - " .  $row['description']);
-                       $err = true;    
-                       }       
+                       $err = true;
+                       }
                }
                if ($err)
                {