Patch level :5.0
Files correlati : Ricompilazione Demo : [ ] Commento :importazione movimenti di budget con fase e controlli! git-svn-id: svn://10.65.10.50/trunk@16706 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
187a666ccb
commit
4f3b3bb920
277
crpa/crpa1.cpp
277
crpa/crpa1.cpp
@ -17,7 +17,8 @@
|
||||
|
||||
#include "crpa1a.h"
|
||||
|
||||
|
||||
#define DESCR_TESTATA TR("Movimento di budget importato")
|
||||
#define DESCR_RIGA TR("Riga movimento di budget importato")
|
||||
//---------------------------------
|
||||
// TAutomask
|
||||
//---------------------------------
|
||||
@ -129,8 +130,6 @@ class TBudget_Import : public TSkeleton_application
|
||||
TBudget_Import_file* _trasfile;
|
||||
TConfig* _configfile;
|
||||
TRelation* _relmovana;
|
||||
TCursor* _cur;
|
||||
TProgind* _prog;
|
||||
TString _lastfile;
|
||||
TString4 _codcaus;
|
||||
|
||||
@ -140,7 +139,9 @@ protected:
|
||||
void mask2ini();
|
||||
void ini2mask();
|
||||
bool transfer();
|
||||
void transfer_movimento(const TRecord_text& curr, TLog_report& log);
|
||||
void elabora_input(const TFilename& file, TLog_report& log);
|
||||
void movana_killer(const TAssoc_array& elenco, const bool kill_all);
|
||||
void transfer_movimento(const TArray& righe, TLog_report& log);
|
||||
const TString& ana2bill(const TString& contone) const;
|
||||
|
||||
long get_next_key();
|
||||
@ -190,35 +191,63 @@ const TString& TBudget_Import::ana2bill(const TString& contone) const
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void TBudget_Import::transfer_movimento(const TRecord_text& curr, TLog_report& log)
|
||||
//metodo di bassa lega che scrive veramente i movimenti analitici sui file movana e rmovana
|
||||
void TBudget_Import::transfer_movimento(const TArray& righe, TLog_report& log)
|
||||
{
|
||||
const TRecord_text& curr = (const TRecord_text&)righe[0];
|
||||
//TESTATA
|
||||
//-------
|
||||
//formato definitivo del tracciato record dei CSV da importare (vedi anche il file crpa1.ini):
|
||||
//codice commessa|conto|importo|inizio cms|fine cms
|
||||
//codice commessa|fase|conto|importo|inizio cms|fine cms
|
||||
TString codcms = curr.get(0);
|
||||
codcms.replace('_', '/');
|
||||
|
||||
const TString codconto = curr.get(1);
|
||||
const real soldini = curr.get(2);
|
||||
const TString16 str_dataini = curr.get(3);
|
||||
const TString16 str_datafine = curr.get(4);
|
||||
//controllo commesse
|
||||
const TRectype& rec_cms = cache().get(LF_COMMESSE, codcms);
|
||||
if (rec_cms.empty())
|
||||
{
|
||||
TString errore;
|
||||
errore << "La commessa " << codcms << " NON esiste!";
|
||||
log.log(2, errore);
|
||||
}
|
||||
|
||||
const TString16 str_dataini = curr.get(4);
|
||||
const TString16 str_datafine = curr.get(5);
|
||||
|
||||
//Controllo del formato date!
|
||||
//Preso atto che il nostro invincibile fuhrer cambia formato date ad ogni importazione, proviamo a..
|
||||
//..rendere piu' intelligente il povero programma
|
||||
const int dataini_len = str_dataini.len();
|
||||
TString4 gg = str_dataini.left(2);
|
||||
TString4 mm = str_dataini.mid(3,2);
|
||||
TString4 yy = str_dataini.right(2);
|
||||
TString4 yy;
|
||||
if (dataini_len == 8) //se la data ha 8 caratteri (es. 12/06/08)...
|
||||
{
|
||||
yy = str_dataini.right(2);
|
||||
yy.insert("20", 0);
|
||||
}
|
||||
else //se invece ne ha 10 (es.12/06/2008)...
|
||||
yy = str_dataini.right(4);
|
||||
|
||||
const TDate dataini(atoi(gg),atoi(mm),atoi(yy));
|
||||
const int annoes = dataini.year();
|
||||
|
||||
const int datafine_len = str_datafine.len();
|
||||
gg = str_datafine.left(2);
|
||||
mm = str_datafine.mid(3,2);
|
||||
if (datafine_len == 8)
|
||||
{
|
||||
yy = str_datafine.right(2);
|
||||
yy.insert("20", 0);
|
||||
}
|
||||
else
|
||||
yy = str_datafine.right(4);
|
||||
|
||||
const TDate datafine(atoi(gg),atoi(mm),atoi(yy));
|
||||
|
||||
//cerca il primo posto libero in movana
|
||||
long numreg = get_next_key();
|
||||
|
||||
//TESTATA
|
||||
//crea il movimento di prima nota da aggiungere a movana
|
||||
TAnal_mov movana(numreg);
|
||||
movana.zero(); //azzera per sicurezza
|
||||
@ -228,11 +257,56 @@ void TBudget_Import::transfer_movimento(const TRecord_text& curr, TLog_report& l
|
||||
movana.put(MOVANA_DATAREG, dataini);
|
||||
movana.put(MOVANA_DATACOMP, dataini);
|
||||
movana.put(MOVANA_DATAFCOMP, datafine);
|
||||
movana.put(MOVANA_DESCR, "Movimento di budget importato");
|
||||
movana.put(MOVANA_DESCR, DESCR_TESTATA);
|
||||
movana.put(MOVANA_CODCAUS, _codcaus);
|
||||
movana.put(MOVANA_TIPOMOV, 'P');
|
||||
movana.put(MOVANA_TOTDOC, soldini);
|
||||
|
||||
|
||||
//RIGHE
|
||||
//-----
|
||||
TImporto totdoc;
|
||||
for (int i = 0; i < righe.items(); i++)
|
||||
{
|
||||
const TRecord_text& curr = (const TRecord_text&)righe[i];
|
||||
|
||||
const TString codconto = curr.get(2);
|
||||
const real soldini = curr.get(3);
|
||||
|
||||
//controllo fase e/o sede
|
||||
TString fase, sede;
|
||||
if (_msk->get(F_CRPA_DIN)[0] == 'C')
|
||||
{
|
||||
//controllo fasi (ricordiamo che le fasi sono legate alle commesse nel crpa)
|
||||
fase = curr.get(1);
|
||||
if (fase.full())
|
||||
{
|
||||
TToken_string chiave = codcms;
|
||||
chiave.add(fase);
|
||||
const TRectype& rec_fase = cache().get(LF_FASI, chiave);
|
||||
if (rec_fase.empty())
|
||||
{
|
||||
TString errore;
|
||||
errore << "La fase " << fase << " NON esiste legata alla commessa" << codcms << "!";
|
||||
log.log(2, errore);
|
||||
}
|
||||
} //fase.full...
|
||||
}
|
||||
else //if(_msk->get_char(F_CRPA_DIN...
|
||||
{
|
||||
sede = curr.get(1);
|
||||
if (sede.full())
|
||||
{
|
||||
const TRectype& rec_sede = cache().get(LF_CDC, sede);
|
||||
if (rec_sede.empty())
|
||||
{
|
||||
TString errore;
|
||||
errore << "La sede " << sede << " NON esiste!";
|
||||
log.log(2, errore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//controllo conti
|
||||
TString query;
|
||||
TString tmp_codconto;
|
||||
tmp_codconto << "'" << codconto << "'";
|
||||
@ -246,7 +320,6 @@ void TBudget_Import::transfer_movimento(const TRecord_text& curr, TLog_report& l
|
||||
TString errore;
|
||||
errore << "Il sottoconto " << codconto << " NON esiste!";
|
||||
log.log(2, errore);
|
||||
return;
|
||||
}
|
||||
|
||||
if (items > 1)
|
||||
@ -264,7 +337,6 @@ void TBudget_Import::transfer_movimento(const TRecord_text& curr, TLog_report& l
|
||||
TString errore;
|
||||
errore << "Il conto analitico " << contone << " non corrisponde ad alcun conto contabile!";
|
||||
log.log(2, errore);
|
||||
return;
|
||||
}
|
||||
//deve stabilire se la sezione e' D o A in base all'indbil del conto analitico
|
||||
TAnal_bill anazio(contone);
|
||||
@ -277,37 +349,54 @@ void TBudget_Import::transfer_movimento(const TRecord_text& curr, TLog_report& l
|
||||
TString errore;
|
||||
errore << "Il conto analitico " << contone << " non ha un indicatore di bilancio!";
|
||||
log.log(2, errore);
|
||||
return;
|
||||
}
|
||||
//mette quella bastarda di sezione nel record
|
||||
movana.put(MOVANA_SEZIONE, sezione);
|
||||
//incrementa l'importo totlae del documento in base a quanto trovato su questa riga
|
||||
TImporto imp_riga(sezione, soldini);
|
||||
totdoc += imp_riga;
|
||||
|
||||
//controllo sulle date
|
||||
const TString16 curr_str_dataini = curr.get(4);
|
||||
const TString16 curr_str_datafine = curr.get(5);
|
||||
if (curr_str_dataini != str_dataini)
|
||||
{
|
||||
TString errore;
|
||||
errore << "La commessa " << codcms << " ha movimenti con date inizio competenza incongruenti";
|
||||
log.log(1, errore);
|
||||
}
|
||||
if (curr_str_datafine != str_datafine)
|
||||
{
|
||||
TString errore;
|
||||
errore << "La commessa " << codcms << " ha movimenti con date fine competenza incongruenti";
|
||||
log.log(1, errore);
|
||||
}
|
||||
|
||||
//RIGA
|
||||
//la riga sara' solo 1 per testata, almeno secondo l'attuale modalita' di import/export del CRPA
|
||||
TRectype& rec_rmovana = movana.new_row();
|
||||
|
||||
rec_rmovana.put(RMOVANA_ANNOES, annoes);
|
||||
rec_rmovana.put(RMOVANA_NUMREG ,numreg);
|
||||
rec_rmovana.put(RMOVANA_NUMRIG ,1);
|
||||
rec_rmovana.put(RMOVANA_SEZIONE ,sezione);
|
||||
rec_rmovana.put(RMOVANA_DATACOMP ,dataini);
|
||||
rec_rmovana.put(RMOVANA_CODCMS ,codcms);
|
||||
rec_rmovana.put(RMOVANA_NUMREG, numreg);
|
||||
rec_rmovana.put(RMOVANA_NUMRIG, i+1);
|
||||
rec_rmovana.put(RMOVANA_SEZIONE, sezione);
|
||||
rec_rmovana.put(RMOVANA_DATACOMP, dataini);
|
||||
rec_rmovana.put(RMOVANA_CODCMS, codcms);
|
||||
rec_rmovana.put(RMOVANA_CODFASE, fase);
|
||||
rec_rmovana.put(RMOVANA_CODCCOSTO, sede);
|
||||
rec_rmovana.put(RMOVANA_CODCONTO, contcon);
|
||||
rec_rmovana.put(RMOVANA_DESCR, "Riga movimento di budget importato");
|
||||
rec_rmovana.put(RMOVANA_DESCR, DESCR_RIGA);
|
||||
rec_rmovana.put(RMOVANA_IMPORTO, soldini);
|
||||
|
||||
}
|
||||
//scrive testata e riga e aggiorna i saldi (write() magggica!)
|
||||
movana.put(MOVANA_TOTDOC, totdoc.valore());
|
||||
movana.put(MOVANA_SEZIONE, totdoc.sezione());
|
||||
|
||||
TLocalisamfile testate(LF_MOVANA);
|
||||
movana.write(testate);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TBudget_Import::transfer()
|
||||
//metodo di eliminazione dei movana
|
||||
void TBudget_Import::movana_killer(const TAssoc_array& elenco, const bool kill_all)
|
||||
{
|
||||
//azzeramento preventivo di movimenti, righe e saldi di tipo P
|
||||
if (_msk->get(F_KILLOLD))
|
||||
{
|
||||
//accoppa i movimenti preventivi che hanno queste commesse
|
||||
TRelation relmovana(LF_MOVANA);
|
||||
TCursor curmovana(&relmovana, "TIPOMOV=='P'");
|
||||
|
||||
@ -319,11 +408,109 @@ bool TBudget_Import::transfer()
|
||||
TLocalisamfile movana(LF_MOVANA); //questo serve alla remove()
|
||||
|
||||
for (curmovana = 0; curmovana.pos() < nrec; ++curmovana)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
//si possono uccidere solo i movimenti importati in automatico
|
||||
const TString& descr = curmovana.curr().get(MOVANA_DESCR);
|
||||
if (descr == DESCR_TESTATA)
|
||||
{
|
||||
TAnal_mov anal_kill(curmovana.curr());
|
||||
anal_kill.remove(movana); //la remove() accoppa anche le righe collegate
|
||||
|
||||
const int original_rows = anal_kill.rows();
|
||||
int residual_rows = kill_all ? 0 : original_rows; //necessario perche', in caso di kill_all=true (genocidio)
|
||||
|
||||
//se e' un diradamento selettivo in base al codice commessa...
|
||||
if (!kill_all)
|
||||
{
|
||||
TString codcms;
|
||||
for (int i = original_rows; i > 0; i--)
|
||||
{
|
||||
codcms = anal_kill.body().row(i).get(RMOVANA_CODCMS);
|
||||
if (elenco.is_key(codcms))
|
||||
{
|
||||
anal_kill.body().destroy_row(i, true);
|
||||
residual_rows--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//controlla quante righe sono rimaste: se nessuna->accoppa il movimento, senno' lo riscrive con le..
|
||||
//..righe compattate (aggiunto il caso del movimento senza righe)
|
||||
if (residual_rows < original_rows || original_rows == 0)
|
||||
{
|
||||
if (residual_rows == 0)
|
||||
anal_kill.remove(movana); //la remove() accoppa anche le righe collegate
|
||||
else
|
||||
anal_kill.rewrite(movana); //non deve eliminare il movimento ma solo riscriverlo compattato..
|
||||
} //..senza le righe eliminate
|
||||
} //if(descr==...
|
||||
} //for(curmovana=0...
|
||||
}
|
||||
|
||||
//metodo di medio livello che gestisce l'ordine delle chiamate dei metodi per l'elaborazione dei record
|
||||
void TBudget_Import::elabora_input(const TFilename& file, TLog_report& log)
|
||||
{
|
||||
//array con le commesse da accoppare
|
||||
TAssoc_array commesse;
|
||||
|
||||
//per cominciare apre il file di input
|
||||
const long dimension = fsize(file);
|
||||
if (dimension > 0)
|
||||
{
|
||||
_trasfile->open(file,'r');
|
||||
|
||||
TRecord_text curr;
|
||||
TString codcms;
|
||||
|
||||
TProgind pi(dimension, TR("Lettura file di input in corso..."));
|
||||
//crea un assoc_array di array (e la madona!!!) in cui la chiave e' il codice commessa e gli elementi..
|
||||
//..sono array con le righe del file di input (con la stessa commessa ma fase\conto etc. diversi)
|
||||
while (_trasfile->read(curr) == NOERR)
|
||||
{
|
||||
pi.setstatus(_trasfile->read_file()->tellg());
|
||||
|
||||
codcms = curr.get(0);
|
||||
codcms.replace('_', '/');
|
||||
|
||||
TArray* righe = (TArray*)commesse.objptr(codcms);
|
||||
if (righe == NULL)
|
||||
{
|
||||
righe = new TArray;
|
||||
commesse.add(codcms, righe);
|
||||
}
|
||||
righe->add(curr);
|
||||
}
|
||||
|
||||
//per finire chiude il file di input che sara' poi riaperto per la vera importazione
|
||||
_trasfile->close();
|
||||
}
|
||||
|
||||
//accoppa i movana con commesse da importare
|
||||
movana_killer(commesse, false);
|
||||
|
||||
//la causale!!!
|
||||
_codcaus = _msk->get(F_COD_CAUS);
|
||||
|
||||
//scrittura dei record memorizzati sui files di testata e righe dei movimenti analitici
|
||||
const int items = commesse.items();
|
||||
TProgind pi(items, "Generazione movimenti preventivi in corso...");
|
||||
FOR_EACH_ASSOC_OBJECT(commesse, obj, key, itm)
|
||||
{
|
||||
pi.addstatus(1);
|
||||
TArray* righe = (TArray*)itm;
|
||||
transfer_movimento(*righe, log);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool TBudget_Import::transfer()
|
||||
{
|
||||
//azzeramento preventivo di TUTTI i movimenti, righe e saldi di tipo P
|
||||
if (_msk->get_bool(F_KILLOLD))
|
||||
{
|
||||
TAssoc_array assoc_civetta;
|
||||
movana_killer(assoc_civetta, true);
|
||||
}
|
||||
|
||||
//file da trasferire
|
||||
//costruire il nome del file con path
|
||||
@ -331,13 +518,6 @@ bool TBudget_Import::transfer()
|
||||
file.add(_msk->get(F_NAMEFILE));
|
||||
file.ext("csv");
|
||||
_trasfile = new TBudget_Import_file(file);
|
||||
_trasfile->open(file,'r');
|
||||
|
||||
//la causale!!!
|
||||
_codcaus = _msk->get(F_COD_CAUS);
|
||||
|
||||
const long dimension = fsize(file);
|
||||
TProgind pi(dimension,TR("Importazione movimenti in corso..."));
|
||||
|
||||
int err = NOERR;
|
||||
TRecord_text curr;
|
||||
@ -345,12 +525,9 @@ bool TBudget_Import::transfer()
|
||||
TLog_report log("Errori");
|
||||
log.kill_duplicates();
|
||||
|
||||
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
||||
{
|
||||
pi.setstatus(_trasfile->read_file()->tellg());
|
||||
transfer_movimento(curr, log);
|
||||
}
|
||||
_trasfile->close();
|
||||
//metodo che fa veramente la eliminazione e la scrittura
|
||||
elabora_input(file, log);
|
||||
|
||||
delete _trasfile;
|
||||
|
||||
log.preview();
|
||||
@ -369,6 +546,7 @@ void TBudget_Import::mask2ini()
|
||||
_configfile->set("LASTFILE", _lastfile);
|
||||
_msk->set(F_COD_CAUS, _codcaus);
|
||||
_configfile->set("CODCAUS", _msk->get(F_COD_CAUS));
|
||||
_configfile->set("CRPADIN", _msk->get(F_CRPA_DIN));
|
||||
}
|
||||
|
||||
void TBudget_Import::ini2mask()
|
||||
@ -376,14 +554,15 @@ void TBudget_Import::ini2mask()
|
||||
//carica i parametri del file di configurazione
|
||||
_configfile->set_paragraph("BUDGET");
|
||||
|
||||
TString path = _configfile->get("PATH");
|
||||
_msk->set(F_PATH, path);
|
||||
_msk->set(F_PATH, _configfile->get("PATH"));
|
||||
|
||||
_lastfile = _configfile->get("LASTFILE");
|
||||
_msk->set(F_LASTFILE, _lastfile);
|
||||
|
||||
_codcaus = _configfile->get("CODCAUS");
|
||||
_msk->set(F_COD_CAUS, _codcaus);
|
||||
|
||||
_msk->set(F_CRPA_DIN, _configfile->get("CRPADIN"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,14 +52,17 @@ PICTURE =
|
||||
NAME(0) = CODCMS
|
||||
TYPE(0) = STRINGA
|
||||
|
||||
NAME(1) = CODCONTO
|
||||
NAME(1) = FASE
|
||||
TYPE(1) = STRINGA
|
||||
|
||||
NAME(2) = IMPORTO
|
||||
TYPE(2) = IMPORTO
|
||||
NAME(2) = CODCONTO
|
||||
TYPE(2) = STRINGA
|
||||
|
||||
NAME(3) = DATAINI
|
||||
TYPE(3) = DATA
|
||||
NAME(3) = IMPORTO
|
||||
TYPE(3) = IMPORTO
|
||||
|
||||
NAME(4) = DATAFINE
|
||||
NAME(4) = DATAINI
|
||||
TYPE(4) = DATA
|
||||
|
||||
NAME(5) = DATAFINE
|
||||
TYPE(5) = DATA
|
||||
|
@ -6,3 +6,4 @@
|
||||
#define F_KILLOLD 104
|
||||
#define F_COD_CAUS 105
|
||||
#define F_DESCR_CAUS 106
|
||||
#define F_CRPA_DIN 107
|
||||
|
@ -45,14 +45,9 @@ BEGIN
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
BOOLEAN F_KILLOLD
|
||||
BEGIN
|
||||
PROMPT 1 7 "Elimina tutti i movimenti ed i saldi preventivi esistenti"
|
||||
END
|
||||
|
||||
STRING F_COD_CAUS 3
|
||||
BEGIN
|
||||
PROMPT 1 9 "Causale "
|
||||
PROMPT 1 7 "Causale "
|
||||
FLAGS "UZ"
|
||||
USE LF_CAUSALI
|
||||
INPUT CODCAUS F_COD_CAUS
|
||||
@ -65,7 +60,7 @@ END
|
||||
|
||||
STRING F_DESCR_CAUS 50 40
|
||||
BEGIN
|
||||
PROMPT 20 9 "Descriz."
|
||||
PROMPT 20 7 "Descriz."
|
||||
USE LF_CAUSALI KEY 2
|
||||
INPUT DESCR F_DESCR_CAUS
|
||||
DISPLAY "Descrizione @50" DESCR
|
||||
@ -73,5 +68,17 @@ BEGIN
|
||||
COPY OUTPUT F_COD_CAUS
|
||||
END
|
||||
|
||||
RADIOBUTTON F_CRPA_DIN 1 27
|
||||
BEGIN
|
||||
PROMPT 1 9 "Tipologia del secondo campo"
|
||||
ITEM "C|Fase (CRPA)"
|
||||
ITEM "S|Sede (DINAMICA)"
|
||||
END
|
||||
|
||||
BOOLEAN F_KILLOLD
|
||||
BEGIN
|
||||
PROMPT 1 13 "Elimina tutti i movimenti ed i saldi preventivi esistenti"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
ENDMASK
|
||||
|
@ -1,3 +1,5 @@
|
||||
[BUDGET]
|
||||
PATH =
|
||||
LASTFILE =
|
||||
CODCAUS =
|
||||
CRPADIN =
|
Loading…
x
Reference in New Issue
Block a user