<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.css"/>
<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css"/>
<script type="text/javascript" src="include/jQuery/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.js"></script>
<script type="text/javascript" src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>
<script type="text/javascript" src="include/jQuery/tablesorter/jquery.tablesorter.js"></script>
<script type="text/javascript" src="include/jQuery/html-table-search.js"></script>
<script type="text/javascript" src="modules/EcmPaymentStates/javascript/summary.js"></script>


<script>
{literal}
$(document).ready(function() 
	    { 
	  /*   $('table.search-table').tableSearch({
	searchText:'Szukaj',
	searchPlaceHolder:'Kontrahent'
});*/
	    } 
	); 
{/literal}
	</script>
<style type="text/css">

	{literal}
			.line {
			border-top: 1px solid black !important;;
		}
	thead, tfoot {font-weight: bold;}
	tr
	{
	    line-height:20px;
	}
		/* Extra selectors needed to override the default styling */

		/* Extra selectors needed to override the default styling */
		table.tablesorter tbody tr:hover td {
		  background: #A8E8E8;
		  color: #343432;
		}

	{/literal}
</style>


<table cellspacing="0" cellpadding="0" border="0">
	<tr>
		<td><h2>Rozrachunki: Salda</h2></td>
	</tr>
</table>
<form action="index.php" method="post" name="searchForm">
	<input type="hidden" name="module" value="EcmPaymentStates" />
	<input type="hidden" name="action" value="summaryNew" />
	<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
	<tr>	
		<td class="dataLabel" width="10%" nowrap="nowrap">Rodzaj Kontrahenta</td>
		<td class="dataField" width="10%" nowrap="nowrap">
		
		    {if $account_type === '' }
        {html_options name=account_type id=account_type options=$account_type_list selected='a'  }
    {else}
        {html_options name=account_type id=account_type options=$account_type_list selected=$account_type}
    {/if}

		</td>
		<td class="dataLabel" width="10%" nowrap="nowrap">Saldo</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="saldo_type" name="saldo_type">
				<option value="" {if $saldo_type eq ''} selected {/if}>Wszystkie</option>
				<option value="plus" {if $saldo_type eq 'plus'} selected {/if}>Dodatnie</option>
				<option value="minus" {if $saldo_type eq 'minus'} selected {/if}>Ujemne</option>
				<option value="zero" {if $saldo_type eq 'zero'} selected {/if}>Zerowe</option>
			</select>

		</td>
				<!-- <td class="dataLabel" width="10%" nowrap="nowrap">Saldo na dzień:</td>
		<td class="dataField" width="10%" nowrap="nowrap">
					<input placeholder="data" autocomplete="off" type="text" name="saldo_date_val" id="saldo_date_val" value="{$saldo_date_val}" title="" tabindex="" size="10" maxlength="10">
			<img border="0" src="themes/Sugar5/images/jscalendar.gif?s=bed8cd35065048ceebdc639ebe305e2c&amp;c=1" alt="Wprowadź datę" id="saldo_date" align="absmiddle">
<script type="text/javascript">
{literal}
Calendar.setup ({
inputField : "saldo_date_val",
daFormat : "%d.%m.%Y",
button : "saldo_date",
singleClick : true,
dateStr : "",
step : 1,
weekNumbers:false
}
);
function generateString(){
    var text= new Array();
    $('input[name^="accounts_xls_id"]').each(function() {
        if($(this).val()!=''){
            text.push('accounts_xls_id[]='+$(this).val());
        }
});
    return  text.join("&");
}
function isDate(txtDate)
{
    var currVal = txtDate;
    if(currVal == '')
        return true;
    
    var rxDatePattern = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; //Declare Regex
    var dtArray = currVal.match(rxDatePattern); // is format OK?
    
    if (dtArray == null) 
        return false;
    
    //Checks for dd/mm/yyyy
    dtMonth = dtArray[3];
    dtDay= dtArray[1];
    dtYear = dtArray[5];        
    
    if (dtMonth < 1 || dtMonth > 12) 
        return false;
    else if (dtDay < 1 || dtDay> 31) 
        return false;
    else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31) 
        return false;
    else if (dtMonth == 2) 
    {
        var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
        if (dtDay> 29 || (dtDay ==29 && !isleap)) 
                return false;
    }
    return true;
}
$(document).ready(function() {
var options =  { 
  onComplete: function(cep) {
       if(isDate(cep))
           $('#saldo_date_val').css("color", "");
        else
             $('#saldo_date_val').css("color", "red");
    return;
  },
  'translation': {
                                        A: {pattern: /[0-3]/}, 
                                        B: {pattern: /[0-9]/}, 
                                        C: {pattern: /[0-1]/},  
                                        D: {pattern: /[0-9]/}, 
                                        Y: {pattern: /[0-9]/}
                                      },
                                      selectOnFocus: true
};
 $('#saldo_date_val').mask('AB.CD.YYYY', options);
});
{/literal}
</script></td> -->
			 <!--<td class="dataLabel" width="10%" nowrap="nowrap">Typ</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="type2" name="type2">
			<option value="" {if $type eq ''} selected {/if}>Wszyscy</option>
			{foreach from=$type2 item=i key=vv}
				{if $vv==$type}
			
					{assign var="ss" value="selected"}
				{else}
					{assign var="ss" value=""}
				{/if}
				<option value="{$vv}" {$ss}>{$i}</option>
			{/foreach}
			</select>
			
		</td> -->
			<!--<td class="dataLabel" width="10%" nowrap="nowrap">Użytkownik</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="user_id" name="user_id">
			<option value="" {if $type eq ''} selected {/if}>Wszyscy</option>
			{foreach from=$users item=i key=vv}
				{if $vv==$user_id}
			
					{assign var="ss" value="selected"}
				{else}
					{assign var="ss" value=""}
				{/if}
				<option value="{$vv}" {$ss}>{$i}</option>
			{/foreach}
			</select>
			
		</td>-->
		<td class="dataLabel" width="10%" nowrap="nowrap"><input class="button" name="submit" value="Wykonaj" type="submit"></td>
	</tr>   
</tbody>
</table>
</form>
<input type="button" value="PDF" id="productcard" name="productcard" onclick="{literal}if($('#div_pdf').css('display') == 'none'){$('#div_pdf').show('slow'); } else { $('#div_pdf').hide('slow'); }{/literal}" class="button" title="PDF">

<input type="button" value="XLS" id="productcard" name="productcard" onclick='{literal}window.open("index.php?to_pdf=1&module=Home&action=Export&settings="+generateString());{/literal}' class="button" title="XLS">
<div style="display:none;border: 1px solid rgb(204, 204, 204); background: rgb(230, 230, 230) none repeat scroll 0% 0%; padding: 5px; position: absolute;" id="div_pdf">
<form method="POST"  target="_blank"
 action="index.php?module=EcmPaymentStates&to_pdf=1&action=rap">
<fieldset id="CreatePDF"><legend>Ustawienia PDF</legend>Typ&nbsp;<select name="pdf_type" id="pdf_type"><option value="0">Salda</option>
<option value="1">Salda z rozbiciem</option></select><br></fieldset>


 <input type="hidden" name="idToPdf" value="{$idToPdf}">
 <input type="hidden" name="type" value="{$saldo_type}">
 <input type="hidden" name='title' value="Rozrachunki z{if $account_type eq 'rec'} Odbiorcami {/if}{if $account_type eq 'sup'} Dostawcami {/if}{if $account_type eq 'rs'} Odbiorca/Dostawca {/if} - salda {if $saldo_type eq ''} wszystki {/if}{if $saldo_type eq 'plus'} dodatnie {/if}{if $saldo_type eq 'minus'} ujemne {/if}
 ">
 <input type="submit" name="submit" value="PDF">
 </form>
 </div>
<table cellpadding="0" cellspacing="0" border="0" class="tablesorter tablesorter-blue search-table" style="width:100%;" id="myTable">
<thead>
<tr>
<th class="oddListRowS1" style="text-align:left; width: 10%">

<p style="cursor: pointer;">Index
{if $SORT.index == 'asc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_down.gif">
{elseif $SORT.index == 'desc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_up.gif">
{else} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow.gif">
{/if}
</p>
</th>
<th class="oddListRowS1" style="text-align:left; width: 38%">
<p style="cursor: pointer;">{$MOD.LBL_SUMMARY_ACCOUNT}
{if $SORT.account == 'asc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_down.gif">
{elseif $SORT.account == 'desc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_up.gif">
{else} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow.gif">
{/if}
</p>
</th>

<th class="oddListRowS1" style="text-align:right; width: 10%">
<p style="cursor: pointer;">Saldo
{if $SORT.saldo == 'asc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_down.gif">
{elseif $SORT.saldo == 'desc'} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow_up.gif">
{else} 
<img width="8" height="10" border="0" align="absmiddle" alt="Sortuj" src="themes/Sugar5/images/arrow.gif">
{/if}
</p>
</th>


<th class="oddListRowS1" style="text-align:right; width: 7%;">{$MOD.LBL_SUMMARY_OVERDUE_1_30}</th>
<th class="oddListRowS1" style="text-align:right; width: 7%;">{$MOD.LBL_SUMMARY_OVERDUE_31_60}</th>
<th class="oddListRowS1" style="text-align:right; width: 7%;">{$MOD.LBL_SUMMARY_OVERDUE_61_90}</th>
<th class="oddListRowS1" style="text-align:right; width: 7%;">{$MOD.LBL_SUMMARY_OVERDUE_91_180}</th>
<th class="oddListRowS1" style="text-align:right; width: 7%;"">{$MOD.LBL_SUMMARY_OVERDUE_181}</th>
</tr>
</thead>
<tbody>
{foreach from=$DATA item=ROW name=loop}
{if $smarty.foreach.loop.index % 2 == 1} 
	<tr>
{else} 
	<tr style="background-color: #e6e6e6;"> 
{/if}
<td class="oddListRowS1" style="text-align:left;">
<input type="hidden" value="{$ROW.index}" name="accounts_xls_id[]">
{$ROW.index}

</td>

<td class="oddListRowS1" style="text-align:left;">
<input type="hidden" value="{$ROW.id}" name="accounts_xls_id[]">
<a target='_blank' href="index.php?module=EcmPaymentStates&action=AccountPaymentStates&return_module=EcmPaymentStates&return_action=DetailView&parentTab=Rozrachunki&account_id={$ROW.id}">
{$ROW.name}
</a>
</td>
<td class="oddListRowS1" data-sort-value="{$ROW.saldo}" style="text-align:right;">{$ROW.saldo|number_format:2:",":"."} {$ROW.currency_id}</td>
<!--<td class="oddListRowS1" data-sort-value="{$ROW.today_saldo}" style="text-align:right;">{$ROW.today_saldo|number_format:2:",":"."} {$ROW.currency_id}</td>
--><td class="oddListRowS1" data-sort-value="{$ROW.2}" style="text-align:right;">{$ROW.2|number_format:2:",":"."} {$ROW.currency_id}</td>
<td class="oddListRowS1" data-sort-value="{$ROW.3}" style="text-align:right;">{$ROW.3|number_format:2:",":"."} {$ROW.currency_id}</td>
<td class="oddListRowS1" data-sort-value="{$ROW.4}" style="text-align:right;">{$ROW.4|number_format:2:",":"."} {$ROW.currency_id}</td>
<td class="oddListRowS1" data-sort-value="{$ROW.5}" style="text-align:right;">{$ROW.5|number_format:2:",":"."} {$ROW.currency_id}</td>
<td class="oddListRowS1" data-sort-value="{$ROW.6}" style="text-align:right;">{$ROW.6|number_format:2:",":"."} {$ROW.currency_id}</td>
</tr>

<tr id="details_{$ROW.id}" style="border-collapse: collapse; display:none;">
</tr>
{/foreach}
</tbody>
					       <tr>
         <td class='line'></td>
         <td class='line'></td>
                  <td class='line'></td>
         <td class='line'></td>
                 <td class='line'></td>
         <td class='line'></td>
                  <td class='line'></td>
                           <td class='line'></td>
        </tr>
{foreach from=$SUM key="key" item="item" name=loop}
<tfoot>
<td class="oddListRowS1" style="text-align:left;">Razem:</td>
<td class="oddListRowS1" style="text-align:left;"></td>
<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.saldo|number_format:2:",":"."} {$SUM.$key.currency_id}</td>

<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.2|number_format:2:",":"."} {$SUM.$key.currency_id}</td>
<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.3|number_format:2:",":"."} {$SUM.$key.currency_id}</td>
<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.4|number_format:2:",":"."} {$SUM.$key.currency_id}</td>
<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.5|number_format:2:",":"."} {$SUM.$key.currency_id}</td>
<td class="oddListRowS1" style="text-align:right;">{$SUM.$key.6|number_format:2:",":"."} {$SUM.$key.currency_id}</td>
</tr>
<tfoot>
{/foreach}
</table>