2001-06-25 10:41:20 +00:00
|
|
|
|
#include <defmask.h>
|
|
|
|
|
#include <recarray.h>
|
2001-04-30 14:22:43 +00:00
|
|
|
|
#include <relapp.h>
|
2001-06-25 10:41:20 +00:00
|
|
|
|
#include <sheet.h>
|
|
|
|
|
#include <utility.h>
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
#include "ce0.h"
|
2001-06-25 10:41:20 +00:00
|
|
|
|
#include "ce2101.h"
|
|
|
|
|
#include "celib.h"
|
|
|
|
|
|
|
|
|
|
#include "ce0500a.h"
|
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "cespi.h"
|
|
|
|
|
#include "salce.h"
|
|
|
|
|
#include "ammce.h"
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
// MASCHERA VIRTUALE
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
class TBasic_cespi_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
int create_fields(int x, int y, short key_id, const int page);
|
|
|
|
|
TBasic_cespi_mask(const char* name) : TAutomask(name) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int TBasic_cespi_mask::create_fields(int x, int y, short key_id, const int page)
|
|
|
|
|
{
|
|
|
|
|
TRectype rec_cespi(LF_CESPI);
|
|
|
|
|
//cicla sui campi user (se ci sono) nel ditta.ini facendoli apparire sulla pagine Personalizz.
|
|
|
|
|
TConfig config (CONFIG_DITTA, "ce");
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
int maxprompt = 0;
|
|
|
|
|
for (i = 0; config.exist("USER", i); i++)
|
|
|
|
|
{
|
|
|
|
|
TToken_string riga = config.get("USER", NULL, i);
|
|
|
|
|
const TString80 prompt = riga.get(1);
|
|
|
|
|
const int len = prompt.len();
|
|
|
|
|
if (len > maxprompt)
|
|
|
|
|
maxprompt = len;
|
|
|
|
|
}
|
|
|
|
|
maxprompt++;
|
|
|
|
|
|
|
|
|
|
for (i = 0; config.exist("USER", i); i++)
|
|
|
|
|
{
|
|
|
|
|
TToken_string riga = config.get("USER", NULL, i);
|
|
|
|
|
|
|
|
|
|
const bool search = riga.get_char(3) == 'X';
|
|
|
|
|
//se e' in pagina di ricerca ed il campo non e' di ricerca lo salta!
|
|
|
|
|
if (page == 0 && !search)
|
|
|
|
|
continue;
|
|
|
|
|
//tutto il resto lo fa comunque,settandondolo nella page corretta
|
|
|
|
|
const short kid = key_id+i; //numero del campo come definito nel .h della maschera
|
|
|
|
|
const TString16 name = riga.get(0); //nome campo
|
|
|
|
|
TString80 prompt = riga.get(1); prompt.left_just(maxprompt); //prompt sulla maschera
|
|
|
|
|
const TString80 picture = riga.get(2); //picture del campo(se c'e')
|
|
|
|
|
//se la lunghezza del campo non e' definita nella picture la prende dal tracciato
|
|
|
|
|
const int len = picture.blank() ? rec_cespi.length(name) : picture.len();
|
|
|
|
|
|
|
|
|
|
//chiede al record di che tipo e' il campo chiamato name...
|
|
|
|
|
const TFieldtypes tipo_campo = rec_cespi.type(name);
|
|
|
|
|
//..quanto e' lungo...(maniaca!)
|
|
|
|
|
const int length_campo = rec_cespi.length(name);
|
|
|
|
|
//...e quanti decimali ha nel caso sia un real
|
|
|
|
|
int ndec_campo = 0;
|
|
|
|
|
if (tipo_campo == _realfld)
|
|
|
|
|
ndec_campo = rec_cespi.ndec(name);
|
|
|
|
|
|
|
|
|
|
const bool btn = search && page == 0;
|
|
|
|
|
|
|
|
|
|
//crea finalmente i nuovi campi sulla pagina 1 (Personalizzazioni)
|
|
|
|
|
switch(tipo_campo)
|
|
|
|
|
{
|
|
|
|
|
case _wordfld: add_number (kid, page, prompt, x, i+y, len, btn ? "BU" : "U"); break;
|
|
|
|
|
|
|
|
|
|
case _intfld :
|
|
|
|
|
case _longfld: add_number (kid, page, prompt, x, i+y, len, btn ? "B" : ""); break;
|
|
|
|
|
|
|
|
|
|
case _intzerofld:
|
|
|
|
|
case _longzerofld: add_number (kid, page, prompt, x, i+y, len, btn ? "BZ" : "Z"); break;
|
|
|
|
|
|
|
|
|
|
case _realfld: add_number (kid, page, prompt, x, i+y, len, "", ndec_campo); break;
|
|
|
|
|
|
|
|
|
|
case _datefld: add_date (kid, page, prompt, x, i+y, btn ? "B" : ""); break;
|
|
|
|
|
|
|
|
|
|
case _memofld: add_zoom(kid, page, prompt, x, i+y, 50); break;
|
|
|
|
|
|
|
|
|
|
default : add_string (kid, page, prompt, x, i+y, len, btn ? "BU" : ""); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//deve poter salvare il contenuto nei campi!! (e' il FIELD delle maschere)
|
|
|
|
|
TEdit_field& efld = efield(kid);
|
|
|
|
|
efld.set_field(name); //la set_field lo fa
|
|
|
|
|
}
|
|
|
|
|
//deve accendere gli handler di questa maschera perche' funzionino
|
|
|
|
|
set_handlers();
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
// MASCHERA RICERCA (ce0500a)
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
class TQuery_mask : public TBasic_cespi_mask
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
int _staat;
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
void on_search_event(TOperable_field& o);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
void on_user_search(TOperable_field& o);
|
2002-02-26 16:20:19 +00:00
|
|
|
|
virtual void on_firm_change();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
int calcola_stato_attivita();
|
|
|
|
|
bool cespite_ok() const;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
void set_cespi_filter();
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
public:
|
2001-06-25 10:41:20 +00:00
|
|
|
|
int stato_attivita() const { return _staat; }
|
|
|
|
|
|
|
|
|
|
TQuery_mask();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
void TQuery_mask::on_user_search(TOperable_field& o)
|
|
|
|
|
{
|
|
|
|
|
TToken_string order, header;
|
|
|
|
|
const TFieldref* campo = o.field();
|
|
|
|
|
const TString nome_campo = campo->name();
|
|
|
|
|
//ordinare per campo personalizzato/idcespite/descrizione
|
|
|
|
|
order.add(nome_campo);
|
|
|
|
|
TString prompt = o.prompt();
|
|
|
|
|
prompt << "@" << o.size(); //lunghezza del prompt del campo
|
|
|
|
|
header.add(prompt);
|
|
|
|
|
order.add(CESPI_IDCESPITE); header.add(TR("Cespite@10"));
|
|
|
|
|
order.add(CESPI_DESC); header.add(FR("Descrizione cespite@50"));
|
|
|
|
|
|
|
|
|
|
TRelation rel(LF_CESPI);
|
|
|
|
|
|
|
|
|
|
TSorted_cursor cur(&rel, order);
|
|
|
|
|
TCursor_sheet sht(&cur, order, TR("Cespiti"), header, 0, 1);
|
|
|
|
|
if (sht.run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
TToken_string& row = sht.row();
|
|
|
|
|
set(F_IDCESPITE, row.get(1), TRUE);
|
|
|
|
|
stop_run(K_AUTO_ENTER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
void TQuery_mask::on_search_event(TOperable_field& o)
|
|
|
|
|
{
|
|
|
|
|
TToken_string order, fields, header;
|
|
|
|
|
if (o.dlg() >= F_SEARCH3)
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
order.add(CESPI_STABILIM); header.add(TR("Stabilimento"));
|
|
|
|
|
order.add(CESPI_REPARTO); header.add(FR("Reparto@10"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (o.dlg() >= F_SEARCH2)
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
order.add(CESPI_CODIMP); header.add(FR("Impianto@10"));
|
|
|
|
|
order.add("CIM->S0"); header.add(FR("Descrizione impianto@40"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (o.dlg() >= F_SEARCH1)
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
order.add(CESPI_CODCAT); header.add(TR("Cat"));
|
|
|
|
|
order.add(CESPI_DTCOMP); header.add(FR("Data Acq.@10"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-12 15:03:40 +00:00
|
|
|
|
order.add(CESPI_IDCESPITE); header.add(FR("Codice@10"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
|
|
|
|
fields = order;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
fields.add(CESPI_DESC); header.add(FR("Descrizione cespite@50"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
|
|
|
|
TRelation rel(LF_CESPI);
|
2003-05-12 15:03:40 +00:00
|
|
|
|
|
|
|
|
|
rel.add("CIM","CODTAB==CODIMP");
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
2003-05-12 15:03:40 +00:00
|
|
|
|
TString filter;
|
|
|
|
|
|
|
|
|
|
if (get(F_SELECT) == "I") // Filtro per impianto
|
2001-09-19 14:52:11 +00:00
|
|
|
|
{
|
|
|
|
|
const TString& imp = get(F_IMPIANTO);
|
|
|
|
|
if (!imp.empty())
|
|
|
|
|
filter << CESPI_CODIMP << "=\"" << imp << '"';
|
|
|
|
|
}
|
|
|
|
|
else // Filtro per attivit<69>
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
filter << "STR(" << CESPI_CODCGRA << "=" << get_int(F_GRUPPO) << ')';
|
2001-09-19 14:52:11 +00:00
|
|
|
|
filter << "&&(" << CESPI_CODSPA << "=\"" << get(F_SPECIE) << "\")";
|
|
|
|
|
}
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
|
|
|
|
TSorted_cursor cur(&rel, order, filter);
|
2003-05-12 15:03:40 +00:00
|
|
|
|
TCursor_sheet sht(&cur, fields, TR("Cespiti"), header, 0, 1);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
if (sht.run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
TToken_string& row = sht.row();
|
|
|
|
|
const int cod_pos = row.items()-2;
|
|
|
|
|
set(F_IDCESPITE, row.get(cod_pos), TRUE);
|
|
|
|
|
stop_run(K_AUTO_ENTER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TQuery_mask::calcola_stato_attivita()
|
|
|
|
|
{
|
|
|
|
|
const int ese = get_int(F_ESERCIZIO);
|
|
|
|
|
const int gru = get_int(F_GRUPPO);
|
|
|
|
|
const char* spe = get(F_SPECIE);
|
|
|
|
|
|
|
|
|
|
TString16 str;
|
|
|
|
|
str.format("%04d%02d%-4s", ese, gru, spe);
|
|
|
|
|
|
|
|
|
|
const TRectype& curr_ccb = cache().get("CCB", str);
|
|
|
|
|
if (curr_ccb.get_bool("B1")) // Bollato stampato
|
|
|
|
|
_staat = 3;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
|
str.format("%04d%02d%-4s", esc.pred(ese), gru, spe);
|
|
|
|
|
const TRectype& prev_ccb = cache().get("CCB", str);
|
|
|
|
|
_staat = prev_ccb.get_bool("B1") ? 2 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
dc.set_attivita(ese, gru, spe);
|
|
|
|
|
|
|
|
|
|
return _staat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TQuery_mask::cespite_ok() const
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
const TRectype & cespi = cache().get(LF_CESPI, get(F_IDCESPITE));
|
|
|
|
|
const bool ok = !cespi.empty();
|
2001-06-25 10:41:20 +00:00
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
void TQuery_mask::set_cespi_filter()
|
|
|
|
|
{
|
|
|
|
|
TString filter;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
if (get(F_SELECT) == "I") // Filtro per impianto
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
2001-09-19 14:52:11 +00:00
|
|
|
|
const TString& imp = get(F_IMPIANTO);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!imp.empty())
|
2001-09-19 14:52:11 +00:00
|
|
|
|
filter << CESPI_CODIMP << "=\"" << imp << '"';
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
else // Filtro per attivit<69>
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
filter << "STR(" << CESPI_CODCGRA << "=" << get_int(F_GRUPPO) << ')';
|
2001-07-24 13:28:55 +00:00
|
|
|
|
filter << "&&(" << CESPI_CODSPA << "=\"" << get(F_SPECIE) << "\")";
|
|
|
|
|
}
|
|
|
|
|
efield(F_IDCESPITE).browse()->set_filter(filter);
|
|
|
|
|
efield(F_DESC).browse()->set_filter(filter);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_ESERCIZIO:
|
|
|
|
|
case F_GRUPPO:
|
|
|
|
|
case F_SPECIE:
|
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
const bool can_create = calcola_stato_attivita() != 3; // Bollato non stampato
|
2001-07-24 13:28:55 +00:00
|
|
|
|
enable(DLG_NEWREC, can_create && !field(F_SPECIE).empty() && !field(F_CATEGORIA).empty());
|
2001-06-25 10:41:20 +00:00
|
|
|
|
enable(DLG_DELREC, can_create);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
set_cespi_filter();
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
case F_SELECT:
|
|
|
|
|
case F_IMPIANTO:
|
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
set_cespi_filter();
|
|
|
|
|
break;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
case F_SEARCH1:
|
|
|
|
|
case F_SEARCH2:
|
|
|
|
|
case F_SEARCH3:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
on_search_event(o);
|
|
|
|
|
break;
|
|
|
|
|
case F_CATEGORIA:
|
|
|
|
|
case F_DESC_CAT:
|
|
|
|
|
{
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
bool ok = dc.on_category_event(o, e, jolly);
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
if (e == fe_modify && !o.empty() && stato_attivita() == 2)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& cac = dc.categoria(0, NULL, get_int(F_CATEGORIA));
|
|
|
|
|
const int fine_validita = cac.get_date("D1").year();
|
|
|
|
|
if (fine_validita > 0 && fine_validita < get_int(F_ESERCIZIO))
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(FR("Categoria scaduta nell'esercizio %d"), fine_validita);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
2001-09-19 14:52:11 +00:00
|
|
|
|
if (e == fe_init || e == fe_modify || e == fe_button)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
const bool bollati = stato_attivita() == 3;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
enable(DLG_NEWREC, !bollati && !o.empty() && !field(F_SPECIE).empty());
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
2003-08-07 14:09:09 +00:00
|
|
|
|
if (e == fe_close && o.empty() && !field(F_IDCESPITE).empty() && !cespite_ok())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("<EFBFBD> necessario specificare la categoria del nuovo cespite"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_IDCESPITE:
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
if (stato_attivita() == 3 && !cespite_ok())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("E' stato stampato il bollato dell'anno:\nnon sono permessi inserimenti"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (e == fe_modify && !o.empty() && cespite_ok())
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
TString key;
|
|
|
|
|
|
|
|
|
|
key = get(F_IDCESPITE);
|
|
|
|
|
key << '|' << get(F_ESERCIZIO) << "|1";
|
|
|
|
|
|
|
|
|
|
const TRectype & salce = cache().get(LF_SALCE, key);
|
|
|
|
|
if (salce.empty())
|
|
|
|
|
return yesno_box(TR("Non esistono saldi per l'anno selezionato:\nSi desidera continuare ugualmente?"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
case F_USER:
|
|
|
|
|
case F_USER+1:
|
|
|
|
|
case F_USER+2:
|
|
|
|
|
case F_USER+3:
|
|
|
|
|
case F_USER+4:
|
|
|
|
|
case F_USER+5:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
on_user_search(o);
|
|
|
|
|
break;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-26 16:20:19 +00:00
|
|
|
|
void TQuery_mask::on_firm_change()
|
|
|
|
|
{
|
|
|
|
|
TAutomask::on_firm_change();
|
|
|
|
|
ditta_cespiti().init_mask(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TQuery_mask::TQuery_mask() : TBasic_cespi_mask("ce0500a")
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
first_focus(F_IDCESPITE);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
create_fields(2, 13, F_USER, 0);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
// MASCHERA DI MODIFICA (ca0500b)
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
class TEdit_mask : public TBasic_cespi_mask
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
TTipo_cespite _tipo;
|
|
|
|
|
int _staat;
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
virtual bool on_key(KEY k);
|
|
|
|
|
|
|
|
|
|
bool one_compiled(const short* f) const;
|
|
|
|
|
TCurrency sum_fields(const short* f) const;
|
|
|
|
|
bool test_ammissibilita_dati();
|
|
|
|
|
bool test_ammissibilita_saldi();
|
|
|
|
|
bool test_ammissibilita_fondi();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2001-06-25 10:41:20 +00:00
|
|
|
|
void set_stato_attivita(int sa) { _staat = sa; }
|
|
|
|
|
int stato_attivita() const { return _staat; }
|
|
|
|
|
|
|
|
|
|
void set_tipo_cespite(TTipo_cespite tc) { _tipo = tc; }
|
|
|
|
|
TTipo_cespite tipo_cespite() const { return _tipo; }
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
void protect_page(int page, TToken_string& enabling);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TEdit_mask();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
bool TEdit_mask::one_compiled(const short* f) const
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; f[i]; i++)
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (!field(f[i]).empty())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-09-19 14:52:11 +00:00
|
|
|
|
return f[i] > 0;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCurrency TEdit_mask::sum_fields(const short* f) const
|
|
|
|
|
{
|
|
|
|
|
TCurrency sum, val;
|
|
|
|
|
for (int i = 0; f[i] != 0; i++)
|
|
|
|
|
{
|
|
|
|
|
get_currency(abs(f[i]), val);
|
|
|
|
|
if (f[i] > 0)
|
|
|
|
|
sum += val;
|
|
|
|
|
else
|
|
|
|
|
sum -= val;
|
|
|
|
|
}
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool TEdit_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
bool ok = TRUE;
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_CATEGORIA:
|
|
|
|
|
if (e == fe_init)
|
|
|
|
|
{
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
dc.on_category_event(o, e, jolly);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_DTCOMP:
|
2003-04-23 13:47:36 +00:00
|
|
|
|
if (e == fe_init && o.empty())
|
|
|
|
|
{
|
|
|
|
|
TConfig ini (CONFIG_DITTA, "ce");
|
|
|
|
|
TString16 datamov = ini.get("DataMovimento");
|
|
|
|
|
if (datamov.empty())
|
|
|
|
|
datamov = TDate(TODAY).string();
|
|
|
|
|
o.set(datamov);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
if (e == fe_modify || e == fe_close)
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtcomp(o.get());
|
2001-06-25 10:41:20 +00:00
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
TDate iniz, fine;
|
2004-03-13 09:12:24 +00:00
|
|
|
|
dc.esercizio_corrente(iniz, fine);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (stato_attivita() == 2)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (dtcomp < iniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data appartiene ad un esercizio gi<67> stampato su bollato"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
const TRectype& cac = dc.categoria(0, NULL, get_int(F_CATEGORIA));
|
|
|
|
|
iniz = cac.get("D0");
|
|
|
|
|
if (iniz.ok() && dtcomp < iniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data <20> precedente all'inizio della validit<69> della categoria"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
fine = cac.get("D1");
|
|
|
|
|
if (fine.ok() && dtcomp > fine)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data <20> succesiva alla fine della validit<69> della categoria"));
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
if (dc.esercizio_costituzione() && dtcomp < iniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("Non <20> possibile specificare una data antecedente all'esercizio di costituzione"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
|
|
|
|
|
if (tipo_cespite() != tc_materiale && dtcomp.year() >= dc.anno_tuir())
|
|
|
|
|
{
|
|
|
|
|
if (field(F_DTFUNZ).empty())
|
|
|
|
|
set(F_DTFUNZ, o.get());
|
|
|
|
|
}
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_DTFUNZ:
|
|
|
|
|
if (e == fe_modify || e == fe_close)
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtfunz(o.get());
|
2001-06-25 10:41:20 +00:00
|
|
|
|
if (dtfunz.ok())
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtcomp(field(F_DTCOMP).get());
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dtfunz < dtcomp)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(FR("La data di entrata in funzione deve essere successiva a quella di aquisizione"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!dtcomp.ok())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data di entrata in funzione non puo' essere inserita senza specificare quella di aquisizione"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (stato_attivita() == 2)
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate iniz(get(F_INIZIO_ES));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dtfunz < iniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data di entrata in funzione deve essere successiva a quella di inizio esercizio"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
if (_tipo != tc_materiale && dtfunz != dtcomp)
|
|
|
|
|
{
|
|
|
|
|
if (dtcomp.year() >= dc.anno_tuir())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("In base alla normativa del TUIR, le date di acquisizione e di entrata in funzione devono coincidere"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
2001-06-25 10:41:20 +00:00
|
|
|
|
const TRectype& cac = dc.categoria(0, NULL, get_int(F_CATEGORIA));
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate iniz = cac.get_date("D0");
|
2001-06-25 10:41:20 +00:00
|
|
|
|
if (iniz.ok() && dtfunz < iniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data <20> precedente all'inizio validit<69> della categoria"));
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate fine = cac.get_date("D1");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (fine.ok() && dtfunz > fine)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("La data <20> successiva alla fine validit<69> della categoria"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dtfunz.year() >= dc.anno_tuir())
|
|
|
|
|
set(F_TUIR, "X");
|
2002-10-23 14:14:55 +00:00
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
else
|
|
|
|
|
reset(F_TUIR);
|
2002-10-23 14:14:55 +00:00
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
case F_QUADRATURA:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
set(F_NORMALE2, get(F_NORMALE));
|
|
|
|
|
set(F_NORMALE3, get(F_NORMALE));
|
|
|
|
|
set(F_ACCELERATO2, get(F_ACCELERATO));
|
|
|
|
|
set(F_ACCELERATO3, get(F_ACCELERATO));
|
|
|
|
|
set(F_ANTICIPATO2, get(F_ANTICIPATO));
|
|
|
|
|
set(F_ANTICIPATO3, get(F_ANTICIPATO));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_VNONAMM:
|
|
|
|
|
if (e == fe_modify || e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
if (o.empty() && get_bool(F_LEASING))
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("Indicare il valore del riscatto per beni in leasing"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
test_ammissibilita_saldi();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_PLUSREIN:
|
|
|
|
|
if ((e == fe_modify || e == fe_close) && !o.empty())
|
|
|
|
|
{
|
|
|
|
|
TCurrency costo; get_currency(F_COSTO, costo);
|
|
|
|
|
TCurrency noamm; get_currency(F_VNONAMM, noamm);
|
|
|
|
|
TCurrency plusr; get_currency(F_PLUSREIN, plusr);
|
|
|
|
|
const TCurrency minim = costo - noamm;
|
|
|
|
|
if (plusr > minim)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(FR("La plusvalenza reinvestita non puo' superare %s"), minim.string(TRUE));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_ELEMENTI:
|
2003-08-07 14:09:09 +00:00
|
|
|
|
if ((e == fe_modify || e == fe_close) && o.empty())
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtcomp(field(F_DTCOMP).get());
|
|
|
|
|
const TDate dtiniz(field(F_INIZIO_ES).get());
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dtcomp.ok() && dtcomp < dtiniz)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("E' necessario specificare il numero di elementi per cespiti acquisiti negli esercizi precedenti"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
const short fields[] = { F_COSTO, F_VNONAMM, F_RIV75, F_RIV83, F_RIV90, F_RIV91, F_RIVGF, F_RIVGC, 0 };
|
|
|
|
|
if (one_compiled(fields))
|
2003-08-07 14:09:09 +00:00
|
|
|
|
return error_box(TR("E' necessario inserire il numero degli elementi"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_RIV90:
|
|
|
|
|
case F_RIV91:
|
|
|
|
|
if ((e == fe_init || e == fe_modify) && o.active())
|
|
|
|
|
{
|
|
|
|
|
TEdit_field& anni = efield(o.dlg()+1);
|
|
|
|
|
if (o.empty())
|
|
|
|
|
{
|
|
|
|
|
anni.reset();
|
|
|
|
|
anni.disable();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
anni.enable();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_ANNIAMM:
|
|
|
|
|
if (e == fe_init || e == fe_modify)
|
2005-02-17 18:13:12 +00:00
|
|
|
|
enable_page(3, !o.empty());
|
2001-07-24 13:28:55 +00:00
|
|
|
|
break;
|
|
|
|
|
case F_NORMALE:
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
const short fv[] = { F_COSTO, -F_VNONAMM, F_RIV75, F_RIV83, F_RIV90, F_RIV91, F_RIVGF, 0 };
|
|
|
|
|
const short fa[] = { F_NORMALE, F_ACCELERATO, F_ANTICIPATO, F_QPERSE, F_FPRIVATO, F_QPERSEPRIV, 0 };
|
|
|
|
|
const TCurrency val_amm = sum_fields(fv);
|
|
|
|
|
const TCurrency fon_amm = sum_fields(fa);
|
|
|
|
|
if (fon_amm > val_amm)
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg << TR("Il fondo ammortamento fiscale (") << fon_amm.string(TRUE) << ')';
|
|
|
|
|
msg << TR("non puo' superare il valore da ammortizzare (") << val_amm.string(TRUE) << ')';
|
2001-07-24 13:28:55 +00:00
|
|
|
|
return error_box(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_FPRIVATO:
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
if (get_int(F_USOPROM) > 1 && !field(F_ANNIAMM).empty())
|
|
|
|
|
{
|
|
|
|
|
if (field(F_FPRIVATO).empty() && field(F_QPERSEPRIV).empty())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return error_box(TR("E' necessario inserire un fondo di ammortamento privato o delle quote perse private"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_NORMALE2:
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
const short fv[] = { F_COSTO, F_RIV75, F_RIV83, F_RIV90, F_RIV91, F_RIVGC, 0 };
|
|
|
|
|
const short fa[] = { F_NORMALE2, F_ACCELERATO2, F_ANTICIPATO2, 0 };
|
|
|
|
|
const TCurrency val_amm = sum_fields(fv);
|
|
|
|
|
const TCurrency fon_amm = sum_fields(fa);
|
|
|
|
|
if (fon_amm > val_amm)
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg << TR("Il fondo ammortamento civilistico (") << fon_amm.string(TRUE) << ')';
|
|
|
|
|
msg << TR("non puo' superare il valore da ammortizzare (") << val_amm.string(TRUE) << ')';
|
2001-07-24 13:28:55 +00:00
|
|
|
|
return error_box(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
// Disabilita tutti i campi della pagina "page" (1 based) tranne quelli nella lista "enabling"
|
|
|
|
|
void TEdit_mask::protect_page(int page, TToken_string& enabling)
|
|
|
|
|
{
|
|
|
|
|
// Determina l'id del primo campo della pagina
|
|
|
|
|
short cid = 0;
|
|
|
|
|
switch (page)
|
|
|
|
|
{
|
|
|
|
|
case 2: cid = F_ELEMENTI; break;
|
|
|
|
|
case 3: cid = F_NORMALE; break;
|
|
|
|
|
default: cid = F_IDCESPITE; break;
|
|
|
|
|
}
|
|
|
|
|
// Determina l'handle della pagina selezionata
|
|
|
|
|
WINDOW parent = field(cid).parent();
|
|
|
|
|
|
|
|
|
|
for (int f = fields()-1; f >= 0; f--)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& c = fld(f);
|
|
|
|
|
if (c.parent() == parent) // Il campo appartiene alla pagina voluta?
|
|
|
|
|
{
|
|
|
|
|
const short id = c.dlg();
|
|
|
|
|
if (id > 100 && id < 1000 && c.is_operable() && c.enabled_default())
|
|
|
|
|
{
|
|
|
|
|
const bool on = enabling.empty() || enabling.get_pos(c.dlg()) >= 0;
|
|
|
|
|
c.enable(on);
|
|
|
|
|
if (cid == id) // Ho raggiunto il capo pagina?
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEdit_mask::test_ammissibilita_dati()
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
const char* msg = insert_mode() ? TR("Inserimento") : TR("Modifica");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
xvt_statbar_set(msg, TRUE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEdit_mask::test_ammissibilita_saldi()
|
|
|
|
|
{
|
|
|
|
|
bool protez = FALSE;
|
|
|
|
|
const char* msg = "";
|
|
|
|
|
switch (_staat)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate iniz(get(F_INIZIO_ES));
|
|
|
|
|
const TDate dtacq(get(F_DTCOMP));
|
|
|
|
|
const TDate dtfunz(get(F_DTFUNZ));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!dtacq.ok() || !dtfunz.ok())
|
|
|
|
|
protez = TRUE;
|
|
|
|
|
else
|
|
|
|
|
protez = dtacq >= iniz || dtfunz >= iniz;
|
|
|
|
|
if (protez)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Inserire gli importi nel movimento d'acquisto");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
protez = TRUE;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Bollato stampato: non sono ammesse modifiche");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TToken_string enabling;
|
|
|
|
|
if (protez)
|
|
|
|
|
enabling = "883"; // Disabilita tutto!
|
|
|
|
|
protect_page(2, enabling);
|
|
|
|
|
|
|
|
|
|
if (*msg)
|
|
|
|
|
beep(1);
|
|
|
|
|
else
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = insert_mode() ? TR("Inserimento") : TR("Modifica");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
xvt_statbar_set(msg, TRUE);
|
|
|
|
|
|
|
|
|
|
return protez;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEdit_mask::test_ammissibilita_fondi()
|
|
|
|
|
{
|
|
|
|
|
bool protez = FALSE;
|
|
|
|
|
const char* msg = "";
|
|
|
|
|
switch (_staat)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtacq(get(F_DTCOMP));
|
|
|
|
|
const TDate dtfunz(get(F_DTFUNZ));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!dtacq.ok() || !dtfunz.ok())
|
|
|
|
|
protez = TRUE;
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate iniz(get(F_INIZIO_ES));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
protez = dtacq >= iniz;
|
|
|
|
|
}
|
|
|
|
|
if (protez)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Inserire gli importi nel movimento d'acquisto");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
protez = TRUE;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Bollato stampato: non sono ammesse modifiche");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
break;
|
|
|
|
|
default: protez = FALSE; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TToken_string enabling;
|
|
|
|
|
if (protez)
|
|
|
|
|
enabling = "883"; // Disabilita tutto!
|
|
|
|
|
protect_page(3, enabling);
|
|
|
|
|
|
|
|
|
|
if (!protez)
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtfunz(get(F_DTFUNZ));
|
|
|
|
|
const TDate iniz(get(F_INIZIO_ES));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
bool prot9 = FALSE;
|
|
|
|
|
if (!dtfunz.ok() || dtfunz >= iniz)
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Cespite non ancora entrato in funzione a inizio esercizio");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
prot9 = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TRectype& cac = ditta_cespiti().categoria(0, NULL, get_int(F_CATEGORIA));
|
|
|
|
|
if (cac.get_bool("B0"))
|
|
|
|
|
{
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = TR("Categoria non ammortizzabile");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
prot9 = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
enable(-9, !prot9);
|
|
|
|
|
}
|
|
|
|
|
if (*msg)
|
|
|
|
|
beep(1);
|
|
|
|
|
else
|
2003-05-12 15:03:40 +00:00
|
|
|
|
msg = insert_mode() ? TR("Inserimento") : TR("Modifica");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
xvt_statbar_set(msg, TRUE);
|
|
|
|
|
|
|
|
|
|
return protez;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TEdit_mask::on_key(KEY k)
|
|
|
|
|
{
|
|
|
|
|
// Try to predict next page!
|
|
|
|
|
const int old_page = curr_page()+1;
|
|
|
|
|
int new_page = old_page;
|
|
|
|
|
switch (k)
|
|
|
|
|
{
|
|
|
|
|
case K_CTRL+K_F1: new_page = 1; break;
|
|
|
|
|
case K_CTRL+K_F2: new_page = 2; break;
|
|
|
|
|
case K_CTRL+K_F3: new_page = 3; break;
|
|
|
|
|
case K_PREV : new_page--; break;
|
|
|
|
|
case K_NEXT : new_page++; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If page will change ...
|
|
|
|
|
if (old_page != new_page) switch(new_page)
|
|
|
|
|
{
|
|
|
|
|
case 1: test_ammissibilita_dati(); break;
|
|
|
|
|
case 2: test_ammissibilita_saldi(); break;
|
|
|
|
|
case 3: test_ammissibilita_fondi(); break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TAutomask::on_key(k);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TEdit_mask::TEdit_mask() : TBasic_cespi_mask("ce0500b")
|
|
|
|
|
{
|
|
|
|
|
create_fields(1, 1, F_USER, 1);
|
|
|
|
|
}
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
// APPLICAZIONE
|
|
|
|
|
//--------------------------------------------------------------
|
2001-04-30 14:22:43 +00:00
|
|
|
|
class TAnacespi : public TRelation_application
|
|
|
|
|
{
|
|
|
|
|
TRelation* _cespiti;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
int _rel_year;
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TQuery_mask* _qmask;
|
|
|
|
|
TEdit_mask* _emask;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void init_mask(TMask& m);
|
2003-05-12 15:03:40 +00:00
|
|
|
|
bool kill_cespite(const TString& idcespite, int lfile, int key = 1);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// @cmember Inizializzazione dei dati dell'utente
|
|
|
|
|
virtual bool user_create();
|
|
|
|
|
// @cmember Distruzione dei dati dell'utente
|
|
|
|
|
virtual bool user_destroy();
|
|
|
|
|
virtual bool changing_mask(int mode);
|
|
|
|
|
// @cmember Richiede la maschera da usare
|
|
|
|
|
virtual TMask* get_mask(int mode);
|
|
|
|
|
// @cmember Ritorna la relazione da modificare
|
|
|
|
|
virtual TRelation* get_relation() const;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
|
|
|
|
virtual const char* get_next_key();
|
|
|
|
|
virtual bool protected_record(TRectype& rec);
|
|
|
|
|
virtual void init_query_mode(TMask& m);
|
|
|
|
|
virtual void init_insert_mode(TMask& m);
|
|
|
|
|
virtual void init_modify_mode(TMask& m);
|
|
|
|
|
|
|
|
|
|
virtual int read(TMask& m);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
virtual int write(const TMask& m);
|
|
|
|
|
virtual bool remove();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TAnacespi::changing_mask(int)
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMask* TAnacespi::get_mask(int mode)
|
|
|
|
|
{
|
|
|
|
|
return mode == MODE_QUERY ? (TMask*)_qmask : (TMask*)_emask;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
// get_relation pi<70> complessa della storia di campo
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TRelation* TAnacespi::get_relation() const
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
const int year = _qmask->get_int(F_ESERCIZIO);
|
|
|
|
|
TRelation*& csp = ((TAnacespi*)this)->_cespiti;
|
|
|
|
|
if (year != _rel_year && csp != NULL)
|
|
|
|
|
{
|
|
|
|
|
delete csp;
|
|
|
|
|
csp = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (csp == NULL)
|
|
|
|
|
{
|
|
|
|
|
// Crea nuova relazione su cespi
|
|
|
|
|
csp = new TRelation(LF_CESPI);
|
|
|
|
|
((TAnacespi*)this)->_rel_year = year; // Memorizza anno utilizzato
|
|
|
|
|
|
|
|
|
|
// Collega salce
|
|
|
|
|
TString80 expr1;
|
|
|
|
|
expr1 << SALCE_IDCESPITE << "==" << CESPI_IDCESPITE;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
expr1 << '|' << SALCE_CODES << "==" << year;
|
|
|
|
|
expr1 << '|' << SALCE_TPSALDO << "==1";
|
2001-06-25 10:41:20 +00:00
|
|
|
|
csp->add(LF_SALCE, expr1);
|
|
|
|
|
|
|
|
|
|
// Collega i tre tipi di ammce
|
|
|
|
|
for (int a = 1; a <= 3; a++)
|
|
|
|
|
{
|
2001-07-24 13:28:55 +00:00
|
|
|
|
TString80 expr2 = expr1;
|
2001-06-25 10:41:20 +00:00
|
|
|
|
expr2 << '|' << AMMCE_TPAMM << "==" << a;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
csp->add(LF_AMMCE, expr2, 1, 0, a-1);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attiva il salvataggio anche di salce e ammce
|
|
|
|
|
csp->write_enable();
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
return _cespiti;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
void TAnacespi::init_query_mode(TMask& m)
|
|
|
|
|
{
|
|
|
|
|
ditta_cespiti().init_mask(m);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
set_search_field(F_IDCESPITE);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAnacespi::protected_record(TRectype& rec)
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
const TDate dtalien = rec.get_date(CESPI_DTALIEN);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
return dtalien.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAnacespi::init_mask(TMask& m)
|
|
|
|
|
{
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
dc.init_mask(m);
|
|
|
|
|
const bool can_edit = !dc.bollato_stampato() && m.field(F_DTALIEN).empty();
|
|
|
|
|
m.enable(DLG_SAVEREC, can_edit);
|
2002-02-26 16:20:19 +00:00
|
|
|
|
m.enable(DLG_DELREC, can_edit && m.edit_mode());
|
2001-07-24 13:28:55 +00:00
|
|
|
|
m.disable(DLG_NEWREC);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
|
|
|
|
_emask->set_stato_attivita(_qmask->stato_attivita());
|
|
|
|
|
|
|
|
|
|
const TRectype& cac = dc.categoria(0, NULL, _qmask->get_int(F_CATEGORIA));
|
|
|
|
|
const int tc = cac.get_int("I0");
|
|
|
|
|
_emask->set_tipo_cespite(tc==0 ? tc_materiale : (tc==1 ? tc_immateriale : tc_pluriennale));
|
|
|
|
|
|
|
|
|
|
const bool mat_only = _emask->tipo_cespite() == tc_materiale;
|
|
|
|
|
m.show(F_LEASING, mat_only);
|
2004-11-30 22:02:59 +00:00
|
|
|
|
m.show(F_ANNIRIC, true); // m.show(F_ANNIRIC, mat_only); // Sempre visibile
|
2001-06-25 10:41:20 +00:00
|
|
|
|
m.show(F_USATO, mat_only);
|
2002-10-23 14:14:55 +00:00
|
|
|
|
m.show(F_AMMPROP, dc.ammortamento_proporzionale());
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAnacespi::init_insert_mode(TMask& m)
|
|
|
|
|
{
|
|
|
|
|
init_mask(m);
|
|
|
|
|
m.set(F_TUIR, "X");
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (_emask->tipo_cespite() == tc_materiale)
|
|
|
|
|
m.set(F_SPEMAN, 2);
|
|
|
|
|
else
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2001-07-24 13:28:55 +00:00
|
|
|
|
m.set(F_SPEMAN, 1);
|
|
|
|
|
m.disable(F_SPEMAN);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
2001-07-24 13:28:55 +00:00
|
|
|
|
m.set(F_ESCLPR, _emask->tipo_cespite() != tc_pluriennale ? "X" : "");
|
|
|
|
|
// Extra: non richiesti da analisi, ma obbligatori
|
|
|
|
|
m.set(F_VEICOLO, 1);
|
|
|
|
|
m.set(F_USOPROM, 1);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAnacespi::init_modify_mode(TMask& m)
|
|
|
|
|
{
|
|
|
|
|
init_mask(m);
|
|
|
|
|
|
|
|
|
|
TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
TDate iniz, fine;
|
2004-03-13 09:12:24 +00:00
|
|
|
|
dc.esercizio_corrente(iniz, fine);
|
|
|
|
|
const TDate dtacq(m.get(F_DTCOMP));
|
|
|
|
|
const TDate dtfunz(m.get(F_DTFUNZ));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
const int staat = _qmask->stato_attivita();
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
TToken_string enabling;
|
|
|
|
|
switch (staat)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
case 2:
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dtacq < iniz)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!dtfunz.ok() || dtfunz >= iniz)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
2001-07-24 13:28:55 +00:00
|
|
|
|
enabling.add(F_DTFUNZ);
|
|
|
|
|
enabling.add(F_USOPROM);
|
|
|
|
|
enabling.add(F_VEIDIP);
|
|
|
|
|
enabling.add(F_VEICOLO);
|
|
|
|
|
if (_emask->tipo_cespite() == tc_materiale)
|
2001-06-25 10:41:20 +00:00
|
|
|
|
enabling.add(F_SPEMAN);
|
|
|
|
|
}
|
2001-07-24 13:28:55 +00:00
|
|
|
|
else
|
2001-06-25 10:41:20 +00:00
|
|
|
|
{
|
|
|
|
|
enabling.add(F_USOPROM);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
enabling.add(F_VEIDIP);
|
|
|
|
|
enabling.add(F_VEICOLO);
|
|
|
|
|
if (_emask->tipo_cespite() == tc_materiale)
|
|
|
|
|
enabling.add(F_SPEMAN);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if (!dtfunz.ok() || dtfunz >= iniz)
|
|
|
|
|
{
|
|
|
|
|
enabling.add(F_DTFUNZ);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
_emask->protect_page(1, enabling);
|
|
|
|
|
|
|
|
|
|
enabling.cut(0);
|
|
|
|
|
if (staat == 2 || staat == 3)
|
|
|
|
|
_emask->protect_page(2, enabling);
|
|
|
|
|
|
|
|
|
|
if (!m.field(F_DTALIEN).empty())
|
2003-05-12 15:03:40 +00:00
|
|
|
|
xvt_statbar_set(TR("Cespite alienato: non <20> possibile apportare modifiche"), TRUE);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* TAnacespi::get_next_key()
|
|
|
|
|
{
|
|
|
|
|
real num = 1;
|
|
|
|
|
TLocalisamfile cespi(LF_CESPI);
|
|
|
|
|
if (cespi.last() == NOERR)
|
|
|
|
|
num = cespi.get_real(CESPI_IDCESPITE) + 1;
|
|
|
|
|
return format("%d|%s", F_IDCESPITE, num.string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TAnacespi::read(TMask& m)
|
|
|
|
|
{
|
|
|
|
|
int err = TRelation_application::read(m);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 13:28:55 +00:00
|
|
|
|
int TAnacespi::write(const TMask& m)
|
|
|
|
|
{
|
|
|
|
|
TRectype& curr = get_relation()->curr();
|
|
|
|
|
const TDitta_cespiti& dc = ditta_cespiti();
|
|
|
|
|
const TRectype& cac = dc.categoria(0, NULL, m.get_int(F_CATEGORIA));
|
|
|
|
|
switch (_emask->tipo_cespite())
|
|
|
|
|
{
|
|
|
|
|
case tc_immateriale:
|
2001-09-19 14:52:11 +00:00
|
|
|
|
if (cac.get_int("I1") == 2) // Percentuali
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
curr.put(CESPI_PIMM, cac.get("R13"));
|
|
|
|
|
curr.put(CESPI_VINCOLO, 1);
|
|
|
|
|
}
|
|
|
|
|
else // Anni
|
|
|
|
|
{
|
|
|
|
|
curr.zero(CESPI_PIMM);
|
|
|
|
|
curr.put(CESPI_ANNIRIC, cac.get("I3"));
|
|
|
|
|
curr.put(CESPI_VINCOLO, 2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case tc_pluriennale:
|
|
|
|
|
curr.put(CESPI_VINCOLO, cac.get("I2"));
|
|
|
|
|
curr.put(CESPI_PMINP, cac.get("R14"));
|
|
|
|
|
curr.put(CESPI_PMAXP, cac.get("R15"));
|
|
|
|
|
curr.put(CESPI_ANNIRIC, cac.get("I3"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
{
|
2004-03-13 09:12:24 +00:00
|
|
|
|
TDate dt(m.get(F_DTFUNZ));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (!dt.ok())
|
2001-09-19 14:52:11 +00:00
|
|
|
|
dt = m.get_date(F_INIZIO_ES);
|
|
|
|
|
// % beni mat D.M. 29/10/74 oppure D.M. 31/12/88
|
|
|
|
|
const TString& pmat = cac.get(dt.year() < 1989 ? "R12" : "R11");
|
|
|
|
|
curr.put(CESPI_PMAT, pmat);
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int cat = m.get_int(F_CATEGORIA);
|
2001-09-19 14:52:11 +00:00
|
|
|
|
if (cat > 40)
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
curr.zero(CESPI_CODCGR);
|
|
|
|
|
curr.zero(CESPI_CODSP);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-09-19 14:52:11 +00:00
|
|
|
|
curr.put(CESPI_CODCGR, m.get(F_GRUPPO));
|
|
|
|
|
curr.put(CESPI_CODSP, m.get(F_SPECIE));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int err = TRelation_application::write(m);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-12 15:03:40 +00:00
|
|
|
|
bool TAnacespi::kill_cespite(const TString& idcespite, int lfile, int key)
|
2001-07-24 13:28:55 +00:00
|
|
|
|
{
|
|
|
|
|
TRelation rel(lfile);
|
|
|
|
|
TRectype& filter = rel.curr();
|
|
|
|
|
filter.put("IDCESPITE", idcespite);
|
|
|
|
|
TCursor cur(&rel, "", key, &filter, &filter);
|
2003-08-07 14:09:09 +00:00
|
|
|
|
const TRecnotype items = cur.items();
|
|
|
|
|
if (items > 0)
|
2002-02-26 16:20:19 +00:00
|
|
|
|
{
|
2003-08-07 14:09:09 +00:00
|
|
|
|
cur.freeze();
|
|
|
|
|
const TRectype& curr = rel.curr();
|
|
|
|
|
for (cur = 0L; cur.pos() < items; ++cur)
|
|
|
|
|
{
|
|
|
|
|
int err = curr.remove(rel.lfile());
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
return error_box(FR("Errore %d di cancellazione sul file %d"), err, lfile);
|
|
|
|
|
}
|
2002-02-26 16:20:19 +00:00
|
|
|
|
}
|
2003-05-12 15:03:40 +00:00
|
|
|
|
return TRUE;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAnacespi::remove()
|
|
|
|
|
{
|
|
|
|
|
const int staat = _qmask->stato_attivita();
|
|
|
|
|
bool yes = FALSE;
|
2001-09-19 14:52:11 +00:00
|
|
|
|
if (staat == 3)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
yes = yesno_box(TR("ATTENZIONE: il cespite <20> gi<67> stato stampato su bollato.\n"
|
|
|
|
|
"Si desidera confermare l'elimininazione?"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
else
|
2003-05-12 15:03:40 +00:00
|
|
|
|
yes = yesno_box(TR("ATTENZIONE: verranno eliminati anche i valori relativi agli esercizi precedenti.\n"
|
|
|
|
|
"Si desidera confermare l'elimininazione?"));
|
2001-07-24 13:28:55 +00:00
|
|
|
|
|
|
|
|
|
if (yes)
|
2003-05-12 15:03:40 +00:00
|
|
|
|
{
|
2003-08-07 14:09:09 +00:00
|
|
|
|
TRelation* rel = get_relation();
|
|
|
|
|
const TString16 idcespite = rel->curr().get(CESPI_IDCESPITE);
|
2003-05-12 15:03:40 +00:00
|
|
|
|
|
|
|
|
|
if (kill_cespite(idcespite, LF_SALCE) && kill_cespite(idcespite, LF_MOVCE, 2) &&
|
|
|
|
|
kill_cespite(idcespite, LF_MOVAM) && kill_cespite(idcespite, LF_AMMMV) &&
|
|
|
|
|
kill_cespite(idcespite, LF_AMMCE))
|
2003-08-07 14:09:09 +00:00
|
|
|
|
{
|
|
|
|
|
rel->write_enable(0, FALSE); // Disabilito la cancellazione dei saldi (gia' cancellati prima)
|
|
|
|
|
yes = TRelation_application::remove();
|
|
|
|
|
rel->write_enable(0, TRUE);
|
|
|
|
|
}
|
2003-05-12 15:03:40 +00:00
|
|
|
|
}
|
2003-08-07 14:09:09 +00:00
|
|
|
|
return yes;
|
2001-07-24 13:28:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool TAnacespi::user_create()
|
|
|
|
|
{
|
2001-09-19 14:52:11 +00:00
|
|
|
|
open_files(LF_TABCOM, LF_TAB, LF_CESPI, LF_SALCE, LF_AMMCE, LF_MOVCE, LF_MOVAM, LF_AMMMV, 0);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
_cespiti = NULL;
|
|
|
|
|
_rel_year = 0;
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
_qmask = new TQuery_mask;
|
|
|
|
|
_emask = new TEdit_mask;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAnacespi::user_destroy()
|
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
delete _cespiti;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
delete _emask;
|
|
|
|
|
delete _qmask;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ce0500(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TAnacespi a;
|
2003-05-12 15:03:40 +00:00
|
|
|
|
a.run(argc, argv, TR("Anagrafica cespiti"));
|
2001-04-30 14:22:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|