<?php

namespace Modules\Admin\Config\InvoiceCashings\DocsList;

/**
 * Model class for listing cashing documents.
 */
class Model extends \App\Mvc\Model_ListingAbstract
{

	public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams)
	{

		$filters = $listingParams->getFilters();

		$list = [];
		foreach (\App\Config\CashingDocuments::getAdmin()->getAll() as $code => $details) {

			// APPLY FILTERS ----------------------------------------------------------------------
			if (($filters['active']==1 or !$filters['active']) and $details['active']!=$filters['active']) {
				continue;
			}
			if (strlen((string)$filters['text'])) {
				if (mb_stripos($code, $filters['text'])===false and mb_stripos($details['name'], $filters['text'])===false) {
					continue ;
				}
			}

			$details['id'] = $code;
			$list[$code] = $details;

		}

		$startIndex = $listingParams->getResultsPerPage()*$listingParams->getCurrentPage();

		$this->totalRecordsCount = count($list);
		$this->recordsList = array_slice($list, $startIndex, $listingParams->getResultsPerPage());

	}
}