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


function get_supplier_invoice_details($from_date, $to_date, $new_only = true, $search_group_reference = '')
{ 
    $sql = "SELECT inv.*,               
                    supp.supp_name
                    
            FROM ".TB_PREF."supp_trans inv 
                    LEFT JOIN ".TB_PREF."suppliers supp ON
                        supp.supplier_id = inv.supplier_id 
                     
            WHERE inv.type IN (".db_escape(ST_SUPPINVOICE).",".db_escape(ST_SUPPLIER_TRANSPORT_INVOICES).",".db_escape(ST_SUBCONTRACTOR_INVOICE).") AND
                    (inv.tran_date >=".db_escape(date2sql($from_date))." AND inv.tran_date <=".db_escape(date2sql($to_date)).")";
    
        
     
      // $new_only = 0;
        if($new_only){
            $sql .= " AND inv.group_reference = '' ";
        }  
        
        if($search_group_reference != ''){
            $sql .= " AND inv.group_reference LIKE ".db_escape('%'.$search_group_reference.'%');
        }
        
        $sql .= " ORDER BY inv.created_on";
        
    return db_query($sql);    
    
}


function update_supplier_invoice_group_reference($type, $id, $new_group_reference)
{
    $sql = "UPDATE ".TB_PREF."supp_trans SET 
                                group_reference = ".db_escape($new_group_reference)." 
            WHERE trans_no = ".db_escape($id)." AND type = ".db_escape($type);
    
    db_query($sql);
    
}


function get_supp_invoice_details_for_edit($selected_id)
 {
    $sql = "SELECT *
            FROM ".TB_PREF."supplier_invoices2
            WHERE supp_inv_no=".db_escape($selected_id);
    
    $result = db_query($sql);
    return db_fetch($result);
     
 }
 
//function get_max_amount_of_groud_id()
//{
//    $sql = "SELECT MAX(group_id) max_group_no 
//            FROM ".TB_PREF."supplier_invoice_details";
//    
//$result = db_query($sql) ;
//return db_fetch($result);   
//    
//}





?>
