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

<?php
$strYear = date("Y");
$dat2Date = date("d/m/Y");

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 Numphon($strNum)
{

  $n3 = substr($strNum,6,4);
  $n2 = substr($strNum,3,3);
  $n1 = substr($strNum,0,3);
  $nump = $n1."-".$n2."-".$n3;
  return "$nump";
}

function Datefor($strDate)
{
 
  if(empty($strDate)){
    $datemat = date("d/m/Y");
  }else{

    $datemat = $strDate;
  }

  //19/06/2021
  return "$datemat";
}

function strgleng($strg)
{
  if(strlen($strg) >= 60){
    $srt = mb_substr($strg ,0,60,'UTF-8')."...";
  }else{
    $srt = $strg;
  }
    return $srt;
}

$inputtimeStart = "";
$inputtimeend= "";


if(!empty($date1)){$inputtimeStart = $date1;}else{$inputtimeStart = "";}
if(!empty($date2)){$inputtimeend = $date2;}else{$inputtimeend = "";}
?>

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">ใบสั่งซื้อ</a></li>
    <li class="breadcrumb-item active" aria-current="page">ข้อมูลใบสั่งซื้อ</li>
  </ol>
</nav>
<!-- DataTales Example -->
<div class="card">
  <form id="form1" action="showpob2date" method="POST" class="col-lg-12 mb-12">
    <?php echo csrf_field(); ?>
    <div class="card-body">
    <div class="row">
      <div class="col-9 mb-12">
        <div class="row">
            <div class="row" style="padding-left: 10px">
              <div class="col-md-12 col-12">
                <p><span class="m-0 font-weight-bold text-primary" id="h6text"  style="font-size:16px;">ตารางข้อมูล PO </span><span class="m-0 font-weight-bold text-dark"  style="font-size:14px;"> </span></p>
                
              </div>
            </div>
            <div class="row" style="padding-left: 10px">
              <div class="col-12">
                  <div class="input-group input-group-sm mb-3">
                      <div class="input-group-prepend">
                          <span class="input-group-text" id="inputGroup-sizing-sm">เริ่ม</span>
                      </div>
                      <input type="text" class="form-control" id="inputtimeStart" name="inputtimeStart"  aria-label="Small" aria-describedby="inputGroup-sizing-sm" value="<?php echo Datefor($inputtimeStart); ?>" readonly>
                  </div>
              </div>
            </div>
            <div class="row" style="padding-left: 10px">
              <div class="col-12">
                  <div class="input-group input-group-sm mb-3">
                      <div class="input-group-prepend">
                          <span class="input-group-text" id="inputGroup-sizing-sm">ถึง</span>
                      </div>
                      <input type="text" class="form-control" id="inputtimeEnd" name="inputtimeEnd" aria-label="Small" aria-describedby="inputGroup-sizing-sm" value="<?php echo Datefor($inputtimeend); ?>" readonly>
                  </div>
              </div>
            </div>
            <div class="row" style="padding-left: 10px">
              <div class="col-12">
                <button  class="btn btn-success btn-success btn-sm" type="submit" style="color: #FFF" data-toggle="modal" data-target="#show2dateModalCenter"> <i class="fas fa-search"></i> ค้นหา</button>
              </div>
            </div>
            <!-- <div class="row" style="padding-left: 20px">
              <div class="col-12">
                <a  class="btn btn-primary btn-primary btn-sm" style="color: #FFF" data-toggle="modal" data-target="#reportSalesModalCenter"> <i class="fas fa-print"></i> ปริ้นรายงานยอดขาย</a>
              </div>
            </div> -->
            <div class="row" style="padding-left: 10px">
              <div class="col-12">
                <div class="btn-group">
                <button type="button"  onclick="window.location.href='add/addpo/menu'" class="btn btn-primary btn-sm"><i class="fas fa-plus-circle"></i>  สร้างใบสั่งซื้อ</button> 
                </div>
              </div>
            </div>
            <div class="row" style="padding-left: 10px">
              <div class="col-12">
                <div class="btn-group">
                <button type="button"  onclick="window.location.href='showpobw8check'" class="btn btn-outline-info btn-sm" style="color:#818705"><i class="far fa-smile"></i>  รอตรวจสอบ  <?php if($countw8chk[0]->cunw8chek == 0): ?> <?php else: ?><span class="badge badge-pill badge-danger" style="background-color:#818705"> <?php echo e(number_format($countw8chk[0]->cunw8chek)); ?></span><?php endif; ?></button>
                <button type="button"  onclick="window.location.href='showpobw8approv'" class="btn btn-outline-info btn-sm" style="color:#950663"><i class="far fa-smile"></i>  รออนุมัติ <?php if($countw8app[0]->cunw8app == 0): ?> <?php else: ?><span class="badge badge-pill badge-danger" style="background-color:#950663"> <?php echo e(number_format($countw8app[0]->cunw8app)); ?></span><?php endif; ?></button> 
                <button type="button"  onclick="window.location.href='tbpo'" class="btn btn-outline-info btn-sm" style="color:#066995"><i class="far fa-file-alt"></i>  รายการทั้งหมด </button>
                </div>
              </div>
            </div>
            
          </div>
      </div>
      <div class="col-3 mb-12 " style="text-align: right;">
        <div class="row">
          <div class="col-md-12 col-12">
          <!-- <button type="button"  onclick="window.location.href='add/sale/menu'" class="btn btn-primary btn-sm"><i class="fas fa-plus-circle"></i>  สร้างใบสั่งซื้อ</button>   -->
          </div>
        </div>
      </div>
      </div>
    </div>
  </form>
</div>

<div class="card mb-4">
  
  <div class="card-body" style="font-size: 12px;">
    <div class="table-responsive" >
      <table class="table table-sm" id="PdTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th scope="col" style="text-align: center;">#</th>
            <th scope="col" style="text-align: center;">ตัวเลือก</th>
            <th class="text-nowrap"  scope="col" style="text-align: center;">เลขที่ใบสั่งซื้อ</th>
            <th scope="col" style="text-align: center;">สถานะ</th>
            <th class="text-nowrap" scope="col" style="text-align: center;">สินค้าที่สั่งซื้อ</th>
            <th  class="text-nowrap" scope="col" style="text-align: right;">จำนวนเงิน</th>  
            <th class="text-nowrap" scope="col" style="text-align: center;">คำอธิบายรายการ</th>
            <th class="text-nowrap" scope="col" style="text-align: center;">วันที่ต้องการ</th>
            <th scope="col" style="text-align: center;">Supplier</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 = $allpo; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <?php
          ?>
          <tr>
          <td scope="row"><?php echo e($i++); ?>.</td>
          <td class="text-nowrap" style="text-align: left; font-size: 8px;">
            
            <a  class="btn btn-primary btn-warning btn-sm" href="edit/addpo/<?php echo e($x->id_po); ?>"><i class="fas fa-edit"></i></a>
            <a  class="btn btn-primary btn-info btn-sm" href="printpopdf/<?php echo e($x->id_po); ?>" target="_blank" hover="ใบเสร็จ">
            <i class="fas fa-file-invoice"></i>
            </a> 
          </td>
          <td class="text-nowrap"><?php echo e($x->DocCodePo); ?></td>
          <td class="text-nowrap"style="text-align: center;"> <?php if(is_null($x->idps_check)): ?> <p style="color: #9F1060">รอตรวจสอบ</p> <?php elseif(is_null($x->idps_approve)): ?> <p style="color: #926A0E">รออนุมัติ</p> <?php else: ?> <p style="color: #0E8892">อนุมัติแล้ว</p> <?php endif; ?></td>
          <td class="text-nowrap" style="text-align: left;"><?php echo e(strgleng($x->product)); ?></td>
          <td class="text-nowrap"style="text-align: right;"><?php echo e(number_format($x->price_total)); ?></td> 
          <td class="text-nowrap" style="text-align: left;"><?php echo e($x->note); ?></td>
          <td class="text-nowrap" style="text-align: center;"><?php echo e(DateThai($x->date_require)); ?></td>
          <td class="text-nowrap" style="text-align: center;"><?php echo e($x->SupName); ?></td>
          <td class="text-nowrap" style="text-align: left;"><?php echo e(strgleng($x->v_pay)); ?></td>       
          <td class="text-nowrap"style="text-align: right;"><?php echo e($x->PsNnameF); ?> <?php echo e($x->PsNameS); ?> (<?php echo e($x->PsNickName); ?>)</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>


<?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');
  }

  $(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();
    });

    });

</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/except/resources/views/home/showTbpo.blade.php ENDPATH**/ ?>