<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"/>
<link rel="stylesheet" type="text/css" href="modules/EcmReports/TableSorter/css/theme.blue.css"/>
<link rel="stylesheet" type="text/css" href="modules/EcmReports/TableSorter/css/theme.blue2.css"/>
<!--  Tablesorter -->
<script type="text/javascript" src="modules/EcmReports/TableSorter/js/jquery.min.js"></script>
<script type="text/javascript" src="modules/EcmReports/TableSorter/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="modules/EcmReports/TableSorter/js/jquery.tablesorter.staticrow.min.js"></script>
<script type="text/javascript" src="modules/EcmReports/TableSorter/js/jquery.tablesorter.widgets.js"></script>
<script type="text/javascript" src="modules/EcmReports/javascript/jquery.blockUI.js"></script>


<script type="text/javascript" src="modules/EcmReports/javascript/ReportSales.js"></script>


<style type="text/css">
        {literal}
        
		thead, tfoot {font-weight: bold;}
	
		.additionalColumn {
			background-color: #87CCED;
			border-top: 1px solid black;
		}
		
		.groupActive {
			border-top: 1px solid black;
			border-bottom: 1px solid black;
			border-left: 1px solid black;
			background-color: #87CCED;
		}
		
		.sumRow {
			background-color: #BDC7B5;
		}
                
                .sumAll td{
                    background-color: #BDC7B5;
                }
		
		table.tablesorter tbody tr:hover td {
		  background: #E8E8E8;
		  color: #343432;
		}
				
		/* Extra selectors needed to override the default styling */
		table.tablesorter tbody tr.normal-row td {
		  background: #EFEFF1;
		  color: #343432;
		}
		table.tablesorter tbody tr.alt-row td {
		  background: #FFF;
		  color: #343432;
		}
		
		/* Extra selectors needed to override the default styling */
		table.tablesorter tbody tr.normal-row:hover td {
		  background: #E8E8E8;
		  color: #343432;
		}
		table.tablesorter tbody tr.alt-row:hover td {
		  background: #E8E8E8;
		  color: #343432;
		}
		table.tablesorter tbody tr.sumAll td {
		  background: #EBEBED;
		  color: black;
		}
		table.tablesorter tbody tr.sumAll:hover td {
		  background: #E0E0E2;
		  color: black;
		  font-weight: bold;
		}
			
		table.tablesorter .sumRow, .oddListRowS1 {
			text-align: right;
		}
		
		table.tablesorter .alignLeft {
			text-align: left;
		}
		
		table.tablesorter .subcategory .alignLeft {
			padding-left: 20px;
		}
		
		table.tablesorter .contractor .alignLeft {
			padding-left: 40px;
		}
		
		.plusStyle {
			color: #abc3d7; 
			text-decoration: none; 
			cursor: pointer;
		}
		
		.green-text{
			color:#2E8B57;
		}

	{/literal}
</style>


<table id="tableMenu" cellspacing="0" cellpadding="0" border="0">
<tbody>
	<tr>
		<td>
			<img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16">
		</td>
		<td>
			<h2>{$MOD.LBL_RAPORT_SALES} </h2>
		</td>
	</tr>
</table>

<br />

<ul class="tablist" style="width:100%;">
	<li>
		<a class="current" href="#">Podstawowe wyszukiwanie</a>
	</li>		
</ul>
<form action="index.php" method="get" name="searchReportSales">
	<input type="hidden" name="module" value="EcmReports" />
	<input type="hidden" name="action" value="ReportSales" />
	<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">

	<tr>		
	
	{* Search by date_from *}	
		<td class="dataLabel" width="5%" nowrap="nowrap"> Data od </td>
		<td class="dataField" width="10%" nowrap="nowrap">
		<input id="date_from" name="date_from" type="text" maxlength="10" size="11" tabindex="" title="" value="{$date_from}" autocomplete="off">
		<img id="date_from_trigger" border="0" align="absmiddle" alt="Enter Date" src="themes/default/images/jscalendar.gif">
			<script language="JavaScript" type="text/javascript">
				Calendar.setup ({ldelim}
				inputField : "date_from",
				daFormat : "{$dateFormat}",
				button : "date_from_trigger",
				singleClick : true,
				dateStr : "",
				step : 1
				{rdelim}
				);
			</script>
		</td>
	</td>	
	
	{* Search by date_to *}
	<td class="dataLabel" width="5%" nowrap="nowrap">Data do</td>
	<td class="dataField" width="10%" nowrap="nowrap">
	<input autocomplete="off" name="date_to" id="date_to" value="{$date_to}" title="" tabindex="" size="11" maxlength="10" type="text">
	<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_to_trigger" align="absmiddle" border="0">
			<script language="JavaScript" type="text/javascript">
				Calendar.setup ({ldelim}
				inputField : "date_to",
				daFormat : "{$dateFormat}",
				button : "date_to_trigger",
				singleClick : true,
				dateStr : "",
				step : 1
				{rdelim}
				);
			</script>
	</td>	
        
	<td class="dataLabel" width="5%" nowrap="nowrap">{$MOD.LBL_GORUP_BY}</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select name="groupByProducentsOrProducts">
			<option value="product" { if $searchBy==""} selected="true" {/if} >produkt</option>
			<option value="contractor" { if $searchBy=="contractor"} selected {/if} >kontrahent</option>
			</select>
	  	</td>
        	
				{* Open popup window to select contractor *}
				<script language="JavaScript" type="text/javascript">
					function getContractor(){ldelim}
					open_popup("Accounts", 600, 400, "", true, false, 
								{ldelim}
									  "call_back_function":"set_return","form_name":"searchDailyReports","field_to_name_array":
									  {ldelim}"id":"account_id","name":"account_name"{rdelim}
								{rdelim}, "single", true);
					{rdelim};
				</script>	
	</td>
        <td class="dataLabel" width="5%" nowrap="nowrap">Typ dokumentu</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="type" name="type">
			<option value="%" { if $searchByType=="%"} selected="true" {/if} >normalny i korekta</option>
			<option value="normal" { if $searchByType=="normal"} selected {/if} >normalny</option>
			<option value="correct" { if $searchByType=="correct"} selected {/if} >korekta</option>
			</select>
	  	</td>
		
		<td class="dataLabel" width="5%" nowrap="nowrap">Handlowiec</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="user" name="selectUser">
			<option value="" { if $selectUser==""} selected="true" {/if} >Wszyscy</option>
			{foreach from=$USERS item=USER key=count name=loop}
				<option value="{$USER.id}" { if $selectUser==$USER.id} selected="true" {/if} >{$USER.first} {$USER.last}</option>
			{/foreach}
			</select>
	  	</td>
		
		<td class="dataLabel" width="5%" nowrap="nowrap">Grupa księgowa</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="group_ks" name="group_ks">
				<option value="%">Wszystkie</option>
				{foreach from=$all_groups_ks item=GROUP key=COUNT name=loop}
					<option value="{$COUNT}" { if $group_ks==$COUNT} selected="true" {/if} >{$GROUP}</option>
				{/foreach}
			</select>
	  	</td>
	  	<td class="dataLabel" width="15%" nowrap="nowrap"></td>
	 </tr><tr>
	  	<td class="dataLabel" width="5%" nowrap="nowrap">Typ sprzedaży</td>
		<td class="dataField" width="10%" nowrap="nowrap">
			<select id="pdf_type" name="selectPdfType">
			<option value="" { if $selectedPdfType eq '' } selected="selected" {/if} >Wszystkie</option>
			<option value="K" {if $selectedPdfType eq 'K'} selected="selected" {/if}>Kraj</option>
			<option value="U" {if $selectedPdfType eq 'U'} selected="selected" {/if}>Unia</option>
			<option value="E" {if $selectedPdfType eq 'E'} selected="selected" {/if}>Eksport</option>
			</select>
	  	</td>
		<td class="dataLabel" width="5%" nowrap="nowrap">Twinpol</td>
			<td class="dataField" width="10%" nowrap="nowrap">
			<input type="checkbox" name="twinpol" value="1" {if $twinpol =='1'} checked="checked" {elseif $twinpol == null && $searchByType == null} checked="checked" {/if}>
			</td>
	 </tr>
</tbody>
</table>

<input class="button" name="submit" value="{$MOD.LBL_EXECUTE}" type="submit">
<input class="button" name="clear" value="{$MOD.LBL_CLEAR}" type="button" onclick="location.href='index.php?module=EcmReports&action=ReportSales';">
<input id="excelEksport" class="button" name="importToExcel" value="{$MOD.BTN_EXCEL_EXPORT}" type="button">
<input id="pdfEksport" class="button" name="importToPDF" value="{$MOD.BTN_PDF_EXPORT}" type="button">


<br>
<br>

<table id="myTable" class="tablesorter tablesorter-blue" role="grid">
    <thead>
		<tr class="tablesorter-headerRow" role="row">

            <th width="30%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="0" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_PRODUCTS}</th>
			{if $searchBy=="product"}
				<th width="10%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Indeks</th>
				<th width="5%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Stan</th>
				<th width="5%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Zamówiona ilość</th>
			{/if}
			<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="2" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_SOLD_AMOUNT}</th>
			<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="3" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_VALUE_SALES}</th>
			{*<th width="8%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="4" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Wartość sprzedaży bez korekt</th>*}
			<th width="8%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="5" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_AVERAGE_PRICE}</th>
			<th width="8%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="6" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_COST}</th>
			<th width="8%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="7" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_MARGIN}</th>
			{if $searchBy=="none"}
				<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="8" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_STOCK_STATES}</th>
				<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="9" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_STOCK_VALUE}</th>                
            {/if}   
				</tr>
	</thead>
{foreach from=$DATA item=CAT key=CATNAME name=loop}
    {* Table headers *}
	<tbody id="functions-core" class="tablesorter-infoOnly">
                <tr class="static category">
                 {if $CATNAME != ""}
                 <td class="oddListRowS1 alignLeft	"><a class="plusStyle showTables">[+]</a><b>   {$CATNAME}</b></td>
                 {/if}
				{if $searchBy=="product"}
					<td class="oddListRowS1 alignLeft" ></td>
					<td class="oddListRowS1 alignLeft" ></td>
					<td class="oddListRowS1 alignLeft" ></td>
				{/if}
                 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.IloscSum|number_format:0:",":"." }</b></td>
                 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.SoldSum|number_format:2:",":"." }</b></td>
				{* <td class="oddListRowS1 sumRow" ><b><span class='green-text'>{$DATA.$CATNAME.SoldSumNormal|number_format:2:",":"." }</span></b></td>*}
                 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.SredniaSum|number_format:2:",":"." }</b></td>
                 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.KosztSum|number_format:2:",":"." }</b></td>
                 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.MarzaSum|number_format:2:",":"." }%</b></td>
				 {if $searchBy=="none"}
					 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.StanSum|number_format:0:",":"." }</b></td>
					 <td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.WartoscSum|number_format:2:",":"." }</b></td>   
				 {/if}
                </tr>
        </tbody>
         {foreach from=$CAT item=CAT2 key=CAT2NAME name=loop}
             {if $CAT2NAME!="IloscSum" && $CAT2NAME!="SoldSum" && $CAT2NAME!="SoldSumNormal" && $CAT2NAME!="IloscNormal" && $CAT2NAME!="SredniaSum" && $CAT2NAME!="KosztSum" && $CAT2NAME!="MarzaSum" && $CAT2NAME!="StanSum" && $CAT2NAME!="WartoscSum"}
                    <tbody id="functions-core" class="tablesorter-infoOnly tablesShowHide">
                    <tr class="subcategory">
                        <td class="oddListRowS1 alignLeft"><a class="showRows" style="color: cadetblue; text-decoration: none; cursor: pointer;">[+]</a><b> {$CAT2NAME}</b></td>
						{if $searchBy=="product"}
							<td class="oddListRowS1 alignLeft" ></td>
							<td class="oddListRowS1 alignLeft" ></td>
							<td class="oddListRowS1 alignLeft" ></td>
						{/if}
                          <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.IloscSum2|number_format:0:",":"." }</b></td>
                          <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SoldSum2|number_format:2:",":"." }</b></td>
                          {*<td class="oddListRowS1 sumRow" ><b><span class='green-text'>{$CAT.$CAT2NAME.SoldSumNormal2|number_format:2:",":"." }</span></b></td>*}
						  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SredniaSum2|number_format:2:",":"." }</b></td>
                          <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.KosztSum2|number_format:2:",":"." }</b></td>
                          <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.MarzaSum2|number_format:2:",":"." }%</b></td>					  
                    </tr>
                    </tbody>

                   <tbody aria-live="polite" aria-relevant="all" class="rowShowHide">
                   {foreach from=$CAT2 item=ROW name=loop}
                       {if $ROW.name!="IloscSum" && $ROW.name!="SoldSum" && $ROW.name!="SredniaSum" && $ROW.name!="KosztSum" && $ROW.name!="MarzaSum" && $CAT2NAME!="StanSum" && $CAT2NAME!="WartoscSum" && $ROW.name!=""}
                               {if $smarty.foreach.loop.index % 2 == 1} 
                                   <tr role="row" class="contractor">
                               {else} 
                                   <tr class="contractor" role="row"> 
                               {/if}
							   
                               {if $searchBy=="contractor"}
                                   <td class="oddListRowS1 alignLeft" style="text-align:left;">
											{if $CAT2NAME!="Reszta"}
												<img category="{$CATNAME}" subcategory="{$CAT2NAME}" class="showProducts" style="color: graytext; text-decoration: none; cursor: pointer;" src="modules/EcmReports/images/search.gif" />
											{/if}
                                           <a href="index.php?module=Accounts&return_module=Accounts&action=DetailView&record={if $ROW.name != 'Media Saturn Holding'}{$ROW.parent_id}{else}1249{/if}" {if $ROW.name != 'Media Saturn Holding' }contractor="{$ROW.parent_id}"{else} contractor="1249" {/if} target="new">{$ROW.name}</a>
                                   </td>

                               {else} 
                                   <td class="oddListRowS1 alignLeft" style="text-align:left;">
                               		   <img src="modules/EcmReports/images/search.gif" class="showContractors" style="color: graytext; text-decoration: none; cursor: pointer;" data-productid="{$ROW.id}" />
                                       <a target="new" href="index.php?module=EcmProducts&action=index&return_module=EcmProducts&action=DetailView&record={$ROW.id}">
                                       {$ROW.name}
                                       </a>
                                   </td>
                               {/if}
								   {if $searchBy=="product"}
										<td class="oddListRowS1 alignLeft" >{$ROW.code}</td>
										<td class="oddListRowS1 alignRight" >{$ROW.state}</td>
										<td class="oddListRowS1 alignRight" >{$ROW.ordered_quantity}</td>
								   {/if}
                                   <td class="oddListRowS1" >{$ROW.ilosc|number_format:0:",":"."}</td>
                                   <td class="oddListRowS1" >{$ROW.netto|number_format:2:",":"."}</td>
								 {*  <td class="oddListRowS1" ><span class='green-text'>{$ROW.nettoNormal|number_format:2:",":"." }</span></td>*}
                                   <td class="oddListRowS1" >{$ROW.srednia|number_format:2:",":"."}</td>
                                   <td class="oddListRowS1" >{$ROW.koszt|number_format:2:",":"."}</td>
                                   <td class="oddListRowS1" >{$ROW.marza|number_format:2:",":"."}%</td>
                                 </tr>
                         {/if}
                     {/foreach} 
                     </tbody>
                     <tbody id="stopRows"></tbody>
              {/if}
         {/foreach} 
         <tbody id="stopTables"></tbody>
{/foreach}
    <tbody id="functions-core" class="tablesorter-infoOnly">
        <tr class="static category sumAll">
         <td class="oddListRowS1 alignLeft"><b>{$MOD.LBL_SUM}:</b></td>
		 {if $searchBy=="product"}
			<td class="oddListRowS1" ></td>
			<td class="oddListRowS1" ></td>
			<td class="oddListRowS1" ></td>
		{/if}
         <td class="oddListRowS1 sumRow" ><b>{$SUM.IloscSumSum|number_format:0:",":"." }</b></td>
         <td class="oddListRowS1 sumRow" ><b>{$SUM.SoldSumSum|number_format:2:",":"." }</b></td>
		{* <td class="oddListRowS1 sumRow" ><b><span class='green-text'>{$SUM.SoldSumSumNormal|number_format:2:",":"." }</span></b></td>*}
         <td class="oddListRowS1 sumRow" ><b>{$SUM.SredniaSumSum|number_format:2:",":"." }</b></td>
         <td class="oddListRowS1 sumRow" ><b>{$SUM.KosztSumSum|number_format:2:",":"." }</b></td>
         <td class="oddListRowS1 sumRow" ><b>{$SUM.MarzaSumSum|number_format:2:",":"." }%</b></td>
        </tr>
    </tbody>
  </table>            


<br/>