Subversion Repositories SmartDukaan

Rev

Rev 34516 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30757 tejbeer 1
$(function() {
2
	$(document).on('click', ".customer-offer", function() {
29707 tejbeer 3
		loadCustomerOffer("main-content");
4
	});
5
 
6
 
30757 tejbeer 7
	$(document).on('click', ".samsung-upgrade-offer", function() {
29707 tejbeer 8
		loadSamsungUpgradeOffer("main-content");
9
	});
10
 
30757 tejbeer 11
	$(document).on('click', ".createoffer", function() {
29707 tejbeer 12
 
13
 
14
		var offerName = $("#offername").val();
15
 
16
		if (offerName === "") {
17
			alert("Offer Name is required");
18
			return;
19
		}
20
 
31147 tejbeer 21
		let customerOfferModel = {};
22
		customerOfferModel['offerName'] = offerName;
23
		customerOfferModel['startDate'] = getDatesFromPicker('input[name="dateRange"]').startDate,
24
			customerOfferModel['endDate'] = getDatesFromPicker('input[name="dateRange"]').endDate,
25
			customerOfferModel['partnerCriteria'] = {};
26
		customerOfferModel['partnerCriteria']['fofoIds'] = ($("#partners").val() || []).map(Number);
27
		customerOfferModel['partnerCriteria']['excludeFofoIds'] = [];
28
		let excludeFofoIdChecked = $('input.excludeFofoId').is(':checked');
29
		if (excludeFofoIdChecked) {
30
			customerOfferModel['partnerCriteria']['excludeFofoIds'] = customerOfferModel['partnerCriteria']['fofoIds'];
31
			customerOfferModel['partnerCriteria']['fofoIds'] = [];
32
		}
29707 tejbeer 33
 
31147 tejbeer 34
		customerOfferModel['partnerCriteria']['partnerTypes'] = [];
35
 
36
		customerOfferModel['partnerCriteria']['regionIds'] = ($("select.criteria-warehouseregion").val() || []).map(Number);
37
 
38
 
39
 
29707 tejbeer 40
		if (confirm("Are you sure you want to create offer!") == true) {
31147 tejbeer 41
			doPostAjaxRequestWithJsonHandler(context
42
				+ "/createCustomerOffer", JSON.stringify(customerOfferModel), function(response) {
30757 tejbeer 43
					if (response = true) {
44
						alert("create  successfully");
45
						loadCustomerOffer("main-content");
46
					}
47
				});
29707 tejbeer 48
		}
49
 
50
 
51
	});
52
 
30757 tejbeer 53
	$(document).on('click', "#downloadCustomerOfferTemplate", function() {
29707 tejbeer 54
 
55
		window.location.href = context + "/customerOffer/downloadTemplate";
56
	});
57
 
58
 
33795 ranu 59
    $(document).on('click', ".customer-offer-daterange", function () {
60
        var startDate = getDatesFromPicker('input[name="customerOfferByDateRange"]').startDate;
61
        var endDate = getDatesFromPicker('input[name="customerOfferByDateRange"]').endDate;
62
 
63
        if (startDate == "" || startDate == undefined) {
64
            alert("start date is not be empty!!");
65
            return;
66
        }
67
        if (endDate == "" || endDate == undefined) {
68
 
69
            alert("end date is not be empty!!");
70
            return;
71
        }
72
        doGetAjaxRequestHandler(`${context}/getCustomerOffer?startDate=` + startDate + `&endDate=` + endDate, function (response) {
73
            $('#' + "main-content").html(response);
74
        });
75
    });
76
 
31147 tejbeer 77
	$(document).on('click', "#offer-item-search-button", function() {
78
		var searchText = $("#offer-item-search-text").val();
79
		var date = $(".schemes-date").val();
80
		if (typeof (searchText) == "undefined" || !searchText) {
81
			searchText = "";
82
			alert("please select item");
83
			return;
84
		}
85
		if (typeof currentItem != "undefined") {
86
			console.log(currentItem);
87
 
88
			doGetAjaxRequestHandler(`${context}/getCustomerOffer?searchModel=` + currentItem, function(response) {
89
				$('#' + "main-content").html(response);
90
			});
91
		} else {
92
			console.log("reeffff")
93
			alert("Data No Found")
94
		}
95
	});
96
 
30757 tejbeer 97
	$(document).on('click', ".downloadOffer", function() {
29707 tejbeer 98
		var id = $(this).data('requestid');
99
 
100
		window.location.href = context + "/customerOfferItem/download?offerId=" + id;
101
	});
102
 
103
 
30757 tejbeer 104
	$(document).on('click', ".extendeDate-button", function() {
30599 amit.gupta 105
		let id = $(this).data('requestid');
106
		let row = $(this).closest("tr");
30757 tejbeer 107
		let pickerElement = row.find("input[name = 'extendEndDate']");
31147 tejbeer 108
 
109
 
30599 amit.gupta 110
		let params = {
29707 tejbeer 111
			"id": id,
31147 tejbeer 112
			"endDate": getDatesFromPicker(pickerElement).endDate
29707 tejbeer 113
		}
30757 tejbeer 114
 
115
		console.log(params)
29707 tejbeer 116
		if (confirm("Are you sure you want extend the offer") == true) {
117
			doPostAjaxRequestWithParamsHandler(context
30757 tejbeer 118
				+ "/extendCustomerOffer", params, function(response) {
119
					row.html(response);
120
				});
29707 tejbeer 121
		}
122
 
123
	});
124
 
125
 
30757 tejbeer 126
	$(document).on('input', 'table#offer-customer-table input[type=file]', function() {
29851 tejbeer 127
		var row = $(this).closest("tr");
128
		var id = $(row).find("td:eq(0)").text();
129
		if (confirm('Confirm upload ?')) {
130
			var fileSelector = $(this)[0];
131
			if (fileSelector != undefined
132
				&& fileSelector.files[0] != undefined) {
133
				var url = `${context}/customerOfferItem/upload?offerId=` + id;
134
				console.log(url);
135
				var file = this.files[0];
136
				console.log("file" + file);
137
				let fileInput = $(this);
138
				console.log("fileInput" + file);
30757 tejbeer 139
				doAjaxUploadRequestHandler(url, 'POST', file, function(response) {
30599 amit.gupta 140
					console.log(response)
141
					alert("successfully uploaded");
142
				});
29849 tejbeer 143
			}
29851 tejbeer 144
		}
145
	});
29707 tejbeer 146
 
147
 
30757 tejbeer 148
	$(document).on('click', ".upgrade-approved", function() {
29851 tejbeer 149
		var id = $(this).data('requestid');
150
		var row = $(this).closest("tr");
29707 tejbeer 151
 
29851 tejbeer 152
		if (confirm("Are you sure you want Approve r!") == true) {
30757 tejbeer 153
			doPostAjaxRequestHandler(`${context}/approveSamsungUpgradeOffer?id=${id}`, function(response) {
30599 amit.gupta 154
				alert("Successfully Approved");
155
				row.html(response);
156
				return false;
157
			});
29851 tejbeer 158
		}
29707 tejbeer 159
 
160
	});
161
 
30757 tejbeer 162
	$(document).on('click', ".upgrade-rejected", function() {
30599 amit.gupta 163
		let id = $(this).data('requestid');
29851 tejbeer 164
		if (confirm("Are you sure you want Reject!") == true) {
30757 tejbeer 165
			doPostAjaxRequestHandler(`${context}/rejectSamsungUpgradeOffer?id=${id}`, function(response) {
30599 amit.gupta 166
				if (response == 'true') {
167
					alert("Successfully Rejected");
168
					loadWalletRequest("main-content");
169
				}
170
				return false;
171
			});
29851 tejbeer 172
		}
173
	});
174
 
31147 tejbeer 175
	$(document).on('click', ".customerOfferItems", function() {
29851 tejbeer 176
 
31147 tejbeer 177
		var currentRow = $(this).closest("tr");
178
 
179
		var offerId = currentRow.find("td:eq(0)").text();
180
 
181
 
182
 
183
		doGetAjaxRequestHandler(context + "/getCustomerOfferItem?offerId="
184
			+ offerId, function(response) {
185
 
186
				console.log(response)
187
				$('#customerOfferItemdetail .modal-content').html(response);
188
 
189
			});
190
 
191
	});
192
 
193
 
194
 
195
	$(document).on('click', ".expired-date-button", function() {
196
		let id = $(this).data('requestid');
197
		let row = $(this).closest("tr");
198
		let pickerElement = row.find("input[name = 'expiredEndDate']");
199
		let params = {
200
			"id": id,
201
			"endDate": getDatesFromPicker(pickerElement).startDate
202
		}
203
 
204
		console.log(params)
205
		if (confirm("Are you sure you want expired the offer") == true) {
206
			doPostAjaxRequestWithParamsHandler(context
207
				+ "/expiredCustomerOfferItem", params, function(response) {
208
					row.html(response);
209
				});
210
		}
211
 
212
	});
213
 
214
 
215
	$(document).on('click', ".addOfferItem", function() {
216
 
217
		let offerId = $(this).data('offerid');
218
 
219
		var dealerPayout = $("#dealerPayout").val();
220
 
33795 ranu 221
        var offerType = $("#offerType").val();
222
 
31147 tejbeer 223
		var schemePayout = $("#schemePayout").val();
224
 
34516 ranu 225
		var additionalInfo = $("#additionalInfo").val();
31147 tejbeer 226
 
34516 ranu 227
 
31147 tejbeer 228
		if (dealerPayout === "") {
229
			alert("Dealer Payout is required");
230
			return;
231
		}
232
 
33795 ranu 233
        if (offerType === "") {
234
            alert("Offer Type is required");
235
            return;
236
        }
237
 
31147 tejbeer 238
		if (schemePayout === "") {
239
			alert("Scheme Payout is required");
240
			return;
241
		}
242
 
243
		var json = {
244
 
245
			"catalogId": currentItem,
246
			"dealerPayout": dealerPayout,
33795 ranu 247
            "offerType": offerType,
31147 tejbeer 248
			"schemePayout": schemePayout,
34516 ranu 249
			"additionalInfo": additionalInfo,
31147 tejbeer 250
			"startDate": getDatesFromPicker('input[name="offerItemDuration"]').startDate,
251
			"endDate": getDatesFromPicker('input[name="offerItemDuration"]').endDate,
252
			"offerId": offerId
253
 
34516 ranu 254
 
31147 tejbeer 255
		}
256
 
34788 ranu 257
		// STEP 1: Check for existing
258
		doPostAjaxRequestWithJsonHandler(context + "/CheckIfExistCustomerOfferItem", JSON.stringify(json), function (checkResponse) {
31147 tejbeer 259
 
34788 ranu 260
			IdempotencyKey = uuidv4();
261
			if (checkResponse === true || checkResponse === "true") {
262
				// Show alert — item exists
263
				if (confirm("Are you sure want to upload this offer")) {
264
					confirmAndAddOffer(json);
265
				}
31147 tejbeer 266
 
34788 ranu 267
			} else {
268
				// Show alert — item exists
269
				if (confirm("This item already exists under the offer. Do you want to continue and create it anyway?")) {
270
					if (confirm("Are you sure want to upload this offer")) {
271
						confirmAndAddOffer(json);
31147 tejbeer 272
					}
34788 ranu 273
				}
274
			}
275
		});
31147 tejbeer 276
 
277
	});
278
 
29851 tejbeer 279
});
280
 
34788 ranu 281
 
282
function confirmAndAddOffer(json) {
283
	doPostAjaxRequestWithJsonHandler(context + "/addCustomerOfferItem", JSON.stringify(json), function (response) {
284
		if (response === true || response === "true") {
285
			alert("Created successfully");
286
			$('#customerOfferItemdetail').modal('hide');
287
			$('.modal-backdrop').remove();
288
			loadCustomerOffer("main-content");
289
		} else {
290
			alert("Something went wrong while creating the offer.");
291
		}
292
	});
293
}
294
 
29851 tejbeer 295
function loadCustomerOffer(domId) {
296
 
30757 tejbeer 297
	doGetAjaxRequestHandler(`${context}/getCustomerOffer`, function(response) {
29851 tejbeer 298
		$('#' + domId).html(response);
299
	});
300
}
301
 
302
function loadSamsungUpgradeOffer(domId) {
30757 tejbeer 303
	doGetAjaxRequestHandler(context + "/getSamsungUpgradeOffer", function(response) {
29851 tejbeer 304
		$('#' + domId).html(response);
305
	});
31147 tejbeer 306
}
307