@react-pakistan/util-functions 1.23.49 → 1.23.51
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,41 +97,62 @@ 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 payment;
|
|
100
|
+
var invoice, allPaymentsForInvoice, balance, payment;
|
|
101
101
|
var amount = _b.amount, attachment = _b.attachment, createdAt = _b.createdAt, 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;
|
|
102
102
|
return __generator(this, function (_c) {
|
|
103
103
|
switch (_c.label) {
|
|
104
|
-
case 0: return [4 /*yield*/, prisma.
|
|
104
|
+
case 0: return [4 /*yield*/, prisma.invoice.findUnique({
|
|
105
105
|
where: {
|
|
106
|
-
id: id,
|
|
107
|
-
},
|
|
108
|
-
update: {
|
|
109
|
-
amount: amount,
|
|
110
|
-
attachment: attachment,
|
|
111
|
-
currency: currency,
|
|
112
|
-
date: date,
|
|
113
|
-
description: description,
|
|
114
|
-
mode: mode,
|
|
115
|
-
paymentType: paymentType,
|
|
116
|
-
quoteInvoiceId: quoteInvoiceId,
|
|
117
|
-
ref: ref,
|
|
118
|
-
balance: '0',
|
|
119
|
-
},
|
|
120
|
-
create: {
|
|
121
|
-
amount: amount,
|
|
122
|
-
attachment: attachment,
|
|
123
|
-
currency: currency,
|
|
124
|
-
date: date,
|
|
125
|
-
description: description,
|
|
126
|
-
mode: mode,
|
|
127
|
-
paymentType: paymentType,
|
|
128
106
|
quoteInvoiceId: quoteInvoiceId,
|
|
129
|
-
ref: ref,
|
|
130
|
-
createdAt: createdAt,
|
|
131
|
-
balance: '0',
|
|
132
107
|
},
|
|
133
108
|
})];
|
|
134
109
|
case 1:
|
|
110
|
+
invoice = _c.sent();
|
|
111
|
+
return [4 /*yield*/, prisma.payment.findMany({
|
|
112
|
+
where: {
|
|
113
|
+
quoteInvoiceId: quoteInvoiceId,
|
|
114
|
+
},
|
|
115
|
+
include: {
|
|
116
|
+
quoteInvoice: true,
|
|
117
|
+
},
|
|
118
|
+
})];
|
|
119
|
+
case 2:
|
|
120
|
+
allPaymentsForInvoice = _c.sent();
|
|
121
|
+
balance = (allPaymentsForInvoice && allPaymentsForInvoice
|
|
122
|
+
.reduce(function (acc, _a) {
|
|
123
|
+
var paymentAmount = _a.amount;
|
|
124
|
+
return acc + paymentAmount;
|
|
125
|
+
}, 0) - invoice.total) || 0;
|
|
126
|
+
return [4 /*yield*/, prisma.payment.upsert({
|
|
127
|
+
where: {
|
|
128
|
+
id: id,
|
|
129
|
+
},
|
|
130
|
+
update: {
|
|
131
|
+
amount: amount,
|
|
132
|
+
attachment: attachment,
|
|
133
|
+
currency: currency,
|
|
134
|
+
date: date,
|
|
135
|
+
description: description,
|
|
136
|
+
mode: mode,
|
|
137
|
+
paymentType: paymentType,
|
|
138
|
+
quoteInvoiceId: quoteInvoiceId,
|
|
139
|
+
ref: ref,
|
|
140
|
+
},
|
|
141
|
+
create: {
|
|
142
|
+
amount: amount,
|
|
143
|
+
attachment: attachment,
|
|
144
|
+
balance: balance,
|
|
145
|
+
createdAt: createdAt,
|
|
146
|
+
currency: currency,
|
|
147
|
+
date: date,
|
|
148
|
+
description: description,
|
|
149
|
+
mode: mode,
|
|
150
|
+
paymentType: paymentType,
|
|
151
|
+
quoteInvoiceId: quoteInvoiceId,
|
|
152
|
+
ref: ref,
|
|
153
|
+
},
|
|
154
|
+
})];
|
|
155
|
+
case 3:
|
|
135
156
|
payment = _c.sent();
|
|
136
157
|
return [2 /*return*/, payment];
|
|
137
158
|
}
|