3554aed558
Files correlati : cg0.EXE Ricompilazione Demo : [ ] Commento : MOdificati i controlli sulla mancanza di partita IVA e Codice Fiscale dei Clienti/ Fornitori vengono ora effettuati in fase di registrazione git-svn-id: svn://10.65.10.50/trunk@18058 c028cbd2-c16b-5b4b-a496-9718f37d4682
1019 lines
27 KiB
C++
Executable File
1019 lines
27 KiB
C++
Executable File
#include "cg0.h"
|
|
#include "cg0200.h"
|
|
#include "cg0201.h"
|
|
|
|
#include <defmask.h>
|
|
#include <execp.h>
|
|
#include <golem.h>
|
|
#include <modaut.h>
|
|
#include <msksheet.h>
|
|
#include <recarray.h>
|
|
#include <relapp.h>
|
|
#include <utility.h>
|
|
|
|
#include <anagr.h>
|
|
#include <anafis.h>
|
|
#include <anagiu.h>
|
|
#include <cfven.h>
|
|
#include <clifo.h>
|
|
#include <comuni.h>
|
|
#include <indsp.h>
|
|
#include <mov.h>
|
|
|
|
class TClifo_application : public TRelation_application
|
|
{
|
|
TMask* _msk;
|
|
TClifoVI* _rel;
|
|
|
|
bool _lbcn, _gesven, _gessal, _has_cg, _liscatven;
|
|
bool _savenew;
|
|
|
|
TToken_string _tmp;
|
|
|
|
protected:
|
|
bool user_create();
|
|
bool user_destroy();
|
|
virtual TMask* get_mask(int mode) { return _msk; }
|
|
virtual bool changing_mask(int mode) { return false; }
|
|
virtual bool save_and_new() const { return _savenew; }
|
|
virtual bool protected_record(TRectype &rec);
|
|
virtual bool get_next_key(TToken_string& key);
|
|
void init_pages(TMask& m);
|
|
virtual void init_query_mode(TMask& m);
|
|
virtual void init_query_insert_mode(TMask& m);
|
|
virtual void init_insert_mode(TMask& m);
|
|
virtual void init_modify_mode(TMask& m);
|
|
virtual void on_config_change();
|
|
|
|
////////////
|
|
static bool indsp_notify(TSheet_field& s, int r, KEY key);
|
|
static void indsp_sheet_rebuilder();
|
|
static bool effetti_notify(TSheet_field& s, int r, KEY key);
|
|
|
|
void set_pnae(TMask& m, TToken_string& nonacc, TToken_string& nonscd);
|
|
void get_pnae(const TMask& m, TToken_string& nonacceff, TToken_string& nonscadeff);
|
|
|
|
virtual int write(const TMask& m);
|
|
virtual int rewrite(const TMask& m);
|
|
virtual int read(TMask& m);
|
|
|
|
virtual void ini2mask(TConfig& ini, TMask&m, bool query);
|
|
virtual void mask2ini(const TMask& m, TConfig& ini);
|
|
|
|
TSheet_field& indsp_sheet() const;
|
|
TString_array& field_sheet(short id) const;
|
|
void reset_sheet();
|
|
void indsp_pack();
|
|
void common_f(const TMask& m);
|
|
|
|
static bool tipocf_handler(TMask_field& f, KEY key);
|
|
static bool tipo_handler(TMask_field& f, KEY key);
|
|
static bool crea_percipienti(TMask_field& f, KEY key);
|
|
static bool percip_handler(TMask_field& f, KEY key);
|
|
static bool email_handler(TMask_field& f, KEY k);
|
|
static bool rsoc_handler(TMask_field& f, KEY k);
|
|
virtual bool has_filtered_cursor() const { return true;}
|
|
|
|
public:
|
|
// @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata
|
|
virtual bool check_autorization() const
|
|
{return false;}
|
|
virtual TRelation* get_relation() const {return (TRelation*)_rel;}
|
|
};
|
|
|
|
inline TClifo_application& app() { return (TClifo_application&)main_app(); }
|
|
|
|
bool TClifo_application::protected_record(TRectype &rec)
|
|
{
|
|
if (!_has_cg)
|
|
return false;
|
|
|
|
const TMask& m = *get_mask(MODE_MOD);
|
|
const char tipocf = m.get(F_TIPOCF)[0];
|
|
const long codice = m.get_long(F_CODCF);
|
|
|
|
TLocalisamfile mov(LF_MOV); mov.setkey(3);
|
|
TRectype& head = mov.curr();
|
|
head.put(MOV_TIPO, tipocf);
|
|
head.put(MOV_CODCF, codice);
|
|
const int err = mov.read(_isgteq);
|
|
return err == NOERR && tipocf == head.get_char(MOV_TIPO)
|
|
&& codice == head.get_long(MOV_CODCF);
|
|
}
|
|
|
|
bool TClifo_application::get_next_key(TToken_string& key)
|
|
{
|
|
TLocalisamfile& clifo = _rel->lfile();
|
|
long codcf = 1L;
|
|
const TString& tipo = _msk->get(F_TIPOCF);
|
|
|
|
if (!clifo.empty())
|
|
{
|
|
clifo.zero() ;
|
|
clifo.setkey(1) ;
|
|
if ( tipo == TCLI )
|
|
{
|
|
clifo.put(CLI_TIPOCF, (const char* ) TFOR);
|
|
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 == tipo )
|
|
codcf += clifo.get_long(CLI_CODCF);
|
|
}
|
|
}
|
|
key.format("%d|%s|%d|%ld", F_TIPOCF, (const char*) tipo, F_CODCF, codcf);
|
|
return true;
|
|
}
|
|
|
|
HIDDEN bool no_dup_fis(TMask_field& f, KEY key)
|
|
{
|
|
bool ok = true;
|
|
|
|
TMask& msk = f.mask() ;
|
|
if (msk.query_mode() || !f.to_check(key))
|
|
return ok;
|
|
|
|
TLocalisamfile& clifo = app().get_relation()->lfile(LF_CLIFO);
|
|
if (!f.empty() && !clifo.empty())
|
|
{
|
|
clifo.zero() ;
|
|
const char t1 = msk.get(F_TIPOCF)[0] ;
|
|
|
|
clifo.put(CLI_TIPOCF, t1);
|
|
clifo.put(CLI_COFI, f.get());
|
|
clifo.setkey(4) ;
|
|
clifo.read() ;
|
|
clifo.setkey(1) ;
|
|
const char t = clifo.get_char(CLI_TIPOCF);
|
|
const long s = clifo.get_long(CLI_CODCF);
|
|
const long s1 = msk.get_long(F_CODCF);
|
|
|
|
if (clifo.good() && (t1 != t || s1 != s))
|
|
{
|
|
f.message_box(FR("Codice fiscale gia' utilizzato per il codice %c/%ld"),
|
|
t, s);
|
|
}
|
|
}
|
|
|
|
return ok ;
|
|
}
|
|
|
|
HIDDEN bool no_dup_iva(TMask_field& f, KEY key)
|
|
{
|
|
bool ok = true;
|
|
|
|
TMask& msk = f.mask() ;
|
|
if (msk.query_mode() || !f.to_check(key))
|
|
return ok;
|
|
|
|
if (!f.empty())
|
|
{
|
|
TLocalisamfile clifo(LF_CLIFO) ;
|
|
clifo.put(CLI_TIPOCF, msk.get(F_TIPOCF)) ;
|
|
clifo.put(CLI_STATOPAIV, msk.get(F_STATOPAIV)) ;
|
|
clifo.put(CLI_PAIV, f.get()) ;
|
|
clifo.setkey(5) ;
|
|
const int err = clifo.read() ;
|
|
if (err == NOERR)
|
|
{
|
|
const long s = clifo.get_long(CLI_CODCF);
|
|
const long s1 = msk.get_long(F_CODCF);
|
|
if (s1 != s)
|
|
ok = f.error_box(FR("Partita IVA gia' utilizzata per il codice %ld"
|
|
"\nsenza avere indicato il valore 4 nell'inserimento in allegato"), s);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
// Controlla la presenza di Codice Fiscale e/o Partita IVA
|
|
HIDDEN bool almeno_cf_o_pi(TMask_field& f)
|
|
{
|
|
bool ok = true;
|
|
if (f.empty())
|
|
{
|
|
const TMask& m = f.mask();
|
|
const TString& stato = m.get(F_STATOPAIV);
|
|
if (stato.blank() || stato == "IT") // Se sono un italiano ...
|
|
{
|
|
const bool occas = m.get_bool(F_OCCASIONALE);
|
|
const int alleg = m.get_int(F_ALLEG);
|
|
if (!occas && (alleg == 0 || alleg == 6)) // ... e non sono occasionale
|
|
{
|
|
const TEdit_field& cofi = m.efield(F_COFI);
|
|
if (cofi.empty()) // Dal 2007 serve il codice fiscale
|
|
ok = cofi.error_box(TR("Codice fiscale obbligatorio per residenti in Italia"));
|
|
else
|
|
{
|
|
// Se NON sono privato (alleg!=6), serve partita IVA
|
|
const TEdit_field& paiv = m.efield(F_PAIV);
|
|
if (alleg != 6 && paiv.empty())
|
|
ok = paiv.error_box(TR("E' necessario specificare la partita IVA per i non privati"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
HIDDEN bool cofi_handler(TMask_field& f, KEY key)
|
|
{
|
|
bool ok = true;
|
|
|
|
TMask& m = f.mask();
|
|
if (key == K_ENTER && !f.dirty() && !m.query_mode())
|
|
ok = ((TEdit_field&)f).validate(key);
|
|
|
|
if (ok && f.to_check(key))
|
|
{
|
|
if (key == K_TAB)
|
|
{
|
|
const TString& s1 = f.get();
|
|
if (s1.full())
|
|
m.set(F_TIPOPERS, isdigit(s1[0]) ? "G" : "F");
|
|
}
|
|
const int alleg = m.get_int(F_ALLEG);
|
|
if (!m.query_mode() && key == K_ENTER && alleg != 4)
|
|
{
|
|
ok = no_dup_fis(f, key);
|
|
if (ok)
|
|
ok = almeno_cf_o_pi(f);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
HIDDEN bool paiv_handler(TMask_field& f, KEY key)
|
|
{
|
|
bool ok = true;
|
|
const TMask& m = f.mask();
|
|
|
|
if (key == K_ENTER && !m.query_mode())
|
|
{
|
|
if (!f.dirty())
|
|
ok = ((TEdit_field&)f).validate(key);
|
|
|
|
if (ok)
|
|
{
|
|
const int alleg = m.get_int(F_ALLEG);
|
|
if (alleg != 4)
|
|
{
|
|
ok = no_dup_iva(f, key);
|
|
if (ok)
|
|
ok = almeno_cf_o_pi(f);
|
|
}
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TClifo_application::tipocf_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
app().update_navigation_bar();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::tipo_handler(TMask_field& f, KEY key)
|
|
{
|
|
TMask& m = f.mask();
|
|
const bool fis = f.get() == "F";
|
|
m.show(-5, fis);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::crea_percipienti(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
TLocalisamfile anag(LF_ANAG);
|
|
TToken_string k;
|
|
long percip = m.get_long(F_CODANAGPER);
|
|
const char tipo = m.get(F_TIPOAPER)[0];
|
|
|
|
if (percip == 0)
|
|
{
|
|
percip = m.get_long(F_CODCF);
|
|
k.add(tipo);
|
|
k.add(percip);
|
|
const TRectype & rec = cache().get(LF_ANAG, k);
|
|
|
|
if (!rec.empty())
|
|
return error_box("Esiste gia' una anagrafica con codice uguale del fornitore");
|
|
m.set(F_CODANAGPER, percip);
|
|
}
|
|
else
|
|
{
|
|
k.add(m.get(F_TIPOAPER));
|
|
k.add(percip);
|
|
const TRectype & rec = cache().get(LF_ANAG, k);
|
|
if (!rec.empty())
|
|
return true;
|
|
}
|
|
|
|
anag.put(ANA_TIPOA, tipo);
|
|
anag.put(ANA_CODANAGR, percip);
|
|
anag.put(ANA_COFI, m.get(F_COFI));
|
|
anag.put(ANA_PAIV, m.get(F_PAIV));
|
|
TString80 ragsoc(m.get(F_RAGSOC));
|
|
|
|
ragsoc.rpad(30);
|
|
ragsoc << m.get(F_RAGSOCA);
|
|
anag.put(ANA_RAGSOC, ragsoc);
|
|
anag.put(ANA_STATORES, m.get(F_STATOCF));
|
|
anag.put(ANA_COMRES, m.get(F_COMCF));
|
|
anag.put(ANA_INDRES, m.get(F_INDCF));
|
|
anag.put(ANA_CIVRES, m.get(F_CIVCF));
|
|
anag.put(ANA_CAPRES, m.get(F_CAPCF));
|
|
|
|
int err = anag.write();
|
|
|
|
if (err == NOERR)
|
|
{
|
|
if (tipo == 'F')
|
|
{
|
|
TLocalisamfile anafis(LF_ANAGFIS);
|
|
|
|
anafis.put(ANF_CODANAGR, percip);
|
|
anafis.put(ANF_DATANASC, m.get(F_DATANASC));
|
|
anafis.put(ANF_SESSO, atoi(m.get(F_COFI).mid(9, 2)) > 31 ? 'F' : 'M');
|
|
anafis.put(ANF_COMNASC, m.get(F_COMNASC));
|
|
err = anafis.write();
|
|
if (err != NOERR)
|
|
return message_box("Scrittura anagrafica persona fisica Errore %d", err);
|
|
}
|
|
else
|
|
{
|
|
TLocalisamfile anagiu(LF_ANAGGIU);
|
|
|
|
anagiu.put(ANG_CODANAGR, percip);
|
|
|
|
err = anagiu.write();
|
|
if (err != NOERR)
|
|
return message_box("Scrittura anagrafica persona fisica Errore %d", err);
|
|
}
|
|
}
|
|
else
|
|
return message_box("Scrittura anagrafica Errore %d", err);
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::percip_handler(TMask_field& f, KEY key)
|
|
{
|
|
TMask& m = f.mask();
|
|
|
|
if (f.to_check(key) && !m.field(F_CODANAGPER).empty())
|
|
{
|
|
long percip = m.get_long(F_CODANAGPER);
|
|
const char tipo = m.get(F_TIPOAPER)[0];
|
|
TToken_string k;
|
|
|
|
k.add(tipo);
|
|
k.add(percip);
|
|
const TRectype & anag = cache().get(LF_ANAG, k);
|
|
const TString& c = m.get(F_COFI), p = m.get(F_PAIV);
|
|
|
|
if (key == K_TAB && anag.empty())
|
|
return true;
|
|
|
|
if ((c.full() && c != anag.get(ANA_COFI)) ||
|
|
(p.full() && p != anag.get(ANA_PAIV)))
|
|
return error_box(TR("Percipiente non corretto: codice fiscale o partita IVA diversa"));
|
|
|
|
const TString& r = anag.get(ANA_RAGSOC);
|
|
if (key == K_TAB && m.field(F_RAGSOC).empty() &&
|
|
yesno_box(FR("Ragione sociale mancante: assumo %s"), (const char*)r))
|
|
{
|
|
m.set(F_RAGSOC, r.left(30), true);
|
|
m.set(F_RAGSOCA, r.mid(30), true);
|
|
}
|
|
|
|
if (m.get(F_INDCF).empty()) m.set(F_INDCF, anag.get(ANA_INDRES));
|
|
if (m.get(F_CIVCF).empty()) m.set(F_CIVCF, anag.get(ANA_CIVRES));
|
|
if (m.get(F_CAPCF).empty()) m.set(F_CAPCF, anag.get(ANA_CAPRES));
|
|
if (m.get(F_COMCF).empty())
|
|
{
|
|
m.set(F_STATOCF, anag.get(ANA_STATORES), true);
|
|
m.set(F_COMCF, anag.get(ANA_COMRES), true);
|
|
}
|
|
if (c.empty()) m.set(F_COFI, anag.get(ANA_COFI));
|
|
if (p.empty()) m.set(F_PAIV, anag.get(ANA_PAIV));
|
|
if (m.get(F_TIPOAPER) == "F")
|
|
{
|
|
const TRectype & fis = cache().get(LF_ANAGFIS, anag.get(ANA_CODANAGR));
|
|
|
|
if (!fis.empty())
|
|
{
|
|
if (m.get(F_DATANASC).empty()) m.set(F_DATANASC, fis.get(ANF_DATANASC));
|
|
if (m.get(F_COMNASC).empty())
|
|
m.set(F_COMNASC, fis.get(ANF_COMNASC), true);
|
|
m.set(F_SESSO, fis.get(ANF_SESSO));
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::email_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TMail_message msg(f.mask().get(F_MAIL));
|
|
msg.send();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::rsoc_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.focusdirty())
|
|
{
|
|
TMask& m = f.mask();
|
|
if (m.query_mode() && m.key_valid(2) && app().find(2))
|
|
{
|
|
f.set_focusdirty(false);
|
|
m.stop_run(K_AUTO_ENTER);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
HIDDEN bool alleg_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (f.to_check(key, true))
|
|
{
|
|
TMask& m = f.mask();
|
|
const int tipoall = atoi(f.get());
|
|
|
|
if (key == K_ENTER)
|
|
{
|
|
if (m.get_bool(F_OCCASIONALE))
|
|
{
|
|
if (tipoall != 2 && tipoall != 5 && tipoall != 6)
|
|
return f.error_box(TR("Tipo allegato non valido per gli occasionali"));
|
|
}
|
|
else
|
|
{
|
|
if (tipoall == 2)
|
|
return f.error_box(TR("Tipo allegato non valido per i non occasionali"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m.field(F_COMCF).check_type(tipoall == 6 ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
if (tipoall == 0 || tipoall == 1 || tipoall == 4 || tipoall == 6)
|
|
m.enable(F_CODALLEG);
|
|
else
|
|
{
|
|
m.disable(F_CODALLEG);
|
|
m.reset(F_CODALLEG);
|
|
}
|
|
if (tipoall == 2)
|
|
m.set(F_OCCASIONALE, "X");
|
|
m.field(F_COFI).set_dirty(true);
|
|
m.field(F_PAIV).set_dirty(true);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
HIDDEN bool codalleg_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (f.to_check(key) && !f.empty())
|
|
{
|
|
TMask& m = f.mask();
|
|
const TString& cod = f.get();
|
|
if (cod == m.get(F_CODCF))
|
|
return error_box(TR("Il codice per allegato coincide con il codice anagrafico"));
|
|
|
|
const char tipo = m.get(F_TIPOCF)[0];
|
|
|
|
TString8 key; key.format("%c|%s", tipo, (const char*)cod);
|
|
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
|
if (clifo.empty())
|
|
return false;
|
|
|
|
if (clifo.get(CLI_CODALLEG).full())
|
|
return error_box(TR("Codice non utilizzabile: contiene a sua volta un codice per allegato"));
|
|
|
|
if (clifo.get(CLI_PAIV).blank() && clifo.get(CLI_COFI).blank())
|
|
return error_box(TR("Codice non utilizzabile: partita IVA e codice fiscale non specificati"));
|
|
|
|
const int tipoall = clifo.get_int(CLI_ALLEG);
|
|
if (tipoall != 0 && tipoall != 1 && tipoall != 4 && tipoall != 6)
|
|
return error_box(TR("Codice non utilizzabile: codice inserimento allegato non corretto"));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
HIDDEN bool contrlav_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_SPACE)
|
|
{
|
|
TFilename tempfile;
|
|
|
|
tempfile.temp("cg0");
|
|
tempfile.ext("ini");
|
|
|
|
{
|
|
TConfig configfile(tempfile);
|
|
TString8 para;
|
|
|
|
para << LF_LVCONDV;
|
|
configfile.set("Action", "Run", "Transaction");
|
|
configfile.set("Mode", "R", "Transaction");
|
|
configfile.set(CLI_CODCF, f.mask().get(F_CODCF), para);
|
|
}
|
|
|
|
TString commandline;
|
|
|
|
commandline.format("lv0 -3 /i%s",(const char*)tempfile);
|
|
|
|
TExternal_app lv(commandline);
|
|
lv.run();
|
|
|
|
remove_file(tempfile);
|
|
}
|
|
return true;
|
|
}
|
|
void TClifo_application::on_config_change()
|
|
{
|
|
TConfig cnf(CONFIG_DITTA);
|
|
_gesven = cnf.get_bool("GesVen") || !_has_cg;
|
|
_gessal = cnf.get_bool("GesSal") || !_has_cg;
|
|
_lbcn = cnf.get_bool("GsLbCn");
|
|
_liscatven = cnf.get_bool("GESLISCV", "ve");
|
|
|
|
init_pages(*_msk);
|
|
_msk->show(-9, _gessal); // Mostra campi Estratti conto
|
|
_msk->enable(DLG_CONTRLAV, main_app().has_module(LVAUT));
|
|
}
|
|
|
|
|
|
void TClifo_application::init_pages(TMask& m)
|
|
{
|
|
_rel->gestione_vendite(_gesven);
|
|
|
|
m.show(-5, _lbcn);
|
|
}
|
|
|
|
void TClifo_application::init_query_mode(TMask& m)
|
|
{
|
|
if (_gesven)
|
|
reset_sheet();
|
|
|
|
if (argc() > 2 && *argv(2) == 'F')
|
|
m.set(F_TIPOCF, "F");
|
|
m.show(F_CODLIST, _liscatven);
|
|
m.show(F_CODLIST1, !_liscatven);
|
|
m.disable(DLG_CONTRLAV);
|
|
}
|
|
|
|
void TClifo_application::init_query_insert_mode(TMask& m)
|
|
{
|
|
init_query_mode(m);
|
|
}
|
|
|
|
void TClifo_application::init_insert_mode(TMask& m)
|
|
{
|
|
init_query_mode(m);
|
|
m.enable_page(4, _gesven);
|
|
}
|
|
|
|
void TClifo_application::init_modify_mode(TMask& m)
|
|
{
|
|
m.enable_page(4, _gesven);
|
|
m.efield(F_IBAN_STATO).validate(K_TAB); // Decodifica IBAN
|
|
m.enable(DLG_CONTRLAV, main_app().has_module(LVAUT) && m.get(F_TIPOCF) == "C");
|
|
}
|
|
|
|
void TClifo_application::set_pnae(TMask& m, TToken_string& nonacc, TToken_string& nonscd)
|
|
{
|
|
TSheet_field& pnae = m.sfield(F_NONACCEFF);
|
|
pnae.destroy();
|
|
TToken_string periodo(12, ',');
|
|
int per = 0;
|
|
for (bool good = nonacc.get(per, periodo); good; good = nonacc.get(++per, periodo))
|
|
{
|
|
TToken_string& row = pnae.row(-1);
|
|
row = periodo << '|' << nonscd.get(per);
|
|
row.replace(';', '|');
|
|
row.replace(',', '|');
|
|
row.replace('-', '|');
|
|
}
|
|
pnae.force_update();
|
|
}
|
|
|
|
int TClifo_application::read(TMask& m)
|
|
{
|
|
TRelation_application::read(m);
|
|
|
|
const TRectype& cfven = get_relation()->curr(LF_CFVEN);
|
|
TToken_string nonacc(cfven.get(CFV_NONACCEFF), ';');
|
|
TToken_string nonscd(cfven.get(CFV_NONSCADEFF), ';');
|
|
set_pnae(m, nonacc, nonscd);
|
|
|
|
if (_gesven)
|
|
{
|
|
TToken_string riga(240);
|
|
indsp_sheet().reset();
|
|
for (int i=0; i< _rel->indirizzi_items();i++)
|
|
{
|
|
TRectype& rec=_rel->indirizzo(i);
|
|
riga.cut(0);
|
|
riga.add(rec.get(IND_RAGSOC));
|
|
riga.add(rec.get(IND_INDIR));
|
|
riga.add(rec.get(IND_CIV));
|
|
riga.add(rec.get(IND_LOCALITA));
|
|
riga.add(rec.get(IND_CAP));
|
|
riga.add(rec.get(IND_STATO));
|
|
riga.add(rec.get(IND_COM));
|
|
riga.add(rec.get(IND_PTEL));
|
|
riga.add(rec.get(IND_TEL));
|
|
riga.add(rec.get(IND_PFAX));
|
|
riga.add(rec.get(IND_FAX));
|
|
riga.add(rec.get(IND_IVARID));
|
|
TString8 key;
|
|
key << rec.get(IND_STATO);
|
|
key << '|' << rec.get(IND_COM);
|
|
const TRectype& com = cache().get(LF_COMUNI, key);
|
|
riga.add(com.get(COM_DENCOM));
|
|
riga.add(rec.get(IND_CODIND));
|
|
|
|
indsp_sheet().row(i)=riga;
|
|
|
|
// Load the sheets of CODINDDOC, CODINDSP, CODINDEFF.
|
|
riga.cut(0);
|
|
riga.add(rec.get(IND_CODIND));
|
|
riga.add(rec.get(IND_RAGSOC));
|
|
riga.add(rec.get(IND_INDIR));
|
|
riga.add(rec.get(IND_CIV));
|
|
riga.add(rec.get(IND_LOCALITA));
|
|
field_sheet(F_CODINDDOC).add(riga);
|
|
field_sheet(F_CODINDSP).add(riga);
|
|
field_sheet(F_CODINDEFF).add(riga);
|
|
}
|
|
}
|
|
return _rel->status();
|
|
}
|
|
|
|
void TClifo_application::ini2mask(TConfig& ini, TMask& m, bool query)
|
|
{
|
|
TRelation_application::ini2mask(ini, m, query);
|
|
|
|
if (!query)
|
|
{
|
|
ini.set_paragraph("17");
|
|
|
|
if (ini.exist(CFV_NONACCEFF))
|
|
{
|
|
TToken_string nonacc(ini.get(CFV_NONACCEFF), ';');
|
|
TToken_string nonscd(ini.get(CFV_NONSCADEFF), ';');
|
|
set_pnae(m, nonacc, nonscd);
|
|
}
|
|
|
|
if (_gesven)
|
|
{
|
|
TToken_string riga(240);
|
|
TString16 para;
|
|
for (int i=0; ;i++)
|
|
{
|
|
para.format("%d,%d", LF_INDSP, i+1);
|
|
if (!ini.set_paragraph(para))
|
|
break;
|
|
if (i == 0)
|
|
indsp_sheet().reset();
|
|
|
|
riga.cut(0);
|
|
riga.add(ini.get(IND_RAGSOC));
|
|
riga.add(ini.get(IND_INDIR));
|
|
riga.add(ini.get(IND_CIV));
|
|
riga.add(ini.get(IND_LOCALITA));
|
|
riga.add(ini.get(IND_CAP));
|
|
riga.add(ini.get(IND_STATO));
|
|
riga.add(ini.get(IND_COM));
|
|
riga.add(ini.get(IND_PTEL));
|
|
riga.add(ini.get(IND_TEL));
|
|
riga.add(ini.get(IND_PFAX));
|
|
riga.add(ini.get(IND_FAX));
|
|
riga.add(ini.get(IND_IVARID));
|
|
TString16 key;
|
|
key << ini.get(IND_STATO);
|
|
key << '|' << ini.get(IND_COM);
|
|
const TRectype & com = cache().get(LF_COMUNI, key);
|
|
riga.add(com.get(COM_DENCOM));
|
|
|
|
indsp_sheet().row(i)=riga;
|
|
|
|
// Load the sheets of CODINDDOC, CODINDSP, CODINDEFF.
|
|
riga.cut(0);
|
|
riga.add(ini.get(IND_CODIND));
|
|
riga.add(ini.get(IND_RAGSOC));
|
|
riga.add(ini.get(IND_INDIR));
|
|
riga.add(ini.get(IND_CIV));
|
|
riga.add(ini.get(IND_LOCALITA));
|
|
field_sheet(F_CODINDDOC).add(riga);
|
|
field_sheet(F_CODINDSP).add(riga);
|
|
field_sheet(F_CODINDEFF).add(riga);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int TClifo_application::rewrite(const TMask& m)
|
|
{
|
|
common_f(m);
|
|
return TRelation_application::rewrite(m);
|
|
}
|
|
|
|
int TClifo_application::write(const TMask& m)
|
|
{
|
|
common_f(m);
|
|
return TRelation_application::write(m);
|
|
}
|
|
|
|
void TClifo_application::mask2ini(const TMask& m, TConfig& ini)
|
|
{
|
|
TRelation_application::mask2ini(m, ini);
|
|
|
|
TToken_string nonacceff(30, ';'), nonscadeff(30, ';');
|
|
get_pnae(m, nonacceff, nonscadeff);
|
|
ini.set(CFV_NONACCEFF, nonacceff, "17");
|
|
ini.set(CFV_NONSCADEFF, nonscadeff, "17");
|
|
|
|
if (_gesven)
|
|
{
|
|
const TString& tipocf = m.get(F_TIPOCF);
|
|
const long codcf = m.get_long(F_CODCF);
|
|
|
|
TString_array& rows=indsp_sheet().rows_array();
|
|
const int n_items = rows.items();
|
|
|
|
TString16 para;
|
|
int i;
|
|
|
|
for (i = 0; i < n_items; i++)
|
|
{
|
|
para.format("%d,%d", LF_INDSP, i+1);
|
|
ini.set_paragraph(para);
|
|
|
|
TToken_string& row=(TToken_string&)rows[i];
|
|
ini.set(IND_TIPOCF,tipocf);
|
|
ini.set(IND_CODCF,codcf);
|
|
ini.set(IND_RAGSOC,row.get(0));
|
|
ini.set(IND_INDIR,row.get());
|
|
ini.set(IND_CIV,row.get());
|
|
ini.set(IND_LOCALITA,row.get());
|
|
ini.set(IND_CAP,row.get());
|
|
ini.set(IND_STATO,row.get());
|
|
ini.set(IND_COM,row.get());
|
|
ini.set(IND_PTEL,row.get());
|
|
ini.set(IND_TEL,row.get());
|
|
ini.set(IND_PFAX,row.get());
|
|
ini.set(IND_FAX,row.get());
|
|
ini.set(IND_IVARID,row.get());
|
|
ini.set(IND_CODIND,i+1);
|
|
}
|
|
for ( ; ; i++)
|
|
{
|
|
para.format("%d,%d", LF_INDSP, i+1);
|
|
if (ini.set_paragraph(para))
|
|
ini.remove_all();
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TString_array& TClifo_application::field_sheet(short id) const
|
|
{
|
|
TEdit_field& f = _msk->efield(id);
|
|
TString_array& ss = f.sheet()->rows_array();
|
|
return ss;
|
|
}
|
|
|
|
TSheet_field& TClifo_application::indsp_sheet() const
|
|
{
|
|
TSheet_field& o_sheet=_msk->sfield(F_SHEET_G_VEN);
|
|
return o_sheet;
|
|
}
|
|
|
|
void TClifo_application::reset_sheet()
|
|
{
|
|
TToken_string nulla = "|**";
|
|
nulla << TR("Nessuno") << "**";
|
|
|
|
|
|
TClifo_application& a = app();
|
|
a.field_sheet(F_CODINDDOC).destroy();
|
|
a.field_sheet(F_CODINDDOC).add(nulla);
|
|
a.field_sheet(F_CODINDSP).destroy();
|
|
a.field_sheet(F_CODINDSP).add(nulla);
|
|
a.field_sheet(F_CODINDEFF).destroy();
|
|
a.field_sheet(F_CODINDEFF).add(nulla);
|
|
}
|
|
|
|
void TClifo_application::indsp_pack()
|
|
{
|
|
TArray& rows = indsp_sheet().rows_array();
|
|
int nr=rows.items();
|
|
|
|
for (int i=0; i<nr; i++)
|
|
{
|
|
TToken_string& riga=(TToken_string&)rows[i];
|
|
if (riga.empty_items())
|
|
rows.destroy(i,false);
|
|
}
|
|
rows.pack();
|
|
}
|
|
|
|
void TClifo_application::get_pnae(const TMask& m, TToken_string& nonacceff, TToken_string& nonscadeff)
|
|
{
|
|
TSheet_field& pnae = m.sfield(F_NONACCEFF);
|
|
FOR_EACH_SHEET_ROW(pnae, re, row) if (!row->empty_items())
|
|
{
|
|
TString16 p;
|
|
p << row->get(0) << '-'; p << row->get(1) << ',';
|
|
p << row->get(2) << '-'; p << row->get(3);
|
|
nonacceff.add(p);
|
|
p = row->get(4); p << '-' << row->get(5);
|
|
nonscadeff.add(p);
|
|
}
|
|
|
|
TRectype& cfven = get_relation()->curr(LF_CFVEN);
|
|
int mass = cfven.length(CFV_NONACCEFF);
|
|
if (nonacceff.len() > mass)
|
|
nonacceff.cut(mass);
|
|
mass = cfven.length(CFV_NONSCADEFF);
|
|
if (nonscadeff.len() > mass)
|
|
nonscadeff.cut(mass);
|
|
}
|
|
|
|
void TClifo_application::common_f(const TMask& m)
|
|
{
|
|
TToken_string nonacceff(30, ';'), nonscadeff(30, ';');
|
|
get_pnae(m, nonacceff, nonscadeff);
|
|
TRectype& cfven = get_relation()->curr(LF_CFVEN);
|
|
cfven.put(CFV_NONACCEFF, nonacceff);
|
|
cfven.put(CFV_NONSCADEFF, nonscadeff);
|
|
|
|
if (_gesven)
|
|
{
|
|
const char tipocf = m.get(F_TIPOCF)[0];
|
|
const long codcf = m.get_long(F_CODCF);
|
|
|
|
_rel->destroy_rows();
|
|
indsp_pack();
|
|
TArray& rows=indsp_sheet().rows_array();
|
|
int n_items = rows.items();
|
|
|
|
for (int i = 0; i < n_items; i++)
|
|
{
|
|
TToken_string& row=(TToken_string&)rows[i];
|
|
TRectype& rec=_rel->indirizzo(i);
|
|
row.restart();
|
|
rec.zero();
|
|
rec.put(IND_TIPOCF,tipocf);
|
|
rec.put(IND_CODCF,codcf);
|
|
rec.put(IND_RAGSOC,row.get());
|
|
rec.put(IND_INDIR,row.get());
|
|
rec.put(IND_CIV,row.get());
|
|
rec.put(IND_LOCALITA,row.get());
|
|
rec.put(IND_CAP,row.get());
|
|
rec.put(IND_STATO,row.get());
|
|
rec.put(IND_COM,row.get());
|
|
rec.put(IND_PTEL,row.get());
|
|
rec.put(IND_TEL,row.get());
|
|
rec.put(IND_PFAX,row.get());
|
|
rec.put(IND_FAX,row.get());
|
|
rec.put(IND_IVARID,row.get());
|
|
rec.put(IND_CODIND,i+1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TClifo_application::indsp_sheet_rebuilder()
|
|
{
|
|
TClifo_application& a = app();
|
|
TString_array& righe = a.indsp_sheet().rows_array();
|
|
const int n = righe.items();
|
|
a.reset_sheet();
|
|
// Rebuild Sheets
|
|
TToken_string rigav;
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
TToken_string& riga= righe.row(i);
|
|
rigav.format("%d", i+1);
|
|
rigav.add(riga.get(0));
|
|
rigav.add(riga.get());
|
|
rigav.add(riga.get());
|
|
rigav.add(riga.get());
|
|
a.field_sheet(F_CODINDDOC).add(rigav);
|
|
a.field_sheet(F_CODINDSP).add(rigav);
|
|
a.field_sheet(F_CODINDEFF).add(rigav);
|
|
}
|
|
}
|
|
|
|
bool TClifo_application::indsp_notify(TSheet_field& indsp, int r, KEY key)
|
|
{
|
|
switch (key)
|
|
{
|
|
case K_CTRL + K_INS:
|
|
// request to add the row #r
|
|
// To avoid rewriting of existing record.
|
|
// To avoid inserts in the middle of the sheet
|
|
if (r != -1 && indsp.items() > (r+1))
|
|
return error_box(TR("Si possono aggiungere indirizzi solo alla fine!"));
|
|
break;
|
|
case K_ENTER:
|
|
indsp_sheet_rebuilder();
|
|
break;
|
|
case K_DEL:
|
|
if (r < indsp.items() - 1)
|
|
return error_box(TR("Si puo' eliminare solo l'ultimo indirizzo!"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::effetti_notify(TSheet_field& pnae, int r, KEY key)
|
|
{
|
|
if (key == K_INS)
|
|
{
|
|
TClifo_application& a = app();
|
|
TRectype& cfven = a.get_relation()->curr(LF_CFVEN);
|
|
int mass_len = cfven.length(CFV_NONACCEFF); // Lunghezza campo
|
|
int mass_rig = mass_len / 11; // Numero di periodi ivi salvabili
|
|
return pnae.items() < mass_rig; // Non accettare righe che non si possono salvare
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::user_create() // initvar e arrmask
|
|
{
|
|
open_files(LF_CLIFO, LF_CFVEN, LF_INDSP, LF_TAB, LF_TABCOM, LF_MOV, LF_ANAG,
|
|
LF_ANAGFIS, LF_PCON, LF_COMUNI, 0);
|
|
_has_cg = has_module(CGAUT, CHK_DONGLE);
|
|
_rel = new TClifoVI;
|
|
|
|
_msk = new TMask("cg0200a") ;
|
|
|
|
_msk->set_handler(F_TIPOCF, tipocf_handler);
|
|
_msk->set_handler(F_COFI, cofi_handler);
|
|
_msk->set_handler(F_PAIV, paiv_handler);
|
|
_msk->set_handler(F_CODANAGPER, percip_handler);
|
|
_msk->set_handler(F_TIPOPERS, tipo_handler);
|
|
_msk->set_handler(DLG_ANAG, crea_percipienti);
|
|
_msk->set_handler(F_ALLEG, alleg_handler);
|
|
_msk->set_handler(F_CODALLEG, codalleg_handler);
|
|
_msk->set_handler(DLG_EMAIL, email_handler);
|
|
_msk->set_handler(F_RAGSOC, rsoc_handler);
|
|
_msk->set_handler(DLG_CONTRLAV, contrlav_handler);
|
|
|
|
TSheet_field& ind = _msk->sfield(F_SHEET_G_VEN);
|
|
ind.set_notify(indsp_notify);
|
|
|
|
TSheet_field& pnae = _msk->sfield(F_NONACCEFF);
|
|
pnae.set_notify(effetti_notify);
|
|
|
|
TConfig config(CONFIG_STUDIO);
|
|
_savenew = !config.get_bool("Cg02SN");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_application::user_destroy() // releasev e arrmask
|
|
{
|
|
delete _msk;
|
|
delete _rel;
|
|
return true;
|
|
}
|
|
|
|
int cg0200(int argc, char* argv[])
|
|
{
|
|
TClifo_application a;
|
|
|
|
a.run(argc, argv, TR("Clienti/Fornitori"));
|
|
return 0;
|
|
}
|
|
|
|
|
|
|