bep40 commited on
Commit
e37f787
·
verified ·
1 Parent(s): 31cf243

fix parsePrompt: Malloca ck 35% discount, ghi chú: giao thứ 7 → note, small ordinal numbers skipped

Browse files
Files changed (1) hide show
  1. qr-payment.js +21 -6
qr-payment.js CHANGED
@@ -1,6 +1,7 @@
1
- /* V.AI STUDIO — QR Payment / Quote Data v1038
2
- * FIX: Excel images now use fetch+cache-busting instead of DOM canvas (which taints)
3
- * Because bizweb.dktcdn.net supports CORS, fetch() with cache-bust works reliably
 
4
  */
5
  (function(){
6
  'use strict';
@@ -56,9 +57,16 @@ function parsePrompt(text){
56
  if(!text)return{fees:fees,notes:notes,discount:discount,deposit:deposit,discountPercent:discountPercent,itemDiscounts:itemDiscounts};
57
  text.split(/[,;\n]+/).forEach(function(line){
58
  line=line.trim();if(!line)return;
 
 
 
 
 
 
59
  parseItemDiscountLine(line,itemDiscounts);
60
  if(Object.keys(itemDiscounts).length&&line.match(/\b[A-Za-z]{1,8}[A-Za-z0-9._\-\/]{1,30}\d[A-Za-z0-9._\-\/]*\b/i)&&line.match(/\b(ck|chiết khấu|chiet khau|giảm|giam|discount)\b/i))return;
61
- if(line.match(/^(ck|chiết khấu|chiet khau|giảm|giam|discount)/i)){
 
62
  discount=line;
63
  var ckm=line.match(/([\d.,]+)\s*(%)?/);
64
  if(ckm){var v=parseFloat(ckm[1].replace(/\./g,'').replace(',','.'));if(v>0&&v<=100)discountPercent=v;}
@@ -69,8 +77,15 @@ function parsePrompt(text){
69
  if(dm){var da=parseFloat(dm[1].replace(/\./g,'').replace(',','.'));var du=(dm[2]||'').toLowerCase();if(du==='k'||du==='nghìn'||du==='nghin')da*=1000;if(du==='triệu'||du==='tr')da*=1000000;deposit=da;}
70
  return;
71
  }
 
72
  var m=line.match(/([\d.,]+)\s*(k|K|nghìn|nghin|triệu|tr|đ|d|vnd)?/);
73
- 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)return;var lb=line.replace(m[0],'').trim();if(lb.match(/giao|ship|vận chuyển|delivery/i))lb='Phí giao hàng';else if(lb.match(/lắp|lap|install/i))lb='Phí lắp đặt';else if(lb.match(/bốc|boc|xếp|xep|vác/i))lb='Phí bốc xếp';else if(!lb||lb.length<2)lb='Phụ phí';fees.push({label:lb,amount:amt});}
 
 
 
 
 
 
74
  else{notes.push(line);}
75
  });
76
  return{fees:fees,notes:notes,discount:discount,deposit:deposit,discountPercent:discountPercent,itemDiscounts:itemDiscounts};
@@ -184,7 +199,7 @@ function doOverride(){
184
  window.exportDeliveryExcel=async function(){if(typeof ExcelJS==='undefined')return;var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryExcel(qd,code);};
185
  window.exportDeliveryPDF=async function(){var qd=window._origGetQuoteData(),code=getEffectiveOrderCode();await _doExportDeliveryPDF(qd,code);};
186
  window.getQuoteData=function(){var qd=window._origGetQuoteData.apply(this,arguments);if(qd.customer)qd.customer.orderCode=getEffectiveOrderCode();return qd;};
187
- console.log('✅ QR Payment v1038 — fetch+CORS images, Excel images fixed');return true;
188
  }
189
 
190
  async function _doExportPDF(d,code){
 
1
+ /* V.AI STUDIO — QR Payment / Quote Data v1039
2
+ * FIX: parsePrompt — 'Malloca ck 35%' now correctly detected as global discount;
3
+ * 'ghi chú: giao thứ 7' treated as note, not a 7đ fee;
4
+ * small numbers with ordinal/date context (thứ, ngày, giờ) = note, not fee
5
  */
6
  (function(){
7
  'use strict';
 
57
  if(!text)return{fees:fees,notes:notes,discount:discount,deposit:deposit,discountPercent:discountPercent,itemDiscounts:itemDiscounts};
58
  text.split(/[,;\n]+/).forEach(function(line){
59
  line=line.trim();if(!line)return;
60
+ // FIX: detect 'ghi chú:' / 'note:' prefix → rest is a note (skip all number matching)
61
+ if(line.match(/^(ghi chú|ghichu|note|notes)\s*[:\-]?\s*/i)){
62
+ var nt=line.replace(/^(ghi chú|ghichu|note|notes)\s*[:\-]?\s*/i,'');
63
+ if(nt) notes.push(nt);
64
+ return;
65
+ }
66
  parseItemDiscountLine(line,itemDiscounts);
67
  if(Object.keys(itemDiscounts).length&&line.match(/\b[A-Za-z]{1,8}[A-Za-z0-9._\-\/]{1,30}\d[A-Za-z0-9._\-\/]*\b/i)&&line.match(/\b(ck|chiết khấu|chiet khau|giảm|giam|discount)\b/i))return;
68
+ // FIX: also match 'WORD ck X%' (e.g. 'Malloca ck 35%') — global discount
69
+ if(line.match(/^(ck|chiết khấu|chiet khau|giảm|giam|discount)/i) || line.match(/\bck\s*[\d.,]+\s*%/i)){
70
  discount=line;
71
  var ckm=line.match(/([\d.,]+)\s*(%)?/);
72
  if(ckm){var v=parseFloat(ckm[1].replace(/\./g,'').replace(',','.'));if(v>0&&v<=100)discountPercent=v;}
 
77
  if(dm){var da=parseFloat(dm[1].replace(/\./g,'').replace(',','.'));var du=(dm[2]||'').toLowerCase();if(du==='k'||du==='nghìn'||du==='nghin')da*=1000;if(du==='triệu'||du==='tr')da*=1000000;deposit=da;}
78
  return;
79
  }
80
+ // FIX: number match — skip lines that look like dates/ordinals (e.g. 'thứ 7')
81
  var m=line.match(/([\d.,]+)\s*(k|K|nghìn|nghin|triệu|tr|đ|d|vnd)?/);
82
+ if(m){
83
+ 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)return;
84
+ // FIX: small numbers (<1000, no unit) with context words → note, not fee
85
+ var lb=line.replace(m[0],'').trim();
86
+ if(amt<1000&&!u&&lb.match(/thứ|ngày|giờ|tuần|tháng|năm|lúc/i)){notes.push(line);return;}
87
+ if(lb.match(/giao|ship|vận chuyển|delivery/i))lb='Phí giao hàng';else if(lb.match(/lắp|lap|install/i))lb='Phí lắp đặt';else if(lb.match(/bốc|boc|xếp|xep|vác/i))lb='Phí bốc xếp';else if(!lb||lb.length<2)lb='Phụ phí';fees.push({label:lb,amount:amt});
88
+ }
89
  else{notes.push(line);}
90
  });
91
  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 v1039 — parsePrompt fixed: ghi chú, Malloca ck 35%, thứ 7');return true;
203
  }
204
 
205
  async function _doExportPDF(d,code){