<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>{$_LANG.cashBookView.exportHtml.pageTitle}</title>
		<style type="text/css">

			body { font-family:Arial; font-size:13px; }

			.errorMessage {
				border-top:1px solid red; border-bottom:1px solid red; background-color:#FFF0F0; color:red; text-align:center;
				font-weight:bold; padding:5px; margin-top:10px; font-size:14px;
			}

			#printBox { padding-top:10px; text-align:center; }

			.title { font-size:20px; text-align:center; font-weight:bold; padding:10px; }
			.subtitle { font-size:13px; font-weight:bold; padding:3px; }

			.right { text-align:right}

			table.cashbookTable { width:100%; margin-top:10px; border-collapse: collapse; }
			table.cashbookTable tr.balance td { font-weight:bold; }
			table.cashbookTable tr th { margin:0px; padding:3px; border:1px solid #000000; }
			table.cashbookTable tr td { margin:0px; padding:3px; border:1px solid #666666; }

		</style>
	</head>

	<body>

		{* determine intial balance *}
		{$oneCurrency="{$currenciesSelected|reset}"}
		{$initialBalanceDate="{$cashBookTotalsArr|key}"}
		{$initialBalance="{$cashBookTotalsArr[$initialBalanceDate][$oneCurrency]}"}

		{$totalCols=8}
		{if $showExchRate} {$totalCols=$totalCols+1} {/if}
		{if $showEquivDefCurr} {$totalCols=$totalCols+1} {/if}

		<div class="subtitle">{$extraStuff.companyName}</div>
		<div class="subtitle">Cod fiscal: {$extraStuff.companyFiscalCode}</div>
		<div class="subtitle">Moneda: {$oneCurrency}</div>
		<div class="subtitle">Punct lucru: {officeLabel ref=$idOffice hideLink="1"}</div>

		{* page title *}
		<div class="title">
			Registru de casa:
			{if $dateStart==$dateEnd}
				{$dateStart|dateTimeFormat}
			{else}
				{$dateStart|dateTimeFormat} - {$dateEnd|dateTimeFormat}
			{/if}
		</div>

		{$selectedCurrenciesCount="{$currenciesSelected|count}"}

		{* check the number of currencies *}
		{if $selectedCurrenciesCount!=1}

			<div class="errorMessage">
				{$_LANG.cashBookView.exportHtml.onlyOneCurrAllowedMsg}
			</div>

		{else}

			{* ************ THE CASHBOOK REPORT ************************************************ *}
			<table class="cashbookTable">

				{* table head *}
				<tr>
					<th rowspan="2">Nr. crt.</th>
					<th colspan="3">Document</th>
					<th rowspan="2">Beneficiar</th>
					<th rowspan="2">Explicatii</th>
					<th rowspan="2">Incasare</th>
					<th rowspan="2">Plata</th>
					{if $showExchRate}
						<th rowspan="2">Curs</th>
					{/if}
					{if $showEquivDefCurr}
						<th rowspan="2">Valoare tranz. lei</th>
					{/if}
				</tr>
				<tr>
					<th>Data</th>
					<th>Tip</th>
					<th>Numar</th>
				</tr>

				{* initial balance *}
				<tr class="balance">
					<td colspan="{$totalCols}" class="bold">Sold precedent: {$initialBalance|priceFormat}</td>
				</tr>

				{$finalBalance=$initialBalance}
				{$cashBalance=0}
				{$payBalance=0}
				{* documents list *}
				{foreach $allDocumentsList as $date=>$docsList}
					{foreach $docsList as $doc}
						{if $doc.currency==$oneCurrency} {* filter by currency *}
							{$finalBalance=$finalBalance+$doc.value}
							{if $doc.value>0}{$cashBalance=$cashBalance+$doc.value}{/if}
							{if $doc.value<0}{$payBalance=$payBalance-$doc.value}{/if}
							<tr>
								<td>
									{counter name="cb"}.
								</td>
								<td>
									{$doc.date|dateTimeFormat}
								</td>
								<td>
									{$doc.documentTypeName}
								</td>
								<td>
									{if $doc.number}
										{$doc.number}
									{else}
										-
									{/if}
								</td>
								<td>
									{if $doc.clientName}
										{$doc.clientName}
									{elseif $doc.supplierName}
										{$doc.supplierName}
									{else}
										{$doc.partner}
									{/if}
								</td>
								<td>
									{$doc.explanations}
								</td>
								<td class="right">
									{if $doc.value>=0} {$doc.value|priceFormat} {/if}
								</td>
								<td class="right">
									{if $doc.value<0} {(-$doc.value)|priceFormat} {/if}
								</td>
								{if $showExchRate}
									<td class="right">
										{$currencyExchangeValues[$doc.date][$oneCurrency]}
									</td>
								{/if}
								{if $showEquivDefCurr}
									<td class="right">
										{if $doc.eqvValue}
											{$doc.eqvValue|priceFormat}
										{else}
											{$doc.value|priceFormat}
										{/if}
									</td>
								{/if}
							</tr>
						{/if}
					{/foreach}
				{/foreach}

				{* final balance for cashing/payment docs *}
				<tr class="balance">
					<td colspan="5" class="bold right">TOTAL</td>
					<td class="bold right">{$cashBalance|priceFormat}</td>
					<td class="bold right">{$payBalance|priceFormat}</td>
					{if $showExchRate}
						<td></td>
					{/if}
					{if $showEquivDefCurr}
						<td></td>
					{/if}
				</tr>


				{* final balance *}
				<tr class="balance">
					<td colspan="{$totalCols}" class="bold">Sold final: {$finalBalance|priceFormat}</td>
				</tr>

			</table>

			<br />
			<div style="float:right">Departament financiar-contabil</div>
			<div>Casier {userLabel ref=$smarty.const.CURRENT_ID_USER noLink="1"}</div>

			<div id="printBox">
				<button class="button"
					onclick="
						document.getElementById('printBox').style.display='none';
						window.print();
						document.getElementById('printBox').style.display='';
					"
				>{$_LANG.cashBookView.exportHtml.printBtn}</button>
			</div>

		{/if}

	</body>
</html>