Subversion Repositories SmartDukaan

Rev

Rev 31147 | Rev 34516 | Go to most recent revision | 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
 
225
 
226
		if (dealerPayout === "") {
227
			alert("Dealer Payout is required");
228
			return;
229
		}
230
 
33795 ranu 231
        if (offerType === "") {
232
            alert("Offer Type is required");
233
            return;
234
        }
235
 
31147 tejbeer 236
		if (schemePayout === "") {
237
			alert("Scheme Payout is required");
238
			return;
239
		}
240
 
241
		var json = {
242
 
243
			"catalogId": currentItem,
244
			"dealerPayout": dealerPayout,
33795 ranu 245
            "offerType": offerType,
31147 tejbeer 246
			"schemePayout": schemePayout,
247
			"startDate": getDatesFromPicker('input[name="offerItemDuration"]').startDate,
248
			"endDate": getDatesFromPicker('input[name="offerItemDuration"]').endDate,
249
			"offerId": offerId
250
 
251
		}
252
 
253
 
254
 
255
		if (confirm("Are you sure you want to create offer!") == true) {
256
			doPostAjaxRequestWithJsonHandler(context
257
				+ "/addCustomerOfferItem", JSON.stringify(json), function(response) {
258
					if (response = true) {
259
						alert("create  successfully");
260
						$('#customerOfferItemdetail').modal('hide');
261
						$('.modal-backdrop').remove();
262
						loadCustomerOffer("main-content");
263
					}
264
				});
265
		}
266
 
267
 
268
	});
269
 
29851 tejbeer 270
});
271
 
272
function loadCustomerOffer(domId) {
273
 
30757 tejbeer 274
	doGetAjaxRequestHandler(`${context}/getCustomerOffer`, function(response) {
29851 tejbeer 275
		$('#' + domId).html(response);
276
	});
277
}
278
 
279
function loadSamsungUpgradeOffer(domId) {
30757 tejbeer 280
	doGetAjaxRequestHandler(context + "/getSamsungUpgradeOffer", function(response) {
29851 tejbeer 281
		$('#' + domId).html(response);
282
	});
31147 tejbeer 283
}
284