accounting-engine 0.1.12 → 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.12",
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": {
@@ -58,6 +58,7 @@ const applyRules = async (rules, data, upperCondition = null) => {
58
58
  additional: line.additional,
59
59
  taxCode: line.code,
60
60
  taxPercent: line.percent,
61
+ all_stocks: line.all_stocks,
61
62
  };
62
63
  _.forEach(Object.keys(item), (key) => {
63
64
  try {
@@ -81,6 +82,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
81
82
  if (['in', 'out'].indexOf(direction) === -1) {
82
83
  throw new Error('Direction must be in or out');
83
84
  }
85
+ let isAddedAllStocks = false;
84
86
  const taxes = [];
85
87
  const taxables = [];
86
88
  const payable = {
@@ -226,7 +228,20 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
226
228
  percent: null,
227
229
  amount: null,
228
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
+ }),
229
243
  });
244
+ isAddedAllStocks = true;
230
245
  }
231
246
  }
232
247
  }
@@ -272,7 +287,7 @@ const normalizeJSON = async (opts, data, dir) => {
272
287
  acc[index].alacak += item.alacak;
273
288
  if (item.type === 'taxable') {
274
289
  acc[index].stocks.push({
275
- code: dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id || null,
290
+ code: (dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id) || null,
276
291
  name: item.name,
277
292
  quantity: item.quantity,
278
293
  quantityPrice: item.price,
@@ -284,10 +299,11 @@ const normalizeJSON = async (opts, data, dir) => {
284
299
  acc.push({
285
300
  ...item,
286
301
  stocks:
287
- item.type === 'taxable'
302
+ // eslint-disable-next-line no-nested-ternary
303
+ item.type === 'taxable' && item.name
288
304
  ? [
289
305
  {
290
- code: dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id || null,
306
+ code: (dir === 'in' ? item.additional?.buyers_item_id : item.additional?.seller_item_id) || null,
291
307
  name: item.name,
292
308
  quantity: item.quantity,
293
309
  quantityPrice: item.price,
@@ -295,7 +311,15 @@ const normalizeJSON = async (opts, data, dir) => {
295
311
  taxPercent: item.taxPercent,
296
312
  },
297
313
  ]
298
- : [],
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,
299
323
  });
300
324
  }
301
325
  return acc;