{* - on 'simple' mode - stores the selected service id - *}
{if $createBalancesMode=='simple'}
	<script>selectedClientService='{$selectedService}';</script>
{/if}

<table class="list" style="margin:2px">

	{******************************************************************************************}
	{********************************* TABLE HEADER *******************************************}
	{******************************************************************************************}

	<tr>
		<th width="1%" class="nowrap left">#</th>
		<th>{$_LANG.invoices.balanceInvoices.clientServicesList.th_res}</th>
		<th>{$_LANG.invoices.balanceInvoices.clientServicesList.th_serv}</th>
		<th>{$_LANG.invoices.balanceInvoices.clientServicesList.th_offer}</th>
		<th width="1%" class="right nowrap">{$_LANG.invoices.balanceInvoices.clientServicesList.th_options}</th>
	</tr>


	{******************************************************************************************}
	{*********************************** TABLE INFO *******************************************}
	{******************************************************************************************}

	{counter name=resultsCount start=$pages.currentPage*$pages.resultsPerPage print=false}

	{foreach $servicesList as $idService=>$service}

		{cycle values="odd,even" assign="trClass"}

		<tr id="serviceTr_{$idService}" {if $selectedRows[$idService]}class="{$trClass} selectedRow"{else}class="{$trClass}"{/if}>

			<td class="left">
				{counter name=resultsCount assign="currentResult" print=true}.</div>
			</td>

			<td>
				<div>
					<b>{$service.reservationConvertedId} / {$service.reservationDate|dateTimeFormat}</b>
				</div>
				<div>
					{$service.reservationNumber}
					{if $service.reservationNumber and $service.reservationCode};{/if}
					{$service.reservationCode}</b>
				</div>
			</td>

			<td>
				<a href="#;" class="icon-infoOrange" tooltip="{$_LANG.invoices.balanceInvoices.clientServicesList.servDetTooltip}"
					onClick="RemoteLoad.load(this, MVC.appUrl('RemoteData/InfoBox', 'service', { 'id': '{$idService}' }), null);"
				></a>
				<div style="padding-right:12px;">
					<b>{$service.serviceName}</b>
				</div>
				<div class="serviceStartDate">{$service.offerStartDatetime|dateTimeFormat}</div>
			</td>

			<td class="nowrap right">
				{if $service.statusFin!='TI' and $service.reversedService}
					<img src="{$smarty.const.SMARTY_BLANKGIF}" alt="" align="absmiddle" class="imgIcon icon-statusPE-10 help"
						tooltip="{$_LANG.invoices.balanceInvoices.clientServicesList.servReversedNonTITooltip}"
					/>
				{/if}

				{if $service.idBalance}
					<i>{$service.offerTotal|priceFormat:$service.offerCurrency}</i>
				{else}
					{$service.offerTotal|priceFormat:$service.offerCurrency}
				{/if}
			</td>



			{* ==================== OPTIONS ==================== *}
			<td class="right">

				{if $service.idBalance}
					{$balance=\Entity\Balance::select($service.idBalance)}
				{/if}

				<table class="options">
					<tr>

						{* --- VIEW BALANCE FOR THIS SERVICE --- *}
						{if $service.idBalance}
							<td>
								<a class="icon-balanceView"
									href="#;"
									onclick="invoiceBalanceView('{$service.idBalance}');"
									tooltip="
										<div class='viewBalanceTitle'>{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceDetTitle}</div>

										<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceNo}:</b> {$balance->balanceNumber}</div>
										<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceDate}:</b> {$balance->balanceDate|dateTimeFormat}</div>
										<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceType}:</b> {$balance->balanceTypeName}</div>
										<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceStatus}:</b> {$balance->balanceStatusName}</div>
										{if $balance->balanceName}
											<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceName}:</b> {$balance->balanceName}</div>
										{/if}
										{if $balance->balanceCode}
											<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceCode}:</b> {$balance->balanceCode}</div>
										{/if}
										<br />
										<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceConfirmed}:</b> <b>{if $balance->confirmTime}{$_LANG.yes}{else}{$_LANG.no}{/if}</b></div>

										<br class='space5' />
										<div class='center italic bold'>{$_LANG.invoices.balanceInvoices.clientInvoicesList.texts.clickToView}</div>
									"
								></a>
							</td>
							<td>|</td>
						{/if}

						{* --- CONFIRM BALANCE FOR THIS SERVICE --- *}
						{if $service.idBalance}
							<td>
								{if CurrentUserAccess::getInstance()->hasAccessToOption('Modules/Invoices/BalancesList-confirm')}
									{if !$balance->confirmTime}
										<a class="icon-lock"
											href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.confirmBalance}"
											onclick="messageBox.showQuestion('{$_LANG.confirm}', '{$_LANG.invoices.balanceInvoices.clientInvoicesList.confirms.confirmBalance}', [ ['{$_LANG.yes}', 'window.location.href=\'./?blockIdBalance={$service.idBalance}\';'], '{$_LANG.no}'])"
										></a>
									{else}
										<a class="icon-unlock"
											href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.cancelConfirmBalance}"
											onclick="messageBox.showQuestion('{$_LANG.confirm}', '{$_LANG.invoices.balanceInvoices.clientInvoicesList.confirms.cancelConfirmBalance}', [ ['{$_LANG.yes}', 'window.location.href=\'./?unblockIdBalance={$service.idBalance}\';'], '{$_LANG.no}'])"
										></a>
									{/if}
								{else}
									{if !$balance->confirmTime}
										<a class="icon-lock-disabled" href="#;" tooltip="{$_LANG.noAccessToOption}"></a>
									{else}
										<a class="icon-unlock-disabled" href="#;" tooltip="{$_LANG.noAccessToOption}"></a>
									{/if}
								{/if}
							</td>
							<td>|</td>
						{/if}

						{* --- DELETE BALANCE FOR THIS SERVICE --- *}
						{if $service.idBalance}
							<td>
								{if CurrentUserAccess::getInstance()->getAccessOptionValue('Modules/Invoices/BalancesList-delete')}
									{if !$balance->confirmTime}
										<a href="#;" class="icon-delete"
											tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.deleteBalance}"
											onclick="{strip}
												messageBox.showQuestion(
													'{$_LANG.confirm}',
													'{$_LANG['invoices']['balanceInvoices']['balanceManagement']['confirms']['deleteBalance']}
														<br><i>{$_LANG['invoices']['balanceInvoices']['balanceManagement']['confirms']['deleteBalanceDetails']}</i>
														<br class=\'space5\' />
														<input
															id=\'forceSelection_{$service.idBalance}\'
															class=\'noBorder\'
															type=\'checkbox\' value=\'1\'
														/> <label for=\'forceSelection_{$service.idBalance}\'>{$_LANG['invoices']['balanceInvoices']['balanceManagement']['confirms']['forceDeletedBalanceSelection']}</label>
													',
													[
														{ title:'{$_LANG.yes}', onClick:' window.location.href=\'./?deleteIdBalance={$service.idBalance}&reselectComponents=\'+ Number($F(\'forceSelection_{$service.idBalance}\')) ', focus:true },
														{ title:'{$_LANG.no}' }
													]
												)
											{/strip}"
										></a>
									{else}
										<a class="icon-delete-disabled"
											href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.cantDeleteConfirmedBalance}"
										></a>
									{/if}
								{else}
									<a class="icon-delete-disabled" href="#;" tooltip="{$_LANG.noAccessToOption}"></a>
								{/if}
							</td>
						{/if}

						{* --- IF NO BALANCE SET FOR THIS SERVICE --- *}
						{if !$service.idBalance}
							<td>
								<a class="icon-balanceAdd" id="checkServiceButton_{$idService}" {if $selectedRows[$idService]}style="display:none;"{/if}
									href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.chooseServiceToBalance}"
									onclick="selectClientService('{$idService}', '{$createBalancesMode}');"
								></a>
								<a class="icon-balanceDelete" id="uncheckServiceButton_{$idService}" {if !$selectedRows[$idService]}style="display:none;"{/if}
									href="#;"" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.unchooseServiceToBalance}"
									onclick="selectClientService('{$idService}', '{$createBalancesMode}');"
								></a>
							</td>
						{/if}

					</tr>
				</table>

			</td>

		</tr>

	{/foreach}



	{* select all/none button *}
	{if $createBalancesMode=="bulk"}
		<tr>
			<td colspan="5" class="right">
				<a href="#;" class="link"
					onclick="
						ajaxIframe('clientServicesListDiv', 'clientServicesList.php?clientServicesSelectAll=-1');
					"
				>{$_LANG.invoices.balanceInvoices.clientServicesList.filters.listClientResUnselectAll}</a>
				&nbsp;
				<a href="#;" class="link"
					onclick="
						ajaxIframe('clientServicesListDiv', 'clientServicesList.php?clientServicesSelectAll=1');
					"
				>{$_LANG.invoices.balanceInvoices.clientServicesList.filters.listClientResSelectAll}</a>
			</td>
		</tr>
	{/if}

</table>
