<?php $__env->startSection("content"); ?>
<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">Product</a></li>
    <li class="breadcrumb-item active" aria-current="page">แก้ไขข้อมูลสินค้า</li>
  </ol>
</nav>
<!-- DataTales Example -->
<div class="card mb-4">
  <div class="card-header py-3">
    <h6 class="m-0 font-weight-bold text-primary">ตารางข้อมูลสินค้า</h6>
  </div>
  <div class="card-body">
    <div class="table-responsive" >
      <table class="table table-sm" id="PdTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th scope="col" style="text-align: left;">#</th>
            <th scope="col" style="text-align: left;">ชื่อสินค้า</th>
            <th scope="col" style="text-align: right;">ประเภทสินค้า</th>
            <th scope="col" style="text-align: right;">ราคาต้นทุน[บาท]</th>
            <th scope="col" style="text-align: right;">ราคาขาย[บาท]</th>
            <th scope="col" style="text-align: right;">หน่วยบรรจุ</th>
            <th scope="col" style="text-align: right;">น้ำหนัก</th>
            <th scope="col" style="text-align: center;">หน่วย นน.</th>
            <th scope="col" style="text-align: center;">ตัวเลือก</th>
          </tr>
        </thead>
        <?php
        $i = 1;
        ?>
        <tbody>
         <?php $__currentLoopData = $showpd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
         <tr>
          <td scope="row"><?php echo e($i++); ?>.</td>
          <td class="text-nowrap"><?php echo e($x->PdName); ?></td>
          <td class="text-nowrap" style="text-align: right;"><?php echo e($x->pdTypeName); ?></td>
          <td class="text-nowrap" style="text-align: right;"><?php echo e($x->PriceCost); ?></td>
          <td class="text-nowrap" style="text-align: right;"><?php echo e($x->Price); ?></td>
          <td class="text-nowrap"style="text-align: right;"><?php echo e($x->UnitName); ?></td>
          <td class="text-nowrap"style="text-align: right;"><?php echo e($x->Weight); ?></td>
          <td class="text-nowrap"style="text-align: center;"><?php echo e($x->nameWeight); ?></td>
          <td class="text-nowrap" style="text-align: center;">
            <a href="#" class="btn btn-primary btn-circle btn-sm" onClick="show('<?php echo e(addslashes($x->PdName)); ?>','<?php echo e(addslashes($x->pdTypeName)); ?>','<?php echo e($x->PriceCost); ?>','<?php echo e($x->Price); ?>','<?php echo e($x->UnitName); ?>','<?php echo e($x->Weight); ?>','<?php echo e($x->nameWeight); ?>','<?php echo e($x->note); ?>','<?php echo e($x->PdDetail); ?>','<?php echo e($x->PdDescription); ?>');">
              <i class="fas fa-search"></i>
            </a>
            <a href="#" class="btn btn-warning btn-circle btn-sm" onClick="edit('<?php echo e($x->idPd); ?>','<?php echo e(addslashes($x->PdName)); ?>','<?php echo e($x->idpdType); ?>','<?php echo e(addslashes($x->pdTypeName)); ?>','<?php echo e($x->PriceCost); ?>','<?php echo e($x->Price); ?>','<?php echo e($x->idUnit); ?>','<?php echo e($x->UnitName); ?>','<?php echo e($x->Weight); ?>','<?php echo e($x->idWeight); ?>','<?php echo e($x->nameWeight); ?>','<?php echo e($x->note); ?>','<?php echo e($x->PdDetail); ?>','<?php echo e($x->PdDescription); ?>');">
              <i class="fas fa-edit"></i>
            </a>
            <a href="#" class="btn btn-danger btn-circle btn-sm" onClick="del(<?php echo e($x->idPd); ?>);">
              <i class="fas fa-trash"></i>
            </a>               

          </td>
        </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </tbody>
    </table>
  </div>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="ShowPdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background:#330099">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #FFFF;">ข้อมูลสินค้า</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">

        <div class="form-row">
          <div class="form-group col-md-6">
            <label for="inputName">ชื่อสินค้า</label>
            
            <input type="text" class="form-control" id="vname" name="vname" placeholder="ชื่อสินค้า" disabled>
          </div>
          <div class="form-group col-md-6">
            <label for="inputType">ประเภทสินค้า</label>
            <input type="text" class="form-control" name="vTypename" id="vTypename" placeholder="" disabled>
          </div>
        </div>
        <div class="form-group">
          <label for="inputDetail">ข้อมูลเพิ่มเติม</label>

          <input type="text" class="form-control" name="vPdDetail" id="vPdDetail" placeholder="" disabled>
        </div>
        <div class="form-group">
          <label for="inputDesc">ลักษณะสินค้า</label>
          <input type="text" class="form-control" name="vPdDes" id="vPdDes" placeholder="" disabled>
        </div>
        <div class="form-row">
          <div class="form-group col-md-6">
            <label for="inputPriceCost">ราคาต้นทุน[บาท]</label>

            <input type="number" class="form-control" name="vCost" id="vCost" min="0.01" step="0.01" disabled>
          </div>
          <div class="form-group col-md-6">
            <label for="inputState">ราคาขาย[บาท]</label>
            
            <input type="number" class="form-control" name="vprice" id="vprice" min="0.01" step="0.01" disabled>
          </div>
        </div>
        <div class="form-row">
          <div class="form-group col-md-4">
            <label for="inputUnit">หน่วยบรรจุ</label>
            <input type="text" class="form-control" name="vUnitName" id="vUnitName" placeholder="" disabled>
          </div>
          <div class="form-group col-md-4">
            <label for="inputWeight">น้ำหนัก</label>
            
            <input type="number" class="form-control" name="vWeight" id="vWeight" min="0.01" step="0.01" disabled>
          </div>
          <div class="form-group col-md-4">
            <label for="inputTypeWeight">หน่วยน้ำหนัก</label>
            <input type="text" class="form-control" name="vnameWeight" id="vnameWeight" placeholder="" disabled>
          </div>
          <div class="form-group col-md-12">
            <label for="inputNote">หมายเหตุ</label>
            <textarea class="form-control" name="vnote" id="vnote" rows="3" disabled></textarea>
          </div>
        </div>       
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<!-- ModalEdit -->
<div class="modal fade" id="EditPdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background:#A0522D">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #FFFF;">แก้ไขข้อมูลสินค้า</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?php echo url('editpddata'); ?>" method="post" id="form1">
       <?php echo csrf_field(); ?>
       <div class="modal-body">

         <div class="form-row">
          <div class="form-group col-md-6">
            <label for="inputName">ชื่อสินค้า</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <input type="text" class="form-control" id="vEname" name="vEname" placeholder="ชื่อสินค้า">
            <input type="hidden" name="inputId" id="inputId">
          </div>
          <div class="form-group col-md-6">
            <label for="inputType">ประเภทสินค้า</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <select id="vEidtype" name="vEidtype" class="form-control">
              <?php $__currentLoopData = $typepd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($x->idpdType); ?>"><?php echo e($x->pdTypeName); ?></option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label for="vEPdDetail">ข้อมูลเพิ่มเติม</label>
          <span class="form-required" style="color: #CC0000">*</span>
          <input type="text" class="form-control" name="vEPdDetail" id="vEPdDetail" placeholder="">
        </div>
        <div class="form-group">
          <label for="vEPdDes">ลักษณะสินค้า</label>
          <input type="text" class="form-control" name="vEPdDes" id="vEPdDes" placeholder="">
        </div>
        <div class="form-row">
          <div class="form-group col-md-6">
            <label for="vECost">ราคาต้นทุน[บาท]</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <input type="number" class="form-control" name="vECost" id="vECost" min="0.01" step="0.01">
          </div>
          <div class="form-group col-md-6">
            <label for="vEprice">ราคาขาย[บาท]</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <input type="number" class="form-control" name="vEprice" id="vEprice" min="0.01" step="0.01">
          </div>
        </div>
        <div class="form-row">
          <div class="form-group col-md-4">
            <label for="inputUnit">หน่วยบรรจุ</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <select id="vEidUnit" name="vEidUnit" class="form-control">

              <?php $__currentLoopData = $dunit; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($x->idUnit); ?>"><?php echo e($x->UnitName); ?></option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
          </div>
          <div class="form-group col-md-4">
            <label for="vEWeight">น้ำหนัก</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <input type="number" class="form-control" name="vEWeight" id="vEWeight" min="0.01" step="0.01">
          </div>
          <div class="form-group col-md-4">
            <label for="vEidWeight">หน่วยน้ำหนัก</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <select id="vEidWeight" name="vEidWeight" class="form-control">
              <?php $__currentLoopData = $dtweight; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($x->idWeight); ?>"><?php echo e($x->nameWeight); ?></option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
          </div>
          <div class="form-group col-md-12">
            <label for="vEnote">หมายเหตุ</label>
            <textarea class="form-control" name="vEnote" id="vEnote" rows="3"></textarea>
          </div>
        </div>     
      </div>
    </form>
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" id="btSmEdit" class="btn btn-primary">Save changes</button>
    </div>
  </div>
</div>
</div>


<?php $__env->stopSection(); ?>
<?php $__env->startSection("script"); ?>
<script type="text/javascript">

  $(document).ready( function () {
    $('#PdTable').DataTable();
  });

  $('#btSmEdit').click(function(){
    if(($("#vEname").val() == "")){
      swal({
        title: "ไม่สามารถบันทึกได้ !!!",
        text: "กรุณากรอกชื่อสินค้า",
        icon: "info",
        button: "ตกลง",
      });

      return false;

    }else if(($("#vEidtype").val() == "")){
      swal({
        title: "ไม่สามารถบันทึกได้ !!!",
        text: "กรุณากรอกข้อมูลเพิ่มเติม",
        icon: "info",
        button: "ตกลง",
      });

      return false;
    }else if(($("#vECost").val() == "")){
      swal({
        title: "ไม่สามารถบันทึกได้ !!!",
        text: "กรุณากรอกราคาต้นทุน",
        icon: "info",
        button: "ตกลง",
      });

      return false;
    }else if(($("#vEprice").val() == "")){
      swal({
        title: "ไม่สามารถบันทึกได้ !!!",
        text: "กรุณากรอกราคาขาย",
        icon: "info",
        button: "ตกลง",
      });

      return false;
    }else if(($("#vEWeight").val() == "")){
      swal({
        title: "ไม่สามารถบันทึกได้ !!!",
        text: "กรุณากรอกน้ำหนัก",
        icon: "info",
        button: "ตกลง",
      });

      return false;
    }else{
     swal({
      title: "การบันทึกข้อมูล",
      text: "คุณต้องการบันทึกแก้ไขสินค้าหรือไม่",
      icon: "warning",
      buttons: true,
      dangerMode: true,
    })
     .then((willDelete) => {
      if (willDelete) {
        swal("บันทึกสำเร็จ", {
          icon: "success",
        });
        $("#form1").submit();
      } else {
        swal("ยกเลิกการบันทึก");
      }
    });

   }
 })

  function del(id){
    swal({
      title: "คุณต้องการลบสินค้านี้หรือไม่ ?",
      icon: "error",
      buttons: true,
      confirm: true,

    })
    .then((willOk) => {
      if (willOk) {

        $.ajax({
          url:'<?php echo e(url("delpd")); ?>',
          type:'GET',
          data:{id},
          success:function(ret){
            if(ret ==1){
              swal("ลบประเภทสินค้าแล้ว", {icon: "success"});
              window.location.href = "<?php echo e(url('dtpd')); ?>";
            }else{
              swal("ขออภัย", "ไม่สามารถลบสินค้าได้เพราะมีรายการขายอยู่");
            }
          },
          error:function(err){
            console.log(err.responseText);
          }

        });
      } 
    });

  }

  function edit(id,name,idtype,typename,Cost,price,idUnit,UnitName,Weight,idWeight,nameWeight,note,PdDetail,PdDescription){

    $('#inputId').val(id);
    $('#vEname').val(name);
    $('#vEidtype').val(idtype);
    $('#vEtypename').val(typename);
    $('#vECost').val(Cost);
    $('#vEprice').val(price);
    $('#vEidUnit').val(idUnit);
    $('#vEUnitName').val(UnitName);
    $('#vEWeight').val(Weight);
    $('#vEidWeight').val(idWeight);
    $('#vEnameWeight').val(nameWeight);
    $('#vEnote').val(note);
    $('#vEPdDetail').val(PdDetail);
    $('#vEPdDes').val(PdDescription);

    $('#EditPdModal').modal('show');
  }
  function show(name,typename,Cost,price,UnitName,Weight,nameWeight,note,PdDetail,PdDescription){

    $('#vname').val(name);
    $('#vTypename').val(typename);
    $('#vCost').val(Cost);
    $('#vprice').val(price);
    $('#vUnitName').val(UnitName);
    $('#vWeight').val(Weight);
    $('#vnameWeight').val(nameWeight);
    $('#vnote').val(note);
    $('#vPdDetail').val(PdDetail);
    $('#vPdDes').val(PdDescription);

    $('#ShowPdModal').modal('show');
  }

</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make("layout.menu", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp7\htdocs\natureplus\resources\views/home/showTbPd.blade.php ENDPATH**/ ?>