Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 1.7 aga patch 102 sul main trunk git-svn-id: svn://10.65.10.50/trunk@9769 c028cbd2-c16b-5b4b-a496-9718f37d4682
491 lines
13 KiB
C++
Executable File
491 lines
13 KiB
C++
Executable File
#include <defmask.h>
|
||
#include <recarray.h>
|
||
#include <relapp.h>
|
||
#include <sheet.h>
|
||
#include <utility.h>
|
||
|
||
#include "ce0.h"
|
||
#include "ce2101.h"
|
||
#include "celib.h"
|
||
|
||
#include "ce1101a.h"
|
||
#include "ce1101b.h"
|
||
#include "../cg/cglib01.h"
|
||
|
||
|
||
#include "cespi.h"
|
||
#include "salce.h"
|
||
#include "ammce.h"
|
||
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Maschera di selezione
|
||
class TQuery_mask : public TAutomask
|
||
{
|
||
int _staat;
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
void on_search_event(TOperable_field& o);
|
||
|
||
int calcola_stato_attivita();
|
||
bool cespite_ok() const;
|
||
|
||
public:
|
||
int stato_attivita() const { return _staat; }
|
||
|
||
TQuery_mask();
|
||
};
|
||
|
||
void TQuery_mask::on_search_event(TOperable_field& o)
|
||
{
|
||
TToken_string order, fields, header;
|
||
if (o.dlg() >= F_SEARCH3)
|
||
{
|
||
order.add(CESPI_STABILIM); header.add("Stabilimento");
|
||
order.add(CESPI_REPARTO); header.add("Reparto@10");
|
||
}
|
||
if (o.dlg() >= F_SEARCH2)
|
||
{
|
||
order.add(CESPI_CODIMP); header.add("Impianto@10");
|
||
}
|
||
if (o.dlg() >= F_SEARCH1)
|
||
{
|
||
order.add(CESPI_CODCAT); header.add("Cat");
|
||
order.add(CESPI_DTCOMP); header.add("Data Acq.@10");
|
||
}
|
||
|
||
order.add(CESPI_IDCESPITE); header.add("Codice@10");
|
||
|
||
fields = order;
|
||
fields.add(CESPI_DESC); header.add("Descrizione@50");
|
||
|
||
TRelation rel(LF_CESPI);
|
||
|
||
TString filter;
|
||
if (!field(F_IMPIANTO).empty())
|
||
filter << CESPI_CODIMP << "==" << get(F_IMPIANTO);
|
||
|
||
TSorted_cursor cur(&rel, order, filter);
|
||
TCursor_sheet sht(&cur, fields, "Cespiti", header, 0, 1);
|
||
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 = 1;
|
||
|
||
TDitta_cespiti& dc = ditta_cespiti();
|
||
dc.set_attivita(ese, gru, spe);
|
||
|
||
return _staat;
|
||
}
|
||
|
||
bool TQuery_mask::cespite_ok() const
|
||
{
|
||
TLocalisamfile cespi(LF_CESPI);
|
||
cespi.put(CESPI_IDCESPITE, get(F_IDCESPITE));
|
||
bool ok = cespi.read() == NOERR;
|
||
return ok;
|
||
}
|
||
|
||
bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_ESERCIZIO:
|
||
case F_GRUPPO:
|
||
case F_SPECIE:
|
||
/* if (e == fe_close)
|
||
{
|
||
const bool can_edit = calcola_stato_attivita() != 1; // Bollato non stampato (se =1 -> bollato stampato)
|
||
enable(DLG_NEWREC, can_edit);
|
||
} */
|
||
break;
|
||
case F_SEARCH1:
|
||
case F_SEARCH2:
|
||
case F_SEARCH3:
|
||
if (e == fe_button)
|
||
on_search_event(o);
|
||
break;
|
||
case F_IDCESPITE:
|
||
case F_IDCESPITE_I:
|
||
if (e == fe_close)
|
||
{
|
||
if (!cespite_ok())
|
||
return error_box("Inserire un cespite valido"); //controlla che esista il cespite
|
||
if (stato_attivita() == 1)
|
||
return error_box("E' stato stampato il bollato dell'anno:\nnon sono permesse forzature"); //il bollato <20> stato stampato
|
||
|
||
TLocalisamfile salce(LF_SALCE); // controlla che esista almeno un saldo
|
||
salce.put(SALCE_IDCESPITE, get(F_IDCESPITE));
|
||
salce.put(SALCE_CODES, get(F_ESERCIZIO));
|
||
salce.put(SALCE_TPSALDO, 1);
|
||
if (salce.read() != NOERR)
|
||
return error_box("Non esistono saldi per l'anno selezionato");
|
||
|
||
TLocalisamfile ammce(LF_AMMCE); // controlla che esista almeno un ammortamento (senn<6E> che forzamo?)
|
||
ammce.put(AMMCE_IDCESPITE, get(F_IDCESPITE));
|
||
ammce.put(AMMCE_CODES, get(F_ESERCIZIO));
|
||
ammce.put(AMMCE_TPSALDO, 1);
|
||
ammce.put(AMMCE_TPAMM, 1);
|
||
if (ammce.read() != NOERR)
|
||
return error_box("Non esistono ammortamenti per l'anno selezionato");
|
||
|
||
TCespite ces (get(F_IDCESPITE)); // controlla che la categoria del cespite sia ammortizzabile
|
||
const TRectype& categoria = ces.categoria();
|
||
bool non_ammortizzabile = categoria.get_bool("B0");
|
||
if (non_ammortizzabile)
|
||
return error_box("La categoria del cespite selezionato non <20> ammortizzabile");
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
TQuery_mask::TQuery_mask() : TAutomask("ce1101a")
|
||
{
|
||
first_focus(F_IDCESPITE);
|
||
}
|
||
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Maschera di forzatura
|
||
class TForce_mask : public TAutomask
|
||
{
|
||
TTipo_cespite _tipo;
|
||
int _staat;
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
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; }
|
||
|
||
TForce_mask() : TAutomask("ce1101b") { }
|
||
};
|
||
|
||
bool TForce_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
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:
|
||
if (e == fe_modify || e == fe_close)
|
||
{
|
||
const TDate dtcomp = o.get();
|
||
TDitta_cespiti& dc = ditta_cespiti();
|
||
TDate iniz, fine;
|
||
const int ese = dc.esercizio_corrente(iniz, fine);
|
||
|
||
if (insert_mode() && stato_attivita() == 2)
|
||
{
|
||
if (dtcomp < iniz)
|
||
return error_box("La data appartiene ad un esercizio gi<67> stampato su bollato");
|
||
const TRectype& cac = dc.categoria(0, NULL, get_int(F_CATEGORIA));
|
||
iniz = cac.get("D0");
|
||
if (iniz.ok() && dtcomp < iniz)
|
||
return error_box("La data <20> precedente all'inizio della validit<69> della categoria");
|
||
fine = cac.get("D1");
|
||
if (fine.ok() && dtcomp > fine)
|
||
return error_box("La data <20> succesiva alla fine della validit<69> della categoria");
|
||
}
|
||
if (dc.esercizio_costituzione() && dtcomp < iniz)
|
||
return error_box("Non <20> possibile specificare una data antecedente all'eserczio di costituzione");
|
||
}
|
||
break;
|
||
case F_DTFUNZ:
|
||
if (e == fe_modify || e == fe_close)
|
||
{
|
||
TDitta_cespiti& dc = ditta_cespiti();
|
||
const TDate dtcomp = field(F_DTCOMP).get();
|
||
const TDate dtfunz = o.get();
|
||
if (dtfunz < dtcomp)
|
||
return error_box("La data di entrata in funzione deve essere successiva a quella di aquisizione");
|
||
if (dtfunz.ok() && !dtcomp.ok())
|
||
return error_box("La data di entrata in funzione non puo' essere inserita senza specificare quella di aquisizione");
|
||
if (_tipo != tc_materiale && dtfunz != dtcomp)
|
||
{
|
||
if (dtcomp.year() >= dc.anno_tuir())
|
||
return error_box("In base alla normativa del TUIR, le date di acquisizione e di entrata in funzione devono coincidere");
|
||
}
|
||
if (dtfunz.ok())
|
||
{
|
||
const TRectype& cac = dc.categoria(0, NULL, get_int(F_CATEGORIA));
|
||
const TDate iniz = cac.get("D0");
|
||
if (iniz.ok() && dtfunz < iniz)
|
||
return error_box("La data <20> precedente all'inizio della validit<69> della categoria");
|
||
const TDate fine = cac.get("D1");
|
||
if (fine.ok() && dtcomp > fine)
|
||
return error_box("La data <20> succesiva alla fine della validit<69> della categoria");
|
||
set(F_TUIR, dtfunz.year() >= dc.anno_tuir() ? "X" : "");
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
} */
|
||
return ok;
|
||
}
|
||
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Applicazione
|
||
class TForza_amm_cespi : public TRelation_application
|
||
{
|
||
TRelation* _cespiti;
|
||
int _rel_year;
|
||
|
||
TQuery_mask* _qmask;
|
||
TForce_mask* _fmask;
|
||
|
||
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;
|
||
|
||
void protect_fields(TMask& m, TToken_string& enabling) const;
|
||
void init_mask(TMask& m);
|
||
|
||
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);
|
||
};
|
||
|
||
bool TForza_amm_cespi::changing_mask(int)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
TMask* TForza_amm_cespi::get_mask(int mode)
|
||
{
|
||
return mode == MODE_QUERY ? (TMask*)_qmask : (TMask*)_fmask;
|
||
}
|
||
|
||
// get_relation pi<70> complessa della storia di campo
|
||
TRelation* TForza_amm_cespi::get_relation() const
|
||
{
|
||
const int year = _qmask->get_int(F_ESERCIZIO);
|
||
TRelation*& csp = ((TForza_amm_cespi*)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);
|
||
((TForza_amm_cespi*)this)->_rel_year = year; // Memorizza anno utilizzato
|
||
|
||
// Collega salce
|
||
TString80 expr1;
|
||
expr1 << SALCE_IDCESPITE << "==" << CESPI_IDCESPITE;
|
||
if (year > 0)
|
||
expr1 << '|' << SALCE_CODES << "==" << year;
|
||
csp->add(LF_SALCE, expr1);
|
||
|
||
// Collega i tre tipi di ammce
|
||
TString80 expr2;
|
||
for (int a = 1; a <= 3; a++)
|
||
{
|
||
expr2 = expr1;
|
||
expr2 << '|' << AMMCE_TPAMM << "==" << a;
|
||
csp->add(LF_AMMCE, expr2, 1, 0, LF_AMMCE+100*(a-1));
|
||
}
|
||
|
||
// Attiva il salvataggio anche di salce e ammce
|
||
csp->write_enable();
|
||
}
|
||
|
||
return _cespiti;
|
||
}
|
||
|
||
void TForza_amm_cespi::init_query_mode(TMask& m)
|
||
{
|
||
ditta_cespiti().init_mask(m);
|
||
}
|
||
|
||
bool TForza_amm_cespi::protected_record(TRectype& rec)
|
||
{
|
||
const TDate dtalien = rec.get(CESPI_DTALIEN);
|
||
return dtalien.ok();
|
||
}
|
||
|
||
void TForza_amm_cespi::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);
|
||
m.enable(DLG_DELREC, can_edit);
|
||
|
||
_fmask->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");
|
||
_fmask->set_tipo_cespite(tc==0 ? tc_materiale : (tc==1 ? tc_immateriale : tc_pluriennale));
|
||
|
||
const bool mat_only = _fmask->tipo_cespite() == tc_materiale;
|
||
// m.show(F_LEASING, mat_only);
|
||
// m.show(F_ANNIRIC, mat_only);
|
||
// m.show(F_USATO, mat_only);
|
||
}
|
||
|
||
void TForza_amm_cespi::init_insert_mode(TMask& m)
|
||
{
|
||
init_mask(m);
|
||
// m.enable(F_DTALIEN);
|
||
// m.set(F_TUIR, "X");
|
||
// m.set(F_SPEMAN, _fmask->tipo_cespite() == tc_materiale ? 2 : 1);
|
||
// m.set(F_ESCLPR, _fmask->tipo_cespite() != tc_pluriennale ? "X" : "");
|
||
}
|
||
|
||
void TForza_amm_cespi::protect_fields(TMask& m, TToken_string& enabling) const
|
||
{
|
||
for (int f = m.fields()-1; f >= 0; f--)
|
||
{
|
||
TMask_field& fld = m.fld(f);
|
||
const short id = fld.dlg();
|
||
if (id > 100 && id < 1000 && fld.is_editable() && fld.enabled_default())
|
||
{
|
||
const bool on = enabling.empty() || enabling.get_pos(fld.dlg()) >= 0;
|
||
fld.enable(on);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TForza_amm_cespi::init_modify_mode(TMask& m)
|
||
{
|
||
init_mask(m);
|
||
/* m.disable(F_DTALIEN);
|
||
|
||
TDitta_cespiti& dc = ditta_cespiti();
|
||
TDate iniz, fine;
|
||
const int ese = dc.esercizio_corrente(iniz, fine);
|
||
const TDate dtacq = m.get(F_DTCOMP);
|
||
const TDate dtfunz = m.get(F_DTFUNZ);
|
||
|
||
TToken_string enabling;
|
||
|
||
switch (_qmask->stato_attivita())
|
||
{
|
||
case 2:
|
||
if (dtacq.ok())
|
||
{
|
||
if (dtacq < iniz)
|
||
{
|
||
if (!dtfunz.ok() || dtfunz >= iniz)
|
||
{
|
||
enabling.add(F_DTFUNZ);
|
||
enabling.add(F_SPEMAN);
|
||
enabling.add(F_USOPROM);
|
||
}
|
||
else
|
||
{
|
||
enabling.add(F_SPEMAN);
|
||
enabling.add(F_USOPROM);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!dtfunz.ok())
|
||
{
|
||
enabling.add(F_DTCOMP);
|
||
enabling.add(F_DTFUNZ);
|
||
enabling.add(F_SPEMAN);
|
||
enabling.add(F_USOPROM);
|
||
}
|
||
}
|
||
break;
|
||
case 3:
|
||
if (!dtfunz.ok() || dtfunz >= iniz)
|
||
{
|
||
enabling.add(F_DTFUNZ);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
protect_fields(m, enabling); */
|
||
}
|
||
|
||
const char* TForza_amm_cespi::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 TForza_amm_cespi::read(TMask& m)
|
||
{
|
||
int err = TRelation_application::read(m);
|
||
return err;
|
||
}
|
||
|
||
bool TForza_amm_cespi::user_create()
|
||
{
|
||
open_files(LF_TABCOM, LF_TAB, LF_CESPI, LF_SALCE, LF_AMMCE, 0);
|
||
_cespiti = NULL;
|
||
_rel_year = 0;
|
||
|
||
_qmask = new TQuery_mask;
|
||
_fmask = new TForce_mask;
|
||
return TRUE;
|
||
}
|
||
|
||
bool TForza_amm_cespi::user_destroy()
|
||
{
|
||
delete _fmask;
|
||
delete _qmask;
|
||
delete _cespiti;
|
||
return TRUE;
|
||
}
|
||
|
||
int ce1100(int argc, char* argv[])
|
||
{
|
||
TForza_amm_cespi a;
|
||
a.run(argc, argv, "Forzatura ammortamento su cespiti");
|
||
return 0;
|
||
}
|
||
|