537 lines
13 KiB
C++
Executable File
537 lines
13 KiB
C++
Executable File
#include <relapp.h>
|
|
#include <modaut.h>
|
|
#include <utility.h>
|
|
#include <validate.h>
|
|
#include <msksheet.h>
|
|
#include <config.h>
|
|
#include <defmask.h>
|
|
|
|
#include <pconti.h>
|
|
#include <clifo.h>
|
|
#include <anagr.h>
|
|
#include <anafis.h>
|
|
|
|
#include "cg0.h"
|
|
#include "cg0200.h"
|
|
#include "cg0201.h"
|
|
|
|
|
|
bool gest_vend()
|
|
{
|
|
TConfig c(CONFIG_DITTA,"cg");
|
|
return (c.get("GesVen") == "X");
|
|
}
|
|
|
|
class CG0200_application : public TRelation_application
|
|
{
|
|
TMask* _msk;
|
|
TClifoVI *_rel;
|
|
TLocalisamfile* _saldi;
|
|
TLocalisamfile* _anag;
|
|
TLocalisamfile* _fis;
|
|
TLocalisamfile* _comuni;
|
|
TLocalisamfile* _pcon;
|
|
|
|
bool user_create();
|
|
bool user_destroy();
|
|
virtual TMask* get_mask(int mode) {return _msk;}
|
|
virtual bool changing_mask(int mode) {return FALSE;}
|
|
virtual bool protected_record(TRectype &rec);
|
|
virtual const char* get_next_key();
|
|
virtual void init_query_mode(TMask& m);
|
|
virtual void init_query_insert_mode(TMask& m) {init_query_mode(m);}
|
|
virtual void init_insert_mode(TMask& m) {init_query_mode(m);}
|
|
virtual void init_modify_mode(TMask& m) {init_query_mode(m);}
|
|
|
|
////////////
|
|
static bool indsp_notify(int r, KEY key);
|
|
static bool indsp_handler(TMask_field& f, KEY key) { return TRUE; }
|
|
virtual int write(const TMask& m);
|
|
virtual int rewrite(const TMask& m);
|
|
virtual int read(TMask& m);
|
|
TSheet_field& indsp_sheet() const;
|
|
void indsp_pack();
|
|
void common_f(const TMask& m);
|
|
///////////
|
|
|
|
public:
|
|
virtual TRelation* get_relation() const {return (TRelation*)_rel;}
|
|
CG0200_application() {}
|
|
};
|
|
|
|
inline CG0200_application& app()
|
|
{return (CG0200_application&)*MainApp();}
|
|
|
|
bool CG0200_application::protected_record(TRectype &rec)
|
|
|
|
{
|
|
TMask* m = get_mask(MODE_MOD);
|
|
const int gruppo = atoi(m->get(F_GRUPPO));
|
|
const int conto = atoi(m->get(F_CONTO));
|
|
const long sottoc = atol(m->get(F_CODCF));
|
|
|
|
_saldi->zero();
|
|
_saldi->put(PCN_GRUPPO, gruppo);
|
|
_saldi->put(PCN_CONTO, conto);
|
|
_saldi->put(PCN_SOTTOCONTO, sottoc);
|
|
_saldi->read();
|
|
|
|
return _saldi->good() &&
|
|
gruppo ==_saldi->get_int(PCN_GRUPPO) &&
|
|
conto ==_saldi->get_int(PCN_CONTO) &&
|
|
sottoc ==_saldi->get_long(PCN_SOTTOCONTO);
|
|
}
|
|
|
|
const char* CG0200_application::get_next_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);
|
|
}
|
|
}
|
|
return format("%d|%s|%d|%ld", F_TIPOCF, (const char*) tipo, F_CODCF, codcf);
|
|
}
|
|
|
|
HIDDEN bool no_dup_fis(TMask_field& f, KEY key)
|
|
{
|
|
TMask& msk = f.mask() ;
|
|
|
|
if (msk.query_mode() || !f.to_check(key)) return TRUE;
|
|
CG0200_application* app = (CG0200_application*) MainApp();
|
|
TLocalisamfile& clifo = *app->get_relation()->lfile(LF_CLIFO) ;
|
|
|
|
if ( f.get().not_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 TFixed_string s = clifo.get(CLI_CODCF);
|
|
const TFixed_string s1(msk.get(F_CODCF));
|
|
|
|
if (clifo.good() && (t1 != t || s1 != s))
|
|
{
|
|
f.yesno_box("Codice fiscale gia' utilizzato per il codice : %c/%s",
|
|
t, (const char*) s);
|
|
return FALSE;
|
|
}
|
|
}
|
|
return TRUE ;
|
|
}
|
|
|
|
HIDDEN bool no_dup_iva(TMask_field& f, KEY key)
|
|
{
|
|
TMask& msk = f.mask() ;
|
|
|
|
if (msk.query_mode() || !f.to_check(key)) return TRUE;
|
|
|
|
CG0200_application* app = (CG0200_application*) MainApp();
|
|
TLocalisamfile& clifo = *app->get_relation()->lfile(LF_CLIFO) ;
|
|
|
|
if ( f.get().not_empty() && !clifo.empty() )
|
|
{
|
|
clifo.zero() ;
|
|
const char t1 = msk.get(F_TIPOCF)[0];
|
|
|
|
clifo.put(CLI_TIPOCF, t1) ;
|
|
clifo.put(CLI_STATOPAIV, msk.get(F_STATOPAIV)) ;
|
|
clifo.put(CLI_PAIV, f.get()) ;
|
|
clifo.setkey(5) ;
|
|
clifo.read() ;
|
|
clifo.setkey(1) ;
|
|
const char t = clifo.get_char(CLI_TIPOCF);
|
|
const TFixed_string s = clifo.get(CLI_CODCF);
|
|
const TFixed_string s1(msk.get(F_CODCF));
|
|
|
|
if (clifo.good() && (t1 != t || s1 != s))
|
|
{
|
|
f.error_box("Partita iva gia' definita per il codice : %c/%s",
|
|
t, (const char*) s);
|
|
return FALSE ;
|
|
}
|
|
}
|
|
return TRUE ;
|
|
}
|
|
|
|
HIDDEN bool autoexit_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
if (f.mask().query_mode())
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
{
|
|
TArray parms;
|
|
parms.add((TString)format("%d", f.dlg()));
|
|
::validate(AUTOEXIT_FUNC, (TEdit_field&) f, key, parms);
|
|
}
|
|
}
|
|
else
|
|
if (f.to_check(key) && f.mask().get(F_ALLEG) != "4")
|
|
{
|
|
if (f.dlg() == F_COFI) return no_dup_fis(f, key);
|
|
else return no_dup_iva(f, key);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
HIDDEN bool lbcn = FALSE;
|
|
|
|
HIDDEN bool tipo_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
TMask& m = f.mask();
|
|
|
|
const bool fis = f.get() == "F";
|
|
|
|
m.send_key(K_SHIFT + K_CTRL + (lbcn && fis ? 's' : 'h'), -5);
|
|
return TRUE;
|
|
}
|
|
|
|
HIDDEN bool percip_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
TMask& m = f.mask();
|
|
|
|
|
|
if (f.to_check(key) && m.get(F_CODANAGPER).not_empty())
|
|
{
|
|
TLocalisamfile anag(LF_ANAG);
|
|
TString c(m.get(F_COFI)), p(m.get(F_PAIV));
|
|
|
|
if ((c.not_empty() && c != anag.get(ANA_COFI)) ||
|
|
(p.not_empty() && p != anag.get(ANA_PAIV))) return error_box("Percipiente non corretto");
|
|
TString r(anag.get(ANA_RAGSOC));
|
|
if (m.get(F_RAGSOC).empty() ||
|
|
(key == K_TAB && yesno_box("Ragione sociale differente correggo in %s", (const char*) r)))
|
|
m.set(F_RAGSOC, r, 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")
|
|
{
|
|
m.send_key(K_SHIFT + K_CTRL + (lbcn ? 's' : 'h'), -5);
|
|
if (lbcn)
|
|
{
|
|
TLocalisamfile fis(LF_ANAGFIS);
|
|
|
|
fis.zero();
|
|
fis.put(ANF_CODANAGR, anag.get(ANA_CODANAGR));
|
|
fis.read();
|
|
if (fis.good())
|
|
{
|
|
if (m.get(F_DATANASC).empty()) m.set(F_DATANASC, fis.get(ANF_DATANASC));
|
|
if (m.get(F_COMNASC).empty())
|
|
{
|
|
m.set(F_STATONASC, fis.get(ANF_STATONASC));
|
|
m.set(F_COMNASC, fis.get(ANF_COMNASC));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
HIDDEN bool alleg_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
const int tipoall = atoi(f.get());
|
|
TMask& m = f.mask();
|
|
|
|
if (tipoall == 0 || tipoall == 4) m.enable(F_CODALLEG);
|
|
else
|
|
{
|
|
m.disable(F_CODALLEG);
|
|
m.reset(F_CODALLEG);
|
|
}
|
|
m.set(F_OCCASIONALE, (tipoall == 2) ? "X" : " ");
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
HIDDEN bool occas_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
const bool occas = f.get().not_empty();
|
|
TMask& m = f.mask();
|
|
|
|
if (occas) m.set(F_ALLEG, "2");
|
|
else
|
|
if (m.get_int(F_ALLEG) == 2) m.set(F_ALLEG, " ");
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
HIDDEN bool codalleg_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
const TString cod(f.get());
|
|
|
|
if (cod.not_empty())
|
|
{
|
|
TMask& m = f.mask();
|
|
|
|
if (cod == m.get(F_TIPOCF))
|
|
return error_box("Codice per allegato non corretto");
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
const TString tipo(m.get(F_TIPOCF));
|
|
|
|
clifo.zero() ;
|
|
clifo.setkey(1) ;
|
|
clifo.put(CLI_TIPOCF, tipo);
|
|
clifo.put(CLI_CODCF, cod);
|
|
clifo.read() ;
|
|
if (clifo.bad()) return FALSE;
|
|
TString tipoall(clifo.get(CLI_ALLEG));
|
|
if (clifo.get(CLI_CODALLEG).not_empty() ||
|
|
clifo.get(CLI_PAIV).empty() ||
|
|
(tipoall.not_empty() && tipoall != "4"))
|
|
return error_box("Codice per allegato non corretto");
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CG0200_application::init_query_mode(TMask& m)
|
|
|
|
{
|
|
TConfig conf(CONFIG_DITTA, "cg");
|
|
|
|
lbcn = (conf.get("GsLbCn") == "X");
|
|
m.send_key(K_SHIFT + K_CTRL + (lbcn ? 's' : 'h'), -5);
|
|
// Se non e' abilitata la gestione delle vendite disabilita le
|
|
// maschere dalla 4 in poi
|
|
|
|
if (!gest_vend())
|
|
{
|
|
for (int j=3; j<8;j++)
|
|
m.disable_page(j);
|
|
// for (int i=F_CODINDDOC; i<= F_SHEET_G_VEN; i++)
|
|
// m.disable(i);
|
|
}
|
|
else
|
|
{
|
|
for (int j=3; j<8;j++)
|
|
m.enable_page(j);
|
|
// for (int i=F_CODINDDOC; i<= F_SHEET_G_VEN; i++)
|
|
// m.enable(i);
|
|
}
|
|
}
|
|
|
|
int CG0200_application::read(TMask& m)
|
|
{
|
|
m.autoload(_rel);
|
|
indsp_sheet().reset();
|
|
TToken_string riga(240);
|
|
for (int i=0; i< _rel->indirizzi_items();i++)
|
|
{
|
|
TRectype& rec=_rel->indirizzo(i);
|
|
riga.cut(0);
|
|
riga.add(rec.get("RAGSOC"));
|
|
riga.add(rec.get("INDIR"));
|
|
riga.add(rec.get("CIV"));
|
|
riga.add(rec.get("LOCALITA"));
|
|
riga.add(rec.get("CAP"));
|
|
riga.add(rec.get("STATO"));
|
|
riga.add(rec.get("COM"));
|
|
riga.add(rec.get("PTEL"));
|
|
riga.add(rec.get("TEL"));
|
|
riga.add(rec.get("PFAX"));
|
|
riga.add(rec.get("FAX"));
|
|
riga.add(rec.get("IVARID"));
|
|
riga.add(rec.get("CODIND"));
|
|
indsp_sheet().row(i)=riga;
|
|
}
|
|
return _rel->status();
|
|
}
|
|
|
|
int CG0200_application::rewrite(const TMask& m)
|
|
{
|
|
common_f(m);
|
|
return _rel->rewrite(TRUE);
|
|
}
|
|
|
|
int CG0200_application::write(const TMask& m)
|
|
{
|
|
common_f(m);
|
|
return _rel->write(TRUE);
|
|
}
|
|
|
|
TSheet_field& CG0200_application::indsp_sheet() const
|
|
{
|
|
TSheet_field& o_sheet=(TSheet_field&) _msk->field(F_SHEET_G_VEN);
|
|
return o_sheet;
|
|
}
|
|
|
|
void CG0200_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 CG0200_application::common_f(const TMask& m)
|
|
{
|
|
char tipocf = m.get(F_TIPOCF)[0];
|
|
long codcf = m.get_long(F_CODCF);
|
|
_rel->lfile()->zero();
|
|
m.autosave(_rel);
|
|
_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);
|
|
rec.zero();
|
|
rec.put("TIPOCF",tipocf);
|
|
rec.put("CODCF",codcf);
|
|
rec.put("RAGSOC",row.get());
|
|
rec.put("INDIR",row.get());
|
|
rec.put("CIV",row.get());
|
|
rec.put("LOCALITA",row.get());
|
|
rec.put("CAP",row.get());
|
|
rec.put("STATO",atoi(row.get()));
|
|
rec.put("COM",row.get());
|
|
rec.put("PTEL",row.get());
|
|
rec.put("TEL",row.get());
|
|
rec.put("PFAX",row.get());
|
|
rec.put("FAX",row.get());
|
|
rec.put("IVARID",row.get());
|
|
rec.put("CODIND",i+1);
|
|
}
|
|
}
|
|
|
|
bool CG0200_application::indsp_notify(int r, KEY key)
|
|
{
|
|
TSheet_field& indsp=app().indsp_sheet();
|
|
|
|
switch (key)
|
|
{
|
|
case K_SPACE:
|
|
{
|
|
// Request to modify row #r
|
|
// Disable field # 101 (CODIND) update # of row
|
|
TMask& m = indsp.sheet_mask();
|
|
|
|
if (m.get_int(114)==0) // Is it a new row ?
|
|
m.set(114,(long)(r+1));
|
|
m.disable(114);
|
|
}
|
|
break;
|
|
case K_INS:
|
|
// request to add the row #r
|
|
// To avoid rewriting of existing record.
|
|
if (indsp.items() >= 999)
|
|
{
|
|
error_box("Raggiunto il numero massimo degli indirizzi per questo C/F");
|
|
return FALSE; // Refuse Permission
|
|
} else
|
|
// To avoid inserts in the middle of the sheet
|
|
if (indsp.items()>r)
|
|
{
|
|
error_box("Si possono aggiungere indirizzi solo alla fine");
|
|
return FALSE; //Refuse permission
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool CG0200_application::user_create() // initvar e arrmask
|
|
{
|
|
|
|
_rel = new TClifoVI;
|
|
|
|
_saldi = new TLocalisamfile(LF_SALDI);
|
|
_anag = new TLocalisamfile(LF_ANAG);
|
|
_fis = new TLocalisamfile(LF_ANAGFIS);
|
|
_pcon = new TLocalisamfile(LF_PCON);
|
|
_comuni = new TLocalisamfile(LF_COMUNI);
|
|
_msk = new TMask("cg0200a") ;
|
|
_msk->set_handler(F_OCCASIONALE, occas_handler);
|
|
_msk->set_handler(F_COFI, autoexit_handler);
|
|
_msk->set_handler(F_PAIV, autoexit_handler);
|
|
_msk->set_handler(F_CODANAGPER, percip_handler);
|
|
_msk->set_handler(F_TIPOPERS, tipo_handler);
|
|
_msk->set_handler(F_ALLEG, alleg_handler);
|
|
_msk->set_handler(F_CODALLEG, codalleg_handler);
|
|
|
|
_msk->set_handler(F_SHEET_G_VEN, indsp_handler);
|
|
|
|
TSheet_field& ind = (TSheet_field&) _msk->field(F_SHEET_G_VEN);
|
|
ind.set_notify(indsp_notify);
|
|
|
|
_saldi->setkey(2);
|
|
return TRUE;
|
|
}
|
|
|
|
bool CG0200_application::user_destroy() // releasev e arrmask
|
|
{
|
|
delete _msk;
|
|
delete _rel;
|
|
delete _saldi;
|
|
delete _anag;
|
|
delete _fis;
|
|
delete _pcon;
|
|
delete _comuni;
|
|
return TRUE;
|
|
}
|
|
|
|
int cg0200(int argc, char* argv[])
|
|
{
|
|
CG0200_application a ;
|
|
a.run(argc, argv, "Clienti/Fornitori");
|
|
return 0;
|
|
}
|