Supporto per allegati a fattura P.A.

git-svn-id: svn://10.65.10.50/branches/R_10_00@23100 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2015-05-20 10:04:00 +00:00
parent 5618a1b489
commit 66243e8aaa

View File

@ -3,7 +3,10 @@
#include <execp.h> #include <execp.h>
#include <golem.h> #include <golem.h>
#include <progind.h> #include <progind.h>
#include <reputils.h>
#include <tabutil.h>
#include <utility.h> #include <utility.h>
#include <agasys.h>
#include "../ve/velib05.h" #include "../ve/velib05.h"
@ -46,7 +49,8 @@ static bool chiave_paf(const TDocumento& doc, TString& cess, TString& numdoc)
// Crea la coppia di chiavi per il db PAF a partire da un semplice record di testata documento // Crea la coppia di chiavi per il db PAF a partire da un semplice record di testata documento
static bool chiave_paf(const TRectype& doc, TString& cess, TString& numdoc) static bool chiave_paf(const TRectype& doc, TString& cess, TString& numdoc)
{ {
TString8 key; key.format("C|%ld", doc.get_long(DOC_CODCF)); const long codcf = doc.get_long(DOC_CODCF);
TString8 key; key.format("C|%ld", codcf);
cess = cache().get(LF_CFVEN, key, CFV_PADESTIN); cess = cache().get(LF_CFVEN, key, CFV_PADESTIN);
CHECK(cess.full(), "Destinatario fattura P.A. non valido"); CHECK(cess.full(), "Destinatario fattura P.A. non valido");
@ -466,12 +470,26 @@ class TPA_mask : public TAutomask
{ {
protected: protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
void fill(); void fill();
void init();
bool is_fattura(const TRectype& doc) const;
public: public:
TPA_mask() : TAutomask("pa0100a") {} TPA_mask() : TAutomask("pa0100a") { }
}; };
bool TPA_mask::is_fattura(const TRectype& doc) const
{
const TTipo_documento& td = cached_tipodoc(doc.get(DOC_TIPODOC));
if (!td.is_fattura()) // Tengo per buone solo le fatture e le note di credito
return false;
const TCodice_numerazione& cn = cached_numerazione(doc.get(DOC_CODNUM));
return !cn.get_bool("B10"); // Controlla se fattura provvisioria esclusa sda P.A.
}
void TPA_mask::fill() void TPA_mask::fill()
{ {
TSheet_field& docs = sfield(F_DOCS); TSheet_field& docs = sfield(F_DOCS);
@ -553,9 +571,11 @@ bool TPA_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{ {
case F_DATAINI: case F_DATAINI:
if (e == fe_init) if (e == fe_init)
o.set("01-06-2014"); o.set(ini_get_string(CONFIG_DITTA, "pa", "LastXML", "31-03-2015")); else
if (e == fe_modify) if (e == fe_modify)
fill(); fill(); else
if (e == fe_close)
ini_set_string(CONFIG_DITTA, "pa", "LastXML", o.get());
break; break;
case F_SHOWALL: case F_SHOWALL:
if (e == fe_modify) if (e == fe_modify)
@ -595,6 +615,8 @@ class TDoc2Paf : public TSkeleton_application
TAnagrafica _ditta; TAnagrafica _ditta;
TString16 _cofi; TString16 _cofi;
TFilename _dbname; TFilename _dbname;
TLog_report* _log;
TString _logpaf;
private: private:
int parse_line(const TString& line, TString& var, TString& val) const; int parse_line(const TString& line, TString& var, TString& val) const;
@ -605,10 +627,14 @@ private:
protected: protected:
bool parse_sconto(const TString& formula, TToken_string& sconti) const; bool parse_sconto(const TString& formula, TToken_string& sconti) const;
bool get_bnp_iban(const TString& abi, const TString& cab, int prg, TString& iban) const;
bool get_bank(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const; bool get_bank(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const;
const char* descrizione(const TRiga_documento& rdoc) const; const char* descrizione(const TRiga_documento& rdoc) const;
const TRectype& cco(const TRectype& doc) const; // Contratto/Convenzione/Offerta const TRectype& cco(const TRectype& doc) const; // Contratto/Convenzione/Offerta
void log(int severity, const char* msg);
bool show_log();
bool elabora(TDocumentoEsteso& doc); bool elabora(TDocumentoEsteso& doc);
bool elabora(const TRectype& rec); bool elabora(const TRectype& rec);
bool elabora(const TDoc_key& key); bool elabora(const TDoc_key& key);
@ -619,6 +645,8 @@ public:
virtual bool create(); virtual bool create();
virtual bool destroy(); virtual bool destroy();
virtual void main_loop(); virtual void main_loop();
TDoc2Paf() : _log(NULL) {}
}; };
bool TDoc2Paf::parse_sconto(const TString& formula, TToken_string& sconti) const bool TDoc2Paf::parse_sconto(const TString& formula, TToken_string& sconti) const
@ -646,43 +674,66 @@ bool TDoc2Paf::parse_sconto(const TString& formula, TToken_string& sconti) const
return sconti.full(); return sconti.full();
} }
bool TDoc2Paf::get_bnp_iban(const TString& abi, const TString& cab, int nprog, TString& iban) const
{
TTable bnp("BNP");
TString16 key;
key << abi << cab;
if (nprog > 0)
{
TString4 sprog; sprog.format("%02d", nprog);
key << sprog;
}
bnp.put("CODTAB", key);
int err = bnp.read(_isgteq);
if (err == NOERR && !bnp.get("CODTAB").starts_with(abi))
err = _iskeynotfound;
if (err == NOERR)
iban = bnp.get("S3");
return err == NOERR;
}
bool TDoc2Paf::get_bank(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const bool TDoc2Paf::get_bank(const TDocumento& doc, TString& iban, TString& abi, TString& cab, TString& istituto) const
{ {
bool found = false; bool found = false;
TToken_string key; abi = doc.get(DOC_CODABIP);
key.add("C"); key.add(doc.codcf()); key.add("N"); key.add(1); cab = doc.get(DOC_CODCABP);
const TRectype& cfban = cache().get(LF_CFBAN, key); int prg = doc.get_int(DOC_PROGBNP);
if (!cfban.empty())
found = abi.full() && cab.full();
if (found)
get_bnp_iban(abi, cab, prg, iban);
if (!found) // Se non trovo banca sul DOC la cerco su CFBAN
{ {
abi = cfban.get(CFBAN_ABI); TToken_string key;
cab = cfban.get(CFBAN_CAB); key.add("C"); key.add(doc.codcf()); key.add("N"); key.add(1);
found = abi.full() && cab.full(); const TRectype& cfban = cache().get(LF_CFBAN, key);
iban = cfban.get(CFBAN_IBAN); if (!cfban.empty())
if (iban.blank() && found)
{ {
key.cut(0) << abi << cab << cfban.get(CFBAN_PROGPR); abi = cfban.get(CFBAN_ABI);
iban = cache().get("BNP", key, "S3"); cab = cfban.get(CFBAN_CAB);
prg = cfban.get_int(CFBAN_PROGPR);
found = abi.full() && cab.full();
iban = cfban.get(CFBAN_IBAN);
if (found && iban.blank())
get_bnp_iban(abi, cab, prg, iban);
} }
} }
if (!found) if (!found) // Se non trovo banca su CFBAN la cerco su CFVEN
{ {
const TRectype& cfven = doc.clifor().vendite(); const TRectype& cfven = doc.clifor().vendite();
abi = cfven.get(CFV_CODABIPR); abi = cfven.get(CFV_CODABIPR);
cab = cfven.get(CFV_CODCABPR); cab = cfven.get(CFV_CODCABPR);
found = abi.full() && cab.full(); found = abi.full() && cab.full();
if (!found) if (found)
{ get_bnp_iban(abi, cab, 0, iban);
abi = doc.get(DOC_CODABIP);
cab = doc.get(DOC_CODCABP);
found = abi.full() && cab.full();
}
} }
if (found) if (found)
{
istituto = cache().get("%BAN", abi, "S0"); istituto = cache().get("%BAN", abi, "S0");
}
return found; return found;
} }
@ -757,6 +808,38 @@ const TRectype& TDoc2Paf::cco(const TRectype& doc) const
return cache().get("&CON", conkey); return cache().get("&CON", conkey);
} }
void TDoc2Paf::log(int severity, const char* msg)
{
if (severity < 0)
{
_logpaf = msg;
} else
if (_log == NULL)
{
_log = new TLog_report;
if (_logpaf.full())
{
TString txt;
txt << _logpaf << ": " << msg;
_log->log(severity, txt);
}
else
_log->log(severity, msg);
}
}
bool TDoc2Paf::show_log()
{
bool ok = true;
if (_log)
{
_log->preview();
delete _log;
_log = NULL;
ok = noyes_box(TR("Si desidera procedere con la generazione file xml?"));
}
return ok;
}
bool TDoc2Paf::elabora(TDocumentoEsteso& doc) bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
{ {
@ -764,6 +847,7 @@ bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
TString20 bfatt; // Codice univoco di 20 caratteri del documento TString20 bfatt; // Codice univoco di 20 caratteri del documento
if (!chiave_paf(doc, hfatt, bfatt)) if (!chiave_paf(doc, hfatt, bfatt))
return false; return false;
log(-1, bfatt);
const TFirm& firm = prefix().firm(); const TFirm& firm = prefix().firm();
const char* const paese = "IT"; const char* const paese = "IT";
@ -1052,6 +1136,9 @@ bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
paf1200f.insert(); paf1200f.insert();
} }
} }
if (cup.blank() && cig.blank())
log(1, "CIG e CUP assenti");
// <DatiBeniServizi> // <DatiBeniServizi>
@ -1219,7 +1306,7 @@ bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
paf2400f.set("PN_KEYBODYFATT", bfatt); paf2400f.set("PN_KEYBODYFATT", bfatt);
paf2400f.remove(); // Cancella i dati pagamento paf2400f.remove(); // Cancella i dati pagamento
const TPagamento& pag = doc.pagamento(); TPagamento& pag = doc.pagamento();
doc.scadenze_recalc(); // Ricalcola array delle rate doc.scadenze_recalc(); // Ricalcola array delle rate
TString_array& scad = doc.scadenze(); TString_array& scad = doc.scadenze();
const int nrate = scad.items(); // Conta rate generate const int nrate = scad.items(); // Conta rate generate
@ -1247,6 +1334,11 @@ bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
paf2500f.set("PO_CAB", cab); paf2500f.set("PO_CAB", cab);
} }
if (cab.blank())
log(2, TR("Non sono presenti ABI, CAB, IBAN per il pagamento")); else
if (iban.blank())
log(1, TR("Non è presente il codice IBAN per il pagamento"));
for (int nr = 0; nr < nrate; nr++) for (int nr = 0; nr < nrate; nr++)
{ {
paf2500f.set("PO_KEYNPROGR", long(nr+1)); // Numero rata paf2500f.set("PO_KEYNPROGR", long(nr+1)); // Numero rata
@ -1270,6 +1362,52 @@ bool TDoc2Paf::elabora(TDocumentoEsteso& doc)
paf2500f.insert(); paf2500f.insert();
} }
TToken_string allegati = doc.get("COLL_GOLEM");
if (allegati.full())
{
TFilename fzip;
fzip = prefix().get_studio();
fzip.add("sql"); fzip.add("attach");
make_dir(fzip);
TString20 code = bfatt; code.replace('/', '_');
fzip.add(code); fzip << ".zip";
TFilename fname;
if (allegati.items() <= 2) // Una sola coppia (path|nome)
{
fname = allegati.get(0);
aga_zip(fname, fzip);
}
else
{
TFilename flist; flist.tempdir(); flist.add("ziplist.txt");
ofstream list(flist);
FOR_EACH_TOKEN(allegati, str)
{
fname = str;
if (fname.exist())
list << fname << endl;
}
list.close();
aga_zip_filelist(flist, fzip);
xvt_fsys_remove_file(flist);
}
TPaf_record paf2600f("PAF2600F");
paf2600f.set("PP_KEYHEADERFATT", hfatt);
paf2600f.set("PP_KEYBODYFATT", bfatt);
paf2600f.remove(); // Cancella allegati
if (fzip.exist())
{
paf2600f.set("PP_NOMEATTACHMENT", fname.name());
paf2600f.set("PP_FMTATTACHMENT", fname.ext());
paf2600f.set("PP_ATTACHMENT", fzip);
paf2600f.set("PP_COMPRESSIONE", "ZIP");
paf2600f.insert();
}
}
// </DatiPagamento> // </DatiPagamento>
return true; return true;
@ -1396,7 +1534,8 @@ void TDoc2Paf::main_loop()
} }
if (ndocs > 0) if (ndocs > 0)
{ {
genera_xml(); if (show_log())
genera_xml();
return; return;
} }
@ -1424,7 +1563,7 @@ void TDoc2Paf::main_loop()
break; break;
} }
message_box(FR("Sono stati elaborati %d documenti"), ndocs); message_box(FR("Sono stati elaborati %d documenti"), ndocs);
if (ndocs > 0) if (ndocs > 0 && show_log())
genera_xml(); genera_xml();
} }
} }
@ -1521,7 +1660,7 @@ bool TDoc2Paf::create_table(TScanner& paf, const TString& table)
bool TDoc2Paf::create() bool TDoc2Paf::create()
{ {
open_files(LF_TAB, LF_TABCOM, LF_TABMOD, LF_ANAG, open_files(LF_TAB, LF_TABCOM, LF_TABMOD, LF_ANAG,
LF_CLIFO, LF_CFVEN, LF_NDITTE, LF_CLIFO, LF_CFVEN, LF_CFBAN, LF_NDITTE,
LF_DOC, LF_RIGHEDOC, 0); LF_DOC, LF_RIGHEDOC, 0);
TRectype cfven(LF_CFVEN); TRectype cfven(LF_CFVEN);