Subversion Repositories SmartDukaan

Rev

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