<?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");

simple_page_mode(true);

page(_($help_context = "Select Petty Cash Payments for Float Reimbursement"));

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



function build_iou_array(&$ious)
{
    $result = get_i_owe_you_expence_batches_for_approval();
    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();


$Ajax->activate('leaves');

div_start('leaves');

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

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

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



$approval_statuses_in = AS_NEW;

$ious = array();
build_iou_array($ious);

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

        //label_cells('',$myrow["id"]);
        label_cells('',$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('',$iou_line["type_name"]);
        label_cells('',sql2date($iou_line["tran_date"]));
        qty_cell($iou_line["amount"], false, 2);

        label_cells('',$iou_line["comments"]);
        label_cells('',$iou_line["batch_no"],'', "align=center");

//        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);
}
?>
