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



function get_batch_item_issue_selected_dii_transactions_common_values($type, $batch_no)
{     
    $sql = " SELECT DISTINCT biit.type,
                            biit.trans_no,
                            biit.source_type_id,
                            biit.source_type_no,
                            biit.movement_type,
                            biit.linked_field_type, 
                            
                            biid.employee_company_code,
                            biid.employee_code  
            FROM ".TB_PREF."batch_item_issue_transactions biit 
                JOIN ".TB_PREF."batch_item_issue_details biid 
                    ON biid.id = biit.bii_line_id  
            WHERE biid.type = ".db_escape($type)." 
                AND biid.trans_no = ".db_escape($batch_no)." 
                AND biit.source_type_id = ".db_escape(ST_DAILY_ITEM_ISSUE)." 
                AND biit.target_line_id = 0 ";
    
    
    $sql .= " ORDER BY biit.source_type_id, biit.source_type_no ";

    return db_query($sql, "get_batch_item_issue_selected_dii_transactions");

}



function get_batch_item_issue_selected_dii_transactions($type, $batch_no, $source_type_id, $movement_type, $linked_field_type,
                                                                $employee_company_code, $employee_code)
{
     
    $sql = " SELECT biit.*,
                    biid.stock_id,
                    biid.item_description,
                    biid.daily_item_type, 
                    biid.item_description,
                    (sm.material_cost + sm.labour_cost + sm.overhead_cost) AS standard_cost, 
                    sm.mb_flag,
                    biid.line_comment 

            FROM ".TB_PREF."batch_item_issue_transactions biit 
                JOIN ".TB_PREF."batch_item_issue_details biid 
                    ON biid.id = biit.bii_line_id  
                JOIN ".TB_PREF."batch_item_issues biih   
                    ON biih.type = biit.type 
                    AND biih.trans_no = biit.trans_no    
                JOIN ".TB_PREF."stock_master sm    
                    ON sm.stock_id = biid.stock_id  
            WHERE biit.type = ".db_escape($type)." 
                AND biit.trans_no = ".db_escape($batch_no)." 
                AND biit.source_type_id = ".db_escape($source_type_id)." 
                AND biit.movement_type = ".db_escape($movement_type)." 
                AND biit.linked_field_type = ".db_escape($linked_field_type)." 
                AND biid.employee_company_code = ".db_escape($employee_company_code)." 
                AND biid.employee_code = ".db_escape($employee_code);
    
    $sql .= " ORDER BY biit.source_type_id, biit.source_type_no ";

    return db_query($sql, "get_batch_item_issue_selected_dii_transactions");

}

