Subversion Repositories SmartDukaan

Rev

Rev 22655 | Rev 22860 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22655 Rev 22681
Line 797... Line 797...
797
	}
797
	}
798
	return true;
798
	return true;
799
	
799
	
800
}
800
}
801
 
801
 
-
 
802
function getSerialNumbersFromOrder($el){
-
 
803
	var $serialNumberElement = $el.find('.serialNumber');
-
 
804
	var insuranceAmount = parseFloat($el.find('.insuranceAmount').val());
-
 
805
	if(insuranceAmount > 0){
-
 
806
		insurance = true;
-
 
807
		globalInsurace = true;
-
 
808
	}else{
-
 
809
		insurance = false;
-
 
810
	}
-
 
811
	return {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
-
 
812
}
-
 
813
 
802
function orderDetailsPayload(){
814
function orderDetailsPayload(){
803
		var orderObj = {};
815
		var orderObj = {};
804
		var priceQtyArray = [];
816
		var priceQtyArray = [];
805
		var customerObj = {};
817
		var customerObj = {};
806
		var paymentOption = [];
818
		var paymentOption = [];
-
 
819
		globalInsurace = false;
807
		
820
		
808
		$("form#cd input.serialNumber").each(function(){
821
		$("form#cd input.serialNumber").each(function(){
809
			var itemId = parseInt($(this).attr("itemId"));
822
			var itemId = parseInt($(this).attr("itemId"));
810
			if (orderObj.hasOwnProperty('fofoLineItems')){
823
			if (orderObj.hasOwnProperty('fofoLineItems')){
811
				var itemDetails = orderObj['fofoLineItems'];
824
				var itemDetails = orderObj['fofoLineItems'];
Line 825... Line 838...
825
				tmp[itemId]  = serialNumbers;
838
				tmp[itemId]  = serialNumbers;
826
				orderObj['fofoLineItems'] = tmp;
839
				orderObj['fofoLineItems'] = tmp;
827
			}
840
			}
828
		});
841
		});
829
		console.log( JSON.stringify(orderObj));
842
		console.log( JSON.stringify(orderObj));
830
		/*$("form#cd input.unitPrice").each(function(){
-
 
831
			var itemId = parseInt($(this).attr("itemId"));
-
 
832
			var unitPrice = parseFloat($(this).val());
-
 
833
			var qty = parseInt($(this).attr("quantity"));
-
 
834
			var discountAmount = parseFloat($(this).val());
-
 
835
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
-
 
836
			if (orderObj['fofoLineItems'][itemId] === undefined){
-
 
837
				tmpObj['serialNumberDetails'] =[];
-
 
838
			}
-
 
839
			else{
-
 
840
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
-
 
841
				tmpObj['serialNumberDetails'] = [];
-
 
842
			}
-
 
843
			var found = false;
-
 
844
			for(var i = 0; i < priceQtyArray.length; i++){			
-
 
845
				if (priceQtyArray[i]["itemId"] == itemId){
-
 
846
					found = true;
-
 
847
					break;
-
 
848
				}
-
 
849
			}
-
 
850
			if(!found){
-
 
851
				priceQtyArray.push(tmpObj);
-
 
852
			}
-
 
853
		});*/
-
 
854
		
-
 
855
		$("#order-details").find("tr:not(:first-child)").each(function(index, el){
843
		$("#order-details").find("tr:not(:first-child)").each(function(index, el){
856
			//console.log(el);
844
			//console.log(el);
857
			//console.log(index);
845
			//console.log(index);
-
 
846
			var $el = $(el);
858
			var $unitPriceElement = $(el).find('.unitPrice');
847
			var $unitPriceElement = $el.find('.unitPrice');
859
			var $discountAmountElement = $(el).find('.discountAmount');
848
			var $discountAmountElement = $el.find('.discountAmount');
860
			
849
			
861
			var itemId = parseInt($unitPriceElement.attr("itemId"));
850
			var itemId = parseInt($unitPriceElement.attr("itemId"));
862
			var unitPrice = parseFloat($unitPriceElement.val());
851
			var unitPrice = parseFloat($unitPriceElement.val());
863
			var qty = parseInt($unitPriceElement.attr("quantity"));
852
			var qty = parseInt($unitPriceElement.attr("quantity"));
864
			var discountAmount = parseFloat($discountAmountElement.val());
853
			var discountAmount = parseFloat($discountAmountElement.val());
865
			var mop = $discountAmountElement.attr("mop");
854
			var mop = $discountAmountElement.attr("mop");
866
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
855
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
867
			tmpObj.discountAmount = discountAmount;
856
			tmpObj.discountAmount = discountAmount;
868
			
-
 
869
			if (orderObj['fofoLineItems'][itemId] === undefined){
-
 
870
				tmpObj['serialNumberDetails'] =[];
-
 
871
			}
-
 
872
			else{
-
 
873
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
-
 
874
				tmpObj['serialNumberDetails'] = [];
857
			tmpObj['serialNumberDetails'] = [getSerialNumbersFromOrder($el)];
875
			}
-
 
876
			var found = false;
-
 
877
			for(var i = 0; i < priceQtyArray.length; i++){			
-
 
878
				if (priceQtyArray[i]["itemId"] == itemId){
-
 
879
					found = true;
-
 
880
					break;
-
 
881
				}
-
 
882
			}
-
 
883
			if(!found){
-
 
884
				priceQtyArray.push(tmpObj);
858
			priceQtyArray.push(tmpObj);
885
			}
-
 
886
		});
-
 
887
		
-
 
888
		
-
 
889
		$("#order-details").find("tr:not(:first-child)").each(function(index,el){
-
 
890
			//console.log(el);
-
 
891
			//console.log(index);
-
 
892
			var $serialNumberElement = $(el).find('.serialNumber');
-
 
893
			var itemId = parseInt($serialNumberElement.attr("itemId"));
-
 
894
			var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
-
 
895
			//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
-
 
896
				
-
 
897
			//}
-
 
898
			//console.log($serialNumberElement.val());
-
 
899
			//console.log(itemId);
-
 
900
			for(var i = 0; i < priceQtyArray.length; i++){
-
 
901
				console.log(priceQtyArray[i]["itemId"]);			
-
 
902
				if (priceQtyArray[i]["itemId"] == itemId){
-
 
903
					if(insuranceAmount > 0){
-
 
904
						insurance = true;
-
 
905
					}else{
-
 
906
						insurance = false;
-
 
907
					}
-
 
908
					var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
-
 
909
					priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
-
 
910
				}
-
 
911
            }
-
 
912
			
859
			
913
		});
860
		});
914
		
861
		
915
		console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
862
		console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
916
		//customer-details
863
		//customer-details
Line 953... Line 900...
953
		});
900
		});
954
		console.log( JSON.stringify(paymentOption));
901
		console.log( JSON.stringify(paymentOption));
955
		
902
		
956
		var retObj = {};
903
		var retObj = {};
957
		var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
904
		var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
958
		if(insurance){
905
		if(globalInsurace){
959
			retObj['customerDateOfBirth'] = (dateOfBirth)
906
			retObj['customerDateOfBirth'] = (dateOfBirth);
960
		}
907
		}
961
		retObj['fofoLineItems'] = (priceQtyArray);
908
		retObj['fofoLineItems'] = (priceQtyArray);
962
		retObj['customer'] = (customerObj);
909
		retObj['customer'] = (customerObj);
963
		retObj['paymentOptions'] =  (paymentOption);
910
		retObj['paymentOptions'] =  (paymentOption);
964
		
911