$past1 = get_company_pref('past_due_days');
$past2 = 2 * $past1;
// removed - debtor_trans.alloc from all summations
-
- $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1)
- * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
-
+ if ($all)
+ $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1)
+ * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
+ else
+ $value = "IFNULL(IF(trans.type=11 OR trans.type=12 OR trans.type=2, -1, 1)
+ * (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount -
+ trans.alloc),0)";
$due = "IF (trans.type=10, trans.due_date, trans.tran_date)";
$sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."payment_terms.terms,
".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description,
Sum(IFNULL($value,0)) AS Balance,
- Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0)) AS Due,
- Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past1,$value,0)) AS Overdue1,
- Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $past2,$value,0)) AS Overdue2
+ Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) > 0,$value,0)) AS Due,
+ Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $past1,$value,0)) AS Overdue1,
+ Sum(IF ((TO_DAYS('$todate') - TO_DAYS($due)) > $past2,$value,0)) AS Overdue2
FROM ".TB_PREF."debtors_master
LEFT JOIN ".TB_PREF."debtor_trans trans ON
AND ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
AND ".TB_PREF."debtors_master.debtor_no = ".db_escape($customer_id)." ";
if (!$all)
- $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > 0.004 ";
+ $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > ".FLOAT_COMP_DELTA." ";
$sql .= "GROUP BY
".TB_PREF."debtors_master.name,
".TB_PREF."payment_terms.terms,
$results = array();
$res = get_crm_persons('customer', $action, $customer_id);
while($contact = db_fetch($res))
+ {
+ if ($contact['lang'] == 'C') // Fix for improper lang in demo sql files.
+ $contact['lang'] = '';
$results[] = $contact;
-
+ }
return $results;
}
return !key_in_foreign_table($id, $tables, 'debtor_no');
}
+
+function get_customer_by_ref($reference)
+{
+ $sql = "SELECT * FROM ".TB_PREF."debtors_master WHERE debtor_ref=".db_escape($reference);
+
+ $result = db_query($sql, "could not get customer");
+
+ return db_fetch($result);
+}
+
?>
\ No newline at end of file