<?php $__env->startSection("pagecss"); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection("content"); ?>
<div class="row">
  <div class="col-lg-12">
    <div class="kt-portlet">
      <div class="kt-portlet__head">
        <div class="kt-portlet__head-label">
          <h3 class="kt-portlet__head-title">
         Update Budget 
          </h3>
        </div>
        <div class="kt-portlet__head-toolbar">
          <div class="kt-portlet__head-wrapper">
            <a href="<?php echo $_SERVER['HTTP_REFERER'] ?>" class="btn btn-primary text-white btn-icon-sm">
            <i class="la la-long-arrow-left"></i>Back</a>
          </div>
        </div>
      </div>
	<!--begin::Form-->
      <form class="kt-form kt-form--label-right" role="form" id="budget_edit_form" action="<?php echo e(url('budgets/update/'.$id)); ?>" method="post">
      <div class="kt-portlet__body">
          <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
            <input type="hidden" value="<?php echo e(Auth::user()->company_id); ?>" name="company_id" />
              <?php if(count($budgets)>0): ?>
              <?php foreach($budgets as $row): ?> 
          <?php if($row->id==$id): ?>
          
          <div class="row">
            <div class="form-group  col-lg-6">
                <label for="deparment" class="">Department</label>
                <select class="form-control " id="deparment" name="category_id">
                  <option value="">Choose Department</option>
                  
                  <?php if(count($categories)>0): ?>
                  <?php foreach($categories as $row1): ?>
                    
                  <option value="<?php echo e($row1->id); ?>" <?php if($row1->id==$row->category_id){ echo 'selected="selected"'; }?>><?php echo e($row1->name); ?></option>
                  
                  <?php endforeach; ?>
                  <?php endif; ?>
                
                </select>
              </div>
              <div class=" form-group  col-lg-6">
                <label for="periods" class="">Periods</label>
                <select class="form-control" id="periods" name="period_id">
                  <option value="">Choose Period</option>
                  
                  <?php if(count($periods)>0): ?>
                  <?php foreach($periods as $row2): ?>
                    
                  <option value="<?php echo e($row2->id); ?>" <?php if($row2->id==$row->period_id){ echo 'selected="selected"'; }?>><?php echo e($row2->name); ?></option>
                  
                  <?php endforeach; ?>
                  <?php endif; ?>
                </select>
              </div>
          </div>
          <div class=" row">
            <div class="form-group col-lg-6">
              <label for="item" class="">Item</label>
              <input type="text" value="<?php echo $row->item; ?>" class="form-control" name="item">
            </div>
         
            <div class=" form-group col-lg-6">
              <label for="unit" class="">Unit Price (<?php echo e(\App\Providers\Common::currency_symbol()); ?>)</label>
              <input type="text" value="<?php echo $row->unit; ?>" class="form-control" name="unit" onkeyup="calcBudget()">
            </div>
          </div>
              <div class=" row">
                <div class=" form-group col-lg-6">
                <label for="quantity" class="">Quantity</label>
                <input type="text" value="<?php echo $row->quantity; ?>" class="form-control" name="quantity" onkeyup="calcBudget()">
                </div>
              <div class=" form-group   col-lg-6">
              <label for="budget" class="">Budget (<?php echo e(\App\Providers\Common::currency_symbol()); ?>)</label>
                <input type="text" value="<?php echo $row->budget; ?>" class="form-control" name="budget" readonly="readonly">
              </div>
            </div>
            <?php endif; ?>
			<?php endforeach; ?>
            <?php endif; ?>
         
        </div>
        <div class="kt-portlet__foot">
          <div class="kt-form__actions">
            <div class="row">
              <div class="col-lg-5"></div>
              <div class="col-lg-6">
                <button type="submit"class="btn btn-primary">Update</button>
                <button type="reset" class="btn btn-secondary">Clear Changes</button>
              </div>
            </div>
          </div>
        </div>
        </div>
      </form>
      <!--end::Form-->
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection("pagejs"); ?>
<script src="<?php echo e(URL::asset('/')); ?>assets/vendors/general/jquery-validation/dist/jquery.validate.js" type="text/javascript"></script>
<script src="<?php echo e(URL::asset('/')); ?>assets/vendors/general/jquery-validation/dist/additional-methods.js" type="text/javascript"></script>
<script src="<?php echo e(URL::asset('/')); ?>assets/vendors/custom/js/vendors/jquery-validation.init.js" type="text/javascript"></script>
<script>
function calcBudget(){
  var unit_per = $("input[name='unit']").val();
  var quantity = $("input[name='quantity']").val();
  var budget = unit_per*quantity;
  budget = parseFloat(budget);
  budget = budget.toFixed(0);
  $("input[name='budget']").val(budget);
}
$( "#budget_edit_form" ).validate({
  // define validation rules
  rules: {
    category_id: {
          required: true,
      },
      period_id: {
          required: true
      },
    item: {
              required: true 
          }, 
    unit: {
          required: true 
      },
      quantity: {
          required: true,
      },
      priority: {
          required: true,
      },
      budget: {
          required: true
      }
  },
  //display error alert on form submit  
  invalidHandler: function(event, validator) {     
     
  },

  submitHandler: function (form) {
      form[0].submit(); // submit the form
  }
});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make("app", array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>