@senior-gestao-empresarial/erpx-components 4.5.0 → 4.6.0

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 (37) hide show
  1. package/bundles/senior-gestao-empresarial-erpx-components.umd.js +756 -5
  2. package/bundles/senior-gestao-empresarial-erpx-components.umd.js.map +1 -1
  3. package/bundles/senior-gestao-empresarial-erpx-components.umd.min.js +2 -2
  4. package/bundles/senior-gestao-empresarial-erpx-components.umd.min.js.map +1 -1
  5. package/components/rateio-editor/erp-rateio-editor.component.d.ts +117 -0
  6. package/components/rateio-editor/erp-rateio-editor.converter.d.ts +18 -0
  7. package/components/rateio-editor/erp-rateio-editor.module.d.ts +2 -0
  8. package/components/rateio-editor/erp-rateio-editor.service.d.ts +17 -0
  9. package/components/rateio-editor/erp-rateio-editor.types.d.ts +149 -0
  10. package/components/rateio-editor/index.d.ts +4 -0
  11. package/esm2015/components/rateio-editor/erp-rateio-editor.component.js +555 -0
  12. package/esm2015/components/rateio-editor/erp-rateio-editor.converter.js +52 -0
  13. package/esm2015/components/rateio-editor/erp-rateio-editor.module.js +40 -0
  14. package/esm2015/components/rateio-editor/erp-rateio-editor.service.js +49 -0
  15. package/esm2015/components/rateio-editor/erp-rateio-editor.types.js +5 -0
  16. package/esm2015/components/rateio-editor/index.js +4 -0
  17. package/esm2015/locale/fallback.js +18 -2
  18. package/esm2015/public-api.js +2 -1
  19. package/esm2015/senior-gestao-empresarial-erpx-components.js +2 -1
  20. package/esm5/components/rateio-editor/erp-rateio-editor.component.js +601 -0
  21. package/esm5/components/rateio-editor/erp-rateio-editor.converter.js +68 -0
  22. package/esm5/components/rateio-editor/erp-rateio-editor.module.js +43 -0
  23. package/esm5/components/rateio-editor/erp-rateio-editor.service.js +51 -0
  24. package/esm5/components/rateio-editor/erp-rateio-editor.types.js +5 -0
  25. package/esm5/components/rateio-editor/index.js +4 -0
  26. package/esm5/locale/fallback.js +18 -2
  27. package/esm5/public-api.js +2 -1
  28. package/esm5/senior-gestao-empresarial-erpx-components.js +2 -1
  29. package/fesm2015/senior-gestao-empresarial-erpx-components.js +686 -3
  30. package/fesm2015/senior-gestao-empresarial-erpx-components.js.map +1 -1
  31. package/fesm5/senior-gestao-empresarial-erpx-components.js +751 -3
  32. package/fesm5/senior-gestao-empresarial-erpx-components.js.map +1 -1
  33. package/locale/fallback.d.ts +16 -0
  34. package/package.json +1 -1
  35. package/public-api.d.ts +1 -0
  36. package/senior-gestao-empresarial-erpx-components.d.ts +1 -0
  37. package/senior-gestao-empresarial-erpx-components.metadata.json +1 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@ngx-translate/core'), require('@senior-gestao-empresarial/angular-components'), require('@seniorsistemas/angular-components'), require('primeng/accordion'), require('@angular/forms'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/platform-utils'), require('bignumber.js'), require('primeng/api'), require('@ngrx/component-store'), require('@angular/common/http'), require('primeng'), require('moment'), require('primeng/confirmdialog'), require('primeng/messages'), require('primeng/panel'), require('primeng/table'), require('primeng/tabview')) :
3
- typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/erpx-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', '@ngx-translate/core', '@senior-gestao-empresarial/angular-components', '@seniorsistemas/angular-components', 'primeng/accordion', '@angular/forms', '@seniorsistemas/platform-components', '@seniorsistemas/platform-utils', 'bignumber.js', 'primeng/api', '@ngrx/component-store', '@angular/common/http', 'primeng', 'moment', 'primeng/confirmdialog', 'primeng/messages', 'primeng/panel', 'primeng/table', 'primeng/tabview'], factory) :
4
- (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['erpx-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.core$1, global.angularComponents, global.angularComponents$1, global.accordion, global.ng.forms, global.platformComponents, global.platformUtils, global.BigNumber, global.api, global.componentStore, global.ng.common.http, global.primeng, global.moment, global.confirmdialog, global.messages, global.panel, global.table, global.tabview));
5
- }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, core$1, angularComponents, angularComponents$1, accordion, forms, platformComponents, platformUtils, BigNumber, api, componentStore, http, primeng, moment, confirmdialog, messages, panel, table, tabview) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@ngx-translate/core'), require('@senior-gestao-empresarial/angular-components'), require('@seniorsistemas/angular-components'), require('primeng/accordion'), require('@angular/forms'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/platform-utils'), require('bignumber.js'), require('primeng/api'), require('@ngrx/component-store'), require('@angular/common/http'), require('primeng'), require('moment'), require('primeng/confirmdialog'), require('primeng/messages'), require('primeng/panel'), require('primeng/table'), require('primeng/tabview'), require('primeng/dialog')) :
3
+ typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/erpx-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', '@ngx-translate/core', '@senior-gestao-empresarial/angular-components', '@seniorsistemas/angular-components', 'primeng/accordion', '@angular/forms', '@seniorsistemas/platform-components', '@seniorsistemas/platform-utils', 'bignumber.js', 'primeng/api', '@ngrx/component-store', '@angular/common/http', 'primeng', 'moment', 'primeng/confirmdialog', 'primeng/messages', 'primeng/panel', 'primeng/table', 'primeng/tabview', 'primeng/dialog'], factory) :
4
+ (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['erpx-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.core$1, global.angularComponents, global.angularComponents$1, global.accordion, global.ng.forms, global.platformComponents, global.platformUtils, global.BigNumber, global.api, global.componentStore, global.ng.common.http, global.primeng, global.moment, global.confirmdialog, global.messages, global.panel, global.table, global.tabview, global.dialog));
5
+ }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, core$1, angularComponents, angularComponents$1, accordion, forms, platformComponents, platformUtils, BigNumber, api, componentStore, http, primeng, moment, confirmdialog, messages, panel, table, tabview, dialog) { 'use strict';
6
6
 
7
7
  BigNumber = BigNumber && Object.prototype.hasOwnProperty.call(BigNumber, 'default') ? BigNumber['default'] : BigNumber;
8
8
 
@@ -32963,13 +32963,760 @@
32963
32963
  return ErpLoteSerieModule;
32964
32964
  }());
32965
32965
 
32966
+ var ErpRateioEditorService = /** @class */ (function () {
32967
+ function ErpRateioEditorService(http, messageService) {
32968
+ this.http = http;
32969
+ this.messageService = messageService;
32970
+ this.baseQueries = 'erpx_fin_rat/rateio/queries';
32971
+ this.baseActions = 'erpx_fin_rat/rateio/actions';
32972
+ }
32973
+ ErpRateioEditorService.prototype.retornarRateio = function (input) {
32974
+ return this.http
32975
+ .post(this.baseQueries + "/retornarRateio", input)
32976
+ .pipe(this.defaultCatch());
32977
+ };
32978
+ ErpRateioEditorService.prototype.sugerirRateio = function (input) {
32979
+ return this.http
32980
+ .post(this.baseQueries + "/sugerirRateio", input)
32981
+ .pipe(this.defaultCatch());
32982
+ };
32983
+ ErpRateioEditorService.prototype.gravarRateioManual = function (input) {
32984
+ return this.http
32985
+ .post(this.baseActions + "/gravarRateioManual", input)
32986
+ .pipe(this.defaultCatch());
32987
+ };
32988
+ ErpRateioEditorService.prototype.defaultCatch = function () {
32989
+ var _this = this;
32990
+ return operators.catchError(function (err) {
32991
+ var _a;
32992
+ if (err) {
32993
+ var summary = (err === null || err === void 0 ? void 0 : err.status) ? String(err.status) : 'Error';
32994
+ var detail = ((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message) || (err === null || err === void 0 ? void 0 : err.statusText) || (err === null || err === void 0 ? void 0 : err.message) || 'Error';
32995
+ _this.messageService.add({ severity: 'error', summary: summary, detail: detail });
32996
+ }
32997
+ return rxjs.throwError(err);
32998
+ });
32999
+ };
33000
+ ErpRateioEditorService.ctorParameters = function () { return [
33001
+ { type: http.HttpClient },
33002
+ { type: api.MessageService }
33003
+ ]; };
33004
+ ErpRateioEditorService = __decorate([
33005
+ core.Injectable()
33006
+ ], ErpRateioEditorService);
33007
+ return ErpRateioEditorService;
33008
+ }());
33009
+
33010
+ var ErpRateioEditorComponent = /** @class */ (function () {
33011
+ function ErpRateioEditorComponent(fb, service, translate, e091PlfLookup, e044CcuLookup) {
33012
+ this.fb = fb;
33013
+ this.service = service;
33014
+ this.translate = translate;
33015
+ this.e091PlfLookup = e091PlfLookup;
33016
+ this.e044CcuLookup = e044CcuLookup;
33017
+ this.readOnly = false;
33018
+ this.showSugestaoButton = true;
33019
+ /**
33020
+ * Critério de rateio padrão usado pela API de sugestão.
33021
+ * Default: 'V3' (Despesas — Conta X C. Custos).
33022
+ */
33023
+ this.criRat = 'V3';
33024
+ // === OUTPUTS ===
33025
+ this.save = new core.EventEmitter();
33026
+ this.cancel = new core.EventEmitter();
33027
+ this.change = new core.EventEmitter();
33028
+ this.error = new core.EventEmitter();
33029
+ // === CONSTANTES EXPOSTAS AO TEMPLATE ===
33030
+ this.ButtonPriority = angularComponents$1.ButtonPriority;
33031
+ this.ButtonSize = angularComponents$1.ButtonSize;
33032
+ this.loading = false;
33033
+ this.selection = [];
33034
+ this.contasDataSource = [];
33035
+ this.editingRowBackup = null;
33036
+ this.editingCCBackup = null;
33037
+ // === MODAL CONTA FINANCEIRA ===
33038
+ this.displayContaDialog = false;
33039
+ this.editingContaIndex = null;
33040
+ // === MODAL CENTRO DE CUSTO ===
33041
+ this.displayCCDialog = false;
33042
+ this.editingCCContaIndex = null;
33043
+ this.editingCCIndex = null;
33044
+ this.ngUnsubscribe = new rxjs.Subject();
33045
+ this.formGroup = this.fb.group({
33046
+ contas: this.fb.array([])
33047
+ });
33048
+ }
33049
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "effectiveReadOnly", {
33050
+ get: function () {
33051
+ var _a;
33052
+ var ic = (_a = this.loadedContext) === null || _a === void 0 ? void 0 : _a.integracaoControladoria;
33053
+ var hasIntegracao = !!ic && (ic.contabilidade === true ||
33054
+ ic.tributos === true ||
33055
+ ic.patrimonio === true);
33056
+ return this.readOnly || hasIntegracao;
33057
+ },
33058
+ enumerable: true,
33059
+ configurable: true
33060
+ });
33061
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "contasFormArray", {
33062
+ get: function () {
33063
+ return this.formGroup.get('contas');
33064
+ },
33065
+ enumerable: true,
33066
+ configurable: true
33067
+ });
33068
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "valorBase", {
33069
+ get: function () {
33070
+ var _a, _b;
33071
+ return (_b = (_a = this.loadedContext) === null || _a === void 0 ? void 0 : _a.valorBase) !== null && _b !== void 0 ? _b : 0;
33072
+ },
33073
+ enumerable: true,
33074
+ configurable: true
33075
+ });
33076
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "percentualRestante", {
33077
+ get: function () {
33078
+ var _a;
33079
+ var soma = this.contasDataSource.reduce(function (acc, conta) { return acc + (conta.percentual || 0); }, 0);
33080
+ return +(100 - soma).toFixed((_a = this.config.percentageScale) !== null && _a !== void 0 ? _a : 4);
33081
+ },
33082
+ enumerable: true,
33083
+ configurable: true
33084
+ });
33085
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "valorRestante", {
33086
+ get: function () {
33087
+ var _a;
33088
+ var soma = this.contasDataSource.reduce(function (acc, conta) { return acc + (conta.valorRateadoConta || 0); }, 0);
33089
+ return +(this.valorBase - soma).toFixed((_a = this.config.currencyScale) !== null && _a !== void 0 ? _a : 2);
33090
+ },
33091
+ enumerable: true,
33092
+ configurable: true
33093
+ });
33094
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "numberFormatOptions", {
33095
+ get: function () {
33096
+ var _a, _b;
33097
+ if (this.currencyCode) {
33098
+ return {
33099
+ numberFormatOptions: {
33100
+ style: 'currency',
33101
+ currency: this.currencyCode
33102
+ }
33103
+ };
33104
+ }
33105
+ return {
33106
+ numberFormatOptions: {
33107
+ style: 'decimal',
33108
+ minimumFractionDigits: (_a = this.config.currencyScale) !== null && _a !== void 0 ? _a : 2,
33109
+ maximumFractionDigits: (_b = this.config.currencyScale) !== null && _b !== void 0 ? _b : 2
33110
+ }
33111
+ };
33112
+ },
33113
+ enumerable: true,
33114
+ configurable: true
33115
+ });
33116
+ ErpRateioEditorComponent.prototype.ngOnChanges = function (changes) {
33117
+ var movimentoChanged = changes.idMovimento || changes.tipoMovimento;
33118
+ if (movimentoChanged && this.idMovimento && this.tipoMovimento) {
33119
+ // Modo conectado: carrega via API
33120
+ this.carregarRateio();
33121
+ }
33122
+ else if (this.isStandalone && (changes.initialContext || changes.initialRateios || movimentoChanged)) {
33123
+ // Modo standalone: usa inputs diretos (mesmo que vazios)
33124
+ this.inicializarStandalone();
33125
+ }
33126
+ };
33127
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "rateios", {
33128
+ /** Retorna o conteúdo atual da grid (uso standalone — quem consome lê os rateios daqui). */
33129
+ get: function () {
33130
+ return this.contasDataSource;
33131
+ },
33132
+ enumerable: true,
33133
+ configurable: true
33134
+ });
33135
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "isStandalone", {
33136
+ /** Indica se o componente está operando sem idMovimento (modo standalone). */
33137
+ get: function () {
33138
+ return !this.idMovimento;
33139
+ },
33140
+ enumerable: true,
33141
+ configurable: true
33142
+ });
33143
+ Object.defineProperty(ErpRateioEditorComponent.prototype, "isReady", {
33144
+ /** Indica se o componente está pronto para exibir UI (modo conectado carregou OU modo standalone inicializado). */
33145
+ get: function () {
33146
+ return !!this.loadedContext || this.isStandalone;
33147
+ },
33148
+ enumerable: true,
33149
+ configurable: true
33150
+ });
33151
+ ErpRateioEditorComponent.prototype.ngOnDestroy = function () {
33152
+ this.ngUnsubscribe.next();
33153
+ this.ngUnsubscribe.complete();
33154
+ };
33155
+ // === AÇÕES PÚBLICAS ===
33156
+ ErpRateioEditorComponent.prototype.onSalvar = function () {
33157
+ var _this = this;
33158
+ if (this.effectiveReadOnly) {
33159
+ return;
33160
+ }
33161
+ var ctx = this.loadedContext;
33162
+ var input = {
33163
+ idMovimento: this.idMovimento,
33164
+ tipoMovimento: this.tipoMovimento,
33165
+ agrupadorId: ctx.agrupadorId,
33166
+ e070fil_id: ctx.e070fil.id,
33167
+ criterioRateio: ctx.criRat,
33168
+ dataBase: ctx.dataBase,
33169
+ dataMovimento: ctx.dataMovimento,
33170
+ rateios: this.contasDataSource
33171
+ };
33172
+ this.loading = true;
33173
+ this.service.gravarRateioManual(input)
33174
+ .pipe(operators.takeUntil(this.ngUnsubscribe), operators.finalize(function () { return (_this.loading = false); }))
33175
+ .subscribe(function () {
33176
+ _this.save.emit({ idMovimento: _this.idMovimento, tipoMovimento: _this.tipoMovimento, rateios: _this.contasDataSource });
33177
+ }, function (err) { var _a; return _this.error.emit({ operacao: 'save', message: ((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message) || (err === null || err === void 0 ? void 0 : err.message) || 'Erro ao salvar rateio', originalError: err }); });
33178
+ };
33179
+ ErpRateioEditorComponent.prototype.onSugerir = function () {
33180
+ var _this = this;
33181
+ var _a, _b;
33182
+ if (this.effectiveReadOnly || !this.showSugestaoButton) {
33183
+ return;
33184
+ }
33185
+ var ctx = this.loadedContext;
33186
+ var e070fil_id = this.filialId || ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.e070fil) === null || _a === void 0 ? void 0 : _a.id);
33187
+ var criterio = this.criRat || (ctx === null || ctx === void 0 ? void 0 : ctx.criRat);
33188
+ var valorBase = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.valorBase) !== null && _b !== void 0 ? _b : 0;
33189
+ if (!e070fil_id || !criterio) {
33190
+ return;
33191
+ }
33192
+ var parametro = {
33193
+ e070fil_id: e070fil_id,
33194
+ valorBase: valorBase,
33195
+ criRat: criterio,
33196
+ dataBase: ctx === null || ctx === void 0 ? void 0 : ctx.dataBase,
33197
+ dataMovimento: ctx === null || ctx === void 0 ? void 0 : ctx.dataMovimento
33198
+ };
33199
+ if (this.idMovimento) {
33200
+ parametro.idMovimento = this.idMovimento;
33201
+ }
33202
+ var input = {
33203
+ tipo: this.tipoMovimento,
33204
+ parametros: [parametro]
33205
+ };
33206
+ this.loading = true;
33207
+ this.service.sugerirRateio(input)
33208
+ .pipe(operators.takeUntil(this.ngUnsubscribe), operators.finalize(function () { return (_this.loading = false); }))
33209
+ .subscribe(function (resp) {
33210
+ var sugestao = (resp.sugestao || [])
33211
+ .find(function (s) { return !_this.idMovimento || s.idMovimento === _this.idMovimento; })
33212
+ || (resp.sugestao || [])[0];
33213
+ var rateio = sugestao === null || sugestao === void 0 ? void 0 : sugestao.rateio;
33214
+ if (!sugestao || !rateio || rateio.length === 0) {
33215
+ return;
33216
+ }
33217
+ _this.popularComRateios(rateio);
33218
+ _this.emitChange();
33219
+ }, function (err) { var _a; return _this.error.emit({ operacao: 'suggest', message: ((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message) || (err === null || err === void 0 ? void 0 : err.message) || 'Erro ao sugerir rateio', originalError: err }); });
33220
+ };
33221
+ // === MODAL CONTA FINANCEIRA ===
33222
+ ErpRateioEditorComponent.prototype.openContaDialog = function (editIndex) {
33223
+ var _this = this;
33224
+ var _a;
33225
+ this.editingContaIndex = editIndex != null ? editIndex : null;
33226
+ var remainingPct = this.editingContaIndex != null
33227
+ ? this.percentualRestante + this.contasDataSource[this.editingContaIndex].percentual
33228
+ : this.percentualRestante;
33229
+ var contaValue = null;
33230
+ var percentualValue = remainingPct > 0 ? remainingPct : null;
33231
+ var valorValue = percentualValue != null
33232
+ ? +((percentualValue / 100) * this.valorBase).toFixed((_a = this.config.currencyScale) !== null && _a !== void 0 ? _a : 2)
33233
+ : null;
33234
+ if (this.editingContaIndex != null) {
33235
+ var conta = this.contasDataSource[this.editingContaIndex];
33236
+ contaValue = { id: conta.idContaFinanceira, label: conta.contaFinanceira };
33237
+ percentualValue = conta.percentual;
33238
+ valorValue = conta.valorRateadoConta;
33239
+ }
33240
+ this.contaDialogFormGroup = this.fb.group({
33241
+ contaFinanceira: [{ value: contaValue, disabled: this.editingContaIndex != null }, forms.Validators.required],
33242
+ percentual: [{ value: percentualValue, disabled: false }, forms.Validators.required],
33243
+ valor: [{ value: valorValue, disabled: false }, forms.Validators.required]
33244
+ });
33245
+ this.setupPercentualValorSync(this.contaDialogFormGroup, function () { return _this.valorBase; });
33246
+ this.contaDialogFields = this.getContaDialogFields();
33247
+ this.displayContaDialog = true;
33248
+ };
33249
+ ErpRateioEditorComponent.prototype.onSaveContaDialog = function () {
33250
+ var _a;
33251
+ if (this.contaDialogFormGroup.invalid) {
33252
+ return;
33253
+ }
33254
+ var data = this.contaDialogFormGroup.getRawValue();
33255
+ var contaFinanceira = data.contaFinanceira;
33256
+ var percentual = Number(data.percentual) || 0;
33257
+ var valor = +(Number(data.valor) || 0).toFixed((_a = this.config.currencyScale) !== null && _a !== void 0 ? _a : 2);
33258
+ if (this.editingContaIndex != null) {
33259
+ var conta = this.contasDataSource[this.editingContaIndex];
33260
+ conta.percentual = percentual;
33261
+ conta.valorRateadoConta = valor;
33262
+ this.contasDataSource = __spread(this.contasDataSource);
33263
+ }
33264
+ else {
33265
+ var idContaFinanceira_1 = (contaFinanceira === null || contaFinanceira === void 0 ? void 0 : contaFinanceira.id) || '';
33266
+ var labelConta = (contaFinanceira === null || contaFinanceira === void 0 ? void 0 : contaFinanceira.label) || '';
33267
+ // Validação extra: bloqueia duplicidade
33268
+ var jaExiste = this.contasDataSource.some(function (c) { return c.idContaFinanceira === idContaFinanceira_1; });
33269
+ if (jaExiste) {
33270
+ this.contaDialogFormGroup.get('contaFinanceira').setErrors({ duplicate: true });
33271
+ return;
33272
+ }
33273
+ var novaConta = {
33274
+ idContaFinanceira: idContaFinanceira_1,
33275
+ contaFinanceira: labelConta,
33276
+ percentual: percentual,
33277
+ valorRateadoConta: valor,
33278
+ rateiosCCusto: []
33279
+ };
33280
+ this.contasDataSource = __spread(this.contasDataSource, [novaConta]);
33281
+ }
33282
+ this.displayContaDialog = false;
33283
+ this.emitChange();
33284
+ };
33285
+ ErpRateioEditorComponent.prototype.onHideContaDialog = function () {
33286
+ this.displayContaDialog = false;
33287
+ };
33288
+ // === MODAL CENTRO DE CUSTO ===
33289
+ ErpRateioEditorComponent.prototype.openCCDialog = function (contaIndex, editCCIndex) {
33290
+ var _this = this;
33291
+ var _a, _b;
33292
+ this.editingCCContaIndex = contaIndex;
33293
+ this.editingCCIndex = editCCIndex != null ? editCCIndex : null;
33294
+ var conta = this.contasDataSource[contaIndex];
33295
+ var ccList = conta.rateiosCCusto || [];
33296
+ var somaCC = ccList.reduce(function (acc, cc, i) { return acc + (i === _this.editingCCIndex ? 0 : (cc.percentual || 0)); }, 0);
33297
+ var remainingPct = +(100 - somaCC).toFixed((_a = this.config.percentageScale) !== null && _a !== void 0 ? _a : 4);
33298
+ var valorBaseCC = conta.valorRateadoConta || 0;
33299
+ var ccValue = null;
33300
+ var percentualValue = remainingPct > 0 ? remainingPct : null;
33301
+ var valorValue = percentualValue != null
33302
+ ? +((percentualValue / 100) * valorBaseCC).toFixed((_b = this.config.currencyScale) !== null && _b !== void 0 ? _b : 2)
33303
+ : null;
33304
+ if (this.editingCCIndex != null) {
33305
+ var cc = ccList[this.editingCCIndex];
33306
+ ccValue = { id: cc.idCentroCusto, label: cc.descCCusto || cc.idCentroCusto };
33307
+ percentualValue = cc.percentual;
33308
+ valorValue = cc.valor;
33309
+ }
33310
+ this.ccDialogFormGroup = this.fb.group({
33311
+ centroCusto: [{ value: ccValue, disabled: this.editingCCIndex != null }, forms.Validators.required],
33312
+ percentual: [{ value: percentualValue, disabled: false }, forms.Validators.required],
33313
+ valor: [{ value: valorValue, disabled: false }, forms.Validators.required]
33314
+ });
33315
+ this.setupPercentualValorSync(this.ccDialogFormGroup, function () { return valorBaseCC; });
33316
+ this.ccDialogFields = this.getCCDialogFields();
33317
+ this.displayCCDialog = true;
33318
+ };
33319
+ ErpRateioEditorComponent.prototype.onSaveCCDialog = function () {
33320
+ var _a;
33321
+ if (this.ccDialogFormGroup.invalid) {
33322
+ return;
33323
+ }
33324
+ var data = this.ccDialogFormGroup.getRawValue();
33325
+ var centroCusto = data.centroCusto;
33326
+ var percentual = Number(data.percentual) || 0;
33327
+ var valor = +(Number(data.valor) || 0).toFixed((_a = this.config.currencyScale) !== null && _a !== void 0 ? _a : 2);
33328
+ var conta = this.contasDataSource[this.editingCCContaIndex];
33329
+ if (this.editingCCIndex != null) {
33330
+ var cc = conta.rateiosCCusto[this.editingCCIndex];
33331
+ cc.percentual = percentual;
33332
+ cc.valor = valor;
33333
+ }
33334
+ else {
33335
+ var idCentroCusto_1 = (centroCusto === null || centroCusto === void 0 ? void 0 : centroCusto.id) || '';
33336
+ var labelCCusto = (centroCusto === null || centroCusto === void 0 ? void 0 : centroCusto.label) || '';
33337
+ // Validação extra: bloqueia duplicidade dentro da mesma conta
33338
+ var ccList = conta.rateiosCCusto || [];
33339
+ var jaExiste = ccList.some(function (cc) { return cc.idCentroCusto === idCentroCusto_1; });
33340
+ if (jaExiste) {
33341
+ this.ccDialogFormGroup.get('centroCusto').setErrors({ duplicate: true });
33342
+ return;
33343
+ }
33344
+ conta.rateiosCCusto = __spread(ccList, [{ idCentroCusto: idCentroCusto_1, descCCusto: labelCCusto, percentual: percentual, valor: valor }]);
33345
+ }
33346
+ this.contasDataSource = __spread(this.contasDataSource);
33347
+ this.displayCCDialog = false;
33348
+ this.emitChange();
33349
+ };
33350
+ ErpRateioEditorComponent.prototype.onHideCCDialog = function () {
33351
+ this.displayCCDialog = false;
33352
+ };
33353
+ // === AÇÕES DA TABELA ===
33354
+ ErpRateioEditorComponent.prototype.onDeleteSelected = function () {
33355
+ if (!this.selection.length) {
33356
+ return;
33357
+ }
33358
+ var idsToRemove = new Set(this.selection.map(function (s) { return s.idContaFinanceira; }));
33359
+ this.contasDataSource = this.contasDataSource.filter(function (c) { return !idsToRemove.has(c.idContaFinanceira); });
33360
+ this.selection = [];
33361
+ this.emitChange();
33362
+ };
33363
+ ErpRateioEditorComponent.prototype.removerConta = function (index) {
33364
+ this.contasDataSource = this.contasDataSource.filter(function (_, i) { return i !== index; });
33365
+ this.emitChange();
33366
+ };
33367
+ ErpRateioEditorComponent.prototype.removerCentroCusto = function (contaIndex, ccIndex) {
33368
+ var conta = this.contasDataSource[contaIndex];
33369
+ conta.rateiosCCusto = conta.rateiosCCusto.filter(function (_, i) { return i !== ccIndex; });
33370
+ this.contasDataSource = __spread(this.contasDataSource);
33371
+ this.emitChange();
33372
+ };
33373
+ ErpRateioEditorComponent.prototype.getMenuOptionsPerRow = function (rowData, rowIndex) {
33374
+ var _this = this;
33375
+ return [
33376
+ { label: this.translate.instant('erpx.rateio_editor.editar'), command: function () { return _this.openContaDialog(rowIndex); } },
33377
+ { label: this.translate.instant('erpx.rateio_editor.adicionar_centro_custo'), command: function () { return _this.openCCDialog(rowIndex); } },
33378
+ { label: this.translate.instant('erpx.rateio_editor.excluir'), command: function () { return _this.removerConta(rowIndex); } }
33379
+ ];
33380
+ };
33381
+ ErpRateioEditorComponent.prototype.getCCMenuOptions = function (contaIndex, ccIndex) {
33382
+ var _this = this;
33383
+ return [
33384
+ { label: this.translate.instant('erpx.rateio_editor.editar'), command: function () { return _this.openCCDialog(contaIndex, ccIndex); } },
33385
+ { label: this.translate.instant('erpx.rateio_editor.excluir'), command: function () { return _this.removerCentroCusto(contaIndex, ccIndex); } }
33386
+ ];
33387
+ };
33388
+ ErpRateioEditorComponent.prototype.getContaIndex = function (rowData) {
33389
+ return this.contasDataSource.indexOf(rowData);
33390
+ };
33391
+ // === PRIVADOS ===
33392
+ /** Inicializa o componente em modo standalone (sem chamada à API). */
33393
+ ErpRateioEditorComponent.prototype.inicializarStandalone = function () {
33394
+ var _a, _b, _c;
33395
+ this.loadedContext = (this.initialContext || {});
33396
+ this.popularComRateios(this.initialRateios || []);
33397
+ if (!this.empresaId) {
33398
+ this.empresaId = (_c = (_b = (_a = this.initialContext) === null || _a === void 0 ? void 0 : _a.e070fil) === null || _b === void 0 ? void 0 : _b.e070emp) === null || _c === void 0 ? void 0 : _c.id;
33399
+ }
33400
+ this.gridColumns = this.getGridColumns();
33401
+ };
33402
+ ErpRateioEditorComponent.prototype.carregarRateio = function () {
33403
+ var _this = this;
33404
+ this.loading = true;
33405
+ this.service
33406
+ .retornarRateio({ idMovimento: this.idMovimento, tipoMovimento: this.tipoMovimento })
33407
+ .pipe(operators.takeUntil(this.ngUnsubscribe), operators.finalize(function () { return (_this.loading = false); }))
33408
+ .subscribe(function (output) {
33409
+ _this.loadedContext = output;
33410
+ _this.popularComRateios(output.rateio || []);
33411
+ if (!_this.empresaId) {
33412
+ _this.empresaId = output.e070fil.e070emp.id;
33413
+ }
33414
+ _this.gridColumns = _this.getGridColumns();
33415
+ }, function (err) { var _a; return _this.error.emit({ operacao: 'load', message: ((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message) || (err === null || err === void 0 ? void 0 : err.message) || 'Erro ao carregar rateio', originalError: err }); });
33416
+ };
33417
+ ErpRateioEditorComponent.prototype.popularComRateios = function (rateios) {
33418
+ this.contasDataSource = __spread(rateios);
33419
+ };
33420
+ ErpRateioEditorComponent.prototype.getContaDialogFields = function () {
33421
+ var _this = this;
33422
+ var _a, _b;
33423
+ return [
33424
+ new angularComponents$1.FormField(__assign(__assign({}, this.e091PlfLookup.mountOptions({
33425
+ multiple: false,
33426
+ formGroup: 'contaFinanceira',
33427
+ defaultFilter: [
33428
+ { field: 'excluido', operator: angularComponents.EnumLogicalOperator.Eq, values: ['false'] },
33429
+ { field: 'e070emp', operator: angularComponents.EnumLogicalOperator.Eq, values: [this.empresaId] }
33430
+ ]
33431
+ })), { size: { sm: 12, md: 12, lg: 12, xl: 12 }, required: function () { return true; } })),
33432
+ new angularComponents$1.FormField({
33433
+ name: 'percentual',
33434
+ label: this.translate.instant('erpx.rateio_editor.percentual'),
33435
+ size: { sm: 12, md: 6, lg: 6, xl: 6 },
33436
+ type: angularComponents$1.FieldType.Double,
33437
+ precision: 7,
33438
+ scale: (_a = this.config.percentageScale) !== null && _a !== void 0 ? _a : 4,
33439
+ rightAddon: { label: '%' },
33440
+ required: function () { return true; }
33441
+ }),
33442
+ new angularComponents$1.FormField({
33443
+ name: 'valor',
33444
+ label: this.translate.instant('erpx.rateio_editor.valor'),
33445
+ size: { sm: 12, md: 6, lg: 6, xl: 6 },
33446
+ type: angularComponents$1.FieldType.Money,
33447
+ currenncy: function () { return _this.currencyCode; },
33448
+ precision: 18,
33449
+ scale: (_b = this.config.currencyScale) !== null && _b !== void 0 ? _b : 2,
33450
+ required: function () { return true; }
33451
+ })
33452
+ ];
33453
+ };
33454
+ ErpRateioEditorComponent.prototype.getCCDialogFields = function () {
33455
+ var _this = this;
33456
+ var _a, _b;
33457
+ return [
33458
+ new angularComponents$1.FormField(__assign(__assign({}, this.e044CcuLookup.mountOptions({
33459
+ multiple: false,
33460
+ formGroup: 'centroCusto',
33461
+ defaultFilter: [
33462
+ { field: 'excluido', operator: angularComponents.EnumLogicalOperator.Eq, values: ['false'] },
33463
+ { field: 'e070emp', operator: angularComponents.EnumLogicalOperator.Eq, values: [this.empresaId] }
33464
+ ]
33465
+ })), { size: { sm: 12, md: 12, lg: 12, xl: 12 }, required: function () { return true; } })),
33466
+ new angularComponents$1.FormField({
33467
+ name: 'percentual',
33468
+ label: this.translate.instant('erpx.rateio_editor.percentual'),
33469
+ size: { sm: 12, md: 6, lg: 6, xl: 6 },
33470
+ type: angularComponents$1.FieldType.Double,
33471
+ precision: 7,
33472
+ scale: (_a = this.config.percentageScale) !== null && _a !== void 0 ? _a : 4,
33473
+ rightAddon: { label: '%' },
33474
+ required: function () { return true; }
33475
+ }),
33476
+ new angularComponents$1.FormField({
33477
+ name: 'valor',
33478
+ label: this.translate.instant('erpx.rateio_editor.valor'),
33479
+ size: { sm: 12, md: 6, lg: 6, xl: 6 },
33480
+ type: angularComponents$1.FieldType.Money,
33481
+ currenncy: function () { return _this.currencyCode; },
33482
+ precision: 18,
33483
+ scale: (_b = this.config.currencyScale) !== null && _b !== void 0 ? _b : 2,
33484
+ required: function () { return true; }
33485
+ })
33486
+ ];
33487
+ };
33488
+ /**
33489
+ * Sincroniza os campos percentual e valor de um FormGroup de modal.
33490
+ * Quando o usuário altera percentual, recalcula valor (percentual/100 * base).
33491
+ * Quando o usuário altera valor, recalcula percentual (valor/base * 100).
33492
+ * O argumento getBase retorna a base usada no cálculo (valorBase global ou valorRateadoConta da conta pai).
33493
+ */
33494
+ ErpRateioEditorComponent.prototype.setupPercentualValorSync = function (form, getBase) {
33495
+ var _a, _b;
33496
+ var percentualScale = (_a = this.config.percentageScale) !== null && _a !== void 0 ? _a : 4;
33497
+ var currencyScale = (_b = this.config.currencyScale) !== null && _b !== void 0 ? _b : 2;
33498
+ form.get('percentual').valueChanges
33499
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
33500
+ .subscribe(function (pct) {
33501
+ var base = getBase();
33502
+ if (pct == null || base == null) {
33503
+ return;
33504
+ }
33505
+ var novoValor = +((Number(pct) / 100) * base).toFixed(currencyScale);
33506
+ if (Number(form.get('valor').value) !== novoValor) {
33507
+ form.get('valor').setValue(novoValor, { emitEvent: false });
33508
+ }
33509
+ });
33510
+ form.get('valor').valueChanges
33511
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
33512
+ .subscribe(function (val) {
33513
+ var base = getBase();
33514
+ if (val == null || !base) {
33515
+ return;
33516
+ }
33517
+ var novoPct = +((Number(val) / base) * 100).toFixed(percentualScale);
33518
+ if (Number(form.get('percentual').value) !== novoPct) {
33519
+ form.get('percentual').setValue(novoPct, { emitEvent: false });
33520
+ }
33521
+ });
33522
+ };
33523
+ ErpRateioEditorComponent.prototype.getGridColumns = function () {
33524
+ return [
33525
+ { field: 'contaFinanceira', header: this.translate.instant('erpx.rateio_editor.conta_financeira') },
33526
+ { field: 'percentual', header: this.translate.instant('erpx.rateio_editor.percentual') },
33527
+ { field: 'valorRateadoConta', header: this.translate.instant('erpx.rateio_editor.valor') }
33528
+ ];
33529
+ };
33530
+ ErpRateioEditorComponent.prototype.emitChange = function () {
33531
+ this.change.emit({
33532
+ isDirty: true,
33533
+ isValid: this.percentualRestante === 0 && this.valorRestante === 0,
33534
+ rateios: this.contasDataSource
33535
+ });
33536
+ };
33537
+ ErpRateioEditorComponent.ctorParameters = function () { return [
33538
+ { type: forms.FormBuilder },
33539
+ { type: ErpRateioEditorService },
33540
+ { type: core$1.TranslateService },
33541
+ { type: angularComponents.E091PlfLookup },
33542
+ { type: angularComponents.E044CcuLookup }
33543
+ ]; };
33544
+ __decorate([
33545
+ core.Input()
33546
+ ], ErpRateioEditorComponent.prototype, "idMovimento", void 0);
33547
+ __decorate([
33548
+ core.Input()
33549
+ ], ErpRateioEditorComponent.prototype, "tipoMovimento", void 0);
33550
+ __decorate([
33551
+ core.Input()
33552
+ ], ErpRateioEditorComponent.prototype, "readOnly", void 0);
33553
+ __decorate([
33554
+ core.Input()
33555
+ ], ErpRateioEditorComponent.prototype, "showSugestaoButton", void 0);
33556
+ __decorate([
33557
+ core.Input()
33558
+ ], ErpRateioEditorComponent.prototype, "config", void 0);
33559
+ __decorate([
33560
+ core.Input()
33561
+ ], ErpRateioEditorComponent.prototype, "initialContext", void 0);
33562
+ __decorate([
33563
+ core.Input()
33564
+ ], ErpRateioEditorComponent.prototype, "initialRateios", void 0);
33565
+ __decorate([
33566
+ core.Input()
33567
+ ], ErpRateioEditorComponent.prototype, "empresaId", void 0);
33568
+ __decorate([
33569
+ core.Input()
33570
+ ], ErpRateioEditorComponent.prototype, "filialId", void 0);
33571
+ __decorate([
33572
+ core.Input()
33573
+ ], ErpRateioEditorComponent.prototype, "criRat", void 0);
33574
+ __decorate([
33575
+ core.Input()
33576
+ ], ErpRateioEditorComponent.prototype, "currencyCode", void 0);
33577
+ __decorate([
33578
+ core.Output()
33579
+ ], ErpRateioEditorComponent.prototype, "save", void 0);
33580
+ __decorate([
33581
+ core.Output()
33582
+ ], ErpRateioEditorComponent.prototype, "cancel", void 0);
33583
+ __decorate([
33584
+ core.Output()
33585
+ ], ErpRateioEditorComponent.prototype, "change", void 0);
33586
+ __decorate([
33587
+ core.Output()
33588
+ ], ErpRateioEditorComponent.prototype, "error", void 0);
33589
+ __decorate([
33590
+ core.ViewChild('tableRateio')
33591
+ ], ErpRateioEditorComponent.prototype, "table", void 0);
33592
+ ErpRateioEditorComponent = __decorate([
33593
+ core.Component({
33594
+ selector: 'erp-rateio-editor',
33595
+ template: "<s-loading-state [loading]=\"loading\" [blockWindow]=\"true\">\n<p-panel styleClass=\"form-group\" [toggleable]=\"false\">\n\n <!-- Se\u00E7\u00E3o 1: Informa\u00E7\u00F5es do movimento -->\n <div class=\"sds-section-title\" *ngIf=\"isReady\">\n {{ 'erpx.rateio_editor.titulo' | translate }}\n </div>\n\n <div class=\"ui-g custom-stats\" *ngIf=\"isReady\">\n <div class=\"ui-sm-12 ui-md-4\">\n <s-stats-card\n [animateNumbers]=\"true\"\n color=\"#0C9348\"\n [lightMode]=\"true\"\n [lightVersion]=\"true\"\n iconClass=\"far fa-dollar-sign\"\n [label]=\"'erpx.rateio_editor.valor_base' | translate\"\n [value]=\"valorBase | numeric:numberFormatOptions | async\"\n ></s-stats-card>\n </div>\n <div class=\"ui-sm-12 ui-md-4\">\n <s-stats-card\n [animateNumbers]=\"true\"\n color=\"#428BCA\"\n [lightMode]=\"true\"\n [lightVersion]=\"true\"\n iconClass=\"far fa-percent\"\n [label]=\"'erpx.rateio_editor.percentual_restante' | translate\"\n [value]=\"percentualRestante + '%'\"\n ></s-stats-card>\n </div>\n <div class=\"ui-sm-12 ui-md-4\">\n <s-stats-card\n [animateNumbers]=\"true\"\n [color]=\"valorRestante === 0 ? '#0C9348' : '#C13018'\"\n [lightMode]=\"true\"\n [lightVersion]=\"true\"\n iconClass=\"far fa-dollar-sign\"\n [label]=\"'erpx.rateio_editor.valor_restante' | translate\"\n [value]=\"valorRestante | numeric:numberFormatOptions | async\"\n ></s-stats-card>\n </div>\n </div>\n\n <!-- Se\u00E7\u00E3o 2: Tabela de rateios -->\n <div class=\"sds-section-title\" *ngIf=\"isReady\">\n {{ 'erpx.rateio_editor.lista_rateios' | translate }}\n </div>\n\n <s-empty-state\n *ngIf=\"isReady && contasDataSource?.length === 0\"\n iconClass=\"far fa-dollar-sign\"\n [title]=\"'erpx.rateio_editor.sem_rateios_titulo' | translate\"\n [description]=\"'erpx.rateio_editor.sem_rateios_descricao' | translate\"\n ></s-empty-state>\n\n <div class=\"ui-g\" *ngIf=\"isReady && contasDataSource?.length > 0\">\n <div class=\"ui-g-12\" *ngIf=\"!effectiveReadOnly\">\n <s-button\n [label]=\"'erpx.rateio_editor.adicionar_conta' | translate\"\n iconClass=\"fa fa-plus\"\n (onClick)=\"openContaDialog()\"\n ></s-button>\n <s-button\n *ngIf=\"showSugestaoButton\"\n [label]=\"'erpx.rateio_editor.sugerir_rateio' | translate\"\n [priority]=\"ButtonPriority.Secondary\"\n iconClass=\"fa fa-magic\"\n (onClick)=\"onSugerir()\"\n ></s-button>\n <s-button\n [label]=\"'erpx.rateio_editor.remover_conta' | translate\"\n [priority]=\"ButtonPriority.Secondary\"\n (onClick)=\"onDeleteSelected()\"\n [disabled]=\"!selection.length\"\n ></s-button>\n </div>\n <div class=\"ui-g-12\">\n <p-table\n #tableRateio\n [value]=\"contasDataSource\"\n [columns]=\"gridColumns\"\n dataKey=\"idContaFinanceira\"\n [resizableColumns]=\"true\"\n [totalRecords]=\"contasDataSource.length\"\n [(selection)]=\"selection\"\n [paginator]=\"false\"\n [rows]=\"10\"\n >\n <ng-template pTemplate=\"header\" let-columns>\n <tr>\n <th scope=\"col\" style=\"width: 3em\"></th>\n <th scope=\"col\" class=\"col-checkbox\">\n <p-tableHeaderCheckbox *ngIf=\"!effectiveReadOnly\"></p-tableHeaderCheckbox>\n </th>\n <th *ngFor=\"let col of columns\" scope=\"col\" pResizableColumn>\n <div class=\"senior-header\">\n <span class=\"senior-header-title\">{{ col.header }}</span>\n </div>\n </th>\n <th scope=\"col\" *ngIf=\"!effectiveReadOnly\">\n <div class=\"senior-header\">\n <span class=\"senior-header-title\">{{ 'erpx.rateio_editor.acoes' | translate }}</span>\n </div>\n </th>\n </tr>\n </ng-template>\n\n <ng-template pTemplate=\"body\" let-rowData let-rowIndex=\"rowIndex\" let-expanded=\"expanded\">\n <tr>\n <td style=\"width: 3em; text-align: center\">\n <a *ngIf=\"rowData.rateiosCCusto?.length\" [pRowToggler]=\"rowData\" role=\"button\" tabindex=\"0\">\n <i [class]=\"expanded ? 'fa fa-minus' : 'fa fa-plus'\"></i>\n </a>\n </td>\n <td class=\"col-checkbox\">\n <p-tableCheckbox *ngIf=\"!effectiveReadOnly\" [value]=\"rowData\"></p-tableCheckbox>\n </td>\n <td>{{ rowData.contaFinanceira || rowData.idContaFinanceira }}</td>\n <td style=\"text-align: right\">{{ rowData.percentual }}</td>\n <td style=\"text-align: right\">{{ rowData.valorRateadoConta | numeric:numberFormatOptions | async }}</td>\n <td *ngIf=\"!effectiveReadOnly\">\n <s-button\n [auxiliary]=\"true\"\n [priority]=\"ButtonPriority.Default\"\n [size]=\"ButtonSize.Small\"\n [label]=\"'erpx.rateio_editor.acoes' | translate\"\n [menuOptions]=\"getMenuOptionsPerRow(rowData, rowIndex)\"\n ></s-button>\n </td>\n </tr>\n </ng-template>\n\n <ng-template pTemplate=\"rowexpansion\" let-rowData let-rowIndex=\"rowIndex\">\n <tr>\n <td [attr.colspan]=\"effectiveReadOnly ? gridColumns.length + 2 : gridColumns.length + 3\">\n <div class=\"ui-g\" style=\"padding: 8px 16px\">\n <p-table [value]=\"rowData.rateiosCCusto\" [responsive]=\"true\">\n <ng-template pTemplate=\"header\">\n <tr>\n <th scope=\"col\">{{ 'erpx.rateio_editor.centro_custo' | translate }}</th>\n <th scope=\"col\">{{ 'erpx.rateio_editor.percentual' | translate }}</th>\n <th scope=\"col\">{{ 'erpx.rateio_editor.valor' | translate }}</th>\n <th scope=\"col\" *ngIf=\"!effectiveReadOnly\">{{ 'erpx.rateio_editor.acoes' | translate }}</th>\n </tr>\n </ng-template>\n <ng-template pTemplate=\"body\" let-cc let-ccIndex=\"rowIndex\">\n <tr>\n <td>{{ cc.descCCusto || cc.idCentroCusto }}</td>\n <td style=\"text-align: right\">{{ cc.percentual }}</td>\n <td style=\"text-align: right\">{{ cc.valor | numeric:numberFormatOptions | async }}</td>\n <td *ngIf=\"!effectiveReadOnly\">\n <s-button\n [auxiliary]=\"true\"\n [priority]=\"ButtonPriority.Default\"\n [size]=\"ButtonSize.Small\"\n [label]=\"'erpx.rateio_editor.acoes' | translate\"\n [menuOptions]=\"getCCMenuOptions(getContaIndex(rowData), ccIndex)\"\n ></s-button>\n </td>\n </tr>\n </ng-template>\n <ng-template pTemplate=\"emptymessage\">\n <tr>\n <td [attr.colspan]=\"effectiveReadOnly ? 3 : 4\">\n {{ 'erpx.rateio_editor.sem_centros_custo' | translate }}\n </td>\n </tr>\n </ng-template>\n </p-table>\n </div>\n </td>\n </tr>\n </ng-template>\n </p-table>\n </div>\n </div>\n\n <!-- Bot\u00F5es de a\u00E7\u00E3o -->\n <div *ngIf=\"isReady\" class=\"ui-g rateio-editor-actions\">\n <div class=\"ui-g-12\">\n <div *ngIf=\"!effectiveReadOnly && contasDataSource?.length === 0\" style=\"margin-bottom: 8px\">\n <s-button\n [label]=\"'erpx.rateio_editor.adicionar_conta' | translate\"\n iconClass=\"fa fa-plus\"\n (onClick)=\"openContaDialog()\"\n ></s-button>\n <s-button\n *ngIf=\"showSugestaoButton\"\n [label]=\"'erpx.rateio_editor.sugerir_rateio' | translate\"\n [priority]=\"ButtonPriority.Secondary\"\n iconClass=\"fa fa-magic\"\n (onClick)=\"onSugerir()\"\n ></s-button>\n </div>\n <s-button\n *ngIf=\"!effectiveReadOnly && !isStandalone\"\n priority=\"primary\"\n iconClass=\"fa fa-check\"\n [label]=\"'erpx.rateio_editor.salvar' | translate\"\n (onClick)=\"onSalvar()\"\n ></s-button>\n </div>\n </div>\n\n</p-panel>\n</s-loading-state>\n\n<!-- Modal: Adicionar/Editar Conta Financeira -->\n<p-dialog\n [header]=\"'erpx.rateio_editor.adicionar_conta' | translate\"\n appendTo=\"body\"\n [modal]=\"true\"\n [(visible)]=\"displayContaDialog\"\n (onHide)=\"onHideContaDialog()\"\n [blockScroll]=\"true\"\n [focusOnShow]=\"false\"\n styleClass=\"custom-dialog\"\n [draggable]=\"false\"\n [resizable]=\"false\"\n [style]=\"{width: '40%'}\"\n>\n <form *ngIf=\"contaDialogFormGroup\" [formGroup]=\"contaDialogFormGroup\" (ngSubmit)=\"onSaveContaDialog()\">\n <div class=\"ui-fluid\">\n <s-dynamic-form\n [fields]=\"contaDialogFields\"\n [form]=\"contaDialogFormGroup\"\n [errorMessages]=\"{\n required: ('erpx.rateio_editor.erro_obrigatorio' | translate),\n duplicate: ('erpx.rateio_editor.conta_duplicada' | translate)\n }\"\n ></s-dynamic-form>\n </div>\n </form>\n <p-footer>\n <s-button\n id=\"dialog-conta-save\"\n type=\"button\"\n priority=\"primary\"\n [label]=\"'erpx.rateio_editor.salvar' | translate\"\n (onClick)=\"onSaveContaDialog()\"\n ></s-button>\n <s-button\n id=\"dialog-conta-cancel\"\n type=\"button\"\n priority=\"secondary\"\n [label]=\"'erpx.rateio_editor.cancelar' | translate\"\n (onClick)=\"onHideContaDialog()\"\n ></s-button>\n </p-footer>\n</p-dialog>\n\n<!-- Modal: Adicionar/Editar Centro de Custo -->\n<p-dialog\n [header]=\"'erpx.rateio_editor.adicionar_centro_custo' | translate\"\n appendTo=\"body\"\n [modal]=\"true\"\n [(visible)]=\"displayCCDialog\"\n (onHide)=\"onHideCCDialog()\"\n [blockScroll]=\"true\"\n [focusOnShow]=\"false\"\n styleClass=\"custom-dialog\"\n [draggable]=\"false\"\n [resizable]=\"false\"\n [style]=\"{width: '40%'}\"\n>\n <form *ngIf=\"ccDialogFormGroup\" [formGroup]=\"ccDialogFormGroup\" (ngSubmit)=\"onSaveCCDialog()\">\n <div class=\"ui-fluid\">\n <s-dynamic-form\n [fields]=\"ccDialogFields\"\n [form]=\"ccDialogFormGroup\"\n [errorMessages]=\"{\n required: ('erpx.rateio_editor.erro_obrigatorio' | translate),\n duplicate: ('erpx.rateio_editor.centro_custo_duplicado' | translate)\n }\"\n ></s-dynamic-form>\n </div>\n </form>\n <p-footer>\n <s-button\n id=\"dialog-cc-save\"\n type=\"button\"\n priority=\"primary\"\n [label]=\"'erpx.rateio_editor.salvar' | translate\"\n (onClick)=\"onSaveCCDialog()\"\n ></s-button>\n <s-button\n id=\"dialog-cc-cancel\"\n type=\"button\"\n priority=\"secondary\"\n [label]=\"'erpx.rateio_editor.cancelar' | translate\"\n (onClick)=\"onHideCCDialog()\"\n ></s-button>\n </p-footer>\n</p-dialog>\n"
33596
+ })
33597
+ ], ErpRateioEditorComponent);
33598
+ return ErpRateioEditorComponent;
33599
+ }());
33600
+
33601
+ var ErpRateioEditorModule = /** @class */ (function () {
33602
+ function ErpRateioEditorModule() {
33603
+ }
33604
+ ErpRateioEditorModule = __decorate([
33605
+ core.NgModule({
33606
+ declarations: [ErpRateioEditorComponent],
33607
+ imports: [
33608
+ common.CommonModule,
33609
+ forms.FormsModule,
33610
+ forms.ReactiveFormsModule,
33611
+ core$1.TranslateModule,
33612
+ angularComponents$1.ButtonModule,
33613
+ angularComponents$1.DynamicFormModule,
33614
+ angularComponents$1.EmptyStateModule,
33615
+ angularComponents$1.LoadingStateModule,
33616
+ angularComponents$1.LocaleModule.forChild(),
33617
+ angularComponents.ErpLookupsModule,
33618
+ angularComponents$1.StatsCardModule,
33619
+ table.TableModule,
33620
+ angularComponents$1.TableModule,
33621
+ panel.PanelModule,
33622
+ dialog.DialogModule
33623
+ ],
33624
+ providers: [ErpRateioEditorService],
33625
+ exports: [ErpRateioEditorComponent]
33626
+ })
33627
+ ], ErpRateioEditorModule);
33628
+ return ErpRateioEditorModule;
33629
+ }());
33630
+
33631
+ /**
33632
+ * Converte entre o modelo plano (recDistribuicaoRateioManual — output de sugerirRateio)
33633
+ * e o modelo hierárquico (recRateioConta + recRateioCCusto — usado pelo form e pela gravação).
33634
+ */
33635
+ var ErpRateioEditorConverter = /** @class */ (function () {
33636
+ function ErpRateioEditorConverter() {
33637
+ }
33638
+ /**
33639
+ * Agrupa itens planos por conta financeira (e091plf_id), gerando a estrutura
33640
+ * hierárquica esperada pelo form e pela API gravarRateioManual.
33641
+ *
33642
+ * Regras:
33643
+ * - Itens com mesmo e091plf_id são agrupados em uma única RateioConta.
33644
+ * - Se e044ccu_id estiver preenchido, gera um RateioCCusto dentro da conta.
33645
+ * - Percentual e valor da conta são a soma dos itens agrupados.
33646
+ * - Labels (contaFinanceira, descCCusto) ficam vazios — devem ser resolvidos via lookup pelo componente.
33647
+ */
33648
+ ErpRateioEditorConverter.sugestaoPlanaParaHierarquica = function (planas) {
33649
+ var e_1, _a;
33650
+ if (!planas || planas.length === 0) {
33651
+ return [];
33652
+ }
33653
+ var porConta = new Map();
33654
+ try {
33655
+ for (var planas_1 = __values(planas), planas_1_1 = planas_1.next(); !planas_1_1.done; planas_1_1 = planas_1.next()) {
33656
+ var item = planas_1_1.value;
33657
+ var conta = porConta.get(item.e091plf_id);
33658
+ if (!conta) {
33659
+ conta = {
33660
+ idContaFinanceira: item.e091plf_id,
33661
+ contaFinanceira: '',
33662
+ idContaContabil: item.e045pla_id || null,
33663
+ contaContabil: null,
33664
+ idProjeto: item.e615prj_id || null,
33665
+ projeto: null,
33666
+ idFaseProjeto: item.e615fpj_id || null,
33667
+ faseProjeto: null,
33668
+ percentual: 0,
33669
+ valorRateadoConta: 0,
33670
+ rateiosCCusto: []
33671
+ };
33672
+ porConta.set(item.e091plf_id, conta);
33673
+ }
33674
+ conta.percentual += item.percentual;
33675
+ conta.valorRateadoConta += item.valor;
33676
+ if (item.e044ccu_id) {
33677
+ conta.rateiosCCusto.push({
33678
+ idCentroCusto: item.e044ccu_id,
33679
+ percentual: item.percentual,
33680
+ valor: item.valor
33681
+ });
33682
+ }
33683
+ }
33684
+ }
33685
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
33686
+ finally {
33687
+ try {
33688
+ if (planas_1_1 && !planas_1_1.done && (_a = planas_1.return)) _a.call(planas_1);
33689
+ }
33690
+ finally { if (e_1) throw e_1.error; }
33691
+ }
33692
+ return Array.from(porConta.values());
33693
+ };
33694
+ return ErpRateioEditorConverter;
33695
+ }());
33696
+
32966
33697
  var fallback = {
32967
33698
  "erpx.tributos.badge_tipo_calculo_imposto_info_sign_text_calculado": "Valor calculado pelo sistema conforme regras fiscais",
32968
33699
  "erpx.tributos.badge_tipo_calculo_imposto_info_sign_text_herdado": "Valor gerado por um processo de origem",
32969
33700
  "erpx.tributos.badge_tipo_calculo_imposto_info_sign_text_manual": "Valor informado manualmente pelo usuário",
32970
33701
  "erpx.tributos.badge_tipo_calculo_imposto_calculo_manual": "Cálculo manual",
32971
33702
  "erpx.tributos.badge_tipo_calculo_imposto_calculo_automatico": "Cálculo automático",
32972
- "erpx.tributos.badge_tipo_calculo_imposto_calculo_gerado_via_processo": "Cálculo gerado via processo"
33703
+ "erpx.tributos.badge_tipo_calculo_imposto_calculo_gerado_via_processo": "Cálculo gerado via processo",
33704
+ "erpx.rateio_editor.titulo": "Edição de Rateio",
33705
+ "erpx.rateio_editor.valor_base": "Valor base",
33706
+ "erpx.rateio_editor.valor_restante": "Valor restante",
33707
+ "erpx.rateio_editor.percentual_restante": "Percentual restante",
33708
+ "erpx.rateio_editor.adicionar_conta": "Adicionar conta financeira",
33709
+ "erpx.rateio_editor.remover_conta": "Remover conta",
33710
+ "erpx.rateio_editor.adicionar_centro_custo": "Adicionar centro de custo",
33711
+ "erpx.rateio_editor.remover_centro_custo": "Remover centro de custo",
33712
+ "erpx.rateio_editor.sugerir_rateio": "Sugerir rateio",
33713
+ "erpx.rateio_editor.salvar": "Salvar",
33714
+ "erpx.rateio_editor.cancelar": "Cancelar",
33715
+ "erpx.rateio_editor.error_soma_percentual_invalida": "A soma dos percentuais deve ser 100%",
33716
+ "erpx.rateio_editor.error_soma_valor_invalida": "A soma dos valores deve ser igual ao valor base",
33717
+ "erpx.rateio_editor.sem_parametrizacao": "Não há parametrização de rateio cadastrada para este movimento",
33718
+ "erpx.rateio_editor.salvo_com_sucesso_titulo": "Rateio salvo",
33719
+ "erpx.rateio_editor.salvo_com_sucesso_detalhe": "A distribuição foi gravada com sucesso"
32973
33720
  };
32974
33721
 
32975
33722
  exports.BreadcrumbComponent = BreadcrumbComponent;
@@ -32977,6 +33724,9 @@
32977
33724
  exports.Breakpoints = Breakpoints;
32978
33725
  exports.ErpLoteSerieComponent = ErpLoteSerieComponent;
32979
33726
  exports.ErpLoteSerieModule = ErpLoteSerieModule;
33727
+ exports.ErpRateioEditorComponent = ErpRateioEditorComponent;
33728
+ exports.ErpRateioEditorConverter = ErpRateioEditorConverter;
33729
+ exports.ErpRateioEditorModule = ErpRateioEditorModule;
32980
33730
  exports.ErpResumoModule = ErpResumoModule;
32981
33731
  exports.ErpTributosComponent = ErpTributosComponent;
32982
33732
  exports.ErpTributosModule = ErpTributosModule;
@@ -33009,6 +33759,7 @@
33009
33759
  exports.ɵbs = QuantidadeDisponivelDemandaService;
33010
33760
  exports.ɵbt = EntityService;
33011
33761
  exports.ɵbu = QuantidadeDisponivelDemandaModule;
33762
+ exports.ɵbv = ErpRateioEditorService;
33012
33763
  exports.ɵc = LoadingContext;
33013
33764
  exports.ɵd = ErpTributosService;
33014
33765
  exports.ɵe = RulesService;