<?php

function display_view_stock_status_header($stock_id, $date, $loc_code) {
    start_table(TABLESTYLE, "width=60%");
    
        $stock_item_name = get_stock_item_formatted_name($stock_id);
        $location_name = get_location_name($loc_code);
        
        start_row();
            label_cells("Item:", $stock_item_name, "class='tableheader2'");
            label_cells("Date:", sql2date($date), "class='tableheader2'");
            label_cells("Location:", $location_name, "class='tableheader2'");
        end_row();

    end_table(2);
}

function display_view_stock_status_details($stock_id, $date, $loc_code, $type) {
    global $systypes_array;
    
    $dec = get_qty_dec($stock_id);
    
    start_table(TABLESTYLE, "width=60%");

        $th = array(_("Trans Type"), _("Trans #"), _("Reference"), _("Tran Date"), _("Quantity"));
        table_header($th);

            $result = get_view_stock_status_details($stock_id, $date, $loc_code, $type);
                $k = $total_qty = 0;
                while ($row = db_fetch($result)) {
                    alt_table_row_color($k);
                        label_cell($systypes_array[$row['trans_type']]);
                        label_cell(get_trans_view_str($row['trans_type'], $row['trans_no']), 'align=center');
                        label_cell($row['reference']);
                        label_cell(sql2date($row['tran_date']), 'align=center');
                        qty_cell($row['total_qty'], false, $dec);
                    end_row();
                    
                    $total_qty += $row['total_qty'];
                }
                
                start_row();
                    label_cell(text_bold('Total'), 'align=right colspan=4');
                    qty_cell($total_qty, true, $dec);
                end_row();
                
    end_table(3);
}

function get_view_stock_status_details($stock_id, $date, $loc_code, $type) {
    switch ($type) {
        case ST_SALESORDER:
            $result = get_view_sales_order_details($stock_id, $loc_code, $date);
            break;

        case ST_PURCH_REQ:
            $result = get_view_purchase_requisition_details($stock_id, $loc_code, $date);
            break;

        case ST_INVENTORY_ISSUE_REQUEST:
            $result = get_view_stock_adjustment_issue_details($stock_id, $loc_code, $date, ST_INVENTORY_ISSUE_REQUEST);
            break;

        case ST_TRANSFERREQ:
            $result = get_view_material_transfer_requisition_details_not_issued($stock_id, $loc_code, $date);
            break;

        case ST_MATERIAL_REQ:
            $result = get_view_material_requisition_details($stock_id, $loc_code, $date);
            break;

        case ST_PURCHORDER:
            $result = get_view_purchase_order_details($stock_id, $loc_code, $date);
            break;

        case ST_INVENTORY_RECEIPT_REQUEST:
            $result = get_view_stock_adjustment_issue_details($stock_id, $loc_code, $date, ST_INVENTORY_RECEIPT_REQUEST);
            break;

        case ST_REQTRANSFER:
            $result = get_view_material_transfer_requisition_details_not_received($stock_id, $loc_code, $date);
            break;
        
        default:
            $result = null;
    }
    
        return $result;
}

?>