function read($type, $trans_no = 0, $view=false ) {
if (!is_array($trans_no)) $trans_no = array($trans_no);
-
if ($trans_no[0]) {
if ($type == 30) { // sales order
read_sales_order($trans_no[0], $this);
if ($view) { // prepare for DN/IV entry
for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
$line = &$this->line_items[$line_no];
+ $line->src_id = $line->id; // save src line ids for update
$line->qty_dispatched = $line->quantity - $line->qty_done;
}
}
- } else { // derivative transaction
+ } else { // derivative transaction
read_sales_trans($type, $trans_no, $this);
if ($this->order_no) { // free hand credit notes have no order_no
$sodata = get_sales_order_header($this->order_no);
$sign = 1; // $type==13 ? 1 : -1; // this is strange debtor_trans atavism
$line = &$this->line_items[$line_no];
+ $line->src_id = $srcline['id']; // save src line ids for update
$line->qty_old = $line->qty_dispatched = $line->quantity;
$line->quantity += $sign * ($srcline['quantity'] - $srcline['qty_done']); // add free qty on src doc
}
} else {
for($line_no = 0; $line_no < count($this->line_items); $line_no++) {
$line = &$this->line_items[$line_no];
+ $line->src_id = $line->id; // save src line ids for update
$line->qty_dispatched = $line->quantity;
}
}
var $tax_type;
var $tax_type_name;
var $src_no; // number of src doc for this line
+ var $src_id;
var $quantity;
var $price;
var $discount_percent;
//
function write_credit_note($credit_note, $write_off_acc)
{
- // Changed 2008-09-26 Joe Hunt -------
- $credit_invoice = count(array_keys($credit_note->src_docs)) ? reset(array_keys($credit_note->src_docs)) : 0;
+ $credit_invoice = is_array($credit_note->src_docs) ?
+ reset(array_keys($credit_note->src_docs)) : $credit_note->src_docs;
$credit_date = $credit_note->document_date;
$tax_group_id = $credit_note->tax_group_id;
void_stock_move(11, $credit_no);
void_customer_trans_tax_details(11, $credit_no);
}
-
if ($credit_invoice) {
$invoice_alloc_balance = get_DebtorTrans_allocation_balance(10, $credit_invoice);
update_customer_trans_version(get_parent_type(11), $credit_note->src_docs );
- if ($invoice_alloc_balance > 0) { /*the invoice is not already fully allocated */
+ if ($invoice_alloc_balance > 0) { //the invoice is not already fully allocated
$total = $credit_note_total + $credit_note->freight_cost +
$items_added_tax + $freight_added_tax;
}
}
+
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->id,($credit_line->qty_dispatched
+ update_parent_line(11, $credit_line->src_id,($credit_line->qty_dispatched
-$credit_line->qty_old));
}
"A tax GL posting for this credit note could not be inserted");
}
}
-
add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
if ($trans_no == 0) {
// Now update sales_order_details for the quantity delivered
if ($delivery_line->qty_old != $delivery_line->qty_dispatched)
- update_parent_line(13, $delivery_line->id,
+ update_parent_line(13, $delivery_line->src_id,
$delivery_line->qty_dispatched-$delivery_line->qty_old);
if ($delivery_line->qty_dispatched != 0) {
// Update delivery items for the quantity invoiced
if ($invoice_line->qty_old != $invoice_line->qty_dispatched)
- update_parent_line(10, $invoice_line->id, ($invoice_line->qty_dispatched-$invoice_line->qty_old));
+ update_parent_line(10, $invoice_line->src_id, ($invoice_line->qty_dispatched-$invoice_line->qty_old));
if ($invoice_line->qty_dispatched != 0) {
$stock_gl_code = get_stock_gl_code($invoice_line->stock_id);
if (count($cart->src_docs) == 1) {
// if this child document has only one parent - update child link
- $del_no = reset($cart->src_docs);
+ $del_no = reset(array_keys($cart->src_docs));
$sql = 'UPDATE '.TB_PREF.'debtor_trans SET trans_link = ' . $del_no .
' WHERE type='.$cart->trans_type.' AND trans_no='. $inv_no ;