<?php

///////////////////////////////////////////////////////////////////////////////////////////////////
// IF FILTERS CHANGED - UPDATE THEM INTO SESSION //////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
if ($R['clientInvoicesList']) {

	// all the filters (client) from request
	$reqFilters=$R['client'];

	// invoice date
	$S['balanceInvoices']['client']['invoiceStartDate']=$reqFilters['invoiceStartDate'];
	$S['balanceInvoices']['client']['invoiceEndDate']=$reqFilters['invoiceEndDate'];

	// invoice number
	$S['balanceInvoices']['client']['invoiceNumber']=$reqFilters['invoiceNumber'];

	// invoice responsible
	$S['balanceInvoices']['client']['invoiceIdOfficeUser']=$reqFilters['invoiceIdOfficeUser'];
	$S['balanceInvoices']['client']['typeInvoiceOfficeUserName']=$reqFilters['typeInvoiceOfficeUserName'];

	// res id
	$S['balanceInvoices']['client']['idReservation']=$reqFilters['idReservation'];

	// client type
	$S['balanceInvoices']['client']['clientType']=$reqFilters['clientType'];

	// client id
	$S['balanceInvoices']['client']['idCorporate']=$reqFilters['idCorporate'];
	$S['balanceInvoices']['client']['typeCorporateName']=$reqFilters['typeCorporateName'];
	$S['balanceInvoices']['client']['idCustomer']=$reqFilters['idCustomer'];
	$S['balanceInvoices']['client']['typeCustomerName']=$reqFilters['typeCustomerName'];

	// service code
	$S['balanceInvoices']['client']['serviceCode']=$reqFilters['serviceCode'];

	// invoice due date
	$S['balanceInvoices']['client']['dueStartDate']=$reqFilters['dueStartDate'];
	$S['balanceInvoices']['client']['dueEndDate']=$reqFilters['dueEndDate'];

	// invoice cashedStatus
	$S['balanceInvoices']['client']['cashedStatus']=$reqFilters['cashedStatus'];

	// invoice reversed
	$S['balanceInvoices']['client']['showReversedInvoices']=$reqFilters['showReversedInvoices'];

	// MICE Project
	$S['balanceInvoices']['client']['idMiceProject']=$reqFilters['idMiceProject'];
	$S['balanceInvoices']['client']['typeMiceProjectName']=$reqFilters['typeMiceProjectName'];

	// text filter
	$S['balanceInvoices']['client']['text']=$reqFilters['text'];
}

// make sure that filtersMode is set
if (!$S['balanceInvoices']['client']['mode']) $S['balanceInvoices']['client']['mode']="invoices";


///////////////////////////////////////////////////////////////////////////////////////////////////
// INVOICES LISTING PAGE CONTROLS /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

// CHANGED FROM REQUEST ///////////////////////////////////////////////////////////////////////////
// current page changed
if (isset($R['currentPage']))
	$S['balanceInvoices']['client']['currentPage']=$R['currentPage'];
// results per page changed
if ( $R['resultsPerPage'] and in_array($R['resultsPerPage'], $CFG['balanceInvoices']['listing']['client']['resultsPerPageSelector'])!==false ) {
	if ($S['balanceInvoices']['client']['resultsPerPage']!=$R['resultsPerPage']) { // if rpp changed
		\DB::startTransaction();
		\App\EntityPreference\User::getInstance()->blnClInvListRpp=$R['resultsPerPage'];
		\DB::commitTransaction();
		$S['balanceInvoices']['client']['resultsPerPage']=$R['resultsPerPage'];
		$S['balanceInvoices']['client']['currentPage']=0;
	}
}


// IF SESSION LISTING STUFF NOT SET (GET DEFAULTS FROM CFG) /////////////////////////////////////
// current page
if (!$S['balanceInvoices']['client']['currentPage'] or $S['balanceInvoices']['client']['currentPage']<0)
	$S['balanceInvoices']['client']['currentPage']=0;
// get default rpp
if(!$S['balanceInvoices']['client']['resultsPerPage']) {
	$userPref=\App\EntityPreference\User::getInstance()->blnClInvListRpp;
	if (!$userPref)
		$S['balanceInvoices']['client']['resultsPerPage']=$CFG['balanceInvoices']['listing']['client']['resultsPerPageDefault'];
	else
		$S['balanceInvoices']['client']['resultsPerPage']=$userPref;
}


?>