<?php

function view_lot_move_lines_by_type($type, $trans_no, $line_id) {
    $line = get_lot_allocation_parent_line($type, $trans_no, $line_id);

        switch ($type) {
            case ST_JOB_MATERIAL_ISSUE : 
            case ST_JOB_MATERIAL_RETURN : 
            case ST_DIRECT_PURCHASE_RECEIPT : 
            case ST_DIRECT_PURCHASE_RETURN : 
            case ST_BUDGET_TO_BUDGET_TRANSFER : 
                view_lot_move_lines($type, $trans_no, $line_id, $line);

                break;
        }
}

function view_lot_move_lines($type, $trans_no, $line_id, $line) {

    $stock_id = $line['stock_id']; $loc_code = $line['loc_code']; $conversion_factor = $line['conversion_factor'];
    $issued_tran_unit_name = $line['tran_unit_name'];
    
    display_heading('Lot Move Details of '.get_stock_item_formatted_name($stock_id).' item in '.$line['location_name']);
    
    start_table(TABLESTYLE, "width=70%");

        $th = array(_("Id"), _("Lot Name"), _("Location"), _("Tran Unit"), _("Tran Qty"), _("Base Unit"), _("Base Qty"));  
        table_header($th);

        $dec = 4;
        $k = 0; //row colour counter
        $result = get_lot_move_lines_details($type, $trans_no, $line_id, $stock_id, $loc_code);   
            while ($row = db_fetch($result)) {
                $tran_id = $row['tran_id'];
                
                alt_table_row_color($k);
                    label_cell($tran_id, 'align=center');
                    label_cell($row['lot_reference']);
                    label_cell($row['location_name']);
                    label_cell($row['unit_name'], 'align=center');
                    label_cell(number_format(abs($row["tran_qty"]), $dec), 'align=right');
                    label_cell(get_item_base_unit_name($row["stock_id"]), 'align=center');
                    label_cell(number_format(abs($row["qty"]), $dec), 'align=right');
                end_row();        
            }
            
            $base_qty_total = get_lot_moves_total_qty($type, $trans_no, $line_id, $stock_id, $loc_code);
            $tran_qty_total = abs($base_qty_total)/ $conversion_factor;
            start_row();
                label_cell(text_bold("Total '$issued_tran_unit_name'"), 'align=right colspan=4');
                label_cell(text_bold(number_format($tran_qty_total, $dec)), 'align=right');
                label_cell(text_bold(number_format(abs($base_qty_total), $dec)), 'colspan=2 align=right');
            end_row();
            
    end_table(3);
}
    
?>