<?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";
}

$idCus = "";
$inputNameF = "";
$inputNameS = "";
$inputIden = "";
$inputAdd = "";
$PROVINCE_ID = "";
$AMPHUR_ID = "";
$DISTRICT_ID = "";
$inputposcode = "";
$inputEmail = "";
$inputPhone = "";
$inputPhone2 = ""; 
$inputSocial = "";
$inputnamesocial = "";
$inputPay = "";
$inputNote = "";
$price_tarn = "";
$price_total = "";
$price_dis = "";
$price_totalNet = "";
$idAdd = "";
$vAdd = "";
$inputidMt = "";
$inputDoccode = "";
$inputRef = "";

if(!empty($cus[0]->idCus)){$idCus = $cus[0]->idCus;}else{$idCus = "";}
if(!empty($cus[0]->CusName)){$inputNameF = $cus[0]->CusName;}else{$inputNameF = "";}
if(!empty($cus[0]->LastName)){$inputNameS = $cus[0]->LastName;}else{$inputNameS = "";}
if(!empty($cus[0]->codeInden)){$inputIden = $cus[0]->codeInden;}else{$inputIden = "";}
if(!empty($daddress[0]->Address)){$inputAdd = $daddress[0]->Address;}else{$inputAdd = "";}
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 = "";}
if(!empty($cus[0]->Email)){$inputEmail = $cus[0]->Email;}else{$inputEmail = "";}
if(!empty($cus[0]->Mobile1)){$inputPhone = $cus[0]->Mobile1;}else{$inputPhone = "";}
if(!empty($cus[0]->Mobile2)){$inputPhone2 = $cus[0]->Mobile2;}else{$inputPhone2 = "";}
if(!empty($ordermt[0]->idSocial)){$inputSocial = $ordermt[0]->idSocial;}else{$inputSocial = "";}
if(!empty($ordermt[0]->nameSocial)){$inputnamesocial = $ordermt[0]->nameSocial;}else{$inputnamesocial = "";}
if(!empty($ordermt[0]->idPay)){$inputPay = $ordermt[0]->idPay;}else{$inputPay = "";}
if(!empty($ordermt[0]->Note)){$inputNote = $ordermt[0]->Note;}else{$inputNote = "";}
if(!empty($ordermt[0]->priceTarn)){$price_tarn = $ordermt[0]->priceTarn;}else{$price_tarn = "0";}
if(!empty($ordermt[0]->Total)){$price_total = $ordermt[0]->Total;}else{$price_total = "0";}
if(!empty($ordermt[0]->DiscountAmout)){$price_dis = $ordermt[0]->DiscountAmout;}else{$price_dis = "0";}
if(!empty($ordermt[0]->TotalNet)){$price_totalNet = $ordermt[0]->TotalNet;}else{$price_totalNet = "0";}
if(!empty($daddress[0]->idAdd)){$idAdd = $daddress[0]->idAdd;}else{$idAdd = "";}
if(!empty($daddress[0]->AddressText)){$vAdd = $daddress[0]->AddressText;}else{$vAdd = "";}
if(!empty($ordermt[0]->idSaleOd)){$inputidMt = $ordermt[0]->idSaleOd;}else{$inputidMt = "";}
if(!empty($ordermt[0]->DocCode)){$inputDoccode = $ordermt[0]->DocCode;}else{$inputDoccode = "";}
if(!empty($ordermt[0]->docRef)){$inputRef = $ordermt[0]->docRef;}else{$inputRef = "";}

?>
<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="#">Sale</a></li>
    <?php if($param == "add"): ?>
    <li class="breadcrumb-item active" aria-current="page" style="color:#801709;">สร้างใบแจ้งหนี้ ERP</li>
     <?php else: ?>
     <li class="breadcrumb-item active" aria-current="page" style="color:#801709;">แก้ไขใบแจ้งหนี้ ERP</li>
    <?php endif; ?>
  </ol>
</nav>
<div class="row" style="font-size: 12px;">
  <div class="col-lg-6 mb-12">
    <div class="row">
      <form id="form1" 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" style="color:#801709;">สร้างใบแจ้งหนี้ ERP </h6>
            <?php else: ?>
            <h6 class="m-0 font-weight-bold text-primary" style="color:#801709;">แก้ไขใบแจ้งหนี้ ERP </h6>
            <?php endif; ?>
          </div>
          <div class="card-body">
            <div class="form-row">
              <div class="form-group col-md-12" style="font-size: 16px;">
                <div class="form-group col-md-12" style="text-align: button; color: #00897B; ">
                  <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" checked="checked" name="phase_type" id="inlineRadio1" value="option1">
                    <label class="form-check-label" for="inlineRadio1">ลูกค้าใหม่</label>
                  </div>
                  <?php if($param == "add"): ?>
                  <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="phase_type" id="inlineRadio2" value="option2">
                    <label class="form-check-label" for="inlineRadio2">ลูกค้าที่เคยซื้อไปแล้ว</label>
                  </div>
                   <?php else: ?>
                   <?php endif; ?>
                   <div class="form-group col-md-12">
                       
                  </div>
                </div>
                <div class="form-group col-md-12">
                    <div class="form-row">
                        <div class="form-group col-12 col-md-4">
                            <label for="inputRef" style="font-size: 12px;">เลขที่อ้างอิง</label>
                            <span class="form-required" style="color: #CC0000">*</span>
                            <input type="text" class="form-control form-control-sm" name="inputRef" id="inputRef" value="<?php echo $inputRef; ?>" id="inputRef" >
                        </div>
  
                    </div>
                </div>
                <div class="form-group col-md-12" id="cusnew">
                  <div class="form-row">
                    <div class="form-group col-12 col-md-4">
                    <label for="inputNameF" style="font-size: 12px;">ชื่อ</label>
                    <span class="form-required" style="color: #CC0000">*</span>
                    <input type="hidden"  name="inputDoccode" id="inputDoccode" value="<?php echo $inputDoccode; ?>">
                    <input type="hidden"  name="inputidMt" id="inputidMt" value="<?php echo $inputidMt; ?>">
                    <input type="text" class="form-control form-control-sm" name="inputNameF" id="inputNameF" value="<?php echo $inputNameF; ?>" placeholder="">
                  </div>
                  <div class="form-group col-12 col-md-4">
                    <label for="inputNameS" style="font-size: 12px;">สกุล</label>
                    <span class="form-required" style="color: #CC0000">*</span>
                    <input type="text" class="form-control form-control-sm" name="inputNameS" id="inputNameS"  value="<?php echo $inputNameS; ?>" placeholder="">
                  </div>

                  </div>
                </div>

                <div class="form-group col-md-12" id="cusnew2">
                  <div class="form-row">
                    <div class="form-group col-12 col-md-4">
                      <label for="inputIden" style="font-size: 12px;">เลขที่ผู้เสียภาษี</label>
                      <input type="number" class="form-control form-control-sm" name="inputIden" id="inputIden" value="<?php echo $inputIden; ?>">
                    </div>
                    <div class="form-group col-12 col-md-4">
                      <label for="inputPhone" style="font-size: 12px;">เบอร์โทร[1]</label>
                      <!-- <span class="form-required" style="color: #CC0000">*</span> -->
                      <input type="number" class="form-control form-control-sm" name="inputPhone" value="<?php echo $inputPhone; ?>" id="inputPhone">
                    </div>
                    <div class="form-group col-12 col-md-4">
                      <label for="inputPhone2" style="font-size: 12px;">เบอร์โทร[2]</label>
                      <input type="number" class="form-control form-control-sm" name="inputPhone2" value="<?php echo $inputAdd; ?>" id="inputPhone2">
                    </div>
                  </div>
                  <div class="form-row">
                    <div class="form-group col-12 col-md-4">
                        <label for="vAdd" style="font-size: 12px;">ที่ตั้ง</label>
                        <input type="hidden" class="form-control form-control-sm" name="vAdd" id="vAdd" readonly="" value="<?php echo $vAdd; ?>">
                        <input type="text" class="form-control form-control-sm" name="inputAdd" id="inputAdd" value="<?php echo $inputAdd; ?>" onkeyup="readd()" placeholder="">
                        </div>
                        <div class="form-group col-12 col-md-4">
                          <label for="inputProvince" style="font-size: 12px;">จังหวัด</label>
                          <span class="form-required" style="color: #CC0000">*</span>
                          <select id="inputProvince" name="inputProvince" class="form-control form-control-sm">
                            <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>
                  <div class="form-row">
                    <div class="form-group col-12 col-md-4">
                      <label style="font-size: 12px;">อำเภอ</label>
                      <span class="form-required" style="color: #CC0000">*</span>
                      <select id="inputAmphur" name="inputAmphur" class="form-control form-control-sm">
                        <option value="">-- กรุณาเลือกจังหวัดก่อน --</option>
                        <?php if($param == "add"): ?>
                        <?php else: ?>
                        <?php $__currentLoopData = $amphur; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($x->AMPHUR_ID); ?>"<?php echo e(($x->AMPHUR_ID == $AMPHUR_ID)?" selected":""); ?>><?php echo e($x->AMPHUR_NAME); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                      </select>
                    </div>
                    <div class="form-group col-12 col-md-4">
                      <label for="inputDistrict" style="font-size: 12px;">ตำบล</label>
                      <span class="form-required" style="color: #CC0000">*</span>
                      <select id="inputDistrict" name="inputDistrict" class="form-control form-control-sm">
                        <option value="">-- กรุณาเลือกอำเภอก่อน --</option>
                        <?php if($param == "add"): ?>
                        <?php else: ?>
                        <?php $__currentLoopData = $district; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($x->DISTRICT_ID); ?>"<?php echo e(($x->DISTRICT_ID == $DISTRICT_ID)?" selected":""); ?>><?php echo e($x->DISTRICT_NAME); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                      </select>
                    </div>
                    <div class="form-group col-12 col-md-4">
                      <label for="inputposcode" style="font-size: 12px;">รหัสไปรษณีย์</label>
                      <input type="text" class="form-control form-control-sm" name="inputposcode" value="<?php echo $inputposcode; ?>" onkeyup="readd()" id="inputposcode">
                    </div>
                  </div>
                  <div class="form-row">           
                    <div class="form-group col-12 col-md-4">
                      <label for="inputEmail" style="font-size: 12px;">E-mail</label>
                      <input type="Email" class="form-control form-control-sm" name="inputEmail" value="<?php echo $inputEmail; ?>" id="inputEmail" >
                    </div>
                   
                  </div>
              </div>
              <div class="form-group col-6 col-md-8" id="cusold" style="display:none">
                <div class="form-row">
                  <div class="col-md-12 form-group">
                    <div class="row gutters-xs">
                      <div class="col">
                        <input type="hidden" class="form-control col-md-7" id="idpsuser" name="idpsuser" value="<?php echo $idCus; ?>">
                        <input type="text" name="username" id="username" class="form-control form-control-sm" placeholder="ชื่อลูกค้า" readonly>
                      </div>
                      <span class="col-auto">
                        <button class="btn btn-secondary" id="userfide" type="button"  data-toggle="modal" data-target="#personModal"><i class="fas fa-user-plus"></i></button>
                      </span>
                    </div>
                  </div>
                  <div class="col-md-12 form-group">
                    <div class="row gutters-xs">
                      <div class="col">
                        <input type="hidden" class="form-control col-md-7" id="idAdd" name="idAdd" value="<?php echo $idAdd; ?>">
                        <textarea type="text" name="vAddold" id="vAddold" class="form-control form-control-sm" placeholder="ที่อยู่จัดส่ง" readonly></textarea>
                      </div>
                      <span class="col-auto">
                        <button class="btn btn-secondary" id="Addfide" type="button"  data-toggle="modal" data-target="#AddressModal"><i class="fas fa-map-marked-alt"></i></button>
                      </span>
                    </div>
                  </div>
                </div>
              </div>
              <div class="form-group col-12 col-md-12">
              <div class="form-row">


                <div class="form-group col-12 col-md-6">
                  <label style="font-size: 12px;">รับจากระบบ</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <select id="inputSocial" name="inputSocial" class="form-control form-control-sm selectpicker">
                    <?php $__currentLoopData = $dsocial; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($x->idSocial); ?>"<?php echo e(($x->idSocial == $inputSocial)?" selected":""); ?>><?php echo e($x->nameSocial); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
                <div class="form-group col-12 col-md-6">
                  <label for="inputIden" style="font-size: 12px;">ชื่อบัญชี - social</label>
                  <input type="text" class="form-control form-control-sm" name="inputnamesocial" id="inputnamesocial" value="<?php echo $inputnamesocial; ?>">
                </div>
                <div class="form-group col-12 col-md-6">
                  <label for="inputPay" style="font-size: 12px;">การชำระเงิน</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <select id="inputPay" name="inputPay" class="form-control form-control-sm">
                    <?php $__currentLoopData = $dpay; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($x->idPay); ?>"<?php echo e(($x->idPay == $inputPay)?" selected":""); ?>><?php echo e($x->NamePay); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
              </div>
              </div>
              <div class="form-group col-12 col-md-6">
              <div class="form-row">
                <div class="form-group col-md-12">
                  <label for="inputNote" style="font-size: 12px;">ติดต่อฝ่ายขาย: <?php echo e(Cookie::get('name')); ?></label>
                  <textarea class="form-control form-control-sm" name="inputNote" id="inputNote" rows="3" value="<?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: 16px; ">กำหนดสินค้าที่ต้องการทำใบเสนอราคา</p></div>
          <div class="col-lg-6 mb-6" style="text-align: right;padding-bottom: 25px;"><button type="button" class="btn btn-outline-primary btn-sm" onClick="show()" ><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;">รายการสินค้า</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;">รวมเป็นเงิน</th>
                <th class="text-nowrap" scope="col" style="text-align: center;">ตัวเลือก</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 scope="row" style="text-align: center;"><input type="hidden" name="idPd[]" value="<?php echo e($x->idPdPk); ?>"></td>
                <td class="text-nowrap" style="text-align: left; color: #00897B;"><input type="hidden" name="namepdT[]" value="<?php echo e($x->PdName); ?>"><?php echo e($x->PdName); ?></td>
                <td style="text-align: right;"><input type="hidden" name="priceT[]" value="<?php echo e($x->PriceM); ?>"><?php echo e(number_format($x->PriceM), 2); ?></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="<?php echo e(number_format($x->Amount), 2); ?>"></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="<?php echo e(number_format($x->Price), 2); ?>"></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="<?php echo e(number_format($x->totalNet), 2); ?>" readonly=""></td>
                <td style="text-align: center; color: #C2185B;">
                <a onclick="deleteRow(this)"><font color="#D50000"> ลบ</font></a> <input type="hidden" name="num_mtrT[]"value="<?php echo e($x->totalNet); ?>"></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 class="col-lg-6 mb-6"></div>
      <div class="col-lg-6 mb-6" style="text-align: right;"> <div class="table-responsive"  style="margin-top: 20px;">
        <table class="table">
          <tbody>
            <tr>
              <th style="width: 40%; color: #00897B;text-align: right; padding-top: 25px">ค่าจัดส่ง :</th>
              <td ><input type="text" class="form-control" name="price_tarn" id="price_tarn" style="font-size: 14px; text-align: right;" onkeyup="totalNet()" min="0.01" step="0.01" value="<?php echo $price_tarn; ?>"></td>
            </tr>
            <tr>
              <th style="width: 40%; color: #00897B;text-align: right; padding-top: 25px">ยอดขาย :</th>
              <td ><input type="text" class="form-control" name="price_total" id="price_total" style="font-size: 14px; text-align: right;" min="0.01" step="0.01" readonly="" value="<?php echo e(number_format($price_total)); ?>"></td>
            </tr>
            <tr>
              <th style="width: 40%; color: #00897B;padding-top: 25px">ส่วนลด :</th>
              <td ><input type="text" class="form-control" name="price_dis" id="price_dis" style="font-size: 14px; text-align: right;" readonly="" value="<?php echo $price_dis; ?>"></td>
            </tr>
            <tr>
              <th style="width: 40%; color: #00897B;padding-top: 27px">เงินสุทธิ :</th>
              <td><input type="text" class="form-control font-weight-bold " name="price_totalNet" id="price_totalNet" style="font-size: 18px; text-align: right; color: #00796B;" min="0.01" step="0.01" readonly="" value="<?php echo e(number_format($price_totalNet)); ?>">
                <input type="hidden" name="price_totalT" id="price_totalT"  value="<?php echo $price_total; ?>">
                <input type="hidden" name="price_totalNetT" id="price_totalNetT" value="<?php echo $price_totalNet; ?>">
                <input type="hidden" name="price_disT" id="price_disT" value="<?php echo $price_dis; ?>">
              </td>
            </tr>
          </tbody>
        </table>
      </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="bteditpo" class="btn btn-info">บันทึกแก้ไข</button>
          <?php endif; ?>
          </div>       
      </div>
  </div>


      </form>
    </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">
        <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">
        <div class="input-group no-border col-4 mt-2 ml-auto pr-1">
          <input type="text" value="" class="form-control"  id="myInput"  onkeyup="PdSearch()" placeholder="Search...">
          <div class="input-group-append">
            <div class="input-group-text">
              <i class="now-ui-icons ui-1_zoom-bold"></i>
            </div>
          </div>
        </div>
        <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: 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: right;">จำนวนคงเหลือ</th>
                <th scope="col" style="text-align: center;">หน่วยบรรจุ</th>
              </tr>
            </thead>
            <?php
            $i = 1;
            ?>
            <tbody id="ListPdDetail">
             <?php $__currentLoopData = $showpd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>  
             <tr data-toggle="collapse" onClick='addpd2chart("<?php echo e($x->PdName); ?>",<?php echo e($x->PriceCost); ?>,<?php echo e($x->idPd); ?>,<?php echo e(number_format($x->SumAmount),2); ?>)'>
              <td class="text-nowrap"><i class="fas fa-plus-circle" style="color: #009688"></i>  <?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->Weight); ?></td>
              <td class="text-nowrap"style="text-align: center;"><?php echo e($x->nameWeight); ?></td>
              <td class="text-nowrap"style="text-align: right; color: #00796B; font-weight: bold;"><?php echo e(number_format($x->SumAmount),2); ?></td>
              <td class="text-nowrap"style="text-align: center;"><?php echo e($x->UnitName); ?></td>
              <td class="text-nowrap" style="text-align: center;">
                <!-- <a href="#" class="btn btn-primary btn-circle btn-sm"  data-toggle="collapse" data-target="#t<?php echo e($x->idPd); ?>" aria-expanded="false" aria-controls="t<?php echo e($x->idPd); ?>" onclick="deTailTranGB('<?php echo e($x->idPd); ?>','dtTran<?php echo e($x->idPd); ?>','dtsTran<?php echo e($x->idPd); ?>')">
                  <i class="fas fa-search"></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>
        <tr class="tranGB">
          <td colspan="10" class="text-nowrap" style="padding: 0px; width: 100%; margin-left: 10px">  
           <div  class="collapse" id="t<?php echo e($x->idPd); ?>" style="margin-left: 20px;">        
            <table class="table table-sm" style="margin-bottom: 5px;">
              <thead>
                <tr>
                  <td style="width: 5px;">[ลำดับ]</td>
                  <td style="width: 50px;text-align: left;">[เลือก]</td>
                  <td style="width: 50px;text-align: left;">[Lot no.]</td>
                  <td style="width: 10px;text-align: left;">[วันหมดอายุ]</td>
                  <td style="width: 50px;text-align: right;">[จำนวนที่ใช้ได้]</td>
                  <td style="width: 50px;text-align: right;">[จำนวนโดนจอง]</td>                  
                  <td style="width: 50px;text-align: right;">[จำนวนคงคลัง]</td>
                  <td style="width: 200px;text-align: center;">[คำอธิบายรายการ]</td>              
                </tr>
              </thead>
              <tbody class="dtTran<?php echo e($x->idPd); ?>">

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

</div>
<div class="modal-footer">
  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="ShowPMModal" 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">
        <div class="input-group no-border col-4 mt-2 ml-auto pr-1">
          <input type="text" value="" class="form-control"  id="myInput"  onkeyup="PdSearch()" placeholder="Search...">
          <div class="input-group-append">
            <div class="input-group-text">
              <i class="now-ui-icons ui-1_zoom-bold"></i>
            </div>
          </div>
        </div>
        <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 scope="col" style="text-align: left;">ชื่อโปรโมชั่น</th>
               <th scope="col" style="text-align: center;">ประเภทโปรโมชั่น</th>
               <th scope="col" style="text-align: center;">โค้ดโปร</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 id="ListPdDetail">
             <?php $__currentLoopData = $pomo; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
             <tr >
              <td class="text-nowrap"><?php echo e($i++); ?></td>
              <td class="text-nowrap" style="text-align: center;"><button class="btn  btn-success btn-sm" onclick="addpromo('<?php echo e($x->idPromotion); ?>','<?php echo e($x->namePromotion); ?>','<?php echo e($x->nameType); ?>','<?php echo e($x->Code); ?>','<?php echo e(number_format($x->disco)); ?>','<?php echo e($x->detailPromotion); ?>','<?php echo e(DateThai($x->endDate)); ?>','<?php echo e($x->disco); ?>')"><i class="fas fa-arrow-circle-down" style="color: #FFF"></i> เลือก</button></td>
              <td class="text-nowrap"><?php echo e($x->namePromotion); ?></td>
              <td class="text-nowrap" style="text-align: center;"><?php echo e($x->nameType); ?></td>
              <td class="text-nowrap" style="text-align: center;"><?php echo e($x->Code); ?></td>
              <td class="text-nowrap" style="text-align: right;"><?php echo e(number_format($x->disco)); ?></td>
              <td class="text-nowrap" style="text-align: center;"><?php echo e($x->detailPromotion); ?></td>
              <td class="text-nowrap"style="text-align: center;"><?php echo e(DateThai($x->endDate)); ?></td>        
            </td>
          </tr>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
      </table>
    </div>

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</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" data-dismiss="modal">
          <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">
          <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">
          <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 -->
<div class="modal fade" id="AddressModal" 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" data-dismiss="modal">
          <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">
          <input type="text" value="" class="form-control"  id="myInputNewper"  onkeyup="allSearch()" 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">
          <thead>
            <tr>
              <th style="text-align: center; width: 30px;">ลำดับ</th>
              <th>ที่อยู่</th>
              <th style="text-align: center; width: 100px;">ตัวเลือก</th>
            </tr>
          </thead>
          <tbody id="addresstd">

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

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

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

  $("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){
    $("#username").val(sname);
    $("#idpsuser").val(ids);
    $("#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(ids,sname){

    $("#vAddold").val(sname);
    $("#idAdd").val(ids);
    $("#AddressModal").modal('toggle');
    

  }

  $(function(){
    $("#userfide").click(function(){
      $.ajax({
        url:'<?php echo e(url("user")); ?>',
        /* data:{CompName:$("#findcompname").val()},*/
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          items = ret;
          $("#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+'\')">เลือก</a> </td></tr> ';
                $("#persontd").append(str);
                rows++;
              }
            },
            error:function(err){
              alert('Error');
              //console.log(err.responseText);
            }
          });
    });

    $("#Addfide").click(function(){
      $.ajax({
        url:'<?php echo e(url("addressall")); ?>',
        data:{idcus:$("#idpsuser").val()},
        type:'GET',
        dataType:'json',
        cache:false,
        success:function(ret){
          items = ret["ad"];
          $("#addresstd").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].AddressText+'</a></td><td style="padding: 0px; text-align: center;"><a class="btn btn-primary btn-sm" style="color:#FFF" onclick="getGetAdd('+items[x].idAdd+',\''+items[x].AddressText+'\')">เลือก</a> </td></tr> ';
                $("#addresstd").append(str);
                rows++;
              }
            },
            error:function(err){
              alert('Error');
              //console.log(err.responseText);
            }
          });
    });

  });

  $(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($("#inputAdd").val()+" "+ $("#inputDistrict option:selected").text() +" "+ $("#inputAmphur option:selected").text() +"จังหวัด"+ $("#inputProvince option:selected").text() +""+ $("#inputposcode").val());
    })

  })

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

    if($("#inlineRadio1").prop('checked')==true){
      if(($("#inputNameF").val() == "")){
        swal({
          title: "ไม่สามารถบันทึกได้ !!!",
          text: "กรุณากรอกชื่อ-สกุล",
          icon: "info",
          button: "ตกลง",
        });

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

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

        return false;

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

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

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

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

        return false;
      }else if(($("#inputDistrict").val() == "")){
        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();
            var form1 = $('#form1')[0];
                var formData = new FormData(form1);
                $.ajax({
                    url:'<?php echo e(url('saveinvoice')); ?>',
                            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",
                            })
                            // $("#error").html(ret);
                            window.location.replace("<?php echo e(url('tbsaleshow')); ?>");
                            
                        },
                        error:function(err){
                            console.log(err);
                            $("#error").html(err.responseText);
                            $("#modal_error").modal('show');
                        }
                    });
          }else{
            swal({
                text: "ยกเลิกแก้ไขข้อมูล",
                icon: "warning",
            })
          }
    });

     }

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

      return false;
    }else if(($("#idpsuser").val() == "")){
      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();
            var form1 = $('#form1')[0];
                var formData = new FormData(form1);
                $.ajax({
                    url:'<?php echo e(url('saveinvoice')); ?>',
                            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",
                            })
                            // $("#error").html(ret);
                            window.location.replace("<?php echo e(url('tbsaleshow')); ?>");
                            
                        },
                        error:function(err){
                            console.log(err);
                            $("#error").html(err.responseText);
                            $("#modal_error").modal('show');
                        }
                    });
          }else{
            swal({
                text: "ยกเลิกแก้ไขข้อมูล",
                icon: "warning",
            })
          }
    });


   }
 }

})
  function readd() {
    $("#vAdd").val($("#inputAdd").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";

      }
    }
  }
  var rcount = 1;
  function addpd2chart(namepd,price,idPd,amonuse){


    $("#trpdlot").append(''
      +'<tr>'
      +'<td scope="row" style="text-align: center;"><input type="hidden" name="idPd[]" value="'+idPd+'">'
      +'. '
      +'</td>'
      +'<td class="text-nowrap" style="text-align: left; color: #00897B;"><input type="hidden" name="namepdT[]" value="\''+namepd+'\'">'
      +namepd
      +'</td>'
      +'<td style="text-align: right;"><input type="hidden" name="priceT[]" value="\''+price+'\'">'
      +price
      +'</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="0"></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++;
    $("#ShowPdModal").modal('toggle');
  }

  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;
  totalNet = (numeral($("#price_total").val()).value() - numeral($("#price_dis").val()).value())+ numeral($("#price_tarn").val()).value();
  $('#price_totalNet').val(numeral(totalNet).format('0,0'));
  $('#price_totalNetT').val(totalNet);
}

function deleteRow(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";

      }
    }
  }

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

</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/sale/invoin.blade.php ENDPATH**/ ?>