{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>
{if $receipt.receipt}
<SCRIPT type="text/javascript">window.open('?m=receipt&id={$receipt.receipt}&which={$receipt.which}');</SCRIPT>
{/if}
{if $receipt.receipt2}
<SCRIPT type="text/javascript">window.open('?m=receipt&id={$receipt.receipt2}&which={$receipt.which}');</SCRIPT>
{/if}
<SCRIPT type="text/javascript">
<!--
	function prints()
	{
		var which = 0;
		$('form[name="page"] [name^="which"]:checked').each(function() {
			which += parseInt($(this).val());
		});

		document.page.action = "?m=receipt&print=cached&which=" + which;
		document.page.target = "_blank";
		document.page.submit();
	}

	function filter()
	{
		document.page.action="?m=receiptlist";
		document.page.target="";
		document.page.submit();
	}

{if ConfigHelper::checkConfig('phpui.short_pagescroller')}
	function pagechange1()
	{
		document.page.action="?m=receiptlist&page=" + document.forms['page'].elements['page1'].value;
		document.page.target="";
		document.page.submit();
	}

	function pagechange2()
	{
		document.page.action="?m=receiptlist&page=" + document.forms['page'].elements['page2'].value;
		document.page.target="";
		document.page.submit();
	}
{/if}
//-->
</SCRIPT>
{$default_printpage = ConfigHelper::getConfig('receipts.default_printpage')}
<FORM METHOD="POST" NAME="page" id="receiptlist">
<INPUT type="submit" class="hiddenbtn">
<TABLE class="lmsbox lms-ui-background-cycle">
    <THEAD>
	<TR>
		<TD WIDTH="1%" nowrap>
			<A href="?m=receiptlist&o=cdate{if $listdata.direction == "asc" && $listdata.order == "cdate"},desc{/if}">{trans("Date:")}</A> {if $listdata.order == "cdate"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}<BR>
			<A href="?m=receiptlist&o=user{if $listdata.direction == "asc" && $listdata.order == "user"},desc{/if}">{trans("User:")}</A> {if $listdata.order == "user"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD WIDTH="1%" nowrap>
			<A href="?m=receiptlist&o=number{if $listdata.direction == "asc" && $listdata.order == "number"},desc{/if}">{trans("Number:")}</A> {if $listdata.order == "number"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD WIDTH="1%" nowrap>
			{trans("Income:")}
		</TD>
		<TD WIDTH="1%" nowrap>
			{trans("Expense:")}
		</TD>
		<TD WIDTH="40%" nowrap>
			<A href="?m=receiptlist&o=name{if $listdata.direction == "asc" && $listdata.order == "name"},desc{/if}">{trans("For:")}</A> {if $listdata.order == "name"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD WIDTH="50%" nowrap>
			{trans("Positions:")}
		</TD>
		<TD WIDTH="1%" class="text-right nobr">
			<A href="?m=receiptadd&type=in&action=init&regid={$listdata.regid}">{trans("New Cash-in Receipt")} <img src="img/save.gif" alt=""></A><BR>
			<A href="?m=receiptadd&type=out&action=init&regid={$listdata.regid}">{trans("New Cash-out Receipt")} <img src="img/save.gif" alt=""></A>
		</TD>
	</TR>
	<TR>
		<TD colspan="7">
				<B>{trans("Filter:")} </B>
				<INPUT name="search" type="text" value="{$listdata.search}" size="15" {tip text="Enter value of searching data and select category"}>&nbsp;
				<SELECT size="1" name="cat">
					<OPTION value=""{if $listdata.cat == ""} SELECTED{/if}>{trans("— select filter —")}</OPTION>
					<OPTION value="number"{if $listdata.cat == "number"} SELECTED{/if}>{trans("number")}</OPTION>
					<OPTION value="value"{if $listdata.cat == "value"} SELECTED{/if}>{trans("value")}</OPTION>
					<OPTION value="name"{if $listdata.cat == "name"} SELECTED{/if}>{trans("customer name")}</OPTION>
					<OPTION value="customerid"{if $listdata.cat == "customerid"} SELECTED{/if}>{trans("customer ID")}</OPTION>
					<OPTION value="ten"{if $listdata.cat == "ten"} SELECTED{/if}>{trans("TEN")}</OPTION>
					<OPTION value="address"{if $listdata.cat == "address"} SELECTED{/if}>{trans("address")}</OPTION>
					<OPTION value="positions"{if $listdata.cat == "positions"} SELECTED{/if}>{trans("Positions")}</OPTION>
				</SELECT>&nbsp;
				<span class="lms-ui-date-period-container">
					<strong>{trans("Period:")}</strong>&nbsp;
					{date_period_preset from="#receiptlist [name=\"from\"]" to="#receiptlist [name=\"to\"]"}
					<span>{trans("from")}</span>
					<input type="text" name="from" size="10" maxlength="10"
						value="{if $listdata.from > 0}{$listdata.from|date_format:"Y/m/d"}{/if}"
						placeholder="{trans("yyyy/mm/dd")}"
						{tip class="lms-ui-date" text="Enter date in YYYY/MM/DD format (empty field means no limit) or click to choose it from calendar"}>
					<span>{trans("to")}</span>
					<input type="text" name="to" size="10" maxlength="10"
						value="{if $listdata.to > 0}{$listdata.to|date_format:"Y/m/d"}{/if}"
						placeholder="{trans("yyyy/mm/dd")}"
						{tip class="lms-ui-date" text="Enter date in YYYY/MM/DD format (empty field means no limit) or click to choose it from calendar"}>&nbsp;
				</span>
				<input type="hidden" name="advances" value="0">
				<label>
					<INPUT type="checkbox" name="advances" value="1"{if $listdata.advances} checked{/if}>{trans("not settled adv. only")}
				</label>&nbsp;
				<A href="javascript: filter();">&raquo;&raquo;&raquo;</A>
		</TD>
	</TR>
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="7">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
    </THEAD>
    <TBODY class="lms-ui-multi-check">
	{foreach $receiptlist as $receipt}
	{assign var=receiptid value=$receipt.id}
	<TR class="highlight" data-name="{$receipt.number}">
		<TD WIDTH="1%" NOWRAP><A id="{$receipt.id}"></A>
			{if !$receipt.closed}<span class="lms-ui-alert">{/if}
			{$receipt.cdate|date_format:"Y-m-d H:i"}<BR>
			{$receipt.user|truncate:"16":"&hellip;":true}
			{if !$receipt.closed}</span>{/if}
		</TD>
		<TD WIDTH="1%" NOWRAP align="right"{if !$receipt.closed} class="lms-ui-alert"{/if}>
			{$receipt.number}
		</TD>
		<TD WIDTH="1%" NOWRAP ALIGN="RIGHT"{if !$receipt.closed} class="lms-ui-alert"{/if}>
			{if $receipt.value > 0}{moneyf($receipt.value, $receipt.currency)}{else}-{/if}
		</TD>
		<TD WIDTH="1%" NOWRAP ALIGN="RIGHT"{if !$receipt.closed} class="lms-ui-alert"{/if}>
			{if $receipt.value < 0}{moneyf($receipt.value*-1, $receipt.currency)}{else}-{/if}
		</TD>
		<TD WIDTH="45%"{if !$receipt.closed} class="lms-ui-alert"{/if}>
			{if $receipt.customerid}<A HREF="?m=customerinfo&id={$receipt.customerid}">{/if}
			{$receipt.customer|truncate:"60":"&hellip;":true}
			{if $receipt.customerid}</A>{/if}
		</TD>
		<TD WIDTH="50%"{if !$receipt.closed} class="lms-ui-alert"{/if}>
			{foreach $receipt.positions as $position}
				{$position.description|truncate:"80":"&hellip;":true}
				({moneyf($position.value, $receipt.currency)})
				{if !$position@last}<br>{/if}
			{/foreach}
		</TD>
		<TD WIDTH="1%" ALIGN="RIGHT" NOWRAP>
			{if !$receipt.closed}
			<A HREF="?m=receiptadv&id={$receipt.id}"><IMG SRC="img/eraser.gif" alt="{trans("Settle advance")}" title="{trans("Settle advance")}"></A>
			{/if}
			<A class="delete-receipt" HREF="?m=receiptdel&id={$receipt.id}"><IMG SRC="img/delete.gif" alt="{trans("Delete")}" title="{trans("Delete")}"></A>
			<A HREF="?m=receiptedit&id={$receipt.id}"><IMG SRC="img/edit.gif" alt="{trans("Edit")}" title="{trans("Edit")}"></A>
			<A HREF="?m=receipt&id={$receipt.id}" TARGET="_blank"><IMG src="img/printr.gif" alt="{trans("Print")}" title="{trans("Print")}"></A>
			<INPUT TYPE="checkbox" NAME="marks[{$receipt.id}]" VALUE="{$receipt.id}" class="lms-ui-multi-check"{if $marks.$receiptid} checked{/if}>
		</TD>
	</TR>
	{foreachelse}
	<tr>
		<td colspan="7" class="empty-table">
			{trans("No such receipts in database.")}
		</td>
	</tr>
	{/foreach}
    </TBODY>
    <TFOOT>
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="7">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
	<TR>
		<TD COLSPAN="7">
			<TABLE WIDTH="100%">
				<TR>
					<TD ALIGN="left" nowrap>
						<A HREF="javascript:prints();">{trans("Print")} <IMG SRC="img/printr.gif" ALT="" ></A>&nbsp;
						 <label>
							<INPUT type="checkbox" name="which[{$smarty.const.DOC_ENTITY_ORIGINAL}]"
									value="{$smarty.const.DOC_ENTITY_ORIGINAL}"
									{if preg_match('/original/i', $default_printpage)} checked{/if}>
							{$_DOCENTITIES[$smarty.const.DOC_ENTITY_ORIGINAL]}
						</label>
						<label>
							<INPUT type="checkbox" name="which[{$smarty.const.DOC_ENTITY_COPY}]"
									value="{$smarty.const.DOC_ENTITY_COPY}"
									{if preg_match('/copy/i', $default_printpage)} checked{/if}>
							{$_DOCENTITIES[$smarty.const.DOC_ENTITY_COPY]}
						</label>
					</TD>
					<TD class="text-right nobr">
						<label>
							{trans("Check All")}
							<INPUT TYPE="checkbox" NAME="allbox" class="lms-ui-multi-check-all" VALUE="1">
						</label>
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
        <TR>
		<TD colspan="2" align="right" NOWRAP style="vertical-align: top;">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_summaries')}
			<B>{trans("Total:")}</B><HR>
			<B>{trans("Initial balance:")}</B><BR>
			<B>{trans("Final balance:")}</B><BR>
			{/if}
		</TD>
		<TD class="nobr text-right valign-top">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_summaries')}
			{moneyf($listdata.totalincome)}<HR>
			{moneyf($listdata.startbalance)}<BR>
			{moneyf($listdata.endbalance)}
			{/if}
		</TD>
		<TD nowrap align="right" style="vertical-align: top;">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_summaries')}
			{moneyf($listdata.totalexpense)}<HR>
			{/if}
		</TD>
		<TD colspan="3" align="right">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_summaries')}
			<H1>{trans("Cash state:")} <B>{moneyf($listdata.cashstate)}</B></H1>{/if}
			<A href="?m=cashreglogview&regid={$listdata.regid}">{trans("Cash history")} <img src="img/value.gif" alt=""></A>&nbsp;
			<A href="?m=receiptadd&type=in&action=init&regid={$listdata.regid}"><img src="img/kp.png" alt=""> {trans("New Cash-in Receipt")}</A>&nbsp;
			<A href="?m=receiptadd&type=out&action=init&regid={$listdata.regid}"><img src="img/kw.png" alt=""> {trans("New Cash-out Receipt")}</A>
		</TD>
	</TR>
    </TFOOT>
</TABLE>
</FORM>
{if $logentry}
<P>
<TABLE WIDTH="100%" CELLPADDING="3">
	<TR>
		<TD WIDTH="1%" nowrap>
			<IMG SRC="img/time.gif" ALT=""> <B>{trans("Cash History Last Entry:")}</B>
		</TD>
		<TD WIDTH="1%" nowrap>
			{$logentry.time|date_format:"Y-m-d H:i"} &nbsp;
			<B>
			{if $logentry.value<0}<span class="lms-ui-alert">{/if}{$logentry.value|money_format}{if $logentry.value<0}</span>{/if}
			<span class="blend">({trans("Cash state:")} {$logentry.snapshot|money_format})</span> &nbsp;
			</B>
		</TD>
		<TD WIDTH="98%" nowrap>
			{$logentry.description}
		</TD>
	</TR>
</TABLE>
</P>
{/if}
	<script>
		$('.delete-receipt').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove receipt '$a' from database?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
	</script>
{/block}
