<!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" />
      
 



<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script> -->

<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css"> -->

<!-- Latest compiled and minified JavaScript -->
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script> -->

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/i18n/defaults-*.min.js"></script> -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/js/BsMultiSelect.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/js/BsMultiSelect.esm.min.js"></script>
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/css/BsMultiSelect.min.css">

<?php
    //set default timezone for creater and updater
    date_default_timezone_set('Asia/Hong_Kong');


?>
</head>

<body>

    <!-- admin javascript -->
     <script type="text/javascript">
      $( document ).ready(function() {

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


          if($('#code').val().length !== 0){
            $("#code").addClass(" is-valid ");
            $("#code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#code";
            }
            passCheck=false;
            $("#code").addClass(" is-invalid ");
           $("#code").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 ");
        //   }

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

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

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

          

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

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

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


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

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

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


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

          // if($('#gender').val().length !== 0){
          //   $("#gender").addClass(" is-valid ");
          //   $("#gender").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#gender";
          //   }
          //   passCheck=false;
          //   $("#gender").addClass(" is-invalid ");
          //  $("#gender").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/customerend/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

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


            var postData ={
                'code':$('#code').val(),
                'chi_name':$('#chi_name').val(),
                'eng_firstname':$('#eng_firstname').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'eng_lastname':$('#eng_lastname').val(),
                'gender':$('#gender').val(),
                'dob':$('#datepicker').val(),
                'mobile':$('#mobile').val(),
                'district_id':$('#area1').val(),
                'area_id':$('#level2').val(),
                'zone':$('#level3').val(),
                'address':$('#address').val(),
                'join_date':$('#datepicker2').val(),
                'shop_id':$('#first_registered_tenant_no').val(),
                'skin_improve':$('#skin_improve').val(),
                'referred_mobile':$('#referred_mobile').val(),
                'remark':$('#remark').val(),
                'need_purchase_service':$checkedpurchase,
                'service_id':$('#service_id').val(),
                'purchased_date':$('#purchased_date').val(),
                'purchased_qty':$('#purchased_qty').val(),
                'available_qty':$('#available_qty').val(),
                'remark2':$('#remark2').val(),
                'promotion_code':$('#promotion_code').val(),
                'first_registered_tenant_no':$('#first_registered_tenant_no').val(),  
                'concurrent_registered_tenant_no':$('#concurrent_registered_tenant_no').val(),  

            }

            // alert($('#level2').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) {

        //end add control


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


          if($('#code').val().length !== 0){
            $("#code").addClass(" is-valid ");
            $("#code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#code";
            }
            passCheck=false;
            $("#code").addClass(" is-invalid ");
           $("#code").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 ");
        //   }

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

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

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

          

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

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

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


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

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

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


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

          // if($('#gender').val().length !== 0){
          //   $("#gender").addClass(" is-valid ");
          //   $("#gender").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#gender";
          //   }
          //   passCheck=false;
          //   $("#gender").addClass(" is-invalid ");
          //  $("#gender").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/customerend/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

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


            var postData ={
                'code':$('#code').val(),
                'chi_name':$('#chi_name').val(),
                'eng_firstname':$('#eng_firstname').val(),
                // 'inputadminname':$('#inputadminname').val(),
                'eng_lastname':$('#eng_lastname').val(),
                'gender':$('#gender').val(),
                'dob':$('#datepicker').val(),
                'mobile':$('#mobile').val(),
                'district_id':$('#area1').val(),
                'area_id':$('#level2').val(),
                'zone':$('#level3').val(),
                'address':$('#address').val(),
                'join_date':$('#datepicker2').val(),
                'shop_id':$('#first_registered_tenant_no').val(),
                'skin_improve':$('#skin_improve').val(),
                'referred_mobile':$('#referred_mobile').val(),
                'remark':$('#remark').val(),
                'oridistrict_id':$('#oridistrict_id').val(),
                'oriarea_id':$('#oriarea_id').val(),
                'orizone':$('#orizone').val(),
                'first_registered_tenant_no':$('#first_registered_tenant_no').val(),  
                'concurrent_registered_tenant_no':$('#concurrent_registered_tenant_no').val(), 
                // 'need_purchase_service':$checkedpurchase,
                // 'service_id':$('#service_id').val(),
                // 'purchased_date':$('#purchased_date').val(),
                // 'purchased_qty':$('#purchased_qty').val(),
                // 'available_qty':$('#available_qty').val(),
                // 'remark2':$('#remark2').val(),
                'id':$('#id').val()

            }

            // alert($('#level2').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) {

        
        //end edit control


         $( ".level1select" ).change(function() {
          // alert( "Handler for .change() called." );
          level1boxajax($(this).attr("id"),$(this).val());
        });
          
          $( ".level2select" ).change(function() {
          // alert( "Handler for .change() called." );
          level2boxajax($(this).attr("id"),$(this).val());
        });

          $( ".level3select" ).change(function() {
          // alert( "Handler for .change() called." );
          $('#address').val($("#area1 option:selected").text()+$(this).val());
        });
        

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

         function level1boxajax($id,$value){
              var id = $id;
              // alert(id);
              var res = id.split("-");
              var fileid=res[0];
              var items=res[1];
              // alert("fileid"+fileid);
              // alert("items"+items);
              // var selectedid= $({"#".id}).val();
              var selectedid=$value;
              // alert(selectedid);
              var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  'destUrl':'<?php echo base_url();?>/api/v1/livingareaend/getSecondZone',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

              //empty lower select box

               var level2box = document.getElementById('level2');
                  // alert(city);
                   $(level2box).empty();     
   

              //end empty lower select box

              var postUrl= GlobalVariables.baseUrl +'/api/v1/livingareaend/getSecondZone';  
              //change select box option  
                 $.ajax({
                        type:'POST',
                        url:postUrl,
                        data:{'zone_id':selectedid},
                    success:function(data){
                      // alert('empty');
                      var obj = $.parseJSON(data);
                      // alert('empty2');
                    // var v = data.k; 

                   // the next thing you want to do 
                   // alert(fileid+'-'+items+'Level2');
                   // id='row' + id.toString();
                  // var findname=fileid.toString()+'-'+items.toString()+'-Level2';
                  // var city = document.getElementById(fileid+'-'.items+'Level2');
                  // var city = document.getElementById('5-1-Level2');
                  var level2box = document.getElementById('level2');
                  // alert(city);
                   $(level2box).empty();
                  //  $jsondata=json_decode($data);
                  // alert( obj.length);
                  // alert( obj[0]['name']);

                   //added empty select record  
                  $(level2box).append('<option  value=' + '>--- 請選擇居住範圍---'  + '</option>');
                  
                  //end added empty select record    
                  

                  for (var i = 0; i < obj.length; i++) {

                  $(level2box).append('<option  value=' + obj[i].id + '>' + obj[i].chi_name + '</option>');
                  }
                  // alert(data);
                  // level3boxajax(fileid+'-'+items+'-Level3', obj[0].id);   
                  // alert('level3'+data);
              }
            });

          }
        //end level1boxajax

        //level2ajax
        function level2boxajax($id,$value){
              var id = $id;
              // alert(id);
              var res = id.split("-");
              var fileid=res[0];
              var items=res[1];
              // alert("fileid"+fileid);
              // alert("items"+items);
              // var selectedid= $({"#".id}).val();
              var selectedid=$value;
              // alert(selectedid);
              var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  'destUrl':'<?php echo base_url();?>/api/v1/livingareaend/getThirdZone',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

              //empty lower select box

               var level3box = document.getElementById('level3');
                  // alert(city);
                   $(level3box).empty();     
   

              //end empty lower select box

              var postUrl= GlobalVariables.baseUrl +'/api/v1/livingareaend/getThirdZone';  
              //change select box option  
                 $.ajax({
                        type:'POST',
                        url:postUrl,
                        data:{'zone_id':selectedid},
                    success:function(data){
                      // alert('empty');
                      var obj = $.parseJSON(data);
                      // alert('empty2');
                    // var v = data.k; 

                   // the next thing you want to do 
                   // alert(fileid+'-'+items+'Level2');
                   // id='row' + id.toString();
                  // var findname=fileid.toString()+'-'+items.toString()+'-Level2';
                  // var city = document.getElementById(fileid+'-'.items+'Level2');
                  // var city = document.getElementById('5-1-Level2');
                  var level3box = document.getElementById('level3');
                  // alert(city);
                   $(level3box).empty();
                  //  $jsondata=json_decode($data);
                  // alert( obj.length);
                  // alert( obj[0]['name']);

                   //added empty select record  
                  $(level3box).append('<option  value=' + '>--- 請選擇居住範圍---'  + '</option>');
                  
                  //end added empty select record    
                  

                  for (var i = 0; i < obj.length; i++) {

                  $(level3box).append('<option  value=' + obj[i] + '>' + obj[i] + '</option>');
                  }
                  // alert(data);
                  // level3boxajax(fileid+'-'+items+'-Level3', obj[0].id);   
                  // alert('level3'+data);
              }
            });

          }

        //end level2ajax




      </script>
    


    <?php   include('include/header.php');?>
    <div class="wrapper" >
        
        <?php   include('include/sidebar.php');?>
        <!-- Page Content  -->
        <div id="content" style="background-color: #ffffff;">
          <!-- <h5>新增客戶</h5> -->
          <div class="title"><?php if($pagemethod=="add"){ 
                echo "新增客戶";
              }?>  
              <?php if($pagemethod=="edit"){ 
                echo "更改客戶";
              }?></div> 

           <div style="" class="menubar2">

           <a href="/at-cms/customeradmin"> <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>
            </div>
            <!-- add button -->
            
            <!-- input form -->
            <form>
            <div class="form-group row">
              <label for="username" class="col-sm-2 col-form-label">客戶編號*</label>
              <div class="col-sm-10">
                <input type="text"  class="form-control" id="code" name="code" value="<?php
                if($pagemethod=="add"){ echo 
                 $customercode;
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->code;
              }
               
              ?>" placeholder="輸入客戶編號" <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="chi_name" class="col-sm-2 col-form-label">中文名稱</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="chi_name" name="chi_name" placeholder="輸入中文名稱" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->chi_name;
              }
                

              ?>" <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="eng_firstname" class="col-sm-2 col-form-label">英文姓</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="eng_firstname" name="eng_firstname" placeholder="輸入英文姓" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->eng_firstname;
              }?>" <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料或密碼和登入密碼不同</div>
              </div>
            </div>
            <div class="form-group row">
              <label for="eng_lastname" class="col-sm-2 col-form-label">英文名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="eng_lastname" name="eng_lastname" placeholder="輸入英文名" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->eng_lastname;
              }?>"
              <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>
              >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>
             <div class="form-group row">
              <label for="eng_firstname" class="col-sm-2 col-form-label">性別</label>
              <div class="col-sm-10">
                <?php
                            // $st[""] = "";
                            // $st["0"] = "女";
                            // $st["1"] = "男";

                            // echo form_dropdown('gender', $st, 0, 'id="gender" name="gender" data-placeholder="' . ' '  . '" class="form-control input-tip select2" style=""');
                            ?>
                <select  id="gender" name="gender" data-placeholder="" class="form-control input-tip select2" style="" <?php
                
                if($pagemethod=="details"){ echo 
                 "disabled";
              }
              ?>>
                  <option value="" <?php if($pagemethod=="edit" || $pagemethod=="details"){ 
                if($customerdetails->gender=="") {echo "selected";}
              }?>></option>
              <option value="0" <?php if($pagemethod=="edit" || $pagemethod=="details"){ 
                if($customerdetails->gender=="0") {echo "selected";}
              }?>>女</option>
              <option value="1" <?php if($pagemethod=="edit" || $pagemethod=="details"){ 
                if($customerdetails->gender=="1") {echo "selected";}
              }?>>男</option>
                </select>
                <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">
                  <!-- date picker -->
                  <!-- dob readonly="true" -->
                  <input id="datepicker" width="276" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->dob;
              }?>" <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>/>
                  <script>
                      $('#datepicker').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="mobile" class="col-sm-2 col-form-label">手機號碼*</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="mobile" name="mobile" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->mobile;
              }?>" <?php
                
                if($pagemethod=="details"){ 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 level1select" id="area1" >
                                <option value="">--- 請選擇居住區域 ---</option>
                             <?php foreach ($firstzone as $firstzonedata): ?>
                               <option value="<?php echo $firstzonedata->id;?>"  ><?php echo $firstzonedata->chi_name;?></option>
                             <?php endforeach ?>
                          <!-- <option value="">1</option> -->
                            </select>   


                <!-- end first column area 1 -->
                <!-- second column area 2 -->
                <select class="form-control level2select" id="level2">
                    <option value=""></option>
                </select> 
                <!-- end second column area 2 -->

                <!-- second column area 3 -->
                <select class="form-control level3select" id="level3">
                    <option value=""></option>
                </select> 
                <!-- end second column area 3 -->

                <!-- <select class="select mas-select select2-offscreen" name="income_type" id="income_type" tabindex="-1">
                  <option value="">--- 請選擇薪酬種類 ---</option> -->
                <?php
                  //foreach ($employeeincometype as $row) {
                ?>
                <!-- <option value="<?php echo $row->id;?>" ><?php echo $row->name;?></option> -->
                 <?php
                    // }
                  ?>
                <?php 

                if($pagemethod=="edit"){

                ?>
                    <input type="hidden" class="form-control" id="oridistrict_id" name="oridistrict_id" placeholder="" value="<?php echo 
                 $customerdetailslivingarea->district_id;?>">

                    <input type="hidden" class="form-control" id="oriarea_id" name="oriarea_id" placeholder="" value="<?php echo 
                 $customerdetailslivingarea->area_id;?>">

                    <input type="hidden" class="form-control" id="orizone" name="orizone" placeholder="" value="<?php echo 
                 $customerdetailslivingarea->zone;?>">
                <?php
               }

                ?>
                <!-- </select> -->
                <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">
                <input type="text" class="form-control" id="address" name="address" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit"  || $pagemethod=="details"){ echo 
                 $customerdetailslivingarea->address;
              }?>">
                <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">
                <!-- date picker -->
                <!-- dob readonly="true" -->
                  <input id="datepicker2" width="276" value="<?php
                if($pagemethod=="add"){  
                 echo date("Y-m-d");
              } 
                if($pagemethod=="edit"  || $pagemethod=="details"){ echo 
                 $customerdetails->join_date;
              }?>" />
                  <script>
                      $('#datepicker2').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="inputPassword" class="col-sm-2 col-form-label">首次登記分店</label>
              <div class="col-sm-10">
                 <select class="select mas-select select2-offscreen" name="first_registered_tenant_no" id="first_registered_tenant_no" tabindex="-1"
                 <?php
                
                if($pagemethod=="details"){ echo 
                 "disabled";
              }
              ?>
                 >
                  <!-- <option value="">--- 請選擇薪酬種類 ---</option> -->
                <?php
                  foreach ($shop as $row) {
                ?>
                <option value="<?php echo $row->id;?>" <?php 
                  if(!empty($customerdetails->first_registered_tenant_no)){
                    if($customerdetails->first_registered_tenant_no==$row->id){
                      echo "selected";
                    }
                  }
                  
                ?> ><?php echo $row->name;?></option>
                 <?php
                    }
                  ?>

                </select>
                  <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">
                 <select class="select mas-select select2-offscreen" name="concurrent_registered_tenant_no" id="concurrent_registered_tenant_no" tabindex="-1"
                 <?php
                
                if($pagemethod=="details"){ echo 
                 "disabled";
              }
              ?>
                 >
                  <!-- <option value="">--- 請選擇薪酬種類 ---</option> -->
                <?php
                  foreach ($shop as $row) {
                ?>
                <option value="<?php echo $row->id;?>"  <?php 
                  if(!empty($customerdetails->concurrent_registered_tenant_no)){
                    if($customerdetails->concurrent_registered_tenant_no==$row->id){
                      echo "selected";
                    }
                  }
                  
                ?>><?php echo $row->name;?></option>
                 <?php
                    }
                  ?>

                </select>
                  <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">
                <?php  

                 
                  if($pagemethod=="add"){  
                 
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ 
                  // echo $customerdetailsSkinImprove->skin_improve_ids;
                  // echo "<br>";
                  $str1 = substr($customerdetailsSkinImprove->skin_improve_ids, 1); 
                  $str2 = substr($str1, 0, -1); 
                  $pieces = explode(",", $str2);
              }
                ?>
     <!--            <input type="text" class="form-control" id="commission" name="commission" placeholder=""> -->
              <select multiple data-style="bg-white rounded-pill px-4 py-3 shadow-sm " class="selectpicker w-100" id="skin_improve" name="skin_improve" <?php
                
                if($pagemethod=="details"){ echo 
                 "disabled";
              }
              ?>>
                <?php  foreach ($shopimprove as $shopimproverow) {
                ?>
                    <option value="<?php echo $shopimproverow->id;?>"  <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array($shopimproverow->id, $pieces)){
                        echo "selected";
                      }
                    }
                    ?>><?php echo $shopimproverow->name;?></option>
                <?php
                }//foreach ($shopimprove as $shopimproverow) {
                ?>
   
            </select><!-- End -->

           <!--  <select class="selectpicker1" multiple data-live-search="true">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select> -->

                <script type="text/javascript">
                   $(function () {
                    // $('.selectpicker').selectpicker();
                     $('.selectpicker').bsMultiSelect();

                    // $('select').selectpicker();
                });


                </script>
                <style type="text/css">
                    .bootstrap-select .bs-ok-default::after {
                        width: 0.3em;
                        height: 0.6em;
                        border-width: 0 0.1em 0.1em 0;
                        transform: rotate(45deg) translateY(0.5rem);
                    }

                    .btn.dropdown-toggle:focus {
                        outline: none !important;
                    }

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

            <div class="form-group row">
              <label for="referred_mobile" class="col-sm-2 col-form-label">介紹人手機號碼</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="referred_mobile" name="referred_mobile" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->referred_mobile;
              }?>"  <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>>
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div>

            <div class="form-group row">
              <label for="promotion_code" class="col-sm-2 col-form-label">促銷代碼</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="promotion_code" name="promotion_code" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ 

                  if(!empty($customerdetailsPromotionCode->promotion_code)){
                     echo  $customerdetailsPromotionCode->promotion_code;
                  }
                 
              }?>"  <?php
                
                if($pagemethod=="details"){ 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">
                <textarea  type="text" class="form-control" id="remark" name="remark" rows="4" cols="50" placeholder="輸入備註" <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?>><?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ echo 
                 $customerdetails->remark;
              }?></textarea>
              </div>
            </div>

            <?php 

              if($pagemethod=="edit" || $pagemethod=="details"){
            ?>
            <div class="form-group row">
              <label for="update_time" class="col-sm-2 col-form-label">更改時間</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="update_time" name="update_time" placeholder="" value="<?php
                
                if($pagemethod=="edit" || $pagemethod=="details"){ 
                  if(!empty($customerdetails->update_time)){
                     // $date = new DateTime($customerdetails->update_time, new DateTimeZone('Asia/Hong') );
                     //  echo $date->format('Y-m-d H:i:s');

                     echo  date("Y-m-d H:i:s",$customerdetails->update_time);
                  }
                 
              }?>"  <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?> >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

          <?php 
                }
           ?>

             <?php 

              if($pagemethod=="edit" || $pagemethod=="details"){
            ?>
            <div class="form-group row">
              <label for="updated_by" class="col-sm-2 col-form-label">更改者</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="updated_by" name="updated_by" placeholder="" value="<?php
                
                if($pagemethod=="edit" || $pagemethod=="details"){ 

                  if(!empty($updater->eng_firstname)){
                     echo  $updater->eng_firstname;
                     echo " ";
                  }
                  if(!empty($updater->eng_lastname)){
                     echo  $updater->eng_lastname;
                  }
                 
              }?>"  <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?> >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

          <?php 
                }
           ?>

           <?php 

              if($pagemethod=="edit" || $pagemethod=="details"){
            ?>
            <div class="form-group row">
              <label for="create_time" class="col-sm-2 col-form-label">創建時間</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="create_time" name="create_time" placeholder="" value="<?php
                
                if($pagemethod=="edit" || $pagemethod=="details"){ 

                  if(!empty($customerdetails->create_time)){
                     echo  date("Y-m-d H:i:s",$customerdetails->create_time);
                  }
                 
              }?>"  <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?> >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

          <?php 
                }
           ?>

            <?php 

              if($pagemethod=="edit" || $pagemethod=="details"){
            ?>
            <div class="form-group row">
              <label for="created_by" class="col-sm-2 col-form-label">創建者</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="created_by" name="created_by" placeholder="" value="<?php
                
                if($pagemethod=="edit" || $pagemethod=="details"){ 

                  if(!empty($creator->eng_firstname)){
                     echo  $creator->eng_firstname;
                     echo " ";
                  }
                  if(!empty($creator->eng_lastname)){
                     echo  $creator->eng_lastname;
                  }
                 
              }?>"  <?php
                
                if($pagemethod=="details"){ echo 
                 "readonly";
              }
              ?> >
                <div class="valid-feedback">正確</div>
                <div class="invalid-feedback">没有资料</div>
              </div>
            </div> 

          <?php 
                }
           ?>

            <div class="form-group row">
                        <div class="col-sm-12">
                        <p style="font-size: 12px;"><span style="color:#616161">*為必填項目</span></p>
                       
                         </div>
            </div>
            <?php
                if($pagemethod=="add"){
            ?>


            <h5>購買療程服務</h5>

            <div class="form-group row">
              <label for="promotion_code" class="col-sm-2 col-form-label">新增購買療程服務</label>
              <div class="col-sm-10">
                <input type="checkbox" id="need_purchase_service" name="need_purchase_service" value="true">
                <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 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"/>
                  <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="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="1">
                <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="1">
                <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="輸入備註"></textarea>
              </div>
            </div>

            <?php

            }//if($pagemethod=="add"){?>

             <div class="form-group row">
                      <div class="col-sm-12 text-center">
                      <span id="newmsg" class="text-center"></span>
                      </div>
            </div>
            
            <!-- load old services record -->
            <?php
              //var_dump($customerService);
            ?>

            <!-- service table -->
              <table id="book-table" class="display responsive wrap table table-bordered table-striped table-hover  ">
         
            <!-- <table id="book-table" class="display responsive nowrap"  width="100%"> -->
            <thead>
            <tr><td>購買日期</td><td>服務種類</td><td>服務項目</td><td>已購買次數</td><td>剩餘次數</td><td>編輯</td></tr>

            </thead>
            <tbody>    
            <?php
              foreach ($customerService as $servicerow) {
            ?>
               <tr><td><?php echo $servicerow->purchased_date;?></td>
                <td><?php echo $servicerow->servicecode;?></td>
                <td><?php echo $servicerow->servicename;?></td>
                <td><?php echo $servicerow->purchased_qty;?></td>
                <td><?php echo $servicerow->available_qty;?></td>
                <td><?php echo $servicerow->purchased_date;?></td>
               </tr>
            <?php
              }//foreach ($customerService as $servicerow) {

            ?>
            </tbody>
            </table>
            <!-- end service table -->

            <!-- end load old services record -->

            
            <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
                        }//if($pagemethod=="add"){?>
                        <?php
                        if($pagemethod=="edit"){?>
                          
                           <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php echo 
                 $customerdetails->id;
              ?>">
                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnResetUpdate" onClick="window.location.reload();">重設</button>
                          <button type="button" class="btn  px-5  custombutton" id="btnUpdate">更改</button>
                        <?php
                        }//if($pagemethod=="edit"){?>

                        <?php
                        if($pagemethod=="details"){?>
                          
                           <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php echo 
                 $customerdetails->id;
              ?>">
                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnResetUpdate" onClick="window.location.reload();">重設</button>
                          <button type="button" class="btn  px-5  custombutton" id="btnUpdate" onclick="location.href='<?php 
                          $link="at-cms/customeradmin/edit/".$customerdetails->id;
                          echo site_url($link); ?>';">更改</button>
                        <?php
                        }//if($pagemethod=="edit"){?>
                        </div>
            </div>
             
          </form>
          <!-- end input form -->
           
            <!-- end add button -->

            
        </div>
    </div>


    <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>