<?php
/**********************************************************************
***********************************************************************/



function get_customer_id_by_cust_ref($customer_ref)
{
    $sql = "SELECT *
            FROM ".TB_PREF."debtors_master
            WHERE debtor_ref =".db_escape($customer_ref);

    $result = db_query($sql);
   
    if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['debtor_no']);
    }

        return array("success" => false, "message" => "Unknown customer code");
}


function get_customer_branch_id_by_name($branch_name, $debtor_no)
{
    $sql = "SELECT *
            FROM ".TB_PREF."cust_branch
            WHERE br_name=".db_escape($branch_name)." AND
                debtor_no=".db_escape($debtor_no);                   
    
    $result = db_query($sql);
   
    if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['debtor_no'], "tax_group_id"=> $row['tax_group_id']);
    }

        return array("success" => false, "message" => "Unknown branch name");
}

function get_customer_default_branch_id($debtor_no)
{
    $sql = "SELECT *
            FROM ".TB_PREF."cust_branch
            WHERE debtor_no=".db_escape($debtor_no);                   
    
    $result = db_query($sql);
   
    if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['debtor_no'], "tax_group_id"=> $row['tax_group_id'], "name"=> $row['br_name']);
    }

        return array("success" => false, "message" => "Unknown branch name");
}


function get_supplier_id_by_supp_ref($customer_ref)
{
    $sql = "SELECT *
            FROM ".TB_PREF."suppliers
            WHERE supp_ref =".db_escape($customer_ref);

    $result = db_query($sql);
   
    if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['supplier_id']);
    }

        return array("success" => false, "message" => "Unknown supplier code");
}

function get_bank_account_id_by_account_no($bank_account_no)
{
    $sql = "SELECT *
            FROM ".TB_PREF."bank_accounts 
            WHERE bank_account_number=".db_escape($bank_account_no);
             

    $result = db_query($sql);
   
    if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['id']);
    }

        return array("success" => false, "message" => "Unknown bank account number");
}
