<?php
namespace ModulesAbstract\PluginReports\Report\Model\Builder\Helpers;


class BuilderHelper
{
	/**
	 * @param \Entity\Invoice $invoiceEntity
	 * @param \Entity\Service $serviceEntity
	 * @return Array
	 */
	public function getExportConfigs(\Entity\Invoice $invoiceEntity, \Entity\Service $serviceEntity, $component = 'price')
	{
		$rowComponents = [];
		$rowComponents['rowType'] = $component;
		$rowComponents['clientType'] = ($invoiceEntity->idCorporate ? 'legalEntity' : 'individual');
		$rowComponents['currency'] = $invoiceEntity->currency;
		$rowComponents['serviceCode'] = $serviceEntity->serviceCode;
		$rowComponents['location'] = $serviceEntity->chosenOffer->location;
		$rowComponents['calculationType'] = $serviceEntity->offerCalculationType;

		return \App\Config\ExportData_Fields_ClientInvoice::getInstance()->getActiveFieldsValues($rowComponents);
	}


	/**
	 *
	 * @param \Entity\Invoice $invoiceEntity
	 * @param \Entity\Service $serviceEntity
	 * @param array $components
	 * @param array $operations
	 * @return array
	 */
	public function getRowVatPercent(\Entity\Invoice $invoiceEntity, \Entity\Service $serviceEntity, array $components, $operations = ['sale', 'refund', 'storno'])
	{
		$return = [];
		// search vat percent for current service and row type (price, service fee)
		foreach ($invoiceEntity->rowsList as $invoiceRow) {
			$op = '';
			if ($invoiceRow['special'] == 'REFUND') {
				$op = 'refund';
			}
			elseif ((bool)$invoiceRow['reversesInvoiceRowId']) {
				$op = 'storno';
			}
			else {
				$op = 'sale';
			}

			if ($invoiceRow['idReservationService'] == $serviceEntity->getId() && in_array($invoiceRow['rowType'], $components) && in_array($op, $operations)) {
				$return[$invoiceRow['rowType']] = $invoiceRow['vatPercent'];
			}
		}

		return $return;
	}

}