<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_PAY_APP_INQ';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$path_to_root = "..";
include_once($path_to_root . "/includes/db_pager.inc");
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/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/projects/includes/db/project_payment_application_inquiry_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();
}


page(_($help_context = "Project Payment Application Inquiry"), false, false, "", $js);
//---------------------------------------------------------------------------------------------
simple_page_mode(true);

if (isset($_GET['BOQGroupId']))
{
    $_POST['BOQGroupId'] = $_GET['BOQGroupId'];
}


function description($row)
{
    return $row['description'];
    return get_trans_view_str(ST_PETTY_CASH);     
}

function department_id($row)
{
    return $row['department_id'];
    return get_trans_view_str(ST_PETTY_CASH);     
}

function project_manager_name($row)
{
    return $row['project_manager_name'];
    return get_trans_view_str(ST_PETTY_CASH);      
}

function reference($row)
{
    return $row['reference'];
    return get_trans_view_str(ST_PETTY_CASH);     
}

function view_link($row)
{
    return get_project_trans_view_str(ST_PROJECT_PAY_APP_BOQ_GROUPS, $row['order_no']); 
}


function tran_date($row)
{
    return sql2date($row['tran_date']);     
    return get_trans_view_str(ST_PETTY_CASH);     
}

function name($row)
{
    return $row['name'];
    return get_trans_view_str(ST_PETTY_CASH);      
}

function edit_link($row) 
{
    if (@$_GET['popup'])
            return '';
    global $trans_type;
    $modify = "PAId" ;
    
    return pager_link( _("Edit"), "/projects/project_payment_application.php?$modify=".$row['order_no'], ICON_EDIT); 
}

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

if ($Mode == 'Delete')
{
        $recs = delete_i_owe_u($selected_id, $_POST['employee_code']);
        
        if($recs == 1){
                display_notification(_("Salary advance has been deleted."));
        }
        else{
                display_error(_("Salary advance could not be deleted."));
        }

	$Mode = 'RESET';
}

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

if (isset($_POST['_selected_id_update']) )
{
	$selected_id = $_POST['selected_id'];
	//$Ajax->activate('_page_body');
}

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

if (!@$_GET['popup'])
	start_form();
start_table(TABLESTYLE_NOBORDER);
    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('Select a project'), true);
//        value_list_cells(_("Department:"), 'department_id', 'DEPARTMENTS', null,"Select a Department"); 
//        customer_list_cells("Customer:", 'customer_id',null,'Select a Customer');
//    end_row();
      // user_list_cells(_("Project Manager:"), 'project_manager_name', null, false, true);
       // text_row("Reference:", 'reference', null, null, null);
        date_cells("From Date:", "from_date", '', null, -30);
        date_cells("To Date:", "to_date", '', null, +1);
        
        submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
   // end_row();
end_table(1);

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

$project_id = "";
if(isset($_POST['project_id'])){
  $project_id = $_POST['project_id'];
}



$from_date = "";
if(isset($_POST['from_date'])){
  $from_date = $_POST['from_date'];
}

$to_date = "";
if(isset($_POST['to_date'])){
  $to_date = $_POST['to_date'];
}

    $sql = get_sql_for_project_payment_application_inquiry($project_id, $from_date, $to_date);    
    
    $cols = array(
                _("PA No")=> array('fun'=>'view_link', 'align'=>'center'),
                _("Reference")=>array('fun'=>'reference'), 
                _("Department")=>array('fun'=>'department_id','align'=>'center'),
                _("Project")=> array('fun'=>'description'),                
                _("Customer")=>array('fun'=>'name','align'=>'center'),              
                _("Project Manager")=>array('fun'=>'project_manager_name','align'=>'left'),               
                _("Date")=>array('fun'=>'tran_date','align'=>'left'),  
                _("Edit")=>array('fun'=>'edit_link','align'=>'left') ,        
              
);
//    array_append($cols, array(
//		//array('insert'=>true, 'fun'=>'dispatch_link'),
//		array('insert'=>true, 'fun'=>'edit_link')));

//------------------------------------------------------------------------------------------------      
//if (get_post('StockLocation') != $all_items) {
//	$cols[_("Location")] = 'skip';
//}
//---------------------------------------------------------------------------------------------------

$table =& new_db_pager('order_sql', $sql, $cols, null, null);

$table->width = "80%";

display_db_pager($table);

br();

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


?>
