<?php
include("_config/addCfg.php");
include("_includes/addInc.php");


###################################################################################################
## CASHBOOK MANUAL DOCUMENTS MANAGEMENT ###########################################################
###################################################################################################


###################################################################################################
## DEFINE THE CASHBOOK FORM #######################################################################
###################################################################################################

// main form details
$formCashBook = \Engine\Form\General::create();
$formCashBook->addContainer(\Engine\Form\Container\Table::create());
$formCashBook->setStyle('width', 320);
$formCashBook->setStyle('labelWidth', 25);
$formCashBook->setId('cashbookForm');

// office
$fldOffice=new \App\Form\Input\Autocomplete_Office($_LANG['cashBookView']['cashBookFilters']['office'], 'office', CURRENT_ID_OFFICE);
$fldOffice->setMandatory(true);
// if the user can't access all offices
if (!$S['auth']['userOptionsAccess']['cashBookViewAllOffices']) {
	$fldOffice->setDisabled(true);
	$hiddenOffice=new \Engine\Form\Input\Hidden('', 'office', CURRENT_ID_OFFICE);
	$hiddenOffice->setId('officeField');
	$formCashBook->addElement($hiddenOffice);
} else {
	$fldOffice->setId('officeField');
}
$formCashBook->addElement($fldOffice);

// period
$fld=new \Engine\Form\Input\DateInterval($_LANG['cashBookView']['cashBookFilters']['dateInterval'], 'interval', array('start'=>$CFG['cashBook']['cashBookView']['defaultFilters']['dateStart'], 'end'=>$CFG['cashBook']['cashBookView']['defaultFilters']['dateEnd']));
$fld->setMandatory();
$fld->setId(array('start'=>'intervalStart', 'end'=>'intervalEnd'));
$formCashBook->addElement($fld);

// currencies
$fld=new \Engine\Form\Input\Checkboxes($_LANG['cashBookView']['cashBookFilters']['currencies'], 'currencies');
$fld->setMandatory();
$currenciesListAssoc=array_combine(\App\Config\Currencies::getInstance()->getSimple(), \App\Config\Currencies::getInstance()->getSimple());
$fld->setId('currencies');
$fld->setPossibleValues($currenciesListAssoc);
if ($CFG['cashBook']['cashBookView']['defaultFilters']['currencies']=='all') $fld->setValue($currenciesListAssoc);
elseif ($CFG['cashBook']['cashBookView']['defaultFilters']['currencies']=='none') $fld->setValue(array());
elseif (is_array($CFG['cashBook']['cashBookView']['defaultFilters']['currencies'])) $fld->setValue($CFG['cashBook']['cashBookView']['defaultFilters']['currencies']);
$formCashBook->addElement($fld);

// equiv default currency
$fld=new \Engine\Form\Input\Checkbox(sprintf($_LANG['cashBookView']['cashBookFilters']['showEquivDefCurr'], $CFG['currencies']['defaultCurrency']), 'showEquivDefCurr', $CFG['cashBook']['cashBookView']['defaultFilters']['showEquivDefCurr']);
$fld->setId('showEquivDefCurr');
$fld->setTooltip($_LANG['cashBookView']['cashBookFilters']['showEquivDefCurrTooltip']);
$formCashBook->addElement($fld);

// equiv work currency
$fld=new \Engine\Form\Input\Checkbox(sprintf($_LANG['cashBookView']['cashBookFilters']['showEquivWorkCurr'], $CFG['currencies']['workCurrency']), 'showEquivWorkCurr', $CFG['cashBook']['cashBookView']['defaultFilters']['showEquivWorkCurr']);
$fld->setId('showEquivWorkCurr');
$fld->setTooltip($_LANG['cashBookView']['cashBookFilters']['showEquivWorkCurrTooltip']);
$formCashBook->addElement($fld);

// currency exchange rate
$fld=new \Engine\Form\Input\Checkbox($_LANG['cashBookView']['cashBookFilters']['showCurrencyExchRate'], 'showExchRate', $CFG['cashBook']['cashBookView']['defaultFilters']['showExchangeRate']);
$fld->setId('showExchRate');
$fld->setTooltip($_LANG['cashBookView']['cashBookFilters']['showCurrencyExchRateTooltip']);
$formCashBook->addElement($fld);



###################################################################################################
###################################################################################################
## SMARTY ASSIGNMENTS #############################################################################
###################################################################################################
###################################################################################################

// filters info
$smarty->assign("currencyArray", \App\Config\Currencies::getInstance()->getSimple());
$smarty->assign("documentTypes", $CFG['cashBook']['documentTypes']);
$smarty->assign("formCashBook", $formCashBook);


// cashBookView info
$smarty->assign("cashBookViewFilters", $cashBookViewFilters);
$smarty->assign("defaultCurrency", $CFG['currencies']['defaultCurrency']);
$smarty->assign("workCurrency", $CFG['currencies']['workCurrency']);
$smarty->assign("enableEquivalentWork", $CFG['cashBook']['cashBookView']['defaultFilters']['enableEquivalentWork']);

// order by / order direction
$smarty->assign('orderBy', $S['cashBook']['listing']['orderBy']);
$smarty->assign('orderDirection', $S['cashBook']['listing']['orderDirection']);

// pages
$smarty->assign("pages",
	array(
		'currentPage'=>		$S['cashBook']['listing']['currentPage'],
		'countResults'=>	$countResults,
		'resultsPerPage'=>	$S['cashBook']['listing']['resultsPerPage'],
		'resultsPerPageSelector'=>$CFG['cashBook']['listing']['resultsPerPageSelector'],
	)
);
$smarty->assign("filterBehaviour", array(
	'floating'=>$filtersFloating,
	'animate'=>$CFG['cashBook']['filterBehaviour']['animate'],
	'collapsed'=>$filtersCollapsed
));


//page and titles
$smarty->assign("headerPageTitle", $_LANG['cashBook']['title_header']);
$smarty->assign("pageTitle", $_LANG['cashBook']['title_page']);

// ---------------------------------------------------------------------------------------------------
$smarty->display("index.tpl");

