@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,131 +0,0 @@
|
|
|
1
|
-
import { EntityManager, Repository } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { Domain, getRepository } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { RECORD_STATUS, TRANSACTION_TYPE } from '../../../constants'
|
|
7
|
-
import { DailyDispatch, DailyDispatchDetail, Organization, OrganizationStaff, Ramp, Truck } from '../../../entities'
|
|
8
|
-
import { generateTransactionHistory, NoGenerator } from '../../../utils'
|
|
9
|
-
|
|
10
|
-
export const generateDailyDispatch = {
|
|
11
|
-
async generateDailyDispatch(_: any, { dailyDispatch }, context: ResolverContext) {
|
|
12
|
-
const { domain, user, tx } = context.state
|
|
13
|
-
|
|
14
|
-
let dailyDispatchDetails: DailyDispatchDetail[] = dailyDispatch.dailyDispatchDetails
|
|
15
|
-
let driver: OrganizationStaff
|
|
16
|
-
let transport: Truck
|
|
17
|
-
let dispatchTo: Organization
|
|
18
|
-
|
|
19
|
-
if (dailyDispatch?.driver) {
|
|
20
|
-
driver = await tx.getRepository(OrganizationStaff).findOne({
|
|
21
|
-
where: { id: dailyDispatch.driver.id }
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (dailyDispatch?.transport) {
|
|
26
|
-
transport = await tx.getRepository(Truck).findOne({
|
|
27
|
-
where: { id: dailyDispatch.transport.id }
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (dailyDispatch?.dispatchTo) {
|
|
32
|
-
dispatchTo = await tx.getRepository(Organization).findOne({
|
|
33
|
-
where: { id: dailyDispatch.dispatchTo.id }
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const totalTonnageRelease: number = dailyDispatchDetails.reduce(function (prev, cur) {
|
|
38
|
-
return prev + cur.collectedRampWeight
|
|
39
|
-
}, 0)
|
|
40
|
-
|
|
41
|
-
// 1. Create daily dispatchment
|
|
42
|
-
let newDailyDispatch: DailyDispatch = new DailyDispatch()
|
|
43
|
-
newDailyDispatch.name = NoGenerator.dailyDispatch()
|
|
44
|
-
newDailyDispatch.domain = domain
|
|
45
|
-
newDailyDispatch.transport = transport
|
|
46
|
-
newDailyDispatch.transportNo = transport.name
|
|
47
|
-
newDailyDispatch.driver = driver
|
|
48
|
-
newDailyDispatch.driverIdentification = driver?.idNumber ? driver.idNumber : null
|
|
49
|
-
newDailyDispatch.externalDriver = driver?.name ? driver?.name : null
|
|
50
|
-
newDailyDispatch.totalTonnageRelease = totalTonnageRelease
|
|
51
|
-
newDailyDispatch.chitNo = dailyDispatch?.chitNo
|
|
52
|
-
newDailyDispatch.percentage = dailyDispatch?.percentage
|
|
53
|
-
newDailyDispatch.dispatchTo = dispatchTo
|
|
54
|
-
newDailyDispatch.dispatchAt = dailyDispatch.dispatchAt
|
|
55
|
-
newDailyDispatch.status = RECORD_STATUS.STORED
|
|
56
|
-
newDailyDispatch.creator = user
|
|
57
|
-
newDailyDispatch = await tx.getRepository(DailyDispatch).save(newDailyDispatch)
|
|
58
|
-
|
|
59
|
-
// 2. Create daily dispatch detail
|
|
60
|
-
dailyDispatchDetails = await addDailyDispatchDetail(
|
|
61
|
-
domain,
|
|
62
|
-
newDailyDispatch,
|
|
63
|
-
dailyDispatchDetails.map((record: DailyDispatchDetail) => {
|
|
64
|
-
return { ...record }
|
|
65
|
-
}),
|
|
66
|
-
user,
|
|
67
|
-
tx
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
await generateDispatchTransaction(domain, newDailyDispatch, dailyDispatchDetails, user, tx)
|
|
71
|
-
|
|
72
|
-
return newDailyDispatch
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export async function addDailyDispatchDetail(
|
|
77
|
-
domain: Domain,
|
|
78
|
-
newDailyDispatch: DailyDispatch,
|
|
79
|
-
dailyDispatchDetails: DailyDispatchDetail[],
|
|
80
|
-
user: User,
|
|
81
|
-
tx?: EntityManager
|
|
82
|
-
): Promise<DailyDispatchDetail[]> {
|
|
83
|
-
const rampRepo: Repository<Ramp> = tx?.getRepository(Ramp) || getRepository(Ramp)
|
|
84
|
-
const dailyDispatchDetailRepo: Repository<DailyDispatchDetail> =
|
|
85
|
-
tx?.getRepository(DailyDispatchDetail) || getRepository(DailyDispatchDetail)
|
|
86
|
-
|
|
87
|
-
dailyDispatchDetails = await Promise.all(
|
|
88
|
-
dailyDispatchDetails.map(async (dailyDispatchDetail: DailyDispatchDetail) => {
|
|
89
|
-
return {
|
|
90
|
-
...dailyDispatchDetail,
|
|
91
|
-
domain,
|
|
92
|
-
name: NoGenerator.dailyDispatchDetail(),
|
|
93
|
-
ramp: await rampRepo.findOneBy({ id: dailyDispatchDetail.ramp.id }),
|
|
94
|
-
dailyDispatch: newDailyDispatch,
|
|
95
|
-
creator: user,
|
|
96
|
-
updater: user
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
return await dailyDispatchDetailRepo.save(dailyDispatchDetails)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function generateDispatchTransaction(
|
|
105
|
-
domain: Domain,
|
|
106
|
-
newDailyDispatch: DailyDispatch,
|
|
107
|
-
dailyDispatchDetails: DailyDispatchDetail[],
|
|
108
|
-
user: User,
|
|
109
|
-
tx?: EntityManager
|
|
110
|
-
): Promise<void> {
|
|
111
|
-
await Promise.all(
|
|
112
|
-
dailyDispatchDetails.map(async record => {
|
|
113
|
-
const dispatchedTonnage: number = record.collectedRampWeight
|
|
114
|
-
const dispatchDate: string = newDailyDispatch.dispatchAt.toString().split('T')[0]
|
|
115
|
-
|
|
116
|
-
await generateTransactionHistory(
|
|
117
|
-
null,
|
|
118
|
-
domain,
|
|
119
|
-
record.ramp,
|
|
120
|
-
newDailyDispatch.id,
|
|
121
|
-
newDailyDispatch.name,
|
|
122
|
-
TRANSACTION_TYPE.DISPATCHMENT,
|
|
123
|
-
dispatchDate,
|
|
124
|
-
0,
|
|
125
|
-
-dispatchedTonnage,
|
|
126
|
-
user,
|
|
127
|
-
tx
|
|
128
|
-
)
|
|
129
|
-
})
|
|
130
|
-
)
|
|
131
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Query } from './daily-dispatch-query'
|
|
2
|
-
|
|
3
|
-
import { generateDailyDispatch } from './generate-daily-dispatch'
|
|
4
|
-
import { deleteDailyDispatch } from './delete-daily-dispatch'
|
|
5
|
-
import { updateDailyDispatch } from './update-daily-dispatch'
|
|
6
|
-
|
|
7
|
-
export const DailyDispatchResolver = {
|
|
8
|
-
Query,
|
|
9
|
-
Mutation: {
|
|
10
|
-
...generateDailyDispatch,
|
|
11
|
-
...deleteDailyDispatch,
|
|
12
|
-
...updateDailyDispatch
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DailyDispatch, DailyDispatchDetail } from '../../../entities'
|
|
2
|
-
|
|
3
|
-
export const updateDailyDispatch = {
|
|
4
|
-
async updateDailyDispatch(_: any, { name, chitNo, percentage, dailyDispatchDetails }, context: ResolverContext) {
|
|
5
|
-
const { domain, tx, user } = context.state
|
|
6
|
-
|
|
7
|
-
const repository = tx.getRepository(DailyDispatch)
|
|
8
|
-
const dailyDispatch = await repository.findOne({
|
|
9
|
-
where: { domain: { id: domain.id }, name },
|
|
10
|
-
relations: ['dailyDispatchDetails']
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
let foundDailyDispatchDetails: DailyDispatchDetail[] = dailyDispatch.dailyDispatchDetails
|
|
14
|
-
|
|
15
|
-
foundDailyDispatchDetails = foundDailyDispatchDetails.map(record => {
|
|
16
|
-
const matchedDispatchDetail: any = dailyDispatchDetails.find(
|
|
17
|
-
dispatchDetail => dispatchDetail.name === record.name
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
...record,
|
|
22
|
-
...matchedDispatchDetail,
|
|
23
|
-
updater: user
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
await tx.getRepository(DailyDispatchDetail).save(foundDailyDispatchDetails)
|
|
28
|
-
|
|
29
|
-
return await repository.save({
|
|
30
|
-
...dailyDispatch,
|
|
31
|
-
chitNo,
|
|
32
|
-
percentage,
|
|
33
|
-
updater: user
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { EntityManager, IsNull } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { buildQuery, Domain, ListParam } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { DailyDispatchDetail as DailyDispatchDetailEntity } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const Query = {
|
|
8
|
-
async dailyDispatchDetail(_: any, { name }, context: ResolverContext) {
|
|
9
|
-
const { domain, tx } = context.state
|
|
10
|
-
|
|
11
|
-
return await tx.getRepository(DailyDispatchDetailEntity).findOne({
|
|
12
|
-
where: { domain: { id: domain.id }, name, deletedAt: IsNull() },
|
|
13
|
-
relations: ['domain', 'dailyDispatch', 'ramp', 'creator', 'updater']
|
|
14
|
-
})
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
async dailyDispatchDetails(_: any, params: ListParam, context: ResolverContext) {
|
|
18
|
-
const { tx } = context.state
|
|
19
|
-
|
|
20
|
-
const queryBuilder = tx.getRepository(DailyDispatchDetailEntity).createQueryBuilder()
|
|
21
|
-
buildQuery(queryBuilder, params, context)
|
|
22
|
-
|
|
23
|
-
queryBuilder
|
|
24
|
-
.leftJoinAndSelect('DailyDispatchDetail.domain', 'Domain')
|
|
25
|
-
.leftJoinAndSelect('DailyDispatchDetail.dailyDispatch', 'DailyDispatch')
|
|
26
|
-
.leftJoinAndSelect('DailyDispatchDetail.ramp', 'Ramp')
|
|
27
|
-
.leftJoinAndSelect('DailyDispatchDetail.creator', 'Creator')
|
|
28
|
-
.leftJoinAndSelect('DailyDispatchDetail.updater', 'Updater')
|
|
29
|
-
|
|
30
|
-
if (params.filters?.length > 0) queryBuilder.andWhere('DailyDispatchDetail.deletedAt IS NULL')
|
|
31
|
-
else queryBuilder.where('DailyDispatchDetail.deletedAt IS NULL')
|
|
32
|
-
|
|
33
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
34
|
-
|
|
35
|
-
return { items, total }
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { EntityManager, IsNull } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { buildQuery, Domain, ListParam } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { DailyHarvest as DailyHarvestEntity, RecordTransaction } from '../../../entities'
|
|
6
|
-
|
|
7
|
-
export const Query = {
|
|
8
|
-
async dailyHarvest(_: any, { name }, context: ResolverContext) {
|
|
9
|
-
const { domain, tx } = context.state
|
|
10
|
-
|
|
11
|
-
const transaction: RecordTransaction = await tx.getRepository(RecordTransaction).findOne({ where: { domain } })
|
|
12
|
-
|
|
13
|
-
return await tx.getRepository(DailyHarvestEntity).findOne({
|
|
14
|
-
where: { domain: { id: domain.id }, name, deletedAt: IsNull() },
|
|
15
|
-
relations: [
|
|
16
|
-
'domain',
|
|
17
|
-
'block',
|
|
18
|
-
'dailyHarvestDetails',
|
|
19
|
-
'dailyHarvestDetails.organizationStaff',
|
|
20
|
-
'dailyHarvestDetails.organizationStaff.organization',
|
|
21
|
-
'creator',
|
|
22
|
-
'updater'
|
|
23
|
-
]
|
|
24
|
-
})
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
async dailyHarvests(_: any, params: ListParam, context: ResolverContext) {
|
|
28
|
-
const { tx } = context.state
|
|
29
|
-
|
|
30
|
-
const queryBuilder = tx.getRepository(DailyHarvestEntity).createQueryBuilder()
|
|
31
|
-
buildQuery(queryBuilder, params, context)
|
|
32
|
-
|
|
33
|
-
queryBuilder
|
|
34
|
-
.leftJoinAndSelect('DailyHarvest.domain', 'Domain')
|
|
35
|
-
.leftJoinAndSelect('DailyHarvest.block', 'Block')
|
|
36
|
-
.leftJoinAndSelect('DailyHarvest.creator', 'Creator')
|
|
37
|
-
.leftJoinAndSelect('DailyHarvest.updater', 'Updater')
|
|
38
|
-
|
|
39
|
-
if (params.filters?.length > 0) queryBuilder.andWhere('DailyHarvest.deletedAt IS NULL')
|
|
40
|
-
else queryBuilder.where('DailyHarvest.deletedAt IS NULL')
|
|
41
|
-
|
|
42
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
43
|
-
|
|
44
|
-
return { items, total }
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { IsNull } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { INVENTORY_TYPE, TRANSACTION_TYPE } from '../../../constants'
|
|
4
|
-
import { DailyHarvest, DailyHarvestDetail, PlantationInventory } from '../../../entities'
|
|
5
|
-
import { generateTransactionHistory } from '../../../utils'
|
|
6
|
-
|
|
7
|
-
export const deleteDailyHarvest = {
|
|
8
|
-
async deleteDailyHarvest(_: any, { name }, context: ResolverContext) {
|
|
9
|
-
try {
|
|
10
|
-
const { domain, user, tx } = context.state
|
|
11
|
-
const dailyHarvest = await tx
|
|
12
|
-
.getRepository(DailyHarvest)
|
|
13
|
-
.findOneOrFail({ where: { name, deletedAt: IsNull() }, relations: ['block'] })
|
|
14
|
-
|
|
15
|
-
await tx.getRepository(DailyHarvest).update(
|
|
16
|
-
{
|
|
17
|
-
domain: { id: domain.id },
|
|
18
|
-
name
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
deletedAt: new Date()
|
|
22
|
-
}
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
await tx.getRepository(DailyHarvestDetail).update(
|
|
26
|
-
{
|
|
27
|
-
domain: { id: domain.id },
|
|
28
|
-
dailyHarvest: { id: dailyHarvest.id }
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
deletedAt: new Date()
|
|
32
|
-
}
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
const foundPlantationInv: PlantationInventory = await tx.getRepository(PlantationInventory).findOne({
|
|
36
|
-
where: { domain: { id: domain.id }, block: { id: dailyHarvest.block.id }, type: INVENTORY_TYPE.FIELD_BUNCHES },
|
|
37
|
-
relations: ['domain', 'block']
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
await tx.getRepository(PlantationInventory).save({
|
|
41
|
-
...foundPlantationInv,
|
|
42
|
-
totalBunches: foundPlantationInv.totalBunches - dailyHarvest.totalBunchHarvested,
|
|
43
|
-
updater: user
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
await generateTransactionHistory(
|
|
47
|
-
dailyHarvest.block,
|
|
48
|
-
domain,
|
|
49
|
-
null,
|
|
50
|
-
dailyHarvest.id,
|
|
51
|
-
dailyHarvest.name,
|
|
52
|
-
TRANSACTION_TYPE.TERMINATED,
|
|
53
|
-
dailyHarvest.harvestDate,
|
|
54
|
-
-dailyHarvest.totalBunchHarvested,
|
|
55
|
-
0,
|
|
56
|
-
user,
|
|
57
|
-
tx
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
return true
|
|
61
|
-
} catch (error) {
|
|
62
|
-
throw error
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { EntityManager, IsNull, Repository } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { Domain, getRepository } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { INVENTORY_STATUS, INVENTORY_TYPE, RECORD_STATUS, TRANSACTION_TYPE } from '../../../constants'
|
|
7
|
-
import { Block, DailyHarvest, DailyHarvestDetail, OrganizationStaff, PlantationInventory } from '../../../entities'
|
|
8
|
-
import { generateTransactionHistory, NoGenerator } from '../../../utils'
|
|
9
|
-
|
|
10
|
-
export const generateDailyHarvest = {
|
|
11
|
-
async generateDailyHarvest(_: any, { dailyHarvest }, context: ResolverContext) {
|
|
12
|
-
const { domain, user, tx } = context.state
|
|
13
|
-
|
|
14
|
-
let dailyHarvestDetails: DailyHarvestDetail[] = dailyHarvest.dailyHarvestDetails
|
|
15
|
-
|
|
16
|
-
const block: Block = await tx.getRepository(Block).findOne({
|
|
17
|
-
where: { domain: { id: domain.id }, name: dailyHarvest.block, deletedAt: IsNull() }
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// get sum of bunch harvested from all staff
|
|
21
|
-
const totalBunchHarvested: number = dailyHarvestDetails.reduce(function (prev, cur) {
|
|
22
|
-
return prev + cur.totalBunchHarvested
|
|
23
|
-
}, 0)
|
|
24
|
-
|
|
25
|
-
const collectedBunch: number = dailyHarvest.collectedBunch || 0
|
|
26
|
-
let yesterdayBalanceBunchInField: number = dailyHarvest.yesterdayBalanceBunchInField || 0
|
|
27
|
-
|
|
28
|
-
// 1. Create daily harvest
|
|
29
|
-
let newDailyHarvest: DailyHarvest = new DailyHarvest()
|
|
30
|
-
newDailyHarvest.name = NoGenerator.dailyHarvest()
|
|
31
|
-
newDailyHarvest.domain = domain
|
|
32
|
-
newDailyHarvest.block = block
|
|
33
|
-
newDailyHarvest.harvestingRound = dailyHarvest.harvestingRound
|
|
34
|
-
newDailyHarvest.harvestDate = dailyHarvest.harvestDate
|
|
35
|
-
newDailyHarvest.coverage = dailyHarvest.coverage
|
|
36
|
-
newDailyHarvest.yesterdayBalanceBunchInField = yesterdayBalanceBunchInField
|
|
37
|
-
newDailyHarvest.totalBunchHarvested = totalBunchHarvested
|
|
38
|
-
newDailyHarvest.collectedBunch = collectedBunch
|
|
39
|
-
newDailyHarvest.balanceBunchInField = yesterdayBalanceBunchInField + totalBunchHarvested - collectedBunch
|
|
40
|
-
newDailyHarvest.status = RECORD_STATUS.STORED
|
|
41
|
-
newDailyHarvest.creator = user
|
|
42
|
-
newDailyHarvest.updater = user
|
|
43
|
-
|
|
44
|
-
await tx.getRepository(DailyHarvest).save(newDailyHarvest)
|
|
45
|
-
|
|
46
|
-
// 2. Create daily harvest detail
|
|
47
|
-
await addDailyHarvestDetail(
|
|
48
|
-
domain,
|
|
49
|
-
newDailyHarvest,
|
|
50
|
-
dailyHarvestDetails.map((record: DailyHarvestDetail) => {
|
|
51
|
-
return { ...record }
|
|
52
|
-
}),
|
|
53
|
-
user,
|
|
54
|
-
tx
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
// 3. Create bunches inventory in field
|
|
58
|
-
await addPlantationInventory(domain, newDailyHarvest, block, user, tx)
|
|
59
|
-
|
|
60
|
-
return newDailyHarvest
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function addDailyHarvestDetail(
|
|
65
|
-
domain: Domain,
|
|
66
|
-
newDailyHarvest: DailyHarvest,
|
|
67
|
-
dailyHarvestDetails: DailyHarvestDetail[],
|
|
68
|
-
user: User,
|
|
69
|
-
tx?: EntityManager
|
|
70
|
-
): Promise<void> {
|
|
71
|
-
const organizationStaffRepo: Repository<OrganizationStaff> =
|
|
72
|
-
tx?.getRepository(OrganizationStaff) || getRepository(OrganizationStaff)
|
|
73
|
-
const dailyHarvestDetailRepo: Repository<DailyHarvestDetail> =
|
|
74
|
-
tx?.getRepository(DailyHarvestDetail) || getRepository(DailyHarvestDetail)
|
|
75
|
-
|
|
76
|
-
dailyHarvestDetails = await Promise.all(
|
|
77
|
-
dailyHarvestDetails.map(async (record: DailyHarvestDetail) => {
|
|
78
|
-
return {
|
|
79
|
-
...record,
|
|
80
|
-
domain,
|
|
81
|
-
name: NoGenerator.dailyHarvestDetail(),
|
|
82
|
-
organizationStaff: await organizationStaffRepo.findOneBy({ id: record.organizationStaff.id }),
|
|
83
|
-
dailyHarvest: newDailyHarvest,
|
|
84
|
-
creator: user,
|
|
85
|
-
updater: user
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
await dailyHarvestDetailRepo.save(dailyHarvestDetails)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function addPlantationInventory(
|
|
94
|
-
domain: Domain,
|
|
95
|
-
newDailyHarvest: DailyHarvest,
|
|
96
|
-
block: Block,
|
|
97
|
-
user: User,
|
|
98
|
-
tx?: EntityManager
|
|
99
|
-
): Promise<void> {
|
|
100
|
-
const plantationInvRepo: Repository<PlantationInventory> =
|
|
101
|
-
tx?.getRepository(PlantationInventory) || getRepository(PlantationInventory)
|
|
102
|
-
|
|
103
|
-
let existingFieldBunch: PlantationInventory = await plantationInvRepo.findOne({
|
|
104
|
-
where: { domain: { id: domain.id }, block: { id: block.id }, type: INVENTORY_TYPE.FIELD_BUNCHES },
|
|
105
|
-
relations: ['domain', 'block']
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
let newTotalBunches: number = 0
|
|
109
|
-
|
|
110
|
-
if (existingFieldBunch) {
|
|
111
|
-
const totalBunches: number = existingFieldBunch.totalBunches
|
|
112
|
-
|
|
113
|
-
if (totalBunches < 0) {
|
|
114
|
-
existingFieldBunch = await plantationInvRepo.save({ ...existingFieldBunch, totalBunches: 0 })
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
newTotalBunches = existingFieldBunch.totalBunches + newDailyHarvest.totalBunchHarvested
|
|
118
|
-
|
|
119
|
-
existingFieldBunch.totalBunches = newTotalBunches
|
|
120
|
-
existingFieldBunch.updater = user
|
|
121
|
-
existingFieldBunch = await plantationInvRepo.save(existingFieldBunch)
|
|
122
|
-
|
|
123
|
-
await generateTransactionHistory(
|
|
124
|
-
block,
|
|
125
|
-
domain,
|
|
126
|
-
null,
|
|
127
|
-
newDailyHarvest.id,
|
|
128
|
-
newDailyHarvest.name,
|
|
129
|
-
TRANSACTION_TYPE.HARVEST,
|
|
130
|
-
newDailyHarvest.harvestDate,
|
|
131
|
-
newDailyHarvest.totalBunchHarvested,
|
|
132
|
-
0,
|
|
133
|
-
user,
|
|
134
|
-
tx
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
if (newDailyHarvest.collectedBunch > 0) {
|
|
138
|
-
existingFieldBunch.totalBunches -= newDailyHarvest.collectedBunch
|
|
139
|
-
existingFieldBunch.updater = user
|
|
140
|
-
existingFieldBunch = await plantationInvRepo.save(existingFieldBunch)
|
|
141
|
-
|
|
142
|
-
await generateTransactionHistory(
|
|
143
|
-
block,
|
|
144
|
-
domain,
|
|
145
|
-
null,
|
|
146
|
-
newDailyHarvest.id,
|
|
147
|
-
newDailyHarvest.name,
|
|
148
|
-
TRANSACTION_TYPE.LOADING,
|
|
149
|
-
newDailyHarvest.harvestDate,
|
|
150
|
-
-newDailyHarvest.collectedBunch,
|
|
151
|
-
0,
|
|
152
|
-
user,
|
|
153
|
-
tx
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
newTotalBunches = newTotalBunches + newDailyHarvest.totalBunchHarvested
|
|
158
|
-
|
|
159
|
-
let plantationInventory: PlantationInventory = new PlantationInventory()
|
|
160
|
-
plantationInventory.domain = domain
|
|
161
|
-
plantationInventory.name = NoGenerator.fieldBunchName()
|
|
162
|
-
plantationInventory.block = block
|
|
163
|
-
plantationInventory.type = INVENTORY_TYPE.FIELD_BUNCHES
|
|
164
|
-
plantationInventory.totalBunches = newTotalBunches
|
|
165
|
-
plantationInventory.status = INVENTORY_STATUS.STORED
|
|
166
|
-
plantationInventory.creator = user
|
|
167
|
-
plantationInventory.updater = user
|
|
168
|
-
|
|
169
|
-
plantationInventory = await plantationInvRepo.save(plantationInventory)
|
|
170
|
-
|
|
171
|
-
await generateTransactionHistory(
|
|
172
|
-
block,
|
|
173
|
-
domain,
|
|
174
|
-
null,
|
|
175
|
-
newDailyHarvest.id,
|
|
176
|
-
newDailyHarvest.name,
|
|
177
|
-
TRANSACTION_TYPE.HARVEST,
|
|
178
|
-
newDailyHarvest.harvestDate,
|
|
179
|
-
newDailyHarvest.totalBunchHarvested,
|
|
180
|
-
0,
|
|
181
|
-
user,
|
|
182
|
-
tx
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
if (newDailyHarvest.collectedBunch > 0) {
|
|
186
|
-
plantationInventory.totalBunches -= newDailyHarvest.collectedBunch
|
|
187
|
-
plantationInventory.updater = user
|
|
188
|
-
plantationInventory = await plantationInvRepo.save(plantationInventory)
|
|
189
|
-
|
|
190
|
-
await generateTransactionHistory(
|
|
191
|
-
block,
|
|
192
|
-
domain,
|
|
193
|
-
null,
|
|
194
|
-
newDailyHarvest.id,
|
|
195
|
-
newDailyHarvest.name,
|
|
196
|
-
TRANSACTION_TYPE.LOADING,
|
|
197
|
-
newDailyHarvest.harvestDate,
|
|
198
|
-
-newDailyHarvest.collectedBunch,
|
|
199
|
-
0,
|
|
200
|
-
user,
|
|
201
|
-
tx
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Query } from './daily-harvest-query'
|
|
2
|
-
|
|
3
|
-
import { generateDailyHarvest } from './generate-daily-harvest'
|
|
4
|
-
import { updateDailyHarvest } from './update-daily-harvest'
|
|
5
|
-
import { deleteDailyHarvest } from './delete-daily-harvest'
|
|
6
|
-
|
|
7
|
-
export const DailyHarvestResolver = {
|
|
8
|
-
Query,
|
|
9
|
-
Mutation: {
|
|
10
|
-
...generateDailyHarvest,
|
|
11
|
-
...updateDailyHarvest,
|
|
12
|
-
...deleteDailyHarvest
|
|
13
|
-
}
|
|
14
|
-
}
|