accounting-engine 0.1.11 → 0.1.13

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": "accounting-engine",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Bu paket, verilen faturanın, belirtilen kurallar çerçevesinde muhasebeleştirilmesini kolaylaştırmak adına oluşturulmuştur.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -48,7 +48,18 @@ const applyRules = async (rules, data, upperCondition = null) => {
48
48
  if (eval(evalCondition)) {
49
49
  willPull.push(_.findIndex(invoice.accounting_lines, line));
50
50
  returnData.forEach(async (item) => {
51
- const r = { type: line.type };
51
+ const r = {
52
+ type: line.type,
53
+ name: line.name,
54
+ quantity: line.quantity,
55
+ unit: line.quantity_unit,
56
+ price: line.price,
57
+ extension_amount: line.extension_amount,
58
+ additional: line.additional,
59
+ taxCode: line.code,
60
+ taxPercent: line.percent,
61
+ all_stocks: line.all_stocks,
62
+ };
52
63
  _.forEach(Object.keys(item), (key) => {
53
64
  try {
54
65
  r[key] = eval(item[key]);
@@ -71,6 +82,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
71
82
  if (['in', 'out'].indexOf(direction) === -1) {
72
83
  throw new Error('Direction must be in or out');
73
84
  }
85
+ let isAddedAllStocks = false;
74
86
  const taxes = [];
75
87
  const taxables = [];
76
88
  const payable = {
@@ -216,7 +228,20 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
216
228
  percent: null,
217
229
  amount: null,
218
230
  },
231
+ all_stocks: isAddedAllStocks
232
+ ? []
233
+ : _.map(invoice.lines, (line) => {
234
+ return {
235
+ code: null,
236
+ name: line.name,
237
+ quantity: line.quantity,
238
+ quantityPrice: line.price,
239
+ taxCode: item.code,
240
+ taxPercent: item.percent,
241
+ };
242
+ }),
219
243
  });
244
+ isAddedAllStocks = true;
220
245
  }
221
246
  }
222
247
  }
@@ -236,7 +261,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
236
261
  receiver_object: invoice.receiver_object,
237
262
  accounting_lines: accountingLines,
238
263
  additional_document_reference: invoice.additional_document_reference,
239
- payable_amount : invoice.payable_amount,
264
+ payable_amount: invoice.payable_amount,
240
265
  };
241
266
  return data;
242
267
  };
@@ -260,8 +285,42 @@ const normalizeJSON = async (opts, data, dir) => {
260
285
  if (index !== -1) {
261
286
  acc[index].borc += item.borc;
262
287
  acc[index].alacak += item.alacak;
288
+ if (item.type === 'taxable') {
289
+ acc[index].stocks.push({
290
+ code: (dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id) || null,
291
+ name: item.name,
292
+ quantity: item.quantity,
293
+ quantityPrice: item.price,
294
+ taxCode: item.taxCode,
295
+ taxPercent: item.taxPercent,
296
+ });
297
+ }
263
298
  } else {
264
- acc.push(item);
299
+ acc.push({
300
+ ...item,
301
+ stocks:
302
+ // eslint-disable-next-line no-nested-ternary
303
+ item.type === 'taxable' && item.name
304
+ ? [
305
+ {
306
+ code: (dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id) || null,
307
+ name: item.name,
308
+ quantity: item.quantity,
309
+ quantityPrice: item.price,
310
+ taxCode: item.taxCode,
311
+ taxPercent: item.taxPercent,
312
+ },
313
+ ]
314
+ : Array.isArray(item.all_stocks)
315
+ ? _.map(item.all_stocks, (stock) => {
316
+ return {
317
+ ...stock,
318
+ code: (dir === 'in' ? stock.additional?.buyers_item_id : stock.additional?.seller_item_id) || null,
319
+ };
320
+ })
321
+ : [],
322
+ all_stocks: undefined,
323
+ });
265
324
  }
266
325
  return acc;
267
326
  },