
<script src="https://cdn.jsdelivr.net/npm/gasparesganga-jquery-loading-overlay@2.1.6/dist/loadingoverlay.min.js"></script>

<script src="<?= BASE_ASSET; ?>/js/jquery.hotkeys.js"></script>
<script type="text/javascript">
    function domo(){
     
       // Binding keys
       $('*').bind('keydown', 'Ctrl+s', function assets() {
          $('#btn_save').trigger('click');
           return false;
       });
    
       $('*').bind('keydown', 'Ctrl+x', function assets() {
          $('#btn_cancel').trigger('click');
           return false;
       });
    
      $('*').bind('keydown', 'Ctrl+d', function assets() {
          $('.btn_save_back').trigger('click');
           return false;
       });
        
    }
    
    jQuery(document).ready(domo);
</script>
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        Agritun Recolte        <small>Edit Agritun Recolte</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class=""><a  href="<?= site_url('administrator/agritun_recolte'); ?>">Agritun Recolte</a></li>
        <li class="active">Edit</li>
    </ol>
</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="widget-user-image" style="text-align:left;">
                                <img class="img-circle" style="width:50px;" src="<?= BASE_ASSET; ?>/img/add2.png" alt="User Avatar">
                            </div>
                            <!-- /.widget-user-image -->
                            <h3 class="widget-user-username">Agritun Recolte</h3>
                            <h5 class="widget-user-desc">Edit Agritun Recolte</h5>
                            <hr>
                        </div>
                        <?= form_open(base_url('administrator/agritun_recolte/edit_save/'.$this->uri->segment(4)), [
                            'name'    => 'form_agritun_recolte', 
                            'class'   => 'form-horizontal form-step', 
                            'id'      => 'form_agritun_recolte', 
                            'method'  => 'POST'
                            ]); ?>

                        <?php
                        $user_groups = $this->model_group->get_user_group_ids();
                        ?>

                         
                         
                        
                        
                        <div class="form-group ">
                            <label for="id_parcel" class="col-sm-2 control-label">قطعة الأرض 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <select  class="form-control chosen chosen-select-deselect" name="id_parcel" id="id_parcel" data-placeholder="Select قطعة الأرض" >
                                    <option value=""></option>
                                    <?php foreach (db_get_all_data('parcels') as $row): ?>
                                    <option <?=  $row->id ==  $agritun_recolte->id_parcel ? 'selected' : ''; ?> value="<?= $row->id ?>"><?= $row->name; ?></option>
                                    <?php endforeach; ?>  
                                </select>
                                <small class="info help-block">
                                <b>Input Id Parcel</b> Max Length : 100.</small>
                            </div>
                        </div>


                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="id_equipe" class="col-sm-2 control-label">الجماعة 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <select  class="form-control chosen chosen-select-deselect" name="id_equipe" id="id_equipe" data-placeholder="Select الجماعة" >
                                    <option value=""></option>
                                    <?php foreach (db_get_all_data('agritun_team') as $row): ?>
                                    <option <?=  $row->id ==  $agritun_recolte->id_equipe ? 'selected' : ''; ?> value="<?= $row->id ?>"><?= $row->team_name; ?></option>
                                    <?php endforeach; ?>  
                                </select>
                                <small class="info help-block">
                                <b>Input Id Equipe</b> Max Length : 100.</small>
                            </div>
                        </div>


                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="mode_paiement" class="col-sm-2 control-label">طريقة الخلاص 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <select  class="form-control chosen chosen-select-deselect" name="mode_paiement" id="mode_paiement" data-placeholder="Select طريقة الخلاص" >
                                    <option value=""></option>
                                                                    </select>
                                <small class="info help-block">
                                </small>
                            </div>
                        </div>

                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="nbr_pieds" class="col-sm-2 control-label">عدد الأشجار 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="nbr_pieds" id="nbr_pieds" placeholder="عدد الأشجار" value="<?= set_value('nbr_pieds', $agritun_recolte->nbr_pieds); ?>">
                                <small class="info help-block">
                                <b>Input Nbr Pieds</b> Max Length : 100.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="hay" class="col-sm-2 control-label">حي 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="hay" id="hay" placeholder="حي" value="<?= set_value('hay', $agritun_recolte->hay); ?>">
                                <small class="info help-block">
                                <b>Input Hay</b> Max Length : 100.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="nchira" class="col-sm-2 control-label">نشيرة 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="nchira" id="nchira" placeholder="نشيرة" value="<?= set_value('nchira', $agritun_recolte->nchira); ?>">
                                <small class="info help-block">
                                <b>Input Nchira</b> Max Length : 100.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="q_unite" class="col-sm-2 control-label">وحدة القيس 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <select  class="form-control chosen chosen-select" name="q_unite" id="q_unite" data-placeholder="Select وحدة القيس" >
                                    <option value=""></option>
                                    <option <?= $agritun_recolte->q_unite == "كغ" ? 'selected' :''; ?> value="كغ">كغ</option>
                                    <option <?= $agritun_recolte->q_unite == "شكارة" ? 'selected' :''; ?> value="شكارة">شكارة</option>
                                    </select>
                                <small class="info help-block">
                                </small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="q_prix" class="col-sm-2 control-label">سعر الوحدة 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="q_prix" id="q_prix" placeholder="سعر الوحدة" value="<?= set_value('q_prix', $agritun_recolte->q_prix); ?>">
                                <small class="info help-block">
                                <b>Input Q Prix</b> Max Length : 300.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="h_prix" class="col-sm-2 control-label">أجرة الرجل 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="h_prix" id="h_prix" placeholder="أجرة الرجل" value="<?= set_value('h_prix', $agritun_recolte->h_prix); ?>">
                                <small class="info help-block">
                                <b>Input H Prix</b> Max Length : 300.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="f_prix" class="col-sm-2 control-label">أجرة المرأة 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="f_prix" id="f_prix" placeholder="أجرة المرأة" value="<?= set_value('f_prix', $agritun_recolte->f_prix); ?>">
                                <small class="info help-block">
                                <b>Input F Prix</b> Max Length : 300.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="h_nbr" class="col-sm-2 control-label">عدد الرجال 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="h_nbr" id="h_nbr" placeholder="عدد الرجال" value="<?= set_value('h_nbr', $agritun_recolte->h_nbr); ?>">
                                <small class="info help-block">
                                <b>Input H Nbr</b> Max Length : 300.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="f_nbr" class="col-sm-2 control-label">عدد النساء 
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="f_nbr" id="f_nbr" placeholder="عدد النساء" value="<?= set_value('f_nbr', $agritun_recolte->f_nbr); ?>">
                                <small class="info help-block">
                                <b>Input F Nbr</b> Max Length : 300.</small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="cout" class="col-sm-2 control-label">التكلفة 
                            <i class="required">*</i>
                            </label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="cout" id="cout" placeholder="التكلفة" value="<?= set_value('cout', $agritun_recolte->cout); ?>">
                                <small class="info help-block">
                                </small>
                            </div>
                        </div>
                        
                        
                         
                        
                        
                        <div class="form-group ">
                            <label for="i_src" class="col-sm-2 control-label">الصورة 
                            </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="i_src" id="i_src" placeholder="الصورة" value="<?= set_value('i_src', $agritun_recolte->i_src); ?>">
                                <small class="info help-block">
                                </small>
                            </div>
                        </div>
                        
                        
                        
                                                 <div class="message"></div>
                                                <div class="row-fluid col-md-7 container-button-bottom">
                            <button class="btn btn-flat btn-primary btn_save btn_action" id="btn_save" data-stype='stay' title="<?= cclang('save_button'); ?> (Ctrl+s)">
                            <i class="fa fa-save" ></i> <?= cclang('save_button'); ?>
                            </button>
                            <a class="btn btn-flat btn-info btn_save btn_action btn_save_back" id="btn_save" data-stype='back' title="<?= cclang('save_and_go_the_list_button'); ?> (Ctrl+d)">
                            <i class="ion ion-ios-list-outline" ></i> <?= cclang('save_and_go_the_list_button'); ?>
                            </a>
                            <a class="btn btn-flat btn-default btn_action" id="btn_cancel" title="<?= cclang('cancel_button'); ?> (Ctrl+x)">
                            <i class="fa fa-undo" ></i> <?= cclang('cancel_button'); ?>
                            </a>
                            <span class="loading loading-hide">
                            <img src="<?= BASE_ASSET; ?>/img/loading-spin-primary.svg"> 
                            <i><?= cclang('loading_saving_data'); ?></i>
                            </span>
                        </div>
                                                 <?= form_close(); ?>
                    </div>
                </div>
                <!--/box body -->
            </div>
            <!--/box -->
        </div>
    </div>
</section>
<!-- /.content -->
<!-- Page script -->
<script>
    $(document).ready(function(){
       
      
             
      $('#btn_cancel').click(function(){
        swal({
            title: "Are you sure?",
            text: "the data that you have created will be in the exhaust!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes!",
            cancelButtonText: "No!",
            closeOnConfirm: true,
            closeOnCancel: true
          },
          function(isConfirm){
            if (isConfirm) {
              window.location.href = BASE_URL + 'administrator/agritun_recolte';
            }
          });
    
        return false;
      }); /*end btn cancel*/
    
      $('.btn_save').click(function(){
        $('.message').fadeOut();
            
        var form_agritun_recolte = $('#form_agritun_recolte');
        var data_post = form_agritun_recolte.serializeArray();
        var save_type = $(this).attr('data-stype');
        data_post.push({name: 'save_type', value: save_type});
    
        $('.loading').show();
    
        $.ajax({
          url: form_agritun_recolte.attr('action'),
          type: 'POST',
          dataType: 'json',
          data: data_post,
        })
        .done(function(res) {
          $('form').find('.form-group').removeClass('has-error');
          $('form').find('.error-input').remove();
          $('.steps li').removeClass('error');
          if(res.success) {
            var id = $('#agritun_recolte_image_galery').find('li').attr('qq-file-id');
            if (save_type == 'back') {
              window.location.href = res.redirect;
              return;
            }
    
            $('.message').printMessage({message : res.message});
            $('.message').fadeIn();
            $('.data_file_uuid').val('');
    
          } else {
            if (res.errors) {
               parseErrorField(res.errors);
            }
            $('.message').printMessage({message : res.message, type : 'warning'});
          }
    
        })
        .fail(function() {
          $('.message').printMessage({message : 'Error save data', type : 'warning'});
        })
        .always(function() {
          $('.loading').hide();
          $('html, body').animate({ scrollTop: $(document).height() }, 2000);
        });
    
        return false;
      }); /*end btn save*/
      
       
       
       

      function chained_mode_paiement(selected, complete){
            var val = $('#mode_paiement').val();
            $.LoadingOverlay('show')
            return $.ajax({
                url: BASE_URL + '/administrator/agritun_recolte/ajax_mode_paiement/'+val,
                dataType: 'JSON',
            })
            .done(function(res) {
                var html = '<option value=""></option>';
                $.each(res, function(index, val) {
                    html += '<option '+(selected == val.mode_paiement ? 'selected' : '')+' value="'+val.mode_paiement+'">'+val.mode_paiement+'</option>'
                });
                $('#mode_paiement').html(html);
                $('#mode_paiement').trigger('chosen:updated');
                if (typeof complete != 'undefined') {
                    complete();
                }

            })
            .fail(function() {
                toastr['error']('Error', 'Getting data fail')
            })
            .always(function() {
                $.LoadingOverlay('hide')
            });
        }

      
        $('#mode_paiement').change(function(event) {
            chained_mode_paiement('')
        });
        
      async function chain(){
          await chained_mode_paiement("<?= $agritun_recolte->mode_paiement ?>");
      }
       
      chain();


    
    
    }); /*end doc ready*/
</script>