<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_CONFIRM_PRODUCTION_SCHEDULE';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/manufacturing/includes/db/confirm_production_schedule_db.inc");
include_once($path_to_root . "/manufacturing/includes/db/generate_production_schedule_db.inc");
include_once($path_to_root . "/manufacturing/includes/db/manufacturing_requirements_db.inc");
include_once($path_to_root . "/manufacturing/includes/confirm_production_schedule.inc");
include_once($path_to_root . "/requisitions/includes/pr_validations.inc");

simple_page_mode(true);

page(_($help_context = "Confirm Production Schedule"));

//------------------------------------------------------------------------------------



function display_production_schedule_details($ps_id, $order_type)
{
    global $systypes_array;
    
    start_table(TABLESTYLE, "width=80%");

    $th = array(_("Source Type"),_("Source No"), _("Item"), _("Item Description"),
                _("Odr. Type"),_("Odr. No"), _("Location"), _("Unit"), _("Qty"),
                _("Required By"), _("Comment"), "Select");
    table_header($th);

    $j = 1;
    $k=0; //row colour counter


//    if (isset($_POST['ConfirmSelected'])){
//        confirm_selected_records($ps_id);
//    }


    $result = get_production_schedule_details($ps_id, $order_type);

    while ($myrow = db_fetch($result))
    {

        alt_table_row_color($k);

            //label_cells('',$myrow["id"]);
            label_cell($systypes_array[$myrow["source_type"]]);
            label_cell($myrow["source_id"], "align=right");
            label_cell($myrow["stock_id"]);
            label_cell($myrow["item_description"]);
            label_cell($systypes_array[$myrow["tran_type"]]);
            
            if($myrow["trans_no"] == 0){
                if($myrow["scheduled_trans_no"] == -99){
                    label_cell("ERROR");
                }
                elseif($myrow["scheduled_trans_no"] != 0){
                    label_cell($myrow["scheduled_trans_no"], "align=right");
                }
                else{
                    label_cell('');
                }
            }
            else{
                label_cell($myrow["trans_no"], "align=right");
            }
            
            if($myrow["scheduled_trans_no"] == -99){
                label_cell($myrow["comment"], "colspan=6");
            }
            else{
                label_cell($myrow["location_name"]);
                label_cell($myrow["tran_unit_name"]);
                label_cell($myrow["tran_qty"], "align=right");
                label_cell(sql2date($myrow["required_by"]), "align=center");
                label_cell($myrow["comment"]);
                //value_list_code_cells(null, 'leave_approval_status'.$myrow["id"], "LEAVE_STATUS", null);
                if(($myrow["source_type"] == ST_MANUF_REQUIREMENT && $myrow["trans_no"] == 0) || 
                        //($myrow["source_type"] == ST_WORKORDER && $myrow["source_id"] > 0 && $myrow["trans_no"] == 0)){
                        ($myrow["tran_type"] == ST_WORKORDER && $myrow["source_id"] > 0 && $myrow["trans_no"] == 0)){
                    check_cells('', 'selected_'.$myrow["id"],0);
                }
                else{
                    label_cell('');
                }
            }
            hidden("row_state_".$myrow["id"], $myrow["row_state"]);

        end_row();
        $j++;
        If ($j == 25)
        {
            $j = 1;
            table_header($th);
        }
    }

    end_table(1);
}

if (isset($_POST['ConfirmSelected'])){
      confirm_selected_records($_POST['production_schedule_id']);
}
    
    
    
start_form();


br();


$Ajax->activate('leaves');

div_start('leaves');


production_schedule_list_row("Production Schedule:", "production_schedule_id", null, '',true);

br(2);

display_heading("Workorders");
display_production_schedule_details($_POST['production_schedule_id'], ST_WORKORDER);

br();
display_heading("Expected Material Requirements");
display_production_schedule_details($_POST['production_schedule_id'], ST_PURCH_REQ);

div_end();
//submit_center('UpdateData', _("Update"), true, false, 'default');
submit_center('ConfirmSelected', _("Confirm Seletced Records"), true, false, 'default');

if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}
?>
