<table id="invoiceRowsTable" class="invoiceRowsTable">

	<tr class="tableHead">
			<th class="nowrap center" width="1%">#</th>
			<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['service']}</th>
			{if $invoiceObj->cumulativeInvoice}
				<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['temporaryInvoice']}</th>
			{/if}
			<th>{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['description']}</th>
			<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['exchangeCource']}</th>
			<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['VATType']}</th>
			<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['measureUnit']}</th>
			<th class="nowrap center" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['quantity']}</th>
			<th class="nowrap right" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['unitPriceValue']}</th>
			<th class="nowrap right" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['priceValue']}</th>
			<th class="nowrap right" width="1%">{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['VATValue']}</th>
			<th class="nowrap right" width="1%" >{$_LANG['Invoices']['InvoiceView']['index']['fields']['tableHead']['totalValue']}</th>
	</tr>

	{foreach from=$invoiceRows item=invoiceRow key=idInvoiceRow}

		{$currencyTypeName = $currTypesNames[{$invoiceRow['currencyType']}]}

		{** get service object **}
		{if $invoiceRow['idReservationService']}
			{$servDet = \Entity\Service::select($invoiceRow['idReservationService'])}
		{/if}

		{** if invoice not issued, not temporary and service not reversal/reversed, rowType is price/commission) - check offer expiration **}
		{if !$invoiceObj->issueTime and !$invoiceObj->temporary and $invoiceRow['idReservationService'] and ($invoiceRow['rowType']=="price" or $invoiceRow['rowType']=="commission") and !$invoiceRow['reversedRow'] and !$invoiceRow['reversesInvoiceRowId'] and !$invoiceObj->voidTime}
			{$expirationDate = $servDet->chosenOffer->expirationDate}
		{/if}

		{** check if service has been balanced **}
		{if $invoiceRow['special']}
			{$idBalance = $servDet->idBalanceRefund}
		{else}
			{$idBalance = $servDet->idBalance}
		{/if}

		<tr id="invoiceRowTr_{$idInvoiceRow}"
			{if $idBalance>0}
				class="balancedRow"
			{else}
				{if $invoiceRow.hidden}class="hiddenRow"
				{else}class="normalRow"{/if}
			{/if}


		>
				<td width="1%" class="nowrap center">
					{counter name="invoiceRows"}.
				</td>
				<td class="left">
					{if $invoiceRow.idReservationService}
						<div>{serviceLabel ref=$invoiceRow.idReservationService}</div>
					{/if}
					{if $invoiceRow['serviceCode']}
						<div 
							{if $invoiceRow['location']}
								tooltip="{$_LANG['locations']['countriesCriteria']['long'][$invoiceRow['location']]}{if strlen($invoiceRow['calculationType'])} - {\App\Config\Services_Calculations::getInstance()->getServiceLocationCalculationName($invoiceRow['serviceCode'], $invoiceRow['location'], $invoiceRow['calculationType'])}{/if}"
							{/if}
						>
							{if $invoiceRow['serviceCode']}
								{\App\Config\Services_Basic::getInstance()->getServiceName($invoiceRow['serviceCode'])}
							{/if}
						</div>
						
					{/if}
					{if $invoiceRow['rowType']}
						<div style="white-space: nowrap;">[{$_LANG.rowType[$invoiceRow['rowType']]}]</div>
					{/if}
				</td>
				{if $invoiceObj->cumulativeInvoice}
					<td class="left">
						<div>{invoiceLabel ref=$invoiceRow.cumulatesInvoiceId}</div>
					</td>
				{/if}
				<td class="left">
					
					{$invoiceRow.description}
					<div class="rowType">

						{if $idBalance>0}
							<a href="#;" class='balanceLink' tooltip="{$_LANG['Invoices']['InvoiceView']['index']['tooltips']['viewBalance']}"
								onclick="invoiceBalanceView('{$idBalance}');"
							>{$lang['index']['texts']['balanced']}</a>
						{/if}

						{if $invoiceRow.special}<span class="refund">[R]</span>{/if}

						{if $invoiceRow.reversedRow and !$invoiceRow.cumulatedOnInvoiceRowId and !$showHiddenRows}
							<span class="reverseDetails">
								({$_LANG['Invoices']['InvoiceView']['index']['texts']['stornedRow']}
								{if !$invoiceRow.reversedByInvoiceEnt->invoiceNumber} #{$invoiceRow.reversedByInvoiceEnt->getId()}
								{else}{$invoiceRow.reversedByInvoiceEnt->invoiceNumber}{/if}
								/ {$invoiceRow.reversedByInvoiceEnt->invoiceDate|dateTimeFormat})
							</span>
						{/if}
						{if $invoiceRow.reversesInvoiceRowId and !$showHiddenRows}
							<span class="reverseDetails">
								({$_LANG['Invoices']['InvoiceView']['index']['texts']['storningRow']}
								{if !$invoiceRow.reverseInvoiceRowEnt->invoiceNumber} #{$invoiceRow.reverseInvoiceRowEnt->getId()}
								{else}{$invoiceRow.reverseInvoiceRowEnt->invoiceNumber}{/if}
								/ {$invoiceRow.reverseInvoiceRowEnt->invoiceDate|dateTimeFormat})
							</span>
						{/if}

					</div>
					
					{if $expirationDate and $expirationDate<$smarty.const.TODAY_ISO}
						<div class="expirationOffer">
							{$_LANG['Invoices']['InvoiceView']['index']['texts']['offerValabilityUntil']}: {$expirationDate|dateTimeFormat}
						</div>
					{/if}

				</td>
				<td class="center nowrap">
					<div>{$currencyTypeName}</div>
					<div>{$invoiceRow.currencyDate|dateTimeFormat}</div>
					{if $invoiceRow.finalizeAdvanceMode}
						<div class="italic help" tooltip="{$_LANG['Invoices']['InvoiceView']['index']['texts']['finalizeAdvanceModeTooltip']}">
							{if $invoiceRow.finalizeAdvanceMode=="total"}[{$_LANG['Invoices']['InvoiceView']['index']['texts']['finalizeAdvanceMode_total']}]{/if}
							{if $invoiceRow.finalizeAdvanceMode=="rest"}[{$_LANG['Invoices']['InvoiceView']['index']['texts']['finalizeAdvanceMode_rest']}]{/if}
						</div>
					{/if}
				</td>

				<td width="1%" class="nowrap center">
					<div>{$invoiceRow.vatText}</div>
					{if $invoiceRow.vatPercent!=-1}
						<div>[{$invoiceRow.vatPercent}%]</div>
					{/if}
				</td>
				<td class="center">{$invoiceRow.measureUnit}</td>
				<td class="center priceCell">{$invoiceRow.quantity}</td>
				<td class="nowrap right priceCell">{$invoiceRow.unitPricePrintValue|priceFormat:$invoiceObj->currency:1}</td>
				<td class="nowrap right priceCell">{$invoiceRow.pricePrintValue|priceFormat:$invoiceObj->currency:1}</td>
				<td class="nowrap right priceCell">{$invoiceRow.vatPrintValue|priceFormat:$invoiceObj->currency:1}</td>
				<td class="nowrap right priceCell priceCellTotalBack bold">{($invoiceRow.pricePrintValue+$invoiceRow.vatPrintValue)|priceFormat:$invoiceObj->currency}</td>
		</tr>
	{/foreach}

	{* TOTAL SERVICE *}

	<tr>
			<td>&nbsp;</td>
			{if $invoiceObj->cumulativeInvoice}
				<td>&nbsp;</td>
			{/if}
			<td>&nbsp;</td>
			<td>&nbsp;</th>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td class="nowrap right bold priceCell">
				{if $invoicePrice<0}<span class="negativeSum">{$invoicePrice|priceFormat:$invoiceObj->currency:1}</span>
				{else}{$invoicePrice|priceFormat:$invoiceObj->currency:1}{/if}
			</td>
			<td class="nowrap right bold priceCell">
				{if $invoiceVat<0}<span class="negativeSum">{$invoiceVat|priceFormat:$invoiceObj->currency:1}</span>
				{else}{$invoiceVat|priceFormat:$invoiceObj->currency:1}{/if}
			</td>
			<td class="nowrap right bold priceCellTotal priceCellTotalBack">
				<div {if $invoiceTotal<0}class="negativeSum"{/if}>
					{$invoiceTotal|priceFormat:$invoiceObj->currency}
				</div>
				<div class="roundedStatus">
					{if $invoiceObj->roundTotal}
						[{$_LANG['Invoices']['InvoiceView']['index']['texts']['totalRounded']}]
					{else}
						[{$_LANG['Invoices']['InvoiceView']['index']['texts']['totalUnrounded']}]
					{/if}
				</div>
			</td>
	</tr>

</table>