'use strict'; // This module prepare by : Jaypee Tanio // June 16, 2013 var currentDate; var transCount; var transLoadPrev; var Gdate; var transPrevNight; function GetDate(d,m,y) { currentDate = y+'-'+m+'-'+d; transCount = 1; transLoadPrev = 1; transPrevNight = 1; $('document').ready(function(){ $('#save').click(function(){ if(($('#save').val()=='SAVE') && transCount==1) { transCount = 0; Gdate = currentDate; alert("Save: " + Gdate); $('.datalisting').each(function(){ var get_seq = 0; var get_time = $(this).find(".time").val(); var countchild = $(this).find(".tr").length; $(this).find(".tr").each(function(){ var get_measure = $(this).find(".measure").val(); var get_source = $(this).find(".source").val(); var get_selected = $(this).find(".selected").val(); GetSaveData(get_time, get_selected, get_source, get_measure, Gdate,get_seq); get_seq++; }); }); } else if(($('#save').val()=='UPDATE') && transCount==1) { transCount = 0; Gdate = currentDate; alert("Update: " + Gdate); GetDelete(Gdate); $('.datalisting').each(function(){ var get_seq = 0; var get_time = $(this).find(".time").val(); var countchild = $(this).find(".tr").length; $(this).find(".tr").each(function(){ var get_measure = $(this).find(".measure").val(); var get_source = $(this).find(".source").val(); var get_selected = $(this).find(".selected").val(); GetUpdateData(get_time, get_selected, get_source, get_measure, Gdate, get_seq); get_seq++; }); }); } }); function GetSaveData(Time,Data,Source,Measure,date,seq){ //alert("Time:"+Time+" | Measure:"+Measure +" | Source:"+Source+" | Data:"+Data); $.ajax({ type: "POST", cache: false, url: "Transaction/insert.php", data: "GTime="+Time+'&Source='+Source+'&measure='+Measure+'&Data='+Data+'&GDate='+date+'&seq='+seq, //posting the data to save success: function(data) { alert('Successfully added ! '+date); //$("#Data").append("Ok"+date); } }); }; function GetDelete(date){ //alert('del'); $.ajax({ type:"POST", cache:false, url:"Transaction/delete.php", data:"Gdate="+date, success:function(data){ } }); }; function GetUpdateData(Time,Data,Source,Measure,date,seq){ //alert("Time:"+Time+" | Measure:"+Measure +" | Source:"+Source+" | Data:"+Data); $.ajax({ type: "POST", cache: false, url: "Transaction/update.php", data: "GTime="+Time+'&Source='+Source+'&measure='+Measure+'&Data='+Data+'&GDate='+date+'&seq='+seq, //posting the data to save success: function(data) { alert('Successfully added ! '+date); //$("#Data").append("Ok"+date); } }); }; }); };