Skip to main content

Water Usage Ratio

A data-entry and reporting tool for Water Usage Ratio (WUR) — how much water is consumed per unit of production. Operators log daily production quantities; the app derives litres, and the report shows WUR = Total Borewell Receipt ÷ Total Production over a date range.

  • Route: /water_ratioWaterRatioPage (libs/waterRatio/src/WaterRatioPage.jsx)
  • Permission: WATER_RATIO (in the Efficiency nav group; the route element isn't wrapped — see Permissions)
  • Library: libs/waterRatio/ — standard dataSource → controller → store → components layering

How the ratio is built

Summary: Each entered quantity is multiplied by a per-field Multiplication Factor to get litres; those sum into per-line totals (Beverage 1 / Beverage 2) and a Total Production. The report divides total borewell water by total production to give the WUR for each day.

The layout is hardcoded to a two-line beverage plant (Production Line-1 / Line-2, fixed bottle-size fields and factors) — it is effectively single-tenant.


The page

Two modes, chosen in the left panel:

ModeWhat you do
New EntryLog production for a consumed date that has no record yet
EditLoad an existing day's record and correct it
AreaComponentWhat it showsOn click / action
Operations panelWaterRatioOperations (in BuildWaterRatioPage)Mode selector, read-only Reading Date (consumed date + 1 day @ 5:00), a Consumed Date picker (max = yesterday), and a Reports buttonFetch Data loads a day's record (disabled in New Entry)
Entry formBuildWaterRatioPageA numeric field per bottle-size line, live per-line totals, and Total ProductionUpload saves (POST for new, PUT for edit); disabled until Total Production > 0
ConfirmationWaterRatioSuccessCardA dismissible banner after uploadGreen on success, red on failure; close to dismiss
ReportWaterRatioReportPopupA dialog with a date-range picker (≤ 30 days) and a WUR tableFetch Data loads the range; Download exports the table

There are no charts — the main view is a form and the report is a table.


APIs

All three operations hit the same path waterRatio/, differing only by HTTP verb (dataSource/waterRatioDataSource.js):

ActionMethodPathTrigger
Fetch a day / a report rangeGETwaterRatio/Fetch Data (single day → { startDate, type: daily }; report → { startDate, endDate, type: monthly })
Save a new entryPOSTwaterRatio/Upload in New Entry mode
Update an entryPUTwaterRatio/Upload in Edit mode

There is no separate report endpoint — the report is the same GET over a date range, stored in reportData. The report download is client-side (Download.EXCEL → an .xlsx file via xlsx), not an API call. No analytics events are fired.

State (WaterRatioStore)

A React Context (WaterRatioProvider / WaterRatioContext) exposing the entry params, reportParams, ratioData, reportData, selectedMode, operationStatus, isLoading, and the getRatioData / uploadNewData / patchExistingData actions. See State Management and API Call Flow.


Edge cases & guards

CaseHandling
Mode gatingFetch Data is disabled in New Entry; switching to New Entry clears the form
Upload guardThe Upload button is disabled until Total Production > 0
Integer-only inputThe change handler accepts digits only — decimal quantities are silently rejected (despite a decimal input hint)
Date guardsConsumed date max = yesterday; report range capped at 30 days
Empty reportPrompts "Click on fetch data to get the report!"; Download stays disabled; closing the dialog clears the range and data
Upload resultSuccess / failure both surface via the success card
GET errors swallowedA failed fetch logs and returns nothing — no error card (the card covers only save/update)

Underlying libraries

PurposeLibrary
Date pickersreact-multi-date-picker (via AppDatePickerSelection)
Excel exportxlsx (via shared Download.EXCEL)
Datesmoment
UI@mui/material (MUI 7), lodash

There is no charting library here. Exact versions live in package.json.


Code reference

FileRole
WaterRatioPage.jsxPage shell + provider
dataSource/waterRatioDataSource.jsGET / POST / PUT to waterRatio/
controller/waterRatioController.jsParam shaping (date + fixed 5:00 time)
store/WaterRatioStore.jsContext state + actions
components/BuildWaterRatioPage.jsxOperations panel + entry form
components/WaterRatioReportPopup.jsxReport dialog + Excel export
components/WaterRatioSuccessCard.jsxUpload confirmation banner
helper/layoutFields.js · helper/waterRatioHelper.js · enum/productionLineEnum.jsPlant-specific field/factor config