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

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

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

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

?>

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="#">Stock</a></li>
    <li class="breadcrumb-item active" aria-current="page">ข้อมูลสต๊อกการ์ด - ปรับปรุง STOCK</li>
  </ol>
</nav>
<div class="card">
  <div class="card-body">
  <div class="row">
    <div class="col-9 mb-12">
      <div class="row">
          <div class="row" style="padding-left: 10px">
            <div class="col-md-12 col-12">
              <p><span class="m-0 font-weight-bold text-primary" id="h6text"  style="font-size:16px;">ตารางข้อมูลจำนวนสินค้า </span><span class="m-0 font-weight-bold text-dark"  style="font-size:14px;"> </span></p>
              
            </div>
          </div>
          <div class="row" style="padding-left: 20px">
            <div class="col-12">
              <a  class="btn btn-success btn-success btn-sm" style="color: #FFF" data-toggle="modal" data-target="#show2dateModalCenter"> <i class="fas fa-cog"></i> ตั้งค่าการค้นหา</a>
            </div>
          </div>
           <div class="row" style="padding-left: 20px">
            <div class="col-12">
              <div class="btn-group">
                <button type="button" class="btn btn-outline-info btn-sm"> <i class="fas fa-warehouse"></i> ระบบสต๊อก</button>
                <button type="button" class="btn btn-outline-info btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <div class="dropdown-menu">          
                  <a class="dropdown-item" href="#"  data-toggle="modal" data-target="#CheckStockModalCenter"><i class="fas fa-clipboard-list"></i> บันทึกสต๊อกคงเหลือรายวัน</a>
                 
                    
                </div>
              </div>
            </div>
          </div> 
          <div class="row" style="padding-left: 20px">
            <div class="col-12">
              <div class="btn-group">
                <button type="button" class="btn btn-primary btn-sm"> <i class="fas fa-print"></i> ออกรายงาน</button>
                <button type="button" class="btn btn-primary btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <div class="dropdown-menu">          
                  <a class="dropdown-item" href="#"  data-toggle="modal" data-target="#reportStorckarnModalCenter"><i class="fas fa-print"></i> excel สต๊อกสินค้า</a>
                  <a class="dropdown-item" href="#" data-toggle="modal" data-target="#reportSalesModalCenter"> <i class="fas fa-print"></i> ปริ้นรายงานยอดขาย</a>
                    
                </div>
              </div>
            </div>
          </div>
          <!-- <div class="row" style="padding-left: 20px">
            <div class="col-12">
              <a  class="btn btn-outline-info btn-sm" href="saleorder"> <i class="fas fa-cart-plus"></i> ออกใบเสนอราคา</a>
            </div>
          </div> -->
          <!-- <div class="row" style="padding-left: 20px">
            <div class="col-12">
              <a  class="btn btn-outline-primary btn-sm" href="sale"> <i class="fas fa-cart-plus"></i> เพิ่มรายการขาย</a>
            </div>
          </div> -->

        </div>
    </div>
    <div class="col-3 mb-12 " style="text-align: right;">
      <div class="row">
        <div class="col-md-12 col-12">
        <p class="m-0 font-weight-bold text-info"  style="text-align: right; font-size: 22px;"><span class="font-weight-light" style="color:#afb9c8;font-size: 16px;">ยอดรวมสินค้าคงเหลือ : </span> <?php echo e(number_format($sumstock[0]->Amount), 2); ?> <span class="font-weight-light" style="color:#afb9c8;font-size: 16px;"> ชิ้น </span></p>
        <!-- <input type="text" class="form-control" name="vSumTotalnet" id="vSumTotalnet" style="text-align: right; color: #1B5E20; size: 18px;"  value="" disabled> -->
        </div>
      </div>
    </div>
    </div>
  </div>
</div>

<!-- DataTales ตารางข้อมูลสินค้า-->
<div class="card mb-4">
  
<div class="card-body">
  <div class="table-responsive" >
    <table class="table table-sm" id="PdTable" width="100%" cellspacing="0">
      <thead>
        <tr >
          <th scope="col" style="text-align: left;">#</th>
          <th scope="col" style="text-align: left;">ชื่อสินค้า</th>
          <th scope="col" style="text-align: right;">ประเภทสินค้า</th>
          <th scope="col" style="text-align: right;">ราคาขาย</th>
          <th scope="col" style="text-align: right;">น้ำหนัก</th>
          <th scope="col" style="text-align: 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>
       <?php $__currentLoopData = $showpd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
       <tr style="background: #F4F6F7;" >
        <td scope="row"><?php echo e($i++); ?>.</td>
        <td class="text-nowrap"><?php echo e($x->PdName); ?></td>
        <td class="text-nowrap" style="text-align: right;"><?php echo e($x->pdTypeName); ?></td>
        <td class="text-nowrap" style="text-align: right;"><?php echo e($x->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: #1A237E; 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-circle btn-info 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); ?>','dtTranmodal<?php echo e($x->idPd); ?>','dtsTran<?php echo e($x->idPd); ?>')">
            <i class="fas fa-arrow-circle-down"></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 style="background: #B2DFDB">
                  <td style="width: 5px;">[ลำดับ]</td>
                  <td style="width: 50px;text-align: left;">[BATCH NO.]</td>
                  <td style="width: 10px;text-align: left;">[วันที่เอกสาร]</td>
                  <td style="width: 10px;text-align: left;">[เลขที่เอกสาร]</td>
                  <td style="width: 10px;text-align: left;">[วันที่หมดอายุ]</td>                  
                  <td style="width: 50px;text-align: right;">[จำนวนคงเหลือ]</td>
                  <td style="width: 200px;text-align: center;">[คำอธิบาย]</td>
                  <td style="width: 50px;text-align: center;">[ผู้รับเข้า]</td>
                  <td style="width: 50px;text-align: center;">[ตัวเลือก]</td>
                </tr>
              </thead>
              <tbody class="dtTranmodal<?php echo e($x->idPd); ?>">

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


<!-- ModalEdit -->
<div class="modal fade" id="EditPdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background:#A0522D">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #FFFF;">แก้ไขจำนวนคงเหลือ</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?php echo url('editstock'); ?>" method="post" id="form1">
       <?php echo csrf_field(); ?>
       <div class="modal-body">
        <div class="form-group">
          <label for="inputLot">หมายเลขLOT :</label>
          <input type="hidden" id="idPdModel" name="idPdModel">
          <input type="text" class="form-control" id="inputLot" name="inputLot" placeholder="lotNumber" readonly="">
          <input type="hidden" name="idLot" id="idLot">
        </div>
        <div class="form-row">
          <div class="form-group col-md-4">
            <label for="VAmount">จำนวนปัจจุบัน</label>
            <input type="number" class="form-control" name="VAmount" id="VAmount" min="0.01" step="0.01" readonly="">
          </div>
          <div class="form-group col-md-4">
            <label for="selOparator">ตัวดำเนินการ</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <select name="selOparator"  id="selOparator" class="form-control custom-select">                   
              <option value="-"> ลบ </option>
              <option value="+"> บวก </option>                
            </select>
          </div>
          <div class="form-group col-md-4">
            <label for="vEamount">จำนวน</label>
            <span class="form-required" style="color: #CC0000">*</span>
            <input type="number" class="form-control" name="vEamount" id="vEamount"  onkeyup="sumAmou()" min="0.01" step="0.01">
          </div>
          <div class="form-group col-md-12">
            <label for="VAmountSum">จำนวนจะคงเหลือ</label>
            <input type="number" class="form-control" name="VAmountSum" id="VAmountSum" min="0.01" step="0.01" readonly="">
          </div>
          <div class="form-group col-md-12">
            <span class="form-required" style="color: #CC0000">*</span>
            <label for="inputnote">หมายเหตุ</label>
            <textarea class="form-control" name="inputnote" id="inputnote" rows="3"></textarea>
          </div>
        </div> 

      </div>
    </form>
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" id="btSmEdit" class="btn btn-primary">บันทึกข้อมูล</button>
    </div>
  </div>
</div>
</div>

<!-- ModalStockCard -->
<div class="modal fade" id="StockPdModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background:#A0522D">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #FFFF;">สต๊อกการ์ด สินค้าขาย</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form action="<?php echo url('stock'); ?>" method="post" id="form1">
       <?php echo csrf_field(); ?>
       <div class="modal-body">
        <div class="form-row">
          <div class="form-group col-md-4">
            <label for="namePd">ชื่อสินค้า :</label>
            <input type="text" class="form-control" id="namePd" name="namePd" placeholder="namePd" readonly="">
          </div>
          <div class="form-group col-md-4">
            <label for="lotno">หมายเลข LOT :</label>
            <input type="text" class="form-control" id="lotno" name="lotno" placeholder="lotno" readonly="">
            <input type="hidden" name="idLot" id="idLot">
          </div>
          <div class="form-group col-md-4">
            <label for="lotno">จำนวนคงเหลือ :</label>
            <input type="text" class="form-control" style="text-align: right;" id="AmountAll" name="AmountAll" placeholder="AmountAll" readonly="">
          </div>
        </div>
        <div class="form-row">
          <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: center;">รายการ</th>
                  <th scope="col" style="text-align: center;">รับเข้า</th>
                  <th scope="col" style="text-align: center;">เบิกออก</th>
                  <th scope="col" style="text-align: center;">วันที่ทำรายการ</th>
                </tr>
              </thead>

              <tbody class="dtcard">


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

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

<!--  Modal  reportsales -->
<div class="modal fade" id="reportSalesModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" 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="exampleModalCenterTitle">กรุณากำหนดข้อมูลที่ต้องการปริ้น</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="<?php echo url('printreportstockcard'); ?>" method="post" id="formreport" target="_blank">
         <?php echo csrf_field(); ?>
         <div class="form-group">
          <div class="form-label">เลือกช่วงข้อมูล</div>
          <div class="custom-controls-stacked">
           <!--  <label class="custom-control custom-radio">
              <input type="radio" id="inlineRadio1" value=""   class="custom-control-input" name="phase_type" >
              <input type="hidden" id="txtMMday" name="mm"  value="1" disabled="disabled"/>
              <div class="custom-control-label">ค้นหาตามช่วงวันที่ : 
                <input type="text" id="txtDay1" size="10" name="date1" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" placeholder="จากวันที่" disabled="disabled" />
                <div class="col-lg-12"> <span>
                  <a>ถึง</a>
                </span>
              </div>
              <input type="text" id="txtDay2" size="10" name="date2" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" placeholder="ถึงวันที่" disabled="disabled"/>
            </div>
          </label>
          <label class="custom-control custom-radio">
            <input type="radio" id="inlineRadio2" value=""  class="custom-control-input" name="phase_type" >
            <input type="hidden" id="txtMMmon" name="mm"  value="2" disabled="disabled"/>
            <div class="custom-control-label">ค้นหาตามช่วงเดือนปีนี้ :
              <select name="month"  id="selMount" class="form-control custom-select" disabled="disabled">                   
                <option value="01">มกราคม</option>
                <option value="02">กุมภาพันธ์</option>
                <option value="03">มีนาคม</option>
                <option value="04">เมษายน</option>
                <option value="05">พฤษภาคม</option>
                <option value="06">มิถุนายน</option>
                <option value="07">กรกฎาคม</option>
                <option value="08">สิงหาคม</option>
                <option value="09">กันยายน</option>
                <option value="10">ตุลาคม</option>
                <option value="11">พฤศจิกายน</option>
                <option value="12">ธันวาคม</option>
              </select>
            </div>
          </label> -->
          <label class="custom-control custom-radio">
            <input type="radio" id="inlineRadio3" value="" rel="txt3"  checked="checked" class="custom-control-input" name="phase_type">
            <div class="custom-control-label">ค้นหาทั้งปี :
              <input type="text" id="txtYear" name="year" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" value="<?php echo e($strYear); ?>"/>
              <input type="hidden" id="txtMMYear" name="mm"  value="3"/>
            </div>
          </label>              
        </div>
      </div>
    </form>
  </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="printsales" target="_blank">แสดงหน้าปริ้น</button>
    <button type="button" class="btn btn-primary" id="reportcxcel" onclick="window.location.href='reportexcel'" target="_blank">Excel</button>
  </div>
</div>
</div>
</div>

<!--  Modal show2date -->
<div class="modal fade" id="show2dateModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" 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="exampleModalCenterTitle">กรุณากำหนดข้อมูลที่ต้องการค้นหา</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="<?php echo url('reportexceltodate'); ?>" method="post" id="form2date" >
         <?php echo csrf_field(); ?>
         <div class="form-group">
          <div class="form-label">เลือกช่วงข้อมูล</div>
          <div class="custom-controls-stacked">
           <!--  <label class="custom-control custom-radio">
              <input type="radio" id="inlineRadio11" value=""   class="custom-control-input" name="phase_type" >
              <input type="hidden" id="txtMMday1" name="mm"  value="1" disabled="disabled"/>
              <div class="custom-control-label">ค้นหาตามช่วงวันที่ : 
                <input type="text" id="txtDay11" size="10" name="date1" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" placeholder="จากวันที่" disabled="disabled" />
                <div class="col-lg-12"> <span>
                  <a>ถึง</a>
                </span>
              </div>
              <input type="text" id="txtDay12" size="10" name="date2" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" placeholder="ถึงวันที่" disabled="disabled"/>
            </div>
          </label>
          <label class="custom-control custom-radio">
            <input type="radio" id="inlineRadio12" value=""  class="custom-control-input" name="phase_type" >
            <input type="hidden" id="txtMMmon1" name="mm"  value="2" disabled="disabled"/>
            <div class="custom-control-label">ค้นหาตามช่วงเดือนปีนี้ :
              <select name="month"  id="selMount1" class="form-control custom-select" disabled="disabled">                   
                <option value="01">มกราคม</option>
                <option value="02">กุมภาพันธ์</option>
                <option value="03">มีนาคม</option>
                <option value="04">เมษายน</option>
                <option value="05">พฤษภาคม</option>
                <option value="06">มิถุนายน</option>
                <option value="07">กรกฎาคม</option>
                <option value="08">สิงหาคม</option>
                <option value="09">กันยายน</option>
                <option value="10">ตุลาคม</option>
                <option value="11">พฤศจิกายน</option>
                <option value="12">ธันวาคม</option>
              </select>
            </div>
          </label> -->
          <label class="custom-control custom-radio">
            <input type="radio" id="inlineRadio13" value="" rel="txt3"  checked="checked" class="custom-control-input" name="phase_type">
            <div class="custom-control-label">ค้นหาทั้งปี :
              <input type="text" id="txtYear1" name="year" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" value="<?php echo e($strYear); ?>"/>
              <input type="hidden" id="txtMMYear1" name="mm"  value="3"/>
            </div>
          </label>              
        </div>
      </div>
    </form>
  </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="btnsuc2date" >แสดง</button> -->
    <button type="button" class="btn btn-primary" id="reportcxcel2" target="_blank"><i class="far fa-file-excel"></i> Excel</button>
  </div>
</div>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="reportStorckarnModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" 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="exampleModalLongTitle">โหลดรายงานสต๊อกสินค้า</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="<?php echo url('excelreportstocktarn'); ?>" method="post" id="formtarn" >
          <?php echo csrf_field(); ?>
        <div class="form-row">
            <div class="form-group col-md-12">
              <div class="form-row"  style="font-size: 14px;">
                <div class="form-group col-md-12">
                  <label for="inputPD">สินค้า</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <select id="inputPD" name="inputPD" class="form-control">
                    <option value="">-- ทั้งหมด --</option>
                    <?php $__currentLoopData = $showpd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($x->idPd); ?>"><?php echo e($x->PdName); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                </div>
                <div class="form-group col-md-12" style="font-size: 14px;">
                  <label >เดือน</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <select id="month" name="month" class="form-control">
                    <option value="01" disabled>มกราคม</option>
                    <option value="02" disabled>กุมภาพันธ์</option>
                    <option value="03" disabled>มีนาคม</option>
                    <option value="04" disabled>เมษายน</option>
                    <option value="05" disabled>พฤษภาคม</option>
                    <option value="06" disabled>มิถุนายน</option>
                    <option value="07" disabled>กรกฎาคม</option>
                    <option value="08">สิงหาคม</option>
                    <option value="09">กันยายน</option>
                    <option value="10">ตุลาคม</option>
                    <option value="11">พฤศจิกายน</option>
                    <option value="12">ธันวาคม</option>
                  </select>
                </div>
                <div class="form-group col-md-12" style="font-size: 14px;">
                  <label for="inputDistrict">ปี</label>
                  <span class="form-required" style="color: #CC0000">*</span>
                  <input type="text" id="txtYear2" name="year" class="form-control date-picker" data-mask="00/00/0000" data-mask-clearifnotmatch="true" value="<?php echo e($strYear); ?>"/>
                </div>     
              </div>   
            </div>    
          </div>
        </from>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary"><i class="far fa-file-excel"></i> Excel</button>
      </div>
    </div>
  </div>
</div>

<!-- ModalCheckStock -->
<div class="modal fade bd-example-modal-lg" id="CheckStockModalCenter" tabindex="-1" role="dialog" aria-labelledby="CheckStockModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="CheckStockModalLongTitle">การบันทึก Stock สินค้าคงเหลือรายวัน</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="alert alert-success" role="alert">
          ตรวจนับประจำวันล่าสุด: <?php echo e(DateThaiHh($datetimestocktoday[0]->dateEdit)); ?>  โดย: <?php echo e($datetimestocktoday[0]->PsNameS); ?> (<?php echo e($datetimestocktoday[0]->PsNickName); ?>)
        </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: left;">ชื่อสินค้า</th>
                <th scope="col" style="text-align: right;">จำนวนคงเหลือ</th>
                <th scope="col" style="text-align: center;">หน่วยบรรจุ</th>
                <th scope="col" style="text-align: center;">ตัวเลือก</th>
              </tr>
            </thead>
            <?php
            $i = 1;
            ?>
            <tbody>
             <?php $__currentLoopData = $showpd; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $x): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
             <tr style="background: #F4F6F7;" >
              <td scope="row"><?php echo e($i++); ?>.</td>
              <td class="text-nowrap"><?php echo e($x->PdName); ?></td>
              <td class="text-nowrap"style="text-align: right; color: #1A237E; 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-circle btn-info btn-sm"  data-toggle="collapse" data-target="#p<?php echo e($x->idPd); ?>" aria-expanded="false" aria-controls="p<?php echo e($x->idPd); ?>" onclick="deTailTranGBModal('<?php echo e($x->idPd); ?>','dtTranmodal<?php echo e($x->idPd); ?>','dtsTranmodal<?php echo e($x->idPd); ?>')">
                  <i class="fas fa-arrow-circle-down"></i>
                </a>
         
                </td>
              </tr>
              <tr class="tranGBModal">
                <td colspan="10" class="text-nowrap" style="padding: 0px; width: 100%; margin-left: 10px">  
                 <div  class="collapse" id="p<?php echo e($x->idPd); ?>" style="margin-left: 20px;">        
                  <table class="table table-sm" style="margin-bottom: 5px;">
                    <thead>
                      <tr style="background: #B2DFDB">
                        <td style="width: 5px;">[ลำดับ]</td>
                        <td style="width: 50px;text-align: left;">[BATCH NO.]</td>
                        <td style="width: 10px;text-align: left;">[วันที่เอกสาร]</td>
                        <td style="width: 10px;text-align: left;">[วันที่หมดอายุ]</td>                  
                        <td style="width: 50px;text-align: right;">[จำนวนคงเหลือ]</td>
                        <td style="width: 200px;text-align: center;">[คำอธิบาย]</td>
                        <td style="width: 50px;text-align: center;">[ผู้รับเข้า]</td>
                      </tr>
                    </thead>
                    <tbody class="dtTranmodal<?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>
        <button type="button" onclick="checkstock2day()" class="btn btn-primary">บันทึกข้อมูลประจำวัน</button>
      </div>
    </div>
  </div>
</div>




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

 $('#printsales').click(function(){
   $("#formreport").submit();
 })

 $('#reportcxcel2').click(function(){
   $("#form2date").submit();
 })
 
 $('#btSmEdit').click(function(){
  if(($("#vEamount").val() == "")){
    swal({
      title: "ไม่สามารถบันทึกได้ !!!",
      text: "กรุณาจำนวนที่ต้องการ",
      icon: "info",
      button: "ตกลง",
    });

    return false;

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

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

 }
})
function checkstock2day(){
  swal({
    title: "Are you sure?",
    text: "ยืนยันบันทึกจำนวนสินค้าคงเหลือประจำวันนี้หรือไม่!",
    icon: "warning",
    buttons: true,
    dangerMode: true,
  })
  .then((willDelete) => {
    if (willDelete) {
      $.ajax({
      url:'<?php echo e(url("approvestocktoday")); ?>',
      type:'GET',
      dataType:'json',
      cache:false,      
        success:function(ret){
          location.reload();
      },
      error:function(err){
        console.log(err);
      }
    });

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

}

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

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

      });*/
    } 
  });

}

function edit(id,lotnaum,AmountOld,idPd){

  $('#inputAmount').empty();

  $('#idLot').val(id);
  $('#inputLot').val(lotnaum);
  $('#VAmount').val(AmountOld);
  $('#idPdModel').val(idPd);


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

function deTailTranGB(id,e,s){

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

      var showpd = ret["showpdStock"];

      $("."+e).empty();
      $("."+s).empty();
      var i= 1;
      for(x in showpd){
        strGB ='<tr style="background: #E0F2F1">'
        +'<td style="width: 5px;">->['+i+']</td>'
        +'<td style="width: 50px;text-align: left;">'+showpd[x]["LotNum"]+'</td>'
        +'<td style="width: 20px;text-align: left;">'+showpd[x]["DateUpdate"]+'</td>'
        +'<td style="width: 50px;text-align: left;">'+showpd[x]["docCode"]+'</td>'
        +'<td style="width: 50px;text-align: left;">'+showpd[x]["datePdCer"]+'</td>'
        +'<td style="width: 50px;text-align: right; color: #00796B; font-weight: bold;">'+showpd[x]["Amount"]+'</td>'
        +'<td style="width: 200px;text-align: center;">'+showpd[x]["Note"]+'</td>'
        +'<td style="width: 50px;text-align: center;">'+showpd[x]["PsNnameF"]+'</td>'
        +'<td style="width: 50px;text-align: center;"><a href="#" class="btn btn-primary btn-circle btn-sm" onclick="showStockCard('+showpd[x].idPdLot+')"><i class="fas fa-search"></i></a> <a href="#" class="btn btn-danger btn-circle btn-sm" onClick="del()"><i class="fas fa-trash"></i></a> <a href="#" class="btn btn-warning btn-circle btn-sm" onClick="edit('+showpd[x].idPdLot+',\''+showpd[x].LotNum+'\',\''+showpd[x].Amount+'\',\''+showpd[x].idPd+'\')"><i class="fas fa-edit"></i></a></td>'
        +'</tr>';
        $("."+e).append(strGB);
        i++;
      }

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

function deTailTranGBModal(id,e,s){

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

    var showpd = ret["showpdStock"];

    $("."+e).empty();
    $("."+s).empty();
    var i= 1;
    for(x in showpd){
      strGB ='<tr style="background: #E0F2F1">'
      +'<td style="width: 5px;">->['+i+']</td>'
      +'<td style="width: 50px;text-align: left;">'+showpd[x]["LotNum"]+'</td>'
      +'<td style="width: 50px;text-align: left;">'+showpd[x]["docCode"]+'</td>'
      +'<td style="width: 50px;text-align: left;">'+showpd[x]["datePdCer"]+'</td>'
      +'<td style="width: 50px;text-align: right; color: #00796B; font-weight: bold;">'+showpd[x]["Amount"]+'</td>'
      +'<td style="width: 200px;text-align: center;">'+showpd[x]["Note"]+'</td>'
      +'<td style="width: 50px;text-align: center;">'+showpd[x]["PsNnameF"]+'</td>'
      +'</tr>';
      $("."+e).append(strGB);
      i++;
    }

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

function showStockCard(id){
      $('#AmountAll').val(0);
      $('#lotno').empty();
      $('#namePd').empty();
  $.ajax({
    url:'<?php echo e(url("finepdstockcard")); ?>/'+id,
    type:'GET',
    dataType:'json',
    cache:false,
    success:function(ret){
      console.log(ret);
      $(".dtcard").empty();
      var showpd = ret["showpdStock"];
      var AmountNet = showpd[0]["allAmount"];
      var numlot = showpd[0]["LotNo"];
      var pdname = showpd[0]["PdName"];
      var i= 1;
      for(x in showpd){
        strGB ='<tr style="background: #E0F2F1">'
        +'<td style="width: 5px;">['+i+']</td>'
        +'<td style="width: 150px;text-align: left;">เบิกออกจากการขาย '+showpd[x]["DocCode"]+' ลูกค้า '+showpd[x]["CusName"]+'</td>'
        +'<td style="width: 10px;text-align: center;"> - </td>'
        +'<td style="width: 10px;text-align: center;" color: #00796B; font-weight: bold;">'+showpd[x]["Amount"]+'</td>'
        +'<td style="width: 50px;text-align: center; color: #00796B; font-weight: bold;">'+showpd[x]["dateCreate"]+'</td>'
        +'</tr>';
        $(".dtcard").append(strGB);
        i++;
      }
      $('#AmountAll').val(AmountNet);
      $('#lotno').val(numlot);
      $('#namePd').val(pdname);
    },
    error:function(err){
      console.log(err);
    }
  });

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

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

$(function(){
  createdatepicker('InputDatePdCer');
}); 

function sumAmou() {
  var amo = "";
  if($("#selOparator option:selected").val() == '='){
     //alert($("#selOparator option:selected").val());
     $("#VAmountSum").val(numeral($("#vEamount").val()).value());
   }else if($("#selOparator option:selected").val() == '-'){
    amo = numeral($("#VAmount").val()).value() - numeral($("#vEamount").val()).value();
    $("#VAmountSum").val(numeral(amo).format('0'));
  }else if($("#selOparator option:selected").val() == '+'){
    amo = numeral($("#VAmount").val()).value() + numeral($("#vEamount").val()).value();
    $("#VAmountSum").val(numeral(amo).format('0'));
  }

}

$("#selOparator").change(function(){
 var amo = "";
 if($("#selOparator option:selected").val() == '='){
     //alert($("#selOparator option:selected").val());
     $("#VAmountSum").val(numeral($("#vEamount").val()).value());
   }else if($("#selOparator option:selected").val() == '-'){
    amo = numeral($("#VAmount").val()).value() - numeral($("#vEamount").val()).value();
    $("#VAmountSum").val(numeral(amo).format('0'));
  }else if($("#selOparator option:selected").val() == '+'){
    amo = numeral($("#VAmount").val()).value() + numeral($("#vEamount").val()).value();
    $("#VAmountSum").val(numeral(amo).format('0'));
  }
})


$( "input[name='phase_type']").change(function() {
  if($("#inlineRadio1").prop('checked')==true){
    $("#txtDay1").prop('disabled', false);
    $("#txtDay2").prop('disabled', false);
    $("#txtMMday").prop('disabled', false);
    $("#txtMMYear").prop('disabled', true);
    $("#txtMMmon").prop('disabled', true);
    $("#selMount").prop('disabled', true);
    $("#txtYear").prop('disabled', true);
  }
  else if($("#inlineRadio2").prop('checked')==true){
    $("#txtDay1").prop('disabled', true);
    $("#txtDay2").prop('disabled', true);
    $("#txtMMday").prop('disabled', true);
    $("#txtMMYear").prop('disabled', true);
    $("#txtMMmon").prop('disabled', false);
    $("#selMount").prop('disabled', false);
    $("#txtYear").prop('disabled', true);
  }
  else if($("#inlineRadio3").prop('checked')==true){
    $("#txtDay1").prop('disabled', true);
    $("#txtDay2").prop('disabled', true);
    $("#selMount").prop('disabled', true);
    $("#txtYear").prop('disabled', false);
    $("#txtMMday").prop('disabled', true);
    $("#txtMMYear").prop('disabled', false);
    $("#txtMMmon").prop('disabled', true);
  }

});

function createdatepicker(id){
  $('#'+id).datepicker({
    format: "dd/mm/yyyy",
    todayBtn: "linked",
    clearBtn: true,
    language: "th",
    daysOfWeekHighlighted: "0",
    autoclose: true,
    todayHighlight: true
  });
}
function createYpicker(id){
  $('#'+id).datepicker({
    format: "yyyy",
    todayBtn: "linked",
    clearBtn: true,
    language: "th",
    minViewMode: 2,
    maxViewMode: 2,
    daysOfWeekHighlighted: "0",
    autoclose: true,
    todayHighlight: true
  });
}
function createMpicker(id){
  $('#'+id).datepicker({
    format: "mm",
    todayBtn: "linked",
    clearBtn: true,
    minViewMode: 1,
    maxViewMode: 1,
    language: "th",
    daysOfWeekHighlighted: "0",
    autoclose: true,
    todayHighlight: true
  });
}

$(function(){

  createdatepicker('txtDay1');
  createdatepicker('txtDay2');
  createMpicker('txtMount');
  createYpicker('txtYear');
  createYpicker('txtYear1');
  createYpicker('txtYear2');

});

 

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

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