! -> Note
$ -> Affected files
+08-Jul-2008 Janusz Dobrowolski
+# Added validation of entered quantities
+$ /sales/customer_credit_invoice.php
+# Fixed ajax update (0000015) and quantity checks
+$ /sales/customer_delivery.php
+ /sales/customer_invoice.php
+# Fixed invalid voiding sales invoice/delivery/credit (0000016)
+$ /sales/includes/db/sales_delivery_db.inc
+ /sales/includes/db/sales_invoice_db.inc
+ /sales/includes/sales_db.inc
+# Fixed setting document date to Today()
+$ /sales/includes/cart_class.inc
+
08-Jul-2008 Joe Hunt
+ Addition in test of duplicate fiscal year
$ /admin/fiscalyears.php
set_focus('ChargeFreightCost');
return false;
}
-
+ if (!check_quantities()) {
+ display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet."));
+ return false;
+ }
return true;
}
} elseif (!processing_active()) {
/* This page can only be called with an invoice number for crediting*/
die (_("This page can only be opened if an invoice has been selected for crediting."));
-} else {
+} elseif (!check_quantities()) {
+ display_error(_("Selected quantity cannot be less than zero nor more than quantity not credited yet."));
+}
+
+function check_quantities()
+{
+ $ok =1;
foreach ($_SESSION['Items']->line_items as $line_no=>$itm) {
if (isset($_POST['Line'.$line_no])) {
- if (check_num('Line'.$line_no, ($itm->quantity - $itm->qty_done))) {
+ if (check_num('Line'.$line_no, 0, $itm->quantity))) {
$_SESSION['Items']->line_items[$line_no]->qty_dispatched =
input_num('Line'.$line_no);
}
}
+ else {
+ $ok = 0;
+ }
if (isset($_POST['Line'.$line_no.'Desc'])) {
$line_desc = $_POST['Line'.$line_no.'Desc'];
}
}
}
+ return $ok;
}
//-----------------------------------------------------------------------------
if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) {
- $ord = new Cart(30,$_GET['OrderNumber'], true);
+ $ord = new Cart(30, $_GET['OrderNumber'], true);
/*read in all the selected order into the Items cart */
}
copy_from_cart();
-
+
} elseif ( !processing_active() ) {
/* This page can only be called with an order number for invoicing*/
$cart = &$_SESSION['Items'];
$cart->ship_via = $_POST['ship_via'];
$cart->freight_cost = input_num('ChargeFreightCost');
- $cart->document_date = $_POST['DispatchDate'];
+ $cart->document_date = $_POST['DispatchDate'];
$cart->due_date = $_POST['due_date'];
$cart->Location = $_POST['Location'];
$cart->Comments = $_POST['Comments'];
$cart = &$_SESSION['Items'];
$_POST['ship_via'] = $cart->ship_via;
$_POST['ChargeFreightCost'] = price_format($cart->freight_cost);
- $_POST['DispatchDate']= $cart->document_date;
+ $_POST['DispatchDate'] = $cart->document_date;
$_POST['due_date'] = $cart->due_date;
- $_POST['Location']= $cart->Location;
- $_POST['Comments']= $cart->Comments;
+ $_POST['Location'] = $cart->Location;
+ $_POST['Comments'] = $cart->Comments;
}
//------------------------------------------------------------------------------
// Update cart delivery quantities/descriptions
foreach ($_SESSION['Items']->line_items as $line=>$itm) {
if (isset($_POST['Line'.$line])) {
- if (!check_num('Line'.$line, $itm->qty_done, $itm->quantity) == 0) {
+ if($_SESSION['Items']->trans_no) {
+ $min = $itm->qty_done;
+ $max = $itm->quantity;
+ } else {
+ $min = 0;
+ $max = $itm->quantity - $itm->qty_done;
+ }
+
+ if (check_num('Line'.$line, $min, $max)) {
$_SESSION['Items']->line_items[$line]->qty_dispatched =
input_num('Line'.$line);
} else {
+ set_focus('Line'.$line);
$ok = 0;
}
}
}
+if (isset($_POST['Update']) || isset($_POST['_Location_update'])) {
+ $Ajax->activate('Items');
+}
//------------------------------------------------------------------------------
start_form(false, true);
$_POST['Location'] = $_SESSION['Items']->Location;
}
label_cell(_("Delivery From"), "class='tableheader2'");
-locations_list_cells(null, 'Location',$_POST['Location'], false, true);
+locations_list_cells(null, 'Location', null, false, true);
if (!isset($_POST['ship_via'])) {
$_POST['ship_via'] = $_SESSION['Items']->ship_via;
end_table(1); // outer table
display_heading(_("Delivery Items"));
-
+div_start('Items');
start_table("$table_style width=80%");
$th = array(_("Item Code"), _("Item Description"), _("Ordered"), _("Units"), _("Delivered"),
_("This Delivery"), _("Price"), _("Tax Type"), _("Discount"), _("Total"));
textarea_row(_("Memo"), 'Comments', null, 50, 4);
end_table(1);
-
+div_end();
submit_center_first('Update', _("Update"),
_('Refresh document page'), true);
submit_center_last('process_delivery', _("Process Dispatch"),
end_page();
exit;
-} else {
+} elseif (!check_quantities()) {
+ display_error(_("Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet."));
+}
+if (isset($_POST['Update'])) {
+ $Ajax->activate('Items');
+}
+//-----------------------------------------------------------------------------
+function check_quantities()
+{
+ $ok =1;
foreach ($_SESSION['Items']->line_items as $line_no=>$itm) {
if (isset($_POST['Line'.$line_no])) {
- if (!check_num('Line'.$line_no, 0, ($itm->quantity - $itm->qty_done))) {
+ if($_SESSION['Items']->trans_no) {
+ $min = $itm->qty_done;
+ $max = $itm->quantity;
+ } else {
+ $min = 0;
+ $max = $itm->quantity - $itm->qty_done;
+ }
+ if (check_num('Line'.$line_no, $min, $max)) {
$_SESSION['Items']->line_items[$line_no]->qty_dispatched =
input_num('Line'.$line_no);
}
+ else {
+ $ok = 0;
+ }
+
}
if (isset($_POST['Line'.$line_no.'Desc'])) {
}
}
}
+ return $ok;
}
-//-----------------------------------------------------------------------------
function copy_to_cart()
{
return false;
}
+ if (!check_quantities()) {
+ display_error(_("Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet."));
+ return false;
+ }
+
return true;
}
display_heading(_("Invoice Items"));
+div_start('Items');
start_table("$table_style width=80%");
$th = array(_("Item Code"), _("Item Description"), _("Delivered"), _("Units"), _("Invoiced"),
_("This Invoice"), _("Price"), _("Tax Type"), _("Discount"), _("Total"));
label_row(_("Invoice Total"), $display_total, "colspan=9 align=right","align=right", $is_batch_invoice ? 2 : 0);
end_table(1);
+div_end();
start_table($table_style2);
-
textarea_row(_("Memo"), 'Comments', null, 50, 4);
end_table(1);
$line = &$this->line_items[$line_no];
$line->qty_dispatched = $line->quantity - $line->qty_done;
}
+ $this->document_date = Today();
}
} else { // derivative transaction
read_sales_trans($type, $trans_no, $this);
void_gl_trans($type, $type_no, true);
- // for invoices and credits related to invoices,
// reverse all the changes in the sales order
$items_result = get_customer_trans_details($type, $type_no);
$order = get_customer_trans_order($type, $type_no);
if ($order) {
+ $order_items = get_sales_order_details($order);
while ($row = db_fetch($items_result)) {
- update_parent_line(13, $row['id'], -$row['quantity']);
+ $order_line = db_fetch($order_items);
+ update_parent_line(13, $order_line['id'], -$row['quantity']);
}
}
void_bank_trans($type, $type_no, true);
void_gl_trans($type, $type_no, true);
- // for invoices and credits related to invoices,
- // reverse all the changes in the sales order
+ // reverse all the changes in parent document(s)
$items_result = get_customer_trans_details($type, $type_no);
- $delivery = get_customer_trans_link($type, $type_no);
+ $deliveries = get_parent_trans($type, $type_no);
- if ($delivery) {
+ if (count($deliveries)) {
+ $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
while ($row = db_fetch($items_result)) {
- update_parent_line(10, $row['id'], -$row['quantity']);
+ $src_line = db_fetch($srcdetails);
+ update_parent_line(10, $src_line['id'], -$row['quantity']);
}
}
-
// clear details after they've been reversed in the sales order
void_customer_trans_details($type, $type_no);
{
$doc_type = get_parent_type($doc_type);
- //echo "update line: $line_id, $doc_type, $qty_dispatch";
+// echo "update line: $line_id, $doc_type, $qty_dispatched";
if ($doc_type==0)
return false;
else {