| 30084 |
amit.gupta |
1 |
function createSchemeOnReady() {
|
| 34317 |
amit.gupta |
2 |
$("form#create-scheme-form input").each(function () {
|
|
|
3 |
$(this).attr('autocomplete', 'off');
|
|
|
4 |
});
|
|
|
5 |
// validate the comment form when it is submitted
|
|
|
6 |
$('#create-scheme-form').validate({
|
|
|
7 |
rules: {
|
|
|
8 |
schemeName: {
|
|
|
9 |
required: true
|
|
|
10 |
},
|
|
|
11 |
schemeType: {
|
|
|
12 |
required: true
|
|
|
13 |
},
|
|
|
14 |
amountType: {
|
|
|
15 |
required: true
|
|
|
16 |
},
|
|
|
17 |
schemeAmount: {
|
|
|
18 |
required: true
|
|
|
19 |
},
|
| 36452 |
amit |
20 |
schemeReference: {
|
|
|
21 |
required: true
|
|
|
22 |
},
|
| 34317 |
amit.gupta |
23 |
startDate: {
|
|
|
24 |
required: true
|
|
|
25 |
},
|
|
|
26 |
endDate: {
|
|
|
27 |
required: true
|
|
|
28 |
},
|
|
|
29 |
itemIdsDescription: {
|
|
|
30 |
required: true
|
|
|
31 |
},
|
|
|
32 |
retailerIds: {
|
|
|
33 |
required: true
|
|
|
34 |
}
|
|
|
35 |
},
|
|
|
36 |
messages: {
|
|
|
37 |
name: {
|
|
|
38 |
required: "Please enter the name"
|
|
|
39 |
},
|
|
|
40 |
schemeType: {
|
|
|
41 |
required: "Please choose type"
|
|
|
42 |
},
|
|
|
43 |
amountType: {
|
|
|
44 |
required: "Please choose amount type"
|
|
|
45 |
},
|
|
|
46 |
schemeAmount: {
|
|
|
47 |
required: "Please enter the amount"
|
|
|
48 |
},
|
| 36452 |
amit |
49 |
schemeReference: {
|
|
|
50 |
required: "Please enter a reference"
|
|
|
51 |
},
|
| 34317 |
amit.gupta |
52 |
startDate: {
|
|
|
53 |
require: "Please choose start date"
|
|
|
54 |
},
|
|
|
55 |
endDate: {
|
|
|
56 |
require: "Please choose end date"
|
|
|
57 |
},
|
|
|
58 |
itemIdsDescription: {
|
|
|
59 |
required: "Please choose items"
|
|
|
60 |
},
|
|
|
61 |
retailerIds: {
|
|
|
62 |
required: "Please enter retailer ids"
|
|
|
63 |
}
|
|
|
64 |
},
|
|
|
65 |
submitHandler: function (form, event) {
|
|
|
66 |
event.preventDefault();
|
|
|
67 |
if (validateSchemeDetails()) {
|
|
|
68 |
alert("Please fix errors");
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
let json = schemeDetailsJson();
|
|
|
72 |
console.log("schemeJson = " + json);
|
|
|
73 |
if (confirm("Are you sure you want to create Scheme!") === true) {
|
|
|
74 |
doPostAjaxRequestWithJsonHandler(context + "/createScheme", json, function (response) {
|
|
|
75 |
alert("Scheme created successfully!");
|
|
|
76 |
$('#main-content').html(response);
|
|
|
77 |
});
|
|
|
78 |
return false; // required to block normal submit since you used ajax
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
});
|
| 22860 |
ashik.ali |
82 |
|
| 30084 |
amit.gupta |
83 |
}
|
| 23347 |
ashik.ali |
84 |
|
| 30084 |
amit.gupta |
85 |
|
| 30454 |
amit.gupta |
86 |
$('#retailerAll').on('change', function () {
|
| 34317 |
amit.gupta |
87 |
if (this.checked) {
|
|
|
88 |
$('#retailerAll').val('true');
|
|
|
89 |
$('#retailer-ids').html('');
|
|
|
90 |
} else {
|
|
|
91 |
$('#retailerAll').val('false');
|
|
|
92 |
$('#retailer-ids').html('<input placeholder="Retailer Ids" id="retailerIds" name="retailerIds" type="text" value="" pattern="^[0-9]{1,10}(?:,[0-9]{1,10})*$" title="Comma Seperated Positive Integer Retailer Ids" class="form-control input-sm">');
|
|
|
93 |
}
|
| 23347 |
ashik.ali |
94 |
});
|
|
|
95 |
|
| 30454 |
amit.gupta |
96 |
$(document).on('change', '#schemeType', function () {
|
| 34317 |
amit.gupta |
97 |
debugger;
|
|
|
98 |
$("#cashbackScheme").prop('checked', false).prop('disabled', true);
|
|
|
99 |
let schemeType = $(this).val();
|
|
|
100 |
console.log("Scheme type " + schemeType);
|
|
|
101 |
if (schemeType === 'ACTIVATION') {
|
|
|
102 |
$("#cashbackScheme").prop('disabled', false);
|
| 23347 |
ashik.ali |
103 |
|
| 34317 |
amit.gupta |
104 |
}
|
| 30454 |
amit.gupta |
105 |
});
|
|
|
106 |
|
| 34317 |
amit.gupta |
107 |
$(document).on('change', ".stockTransactionType, .amountType", function () {
|
|
|
108 |
let stockTransactionType = $(".stockTransactionType").val();
|
|
|
109 |
let amountType = $('.amountType').val();
|
|
|
110 |
if (stockTransactionType !== null && amountType !== null) {
|
| 30454 |
amit.gupta |
111 |
|
| 34317 |
amit.gupta |
112 |
|
|
|
113 |
let options = document.querySelectorAll("#schemeType option");
|
|
|
114 |
|
|
|
115 |
Array.from(options).slice(1).forEach(option => {
|
|
|
116 |
let currentStockTransactionType = $(option).data('stocktransactiontype'); // current stock transaction type
|
|
|
117 |
let currentAmountType = $(option).data('amounttype'); // Current amount type
|
|
|
118 |
if (currentAmountType === amountType && currentStockTransactionType === stockTransactionType) {
|
|
|
119 |
option.style.display = "";
|
|
|
120 |
} else {
|
|
|
121 |
option.style.display = "none";
|
|
|
122 |
}
|
|
|
123 |
});
|
|
|
124 |
}
|
|
|
125 |
});
|
|
|
126 |
|
|
|
127 |
|
| 30432 |
tejbeer |
128 |
function validateSchemeDetails() {
|
| 34317 |
amit.gupta |
129 |
console.log("validating Scheme Details...");
|
|
|
130 |
var error = false;
|
|
|
131 |
var name = $("form#create-scheme-form input[name=schemeName]").val();
|
|
|
132 |
console.log("schemeName = " + name);
|
|
|
133 |
let regionIds = $('.criteria-regionids').val();
|
|
|
134 |
//console.log(regionIds);
|
|
|
135 |
if (regionIds.length > 1 && regionIds.indexOf('5') > 0) {
|
|
|
136 |
alert("Cant add ALL region with other regions");
|
|
|
137 |
error = true;
|
|
|
138 |
return error;
|
|
|
139 |
}
|
|
|
140 |
if (regionIds.length == 0) {
|
|
|
141 |
alert("Region required");
|
|
|
142 |
error = true;
|
|
|
143 |
return error;
|
|
|
144 |
}
|
|
|
145 |
$("#schemeName").removeClass("border-highlight");
|
|
|
146 |
if (name == "") {
|
|
|
147 |
alert("Name is required");
|
|
|
148 |
$("#schemeName").addClass("border-highlight");
|
|
|
149 |
error = true;
|
|
|
150 |
return error;
|
|
|
151 |
}
|
| 36452 |
amit |
152 |
var reference = $("#schemeReference").val();
|
|
|
153 |
$("#schemeReference").removeClass("border-highlight");
|
|
|
154 |
if (reference == "" || reference.trim() === '') {
|
|
|
155 |
alert("Reference is required");
|
|
|
156 |
$("#schemeReference").addClass("border-highlight");
|
|
|
157 |
error = true;
|
|
|
158 |
return error;
|
|
|
159 |
}
|
| 34317 |
amit.gupta |
160 |
var schemeType = $("#schemeType option:selected").val();
|
|
|
161 |
console.log("schemeType = " + schemeType);
|
|
|
162 |
$("#schemeType").removeClass("border-highlight");
|
|
|
163 |
if (schemeType == "") {
|
|
|
164 |
alert("Please choose Scheme Type");
|
|
|
165 |
$("#schemeType").addClass("border-highlight");
|
|
|
166 |
error = true;
|
|
|
167 |
return error;
|
|
|
168 |
}
|
|
|
169 |
var amountType = $("#amountType option:selected").val();
|
|
|
170 |
console.log("amountType = " + amountType);
|
|
|
171 |
$("#amountType").removeClass("border-highlight");
|
|
|
172 |
if (amountType == "") {
|
|
|
173 |
alert("Please choose Amount Type");
|
|
|
174 |
$("#amountType").addClass("border-highlight");
|
|
|
175 |
error = true;
|
|
|
176 |
return error;
|
|
|
177 |
}
|
|
|
178 |
var amount = $("form#create-scheme-form input[name=schemeAmount]").val();
|
|
|
179 |
console.log("amount = " + amount);
|
|
|
180 |
$("#schemeAmount").removeClass("border-highlight");
|
|
|
181 |
if (amount == "") {
|
|
|
182 |
$("form#create-scheme-form input[name=schemeAmount]").val(0);
|
|
|
183 |
} else if (amount <= 0) {
|
|
|
184 |
alert("Amount should be greater than 0");
|
|
|
185 |
$("#schemeAmount").addClass("border-highlight");
|
|
|
186 |
error = true;
|
|
|
187 |
return error;
|
|
|
188 |
}
|
| 30148 |
amit.gupta |
189 |
|
|
|
190 |
|
| 34317 |
amit.gupta |
191 |
//$('#brand-value').text($(this).text());
|
|
|
192 |
$("#tag-listing-brand-value").removeClass("border-highlight");
|
|
|
193 |
if ($("#tag-listing-brand-value").text() == "Brands") {
|
|
|
194 |
alert("Please choose Brand");
|
|
|
195 |
$("#tag-listing-brand-value").addClass("border-highlight");
|
|
|
196 |
error = true;
|
|
|
197 |
return error;
|
|
|
198 |
}
|
| 30148 |
amit.gupta |
199 |
|
| 34317 |
amit.gupta |
200 |
$("select.catalogItemsDescription").removeClass("border-hightlight");
|
|
|
201 |
var itemIdsString = $("select.catalogItemsDescription").val();
|
|
|
202 |
debugger;
|
|
|
203 |
if (itemIdsString == null) {
|
|
|
204 |
alert("Please choose items");
|
|
|
205 |
$("select.catalogItemsDescription").addClass("border-highlight");
|
|
|
206 |
error = true;
|
|
|
207 |
return error;
|
|
|
208 |
}
|
| 30148 |
amit.gupta |
209 |
|
| 34317 |
amit.gupta |
210 |
console.log("validation scheme error = " + error);
|
|
|
211 |
return error;
|
| 23343 |
ashik.ali |
212 |
}
|
|
|
213 |
|
| 30432 |
tejbeer |
214 |
function schemeDetailsJson() {
|
| 34317 |
amit.gupta |
215 |
var schemeObject = {};
|
|
|
216 |
schemeObject['description'] = $("form#create-scheme-form input[name=schemeName]").val();
|
|
|
217 |
schemeObject['type'] = $("#schemeType option:selected").val();
|
|
|
218 |
schemeObject['name'] = $("#schemeType option:selected").html();
|
|
|
219 |
schemeObject['amountType'] = $("#amountType option:selected").val();
|
|
|
220 |
schemeObject['amount'] = $('#schemeAmount').val();
|
|
|
221 |
schemeObject['partnerType'] = $('#retailerType').val();
|
|
|
222 |
schemeObject['cashback'] = $("#cashbackScheme").is(":checked")
|
|
|
223 |
schemeObject['startDate'] = $("#schemeDuration").data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
|
|
224 |
schemeObject['endDate'] = $("#schemeDuration").data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
|
|
225 |
schemeObject['catalogIds'] = $("select.catalogItemsDescription").val();
|
|
|
226 |
schemeObject['regionIds'] = $("form#create-scheme-form .criteria-regionids").val();
|
| 36452 |
amit |
227 |
schemeObject['reference'] = $("#schemeReference").val();
|
| 34317 |
amit.gupta |
228 |
return JSON.stringify(schemeObject);
|
| 23343 |
ashik.ali |
229 |
}
|