Subversion Repositories SmartDukaan

Rev

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

Rev 35884 Rev 36206
Line 1170... Line 1170...
1170
        }
1170
        }
1171
    });
1171
    });
1172
 
1172
 
1173
    // Collect item corrections (serialized or non-serialized)
1173
    // Collect item corrections (serialized or non-serialized)
1174
    var qtyCorrections = [];
1174
    var qtyCorrections = [];
-
 
1175
    var imeiCountError = false;
1175
    $('#qty-corrections-table > tbody > tr').each(function () {
1176
    $('#qty-corrections-table > tbody > tr').each(function () {
1176
        var oldItemId = $(this).find('.qty-old-itemid').val();
1177
        var oldItemId = $(this).find('.qty-old-itemid').val();
1177
        var newItemId = $(this).find('.qty-new-itemid').val();
1178
        var newItemId = $(this).find('.qty-new-itemid').val();
1178
        var serial = $(this).find('.qty-serial').val();
1179
        var serial = $(this).find('.qty-serial').val();
1179
        var qty = parseInt($(this).find('.qty-correction-val').val());
1180
        var qty = parseInt($(this).find('.qty-correction-val').val());
1180
 
1181
 
1181
        // For serialized items with IMEI, default qty to 1
-
 
1182
        if (oldItemId && newItemId && serial && serial.trim() !== '') {
1182
        if (oldItemId && newItemId && serial && serial.trim() !== '') {
-
 
1183
            // Split IMEIs by space, comma, or newline
-
 
1184
            var imeis = serial.trim().split(/[\s,]+/).filter(function(s) { return s.length > 0; });
-
 
1185
            var imeiCount = imeis.length;
-
 
1186
 
-
 
1187
            // Auto-set qty from IMEI count, validate if qty was manually entered
-
 
1188
            if (qty > 0 && qty !== imeiCount) {
-
 
1189
                alert("Row error: Qty (" + qty + ") does not match IMEI count (" + imeiCount + ").\nIMEIs: " + imeis.join(", "));
-
 
1190
                imeiCountError = true;
-
 
1191
                return false;
-
 
1192
            }
-
 
1193
 
-
 
1194
            // Create one entry per IMEI (each with qty=1)
-
 
1195
            for (var i = 0; i < imeis.length; i++) {
1183
            qtyCorrections.push({
1196
                qtyCorrections.push({
1184
                oldItemId: parseInt(oldItemId),
1197
                    oldItemId: parseInt(oldItemId),
1185
                newItemId: parseInt(newItemId),
1198
                    newItemId: parseInt(newItemId),
1186
                qty: qty > 0 ? qty : 1,
1199
                    qty: 1,
1187
                serialNumber: serial.trim()
1200
                    serialNumber: imeis[i].trim()
-
 
1201
                });
1188
            });
1202
            }
1189
        } else if (oldItemId && newItemId && qty > 0) {
1203
        } else if (oldItemId && newItemId && qty > 0) {
1190
            qtyCorrections.push({
1204
            qtyCorrections.push({
1191
                oldItemId: parseInt(oldItemId),
1205
                oldItemId: parseInt(oldItemId),
1192
                newItemId: parseInt(newItemId),
1206
                newItemId: parseInt(newItemId),
1193
                qty: qty
1207
                qty: qty
1194
            });
1208
            });
1195
        }
1209
        }
1196
    });
1210
    });
1197
 
1211
 
-
 
1212
    if (imeiCountError) return false;
-
 
1213
 
1198
    if (corrections.length === 0 && qtyCorrections.length === 0) {
1214
    if (corrections.length === 0 && qtyCorrections.length === 0) {
1199
        alert("No corrections specified. Please enter serial number or quantity corrections.");
1215
        alert("No corrections specified. Please enter serial number or quantity corrections.");
1200
        return false;
1216
        return false;
1201
    }
1217
    }
1202
 
1218