@react-pakistan/util-functions 1.23.54 → 1.23.56
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.
|
@@ -97,10 +97,8 @@ var postPayments = function (_a) { return __awaiter(void 0, [_a], void 0, functi
|
|
|
97
97
|
}); };
|
|
98
98
|
exports.postPayments = postPayments;
|
|
99
99
|
var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
100
|
-
var invoice, allPaymentsForInvoice,
|
|
101
|
-
var amount = _b.amount, attachment = _b.attachment,
|
|
102
|
-
// createdAt,
|
|
103
|
-
currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, mode = _b.mode, paymentType = _b.paymentType, prisma = _b.prisma, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
|
|
100
|
+
var invoice, allPaymentsForInvoice, calculateBalance, payment;
|
|
101
|
+
var amount = _b.amount, attachment = _b.attachment, currency = _b.currency, date = _b.date, description = _b.description, id = _b.id, mode = _b.mode, paymentType = _b.paymentType, prisma = _b.prisma, quoteInvoiceId = _b.quoteInvoiceId, ref = _b.ref;
|
|
104
102
|
return __generator(this, function (_c) {
|
|
105
103
|
switch (_c.label) {
|
|
106
104
|
case 0: return [4 /*yield*/, prisma.quoteInvoice.findUnique({
|
|
@@ -120,11 +118,16 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
|
|
|
120
118
|
})];
|
|
121
119
|
case 2:
|
|
122
120
|
allPaymentsForInvoice = _c.sent();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
calculateBalance = function () {
|
|
122
|
+
if (paymentType === 'PARTIAL_AMOUNT') {
|
|
123
|
+
return allPaymentsForInvoice && allPaymentsForInvoice
|
|
124
|
+
.reduce(function (acc, _a) {
|
|
125
|
+
var paymentAmount = _a.amount;
|
|
126
|
+
return acc + paymentAmount;
|
|
127
|
+
}, 0) - invoice.total;
|
|
128
|
+
}
|
|
129
|
+
return 0;
|
|
130
|
+
};
|
|
128
131
|
return [4 /*yield*/, prisma.payment.upsert({
|
|
129
132
|
where: {
|
|
130
133
|
id: id,
|
|
@@ -142,8 +145,7 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
|
|
|
142
145
|
create: {
|
|
143
146
|
amount: amount,
|
|
144
147
|
attachment: attachment,
|
|
145
|
-
balance:
|
|
146
|
-
// createdAt,
|
|
148
|
+
balance: String(calculateBalance()),
|
|
147
149
|
currency: currency,
|
|
148
150
|
date: date,
|
|
149
151
|
description: description,
|