node:internal/modules/cjs/loader:1210
  throw err;
  ^

Error: Cannot find module 'dotenv'
Require stack:
- /home/zaistsnv/api.zaishapos.org/dist/index.js
- /home/zaistsnv/api.zaishapos.org/app.js
- /usr/local/lsws/fcgi-bin/lsnode.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1207:15)
    at Module._load (node:internal/modules/cjs/loader:1038:27)
    at Module.require (node:internal/modules/cjs/loader:1289:19)
    at require (node:internal/modules/helpers:182:18)
    at Object.<anonymous> (/home/zaistsnv/api.zaishapos.org/dist/index.js:1:5171)
    at Module._compile (node:internal/modules/cjs/loader:1521:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at Module.require (node:internal/modules/cjs/loader:1289:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/zaistsnv/api.zaishapos.org/dist/index.js',
    '/home/zaistsnv/api.zaishapos.org/app.js',
    '/usr/local/lsws/fcgi-bin/lsnode.js'
  ]
}

Node.js v20.20.2
node:internal/modules/cjs/loader:1210
  throw err;
  ^

Error: Cannot find module 'dotenv'
Require stack:
- /home/zaistsnv/api.zaishapos.org/dist/index.js
- /home/zaistsnv/api.zaishapos.org/app.js
- /usr/local/lsws/fcgi-bin/lsnode.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1207:15)
    at Module._load (node:internal/modules/cjs/loader:1038:27)
    at Module.require (node:internal/modules/cjs/loader:1289:19)
    at require (node:internal/modules/helpers:182:18)
    at Object.<anonymous> (/home/zaistsnv/api.zaishapos.org/dist/index.js:1:5171)
    at Module._compile (node:internal/modules/cjs/loader:1521:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at Module.require (node:internal/modules/cjs/loader:1289:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/zaistsnv/api.zaishapos.org/dist/index.js',
    '/home/zaistsnv/api.zaishapos.org/app.js',
    '/usr/local/lsws/fcgi-bin/lsnode.js'
  ]
}

Node.js v20.20.2
DrizzleQueryError: Failed query: select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    ... 4 lines matching cause stack trace ...
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
  query: 'select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "vendor_id" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async Promise.all (index 1)
      at async getSalonGallaBalances (/home/zaistsnv/api.zaishapos.org/dist/utils/ledger.js:37:8165)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:8058
      at async Promise.all (index 0)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
    length: 109,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '39',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    ... 4 lines matching cause stack trace ...
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
  query: 'select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "vendor_id" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async Promise.all (index 1)
      at async getSalonGallaBalances (/home/zaistsnv/api.zaishapos.org/dist/utils/ledger.js:37:8165)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:8058
      at async Promise.all (index 0)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
    length: 109,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '39',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    ... 4 lines matching cause stack trace ...
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
  query: 'select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "vendor_id" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async Promise.all (index 1)
      at async getSalonGallaBalances (/home/zaistsnv/api.zaishapos.org/dist/utils/ledger.js:37:8165)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:8058
      at async Promise.all (index 0)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
    length: 109,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '39',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    ... 4 lines matching cause stack trace ...
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
  query: 'select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "vendor_id" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async Promise.all (index 1)
      at async getSalonGallaBalances (/home/zaistsnv/api.zaishapos.org/dist/utils/ledger.js:37:8165)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:8058
      at async Promise.all (index 0)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
    length: 109,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '39',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    ... 4 lines matching cause stack trace ...
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
  query: 'select "id", "salon_id", "client_id", "vendor_id", "staff_id", "sale_id", "purchase_id", "salary_deduction_id", "expense_id", "type", "amount", "category", "notes", "person_name", "date", "created_at" from "ledger_entries" where "ledger_entries"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "vendor_id" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async Promise.all (index 1)
      at async getSalonGallaBalances (/home/zaistsnv/api.zaishapos.org/dist/utils/ledger.js:37:8165)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:8058
      at async Promise.all (index 0)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/salons.js:1:7928 {
    length: 109,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '39',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
DrizzleQueryError: Failed query: select "appointments"."id", "appointments"."salon_id", "appointments"."service_id", "appointments"."service_ids", "appointments"."service_details", "appointments"."staff_id", "appointments"."customer_name", "appointments"."customer_phone", "appointments"."appointment_time", "appointments"."status", "appointments"."notes", "appointments"."created_at", "appointments_service"."data" as "service", "appointments_staff"."data" as "staff" from "appointments" "appointments" left join lateral (select json_build_array("appointments_service"."id", "appointments_service"."salon_id", "appointments_service"."name", "appointments_service"."price", "appointments_service"."category", "appointments_service"."is_active", "appointments_service"."is_package", "appointments_service"."description", "appointments_service"."arabic_name", "appointments_service"."created_at", "appointments_service_bundleItems"."data") as "data" from (select * from "services" "appointments_service" where "appointments_service"."id" = "appointments"."service_id" limit $1) "appointments_service" left join lateral (select coalesce(json_agg(json_build_array("appointments_service_bundleItems"."id", "appointments_service_bundleItems"."package_id", "appointments_service_bundleItems"."service_id", "appointments_service_bundleItems"."price", "appointments_service_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "appointments_service_bundleItems" left join lateral (select json_build_array("appointments_service_bundleItems_service"."id", "appointments_service_bundleItems_service"."salon_id", "appointments_service_bundleItems_service"."name", "appointments_service_bundleItems_service"."price", "appointments_service_bundleItems_service"."category", "appointments_service_bundleItems_service"."is_active", "appointments_service_bundleItems_service"."is_package", "appointments_service_bundleItems_service"."description", "appointments_service_bundleItems_service"."arabic_name", "appointments_service_bundleItems_service"."created_at") as "data" from (select * from "services" "appointments_service_bundleItems_service" where "appointments_service_bundleItems_service"."id" = "appointments_service_bundleItems"."service_id" limit $2) "appointments_service_bundleItems_service") "appointments_service_bundleItems_service" on true where "appointments_service_bundleItems"."package_id" = "appointments_service"."id") "appointments_service_bundleItems" on true) "appointments_service" on true left join lateral (select json_build_array("appointments_staff"."id", "appointments_staff"."user_id", "appointments_staff"."salon_id", "appointments_staff"."name", "appointments_staff"."phone", "appointments_staff"."salary_type", "appointments_staff"."salary_value", "appointments_staff"."commission_percentage", "appointments_staff"."in_time_limit", "appointments_staff"."out_time_limit", "appointments_staff"."late_time_limit", "appointments_staff"."early_exit_time_limit", "appointments_staff"."late_deduction_rate", "appointments_staff"."early_exit_deduction_rate", "appointments_staff"."allowed_leaves", "appointments_staff"."joining_date", "appointments_staff"."created_at") as "data" from (select * from "staff" "appointments_staff" where "appointments_staff"."id" = "appointments"."staff_id" limit $3) "appointments_staff") "appointments_staff" on true where "appointments"."salon_id" = $4 order by "appointments"."appointment_time" asc
params: 1,1,1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/appointments.js:1:9940 {
  query: `select "appointments"."id", "appointments"."salon_id", "appointments"."service_id", "appointments"."service_ids", "appointments"."service_details", "appointments"."staff_id", "appointments"."customer_name", "appointments"."customer_phone", "appointments"."appointment_time", "appointments"."status", "appointments"."notes", "appointments"."created_at", "appointments_service"."data" as "service", "appointments_staff"."data" as "staff" from "appointments" "appointments" left join lateral (select json_build_array("appointments_service"."id", "appointments_service"."salon_id", "appointments_service"."name", "appointments_service"."price", "appointments_service"."category", "appointments_service"."is_active", "appointments_service"."is_package", "appointments_service"."description", "appointments_service"."arabic_name", "appointments_service"."created_at", "appointments_service_bundleItems"."data") as "data" from (select * from "services" "appointments_service" where "appointments_service"."id" = "appointments"."service_id" limit $1) "appointments_service" left join lateral (select coalesce(json_agg(json_build_array("appointments_service_bundleItems"."id", "appointments_service_bundleItems"."package_id", "appointments_service_bundleItems"."service_id", "appointments_service_bundleItems"."price", "appointments_service_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "appointments_service_bundleItems" left join lateral (select json_build_array("appointments_service_bundleItems_service"."id", "appointments_service_bundleItems_service"."salon_id", "appointments_service_bundleItems_service"."name", "appointments_service_bundleItems_service"."price", "appointments_service_bundleItems_service"."category", "appointments_service_bundleItems_service"."is_active", "appointments_service_bundleItems_service"."is_package", "appointments_service_bundleItems_service"."description", "appointments_service_bundleItems_service"."arabic_name", "appointments_service_bundleItems_service"."created_at") as "data" from (select * from "services" "appointments_service_bundleItems_service" where "appointments_service_bundleItems_service"."id" = "appointments_service_bundleItems"."service_id" limit $2) "appointments_service_bundleItems_service") "appointments_service_bundleItems_service" on true where "appointments_service_bundleItems"."package_id" = "appointments_service"."id") "appointments_service_bundleItems" on true) "appointments_service" on true left join lateral (select json_build_array("appointments_staff"."id", "appointments_staff"."user_id", "appointments_staff"."salon_id", "appointments_staff"."name", "appointments_staff"."phone", "appointments_staff"."salary_type", "appointments_staff"."salary_value", "appointments_staff"."commission_percentage", "appointments_staff"."in_time_limit", "appointments_staff"."out_time_limit", "appointments_staff"."late_time_limit", "appointments_staff"."early_exit_time_limit", "appointments_staff"."late_deduction_rate", "appointments_staff"."early_exit_deduction_rate", "appointments_staff"."allowed_leaves", "appointments_staff"."joining_date", "appointments_staff"."created_at") as "data" from (select * from "staff" "appointments_staff" where "appointments_staff"."id" = "appointments"."staff_id" limit $3) "appointments_staff") "appointments_staff" on true where "appointments"."salon_id" = $4 order by "appointments"."appointment_time" asc`,
  params: [ 1, 1, 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column appointments_service_bundleItems.price does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/appointments.js:1:9940 {
    length: 138,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '1267',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)
params: 1,8eb099be-7518-4950-9319-d5fa236007e6,true
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
  query: `select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)`,
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6', 'true' ],
  cause: error: column services_bundleItems.price does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
    length: 125,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '474',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: 
      SELECT 
        customer_phone,
        customer_name,
        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt
      FROM sales
      WHERE salon_id = $1::uuid AND status = 'ACTIVE'
      GROUP BY customer_phone, customer_name
    
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
  query: '\n' +
    '      SELECT \n' +
    '        customer_phone,\n' +
    '        customer_name,\n' +
    "        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt\n" +
    '      FROM sales\n' +
    "      WHERE salon_id = $1::uuid AND status = 'ACTIVE'\n" +
    '      GROUP BY customer_phone, customer_name\n' +
    '    ',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "customer_phone" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:148:20
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
    length: 114,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '24',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2
params: 1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
  query: 'select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2',
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
    length: 117,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '379',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
DrizzleQueryError: Failed query: select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)
params: 1,,true
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
  query: `select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)`,
  params: [ 1, undefined, 'true' ],
  cause: error: column services_bundleItems.price does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
    length: 125,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '474',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2
params: 1,
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
  query: 'select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2',
  params: [ 1, undefined ],
  cause: error: column staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
    length: 117,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '379',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: 
      SELECT 
        customer_phone,
        customer_name,
        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt
      FROM sales
      WHERE salon_id = ::uuid AND status = 'ACTIVE'
      GROUP BY customer_phone, customer_name
    
params: 
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
  query: '\n' +
    '      SELECT \n' +
    '        customer_phone,\n' +
    '        customer_name,\n' +
    "        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt\n" +
    '      FROM sales\n' +
    "      WHERE salon_id = ::uuid AND status = 'ACTIVE'\n" +
    '      GROUP BY customer_phone, customer_name\n' +
    '    ',
  params: [],
  cause: error: syntax error at or near "::"
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:148:20
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
    length: 92,
    severity: 'ERROR',
    code: '42601',
    detail: undefined,
    hint: undefined,
    position: '213',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'scan.l',
    line: '1127',
    routine: 'scanner_yyerror'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "name", "category", "amount", "date", "created_at" from "expenses" "expenses" where "expenses"."salon_id" = $1 order by "expenses"."date" desc
params: 
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/expenses.js:1:14262 {
  query: 'select "id", "salon_id", "name", "category", "amount", "date", "created_at" from "expenses" "expenses" where "expenses"."salon_id" = $1 order by "expenses"."date" desc',
  params: [ undefined ],
  cause: error: column "name" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/expenses.js:1:14262 {
    length: 104,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '26',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "sales"."id", "sales"."invoice_number", "sales"."salon_id", "sales"."staff_id", "sales"."customer_phone", "sales"."customer_name", "sales"."customer_source", "sales"."subtotal", "sales"."discount", "sales"."total", "sales"."commission_rate", "sales"."tax_rate", "sales"."tax_amount", "sales"."status", "sales"."void_reason", "sales"."payment_method", "sales"."amount_paid", "sales"."created_at", "sales_saleItems"."data" as "saleItems", "sales_staff"."data" as "staff", "sales_salon"."data" as "salon" from "sales" "sales" left join lateral (select coalesce(json_agg(json_build_array("sales_saleItems"."id", "sales_saleItems"."sale_id", "sales_saleItems"."service_id", "sales_saleItems"."product_id", "sales_saleItems"."staff_id", "sales_saleItems"."quantity", "sales_saleItems"."price", "sales_saleItems"."discount_amount", "sales_saleItems"."tax_amount", "sales_saleItems"."commission_amount", "sales_saleItems"."is_internal", "sales_saleItems_service"."data", "sales_saleItems_product"."data", "sales_saleItems_staff"."data")), '[]'::json) as "data" from "sale_items" "sales_saleItems" left join lateral (select json_build_array("sales_saleItems_service"."id", "sales_saleItems_service"."salon_id", "sales_saleItems_service"."name", "sales_saleItems_service"."price", "sales_saleItems_service"."category", "sales_saleItems_service"."is_active", "sales_saleItems_service"."is_package", "sales_saleItems_service"."description", "sales_saleItems_service"."arabic_name", "sales_saleItems_service"."created_at") as "data" from (select * from "services" "sales_saleItems_service" where "sales_saleItems_service"."id" = "sales_saleItems"."service_id" limit $1) "sales_saleItems_service") "sales_saleItems_service" on true left join lateral (select json_build_array("sales_saleItems_product"."id", "sales_saleItems_product"."salon_id", "sales_saleItems_product"."vendor_id", "sales_saleItems_product"."name", "sales_saleItems_product"."sku", "sales_saleItems_product"."stock_quantity", "sales_saleItems_product"."unit", "sales_saleItems_product"."unit_price", "sales_saleItems_product"."selling_price", "sales_saleItems_product"."can_be_sold", "sales_saleItems_product"."expiry_date", "sales_saleItems_product"."low_stock_threshold", "sales_saleItems_product"."created_at") as "data" from (select * from "inventory_items" "sales_saleItems_product" where "sales_saleItems_product"."id" = "sales_saleItems"."product_id" limit $2) "sales_saleItems_product") "sales_saleItems_product" on true left join lateral (select json_build_array("sales_saleItems_staff"."id", "sales_saleItems_staff"."user_id", "sales_saleItems_staff"."salon_id", "sales_saleItems_staff"."name", "sales_saleItems_staff"."phone", "sales_saleItems_staff"."salary_type", "sales_saleItems_staff"."salary_value", "sales_saleItems_staff"."commission_percentage", "sales_saleItems_staff"."in_time_limit", "sales_saleItems_staff"."out_time_limit", "sales_saleItems_staff"."late_time_limit", "sales_saleItems_staff"."early_exit_time_limit", "sales_saleItems_staff"."late_deduction_rate", "sales_saleItems_staff"."early_exit_deduction_rate", "sales_saleItems_staff"."allowed_leaves", "sales_saleItems_staff"."joining_date", "sales_saleItems_staff"."created_at") as "data" from (select * from "staff" "sales_saleItems_staff" where "sales_saleItems_staff"."id" = "sales_saleItems"."staff_id" limit $3) "sales_saleItems_staff") "sales_saleItems_staff" on true where "sales_saleItems"."sale_id" = "sales"."id") "sales_saleItems" on true left join lateral (select json_build_array("sales_staff"."id", "sales_staff"."user_id", "sales_staff"."salon_id", "sales_staff"."name", "sales_staff"."phone", "sales_staff"."salary_type", "sales_staff"."salary_value", "sales_staff"."commission_percentage", "sales_staff"."in_time_limit", "sales_staff"."out_time_limit", "sales_staff"."late_time_limit", "sales_staff"."early_exit_time_limit", "sales_staff"."late_deduction_rate", "sales_staff"."early_exit_deduction_rate", "sales_staff"."allowed_leaves", "sales_staff"."joining_date", "sales_staff"."created_at") as "data" from (select * from "staff" "sales_staff" where "sales_staff"."id" = "sales"."staff_id" limit $4) "sales_staff") "sales_staff" on true left join lateral (select json_build_array("sales_salon"."id", "sales_salon"."name", "sales_salon"."logo", "sales_salon"."address", "sales_salon"."subscription_end", "sales_salon"."is_suspended", "sales_salon"."cash_balance", "sales_salon"."created_at", "sales_salon"."updated_at", "sales_salon"."late_time_limit", "sales_salon"."timezone", "sales_salon"."in_time_limit", "sales_salon"."out_time_limit", "sales_salon"."early_exit_time_limit", "sales_salon"."late_deduction_rate", "sales_salon"."early_exit_deduction_rate", "sales_salon"."vat_number", "sales_salon"."qr_domain") as "data" from (select * from "salons" "sales_salon" where "sales_salon"."id" = "sales"."salon_id" limit $5) "sales_salon") "sales_salon" on true where ("sales"."salon_id" = $6 and "sales"."status" != 'DRAFT') order by "sales"."created_at" desc
params: 1,1,1,1,1,
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/sales.js:7:909 {
  query: `select "sales"."id", "sales"."invoice_number", "sales"."salon_id", "sales"."staff_id", "sales"."customer_phone", "sales"."customer_name", "sales"."customer_source", "sales"."subtotal", "sales"."discount", "sales"."total", "sales"."commission_rate", "sales"."tax_rate", "sales"."tax_amount", "sales"."status", "sales"."void_reason", "sales"."payment_method", "sales"."amount_paid", "sales"."created_at", "sales_saleItems"."data" as "saleItems", "sales_staff"."data" as "staff", "sales_salon"."data" as "salon" from "sales" "sales" left join lateral (select coalesce(json_agg(json_build_array("sales_saleItems"."id", "sales_saleItems"."sale_id", "sales_saleItems"."service_id", "sales_saleItems"."product_id", "sales_saleItems"."staff_id", "sales_saleItems"."quantity", "sales_saleItems"."price", "sales_saleItems"."discount_amount", "sales_saleItems"."tax_amount", "sales_saleItems"."commission_amount", "sales_saleItems"."is_internal", "sales_saleItems_service"."data", "sales_saleItems_product"."data", "sales_saleItems_staff"."data")), '[]'::json) as "data" from "sale_items" "sales_saleItems" left join lateral (select json_build_array("sales_saleItems_service"."id", "sales_saleItems_service"."salon_id", "sales_saleItems_service"."name", "sales_saleItems_service"."price", "sales_saleItems_service"."category", "sales_saleItems_service"."is_active", "sales_saleItems_service"."is_package", "sales_saleItems_service"."description", "sales_saleItems_service"."arabic_name", "sales_saleItems_service"."created_at") as "data" from (select * from "services" "sales_saleItems_service" where "sales_saleItems_service"."id" = "sales_saleItems"."service_id" limit $1) "sales_saleItems_service") "sales_saleItems_service" on true left join lateral (select json_build_array("sales_saleItems_product"."id", "sales_saleItems_product"."salon_id", "sales_saleItems_product"."vendor_id", "sales_saleItems_product"."name", "sales_saleItems_product"."sku", "sales_saleItems_product"."stock_quantity", "sales_saleItems_product"."unit", "sales_saleItems_product"."unit_price", "sales_saleItems_product"."selling_price", "sales_saleItems_product"."can_be_sold", "sales_saleItems_product"."expiry_date", "sales_saleItems_product"."low_stock_threshold", "sales_saleItems_product"."created_at") as "data" from (select * from "inventory_items" "sales_saleItems_product" where "sales_saleItems_product"."id" = "sales_saleItems"."product_id" limit $2) "sales_saleItems_product") "sales_saleItems_product" on true left join lateral (select json_build_array("sales_saleItems_staff"."id", "sales_saleItems_staff"."user_id", "sales_saleItems_staff"."salon_id", "sales_saleItems_staff"."name", "sales_saleItems_staff"."phone", "sales_saleItems_staff"."salary_type", "sales_saleItems_staff"."salary_value", "sales_saleItems_staff"."commission_percentage", "sales_saleItems_staff"."in_time_limit", "sales_saleItems_staff"."out_time_limit", "sales_saleItems_staff"."late_time_limit", "sales_saleItems_staff"."early_exit_time_limit", "sales_saleItems_staff"."late_deduction_rate", "sales_saleItems_staff"."early_exit_deduction_rate", "sales_saleItems_staff"."allowed_leaves", "sales_saleItems_staff"."joining_date", "sales_saleItems_staff"."created_at") as "data" from (select * from "staff" "sales_saleItems_staff" where "sales_saleItems_staff"."id" = "sales_saleItems"."staff_id" limit $3) "sales_saleItems_staff") "sales_saleItems_staff" on true where "sales_saleItems"."sale_id" = "sales"."id") "sales_saleItems" on true left join lateral (select json_build_array("sales_staff"."id", "sales_staff"."user_id", "sales_staff"."salon_id", "sales_staff"."name", "sales_staff"."phone", "sales_staff"."salary_type", "sales_staff"."salary_value", "sales_staff"."commission_percentage", "sales_staff"."in_time_limit", "sales_staff"."out_time_limit", "sales_staff"."late_time_limit", "sales_staff"."early_exit_time_limit", "sales_staff"."late_deduction_rate", "sales_staff"."early_exit_deduction_rate", "sales_staff"."allowed_leaves", "sales_staff"."joining_date", "sales_staff"."created_at") as "data" from (select * from "staff" "sales_staff" where "sales_staff"."id" = "sales"."staff_id" limit $4) "sales_staff") "sales_staff" on true left join lateral (select json_build_array("sales_salon"."id", "sales_salon"."name", "sales_salon"."logo", "sales_salon"."address", "sales_salon"."subscription_end", "sales_salon"."is_suspended", "sales_salon"."cash_balance", "sales_salon"."created_at", "sales_salon"."updated_at", "sales_salon"."late_time_limit", "sales_salon"."timezone", "sales_salon"."in_time_limit", "sales_salon"."out_time_limit", "sales_salon"."early_exit_time_limit", "sales_salon"."late_deduction_rate", "sales_salon"."early_exit_deduction_rate", "sales_salon"."vat_number", "sales_salon"."qr_domain") as "data" from (select * from "salons" "sales_salon" where "sales_salon"."id" = "sales"."salon_id" limit $5) "sales_salon") "sales_salon" on true where ("sales"."salon_id" = $6 and "sales"."status" != 'DRAFT') order by "sales"."created_at" desc`,
  params: [ 1, 1, 1, 1, 1, undefined ],
  cause: error: column sales_saleItems.product_id does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/sales.js:7:909 {
    length: 126,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '2390',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "attendance"."id", "attendance"."staff_id", "attendance"."salon_id", "attendance"."status", "attendance"."approval_status", "attendance"."check_in", "attendance"."check_out", "attendance"."early_exit", "attendance"."date", "attendance"."created_at", "attendance_staff"."data" as "staff" from "attendance" "attendance" left join lateral (select json_build_array("attendance_staff"."id", "attendance_staff"."user_id", "attendance_staff"."salon_id", "attendance_staff"."name", "attendance_staff"."phone", "attendance_staff"."salary_type", "attendance_staff"."salary_value", "attendance_staff"."commission_percentage", "attendance_staff"."in_time_limit", "attendance_staff"."out_time_limit", "attendance_staff"."late_time_limit", "attendance_staff"."early_exit_time_limit", "attendance_staff"."late_deduction_rate", "attendance_staff"."early_exit_deduction_rate", "attendance_staff"."allowed_leaves", "attendance_staff"."joining_date", "attendance_staff"."created_at") as "data" from (select * from "staff" "attendance_staff" where "attendance_staff"."id" = "attendance"."staff_id" limit $1) "attendance_staff") "attendance_staff" on true where "attendance"."salon_id" = $2 order by "attendance"."date" desc, "attendance"."created_at" desc
params: 1,
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/attendance.js:1:11051 {
  query: 'select "attendance"."id", "attendance"."staff_id", "attendance"."salon_id", "attendance"."status", "attendance"."approval_status", "attendance"."check_in", "attendance"."check_out", "attendance"."early_exit", "attendance"."date", "attendance"."created_at", "attendance_staff"."data" as "staff" from "attendance" "attendance" left join lateral (select json_build_array("attendance_staff"."id", "attendance_staff"."user_id", "attendance_staff"."salon_id", "attendance_staff"."name", "attendance_staff"."phone", "attendance_staff"."salary_type", "attendance_staff"."salary_value", "attendance_staff"."commission_percentage", "attendance_staff"."in_time_limit", "attendance_staff"."out_time_limit", "attendance_staff"."late_time_limit", "attendance_staff"."early_exit_time_limit", "attendance_staff"."late_deduction_rate", "attendance_staff"."early_exit_deduction_rate", "attendance_staff"."allowed_leaves", "attendance_staff"."joining_date", "attendance_staff"."created_at") as "data" from (select * from "staff" "attendance_staff" where "attendance_staff"."id" = "attendance"."staff_id" limit $1) "attendance_staff") "attendance_staff" on true where "attendance"."salon_id" = $2 order by "attendance"."date" desc, "attendance"."created_at" desc',
  params: [ 1, undefined ],
  cause: error: column attendance_staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/attendance.js:1:11051 {
    length: 128,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '905',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
DrizzleQueryError: Failed query: select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)
params: 1,8eb099be-7518-4950-9319-d5fa236007e6,true
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
  query: `select "services"."id", "services"."salon_id", "services"."name", "services"."price", "services"."category", "services"."is_active", "services"."is_package", "services"."description", "services"."arabic_name", "services"."created_at", "services_bundleItems"."data" as "bundleItems" from "services" "services" left join lateral (select coalesce(json_agg(json_build_array("services_bundleItems"."id", "services_bundleItems"."package_id", "services_bundleItems"."service_id", "services_bundleItems"."price", "services_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "services_bundleItems" left join lateral (select json_build_array("services_bundleItems_service"."id", "services_bundleItems_service"."salon_id", "services_bundleItems_service"."name", "services_bundleItems_service"."price", "services_bundleItems_service"."category", "services_bundleItems_service"."is_active", "services_bundleItems_service"."is_package", "services_bundleItems_service"."description", "services_bundleItems_service"."arabic_name", "services_bundleItems_service"."created_at") as "data" from (select * from "services" "services_bundleItems_service" where "services_bundleItems_service"."id" = "services_bundleItems"."service_id" limit $1) "services_bundleItems_service") "services_bundleItems_service" on true where "services_bundleItems"."package_id" = "services"."id") "services_bundleItems" on true where ("services"."salon_id" = $2 and "services"."is_active" = $3)`,
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6', 'true' ],
  cause: error: column services_bundleItems.price does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/services.js:1:6270 {
    length: 125,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '474',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "appointments"."id", "appointments"."salon_id", "appointments"."service_id", "appointments"."service_ids", "appointments"."service_details", "appointments"."staff_id", "appointments"."customer_name", "appointments"."customer_phone", "appointments"."appointment_time", "appointments"."status", "appointments"."notes", "appointments"."created_at", "appointments_service"."data" as "service", "appointments_staff"."data" as "staff" from "appointments" "appointments" left join lateral (select json_build_array("appointments_service"."id", "appointments_service"."salon_id", "appointments_service"."name", "appointments_service"."price", "appointments_service"."category", "appointments_service"."is_active", "appointments_service"."is_package", "appointments_service"."description", "appointments_service"."arabic_name", "appointments_service"."created_at", "appointments_service_bundleItems"."data") as "data" from (select * from "services" "appointments_service" where "appointments_service"."id" = "appointments"."service_id" limit $1) "appointments_service" left join lateral (select coalesce(json_agg(json_build_array("appointments_service_bundleItems"."id", "appointments_service_bundleItems"."package_id", "appointments_service_bundleItems"."service_id", "appointments_service_bundleItems"."price", "appointments_service_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "appointments_service_bundleItems" left join lateral (select json_build_array("appointments_service_bundleItems_service"."id", "appointments_service_bundleItems_service"."salon_id", "appointments_service_bundleItems_service"."name", "appointments_service_bundleItems_service"."price", "appointments_service_bundleItems_service"."category", "appointments_service_bundleItems_service"."is_active", "appointments_service_bundleItems_service"."is_package", "appointments_service_bundleItems_service"."description", "appointments_service_bundleItems_service"."arabic_name", "appointments_service_bundleItems_service"."created_at") as "data" from (select * from "services" "appointments_service_bundleItems_service" where "appointments_service_bundleItems_service"."id" = "appointments_service_bundleItems"."service_id" limit $2) "appointments_service_bundleItems_service") "appointments_service_bundleItems_service" on true where "appointments_service_bundleItems"."package_id" = "appointments_service"."id") "appointments_service_bundleItems" on true) "appointments_service" on true left join lateral (select json_build_array("appointments_staff"."id", "appointments_staff"."user_id", "appointments_staff"."salon_id", "appointments_staff"."name", "appointments_staff"."phone", "appointments_staff"."salary_type", "appointments_staff"."salary_value", "appointments_staff"."commission_percentage", "appointments_staff"."in_time_limit", "appointments_staff"."out_time_limit", "appointments_staff"."late_time_limit", "appointments_staff"."early_exit_time_limit", "appointments_staff"."late_deduction_rate", "appointments_staff"."early_exit_deduction_rate", "appointments_staff"."allowed_leaves", "appointments_staff"."joining_date", "appointments_staff"."created_at") as "data" from (select * from "staff" "appointments_staff" where "appointments_staff"."id" = "appointments"."staff_id" limit $3) "appointments_staff") "appointments_staff" on true where "appointments"."salon_id" = $4 order by "appointments"."appointment_time" asc
params: 1,1,1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/appointments.js:1:9940 {
  query: `select "appointments"."id", "appointments"."salon_id", "appointments"."service_id", "appointments"."service_ids", "appointments"."service_details", "appointments"."staff_id", "appointments"."customer_name", "appointments"."customer_phone", "appointments"."appointment_time", "appointments"."status", "appointments"."notes", "appointments"."created_at", "appointments_service"."data" as "service", "appointments_staff"."data" as "staff" from "appointments" "appointments" left join lateral (select json_build_array("appointments_service"."id", "appointments_service"."salon_id", "appointments_service"."name", "appointments_service"."price", "appointments_service"."category", "appointments_service"."is_active", "appointments_service"."is_package", "appointments_service"."description", "appointments_service"."arabic_name", "appointments_service"."created_at", "appointments_service_bundleItems"."data") as "data" from (select * from "services" "appointments_service" where "appointments_service"."id" = "appointments"."service_id" limit $1) "appointments_service" left join lateral (select coalesce(json_agg(json_build_array("appointments_service_bundleItems"."id", "appointments_service_bundleItems"."package_id", "appointments_service_bundleItems"."service_id", "appointments_service_bundleItems"."price", "appointments_service_bundleItems_service"."data")), '[]'::json) as "data" from "service_package_items" "appointments_service_bundleItems" left join lateral (select json_build_array("appointments_service_bundleItems_service"."id", "appointments_service_bundleItems_service"."salon_id", "appointments_service_bundleItems_service"."name", "appointments_service_bundleItems_service"."price", "appointments_service_bundleItems_service"."category", "appointments_service_bundleItems_service"."is_active", "appointments_service_bundleItems_service"."is_package", "appointments_service_bundleItems_service"."description", "appointments_service_bundleItems_service"."arabic_name", "appointments_service_bundleItems_service"."created_at") as "data" from (select * from "services" "appointments_service_bundleItems_service" where "appointments_service_bundleItems_service"."id" = "appointments_service_bundleItems"."service_id" limit $2) "appointments_service_bundleItems_service") "appointments_service_bundleItems_service" on true where "appointments_service_bundleItems"."package_id" = "appointments_service"."id") "appointments_service_bundleItems" on true) "appointments_service" on true left join lateral (select json_build_array("appointments_staff"."id", "appointments_staff"."user_id", "appointments_staff"."salon_id", "appointments_staff"."name", "appointments_staff"."phone", "appointments_staff"."salary_type", "appointments_staff"."salary_value", "appointments_staff"."commission_percentage", "appointments_staff"."in_time_limit", "appointments_staff"."out_time_limit", "appointments_staff"."late_time_limit", "appointments_staff"."early_exit_time_limit", "appointments_staff"."late_deduction_rate", "appointments_staff"."early_exit_deduction_rate", "appointments_staff"."allowed_leaves", "appointments_staff"."joining_date", "appointments_staff"."created_at") as "data" from (select * from "staff" "appointments_staff" where "appointments_staff"."id" = "appointments"."staff_id" limit $3) "appointments_staff") "appointments_staff" on true where "appointments"."salon_id" = $4 order by "appointments"."appointment_time" asc`,
  params: [ 1, 1, 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column appointments_service_bundleItems.price does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/appointments.js:1:9940 {
    length: 138,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '1267',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: 
      SELECT 
        customer_phone,
        customer_name,
        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt
      FROM sales
      WHERE salon_id = $1::uuid AND status = 'ACTIVE'
      GROUP BY customer_phone, customer_name
    
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
  query: '\n' +
    '      SELECT \n' +
    '        customer_phone,\n' +
    '        customer_name,\n' +
    "        sum(GREATEST(0, CAST(total AS NUMERIC) - CAST(COALESCE(amount_paid, '0') AS NUMERIC))) as active_debt\n" +
    '      FROM sales\n' +
    "      WHERE salon_id = $1::uuid AND status = 'ACTIVE'\n" +
    '      GROUP BY customer_phone, customer_name\n' +
    '    ',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "customer_phone" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:148:20
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/clients.js:1:7771 {
    length: 114,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '24',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2
params: 1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
  query: 'select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2',
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
    length: 117,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '379',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2
params: 1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
  query: 'select "staff"."id", "staff"."user_id", "staff"."salon_id", "staff"."name", "staff"."phone", "staff"."salary_type", "staff"."salary_value", "staff"."commission_percentage", "staff"."in_time_limit", "staff"."out_time_limit", "staff"."late_time_limit", "staff"."early_exit_time_limit", "staff"."late_deduction_rate", "staff"."early_exit_deduction_rate", "staff"."allowed_leaves", "staff"."joining_date", "staff"."created_at", "staff_user"."data" as "user" from "staff" "staff" left join lateral (select json_build_array("staff_user"."id", "staff_user"."email", "staff_user"."phone", "staff_user"."role", "staff_user"."salon_id", "staff_user"."name", "staff_user"."is_active", "staff_user"."created_at") as "data" from (select * from "users" "staff_user" where "staff_user"."id" = "staff"."user_id" limit $1) "staff_user") "staff_user" on true where "staff"."salon_id" = $2',
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/staff.js:1:20148 {
    length: 117,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '379',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
DrizzleQueryError: Failed query: select "attendance"."id", "attendance"."staff_id", "attendance"."salon_id", "attendance"."status", "attendance"."approval_status", "attendance"."check_in", "attendance"."check_out", "attendance"."early_exit", "attendance"."date", "attendance"."created_at", "attendance_staff"."data" as "staff" from "attendance" "attendance" left join lateral (select json_build_array("attendance_staff"."id", "attendance_staff"."user_id", "attendance_staff"."salon_id", "attendance_staff"."name", "attendance_staff"."phone", "attendance_staff"."salary_type", "attendance_staff"."salary_value", "attendance_staff"."commission_percentage", "attendance_staff"."in_time_limit", "attendance_staff"."out_time_limit", "attendance_staff"."late_time_limit", "attendance_staff"."early_exit_time_limit", "attendance_staff"."late_deduction_rate", "attendance_staff"."early_exit_deduction_rate", "attendance_staff"."allowed_leaves", "attendance_staff"."joining_date", "attendance_staff"."created_at") as "data" from (select * from "staff" "attendance_staff" where "attendance_staff"."id" = "attendance"."staff_id" limit $1) "attendance_staff") "attendance_staff" on true where "attendance"."salon_id" = $2 order by "attendance"."date" desc, "attendance"."created_at" desc
params: 1,8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/attendance.js:1:11051 {
  query: 'select "attendance"."id", "attendance"."staff_id", "attendance"."salon_id", "attendance"."status", "attendance"."approval_status", "attendance"."check_in", "attendance"."check_out", "attendance"."early_exit", "attendance"."date", "attendance"."created_at", "attendance_staff"."data" as "staff" from "attendance" "attendance" left join lateral (select json_build_array("attendance_staff"."id", "attendance_staff"."user_id", "attendance_staff"."salon_id", "attendance_staff"."name", "attendance_staff"."phone", "attendance_staff"."salary_type", "attendance_staff"."salary_value", "attendance_staff"."commission_percentage", "attendance_staff"."in_time_limit", "attendance_staff"."out_time_limit", "attendance_staff"."late_time_limit", "attendance_staff"."early_exit_time_limit", "attendance_staff"."late_deduction_rate", "attendance_staff"."early_exit_deduction_rate", "attendance_staff"."allowed_leaves", "attendance_staff"."joining_date", "attendance_staff"."created_at") as "data" from (select * from "staff" "attendance_staff" where "attendance_staff"."id" = "attendance"."staff_id" limit $1) "attendance_staff") "attendance_staff" on true where "attendance"."salon_id" = $2 order by "attendance"."date" desc, "attendance"."created_at" desc',
  params: [ 1, '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column attendance_staff.joining_date does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/attendance.js:1:11051 {
    length: 128,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '905',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
DrizzleQueryError: Failed query: select "id", "salon_id", "name", "category", "amount", "date", "created_at" from "expenses" "expenses" where (("expenses"."salon_id" = $1 and "expenses"."date" >= $2) and "expenses"."date" <= $3) order by "expenses"."date" desc
params: 8eb099be-7518-4950-9319-d5fa236007e6,2026-07-22,2026-08-21
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/expenses.js:1:14262 {
  query: 'select "id", "salon_id", "name", "category", "amount", "date", "created_at" from "expenses" "expenses" where (("expenses"."salon_id" = $1 and "expenses"."date" >= $2) and "expenses"."date" <= $3) order by "expenses"."date" desc',
  params: [
    '8eb099be-7518-4950-9319-d5fa236007e6',
    '2026-07-22',
    '2026-08-21'
  ],
  cause: error: column "name" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/expenses.js:1:14262 {
    length: 104,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '26',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
[Reports] Critical Summary Error: DrizzleQueryError: Failed query: select "id", "user_id", "salon_id", "name", "phone", "salary_type", "salary_value", "commission_percentage", "in_time_limit", "out_time_limit", "late_time_limit", "early_exit_time_limit", "late_deduction_rate", "early_exit_deduction_rate", "allowed_leaves", "joining_date", "created_at" from "staff" "staff" where "staff"."salon_id" = $1
params: 8eb099be-7518-4950-9319-d5fa236007e6
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/reports.js:1:26673 {
  query: 'select "id", "user_id", "salon_id", "name", "phone", "salary_type", "salary_value", "commission_percentage", "in_time_limit", "out_time_limit", "late_time_limit", "early_exit_time_limit", "late_deduction_rate", "early_exit_deduction_rate", "allowed_leaves", "joining_date", "created_at" from "staff" "staff" where "staff"."salon_id" = $1',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6' ],
  cause: error: column "joining_date" does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/reports.js:1:26673 {
    length: 113,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '259',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Top services error: DrizzleQueryError: Failed query: 
      SELECT COALESCE(s.name, i.name, 'Unknown') as name, 
             count(si.id) as count, 
             sum(
               (CAST(si.price AS NUMERIC) * CAST(si.quantity AS NUMERIC) - COALESCE(CAST(si.discount_amount AS NUMERIC), 0)) * 
               (CAST(l.amount AS NUMERIC) / NULLIF(CAST(sa.total AS NUMERIC), 0))
             ) as revenue
      FROM ledger_entries l
      JOIN sales sa ON l.sale_id = sa.id
      JOIN sale_items si ON si.sale_id = sa.id
      LEFT JOIN services s ON si.service_id = s.id
      LEFT JOIN inventory_items i ON si.product_id = i.id
      WHERE sa.salon_id = $1::uuid AND sa.status = 'ACTIVE'
            AND l.category = 'PAYMENT' AND l.type = 'DEBIT'
            AND l.date >= $2::timestamptz AND l.date <= $3::timestamptz
            AND CAST(si.price AS NUMERIC) > 0
            AND CAST(si.quantity AS NUMERIC) > 0
            AND si.is_internal = false
            
      GROUP BY 1
      ORDER BY revenue DESC
      LIMIT $4
    
params: 8eb099be-7518-4950-9319-d5fa236007e6,2026-07-21T04:00:00.000Z,2026-08-21T03:59:59.999Z,10
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/reports.js:232:16705 {
  query: '\n' +
    "      SELECT COALESCE(s.name, i.name, 'Unknown') as name, \n" +
    '             count(si.id) as count, \n' +
    '             sum(\n' +
    '               (CAST(si.price AS NUMERIC) * CAST(si.quantity AS NUMERIC) - COALESCE(CAST(si.discount_amount AS NUMERIC), 0)) * \n' +
    '               (CAST(l.amount AS NUMERIC) / NULLIF(CAST(sa.total AS NUMERIC), 0))\n' +
    '             ) as revenue\n' +
    '      FROM ledger_entries l\n' +
    '      JOIN sales sa ON l.sale_id = sa.id\n' +
    '      JOIN sale_items si ON si.sale_id = sa.id\n' +
    '      LEFT JOIN services s ON si.service_id = s.id\n' +
    '      LEFT JOIN inventory_items i ON si.product_id = i.id\n' +
    "      WHERE sa.salon_id = $1::uuid AND sa.status = 'ACTIVE'\n" +
    "            AND l.category = 'PAYMENT' AND l.type = 'DEBIT'\n" +
    '            AND l.date >= $2::timestamptz AND l.date <= $3::timestamptz\n' +
    '            AND CAST(si.price AS NUMERIC) > 0\n' +
    '            AND CAST(si.quantity AS NUMERIC) > 0\n' +
    '            AND si.is_internal = false\n' +
    '            \n' +
    '      GROUP BY 1\n' +
    '      ORDER BY revenue DESC\n' +
    '      LIMIT $4\n' +
    '    ',
  params: [
    '8eb099be-7518-4950-9319-d5fa236007e6',
    '2026-07-21T04:00:00.000Z',
    '2026-08-21T03:59:59.999Z',
    10
  ],
  cause: error: column si.product_id does not exist
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:148:20
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/reports.js:232:16705 {
    length: 112,
    severity: 'ERROR',
    code: '42703',
    detail: undefined,
    hint: undefined,
    position: '556',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '3337',
    routine: 'errorMissingColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
Dashboard metrics error: DrizzleQueryError: Failed query: select (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (
  CASE
    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true
    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR
         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false
         
    -- 2. Check plain text notes
    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%card%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%check%' OR 
         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true

    -- 3. Fallback to joined sale / purchase default payment method
    WHEN sale_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM sales s 
      WHERE s.id = sale_id 
      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    WHEN purchase_id IS NOT NULL AND EXISTS (
      SELECT 1 FROM purchases p 
      WHERE p.id = purchase_id 
      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')
    ) THEN true
    ELSE false
  END
)
params: 8eb099be-7518-4950-9319-d5fa236007e6,PAYMENT,DEBIT
    at NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:66:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
    at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
  query: 'select (\n' +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    `), sum("ledger_entries"."amount") from "ledger_entries" left join "sales" on "ledger_entries"."sale_id" = "sales"."id" where ("ledger_entries"."salon_id" = $1 and "ledger_entries"."category" = $2 and "ledger_entries"."type" = $3 and "ledger_entries"."vendor_id" IS NULL and ("ledger_entries"."sale_id" IS NULL OR "sales"."status" != 'VOID')) group by (\n` +
    '  CASE\n' +
    '    -- 1. Check explicit JSON notes for paymentMethod containing ONLINE, CARD, BANK, UPI, DIGITAL, CHECK, CHEQUE, CHQ\n' +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"online"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"card"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"bank"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"upi"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"digital"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"check"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cheque"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"chq"%' THEN true\n` +
    `    WHEN LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash"%' OR\n` +
    `         LOWER(COALESCE(notes, '')) LIKE '%"paymentmethod"%"cash_on_delivery"%' THEN false\n` +
    '         \n' +
    '    -- 2. Check plain text notes\n' +
    "    WHEN LOWER(COALESCE(notes, '')) LIKE '%online%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%card%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%bank%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%upi%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%cheque%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%check%' OR \n" +
    "         LOWER(COALESCE(notes, '')) LIKE '%chq%' THEN true\n" +
    '\n' +
    '    -- 3. Fallback to joined sale / purchase default payment method\n' +
    '    WHEN sale_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM sales s \n' +
    '      WHERE s.id = sale_id \n' +
    "      AND UPPER(COALESCE(s.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    WHEN purchase_id IS NOT NULL AND EXISTS (\n' +
    '      SELECT 1 FROM purchases p \n' +
    '      WHERE p.id = purchase_id \n' +
    "      AND UPPER(COALESCE(p.payment_method, '')) IN ('ONLINE', 'CARD', 'BANK_TRANSFER', 'UPI', 'DIGITAL', 'CHECK', 'CHEQUE', 'CHQ')\n" +
    '    ) THEN true\n' +
    '    ELSE false\n' +
    '  END\n' +
    ')',
  params: [ '8eb099be-7518-4950-9319-d5fa236007e6', 'PAYMENT', 'DEBIT' ],
  cause: error: column reference "notes" is ambiguous
      at /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/pg-pool/index.js:45:11
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:159:18
      at async NodePgPreparedQuery.queryWithCache (/home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/pg-core/session.cjs:64:16)
      at async /home/zaistsnv/nodevenv/api.zaishapos.org/20/lib/node_modules/drizzle-orm/node-postgres/session.cjs:152:22
      at async /home/zaistsnv/api.zaishapos.org/dist/routes/dashboard.js:1:7616 {
    length: 111,
    severity: 'ERROR',
    code: '42702',
    detail: undefined,
    hint: undefined,
    position: '159',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '691',
    routine: 'scanRTEForColumn'
  }
}
