<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PETTY_CASH_EXPENSES_APPROVE';
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 . "/petty_cash/includes/db/i_owe_you_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/i_owe_you_expenses_db.inc");
include_once($path_to_root . "/petty_cash/includes/db/petty_cash_floats_db.inc");

include_once($path_to_root . "/includes/db/group_companies_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();
}

simple_page_mode(true);

page(_($help_context = "Approve I Owe You Expenses"), false, false, "", $js);


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



function build_iou_array(&$ious, $from_date_, $to_date_)
{
    $from_date = date2sql($from_date_);
    $to_date = date2sql($to_date_);
    
    $result = get_i_owe_you_expence_batches_for_approval($from_date, $to_date);
    while ($myrow = db_fetch($result))
    {
        $a = array(
                "id" => $myrow["id"],
                "project_id" => $myrow["project_id"],
                "project_description" => $myrow["project_description"],
                "float_id" => $myrow["float_id"],
                "float_name" => $myrow["float_name"],
                "employee_code" => $myrow["employee_code"],
                "company_code" => $myrow["company_code"],
                "type_name" => $myrow["type_name"],
                "tran_date" => $myrow["tran_date"],
                "amount" => $myrow["amount"],
                "comments" => $myrow["comments"],
                "batch_no" => $myrow["batch_no"]);

        $ious[] = $a;
    }
//    $result = get_i_owe_yous_for_expenses_entry(true);
//    while ($myrow = db_fetch($result))
//    {
//        $a = array(
//                "id" => $myrow["id"],
//                "project_id" => $myrow["project_id"],
//                "project_description" => $myrow["project_description"],
//                "float_id" => $myrow["float_id"],
//                "float_name" => $myrow["float_name"],
//                "employee" => $myrow["employee"],
//                "type_name" => $myrow["type_name"],
//                "tran_date" => $myrow["tran_date"],
//                "amount" => $myrow["amount"],
//                "comments" => $myrow["comments"],
//                "batch_no" => $myrow["batch_no"]);
//
//        $ious[] = $a;
//    }

}

//if (isset($_POST['UpdateData'])){
//    mark_selected_i_owe_yous($path_to_root);
//}

start_form();

br();

start_table(TABLESTYLE_NOBORDER, "width=40%");
    start_row();
        date_cells(_("From Date:"), 'from_date', '', null, -60);
        date_cells(_("To Date:"), 'to_date', '', null, +1);
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
    end_row();
end_table(2);




$Ajax->activate('leaves');

div_start('leaves');

start_table(TABLESTYLE, "width=90%");

$th = array("Batch No", _("Type"), _("Id"),"Project", _("Employee Name"), "Float", 
            _("Date"),_("Amount"), "Comment", "");
table_header($th);

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



$approval_statuses_in = AS_NEW;

$ious = array();
build_iou_array($ious, $_POST["from_date"], $_POST["to_date"]);

foreach ($ious as $iou_line) {
	alt_table_row_color($k);

    $batch_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU_BATCH, $iou_line["batch_no"]);
    label_cells('',$batch_link,'', "align=center");
    label_cells('',$iou_line["type_name"]);
    //label_cells('',$myrow["id"]);
    label_cells('',get_petty_cash_trans_view_str(ST_I_OWE_YOU, $iou_line["id"]));
    label_cells('',$iou_line["project_description"]);
    label_cells('',get_group_company_employee_formatted_long_name($iou_line["company_code"], $iou_line["employee_code"]));
    label_cells('',$iou_line["float_name"]);
    
    label_cells('',sql2date($iou_line["tran_date"]));
    qty_cell($iou_line["amount"], false, 2);

    label_cells('',$iou_line["comments"]);
        
        

//        check_cells('', 'selected_'.$iou_line["id"],0);
        $url = "<a href='$path_to_root/petty_cash/approve_i_owe_you_expenses.php?BatchNo=".$iou_line["batch_no"]."'>" . "Approve" . "</a>";

		label_cell($url);
	end_row();
	$j++;
	If ($j == 12)
	{
		$j = 1;
		table_header($th);
	}
}

end_table(1);
div_end();
//submit_center('UpdateData', _("Select"), true, false, 'default');

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