campo-sirio/ibm36/ibm36100.cpp
guy a9a9ba67c5 This commit was generated by cvs2svn to compensate for changes in r6942,
which included commits to RCS files with non-trunk default branches.

git-svn-id: svn://10.65.10.50/trunk@6943 c028cbd2-c16b-5b4b-a496-9718f37d4682
1998-08-10 09:54:46 +00:00

371 lines
8.6 KiB
C++
Executable File

#include <applicat.h>
#include <automask.h>
#include <browfile.h>
#include <filetext.h>
#include <prefix.h>
#include <progind.h>
#include <tabutil.h>
#include <utility.h>
#include <viswin.h>
#include "ibm36.h"
#include <comuni.h>
#include <clifo.h>
class TMask36 : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TMask36() : TAutomask("ibm36100") { }
virtual ~TMask36() { }
};
bool TMask36::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
return TRUE;
}
class TTrasfer36 : public TSkeleton_application
{
protected:
virtual void main_loop();
virtual const char* extra_modules() const { return "*"; } // Non e' un modulo normale
public:
const TString& cap2com(const TString& cap, const TString& name) const;
void split_indir(const TString& indir, TString& via, TString& civ) const;
void import_tables(const TFilename& name, TBrowsefile_field& bf);
void import_clifo(const TFilename& name, TBrowsefile_field& bf);
};
const TString& TTrasfer36::cap2com(const TString& cap, const TString& name) const
{
if (cap.not_empty())
{
TString16 str(cap); str.right_just(5, '0');
if (str[2] == '1')
str.overwrite("00", 3);
TRelation rel(LF_COMUNI);
TRectype filter(LF_COMUNI); filter.put(COM_CAPCOM, cap);
TCursor comuni(&rel, "", 3, &filter, &filter);
const TRecnotype total = comuni.items();
if (total > 0)
{
comuni = 0;
if (total > 1)
{
TRecnotype bestpos = 0L;
int bestlen = 0;
comuni.freeze(TRUE);
for (; comuni.pos() < total; ++comuni)
{
const TString& dencom = comuni.curr().get(COM_DENCOM);
for (int l = 0; toupper(dencom[l]) == toupper(name[l]); l++);
if (l > bestlen)
{
bestlen = l;
bestpos = comuni.pos();
}
}
comuni = bestpos;
}
return comuni.curr().get(COM_COM);
}
}
return EMPTY_STRING;
}
void TTrasfer36::split_indir(const TString& indir, TString& via, TString& civ) const
{
const int comma = indir.rfind(',');
if (comma > 0)
{
via = indir.left(comma);
civ = indir.mid(comma+1);
}
else
{
bool has_digit = FALSE;
for (int i = indir.len()-1; i > 0; i--)
{
if (has_digit)
{
if (indir[i] == ' ')
break;
}
else
{
if (isdigit(indir[i]))
has_digit = TRUE;
}
}
if (i > 0 && has_digit)
{
via = indir.left(i);
civ = indir.mid(i+1);
}
}
if (via.empty())
{
via = indir;
civ.cut(0);
}
via.cut(35);
civ.cut(10);
}
void TTrasfer36::import_tables(const TFilename& name, TBrowsefile_field& bf)
{
TString msg;
msg = "Importazione tabelle vendite";
TProgind pi(::fsize(name), msg, TRUE, TRUE);
long valid = 0;
msg.insert("@b", 0);
msg << " dal file " << name;
bf.add_line(msg);
bf.add_line("");
TFile_text file(name, "ibm36tab.ini");
TTable ban("%BAN");
TRecord_text curr;
while (file.read(curr) == NOERR)
{
pi.setstatus(file.read_file()->tellg());
if (pi.iscancelled())
break;
const TString& type = curr.type();
if (type == "A26")
{
const TString& ann = file.get_field(curr, "ANNULLATO");
if (ann != "A")
{
msg = "Importazione tabelle vendite - Record validi: ";
msg << ++valid;
pi.set_text(msg);
TString16 cod = file.get_field(curr, "CODICE");
TString16 abi = file.get_field(curr, "ABI");
TString16 cab = file.get_field(curr, "CAB");
if (abi.empty() || cab.empty())
{
if (abi.empty()) abi = "99999";
if (cab.empty()) { cab = cod; cab.right_just(5, '0'); }
msg = "! La banca ";
msg << cod << " non dispone di un codice ABI/CAB valido";
bf.add_line(msg);
msg = "- Verra' creata la banca fittizia ";
msg << abi << ' ' << cab;
bf.add_line(msg);
}
abi.right_just(5, '0');
cab.right_just(5, '0');
TString16 codtab = abi;
ban.put("CODTAB", codtab);
if (ban.read() != NOERR)
{
msg = "- Creazione dell'istituto fittizio ";
msg << abi;
bf.add_line(msg);
ban.put("CODTAB", codtab);
ban.put("S0", "Banca per trasferimenti IBM36");
ban.write();
}
codtab << cab;
ban.put("CODTAB", codtab);
if (ban.read() == NOERR)
{
ban.put("I14", cod);
ban.rewrite();
}
else
{
ban.put("CODTAB", codtab);
ban.put("S0", file.get_field(curr, "RAGSOC"));
ban.put("I14", cod);
const TString& cap = file.get_field(curr, "CAP");
ban.put("S3", cap);
const TString& loc = file.get_field(curr, "LOCALITA");
ban.put("S1", loc);
const TString& com = cap2com(cap, loc);
ban.put("S5", com);
const TString& ind = file.get_field(curr, "INDIRIZZO");
TString via, civ;
split_indir(ind, via, civ);
ban.put("S2", via);
ban.put("S7", civ);
ban.write();
}
}
}
}
msg = "Record importati: ";
msg << valid;
bf.add_line(msg);
bf.add_line("");
}
void TTrasfer36::import_clifo(const TFilename& name, TBrowsefile_field& bf)
{
TAssoc_array missing_firm;
TString msg;
long valid = 0;
msg = "Importazione Clienti/Fornitori";
TProgind pi(::fsize(name), msg, TRUE, TRUE);
TFile_text file(name, "ibm36cf.ini");
msg.insert("@b", 0);
bf.add_line(msg);
bf.add_line("");
TRelation rel(LF_CLIFO); rel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
TRecord_text curr;
while (file.read(curr) == NOERR)
{
pi.setstatus(file.read_file()->tellg());
if (pi.iscancelled())
break;
const int tipo_record = curr.type()[0] - '0';
if (tipo_record >= 1 && tipo_record <= 6)
{
const char stato_record = file.get_field(curr, "ANNULLATO")[0];
if (stato_record == 'A')
continue;
const long ditta = atol(file.get_field(curr, "DITTA"));
if (prefix().get_codditta() != ditta)
{
if (prefix().exist(ditta))
prefix().set_codditta(ditta);
else
{
msg.format("%ld", ditta);
if (missing_firm.objptr(msg) == NULL)
{
missing_firm.add(msg, msg);
msg.insert("Non esiste la ditta ", 0);
msg << ": Effettuare il trasferimento della contabilita'";
bf.add_line(msg);
}
continue;
}
}
const char* tipocf = (tipo_record & 0x1) ? "C" : "F";
const long codcf = atol(file.get_field(curr, "CODCF"));
TLocalisamfile& clifo = rel.lfile();
clifo.put(CLI_TIPOCF, tipocf);
clifo.put(CLI_CODCF, codcf);
int err = clifo.read();
if (err == NOERR)
{
file.add_field(curr, "TIPOCF", tipocf);
}
switch(tipo_record)
{
case 1:
case 2:
if (err != NOERR)
{
msg = "! Non esiste il ";
msg << (*tipocf == 'C' ? "cliente" : "fornitore") << ' ' << codcf;
bf.add_line(msg);
msg = "- Inserimento di ";
msg << file.get_field(curr, "COGNOME") << file.get_field(curr, "NOME");
bf.add_line(msg);
rel.write_enable(LF_CFVEN, FALSE);
const int err = file.autosave(rel, curr);
if (err != NOERR)
{
msg = "! Errore di scrittura sul file LF_CLIFO: ";
msg << err;
bf.add_line(msg);
}
}
break;
case 3:
if (err == NOERR)
{
rel.write_enable(LF_CFVEN);
const int err = file.autosave(rel, curr);
if (err != NOERR)
{
msg = "! Errore di scrittura sul file LF_CFVEN: ";
msg << err;
bf.add_line(msg);
}
else
valid++;
}
break;
case 4:
// Ignored
break;
default: break;
}
}
}
msg = "Record importati: ";
msg << valid;
bf.add_line(msg);
bf.add_line("");
}
void TTrasfer36::main_loop()
{
TMask36 m;
TBrowsefile_field& bf = (TBrowsefile_field&)m.field(201);
TViswin& vw = bf.vis_win();
vw.show_rulers(FALSE);
while (m.run() == K_ENTER)
{
vw.destroy_lines();
TFilename name;
name = m.get(101);
if (name.not_empty())
import_tables(name, bf);
name = m.get(102);
if (name.not_empty())
import_clifo(name, bf);
vw.goto_top();
}
}
int ibm36100(int argc, char* argv[])
{
TTrasfer36 a;
a.run(argc, argv, "Trasferimento IBM36");
return 0;
}