accounting-engine 0.1.0 → 0.1.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "accounting-engine",
3
- "version": "0.1.0",
4
- "description": "",
3
+ "version": "0.1.2",
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": {
7
7
  "test": "jest -i --colors --verbose --detectOpenHandles",
@@ -36,7 +36,6 @@
36
36
  "supertest": "^6.3.3"
37
37
  },
38
38
  "dependencies": {
39
- "date-and-time": "^3.1.1",
40
39
  "lodash": "^4.17.21",
41
40
  "moment": "^2.30.1",
42
41
  "ubl2json": "^2.0.2"
@@ -45,7 +45,9 @@ const applyRules = async (rules, data, upperCondition = null) => {
45
45
  const invoice = data;
46
46
  const willPull = [];
47
47
  for await (const line of invoice.accounting_lines) {
48
+ console.log(evalCondition);
48
49
  if (eval(evalCondition)) {
50
+ console.log(true);
49
51
  willPull.push(_.findIndex(invoice.accounting_lines, line));
50
52
  returnData.forEach((item) => {
51
53
  resultLines.push({
@@ -80,6 +82,22 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
80
82
  const index = _.findIndex(taxes, { id: line.id, type: 'tax', code: item.code, percent: item.percent });
81
83
  taxes[index].amount += item.amount;
82
84
  } else {
85
+ let withholding = {
86
+ type: null,
87
+ code: null,
88
+ name: null,
89
+ percent: null,
90
+ amount: null,
91
+ };
92
+ if (line.withholding_tax_subtotals && line.withholding_tax_subtotals.length > 0 && item.code === '0015') {
93
+ withholding = {
94
+ type: 'tax',
95
+ code: line.withholding_tax_subtotals[0].code,
96
+ name: line.withholding_tax_subtotals[0].name,
97
+ percent: line.withholding_tax_subtotals[0].percent,
98
+ amount: line.withholding_tax_subtotals[0].amount,
99
+ };
100
+ }
83
101
  taxes.push({
84
102
  id: line.id,
85
103
  name: line.name,
@@ -92,6 +110,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
92
110
  code: item.code,
93
111
  percent: item.percent,
94
112
  amount: item.amount,
113
+ withholding,
95
114
  });
96
115
  }
97
116
 
@@ -99,6 +118,22 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
99
118
  const index = _.findIndex(taxables, { id: line.id, type: 'taxable', code: item.code, percent: item.percent });
100
119
  taxables[index].amount += item.taxable;
101
120
  } else {
121
+ let withholding = {
122
+ type: null,
123
+ code: null,
124
+ name: null,
125
+ percent: null,
126
+ amount: null,
127
+ };
128
+ if (line.withholding_tax_subtotals && line.withholding_tax_subtotals.length > 0 && item.code === '0015') {
129
+ withholding = {
130
+ type: 'taxable',
131
+ code: line.withholding_tax_subtotals[0].code,
132
+ name: line.withholding_tax_subtotals[0].name,
133
+ percent: line.withholding_tax_subtotals[0].percent,
134
+ amount: line.withholding_tax_subtotals[0].amount,
135
+ };
136
+ }
102
137
  taxables.push({
103
138
  id: line.id,
104
139
  name: line.name,
@@ -111,6 +146,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
111
146
  code: item.code,
112
147
  percent: item.percent,
113
148
  amount: item.taxable,
149
+ withholding,
114
150
  });
115
151
  }
116
152
  }
@@ -126,6 +162,13 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
126
162
  code: item.code,
127
163
  percent: item.percent,
128
164
  amount: item.amount,
165
+ withholding: {
166
+ type: null,
167
+ code: null,
168
+ name: null,
169
+ percent: null,
170
+ amount: null,
171
+ },
129
172
  });
130
173
  }
131
174
 
@@ -138,24 +181,19 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
138
181
  code: item.code,
139
182
  percent: item.percent,
140
183
  amount: item.taxable,
184
+ withholding: {
185
+ type: null,
186
+ code: null,
187
+ name: null,
188
+ percent: null,
189
+ amount: null,
190
+ },
141
191
  });
142
192
  }
143
193
  }
144
194
  }
145
195
  const payableCounterLines = [...taxes, ...taxables];
146
196
  const payableLines = [payable];
147
- // const payableCounterTotalAmount = payableCounterLines.reduce((acc, item) => acc + item.amount, 0);
148
- // if (payableCounterTotalAmount > payable.amount) {
149
- // payableLines.push({
150
- // type: 'payable_extra',
151
- // amount: payableCounterTotalAmount - payable.amount,
152
- // });
153
- // } else if (payableCounterTotalAmount < payable.amount) {
154
- // payableCounterLines.push({
155
- // type: 'taxable_extra',
156
- // amount: payable.amount - payableCounterTotalAmount,
157
- // });
158
- // }
159
197
  const accountingLines = [...payableLines, ...payableCounterLines];
160
198
  const data = {
161
199
  uuid: invoice.uuid,
@@ -170,6 +208,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
170
208
  receiver_object: invoice.receiver_object,
171
209
  accounting_lines: accountingLines,
172
210
  };
211
+ // console.log(data.accounting_lines[1]);
173
212
  return data;
174
213
  };
175
214