
<script src="<?= BASE_ASSET; ?>/js/jquery.hotkeys.js"></script>

<script type="text/javascript">
//This page is a result of an autogenerated content made by running test.html with firefox.
function domo(){

   // Binding keys
   $('*').bind('keydown', 'Ctrl+a', function assets() {
       window.location.href = BASE_URL + '/administrator/Agritun_achat/add';
       return false;
   });

   $('*').bind('keydown', 'Ctrl+f', function assets() {
       $('#sbtn').trigger('click');
       return false;
   });

   $('*').bind('keydown', 'Ctrl+x', function assets() {
       $('#reset').trigger('click');
       return false;
   });

   $('*').bind('keydown', 'Ctrl+b', function assets() {

       $('#reset').trigger('click');
       return false;
   });
}

jQuery(document).ready(domo);
</script>
<!-- Content Header (Page header) -->
<section class="content-header">
   <h1>
     <i class="fa fa-users default"></i>  &nbsp;&nbsp; عمليات الشراء
   </h1>
</section>
<!-- Main content -->
<section class="content">
   <div class="row" >
      
      <div class="col-md-12">
         <div class="box box-warning">
            <div class="box-body ">
               <!-- Widget: user widget style 1 -->
               <div class="box box-widget widget-user-2">
                  <!-- Add the bg color to the header using any of the bg-* classes -->
                  <div class="widget-user-header ">
                     <div class="row pull-right" style="margin-right: 0px!important;">
                        <?php is_allowed('agritun_achat_add', function(){?>
                        <a class="btn btn-flat btn-success btn_add_new" id="btn_add_new" title="<?= cclang('add_new_button', [cclang('agritun_achat')]); ?>  (Ctrl+a)" href="<?=  site_url('administrator/agritun_achat/add'); ?>"><i class="fa fa-plus-square-o" ></i> <?= cclang('add_new_button', [cclang('agritun_achat')]); ?></a>
                        <?php }) ?>
                        <?php is_allowed('agritun_achat_export', function(){?>
                        <a class="btn btn-flat btn-success" title="<?= cclang('export'); ?> <?= cclang('agritun_achat') ?> " href="<?= site_url('administrator/agritun_achat/export?q='.$this->input->get('q').'&f='.$this->input->get('f')); ?>"><i class="fa fa-file-excel-o" ></i> <?= cclang('export'); ?> XLS</a>
                        <?php }) ?>
                        <?php is_allowed('agritun_achat_export', function(){?>
                        <a class="btn btn-flat btn-success" title="<?= cclang('export'); ?> pdf <?= cclang('agritun_achat') ?> " href="<?= site_url('administrator/agritun_achat/export_pdf?q='.$this->input->get('q').'&f='.$this->input->get('f')); ?>"><i class="fa fa-file-pdf-o" ></i> <?= cclang('export'); ?> PDF</a>
                        <?php }) ?>
                     </div>
                     <div class="widget-user-image" style="text-align:left;">
					 </br></br></br>
                     </div>
                     <!-- /.widget-user-image -->
                  </div>


               <!-- /.widget-user -->
               <div class="row">
                  <div class="col-md-8">
                     <div class="col-sm-2 padd-left-0 " >
                        <select type="text" class="form-control chosen chosen-select" name="bulk" id="bulk" placeholder="Site Email" >
                           <option value="">إختيار</option>
                                                     <option value="delete">حذف</option>
                                                  </select>
                     </div>
                     <div class="col-sm-2 padd-left-0 ">
                        <button type="button" class="btn btn-flat" name="apply" id="apply" title="<?= cclang('apply_bulk_action'); ?>"><?= cclang('apply_button'); ?></button>
                     </div>
                     <div class="col-sm-3 padd-left-0  " >
                        <input type="text" class="form-control" name="q" id="filter" placeholder="<?= cclang('filter'); ?>" value="بحث">
                     </div>
                     <div class="col-sm-3 padd-left-0 " >
                        <select type="text" class="form-control chosen chosen-select" name="f" id="field" >
                            <option <?= $this->input->get('f') == 'fournisseur' ? 'selected' :''; ?> value="fournisseur">البائع</option>
                           <option <?= $this->input->get('f') == 'article' ? 'selected' :''; ?> value="article">المنتوج</option>
                           <option <?= $this->input->get('f') == 'qte' ? 'selected' :''; ?> value="qte">الكمية</option>
                           <option <?= $this->input->get('f') == 'prix_u' ? 'selected' :''; ?> value="prix_u">سعر الوحدة</option>
                           <option <?= $this->input->get('f') == 'total' ? 'selected' :''; ?> value="total">المجموع</option>
                           <option <?= $this->input->get('f') == 'user_id' ? 'selected' :''; ?> value="user_id">User Id</option>
                           <option <?= $this->input->get('f') == 'i_src' ? 'selected' :''; ?> value="i_src">I Src</option>
                          </select>
                     </div>
                     <div class="col-sm-1 padd-left-0 ">
                        <button type="submit" class="btn btn-flat" name="sbtn" id="sbtn" value="Apply" title="<?= cclang('filter_search'); ?>">
                        بحث
                        </button>
                     </div>
                     <div class="col-sm-1 padd-left-0 ">
                        <a class="btn btn-default btn-flat" name="reset" id="reset" value="Apply" href="<?= base_url('administrator/agritun_achat');?>" title="<?= cclang('reset_filter'); ?>">
                        <i class="fa fa-undo"></i>
                        </a>
                     </div>
                  </div>
                  </form>                  <div class="col-md-4">
                     <div class="dataTables_paginate paging_simple_numbers pull-right" id="example2_paginate" >
                        <?= $pagination; ?>
                     </div>
                  </div>
               </div>
			   
			   </br>


                  <form name="form_agritun_achat" id="form_agritun_achat" action="<?= base_url('administrator/agritun_achat/index'); ?>">
                  

                  <div class="table-responsive"> 
                  <table class="table table-bordered table-striped dataTable">
                     <thead>
                        <tr class="">
                                                     <th>
                            <input type="checkbox" class="flat-red toltip" id="check_all" name="check_all" title="check all">
                           </th>
                           <th data-field="date"data-sort="1" data-primary-key="0"> <?= cclang('date') ?></th>
                           <th data-field="fournisseur"data-sort="1" data-primary-key="0"> <?= cclang('fournisseur') ?></th>
                           <th data-field="article"data-sort="1" data-primary-key="0"> <?= cclang('article') ?></th>
                           <th data-field="qte"data-sort="1" data-primary-key="0"> <?= cclang('qte') ?></th>
                           <th data-field="prix_u"data-sort="1" data-primary-key="0"> <?= cclang('prix_u') ?></th>
                           <th data-field="total"data-sort="1" data-primary-key="0"> <?= cclang('total') ?></th>
                           
                           <th data-field="user_id"data-sort="1" data-primary-key="0">من قام بالعملية</th>
                           <th data-field="i_src"data-sort="1" data-primary-key="0"> الصورة</th>
                           <th>Action</th>                        </tr>
                     </thead>
                     <tbody id="tbody_agritun_achat">
                     <?php foreach($agritun_achats as $agritun_achat): ?>
                        <tr>
                                                       <td width="5">
                              <input type="checkbox" class="flat-red check" name="id[]" value="<?= $agritun_achat->id; ?>">
                           </td>
                           <td><?= _ent($agritun_achat->date); ?></td>                          
                           <td><?= _ent($agritun_achat->fournisseur); ?></td> 
                           <td><?= _ent($agritun_achat->article); ?></td> 
                           <td><?= _ent($agritun_achat->qte); ?></td> 
                           <td><?= _ent($agritun_achat->prix_u); ?></td> 
                           <td><?= _ent($agritun_achat->total); ?></td> 
                            
                           <td><?= _ent($agritun_achat->user_id); ?></td> 
                           <td>
						   <?php
						   if (_ent($agritun_achat->i_src) != 'null'){
						   ?>
						   <a href='/api/images/show.php?img=<?= site_url('api/images/' .$agritun_achat->i_src); ?>.jpeg' class="popup-view"><img src='/api/images/<?= _ent($agritun_achat->i_src); ?>.jpeg' style="width:100px;height:100px"/></a>
						   <?php
						   }
						   ?>						   
						   </td>  
                           <td width="200">
                            
                              <?php is_allowed('agritun_achat_view', function() use ($agritun_achat){?>
                                 <a href="<?= site_url('administrator/agritun_achat/single_pdf/' .$agritun_achat->id); ?>" class="label-default"><i class="fa fa-file-pdf-o"></i> <?= cclang('PDF') ?>
                              <a href="<?= site_url('administrator/agritun_achat/view/' . $agritun_achat->id); ?>" class="label-default"><i class="fa fa-newspaper-o"></i> <?= cclang('view_button'); ?>
                              <?php }) ?>
                              <?php is_allowed('agritun_achat_update', function() use ($agritun_achat){?>
                              <a href="<?= site_url('administrator/agritun_achat/edit/' . $agritun_achat->id); ?>" class="label-default"><i class="fa fa-edit "></i> <?= cclang('update_button'); ?></a>
                              <?php }) ?>
                              <?php is_allowed('agritun_achat_delete', function() use ($agritun_achat){?>
                              <a href="javascript:void(0);" data-href="<?= site_url('administrator/agritun_achat/delete/' . $agritun_achat->id); ?>" class="label-default remove-data"><i class="fa fa-close"></i> <?= cclang('remove_button'); ?></a>
                               <?php }) ?>

                           </td>                        </tr>
                      <?php endforeach; ?>
                      <?php if ($agritun_achat_counts == 0) :?>
                         <tr>
                           <td colspan="100">
                           Agritun Achat data is not available
                           </td>
                         </tr>
                      <?php endif; ?>

                     </tbody>
                  </table>
                  </div>
               </div>
               <hr>

            </div>
            <!--/box body -->
         </div>
         <!--/box -->
      </div>
   </div>
</section>
<!-- /.content -->

<!-- Page script -->
<script>
  $(document).ready(function(){
   
    $('.remove-data').click(function(){

      var url = $(this).attr('data-href');

      swal({
          title: "<?= cclang('are_you_sure'); ?>",
          text: "<?= cclang('data_to_be_deleted_can_not_be_restored'); ?>",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "<?= cclang('yes_delete_it'); ?>",
          cancelButtonText: "<?= cclang('no_cancel_plx'); ?>",
          closeOnConfirm: true,
          closeOnCancel: true
        },
        function(isConfirm){
          if (isConfirm) {
            document.location.href = url;            
          }
        });

      return false;
    });


    $('#apply').click(function(){

      var bulk = $('#bulk');
      var serialize_bulk = $('#form_agritun_achat').serialize();

      if (bulk.val() == 'delete') {
         swal({
            title: "<?= cclang('are_you_sure'); ?>",
            text: "<?= cclang('data_to_be_deleted_can_not_be_restored'); ?>",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "<?= cclang('yes_delete_it'); ?>",
            cancelButtonText: "<?= cclang('no_cancel_plx'); ?>",
            closeOnConfirm: true,
            closeOnCancel: true
          },
          function(isConfirm){
            if (isConfirm) {
               document.location.href = BASE_URL + '/administrator/agritun_achat/delete?' + serialize_bulk;      
            }
          });

        return false;

      } else if(bulk.val() == '')  {
          swal({
            title: "Upss",
            text: "<?= cclang('please_choose_bulk_action_first'); ?>",
            type: "warning",
            showCancelButton: false,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Okay!",
            closeOnConfirm: true,
            closeOnCancel: true
          });

        return false;
      }

      return false;

    });/*end appliy click*/


    //check all
    var checkAll = $('#check_all');
    var checkboxes = $('input.check');

    checkAll.on('ifChecked ifUnchecked', function(event) {   
        if (event.type == 'ifChecked') {
            checkboxes.iCheck('check');
        } else {
            checkboxes.iCheck('uncheck');
        }
    });

    checkboxes.on('ifChanged', function(event){
        if(checkboxes.filter(':checked').length == checkboxes.length) {
            checkAll.prop('checked', 'checked');
        } else {
            checkAll.removeProp('checked');
        }
        checkAll.iCheck('update');
    });
    initSortable('agritun_achat', $('table.dataTable'));
  }); /*end doc ready*/
</script>