fix: preserve Turkish decimal prices and verify preparation persistence
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
// Preserve typed input; never delete a decimal separator and change its value.
|
||||
export function parseBidPrice(value) {
|
||||
if (typeof value === 'number') return Number.isFinite(value) && value >= 0 ? value : null;
|
||||
const text = String(value ?? '').trim();
|
||||
const plain = /^\d+(?:[.,]\d{1,8})?$/;
|
||||
const groupedTurkish = /^\d{1,3}(?:\.\d{3})+,\d{1,8}$/;
|
||||
if (!plain.test(text) && !groupedTurkish.test(text)) return null;
|
||||
const normalized = text.includes(',') ? text.replace(/\./g,'').replace(',','.') : text;
|
||||
const result = Number(normalized);
|
||||
return Number.isFinite(result) ? result : null;
|
||||
}
|
||||
export function quantityParts(value) {
|
||||
if (typeof value === 'number') return {miktar:Number.isFinite(value) ? value : null,birim:''};
|
||||
const match = /^\s*([+-]?[\d]+(?:[.,]\d+)*)\s+(.+?)\s*$/.exec(String(value || ''));
|
||||
@@ -11,8 +22,9 @@ export function quantityParts(value) {
|
||||
export const roundMoney = n => Math.round((n + Number.EPSILON) * 100) / 100;
|
||||
export function bidRowTotal(row) {
|
||||
const {miktar} = quantityParts(row.quantity);
|
||||
const price = Number(row.birimFiyat);
|
||||
return miktar > 0 && Number.isFinite(price) && price > 0 ? roundMoney(miktar * price) : null;
|
||||
const price = parseBidPrice(row.birimFiyat);
|
||||
const total = miktar * price;
|
||||
return miktar > 0 && price > 0 && Number.isFinite(total) && total <= Number.MAX_SAFE_INTEGER / 100 ? roundMoney(total) : null;
|
||||
}
|
||||
export function validateBidRows(rows) {
|
||||
if (!rows.length) return ['Resmi teklif cetvelindeki kalemler eksik.'];
|
||||
|
||||
Reference in New Issue
Block a user