@things-factory/operato-pms 6.1.83 → 6.1.85
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/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -34
- package/server/constants/block.ts +0 -4
- package/server/constants/index.ts +0 -8
- package/server/constants/inventory.ts +0 -9
- package/server/constants/master.ts +0 -9
- package/server/constants/organization.ts +0 -5
- package/server/constants/ramp.ts +0 -9
- package/server/constants/record.ts +0 -4
- package/server/constants/template.ts +0 -3
- package/server/constants/transaction.ts +0 -9
- package/server/controllers/index.ts +0 -1
- package/server/controllers/render-dispatchment.ts +0 -53
- package/server/entities/block-detail.ts +0 -59
- package/server/entities/block.ts +0 -49
- package/server/entities/daily-block-detail.ts +0 -54
- package/server/entities/daily-dispatch-detail.ts +0 -64
- package/server/entities/daily-dispatch.ts +0 -90
- package/server/entities/daily-harvest-detail.ts +0 -56
- package/server/entities/daily-harvest.ts +0 -89
- package/server/entities/daily-loading-detail.ts +0 -68
- package/server/entities/daily-loading-ramp.ts +0 -56
- package/server/entities/daily-loading.ts +0 -70
- package/server/entities/index.ts +0 -57
- package/server/entities/organization-staff.ts +0 -60
- package/server/entities/organization.ts +0 -43
- package/server/entities/plantation-inventory.ts +0 -56
- package/server/entities/plantation-setting.ts +0 -60
- package/server/entities/ramp.ts +0 -47
- package/server/entities/record-transaction.ts +0 -76
- package/server/entities/truck.ts +0 -58
- package/server/graphql/index.ts +0 -9
- package/server/graphql/resolvers/block/block-query.ts +0 -36
- package/server/graphql/resolvers/block/delete-blocks.ts +0 -39
- package/server/graphql/resolvers/block/index.ts +0 -11
- package/server/graphql/resolvers/block/update-multiple-block.ts +0 -69
- package/server/graphql/resolvers/block-detail/block-detail-query.ts +0 -55
- package/server/graphql/resolvers/block-detail/delete-block-details.ts +0 -20
- package/server/graphql/resolvers/block-detail/index.ts +0 -12
- package/server/graphql/resolvers/block-detail/update-multiple-block-detail.ts +0 -55
- package/server/graphql/resolvers/daily-block-detail/create-daily-block-detail.ts +0 -14
- package/server/graphql/resolvers/daily-block-detail/daily-block-detail-query.ts +0 -36
- package/server/graphql/resolvers/daily-block-detail/delete-daily-block-detail.ts +0 -14
- package/server/graphql/resolvers/daily-block-detail/delete-daily-block-details.ts +0 -17
- package/server/graphql/resolvers/daily-block-detail/index.ts +0 -18
- package/server/graphql/resolvers/daily-block-detail/update-daily-block-detail.ts +0 -17
- package/server/graphql/resolvers/daily-block-detail/update-multiple-daily-block-detail.ts +0 -44
- package/server/graphql/resolvers/daily-dispatch/daily-dispatch-query.ts +0 -48
- package/server/graphql/resolvers/daily-dispatch/delete-daily-dispatch.ts +0 -34
- package/server/graphql/resolvers/daily-dispatch/generate-daily-dispatch.ts +0 -131
- package/server/graphql/resolvers/daily-dispatch/index.ts +0 -14
- package/server/graphql/resolvers/daily-dispatch/update-daily-dispatch.ts +0 -36
- package/server/graphql/resolvers/daily-dispatch-detail/daily-dispatch-detail-query.ts +0 -37
- package/server/graphql/resolvers/daily-dispatch-detail/index.ts +0 -6
- package/server/graphql/resolvers/daily-harvest/daily-harvest-query.ts +0 -46
- package/server/graphql/resolvers/daily-harvest/delete-daily-harvest.ts +0 -65
- package/server/graphql/resolvers/daily-harvest/generate-daily-harvest.ts +0 -205
- package/server/graphql/resolvers/daily-harvest/index.ts +0 -14
- package/server/graphql/resolvers/daily-harvest/update-daily-harvest.ts +0 -153
- package/server/graphql/resolvers/daily-harvest-detail/daily-harvest-detail-query.ts +0 -35
- package/server/graphql/resolvers/daily-harvest-detail/index.ts +0 -6
- package/server/graphql/resolvers/daily-loading/daily-loading-query.ts +0 -43
- package/server/graphql/resolvers/daily-loading/delete-daily-loading.ts +0 -38
- package/server/graphql/resolvers/daily-loading/generate-daily-loading.ts +0 -149
- package/server/graphql/resolvers/daily-loading/index.ts +0 -14
- package/server/graphql/resolvers/daily-loading/update-daily-loading.ts +0 -154
- package/server/graphql/resolvers/daily-loading-detail/daily-loading-detail-query.ts +0 -35
- package/server/graphql/resolvers/daily-loading-detail/index.ts +0 -6
- package/server/graphql/resolvers/daily-loading-ramp/daily-loading-ramp-query.ts +0 -34
- package/server/graphql/resolvers/daily-loading-ramp/delete-daily-loading-ramp.ts +0 -15
- package/server/graphql/resolvers/daily-loading-ramp/index.ts +0 -12
- package/server/graphql/resolvers/daily-loading-ramp/update-daily-loading-ramp.ts +0 -18
- package/server/graphql/resolvers/dashboard/dashboard-query.ts +0 -245
- package/server/graphql/resolvers/dashboard/index.ts +0 -5
- package/server/graphql/resolvers/index.ts +0 -20
- package/server/graphql/resolvers/organization/delete-organizations.ts +0 -40
- package/server/graphql/resolvers/organization/index.ts +0 -11
- package/server/graphql/resolvers/organization/organization-query.ts +0 -35
- package/server/graphql/resolvers/organization/update-multiple-organization.ts +0 -48
- package/server/graphql/resolvers/organization-staff/delete-organization-staffs.ts +0 -20
- package/server/graphql/resolvers/organization-staff/index.ts +0 -12
- package/server/graphql/resolvers/organization-staff/organization-staff-query.ts +0 -43
- package/server/graphql/resolvers/organization-staff/update-multiple-organization-staff.ts +0 -60
- package/server/graphql/resolvers/plantation-inventory/index.ts +0 -6
- package/server/graphql/resolvers/plantation-inventory/plantation-inventory-query.ts +0 -43
- package/server/graphql/resolvers/plantation-setting/create-plantation-setting.ts +0 -16
- package/server/graphql/resolvers/plantation-setting/delete-plantation-setting.ts +0 -13
- package/server/graphql/resolvers/plantation-setting/delete-plantation-settings.ts +0 -18
- package/server/graphql/resolvers/plantation-setting/index.ts +0 -19
- package/server/graphql/resolvers/plantation-setting/plantation-setting-query.ts +0 -38
- package/server/graphql/resolvers/plantation-setting/update-multiple-plantation-setting.ts +0 -46
- package/server/graphql/resolvers/plantation-setting/update-plantation-setting.ts +0 -20
- package/server/graphql/resolvers/ramp/delete-ramps.ts +0 -24
- package/server/graphql/resolvers/ramp/index.ts +0 -12
- package/server/graphql/resolvers/ramp/ramp-query.ts +0 -34
- package/server/graphql/resolvers/ramp/update-multiple-ramp.ts +0 -61
- package/server/graphql/resolvers/record-transaction/index.ts +0 -6
- package/server/graphql/resolvers/record-transaction/record-transaction-query.ts +0 -34
- package/server/graphql/resolvers/report/daily-ffb-dispatch-production-reports.ts +0 -149
- package/server/graphql/resolvers/report/daily-production-reports.ts +0 -167
- package/server/graphql/resolvers/report/daily-staff-harvest-reports.ts +0 -84
- package/server/graphql/resolvers/report/index.ts +0 -22
- package/server/graphql/resolvers/report/monthly-block-dispatch-reports.ts +0 -122
- package/server/graphql/resolvers/report/monthly-dispatch-summary-reports.ts +0 -114
- package/server/graphql/resolvers/report/monthly-ffb-sale-reports.ts +0 -111
- package/server/graphql/resolvers/report/monthly-production-reports.ts +0 -117
- package/server/graphql/resolvers/report/yearly-production-reports.ts +0 -101
- package/server/graphql/resolvers/truck/delete-trucks.ts +0 -21
- package/server/graphql/resolvers/truck/index.ts +0 -12
- package/server/graphql/resolvers/truck/truck-query.ts +0 -50
- package/server/graphql/resolvers/truck/update-multiple-truck.ts +0 -55
- package/server/graphql/types/block/block-list.ts +0 -8
- package/server/graphql/types/block/block-patch.ts +0 -13
- package/server/graphql/types/block/block.ts +0 -18
- package/server/graphql/types/block/index.ts +0 -18
- package/server/graphql/types/block/new-block.ts +0 -8
- package/server/graphql/types/block-detail/block-detail-list.ts +0 -8
- package/server/graphql/types/block-detail/block-detail-patch.ts +0 -16
- package/server/graphql/types/block-detail/block-detail.ts +0 -21
- package/server/graphql/types/block-detail/index.ts +0 -18
- package/server/graphql/types/block-detail/new-block-detail.ts +0 -13
- package/server/graphql/types/daily-block-detail/daily-block-detail-list.ts +0 -8
- package/server/graphql/types/daily-block-detail/daily-block-detail-patch.ts +0 -10
- package/server/graphql/types/daily-block-detail/daily-block-detail.ts +0 -18
- package/server/graphql/types/daily-block-detail/index.ts +0 -21
- package/server/graphql/types/daily-block-detail/new-daily-block-detail.ts +0 -8
- package/server/graphql/types/daily-dispatch/daily-dispatch-list.ts +0 -8
- package/server/graphql/types/daily-dispatch/daily-dispatch-patch.ts +0 -22
- package/server/graphql/types/daily-dispatch/daily-dispatch.ts +0 -27
- package/server/graphql/types/daily-dispatch/index.ts +0 -24
- package/server/graphql/types/daily-dispatch/new-daily-dispatch.ts +0 -20
- package/server/graphql/types/daily-dispatch-detail/daily-dispatch-detail-list.ts +0 -8
- package/server/graphql/types/daily-dispatch-detail/daily-dispatch-detail-patch.ts +0 -16
- package/server/graphql/types/daily-dispatch-detail/daily-dispatch-detail.ts +0 -21
- package/server/graphql/types/daily-dispatch-detail/index.ts +0 -14
- package/server/graphql/types/daily-dispatch-detail/new-daily-dispatch-detail.ts +0 -12
- package/server/graphql/types/daily-harvest/daily-harvest-list.ts +0 -8
- package/server/graphql/types/daily-harvest/daily-harvest-patch.ts +0 -17
- package/server/graphql/types/daily-harvest/daily-harvest.ts +0 -27
- package/server/graphql/types/daily-harvest/index.ts +0 -19
- package/server/graphql/types/daily-harvest/new-daily-harvest.ts +0 -15
- package/server/graphql/types/daily-harvest-detail/daily-harvest-detail-list.ts +0 -8
- package/server/graphql/types/daily-harvest-detail/daily-harvest-detail-patch.ts +0 -11
- package/server/graphql/types/daily-harvest-detail/daily-harvest-detail.ts +0 -20
- package/server/graphql/types/daily-harvest-detail/index.ts +0 -14
- package/server/graphql/types/daily-harvest-detail/new-daily-harvest-detail.ts +0 -10
- package/server/graphql/types/daily-loading/daily-loading-list.ts +0 -8
- package/server/graphql/types/daily-loading/daily-loading-patch.ts +0 -8
- package/server/graphql/types/daily-loading/daily-loading.ts +0 -21
- package/server/graphql/types/daily-loading/index.ts +0 -19
- package/server/graphql/types/daily-loading/new-daily-loading.ts +0 -8
- package/server/graphql/types/daily-loading-detail/daily-loading-detail-list.ts +0 -8
- package/server/graphql/types/daily-loading-detail/daily-loading-detail-patch.ts +0 -14
- package/server/graphql/types/daily-loading-detail/daily-loading-detail.ts +0 -23
- package/server/graphql/types/daily-loading-detail/index.ts +0 -14
- package/server/graphql/types/daily-loading-detail/new-daily-loading-detail.ts +0 -13
- package/server/graphql/types/daily-loading-ramp/daily-loading-ramp-list.ts +0 -8
- package/server/graphql/types/daily-loading-ramp/daily-loading-ramp-patch.ts +0 -13
- package/server/graphql/types/daily-loading-ramp/daily-loading-ramp.ts +0 -17
- package/server/graphql/types/daily-loading-ramp/index.ts +0 -18
- package/server/graphql/types/daily-loading-ramp/new-daily-loading-ramp.ts +0 -11
- package/server/graphql/types/dashboard/bunches-count.ts +0 -9
- package/server/graphql/types/dashboard/index.ts +0 -17
- package/server/graphql/types/dashboard/productions-overview.ts +0 -9
- package/server/graphql/types/dashboard/tonnage-bunches-inventories.ts +0 -8
- package/server/graphql/types/dashboard/tonnage-production.ts +0 -11
- package/server/graphql/types/dashboard/yield-production.ts +0 -11
- package/server/graphql/types/index.ts +0 -20
- package/server/graphql/types/organization/index.ts +0 -18
- package/server/graphql/types/organization/new-organization.ts +0 -9
- package/server/graphql/types/organization/organization-list.ts +0 -8
- package/server/graphql/types/organization/organization-patch.ts +0 -11
- package/server/graphql/types/organization/organization.ts +0 -16
- package/server/graphql/types/organization-staff/index.ts +0 -19
- package/server/graphql/types/organization-staff/new-organization-staff.ts +0 -8
- package/server/graphql/types/organization-staff/organization-staff-list.ts +0 -8
- package/server/graphql/types/organization-staff/organization-staff-patch.ts +0 -15
- package/server/graphql/types/organization-staff/organization-staff.ts +0 -21
- package/server/graphql/types/plantation-inventory/index.ts +0 -14
- package/server/graphql/types/plantation-inventory/new-plantation-inventory.ts +0 -8
- package/server/graphql/types/plantation-inventory/plantation-inventory-list.ts +0 -8
- package/server/graphql/types/plantation-inventory/plantation-inventory-patch.ts +0 -10
- package/server/graphql/types/plantation-inventory/plantation-inventory.ts +0 -22
- package/server/graphql/types/plantation-setting/index.ts +0 -21
- package/server/graphql/types/plantation-setting/new-plantation-setting.ts +0 -10
- package/server/graphql/types/plantation-setting/plantation-setting-list.ts +0 -8
- package/server/graphql/types/plantation-setting/plantation-setting-patch.ts +0 -12
- package/server/graphql/types/plantation-setting/plantation-setting.ts +0 -16
- package/server/graphql/types/ramp/index.ts +0 -18
- package/server/graphql/types/ramp/new-ramp.ts +0 -8
- package/server/graphql/types/ramp/ramp-list.ts +0 -8
- package/server/graphql/types/ramp/ramp-patch.ts +0 -12
- package/server/graphql/types/ramp/ramp.ts +0 -17
- package/server/graphql/types/record-transaction/index.ts +0 -14
- package/server/graphql/types/record-transaction/new-record-transaction.ts +0 -8
- package/server/graphql/types/record-transaction/record-transaction-list.ts +0 -8
- package/server/graphql/types/record-transaction/record-transaction-patch.ts +0 -10
- package/server/graphql/types/record-transaction/record-transaction.ts +0 -24
- package/server/graphql/types/report/daily-ffb-dispatch-production-report-list.ts +0 -8
- package/server/graphql/types/report/daily-ffb-dispatch-production-report.ts +0 -9
- package/server/graphql/types/report/daily-production-report-list.ts +0 -8
- package/server/graphql/types/report/daily-production-report.ts +0 -23
- package/server/graphql/types/report/daily-staff-harvest-report-list.ts +0 -8
- package/server/graphql/types/report/daily-staff-harvest-report.ts +0 -10
- package/server/graphql/types/report/index.ts +0 -62
- package/server/graphql/types/report/monthly-block-dispatch-report-list.ts +0 -7
- package/server/graphql/types/report/monthly-block-dispatch-report.ts +0 -13
- package/server/graphql/types/report/monthly-dispatch-summary-report-list.ts +0 -7
- package/server/graphql/types/report/monthly-dispatch-summary-report.ts +0 -19
- package/server/graphql/types/report/monthly-ffb-sale-report-list.ts +0 -7
- package/server/graphql/types/report/monthly-ffb-sale-report.ts +0 -18
- package/server/graphql/types/report/monthly-production-report-list.ts +0 -8
- package/server/graphql/types/report/monthly-production-report.ts +0 -25
- package/server/graphql/types/report/yearly-production-report-list.ts +0 -8
- package/server/graphql/types/report/yearly-production-report.ts +0 -18
- package/server/graphql/types/truck/index.ts +0 -18
- package/server/graphql/types/truck/new-truck.ts +0 -8
- package/server/graphql/types/truck/truck-list.ts +0 -8
- package/server/graphql/types/truck/truck-patch.ts +0 -11
- package/server/graphql/types/truck/truck.ts +0 -16
- package/server/index.ts +0 -6
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -7
- package/server/utils/core-values.ts +0 -98
- package/server/utils/datetime-util.ts +0 -39
- package/server/utils/index.ts +0 -4
- package/server/utils/no-generator.ts +0 -64
- package/server/utils/transaction-util.ts +0 -101
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PlantationSetting } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const deletePlantationSetting = {
|
|
6
|
-
async deletePlantationSetting(_: any, { name }, context: ResolverContext) {
|
|
7
|
-
const { domain, user } = context.state
|
|
8
|
-
|
|
9
|
-
await getRepository(PlantationSetting).delete({ domain, name })
|
|
10
|
-
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { In } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { getRepository } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { PlantationSetting } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const deletePlantationSettings = {
|
|
8
|
-
async deletePlantationSettings(_: any, { names }, context: ResolverContext) {
|
|
9
|
-
const { domain, user } = context.state
|
|
10
|
-
|
|
11
|
-
await getRepository(PlantationSetting).delete({
|
|
12
|
-
domain,
|
|
13
|
-
name: In(names)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Query, PlantationSetting } from './plantation-setting-query'
|
|
2
|
-
|
|
3
|
-
import { updatePlantationSetting } from './update-plantation-setting'
|
|
4
|
-
import { updateMultiplePlantationSetting } from './update-multiple-plantation-setting'
|
|
5
|
-
import { createPlantationSetting } from './create-plantation-setting'
|
|
6
|
-
import { deletePlantationSetting } from './delete-plantation-setting'
|
|
7
|
-
import { deletePlantationSettings } from './delete-plantation-settings'
|
|
8
|
-
|
|
9
|
-
export const PlantationSettingResolver = {
|
|
10
|
-
PlantationSetting,
|
|
11
|
-
Query,
|
|
12
|
-
Mutation: {
|
|
13
|
-
...updatePlantationSetting,
|
|
14
|
-
...updateMultiplePlantationSetting,
|
|
15
|
-
...createPlantationSetting,
|
|
16
|
-
...deletePlantationSetting,
|
|
17
|
-
...deletePlantationSettings
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { User } from '@things-factory/auth-base'
|
|
2
|
-
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
-
|
|
4
|
-
import { PlantationSetting as PlantationSettingEntity } from '../../../entities'
|
|
5
|
-
|
|
6
|
-
export const Query = {
|
|
7
|
-
async plantationSetting(_: any, { name }, context: ResolverContext) {
|
|
8
|
-
const { domain, user } = context.state
|
|
9
|
-
const repository = getRepository(PlantationSettingEntity)
|
|
10
|
-
|
|
11
|
-
return await repository.findOne({
|
|
12
|
-
where: { domain: { id: domain.id }, name }
|
|
13
|
-
})
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
async plantationSettings(_: any, params: ListParam, context: ResolverContext) {
|
|
17
|
-
const convertedParams = convertListParams(params)
|
|
18
|
-
const [items, total] = await getRepository(PlantationSettingEntity).findAndCount({
|
|
19
|
-
...convertedParams
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
return { items, total }
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const PlantationSetting = {
|
|
27
|
-
async domain(plantationSetting) {
|
|
28
|
-
return await getRepository(Domain).findOneBy({ id: plantationSetting.domainId })
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
async creator(plantationSetting) {
|
|
32
|
-
return await getRepository(User).findOneBy({ id: plantationSetting.creatorId })
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
async updater(plantationSetting) {
|
|
36
|
-
return await getRepository(User).findOneBy({ id: plantationSetting.updaterId })
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PlantationSetting } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const updateMultiplePlantationSetting = {
|
|
6
|
-
async updateMultiplePlantationSetting(_: any, { patches }, context: ResolverContext) {
|
|
7
|
-
const { domain, user } = context.state
|
|
8
|
-
|
|
9
|
-
let results = []
|
|
10
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
11
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
12
|
-
const plantationSettingRepo = getRepository(PlantationSetting)
|
|
13
|
-
|
|
14
|
-
if (_createRecords.length > 0) {
|
|
15
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
16
|
-
const newRecord = _createRecords[i]
|
|
17
|
-
|
|
18
|
-
const result = await plantationSettingRepo.save({
|
|
19
|
-
...newRecord,
|
|
20
|
-
domain: domain,
|
|
21
|
-
creator: user,
|
|
22
|
-
updater: user
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
results.push({ ...result, cuFlag: '+' })
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (_updateRecords.length > 0) {
|
|
30
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
31
|
-
const newRecord = _updateRecords[i]
|
|
32
|
-
const plantationSetting = await plantationSettingRepo.findOneBy({ domain: { id: domain.id }, id: newRecord.id })
|
|
33
|
-
|
|
34
|
-
const result = await plantationSettingRepo.save({
|
|
35
|
-
...plantationSetting,
|
|
36
|
-
...newRecord,
|
|
37
|
-
updater: user
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return results
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PlantationSetting } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const updatePlantationSetting = {
|
|
6
|
-
async updatePlantationSetting(_: any, { name, patch }, context: ResolverContext) {
|
|
7
|
-
const { domain, user } = context.state
|
|
8
|
-
|
|
9
|
-
const repository = getRepository(PlantationSetting)
|
|
10
|
-
const plantationSetting = await repository.findOne({
|
|
11
|
-
where: { domain: { id: domain.id }, name }
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
return await repository.save({
|
|
15
|
-
...plantationSetting,
|
|
16
|
-
...patch,
|
|
17
|
-
updater: user
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { In } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Ramp } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const deleteRamps = {
|
|
6
|
-
async deleteRamps(_: any, { ids }, context: ResolverContext) {
|
|
7
|
-
try {
|
|
8
|
-
const { tx, domain } = context.state
|
|
9
|
-
|
|
10
|
-
await tx.getRepository(Ramp).update(
|
|
11
|
-
{
|
|
12
|
-
domain: { id: domain.id },
|
|
13
|
-
id: In(ids)
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
deletedAt: new Date()
|
|
17
|
-
}
|
|
18
|
-
)
|
|
19
|
-
return true
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw error
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Query } from './ramp-query'
|
|
2
|
-
|
|
3
|
-
import { updateMultipleRampResolver } from './update-multiple-ramp'
|
|
4
|
-
import { deleteRamps } from './delete-ramps'
|
|
5
|
-
|
|
6
|
-
export const RampResolver = {
|
|
7
|
-
Query,
|
|
8
|
-
Mutation: {
|
|
9
|
-
...updateMultipleRampResolver,
|
|
10
|
-
...deleteRamps
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { buildQuery, ListParam } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { Ramp as RampEntity } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const Query = {
|
|
6
|
-
async ramp(_: any, { name }, context: ResolverContext) {
|
|
7
|
-
const { tx, domain } = context.state
|
|
8
|
-
|
|
9
|
-
return await tx.getRepository(RampEntity).findOne({
|
|
10
|
-
where: { domain: { id: domain.id }, name },
|
|
11
|
-
relations: ['domain', 'block', 'creator', 'updater']
|
|
12
|
-
})
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
async ramps(_: any, params: ListParam, context: ResolverContext) {
|
|
16
|
-
const { tx } = context.state
|
|
17
|
-
|
|
18
|
-
const queryBuilder = tx.getRepository(RampEntity).createQueryBuilder()
|
|
19
|
-
buildQuery(queryBuilder, params, context)
|
|
20
|
-
|
|
21
|
-
queryBuilder
|
|
22
|
-
.leftJoinAndSelect('Ramp.domain', 'Domain')
|
|
23
|
-
.leftJoinAndSelect('Ramp.block', 'Block')
|
|
24
|
-
.leftJoinAndSelect('Ramp.creator', 'Creator')
|
|
25
|
-
.leftJoinAndSelect('Ramp.updater', 'Updater')
|
|
26
|
-
|
|
27
|
-
if (params.filters?.length > 0) queryBuilder.andWhere('Ramp.deletedAt IS NULL')
|
|
28
|
-
else queryBuilder.where('Ramp.deletedAt IS NULL')
|
|
29
|
-
|
|
30
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
31
|
-
|
|
32
|
-
return { items, total }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { RAMP_STATUS } from '../../../constants'
|
|
2
|
-
import { Block, Ramp } from '../../../entities'
|
|
3
|
-
|
|
4
|
-
export const updateMultipleRampResolver = {
|
|
5
|
-
updateMultipleRamp
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function updateMultipleRamp(_: any, { patches }, context: ResolverContext) {
|
|
9
|
-
const { tx, domain, user } = context.state
|
|
10
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
11
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
12
|
-
const rampRepo = tx.getRepository(Ramp)
|
|
13
|
-
const blockRepo = tx.getRepository(Block)
|
|
14
|
-
|
|
15
|
-
let results = []
|
|
16
|
-
|
|
17
|
-
if (_createRecords.length > 0) {
|
|
18
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
19
|
-
const newRecord = _createRecords[i]
|
|
20
|
-
|
|
21
|
-
const block = await blockRepo.findOneOrFail({
|
|
22
|
-
where: { id: newRecord?.block?.id }
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const result = await rampRepo.save({
|
|
26
|
-
...newRecord,
|
|
27
|
-
block,
|
|
28
|
-
domain,
|
|
29
|
-
status: RAMP_STATUS.EMPTY,
|
|
30
|
-
creator: user,
|
|
31
|
-
updater: user
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
results.push({ ...result, cuFlag: '+' })
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (_updateRecords.length > 0) {
|
|
39
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
40
|
-
let newRecord = _updateRecords[i]
|
|
41
|
-
const ramp = await rampRepo.findOneBy({ id: newRecord.id })
|
|
42
|
-
|
|
43
|
-
if (newRecord?.block?.id) {
|
|
44
|
-
const block = await blockRepo.findOneOrFail({
|
|
45
|
-
where: { id: newRecord?.block?.id }
|
|
46
|
-
})
|
|
47
|
-
newRecord = { ...newRecord, block }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const result = await rampRepo.save({
|
|
51
|
-
...ramp,
|
|
52
|
-
...newRecord,
|
|
53
|
-
updater: user
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return results
|
|
61
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { buildQuery, ListParam } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { RecordTransaction as RecordTransactionEntity } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const Query = {
|
|
6
|
-
async recordTransaction(_: any, { name }, context: ResolverContext) {
|
|
7
|
-
const { tx, domain } = context.state
|
|
8
|
-
|
|
9
|
-
return await tx.getRepository(RecordTransactionEntity).findOne({
|
|
10
|
-
where: { domain: { id: domain.id }, name },
|
|
11
|
-
relations: ['domain', 'plantationInventory', 'block', 'creator', 'updater']
|
|
12
|
-
})
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
async recordTransactions(_: any, params: ListParam, context: ResolverContext) {
|
|
16
|
-
const { tx } = context.state
|
|
17
|
-
|
|
18
|
-
const queryBuilder = tx.getRepository(RecordTransactionEntity).createQueryBuilder()
|
|
19
|
-
buildQuery(queryBuilder, params, context)
|
|
20
|
-
|
|
21
|
-
queryBuilder
|
|
22
|
-
.leftJoinAndSelect('RecordTransaction.domain', 'Domain')
|
|
23
|
-
.leftJoinAndSelect('RecordTransaction.plantationInventory', 'PlantationInventory')
|
|
24
|
-
.leftJoinAndSelect('RecordTransaction.block', 'Block')
|
|
25
|
-
.leftJoinAndSelect('RecordTransaction.creator', 'Creator')
|
|
26
|
-
.leftJoinAndSelect('RecordTransaction.updater', 'Updater')
|
|
27
|
-
.orderBy('RecordTransaction.transactionDate', 'ASC')
|
|
28
|
-
.addOrderBy('RecordTransaction.createdAt', 'ASC')
|
|
29
|
-
|
|
30
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
31
|
-
|
|
32
|
-
return { items, total }
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { IsNull } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { getRepository, ListParam } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { Block, Organization, Ramp } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const dailyFfbDispatchProductionReports = {
|
|
8
|
-
async dailyFfbDispatchProductionReports(_: any, params: ListParam, context: ResolverContext) {
|
|
9
|
-
try {
|
|
10
|
-
const { domain, tx } = context.state
|
|
11
|
-
|
|
12
|
-
let year = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[0])
|
|
13
|
-
let month = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[1])
|
|
14
|
-
|
|
15
|
-
let fromDate = new Date(year, month - 1, 1)
|
|
16
|
-
let toDate = new Date(year, month, 1)
|
|
17
|
-
toDate.setDate(toDate.getDate() - 1)
|
|
18
|
-
|
|
19
|
-
let fromDateString = [
|
|
20
|
-
fromDate.getFullYear().toString(),
|
|
21
|
-
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
22
|
-
'01'
|
|
23
|
-
].join('-')
|
|
24
|
-
|
|
25
|
-
let toDateString = [
|
|
26
|
-
toDate.getFullYear().toString(),
|
|
27
|
-
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
28
|
-
String(toDate.getDate()).padStart(2, '0')
|
|
29
|
-
].join('-')
|
|
30
|
-
|
|
31
|
-
let ramps = await getRepository(Ramp).find({
|
|
32
|
-
where: { domain: { id: domain.id }, deletedAt: IsNull() },
|
|
33
|
-
relations: ['block']
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
let organizations = await getRepository(Organization).find({
|
|
37
|
-
where: { domain: { id: domain.id }, deletedAt: IsNull() }
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
let blocks = await tx.getRepository(Block).query(
|
|
41
|
-
`
|
|
42
|
-
SELECT b.id, b.name FROM ramps r
|
|
43
|
-
INNER JOIN blocks b ON b.id = r.block_id
|
|
44
|
-
WHERE b.deleted_at IS NULL
|
|
45
|
-
AND r.domain_id = $1
|
|
46
|
-
GROUP BY b.id, b.name
|
|
47
|
-
`,
|
|
48
|
-
[domain.id]
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
// -- WHERE dd.dispatch_at::timestamp between $1::timestamp and $2::timestamp
|
|
52
|
-
// [fromDateString, toDateString]
|
|
53
|
-
await tx.query(`create extension if not exists tablefunc`)
|
|
54
|
-
|
|
55
|
-
await tx.query(
|
|
56
|
-
`
|
|
57
|
-
CREATE TEMP TABLE raw_block_dispatch ON COMMIT DROP AS (
|
|
58
|
-
SELECT "name", "dispatch_at", sum(weight) AS weight FROM(
|
|
59
|
-
SELECT * FROM (
|
|
60
|
-
SELECT dd.id,COALESCE(b.name, 'unknown') AS name, 1 AS "rank", dd.dispatch_at::date AS dispatch_at,
|
|
61
|
-
COALESCE(ddd.adjusted_weight, ddd.collected_ramp_weight, 0) AS weight
|
|
62
|
-
FROM daily_dispatches dd
|
|
63
|
-
INNER JOIN daily_dispatch_details ddd ON ddd.daily_dispatch_id = dd.id
|
|
64
|
-
INNER JOIN ramps r ON r.id = ddd.ramp_id
|
|
65
|
-
INNER JOIN blocks b ON b.id = r.block_id
|
|
66
|
-
WHERE dd.dispatch_at::date between $1 and $2
|
|
67
|
-
UNION
|
|
68
|
-
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,
|
|
69
|
-
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
|
|
70
|
-
FROM daily_dispatches dd
|
|
71
|
-
LEFT JOIN organizations c ON c.id = dd.dispatch_to_id
|
|
72
|
-
WHERE dd.dispatch_at::date between $1 and $2
|
|
73
|
-
) foo
|
|
74
|
-
ORDER BY "rank", "name", "dispatch_at"
|
|
75
|
-
) foo
|
|
76
|
-
GROUP BY "name", "dispatch_at"
|
|
77
|
-
ORDER BY name, "dispatch_at"
|
|
78
|
-
)
|
|
79
|
-
`,
|
|
80
|
-
[fromDateString, toDateString]
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
await tx.query(
|
|
84
|
-
`
|
|
85
|
-
CREATE TEMP TABLE pivot_block_dispatch ON COMMIT DROP AS (
|
|
86
|
-
SELECT * FROM crosstab(
|
|
87
|
-
$$
|
|
88
|
-
SELECT rbd."dispatch_at", rbd."name",
|
|
89
|
-
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
|
|
90
|
-
FROM raw_block_dispatch rbd
|
|
91
|
-
ORDER BY rbd."dispatch_at", rbd."name"
|
|
92
|
-
$$,
|
|
93
|
-
$$
|
|
94
|
-
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 = '${
|
|
95
|
-
domain.id
|
|
96
|
-
}'
|
|
97
|
-
GROUP BY b.id, b.name
|
|
98
|
-
UNION
|
|
99
|
-
SELECT c.name FROM organizations c
|
|
100
|
-
$$
|
|
101
|
-
) AS (dispatch_at date, ${[
|
|
102
|
-
...blocks.map(block => `"${block.name}" varchar`),
|
|
103
|
-
...organizations.map(organization => `"${organization.name}" varchar`)
|
|
104
|
-
].join(',')},"unknown" varchar)
|
|
105
|
-
);
|
|
106
|
-
`
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
await tx.query(
|
|
110
|
-
`
|
|
111
|
-
CREATE TEMP TABLE temp_monthly_production_data ON COMMIT DROP AS (
|
|
112
|
-
SELECT TO_CHAR(md.dateDay:: DATE, 'dd/mm/yyyy') as "date"
|
|
113
|
-
, row_to_json((SELECT d FROM (SELECT ${[
|
|
114
|
-
...blocks.map(block => `pbd."${block.name}"`),
|
|
115
|
-
...organizations.map(organization => `pbd."${organization.name}"`)
|
|
116
|
-
].join(',')}, pbd."unknown") d))::varchar as "blockData"
|
|
117
|
-
, (SELECT sum(weight) FROM raw_block_dispatch rbd WHERE rbd.dispatch_at = pbd.dispatch_at) AS "today"
|
|
118
|
-
FROM (select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
119
|
-
LEFT JOIN pivot_block_dispatch pbd on pbd.dispatch_at::date = md.dateDay
|
|
120
|
-
);
|
|
121
|
-
`
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
const result: any = await tx.query(
|
|
125
|
-
`
|
|
126
|
-
select "date", "blockData", "today"
|
|
127
|
-
from temp_monthly_production_data dt
|
|
128
|
-
`
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
const total: any = await tx.query(
|
|
132
|
-
`
|
|
133
|
-
select count(*) from temp_monthly_production_data
|
|
134
|
-
`
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
items: result.map(itm => {
|
|
139
|
-
return {
|
|
140
|
-
...itm
|
|
141
|
-
}
|
|
142
|
-
}),
|
|
143
|
-
total: total[0].count
|
|
144
|
-
}
|
|
145
|
-
} catch (error) {
|
|
146
|
-
throw error
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { EntityManager } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { ListParam } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { Block } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const dailyProductionReports = {
|
|
8
|
-
async dailyProductionReports(_: any, params: ListParam, context: ResolverContext) {
|
|
9
|
-
try {
|
|
10
|
-
const { tx } = context.state
|
|
11
|
-
|
|
12
|
-
let year = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[0])
|
|
13
|
-
let month = parseInt(params.filters.filter(x => x.name == 'month')[0].value.split('-')[1])
|
|
14
|
-
|
|
15
|
-
let fromDate = new Date(year, month - 1, 1)
|
|
16
|
-
let toDate = new Date(year, month, 1)
|
|
17
|
-
toDate.setDate(toDate.getDate() - 1)
|
|
18
|
-
|
|
19
|
-
let fromDateString = [
|
|
20
|
-
fromDate.getFullYear().toString(),
|
|
21
|
-
String(fromDate.getMonth() + 1).padStart(2, '0'),
|
|
22
|
-
'01'
|
|
23
|
-
].join('-')
|
|
24
|
-
|
|
25
|
-
let toDateString = [
|
|
26
|
-
toDate.getFullYear().toString(),
|
|
27
|
-
String(toDate.getMonth() + 1).padStart(2, '0'),
|
|
28
|
-
String(toDate.getDate()).padStart(2, '0')
|
|
29
|
-
].join('-')
|
|
30
|
-
|
|
31
|
-
const block = await tx
|
|
32
|
-
.getRepository(Block)
|
|
33
|
-
.findOneOrFail({ where: { id: params.filters.filter(x => x.name == 'block')[0].value } })
|
|
34
|
-
|
|
35
|
-
await tx.query(
|
|
36
|
-
`
|
|
37
|
-
CREATE TEMP TABLE temp_blocks on commit drop AS (
|
|
38
|
-
WITH RECURSIVE b AS (
|
|
39
|
-
SELECT $1::uuid as block_id, * FROM blocks b
|
|
40
|
-
WHERE id = $1::uuid
|
|
41
|
-
AND b.deleted_at IS null
|
|
42
|
-
UNION ALL
|
|
43
|
-
SELECT $1::uuid as block_id, cb.* FROM blocks cb
|
|
44
|
-
INNER JOIN b ON b.id = cb.parent_block_id
|
|
45
|
-
WHERE cb.deleted_at IS null
|
|
46
|
-
)
|
|
47
|
-
SELECT * FROM b
|
|
48
|
-
);
|
|
49
|
-
`,
|
|
50
|
-
[block.id]
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
await tx.query(
|
|
54
|
-
`
|
|
55
|
-
CREATE TEMP TABLE temp_records on commit drop AS (
|
|
56
|
-
select blk.block_id, coalesce(sum(field_bunches),0) AS today_field_bunches,
|
|
57
|
-
round(coalesce(sum(ramp_weight),0)::numeric,4) AS today_ramp_weight,
|
|
58
|
-
sum(case when transaction_type = 'HARVEST' OR transaction_type = 'BUNCHES_ADJUSTMENT' then field_bunches else 0 end) as today_bunch_harvest,
|
|
59
|
-
sum(case when transaction_type = 'LOADING' OR transaction_type = 'LOADING_ADJUSTMENT' then -field_bunches else 0 end) as today_bunch_collected,
|
|
60
|
-
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,
|
|
61
|
-
round(sum(case when transaction_type = 'DISPATCHMENT' OR transaction_type = 'DISPATCHMENT_ADJUSTMENT' then -ramp_weight else 0 end)::numeric,4) as today_weight_dispatch,
|
|
62
|
-
transaction_date
|
|
63
|
-
from record_transactions t2
|
|
64
|
-
inner join temp_blocks blk on blk.id = t2.block_id
|
|
65
|
-
where transaction_date <= $1
|
|
66
|
-
group by blk.block_id, transaction_date
|
|
67
|
-
)
|
|
68
|
-
`,
|
|
69
|
-
[toDateString]
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
await tx.query(
|
|
73
|
-
`
|
|
74
|
-
create temp table temp_daily_production_data on commit drop as (
|
|
75
|
-
select *,
|
|
76
|
-
prev_bunch_bal_in_field + today_bunch_harvest as today_bunch_in_field,
|
|
77
|
-
prev_bunch_bal_in_field + today_bunch_harvest - today_bunch_collected as today_bunch_bal_in_field,
|
|
78
|
-
prev_weight_bal_in_ramp + today_ramp_weight_collected - today_weight_dispatch as today_weight_bal_in_ramp FROM (
|
|
79
|
-
select extract(day from md.dateDay) as date_day,
|
|
80
|
-
coalesce(
|
|
81
|
-
(
|
|
82
|
-
select sum(today_field_bunches) from temp_records t2
|
|
83
|
-
where transaction_date::timestamp < md.dateDay
|
|
84
|
-
)
|
|
85
|
-
, 0) as prev_bunch_bal_in_field,
|
|
86
|
-
coalesce(
|
|
87
|
-
(
|
|
88
|
-
select sum(today_ramp_weight) from temp_records t2
|
|
89
|
-
where transaction_date::timestamp < md.dateDay
|
|
90
|
-
)
|
|
91
|
-
, 0) as prev_weight_bal_in_ramp,
|
|
92
|
-
coalesce(today_bunch_harvest, 0) as today_bunch_harvest,
|
|
93
|
-
coalesce(sum(today_bunch_harvest) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_harvest,
|
|
94
|
-
coalesce(today_bunch_collected, 0) as today_bunch_collected,
|
|
95
|
-
coalesce(sum(today_bunch_collected) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_bunch_collected,
|
|
96
|
-
coalesce(today_ramp_weight_collected, 0) as today_ramp_weight_collected,
|
|
97
|
-
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,
|
|
98
|
-
coalesce(today_weight_dispatch, 0) as today_weight_dispatch,
|
|
99
|
-
coalesce(sum(today_weight_dispatch) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_weight_dispatch,
|
|
100
|
-
coalesce(tot.today_out_turn, 0) as today_out_turn,
|
|
101
|
-
coalesce(sum(tot.today_out_turn) over (order by dateDay asc rows between unbounded preceding and current row), 0) as to_date_out_turn,
|
|
102
|
-
(select name from blocks b2 where id = $3) as block,
|
|
103
|
-
coalesce(thr.today_harvesting_round, 0) as today_harvesting_round,
|
|
104
|
-
coalesce(thr.today_hectare_cover, 0) as today_hectare_cover
|
|
105
|
-
from
|
|
106
|
-
(select generate_series((date '${fromDateString}')::timestamp, (date '${toDateString}')::timestamp, interval '1 day')::date as dateDay) as md
|
|
107
|
-
left join (
|
|
108
|
-
select * from temp_records trx
|
|
109
|
-
where transaction_date between $1 and $2
|
|
110
|
-
order by transaction_date
|
|
111
|
-
) as dt on dt.transaction_date::date = md.dateDay
|
|
112
|
-
LEFT JOIN (
|
|
113
|
-
select sum(harvesting_round) AS today_harvesting_round, sum(coverage) AS today_hectare_cover, harvest_date
|
|
114
|
-
from daily_harvests dh
|
|
115
|
-
inner join temp_blocks blk on blk.id = dh.block_id
|
|
116
|
-
where harvest_date between $1 and $2
|
|
117
|
-
group by blk.block_id, harvest_date
|
|
118
|
-
) as thr ON thr.harvest_date::date = md.dateDay
|
|
119
|
-
LEFT JOIN (
|
|
120
|
-
select count(*) AS today_out_turn, dh.harvest_date
|
|
121
|
-
from daily_harvest_details dhd
|
|
122
|
-
inner join daily_harvests dh on dh.id = dhd.daily_harvest_id
|
|
123
|
-
inner join temp_blocks blk on blk.id = dh.block_id
|
|
124
|
-
where dh.harvest_date between $1 and $2
|
|
125
|
-
GROUP BY blk.block_id, dh.harvest_date
|
|
126
|
-
) as tot ON tot.harvest_date::date = md.dateDay
|
|
127
|
-
) dt
|
|
128
|
-
)`,
|
|
129
|
-
[fromDateString, toDateString, block.id]
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
const result: any = await tx.query(`
|
|
133
|
-
select * from temp_daily_production_data dt
|
|
134
|
-
`)
|
|
135
|
-
|
|
136
|
-
const total: any = await tx.query(`
|
|
137
|
-
select count(*) from temp_daily_production_data
|
|
138
|
-
`)
|
|
139
|
-
|
|
140
|
-
let items = result.map(itm => {
|
|
141
|
-
return {
|
|
142
|
-
block: itm.block,
|
|
143
|
-
dateDay: itm.date_day,
|
|
144
|
-
diffInBunches: parseFloat(itm.diff_in_bunches).toFixed(1),
|
|
145
|
-
prevBunchBalInField: parseFloat(itm.prev_bunch_bal_in_field).toFixed(1),
|
|
146
|
-
prevWeightBalInRamp: parseFloat(itm.prev_weight_bal_in_ramp).toFixed(4),
|
|
147
|
-
toDateBunchHarvest: parseFloat(itm.to_date_bunch_harvest).toFixed(1),
|
|
148
|
-
toDateOutTurn: itm.to_date_out_turn,
|
|
149
|
-
toDateWeightDispatch: parseFloat(itm.to_date_weight_dispatch).toFixed(4),
|
|
150
|
-
todayBunchBalInField: parseFloat(itm.today_bunch_bal_in_field).toFixed(1),
|
|
151
|
-
todayBunchCollected: parseFloat(itm.today_bunch_collected).toFixed(1),
|
|
152
|
-
todayBunchHarvest: parseFloat(itm.today_bunch_harvest).toFixed(1),
|
|
153
|
-
todayBunchInField: parseFloat(itm.today_bunch_in_field).toFixed(1),
|
|
154
|
-
todayHarvestingRound: itm.today_harvesting_round,
|
|
155
|
-
todayHectareCover: parseFloat(itm.today_hectare_cover).toFixed(4),
|
|
156
|
-
todayOutTurn: itm.today_out_turn,
|
|
157
|
-
todayWeightBalInRamp: parseFloat(itm.today_weight_bal_in_ramp).toFixed(4),
|
|
158
|
-
todayWeightDispatch: parseFloat(itm.today_weight_dispatch).toFixed(4)
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
return { items, total: total[0].count }
|
|
163
|
-
} catch (error) {
|
|
164
|
-
throw error
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|