1994-11-18 17:38:53 +00:00
|
|
|
#include <applicat.h>
|
1994-12-07 11:08:53 +00:00
|
|
|
#include <assoc.h>
|
1994-11-18 17:38:53 +00:00
|
|
|
#include <isam.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <prefix.h>
|
1994-12-07 11:08:53 +00:00
|
|
|
#include <urldefid.h>
|
1994-11-18 17:38:53 +00:00
|
|
|
|
|
|
|
#include "cg4.h"
|
|
|
|
#include "cg4200.h"
|
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
#include <pconti.h>
|
|
|
|
|
1994-11-18 17:38:53 +00:00
|
|
|
class TCopia_archivi : public TApplication
|
|
|
|
{
|
|
|
|
TMask* _msk;
|
|
|
|
long _default_firm;
|
|
|
|
|
|
|
|
virtual bool create() ;
|
|
|
|
virtual bool destroy() ;
|
|
|
|
bool menu(MENU_TAG);
|
|
|
|
bool copyfile(int logicnum, long from, long to);
|
|
|
|
void clearivd(long to);
|
|
|
|
void copyivd(long from, long to);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TCopia_archivi() : _msk(NULL) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TCopia_archivi::copyfile(int logicnum, long from, long to)
|
|
|
|
{
|
|
|
|
if (from > 0) set_firm(from);
|
1995-03-23 08:45:05 +00:00
|
|
|
else prefix().set("com");
|
1994-11-18 17:38:53 +00:00
|
|
|
TSystemisamfile file(logicnum);
|
|
|
|
TFilename t; t.tempdir(); t << "/tr" << logicnum;
|
|
|
|
|
|
|
|
if (file.dump(t) != NOERR)
|
|
|
|
return error_box("Impossibile leggere i dati da copiare errore n. %d", file.status());
|
|
|
|
set_firm(to);
|
|
|
|
TFilename s; s.tempdir(); s << "/sv" << logicnum;
|
|
|
|
|
|
|
|
if (file.dump(s) != NOERR)
|
|
|
|
return error_box("Impossibile salvare i dati originali errore n. %d", file.status());
|
|
|
|
|
|
|
|
TDir dir;
|
|
|
|
|
|
|
|
dir.get(logicnum, _lock, _nordir, _sysdirop);
|
|
|
|
dir.eod() = 0L;
|
|
|
|
dir.put(logicnum, _nordir, _sysdirop);
|
|
|
|
file.packindex();
|
|
|
|
if (file.load(t) != NOERR)
|
|
|
|
{
|
|
|
|
error_box("Impossibile scrivere i dati errore n. %d. Cerco di ripristinare i dati originali.", file.status());
|
|
|
|
dir.get(logicnum, _lock, _nordir, _sysdirop);
|
|
|
|
dir.eod() = 0L;
|
|
|
|
dir.put(logicnum, _nordir, _sysdirop);
|
|
|
|
file.packindex();
|
|
|
|
if (file.load(s))
|
|
|
|
error_box("Impossibile scrivere i dati originali errore n. %d", file.status());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCopia_archivi::clearivd(long to)
|
|
|
|
{
|
|
|
|
TLocalisamfile pcon(LF_PCON);
|
|
|
|
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, "0");
|
|
|
|
pcon.zero(PCN_LETTIVD);
|
|
|
|
pcon.zero(PCN_NUMRIVD);
|
|
|
|
pcon.zero(PCN_NUMIVD);
|
|
|
|
pcon.put(PCN_SEZIVDOPP, "0");
|
|
|
|
pcon.zero(PCN_LETTIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMRIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMIVDOPP);
|
|
|
|
pcon.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCopia_archivi::copyivd(long from, long to)
|
|
|
|
{
|
1995-03-01 15:19:25 +00:00
|
|
|
if (from > 0) set_firm(from);
|
1995-03-23 08:45:05 +00:00
|
|
|
else prefix().set("com");
|
1994-11-18 17:38:53 +00:00
|
|
|
TLocalisamfile pcon(LF_PCON);
|
|
|
|
TAssoc_array riclass;
|
|
|
|
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
TString16 key;
|
|
|
|
TToken_string data;
|
|
|
|
|
|
|
|
key.format("%03d%03d%06ld", pcon.get_int(PCN_GRUPPO),
|
|
|
|
pcon.get_int(PCN_CONTO), pcon.get_long(PCN_SOTTOCONTO));
|
|
|
|
data.add(pcon.get(PCN_SEZIVD));
|
|
|
|
data.add(pcon.get(PCN_LETTIVD));
|
|
|
|
data.add(pcon.get(PCN_NUMRIVD));
|
|
|
|
data.add(pcon.get(PCN_NUMIVD));
|
|
|
|
data.add(pcon.get(PCN_SEZIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_LETTIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_NUMRIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_NUMIVDOPP));
|
|
|
|
riclass.add(key, data);
|
|
|
|
}
|
|
|
|
set_firm(to);
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
TString16 key;
|
|
|
|
|
|
|
|
key.format("%03d%03d%06ld", pcon.get_int(PCN_GRUPPO),
|
|
|
|
pcon.get_int(PCN_CONTO), pcon.get_long(PCN_SOTTOCONTO));
|
|
|
|
|
|
|
|
TToken_string * data = (TToken_string *) riclass.objptr(key);
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, "0");
|
|
|
|
pcon.zero(PCN_LETTIVD);
|
|
|
|
pcon.zero(PCN_NUMRIVD);
|
|
|
|
pcon.zero(PCN_NUMIVD);
|
|
|
|
pcon.put(PCN_SEZIVDOPP, "0");
|
|
|
|
pcon.zero(PCN_LETTIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMRIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMIVDOPP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, data->get(0));
|
|
|
|
pcon.put(PCN_LETTIVD, data->get());
|
|
|
|
pcon.put(PCN_NUMRIVD, data->get());
|
|
|
|
pcon.put(PCN_NUMIVD, data->get());
|
|
|
|
pcon.put(PCN_SEZIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_LETTIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_NUMRIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_NUMIVDOPP, data->get());
|
|
|
|
}
|
|
|
|
pcon.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCopia_archivi::create()
|
|
|
|
{
|
1994-12-07 11:08:53 +00:00
|
|
|
TApplication::create();
|
1994-11-18 17:38:53 +00:00
|
|
|
_msk = new TMask("cg4200a") ;
|
|
|
|
_default_firm = get_firm();
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCopia_archivi::destroy()
|
|
|
|
{
|
|
|
|
if (_msk != NULL) delete _msk;
|
1994-12-07 11:08:53 +00:00
|
|
|
return TApplication::destroy();
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TCopia_archivi::menu(MENU_TAG)
|
|
|
|
{
|
|
|
|
while (_msk->run() == K_ENTER)
|
|
|
|
{
|
|
|
|
const long from_firm = _msk->get_long(F_FROMFIRM);
|
|
|
|
const long to_firm = _msk->get_long(F_TOFIRM);
|
1994-12-14 11:10:15 +00:00
|
|
|
if (from_firm == to_firm)
|
|
|
|
error_box("La copia si puo' effettuare solo tra due ditte diverse");
|
|
|
|
else
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
const bool copy_pcon = _msk->get_bool(F_PCON);
|
|
|
|
const bool copy_causali = _msk->get_bool(F_CAUS);
|
|
|
|
const bool copy_clifo = _msk->get_bool(F_CLIFO);
|
|
|
|
const bool copy_ivd = _msk->get_bool(F_IVD);
|
|
|
|
if (copy_pcon || copy_causali || copy_clifo || copy_ivd)
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1995-03-23 08:45:05 +00:00
|
|
|
if (prefix().exist(to_firm))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
set_firm(to_firm);
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
1994-11-18 17:38:53 +00:00
|
|
|
|
1994-12-14 11:10:15 +00:00
|
|
|
if ((mov.eod() == 0) || (!copy_pcon && !copy_causali && !copy_clifo))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1995-03-01 15:19:25 +00:00
|
|
|
TString256 mess("Attenzione \n");
|
1994-12-14 11:10:15 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (copy_pcon)
|
|
|
|
{
|
|
|
|
mess << "il piano dei conti";
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_causali)
|
|
|
|
{
|
|
|
|
if (count > 0) mess << ",\n";
|
|
|
|
mess << " le causali";
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_clifo)
|
|
|
|
{
|
|
|
|
if (count > 0) mess << ",\n";
|
|
|
|
mess << " i clienti e fornitori";
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_ivd)
|
|
|
|
{
|
|
|
|
if (count > 0) mess << ",\n";
|
|
|
|
mess << " la riclassificazione IV direttiva";
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
mess << "\n della ditta " << to_firm;
|
|
|
|
if (count > 1)
|
|
|
|
mess << " saranno sovrascritti";
|
|
|
|
else
|
|
|
|
mess << " sara' sovrascritto";
|
|
|
|
mess << ". Devo continuare";
|
1994-11-18 17:38:53 +00:00
|
|
|
if (yesno_box((const char *) mess))
|
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
mess.rtrim(16); mess << " Devo veramente continuare";
|
|
|
|
if (yesno_box((const char *) mess))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
if (copy_pcon)
|
|
|
|
{
|
|
|
|
if (copyfile(LF_PCON, from_firm, to_firm) && !copy_ivd)
|
|
|
|
clearivd(to_firm);
|
|
|
|
}
|
|
|
|
if (copy_causali)
|
|
|
|
{
|
|
|
|
if (copyfile(LF_CAUSALI, from_firm, to_firm))
|
|
|
|
copyfile(LF_RCAUSALI, from_firm, to_firm);
|
|
|
|
}
|
|
|
|
if (copy_clifo)
|
|
|
|
copyfile(LF_CLIFO, from_firm, to_firm);
|
|
|
|
if (!copy_pcon && copy_ivd)
|
|
|
|
copyivd(from_firm, to_firm);
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-12-14 11:10:15 +00:00
|
|
|
else error_box("La copia si puo' effettuare solo se non sono stati registrati movimenti");
|
|
|
|
set_firm(_default_firm);
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
1995-03-01 15:19:25 +00:00
|
|
|
else error_box("Gli archivi della ditta %ld non sono stati ancora generati",to_firm);
|
1994-12-14 11:10:15 +00:00
|
|
|
_msk->reset();
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cg4200(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TCopia_archivi a ;
|
|
|
|
a.run(argc, argv, "Copia archivi");
|
|
|
|
return 0;
|
|
|
|
}
|