taxtank-core 0.27.5 → 0.27.6

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.
Files changed (40) hide show
  1. package/bundles/taxtank-core.umd.js +261 -34
  2. package/bundles/taxtank-core.umd.js.map +1 -1
  3. package/esm2015/lib/db/Enums/sole-invoice-statuses.enum.js +8 -0
  4. package/esm2015/lib/db/Enums/sole-invoice-template-tax-type.enum.js +7 -0
  5. package/esm2015/lib/db/Models/chart-accounts/chart-accounts.js +1 -1
  6. package/esm2015/lib/db/Models/sole/sole-invoice-template.js +1 -1
  7. package/esm2015/lib/db/Models/sole/sole-invoice.js +1 -1
  8. package/esm2015/lib/forms/bank/bank-account/bank-account-add-manual.form.js +6 -10
  9. package/esm2015/lib/forms/sole/index.js +3 -1
  10. package/esm2015/lib/forms/sole/sole-invoice-item.form.js +43 -0
  11. package/esm2015/lib/forms/sole/sole-invoice-template.form.js +5 -3
  12. package/esm2015/lib/forms/sole/sole-invoice.form.js +51 -0
  13. package/esm2015/lib/models/endpoint/endpoints.const.js +5 -1
  14. package/esm2015/lib/models/sole/sole-details.js +3 -1
  15. package/esm2015/lib/models/sole/sole-invoice-item.js +8 -1
  16. package/esm2015/lib/models/sole/sole-invoice-template.js +12 -2
  17. package/esm2015/lib/models/sole/sole-invoice.js +55 -2
  18. package/esm2015/lib/services/http/sole/index.js +2 -1
  19. package/esm2015/lib/services/http/sole/sole-invoice/sole-invoice.service.js +21 -0
  20. package/esm2015/public-api.js +3 -1
  21. package/fesm2015/taxtank-core.js +211 -21
  22. package/fesm2015/taxtank-core.js.map +1 -1
  23. package/lib/db/Enums/sole-invoice-statuses.enum.d.ts +6 -0
  24. package/lib/db/Enums/sole-invoice-template-tax-type.enum.d.ts +5 -0
  25. package/lib/db/Models/chart-accounts/chart-accounts.d.ts +1 -0
  26. package/lib/db/Models/sole/sole-invoice-template.d.ts +2 -1
  27. package/lib/db/Models/sole/sole-invoice.d.ts +2 -1
  28. package/lib/forms/bank/bank-account/bank-account-add-manual.form.d.ts +1 -3
  29. package/lib/forms/sole/index.d.ts +2 -0
  30. package/lib/forms/sole/sole-invoice-item.form.d.ts +10 -0
  31. package/lib/forms/sole/sole-invoice-template.form.d.ts +3 -2
  32. package/lib/forms/sole/sole-invoice.form.d.ts +14 -0
  33. package/lib/models/sole/sole-details.d.ts +2 -0
  34. package/lib/models/sole/sole-invoice-item.d.ts +2 -0
  35. package/lib/models/sole/sole-invoice-template.d.ts +5 -1
  36. package/lib/models/sole/sole-invoice.d.ts +12 -0
  37. package/lib/services/http/sole/index.d.ts +1 -0
  38. package/lib/services/http/sole/sole-invoice/sole-invoice.service.d.ts +11 -0
  39. package/package.json +1 -1
  40. package/public-api.d.ts +2 -0
@@ -1059,6 +1059,10 @@
1059
1059
  SOLE_BUSINESSES_PUT: new Endpoint('PUT', '\\/sole-businesses\\/\\d+'),
1060
1060
  SOLE_DEPRECIATION_METHODS_GET: new Endpoint('GET', '\\/sole-depreciation-methods'),
1061
1061
  SOLE_DEPRECIATION_METHODS_PUT: new Endpoint('PUT', '\\/sole-depreciation-methods\\/\\d+'),
1062
+ SOLE_INVOICES_GET: new Endpoint('GET', '\\/sole-invoices'),
1063
+ SOLE_INVOICES_POST: new Endpoint('POST', '\\/sole-invoices'),
1064
+ SOLE_INVOICES_PUT: new Endpoint('PUT', '\\/sole-invoices\\/\\d+'),
1065
+ SOLE_INVOICES_DELETE: new Endpoint('DELETE', '\\/sole-invoices\\/\\d+'),
1062
1066
  SOLE_INVOICE_TEMPLATES_GET: new Endpoint('GET', '\\/sole-invoice-templates'),
1063
1067
  SOLE_INVOICE_TEMPLATES_POST: new Endpoint('POST', '\\/sole-invoice-templates'),
1064
1068
  SOLE_INVOICE_TEMPLATES_PUT: new Endpoint('PUT', '\\/sole-invoice-templates\\/\\d+'),
@@ -3126,8 +3130,17 @@
3126
3130
  var SoleInvoiceItem = /** @class */ (function (_super) {
3127
3131
  __extends(SoleInvoiceItem, _super);
3128
3132
  function SoleInvoiceItem() {
3129
- return _super !== null && _super.apply(this, arguments) || this;
3133
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3134
+ _this.isGST = false;
3135
+ return _this;
3130
3136
  }
3137
+ Object.defineProperty(SoleInvoiceItem.prototype, "amount", {
3138
+ get: function () {
3139
+ return this.price * this.quantity;
3140
+ },
3141
+ enumerable: false,
3142
+ configurable: true
3143
+ });
3131
3144
  return SoleInvoiceItem;
3132
3145
  }(SoleInvoiceItem$1));
3133
3146
  __decorate([
@@ -3188,13 +3201,29 @@
3188
3201
  return SoleInvoiceTemplate;
3189
3202
  }(AbstractModel));
3190
3203
 
3204
+ exports.SoleInvoiceTemplateTaxTypeEnum = void 0;
3205
+ (function (SoleInvoiceTemplateTaxTypeEnum) {
3206
+ SoleInvoiceTemplateTaxTypeEnum[SoleInvoiceTemplateTaxTypeEnum["EXCLUSIVE"] = 0] = "EXCLUSIVE";
3207
+ SoleInvoiceTemplateTaxTypeEnum[SoleInvoiceTemplateTaxTypeEnum["INCLUSIVE"] = 1] = "INCLUSIVE";
3208
+ SoleInvoiceTemplateTaxTypeEnum[SoleInvoiceTemplateTaxTypeEnum["NONE"] = 2] = "NONE";
3209
+ })(exports.SoleInvoiceTemplateTaxTypeEnum || (exports.SoleInvoiceTemplateTaxTypeEnum = {}));
3210
+
3191
3211
  var SoleInvoiceTemplate = /** @class */ (function (_super) {
3192
3212
  __extends(SoleInvoiceTemplate, _super);
3193
3213
  function SoleInvoiceTemplate() {
3194
3214
  var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3195
- _this.isTaxIncluded = false;
3215
+ _this.taxType = exports.SoleInvoiceTemplateTaxTypeEnum.NONE;
3196
3216
  return _this;
3197
3217
  }
3218
+ SoleInvoiceTemplate.prototype.isNoTax = function () {
3219
+ return this.taxType === exports.SoleInvoiceTemplateTaxTypeEnum.NONE;
3220
+ };
3221
+ SoleInvoiceTemplate.prototype.isTaxExclusive = function () {
3222
+ return this.taxType === exports.SoleInvoiceTemplateTaxTypeEnum.EXCLUSIVE;
3223
+ };
3224
+ SoleInvoiceTemplate.prototype.isTaxInclusive = function () {
3225
+ return this.taxType === exports.SoleInvoiceTemplateTaxTypeEnum.INCLUSIVE;
3226
+ };
3198
3227
  return SoleInvoiceTemplate;
3199
3228
  }(SoleInvoiceTemplate$1));
3200
3229
  __decorate([
@@ -3204,11 +3233,105 @@
3204
3233
  classTransformer.Type(function () { return BankAccount; })
3205
3234
  ], SoleInvoiceTemplate.prototype, "bankAccount", void 0);
3206
3235
 
3236
+ exports.SoleInvoiceStatusesEnum = void 0;
3237
+ (function (SoleInvoiceStatusesEnum) {
3238
+ SoleInvoiceStatusesEnum[SoleInvoiceStatusesEnum["CANCELED"] = 0] = "CANCELED";
3239
+ SoleInvoiceStatusesEnum[SoleInvoiceStatusesEnum["DRAFT"] = 1] = "DRAFT";
3240
+ SoleInvoiceStatusesEnum[SoleInvoiceStatusesEnum["PENDING"] = 2] = "PENDING";
3241
+ SoleInvoiceStatusesEnum[SoleInvoiceStatusesEnum["PAID"] = 3] = "PAID";
3242
+ })(exports.SoleInvoiceStatusesEnum || (exports.SoleInvoiceStatusesEnum = {}));
3243
+
3244
+ var SoleDetails$1 = /** @class */ (function (_super) {
3245
+ __extends(SoleDetails, _super);
3246
+ function SoleDetails() {
3247
+ return _super !== null && _super.apply(this, arguments) || this;
3248
+ }
3249
+ return SoleDetails;
3250
+ }(AbstractModel));
3251
+
3252
+ var SoleDetails = /** @class */ (function (_super) {
3253
+ __extends(SoleDetails, _super);
3254
+ function SoleDetails() {
3255
+ return _super !== null && _super.apply(this, arguments) || this;
3256
+ }
3257
+ return SoleDetails;
3258
+ }(SoleDetails$1));
3259
+ SoleDetails.GSTPercentMultiplier = 0.1;
3260
+ SoleDetails.GSTPercentDivider = 11;
3261
+ __decorate([
3262
+ classTransformer.Type(function () { return User; })
3263
+ ], SoleDetails.prototype, "user", void 0);
3264
+
3207
3265
  var SoleInvoice = /** @class */ (function (_super) {
3208
3266
  __extends(SoleInvoice, _super);
3209
3267
  function SoleInvoice() {
3210
- return _super !== null && _super.apply(this, arguments) || this;
3268
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3269
+ _this.items = [classTransformer.plainToClass(SoleInvoiceItem, {})];
3270
+ _this.status = exports.SoleInvoiceStatusesEnum.DRAFT;
3271
+ return _this;
3211
3272
  }
3273
+ Object.defineProperty(SoleInvoice.prototype, "amount", {
3274
+ get: function () {
3275
+ return this.items.reduce(function (sum, item) { return sum + item.amount; }, 0);
3276
+ },
3277
+ enumerable: false,
3278
+ configurable: true
3279
+ });
3280
+ SoleInvoice.prototype.getGSTItems = function () {
3281
+ return this.items.filter(function (item) { return item.isGST; });
3282
+ };
3283
+ SoleInvoice.prototype.getGSTItemsAmount = function () {
3284
+ return this.getGSTItems().reduce(function (sum, item) { return sum + item.amount; }, 0);
3285
+ };
3286
+ Object.defineProperty(SoleInvoice.prototype, "subtotal", {
3287
+ get: function () {
3288
+ var _a;
3289
+ if ((_a = this.template) === null || _a === void 0 ? void 0 : _a.isTaxInclusive()) {
3290
+ return this.amount - this.GSTAmount;
3291
+ }
3292
+ return this.amount;
3293
+ },
3294
+ enumerable: false,
3295
+ configurable: true
3296
+ });
3297
+ Object.defineProperty(SoleInvoice.prototype, "GSTAmount", {
3298
+ get: function () {
3299
+ var _a, _b;
3300
+ switch (true) {
3301
+ case (_a = this.template) === null || _a === void 0 ? void 0 : _a.isTaxInclusive():
3302
+ return +(this.getGSTItemsAmount() / SoleDetails.GSTPercentDivider).toFixed(2);
3303
+ case (_b = this.template) === null || _b === void 0 ? void 0 : _b.isTaxExclusive():
3304
+ return +(this.getGSTItemsAmount() * SoleDetails.GSTPercentMultiplier).toFixed(2);
3305
+ default:
3306
+ return 0;
3307
+ }
3308
+ },
3309
+ enumerable: false,
3310
+ configurable: true
3311
+ });
3312
+ Object.defineProperty(SoleInvoice.prototype, "total", {
3313
+ get: function () {
3314
+ var _a;
3315
+ if ((_a = this.template) === null || _a === void 0 ? void 0 : _a.isTaxExclusive()) {
3316
+ return this.amount + this.GSTAmount;
3317
+ }
3318
+ return this.amount;
3319
+ },
3320
+ enumerable: false,
3321
+ configurable: true
3322
+ });
3323
+ SoleInvoice.prototype.isDraft = function () {
3324
+ return this.status === exports.SoleInvoiceStatusesEnum.DRAFT;
3325
+ };
3326
+ SoleInvoice.prototype.isCancelled = function () {
3327
+ return this.status === exports.SoleInvoiceStatusesEnum.CANCELED;
3328
+ };
3329
+ SoleInvoice.prototype.isPending = function () {
3330
+ return this.status === exports.SoleInvoiceStatusesEnum.PENDING;
3331
+ };
3332
+ SoleInvoice.prototype.isPaid = function () {
3333
+ return this.status === exports.SoleInvoiceStatusesEnum.PAID;
3334
+ };
3212
3335
  return SoleInvoice;
3213
3336
  }(SoleInvoice$1));
3214
3337
  __decorate([
@@ -4584,25 +4707,6 @@
4584
4707
  return SoleDepreciationMethod;
4585
4708
  }(SoleDepreciationMethod$1));
4586
4709
 
4587
- var SoleDetails$1 = /** @class */ (function (_super) {
4588
- __extends(SoleDetails, _super);
4589
- function SoleDetails() {
4590
- return _super !== null && _super.apply(this, arguments) || this;
4591
- }
4592
- return SoleDetails;
4593
- }(AbstractModel));
4594
-
4595
- var SoleDetails = /** @class */ (function (_super) {
4596
- __extends(SoleDetails, _super);
4597
- function SoleDetails() {
4598
- return _super !== null && _super.apply(this, arguments) || this;
4599
- }
4600
- return SoleDetails;
4601
- }(SoleDetails$1));
4602
- __decorate([
4603
- classTransformer.Type(function () { return User; })
4604
- ], SoleDetails.prototype, "user", void 0);
4605
-
4606
4710
  var User = /** @class */ (function (_super) {
4607
4711
  __extends(User, _super);
4608
4712
  function User() {
@@ -11171,6 +11275,26 @@
11171
11275
  }] }];
11172
11276
  } });
11173
11277
 
11278
+ var SoleInvoiceService = /** @class */ (function (_super) {
11279
+ __extends(SoleInvoiceService, _super);
11280
+ function SoleInvoiceService() {
11281
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11282
+ _this.modelClass = SoleInvoice;
11283
+ _this.url = 'sole-invoices';
11284
+ _this.isHydra = true;
11285
+ return _this;
11286
+ }
11287
+ return SoleInvoiceService;
11288
+ }(RestService));
11289
+ SoleInvoiceService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleInvoiceService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11290
+ SoleInvoiceService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleInvoiceService, providedIn: 'root' });
11291
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleInvoiceService, decorators: [{
11292
+ type: i0.Injectable,
11293
+ args: [{
11294
+ providedIn: 'root'
11295
+ }]
11296
+ }] });
11297
+
11174
11298
  var SoleInvoiceTemplateService = /** @class */ (function (_super) {
11175
11299
  __extends(SoleInvoiceTemplateService, _super);
11176
11300
  function SoleInvoiceTemplateService() {
@@ -16926,15 +17050,119 @@
16926
17050
  return SoleDetailsForm;
16927
17051
  }(AbstractForm));
16928
17052
 
17053
+ var SoleInvoiceItemForm = /** @class */ (function (_super) {
17054
+ __extends(SoleInvoiceItemForm, _super);
17055
+ function SoleInvoiceItemForm(item) {
17056
+ var _this = this;
17057
+ var _a;
17058
+ _this = _super.call(this, {
17059
+ description: new forms.FormControl(item.description, forms.Validators.required),
17060
+ quantity: new forms.FormControl(item.quantity, forms.Validators.required),
17061
+ price: new forms.FormControl(item.price, forms.Validators.required),
17062
+ isGST: new forms.FormControl({ value: item.isGST, disabled: !((_a = item.chartAccounts) === null || _a === void 0 ? void 0 : _a.isGST) }),
17063
+ chartAccounts: new forms.FormControl(item.chartAccounts, forms.Validators.required)
17064
+ }, item) || this;
17065
+ _this.listenEvents();
17066
+ return _this;
17067
+ }
17068
+ SoleInvoiceItemForm.prototype.listenEvents = function () {
17069
+ this.listenChartAccountsChanges();
17070
+ };
17071
+ SoleInvoiceItemForm.prototype.onTemplateChanged = function (template) {
17072
+ this.template = template;
17073
+ if (this.template.isNoTax()) {
17074
+ this.get('isGST').setValue(false);
17075
+ this.get('isGST').disable();
17076
+ }
17077
+ else {
17078
+ this.get('isGST').enable();
17079
+ }
17080
+ };
17081
+ SoleInvoiceItemForm.prototype.listenChartAccountsChanges = function () {
17082
+ var _this = this;
17083
+ this.get('chartAccounts').valueChanges.subscribe(function (chartAccounts) {
17084
+ if (_this.template.isNoTax()) {
17085
+ return;
17086
+ }
17087
+ if (chartAccounts.isGST) {
17088
+ _this.get('isGST').enable();
17089
+ }
17090
+ else {
17091
+ _this.get('isGST').setValue(false);
17092
+ _this.get('isGST').disable();
17093
+ }
17094
+ });
17095
+ };
17096
+ return SoleInvoiceItemForm;
17097
+ }(AbstractForm));
17098
+
17099
+ var SoleInvoiceForm = /** @class */ (function (_super) {
17100
+ __extends(SoleInvoiceForm, _super);
17101
+ function SoleInvoiceForm(invoice) {
17102
+ var _this = _super.call(this, {
17103
+ dateFrom: new forms.FormControl(invoice.dateFrom, forms.Validators.required),
17104
+ dateTo: new forms.FormControl(invoice.dateTo, forms.Validators.required),
17105
+ items: new forms.FormArray(invoice.items.map(function (item) { return new SoleInvoiceItemForm(item); })),
17106
+ payer: new forms.FormControl(invoice.payer, forms.Validators.required),
17107
+ template: new forms.FormControl(invoice.template, forms.Validators.required)
17108
+ }, invoice) || this;
17109
+ if (invoice.id) {
17110
+ _this.updateItemsForm(invoice.template);
17111
+ }
17112
+ _this.listenEvents();
17113
+ return _this;
17114
+ }
17115
+ Object.defineProperty(SoleInvoiceForm.prototype, "items", {
17116
+ get: function () {
17117
+ return this.get('items');
17118
+ },
17119
+ enumerable: false,
17120
+ configurable: true
17121
+ });
17122
+ SoleInvoiceForm.prototype.listenEvents = function () {
17123
+ this.listenTemplateChanges();
17124
+ };
17125
+ SoleInvoiceForm.prototype.addItem = function () {
17126
+ this.items.push(new SoleInvoiceItemForm(classTransformer.plainToClass(SoleInvoiceItem, {})));
17127
+ };
17128
+ SoleInvoiceForm.prototype.removeItem = function (index) {
17129
+ // do not remove the last item
17130
+ if (this.items.length === 1) {
17131
+ return;
17132
+ }
17133
+ this.items.removeAt(index);
17134
+ };
17135
+ SoleInvoiceForm.prototype.submit = function (data) {
17136
+ if (data === void 0) { data = {}; }
17137
+ var items = this.items.controls.map(function (control) { return control.submit(); });
17138
+ return _super.prototype.submit.call(this, Object.assign({}, data, { items: items }));
17139
+ };
17140
+ SoleInvoiceForm.prototype.listenTemplateChanges = function () {
17141
+ var _this = this;
17142
+ this.get('template').valueChanges.subscribe(function (template) {
17143
+ _this.updateItemsForm(template);
17144
+ });
17145
+ };
17146
+ SoleInvoiceForm.prototype.updateItemsForm = function (template) {
17147
+ this.items.controls.forEach(function (itemForm) {
17148
+ itemForm.onTemplateChanged(template);
17149
+ });
17150
+ };
17151
+ return SoleInvoiceForm;
17152
+ }(AbstractForm));
17153
+
16929
17154
  var SoleInvoiceTemplateForm = /** @class */ (function (_super) {
16930
17155
  __extends(SoleInvoiceTemplateForm, _super);
16931
- function SoleInvoiceTemplateForm(invoiceTemplate) {
16932
- return _super.call(this, {
17156
+ function SoleInvoiceTemplateForm(invoiceTemplate, soleDetails) {
17157
+ var _this = _super.call(this, {
16933
17158
  name: new forms.FormControl(invoiceTemplate.name, forms.Validators.required),
16934
- isTaxIncluded: new forms.FormControl(invoiceTemplate.isTaxIncluded),
17159
+ // taxType always 'No Tax' when sole details are not GST registered
17160
+ taxType: new forms.FormControl({ value: invoiceTemplate.taxType, disabled: !soleDetails.isGST }, forms.Validators.required),
16935
17161
  term: new forms.FormControl(invoiceTemplate.term, [forms.Validators.required, forms.Validators.min(0)]),
16936
17162
  bankAccount: new forms.FormControl(invoiceTemplate.bankAccount, [forms.Validators.required])
16937
17163
  }, invoiceTemplate) || this;
17164
+ _this.soleDetails = soleDetails;
17165
+ return _this;
16938
17166
  }
16939
17167
  return SoleInvoiceTemplateForm;
16940
17168
  }(AbstractForm));
@@ -17006,17 +17234,13 @@
17006
17234
  function BankAccountAddManualForm(connection) {
17007
17235
  var _this = _super.call(this) || this;
17008
17236
  _this.connection = connection;
17009
- _this
17010
- .addControl('type', new forms.FormControl(null, forms.Validators.required))
17011
- .addControl('accountName', new forms.FormControl(null, forms.Validators.required))
17012
- .addControl('currentBalance', new forms.FormControl(null, forms.Validators.required))
17013
- .addControl('accountNumber', new forms.FormControl(null, [forms.Validators.required, forms.Validators.pattern(BankAccountAddManualForm.accountNumberPattern)]));
17014
- _this.listenEvents();
17237
+ _this.addControl('type', new forms.FormControl(null, forms.Validators.required));
17238
+ _this.addControl('accountName', new forms.FormControl(null, forms.Validators.required));
17239
+ _this.addControl('currentBalance', new forms.FormControl(null, forms.Validators.required));
17240
+ _this.addControl('accountNumber', new forms.FormControl(null, [forms.Validators.required, forms.Validators.pattern(BankAccountAddManualForm.accountNumberPattern)]));
17241
+ _this.listenTypeChanges();
17015
17242
  return _this;
17016
17243
  }
17017
- BankAccountAddManualForm.prototype.listenEvents = function () {
17018
- this.listenTypeChanges();
17019
- };
17020
17244
  /**
17021
17245
  * Add/Remove loan form depends on selected bank account type
17022
17246
  */
@@ -18054,7 +18278,10 @@
18054
18278
  exports.SoleForecast = SoleForecast;
18055
18279
  exports.SoleForecastService = SoleForecastService;
18056
18280
  exports.SoleInvoice = SoleInvoice;
18281
+ exports.SoleInvoiceForm = SoleInvoiceForm;
18057
18282
  exports.SoleInvoiceItem = SoleInvoiceItem;
18283
+ exports.SoleInvoiceItemForm = SoleInvoiceItemForm;
18284
+ exports.SoleInvoiceService = SoleInvoiceService;
18058
18285
  exports.SoleInvoiceTemplate = SoleInvoiceTemplate;
18059
18286
  exports.SoleInvoiceTemplateForm = SoleInvoiceTemplateForm;
18060
18287
  exports.SoleInvoiceTemplateService = SoleInvoiceTemplateService;