Corretta maschera registri e vidimazioni git-svn-id: svn://10.65.10.50/trunk@1022 c028cbd2-c16b-5b4b-a496-9718f37d4682
219 lines
4.9 KiB
C++
Executable File
219 lines
4.9 KiB
C++
Executable File
#include <xvt.h>
|
|
|
|
#include <applicat.h>
|
|
#include <isam.h>
|
|
#include <mailbox.h>
|
|
#include <progind.h>
|
|
#include <prefix.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#define usage "Errore - uso : bacnv [1|2] ditta"
|
|
|
|
class TConversione_archivi : public TApplication
|
|
{
|
|
int _nconv;
|
|
long _codditta;
|
|
long _oldditta;
|
|
int _error;
|
|
|
|
protected: // TApplication
|
|
virtual bool create() ;
|
|
virtual bool destroy() ;
|
|
virtual bool menu(MENU_TAG);
|
|
|
|
public:
|
|
bool convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs);
|
|
void contropartita_rmov();
|
|
|
|
void liala(const char* table);
|
|
|
|
TConversione_archivi() : _oldditta(0), _codditta(0), _error(0) {}
|
|
};
|
|
|
|
bool TConversione_archivi::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
if (argc() < 3)
|
|
{
|
|
_error = 101;
|
|
TMessage msg("ba1100", 0, format("%d", _error));
|
|
|
|
msg.send();
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
_oldditta = get_firm();
|
|
_codditta = atol(argv(argc() - 1));
|
|
_nconv = atoi(argv(1));
|
|
if (_codditta != _oldditta)
|
|
{
|
|
if (_codditta == 0) prefhndl->set("com");
|
|
else set_firm(_codditta);
|
|
}
|
|
dispatch_e_menu(MENU_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
bool TConversione_archivi::destroy()
|
|
{
|
|
if (_codditta != _oldditta)
|
|
{
|
|
if (_oldditta == 0) prefhndl->set("com");
|
|
else set_firm(_oldditta);
|
|
}
|
|
if (_error > 0)
|
|
{
|
|
TMessage msg("ba1100", 0, format("%d", _error));
|
|
msg.send();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TConversione_archivi::menu(MENU_TAG)
|
|
{
|
|
switch (_nconv)
|
|
{
|
|
case 1:
|
|
contropartita_rmov(); break;
|
|
case 2:
|
|
liala("LIA");
|
|
liala("PLA");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Cambia i movimenti contabili in modo che abbiano un
|
|
// conto di contropartita e non una riga di riferimento
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool TConversione_archivi::convert_rmov(TLocalisamfile & rmov, TArray & recs, int nrecs)
|
|
{
|
|
const TRecnotype pos = rmov.recno();
|
|
|
|
for (int i = 0; i < nrecs; i++)
|
|
{
|
|
TRectype & r0 = (TRectype &) recs[i];
|
|
const int rcontr = r0.get_int(RMV_RCONTR) - 1;
|
|
|
|
if (rcontr >= 0 && rcontr < nrecs)
|
|
{
|
|
const TRectype & r1 = (const TRectype &) recs[rcontr];
|
|
|
|
r0.put(RMV_TIPOCC, r1.get(RMV_TIPOC));
|
|
r0.put(RMV_GRUPPOC, r1.get_int(RMV_GRUPPO));
|
|
r0.put(RMV_CONTOC, r1.get_int(RMV_CONTO));
|
|
r0.put(RMV_SOTTOCONTOC, r1.get_long(RMV_SOTTOCONTO));
|
|
}
|
|
r0.zero(RMV_RCONTR);
|
|
if (rmov.rewrite(r0) != NOERR)
|
|
{
|
|
const long reg = r0.get_long(RMV_NUMREG);
|
|
error_box("Non riesco ad aggiornare la riga contabile %ld / %d\nErrore n. %d", reg, i + 1, rmov.status());
|
|
rmov.readat(pos);
|
|
_error = 102;
|
|
return FALSE;
|
|
}
|
|
}
|
|
rmov.readat(pos);
|
|
return TRUE;
|
|
}
|
|
|
|
void TConversione_archivi::contropartita_rmov()
|
|
{
|
|
TDir d;
|
|
d.get(LF_RMOV);
|
|
if (d.eox() == 0) return;
|
|
|
|
TLocalisamfile rmov(LF_RMOV);
|
|
const TRecnotype nitems = rmov.items();
|
|
TArray recs;
|
|
long oldreg = -1;
|
|
long reg = -1;
|
|
int nrow = 0;
|
|
TProgind p(nitems ? nitems : 1,
|
|
format("Conversione righe di movimento della ditta %ld", get_firm()),
|
|
FALSE, TRUE, 70);
|
|
for (rmov.first(); rmov.good(); rmov.next())
|
|
{
|
|
p.addstatus(1);
|
|
reg = rmov.get_long(RMV_NUMREG);
|
|
if (oldreg != reg)
|
|
{
|
|
if (oldreg > 0)
|
|
if (convert_rmov(rmov, recs, nrow) == FALSE)
|
|
return;
|
|
oldreg = reg;
|
|
nrow = 0;
|
|
}
|
|
recs.add(rmov.curr(), nrow++);
|
|
CHECKD(nrow == rmov.get_int(RMV_NUMRIG), "Missed row ", nrow);
|
|
}
|
|
if (oldreg > 0)
|
|
if (convert_rmov(rmov, recs, nrow) == FALSE)
|
|
return;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Passa le tabelle LIA e PLA a %LIA e %PLA
|
|
///////////////////////////////////////////////////////////
|
|
|
|
void TConversione_archivi::liala(const char* table)
|
|
{
|
|
TString16 tab(table);
|
|
|
|
TTable lia(tab);
|
|
tab.insert("%", 0);
|
|
TTable cia(tab);
|
|
|
|
const long n = lia.items()+1;
|
|
TProgind p(n, format("Conversione tabella %s della ditta %ld", table, get_firm()), FALSE, TRUE, 70);
|
|
|
|
TString16 firm; firm.format("%05ld", get_firm());
|
|
TString16 codtab;
|
|
|
|
for (lia.first(); lia.good(); lia.next())
|
|
{
|
|
codtab = lia.get("CODTAB");
|
|
codtab.insert(firm, 0);
|
|
lia.put("CODTAB", codtab);
|
|
cia.write(lia.curr());
|
|
}
|
|
|
|
for (lia.first(); lia.good(); lia.next())
|
|
lia.remove();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Programma di conversione archivi speciale
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int main(int argc,char** argv)
|
|
{
|
|
const int r = (argc > 1) ? atoi(argv[1]) : 0;
|
|
|
|
if (r <= 0 || r > 2)
|
|
{
|
|
error_box(usage);
|
|
return 100;
|
|
}
|
|
|
|
TConversione_archivi a ;
|
|
a.run(argc, argv, "Conversione archivi");
|
|
|
|
return 0;
|
|
}
|
|
|