<?php defined('BASEPATH')or exit('NO direct Access is Allowed');?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css" rel="stylesheet"/>
<link href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<style>
.bootstrap-timepicker-widget table td input {
    width: 100%;
  }
  .border_full{
    border: 2px solid #ccc;

  }
  .full_h3{
    margin-top: -4px;
    background-color: #999;
    color: #fff;
    padding: 9px;
  }
  .add_course{
    margin-top: 15px;
    border: 2px solid #ccc;
  }
  .add_h3{
    margin-top: -4px;
    background-color: #dd4b39;
    color: #fff;
    padding: 9px;
}

</style>
<?php
  $last     = $this->uri->total_segments();
  $getcurrentbalance_id = $this->uri->segment($last);
  date_default_timezone_set('Asia/Kolkata');
?>

<div class="content-wrapper">
  <section class="content">
      <div class="row">
          <div class="col-xs-12">
              <div class="box">
                  <div class="box-header">
                      <!--<h3 class="box-title">Add Products</h3>-->

                      <?php echo anchor('admin/course/Course','<i class="fa fa-fw fa-list"></i> Course List',['class'=>'btn btn-default pull-right',
                      'style'=>'background-color: #ffffff;']); ?>
                      <div class="col-md-12" id="respose">
                      <?php if ($this->session->flashdata('failure') == TRUE): ?>
                            <div class="alert alert-error"><?php echo $this->session->flashdata('failure'); ?></div>
                            <?php endif; ?>
                            <?php if ($this->session->flashdata('success') == TRUE): ?>
                            <div class="alert alert-success"><?php echo $this->session->flashdata('success'); ?></div>
                        <?php endif; ?>
                      </div>
                  </div>
                  <!-- /.box-header -->
                  <div class="box-body">
                    <div class="row">
                      <div class="col-md-12">
                        <div  class="border_full">
                        <h3  class="full_h3">Student Info</h3>
                        <div class="table-responsive">
                            <table class="table table-bordered" id="">
                              <thead>
                              <tr>
                                <th>Student</th>
                                <th>Wallet Balance Left</th>
                             </tr>
                           </thead>
                              <tbody>
                              <tr>
                                <td><?=strtoupper($data[0]->student_name);?></td>
                                <td><?=strtoupper($data[0]->wallet_amount);?></td>
                             </tr>
                           </tbody>
                      </table>
                      </div>

              </div>
                    </div>
                      <div class="col-md-12">
                        <div class="add_course">
                        <h3 class="add_h3">Edit Student Wallet Account </h3>
                         <form name="add_name"  method="post" action='<?=site_url("admin/account/Account/edit_student_money_account/{$getcurrentbalance_id}");?>' id="add_name">
                            <div class="table-responsive">
                                <table class="table table-bordered" id="dynamic_field">
                                  <thead>
                                  <tr>
                                     <td>#</td>
                                    <td>Wallet Date</td>
                                    <td>Time</td>
                                    <td>Payment Mode</td>
                                    <td>Wallet Amount</td>
                                    <td>Remarks</td>
                                    <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
                                  </tr>
                                </thead>
                                <tbody>
                                <?php
                                $k=1;
                                foreach($data as $list) {?>
                                    <tr>
                                      <td><?=$k;?></td>
                                      <td>
                                        <input type="hidden" name="student" value="<?=$data[0]->student_id;?>">
                                        <input type="hidden" name="history_id[]" value="<?=$list->historyid;?>">
                                        <input type="hidden" name="current_wallet_id[]" value="<?=$list->current_wallet_id;?>">
                                      <?php echo form_input(['name'=>'wallet_date[]','class'=>'form-control ','id'=>'datepicker','placeholder'=>'Wallet Date',
                                      'value'=>set_value('wallet_date',date("m/d/Y",strtotime($list->wallet_add_date_time))),'autocomplete'=>'off','required'=>'required']);?>
                                      </td>
                                      <td>
                                      <div class="bootstrap-timepicker"><div class="bootstrap-timepicker-widget dropdown-menu"><table><tbody><tr><td><a href="#" data-action="incrementHour"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-up"></i></a></td></tr><tr><td><span class="bootstrap-timepicker-hour">08</span></td> <td class="separator">:</td><td><span class="bootstrap-timepicker-minute">45</span></td> <td class="separator">&nbsp;</td><td><span class="bootstrap-timepicker-meridian">AM</span></td></tr><tr><td><a href="#" data-action="decrementHour"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator"></td><td><a href="#" data-action="decrementMinute"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-down"></i></a></td></tr></tbody></table></div>
                                      <?php echo form_input(['name'=>'wallet_add_time[]','class'=>'form-control timepicker','placeholder'=>'Enter Wallet Add Time',
                                      'value'=>set_value('wallet_add_time',date("h:i A",strtotime($list->wallet_add_date_time))),'autocomplete'=>'off','required'=>'required']);?>
                                      </td>
                                      <td>
                                      <?php echo form_dropdown('mode_of_payment[]',$paymode,set_value('mode_of_payment',$list->mode_of_payment),['class'=>'form-control','autocomplete'=>'off','required'=>'required']);?>
                                      </td>
                                      <!-- <td>  <?php echo form_dropdown('student[]',$student34,set_value('student',$list->student_id),['class'=>'form-control','autocomplete'=>'off','required'=>'required']);?></td> -->
                                      <td>  <?php echo form_input(['name'=>'student_wallet[]','class'=>'form-control ','placeholder'=>'Student Wallet Amount',
                                      'value'=>set_value('student_wallet',$list->w_amount),'autocomplete'=>'off','required'=>'required','readonly'=>'readonly']);?></td>
                                      <td>  <?php echo form_textarea(['name'=>'remarks[]','class'=>'form-control','id'=>'','placeholder'=>'Remarks',
                                      'value'=>set_value('remarks',$list->remarks),'rows'=> '1','cols' => '10','autocomplete'=>'off']);?></td>

                                    </tr>
                                  <?php $k++;}?>
                                  </tbody>
                                </table>
                                <input type="submit" name="submit" id="submit" class="btn btn-info pull-right" value="Submit" />
                            </div>
                         </form>
                          </div>
                      </div>
                    </div>
                  </div>
                  <hr/>

              </div>
          </div>
      </div>
  </section>
</div>
<script>
$(document).ready(function(){
	$(".addCF").click(function(){
		$("#customFields").append('<tr valign="top"><th scope="row"><label for="customFieldName">Custom Field</label></th><td><input type="text" class="code" id="customFieldName" name="customFieldName[]" value="" placeholder="Input Name" /> &nbsp; <input type="text" class="code" id="customFieldValue" name="customFieldValue[]" value="" placeholder="Input Value" /> &nbsp; <a href="javascript:void(0);" class="remCF">Remove</a></td></tr>');
	});
    $("#customFields").on('click','.remCF',function(){
        $(this).parent().parent().remove();
    });
});
</script>
<style>
.SumoSelect {
    display: block;
    position: relative;
    outline: none;
}

</style>
<script>$('#mdp-demo').multiDatesPicker();</script>


<script type="text/javascript">
    $(document).ready(function(){
    //  var postURL = "/addmore.php";
      var i=1;
	  var limit= 5;

  $('#add').on('click',function(){
			//  if(i>=limit){
			// 	alert("You dont have right to add more than "+limit+" class at one time");
			// }
		  //   else{

				i++;
           // $('#dynamic_field').append('<tr id="row'+i+'" class="dynamic-added"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" required /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
                      $('#dynamic_field').append('<tr id="row'+i+'" class="dynamic-added"> \
                      <td>'+i+'</td> \
                      <td>  \
                      <input type="text" name="wallet_date[]" class="form-control datepick" id="" placeholder="Wallet Date" required autocomplete="off"> \
                     </td> \
                     <td> \
                      <div class="bootstrap-timepicker"><div class="bootstrap-timepicker-widget dropdown-menu"><table><tbody><tr><td><a href="#" data-action="incrementHour"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"> \
                      <i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-up"></i></a></td></tr><tr><td><span class="bootstrap-timepicker-hour">08</span></td> <td class="separator">:</td><td><span class="bootstrap-timepicker-minute">45</span></td> <td class="separator">&nbsp;</td><td><span class="bootstrap-timepicker-meridian">AM</span></td> \
                      </tr><tr><td><a href="#" data-action="decrementHour"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator"></td><td><a href="#" data-action="decrementMinute"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-down"></i></a></td></tr></tbody></table></div> \
                        <input type="text" name="wallet_add_time[]" class="form-control timepicker" placeholder="Wallet time" autocomplete="off" required> \
                      </td> \
                      <td><select name="mode_of_payment[]" class="form-control  name_list" data-placeholder="Mode Of Payment" style="" tabindex="-1" aria-hidden="true" required> \
                      <?php foreach($paymode as $p=>$b){ ?>\
                                  <option value="<?=$p?>"> <?=$b?></option>\
                                  <?php }?>\
                      </select></td> \
                      <td> \
                         <input type="text" name="student_wallet[]" class="form-control" id="datepicker" placeholder="Student Wallet Amount" required autocomplete="off"> \
                       </td> \
                      <td> <textarea name="remarks[]" cols="10" rows="1" class="form-control" id="" placeholder="Remarks" autocomplete="off"></textarea></td> \
                      <td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');

              $('.datepick').each(function(){
                $(this).datepicker();
              });
              $('.timepicker').each(function(){
                showInputs: false;
                minuteStep: 5;
                $(this).timepicker();
                });

    //  }

      });


      $(document).on('click', '.btn_remove', function(){
           var button_id = $(this).attr("id");
           $('#row'+button_id+'').remove();
      });


      $('#submit').click(function(){
           $.ajax({
                url:postURL,
                method:"POST",
                data:$('#add_name').serialize(),
                type:'json',
                success:function(data)
                {
                  	i=1;
                  	$('.dynamic-added').remove();
                  	$('#add_name')[0].reset();
    				        alert('Record Inserted Successfully.');
                }
           });
      });

    });
</script>
