Subversion Repositories SmartDukaan

Rev

Rev 31878 | Rev 31882 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27711 amit.gupta 1
const MAIN_CONTAINER = "#main-content";
24440 amit.gupta 2
var logosmapping = {
27618 tejbeer 3
	mobile_insurance_providers: {
4
		"0": context + '/resources/images/icons/provider-logos/iffco.png',
5
		"1": context + '/resources/images/icons/provider-logos/icici.jpg',
6
		"2": context + '/resources/images/icons/provider-logos/tataaig.png',
30725 amit.gupta 7
		"3": context + '/resources/images/icons/provider-logos/bharti.jpg',
30839 amit.gupta 8
		"4": context + '/resources/images/icons/provider-logos/bharti.jpg',
9
		"5": context + '/resources/images/icons/provider-logos/oneassist.jpeg'
24595 tejbeer 10
	}
24440 amit.gupta 11
}
30414 amit.gupta 12
 
24595 tejbeer 13
function badRequestAlert(response) {
22956 ashik.ali 14
	console.log(response.responseText);
15
	var errorObject = JSON.parse(response.responseText);
16
	errorObject = errorObject.response;
24595 tejbeer 17
	bootbox.alert('Bad Request\n' + 'rejectedType : '
27618 tejbeer 18
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
19
		+ errorObject.rejectedValue + '\n' + 'message : '
20
		+ errorObject.message);
22956 ashik.ali 21
}
24595 tejbeer 22
 
23
function internalServerErrorAlert(response) {
22956 ashik.ali 24
	console.log(response.responseText);
25
	var errorObject = JSON.parse(response.responseText);
26
	errorObject = errorObject.response;
24595 tejbeer 27
	bootbox.alert('Internal Server Error\n' + 'rejectedType : '
27618 tejbeer 28
		+ errorObject.rejectedType + '\n' + 'rejectedValue : '
29
		+ errorObject.rejectedValue + '\n' + 'message : '
30
		+ errorObject.message);
22956 ashik.ali 31
}
32
 
31762 tejbeer 33
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
27355 tejbeer 34
	if (typeof loaderDialogObj != "undefined") {
35
		loaderDialogObj.modal('hide');
36
		// $('div.modal-backdrop.fade').remove();
37
	}
24595 tejbeer 38
	if (jqxhr.status == 400) {
23872 amit.gupta 39
		// $('#error-prompt-model').modal();
24595 tejbeer 40
		badRequestAlert(jqxhr);
41
	} else {
22956 ashik.ali 42
		internalServerErrorAlert(jqxhr);
43
	}
44
});
45
 
31762 tejbeer 46
$(document).ajaxComplete(function() {
26140 amit.gupta 47
	if (typeof loaderDialogObj != "undefined") {
24271 amit.gupta 48
		loaderDialogObj.modal('hide');
27355 tejbeer 49
		// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 50
	}
23946 amit.gupta 51
});
30017 amit.gupta 52
 
24992 tejbeer 53
function ajaxStartHandler() {
24976 amit.gupta 54
	if (typeof loaderDialogObj != "undefined")
55
		loaderDialogObj.modal('show');
56
}
30017 amit.gupta 57
 
24976 amit.gupta 58
$(document).ajaxStart(ajaxStartHandler);
24595 tejbeer 59
 
60
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
31762 tejbeer 61
	callback_function) {
24595 tejbeer 62
	$.ajax({
27618 tejbeer 63
		url: urlString,
64
		async: true,
65
		cache: false,
66
		data: params,
24595 tejbeer 67
		// dataType:'json',
27618 tejbeer 68
		type: httpType,
31762 tejbeer 69
		success: function(response) {
24595 tejbeer 70
			callback_function(response);
31762 tejbeer 71
			$('.currency').each(function(index, ele) {
24595 tejbeer 72
				if (!isNaN(parseInt($(ele).html()))) {
73
					$(ele).html(numberToComma($(ele).html()));
74
				}
23918 amit.gupta 75
			});
76
		}
77
	});
23193 ashik.ali 78
}
79
 
24595 tejbeer 80
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
23500 ashik.ali 81
	doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
82
}
83
 
24595 tejbeer 84
function doPostAjaxRequestWithParamsHandler(urlString, params,
31762 tejbeer 85
	callback_function) {
23500 ashik.ali 86
	doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
87
}
88
 
24595 tejbeer 89
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
31762 tejbeer 90
	callback_function) {
23032 ashik.ali 91
	$.ajax({
27618 tejbeer 92
		url: urlString,
93
		async: true,
94
		cache: false,
95
		processData: false,
96
		data: json,
97
		contentType: 'application/json',
98
		type: httpType,
31762 tejbeer 99
		success: function(response) {
24595 tejbeer 100
			// console.log("response"+JSON.stringify(data));
101
			callback_function(response);
31762 tejbeer 102
			$('.currency').each(function(index, ele) {
24595 tejbeer 103
				if (!isNaN(parseInt($(ele).html()))) {
104
					$(ele).html(numberToComma($(ele).html()));
105
				}
106
			});
107
		}
23032 ashik.ali 108
	});
109
}
110
 
24595 tejbeer 111
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 112
	doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
113
}
23032 ashik.ali 114
 
24595 tejbeer 115
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function) {
23500 ashik.ali 116
	doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
117
}
118
 
24595 tejbeer 119
function doAjaxRequestHandler(urlString, httpType, callback_function) {
22982 ashik.ali 120
	$.ajax({
27618 tejbeer 121
		url: urlString,
122
		async: true,
123
		cache: false,
124
		type: httpType,
31762 tejbeer 125
		success: function(response) {
24595 tejbeer 126
			callback_function(response);
31762 tejbeer 127
			$('.currency').each(function(index, ele) {
24595 tejbeer 128
				if (!isNaN(parseInt($(ele).html()))) {
129
					$(ele).html(numberToComma($(ele).html()));
130
				}
131
			});
132
		}
22982 ashik.ali 133
	});
134
}
135
 
24595 tejbeer 136
function doGetAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 137
	doAjaxRequestHandler(urlString, "GET", callback_function);
138
}
139
 
24595 tejbeer 140
function doPutAjaxRequestHandler(urlString, callback_function) {
23500 ashik.ali 141
	doAjaxRequestHandler(urlString, "PUT", callback_function);
142
}
143
 
24595 tejbeer 144
function doPostAjaxRequestHandler(urlString, callback_function) {
23629 ashik.ali 145
	doAjaxRequestHandler(urlString, "POST", callback_function);
146
}
147
 
24595 tejbeer 148
function doDeleteAjaxRequestHandler(urlString, callback_function) {
23783 ashik.ali 149
	doAjaxRequestHandler(urlString, "DELETE", callback_function);
150
}
151
 
24595 tejbeer 152
function doAjaxUploadRequest(urlString, httpType, file) {
23347 ashik.ali 153
	var response;
24595 tejbeer 154
	doAjaxUploadRequestHandler(urlString, httpType, file,
31762 tejbeer 155
		function(ajaxResponse) {
27618 tejbeer 156
			response = ajaxResponse;
157
		});
23347 ashik.ali 158
	return response;
159
}
160
 
24595 tejbeer 161
function doAjaxUploadRequestHandler(urlString, httpType, file,
31762 tejbeer 162
	callback_function) {
22982 ashik.ali 163
	var formData = new FormData();
164
	formData.append("file", file);
165
	$.ajax({
27618 tejbeer 166
		url: urlString,
167
		type: httpType,
168
		data: formData,
169
		dataType: 'json',
170
		async: true,
171
		cache: false,
172
		contentType: false,
173
		enctype: 'multipart/form-data',
174
		processData: false,
31762 tejbeer 175
		success: function(response) {
24595 tejbeer 176
			// console.log("response"+JSON.stringify(data));
177
			callback_function(response);
178
		}
22982 ashik.ali 179
	});
180
}
30017 amit.gupta 181
 
24595 tejbeer 182
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
31762 tejbeer 183
	callback_function) {
24171 govind 184
	var formData = new FormData();
185
	formData.append("file", file);
27618 tejbeer 186
	formData.append('json', new Blob([json]));
24171 govind 187
	$.ajax({
27618 tejbeer 188
		url: urlString,
189
		type: httpType,
190
		data: formData,
191
		enctype: 'multipart/form-data',
192
		contentType: false,
193
		processData: false,
31762 tejbeer 194
		success: function(response) {
24595 tejbeer 195
			// console.log("response"+JSON.stringify(data));
196
			callback_function(response);
197
		}
24171 govind 198
	});
199
}
22982 ashik.ali 200
 
24595 tejbeer 201
function uploadDocument(file) {
26389 amit.gupta 202
	var url = context + '/document-upload';
31762 tejbeer 203
	doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
24595 tejbeer 204
		var documentId = response.response.document_id;
205
		console.log("documentId : " + documentId);
23377 ashik.ali 206
		return documentId;
207
	});
23347 ashik.ali 208
}
209
 
24595 tejbeer 210
function doAjaxGetDownload(urlString, fileName) {
211
	console.log("fileName : " + fileName);
23343 ashik.ali 212
	doAjaxDownload(urlString, "GET", null, fileName);
22982 ashik.ali 213
}
214
 
31702 amit.gupta 215
function doAjaxPostDownload(urlString, data, fileName, callback) {
216
	doAjaxDownload(urlString, "POST", data, fileName, callback);
21627 kshitij.so 217
}
218
 
31702 amit.gupta 219
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
22488 ashik.ali 220
	xhttp = new XMLHttpRequest();
25093 amit.gupta 221
	if (typeof loaderDialogObj != "undefined")
222
		loaderDialogObj.modal('show');
31762 tejbeer 223
	xhttp.onreadystatechange = function() {
24595 tejbeer 224
		var a;
225
		if (xhttp.readyState === 2) {
226
			if (xhttp.status == 200) {
227
				xhttp.responseType = "blob";
228
			} else {
229
				xhttp.responseType = "text";
230
			}
231
		} else if (xhttp.readyState === 4 && xhttp.status === 200) {
232
			// Trick for making downloadable link
26140 amit.gupta 233
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 234
				loaderDialogObj.modal('hide');
27355 tejbeer 235
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 236
			}
27355 tejbeer 237
 
24595 tejbeer 238
			a = document.createElement('a');
239
			a.href = window.URL.createObjectURL(xhttp.response);
240
			// Give filename you wish to download
241
			a.download = fileName;
242
			a.style.display = 'none';
243
			document.body.appendChild(a);
244
			a.click();
245
		} else if (xhttp.readyState == 4 && xhttp.status === 400) {
26140 amit.gupta 246
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 247
				loaderDialogObj.modal('hide');
27355 tejbeer 248
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 249
			}
24595 tejbeer 250
			badRequestAlert(xhttp);
251
		} else if (xhttp.readyState == 4 && xhttp.status === 500) {
26140 amit.gupta 252
			if (typeof loaderDialogObj != "undefined") {
24976 amit.gupta 253
				loaderDialogObj.modal('hide');
27355 tejbeer 254
				// $('div.modal-backdrop.fade').remove();
26140 amit.gupta 255
			}
24595 tejbeer 256
			internalServerErrorAlert(xhttp);
257
		}
22488 ashik.ali 258
	};
259
	// Post data to URL which handles post request
23343 ashik.ali 260
	xhttp.open(httpType, urlString);
24595 tejbeer 261
	if (httpType == "POST") {
23343 ashik.ali 262
		xhttp.setRequestHeader("Content-Type", "application/json");
263
	}
22488 ashik.ali 264
	// You should set responseType as blob for binary responses
23872 amit.gupta 265
	// xhttp.responseType = 'blob';
22488 ashik.ali 266
	xhttp.send(data);
23405 amit.gupta 267
}
30017 amit.gupta 268
 
27618 tejbeer 269
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
31762 tejbeer 270
	tableIdentifier, detailsContainerIdentifier) {
27618 tejbeer 271
	var start = $("#" + paginatedIdentifier + " .start").text();
23405 amit.gupta 272
 
27618 tejbeer 273
	var end = $("#" + paginatedIdentifier + " .end").text();
274
 
275
	url = context + url + "?offset=" + end;
276
 
277
	if (params != null) {
278
		for (var key in params) {
279
			if (params.hasOwnProperty(key)) {
280
				//console.log(key + " -> " + params[key]);
281
				url = url + "&" + key + "=" + params[key];
282
			}
283
		}
284
	}
285
 
31762 tejbeer 286
	doGetAjaxRequestHandler(url, function(response) {
27618 tejbeer 287
		var size = $("#" + paginatedIdentifier + " .size").text();
288
		if ((parseInt(end) + 20) > parseInt(size)) {
289
			// console.log("(end + 10) > size == true");
290
			$("#" + paginatedIdentifier + " .end").text(size);
291
		} else {
292
			// console.log("(end + 10) > size == false");
293
			$("#" + paginatedIdentifier + " .end").text(+end + +20);
294
		}
295
		$("#" + paginatedIdentifier + " .start").text(+start + +20);
296
		var last = $("#" + paginatedIdentifier + " .end").text();
297
		var temp = $("#" + paginatedIdentifier + " .size").text();
298
		console.log("last" + last);
299
		if (parseInt(last) >= parseInt(temp)) {
300
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
301
			// $( "#good-inventory-paginated .end" ).text(temp);
302
		}
303
		$('#' + tableIdentifier).html(response);
304
		if (detailsContainerIdentifier != null) {
305
			$('#' + detailsContainerIdentifier).html('');
306
		}
307
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
308
	});
309
 
310
}
30017 amit.gupta 311
 
27618 tejbeer 312
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
31762 tejbeer 313
	tableIdentifier, detailsContainerIdentifier) {
27618 tejbeer 314
	var start = $("#" + paginatedIdentifier + " .start").text();
315
	console.log("start" + start);
316
	var end = $("#" + paginatedIdentifier + " .end").text();
317
	console.log("Startend" + end);
318
	var size = $("#" + paginatedIdentifier + " .size").text();
319
	console.log("size" + size);
320
	if (parseInt(end) == parseInt(size) && parseInt(end) % 20 != 0) {
321
		var mod = parseInt(end) % 20;
322
		end = parseInt(end) + (20 - mod);
323
	}
324
	var pre = end - 20;
325
	var lat = pre - 20;
326
	//console.log("preCatalog" +pre);
327
 
328
	url = context + url + "?offset=" + pre;
329
 
330
	if (params != null) {
331
		for (var key in params) {
332
			if (params.hasOwnProperty(key)) {
333
				url = url + "&" + key + "=" + params[key];
334
			}
335
		}
336
	}
337
 
31762 tejbeer 338
	doGetAjaxRequestHandler(url, function(response) {
27618 tejbeer 339
		$("#" + paginatedIdentifier + " .end").text(+end - +20);
340
		$("#" + paginatedIdentifier + " .start").text(+start - +20);
341
		$('#' + tableIdentifier).html(response);
342
		if (detailsContainerIdentifier != null) {
343
			$('#' + detailsContainerIdentifier).html('');
344
		}
345
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
346
		if (parseInt(lat) == 0) {
347
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
348
		}
349
	});
350
 
351
}
352
 
24595 tejbeer 353
function loadPaginatedNextItems(url, params, paginatedIdentifier,
31762 tejbeer 354
	tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 355
	var start = $("#" + paginatedIdentifier + " .start").text();
356
	var end = $("#" + paginatedIdentifier + " .end").text();
23629 ashik.ali 357
	url = context + url + "?offset=" + end;
24595 tejbeer 358
 
359
	if (params != null) {
27618 tejbeer 360
		for (var key in params) {
23629 ashik.ali 361
			if (params.hasOwnProperty(key)) {
23872 amit.gupta 362
				// console.log(key + " -> " + p[key]);
24595 tejbeer 363
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 364
			}
365
		}
366
	}
24595 tejbeer 367
 
31762 tejbeer 368
	doGetAjaxRequestHandler(url, function(response) {
24595 tejbeer 369
		var size = $("#" + paginatedIdentifier + " .size").text();
370
		if ((parseInt(end) + 10) > parseInt(size)) {
23629 ashik.ali 371
			console.log("(end + 10) > size == true");
24595 tejbeer 372
			$("#" + paginatedIdentifier + " .end").text(size);
373
		} else {
23629 ashik.ali 374
			console.log("(end + 10) > size == false");
24595 tejbeer 375
			$("#" + paginatedIdentifier + " .end").text(+end + +10);
23629 ashik.ali 376
		}
24595 tejbeer 377
		$("#" + paginatedIdentifier + " .start").text(+start + +10);
378
		var last = $("#" + paginatedIdentifier + " .end").text();
379
		var temp = $("#" + paginatedIdentifier + " .size").text();
380
		if (parseInt(last) >= parseInt(temp)) {
381
			$("#" + paginatedIdentifier + " .next").prop('disabled', true);
23872 amit.gupta 382
			// $( "#good-inventory-paginated .end" ).text(temp);
23629 ashik.ali 383
		}
24595 tejbeer 384
		$('#' + tableIdentifier).html(response);
385
		if (detailsContainerIdentifier != null) {
386
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 387
		}
24595 tejbeer 388
		$("#" + paginatedIdentifier + " .previous").prop('disabled', false);
23629 ashik.ali 389
	});
24595 tejbeer 390
 
23629 ashik.ali 391
}
23405 amit.gupta 392
 
24595 tejbeer 393
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
31762 tejbeer 394
	tableIdentifier, detailsContainerIdentifier) {
24595 tejbeer 395
	var start = $("#" + paginatedIdentifier + " .start").text();
396
	var end = $("#" + paginatedIdentifier + " .end").text();
397
	var size = $("#" + paginatedIdentifier + " .size").text();
398
	if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
23629 ashik.ali 399
		var mod = parseInt(end) % 10;
24595 tejbeer 400
		end = parseInt(end) + (10 - mod);
23629 ashik.ali 401
	}
27618 tejbeer 402
	var pre = end - 10;
24595 tejbeer 403
 
23629 ashik.ali 404
	url = context + url + "?offset=" + pre;
24595 tejbeer 405
 
406
	if (params != null) {
27618 tejbeer 407
		for (var key in params) {
23629 ashik.ali 408
			if (params.hasOwnProperty(key)) {
24595 tejbeer 409
				url = url + "&" + key + "=" + params[key];
23629 ashik.ali 410
			}
411
		}
412
	}
24595 tejbeer 413
 
31762 tejbeer 414
	doGetAjaxRequestHandler(url, function(response) {
24595 tejbeer 415
		$("#" + paginatedIdentifier + " .end").text(+end - +10);
416
		$("#" + paginatedIdentifier + " .start").text(+start - +10);
417
		$('#' + tableIdentifier).html(response);
418
		if (detailsContainerIdentifier != null) {
419
			$('#' + detailsContainerIdentifier).html('');
23629 ashik.ali 420
		}
24595 tejbeer 421
		$("#" + paginatedIdentifier + " .next").prop('disabled', false);
422
		if (parseInt(pre) == 0) {
423
			$("#" + paginatedIdentifier + " .previous").prop('disabled', true);
23629 ashik.ali 424
		}
24595 tejbeer 425
	});
426
 
23629 ashik.ali 427
}
428
 
23405 amit.gupta 429
function numberToComma(x) {
30843 amit.gupta 430
	if (isNaN(x)) {
31356 amit.gupta 431
		x = x.replaceAll(",", '');
30843 amit.gupta 432
	}
31356 amit.gupta 433
	x = parseInt(x);
434
	x = Math.round(x * 100) / 100;
24595 tejbeer 435
	x = x.toString();
24992 tejbeer 436
	x = x.split('.');
437
	var x1 = x[0];
25649 tejbeer 438
	var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
24992 tejbeer 439
	var lastThree = x1.substring(x1.length - 3);
25066 tejbeer 440
	var otherNumbers = x1.substring(0, x1.length - 3);
25649 tejbeer 441
	if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
25144 amit.gupta 442
		console.log(lastThree)
25649 tejbeer 443
	} else {
444
		if (otherNumbers != '')
445
			lastThree = ',' + lastThree;
25066 tejbeer 446
	}
24992 tejbeer 447
	return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
27618 tejbeer 448
		+ x2;
24992 tejbeer 449
 
23786 amit.gupta 450
}
23870 amit.gupta 451
 
30599 amit.gupta 452
function getSingleDatePicker(startMoment) {
24595 tejbeer 453
	var singleDatePicker = {
27618 tejbeer 454
		"todayHighlight": true,
455
		"startDate": startMoment || moment(),
456
		"autoclose": true,
457
		"autoUpdateInput": true,
458
		"singleDatePicker": true,
459
		"locale": {
460
			'format': 'DD/MM/YYYY'
24595 tejbeer 461
		}
462
	};
23872 amit.gupta 463
	return singleDatePicker;
23886 amit.gupta 464
}
465
 
30599 amit.gupta 466
function getDatesFromPicker(pickerElement) {
467
	return {
468
		startDate: $(pickerElement).data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS),
469
		endDate: $(pickerElement).data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
470
	}
471
}
472
 
473
function getReporticoDatesFromPicker(pickerElement) {
474
	let datePickerData = $(pickerElement).data('daterangepicker');
475
	let formattedEndDate = null;
476
	if (typeof datePickerData.endDate == "object") {
477
		formattedEndDate = datePickerData.endDate.format(moment.HTML5_FMT.DATE);
478
	}
479
	return {
480
		startDate: datePickerData.startDate.format(moment.HTML5_FMT.DATE),
481
		endDate: formattedEndDate
482
	};
483
}
484
 
485
 
486
function getRangedDatePicker(showRanges, startMoment, endMoment) {
24595 tejbeer 487
	if (typeof showRanges == "undefined") {
23886 amit.gupta 488
		showRanges = false;
489
	}
24595 tejbeer 490
	var rangedDatePicker = {
27618 tejbeer 491
		"todayHighlight": true,
492
		"opens": "right",
30599 amit.gupta 493
		"startDate": startMoment || moment().startOf('day'),
494
		"endDate": endMoment || moment().endOf('day'),
27618 tejbeer 495
		"autoclose": true,
496
		"alwaysShowCalendars": false,
30075 amit.gupta 497
		"autoUpdateInput": true,
27618 tejbeer 498
		"locale": {
499
			'format': 'DD/MM/YYYY'
24595 tejbeer 500
		}
23886 amit.gupta 501
	};
24595 tejbeer 502
	if (showRanges) {
503
		rangedDatePicker['ranges'] = {
27618 tejbeer 504
			'Today': [moment(), moment()],
505
			'Yesterday': [moment().subtract(1, 'days'),
31762 tejbeer 506
			moment().subtract(1, 'days')],
27618 tejbeer 507
			'Last 7 Days': [moment().subtract(6, 'days'), moment()],
508
			'Last 30 Days': [moment().subtract(29, 'days'), moment()],
509
			'This Month': [moment().startOf('month'), moment().endOf('month')],
510
			'Last Month': [moment().subtract(1, 'month').startOf('month'),
31762 tejbeer 511
			moment()],
27618 tejbeer 512
			'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
31762 tejbeer 513
			moment()],
27618 tejbeer 514
			'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
31762 tejbeer 515
			moment()]
24595 tejbeer 516
		}
23886 amit.gupta 517
	}
518
	return rangedDatePicker;
23892 amit.gupta 519
}
30017 amit.gupta 520
 
23946 amit.gupta 521
function showPosition(position) {
24595 tejbeer 522
	if (typeof latitude == "undefined") {
523
		var coords = {
27618 tejbeer 524
			latitude: position.coords.latitude,
525
			longitude: position.coords.longitude
24595 tejbeer 526
		}
527
		doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
31762 tejbeer 528
			.stringify(coords), function() {
529
				latitude = position.coords.latitude;
530
				longitude = position.coords.longitude;
531
			});
24052 amit.gupta 532
	}
24176 amit.gupta 533
	// distance = getDistance(latitude, longitude, position.coords.latitude,
534
	// position.coords.longitude);
24168 amit.gupta 535
}
536
 
24595 tejbeer 537
function getAuthorisedWarehouses(callback) {
538
	bootBoxObj = {
27618 tejbeer 539
		size: "small",
540
		title: "Choose Warehouse",
541
		callback: callback,
542
		inputType: 'select',
543
		inputOptions: typeof inputOptions == "undefined" ? undefined
544
			: inputOptions
24168 amit.gupta 545
	}
24595 tejbeer 546
	if (typeof inputOptions == "undefined") {
31762 tejbeer 547
		doGetAjaxRequestHandler(context + "/authorisedWarehouses", function(
27618 tejbeer 548
			response) {
24168 amit.gupta 549
			response = JSON.parse(response);
550
			inputOptions = [];
31762 tejbeer 551
			response.forEach(function(warehouse) {
24168 amit.gupta 552
				inputOptions.push({
27618 tejbeer 553
					text: warehouse.name,
554
					value: warehouse.id,
24168 amit.gupta 555
				});
556
			});
557
			bootBoxObj['inputOptions'] = inputOptions;
558
			bootbox.prompt(bootBoxObj);
559
		});
24595 tejbeer 560
	} else if (inputOptions.length == 1) {
24168 amit.gupta 561
		callback(inputOptions[0].warehouse.id);
24595 tejbeer 562
	} else {
24168 amit.gupta 563
		bootbox.prompt(bootBoxObj);
564
	}
24595 tejbeer 565
 
24176 amit.gupta 566
}
30017 amit.gupta 567
 
24410 amit.gupta 568
function getColorsForItems(catalogId, itemId, description, callback) {
30017 amit.gupta 569
	colorCheckboxHandler(catalogId, itemId, description, callback);
570
}
571
 
572
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
573
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
31762 tejbeer 574
		+ catalogId + "&itemId=" + itemId, function(response) {
575
			let coloredItems = JSON.parse(response);
576
			let modalBody = [];
577
			coloredItems.forEach(function(item) {
578
				modalBody.push(`
30017 amit.gupta 579
                <div class="row">
580
                    <div class="col-sm-2">
581
                        ${item.color}
582
                    </div>
583
                    <div class="col-sm-2">
584
                            <input data-itemid="${item.id}" type="text" class="form-control" />
585
                    </div>
586
                </div>
587
            `);
31762 tejbeer 588
			});
589
			let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
30017 amit.gupta 590
                              <div class="modal-dialog" >
591
                                <div class="modal-content">
592
                                  <div class="modal-header">
593
                                    <h5 class="modal-title">${title}</h5>
594
                                  </div>
595
                                  <div class="modal-body">
596
                                        ${modalBody.join('')}
597
                                  </div>
598
                                  <div class="modal-footer">
599
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
600
                                  </div>
601
                                </div>
602
                              </div>
603
                            </div>`;
31762 tejbeer 604
			let $dialog = $(dialogBoxHtml);
605
			let modalObj = $dialog.modal('show');
606
			modalObj.on('hidden.bs.modal', function(e) {
607
				$dialog.remove();
608
			});
609
			$('button.number_dialog').on('click', function() {
610
				let itemQty = [];
611
				let anySelected = false;
612
				$(modalObj).find('.modal-body').find('input').each(function() {
613
					$input = $(this);
614
					if ($input.val() > 0) {
615
						itemQty.push({
616
							itemId: $input.data("itemid"),
617
							quantity: $input.val()
618
						});
619
						anySelected = true;
620
					}
621
				});
622
				if (anySelected && confirm("Are you sure want to notify?")) {
623
					$that = $(this);
624
					callback(itemQty, function() {
625
						$that.off('click');
626
						modalObj.hide();
30017 amit.gupta 627
					});
31762 tejbeer 628
				} else {
629
					alert("Pls mention quantity");
30017 amit.gupta 630
				}
631
			});
632
		});
633
}
634
 
635
 
30021 amit.gupta 636
function colorCheckboxHandler(catalogId, itemId, description, callback) {
30017 amit.gupta 637
	let bootBoxObj = {
27618 tejbeer 638
		size: "small",
639
		className: "item-wrapper",
640
		title: description,
641
		callback: callback,
642
		inputType: 'checkbox',
24349 amit.gupta 643
	}
24595 tejbeer 644
	doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
31762 tejbeer 645
		+ catalogId + "&itemId=" + itemId, function(response) {
646
			coloredItems = JSON.parse(response);
647
			inputOptions = [{
648
				text: "All",
649
				value: "0",
650
				onclick: "toggleAll('itemIds')"
651
			}];
652
			coloredItems.forEach(function(item) {
653
				inputOptions.push({
654
					text: item.color,
655
					value: item.id,
656
					selected: item.active
657
				});
24349 amit.gupta 658
			});
31762 tejbeer 659
			bootBoxObj['inputOptions'] = inputOptions;
660
			promptObj = bootbox.prompt(bootBoxObj);
661
			promptObj.modal('show')
662
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
663
				function(index, checkbox) {
664
					checkbox.checked = coloredItems[index].active;
665
				});
27618 tejbeer 666
		});
24406 amit.gupta 667
}
28055 tejbeer 668
 
669
function getHotdealsForItems(catalogId, itemId, description, callback) {
670
	bootBoxObj = {
671
		size: "small",
672
		className: "item-wrapper",
673
		title: description,
674
		callback: callback,
675
		inputType: 'checkbox',
676
	}
677
	doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
31762 tejbeer 678
		+ catalogId + "&itemId=" + itemId, function(response) {
679
			coloredItems = JSON.parse(response);
680
			inputOptions = [{
681
				text: "All",
682
				value: "0",
683
				onclick: "toggleAll('itemIds')"
684
			}];
685
			coloredItems.forEach(function(item) {
686
				inputOptions.push({
687
					text: item.color,
688
					value: item.id,
689
					selected: item.hotDeals
690
				});
28055 tejbeer 691
			});
31762 tejbeer 692
			bootBoxObj['inputOptions'] = inputOptions;
693
			promptObj = bootbox.prompt(bootBoxObj);
694
			promptObj.modal('show')
695
			$('.item-wrapper').find("input[type='checkbox']").slice(1).each(
696
				function(index, checkbox) {
697
					checkbox.checked = coloredItems[index].hotDeals;
698
				});
28055 tejbeer 699
		});
700
}
30017 amit.gupta 701
 
27763 tejbeer 702
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
31762 tejbeer 703
	function() {
27618 tejbeer 704
		if (this.value == "0") {
705
			$(this).closest('.item-wrapper').find("input[type='checkbox']")
706
				.slice(1).prop('checked', $(this).prop('checked'));
707
		}
708
	});
30017 amit.gupta 709
 
27618 tejbeer 710
function getItemAheadOptions(jqElement, anyColor, callback) {
711
	console.log(anyColor)
24176 amit.gupta 712
	jqElement.typeahead('destroy').typeahead({
31762 tejbeer 713
		source: function(q, process) {
24595 tejbeer 714
			if (q.length >= 3) {
27618 tejbeer 715
				return $.ajax(context + "/item?anyColor=" + anyColor, {
716
					global: false,
717
					data: {
718
						query: q
24595 tejbeer 719
					},
31762 tejbeer 720
					success: function(data) {
24191 amit.gupta 721
						queryData = JSON.parse(data);
722
						process(queryData);
24176 amit.gupta 723
					},
724
				});
24378 amit.gupta 725
			}
24176 amit.gupta 726
		},
27618 tejbeer 727
		delay: 300,
728
		items: 20,
31762 tejbeer 729
		displayText: function(item) {
24595 tejbeer 730
			return item.itemDescription;
731
		},
27618 tejbeer 732
		autoSelect: true,
733
		afterSelect: callback
24176 amit.gupta 734
	});
735
}
28795 tejbeer 736
 
737
 
738
function getImeiAheadOptions(jqElement, fofoId, callback) {
739
	jqElement.typeahead('destroy').typeahead({
31762 tejbeer 740
		source: function(q, process) {
28795 tejbeer 741
			if (q.length >= 3) {
742
				return $.ajax(context + "/imei?fofoId=" + fofoId, {
743
					global: false,
744
					data: {
745
						query: q
746
					},
31762 tejbeer 747
					success: function(data) {
28795 tejbeer 748
						queryData = JSON.parse(data);
749
						process(queryData);
750
					},
751
				});
752
			}
753
		},
754
		delay: 300,
755
		items: 20,
31762 tejbeer 756
		displayText: function(imei) {
28795 tejbeer 757
			return imei;
758
		},
759
		autoSelect: true,
760
		afterSelect: callback
31762 tejbeer 761
	}
762
 
763
	);
764
}
765
 
766
 
767
 
768
 
769
function getAllImeiAheadOptions(jqElement, callback) {
770
	jqElement.typeahead('destroy').typeahead({
771
		source: function(q, process) {
772
			if (q.length >= 3) {
773
				return $.ajax(context + "/allimei", {
774
					global: false,
775
					data: {
776
						query: q
777
					},
778
					success: function(data) {
779
						queryData = JSON.parse(data);
780
						process(queryData);
781
					},
782
				});
783
			}
784
		},
785
		delay: 300,
786
		items: 20,
787
		displayText: function(imei) {
788
			return imei;
789
		},
790
		autoSelect: true,
791
		afterSelect: callback
28795 tejbeer 792
	});
793
}
794
 
795
 
25394 amit.gupta 796
function getEntityAheadOptions(jqElement, callback) {
797
	jqElement.typeahead('destroy').typeahead({
31762 tejbeer 798
		source: function(q, process) {
25394 amit.gupta 799
			if (q.length >= 3) {
800
				return $.ajax(context + "/entity", {
27618 tejbeer 801
					global: false,
802
					data: {
803
						query: q
25394 amit.gupta 804
					},
31762 tejbeer 805
					success: function(data) {
25394 amit.gupta 806
						queryData = JSON.parse(data);
807
						process(queryData);
808
					},
809
				});
810
			}
811
		},
27618 tejbeer 812
		delay: 300,
30067 amit.gupta 813
		items: 30,
31762 tejbeer 814
		displayText: function(entity) {
25394 amit.gupta 815
			return entity.title_s + "(" + entity.catalogId_i + ")";
816
		},
27618 tejbeer 817
		autoSelect: true,
818
		afterSelect: callback
25394 amit.gupta 819
	});
820
}
30017 amit.gupta 821
 
24349 amit.gupta 822
function getPartnerAheadOptions(jqElement, callback) {
823
	jqElement.typeahead('destroy').typeahead({
31762 tejbeer 824
		source: function(q, process) {
24595 tejbeer 825
			if (q.length >= 3) {
826
				return $.ajax(context + "/partners", {
27618 tejbeer 827
					global: false,
828
					data: {
829
						query: q
24595 tejbeer 830
					},
31762 tejbeer 831
					success: function(data) {
24349 amit.gupta 832
						queryData = JSON.parse(data);
833
						process(queryData);
834
					},
835
				});
836
			}
837
		},
27618 tejbeer 838
		delay: 300,
839
		items: 20,
31762 tejbeer 840
		displayText: function(partner) {
24595 tejbeer 841
			return partner.displayName;
842
		},
27618 tejbeer 843
		autoSelect: true,
844
		afterSelect: callback
24349 amit.gupta 845
	});
846
}
24406 amit.gupta 847
 
24595 tejbeer 848
function loadPriceDrop(domId) {
849
	doGetAjaxRequestHandler(context + "/getItemDescription",
31762 tejbeer 850
		function(response) {
27618 tejbeer 851
			$('#' + domId).html(response);
852
		});
24406 amit.gupta 853
}
30017 amit.gupta 854
 
31762 tejbeer 855
$(document).on('click', ".price_drop", function() {
24406 amit.gupta 856
	loadPriceDrop("main-content");
24595 tejbeer 857
});
25649 tejbeer 858
 
27618 tejbeer 859
 
31762 tejbeer 860
$(document).on('click', ".closed_pricedrop", function() {
28569 amit.gupta 861
	loadClosedPriceDrop("main-content");
862
});
863
 
864
function loadClosedPriceDrop(domId) {
865
	doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
31762 tejbeer 866
		function(response) {
28569 amit.gupta 867
			$('#' + domId).html(response);
868
		});
869
}
870
 
27696 tejbeer 871
function notifyTypeChange(messageType, $container) {
25683 tejbeer 872
	var messageQueryString = "?messageType=" + messageType;
25721 tejbeer 873
	if (messageType == null) {
25680 amit.gupta 874
		messageQueryString = "";
875
	}
31762 tejbeer 876
	doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function(response) {
27711 amit.gupta 877
		if ($container != null) {
31762 tejbeer 878
			loaderDialogObj.one('hidden.bs.modal', function() {
27696 tejbeer 879
				$container.popover({
880
					container: $container,
27824 amit.gupta 881
					template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
27696 tejbeer 882
					content: response,
883
					html: true,
884
					placement: "bottom",
27824 amit.gupta 885
					trigger: "manual",
886
					sanitize: false
27711 amit.gupta 887
				}).popover('show');
31762 tejbeer 888
				setTimeout(function() {
889
					$container.focus().one('blur', function() {
27711 amit.gupta 890
						$container.popover('destroy');
891
					});
27826 amit.gupta 892
				}, 100);
27711 amit.gupta 893
			});
894
		}
895
	});
25649 tejbeer 896
}
25651 tejbeer 897
 
25689 amit.gupta 898
function downloadNotifyDocument(documentId, cid, documentName) {
25721 tejbeer 899
	doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
27618 tejbeer 900
		documentName);
25651 tejbeer 901
}
28051 amit.gupta 902
 
903
 
904
/* Create an array with the values of all the input boxes in a column */
31762 tejbeer 905
$.fn.dataTable.ext.order['dom-text'] = function(settings, col) {
906
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
28795 tejbeer 907
		return $('input', td).val();
908
	});
28051 amit.gupta 909
}
28795 tejbeer 910
 
28063 amit.gupta 911
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
31762 tejbeer 912
$.fn.dataTable.ext.order['dom-text-numeric'] = function(settings, col) {
913
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
28795 tejbeer 914
		return $('input', td).val() * 1;
915
	});
28051 amit.gupta 916
}
28795 tejbeer 917
 
31762 tejbeer 918
$.fn.dataTable.ext.order['dom-stock-numeric'] = function(settings, col) {
919
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
28870 tejbeer 920
		return $(td).html().split("/")[0] * 1;
921
	});
922
}
28051 amit.gupta 923
/* Create an array with the values of all the select options in a column */
31762 tejbeer 924
$.fn.dataTable.ext.order['dom-select'] = function(settings, col) {
925
	return this.api().column(col, { order: 'index' }).nodes().map(function(td, i) {
28795 tejbeer 926
		return $('select', td).val();
927
	});
28051 amit.gupta 928
}
28795 tejbeer 929
 
28051 amit.gupta 930
/* Create an array with the values of all the checkboxes in a column */
31762 tejbeer 931
$.fn.dataTable.ext.order['dom-checkbox'] = function(settings, col) {
30587 tejbeer 932
	return this.api().column(col, {
933
		order: 'index'
31762 tejbeer 934
	}).nodes().map(function(td, i) {
28795 tejbeer 935
		return $('input', td).prop('checked') ? '1' : '0';
936
	});
30414 amit.gupta 937
}
938
 
31762 tejbeer 939
$.fn.dataTable.Api.register('sum()', function() {
940
	return this.flatten().reduce(function(a, b) {
30414 amit.gupta 941
		if (typeof a === 'string') {
942
			a = a.replace(/[^\d.-]/g, '') * 1;
943
			a = isNaN(a) ? 0 : a;
944
		}
945
		if (typeof b === 'string') {
946
			b = b.replace(/[^\d.-]/g, '') * 1;
947
			b = isNaN(b) ? 0 : b;
948
		}
949
 
950
		return a + b;
951
	}, 0);
30694 amit.gupta 952
});
953
 
954
const debounce = (func, delay) => {
955
	let debounceTimer
31762 tejbeer 956
	return function() {
30694 amit.gupta 957
		const context = this
958
		const args = arguments
959
		clearTimeout(debounceTimer)
960
		debounceTimer
961
			= setTimeout(() => func.apply(context, args), delay)
962
	}
963
}
31687 amit.gupta 964
 
965
 
966
function ExportToExcel(container, type, fn, dl) {
967
	let tableId = $(container).data('tableid');
968
	var elt = document.getElementById(tableId);
969
	if ($.fn.DataTable.isDataTable(`#${tableId}`)) {
970
		elt = $(`#${tableId}`).DataTable().table(0).container();
971
	}
31762 tejbeer 972
	var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
31687 amit.gupta 973
	return dl ?
31762 tejbeer 974
		XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
31687 amit.gupta 975
		XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));
976
}
977
 
978
 
31762 tejbeer 979
$(document).on('click', ".manage-pcm", function() {
31687 amit.gupta 980
	managePCM();
981
});
982
 
983
function managePCM() {
31762 tejbeer 984
	doGetAjaxRequestHandler(`${context}/brand-pcm`, function(response) {
31687 amit.gupta 985
		$('#main-content').html(response);
986
	});
987
}
31786 tejbeer 988
 
989
 
990
 
31809 tejbeer 991
$(document).on('click', ".digify-retailer-login", function() {
31878 tejbeer 992
	$('#main-content').html(`<iframe class="wrapper" src="${context}/digify/register" style="width:100%;height:100vh"> </iframe>`);
993
	//$('#main-content').html(`<a class="wrapper" href="${context}/digify/register" target="_blank" style="width:100%;height:100vh"> </a>`);
31786 tejbeer 994
 
995
});
31878 tejbeer 996
 
997
 
998
$(document).on('click', ".digify-retailer-login-test", function() {
999
	//$('#main-content').html(`<iframe class="wrapper" src="${context}/digify/register" style="width:100%;height:100vh"> </iframe>`);
31881 tejbeer 1000
	return `<a class="wrapper" href="${context}/digify/register" target="_blank" style="width:100%;height:100vh"> </a>`
31878 tejbeer 1001
 
1002
});
1003
 
1004
 
1005