And a few small bug fixes.
! -> Note
$ -> Affected files
+26-Apr-2010 Joe Hunt
+! Changed voiding of Direct Invoice to automatically void 'auto' delivery
+ and set SO quantity and qty_sent to 0.
+ And a few small bug fixes.
+$ /admin/db/voiding_db.inc
+ /sales/includes/sales_db.inc
+ /sales/includes/db/sales_credit_db.inc
+ /sales/includes/db/sales_invoice_db.inc
+ /sales/includes/db/sales_delivery_db.inc
+
21-Apr-2010 Joe Hunt
# Bug in systypes selector (no type update)
$ /admin/attachments.php
case ST_CUSTDELIVERY : // it's a customer dispatch
if (!exists_customer_trans($type, $type_no))
return false;
- if ($type == 13) // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
+ if ($type == ST_CUSTDELIVERY) // added 04 Oct 2008 by Joe Hunt. If delivery note has a not voided invoice, then NO.
{
$delivery = get_customer_trans($type_no, $type);
if ($delivery['trans_link'] != 0)
{
- if (get_voided_entry(10, $delivery['trans_link']) === false)
+ if (get_voided_entry(ST_SALESINVOICE, $delivery['trans_link']) === false)
return false;
}
}
foreach ($credit_note->line_items as $credit_line) {
if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) {
- update_parent_line(11, $credit_line->src_id,($credit_line->qty_dispatched
+ update_parent_line(ST_CUSTCREDIT, $credit_line->src_id,($credit_line->qty_dispatched
-$credit_line->qty_old));
}
//--------------------------------------------------------------------------------------------------
-function void_sales_delivery($type, $type_no)
+function void_sales_delivery($type, $type_no, $transactions=true)
{
- begin_transaction();
+ if ($transactions)
+ begin_transaction();
void_gl_trans($type, $type_no, true);
$order = get_customer_trans_order($type, $type_no);
if ($order) {
+ $auto = (get_reference(ST_SALESORDER, $order) == "auto");
$order_items = get_sales_order_details($order, ST_SALESORDER);
while ($row = db_fetch($items_result)) {
$order_line = db_fetch($order_items);
- update_parent_line(ST_CUSTDELIVERY, $order_line['id'], -$row['quantity']);
+ update_parent_line(ST_CUSTDELIVERY, $order_line['id'], -$row['quantity'], $auto);
}
}
// DO NOT MOVE THIS ABOVE VOIDING or we can end up with trans with alloc < 0
void_customer_trans($type, $type_no);
- commit_transaction();
+ if ($transactions)
+ commit_transaction();
}
?>
\ No newline at end of file
$deliveries = get_parent_trans($type, $type_no);
if ($deliveries !== 0) {
- $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
- while ($row = db_fetch($items_result)) {
- $src_line = db_fetch($srcdetails);
- update_parent_line($type, $src_line['id'], -$row['quantity']);
- }
+ if (count($deliveries) == 1 && get_reference(ST_CUSTDELIVERY, $deliveries[0]) == "auto")
+ {
+ void_sales_delivery(ST_CUSTDELIVERY, $deliveries[0], false);
+ $date_ = Today();
+ add_audit_trail(ST_CUSTDELIVERY, $deliveries[0], $date_, _("Voided."));
+ add_voided_entry(ST_CUSTDELIVERY, $deliveries[0], $date_, "");
+ }
+ else
+ {
+
+ $srcdetails = get_customer_trans_details(get_parent_type($type), $deliveries);
+ while ($row = db_fetch($items_result)) {
+ $src_line = db_fetch($srcdetails);
+ update_parent_line($type, $src_line['id'], -$row['quantity']);
+ }
+ }
}
// clear details after they've been reversed in the sales order
void_customer_trans_details($type, $type_no);
}
//--------------------------------------------------------------------------------------------------
-function update_parent_line($doc_type, $line_id, $qty_dispatched)
+function update_parent_line($doc_type, $line_id, $qty_dispatched, $auto=false)
{
$doc_type = get_parent_type($doc_type);
return false;
else {
if ($doc_type==ST_SALESORDER)
+ {
$sql = "UPDATE ".TB_PREF."sales_order_details
- SET qty_sent = qty_sent + $qty_dispatched
- WHERE id=".db_escape($line_id);
+ SET qty_sent = qty_sent + $qty_dispatched";
+ if ($auto)
+ $sql .= ", quantity = quantity + $qty_dispatched";
+ $sql .= " WHERE id=".db_escape($line_id);
+ }
else
$sql = "UPDATE ".TB_PREF."debtor_trans_details
SET qty_done = qty_done + $qty_dispatched