Skip to content

Commit

Permalink
Issue #458
Browse files Browse the repository at this point in the history
- Ora viene esportato uno zip che contiene l'esportazione precedente (corretta) e l'esportazione delle singole riconciliazioni.
  • Loading branch information
atatarelli committed Mar 21, 2022
1 parent 7b337f1 commit efca9af
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,17 @@ export class IncassiViewComponent implements IModalDialog, IExport, AfterViewIni

protected info: Riepilogo;

_quoteExport = ['titolo', 'tipologia', 'categoria', 'capitolo', 'articolo', 'accertamento', 'annoEsercizio', 'importo'];
_quoteLabel = {
capitolo: 'Capitolo',
annoEsercizio: 'Anno esercizio',
importo: 'Importo',
titolo: 'Titolo',
accertamento: 'Accertamento',
tipologia: 'Tipologia',
categoria: 'Categoria',
articolo: 'Articolo',
proprietaCustom: 'Proprieta custom'
};
_exportLabel = {
idDominio: 'Dominio',
idFlusso: 'Id Flusso',
iuv: 'IUV',
importo: 'Importo',
data: 'Data',
idPendenza: 'Id Pendenze',
tipoPendenza: 'Tipo pendenza',
idVocePendenza: 'Id voce pendenza',
datiAllegatiPendenza: 'Dati allegati pendenza',
datiAllegatiVocePendenza: 'Dati allegati voce pendenza'
};

_quoteExport = [];
_quoteLabel = null;
_exportLabel = null;
_quoteCount = 10;

constructor(public gps: GovpayService, public us: UtilService) {
if (GovRiconciliazioniConfig && GovRiconciliazioniConfig.quoteExport && GovRiconciliazioniConfig.quoteLabel && GovRiconciliazioniConfig.exportLabel) {
this._quoteExport = GovRiconciliazioniConfig.quoteExport;
this._quoteLabel = GovRiconciliazioniConfig.quoteLabel;
this._exportLabel = GovRiconciliazioniConfig.exportLabel;
this._exportLabel = GovRiconciliazioniConfig.exportLabel;
this._quoteCount = GovRiconciliazioniConfig.quoteCount || 10;
}
const _configRic: any = this.us.getConfigRiconciliazioni();
this._quoteExport = _configRic.quoteExport;
this._quoteLabel = _configRic.quoteLabel;
this._exportLabel = _configRic.exportLabel;
this._quoteCount = _configRic.quoteCount || 10;
}

ngAfterViewInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,12 +956,17 @@ export class SideListComponent implements OnInit, OnDestroy, IExport {
this.us.fullJson(_jsonData);
break;
case UtilService.EXPORT_INCASSI:
let _cloneJsondData = JSON.parse(JSON.stringify(_jsonData));
_cloneJsondData = _cloneJsondData.map((item) => {
item.dominio = item.dominio.idDominio;
return item;
});
this.us.fullJson(_cloneJsondData);
const _newExport = true;
if (_newExport) {
this._exportIncassi(_jsonData);
} else {
let _cloneJsondData = JSON.parse(JSON.stringify(_jsonData));
_cloneJsondData = _cloneJsondData.map((item) => {
item.dominio = item.dominio.idDominio;
return item;
});
this.us.fullJson(_cloneJsondData);
}
break;
case UtilService.EXPORT_RENDICONTAZIONI:
_jsonData = _jsonData.map((item) => {
Expand All @@ -975,4 +980,100 @@ export class SideListComponent implements OnInit, OnDestroy, IExport {
break;
}
}

_exportIncassi(data: any) {
const name = UtilService.TXT_INCASSI;
const zip: any = this.us.initZip();
const structure: any = {
names: [],
filenames: [],
json: []
};

this.us.updateProgress(true, 'Elaborazione in corso...', 'indeterminate', 0);

let _cloneJsondData = JSON.parse(JSON.stringify(data));
_cloneJsondData = _cloneJsondData.map((item) => {
item.dominio = item.dominio.idDominio;
return item;
});

structure.names.push('PagamentiRiconciliati.csv');
structure.filenames.push(name + '.csv');
structure.json.push(_cloneJsondData);

const chunk: any[] = [];
data.forEach(item => {
const _url = UtilService.URL_INCASSI + '/' + item.dominio.idDominio + '/' + item.idIncasso;
const chunkData: any = {
url: _url,
content: 'application/json',
type: 'json'
};
chunk.push(chunkData);
});

const _configRic = this.us.getConfigRiconciliazioni();
const urls = chunk.map(chk => chk.url);
const contents = chunk.map(chk => chk.content);
const types = chunk.map(chk => chk.type);
this.gps.multiExportService(urls, contents, types).subscribe(function (_responses) {
_responses.forEach((response, index) => {
const _json: any = JSON.parse(JSON.stringify(response.body));
const _riscossioni: any[] = [];
_json.riscossioni.forEach(risc => {
const quote = (risc.vocePendenza && risc.vocePendenza.contabilita) ? risc.vocePendenza.contabilita.quote : [];
const riscossione: any = {};
riscossione[_configRic.exportLabel['idDominio']] = _json.dominio.idDominio;
riscossione[_configRic.exportLabel['idFlusso']] = _json.idFlusso ? _json.idFlusso : '';
riscossione[_configRic.exportLabel['iuv']] = risc.iuv || '';
riscossione[_configRic.exportLabel['importo']] = risc.importo || 0;
riscossione[_configRic.exportLabel['data']] = risc.data || '';
riscossione[_configRic.exportLabel['idPendenza']] = risc.vocePendenza.pendenza.idPendenza || '';
riscossione[_configRic.exportLabel['tipoPendenza']] = risc.vocePendenza.pendenza.idTipoPendenza || '';
riscossione[_configRic.exportLabel['idVocePendenza']] = risc.vocePendenza.idVocePendenza || '';
riscossione[_configRic.exportLabel['datiAllegatiPendenza']] = risc.vocePendenza.pendenza.datiAllegati || '';
riscossione[_configRic.exportLabel['datiAllegatiVocePendenza']] = risc.vocePendenza.datiAllegati || '';

for (let i = 0; i < _configRic.quoteCount; i++) {
_configRic.quoteExport.forEach(key => {
const label = `${_configRic.quoteLabel[key]} ${i + 1}`;
riscossione[label] = (this.us.hasValue(quote[i])) ? quote[i][key] : '';
});
}

_riscossioni.push(riscossione);
});

const _fileName = _json.idFlusso ? _json.idFlusso : _json.iuv;
structure.names.push('PagamentiRiconciliati.csv');
structure.filenames.push(_fileName + '.csv');
structure.json.push(_riscossioni);
});

this.__loopElaborate(zip, structure, name);
}.bind(this),
(error) => {
this.us.updateProgress(false);
this.gps.updateSpinner(false);
this.us.onError(error);
});
}

__loopElaborate(zip: any, structure: any, name: string) {
setTimeout(() => {
if (structure.names.length !== 0) {
const data: any = this.us.jsonToCsv(structure.names[0], structure.json[0]);
this.us.addDataToZip(data, structure.filenames[0], zip);
this.us.updateProgress(true, 'Export in corso...', 'determinate', Math.trunc(100 / structure.names.length));
structure.names.shift();
structure.filenames.shift();
structure.json.shift();
this.__loopElaborate(zip, structure, name);
} else {
this.us.updateProgress(true, 'Export in corso...', 'determinate', 100);
this.us.saveZip(zip, name);
}
}, 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ declare let GovPayConfig: any;
declare let JSZip: any;
declare let FileSaver: any;

declare let GovRiconciliazioniConfig: any;

@Injectable()
export class UtilService {

Expand Down Expand Up @@ -1790,7 +1792,7 @@ export class UtilService {
case UtilService.INCASSI:
_list = [
new FormInput({ id: 'idFlusso', label: FormService.FORM_IDENTIFICATIVO_FLUSSO, type: UtilService.INPUT }),
new FormInput({ id: 'iuv', label: FormService.FORM_IUV, placeholder: FormService.FORM_PH_IUV, type: UtilService.INPUT }),
new FormInput({ id: 'iuv', label: FormService.FORM_IUV, placeholder: FormService.FORM_IUV, type: UtilService.INPUT }),
new FormInput({ id: 'sct', label: FormService.FORM_SCT, type: UtilService.INPUT }),
new FormInput({ id: 'idDominio', label: FormService.FORM_ENTE_CREDITORE, type: UtilService.FILTERABLE,
promise: { async: true, url: UtilService.RootByTOA() + UtilService.URL_DOMINI, mapFct: this.asyncElencoDominiPendenza.bind(this),
Expand Down Expand Up @@ -1993,4 +1995,47 @@ export class UtilService {
UtilService.DASHBOARD_LINKS_PARAMS = { method: null, params: [] };
}

// Config Riconciliazioni

getConfigRiconciliazioni() {
let _quoteExport = ['titolo', 'tipologia', 'categoria', 'capitolo', 'articolo', 'accertamento', 'annoEsercizio', 'importo'];
let _quoteLabel = {
capitolo: 'Capitolo',
annoEsercizio: 'Anno esercizio',
importo: 'Importo',
titolo: 'Titolo',
accertamento: 'Accertamento',
tipologia: 'Tipologia',
categoria: 'Categoria',
articolo: 'Articolo',
proprietaCustom: 'Proprieta custom'
};
let _exportLabel = {
idDominio: 'Dominio',
idFlusso: 'Id Flusso',
iuv: 'IUV',
importo: 'Importo',
data: 'Data',
idPendenza: 'Id Pendenze',
tipoPendenza: 'Tipo pendenza',
idVocePendenza: 'Id voce pendenza',
datiAllegatiPendenza: 'Dati allegati pendenza',
datiAllegatiVocePendenza: 'Dati allegati voce pendenza'
};
let _quoteCount = 10;

if (GovRiconciliazioniConfig && GovRiconciliazioniConfig.quoteExport && GovRiconciliazioniConfig.quoteLabel && GovRiconciliazioniConfig.exportLabel) {
_quoteExport = GovRiconciliazioniConfig.quoteExport;
_quoteLabel = GovRiconciliazioniConfig.quoteLabel;
_exportLabel = GovRiconciliazioniConfig.exportLabel;
_quoteCount = GovRiconciliazioniConfig.quoteCount || 10;
}

return {
quoteExport: _quoteExport,
quoteLabel : _quoteLabel,
exportLabel: _exportLabel,
quoteCount : _quoteCount
};
}
}

0 comments on commit efca9af

Please sign in to comment.