Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
34881 aman 1
$(document).on('click', '.affiliate-product', function () {
2
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateProductList`, function (response) {
3
        $('#main-content').html(response);
4
    });
5
});
34947 aman 6
 
7
$(document).on('click', '.affiliate-kyc', function () {
8
    doGetAjaxRequestHandler(`${context}/affiliate/getPendingKyc`, function (response) {
9
        $('#main-content').html(response);
10
    });
11
});
12
 
34881 aman 13
$(document).on('click', '.saveAffiliateProduct', function () {
14
    if (!$('#catalog_id').val()) {
15
        alert('Please select a catalog');
16
        return;
17
    }
18
    const formData = {
19
        catalogId: $('#catalog_id').val(),
20
        status: $('#status').val(),
21
        expiryDate: $('#expiry_date').val(),
34947 aman 22
        commission: $('#commission').val(),
34881 aman 23
        giftId: $('#gift_ids').val()?.toString(),
34947 aman 24
        featured: $('#featured').is(':checked')
34881 aman 25
    };
26
    doAjaxRequestWithJsonHandler(
27
        `${context}/affiliate/create-affiliate-product`,
28
        "POST",
29
        JSON.stringify(formData),
30
        function (response) {
31
            if (response.responseStatus === "SUCCESS") {
32
                alert('Affiliate product created successfully!');
33
                $('#addAffiliateProductModal').modal('hide');
34900 aman 34
                $('.affiliate-product').click();
34881 aman 35
            } else {
36
                alert('Error: ' + response.message);
37
            }
38
 
39
        }
40
    );
41
});
42
 
43
$(document).on('click', '.map-catalog', function () {
44
    $('#addAffiliateProductModal').modal('show');
45
});
46
 
47
$(document).on('click', '.edit-affiliate-product', function () {
48
    const productId = $(this).data('productid');
49
 
50
    doGetAjaxRequestHandler(`${context}/affiliate/updateAffiliateProductList/${productId}`, function (response) {
51
        console.log('Response received:', response);
52
 
53
        try {
54
            if (!response) {
55
                console.error('Empty response received');
56
                return;
57
            }
58
 
59
            if (response.catalogId) {
60
                $('#edit_catalog_id').val(response.catalogId).multiselect('refresh');
61
            }
62
            const giftIds = response.giftId ? response.giftId.split(',') : [];
63
            $('#edit_gift_ids').val(giftIds).multiselect('refresh');
64
            if (response.status) {
65
                $('#edit_status').val(response.status);
66
            }
34947 aman 67
            if (response.commission) {
68
                $('#edit_commission').val(response.commission);
69
            }
70
            if (response.featured !== undefined) {
71
                $('#edit_featured').prop('checked', response.featured);
72
            }
34881 aman 73
            if (response.expiryDate && Array.isArray(response.expiryDate)) {
74
                const [year, month, day, hour, minute] = response.expiryDate;
75
                const dateString = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}T${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`;
76
                $('#edit_expiry_date').val(dateString);
77
            }
78
 
79
            console.log('About to show modal'); // Debug log
80
 
81
            $('#editAffiliateProductModal').data('product-id', productId);
82
            $('#editAffiliateProductModal').modal('show');
83
 
84
            console.log('Modal show command executed'); // Debug log
85
 
86
        } catch (error) {
87
            console.error('Error processing response:', error);
88
        }
89
    }, function (error) {
90
        console.error('AJAX request failed:', error);
91
    });
92
});
93
 
94
 
95
$(document).on('click', '.updateAffiliateProduct', function () {
96
    const productId = $('#editAffiliateProductModal').data('product-id');
97
 
98
    const formData = {
99
        id: productId,
100
        catalogId: $('#edit_catalog_id').val(),
34947 aman 101
        giftId: $('#edit_gift_ids').val().join(','),
34881 aman 102
        status: $('#edit_status').val(),
34947 aman 103
        expiryDate: $('#edit_expiry_date').val(),
104
        commission: $('#edit_commission').val(),
105
        featured: $('#edit_featured').is(':checked')
34881 aman 106
    };
107
 
108
    doAjaxRequestWithJsonHandler(
109
        `${context}/affiliate/edit-affiliate-product`,
110
        "POST",
111
        JSON.stringify(formData),
112
        function (response) {
113
            if (response) {
114
                alert('Updated successfully!');
115
                $('#editAffiliateProductModal').modal('hide');
34900 aman 116
                $('.affiliate-product').click();
34881 aman 117
            } else {
118
                alert('Error: ' + response.message);
119
            }
120
        }
121
    );
122
});
123
// Reset CREATE modal when closed
124
$('#addAffiliateProductModal').on('hidden.bs.modal', function () {
125
    $(this).find('form')[0].reset();
126
    $('#catalog_id, #gift_ids').val('').multiselect('refresh');
127
});
128
 
129
$('#editAffiliateProductModal').on('hidden.bs.modal', function () {
130
    $(this).find('form')[0].reset();
131
    $(this).removeData('product-id');
132
    $('#edit_catalog_id, #edit_gift_ids').val('').multiselect('refresh');
34947 aman 133
    $('#edit_featured').prop('checked', false);
34881 aman 134
});
135
 
136
$(document).on('click', '.delete-affiliate-product', function () {
137
    const id = $(this).data('productid');
138
    console.log("this is the id" + id);
139
    if (confirm('Are you sure you want to delete this product?')) {
140
        doDeleteAjaxRequestHandler(
141
            `${context}/affiliate/delete-affiliate-product/${id}`,
142
            function () {
143
                alert('Product deleted successfully!');
144
 
145
            }
146
        );
147
    }
148
});
149
 
150
 
151
$(document).on('click', '.affiliate-gift', function () {
152
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateGiftList`, function (response) {
153
        $('#main-content').html(response);
154
    });
155
});
156
 
157
$(document).on('click', '.saveAffiliateGift', function () {
158
    const formData = {
159
        name: $('#gift_name').val(),
160
        status: $('#gift_Status').val() || "ACTIVE",
161
        qty: $('#gift_qty').val(),
162
    };
163
    console.log("we are getting the request body", formData);
164
    doAjaxRequestWithJsonHandler(
165
        `${context}/affiliate/create-affiliate-gift`,
166
        "POST",
167
        JSON.stringify(formData),
168
        function (response) {
169
            if (response.responseStatus === "SUCCESS") {
170
                alert('Affiliate product created successfully!');
171
                $('#addAffiliateGiftModal').modal('hide');
34900 aman 172
                $('.affiliate-gift').click();
34881 aman 173
            } else {
174
                alert('Error: ' + response.message);
175
            }
176
 
177
        }
178
    );
179
});
180
 
181
 
182
$(document).on('click', '.edit-affiliate-gift', function () {
183
    const giftId = $(this).data('giftid');
184
 
185
    doGetAjaxRequestHandler(`${context}/affiliate/updateAffiliateGift/${giftId}`, function (response) {
186
        console.log('Response received:', response);
187
 
188
        try {
189
            if (!response) {
190
                console.error('Empty response received');
191
                return;
192
            }
193
            if (response.name) {
194
                $('#edit_gift_name').val(response.name);
195
            }
196
            $('#edit_gift_qty').val(response.qty);
197
            if (response.status) {
198
                $('#edit_gift_Status').val(response.status);
199
            }
200
            console.log('About to show modal'); // Debug log
201
            $('#editAffiliateGiftModal').data('gift-id', giftId);
202
            $('#editAffiliateGiftModal').modal('show');
203
            console.log('Modal show command executed'); // Debug log
204
        } catch (error) {
205
            console.error('Error processing response:', error);
206
        }
207
    }, function (error) {
208
        console.error('AJAX request failed:', error);
209
    });
210
});
211
 
212
$(document).on('click', '.updateAffiliateGift', function () {
213
    const giftId = $('#editAffiliateGiftModal').data('gift-id');
214
 
215
    const formData = {
216
        id: giftId,
217
        name: $('#edit_gift_name').val(),
218
        qty: $('#edit_gift_qty').val(),
219
        status: $('#edit_gift_Status').val(),
220
 
221
    };
222
 
223
    doAjaxRequestWithJsonHandler(
224
        `${context}/affiliate/edit-affiliate-gift`,
225
        "POST",
226
        JSON.stringify(formData),
227
        function (response) {
228
            if (response) {
229
                alert('Updated successfully!');
230
                $('#editAffiliateGiftModal').modal('hide');
34900 aman 231
                $('.affiliate-gift').click();
34881 aman 232
            } else {
233
                alert('Error: ' + response.message);
234
            }
235
        }
236
    );
237
});
238
 
239
 
240
$(document).on('click', '.delete-affiliate-gift', function () {
241
    const id = $(this).data('giftid');
242
    console.log("this is the id" + id);
243
    if (confirm('Are you sure you want to delete this gift?')) {
244
        doDeleteAjaxRequestHandler(
245
            `${context}/affiliate/delete-affiliate-gift/${id}`,
246
            function () {
247
                alert('Gift deleted successfully!');
248
 
249
            }
250
        );
251
    }
252
});
253
 
34947 aman 254
$(document).on('click', '.approve-btn', function () {
255
    let approveModal = {
256
        id: $(this).data('kyc-id'),
257
        status: "APPROVED"
258
    };
259
    doPostAjaxRequestWithJsonHandler(
260
        `${context}/affiliate/approveRejectKyc`,
261
        JSON.stringify(approveModal),
262
        function (response) {
263
            alert("KYC Approved successfully");
264
 
265
        }
266
    );
267
});
268
 
269
$(document).on('click', '#confirmReject', function () {
270
    let rejectModal = {
271
        id: $('#rejectionModal').data('kyc-id'),
272
        status: "REJECTED",
273
        reason: $('#rejectionReason').val()
274
    };
275
    doPostAjaxRequestWithJsonHandler(
276
        `${context}/affiliate/approveRejectKyc`,
277
        JSON.stringify(rejectModal),
278
        function (response) {
279
            alert("KYC REJECTED successfully");
280
            $('#rejectionModal').modal('hide');
281
        }
282
    );
283
});
284
 
285
$(document).on('click', '.reject-btn', function () {
286
    let kycId = $(this).data('kyc-id');
287
    $('#rejectionModal').data('kyc-id', kycId);
288
});
289
 
290
$(document).on("click", ".view-btn", function () {
291
    var docId = $(this).attr("data-doc-id");
292
    if (!docId) {
293
        alert("Document not available");
294
        return;
295
    }
296
    var url = context + "/document/" + docId;
297
    var isPdf = /\.pdf($|\?)/i.test(url);
298
    var $body = $("#kycDocBody").empty();
299
    if (isPdf) {
300
        $body.html('<iframe src="' + url + '" width="100%" height="600" frameborder="0"></iframe>');
301
    } else {
302
        $body.html('<img src="' + url + '" alt="KYC Document" class="img-fluid rounded">');
303
    }
304
    $("#kycDocModal").modal("show");
305
});
306