<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_SALELAUNRYORDERS';
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 . "/sales/includes/db/pos_invoices_db.inc");

$js = '';

if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}


if (!@$_GET['popup'])
	page(_($help_context = "Laundry Orders"), @$_GET['popup'], false, "", $js);

//----------------------------------------------------------------------------------------
simple_page_mode(true);
if (isset($_GET['employee_code']))
{
	$_POST['employee_code'] = $_GET['employee_code'];
}

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

function update_laundry_order_status($myrow)
{
    $temp_name = 'laundry_order_status'.$myrow["id"];
    
    if(isset($_POST['laundry_order_status'.$myrow["id"]])){ 
        if($_POST[$temp_name] != $myrow["status"])
        {
            update_pos_invoice_status($myrow["id"], $_POST[$temp_name]);
        }
    }
}
//--------------------------------------------------------------------------------------------------


function clear_data()
{
	unset($_POST['long_description']);
}

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

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

//--------------------------------------------------------------------------------------------------
function initialize_values()
{
        $_POST['id'] = "";
        $_POST['date'] = "";
        $_POST['work_time_name'] = "";
        $_POST['date'] = "";
        $_POST['work_time_name'] = "";
        $_POST['from_date_time'] = "";
        $_POST['to_date_time'] = "";
        $_POST['duration'] = "";
        $_POST['comment'] = "";
        $_POST['leave_status_name'] = "";
        $_POST['real_name'] = "";
        $_POST['created_on'] = "";
        
        $_POST['rec_type'] = "";
        
}

function display_laundry_orders($result,$employee_code)
{
    if (db_num_rows($result) == 0)
    {
        display_note(_("There is orders available for the selected criteria"));
    }
    else
    {
        start_table(TABLESTYLE, "width=65%");

                $th = array(_("#"),_("Reference"),_("Date"),_("Terminal Id"), _("Location"), 
                            _("POS User"),_("Updated By"), _("Updated On"), "Status");

        table_header($th);
        $last_header_date ="";

        $k = $j = 0; //row colour counter
        $_POST['last_leave_date'] = "";
        $rec_count = $hour_count = 0;

        while ($myrow = db_fetch($result))
        {
            alt_table_row_color($k);

            initialize_values();

            $_POST['id'] = $myrow["id"];
            
            if (isset($_POST['UpdateData'])){
                update_laundry_order_status($myrow);
            }
            
            $_POST['status'] = $myrow['status'];

            //label_cell($myrow['id']);
            label_cell(get_trans_view_str(ST_SALESINVOICE, $myrow["debtor_tran_no"]));
            label_cell($myrow['reference']);
            label_cell(sql2date($myrow['tran_date']));
            label_cell($myrow['terminal_id']);
            label_cell($myrow['location_name']);
            label_cell($myrow['pos_user_id']);
            //label_cell($_POST['status']);
            label_cell($myrow['real_name']);
            label_cell($myrow['updated_on']);
            
            if(isset($_POST['laundry_order_status'.$myrow["id"]])){
                $status = $_POST['laundry_order_status'.$myrow["id"]];
            }
            else{
                $status =$myrow['status'];
            }
    
            if($status == 'D'){
                label_cells(null, "Delivered");
            }
            else{
                value_list_code_cells(null, 'laundry_order_status'.$myrow["id"], "LAUNDRY_ORDER_STATUS", $status);  
            }
            

            end_row();
            
        }
        //end of while loop

        end_table();
    }
    
    if (isset($_POST['UpdateData'])){
        display_notification("Status of selected laundry orders updated");
    }
}



if ($Mode == 'RESET')
{
	$selected_id = -1;
}

//if (list_updated('employee_code')) 
//	$Ajax->activate('Entitlements');
//--------------------------------------------------------------------------------------------------

if (!@$_GET['popup'])
	start_form();



date_cells(_("From:"), 'from_date', '', null, -7);
date_cells(_("To:"), 'to_date');

locations_list_cells(_("Location:"), 'filter_Location', null, "");

value_list_code_cells("Status:", "filter_status", "LAUNDRY_ORDER_STATUS",null, "");

submit_cells('ShowOrders',_("Show Laundry Orders"),'',_('Refresh Inquiry'), 'default');

br(2);

$Ajax->activate('attendance');


$result = get_pos_invoices(2, $_POST['from_date'], $_POST['to_date'], $_POST['filter_Location'], $_POST['filter_status']);

div_start('attendance');

display_laundry_orders($result,"");

br();

div_end();

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

hidden('selected_id', $selected_id);

end_table(1);
div_end();

submit_center('UpdateData', _("Update"), true, false, 'default');

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