<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_FI_INQ';
$path_to_root="../..";

include($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 . "/gl/includes/db/financial_integration_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 = "Financial Integration Inquiry"), false, false, "", $js);

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

if (get_post('Search'))
{
    $Ajax->activate('financial_integration_tbl');
}

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

if (!isset($_POST['filterType']))
	$_POST['filterType'] = -1;

start_form();

start_table(TABLESTYLE_NOBORDER);
start_row();

ref_cells(_("Batch No:"), 'batch_no', '',null, _('Enter memo fragment or leave empty'));
journal_types_list_cells(_("Type:"), "filterType");
date_cells(_("From:"), 'FromDate', '', null, 0, -1, 0);
date_cells(_("To:"), 'ToDate');



submit_cells('Search', _("Search"), '', '', 'default');


//gl_all_accounts_list_cells(_("Account:"), 'account_no', null, false, false, 'Select an Account');
end_row();

end_table();

function batch_no($row)
{
    return get_journal_trans_view_str(ST_FI_BATCH, $row['batch_no']);
}

function amount($row)
{
    return number_format($row['amount'],2); 
}

function account($row)
{
    return $row['account_code']." - ".$row['account_name']; 
}

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

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

function view_link($row) 
{
    return get_trans_view_str($row["type"], $row["type_no"]);
}

function fi_link($row) 
{
    return get_fi_view_str($row["type"], $row["type_no"]);
}

$editors = array(
	ST_JOURNAL => "/gl/gl_journal.php?ModifyGL=Yes&trans_no=%d&trans_type=%d",
	ST_BANKPAYMENT => "/gl/gl_bank.php?ModifyPayment=Yes&trans_no=%d&trans_type=%d",
	ST_BANKDEPOSIT => "/gl/gl_bank.php?ModifyDeposit=Yes&trans_no=%d&trans_type=%d",
//	4=> Funds Transfer,
   ST_SALESINVOICE => "/sales/customer_invoice.php?ModifyInvoice=%d",
//   11=>
// free hand (debtors_trans.order_==0)
//	"/sales/credit_note_entry.php?ModifyCredit=%d"
// credit invoice
//	"/sales/customer_credit_invoice.php?ModifyCredit=%d"
//	 12=> Customer Payment,
   ST_CUSTDELIVERY => "/sales/customer_delivery.php?ModifyDelivery=%d",
//   16=> Location Transfer,
//   17=> Inventory Adjustment,
//   20=> Supplier Invoice,
//   21=> Supplier Credit Note,
//   22=> Supplier Payment,
//   25=> Purchase Order Delivery,
//   28=> Work Order Issue,
//   29=> Work Order Production",
//   35=> Cost Update,

//    ST_POINTSUPDATE => "/sales/customer_invoice.php?ModifyInvoice=%d",
);



$sql = get_sql_for_financial_integration_inquiry(get_post('filterType', -1), get_post('batch_no'), 
                                                get_post('FromDate'), get_post('ToDate'));

$cols = array(
 
        _("Batch No") => array('fun'=>'batch_no', 'align'=>'center'), 
        _("Date") =>array('fun'=>'tran_date', 'align'=>'center'),
    	_("Type") => array('fun'=>'systype_name'), 
        _("Trans #") => array('fun'=>'view_link', 'align'=>'center'), 
		        	
//        _("Account") => array('fun'=>'account'), 
	_("Accounts Total") => array('fun'=>'amount','align'=>'right'),    

	_("View") => array('insert'=>true, 'fun'=>'fi_link', 'align'=>'center'),

);



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

$table->width = "60%";

display_db_pager($table);

end_form();
end_page();



?>
