@senior-agronegocio/angular-components 0.0.9884 → 0.0.9885

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 (26) hide show
  1. package/bundles/senior-agronegocio-angular-components.umd.js +122 -65
  2. package/bundles/senior-agronegocio-angular-components.umd.js.map +1 -1
  3. package/bundles/senior-agronegocio-angular-components.umd.min.js +2 -2
  4. package/bundles/senior-agronegocio-angular-components.umd.min.js.map +1 -1
  5. package/components/modal-invoice-pj/for-fixation/modal-invoice-pj-for-fixation.component.d.ts +6 -5
  6. package/components/modal-invoice-pj/services/agro-invoice/interfaces.d.ts +2 -1
  7. package/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice-dto.d.ts +15 -0
  8. package/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice.service.d.ts +18 -0
  9. package/esm2015/components/modal-invoice-pj/for-fixation/modal-invoice-pj-for-fixation.component.js +43 -25
  10. package/esm2015/components/modal-invoice-pj/modal-invoice-pj-base.class.js +9 -4
  11. package/esm2015/components/modal-invoice-pj/services/agro-invoice/interfaces.js +1 -1
  12. package/esm2015/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice-dto.js +1 -0
  13. package/esm2015/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice.service.js +63 -0
  14. package/esm2015/services/producer-invoice/producer-invoice.service.js +4 -37
  15. package/esm5/components/modal-invoice-pj/for-fixation/modal-invoice-pj-for-fixation.component.js +52 -28
  16. package/esm5/components/modal-invoice-pj/modal-invoice-pj-base.class.js +15 -4
  17. package/esm5/components/modal-invoice-pj/services/agro-invoice/interfaces.js +1 -1
  18. package/esm5/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice-dto.js +1 -0
  19. package/esm5/components/modal-invoice-pj/services/producer-invoice-fixation/producer-invoice.service.js +71 -0
  20. package/esm5/services/producer-invoice/producer-invoice.service.js +4 -42
  21. package/fesm2015/senior-agronegocio-angular-components.js +99 -57
  22. package/fesm2015/senior-agronegocio-angular-components.js.map +1 -1
  23. package/fesm5/senior-agronegocio-angular-components.js +122 -65
  24. package/fesm5/senior-agronegocio-angular-components.js.map +1 -1
  25. package/package.json +1 -1
  26. package/services/producer-invoice/producer-invoice.service.d.ts +1 -4
@@ -5778,43 +5778,6 @@
5778
5778
  _this.translate = translate;
5779
5779
  return _this;
5780
5780
  }
5781
- ProducerInvoiceService.prototype.getTotalLinkedInInvoices = function (invoiceId, fixationId) {
5782
- return __awaiter(this, void 0, void 0, function () {
5783
- var filter;
5784
- var _this = this;
5785
- return __generator(this, function (_a) {
5786
- filter = "fixationItem.fixation.id eq '" + fixationId + "' " + ("and invoiceId in ('" + invoiceId.join("','") + "') ");
5787
- return [2 /*return*/, new Promise(function (resolve, reject) {
5788
- _this.list({
5789
- filterQuery: filter,
5790
- size: exports.AGRO_NUMBERS.ONE_HUNDRED,
5791
- }).subscribe({
5792
- next: function (data) {
5793
- var invoiceList = data.contents;
5794
- var producerInvoice = new Map();
5795
- if (invoiceList.length) {
5796
- invoiceList.forEach(function (invoice) {
5797
- var _a;
5798
- producerInvoice.set(invoice.invoiceId, ((_a = producerInvoice.get(invoice.invoiceId)) !== null && _a !== void 0 ? _a : 0) + invoice.linkedValue);
5799
- });
5800
- }
5801
- resolve(Array.from(producerInvoice.entries()).map(function (_a) {
5802
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
5803
- return {
5804
- invoiceId: key,
5805
- totalLinked: value,
5806
- };
5807
- }));
5808
- },
5809
- error: function (err) { return reject(new Error(typeof err === 'string' ? err : JSON.stringify(err))); },
5810
- });
5811
- })];
5812
- });
5813
- });
5814
- };
5815
- ProducerInvoiceService.prototype.deleteAllProducerInvoice = function (fixationId) {
5816
- return this.http.post(this.actionsUrl + "/deleteAllProducerInvoice", { fixationId: fixationId }).pipe(this.defaultCatch());
5817
- };
5818
5781
  ProducerInvoiceService.ctorParameters = function () { return [
5819
5782
  { type: http.HttpClient },
5820
5783
  { type: api.MessageService },
@@ -7780,6 +7743,7 @@
7780
7743
  this.gridLoading = true;
7781
7744
  this.dontHaveAnyInvoice = false;
7782
7745
  this.updateCurrentParams(event);
7746
+ var numberSearchValue = searchValue ? AgroNumberUtils.getNearInteger(searchValue) : null;
7783
7747
  var filterBody = {
7784
7748
  filter: {
7785
7749
  companyId: companyId,
@@ -7788,6 +7752,7 @@
7788
7752
  ruralEstateIds: [ruralEstateId],
7789
7753
  multiProducts: false,
7790
7754
  productId: this.options.productId,
7755
+ number: numberSearchValue,
7791
7756
  },
7792
7757
  pageRequest: {
7793
7758
  offset: this.currentParams.page,
@@ -7799,11 +7764,20 @@
7799
7764
  },
7800
7765
  };
7801
7766
  if (searchValue) {
7802
- searchValue = AgroNumberUtils.getNearInteger(searchValue).toString();
7767
+ searchValue = numberSearchValue.toString();
7803
7768
  }
7804
7769
  this.invoiceService
7805
7770
  .invoiceLookupFilter(filterBody)
7806
- .pipe(operators.takeUntil(this.ngUnsubscribe), operators.finalize(function () {
7771
+ .pipe(operators.takeUntil(this.ngUnsubscribe), operators.switchMap(function (result) { return __awaiter(_this, void 0, void 0, function () {
7772
+ return __generator(this, function (_a) {
7773
+ switch (_a.label) {
7774
+ case 0: return [4 /*yield*/, this.adaptResult(result)];
7775
+ case 1:
7776
+ _a.sent();
7777
+ return [2 /*return*/, result];
7778
+ }
7779
+ });
7780
+ }); }), operators.finalize(function () {
7807
7781
  _this.gridLoading = false;
7808
7782
  }))
7809
7783
  .subscribe(function (result) {
@@ -8036,6 +8010,66 @@
8036
8010
  return ModalInvoicePjForTransferModule;
8037
8011
  }());
8038
8012
 
8013
+ var ProducerInvoiceService$1 = /** @class */ (function (_super) {
8014
+ __extends(ProducerInvoiceService, _super);
8015
+ function ProducerInvoiceService(http, messageService, translate) {
8016
+ var _this = _super.call(this, http, messageService, "agro/fixation/entities/producerInvoice", "agro/fixation/actions", "agro/fixation/queries", translate) || this;
8017
+ _this.http = http;
8018
+ _this.messageService = messageService;
8019
+ _this.translate = translate;
8020
+ return _this;
8021
+ }
8022
+ ProducerInvoiceService.prototype.getTotalLinkedInInvoices = function (invoiceId, fixationId) {
8023
+ return __awaiter(this, void 0, void 0, function () {
8024
+ var filter;
8025
+ var _this = this;
8026
+ return __generator(this, function (_a) {
8027
+ filter = "fixationItem.fixation.id eq '" + fixationId + "' " + ("and externalInvoiceId in ('" + invoiceId.join("','") + "') ");
8028
+ return [2 /*return*/, new Promise(function (resolve, reject) {
8029
+ _this.list({
8030
+ filterQuery: filter,
8031
+ size: 100
8032
+ }).subscribe({
8033
+ next: function (data) {
8034
+ var invoiceList = data.contents;
8035
+ var producerInvoice = new Map();
8036
+ if (invoiceList.length) {
8037
+ invoiceList.forEach(function (invoice) {
8038
+ var _a;
8039
+ producerInvoice.set(invoice.invoiceId, ((_a = producerInvoice.get(invoice.invoiceId)) !== null && _a !== void 0 ? _a : 0) + invoice.linkedValue);
8040
+ });
8041
+ }
8042
+ resolve(Array.from(producerInvoice.entries()).map(function (_a) {
8043
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
8044
+ return {
8045
+ invoiceId: key,
8046
+ totalLinked: value
8047
+ };
8048
+ }));
8049
+ },
8050
+ error: function (err) { return reject(err instanceof Error ? err : new Error(String(err))); }
8051
+ });
8052
+ })];
8053
+ });
8054
+ });
8055
+ };
8056
+ ProducerInvoiceService.prototype.deleteAllProducerInvoice = function (fixationId) {
8057
+ return this.http.post(this.actionsUrl + "/deleteAllProducerInvoice", { fixationId: fixationId }).pipe(this.defaultCatch());
8058
+ };
8059
+ ProducerInvoiceService.ctorParameters = function () { return [
8060
+ { type: http.HttpClient },
8061
+ { type: api.MessageService },
8062
+ { type: LibTranslationService }
8063
+ ]; };
8064
+ ProducerInvoiceService.ɵprov = core["ɵɵdefineInjectable"]({ factory: function ProducerInvoiceService_Factory() { return new ProducerInvoiceService(core["ɵɵinject"](http.HttpClient), core["ɵɵinject"](api.MessageService), core["ɵɵinject"](LibTranslationService)); }, token: ProducerInvoiceService, providedIn: "root" });
8065
+ ProducerInvoiceService = __decorate([
8066
+ core.Injectable({
8067
+ providedIn: 'root'
8068
+ })
8069
+ ], ProducerInvoiceService);
8070
+ return ProducerInvoiceService;
8071
+ }(AgroEntityService));
8072
+
8039
8073
  var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
8040
8074
  __extends(ModalInvoicePjForFixationComponent, _super);
8041
8075
  function ModalInvoicePjForFixationComponent(translationService, invoiceService, localeService, kilogramPipe, currencyPipe, producerInvoiceService, messageService, datePipe) {
@@ -8049,12 +8083,17 @@
8049
8083
  _this.messageService = messageService;
8050
8084
  _this.datePipe = datePipe;
8051
8085
  _this.whenSelectInvoices = new core.EventEmitter();
8086
+ common.registerLocaleData(localePt);
8052
8087
  return _this;
8053
8088
  }
8054
8089
  ModalInvoicePjForFixationComponent.prototype.ngOnInit = function () {
8055
8090
  var _this = this;
8056
8091
  this.defineGridColumns();
8057
- this.gridFieldValuesMap = __assign(__assign({}, this.gridFieldValuesMap), { series: function (row) { return (row === null || row === void 0 ? void 0 : row.seriesLegal) || (row === null || row === void 0 ? void 0 : row.series) || row.series; }, totalValue: function (row) { return _this.currencyPipe.transform((row === null || row === void 0 ? void 0 : row.netTotalValue) || 0, 'BRL'); } });
8092
+ this.gridFieldValuesMap = __assign(__assign({}, this.gridFieldValuesMap), { series: function (row) { return (row === null || row === void 0 ? void 0 : row.seriesLegal) || (row === null || row === void 0 ? void 0 : row.series) || row.series; }, totalValue: function (row) {
8093
+ return _this.currencyPipe.transform(_this.getTotalValue(row) || 0, 'BRL', 'symbol', undefined, 'pt-BR');
8094
+ }, linkedValue: function (row) {
8095
+ return _this.currencyPipe.transform((row === null || row === void 0 ? void 0 : row.linkedValue) || 0, 'BRL', 'symbol', undefined, 'pt-BR');
8096
+ } });
8058
8097
  _super.prototype.ngOnInit.call(this);
8059
8098
  };
8060
8099
  ModalInvoicePjForFixationComponent.prototype.defineGridColumns = function () {
@@ -8076,7 +8115,7 @@
8076
8115
  };
8077
8116
  ModalInvoicePjForFixationComponent.prototype.beforeAdd = function (selectedInvoices) {
8078
8117
  if (selectedInvoices === null || selectedInvoices === void 0 ? void 0 : selectedInvoices.length) {
8079
- this.linkSelectedInvoicesInFixationItem();
8118
+ this.linkSelectedInvoicesInFixationItem(selectedInvoices);
8080
8119
  }
8081
8120
  return rxjs.of(rxjs.EMPTY).toPromise();
8082
8121
  };
@@ -8091,20 +8130,20 @@
8091
8130
  }
8092
8131
  _super.prototype.open.call(this);
8093
8132
  };
8094
- ModalInvoicePjForFixationComponent.prototype.linkSelectedInvoicesInFixationItem = function () {
8133
+ ModalInvoicePjForFixationComponent.prototype.linkSelectedInvoicesInFixationItem = function (selectedInvoices) {
8095
8134
  return __awaiter(this, void 0, void 0, function () {
8096
8135
  var entities;
8097
8136
  var _this = this;
8098
8137
  return __generator(this, function (_a) {
8099
8138
  switch (_a.label) {
8100
- case 0: return [4 /*yield*/, this.isValidAndSetLinkedValueInInvoices()];
8139
+ case 0: return [4 /*yield*/, this.isValidAndSetLinkedValueInInvoices(selectedInvoices)];
8101
8140
  case 1:
8102
8141
  if (!(_a.sent())) {
8103
8142
  this.gridLoading = false;
8104
8143
  return [2 /*return*/];
8105
8144
  }
8106
8145
  entities = []
8107
- .concat.apply([], __spread(this.selected.map(function (invoice) {
8146
+ .concat.apply([], __spread(selectedInvoices.map(function (invoice) {
8108
8147
  return _this.options.fixationItems.map(function (fixationItem) {
8109
8148
  var requiredValue = (fixationItem.requiredValue || 0) - (fixationItem.totalValueInvoices || 0);
8110
8149
  if (invoice.remainingValue <= 0 || requiredValue <= 0) {
@@ -8115,11 +8154,11 @@
8115
8154
  var body = {
8116
8155
  series: invoice === null || invoice === void 0 ? void 0 : invoice.series,
8117
8156
  number: String(invoice === null || invoice === void 0 ? void 0 : invoice.number),
8118
- invoiceId: invoice === null || invoice === void 0 ? void 0 : invoice.id,
8157
+ externalInvoiceId: invoice === null || invoice === void 0 ? void 0 : invoice.externalInvoiceId,
8119
8158
  linkedValue: valueToBeLinked,
8120
- totalValue: invoice === null || invoice === void 0 ? void 0 : invoice.totalValue,
8159
+ totalValue: _this.getTotalValue(invoice),
8121
8160
  issuanceDate: invoice === null || invoice === void 0 ? void 0 : invoice.issuanceDate,
8122
- fixationItem: fixationItem,
8161
+ fixationItem: { id: fixationItem === null || fixationItem === void 0 ? void 0 : fixationItem.id },
8123
8162
  };
8124
8163
  fixationItem.totalValueInvoices = (fixationItem.totalValueInvoices || 0) + valueToBeLinked;
8125
8164
  return body;
@@ -8145,19 +8184,25 @@
8145
8184
  });
8146
8185
  });
8147
8186
  };
8148
- ModalInvoicePjForFixationComponent.prototype.isValidAndSetLinkedValueInInvoices = function () {
8187
+ ModalInvoicePjForFixationComponent.prototype.isValidAndSetLinkedValueInInvoices = function (selectedInvoices) {
8149
8188
  return __awaiter(this, void 0, void 0, function () {
8150
8189
  var valorLinked, isValid;
8151
8190
  var _this = this;
8152
8191
  return __generator(this, function (_a) {
8153
8192
  switch (_a.label) {
8154
- case 0: return [4 /*yield*/, this.producerInvoiceService.getTotalLinkedInInvoices(this.selected.map(function (invoice) { return invoice.id; }), this.options.fixationId)];
8193
+ case 0: return [4 /*yield*/, this.producerInvoiceService.getTotalLinkedInInvoices(selectedInvoices.map(function (invoice) { return invoice.externalInvoiceId; }), this.options.fixationId)];
8155
8194
  case 1:
8156
8195
  valorLinked = _a.sent();
8196
+ selectedInvoices.forEach(function (invoice) {
8197
+ if (!invoice.totalValue) {
8198
+ invoice.totalValue = _this.getTotalValue(invoice);
8199
+ }
8200
+ });
8157
8201
  isValid = true;
8158
- this.selected.forEach(function (invoice) {
8202
+ selectedInvoices.forEach(function (invoice) {
8159
8203
  var _a;
8160
- invoice.linkedValue = ((_a = valorLinked.find(function (linked) { return linked.invoiceId === invoice.id; })) === null || _a === void 0 ? void 0 : _a.totalLinked) || 0;
8204
+ invoice.linkedValue =
8205
+ ((_a = valorLinked.find(function (linked) { return linked.externalInvoiceId === invoice.externalInvoiceId; })) === null || _a === void 0 ? void 0 : _a.totalLinked) || 0;
8161
8206
  if (invoice.linkedValue >= invoice.totalValue) {
8162
8207
  _this.messageService.add({
8163
8208
  severity: 'warn',
@@ -8174,9 +8219,13 @@
8174
8219
  });
8175
8220
  };
8176
8221
  ModalInvoicePjForFixationComponent.prototype.adaptResult = function (result) {
8222
+ var _a;
8177
8223
  return __awaiter(this, void 0, void 0, function () {
8178
- return __generator(this, function (_a) {
8179
- return [2 /*return*/, Promise.resolve(result)];
8224
+ return __generator(this, function (_b) {
8225
+ switch (_b.label) {
8226
+ case 0: return [4 /*yield*/, this.updateLinkedValueInGrid(((_a = result === null || result === void 0 ? void 0 : result.result) === null || _a === void 0 ? void 0 : _a.invoices) || [])];
8227
+ case 1: return [2 /*return*/, _b.sent()];
8228
+ }
8180
8229
  });
8181
8230
  });
8182
8231
  };
@@ -8184,21 +8233,20 @@
8184
8233
  this.options.fixationItems = [];
8185
8234
  return _super.prototype.cancel.call(this);
8186
8235
  };
8187
- ModalInvoicePjForFixationComponent.prototype.updateLinkedValueInGrid = function (rows) {
8236
+ ModalInvoicePjForFixationComponent.prototype.updateLinkedValueInGrid = function (result) {
8188
8237
  return __awaiter(this, void 0, void 0, function () {
8189
- var invoiceId, filter, listParams;
8190
- var _this = this;
8238
+ var externalInvoiceId, filter, listParams;
8191
8239
  return __generator(this, function (_a) {
8192
8240
  switch (_a.label) {
8193
8241
  case 0:
8194
- invoiceId = this.gridData.map(function (invoice) { return invoice.id; });
8242
+ externalInvoiceId = result.map(function (invoice) { return invoice.externalInvoiceId; });
8195
8243
  filter = "fixationItem.fixation.id eq '" + this.options.fixationId + "'";
8196
- if (invoiceId && invoiceId.length > 0) {
8197
- filter += "and invoiceId in ('" + invoiceId.join("','") + "') ";
8244
+ if (externalInvoiceId && externalInvoiceId.length > 0) {
8245
+ filter += "and externalInvoiceId in ('" + externalInvoiceId.join("','") + "') ";
8198
8246
  }
8199
8247
  listParams = {
8200
8248
  page: 0,
8201
- size: rows,
8249
+ size: result.length,
8202
8250
  filterQuery: filter,
8203
8251
  };
8204
8252
  return [4 /*yield*/, this.producerInvoiceService
@@ -8207,10 +8255,11 @@
8207
8255
  .toPromise()
8208
8256
  .then(function (producerInvoices) {
8209
8257
  producerInvoices === null || producerInvoices === void 0 ? void 0 : producerInvoices.contents.forEach(function (invoice) {
8210
- var gridInvoice = _this.gridData.find(function (item) { return item.id === invoice.invoiceId; });
8211
- if (gridInvoice) {
8212
- gridInvoice.linkedValue = invoice.linkedValue;
8213
- }
8258
+ var _a;
8259
+ (_a = result
8260
+ .filter(function (item) { return item.externalInvoiceId === invoice.externalInvoiceId; })) === null || _a === void 0 ? void 0 : _a.forEach(function (linkedInvoice) {
8261
+ linkedInvoice.linkedValue = invoice.linkedValue;
8262
+ });
8214
8263
  });
8215
8264
  })];
8216
8265
  case 1:
@@ -8220,13 +8269,21 @@
8220
8269
  });
8221
8270
  });
8222
8271
  };
8272
+ ModalInvoicePjForFixationComponent.prototype.getTotalValue = function (row) {
8273
+ var netTotalValue = row === null || row === void 0 ? void 0 : row.netTotalValue;
8274
+ if (netTotalValue) {
8275
+ return netTotalValue;
8276
+ }
8277
+ var items = (row === null || row === void 0 ? void 0 : row.items) || [];
8278
+ return items.reduce(function (total, item) { return total + (item.unitPrice || 0) * (item.quantity || 0); }, 0);
8279
+ };
8223
8280
  ModalInvoicePjForFixationComponent.ctorParameters = function () { return [
8224
8281
  { type: LibTranslationService },
8225
8282
  { type: AgroInvoiceService },
8226
8283
  { type: angularComponents.LocaleService },
8227
8284
  { type: KilogramPipe },
8228
8285
  { type: common.CurrencyPipe },
8229
- { type: ProducerInvoiceService },
8286
+ { type: ProducerInvoiceService$1 },
8230
8287
  { type: primeng.MessageService },
8231
8288
  { type: common.DatePipe }
8232
8289
  ]; };