Water Calculator Service

Overview

Water Calculator Service is used for creating meter reading, searching meter reading, updating existing meter reading, calculation of water charge, demand generation, SMS & email notification to ULB officials on-demand generation and estimation of water charge(one-time cost) which involves cost like road-cutting charge, form fee, scrutiny fee, etc.

Pre-requisites

Before you proceed with the documentation, make sure the following pre-requisites are met -

  • Java 8

  • Kafka server is up and running

  • egov-persister service is running and has water service persister configs path added in it

  • PSQL server is running and database is created to store water connection / application data

  • Following services should be up and running:

    • egov-perister

    • egov-mdms

    • ws-services

    • billing-service

Key Functionalities

  • Calculate water charge and taxes based on billing slab.

  • Calculate meter reading charge for water connection

  • Generate demand

  • Scheduler for generating the demand(for non metered connection)

Deployment Details

  1. Deploy the latest version of ws-service and ws-calculator

  2. Add water-persist.yml & water-meter.yml file in config folder in git and add that path in persister . (The file path is to be added in environment yaml file in param called persist-yml-path )

Configuration Details

MDMS Configuration

Billing Slabs:

Criteria :

  1. connection type

  2. building type

  3. calculation attribute

  4. property usage type

The combination of the above can be used to define the billing slab. Billing Slab is defined in mdms under ws-services-calculation folder with the WCBillingSlab. The following is the sample slab.

{ "id": "1", "buildingType": "RESIDENTIAL", "connectionType": "Metered", "calculationAttribute": "Water consumption", "minimumCharge": 100, "slabs": [ { "from": 0, "to": 10, "charge": 2, "meterCharge": 50 }, { "from": 10, "to": 20, "charge": 2.5, "meterCharge": 50 }, { "from": 20, "to": 30, "charge": 8, "meterCharge": 150 }, { "from": 30, "to": 40, "charge": 12, "meterCharge": 150 }, { "from": 40, "to": 1000000000, "charge": 15, "meterCharge": 150 } ] }, { "id": "5", "buildingType": "RESIDENTIAL", "calculationAttribute": "No. of taps", "connectionType": "Non Metered", "minimumCharge": 100, "slabs": [ { "from": 0, "to": 1000000000, "charge": 100 } ] },

If all criteria will match for that water connection this slab will use for calculation.

Estimation:

For application one-time fee, the estimation will return all the related tax head based on criteria. For estimation, all configuration is present in ws-services-calculation.

  1. FeeSlab.json

  2. PlotSizeSlab.json

  3. RoadType.json

All the above master configuration is used for estimation.

Following are the exemptions and taxes that are calculated:

  • Form fee

  • Scrutiny fee

  • Meter charge (For metered connection)

  • Other charges

  • Road cutting charges

  • One time fee

  • Security charges

  • Tax and cess

Water Charge and Tax:

Water charge is based on billing slab, for water application charge will be based on slab and tax based on master configuration.

Interest:

Below is a sample of master data JSON for interest :

{ "tenantId": "pb", "moduleName": "ws-services-calculation", "Interest": [ { "rate": 5, "minAmount": null, "applicableAfterDays":0, "flatAmount": null, "maxAmount": null, "fromFY": "2019-20", "startingDay": "1/01/2019" } ] }

Penalty:

Below is a sample of master data JSON for penalty :

{ "tenantId": "pb", "moduleName": "ws-services-calculation", "Penalty": [ { "rate": 10, "minAmount": null, "applicableAfterDays": 0, "flatAmount": null, "fromFY": "2019-20", "startingDay": "1/01/2019" } ] }

Round Off:

If the fraction is greater than equal to 0.5 the number is round up else it’s round down. eg: 100.4 will be rounded to 100 while 100.6 will be rounded to 101.

Actions & Role Action Mapping


Actions


Role Action Mapping



Demand Generation:

Once water is sent to calculator it’s tax estimates are calculated. Using this tax head estimates demand details are created. For every tax head, estimate demand generates function will create a corresponding demand detail.

Whenever _calculate API is called demand is first searched based on the connection no or application no and the demand from and to period. If demand already exists the same demand is updated else new demand is generated with consumer code as connection no or application no and demand from and to a period equal to financial year start and end period.

In case of the update if the tax head estimates change, the difference in amount for that tax head is added as new demand detail. For example, if the initial demand has one demand detail with WATER_CHARGE equal to 120

After updating if the WATER_CHARGE increases to 150 we add one more demand detail to account for the increased amount. The demand detail will be updated to:

RoundOff is bill based i.e every time bill is generated round off is adjusted so that payable amount is the whole number. Individual WS_ROUNDOFF in demand detail can be greater than 0.5 but the sum of all WS_ROUNDOFF will always be less than 0.5.

Scheduler for generating the demand(For non metered connection):

Description :

For generating the demand for non metered connection we have a feature for generating the demand in batch. The scheduler is responsible for generating the demand based on the tenant.

  • The scheduler can be hit by scheduler API or we can schedule cron job or we can put config to kubectl which will hit scheduler based on config.

  • After the scheduler been hit we will search the list of the tenant (city) present in the database.

  • After getting the tenants we will pickup tenant one by one and generate the demand for that tenant.

  • We will load the consumer codes for the tenant and push the calculation criteria to Kafka. Calculation criteria contain minimal information (We are not pushing large data to Kafka), calculation criteria contain consumer code and one boolean variable.

  • After pushing the data into Kafka we are consuming the records based on the batch configuration. Ex:-> if the batch configuration is 50 so we will consume the 50 calculation criteria at a time.

  • After consuming the record(Calculation criteria) we will process the batch for generating the demand. If the batch is successful so will log the consumer codes which have been processed.

  • If some records failed in batch so we will push the batch into dead letter batch topic. From the dead letter batch topic, we will process the batch one by one.

  • If the record is successful we will log the consumer code, If the record is failed so we will push the data into a dead letter single topic.

  • Dead letter single topic contains information about failure records in Kafka.

Use cases:

  1. If the same job trigger multiple time what will happen?

If the same job triggers multiple times we will process again as mentioned above but at the demand level we will check the demand based on consumer code and billing period, If demand already exists then we will update the demand otherwise we will create the demand.

  1. Are we maintaining success or failure status anywhere?

Currently, we are maintaining the status of failed records in Kafka.

Configuration :

We need to configure the batch size for Kafka consumer. This configuration is for how much data will be processed at a time.

 

Integration

Integration Scope

ws-calculator will be integrated with ws-service. ws-services internally invoke the ws-calculator service to calculate and generate demand for the charges.

Integration Benefits

WS calculator application is used to calculate the water application one time Fees and meter reading charges based on the different billing slabs that's why the calculation and demand generation logic will be separate out from WS service.
So in future, if calculation logic need to modify then changes can be carry out for each implementation without modifying the WS service.

Steps to Integration

  1. Once the water connection is activated for metered-connection, employee can add meter reading details using this API - /ws-calculator/meterConnection/_createwhich in-turn will generate the demand. For the Non-Metered connections, the scheduler APIs need to be called periodically to generate the demand.

  2. For the Metered Connection service, to get the previous meter reading /meterConnection/_search API is use.

  3. To Activate the Water Service application, the user needs to pay the ONE_TIME_FEE for the connection. To calculate the ONE_TIME_FEE /waterCalculator/_estimate API is use.

  4. To generate the demand for metered or non-metered water connection /waterCalculator/_calculate API is use.

  5. User can pay partial / full / advance amount for the Metered or Non-Metered connection bill. In these cases, Billing service would call back /waterCalculator/_updateDemandAPI to update the details of the demand generated.

  6. /waterCalculator/_jobscheduler API is use to generate demand for Non-metered connections. This API can be called periodically.

  7. /waterCalculator/_applyAdhocTax API is use to add Rebate or Penalty on any bill and based on that the bill amount will be adjusted.

 

Reference Docs

Doc Links

Title 

Link

API Swagger Contract

https://editor.swagger.io/?url=https://raw.githubusercontent.com/egovernments/DIGIT-OSS/master/municipal-services/docs/water-sewerage-services.yaml#!/

Water Service Document

Water Service

API List

(Note: All the API’s are in the same postman collection therefore same link is added in each row)