<?php $__env->startSection("content"); ?>

<?php


function DateThai($strDate)
{
  $strYear = date("Y",strtotime($strDate))+543;
  $strMonth= date("n",strtotime($strDate));
  $strWeek= date("w",strtotime($strDate));
  $strDay= date("j",strtotime($strDate));
  $strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
  $thai_day_arr = Array("อา","จ","อ","พ","พฤ","ศ","ส");
  $strMonthThai=$strMonthCut[$strMonth];
  $strWeekThai=$thai_day_arr[$strWeek];
  return "$strWeekThai $strDay $strMonthThai $strYear";
}

function DateFic($Date)
{
  $timestampa = strtotime($Date);
  $new_date = date("d/m/Y", $timestampa);
  return "$new_date";
}


?>
<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">Promotion</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">
    <div class="row">
      <div class="col-6 mb-6">
       <h6 class="m-0 font-weight-bold text-primary">ตารางข้อมูลโปรโมชั่น</h6>
     </div>
     <div class="col-3 mb-3" style="text-align: right;">
       <h6 class="m-0 font-weight-bold text-primary"></h6>
     </div>
     <div class="col-3 mb-3" style="text-align: right;">
       <h6 class="m-0 font-weight-bold text-primary"></h6>
     </div>
   </div>
 </div>
 <div class="card-body">
  <div class="table-responsive" >
    <table class="table table-sm" id="PdTable" width="100%" cellspacing="0">
      <thead>
        <tr>
          <th style="text-align: center;">#</th>
          
          <th scope="col" style="text-align: center;">โค้ดที่ระบุ</th>
          <th scope="col" style="text-align: left;">ชื่อโปรโมชั่น</th>
          <th scope="col" style="text-align: center;">รายละเอียด</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>
          <th scope="col" style="text-align: center;">ตัวเลือก</th>

        </tr>
      </thead>
      <?php
      $i = 1;
      ?>
      <tbody>
       <?php $__currentLoopData = $mt; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
       <?php

       ?>
       <tr>
        <td style="text-align: center;"><?php echo e($i++); ?>.</td>
        <td class="text-nowrap" style="text-align: center;"><?php echo e($x->Code); ?></td>
        <td class="text-nowrap" style="text-align: left;"><?php echo e($x->namePromotion); ?></td>
        <td class="text-nowrap"style="text-align: center;"><?php echo e($x->detailPromotion); ?></td>
        <td class="text-nowrap"style="text-align: right;"><?php echo e(number_format($x->disco)); ?></td>
        <td class="text-nowrap"style="text-align: right;"><?php echo e(DateThai($x->StartDate)); ?></td>
        <td class="text-nowrap"style="text-align: center;"><?php echo e(DateThai($x->endDate)); ?></td>
        <td class="text-nowrap"style="text-align: center;"><?php echo e($x->nameType); ?></td>
        <td class="text-nowrap" style="text-align: center;">
         <!--  <a href="#" class="btn btn-primary btn-circle btn-sm" onClick="show()">
            <i class="fas fa-search"></i>
          </a>  -->
          <a href="#" class="btn btn-warning btn-circle btn-sm" onClick="edit('<?php echo e($x->idPromotion); ?>','<?php echo e($x->namePromotion); ?>','<?php echo e($x->detailPromotion); ?>','<?php echo e(number_format($x->disco)); ?>','<?php echo e(DateFic($x->StartDate)); ?>','<?php echo e(DateFic($x->endDate)); ?>','<?php echo e($x->idType); ?>','<?php echo e($x->Code); ?>','<?php echo e($x->notePromotion); ?>','<?php echo e($x->StartDate); ?>','<?php echo e($x->endDate); ?>');">
            <i class="fas fa-edit"></i>
          </a>
          <!-- <a href="#" class="btn btn-danger btn-circle btn-sm" onClick="del(<?php echo e($x->idPromotion); ?>);">
            <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 modal-xl" 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="vCusName">ชื่อลูกค้า :</label>
            <input type="text" class="form-control" name="vCusName" id="vCusName"  disabled>
          </div>
          <div class="form-group col-md-3">
            <label for="vCodeInden">เลขที่ผู้เสียภาษี :</label>
            <input type="number" class="form-control" name="vCodeInden" id="vCodeInden" disabled>
          </div>
          <div class="form-group col-md-3">
           <label for="vPromotion">โปรโมชั่นที่ใช้ :</label>
           <input type="number" class="form-control" name="vPromotion" id="vPromotion" placeholder="โปรโมชั่นที่ใช้" disabled>
         </div>
       </div>
       <div class="form-row">
        <div class="form-group col-md-4">
          <label for="vDocCode">เลขที่รายการ :</label>
          <input type="text" class="form-control" id="vDocCode" name="vDocCode" placeholder="เลขที่รายการ" disabled>
        </div>
        <div class="form-group col-md-4">
          <label for="vDateCreate">วันที่รายการ :</label>
          <input type="text" class="form-control" name="vDateCreate" id="vDateCreate" placeholder="วันที่รายการ" disabled>
        </div>
        <div class="form-group col-md-4">
          <label for="vNameSocial">จากระบบ :</label>
          <input type="text" class="form-control" id="vNameSocial" name="vNameSocial" placeholder="จากระบบ" disabled>
        </div>
        <div class="form-group col-md-4">
          <label for="vNamePay">การชำระเงิน :</label>
          <input type="text" class="form-control" name="vNamePay" id="vNamePay" placeholder="การชำระเงิน" disabled>
        </div>
        <div class="form-group col-md-4">
          <label for="vMobile1">เบอร์โทร :</label>

          <input type="text" class="form-control" id="vMobile1" name="vMobile1" placeholder="เบอร์โทร" disabled>
        </div>
        <div class="form-group col-md-4">
          <label for="vPsNnameF">เจ้าหน้าที่ขาย :</label>
          <input type="text" class="form-control" name="vPsNnameF" id="vPsNnameF" placeholder="เจ้าหน้าที่ขาย" disabled>
        </div>
      </div>
      <div class="form-row">
        <div class="form-group col-md-6">
          <label for="vAddressText">ที่อยู่จัดส่ง :</label>
          <textarea class="form-control" name="vAddressText" id="vAddressText" rows="3" disabled></textarea>
        </div>
        <div class="form-group col-md-6">
          <label for="vNote">หมายเหตุ :</label>
          <textarea class="form-control" name="vNote" id="vNote" rows="3" disabled></textarea>
        </div>
      </div>
      <div class="form-row">
        <div class="form-group col-md-6">
          <label for="vNote">หมายเลข Tacking :</label>
          <input type="" name="" class="form-control" name="vnumeTack" id="vnumeTack" rows="3" disabled>
        </div>
      </div>

      
      <div class="form-row">
       <div class="col-lg-12 mb-12">
        <div class="row">
          <div class="col-lg-6 mb-6"> <p class="font-weight-bold" for="inputProvince" style="text-align: left; color: #00897B; ">ตารางสินค้า</p></div>
        </div>
      </div>
      <div class="col-lg-12 mb-12">
        <div class="table-responsive">
          <table class="table table-bordered table-sm">
            <thead>
              <tr>
                <th scope="col" style="text-align: center;">#</th>
                <th scope="col" style="text-align: center;">lot no.</th>
                <th scope="col" style="text-align: center;">รายการสินค้า</th>
                <th scope="col" style="text-align: center;">ราคาปกติ[฿]</th>
                <th scope="col" style="text-align: center;">จน.ขาย</th>
                <th scope="col" style="text-align: center;">ราคาขาย[฿]</th>
                <th scope="col" style="text-align: center;">รวมเป็นเงิน[฿]</th>
              </tr>
            </thead>
            <tbody id="tdDt">

            </tbody>
          </table>
        </div>
      </div>
    </div>    
    <div class="form-row">
      <div class="form-group col-md-8">
      </div>
      <div class="form-group col-md-4">
        <label for="vTotalNet">รวมเป็นเงินสุทธิ[บาท]</label>
        <input type="text" class="form-control font-weight-bold " name="vTotalNet" id="vTotalNet" style="font-size: 18px; text-align: right; color: #00796B;" min="0.01" step="0.01" readonly="" value="0">
      </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('editdatapromonew'); ?>" method="post" id="form1">
       <?php echo csrf_field(); ?>
       <div class="modal-body">

        <div class="col-lg-12 mb-12">
          <!-- เพิ่มสินค้าใหม่ -->
          <div class="card shadow 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="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="inputName" name="inputName" placeholder="ชื่อโปรโมชั่น">
                  <input type="hidden" class="form-control" id="inputId" name="inputId">
                </div>
                <div class="form-group col-md-6">
                  <label for="inputType">ประเภทโปรโมชั่น</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <select id="inputpmType" name="inputpmType" class="form-control">

                    <?php $__currentLoopData = $typepm; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($x->idtype); ?>"><?php echo e($x->nameType); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label for="inputDetail">ข้อมูลเพิ่มเติม</label>
                <span class="form-required" style="color: #CC0000">*</span>
                <input type="text" class="form-control" name="inputDetail" id="inputDetail" placeholder="">
              </div>
              <div class="form-row">

                <div class="form-group col-md-12">
                  <label for="inputCode">โค้ดโปรโมชั่น</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <input type="text" class="form-control" name="inputCode" id="inputCode">
                </div>
                <div class="form-group col-md-6">
                  <label for="inputDic">ส่วนลด[บาท/ชิ้น]</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <input type="number" class="form-control" name="inputDic" id="inputDic" min="0.01" step="0.01">
                </div>
                <div class="form-group col-md-12" style="padding-left: 25px;">
                  <label for="inputCode">วันที่เริ่ม-โปรโมชั่น</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <div class="row gutters-xs">
                    <div class="col">
                      <input type="text" name="timeStart" id="inputtimeStart" class="form-control date-picker" placeholder="ว/ด/ป" readonly>
                    </div>
                    <span class="col-auto">
                      <button class="btn btn-secondary" id="timeStart" type="button"><i class="far fa-calendar-alt"></i></button>
                    </span>
                  </div>
                </div>
                <div class="form-group col-md-12" style="padding-left: 25px;">
                  <label for="inputWeight">วันที่สิ้นสุด-โปรโมชั่น</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <div class="row gutters-xs">
                    <div class="col">
                      <input type="text" name="timeEnd" id="inputtimeEnd" class="form-control date-picker" placeholder="ว/ด/ป" readonly>
                    </div>
                    <span class="col-auto">
                      <button class="btn btn-secondary" id="timeEnd" type="button"><i class="far fa-calendar-alt"></i></button>
                    </span>
                  </div>
                </div>

                <div class="form-group col-md-12">
                  <label for="inputNote">หมายเหตุ</label>
                  <textarea class="form-control" name="inputNote" id="inputNote" rows="3"></textarea>
                 
                </div>
              </div>      
            </div>
          </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();
  });

  $(function(){ 

    $("#inputtimeStart").datepicker({
      format: "dd/mm/yyyy",
      todayBtn: "linked",
      clearBtn: true,
      language: "th",
      daysOfWeekHighlighted: "0",
      autoclose: true,
      todayHighlight: true
    });

    $("#timeStart").click(function(){
      $("#inputtimeStart").focus();
    });

    $("#inputtimeEnd").datepicker({
      format: "dd/mm/yyyy",
      todayBtn: "linked",
      clearBtn: true,
      language: "th",
      daysOfWeekHighlighted: "0",
      autoclose: true,
      todayHighlight: true
    });

    $("#timeEnd").click(function(){
      $("#inputtimeEnd").focus();
    });

  });

  $('#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(idPromotion,namePromotion,detailPromotion,disco,StartDate,endDate,idType,Code,note,dstr,dend){

    $('#inputId').val(idPromotion);
    $('#inputName').val(namePromotion);
    $('#inputDetail').val(detailPromotion);
    $('#inputCode').val(Code);
    $('#inputDic').val(disco);
    $('#inputtimeStart').val(StartDate);
    $('#inputtimeEnd').val(endDate);
    $('#inputNote').val(note);
    $('#inputTstrt').val(dstr);
    $('#inputTend').val(dend);

    $('#EditPdModal').modal('show');
  }
  function show(idSale,DocCode,CusName,LastName,PROVINCE_NAME,TotalNet,PsNnameF,nameSocial,NamePay,dateCreate,Mobile1,Email,namePromotion,AddressText,Note,codeInden,numeTack){

    $('#vCusName').val(CusName +" "+ LastName);
    $('#vCodeInden').val(codeInden);
    $('#vPromotion').val(namePromotion);
    $('#vDocCode').val(DocCode);
    $('#vDateCreate').val(dateCreate);
    $('#vNameSocial').val(nameSocial);
    $('#vNamePay').val(NamePay);
    $('#vMobile1').val(Mobile1);
    $('#vPsNnameF').val(PsNnameF);
    $('#vAddressText').val(AddressText);
    $('#vNote').val(Note);
    $('#vTotalNet').val(TotalNet);
    $('#vnumeTack').val(numeTack);

    $.ajax({
      url:'<?php echo e(url("finepddtsale")); ?>/'+idSale,
      type:'GET',
      dataType:'json',
      cache:false,
      
      success:function(ret){
        console.log(ret);
        $("#tdDt").empty();
        var showdt = ret["dt"];
        var rows = 1;
        for(x in showdt){
          var PriceM = numeral(showdt[x].PriceM).format('0,0');
          var Price = numeral(showdt[x].Price).format('0,0');
          var d = numeral(showdt[x].totalNet).format('0,0');
          var Amount = numeral(showdt[x].Amount).format('0,0');
          str = '<tr>'
          +'<td scope="row" style="text-align: center;">'
          +rows
          +'. '
          +'</td>'
          +'<td style="text-align: center;"><input type="hidden" name="numlotT" value="'+showdt[x].LotNo+'">'
          +showdt[x].LotNo
          +'</td>'
          +'<td scope="row" style="text-align: left; color: #00897B;"><input type="hidden" name="idPdPkLot" value="'+showdt[x].idPdPkLot+'"><input type="hidden" name="idPd" value="'+showdt[x].idPdPk+'">'
          +showdt[x].PdName
          +'</td>'
          +'<td style="text-align: right; "><input type="hidden" name="PriceM" value="\''+showdt[x].PriceM+'\'">'
          +PriceM
          +'</td>'
          +'<td style="text-align: center;"><input type="hidden" name="Amount" value="'+showdt[x].Amount+'">'
          +Amount
          +'</td>'
          +'<td style="text-align: right;"><input type="hidden" name="priceT" value="\''+showdt[x].Price+'\'">'
          +Price
          +'</td>'
          +'<td class="text-nowrap"style="text-align: right;">'+d+'</td>';
          $("#tdDt").append(str);
          rows++;
        }

        $('#ShowPdModal').modal('show');
      },
      error:function(err){
        console.log(err);
      }
    });

    
  }

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

<?php echo $__env->make("layout.menu", \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/cp325668/public_html/erp/resources/views/promotion/showTbPromotion.blade.php ENDPATH**/ ?>