tango-app-api-payment-subscription 3.5.3 → 3.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-payment-subscription",
3
- "version": "3.5.3",
3
+ "version": "3.5.4",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -113,6 +113,72 @@ export async function createInvoice( req, res ) {
113
113
  invoiceGroupList.push( invoiceGroup );
114
114
  }
115
115
 
116
+ // Custom-create path: the Create Invoice modal posts a fully-composed
117
+ // invoice (companyName, products, tax, totals — all entered by the user).
118
+ // The legacy aggregation paths above don't handle this shape and would
119
+ // silently no-op (empty invoiceGroupList → loop skipped → 2xx with nothing
120
+ // written). When the caller sets customInvoice=true we insert exactly
121
+ // what they sent, with a server-generated invoice number.
122
+ if ( req.body.customInvoice === true ) {
123
+ if ( !req.body.clientId ) {
124
+ return res.sendError( 'clientId is required for customInvoice', 400 );
125
+ }
126
+ const Finacialyear = getCurrentFinancialYear();
127
+ const previousinvoice = await invoiceService.findandsort(
128
+ { invoice: { $regex: `^INV-${Finacialyear}-` } },
129
+ {},
130
+ { invoiceIndex: -1 },
131
+ );
132
+ let invoiceNo = '00001';
133
+ if ( previousinvoice && previousinvoice.length > 0 ) {
134
+ invoiceNo = Number( previousinvoice[0].invoiceIndex ) + 1;
135
+ invoiceNo = invoiceNo.toString().padStart( 5, '0' );
136
+ }
137
+ const baseDate = req.body.billingDate ? dayjs( req.body.billingDate ) : dayjs();
138
+ const data = {
139
+ invoice: `INV-${Finacialyear}-${invoiceNo}`,
140
+ invoiceIndex: invoiceNo,
141
+ clientId: req.body.clientId,
142
+ groupId: req.body.groupId || undefined,
143
+ groupName: req.body.groupName || '',
144
+ companyName: req.body.companyName || '',
145
+ companyAddress: req.body.companyAddress || '',
146
+ GSTNumber: req.body.GSTNumber || '',
147
+ PlaceOfSupply: req.body.PlaceOfSupply || '',
148
+ products: Array.isArray( req.body.products ) ? req.body.products : [],
149
+ tax: Array.isArray( req.body.tax ) ? req.body.tax : [],
150
+ amount: Math.round( Number( req.body.amount ) || 0 ),
151
+ totalAmount: Math.round( Number( req.body.totalAmount ) || 0 ),
152
+ stores: Number( req.body.stores ) || 0,
153
+ currency: req.body.currency || 'inr',
154
+ billingDate: baseDate.toDate(),
155
+ dueDate: req.body.dueDate ? new Date( req.body.dueDate ) : baseDate.add( 30, 'days' ).toDate(),
156
+ monthOfbilling: baseDate.format( 'MM' ),
157
+ paymentMethod: 'Online',
158
+ status: 'pendingCsm',
159
+ paymentStatus: 'unpaid',
160
+ };
161
+ const created = await invoiceService.create( data );
162
+ const logObj = {
163
+ userName: req.user?.userName,
164
+ email: req.user?.email,
165
+ clientId: data.clientId,
166
+ logSubType: 'invoiceCreated',
167
+ logType: 'invoice',
168
+ date: new Date(),
169
+ changes: [ `${data.invoice} invoice created manually by ${req.user?.email}` ],
170
+ eventType: 'create',
171
+ timestamp: new Date(),
172
+ showTo: [ 'tango' ],
173
+ };
174
+ try {
175
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).activityLog, logObj );
176
+ } catch ( logErr ) {
177
+ logger.error( { error: logErr, function: 'createInvoice.customLog' } );
178
+ }
179
+ return res.sendSuccess( { data: created } );
180
+ }
181
+
116
182
  for ( let group of invoiceGroupList ) {
117
183
  let Finacialyear = getCurrentFinancialYear();
118
184
  // Scope the highest-index lookup to invoices created in the current FY