<?php

/* ======================================================\
  |                      CHurch                           |
  |-------------------------------------------------------|
  \====================================================== */

$page_security = 'SA_MMBRTR';
$path_to_root = '../../..';
include($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
add_access_extensions();

$js = "";
if ($SysPrefs->use_popup_windows)
    $js .= get_js_open_window(700, 300);
if (user_use_date_picker())
    $js .= get_js_date_picker();

include_once($path_to_root . "/modules/church/includes/entity/contribution.php");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/banking.inc");
include_once($path_to_root . "/modules/church/includes/church_db.inc");
include_once($path_to_root . "/modules/church/includes/church_ui.inc");
include_once($path_to_root . '/modules/kanban/includes/kanban_db.inc');
include_once($path_to_root . '/modules/kanban/includes/kanban_ui.inc');

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

function target_link($row) {
    return get_gl_view_str($row['type'], $row['id'], _($row['id']));
}

function edit_link($row) {
    return viewer_link('', 'modules/church/manage/addcontributions.php?id=' . $row['id'], '', '', ICON_EDIT);
}
function systype_name($dummy, $type)
{
	global $systypes_array;

	return $systypes_array[$type];
}
function amount_format($row) {
    return price_format($row['amount']);
}

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



page(_($help_context = "Member Transactions"), false, false, "", $js);
start_form();

start_table(TABLESTYLE_NOBORDER);
start_row();

member_list_cells(_('Member'), 'per_ID', get_post('per_ID'),  _('Select Member'), TRUE);
bank_accounts_list_cells(_("Into Bank Account:"), 'bank_account', get_post('bank_account'), TRUE,_('Select Bank'));
projects_list_cells(_('Project'), 'project_id', get_post('project_id'), _("Select Project"));
date_cells(_("Start Date :"), 'start_date', '', true, 0, 0, 0, null, FALSE);
date_cells(_("End Date :"), 'end_date', '', true, 0, 0, 0, null, FALSE);
submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
end_row();
end_table();

if (get_post('RefreshInquiry') || list_updated('filterType'))
{
	$Ajax->activate('_page_body');
}
$sql = get_member_contributions(0, get_post('per_ID'), FALSE, get_post('type'), get_post('bank_account'), get_post('start_date'), get_post('end_date'),get_post('project_id'));

$cols = array(
    _('Type') => array('fun' => 'systype_name'),
    _('#') => array('align' => 'center', 'fun' => 'target_link'),
    _('Ref'),
    _('Member'),
    _('Project'),
    _('Date') => array('type' => 'date'),
    _('Bank'),
    _('Amount') => array('fun'=>'amount_format', 'align'=>'right'),
    _('Edit') => array('fun' => 'edit_link', 'align' => 'center')
);

$table = new_db_pager('projects_tbl', $sql, $cols);
$table->width = "80%";
        $table->page_len = 25;
display_note(_('Press id to go to project details.'));
display_db_pager($table);

end_form();


end_page();
