From dbbc416676d39833e444caab363b01d1b87d6208 Mon Sep 17 00:00:00 2001 From: pavlov346346-source Date: Fri, 11 Sep 2026 13:19:24 +0300 Subject: [PATCH] Fix incorrect order totals from hidden orphan lines * chore: add one-time order total repair * fix: exclude hidden orphan lines from totals [order-total-fix] --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/fix-order-total-v1774.yml | 42 +++++++++++++++++++++ public/index.html | 4 +- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fix-order-total-v1774.yml diff --git a/.github/workflows/fix-order-total-v1774.yml b/.github/workflows/fix-order-total-v1774.yml new file mode 100644 index 0000000..9232746 --- /dev/null +++ b/.github/workflows/fix-order-total-v1774.yml @@ -0,0 +1,42 @@ +name: Caterium One-Time Order Total Fix +on: + push: + branches: ["fix/order-total-orphan-lines-v1774"] +permissions: + contents: write +jobs: + repair: + if: ${{ !contains(github.event.head_commit.message, '[order-total-fix]') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: fix/order-total-orphan-lines-v1774 + fetch-depth: 0 + - name: Exclude hidden orphan order lines from totals + shell: bash + run: | + node <<'NODE' + const fs=require('fs'); + const path='public/index.html'; + let src=fs.readFileSync(path,'utf8'); + const from1="calcOrderTotal=function(){return (draft.lines||[]).reduce((sum,line)=>sum+unitPrice(line)*Math.max(0,Number(line.qty||0)),0)};"; + const to1="calcOrderTotal=function(){return (draft.lines||[]).reduce((sum,line)=>itemById(line.id)?sum+unitPrice(line)*Math.max(0,Number(line.qty||0)):sum,0)};"; + const from2="orderTotalValue=function(order){return (order?.lines||[]).reduce((sum,line)=>sum+unitPrice(line)*Math.max(0,Number(line.qty||0)),0)};"; + const to2="orderTotalValue=function(order){return (order?.lines||[]).reduce((sum,line)=>itemById(line.id)?sum+unitPrice(line)*Math.max(0,Number(line.qty||0)):sum,0)};"; + for(const [from,to] of [[from1,to1],[from2,to2]]){ + const count=src.split(from).length-1; + if(count!==1) throw new Error(`Expected exactly one target occurrence, found ${count}`); + src=src.replace(from,to); + } + fs.writeFileSync(path,src); + NODE + - name: Commit total fix + shell: bash + run: | + set -euo pipefail + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add public/index.html + git commit -m "fix: exclude hidden orphan lines from totals [order-total-fix]" + git push origin HEAD:fix/order-total-orphan-lines-v1774 diff --git a/public/index.html b/public/index.html index 97f69cc..17cef58 100644 --- a/public/index.html +++ b/public/index.html @@ -7149,8 +7149,8 @@ body.sun-splitting *{cursor:col-resize!important} pane?.classList.add('sun-order-pane'); // Correct calculations: custom per-order item price is preferred over catalog price. - calcOrderTotal=function(){return (draft.lines||[]).reduce((sum,line)=>sum+unitPrice(line)*Math.max(0,Number(line.qty||0)),0)}; - orderTotalValue=function(order){return (order?.lines||[]).reduce((sum,line)=>sum+unitPrice(line)*Math.max(0,Number(line.qty||0)),0)}; + calcOrderTotal=function(){return (draft.lines||[]).reduce((sum,line)=>itemById(line.id)?sum+unitPrice(line)*Math.max(0,Number(line.qty||0)):sum,0)}; + orderTotalValue=function(order){return (order?.lines||[]).reduce((sum,line)=>itemById(line.id)?sum+unitPrice(line)*Math.max(0,Number(line.qty||0)):sum,0)}; updateOrderSummary=function(){ const total=calcOrderTotal(),paid=Math.max(0,Number(prepayment.value||0)),rest=Math.max(0,total-paid); orderTotal.value=Math.round(total);balance.value=Math.round(rest);