accounting-engine 0.1.7 → 0.1.9

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.7",
3
+ "version": "0.1.9",
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,7 @@ 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 = {};
51
+ const r = { type: line.type };
52
52
  _.forEach(Object.keys(item), (key) => {
53
53
  try {
54
54
  r[key] = eval(item[key]);
@@ -137,9 +137,15 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
137
137
  };
138
138
  }
139
139
  let amount = item.taxable;
140
- if (item.code === '0015' && Number(item.percent) !== 0 && Number(item.amount) !== 0) {
140
+ if (
141
+ item.code === '0015' &&
142
+ Number(item.percent) !== 0 &&
143
+ Number(item.amount) !== 0 &&
144
+ !Number.isNaN(Number(item.percent)) &&
145
+ !Number.isNaN(Number(item.amount))
146
+ ) {
141
147
  const calculatedAmount = Number(item.amount) / (Number(item.percent) / 100).toFixed(2);
142
- if (Math.abs(calculatedAmount - item.taxable) > 1) {
148
+ if (Math.abs(calculatedAmount - (item.taxable || 0)) > 1) {
143
149
  amount = calculatedAmount;
144
150
  }
145
151
  }
@@ -186,9 +192,15 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
186
192
  taxables[index].amount += item.taxable;
187
193
  } else {
188
194
  let amount = item.taxable;
189
- if (item.code === '0015' && Number(item.percent) !== 0 && Number(item.amount) !== 0) {
195
+ if (
196
+ item.code === '0015' &&
197
+ Number(item.percent) !== 0 &&
198
+ Number(item.amount) !== 0 &&
199
+ !Number.isNaN(Number(item.percent)) &&
200
+ !Number.isNaN(Number(item.amount))
201
+ ) {
190
202
  const calculatedAmount = Number(item.amount) / (Number(item.percent) / 100).toFixed(2);
191
- if (Math.abs(calculatedAmount - item.taxable) > 1) {
203
+ if (Math.abs(calculatedAmount - (item.taxable || 0)) > 1) {
192
204
  amount = calculatedAmount;
193
205
  }
194
206
  }