@senior-gestao-empresarial/erpx-components 3.16.0 → 3.16.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.
@@ -1832,73 +1832,53 @@
1832
1832
  _this.validateAllFormFields(control);
1833
1833
  });
1834
1834
  };
1835
- ErpTributosComponent.prototype.validateAllFieldsTributos = function () {
1835
+ /**
1836
+ * Executa a validação de todos os campos dos formulários dentro dos grupos.
1837
+ *
1838
+ * **Atenção:** Este método **não** deve ser utilizado no template.
1839
+ *
1840
+ * @returns `true` se todos os formulários forem válidos e nenhum valor de imposto for negativo; caso contrário, retorna `false`.
1841
+ */
1842
+ ErpTributosComponent.prototype.validate = function () {
1836
1843
  var _this = this;
1837
- if (this.isAnyTaxValueNegative())
1838
- return false;
1839
- var valueValid = true;
1840
- if (this.grupos && this.grupos != undefined && this.grupos.length > 0) {
1841
- this.grupos.map(function (grupo) {
1842
- grupo.item.map(function (it) {
1843
- Object.keys(it.formGroup.controls).forEach(function (field) {
1844
- var control = it.formGroup.get(field);
1845
- if (control instanceof forms.FormControl)
1846
- control.markAsDirty({ onlySelf: true });
1847
- else if (control instanceof forms.FormGroup)
1848
- _this.validateAllFieldsTributos();
1849
- });
1850
- if (it.formGroup.invalid) {
1851
- valueValid = false;
1852
- }
1853
- });
1844
+ var group = this.findGroupWithNegativeTaxValue();
1845
+ if (group) {
1846
+ this.messageService.add({
1847
+ severity: 'error',
1848
+ sticky: true,
1849
+ summary: this.translate.instant('erpx.tributos.error'),
1850
+ detail: this.translate.instant('erpx.tributos.error_tax_with_negative_tax_value', {
1851
+ tax: this.translate.instant("erpx.tributos.enum_grupo_tributo_" + group.grupoTributo.toLowerCase())
1852
+ })
1854
1853
  });
1854
+ return false;
1855
1855
  }
1856
- return valueValid;
1857
- };
1858
- ErpTributosComponent.prototype.isAnyTaxValueNegative = function () {
1859
- var e_1, _a, e_2, _b;
1860
- var _c;
1861
- try {
1862
- for (var _d = __values(this.grupos.filter(function (group) {
1863
- return group.grupoTributo === exports.EnumGrupoTributo.CBS ||
1864
- group.grupoTributo === exports.EnumGrupoTributo.IBS_ESTADUAL ||
1865
- group.grupoTributo === exports.EnumGrupoTributo.IBS_MUNICIPAL ||
1866
- group.grupoTributo === exports.EnumGrupoTributo.IBS_MUNICIPAL_DIFERIDO;
1867
- })), _e = _d.next(); !_e.done; _e = _d.next()) {
1868
- var group = _e.value;
1869
- try {
1870
- for (var _f = (e_2 = void 0, __values(group.item)), _g = _f.next(); !_g.done; _g = _f.next()) {
1871
- var item = _g.value;
1872
- var taxValue = new BigNumber((_c = item.formGroup.get('valor').value) !== null && _c !== void 0 ? _c : 0);
1873
- if (taxValue.isLessThan(0)) {
1874
- this.messageService.add({
1875
- severity: 'error',
1876
- summary: this.translate.instant('erpx.tributos.error'),
1877
- detail: this.translate.instant('erpx.tributos.error_tax_with_negative_tax_value', {
1878
- tax: this.translate.instant("erpx.tributos.enum_grupo_tributo_" + group.grupoTributo.toLowerCase())
1879
- })
1880
- });
1881
- return true;
1882
- }
1883
- }
1884
- }
1885
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1886
- finally {
1887
- try {
1888
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1889
- }
1890
- finally { if (e_2) throw e_2.error; }
1891
- }
1892
- }
1893
- }
1894
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1895
- finally {
1896
- try {
1897
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1898
- }
1899
- finally { if (e_1) throw e_1.error; }
1900
- }
1901
- return false;
1856
+ return this.grupos.every(function (group) {
1857
+ return group.item.every(function (item) {
1858
+ _this.validateAllFormFields(item.formGroup);
1859
+ return item.formGroup.valid;
1860
+ });
1861
+ });
1862
+ };
1863
+ /**
1864
+ * Verifica se algum formulário está inválido.
1865
+ *
1866
+ * Deve ser utilizado somente no template para controle de botões ou exibição de mensagens.
1867
+ *
1868
+ * @returns `true` se algum `formGroup` estiver inválido ou se algum valor de imposto for negativo.
1869
+ */
1870
+ ErpTributosComponent.prototype.isInvalid = function () {
1871
+ return !!this.findGroupWithNegativeTaxValue() || this.grupos.some(function (group) { return group.item.some(function (item) { return item.formGroup.invalid; }); });
1872
+ };
1873
+ ErpTributosComponent.prototype.findGroupWithNegativeTaxValue = function () {
1874
+ return this.grupos
1875
+ .filter(function (group) {
1876
+ return group.grupoTributo === exports.EnumGrupoTributo.CBS ||
1877
+ group.grupoTributo === exports.EnumGrupoTributo.IBS_ESTADUAL ||
1878
+ group.grupoTributo === exports.EnumGrupoTributo.IBS_MUNICIPAL ||
1879
+ group.grupoTributo === exports.EnumGrupoTributo.IBS_MUNICIPAL_DIFERIDO;
1880
+ })
1881
+ .find(function (group) { return group.item.some(function (item) { var _a; return new BigNumber((_a = item.formGroup.get('valor').value) !== null && _a !== void 0 ? _a : 0).isLessThan(0); }); });
1902
1882
  };
1903
1883
  ErpTributosComponent.prototype.backValue = function () {
1904
1884
  var _this = this;
@@ -1945,10 +1925,10 @@
1945
1925
  disabled: this.menuItemCBS,
1946
1926
  visible: this.podeAdicionarImpostoManual(),
1947
1927
  command: function () {
1948
- _this.montaCBS().forEach(function (value) {
1928
+ (_this.montaCBS().forEach(function (value) {
1949
1929
  _this.novoImpostoManual(value);
1950
1930
  }),
1951
- (_this.indexAccordion = [0]);
1931
+ (_this.indexAccordion = [0]));
1952
1932
  _this.changeDetector.detectChanges();
1953
1933
  }
1954
1934
  }, {
@@ -1956,10 +1936,10 @@
1956
1936
  disabled: this.menuItemIBSEstadual,
1957
1937
  visible: this.podeAdicionarImpostoManual(),
1958
1938
  command: function () {
1959
- _this.montaIBSEstadual().forEach(function (value) {
1939
+ (_this.montaIBSEstadual().forEach(function (value) {
1960
1940
  _this.novoImpostoManual(value);
1961
1941
  }),
1962
- (_this.indexAccordion = [0]);
1942
+ (_this.indexAccordion = [0]));
1963
1943
  _this.changeDetector.detectChanges();
1964
1944
  }
1965
1945
  }, {
@@ -1967,10 +1947,10 @@
1967
1947
  disabled: this.menuItemIBSMunicipal,
1968
1948
  visible: this.podeAdicionarImpostoManual(),
1969
1949
  command: function () {
1970
- _this.montaIBSMunicipal().forEach(function (value) {
1950
+ (_this.montaIBSMunicipal().forEach(function (value) {
1971
1951
  _this.novoImpostoManual(value);
1972
1952
  }),
1973
- (_this.indexAccordion = [0]);
1953
+ (_this.indexAccordion = [0]));
1974
1954
  _this.changeDetector.detectChanges();
1975
1955
  }
1976
1956
  }, {
@@ -1978,10 +1958,10 @@
1978
1958
  disabled: this.menuItemIS,
1979
1959
  visible: this.podeAdicionarImpostoManual(),
1980
1960
  command: function () {
1981
- _this.montaIS().forEach(function (value) {
1961
+ (_this.montaIS().forEach(function (value) {
1982
1962
  _this.novoImpostoManual(value);
1983
1963
  }),
1984
- (_this.indexAccordion = [0]);
1964
+ (_this.indexAccordion = [0]));
1985
1965
  _this.changeDetector.detectChanges();
1986
1966
  }
1987
1967
  }, {
@@ -1989,10 +1969,10 @@
1989
1969
  label: this.translate.instant('erpx.tributos.actions_retencao_funrural_label'),
1990
1970
  disabled: this.menuItemRetencoesFunrural,
1991
1971
  command: function () {
1992
- _this.montaRetencoesFunrural().forEach(function (value) {
1972
+ (_this.montaRetencoesFunrural().forEach(function (value) {
1993
1973
  _this.novoImpostoManual(value);
1994
1974
  }),
1995
- (_this.indexAccordion = [0]);
1975
+ (_this.indexAccordion = [0]));
1996
1976
  _this.changeDetector.detectChanges();
1997
1977
  }
1998
1978
  }, {
@@ -2000,10 +1980,10 @@
2000
1980
  label: this.translate.instant('erpx.tributos.actions_pis_label'),
2001
1981
  disabled: this.menuItemPis,
2002
1982
  command: function () {
2003
- _this.montaPis().forEach(function (value) {
1983
+ (_this.montaPis().forEach(function (value) {
2004
1984
  _this.novoImpostoManual(value);
2005
1985
  }),
2006
- (_this.indexAccordion = [0]);
1986
+ (_this.indexAccordion = [0]));
2007
1987
  _this.changeDetector.detectChanges();
2008
1988
  }
2009
1989
  }, {
@@ -2011,10 +1991,10 @@
2011
1991
  label: this.translate.instant('erpx.tributos.actions_cofins_label'),
2012
1992
  disabled: this.menuItemCofins,
2013
1993
  command: function () {
2014
- _this.montaCofins().forEach(function (value) {
1994
+ (_this.montaCofins().forEach(function (value) {
2015
1995
  _this.novoImpostoManual(value);
2016
1996
  }),
2017
- (_this.indexAccordion = [0]);
1997
+ (_this.indexAccordion = [0]));
2018
1998
  _this.changeDetector.detectChanges();
2019
1999
  }
2020
2000
  }, {
@@ -2022,10 +2002,10 @@
2022
2002
  label: this.translate.instant('erpx.tributos.actions_ipi_label'),
2023
2003
  disabled: this.menuItemIpi,
2024
2004
  command: function () {
2025
- _this.montaIpi().forEach(function (value) {
2005
+ (_this.montaIpi().forEach(function (value) {
2026
2006
  _this.novoImpostoManual(value);
2027
2007
  }),
2028
- (_this.indexAccordion = [0]);
2008
+ (_this.indexAccordion = [0]));
2029
2009
  _this.changeDetector.detectChanges();
2030
2010
  }
2031
2011
  }, {
@@ -2033,10 +2013,10 @@
2033
2013
  label: this.translate.instant('erpx.tributos.actions_icms_label'),
2034
2014
  disabled: this.menuItemIcms,
2035
2015
  command: function () {
2036
- _this.montaIcms().forEach(function (value) {
2016
+ (_this.montaIcms().forEach(function (value) {
2037
2017
  _this.novoImpostoManual(value);
2038
2018
  }),
2039
- (_this.indexAccordion = [0]);
2019
+ (_this.indexAccordion = [0]));
2040
2020
  _this.changeDetector.detectChanges();
2041
2021
  }
2042
2022
  });
@@ -2046,10 +2026,10 @@
2046
2026
  label: this.translate.instant('erpx.tributos.actions_importacoes_label'),
2047
2027
  disabled: this.menuItemImportacoes,
2048
2028
  command: function () {
2049
- _this.montaImportacoes().forEach(function (value) {
2029
+ (_this.montaImportacoes().forEach(function (value) {
2050
2030
  _this.novoImpostoManual(value, true);
2051
2031
  }),
2052
- (_this.indexAccordion = [0]);
2032
+ (_this.indexAccordion = [0]));
2053
2033
  _this.changeDetector.detectChanges();
2054
2034
  }
2055
2035
  });
@@ -2060,10 +2040,10 @@
2060
2040
  label: this.translate.instant('erpx.tributos.actions_iss_label'),
2061
2041
  disabled: this.menuItemIss,
2062
2042
  command: function () {
2063
- _this.montaIss().forEach(function (value) {
2043
+ (_this.montaIss().forEach(function (value) {
2064
2044
  _this.novoImpostoManual(value);
2065
2045
  }),
2066
- (_this.indexAccordion = [0]);
2046
+ (_this.indexAccordion = [0]));
2067
2047
  _this.changeDetector.detectChanges();
2068
2048
  }
2069
2049
  }, {
@@ -2071,10 +2051,10 @@
2071
2051
  label: this.translate.instant('erpx.tributos.actions_retencoes_label'),
2072
2052
  disabled: this.menuItemRetencoes,
2073
2053
  command: function () {
2074
- _this.montaRetencoes().forEach(function (value) {
2054
+ (_this.montaRetencoes().forEach(function (value) {
2075
2055
  _this.novoImpostoManual(value);
2076
2056
  }),
2077
- (_this.indexAccordion = [0]);
2057
+ (_this.indexAccordion = [0]));
2078
2058
  _this.changeDetector.detectChanges();
2079
2059
  }
2080
2060
  });
@@ -2085,10 +2065,10 @@
2085
2065
  label: this.translate.instant('erpx.tributos.actions_cide_label'),
2086
2066
  disabled: this.menuItemCideTecnologia,
2087
2067
  command: function () {
2088
- _this.montaCide().forEach(function (value) {
2068
+ (_this.montaCide().forEach(function (value) {
2089
2069
  _this.novoImpostoManual(value);
2090
2070
  }),
2091
- (_this.indexAccordion = [0]);
2071
+ (_this.indexAccordion = [0]));
2092
2072
  _this.changeDetector.detectChanges();
2093
2073
  }
2094
2074
  });
@@ -2098,19 +2078,19 @@
2098
2078
  label: this.translate.instant('erpx.tributos.actions_icms_credito_presumido_label'),
2099
2079
  disabled: this.menuItemIcmsCreditoPresumido,
2100
2080
  command: function () {
2101
- _this.montaIcmsCreditoPresumido().forEach(function (value) {
2081
+ (_this.montaIcmsCreditoPresumido().forEach(function (value) {
2102
2082
  _this.novoImpostoManual(value);
2103
2083
  }),
2104
- (_this.indexAccordion = [0]);
2084
+ (_this.indexAccordion = [0]));
2105
2085
  _this.changeDetector.detectChanges();
2106
2086
  }
2107
2087
  });
2108
2088
  return menu;
2109
2089
  };
2110
2090
  ErpTributosComponent.prototype.podeAdicionarImpostoManual = function () {
2111
- return this.featureReformaTributaria &&
2091
+ return (this.featureReformaTributaria &&
2112
2092
  this.documento !== exports.EnumTipoDocumento.NF_ENTRADA_COMPLEMENTAR &&
2113
- this.documento !== exports.EnumTipoDocumento.NF_ENTRADA_AJUSTE;
2093
+ this.documento !== exports.EnumTipoDocumento.NF_ENTRADA_AJUSTE);
2114
2094
  };
2115
2095
  ErpTributosComponent.prototype.montaIcmsCreditoPresumido = function () {
2116
2096
  if (this.menuItemIcmsCreditoPresumido)
@@ -3835,7 +3815,7 @@
3835
3815
  return (Number(number) + 1 / x).toFixed(decimals);
3836
3816
  };
3837
3817
  ErpTributosComponent.prototype.addPathCalculoValorRounded = function (it, baseCalculoKey, aliquotaKey, valorKey) {
3838
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
3818
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
3839
3819
  var form = it.formGroup;
3840
3820
  var baseCalculo = (_b = (_a = form.get(baseCalculoKey)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
3841
3821
  var aliquota = (_d = (_c = form.get(aliquotaKey)) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null;
@@ -3851,24 +3831,22 @@
3851
3831
  }
3852
3832
  var valorBruto = this.roundImposto((baseCalculo * aliquota) / 100, 2);
3853
3833
  var valorCalculadoAliquEfetiva = this.roundImposto((baseCalculo * aliquotaEfetiva) / 100, 2);
3854
- if (valorKey === 'valorBrutoImposto') {
3855
- (_k = form.get(valorKey)) === null || _k === void 0 ? void 0 : _k.patchValue(valorBruto, { emitEvent: false });
3856
- }
3834
+ form.get('valorBrutoImposto').patchValue(valorBruto, { emitEvent: false });
3857
3835
  if (isAliquotaEfetivaValida) {
3858
- (_l = form.get(valorKey)) === null || _l === void 0 ? void 0 : _l.patchValue(valorCalculadoAliquEfetiva, { emitEvent: false });
3836
+ (_k = form.get(valorKey)) === null || _k === void 0 ? void 0 : _k.patchValue(valorCalculadoAliquEfetiva, { emitEvent: false });
3859
3837
  }
3860
3838
  else {
3861
- (_m = form.get(valorKey)) === null || _m === void 0 ? void 0 : _m.patchValue(valorBruto, { emitEvent: false });
3839
+ (_l = form.get(valorKey)) === null || _l === void 0 ? void 0 : _l.patchValue(valorBruto, { emitEvent: false });
3862
3840
  }
3863
3841
  if (this.isReducaoDiferido(it)) {
3864
- (_o = form.get(valorKey)) === null || _o === void 0 ? void 0 : _o.patchValue(it.valorMenosDiferido, { emitEvent: false });
3842
+ (_m = form.get(valorKey)) === null || _m === void 0 ? void 0 : _m.patchValue(it.valorMenosDiferido, { emitEvent: false });
3865
3843
  }
3866
3844
  }
3867
3845
  else {
3868
- (_p = form.get(valorKey)) === null || _p === void 0 ? void 0 : _p.reset(null, { emitEvent: false });
3846
+ (_o = form.get(valorKey)) === null || _o === void 0 ? void 0 : _o.reset(null, { emitEvent: false });
3869
3847
  if (impostosReforma.includes(it.name)) {
3870
- (_q = form.get('valorBrutoImposto')) === null || _q === void 0 ? void 0 : _q.reset(null, { emitEvent: false });
3871
- (_r = form.get('aliquotaEfetiva')) === null || _r === void 0 ? void 0 : _r.reset(null, { emitEvent: false });
3848
+ (_p = form.get('valorBrutoImposto')) === null || _p === void 0 ? void 0 : _p.reset(null, { emitEvent: false });
3849
+ (_q = form.get('aliquotaEfetiva')) === null || _q === void 0 ? void 0 : _q.reset(null, { emitEvent: false });
3872
3850
  }
3873
3851
  }
3874
3852
  };