200b962343
git-svn-id: svn://10.65.10.50/branches/R_10_00@22755 c028cbd2-c16b-5b4b-a496-9718f37d4682
1517 lines
39 KiB
C++
Executable File
1517 lines
39 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 <validate.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>
|
||
#include "cfban.h"
|
||
|
||
class TClifo_application : public TRelation_application
|
||
{
|
||
TMask* _msk;
|
||
TClifoVI* _rel;
|
||
|
||
bool _lbcn, _gesven, _gessal, _has_cg, _liscatven, _geslv;
|
||
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);
|
||
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);
|
||
void add_bank(TSheet_field& ns_sh, const TRectype& rec);
|
||
|
||
|
||
virtual int write(const TMask& m);
|
||
virtual int rewrite(const TMask& m);
|
||
virtual int read(TMask& m);
|
||
virtual bool remove();
|
||
|
||
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);
|
||
static bool comi_handler(TMask_field& f, KEY k);
|
||
virtual bool has_filtered_cursor() const { return true;}
|
||
|
||
public:
|
||
virtual bool get_next_key(TToken_string& key);
|
||
// @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);
|
||
}
|
||
|
||
}
|
||
if (codcf > 999999L)
|
||
{
|
||
key.cut(0);
|
||
return false;
|
||
}
|
||
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 || alleg == 7)) // ... e non sono occasionale
|
||
{
|
||
const TEdit_field& cofi = m.efield(F_COFI);
|
||
if (cofi.empty()) // Dal 2007 serve il codice fiscale
|
||
ok = cofi.yesno_box(TR("Codice fiscale assente per residente in Italia : lo accetto ugualmente ?"));
|
||
// Se NON sono privato (alleg!=6), serve partita IVA
|
||
if (ok)
|
||
{
|
||
const TEdit_field& paiv = m.efield(F_PAIV);
|
||
if (alleg != 6 && paiv.empty())
|
||
ok = paiv.yesno_box(TR("Partita IVA assente per non privato : la accetto ugualmente ?"));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
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 && alleg != 7)
|
||
{
|
||
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)
|
||
{
|
||
const TString& cofi = m.get(F_COFI);
|
||
if (cofi.full())
|
||
{
|
||
anag.setkey(3);
|
||
anag.put(ANA_TIPOA, tipo);
|
||
anag.put(ANA_COFI, cofi);
|
||
if (anag.read() == NOERR)
|
||
percip = anag.get_long(ANA_CODANAGR);
|
||
}
|
||
if (percip == 0)
|
||
{
|
||
const TString& paiv = m.get(F_PAIV);
|
||
if (paiv.full())
|
||
{
|
||
anag.setkey(4);
|
||
anag.put(ANA_TIPOA, tipo);
|
||
anag.put(ANA_STATOPAIV, m.get(F_STATOPAIV));
|
||
anag.put(ANA_PAIV, paiv);
|
||
if (anag.read() == NOERR)
|
||
percip = anag.get_long(ANA_CODANAGR);
|
||
}
|
||
}
|
||
if (percip == 0)
|
||
{
|
||
percip = m.get_long(F_CODCF);
|
||
|
||
anag.setkey(1);
|
||
anag.put(ANA_TIPOA, tipo);
|
||
anag.put(ANA_CODANAGR, percip);
|
||
if (anag.read() == NOERR)
|
||
{
|
||
m.set(F_CODANAGPER, percip);
|
||
message_box(TR("Esiste gi<67> una anagrafica corrispondente al fornitore"));
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
m.set(F_CODANAGPER, percip);
|
||
anag.setkey(1);
|
||
anag.put(ANA_TIPOA, tipo);
|
||
anag.put(ANA_CODANAGR, percip);
|
||
if (anag.read() == NOERR)
|
||
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 == _isreinsert)
|
||
return true;
|
||
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 cantwrite_box(anafis.description());
|
||
}
|
||
else
|
||
{
|
||
TLocalisamfile anagiu(LF_ANAGGIU);
|
||
anagiu.put(ANG_CODANAGR, percip);
|
||
err = anagiu.write();
|
||
if (err != NOERR)
|
||
return cantwrite_box(anagiu.description());
|
||
}
|
||
}
|
||
else
|
||
return cantwrite_box(anag.description());
|
||
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TClifo_application::percip_handler(TMask_field& f, KEY key)
|
||
{
|
||
TMask& m = f.mask();
|
||
const bool full = f.get().full();
|
||
|
||
if (f.to_check(key, true))
|
||
m.enable(DLG_ANAG, !full);
|
||
|
||
if (f.to_check(key) && full)
|
||
{
|
||
const 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)[0] == '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;
|
||
}
|
||
|
||
bool TClifo_application::comi_handler(TMask_field& f, KEY k)
|
||
{
|
||
if (f.to_check(k))
|
||
{
|
||
const TEdit_field& ef = (const TEdit_field&)f;
|
||
const TRectype& curr_comune = ef.browse()->cursor()->curr();
|
||
long cap_curr_comune = curr_comune.get_long(COM_CAPCOM);
|
||
//il controllo va fatto solo per i comuni a cap multipli, ovvero con il cap base divisibile per 100
|
||
if (cap_curr_comune%100 == 0)
|
||
{
|
||
const long cap_scritto = f.mask().get_long(F_CAPI);
|
||
//test compatibilit<69> dei 2 cap
|
||
if (cap_curr_comune / 100 == cap_scritto / 100)
|
||
cap_curr_comune = cap_scritto;
|
||
}
|
||
f.mask().set(F_CAPI, cap_curr_comune);
|
||
}
|
||
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 altnewcli_handler(TMask_field& f, KEY key)
|
||
{
|
||
TMask& m = f.mask();
|
||
if (key == K_SPACE)
|
||
{
|
||
long divisore = ini_get_int(CONFIG_DITTA, "cg", "CliForModule", 100);
|
||
TToken_string key;
|
||
|
||
app().get_next_key(key);
|
||
const long cod = (key.get_long(3) / divisore + 1) * divisore;
|
||
|
||
m.set(F_CODCF, cod);
|
||
if (m.mode() == MODE_QUERY)
|
||
m.stop_run(K_AUTO_ENTER);
|
||
}
|
||
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");
|
||
_geslv = _gesven && main_app().has_module(LVAUT);
|
||
|
||
init_pages(*_msk);
|
||
_msk->show(-9, _gessal); // Mostra campi Estratti conto
|
||
_msk->enable(DLG_CONTRLAV, main_app().has_module(LVAUT));
|
||
if (_msk->id2pos(DLG_ALTNEWCLI) >= 0)
|
||
_msk->set_handler(DLG_ALTNEWCLI, altnewcli_handler);
|
||
}
|
||
|
||
|
||
void TClifo_application::init_pages(TMask& m)
|
||
{
|
||
_rel->gestione_vendite(_gesven);
|
||
_rel->gestione_lavanderie(_geslv);
|
||
|
||
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);
|
||
if (m.id2pos(DLG_ALTNEWCLI) >= 0)
|
||
m.enable(DLG_ALTNEWCLI);
|
||
}
|
||
|
||
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);
|
||
if(_gesven)
|
||
{
|
||
m.enable_page(10, _geslv);
|
||
if (_geslv)
|
||
m.set(F_ARTSEP, "X");
|
||
}
|
||
if (m.id2pos(DLG_ALTNEWCLI) >= 0)
|
||
m.enable(DLG_ALTNEWCLI);
|
||
}
|
||
|
||
void TClifo_application::init_modify_mode(TMask& m)
|
||
{
|
||
m.enable_page(4, _gesven);
|
||
if(_gesven)
|
||
m.enable_page(10, _geslv);
|
||
m.enable(DLG_CONTRLAV, _geslv && m.get(F_TIPOCF) == "C");
|
||
if (m.id2pos(DLG_ALTNEWCLI) >= 0)
|
||
m.disable(DLG_ALTNEWCLI);
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
void TClifo_application::add_bank(TSheet_field& ns_sh, const TRectype& rec)
|
||
{
|
||
TToken_string & row = ns_sh.row(-1);
|
||
|
||
TString8 abi, cab;
|
||
TString80 numcc, iban;
|
||
|
||
switch (rec.num())
|
||
{
|
||
case LF_CLIFO:
|
||
abi = rec.get(CLI_CODABI);
|
||
cab = rec.get(CLI_CODCAB);
|
||
numcc = rec.get(CLI_NUMCC);
|
||
iban = rec.get(CLI_IBAN);
|
||
break;
|
||
case LF_CFVEN:
|
||
abi = rec.get(CFV_CODABIPR);
|
||
cab = rec.get(CFV_CODCABPR);
|
||
break;
|
||
case LF_CFBAN:
|
||
abi = rec.get(CFBAN_ABI);
|
||
cab = rec.get(CFBAN_CAB);
|
||
numcc = rec.get(CFBAN_NUMCC);
|
||
iban = rec.get(CFBAN_IBAN);
|
||
// Copia il progressivo solo nello sheet delle banche di presentazione
|
||
if (ns_sh.sheet_mask().efield(F_PROGPR).active())
|
||
{
|
||
const TString& progr = rec.get(CFBAN_PROGPR);
|
||
row.add(progr, ns_sh.cid2index(F_PROGPR));
|
||
if (abi.len()+cab.len() == 10)
|
||
{
|
||
TString16 codtab; codtab << abi << cab << progr;
|
||
const TString& ib = cache().get("BNP", codtab, "S3");
|
||
TString msg;
|
||
if (iban_check(ib, msg) == 0)
|
||
iban = ib;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
// Esistono dati erronamente pi<70> lunghi
|
||
numcc.cut(12); numcc.trim();
|
||
|
||
if (iban.full())
|
||
{
|
||
TString msg;
|
||
if (iban_check(iban, msg) == 0)
|
||
{
|
||
if (iban.starts_with("IT"))
|
||
{
|
||
abi = iban.mid(5, 5);
|
||
cab = iban.mid(10, 5);
|
||
numcc = iban.right(12);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (bban_check(iban, msg) == 0)
|
||
{
|
||
abi = iban.mid(1, 5);
|
||
cab = iban.mid(6, 5);
|
||
numcc = iban.mid(11);
|
||
row.add("IT", ns_sh.cid2index(F_IBAN_STATO));
|
||
row.add(iban.left(1), ns_sh.cid2index(F_BBAN_CIN));
|
||
}
|
||
else
|
||
iban.cut(0);
|
||
}
|
||
}
|
||
|
||
row.add(abi, ns_sh.cid2index(F_BBAN_ABI));
|
||
row.add(cab, ns_sh.cid2index(F_BBAN_CAB));
|
||
row.add(numcc, ns_sh.cid2index(F_BBAN_CONTO));
|
||
|
||
if (abi.len()+cab.len() == 10)
|
||
{
|
||
TString16 key; key << abi << cab;
|
||
row.add(cache().get("%BAN", key, "S0"), ns_sh.cid2index(F_DESBAN));
|
||
}
|
||
|
||
if (row.starts_with("IT") && row.get_int(ns_sh.cid2index(F_IBAN_CHECK)) == 0)
|
||
{
|
||
const int i = ns_sh.items()-1;
|
||
TMask& msk = ns_sh.sheet_row_mask(i);
|
||
ns_sh.update_mask(i); // Copia dalla riga alla maschera
|
||
msk.efield(F_IBAN_CHECK).validate(K_TAB); // Calcola checksum
|
||
const TString& chk = msk.get(F_IBAN_CHECK);
|
||
if (!real::is_null(chk) && iban.len() == 23) // BBAN da completare
|
||
{
|
||
iban.insert(chk);
|
||
iban.insert("IT");
|
||
}
|
||
}
|
||
|
||
if (iban.full())
|
||
{
|
||
row.add(iban.left(2), ns_sh.cid2index(F_IBAN_STATO));
|
||
row.add(iban.mid(2,2), ns_sh.cid2index(F_IBAN_CHECK));
|
||
if (row.starts_with("IT"))
|
||
row.add(iban.mid(4,1), ns_sh.cid2index(F_BBAN_CIN));
|
||
else
|
||
row.add(iban.mid(4), ns_sh.cid2index(F_BBAN));
|
||
row.add(iban, ns_sh.cid2index(F_IBAN));
|
||
}
|
||
}
|
||
|
||
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), ';');
|
||
int i;
|
||
|
||
set_pnae(m, nonacc, nonscd);
|
||
|
||
if (_gesven)
|
||
{
|
||
TToken_string riga(240);
|
||
indsp_sheet().reset();
|
||
for (i = 0; i < _rel->indirizzi(); 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_INDIR2));
|
||
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);
|
||
}
|
||
|
||
TSheet_field& s = m.sfield(F_SHEET_CONT);
|
||
s.destroy();
|
||
for (int c = 0; c < _rel->contatti(); c++)
|
||
{
|
||
const TRectype& contact = _rel->contatto(c);
|
||
TToken_string& row = s.row(-1);
|
||
row = contact.get("SECOND");
|
||
row << "|||" << contact.get("DATA");
|
||
s.check_row(c);
|
||
}
|
||
}
|
||
|
||
TToken_string key;
|
||
key.add(m.get(F_TIPOCF));
|
||
key.add(m.get(F_CODCF));
|
||
key.add("V");
|
||
TRecord_array ns_ban(key, LF_CFBAN);
|
||
|
||
const TRectype& clifo = get_relation()->curr(LF_CLIFO);
|
||
TSheet_field & ns_sh = m.sfield(F_BANA);
|
||
|
||
ns_sh.destroy(-1, false);
|
||
for (i = 1; i <= ns_ban.rows(); i++)
|
||
add_bank(ns_sh, ns_ban.row(i));
|
||
if (ns_ban.rows() == 0 && clifo.get_int(CLI_CODABI) != 0)
|
||
add_bank(ns_sh, clifo);
|
||
|
||
key.cut(0);
|
||
key.add(m.get(F_TIPOCF));
|
||
key.add(m.get(F_CODCF));
|
||
key.add("N");
|
||
|
||
TRecord_array vs_ban(key, LF_CFBAN);
|
||
TSheet_field & vs_sh = m.sfield(F_BANP);
|
||
|
||
vs_sh.destroy(-1, false);
|
||
for (i = 1; i <= vs_ban.rows(); i++)
|
||
add_bank(vs_sh, vs_ban.row(i));
|
||
if (vs_ban.rows() == 0 && cfven.get_int(CFV_CODABIPR) != 0)
|
||
add_bank(vs_sh, cfven);
|
||
|
||
return _rel->status();
|
||
}
|
||
|
||
void TClifo_application::ini2mask(TConfig& ini, TMask& m, bool query)
|
||
{
|
||
TRelation_application::ini2mask(ini, m, query);
|
||
int i;
|
||
|
||
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 (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));
|
||
riga.add(ini.get(IND_INDIR2));
|
||
riga.add(ini.get(IND_CODIND));
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
TString p;
|
||
|
||
p << LF_CFBAN << ",V";
|
||
TSheet_field & ns_sh = m.sfield(F_BANA);
|
||
|
||
for (i = 0; ; i++)
|
||
{
|
||
TString para(p); para << "," << i + 1;
|
||
const TString & abi = ini.get(CFBAN_ABI, para);
|
||
if (abi.blank())
|
||
break;
|
||
TToken_string & row = ns_sh.row(i);
|
||
|
||
row.add(abi, ns_sh.cid2index(F_BBAN_ABI));
|
||
row.add(ini.get(CFBAN_CAB, para), ns_sh.cid2index(F_BBAN_CAB));
|
||
row.add(ini.get(CFBAN_NUMCC, para), ns_sh.cid2index(F_BBAN_CONTO));
|
||
|
||
const TString & iban = ini.get(CFBAN_IBAN, para);
|
||
|
||
row.add(iban, ns_sh.cid2index(F_IBAN));
|
||
ns_sh.update_mask(i - 1);
|
||
}
|
||
p.cut(0);
|
||
p << LF_CFBAN << ",N";
|
||
TSheet_field & vs_sh = m.sfield(F_BANP);
|
||
|
||
for (i = 0; ; i++)
|
||
{
|
||
TString para(p); para << "," << i + 1;
|
||
const TString & abi = ini.get(CFBAN_ABI, para);
|
||
|
||
if (abi.blank())
|
||
break;
|
||
TToken_string & row = vs_sh.row(i);
|
||
|
||
row.add(abi, vs_sh.cid2index(F_BBAN_ABI));
|
||
row.add(ini.get(CFBAN_CAB, para), vs_sh.cid2index(F_BBAN_CAB));
|
||
row.add(ini.get(CFBAN_PROGPR, para), vs_sh.cid2index(F_PROGPR));
|
||
vs_sh.update_mask(i - 1);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
bool TClifo_application::remove()
|
||
{
|
||
int err = TRelation_application::remove();
|
||
|
||
if (err == NOERR)
|
||
{
|
||
TRelation * r = get_relation();
|
||
TToken_string key;
|
||
|
||
key.add(r->lfile().get(CLI_TIPOCF));
|
||
key.add(r->lfile().get(CLI_CODCF));
|
||
key.add("V");
|
||
|
||
TRecord_array ns_ban(key, LF_CFBAN);
|
||
|
||
ns_ban.remove();
|
||
|
||
key.cut(0);
|
||
key.add(r->lfile().get(CLI_TIPOCF));
|
||
key.add(r->lfile().get(CLI_CODCF));
|
||
key.add("N");
|
||
|
||
TRecord_array vs_ban(key, LF_CFBAN);
|
||
|
||
vs_ban.remove();
|
||
}
|
||
return err == NOERR;
|
||
}
|
||
|
||
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");
|
||
int i;
|
||
|
||
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;
|
||
|
||
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_INDIR2,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 p;
|
||
|
||
p << LF_CFBAN << ",V";
|
||
TSheet_field & ns_sh = m.sfield(F_BANA);
|
||
|
||
for (int i = 0; i < ns_sh.items(); i++)
|
||
{
|
||
TString para(p); para << "," << i + 1;
|
||
TToken_string & row = ns_sh.row(i);
|
||
|
||
ini.set(CFBAN_ABI, row.get(ns_sh.cid2index(F_BBAN_ABI)), para);
|
||
ini.set(CFBAN_CAB, row.get(ns_sh.cid2index(F_BBAN_CAB)), para);
|
||
ini.set(CFBAN_NUMCC, row.get(ns_sh.cid2index(F_BBAN_CONTO)), para);
|
||
ini.set(CFBAN_IBAN, row.get(ns_sh.cid2index(F_IBAN)), para);
|
||
}
|
||
for ( ; ; i++)
|
||
{
|
||
TString para(p); para << "," << i + 1;
|
||
|
||
if (ini.set_paragraph(para))
|
||
ini.remove_all();
|
||
else
|
||
break;
|
||
}
|
||
|
||
p.cut(0);
|
||
p << LF_CFBAN << ",N";
|
||
TSheet_field & vs_sh = m.sfield(F_BANP);
|
||
|
||
for (i = 0; i < vs_sh.items(); i++)
|
||
{
|
||
TString para(p); para << "," << i + 1;
|
||
TToken_string & row = vs_sh.row(i);
|
||
|
||
ini.set(CFBAN_ABI, row.get(vs_sh.cid2index(F_BBAN_ABI)), para);
|
||
ini.set(CFBAN_CAB, row.get(vs_sh.cid2index(F_BBAN_CAB)), para);
|
||
ini.set(CFBAN_PROGPR, row.get(vs_sh.cid2index(F_PROGPR)), para);
|
||
}
|
||
for ( ; ; i++)
|
||
{
|
||
TString para(p); para << "," << 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)
|
||
{
|
||
const TString& alter = m.get(F_RICALT);
|
||
if (alter.blank() && m.mode() == MODE_INS)
|
||
((TMask &)m).set(F_RICALT, m.get(F_RAGSOC).left(m.field(F_RICALT).size()));
|
||
|
||
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());
|
||
row.get();
|
||
rec.put(IND_INDIR2,row.get());
|
||
rec.put(IND_CODIND,i+1);
|
||
}
|
||
|
||
TToken_string data;
|
||
TString8 first, second;
|
||
first.format("%c%06ld", m.get(F_TIPOCF)[0], m.get_long(F_CODCF));
|
||
TSheet_field& s = m.sfield(F_SHEET_CONT);
|
||
FOR_EACH_SHEET_ROW(s, r, row)
|
||
{
|
||
TRectype& rec=_rel->contatto(r);
|
||
rec.put("COD", "BACON");
|
||
rec.put("FIRST", first);
|
||
second.format("%06ld", row->get_long(0));
|
||
rec.put("SECOND", second);
|
||
row->get(2);
|
||
data.cut(0);
|
||
const char* d = NULL;
|
||
while ((d = row->get()))
|
||
{
|
||
if (*d > ' ')
|
||
data.add(d);
|
||
}
|
||
rec.put("DATA", data);
|
||
}
|
||
}
|
||
|
||
TToken_string key;
|
||
key.add(m.get(F_TIPOCF));
|
||
key.add(m.get(F_CODCF));
|
||
key.add("V");
|
||
|
||
TRecord_array ns_ban(key, LF_CFBAN);
|
||
ns_ban.destroy_rows();
|
||
|
||
TRectype& clifo = get_relation()->curr(LF_CLIFO);
|
||
TSheet_field & ns_sh = m.sfield(F_BANA);
|
||
const int nsrow = ns_sh.items();
|
||
|
||
for (int i = 0; i < nsrow; i++)
|
||
{
|
||
TToken_string & row = ns_sh.row(i);
|
||
TRectype & ban = ns_ban.row(i + 1, true);
|
||
|
||
ban.put(CFBAN_ABI, row.get(ns_sh.cid2index(F_BBAN_ABI)));
|
||
ban.put(CFBAN_CAB, row.get(ns_sh.cid2index(F_BBAN_CAB)));
|
||
ban.put(CFBAN_NUMCC, row.get(ns_sh.cid2index(F_BBAN_CONTO)));
|
||
ban.put(CFBAN_IBAN, row.get(ns_sh.cid2index(F_IBAN)));
|
||
if (i == 0)
|
||
{
|
||
clifo.put(CLI_CODABI, row.get(ns_sh.cid2index(F_BBAN_ABI)));
|
||
clifo.put(CLI_CODCAB, row.get(ns_sh.cid2index(F_BBAN_CAB)));
|
||
clifo.put(CLI_NUMCC, row.get(ns_sh.cid2index(F_BBAN_CONTO)));
|
||
clifo.put(CLI_IBAN, row.get(ns_sh.cid2index(F_IBAN)));
|
||
}
|
||
}
|
||
if (nsrow == 0)
|
||
{
|
||
clifo.zero(CLI_CODABI);
|
||
clifo.zero(CLI_CODCAB);
|
||
clifo.zero(CLI_NUMCC);
|
||
clifo.zero(CLI_IBAN);
|
||
}
|
||
if (ns_ban.write(true) != NOERR)
|
||
return;
|
||
|
||
key.cut(0);
|
||
key.add(m.get(F_TIPOCF));
|
||
key.add(m.get(F_CODCF));
|
||
key.add("N");
|
||
|
||
TRecord_array vs_ban(key, LF_CFBAN);
|
||
vs_ban.destroy_rows();
|
||
|
||
TSheet_field & vs_sh = m.sfield(F_BANP);
|
||
const int vsrow = vs_sh.items();
|
||
|
||
for (int i = 0; i < vsrow; i++)
|
||
{
|
||
TToken_string & row = vs_sh.row(i);
|
||
TRectype & ban = vs_ban.row(i + 1, true);
|
||
|
||
ban.put(CFBAN_ABI, row.get(vs_sh.cid2index(F_BBAN_ABI)));
|
||
ban.put(CFBAN_CAB, row.get(vs_sh.cid2index(F_BBAN_CAB)));
|
||
ban.put(CFBAN_PROGPR, row.get(vs_sh.cid2index(F_PROGPR)));
|
||
if (i == 0)
|
||
{
|
||
cfven.put(CFV_CODABIPR, row.get(ns_sh.cid2index(F_BBAN_ABI)));
|
||
cfven.put(CFV_CODCABPR, row.get(ns_sh.cid2index(F_BBAN_CAB)));
|
||
}
|
||
}
|
||
if (vsrow == 0)
|
||
{
|
||
cfven.zero(CFV_CODABIPR);
|
||
cfven.zero(CFV_CODCABPR);
|
||
}
|
||
vs_ban.write(true);
|
||
}
|
||
|
||
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();
|
||
const TRectype& cfven = a.get_relation()->curr(LF_CFVEN);
|
||
const int mass_len = cfven.length(CFV_NONACCEFF); // Lunghezza campo
|
||
const int mass_rig = mass_len / 11; // Numero di periodi IVA salvabili
|
||
return pnae.items() < mass_rig; // Non accettare righe che non si possono salvare
|
||
}
|
||
|
||
if (key == K_ENTER)
|
||
{
|
||
// Controlla che i giorni superiori a 29 appartengano veramente al mese corrispondente
|
||
TToken_string& row = pnae.row(r);
|
||
bool dirty = false;
|
||
for (int i = 0; i <= 4; i += 2)
|
||
{
|
||
int gg; row.get(i, gg);
|
||
int mm; row.get(i+1, mm);
|
||
if (gg > 29)
|
||
{
|
||
TDate d(1, mm, 2000); // Scelgo un anno bisestile arbitrario
|
||
d.set_end_month();
|
||
if (d.day() < gg)
|
||
{
|
||
gg = d.day();
|
||
row.add(gg, i);
|
||
dirty = true;
|
||
}
|
||
}
|
||
}
|
||
if (dirty)
|
||
pnae.force_update(r);
|
||
}
|
||
|
||
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, LF_TABMOD, 0);
|
||
_has_cg = has_module(CGAUT, CHK_DONGLE);
|
||
|
||
_rel = new TClifoVI;
|
||
//gestisce i campi salvati sulla tabella di modulo lv020 (lvclifo)
|
||
_rel->add("&LV020" ,"CODTAB==" CLI_TIPOCF "+" CLI_CODCF, 1, LF_CLIFO, LVAUT);
|
||
_rel->write_enable(-LVAUT); //abilita la lettura / scrittura sul record collegato
|
||
|
||
_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);
|
||
ind.sheet_mask().set_handler(F_COMI, comi_handler);
|
||
|
||
TSheet_field& pnae = _msk->sfield(F_NONACCEFF);
|
||
pnae.set_notify(effetti_notify);
|
||
|
||
_savenew = !ini_get_bool(CONFIG_STUDIO, "cg", "Cg02SN");
|
||
|
||
return true;
|
||
}
|
||
|
||
bool TClifo_application::user_destroy() // releasev e arrmask
|
||
{
|
||
delete _rel;
|
||
return true;
|
||
}
|
||
|
||
int cg0200(int argc, char* argv[])
|
||
{
|
||
TClifo_application a;
|
||
|
||
a.run(argc, argv, TR("Clienti/Fornitori"));
|
||
return 0;
|
||
}
|
||
|
||
|
||
|