<?php 
include('include/script.php'); 
$yearY = date("Y"); 
$yearM = date("m"); 
$yearD = date("d"); 
$current_time = $yearD.'.'.$yearM.'.'.($yearY+543);
?>
<script>  

$(document).ready(function(){

  SITEA_BILLHEADER();

});

function SITEA_BILLHEADER(){
  $.ajax({
  url: 'service/SITEA_BILLHEADER.php',
  dataType: 'text', 
  data: '',
  type: 'post',
  success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            //  alert('SITEA_BILLHEADER');
            SITEA_C1_HEADER();
        }else{
            alert('Not+++SITEA_BILLHEADER'+obj["RESULT"]);
        }
  },
  error: function (data) {

   return false;
  }
 }); 
}

function SITEA_C1_HEADER(){
    // alert('SITEA_C1_HEADER');
    $.ajax({
    url: 'service/SITEA_C1_HEADER.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            //  alert('SITEA_C1_HEADER OK');
            SITEA_C1_BILL();
        }else{
            alert('Not+++SITEA_C1_HEADER'+obj["RESULT"]);
        }
    },
    error: function (data) {
      return false;
    }
  }); 
}


function SITEA_C1_BILL(){
  // alert('SITEA_C1_BILL');
  $.ajax({
  url: 'service/SITEA_C1_BILL.php',
  dataType: 'text', 
  data: '',
  type: 'post',
  success: function (data) {
    var obj = JSON.parse(data)
      if(obj["STATUS"]=='1'){
          //  alert('SITEA_C1_BILL OK');
          SITEA_C1_VDRIVER();
      }else{
          alert('Not+++SITEA_C1_BILL'+obj["RESULT"]);
      }
  },
  error: function (data) {

   return false;
  }
 }); 
}

function SITEA_C1_VDRIVER(){  //ถ้าลบตรงนี้แล้ว PK แต่ค้นหาไม่พบ แต่เอา C1 มาค้นหาตรงๆเจอ แสดงว่า C1 header พัง เพราะไปจอยเอาวันที่ C1  C1 HEADER ต้องสำเร็จ
  // alert('SITEA_C1_VDRIVER');
    $.ajax({
    url: 'service/SITEA_C1_VDRIVER.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('SITEA_C1_VDRIVER OK');
            SPOD_CF_DETAILS();
        }else{
            alert('Not+++SITEA_C1_VDRIVER'+obj["RESULT"]);
        }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function SPOD_CF_DETAILS(){
    // alert('SPOD_CF_DETAILS');
    $.ajax({
    url: 'service/SPOD_CF_DETAILS.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('SITEA_C1_VDRIVER OK');
            BRANCH_TABLE();
        }else{
            alert('Not+++SPOD_CF_DETAILS'+obj["RESULT"]);
        }
    },
    error: function (data) {
    //    $('#other_owner_id').html(data);
      return false;
    }
  }); 
}

function BRANCH_TABLE(){
    // alert('BRANCH_TABLE');
      $.ajax({
      url: 'service/BRANCH_TABLE.php',
      dataType: 'text', 
      data: '',
      type: 'post',
      success: function (data) {
        var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('Success ');
            FLEET_TYPEID();
        }else{
            alert('Not+++BRANCH_TABLE'+obj["RESULT"]);
        }
      },
      error: function (data) {
        return false;
      }
  }); 
}

function FLEET_TYPEID(){
    // alert('FLEET_TYPEID');
    $.ajax({
    url: 'service/FLEET_TYPEID.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('FLEET_TYPEID OK');
            FLEET_VEHICLE_SPEC();
        }else{
            alert('Not+++FLEET_TYPEID'+obj["RESULT"]);
        }
    },
    error: function (data) {
      //    $('#other_owner_id').html(data);
      return false;
    }
  }); 
}

function FLEET_VEHICLE_SPEC(){
    // alert('FLEET_VEHICLE_SPEC');
    $.ajax({
    url: 'service/FLEET_VEHICLE_SPEC.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('FLEET_VEHICLE_SPEC OK');
            HR_EM_POSITION();
        }else{
            alert('Not+++FLEET_VEHICLE_SPEC'+obj["RESULT"]);
        }
    },
    error: function (data) {
    return false;
    }
  }); 
}

function HR_EM_POSITION(){
    // alert('HR_EM_POSITION');
    $.ajax({
    url: 'service/HR_EM_POSITION.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('HR_EM_POSITION OK');
            HR_EM_HEADER();
        }else{
            alert('Not+++HR_EM_POSITION'+obj["RESULT"]);
        }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function HR_EM_HEADER(){
    // alert('HR_EM_HEADER');
    $.ajax({
    url: 'service/HR_EM_HEADER.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
      if(obj["STATUS"]=='1'){
          // alert('HR_EM_HEADER OK');
          L_DELIVERY_DETAIL_TOPIC();
      }else{
          alert('Not+++HR_EM_HEADER'+obj["RESULT"]);
      }
    },
    error: function (data) {
  //    $('#other_owner_id').html(data);
    return false;
    }
  }); 
}

function L_DELIVERY_DETAIL_TOPIC(){
    // alert('L_DELIVERY_DETAIL_TOPIC');
    $.ajax({
    url: 'service/L_DELIVERY_DETAIL_TOPIC.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
      if(obj["STATUS"]=='1'){
          // alert('L_DELIVERY_DETAIL_TOPIC OK');
          T_DELIVERY_HEADER();
      }else{
          alert('Not+++L_DELIVERY_DETAIL_TOPIC'+obj["RESULT"]);
      }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function T_DELIVERY_HEADER(){
    // alert('T_DELIVERY_HEADER');
    $.ajax({
    url: 'service/T_DELIVERY_HEADER.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
      if(obj["STATUS"]=='1'){
          // alert('T_DELIVERY_HEADER OK');
          T_DELIVERY_DETAIL();
      }else{
          alert('Not+++T_DELIVERY_HEADER'+obj["RESULT"]);
      }
    },
    error: function (data) {
  //    $('#other_owner_id').html(data);
    return false;
    }
  }); 
}

function T_DELIVERY_DETAIL(){
  // alert('T_DELIVERY_DETAIL');
  $.ajax({
    url: 'service/T_DELIVERY_DETAIL.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('T_DELIVERY_DETAIL OK');
            SITEA_C1_BILLRETURN();
        }else{
            alert('Not+++T_DELIVERY_DETAIL'+obj["RESULT"]);
        }
      },
      error: function (data) {
    //    $('#other_owner_id').html(data);
    return false;
    }
  }); 
}

function SITEA_C1_BILLRETURN(){
    // alert('SITEA_C1_BILLRETURN');
    $.ajax({
    url: 'service/SITEA_C1_BILLRETURN.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('SITEA_C1_BILLRETURN OK');
            FLEET_VEHICLE_GROUP();
        }else{
            alert('Not+++SITEA_C1_BILLRETURN'+obj["RESULT"]);
        }
    },
      error: function (data) {
    //    $('#other_owner_id').html(data);
    return false;
    }
  }); 
}

function FLEET_VEHICLE_GROUP(){
    // alert('FLEET_VEHICLE_GROUP');
    $.ajax({
    url: 'service/FLEET_VEHICLE_GROUP.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
      var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            // alert('T_DELIVERY_DETAIL OK');
            SITEA_BILLOWNER();
        }else{
            alert('Not+++T_DELIVERY_DETAIL'+obj["RESULT"]);
        }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function SITEA_BILLOWNER(){
    $.ajax({
    url: 'service/SITEA_BILLOWNER.php',
    dataType: 'text', 
    data: '',
    type: 'post',
    success: function (data) {
        var obj = JSON.parse(data)
        if(obj["STATUS"]=='1'){
            //  alert('SITEA_BILLOWNER OK');
            SITEA_C1_VINV();
        }else{
            alert('Not+++SITEA_BILLOWNER'+obj["RESULT"]);
        }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function SITEA_C1_VINV(){
    $.ajax({
      url: 'service/SITEA_C1_VINV.php',
      dataType: 'json', 
      data: '',
      type: 'post',
      success: function (data) {
        if(data["STATUS"]=='1'){
            //  alert('SITEA_C1_VINV OK');
            SITEA_BILLRETURN_DRIVER();
        }else{
            alert('Not+++SITEA_C1_VINV'+data["RESULT"]);
        }
      },
        error: function (data) {
        return false;
      }
    }); 
}

function SITEA_BILLRETURN_DRIVER(){
    $.ajax({
    url: 'service/SITEA_BILLRETURN_DRIVER.php',
    dataType: 'json', 
    data: '',
    type: 'post',
      success: function (data) {
        if(data["STATUS"]=='1'){
              // alert('SITEA_BILLRETURN_DRIVER OK');
              SITEA_BILLRETURN_CUST();
          }else{
              alert('Not+++SITEA_BILLRETURN_DRIVER'+data["RESULT"]);
          }
      },
      error: function (data) {
        return false;
      }
    }); 
}

function SITEA_BILLRETURN_CUST(){

  $.ajax({
  url: 'service/SITEA_BILLRETURN_CUST.php',
  dataType: 'json', 
  data: '',
  type: 'post',
    success: function (data) {
      if(data["STATUS"]=='1'){
              // alert('SITEA_BILLRETURN_CUST OK');
              O_TRAINING_EMPLOYEE();
          }else{
              alert('Not+++SITEA_BILLRETURN_CUST'+data["RESULT"]);
          }
    },
    error: function (data) {
      return false;
    }
  }); 
}

function O_TRAINING_EMPLOYEE(){
  $.ajax({
  url: 'service/O_TRAINING_EMPLOYEE.php',
  dataType: 'json', 
  data: '',
  type: 'post',
    success: function (data) {
      if(data["STATUS"]=='1'){
          alert('Success OK');
          // O_TRAINING_EMPLOYEE();
      }else{
          alert('Not+++O_TRAINING_EMPLOYEE'+data["RESULT"]);
      }
    },
    error: function (data) {
      return false;
    }
  }); 
}

</script>

