{* - 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.clientInvoicesList.texts.invoice}</th>
		<th>{$_LANG.invoices.balanceInvoices.clientInvoicesList.texts.service}</th>
		<th>{$_LANG.invoices.balanceInvoices.clientInvoicesList.texts.value}</th>
		<th width="1%" class="right nowrap">{$_LANG.invoices.balanceInvoices.clientInvoicesList.texts.options}</th>
	</tr>


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

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

	{foreach name=invLoop from=$invoicesList key=thisInvKey item=invoice}

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

		{foreach name=servLoop from=$invoice.servicesList key=thisServKey item=service}

			<tr id="serviceTr_{$service.id}"
				{if $selectedRows[$service.id] and !$service.hideService}class="{$trClass} selectedRow"
				{else}class="{$trClass}"{/if}
			>

				<td class="left">
					{if $smarty.foreach.servLoop.first}
						<div>{counter name=resultsCount assign="currentResult" print=true}.</div>
						{if $invoice.servicesCountTotal>$invoice.servicesCountDisplayed}
							<div class="hiddenRowsStats help" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.hiddenRows}">[{$invoice.servicesCountDisplayed}/{$invoice.servicesCountTotal}]</div>
						{/if}
					{/if}
				</td>

				<td {if !$smarty.foreach.servLoop.first}class="notFirstRow"{/if}>

					{if $smarty.foreach.servLoop.first}
						<a href="#;"
							{if $userOptionsAccess['Modules/Invoices/InvoiceView']}
								class="icon-view" onclick="clientInvoiceView('{$invoice['idInvoice']}');"
								tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.viewInvoice}"
							{else}
								class="icon-view-disabled"
								tooltip="{$_LANG.noAccessToOption}"
							{/if}
						></a>
					{/if}

					<div style="padding-right:16px;">
						<b>{$invoice.invoiceNumber} / {$invoice.invoiceDate|dateTimeFormat}</b>
						{if $invoice.idCorporate}[{$_LANG.invoices.balanceInvoices.clientIntList.list.legalEnt}]{/if}{if $invoice.idCustomer}[{$_LANG.invoices.balanceInvoices.clientIntList.list.individual}]{/if}
					</div>
					<div>
						{$invoice.clientName}
					</div>

				</td>

				<td>
					{if $service.originalId}
						<a class="icon-infoOrange" href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.serviceDetails}"
							onClick="RemoteLoad.load(this, MVC.appUrl('RemoteData/InfoBox', 'service', { 'id': '{$service.originalId}' }), null);"
						></a>
					{/if}
					<div style="margin-right:14px;">
						<b>{$service.serviceType|default:'-'}</b> {if $service.refund}<span class="refund">[R]</span>{/if}
					</div>
					<div class="serviceStartDate">{$service.startDate|dateTimeFormat}</div>
				</td>

				<td class="nowrap right {if $service.hideService}hiddenRow{/if}">
					{if $service.idBalance}
						<i>{$service.serviceTotalValue|priceFormat:$invoice.currency}</i>
					{else}
						{$service.serviceTotalValue|priceFormat:$invoice.currency}
					{/if}
				</td>

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

					<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>

											{if $service.balanceDetails.balanceNumber}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceNo}:</b> {$service.balanceDetails.balanceNumber}</div>
											{/if}
											{if $service.balanceDetails.balanceDate}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceDate}:</b> {$service.balanceDetails.balanceDate|dateTimeFormat}</div>
											{/if}
											{if $service.balanceDetails.balanceType}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceType}:</b> {$service.balanceDetails.balanceTypeName}</div>
											{/if}
											{if $service.balanceDetails.balanceStatus}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceStatus}:</b> {$service.balanceDetails.balanceStatusName}</div>
											{/if}
											{if $service.balanceDetails.balanceName}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceName}:</b> {$service.balanceDetails.balanceName}</div>
											{/if}
											{if $service.balanceDetails.balanceCode}
												<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceCode}:</b> {$service.balanceDetails.balanceCode}</div>
											{/if}
											<br />
											<div><b>&bull; {$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.balanceConfirmed}:</b> <b>{if $service.balanceDetails.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 !$service.balanceDetails.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 !$service.balanceDetails.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 !$service.balanceDetails.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>
									{if !$service.hideService and $service.id}
										<a class="icon-balanceAdd" id="checkServiceButton_{$service.id}" {if $selectedRows[$service.id]}style="display:none;"{/if}
											href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.chooseServiceToBalance}"
											onclick="selectClientService('{$service.id}', '{$createBalancesMode}');"
										></a>
										<a class="icon-balanceDelete" id="uncheckServiceButton_{$service.id}" {if !$selectedRows[$service.id]}style="display:none;"{/if}
											href="#;"" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.unchooseServiceToBalance}"
											onclick="selectClientService('{$service.id}', '{$createBalancesMode}');"
										></a>
									{else}
										<a class="icon-balanceAdd-disabled"
											href="#;" tooltip="{$_LANG.invoices.balanceInvoices.clientInvoicesList.tooltips.repeatedService}"
										></a>
									{/if}
								</td>
							{/if}

						</tr>
					</table>

				</td>
			</tr>

		{/foreach}

		<tr>
			<td colspan="5" class="invoiceSeparator"></td>
		</tr>

	{/foreach}

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

</table>
