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

function get_requisition_detail_edit($pr_line_id, $pr_po_line_id)
{
	$sql = "SELECT 
                    pr.pr_no,
                    prd.id pr_line_id,
                    prd.item_code , 
                    prd.quantity requested_quantity,
                    prd.quantity_ordered,
                    pr.project_id,
                    pr.location pr_loc_code,
                    prl.location_name pr_location_name,
                    sm.units base_unit, 
                    sm.description item_description,
                    sm.editable editable_descri,  
                    prd.estimate_price, 
                    pm.description project_description,
                    pt.description task_description,
                    sm.description, 
                    prd.item_pr_description, 
                    prd.line_comment, 
                    prd.requested_unit,
                    prd.requested_unit_qty,
                    prd.required_date,
                    prd.project_site_id,
                    ps.description project_site_name,
                    ru.convertion_factor req_unit_conversion_factor,
                    unit.name requested_unit_name,  
                    ppd.item_code pr_po_item_code,
                    ppd.item_description pr_po_item_description,
                    ppd.supplier_id ,
                    ppd.order_quantity,
                    ppd.order_unit,
                    ppd.order_unit_qty,
                    ppd.order_unit_price,
                    ppd.order_unit_price_discount,
                    ou.convertion_factor order_unit_conversion_factor,
                    ppd.required_date order_line_required_date,
                    ppd.id pr_po_line_id,
                    ppd.line_loc_code,
                    ppd.project_site_id pr_po_project_site_id,
                    ppd.row_state,
                    dp.value_name department_name,
                    req.real_name requester_name,
                    p_offic.real_name created_pofficer_name,
                    p_offiu.real_name updated_pofficer_name 
                FROM ".TB_PREF."purchase_requisition_details prd                     
                    INNER JOIN ".TB_PREF."purchase_requisitions pr ON 
                        prd.requisition_id = pr.pr_no 
                    INNER JOIN ".TB_PREF."projects_master pm ON 
                        pr.project_id = pm.project_id 
                    INNER JOIN ".TB_PREF."stock_master sm ON 
                        prd.item_code = sm.stock_id   
                    INNER JOIN ".TB_PREF."item_units unit ON 
                        prd.requested_unit = unit.abbr   
                    INNER JOIN ".TB_PREF."alternate_units ru ON 
                        ru.stock_id = sm.stock_id AND 
                        prd.requested_unit = ru.alternate_unit 
                    INNER JOIN ".TB_PREF."list_values dp ON 
                        pm.department_id = dp.id   
                    INNER JOIN ".TB_PREF."project_tasks pt ON 
                        prd.task_id = pt.task_id 
                    INNER JOIN ".TB_PREF."users req ON 
                        pr.created_by = req.id  
                    LEFT JOIN ".TB_PREF."pr_po_details ppd ON 
                        prd.id = ppd.pr_line_id 
                    LEFT JOIN ".TB_PREF."locations prl ON 
                        pr.location = prl.loc_code 
                    LEFT JOIN ".TB_PREF."alternate_units ou ON 
                        ou.stock_id = sm.stock_id AND 
                        ppd.order_unit = ou.alternate_unit 
                    LEFT JOIN ".TB_PREF."project_sites ps ON 
                        prd.project_site_id = ps.id 
                    LEFT JOIN ".TB_PREF."users p_offic 
                        ON ppd.created_by = p_offic.id
                    LEFT JOIN ".TB_PREF."users p_offiu 
                        ON ppd.updated_by = p_offiu.id 
                WHERE ppd.pr_line_id = ".db_escape($pr_line_id)."
                    AND ppd.id = ".db_escape($pr_po_line_id)."";
   

	$result = db_query($sql, "could not get get_requisition_detail_edit");

	return db_fetch($result);
}

function get_pr_po_details($pr_line_id)
{
    $sql = "SELECT ppd.*,
                   sup.supp_name,
                   loc.location_name,
                   pod.order_no,
                   p_offic.real_name created_pofficer_name,
                   p_offiu.real_name updated_pofficer_name 
                   
            FROM ".TB_PREF."pr_po_details ppd  
                LEFT JOIN ".TB_PREF."suppliers sup 
                    ON ppd.supplier_id = sup.supplier_id 
                LEFT JOIN ".TB_PREF."locations loc  
                    ON ppd.line_loc_code = loc.loc_code  
                LEFT JOIN ".TB_PREF."purch_order_details pod   
                    ON ppd.po_line_id = pod.po_detail_item 
                LEFT JOIN ".TB_PREF."users p_offic 
                    ON ppd.created_by = p_offic.id
                LEFT JOIN ".TB_PREF."users p_offiu 
                    ON ppd.updated_by = p_offiu.id 
            WHERE ppd.pr_line_id = ".db_escape($pr_line_id)."";
            
    return db_query($sql, "could not get_pr_po_details");
}

function get_pr_item_purchase_history($item_code)
{
    $sql = "SELECT pod.*,
                   sup.supplier_id,
                   sup.supp_name,
                   sup.supp_address 
            FROM ".TB_PREF."purch_order_details pod 
                JOIN ".TB_PREF."purch_orders po 
                    ON pod.order_no = po.order_no 
                JOIN ".TB_PREF."suppliers sup  
                    ON sup.supplier_id = po.supplier_id 
                    
            WHERE pod.item_code = ".db_escape($item_code)." 
            ORDER BY pod.order_no DESC LIMIT 50";
    
    return db_query($sql, "get_pr_item_purchase_history");
}

function get_pr_detail_info_line($pr_line_id)
{
        
    $sql = "SELECT prd.*,
                ru.convertion_factor req_unit_conversion_factor,
                lu.name req_unit,
                sm.description item_description, 
                sm.stock_control_method,
                sm.material_cost + sm.labour_cost + sm.overhead_cost AS standard_cost,
                bu.name base_unit_name,
                pt.description task_description,
                ps.description project_site_name,
                pr_po.id allocation_id,
                prl.location_name pr_location_name,
                pr.pr_no,
                pm.description project_description,
                prd.id pr_line_id,
                pr.project_id,
                pr.location pr_loc_code,
                sm.editable editable_descri,
                dp.value_name department_name,
                req.real_name requester_name,
                prd.quantity requested_quantity 
                
            FROM ".TB_PREF."purchase_requisition_details prd
                INNER JOIN ".TB_PREF."purchase_requisitions pr ON 
                        prd.requisition_id = pr.pr_no 
                INNER JOIN ".TB_PREF."projects_master pm ON 
                        pr.project_id = pm.project_id 
                INNER JOIN ".TB_PREF."stock_master sm ON 
                        prd.item_code = sm.stock_id 
                INNER JOIN ".TB_PREF."item_units bu ON 
                        bu.abbr=sm.units
                INNER JOIN ".TB_PREF."project_tasks pt ON 
                        prd.task_id = pt.task_id 
                INNER JOIN ".TB_PREF."list_values dp ON 
                        pm.department_id = dp.id 
                INNER JOIN ".TB_PREF."users req ON 
                        pr.created_by = req.id 
                INNER JOIN ".TB_PREF."alternate_units ru ON 
                        ru.stock_id = sm.stock_id AND 
                        prd.requested_unit = ru.alternate_unit 
                LEFT JOIN ".TB_PREF."project_sites ps ON 
                        prd.project_site_id = ps.id  
                LEFT JOIN ".TB_PREF."item_units lu ON 
                        lu.abbr=prd.units
                LEFT JOIN ".TB_PREF."pr_po_details pr_po ON 
                        pr_po.pr_line_id=prd.id 
                LEFT JOIN ".TB_PREF."locations prl ON 
                        pr.location = prl.loc_code 
            WHERE 
                prd.id = ".$pr_line_id ;
    
    $result = db_query($sql,"Purchase requisition item detail could not be retreived");

    return db_fetch($result);

}


?>



































































