@react-pakistan/util-functions 1.23.55 → 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({
|
|
@@ -110,7 +108,6 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
|
|
|
110
108
|
})];
|
|
111
109
|
case 1:
|
|
112
110
|
invoice = _c.sent();
|
|
113
|
-
console.log('_>', invoice);
|
|
114
111
|
return [4 /*yield*/, prisma.payment.findMany({
|
|
115
112
|
where: {
|
|
116
113
|
quoteInvoiceId: quoteInvoiceId,
|
|
@@ -121,13 +118,16 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
|
|
|
121
118
|
})];
|
|
122
119
|
case 2:
|
|
123
120
|
allPaymentsForInvoice = _c.sent();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
};
|
|
131
131
|
return [4 /*yield*/, prisma.payment.upsert({
|
|
132
132
|
where: {
|
|
133
133
|
id: id,
|
|
@@ -145,8 +145,7 @@ var postPayment = function (_a) { return __awaiter(void 0, [_a], void 0, functio
|
|
|
145
145
|
create: {
|
|
146
146
|
amount: amount,
|
|
147
147
|
attachment: attachment,
|
|
148
|
-
balance: String(
|
|
149
|
-
// createdAt,
|
|
148
|
+
balance: String(calculateBalance()),
|
|
150
149
|
currency: currency,
|
|
151
150
|
date: date,
|
|
152
151
|
description: description,
|