446 lines
12 KiB
C++
446 lines
12 KiB
C++
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <reputils.h>
|
|
#include <textset.h>
|
|
|
|
#include "../cg/cg2101.h"
|
|
|
|
#include "ps0431.h"
|
|
#include "ps0431100a.h"
|
|
|
|
#include <causali.h>
|
|
#include <clifo.h>
|
|
#include <mov.h>
|
|
#include <pconti.h>
|
|
#include <rmov.h>
|
|
#include <rmoviva.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TApollonia_msk
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TApollonia_msk : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TApollonia_msk() : TAutomask("ps0431100a") {}
|
|
};
|
|
|
|
bool TApollonia_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_CAUFAT:
|
|
if (e == fe_modify || e == fe_init)
|
|
{
|
|
if (field(F_CONCLI).empty())
|
|
{
|
|
const TRectype& rcaus1 = cache().get_rec(LF_RCAUSALI, o.get(), "1");
|
|
set(F_GRUCLI, rcaus1.get("GRUPPO"));
|
|
set(F_CONCLI, rcaus1.get("CONTO"), 0x3);
|
|
if (field(F_CONCLI).empty())
|
|
{
|
|
TISAM_recordset pcon("USE PCON SELECT TMCF='C'");
|
|
if (pcon.move_first())
|
|
{
|
|
set(F_GRUCLI, pcon.get("GRUPPO").as_int());
|
|
set(F_CONCLI, pcon.get("CONTO").as_int(), 0x3);
|
|
}
|
|
}
|
|
}
|
|
if (field(F_CONRIC).empty())
|
|
{
|
|
const TRectype& rcaus2 = cache().get_rec(LF_RCAUSALI, o.get(), "2");
|
|
set(F_GRURIC, rcaus2.get("GRUPPO"));
|
|
set(F_CONRIC, rcaus2.get("CONTO"));
|
|
set(F_SOTRIC, rcaus2.get("SOTTOCONTO"), 0x3);
|
|
}
|
|
}
|
|
break;
|
|
default: break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TApollonia_set
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TApollonia_set : public TCSV_recordset
|
|
{
|
|
public:
|
|
int get_int(const char* name) const { return TRecordset::get(name).as_int(); }
|
|
real get_real(const char* name) const;
|
|
const TString& get_str(const char* name) const { return TRecordset::get(name).as_string(); }
|
|
TApollonia_set(const TString& name);
|
|
};
|
|
|
|
real TApollonia_set::get_real(const char* name) const
|
|
{
|
|
TString16 val = TRecordset::get(name).as_string();
|
|
val.replace(',','.');
|
|
return real(val);
|
|
}
|
|
|
|
TApollonia_set::TApollonia_set(const TString& name) : TCSV_recordset("CSV(;)")
|
|
{
|
|
create_column("NOME", _alfafld);
|
|
create_column("COGNOME", _alfafld);
|
|
create_column("INDIRIZZO", _alfafld);
|
|
create_column("CITTA", _alfafld);
|
|
create_column("PROVINCIA", _alfafld);
|
|
create_column("CAP", _intfld);
|
|
create_column("CODFIS", _alfafld);
|
|
create_column("DATA", _datefld);
|
|
create_column("DESCR", _alfafld);
|
|
create_column("ENTRATA", _realfld);
|
|
create_column("USCITA", _realfld);
|
|
create_column("CB", _alfafld);
|
|
create_column("TIPOPAG", _alfafld);
|
|
create_column("DESPAG", _alfafld);
|
|
create_column("IMPONIBILE",_realfld);
|
|
create_column("IVA", _realfld);
|
|
create_column("RA", _realfld);
|
|
create_column("BOLLO", _realfld);
|
|
create_column("NUMERO", _intfld);
|
|
|
|
const TFilename fn = name;
|
|
load_file(fn);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TApollonia_app
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TApollonia_app : public TSkeleton_application
|
|
{
|
|
long _codcf, _numreg;
|
|
TString4 _caufat,_caupag, _codiva;
|
|
TBill _contoric, _clifo, _contocas, _contoass, _contoban, _contocar;
|
|
bool _read_only;
|
|
|
|
protected:
|
|
long cliente(const TApollonia_set& rec, TLog_report& log);
|
|
bool fattura(const TApollonia_set& rec, TLog_report& log);
|
|
bool pagame(const TApollonia_set& rec, TLog_report& log);
|
|
void elabora_riga(const TApollonia_set& rec, TLog_report& log);
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
// cerca o crea un cliente e ne ritorna il codice
|
|
long TApollonia_app::cliente(const TApollonia_set& rec, TLog_report& log)
|
|
{
|
|
TString16 cf = rec.get_str("CODFIS"); cf.trim();
|
|
if (cf.len() < 11)
|
|
{
|
|
TString msg;
|
|
msg.format("Riga %5ld: Codice fiscale non valido '%s'", rec.current_row()+1, (const char*)cf);
|
|
return 0;
|
|
}
|
|
|
|
TLocalisamfile cfile(LF_CLIFO);
|
|
TRectype& crec = cfile.curr();
|
|
|
|
cfile.setkey(4);
|
|
crec.put(CLI_TIPOCF, 'C');
|
|
crec.put(CLI_COFI, cf);
|
|
if (cfile.read() == NOERR)
|
|
return crec.get_long(CLI_CODCF);
|
|
|
|
if (cf.len() <= 12)
|
|
{
|
|
cfile.zero();
|
|
cfile.setkey(5);
|
|
crec.put(CLI_TIPOCF, 'C');
|
|
crec.put(CLI_PAIV, cf);
|
|
if (cfile.read() == NOERR)
|
|
return crec.get_long(CLI_CODCF);
|
|
}
|
|
|
|
TString80 ragsoc;
|
|
ragsoc = rec.get_str("COGNOME");
|
|
ragsoc.overwrite(rec.get_str("NOME"), 30);
|
|
ragsoc.cut(50); ragsoc.trim();
|
|
|
|
_codcf++;
|
|
cfile.zero();
|
|
crec.put(CLI_TIPOCF, 'C');
|
|
crec.put(CLI_CODCF, _codcf);
|
|
crec.put(CLI_RAGSOC, ragsoc);
|
|
if (cf[0] < '8')
|
|
crec.put(CLI_PAIV, cf);
|
|
else
|
|
crec.put(CLI_COFI, cf);
|
|
|
|
TString80 indirizzo = rec.get_str("INDIRIZZO");
|
|
const int comma = indirizzo.rfind(',');
|
|
if (comma > 4)
|
|
{
|
|
TString80 civ = indirizzo.mid(comma+1);
|
|
civ.trim();
|
|
if (civ.full() && civ.len() <= 8)
|
|
{
|
|
crec.put(CLI_CIVCF, civ);
|
|
indirizzo.cut(comma);
|
|
}
|
|
}
|
|
crec.put(CLI_INDCF, indirizzo);
|
|
const TString8 cap = rec.get_str("CAP");
|
|
const TString& codcom = cap2comune(cap, rec.get_str("CITTA"));
|
|
crec.put(CLI_COMCF, codcom);
|
|
crec.put(CLI_CAPCF, cap);
|
|
if (codcom.empty())
|
|
crec.put(CLI_LOCCF, rec.get_str("CITTA"));
|
|
|
|
if (!_read_only)
|
|
{
|
|
cfile.setkey(1);
|
|
while (cfile.write() == _isreinsert)
|
|
crec.put(CLI_CODCF, ++_codcf);
|
|
}
|
|
|
|
TString msg; msg << TR("Creazione cliente ") << _codcf << ' ' << ragsoc;
|
|
log.log(1, msg);
|
|
return _codcf;
|
|
}
|
|
|
|
bool TApollonia_app::fattura(const TApollonia_set& rec, TLog_report& log)
|
|
{
|
|
const int numdoc = rec.get_int("NUMERO");
|
|
if (numdoc <= 0)
|
|
return false; // Anticipo segnalato oltre
|
|
|
|
_numreg++;
|
|
|
|
TMovimentoPN mov;
|
|
TRectype& mrec = mov.curr();
|
|
|
|
const TDate datareg = rec.get_str("DATA");
|
|
mrec.put(MOV_NUMREG, _numreg);
|
|
mrec.put(MOV_DATAREG, datareg);
|
|
mrec.put(MOV_ANNOIVA, datareg.year());
|
|
mrec.put(MOV_PROTIVA, numdoc);
|
|
|
|
mrec.put(MOV_NUMDOC, numdoc);
|
|
mrec.put(MOV_DATADOC, datareg);
|
|
TString80 desc; desc.format(FR("Fattura n. %d"), numdoc);
|
|
mrec.put(MOV_DESCR, desc);
|
|
|
|
TEsercizi_contabili esc;
|
|
const int annoes = esc.date2esc(datareg);
|
|
mrec.put(MOV_DATACOMP, datareg);
|
|
mrec.put(MOV_ANNOES, annoes);
|
|
|
|
mrec.put(MOV_TIPO, 'C');
|
|
mrec.put(MOV_CODCF, _clifo.codclifo());
|
|
|
|
const TCausale caus(_caufat, datareg.year());
|
|
mrec.put(MOV_CODCAUS, _caufat);
|
|
mrec.put(MOV_REG, caus.reg().name());
|
|
|
|
const real imp = rec.get_real("IMPONIBILE");
|
|
mrec.put(MOV_TOTDOC, imp);
|
|
|
|
TRectype& irec = mov.iva(0);
|
|
irec.put(RMI_IMPONIBILE, imp);
|
|
irec.put(RMI_CODIVA, _codiva);
|
|
irec.put(RMI_IMPOSTA, rec.get_real("IVA"));
|
|
_contoric.put(irec);
|
|
|
|
TRectype& r1 = mov.cg(0);
|
|
r1.put(RMV_SEZIONE, 'D');
|
|
r1.put(RMV_IMPORTO, imp);
|
|
r1.put(RMV_DATAREG, datareg);
|
|
r1.put(RMV_ANNOES, annoes);
|
|
_clifo.put(r1);
|
|
_contoric.put(r1, true);
|
|
|
|
TRectype& r2 = mov.cg(1);
|
|
r2.put(RMV_SEZIONE, 'A');
|
|
r2.put(RMV_IMPORTO, imp);
|
|
r2.put(RMV_DATAREG, datareg);
|
|
r2.put(RMV_ANNOES, annoes);
|
|
_clifo.put(r2, true);
|
|
_contoric.put(r2);
|
|
|
|
if (!_read_only)
|
|
{
|
|
while (mov.write() == _isreinsert)
|
|
mrec.put(MOV_NUMREG, ++_numreg);
|
|
}
|
|
|
|
TString msg; msg.format(TR("Fattura %d del %s : n. reg. %ld %s"),
|
|
numdoc, datareg.stringa(), _numreg, (const char*)rec.get_str("COGNOME"));
|
|
log.log(0, msg);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TApollonia_app::pagame(const TApollonia_set& rec, TLog_report& log)
|
|
{
|
|
TMovimentoPN mov;
|
|
TRectype& mrec = mov.curr();
|
|
_numreg++;
|
|
|
|
const TDate datareg = rec.get_str("DATA");
|
|
mrec.put(MOV_NUMREG, _numreg);
|
|
mrec.put(MOV_DATAREG, datareg);
|
|
mrec.put(MOV_DATADOC, datareg);
|
|
|
|
const int numdoc = rec.get_int("NUMERO");
|
|
mrec.put(MOV_NUMDOC, numdoc);
|
|
|
|
TString desc;
|
|
desc = rec.get_str("DESCR");
|
|
if (desc.blank())
|
|
{
|
|
if (numdoc > 0)
|
|
desc.format(FR("Incasso Fattura n. %d"), numdoc);
|
|
else
|
|
desc.format(FR("Anticipo su fattura"));
|
|
}
|
|
mrec.put(MOV_DESCR, desc);
|
|
|
|
TEsercizi_contabili esc;
|
|
const int annoes = esc.date2esc(datareg);
|
|
mrec.put(MOV_DATACOMP, datareg);
|
|
mrec.put(MOV_ANNOES, annoes);
|
|
|
|
mrec.put(MOV_CODCAUS, _caupag);
|
|
|
|
const real imp = rec.get_real("IMPONIBILE");
|
|
mrec.put(MOV_TOTDOC, imp);
|
|
|
|
TBill counter = _contocas;
|
|
const TString& tipopag = rec.get_str("TIPOPAG");
|
|
if (tipopag.starts_with("Con", true))
|
|
counter = _contocas; else
|
|
if (tipopag.starts_with("Ass", true))
|
|
counter = _contoass; else
|
|
if (tipopag.starts_with("Ban", true))
|
|
counter = _contoban; else
|
|
if (tipopag.starts_with("Car", true))
|
|
counter = _contocar;
|
|
|
|
TRectype& r1 = mov.cg(0);
|
|
r1.put(RMV_SEZIONE, 'A');
|
|
r1.put(RMV_IMPORTO, imp);
|
|
r1.put(RMV_DATAREG, datareg);
|
|
r1.put(RMV_ANNOES, annoes);
|
|
_clifo.put(r1);
|
|
counter.put(r1, true);
|
|
|
|
TRectype& r2 = mov.cg(1);
|
|
r2.put(RMV_SEZIONE, 'D');
|
|
r2.put(RMV_IMPORTO, imp);
|
|
r2.put(RMV_DATAREG, datareg);
|
|
r2.put(RMV_ANNOES, annoes);
|
|
counter.put(r2);
|
|
_clifo.put(r2, true);
|
|
|
|
if (!_read_only)
|
|
{
|
|
while (mov.write() == _isreinsert)
|
|
mrec.put(MOV_NUMREG, ++_numreg);
|
|
}
|
|
|
|
TString msg;
|
|
if (numdoc > 0)
|
|
{
|
|
msg.format(FR("Incasso fattura %d del %s : n. reg. %ld %s"),
|
|
numdoc, datareg.stringa(), _numreg, (const char*)rec.get_str("COGNOME"));
|
|
log.log(0, msg);
|
|
}
|
|
else
|
|
{
|
|
msg.format(FR("Anticipo del %s : n. reg. %ld %s"),
|
|
datareg.stringa(), _numreg, (const char*)rec.get_str("COGNOME"));
|
|
log.log(1, msg);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void TApollonia_app::elabora_riga(const TApollonia_set& rec, TLog_report& log)
|
|
{
|
|
const long codcf = cliente(rec, log);
|
|
if (codcf > 0)
|
|
{
|
|
_clifo.codclifo() = codcf;
|
|
|
|
fattura(rec, log);
|
|
pagame(rec, log);
|
|
}
|
|
}
|
|
|
|
void TApollonia_app::main_loop()
|
|
{
|
|
open_files(LF_TABCOM, LF_COMUNI, LF_CLIFO, LF_CAUSALI, LF_MOV, LF_RMOV,LF_RMOVIVA, 0);
|
|
|
|
TApollonia_msk m;
|
|
while (m.run() == K_ENTER)
|
|
{
|
|
const TFilename txt = m.get(F_FILE);
|
|
TLog_report log(txt.name());
|
|
if (txt.exist())
|
|
{
|
|
TApollonia_set recset(txt);
|
|
TProgress_monitor pi(recset.items(), TR("Importazione txt"));
|
|
_caufat = m.get(F_CAUFAT);
|
|
_caupag = m.get(F_CAUPAG);
|
|
_clifo.set(m.get_int(F_GRUCLI), m.get_int(F_CONCLI), 0L, 'C');
|
|
_contoric.get(m, F_GRURIC, F_CONRIC, F_SOTRIC);
|
|
_contocas.get(m, F_GRUCAS, F_CONCAS, F_SOTCAS);
|
|
_contoass.get(m, F_GRUASS, F_CONASS, F_SOTASS);
|
|
_contoban.get(m, F_GRUBAN, F_CONBAN, F_SOTBAN);
|
|
_contocar.get(m, F_GRUCAR, F_CONCAR, F_SOTCAR);
|
|
_codiva = m.get(F_CODIVA);
|
|
_read_only = m.get_bool(F_READONLY);
|
|
if (!_read_only)
|
|
_read_only = !yesno_box(TR("Confermare la registrazione definitiva dei movimenti"));
|
|
|
|
_codcf = _numreg = 0;
|
|
|
|
if (_codcf <= 0) // Dummy test
|
|
{
|
|
TLocalisamfile cfile(LF_CLIFO);
|
|
cfile.put(CLI_TIPOCF, 'F');
|
|
if (cfile.read(_isgteq) == NOERR)
|
|
{
|
|
if (cfile.read(_isprev) == NOERR)
|
|
_codcf = cfile.get_long(CLI_CODCF);
|
|
}
|
|
}
|
|
if (_numreg <= 0) // Dummy Test
|
|
{
|
|
TLocalisamfile mfile(LF_MOV);
|
|
if (mfile.last() == NOERR)
|
|
_numreg = mfile.get_long(MOV_NUMREG);
|
|
}
|
|
|
|
for (bool go = recset.move_first(); go; go = recset.move_next())
|
|
{
|
|
if (recset.get_real("IMPONIBILE").is_zero())
|
|
continue;
|
|
elabora_riga(recset, log);
|
|
pi.set_status(recset.current_row());
|
|
}
|
|
}
|
|
if (log.recordset()->items())
|
|
log.preview();
|
|
}
|
|
}
|
|
|
|
int ps0431100(int argc, char* argv[])
|
|
{
|
|
TApollonia_app a;
|
|
a.run(argc, argv, TR("Generazione fatture"));
|
|
return 0;
|
|
}
|