Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- console.log("Machine loaded");
- $("#BtnSend").on("click", function() {
- AddMachine();
- });
- GetListMachine(0);
- HideInput();
- });
- window.onscroll = function() {
- FunctionSticky()
- };
- var navbar = document.getElementById("navbar");
- var sticky = navbar.offsetTop;
- function FunctionSticky() {
- if (window.pageYOffset > sticky) {
- navbar.classList.add("sticky")
- // console.log(window.pageYOffset +"-"+sticky)
- } else {
- navbar.classList.remove("sticky");
- }
- }
- function AddMachine() {
- if ($("#NumberHousehold").val()
- && $("#Name").val()
- && $("#Lifetime").val()
- && $("#PurchasePrice").val()
- && (($("#BuyFreshOrPay").val() == "ผ่อนจ่าย"
- && $("#TotalInstallments").val() && $("#YearPayment").val()
- && $("#DownPayment").val() && $("#PayperYear").val()) || $(
- "#BuyFreshOrPay").val() == "ซื้อสด")) {
- $.ajax({
- url : "process/MachineProcess.php",
- method : "POST",
- data : {
- CMD : "ADD-Machine",
- NumberHousehold : $("#NumberHousehold").val(),
- Name : $("#Name").val(),
- Lifetime : $("#Lifetime").val(),
- PurchasePrice : $("#PurchasePrice").val(),
- BuyFreshOrPay : $("#BuyFreshOrPay").val(),
- TotalInstallments : $("#TotalInstallments").val(),
- YearPayment : $("#YearPayment").val(),
- DownPayment : $("#DownPayment").val(),
- PayperYear : $("#PayperYear").val()
- },
- success : function(result) {
- console.log(result);
- $("#Log").html(result);
- var obj = JSON.parse(result);
- if (obj.Success == 1 && obj.Error == 0) {
- $("#NumberHousehold").val("");
- $("#Name").val("");
- $("#Lifetime").val("");
- $("#PurchasePrice").val("");
- $("#BuyFreshOrPay").val("ซื้อสดหรือผ่อนจ่าย");
- $("#TotalInstallments").val("");
- $("#YearPayment").val("");
- $("#DownPayment").val("");
- $("#PayperYear").val("");
- HideInput();
- GetListMachine(1);
- } else if (obj.Success == 0 && obj.Error == 0) {
- swal("ไม่มีรหัสครัวเรือนนี้", "คลิก OK เพื่อออก", "error");
- } else {
- swal("การเพิ่มข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
- "error");
- }
- },
- error : function(_jqXHR, _textStatus, _errorThrown) {
- console.log("Error Machine");
- swal("Ajax Error", "คลิก OK เพื่อออก", "error");
- }
- });
- } else {
- swal("กรุณากรอกขอมูลให้ครบถ้วน", "คลิก OK เพื่อออก", "error");
- }
- }
- function DeleteMachine(IdMachine) {
- $.ajax({
- url : "process/MachineProcess.php",
- method : "POST",
- data : {
- CMD : "DELETE-Machine",
- IdMachine : IdMachine
- },
- success : function(result) {
- console.log(result);
- $("#Log").html(result);
- var obj = JSON.parse(result);
- if (obj.Error == 0) {
- GetListMachine(3);
- } else {
- swal("การลบข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
- "error");
- }
- },
- error : function(_jqXHR, _textStatus, _errorThrown) {
- console.log("Error Delerte Machine")
- swal("Ajax Error", "คลิก OK เพื่อออก", "error");
- }
- });
- }
- function EditMachine(IdMachine) {
- if ($("#NameModal").val()
- && $("#LifetimeModal").val()
- && $("#PurchasePriceModal").val()
- && (($("#BuyFreshOrPayModal").val() == "ผ่อนจ่าย"
- && $("#TotalInstallmentsModal").val()
- && $("#YearPaymentModal").val()
- && $("#DownPaymentModal").val() && $("#PayperYearModal")
- .val()) || $("#BuyFreshOrPayModal").val() == "ซื้อสด")) {
- $.ajax({
- url : "process/MachineProcess.php",
- method : "POST",
- data : {
- CMD : "EDIT-Machine",
- Name : $("#NameModal").val(),
- Lifetime : $("#LifetimeModal").val(),
- PurchasePrice : $("#PurchasePriceModal").val(),
- BuyFreshOrPay : $("#BuyFreshOrPayModal").val(),
- TotalInstallments : $("#TotalInstallmentsModal").val(),
- YearPayment : $("#YearPaymentModal").val(),
- DownPayment : $("#DownPaymentModal").val(),
- PayperYear : $("#PayperYearModal").val(),
- IdMachine : IdMachine
- },
- success : function(result) {
- console.log(result);
- $("#Log").html(result);
- var obj = JSON.parse(result);
- console.log("Error = " + obj.Error);
- if (obj.Error == 0) {
- GetListMachine(2);
- } else {
- swal("การแก้ไขข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
- "error");
- }
- },
- error : function(_jqXHR, _textStatus, _errorThrown) {
- console.log("Error Edit Machine");
- swal("Ajax Error", "คลิก OK เพื่อออก", "error");
- }
- });
- } else {
- swal("กรุณากรอกขอมูลให้ครบถ้วน", "คลิก OK เพื่อออก", "error");
- }
- }
- function GetListMachine(Numberfunction) {
- $.ajax({
- url : "process/MachineProcess.php",
- method : "POST",
- data : {
- CMD : "GET-LIST-Machine"
- },
- success : function(result) {
- console.log(result);
- var obj = JSON.parse(result);
- console.log("Error = " + obj.Error);
- $("#Log").html(result);
- if (obj.Error == 0) {
- $("#Log").html("เพิ่มข้อมูลสำเร็จ");
- console.log(obj.Data[0]);
- if (typeof (table) != "undefined") {
- table.destroy();
- }
- table = $('#machinelist').DataTable({
- data : obj.Data,
- columns : [ {
- title : "Action"
- }, {
- tit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement