<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_BILLING_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_billing_inquiry_db.inc");
//include_once($path_to_root . "/gl/includes/db/approve_i_owe_you_enties_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 Invoices Inquiry", false, false, "", $js);
//---------------------------------------------------------------------------------------------
simple_page_mode(true);

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


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

function ord_date($row)
{
   return sql2date($row['ord_date']);
}

function show_type_name($row)
{
    global  $petty_cash_float_transaction_types;
    
    return $petty_cash_float_transaction_types[$row['tran_type']];
}


function project_description($row)
{
    return $row['project_description'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);
}

function type($row)
{
    global $systypes_array;
    
    return $systypes_array[$row['type']];

}

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

function _due_date($row)
{
    return sql2date($row['due_date']);   
}

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

function terms($row)
{
    return $row['terms'];
    return get_trans_view_str(ST_PETTY_CASH, $iou);     
}


function edit_link($row) 
{
    if (@$_GET['popup'])
            return '';
    global $trans_type;
    $modify = "PINo";
    if($row['approval_status'] == AS_NEW || $row['approval_status'] == AS_WITH_THE_APPROVER || $row['approval_status'] == AS_AWAITING_APPROVAL)
    {
//        if($row['type'] == ST_PROJECT_INVOICE){
            $file_name = "manual_project_invoice.php";
//        }
//        elseif($row['type'] == ST_PROJECT_CREDIT_NOTE){
//            $file_name = "project_credit_notes.php";
//        }
//        else{
//            return null;
//        }
        return pager_link( _("Edit"), "/projects/".$file_name."?$modify=" . $row['order_no'], ICON_EDIT);
    }
    else
    {
        return null;
    }    
}


function _status($row)
{
    global $approval_statuses;
    
    return $approval_statuses[$row['approval_status']];
     		
}
//--------------------------------------------------------------------------------------------------

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');
//--------------------------------------------------------------------------------------------------

	start_form();
//start_table();
//    start_row();
//        project_list_cells(_("Project:"), 'project_id', null, _('Select a project'), true);
//        date_cells(_("from:"), 'from_date', '', null, -30);
//        date_cells(_("to:"), 'to_date');
//       // petty_cash_floats_list_cells("Float", "float_id", null, "All floats");
//        
//        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
//
//    end_row();
//end_table(1);

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

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

$customer_id = "";
if(isset($_POST['customer_id'])){
  $customer_id = $_POST['customer_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'];
}

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

$current_user_id = $_SESSION['wa_current_user']->user;

$sql = get_sql_for_approve_project_billing_inquiry($current_user_id);    

$cols = array(
            _("Id")=> array('fun'=>'view_link','align'=>'center'),
            _("Reference"),
            _("Order Date")=>array('fun'=>'ord_date','align'=>'center'),
            _("Project")=> array('fun'=>'project_description','align'=>'left'),
            _("Customer")=>array('fun'=>'name','align'=>'left'),           
            _("Due Date")=>array('fun'=>'_due_date','align'=>'center')           
        );

        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('orders_tbl', $sql, $cols, null, null);

$table->width = "80%";

display_db_pager($table);

br();


end_form();
end_page();


?>
