Subversion Repositories SmartDukaan

Rev

Show changed files | Directory listing | RSS feed

Filtering Options

Rev Age Author Path Log message Diff
37862 1 d 21 h ranu /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/migrations/ rbm ranking modal for september  
37858 1 d 23 h ranu /trunk/ remove tarun sir email from some storetimline tat email  
37857 2 d 0 h ranu /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/migrations/ remove tarun sir email from some storetimline tat email  
37848 2 d 22 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ feat(warehouse): daily 10:00 mail of stock in suspended/inactive warehouses (--sendSuspendedWarehouseStockAlert for a one-off); Shopify sync warehouse from shopify.warehouseId (default 13372 HR-NSSPL/UPW) instead of WAREHOUSE_NAME_MAP UP-WEST/NOIDA  
37833 6 d 14 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ feat(cron): --retryIrn re-files rejected e-invoices after their data is corrected - reset and filing in one transaction so the scheduled IRN job cannot race it  
37832 6 d 15 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ feat(cron): --closeMovementPO closes movement POs the way the PO screen's Close does (refund live orders, preclose); dry run by default  
37831 6 d 15 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/migrations/ feat(cron): movement billing takes only units at the order's price; PO dry run names each PO's vendor warehouse  
37828 6 d 16 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ fix(cron): movement billing looks POs up inside a transaction (driver has none - 'Could not obtain transaction-synchronized Session'); failure message no longer claims nothing was raised  
37827 6 d 17 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ feat(cron): --autoCreateMovementPO raises an internal movement PO from an upload file as the operator; dry run previews every PO, line, price and origin; --bill dry-runs billing of the raised POs  
37825 6 d 17 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/ feat(cron): --autoBillMovement bills internal movement POs (dry run by default)

Bills the orders a movement PO raised the way the order management screen does:
orders parked on the Dummy (brand without a source mapping) are re-pointed to the
source vendor warehouse holding the stock (split when it spans several), serialized
units take IMEIs oldest first at qty 1 with a good last scan, then acceptOrders ->
addBillingDetailsForGrouppedOrders -> checkOrderDispatchEligibility, one invoice per
transaction, all-or-nothing. IRN / e-way bill follow from the existing cron job.

Usage: --autoBillMovement --pos=PO1,PO2 --email=<operator> --provider=<id> [--live]
Dry run (default) plans and validates only - billing opens its own REQUIRES_NEW
transaction (createLoanForBilling) that a rollback would not undo. Refuses a
transaction over 900 invoice lines (NIC caps an IRN at 1000). Prints the invoice
list for --autoGrnInternal.
 
37814 8 d 22 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/scheduled/ revert(samsung-rebilling): drop TODO, keep ritesh.chauhan1 on the mail

Removes the TODO(amit.gupta) comment added in r37812. The only change left from
r37812 is ritesh.chauhan1 on To alongside kamini.sharma; tarun.verma stays on CC.
 
37812 9 d 0 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/scheduled/ fix(samsung-rebilling): send rebilling mail to kamini.sharma and ritesh.chauhan1

praveen.sharma was dropped in r37631 (inactive auth user); ritesh.chauhan1 now joins
kamini.sharma on To, tarun.verma stays on CC. TODO(amit.gupta) records the open
points: recipients cannot open Manage PCM (menu 208 is Financial Services L1/L2),
and the CSV omits the invoice and PCM dates the query already returns.

Requires profitmandi-dao r37811 (missing-PCM rows); deploy dao and cron together.
 
37788 11 d 1 h amit /trunk/profitmandi-cron/ activation: stop a broken JVM from spending the day's imei pool, and take the
selenium atom read out of the nested jar

Oppo/Realme activation collapsed on 21-22 Sep. Every WebDriver command failed with
java.util.zip.ZipException reading a Selenium JS atom:

W3CHttpCommandCodec.amendParameters:227 -> executeAtom:397
-> com.google.common.io.Resources.toString
-> org.springframework.boot.loader.jar.ZipInflaterInputStream.read -> ZipException

Scale, from fofo.activated_imei: a ~30-50 errors/day baseline became 17,508 on 21-Sep
and 27,768 on 22-Sep. On 22-Sep it touched 3,920 realme imeis for 0 dates and 4,824
oppo for 96, against a normal 76-100% hit rate. Realme burned its entire day pool by
11:07 and then correctly went quiet, having answered nothing.

TWO INDEPENDENT FAULTS, one fixed each way.

1. The pool was spent on an outage. restUnanswered stamps every unanswered imei so the
20-second tick advances instead of re-handing the same rows -- correct for a per-imei
failure, catastrophic for a systemic one, because a stamped row does not come back
until its rest expires. So a JVM that cannot read a jar quietly consumed a day of
payout data. Now: if NOTHING in the chunk was answered and the chunk had more than one
imei, that is infrastructure rather than a verdict, and nothing is stamped. Cost is a
re-ask of the same chunk next tick -- loud and self-limiting -- instead of the day.
Same class of bug as the carlcare transient refusal (r37537): far-end/our-end noise
must never be recorded as an answer.

2. The read itself. Selenium loads its atoms as classpath RESOURCES on essentially
every command, which inside a fat jar is a nested-jar read on the Spring Boot 2.0.2
(2018) loader. Three different inflater errors appeared on prod -- "invalid stored
block lengths", "invalid distance too far back", "invalid code lengths set" -- on a jar
whose outer AND extracted nested archives both pass `unzip -t`. Intact bytes with three
distinct inflater failures is a reader fault, not a file fault. bootJar now sets
requiresUnpack for selenium-remote-driver, so it is extracted to a real file at launch
and the atom read never touches the nested reader. Verified in the built jar: the entry
carries UNPACK:<sha1> and is STORED rather than DEFLATED.

TRAPS WORTH RECORDING.

- A restart is NOT a diagnosis here. It was restarted 13:16 on 22-Sep and still failed
for three more hours at ~1,260/hour, then a 16:36 restart came up clean -- same jar,
mtime unchanged. Anyone reading "restart fixed it" should distrust it.
- Concurrency alone does not explain it: up to 2 scheduler pools ran these tasks per
minute in the broken window AND in the healthy one.
- The GlitchTip board under-reported this badly (#1495 lastSeen 17-Sep while the log
held thousands on 21-22 Sep), so the board is not a reliable outage signal for cron.
Judge this lane on dates written in fofo.activated_imei, not on issue counts.
- Deploy the cron jar stop -> replace -> start. The jar on disk was overwritten in place
at 12:31 on 21-Sep while a JVM held it open, which is how this started.
 
37771 13 d 22 h amit /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/scheduled/ fix(movement): movement POs no longer auto-close; open movement PO digest to Warehouse L1/L2 at 09:00 and 17:00  
37751 14 d 22 h ranu /trunk/ aging po approval mail to some collected users  
37735 17 d 4 h amit /trunk/profitmandi-cron/src/main/ Remove dead third-party integrations: cron

- Toffee: attachToffeeInvoices (schedule already commented out), toffeeRollback
and the --tc option; tofee.* keys in run.properties
- Bharti Assist: sendBAGPendingPolicies, testBag/mapBag and the --bag /
--mapbag options
- HyperTrack geofence one-offs (--createGeofence, --getAllGeofences,
--deleteGeofences) and their hardcoded account keys
- SmartPing injection in ScheduledTasks; leftover DTDC comment
- aramex.tracking.url in run.properties
 
37729 17 d 4 h amit /trunk/ lead: one workable lead per mobile, with a 6-month supersede and an L2+ override

There was no choke point for lead creation. Ten sites did `new Lead()` across four
modules -- three in web's LeadController, two in V2FofoLeadController, three in fofo's
LeadController, one in TrialServiceImpl and one in the cron LeadSyncRunner -- and only
ONE of them (fofo /createLead) checked for an existing lead at all. Result on live data:
5,137 mobiles carrying duplicate leads over 12,156 rows, worst case 29 on one number,
and two agents unknowingly working the same shop.

THE RULE, in new LeadCreationService, which all ten now route through:

no active lead on the number -> create
active, last activity >= 6 months -> retire the old one, create the new one, SILENTLY
active, last activity < 6 months -> BLOCK; only an L2+ user may override

Active = status in (pending, followUp) AND the assignee is still an active auth_user.
Last activity = GREATEST(lead.updated/created, MAX(lead_activity.created)).

The stale branch is deliberately quiet. A shop enquiring again after six months is a
handover, not a clash, and mailing on it would train the desk to ignore the alert -- so
only a genuine collision notifies. Live split: 195 stale against 1,241 fresh, and roughly
three blocks a month.

WHY "ACTIVE" ALSO MEANS A LIVE OWNER

331 open leads are assigned to 11 DEACTIVATED accounts (157 to sm@smartdukaan.com alone,
whose newest lead is from 2022). Counting them as active would block fresh enquiries
behind an account nobody can log in to and therefore nobody can close. Requiring a live
owner defuses all 331 without retiring a single row. Retirement here is only ever
REACTIVE -- triggered by a new entry on the same number. Nothing runs on a schedule.

ASSUMPTION worth flagging: a superseded lead becomes status=notInterested (stage DROPPED)
with closure_timestamp and reason 'Superseded after 6 months inactivity', rather than a
new `expired` status. "Closed" is an explicit allow-list in the UI --
Arrays.asList(notInterested, finalized) at V2FofoLeadController:150 and fofo
LeadController:313 -- and there are ~107 references to specific LeadStatus values, so a
new enum value would make these leads vanish from BOTH the open and closed screens.
Stage DROPPED keeps the nuance (the shop never said no) and still maps to notInterested
via LeadStage.toLegacyStatus().

OVERRIDE is L2+ in ANY team, not Call Center only: Sales L1 owns 1,063 of the 1,776 open
leads, so a Call-Center-only gate would funnel every team's collisions through three
people. The MAIL still goes to Call Center L2+, resolved from cs.position at send time
rather than hardcoded. An override is a TAKEOVER -- it closes the existing lead -- because
a second live lead is the exact thing the rule exists to prevent.

UNATTENDED CALLERS (cron sync, CSV upload, trial registration, AI intake) have nobody to
offer an override to, so they use createUnattended: skip the colliding row and mail the
desk rather than throwing. CSV reports imported/duplicateSkipped/duplicateMobiles back to
the operator instead of failing the whole file over one number.

ALSO FIXES selectByMobileNumber, which called getSingleResult and therefore threw
NonUniqueResultException on any mobile with more than one lead -- GlitchTip #99 and #1359,
both still firing. It now prefers the open lead, then the most recently touched.

NOT INCLUDED, deliberately: no DB unique constraint. 10 mobiles already carry more than
one open lead and would have to be resolved by hand first, which conflicts with the
no-auto-retirement rule. The service enforces the invariant going forward.

NEEDS A DBA STEP: user.lead.mobile is unindexed on 37,580 rows, so this check is a full
scan on every create. Index DDL is in the accompanying note; it has NOT been applied.
 
37726 19 d 1 h amit /trunk/ sentry: stop developer laptops reporting to the live GlitchTip board

GlitchTip #586 was 57 events tagged environment=production whose stack read
/opt/homebrew/Cellar/tomcat@8/8.5.100/libexec/... with server_name set to a
developer's machine. Nothing was wrong on prod: a laptop was posting into the
production project and was indistinguishable from it.

Two things combined to allow that. The DSN lives in log4j2.xml, which ships inside
every build, so any machine running this code can report. And the Sentry SDK
defaults `environment` to "production" when it is not set -- which it never was --
so local runs arrived pre-labelled as prod.

Adds sentry.properties to each module, read off the classpath by the SDK itself
(io.sentry.config.PropertiesProviderFactory) and merged over the appender's config.
Both keys used here are honoured by io.sentry.ExternalOptions in 7.22.6 (verified
against the jar): `enabled` and `environment`.

The COMMITTED values are the safe ones -- enabled=false, environment=dev -- so a
plain local build is silent. build.gradle rewrites both from -Penv= alongside the
env.property it already writes, so only a deliberate -Penv=staging|prod build
reports, and it carries the right environment tag. tasks.build.doLast restores the
safe default afterwards, mirroring the existing handling of env.property.

Verified both directions: default build leaves enabled=false/environment=dev,
-Penv=prod yields enabled=true/environment=prod.

Note this makes the board trustworthy rather than merely quieter: events can now be
filtered on environment, and anything unlabelled is a build that predates this.
 
37704 20 d 12 h amit /trunk/ Reopen a movement PO whose stock arrived late, and stop stranding GRN price corrections

Internal movements auto-close after four days, which fits 99.6% of them - 5,491 of 5,515 receipts
land inside the window. The remainder leave the PO closed with the stock still in transit and
nowhere to receive it: 998 internal POs closed during 2026 still holding 21,996 unreceived units.

A closed movement PO can now be reopened from the purchase order list. Reopening stamps
reopenedAt, and auto-close measures from WarehousePurchaseOrder.getOpenSince() - reopenedAt when
set, the PO date otherwise - so a reopened PO gets the same fresh window a new one gets instead of
being closed straight back on the next sweep. Only movements between our own warehouses: an
external vendor PO that has closed is settled with that vendor, not reopened unilaterally.

Separately, a GRN price correction now checks that the PO it just raised is one the invoice can
actually be received against. Matching reads POs that are open and approved for the same supplier
and warehouse dated on or before the invoice; it never looks at the PO being corrected, so what
matters is that the new PO is receivable. 54 were not - backdated into INIT by the old approval
gate, hence outside the match - and each stranded silently: original line discarded, GRN completed
without it, the correction left holding a reservation for stock that had already arrived.

isOpen() names the open set - INIT, READY, PARTIALLY_FULFILLED - that the movement and commitment
queries already read.

Migration sql/add_po_reopened_at_20260918.sql adds reopenedAt, nullable and additive. It must run
before this ships: the entity maps the column.
 
37693 20 d 23 h ranu /trunk/profitmandi-cron/src/main/java/com/smartdukaan/cron/migrations/ rbm ranking mailer  

Show All