@tomei/finance 0.4.26 → 0.5.0
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/.commitlintrc.json +22 -22
- package/.eslintrc.js +72 -72
- package/.husky/commit-msg +4 -4
- package/.husky/pre-commit +4 -4
- package/.prettierrc +4 -4
- package/CONTRIBUTING.md +30 -30
- package/LICENSE +21 -21
- package/README.md +13 -13
- package/configs/config.js +336 -336
- package/dist/account/account.d.ts +35 -35
- package/dist/account/account.js +231 -231
- package/dist/account/account.repository.d.ts +5 -5
- package/dist/account/account.repository.js +11 -11
- package/dist/account/interfaces/account-attr.interface.d.ts +29 -29
- package/dist/account/interfaces/account-attr.interface.js +2 -2
- package/dist/account/interfaces/account.repository.interface.d.ts +3 -3
- package/dist/account/interfaces/account.repository.interface.js +2 -2
- package/dist/account-system-entity/account-system-entity.d.ts +11 -11
- package/dist/account-system-entity/account-system-entity.js +66 -66
- package/dist/account-system-entity/post-history.repository.d.ts +5 -5
- package/dist/account-system-entity/post-history.repository.js +11 -11
- package/dist/config.d.ts +1888 -1888
- package/dist/config.js +331 -331
- package/dist/customer/customer.d.ts +41 -41
- package/dist/customer/customer.js +214 -214
- package/dist/customer/finance-customer.repository.d.ts +5 -5
- package/dist/customer/finance-customer.repository.js +25 -25
- package/dist/customer/interfaces/customer.repository.interface.d.ts +3 -3
- package/dist/customer/interfaces/customer.repository.interface.js +2 -2
- package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +10 -10
- package/dist/customer/interfaces/finance-customer-attr.interface.js +2 -2
- package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -3
- package/dist/customer/interfaces/finance-customer.repository.interface.js +2 -2
- package/dist/database.d.ts +4 -4
- package/dist/database.js +14 -14
- package/dist/document/document-item.d.ts +38 -38
- package/dist/document/document-item.js +83 -83
- package/dist/document/document-item.repository.d.ts +5 -5
- package/dist/document/document-item.repository.js +11 -11
- package/dist/document/document.d.ts +76 -76
- package/dist/document/document.js +566 -566
- package/dist/document/document.repository.d.ts +5 -5
- package/dist/document/document.repository.js +11 -11
- package/dist/document/interfaces/document-attr.interface.d.ts +27 -27
- package/dist/document/interfaces/document-attr.interface.js +6 -6
- package/dist/document/interfaces/document-item-attr.interface.d.ts +22 -22
- package/dist/document/interfaces/document-item-attr.interface.js +6 -6
- package/dist/document/interfaces/document-item.repository.interface.d.ts +3 -3
- package/dist/document/interfaces/document-item.repository.interface.js +2 -2
- package/dist/document/interfaces/document.repository.interface.d.ts +3 -3
- package/dist/document/interfaces/document.repository.interface.js +2 -2
- package/dist/enum/doc-type.enum.d.ts +8 -8
- package/dist/enum/doc-type.enum.js +12 -12
- package/dist/enum/document-status.enum.d.ts +6 -6
- package/dist/enum/document-status.enum.js +10 -10
- package/dist/enum/index.d.ts +8 -8
- package/dist/enum/index.js +17 -17
- package/dist/enum/payment-method.enum.d.ts +3 -3
- package/dist/enum/payment-method.enum.js +7 -7
- package/dist/enum/payment-status.enum.d.ts +4 -4
- package/dist/enum/payment-status.enum.js +8 -8
- package/dist/enum/payment-type.enum.d.ts +4 -4
- package/dist/enum/payment-type.enum.js +8 -8
- package/dist/enum/quick-book-client-scopes.enum.d.ts +13 -13
- package/dist/enum/quick-book-client-scopes.enum.js +18 -18
- package/dist/enum/transaction-type.enum.d.ts +4 -4
- package/dist/enum/transaction-type.enum.js +8 -8
- package/dist/finance-company/finance-company.d.ts +57 -57
- package/dist/finance-company/finance-company.js +1192 -1192
- package/dist/finance-company/finance-company.repository.d.ts +5 -5
- package/dist/finance-company/finance-company.repository.js +11 -11
- package/dist/helpers/typeof.d.ts +1 -1
- package/dist/helpers/typeof.js +26 -26
- package/dist/index.d.ts +17 -16
- package/dist/index.js +32 -30
- package/dist/index.js.map +1 -1
- package/dist/interfaces/account-system.interface.d.ts +13 -13
- package/dist/interfaces/account-system.interface.js +2 -2
- package/dist/interfaces/index.d.ts +2 -2
- package/dist/interfaces/index.js +2 -2
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +11 -11
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +2 -2
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.d.ts +10 -10
- package/dist/journal-entry/interfaces/journal-entry.repository.interface.js +2 -2
- package/dist/journal-entry/journal-entry.d.ts +39 -39
- package/dist/journal-entry/journal-entry.js +215 -215
- package/dist/journal-entry/journal-entry.repository.d.ts +5 -5
- package/dist/journal-entry/journal-entry.repository.js +11 -11
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +17 -17
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +2 -2
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -5
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +2 -2
- package/dist/ledger-transaction/ledger-transaction.d.ts +48 -48
- package/dist/ledger-transaction/ledger-transaction.js +155 -155
- package/dist/ledger-transaction/ledger-transaction.repository.d.ts +5 -5
- package/dist/ledger-transaction/ledger-transaction.repository.js +11 -11
- package/dist/models/account.entity.d.ts +30 -30
- package/dist/models/account.entity.js +232 -232
- package/dist/models/customer.entity.d.ts +13 -13
- package/dist/models/customer.entity.js +109 -109
- package/dist/models/document-item.entity.d.ts +27 -27
- package/dist/models/document-item.entity.js +172 -172
- package/dist/models/document.entity.d.ts +36 -36
- package/dist/models/document.entity.js +242 -242
- package/dist/models/finance-company.entity.d.ts +9 -9
- package/dist/models/finance-company.entity.js +44 -44
- package/dist/models/journal-entry.entity.d.ts +16 -16
- package/dist/models/journal-entry.entity.js +127 -127
- package/dist/models/ledger-transaction.entity.d.ts +24 -24
- package/dist/models/ledger-transaction.entity.js +172 -172
- package/dist/models/payment-item.entity.d.ts +12 -12
- package/dist/models/payment-item.entity.js +75 -75
- package/dist/models/payment-method-type.entity.d.ts +13 -13
- package/dist/models/payment-method-type.entity.js +85 -85
- package/dist/models/payment-method.entity.d.ts +10 -10
- package/dist/models/payment-method.entity.js +62 -62
- package/dist/models/payment-paid-with.entity.d.ts +24 -24
- package/dist/models/payment-paid-with.entity.js +158 -158
- package/dist/models/payment.entity.d.ts +27 -27
- package/dist/models/payment.entity.js +188 -188
- package/dist/models/post-history.entity.d.ts +11 -11
- package/dist/models/post-history.entity.js +63 -63
- package/dist/payment/interfaces/payment-attr.interface.d.ts +22 -22
- package/dist/payment/interfaces/payment-attr.interface.js +6 -6
- package/dist/payment/interfaces/payment-item-attr.interface.d.ts +7 -8
- package/dist/payment/interfaces/payment-item-attr.interface.js +6 -6
- package/dist/payment/interfaces/payment-item-attr.interface.js.map +1 -1
- package/dist/payment/interfaces/payment-item.repository.interface.d.ts +3 -3
- package/dist/payment/interfaces/payment-item.repository.interface.js +2 -2
- package/dist/payment/interfaces/payment-params.interface.d.ts +7 -7
- package/dist/payment/interfaces/payment-params.interface.js +2 -2
- package/dist/payment/interfaces/payment.repository.interface.d.ts +3 -3
- package/dist/payment/interfaces/payment.repository.interface.js +2 -2
- package/dist/payment/payment-item.repository.d.ts +17 -5
- package/dist/payment/payment-item.repository.js +50 -11
- package/dist/payment/payment-item.repository.js.map +1 -1
- package/dist/payment/payment.d.ts +51 -51
- package/dist/payment/payment.js +179 -179
- package/dist/payment/payment.repository.d.ts +5 -5
- package/dist/payment/payment.repository.js +11 -11
- package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +10 -10
- package/dist/payment-item/interfaces/payment-item-attr.interface.js +6 -6
- package/dist/payment-item/payment-item.d.ts +23 -23
- package/dist/payment-item/payment-item.js +119 -117
- package/dist/payment-item/payment-item.js.map +1 -1
- package/dist/payment-item/payment-item.repository.d.ts +5 -5
- package/dist/payment-item/payment-item.repository.js +11 -11
- package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +5 -5
- package/dist/payment-method/interfaces/payment-method-attr.interface.js +2 -2
- package/dist/payment-method/payment-method.d.ts +18 -18
- package/dist/payment-method/payment-method.js +98 -98
- package/dist/payment-method/payment-method.repository.d.ts +5 -5
- package/dist/payment-method/payment-method.repository.js +11 -11
- package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -8
- package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +2 -2
- package/dist/payment-method-type/payment-method-type.d.ts +16 -16
- package/dist/payment-method-type/payment-method-type.js +70 -70
- package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -5
- package/dist/payment-method-type/payment-method-type.repository.js +11 -11
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +19 -19
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js +6 -6
- package/dist/payment-paid-with/payment-paid-with.d.ts +31 -31
- package/dist/payment-paid-with/payment-paid-with.js +52 -52
- package/dist/payment-paid-with/payment-paid-with.repository.d.ts +5 -5
- package/dist/payment-paid-with/payment-paid-with.repository.js +11 -11
- package/dist/test-document.d.ts +3 -0
- package/dist/test-document.js +19 -0
- package/dist/test-document.js.map +1 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +7 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/invoice-template/assets/css/style.css.map +12 -12
- package/invoice-template/assets/css/style.min.css +1 -1
- package/invoice-template/assets/img/arrow_bg.svg +11 -11
- package/invoice-template/assets/img/coffy_shop_img.svg +18 -18
- package/invoice-template/assets/img/logo_accent.svg +3 -3
- package/invoice-template/assets/img/logo_white.svg +4 -4
- package/invoice-template/assets/img/sign.svg +12 -12
- package/invoice-template/assets/img/tomei-logo.svg +9 -9
- package/invoice-template/assets/js/html2canvas.min.js +10379 -10379
- package/invoice-template/assets/js/jquery.min.js +1 -1
- package/invoice-template/assets/sass/common/_color_variable.scss +12 -12
- package/invoice-template/assets/sass/common/_typography.scss +178 -178
- package/invoice-template/assets/sass/style.scss +12 -12
- package/migrations/finance-account-migration.js +97 -97
- package/migrations/finance-company-migration.js +29 -29
- package/migrations/finance-customer-migration.js +51 -51
- package/migrations/finance-document-item-migration.js +111 -111
- package/migrations/finance-document-migration.js +116 -116
- package/migrations/finance-payment-item-migration.js +52 -52
- package/migrations/finance-payment-method-migration.js +31 -31
- package/migrations/finance-payment-method-type-migration.js +55 -55
- package/migrations/finance-payment-migration.js +96 -96
- package/migrations/finance-post-history-migration.js +45 -45
- package/nest-cli.json +19 -19
- package/package.json +79 -79
- package/src/account/account.repository.ts +11 -11
- package/src/account/account.ts +264 -264
- package/src/account/interfaces/account-attr.interface.ts +31 -31
- package/src/account-system-entity/account-system-entity.ts +65 -65
- package/src/account-system-entity/post-history.repository.ts +11 -11
- package/src/config.ts +382 -382
- package/src/customer/customer.ts +276 -276
- package/src/customer/finance-customer.repository.ts +13 -13
- package/src/customer/interfaces/customer.repository.interface.ts +3 -3
- package/src/customer/interfaces/finance-customer-attr.interface.ts +10 -10
- package/src/customer/interfaces/finance-customer.repository.interface.ts +4 -4
- package/src/database.ts +15 -15
- package/src/document/document-item.repository.ts +11 -11
- package/src/document/document.repository.ts +11 -11
- package/src/document/interfaces/document-attr.interface.ts +28 -28
- package/src/document/interfaces/document-item-attr.interface.ts +22 -22
- package/src/document/interfaces/document-item.repository.interface.ts +4 -4
- package/src/enum/doc-type.enum.ts +8 -8
- package/src/enum/index.ts +17 -17
- package/src/enum/payment-method.enum.ts +3 -3
- package/src/enum/payment-type.enum.ts +4 -4
- package/src/finance-company/finance-company.repository.ts +11 -11
- package/src/finance-company/finance-company.ts +1754 -1754
- package/src/helpers/typeof.ts +29 -29
- package/src/index.ts +32 -30
- package/src/interfaces/account-system.interface.ts +20 -20
- package/src/interfaces/index.ts +3 -3
- package/src/models/account.entity.ts +206 -206
- package/src/models/customer.entity.ts +93 -93
- package/src/models/document-item.entity.ts +143 -143
- package/src/models/document.entity.ts +211 -211
- package/src/models/finance-company.entity.ts +25 -25
- package/src/models/journal-entry.entity.ts +110 -110
- package/src/models/ledger-transaction.entity.ts +148 -148
- package/src/models/payment-item.entity.ts +60 -60
- package/src/models/payment-method-type.entity.ts +70 -70
- package/src/models/payment-method.entity.ts +51 -51
- package/src/models/payment.entity.ts +161 -161
- package/src/models/post-history.entity.ts +41 -41
- package/src/payment/interfaces/payment-attr.interface.ts +23 -23
- package/src/payment/interfaces/payment-params.interface.ts +8 -8
- package/src/payment/payment.repository.ts +11 -11
- package/src/payment/payment.ts +213 -213
- package/src/payment-item/interfaces/payment-item-attr.interface.ts +10 -10
- package/src/payment-item/payment-item.repository.ts +11 -11
- package/src/payment-item/payment-item.ts +125 -119
- package/src/payment-method/payment-method.repository.ts +11 -11
- package/src/payment-method-type/payment-method-type.repository.ts +11 -11
- package/src/test-document.ts +25 -0
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +22 -22
- package/tslint.json +18 -18
- package/dist/account/entities/account.entity.d.ts +0 -26
- package/dist/account/entities/account.entity.js +0 -199
- package/dist/account/entities/account.entity.js.map +0 -1
- package/dist/account/entities/fee-associated-object.entity.d.ts +0 -6
- package/dist/account/entities/fee-associated-object.entity.js +0 -52
- package/dist/account/entities/fee-associated-object.entity.js.map +0 -1
- package/dist/account/index.d.ts +0 -6
- package/dist/account/index.js +0 -10
- package/dist/account/index.js.map +0 -1
- package/dist/account-system-entity/index.d.ts +0 -2
- package/dist/account-system-entity/index.js +0 -6
- package/dist/account-system-entity/index.js.map +0 -1
- package/dist/account-system-entity/post-history.entity.d.ts +0 -11
- package/dist/account-system-entity/post-history.entity.js +0 -65
- package/dist/account-system-entity/post-history.entity.js.map +0 -1
- package/dist/base/account-system.interface.d.ts +0 -7
- package/dist/base/account-system.interface.js +0 -3
- package/dist/base/account-system.interface.js.map +0 -1
- package/dist/base/address.base.abstract.d.ts +0 -4
- package/dist/base/address.base.abstract.js +0 -10
- package/dist/base/address.base.abstract.js.map +0 -1
- package/dist/base/base.address.d.ts +0 -8
- package/dist/base/base.address.js +0 -15
- package/dist/base/base.address.js.map +0 -1
- package/dist/base/base.object.d.ts +0 -7
- package/dist/base/base.object.js +0 -14
- package/dist/base/base.object.js.map +0 -1
- package/dist/base/base.owner.d.ts +0 -23
- package/dist/base/base.owner.js +0 -34
- package/dist/base/base.owner.js.map +0 -1
- package/dist/base/base.repository.abstract.d.ts +0 -12
- package/dist/base/base.repository.abstract.js +0 -22
- package/dist/base/base.repository.abstract.js.map +0 -1
- package/dist/base/base.repository.interface.d.ts +0 -9
- package/dist/base/base.repository.interface.js +0 -3
- package/dist/base/base.repository.interface.js.map +0 -1
- package/dist/base/index.d.ts +0 -4
- package/dist/base/index.js +0 -10
- package/dist/base/index.js.map +0 -1
- package/dist/base/object/base.object.abstract.d.ts +0 -5
- package/dist/base/object/base.object.abstract.js +0 -7
- package/dist/base/object/base.object.abstract.js.map +0 -1
- package/dist/base/object/base.object.d.ts +0 -7
- package/dist/base/object/base.object.js +0 -14
- package/dist/base/object/base.object.js.map +0 -1
- package/dist/base/object/object.interface.d.ts +0 -4
- package/dist/base/object/object.interface.js +0 -3
- package/dist/base/object/object.interface.js.map +0 -1
- package/dist/base/object.base.abstract.d.ts +0 -5
- package/dist/base/object.base.abstract.js +0 -11
- package/dist/base/object.base.abstract.js.map +0 -1
- package/dist/base/owner/base.owner.abstract.d.ts +0 -20
- package/dist/base/owner/base.owner.abstract.js +0 -8
- package/dist/base/owner/base.owner.abstract.js.map +0 -1
- package/dist/base/owner/base.owner.d.ts +0 -22
- package/dist/base/owner/base.owner.js +0 -31
- package/dist/base/owner/base.owner.js.map +0 -1
- package/dist/base/owner/owner.interface.d.ts +0 -19
- package/dist/base/owner/owner.interface.js +0 -3
- package/dist/base/owner/owner.interface.js.map +0 -1
- package/dist/base/person.base.abstract.d.ts +0 -21
- package/dist/base/person.base.abstract.js +0 -17
- package/dist/base/person.base.abstract.js.map +0 -1
- package/dist/base/repository/base.repository.abstract.d.ts +0 -12
- package/dist/base/repository/base.repository.abstract.js +0 -22
- package/dist/base/repository/base.repository.abstract.js.map +0 -1
- package/dist/base/repository/base.repository.interface.d.ts +0 -9
- package/dist/base/repository/base.repository.interface.js +0 -3
- package/dist/base/repository/base.repository.interface.js.map +0 -1
- package/dist/customer/customer.repository.d.ts +0 -0
- package/dist/customer/customer.repository.js +0 -1
- package/dist/customer/customer.repository.js.map +0 -1
- package/dist/customer/entities/customer.entity.d.ts +0 -13
- package/dist/customer/entities/customer.entity.js +0 -111
- package/dist/customer/entities/customer.entity.js.map +0 -1
- package/dist/customer/index.d.ts +0 -7
- package/dist/customer/index.js +0 -10
- package/dist/customer/index.js.map +0 -1
- package/dist/document/entities/document-item.entity.d.ts +0 -27
- package/dist/document/entities/document-item.entity.js +0 -174
- package/dist/document/entities/document-item.entity.js.map +0 -1
- package/dist/document/entities/document.entity.d.ts +0 -22
- package/dist/document/entities/document.entity.js +0 -139
- package/dist/document/entities/document.entity.js.map +0 -1
- package/dist/document/index.d.ts +0 -11
- package/dist/document/index.js +0 -20
- package/dist/document/index.js.map +0 -1
- package/dist/enum/document-type.enum.d.ts +0 -7
- package/dist/enum/document-type.enum.js +0 -12
- package/dist/enum/document-type.enum.js.map +0 -1
- package/dist/enum/intuit-client.enum.d.ts +0 -13
- package/dist/enum/intuit-client.enum.js +0 -19
- package/dist/enum/intuit-client.enum.js.map +0 -1
- package/dist/finance-company/entities/finance-company.entity.d.ts +0 -13
- package/dist/finance-company/entities/finance-company.entity.js +0 -113
- package/dist/finance-company/entities/finance-company.entity.js.map +0 -1
- package/dist/finance-company/finance-company.entity.d.ts +0 -13
- package/dist/finance-company/finance-company.entity.js +0 -66
- package/dist/finance-company/finance-company.entity.js.map +0 -1
- package/dist/finance-company/index.d.ts +0 -3
- package/dist/finance-company/index.js +0 -8
- package/dist/finance-company/index.js.map +0 -1
- package/dist/finance-company/interfaces/finance-company-attr.interface.d.ts +0 -10
- package/dist/finance-company/interfaces/finance-company-attr.interface.js +0 -3
- package/dist/finance-company/interfaces/finance-company-attr.interface.js.map +0 -1
- package/dist/finance-company/interfaces/finance-company.repository.interface.d.ts +0 -3
- package/dist/finance-company/interfaces/finance-company.repository.interface.js +0 -3
- package/dist/finance-company/interfaces/finance-company.repository.interface.js.map +0 -1
- package/dist/interfaces/account-system-entity.interface.d.ts +0 -7
- package/dist/interfaces/account-system-entity.interface.js +0 -3
- package/dist/interfaces/account-system-entity.interface.js.map +0 -1
- package/dist/interfaces/customer.repository.interface.d.ts +0 -3
- package/dist/interfaces/customer.repository.interface.js +0 -3
- package/dist/interfaces/customer.repository.interface.js.map +0 -1
- package/dist/interfaces/finance-customer.repository.interface.d.ts +0 -3
- package/dist/interfaces/finance-customer.repository.interface.js +0 -3
- package/dist/interfaces/finance-customer.repository.interface.js.map +0 -1
- package/dist/interfaces/systemConfig.interface.d.ts +0 -0
- package/dist/interfaces/systemConfig.interface.js +0 -1
- package/dist/interfaces/systemConfig.interface.js.map +0 -1
- package/dist/intuit-client/client.d.ts +0 -14
- package/dist/intuit-client/client.js +0 -44
- package/dist/intuit-client/client.js.map +0 -1
- package/dist/journal-entry/entities/journal-entry.entity.d.ts +0 -16
- package/dist/journal-entry/entities/journal-entry.entity.js +0 -129
- package/dist/journal-entry/entities/journal-entry.entity.js.map +0 -1
- package/dist/journal-entry/index.d.ts +0 -6
- package/dist/journal-entry/index.js +0 -10
- package/dist/journal-entry/index.js.map +0 -1
- package/dist/ledger-transaction/entities/ledger-transaction.entity.d.ts +0 -19
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js +0 -157
- package/dist/ledger-transaction/entities/ledger-transaction.entity.js.map +0 -1
- package/dist/ledger-transaction/index.d.ts +0 -6
- package/dist/ledger-transaction/index.js +0 -10
- package/dist/ledger-transaction/index.js.map +0 -1
- package/dist/payment/entities/payment-item.entity.d.ts +0 -10
- package/dist/payment/entities/payment-item.entity.js +0 -62
- package/dist/payment/entities/payment-item.entity.js.map +0 -1
- package/dist/payment/entities/payment.entity.d.ts +0 -25
- package/dist/payment/entities/payment.entity.js +0 -152
- package/dist/payment/entities/payment.entity.js.map +0 -1
- package/dist/payment/index.d.ts +0 -10
- package/dist/payment/index.js +0 -18
- package/dist/payment/index.js.map +0 -1
- package/dist/payment-item/interfaces/payment-item.repository.interface.d.ts +0 -3
- package/dist/payment-item/interfaces/payment-item.repository.interface.js +0 -3
- package/dist/payment-item/interfaces/payment-item.repository.interface.js.map +0 -1
- package/dist/quickbook-client/client.d.ts +0 -39
- package/dist/quickbook-client/client.js +0 -205
- package/dist/quickbook-client/client.js.map +0 -1
- package/dist/quickbook-client/constant.d.ts +0 -1
- package/dist/quickbook-client/constant.js +0 -5
- package/dist/quickbook-client/constant.js.map +0 -1
- package/dist/quickbook-client/index.d.ts +0 -5
- package/dist/quickbook-client/index.js +0 -6
- package/dist/quickbook-client/index.js.map +0 -1
- package/dist/quickbook-client/interfaces/quickbook-client-call-options.interface.d.ts +0 -6
- package/dist/quickbook-client/interfaces/quickbook-client-call-options.interface.js +0 -3
- package/dist/quickbook-client/interfaces/quickbook-client-call-options.interface.js.map +0 -1
- package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.d.ts +0 -9
- package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.js +0 -3
- package/dist/quickbook-client/interfaces/quickbook-client-create-account-options.interface.js.map +0 -1
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.d.ts +0 -7
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.js +0 -3
- package/dist/quickbook-client/interfaces/quickbook-client-create-customer-options.interface.js.map +0 -1
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.d.ts +0 -8
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.js +0 -3
- package/dist/quickbook-client/interfaces/quickbook-client-options.interface.js.map +0 -1
- package/dist/quickbook-client/quickbook-client.module-definition.d.ts +0 -2
- package/dist/quickbook-client/quickbook-client.module-definition.js +0 -9
- package/dist/quickbook-client/quickbook-client.module-definition.js.map +0 -1
- package/dist/quickbook-client/quickbook-client.module.d.ts +0 -6
- package/dist/quickbook-client/quickbook-client.module.js +0 -34
- package/dist/quickbook-client/quickbook-client.module.js.map +0 -1
|
@@ -1,1193 +1,1193 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const axios_1 = require("axios");
|
|
13
|
-
const cuid = require("cuid");
|
|
14
|
-
const general_1 = require("@tomei/general");
|
|
15
|
-
const journal_entry_1 = require("../journal-entry/journal-entry");
|
|
16
|
-
const document_1 = require("../document/document");
|
|
17
|
-
const finance_company_repository_1 = require("./finance-company.repository");
|
|
18
|
-
const finance_customer_repository_1 = require("../customer/finance-customer.repository");
|
|
19
|
-
const ledger_transaction_repository_1 = require("../ledger-transaction/ledger-transaction.repository");
|
|
20
|
-
const enum_1 = require("../enum");
|
|
21
|
-
const payment_method_type_1 = require("../payment-method-type/payment-method-type");
|
|
22
|
-
const payment_repository_1 = require("../payment/payment.repository");
|
|
23
|
-
const payment_item_repository_1 = require("../payment-item/payment-item.repository");
|
|
24
|
-
const document_repository_1 = require("../document/document.repository");
|
|
25
|
-
const document_item_repository_1 = require("../document/document-item.repository");
|
|
26
|
-
const payment_method_repository_1 = require("../payment-method/payment-method.repository");
|
|
27
|
-
const payment_method_type_repository_1 = require("../payment-method-type/payment-method-type.repository");
|
|
28
|
-
const payment_method_1 = require("../payment-method/payment-method");
|
|
29
|
-
const account_repository_1 = require("../account/account.repository");
|
|
30
|
-
const payment_paid_with_repository_1 = require("../payment-paid-with/payment-paid-with.repository");
|
|
31
|
-
const document_item_1 = require("../document/document-item");
|
|
32
|
-
const typeof_1 = require("../helpers/typeof");
|
|
33
|
-
const getConfig = require('../config');
|
|
34
|
-
const config = getConfig();
|
|
35
|
-
class FinanceCompany extends general_1.ObjectBase {
|
|
36
|
-
get CompSystemCode() {
|
|
37
|
-
return this._CompSystemCode;
|
|
38
|
-
}
|
|
39
|
-
set CompSystemCode(code) {
|
|
40
|
-
this._CompSystemCode = code;
|
|
41
|
-
}
|
|
42
|
-
get CompSystemRefId() {
|
|
43
|
-
return this._CompSystemRefId;
|
|
44
|
-
}
|
|
45
|
-
set CompSystemRefId(id) {
|
|
46
|
-
this._CompSystemRefId = id;
|
|
47
|
-
}
|
|
48
|
-
get AccSystemCode() {
|
|
49
|
-
return this._AccSystemCode;
|
|
50
|
-
}
|
|
51
|
-
set AccSystemCode(code) {
|
|
52
|
-
this._AccSystemCode = code;
|
|
53
|
-
}
|
|
54
|
-
get CompanyId() {
|
|
55
|
-
return this._CompanyId;
|
|
56
|
-
}
|
|
57
|
-
get ObjectId() {
|
|
58
|
-
return this._CompanyId;
|
|
59
|
-
}
|
|
60
|
-
set ObjectId(id) {
|
|
61
|
-
this._CompanyId = id;
|
|
62
|
-
}
|
|
63
|
-
get ObjectName() {
|
|
64
|
-
return `${this.CompSystemCode}-${this.CompSystemRefId}-${this.AccSystemCode}`;
|
|
65
|
-
}
|
|
66
|
-
get TableName() {
|
|
67
|
-
return 'finance_Company';
|
|
68
|
-
}
|
|
69
|
-
get AccountingSystem() {
|
|
70
|
-
return this._AccountingSystem;
|
|
71
|
-
}
|
|
72
|
-
set AccountingSystem(system) {
|
|
73
|
-
this._AccountingSystem = system;
|
|
74
|
-
}
|
|
75
|
-
constructor(compSystemCode, compSystemRefId, accSystemCode) {
|
|
76
|
-
super();
|
|
77
|
-
this._CompanyId = 'New';
|
|
78
|
-
this._CompSystemCode = '';
|
|
79
|
-
this._CompSystemRefId = '';
|
|
80
|
-
this._AccSystemCode = '';
|
|
81
|
-
this._PaymentMethods = [];
|
|
82
|
-
this.CompSystemCode = compSystemCode;
|
|
83
|
-
this.CompSystemRefId = compSystemRefId;
|
|
84
|
-
this.AccSystemCode = accSystemCode;
|
|
85
|
-
}
|
|
86
|
-
static getFinanceCompanyId(compSystemCode, compSystemRefId, accSystemCode) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
let sCompanyId = '';
|
|
89
|
-
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
90
|
-
if (!FinanceCompany._htFinanceCompanyIds.get(sKey)) {
|
|
91
|
-
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
92
|
-
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
93
|
-
where: {
|
|
94
|
-
CompSystemCode: compSystemCode,
|
|
95
|
-
CompSystemRefId: compSystemRefId,
|
|
96
|
-
AccSystemCode: accSystemCode,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
financeCompany.ObjectId = company.CompanyId;
|
|
100
|
-
sCompanyId = financeCompany.ObjectId;
|
|
101
|
-
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
102
|
-
FinanceCompany._htFinanceCompanies.add(sCompanyId, financeCompany);
|
|
103
|
-
}
|
|
104
|
-
if (typeof FinanceCompany._htFinanceCompanyIds.get(sKey) === 'string') {
|
|
105
|
-
sCompanyId = FinanceCompany._htFinanceCompanyIds.get(sKey);
|
|
106
|
-
}
|
|
107
|
-
return sCompanyId;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
static getFinanceCompany(companyId) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
if (!FinanceCompany._htFinanceCompanies.get(companyId)) {
|
|
113
|
-
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
114
|
-
where: { CompanyId: companyId },
|
|
115
|
-
});
|
|
116
|
-
if (!company) {
|
|
117
|
-
throw Error('No finance company found. Please create first.');
|
|
118
|
-
}
|
|
119
|
-
const compSystemCode = company.CompSystemCode;
|
|
120
|
-
const compSystemRefId = company.CompSystemRefId;
|
|
121
|
-
const accSystemCode = company.AccSystemCode;
|
|
122
|
-
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
123
|
-
financeCompany.ObjectId = company.CompanyId;
|
|
124
|
-
financeCompany._CompanyId = company.CompanyId;
|
|
125
|
-
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
126
|
-
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
127
|
-
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
128
|
-
}
|
|
129
|
-
console.log('return from hash table');
|
|
130
|
-
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
static createFinanceCompany(dbTransaction, loginUser, companyId, compSystemCode, compSystemRefId, accSystemCode) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
136
|
-
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
137
|
-
where: {
|
|
138
|
-
CompSystemCode: compSystemCode,
|
|
139
|
-
CompSystemRefId: compSystemRefId,
|
|
140
|
-
AccSystemCode: accSystemCode,
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
if (company) {
|
|
144
|
-
throw Error('There is already another Finance Company with the compSystemCode, CompSystemRefId and accSystemCode specified.');
|
|
145
|
-
}
|
|
146
|
-
financeCompany.ObjectId = companyId;
|
|
147
|
-
yield FinanceCompany._financeCompanyRepository.create({
|
|
148
|
-
CompanyId: financeCompany.CompanyId,
|
|
149
|
-
CompSystemCode: financeCompany.CompSystemCode,
|
|
150
|
-
CompSystemRefId: financeCompany.CompSystemRefId,
|
|
151
|
-
AccSystemCode: financeCompany.AccSystemCode,
|
|
152
|
-
}, {
|
|
153
|
-
transaction: dbTransaction,
|
|
154
|
-
});
|
|
155
|
-
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
156
|
-
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
157
|
-
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
158
|
-
console.log('return from hash table');
|
|
159
|
-
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
createCustomer(dbTransaction, custSystemCode, custSystemRefId, customer, loginUser) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
try {
|
|
165
|
-
if (!custSystemCode || !custSystemRefId) {
|
|
166
|
-
throw new Error('CustSystemCode and CustomerRefId are required fields.');
|
|
167
|
-
}
|
|
168
|
-
const financeCustomerData = yield FinanceCompany._FinanceCustomerRepository.findOne({
|
|
169
|
-
where: {
|
|
170
|
-
CompanyId: this._CompanyId,
|
|
171
|
-
CustSystemCode: custSystemCode,
|
|
172
|
-
CustSystemRefId: custSystemRefId,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
if (financeCustomerData) {
|
|
176
|
-
throw new Error('Customer already created previously.');
|
|
177
|
-
}
|
|
178
|
-
const customerId = yield this.AccountingSystem.createCustomer({
|
|
179
|
-
customer,
|
|
180
|
-
});
|
|
181
|
-
customer.CompanyId = this._CompanyId;
|
|
182
|
-
const newCustomer = yield customer.save(customerId, custSystemCode, custSystemRefId, dbTransaction);
|
|
183
|
-
const payload = {
|
|
184
|
-
Action: 'Create',
|
|
185
|
-
Activity: 'Finance Customer Created',
|
|
186
|
-
Description: `Customer (ID: ${newCustomer.CustomerId}) has been created for ${this.AccSystemCode}`,
|
|
187
|
-
EntityType: 'finance_Customer',
|
|
188
|
-
EntityValueBefore: JSON.stringify({}),
|
|
189
|
-
EntityValueAfter: JSON.stringify(newCustomer),
|
|
190
|
-
PerformedById: loginUser.ObjectId,
|
|
191
|
-
PerformedAt: new Date(),
|
|
192
|
-
EntityId: newCustomer.CustomerId,
|
|
193
|
-
};
|
|
194
|
-
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
195
|
-
return customer;
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
postJournal(dbTransaction, journalEntry, loginUser) {
|
|
203
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
const debitTransactions = yield journalEntry.DebitTransactions;
|
|
205
|
-
const creditTransactions = yield journalEntry.CreditTransactions;
|
|
206
|
-
try {
|
|
207
|
-
if (creditTransactions.length < 1 || (debitTransactions === null || debitTransactions === void 0 ? void 0 : debitTransactions.length) < 1) {
|
|
208
|
-
throw new Error('There should be at least 1 debit ledger transaction and 1 credit ledger transaction in the journal entry');
|
|
209
|
-
}
|
|
210
|
-
const totalCreditAmount = creditTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.CreditAmount, 0);
|
|
211
|
-
const totalDebitAmount = debitTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.DebitAmount, 0);
|
|
212
|
-
if (totalCreditAmount !== totalDebitAmount) {
|
|
213
|
-
throw new Error('Credit ledger transaction and debit ledger transaction should the same amount');
|
|
214
|
-
}
|
|
215
|
-
const newJournalEntry = yield journalEntry.save(loginUser.ObjectId, dbTransaction);
|
|
216
|
-
for (const ledgerTransaction of debitTransactions) {
|
|
217
|
-
ledgerTransaction.TransactionId = cuid();
|
|
218
|
-
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
219
|
-
yield ledgerTransaction.save(dbTransaction);
|
|
220
|
-
}
|
|
221
|
-
for (const ledgerTransaction of creditTransactions) {
|
|
222
|
-
ledgerTransaction.TransactionId = cuid();
|
|
223
|
-
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
224
|
-
yield ledgerTransaction.save(dbTransaction);
|
|
225
|
-
}
|
|
226
|
-
yield this.AccountingSystem.postJournalEntry(newJournalEntry);
|
|
227
|
-
const payload = {
|
|
228
|
-
Action: 'Create',
|
|
229
|
-
Activity: 'Post Journal Entry',
|
|
230
|
-
Description: `Journal Entry (ID: ${newJournalEntry.JournalEntryId}) has been created`,
|
|
231
|
-
EntityType: 'JournalEntry',
|
|
232
|
-
EntityValueBefore: JSON.stringify({}),
|
|
233
|
-
EntityValueAfter: JSON.stringify(newJournalEntry),
|
|
234
|
-
PerformedById: loginUser.ObjectId,
|
|
235
|
-
PerformedAt: new Date(),
|
|
236
|
-
EntityId: newJournalEntry.JournalEntryId,
|
|
237
|
-
};
|
|
238
|
-
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
createAccount(dbTransaction, account, loginUser) {
|
|
246
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
-
try {
|
|
248
|
-
if (!account.AccountType) {
|
|
249
|
-
throw new Error('AccountType is required.');
|
|
250
|
-
}
|
|
251
|
-
let createAccountPayload = {
|
|
252
|
-
Name: account.Name,
|
|
253
|
-
AcctNum: account.AccountNo,
|
|
254
|
-
AccountType: account.AccountType,
|
|
255
|
-
AccountSubType: account.AccountSubtype,
|
|
256
|
-
};
|
|
257
|
-
if (account.isParentAccountExists()) {
|
|
258
|
-
createAccountPayload = Object.assign(Object.assign({}, createAccountPayload), { CurrencyRef: 'MYR', ParentRef: account.ParentAccountNo, SubAccount: true });
|
|
259
|
-
}
|
|
260
|
-
console.log('Finance Company Create Account: Before accSystemAccountId Create');
|
|
261
|
-
const accSystemAccountId = yield this.AccountingSystem.createAccount(createAccountPayload);
|
|
262
|
-
console.log('Finance Company Create Account: After accSystemAccountId Create');
|
|
263
|
-
account.PostedToAccSystemYN = 'Y';
|
|
264
|
-
console.log('Finance Company Create Account: Before new Account Create');
|
|
265
|
-
const newAccount = yield account.save(this.CompanyId, accSystemAccountId, loginUser.ObjectId, dbTransaction);
|
|
266
|
-
console.log('Finance Company Create Account: After new Account Create');
|
|
267
|
-
const payload = {
|
|
268
|
-
Action: 'Create',
|
|
269
|
-
Activity: 'Account Created',
|
|
270
|
-
Description: `Account (ID: ${newAccount.AccountNo}) has been created`,
|
|
271
|
-
EntityType: 'Account',
|
|
272
|
-
EntityValueBefore: JSON.stringify({}),
|
|
273
|
-
EntityValueAfter: JSON.stringify(newAccount),
|
|
274
|
-
PerformedById: loginUser.ObjectId,
|
|
275
|
-
PerformedAt: new Date(),
|
|
276
|
-
EntityId: newAccount.AccountNo,
|
|
277
|
-
};
|
|
278
|
-
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
279
|
-
return account;
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
issueInvoice(dbTransaction, invoice, loginUser, customer, dtAccountNo) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
try {
|
|
289
|
-
const duplicateInvoice = yield FinanceCompany._DocumentRepository.findOne({
|
|
290
|
-
where: {
|
|
291
|
-
DocNo: invoice.DocNo,
|
|
292
|
-
},
|
|
293
|
-
transaction: dbTransaction,
|
|
294
|
-
});
|
|
295
|
-
if (duplicateInvoice) {
|
|
296
|
-
throw new Error('Invoice number already exists');
|
|
297
|
-
}
|
|
298
|
-
const documentItems = yield invoice.DocumentItems;
|
|
299
|
-
if (!documentItems.length) {
|
|
300
|
-
throw new Error('Document must have at least 1 document item');
|
|
301
|
-
}
|
|
302
|
-
for (const invoiceItem of documentItems) {
|
|
303
|
-
if (!invoiceItem.CtAccountNo) {
|
|
304
|
-
throw new Error('Each document item should have CtAccountNo provided');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
invoice.DocType = enum_1.DocType.INVOICE;
|
|
308
|
-
let invoiceMedia;
|
|
309
|
-
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
310
|
-
yield this.AccountingSystem.createInvoice(invoice);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
invoiceMedia = yield invoice.generateInvoice(invoice.IssuedById, customer);
|
|
314
|
-
}
|
|
315
|
-
yield FinanceCompany._DocumentRepository.create({
|
|
316
|
-
DocNo: invoice.DocNo,
|
|
317
|
-
DocType: invoice.DocType,
|
|
318
|
-
DocDate: invoice.DocDate,
|
|
319
|
-
CompanyId: invoice.CompanyId,
|
|
320
|
-
Currency: invoice.Currency,
|
|
321
|
-
Amount: invoice.Amount,
|
|
322
|
-
Description: invoice.Description,
|
|
323
|
-
Status: invoice.Status,
|
|
324
|
-
IssuedById: invoice.IssuedById,
|
|
325
|
-
IssuedToId: invoice.IssuedToId,
|
|
326
|
-
IssuedToType: invoice.IssuedToType,
|
|
327
|
-
RelatedObjectId: invoice.RelatedObjectId,
|
|
328
|
-
RelatedObjectType: invoice.RelatedObjectType,
|
|
329
|
-
CreatedById: invoice.CreatedById,
|
|
330
|
-
CreatedAt: new Date(),
|
|
331
|
-
UpdatedById: invoice.UpdatedById,
|
|
332
|
-
UpdatedAt: new Date(),
|
|
333
|
-
DocPDFFileMediaId: invoiceMedia.PDFMedia.MediaId,
|
|
334
|
-
DocHTMLFileMediaId: invoiceMedia.HTMLMedia.MediaId,
|
|
335
|
-
AccSystemRefId: invoice.AccSystemRefId,
|
|
336
|
-
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
337
|
-
PostedById: invoice.PostedById,
|
|
338
|
-
PostedDateTime: new Date(),
|
|
339
|
-
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
340
|
-
}, {
|
|
341
|
-
transaction: dbTransaction,
|
|
342
|
-
});
|
|
343
|
-
for (const documentItem of documentItems) {
|
|
344
|
-
yield FinanceCompany._DocumentItemRepository.create({
|
|
345
|
-
DocumentItemId: cuid(),
|
|
346
|
-
DocNo: invoice.DocNo,
|
|
347
|
-
Name: documentItem.Name,
|
|
348
|
-
NameBM: documentItem.NameBM,
|
|
349
|
-
Description: documentItem.Description,
|
|
350
|
-
ItemId: documentItem.ItemId,
|
|
351
|
-
ItemType: documentItem.ItemType,
|
|
352
|
-
ItemSKU: documentItem.ItemSKU,
|
|
353
|
-
ItemSerialNo: documentItem.ItemSerialNo,
|
|
354
|
-
Currency: documentItem.Currency,
|
|
355
|
-
UnitPrice: documentItem.UnitPrice,
|
|
356
|
-
Quantity: documentItem.Quantity,
|
|
357
|
-
QuantityUOM: documentItem.QuantityUOM,
|
|
358
|
-
Amount: documentItem.Amount,
|
|
359
|
-
TaxCode: documentItem.TaxCode,
|
|
360
|
-
TaxAmount: documentItem.TaxAmount,
|
|
361
|
-
TaxRate: documentItem.TaxRate,
|
|
362
|
-
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
363
|
-
DtAccountNo: documentItem.DtAccountNo
|
|
364
|
-
? documentItem.DtAccountNo
|
|
365
|
-
: null,
|
|
366
|
-
CtAccountNo: documentItem.CtAccountNo
|
|
367
|
-
? documentItem.CtAccountNo
|
|
368
|
-
: null,
|
|
369
|
-
}, {
|
|
370
|
-
transaction: dbTransaction,
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
const transactionDate = new Date();
|
|
374
|
-
const htCreditAccountAmount = new general_1.HashTable();
|
|
375
|
-
const htCreditAccountCurrency = new general_1.HashTable();
|
|
376
|
-
const htCreditAccountPurpose = new general_1.HashTable();
|
|
377
|
-
documentItems.forEach((invoiceItem) => {
|
|
378
|
-
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
379
|
-
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
380
|
-
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
381
|
-
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
385
|
-
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
const savedItems = htCreditAccountAmount.list();
|
|
389
|
-
for (const item of savedItems) {
|
|
390
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
391
|
-
journalEntry.init({
|
|
392
|
-
CompanyId: this.CompanyId,
|
|
393
|
-
Name: 'Issue Invoice ' + invoice.DocNo,
|
|
394
|
-
});
|
|
395
|
-
const creditAmount = item.value[1];
|
|
396
|
-
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
397
|
-
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
398
|
-
const dt = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
399
|
-
if (dtAccountNo) {
|
|
400
|
-
dt.AccountNo = dtAccountNo;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
dt.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
404
|
-
}
|
|
405
|
-
dt.Currency = currency ? currency : 'MYR';
|
|
406
|
-
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
407
|
-
dt.Date = transactionDate;
|
|
408
|
-
dt.Description = `${purpose}`;
|
|
409
|
-
dt.Name = `${purpose}`;
|
|
410
|
-
dt.RelatedDocNo = invoice.DocNo;
|
|
411
|
-
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
412
|
-
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
413
|
-
const ct = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
414
|
-
ct.AccountNo = item.value[0];
|
|
415
|
-
ct.Currency = currency ? currency : 'MYR';
|
|
416
|
-
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
417
|
-
ct.Date = transactionDate;
|
|
418
|
-
ct.Description = customer.FullName;
|
|
419
|
-
ct.Name = customer.FullName;
|
|
420
|
-
ct.RelatedDocNo = invoice.DocNo;
|
|
421
|
-
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
422
|
-
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
423
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
424
|
-
}
|
|
425
|
-
return invoice;
|
|
426
|
-
}
|
|
427
|
-
catch (err) {
|
|
428
|
-
console.log('Issue invoice err: ', err);
|
|
429
|
-
throw err;
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
issueDebitNote(dbTransaction, loginUser, invoice, customer, dtAccountNo) {
|
|
434
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
-
try {
|
|
436
|
-
const duplicateInvoice = yield FinanceCompany._DocumentRepository.findOne({
|
|
437
|
-
where: {
|
|
438
|
-
DocNo: invoice.DocNo,
|
|
439
|
-
},
|
|
440
|
-
transaction: dbTransaction,
|
|
441
|
-
});
|
|
442
|
-
if (duplicateInvoice) {
|
|
443
|
-
throw new Error('Invoice number already exists');
|
|
444
|
-
}
|
|
445
|
-
const documentItems = yield invoice.DocumentItems;
|
|
446
|
-
if (!documentItems.length) {
|
|
447
|
-
throw new Error('Document must have at least 1 document item');
|
|
448
|
-
}
|
|
449
|
-
for (const invoiceItem of documentItems) {
|
|
450
|
-
if (!invoiceItem.CtAccountNo) {
|
|
451
|
-
throw new Error('Each document item should have CtAccountNo provided');
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
invoice.DocType = enum_1.DocType.DEBIT_NOTE;
|
|
455
|
-
yield FinanceCompany._DocumentRepository.create({
|
|
456
|
-
DocNo: invoice.DocNo,
|
|
457
|
-
DocType: invoice.DocType,
|
|
458
|
-
DocDate: invoice.DocDate,
|
|
459
|
-
CompanyId: invoice.CompanyId,
|
|
460
|
-
Currency: invoice.Currency,
|
|
461
|
-
Amount: invoice.Amount,
|
|
462
|
-
Description: invoice.Description,
|
|
463
|
-
Status: invoice.Status,
|
|
464
|
-
IssuedById: loginUser.ObjectId,
|
|
465
|
-
IssuedToId: customer.ObjectId,
|
|
466
|
-
IssuedToType: invoice.IssuedToType,
|
|
467
|
-
RelatedObjectId: invoice.RelatedObjectId,
|
|
468
|
-
RelatedObjectType: invoice.RelatedObjectType,
|
|
469
|
-
CreatedById: loginUser.ObjectId,
|
|
470
|
-
CreatedAt: new Date(),
|
|
471
|
-
UpdatedById: loginUser.ObjectId,
|
|
472
|
-
UpdatedAt: new Date(),
|
|
473
|
-
DocPDFFileMediaId: invoice.DocPDFFileMediaId,
|
|
474
|
-
DocHTMLFileMediaId: invoice.DocHTMLFileMediaId,
|
|
475
|
-
AccSystemRefId: invoice.AccSystemRefId,
|
|
476
|
-
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
477
|
-
PostedById: invoice.PostedById,
|
|
478
|
-
PostedDateTime: new Date(),
|
|
479
|
-
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
480
|
-
}, {
|
|
481
|
-
transaction: dbTransaction,
|
|
482
|
-
});
|
|
483
|
-
documentItems.forEach((documentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
-
yield FinanceCompany._DocumentItemRepository.create({
|
|
485
|
-
DocumentItemId: cuid(),
|
|
486
|
-
DocNo: documentItem.DocNo,
|
|
487
|
-
Name: documentItem.Name,
|
|
488
|
-
NameBM: documentItem.NameBM,
|
|
489
|
-
Description: documentItem.Description,
|
|
490
|
-
ItemId: documentItem.ItemId,
|
|
491
|
-
ItemType: documentItem.ItemType,
|
|
492
|
-
ItemSKU: documentItem.ItemSKU,
|
|
493
|
-
ItemSerialNo: documentItem.ItemSerialNo,
|
|
494
|
-
Currency: documentItem.Currency,
|
|
495
|
-
UnitPrice: documentItem.UnitPrice,
|
|
496
|
-
Quantity: documentItem.Quantity,
|
|
497
|
-
QuantityUOM: documentItem.QuantityUOM,
|
|
498
|
-
Amount: documentItem.Amount,
|
|
499
|
-
TaxCode: documentItem.TaxCode,
|
|
500
|
-
TaxAmount: documentItem.TaxAmount,
|
|
501
|
-
TaxRate: documentItem.TaxRate,
|
|
502
|
-
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
503
|
-
DtAccountNo: documentItem.DtAccountNo,
|
|
504
|
-
CtAccountNo: documentItem.CtAccountNo,
|
|
505
|
-
}, {
|
|
506
|
-
transaction: dbTransaction,
|
|
507
|
-
});
|
|
508
|
-
}));
|
|
509
|
-
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
510
|
-
yield this.AccountingSystem.createInvoice(invoice);
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
invoice.generateInvoice(loginUser.IDNo, customer);
|
|
514
|
-
}
|
|
515
|
-
const transactionDate = new Date();
|
|
516
|
-
const htCreditAccountAmount = new general_1.HashTable();
|
|
517
|
-
const htCreditAccountCurrency = new general_1.HashTable();
|
|
518
|
-
const htCreditAccountPurpose = new general_1.HashTable();
|
|
519
|
-
documentItems.forEach((invoiceItem) => {
|
|
520
|
-
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
521
|
-
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
522
|
-
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
523
|
-
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
527
|
-
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
const savedItems = htCreditAccountAmount.list();
|
|
531
|
-
for (const item of savedItems) {
|
|
532
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
533
|
-
journalEntry.init({
|
|
534
|
-
CompanyId: this.CompanyId,
|
|
535
|
-
Name: 'issue Invoice ' + invoice.DocNo,
|
|
536
|
-
});
|
|
537
|
-
const creditAmount = item.value[1];
|
|
538
|
-
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
539
|
-
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
540
|
-
const dt = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
541
|
-
if (dtAccountNo) {
|
|
542
|
-
dt.AccountNo = dtAccountNo;
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
dt.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
546
|
-
}
|
|
547
|
-
dt.Currency = currency ? currency : 'MYR';
|
|
548
|
-
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
549
|
-
dt.Date = transactionDate;
|
|
550
|
-
dt.Description = `${purpose}`;
|
|
551
|
-
dt.Name = `${purpose}`;
|
|
552
|
-
dt.RelatedDocNo = invoice.DocNo;
|
|
553
|
-
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
554
|
-
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
555
|
-
const ct = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
556
|
-
ct.AccountNo = item.value[0];
|
|
557
|
-
ct.Currency = currency ? currency : 'MYR';
|
|
558
|
-
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
559
|
-
ct.Date = transactionDate;
|
|
560
|
-
ct.Description = customer.FullName;
|
|
561
|
-
ct.Name = customer.FullName;
|
|
562
|
-
ct.RelatedDocNo = invoice.DocNo;
|
|
563
|
-
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
564
|
-
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
565
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
566
|
-
}
|
|
567
|
-
return invoice;
|
|
568
|
-
}
|
|
569
|
-
catch (err) {
|
|
570
|
-
console.log('Issue debit note err: ', err);
|
|
571
|
-
throw err;
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
issueCreditNote(dbTransaction, loginUser, creditNote, customer, ctAccountNo) {
|
|
576
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
577
|
-
try {
|
|
578
|
-
const duplicateCreditNote = yield FinanceCompany._DocumentRepository.findOne({
|
|
579
|
-
where: {
|
|
580
|
-
DocNo: creditNote.DocNo,
|
|
581
|
-
},
|
|
582
|
-
transaction: dbTransaction,
|
|
583
|
-
});
|
|
584
|
-
if (duplicateCreditNote) {
|
|
585
|
-
throw new Error('Invoice number already exists');
|
|
586
|
-
}
|
|
587
|
-
const documentItems = yield creditNote.DocumentItems;
|
|
588
|
-
if (!documentItems.length) {
|
|
589
|
-
throw new Error('Document must have at least 1 document item');
|
|
590
|
-
}
|
|
591
|
-
for (const invoiceItem of documentItems) {
|
|
592
|
-
if (!invoiceItem.CtAccountNo) {
|
|
593
|
-
throw new Error('Each document item should have CtAccountNo provided');
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
creditNote.DocType = enum_1.DocType.DEBIT_NOTE;
|
|
597
|
-
yield FinanceCompany._DocumentRepository.create({
|
|
598
|
-
DocNo: creditNote.DocNo,
|
|
599
|
-
DocType: creditNote.DocType,
|
|
600
|
-
DocDate: creditNote.DocDate,
|
|
601
|
-
CompanyId: creditNote.CompanyId,
|
|
602
|
-
Currency: creditNote.Currency,
|
|
603
|
-
Amount: creditNote.Amount,
|
|
604
|
-
Description: creditNote.Description,
|
|
605
|
-
Status: creditNote.Status,
|
|
606
|
-
IssuedById: loginUser.ObjectId,
|
|
607
|
-
IssuedToId: customer.ObjectId,
|
|
608
|
-
IssuedToType: creditNote.IssuedToType,
|
|
609
|
-
RelatedObjectId: creditNote.RelatedObjectId,
|
|
610
|
-
RelatedObjectType: creditNote.RelatedObjectType,
|
|
611
|
-
CreatedById: loginUser.ObjectId,
|
|
612
|
-
CreatedAt: new Date(),
|
|
613
|
-
UpdatedById: loginUser.ObjectId,
|
|
614
|
-
UpdatedAt: new Date(),
|
|
615
|
-
DocPDFFileMediaId: creditNote.DocPDFFileMediaId,
|
|
616
|
-
DocHTMLFileMediaId: creditNote.DocHTMLFileMediaId,
|
|
617
|
-
AccSystemRefId: creditNote.AccSystemRefId,
|
|
618
|
-
PostedToAccSystemYN: creditNote.PostedToAccSystemYN,
|
|
619
|
-
PostedById: creditNote.PostedById,
|
|
620
|
-
PostedDateTime: new Date(),
|
|
621
|
-
UseAccSystemDocYN: creditNote.UseAccSystemDocYN,
|
|
622
|
-
}, {
|
|
623
|
-
transaction: dbTransaction,
|
|
624
|
-
});
|
|
625
|
-
documentItems.forEach((documentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
626
|
-
yield FinanceCompany._DocumentItemRepository.create({
|
|
627
|
-
DocumentItemId: documentItem.DocumentItemId,
|
|
628
|
-
DocNo: documentItem.DocNo,
|
|
629
|
-
Name: documentItem.Name,
|
|
630
|
-
NameBM: documentItem.NameBM,
|
|
631
|
-
Description: documentItem.Description,
|
|
632
|
-
ItemId: documentItem.ItemId,
|
|
633
|
-
ItemType: documentItem.ItemType,
|
|
634
|
-
ItemSKU: documentItem.ItemSKU,
|
|
635
|
-
ItemSerialNo: documentItem.ItemSerialNo,
|
|
636
|
-
Currency: documentItem.Currency,
|
|
637
|
-
UnitPrice: documentItem.UnitPrice,
|
|
638
|
-
Quantity: documentItem.Quantity,
|
|
639
|
-
QuantityUOM: documentItem.QuantityUOM,
|
|
640
|
-
Amount: documentItem.Amount,
|
|
641
|
-
TaxCode: documentItem.TaxCode,
|
|
642
|
-
TaxAmount: documentItem.TaxAmount,
|
|
643
|
-
TaxRate: documentItem.TaxRate,
|
|
644
|
-
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
645
|
-
DtAccountNo: documentItem.DtAccountNo,
|
|
646
|
-
CtAccountNo: documentItem.CtAccountNo,
|
|
647
|
-
}, {
|
|
648
|
-
transaction: dbTransaction,
|
|
649
|
-
});
|
|
650
|
-
}));
|
|
651
|
-
if (creditNote.UseAccSystemDocYN === 'Y') {
|
|
652
|
-
yield this.AccountingSystem.createCreditNote(creditNote);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
creditNote.generateCreditNote(loginUser.IDNo, customer);
|
|
656
|
-
}
|
|
657
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
658
|
-
journalEntry.init({
|
|
659
|
-
CompanyId: this.CompanyId,
|
|
660
|
-
Name: 'Issue Debit Note ' + creditNote.DocNo,
|
|
661
|
-
});
|
|
662
|
-
const transactionDate = new Date();
|
|
663
|
-
const creditTransaction = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
664
|
-
if (ctAccountNo) {
|
|
665
|
-
creditTransaction.AccountNo = ctAccountNo;
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
creditTransaction.AccountNo = customer.CustSystemCode + '-AP';
|
|
669
|
-
}
|
|
670
|
-
creditTransaction.Currency = creditNote.Currency;
|
|
671
|
-
creditTransaction.CreditAmount = creditNote.Amount;
|
|
672
|
-
creditTransaction.Date = transactionDate;
|
|
673
|
-
creditTransaction.Description = creditNote.DocNo;
|
|
674
|
-
creditTransaction.Name = creditNote.DocNo;
|
|
675
|
-
creditTransaction.RelatedDocNo = creditNote.DocNo;
|
|
676
|
-
creditTransaction.RelatedObjectId = creditNote.RelatedObjectId;
|
|
677
|
-
creditTransaction.RelatedObjectType = creditNote.RelatedObjectType;
|
|
678
|
-
for (const invoiceItem of documentItems) {
|
|
679
|
-
const itemLedger = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
680
|
-
itemLedger.AccountNo = invoiceItem.CtAccountNo;
|
|
681
|
-
itemLedger.Currency = invoiceItem.Currency;
|
|
682
|
-
itemLedger.DebitAmount = invoiceItem.Amount;
|
|
683
|
-
itemLedger.Date = transactionDate;
|
|
684
|
-
itemLedger.Description = invoiceItem.Description;
|
|
685
|
-
itemLedger.Name = invoiceItem.Name;
|
|
686
|
-
itemLedger.RelatedDocNo = creditNote.DocNo;
|
|
687
|
-
itemLedger.RelatedObjectId = creditNote.RelatedObjectId;
|
|
688
|
-
itemLedger.RelatedObjectType = creditNote.RelatedObjectType;
|
|
689
|
-
}
|
|
690
|
-
this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
691
|
-
const payload = {
|
|
692
|
-
Action: 'Create',
|
|
693
|
-
Activity: 'Issuing a Credit Note Transaction',
|
|
694
|
-
Description: `Credit Transaction (ID: ${creditTransaction.TransactionId}) has been created`,
|
|
695
|
-
EntityType: 'CreditTransaction',
|
|
696
|
-
EntityValueBefore: JSON.stringify({}),
|
|
697
|
-
EntityValueAfter: JSON.stringify(creditTransaction),
|
|
698
|
-
PerformedById: loginUser.ObjectId,
|
|
699
|
-
PerformedAt: transactionDate,
|
|
700
|
-
EntityId: creditTransaction.TransactionId,
|
|
701
|
-
};
|
|
702
|
-
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
703
|
-
return creditNote;
|
|
704
|
-
}
|
|
705
|
-
catch (err) {
|
|
706
|
-
console.log('Issue credit note err: ', err);
|
|
707
|
-
throw err;
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
collectPayment(dbTransaction, loginUser, payment, customer, ctAccountNo, receiptNo) {
|
|
712
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
713
|
-
try {
|
|
714
|
-
const paymentItems = yield payment.PaymentItems;
|
|
715
|
-
if (paymentItems.length < 1) {
|
|
716
|
-
throw new Error('Atleast one payment item is required to identify what payment is being paid for.');
|
|
717
|
-
}
|
|
718
|
-
const paymentPaidWithItems = yield payment.PaymentPaidWith;
|
|
719
|
-
if (paymentPaidWithItems.length < 1) {
|
|
720
|
-
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
721
|
-
}
|
|
722
|
-
const receiptDocuments = yield FinanceCompany._DocumentRepository.findAll({
|
|
723
|
-
where: {
|
|
724
|
-
DocType: enum_1.DocType.RECEIPT,
|
|
725
|
-
CompanyId: config.financeCompanies['TXG-FS'].companyId,
|
|
726
|
-
},
|
|
727
|
-
});
|
|
728
|
-
const receipt = new document_1.default(dbTransaction);
|
|
729
|
-
if (receiptNo) {
|
|
730
|
-
receipt.DocNo = receiptNo;
|
|
731
|
-
}
|
|
732
|
-
else {
|
|
733
|
-
receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
|
|
734
|
-
}
|
|
735
|
-
receipt.DocType = enum_1.DocType.RECEIPT;
|
|
736
|
-
receipt.DocDate = new Date();
|
|
737
|
-
receipt.CompanyId = config.financeCompanies['TXG-FS'].companyId;
|
|
738
|
-
receipt.Currency = payment.Currency;
|
|
739
|
-
receipt.Description = 'Payment Received';
|
|
740
|
-
receipt.IssuedById = loginUser.ObjectId;
|
|
741
|
-
receipt.IssuedToId = customer.CustomerId;
|
|
742
|
-
receipt.IssuedToType = (0, typeof_1.type)(customer);
|
|
743
|
-
receipt.RelatedObjectId = payment.RelatedObjectId;
|
|
744
|
-
receipt.RelatedObjectType = payment.RelatedObjectType;
|
|
745
|
-
receipt.UseAccSystemDocYN = 'N';
|
|
746
|
-
receipt.CreatedById = loginUser.ObjectId;
|
|
747
|
-
receipt.UpdatedById = loginUser.ObjectId;
|
|
748
|
-
for (const paymentItem of paymentItems) {
|
|
749
|
-
const receiptItem = new document_item_1.default(dbTransaction, receipt);
|
|
750
|
-
receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
751
|
-
receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
752
|
-
receiptItem.Description = '-';
|
|
753
|
-
receiptItem.Currency = paymentItem.Currency;
|
|
754
|
-
receiptItem.UnitPrice = paymentItem.Amount;
|
|
755
|
-
receiptItem.Quantity = 1;
|
|
756
|
-
receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
|
|
757
|
-
receiptItem.ItemId = receipt.DocNo;
|
|
758
|
-
receiptItem.ItemType = (0, typeof_1.type)(payment);
|
|
759
|
-
receiptItem.CtAccountNo = ctAccountNo;
|
|
760
|
-
yield receipt.newDocumentItem(receiptItem);
|
|
761
|
-
}
|
|
762
|
-
const receiptMedia = yield receipt.generateReceipt(receipt.IssuedById, customer);
|
|
763
|
-
yield FinanceCompany._DocumentRepository.create({
|
|
764
|
-
DocNo: receipt.DocNo,
|
|
765
|
-
DocType: receipt.DocType,
|
|
766
|
-
DocDate: receipt.DocDate,
|
|
767
|
-
CompanyId: receipt.CompanyId,
|
|
768
|
-
Currency: receipt.Currency,
|
|
769
|
-
Amount: receipt.Amount,
|
|
770
|
-
Description: receipt.Description,
|
|
771
|
-
Status: receipt.Status,
|
|
772
|
-
IssuedById: receipt.IssuedById,
|
|
773
|
-
IssuedToId: receipt.IssuedToId,
|
|
774
|
-
IssuedToType: receipt.IssuedToType,
|
|
775
|
-
RelatedObjectId: receipt.RelatedObjectId,
|
|
776
|
-
RelatedObjectType: receipt.RelatedObjectType,
|
|
777
|
-
CreatedById: receipt.CreatedById,
|
|
778
|
-
CreatedAt: new Date(),
|
|
779
|
-
UpdatedById: receipt.UpdatedById,
|
|
780
|
-
UpdatedAt: new Date(),
|
|
781
|
-
DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
|
|
782
|
-
DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
|
|
783
|
-
AccSystemRefId: receipt.AccSystemRefId,
|
|
784
|
-
PostedToAccSystemYN: receipt.PostedToAccSystemYN,
|
|
785
|
-
PostedById: receipt.PostedById,
|
|
786
|
-
PostedDateTime: new Date(),
|
|
787
|
-
UseAccSystemDocYN: receipt.UseAccSystemDocYN,
|
|
788
|
-
}, {
|
|
789
|
-
transaction: dbTransaction,
|
|
790
|
-
});
|
|
791
|
-
const receiptItems = yield receipt.DocumentItems;
|
|
792
|
-
for (const receiptItem of receiptItems) {
|
|
793
|
-
yield FinanceCompany._DocumentItemRepository.create({
|
|
794
|
-
DocumentItemId: cuid(),
|
|
795
|
-
DocNo: receipt.DocNo,
|
|
796
|
-
Name: receiptItem.Name,
|
|
797
|
-
NameBM: receiptItem.NameBM,
|
|
798
|
-
Description: receiptItem.Description,
|
|
799
|
-
ItemId: receiptItem.ItemId,
|
|
800
|
-
ItemType: receiptItem.ItemType,
|
|
801
|
-
ItemSKU: receiptItem.ItemSKU,
|
|
802
|
-
ItemSerialNo: receiptItem.ItemSerialNo,
|
|
803
|
-
Currency: receiptItem.Currency,
|
|
804
|
-
UnitPrice: receiptItem.UnitPrice,
|
|
805
|
-
Quantity: receiptItem.Quantity,
|
|
806
|
-
QuantityUOM: receiptItem.QuantityUOM,
|
|
807
|
-
Amount: receiptItem.Amount,
|
|
808
|
-
TaxCode: receiptItem.TaxCode,
|
|
809
|
-
TaxAmount: receiptItem.TaxAmount,
|
|
810
|
-
TaxRate: receiptItem.TaxRate,
|
|
811
|
-
TaxInclusiveYN: receiptItem.TaxInclusiveYN,
|
|
812
|
-
DtAccountNo: receiptItem.DtAccountNo
|
|
813
|
-
? receiptItem.DtAccountNo
|
|
814
|
-
: null,
|
|
815
|
-
CtAccountNo: receiptItem.CtAccountNo
|
|
816
|
-
? receiptItem.CtAccountNo
|
|
817
|
-
: null,
|
|
818
|
-
}, {
|
|
819
|
-
transaction: dbTransaction,
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
payment.PaymentId = cuid();
|
|
823
|
-
payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
|
|
824
|
-
payment.ReceivedBy = loginUser.ObjectId;
|
|
825
|
-
payment.IssuedBy = loginUser.ObjectId;
|
|
826
|
-
payment.ReceiptDocNo = receipt.DocNo;
|
|
827
|
-
yield FinanceCompany._PaymentRepository.create({
|
|
828
|
-
PaymentId: payment.PaymentId,
|
|
829
|
-
PaymentType: payment.PaymentType,
|
|
830
|
-
PaymentDate: payment.PaymentDate,
|
|
831
|
-
Description: payment.Description,
|
|
832
|
-
Currency: payment.Currency,
|
|
833
|
-
Amount: payment.Amount,
|
|
834
|
-
Status: enum_1.PaymentStatus.SUCCESSFUL,
|
|
835
|
-
PostedToAccSystemYN: 'N',
|
|
836
|
-
ReceivedBy: payment.ReceivedBy,
|
|
837
|
-
IssuedBy: payment.IssuedBy,
|
|
838
|
-
Remarks: payment.Remarks,
|
|
839
|
-
RelatedObjectId: payment.RelatedObjectId,
|
|
840
|
-
RelatedObjectType: payment.RelatedObjectType,
|
|
841
|
-
ReceiptDocNo: payment.ReceiptDocNo,
|
|
842
|
-
UpdatedAt: new Date(),
|
|
843
|
-
UpdatedBy: loginUser.ObjectId,
|
|
844
|
-
CreatedAt: new Date(),
|
|
845
|
-
CreatedBy: loginUser.ObjectId,
|
|
846
|
-
}, { transaction: dbTransaction });
|
|
847
|
-
for (const paymentItem of paymentItems) {
|
|
848
|
-
yield FinanceCompany._PaymentItemRepository.create({
|
|
849
|
-
PaymentId: payment.PaymentId,
|
|
850
|
-
PayForObjectId: paymentItem.PayForObjectId,
|
|
851
|
-
PayForObjectType: paymentItem.PayForObjectType,
|
|
852
|
-
Currency: paymentItem.Currency,
|
|
853
|
-
Amount: paymentItem.Amount,
|
|
854
|
-
Name: paymentItem.Name,
|
|
855
|
-
Description: paymentItem.Description,
|
|
856
|
-
}, { transaction: dbTransaction });
|
|
857
|
-
yield paymentItem.paid(dbTransaction);
|
|
858
|
-
}
|
|
859
|
-
for (const paymentPaidWithItem of paymentPaidWithItems) {
|
|
860
|
-
yield FinanceCompany._PaymentPaidWithRepository.create({
|
|
861
|
-
PaymentId: payment.PaymentId,
|
|
862
|
-
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
863
|
-
Currency: paymentPaidWithItem.Currency,
|
|
864
|
-
Amount: paymentPaidWithItem.Amount,
|
|
865
|
-
Status: paymentPaidWithItem.Status,
|
|
866
|
-
TransactionId: paymentPaidWithItem.TransactionId,
|
|
867
|
-
RefBank: paymentPaidWithItem.RefBank,
|
|
868
|
-
RefName: paymentPaidWithItem.RefName,
|
|
869
|
-
RefNo: paymentPaidWithItem.RefNo,
|
|
870
|
-
RefOther1: paymentPaidWithItem.RefOther1,
|
|
871
|
-
RefOther2: paymentPaidWithItem.RefOther2,
|
|
872
|
-
RefOther3: paymentPaidWithItem.RefOther3,
|
|
873
|
-
RefOther4: paymentPaidWithItem.RefOther4,
|
|
874
|
-
RefOther5: paymentPaidWithItem.RefOther5,
|
|
875
|
-
Remarks: paymentPaidWithItem.Remarks,
|
|
876
|
-
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
877
|
-
}, { transaction: dbTransaction });
|
|
878
|
-
}
|
|
879
|
-
const transactionDate = new Date();
|
|
880
|
-
for (const paymentPaidWith of paymentPaidWithItems) {
|
|
881
|
-
let paymentMethodType;
|
|
882
|
-
try {
|
|
883
|
-
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
|
|
884
|
-
}
|
|
885
|
-
catch (error) {
|
|
886
|
-
if (error instanceof general_1.RecordNotFoundError) {
|
|
887
|
-
throw new Error('Invalid Payment Method Type Id');
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
throw error;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
894
|
-
journalEntry.init({
|
|
895
|
-
CompanyId: this.CompanyId,
|
|
896
|
-
Name: 'Collect-payments for ' + payment.PaymentId,
|
|
897
|
-
});
|
|
898
|
-
const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
899
|
-
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
900
|
-
debitLT.Currency = paymentPaidWith.Currency;
|
|
901
|
-
debitLT.DebitAmount = paymentPaidWith.Amount;
|
|
902
|
-
debitLT.Date = transactionDate;
|
|
903
|
-
debitLT.Description = 'Payment Received';
|
|
904
|
-
debitLT.Name = customer.FullName;
|
|
905
|
-
debitLT.RelatedObjectId = receipt.RelatedObjectId;
|
|
906
|
-
debitLT.RelatedObjectType = payment.RelatedObjectType;
|
|
907
|
-
debitLT.RelatedPaymentId = payment.PaymentId;
|
|
908
|
-
const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
909
|
-
if (ctAccountNo) {
|
|
910
|
-
creditLT.AccountNo = ctAccountNo;
|
|
911
|
-
}
|
|
912
|
-
else {
|
|
913
|
-
creditLT.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
914
|
-
}
|
|
915
|
-
creditLT.Currency = paymentPaidWith.Currency;
|
|
916
|
-
creditLT.CreditAmount = paymentPaidWith.Amount;
|
|
917
|
-
creditLT.Date = transactionDate;
|
|
918
|
-
creditLT.Description = 'Payment Received';
|
|
919
|
-
creditLT.Name = paymentMethodType.Name;
|
|
920
|
-
creditLT.RelatedObjectId = receipt.RelatedObjectId;
|
|
921
|
-
creditLT.RelatedObjectType = payment.RelatedObjectType;
|
|
922
|
-
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
923
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
924
|
-
}
|
|
925
|
-
return payment;
|
|
926
|
-
}
|
|
927
|
-
catch (error) {
|
|
928
|
-
throw error;
|
|
929
|
-
}
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
makePayment(dbTransaction, loginUser, payment, customer, dtAccountNo) {
|
|
933
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
934
|
-
let paymentMethodType;
|
|
935
|
-
try {
|
|
936
|
-
const paymentPaidWith = yield payment.PaymentPaidWith;
|
|
937
|
-
if (paymentPaidWith.length < 1) {
|
|
938
|
-
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
939
|
-
}
|
|
940
|
-
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith[0].MethodTypeId);
|
|
941
|
-
const paymentItems = yield payment.PaymentItems;
|
|
942
|
-
if (paymentItems.length < 1) {
|
|
943
|
-
throw new Error('Atleast one payment item is required to identify what payment is being paid for');
|
|
944
|
-
}
|
|
945
|
-
payment.PaymentId = cuid();
|
|
946
|
-
payment.PaymentType = enum_1.PaymentType.PAYOUT;
|
|
947
|
-
payment.ReceivedBy = loginUser.ObjectId;
|
|
948
|
-
payment.IssuedBy = loginUser.ObjectId;
|
|
949
|
-
yield FinanceCompany._PaymentRepository.create({
|
|
950
|
-
PaymentId: payment.PaymentId,
|
|
951
|
-
PaymentType: payment.PaymentType,
|
|
952
|
-
PaymentDate: payment.PaymentDate,
|
|
953
|
-
Description: payment.Description,
|
|
954
|
-
Currency: payment.Currency,
|
|
955
|
-
ReceivedBy: payment.ReceivedBy,
|
|
956
|
-
IssuedBy: payment.IssuedBy,
|
|
957
|
-
Remarks: payment.Remarks,
|
|
958
|
-
RelatedObjectId: payment.RelatedObjectId,
|
|
959
|
-
RelatedObjectType: payment.RelatedObjectType,
|
|
960
|
-
Amount: payment.Amount,
|
|
961
|
-
Status: enum_1.PaymentStatus.SUCCESSFUL,
|
|
962
|
-
PostedToAccSystemYN: 'N',
|
|
963
|
-
UpdatedAt: new Date(),
|
|
964
|
-
UpdatedBy: loginUser.ObjectId,
|
|
965
|
-
CreatedAt: new Date(),
|
|
966
|
-
CreatedBy: loginUser.ObjectId,
|
|
967
|
-
}, { transaction: dbTransaction });
|
|
968
|
-
paymentItems.forEach((paymentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
969
|
-
yield FinanceCompany._PaymentItemRepository.create({
|
|
970
|
-
PaymentId: payment.PaymentId,
|
|
971
|
-
PayForObjectId: paymentItem.PayForObjectId,
|
|
972
|
-
PayForObjectType: paymentItem.PayForObjectType,
|
|
973
|
-
Currency: paymentItem.Currency,
|
|
974
|
-
Amount: paymentItem.Amount,
|
|
975
|
-
Name: paymentItem.Name,
|
|
976
|
-
Description: paymentItem.Description,
|
|
977
|
-
}, { transaction: dbTransaction });
|
|
978
|
-
yield paymentItem.paid(dbTransaction);
|
|
979
|
-
}));
|
|
980
|
-
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
981
|
-
yield FinanceCompany._PaymentPaidWithRepository.create({
|
|
982
|
-
PaymentId: payment.PaymentId,
|
|
983
|
-
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
984
|
-
Currency: paymentPaidWithItem.Currency,
|
|
985
|
-
Amount: paymentPaidWithItem.Amount,
|
|
986
|
-
Status: paymentPaidWithItem.Status,
|
|
987
|
-
TransactionId: paymentPaidWithItem.TransactionId,
|
|
988
|
-
RefBank: paymentPaidWithItem.RefBank,
|
|
989
|
-
RefName: paymentPaidWithItem.RefName,
|
|
990
|
-
RefNo: paymentPaidWithItem.RefNo,
|
|
991
|
-
RefOther1: paymentPaidWithItem.RefOther1,
|
|
992
|
-
RefOther2: paymentPaidWithItem.RefOther2,
|
|
993
|
-
RefOther3: paymentPaidWithItem.RefOther3,
|
|
994
|
-
RefOther4: paymentPaidWithItem.RefOther4,
|
|
995
|
-
RefOther5: paymentPaidWithItem.RefOther5,
|
|
996
|
-
Remarks: paymentPaidWithItem.Remarks,
|
|
997
|
-
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
998
|
-
}, { transaction: dbTransaction });
|
|
999
|
-
}
|
|
1000
|
-
const transactionDate = new Date();
|
|
1001
|
-
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
1002
|
-
try {
|
|
1003
|
-
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
|
|
1004
|
-
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
1005
|
-
journalEntry.init({
|
|
1006
|
-
CompanyId: this.CompanyId,
|
|
1007
|
-
Name: 'Make Payment for ' + payment.PaymentId,
|
|
1008
|
-
});
|
|
1009
|
-
const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
1010
|
-
creditLT.AccountNo = paymentMethodType.AccountNo;
|
|
1011
|
-
creditLT.Currency = paymentPaidWithItem.Currency;
|
|
1012
|
-
creditLT.CreditAmount = paymentPaidWithItem.Amount;
|
|
1013
|
-
creditLT.Date = transactionDate;
|
|
1014
|
-
creditLT.Description = customer.FullName;
|
|
1015
|
-
creditLT.Name = customer.FullName;
|
|
1016
|
-
creditLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1017
|
-
creditLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1018
|
-
const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
1019
|
-
if (dtAccountNo) {
|
|
1020
|
-
debitLT.AccountNo = dtAccountNo;
|
|
1021
|
-
}
|
|
1022
|
-
else {
|
|
1023
|
-
debitLT.AccountNo = (yield customer.AccountPayable).AccountNo;
|
|
1024
|
-
}
|
|
1025
|
-
debitLT.Currency = paymentPaidWithItem.Currency;
|
|
1026
|
-
debitLT.DebitAmount = paymentPaidWithItem.Amount;
|
|
1027
|
-
debitLT.Date = transactionDate;
|
|
1028
|
-
debitLT.Description = paymentMethodType.Name;
|
|
1029
|
-
debitLT.Name = paymentMethodType.Name;
|
|
1030
|
-
debitLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1031
|
-
debitLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1032
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1033
|
-
}
|
|
1034
|
-
catch (error) {
|
|
1035
|
-
if (error instanceof general_1.RecordNotFoundError) {
|
|
1036
|
-
throw new Error('Invalid Payment Method Type Id');
|
|
1037
|
-
}
|
|
1038
|
-
else {
|
|
1039
|
-
throw error;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
return payment;
|
|
1044
|
-
}
|
|
1045
|
-
catch (error) {
|
|
1046
|
-
if (error instanceof general_1.RecordNotFoundError) {
|
|
1047
|
-
throw new Error('Invalid PaymentMethodType id');
|
|
1048
|
-
}
|
|
1049
|
-
else {
|
|
1050
|
-
throw error;
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
get PaymentMethods() {
|
|
1056
|
-
return new Promise((resolve, reject) => {
|
|
1057
|
-
if (this.CompanyId !== 'New') {
|
|
1058
|
-
FinanceCompany._PaymentMethodRepository
|
|
1059
|
-
.findAll({
|
|
1060
|
-
where: {
|
|
1061
|
-
CompanyId: this.CompanyId,
|
|
1062
|
-
},
|
|
1063
|
-
transaction: this._DbTransaction,
|
|
1064
|
-
})
|
|
1065
|
-
.then((paymentMethod) => {
|
|
1066
|
-
const paymentMethodObjects = paymentMethod.map((paymentMethodData) => {
|
|
1067
|
-
return new Promise((resolve, reject) => {
|
|
1068
|
-
FinanceCompany._PaymentMethodTypeRepository
|
|
1069
|
-
.findAll({
|
|
1070
|
-
where: {
|
|
1071
|
-
MethodId: paymentMethodData.MethodId,
|
|
1072
|
-
},
|
|
1073
|
-
transaction: this._DbTransaction,
|
|
1074
|
-
raw: true,
|
|
1075
|
-
})
|
|
1076
|
-
.then((paymentMethodTypes) => {
|
|
1077
|
-
const paymentMethodObjects = Object.assign(Object.assign({}, paymentMethodData.get({ plain: true })), { Types: paymentMethodTypes });
|
|
1078
|
-
resolve(paymentMethodObjects);
|
|
1079
|
-
})
|
|
1080
|
-
.catch((err) => {
|
|
1081
|
-
reject(err);
|
|
1082
|
-
});
|
|
1083
|
-
}).then((paymentMethods) => paymentMethods);
|
|
1084
|
-
});
|
|
1085
|
-
return Promise.all(paymentMethodObjects);
|
|
1086
|
-
})
|
|
1087
|
-
.then((paymentMethodObjects) => {
|
|
1088
|
-
this._PaymentMethods = paymentMethodObjects;
|
|
1089
|
-
resolve(this._PaymentMethods);
|
|
1090
|
-
})
|
|
1091
|
-
.catch((err) => {
|
|
1092
|
-
reject(err);
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
else {
|
|
1096
|
-
resolve(this._PaymentMethods);
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
LoadPaymentMethods() {
|
|
1101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1102
|
-
const { companyId, paymentMethods } = config.financeCompanies['TXG-FS'];
|
|
1103
|
-
const paymentMethod = new payment_method_1.default();
|
|
1104
|
-
for (const method in paymentMethods) {
|
|
1105
|
-
const paymentMethodData = yield FinanceCompany._PaymentMethodRepository.findOne({
|
|
1106
|
-
where: {
|
|
1107
|
-
MethodId: paymentMethods[method].id,
|
|
1108
|
-
Name: paymentMethods[method].name,
|
|
1109
|
-
},
|
|
1110
|
-
});
|
|
1111
|
-
if (!paymentMethodData) {
|
|
1112
|
-
const newPaymentMethod = yield FinanceCompany._PaymentMethodRepository.create({
|
|
1113
|
-
MethodId: paymentMethods[method].id,
|
|
1114
|
-
Name: paymentMethods[method].name,
|
|
1115
|
-
CompanyId: companyId,
|
|
1116
|
-
});
|
|
1117
|
-
this._PaymentMethods.push(newPaymentMethod);
|
|
1118
|
-
}
|
|
1119
|
-
this._PaymentMethods.push(paymentMethodData);
|
|
1120
|
-
}
|
|
1121
|
-
this._PaymentMethods.forEach((item) => __awaiter(this, void 0, void 0, function* () {
|
|
1122
|
-
var _a, _b;
|
|
1123
|
-
const p = item === null || item === void 0 ? void 0 : item.get({ plain: true });
|
|
1124
|
-
for (const method in paymentMethods) {
|
|
1125
|
-
if (!p) {
|
|
1126
|
-
continue;
|
|
1127
|
-
}
|
|
1128
|
-
if (p.MethodId === ((_a = paymentMethods[method]) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1129
|
-
const paymentMethodTypeData = yield FinanceCompany._PaymentMethodTypeRepository.findOne({
|
|
1130
|
-
where: {
|
|
1131
|
-
MethodId: p.MethodId,
|
|
1132
|
-
},
|
|
1133
|
-
});
|
|
1134
|
-
if (!paymentMethodTypeData) {
|
|
1135
|
-
const configPaymentMethodTypes = (_b = paymentMethods[method]) === null || _b === void 0 ? void 0 : _b.types;
|
|
1136
|
-
for (const methodType in configPaymentMethodTypes) {
|
|
1137
|
-
const accountData = yield FinanceCompany._AccountRepository.findOne({
|
|
1138
|
-
where: {
|
|
1139
|
-
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1140
|
-
},
|
|
1141
|
-
});
|
|
1142
|
-
if (!accountData) {
|
|
1143
|
-
const accountPayload = {
|
|
1144
|
-
CompanyId: companyId,
|
|
1145
|
-
Name: configPaymentMethodTypes[methodType].name,
|
|
1146
|
-
AccountType: 'PaymentMethod',
|
|
1147
|
-
CreatedAt: new Date(),
|
|
1148
|
-
CreatedById: 'System',
|
|
1149
|
-
AccSystemRefId: 'REF',
|
|
1150
|
-
PostedToAccSystemYN: 'N',
|
|
1151
|
-
};
|
|
1152
|
-
try {
|
|
1153
|
-
yield FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType].accountNo }, accountPayload));
|
|
1154
|
-
yield FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType]
|
|
1155
|
-
.processingFeeAccountNo }, accountPayload));
|
|
1156
|
-
}
|
|
1157
|
-
catch (err) { }
|
|
1158
|
-
}
|
|
1159
|
-
const paymentMethodTypePayload = {
|
|
1160
|
-
MethodId: p.MethodId,
|
|
1161
|
-
MethodTypeId: configPaymentMethodTypes[methodType].id,
|
|
1162
|
-
Name: configPaymentMethodTypes[methodType].name,
|
|
1163
|
-
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1164
|
-
ProcessingFeeRate: configPaymentMethodTypes[methodType].processingFeeRate,
|
|
1165
|
-
ProcessingFeeAccountNo: configPaymentMethodTypes[methodType].processingFeeAccountNo,
|
|
1166
|
-
};
|
|
1167
|
-
try {
|
|
1168
|
-
yield paymentMethod.newPaymentMethodType(paymentMethodTypePayload);
|
|
1169
|
-
}
|
|
1170
|
-
catch (err) { }
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}));
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
exports.default = FinanceCompany;
|
|
1180
|
-
FinanceCompany._htFinanceCompanyIds = new general_1.HashTable();
|
|
1181
|
-
FinanceCompany._htFinanceCompanies = new general_1.HashTable();
|
|
1182
|
-
FinanceCompany._financeCompanyRepository = new finance_company_repository_1.FinanceCompanyRepository();
|
|
1183
|
-
FinanceCompany._PaymentRepository = new payment_repository_1.PaymentRepository();
|
|
1184
|
-
FinanceCompany._PaymentItemRepository = new payment_item_repository_1.PaymentItemRepository();
|
|
1185
|
-
FinanceCompany._PaymentPaidWithRepository = new payment_paid_with_repository_1.PaymentPaidWithRepository();
|
|
1186
|
-
FinanceCompany._PaymentMethodRepository = new payment_method_repository_1.PaymentMethodRepository();
|
|
1187
|
-
FinanceCompany._PaymentMethodTypeRepository = new payment_method_type_repository_1.PaymentMethodTypeRepository();
|
|
1188
|
-
FinanceCompany._DocumentRepository = new document_repository_1.DocumentRepository();
|
|
1189
|
-
FinanceCompany._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
1190
|
-
FinanceCompany._FinanceCustomerRepository = new finance_customer_repository_1.FinanceCustomerRepository();
|
|
1191
|
-
FinanceCompany._LedgerTransactionRepository = new ledger_transaction_repository_1.LedgerTransactionRepository();
|
|
1192
|
-
FinanceCompany._AccountRepository = new account_repository_1.AccountRepository();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const axios_1 = require("axios");
|
|
13
|
+
const cuid = require("cuid");
|
|
14
|
+
const general_1 = require("@tomei/general");
|
|
15
|
+
const journal_entry_1 = require("../journal-entry/journal-entry");
|
|
16
|
+
const document_1 = require("../document/document");
|
|
17
|
+
const finance_company_repository_1 = require("./finance-company.repository");
|
|
18
|
+
const finance_customer_repository_1 = require("../customer/finance-customer.repository");
|
|
19
|
+
const ledger_transaction_repository_1 = require("../ledger-transaction/ledger-transaction.repository");
|
|
20
|
+
const enum_1 = require("../enum");
|
|
21
|
+
const payment_method_type_1 = require("../payment-method-type/payment-method-type");
|
|
22
|
+
const payment_repository_1 = require("../payment/payment.repository");
|
|
23
|
+
const payment_item_repository_1 = require("../payment-item/payment-item.repository");
|
|
24
|
+
const document_repository_1 = require("../document/document.repository");
|
|
25
|
+
const document_item_repository_1 = require("../document/document-item.repository");
|
|
26
|
+
const payment_method_repository_1 = require("../payment-method/payment-method.repository");
|
|
27
|
+
const payment_method_type_repository_1 = require("../payment-method-type/payment-method-type.repository");
|
|
28
|
+
const payment_method_1 = require("../payment-method/payment-method");
|
|
29
|
+
const account_repository_1 = require("../account/account.repository");
|
|
30
|
+
const payment_paid_with_repository_1 = require("../payment-paid-with/payment-paid-with.repository");
|
|
31
|
+
const document_item_1 = require("../document/document-item");
|
|
32
|
+
const typeof_1 = require("../helpers/typeof");
|
|
33
|
+
const getConfig = require('../config');
|
|
34
|
+
const config = getConfig();
|
|
35
|
+
class FinanceCompany extends general_1.ObjectBase {
|
|
36
|
+
get CompSystemCode() {
|
|
37
|
+
return this._CompSystemCode;
|
|
38
|
+
}
|
|
39
|
+
set CompSystemCode(code) {
|
|
40
|
+
this._CompSystemCode = code;
|
|
41
|
+
}
|
|
42
|
+
get CompSystemRefId() {
|
|
43
|
+
return this._CompSystemRefId;
|
|
44
|
+
}
|
|
45
|
+
set CompSystemRefId(id) {
|
|
46
|
+
this._CompSystemRefId = id;
|
|
47
|
+
}
|
|
48
|
+
get AccSystemCode() {
|
|
49
|
+
return this._AccSystemCode;
|
|
50
|
+
}
|
|
51
|
+
set AccSystemCode(code) {
|
|
52
|
+
this._AccSystemCode = code;
|
|
53
|
+
}
|
|
54
|
+
get CompanyId() {
|
|
55
|
+
return this._CompanyId;
|
|
56
|
+
}
|
|
57
|
+
get ObjectId() {
|
|
58
|
+
return this._CompanyId;
|
|
59
|
+
}
|
|
60
|
+
set ObjectId(id) {
|
|
61
|
+
this._CompanyId = id;
|
|
62
|
+
}
|
|
63
|
+
get ObjectName() {
|
|
64
|
+
return `${this.CompSystemCode}-${this.CompSystemRefId}-${this.AccSystemCode}`;
|
|
65
|
+
}
|
|
66
|
+
get TableName() {
|
|
67
|
+
return 'finance_Company';
|
|
68
|
+
}
|
|
69
|
+
get AccountingSystem() {
|
|
70
|
+
return this._AccountingSystem;
|
|
71
|
+
}
|
|
72
|
+
set AccountingSystem(system) {
|
|
73
|
+
this._AccountingSystem = system;
|
|
74
|
+
}
|
|
75
|
+
constructor(compSystemCode, compSystemRefId, accSystemCode) {
|
|
76
|
+
super();
|
|
77
|
+
this._CompanyId = 'New';
|
|
78
|
+
this._CompSystemCode = '';
|
|
79
|
+
this._CompSystemRefId = '';
|
|
80
|
+
this._AccSystemCode = '';
|
|
81
|
+
this._PaymentMethods = [];
|
|
82
|
+
this.CompSystemCode = compSystemCode;
|
|
83
|
+
this.CompSystemRefId = compSystemRefId;
|
|
84
|
+
this.AccSystemCode = accSystemCode;
|
|
85
|
+
}
|
|
86
|
+
static getFinanceCompanyId(compSystemCode, compSystemRefId, accSystemCode) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
let sCompanyId = '';
|
|
89
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
90
|
+
if (!FinanceCompany._htFinanceCompanyIds.get(sKey)) {
|
|
91
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
92
|
+
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
93
|
+
where: {
|
|
94
|
+
CompSystemCode: compSystemCode,
|
|
95
|
+
CompSystemRefId: compSystemRefId,
|
|
96
|
+
AccSystemCode: accSystemCode,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
financeCompany.ObjectId = company.CompanyId;
|
|
100
|
+
sCompanyId = financeCompany.ObjectId;
|
|
101
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
102
|
+
FinanceCompany._htFinanceCompanies.add(sCompanyId, financeCompany);
|
|
103
|
+
}
|
|
104
|
+
if (typeof FinanceCompany._htFinanceCompanyIds.get(sKey) === 'string') {
|
|
105
|
+
sCompanyId = FinanceCompany._htFinanceCompanyIds.get(sKey);
|
|
106
|
+
}
|
|
107
|
+
return sCompanyId;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
static getFinanceCompany(companyId) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
if (!FinanceCompany._htFinanceCompanies.get(companyId)) {
|
|
113
|
+
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
114
|
+
where: { CompanyId: companyId },
|
|
115
|
+
});
|
|
116
|
+
if (!company) {
|
|
117
|
+
throw Error('No finance company found. Please create first.');
|
|
118
|
+
}
|
|
119
|
+
const compSystemCode = company.CompSystemCode;
|
|
120
|
+
const compSystemRefId = company.CompSystemRefId;
|
|
121
|
+
const accSystemCode = company.AccSystemCode;
|
|
122
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
123
|
+
financeCompany.ObjectId = company.CompanyId;
|
|
124
|
+
financeCompany._CompanyId = company.CompanyId;
|
|
125
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
126
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
127
|
+
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
128
|
+
}
|
|
129
|
+
console.log('return from hash table');
|
|
130
|
+
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
static createFinanceCompany(dbTransaction, loginUser, companyId, compSystemCode, compSystemRefId, accSystemCode) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
136
|
+
const company = yield FinanceCompany._financeCompanyRepository.findOne({
|
|
137
|
+
where: {
|
|
138
|
+
CompSystemCode: compSystemCode,
|
|
139
|
+
CompSystemRefId: compSystemRefId,
|
|
140
|
+
AccSystemCode: accSystemCode,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
if (company) {
|
|
144
|
+
throw Error('There is already another Finance Company with the compSystemCode, CompSystemRefId and accSystemCode specified.');
|
|
145
|
+
}
|
|
146
|
+
financeCompany.ObjectId = companyId;
|
|
147
|
+
yield FinanceCompany._financeCompanyRepository.create({
|
|
148
|
+
CompanyId: financeCompany.CompanyId,
|
|
149
|
+
CompSystemCode: financeCompany.CompSystemCode,
|
|
150
|
+
CompSystemRefId: financeCompany.CompSystemRefId,
|
|
151
|
+
AccSystemCode: financeCompany.AccSystemCode,
|
|
152
|
+
}, {
|
|
153
|
+
transaction: dbTransaction,
|
|
154
|
+
});
|
|
155
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
156
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
157
|
+
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
158
|
+
console.log('return from hash table');
|
|
159
|
+
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
createCustomer(dbTransaction, custSystemCode, custSystemRefId, customer, loginUser) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
try {
|
|
165
|
+
if (!custSystemCode || !custSystemRefId) {
|
|
166
|
+
throw new Error('CustSystemCode and CustomerRefId are required fields.');
|
|
167
|
+
}
|
|
168
|
+
const financeCustomerData = yield FinanceCompany._FinanceCustomerRepository.findOne({
|
|
169
|
+
where: {
|
|
170
|
+
CompanyId: this._CompanyId,
|
|
171
|
+
CustSystemCode: custSystemCode,
|
|
172
|
+
CustSystemRefId: custSystemRefId,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
if (financeCustomerData) {
|
|
176
|
+
throw new Error('Customer already created previously.');
|
|
177
|
+
}
|
|
178
|
+
const customerId = yield this.AccountingSystem.createCustomer({
|
|
179
|
+
customer,
|
|
180
|
+
});
|
|
181
|
+
customer.CompanyId = this._CompanyId;
|
|
182
|
+
const newCustomer = yield customer.save(customerId, custSystemCode, custSystemRefId, dbTransaction);
|
|
183
|
+
const payload = {
|
|
184
|
+
Action: 'Create',
|
|
185
|
+
Activity: 'Finance Customer Created',
|
|
186
|
+
Description: `Customer (ID: ${newCustomer.CustomerId}) has been created for ${this.AccSystemCode}`,
|
|
187
|
+
EntityType: 'finance_Customer',
|
|
188
|
+
EntityValueBefore: JSON.stringify({}),
|
|
189
|
+
EntityValueAfter: JSON.stringify(newCustomer),
|
|
190
|
+
PerformedById: loginUser.ObjectId,
|
|
191
|
+
PerformedAt: new Date(),
|
|
192
|
+
EntityId: newCustomer.CustomerId,
|
|
193
|
+
};
|
|
194
|
+
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
195
|
+
return customer;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
postJournal(dbTransaction, journalEntry, loginUser) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const debitTransactions = yield journalEntry.DebitTransactions;
|
|
205
|
+
const creditTransactions = yield journalEntry.CreditTransactions;
|
|
206
|
+
try {
|
|
207
|
+
if (creditTransactions.length < 1 || (debitTransactions === null || debitTransactions === void 0 ? void 0 : debitTransactions.length) < 1) {
|
|
208
|
+
throw new Error('There should be at least 1 debit ledger transaction and 1 credit ledger transaction in the journal entry');
|
|
209
|
+
}
|
|
210
|
+
const totalCreditAmount = creditTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.CreditAmount, 0);
|
|
211
|
+
const totalDebitAmount = debitTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.DebitAmount, 0);
|
|
212
|
+
if (totalCreditAmount !== totalDebitAmount) {
|
|
213
|
+
throw new Error('Credit ledger transaction and debit ledger transaction should the same amount');
|
|
214
|
+
}
|
|
215
|
+
const newJournalEntry = yield journalEntry.save(loginUser.ObjectId, dbTransaction);
|
|
216
|
+
for (const ledgerTransaction of debitTransactions) {
|
|
217
|
+
ledgerTransaction.TransactionId = cuid();
|
|
218
|
+
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
219
|
+
yield ledgerTransaction.save(dbTransaction);
|
|
220
|
+
}
|
|
221
|
+
for (const ledgerTransaction of creditTransactions) {
|
|
222
|
+
ledgerTransaction.TransactionId = cuid();
|
|
223
|
+
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
224
|
+
yield ledgerTransaction.save(dbTransaction);
|
|
225
|
+
}
|
|
226
|
+
yield this.AccountingSystem.postJournalEntry(newJournalEntry);
|
|
227
|
+
const payload = {
|
|
228
|
+
Action: 'Create',
|
|
229
|
+
Activity: 'Post Journal Entry',
|
|
230
|
+
Description: `Journal Entry (ID: ${newJournalEntry.JournalEntryId}) has been created`,
|
|
231
|
+
EntityType: 'JournalEntry',
|
|
232
|
+
EntityValueBefore: JSON.stringify({}),
|
|
233
|
+
EntityValueAfter: JSON.stringify(newJournalEntry),
|
|
234
|
+
PerformedById: loginUser.ObjectId,
|
|
235
|
+
PerformedAt: new Date(),
|
|
236
|
+
EntityId: newJournalEntry.JournalEntryId,
|
|
237
|
+
};
|
|
238
|
+
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
createAccount(dbTransaction, account, loginUser) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
try {
|
|
248
|
+
if (!account.AccountType) {
|
|
249
|
+
throw new Error('AccountType is required.');
|
|
250
|
+
}
|
|
251
|
+
let createAccountPayload = {
|
|
252
|
+
Name: account.Name,
|
|
253
|
+
AcctNum: account.AccountNo,
|
|
254
|
+
AccountType: account.AccountType,
|
|
255
|
+
AccountSubType: account.AccountSubtype,
|
|
256
|
+
};
|
|
257
|
+
if (account.isParentAccountExists()) {
|
|
258
|
+
createAccountPayload = Object.assign(Object.assign({}, createAccountPayload), { CurrencyRef: 'MYR', ParentRef: account.ParentAccountNo, SubAccount: true });
|
|
259
|
+
}
|
|
260
|
+
console.log('Finance Company Create Account: Before accSystemAccountId Create');
|
|
261
|
+
const accSystemAccountId = yield this.AccountingSystem.createAccount(createAccountPayload);
|
|
262
|
+
console.log('Finance Company Create Account: After accSystemAccountId Create');
|
|
263
|
+
account.PostedToAccSystemYN = 'Y';
|
|
264
|
+
console.log('Finance Company Create Account: Before new Account Create');
|
|
265
|
+
const newAccount = yield account.save(this.CompanyId, accSystemAccountId, loginUser.ObjectId, dbTransaction);
|
|
266
|
+
console.log('Finance Company Create Account: After new Account Create');
|
|
267
|
+
const payload = {
|
|
268
|
+
Action: 'Create',
|
|
269
|
+
Activity: 'Account Created',
|
|
270
|
+
Description: `Account (ID: ${newAccount.AccountNo}) has been created`,
|
|
271
|
+
EntityType: 'Account',
|
|
272
|
+
EntityValueBefore: JSON.stringify({}),
|
|
273
|
+
EntityValueAfter: JSON.stringify(newAccount),
|
|
274
|
+
PerformedById: loginUser.ObjectId,
|
|
275
|
+
PerformedAt: new Date(),
|
|
276
|
+
EntityId: newAccount.AccountNo,
|
|
277
|
+
};
|
|
278
|
+
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
279
|
+
return account;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
issueInvoice(dbTransaction, invoice, loginUser, customer, dtAccountNo) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
try {
|
|
289
|
+
const duplicateInvoice = yield FinanceCompany._DocumentRepository.findOne({
|
|
290
|
+
where: {
|
|
291
|
+
DocNo: invoice.DocNo,
|
|
292
|
+
},
|
|
293
|
+
transaction: dbTransaction,
|
|
294
|
+
});
|
|
295
|
+
if (duplicateInvoice) {
|
|
296
|
+
throw new Error('Invoice number already exists');
|
|
297
|
+
}
|
|
298
|
+
const documentItems = yield invoice.DocumentItems;
|
|
299
|
+
if (!documentItems.length) {
|
|
300
|
+
throw new Error('Document must have at least 1 document item');
|
|
301
|
+
}
|
|
302
|
+
for (const invoiceItem of documentItems) {
|
|
303
|
+
if (!invoiceItem.CtAccountNo) {
|
|
304
|
+
throw new Error('Each document item should have CtAccountNo provided');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
invoice.DocType = enum_1.DocType.INVOICE;
|
|
308
|
+
let invoiceMedia;
|
|
309
|
+
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
310
|
+
yield this.AccountingSystem.createInvoice(invoice);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
invoiceMedia = yield invoice.generateInvoice(invoice.IssuedById, customer);
|
|
314
|
+
}
|
|
315
|
+
yield FinanceCompany._DocumentRepository.create({
|
|
316
|
+
DocNo: invoice.DocNo,
|
|
317
|
+
DocType: invoice.DocType,
|
|
318
|
+
DocDate: invoice.DocDate,
|
|
319
|
+
CompanyId: invoice.CompanyId,
|
|
320
|
+
Currency: invoice.Currency,
|
|
321
|
+
Amount: invoice.Amount,
|
|
322
|
+
Description: invoice.Description,
|
|
323
|
+
Status: invoice.Status,
|
|
324
|
+
IssuedById: invoice.IssuedById,
|
|
325
|
+
IssuedToId: invoice.IssuedToId,
|
|
326
|
+
IssuedToType: invoice.IssuedToType,
|
|
327
|
+
RelatedObjectId: invoice.RelatedObjectId,
|
|
328
|
+
RelatedObjectType: invoice.RelatedObjectType,
|
|
329
|
+
CreatedById: invoice.CreatedById,
|
|
330
|
+
CreatedAt: new Date(),
|
|
331
|
+
UpdatedById: invoice.UpdatedById,
|
|
332
|
+
UpdatedAt: new Date(),
|
|
333
|
+
DocPDFFileMediaId: invoiceMedia.PDFMedia.MediaId,
|
|
334
|
+
DocHTMLFileMediaId: invoiceMedia.HTMLMedia.MediaId,
|
|
335
|
+
AccSystemRefId: invoice.AccSystemRefId,
|
|
336
|
+
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
337
|
+
PostedById: invoice.PostedById,
|
|
338
|
+
PostedDateTime: new Date(),
|
|
339
|
+
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
340
|
+
}, {
|
|
341
|
+
transaction: dbTransaction,
|
|
342
|
+
});
|
|
343
|
+
for (const documentItem of documentItems) {
|
|
344
|
+
yield FinanceCompany._DocumentItemRepository.create({
|
|
345
|
+
DocumentItemId: cuid(),
|
|
346
|
+
DocNo: invoice.DocNo,
|
|
347
|
+
Name: documentItem.Name,
|
|
348
|
+
NameBM: documentItem.NameBM,
|
|
349
|
+
Description: documentItem.Description,
|
|
350
|
+
ItemId: documentItem.ItemId,
|
|
351
|
+
ItemType: documentItem.ItemType,
|
|
352
|
+
ItemSKU: documentItem.ItemSKU,
|
|
353
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
354
|
+
Currency: documentItem.Currency,
|
|
355
|
+
UnitPrice: documentItem.UnitPrice,
|
|
356
|
+
Quantity: documentItem.Quantity,
|
|
357
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
358
|
+
Amount: documentItem.Amount,
|
|
359
|
+
TaxCode: documentItem.TaxCode,
|
|
360
|
+
TaxAmount: documentItem.TaxAmount,
|
|
361
|
+
TaxRate: documentItem.TaxRate,
|
|
362
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
363
|
+
DtAccountNo: documentItem.DtAccountNo
|
|
364
|
+
? documentItem.DtAccountNo
|
|
365
|
+
: null,
|
|
366
|
+
CtAccountNo: documentItem.CtAccountNo
|
|
367
|
+
? documentItem.CtAccountNo
|
|
368
|
+
: null,
|
|
369
|
+
}, {
|
|
370
|
+
transaction: dbTransaction,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
const transactionDate = new Date();
|
|
374
|
+
const htCreditAccountAmount = new general_1.HashTable();
|
|
375
|
+
const htCreditAccountCurrency = new general_1.HashTable();
|
|
376
|
+
const htCreditAccountPurpose = new general_1.HashTable();
|
|
377
|
+
documentItems.forEach((invoiceItem) => {
|
|
378
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
379
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
380
|
+
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
381
|
+
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
385
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
const savedItems = htCreditAccountAmount.list();
|
|
389
|
+
for (const item of savedItems) {
|
|
390
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
391
|
+
journalEntry.init({
|
|
392
|
+
CompanyId: this.CompanyId,
|
|
393
|
+
Name: 'Issue Invoice ' + invoice.DocNo,
|
|
394
|
+
});
|
|
395
|
+
const creditAmount = item.value[1];
|
|
396
|
+
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
397
|
+
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
398
|
+
const dt = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
399
|
+
if (dtAccountNo) {
|
|
400
|
+
dt.AccountNo = dtAccountNo;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
dt.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
404
|
+
}
|
|
405
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
406
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
407
|
+
dt.Date = transactionDate;
|
|
408
|
+
dt.Description = `${purpose}`;
|
|
409
|
+
dt.Name = `${purpose}`;
|
|
410
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
411
|
+
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
412
|
+
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
413
|
+
const ct = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
414
|
+
ct.AccountNo = item.value[0];
|
|
415
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
416
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
417
|
+
ct.Date = transactionDate;
|
|
418
|
+
ct.Description = customer.FullName;
|
|
419
|
+
ct.Name = customer.FullName;
|
|
420
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
421
|
+
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
422
|
+
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
423
|
+
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
424
|
+
}
|
|
425
|
+
return invoice;
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
console.log('Issue invoice err: ', err);
|
|
429
|
+
throw err;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
issueDebitNote(dbTransaction, loginUser, invoice, customer, dtAccountNo) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
try {
|
|
436
|
+
const duplicateInvoice = yield FinanceCompany._DocumentRepository.findOne({
|
|
437
|
+
where: {
|
|
438
|
+
DocNo: invoice.DocNo,
|
|
439
|
+
},
|
|
440
|
+
transaction: dbTransaction,
|
|
441
|
+
});
|
|
442
|
+
if (duplicateInvoice) {
|
|
443
|
+
throw new Error('Invoice number already exists');
|
|
444
|
+
}
|
|
445
|
+
const documentItems = yield invoice.DocumentItems;
|
|
446
|
+
if (!documentItems.length) {
|
|
447
|
+
throw new Error('Document must have at least 1 document item');
|
|
448
|
+
}
|
|
449
|
+
for (const invoiceItem of documentItems) {
|
|
450
|
+
if (!invoiceItem.CtAccountNo) {
|
|
451
|
+
throw new Error('Each document item should have CtAccountNo provided');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
invoice.DocType = enum_1.DocType.DEBIT_NOTE;
|
|
455
|
+
yield FinanceCompany._DocumentRepository.create({
|
|
456
|
+
DocNo: invoice.DocNo,
|
|
457
|
+
DocType: invoice.DocType,
|
|
458
|
+
DocDate: invoice.DocDate,
|
|
459
|
+
CompanyId: invoice.CompanyId,
|
|
460
|
+
Currency: invoice.Currency,
|
|
461
|
+
Amount: invoice.Amount,
|
|
462
|
+
Description: invoice.Description,
|
|
463
|
+
Status: invoice.Status,
|
|
464
|
+
IssuedById: loginUser.ObjectId,
|
|
465
|
+
IssuedToId: customer.ObjectId,
|
|
466
|
+
IssuedToType: invoice.IssuedToType,
|
|
467
|
+
RelatedObjectId: invoice.RelatedObjectId,
|
|
468
|
+
RelatedObjectType: invoice.RelatedObjectType,
|
|
469
|
+
CreatedById: loginUser.ObjectId,
|
|
470
|
+
CreatedAt: new Date(),
|
|
471
|
+
UpdatedById: loginUser.ObjectId,
|
|
472
|
+
UpdatedAt: new Date(),
|
|
473
|
+
DocPDFFileMediaId: invoice.DocPDFFileMediaId,
|
|
474
|
+
DocHTMLFileMediaId: invoice.DocHTMLFileMediaId,
|
|
475
|
+
AccSystemRefId: invoice.AccSystemRefId,
|
|
476
|
+
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
477
|
+
PostedById: invoice.PostedById,
|
|
478
|
+
PostedDateTime: new Date(),
|
|
479
|
+
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
480
|
+
}, {
|
|
481
|
+
transaction: dbTransaction,
|
|
482
|
+
});
|
|
483
|
+
documentItems.forEach((documentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
yield FinanceCompany._DocumentItemRepository.create({
|
|
485
|
+
DocumentItemId: cuid(),
|
|
486
|
+
DocNo: documentItem.DocNo,
|
|
487
|
+
Name: documentItem.Name,
|
|
488
|
+
NameBM: documentItem.NameBM,
|
|
489
|
+
Description: documentItem.Description,
|
|
490
|
+
ItemId: documentItem.ItemId,
|
|
491
|
+
ItemType: documentItem.ItemType,
|
|
492
|
+
ItemSKU: documentItem.ItemSKU,
|
|
493
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
494
|
+
Currency: documentItem.Currency,
|
|
495
|
+
UnitPrice: documentItem.UnitPrice,
|
|
496
|
+
Quantity: documentItem.Quantity,
|
|
497
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
498
|
+
Amount: documentItem.Amount,
|
|
499
|
+
TaxCode: documentItem.TaxCode,
|
|
500
|
+
TaxAmount: documentItem.TaxAmount,
|
|
501
|
+
TaxRate: documentItem.TaxRate,
|
|
502
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
503
|
+
DtAccountNo: documentItem.DtAccountNo,
|
|
504
|
+
CtAccountNo: documentItem.CtAccountNo,
|
|
505
|
+
}, {
|
|
506
|
+
transaction: dbTransaction,
|
|
507
|
+
});
|
|
508
|
+
}));
|
|
509
|
+
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
510
|
+
yield this.AccountingSystem.createInvoice(invoice);
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
invoice.generateInvoice(loginUser.IDNo, customer);
|
|
514
|
+
}
|
|
515
|
+
const transactionDate = new Date();
|
|
516
|
+
const htCreditAccountAmount = new general_1.HashTable();
|
|
517
|
+
const htCreditAccountCurrency = new general_1.HashTable();
|
|
518
|
+
const htCreditAccountPurpose = new general_1.HashTable();
|
|
519
|
+
documentItems.forEach((invoiceItem) => {
|
|
520
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
521
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
522
|
+
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
523
|
+
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
527
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
const savedItems = htCreditAccountAmount.list();
|
|
531
|
+
for (const item of savedItems) {
|
|
532
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
533
|
+
journalEntry.init({
|
|
534
|
+
CompanyId: this.CompanyId,
|
|
535
|
+
Name: 'issue Invoice ' + invoice.DocNo,
|
|
536
|
+
});
|
|
537
|
+
const creditAmount = item.value[1];
|
|
538
|
+
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
539
|
+
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
540
|
+
const dt = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
541
|
+
if (dtAccountNo) {
|
|
542
|
+
dt.AccountNo = dtAccountNo;
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
dt.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
546
|
+
}
|
|
547
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
548
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
549
|
+
dt.Date = transactionDate;
|
|
550
|
+
dt.Description = `${purpose}`;
|
|
551
|
+
dt.Name = `${purpose}`;
|
|
552
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
553
|
+
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
554
|
+
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
555
|
+
const ct = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
556
|
+
ct.AccountNo = item.value[0];
|
|
557
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
558
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
559
|
+
ct.Date = transactionDate;
|
|
560
|
+
ct.Description = customer.FullName;
|
|
561
|
+
ct.Name = customer.FullName;
|
|
562
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
563
|
+
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
564
|
+
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
565
|
+
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
566
|
+
}
|
|
567
|
+
return invoice;
|
|
568
|
+
}
|
|
569
|
+
catch (err) {
|
|
570
|
+
console.log('Issue debit note err: ', err);
|
|
571
|
+
throw err;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
issueCreditNote(dbTransaction, loginUser, creditNote, customer, ctAccountNo) {
|
|
576
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
577
|
+
try {
|
|
578
|
+
const duplicateCreditNote = yield FinanceCompany._DocumentRepository.findOne({
|
|
579
|
+
where: {
|
|
580
|
+
DocNo: creditNote.DocNo,
|
|
581
|
+
},
|
|
582
|
+
transaction: dbTransaction,
|
|
583
|
+
});
|
|
584
|
+
if (duplicateCreditNote) {
|
|
585
|
+
throw new Error('Invoice number already exists');
|
|
586
|
+
}
|
|
587
|
+
const documentItems = yield creditNote.DocumentItems;
|
|
588
|
+
if (!documentItems.length) {
|
|
589
|
+
throw new Error('Document must have at least 1 document item');
|
|
590
|
+
}
|
|
591
|
+
for (const invoiceItem of documentItems) {
|
|
592
|
+
if (!invoiceItem.CtAccountNo) {
|
|
593
|
+
throw new Error('Each document item should have CtAccountNo provided');
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
creditNote.DocType = enum_1.DocType.DEBIT_NOTE;
|
|
597
|
+
yield FinanceCompany._DocumentRepository.create({
|
|
598
|
+
DocNo: creditNote.DocNo,
|
|
599
|
+
DocType: creditNote.DocType,
|
|
600
|
+
DocDate: creditNote.DocDate,
|
|
601
|
+
CompanyId: creditNote.CompanyId,
|
|
602
|
+
Currency: creditNote.Currency,
|
|
603
|
+
Amount: creditNote.Amount,
|
|
604
|
+
Description: creditNote.Description,
|
|
605
|
+
Status: creditNote.Status,
|
|
606
|
+
IssuedById: loginUser.ObjectId,
|
|
607
|
+
IssuedToId: customer.ObjectId,
|
|
608
|
+
IssuedToType: creditNote.IssuedToType,
|
|
609
|
+
RelatedObjectId: creditNote.RelatedObjectId,
|
|
610
|
+
RelatedObjectType: creditNote.RelatedObjectType,
|
|
611
|
+
CreatedById: loginUser.ObjectId,
|
|
612
|
+
CreatedAt: new Date(),
|
|
613
|
+
UpdatedById: loginUser.ObjectId,
|
|
614
|
+
UpdatedAt: new Date(),
|
|
615
|
+
DocPDFFileMediaId: creditNote.DocPDFFileMediaId,
|
|
616
|
+
DocHTMLFileMediaId: creditNote.DocHTMLFileMediaId,
|
|
617
|
+
AccSystemRefId: creditNote.AccSystemRefId,
|
|
618
|
+
PostedToAccSystemYN: creditNote.PostedToAccSystemYN,
|
|
619
|
+
PostedById: creditNote.PostedById,
|
|
620
|
+
PostedDateTime: new Date(),
|
|
621
|
+
UseAccSystemDocYN: creditNote.UseAccSystemDocYN,
|
|
622
|
+
}, {
|
|
623
|
+
transaction: dbTransaction,
|
|
624
|
+
});
|
|
625
|
+
documentItems.forEach((documentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
626
|
+
yield FinanceCompany._DocumentItemRepository.create({
|
|
627
|
+
DocumentItemId: documentItem.DocumentItemId,
|
|
628
|
+
DocNo: documentItem.DocNo,
|
|
629
|
+
Name: documentItem.Name,
|
|
630
|
+
NameBM: documentItem.NameBM,
|
|
631
|
+
Description: documentItem.Description,
|
|
632
|
+
ItemId: documentItem.ItemId,
|
|
633
|
+
ItemType: documentItem.ItemType,
|
|
634
|
+
ItemSKU: documentItem.ItemSKU,
|
|
635
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
636
|
+
Currency: documentItem.Currency,
|
|
637
|
+
UnitPrice: documentItem.UnitPrice,
|
|
638
|
+
Quantity: documentItem.Quantity,
|
|
639
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
640
|
+
Amount: documentItem.Amount,
|
|
641
|
+
TaxCode: documentItem.TaxCode,
|
|
642
|
+
TaxAmount: documentItem.TaxAmount,
|
|
643
|
+
TaxRate: documentItem.TaxRate,
|
|
644
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
645
|
+
DtAccountNo: documentItem.DtAccountNo,
|
|
646
|
+
CtAccountNo: documentItem.CtAccountNo,
|
|
647
|
+
}, {
|
|
648
|
+
transaction: dbTransaction,
|
|
649
|
+
});
|
|
650
|
+
}));
|
|
651
|
+
if (creditNote.UseAccSystemDocYN === 'Y') {
|
|
652
|
+
yield this.AccountingSystem.createCreditNote(creditNote);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
creditNote.generateCreditNote(loginUser.IDNo, customer);
|
|
656
|
+
}
|
|
657
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
658
|
+
journalEntry.init({
|
|
659
|
+
CompanyId: this.CompanyId,
|
|
660
|
+
Name: 'Issue Debit Note ' + creditNote.DocNo,
|
|
661
|
+
});
|
|
662
|
+
const transactionDate = new Date();
|
|
663
|
+
const creditTransaction = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
664
|
+
if (ctAccountNo) {
|
|
665
|
+
creditTransaction.AccountNo = ctAccountNo;
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
creditTransaction.AccountNo = customer.CustSystemCode + '-AP';
|
|
669
|
+
}
|
|
670
|
+
creditTransaction.Currency = creditNote.Currency;
|
|
671
|
+
creditTransaction.CreditAmount = creditNote.Amount;
|
|
672
|
+
creditTransaction.Date = transactionDate;
|
|
673
|
+
creditTransaction.Description = creditNote.DocNo;
|
|
674
|
+
creditTransaction.Name = creditNote.DocNo;
|
|
675
|
+
creditTransaction.RelatedDocNo = creditNote.DocNo;
|
|
676
|
+
creditTransaction.RelatedObjectId = creditNote.RelatedObjectId;
|
|
677
|
+
creditTransaction.RelatedObjectType = creditNote.RelatedObjectType;
|
|
678
|
+
for (const invoiceItem of documentItems) {
|
|
679
|
+
const itemLedger = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
680
|
+
itemLedger.AccountNo = invoiceItem.CtAccountNo;
|
|
681
|
+
itemLedger.Currency = invoiceItem.Currency;
|
|
682
|
+
itemLedger.DebitAmount = invoiceItem.Amount;
|
|
683
|
+
itemLedger.Date = transactionDate;
|
|
684
|
+
itemLedger.Description = invoiceItem.Description;
|
|
685
|
+
itemLedger.Name = invoiceItem.Name;
|
|
686
|
+
itemLedger.RelatedDocNo = creditNote.DocNo;
|
|
687
|
+
itemLedger.RelatedObjectId = creditNote.RelatedObjectId;
|
|
688
|
+
itemLedger.RelatedObjectType = creditNote.RelatedObjectType;
|
|
689
|
+
}
|
|
690
|
+
this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
691
|
+
const payload = {
|
|
692
|
+
Action: 'Create',
|
|
693
|
+
Activity: 'Issuing a Credit Note Transaction',
|
|
694
|
+
Description: `Credit Transaction (ID: ${creditTransaction.TransactionId}) has been created`,
|
|
695
|
+
EntityType: 'CreditTransaction',
|
|
696
|
+
EntityValueBefore: JSON.stringify({}),
|
|
697
|
+
EntityValueAfter: JSON.stringify(creditTransaction),
|
|
698
|
+
PerformedById: loginUser.ObjectId,
|
|
699
|
+
PerformedAt: transactionDate,
|
|
700
|
+
EntityId: creditTransaction.TransactionId,
|
|
701
|
+
};
|
|
702
|
+
yield axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
703
|
+
return creditNote;
|
|
704
|
+
}
|
|
705
|
+
catch (err) {
|
|
706
|
+
console.log('Issue credit note err: ', err);
|
|
707
|
+
throw err;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
collectPayment(dbTransaction, loginUser, payment, customer, ctAccountNo, receiptNo) {
|
|
712
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
713
|
+
try {
|
|
714
|
+
const paymentItems = yield payment.PaymentItems;
|
|
715
|
+
if (paymentItems.length < 1) {
|
|
716
|
+
throw new Error('Atleast one payment item is required to identify what payment is being paid for.');
|
|
717
|
+
}
|
|
718
|
+
const paymentPaidWithItems = yield payment.PaymentPaidWith;
|
|
719
|
+
if (paymentPaidWithItems.length < 1) {
|
|
720
|
+
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
721
|
+
}
|
|
722
|
+
const receiptDocuments = yield FinanceCompany._DocumentRepository.findAll({
|
|
723
|
+
where: {
|
|
724
|
+
DocType: enum_1.DocType.RECEIPT,
|
|
725
|
+
CompanyId: config.financeCompanies['TXG-FS'].companyId,
|
|
726
|
+
},
|
|
727
|
+
});
|
|
728
|
+
const receipt = new document_1.default(dbTransaction);
|
|
729
|
+
if (receiptNo) {
|
|
730
|
+
receipt.DocNo = receiptNo;
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
|
|
734
|
+
}
|
|
735
|
+
receipt.DocType = enum_1.DocType.RECEIPT;
|
|
736
|
+
receipt.DocDate = new Date();
|
|
737
|
+
receipt.CompanyId = config.financeCompanies['TXG-FS'].companyId;
|
|
738
|
+
receipt.Currency = payment.Currency;
|
|
739
|
+
receipt.Description = 'Payment Received';
|
|
740
|
+
receipt.IssuedById = loginUser.ObjectId;
|
|
741
|
+
receipt.IssuedToId = customer.CustomerId;
|
|
742
|
+
receipt.IssuedToType = (0, typeof_1.type)(customer);
|
|
743
|
+
receipt.RelatedObjectId = payment.RelatedObjectId;
|
|
744
|
+
receipt.RelatedObjectType = payment.RelatedObjectType;
|
|
745
|
+
receipt.UseAccSystemDocYN = 'N';
|
|
746
|
+
receipt.CreatedById = loginUser.ObjectId;
|
|
747
|
+
receipt.UpdatedById = loginUser.ObjectId;
|
|
748
|
+
for (const paymentItem of paymentItems) {
|
|
749
|
+
const receiptItem = new document_item_1.default(dbTransaction, receipt);
|
|
750
|
+
receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
751
|
+
receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
752
|
+
receiptItem.Description = '-';
|
|
753
|
+
receiptItem.Currency = paymentItem.Currency;
|
|
754
|
+
receiptItem.UnitPrice = paymentItem.Amount;
|
|
755
|
+
receiptItem.Quantity = 1;
|
|
756
|
+
receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
|
|
757
|
+
receiptItem.ItemId = receipt.DocNo;
|
|
758
|
+
receiptItem.ItemType = (0, typeof_1.type)(payment);
|
|
759
|
+
receiptItem.CtAccountNo = ctAccountNo;
|
|
760
|
+
yield receipt.newDocumentItem(receiptItem);
|
|
761
|
+
}
|
|
762
|
+
const receiptMedia = yield receipt.generateReceipt(receipt.IssuedById, customer);
|
|
763
|
+
yield FinanceCompany._DocumentRepository.create({
|
|
764
|
+
DocNo: receipt.DocNo,
|
|
765
|
+
DocType: receipt.DocType,
|
|
766
|
+
DocDate: receipt.DocDate,
|
|
767
|
+
CompanyId: receipt.CompanyId,
|
|
768
|
+
Currency: receipt.Currency,
|
|
769
|
+
Amount: receipt.Amount,
|
|
770
|
+
Description: receipt.Description,
|
|
771
|
+
Status: receipt.Status,
|
|
772
|
+
IssuedById: receipt.IssuedById,
|
|
773
|
+
IssuedToId: receipt.IssuedToId,
|
|
774
|
+
IssuedToType: receipt.IssuedToType,
|
|
775
|
+
RelatedObjectId: receipt.RelatedObjectId,
|
|
776
|
+
RelatedObjectType: receipt.RelatedObjectType,
|
|
777
|
+
CreatedById: receipt.CreatedById,
|
|
778
|
+
CreatedAt: new Date(),
|
|
779
|
+
UpdatedById: receipt.UpdatedById,
|
|
780
|
+
UpdatedAt: new Date(),
|
|
781
|
+
DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
|
|
782
|
+
DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
|
|
783
|
+
AccSystemRefId: receipt.AccSystemRefId,
|
|
784
|
+
PostedToAccSystemYN: receipt.PostedToAccSystemYN,
|
|
785
|
+
PostedById: receipt.PostedById,
|
|
786
|
+
PostedDateTime: new Date(),
|
|
787
|
+
UseAccSystemDocYN: receipt.UseAccSystemDocYN,
|
|
788
|
+
}, {
|
|
789
|
+
transaction: dbTransaction,
|
|
790
|
+
});
|
|
791
|
+
const receiptItems = yield receipt.DocumentItems;
|
|
792
|
+
for (const receiptItem of receiptItems) {
|
|
793
|
+
yield FinanceCompany._DocumentItemRepository.create({
|
|
794
|
+
DocumentItemId: cuid(),
|
|
795
|
+
DocNo: receipt.DocNo,
|
|
796
|
+
Name: receiptItem.Name,
|
|
797
|
+
NameBM: receiptItem.NameBM,
|
|
798
|
+
Description: receiptItem.Description,
|
|
799
|
+
ItemId: receiptItem.ItemId,
|
|
800
|
+
ItemType: receiptItem.ItemType,
|
|
801
|
+
ItemSKU: receiptItem.ItemSKU,
|
|
802
|
+
ItemSerialNo: receiptItem.ItemSerialNo,
|
|
803
|
+
Currency: receiptItem.Currency,
|
|
804
|
+
UnitPrice: receiptItem.UnitPrice,
|
|
805
|
+
Quantity: receiptItem.Quantity,
|
|
806
|
+
QuantityUOM: receiptItem.QuantityUOM,
|
|
807
|
+
Amount: receiptItem.Amount,
|
|
808
|
+
TaxCode: receiptItem.TaxCode,
|
|
809
|
+
TaxAmount: receiptItem.TaxAmount,
|
|
810
|
+
TaxRate: receiptItem.TaxRate,
|
|
811
|
+
TaxInclusiveYN: receiptItem.TaxInclusiveYN,
|
|
812
|
+
DtAccountNo: receiptItem.DtAccountNo
|
|
813
|
+
? receiptItem.DtAccountNo
|
|
814
|
+
: null,
|
|
815
|
+
CtAccountNo: receiptItem.CtAccountNo
|
|
816
|
+
? receiptItem.CtAccountNo
|
|
817
|
+
: null,
|
|
818
|
+
}, {
|
|
819
|
+
transaction: dbTransaction,
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
payment.PaymentId = cuid();
|
|
823
|
+
payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
|
|
824
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
825
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
826
|
+
payment.ReceiptDocNo = receipt.DocNo;
|
|
827
|
+
yield FinanceCompany._PaymentRepository.create({
|
|
828
|
+
PaymentId: payment.PaymentId,
|
|
829
|
+
PaymentType: payment.PaymentType,
|
|
830
|
+
PaymentDate: payment.PaymentDate,
|
|
831
|
+
Description: payment.Description,
|
|
832
|
+
Currency: payment.Currency,
|
|
833
|
+
Amount: payment.Amount,
|
|
834
|
+
Status: enum_1.PaymentStatus.SUCCESSFUL,
|
|
835
|
+
PostedToAccSystemYN: 'N',
|
|
836
|
+
ReceivedBy: payment.ReceivedBy,
|
|
837
|
+
IssuedBy: payment.IssuedBy,
|
|
838
|
+
Remarks: payment.Remarks,
|
|
839
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
840
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
841
|
+
ReceiptDocNo: payment.ReceiptDocNo,
|
|
842
|
+
UpdatedAt: new Date(),
|
|
843
|
+
UpdatedBy: loginUser.ObjectId,
|
|
844
|
+
CreatedAt: new Date(),
|
|
845
|
+
CreatedBy: loginUser.ObjectId,
|
|
846
|
+
}, { transaction: dbTransaction });
|
|
847
|
+
for (const paymentItem of paymentItems) {
|
|
848
|
+
yield FinanceCompany._PaymentItemRepository.create({
|
|
849
|
+
PaymentId: payment.PaymentId,
|
|
850
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
851
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
852
|
+
Currency: paymentItem.Currency,
|
|
853
|
+
Amount: paymentItem.Amount,
|
|
854
|
+
Name: paymentItem.Name,
|
|
855
|
+
Description: paymentItem.Description,
|
|
856
|
+
}, { transaction: dbTransaction });
|
|
857
|
+
yield paymentItem.paid(dbTransaction);
|
|
858
|
+
}
|
|
859
|
+
for (const paymentPaidWithItem of paymentPaidWithItems) {
|
|
860
|
+
yield FinanceCompany._PaymentPaidWithRepository.create({
|
|
861
|
+
PaymentId: payment.PaymentId,
|
|
862
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
863
|
+
Currency: paymentPaidWithItem.Currency,
|
|
864
|
+
Amount: paymentPaidWithItem.Amount,
|
|
865
|
+
Status: paymentPaidWithItem.Status,
|
|
866
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
867
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
868
|
+
RefName: paymentPaidWithItem.RefName,
|
|
869
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
870
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
871
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
872
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
873
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
874
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
875
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
876
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
877
|
+
}, { transaction: dbTransaction });
|
|
878
|
+
}
|
|
879
|
+
const transactionDate = new Date();
|
|
880
|
+
for (const paymentPaidWith of paymentPaidWithItems) {
|
|
881
|
+
let paymentMethodType;
|
|
882
|
+
try {
|
|
883
|
+
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
|
|
884
|
+
}
|
|
885
|
+
catch (error) {
|
|
886
|
+
if (error instanceof general_1.RecordNotFoundError) {
|
|
887
|
+
throw new Error('Invalid Payment Method Type Id');
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
throw error;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
894
|
+
journalEntry.init({
|
|
895
|
+
CompanyId: this.CompanyId,
|
|
896
|
+
Name: 'Collect-payments for ' + payment.PaymentId,
|
|
897
|
+
});
|
|
898
|
+
const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
899
|
+
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
900
|
+
debitLT.Currency = paymentPaidWith.Currency;
|
|
901
|
+
debitLT.DebitAmount = paymentPaidWith.Amount;
|
|
902
|
+
debitLT.Date = transactionDate;
|
|
903
|
+
debitLT.Description = 'Payment Received';
|
|
904
|
+
debitLT.Name = customer.FullName;
|
|
905
|
+
debitLT.RelatedObjectId = receipt.RelatedObjectId;
|
|
906
|
+
debitLT.RelatedObjectType = payment.RelatedObjectType;
|
|
907
|
+
debitLT.RelatedPaymentId = payment.PaymentId;
|
|
908
|
+
const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
909
|
+
if (ctAccountNo) {
|
|
910
|
+
creditLT.AccountNo = ctAccountNo;
|
|
911
|
+
}
|
|
912
|
+
else {
|
|
913
|
+
creditLT.AccountNo = (yield customer.AccountReceivable).AccountNo;
|
|
914
|
+
}
|
|
915
|
+
creditLT.Currency = paymentPaidWith.Currency;
|
|
916
|
+
creditLT.CreditAmount = paymentPaidWith.Amount;
|
|
917
|
+
creditLT.Date = transactionDate;
|
|
918
|
+
creditLT.Description = 'Payment Received';
|
|
919
|
+
creditLT.Name = paymentMethodType.Name;
|
|
920
|
+
creditLT.RelatedObjectId = receipt.RelatedObjectId;
|
|
921
|
+
creditLT.RelatedObjectType = payment.RelatedObjectType;
|
|
922
|
+
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
923
|
+
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
924
|
+
}
|
|
925
|
+
return payment;
|
|
926
|
+
}
|
|
927
|
+
catch (error) {
|
|
928
|
+
throw error;
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
makePayment(dbTransaction, loginUser, payment, customer, dtAccountNo) {
|
|
933
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
934
|
+
let paymentMethodType;
|
|
935
|
+
try {
|
|
936
|
+
const paymentPaidWith = yield payment.PaymentPaidWith;
|
|
937
|
+
if (paymentPaidWith.length < 1) {
|
|
938
|
+
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
939
|
+
}
|
|
940
|
+
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith[0].MethodTypeId);
|
|
941
|
+
const paymentItems = yield payment.PaymentItems;
|
|
942
|
+
if (paymentItems.length < 1) {
|
|
943
|
+
throw new Error('Atleast one payment item is required to identify what payment is being paid for');
|
|
944
|
+
}
|
|
945
|
+
payment.PaymentId = cuid();
|
|
946
|
+
payment.PaymentType = enum_1.PaymentType.PAYOUT;
|
|
947
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
948
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
949
|
+
yield FinanceCompany._PaymentRepository.create({
|
|
950
|
+
PaymentId: payment.PaymentId,
|
|
951
|
+
PaymentType: payment.PaymentType,
|
|
952
|
+
PaymentDate: payment.PaymentDate,
|
|
953
|
+
Description: payment.Description,
|
|
954
|
+
Currency: payment.Currency,
|
|
955
|
+
ReceivedBy: payment.ReceivedBy,
|
|
956
|
+
IssuedBy: payment.IssuedBy,
|
|
957
|
+
Remarks: payment.Remarks,
|
|
958
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
959
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
960
|
+
Amount: payment.Amount,
|
|
961
|
+
Status: enum_1.PaymentStatus.SUCCESSFUL,
|
|
962
|
+
PostedToAccSystemYN: 'N',
|
|
963
|
+
UpdatedAt: new Date(),
|
|
964
|
+
UpdatedBy: loginUser.ObjectId,
|
|
965
|
+
CreatedAt: new Date(),
|
|
966
|
+
CreatedBy: loginUser.ObjectId,
|
|
967
|
+
}, { transaction: dbTransaction });
|
|
968
|
+
paymentItems.forEach((paymentItem) => __awaiter(this, void 0, void 0, function* () {
|
|
969
|
+
yield FinanceCompany._PaymentItemRepository.create({
|
|
970
|
+
PaymentId: payment.PaymentId,
|
|
971
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
972
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
973
|
+
Currency: paymentItem.Currency,
|
|
974
|
+
Amount: paymentItem.Amount,
|
|
975
|
+
Name: paymentItem.Name,
|
|
976
|
+
Description: paymentItem.Description,
|
|
977
|
+
}, { transaction: dbTransaction });
|
|
978
|
+
yield paymentItem.paid(dbTransaction);
|
|
979
|
+
}));
|
|
980
|
+
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
981
|
+
yield FinanceCompany._PaymentPaidWithRepository.create({
|
|
982
|
+
PaymentId: payment.PaymentId,
|
|
983
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
984
|
+
Currency: paymentPaidWithItem.Currency,
|
|
985
|
+
Amount: paymentPaidWithItem.Amount,
|
|
986
|
+
Status: paymentPaidWithItem.Status,
|
|
987
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
988
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
989
|
+
RefName: paymentPaidWithItem.RefName,
|
|
990
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
991
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
992
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
993
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
994
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
995
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
996
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
997
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
998
|
+
}, { transaction: dbTransaction });
|
|
999
|
+
}
|
|
1000
|
+
const transactionDate = new Date();
|
|
1001
|
+
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
1002
|
+
try {
|
|
1003
|
+
paymentMethodType = yield payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
|
|
1004
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
1005
|
+
journalEntry.init({
|
|
1006
|
+
CompanyId: this.CompanyId,
|
|
1007
|
+
Name: 'Make Payment for ' + payment.PaymentId,
|
|
1008
|
+
});
|
|
1009
|
+
const creditLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
1010
|
+
creditLT.AccountNo = paymentMethodType.AccountNo;
|
|
1011
|
+
creditLT.Currency = paymentPaidWithItem.Currency;
|
|
1012
|
+
creditLT.CreditAmount = paymentPaidWithItem.Amount;
|
|
1013
|
+
creditLT.Date = transactionDate;
|
|
1014
|
+
creditLT.Description = customer.FullName;
|
|
1015
|
+
creditLT.Name = customer.FullName;
|
|
1016
|
+
creditLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1017
|
+
creditLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1018
|
+
const debitLT = yield journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
1019
|
+
if (dtAccountNo) {
|
|
1020
|
+
debitLT.AccountNo = dtAccountNo;
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
debitLT.AccountNo = (yield customer.AccountPayable).AccountNo;
|
|
1024
|
+
}
|
|
1025
|
+
debitLT.Currency = paymentPaidWithItem.Currency;
|
|
1026
|
+
debitLT.DebitAmount = paymentPaidWithItem.Amount;
|
|
1027
|
+
debitLT.Date = transactionDate;
|
|
1028
|
+
debitLT.Description = paymentMethodType.Name;
|
|
1029
|
+
debitLT.Name = paymentMethodType.Name;
|
|
1030
|
+
debitLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1031
|
+
debitLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1032
|
+
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1033
|
+
}
|
|
1034
|
+
catch (error) {
|
|
1035
|
+
if (error instanceof general_1.RecordNotFoundError) {
|
|
1036
|
+
throw new Error('Invalid Payment Method Type Id');
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
throw error;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return payment;
|
|
1044
|
+
}
|
|
1045
|
+
catch (error) {
|
|
1046
|
+
if (error instanceof general_1.RecordNotFoundError) {
|
|
1047
|
+
throw new Error('Invalid PaymentMethodType id');
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
throw error;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
get PaymentMethods() {
|
|
1056
|
+
return new Promise((resolve, reject) => {
|
|
1057
|
+
if (this.CompanyId !== 'New') {
|
|
1058
|
+
FinanceCompany._PaymentMethodRepository
|
|
1059
|
+
.findAll({
|
|
1060
|
+
where: {
|
|
1061
|
+
CompanyId: this.CompanyId,
|
|
1062
|
+
},
|
|
1063
|
+
transaction: this._DbTransaction,
|
|
1064
|
+
})
|
|
1065
|
+
.then((paymentMethod) => {
|
|
1066
|
+
const paymentMethodObjects = paymentMethod.map((paymentMethodData) => {
|
|
1067
|
+
return new Promise((resolve, reject) => {
|
|
1068
|
+
FinanceCompany._PaymentMethodTypeRepository
|
|
1069
|
+
.findAll({
|
|
1070
|
+
where: {
|
|
1071
|
+
MethodId: paymentMethodData.MethodId,
|
|
1072
|
+
},
|
|
1073
|
+
transaction: this._DbTransaction,
|
|
1074
|
+
raw: true,
|
|
1075
|
+
})
|
|
1076
|
+
.then((paymentMethodTypes) => {
|
|
1077
|
+
const paymentMethodObjects = Object.assign(Object.assign({}, paymentMethodData.get({ plain: true })), { Types: paymentMethodTypes });
|
|
1078
|
+
resolve(paymentMethodObjects);
|
|
1079
|
+
})
|
|
1080
|
+
.catch((err) => {
|
|
1081
|
+
reject(err);
|
|
1082
|
+
});
|
|
1083
|
+
}).then((paymentMethods) => paymentMethods);
|
|
1084
|
+
});
|
|
1085
|
+
return Promise.all(paymentMethodObjects);
|
|
1086
|
+
})
|
|
1087
|
+
.then((paymentMethodObjects) => {
|
|
1088
|
+
this._PaymentMethods = paymentMethodObjects;
|
|
1089
|
+
resolve(this._PaymentMethods);
|
|
1090
|
+
})
|
|
1091
|
+
.catch((err) => {
|
|
1092
|
+
reject(err);
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
else {
|
|
1096
|
+
resolve(this._PaymentMethods);
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
LoadPaymentMethods() {
|
|
1101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1102
|
+
const { companyId, paymentMethods } = config.financeCompanies['TXG-FS'];
|
|
1103
|
+
const paymentMethod = new payment_method_1.default();
|
|
1104
|
+
for (const method in paymentMethods) {
|
|
1105
|
+
const paymentMethodData = yield FinanceCompany._PaymentMethodRepository.findOne({
|
|
1106
|
+
where: {
|
|
1107
|
+
MethodId: paymentMethods[method].id,
|
|
1108
|
+
Name: paymentMethods[method].name,
|
|
1109
|
+
},
|
|
1110
|
+
});
|
|
1111
|
+
if (!paymentMethodData) {
|
|
1112
|
+
const newPaymentMethod = yield FinanceCompany._PaymentMethodRepository.create({
|
|
1113
|
+
MethodId: paymentMethods[method].id,
|
|
1114
|
+
Name: paymentMethods[method].name,
|
|
1115
|
+
CompanyId: companyId,
|
|
1116
|
+
});
|
|
1117
|
+
this._PaymentMethods.push(newPaymentMethod);
|
|
1118
|
+
}
|
|
1119
|
+
this._PaymentMethods.push(paymentMethodData);
|
|
1120
|
+
}
|
|
1121
|
+
this._PaymentMethods.forEach((item) => __awaiter(this, void 0, void 0, function* () {
|
|
1122
|
+
var _a, _b;
|
|
1123
|
+
const p = item === null || item === void 0 ? void 0 : item.get({ plain: true });
|
|
1124
|
+
for (const method in paymentMethods) {
|
|
1125
|
+
if (!p) {
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
if (p.MethodId === ((_a = paymentMethods[method]) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1129
|
+
const paymentMethodTypeData = yield FinanceCompany._PaymentMethodTypeRepository.findOne({
|
|
1130
|
+
where: {
|
|
1131
|
+
MethodId: p.MethodId,
|
|
1132
|
+
},
|
|
1133
|
+
});
|
|
1134
|
+
if (!paymentMethodTypeData) {
|
|
1135
|
+
const configPaymentMethodTypes = (_b = paymentMethods[method]) === null || _b === void 0 ? void 0 : _b.types;
|
|
1136
|
+
for (const methodType in configPaymentMethodTypes) {
|
|
1137
|
+
const accountData = yield FinanceCompany._AccountRepository.findOne({
|
|
1138
|
+
where: {
|
|
1139
|
+
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1140
|
+
},
|
|
1141
|
+
});
|
|
1142
|
+
if (!accountData) {
|
|
1143
|
+
const accountPayload = {
|
|
1144
|
+
CompanyId: companyId,
|
|
1145
|
+
Name: configPaymentMethodTypes[methodType].name,
|
|
1146
|
+
AccountType: 'PaymentMethod',
|
|
1147
|
+
CreatedAt: new Date(),
|
|
1148
|
+
CreatedById: 'System',
|
|
1149
|
+
AccSystemRefId: 'REF',
|
|
1150
|
+
PostedToAccSystemYN: 'N',
|
|
1151
|
+
};
|
|
1152
|
+
try {
|
|
1153
|
+
yield FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType].accountNo }, accountPayload));
|
|
1154
|
+
yield FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType]
|
|
1155
|
+
.processingFeeAccountNo }, accountPayload));
|
|
1156
|
+
}
|
|
1157
|
+
catch (err) { }
|
|
1158
|
+
}
|
|
1159
|
+
const paymentMethodTypePayload = {
|
|
1160
|
+
MethodId: p.MethodId,
|
|
1161
|
+
MethodTypeId: configPaymentMethodTypes[methodType].id,
|
|
1162
|
+
Name: configPaymentMethodTypes[methodType].name,
|
|
1163
|
+
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1164
|
+
ProcessingFeeRate: configPaymentMethodTypes[methodType].processingFeeRate,
|
|
1165
|
+
ProcessingFeeAccountNo: configPaymentMethodTypes[methodType].processingFeeAccountNo,
|
|
1166
|
+
};
|
|
1167
|
+
try {
|
|
1168
|
+
yield paymentMethod.newPaymentMethodType(paymentMethodTypePayload);
|
|
1169
|
+
}
|
|
1170
|
+
catch (err) { }
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}));
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
exports.default = FinanceCompany;
|
|
1180
|
+
FinanceCompany._htFinanceCompanyIds = new general_1.HashTable();
|
|
1181
|
+
FinanceCompany._htFinanceCompanies = new general_1.HashTable();
|
|
1182
|
+
FinanceCompany._financeCompanyRepository = new finance_company_repository_1.FinanceCompanyRepository();
|
|
1183
|
+
FinanceCompany._PaymentRepository = new payment_repository_1.PaymentRepository();
|
|
1184
|
+
FinanceCompany._PaymentItemRepository = new payment_item_repository_1.PaymentItemRepository();
|
|
1185
|
+
FinanceCompany._PaymentPaidWithRepository = new payment_paid_with_repository_1.PaymentPaidWithRepository();
|
|
1186
|
+
FinanceCompany._PaymentMethodRepository = new payment_method_repository_1.PaymentMethodRepository();
|
|
1187
|
+
FinanceCompany._PaymentMethodTypeRepository = new payment_method_type_repository_1.PaymentMethodTypeRepository();
|
|
1188
|
+
FinanceCompany._DocumentRepository = new document_repository_1.DocumentRepository();
|
|
1189
|
+
FinanceCompany._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
1190
|
+
FinanceCompany._FinanceCustomerRepository = new finance_customer_repository_1.FinanceCustomerRepository();
|
|
1191
|
+
FinanceCompany._LedgerTransactionRepository = new ledger_transaction_repository_1.LedgerTransactionRepository();
|
|
1192
|
+
FinanceCompany._AccountRepository = new account_repository_1.AccountRepository();
|
|
1193
1193
|
//# sourceMappingURL=finance-company.js.map
|