b3eb695ca4
Files correlati : Ricompilazione Demo : [ ] Commento :aggiornato modulo DT (store) git-svn-id: svn://10.65.10.50/trunk@13357 c028cbd2-c16b-5b4b-a496-9718f37d4682
740 lines
20 KiB
C++
Executable File
740 lines
20 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <config.h>
|
|
#include <currency.h>
|
|
#include <execp.h>
|
|
#include <filetext.h>
|
|
#include <progind.h>
|
|
#include <printer.h>
|
|
#include <recarray.h>
|
|
#include <strings.h>
|
|
#include <utility.h>
|
|
|
|
#include "dt0.h"
|
|
#include "dt0400a.h"
|
|
|
|
#include "clifo.h"
|
|
#include "comuni.h"
|
|
#include "doc.h"
|
|
#include "rdoc.h"
|
|
|
|
#include "..\cg\cglib01.h"
|
|
|
|
// 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:
|
|
TDT2Doc_file(const TString& file_name);
|
|
virtual ~TDT2Doc_file() { }
|
|
};
|
|
|
|
TDT2Doc_file::TDT2Doc_file(const TString& file_name)
|
|
: TFile_text(file_name, "dt0400a.ini")
|
|
{
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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());
|
|
//strcpy(fs.creator, "ba1");
|
|
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;
|
|
}
|
|
|
|
|
|
// TSkeleton_application
|
|
|
|
class TDT2Doc : public TSkeleton_application
|
|
{
|
|
TDT2Doc_mask* _msk;
|
|
TDT2Doc_file* _trasfile;
|
|
TLocalisamfile* _clienti;
|
|
TRelation* _rel;
|
|
TCursor* _cur;
|
|
TProgind* _prog;
|
|
TAssoc_array* _array_clienti;
|
|
TAssoc_array* _confditte;
|
|
TAssoc_array* _confdoc;
|
|
TAssoc_array* _totalilordi;
|
|
TAssoc_array* _castelletto;
|
|
TAssoc_array* _primariga;
|
|
TString80 _cms, _condpag, _codnum, _negozio;
|
|
bool _contnetto;
|
|
|
|
|
|
public:
|
|
bool print_header(const TString80& percorso);
|
|
void print_line(const TString& rigastampa = "");
|
|
void print_footer();
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
bool import_clienti(const TString80& percorso);
|
|
bool import_documenti(const TString80& percorso);
|
|
const long get_nextcodcf();
|
|
bool load_conf_ditte();
|
|
bool load_conf_doc();
|
|
bool check_negozio(const TString80& percorso);
|
|
bool TDT2Doc::error_msg(const TString& msg, const TString16& causale, const int numdoc, const TString& codice);
|
|
TDT2Doc() {}
|
|
};
|
|
|
|
TDT2Doc& app() { return (TDT2Doc&) main_app(); }
|
|
|
|
bool TDT2Doc::print_header(const TString80& percorso)
|
|
{
|
|
if (printer().open())
|
|
{
|
|
TDate oggi(TODAY);
|
|
TPrintrow row;
|
|
TString256 rigastampa;
|
|
rigastampa = "IMPORTAZIONE FILE ";
|
|
rigastampa << percorso;
|
|
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
|
|
return error_box("Errore in apertura stampante.");
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
bool TDT2Doc::check_negozio(const TString80& percorso)
|
|
{
|
|
TConfig config_studio = TConfig(CONFIG_STUDIO, "dt");
|
|
int inizio = percorso.find("DF");
|
|
inizio+=2;
|
|
const int fine = percorso.find('.');
|
|
_negozio = percorso.mid(inizio, fine);
|
|
_negozio.trim();
|
|
if (_confditte->is_key(_negozio))
|
|
{
|
|
TToken_string& config = (TToken_string&) _confditte->find(_negozio);
|
|
TString16 dittastr = config.get();
|
|
_cms = config.get();
|
|
_codnum = config.get();
|
|
if (_codnum.empty())
|
|
return error_box("Attenzione: manca la numerazione corrispondente al negozio. Completare la tabella prima di effettuare il trasferimento");
|
|
const long ditta = atol(dittastr);
|
|
if (prefix().exist(ditta))
|
|
{
|
|
load_conf_doc();
|
|
return set_firm(ditta);
|
|
}
|
|
else
|
|
return error_box("Attenzione: non esiste la ditta %ld; trasferimento annullato", ditta);
|
|
}
|
|
else
|
|
return error_box("Attenzione: manca la corrispondenza negozio - ditta; trasferimento annullato");
|
|
}
|
|
|
|
bool TDT2Doc::load_conf_ditte()
|
|
{
|
|
TConfig config_studio = TConfig(CONFIG_STUDIO, "dt");
|
|
TToken_string workstring;
|
|
_confditte->destroy();
|
|
for (int k = 0; config_studio.exist("ConfDitte", k); k++)
|
|
{
|
|
workstring= config_studio.get("ConfDitte", NULL, k);
|
|
const TString16 negozio = workstring.get(0);
|
|
const TString16 ditta = workstring.get(1);
|
|
const TString80 cms = workstring.get(2);
|
|
const TString16 codnum = workstring.get(3);
|
|
TToken_string config;
|
|
config.add(ditta);
|
|
config.add(cms);
|
|
config.add(codnum);
|
|
_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");
|
|
return TRUE;
|
|
}
|
|
|
|
bool TDT2Doc::create()
|
|
{
|
|
open_files(LF_CLIFO, 0);
|
|
_msk = new TDT2Doc_mask();
|
|
_msk->set_handler(F_PERCORSO, browse_file_handler);
|
|
_cms = " ";
|
|
_condpag = " ";
|
|
_clienti = new TLocalisamfile(LF_CLIFO);
|
|
// array delle corrispondenze tra codici clienti
|
|
_array_clienti = new TAssoc_array();
|
|
// 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 ();
|
|
}
|
|
|
|
bool TDT2Doc::destroy()
|
|
{
|
|
delete _primariga;
|
|
delete _castelletto;
|
|
delete _totalilordi;
|
|
delete _confdoc;
|
|
delete _confditte;
|
|
delete _array_clienti;
|
|
delete _clienti;
|
|
delete _msk;
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
void TDT2Doc::main_loop()
|
|
{
|
|
TString80 percorso;
|
|
KEY tasto;
|
|
TConfig configfile("dt0400.ini");
|
|
_msk->set(F_PERCORSO, configfile.get("PERCORSO", "OPZIONI"));
|
|
tasto = _msk->run();
|
|
if (tasto == K_ENTER)
|
|
{
|
|
percorso = _msk->get(F_PERCORSO);
|
|
if (check_negozio(percorso))
|
|
{
|
|
if (print_header(percorso))
|
|
{
|
|
_trasfile = new TDT2Doc_file(percorso);
|
|
import_clienti(percorso);
|
|
import_documenti(percorso);
|
|
configfile.set("PERCORSO", percorso, "OPZIONI");
|
|
delete _trasfile;
|
|
message_box(TR("Importazione documenti completata"));
|
|
print_footer();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const long TDT2Doc::get_nextcodcf()
|
|
{
|
|
TLocalisamfile& clifo = *_clienti;
|
|
long codcf = 1L ;
|
|
if (!clifo.empty())
|
|
{
|
|
clifo.zero() ;
|
|
clifo.setkey(1) ;
|
|
clifo.put(CLI_TIPOCF, 'F');
|
|
clifo.read(_isgteq) ;
|
|
if (clifo.good())
|
|
clifo.prev() ;
|
|
clifo.setstatus(NOERR);
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
return codcf;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
bool TDT2Doc::import_documenti(const TString80& percorso)
|
|
{
|
|
// eliminazione files delle elaborazioni precedenti
|
|
TString_array transactions;
|
|
list_files("ditet*.ini", transactions);
|
|
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
|
remove(*name);
|
|
// lettura file
|
|
_trasfile->open(percorso, 'r');
|
|
const long dimension = fsize(percorso);
|
|
TProgind pi(dimension,"Importazione in corso...");
|
|
TConfig* docum=NULL;
|
|
TString256 stampa;
|
|
real* tl;
|
|
int err = NOERR;
|
|
int ntransac=0;
|
|
int nriga=0;
|
|
bool error = FALSE;
|
|
real sconto(ZERO);
|
|
real importodoc(ZERO);
|
|
real percsconto(ZERO);
|
|
int numdoc;
|
|
TString16 causale;
|
|
TRecord_text curr;
|
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
|
{
|
|
pi.setstatus(_trasfile->read_file()->tellg());
|
|
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)
|
|
{
|
|
TGeneric_distrib d(sconto, TCurrency::get_firm_dec(true));
|
|
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();
|
|
TString16 codiva = _totalilordi->get_hashobj()->key();
|
|
TCodiceIVA codiceIVA(codiva);
|
|
codiceIVA.scorpora(sconto, TCurrency::get_firm_dec(true));
|
|
real& imp_calcolato = *tl;
|
|
real& imp_castelletto = (real&) _castelletto->find(codiva);
|
|
codiceIVA.scorpora(imp_calcolato, TCurrency::get_firm_dec(true));
|
|
real diff = imp_calcolato-sconto-imp_castelletto;
|
|
sconto = 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");
|
|
TString16 str = sconto.string(TCurrency::get_firm_dec(true));
|
|
docum->set(RDOC_PREZZO, str);
|
|
docum->set(RDOC_CODIVA, codiva);
|
|
docum->set(RDOC_CODCMS, _cms);
|
|
totsconti+=sconto;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (tl = (real*) _totalilordi->first_item(); tl != NULL; tl = (real*) _totalilordi->succ_item())
|
|
{
|
|
TString16 codiva = _totalilordi->get_hashobj()->key();
|
|
TCodiceIVA codiceIVA(codiva);
|
|
real& imp_calcolato = *tl;
|
|
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");
|
|
TString16 str = diff.string(TCurrency::get_firm_dec());
|
|
docum->set(RDOC_PREZZO, str);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 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
|
|
{
|
|
TFilename file = format("ditet%03d.ini",ntransac);
|
|
if (file.exist())
|
|
remove(file);
|
|
}
|
|
error = FALSE;
|
|
if (curr.type() == "01")
|
|
{
|
|
ntransac++;
|
|
docum = new TConfig(format("ditet%03d.ini",ntransac));
|
|
sconto = ZERO;
|
|
numdoc = atoi(curr.get(3));
|
|
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())
|
|
{
|
|
TString16 codclidt;
|
|
codclidt = curr.get(5);
|
|
if (_array_clienti->is_key(codclidt))
|
|
{
|
|
TString& codcli = (TString&) _array_clienti->find(codclidt);
|
|
//ntransac++;
|
|
nriga=0;
|
|
//docum = new TConfig(format("ditet%03d.ini",ntransac));
|
|
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);
|
|
docum->set(DOC_NDOC, numdoc);
|
|
docum->set(DOC_DATADOC, datadoc);
|
|
docum->set(DOC_TIPOCF, "C");
|
|
docum->set(DOC_CODCF, codcli);
|
|
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);
|
|
}
|
|
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);
|
|
}
|
|
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;
|
|
}
|
|
else if ((!error) && (curr.type() == "04" || curr.type() == "05")) // righe documento
|
|
{
|
|
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);
|
|
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);
|
|
}
|
|
}
|
|
_trasfile->close();
|
|
// chiudo l'ultimo file
|
|
if (docum != NULL)
|
|
delete docum;
|
|
if (error) // cancello il file perch'e la transazione non e' andata bene
|
|
{
|
|
TFilename file = format("ditet%03d.ini",ntransac);
|
|
if (file.exist())
|
|
remove(file);
|
|
}
|
|
TExternal_app gestdoc("ve0.exe -1 -iditet*.ini ");
|
|
gestdoc.run();
|
|
return TRUE;
|
|
}
|
|
|
|
bool TDT2Doc::import_clienti(const TString80& percorso)
|
|
{
|
|
// cache per i comuni
|
|
TRecord_cache cache_comuni(LF_COMUNI, 2);
|
|
_trasfile->open('r');
|
|
const long dimension = fsize(percorso);
|
|
TProgind pi(dimension,"Importazione in corso...");
|
|
TRelation rel(LF_CLIFO);
|
|
TRectype& reccli = rel.curr();
|
|
TLocalisamfile& clifo = rel.lfile();
|
|
_array_clienti->destroy();
|
|
TString256 stampa;
|
|
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();
|
|
reccli.put(CLI_TIPOCF, 'C');
|
|
reccli.put(CLI_COFI, cofi);
|
|
if (reccli.read(rel.lfile())!=NOERR)
|
|
{
|
|
reccli.zero();
|
|
const long codcf = get_nextcodcf();
|
|
reccli.put(CLI_TIPOCF, 'C');
|
|
reccli.put(CLI_CODCF, codcf);
|
|
reccli.put(CLI_RAGSOC, ragsoc);
|
|
err = reccli.write(rel.lfile());
|
|
if (err != NOERR)
|
|
message_box("Errore in scrittura clienti %d", err);
|
|
}
|
|
}
|
|
else if (!paiv.blank())
|
|
{
|
|
rel.lfile().setkey(5);
|
|
reccli.zero();
|
|
reccli.put(CLI_TIPOCF, 'C');
|
|
reccli.put(CLI_STATOPAIV, statopaiv);
|
|
reccli.put(CLI_PAIV, paiv);
|
|
if (reccli.read(rel.lfile())!=NOERR)
|
|
{
|
|
reccli.zero();
|
|
const long codcf = get_nextcodcf();
|
|
reccli.put(CLI_TIPOCF, 'C');
|
|
reccli.put(CLI_CODCF, codcf);
|
|
reccli.put(CLI_RAGSOC, ragsoc);
|
|
err = reccli.write(rel.lfile());
|
|
if (err != NOERR)
|
|
message_box("Errore in scrittura clienti %d", err);
|
|
}
|
|
}
|
|
_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
|
|
const TString16 codcli = rel.curr().get(CLI_CODCF);
|
|
const TString16 codclidt = curr.get(3);
|
|
if (!_array_clienti->is_key(codclidt))
|
|
_array_clienti->add(codclidt, codcli);
|
|
}
|
|
}
|
|
_trasfile->close();
|
|
return TRUE;
|
|
}
|
|
|
|
int dt0400(int argc, char* argv[])
|
|
{
|
|
TDT2Doc main_app;
|
|
main_app.run(argc, argv, TR("Importazione documenti"));
|
|
return TRUE;
|
|
}
|
|
|