<link rel="stylesheet" type="text/css" href="modules/EcmReports/css/SearchTable.css"/>
<script src="include/jQuery/tablesorter/jquery.tablesorter.min.js"></script>
<link class="theme" rel="stylesheet" href="include/jQuery/tablesorter/themes/blue/style.css">

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


<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>Obroty wg dokumentów</h2>
            </td>
        </tr>
</table>
<br>
<ul class="tablist" style="width:100%;">
    <li>
        <a class="current" href="#">Wyszukiwanie</a>
    </li>		
</ul>
<form action="index.php" method="get" name="ReportStockDocMoves">
    <input type="hidden" name="module" value="EcmReports" />
    <input type="hidden" name="action" value="ReportStockDocMoves" />
    <table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td class="dataField" width="10%" nowrap="nowrap">
                    <span id="stockSelectedspan">{$MOD.LBL_STOCK}</span>
                    <select multiple="multiple" name="stockSelected[]">
                        {foreach from=$stocksList key="key" item="item"}
                            <option value="{$key}" {if @in_array($key, $stockSelected) } selected="true" {/if}>{$item}</option>
                        {/foreach}
                    </select>

                </td>
                <td class="dataField" width="10%" nowrap="nowrap">
                    Dokument
                    {html_options name=documentsSelected options=$documentList selected=$documentSelected}
                </td>
                <td class="dataField" width="10%" nowrap="nowrap">
                    Widok:
                    {html_options name=viewSelected options=$viewList selected=$viewSelected}
                </td>
                <td class="dataField" width="10%" nowrap="nowrap">
                    <span class="changebox kartotekamaterialowa">
                        Kartoteka materiałowa
                        <select multiple name="stockIndexSelected[]">
                            <option value="NULL" {if @in_array('NULL', $stockIndexSelected) } selected="true" {/if}></option>
                            {foreach from=$stockIndexList key="key" item="item"}
                                <option value="{$key}" {if @in_array($key, $stockIndexSelected) } selected="true" {/if}>{$item}</option>
                            {/foreach}
                        </select>
                    </span>
                    <span class="changebox magazyndocelowy">
                        Do magazynu
                        <select multiple="multiple" name="mmSelected[]">
                            {foreach from=$stocksList key="key" item="item"}
                                <option value="{$key}" {if @in_array($key, $mmSelected) } selected="true" {/if}>{$item}</option>
                            {/foreach}
                        </select>
                    </span>
                    <span class="changebox kontrahent">
                        {$MOD.LBL_CONTRACTOR}
                        <input type="text" id="accountName" name="accountName" value="{$accountName}">
                        <input type="hidden" id="accountId" name="accountId" value="{$accountId}">
                        <button 
                            type="button"  
                            id="selectAccount"
                            value="{$APP.LBL_ADD_BUTTON}"
                            title="Wybierz kontrahenta">
                            <img src="{sugar_getimagepath file="id-ff-select.png"}">
                        </button>
                        <button 
                            type="button"  
                            id="clear"
                            value="Wyczyść"
                            title="Wyczyść">
                            <img src="{sugar_getimagepath file="id-ff-clear.png"}">
                        </button>
                    </span>
					<span class="changebox kategoriawz">
						Kategoria 
						{html_options name=wz_category options=$kategorie_wz selected=$wz_category_selected}
					</span>
                </td>
            </tr>
            <tr>
                <td class="dataLabel" width="10%" nowrap="nowrap">
                    Data od
                    <input id="date_from" name="date_from" type="text" maxlength="10" size="11" tabindex="" title="Data od" 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 class="dataLabel" width="10%" nowrap="nowrap"> 
                    Data do
                    <input autocomplete="off" name="date_to" id="date_to" value="{$date_to}" title="Data do" 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>
            </tr>
        </tbody>
    </table>
    <input type="submit" value="{$MOD.LBL_EXECUTE}">
    <input class="button" name="clear" value="{$MOD.LBL_CLEAR}" type="button" onclick="location.href = 'index.php?module=EcmReports&action=ReportStockDocMoves';">
    <input id="pdf" class="button" name="pdf" value="PDF" onClick="pdfExport();" type="button">
    <!-- <input id="pdf" class="button" name="pdf" value="XLS" onClick="xlsExport();" type="button"> -->
</form>
<br>
<div class="content" style="text-align:center">
    {if $viewSelected eq 'documents'}
        <table id="myTable"  class="tablesorter"> 
            <thead>
                <tr>
                    <th >Numer dokumentu</th>
                    <th>Data</th>
                    <th>
                        {if $documentSelected eq 'EcmStockDocInsideOuts' or $documentSelected eq 'EcmStockDocInsideIns' or $documentSelected eq 'EcmStockDocCorrects'}
                            Kartoteka materiałowa
                        {elseif $documentSelected eq 'EcmStockDocMoves'}
                            Magazyn docelowy  
                        {elseif $documentSelected eq 'EcmStockDocIns'}
                            Dostawca 
                        {elseif $documentSelected eq 'EcmStockDocOuts'}
                            Odbiorca
                        {elseif $documentSelected eq 'EcmInvoiceOuts'}
                            Kontrahent
                        {/if}
                    </th>
                    <th>Opis dokumentu</th>
                    <th>Wartość</th>
                    <th>Magazyn</th>
					{if $documentSelected eq 'EcmStockDocOuts'}
						<th>Kategoria</th>
					{/if}
                </tr>
            </thead>
            <tbody aria-live="polite" aria-relevant="all">
                {foreach from=$DATA.doc key="key" item="item" name=loop}
                    <tr>
                        <td>
                            <a href="index.php?module={$documentSelected}&action=DetailView&record={$item.id}">{$item.typ} {$item.numer}</a>
                        </td>
                        <td>
                            {$item.data}
                        </td>
                        <td>
                            {if $documentSelected eq 'EcmStockDocInsideOuts' or $documentSelected eq 'EcmStockDocInsideIns' or $documentSelected eq 'EcmStockDocCorrects'}
                                {$item.kartoteka}
                            {elseif $documentSelected eq 'EcmStockDocMoves'}
                                {$item.magazynIn}
                            {elseif $documentSelected eq 'EcmStockDocIns' or $documentSelected eq 'EcmStockDocOuts' or $documentSelected eq 'EcmInvoiceOuts' }
                                <a href="index.php?module=Accounts&action=DetailView&record={$item.accountId}">{$item.accountNazwa}</a>
                            {/if}

                        </td>
                        <td>
                               {if $item.typ=='KS'}
                        {if $item.otyp==0}
                        	Przychód
                        {/if}
                         {if $item.otyp==1}
                        	Rozchód
                        {/if}
                        {else}
                            {$item.nazwa}
                            {/if}
                        </td>

                        <td style="text-align: right">
                            {assign var=suma value=$suma+$item.wartosc}
                            {$item.wartosc|number_format:2:",":"."}
                        </td>
                        <td style="text-align: left">
                            {$item.magazyn}
                        </td>
						{if $documentSelected eq 'EcmStockDocOuts'}
							<td>{$item.doccategory}</td>
						{/if}
                    </tr>
                {/foreach}
            </tbody>
            <tfoot>
                <tr>
                    <th colspan='4' style="text-align:left;">Suma:</th>
                    <th  style="text-align:right;">{$suma|number_format:2:",":"." }</th>
                    <th ></th>
					{if $documentSelected eq 'EcmStockDocOuts'}
					<th></th>
					{/if}
                </tr>
            </tfoot>
        </table>
    {elseif $viewSelected eq 'positions'}
        <table id="myTable"   class="tablesorter"> 
            <thead>
                <tr>
                    <th>Indeks</th>
                    <th>Nazwa</th>
                    <th>Jm</th>
                    <th>Ilość</th>
                    <th>Wartość</th>
                </tr>
            </thead>
            <tbody aria-live="polite" aria-relevant="all">
                {foreach from=$DATA.prod key="key" item="item" name=loop}
                    <tr>
                        <td>
                            <a href="index.php?module=EcmProducts&action=DetailView&record={$item.id}">{$item.kod} </a>
                        </td>
                        <td>
                            <a href="index.php?module=EcmProducts&action=DetailView&record={$item.id}">{$item.nazwa} </a>
                        </td>
                        <td>
                            {$item.jm}
                        </td>
                        <td  style="text-align: right">
                            {assign var=sumaIlosci value=$sumaIlosci+$item.ilosc}
                            {$item.ilosc|number_format:2:",":"."}
                        </td>
                        <td style="text-align: right">
                            {assign var=suma value=$suma+$item.wartosc}
                            {$item.wartosc|number_format:2:",":"."}
                        </td>
                    </tr>
                {/foreach}
            </tbody>
            <tfoot>
                <tr>
                    <th colspan='3' style="text-align:left;">Suma:</th>
                    <th colspan='1' style="text-align:right;">{$sumaIlosci|number_format:2:",":"." }</th>
                    <th colspan='1' style="text-align:right;">{$suma|number_format:2:",":"." }</th>
                </tr>
            </tfoot>
        </table>         
    {/if}
    <span id="info">Strona w budowie :)</span>
</div>
