2013-01-04 08:13:26 +00:00
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <reputils.h>
|
|
|
|
|
#include <textset.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
#include "ps0430400a.h"
|
|
|
|
|
|
|
|
|
|
#include "../ve/velib.h"
|
|
|
|
|
|
|
|
|
|
#include "../cg/cfban.h"
|
2013-02-07 14:17:40 +00:00
|
|
|
|
#include "cfven.h"
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TCBA_recset
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TCBA_recset : public TCSV_recordset
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual const TVariant& get(unsigned int column) const;
|
|
|
|
|
TDate get_date(unsigned int column) const;
|
|
|
|
|
TCBA_recset() : TCSV_recordset("CSV(;)") {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const TVariant& TCBA_recset::get(unsigned int column) const
|
|
|
|
|
{
|
|
|
|
|
const TVariant& var = TCSV_recordset::get(column);
|
|
|
|
|
if (var.is_string())
|
|
|
|
|
{
|
|
|
|
|
TString80 str = var.as_string();
|
|
|
|
|
if (str[0] == '"')
|
|
|
|
|
{
|
|
|
|
|
str.strip("\"");
|
|
|
|
|
return get_tmp_var() = str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDate TCBA_recset::get_date(unsigned int column) const
|
|
|
|
|
{
|
|
|
|
|
const TVariant& var = TCSV_recordset::get(column);
|
|
|
|
|
const long v = var.as_int();
|
|
|
|
|
const int d = v / 1000000;
|
|
|
|
|
const int m = (v / 10000) % 100;
|
|
|
|
|
const int y = v % 10000;
|
|
|
|
|
return TDate(d, m, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TImport_mask
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TImport_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TImport_mask() : TAutomask("ps0430400a") {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TImport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_CLI:
|
|
|
|
|
case F_FAT:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
TFilename n = get(F_DIR);
|
|
|
|
|
n.add("*.csv");
|
|
|
|
|
if (input_filename(n))
|
|
|
|
|
o.set(n.name());
|
|
|
|
|
} else
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
TFilename n = get(F_DIR);
|
|
|
|
|
n.add(o.get());
|
|
|
|
|
if (!n.exist())
|
|
|
|
|
return cantread_box(n);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TImport_app
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TImport_app : public TSkeleton_application
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual const char* extra_modules() const { return "ca|ve"; }
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
long find_clifo(const TString& cf_pi, TLocalisamfile& clifo) const;
|
2013-02-07 14:17:40 +00:00
|
|
|
|
const TRectype& find_codart(TString& codart) const;
|
|
|
|
|
bool find_or_create_clifo(const TCBA_recset& cli, TLocalisamfile& clifo,
|
|
|
|
|
const TString& cdc, TLog_report& log) const;
|
|
|
|
|
const TString& get_periodo(const TCBA_recset& fat) const;
|
|
|
|
|
void aggiorna_referente(long codcf, const char* ospite) const;
|
|
|
|
|
|
|
|
|
|
bool importa_clienti(const TFilename& fname, const TString& cdc, TLog_report& log) const;
|
|
|
|
|
bool importa_fatture(const TFilename& fname, const TString& codnum, const TString& cdc, TLog_report& log) const;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
long TImport_app::find_clifo(const TString& cf_pi, TLocalisamfile& clifo) const
|
|
|
|
|
{
|
|
|
|
|
if (cf_pi.blank() || cf_pi.len() < 10)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
TString cod = cf_pi;
|
|
|
|
|
cod.trim();
|
|
|
|
|
cod.upper();
|
|
|
|
|
|
|
|
|
|
// Tento prima il codice fiscale o la partita IVA?
|
|
|
|
|
const char* const cofi_paiv = cod.len() > 16 ? "PC" : "CP";
|
|
|
|
|
|
|
|
|
|
int err = 204;
|
|
|
|
|
for (int tentativo = 0; tentativo < 2; tentativo++)
|
|
|
|
|
{
|
|
|
|
|
clifo.zero();
|
|
|
|
|
clifo.put(CLI_TIPOCF, 'C');
|
|
|
|
|
if (cofi_paiv[tentativo] == 'C')
|
|
|
|
|
{
|
|
|
|
|
clifo.setkey(4);
|
|
|
|
|
clifo.put(CLI_COFI, cod);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
clifo.setkey(5);
|
|
|
|
|
clifo.put(CLI_PAIV, cod);
|
|
|
|
|
}
|
|
|
|
|
err = clifo.read();
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err == NOERR ? clifo.get_long(CLI_CODCF) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
const TRectype& TImport_app::find_codart(TString& cod) const
|
2013-01-04 08:13:26 +00:00
|
|
|
|
{
|
|
|
|
|
cod.trim(); cod.upper();
|
|
|
|
|
const TRectype& anamag = cache().get(LF_ANAMAG, cod);
|
2013-02-07 14:17:40 +00:00
|
|
|
|
return anamag;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
bool TImport_app::find_or_create_clifo(const TCBA_recset& cli, TLocalisamfile& clifo, const TString& cdc, TLog_report& log) const
|
2013-01-04 08:13:26 +00:00
|
|
|
|
{
|
|
|
|
|
TString cofi = cli.get(2).as_string();
|
|
|
|
|
if (cofi.full() && find_clifo(cofi, clifo))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
TString piva = cli.get(1).as_string();
|
|
|
|
|
if (piva.full() && find_clifo(piva, clifo))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
const TString ragsoc = cli.get(6).as_string();
|
|
|
|
|
|
|
|
|
|
if (piva.blank() && cofi.blank())
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
|
|
|
|
msg << ragsoc << TR(" non ha n<> codice fiscale n<> partita IVA")
|
|
|
|
|
<< TR(" alla riga ") << (cli.current_row()+1);
|
|
|
|
|
log.log(2, msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long next_clifo = 1;
|
|
|
|
|
TISAM_recordset recset("USE CLIFO\tTO TIPOCF=C");
|
|
|
|
|
if (recset.move_last())
|
|
|
|
|
next_clifo += recset.get(CLI_CODCF).as_int();
|
|
|
|
|
|
|
|
|
|
clifo.setkey(1);
|
|
|
|
|
clifo.zero();
|
|
|
|
|
clifo.put(CLI_TIPOCF, 'C');
|
|
|
|
|
clifo.put(CLI_CODCF, next_clifo);
|
|
|
|
|
clifo.put(CLI_RAGSOC, ragsoc);
|
|
|
|
|
|
|
|
|
|
cofi.trim(); cofi.upper();
|
|
|
|
|
clifo.put(CLI_COFI, cofi);
|
|
|
|
|
|
|
|
|
|
piva.trim(); piva.upper();
|
|
|
|
|
clifo.put(CLI_PAIV, piva);
|
|
|
|
|
|
|
|
|
|
const int err = clifo.write();
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
|
|
|
|
msg << TR("Impossibile creare l'anagrafica di ") << ragsoc << TR(" alla riga ") << (cli.current_row()+1);
|
|
|
|
|
log.log(2, msg);
|
|
|
|
|
}
|
2013-02-07 14:17:40 +00:00
|
|
|
|
|
2013-01-04 08:13:26 +00:00
|
|
|
|
return err == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
bool TImport_app::importa_clienti(const TFilename& fname, const TString& cdc, TLog_report& log) const
|
2013-01-04 08:13:26 +00:00
|
|
|
|
{
|
|
|
|
|
TString str = TR("Importazione clienti");
|
|
|
|
|
log.log(0, str);
|
|
|
|
|
|
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
2013-02-07 14:17:40 +00:00
|
|
|
|
TLocalisamfile cfven(LF_CFVEN);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
TCBA_recset cli;
|
|
|
|
|
cli.load_file(fname);
|
|
|
|
|
|
|
|
|
|
long clifos = 0;
|
|
|
|
|
|
|
|
|
|
bool done = true;
|
|
|
|
|
|
|
|
|
|
TProgind pi(cli.items(), str);
|
|
|
|
|
for (bool ok = cli.move_first(); ok && done; ok = cli.move_next())
|
|
|
|
|
{
|
|
|
|
|
done = pi.addstatus(1);
|
|
|
|
|
if (!done)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (cli.get(0).is_empty()) // Salta righe vuote
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
done = find_or_create_clifo(cli, clifo, cdc, log);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
if (!done)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Aggiorna dati cliente
|
2013-02-07 14:17:40 +00:00
|
|
|
|
const TString16 piva = cli.get(1).as_string();
|
|
|
|
|
const TString16 cofi = cli.get(2).as_string();
|
2013-01-04 08:13:26 +00:00
|
|
|
|
const int privato = cli.get(27).as_int();
|
|
|
|
|
|
|
|
|
|
TRectype& curr = clifo.curr();
|
2013-02-07 14:17:40 +00:00
|
|
|
|
|
|
|
|
|
curr.put(CLI_PAIV, piva);
|
|
|
|
|
curr.put(CLI_COFI, cofi);
|
|
|
|
|
if (cofi.len() == 16)
|
|
|
|
|
{
|
|
|
|
|
curr.put(CLI_SESSO, cofi.mid(9, 1) > "3" ? 'F': 'M');
|
|
|
|
|
curr.put(CLI_COMNASC, cofi.mid(11, 4));
|
|
|
|
|
}
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
TString rs1 = cli.get(6).as_string(); rs1.trim();
|
|
|
|
|
TString rs2 = cli.get(7).as_string(); rs2.trim();
|
|
|
|
|
|
|
|
|
|
if (rs2.blank())
|
|
|
|
|
{
|
|
|
|
|
const int spc = rs1.find(' ');
|
|
|
|
|
if (spc > 0)
|
|
|
|
|
{
|
|
|
|
|
str = rs1.left(spc);
|
|
|
|
|
str.left_just(30);
|
|
|
|
|
str << rs1.mid(spc+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (str.empty())
|
|
|
|
|
{
|
|
|
|
|
str << rs1 << ' ' << rs2;
|
|
|
|
|
str.strip_double_spaces();
|
|
|
|
|
}
|
|
|
|
|
TParagraph_string ragsoc(str, 50);
|
|
|
|
|
curr.put(CLI_RAGSOC, ragsoc.get());
|
2013-02-07 14:17:40 +00:00
|
|
|
|
curr.put(CLI_REFERENTE, curr.get(CLI_RAGSOC));
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
curr.put(CLI_INDCF, cli.get(8).as_string());
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
const TString80 loc = cli.get(10).as_string();
|
2013-01-04 08:13:26 +00:00
|
|
|
|
curr.put(CLI_LOCCF, loc);
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
const TString8 cap = cli.get(9).as_string();
|
2013-01-04 08:13:26 +00:00
|
|
|
|
curr.put(CLI_CAPCF, cap);
|
|
|
|
|
|
|
|
|
|
const int naz = cli.get(16).as_int();
|
|
|
|
|
if (naz == 0)
|
|
|
|
|
{
|
|
|
|
|
const TString& com = cap2comune(cap, loc);
|
|
|
|
|
curr.put(CLI_COMCF, com);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int alleg = 0;
|
|
|
|
|
if (privato == 1)
|
2013-02-07 14:17:40 +00:00
|
|
|
|
alleg = 6;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (naz > 0)
|
|
|
|
|
alleg = naz == 1 ? 5 : 9;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (piva.empty())
|
|
|
|
|
alleg = 6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
curr.put(CLI_ALLEG, alleg);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
const TString8 abi = cli.get(17).as_string();
|
|
|
|
|
const TString8 cab = cli.get(18).as_string();
|
|
|
|
|
if (abi.len() == 5 && cab.len() == 5)
|
|
|
|
|
{
|
|
|
|
|
TToken_string key;
|
|
|
|
|
key = "C";
|
|
|
|
|
key.add(curr.get(CLI_CODCF));
|
|
|
|
|
key.add("N");
|
|
|
|
|
TRecord_array nsban(key, LF_CFBAN);
|
|
|
|
|
TRectype& rec = nsban.row(1, true);
|
|
|
|
|
rec.put(CFBAN_ABI, abi);
|
|
|
|
|
rec.put(CFBAN_CAB, cab);
|
|
|
|
|
rec.put(CFBAN_NUMCC, cli.get(23).as_string());
|
|
|
|
|
|
|
|
|
|
key.cut(0) << abi << cab;
|
|
|
|
|
const TString& iban = cache().get("BNP", key, "S3");
|
|
|
|
|
rec.put(CFBAN_IBAN, iban);
|
|
|
|
|
|
|
|
|
|
const int err = nsban.rewrite();
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
ragsoc.strip_double_spaces();
|
|
|
|
|
str.cut(0) << TR("Impossibile aggiornare la banca di ") << ragsoc << TR(" alla riga ") << (cli.current_row()+1);
|
|
|
|
|
log.log(1, str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curr.put(CLI_CODPAG, cli.get(20).as_string());
|
|
|
|
|
curr.put(CLI_MAIL, cli.get(28).as_string());
|
|
|
|
|
|
|
|
|
|
const int err = clifo.rewrite();
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
clifos++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ragsoc.strip_double_spaces();
|
|
|
|
|
str.cut(0) << TR("Impossibile aggiornare l'anagrafica di ") << ragsoc << TR(" alla riga ") << (cli.current_row()+1);
|
|
|
|
|
log.log(2, str);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-07 14:17:40 +00:00
|
|
|
|
|
|
|
|
|
if (cdc.full())
|
|
|
|
|
{
|
|
|
|
|
cfven.setkey(1);
|
|
|
|
|
cfven.zero();
|
|
|
|
|
cfven.put(CFV_TIPOCF, 'C');
|
|
|
|
|
cfven.put(CFV_CODCF, curr.get(CLI_CODCF));
|
|
|
|
|
if (cfven.read() != NOERR)
|
|
|
|
|
{
|
|
|
|
|
cfven.zero();
|
|
|
|
|
cfven.put(CFV_TIPOCF, 'C');
|
|
|
|
|
cfven.put(CFV_CODCF, curr.get(CLI_CODCF));
|
|
|
|
|
cfven.write();
|
|
|
|
|
}
|
|
|
|
|
cfven.put(CFV_CODPRCF, cdc.right(3));
|
|
|
|
|
cfven.rewrite();
|
|
|
|
|
}
|
2013-01-04 08:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.log(0, str.cut(0));
|
|
|
|
|
str << TR("Sono state importate/aggiornate ") << clifos << TR(" anagrafiche");
|
|
|
|
|
log.log(0, str);
|
|
|
|
|
log.log(0, str.cut(0));
|
|
|
|
|
|
|
|
|
|
return done;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
void TImport_app::aggiorna_referente(long codcf, const char* ospite) const
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
|
|
|
clifo.put(CLI_TIPOCF, 'C');
|
|
|
|
|
clifo.put(CLI_CODCF, codcf);
|
|
|
|
|
if (clifo.read(_isequal, _lock) == NOERR)
|
|
|
|
|
{
|
|
|
|
|
clifo.put(CLI_REFERENTE, ospite);
|
|
|
|
|
clifo.rewrite();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TImport_app::get_periodo(const TCBA_recset& fat) const
|
|
|
|
|
{
|
|
|
|
|
TString80 periodo;
|
|
|
|
|
fat.get(10).as_string(periodo);
|
|
|
|
|
|
|
|
|
|
if (periodo[0] >= '0' && periodo[0] <= '9')
|
|
|
|
|
{
|
|
|
|
|
const int mese = atoi(periodo.left(6 - periodo.len()));
|
|
|
|
|
if (mese >= 1 && mese < 12)
|
|
|
|
|
{
|
|
|
|
|
int anno = atoi(periodo.right(4));
|
|
|
|
|
periodo = itom(mese);
|
|
|
|
|
if (anno < 2000)
|
|
|
|
|
anno = fat.get(9).as_int();
|
|
|
|
|
periodo << ' ' << anno;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return get_tmp_string() = periodo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImport_app::importa_fatture(const TFilename& fname, const TString& codnum, const TString& cdc, TLog_report& log) const
|
2013-01-04 08:13:26 +00:00
|
|
|
|
{
|
|
|
|
|
TString str = TR("Importazione documenti");
|
|
|
|
|
log.log(0, str);
|
|
|
|
|
|
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
|
|
|
|
|
|
|
|
TCBA_recset fat;
|
|
|
|
|
fat.load_file(fname);
|
|
|
|
|
|
|
|
|
|
long ndocs = 0;
|
2013-01-30 17:02:41 +00:00
|
|
|
|
long mindoc = 0;
|
|
|
|
|
long maxdoc = 0;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
bool done = true;
|
|
|
|
|
|
|
|
|
|
long codcf = 0;
|
|
|
|
|
TString4 codpag;
|
2013-02-07 14:17:40 +00:00
|
|
|
|
TString periodo;
|
|
|
|
|
TToken_string ospiti(80, '@');
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
TProgind pi(fat.items(), str);
|
|
|
|
|
for (bool ok = fat.move_first(); ok && done; ok = fat.move_next())
|
|
|
|
|
{
|
|
|
|
|
done = pi.addstatus(1);
|
|
|
|
|
if (!done)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const TString4 tipo = fat.get(8).as_string();
|
|
|
|
|
|
|
|
|
|
if (tipo == "T")
|
|
|
|
|
{
|
|
|
|
|
TString80 cofi_paiv = fat.get(14).as_string();
|
|
|
|
|
cofi_paiv.trim(); cofi_paiv.upper();
|
|
|
|
|
codcf = find_clifo(cofi_paiv, clifo);
|
|
|
|
|
if (codcf <= 0)
|
|
|
|
|
{
|
|
|
|
|
str.format("Impossibile associare un cliente al C.F./P.I '%s' alla riga %ld",
|
|
|
|
|
(const char*)cofi_paiv, fat.current_row()+1);
|
|
|
|
|
log.log(2, str);
|
|
|
|
|
}
|
2013-02-07 14:17:40 +00:00
|
|
|
|
periodo = get_periodo(fat); // 10 + 9
|
|
|
|
|
fat.get(11).as_string(codpag);
|
|
|
|
|
|
|
|
|
|
fat.get(15).as_string(ospiti);
|
|
|
|
|
const char* ospite = ospiti.get(0);
|
|
|
|
|
if (codcf > 0 && ospite && *ospite > ' ')
|
|
|
|
|
aggiorna_referente(codcf, ospite);
|
|
|
|
|
|
2013-01-04 08:13:26 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tipo != "N" || codcf <= 0)
|
|
|
|
|
continue; // Considera solo le righe articolo di clienti validi
|
|
|
|
|
|
|
|
|
|
const TDate datadoc = fat.get_date(5);
|
|
|
|
|
const long ndoc = fat.get(6).as_int();
|
|
|
|
|
if (!datadoc.ok() || ndoc <= 0)
|
|
|
|
|
{
|
|
|
|
|
str.format("Data o numero documento nulli alla riga %ld", fat.current_row()+1);
|
|
|
|
|
log.log(2, str);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
TString80 codart;
|
|
|
|
|
codart << fat.get(12); codart.trim();
|
|
|
|
|
codart << '.' << cdc.right(3);
|
|
|
|
|
|
|
|
|
|
const TRectype& anamag = find_codart(codart);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
if (anamag.empty())
|
|
|
|
|
{
|
|
|
|
|
str.format("Articolo non valido '%s' alla riga %ld", (const char*)codart, fat.current_row()+1);
|
|
|
|
|
log.log(1, str);
|
2013-02-07 14:17:40 +00:00
|
|
|
|
continue;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
str = codart; str << "|1";
|
|
|
|
|
const TString4 um = cache().get(LF_UMART, str, UMART_UM);
|
|
|
|
|
|
2013-01-30 17:02:41 +00:00
|
|
|
|
TDocumento doc('D', datadoc.year(), codnum, 0);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
doc.put(DOC_TIPOCF, 'C');
|
|
|
|
|
doc.put(DOC_CODCF, codcf);
|
|
|
|
|
doc.put(DOC_DATADOC, datadoc);
|
2013-01-30 17:02:41 +00:00
|
|
|
|
doc.put(DOC_DOC1, ndoc);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
doc.put(DOC_CODPAG, codpag);
|
2013-01-30 17:02:41 +00:00
|
|
|
|
doc.put(DOC_STATO, 1);
|
2013-02-07 14:17:40 +00:00
|
|
|
|
doc.put(DOC_CODCMS, cdc);
|
|
|
|
|
|
|
|
|
|
TToken_string key;
|
|
|
|
|
key = "C";
|
|
|
|
|
key.add(codcf);
|
|
|
|
|
key.add("N");
|
|
|
|
|
TRecord_array nsban(key, LF_CFBAN);
|
|
|
|
|
if (nsban.rows() > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& rec = nsban.row(1);
|
|
|
|
|
doc.put(DOC_CODABIP, rec.get(CFBAN_ABI));
|
|
|
|
|
doc.put(DOC_CODCABP, rec.get(CFBAN_CAB));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key.add("V", 2);
|
|
|
|
|
TRecord_array vsban(key, LF_CFBAN);
|
|
|
|
|
if (vsban.rows() > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& rec = vsban.row(1);
|
|
|
|
|
doc.put(DOC_CODABIA, rec.get(CFBAN_ABI));
|
|
|
|
|
doc.put(DOC_CODCABA, rec.get(CFBAN_CAB));
|
|
|
|
|
doc.put(DOC_IBAN, rec.get(CFBAN_IBAN));
|
|
|
|
|
}
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
if (doc.rows() == 0) // Nuovo documento
|
|
|
|
|
{
|
|
|
|
|
doc.put(DOC_TIPODOC, "F01");
|
|
|
|
|
doc.put(DOC_STATO, 2);
|
|
|
|
|
doc.new_row("01");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRiga_documento& rdoc = doc[doc.physical_rows()];
|
|
|
|
|
rdoc.put(RDOC_CODART, codart);
|
|
|
|
|
rdoc.put(RDOC_CODARTMAG, codart);
|
|
|
|
|
rdoc.checked(true);
|
2013-02-07 14:17:40 +00:00
|
|
|
|
|
2013-01-04 08:13:26 +00:00
|
|
|
|
rdoc.put(RDOC_UMQTA, um);
|
|
|
|
|
rdoc.put(RDOC_QTA, UNO);
|
|
|
|
|
rdoc.put(RDOC_PREZZO, fat.get(19).as_real());
|
|
|
|
|
rdoc.put(RDOC_CODIVA, anamag.get(ANAMAG_CODIVA));
|
|
|
|
|
|
2013-02-07 14:17:40 +00:00
|
|
|
|
TString desc = anamag.get(ANAMAG_DESCR);
|
|
|
|
|
desc << ' ' << periodo;
|
|
|
|
|
if (!ospiti.empty_items())
|
|
|
|
|
{
|
|
|
|
|
const char* sep = " ";
|
|
|
|
|
FOR_EACH_TOKEN(ospiti, o) if (o && *o > ' ')
|
|
|
|
|
{
|
|
|
|
|
desc << sep << o;
|
|
|
|
|
sep = ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (desc.len() > 50)
|
|
|
|
|
{
|
|
|
|
|
TParagraph_string p(desc, 50);
|
|
|
|
|
rdoc.put(RDOC_DESCR, p.get());
|
|
|
|
|
rdoc.put(RDOC_DESCLUNGA, "X");
|
|
|
|
|
rdoc.put(RDOC_DESCEST, p.get());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rdoc.put(RDOC_DESCR, desc);
|
|
|
|
|
|
2013-01-04 08:13:26 +00:00
|
|
|
|
const int err = doc.write();
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
ndocs++;
|
2013-01-30 17:02:41 +00:00
|
|
|
|
maxdoc = doc.get_long(DOC_NDOC);
|
|
|
|
|
if (ndocs == 1)
|
|
|
|
|
mindoc = maxdoc;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-01-30 17:02:41 +00:00
|
|
|
|
str.format("Impossibile registrare il documento %s/%ld alla riga %ld",
|
|
|
|
|
(const char*)codnum, ndoc, fat.current_row()+1);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
log.log(2, str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.log(0, str.cut(0));
|
2013-02-07 14:17:40 +00:00
|
|
|
|
str << TR("Sono stati importati ") << ndocs << TR(" documenti ") << codnum
|
2013-01-30 17:02:41 +00:00
|
|
|
|
<< TR(" dal ") << mindoc << TR(" al ") << maxdoc;
|
2013-01-04 08:13:26 +00:00
|
|
|
|
log.log(0, str);
|
|
|
|
|
|
|
|
|
|
return done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TImport_app::main_loop()
|
|
|
|
|
{
|
2013-02-07 14:17:40 +00:00
|
|
|
|
open_files(LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_UMART, 0);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
|
|
|
|
|
TImport_mask mask;
|
|
|
|
|
while (mask.run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
TLog_report log;
|
|
|
|
|
TFilename fname = mask.get(F_DIR);
|
|
|
|
|
fname.add(mask.get(F_CLI));
|
2013-02-07 14:17:40 +00:00
|
|
|
|
if (!fname.exist())
|
|
|
|
|
{
|
|
|
|
|
cantread_box(fname);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const TString& cdc = mask.get(F_CDC);
|
|
|
|
|
if (importa_clienti(fname, cdc, log))
|
2013-01-04 08:13:26 +00:00
|
|
|
|
{
|
2013-01-30 17:02:41 +00:00
|
|
|
|
const TString& codnum = mask.get(F_NUM);
|
2013-01-04 08:13:26 +00:00
|
|
|
|
fname = mask.get(F_DIR);
|
|
|
|
|
fname.add(mask.get(F_FAT));
|
2013-02-07 14:17:40 +00:00
|
|
|
|
if (fname.exist())
|
|
|
|
|
importa_fatture(fname, codnum, cdc, log);
|
|
|
|
|
else
|
|
|
|
|
cantread_box(fname);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
log.log(2, TR("E' necessario correggere i problemi segnalati prima di importare le fatture"));
|
2013-01-04 08:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.preview();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ps0430400(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TImport_app a;
|
|
|
|
|
a.run(argc, argv, TR("Importazione CBA"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|