commit_transaction();
}
+/*
+ This function probably should be renamed to get_customer_summary
+*/
function get_customer_details($customer_id, $to=null, $all=true)
{
$past1 = get_company_pref('past_due_days');
$past2 = 2 * $past1;
// removed - debtor_trans.alloc from all summations
- $sign = "IF(`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT,ST_JOURNAL))."), -1, 1)";
+ $sign = "IF(`type` IN(".implode(',', array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)";
if ($all)
$value = "IFNULL($sign*(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount),0)";
else
$due = "IF (trans.type=".ST_SALESINVOICE.", trans.due_date, trans.tran_date)";
$sql = "SELECT debtor.name, debtor.curr_code, terms.terms, debtor.credit_limit,
credit_status.dissallow_invoices, credit_status.reason_description,
- Sum(IFNULL($value,0)) AS Balance,
+ Sum($value) 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
.TB_PREF."credit_status credit_status
WHERE
debtor.payment_terms = terms.terms_indicator
- AND debtor.credit_status = credit_status.id
- AND debtor.debtor_no = ".db_escape($customer_id);
+ AND debtor.credit_status = credit_status.id";
+ if ($customer_id)
+ $sql .= " AND debtor.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) > ".FLOAT_COMP_DELTA;
$sql .= " GROUP BY
return $myrow[0];
}
+function get_customers_search($customer)
+{
+ global $SysPrefs;
+
+ if (isset($SysPrefs->max_rows_in_search))
+ $limit = $SysPrefs->max_rows_in_search;
+ else
+ $limit = 10;
+
+ $sql = "SELECT debtor_no, name, debtor_ref, address, tax_id FROM ".TB_PREF."debtors_master
+ WHERE ( name LIKE " . db_escape("%" . $customer. "%") . " OR
+ debtor_ref LIKE " . db_escape("%" . $customer. "%") . " OR
+ address LIKE " . db_escape("%" . $customer. "%") . " OR
+ tax_id LIKE " . db_escape("%" . $customer. "%").")
+ ORDER BY name LIMIT 0,".(int)($limit);
+
+ return db_query($sql, "Failed in retreiving customer list.");
+}