<html>
<head>
    <style>
        {literal}
        .edit tr td{
            vertical-align : middle;
        }

        .money ,.quantity{
            text-align : right;
        }
        table.tablesorter {
            font-family:arial;
            background-color: #CDCDCD;
            margin:10px 0pt 15px;
            font-size: 8pt;
            width: 100%;
            text-align: left;
        }
        table.tablesorter thead tr th, table.tablesorter tfoot tr th {
            background-color: #e6EEEE;
            border: 1px solid #FFF;
            font-size: 8pt;
            padding: 4px;
        }
        table.tablesorter thead tr .header {
            background-image: url(bg.gif);
            background-repeat: no-repeat;
            background-position: center right;
            cursor: pointer;
        }
        table.tablesorter tbody td {
            color: #3D3D3D;
            padding: 4px;
            background-color: #FFF;
            vertical-align: top;
        }
        table.tablesorter tbody tr.odd td {
            background-color:#F0F0F6;
        }
        table.tablesorter thead tr .headerSortUp {
            background-image: url(asc.gif);
        }
        table.tablesorter thead tr .headerSortDown {
            background-image: url(desc.gif);
        }
        table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
            background-color: #8dbdd8;
        }
        {/literal}
    </style>
    <style>
        {literal}
        .pull-right {
            text-align: right;
        }
        .pull-center {
            text-align: right;
        }
        .tr-style-top td {
            /*border-top: 1px solid #6d6d6d;*/
            box-shadow: 0 1px 0 #828181 inset;
            outline: none;
        }
        {/literal}
    </style>
</head>
<body>

<table style="width:100%;font-size:10px">
    <thead>
    <tr>
        <td colspan='4'>
            <p style="font-size:15px"><b>Raport sprzedaż w grupach</b></p>
        </td>
        <td style="text-align:right">
            Data wygenerowania raportu:<br>
            {$smarty.now|date_format:"%d.%m.%Y %H:%M:%S"}
        </td>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>
            <table>
                <tr>
                    <td>
                        Rok:
                    </td>
                    <td>
                        <select name="years_group[]" title="">
                            {foreach from=$list_years key=key item=item}
                                <option
                                        value="{$item}"
                                        {if @in_array($item, $smarty.request.years_group) } selected="true" {/if}>
                                    {$item}
                                </option>
                            {/foreach}
                        </select>
                    </td>
                </tr>
            </table>
        </td>
        <td>
            <table>
                <tr>
                    <td>
                        Miesiąc:
                    </td>
                    <td>
                        <select name="months_group[]" title="">
                            {foreach from=$list_months key=key item=item}
                                <option
                                        value="{$key}"
                                        {if @in_array($key, $smarty.request.months_group) } selected="true" {/if}>
                                    {$months.$item}
                                </option>
                            {/foreach}
                        </select>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    </tbody>
</table>

<table id="myTable" class="tablesorter">

    <thead>
    <tr>
        <td>ROK</td>
        <td>MIESIĄC</td>
        <td>PROFIL GŁÓWNY</td>
        <td>ILU ODBIORCÓW W LICZBACH</td>
        <td>ILE DOKUMENTÓW</td>

        {foreach from=$list_group_ks key=groups_key item=group_ks}
           {if in_array($groups_key,$types_prod_req)}
            <td>{$group_ks}</td>
            {else}
             <td></td>
            {/if}
        {/foreach}
        <td>
					Pozostałe
					
				</td>
    </tr>
    </thead>
	
    <tbody>
    {foreach from=$table_array key=year_key item=year name=year_name}
        {assign var=count_month value=0}

        {* Generate sum all types for years column *}
        {assign var=sum_type value=0}
        {foreach from=$year key=month_key item=month name=month_name}
            {math assign=sum_type equation="x + y" x=$sum_type y=$month|@count}
        {/foreach}

        {foreach from=$year key=month_key item=month name=month_name}
            {assign var=count_type value=0}

            {foreach from=$month key=type_key item=type name=type_name}

                <tr {if $smarty.foreach.type_name.first} class="tr-style-top" {/if}>
                    {if $count_type == 0}
                        {if $count_month == 0}
                            <td rowspan="{$sum_type}" class="pull-right">{$year_key}</td>
                        {/if}

                        <td rowspan="{$month|@count}">{$months[$month_key]}</td>
                    {/if}

{if in_array($type_key,$types_group_req)}
	{if !empty($list_types.$type_key)}
                    <td>{$list_types.$type_key}</td>
                    {else}
                     <td>Pozostałe</td>
                    {/if}
                    

                    <td class="pull-right">{$type.accounts_count}</td>

                    <td class="pull-right">{$type.documents_count}</td>

                    {foreach from=$list_group_ks key=groups_key item=groups}
                        {assign var=found value=0}

                        {foreach from=$type.accounts_type key=group_key item=group name=group_name}
{if in_array($group_key,$types_prod_req)}
                            {if $groups_key == $group_key}
                                {assign var=found value=1}
                                <td class="pull-right"> {$group|number_format:2:",":"."}</td>
                               
                              
                                
                            {/if}
	{/if}
                        {/foreach}

                        {if $found==0}
                            <td class="pull-center">-</td>
                        {/if}

                    {/foreach}
                    <td class="pull-right">{$type.accounts_type.total|number_format:2:".":","}</td>
			{/if}
                </tr>

                {assign var=count_type value=$count_type+1}
               
            {/foreach}

            {assign var=count_month value=$count_month+1}
        {/foreach}

    {/foreach}
    </tbody>

</table>

</body>
</html>