read_sales_order($trans_no[0], $this, $type);
} else { // other type of sales transaction
read_sales_trans($type, $trans_no, $this);
- $this->prepayments = get_payments_for($trans_no[0], $type);
+ $this->prepayments = get_payments_for($trans_no[0], $type, $this->customer_id);
+ $this->update_payments();
if ($this->order_no) { // free hand credit notes have no order_no
$sodata = get_sales_order_header($this->order_no, ST_SALESORDER);
$this->cust_ref = $sodata["customer_ref"];
$remainder = prepaid_invoice_remainder($this->order_no);
// recalculate prepaid part from payments
- if ($this->payment_terms['days_before_due'] < 0)
+ if ($this->payment_terms['days_before_due'] == -1)
{ // this is partial invoice for selected prepayments made.
$paid = 0;
foreach($this->prepayments as $payment)
$paid += $payment['amt'];
- $this->prep_amount = min($remainder, $paid);
+ $this->prep_amount = $this->trans_no ? $paid : min($remainder, $paid);
} else // this is final invoice
$this->prep_amount = $remainder;
}