2005-06-10 12:55:53 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <automask.h>
|
|
|
|
#include <execp.h>
|
|
|
|
#include <filetext.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <printer.h>
|
2006-07-11 13:10:51 +00:00
|
|
|
#include <sort.h>
|
2005-06-10 12:55:53 +00:00
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include "dt0.h"
|
|
|
|
#include "dt0400a.h"
|
|
|
|
|
|
|
|
#include "clifo.h"
|
|
|
|
#include "comuni.h"
|
2005-09-20 10:53:56 +00:00
|
|
|
#include "doc.h"
|
|
|
|
#include "rdoc.h"
|
|
|
|
|
|
|
|
#include "..\cg\cglib01.h"
|
2006-07-11 13:10:51 +00:00
|
|
|
#include "..\ve\velib.h"
|
2005-06-10 12:55:53 +00:00
|
|
|
|
|
|
|
// TAutomask
|
|
|
|
|
|
|
|
class TDT2Doc_mask : public TAutomask
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
|
|
TDT2Doc_mask();
|
|
|
|
virtual ~TDT2Doc_mask(){};
|
|
|
|
};
|
|
|
|
|
|
|
|
TDT2Doc_mask::TDT2Doc_mask() :TAutomask ("dt0400a")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TDT2Doc_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TFile_text
|
|
|
|
|
|
|
|
class TDT2Doc_file: public TFile_text
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
|
|
|
|
|
|
|
public:
|
2006-07-11 13:10:51 +00:00
|
|
|
TDT2Doc_file(const TString& file_name, const TString& config_name) : TFile_text(file_name, config_name) {};
|
2005-06-10 12:55:53 +00:00
|
|
|
virtual ~TDT2Doc_file() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
void TDT2Doc_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
|
|
|
{
|
|
|
|
const TString code(s.get(0));
|
|
|
|
TString valore = str;
|
|
|
|
if (code == "_UPPERCASE")
|
|
|
|
{
|
|
|
|
valore.upper();
|
|
|
|
}
|
|
|
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
|
|
|
str = valore;
|
|
|
|
}
|
|
|
|
|
2005-09-20 10:53:56 +00:00
|
|
|
HIDDEN bool browse_file_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
if (k == K_F9)
|
|
|
|
{
|
|
|
|
FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC));
|
|
|
|
strcpy(fs.type, "");
|
|
|
|
strcpy(fs.name, f.get());
|
|
|
|
xvt_fsys_get_default_dir(&fs.dir);
|
|
|
|
xvt_fsys_save_dir();
|
|
|
|
if (xvt_dm_post_file_open(&fs, TR("Selezione file")) == FL_OK)
|
|
|
|
{
|
|
|
|
TFilename n;
|
|
|
|
xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(n.size()), n.size());
|
|
|
|
n.add(fs.name);
|
|
|
|
f.set(n);
|
|
|
|
}
|
|
|
|
xvt_fsys_restore_dir();
|
|
|
|
f.set_focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
// TSkeleton_application
|
|
|
|
|
|
|
|
class TDT2Doc : public TSkeleton_application
|
|
|
|
{
|
|
|
|
TDT2Doc_mask* _msk;
|
|
|
|
TDT2Doc_file* _trasfile;
|
2006-07-11 13:10:51 +00:00
|
|
|
TLocalisamfile* _clifor;
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
TRelation* _rel;
|
|
|
|
TCursor* _cur;
|
|
|
|
TProgind* _prog;
|
2006-07-11 13:10:51 +00:00
|
|
|
TAssoc_array* _array_clifor;
|
2005-09-20 10:53:56 +00:00
|
|
|
TAssoc_array* _confditte;
|
|
|
|
TAssoc_array* _confdoc;
|
|
|
|
TAssoc_array* _totalilordi;
|
|
|
|
TAssoc_array* _castelletto;
|
|
|
|
TAssoc_array* _primariga;
|
2006-07-11 13:10:51 +00:00
|
|
|
TString80 _cms, _condpag, _codnum, _negozio, _speseacc1, _speseacc2, _scontofin;
|
2005-09-20 10:53:56 +00:00
|
|
|
bool _contnetto;
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
public:
|
2006-07-12 09:19:43 +00:00
|
|
|
bool print_header(const TFilename& percorso);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
void print_line(const TString& rigastampa = "");
|
|
|
|
void print_footer();
|
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
|
|
|
virtual void main_loop();
|
2006-07-11 13:10:51 +00:00
|
|
|
bool import_clifor(const TFilename& percorso, const char tipocf);
|
|
|
|
bool import_documenti(const TFilename& percorso, const bool doc_attivi);
|
|
|
|
bool elabora_documenti(const bool doc_attivi);
|
|
|
|
const long get_nextcodcf(const char tipocf);
|
2005-09-20 10:53:56 +00:00
|
|
|
bool load_conf_ditte();
|
|
|
|
bool load_conf_doc();
|
2006-07-11 13:10:51 +00:00
|
|
|
char check_negozio(const TFilename& percorso);
|
|
|
|
bool error_msg(const TString& msg, const TString16& causale, const int numdoc, const TString& codice);
|
|
|
|
void rename_file(const TFilename& percorso);
|
|
|
|
int get_numdoc(const TString& numdocrif, const TDate datadoc, const TString& _codnum, const TString& tipodoc, const long codcf);
|
|
|
|
int add_riga_doc(TDocumento* doc, TConfig& config);
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
TDT2Doc() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TDT2Doc& app() { return (TDT2Doc&) main_app(); }
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
bool TDT2Doc::print_header(const TFilename& percorso)
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
|
|
|
if (printer().open())
|
|
|
|
{
|
|
|
|
TDate oggi(TODAY);
|
|
|
|
TPrintrow row;
|
|
|
|
TString256 rigastampa;
|
2005-09-20 10:53:56 +00:00
|
|
|
rigastampa = "IMPORTAZIONE FILE ";
|
|
|
|
rigastampa << percorso;
|
2005-06-10 12:55:53 +00:00
|
|
|
rigastampa.center_just(80);
|
|
|
|
row.put(rigastampa);
|
|
|
|
row.put("@>", 1);
|
|
|
|
row.put("Pag. @#", 65);
|
|
|
|
printer().setheaderline(2, row);
|
|
|
|
rigastampa = "";
|
|
|
|
rigastampa.fill('-',80);
|
|
|
|
row.reset();
|
|
|
|
row.put(rigastampa);
|
|
|
|
printer().setheaderline(3, row);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
2006-07-11 13:10:51 +00:00
|
|
|
return error_box(TR("Errore in apertura stampante."));
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TDT2Doc::print_line(const TString& rigastampa)
|
|
|
|
{
|
|
|
|
TPrintrow row;
|
|
|
|
row.reset();
|
|
|
|
if (rigastampa.not_empty())
|
|
|
|
{
|
|
|
|
row.put((const char*) rigastampa);
|
|
|
|
printer().print(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TDT2Doc::print_footer()
|
|
|
|
{
|
|
|
|
printer().formfeed();
|
|
|
|
printer().close();
|
|
|
|
}
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
char TDT2Doc::check_negozio(const TFilename& percorso)
|
2005-09-20 10:53:56 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
char tipocf = 'E';
|
|
|
|
TConfig config_studio(CONFIG_STUDIO, "dt");
|
|
|
|
TString80 nomefile(percorso.name());
|
|
|
|
TString80 estensione(percorso.ext());
|
|
|
|
const int fine = nomefile.find(estensione);
|
|
|
|
if (fine > 0)
|
|
|
|
nomefile = nomefile.sub(0,fine-1);
|
|
|
|
if (_confditte->is_key(nomefile))
|
2005-09-20 10:53:56 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TToken_string& config = (TToken_string&) _confditte->find(nomefile);
|
|
|
|
TString16 dittastr(config.get());
|
2005-09-20 10:53:56 +00:00
|
|
|
_cms = config.get();
|
|
|
|
_codnum = config.get();
|
2006-07-11 13:10:51 +00:00
|
|
|
tipocf = config.get_char();
|
2005-09-20 10:53:56 +00:00
|
|
|
if (_codnum.empty())
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
error_box(TR("Attenzione: manca la numerazione corrispondente al negozio. Completare la tabella prima di effettuare il trasferimento"));
|
|
|
|
tipocf = 'E';
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
else
|
2006-07-11 13:10:51 +00:00
|
|
|
{
|
|
|
|
const long ditta = atol(dittastr);
|
|
|
|
if (prefix().exist(ditta))
|
|
|
|
{
|
|
|
|
_negozio = nomefile.sub(2);
|
|
|
|
load_conf_doc();
|
|
|
|
if (!set_firm(ditta))
|
|
|
|
tipocf = 'E';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error_box(TR("Attenzione: non esiste la ditta %ld; trasferimento annullato"), ditta);
|
|
|
|
tipocf = 'E';
|
|
|
|
}
|
|
|
|
}
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
else
|
2006-07-11 13:10:51 +00:00
|
|
|
{
|
|
|
|
error_box(TR("Attenzione: manca la corrispondenza negozio - ditta; trasferimento annullato"));
|
|
|
|
tipocf = 'E';
|
|
|
|
}
|
|
|
|
return tipocf;
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TDT2Doc::load_conf_ditte()
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TConfig config_studio(TConfig(CONFIG_STUDIO, "dt"));
|
2005-09-20 10:53:56 +00:00
|
|
|
TToken_string workstring;
|
|
|
|
_confditte->destroy();
|
|
|
|
for (int k = 0; config_studio.exist("ConfDitte", k); k++)
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
workstring = config_studio.get("ConfDitte", NULL, k);
|
|
|
|
TString16 negozio(workstring.get(0));
|
|
|
|
negozio << workstring.get(1);
|
|
|
|
const TString16 ditta(workstring.get(2));
|
|
|
|
const TString80 cms(workstring.get(3));
|
|
|
|
const TString16 codnum(workstring.get(4));
|
|
|
|
const char attpass(workstring.get_char());
|
2005-09-20 10:53:56 +00:00
|
|
|
TToken_string config;
|
|
|
|
config.add(ditta);
|
|
|
|
config.add(cms);
|
|
|
|
config.add(codnum);
|
2006-07-11 13:10:51 +00:00
|
|
|
config.add(attpass);
|
2005-09-20 10:53:56 +00:00
|
|
|
_confditte->add(negozio, config);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TDT2Doc::load_conf_doc()
|
|
|
|
{
|
|
|
|
TConfig config_studio = TConfig(CONFIG_STUDIO, "dt");
|
|
|
|
TToken_string workstring;
|
|
|
|
_confdoc->destroy();
|
|
|
|
for (int k = 0; config_studio.exist("ConfDoc", k); k++)
|
|
|
|
{
|
|
|
|
workstring = config_studio.get("ConfDoc", NULL, k);
|
|
|
|
TToken_string chiavedt;
|
|
|
|
TString80 negozio = workstring.get(0);
|
|
|
|
negozio.trim();
|
|
|
|
if (negozio == _negozio)
|
|
|
|
{
|
|
|
|
chiavedt.add(workstring.get(1));
|
|
|
|
chiavedt.add(workstring.get(2));
|
|
|
|
TToken_string chiavecampo;
|
|
|
|
chiavecampo.add(workstring.get(3));
|
|
|
|
chiavecampo.add(workstring.get(4));
|
|
|
|
_confdoc->add(chiavedt, chiavecampo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_condpag = config_studio.get("CondPag");
|
|
|
|
_contnetto = config_studio.get_bool("ContNettoSconto");
|
2006-07-11 13:10:51 +00:00
|
|
|
_speseacc1 = config_studio.get("SpeseAcc1");
|
|
|
|
_speseacc2 = config_studio.get("SpeseAcc2");
|
|
|
|
_scontofin = config_studio.get("ScontoFin");
|
2005-09-20 10:53:56 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
bool TDT2Doc::create()
|
|
|
|
{
|
|
|
|
open_files(LF_CLIFO, 0);
|
|
|
|
_msk = new TDT2Doc_mask();
|
2005-09-20 10:53:56 +00:00
|
|
|
_msk->set_handler(F_PERCORSO, browse_file_handler);
|
|
|
|
_cms = " ";
|
|
|
|
_condpag = " ";
|
2006-07-11 13:10:51 +00:00
|
|
|
_clifor = new TLocalisamfile(LF_CLIFO);
|
2005-09-20 10:53:56 +00:00
|
|
|
// array delle corrispondenze tra codici clienti
|
2006-07-11 13:10:51 +00:00
|
|
|
_array_clifor = new TAssoc_array();
|
2005-09-20 10:53:56 +00:00
|
|
|
// array della configurazione negozi/ditte
|
|
|
|
_confditte = new TAssoc_array();
|
|
|
|
load_conf_ditte();
|
|
|
|
// array delle corrispondenze documenti
|
|
|
|
_confdoc = new TAssoc_array();
|
|
|
|
// verra' caricato quando si e' deciso il negozio
|
|
|
|
//load_conf_doc();
|
|
|
|
// riepilogo iva per redistribuzione sconto per aliquote
|
|
|
|
_totalilordi = new TAssoc_array();
|
|
|
|
// castelletto iva per controllo imponibili
|
|
|
|
_castelletto = new TAssoc_array();
|
|
|
|
// primariga di ogni aliquota
|
|
|
|
_primariga = new TAssoc_array();
|
|
|
|
return TSkeleton_application::create ();
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
bool TDT2Doc::destroy()
|
|
|
|
{
|
2005-09-20 10:53:56 +00:00
|
|
|
delete _primariga;
|
|
|
|
delete _castelletto;
|
|
|
|
delete _totalilordi;
|
|
|
|
delete _confdoc;
|
|
|
|
delete _confditte;
|
2006-07-11 13:10:51 +00:00
|
|
|
delete _array_clifor;
|
|
|
|
delete _clifor;
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
delete _msk;
|
|
|
|
return TApplication::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TDT2Doc::main_loop()
|
|
|
|
{
|
2005-09-20 10:53:56 +00:00
|
|
|
TString80 percorso;
|
2005-06-10 12:55:53 +00:00
|
|
|
KEY tasto;
|
2005-09-20 10:53:56 +00:00
|
|
|
TConfig configfile("dt0400.ini");
|
|
|
|
_msk->set(F_PERCORSO, configfile.get("PERCORSO", "OPZIONI"));
|
2005-06-10 12:55:53 +00:00
|
|
|
tasto = _msk->run();
|
|
|
|
if (tasto == K_ENTER)
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TFilename percorso(_msk->get(F_PERCORSO));
|
|
|
|
const char tipocf = check_negozio(percorso);
|
|
|
|
if (tipocf != 'E')
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
2005-09-20 10:53:56 +00:00
|
|
|
if (print_header(percorso))
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
const bool doc_attivi = tipocf == 'A';
|
|
|
|
_trasfile = new TDT2Doc_file(percorso, (doc_attivi ? true, "dt0400a.ini" : "dt0400b.ini"));
|
|
|
|
import_clifor(percorso, (doc_attivi ? true, 'C' : 'F'));
|
|
|
|
int error = import_documenti(percorso, doc_attivi);
|
2005-09-20 10:53:56 +00:00
|
|
|
configfile.set("PERCORSO", percorso, "OPZIONI");
|
|
|
|
delete _trasfile;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
rename_file(percorso);
|
|
|
|
message_box(TR("Importazione documenti completata"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
message_box(TR("Errori nell'importazione"));
|
2005-09-20 10:53:56 +00:00
|
|
|
print_footer();
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
const long TDT2Doc::get_nextcodcf(const char tipocfchiesto)
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TLocalisamfile& clifo = *_clifor;
|
2005-06-10 12:55:53 +00:00
|
|
|
long codcf = 1L ;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (tipocfchiesto == 'C')
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
if (!clifo.empty())
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
clifo.zero() ;
|
|
|
|
clifo.setkey(1) ;
|
|
|
|
clifo.put(CLI_TIPOCF, 'F');
|
|
|
|
clifo.read(_isgteq) ;
|
|
|
|
if (clifo.good())
|
|
|
|
clifo.prev() ;
|
|
|
|
clifo.setstatus(NOERR);
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
else clifo.last();
|
|
|
|
if (clifo.good())
|
|
|
|
{
|
|
|
|
const TFixed_string tipocf(clifo.get(CLI_TIPOCF));
|
|
|
|
if ( tipocf == "C")
|
|
|
|
{
|
|
|
|
codcf = clifo.get_long(CLI_CODCF);
|
|
|
|
if (codcf == 999999)
|
|
|
|
clifo.prev();
|
|
|
|
codcf = clifo.get_long(CLI_CODCF)+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clifo.last();
|
|
|
|
if (clifo.good())
|
|
|
|
{
|
|
|
|
const TFixed_string tipocf(clifo.get(CLI_TIPOCF));
|
|
|
|
if ( tipocf == "C")
|
|
|
|
codcf = 1;
|
|
|
|
else
|
|
|
|
codcf = clifo.get_long(CLI_CODCF)+1;
|
|
|
|
}
|
|
|
|
}
|
2005-06-10 12:55:53 +00:00
|
|
|
return codcf;
|
|
|
|
}
|
|
|
|
|
2005-09-20 10:53:56 +00:00
|
|
|
bool TDT2Doc::error_msg(const TString& msg, const TString16& causale, const int numdoc, const TString& codice)
|
|
|
|
{
|
|
|
|
TString messaggio;
|
|
|
|
TString16 desdoc;
|
|
|
|
TToken_string str(causale);
|
|
|
|
TString16 tipodoc = str.get(1);
|
|
|
|
if (tipodoc == "A")
|
|
|
|
desdoc = "Fatt. acc.";
|
|
|
|
else if (tipodoc == "B")
|
|
|
|
desdoc = "Bolla";
|
|
|
|
else if (tipodoc == "D")
|
|
|
|
desdoc = "Fatt. diff.";
|
|
|
|
messaggio.format("Doc. %s %s, n. %d non trasferito: %s %s", (const char*) causale, (const char*) desdoc, numdoc, (const char*) msg, (const char*) codice);
|
|
|
|
print_line(messaggio);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
bool TDT2Doc::import_documenti(const TFilename& percorso, const bool doc_attivi)
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
|
|
|
// eliminazione files delle elaborazioni precedenti
|
|
|
|
TString_array transactions;
|
2006-07-11 13:10:51 +00:00
|
|
|
TFilename dtfiles; dtfiles.tempdir();
|
|
|
|
dtfiles.add("ditet*.ini");
|
|
|
|
list_files(dtfiles, transactions);
|
2005-06-10 12:55:53 +00:00
|
|
|
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
2006-07-11 13:10:51 +00:00
|
|
|
remove_file(*name);
|
|
|
|
TFilename tempname;
|
|
|
|
if (doc_attivi)
|
|
|
|
_trasfile->open(percorso, 'r');
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// riordina i record del file di input documenti passivi per ndoc+tiporec
|
|
|
|
tempname.temp("", "txt");
|
|
|
|
const size_t recordsize = 256;
|
|
|
|
char * buf = new char[recordsize];
|
|
|
|
ifstream infile(percorso);
|
|
|
|
ofstream outfile(tempname);
|
|
|
|
TSort s(recordsize);
|
|
|
|
s.addsortkey(8, 3);
|
|
|
|
s.addsortkey(11, 10);
|
|
|
|
s.addsortkey(6, 2);
|
|
|
|
s.init();
|
|
|
|
while (infile.getline(buf, recordsize) != NULL)
|
|
|
|
s.sort(buf);
|
|
|
|
s.endsort();
|
|
|
|
delete buf;
|
|
|
|
const char * outbuf;
|
|
|
|
while ((outbuf = s.retrieve()) != NULL)
|
|
|
|
outfile << outbuf << endl;
|
|
|
|
_trasfile->open(tempname, 'r');
|
|
|
|
}
|
|
|
|
bool error = elabora_documenti(doc_attivi);
|
|
|
|
_trasfile->close();
|
|
|
|
if (tempname.exist())
|
|
|
|
remove_file(tempname);
|
|
|
|
TString80 applicat;
|
|
|
|
applicat.format("ve0.exe -1 -i%s", (const char*) dtfiles);
|
|
|
|
TExternal_app gestdoc(applicat);
|
|
|
|
gestdoc.run();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TDT2Doc::get_numdoc(const TString& numdocrif, const TDate datadoc, const TString& _codnum, const TString& tipodoc, const long codcf)
|
|
|
|
{
|
|
|
|
int numdoc = 0;
|
|
|
|
TRelation rel(LF_DOC);
|
|
|
|
TRectype& curr = rel.curr();
|
|
|
|
curr.put(DOC_TIPOCF, "F");
|
|
|
|
curr.put(DOC_CODCF, codcf);
|
|
|
|
curr.put(DOC_PROVV, "D");
|
|
|
|
curr.put(DOC_ANNO, datadoc.year());
|
|
|
|
curr.put(DOC_DATADOC, datadoc);
|
|
|
|
curr.put(DOC_CODNUM, _codnum);
|
|
|
|
TCursor cur(&rel, "", 2, &curr, &curr);
|
|
|
|
const long items = cur.items();
|
|
|
|
for (cur = 0; cur.pos() < items; ++cur)
|
|
|
|
{
|
|
|
|
TString80 ndr = cur.curr().get(DOC_NUMDOCRIF);
|
|
|
|
ndr.trim();
|
|
|
|
if (ndr == numdocrif)
|
|
|
|
numdoc = cur.curr().get_int(DOC_NDOC);
|
|
|
|
}
|
|
|
|
return numdoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TDT2Doc::add_riga_doc(TDocumento* doc, TConfig& config)
|
|
|
|
{
|
|
|
|
TRiga_documento& riga = doc->new_row(config.get(RDOC_TIPORIGA));
|
|
|
|
riga.put(RDOC_QTA, config.get(RDOC_QTA));
|
|
|
|
riga.put(RDOC_UMQTA,config.get(RDOC_UMQTA));
|
|
|
|
riga.put(RDOC_CODIVA, config.get(RDOC_CODIVA));
|
|
|
|
riga.put(RDOC_PREZZO, config.get(RDOC_PREZZO));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TDT2Doc::rename_file(const TFilename& percorso)
|
|
|
|
{
|
|
|
|
TFilename newfile;
|
|
|
|
const TDate data(TODAY);
|
|
|
|
TString str = data.string(full,'-',full,full,amg_date);
|
|
|
|
str.strip("-");
|
|
|
|
TFilename renamedfiles(percorso);
|
|
|
|
renamedfiles << str;
|
|
|
|
newfile = renamedfiles;
|
|
|
|
renamedfiles << "*.*";
|
|
|
|
TString_array listfiles;
|
|
|
|
list_files(renamedfiles, listfiles);
|
|
|
|
int suffisso = 0;
|
|
|
|
FOR_EACH_ARRAY_ROW(listfiles, row, name)
|
|
|
|
{
|
|
|
|
TString80 namef(*name);
|
|
|
|
namef.trim();
|
|
|
|
suffisso = atoi(namef.right(1));
|
|
|
|
}
|
|
|
|
suffisso++;
|
|
|
|
newfile << suffisso;
|
|
|
|
if (fcopy(percorso, newfile))
|
|
|
|
remove_file(percorso);
|
|
|
|
TString messaggio;
|
|
|
|
messaggio << "Il file " << percorso << " e' stato copiato in " << newfile;
|
|
|
|
print_line(messaggio);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TDT2Doc::elabora_documenti(const bool doc_attivi)
|
|
|
|
{
|
|
|
|
const long dimension = fsize(_trasfile->name());
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
TProgind pi(dimension,"Importazione in corso...");
|
2005-09-20 10:53:56 +00:00
|
|
|
TConfig* docum=NULL;
|
|
|
|
TString256 stampa;
|
|
|
|
real* tl;
|
2005-06-10 12:55:53 +00:00
|
|
|
int err = NOERR;
|
|
|
|
int ntransac=0;
|
2005-09-20 10:53:56 +00:00
|
|
|
int nriga=0;
|
|
|
|
bool error = FALSE;
|
|
|
|
real sconto(ZERO);
|
|
|
|
real importodoc(ZERO);
|
|
|
|
real percsconto(ZERO);
|
|
|
|
int numdoc;
|
|
|
|
TString16 causale;
|
2006-07-11 13:10:51 +00:00
|
|
|
TDocumento* doc=NULL;
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
TRecord_text curr;
|
|
|
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
|
|
|
{
|
|
|
|
pi.setstatus(_trasfile->read_file()->tellg());
|
2005-09-20 10:53:56 +00:00
|
|
|
if ((curr.type() == "01") || (curr.type()=="06"))// testata documento oppure ho finito i doc. e sono ai clienti
|
|
|
|
{
|
|
|
|
// verifico il castelletto
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
if (sconto != ZERO && !_contnetto)
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
const int ndec = TCurrency::get_firm_dec(false);
|
|
|
|
TGeneric_distrib d(sconto, ndec);
|
2005-09-20 10:53:56 +00:00
|
|
|
for (tl = (real*) _totalilordi->first_item(); tl != NULL; tl = (real*) _totalilordi->succ_item())
|
|
|
|
d.add(*tl);
|
|
|
|
real totsconti(ZERO);
|
|
|
|
for (tl = (real*) _totalilordi->first_item(); tl != NULL; tl = (real*) _totalilordi->succ_item())
|
|
|
|
{
|
|
|
|
sconto = d.get();
|
2006-07-11 13:10:51 +00:00
|
|
|
const TString& codiva = _totalilordi->get_hashobj()->key();
|
2005-09-20 10:53:56 +00:00
|
|
|
TCodiceIVA codiceIVA(codiva);
|
2006-07-11 13:10:51 +00:00
|
|
|
codiceIVA.scorpora(sconto, ndec);
|
2005-09-20 10:53:56 +00:00
|
|
|
real& imp_calcolato = *tl;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (_castelletto->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& imp_castelletto = (real&) _castelletto->find(codiva);
|
|
|
|
codiceIVA.scorpora(imp_calcolato, ndec);
|
|
|
|
real diff = imp_calcolato-sconto-imp_castelletto;
|
|
|
|
if (sconto != ZERO)
|
|
|
|
{
|
|
|
|
if (doc_attivi)
|
|
|
|
sconto += diff;
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "07");
|
|
|
|
docum->set(RDOC_DESCR, "Sconto");
|
|
|
|
docum->set(RDOC_PREZZO, sconto.string());
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
totsconti+=sconto;
|
|
|
|
if (!doc_attivi)
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_CODART, codiva);
|
|
|
|
docum->set(RDOC_DESCR, "Pareggio sconto");
|
|
|
|
docum->set(RDOC_QTA, "1");
|
|
|
|
docum->set(RDOC_PREZZO, sconto.string());
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("incongruenza nel castelletto - iva assente ", causale, numdoc, codiva);
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (tl = (real*) _totalilordi->first_item(); tl != NULL; tl = (real*) _totalilordi->succ_item())
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
const TString& codiva = _totalilordi->get_hashobj()->key();
|
2005-09-20 10:53:56 +00:00
|
|
|
TCodiceIVA codiceIVA(codiva);
|
|
|
|
real& imp_calcolato = *tl;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (_castelletto->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& imp_castelletto = (real&) _castelletto->find(codiva);
|
|
|
|
codiceIVA.scorpora(imp_calcolato, TCurrency::get_firm_dec(true));
|
|
|
|
real diff = imp_castelletto-imp_calcolato;
|
|
|
|
diff.round(2);
|
|
|
|
if (diff != ZERO)
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_DESCR, "Rettifica");
|
|
|
|
docum->set(RDOC_PREZZO, diff.string());
|
|
|
|
docum->set(RDOC_QTA, "1");
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
TString& codart = (TString&) _primariga->find(codiva);
|
|
|
|
docum->set(RDOC_CODART, codart);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("incongruenza nel castelletto - iva assente ", causale, numdoc, codiva);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((!doc_attivi) && (doc!=NULL))
|
|
|
|
{
|
|
|
|
// verifico tabella iva
|
|
|
|
TAssoc_array& tabella_iva = doc->tabella_iva();
|
|
|
|
TRiepilogo_iva* riepilogo_iva;
|
|
|
|
// Scorre tutti gli elementi della tabella IVA del documento (elementi per codice iva)
|
|
|
|
for (riepilogo_iva = (TRiepilogo_iva*) tabella_iva.first_item(); riepilogo_iva != NULL; riepilogo_iva = (TRiepilogo_iva*) tabella_iva.succ_item())
|
|
|
|
{
|
|
|
|
const TString& codiva_riep = riepilogo_iva->cod_iva().codice();
|
|
|
|
real& imp_castelletto = (real&) _castelletto->find( codiva_riep);
|
|
|
|
real imponibile = riepilogo_iva->imponibile();
|
|
|
|
real diff = imp_castelletto-imponibile;
|
2005-09-20 10:53:56 +00:00
|
|
|
diff.round(2);
|
|
|
|
if (diff != ZERO)
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_DESCR, "Rettifica");
|
2006-07-11 13:10:51 +00:00
|
|
|
docum->set(RDOC_PREZZO, diff.string());
|
2005-09-20 10:53:56 +00:00
|
|
|
docum->set(RDOC_QTA, "1");
|
2006-07-11 13:10:51 +00:00
|
|
|
docum->set(RDOC_CODIVA, codiva_riep);
|
|
|
|
TString& codart = (TString&) _primariga->find(codiva_riep);
|
2005-09-20 10:53:56 +00:00
|
|
|
docum->set(RDOC_CODART, codart);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
2006-07-11 13:10:51 +00:00
|
|
|
add_riga_doc(doc, *docum);
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
// chiudo il file precedente
|
|
|
|
_totalilordi->destroy();
|
|
|
|
_castelletto->destroy();
|
|
|
|
_primariga->destroy();
|
|
|
|
if (docum != NULL)
|
|
|
|
{
|
|
|
|
delete docum;
|
|
|
|
docum = NULL;
|
|
|
|
}
|
|
|
|
if (error) // cancello il file perch'e la transazione non e' andata bene
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TFilename dtfile; dtfile.tempdir();
|
|
|
|
dtfile.add(format("ditet%03d.ini",ntransac));
|
|
|
|
if (dtfile.exist())
|
|
|
|
remove_file(dtfile);
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
error = FALSE;
|
|
|
|
if (curr.type() == "01")
|
|
|
|
{
|
|
|
|
ntransac++;
|
2006-07-11 13:10:51 +00:00
|
|
|
TFilename dtfile; dtfile.tempdir();
|
|
|
|
dtfile.add(format("ditet%03d.ini",ntransac));
|
|
|
|
docum = new TConfig(dtfile);
|
2005-09-20 10:53:56 +00:00
|
|
|
sconto = ZERO;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (doc_attivi)
|
|
|
|
numdoc = atoi(curr.get(3));
|
|
|
|
else
|
|
|
|
numdoc = 0;
|
2005-09-20 10:53:56 +00:00
|
|
|
const TDate datadoc = (TDate) curr.get(4);
|
|
|
|
causale = curr.get(10);
|
|
|
|
causale << "|";
|
|
|
|
causale << curr.get(2);
|
|
|
|
causale.trim();
|
|
|
|
// cerca sul file di configurazione la corrispondenza causale|tipodoc -> tipodocCAMPO|stato
|
|
|
|
if (_confdoc->is_key(causale))
|
|
|
|
{
|
|
|
|
TToken_string str = (TToken_string&) _confdoc->find(causale);
|
|
|
|
const TString16 tipodoc = str.get();
|
|
|
|
if (tipodoc.not_empty())
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TString16 codcfdt;
|
|
|
|
codcfdt = curr.get(5);
|
|
|
|
if (_array_clifor->is_key(codcfdt))
|
2005-09-20 10:53:56 +00:00
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TString& codcf = (TString&) _array_clifor->find(codcfdt);
|
2005-09-20 10:53:56 +00:00
|
|
|
nriga=0;
|
|
|
|
docum->set_paragraph("Transaction");
|
|
|
|
docum->set("Action","INSERT");
|
|
|
|
docum->set("Mode","AUTO");
|
|
|
|
docum->set_paragraph(format("%d",LF_DOC));
|
|
|
|
docum->set(DOC_ANNO, datadoc.year());
|
|
|
|
docum->set(DOC_PROVV, "D");
|
|
|
|
docum->set(DOC_CODNUM, _codnum);
|
|
|
|
docum->set(DOC_TIPODOC, tipodoc);
|
2006-07-11 13:10:51 +00:00
|
|
|
if (!doc_attivi)
|
|
|
|
{
|
|
|
|
TString80 numdocrif = curr.get(3);
|
|
|
|
numdocrif.strip("/");
|
|
|
|
numdocrif.strip("\\");
|
|
|
|
numdocrif.strip("-");
|
|
|
|
numdocrif.strip("_");
|
|
|
|
numdocrif.trim();
|
|
|
|
numdoc = get_numdoc(numdocrif, datadoc, _codnum, tipodoc, atol(codcf));
|
|
|
|
docum->set(DOC_NUMDOCRIF, numdocrif);
|
|
|
|
docum->set(DOC_DATADOCRIF, datadoc);
|
|
|
|
}
|
|
|
|
if (numdoc != 0)
|
|
|
|
docum->set(DOC_NDOC, numdoc);
|
2005-09-20 10:53:56 +00:00
|
|
|
docum->set(DOC_DATADOC, datadoc);
|
2006-07-11 13:10:51 +00:00
|
|
|
docum->set(DOC_TIPOCF, (doc_attivi ? "C": "F"));
|
|
|
|
docum->set(DOC_CODCF, codcf);
|
2005-09-20 10:53:56 +00:00
|
|
|
TString16 codpag = curr.get(6);
|
|
|
|
codpag.trim();
|
|
|
|
const TString16 codpagdt = cache().get("%DTP", codpag, "S4");
|
|
|
|
if (codpagdt.blank())
|
|
|
|
docum->set(DOC_CODPAG, _condpag);
|
|
|
|
else
|
|
|
|
docum->set(DOC_CODPAG, codpagdt);
|
2006-07-11 13:10:51 +00:00
|
|
|
// istanzio TDocumento per fare le verifiche sul castelletto
|
|
|
|
if (doc != NULL)
|
|
|
|
delete doc;
|
|
|
|
doc = new TDocumento('D', datadoc.year(), _codnum, 0);
|
|
|
|
doc->set_tipo(tipodoc);
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("cliente non identificato", causale, numdoc, "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("manca la corrispondenza sul tipo documento", causale, numdoc, "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("manca la corrispondenza sul tipo documento", causale, numdoc, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (curr.type() == "02") // castelletto iva
|
|
|
|
{
|
|
|
|
TString16 tabiva = curr.get(5);
|
|
|
|
tabiva.trim();
|
|
|
|
tabiva.rpad(4);
|
|
|
|
TString str = curr.get(6);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
tabiva.rpad(7);
|
|
|
|
str = curr.get(7);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
const TString16 codiva = cache().get("%DTI", tabiva, "S4");
|
|
|
|
if (codiva.not_empty())
|
|
|
|
{
|
|
|
|
real importo = (real) curr.get(9);
|
|
|
|
importo=importo/100;
|
|
|
|
real* oggetto = new real(importo);
|
|
|
|
_castelletto->add(codiva,(TObject*)oggetto);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
// creo le righe di doc. perche' nei doc.passivi non ci sono
|
|
|
|
if (!doc_attivi)
|
|
|
|
{
|
|
|
|
real imposta = (real) curr.get(10);
|
|
|
|
imposta=imposta/100;
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_CODART, codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
if (!_primariga->is_key(codiva))
|
|
|
|
{
|
|
|
|
TString* ca = new TString(codiva);
|
|
|
|
_primariga->add(codiva,(TObject*)ca);
|
|
|
|
}
|
|
|
|
docum->set(RDOC_DESCR, "Riga documento ");
|
|
|
|
real qta = 1;
|
|
|
|
TString str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, "N.");
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real impostacalc = codiceIVA.imposta(importo);
|
|
|
|
str = importo.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
if (imposta != impostacalc) //inserisco riga di rettifica IVA
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "15");
|
|
|
|
docum->set(RDOC_CODART, codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
if (!_primariga->is_key(codiva))
|
|
|
|
{
|
|
|
|
TString* ca = new TString(codiva);
|
|
|
|
_primariga->add(codiva,(TObject*)ca);
|
|
|
|
}
|
|
|
|
docum->set(RDOC_DESCR, "Rettifica IVA ");
|
|
|
|
real qta = 1;
|
|
|
|
TString str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, "N.");
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real diff = imposta - impostacalc;
|
|
|
|
str = diff.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
real importoriga = importo+impostacalc;
|
|
|
|
if (_totalilordi->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& importor = (real&)_totalilordi->find(codiva);
|
|
|
|
importor+=importoriga;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real* oggetto = new real(importoriga);
|
|
|
|
_totalilordi->add(codiva,(TObject*)oggetto);
|
|
|
|
}
|
|
|
|
}
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("manca la corrispondenza iva" ,causale, numdoc, tabiva);
|
|
|
|
}
|
|
|
|
else if (curr.type() == "03") // piede documento (serve per leggere lo sconto)
|
|
|
|
{
|
|
|
|
importodoc = (real) curr.get(5);
|
|
|
|
importodoc = importodoc/100;
|
|
|
|
sconto = (real) curr.get(6);
|
|
|
|
sconto = sconto/100;
|
|
|
|
importodoc = importodoc + sconto;
|
|
|
|
percsconto = sconto/importodoc;
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
if (!doc_attivi)
|
|
|
|
{
|
|
|
|
TString str;
|
|
|
|
// sconto finanziario
|
|
|
|
real scontofin = (real) curr.get(9);
|
|
|
|
real importoriga = scontofin/100;
|
|
|
|
if (importoriga != ZERO)
|
|
|
|
{
|
|
|
|
const TString16 codiva = cache().get("SPP", _scontofin, "S3");
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "02");
|
|
|
|
docum->set(RDOC_CODART, _scontofin);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
docum->set(RDOC_DESCR, "Sconto finanziario");
|
|
|
|
real qta = 1;
|
|
|
|
str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, "N.");
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real imposta = codiceIVA.imposta(importoriga);
|
|
|
|
str = importoriga.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
// spese accessorie 1
|
|
|
|
char segno = curr.get(10)[0];
|
|
|
|
importoriga = (real) curr.get(11);
|
|
|
|
importoriga = importoriga/100;
|
|
|
|
if (segno == '-')
|
|
|
|
importoriga = -importoriga;
|
|
|
|
if (importoriga != ZERO)
|
|
|
|
{
|
|
|
|
TString16 tabiva = curr.get(12);
|
|
|
|
tabiva.trim();
|
|
|
|
tabiva.rpad(4);
|
|
|
|
str = curr.get(13);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
tabiva.rpad(7);
|
|
|
|
str = curr.get(14);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
const TString16 codiva = cache().get("%DTI", tabiva, "S4");
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "02");
|
|
|
|
docum->set(RDOC_CODART, _speseacc1);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
if (!_primariga->is_key(codiva))
|
|
|
|
{
|
|
|
|
TString* ca = new TString(_speseacc1);
|
|
|
|
_primariga->add(codiva,(TObject*)ca);
|
|
|
|
}
|
|
|
|
docum->set(RDOC_DESCR, "Spese accessorie 1");
|
|
|
|
real qta = 1;
|
|
|
|
str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, "N.");
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real imposta = codiceIVA.imposta(importoriga);
|
|
|
|
str = importoriga.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
if (_contnetto)
|
|
|
|
{
|
|
|
|
real importo = importoriga+imposta;
|
|
|
|
if (_totalilordi->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& importoi = (real&)_totalilordi->find(codiva);
|
|
|
|
importoi+=importo; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real* oggetto = new real(importo);
|
|
|
|
_totalilordi->add(codiva,(TObject*)oggetto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //aggiungo la rettifica per far quadrare il castelletto
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_DESCR, "Rettifica spese acc. 1");
|
|
|
|
importoriga = -importoriga;
|
|
|
|
str = importoriga.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
docum->set(RDOC_QTA, "1");
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
TString& codart = (TString&) _primariga->find(codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// spese accessorie 2
|
|
|
|
segno = curr.get(15)[0];
|
|
|
|
importoriga = (real) curr.get(16);
|
|
|
|
importoriga = importoriga/100;
|
|
|
|
if (segno =='-')
|
|
|
|
importoriga = -importoriga;
|
|
|
|
if (importoriga != ZERO)
|
|
|
|
{
|
|
|
|
TString16 tabiva = curr.get(17);
|
|
|
|
tabiva.trim();
|
|
|
|
tabiva.rpad(4);
|
|
|
|
TString str = curr.get(18);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
tabiva.rpad(7);
|
|
|
|
str = curr.get(19);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
const TString16 codiva = cache().get("%DTI", tabiva, "S4");
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "02");
|
|
|
|
docum->set(RDOC_CODART, _speseacc2);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
if (!_primariga->is_key(codiva))
|
|
|
|
{
|
|
|
|
TString* ca = new TString(_speseacc2);
|
|
|
|
_primariga->add(codiva,(TObject*)ca);
|
|
|
|
}
|
|
|
|
docum->set(RDOC_DESCR, "Spese accessorie 2");
|
|
|
|
real qta = 1;
|
|
|
|
str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, "N.");
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real imposta = codiceIVA.imposta(importoriga);
|
|
|
|
str = importoriga.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
if (_contnetto)
|
|
|
|
{
|
|
|
|
real importo = importoriga+imposta;
|
|
|
|
if (_totalilordi->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& importoi = (real&)_totalilordi->find(codiva);
|
|
|
|
importoi+=importo; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real* oggetto = new real(importo);
|
|
|
|
_totalilordi->add(codiva,(TObject*)oggetto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // aggiungo la rettifica per far quadrare il castelletto
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_DESCR, "Rettifica spese acc. 2");
|
|
|
|
importoriga = -importoriga;
|
|
|
|
str = importoriga.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
|
|
|
docum->set(RDOC_QTA, "1");
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
TString& codart = (TString&) _primariga->find(codiva);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
add_riga_doc(doc, *docum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
|
|
|
else if ((!error) && (curr.type() == "04" || curr.type() == "05")) // righe documento
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
2005-09-20 10:53:56 +00:00
|
|
|
TString16 tabiva = curr.get(11);
|
|
|
|
tabiva.trim();
|
|
|
|
tabiva.rpad(4);
|
|
|
|
TString str = curr.get(12);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
tabiva.rpad(7);
|
|
|
|
str = curr.get(19);
|
|
|
|
str.trim();
|
|
|
|
tabiva << str;
|
|
|
|
const TString16 codiva = cache().get("%DTI", tabiva, "S4");
|
|
|
|
if (codiva.not_empty())
|
|
|
|
{
|
|
|
|
nriga++;
|
|
|
|
docum->set_paragraph(format("%d,%d",LF_RIGHEDOC, nriga));
|
|
|
|
TString80 codart = curr.get(6);
|
|
|
|
codart.trim();
|
|
|
|
docum->set(RDOC_CHECKED, "X");
|
|
|
|
docum->set(RDOC_TIPORIGA, "01");
|
|
|
|
docum->set(RDOC_CODART, codart);
|
|
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
|
|
if (!_primariga->is_key(codiva))
|
|
|
|
{
|
|
|
|
TString* ca = new TString(codart);
|
|
|
|
_primariga->add(codiva,(TObject*)ca);
|
|
|
|
}
|
|
|
|
const TRectype& recanamag = cache().get(LF_ANAMAG, codart);
|
|
|
|
if (!recanamag.empty())
|
|
|
|
docum->set(RDOC_CODARTMAG,codart);
|
|
|
|
docum->set(RDOC_DESCR, curr.get(7));
|
|
|
|
real qta = (real) curr.get(8);
|
|
|
|
qta = qta/1000;
|
|
|
|
TString str = qta.string();
|
|
|
|
docum->set(RDOC_QTA, str);
|
|
|
|
docum->set(RDOC_UMQTA, curr.get(9));
|
|
|
|
real prezzo = (real) curr.get(10);
|
|
|
|
prezzo = prezzo/100;
|
|
|
|
TCodiceIVA codiceIVA((const char*) codiva);
|
|
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
|
|
real importoriga = prezzo*qta;
|
|
|
|
codiceIVA.scorpora(importoriga, TCurrency::get_firm_dec(true));
|
|
|
|
importoriga.round(TCurrency::get_firm_dec());
|
|
|
|
prezzo = importoriga/qta;
|
|
|
|
prezzo.round(TCurrency::get_firm_dec(true));
|
|
|
|
str = prezzo.string();
|
|
|
|
docum->set(RDOC_PREZZO, str);
|
2006-07-11 13:10:51 +00:00
|
|
|
add_riga_doc(doc, *docum);
|
2005-09-20 10:53:56 +00:00
|
|
|
importoriga=prezzo*qta;
|
|
|
|
importoriga = codiceIVA.lordo(importoriga, TCurrency::get_firm_dec(true));
|
|
|
|
if (_totalilordi->is_key(codiva))
|
|
|
|
{
|
|
|
|
real& importo = (real&)_totalilordi->find(codiva);
|
|
|
|
importo+=importoriga;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
real* oggetto = new real(importoriga);
|
|
|
|
_totalilordi->add(codiva,(TObject*)oggetto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = error_msg("manca la corrispondenza iva" ,causale, numdoc, tabiva);
|
|
|
|
}
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
2005-09-20 10:53:56 +00:00
|
|
|
// chiudo l'ultimo file
|
|
|
|
if (docum != NULL)
|
|
|
|
delete docum;
|
2006-07-11 13:10:51 +00:00
|
|
|
if (doc != NULL)
|
|
|
|
delete doc;
|
|
|
|
|
2005-09-20 10:53:56 +00:00
|
|
|
if (error) // cancello il file perch'e la transazione non e' andata bene
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
TFilename dtfile; dtfile.tempdir();
|
|
|
|
dtfile.add(format("ditet%03d.ini",ntransac));
|
|
|
|
if (dtfile.exist())
|
|
|
|
remove_file(dtfile);
|
|
|
|
|
2005-09-20 10:53:56 +00:00
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
return error;
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
bool TDT2Doc::import_clifor(const TFilename& percorso, const char tipocf)
|
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
{
|
|
|
|
// cache per i comuni
|
|
|
|
TRecord_cache cache_comuni(LF_COMUNI, 2);
|
|
|
|
_trasfile->open('r');
|
2005-09-20 10:53:56 +00:00
|
|
|
const long dimension = fsize(percorso);
|
2005-06-10 12:55:53 +00:00
|
|
|
TProgind pi(dimension,"Importazione in corso...");
|
|
|
|
TRelation rel(LF_CLIFO);
|
|
|
|
TRectype& reccli = rel.curr();
|
|
|
|
TLocalisamfile& clifo = rel.lfile();
|
2006-07-11 13:10:51 +00:00
|
|
|
_array_clifor->destroy();
|
2005-09-20 10:53:56 +00:00
|
|
|
TString256 stampa;
|
2006-07-11 13:10:51 +00:00
|
|
|
|
2005-06-10 12:55:53 +00:00
|
|
|
int err = NOERR;
|
|
|
|
TRecord_text curr;
|
|
|
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
|
|
|
{
|
|
|
|
pi.setstatus(_trasfile->read_file()->tellg());
|
|
|
|
if (curr.type() == "06")
|
|
|
|
{
|
|
|
|
TString16 paiv = curr.get(11);
|
|
|
|
TString80 cofi = curr.get(12);
|
|
|
|
TString16 statopaiv = " ";
|
|
|
|
TString80 ragsoc = curr.get(4);
|
|
|
|
ragsoc << curr.get(5);
|
|
|
|
if (!cofi.blank())
|
|
|
|
{
|
|
|
|
rel.lfile().setkey(4);
|
|
|
|
reccli.zero();
|
2006-07-11 13:10:51 +00:00
|
|
|
reccli.put(CLI_TIPOCF, tipocf);
|
2005-06-10 12:55:53 +00:00
|
|
|
reccli.put(CLI_COFI, cofi);
|
|
|
|
if (reccli.read(rel.lfile())!=NOERR)
|
|
|
|
{
|
|
|
|
reccli.zero();
|
2006-07-11 13:10:51 +00:00
|
|
|
const long codcf = get_nextcodcf(tipocf);
|
|
|
|
reccli.put(CLI_TIPOCF, tipocf);
|
2005-06-10 12:55:53 +00:00
|
|
|
reccli.put(CLI_CODCF, codcf);
|
|
|
|
reccli.put(CLI_RAGSOC, ragsoc);
|
|
|
|
err = reccli.write(rel.lfile());
|
|
|
|
if (err != NOERR)
|
2006-07-11 13:10:51 +00:00
|
|
|
message_box(TR("Errore in scrittura clienti/fornitori %d"), err);
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!paiv.blank())
|
|
|
|
{
|
|
|
|
rel.lfile().setkey(5);
|
|
|
|
reccli.zero();
|
2006-07-11 13:10:51 +00:00
|
|
|
reccli.put(CLI_TIPOCF, tipocf);
|
2005-06-10 12:55:53 +00:00
|
|
|
reccli.put(CLI_STATOPAIV, statopaiv);
|
|
|
|
reccli.put(CLI_PAIV, paiv);
|
|
|
|
if (reccli.read(rel.lfile())!=NOERR)
|
|
|
|
{
|
|
|
|
reccli.zero();
|
2006-07-11 13:10:51 +00:00
|
|
|
const long codcf = get_nextcodcf(tipocf);
|
|
|
|
reccli.put(CLI_TIPOCF, tipocf);
|
2005-06-10 12:55:53 +00:00
|
|
|
reccli.put(CLI_CODCF, codcf);
|
|
|
|
reccli.put(CLI_RAGSOC, ragsoc);
|
|
|
|
err = reccli.write(rel.lfile());
|
|
|
|
if (err != NOERR)
|
2006-07-11 13:10:51 +00:00
|
|
|
message_box(TR("Errore in scrittura clienti/fornitori %d"), err);
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_trasfile->autosave(rel, curr);
|
|
|
|
TString80 str;
|
|
|
|
// comune
|
|
|
|
TString80 dencom = curr.get(9);
|
|
|
|
dencom.trim();
|
|
|
|
dencom.upper();
|
|
|
|
TRectype reccom = cache_comuni.get(dencom);
|
|
|
|
str = reccom.get(COM_DENCOM);
|
|
|
|
str.trim();
|
|
|
|
if (str == dencom)
|
|
|
|
reccli.put(CLI_COMCF, reccom.get(COM_COM));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reccli.put(CLI_COMCF, " ");
|
|
|
|
reccli.put(CLI_LOCCF, dencom);
|
|
|
|
stampa = "Cliente ";
|
|
|
|
stampa << reccli.get(CLI_CODCF);
|
|
|
|
stampa << " - comune " << dencom << " non trovato";
|
|
|
|
print_line(stampa);
|
|
|
|
}
|
|
|
|
rel.rewrite();
|
|
|
|
// aggiungo il cliente all'array per ritrovarlo sui documenti
|
2006-07-11 13:10:51 +00:00
|
|
|
const TString16 codcf = rel.curr().get(CLI_CODCF);
|
|
|
|
const TString16 codcfdt = curr.get(3);
|
|
|
|
if (!_array_clifor->is_key(codcfdt))
|
|
|
|
_array_clifor->add(codcfdt, codcf);
|
2005-06-10 12:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_trasfile->close();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dt0400(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TDT2Doc main_app;
|
|
|
|
main_app.run(argc, argv, TR("Importazione documenti"));
|
|
|
|
return TRUE;
|
|
|
|
}
|