<?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 Datefor($strDate)
{
  $strYear = date("Y",strtotime($strDate));
  $strMonth= date("m",strtotime($strDate));
  $strDay= date("d",strtotime($strDate));
  $datemat = $strDay."/".$strMonth."/".$strYear;
  return "$datemat";
}


    $datetime1 = date("Y-m-d");
   

    $idMt = "";
    $idsub = "";
    $SupName = "";
    $no_posub = "";
    $DocCodemt = ""; 
    $vadd = "";
    $idpaychek = "";
    $vpay = "";
    $inputtimeStart = "";
    $inputNote ="" ;
    $price_total ="" ;
    $price_vat ="" ;
    $price_totalNetT ="" ;
    $id_Transt ="" ;
    $idAdd ="" ;
    $inputpricetarn ="" ;
    $inputtracking ="" ;
    $Mobile1 ="" ;

    if(!empty($mt[0]->id_transport_mt)){$idMt = $mt[0]->id_transport_mt;}else{$idMt = "";}
    if(!empty($mt[0]->id_cus)){$idsub = $mt[0]->id_cus;}else{$idsub = "";}
    if(!empty($mt[0]->Psname)){$SupName = $mt[0]->Psname;}else{$SupName = "";}
    if(!empty($mt[0]->no_posub)){$no_posub = $mt[0]->no_posub;}else{$no_posub = "";}
    if(!empty($mt[0]->DocCode)){$DocCodemt = $mt[0]->DocCode;}else{$DocCodemt = "";}
    if(!empty($mt[0]->AddressText)){$vadd = $mt[0]->AddressText;}else{$vadd = "ที่อยู่จัดส่ง";}
    if(!empty($mt[0]->id_pay)){$idpaychek = $mt[0]->id_pay;}else{$idpaychek = "";}
    if(!empty($mt[0]->v_pay)){$vpay = $mt[0]->v_pay;}else{$vpay = "บริษัทขนส่ง";}
    if(!empty($mt[0]->date_to)){$inputtimeStart = $mt[0]->date_to;}else{$inputtimeStart = $datetime1;}
    if(!empty($mt[0]->notets)){$inputNote = $mt[0]->notets;}else{$inputNote = "";}
    if(!empty($mt[0]->price)){$price_total = $mt[0]->price;}else{$price_total = "0";}
    if(!empty($mt[0]->vat)){$price_vat = $mt[0]->vat;}else{$price_vat = "0";}
    if(!empty($mt[0]->price_total)){$price_totalNetT = $mt[0]->price_total;}else{$price_totalNetT = "0";}
    if(!empty($mt[0]->id_dtran)){$id_Transt = $mt[0]->id_dtran;}else{$id_Transt = "";}
    if(!empty($mt[0]->price_tarn)){$inputpricetarn = $mt[0]->price_tarn;}else{$inputpricetarn = "";}
    if(!empty($mt[0]->tracking)){$inputtracking = $mt[0]->tracking;}else{$inputtracking = "";}
    if(!empty($mt[0]->Mobile1)){$Mobile1 = $mt[0]->Mobile1;}else{$Mobile1 = "";}
    if(!empty($mt[0]->id_add)){$idAdd = $mt[0]->id_add;}else{$idAdd = "";}

    if(!empty($daddress[0]->idPv)){$PROVINCE_ID = $daddress[0]->idPv;}else{$PROVINCE_ID = "";}
    if(!empty($daddress[0]->idAp)){$AMPHUR_ID = $daddress[0]->idAp;}else{$AMPHUR_ID = "";}
    if(!empty($daddress[0]->idTb)){$DISTRICT_ID = $daddress[0]->idTb;}else{$DISTRICT_ID = "";}
    if(!empty($daddress[0]->PostCode)){$inputposcode = $daddress[0]->PostCode;}else{$inputposcode = "";}
    
    

?>
<nav aria-label="breadcrumb">
<!-- <img src="assets/file/img/Loading.gif" class="rounded"></td>
<img src="assets/file/img/Loading.gif" class="rounded-circle"> -->
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">TarnSpot</a></li>
    <li class="breadcrumb-item"><a href="#">การจัดส่ง</a></li>
    <?php if($param == "add"): ?>
    <li class="breadcrumb-item active" aria-current="page">สร้างการจัดส่ง</li>
     <?php else: ?>
     <li class="breadcrumb-item active" aria-current="page">แก้ไขการจัดส่ง</li>
    <?php endif; ?>
  </ol>
</nav>
<div class="row" style="font-size: 12px;">
  <div class="col-lg-8 mb-12">
    <div class="row"> 

      <form id="formsave"  class="col-lg-12 mb-12">
        <?php echo csrf_field(); ?>
        <!-- เพิ่มรายการการจัดส่ง -->
        <div class="card shadow mb-4">
          <div class="card-header py-3">
            <?php if($param == "add"): ?>
            <h6 class="m-0 font-weight-bold text-primary">สร้างการจัดส่ง </h6>
            <?php else: ?>
            <h6 class="m-0 font-weight-bold text-primary">แก้ไขใการจัดส่ง </h6>
            <?php endif; ?>
          </div>
          <div class="card-body">
            <div class="form-row">
              <div class="form-group col-12 col-md-12" id="cusold">
                <div class="form-row">
                  <?php if($param == "edit"): ?>
                  <div class="col-md-4 form-group">
                    <div class="row gutters-xs">
                      <div class="col">
                        <input type="text" class="form-control form-control-sm" id="ipDoc" name="ipDoc" placeholder="เลขที่รายการ" value="<?php echo $DocCodemt; ?>" readonly>
                        <input type="hidden" class="form-control form-control-sm" id="idMt" name="idMt" placeholder="เลขที่รายการ" value="<?php echo $idMt; ?>" >
                        
                      </div>
                    </div>
                  </div>
                  <?php endif; ?> 
                  <div class="col-md-10 form-group">
                    <div class="row gutters-xs">
                      <div class="col">
                       <input type="hidden" class="form-control form-control-sm" id="idAdd" name="idAdd"  value="<?php echo $idAdd; ?>" readonly>
                        <input type="hidden" class="form-control col-md-7" id="idpsuser" name="idpsuser" value="<?php echo $idsub; ?>">
                        <input type="text" name="username" id="username" class="form-control form-control-sm" placeholder="ชื่อลูกค้า"  value="<?php echo $SupName; ?>" readonly>
                      </div>
                      <div class="col">
                        <input type="text" name="inputtel" id="inputtel" class="form-control form-control-sm" placeholder="เบอร์โทร"  value="<?php echo $Mobile1; ?>" >
                      </div>
                      <span class="col-auto">
                        <button class="btn btn-outline-primary btn-sm" id="supfide" type="button"  data-toggle="modal" data-target="#personModal"><i class="fas fa-search"></i> ค้นหาลูกค้า</button>
                      </span>
                    </div>
                  </div>
                  <div class="col-md-12 form-group">
                    <div class="row gutters-xs">
                      <div class="col"> 
                        <textarea type="text" name="vAddold" id="vAddold" class="form-control form-control-sm"   readonly><?php echo $vadd; ?></textarea>
                      </div>
                      <span class="col-auto">
                        <button class="btn btn-outline-primary btn-sm" id="payfide" type="button"  data-toggle="modal" data-target="#payModal"><i class="fas fa-map-marked-alt"></i> ยืนยันที่อยู่จัดส่ง</button>
                      </span>
                      <span class="col-auto">
                        <button class="btn btn btn-outline-info btn-sm" id="" type="button"  data-toggle="modal" data-target="#AddPayModalCenter"><i class="fas fa-plus-circle"></i> สร้างที่อยู่จัดส่ง</button>
                      </span>
                    </div>
                  </div>
                  <div class="col-md-4 form-group">
                   
                      <select id="inputdtransp" name="inputdtransp" class="form-control">
                        <option value="">-- ยังไม่จัดส่ง -- </option>
                        <?php $__currentLoopData = $dtransp; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($x->id_trans); ?>"<?php echo e(($x->id_trans == $id_Transt)?" selected":""); ?>><?php echo e($x->name_transport); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                     
                    </select>
                  </div>
                  <div class="col-md-4 form-group">
                    <div class="row gutters-xs">
                        <div class="input-group input-group-sm mb-8" style="padding-left: 5%">
                            <div class="input-group-prepend">
                                <span class="input-group-text" id="inputGroup-sizing-sm">ราคาค่าขนส่ง/บาท</span>
                            </div>
                            <input type="number" class="form-control" style="text-align: right;" id="inputpricetarn" name="inputpricetarn" value="<?php echo $inputpricetarn; ?>" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
                        </div>
                    </div>
                  </div>
                  <div class="col-md-4 form-group">
                    <div class="row gutters-xs">
                        <div class="input-group input-group-sm mb-8" style="padding-left: 5%">
                            <div class="input-group-prepend">
                                <span class="input-group-text" id="inputGroup-sizing-sm">tracking</span>
                            </div>
                            <input type="text" class="form-control" style="text-align: right;" id="inputtracking" name="inputtracking" value="<?php echo $inputtracking; ?>" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
                        </div>
                    </div>
                  </div>
                  <div class="col-md-3 form-group"style="padding-left: 10px">
                    <div class="row gutters-xs">
                        <div class="input-group input-group-sm mb-8" style="padding-left: 5%">
                            <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" value="<?php echo e(Datefor($inputtimeStart)); ?>" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
                        </div>
                    </div>
                  </div>
                  
                </div>
              </div>
              <div class="form-group col-12 col-md-12">
              <div class="form-row">
                <div class="form-group col-md-12">
                  <label for="inputNote" style="font-size: 14x;">หมายเหตุ: </label>
                  <textarea type="text" class="form-control form-control-sm" name="inputNote" id="inputNote" rows="3" ><?php echo $inputNote; ?></textarea>
                </div>
                </div>
              </div>
            </div>
        </div>

    <!-- ตารางสินค้า -->
    <div class="form-group col-md-12"style="font-size: 12px;" >
    <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: #043F8E;font-size: 14px; ">กำหนดสินค้าที่ต้องการทำใบสั่งซื้อ</p></div>
          <div class="col-lg-6 mb-6" style="text-align: right;padding-bottom: 25px;"><button type="button" id="fidePd" class="btn btn-outline-primary btn-sm"data-toggle="modal" data-target="#ShowPdModal" ><i class="fas fa-plus-circle"></i> เลือกสินค้าจาการขาย</button></div>
        </div>
      </div>

      <div class="col-lg-12 mb-12">
        <div class="table-responsive">
          <table class="table table-sm" >
            <thead>
              <tr>
                <th class="text-nowrap" scope="col" style="text-align: center;">#</th>
                <th class="text-nowrap" scope="col" style="text-align: center;">BATCH NO.</th>
                <th class="text-nowrap" 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: center;">จำนวนขาย</th>
                <th class="text-nowrap" scope="col" style="text-align: center;">จำนวน Packing</th>
              </tr>
            </thead>
            <tbody id="trpdlot">
            <?php if($param == "add"): ?>
            <?php else: ?>
            <?php $i=1;
            ?>
            <?php $__currentLoopData = $dt; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td style="text-align: center; color: #C2185B;">
                <a  href="#" onclick="deleteRow('<?php echo e($x->id_saleDt); ?>')"><font color="#D50000"> ลบ</font></a><input type="hidden" name="idlotTK[]" value="<?php echo e($x->id_lot); ?>"><input type="hidden" name="idsaleDtK[]" value="<?php echo e($x->id_saleDt); ?>">
                <input type="hidden" name="idPdK[]" value="<?php echo e($x->id_pd); ?>"><input type="hidden" name="iddtK[]" value="<?php echo e($x->id_saleDt); ?>"><input type="hidden" name="idmtK[]" value="<?php echo e($x->id_saleMt); ?>">
                <input type="hidden" name="numdefK[]" value="">
                </td>
                <td class="text-nowrap"style="text-align: center;"><input style="text-align: right; width:100px;" type="hidden" class="form-control form-control-sm" maxlength="9"  name="numlotTK[]" id="numlotT" value="<?php echo e($x->numlot); ?>"><?php echo e($x->numlot); ?></td>
                <td class="text-nowrap" style="text-align: left; color: #00897B;"><input type="hidden" name="namepdTK[]" value="<?php echo e($x->PdName); ?>">
                  <?php echo e($x->PdName); ?></td>
                <td style="text-align: right;"><?php echo e(number_format($x->Amout)); ?></td>
                <td style="text-align: right;"><?php echo e(number_format($x->Amout)); ?></td>
                <td style="text-align: right;padding-left: 30px;">
                  <?php echo e(number_format($x->Amout)); ?>

                  <input style="text-align: right; width:100px;" type="hidden"  class="form-control form-control-sm" maxlength="9"  name="AmountTarnK[]" id="AmountTarn" value="<?php echo e($x->Amout); ?>"></td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
            </tbody>
          </table>
        </div>
      </div>

      <div class="col-lg-12 mb-12" style="margin-top: 120px;">
        <div class="row">
          <div class="col-lg-12 mb-12">
            <div class="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: #0C4973;font-size: 16px; ">กำหนดโปรโมชั่นที่ต้องการใช้งาน</p></div>
                  <div class="col-lg-6 mb-6" style="text-align: right;"><button type="button" class="btn btn-outline-info btn-sm" onClick="showpomo()"><i class="fas fa-plus-circle"></i> เพิ่มโปรโมชั่น</button></div> -->
                </div>
              </div>
              <div class="col-lg-8 mb-8" id="carddic">
              </div>
            </div>
          </div>
        </div> 
      </div>
      <div style="text-align: right; ">
      
        <?php if($param == "add"): ?>
          <button type="button" id="btSm" class="btn btn-primary">บันทึกรายการ</button>
        
        <?php else: ?>
          <button type="button" id="btedittarn" class="btn btn-info">บันทึกแก้ไข</button>
        <?php endif; ?>
        
      </div>   
    </div>  
  </div>   
</div>
</div>
</form>
</div> 
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="personModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">รายชื่อลูกค้ารอจัดส่งของ</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="input-group no-border col-8 mt-2 ml-auto pr-1"  style="padding-bottom: 20px">
          <input type="text" value="" class="form-control"  id="myInputCus"  onkeyup="CusAllSearch()" placeholder="Search...">
          <div class="input-group-append">
            <div class="input-group-text">
              <i class="dropdown-icon fe fe-search"></i>
            </div>
          </div>
        </div>
        <table class="table card-table table-sm" style="color: #00897B;">
          <thead>
            <tr>
              <th style="text-align: center; width: 30px;">ลำดับ</th>
              <th> รายชื่อ </th>
              <th style="text-align: center; width: 100px;">ตัวเลือก</th>
            </tr>
          </thead>
          <tbody id="persontd">

          </tbody>
        </table>
      </div>

    </div>
  </div>
</div>

<!-- Modal addที่อยู่ใหม่ -->
<div class="modal fade" id="AddPayModalCenter" tabindex="-1" role="dialog" aria-labelledby="AddPayModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="AddPayModalLongTitle">สร้างที่อยู่จัดส่งใหม่</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="row">
          <div class="col-lg-12 mb-12">
            <div class="row">
              <form action="<?php echo url('savetarn'); ?>" method="post" id="form133355" class="col-lg-12 mb-12">
                <?php echo csrf_field(); ?>
                <!-- เงื่อนไขการที่อยู่ -->
                <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-12">
                        <div class="form-group col-md-12">
                          <div class="form-row">
                            <div class="col-md-12 form-group">
                              <label>ชื่อผู้รับ
                                <span class="form-required">*</span>
                              </label>
                              <div class="row gutters-xs">
                                <div class="col">
                                  <input type="hidden" class="form-control col-md-7" id="idpssuppay" name="idpssuppay" value="<?php echo $idsub; ?>">
                                  <input type="text" name="suppayname" id="suppayname" class="form-control" placeholder="ชื่อผู้รับ">
                                </div>  
                              </div>
                            </div>
                            <div class="col-md-12 form-group">
                              <label>เบอร์ติดต่อ
                                <span class="form-required">*</span>
                              </label>
                              <div class="row gutters-xs">
                                <div class="col">
                                  <input type="text" name="inputtalModel" id="inputtalModel" class="form-control" placeholder="เบอร์ติดต่อ">
                                </div>  
                              </div>
                            </div>
                            <div class="col-md-12 form-group">
                              <label>ที่อยู่จัดส่ง
                                <span class="form-required">*</span>
                              </label>
                              <div class="row gutters-xs">
                                <div class="col">
                                  <input type="hidden" class="form-control" name="vAdd" id="vAdd" value="" >
                                  <input type="text" name="inputAddModel" id="inputAddModel" class="form-control" onkeyup="readd()" placeholder="ที่อยู่จัดส่ง">
                                </div>  
                              </div>
                            </div>
        
                          </div>
                          <div class="form-row"  style="font-size: 14px;">
                            <div class="form-group col-md-6">
                              <label for="inputProvince">จังหวัด</label>
                              <span class="form-required" style="color: #CC0000">*</span>
                              <select id="inputProvince" name="inputProvince" class="form-control">
                                <option value="">-- กรุณาเลือก --</option>
                                <?php $__currentLoopData = $province; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($x->PROVINCE_ID); ?>"<?php echo e(($x->PROVINCE_ID == $PROVINCE_ID)?" selected":""); ?>><?php echo e($x->PROVINCE_NAME); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                              </select>
                            </div>
                            <div class="form-group col-md-6" style="font-size: 14px;">
                              <label >อำเภอ</label>
                              <span class="form-required" style="color: #CC0000">*</span>
                              <select id="inputAmphur" name="inputAmphur" class="form-control">
                                <option value="">-- กรุณาเลือกจังหวัดก่อน --</option>
                                <?php if($param == "add"): ?>
                                <?php else: ?>
                                
                                <?php endif; ?>
                              </select>
                            </div>
                            <div class="form-group col-md-6" style="font-size: 14px;">
                              <label for="inputDistrict">ตำบล</label>
                              <span class="form-required" style="color: #CC0000">*</span>
                              <select id="inputDistrict" name="inputDistrict" class="form-control">
                                <option value="">-- กรุณาเลือกอำเภอก่อน --</option>
                                <?php if($param == "add"): ?>
                                <?php else: ?>
                               
                                <?php endif; ?>
                              </select>
                            </div>
                            <div class="form-group col-md-6" style="font-size: 14px;">
                              <label for="inputposcode">รหัสไปรษณีย์</label>
                              <input type="text" class="form-control" name="inputposcode" onkeyup="readd()"  value="<?php echo $inputposcode; ?>" id="inputposcode">
                            </div>
                           
                          </div>
                            <div class="form-group">
                              <label for="inputnotModel">หมายเหตุ</label>                         
                              <textarea  type="text" class="form-control" name="inputnotModel" id="inputnotModel"  placeholder=""></textarea>
                            </div>
                          </div>
                          
                      </div>
                    </div>
                    <div style="text-align: right;">
                     
                   </div>       
                 </div>
               </div>
        
        
             </form>
           </div>
         </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="Addnewadd">Save changes</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal -->
<div class="modal fade" id="payModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">ที่อยู่จัดส่งของลูกค้า</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" id="modalcard">    
        <table class="table card-table table-sm" cellspacing="0" cellpadding="0" style="border: none;" >
          <tbody id="addresstd">
          </tbody>
        </table>
      </div>

    </div>
  </div>
</div>

<!-- ModalPd -->
<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">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #004D40;">สินค้ารอจัดส่ง</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-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: left;">ชื่อสินค้า</th>
                <th scope="col" style="text-align: center;">BATCH NO.</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>
            <tbody id="ListPdDetail">

                
            </tbody>
          </table>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="add2cas">เลือกสินค้า</button>
      </div>
    </div>
  </div>
</div>

</div>

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

$(function() {
  $('.selectpicker').selectpicker();
});

  $("input[name='phase_type']").change(function() {
    if($("#inlineRadio1").prop('checked')==true){
      $("#idpsuser").val('');
      $("#username").val('');
      $("#vAddold").val('');
      $("#idAdd").val('');
      $("#cusnew").show(200);
      $("#cusnew2").show(200);
      $("#cusold").hide(100);
    }
    else if($("#inlineRadio2").prop('checked')==true){
      $("#cusold").show(200);
      $("#cusnew").hide(100);
      $("#cusnew2").hide(100);
    }

  });

  function getGetUser(ids,sname,numbe,Mobile1){
    $("#username").val(sname);
    $("#idpsuser").val(ids);
    $("#vnumsup").val(numbe);
    $("#idpssuppay").val(ids);
    $("#suppayname").val(sname);
    $("#inputtel").val(Mobile1);
    $("#personModal").modal('toggle');
    

    $.ajax({
      url:'<?php echo e(url("address")); ?>',
      data:{idcus:ids},
      type:'GET',
      dataType:'json',
      cache:false,
      success:function(ret){

       $("#vAdd").empty()
       sc = ret["ad"];
      // $("#vAddold").val(sc[0].AddressText);
      // $("#idAdd").val(sc[0].idAdd);

     },
     error:function(err){
      alert('Error');
    }
  });
      
  }

  function getGetAdd(idAdd,AddressText,Mobile1,NameUser){
 
    $("#username").val(NameUser);
    $("#vAddold").val(AddressText);
    $("#inputtel").val(Mobile1);
    $("#idAdd").val(idAdd);
    
    $("#payModal").modal('toggle');
  }

  $(function(){

    // var rcount = 1;
    // $("#Addpd2cart").click(function(){
     
    //   var namepd = $("#pdnameadd").val();
    //   var price = $("#priceadd").val();
    //   var amonuseadd = 0;
    //   var idunit = $("#select-testing").val();
    //   var unit = $("#unit").text();
    //   var inputnoteadd = $("#inputnoteadd").val();

    //   if(($("#pdnameadd").val() == "")){
    //     swal({
    //       title: "ไม่สามารถเพิ่มได้ !!!",
    //       text: "กรุณาเพิ่มชื่อสินค้า",
    //       icon: "info",
    //       button: "ตกลง",
    //     });

    //     return false;

    //   }

    //   $("#trpdlot").append(''
    //     +'<tr>'
    //     +'<td scope="row" style="text-align: center;"><input type="hidden" name="idunit[]" value="'+idunit+'"><input type="hidden" name="idmaterial[]" value=""><input type="hidden" name="inputnoteadd[]" value="'+inputnoteadd+'" readonly="">'
    //     +'. '
    //     +'</td>'
    //     +'<td class="text-nowrap" style="text-align: left; color: #00897B;"><input type="hidden" name="namepdT[]" value="'+namepd+'">'
    //     +namepd
    //     +'</td>'
    //     +'<td class="text-nowrap"style="text-align: right;"><input style="text-align: right; width:100px;" type="number" class="form-control form-control-sm" maxlength="9"  name="amoun[]" id="amoun" onchange="SumPrice(this)" value="'+amonuseadd+'"></td>'
    //     +'<td style="text-align: right;"><input style="text-align: right; width:100px;" type="number" onchange="SumPrice(this)" class="form-control form-control-sm" maxlength="9"  name="inputpice[]" id="inputpice" value="'+price+'"></td>'
    //     +'<td class="font-weight-bold"><input class="form-control form-control-sm font-weight-bold price_mtr" type="text" name="num_mtr[]" style="text-align: right; color: #1E88E5;width:100px;"  value="0" readonly=""></td>'
    //     +'<td style="text-align: center; color: #C2185B;">'
    //     +'<a onclick="deleteRow(this)"><font color="#D50000"> ลบ</font></a> <input type="hidden" name="num_mtrT[]">'
    //     +'</td>'
    //     +'</tr>'
    //     );

    //   rcount++;
    //   SumPrice();
    //   $("#AddPDModalCenter").modal('toggle');
    //     $("#pdnameadd").val("");
    //     $("#priceadd").val("");
    //     $("#inputUnitadd").val("");
    //     $("#unit").text("");
    // });

    $("#supfide").click(function(){
      $.ajax({
        url:'<?php echo e(url("fidecus2w8tarn")); ?>',
        /* data:{CompName:$("#findcompname").val()},*/
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          items = ret;
          itemsx = ret["daad"];
          $("#persontd").empty();
          var rows = 1;
        
          for(x in items){
                //str = '<tr><td >'+ rows +'</td><td style="text-align:left">'+items[x].CompName+'</td><td ><button type="button" class="btn btn-default" onclick="getCus('+x+')">เลือก</button> </td></tr> ';
                str = '<tr><td >'+ rows +'</td><td style="text-align:left padding: 0px;"><a>'+items[x].CusName+' '+items[x].LastName+'</a></td><td style="padding: 0px; text-align: center;"><a class="btn btn-primary btn-sm" style="color:#FFF" onclick="getGetUser('+ret[x].idCus+',\''+ret[x].CusName+'\',\''+ret[x].LastName+'\',\''+ret[x].Mobile1+'\')">เลือก</a> </td></tr> ';
                $("#persontd").append(str);
                rows++;
              }
            },
            error:function(err){
              alert('Error');
              //console.log(err.responseText);
            }
          });
    });

    $("#payfide").click(function(){
      if(($("#idpsuser").val() == "")){
        swal("กรุณาเลือกลูกค้าก่อน");
        return false;
      }
      $.ajax({
        url:'<?php echo e(url("fideadd2Cus")); ?>',
        data:{idsup:$("#idpsuser").val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          items = ret;
          $("#addresstd").empty();
          var rows = 1;
          var img = "";
          var noacc = "";
          for(x in items){
            str='<tr>'
              +'<td>'
                +' <a onclick="getGetAdd('+items[x].idAdd+',\''+items[x].AddressText+'\',\''+items[x].Mobile1+'\',\''+items[x].NameUser+'\')"><div class="card" style="width: 29rem;">'
                  +'<div class="card-body">'
                    +'<div class="container">'
                      +'<div class="row">'
                        +' <div class="col-sm-2" style=" padding-top: 40px;">'
                          +'<img style="box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); " width="40"  height="40" src="https://map.teedd360.com/wp-content/uploads/2021/01/placeholder.png" alt="..." class="rounded">'
                        +'</div>'
                        +'<div class="col-sm">'
                         +' <h5 class="card-title" style="color: #2D3857;">'+items[x].NameUser+'</h5>'
                         +' <h6 class="card-subtitle"style="color: #58595A;" > ที่อยู่จัดส่ง :<span style="color: #8E8F92;"> '+items[x].AddressText+' </span></h6>'
                         +' <p class="card-text" style="color: #8E8F92;"> <span style="color: #58595A;"> เบอร์ติดต่อ : </span>'+items[x].Mobile1+'</p>'
                        +' </div>'
                     +' </div>'
                    +' </div>'
                    +' <a href="#" class="card-link"></a>'
                    +' <a href="#" class="card-link"></a>'
                    +'</div>'
                  +'</div></a>'
                +'</td>'
            +'</tr>' ;
                
                $("#addresstd").append(str);
                rows++;
              }
            },
            error:function(err){
              // alert('Error');
              console.log(err.responseText);
            }
          });
    });

    $("#fidePd").click(function(){
      if(($("#idpsuser").val() == "")){
        swal("กรุณาเลือกลูกค้าก่อน");
        return false;
      }
      $.ajax({
        url:'<?php echo e(url("fidePd2Cus")); ?>',
        data:{idsup:$("#idpsuser").val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          items = ret;
          $("#ListPdDetail").empty();
          var rows = 1;
          var img = "";
          var noacc = "";
          for(x in items){

            str = '<tr>'
                    +'<td class="text-nowrap"style="text-align: center;"><input type="checkbox" name="chkItem[]" id="chkItem'+items[x].idSaleDt+'" value="'+items[x].idSaleDt+'"></td>'
                    +'<td class="text-nowrap" style="text-align: left; color: #00796B; font-weight: bold;"> '+items[x].PdName+'</td>'
                    +'<td class="text-nowrap" style="text-align: center;">'+items[x].LotNo+'</td>'
                    +'<td class="text-nowrap" style="text-align: right;">'+numeral(items[x]["AmountTarn"]).format('0,0')+'</td>'
                    +'<td class="text-nowrap" style="text-align: right;">'+numeral(items[x]["SumAmount"]).format('0,0')+'</td>'
                    +'<td class="text-nowrap"style="text-align: center;"> ชิ้น </td>'
                    +'<td class="text-nowrap"style="text-align: center;">'+items[x].DocCode+'</td>'
                    +'<td class="text-nowrap"style="text-align: center;">'+items[x].Psname+'</td>'
                  +'</tr>';                      
                $("#ListPdDetail").append(str);
                rows++;
              }
            },
            error:function(err){
              // alert('Error');
              console.log(err.responseText);
            }
        });
    });

    $("#add2cas").click(function(){
      var rcount = 1;
      $("input:checkbox:checked").each(function () {
        //alert($(this).attr('id'));
        var iddt = $(this).attr('value');
          $.ajax({
          url:'<?php echo e(url("fidePddt2Cus")); ?>',
          data:{idsaledt:iddt},
          type:'GET',
          dataType:'json',
          cache:false,
          success:function(ret){
          
            items = ret;           
            var rows = 1;
            var img = "";
            var noacc = "";
            for(x in items){
              str = '<tr>'
                      +'<td style="text-align: center; color: #C2185B;">'
                      +'<a onclick="deleteRowNew(this)"><font color="#D50000"> ลบ</font></a><input type="hidden" name="idlotT[]" value="'+items[x].idPdPkLot+'"><input type="hidden" name="idsaleDt[]" value="'+items[x].idSaleDt+'">'
                      +'<input type="hidden" name="idPd[]" value="'+items[x].idPdPk+'"><input type="hidden" name="iddt[]" value="'+iddt+'"><input type="hidden" name="idmt[]" value="'+items[x].idSale+'">'
                      +'<input type="hidden" name="numdef[]" value="'+items[x].DocCode+'">'
                      +'</td>'
                      +'<td class="text-nowrap"style="text-align: center;"><input style="text-align: right; width:100px;" type="hidden" class="form-control form-control-sm" maxlength="9"  name="numlotT[]" id="numlotT" value="'+items[x].LotNo+'">'+items[x].LotNo+'</td>'
                      +'<td class="text-nowrap" style="text-align: left; color: #00897B;"><input type="hidden" name="namepdT[]" value="'+items[x].PdName+'">'
                      +items[x].PdName+'</td>'
                      +'<td style="text-align: right;">'+numeral(items[x]["SumAmount"]).format('0,0')+'</td>'
                      +'<td style="text-align: right;">'+numeral(items[x]["AmountTarn"]).format('0,0')+'</td>'
                      +'<td style="padding-left: 30px;"><input style="text-align: right; width:100px;" type="number"  class="form-control form-control-sm" maxlength="9"  name="AmountTarn[]" id="AmountTarn" value="'+items[x]["AmountTarn"]+'"></td>'
                    +'</tr>';                      
                  $("#trpdlot").append(str);
                  rows++;
                }
              },
              error:function(err){
                // alert('Error');
                console.log(err.responseText);
              }
          });
        $("#ShowPdModal").modal('toggle');
      });
    });


    $("#Addnewadd").click(function(){
      
      $.ajax({
        url:'<?php echo e(url("addnewadd")); ?>',
        data:{idsup:$("#idpssuppay").val(),name:$("#suppayname").val(),inputtalModel:$("#inputtalModel").val(),inputAddModel:$("#inputAddModel").val(),vAdd:$("#vAdd").val(),PROVINCE_ID:$("#inputProvince").val(),AMPHUR_ID:$("#inputAmphur").val(),DISTRICT_ID:$("#inputDistrict").val(),inputposcode:$("#inputposcode").val(),inputnotModel:$("#inputnotModel").val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          console.log(ret);
          items = ret["daad"];
          $("#idAdd").empty();
          $("#username").empty();
          for(x in items){

          $("#idAdd").val(items[x].idAdd);
          $("#vAddold").val(items[x].AddressText);
          $("#username").val(items[x].NameUser);
          $("#inputNote").val(items[x].note);
          $("#inputtel").val(items[x].Mobile1);
            }
            $("#inputtalModel").val('');
            $("#inputAddModel").val('');
            $("#vAdd").val('');
            $("#inputnotModel").val('');
            $('#AddPayModalCenter').modal('hide');
          },
          error:function(err){
            alert('Error');
          }
        });
    });

    

  });

  $(function(){
    $("#inputPay").change(function(){
      if($('#inputPay').val() == 1 || $('#inputPay').val()== 4){
        $("#divPay2").show(200);
        $("#divPay").show(100);
      }else{
        $("#inputnoAcc").val("");
        $("#divPay2").hide(200);
        $("#divPay").hide(100);
      }      
    })
  })

  $('#btSm').click(function(){
    row = $("#trpdlot tr").length;

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

        return false;

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

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

        return false;
        }else if(row == 0){
        swal({
          title: "ไม่สามารถบันทึกได้ !!!",
          text: "กรุณาเพิ่มรายการสินค้า",
          icon: "info",
          button: "ตกลง",
        });

        return false;
        }else{
      swal({
        title: "การบันทึกข้อมูล",
        text: "คุณต้องการบันทึกหรือไม่",
        icon: "warning",
        buttons: true,
        dangerMode: true,
      })
      .then((willSuccess) => {
        if (willSuccess) {
          $(".md-Load").show();
          //$("#form1").submit();
          var form1 = $('#formsave')[0];
          var formData = new FormData(form1);
            $.ajax({
              url:'<?php echo e(url('adddatanewtarn')); ?>',
                      headers: {
                          'X-CSRF-TOKEN': $('input[name="_token"]').val()
                      },
                      data: formData,
                      type: 'POST',
                      contentType: false,
                      processData: false,
                      cache:false,
                      success:function(ret){
                      $("#loadPage").hide();
                      swal({
                          text: "บันทึกข้อมูลเรียบร้อยแล้ว",
                          icon: "success",
                      })
                     
                      window.location.replace("<?php echo e(url('approvewihtpack')); ?>");
                      
                  },
                  error:function(err){
                      console.log(err);
                      $("#error").html(err.responseText);
                      $("#modal_error").modal('show');
                  }
              });
        } else {
          swal("ยกเลิกการบันทึก");
        }
      });

    }
  })


  $('#btedittarn').click(function(){
    row = $("#trpdlot tr").length;

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

        return false;

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

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

        return false;
        }else if(row == 0){
        swal({
          title: "ไม่สามารถบันทึกได้ !!!",
          text: "กรุณาเพิ่มรายการสินค้า",
          icon: "info",
          button: "ตกลง",
        });

        return false;
        }else{
      swal({
        title: "การบันทึกข้อมูล",
        text: "คุณต้องการบันทึกหรือไม่",
        icon: "warning",
        buttons: true,
        dangerMode: true,
      })
      .then((willSuccess) => {
        if (willSuccess) {
          $(".md-Load").show();
           //$("#form1").submit();

          var form1 = $('#formsave')[0];
          var formData = new FormData(form1);
            $.ajax({
              url:'<?php echo e(url('editdatanewtarn')); ?>',
                      headers: {
                          'X-CSRF-TOKEN': $('input[name="_token"]').val()
                      },
                      data: formData,
                      type: 'POST',
                      contentType: false,
                      processData: false,
                      cache:false,
                      success:function(ret){
                      $("#loadPage").hide();
                      swal({
                          text: "บันทึกข้อมูลเรียบร้อยแล้ว",
                          icon: "success",
                      })
                      
                      window.location.replace("<?php echo e(url('approvewihtpack')); ?>");
                      
                  },
                  error:function(err){
                      console.log(err);
                      $("#error").html(err.responseText);
                      $("#modal_error").modal('show');
                  }
              });
        } else {
          swal("ยกเลิกการบันทึก");
        }
      });

    }
  })
   
  function readd() {
    $("#vAdd").val($("#inputAddModel").val()+" "+ $("#inputDistrict option:selected").text() +" "+ $("#inputAmphur option:selected").text() +"จังหวัด"+ $("#inputProvince option:selected").text() +""+ $("#inputposcode").val());
  }

  function show(){

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

  function showpomo(){

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

  function deTailTranGB(id,e,s){

    $.ajax({
      url:'<?php echo e(url("finepdstock")); ?>/'+id,
      type:'GET',
      dataType:'json',
      cache:false,
      success:function(ret){
        console.log(ret);

        var showpd = ret["showpdStock"];

        $("."+e).empty();
        $("."+s).empty();
        var i= 1;
        var amonuse = 0;
        for(x in showpd){
         var textname =  addslashes(showpd[x].PdName);
         amonuse = showpd[x]["Amount"] - showpd[x]["AmountUse"];
         strGB ='<tr style="background: #E0F2F1">'
         +'<td style="width: 3px;">->['+i+']</td>'
         +'<td style="width: 5px;text-align: left;"><a href="#" class="btn btn-success btn-circle btn-sm" onClick="addpd2chart(\''+textname+'\',\''+showpd[x].Price+'\',\''+showpd[x].idPd+'\',\''+amonuse+'\')"><i class="fas fa-cart-arrow-down"></i></a></td>'
         +'<td style="width: 150px;text-align: left;">'+showpd[x]["LotNum"]+'</td>'
         +'<td style="width: 50px;text-align: left;">'+showpd[x]["datePdCer"]+'</td>'
         +'<td style="width: 50px;text-align: right; color: #00796B; font-weight: bold;">'+amonuse+'</td>'
         +'<td style="width: 50px;text-align: right; color: #E65100; font-weight: bold;">'+showpd[x]["AmountUse"]+'</td>'
         +'<td style="width: 50px;text-align: right; color: #6D4C41; font-weight: bold;">'+showpd[x]["Amount"]+'</td>'
         +'<td style="width: 200px;text-align: center;">'+showpd[x]["Note"]+'</td>'

         +'</tr>';
         $("."+e).append(strGB);
         i++;
       }

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

  function addslashes(str) {
    str = str.replace(/\\/g, '\\\\');
    str = str.replace(/\'/g, '\\\'');
    str = str.replace(/\"/g, '\\"');
    str = str.replace(/\0/g, '\\0');
    return str;
  }

  function PdSearch() {
    var input, filter, tbody, tr, a, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    tbody = document.getElementById("ListPdDetail");
    tr = tbody.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++) {
      a = tr[i].getElementsByTagName("td")[0];
      if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";

      }
    }
  }
  

  function SumPrice(e){

   var tr = $(e).parent().parent();

   price_unit_mtr = tr.find('input[name="amoun[]"]').val();
   price_mtr = tr.find('input[name="inputpice[]"]').val();

        totalrow = numeral(price_mtr).value() * numeral(price_unit_mtr).value();
        tr.find('input[name="num_mtr[]"]').val(numeral(totalrow).format('0,0'));
        tr.find('input[name="num_mtrT[]"]').val(totalrow);
        totalPrice();
        totalNet(); 

   
 }

 function totalPrice(){
  var total = 0;
  $(".price_mtr").each(function( index ) {
    total += numeral($(this).val()).value();
  });
  $('#price_total').val(numeral(total).format('0,0'));
  $('#price_totalT').val(total);
}

function totalNet(){
  var totalNet = 0;
  var total = 0;
  var vatt = 0;
  vatt = ((numeral($("#price_total").val()).value() * 7)/100) ;
  totalNet = numeral($("#price_total").val()).value() + numeral($("#price_tarn").val()).value() + vatt;
  $('#price_totalNet').val(numeral(totalNet).format('0,0'));
  $('#price_totalNetT').val(totalNet);
  $('#price_vat').val(numeral(vatt).format('0,0'));
  $('#price_vatT').val(vatt);
}

function deleteRow(idsaleDt){
  swal({
    title: "Are you sure?",
    text: "ลบสินค้าหรือไม่!",
    icon: "warning",
    buttons: true,
    dangerMode: true,
  })
  .then((willDelete) => {
    if (willDelete) {
      $.ajax({
      url:'<?php echo e(url("deldatatarndt")); ?>/'+idsaleDt,
      type:'GET',
      dataType:'json',
      cache:false,      
        success:function(ret){
          location.reload();
      },
      error:function(err){
        console.log(err);
      }
    });

      swal("ลบสำเร็จ", {
        icon: "success",
      });
    } else {
      swal("ยกเลิกการลบแล้ว!");
    }
  });

}

function deleteRowNew(e){

  tag = $(e).parent().parent();
  tag.remove();
  totalPrice();
  totalNet(); 
}
function addpromo(idpro,name,typepro,codepro,dic,detailpro,date,fulldic){
 $('#price_dis').val(dic);
 $('#price_disT').val(fulldic);

 totalNet();
 $('#carddic').html('<div class="card"><div class="card-header" style="background: #EC407A; color: #FFF">โปรโมชั่นสำหรับโค้ดนี้ ['+codepro+'] <button type="button" class="close"  onclick="deletePro()"><span aria-hidden="true">&times;</span></div><div class="card-body"><input type="hidden" name="idPro" value="'+idpro+'"><h5 class="card-title font-weight-bold" style="color: #880E4F"> ->>โปรโมชั่น '+name+'</h5><p class="card-text">หมายเหตุ : '+detailpro+'</p></div></div>');
 $("#ShowPMModal").modal('toggle');

}
function deletePro(){
  $( "#carddic" ).empty();
}

function CusAllSearch() {
    var input, filter, tbody, tr, td, a, i;
    input = document.getElementById("myInputCus");
    filter = input.value.toUpperCase();
    tbody = document.getElementById("persontd");
    tr = tbody.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++) {
      a = tr[i].getElementsByTagName("a")[0];
      if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";

      }
    }
  }



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

  });

  $(function(){
    $("#inputProvince").change(function(){
      $.ajax({
        url:'<?php echo e(url("fineamphur")); ?>',
        data:{idpv:$('#inputProvince').val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          $("#inputAmphur").empty().append('<option value="">-- กรุณาเลือก --</option>');  
          sc = ret["amphur"];
          for(a in sc){
            $("#inputAmphur").append('<option value="'+sc[a].AMPHUR_ID+'">'+sc[a].AMPHUR_NAME+'</option>');  
          }
        },
        error:function(err){
          alert('Error');
        }
      });
    })
    $("#inputAmphur").change(function(){
      $.ajax({
        url:'<?php echo e(url("finedist")); ?>',
        data:{idAmp:$('#inputAmphur').val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          $("#inputDistrict").empty().append('<option value="">-- กรุณาเลือก --</option>');  
          sc = ret["dist"];
          ps = ret["poscode"];
          
          $("#inputposcode").val(ps[0].POSTCODE);
          for(a in sc){
            $("#inputDistrict").append('<option value="'+sc[a].DISTRICT_ID+'">'+sc[a].DISTRICT_NAME+'</option>');  
          }
        },
        error:function(err){
          alert('Error');
        }
      });
    })
    $("#inputDistrict").change(function(){
      $("#vAdd").empty()
      $("#vAdd").val($("#inputAddModel").val()+" "+ $("#inputDistrict option:selected").text() +" "+ $("#inputAmphur option:selected").text() +"จังหวัด"+ $("#inputProvince option:selected").text() +""+ $("#inputposcode").val());
    })

  })

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

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