{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
$(function(){
  $.datepicker.setDefaults($.datepicker.regional['ru']);
  var VarYearE = (new Date).getFullYear()+1;
  $("#purchase_date_b").datepicker($.extend({yearRange: '1978:'+VarYearE, dateFormat: "dd.mm.yy", changeMonth: true, changeYear: true, closeText: 'X', showButtonPanel: true, showStatus: true,showOn: 'both', buttonText: 'Выбрать дату', buttonImageOnly: true, buttonImage: '{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/ms_check_calendar.png{literal}'}));
  $("#purchase_date_e").datepicker($.extend({yearRange: '1978:'+VarYearE, dateFormat: "dd.mm.yy", changeMonth: true, changeYear: true, closeText: 'X', showButtonPanel: true, showStatus: true,showOn: 'both', buttonText: 'Выбрать дату', buttonImageOnly: true, buttonImage: '{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/ms_check_calendar.png{literal}'}));
  $("#purchase_date_b").datepicker( "setDate", '-1m');
  $("#purchase_date_e").datepicker( "setDate", '0d');
});

$(function(){
  var param = GetParamForGrid($("#DateForm").serialize());
  $("#GridPurchaseReportByPeriod").jqGrid({
    caption:"Отчет по закупкам",
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/ReportPurchaseForOperatorsList.ajax.php{literal}",
    colNames:['Наименование','Подразделение','Статус','Стоимость','Дата закупки'],
    colModel:[
      {name:'purchase_name', index:'purchase_name', width:350},
      {name:'structureorganization_title', index:'structureorganization_title', width:120},
      {name:'purchasestatus_name', index:'purchasestatus_name', width:120},
      {name:'purchase_price', index:'purchase_price', width:100, align:"right", formatter:"number", summaryType:'sum'},
      {name:'purchase_datetill', index:'purchase_datetill', width:80, align:"right", sorttype:'date'}
    ],
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridPurchasePager",
    sortname: 'purchase_id',
    sortorder: "desc",
    viewrecords: true,
    rownumbers: true,
    footerrow: true,
    userDataOnFooter: true,
    altRows: true,
    width: "100%",
    height: 290,
    postData: param
  });
  $("#GridPurchaseReportByPeriod").jqGrid('navGrid','#GridPurchasePager', {edit:false,add:false,del:false,search:false,refresh:false});
});

$(function(){
  $("#DateForm").submit(function() {
    var param = GetParamForGrid($(this).serialize());
    $('#GridPurchaseReportByPeriod').setGridParam({postData: param});
    $("#GridPurchaseReportByPeriod").trigger("reloadGrid");
    return false;
  });
});
//]]>
</script>
{/literal}

<form id="DateForm" name="DateForm" action="" method="post">
<table>
  <tr>
    <td><label>Дата с:</label></td>
    <td>
  		<input type="text" id="purchase_date_b" name="purchase_date_b" value="" />
  		<label>по:</label>
  		<input type="text" id="purchase_date_e" name="purchase_date_e" value="" />
  	</td>
  </tr>
  <tr>
    <td><label for="purchasestatus_id">Статус :&nbsp;</label><span></span></td>
    <td>
      {foreach $ArrPurchaseStatus as $val}
        {if $val@first}
          <select id="purchasestatus_id" name="purchasestatus_id">
        {/if}
            <option value="{$val.purchasestatus_id}">{$val.purchasestatus_name}</option>
        {if $val@last}
          </select>
        {/if}
      {/foreach}
    </td>
  </tr>
  <tr>
    <td colspan="2" class="MsFormSubmit"><input class="AltButtons" name="FormSubmit" value="искать" type="submit" /></td>
  </tr>
</table>
</form>
<br />
<table id="GridPurchaseReportByPeriod"><tr><td></td></tr></table>
<div id="GridPurchasePager"></div>