@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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { EntityManager } from 'typeorm'
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Query = void 0;
|
|
3
|
+
exports.getDailyProductionData = exports.Query = void 0;
|
|
5
4
|
// import { buildQuery, ListParam } from '@things-factory/shell'
|
|
6
5
|
exports.Query = {
|
|
7
6
|
/**
|
|
@@ -10,46 +9,34 @@ exports.Query = {
|
|
|
10
9
|
* @returns tonnage data with its sorted date
|
|
11
10
|
*/
|
|
12
11
|
async monthlyTonnageProductions(_, { blockId, yearAndMonth }, context) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let theDate = new Date(`${year}-${month}-${i}`);
|
|
22
|
-
theDate.setHours(8, 0, 0, 0);
|
|
23
|
-
data.push({
|
|
24
|
-
blockId,
|
|
25
|
-
tonnage: Math.floor(Math.random() * 1000) + 200,
|
|
26
|
-
year,
|
|
27
|
-
month,
|
|
28
|
-
date: theDate.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
12
|
+
try {
|
|
13
|
+
const { tx } = context.state;
|
|
14
|
+
const year = parseInt(yearAndMonth.substring(0, 4));
|
|
15
|
+
const month = parseInt(yearAndMonth.substring(4));
|
|
16
|
+
let data = await getDailyProductionData(blockId, year, month, tx);
|
|
17
|
+
let result = [];
|
|
18
|
+
result = data.map(itm => {
|
|
19
|
+
return Object.assign(Object.assign({}, itm), { blockId, tonnage: itm.todayWeightCollected, year: itm.dateDay.getFullYear(), month: itm.dateDay.getMonth(), date: itm.dateDay.toLocaleString('default', { day: '2-digit', month: 'short' }) });
|
|
29
20
|
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
catch (ex) {
|
|
30
24
|
}
|
|
31
|
-
return data.sort((a, b) => (a.date > b.date ? 1 : -1));
|
|
32
25
|
},
|
|
33
26
|
async monthlyYields(_, { blockId, yearAndMonth }, context) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let theDate = new Date(`${year}-${month}-${i}`);
|
|
43
|
-
theDate.setHours(8, 0, 0, 0);
|
|
44
|
-
data.push({
|
|
45
|
-
blockId,
|
|
46
|
-
yield: Math.floor(Math.random() * 1000) + 200,
|
|
47
|
-
year,
|
|
48
|
-
month,
|
|
49
|
-
date: theDate.toLocaleString('default', { day: '2-digit', month: 'short' })
|
|
27
|
+
try {
|
|
28
|
+
const { tx } = context.state;
|
|
29
|
+
const year = parseInt(yearAndMonth.substring(0, 4));
|
|
30
|
+
const month = parseInt(yearAndMonth.substring(4));
|
|
31
|
+
let data = await getDailyProductionData(blockId, year, month, tx);
|
|
32
|
+
let result = [];
|
|
33
|
+
result = data.map(itm => {
|
|
34
|
+
return Object.assign(Object.assign({}, itm), { blockId, yield: (itm.todayHectareCover != 0 ? itm.todayWeightCollected / itm.todayHectareCover : 0).toFixed(4), year: itm.dateDay.getFullYear(), month: itm.dateDay.getMonth(), date: itm.dateDay.toLocaleString('default', { day: '2-digit', month: 'short' }) });
|
|
50
35
|
});
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
catch (ex) {
|
|
51
39
|
}
|
|
52
|
-
return data.sort((a, b) => (a.date > b.date ? 1 : -1));
|
|
53
40
|
},
|
|
54
41
|
async weeklyBunchesCount(_, { targetDate }, context) {
|
|
55
42
|
if (!targetDate || targetDate == '')
|
|
@@ -58,8 +45,10 @@ exports.Query = {
|
|
|
58
45
|
for (let i = 0; i < 7; i++) {
|
|
59
46
|
bunchesCount.push({
|
|
60
47
|
date: new Date(targetDate).toLocaleString('default', { day: '2-digit', month: 'short' }),
|
|
61
|
-
harvestedCount:
|
|
62
|
-
collectedCount:
|
|
48
|
+
harvestedCount: 0,
|
|
49
|
+
collectedCount: 0
|
|
50
|
+
// harvestedCount: Math.floor(Math.random() * 1000) + 500,
|
|
51
|
+
// collectedCount: Math.floor(Math.random() * 500) + 50
|
|
63
52
|
});
|
|
64
53
|
targetDate.setDate(targetDate.getDate() - 1);
|
|
65
54
|
}
|
|
@@ -67,16 +56,149 @@ exports.Query = {
|
|
|
67
56
|
},
|
|
68
57
|
async tonnageAndBunchesInventories(_, { something }, context) {
|
|
69
58
|
return {
|
|
70
|
-
bunches:
|
|
71
|
-
tonnage:
|
|
59
|
+
bunches: 0,
|
|
60
|
+
tonnage: 0
|
|
61
|
+
// bunches: Math.floor(Math.random() * 10000) + 500,
|
|
62
|
+
// tonnage: Math.floor(Math.random() * 10000) + 500
|
|
72
63
|
};
|
|
73
64
|
},
|
|
74
65
|
async productionsOverview(_, { something }, context) {
|
|
75
66
|
return {
|
|
76
|
-
averageBunchWeight:
|
|
77
|
-
bunchesCount:
|
|
78
|
-
tonnageWeighed:
|
|
67
|
+
averageBunchWeight: 0,
|
|
68
|
+
bunchesCount: 0,
|
|
69
|
+
tonnageWeighed: 0,
|
|
70
|
+
// averageBunchWeight: Math.floor(Math.random() * 150) + 70,
|
|
71
|
+
// bunchesCount: Math.floor(Math.random() * 10000) + 500,
|
|
72
|
+
// tonnageWeighed: Math.floor(Math.random() * 10000) + 500
|
|
79
73
|
};
|
|
80
74
|
}
|
|
81
75
|
};
|
|
76
|
+
async function getDailyProductionData(blockId, year, month, tx) {
|
|
77
|
+
await tx.query(`
|
|
78
|
+
CREATE TEMP TABLE temp_blocks on commit drop AS (
|
|
79
|
+
WITH RECURSIVE b AS (
|
|
80
|
+
SELECT b.id AS block_id, * FROM blocks b
|
|
81
|
+
WHERE b.deleted_at IS null
|
|
82
|
+
UNION ALL
|
|
83
|
+
SELECT b.id AS block_id, cb.* FROM blocks cb
|
|
84
|
+
INNER JOIN b ON b.id = cb.parent_block_id
|
|
85
|
+
WHERE cb.deleted_at IS null
|
|
86
|
+
)
|
|
87
|
+
SELECT block_id, id, name FROM b
|
|
88
|
+
${blockId != 'all-blocks' && blockId != '' ? `WHERE block_id = '${blockId}' or id = '${blockId}'` : ``}
|
|
89
|
+
GROUP BY block_id, id, name
|
|
90
|
+
ORDER BY block_id, id, name
|
|
91
|
+
);
|
|
92
|
+
`);
|
|
93
|
+
let fromDate = new Date(year, month - 1, 1);
|
|
94
|
+
let toDate = new Date(year, month, 1);
|
|
95
|
+
toDate.setDate(toDate.getDate() - 1);
|
|
96
|
+
let fromDateString = [
|
|
97
|
+
fromDate.getFullYear().toString(),
|
|
98
|
+
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
99
|
+
'01'
|
|
100
|
+
].join('-');
|
|
101
|
+
let toDateString = [
|
|
102
|
+
toDate.getFullYear().toString(),
|
|
103
|
+
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
104
|
+
String(toDate.getDate()).padStart(2, '0')
|
|
105
|
+
].join('-');
|
|
106
|
+
await tx.query(`
|
|
107
|
+
CREATE TEMP TABLE temp_records on commit drop AS (
|
|
108
|
+
select blk.block_id, coalesce(sum(field_bunches),0) AS today_field_bunches,
|
|
109
|
+
round(coalesce(sum(ramp_weight),0)::numeric,4) AS today_ramp_weight,
|
|
110
|
+
sum(case when transaction_type = 'HARVEST' OR transaction_type = 'BUNCHES_ADJUSTMENT' then field_bunches else 0 end) as today_bunch_harvest,
|
|
111
|
+
sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then -field_bunches else 0 end) as today_bunch_collected,
|
|
112
|
+
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,
|
|
113
|
+
round(sum(case when transaction_type = 'DISPATCHMENT' OR transaction_type = 'DISPATCHMENT_ADJUSTMENT' then -ramp_weight else 0 end)::numeric,4) as today_weight_dispatch,
|
|
114
|
+
transaction_date
|
|
115
|
+
from record_transactions t2
|
|
116
|
+
inner join temp_blocks blk on blk.id = t2.block_id
|
|
117
|
+
where transaction_date <= $1
|
|
118
|
+
group by blk.block_id, transaction_date
|
|
119
|
+
)
|
|
120
|
+
`, [toDateString]);
|
|
121
|
+
await tx.query(`
|
|
122
|
+
create temp table temp_daily_production_data on commit drop as (
|
|
123
|
+
select *,
|
|
124
|
+
prev_bunch_bal_in_field + today_bunch_harvest as today_bunch_in_field,
|
|
125
|
+
prev_bunch_bal_in_field + today_bunch_harvest - today_bunch_collected as today_bunch_bal_in_field,
|
|
126
|
+
prev_weight_bal_in_ramp + today_ramp_weight_collected - today_weight_dispatch as today_weight_bal_in_ramp FROM (
|
|
127
|
+
select md.dateDay as date_day,
|
|
128
|
+
coalesce(
|
|
129
|
+
(
|
|
130
|
+
select sum(today_field_bunches) from temp_records t2
|
|
131
|
+
where transaction_date::timestamp < md.dateDay
|
|
132
|
+
)
|
|
133
|
+
, 0) as prev_bunch_bal_in_field,
|
|
134
|
+
coalesce(
|
|
135
|
+
(
|
|
136
|
+
select sum(today_ramp_weight) from temp_records t2
|
|
137
|
+
where transaction_date::timestamp < md.dateDay
|
|
138
|
+
)
|
|
139
|
+
, 0) as prev_weight_bal_in_ramp,
|
|
140
|
+
coalesce(today_bunch_harvest, 0) as today_bunch_harvest,
|
|
141
|
+
coalesce(sum(today_bunch_harvest) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_harvest,
|
|
142
|
+
coalesce(today_bunch_collected, 0) as today_bunch_collected,
|
|
143
|
+
coalesce(sum(today_bunch_collected) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_collected,
|
|
144
|
+
coalesce(today_ramp_weight_collected, 0) as today_ramp_weight_collected,
|
|
145
|
+
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,
|
|
146
|
+
coalesce(today_weight_dispatch, 0) as today_weight_dispatch,
|
|
147
|
+
coalesce(sum(today_weight_dispatch) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_weight_dispatch,
|
|
148
|
+
coalesce(tot.today_out_turn, 0) as today_out_turn,
|
|
149
|
+
coalesce(sum(tot.today_out_turn) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_out_turn,
|
|
150
|
+
${blockId != 'all-blocks' && blockId != '' ? `(select name from blocks b2 WHERE id = '${blockId}')` : `''`} as block,
|
|
151
|
+
coalesce(thr.today_harvesting_round, 0) as today_harvesting_round,
|
|
152
|
+
coalesce(thr.today_hectare_cover, 0) as today_hectare_cover
|
|
153
|
+
from
|
|
154
|
+
(select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
155
|
+
left join (
|
|
156
|
+
select * from temp_records trx
|
|
157
|
+
where transaction_date between $1 and $2
|
|
158
|
+
order by transaction_date
|
|
159
|
+
) as dt on dt.transaction_date::date = md.dateDay
|
|
160
|
+
LEFT JOIN (
|
|
161
|
+
select sum(harvesting_round) AS today_harvesting_round, sum(coverage) AS today_hectare_cover, harvest_date
|
|
162
|
+
from daily_harvests dh
|
|
163
|
+
inner join temp_blocks blk on blk.id = dh.block_id
|
|
164
|
+
where harvest_date between $1 and $2
|
|
165
|
+
group by blk.block_id, harvest_date
|
|
166
|
+
) as thr ON thr.harvest_date::date = md.dateDay
|
|
167
|
+
LEFT JOIN (
|
|
168
|
+
select count(*) AS today_out_turn, dh.harvest_date
|
|
169
|
+
from daily_harvest_details dhd
|
|
170
|
+
inner join daily_harvests dh on dh.id = dhd.daily_harvest_id
|
|
171
|
+
inner join temp_blocks blk on blk.id = dh.block_id
|
|
172
|
+
where dh.harvest_date between $1 and $2
|
|
173
|
+
GROUP BY blk.block_id, dh.harvest_date
|
|
174
|
+
) as tot ON tot.harvest_date::date = md.dateDay
|
|
175
|
+
) dt
|
|
176
|
+
)`, [fromDateString, toDateString]);
|
|
177
|
+
const result = await tx.query(`
|
|
178
|
+
select * from temp_daily_production_data dt
|
|
179
|
+
`);
|
|
180
|
+
return result.map(itm => {
|
|
181
|
+
return {
|
|
182
|
+
block: itm.block,
|
|
183
|
+
dateDay: itm.date_day,
|
|
184
|
+
diffInBunches: parseFloat(itm.diff_in_bunches).toFixed(1),
|
|
185
|
+
prevBunchBalInField: parseFloat(itm.prev_bunch_bal_in_field).toFixed(1),
|
|
186
|
+
prevWeightBalInRamp: parseFloat(itm.prev_weight_bal_in_ramp).toFixed(4),
|
|
187
|
+
toDateBunchHarvest: parseFloat(itm.to_date_bunch_harvest).toFixed(1),
|
|
188
|
+
toDateOutTurn: itm.to_date_out_turn,
|
|
189
|
+
toDateWeightDispatch: parseFloat(itm.to_date_weight_dispatch).toFixed(4),
|
|
190
|
+
todayBunchBalInField: parseFloat(itm.today_bunch_bal_in_field).toFixed(1),
|
|
191
|
+
todayBunchCollected: parseFloat(itm.today_bunch_collected).toFixed(1),
|
|
192
|
+
todayBunchHarvest: parseFloat(itm.today_bunch_harvest).toFixed(1),
|
|
193
|
+
todayBunchInField: parseFloat(itm.today_bunch_in_field).toFixed(1),
|
|
194
|
+
todayHarvestingRound: itm.today_harvesting_round,
|
|
195
|
+
todayHectareCover: parseFloat(itm.today_hectare_cover).toFixed(4),
|
|
196
|
+
todayOutTurn: itm.today_out_turn,
|
|
197
|
+
todayWeightCollected: parseFloat(itm.today_ramp_weight_collected).toFixed(4),
|
|
198
|
+
todayWeightBalInRamp: parseFloat(itm.today_weight_bal_in_ramp).toFixed(4),
|
|
199
|
+
todayWeightDispatch: parseFloat(itm.today_weight_dispatch).toFixed(4),
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
exports.getDailyProductionData = getDailyProductionData;
|
|
82
204
|
//# sourceMappingURL=dashboard-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-query.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/dashboard/dashboard-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard-query.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/dashboard/dashboard-query.ts"],"names":[],"mapp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AA;IACH,CAAC,CAAC,CAAA;AAEJ,CAAC;AAhJD,wDAgJC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dailyFfbDispatchProductionReports = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const entities_1 = require("../../../entities");
|
|
6
|
+
exports.dailyFfbDispatchProductionReports = {
|
|
7
|
+
async dailyFfbDispatchProductionReports(_, params, context) {
|
|
8
|
+
try {
|
|
9
|
+
const { domain, tx } = context.state;
|
|
10
|
+
let year = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[0]);
|
|
11
|
+
let month = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[1]);
|
|
12
|
+
let fromDate = new Date(year, month - 1, 1);
|
|
13
|
+
let toDate = new Date(year, month, 1);
|
|
14
|
+
toDate.setDate(toDate.getDate() - 1);
|
|
15
|
+
let fromDateString = [
|
|
16
|
+
fromDate.getFullYear().toString(),
|
|
17
|
+
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
18
|
+
'01'
|
|
19
|
+
].join('-');
|
|
20
|
+
let toDateString = [
|
|
21
|
+
toDate.getFullYear().toString(),
|
|
22
|
+
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
23
|
+
String(toDate.getDate()).padStart(2, '0')
|
|
24
|
+
].join('-');
|
|
25
|
+
let ramps = await (0, typeorm_1.getRepository)(entities_1.Ramp).find({
|
|
26
|
+
where: { domain: domain.id, deletedAt: (0, typeorm_1.IsNull)() },
|
|
27
|
+
relations: ['block']
|
|
28
|
+
});
|
|
29
|
+
let organizations = await (0, typeorm_1.getRepository)(entities_1.Organization).find({
|
|
30
|
+
where: { domain: domain.id, deletedAt: (0, typeorm_1.IsNull)() }
|
|
31
|
+
});
|
|
32
|
+
let blocks = await tx.getRepository(entities_1.Block).query(`
|
|
33
|
+
SELECT b.id, b.name FROM ramps r
|
|
34
|
+
INNER JOIN blocks b ON b.id = r.block_id
|
|
35
|
+
WHERE b.deleted_at IS NULL
|
|
36
|
+
AND r.domain_id = $1
|
|
37
|
+
GROUP BY b.id, b.name
|
|
38
|
+
`, [domain.id]);
|
|
39
|
+
// -- WHERE dd.dispatch_at::timestamp between $1::timestamp and $2::timestamp
|
|
40
|
+
// [fromDateString, toDateString]
|
|
41
|
+
await tx.query(`create extension if not exists tablefunc`);
|
|
42
|
+
await tx.query(`
|
|
43
|
+
CREATE TEMP TABLE raw_block_dispatch ON COMMIT DROP AS (
|
|
44
|
+
SELECT "name", "dispatch_at", sum(weight) AS weight FROM(
|
|
45
|
+
SELECT * FROM (
|
|
46
|
+
SELECT dd.id,COALESCE(b.name, 'unknown') AS name, 1 AS "rank", dd.dispatch_at::date AS dispatch_at,
|
|
47
|
+
COALESCE(ddd.adjusted_weight, ddd.collected_ramp_weight, 0) AS weight
|
|
48
|
+
FROM daily_dispatches dd
|
|
49
|
+
INNER JOIN daily_dispatch_details ddd ON ddd.daily_dispatch_id = dd.id
|
|
50
|
+
INNER JOIN ramps r ON r.id = ddd.ramp_id
|
|
51
|
+
INNER JOIN blocks b ON b.id = r.block_id
|
|
52
|
+
WHERE dd.dispatch_at::date between $1 and $2
|
|
53
|
+
UNION
|
|
54
|
+
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,
|
|
55
|
+
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
|
|
56
|
+
FROM daily_dispatches dd
|
|
57
|
+
LEFT JOIN organizations c ON c.id = dd.dispatch_to_id
|
|
58
|
+
WHERE dd.dispatch_at::date between $1 and $2
|
|
59
|
+
) foo
|
|
60
|
+
ORDER BY "rank", "name", "dispatch_at"
|
|
61
|
+
) foo
|
|
62
|
+
GROUP BY "name", "dispatch_at"
|
|
63
|
+
ORDER BY name, "dispatch_at"
|
|
64
|
+
)
|
|
65
|
+
`, [fromDateString, toDateString]);
|
|
66
|
+
await tx.query(`
|
|
67
|
+
CREATE TEMP TABLE pivot_block_dispatch ON COMMIT DROP AS (
|
|
68
|
+
SELECT * FROM crosstab(
|
|
69
|
+
$$
|
|
70
|
+
SELECT rbd."dispatch_at", rbd."name",
|
|
71
|
+
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
|
|
72
|
+
FROM raw_block_dispatch rbd
|
|
73
|
+
ORDER BY rbd."dispatch_at", rbd."name"
|
|
74
|
+
$$,
|
|
75
|
+
$$
|
|
76
|
+
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}'
|
|
77
|
+
GROUP BY b.id, b.name
|
|
78
|
+
UNION
|
|
79
|
+
SELECT c.name FROM organizations c
|
|
80
|
+
$$
|
|
81
|
+
) AS (dispatch_at date, ${[...blocks.map(block => `"${block.name}" varchar`), ...organizations.map(organization => `"${organization.name}" varchar`)].join(',')},"unknown" varchar)
|
|
82
|
+
);
|
|
83
|
+
`);
|
|
84
|
+
await tx.query(`
|
|
85
|
+
CREATE TEMP TABLE temp_monthly_production_data ON COMMIT DROP AS (
|
|
86
|
+
SELECT TO_CHAR(md.dateDay:: DATE, 'dd/mm/yyyy') as "date"
|
|
87
|
+
, 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"
|
|
88
|
+
, (SELECT sum(weight) FROM raw_block_dispatch rbd WHERE rbd.dispatch_at = pbd.dispatch_at) AS "today"
|
|
89
|
+
FROM (select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
90
|
+
LEFT JOIN pivot_block_dispatch pbd on pbd.dispatch_at::date = md.dateDay
|
|
91
|
+
);
|
|
92
|
+
`);
|
|
93
|
+
const result = await tx.query(`
|
|
94
|
+
select "date", "blockData", "today"
|
|
95
|
+
from temp_monthly_production_data dt
|
|
96
|
+
`);
|
|
97
|
+
const total = await tx.query(`
|
|
98
|
+
select count(*) from temp_monthly_production_data
|
|
99
|
+
`);
|
|
100
|
+
return {
|
|
101
|
+
items: result.map(itm => {
|
|
102
|
+
return Object.assign({}, itm);
|
|
103
|
+
}), total: total[0].count
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=daily-ffb-dispatch-production-reports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-ffb-dispatch-production-reports.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.ts"],"names":[],"mappings":";;;AAAA,qCAAmE;AAGnE,gDAA6D;AAEhD,QAAA,iCAAiC,GAAG;IAC/C,KAAK,CAAC,iCAAiC,CAAC,CAAM,EAAE,MAAiB,EAAE,OAAY;QAC7E,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAA0C,OAAO,CAAC,KAAK,CAAA;YAE3E,IAAI,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACzF,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAA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YAED,MAAM,KAAK,GAAQ,MAAM,EAAE,CAAC,KAAK,CAC/B;;SAEC,CACF,CAAA;YAGD,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACtB,yBACK,GAAG,EACP;gBACH,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;aAC1B,CAAA;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA"}
|
|
@@ -42,10 +42,10 @@ exports.dailyProductionReports = {
|
|
|
42
42
|
CREATE TEMP TABLE temp_records on commit drop AS (
|
|
43
43
|
select blk.block_id, coalesce(sum(field_bunches),0) AS today_field_bunches,
|
|
44
44
|
round(coalesce(sum(ramp_weight),0)::numeric,4) AS today_ramp_weight,
|
|
45
|
-
sum(case when transaction_type = 'HARVEST' then field_bunches else 0 end) as today_bunch_harvest,
|
|
46
|
-
sum(case when transaction_type = 'LOADING' then -field_bunches else 0 end) as today_bunch_collected,
|
|
47
|
-
round(sum(case when transaction_type = 'LOADING' then ramp_weight else 0 end)::numeric,4) as today_ramp_weight_collected,
|
|
48
|
-
round(sum(case when transaction_type = 'DISPATCHMENT' then -ramp_weight else 0 end)::numeric,4) as today_weight_dispatch,
|
|
45
|
+
sum(case when transaction_type = 'HARVEST' OR transaction_type = 'BUNCHES_ADJUSTMENT' then field_bunches else 0 end) as today_bunch_harvest,
|
|
46
|
+
sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then -field_bunches else 0 end) as today_bunch_collected,
|
|
47
|
+
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,
|
|
48
|
+
round(sum(case when transaction_type = 'DISPATCHMENT' OR transaction_type = 'DISPATCHMENT_ADJUSTMENT' then -ramp_weight else 0 end)::numeric,4) as today_weight_dispatch,
|
|
49
49
|
transaction_date
|
|
50
50
|
from record_transactions t2
|
|
51
51
|
inner join temp_blocks blk on blk.id = t2.block_id
|
|
@@ -110,10 +110,10 @@ exports.dailyProductionReports = {
|
|
|
110
110
|
) dt
|
|
111
111
|
)`, [fromDateString, toDateString, block.id]);
|
|
112
112
|
const result = await tx.query(`
|
|
113
|
-
|
|
113
|
+
select * from temp_daily_production_data dt
|
|
114
114
|
`);
|
|
115
115
|
const total = await tx.query(`
|
|
116
|
-
|
|
116
|
+
select count(*) from temp_daily_production_data
|
|
117
117
|
`);
|
|
118
118
|
let items = result.map(itm => {
|
|
119
119
|
return {
|
|
@@ -8,8 +8,9 @@ const yearly_production_reports_1 = require("./yearly-production-reports");
|
|
|
8
8
|
const daily_staff_harvest_reports_1 = require("./daily-staff-harvest-reports");
|
|
9
9
|
const monthly_block_dispatch_reports_1 = require("./monthly-block-dispatch-reports");
|
|
10
10
|
const monthly_ffb_sale_reports_1 = require("./monthly-ffb-sale-reports");
|
|
11
|
+
const daily_ffb_dispatch_production_reports_1 = require("./daily-ffb-dispatch-production-reports");
|
|
11
12
|
exports.ReportResolver = {
|
|
12
|
-
Query: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, daily_production_reports_1.dailyProductionReports), monthly_production_reports_1.monthlyProductionReports), monthly_dispatch_summary_reports_1.monthlyDispatchSummaryReports), yearly_production_reports_1.yearlyProductionReports), daily_staff_harvest_reports_1.dailyStaffHarvestReports), monthly_block_dispatch_reports_1.monthlyBlockDispatchReports), monthly_ffb_sale_reports_1.monthlyFfbSaleReports),
|
|
13
|
+
Query: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, daily_production_reports_1.dailyProductionReports), monthly_production_reports_1.monthlyProductionReports), monthly_dispatch_summary_reports_1.monthlyDispatchSummaryReports), yearly_production_reports_1.yearlyProductionReports), daily_staff_harvest_reports_1.dailyStaffHarvestReports), monthly_block_dispatch_reports_1.monthlyBlockDispatchReports), monthly_ffb_sale_reports_1.monthlyFfbSaleReports), daily_ffb_dispatch_production_reports_1.dailyFfbDispatchProductionReports),
|
|
13
14
|
Mutation: {}
|
|
14
15
|
};
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/report/index.ts"],"names":[],"mappings":";;;AAAA,yEAAmE;AACnE,6EAAuE;AACvE,yFAAkF;AAClF,2EAAqE;AACrE,+EAAwE;AACxE,qFAA8E;AAC9E,yEAAkE;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/report/index.ts"],"names":[],"mappings":";;;AAAA,yEAAmE;AACnE,6EAAuE;AACvE,yFAAkF;AAClF,2EAAqE;AACrE,+EAAwE;AACxE,qFAA8E;AAC9E,yEAAkE;AAClE,mGAA2F;AAE9E,QAAA,cAAc,GAAG;IAC5B,KAAK,sHACA,iDAAsB,GACtB,qDAAwB,GACxB,gEAA6B,GAC7B,mDAAuB,GACvB,sDAAwB,GACxB,4DAA2B,GAC3B,gDAAqB,GACrB,yEAAiC,CACrC;IACD,QAAQ,EAAE,EAAE;CACb,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.monthlyBlockDispatchReports = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
4
|
const entities_1 = require("../../../entities");
|
|
6
5
|
exports.monthlyBlockDispatchReports = {
|
|
7
6
|
async monthlyBlockDispatchReports(_, params, context) {
|
|
@@ -22,10 +21,13 @@ exports.monthlyBlockDispatchReports = {
|
|
|
22
21
|
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
23
22
|
String(toDate.getDate()).padStart(2, '0')
|
|
24
23
|
].join('-');
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
let blocks = await tx.getRepository(entities_1.Block).query(`
|
|
25
|
+
SELECT b.id, b.name FROM ramps r
|
|
26
|
+
INNER JOIN blocks b ON b.id = r.block_id
|
|
27
|
+
WHERE b.deleted_at IS NULL
|
|
28
|
+
AND r.domain_id = $1
|
|
29
|
+
GROUP BY b.id, b.name
|
|
30
|
+
`, [domain.id]);
|
|
29
31
|
// -- WHERE dd.dispatch_at::timestamp between $1::timestamp and $2::timestamp
|
|
30
32
|
// [fromDateString, toDateString]
|
|
31
33
|
await tx.query(`create extension if not exists tablefunc`);
|
|
@@ -44,8 +46,8 @@ exports.monthlyBlockDispatchReports = {
|
|
|
44
46
|
CREATE TEMP TABLE pivot_block_dispatch ON COMMIT DROP AS (
|
|
45
47
|
SELECT * FROM crosstab(
|
|
46
48
|
$$SELECT rbd.id, rbd.block_name, round(rbd.weight, 2 )::varchar FROM raw_block_dispatch rbd$$,
|
|
47
|
-
$$SELECT b.name FROM ramps r INNER JOIN blocks b ON b.id = r.block_id WHERE r.deleted_at IS NULL$$
|
|
48
|
-
) AS ("id" uuid, ${
|
|
49
|
+
$$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}' GROUP BY b.id, b.name$$
|
|
50
|
+
) AS ("id" uuid, ${blocks.map(block => `"${block.name}" varchar`).join(',')})
|
|
49
51
|
);
|
|
50
52
|
`);
|
|
51
53
|
await tx.query(`
|
|
@@ -59,7 +61,7 @@ exports.monthlyBlockDispatchReports = {
|
|
|
59
61
|
, dd.transport_no as "lorryNo"
|
|
60
62
|
, dd.driver_identification as "driverIdentification"
|
|
61
63
|
, TO_CHAR(dd.dispatch_at:: DATE, 'dd/mm/yyyy') as "date"
|
|
62
|
-
, row_to_json((SELECT d FROM (SELECT ${
|
|
64
|
+
, row_to_json((SELECT d FROM (SELECT ${blocks.map(block => `pbd."${block.name}"`).join(',')}) d))::varchar as "blockData"
|
|
63
65
|
, (SELECT sum(weight) FROM raw_block_dispatch rbd WHERE rbd.id = dd.id) AS "today"
|
|
64
66
|
FROM daily_dispatches dd
|
|
65
67
|
INNER JOIN pivot_block_dispatch pbd ON pbd.id = dd.id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monthly-block-dispatch-reports.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/report/monthly-block-dispatch-reports.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"monthly-block-dispatch-reports.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/report/monthly-block-dispatch-reports.ts"],"names":[],"mappings":";;;AAGA,gDAA+C;AAElC,QAAA,2BAA2B,GAAG;IACzC,KAAK,CAAC,2BAA2B,CAAC,CAAM,EAAE,MAAiB,EAAE,OAAY;QACvE,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAA0C,OAAO,CAAC,KAAK,CAAA;YAE3E,IAAI,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACzF,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1F,IAAI,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;YAC3C,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;YACrC,MAAM,CAAC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GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;SAM9F,CACF,CAAA;YAED,MAAM,MAAM,GAAQ,MAAM,EAAE,CAAC,KAAK,CAChC;;;;;SAKC,CACF,CAAA;YAED,MAAM,KAAK,GAAQ,MAAM,EAAE,CAAC,KAAK,CAC/B;;SAEC,CACF,CAAA;YAGD,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBACtB,yBACK,GAAG,EACP;gBACH,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;aAC1B,CAAA;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA"}
|
|
@@ -35,7 +35,7 @@ exports.monthlyFfbSaleReports = {
|
|
|
35
35
|
SELECT "id", dispatch_at, transport_no AS "lorryNo",
|
|
36
36
|
driver_identification AS "driverIdentification", chit_no AS "chitNo", round(COALESCE(percentage,0)::numeric, 2)::varchar AS "percentage",
|
|
37
37
|
COALESCE(diapatch_to_name, 'UNKNOWN') AS "dispatchTo", round(COALESCE(tonnage,0), 2)::varchar AS "tonnage",
|
|
38
|
-
CASE WHEN forward_rn = 1 THEN dispatch_at::
|
|
38
|
+
CASE WHEN forward_rn = 1 THEN TO_CHAR(dispatch_at:: DATE, 'dd/mm/yyyy') ELSE '' END AS "dispatchAt",
|
|
39
39
|
CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (PARTITION BY dispatch_to_id, dispatch_at::date ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0)/forward_rn)::numeric,2)::varchar ELSE '' END AS "todayAvg",
|
|
40
40
|
CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (PARTITION BY dispatch_to_id ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0)/forward_rn)::numeric,2)::varchar ELSE '' END AS "todateAvg",
|
|
41
41
|
CASE WHEN reverse_rn = 1 THEN round(coalesce(sum(tonnage) over (PARTITION BY dispatch_to_id, dispatch_at::date ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0),2)::varchar ELSE '' END AS "today",
|
|
@@ -70,8 +70,8 @@ exports.monthlyProductionReports = {
|
|
|
70
70
|
left join(
|
|
71
71
|
select blk.block_id, sum(total_weight) as total_weight_loaded, sum(total_bunch) as total_bunch_loaded
|
|
72
72
|
from daily_loadings dl
|
|
73
|
-
inner join temp_blocks blk on blk.id = dl.block_id
|
|
74
73
|
inner join daily_loading_details dld on dld.daily_loading_id = dl.id
|
|
74
|
+
inner join temp_blocks blk on blk.id = dld.block_id
|
|
75
75
|
where dl.loading_date::timestamp between $1::timestamp and $2::timestamp
|
|
76
76
|
group by blk.block_id
|
|
77
77
|
) as loading on loading.block_id = b.id
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DailyFfbDispatchProductionReportList = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
exports.DailyFfbDispatchProductionReportList = (0, graphql_tag_1.default) `
|
|
9
|
+
type DailyFfbDispatchProductionReportList {
|
|
10
|
+
items: [DailyFfbDispatchProductionReport]
|
|
11
|
+
total: Int
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
//# sourceMappingURL=daily-ffb-dispatch-production-report-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-ffb-dispatch-production-report-list.js","sourceRoot":"","sources":["../../../../server/graphql/types/report/daily-ffb-dispatch-production-report-list.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,oCAAoC,GAAG,IAAA,qBAAG,EAAA;;;;;CAKtD,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DailyFfbDispatchProductionReport = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
exports.DailyFfbDispatchProductionReport = (0, graphql_tag_1.default) `
|
|
9
|
+
type DailyFfbDispatchProductionReport {
|
|
10
|
+
date: String
|
|
11
|
+
blockData: String
|
|
12
|
+
today: String
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
//# sourceMappingURL=daily-ffb-dispatch-production-report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-ffb-dispatch-production-report.js","sourceRoot":"","sources":["../../../../server/graphql/types/report/daily-ffb-dispatch-production-report.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,gCAAgC,GAAG,IAAA,qBAAG,EAAA;;;;;;CAMlD,CAAA"}
|
|
@@ -27,15 +27,19 @@ __exportStar(require("./monthly-production-report-list"), exports);
|
|
|
27
27
|
__exportStar(require("./monthly-production-report"), exports);
|
|
28
28
|
__exportStar(require("./yearly-production-report-list"), exports);
|
|
29
29
|
__exportStar(require("./yearly-production-report"), exports);
|
|
30
|
+
__exportStar(require("./daily-ffb-dispatch-production-report"), exports);
|
|
31
|
+
__exportStar(require("./daily-ffb-dispatch-production-report-list"), exports);
|
|
30
32
|
exports.ReportResolver = (0, graphql_tag_1.default) `
|
|
31
33
|
extend type Query {
|
|
32
34
|
dailyProductionReports(filters: [Filter], pagination: Pagination, sortings: [Sorting]): DailyProductionReportList
|
|
33
35
|
@transaction
|
|
36
|
+
|
|
34
37
|
monthlyProductionReports(
|
|
35
38
|
filters: [Filter]
|
|
36
39
|
pagination: Pagination
|
|
37
40
|
sortings: [Sorting]
|
|
38
41
|
): MonthlyProductionReportList @transaction
|
|
42
|
+
|
|
39
43
|
yearlyProductionReports(filters: [Filter], pagination: Pagination, sortings: [Sorting]): YearlyProductionReportList
|
|
40
44
|
@transaction
|
|
41
45
|
dailyStaffHarvestReports(
|
|
@@ -43,21 +47,30 @@ exports.ReportResolver = (0, graphql_tag_1.default) `
|
|
|
43
47
|
pagination: Pagination
|
|
44
48
|
sortings: [Sorting]
|
|
45
49
|
): DailyStaffHarvestReportList @transaction
|
|
50
|
+
|
|
46
51
|
monthlyDispatchSummaryReports(
|
|
47
52
|
filters: [Filter],
|
|
48
53
|
pagination: Pagination,
|
|
49
54
|
sortings: [Sorting]
|
|
50
55
|
): MonthlyDispatchSummaryReportList @transaction
|
|
56
|
+
|
|
51
57
|
monthlyBlockDispatchReports(
|
|
52
58
|
filters: [Filter],
|
|
53
59
|
pagination: Pagination,
|
|
54
60
|
sortings: [Sorting]
|
|
55
61
|
): MonthlyBlockDispatchReportList @transaction
|
|
62
|
+
|
|
56
63
|
monthlyFfbSaleReports(
|
|
57
64
|
filters: [Filter],
|
|
58
65
|
pagination: Pagination,
|
|
59
66
|
sortings: [Sorting]
|
|
60
67
|
): MonthlyDispatchSummaryReportList @transaction
|
|
68
|
+
|
|
69
|
+
dailyFfbDispatchProductionReports(
|
|
70
|
+
filters: [Filter],
|
|
71
|
+
pagination: Pagination,
|
|
72
|
+
sortings: [Sorting]
|
|
73
|
+
): DailyFfbDispatchProductionReportList @transaction
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
`;
|