<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/ReportSalesByContractor2.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>
				{if $reportSales ==1}
			{$MOD.LBL_RAPORT_SALES_BY_CONTRACTOR} - cena produkcyjna
			{else}
			{$MOD.LBL_RAPORT_SALES_BY_CONTRACTOR} 
			{/if}
			</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="{if $reportSales ==1}ReportSalesByContractor3{else}ReportSalesByContractor2{/if}" />
    <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 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 $selectedUser eq '' } selected="selected" {/if} >wszyscy</option>
                    {foreach from=$USERS item=USER key=count name=loop}
                        <option value="{$USER.id}" {if $selectedUser eq $USER.id} selected="selected" {/if}>{$USER.first} {$USER.last}</option>
                    {/foreach}
                </select>
            </td>

            <td class="dataLabel" width="15%" nowrap="nowrap">
                Grupuj "Media Saturn Holding" <input type="checkbox" value="enabled" name="group_media_saturn_holding" {if $group_media_saturn_holding == 'enabled'}checked{/if}>
            </td>

            <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">Źródło</td>
            <td class="dataField" width="10%" nowrap="nowrap">
                <select id="source" name="source">
                    <option value="" { if $source eq '' } selected="selected" {/if} >Wszystkie</option>
                    <option value="allegro" {if $source eq 'allegro'} selected="selected" {/if}>Allegro</option>
                    <option value="no-allegro" {if $source eq 'no-allegro'} selected="selected" {/if}>Oprócz Allegro</option>
                </select>
            </td>            </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={if $reportSales ==1}ReportSalesByContractor3{else}ReportSalesByContractor2{/if}';">
    <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="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>


    <br/>