@tomei/finance 0.6.36 → 0.6.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/finance-company/finance-company.js +6 -6
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/models/payment.entity.d.ts +2 -0
- package/dist/models/payment.entity.js +5 -0
- package/dist/models/payment.entity.js.map +1 -1
- package/dist/payment/payment.d.ts +2 -2
- package/dist/payment/payment.js +58 -42
- package/dist/payment/payment.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/finance-company/finance-company.ts +6 -6
- package/src/models/payment.entity.ts +4 -0
- package/src/payment/payment.ts +68 -57
package/package.json
CHANGED
|
@@ -1157,7 +1157,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1157
1157
|
): Promise<Payment> {
|
|
1158
1158
|
try {
|
|
1159
1159
|
/*validation 1: Make sure that the payment has at least 1 payment item*/
|
|
1160
|
-
const paymentItems = await payment.
|
|
1160
|
+
const paymentItems = await payment.getPaymentItems();
|
|
1161
1161
|
if (paymentItems.length < 1) {
|
|
1162
1162
|
throw new Error(
|
|
1163
1163
|
'Atleast one payment item is required to identify what payment is being paid for.',
|
|
@@ -1165,7 +1165,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
1167
|
/*validation 2: Make sure that the payment has at least 1 payment method*/
|
|
1168
|
-
const paymentPaidWithItems = await payment.
|
|
1168
|
+
const paymentPaidWithItems = await payment.getPaymentPaidWith();
|
|
1169
1169
|
if (paymentPaidWithItems.length < 1) {
|
|
1170
1170
|
throw new Error(
|
|
1171
1171
|
'Atleast one payment paid with item is required to identify how the payment was made.',
|
|
@@ -1452,7 +1452,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1452
1452
|
): Promise<Payment> {
|
|
1453
1453
|
let paymentMethodType: PaymentMethodType;
|
|
1454
1454
|
try {
|
|
1455
|
-
const paymentPaidWith = await payment.
|
|
1455
|
+
const paymentPaidWith = await payment.getPaymentPaidWith();
|
|
1456
1456
|
if (paymentPaidWith.length < 1) {
|
|
1457
1457
|
throw new Error(
|
|
1458
1458
|
'Atleast one payment paid with item is required to identify how the payment was made.',
|
|
@@ -1463,7 +1463,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1463
1463
|
paymentPaidWith[0].MethodTypeId,
|
|
1464
1464
|
);
|
|
1465
1465
|
|
|
1466
|
-
const paymentItems = await payment.
|
|
1466
|
+
const paymentItems = await payment.getPaymentItems();
|
|
1467
1467
|
if (paymentItems.length < 1) {
|
|
1468
1468
|
throw new Error(
|
|
1469
1469
|
'Atleast one payment item is required to identify what payment is being paid for',
|
|
@@ -1892,7 +1892,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1892
1892
|
|
|
1893
1893
|
//Part 2: Validation
|
|
1894
1894
|
//Make sure that the payment has at least 1 payment item
|
|
1895
|
-
const paymentItems = await payment.
|
|
1895
|
+
const paymentItems = await payment.getPaymentItems();
|
|
1896
1896
|
if (paymentItems.length < 1) {
|
|
1897
1897
|
throw new Error(
|
|
1898
1898
|
'Atleast one payment item is required to identify what payment is being paid for.',
|
|
@@ -1900,7 +1900,7 @@ export default class FinanceCompany extends ObjectBase {
|
|
|
1900
1900
|
}
|
|
1901
1901
|
|
|
1902
1902
|
//Make sure that the payment has at least 1 payment method
|
|
1903
|
-
const paymentPaidWithItems = await payment.
|
|
1903
|
+
const paymentPaidWithItems = await payment.getPaymentPaidWith();
|
|
1904
1904
|
if (paymentPaidWithItems.length < 1) {
|
|
1905
1905
|
throw new Error(
|
|
1906
1906
|
'Atleast one payment paid with item is required to identify how the payment was made.',
|
|
@@ -12,6 +12,7 @@ import { ForeignKey } from 'sequelize-typescript/dist/associations/foreign-key/f
|
|
|
12
12
|
import { PaymentType, PaymentStatus } from '../enum';
|
|
13
13
|
import DocumentModel from './document.entity';
|
|
14
14
|
import PaymentItemModel from './payment-item.entity';
|
|
15
|
+
import PaymentPaidWithModel from './payment-paid-with.entity';
|
|
15
16
|
|
|
16
17
|
@Table({
|
|
17
18
|
tableName: 'finance_Payment',
|
|
@@ -156,6 +157,9 @@ export default class PaymentModel extends Model {
|
|
|
156
157
|
@HasMany(() => PaymentItemModel)
|
|
157
158
|
PaymentItems: PaymentItemModel[];
|
|
158
159
|
|
|
160
|
+
@HasMany(() => PaymentPaidWithModel)
|
|
161
|
+
PaymentPaidWiths: PaymentPaidWithModel[];
|
|
162
|
+
|
|
159
163
|
@BelongsTo(() => DocumentModel)
|
|
160
164
|
Document: DocumentModel;
|
|
161
165
|
}
|
package/src/payment/payment.ts
CHANGED
|
@@ -123,75 +123,86 @@ export default class Payment extends AccountSystemEntity {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
async getPaymentItems(): Promise<PaymentItem[]> {
|
|
127
|
+
try {
|
|
128
128
|
if (this.PaymentId !== 'New') {
|
|
129
|
-
Payment._PaymentItemRepository
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
const paymentItems = await Payment._PaymentItemRepository.findAll({
|
|
130
|
+
where: {
|
|
131
|
+
PaymentId: this.PaymentId,
|
|
132
|
+
},
|
|
133
|
+
transaction: this._DbTransaction,
|
|
134
|
+
});
|
|
135
|
+
const paymentItemObjects = paymentItems.map((paymentItem) => {
|
|
136
|
+
const pi = new PaymentItem(
|
|
137
|
+
new Payment(this._DbTransaction, paymentItem.PaymentId),
|
|
138
|
+
{
|
|
139
|
+
ObjectId: this.ObjectId,
|
|
140
|
+
ObjectName: this.ObjectName,
|
|
141
|
+
TableName: this.TableName,
|
|
133
142
|
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
})
|
|
149
|
-
.then((paymentItemObjects) => {
|
|
150
|
-
this._PaymentItems = paymentItemObjects;
|
|
151
|
-
resolve(this._PaymentItems);
|
|
152
|
-
})
|
|
153
|
-
.catch((err) => {
|
|
154
|
-
reject(err);
|
|
155
|
-
});
|
|
143
|
+
);
|
|
144
|
+
pi.PayForObjectType = paymentItem.PayForObjectType;
|
|
145
|
+
pi.PayForObjectId = paymentItem.PayForObjectId;
|
|
146
|
+
pi.Currency = paymentItem.Currency;
|
|
147
|
+
pi.Amount = paymentItem.Amount;
|
|
148
|
+
pi.Name = paymentItem.Name;
|
|
149
|
+
pi.Description = paymentItem.Description;
|
|
150
|
+
|
|
151
|
+
return pi;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
this._PaymentItems = paymentItemObjects;
|
|
155
|
+
} else {
|
|
156
|
+
return this._PaymentItems;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
async getPaymentPaidWith(): Promise<PaymentPaidWith[]> {
|
|
164
|
+
try {
|
|
163
165
|
if (this.PaymentId !== 'New') {
|
|
164
|
-
|
|
165
|
-
.findAll({
|
|
166
|
+
const paymentPaidWithItems =
|
|
167
|
+
await Payment._PaymentPaidWithRepository.findAll({
|
|
166
168
|
where: {
|
|
167
169
|
PaymentId: this.PaymentId,
|
|
168
170
|
},
|
|
169
171
|
transaction: this._DbTransaction,
|
|
170
|
-
})
|
|
171
|
-
.then((paymentPaidWithItems) => {
|
|
172
|
-
const paymentPaidWithObjects = paymentPaidWithItems.map(
|
|
173
|
-
(paymentPaidWithItem) => {
|
|
174
|
-
new PaymentPaidWith(
|
|
175
|
-
new Payment(
|
|
176
|
-
this._DbTransaction,
|
|
177
|
-
paymentPaidWithItem.PaymentId,
|
|
178
|
-
),
|
|
179
|
-
paymentPaidWithItem.MethodTypeId,
|
|
180
|
-
);
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
return Promise.all(paymentPaidWithObjects);
|
|
184
|
-
})
|
|
185
|
-
.then((paymentPaidWithObjects) => {
|
|
186
|
-
this._PaymentPaidWith = paymentPaidWithObjects;
|
|
187
|
-
resolve(this._PaymentPaidWith);
|
|
188
|
-
})
|
|
189
|
-
.catch((err) => {
|
|
190
|
-
reject(err);
|
|
191
172
|
});
|
|
173
|
+
const paymentPaidWithObjects = paymentPaidWithItems.map(
|
|
174
|
+
(paymentPaidWithItem) => {
|
|
175
|
+
const ppw = new PaymentPaidWith(
|
|
176
|
+
new Payment(this._DbTransaction, paymentPaidWithItem.PaymentId),
|
|
177
|
+
paymentPaidWithItem.MethodTypeId,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
ppw.Currency = paymentPaidWithItem.Currency;
|
|
181
|
+
ppw.Amount = paymentPaidWithItem.Amount;
|
|
182
|
+
ppw.Status = paymentPaidWithItem.Status;
|
|
183
|
+
ppw.TransactionId = paymentPaidWithItem.TransactionId;
|
|
184
|
+
ppw.RefBank = paymentPaidWithItem.RefBank;
|
|
185
|
+
ppw.RefName = paymentPaidWithItem.RefName;
|
|
186
|
+
ppw.RefNo = paymentPaidWithItem.RefNo;
|
|
187
|
+
ppw.RefOther1 = paymentPaidWithItem.RefOther1;
|
|
188
|
+
ppw.RefOther2 = paymentPaidWithItem.RefOther2;
|
|
189
|
+
ppw.RefOther3 = paymentPaidWithItem.RefOther3;
|
|
190
|
+
ppw.RefOther4 = paymentPaidWithItem.RefOther4;
|
|
191
|
+
ppw.RefOther5 = paymentPaidWithItem.RefOther5;
|
|
192
|
+
ppw.Remarks = paymentPaidWithItem.Remarks;
|
|
193
|
+
ppw.PaymentMediaId = paymentPaidWithItem.PaymentMediaId;
|
|
194
|
+
|
|
195
|
+
return ppw;
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
this._PaymentPaidWith = paymentPaidWithObjects;
|
|
200
|
+
} else {
|
|
201
|
+
return this._PaymentPaidWith;
|
|
192
202
|
}
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
195
206
|
}
|
|
196
207
|
|
|
197
208
|
newPaymentItem(objectBeingPaidFor: ObjectBase): PaymentItem {
|