feat: Ajuste Fino priced per art, with the offer under each Prumo warning (Marcus 10/11, point 1)
The designer treatment becomes Ajuste Fino, priced per art with a batch band set in the Site tab (e.g. R$ 9,90, from 10 arts R$ 6,90). Under each art the Prumo warns about, the Site offers 'Quer que um designer resolva? Ajuste Fino'; the cart keeps 'Ajuste Fino em todas as artes'. The server counts the chosen arts, Tiny gets the line with that quantity, the card shows 'Ajuste Fino · N artes'. Old carts asking the treatment for the whole order keep working. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
which defines api, may, money, when, say, node and button.
|
||||
A price is history: one that has started is never changed or deleted, so
|
||||
only a scheduled (future) price may be cancelled. */
|
||||
const SITE_UNIT_LABEL={metro:' /m',pedido:' por pedido'};
|
||||
const SITE_UNIT_LABEL={metro:' /m',pedido:' por pedido',arte:' por arte'};
|
||||
|
||||
// Reais with a comma, as the Site shows them: "19,90" is 1990 cents.
|
||||
function moneyInputCents(value){
|
||||
@@ -18,10 +18,11 @@ function moneyInputCents(value){
|
||||
// A price that already started is refused by the server (409).
|
||||
const cancelScheduledPrice=id=>api('/site/prices/'+id+'/cancel',{});
|
||||
|
||||
// "5" or "5,5": a band's start in metres, as the table reads it.
|
||||
// "5" or "5,5": a band's start, in metres or arts, as the table reads it.
|
||||
function bandMetres(value){return String(Number(value)).replace('.',',');}
|
||||
function bandsText(bands){
|
||||
return (bands||[]).map(band=>' · '+bandMetres(band.from_metres)+' m: '+money(band.unit_cents)).join('');
|
||||
function bandsText(bands,unit='metro'){
|
||||
return (bands||[]).map(band=>' · '+bandMetres(band.from_metres)+' '+
|
||||
(unit==='arte'?(Number(band.from_metres)===1?'arte':'artes'):'m')+': '+money(band.unit_cents)).join('');
|
||||
}
|
||||
|
||||
function siteProductRow(product){
|
||||
@@ -66,17 +67,18 @@ function sitePriceBlock(product){
|
||||
starts.setAttribute('aria-label','Quando o novo preço de '+product.title+' começa');
|
||||
startsLabel.append(starts);
|
||||
// Faixas progressivas (front 8.2): a nova tabela começa vazia; as faixas
|
||||
// viajam com este preço. O tratamento é um valor por pedido, sem faixas.
|
||||
// viajam com este preço. Ajuste Fino conta as faixas em artes, os produtos em metros.
|
||||
const bandUnit=product.unit==='arte'?'artes':'m';
|
||||
const bandRows=node('div',undefined,'siteBandRows');
|
||||
const addBand=node('button','Adicionar faixa','btn ghost');addBand.type='button';
|
||||
const paintAdd=()=>{addBand.disabled=bandRows.children.length>=5;};
|
||||
const bandRow=()=>{
|
||||
const row=node('div',undefined,'siteBandRow');
|
||||
const fromLabel=node('label');fromLabel.append(node('span','A partir de (m)'));
|
||||
const fromLabel=node('label');fromLabel.append(node('span','A partir de ('+bandUnit+')'));
|
||||
const from=node('input');from.type='text';from.inputMode='decimal';from.className='siteBandFrom';
|
||||
from.setAttribute('aria-label','Metragem da faixa de '+product.title);
|
||||
from.setAttribute('aria-label','Início da faixa em '+bandUnit+' de '+product.title);
|
||||
fromLabel.append(from);
|
||||
const priceLabel=node('label');priceLabel.append(node('span','R$ por metro'));
|
||||
const priceLabel=node('label');priceLabel.append(node('span','R$ por '+(product.unit==='arte'?'arte':'metro')));
|
||||
const bandPrice=node('input');bandPrice.type='text';bandPrice.inputMode='decimal';bandPrice.className='siteBandPrice';
|
||||
bandPrice.setAttribute('aria-label','Preço da faixa de '+product.title);
|
||||
priceLabel.append(bandPrice);
|
||||
@@ -93,7 +95,7 @@ function sitePriceBlock(product){
|
||||
const from=Number(row.querySelector('.siteBandFrom').value.replace(',','.'));
|
||||
const unit=moneyInputCents(row.querySelector('.siteBandPrice').value);
|
||||
if(!Number.isFinite(from)||from<=0||unit===null||unit<=0)
|
||||
throw new Error('Confira as faixas: metragem e preço maiores que zero.');
|
||||
throw new Error('Confira as faixas: início e preço maiores que zero.');
|
||||
return {from_metres:String(from),unit_cents:unit};
|
||||
});
|
||||
const save=button('Salvar',async()=>{
|
||||
@@ -103,18 +105,17 @@ function sitePriceBlock(product){
|
||||
if(whenDate&&Number.isNaN(whenDate.getTime()))throw new Error('Data inválida.');
|
||||
await api('/site/products/'+product.id+'/prices',
|
||||
{unit_cents:cents,starts_at:whenDate?whenDate.toISOString():null,
|
||||
bands:product.id==='tratamento'?[]:formBands()});
|
||||
bands:formBands()});
|
||||
say(whenDate?'Preço salvo para '+when(whenDate)+'.':'Preço salvo. Vale a partir de agora.');
|
||||
await loadSiteAdmin();
|
||||
},'btn pri');
|
||||
form.append(priceLabel,startsLabel,save);
|
||||
if(product.id!=='tratamento')form.append(bands);
|
||||
form.append(priceLabel,startsLabel,save,bands);
|
||||
|
||||
const scheduled=node('div',undefined,'siteScheduled');
|
||||
if(product.scheduled.length){
|
||||
for(const row of product.scheduled){
|
||||
const line=node('div',undefined,'siteScheduledRow');
|
||||
line.append(node('span',money(row.unit_cents)+SITE_UNIT_LABEL[product.unit]+bandsText(row.bands)+
|
||||
line.append(node('span',money(row.unit_cents)+SITE_UNIT_LABEL[product.unit]+bandsText(row.bands,product.unit)+
|
||||
' a partir de '+when(row.starts_at)));
|
||||
line.append(button('Cancelar',async()=>{
|
||||
await cancelScheduledPrice(row.id);
|
||||
@@ -132,7 +133,7 @@ function sitePriceBlock(product){
|
||||
const body=node('tbody');
|
||||
for(const row of product.history){
|
||||
const tr=node('tr');
|
||||
tr.append(node('td',money(row.unit_cents)+bandsText(row.bands),'nowrap'),node('td',when(row.starts_at),'nowrap'),
|
||||
tr.append(node('td',money(row.unit_cents)+bandsText(row.bands,product.unit),'nowrap'),node('td',when(row.starts_at),'nowrap'),
|
||||
node('td',row.created_by),node('td',when(row.created_at),'nowrap'));
|
||||
body.append(tr);
|
||||
}
|
||||
@@ -188,7 +189,7 @@ async function loadGradeRules(){
|
||||
ensureGradePanel();
|
||||
const data=await api('/site/grade-rules');
|
||||
const aviso=gradeRuleRow('Avisar o designer abaixo de',data.aviso);
|
||||
const tratamento=gradeRuleRow('Exigir o tratamento abaixo de',data.tratamento);
|
||||
const tratamento=gradeRuleRow('Exigir o Ajuste Fino abaixo de',data.tratamento);
|
||||
const save=button('Salvar',async()=>{
|
||||
const avisoValue=aviso.on.checked?Number(aviso.num.value):null;
|
||||
const tratamentoValue=tratamento.on.checked?Number(tratamento.num.value):null;
|
||||
@@ -196,14 +197,14 @@ async function loadGradeRules(){
|
||||
if(value!==null&&(!Number.isInteger(value)||value<1||value>100))
|
||||
throw new Error('A nota vai de 1 a 100.');
|
||||
if(avisoValue!==null&&tratamentoValue!==null&&tratamentoValue>avisoValue)
|
||||
throw new Error('A regra do tratamento precisa ser menor ou igual à do aviso.');
|
||||
throw new Error('A regra do Ajuste Fino precisa ser menor ou igual à do aviso.');
|
||||
await api('/site/grade-rules',{aviso:avisoValue,tratamento:tratamentoValue});
|
||||
say('Regras da nota da arte salvas.');
|
||||
await loadGradeRules();
|
||||
},'btn pri');
|
||||
const children=[aviso.row,tratamento.row];
|
||||
if(!data.treatment_offered)
|
||||
children.push(node('p','Ative e dê preço ao Tratamento pelo designer para esta regra valer.','siteGradeWarn'));
|
||||
children.push(node('p','Ative e dê preço ao Ajuste Fino para esta regra valer.','siteGradeWarn'));
|
||||
const foot=node('div',undefined,'siteGradeSave');foot.append(save);children.push(foot);
|
||||
$('site-grade-body').replaceChildren(...children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user