$_SESSION['page_title'] = _($help_context = "Direct Sales Delivery");
create_cart(ST_CUSTDELIVERY, $_GET['NewDelivery']);
-
} elseif (isset($_GET['NewInvoice']) && is_numeric($_GET['NewInvoice'])) {
create_cart(ST_SALESINVOICE, $_GET['NewInvoice']);
page($_SESSION['page_title'], false, false, "", $js);
+if (isset($_GET['ModifyOrderNumber']) && is_prepaid_order_open($_GET['ModifyOrderNumber']))
+{
+ display_error(_("This order cannot be edited because there are invoices or payments related to it, and prepayment terms were used."));
+ end_page(); exit;
+}
if (isset($_GET['ModifyOrderNumber']))
check_is_editable(ST_SALESORDER, $_GET['ModifyOrderNumber']);
elseif (isset($_GET['ModifyQuotationNumber']))
{
$cart = &$_SESSION['Items'];
+
$cart->reference = $_POST['ref'];
$cart->Comments = $_POST['Comments'];
$cart->document_date = $_POST['OrderDate'];
- $newpayment = false;
+ $newpayment = false;
if (isset($_POST['payment']) && ($cart->payment != $_POST['payment'])) {
$cart->payment = $_POST['payment'];
$cart->payment_terms = get_payment_terms($_POST['payment']);
$newpayment = true;
}
- if ($cart->payment_terms['cash_sale']) {
- if ($newpayment) {
+ if ($cart->payment_terms['type'] == PTT_CASH) {
+ if ($newpayment)
+ {
$cart->due_date = $cart->document_date;
$cart->phone = $cart->cust_ref = $cart->delivery_address = '';
- $cart->ship_via = 0;
$cart->deliver_to = '';
$cart->prep_amount = 0;
}
$cart->deliver_to = $_POST['deliver_to'];
$cart->delivery_address = $_POST['delivery_address'];
$cart->phone = $_POST['phone'];
- $cart->ship_via = $_POST['ship_via'];
if (!$cart->trans_no || ($cart->trans_type == ST_SALESORDER && !$cart->is_started()))
$cart->prep_amount = input_num('prep_amount', 0);
}
+
+ $cart->ship_via = $_POST['ship_via'];
$cart->Location = $_POST['Location'];
$cart->freight_cost = input_num('freight_cost');
if (isset($_POST['email']))
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 (!$_SESSION['Items']->is_started() && ($_SESSION['Items']->payment_terms['days_before_due'] == -1) && ((input_num('prep_amount')<=0) ||
+ if ($_SESSION['Items']->payment_terms['type'] != PTT_CASH) {
+ if (!$_SESSION['Items']->is_started() && ($_SESSION['Items']->payment_terms['type'] == PTT_PREPAY) && ((input_num('prep_amount')<=0) ||
input_num('prep_amount')>$_SESSION['Items']->get_trans_total())) {
display_error(_("Pre-payment required have to be positive and less than total amount."));
set_focus('prep_amount');
return false;
}
- if ($_POST['freight_cost'] == "")
- $_POST['freight_cost'] = price_format(0);
-
- if (!check_num('freight_cost',0)) {
+ if (isset($_POST['freight_cost']) && !check_num('freight_cost',0)) {
display_error(_("The shipping cost entered is expected to be numeric."));
set_focus('freight_cost');
return false;
display_error("Invoice total amount cannot be less than zero.");
return false;
}
+
+ if ($_SESSION['Items']->payment_terms['type'] == PTT_CASH &&
+ ($_SESSION['Items']->trans_type == ST_CUSTDELIVERY || $_SESSION['Items']->trans_type == ST_SALESINVOICE))
+ $_SESSION['Items']->due_date = $_SESSION['Items']->document_date;
return true;
}
$modified = ($_SESSION['Items']->trans_no != 0);
$so_type = $_SESSION['Items']->so_type;
- $ret = $_SESSION['Items']->write(1);
+ $ret = write_sales_trans($_SESSION['Items'], 1);
if ($ret == -1)
{
display_error(_("The entered reference is already in use."));
$ref = $Refs->get_next($_SESSION['Items']->trans_type, null, array('date' => Today()));
if ($ref != $_SESSION['Items']->reference)
{
+ unset($_POST['ref']); // force refresh reference
display_error(_("The reference number field has been increased. Please save the document again."));
- $_POST['ref'] = $_SESSION['Items']->reference = $ref;
- $Ajax->activate('ref');
- }
+ }
set_focus('ref');
}
else
$doc->trans_no = 0;
$doc->document_date = new_doc_date();
if ($type == ST_SALESINVOICE) {
- $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
+ $doc->due_date = get_payment_due_date($doc->payment, $doc->document_date);
$doc->pos = get_sales_point(user_pos());
} else
$doc->due_date = $doc->document_date;