@things-factory/operato-pms 3.8.13 → 3.8.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/pages/dispatchment/daily-dispatch-detail.js +1 -1
- package/client/pages/dispatchment/dispatchment-create-record.js +20 -44
- package/client/pages/harvesting/daily-harvesting-detail.js +2 -2
- package/client/pages/harvesting/edit-harvesting-record.js +2 -2
- package/client/pages/harvesting/harvesting-create-record.js +2 -2
- package/client/pages/inventory/inventory-ramp-tonnage.js +23 -31
- package/client/pages/report/report-daily-ffb-dispatch-and-production.js +167 -124
- package/client/pages/report/report-ffb-tonnage-between-individual-block.js +12 -7
- package/dist-server/constants/transaction.js +2 -1
- package/dist-server/constants/transaction.js.map +1 -1
- package/dist-server/entities/daily-dispatch.js +1 -2
- package/dist-server/entities/daily-dispatch.js.map +1 -1
- package/dist-server/graphql/resolvers/daily-dispatch/update-daily-dispatch.js +1 -1
- package/dist-server/graphql/resolvers/daily-dispatch/update-daily-dispatch.js.map +1 -1
- package/dist-server/graphql/resolvers/daily-harvest/generate-daily-harvest.js +2 -2
- package/dist-server/graphql/resolvers/daily-harvest/generate-daily-harvest.js.map +1 -1
- package/dist-server/graphql/resolvers/daily-loading/update-daily-loading.js +19 -6
- package/dist-server/graphql/resolvers/daily-loading/update-daily-loading.js.map +1 -1
- package/dist-server/graphql/resolvers/dashboard/dashboard-query.js +165 -43
- package/dist-server/graphql/resolvers/dashboard/dashboard-query.js.map +1 -1
- package/dist-server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.js +111 -0
- package/dist-server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.js.map +1 -0
- package/dist-server/graphql/resolvers/report/daily-production-reports.js +6 -6
- package/dist-server/graphql/resolvers/report/index.js +2 -1
- package/dist-server/graphql/resolvers/report/index.js.map +1 -1
- package/dist-server/graphql/resolvers/report/monthly-block-dispatch-reports.js +10 -8
- package/dist-server/graphql/resolvers/report/monthly-block-dispatch-reports.js.map +1 -1
- package/dist-server/graphql/resolvers/report/monthly-ffb-sale-reports.js +1 -1
- package/dist-server/graphql/resolvers/report/monthly-production-reports.js +1 -1
- package/dist-server/graphql/types/report/daily-ffb-dispatch-production-report-list.js +14 -0
- package/dist-server/graphql/types/report/daily-ffb-dispatch-production-report-list.js.map +1 -0
- package/dist-server/graphql/types/report/daily-ffb-dispatch-production-report.js +15 -0
- package/dist-server/graphql/types/report/daily-ffb-dispatch-production-report.js.map +1 -0
- package/dist-server/graphql/types/report/index.js +13 -0
- package/dist-server/graphql/types/report/index.js.map +1 -1
- package/dist-server/utils/core-values.js +2 -2
- package/dist-server/utils/transaction-util.js +2 -1
- package/dist-server/utils/transaction-util.js.map +1 -1
- package/package.json +4 -4
- package/server/constants/transaction.ts +2 -1
- package/server/entities/daily-dispatch.ts +1 -4
- package/server/graphql/resolvers/daily-dispatch/update-daily-dispatch.ts +2 -2
- package/server/graphql/resolvers/daily-harvest/generate-daily-harvest.ts +2 -2
- package/server/graphql/resolvers/daily-loading/update-daily-loading.ts +39 -11
- package/server/graphql/resolvers/dashboard/dashboard-query.ts +208 -52
- package/server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.ts +138 -0
- package/server/graphql/resolvers/report/daily-production-reports.ts +6 -6
- package/server/graphql/resolvers/report/index.ts +3 -1
- package/server/graphql/resolvers/report/monthly-block-dispatch-reports.ts +11 -9
- package/server/graphql/resolvers/report/monthly-ffb-sale-reports.ts +1 -1
- package/server/graphql/resolvers/report/monthly-production-reports.ts +1 -1
- package/server/graphql/types/report/daily-ffb-dispatch-production-report-list.ts +8 -0
- package/server/graphql/types/report/daily-ffb-dispatch-production-report.ts +9 -0
- package/server/graphql/types/report/index.ts +13 -0
- package/server/utils/core-values.ts +2 -2
- package/server/utils/transaction-util.ts +2 -1
- package/translations/en.json +7 -6
- package/translations/ko.json +7 -6
- package/translations/ms.json +10 -9
- package/translations/zh.json +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/report/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,iEAA8C;AAC9C,4DAAyC;AACzC,oEAAiD;AACjD,+DAA4C;AAC5C,uEAAoD;AACpD,kEAA+C;AAC/C,yEAAsD;AACtD,oEAAiD;AACjD,mEAAgD;AAChD,8DAA2C;AAC3C,kEAA+C;AAC/C,6DAA0C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/report/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,iEAA8C;AAC9C,4DAAyC;AACzC,oEAAiD;AACjD,+DAA4C;AAC5C,uEAAoD;AACpD,kEAA+C;AAC/C,yEAAsD;AACtD,oEAAiD;AACjD,mEAAgD;AAChD,8DAA2C;AAC3C,kEAA+C;AAC/C,6DAA0C;AAC1C,yEAAsD;AACtD,8EAA2D;AAE9C,QAAA,cAAc,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4ChC,CAAA"}
|
|
@@ -37,8 +37,8 @@ async function getDailyBlockCalculatedValues(block, date, trxMgr) {
|
|
|
37
37
|
select block_id, transaction_date,
|
|
38
38
|
(select opening_field_bunches from transactions dt where dt.block_id = trx.block_id and dt.seq = min(trx.seq)) as prev_bunch_bal_in_field,
|
|
39
39
|
0 as prev_weight_bal_in_ramp,
|
|
40
|
-
sum(case when transaction_type = 'HARVEST' then field_bunches else 0 end) as today_bunch_harvest,
|
|
41
|
-
sum(case when transaction_type = 'LOADING' then -field_bunches else 0 end) as today_bunch_collected,
|
|
40
|
+
sum(case when transaction_type = 'HARVEST' OR transaction_type = 'BUNCHES_ADJUSTMENT' then field_bunches else 0 end) as today_bunch_harvest,
|
|
41
|
+
sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then -field_bunches else 0 end) as today_bunch_collected,
|
|
42
42
|
0 as today_weight_dispatch,
|
|
43
43
|
0 as today_weight_bal_in_ramp,
|
|
44
44
|
(
|
|
@@ -31,7 +31,8 @@ async function generateTransactionHistory(plantationInventory, refActionID, refR
|
|
|
31
31
|
await transactionRepo.save(recTransactionHistory);
|
|
32
32
|
if (transactionType === constants_1.TRANSACTION_TYPE.LOADING ||
|
|
33
33
|
transactionType === constants_1.TRANSACTION_TYPE.DISPATCHMENT ||
|
|
34
|
-
transactionType === constants_1.TRANSACTION_TYPE.
|
|
34
|
+
transactionType === constants_1.TRANSACTION_TYPE.LOADING_ADJUSTMENT ||
|
|
35
|
+
transactionType === constants_1.TRANSACTION_TYPE.DISPATCHMENT_ADJUSTMENT) {
|
|
35
36
|
await switchRampStatus(domain, ramp, user, trxMgr);
|
|
36
37
|
}
|
|
37
38
|
return recTransactionHistory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-util.js","sourceRoot":"","sources":["../../server/utils/transaction-util.ts"],"names":[],"mappings":";;;AAEA,4CAA8E;AAC9E,0CAA0E;AAC1E,oCAAsC;AACtC,qCAAkE;AAElE;;;GAGG;AAEI,KAAK,UAAU,0BAA0B,CAC9C,mBAAwC,EACxC,WAAgB,EAChB,WAAmB,EACnB,eAAuB,EACvB,eAAuB,EACvB,YAAoB,EACpB,UAAkB,EAClB,IAAU,EACV,MAAsB;IAEtB,MAAM,eAAe,GACnB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAC,4BAAiB,CAAC,KAAI,IAAA,uBAAa,EAAC,4BAAiB,CAAC,CAAA;IAE9E,IAAI,CAAC,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,EAAE,CAAA;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAE3F,MAAM,MAAM,GAAW,mBAAmB,CAAC,MAAM,CAAA;IACjD,MAAM,IAAI,GAAS,mBAAmB,CAAC,IAAI,CA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|
|
3
|
+
"version": "3.8.26",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@operato/ghost-print": "0.1.14",
|
|
42
42
|
"@things-factory/apptool-ui": "^3.8.0",
|
|
43
43
|
"@things-factory/auth-ui": "^3.8.0",
|
|
44
|
-
"@things-factory/biz-base": "^3.8.
|
|
44
|
+
"@things-factory/biz-base": "^3.8.26",
|
|
45
45
|
"@things-factory/board-service": "^3.8.0",
|
|
46
46
|
"@things-factory/board-ui": "^3.8.0",
|
|
47
47
|
"@things-factory/code-ui": "^3.8.0",
|
|
@@ -89,12 +89,12 @@
|
|
|
89
89
|
"@things-factory/scene-table": "^3.7.5",
|
|
90
90
|
"@things-factory/scene-visualizer": "^3.7.5",
|
|
91
91
|
"@things-factory/scene-wheel-sorter": "^3.7.5",
|
|
92
|
-
"@things-factory/setting-ui": "^3.8.
|
|
92
|
+
"@things-factory/setting-ui": "^3.8.19",
|
|
93
93
|
"@things-factory/shell": "^3.8.0",
|
|
94
94
|
"@things-factory/system-ui": "^3.8.0"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@things-factory/builder": "^3.7.5"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "6ca26d91b7dad8eec6bc7859391bbd50374c744b"
|
|
100
100
|
}
|
|
@@ -2,7 +2,8 @@ export const TRANSACTION_TYPE = {
|
|
|
2
2
|
HARVEST: 'HARVEST',
|
|
3
3
|
LOADING: 'LOADING',
|
|
4
4
|
DISPATCHMENT: 'DISPATCHMENT',
|
|
5
|
-
|
|
5
|
+
LOADING_ADJUSTMENT: 'LOADING_ADJUSTMENT',
|
|
6
|
+
DISPATCHMENT_ADJUSTMENT: 'DISPATCHMENT_ADJUSTMENT',
|
|
6
7
|
BUNCHES_ADJUSTMENT: 'BUNCHES_ADJUSTMENT',
|
|
7
8
|
TERMINATED: 'TERMINATED'
|
|
8
9
|
}
|
|
@@ -3,10 +3,8 @@ import {
|
|
|
3
3
|
CreateDateColumn,
|
|
4
4
|
Entity,
|
|
5
5
|
Index,
|
|
6
|
-
JoinColumn,
|
|
7
6
|
ManyToOne,
|
|
8
7
|
OneToMany,
|
|
9
|
-
OneToOne,
|
|
10
8
|
PrimaryGeneratedColumn,
|
|
11
9
|
UpdateDateColumn
|
|
12
10
|
} from 'typeorm'
|
|
@@ -39,8 +37,7 @@ export class DailyDispatch {
|
|
|
39
37
|
@Column({ nullable: true })
|
|
40
38
|
externalDriver: string
|
|
41
39
|
|
|
42
|
-
@
|
|
43
|
-
@JoinColumn()
|
|
40
|
+
@ManyToOne(type => Truck, { nullable: true })
|
|
44
41
|
transport: Truck
|
|
45
42
|
|
|
46
43
|
@Column()
|
|
@@ -18,9 +18,9 @@ export const updateDailyDispatch = {
|
|
|
18
18
|
let foundDailyDispatchDetails: DailyDispatchDetail[] = dailyDispatch.dailyDispatchDetails
|
|
19
19
|
|
|
20
20
|
foundDailyDispatchDetails = foundDailyDispatchDetails.map(record => {
|
|
21
|
-
const matchedDispatchDetail: any = dailyDispatchDetails.
|
|
21
|
+
const matchedDispatchDetail: any = dailyDispatchDetails.find(
|
|
22
22
|
dispatchDetail => dispatchDetail.name === record.name
|
|
23
|
-
)
|
|
23
|
+
)
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
26
|
...record,
|
|
@@ -137,7 +137,7 @@ export async function addPlantationInventory(
|
|
|
137
137
|
existingFieldBunch,
|
|
138
138
|
newDailyHarvest.id,
|
|
139
139
|
newDailyHarvest.name,
|
|
140
|
-
TRANSACTION_TYPE.
|
|
140
|
+
TRANSACTION_TYPE.LOADING,
|
|
141
141
|
newDailyHarvest.harvestDate,
|
|
142
142
|
-newDailyHarvest.collectedBunch,
|
|
143
143
|
0,
|
|
@@ -181,7 +181,7 @@ export async function addPlantationInventory(
|
|
|
181
181
|
plantationInventory,
|
|
182
182
|
newDailyHarvest.id,
|
|
183
183
|
newDailyHarvest.name,
|
|
184
|
-
TRANSACTION_TYPE.
|
|
184
|
+
TRANSACTION_TYPE.LOADING,
|
|
185
185
|
newDailyHarvest.harvestDate,
|
|
186
186
|
-newDailyHarvest.collectedBunch,
|
|
187
187
|
0,
|
|
@@ -3,8 +3,9 @@ import { EntityManager, getRepository, Repository } from 'typeorm'
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Domain } from '@things-factory/shell'
|
|
5
5
|
|
|
6
|
+
import { INVENTORY_TYPE, TRANSACTION_TYPE } from '../../../constants'
|
|
6
7
|
import { Block, DailyLoading, DailyLoadingDetail, PlantationInventory, Ramp, Truck } from '../../../entities'
|
|
7
|
-
import { NoGenerator } from '../../../utils'
|
|
8
|
+
import { generateTransactionHistory, NoGenerator } from '../../../utils'
|
|
8
9
|
|
|
9
10
|
export const updateDailyLoading = {
|
|
10
11
|
async updateDailyLoading(_: any, { name, dailyLoadingPatch }, context: any) {
|
|
@@ -68,15 +69,21 @@ export async function updateDailyLoadingDetail(
|
|
|
68
69
|
|
|
69
70
|
if (existingDailyLoadingDetails?.length > 0) {
|
|
70
71
|
updatedDailyLoadingDetails = await Promise.all(
|
|
71
|
-
dailyLoadingDetails.map(async (
|
|
72
|
-
const foundDailyLoadingDetailPatch = dailyLoadingDetailPatches.find(
|
|
72
|
+
dailyLoadingDetails.map(async (existingRecord: DailyLoadingDetail) => {
|
|
73
|
+
const foundDailyLoadingDetailPatch = dailyLoadingDetailPatches.find(
|
|
74
|
+
detail => detail.name === existingRecord.name
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (foundDailyLoadingDetailPatch.totalBunchWeight !== existingRecord.totalBunchWeight) {
|
|
78
|
+
await updatePlantationInventory(domain, dailyLoading, foundDailyLoadingDetailPatch, existingRecord, user, tx)
|
|
79
|
+
}
|
|
73
80
|
|
|
74
81
|
return {
|
|
75
|
-
...
|
|
82
|
+
...existingRecord,
|
|
76
83
|
dailyLoading,
|
|
77
|
-
truck: await truckRepo.findOne({ id:
|
|
78
|
-
block: await blockRepo.findOne({ id:
|
|
79
|
-
ramp: await rampRepo.findOne({ id:
|
|
84
|
+
truck: await truckRepo.findOne({ id: existingRecord.truck.id }),
|
|
85
|
+
block: await blockRepo.findOne({ id: existingRecord.block.id }),
|
|
86
|
+
ramp: await rampRepo.findOne({ id: existingRecord.ramp.id }),
|
|
80
87
|
totalBunchLoaded: foundDailyLoadingDetailPatch?.totalBunchLoaded || 0,
|
|
81
88
|
totalBunchWeight: foundDailyLoadingDetailPatch?.totalBunchWeight || 0,
|
|
82
89
|
remark: foundDailyLoadingDetailPatch?.remark || null,
|
|
@@ -85,8 +92,6 @@ export async function updateDailyLoadingDetail(
|
|
|
85
92
|
})
|
|
86
93
|
)
|
|
87
94
|
updatedDailyLoadingDetails = await dailyLoadingDetailRepo.save(updatedDailyLoadingDetails)
|
|
88
|
-
|
|
89
|
-
// await updatePlantationInventory(domain, dailyLoading, updatedDailyLoadingDetails, user, tx)
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
if (newDailyLoadingDetail?.length > 0) {
|
|
@@ -113,12 +118,35 @@ export async function updateDailyLoadingDetail(
|
|
|
113
118
|
export async function updatePlantationInventory(
|
|
114
119
|
domain: Domain,
|
|
115
120
|
dailyLoading: DailyLoading,
|
|
116
|
-
|
|
121
|
+
foundDailyLoadingDetailPatch: any,
|
|
122
|
+
existingRecord: DailyLoadingDetail,
|
|
117
123
|
user: User,
|
|
118
124
|
tx?: EntityManager
|
|
119
125
|
): Promise<void> {
|
|
120
126
|
const plantationInvRepo: Repository<PlantationInventory> =
|
|
121
127
|
tx?.getRepository(PlantationInventory) || getRepository(PlantationInventory)
|
|
122
128
|
|
|
123
|
-
|
|
129
|
+
let existingRampTonnage: PlantationInventory = await plantationInvRepo.findOne({
|
|
130
|
+
where: { domain, type: INVENTORY_TYPE.RAMP_TONNAGE, ramp: existingRecord.ramp },
|
|
131
|
+
relations: ['domain', 'block', 'ramp']
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
if (existingRampTonnage) {
|
|
135
|
+
const tonnageChanges: number = foundDailyLoadingDetailPatch.totalBunchWeight - existingRecord.totalBunchWeight
|
|
136
|
+
existingRampTonnage.totalTonnage = existingRampTonnage.totalTonnage + tonnageChanges
|
|
137
|
+
existingRampTonnage.updater = user
|
|
138
|
+
await plantationInvRepo.save(existingRampTonnage)
|
|
139
|
+
|
|
140
|
+
await generateTransactionHistory(
|
|
141
|
+
existingRampTonnage,
|
|
142
|
+
dailyLoading.id,
|
|
143
|
+
dailyLoading.name,
|
|
144
|
+
TRANSACTION_TYPE.LOADING_ADJUSTMENT,
|
|
145
|
+
dailyLoading.loadingDate,
|
|
146
|
+
0,
|
|
147
|
+
tonnageChanges,
|
|
148
|
+
user,
|
|
149
|
+
tx
|
|
150
|
+
)
|
|
151
|
+
}
|
|
124
152
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { ListParam } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { Block } from '../../../entities'
|
|
2
6
|
|
|
3
7
|
// import { buildQuery, ListParam } from '@things-factory/shell'
|
|
4
8
|
|
|
@@ -9,57 +13,55 @@ export const Query = {
|
|
|
9
13
|
* @returns tonnage data with its sorted date
|
|
10
14
|
*/
|
|
11
15
|
async monthlyTonnageProductions(_: any, { blockId, yearAndMonth }, context: any) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
month,
|
|
31
|
-
date: theDate.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
16
|
+
try {
|
|
17
|
+
const { tx }: { tx: EntityManager } = context.state
|
|
18
|
+
|
|
19
|
+
const year = parseInt(yearAndMonth.substring(0, 4))
|
|
20
|
+
const month = parseInt(yearAndMonth.substring(4))
|
|
21
|
+
|
|
22
|
+
let data: any[] = await getDailyProductionData(blockId, year, month, tx);
|
|
23
|
+
let result = []
|
|
24
|
+
|
|
25
|
+
result = data.map(itm => {
|
|
26
|
+
return {
|
|
27
|
+
...itm,
|
|
28
|
+
blockId,
|
|
29
|
+
tonnage: itm.todayWeightCollected,
|
|
30
|
+
year: itm.dateDay.getFullYear(),
|
|
31
|
+
month: itm.dateDay.getMonth(),
|
|
32
|
+
date: itm.dateDay.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
33
|
+
}
|
|
32
34
|
})
|
|
33
|
-
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
return result
|
|
37
|
+
} catch (ex) {
|
|
38
|
+
}
|
|
36
39
|
},
|
|
37
40
|
|
|
38
41
|
async monthlyYields(_: any, { blockId, yearAndMonth }, context: any) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
month,
|
|
58
|
-
date: theDate.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
42
|
+
try {
|
|
43
|
+
const { tx }: { tx: EntityManager } = context.state
|
|
44
|
+
|
|
45
|
+
const year = parseInt(yearAndMonth.substring(0, 4))
|
|
46
|
+
const month = parseInt(yearAndMonth.substring(4))
|
|
47
|
+
|
|
48
|
+
let data: any[] = await getDailyProductionData(blockId, year, month, tx);
|
|
49
|
+
let result = []
|
|
50
|
+
|
|
51
|
+
result = data.map(itm => {
|
|
52
|
+
return {
|
|
53
|
+
...itm,
|
|
54
|
+
blockId,
|
|
55
|
+
yield: (itm.todayHectareCover != 0 ? itm.todayWeightCollected / itm.todayHectareCover : 0).toFixed(4),
|
|
56
|
+
year: itm.dateDay.getFullYear(),
|
|
57
|
+
month: itm.dateDay.getMonth(),
|
|
58
|
+
date: itm.dateDay.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
59
|
+
}
|
|
59
60
|
})
|
|
60
|
-
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
return result
|
|
63
|
+
} catch (ex) {
|
|
64
|
+
}
|
|
63
65
|
},
|
|
64
66
|
|
|
65
67
|
async weeklyBunchesCount(_: any, { targetDate }, context: any) {
|
|
@@ -70,8 +72,10 @@ export const Query = {
|
|
|
70
72
|
for (let i = 0; i < 7; i++) {
|
|
71
73
|
bunchesCount.push({
|
|
72
74
|
date: new Date(targetDate).toLocaleString('default', { day: '2-digit', month: 'short' }),
|
|
73
|
-
harvestedCount:
|
|
74
|
-
collectedCount:
|
|
75
|
+
harvestedCount: 0,
|
|
76
|
+
collectedCount: 0
|
|
77
|
+
// harvestedCount: Math.floor(Math.random() * 1000) + 500,
|
|
78
|
+
// collectedCount: Math.floor(Math.random() * 500) + 50
|
|
75
79
|
})
|
|
76
80
|
targetDate.setDate(targetDate.getDate() - 1)
|
|
77
81
|
}
|
|
@@ -81,16 +85,168 @@ export const Query = {
|
|
|
81
85
|
|
|
82
86
|
async tonnageAndBunchesInventories(_: any, { something }, context: any) {
|
|
83
87
|
return {
|
|
84
|
-
bunches:
|
|
85
|
-
tonnage:
|
|
88
|
+
bunches: 0,
|
|
89
|
+
tonnage: 0
|
|
90
|
+
// bunches: Math.floor(Math.random() * 10000) + 500,
|
|
91
|
+
// tonnage: Math.floor(Math.random() * 10000) + 500
|
|
86
92
|
}
|
|
87
93
|
},
|
|
88
94
|
|
|
89
95
|
async productionsOverview(_: any, { something }, context: any) {
|
|
90
96
|
return {
|
|
91
|
-
averageBunchWeight:
|
|
92
|
-
bunchesCount:
|
|
93
|
-
tonnageWeighed:
|
|
97
|
+
averageBunchWeight: 0,
|
|
98
|
+
bunchesCount: 0,
|
|
99
|
+
tonnageWeighed: 0,
|
|
100
|
+
// averageBunchWeight: Math.floor(Math.random() * 150) + 70,
|
|
101
|
+
// bunchesCount: Math.floor(Math.random() * 10000) + 500,
|
|
102
|
+
// tonnageWeighed: Math.floor(Math.random() * 10000) + 500
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
105
|
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export async function getDailyProductionData(
|
|
109
|
+
blockId: String,
|
|
110
|
+
year: number,
|
|
111
|
+
month: number,
|
|
112
|
+
tx: EntityManager
|
|
113
|
+
): Promise<any> {
|
|
114
|
+
await tx.query(`
|
|
115
|
+
CREATE TEMP TABLE temp_blocks on commit drop AS (
|
|
116
|
+
WITH RECURSIVE b AS (
|
|
117
|
+
SELECT b.id AS block_id, * FROM blocks b
|
|
118
|
+
WHERE b.deleted_at IS null
|
|
119
|
+
UNION ALL
|
|
120
|
+
SELECT b.id AS block_id, cb.* FROM blocks cb
|
|
121
|
+
INNER JOIN b ON b.id = cb.parent_block_id
|
|
122
|
+
WHERE cb.deleted_at IS null
|
|
123
|
+
)
|
|
124
|
+
SELECT block_id, id, name FROM b
|
|
125
|
+
${blockId != 'all-blocks' && blockId != '' ? `WHERE block_id = '${blockId}' or id = '${blockId}'` : ``}
|
|
126
|
+
GROUP BY block_id, id, name
|
|
127
|
+
ORDER BY block_id, id, name
|
|
128
|
+
);
|
|
129
|
+
`)
|
|
130
|
+
|
|
131
|
+
let fromDate = new Date(year, month - 1, 1)
|
|
132
|
+
let toDate = new Date(year, month, 1)
|
|
133
|
+
toDate.setDate(toDate.getDate() - 1)
|
|
134
|
+
|
|
135
|
+
let fromDateString = [
|
|
136
|
+
fromDate.getFullYear().toString(),
|
|
137
|
+
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
138
|
+
'01'
|
|
139
|
+
].join('-')
|
|
140
|
+
|
|
141
|
+
let toDateString = [
|
|
142
|
+
toDate.getFullYear().toString(),
|
|
143
|
+
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
144
|
+
String(toDate.getDate()).padStart(2, '0')
|
|
145
|
+
].join('-')
|
|
146
|
+
|
|
147
|
+
await tx.query(`
|
|
148
|
+
CREATE TEMP TABLE temp_records on commit drop AS (
|
|
149
|
+
select blk.block_id, coalesce(sum(field_bunches),0) AS today_field_bunches,
|
|
150
|
+
round(coalesce(sum(ramp_weight),0)::numeric,4) AS today_ramp_weight,
|
|
151
|
+
sum(case when transaction_type = 'HARVEST' OR transaction_type = 'BUNCHES_ADJUSTMENT' then field_bunches else 0 end) as today_bunch_harvest,
|
|
152
|
+
sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then -field_bunches else 0 end) as today_bunch_collected,
|
|
153
|
+
round(sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then ramp_weight else 0 end)::numeric,4) as today_ramp_weight_collected,
|
|
154
|
+
round(sum(case when transaction_type = 'DISPATCHMENT' OR transaction_type = 'DISPATCHMENT_ADJUSTMENT' then -ramp_weight else 0 end)::numeric,4) as today_weight_dispatch,
|
|
155
|
+
transaction_date
|
|
156
|
+
from record_transactions t2
|
|
157
|
+
inner join temp_blocks blk on blk.id = t2.block_id
|
|
158
|
+
where transaction_date <= $1
|
|
159
|
+
group by blk.block_id, transaction_date
|
|
160
|
+
)
|
|
161
|
+
`,
|
|
162
|
+
[toDateString]
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
await tx.query(
|
|
166
|
+
`
|
|
167
|
+
create temp table temp_daily_production_data on commit drop as (
|
|
168
|
+
select *,
|
|
169
|
+
prev_bunch_bal_in_field + today_bunch_harvest as today_bunch_in_field,
|
|
170
|
+
prev_bunch_bal_in_field + today_bunch_harvest - today_bunch_collected as today_bunch_bal_in_field,
|
|
171
|
+
prev_weight_bal_in_ramp + today_ramp_weight_collected - today_weight_dispatch as today_weight_bal_in_ramp FROM (
|
|
172
|
+
select md.dateDay as date_day,
|
|
173
|
+
coalesce(
|
|
174
|
+
(
|
|
175
|
+
select sum(today_field_bunches) from temp_records t2
|
|
176
|
+
where transaction_date::timestamp < md.dateDay
|
|
177
|
+
)
|
|
178
|
+
, 0) as prev_bunch_bal_in_field,
|
|
179
|
+
coalesce(
|
|
180
|
+
(
|
|
181
|
+
select sum(today_ramp_weight) from temp_records t2
|
|
182
|
+
where transaction_date::timestamp < md.dateDay
|
|
183
|
+
)
|
|
184
|
+
, 0) as prev_weight_bal_in_ramp,
|
|
185
|
+
coalesce(today_bunch_harvest, 0) as today_bunch_harvest,
|
|
186
|
+
coalesce(sum(today_bunch_harvest) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_harvest,
|
|
187
|
+
coalesce(today_bunch_collected, 0) as today_bunch_collected,
|
|
188
|
+
coalesce(sum(today_bunch_collected) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_collected,
|
|
189
|
+
coalesce(today_ramp_weight_collected, 0) as today_ramp_weight_collected,
|
|
190
|
+
coalesce(sum(today_ramp_weight_collected) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_ramp_weight_collected,
|
|
191
|
+
coalesce(today_weight_dispatch, 0) as today_weight_dispatch,
|
|
192
|
+
coalesce(sum(today_weight_dispatch) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_weight_dispatch,
|
|
193
|
+
coalesce(tot.today_out_turn, 0) as today_out_turn,
|
|
194
|
+
coalesce(sum(tot.today_out_turn) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_out_turn,
|
|
195
|
+
${blockId != 'all-blocks' && blockId != '' ? `(select name from blocks b2 WHERE id = '${blockId}')` : `''`} as block,
|
|
196
|
+
coalesce(thr.today_harvesting_round, 0) as today_harvesting_round,
|
|
197
|
+
coalesce(thr.today_hectare_cover, 0) as today_hectare_cover
|
|
198
|
+
from
|
|
199
|
+
(select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
200
|
+
left join (
|
|
201
|
+
select * from temp_records trx
|
|
202
|
+
where transaction_date between $1 and $2
|
|
203
|
+
order by transaction_date
|
|
204
|
+
) as dt on dt.transaction_date::date = md.dateDay
|
|
205
|
+
LEFT JOIN (
|
|
206
|
+
select sum(harvesting_round) AS today_harvesting_round, sum(coverage) AS today_hectare_cover, harvest_date
|
|
207
|
+
from daily_harvests dh
|
|
208
|
+
inner join temp_blocks blk on blk.id = dh.block_id
|
|
209
|
+
where harvest_date between $1 and $2
|
|
210
|
+
group by blk.block_id, harvest_date
|
|
211
|
+
) as thr ON thr.harvest_date::date = md.dateDay
|
|
212
|
+
LEFT JOIN (
|
|
213
|
+
select count(*) AS today_out_turn, dh.harvest_date
|
|
214
|
+
from daily_harvest_details dhd
|
|
215
|
+
inner join daily_harvests dh on dh.id = dhd.daily_harvest_id
|
|
216
|
+
inner join temp_blocks blk on blk.id = dh.block_id
|
|
217
|
+
where dh.harvest_date between $1 and $2
|
|
218
|
+
GROUP BY blk.block_id, dh.harvest_date
|
|
219
|
+
) as tot ON tot.harvest_date::date = md.dateDay
|
|
220
|
+
) dt
|
|
221
|
+
)`,
|
|
222
|
+
[fromDateString, toDateString]
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
const result: any = await tx.query(`
|
|
226
|
+
select * from temp_daily_production_data dt
|
|
227
|
+
`)
|
|
228
|
+
|
|
229
|
+
return result.map(itm => {
|
|
230
|
+
return {
|
|
231
|
+
block: itm.block,
|
|
232
|
+
dateDay: itm.date_day,
|
|
233
|
+
diffInBunches: parseFloat(itm.diff_in_bunches).toFixed(1),
|
|
234
|
+
prevBunchBalInField: parseFloat(itm.prev_bunch_bal_in_field).toFixed(1),
|
|
235
|
+
prevWeightBalInRamp: parseFloat(itm.prev_weight_bal_in_ramp).toFixed(4),
|
|
236
|
+
toDateBunchHarvest: parseFloat(itm.to_date_bunch_harvest).toFixed(1),
|
|
237
|
+
toDateOutTurn: itm.to_date_out_turn,
|
|
238
|
+
toDateWeightDispatch: parseFloat(itm.to_date_weight_dispatch).toFixed(4),
|
|
239
|
+
todayBunchBalInField: parseFloat(itm.today_bunch_bal_in_field).toFixed(1),
|
|
240
|
+
todayBunchCollected: parseFloat(itm.today_bunch_collected).toFixed(1),
|
|
241
|
+
todayBunchHarvest: parseFloat(itm.today_bunch_harvest).toFixed(1),
|
|
242
|
+
todayBunchInField: parseFloat(itm.today_bunch_in_field).toFixed(1),
|
|
243
|
+
todayHarvestingRound: itm.today_harvesting_round,
|
|
244
|
+
todayHectareCover: parseFloat(itm.today_hectare_cover).toFixed(4),
|
|
245
|
+
todayOutTurn: itm.today_out_turn,
|
|
246
|
+
todayWeightCollected: parseFloat(itm.today_ramp_weight_collected).toFixed(4),
|
|
247
|
+
todayWeightBalInRamp: parseFloat(itm.today_weight_bal_in_ramp).toFixed(4),
|
|
248
|
+
todayWeightDispatch: parseFloat(itm.today_weight_dispatch).toFixed(4),
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { EntityManager, getRepository, Not, IsNull } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { ListParam, Domain } from '@things-factory/shell'
|
|
4
|
+
import { Block, Organization, Ramp } from '../../../entities'
|
|
5
|
+
|
|
6
|
+
export const dailyFfbDispatchProductionReports = {
|
|
7
|
+
async dailyFfbDispatchProductionReports(_: any, params: ListParam, context: any) {
|
|
8
|
+
try {
|
|
9
|
+
const { domain, tx }: { domain: Domain, tx: EntityManager } = context.state
|
|
10
|
+
|
|
11
|
+
let year = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[0])
|
|
12
|
+
let month = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[1])
|
|
13
|
+
|
|
14
|
+
let fromDate = new Date(year, month - 1, 1)
|
|
15
|
+
let toDate = new Date(year, month, 1)
|
|
16
|
+
toDate.setDate(toDate.getDate() - 1)
|
|
17
|
+
|
|
18
|
+
let fromDateString = [
|
|
19
|
+
fromDate.getFullYear().toString(),
|
|
20
|
+
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
21
|
+
'01'
|
|
22
|
+
].join('-')
|
|
23
|
+
|
|
24
|
+
let toDateString = [
|
|
25
|
+
toDate.getFullYear().toString(),
|
|
26
|
+
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
27
|
+
String(toDate.getDate()).padStart(2, '0')
|
|
28
|
+
].join('-')
|
|
29
|
+
|
|
30
|
+
let ramps = await getRepository(Ramp).find({
|
|
31
|
+
where: { domain: domain.id, deletedAt: IsNull() },
|
|
32
|
+
relations: ['block']
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let organizations = await getRepository(Organization).find({
|
|
36
|
+
where: { domain: domain.id, deletedAt: IsNull() }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
let blocks = await tx.getRepository(Block).query(`
|
|
40
|
+
SELECT b.id, b.name FROM ramps r
|
|
41
|
+
INNER JOIN blocks b ON b.id = r.block_id
|
|
42
|
+
WHERE b.deleted_at IS NULL
|
|
43
|
+
AND r.domain_id = $1
|
|
44
|
+
GROUP BY b.id, b.name
|
|
45
|
+
`, [domain.id])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// -- WHERE dd.dispatch_at::timestamp between $1::timestamp and $2::timestamp
|
|
49
|
+
// [fromDateString, toDateString]
|
|
50
|
+
await tx.query(`create extension if not exists tablefunc`)
|
|
51
|
+
|
|
52
|
+
await tx.query(
|
|
53
|
+
`
|
|
54
|
+
CREATE TEMP TABLE raw_block_dispatch ON COMMIT DROP AS (
|
|
55
|
+
SELECT "name", "dispatch_at", sum(weight) AS weight FROM(
|
|
56
|
+
SELECT * FROM (
|
|
57
|
+
SELECT dd.id,COALESCE(b.name, 'unknown') AS name, 1 AS "rank", dd.dispatch_at::date AS dispatch_at,
|
|
58
|
+
COALESCE(ddd.adjusted_weight, ddd.collected_ramp_weight, 0) AS weight
|
|
59
|
+
FROM daily_dispatches dd
|
|
60
|
+
INNER JOIN daily_dispatch_details ddd ON ddd.daily_dispatch_id = dd.id
|
|
61
|
+
INNER JOIN ramps r ON r.id = ddd.ramp_id
|
|
62
|
+
INNER JOIN blocks b ON b.id = r.block_id
|
|
63
|
+
WHERE dd.dispatch_at::date between $1 and $2
|
|
64
|
+
UNION
|
|
65
|
+
SELECT dd.id, COALESCE(c.name, 'unknown') AS name, CASE WHEN c.name IS NULL THEN 3 ELSE 2 END AS "rank", dd.dispatch_at::date AS dispatch_at,
|
|
66
|
+
COALESCE((SELECT SUM(COALESCE(ddd.adjusted_weight, ddd.collected_ramp_weight, 0)) FROM daily_dispatch_details ddd WHERE ddd.daily_dispatch_id = dd.id),0) AS weight
|
|
67
|
+
FROM daily_dispatches dd
|
|
68
|
+
LEFT JOIN organizations c ON c.id = dd.dispatch_to_id
|
|
69
|
+
WHERE dd.dispatch_at::date between $1 and $2
|
|
70
|
+
) foo
|
|
71
|
+
ORDER BY "rank", "name", "dispatch_at"
|
|
72
|
+
) foo
|
|
73
|
+
GROUP BY "name", "dispatch_at"
|
|
74
|
+
ORDER BY name, "dispatch_at"
|
|
75
|
+
)
|
|
76
|
+
`,
|
|
77
|
+
[fromDateString, toDateString]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
await tx.query(
|
|
81
|
+
`
|
|
82
|
+
CREATE TEMP TABLE pivot_block_dispatch ON COMMIT DROP AS (
|
|
83
|
+
SELECT * FROM crosstab(
|
|
84
|
+
$$
|
|
85
|
+
SELECT rbd."dispatch_at", rbd."name",
|
|
86
|
+
CONCAT('today: ', round(rbd.weight,2)::varchar, ' | todate: ', round(coalesce(sum(rbd.weight) over (PARTITION BY "name" ORDER BY name, dispatch_at asc rows between unbounded preceding and current row), 0),2)::varchar) AS weight
|
|
87
|
+
FROM raw_block_dispatch rbd
|
|
88
|
+
ORDER BY rbd."dispatch_at", rbd."name"
|
|
89
|
+
$$,
|
|
90
|
+
$$
|
|
91
|
+
SELECT b.name FROM ramps r INNER JOIN blocks b ON b.id = r.block_id WHERE r.deleted_at IS NULL AND r.domain_id = '${domain.id}'
|
|
92
|
+
GROUP BY b.id, b.name
|
|
93
|
+
UNION
|
|
94
|
+
SELECT c.name FROM organizations c
|
|
95
|
+
$$
|
|
96
|
+
) AS (dispatch_at date, ${[...blocks.map(block => `"${block.name}" varchar`), ...organizations.map(organization => `"${organization.name}" varchar`)].join(',')},"unknown" varchar)
|
|
97
|
+
);
|
|
98
|
+
`
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
await tx.query(
|
|
102
|
+
`
|
|
103
|
+
CREATE TEMP TABLE temp_monthly_production_data ON COMMIT DROP AS (
|
|
104
|
+
SELECT TO_CHAR(md.dateDay:: DATE, 'dd/mm/yyyy') as "date"
|
|
105
|
+
, row_to_json((SELECT d FROM (SELECT ${[...blocks.map(block => `pbd."${block.name}"`), ...organizations.map(organization => `pbd."${organization.name}"`)].join(',')}, pbd."unknown") d))::varchar as "blockData"
|
|
106
|
+
, (SELECT sum(weight) FROM raw_block_dispatch rbd WHERE rbd.dispatch_at = pbd.dispatch_at) AS "today"
|
|
107
|
+
FROM (select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
108
|
+
LEFT JOIN pivot_block_dispatch pbd on pbd.dispatch_at::date = md.dateDay
|
|
109
|
+
);
|
|
110
|
+
`
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
const result: any = await tx.query(
|
|
114
|
+
`
|
|
115
|
+
select "date", "blockData", "today"
|
|
116
|
+
from temp_monthly_production_data dt
|
|
117
|
+
`
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const total: any = await tx.query(
|
|
121
|
+
`
|
|
122
|
+
select count(*) from temp_monthly_production_data
|
|
123
|
+
`
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
items: result.map(itm => {
|
|
129
|
+
return {
|
|
130
|
+
...itm
|
|
131
|
+
}
|
|
132
|
+
}), total: total[0].count
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw error
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|