function check_data() { global $Refs, $SysPrefs; /*--------------------MOODLEARNING---------------------------*/ if (!get_post('custom_num')) { display_error(_("There is no delivery number entered.")); set_focus('custom_num'); return false; } /*--------------------------------------------------------------------*/ if (!isset($_POST['DispatchDate']) || !is_date($_POST['DispatchDate'])) { display_error(_("The entered date of delivery is invalid.")); set_focus('DispatchDate'); return false; } if (!is_date_in_fiscalyear($_POST['DispatchDate'])) { display_error(_("The entered date of delivery is not in fiscal year.")); set_focus('DispatchDate'); return false; } if (!isset($_POST['due_date']) || !is_date($_POST['due_date'])) { display_error(_("The entered dead-line for invoice is invalid.")); set_focus('due_date'); return false; } if ($_SESSION['Items']->trans_no == 0) { if (!$Refs->is_valid($_POST['ref'])) { display_error(_("You must enter a reference.")); set_focus('ref'); return false; } } if ($_POST['ChargeFreightCost'] == "") { $_POST['ChargeFreightCost'] = price_format(0); } if (!check_num('ChargeFreightCost', 0)) { display_error(_("The entered shipping value is not numeric.")); set_focus('ChargeFreightCost'); return false; } if ($_SESSION['Items']->has_items_dispatch() == 0 && input_num('ChargeFreightCost') == 0) { display_error(_("There are no item quantities on this delivery note.")); return false; } if (!check_quantities()) { return false; } copy_to_cart(); if (!$SysPrefs->allow_negative_stock() && ($low_stock = $_SESSION['Items']->check_qoh())) { display_error(_("This document cannot be processed because there is insufficient quantity for: ") . implode(',', $low_stock)); return false; } return true; }
function can_process() { global $Refs, $SysPrefs; copy_to_cart(); if (!get_post('customer_id')) { display_error(_("There is no customer selected.")); set_focus('customer_id'); return false; } if (!get_post('branch_id')) { display_error(_("This customer has no branch defined.")); set_focus('branch_id'); return false; } if (!is_date($_POST['OrderDate'])) { display_error(_("The entered date is invalid.")); set_focus('OrderDate'); return false; } if ($_SESSION['Items']->trans_type != ST_SALESORDER && $_SESSION['Items']->trans_type != ST_SALESQUOTE && !is_date_in_fiscalyear($_POST['OrderDate'])) { display_error(_("The entered date is not in fiscal year")); set_focus('OrderDate'); return false; } if (count($_SESSION['Items']->line_items) == 0) { display_error(_("You must enter at least one non empty item line.")); set_focus('AddItem'); return false; } if (!$SysPrefs->allow_negative_stock() && ($low_stock = $_SESSION['Items']->check_qoh())) { display_error(_("This document cannot be processed because there is insufficient quantity for items marked.")); return false; } if ($_SESSION['Items']->payment_terms['cash_sale'] == 0) { if (strlen($_POST['deliver_to']) <= 1) { display_error(_("You must enter the person or company to whom delivery should be made to.")); set_focus('deliver_to'); return false; } if ($_SESSION['Items']->trans_type != ST_SALESQUOTE && strlen($_POST['delivery_address']) <= 1) { display_error(_("You should enter the street address in the box provided. Orders cannot be accepted without a valid street address.")); set_focus('delivery_address'); return false; } if ($_POST['freight_cost'] == "") { $_POST['freight_cost'] = price_format(0); } if (!check_num('freight_cost', 0)) { display_error(_("The shipping cost entered is expected to be numeric.")); set_focus('freight_cost'); return false; } if (!is_date($_POST['delivery_date'])) { if ($_SESSION['Items']->trans_type == ST_SALESQUOTE) { display_error(_("The Valid date is invalid.")); } else { display_error(_("The delivery date is invalid.")); } set_focus('delivery_date'); return false; } if (date1_greater_date2($_POST['OrderDate'], $_POST['delivery_date'])) { if ($_SESSION['Items']->trans_type == ST_SALESQUOTE) { display_error(_("The requested valid date is before the date of the quotation.")); } else { display_error(_("The requested delivery date is before the date of the order.")); } set_focus('delivery_date'); return false; } } else { if (!db_has_cash_accounts()) { display_error(_("You need to define a cash account for your Sales Point.")); return false; } } if (!$Refs->is_valid($_POST['ref'])) { display_error(_("You must enter a reference.")); set_focus('ref'); return false; } if (!db_has_currency_rates($_SESSION['Items']->customer_currency, $_POST['OrderDate'])) { return false; } if ($_SESSION['Items']->get_items_total() < 0) { display_error("Invoice total amount cannot be less than zero."); return false; } return true; }
$_POST['Location'] = $cart->Location; $_POST['CreditText'] = $cart->Comments; $_POST['cart_id'] = $cart->cart_id; $_POST['ref'] = $cart->reference; $_POST['custom_num'] = $cart->custom_num; //moodlearning $_POST['bulk_dis'] = $cart->bulk_discount; //moodlearning } //----------------------------------------------------------------------------- if (isset($_POST['ProcessCredit']) && can_process()) { $new_credit = $_SESSION['Items']->trans_no == 0; if (!isset($_POST['WriteOffGLCode'])) { $_POST['WriteOffGLCode'] = 0; } copy_to_cart(); if ($new_credit) { new_doc_date($_SESSION['Items']->document_date); } $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']); if ($credit_no == -1) { display_error(_("The entered reference is already in use.")); set_focus('ref'); } elseif ($credit_no) { processing_end(); if ($new_credit) { meta_forward($_SERVER['PHP_SELF'], "AddedID={$credit_no}"); } else { meta_forward($_SERVER['PHP_SELF'], "UpdatedID={$credit_no}"); } }
function handle_commit_order() { $cart =& $_SESSION['PO']; if (can_commit()) { copy_to_cart(); if ($cart->trans_type != ST_PURCHORDER) { // for direct grn/invoice set same dates for lines as for whole document foreach ($cart->line_items as $line_no => $line) { $cart->line_items[$line_no]->req_del_date = $cart->orig_order_date; } } if ($cart->order_no == 0) { // new po/grn/invoice /*its a new order to be inserted */ $ref = $cart->reference; if ($cart->trans_type != ST_PURCHORDER) { $cart->reference = 'auto'; begin_transaction(); // all db changes as single transaction for direct document } $order_no = add_po($cart); new_doc_date($cart->orig_order_date); $cart->order_no = $order_no; if ($cart->trans_type == ST_PURCHORDER) { unset($_SESSION['PO']); meta_forward($_SERVER['PHP_SELF'], "AddedID={$order_no}"); } //Direct GRN if ($cart->trans_type == ST_SUPPRECEIVE) { $cart->reference = $ref; } if ($cart->trans_type != ST_SUPPINVOICE) { $cart->Comments = $cart->reference; } //grn does not hold supp_ref foreach ($cart->line_items as $key => $line) { $cart->line_items[$key]->receive_qty = $line->quantity; } $grn_no = add_grn($cart); if ($cart->trans_type == ST_SUPPRECEIVE) { commit_transaction(); // save PO+GRN unset($_SESSION['PO']); meta_forward($_SERVER['PHP_SELF'], "AddedGRN={$grn_no}"); } // Direct Purchase Invoice $inv = new supp_trans(ST_SUPPINVOICE); $inv->Comments = $cart->Comments; $inv->supplier_id = $cart->supplier_id; $inv->tran_date = $cart->orig_order_date; $inv->due_date = $cart->due_date; $inv->reference = $ref; $inv->supp_reference = $cart->supp_ref; $inv->tax_included = $cart->tax_included; $supp = get_supplier($cart->supplier_id); $inv->tax_group_id = $supp['tax_group_id']; $inv->ov_amount = $inv->ov_gst = $inv->ov_discount = 0; $total = 0; foreach ($cart->line_items as $key => $line) { $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id, $line->item_description, $line->receive_qty, 0, $line->receive_qty, $line->price, $line->price, true, get_standard_cost($line->stock_id), ''); $inv->ov_amount += round2($line->receive_qty * $line->price, user_price_dec()); } $inv->tax_overrides = $cart->tax_overrides; if (!$inv->tax_included) { $taxes = $inv->get_taxes($inv->tax_group_id, 0, false); foreach ($taxes as $taxitem) { $total += isset($taxitem['Override']) ? $taxitem['Override'] : $taxitem['Value']; } } $inv->ex_rate = $cart->ex_rate; $inv_no = add_supp_invoice($inv); commit_transaction(); // save PO+GRN+PI // FIXME payment for cash terms. (Needs cash account selection) unset($_SESSION['PO']); meta_forward($_SERVER['PHP_SELF'], "AddedPI={$inv_no}"); } else { // order modification $order_no = update_po($cart); unset($_SESSION['PO']); meta_forward($_SERVER['PHP_SELF'], "AddedID={$order_no}&Updated=1"); } } }
if ($com != "") { display_notification_centered("Error"); $error = true; } copy_to_cart($customer_id, $branchNo, $sales_type_name, $reference, $date, $payment_id, $dimension_id, $dimension2_id, $freightcost = 0, $delfrom, $deldate, $delto, $deladdress, $contactphone, $email, $custref, $shipvia, $comments, $exrate = null); $firstlinecopied = true; } if ($prev_ref == $reference) { $docline = $docline + 1; $com = get_customer_details_to_order($_SESSION['Items'], $customer_id, $branchNo); display_notification_centered($com); if ($com != "") { display_notification_centered("Error"); $error = true; } copy_to_cart($customer_id, $branchNo, $sales_type_name, $reference, $date, $payment_id, $dimension_id, $dimension2_id, $freightcost = 0, $delfrom, $deldate, $delto, $deladdress, $contactphone, $email, $custref, $shipvia, $comments, $exrate = null); } import_add_to_order($_SESSION['Items'], $item_code, $quantity, $price, $discountpercentage, $item_description); $_SESSION['Items']->cust_ref = $reference; if (!check_import_item_data($line_no = $docline, $item_code, $item_description, $quantity, $unit, $price, $discountpercentage) || !can_process($line, $customer_id, $branchNo, $reference, $date, $dimension_id, $dimension2_id, $freightcost = 0, $delfrom, $deldate, $delto, $deladdress, $contactphone, $email, $custref, $shipvia, $comments, $exrate)) { display_notification_centered("Error"); $error = true; } } if ($prev_ref != $reference && $type < 4) { init_entry_part_2($entry, $date, $reference); } if ($type == 0) { list($error, $input_id, $total_debit_positive, $total_credit_negative) = journal_id($prev_date, $date, $amt, $input_id = 0, $total_debit_positive, $total_credit_negative, $line); } if ($type == ST_BANKDEPOSIT || $type == ST_BANKPAYMENT || $type == ST_JOURNAL) {