1115 lines
29 KiB
C++
1115 lines
29 KiB
C++
|
// cg0500.cpp - Tabella causali
|
||
|
|
||
|
#include <applicat.h>
|
||
|
#include <msksheet.h>
|
||
|
#include <relapp.h>
|
||
|
#include <tabutil.h>
|
||
|
#include <config.h>
|
||
|
#include <utility.h>
|
||
|
|
||
|
#include <clifo.h>
|
||
|
#include <pconti.h>
|
||
|
#include <causali.h>
|
||
|
#include <rcausali.h>
|
||
|
|
||
|
#include "cglib.h"
|
||
|
#include "cg0501.h"
|
||
|
#include "cg0500.h"
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
// Funzioni legate ai parametri ditta
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
HIDDEN bool salda_conto()
|
||
|
{
|
||
|
static bool _saldaconto = 2;
|
||
|
|
||
|
if (_saldaconto == 2)
|
||
|
{
|
||
|
TConfig conf(CONFIG_DITTA);
|
||
|
_saldaconto = conf.get_bool("GesSal");
|
||
|
}
|
||
|
return _saldaconto;
|
||
|
}
|
||
|
|
||
|
HIDDEN bool gestione_valuta()
|
||
|
{
|
||
|
static bool _gest_val = 2;
|
||
|
|
||
|
if (_gest_val == 2)
|
||
|
{
|
||
|
TConfig conf(CONFIG_DITTA);
|
||
|
_gest_val = conf.get_bool("GesVal");
|
||
|
}
|
||
|
return _gest_val;
|
||
|
}
|
||
|
|
||
|
HIDDEN int anno_iva()
|
||
|
{
|
||
|
static int _anno_iva = 0;
|
||
|
if (_anno_iva == 0)
|
||
|
{
|
||
|
TConfig conf(CONFIG_DITTA);
|
||
|
_anno_iva = (int)conf.get_long("AnLiIv", "cg");
|
||
|
if (_anno_iva < 1900)
|
||
|
{
|
||
|
_anno_iva = TDate(TODAY).year();
|
||
|
error_box("Anno liquidazione IVA non specificato: assumo %d", _anno_iva);
|
||
|
}
|
||
|
}
|
||
|
return _anno_iva;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
// Le righe di causale:
|
||
|
// Righe_rcaus e' un array di Riga_rcaus
|
||
|
// Riga_rcaus e' una token_string corrispondente ad una riga dello spreadsheet
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
class Riga_rcaus : public TToken_string
|
||
|
{
|
||
|
public:
|
||
|
const TString& operator = (const TString& s)
|
||
|
{return TToken_string::operator=(s);}
|
||
|
|
||
|
Riga_rcaus (TConto& tc, // il conto
|
||
|
const char *df="", // descrizione fissa
|
||
|
char tipocf=' ', // tipo C/F
|
||
|
char sezione=' ', // dare/avere
|
||
|
const char * des="", // descrizione del conto
|
||
|
const char * desagg="", // codice descr. aggiuntiva
|
||
|
bool rigaiva=' ', // se e' una riga iva
|
||
|
const char * codiva=""); // codice iva
|
||
|
};
|
||
|
|
||
|
Riga_rcaus::Riga_rcaus (TConto& tc,const char * df, char tipocf, char sez,
|
||
|
const char * des, const char * desagg,
|
||
|
bool rigaiva, const char * codiva)
|
||
|
: TToken_string(80)
|
||
|
{
|
||
|
add(df);
|
||
|
// add(tc.tipo());
|
||
|
add(tipocf);
|
||
|
if (tc.ok())
|
||
|
{
|
||
|
add((long)tc.gruppo());
|
||
|
add((long)tc.conto());
|
||
|
add((long)tc.sottoconto());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
add("");
|
||
|
add("");
|
||
|
add("");
|
||
|
}
|
||
|
add(sez);
|
||
|
add(des);
|
||
|
add(desagg);
|
||
|
add((char)rigaiva);
|
||
|
add(codiva);
|
||
|
}
|
||
|
|
||
|
class TRighe_rcaus : public TArray
|
||
|
{
|
||
|
public:
|
||
|
void set_descr (int numrig=-1, const char * descr="", char tipocf=' ');
|
||
|
void add_riga(int numrig, const char * dfi, char tipocf,
|
||
|
char sezione, const char * des, const char * desagg,
|
||
|
bool rigaiva, const char * codiva, TConto& tc );
|
||
|
|
||
|
void carica_descr_0 ();
|
||
|
void carica_descr_1 ();
|
||
|
void carica_descr_2 ();
|
||
|
void carica_descr_tpr1 ();
|
||
|
void carica_descr_tpr2 ();
|
||
|
TRighe_rcaus() : TArray(20) {}
|
||
|
};
|
||
|
|
||
|
void TRighe_rcaus::add_riga(int i, const char * dfi, char tipocf,
|
||
|
char sez, const char * des, const char * desagg, bool rigaiva,
|
||
|
const char * codiva, TConto& tc)
|
||
|
{
|
||
|
Riga_rcaus *r = (Riga_rcaus*)objptr(i);
|
||
|
// TString df(20), d(50), da(4), civa(3);
|
||
|
int g=0,c=0;
|
||
|
long s=0L;
|
||
|
// char sz=' ', cf=' ';
|
||
|
// bool riva;
|
||
|
|
||
|
if (r == NULL)
|
||
|
{
|
||
|
r = new Riga_rcaus (tc,dfi,tipocf,sez,des,desagg,rigaiva,codiva);
|
||
|
add(r,i); // ???
|
||
|
}
|
||
|
// else
|
||
|
// {
|
||
|
// if (tc.ok())
|
||
|
// {
|
||
|
g = tc.gruppo();
|
||
|
c = tc.conto();
|
||
|
s = tc.sottoconto();
|
||
|
// }
|
||
|
|
||
|
(*r)="";
|
||
|
r->add(dfi);
|
||
|
r->add(tipocf);
|
||
|
r->add((long)g);
|
||
|
r->add((long)c);
|
||
|
r->add((long)s);
|
||
|
r->add(sez);
|
||
|
r->add(des);
|
||
|
r->add(desagg);
|
||
|
r->add(rigaiva ? "X" : "");
|
||
|
r->add(codiva);
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
void TRighe_rcaus::set_descr(int i, const char * dfi, char tipocf)
|
||
|
{
|
||
|
Riga_rcaus *r = (Riga_rcaus*)objptr(i);
|
||
|
TConto tc;
|
||
|
|
||
|
if (r == NULL)
|
||
|
{
|
||
|
r = new Riga_rcaus (tc,dfi,tipocf);
|
||
|
add(r,i);
|
||
|
}
|
||
|
r->add(dfi, 0);
|
||
|
r->add(tipocf, 1);
|
||
|
}
|
||
|
|
||
|
bool filtra_reg(const TRelation * r);
|
||
|
|
||
|
class CG0500_application : public TRelation_application
|
||
|
{
|
||
|
int _filtro; // tipo di filtro su tab. reg.
|
||
|
// 1 vendite senza corrisp
|
||
|
// 2 vendite con corrisp
|
||
|
// 3 acquisti
|
||
|
|
||
|
friend bool filtra_reg(const TRelation * r);
|
||
|
|
||
|
// static bool conto_hndl (TMask_field& f, KEY k);
|
||
|
static bool sottoconto_hndl (TMask_field& f, KEY k);
|
||
|
static bool tipocf_hndl (TMask_field& f, KEY k);
|
||
|
// static bool m770_hndl (TMask_field& f, KEY k);
|
||
|
static bool cod_reg_hndl (TMask_field& f, KEY k);
|
||
|
static bool tipodoc_hndl (TMask_field& f, KEY k);
|
||
|
static bool tipomov_hndl (TMask_field& f, KEY k);
|
||
|
// static bool codcausim_hndl (TMask_field& f, KEY k);
|
||
|
static bool leggi_riga (int r, KEY k);
|
||
|
|
||
|
TRelation * _rel;
|
||
|
TMask * _msk;
|
||
|
int _mode; // Modo maschera corrente
|
||
|
int _items;
|
||
|
TRighe_rcaus _righe_rcaus;
|
||
|
TBit_array _righe_gia_presenti;
|
||
|
|
||
|
void togli_dal_file(const TString&);
|
||
|
|
||
|
void compila_righe_rcaus (const TString&, int, int, int);
|
||
|
void read_rcaus(TMask&);
|
||
|
bool carica_descr(TMask&);
|
||
|
bool fill_sheet(TMask&);
|
||
|
static bool has_iva (const char * tpc);
|
||
|
bool is_clifo(const char * tpc);
|
||
|
|
||
|
protected:
|
||
|
virtual bool user_create();
|
||
|
virtual bool user_destroy();
|
||
|
|
||
|
virtual TRelation* get_relation() const { return _rel; }
|
||
|
virtual TMask* get_mask(int mode);
|
||
|
virtual bool changing_mask(int mode) {return FALSE; }
|
||
|
virtual bool remove();
|
||
|
|
||
|
void init_mask(TMask&);
|
||
|
virtual void init_query_mode(TMask&);
|
||
|
virtual void init_insert_mode(TMask&);
|
||
|
virtual void init_modify_mode(TMask&);
|
||
|
virtual int rewrite(const TMask& m);
|
||
|
virtual int write(const TMask& m);
|
||
|
virtual int read(TMask& m);
|
||
|
// int cancella(long items);
|
||
|
|
||
|
public:
|
||
|
int _riga;
|
||
|
TMask * main_mask() { return _msk; }
|
||
|
CG0500_application() {}
|
||
|
};
|
||
|
|
||
|
HIDDEN CG0500_application * app() { return (CG0500_application*) MainApp(); }
|
||
|
|
||
|
// Per sapere su che riga sono dello spreadsheet. v. set_notify piu' sotto
|
||
|
bool CG0500_application::leggi_riga(int r, KEY k)
|
||
|
{
|
||
|
if (k == K_SPACE)
|
||
|
app()->_riga = r;
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool filtra_reg(const TRelation * r)
|
||
|
{
|
||
|
const TString codtab(r->lfile()->get("CODTAB"));
|
||
|
int tiporeg = r->lfile()->get_int("I0");
|
||
|
bool corrisp = r->lfile()->get_bool("B0");
|
||
|
|
||
|
const int anno = atoi(codtab.left(4));
|
||
|
|
||
|
switch (app()->_filtro)
|
||
|
{
|
||
|
case 1:
|
||
|
if (anno == anno_iva() && tiporeg == 1 && !corrisp)
|
||
|
return TRUE;
|
||
|
break;
|
||
|
case 2:
|
||
|
if (anno == anno_iva() && tiporeg == 1 && corrisp)
|
||
|
return TRUE;
|
||
|
break;
|
||
|
case 3:
|
||
|
if (anno == anno_iva() && tiporeg == 2)
|
||
|
return TRUE;
|
||
|
break;
|
||
|
case 4: // tiporeg 1 senza corrisp OPPURE 2 (NC ST ND AF)
|
||
|
if (anno == anno_iva())
|
||
|
if ( (tiporeg == 1 && !corrisp) || tiporeg == 2 )
|
||
|
return TRUE;
|
||
|
break;
|
||
|
default:
|
||
|
return FALSE;
|
||
|
}
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
TMask* CG0500_application::get_mask(int mode)
|
||
|
{
|
||
|
return _msk;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::has_iva (const char * tpconto)
|
||
|
{
|
||
|
TFixed_string tpc(tpconto);
|
||
|
|
||
|
// Lascio abilitato codiva e rigaiva solo per i conti senza descr.fissa
|
||
|
if (tpc.trim().empty())
|
||
|
return TRUE;
|
||
|
else
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::is_clifo (const char * tpconto)
|
||
|
{
|
||
|
TFixed_string tpc(tpconto);
|
||
|
if ( (tpc == "C Clienti/Fornitori") || (tpc == "C Clienti") ||
|
||
|
(tpc == "C Fornitori") )
|
||
|
return TRUE;
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
// Handler
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
bool CG0500_application::cod_reg_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (k == K_TAB && f.focusdirty())
|
||
|
app()->fill_sheet(f.mask());
|
||
|
|
||
|
// controllo di consistenza tra codice (tipo) registro e tipo documento
|
||
|
if (k == K_ENTER && f.dirty())
|
||
|
{
|
||
|
bool ok = TRUE;
|
||
|
|
||
|
const TString16 tpd = f.mask().get(F_TIPO_DOC);
|
||
|
const int tipo = f.mask().get_int(F_TIPO_REG);
|
||
|
const bool corrisp = f.mask().get_bool(F_CORRISP);
|
||
|
|
||
|
// con tipo=1 e corrisp=""
|
||
|
if (tpd == "FV" || tpd == "FS" || tpd == "FS")
|
||
|
{
|
||
|
if (tipo != 1 || corrisp) ok = FALSE;
|
||
|
} else
|
||
|
|
||
|
// con tipo=1 e corrisp="X"
|
||
|
if (tpd == "CN" || tpd == "RN" || tpd == "CR" ||
|
||
|
tpd == "SC" || tpd == "RF" || tpd == "SN")
|
||
|
{
|
||
|
if (tipo != 1 || !corrisp) ok = FALSE;
|
||
|
} else
|
||
|
// Possono essere 1 o 2
|
||
|
if (tpd == "NC" || tpd == "ST" || tpd == "ND" ||
|
||
|
tpd == "AF")
|
||
|
{
|
||
|
if (tipo != 1 && tipo != 2) ok = FALSE;
|
||
|
} else
|
||
|
|
||
|
// con tipo=2
|
||
|
if (tpd == "FA" || tpd == "BD")
|
||
|
{
|
||
|
if (tipo != 2) ok = FALSE;
|
||
|
}
|
||
|
|
||
|
if (!ok)
|
||
|
return f.warning_box("Il registro (tipo %d) non e' compatibile con il tipo di documento (%s)",
|
||
|
tipo, (const char*)tpd);
|
||
|
}
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
/* ???
|
||
|
bool CG0500_application::m770_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (k == K_TAB && f.focusdirty())
|
||
|
app()->fill_sheet(f.mask());
|
||
|
return TRUE;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
/*******************
|
||
|
15/07/94 se compilo conto o sottoconto metto REQUIRED in DARE/AVERE
|
||
|
21/07/94 Metto REQUIRED fisso nel .uml perche' g-c-s ci saranno sempre
|
||
|
bool CG0500_application::conto_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (f.to_check(k))
|
||
|
{
|
||
|
const TString val(f.get());
|
||
|
TEdit_field& sezione = (TEdit_field&)f.mask().field(106);
|
||
|
|
||
|
if (val.not_empty())
|
||
|
sezione.check_type(CHECK_REQUIRED);
|
||
|
else
|
||
|
sezione.check_type(CHECK_NONE);
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
*******************/
|
||
|
|
||
|
// Handler del campo sottoconto C/F (205) della maschera di edit dello sheet
|
||
|
// controlla se il tipocf del g-c-s corrisponde al tipo inserito
|
||
|
// (nel campo 102)
|
||
|
bool CG0500_application::sottoconto_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (k == K_TAB)
|
||
|
{
|
||
|
const int tpr = app()->main_mask()->get_int(F_TIPO_REG);
|
||
|
// se sono sulla prima riga e acquisti o vendite
|
||
|
if (app()->_riga == 0 && (tpr == 1 || tpr == 2) )
|
||
|
{
|
||
|
int g = f.mask().get_int(103);
|
||
|
int c = f.mask().get_int(104);
|
||
|
|
||
|
if (g != 0 || c != 0)
|
||
|
{
|
||
|
f.mask().disable(103);
|
||
|
f.mask().disable(104);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
f.mask().enable(103);
|
||
|
f.mask().enable(104);
|
||
|
}
|
||
|
}
|
||
|
/*
|
||
|
int g = f.mask().get_int(103);
|
||
|
int c = f.mask().get_int(104);
|
||
|
long s = f.mask().get_long(105);
|
||
|
TString tipocf = f.mask().get(102);
|
||
|
|
||
|
TConto tc(g,c,s);
|
||
|
|
||
|
if (tipocf != tc.tipo())
|
||
|
return f.warning_box("Il tipo C/F non corrisponde a quello del conto");
|
||
|
*/
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
// Handler del campo tipocf ? della maschera di edit dello sheet
|
||
|
// 106 e' la sezione dare o avere
|
||
|
// 105 e' il sottoconto
|
||
|
// 205 e' il sottoconto in caso di C/F
|
||
|
bool CG0500_application::tipocf_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
// TFixed_string tpc(f.mask().get(101));
|
||
|
|
||
|
if (k == K_SPACE)
|
||
|
{
|
||
|
const int tpr = app()->main_mask()->get_int(F_TIPO_REG);
|
||
|
|
||
|
// 109 e 110 sono rigaiva e codiva
|
||
|
if (tpr == 1 || tpr == 2)
|
||
|
{
|
||
|
f.mask().enable(109); f.mask().enable(110);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
f.mask().disable(109); f.mask().disable(110);
|
||
|
}
|
||
|
|
||
|
// se sono sulla prima riga e acquisti o vendite
|
||
|
// servira' a qualcosa ? boh ?
|
||
|
if (app()->_riga == 0)
|
||
|
{
|
||
|
if (tpr == 1) // VENDITE => C
|
||
|
{
|
||
|
f.mask().hide(105);
|
||
|
f.mask().hide(305);
|
||
|
f.mask().show(205);
|
||
|
return TRUE;
|
||
|
}
|
||
|
else
|
||
|
if (tpr == 2) // ACQUISTI => F
|
||
|
{
|
||
|
f.mask().hide(105);
|
||
|
f.mask().hide(205);
|
||
|
f.mask().show(305);
|
||
|
return TRUE;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*** Questo lo ri-faccio fare nel .uml
|
||
|
const TString cf(f.get());
|
||
|
|
||
|
if (cf == "C")
|
||
|
{
|
||
|
f.mask().hide(105);
|
||
|
f.mask().hide(305);
|
||
|
f.mask().show(205);
|
||
|
}
|
||
|
else
|
||
|
if (cf == "F")
|
||
|
{
|
||
|
f.mask().hide(105);
|
||
|
f.mask().hide(205);
|
||
|
f.mask().show(305);
|
||
|
}
|
||
|
else // TIPOCF VUOTO
|
||
|
{
|
||
|
f.mask().hide(205);
|
||
|
f.mask().hide(305);
|
||
|
f.mask().show(105);
|
||
|
return TRUE;
|
||
|
}
|
||
|
*********************/
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool CG0500_application::tipodoc_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (k == K_TAB && f.focusdirty())
|
||
|
{
|
||
|
const TString16 val(f.get());
|
||
|
const int tpm = f.mask().get_int(F_TIPO_MOV);
|
||
|
|
||
|
TEdit_field& field_reg = (TEdit_field&)f.mask().field(F_COD_REG);
|
||
|
|
||
|
if (val.not_empty())
|
||
|
{
|
||
|
f.mask().hide(F_OP_FINE_ANNO);
|
||
|
f.mask().enable(F_COD_REG);
|
||
|
field_reg.check_type(CHECK_REQUIRED);
|
||
|
|
||
|
// Cambio il filtro sui registri
|
||
|
// con tipo=1 e corrisp=""
|
||
|
if (val == "FV" || val == "FF" || val == "FS")
|
||
|
{
|
||
|
app()->_filtro = 1;
|
||
|
field_reg.browse()->cursor()->set_filterfunction(filtra_reg);
|
||
|
|
||
|
// TString filt(format("CODTAB[1,4]=%s && I0=1 && B0=\"\"",
|
||
|
// (const char *)an_iva));
|
||
|
// field_reg.browse()->cursor()->filter(filt);
|
||
|
}
|
||
|
|
||
|
// con tipo=1 e corrisp="X"
|
||
|
if (val == "CN" || val == "RN" || val == "CR" ||
|
||
|
val == "SC" || val == "RF" || val == "SN")
|
||
|
{
|
||
|
app()->_filtro = 2;
|
||
|
field_reg.browse()->cursor()->set_filterfunction(filtra_reg);
|
||
|
}
|
||
|
// Possono essere 1 o 2
|
||
|
if (val == "NC" || val == "ST" || val == "ND" ||
|
||
|
val == "AF")
|
||
|
{
|
||
|
app()->_filtro = 4;
|
||
|
field_reg.browse()->cursor()->set_filterfunction(filtra_reg);
|
||
|
}
|
||
|
|
||
|
// con tipo=2
|
||
|
if (val == "FA" || val == "BD")
|
||
|
{
|
||
|
app()->_filtro = 3;
|
||
|
field_reg.browse()->cursor()->set_filterfunction(filtra_reg);
|
||
|
}
|
||
|
f.mask().hide(F_TIPO_MOV_2);
|
||
|
f.mask().show(F_TIPO_MOV_1);
|
||
|
|
||
|
f.mask().show(F_AUTO_FAT);
|
||
|
f.mask().show(F_OP_INTRACOM);
|
||
|
f.mask().show(F_ALLEGAT);
|
||
|
f.mask().show(F_FAT_RITARDO);
|
||
|
f.mask().show(F_COD_CAUS_IM);
|
||
|
f.mask().show(F_MOV_VALU);
|
||
|
f.mask().show(F_MOV_SEZ);
|
||
|
f.mask().show(F_M_770);
|
||
|
f.mask().show(F_OP_FINE_ANNO);
|
||
|
|
||
|
}
|
||
|
else // tipodoc vuoto
|
||
|
{
|
||
|
// Devo poter rivedere tutti i registri se ho cancellato il campo TIPODOC
|
||
|
field_reg.check_type(CHECK_NORMAL);
|
||
|
|
||
|
if ( !salda_conto() || tpm == 0 )
|
||
|
f.mask().show(F_OP_FINE_ANNO);
|
||
|
else
|
||
|
f.mask().hide(F_OP_FINE_ANNO);
|
||
|
|
||
|
f.mask().set(F_COD_REG,"");
|
||
|
f.mask().disable(F_COD_REG);
|
||
|
f.mask().hide(F_TIPO_MOV_1);
|
||
|
f.mask().show(F_TIPO_MOV_2);
|
||
|
|
||
|
f.mask().hide(F_AUTO_FAT);
|
||
|
f.mask().hide(F_OP_INTRACOM);
|
||
|
f.mask().hide(F_ALLEGAT);
|
||
|
f.mask().hide(F_FAT_RITARDO);
|
||
|
f.mask().hide(F_COD_CAUS_IM);
|
||
|
f.mask().hide(F_MOV_VALU);
|
||
|
f.mask().hide(F_MOV_SEZ);
|
||
|
|
||
|
if (tpm > 0) // tipomov != nessuno
|
||
|
{
|
||
|
f.mask().hide(F_M_770);
|
||
|
f.mask().hide(F_OP_FINE_ANNO);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
f.mask().show(F_M_770);
|
||
|
f.mask().show(F_OP_FINE_ANNO);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
app()->fill_sheet(f.mask());
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::tipomov_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (f.to_check(k))
|
||
|
{
|
||
|
const int tpm = atoi(f.get());
|
||
|
if (tpm > 0)
|
||
|
{
|
||
|
if ( (tpm == 3) || (tpm == 5) || (tpm == 6) )
|
||
|
f.mask().enable(F_MOV_SEZ);
|
||
|
else
|
||
|
f.mask().disable(F_MOV_SEZ);
|
||
|
}
|
||
|
if (k == K_TAB)
|
||
|
app()->fill_sheet(f.mask());
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
/* ??? CLEAR da maschera
|
||
|
bool CG0500_application::codcausim_hndl (TMask_field& f, KEY k)
|
||
|
{
|
||
|
if (f.to_check(k))
|
||
|
{
|
||
|
const int m770 = f.mask().get_int(F_M_770);
|
||
|
if (m770 > 0)
|
||
|
return f.error_box ("Il codice causale per l'incasso immediato puo' essere indicato solo se non c'e' il collegamento Mod.770");
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
////////////////////////////////////////////////////////////////////////////
|
||
|
// Registro vendite prima riga tipocf = "C" le altre fisso a BLANK
|
||
|
void TRighe_rcaus::carica_descr_tpr1()
|
||
|
{
|
||
|
int i=0;
|
||
|
TConto tc();
|
||
|
set_descr(i++, "C Clienti", 'C');
|
||
|
set_descr(i++, "C Di ricavo", ' ');
|
||
|
set_descr(i++, "C Iva vendite", ' ');
|
||
|
set_descr(i++, "C Iva non detraibile", ' ');
|
||
|
set_descr(i++, "C Imp. esenti", ' ');
|
||
|
set_descr(i++, "C Imp. non imponibili", ' ');
|
||
|
set_descr(i++, "C Imp. non soggetti", ' ');
|
||
|
set_descr(i++, "C Ritenute fiscali", ' ');
|
||
|
set_descr(i++, "C Ritenute soc.", ' ');
|
||
|
carica_descr_0();
|
||
|
}
|
||
|
|
||
|
// Registro ACQUISTI prima riga tipocf = "F" le altre fisso a BLANK
|
||
|
void TRighe_rcaus::carica_descr_tpr2()
|
||
|
{
|
||
|
int i=0;
|
||
|
set_descr( i++, "C Fornitori", 'F');
|
||
|
set_descr(i++, "C Di costo", ' ');
|
||
|
set_descr(i++, "C Iva acquisti", ' ');
|
||
|
set_descr(i++, "C Iva non detraibile", ' ');
|
||
|
set_descr(i++, "C Imp. esenti", ' ');
|
||
|
set_descr(i++, "C Imp. non imponibili", ' ');
|
||
|
set_descr(i++, "C Imp. non soggetti", ' ');
|
||
|
set_descr(i++, "C Ritenute fiscali", ' ');
|
||
|
set_descr(i++, "C Ritenute soc.", ' ');
|
||
|
carica_descr_0();
|
||
|
}
|
||
|
|
||
|
void TRighe_rcaus::carica_descr_2()
|
||
|
{
|
||
|
int i=0;
|
||
|
set_descr (i++, "Costo");
|
||
|
set_descr (i++, "Cassa/banca");
|
||
|
set_descr (i++, "Erario");
|
||
|
carica_descr_0();
|
||
|
}
|
||
|
|
||
|
void TRighe_rcaus::carica_descr_0()
|
||
|
{
|
||
|
for (int i = items(); i < 20; i++)
|
||
|
set_descr(i);
|
||
|
}
|
||
|
|
||
|
void TRighe_rcaus::carica_descr_1()
|
||
|
{
|
||
|
int i=0;
|
||
|
set_descr ( i++, "C Clienti/Fornitori");
|
||
|
set_descr ( i++, "C Cassa o banca");
|
||
|
set_descr ( i++, "C Tratta");
|
||
|
set_descr ( i++, "C Ricevuta bancaria");
|
||
|
set_descr ( i++, "C Cessione");
|
||
|
set_descr ( i++, "C Paghero'");
|
||
|
set_descr ( i++, "C Lettera di credito");
|
||
|
set_descr ( i++, "C Abb. pass/sc.");
|
||
|
set_descr ( i++, "C Abb. att/sc.");
|
||
|
set_descr ( i++, "C Spese e rimborsi");
|
||
|
set_descr ( i++, "C Ritenute fiscali");
|
||
|
if (gestione_valuta())
|
||
|
set_descr (i++, "C Differenza cambio");
|
||
|
carica_descr_0();
|
||
|
}
|
||
|
|
||
|
void CG0500_application::compila_righe_rcaus (const TString& tpd, int tpm, int tpr, int m770)
|
||
|
{
|
||
|
if (tpd.empty())
|
||
|
{
|
||
|
if ( tpm == 3 || tpm == 5 || tpm == 6 )
|
||
|
_righe_rcaus.carica_descr_1();
|
||
|
else
|
||
|
{
|
||
|
if ( !salda_conto() || tpm == 0 )
|
||
|
if (m770 == 6)
|
||
|
{
|
||
|
_righe_rcaus.carica_descr_2();
|
||
|
return;
|
||
|
}
|
||
|
_righe_rcaus.carica_descr_0();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (tpr == 1)
|
||
|
_righe_rcaus.carica_descr_tpr1();
|
||
|
else
|
||
|
if (tpr == 2)
|
||
|
_righe_rcaus.carica_descr_tpr2();
|
||
|
_righe_rcaus.carica_descr_0();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CG0500_application::read_rcaus(TMask& m)
|
||
|
{
|
||
|
int numrig, g, c;
|
||
|
long s;
|
||
|
TString d(50), da(3), civa(3);
|
||
|
char sz, cf;
|
||
|
bool riva;
|
||
|
TLocalisamfile * rcaus = _rel->lfile(LF_RCAUSALI);
|
||
|
|
||
|
_rel->update(); // chiamo position_rels()
|
||
|
|
||
|
_righe_gia_presenti.reset();
|
||
|
_righe_rcaus.destroy();
|
||
|
|
||
|
bool ok = _rel->is_first_match(LF_RCAUSALI);
|
||
|
while (ok)
|
||
|
{
|
||
|
numrig = rcaus->get_int(RCA_NRIGA);
|
||
|
CHECK(numrig > 0, "Causale con numero riga nullo");
|
||
|
g = rcaus->get_int(RCA_GRUPPO);
|
||
|
c = rcaus->get_int(RCA_CONTO);
|
||
|
s = rcaus->get_long(RCA_SOTTOCONTO);
|
||
|
sz = rcaus->get(RCA_SEZIONE)[0];
|
||
|
d = rcaus->get(RCA_DESC);
|
||
|
da = rcaus->get(RCA_CODDESC);
|
||
|
cf = rcaus->get(RCA_TIPOCF)[0];
|
||
|
riva = rcaus->get_bool(RCA_RIGAIVA);
|
||
|
civa = rcaus->get(RCA_CODIVA);
|
||
|
TConto tc(g,c,s,cf);
|
||
|
_righe_rcaus.add_riga(numrig-1, "", cf, sz, d, da, riva, civa, tc);
|
||
|
// g.right_just(3); c.right_just(3); s.right_just(6);
|
||
|
// _righe_rcaus.add_riga(numrig-1,"",g,c,s,sz,d,da,tc,riva,civa);
|
||
|
_righe_gia_presenti.set(numrig);
|
||
|
ok = _rel->next_match(LF_RCAUSALI);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::carica_descr(TMask& m)
|
||
|
{
|
||
|
TLocalisamfile& caus = *_rel->lfile();
|
||
|
TString tpd(caus.get("TIPODOC"));
|
||
|
int tpm = caus.get_int("TIPOMOV");
|
||
|
int m770 = caus.get_int("M770");
|
||
|
|
||
|
TString16 chiave; chiave << anno_iva() << caus.get("REG");
|
||
|
TTable reg("REG");
|
||
|
reg.put("CODTAB", chiave);
|
||
|
reg.read();
|
||
|
int tpr = reg.get_int("I0");
|
||
|
|
||
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_GCS);
|
||
|
|
||
|
compila_righe_rcaus(tpd,tpm,tpr,m770);
|
||
|
|
||
|
_items = _righe_rcaus.items();
|
||
|
|
||
|
cs.reset();
|
||
|
for (int i = 0; i < _items; i++)
|
||
|
{
|
||
|
TToken_string &riga = cs.row(i);
|
||
|
Riga_rcaus* r = (Riga_rcaus*)_righe_rcaus.objptr(i);
|
||
|
if (r != NULL) riga = *r;
|
||
|
else riga.cut(0);
|
||
|
}
|
||
|
cs.force_update();
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::fill_sheet(TMask& m)
|
||
|
{
|
||
|
TString tpd(m.get(F_TIPO_DOC));
|
||
|
int tpm = m.get_int(F_TIPO_MOV);
|
||
|
int tpr = m.get_int(F_TIPO_REG);
|
||
|
int m770 = m.get_int(F_M_770);
|
||
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_GCS);
|
||
|
int i;
|
||
|
|
||
|
/***************
|
||
|
int items=cs.items();
|
||
|
for (i = 0; i < items; i++)
|
||
|
{
|
||
|
TToken_string &riga = cs.row(i);
|
||
|
(Riga_rcaus&)_righe_rcaus[i] = riga;
|
||
|
}
|
||
|
********************/
|
||
|
|
||
|
compila_righe_rcaus(tpd,tpm,tpr,m770);
|
||
|
|
||
|
_items = _righe_rcaus.items();
|
||
|
|
||
|
cs.reset();
|
||
|
|
||
|
for (i = 0; i < _items; i++)
|
||
|
{
|
||
|
TToken_string &riga = cs.row(i);
|
||
|
Riga_rcaus* r = (Riga_rcaus*)_righe_rcaus.objptr(i);
|
||
|
if (r != NULL) riga = *r;
|
||
|
else riga.cut(0);
|
||
|
}
|
||
|
cs.force_update();
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
void CG0500_application::togli_dal_file(const TString& cau)
|
||
|
{
|
||
|
long i;
|
||
|
TLocalisamfile *rcaus = _rel->lfile(LF_RCAUSALI);
|
||
|
long last = _righe_gia_presenti.last_one();
|
||
|
long start = _righe_gia_presenti.first_one();
|
||
|
|
||
|
for (i=start; i<=last; i++)
|
||
|
{
|
||
|
if (_righe_gia_presenti[i])
|
||
|
{
|
||
|
rcaus->zero();
|
||
|
rcaus->put(RCA_CODCAUS,cau);
|
||
|
rcaus->put(RCA_NRIGA, i);
|
||
|
rcaus->remove();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
int CG0500_application::rewrite(const TMask& m)
|
||
|
{
|
||
|
const int tpm = m.get_int(F_TIPO_MOV);
|
||
|
const TString16 cau(m.get(F_COD_CAUS));
|
||
|
TString80 desc;
|
||
|
TString16 coddesc;
|
||
|
TLocalisamfile *rcaus = _rel->lfile(LF_RCAUSALI);
|
||
|
TLocalisamfile *caus = _rel->lfile(LF_CAUSALI);
|
||
|
|
||
|
m.autosave(_rel);
|
||
|
caus->put(CAU_TIPOMOV, tpm);
|
||
|
|
||
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_GCS);
|
||
|
// _items = _righe_rcaus.items();
|
||
|
_items = cs.items();
|
||
|
|
||
|
for (int i = 0; i < _items; i++)
|
||
|
{
|
||
|
TToken_string &riga = cs.row(i);
|
||
|
desc = riga.get(0);
|
||
|
const char tipo_cf = riga.get()[0];
|
||
|
const int g = riga.get_int();
|
||
|
const int c = riga.get_int();
|
||
|
long s = riga.get_long();
|
||
|
char sezione = riga.get()[0];
|
||
|
desc = riga.get();
|
||
|
coddesc = riga.get();
|
||
|
|
||
|
// NB spostato TIPOCF da terzultimo a secondo
|
||
|
if (g > 0 || c > 0 || s > 0L)
|
||
|
{
|
||
|
rcaus->zero();
|
||
|
rcaus->put (RCA_CODCAUS, (const char *)cau);
|
||
|
rcaus->put (RCA_NRIGA, i+1); // Numerare da uno!
|
||
|
// rcaus->put (RCA_NRIGA , i);
|
||
|
rcaus->put (RCA_GRUPPO , g);
|
||
|
rcaus->put (RCA_CONTO , c);
|
||
|
rcaus->put (RCA_SOTTOCONTO, s);
|
||
|
rcaus->put (RCA_SEZIONE, sezione);
|
||
|
rcaus->put (RCA_DESC , (const char *)desc);
|
||
|
rcaus->put (RCA_CODDESC, (const char *)coddesc);
|
||
|
rcaus->put (RCA_TIPOCF, tipo_cf);
|
||
|
if (_righe_gia_presenti[i+1])
|
||
|
{
|
||
|
rcaus->rewrite();
|
||
|
_righe_gia_presenti.reset(i+1);
|
||
|
}
|
||
|
else
|
||
|
rcaus->write();
|
||
|
}
|
||
|
}
|
||
|
togli_dal_file(cau);
|
||
|
// cs.reset();
|
||
|
// cs.force_update();
|
||
|
return _rel->rewrite();
|
||
|
}
|
||
|
|
||
|
int CG0500_application::write(const TMask& m)
|
||
|
{
|
||
|
const TString tpm(m.get(F_TIPO_MOV));
|
||
|
const TString cau(m.get(F_COD_CAUS));
|
||
|
TString desc_conto(30);
|
||
|
TString desc(50);
|
||
|
TString coddesc(3);
|
||
|
char tipo_cf;
|
||
|
TLocalisamfile *rcaus = _rel->lfile(LF_RCAUSALI);
|
||
|
TLocalisamfile *caus = _rel->lfile(LF_CAUSALI);
|
||
|
|
||
|
m.autosave(_rel);
|
||
|
caus->put(CAU_TIPOMOV, (const char*)tpm);
|
||
|
|
||
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_GCS);
|
||
|
// _items = _righe_rcaus.items();
|
||
|
_items = cs.items();
|
||
|
|
||
|
// NB spostato TIPOCF da terzultimo a secondo
|
||
|
for (int i = 0; i < _items; i++)
|
||
|
{
|
||
|
TToken_string &riga = cs.row(i);
|
||
|
desc_conto = riga.get(0);
|
||
|
tipo_cf = riga.get()[0];
|
||
|
const int g = riga.get_int();
|
||
|
const int c = riga.get_int();
|
||
|
long s = riga.get_long();
|
||
|
char sezione = riga.get()[0];
|
||
|
desc = riga.get();
|
||
|
coddesc = riga.get();
|
||
|
|
||
|
// NB spostato TIPOCF da terzultimo a secondo
|
||
|
if (g > 0 || c > 0 || s > 0L)
|
||
|
{
|
||
|
rcaus->zero();
|
||
|
rcaus->put (RCA_CODCAUS, (const char *)cau);
|
||
|
rcaus->put (RCA_NRIGA , i+1);
|
||
|
// rcaus->put (RCA_NRIGA , i);
|
||
|
rcaus->put (RCA_TIPOCF, tipo_cf);
|
||
|
rcaus->put (RCA_GRUPPO , g);
|
||
|
rcaus->put (RCA_CONTO , c);
|
||
|
rcaus->put (RCA_SOTTOCONTO, s);
|
||
|
rcaus->put (RCA_SEZIONE, sezione);
|
||
|
rcaus->put (RCA_DESC , (const char *)desc);
|
||
|
rcaus->put (RCA_CODDESC, (const char *)coddesc);
|
||
|
rcaus->write();
|
||
|
}
|
||
|
}
|
||
|
return _rel->write();
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
int CG0500_application::cancella(long items)
|
||
|
{
|
||
|
TLocalisamfile * rcaus = _rel->lfile(LF_RCAUSALI);
|
||
|
const TString codcaus = _rel->lfile()->get(RCA_CODCAUS);
|
||
|
for (int i = 1; i <= items; i++)
|
||
|
{
|
||
|
rcaus->zero();
|
||
|
rcaus->put(RCA_CODCAUS, codcaus);
|
||
|
rcaus->put(RCA_NRIGA, i);
|
||
|
if (rcaus->read(_isequal, _lock) == NOERR)
|
||
|
rcaus->remove();
|
||
|
}
|
||
|
return rcaus->status();
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
|
||
|
bool CG0500_application::remove()
|
||
|
{
|
||
|
const bool ok = TRelation_application::remove();
|
||
|
if (ok)
|
||
|
{
|
||
|
const TString cod(_rel->lfile()->get(RCA_CODCAUS));
|
||
|
TLocalisamfile& rcaus = *_rel->lfile(LF_RCAUSALI);
|
||
|
rcaus.zero();
|
||
|
rcaus.put(RCA_CODCAUS, cod);
|
||
|
int e = rcaus.read(_isgteq);
|
||
|
while (e == NOERR && rcaus.get(RCA_CODCAUS) == cod)
|
||
|
{
|
||
|
rcaus.remove();
|
||
|
e = rcaus.next();
|
||
|
}
|
||
|
}
|
||
|
return ok;
|
||
|
}
|
||
|
|
||
|
void CG0500_application::init_query_mode(TMask& m)
|
||
|
{
|
||
|
_righe_rcaus.destroy();
|
||
|
init_mask(m);
|
||
|
}
|
||
|
|
||
|
void CG0500_application::init_insert_mode(TMask& m)
|
||
|
{
|
||
|
init_mask(m);
|
||
|
}
|
||
|
|
||
|
void CG0500_application::init_modify_mode(TMask& m)
|
||
|
{
|
||
|
init_mask(m);
|
||
|
}
|
||
|
|
||
|
void CG0500_application::init_mask(TMask& m)
|
||
|
{
|
||
|
const TString tpd(m.get(F_TIPO_DOC));
|
||
|
const TString tpm(m.get(F_TIPO_MOV));
|
||
|
const TString codreg(m.get(F_COD_REG));
|
||
|
|
||
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_GCS);
|
||
|
// cs.reset();
|
||
|
// cs.force_update();
|
||
|
|
||
|
// F_TIPO_MOV e', nella maschera, un campo nascosto.
|
||
|
// Sono visibili nella maschera F_TIPO_MOV_1 oppure F_TIPO_MOV2,
|
||
|
// a seconda che F_TIPO_DOC sia compilato oppure no.
|
||
|
// All'inizio viene fatto l'output del campo TIPOMOV del file nel campo
|
||
|
// nascosto F_TIPO_MOV.
|
||
|
// Qui il contenuto di F_TIPO_MOV viene mandato a F_TIPO_MOV_1
|
||
|
// oppure F_TIPO_MOV_2.
|
||
|
if (tpd.empty())
|
||
|
m.set(F_TIPO_MOV_2, tpm);
|
||
|
else
|
||
|
m.set(F_TIPO_MOV_1, tpm);
|
||
|
|
||
|
// 27/06/94 Setto il campo nascosto F_ANNOES all'anno di liq. Iva
|
||
|
// preso dai par.ditta
|
||
|
const int anno = anno_iva();
|
||
|
m.set(F_ANNOES, anno);
|
||
|
|
||
|
// Setto il tipo reg e il flag corrisp nei campi nascosti della maschera
|
||
|
// perche non mi fa l'output su di essi quando carica i dati dal file
|
||
|
/*
|
||
|
TRegistro reg(codreg, anno);
|
||
|
const int tipo = reg.tipo();
|
||
|
m.set(F_TIPO_REG, tipo);
|
||
|
m.set(F_CORRISP, reg.corrisp());
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
int CG0500_application::read(TMask& m)
|
||
|
{
|
||
|
m.autoload(_rel);
|
||
|
read_rcaus(m);
|
||
|
carica_descr(m);
|
||
|
return NOERR;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::user_create()
|
||
|
{
|
||
|
_rel = new TRelation (LF_CAUSALI);
|
||
|
_rel->add(LF_RCAUSALI, "CODCAUS=CODCAUS");
|
||
|
|
||
|
_msk = new TMask("cg0500a");
|
||
|
|
||
|
if (!salda_conto())
|
||
|
{
|
||
|
_msk->hide (F_MOV_SEZ);
|
||
|
_msk->hide (F_TIPO_MOV);
|
||
|
}
|
||
|
else
|
||
|
_msk->hide (F_COD_CAUS_IM);
|
||
|
|
||
|
if (!gestione_valuta()) _msk->hide (F_MOV_VALU);
|
||
|
|
||
|
_msk->set_handler(F_TIPO_DOC, tipodoc_hndl);
|
||
|
_msk->set_handler(F_TIPO_MOV_1, tipomov_hndl);
|
||
|
_msk->set_handler(F_TIPO_MOV_2, tipomov_hndl);
|
||
|
_msk->set_handler(F_COD_REG, cod_reg_hndl);
|
||
|
// _msk->set_handler(F_COD_CAUS_IM, codcausim_hndl);
|
||
|
// _msk->set_handler(F_M_770, m770_hndl);
|
||
|
|
||
|
//
|
||
|
// Handler del campo GRUPPO della maschera di edit dello sheet.
|
||
|
// Uso per abilitare il campo C/F per alcuni tipi di conti.
|
||
|
//
|
||
|
TSheet_field& cs = (TSheet_field&)_msk->field(F_SHEET_GCS);
|
||
|
cs.sheet_mask().set_handler(102, tipocf_hndl); // 102 e' il TIPOCF
|
||
|
// cs.sheet_mask().set_handler(104, conto_hndl); // ..conto se non vuoti
|
||
|
// mettono required dare/avere
|
||
|
cs.sheet_mask().set_handler(105, sottoconto_hndl); // 205 e' il sottoc. C/F
|
||
|
cs.sheet_mask().set_handler(205, sottoconto_hndl); // 205 e' il sottoc. C/F
|
||
|
cs.sheet_mask().set_handler(305, sottoconto_hndl); // 205 e' il sottoc. C/F
|
||
|
cs.set_notify(leggi_riga);
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
bool CG0500_application::user_destroy()
|
||
|
{
|
||
|
delete _msk;
|
||
|
delete _rel;
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
int cg0500(int argc, char* argv[])
|
||
|
{
|
||
|
CG0500_application a;
|
||
|
a.run(argc, argv, "Tabella causali");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|