<!DOCTYPE html>
<html>

<head>

<?php   include('include/common.php');?>  



 <script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script>
    <link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css" />



<!-- new datatable js and css -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.css"/>
<!-- <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script> -->
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.4/css/responsive.dataTables.min.css"/>
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css"/>

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>

<!-- https://code.jquery.com/jquery-3.5.1.js
https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js -->
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.4/js/dataTables.responsive.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.colVis.min.js"></script>


<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>

<!-- end new datatable js and css -->


</head>

<body>

    <!-- admin javascript -->
     <script type="text/javascript">

      // alert("123");
      // $( document ).ready(function() {
      //   alert($('#unit_price').val());
      // }
      //   //added change input box javascript
      //    $('#unit_price').change(function() {
      //     alert("123");
      //     // console.log('.change = ' + $(this).val());
      //   });

        //end added change input box javascript
      function showdeletemodal() {
                // checkboxes = document.getElementsByName('admincheck');
                // var favorite = [];
                // $count=0;
                // $.each($("input[name='admincheck']:checked"), function(){
                //     favorite.push($(this).val());
                //     $count=$count+1;
                // });
                // // alert(1);
                // // alert("My favourite sports are: " + favorite.join(", "));
                // document.getElementById("deletenum").innerHTML = $count;
                $('#deleteModalCenter').modal({
                                    show: true,
                                }); 
    }//function showdeletemodal() {    



      $( document ).ready(function() {

          //add control
        $("#btnSubmit").click(function(event) {
          var forcusitem="";
          var passCheck=true;


          if($('#service_id').val().length !== 0){
            $("#service_id").addClass(" is-valid ");
            $("#service_id").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#service_id";
            }
            passCheck=false;
            $("#service_id").addClass(" is-invalid ");
           $("#service_id").removeClass(" is-valid ");
          }


           if($('#available_qty').val().length !== 0){
            $("#available_qty").addClass(" is-valid ");
            $("#available_qty").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#available_qty";
            }
            passCheck=false;
            $("#available_qty").addClass(" is-invalid ");
           $("#available_qty").removeClass(" is-valid ");
          }


          if($('#purchased_qty').val().length !== 0){
            $("#purchased_qty").addClass(" is-valid ");
            $("#purchased_qty").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#purchased_qty";
            }
            passCheck=false;
            $("#purchased_qty").addClass(" is-invalid ");
           $("#purchased_qty").removeClass(" is-valid ");
          }

          if($('#reason').val().length !== 0){
            $("#reason").addClass(" is-valid ");
            $("#reason").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#reason";
            }
            passCheck=false;
            $("#reason").addClass(" is-invalid ");
           $("#reason").removeClass(" is-valid ");
          }


        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

         




        //   alert("1");
          if(passCheck==true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'/api/v1/brserviceuserend/add';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            $checkeddebate=0;
            if($('#no_credit_rebate').is(':checked')){
                $checkeddebate=1;
            }
            else
            {
              $checkeddebate=0;
            }  

            var postData ={
                'service_id':$('#service_id').val(),
                'available_qty':$('#available_qty').val(),
                'purchased_qty':$('#purchased_qty').val(),
                'unit_price':$('#unit_price').val(),
                'purchased_price':$('#purchased_price').val(),
                'remark2':$('#remark2').val(),
                'id':$('#id').val(),
                'reason':$('#reason').val(),
                'purchased_date':$('#purchased_date').val(),
            }
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){
        });//$("#btnSubmit").click(function(event) {

            $('#btnReset').click(function() {
                  $('#category_code').val('1'); 
                  $('#code').val('lastestcode');  
                  $('#name').val('');  
                  $('#description').val('');  
                  $('#work').val('2');  
                  $('#price').val('');  
                  $('#no_credit_rebate').val('');   
                  $('#time').val('60');   
                  $('#remark').val('');   
              });   


              //refresh update
              $('#btnResetUpdate').click(function() {
                  location.reload();
              });  

              //end refresh updae


              //button update
                
      $("#btnUpdate").click(function(event) {
          var forcusitem="";
          var passCheck=true;


          if($('#service_id').val().length !== 0){
            $("#service_id").addClass(" is-valid ");
            $("#service_id").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#service_id";
            }
            passCheck=false;
            $("#service_id").addClass(" is-invalid ");
           $("#service_id").removeClass(" is-valid ");
          }

          if($('#available_qty').val().length !== 0){
            $("#available_qty").addClass(" is-valid ");
            $("#available_qty").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#available_qty";
            }
            passCheck=false;
            $("#available_qty").addClass(" is-invalid ");
           $("#available_qty").removeClass(" is-valid ");
          }


          if($('#purchased_qty').val().length !== 0){
            $("#purchased_qty").addClass(" is-valid ");
            $("#purchased_qty").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#purchased_qty";
            }
            passCheck=false;
            $("#purchased_qty").addClass(" is-invalid ");
           $("#purchased_qty").removeClass(" is-valid ");
          }

          if($('#reason').val().length !== 0){
            $("#reason").addClass(" is-valid ");
            $("#reason").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#reason";
            }
            passCheck=false;
            $("#reason").addClass(" is-invalid ");
           $("#reason").removeClass(" is-valid ");
          }


          
          
        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          




        //   alert("1");
          if(passCheck==true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'/api/v1/brserviceuserend/update';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            // $checkeddebate=0;
            // if($('#no_credit_rebate').is(':checked')){
            //     $checkeddebate=1;
            // }
            // else
            // {
            //   $checkeddebate=0;
            // }  

            var postData ={
                'service_id':$('#service_id').val(),
                'available_qty':$('#available_qty').val(),
                'purchased_qty':$('#purchased_qty').val(),
                'unit_price':$('#unit_price').val(),
                'purchased_price':$('#purchased_price').val(),
                'purchased_date':$('#purchased_date').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'remark2':$('#remark2').val(),
                // 'no_credit_rebate':$('#no_credit_rebate').val(),
                'id':$('#id').val(),
                'reason':$('#reason').val()
            }
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){
        });//$("#btnUpdate").click(function(event) {


          
        });// $( document ).ready(function() {

        $(document).ready(function(){
             $("#btndeleteSubmit").click(function(event) {       
              var forcusitem="";
          var passCheck=true;
            //check delete have value
            // var checkboxvalue = $('.checkbox').val();   


             var postData ={
                // 'service_id':$('#service_id').val(),
                // 'available_qty':$('#available_qty').val(),
                // 'purchased_qty':$('#purchased_qty').val(),
                // 'unit_price':$('#unit_price').val(),
                // 'purchased_price':$('#purchased_price').val(),
                // 'remark2':$('#remark2').val(),
                'id':$('#id').val(),
            }

            // var checkboxvalue =  [];    
            // // $("input.checkbox[type=checkbox]:checked").each(function(i){
            // //     alert(i.value );
            // // checkboxvalue.push( i.value );
            // // }); 

            // $('input.checkbox:checkbox:checked').each(function () {

            //     // alert($(this).val());
            //     checkboxvalue.push( $(this).val() );

            // });
            // var postData ={
            //     'inputdeletecheckboxvalue':checkboxvalue
            // }
            var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  'destUrl':'<?php echo base_url();?>/api/v1/fileend/delete',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'/api/v1/brserviceuserend/delete';
            //end　check delete have value
            // $('#loading').show();
             $.ajax({
                      method: "POST",
                      url: postUrl,
                      dataType: "json",
                     data: postData,
                     success : function(data){

                    // alert("posted");
                    // alert('formsubmit');
                    // alert(data);
                    
                    // alert(data['recordstatus']);
                    // alert(data['msg']);
                    if(data['recordstatus']=="SUCCESS"){
                        // $('#feedback').remove();
                        $( '#deletemsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                        setTimeout(function() {
                        //     location.reload();
                        <?php if(!empty($servicesuserdetails->user_id)){
                        ?>    

                        location.href='/at-cms/brcustomeradmin/edit/<?php echo $servicesuserdetails->user_id;?>';

                      <?php
                        }
                        ?>
                        }, 3000);
                        // location.reload();

                    }
                      if(data['recordstatus']=="FAILURE"){
                        // $('#feedback').remove();
                        $( '#deletemsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                    //   $( '#modal-bodymsg' ).empty();
                    //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                    //   $('#finishModal').modal('show');
                    // }
                      // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                      //     window.location.href=GlobalVariables.destUrl;
                      // } else {
                      //     $('.alert').text("登入錯誤");
                      //    $('.alert').removeClass('hidden');
                      }
                  }
                }); 

        });  //$("#btndeleteSubmit").click(function(event)
        });
        $(document).ready(function(){
          //for calculate purchase user qty
          let tempInput;
          $("#purchased_qty").keyup(function(){
            // alert($("#purchased_qty").val);
            tempInput=$("#unit_price").val() * $("#purchased_qty").val();
            $("#purchased_price").val(tempInput);            
          });
          $("#unit_price").keyup(function(){
            tempInput=$("#unit_price").val() * $("#purchased_qty").val();
            $("#purchased_price").val(tempInput);               
          });
          $("#purchased_price").keyup(function(){
            tempInput=$("#purchased_price").val() / $("#purchased_qty").val();       
            $("#unit_price").val(tempInput);      
          });

        });


      </script>
    


    <?php   include('include/header.php');?>
    <div class="wrapper" >
        
        <?php   include('include/sidebar.php');?>
        <!-- Page Content  -->

           <!-- delete modal -->
            <script>
                
            </script>

            <div class="modal fade" id="deleteModalCenter" tabindex="-1" role="dialog" aria-labelledby="deleteModalCenterTitle" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered  " role="document" style="max-width: 600px;">
                <div class="modal-content px-3">
                <!-- <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                </div> -->
                <div class="modal-body ">
                     <h5 style="color:<?php echo MAIN_TEXT_COLOR;?>" class="text-center py-2"><i class="fas fa-plus mr-2" style="color:<?php echo MAIN_TEXT_COLOR;?>"></i>删除服務</h5>
                     <form>

                   
                    <div class="form-group row">
                        <label for="inputRePassword" class="col-sm-12 "><span style="color:<?php echo MAIN_TEXT_COLOR;?>;" >確定删除服務?</span></label>
                        
                        <span id="deletemsg" class="text-center"></span>
                    </div>
                    <!-- <div class="form-group row">
                        <div class="col-sm-12">
                        <p style="font-size: 12px;"><span style="color:#616161">*為必填項目<br>登入名稱為英文字或數字組成(不分大小寫)</span></p>
                        <span id="editmsg" class="text-center"></span>
                         </div>
                    </div> -->
                    <div class="form-group row">
                        <div class="col-sm-12 text-center">
                        <button type="button" class="btn  px-5  custombutton" id="btndeleteSubmit">確定</button>
                        <span id="deletemsg" class="text-center"></span>
                        </div>
                    </div>
                    <input type="hidden" class="form-control" id="inputadminid" placeholder="">
                    </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">Save changes</button>
                </div> -->
                </div>
            </div>
            </div>
            <script type="text/javascript">
             


            </script>
            <!-- end delete modal -->   


        <div id="content" style="background-color: #ffffff;">
          <div class="title"><?php if($pagemethod=="add"){ 
                echo "新增服務";
              }?>  
              <?php if($pagemethod=="edit"){ 
                echo "更改服務";
              }?></div> 

           <div style="" class="menubar2">
                      
<!--            <a href="/at-cms/brservicesadmin">
            <i class="fas fa-chevron-left" style=" display: inline-block;
  border-radius: 10px;
  box-shadow: 0px 0px 2px #888;
  color: #33aaae;
  padding: 2px 2px;"></i>
           返回</a> -->
           <?php 

            if($pagemethod=="add" ){
            ?>
              <a href="/at-cms/brcustomeradmin/edit/<?php echo $this->uri->segment(4);?>">
                <i class="fas fa-chevron-left" style=" display: inline-block;
  border-radius: 10px;
  box-shadow: 0px 0px 2px #888;
  color: #33aaae;
  padding: 2px 2px;"></i>
           返回</a>

          <?php
            }
            ?>
           <?php 
            if( $pagemethod=="edit"  ){
           ?>
            <a href="/at-cms/brcustomeradmin/edit/<?php echo $servicesuserdetails->user_id;?>">
            <i class="fas fa-chevron-left" style=" display: inline-block;
  border-radius: 10px;
  box-shadow: 0px 0px 2px #888;
  color: #33aaae;
  padding: 2px 2px;"></i>
           返回</a>
           <?php
            }//if($pagemethod=="edit"){
           ?>
         </div>
            <!-- add button -->
            <!-- <h5>新增服務</h5> -->
            <!-- input form -->
            <form>
            <div class="form-group row formrowdiv">
              <div class="col-sm-2 col-form-label formleftdiv" for="username" style="" >購買記錄詳性
            <!--   <label for="username" class="col-sm-2 col-form-label">服務種類*</label> --></div>
            
            </div>
            <div class="form-group row">
              <label for="name" class="col-sm-2 col-form-label">客戶名稱</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="name" name="name" placeholder="輸入服務項目" value="<?php if($pagemethod=="add"){
                  echo $customerdetail->display_name;
                }?><?php if($pagemethod=="edit"){ echo 
                 $servicesuserdetails->display_name;
              }?>"  <?php if($pagemethod=="add" || $pagemethod=="edit"){ echo 
                 "readonly";
              }?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有資料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="inputPassword" class="col-sm-2 col-form-label">服務項目*</label>
              <div class="col-sm-10">
                <!-- first column area 1 -->
                              <select class="form-control " id="service_id" name="service_id">
                                <option value="">--</option>
                             <?php foreach ($services as $servicesrow): ?>
                               <option value="<?php echo $servicesrow->id;?>"
                                <?php
                                if($pagemethod=="edit"){
                                  if($servicesrow->id==$servicesuserdetails->service_id){
                                    echo "selected";
                                  }
                                }
                                ?>  
                                 ><?php echo $servicesrow->name;?></option>
                             <?php endforeach ?>
                          <!-- <option value="">1</option> -->
                            </select>   


               

                <!-- </select> -->
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>

             <div class="form-group row">
              <label for="purchased_date" class="col-sm-2 col-form-label">購買日期</label>
              <div class="col-sm-10">
                  <!-- date picker -->
                  <!-- dob readonly="true" -->
<!--                   <input id="purchased_date" width="276" name="purchased_date" value="<?php echo $servicesuserdetails->purchased_date;?>" /> -->
              <?php
            function isTimestamp( $string ) {
                return ( 1 === preg_match( '~^[1-9][0-9]*$~', $string ) );
            }
            date_default_timezone_set('Asia/Hong_Kong');


            if($pagemethod=="edit"){
              $purchaseTimeStamp=$servicesuserdetails->purchased_date;

               $datetimeFormat = 'Y-m-d';
                $outPutDate="";
                $date = new \DateTime();
                // If you must have use time zones
                // $date = new \DateTime('now', new \DateTimeZone('Europe/Helsinki'));
                if(isTimestamp($purchaseTimeStamp)==false){
                  $outPutDate=$purchaseTimeStamp;
                }
                else{
                  $outPutDate=date('Y-m-d', $purchaseTimeStamp);
                }
            }//if($pagemethod=="edit"){
            ?>
                  <input id="purchased_date" width="276" name="purchased_date" value="<?php  if($pagemethod=="edit"){echo $outPutDate;}?>" readonly />
                  <script>
                      $('#purchased_date').datepicker({
                          uiLibrary: 'bootstrap4',
                          format: 'yyyy-mm-dd'
                      });
                  </script>
                  <!-- end date picker -->
                  
                  <div class="valid-feedback">正確</div>
                  <div class="invalid-feedback">没有资料</div>
              </div>
            </div>

            <div class="form-group row">
              <label for="available_qty" class="col-sm-2 col-form-label">可用次數*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="available_qty" name="available_qty" placeholder="" value="<?php  if($pagemethod=="edit"){echo $servicesuserdetails->available_qty;}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

             <div class="form-group row">
              <label for="purchased_qty" class="col-sm-2 col-form-label">購買次數*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="purchased_qty" name="purchased_qty" placeholder="" value="<?php  if($pagemethod=="edit"){echo $servicesuserdetails->purchased_qty;}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

             <div class="form-group row">
              <label for="purchased_price" class="col-sm-2 col-form-label">單次計</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="unit_price" name="unit_price" placeholder="" value="<?php  if($pagemethod=="edit"){echo  round($servicesuserdetails->unit_price,ROUNDDIGITS);}?>" >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>

             <div class="form-group row">
              <label for="purchased_price" class="col-sm-2 col-form-label">購買價錢</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="purchased_price" name="purchased_price" placeholder="" value="<?php  if($pagemethod=="edit"){echo round($servicesuserdetails->purchased_price,ROUNDDIGITS);}?>">
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>

            <div class="form-group row">
              <label for="inputPassword" class="col-sm-2 col-form-label">備註</label>
              <div class="col-sm-10">
                <textarea  type="text" class="form-control" id="remark2" name="remark2" rows="4" cols="50" placeholder="輸入備註"><?php  if($pagemethod=="edit"){echo $servicesuserdetails->serviceRemark;}?></textarea>
              </div>
            </div>

            <div class="form-group row">
              <label for="inputPassword" class="col-sm-2 col-form-label">原因*</label>
              <div class="col-sm-10">
                <textarea  type="text" class="form-control" id="reason" name="reason" rows="4" cols="50" placeholder="輸入原因"></textarea>
              </div>
            </div>

            <?php if($pagemethod=="add"){
                ?>
                  <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php 
                echo $customerdetail->id;?>">
             <?php    
              }?>

              <?php if($pagemethod=="edit"){
                ?>
                  <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php 
                echo $servicesuserdetails->id;?>">
             <?php    
              }?>
            
            <div class="form-group row">
                        <div class="col-sm-12">
                        <p style="font-size: 12px;"><span style="color:#616161">*為必填項目</span></p>
                        <span id="newmsg" class="text-center"></span>
                         </div>
            </div>
            
            <div class="form-group row">
                        <div class="col-sm-12 text-center">
                       <?php if($pagemethod=="add"){ 
                      ?>
                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnReset">重設</button>

                        <button type="button" class="btn  px-5  custombutton" id="btnSubmit">確定</button>
                      <?php
              }?><?php if($pagemethod=="edit"){
                ?>    

                      <button type="button" class="btn  px-5  custombutton mr-5" id="btnDelete" onclick="showdeletemodal()">删除</button>

                       <button type="button" class="btn  px-5  custombutton mr-5" id="btnResetUpdate">重設</button>

                        <button type="button" class="btn  px-5  custombutton" id="btnUpdate">更改</button>     
                <?php
              }?>
                        
                        </div>
            </div>
          </form>
          <!-- end input form -->
           
            <!-- end add button -->

          <!-- added change reson -->
          <?php if($pagemethod=="edit"){
                ?>
          <h5>更改記錄</h5> 
           <table id="reson-table" class="display responsive wrap table table-bordered table-striped table-hover  " width="100%"> 
            <thead>
            <tr><td>日期</td><td>動作</td><td>更改內客</td><td>原因</td></tr>

            </thead>
            <?php
            foreach ($servicesuserresons as $servicesuserrow) {
            ?>
            <tr>
                <td><?php //echo $servicesuserrow->create_time;
                  if(isTimestamp($servicesuserrow->create_time)==false){
                  $outPutDate=$servicesuserrow->create_time;
                }
                else{
                  $outPutDate=date('Y-m-d',$servicesuserrow->create_time);
                }

                echo $outPutDate;


                ?></td>
                <td><?php echo $servicesuserrow->action;?></td>
                <td><?php echo $servicesuserrow->description;?></td>
                <td><?php echo $servicesuserrow->reason;?></td>    
            </tr>
             <?php
              }//foreach ($servicesuserresons as $servicesuserrow) {

            ?>
             </tbody>
            </table>      
          <?php }//if($pagemethod=="edit"){
                ?>
          <!-- end change reason -->

            
        </div>
    </div>
     <script type="text/javascript">
            $(document).ready(function() {
                $('#reson-table').DataTable( {
                    "order": [[ 0, "desc" ]],
                     dom: 'Bfrtip',
                    buttons: [
                        // 'colvis'
                    ]
                }

                    );  
              });
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').toggleClass('active');
            });

            // password click
            bootstrapRevealPassword();

// Plugin to integrate in your javascript file
            function bootstrapRevealPassword() {
            $('[data-password]').closest('.form-group').addClass('position-relative').append('<span class="form-password-icon"><i class="material-icons">visibility_off</i></span>');

            $('.form-password-icon').on('click', function() {
                var clicks = $(this).data('clicks');
                if (clicks) {
                // odd clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye-slash"></i></span>').prevAll(':input').attr('type', 'password');
                } else {
                // even clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye"></i></span>').prevAll(':input').attr('type', 'text');
                }
                $(this).data("clicks", !clicks);
            });
            }

            // end password click

        });
    </script>
</body>

</html>