<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/

$page_security = 'SA_GLANALYTIC';
$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/ui.inc");
include_once($path_to_root . "/gl/includes/db/print_cheques_db.inc"); 

$js = "";
$js .= get_js_open_window(800, 500);
$js .= get_js_date_picker();


page(_($help_context = "Cheque Printing Log Inquiry"), false, false, "", $js);

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

$values_array[ST_BANKPAYMENT] = $systypes_array[ST_BANKPAYMENT];
$values_array[ST_BANKTRANSFER] = $systypes_array[ST_BANKTRANSFER];
$values_array[ST_SUPPAYMENT] = $systypes_array[ST_SUPPAYMENT];

start_form();
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            ref_cells(_("Trans #:"), 'trans_no', null, null, null, true);
            custom_values_list_cells(_("Type:"), "type", $values_array, null, '', true);
            date_cells(_("From:"), 'from_date', '', null, -14, 0, 0, null, true);
            date_cells(_("To:"), 'to_date', '', null, 0, 0, 0, null, true);
            bank_accounts_list_cells(_("Account:"), 'bank_account', null, true, '');
            system_users_list_cells('User:', 'user_id', null, '', true);
            submit_cells('Search', _("Search"), '', '', 'default');
        end_row();
    end_table(1);

    function _id($row) {
        return $row['id'];
    }

    function _systype_name($row) {
        global $systypes_array;
        return $systypes_array[$row["type"]];
    }

    function _trans_view($row) {
        return get_trans_view_str($row["type"], $row["trans_no"]);
    }
    
    function _bank_account($row) {
        return $row["bank_account_number"];
    }
    
    function _account_name($row) {
        return $row["account_name"];
    }
    
    function _crossing($row) {
        return $row["crossing_name"];
    }
    
    function _payment_type($row) {
        return $row["payment_type"] == 1 ? 'Online' : 'Cheque';
    }
    
    function _amount($row) {
        return number_format($row['amount'],2);
    }
    
    function _tran_date($row) {
        return sql2date($row['cheque_date']);
    }
    
    function _cheque_no($row) {
        return $row['cheque_no'];
    }
    
    function _manual($row) {
        return $row['manual'] == 1 ? 'Yes' : 'No';
    }
    
    function _user($row) {
        return $row['real_name'];
    }
    
    function _printed_on($row) {
        return $row['created_on'];
    }


    $sql = get_sql_for_cheque_printing_log_inquiry($_POST['trans_no'], $_POST['type'], $_POST['from_date'], $_POST['to_date'], $_POST['bank_account'], 
                                                   $_POST['user_id']);
    
    $cols = array(_("Id") => array('fun'=>'_id', 'align'=>'center'),                     
                  _("Type") => array('fun'=>'_systype_name'),                     
                  _("Trans #") => array('fun'=>'_trans_view', 'align'=>'center'), 
                  _("Bank Account") => array('fun' => '_bank_account'),
                  _("Account Name") =>array('fun'=>'_account_name'), 
                  _("Crossing") =>array('fun'=>'_crossing'), 
                  _("Payment Type") =>array('fun'=>'_payment_type','align'=>'center'), 
                  _("Cheque / Transaction Date") =>array('fun'=>'_tran_date','align'=>'center'), 
                  _("Cheque / Transaction No") =>array('fun'=>'_cheque_no'), 
                  _("Counterparty") => array('fun' => '_manual', 'align'=>'center'),
                  _("User") => array('fun' => '_user'), 
                  _("Printed On") => array('insert'=>true, 'fun'=>'_printed_on', 'align'=>'center'));
        

    $table =& new_db_pager('cheque_printing_tbl', $sql, $cols);
    $table->width = "98%";

    display_db_pager($table);

end_form();
end_page(2);