Refinery (المصفاة): port trips, wage claims, commission claims, wallets, variables and cards from AqabaTCS
New API slice under /api/v1/refinery (Dapper on the NAFITHTCS REFINERY_* tables), web screens under features/refinery, Dinarak and Jopetrol gateways (off by default, secrets from env), remaining-balance recalculation after the ton price correction, Excel reports (trips, operator, exchange, diesel, cards, bank). Access only through permission keys: db/refinery-permissions.sql gives the 6 screens and all action keys to PTADM (SU always allowed). Docs: docs/refinery-agent-brief.md, docs/refinery-db-objects.txt (legacy views and diesel functions), ENVIRONMENTS.md. The REFINERY_OIL import job and the daily totals email job are not ported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a318d2b2f0
commit
4066151033
|
|
@ -0,0 +1,63 @@
|
|||
-- Refinery (المصفاة) modules ported from AqabaTCS: trips, wage claims, commission claims, wallets, variables, cards.
|
||||
-- Authority: SU (always allowed by the code, needs no row) and PTADM (rows below: 6 screens + every action key).
|
||||
-- Run on a database where GRAINS_SCREEN_PERMISSIONS exists (db/grains-screen-permissions.sql). Safe to re-run. Not executed by the application.
|
||||
-- Delete a row to take a key away (the API applies it within about a minute, the browser on the next reload or sign-in).
|
||||
-- Give another role access: copy the block and change the role code.
|
||||
|
||||
INSERT INTO GRAINS_SCREEN_PERMISSIONS (ROLECODE, RESOURCE_KEY)
|
||||
SELECT 'PTADM', v.resource_key
|
||||
FROM (SELECT 'refinery.trips' AS resource_key FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.firstAdvance' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.secondAdvance' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.firstAdvanceReverse' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.secondAdvanceReverse' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.exchange' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.exchangeAudit' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.receipt' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.payment' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.activateWalletExchange' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.orangePayment' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.cashPayment' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.confirmExchange' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.print' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.report' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.operatorReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.exchangeReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.dieselReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.cardsReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.bankReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.trips.recalculateBalance' FROM dual UNION ALL
|
||||
SELECT 'refinery.wageClaims' FROM dual UNION ALL
|
||||
SELECT 'refinery.wageClaims.create' FROM dual UNION ALL
|
||||
SELECT 'refinery.wageClaims.close' FROM dual UNION ALL
|
||||
SELECT 'refinery.wageClaims.transfer' FROM dual UNION ALL
|
||||
SELECT 'refinery.wageClaims.report' FROM dual UNION ALL
|
||||
SELECT 'refinery.commissionClaims' FROM dual UNION ALL
|
||||
SELECT 'refinery.commissionClaims.create' FROM dual UNION ALL
|
||||
SELECT 'refinery.commissionClaims.complete' FROM dual UNION ALL
|
||||
SELECT 'refinery.commissionClaims.report' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets.create' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets.update' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets.activate' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets.deactivate' FROM dual UNION ALL
|
||||
SELECT 'refinery.wallets.report' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables.create' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables.update' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables.tonPriceCorrection' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables.report' FROM dual UNION ALL
|
||||
SELECT 'refinery.variables.remainingBalanceReport' FROM dual UNION ALL
|
||||
SELECT 'refinery.cards' FROM dual UNION ALL
|
||||
SELECT 'refinery.cards.create' FROM dual UNION ALL
|
||||
SELECT 'refinery.cards.activate' FROM dual UNION ALL
|
||||
SELECT 'refinery.cards.deactivate' FROM dual UNION ALL
|
||||
SELECT 'refinery.cards.report' FROM dual) v
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM GRAINS_SCREEN_PERMISSIONS p
|
||||
WHERE p.rolecode = 'PTADM' AND p.resource_key = v.resource_key);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- Check (expect 47 rows):
|
||||
-- SELECT resource_key FROM GRAINS_SCREEN_PERMISSIONS WHERE rolecode = 'PTADM' AND resource_key LIKE 'refinery.%' ORDER BY resource_key;
|
||||
|
|
@ -58,6 +58,7 @@ Apply these scripts once per database (not run by the application), in this orde
|
|||
5c. `db/role-co.sql` - new role CO with the same rights as GTO: role row (NTP schema) + copy of every GTO row in GRAINS_SCREEN_PERMISSIONS (safe to re-run)
|
||||
7. `db/grains-jobs.sql` - tables of the scheduled jobs (`GRAINS_JOBS`, `GRAINS_JOB_RUNS`), primary schema. Without it the scheduler stays idle. Jobs are then started, stopped and timed on the SU screen "المهام المجدولة" (`/jobs`); nothing runs until a job is started there. `Jobs:SchedulerEnabled=false` (set in appsettings.Development.json) switches the scheduler loop off for a process
|
||||
6. `db/gnac-finance-screens.sql` - GNAC gets claims, fines, wages, invoices and the invoice check report (safe to re-run)
|
||||
8. `db/refinery-permissions.sql` - refinery (المصفاة) modules: PTADM gets the 6 screens and every action key (47 rows); SU needs none (safe to re-run). The external services are OFF until configured: `Refinery__Dinarak__Enabled/BaseUrl/UserName/Password` (trip payment) and `Refinery__Jopetrol__Enabled/Url/UserName/Password` (wage claim ترحيل); `Refinery__Trips__MaxPaymentAmount` (default 500, unverified)
|
||||
|
||||
**Switching a feature off for everybody:** a row with `ROLECODE = 'DISABLED'` takes that resource out of the system for all users, SU
|
||||
included: the menu entry and buttons disappear and the API answers 403. It overrides every other row. Delete the row to bring the
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
# Refinery migration: shared brief for the porting agents
|
||||
|
||||
Port refinery modules of the legacy ColdFusion app **AqabaTCS** (`C:\inetpub\wwwroot\AqabaTCS_LIVE`, read-only) into NTP V2
|
||||
(.NET 10 API + Oracle 11g/Dapper + React/MUI web). Read first: `CLAUDE.md`, `docs/MIGRATION.md`, `docs/refinery-db-objects.txt`
|
||||
(text of the legacy DB views and the diesel / amount functions, already extracted), and `docs/schema/NAFITHTCS.md` sections
|
||||
`REFINERY_*`. Reference slices that show the house style: `src/NTP.Application/Grains/Registry`, `.../Orders` (BillingService),
|
||||
`src/NTP.Infrastructure/Persistence/Repositories/Grains/*`, `src/NTP.Api/Controllers/V1/Grains/RegistryController.cs`,
|
||||
`web/src/features/grains-registry` (pages, meta, strings, api hooks).
|
||||
|
||||
## Legacy layout (AqabaTCS)
|
||||
- Backend per entity: `backend/entities/<entity>/` : `*dao.cfc` (SQL), `*factory.cfc` (business rules, validation, transactions, log rows),
|
||||
`*factoryweb.cfc` (web layer: filter whitelist, role specific branches, row actions), `*bean.cfc` (fields).
|
||||
- Frontend per entity: `frontend/entities/<ENTITY>/<ENTITY>GRID`, `<ENTITY>` (form), `<ENTITY>Log` (history popup): `.js` + `.html`.
|
||||
- Menu / authority: `customtags/Menu.cfm` (entries REFINERYTRIP, REFINERY_WAGE_CLAIM, REFINERY_COMMISSION_CLAIM, REFINERY_WALLET,
|
||||
REFINERY_VARIABLES, REFINERY_CARDS). Grids read DB views (`REFINERY_*_VIEW`, text in docs/refinery-db-objects.txt); `common.getGridData`
|
||||
builds the filter SQL (look at `backend/common/common.cfc` when you need to know how a filter field maps to a column).
|
||||
- Captions (Arabic UI / message texts) are in the database: `select code, ar from ntp.lt_caption where code like 'REFINERY%'` (also
|
||||
`PUBLIC.%`, `ERROR.%`, `MESSAGE.%`, `MENU.%` for the codes you meet). **User-facing texts must be the legacy Arabic captions, verbatim.**
|
||||
|
||||
## Read-only database access (NAFITHTCS, real data)
|
||||
`dotnet "C:\Users\samers\AppData\Local\Temp\claude\d72adf472b8502c5\42c5454f-ddae-4fd6-af13-dba201a0f7ce\scratchpad\q\out\q.dll" NAFITHTCS "select ..."`
|
||||
(only SELECT / WITH; prints `|` separated rows, max 400). Use it to check columns, status codes, sample rows, views, `user_source`,
|
||||
`user_tab_columns`, `ntp.lt_caption`. Never print or copy a connection string; never write to the database; do not run SQL scripts.
|
||||
`appsettings.Local.json` is in the MAIN checkout (`C:\inetpub\wwwroot\NTP_V2\src\NTP.Api\`), not in your worktree: you cannot run the API.
|
||||
|
||||
## Rules (see CLAUDE.md too, they apply)
|
||||
- Oracle 11.2: no OFFSET/FETCH or identity, page with ROWNUM (`OracleSql.Paginate`), sequences for ids (`SEQ_REFINERY_*` exist). Dapper with
|
||||
classes that have settable properties for results. Bind by name; do not add unused DynamicParameters. Bind numbers, no `TO_CHAR` on indexed columns.
|
||||
Reuse the legacy views where it is simplest (they exist in the database) but prefer explicit SQL when the view is slow or wrong for the screen.
|
||||
- Layers: thin controllers (`src/NTP.Api/Controllers/V1/Refinery/<Module>Controller.cs`, route `api/v{version}/refinery/<module>`, `[RequirePermission(key)]`),
|
||||
services + contracts + validators + repository interfaces in `src/NTP.Application/Refinery/<Module>/`, Dapper repositories in
|
||||
`src/NTP.Infrastructure/Persistence/Repositories/Refinery/<Module>/` (class names `*Service` / `*Repository` registered by convention against `I{Name}`).
|
||||
Primary connection `IDbSession` (NAFITHTCS) holds all REFINERY_* tables; `IUnitOfWork.ExecuteInTransactionAsync` for multi-statement writes.
|
||||
Errors: `BusinessException` (422), `ForbiddenException`, `NotFoundException`, FluentValidation (400) with the legacy Arabic text.
|
||||
- The legacy `*_LOG` tables (OLD_DATA / NEW_DATA JSON, METHOD_NAME, USER_ID, USER_IP) are written on every legacy action: keep doing it
|
||||
(same method names, same JSON content as far as you can see in the factory) and port the log popup (history list + old/new view).
|
||||
Find out what legacy puts in USER_ID / CREATED_BY (numeric NTPUSERS id vs login) and use the matching `ICurrentUser` member.
|
||||
- **Authority**: ONLY `SU` (always allowed by the code) and role `PTADM` get access. Do not port the legacy role-specific branches
|
||||
(REFINERY_MGR, REFINERY_OP, EXCHANGE_OP, REFINERY_AC, OPOFF, hard-coded user ids ...). Instead: one screen key per module (already defined in
|
||||
`PermissionKeys.Refinery.cs`) and one **action key per legacy action** (e.g. `refinery.trips.firstAdvance`), declared in YOUR OWN partial file
|
||||
`src/NTP.Application/Access/PermissionKeys.Refinery.<Module>.cs` (`public static partial class PermissionKeys`). Every endpoint carries
|
||||
`[RequirePermission(...)]` with the right key; the web hides buttons with `useAuth().can(key)`. Do NOT add them to `PermissionDefaults`
|
||||
(rows in GRAINS_SCREEN_PERMISSIONS are the source; the lead writes `db/refinery-permissions.sql` from the key list you report).
|
||||
Where a legacy rule depended on the role only to narrow what a user sees, drop it and say so in your report.
|
||||
- **No secrets, no real side effects**: legacy code contains hard-coded credentials (e.g. the Jopetrol SOAP password). Never copy them. External
|
||||
calls go behind `IDinarakGateway` / `IJopetrolGateway` (`src/NTP.Application/Refinery/Integrations/RefineryGateways.cs`, already written; do not
|
||||
change the signatures) with options from configuration and `Enabled=false` by default; add the non-secret defaults to
|
||||
`src/NTP.Api/appsettings.json` (section `Refinery:...`) and say in your report which env vars hold the secrets. Never call a real endpoint.
|
||||
- Web (React 19, MUI 9): Arabic (RTL), logical CSS properties, metadata-driven `DataGrid` / `MetaForm` from `web/src/components`, strings `{ en, ar }`
|
||||
in the module's `strings.ts`, API hooks with React Query like `grains-registry/api.ts`. Put everything of a module under
|
||||
`web/src/features/refinery/<module>/` and export from `web/src/features/refinery/<module>/index.ts`:
|
||||
`export const routes: RouteObject[]` (absolute paths `/refinery/<module>...`) and `export const menuItems: MenuItem[]` (leaf entries only: key = the
|
||||
screen key, title, icon, path; the lead composes the group and `features/refinery/routes.tsx`). Do NOT create `features/refinery/routes.tsx`.
|
||||
- Port behaviour, not markup: same filters, same grid columns, same row actions, same validations and messages, same status flow. Do not port dead
|
||||
code (check callers / Menu.cfm). Cite legacy `file:line` in code comments where a rule is non-obvious.
|
||||
- Tests: xUnit in `tests/NTP.Tests/Refinery/` for pure logic (calculations, status rules, validators). `dotnet test tests/NTP.Tests`.
|
||||
|
||||
## Working environment
|
||||
- You work in your own git worktree. Do not touch the main checkout. Do NOT start the API or the dev server (ports are used by the lead).
|
||||
- First copy these uncommitted foundation files from the main checkout into the same relative paths in your worktree (they are identical for all agents):
|
||||
`src/NTP.Application/Access/PermissionDefaults.cs` (class made `partial`), `src/NTP.Application/Access/PermissionKeys.Refinery.cs`,
|
||||
`src/NTP.Application/Refinery/Integrations/RefineryGateways.cs` (all under `C:\inetpub\wwwroot\NTP_V2\`). Commit them with your work.
|
||||
- Web checks need node_modules: in your worktree `web/` create a junction to the main one: `cmd /c mklink /J node_modules C:\inetpub\wwwroot\NTP_V2\web\node_modules`
|
||||
(do not commit it; check `git status`). Then `cd web && npx tsc -b --noEmit`.
|
||||
- Build with `dotnet build src/NTP.Api` and test with `dotnet test tests/NTP.Tests` in your worktree. Everything must build and pass before you finish.
|
||||
- Shared files you may have to touch (re-read right before editing, make a minimal Edit, never rewrite): `src/NTP.Infrastructure/DependencyInjection.cs`
|
||||
(gateway registration), `src/NTP.Api/appsettings.json`. Touch nothing else outside your module folders.
|
||||
- Commit your work in the worktree branch (one commit, clear message, end it with the line `Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>`).
|
||||
Do not push.
|
||||
|
||||
## Report back (your final message, plain text, concise)
|
||||
1. Branch name and commit hash. 2. Files added / changed outside your module folders. 3. **Exact list of permission keys** you declared (screen + action keys).
|
||||
4. What you did NOT port or changed on purpose (and why). 5. Anything you could not verify (nothing was run against real data except read-only SELECTs).
|
||||
6. Open questions for the owner.
|
||||
|
|
@ -0,0 +1,983 @@
|
|||
=== VIEWS (user_views text, NAFITHTCS) ===
|
||||
|
||||
--- REFINERY_CARDS_VIEW
|
||||
select "ID","TN","CARD_NUMBER","BOX_NO","CURRENT_BALANCE","CREATION_DATE","CREATED_BY","UPDATE_DATE","UPDATED_BY","STATUS_CODE","LAST_TRIP_ID"
|
||||
from REFINERY_CARDS
|
||||
|
||||
|
||||
--- REFINERY_CARDS_LOG_VIEW
|
||||
select "ID","ENTITIY_ID","METHOD_NAME","BALANCE_BEFORE","BALANCE_AFTER","CREATED_BY",to_char( "CREATION_DATE",'dd/mm/yyyy HH24:MI') CREATION_DATE,"UPDATED_BY",to_char(LAST_UPDATE_DATE,'dd/mm/yyyy HH24:MI') LAST_UPDATE_DATE, "AMOUNT","PN"
|
||||
from REFINERY_CARDS_LOG
|
||||
|
||||
|
||||
--- REFINERY_COMMISSION_CLAIM_VIEW
|
||||
select "ID","COMMISSION_CLAIM_NO",to_char("COMMISSION_CLAIM_DATE",'dd/mm/yyyy') COMMISSION_CLAIM_DATE,
|
||||
to_char(trunc(COMMISSION_CLAIM_DATE) , 'yyyymmdd') as COMMISSION_CLAIM_DATE_STRING,
|
||||
"STATUS_CODE" ,
|
||||
(select count(id) from refinery_wage_claim tr where tr.COMMISSION_claim_id = REFINERY_COMMISSION_CLAIM.id) trip_cnt
|
||||
from REFINERY_COMMISSION_CLAIM
|
||||
|
||||
|
||||
--- REFINERY_COMMISSION_LOG_VIEW
|
||||
select n.login,t."ID",t."ENTITIY_ID",t."METHOD_NAME",to_char(t."LOG_DATE",'dd/mm/yyyy HH24:MI') LOG_DATE,t."USER_ID",t."USER_IP",t."OLD_DATA",t."NEW_DATA" from refinery_commission_claim_log t
|
||||
join ntp.ntpusers n ON
|
||||
t.user_id = n.id(+)
|
||||
order by t.id desc
|
||||
|
||||
|
||||
--- REFINERY_TRIPS_VIEW
|
||||
select REFINERY_TRIPS."ID",
|
||||
"SECOND_ADVANCE_PAYMENT",
|
||||
"FIRST_ADVANCE_PAYMENT",
|
||||
"PN",REFINERY_TRIPS."STATUS_CODE",
|
||||
to_char("DISPATCH_DATE",'dd/mm/yyyy') DISPATCH_DATE,
|
||||
to_char("ACTUAL_LOADING_DATE",'dd/mm/yyyy') ACTUAL_LOADING_DATE,
|
||||
DateToString("ACTUAL_LOADING_DATE") ACTUAL_LOADING_DATE_STRING,
|
||||
DATETOSTRING(RECEIVED_DATE) RECEIVED_DATE_STRING,
|
||||
ACTUAL_LOADING_DATE LOADING_DATE,
|
||||
"ACTUAL_LOADING_TIME",
|
||||
Datetostring("DISCHARGE_ENTRY_DATE") DISCHARGE_ENTRY_DATE_STRING,
|
||||
"LOADING_CENTER","CLIENT_NO",comp.display_name CLIENT_NAME,
|
||||
REFINERY_TRIPS."TN","TRN",REFINERY_TRIPS."NNPN","MATERIAL_NO",
|
||||
"MENAGATE_NO","EMPTY_WEIGHT",
|
||||
"GROSS_WEIGHT","NET_LOADING_WEIGHT",
|
||||
"STANDARD_UNITS_WEIGHT","LITERS_WEIGHT",
|
||||
"DENSITY","TEMPERATURE","FLAG",
|
||||
"DISCHARGE_AUTHORIZTION_NO",
|
||||
"DISCHARGE_AUTHORIZTION_YEAR",
|
||||
"DISCHARGE_ENTRY_TIME",
|
||||
"DISCHARGE_EXIT_DATE",
|
||||
"DISCHARGE_EXIT_TIME",
|
||||
"ACTUAL_GROSS_WEIGHT",
|
||||
"ACTUAL_EMPTY_WEIGHT",
|
||||
"NET_DISCHARGE_WEIGHT",
|
||||
"NET_WAGE" ,REFINERY_TRIPS.DIESEL_CHARGE,
|
||||
wa.epayment,
|
||||
|
||||
decode(paid_wallet.wallet_number,null,wa.wallet_number,paid_wallet.wallet_number) wallet_number,
|
||||
decode(paid_wallet.company_code,null,wa.company_code,paid_wallet.company_code) company_code,
|
||||
decode(paid_wallet.owner_nnpn,null,wa.owner_nnpn,paid_wallet.owner_nnpn) owner_nnpn,
|
||||
decode(paid_wallet.owner_name,null,wa.owner_name,paid_wallet.owner_name) owner_name,
|
||||
decode(paid_wallet.owner_name_english,null,wa.owner_name_english,paid_wallet.owner_name_english) owner_name_english,
|
||||
decode(paid_wallet.iban,null,wa.iban,paid_wallet.iban) iban,
|
||||
decode(paid_wallet.bank_account,null,wa.bank_account,paid_wallet.bank_account) bank_account,
|
||||
decode(paid_wallet.bank_name,null,wa.bank_name,paid_wallet.bank_name) bank_name,
|
||||
|
||||
decode(wa.id,null,'0','1') as HAVE_PAYMENT_METHOD,
|
||||
drvr_wallet.wallet_number driver_wallet_number,
|
||||
decode(REFINERY_TRIPS.WAGE_CLAIM_ID ,null,'0','1') as HAS_WAGE_CLAIM,
|
||||
RECEIVED_BY,RECEIVED_DATE,PAYMENTED_BY,PAYMENTED_DATE,
|
||||
REFINERY_TRIPS.Payment_Options,
|
||||
REFINERY_TRIPS.VOUCHER_SERIAL_NUMBER,
|
||||
|
||||
--Datetostring("PAYMENTED_DATE") ,
|
||||
|
||||
--decode(REFINERY_TRIPS.Status_Code,'EXCHANGED',Datetostring(REFINERY_TRIPS.PAYMENTED_DATE),'READY_TO_PAY',Datetostring(REFINERY_TRIPS.Received_Date),
|
||||
--'DISCHARGED',Datetostring(REFINERY_TRIPS.ACTUAL_LOADING_DATE)) PAYMENTED_DATE_STRING,
|
||||
|
||||
Datetostring(REFINERY_TRIPS.ACTUAL_LOADING_DATE) PAYMENTED_DATE_STRING,
|
||||
|
||||
DISCHARGE_ENTRY_DATE,to_char("DISCHARGE_ENTRY_DATE",'dd/mm/yyyy') DISCHARGE_ENTRY_DATE_DISPLAY,
|
||||
to_char("PAYMENTED_DATE",'dd/mm/yyyy') PAYMENTED_DATE_DISPLAY,
|
||||
"WATER_AMOUNT","SEDIMENT_AMOUNT",REFINERY_TRIPS."TRIP_STATUS",REFINERY_TRIPS."USER_ID",REFINERY_TRIPS."LAST_UPDATE_DATE","DAY_TIME","PROGRAM_ID","WORK_STN_ID","EXCHANGE_CLAIM_NO","PAID_AMOUNT_WATER",
|
||||
WAGE_CLAIM_ID,
|
||||
rwc.wage_claim_no,
|
||||
info.name_ar DRVR,
|
||||
REVERSE_PAYMENT,
|
||||
S.FIRSTNAME RECEIVED_BY_NAME,
|
||||
LT.AR STATUS_CODE_AR,remarks,
|
||||
REFINERY_TRIPS.Loading_No,
|
||||
(NET_LOADING_WEIGHT - net_discharge_weight) as "WEIGHT_DIIERANCE",
|
||||
CARD.CARD_NUMBER,CARD.CURRENT_BALANCE,
|
||||
decode(wa.epayment,null,unistr('\0644\0627\0020\064A\0648\062C\062F'),'0',unistr('\062D\0648\0627\0644\0629'),'1',unistr('\0627\0644\0643\062A\0631\0648\0646\064A')) as PAYMENT_METHOD,
|
||||
--decode(wa.epayment,null,0,'0',1,'1',2) as PAYMENT_METHOD_CODE,
|
||||
decode(REFINERY_TRIPS.PAYMENT_OPTIONS,NULL,decode(wa.epayment,null,0,'0',1,'1',2),'CACH_PAYMENT',3) as PAYMENT_METHOD_CODE,
|
||||
Datetostring("PAYMENTED_DATE") PAYMENTED_DATE_STRING_SEARCH,
|
||||
|
||||
REFINERY_TRIPS.DINARAK_REFERENCE_ID , REFINERY_WALLET_ID ,
|
||||
(CASE WHEN WATER_AMOUNT > 0 THEN 1
|
||||
ELSE 0 END) as WATER_EXIST,
|
||||
|
||||
decode(paid_wallet.epayment,null,'','0',unistr('\062D\0648\0627\0644\0629'),'1',unistr('\0627\0644\0643\062A\0631\0648\0646\064A')) as paid_epayment
|
||||
,"TRIP_NET_WAGE" , "REMAINING_BALANCE" ,penalty_amount , penalty_quantity
|
||||
|
||||
from REFINERY_TRIPS,ntp.lt_caption lt,refinery_wage_claim rwc,drivers_info info,refinery_company comp,REFINERY_WALLET wa,NTP.NTPUSERS S,REFINERY_WALLET drvr_wallet,
|
||||
REFINERY_CARDS CARD,REFINERY_WALLET paid_wallet
|
||||
where LT.CODE(+) = 'REFINERYTRIP.STATUS.'|| REFINERY_TRIPS.STATUS_CODE
|
||||
and rwc.id(+)=REFINERY_TRIPS.Wage_Claim_Id
|
||||
and wa.tn(+)=REFINERY_TRIPS.tn
|
||||
and info.nnpn(+)=REFINERY_TRIPS.Nnpn
|
||||
and info.status_code(+) = 'COMPLETED'
|
||||
and comp.code(+) = CLIENT_NO
|
||||
AND s.id(+)=REFINERY_TRIPS.Received_By
|
||||
and to_char(drvr_wallet.driver_nnpn(+))=REFINERY_TRIPS.Nnpn
|
||||
and CARD.TN(+) = REFINERY_TRIPS.tn
|
||||
AND card.Status_Code(+) = 'ACTIVE'
|
||||
and wa.status_code(+) = 'ACTIVE'
|
||||
and drvr_wallet.Status_Code(+)='ACTIVE'
|
||||
and paid_wallet.id(+)=REFINERY_TRIPS.Refinery_Wallet_Id
|
||||
|
||||
|
||||
--- REFINERY_TRIPS_LOG_VIEW
|
||||
select n.login,t."ID",t."ENTITIY_ID",t."METHOD_NAME",to_char(t."LOG_DATE",'dd/mm/yyyy HH24:MI') LOG_DATE,t."USER_ID",t."USER_IP",t."OLD_DATA",t."NEW_DATA" from refinery_trips_LOG t
|
||||
join ntp.ntpusers n ON
|
||||
t.user_id = n.id(+)
|
||||
order by t.id desc
|
||||
|
||||
|
||||
--- REFINERY_VARIABLES_VIEW
|
||||
select rownum ID,GROUP_ID ,to_char("START_DATE",'yyyy-mm-dd') "START_DATE" , Datetostring("START_DATE") START_DATE_STRING, to_char("END_DATE",'yyyy-mm-dd') "END_DATE", Datetostring("END_DATE") END_DATE_STRING,"DIESEL_LITER_PRICE","TON_WAGE","TON_PRICE","DRIVER_TIP","PERMIT_DISPATCH","WAYBILL_FEE","COMMISSION","TOLERANCE_PERCENTAGE","FIRST_ADVANCE_PAYMENT" /*, TON_PRICE_CORRECTION */ from (
|
||||
select start_date,end_date,key_name,key_value ,GROUP_ID from REFINERY_VARIABLES where KEY_NAME != 'AUTDIT_MODE'
|
||||
)
|
||||
pivot
|
||||
(
|
||||
sum(key_value)
|
||||
for key_name in ('DIESEL_LITER_PRICE' DIESEL_LITER_PRICE,'TON_WAGE' TON_WAGE,'TON_PRICE' TON_PRICE,'DRIVER_TIP' DRIVER_TIP,'PERMIT_DISPATCH' PERMIT_DISPATCH,'WAYBILL_FEE' WAYBILL_FEE,'COMMISSION' COMMISSION,'TOLERANCE_PERCENTAGE' TOLERANCE_PERCENTAGE, 'FIRST_ADVANCE_PAYMENT' FIRST_ADVANCE_PAYMENT /* , 'TON_PRICE_CORRECTION' TON_PRICE_CORRECTION */)
|
||||
)
|
||||
order by 1
|
||||
|
||||
|
||||
--- REFINERY_WAGE_CLAIM_VIEW
|
||||
select REFINERY_WAGE_CLAIM."ID","WAGE_CLAIM_NO",to_char("WAGE_CLAIM_DATE",'dd/mm/yyyy') WAGE_CLAIM_DATE,REFINERY_WAGE_CLAIM."STATUS_CODE" ,COMMISSION_CLAIM_ID,
|
||||
decode(REFINERY_WAGE_CLAIM.COMMISSION_CLAIM_ID ,null,'0','1') as HAS_COMMISSION_CLAIM,
|
||||
(select count(id) from refinery_trips tr where tr.wage_claim_id = REFINERY_WAGE_CLAIM.id) trip_cnt,comm.commission_claim_no
|
||||
from REFINERY_WAGE_CLAIM,refinery_commission_claim comm
|
||||
where comm.id(+)=REFINERY_WAGE_CLAIM.COMMISSION_CLAIM_ID
|
||||
|
||||
|
||||
--- REFINERY_WAGE_CLAIM_LOG_VIEW
|
||||
select n.login,t."ID",t."ENTITIY_ID",t."METHOD_NAME",to_char(t."LOG_DATE",'dd/mm/yyyy HH24:MI') LOG_DATE,t."USER_ID",t."USER_IP",t."OLD_DATA",t."NEW_DATA" from refinery_wage_claim_log t
|
||||
join ntp.ntpusers n ON
|
||||
t.user_id = n.id(+)
|
||||
order by t.id desc
|
||||
|
||||
|
||||
--- REFINERY_WALLET_VIEW
|
||||
select "ID"
|
||||
,"TN"
|
||||
,"COMPANY_CODE"
|
||||
,"EPAYMENT"
|
||||
,decode("OWNER_NNPN",null,DRIVER_NNPN,OWNER_NNPN) OWNER_NNPN
|
||||
,decode("OWNER_NNPN",null,DRIVER_NNPN,OWNER_NNPN) NNPN
|
||||
,"WALLET_NUMBER"
|
||||
,decode("OWNER_NAME",null,DRIVER_NAME,OWNER_NAME) OWNER_NAME
|
||||
,"CREATION_DATE"
|
||||
,"DRIVER_NAME"
|
||||
,"DRIVER_NNPN"
|
||||
,"IBAN"
|
||||
,"BANK_ACCOUNT"
|
||||
,"BANK_NAME"
|
||||
,"CREATED_BY"
|
||||
,"UPDATE_DATE"
|
||||
,"UPDATED_BY"
|
||||
,"STATUS_CODE"
|
||||
,"BANK_BRANCH","OWNER_NAME_ENGLISH",
|
||||
----,DECODE("EPAYMENT",0,unistr('\062D\0648\0627\0644\0629'),unistr('\0645\062D\0641\0638\0629\0020\0627\0644\0643\062A\0631\0648\0646\064A\0629')) PAYMENT_METHOD,
|
||||
( CASE
|
||||
WHEN DRIVER_NNPN is not null THEN 'DRAIVER_WALLET'
|
||||
WHEN EPAYMENT = 0 THEN 'BANK'
|
||||
|
||||
ELSE 'EWALLET'
|
||||
END ) PAYMENT_METHOD
|
||||
from REFINERY_WALLET
|
||||
|
||||
|
||||
--- REFINERY_WALLET_LOG_VIEW
|
||||
select n.login,t."ID",t."ENTITIY_ID",t."METHOD_NAME",to_char(t."LOG_DATE",'dd/mm/yyyy HH24:MI') LOG_DATE,t."USER_ID",t."USER_IP",t."OLD_DATA",t."NEW_DATA" from refinery_WALLET_LOG t
|
||||
join ntp.ntpusers n ON
|
||||
t.user_id = n.id(+)
|
||||
order by t.id desc
|
||||
|
||||
|
||||
--- REFINERY_DIESEL_REPORT_VIEW
|
||||
select T.ID, t.pn,t.tn,T.STATUS_CODE,
|
||||
t.discharge_authoriztion_no,c.creation_date,
|
||||
s.firstname,
|
||||
t.DIESEL_CHARGE,
|
||||
|
||||
decode (c.method_name,'FIRST_ADVANCED_PAYMENT',unistr('\0634\062D\0646\0020\0644\0644\062A\062D\0645\064A\0644'),'SECOND_ADVANCED_PAYMENT',unistr('\0634\062D\0646\0020\0644\0644\062A\0641\0631\064A\063A'),'SECOND_ADVANCED_PAYMENT_REVERSE',unistr('\0627\0644\063A\0627\0621\0020\0634\062D\0646\0020\0627\0644\062A\0641\0631\064A\063A'),'FIRST_ADVANCED_PAYMENT_REVERSE',unistr('\0627\0644\063A\0627\0621\0020\0634\062D\0646\0020\0627\0644\062A\062D\0645\064A\0644')) method_name,
|
||||
|
||||
c.balance_before,c.balance_after,C.AMOUNT from refinery_trips_view t,refinery_cards_log c,NTP.NTPUSERS s
|
||||
|
||||
where c.PN=t.PN
|
||||
and s.id(+)=to_number(c.created_by)
|
||||
|
||||
ORDER BY CREATION_DATE
|
||||
|
||||
|
||||
--- REFINERY_CLAIMS_REPORT_VIEW
|
||||
select t."ID",t.WAGE_CLAIM_ID, t.STATUS_CODE,TRIP_STATUS, "DISCHARGE_AUTHORIZTION_NO",discharge_authoriztion_year, to_char(Discharge_Entry_Date , 'dd/mm/yyyy' ) Discharge_Entry_Date, client_no, '' client_NAME,'' serial,loading_no , to_char(actual_loading_date , 'dd/mm/yyyy') actual_loading_date , NET_LOADING_WEIGHT,WATER_AMOUNT , NET_DISCHARGE_WEIGHT
|
||||
,(NET_LOADING_WEIGHT - net_discharge_weight) as "WEIGHT_DIIERANCE",
|
||||
TON_WAGE ,CALCULATED_QUANTITY_TON ,QUANTITY_WAGE ,w.wage_claim_no, TOLERANCE_QUANTITY ,
|
||||
(CASE
|
||||
WHEN Water_amount > 0 THEN
|
||||
'YES'
|
||||
ELSE 'NO'
|
||||
END) WATER_EXIST,
|
||||
|
||||
|
||||
CASE
|
||||
WHEN (NET_LOADING_WEIGHT - net_discharge_weight) < TOLERANCE_QUANTITY THEN
|
||||
ltrim(to_char(0, '0.000'))
|
||||
ELSE ltrim(to_char(PENALTY_QUANTITY, '9999999.999'))
|
||||
END PENALTY_QUANTITY,
|
||||
|
||||
--ltrim(to_char(PENALTY_QUANTITY, '9999999.999')) PENALTY_QUANTITY ,
|
||||
ltrim(to_char(TON_PRICE, '9999999.999')) TON_PRICE ,
|
||||
PENALTY_AMOUNT,
|
||||
ltrim(to_char(DRIVER_TIP, '9999999.999')) DRIVER_TIP ,
|
||||
ltrim(to_char(PERMIT_DISPATCH, '9999999.999')) PERMIT_DISPATCH ,
|
||||
WAYBILL_FEE,DIESEL_LITER_PRICE,
|
||||
ltrim(to_char((select sum(amount) from REFINERY_CARDS_LOG where pn = t.pn),'9999999.99')) advance_payment_FOR_DIESEL,
|
||||
ltrim(to_char(COMMISSION, '9999999.999')) COMMISSION ,
|
||||
ltrim(to_char(NET_WAGE, '9999999.999')) NET_WAGE,T.TN,info.name_ar DRVR
|
||||
|
||||
from REFINERY_TRIPS t,refinery_wage_claim w,DRIVERS_INFO info
|
||||
|
||||
where w.id=t.wage_claim_id
|
||||
and info.nnpn(+)=t.Nnpn
|
||||
and info.status_code(+) = 'COMPLETED'
|
||||
|
||||
|
||||
--- REFINERY_CLAIMS_REPORT
|
||||
select "ID",STATUS_CODE,TRIP_STATUS, "DISCHARGE_AUTHORIZTION_NO",discharge_authoriztion_year, Discharge_Entry_Date, client_no, '' client_NAME,'' serial,loading_no , actual_loading_date, NET_LOADING_WEIGHT,Water_amount , net_discharge_weight ,(NET_LOADING_WEIGHT - net_discharge_weight) as "WEIGHT_DIIERANCE",
|
||||
TON_WAGE ,CALCULATED_QUANTITY_TON ,QUANTITY_WAGE , TOLERANCE_QUANTITY ,
|
||||
(CASE
|
||||
WHEN Water_amount > 0 THEN
|
||||
'YES'
|
||||
ELSE 'NO'
|
||||
END) WATER_EXIST,
|
||||
ltrim(to_char(PENALTY_QUANTITY, '9999999.99')) PENALTY_QUANTITY ,
|
||||
ltrim(to_char(TON_PRICE, '9999999.99')) TON_PRICE ,
|
||||
PENALTY_AMOUNT,
|
||||
ltrim(to_char(DRIVER_TIP, '9999999.99')) DRIVER_TIP ,
|
||||
ltrim(to_char(PERMIT_DISPATCH, '9999999.99')) PERMIT_DISPATCH ,
|
||||
WAYBILL_FEE,DIESEL_LITER_PRICE,
|
||||
ltrim(to_char((select sum(amount) from REFINERY_CARDS_LOG where pn = REFINERY_TRIPS.pn),'9999999.99')) advance_payment_FOR_DIESEL,
|
||||
COMMISSION ,NET_WAGE
|
||||
from REFINERY_TRIPS
|
||||
|
||||
|
||||
=== FUNCTIONS ===
|
||||
|
||||
--- CALCULATEREFINARYDIESEL
|
||||
FUNCTION "CALCULATEREFINARYDIESEL" (RefineryId in numeric)
|
||||
|
||||
return float as
|
||||
|
||||
|
||||
|
||||
DieslCount number;
|
||||
|
||||
LoadingDate date;
|
||||
|
||||
CURRENT_BALANCE float;
|
||||
|
||||
DIESEL_LITER_PRICE float;
|
||||
|
||||
FIRST_ADVANCE_PAYMENT float;
|
||||
|
||||
begin
|
||||
|
||||
|
||||
|
||||
select LOADING_DATE,CURRENT_BALANCE
|
||||
|
||||
into LoadingDate,CURRENT_BALANCE
|
||||
|
||||
from refinery_trips_view where id = RefineryId;
|
||||
|
||||
|
||||
|
||||
SELECT ( select DIESEL_CHARGE from REFINERY_TRIPS where ID = RefineryId)
|
||||
|
||||
into DieslCount FROM DUAL;
|
||||
|
||||
|
||||
|
||||
select key_value into FIRST_ADVANCE_PAYMENT
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'FIRST_ADVANCE_PAYMENT'
|
||||
|
||||
and sysdate between start_date and end_date +1 ;
|
||||
|
||||
|
||||
|
||||
if DieslCount = 0 then -- No First Payment
|
||||
|
||||
return FIRST_ADVANCE_PAYMENT+CURRENT_BALANCE;
|
||||
|
||||
else if DieslCount = 1 then -- No Second Payment
|
||||
|
||||
|
||||
|
||||
-- Get Liter current price
|
||||
|
||||
select key_value into DIESEL_LITER_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DIESEL_LITER_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
|
||||
|
||||
return (DIESEL_LITER_PRICE * 350)+CURRENT_BALANCE-FIRST_ADVANCE_PAYMENT;
|
||||
|
||||
else
|
||||
|
||||
return CURRENT_BALANCE;
|
||||
|
||||
end if;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
end CalculateRefinaryDiesel;
|
||||
|
||||
|
||||
--- CALCULATEREFINARYAMOUNT
|
||||
FUNCTION "CALCULATEREFINARYAMOUNT" (RefineryId in numeric)
|
||||
|
||||
return float as
|
||||
|
||||
FIRST_ADVANCE_PAYMENT float;
|
||||
|
||||
DIESEL_LITER_PRICE float;
|
||||
|
||||
TON_WAGE float;
|
||||
|
||||
TON_PRICE float;
|
||||
|
||||
DRIVER_TIP float;
|
||||
|
||||
PERMIT_DISPATCH float;
|
||||
|
||||
WAYBILL_FEE float;
|
||||
|
||||
COMMISSION float;
|
||||
|
||||
TOLERANCE_PERCENTAGE float;
|
||||
|
||||
NetLoadingWeight int;
|
||||
|
||||
NetDischargeWeight int;
|
||||
|
||||
CalculatedAmount float;
|
||||
|
||||
WaterAmount int;
|
||||
|
||||
FineQuantity float;
|
||||
|
||||
AllowQuantity float;
|
||||
|
||||
LoadingDate Date;
|
||||
|
||||
truckNumber int;
|
||||
|
||||
REMAINING_BALANCE float;
|
||||
|
||||
begin
|
||||
|
||||
select tn,net_loading_weight,
|
||||
|
||||
net_discharge_weight,
|
||||
|
||||
water_amount,
|
||||
|
||||
actual_loading_date
|
||||
|
||||
into truckNumber,NetLoadingWeight, NetDischargeWeight, WaterAmount, LoadingDate
|
||||
|
||||
from refinery_trips
|
||||
|
||||
where id = RefineryId;
|
||||
|
||||
select key_value
|
||||
|
||||
into FIRST_ADVANCE_PAYMENT
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'FIRST_ADVANCE_PAYMENT'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DIESEL_LITER_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DIESEL_LITER_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_WAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_WAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DRIVER_TIP
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DRIVER_TIP'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into PERMIT_DISPATCH
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'PERMIT_DISPATCH'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into WAYBILL_FEE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'WAYBILL_FEE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into COMMISSION
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'COMMISSION'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TOLERANCE_PERCENTAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TOLERANCE_PERCENTAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
|
||||
|
||||
AllowQuantity := FLOOR(NetLoadingWeight * TOLERANCE_PERCENTAGE);
|
||||
|
||||
|
||||
|
||||
FineQuantity := (NetLoadingWeight - NetDischargeWeight - WaterAmount);
|
||||
|
||||
|
||||
|
||||
IF FineQuantity <= AllowQuantity THEN
|
||||
|
||||
FineQuantity := 0;
|
||||
|
||||
else
|
||||
|
||||
FineQuantity := FineQuantity - AllowQuantity;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
FineQuantity := (FineQuantity / 1000) * TON_PRICE;
|
||||
|
||||
|
||||
|
||||
IF WaterAmount >= (NetLoadingWeight - NetDischargeWeight) THEN
|
||||
|
||||
CalculatedAmount := (NetLoadingWeight) / 1000;
|
||||
|
||||
ELSE
|
||||
|
||||
CalculatedAmount := (NetDischargeWeight + WaterAmount) / 1000;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
CalculatedAmount := (CalculatedAmount * TON_WAGE) - FineQuantity -
|
||||
|
||||
DRIVER_TIP - PERMIT_DISPATCH - WAYBILL_FEE -
|
||||
|
||||
(DIESEL_LITER_PRICE * 350) - COMMISSION;
|
||||
|
||||
|
||||
|
||||
--- calcualte amount after remaining balance
|
||||
|
||||
select remaining_balance
|
||||
|
||||
into REMAINING_BALANCE
|
||||
|
||||
from REFINERY_REMAINING_BALANCE
|
||||
|
||||
where tn = truckNumber ;
|
||||
|
||||
CalculatedAmount := CalculatedAmount +REMAINING_BALANCE;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return ROUND(CalculatedAmount, 3);
|
||||
|
||||
|
||||
|
||||
end CalculateRefinaryAmount;
|
||||
|
||||
|
||||
--- CALCULATEREFINARYAMOUNT6
|
||||
FUNCTION "CALCULATEREFINARYAMOUNT6" (RefineryId in numeric)
|
||||
|
||||
return float as
|
||||
|
||||
FIRST_ADVANCE_PAYMENT float;
|
||||
|
||||
DIESEL_LITER_PRICE float;
|
||||
|
||||
TON_WAGE float;
|
||||
|
||||
TON_PRICE float;
|
||||
|
||||
DRIVER_TIP float;
|
||||
|
||||
PERMIT_DISPATCH float;
|
||||
|
||||
WAYBILL_FEE float;
|
||||
|
||||
COMMISSION float;
|
||||
|
||||
TOLERANCE_PERCENTAGE float;
|
||||
|
||||
NetLoadingWeight int;
|
||||
|
||||
NetDischargeWeight int;
|
||||
|
||||
CalculatedAmount float;
|
||||
|
||||
WaterAmount int;
|
||||
|
||||
FineQuantity float;
|
||||
|
||||
AllowQuantity float;
|
||||
|
||||
LoadingDate Date;
|
||||
|
||||
truckNumber int;
|
||||
|
||||
REMAINING_BALANCE float;
|
||||
|
||||
begin
|
||||
|
||||
select tn,net_loading_weight,
|
||||
|
||||
net_discharge_weight,
|
||||
|
||||
water_amount,
|
||||
|
||||
actual_loading_date
|
||||
|
||||
into truckNumber,NetLoadingWeight, NetDischargeWeight, WaterAmount, LoadingDate
|
||||
|
||||
from refinery_trips
|
||||
|
||||
where id = RefineryId;
|
||||
|
||||
select key_value
|
||||
|
||||
into FIRST_ADVANCE_PAYMENT
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'FIRST_ADVANCE_PAYMENT'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DIESEL_LITER_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DIESEL_LITER_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_WAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_WAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DRIVER_TIP
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DRIVER_TIP'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into PERMIT_DISPATCH
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'PERMIT_DISPATCH'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into WAYBILL_FEE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'WAYBILL_FEE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into COMMISSION
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'COMMISSION'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TOLERANCE_PERCENTAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TOLERANCE_PERCENTAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
|
||||
|
||||
AllowQuantity := FLOOR(NetLoadingWeight * TOLERANCE_PERCENTAGE);
|
||||
|
||||
|
||||
|
||||
FineQuantity := (NetLoadingWeight - NetDischargeWeight - WaterAmount);
|
||||
|
||||
|
||||
|
||||
IF FineQuantity <= AllowQuantity THEN
|
||||
|
||||
FineQuantity := 0;
|
||||
|
||||
else
|
||||
|
||||
FineQuantity := FineQuantity - AllowQuantity;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
FineQuantity := (FineQuantity / 1000) * TON_PRICE;
|
||||
|
||||
|
||||
|
||||
IF WaterAmount >= (NetLoadingWeight - NetDischargeWeight) THEN
|
||||
|
||||
CalculatedAmount := (NetLoadingWeight) / 1000;
|
||||
|
||||
ELSE
|
||||
|
||||
CalculatedAmount := (NetDischargeWeight + WaterAmount) / 1000;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
CalculatedAmount := (CalculatedAmount * TON_WAGE) - FineQuantity -
|
||||
|
||||
DRIVER_TIP - PERMIT_DISPATCH - WAYBILL_FEE -
|
||||
|
||||
(DIESEL_LITER_PRICE * 350) - COMMISSION;
|
||||
|
||||
|
||||
|
||||
--- calcualte amount after remaining balance
|
||||
|
||||
select remaining_balance
|
||||
|
||||
into REMAINING_BALANCE
|
||||
|
||||
from REFINERY_REMAINING_BALANCE
|
||||
|
||||
where tn = truckNumber ;
|
||||
|
||||
CalculatedAmount := CalculatedAmount +REMAINING_BALANCE;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return ROUND(CalculatedAmount, 3);
|
||||
|
||||
|
||||
|
||||
end CalculateRefinaryAmount6;
|
||||
|
||||
|
||||
--- CALCULATEREFINARYAMOUNTREPORT
|
||||
FUNCTION "CALCULATEREFINARYAMOUNTREPORT" (RefineryId in numeric,calType in numeric)
|
||||
|
||||
return float as
|
||||
|
||||
FIRST_ADVANCE_PAYMENT float;
|
||||
|
||||
DIESEL_LITER_PRICE float;
|
||||
|
||||
TON_WAGE float;
|
||||
|
||||
TON_PRICE float;
|
||||
|
||||
DRIVER_TIP float;
|
||||
|
||||
PERMIT_DISPATCH float;
|
||||
|
||||
WAYBILL_FEE float;
|
||||
|
||||
COMMISSION float;
|
||||
|
||||
TOLERANCE_PERCENTAGE float;
|
||||
|
||||
NetLoadingWeight int;
|
||||
|
||||
NetDischargeWeight int;
|
||||
|
||||
CalculatedAmount float;
|
||||
|
||||
WaterAmount int;
|
||||
|
||||
FineQuantity float;
|
||||
|
||||
AllowQuantity float;
|
||||
|
||||
LoadingDate Date;
|
||||
|
||||
begin
|
||||
|
||||
|
||||
|
||||
select net_loading_weight,
|
||||
|
||||
net_discharge_weight,
|
||||
|
||||
water_amount,
|
||||
|
||||
actual_loading_date
|
||||
|
||||
into NetLoadingWeight, NetDischargeWeight, WaterAmount, LoadingDate
|
||||
|
||||
from refinery_trips
|
||||
|
||||
where id = RefineryId;
|
||||
|
||||
select key_value
|
||||
|
||||
into FIRST_ADVANCE_PAYMENT
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'FIRST_ADVANCE_PAYMENT'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DIESEL_LITER_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DIESEL_LITER_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_WAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_WAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TON_PRICE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TON_PRICE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into DRIVER_TIP
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'DRIVER_TIP'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into PERMIT_DISPATCH
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'PERMIT_DISPATCH'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into WAYBILL_FEE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'WAYBILL_FEE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into COMMISSION
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'COMMISSION'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
select key_value
|
||||
|
||||
into TOLERANCE_PERCENTAGE
|
||||
|
||||
from refinery_variables
|
||||
|
||||
where KEY_NAME = 'TOLERANCE_PERCENTAGE'
|
||||
|
||||
and LoadingDate between start_date and end_date;
|
||||
|
||||
|
||||
|
||||
AllowQuantity := FLOOR(NetLoadingWeight * TOLERANCE_PERCENTAGE);
|
||||
|
||||
|
||||
|
||||
FineQuantity := (NetLoadingWeight - NetDischargeWeight - WaterAmount);
|
||||
|
||||
|
||||
|
||||
IF FineQuantity <= AllowQuantity THEN
|
||||
|
||||
FineQuantity := 0;
|
||||
|
||||
else
|
||||
|
||||
FineQuantity := FineQuantity - AllowQuantity;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
FineQuantity := (FineQuantity / 1000) * TON_PRICE;
|
||||
|
||||
|
||||
|
||||
IF WaterAmount >= (NetLoadingWeight - NetDischargeWeight) THEN
|
||||
|
||||
CalculatedAmount := (NetLoadingWeight) / 1000;
|
||||
|
||||
ELSE
|
||||
|
||||
CalculatedAmount := (NetDischargeWeight + WaterAmount) / 1000;
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
if calType = 0 then
|
||||
|
||||
CalculatedAmount := (CalculatedAmount * TON_WAGE) - FineQuantity -
|
||||
|
||||
DRIVER_TIP - PERMIT_DISPATCH - WAYBILL_FEE -
|
||||
|
||||
(DIESEL_LITER_PRICE * 350) - COMMISSION;
|
||||
|
||||
|
||||
|
||||
return ROUND(CalculatedAmount, 4);
|
||||
|
||||
|
||||
|
||||
else
|
||||
|
||||
|
||||
|
||||
return ROUND(CalculatedAmount*TON_WAGE, 4);
|
||||
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
end CalculateRefinaryAmountReport;
|
||||
|
||||
|
|
@ -138,6 +138,22 @@ public sealed class TripsController(
|
|||
return File(f.Content, f.ContentType, f.FileName);
|
||||
}
|
||||
|
||||
[HttpGet("reports/operator")]
|
||||
[RequirePermission(PermissionKeys.RefineryTripsOperatorReport)]
|
||||
public async Task<IActionResult> OperatorReport([FromQuery] TripQuery query, CancellationToken ct)
|
||||
{
|
||||
var f = await reports.OperatorAsync(query, ct);
|
||||
return File(f.Content, f.ContentType, f.FileName);
|
||||
}
|
||||
|
||||
[HttpGet("reports/exchange")]
|
||||
[RequirePermission(PermissionKeys.RefineryTripsExchangeReport)]
|
||||
public async Task<IActionResult> ExchangeReport([FromQuery] TripQuery query, CancellationToken ct)
|
||||
{
|
||||
var f = await reports.ExchangeAsync(query, ct);
|
||||
return File(f.Content, f.ContentType, f.FileName);
|
||||
}
|
||||
|
||||
[HttpGet("reports/diesel")]
|
||||
[RequirePermission(PermissionKeys.RefineryTripsDieselReport)]
|
||||
public async Task<IActionResult> DieselReport([FromQuery] DieselReportQuery query, CancellationToken ct)
|
||||
|
|
|
|||
|
|
@ -61,5 +61,17 @@
|
|||
"ConnectionTimeoutSeconds": 15,
|
||||
"StatementCacheSize": 50,
|
||||
"CommandTimeoutSeconds": 30
|
||||
},
|
||||
|
||||
// Refinery (المصفاة). Dinarak is the e-wallet payment API used by the trip action "صرف" (legacy RefinaryDinarakApi.cfc).
|
||||
// Off here: while Enabled is false nothing is called (the action answers that the service is disabled). UserName / Password are SECRETS:
|
||||
// env vars Refinery__Dinarak__UserName / Refinery__Dinarak__Password (server .env); BaseUrl is set per environment
|
||||
// (Refinery__Dinarak__BaseUrl). MaxPaymentAmount is the largest net wage a payment action accepts (UNVERIFIED legacy value, caption says 500).
|
||||
"Refinery": {
|
||||
"Dinarak": { "Enabled": false, "BaseUrl": "", "TimeoutSeconds": 30 },
|
||||
// Jopetrol claim web service used by the wage claim "ترحيل" action: OFF, nothing is called while Enabled is false.
|
||||
// UserName / Password are secrets: env vars Refinery__Jopetrol__UserName / Refinery__Jopetrol__Password (server .env), never in a file.
|
||||
"Jopetrol": { "Enabled": false, "Url": "http://fueltrans.jopetrol.com.jo:6060/TransportPmt/TransportPaymentWS.asmx", "TimeoutSeconds": 30 },
|
||||
"Trips": { "MaxPaymentAmount": 500 }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ public static partial class PermissionKeys
|
|||
public const string RefineryTripsConfirmExchange = "refinery.trips.confirmExchange"; // CONFIRM_EXCHANGE
|
||||
public const string RefineryTripsPrint = "refinery.trips.print"; // print (cash voucher)
|
||||
public const string RefineryTripsReport = "refinery.trips.report"; // report (trips excel)
|
||||
public const string RefineryTripsOperatorReport = "refinery.trips.operatorReport"; // report(), REFINERY_OP column set
|
||||
public const string RefineryTripsExchangeReport = "refinery.trips.exchangeReport"; // report(), EXCHANGE_OP column set
|
||||
public const string RefineryTripsDieselReport = "refinery.trips.dieselReport"; // REFINERY_DIESEL_REPORT_VIEW report
|
||||
public const string RefineryTripsCardsReport = "refinery.trips.cardsReport"; // refineryCardsReport
|
||||
public const string RefineryTripsBankReport = "refinery.trips.bankReport"; // refineryBankReport
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ namespace NTP.Application.Refinery.Trips;
|
|||
public interface ITripReportService
|
||||
{
|
||||
Task<TripExportFile> TripsAsync(TripQuery query, CancellationToken ct);
|
||||
Task<TripExportFile> OperatorAsync(TripQuery query, CancellationToken ct);
|
||||
Task<TripExportFile> ExchangeAsync(TripQuery query, CancellationToken ct);
|
||||
Task<TripExportFile> DieselAsync(DieselReportQuery query, CancellationToken ct);
|
||||
Task<TripExportFile> CardsAsync(string? tn, CancellationToken ct);
|
||||
Task<TripExportFile> BankAsync(BankReportQuery query, CancellationToken ct);
|
||||
|
|
@ -68,6 +70,36 @@ public sealed class TripReportService(ITripRepository trips) : ITripReportServic
|
|||
return Xlsx("refinery-trips", new ExportTable(["شاشة الارساليات"], headers, data));
|
||||
}
|
||||
|
||||
/// <summary>factoryweb.report, REFINERY_OP column set (lines 825-870): form no., truck, net wage, paid / received dates and receiver.
|
||||
/// The legacy limit to the trips the user received himself is a role rule and is not ported.</summary>
|
||||
public async Task<TripExportFile> OperatorAsync(TripQuery query, CancellationToken ct)
|
||||
{
|
||||
TripQueryService.ValidateRanges(query);
|
||||
var rows = await trips.ReportAsync(query, ct);
|
||||
var data = rows.Select((r, i) => (IReadOnlyList<object?>)
|
||||
[i + 1, r.DischargeAuthNo, r.Tn, r.NetWage, Day(r.PaymentedDate), Day(r.ReceivedDate), r.ReceivedByName]).ToList();
|
||||
string[] headers = ["متسلسل", "رقم النموذج", "رقم القاطرة", "صافي قيمة الصرف الفعلي", "تاريخ الدفع", "تاريخ الاستلام", "اسم المستلم"];
|
||||
return Xlsx("refinery-trips-operator", new ExportTable(["شاشة الارساليات"], headers, data));
|
||||
}
|
||||
|
||||
/// <summary>factoryweb.report, EXCHANGE_OP column set (lines 870-940): the trip, weights, truck, trailer, driver id, net wage and status.</summary>
|
||||
public async Task<TripExportFile> ExchangeAsync(TripQuery query, CancellationToken ct)
|
||||
{
|
||||
TripQueryService.ValidateRanges(query);
|
||||
var rows = await trips.ReportAsync(query, ct);
|
||||
var data = rows.Select((r, i) => (IReadOnlyList<object?>)
|
||||
[
|
||||
i + 1, r.Pn, r.DispatchDate, r.LoadingNo, r.DischargeAuthNo, r.DischargeEntryDate, r.NetLoadingWeight, r.NetDischargeWeight,
|
||||
r.Tn, r.Trn, r.Nnpn, r.NetWage, TripStatus.Captions.GetValueOrDefault(r.StatusCode ?? string.Empty, r.StatusCode ?? string.Empty)
|
||||
]).ToList();
|
||||
string[] headers =
|
||||
[
|
||||
"متسلسل", "رقم الارسالية", "تاريخ الارسالية", "رقم الحمولة", "رقم النموذج", "تاريخ النموذج", "الوزن الصافي(كغ)",
|
||||
"الوزن الصافي للتفريغ(كغ)", "رقم القاطرة", "رقم المقطورة", "الرقم الوطني", "صافي قيمة الصرف الفعلي", "الحالة"
|
||||
];
|
||||
return Xlsx("refinery-trips-exchange", new ExportTable(["شاشة الارساليات"], headers, data));
|
||||
}
|
||||
|
||||
public async Task<TripExportFile> DieselAsync(DieselReportQuery query, CancellationToken ct)
|
||||
{
|
||||
if (query.DateFrom > query.DateTo) throw TripErrors.FromAfterTo();
|
||||
|
|
|
|||
|
|
@ -1,29 +1,16 @@
|
|||
using NTP.Application.Common;
|
||||
using NTP.Application.Refinery.RemainingBalance;
|
||||
|
||||
namespace NTP.Application.Refinery.Variables;
|
||||
|
||||
/// <summary>
|
||||
/// Port of the checks of refinerytripFactory.calculateRemainigBalance (refinerytripfactory.cfc:1269-1300) that run when the actual ton price
|
||||
/// is set: there must be trips in the period (ERROR.THERE_IS_NO_ANY_TRIP_IN_THIS_PERIOD) and all of them must be exchanged
|
||||
/// (ERROR.NO_TON_PRICE_EDIT_NOT_ALL_TRIPS_EXCHANGED).
|
||||
/// <para>
|
||||
/// NOT ported here: for every trip with PENALTY_AMOUNT > 0 legacy calls calculateAmounts(trip, 'TON_PRICE_CORRECTION') and, when the net wage
|
||||
/// changes, writes the difference into REFINERY_REMAINING_BALANCE (+ its log) per truck. That calculation is the trips module's
|
||||
/// (<c>calculateAmounts</c>). Until it is wired in here, a period that HAS such trips is refused with a clear message instead of being
|
||||
/// priced without recalculating the balances; a period without penalty trips (nothing to recalculate) works as legacy.
|
||||
/// Replace the throw below with the trips module's recalculation to finish the port.
|
||||
/// </para>
|
||||
/// Recalculation after the actual ton price (TON_PRICE_CORRECTION) is set: legacy UPDATE_TON_PRICE_CORRECTION calls
|
||||
/// refinerytripFactory.calculateRemainigBalance (refinerytripfactory.cfc:1269). That port lives in the trips module
|
||||
/// (<see cref="IRemainingBalanceService.RecalculateForPeriodAsync"/>: trips must exist and be exchanged, the net wage difference of every
|
||||
/// penalised trip goes to the truck's remaining balance). It joins the caller's transaction (DbSession nesting), so a failure rolls back the
|
||||
/// correction rows too (legacy reset them to 0 instead).
|
||||
/// </summary>
|
||||
public sealed class TonPriceRecalculationService(IVariablesRepository repository) : ITonPriceRecalculationService
|
||||
public sealed class TonPriceRecalculationService(IRemainingBalanceService balances) : ITonPriceRecalculationService
|
||||
{
|
||||
public async Task RecalculateAsync(long groupId, DateTime start, DateTime end, CancellationToken ct = default)
|
||||
{
|
||||
var info = await repository.GetTripsOfPeriodAsync(start, end, ct);
|
||||
if (info.TripCount == 0)
|
||||
throw new BusinessException(VariablesErrors.NoTripsInPeriod, VariablesMessages.NoTripsInPeriod);
|
||||
if (info.NotExchangedCount > 0)
|
||||
throw new BusinessException(VariablesErrors.NotAllTripsExchanged, VariablesMessages.NotAllTripsExchanged);
|
||||
if (info.PenaltyTripCount > 0)
|
||||
throw new BusinessException(VariablesErrors.RecalculationNotAvailable, VariablesMessages.RecalculationNotAvailable);
|
||||
}
|
||||
public async Task RecalculateAsync(long groupId, DateTime start, DateTime end, CancellationToken ct = default) =>
|
||||
await balances.RecalculateForPeriodAsync(start, end, groupId, ct);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,25 @@ public static class DependencyInjection
|
|||
// mobile notifications run in the background in their own scope (see MobileNotificationGatewayService)
|
||||
services.AddScoped<NTP.Infrastructure.Grains.NotificationDispatcher>();
|
||||
|
||||
// Refinery: Jopetrol claim web service (OFF unless Refinery:Jopetrol:Enabled; credentials only from env / .env)
|
||||
services.AddOptions<NTP.Infrastructure.Integrations.JopetrolOptions>()
|
||||
.Bind(configuration.GetSection(NTP.Infrastructure.Integrations.JopetrolOptions.SectionName));
|
||||
services.AddHttpClient(NTP.Infrastructure.Integrations.JopetrolOptions.HttpClientName);
|
||||
services.AddScoped<NTP.Application.Refinery.Integrations.IJopetrolGateway, NTP.Infrastructure.Integrations.JopetrolGateway>();
|
||||
|
||||
// Convention: every concrete *Repository / *Service in this assembly is registered against I{Name} (scoped).
|
||||
// Do NOT add per-table lines here.
|
||||
services.AddConventionalServices(typeof(DependencyInjection).Assembly);
|
||||
|
||||
// Refinery: Dinarak payment API (no "Service" suffix, so not convention registered). Off unless Refinery:Dinarak:Enabled.
|
||||
services.AddOptions<NTP.Infrastructure.Integrations.DinarakOptions>()
|
||||
.Bind(configuration.GetSection(NTP.Infrastructure.Integrations.DinarakOptions.SectionName));
|
||||
services.AddHttpClient(NTP.Infrastructure.Integrations.DinarakOptions.HttpClientName, (sp, client) =>
|
||||
client.Timeout = TimeSpan.FromSeconds(Math.Max(5, sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<NTP.Infrastructure.Integrations.DinarakOptions>>().Value.TimeoutSeconds)));
|
||||
services.AddScoped<NTP.Infrastructure.Integrations.DinarakGateway>();
|
||||
services.AddScoped<NTP.Application.Refinery.Integrations.IDinarakGateway>(sp => sp.GetRequiredService<NTP.Infrastructure.Integrations.DinarakGateway>());
|
||||
services.AddScoped<NTP.Application.Refinery.Integrations.IDinarakReferenceGateway>(sp => sp.GetRequiredService<NTP.Infrastructure.Integrations.DinarakGateway>());
|
||||
|
||||
services.AddHealthChecks()
|
||||
.AddCheck<OracleHealthCheck>("oracle", tags: ["ready"])
|
||||
.AddCheck<NtpSchemaHealthCheck>("oracle-ntp", tags: ["ready"]);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export function cardsGrid(h: { onOpen: (r: CardRow) => void }): GridMeta<CardRow
|
|||
onRowClick: h.onOpen,
|
||||
pageSize: 16,
|
||||
emptyAsGrid: true,
|
||||
requireFilter: true,
|
||||
status: { param: 'statusCode', options: cardStatuses },
|
||||
filters: [
|
||||
{ name: 'tn', type: 'text', label: s['rc.tn'], ltr: true },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
import type { RouteObject } from 'react-router-dom';
|
||||
import OilBarrelIcon from '@mui/icons-material/OilBarrel';
|
||||
import type { MenuItem } from '@/shell/types';
|
||||
import * as trips from './trips';
|
||||
import * as wageClaims from './wage-claims';
|
||||
import * as commissionClaims from './commission-claims';
|
||||
import * as wallets from './wallets';
|
||||
import * as variables from './variables';
|
||||
import * as cards from './cards';
|
||||
|
||||
/**
|
||||
* Refinery (المصفاة) slice ported from AqabaTCS: one folder per legacy module, each exports `routes` + `menuItems`.
|
||||
* Menu order as the legacy customtags/Menu.cfm: trips, wage claim, commission claim, wallet, variables, cards.
|
||||
* Every key is granted only by rows in GRAINS_SCREEN_PERMISSIONS (db/refinery-permissions.sql: SU always, PTADM).
|
||||
*/
|
||||
const modules = [trips, wageClaims, commissionClaims, wallets, variables, cards];
|
||||
|
||||
export const routes: RouteObject[] = modules.flatMap((m) => m.routes);
|
||||
|
||||
export const menu: MenuItem[] = [
|
||||
{
|
||||
key: 'refinery',
|
||||
title: { en: 'Crude oil tender forms', ar: 'عطاء صرف نماذج النفط الخام' },
|
||||
icon: OilBarrelIcon,
|
||||
children: modules.flatMap((m) => m.menuItems),
|
||||
},
|
||||
];
|
||||
|
|
@ -93,7 +93,7 @@ export function tripsGrid(onOpen: (r: TripGridRow) => void): GridMeta<TripGridRo
|
|||
status: { param: 'statusCode', options: statuses },
|
||||
filters,
|
||||
onRowClick: onOpen,
|
||||
visualLtr: true,
|
||||
requireFilter: true,
|
||||
columns: [
|
||||
{ key: 'pn', header: s['trips.pn'], ltr: true },
|
||||
{ key: 'dispatchDate', header: s['trips.dispatchDate'], ltr: true, hideBelow: 'md' },
|
||||
|
|
|
|||
|
|
@ -1,16 +1,23 @@
|
|||
import { useState, type ReactNode } from 'react';
|
||||
import { useState, type ElementType, type ReactNode } from 'react';
|
||||
import { Link as RouterLink, useNavigate, useParams } from 'react-router-dom';
|
||||
import {
|
||||
Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, Link, Menu, MenuItem, Stack, Table, TableBody, TableCell,
|
||||
Alert, Box, Button, Dialog, GlobalStyles, DialogActions, DialogContent, DialogTitle, Link, Menu, MenuItem, Stack, Table, TableBody, TableCell,
|
||||
TableHead, TableRow, TablePagination, Typography,
|
||||
} from '@mui/material';
|
||||
import SummarizeIcon from '@mui/icons-material/Summarize';
|
||||
import PrintIcon from '@mui/icons-material/Print';
|
||||
import AccountBalanceWalletIcon from '@mui/icons-material/AccountBalanceWallet';
|
||||
import AssignmentIcon from '@mui/icons-material/Assignment';
|
||||
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
||||
import FileUploadIcon from '@mui/icons-material/FileUpload';
|
||||
import HistoryIcon from '@mui/icons-material/History';
|
||||
import PaymentsIcon from '@mui/icons-material/Payments';
|
||||
import VisibilityOutlined from '@mui/icons-material/VisibilityOutlined';
|
||||
import { DataGrid } from '@/components/DataGrid';
|
||||
import { LoadingBanner } from '@/components/LoadingBanner';
|
||||
import { PageHeader } from '@/components/PageHeader';
|
||||
import { SectionPaper } from '@/components/SectionPaper';
|
||||
import { SectionTitle } from '@/components/SectionTitle';
|
||||
import { StatusChip } from '@/components/StatusChip';
|
||||
import { ViewItem } from '@/components/ViewItem';
|
||||
import { formatNumber } from '@/components/meta/format';
|
||||
|
|
@ -48,6 +55,8 @@ export function TripsPage() {
|
|||
const current = () => Object.fromEntries([...new URLSearchParams(window.location.search)].filter(([k]) => !['page', 'size', 'f'].includes(k)));
|
||||
const reports: { key: string; label: string; show: boolean; go: () => void }[] = [
|
||||
{ key: 'trips', label: t('trips.report.trips'), show: can('refinery.trips.report'), go: () => void run('trips', current(), 'refinery-trips.xlsx') },
|
||||
{ key: 'operator', label: t('trips.report.operator'), show: can('refinery.trips.operatorReport'), go: () => void run('operator', current(), 'refinery-trips-operator.xlsx') },
|
||||
{ key: 'exchange', label: t('trips.report.exchange'), show: can('refinery.trips.exchangeReport'), go: () => void run('exchange', current(), 'refinery-trips-exchange.xlsx') },
|
||||
{ key: 'diesel', label: t('trips.report.diesel'), show: can('refinery.trips.dieselReport'), go: () => void run('diesel', current(), 'refinery-diesel.xlsx') },
|
||||
{ key: 'cards', label: t('trips.report.cards'), show: can('refinery.trips.cardsReport'), go: () => void run('cards', { tn: current().tn ?? '' }, 'refinery-cards.xlsx') },
|
||||
{
|
||||
|
|
@ -83,10 +92,10 @@ function Num({ v }: { v: number | null | undefined }) {
|
|||
return v === null || v === undefined ? null : <bdi dir="ltr">{formatNumber(v, lang)}</bdi>;
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: ReactNode }) {
|
||||
function Section({ title, icon, children }: { title: string; icon: ElementType; children: ReactNode }) {
|
||||
return (
|
||||
<SectionPaper sx={{ p: 2 }}>
|
||||
<Typography component="h2" sx={{ fontSize: 15, fontWeight: 700, mb: 1.5, pb: 0.75, borderBottom: 1, borderColor: 'divider' }}>{title}</Typography>
|
||||
<SectionTitle icon={icon} title={title} />
|
||||
<Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, 1fr)', md: 'repeat(4, 1fr)' } }}>{children}</Box>
|
||||
</SectionPaper>
|
||||
);
|
||||
|
|
@ -141,7 +150,7 @@ function TripView({ trip }: { trip: TripDetail }) {
|
|||
actions={buttons}
|
||||
/>
|
||||
|
||||
<Section title={t('trips.sec.basic')}>
|
||||
<Section icon={AssignmentIcon} title={t('trips.sec.basic')}>
|
||||
<ViewItem label={t('trips.pn')}><bdi dir="ltr">{trip.pn}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.dispatchDate')}><bdi dir="ltr">{trip.dispatchDate}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.tn')}><bdi dir="ltr">{trip.tn}</bdi></ViewItem>
|
||||
|
|
@ -168,7 +177,7 @@ function TripView({ trip }: { trip: TripDetail }) {
|
|||
</Section>
|
||||
|
||||
{loaded && (
|
||||
<Section title={t('trips.sec.loading')}>
|
||||
<Section icon={FileUploadIcon} title={t('trips.sec.loading')}>
|
||||
<ViewItem label={t('trips.loadingNo')}><bdi dir="ltr">{trip.loadingNo}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.loadingFrom')}><bdi dir="ltr">{trip.actualLoadingDate}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.grossWeight')}><Num v={trip.grossWeight} /></ViewItem>
|
||||
|
|
@ -178,7 +187,7 @@ function TripView({ trip }: { trip: TripDetail }) {
|
|||
)}
|
||||
|
||||
{dischargeSection && (
|
||||
<Section title={t('trips.sec.discharge')}>
|
||||
<Section icon={FileDownloadIcon} title={t('trips.sec.discharge')}>
|
||||
<ViewItem label={t('trips.dischargeNo')}><bdi dir="ltr">{trip.dischargeAuthNo}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.dischargeDate')}><bdi dir="ltr">{trip.dischargeEntryDate}</bdi></ViewItem>
|
||||
<ViewItem label={t('trips.actualGross')}><Num v={trip.actualGrossWeight} /></ViewItem>
|
||||
|
|
@ -192,7 +201,7 @@ function TripView({ trip }: { trip: TripDetail }) {
|
|||
)}
|
||||
|
||||
{loaded && (
|
||||
<Section title={t('trips.sec.payment')}>
|
||||
<Section icon={PaymentsIcon} title={t('trips.sec.payment')}>
|
||||
{w?.epayment === 1 && (
|
||||
<>
|
||||
<ViewItem label={t('trips.walletNumber')}><bdi dir="ltr">{w.walletNumber}</bdi></ViewItem>
|
||||
|
|
@ -219,7 +228,7 @@ function TripView({ trip }: { trip: TripDetail }) {
|
|||
)}
|
||||
|
||||
{dischargeSection && (
|
||||
<Section title={t('trips.sec.driverWallet')}>
|
||||
<Section icon={AccountBalanceWalletIcon} title={t('trips.sec.driverWallet')}>
|
||||
{w?.driverWalletNumber
|
||||
? <ViewItem label={t('trips.driverWallet')}><bdi dir="ltr">{w.driverWalletNumber}</bdi></ViewItem>
|
||||
: <Typography color="error" sx={{ gridColumn: '1 / -1' }}>{t('trips.driverNoWallet')}</Typography>}
|
||||
|
|
@ -241,7 +250,11 @@ function TripLog({ tripId }: { tripId: number }) {
|
|||
const q = useTripLog(tripId, page, open);
|
||||
return (
|
||||
<SectionPaper sx={{ p: 2 }}>
|
||||
<Button size="small" onClick={() => setOpen((o) => !o)}>{t('trips.sec.history')}</Button>
|
||||
<Box role="button" tabIndex={0} aria-expanded={open} onClick={() => setOpen((o) => !o)}
|
||||
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setOpen((o) => !o); } }}
|
||||
sx={{ cursor: 'pointer', '& h2': { mb: open ? 1.5 : 0 } }}>
|
||||
<SectionTitle icon={HistoryIcon} title={t('trips.sec.history')} />
|
||||
</Box>
|
||||
{open && (
|
||||
<>
|
||||
{q.isLoading && <LoadingBanner variant="first" />}
|
||||
|
|
@ -325,9 +338,15 @@ function VoucherDialog({ voucher, onClose }: { voucher: TripVoucher | null; onCl
|
|||
const { t } = useFeatureUi(strings);
|
||||
return (
|
||||
<Dialog open={!!voucher} onClose={onClose} maxWidth="sm" fullWidth>
|
||||
{/* print only the voucher, not the page behind the dialog */}
|
||||
<GlobalStyles styles={{ '@media print': { 'body *': { visibility: 'hidden' }, '#trip-voucher, #trip-voucher *': { visibility: 'visible' }, '#trip-voucher': { position: 'absolute', top: 0, left: 0, right: 0 } } }} />
|
||||
<DialogContent>
|
||||
{voucher && (
|
||||
<Box id="trip-voucher" dir="rtl" sx={{ p: 2, '@media print': { p: 0 } }}>
|
||||
{/* the printed voucher always carries the Arabic logo (white background, fixed size) */}
|
||||
<Box sx={{ textAlign: 'left', mb: 1, bgcolor: '#fff', lineHeight: 0 }}>
|
||||
<img src="/brand/nafith-ar.gif" alt="نافذ" width={139} height={30} style={{ display: 'inline-block' }} />
|
||||
</Box>
|
||||
<Typography align="center" sx={{ fontSize: 18, fontWeight: 700, mb: 3 }}>{t('trips.voucher.title')}</Typography>
|
||||
<Stack direction="row" sx={{ justifyContent: 'space-between', mb: 3 }}>
|
||||
<span>{t('trips.voucher.date')} : <bdi dir="ltr">{voucher.date}</bdi></span>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { defineStrings } from '@/i18n/useUi';
|
|||
|
||||
/** Strings of the refinery trips screen. Arabic texts are the legacy captions (ntp.lt_caption REFINERYTRIP*, PUBLIC.*) verbatim. */
|
||||
export default defineStrings({
|
||||
'trips.menu': { en: 'Trips', ar: 'شاشة الارساليات' },
|
||||
'trips.menu': { en: 'Trips', ar: 'الارساليات' },
|
||||
'trips.title': { en: 'Refinery trips', ar: 'شاشة الارساليات' },
|
||||
'trips.crumb': { en: 'Trip details', ar: 'معلومات الارسالية' },
|
||||
|
||||
|
|
@ -45,6 +45,8 @@ export default defineStrings({
|
|||
// reports
|
||||
'trips.reports': { en: 'Reports', ar: 'التقارير' },
|
||||
'trips.report.trips': { en: 'Trips (Excel)', ar: 'شاشة الارساليات (Excel)' },
|
||||
'trips.report.operator': { en: 'Trips - operator (Excel)', ar: 'شاشة الارساليات - المشغل (Excel)' },
|
||||
'trips.report.exchange': { en: 'Trips - exchange (Excel)', ar: 'شاشة الارساليات - الصرف (Excel)' },
|
||||
'trips.report.diesel': { en: 'Diesel charges (Excel)', ar: 'شحن الديزل (Excel)' },
|
||||
'trips.report.cards': { en: 'Diesel balances (Excel)', ar: 'أرصدة الديزل (Excel)' },
|
||||
'trips.report.bank': { en: 'Bank report (Excel)', ar: 'تقرير البنك (Excel)' },
|
||||
|
|
@ -117,7 +119,7 @@ export default defineStrings({
|
|||
'trips.log.none': { en: 'No movements', ar: 'لا يوجد معلومات' },
|
||||
'trips.voucher.title': { en: 'Cash voucher', ar: 'سند صرف نقدي' },
|
||||
'trips.voucher.date': { en: 'Date', ar: 'التاريخ' },
|
||||
'trips.voucher.no': { en: 'No', ar: 'No' },
|
||||
'trips.voucher.no': { en: 'No', ar: 'الرقم' },
|
||||
'trips.voucher.body1': { en: 'Received from Nafith Logistics the amount of', ar: 'وصلني من السادة شركة نافذ للخدمات اللوجستية مبلغ وقدره' },
|
||||
'trips.voucher.dinar': { en: 'dinars', ar: 'دينارا' },
|
||||
'trips.voucher.body2': { en: 'for crude oil transport wages of form number', ar: 'وذلك عن أجور نقل النفط الخام للنموذج رقم' },
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@ import { GRID_VARIABLES, type VariablesRow } from './api';
|
|||
|
||||
const s = strings;
|
||||
|
||||
const p2 = (n: number) => String(n).padStart(2, '0');
|
||||
const iso = (d: Date) => `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`;
|
||||
/** First and last day of the current month as the grid's startDate / endDate filters. */
|
||||
const monthRange = () => {
|
||||
const now = new Date();
|
||||
return { startDate: iso(new Date(now.getFullYear(), now.getMonth(), 1)), endDate: iso(new Date(now.getFullYear(), now.getMonth() + 1, 0)) };
|
||||
};
|
||||
|
||||
/** Legacy REFINERY_VARIABLESGRID: period, then the prices; the filters are the two period dates. */
|
||||
export function variablesGrid(h: { onOpen: (r: VariablesRow) => void }): GridMeta<VariablesRow> {
|
||||
return {
|
||||
|
|
@ -13,6 +21,8 @@ export function variablesGrid(h: { onOpen: (r: VariablesRow) => void }): GridMet
|
|||
onRowClick: h.onOpen,
|
||||
pageSize: 16,
|
||||
emptyAsGrid: true,
|
||||
// opens on the periods that start in the current month (first day .. last day)
|
||||
defaultFilters: monthRange(),
|
||||
filters: [
|
||||
{ name: 'startDate', type: 'date', label: s['rv.filter.startDate'] },
|
||||
{ name: 'endDate', type: 'date', label: s['rv.filter.endDate'] },
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { defineStrings } from '@/i18n/useUi';
|
|||
*/
|
||||
export default defineStrings({
|
||||
// ---- menu / titles
|
||||
'wc.menu': { en: 'Wage claims', ar: 'شاشة مطالبات صرف أجور النقل' }, // MENU.REFINERY_WAGE_CLAIM
|
||||
'wc.title': { en: 'Transport wage claims', ar: 'شاشة مطالبات صرف أجور النقل' },
|
||||
'wc.menu': { en: 'Wage claims', ar: 'مطالبات صرف أجور النقل' }, // MENU.REFINERY_WAGE_CLAIM
|
||||
'wc.title': { en: 'Transport wage claims', ar: 'مطالبات صرف أجور النقل' },
|
||||
'wc.subtitle': { en: 'Claims that group the exchanged trips of the refinery tender', ar: 'مطالبات تجمع الارساليات المصروفة لعطاء المصفاة' },
|
||||
'wc.details': { en: 'Wage claim details', ar: 'معلومات مطالبة صرف اجور النقل' }, // REFINERY_WAGE_CLAIM_DETAILS
|
||||
'wc.crumb.new': { en: 'New', ar: 'جديد' },
|
||||
|
|
@ -54,11 +54,11 @@ export default defineStrings({
|
|||
|
||||
// ---- create
|
||||
'wc.create.title': { en: 'New wage claim', ar: 'إنشاء مطالبة صرف اجور النقل' }, // new
|
||||
'wc.create.subtitle': { en: 'Trips of the chosen statuses and policy dates that are not in a claim yet', ar: 'الارساليات بالحالات وتواريخ البوليصة المختارة التي لا تتبع مطالبة بعد' },
|
||||
'wc.create.subtitle': { en: 'Trips of the chosen statuses and claim dates that are not in a claim yet', ar: 'الارساليات بالحالات وتواريخ المطالبة المختارة التي لا تتبع مطالبة بعد' },
|
||||
'wc.create.status': { en: 'Trip status', ar: 'الحالة' }, // PUBLIC.STATUS
|
||||
'wc.create.all': { en: 'All', ar: 'الكل' },
|
||||
'wc.create.from': { en: 'From (policy date)', ar: 'من (تاريخ البوليصة)' },
|
||||
'wc.create.to': { en: 'To (policy date)', ar: 'الى (تاريخ البوليصة)' },
|
||||
'wc.create.from': { en: 'From (claim date)', ar: 'من (تاريخ المطالبة)' },
|
||||
'wc.create.to': { en: 'To (claim date)', ar: 'الى (تاريخ المطالبة)' },
|
||||
'wc.create.search': { en: 'Search', ar: 'بحث' },
|
||||
'wc.create.save': { en: 'Create claim', ar: 'إنشاء' }, // PUBLIC.CREATE
|
||||
'wc.create.statusRequired': { en: 'Choose the status', ar: 'يجب اختيار الحالة' }, // ERROR.STATUS_REQUIRED
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ export function walletsGrid(h: { onOpen: (r: WalletRow) => void }): GridMeta<Wal
|
|||
onRowClick: h.onOpen,
|
||||
pageSize: 16,
|
||||
emptyAsGrid: true,
|
||||
requireFilter: true,
|
||||
status: { param: 'statusCode', options: walletStatuses },
|
||||
filters: [
|
||||
{ name: 'tn', type: 'text', label: s['rw.tn'], ltr: true },
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { defineStrings } from '@/i18n/useUi';
|
|||
|
||||
/** Strings of the refinery payment methods screen (legacy captions REFINERY_WALLET.* / PUBLIC.* / ERROR.*, verbatim in Arabic where they exist). */
|
||||
export default defineStrings({
|
||||
'rw.menu': { en: 'Payment methods', ar: 'شاشة طرق الدفع' },
|
||||
'rw.menu': { en: 'Payment methods', ar: 'طرق الدفع' },
|
||||
'rw.title': { en: 'Payment methods', ar: 'شاشة طرق الدفع' },
|
||||
'rw.subtitle': { en: 'How the truck owners (and the drivers, for the tip) get paid', ar: 'آلية صرف الأجور لأصحاب الشاحنات وإكرامية السائقين' },
|
||||
'rw.new': { en: 'New payment method', ar: 'آلية صرف جديدة' },
|
||||
|
|
|
|||
Loading…
Reference in New Issue