Subversion Repositories SmartDukaan

Rev

Rev 34047 | Rev 35884 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34047 Rev 35806
Line 1127... Line 1127...
1127
        });
1127
        });
1128
    }
1128
    }
1129
}
1129
}
1130
 
1130
 
1131
 
1131
 
-
 
1132
// ============ GRN Correction ============
-
 
1133
 
-
 
1134
$(document).on('click', '.warehouse-grn-correction', function () {
-
 
1135
    loadGrnCorrection("main-content");
-
 
1136
});
-
 
1137
 
-
 
1138
$(document).on('click', '.warehouse-grn-correction-approval', function () {
-
 
1139
    loadGrnCorrectionApproval("main-content");
-
 
1140
});
-
 
1141
 
-
 
1142
$(document).on('click', '.searchCorrectionInvoices', function () {
-
 
1143
    var startDate = getDatesFromPicker('input[name="correction-duration"]').startDate;
-
 
1144
    var endDate = getDatesFromPicker('input[name="correction-duration"]').endDate;
-
 
1145
    doGetAjaxRequestHandler(context + "/grnCorrection?startDate=" + startDate + "&endDate=" + endDate, function (response) {
-
 
1146
        $('#main-content').html(response);
-
 
1147
    });
-
 
1148
});
-
 
1149
 
-
 
1150
$(document).on('click', '.submitGrnCorrection', function () {
-
 
1151
    var invoiceId = $(this).data('invoiceid');
-
 
1152
    var remarks = $('#correctionRemarks').val();
-
 
1153
 
-
 
1154
    if (!remarks || remarks.trim() === '') {
-
 
1155
        alert("Please enter remarks explaining the reason for correction");
-
 
1156
        return false;
-
 
1157
    }
-
 
1158
 
-
 
1159
    // Collect serial number corrections (old → new)
-
 
1160
    var corrections = [];
-
 
1161
    $('#serial-corrections-table > tbody > tr').each(function () {
-
 
1162
        var oldSerial = $(this).find('.old-serial').val();
-
 
1163
        var newSerial = $(this).find('.new-serial').val();
-
 
1164
 
-
 
1165
        if (oldSerial && newSerial && oldSerial.trim() !== '' && newSerial.trim() !== '') {
-
 
1166
            corrections.push({
-
 
1167
                oldSerialNumber: oldSerial.trim(),
-
 
1168
                newSerialNumber: newSerial.trim()
-
 
1169
            });
-
 
1170
        }
-
 
1171
    });
-
 
1172
 
-
 
1173
    // Collect non-serialized qty corrections
-
 
1174
    var qtyCorrections = [];
-
 
1175
    $('#qty-corrections-table > tbody > tr').each(function () {
-
 
1176
        var oldItemId = $(this).find('.qty-old-itemid').val();
-
 
1177
        var newItemId = $(this).find('.qty-new-itemid').val();
-
 
1178
        var qty = parseInt($(this).find('.qty-correction-val').val());
-
 
1179
 
-
 
1180
        if (oldItemId && newItemId && qty > 0) {
-
 
1181
            qtyCorrections.push({
-
 
1182
                oldItemId: parseInt(oldItemId),
-
 
1183
                newItemId: parseInt(newItemId),
-
 
1184
                qty: qty
-
 
1185
            });
-
 
1186
        }
-
 
1187
    });
-
 
1188
 
-
 
1189
    if (corrections.length === 0 && qtyCorrections.length === 0) {
-
 
1190
        alert("No corrections specified. Please enter serial number or quantity corrections.");
-
 
1191
        return false;
-
 
1192
    }
-
 
1193
 
-
 
1194
    var requestModel = {
-
 
1195
        invoiceId: invoiceId,
-
 
1196
        remarks: remarks,
-
 
1197
        corrections: corrections,
-
 
1198
        qtyCorrections: qtyCorrections
-
 
1199
    };
-
 
1200
 
-
 
1201
    if (confirm("Are you sure you want to raise this GRN correction request?")) {
-
 
1202
        doPostAjaxRequestWithJsonHandler(context + "/raiseGrnCorrection",
-
 
1203
            JSON.stringify(requestModel), function (response) {
-
 
1204
                if (response == 'true') {
-
 
1205
                    alert("Correction request submitted successfully");
-
 
1206
                    loadGrnCorrection("main-content");
-
 
1207
                }
-
 
1208
            });
-
 
1209
    }
-
 
1210
});
-
 
1211
 
-
 
1212
$(document).on('click', '.approveGrnCorrectionBtn', function () {
-
 
1213
    var requestId = $(this).data('requestid');
-
 
1214
    var remarks = $('#approvalRemarks').val();
-
 
1215
 
-
 
1216
    if (confirm("Are you sure you want to APPROVE this correction request? This will apply the IMEI/qty changes.")) {
-
 
1217
        doPostAjaxRequestHandler(context + "/approveGrnCorrection?requestId=" + requestId + "&remarks=" + encodeURIComponent(remarks),
-
 
1218
            function (response) {
-
 
1219
                if (response == 'true') {
-
 
1220
                    alert("Correction approved and applied successfully");
-
 
1221
                    loadGrnCorrectionApproval("main-content");
-
 
1222
                }
-
 
1223
            });
-
 
1224
    }
-
 
1225
});
-
 
1226
 
-
 
1227
$(document).on('click', '.rejectGrnCorrectionBtn', function () {
-
 
1228
    var requestId = $(this).data('requestid');
-
 
1229
    var remarks = $('#approvalRemarks').val();
-
 
1230
 
-
 
1231
    if (!remarks || remarks.trim() === '') {
-
 
1232
        alert("Please enter remarks explaining the reason for rejection");
-
 
1233
        return false;
-
 
1234
    }
-
 
1235
 
-
 
1236
    if (confirm("Are you sure you want to REJECT this correction request?")) {
-
 
1237
        doPostAjaxRequestHandler(context + "/rejectGrnCorrection?requestId=" + requestId + "&remarks=" + encodeURIComponent(remarks),
-
 
1238
            function (response) {
-
 
1239
                if (response == 'true') {
-
 
1240
                    alert("Correction request rejected");
-
 
1241
                    loadGrnCorrectionApproval("main-content");
-
 
1242
                }
-
 
1243
            });
-
 
1244
    }
-
 
1245
});
-
 
1246
 
-
 
1247
function loadGrnCorrection(domId) {
-
 
1248
    doGetAjaxRequestHandler(context + "/grnCorrection", function (response) {
-
 
1249
        $('#' + domId).html(response);
-
 
1250
    });
-
 
1251
}
-
 
1252
 
-
 
1253
function loadGrnCorrectionApproval(domId) {
-
 
1254
    doGetAjaxRequestHandler(context + "/grnCorrectionApproval", function (response) {
-
 
1255
        $('#' + domId).html(response);
-
 
1256
    });
-
 
1257
}
-
 
1258
 
-
 
1259
function loadGrnCorrectionDetail(invoiceId) {
-
 
1260
    doGetAjaxRequestHandler(context + "/grnCorrectionDetail?invoiceId=" + invoiceId, function (response) {
-
 
1261
        $('.grnCorrectionDetailContainer').html(response);
-
 
1262
    });
-
 
1263
}
-
 
1264
 
-
 
1265
function loadGrnCorrectionRequestDetail(requestId) {
-
 
1266
    doGetAjaxRequestHandler(context + "/grnCorrectionRequestDetail?requestId=" + requestId, function (response) {
-
 
1267
        $('.grnCorrectionRequestDetailContainer').html(response);
-
 
1268
    });
-
 
1269
}
-
 
1270
 
-
 
1271