{$use_alert_color = ConfigHelper::checkConfig('invoices.use_alert_color')}
{$show_balance = ConfigHelper::checkConfig('invoices.show_balance', true)}
{$show_expired_balance = ConfigHelper::checkConfig('invoices.show_expired_balance')}
{$show_balance_summary = ConfigHelper::checkConfig('invoices.show_balance_summary')}
{$hide_discount = ConfigHelper::checkConfig('invoices.hide_discount')}
{$hide_prodid = ConfigHelper::checkConfig('invoices.hide_prodid')}
{$show_tax_category = ConfigHelper::checkConfig('invoices.show_tax_category', true)}
{if empty($invoice.taxcategories)}
	{$show_tax_category = false}
{/if}
{if !empty($invoice.div_ccode)}
	{Localisation::setSystemLanguage($invoice.div_ccode)}
{/if}

{$cols = 12}
{if $hide_prodid}
	{$cols = $cols - 1}
{/if}
{if !$show_tax_category}
	{$cols = $cols - 1}
{/if}
{if $hide_discount || (empty($invoice.pdiscount) && empty($invoice.vdiscount))}
	{$cols = $cols - 1}
{/if}

<!--// $Id$ //-->
<div{if !$invoice.last} style="page-break-after: always"{/if}>
	<table width="100%" cellspacing="3">
		<colgroup>
			{if empty($ksefurl)}
				<col style="width: 1%;">
			{else}
				<col style="width: 1%;">
				<col style="width: 97%;">
			{/if}
			<col style="width: 1%;">
			<col style="width: 1%;">
		</colgroup>
		<tr>
			<td class="hdf{if !empty($ksefurl)} ksef-invoice{/if}" valign="top" nowrap>
				{number number=$invoice.number template=$invoice.template time=$invoice.cdate customerid=$invoice.customerid assign=number}
				{if $invoice.invoice && $invoice.doctype == $smarty.const.DOC_CNOTE}
					{number number=$invoice.invoice.number template=$invoice.invoice.template time=$invoice.invoice.cdate customerid=$invoice.invoice.customerid assign=number_ref}
					<strong>{t a=$number}Credit Note No. $a{/t}</strong><br>
					<strong class="mdf">
						{t a=$number_ref}for Invoice No. $a{/t}
					</strong><br>
				{elseif $invoice.doctype == $smarty.const.DOC_INVOICE_PRO}
					<strong>{t a=$number}Pro Forma Invoice No. $a{/t}</strong><br>
				{else}
					<strong>{t a=$number}Invoice No. $a{/t}</strong><br>
				{/if}
				{if $invoice.cancelled}
					<strong>{trans("CANCELLED")}</strong><br>
				{/if}
				{if !empty($invoice.dontpublish)}
					<strong>{trans("NO ACCOUNTANT DOCUMENT")}</strong><br>
				{/if}
				<!--<strong>{*$type*}</strong>//-->
				{if $duplicate}
					<br>
					<span class="sdr">
						{trans("DUPLICATE, draw-up date:")}
						{if $invoice['duplicate-date']}
							{$invoice['duplicate-date']|date_format:"Y-m-d"}
						{else}
							{$smarty.now|date_format:"Y-m-d"}
						{/if}
					</span>
				{/if}
			</td>
			{if !empty($ksefurl)}
				<td class="ksef-invoice-info">
					<div>
						<a href="{$ksefurl}" target="_blank">
							{barcode type="QRCODE" text=$ksefurl show_text=false transliterate=false width=-2 height=-2}
						</a>
						<strong>{$ksefnumber}</strong>
					</div>
					{if !empty($ksefcertificateurl)}
						<div>
							<a href="{$ksefcertificateurl}" target="_blank">
								{barcode type="QRCODE" text=$ksefcertificateurl show_text=false transliterate=false width=-2 height=-2}
							</a>
							<strong>CERTYFIKAT</strong>
						</div>
					{/if}
				</td>
			{/if}
			<td nowrap align="right" valign="top" class="sdr">
				{trans("Draw-up date:")}
				<br>
				{if !ConfigHelper::checkConfig('invoices.hide_sale_date')}
					{trans("Sale date:")}
					<br>
				{/if}
				{if $use_alert_color}
					<span style="color: red; font-weight: bold;">
				{/if}
				{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_DEADLINE) > 0}
					{trans("Deadline:")}
				{else}
					{trans("Payment Cleared")}
				{/if}
				{if $use_alert_color}
					</span>
				{/if}
				<br>
				{if !ConfigHelper::checkConfig('invoices.hide_payment_type')}
					{trans("Payment type:")}
				{/if}
			</td>
			<td nowrap align="left" valign="top" class="sdr">
				{$invoice.cdate|date_format:"Y-m-d"}
				{if $invoice.division_cplace != ""}
					, {$invoice.division_cplace}
				{/if}
				<br>
				{if !ConfigHelper::checkConfig('invoices.hide_sale_date')}
					{$invoice.sdate|date_format:"Y-m-d"}
					<br>
				{/if}
				{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_DEADLINE) > 0}
					{if $use_alert_color}
						<span style="color: red; font-weight: bold;">
					{/if}
					{$invoice.pdate|date_format:"Y-m-d"}
					{if $use_alert_color}
						</span>
					{/if}
				{else}
					&nbsp;
				{/if}
				<br>
				{if !ConfigHelper::checkConfig('invoices.hide_payment_type')}
					{trans($invoice.paytypename)}
					{if !empty($invoice.splitpayment)}
						<br>
						{trans("(split payment)")}
					{/if}
					{if !empty($invoice.flags[$smarty.const.DOC_FLAG_RECEIPT])}
						<br>
						{trans("<!invoice>(receipt)")}
					{/if}
				{/if}
			</td>
		</tr>
		<tr>
			<td colspan="{if empty($ksefurl)}3{else}4{/if}" align="center">
				&nbsp;
			</td>
		</tr>
	</table>

	<table width="100%" cellspacing="3">
		<tr>
			<td width="66%" valign="top">
				<div class="address-header">{trans("Seller:")}</div>
				{if !ConfigHelper::checkConfig('invoices.show_only_alternative_accounts')
					|| empty($invoice.bankccounts)}
					{$accounts = array(bankaccount($invoice.customerid, $invoice.account, $invoice.export))}
				{else}
					{$accounts = array()}
				{/if}
				{if ConfigHelper::checkConfig('invoices.show_all_accounts')
					|| ConfigHelper::checkConfig('invoices.show_only_alternative_accounts')}
					{$accounts = array_merge($accounts, $invoice.bankaccounts)}
				{/if}
				{foreach $accounts as $accountidx => $account}
					{$accounts[$accountidx] = format_bankaccount($account, $invoice.export)}
				{/foreach}
				{textformat assign="account_text" wrap=5000}
					{if $use_alert_color}
						<span style="color:red">
					{/if}
					{implode('<br>', $accounts)}
					{if $use_alert_color}
						</span>
					{/if}
				{/textformat}
				{$tmp = str_replace('%ten%', format_ten($invoice.division_ten, $invoice.export), $invoice.division_header)}
				{$tmp = str_replace("\n", '<br>', $tmp)}
				{$tmp = str_replace('%bankaccount', $account_text, $tmp)}
				{$tmp = str_replace('%bankname', $invoice.div_bank, $tmp)}
				{$tmp = str_replace('%extid', $invoice.extid, $tmp)}

				{if ConfigHelper::checkConfig('invoices.customer_bankaccount', true)}
					{textformat assign="tmp" wrap=5000}
						{$tmp}
						<br>
						{trans('Bank account:')}
						<br>
						<strong>{$account_text}</strong>
					{/textformat}
				{/if}

				{$tmp}

				<br><br>

				<div class="address-header">{trans("Purchaser:")}</div>
				{$invoice.name}
				<br>
				{$invoice.address}
				<br>
				{$invoice.zip} {$invoice.city}{if $invoice.export}, {trans($invoice.country)}{/if}
				<br>
				{if $invoice.ten != ""}
					{trans("TEN:")}
					{$currentSystemLanguage = Localisation::getCurrentSystemLanguage()}
					{Localisation::setSystemLanguage($invoice.lang)}
					{format_ten($invoice.ten, $invoice.export)}
					<br>
					{Localisation::setSystemLanguage($currentSystemLanguage)}
				{elseif !ConfigHelper::checkConfig('invoices.hide_ssn', true) && $invoice.ssn != ""}
					{trans("SSN:")} {$invoice.ssn}
					<br>
				{/if}

				<br>

				{if $invoice.recipient_address_id}
					<div class="address-header">{trans("Recipient:")}</div>
					{document_address name=$invoice.rec_name address=$invoice.rec_address
							street=$invoice.rec_street zip=$invoice.rec_zip
							postoffice=$invoice.rec_postoffice city=$invoice.rec_city}
					{if (!empty($invoice.recipient_ten))}
						<br>
						{trans("TEN")}
						{$invoice.recipient_ten}
					{/if}
				{/if}
			</td>
			<td width="34%" valign="top" class="sdr">
				{if ConfigHelper::checkConfig('invoices.post_address', true)}
					<br>
					<br>
					<br>
					<strong>
					{if $invoice.post_name || $invoice.post_address}
						{if $invoice.post_name}
							{$name=$invoice.post_name}
						{else}
							{$name=$invoice.name}
						{/if}
						{document_address name=$name address=$invoice.post_address
								street=$invoice.post_street zip=$invoice.post_zip
								postoffice=$invoice.post_postoffice city=$invoice.post_city}
					{else}
						{$invoice.name}
						<br>
						{$invoice.address}
						<br>
						{$invoice.zip} {$invoice.city}
					{/if}</strong>
				{/if}
			</td>
		</tr>
		<tr>
			<td width="100%" colspan="2">
				&nbsp;
				<br>
				&nbsp;
			</td>
		</tr>
	</table>

	<table width="100%" cellpadding="3">
		<tr class="fall">
			<td width="1%" class="head" align="center">
				<strong>{trans("No.")}</strong>
			</td>
			<td width="{-$cols + 101}%" class="head" align="center">
				<strong>{trans("Name of Product, Commodity or Service")}</strong>
			</td>
			{if !$hide_prodid}
				<td width="1%" class="head" align="center">
					<strong>{trans("<!invoice>Product ID")}</strong>
				</td>
			{/if}
			{if $show_tax_category}
				<td width="1%" class="head" align="center">
					<strong>{trans("Tax Category")}</strong>
				</td>
			{/if}
			<td width="1%" class="head" align="center">
				<strong>{trans("Unit")}</strong>
			</td>
			<td width="1%" class="head" align="center">
				<strong>{trans("Amount")}</strong>
			</td>
			{if !$hide_discount && ($invoice.pdiscount != 0 || $invoice.vdiscount != 0)}
				<td width="1%" class="head" align="center">
					<strong>{trans("Discount")}</strong>
				</td>
			{/if}
			{if $invoice.netflag}
				<td width="1%" class="head" align="center">
					<strong>{trans("Unitary Net Value")}</strong>
				</td>
			{else}
				<td width="1%" class="head" align="center">
					<strong>{trans("Unitary gross value")}</strong>
				</td>
			{/if}
			<td width="1%" class="head" align="center">
				<strong>{trans("Net Value")}</strong>
			</td>
			<td width="1%" class="head" align="center">
				<strong>{trans("Tax Rate")}</strong>
			</td>
			<td width="1%" class="head" align="center">
				<strong>{trans("Tax Value")}</strong>
			</td>
			<td width="1%" class="head" align="center">
				<strong>{trans("Gross Value")}</strong>
			</td>
		</tr>
		{if $invoice.invoice && $invoice.doctype == $smarty.const.DOC_CNOTE}
			<tr>
				<td colspan="{$cols}" class="fbottom">
					<strong>{trans("Was:")}</strong>
				</td>
			</tr>
			{cycle values="grey,white" print=false}
			{counter start=0 print=false}
			{foreach from=$invoice.invoice.content item=item}
				<tr class="{cycle}">
					<td class="flr" align="right">
						{counter}.
					</td>
					<td width="{-$cols + 101}%" class="flr">
						{$item.description}
					</td>
					{if !$hide_prodid}
						<td class="flr">
							{$item.prodid}
						</td>
					{/if}
					{if $show_tax_category}
						<td class="flr" align="center">
							{if !empty($item.taxcategory)}
								{sprintf('%02d', $item.taxcategory)}
							{/if}
						</td>
					{/if}
					<td class="flr" align="center">
						{$item.content}
					</td>
					<td class="flr" align="center">
						{floatval($item.count)}
					</td>
					{if !$hide_discount && ($invoice.pdiscount != 0 || $invoice.vdiscount != 0)}
						<td class="flr" align="right" nowrap>
							{if $item.pdiscount != 0}
								{Localisation::formatNumber($item.pdiscount)} %
							{else}
								{Localisation::smartFormatNumber($item.vdiscount)}
							{/if}
						</td>
					{/if}
					{if $invoice.netflag}
						<td class="flr" align="right" nowrap>
							{Localisation::smartFormatNumber($item.basevalue)}
						</td>
					{else}
						<td class="flr" align="right" nowrap>
							{Localisation::smartFormatNumber($item.value)}
						</td>
					{/if}
					<td class="flr" align="right" nowrap>
						{Localisation::formatNumber($item.totalbase)}
					</td>
					<td class="flr" align="right" nowrap>
						{$item.taxlabel}
					</td>
					<td class="flr" align="right" nowrap>
						{Localisation::formatNumber($item.totaltax)}
					</td>
					<td width="1%" class="flr" align="right" nowrap>
						{Localisation::formatNumber($item.total)}
					</td>
				</tr>
			{/foreach}
			<tr>
				<td colspan="{$cols - 4}" align="right" class="ftop" style="text-align: right">
					<p align="right"><strong>{trans("Total:")}</strong></p>
				</td>
				<td align="right" class="fall" nowrap>
					{Localisation::formatNumber($invoice.invoice.totalbase)}
				</td>
				<td class="fall" align="right">
					<strong>x</strong>
				</td>
				<td class="fall" align="right" nowrap>
					{Localisation::formatNumber($invoice.invoice.totaltax)}
				</td>
				<td class="fall" align="right" nowrap>
					{Localisation::formatNumber($invoice.invoice.total)}
				</td>
				</tr>
				<tr>
				<td colspan="{$cols - 4}" align="right">
					&nbsp;
				</td>
				<td colspan="4" align="center">
					<strong>{trans("in it:")}</strong>
				</td>
			</tr>
			{foreach from=$invoice.invoice.taxest item=item}
				<tr>
					<td colspan="{$cols - 4}" align="right">
						&nbsp;
					</td>
					<td align="right" class="fall" nowrap>
						{Localisation::formatNumber($item.base)}
					</td>
					<td class="fall" align="right">
						{$item.taxlabel}
					</td>
					<td class="fall" align="right" nowrap>
						{Localisation::formatNumber($item.tax)}
					</td>
					<td class="fall" align="right" nowrap>
						{Localisation::formatNumber($item.total)}
					</td>
				</tr>
			{/foreach}
			<tr>
				<td colspan="{$cols}" class="fbottom">
					<strong>{trans("Corrected to:")}</strong>
				</td>
			</tr>
		{/if}
		{cycle values="grey,white" print=false name=cycle2}
		{counter start=0 print=false}
		{foreach from=$invoice.content item=item}
			<tr class="{cycle name=cycle2}">
				<td class="flr" align="right">
					{counter}.
				</td>
				<td width="{-$cols + 101}%" class="flr">
					{$item.description}
				</td>
				{if !$hide_prodid}
					<td class="flr">
						{$item.prodid}
					</td>
				{/if}
				{if $show_tax_category}
					<td class="flr" align="center">
						{if !empty($item.taxcategory)}
							{sprintf('%02d', $item.taxcategory)}
						{/if}
					</td>
				{/if}
				<td class="flr" align="center">
					{$item.content}
				</td>
				<td class="flr" align="center">
					{floatval($item.count)}
				</td>
				{if !$hide_discount && ($invoice.pdiscount != 0 || $invoice.vdiscount != 0)}
					<td class="flr" align="right" nowrap>
						{if $item.pdiscount != 0}{Localisation::formatNumber($item.pdiscount)} %{else}{Localisation::smartFormatNumber($item.vdiscount)}{/if}
					</td>
				{/if}
				{if $invoice.netflag}
					<td class="flr" align="right" nowrap>
						{Localisation::smartFormatNumber($item.basevalue)}
					</td>
				{else}
					<td class="flr" align="right" nowrap>
						{Localisation::smartFormatNumber($item.value)}
					</td>
				{/if}
				<td class="flr" align="right" nowrap>
					{Localisation::formatNumber($item.totalbase)}
				</td>
				<td class="flr" align="right" nowrap>
					{$item.taxlabel}
				</td>
				<td class="flr" align="right" nowrap>
					{Localisation::formatNumber($item.totaltax)}
				</td>
				<td class="flr" align="right" nowrap>
					{Localisation::formatNumber($item.total)}
				</td>
			</tr>
		{/foreach}
		<tr>
			<td colspan="{$cols - 4}" align="right" class="ftop" style="text-align: right">
				<p align="right"><strong>{trans("Total:")}</strong></p>
			</td>
			<td align="right" class="fall" nowrap>
				{Localisation::formatNumber($invoice.totalbase)}
			</td>
			<td class="fall" align="right">
				<strong>x</strong>
			</td>
			<td class="fall" align="right" nowrap>
				{Localisation::formatNumber($invoice.totaltax)}
			</td>
			<td class="fall" align="right" nowrap>
				{Localisation::formatNumber($invoice.total)}
			</td>
		</tr>
		<tr>
			<td colspan="{$cols - 4}" align="right">
				&nbsp;
			</td>
			<td colspan="4" align="center">
				<strong>{trans("in it:")}</strong>
			</td>
		</tr>
		{foreach from=$invoice.taxest item=item}
			<tr>
				<td colspan="{$cols - 4}" align="right">
					&nbsp;
				</td>
				<td align="right" class="fall" nowrap>
					{Localisation::formatNumber($item.base)}
				</td>
				<td class="fall" align="right">
					{$item.taxlabel}
				</td>
				<td class="fall" align="right" nowrap>
					{Localisation::formatNumber($item.tax)}
				</td>
				<td class="fall" align="right" nowrap>
					{Localisation::formatNumber($item.total)}
				</td>
			</tr>
		{/foreach}
		{if $invoice.invoice && $invoice.doctype == $smarty.const.DOC_CNOTE}
			{math assign=totalbase equation="x-y" x=$invoice.totalbase y=$invoice.invoice.totalbase}
			{math assign=totaltax equation="x-y" x=$invoice.totaltax y=$invoice.invoice.totaltax}
			{math assign=total equation="x-y" x=$invoice.total y=$invoice.invoice.total}
			<tr>
				<td colspan="{$cols}"></td>
				</tr>
				<tr>
				<td colspan="{$cols - 4}" align="right">
					<strong>{trans("Difference value:")}</strong>
				</td>
				<td align="right" class="fall" nowrap>
					{if $totalbase > 0}+{/if}{Localisation::formatNumber($totalbase)}
				</td>
				<td class="fall" align="right">
					<strong>x</strong>
				</td>
				<td class="fall" align="right" nowrap>
					{if $totaltax > 0}+{/if}{Localisation::formatNumber($totaltax)}
				</td>
				<td class="fall" align="right" nowrap>
					{if $total > 0}+{/if}{Localisation::formatNumber($total)}
				</td>
			</tr>
		{/if}
		{if $invoice.reason}
			<tr>
				<td colspan="{if $invoice.reason}11{else}10{/if}">
					<strong>{trans("Reason:")}</strong> {$invoice.reason}
				</td>
			</tr>
		{/if}
	</table>

	<table width="100%" cellpadding="3">
		<tr>
			<td width="50%" align="left" class="hdf">
				{if $invoice.rebate}
					{if $use_alert_color && !$show_balance_summary}<span style="color: red; font-weight: bold;">{/if}
					{if $invoice.invoice && $invoice.doctype == $smarty.const.DOC_CNOTE}
						{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_TO_PAY) > 0}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Correction value: $a (to repay){/t}
						{else}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Correction value: $a{/t}
						{/if}
					{else}
						{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_TO_PAY) > 0}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Invoice value: $a (to repay){/t}
						{else}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Invoice value: $a{/t}
						{/if}
					{/if}
					{if $use_alert_color && !$show_balance_summary}</span>{/if}
				{else}
					{if $use_alert_color && !$show_balance_summary}<span style="color: red; font-weight: bold;">{/if}
					{if $invoice.invoice && $invoice.doctype == $smarty.const.DOC_CNOTE}
						{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_TO_PAY) > 0}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Correction value: $a (to pay){/t}
						{else}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Correction value: $a{/t}
						{/if}
					{else}
						{if ($_PAYTYPES[$invoice.paytype].features & $smarty.const.INVOICE_FEATURE_TO_PAY) > 0}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Invoice value: $a (to pay){/t}
						{else}
							{t a=Utils::formatMoney($invoice.value, $invoice.currency)}Invoice value: $a{/t}
						{/if}
					{/if}
					{if $use_alert_color && !$show_balance_summary}</span>{/if}
				{/if}
			</td>
			<td width="50%" align="right" rowspan="2">
				{if !ConfigHelper::checkConfig('invoices.hide_expositor')}
					{t a=$invoice.expositor}Expositor: <b>$a</b>{/t}
				{/if}
			</td>
		</tr>
		{if !ConfigHelper::checkConfig('invoices.hide_in_words')}
			<tr>
				<td width="50%" align="left" class="SDR">
					{trans("In words:")}
					{if ConfigHelper::checkConfig('phpui.to_words_short_version')}
						{$invoice.value|string_format:"%d"|to_words:0:"":1} {$invoice.valuep|string_format:"%02d"}/100
					{else}
						{moneyf_in_words($invoice.value, $invoice.currency)}
					{/if}
				</td>
			</tr>
		{/if}

		{if ConfigHelper::checkConfig('invoices.show_pricing_method', true)}
			<tr>
				<td colspan="2" class="bold">
					{if $invoice.netflag}
						{$comment = trans('net')}
					{else}
						{$comment = trans('gross')}
					{/if}
					{trans('The document is issued according to the $a price', $comment)}
				</td>
			</tr>
		{/if}

		{$customerbalance = $invoice.customerbalance}

		{if !empty($invoice.balance_on_documents)}
			{if $show_balance_summary}
				<tr>
					<td colspan="2" style="padding-bottom: 1em;">
						{if isset($invoice.invoice) && $invoice.doctype == $smarty.const.DOC_CNOTE}
							{$total = $invoice.total - $invoice.invoice.total}
						{else}
							{$total = $invoice.total}
						{/if}

						{$previous_balance = $customerbalance + $total}

						{if $previous_balance > 0}
							{$comment = trans('(excess payment)')}
						{elseif $previous_balance < 0}
							{$comment = trans('(to pay)')}
						{else}
							{$comment = ""}
						{/if}

						{trans('Previous balance: $a $b', Utils::formatMoney(abs($previous_balance) / $invoice.currencyvalue, $invoice.currency), $comment)}
						<br>

						{if $icustomerbalance > 0}
							<span style="font-size: 180%; font-weight: bold; display: inline-block; margin-top: 0.3em;{if $use_alert_color} color: red;{/if}">
								{trans('Excess payment: $a', Utils::formatMoney($customerbalance / $invoice.currencyvalue, $invoice.currency))}
							</span>
						{else}
							<span style="font-size: 180%; font-weight: bold; display: inline-block; margin-top: 0.3em;{if $use_alert_color} color: red;{/if}">
								{trans('Total to pay: $a', Utils::formatMoney(-$customerbalance / $invoice.currencyvalue, $invoice.currency))}
							</span>
						{/if}
					</td>
				</tr>
			{else}
				{if $icustomerbalance > 0}
					{$comment = trans('(excess payment)')}
				{elseif $customerbalance < 0}
					{$comment = trans('(to pay)')}
				{else}
					{$comment = ''}
				{/if}
				<tr>
					<td colspan="2">
						<span style="font-weight: bold">
							{if $use_alert_color}
								<span style="color: red;">
							{/if}
							{trans('Your balance on date of invoice issue: $a $b', Utils::formatMoney($customerbalance / $invoice.currencyvalue, $invoice.currency), $comment)}
							{if $use_alert_color}
								</span>
							{/if}
							<br>
							{trans('Balance includes current invoice')}
						</span>
					</td>
				</tr>
			{/if}
		{/if}
		<tr>
			<td colspan="2">
				<strong>{trans("Cautions:")}</strong><br>
				<blockquote>
				{trans("If you have any questions or doubts, contact with our Customer Service Representative. Prepare your Customer ID, please.")}<br>
				{trans("You may use our automated Customer Care Web Panel, just remember your PIN (it's printed on the other side of this page)")}
				</blockquote>
				<br>
			</td>
		</tr>
		{if $invoice.comment}
			<tr>
				<td colspan="2">
					<strong>{trans("Comment:")}</strong><br>
					<blockquote>
					{$invoice.comment}
					</blockquote>
				</td>
			</tr>
		{/if}
	</table>

	<table width="100%" cellpadding="3">
		<tr>
			<td width="100%" align="center" colspan="2" class="hd1">
				<strong>{trans("Thanks for using our services!")}</strong>
			</td>
		</tr>
		{if $invoice.division_footer}
			<tr>
				<td width="100%" align="center" colspan="2">
					{$invoice.division_footer|replace:"\n":"<br>"}
				</td>
			</tr>
		{/if}
	</table>

	{if ConfigHelper::checkConfig('invoices.show_memo', true) && $invoice.memo}
		<table width="100%" cellpadding="3">
			<tr>
				<td width="100%" colspan="2">
					<strong>{trans("Memo:")}</strong><br>
					<blockquote>
						{$invoice.memo}
					</blockquote>
				</td>
			</tr>
		</table>
	{/if}

	<!-- The Other Page of Invoice customerbalancelist + customerpin -->
	<!-- insert page break here and buy auto-duplex printer :p -->

	{if ConfigHelper::checkConfig('invoices.customer_credentials', true)}
		{if $invoice.customerpin}
			<br><br>
			<strong>{trans("Customer ID:")} {$invoice.customerid|string_format:"%04d"}</strong><br>
			PIN: <code>{if strlen($invoice.customerpin) < 4}{$invoice.customerpin|string_format:"%04d"}{else}{$invoice.customerpin}{/if}</code>
			<br><br>
		{/if}
	{/if}

	{*
	customer's balance: {$invoice.customerbalancelist.balance}
	*}

	{if $invoice.customerbalancelist.list}
		<table cellpadding="5" cellspacing="0" width="100%">
			<tr>
				<td width="1%" class="fleftu">{trans("Date:")}</td>
				<td width="1%" class="fbt" align="right">{trans("Value:")}</td>
				<td width="1%" class="fbt" align="right">{trans("Tax:")}</td>
				<td width="1%" class="fbt" align="center">&raquo;</td>
				<td width="1%" class="fbt" align="right">{trans("After:")}</td>
				<td width="93%" class="frightu">{trans("Description:")}</td>
			</tr>
			{if $invoice.customerbalancelistlimit >= $invoice.customerbalancelist.total}
				{assign var="startloop" value="0"}
			{else}
				{math assign="startloop" equation="x-y" x=$invoice.customerbalancelist.total y=$invoice.customerbalancelistlimit}
			{/if}
			{section name=balancelist loop=$invoice.customerbalancelist.list start=$startloop max=$invoice.customerbalancelistlimit}
			{* section name=balancelist loop=$invoice.customerbalancelist.list start=$invoice.customerbalancelistlimit step=-1 *}
			{$item=$invoice.customerbalancelist.list[balancelist]}
			<tr>
				<td width="1%" class="nobr">{$item.date}</td>
				<td width="1%" align="right" class="nobr">{if $item.value > 0}+{/if}{moneyf($item.value, $item.currency)}</td>
				<td width="1%" align="right" class="nobr">{$item.tax}</td>
				<td width="1%" align="center">&raquo;</td>
				<td width="1%" align="right" class="nobr">
					{if $item.after < 0}<STRONG>{/if}
						{moneyf($item.after)}
					{if $item.after < 0}</STRONG>{/if}
				</td>
				<td width="93%">{$item.comment}</td>
				</tr>
			{/section}
		</table>
	{/if}
</div>

{if !empty($invoice.div_ccode)}
	{Localisation::resetSystemLanguage()}
{/if}
