{extends file=$smarty.const.SMARTY_LAYOUT_CONTENT_LIST_TABLE_CURRENT_DATA}

{block name="listing-tr-class"}
	{if $rowFields['status']=='blocked'}disabled{/if}
{/block}

{block name="listing-td-idExternalSystem"}
	<td
		{if $rowFields['systemStatus']=='cancelled' and ($rowFields['status']=='partial' or $rowFields['status']=='processed' or $rowFields['status']=='stopped')}
			class="flag-Red"
		{/if}
	>
		<div>
			{importedDocumentsSystemLabel ref=$rowFields['idExternalSystem'] format="%name%"}
		</div>
		<div class="systemStatus">
			<span class="systemStatus systemStatus-{$rowFields['systemStatus']}">{$rowFields['systemStatus']}</span>

			{if $rowFields['systemStatus']=='cancelled' and ($rowFields['status']=='partial' or $rowFields['status']=='processed' or $rowFields['status']=='stopped')}
				<div class="info">
					<a class="icon-infoBlue"
						tooltip="{$lang['index']['listCols']['docCancelledTooltip']}"
					></a>
				</div>
			{/if}
		</div>
	</td>
{/block}

{block name="listing-td-content-agencyBankAccount"}
	{if $rowFields['idAgencyBankAccount']}
		<div>{\Entity\AgencyBankAccount::select($rowFields['idAgencyBankAccount'])->account}</div>
		<div>[{bankLabel ref=\Entity\AgencyBankAccount::select($rowFields['idAgencyBankAccount'])->idBank}]</div>
	{/if}
{/block}

{block name="listing-td-content-status"}
	<div class="status">
		<span>
			{$lang['index']['status'][$rowFields['status']]}
		</span>
	</div>
{/block}

{block name="listing-td-content-docType"}
	{if $rowFields['docCategory'] == 'cashing'}
		{\App\Config\CashingDocuments::getInstance()->getName($rowFields['docType'])}
	{else}
		{\App\Config\PaymentDocuments::getInstance()->getName($rowFields['docType'])}
	{/if}

	<span style="float:right; padding-right:5%;">
		[{$rowFields['docCategory']}]
	</span>
{/block}

{block name="listing-td-content-docNumber"}
	{if $rowFields['docNumber']}
		{$rowFields['docNumber']}
	{/if}
{/block}

{block name="listing-td-content-partner"}
	{if $rowFields['idCorporate']}
		{corporateLabel ref=$rowFields['idCorporate']}
		<span style="float:right; padding-right:5%;">
			[{$lang['index']['listCols']['corporate']}]
		</span>
	{elseif $rowFields['idCustomer']}
		{customerLabel ref=$rowFields['idCustomer']}
		<span style="float:right; padding-right:5%;">
			[{$lang['index']['listCols']['customer']}]
		</span>
	{elseif $rowFields['idSupplier']}
		{supplierLabel ref=$rowFields['idSupplier']}
		<span style="float:right; padding-right:5%;">
			[{$lang['index']['listCols']['supplier']}]
		</span>
	{/if}
{/block}

{block name="listing-td-content-docValue"}

	{$percent=0}
	{if $rowFields['status']!='new' and $rowFields['docValue']!=0}
		{$percent=$rowFields['usedValue']/$rowFields['docValue']}
	{/if}

	{if $percent>0.99 and $percent<1}
		{$percent=0.99}
	{elseif $percent<0.01 and $percent>0}
		{$percent=0.01}
	{/if}


	<div style="text-align: right" class="value">
		<b>
			<span
				{if $rowFields['docValue']<0}
					class="value-negative"
				{/if}
			>
				{if $rowFields['status']=='stopped' or $rowFields['status']=='partial'}
					{$rowFields['usedValue']|priceFormat:$rowFields['docCurrency']} / {$rowFields['docValue']|priceFormat:$rowFields['docCurrency']}
				{else}
					{$rowFields['docValue']|priceFormat:$rowFields['docCurrency']}
				{/if}
			</span>
		</b>
	</div>

	{if $rowFields['status']=='partial' or $rowFields['status']=='stopped'}
		{$tooltip=sprintf($lang['index']['tooltip']['processMessage'], {$rowFields['docValue']|priceFormat:$rowFields['docCurrency']}, {$rowFields['usedValue']|priceFormat:$rowFields['docCurrency']}, {($rowFields['docValue']-$rowFields['usedValue'])|priceFormat:$rowFields['docCurrency']})}
	{else}
		{$tooltip=''}
	{/if}
	{progressbar value=$percent label=sprintf("%s%%", round($percent*100)) tooltip=$tooltip}

{/block}

{block name="listing-td-content-id"}
	<div class='date'>
		{$rowFields['addTime']|dateTimeFormat:'dateWithHMS'}
	</div>
	<div>
		[{importedDocumentLabel ref=$rowFields['id']}]
	</div>
{/block}

{block name="listing-td-content-issued"}
	{if $rowFields['issueTime']}
		<div>
			<var class="icon-info" tooltip={strip}"
				<div><b>{$lang['index']['list']['issuedDate']}</b>: {$rowFields['issueTime']|dateTimeFormat:'dateWithHMS'}</div>
				<div><b>{$lang['index']['list']['issuedUser']}</b>: {userLabel ref=$rowFields['idIssueUser'] hideLink="1" default="-"}</div>
			"{/strip}>
			</var>
			{$lang['index']['list']['issuedFlag']}
		</div>
	{/if}
{/block}
