} /* inserted line items into sales order details */
add_audit_trail($order->trans_type, $order_no, $order->document_date);
- $Refs->save($order->trans_type, $order_no, $order->reference);
+ $Refs->save($order->trans_type, $order_no, $order->reference, null, $order->fixed_asset);
hook_db_postwrite($order, $order->trans_type);
commit_transaction();
{
foreach ($order as $so_num => $so_ver) {
$sql= 'UPDATE '.TB_PREF.'sales_orders SET version=version+1 WHERE order_no='. db_escape($so_num).
- ' AND version='.$so_ver . " AND trans_type=30";
+ ' AND version='.$so_ver . " AND trans_type=".ST_SALESORDER;
db_query($sql, 'Concurrent editing conflict while sales order update');
}
}
hook_db_prewrite($order, $order->trans_type);
if ($order->trans_type == ST_SALESORDER)
- $allocs = get_payments_for($order_no, ST_SALESORDER);
+ $allocs = get_payments_for($order_no, $order->trans_type, $order->customer_id);
$sql = "UPDATE ".TB_PREF."sales_orders SET type =".db_escape($order->so_type)." ,
debtor_no = " . db_escape($order->customer_id) . ",
} /* inserted line items into sales order details */
if ($order->trans_type == ST_SALESORDER)
- reallocate_payments($order_no, ST_SALESORDER, $ord_date, $total, $allocs);
+ reallocate_payments($order_no, ST_SALESORDER, $ord_date, $total, $allocs, $order->customer_id);
add_audit_trail($order->trans_type, $order_no, $order->document_date, _("Updated."));
- $Refs->save($order->trans_type, $order_no, $order->reference);
+ $Refs->save($order->trans_type, $order_no, $order->reference, null, $order->fixed_asset);
hook_db_postwrite($order, $order->trans_type);
commit_transaction();
qty_sent as qty_done,
item.units,
item.mb_flag,
- item.material_cost + item.labour_cost + item.overhead_cost AS standard_cost
+ item.material_cost
FROM ".TB_PREF."sales_order_details line,"
.TB_PREF."stock_master item
- WHERE line.stk_code = line.stock_id
+ WHERE line.stk_code = item.stock_id
AND order_no =".db_escape($order_no)
." AND trans_type = ".db_escape($trans_type) . " ORDER BY id";
$order->alloc = $myrow['alloc'];
$order->sum_paid = $myrow["sum_paid"]; // sum of all prepayments to so (also invoiced)
$order->prep_amount = $myrow["prep_amount"];
- $order->prepayments = get_payments_for($order_no, $myrow['trans_type']);
+ $order->prepayments = get_payments_for($order_no, $myrow['trans_type'], $myrow['debtor_no']);
$result = get_sales_order_details($order_no, $order->trans_type);
if (db_num_rows($result) > 0)
{
$order->add_to_cart($line_no,$myrow["stk_code"],$myrow["quantity"],
$myrow["unit_price"], $myrow["discount_percent"],
- $myrow["qty_done"], $myrow["standard_cost"], $myrow["description"], $myrow["id"] );
+ $myrow["qty_done"], $myrow["material_cost"], $myrow["description"], $myrow["id"] );
$line_no++;
}
}
cust.discount,
cust.payment_terms,
cust.pymt_discount,
- cust.credit_limit - Sum(IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2,
+ cust.credit_limit - Sum(IFNULL(IF(trans.type IN(".implode(',', array(ST_CUSTCREDIT, ST_CUSTPAYMENT, ST_BANKDEPOSIT))."),
-1, 1) * (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount),0)) as cur_credit
FROM ".TB_PREF."debtors_master cust
LEFT JOIN ".TB_PREF."debtor_trans trans ON trans.type!=".ST_CUSTDELIVERY." AND trans.debtor_no = cust.debtor_no,"
$sql = "UPDATE ".TB_PREF."sales_orders SET type = ".db_escape($status)." WHERE order_no=".db_escape($id);
db_query($sql, "Can't change sales order type");
}
+
+/*
+ Check whether sales order is issued in prepaid mode and already opened
+*/
+
+function is_prepaid_order_open($order_no)
+{
+ $sql = "SELECT count(*)
+ FROM ".TB_PREF."sales_orders o,
+ ((SELECT trans_no_to FROM ".TB_PREF."cust_allocations
+ WHERE trans_type_to=".ST_SALESORDER." AND trans_no_to=".db_escape($order_no).")
+ UNION
+ (SELECT order_ FROM ".TB_PREF."debtor_trans
+ WHERE type=".ST_SALESINVOICE." AND order_=".db_escape($order_no).")) related
+ WHERE
+ o.prep_amount>0
+ AND o.trans_type = ".ST_SALESORDER."
+ AND o.order_no = " . db_escape($order_no);
+
+ $result = db_fetch(db_query($sql, "cannot check prepaid order open"));
+
+ return $result[0];
+}