+function get_customer_to_order($customer_id) {
+
+ // Now check to ensure this account is not on hold */
+ $sql = "SELECT cust.name,
+ cust.address,
+ credit_status.dissallow_invoices,
+ cust.sales_type AS salestype,
+ cust.dimension_id,
+ cust.dimension2_id,
+ stype.sales_type,
+ stype.tax_included,
+ stype.factor,
+ cust.curr_code,
+ cust.discount,
+ cust.payment_terms,
+ cust.pymt_discount,
+ 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,"
+ .TB_PREF."credit_status credit_status,"
+ .TB_PREF."sales_types stype
+ WHERE cust.sales_type=stype.id
+ AND cust.credit_status=credit_status.id
+ AND cust.debtor_no=".db_escape($customer_id)
+ ." GROUP by cust.debtor_no";
+
+ $result =db_query($sql,"Customer Record Retreive");
+ return db_fetch($result);
+}
+
+function get_branch_to_order($customer_id, $branch_id) {
+
+ // the branch was also selected from the customer selection so default the delivery details from the customer branches table cust_branch. The order process will ask for branch details later anyway
+ $sql = "SELECT branch.br_name,
+ branch.br_address,
+ branch.br_post_address,
+ default_location, location_name, default_ship_via,
+ tax_group.name AS tax_group_name,
+ tax_group.id AS tax_group_id
+ FROM ".TB_PREF."cust_branch branch,"
+ .TB_PREF."tax_groups tax_group,"
+ .TB_PREF."locations location
+ WHERE branch.tax_group_id = tax_group.id
+ AND location.loc_code=default_location
+ AND branch.branch_code=".db_escape($branch_id)."
+ AND branch.debtor_no=".db_escape($customer_id);
+
+ return db_query($sql,"Customer Branch Record Retreive");
+}