<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/ReportSalesByContractor.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;
		}
		
		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 .alignLeft {
			text-align: left;
		}
		
		table.tablesorter .sumRow, .oddListRowS1 {
			text-align: right;
		}
		
		table.tablesorter .subcategory .alignLeft {
			padding-left: 20px;
		}
                
        table.tablesorter .category .alignLeft {
			padding-left: 10px;
		}
		
		table.tablesorter .products .alignLeft {
			padding-left: 40px;
		}
		
		.plusStyle {
			color: #abc3d7; 
			text-decoration: none; 
			cursor: pointer;
		}
                
                .sumAll td{
                    background-color: #BDC7B5;
                }

	{/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_REPORT_SALES_BY_CONTRACTORS} </h2>
		</td>
	</tr>
</table>

<br />

<ul class="tablist" style="width:100%;">	
</ul>
<form action="index.php" method="get" name="searchReportSales">
	<input type="hidden" name="module" value="EcmReports" />
	<input type="hidden" name="action" value="ReportSalesByContractor" />
	<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 : "%d.%m.%Y",
				button : "date_from_trigger",
				singleClick : true,
				dateStr : "",
				step : 1
				{rdelim}
				);
			</script>
		</td>
	</td>	
	
	{* Search by date_to *}
	<td class="dataLabel" width="10%" nowrap="nowrap">Data do</td>
	<td class="dataField" width="30%" 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 : "%d.%m.%Y",
				button : "date_to_trigger",
				singleClick : true,
				dateStr : "",
				step : 1
				{rdelim}
				);
			</script>
	</td>	
	
	{* Search by contractor *}
	<td class="dataLabel" width="10%" nowrap="nowrap">{$MOD.LBL_CONTRACTOR}</td>
	<td class="dataField" width="30%" nowrap="nowrap">
		<input id="account_name" type="text" title="" value="{$contractorName}" size="" tabindex="" name="account_name">
		<input id="account_id" type="hidden" value="{$contractorId}" name="account_id">
		<input class="button" type="button" value="Wybierz" accesskey="T" title="Select [Alt+T]" tabindex="" value="{$contractorName}" name="btn_account_name" onClick="getContractor()">
				
				{* 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>
	{if $submit eq "Wykonaj"} 
	<td class="dataLabel" width="10%" nowrap="nowrap">Kategoria dokumentu</td>
		<td class="dataField" width="30%" nowrap="nowrap">
			<select name="category[]" multiple="multiple">
			{ foreach from=$CATEGORY item=c key=k }
				<option value="{$k}" {if @in_array($k, $categories) } selected="true" {/if}>{$c}</option>
			{/foreach}
			</select>
	  	</td>

	<td class="dataLabel" width="10%" nowrap="nowrap">Typ dokumentu</td>
		<td class="dataField" width="30%" nowrap="nowrap">
			<select name="type[]" multiple="multiple">
			<option value="fv" { if $searchByType.fv } selected="true" {/if} >FV</option>
			<option value="fvk" { if $searchByType.fvk } selected="true" {/if} >FVK</option>
			<option value="pr" { if $searchByType.pr } selected="true" {/if} >PR</option>
			<option value="prk" { if $searchByType.prk } selected="true" {/if} >PRK</option>

			</select>
	  	</td>

	    <td class="dataLabel" width="10%" nowrap="nowrap">Rodzaj dokumentu:</td>
		<td class="dataField" width="30%" nowrap="nowrap">
			<select name="pdfType[]" multiple="multiple">
				<option value="K" {if $pdfType.K} selected="true"{/if}>Kraj</option>
				<option value="U" {if $pdfType.U} selected="true"{/if}>Unia</option>
				<option value="E" {if $pdfType.E} selected="true"{/if}>Eksport</option>
			</select>
	  	</td> 
	  	
	  {else}
		  	<td class="dataLabel" width="10%" nowrap="nowrap">Kategoria dokumentu</td>
			<td class="dataField" width="30%" nowrap="nowrap">
				<select name="category[]" multiple="multiple">
				{ foreach from=$CATEGORY item=c key=k }
					<option value="{$k}" >{$c}</option>
				{/foreach}
				</select>
		  	</td>
	
		<td class="dataLabel" width="10%" nowrap="nowrap">Typ dokumentu</td>
			<td class="dataField" width="30%" nowrap="nowrap">
				<select name="type[]" multiple="multiple">
				<option value="fv" selected="true">FV</option>
				<option value="fvk" selected="true" >FVK</option>
				<option value="pr" selected="true" >PR</option>
				<option value="prk" selected="true" >PRK</option>
	
				</select>
		  	</td>
	
		    <td class="dataLabel" width="10%" nowrap="nowrap">Rodzaj dokumentu:</td>
			<td class="dataField" width="30%" nowrap="nowrap">
				<select name="pdfType[]" multiple="multiple">
					<option value="K" selected="true">Kraj</option>
					<option value="U" selected="true">Unia</option>
					<option value="E" selected="true">Eksport</option>
				</select>
		  	</td> 
	  {/if}
	  	
</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=ReportSalesByContractor';">
<input id="excelEksport" class="button" name="importToExcel" value="{$MOD.BTN_EXCEL_EXPORT}" type="button">

<table id="myTable" class="ablesorter-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_CONTRACTOR}</th>
			<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="10%" class="sorter-saas 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">{$MOD.LBL_SOLD_AMOUNT}</th>
			<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_VALUE_SALES}</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_AVERAGE_PRICE}</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">{$MOD.LBL_COST}</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_MARGIN}</th>                
                </tr>
	</thead>
{foreach from=$ContractorData item=DATA key=CONNAME name=loop}
	{if $CONNAME!=""}
		 <tbody id="functions-core" class="tablesorter-infoOnly">
			<tr class="static contractor">
			 <td class="oddListRowS1 alignLeft"><a class="plusStyle showTablesContractor">[+]</a><b>   {$CONNAME}</b></td>
			 <td class="oddListRowS1 sumRow" ></td>
			 <td class="oddListRowS1 sumRow" ><b>{$ContractorData.$CONNAME.IloscSum|number_format:0:",":"." }</b></td>
			 <td class="oddListRowS1 sumRow" ><b>{$ContractorData.$CONNAME.SoldSum|number_format:2:",":"." }</b></td>
			 <td class="oddListRowS1 sumRow" ><b>{$ContractorData.$CONNAME.SredniaSum|number_format:2:",":"." }</b></td>
			 <td class="oddListRowS1 sumRow" ><b>{$ContractorData.$CONNAME.KosztSum|number_format:2:",":"." }</b></td>
			 <td class="oddListRowS1 sumRow" ><b>{$ContractorData.$CONNAME.MarzaSum|number_format:2:",":"." }%</b></td>              
			</tr>
		 </tbody>
		{foreach from=$DATA item=CAT key=CATNAME name=loop}
			 {if $CATNAME!="IloscSum" && $CATNAME!="SoldSum" && $CATNAME!="SredniaSum" && $CATNAME!="KosztSum" && $CATNAME!="MarzaSum" && $CATNAME!="StanSum" && $CATNAME!="WartoscSum"}
				<tbody id="functions-core" class="tablesorter-infoOnly categoryShowHide">
						<tr class="static category">
						 <td class="oddListRowS1 alignLeft	"><a class="plusStyle showTables">[+]</a><b>   {$CATNAME}</b></td>
						 <td class="oddListRowS1 sumRow" ></td>
						 <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>{$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>              
						</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>
								  <td class="oddListRowS1 sumRow"></td>
								  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.IloscSum|number_format:0:",":"." }</b></td>
								  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SoldSum|number_format:2:",":"." }</b></td>
								  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SredniaSum|number_format:2:",":"." }</b></td>
								  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.KosztSum|number_format:2:",":"." }</b></td>
								  <td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.MarzaSum|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="products">
									   {else} 
										   <tr class="products" role="row"> 
									   {/if}
										   <td class="oddListRowS1 alignLeft" style="text-align:left;">
											  <a target="new" href="index.php?module=EcmProducts&action=index&return_module=EcmProducts&action=DetailView&record={$ROW.id}">{$ROW.name}</a>
										   </td>
										   <td class="oddListRowS1" >{$ROW.code}</td>
										   <td class="oddListRowS1" >{$ROW.ilosc|number_format:0:",":"."}</td>
										   <td class="oddListRowS1" >{$ROW.netto|number_format:2:",":"."}</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>
				 {/if}
		{/foreach}
		<tbody id="stopCategory"></tbody>
	{/if}
{/foreach}
    <tbody id="functions-core" class="tablesorter-infoOnly">
        <tr class="static sumAll">
         <td class="oddListRowS1 alignLeft"><b>{$MOD.LBL_SUM}:</b></td>
		 <td class="oddListRowS1" ></td>
         <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>{$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>            
