| 21627 |
kshitij.so |
1 |
var googleProfile;
|
|
|
2 |
|
| 22139 |
amit.gupta |
3 |
|
|
|
4 |
$(document).ajaxComplete(
|
|
|
5 |
function(){
|
|
|
6 |
|
|
|
7 |
}
|
|
|
8 |
);
|
| 21627 |
kshitij.so |
9 |
var startApp = function() {
|
|
|
10 |
gapi.load('auth2', function(){
|
|
|
11 |
// Retrieve the singleton for the GoogleAuth library and set up the client.
|
|
|
12 |
auth2 = gapi.auth2.init({
|
| 22071 |
ashik.ali |
13 |
client_id: googleApiKey,
|
| 21627 |
kshitij.so |
14 |
cookiepolicy: 'single_host_origin',
|
|
|
15 |
// Request scopes in addition to 'profile' and 'email'
|
|
|
16 |
//scope: 'additional_scope'
|
|
|
17 |
});
|
|
|
18 |
attachSignin(document.getElementById('customBtn'));
|
|
|
19 |
});
|
|
|
20 |
};
|
|
|
21 |
|
|
|
22 |
function attachSignin(element) {
|
|
|
23 |
console.log(element.id);
|
|
|
24 |
auth2.attachClickHandler(element, {},
|
|
|
25 |
function(googleUser) {
|
|
|
26 |
googleProfile = googleUser.getBasicProfile();
|
|
|
27 |
console.log(googleProfile.getImageUrl());
|
|
|
28 |
submitUser(googleUser);
|
|
|
29 |
}, function(error) {
|
|
|
30 |
console.log(JSON.stringify(error, undefined, 2));
|
|
|
31 |
});
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
function submitUser(googleUser){
|
|
|
35 |
jQuery.ajax({
|
|
|
36 |
type : "POST",
|
| 22090 |
amit.gupta |
37 |
url : context+"/login",
|
| 22139 |
amit.gupta |
38 |
dataType: 'json',
|
| 21627 |
kshitij.so |
39 |
data: {"token":googleUser.getAuthResponse().id_token},
|
|
|
40 |
success: function(data, textStatus, request){
|
|
|
41 |
console.log(data);
|
|
|
42 |
addProfileInLocalDb();
|
| 22139 |
amit.gupta |
43 |
window.location.href= data.redirectUrl;
|
| 21627 |
kshitij.so |
44 |
}
|
|
|
45 |
});
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function addProfileInLocalDb(){
|
|
|
49 |
var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
|
|
|
50 |
localStorage.setItem("profile",JSON.stringify(profile));
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
function loadNewGrn(domId){
|
|
|
55 |
jQuery.ajax({
|
|
|
56 |
type : "GET",
|
| 22091 |
amit.gupta |
57 |
url : context+"/purchase",
|
| 21627 |
kshitij.so |
58 |
success : function(response) {
|
|
|
59 |
$('#' + domId).html(response);
|
|
|
60 |
}
|
|
|
61 |
});
|
|
|
62 |
}
|
|
|
63 |
|
| 21987 |
kshitij.so |
64 |
function loadGoodInventory(domId, search_text){
|
|
|
65 |
jQuery.ajax({
|
|
|
66 |
type : "GET",
|
| 22091 |
amit.gupta |
67 |
url : context+"/getCurrentInventorySnapshot/?searchTerm="+search_text,
|
| 21987 |
kshitij.so |
68 |
success : function(response) {
|
|
|
69 |
$('#' + domId).html(response);
|
|
|
70 |
}
|
|
|
71 |
});
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
function loadCatalog(domId, search_text){
|
|
|
75 |
jQuery.ajax({
|
|
|
76 |
type : "GET",
|
| 22091 |
amit.gupta |
77 |
url : context+"/getCatalog/?searchTerm="+search_text,
|
| 21987 |
kshitij.so |
78 |
success : function(response) {
|
|
|
79 |
$('#' + domId).html(response);
|
|
|
80 |
}
|
|
|
81 |
});
|
|
|
82 |
}
|
|
|
83 |
|
| 22488 |
ashik.ali |
84 |
function downloadAgingReport(){
|
|
|
85 |
data = JSON.stringify([5,10,15,20,25,30,35,40]),
|
|
|
86 |
xhttp = new XMLHttpRequest();
|
|
|
87 |
xhttp.onreadystatechange = function() {
|
|
|
88 |
var a;
|
|
|
89 |
if (xhttp.readyState === 4 && xhttp.status === 200) {
|
|
|
90 |
// Trick for making downloadable link
|
|
|
91 |
a = document.createElement('a');
|
|
|
92 |
a.href = window.URL.createObjectURL(xhttp.response);
|
|
|
93 |
// Give filename you wish to download
|
|
|
94 |
a.download = "InventoryItemAging.xlsx";
|
|
|
95 |
a.style.display = 'none';
|
|
|
96 |
document.body.appendChild(a);
|
|
|
97 |
a.click();
|
|
|
98 |
}
|
|
|
99 |
};
|
|
|
100 |
// Post data to URL which handles post request
|
|
|
101 |
xhttp.open("POST", context+"/getInventoryItemAgingByInterval");
|
|
|
102 |
xhttp.setRequestHeader("Content-Type", "application/json");
|
|
|
103 |
// You should set responseType as blob for binary responses
|
|
|
104 |
xhttp.responseType = 'blob';
|
|
|
105 |
xhttp.send(data);
|
|
|
106 |
}
|
|
|
107 |
|
| 21987 |
kshitij.so |
108 |
function loadBadInventory(domId, search_text){
|
|
|
109 |
jQuery.ajax({
|
|
|
110 |
type : "GET",
|
| 22090 |
amit.gupta |
111 |
url : context+"/getBadInventorySnapshot/?searchTerm="+search_text,
|
| 21987 |
kshitij.so |
112 |
success : function(response) {
|
|
|
113 |
$('#' + domId).html(response);
|
|
|
114 |
}
|
|
|
115 |
});
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
|
|
|
119 |
jQuery.ajax({
|
|
|
120 |
type : "GET",
|
| 22090 |
amit.gupta |
121 |
url : context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
|
| 21987 |
kshitij.so |
122 |
+"&startTime="+startTime
|
|
|
123 |
+"&endTime="+endTime,
|
|
|
124 |
success : function(response) {
|
|
|
125 |
$('#' + domId).html(response);
|
|
|
126 |
}
|
|
|
127 |
});
|
|
|
128 |
}
|
|
|
129 |
|
| 22245 |
ashik.ali |
130 |
|
|
|
131 |
|
| 22283 |
ashik.ali |
132 |
|
|
|
133 |
|
| 21987 |
kshitij.so |
134 |
function getNextItems(start, end, searchText){
|
|
|
135 |
console.log(start);
|
|
|
136 |
console.log(end);
|
|
|
137 |
console.log(+end + +10);
|
|
|
138 |
console.log(+start + +10);
|
|
|
139 |
jQuery.ajax({
|
|
|
140 |
type : "GET",
|
| 22090 |
amit.gupta |
141 |
url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText,
|
| 21987 |
kshitij.so |
142 |
beforeSend: function(){
|
|
|
143 |
//$('#ajax-spinner').show();
|
|
|
144 |
},
|
|
|
145 |
complete: function(){
|
|
|
146 |
//$('#ajax-spinner').hide();
|
|
|
147 |
},
|
|
|
148 |
success : function(response) {
|
|
|
149 |
$( "#good-inventory-paginated .end" ).text(+end + +10);
|
|
|
150 |
$( "#good-inventory-paginated .start" ).text(+start + +10);
|
|
|
151 |
var last = $( "#good-inventory-paginated .end" ).text();
|
|
|
152 |
var temp = $( "#good-inventory-paginated .size" ).text();
|
|
|
153 |
if (parseInt(last) >= parseInt(temp)){
|
|
|
154 |
$("#good-inventory-paginated .next").prop('disabled', true);
|
|
|
155 |
//$( "#good-inventory-paginated .end" ).text(temp);
|
|
|
156 |
}
|
|
|
157 |
$('#good-inventory-table').html(response);
|
|
|
158 |
$("#good-inventory-paginated .previous").prop('disabled', false);
|
|
|
159 |
},
|
|
|
160 |
error : function() {
|
|
|
161 |
alert("Unable to fetch items");
|
|
|
162 |
},
|
|
|
163 |
});
|
|
|
164 |
}
|
|
|
165 |
function getPreviousItems(start,end,pre,searchText){
|
|
|
166 |
jQuery.ajax({
|
|
|
167 |
type : "GET",
|
| 22090 |
amit.gupta |
168 |
url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText,
|
| 21987 |
kshitij.so |
169 |
beforeSend: function(){
|
|
|
170 |
//$('#ajax-spinner').show();
|
|
|
171 |
},
|
|
|
172 |
complete: function(){
|
|
|
173 |
//$('#ajax-spinner').hide();
|
|
|
174 |
},
|
|
|
175 |
success : function(response) {
|
|
|
176 |
$( "#good-inventory-paginated .end" ).text(+end - +10);
|
|
|
177 |
$( "#good-inventory-paginated .start" ).text(+start - +10);
|
|
|
178 |
$('#good-inventory-table').html(response);
|
|
|
179 |
$("#good-inventory-paginated .next").prop('disabled', false);
|
|
|
180 |
if (parseInt(pre)==0)
|
|
|
181 |
{
|
|
|
182 |
$("#good-inventory-paginated .previous").prop('disabled', true);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
},
|
|
|
186 |
error : function() {
|
|
|
187 |
alert("Unable to fetch items");
|
|
|
188 |
},
|
|
|
189 |
});
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
|
|
|
193 |
console.log(start);
|
|
|
194 |
console.log(end);
|
|
|
195 |
console.log(+end + +10);
|
|
|
196 |
console.log(+start + +10);
|
|
|
197 |
jQuery.ajax({
|
|
|
198 |
type : "GET",
|
| 22090 |
amit.gupta |
199 |
url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
|
| 21987 |
kshitij.so |
200 |
+"&startTime="+startTime
|
|
|
201 |
+"&endTime="+endTime+"&offset="+end,
|
|
|
202 |
beforeSend: function(){
|
|
|
203 |
//$('#ajax-spinner').show();
|
|
|
204 |
},
|
|
|
205 |
complete: function(){
|
|
|
206 |
//$('#ajax-spinner').hide();
|
|
|
207 |
},
|
|
|
208 |
success : function(response) {
|
|
|
209 |
$( "#grn-history-paginated .end" ).text(+end + +10);
|
|
|
210 |
$( "#grn-history-paginated .start" ).text(+start + +10);
|
|
|
211 |
var last = $( "#grn-history-paginated .end" ).text();
|
|
|
212 |
var temp = $( "#grn-history-paginated .size" ).text();
|
|
|
213 |
if (parseInt(last) >= parseInt(temp)){
|
|
|
214 |
$("#grn-history-paginated .next").prop('disabled', true);
|
|
|
215 |
//$( "#good-inventory-paginated .end" ).text(temp);
|
|
|
216 |
}
|
|
|
217 |
$('#grn-history-table').html(response);
|
|
|
218 |
$("#grn-history-paginated .previous").prop('disabled', false);
|
|
|
219 |
},
|
|
|
220 |
error : function() {
|
|
|
221 |
alert("Unable to fetch items");
|
|
|
222 |
},
|
|
|
223 |
});
|
|
|
224 |
}
|
|
|
225 |
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
|
|
|
226 |
jQuery.ajax({
|
|
|
227 |
type : "GET",
|
| 22090 |
amit.gupta |
228 |
url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
|
| 21987 |
kshitij.so |
229 |
+"&startTime="+startTime
|
|
|
230 |
+"&endTime="+endTime+"&offset="+pre,
|
|
|
231 |
beforeSend: function(){
|
|
|
232 |
//$('#ajax-spinner').show();
|
|
|
233 |
},
|
|
|
234 |
complete: function(){
|
|
|
235 |
//$('#ajax-spinner').hide();
|
|
|
236 |
},
|
|
|
237 |
success : function(response) {
|
|
|
238 |
$( "#grn-history-paginated .end" ).text(+end - +10);
|
|
|
239 |
$( "#grn-history-paginated .start" ).text(+start - +10);
|
|
|
240 |
$('#grn-history-table').html(response);
|
|
|
241 |
$("#grn-history-paginated .next").prop('disabled', false);
|
|
|
242 |
if (parseInt(pre)==0)
|
|
|
243 |
{
|
|
|
244 |
$("#grn-history-paginated .previous").prop('disabled', true);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
},
|
|
|
248 |
error : function() {
|
|
|
249 |
alert("Unable to fetch items");
|
|
|
250 |
},
|
|
|
251 |
});
|
|
|
252 |
}
|
|
|
253 |
|
| 22292 |
ashik.ali |
254 |
function getSaleHistoryNextItems(start, end, invoiceNumber, searchType, startTime, endTime){
|
|
|
255 |
console.log(start);
|
|
|
256 |
console.log(end);
|
|
|
257 |
console.log(+end + +10);
|
|
|
258 |
console.log(+start + +10);
|
|
|
259 |
jQuery.ajax({
|
|
|
260 |
type : "GET",
|
|
|
261 |
url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
|
|
|
262 |
+"&startTime="+startTime
|
|
|
263 |
+"&endTime="+endTime+"&offset="+end,
|
|
|
264 |
beforeSend: function(){
|
|
|
265 |
//$('#ajax-spinner').show();
|
|
|
266 |
},
|
|
|
267 |
complete: function(){
|
|
|
268 |
//$('#ajax-spinner').hide();
|
|
|
269 |
},
|
|
|
270 |
success : function(response) {
|
|
|
271 |
$( "#sale-history-paginated .end" ).text(+end + +10);
|
|
|
272 |
$( "#sale-history-paginated .start" ).text(+start + +10);
|
|
|
273 |
var last = $( "#sale-history-paginated .end" ).text();
|
|
|
274 |
var temp = $( "#sale-history-paginated .size" ).text();
|
|
|
275 |
if (parseInt(last) >= parseInt(temp)){
|
|
|
276 |
$("#sale-history-paginated .next").prop('disabled', true);
|
|
|
277 |
//$( "#good-inventory-paginated .end" ).text(temp);
|
|
|
278 |
}
|
|
|
279 |
$('#sale-history-table').html(response);
|
|
|
280 |
$("#sale-history-paginated .previous").prop('disabled', false);
|
|
|
281 |
},
|
|
|
282 |
error : function() {
|
|
|
283 |
alert("Unable to fetch items");
|
|
|
284 |
},
|
|
|
285 |
});
|
|
|
286 |
}
|
|
|
287 |
function getSaleHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
|
|
|
288 |
jQuery.ajax({
|
|
|
289 |
type : "GET",
|
|
|
290 |
url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
|
|
|
291 |
+"&startTime="+startTime
|
|
|
292 |
+"&endTime="+endTime+"&offset="+pre,
|
|
|
293 |
beforeSend: function(){
|
|
|
294 |
//$('#ajax-spinner').show();
|
|
|
295 |
},
|
|
|
296 |
complete: function(){
|
|
|
297 |
//$('#ajax-spinner').hide();
|
|
|
298 |
},
|
|
|
299 |
success : function(response) {
|
|
|
300 |
$( "#sale-history-paginated .end" ).text(+end - +10);
|
|
|
301 |
$( "#sale-history-paginated .start" ).text(+start - +10);
|
|
|
302 |
$('#sale-history-table').html(response);
|
|
|
303 |
$("#sale-history-paginated .next").prop('disabled', false);
|
|
|
304 |
if (parseInt(pre)==0)
|
|
|
305 |
{
|
|
|
306 |
$("#sale-history-paginated .previous").prop('disabled', true);
|
|
|
307 |
}
|
|
|
308 |
},
|
|
|
309 |
error : function() {
|
|
|
310 |
alert("Unable to fetch items");
|
|
|
311 |
},
|
|
|
312 |
});
|
|
|
313 |
}
|
|
|
314 |
|
| 21987 |
kshitij.so |
315 |
function loadGoodInventorySearchInfo(search_text){
|
|
|
316 |
loadGoodInventory("main-content",search_text);
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
|
|
|
320 |
loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
|
|
|
321 |
}
|
|
|
322 |
|
| 21627 |
kshitij.so |
323 |
function findDuplicateSerialNumbers(value){
|
|
|
324 |
var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
|
|
|
325 |
return result;
|
|
|
326 |
}
|
| 21987 |
kshitij.so |
327 |
|
|
|
328 |
function loadGrnDetails(purchaseId,domId){
|
|
|
329 |
jQuery.ajax({
|
|
|
330 |
type : "GET",
|
| 22090 |
amit.gupta |
331 |
url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
|
| 21987 |
kshitij.so |
332 |
success : function(response) {
|
|
|
333 |
$('#' + domId).html(response);
|
|
|
334 |
window.dispatchEvent(new Event('resize'));
|
|
|
335 |
}
|
|
|
336 |
});
|
|
|
337 |
}
|
|
|
338 |
|
| 22245 |
ashik.ali |
339 |
function loadSaleDetails(orderId, domId){
|
|
|
340 |
jQuery.ajax({
|
|
|
341 |
type : "GET",
|
|
|
342 |
url : context+"/saleDetails?orderId="+orderId,
|
|
|
343 |
success : function(response) {
|
|
|
344 |
$('#' + domId).html(response);
|
|
|
345 |
window.dispatchEvent(new Event('resize'));
|
|
|
346 |
}
|
|
|
347 |
});
|
|
|
348 |
}
|
|
|
349 |
|
| 21987 |
kshitij.so |
350 |
function loadPendingGrnDetails(purchaseId,domId){
|
|
|
351 |
jQuery.ajax({
|
| 22090 |
amit.gupta |
352 |
url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
|
| 21987 |
kshitij.so |
353 |
type: 'POST',
|
|
|
354 |
async: false,
|
|
|
355 |
success: function (data) {
|
|
|
356 |
$('#'+domId).html(data);
|
|
|
357 |
},
|
|
|
358 |
error : function() {
|
|
|
359 |
alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
|
|
|
360 |
},
|
|
|
361 |
cache: false,
|
|
|
362 |
contentType: false,
|
|
|
363 |
processData: false
|
|
|
364 |
});
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
function getNextCatalogItems(start, end, searchText){
|
|
|
368 |
console.log(start);
|
|
|
369 |
console.log(end);
|
|
|
370 |
console.log(+end + +10);
|
|
|
371 |
console.log(+start + +10);
|
|
|
372 |
jQuery.ajax({
|
|
|
373 |
type : "GET",
|
| 22090 |
amit.gupta |
374 |
url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
|
| 21987 |
kshitij.so |
375 |
beforeSend: function(){
|
|
|
376 |
//$('#ajax-spinner').show();
|
|
|
377 |
},
|
|
|
378 |
complete: function(){
|
|
|
379 |
//$('#ajax-spinner').hide();
|
|
|
380 |
},
|
|
|
381 |
success : function(response) {
|
|
|
382 |
$( "#catalog-paginated .end" ).text(+end + +10);
|
|
|
383 |
$( "#catalog-paginated .start" ).text(+start + +10);
|
|
|
384 |
var last = $( "#catalog-paginated .end" ).text();
|
|
|
385 |
var temp = $( "#catalog-paginated .size" ).text();
|
|
|
386 |
if (parseInt(last) >= parseInt(temp)){
|
|
|
387 |
$("#catalog-paginated .next").prop('disabled', true);
|
|
|
388 |
}
|
|
|
389 |
$('#catalog-table').html(response);
|
|
|
390 |
$("#catalog-paginated .previous").prop('disabled', false);
|
|
|
391 |
},
|
|
|
392 |
error : function() {
|
|
|
393 |
alert("Unable to fetch items");
|
|
|
394 |
},
|
|
|
395 |
});
|
|
|
396 |
}
|
|
|
397 |
function getPreviousCatalogItems(start,end,pre,searchText){
|
|
|
398 |
jQuery.ajax({
|
|
|
399 |
type : "GET",
|
| 22090 |
amit.gupta |
400 |
url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
|
| 21987 |
kshitij.so |
401 |
beforeSend: function(){
|
|
|
402 |
//$('#ajax-spinner').show();
|
|
|
403 |
},
|
|
|
404 |
complete: function(){
|
|
|
405 |
//$('#ajax-spinner').hide();
|
|
|
406 |
},
|
|
|
407 |
success : function(response) {
|
|
|
408 |
$( "#catalog-paginated .end" ).text(+end - +10);
|
|
|
409 |
$( "#catalog-paginated .start" ).text(+start - +10);
|
|
|
410 |
$('#catalog-table').html(response);
|
|
|
411 |
$("#catalog-paginated .next").prop('disabled', false);
|
|
|
412 |
if (parseInt(pre)==0)
|
|
|
413 |
{
|
|
|
414 |
$("#catalog-paginated .previous").prop('disabled', true);
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
},
|
|
|
418 |
error : function() {
|
|
|
419 |
alert("Unable to fetch items");
|
|
|
420 |
},
|
|
|
421 |
});
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
function loadCatalogSearchInfo(search_text){
|
|
|
425 |
loadCatalog("main-content",search_text);
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
function addItemInLocalStorage(bagObj){
|
|
|
429 |
if (localStorage.getItem("bag")!=null){
|
|
|
430 |
var bag = JSON.parse(localStorage.getItem("bag"));
|
|
|
431 |
bag[bagObj.itemId] = bagObj
|
|
|
432 |
localStorage.setItem("bag",JSON.stringify(bag));
|
|
|
433 |
bag = localStorage.getItem("bag")
|
|
|
434 |
$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
|
|
|
435 |
}
|
|
|
436 |
else{
|
|
|
437 |
var tempObj = {};
|
|
|
438 |
tempObj[bagObj.itemId] = bagObj
|
|
|
439 |
localStorage.setItem("bag",JSON.stringify(tempObj));
|
|
|
440 |
var bag = localStorage.getItem("bag")
|
|
|
441 |
$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
|
|
|
442 |
}
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
function changeQuantityInLocalStorage(itemId, newQuantity){
|
|
|
447 |
var bag = JSON.parse(localStorage.getItem("bag"));
|
|
|
448 |
bag[itemId].quantity = newQuantity;
|
|
|
449 |
localStorage.setItem("bag",JSON.stringify(bag));
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
function removeItemFromLocalStorage(itemId){
|
|
|
453 |
if (localStorage.getItem("bag")!=null){
|
|
|
454 |
var bag = JSON.parse(localStorage.getItem("bag"));
|
|
|
455 |
delete bag[itemId];
|
|
|
456 |
localStorage.setItem("bag",JSON.stringify(bag));
|
|
|
457 |
$("#cart_bar").find('span').text(Object.keys(bag).length);
|
|
|
458 |
}
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
function emptyBag(){
|
| 22095 |
kshitij.so |
462 |
localStorage.setItem("bag",JSON.stringify({}));
|
| 21987 |
kshitij.so |
463 |
$("#cart_bar").find('span').text(0);
|
|
|
464 |
}
|
|
|
465 |
|
|
|
466 |
function loadCart(domId){
|
|
|
467 |
jQuery.ajax({
|
|
|
468 |
type : "POST",
|
|
|
469 |
data: {"cartData":localStorage.getItem("bag")},
|
| 22090 |
amit.gupta |
470 |
url : context+"/cart",
|
| 21987 |
kshitij.so |
471 |
success : function(response) {
|
|
|
472 |
$('#' + domId).html(response);
|
|
|
473 |
}
|
|
|
474 |
});
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
function checkout(domId){
|
|
|
478 |
jQuery.ajax({
|
| 22095 |
kshitij.so |
479 |
type : "GET",
|
| 21987 |
kshitij.so |
480 |
data: {"cartData":localStorage.getItem("bag")},
|
| 22090 |
amit.gupta |
481 |
url : context+"/validate-cart",
|
| 21987 |
kshitij.so |
482 |
success : function(response) {
|
|
|
483 |
var obj = JSON.parse(response);
|
|
|
484 |
redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
|
| 22095 |
kshitij.so |
485 |
$('#main-content').html(response);
|
| 21987 |
kshitij.so |
486 |
}
|
| 22245 |
ashik.ali |
487 |
});
|
| 21987 |
kshitij.so |
488 |
}
|
|
|
489 |
|
|
|
490 |
function redirectCart(url, cartData, method, domId){
|
|
|
491 |
jQuery.ajax({
|
|
|
492 |
type : method,
|
|
|
493 |
data: {"cartData":cartData},
|
|
|
494 |
url : context+url,
|
|
|
495 |
success : function(response) {
|
|
|
496 |
$('#' + domId).html(response);
|
|
|
497 |
window.dispatchEvent(new Event('resize'));
|
|
|
498 |
}
|
|
|
499 |
});
|
|
|
500 |
}
|
|
|
501 |
|
| 22245 |
ashik.ali |
502 |
function saleHistory(domId, invoiceNumber, searchType, startTime, endTime){
|
|
|
503 |
jQuery.ajax({
|
|
|
504 |
type : "GET",
|
|
|
505 |
url : context+"/saleHistory?invoiceNumber="+invoiceNumber+"&searchType="+searchType
|
|
|
506 |
+"&startTime="+startTime
|
|
|
507 |
+"&endTime="+endTime,
|
|
|
508 |
success : function(response) {
|
|
|
509 |
$('#' + domId).html(response);
|
|
|
510 |
}
|
|
|
511 |
});
|
|
|
512 |
}
|
|
|
513 |
|
| 22354 |
ashik.ali |
514 |
|
|
|
515 |
function contactUs(domId){
|
|
|
516 |
jQuery.ajax({
|
|
|
517 |
type : "GET",
|
|
|
518 |
url : context+"/contactUs",
|
|
|
519 |
success : function(response) {
|
|
|
520 |
$('#' + domId).html(response);
|
|
|
521 |
}
|
|
|
522 |
});
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
|
|
|
526 |
jQuery.ajax({
|
|
|
527 |
type : "GET",
|
|
|
528 |
url : context+"/customer/mobileNumber?mobileNumber="+mobileNumber,
|
|
|
529 |
success : function(response) {
|
|
|
530 |
console.log("response"+response);
|
|
|
531 |
var customer = response.response;
|
|
|
532 |
$('#firstName').attr('value', customer.firstName);
|
|
|
533 |
$('#lastName').attr('value', customer.lastName);
|
|
|
534 |
$('#email').attr('value', customer.emailId);
|
|
|
535 |
$('#phone').attr('value', customer.mobileNumber);
|
|
|
536 |
$('#alternatePhone').attr('value', customer.address.phoneNumber);
|
|
|
537 |
$('#line1').attr('value', customer.address.line1);
|
|
|
538 |
$('#line2').attr('value', customer.address.line2);
|
|
|
539 |
$('#landmark').attr('value', customer.address.landmark);
|
|
|
540 |
$('#pinCode').attr('value', customer.address.pinCode);
|
|
|
541 |
$('#city').attr('value', customer.address.city);
|
|
|
542 |
$('#state').attr('value', customer.address.state);
|
|
|
543 |
}
|
|
|
544 |
});
|
|
|
545 |
}
|
|
|
546 |
|
| 22283 |
ashik.ali |
547 |
function saleHistorySearchInfo(search_text, searchType, startTime, endTime){
|
|
|
548 |
saleHistory("main-content", search_text, searchType, startTime, endTime);
|
|
|
549 |
}
|
| 22245 |
ashik.ali |
550 |
|
| 22283 |
ashik.ali |
551 |
|
| 21987 |
kshitij.so |
552 |
function validateOrderDetails(){
|
|
|
553 |
var sNumbers = [];
|
|
|
554 |
var error = false;
|
|
|
555 |
$("form#cd input.serialNumber").each(function(){
|
|
|
556 |
var input = $(this).val().trim();
|
| 22245 |
ashik.ali |
557 |
var itemType = $(this).attr("itemType");
|
| 21987 |
kshitij.so |
558 |
$(this).removeClass("border-highlight");
|
| 22245 |
ashik.ali |
559 |
if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
|
| 21987 |
kshitij.so |
560 |
error = true;
|
|
|
561 |
$(this).addClass("border-highlight");
|
|
|
562 |
}
|
|
|
563 |
sNumbers.push(input);
|
|
|
564 |
});
|
|
|
565 |
|
|
|
566 |
$("form#cd input.unitPrice").each(function(){
|
|
|
567 |
var input = $(this).val().trim();
|
|
|
568 |
$(this).removeClass("border-highlight");
|
|
|
569 |
if (!input || parseInt(input)<=0 || isNaN(input)){
|
|
|
570 |
error=true;
|
|
|
571 |
$(this).addClass("border-highlight");
|
|
|
572 |
}
|
|
|
573 |
});
|
|
|
574 |
|
|
|
575 |
var amount = 0;
|
|
|
576 |
var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
$("form#cd input.amount").each(function(){
|
| 22354 |
ashik.ali |
580 |
if ($(this).val() == ""){
|
| 21987 |
kshitij.so |
581 |
$(this).val(0);
|
|
|
582 |
}
|
|
|
583 |
var tmpAmount = parseFloat($(this).val());
|
|
|
584 |
amount = amount + tmpAmount;
|
|
|
585 |
});
|
|
|
586 |
|
|
|
587 |
console.log(amount);
|
|
|
588 |
console.log(netPayableAmount);
|
|
|
589 |
|
| 22354 |
ashik.ali |
590 |
if (amount != netPayableAmount){
|
|
|
591 |
if(amount < netPayableAmount){
|
|
|
592 |
alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
|
|
|
593 |
}else{
|
|
|
594 |
alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
|
|
|
595 |
}
|
|
|
596 |
$("form#cd input.netPayableAmount").each(function(){
|
|
|
597 |
$(this).addClass("border-highlight");
|
|
|
598 |
});
|
| 21987 |
kshitij.so |
599 |
error = true;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
if (error){
|
|
|
603 |
return false;
|
|
|
604 |
}
|
|
|
605 |
return true;
|
|
|
606 |
|
|
|
607 |
}
|
|
|
608 |
|
|
|
609 |
function orderDetailsPayload(){
|
|
|
610 |
var orderObj = {};
|
|
|
611 |
var priceQtyArray = [];
|
|
|
612 |
var customerObj = {};
|
|
|
613 |
var paymentOption = [];
|
|
|
614 |
|
|
|
615 |
$("form#cd input.serialNumber").each(function(){
|
|
|
616 |
var itemId = parseInt($(this).attr("itemId"));
|
|
|
617 |
if (orderObj.hasOwnProperty('fofoLineItems')){
|
|
|
618 |
var itemDetails = orderObj['fofoLineItems'];
|
|
|
619 |
if (itemDetails.hasOwnProperty(itemId)){
|
|
|
620 |
var serialNumbers = itemDetails[itemId];
|
|
|
621 |
serialNumbers.push($(this).val());
|
|
|
622 |
itemDetails[itemId] = serialNumbers;
|
| 22245 |
ashik.ali |
623 |
}else{
|
| 21987 |
kshitij.so |
624 |
var serialNumbers = [];
|
|
|
625 |
serialNumbers.push($(this).val());
|
|
|
626 |
itemDetails[itemId] = serialNumbers;
|
|
|
627 |
}
|
| 22245 |
ashik.ali |
628 |
}else{
|
| 21987 |
kshitij.so |
629 |
var serialNumbers = [];
|
|
|
630 |
serialNumbers.push($(this).val());
|
|
|
631 |
var tmp ={};
|
|
|
632 |
tmp[itemId] = serialNumbers;
|
|
|
633 |
orderObj['fofoLineItems'] = tmp;
|
|
|
634 |
}
|
|
|
635 |
});
|
|
|
636 |
console.log( JSON.stringify(orderObj));
|
|
|
637 |
$("form#cd input.unitPrice").each(function(){
|
|
|
638 |
var itemId = parseInt($(this).attr("itemId"));
|
|
|
639 |
var unitPrice = parseFloat($(this).val());
|
|
|
640 |
var qty = parseInt($(this).attr("quantity"));
|
|
|
641 |
var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
|
| 22245 |
ashik.ali |
642 |
if (orderObj['fofoLineItems'][itemId] === undefined){
|
|
|
643 |
tmpObj['serialNumberDetails'] =[];
|
| 21987 |
kshitij.so |
644 |
}
|
|
|
645 |
else{
|
| 22245 |
ashik.ali |
646 |
//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
|
|
|
647 |
tmpObj['serialNumberDetails'] = [];
|
| 21987 |
kshitij.so |
648 |
}
|
| 22245 |
ashik.ali |
649 |
var found = false;
|
|
|
650 |
for(var i = 0; i < priceQtyArray.length; i++){
|
|
|
651 |
if (priceQtyArray[i]["itemId"] == itemId){
|
|
|
652 |
found = true;
|
|
|
653 |
break;
|
|
|
654 |
}
|
|
|
655 |
}
|
|
|
656 |
if(!found){
|
|
|
657 |
priceQtyArray.push(tmpObj);
|
|
|
658 |
}
|
| 21987 |
kshitij.so |
659 |
});
|
|
|
660 |
|
| 22245 |
ashik.ali |
661 |
|
| 22254 |
ashik.ali |
662 |
var insurance = false;
|
|
|
663 |
|
| 22245 |
ashik.ali |
664 |
$("#order-details").find("tr:not(:first-child)").each(function(index,el){
|
|
|
665 |
//console.log(el);
|
|
|
666 |
//console.log(index);
|
|
|
667 |
var $serialNumberElement = $(el).find('.serialNumber');
|
|
|
668 |
var itemId = parseInt($serialNumberElement.attr("itemId"));
|
|
|
669 |
var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
|
|
|
670 |
//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
|
|
|
671 |
|
|
|
672 |
//}
|
|
|
673 |
//console.log($serialNumberElement.val());
|
|
|
674 |
//console.log(itemId);
|
|
|
675 |
for(var i = 0; i < priceQtyArray.length; i++){
|
|
|
676 |
console.log(priceQtyArray[i]["itemId"]);
|
|
|
677 |
if (priceQtyArray[i]["itemId"] == itemId){
|
|
|
678 |
if(insuranceAmount > 0){
|
|
|
679 |
insurance = true;
|
|
|
680 |
}
|
|
|
681 |
var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
|
|
|
682 |
priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
|
|
|
683 |
}
|
|
|
684 |
}
|
|
|
685 |
|
|
|
686 |
});
|
|
|
687 |
|
|
|
688 |
console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
|
| 21987 |
kshitij.so |
689 |
//customer-details
|
|
|
690 |
/*$("#customer-details input").each(function(){
|
|
|
691 |
console.log($(this).attr('name'));
|
|
|
692 |
customerObj[$(this).attr('name')] = $(this).val();
|
|
|
693 |
});*/
|
|
|
694 |
//$("input[name=nameGoesHere]").val();
|
| 22245 |
ashik.ali |
695 |
customerObj['firstName'] = $("form#cd input[name=firstName]").val();
|
|
|
696 |
customerObj['lastName'] = $("form#cd input[name=lastName]").val();
|
| 21987 |
kshitij.so |
697 |
customerObj['mobileNumber'] = $("form#cd input[name=phone]").val();
|
|
|
698 |
customerObj['emailId'] = $("form#cd input[name=email]").val();
|
| 22245 |
ashik.ali |
699 |
customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth").val();
|
| 21987 |
kshitij.so |
700 |
var customerAddress = {};
|
| 22245 |
ashik.ali |
701 |
customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
|
| 21987 |
kshitij.so |
702 |
customerAddress['line1'] = $("form#cd input[name=line1]").val();
|
|
|
703 |
customerAddress['line2'] = $("form#cd input[name=line2]").val();
|
|
|
704 |
customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
|
|
|
705 |
customerAddress['city'] = $("form#cd input[name=city]").val();
|
|
|
706 |
customerAddress['state'] = $('select[name=state] option:selected').val();
|
| 22245 |
ashik.ali |
707 |
customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
|
| 21987 |
kshitij.so |
708 |
customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
|
|
|
709 |
customerAddress['country'] = "India";
|
|
|
710 |
customerObj['address'] = customerAddress;
|
|
|
711 |
console.log( JSON.stringify(customerObj));
|
|
|
712 |
$("#payment-details input").each(function(){
|
|
|
713 |
console.log($(this).attr('name'));
|
|
|
714 |
if ($(this).attr('name') =="" ){
|
|
|
715 |
return;
|
|
|
716 |
}
|
|
|
717 |
var paymentObj = {};
|
|
|
718 |
paymentObj['type'] = $(this).attr('name');
|
|
|
719 |
if ($(this).val() == ""){
|
|
|
720 |
paymentObj['amount'] = 0.0;
|
|
|
721 |
}
|
|
|
722 |
else{
|
|
|
723 |
paymentObj['amount'] = parseFloat($(this).val());
|
|
|
724 |
}
|
|
|
725 |
paymentOption.push(paymentObj);
|
|
|
726 |
});
|
|
|
727 |
console.log( JSON.stringify(paymentOption));
|
|
|
728 |
|
|
|
729 |
var retObj = {};
|
| 22254 |
ashik.ali |
730 |
var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
|
|
|
731 |
if(insurance){
|
|
|
732 |
retObj['customerDateOfBirth'] = (dateOfBirth)
|
|
|
733 |
}
|
| 21987 |
kshitij.so |
734 |
retObj['fofoLineItems'] = (priceQtyArray);
|
|
|
735 |
retObj['customer'] = (customerObj);
|
|
|
736 |
retObj['paymentOptions'] = (paymentOption);
|
| 22254 |
ashik.ali |
737 |
|
| 21987 |
kshitij.so |
738 |
console.log(retObj);
|
|
|
739 |
return JSON.stringify(retObj);
|
|
|
740 |
}
|