@things-factory/operato-pms 4.3.595 → 4.3.601

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.
Files changed (68) hide show
  1. package/client/pages/harvesting/harvesting-create-record.js +5 -2
  2. package/client/pages/loading/edit-loading-record.js +2 -0
  3. package/client/pages/report/report-daily-ffb-dispatch-and-production.js +19 -23
  4. package/dist-server/entities/daily-dispatch.js +2 -2
  5. package/dist-server/entities/daily-dispatch.js.map +1 -1
  6. package/dist-server/entities/ramp-block-history.js.map +1 -1
  7. package/dist-server/graphql/resolvers/daily-dispatch/delete-daily-dispatch.js +49 -1
  8. package/dist-server/graphql/resolvers/daily-dispatch/delete-daily-dispatch.js.map +1 -1
  9. package/dist-server/graphql/resolvers/daily-dispatch/generate-daily-dispatch.js +124 -112
  10. package/dist-server/graphql/resolvers/daily-dispatch/generate-daily-dispatch.js.map +1 -1
  11. package/dist-server/graphql/resolvers/daily-dispatch/update-daily-dispatch.js +51 -2
  12. package/dist-server/graphql/resolvers/daily-dispatch/update-daily-dispatch.js.map +1 -1
  13. package/dist-server/graphql/resolvers/daily-harvest/delete-daily-harvest.js +5 -7
  14. package/dist-server/graphql/resolvers/daily-harvest/delete-daily-harvest.js.map +1 -1
  15. package/dist-server/graphql/resolvers/daily-harvest/generate-daily-harvest.js +3 -3
  16. package/dist-server/graphql/resolvers/daily-harvest/generate-daily-harvest.js.map +1 -1
  17. package/dist-server/graphql/resolvers/daily-loading/delete-daily-loading.js +6 -0
  18. package/dist-server/graphql/resolvers/daily-loading/delete-daily-loading.js.map +1 -1
  19. package/dist-server/graphql/resolvers/daily-loading/generate-daily-loading.js +68 -52
  20. package/dist-server/graphql/resolvers/daily-loading/generate-daily-loading.js.map +1 -1
  21. package/dist-server/graphql/resolvers/daily-loading/update-daily-loading.js +16 -22
  22. package/dist-server/graphql/resolvers/daily-loading/update-daily-loading.js.map +1 -1
  23. package/dist-server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.js +50 -19
  24. package/dist-server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.js.map +1 -1
  25. package/dist-server/graphql/resolvers/report/daily-production-reports.js +96 -67
  26. package/dist-server/graphql/resolvers/report/daily-production-reports.js.map +1 -1
  27. package/dist-server/graphql/resolvers/report/daily-staff-harvest-reports.js +1 -0
  28. package/dist-server/graphql/resolvers/report/daily-staff-harvest-reports.js.map +1 -1
  29. package/dist-server/graphql/resolvers/report/monthly-block-dispatch-reports.js +7 -2
  30. package/dist-server/graphql/resolvers/report/monthly-block-dispatch-reports.js.map +1 -1
  31. package/dist-server/graphql/resolvers/report/monthly-dispatch-summary-reports.js +11 -5
  32. package/dist-server/graphql/resolvers/report/monthly-dispatch-summary-reports.js.map +1 -1
  33. package/dist-server/graphql/resolvers/report/monthly-ffb-sale-reports.js +21 -9
  34. package/dist-server/graphql/resolvers/report/monthly-ffb-sale-reports.js.map +1 -1
  35. package/dist-server/graphql/resolvers/report/monthly-production-reports.js +5 -2
  36. package/dist-server/graphql/resolvers/report/monthly-production-reports.js.map +1 -1
  37. package/dist-server/graphql/resolvers/report/yearly-production-reports.js +5 -2
  38. package/dist-server/graphql/resolvers/report/yearly-production-reports.js.map +1 -1
  39. package/dist-server/graphql/types/daily-loading-detail/daily-loading-detail-patch.js +2 -0
  40. package/dist-server/graphql/types/daily-loading-detail/daily-loading-detail-patch.js.map +1 -1
  41. package/dist-server/utils/transaction-util.js +32 -53
  42. package/dist-server/utils/transaction-util.js.map +1 -1
  43. package/package.json +2 -2
  44. package/server/entities/daily-dispatch.ts +2 -2
  45. package/server/entities/ramp-block-history.ts +2 -5
  46. package/server/graphql/resolvers/daily-dispatch/delete-daily-dispatch.ts +69 -2
  47. package/server/graphql/resolvers/daily-dispatch/generate-daily-dispatch.ts +179 -141
  48. package/server/graphql/resolvers/daily-dispatch/update-daily-dispatch.ts +68 -5
  49. package/server/graphql/resolvers/daily-harvest/delete-daily-harvest.ts +9 -26
  50. package/server/graphql/resolvers/daily-harvest/generate-daily-harvest.ts +3 -3
  51. package/server/graphql/resolvers/daily-loading/delete-daily-loading.ts +11 -1
  52. package/server/graphql/resolvers/daily-loading/generate-daily-loading.ts +95 -98
  53. package/server/graphql/resolvers/daily-loading/update-daily-loading.ts +44 -47
  54. package/server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.ts +61 -26
  55. package/server/graphql/resolvers/report/daily-production-reports.ts +103 -72
  56. package/server/graphql/resolvers/report/daily-staff-harvest-reports.ts +5 -2
  57. package/server/graphql/resolvers/report/monthly-block-dispatch-reports.ts +20 -9
  58. package/server/graphql/resolvers/report/monthly-dispatch-summary-reports.ts +16 -12
  59. package/server/graphql/resolvers/report/monthly-ffb-sale-reports.ts +26 -12
  60. package/server/graphql/resolvers/report/monthly-production-reports.ts +5 -3
  61. package/server/graphql/resolvers/report/yearly-production-reports.ts +5 -2
  62. package/server/graphql/types/daily-loading-detail/daily-loading-detail-patch.ts +2 -0
  63. package/server/utils/transaction-util.ts +36 -56
  64. package/translations/en.json +1 -1
  65. package/translations/ja.json +1 -1
  66. package/translations/ko.json +1 -1
  67. package/translations/ms.json +1 -1
  68. package/translations/zh.json +1 -1
@@ -6,7 +6,7 @@ import { Ramp } from '../../../entities'
6
6
  export const monthlyFfbSaleReports = {
7
7
  async monthlyFfbSaleReports(_: any, params: ListParam, context: any) {
8
8
  try {
9
- const { domain, tx }: { domain: Domain, tx: EntityManager } = context.state
9
+ const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
10
10
 
11
11
  let year = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[0])
12
12
  let month = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[1])
@@ -32,28 +32,42 @@ export const monthlyFfbSaleReports = {
32
32
  `
33
33
  CREATE TEMP TABLE raw_block_dispatch ON COMMIT DROP AS (
34
34
  SELECT dd.*,
35
- 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 tonnage
35
+ COALESCE((SELECT SUM(COALESCE(ddd.adjusted_weight, ddd.collected_ramp_weight, 0)) FROM daily_dispatch_details ddd WHERE ddd.daily_dispatch_id = dd.id AND ddd.deleted_at is null),0) AS tonnage
36
36
  FROM daily_dispatches dd
37
37
  WHERE dd.dispatch_date::timestamp between $1::timestamp and $2::timestamp
38
38
  AND dd.deleted_at is null
39
- ${organization ? organization.value == 'null' ? `AND dd.dispatch_to_id IS NULL` : `AND dd.dispatch_to_id = '${organization.value}'` : ''}
39
+ ${
40
+ organization
41
+ ? organization.value == 'null'
42
+ ? `AND dd.dispatch_to_id IS NULL`
43
+ : `AND dd.dispatch_to_id = '${organization.value}'`
44
+ : ''
45
+ }
40
46
  );
41
- `, [fromDateString, toDateString]
47
+ `,
48
+ [fromDateString, toDateString]
42
49
  )
43
50
 
44
51
  await tx.query(
45
52
  `
46
53
  CREATE TEMP TABLE temp_monthly_dispatch_to_mill_data ON COMMIT DROP AS (
47
54
  SELECT "id", dispatch_at, transport_no AS "lorryNo",
48
- driver_identification AS "driverIdentification", chit_no AS "chitNo", round(COALESCE(percentage,0)::numeric, 2)::varchar AS "percentage",
49
- COALESCE(diapatch_to_name, 'UNKNOWN') AS "dispatchTo", round(COALESCE(tonnage,0), 2)::varchar AS "tonnage",
55
+ COALESCE(diapatch_to_name, 'UNKNOWN') AS "dispatchTo",
56
+ driver_identification AS "driverIdentification", chit_no AS "chitNo",
50
57
  CASE WHEN forward_rn = 1 THEN TO_CHAR(dispatch_at:: DATE, 'dd/mm/yyyy') ELSE '' END AS "dispatchAt",
51
- 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",
52
- 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",
53
- 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",
54
- CASE WHEN reverse_rn = 1 THEN round(coalesce(sum(tonnage) over (PARTITION BY dispatch_to_id ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0),2)::varchar ELSE '' END AS "todate"
58
+ round(COALESCE(percentage,0)::numeric, 2)::varchar AS "percentage", round(COALESCE(tonnage,0), 2)::varchar AS "tonnage",
59
+ rn, forward_rn, reverse_rn,
60
+ CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (PARTITION BY dispatch_at::date ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0))::numeric,2)::varchar ELSE '' END AS "todaytotal",
61
+ CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0))::numeric,2)::varchar ELSE '' END AS "total",
62
+ CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (PARTITION BY 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",
63
+ CASE WHEN reverse_rn = 1 THEN round((coalesce(sum(percentage) over (ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0)/rn)::numeric,2)::varchar ELSE '' END AS "todateAvg",
64
+ CASE WHEN reverse_rn = 1 THEN round(coalesce(sum(tonnage) over (PARTITION BY dispatch_at::date ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0),2)::varchar ELSE '' END AS "today",
65
+ CASE WHEN reverse_rn = 1 THEN round(coalesce(sum(tonnage) over (ORDER BY dispatch_at asc rows between unbounded preceding and current row), 0),2)::varchar ELSE '' END AS "todate"
55
66
  FROM (
56
67
  SELECT
68
+ ROW_NUMBER() OVER(
69
+ ORDER BY rbd.dispatch_at ASC
70
+ ) as rn,
57
71
  ROW_NUMBER() OVER(
58
72
  PARTITION BY rbd.dispatch_at::date
59
73
  ORDER BY rbd.dispatch_at ASC
@@ -93,13 +107,13 @@ export const monthlyFfbSaleReports = {
93
107
  `
94
108
  )
95
109
 
96
-
97
110
  return {
98
111
  items: result.map(itm => {
99
112
  return {
100
113
  ...itm
101
114
  }
102
- }), total: total[0].count
115
+ }),
116
+ total: total[0].count
103
117
  }
104
118
  } catch (error) {
105
119
  throw error
@@ -73,6 +73,7 @@ export const monthlyProductionReports = {
73
73
  inner join temp_blocks blk on blk.id = dh.block_id
74
74
  inner join daily_harvest_details dhd on dhd.daily_harvest_id = dh.id
75
75
  where dh.harvest_date::timestamp between $1::timestamp and $2::timestamp
76
+ and dhd.deleted_at is null
76
77
  group by blk.block_id
77
78
  ) as harvest on harvest.block_id = b.id
78
79
  left join(
@@ -82,6 +83,7 @@ export const monthlyProductionReports = {
82
83
  inner join daily_loading_details dld on dld.daily_loading_id = dl.id
83
84
  inner join temp_blocks blk on blk.id = dld.block_id
84
85
  where dl.loading_date::timestamp between $1::timestamp and $2::timestamp
86
+ and dld.deleted_at is null
85
87
  group by blk.block_id
86
88
  ) as loading on loading.block_id = b.id
87
89
  left join(
@@ -105,14 +107,14 @@ export const monthlyProductionReports = {
105
107
  select count(*) from temp_monthly_production_data
106
108
  `)
107
109
 
108
-
109
110
  return {
110
111
  items: result.map(itm => {
111
112
  return {
112
113
  ...itm,
113
- avgOutTurn: ((parseFloat(itm.totalOutTurn) / parseFloat(itm.daysWorked)) || 0).toFixed(4)
114
+ avgOutTurn: (parseFloat(itm.totalOutTurn) / parseFloat(itm.daysWorked) || 0).toFixed(4)
114
115
  }
115
- }), total: total[0].count
116
+ }),
117
+ total: total[0].count
116
118
  }
117
119
  } catch (error) {
118
120
  throw error
@@ -63,16 +63,18 @@ export const yearlyProductionReports = {
63
63
  select blk.block_id, sum(ramp_weight) as total_ffb
64
64
  from record_transactions t
65
65
  inner join temp_blocks blk on blk.id = t.block_id
66
- where transaction_type = 'LOADING'
66
+ where (transaction_type = 'LOADING' or transaction_type = 'LOADING_ADJUSTMENT')
67
67
  and transaction_date::timestamp between $2::timestamp and $3::timestamp
68
+ and t.deleted_at is null
68
69
  group by blk.block_id
69
70
  ) trans on trans.block_id = b.id
70
71
  left join (
71
72
  select blk.block_id, sum(ramp_weight) as total_ffb
72
73
  from record_transactions t
73
74
  inner join temp_blocks blk on blk.id = t.block_id
74
- where transaction_type = 'LOADING'
75
+ where (transaction_type = 'LOADING' or transaction_type = 'LOADING_ADJUSTMENT')
75
76
  and transaction_date::timestamp between $1::timestamp and $2::timestamp
77
+ and t.deleted_at is null
76
78
  group by blk.block_id
77
79
  ) last_trans on last_trans.block_id = b.id
78
80
  left join (
@@ -80,6 +82,7 @@ export const yearlyProductionReports = {
80
82
  from daily_harvests dh
81
83
  inner join temp_blocks blk on blk.id = dh.block_id
82
84
  where harvest_date::timestamp between $2::timestamp and $3::timestamp
85
+ and dh.deleted_at is null
83
86
  group by blk.block_id
84
87
  ) harvest on harvest.block_id = b.id
85
88
  where b.deleted_at is null
@@ -9,6 +9,8 @@ export const DailyLoadingDetailPatch = gql`
9
9
  ramp: ObjectRef
10
10
  totalBunchLoaded: Int
11
11
  totalBunchWeight: Float
12
+ prevTotalBunchLoaded: Int
13
+ prevTotalBunchWeight: Float
12
14
  remark: String
13
15
  }
14
16
  `
@@ -80,7 +80,7 @@ export async function updateTransactionHistory(
80
80
 
81
81
  await transactionRepo.update(
82
82
  { id: existingTransactionRecord.id },
83
- { fieldBunches: totalBunches, updater: user, updatedAt: new Date() }
83
+ { fieldBunches: totalBunches, transactionDate, block, updater: user, updatedAt: new Date() }
84
84
  )
85
85
  }
86
86
 
@@ -104,70 +104,50 @@ export async function generateRampBlockHistories(
104
104
  dailyDispatch?: DailyDispatch,
105
105
  trxMgr?: EntityManager
106
106
  ): Promise<RampBlockHistory> {
107
- console.log(block, domain, ramp, user)
108
107
  const rampBlockHistoryRepo: Repository<RampBlockHistory> =
109
108
  trxMgr?.getRepository(RampBlockHistory) || getRepository(RampBlockHistory)
110
109
 
111
110
  if (!ramp?.id) throw new Error(`Can't find a matching ramp.`)
112
111
 
112
+ // Fetch the last ramp block history for the given block, ramp, and domain
113
113
  const lastRampBlockHistory: RampBlockHistory = await rampBlockHistoryRepo.findOne({
114
114
  where: { domain, ramp, block },
115
- order: { seq: 'DESC' }
115
+ order: { createdAt: 'DESC' }
116
116
  })
117
117
 
118
- let res: any
119
-
120
- if (!lastRampBlockHistory) {
121
- res = await rampBlockHistoryRepo
122
- .createQueryBuilder()
123
- .insert()
124
- .into(RampBlockHistory)
125
- .values([
126
- {
127
- transactionDate,
128
- transactionType,
129
- seq: 0,
130
- domain,
131
- block,
132
- ramp,
133
- weight: rampWeight,
134
- previousWeight: 0,
135
- currentWeight: rampWeight,
136
- dailyDispatch,
137
- deletedAt: deletedAt ? deletedAt : null,
138
- creator: user,
139
- updater: user
140
- }
141
- ])
142
- .returning('*')
143
- .execute()
144
- } else {
145
- const previousWeight: number = lastRampBlockHistory.currentWeight
146
-
147
- res = await rampBlockHistoryRepo
148
- .createQueryBuilder()
149
- .insert()
150
- .into(RampBlockHistory)
151
- .values([
152
- {
153
- domain,
154
- block,
155
- ramp,
156
- transactionType,
157
- transactionDate,
158
- weight: rampWeight,
159
- previousWeight,
160
- currentWeight: parseFloat((previousWeight + rampWeight).toFixed(4)),
161
- creator: user,
162
- updater: user,
163
- seq: () =>
164
- `(select seq from ramp_block_histories where ramp_id = '${ramp.id}' and block_id = '${block.id}' and domain_id = '${domain.id}' order by seq desc limit 1) + 1`
165
- }
166
- ])
167
- .returning('*')
168
- .execute()
169
- }
170
-
118
+ // if (!lastRampBlockHistory) {
119
+ // throw new Error(
120
+ // `No opening quantity defined for block ${block.id} in ramp ${ramp.id}. Please set an opening quantity before creating dispatch records to avoid negative calculation in report.`
121
+ // )
122
+ // }
123
+
124
+ const previousWeight: number = lastRampBlockHistory.currentWeight
125
+
126
+ const res: any = await rampBlockHistoryRepo
127
+ .createQueryBuilder()
128
+ .insert()
129
+ .into(RampBlockHistory)
130
+ .values([
131
+ {
132
+ domain,
133
+ block,
134
+ ramp,
135
+ transactionType,
136
+ transactionDate,
137
+ weight: rampWeight,
138
+ previousWeight,
139
+ currentWeight: parseFloat((previousWeight + rampWeight).toFixed(4)),
140
+ dailyDispatch, // Include dailyDispatch object
141
+ creator: user,
142
+ updater: user,
143
+ seq: () =>
144
+ `(select seq from ramp_block_histories where ramp_id = '${ramp.id}' and block_id = '${block.id}' and domain_id = '${domain.id}' order by seq desc limit 1) + 1`
145
+ }
146
+ ])
147
+ .returning('*')
148
+ .execute()
149
+
150
+ // Extract the newly created ramp block history
171
151
  let newRampBlockHistory: RampBlockHistory = res.generatedMaps[0]
172
152
 
173
153
  return newRampBlockHistory
@@ -200,7 +200,7 @@
200
200
  "text.there_is_no_selected_items": "there is no selected items",
201
201
  "text.total_bunch_weight_should_be_positive": "total bunch weight should be positive",
202
202
  "text.total_bunches_loaded_should_be_positive": "total bunches loaded should be positive",
203
- "text.total_no_of_bunches_should_be_positive": "total no of bunches should be positive",
203
+ "text.total_no_of_bunches_should_be_positive_and_whole_number": "total no of bunches should be positive and whole number",
204
204
  "text.total_tonnage_harvested_should_be_positive": "total tonnage harvested should be positive",
205
205
  "text.tracked_inventory_setting": "tracked inventory setting",
206
206
  "text.truck_is_not_selected": "truck not selected",
@@ -69,7 +69,7 @@
69
69
  "text.there_is_duplicated_staff_in_record": "there is duplicated staff in this record",
70
70
  "text.total_bunch_weight_should_be_positive": "total bunch weight should be positive",
71
71
  "text.total_bunches_loaded_should_be_positive": "total bunches loaded should be positive",
72
- "text.total_no_of_bunches_should_be_positive": "total no of bunches should be positive",
72
+ "text.total_no_of_bunches_should_be_positive_and_whole_number": "total no of bunches should be positive and whole number",
73
73
  "text.total_tonnage_harvested_should_be_positive": "total tonnage harvested should be positive",
74
74
  "text.tracked_inventory_setting": "tracked inventory setting",
75
75
  "text.x_has_invalid_value": "{x} has invalid value",
@@ -69,7 +69,7 @@
69
69
  "text.there_is_duplicated_staff_in_record": "there is duplicated staff in this record",
70
70
  "text.total_bunch_weight_should_be_positive": "total bunch weight should be positive",
71
71
  "text.total_bunches_loaded_should_be_positive": "total bunches loaded should be positive",
72
- "text.total_no_of_bunches_should_be_positive": "total no of bunches should be positive",
72
+ "text.total_no_of_bunches_should_be_positive_and_whole_number": "total no of bunches should be positive and whole number",
73
73
  "text.total_tonnage_harvested_should_be_positive": "total tonnage harvested should be positive",
74
74
  "text.tracked_inventory_setting": "tracked inventory setting",
75
75
  "text.x_has_invalid_value": "{x} has invalid value",
@@ -69,7 +69,7 @@
69
69
  "text.there_is_duplicated_staff_in_record": "there is duplicated staff in this record",
70
70
  "text.total_bunch_weight_should_be_positive": "total bunch weight should be positive",
71
71
  "text.total_bunches_loaded_should_be_positive": "total bunches loaded should be positive",
72
- "text.total_no_of_bunches_should_be_positive": "total no of bunches should be positive",
72
+ "text.total_no_of_bunches_should_be_positive_and_whole_number": "total no of bunches should be positive and whole number",
73
73
  "text.total_tonnage_harvested_should_be_positive": "total tonnage harvested should be positive",
74
74
  "text.tracked_inventory_setting": "tracked inventory setting",
75
75
  "text.x_has_invalid_value": "{x} has invalid value",
@@ -69,7 +69,7 @@
69
69
  "text.there_is_duplicated_staff_in_record": "there is duplicated staff in this record",
70
70
  "text.total_bunch_weight_should_be_positive": "total bunch weight should be positive",
71
71
  "text.total_bunches_loaded_should_be_positive": "total bunches loaded should be positive",
72
- "text.total_no_of_bunches_should_be_positive": "total no of bunches should be positive",
72
+ "text.total_no_of_bunches_should_be_positive_and_whole_number": "total no of bunches should be positive and whole number",
73
73
  "text.total_tonnage_harvested_should_be_positive": "total tonnage harvested should be positive",
74
74
  "text.tracked_inventory_setting": "tracked inventory setting",
75
75
  "text.x_has_invalid_value": "{x} has invalid value",