function can_process()
{
    global $wo_details;
    if (!references::is_valid($_POST['ref'])) {
        display_error(tr("You must enter a reference."));
        set_focus('ref');
        return false;
    }
    if (!is_new_reference($_POST['ref'], 29)) {
        display_error(tr("The entered reference is already in use."));
        set_focus('ref');
        return false;
    }
    if (!check_num('quantity', 0)) {
        display_error(tr("The quantity entered is not a valid number or less then zero."));
        set_focus('quantity');
        return false;
    }
    if (!is_date($_POST['date_'])) {
        display_error(tr("The entered date is invalid."));
        set_focus('date_');
        return false;
    } elseif (!is_date_in_fiscalyear($_POST['date_'])) {
        display_error(tr("The entered date is not in fiscal year."));
        set_focus('date_');
        return false;
    }
    if (date_diff(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0) {
        display_error(tr("The production date cannot be before the release date of the work order."));
        set_focus('date_');
        return false;
    }
    // if unassembling we need to check the qoh
    if ($_POST['ProductionType'] == 0 && !sys_prefs::allow_negative_stock()) {
        $wo_details = get_work_order($_POST['selected_id']);
        $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
        if (-$_POST['quantity'] + $qoh < 0) {
            display_error(tr("The unassembling cannot be processed because there is insufficient stock."));
            set_focus('quantity');
            return false;
        }
    }
    return true;
}
function inventory_movements()
{
    global $path_to_root;
    $from_date = $_POST['PARAM_0'];
    $to_date = $_POST['PARAM_1'];
    $category = $_POST['PARAM_2'];
    $location = $_POST['PARAM_3'];
    $comments = $_POST['PARAM_4'];
    $orientation = $_POST['PARAM_5'];
    $destination = $_POST['PARAM_6'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    if ($location == '') {
        $loc = _('All');
    } else {
        $loc = get_location_name($location);
    }
    $cols = array(0, 60, 130, 160, 185, 215, 250, 275, 305, 340, 365, 395, 430, 455, 485, 520);
    $headers = array(_('Category'), _('Description'), _('UOM'), '', '', _('OpeningStock'), '', '', _('StockIn'), '', '', _('Delivery'), '', '', _('ClosingStock'));
    $headers2 = array("", "", "", _("QTY"), _("Rate"), _("Value"), _("QTY"), _("Rate"), _("Value"), _("QTY"), _("Rate"), _("Value"), _("QTY"), _("Rate"), _("Value"));
    $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from_date, 'to' => $to_date), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
    $rep = new FrontReport(_('Costed Inventory Movements'), "CostedInventoryMovements", user_pagesize(), 8, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers2, $aligns, $cols, $headers, $aligns);
    $rep->NewPage();
    $totval_open = $totval_in = $totval_out = $totval_close = 0;
    $result = fetch_items($category);
    $dec = user_price_dec();
    $catgor = '';
    while ($myrow = db_fetch($result)) {
        if ($catgor != $myrow['description']) {
            $rep->NewLine(2);
            $rep->fontSize += 2;
            $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
            $catgor = $myrow['description'];
            $rep->fontSize -= 2;
            $rep->NewLine();
        }
        $rep->NewLine();
        $rep->TextCol(0, 1, $myrow['stock_id']);
        $rep->TextCol(1, 2, $myrow['name']);
        $rep->TextCol(2, 3, $myrow['units']);
        $qoh_start = get_qoh_on_date($myrow['stock_id'], $location, add_days($from_date, -1));
        $qoh_end = get_qoh_on_date($myrow['stock_id'], $location, $to_date);
        $inward = trans_qty($myrow['stock_id'], $location, $from_date, $to_date);
        $outward = trans_qty($myrow['stock_id'], $location, $from_date, $to_date, false);
        $openCost = avg_unit_cost($myrow['stock_id'], $location, $from_date);
        $unitCost = avg_unit_cost($myrow['stock_id'], $location, add_days($to_date, 1));
        $rep->AmountCol(3, 4, $qoh_start, get_qty_dec($myrow['stock_id']));
        $rep->AmountCol(4, 5, $openCost, $dec);
        $openCost *= $qoh_start;
        $totval_open += $openCost;
        $rep->AmountCol(5, 6, $openCost);
        if ($inward > 0) {
            $rep->AmountCol(6, 7, $inward, get_qty_dec($myrow['stock_id']));
            $unitCost_in = trans_qty_unit_cost($myrow['stock_id'], $location, $from_date, $to_date);
            $rep->AmountCol(7, 8, $unitCost_in, $dec);
            $unitCost_in *= $inward;
            $totval_in += $unitCost_in;
            $rep->AmountCol(8, 9, $unitCost_in);
        }
        if ($outward > 0) {
            $rep->AmountCol(9, 10, $outward, get_qty_dec($myrow['stock_id']));
            $unitCost_out = trans_qty_unit_cost($myrow['stock_id'], $location, $from_date, $to_date, false);
            $rep->AmountCol(10, 11, $unitCost_out, $dec);
            $unitCost_out *= $outward;
            $totval_out += $unitCost_out;
            $rep->AmountCol(11, 12, $unitCost_out);
        }
        $rep->AmountCol(12, 13, $qoh_end, get_qty_dec($myrow['stock_id']));
        $rep->AmountCol(13, 14, $unitCost, $dec);
        $unitCost *= $qoh_end;
        $totval_close += $unitCost;
        $rep->AmountCol(14, 15, $unitCost);
        $rep->NewLine(0, 1);
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine(2);
    $rep->TextCol(0, 1, _("Total"));
    $rep->AmountCol(5, 6, $totval_open);
    $rep->AmountCol(8, 9, $totval_in);
    $rep->AmountCol(11, 12, $totval_out);
    $rep->AmountCol(14, 15, $totval_close);
    $rep->Line($rep->row - 4);
    $rep->End();
}
$j = 1;
$k = 0;
//row colour counter
$result = get_loc_details($_POST['stock_id']);
if (@$_GET['popup']) {
    hidden('_tabs_sel', get_post('_tabs_sel'));
    hidden('popup', @$_GET['popup']);
}
while ($myrow = db_fetch($result)) {
    alt_table_row_color($k);
    if (isset($_POST['UpdateData']) && check_num($myrow["loc_code"])) {
        $myrow["reorder_level"] = input_num($myrow["loc_code"]);
        set_reorder_level($_POST['stock_id'], $myrow["loc_code"], input_num($myrow["loc_code"]));
        display_notification(_("Reorder levels has been updated."));
    }
    $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
    label_cell($myrow["location_name"]);
    $_POST[$myrow["loc_code"]] = qty_format($myrow["reorder_level"], $_POST['stock_id'], $dec);
    qty_cell($qoh, false, $dec);
    qty_cells(null, $myrow["loc_code"], null, null, null, $dec);
    end_row();
    $j++;
    if ($j == 12) {
        $j = 1;
        table_header($th);
    }
}
end_table(1);
div_end();
submit_center('UpdateData', _("Update"), true, false, 'default');
if (!@$_GET['popup']) {
function can_process()
{
    global $wo_details, $SysPrefs, $Refs;
    if (!$Refs->is_valid($_POST['ref'])) {
        display_error(_("You must enter a reference."));
        set_focus('ref');
        return false;
    }
    if (!is_new_reference($_POST['ref'], 29)) {
        display_error(_("The entered reference is already in use."));
        set_focus('ref');
        return false;
    }
    if (!check_num('quantity', 0)) {
        display_error(_("The quantity entered is not a valid number or less then zero."));
        set_focus('quantity');
        return false;
    }
    if (!is_date($_POST['date_'])) {
        display_error(_("The entered date is invalid."));
        set_focus('date_');
        return false;
    } elseif (!is_date_in_fiscalyear($_POST['date_'])) {
        display_error(_("The entered date is not in fiscal year."));
        set_focus('date_');
        return false;
    }
    if (date_diff2(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0) {
        display_error(_("The production date cannot be before the release date of the work order."));
        set_focus('date_');
        return false;
    }
    // don't produce more that required. Otherwise change the Work Order.
    if (input_num('quantity') > $wo_details["units_reqd"] - $wo_details["units_issued"]) {
        display_error(_("The production exceeds the quantity needed. Please change the Work Order."));
        set_focus('quantity');
        return false;
    }
    // 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) {
            display_error(_("The unassembling cannot be processed because there is insufficient stock."));
            set_focus('quantity');
            return false;
        }
    }
    // if production we need to check the qoh of the wo requirements
    if ($_POST['ProductionType'] == 1 && !$SysPrefs->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"], $_POST['date_']);
            if ($qoh - $row['units_req'] * input_num('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;
}
function check_qoh()
{
    global $SysPrefs;
    $dn =& $_SESSION['Items'];
    $newdelivery = $dn->trans_no == 0;
    if (!$SysPrefs->allow_negative_stock()) {
        foreach ($_SESSION['Items']->line_items as $itm) {
            if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) {
                $qoh_by_date = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
                $qoh_abs = get_qoh_on_date($itm->stock_id, $_POST['Location'], null);
                //If editing current delivery delivered qty should be added
                if (!$newdelivery) {
                    $delivered = get_already_delivered($itm->stock_id, $_POST['Location'], key($dn->trans_no));
                    $qoh_abs = $qoh_abs - $delivered;
                    $qoh_by_date = $qoh_by_date - $delivered;
                }
                $qoh = $qoh_by_date < $qoh_abs ? $qoh_by_date : $qoh_abs;
                if ($itm->qty_dispatched > $qoh) {
                    display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") . " " . $itm->stock_id . " - " . $itm->item_description);
                    return false;
                }
            }
        }
    }
    return true;
}
function check_item_data()
{
    global $SysPrefs, $allow_negative_prices;
    $is_inventory_item = is_inventory_item(get_post('stock_id'));
    if (!get_post('stock_id_text', true)) {
        display_error(_("Item description cannot be empty."));
        set_focus('stock_id_edit');
        return false;
    } elseif (!check_num('qty', 0) || !check_num('Disc', 0, 100)) {
        display_error(_("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
        set_focus('qty');
        return false;
    } elseif (!check_num('price', 0) && (!$allow_negative_prices || $is_inventory_item)) {
        display_error(_("Price for inventory item must be entered and can not be less than 0"));
        set_focus('price');
        return false;
    } elseif (isset($_POST['LineNo']) && isset($_SESSION['Items']->line_items[$_POST['LineNo']]) && !check_num('qty', $_SESSION['Items']->line_items[$_POST['LineNo']]->qty_done)) {
        set_focus('qty');
        display_error(_("You attempting to make the quantity ordered a quantity less than has already been delivered. The quantity delivered cannot be modified retrospectively."));
        return false;
    } elseif ($is_inventory_item && $_SESSION['Items']->trans_type != ST_SALESORDER && $_SESSION['Items']->trans_type != ST_SALESQUOTE && !$SysPrefs->allow_negative_stock()) {
        $qoh = get_qoh_on_date($_POST['stock_id'], $_POST['Location'], $_POST['OrderDate']);
        if (input_num('qty') > $qoh) {
            $stock = get_item($_POST['stock_id']);
            display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") . " " . $stock['stock_id'] . " - " . $stock['description'] . " - " . _("Quantity On Hand") . " = " . number_format2($qoh, get_qty_dec($_POST['stock_id'])));
            return false;
        }
        return true;
    }
    $cost_home = get_standard_cost(get_post('stock_id'));
    // Added 2011-03-27 Joe Hunt
    $cost = $cost_home / get_exchange_rate_from_home_currency($_SESSION['Items']->customer_currency, $_SESSION['Items']->document_date);
    if (input_num('price') < $cost) {
        $dec = user_price_dec();
        $curr = $_SESSION['Items']->customer_currency;
        $price = number_format2(input_num('price'), $dec);
        if ($cost_home == $cost) {
            $std_cost = number_format2($cost_home, $dec);
        } else {
            $price = $curr . " " . $price;
            $std_cost = $curr . " " . number_format2($cost, $dec);
        }
        display_warning(sprintf(_("Price %s is below Standard Cost %s"), $price, $std_cost));
    }
    return true;
}
Exemple #7
0
function inventory_movements()
{
    global $path_to_root;
    $from_date = $_POST['PARAM_0'];
    $to_date = $_POST['PARAM_1'];
    $category = $_POST['PARAM_2'];
    $location = $_POST['PARAM_3'];
    $comments = $_POST['PARAM_4'];
    $orientation = $_POST['PARAM_5'];
    $destination = $_POST['PARAM_6'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    //	if ($location == ALL_TEXT)
    //		$location = '';
    if ($location == '') {
        $loc = _('All');
    } else {
        $loc = get_location_name($location);
    }
    //$cols = array(0, 100, 300, 365, 440, 540, 640, 715);
    $cols = array(0, 60, 220, 240, 310, 380, 450, 520);
    $headers = array(_('Category'), _('Description'), _('UOM'), _('Opening'), _('Quantity In'), _('Quantity Out'), _('Balance'));
    $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from_date, 'to' => $to_date), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
    $rep = new FrontReport(_('Inventory Movements'), "InventoryMovements", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $result = fetch_items($category);
    $catgor = '';
    while ($myrow = db_fetch($result)) {
        if ($catgor != $myrow['description']) {
            $rep->Line($rep->row - $rep->lineHeight);
            $rep->NewLine(2);
            $rep->fontSize += 2;
            $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
            $catgor = $myrow['description'];
            $rep->fontSize -= 2;
            $rep->NewLine();
        }
        $rep->NewLine();
        $rep->TextCol(0, 1, $myrow['stock_id']);
        $rep->TextCol(1, 2, $myrow['name']);
        $rep->TextCol(2, 3, $myrow['units']);
        $qoh_start = $inward = $outward = $qoh_end = 0;
        $qoh_start += get_qoh_on_date($myrow['stock_id'], $location, add_days($from_date, -1));
        $qoh_end += get_qoh_on_date($myrow['stock_id'], $location, $to_date);
        $inward += trans_qty($myrow['stock_id'], $location, $from_date, $to_date);
        $outward += trans_qty($myrow['stock_id'], $location, $from_date, $to_date, false);
        $rep->AmountCol(3, 4, $qoh_start, get_qty_dec($myrow['stock_id']));
        $rep->AmountCol(4, 5, $inward, get_qty_dec($myrow['stock_id']));
        $rep->AmountCol(5, 6, $outward, get_qty_dec($myrow['stock_id']));
        $rep->AmountCol(6, 7, $qoh_end, get_qty_dec($myrow['stock_id']));
        $rep->NewLine(0, 1);
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine();
    $rep->End();
}
function can_process()
{
    global $selected_id, $SysPrefs, $Refs;
    if (!isset($selected_id)) {
        if (!$Refs->is_valid($_POST['wo_ref'])) {
            display_error(_("You must enter a reference."));
            set_focus('wo_ref');
            return false;
        }
        if (!is_new_reference($_POST['wo_ref'], ST_WORKORDER)) {
            display_error(_("The entered reference is already in use."));
            set_focus('wo_ref');
            return false;
        }
    }
    if (!check_num('quantity', 0)) {
        display_error(_("The quantity entered is invalid or less than zero."));
        set_focus('quantity');
        return false;
    }
    if (!is_date($_POST['date_'])) {
        display_error(_("The date entered is in an invalid format."));
        set_focus('date_');
        return false;
    } elseif (!is_date_in_fiscalyear($_POST['date_'])) {
        display_error(_("The entered date is not in fiscal year."));
        set_focus('date_');
        return false;
    }
    // only check bom and quantites if quick assembly
    if (!($_POST['type'] == WO_ADVANCED)) {
        if (!has_bom($_POST['stock_id'])) {
            display_error(_("The selected item to manufacture does not have a bom."));
            set_focus('stock_id');
            return false;
        }
        if ($_POST['Labour'] == "") {
            $_POST['Labour'] = price_format(0);
        }
        if (!check_num('Labour', 0)) {
            display_error(_("The labour cost entered is invalid or less than zero."));
            set_focus('Labour');
            return false;
        }
        if ($_POST['Costs'] == "") {
            $_POST['Costs'] = price_format(0);
        }
        if (!check_num('Costs', 0)) {
            display_error(_("The cost entered is invalid or less than zero."));
            set_focus('Costs');
            return false;
        }
        if (!$SysPrefs->allow_negative_stock()) {
            if ($_POST['type'] == WO_ASSEMBLY) {
                // check bom if assembling
                $result = get_bom($_POST['stock_id']);
                while ($bom_item = db_fetch($result)) {
                    if (has_stock_holding($bom_item["ResourceType"])) {
                        $quantity = $bom_item["quantity"] * input_num('quantity');
                        $qoh = get_qoh_on_date($bom_item["component"], $bom_item["loc_code"], $_POST['date_']);
                        if (-$quantity + $qoh < 0) {
                            display_error(_("The work order cannot be processed because there is an insufficient quantity for component:") . " " . $bom_item["component"] . " - " . $bom_item["description"] . ".  " . _("Location:") . " " . $bom_item["location_name"]);
                            set_focus('quantity');
                            return false;
                        }
                    }
                }
            } elseif ($_POST['type'] == WO_UNASSEMBLY) {
                // if unassembling, check item to unassemble
                $qoh = get_qoh_on_date($_POST['stock_id'], $_POST['StockLocation'], $_POST['date_']);
                if (-input_num('quantity') + $qoh < 0) {
                    display_error(_("The selected item cannot be unassembled because there is insufficient stock."));
                    return false;
                }
            }
        }
    } else {
        if (!is_date($_POST['RequDate'])) {
            set_focus('RequDate');
            display_error(_("The date entered is in an invalid format."));
            return false;
        }
        //elseif (!is_date_in_fiscalyear($_POST['RequDate']))
        //{
        //	display_error(_("The entered date is not in fiscal year."));
        //	return false;
        //}
        if (isset($selected_id)) {
            $myrow = get_work_order($selected_id, true);
            if ($_POST['units_issued'] > input_num('quantity')) {
                set_focus('quantity');
                display_error(_("The quantity cannot be changed to be less than the quantity already manufactured for this order."));
                return false;
            }
        }
    }
    return true;
}
Exemple #9
0
function print_workorders()
{
    global $path_to_root, $SysPrefs, $dflt_lang;
    include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $email = $_POST['PARAM_2'];
    $comments = $_POST['PARAM_3'];
    $orientation = $_POST['PARAM_4'];
    if (!$from || !$to) {
        return;
    }
    $orientation = $orientation ? 'L' : 'P';
    $fno = explode("-", $from);
    $tno = explode("-", $to);
    $from = min($fno[0], $tno[0]);
    $to = max($fno[0], $tno[0]);
    $cols = array(4, 60, 190, 255, 320, 385, 450, 515);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
    $params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    if ($email == 0) {
        $rep = new FrontReport(_('WORK ORDER'), "WorkOrderBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        $myrow = get_work_order($i);
        if ($myrow === false) {
            continue;
        }
        $date_ = sql2date($myrow["date_"]);
        if ($email == 1) {
            $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
            $rep->title = _('WORK ORDER');
            $rep->filename = "WorkOrder" . $myrow['wo_ref'] . ".pdf";
        }
        $rep->SetHeaderType('Header2');
        $rep->currency = $cur;
        $rep->Font();
        $rep->Info($params, $cols, null, $aligns);
        $contact = array('email' => $myrow['email'], 'lang' => $dflt_lang, 'name' => $myrow['contact'], 'name2' => '', 'contact');
        $rep->SetCommonData($myrow, null, null, '', 26, $contact);
        $rep->NewPage();
        $result = get_wo_requirements($i);
        $rep->TextCol(0, 5, _("Work Order Requirements"), -2);
        $rep->NewLine(2);
        $has_marked = false;
        while ($myrow2 = db_fetch($result)) {
            $qoh = 0;
            $show_qoh = true;
            // if it's a non-stock item (eg. service) don't show qoh
            if (!has_stock_holding($myrow2["mb_flag"])) {
                $show_qoh = false;
            }
            if ($show_qoh) {
                $qoh = get_qoh_on_date($myrow2["stock_id"], $myrow2["loc_code"], $date_);
            }
            if ($show_qoh && $myrow2["units_req"] * $myrow["units_issued"] > $qoh && !$SysPrefs->allow_negative_stock()) {
                // oops, we don't have enough of one of the component items
                $has_marked = true;
            } else {
                $has_marked = false;
            }
            if ($has_marked) {
                $str = $myrow2['stock_id'] . " ***";
            } else {
                $str = $myrow2['stock_id'];
            }
            $rep->TextCol(0, 1, $str, -2);
            $rep->TextCol(1, 2, $myrow2['description'], -2);
            $rep->TextCol(2, 3, $myrow2['location_name'], -2);
            $rep->TextCol(3, 4, $myrow2['WorkCentreDescription'], -2);
            $dec = get_qty_dec($myrow2["stock_id"]);
            $rep->AmountCol(4, 5, $myrow2['units_req'], $dec, -2);
            $rep->AmountCol(5, 6, $myrow2['units_req'] * $myrow['units_issued'], $dec, -2);
            $rep->AmountCol(6, 7, $myrow2['units_issued'], $dec, -2);
            $rep->NewLine(1);
            if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                $rep->NewPage();
            }
        }
        $rep->NewLine(1);
        $rep->TextCol(0, 5, " *** = " . _("Insufficient stock"), -2);
        $memo = get_comments_string(ST_WORKORDER, $i);
        if ($memo != "") {
            $rep->NewLine();
            $rep->TextColLines(1, 5, $memo, -2);
        }
        if ($email == 1) {
            $myrow['DebtorName'] = $myrow['contact'];
            $myrow['reference'] = $myrow['wo_ref'];
            $rep->End($email);
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
function check_data()
{
    global $total_grn_value, $total_gl_value, $Refs, $SysPrefs;
    if (!$_SESSION['supp_trans']->is_valid_trans_to_post()) {
        display_error(_("The credit note cannot be processed because the there are no items or values on the invoice.  Credit notes are expected to have a charge."));
        set_focus('');
        return false;
    }
    if (!$Refs->is_valid($_SESSION['supp_trans']->reference)) {
        display_error(_("You must enter an credit note reference."));
        set_focus('reference');
        return false;
    }
    if (!is_new_reference($_SESSION['supp_trans']->reference, ST_SUPPCREDIT)) {
        display_error(_("The entered reference is already in use."));
        set_focus('reference');
        return false;
    }
    if (!$Refs->is_valid($_SESSION['supp_trans']->supp_reference)) {
        display_error(_("You must enter a supplier's credit note reference."));
        set_focus('supp_reference');
        return false;
    }
    if (!is_date($_SESSION['supp_trans']->tran_date)) {
        display_error(_("The credit note as entered cannot be processed because the date entered is not valid."));
        set_focus('tran_date');
        return false;
    } elseif (!is_date_in_fiscalyear($_SESSION['supp_trans']->tran_date)) {
        display_error(_("The entered date is not in fiscal year."));
        set_focus('tran_date');
        return false;
    }
    if (!is_date($_SESSION['supp_trans']->due_date)) {
        display_error(_("The invoice as entered cannot be processed because the due date is in an incorrect format."));
        set_focus('due_date');
        return false;
    }
    if ($_SESSION['supp_trans']->ov_amount < $total_gl_value + $total_grn_value) {
        display_error(_("The credit note total as entered is less than the sum of the the general ledger entires (if any) and the charges for goods received. There must be a mistake somewhere, the credit note as entered will not be processed."));
        return false;
    }
    if (!$SysPrefs->allow_negative_stock()) {
        foreach ($_SESSION['supp_trans']->grn_items as $n => $item) {
            if (is_inventory_item($item->item_code)) {
                $qoh = get_qoh_on_date($item->item_code, null, $_SESSION['supp_trans']->tran_date);
                if ($item->this_quantity_inv > $qoh) {
                    $stock = get_item($item->item_code);
                    display_error(_("The return cannot be processed because there is an insufficient quantity for item:") . " " . $stock['stock_id'] . " - " . $stock['description'] . " - " . _("Quantity On Hand") . " = " . number_format2($qoh, get_qty_dec($stock['stock_id'])));
                    return false;
                }
                return true;
            }
        }
    }
    return true;
}
function check_qoh()
{
    if (!sys_prefs::allow_negative_stock()) {
        foreach ($_SESSION['Items']->line_items as $itm) {
            if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) {
                $qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
                if ($itm->qty_dispatched > $qoh) {
                    display_error(tr("The delivery cannot be processed because there is an insufficient quantity for item:") . " " . $itm->stock_id . " - " . $itm->item_description);
                    return false;
                }
            }
        }
    }
    return true;
}