<?php

function get_sql_for_asset_verification_count_search($location, $from_date_, $to_date_) {
    $from_date = date2sql($from_date_);
    $to_date = date2sql($to_date_);
        
	$sql = "SELECT av.asset_verification_count_no,
                    av.reference,
                    av.loc_code,
                    av.tran_date,
                    av.status_id,
                    loc.location_name 
		FROM ".TB_PREF."asset_verification_counts av,
                    ".TB_PREF."asset_locations loc            
		WHERE av.loc_code = loc.loc_code 
                    AND av.tran_date >= ".db_escape($from_date)." 
                    AND av.tran_date <= ".db_escape($to_date);
                
                    if (strlen($location) > 1) {
                        $sql .= " AND av.loc_code = ".db_escape($location);
                    }
                    
            $sql .= " ORDER BY av.asset_verification_count_no";
                   
	return $sql;
}       

function get_view_asset_verification_count_details($asset_verification_count_no, $sheet_no) {
    $sql = "SELECT scd.*,
                sm.description,  
                sm.asset_code,  
                sm.current_value  
            FROM ".TB_PREF."asset_verification_count_details scd 
                INNER JOIN ".TB_PREF."asset_master sm 
                    ON sm.asset_id = scd.asset_id  
            WHERE scd.asset_verification_count_no = ".db_escape($asset_verification_count_no);
    
        if ($sheet_no > 0) {
            $sql .= " AND scd.sheet_no = ".db_escape($sheet_no);
        }
               
        return db_query($sql, "get_view_asset_verification_count_details"); 
}

function get_asset_verification_count_view_header($asset_verification_count_no) {
    $sql = "SELECT sc.asset_verification_count_no,
                sc.reference,
                sc.loc_code,
                sc.tran_date,
                sc.status_id,
                sc.comments,
                l.location_name  
            FROM ".TB_PREF."asset_verification_counts sc,
                ".TB_PREF."asset_locations l  
            WHERE sc.loc_code = l.loc_code 
                AND sc.asset_verification_count_no = ".db_escape($asset_verification_count_no);
               
        $result = db_query($sql, "get_asset_verification_count_view_header"); 
        return db_fetch($result);
}

?>