accounting-engine 0.1.1 → 0.1.3
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 +1 -1
- package/src/services/engine.service.js +48 -12
package/package.json
CHANGED
@@ -80,6 +80,22 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
80
80
|
const index = _.findIndex(taxes, { id: line.id, type: 'tax', code: item.code, percent: item.percent });
|
81
81
|
taxes[index].amount += item.amount;
|
82
82
|
} else {
|
83
|
+
let withholding = {
|
84
|
+
type: null,
|
85
|
+
code: null,
|
86
|
+
name: null,
|
87
|
+
percent: null,
|
88
|
+
amount: null,
|
89
|
+
};
|
90
|
+
if (line.withholding_tax_subtotals && line.withholding_tax_subtotals.length > 0 && item.code === '0015') {
|
91
|
+
withholding = {
|
92
|
+
type: 'tax',
|
93
|
+
code: line.withholding_tax_subtotals[0].code,
|
94
|
+
name: line.withholding_tax_subtotals[0].name,
|
95
|
+
percent: line.withholding_tax_subtotals[0].percent,
|
96
|
+
amount: line.withholding_tax_subtotals[0].amount,
|
97
|
+
};
|
98
|
+
}
|
83
99
|
taxes.push({
|
84
100
|
id: line.id,
|
85
101
|
name: line.name,
|
@@ -92,6 +108,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
92
108
|
code: item.code,
|
93
109
|
percent: item.percent,
|
94
110
|
amount: item.amount,
|
111
|
+
withholding,
|
95
112
|
});
|
96
113
|
}
|
97
114
|
|
@@ -99,6 +116,22 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
99
116
|
const index = _.findIndex(taxables, { id: line.id, type: 'taxable', code: item.code, percent: item.percent });
|
100
117
|
taxables[index].amount += item.taxable;
|
101
118
|
} else {
|
119
|
+
let withholding = {
|
120
|
+
type: null,
|
121
|
+
code: null,
|
122
|
+
name: null,
|
123
|
+
percent: null,
|
124
|
+
amount: null,
|
125
|
+
};
|
126
|
+
if (line.withholding_tax_subtotals && line.withholding_tax_subtotals.length > 0 && item.code === '0015') {
|
127
|
+
withholding = {
|
128
|
+
type: 'taxable',
|
129
|
+
code: line.withholding_tax_subtotals[0].code,
|
130
|
+
name: line.withholding_tax_subtotals[0].name,
|
131
|
+
percent: line.withholding_tax_subtotals[0].percent,
|
132
|
+
amount: line.withholding_tax_subtotals[0].amount,
|
133
|
+
};
|
134
|
+
}
|
102
135
|
taxables.push({
|
103
136
|
id: line.id,
|
104
137
|
name: line.name,
|
@@ -111,6 +144,7 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
111
144
|
code: item.code,
|
112
145
|
percent: item.percent,
|
113
146
|
amount: item.taxable,
|
147
|
+
withholding,
|
114
148
|
});
|
115
149
|
}
|
116
150
|
}
|
@@ -126,6 +160,13 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
126
160
|
code: item.code,
|
127
161
|
percent: item.percent,
|
128
162
|
amount: item.amount,
|
163
|
+
withholding: {
|
164
|
+
type: null,
|
165
|
+
code: null,
|
166
|
+
name: null,
|
167
|
+
percent: null,
|
168
|
+
amount: null,
|
169
|
+
},
|
129
170
|
});
|
130
171
|
}
|
131
172
|
|
@@ -138,24 +179,19 @@ const normalizeInvoiceForAccounting = async (invoice, direction) => {
|
|
138
179
|
code: item.code,
|
139
180
|
percent: item.percent,
|
140
181
|
amount: item.taxable,
|
182
|
+
withholding: {
|
183
|
+
type: null,
|
184
|
+
code: null,
|
185
|
+
name: null,
|
186
|
+
percent: null,
|
187
|
+
amount: null,
|
188
|
+
},
|
141
189
|
});
|
142
190
|
}
|
143
191
|
}
|
144
192
|
}
|
145
193
|
const payableCounterLines = [...taxes, ...taxables];
|
146
194
|
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
195
|
const accountingLines = [...payableLines, ...payableCounterLines];
|
160
196
|
const data = {
|
161
197
|
uuid: invoice.uuid,
|