Subversion Repositories SmartDukaan

Rev

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