@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
@@ -5602,43 +5602,6 @@ var ProducerInvoiceService = /** @class */ (function (_super) {
5602
5602
  _this.translate = translate;
5603
5603
  return _this;
5604
5604
  }
5605
- ProducerInvoiceService.prototype.getTotalLinkedInInvoices = function (invoiceId, fixationId) {
5606
- return __awaiter(this, void 0, void 0, function () {
5607
- var filter;
5608
- var _this = this;
5609
- return __generator(this, function (_a) {
5610
- filter = "fixationItem.fixation.id eq '" + fixationId + "' " + ("and invoiceId in ('" + invoiceId.join("','") + "') ");
5611
- return [2 /*return*/, new Promise(function (resolve, reject) {
5612
- _this.list({
5613
- filterQuery: filter,
5614
- size: AGRO_NUMBERS.ONE_HUNDRED,
5615
- }).subscribe({
5616
- next: function (data) {
5617
- var invoiceList = data.contents;
5618
- var producerInvoice = new Map();
5619
- if (invoiceList.length) {
5620
- invoiceList.forEach(function (invoice) {
5621
- var _a;
5622
- producerInvoice.set(invoice.invoiceId, ((_a = producerInvoice.get(invoice.invoiceId)) !== null && _a !== void 0 ? _a : 0) + invoice.linkedValue);
5623
- });
5624
- }
5625
- resolve(Array.from(producerInvoice.entries()).map(function (_a) {
5626
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
5627
- return {
5628
- invoiceId: key,
5629
- totalLinked: value,
5630
- };
5631
- }));
5632
- },
5633
- error: function (err) { return reject(new Error(typeof err === 'string' ? err : JSON.stringify(err))); },
5634
- });
5635
- })];
5636
- });
5637
- });
5638
- };
5639
- ProducerInvoiceService.prototype.deleteAllProducerInvoice = function (fixationId) {
5640
- return this.http.post(this.actionsUrl + "/deleteAllProducerInvoice", { fixationId: fixationId }).pipe(this.defaultCatch());
5641
- };
5642
5605
  ProducerInvoiceService.ctorParameters = function () { return [
5643
5606
  { type: HttpClient },
5644
5607
  { type: MessageService },
@@ -7604,6 +7567,7 @@ var ModalInvoicePjBase = /** @class */ (function () {
7604
7567
  this.gridLoading = true;
7605
7568
  this.dontHaveAnyInvoice = false;
7606
7569
  this.updateCurrentParams(event);
7570
+ var numberSearchValue = searchValue ? AgroNumberUtils.getNearInteger(searchValue) : null;
7607
7571
  var filterBody = {
7608
7572
  filter: {
7609
7573
  companyId: companyId,
@@ -7612,6 +7576,7 @@ var ModalInvoicePjBase = /** @class */ (function () {
7612
7576
  ruralEstateIds: [ruralEstateId],
7613
7577
  multiProducts: false,
7614
7578
  productId: this.options.productId,
7579
+ number: numberSearchValue,
7615
7580
  },
7616
7581
  pageRequest: {
7617
7582
  offset: this.currentParams.page,
@@ -7623,11 +7588,20 @@ var ModalInvoicePjBase = /** @class */ (function () {
7623
7588
  },
7624
7589
  };
7625
7590
  if (searchValue) {
7626
- searchValue = AgroNumberUtils.getNearInteger(searchValue).toString();
7591
+ searchValue = numberSearchValue.toString();
7627
7592
  }
7628
7593
  this.invoiceService
7629
7594
  .invoiceLookupFilter(filterBody)
7630
- .pipe(takeUntil(this.ngUnsubscribe), finalize(function () {
7595
+ .pipe(takeUntil(this.ngUnsubscribe), switchMap(function (result) { return __awaiter(_this, void 0, void 0, function () {
7596
+ return __generator(this, function (_a) {
7597
+ switch (_a.label) {
7598
+ case 0: return [4 /*yield*/, this.adaptResult(result)];
7599
+ case 1:
7600
+ _a.sent();
7601
+ return [2 /*return*/, result];
7602
+ }
7603
+ });
7604
+ }); }), finalize(function () {
7631
7605
  _this.gridLoading = false;
7632
7606
  }))
7633
7607
  .subscribe(function (result) {
@@ -7860,6 +7834,66 @@ var ModalInvoicePjForTransferModule = /** @class */ (function () {
7860
7834
  return ModalInvoicePjForTransferModule;
7861
7835
  }());
7862
7836
 
7837
+ var ProducerInvoiceService$1 = /** @class */ (function (_super) {
7838
+ __extends(ProducerInvoiceService, _super);
7839
+ function ProducerInvoiceService(http, messageService, translate) {
7840
+ var _this = _super.call(this, http, messageService, "agro/fixation/entities/producerInvoice", "agro/fixation/actions", "agro/fixation/queries", translate) || this;
7841
+ _this.http = http;
7842
+ _this.messageService = messageService;
7843
+ _this.translate = translate;
7844
+ return _this;
7845
+ }
7846
+ ProducerInvoiceService.prototype.getTotalLinkedInInvoices = function (invoiceId, fixationId) {
7847
+ return __awaiter(this, void 0, void 0, function () {
7848
+ var filter;
7849
+ var _this = this;
7850
+ return __generator(this, function (_a) {
7851
+ filter = "fixationItem.fixation.id eq '" + fixationId + "' " + ("and externalInvoiceId in ('" + invoiceId.join("','") + "') ");
7852
+ return [2 /*return*/, new Promise(function (resolve, reject) {
7853
+ _this.list({
7854
+ filterQuery: filter,
7855
+ size: 100
7856
+ }).subscribe({
7857
+ next: function (data) {
7858
+ var invoiceList = data.contents;
7859
+ var producerInvoice = new Map();
7860
+ if (invoiceList.length) {
7861
+ invoiceList.forEach(function (invoice) {
7862
+ var _a;
7863
+ producerInvoice.set(invoice.invoiceId, ((_a = producerInvoice.get(invoice.invoiceId)) !== null && _a !== void 0 ? _a : 0) + invoice.linkedValue);
7864
+ });
7865
+ }
7866
+ resolve(Array.from(producerInvoice.entries()).map(function (_a) {
7867
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
7868
+ return {
7869
+ invoiceId: key,
7870
+ totalLinked: value
7871
+ };
7872
+ }));
7873
+ },
7874
+ error: function (err) { return reject(err instanceof Error ? err : new Error(String(err))); }
7875
+ });
7876
+ })];
7877
+ });
7878
+ });
7879
+ };
7880
+ ProducerInvoiceService.prototype.deleteAllProducerInvoice = function (fixationId) {
7881
+ return this.http.post(this.actionsUrl + "/deleteAllProducerInvoice", { fixationId: fixationId }).pipe(this.defaultCatch());
7882
+ };
7883
+ ProducerInvoiceService.ctorParameters = function () { return [
7884
+ { type: HttpClient },
7885
+ { type: MessageService },
7886
+ { type: LibTranslationService }
7887
+ ]; };
7888
+ ProducerInvoiceService.ɵprov = ɵɵdefineInjectable({ factory: function ProducerInvoiceService_Factory() { return new ProducerInvoiceService(ɵɵinject(HttpClient), ɵɵinject(MessageService), ɵɵinject(LibTranslationService)); }, token: ProducerInvoiceService, providedIn: "root" });
7889
+ ProducerInvoiceService = __decorate([
7890
+ Injectable({
7891
+ providedIn: 'root'
7892
+ })
7893
+ ], ProducerInvoiceService);
7894
+ return ProducerInvoiceService;
7895
+ }(AgroEntityService));
7896
+
7863
7897
  var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7864
7898
  __extends(ModalInvoicePjForFixationComponent, _super);
7865
7899
  function ModalInvoicePjForFixationComponent(translationService, invoiceService, localeService, kilogramPipe, currencyPipe, producerInvoiceService, messageService, datePipe) {
@@ -7873,12 +7907,17 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7873
7907
  _this.messageService = messageService;
7874
7908
  _this.datePipe = datePipe;
7875
7909
  _this.whenSelectInvoices = new EventEmitter();
7910
+ registerLocaleData(localePt);
7876
7911
  return _this;
7877
7912
  }
7878
7913
  ModalInvoicePjForFixationComponent.prototype.ngOnInit = function () {
7879
7914
  var _this = this;
7880
7915
  this.defineGridColumns();
7881
- 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'); } });
7916
+ 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) {
7917
+ return _this.currencyPipe.transform(_this.getTotalValue(row) || 0, 'BRL', 'symbol', undefined, 'pt-BR');
7918
+ }, linkedValue: function (row) {
7919
+ return _this.currencyPipe.transform((row === null || row === void 0 ? void 0 : row.linkedValue) || 0, 'BRL', 'symbol', undefined, 'pt-BR');
7920
+ } });
7882
7921
  _super.prototype.ngOnInit.call(this);
7883
7922
  };
7884
7923
  ModalInvoicePjForFixationComponent.prototype.defineGridColumns = function () {
@@ -7900,7 +7939,7 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7900
7939
  };
7901
7940
  ModalInvoicePjForFixationComponent.prototype.beforeAdd = function (selectedInvoices) {
7902
7941
  if (selectedInvoices === null || selectedInvoices === void 0 ? void 0 : selectedInvoices.length) {
7903
- this.linkSelectedInvoicesInFixationItem();
7942
+ this.linkSelectedInvoicesInFixationItem(selectedInvoices);
7904
7943
  }
7905
7944
  return of(EMPTY).toPromise();
7906
7945
  };
@@ -7915,20 +7954,20 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7915
7954
  }
7916
7955
  _super.prototype.open.call(this);
7917
7956
  };
7918
- ModalInvoicePjForFixationComponent.prototype.linkSelectedInvoicesInFixationItem = function () {
7957
+ ModalInvoicePjForFixationComponent.prototype.linkSelectedInvoicesInFixationItem = function (selectedInvoices) {
7919
7958
  return __awaiter(this, void 0, void 0, function () {
7920
7959
  var entities;
7921
7960
  var _this = this;
7922
7961
  return __generator(this, function (_a) {
7923
7962
  switch (_a.label) {
7924
- case 0: return [4 /*yield*/, this.isValidAndSetLinkedValueInInvoices()];
7963
+ case 0: return [4 /*yield*/, this.isValidAndSetLinkedValueInInvoices(selectedInvoices)];
7925
7964
  case 1:
7926
7965
  if (!(_a.sent())) {
7927
7966
  this.gridLoading = false;
7928
7967
  return [2 /*return*/];
7929
7968
  }
7930
7969
  entities = []
7931
- .concat.apply([], __spread(this.selected.map(function (invoice) {
7970
+ .concat.apply([], __spread(selectedInvoices.map(function (invoice) {
7932
7971
  return _this.options.fixationItems.map(function (fixationItem) {
7933
7972
  var requiredValue = (fixationItem.requiredValue || 0) - (fixationItem.totalValueInvoices || 0);
7934
7973
  if (invoice.remainingValue <= 0 || requiredValue <= 0) {
@@ -7939,11 +7978,11 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7939
7978
  var body = {
7940
7979
  series: invoice === null || invoice === void 0 ? void 0 : invoice.series,
7941
7980
  number: String(invoice === null || invoice === void 0 ? void 0 : invoice.number),
7942
- invoiceId: invoice === null || invoice === void 0 ? void 0 : invoice.id,
7981
+ externalInvoiceId: invoice === null || invoice === void 0 ? void 0 : invoice.externalInvoiceId,
7943
7982
  linkedValue: valueToBeLinked,
7944
- totalValue: invoice === null || invoice === void 0 ? void 0 : invoice.totalValue,
7983
+ totalValue: _this.getTotalValue(invoice),
7945
7984
  issuanceDate: invoice === null || invoice === void 0 ? void 0 : invoice.issuanceDate,
7946
- fixationItem: fixationItem,
7985
+ fixationItem: { id: fixationItem === null || fixationItem === void 0 ? void 0 : fixationItem.id },
7947
7986
  };
7948
7987
  fixationItem.totalValueInvoices = (fixationItem.totalValueInvoices || 0) + valueToBeLinked;
7949
7988
  return body;
@@ -7969,19 +8008,25 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7969
8008
  });
7970
8009
  });
7971
8010
  };
7972
- ModalInvoicePjForFixationComponent.prototype.isValidAndSetLinkedValueInInvoices = function () {
8011
+ ModalInvoicePjForFixationComponent.prototype.isValidAndSetLinkedValueInInvoices = function (selectedInvoices) {
7973
8012
  return __awaiter(this, void 0, void 0, function () {
7974
8013
  var valorLinked, isValid;
7975
8014
  var _this = this;
7976
8015
  return __generator(this, function (_a) {
7977
8016
  switch (_a.label) {
7978
- case 0: return [4 /*yield*/, this.producerInvoiceService.getTotalLinkedInInvoices(this.selected.map(function (invoice) { return invoice.id; }), this.options.fixationId)];
8017
+ case 0: return [4 /*yield*/, this.producerInvoiceService.getTotalLinkedInInvoices(selectedInvoices.map(function (invoice) { return invoice.externalInvoiceId; }), this.options.fixationId)];
7979
8018
  case 1:
7980
8019
  valorLinked = _a.sent();
8020
+ selectedInvoices.forEach(function (invoice) {
8021
+ if (!invoice.totalValue) {
8022
+ invoice.totalValue = _this.getTotalValue(invoice);
8023
+ }
8024
+ });
7981
8025
  isValid = true;
7982
- this.selected.forEach(function (invoice) {
8026
+ selectedInvoices.forEach(function (invoice) {
7983
8027
  var _a;
7984
- invoice.linkedValue = ((_a = valorLinked.find(function (linked) { return linked.invoiceId === invoice.id; })) === null || _a === void 0 ? void 0 : _a.totalLinked) || 0;
8028
+ invoice.linkedValue =
8029
+ ((_a = valorLinked.find(function (linked) { return linked.externalInvoiceId === invoice.externalInvoiceId; })) === null || _a === void 0 ? void 0 : _a.totalLinked) || 0;
7985
8030
  if (invoice.linkedValue >= invoice.totalValue) {
7986
8031
  _this.messageService.add({
7987
8032
  severity: 'warn',
@@ -7998,9 +8043,13 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
7998
8043
  });
7999
8044
  };
8000
8045
  ModalInvoicePjForFixationComponent.prototype.adaptResult = function (result) {
8046
+ var _a;
8001
8047
  return __awaiter(this, void 0, void 0, function () {
8002
- return __generator(this, function (_a) {
8003
- return [2 /*return*/, Promise.resolve(result)];
8048
+ return __generator(this, function (_b) {
8049
+ switch (_b.label) {
8050
+ 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) || [])];
8051
+ case 1: return [2 /*return*/, _b.sent()];
8052
+ }
8004
8053
  });
8005
8054
  });
8006
8055
  };
@@ -8008,21 +8057,20 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
8008
8057
  this.options.fixationItems = [];
8009
8058
  return _super.prototype.cancel.call(this);
8010
8059
  };
8011
- ModalInvoicePjForFixationComponent.prototype.updateLinkedValueInGrid = function (rows) {
8060
+ ModalInvoicePjForFixationComponent.prototype.updateLinkedValueInGrid = function (result) {
8012
8061
  return __awaiter(this, void 0, void 0, function () {
8013
- var invoiceId, filter, listParams;
8014
- var _this = this;
8062
+ var externalInvoiceId, filter, listParams;
8015
8063
  return __generator(this, function (_a) {
8016
8064
  switch (_a.label) {
8017
8065
  case 0:
8018
- invoiceId = this.gridData.map(function (invoice) { return invoice.id; });
8066
+ externalInvoiceId = result.map(function (invoice) { return invoice.externalInvoiceId; });
8019
8067
  filter = "fixationItem.fixation.id eq '" + this.options.fixationId + "'";
8020
- if (invoiceId && invoiceId.length > 0) {
8021
- filter += "and invoiceId in ('" + invoiceId.join("','") + "') ";
8068
+ if (externalInvoiceId && externalInvoiceId.length > 0) {
8069
+ filter += "and externalInvoiceId in ('" + externalInvoiceId.join("','") + "') ";
8022
8070
  }
8023
8071
  listParams = {
8024
8072
  page: 0,
8025
- size: rows,
8073
+ size: result.length,
8026
8074
  filterQuery: filter,
8027
8075
  };
8028
8076
  return [4 /*yield*/, this.producerInvoiceService
@@ -8031,10 +8079,11 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
8031
8079
  .toPromise()
8032
8080
  .then(function (producerInvoices) {
8033
8081
  producerInvoices === null || producerInvoices === void 0 ? void 0 : producerInvoices.contents.forEach(function (invoice) {
8034
- var gridInvoice = _this.gridData.find(function (item) { return item.id === invoice.invoiceId; });
8035
- if (gridInvoice) {
8036
- gridInvoice.linkedValue = invoice.linkedValue;
8037
- }
8082
+ var _a;
8083
+ (_a = result
8084
+ .filter(function (item) { return item.externalInvoiceId === invoice.externalInvoiceId; })) === null || _a === void 0 ? void 0 : _a.forEach(function (linkedInvoice) {
8085
+ linkedInvoice.linkedValue = invoice.linkedValue;
8086
+ });
8038
8087
  });
8039
8088
  })];
8040
8089
  case 1:
@@ -8044,13 +8093,21 @@ var ModalInvoicePjForFixationComponent = /** @class */ (function (_super) {
8044
8093
  });
8045
8094
  });
8046
8095
  };
8096
+ ModalInvoicePjForFixationComponent.prototype.getTotalValue = function (row) {
8097
+ var netTotalValue = row === null || row === void 0 ? void 0 : row.netTotalValue;
8098
+ if (netTotalValue) {
8099
+ return netTotalValue;
8100
+ }
8101
+ var items = (row === null || row === void 0 ? void 0 : row.items) || [];
8102
+ return items.reduce(function (total, item) { return total + (item.unitPrice || 0) * (item.quantity || 0); }, 0);
8103
+ };
8047
8104
  ModalInvoicePjForFixationComponent.ctorParameters = function () { return [
8048
8105
  { type: LibTranslationService },
8049
8106
  { type: AgroInvoiceService },
8050
8107
  { type: LocaleService },
8051
8108
  { type: KilogramPipe },
8052
8109
  { type: CurrencyPipe },
8053
- { type: ProducerInvoiceService },
8110
+ { type: ProducerInvoiceService$1 },
8054
8111
  { type: MessageService$1 },
8055
8112
  { type: DatePipe }
8056
8113
  ]; };