Spaces:
Running
Running
Upload qr-payment.js
Browse files- qr-payment.js +11 -8
qr-payment.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
/* V.AI STUDIO — QR Payment / Quote Data v1037.
|
|
|
|
| 2 |
* FIX v1037.4: Skip note patterns (BẢO HÀNH X NĂM, giao thứ X) khỏi fees/phụ phí
|
| 3 |
-
* Chỉ thêm vào fees nếu label là phí đã biết (giao hàng, lắp đặt, cọc, bốc xếp)
|
| 4 |
* FIX v1037.3: Thêm CORS proxy fallback wsrv.nl cho ảnh trong Excel
|
| 5 |
* FIX v1037.2: parsePrompt() extract brand discount, formula =G*0.65
|
| 6 |
* FIX v1037.1: Loại bỏ dòng CK/giá trị số (35đ, 50đ) khỏi fees
|
|
@@ -88,17 +88,20 @@ function parsePrompt(text){
|
|
| 88 |
if(priceUnit&&line.replace(/[\d.,\s%\knhìnghintrriệuđdvnđvndKHTRML]/gi,'').trim().length<2){notes.push(line);return;}
|
| 89 |
var brandNum=line.match(/^(malloca|eurogold|grob|canzy|demax|hafele|garis|boss)\b.*[\d.,]/i);
|
| 90 |
if(brandNum){var textAfterBrand=line.replace(/^(malloca|eurogold|grob|canzy|demax|hafele|garis|boss)/i,'').trim();if(textAfterBrand.match(/^[\d.,\s%(k|nghìn|nghin|tr|triệu|m|đ|d|vnd)]+$/i)){notes.push(line);return;}}
|
| 91 |
-
// === FIX v1037.
|
| 92 |
var lo_check=stripDiacritics(line).toLowerCase();
|
|
|
|
| 93 |
// Bảo hành X năm/tháng là ghi chú, ko phải phụ phí
|
| 94 |
-
if(lo_check.match(/bao hanh\s*\d+\s*(nam|thang)/)){notes.push(line);
|
| 95 |
// Giao thứ X / giao ngày X là lịch giao hàng, ko phải phí
|
| 96 |
-
if(lo_check.match(/giao\s+(thu|ngay)\s*\d+/)){notes.push(line);
|
| 97 |
// Các ghi chú bảo hành khác
|
| 98 |
-
if(lo_check.match(/\b(nam|thang)\s*(bao hanh|bh)/)||lo_check.match(/bao hanh\s+chinh\s*hang/)){notes.push(line);
|
|
|
|
|
|
|
| 99 |
// === End note skip ===
|
| 100 |
var m=line.match(/([\d.,]+)\s*(k|K|nghìn|nghin|triệu|tr|đ|d|vnd)?/);
|
| 101 |
-
if(m){var amt=parseFloat(m[1].replace(/\./g,'').replace(',','.'));var u=(m[2]||'').toLowerCase();if(u==='k'||u==='nghìn'||u==='nghin')amt*=1000;if(u==='triệu'||u==='tr')amt*=1000000;if(amt<=0){notes.push(line);return;}var lb=line.replace(m[0],'').trim();if(lb.match(/^(phi\s*giao|giao\s+hàng|ship)/i))lb='Phí giao hàng';else if(lb.match(/^(phi\s*lap|lap\s*dat|install)/i))lb='Phí lắp đặt';else if(lb.match(/^(phi\s*boc|bốc|boc|xế.p|xep|vác)/i))lb='Phí bốc xếp';else if(lb.match(/^(coc|dat.coc|deposit)/i))lb='Tiền cọc';else if(!lb||lb.length<2)lb='Phụ phí';else
|
| 102 |
else{notes.push(line);}
|
| 103 |
});
|
| 104 |
return{fees:fees,notes:notes,discount:discount,deposit:deposit,discountPercent:discountPercent,itemDiscounts:itemDiscounts};
|
|
@@ -196,7 +199,7 @@ function doOverride(){
|
|
| 196 |
window.exportDeliveryExcel=async function(){if(typeof ExcelJS==='undefined')return;var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryExcel(qd,code);};
|
| 197 |
window.exportDeliveryPDF=async function(){var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryPDF(qd,code);};
|
| 198 |
window.getQuoteData=function(){var qd=window._origGetQuoteData.apply(this,arguments);if(qd.customer)qd.customer.orderCode=getEffectiveOrderCode();return qd;};
|
| 199 |
-
console.log('✅ QR Payment v1037.
|
| 200 |
}
|
| 201 |
|
| 202 |
async function _doExportPDF(d,code){
|
|
|
|
| 1 |
+
/* V.AI STUDIO — QR Payment / Quote Data v1037.5
|
| 2 |
+
* FIX v1037.5: Khôi phục phụ phí - mọi text có số đều thành Phụ phí, ko đẩy vào notes
|
| 3 |
* FIX v1037.4: Skip note patterns (BẢO HÀNH X NĂM, giao thứ X) khỏi fees/phụ phí
|
|
|
|
| 4 |
* FIX v1037.3: Thêm CORS proxy fallback wsrv.nl cho ảnh trong Excel
|
| 5 |
* FIX v1037.2: parsePrompt() extract brand discount, formula =G*0.65
|
| 6 |
* FIX v1037.1: Loại bỏ dòng CK/giá trị số (35đ, 50đ) khỏi fees
|
|
|
|
| 88 |
if(priceUnit&&line.replace(/[\d.,\s%\knhìnghintrriệuđdvnđvndKHTRML]/gi,'').trim().length<2){notes.push(line);return;}
|
| 89 |
var brandNum=line.match(/^(malloca|eurogold|grob|canzy|demax|hafele|garis|boss)\b.*[\d.,]/i);
|
| 90 |
if(brandNum){var textAfterBrand=line.replace(/^(malloca|eurogold|grob|canzy|demax|hafele|garis|boss)/i,'').trim();if(textAfterBrand.match(/^[\d.,\s%(k|nghìn|nghin|tr|triệu|m|đ|d|vnd)]+$/i)){notes.push(line);return;}}
|
| 91 |
+
// === FIX v1037.5: Skip note patterns nhưng KHÔNG chặn fee detection ===
|
| 92 |
var lo_check=stripDiacritics(line).toLowerCase();
|
| 93 |
+
var isNotePattern=false;
|
| 94 |
// Bảo hành X năm/tháng là ghi chú, ko phải phụ phí
|
| 95 |
+
if(lo_check.match(/bao hanh\s*\d+\s*(nam|thang)/)){notes.push(line);isNotePattern=true;}
|
| 96 |
// Giao thứ X / giao ngày X là lịch giao hàng, ko phải phí
|
| 97 |
+
if(!isNotePattern&&lo_check.match(/giao\s+(thu|ngay)\s*\d+/)){notes.push(line);isNotePattern=true;}
|
| 98 |
// Các ghi chú bảo hành khác
|
| 99 |
+
if(!isNotePattern&&(lo_check.match(/\b(nam|thang)\s*(bao hanh|bh)/)||lo_check.match(/bao hanh\s+chinh\s*hang/))){notes.push(line);isNotePattern=true;}
|
| 100 |
+
// Nếu đã là note pattern thì skip không xử lý fee nữa
|
| 101 |
+
if(isNotePattern)return;
|
| 102 |
// === End note skip ===
|
| 103 |
var m=line.match(/([\d.,]+)\s*(k|K|nghìn|nghin|triệu|tr|đ|d|vnd)?/);
|
| 104 |
+
if(m){var amt=parseFloat(m[1].replace(/\./g,'').replace(',','.'));var u=(m[2]||'').toLowerCase();if(u==='k'||u==='nghìn'||u==='nghin')amt*=1000;if(u==='triệu'||u==='tr')amt*=1000000;if(amt<=0){notes.push(line);return;}var lb=line.replace(m[0],'').trim();if(lb.match(/^(phi\s*giao|giao\s+hàng|ship)/i))lb='Phí giao hàng';else if(lb.match(/^(phi\s*lap|lap\s*dat|install)/i))lb='Phí lắp đặt';else if(lb.match(/^(phi\s*boc|bốc|boc|xế.p|xep|vác)/i))lb='Phí bốc xếp';else if(lb.match(/^(coc|dat.coc|deposit)/i))lb='Tiền cọc';else if(!lb||lb.length<2)lb='Phụ phí';else lb='Phụ phí';fees.push({label:lb,amount:amt});}
|
| 105 |
else{notes.push(line);}
|
| 106 |
});
|
| 107 |
return{fees:fees,notes:notes,discount:discount,deposit:deposit,discountPercent:discountPercent,itemDiscounts:itemDiscounts};
|
|
|
|
| 199 |
window.exportDeliveryExcel=async function(){if(typeof ExcelJS==='undefined')return;var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryExcel(qd,code);};
|
| 200 |
window.exportDeliveryPDF=async function(){var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryPDF(qd,code);};
|
| 201 |
window.getQuoteData=function(){var qd=window._origGetQuoteData.apply(this,arguments);if(qd.customer)qd.customer.orderCode=getEffectiveOrderCode();return qd;};
|
| 202 |
+
console.log('✅ QR Payment v1037.5 — Restored surcharge detection, skip note patterns');return true;
|
| 203 |
}
|
| 204 |
|
| 205 |
async function _doExportPDF(d,code){
|