Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione aga 1.7 patch 126 sul main trunk git-svn-id: svn://10.65.10.50/trunk@9819 c028cbd2-c16b-5b4b-a496-9718f37d4682
482 lines
15 KiB
C++
Executable File
482 lines
15 KiB
C++
Executable File
#include <defmask.h>
|
||
#include <recarray.h>
|
||
#include <relapp.h>
|
||
#include <sheet.h>
|
||
#include <utility.h>
|
||
|
||
#include "ce1.h"
|
||
#include "ce2101.h"
|
||
#include "celib.h"
|
||
|
||
#include "ce1301a.h"
|
||
//#include "ce1301b.h"
|
||
#include "../cg/cglib01.h"
|
||
|
||
|
||
#include "cespi.h"
|
||
#include "salce.h"
|
||
#include "ammce.h"
|
||
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Maschera di selezione
|
||
class TSelect_ammoces_qmask : public TAutomask
|
||
{
|
||
int _staat;
|
||
real _residuof, _residuoc;
|
||
|
||
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; }
|
||
real get_residuof() const { return _residuof; }
|
||
real get_residuoc() const { return _residuoc; }
|
||
void calc_res(bool prec);
|
||
|
||
TSelect_ammoces_qmask();
|
||
};
|
||
|
||
void TSelect_ammoces_qmask::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 TSelect_ammoces_qmask::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 TSelect_ammoces_qmask::cespite_ok() const
|
||
{
|
||
TLocalisamfile cespi(LF_CESPI);
|
||
cespi.put(CESPI_IDCESPITE, get(F_IDCESPITE));
|
||
bool ok = cespi.read() == NOERR;
|
||
return ok;
|
||
}
|
||
|
||
void TSelect_ammoces_qmask::calc_res(bool prec)
|
||
{
|
||
TCespite ces (get(F_IDCESPITE));
|
||
// calcolo ammortamento sul cespite (per sit. fiscale(1) e civilistica(2))
|
||
TDate fine_es = get(F_FINE_ES);
|
||
ces.calc_amm(1, FALSE, fine_es);
|
||
const TRectype& salce2=ces.sal_pro(); //rectype gi<67> di "tipo fiscale"
|
||
const TRectype& ammce2=ces.amm_pro();
|
||
// determinazione del residuo fiscale
|
||
_residuof = ZERO;
|
||
_residuof = salce2.get_real(SALCE_CSTO)-salce2.get_real(SALCE_VNONAMM)+salce2.get_real(SALCE_RIV75)+salce2.get_real(SALCE_RIV83)+salce2.get_real(SALCE_RIV90)+salce2.get_real(SALCE_RIV91)+salce2.get_real(SALCE_RIVGF);
|
||
_residuof -= ammce2.get_real(AMMCE_QNORP)+ammce2.get_real(AMMCE_QACCP)+ammce2.get_real(AMMCE_QANTP)+ammce2.get_real(AMMCE_QPERSEP)+ammce2.get_real(AMMCE_FPRIVATOP)+ammce2.get_real(AMMCE_QPPRIVATEP);
|
||
if (!prec)
|
||
_residuof -= ammce2.get_real(AMMCE_QNOR)+ammce2.get_real(AMMCE_QACC)+ammce2.get_real(AMMCE_QANT)+ammce2.get_real(AMMCE_QPERSE)+ammce2.get_real(AMMCE_FPRIVATO)+ammce2.get_real(AMMCE_QPPRIVATE);
|
||
|
||
ces.calc_amm(2, FALSE, fine_es);
|
||
//rectype gi<67> di "tipo civilistico"
|
||
// determinazione del residuo civilistico
|
||
_residuoc = ZERO;
|
||
_residuoc = salce2.get_real(SALCE_CSTO)+salce2.get_real(SALCE_RIV75)+salce2.get_real(SALCE_RIV83)+salce2.get_real(SALCE_RIV90)+salce2.get_real(SALCE_RIV91)+salce2.get_real(SALCE_RIVGC);
|
||
_residuoc -= ammce2.get_real(AMMCE_QNORP)+ammce2.get_real(AMMCE_QACCP)+ammce2.get_real(AMMCE_QANTP);
|
||
if (!prec)
|
||
_residuoc -= ammce2.get_real(AMMCE_QNOR)+ammce2.get_real(AMMCE_QACC)+ammce2.get_real(AMMCE_QANT);
|
||
}
|
||
|
||
|
||
bool TSelect_ammoces_qmask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_ESERCIZIO:
|
||
if (e == fe_close)
|
||
calcola_stato_attivita();
|
||
break;
|
||
|
||
case F_SEARCH1:
|
||
case F_SEARCH2:
|
||
case F_SEARCH3:
|
||
if (e == fe_button)
|
||
on_search_event(o);
|
||
break;
|
||
|
||
case F_IDCESPITE: //<2F> come fare l'OR (F_IDCESPITE || F_IDCESPITE_I)
|
||
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)
|
||
warning_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");
|
||
|
||
calc_res(TRUE); // controllo dei residui fiscale e civilistico in ingresso (prec=TRUE)
|
||
if (_residuof==ZERO)
|
||
return error_box("Impossibile forzare ammortamento perch<63> non esiste residuo fiscale da ammortizzare per il cespite");
|
||
|
||
if (_residuoc==ZERO)
|
||
return error_box("Impossibile forzare ammortamento perch<63> non esiste residuo civilistico da ammortizzare per il cespite");
|
||
|
||
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
TSelect_ammoces_qmask::TSelect_ammoces_qmask() : TAutomask("ce1301a")
|
||
{
|
||
first_focus(F_IDCESPITE);
|
||
}
|
||
/*
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Maschera di selezione ammortamento sul cespite
|
||
class TSelect_ammoces_smask : public TAutomask
|
||
{
|
||
TTipo_cespite _tipo;
|
||
int _staat;
|
||
real _residuof_ini,_residuoc_ini;
|
||
|
||
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; }
|
||
|
||
void set_residuof_ini(const real& rfini) { _residuof_ini = rfini; }
|
||
void set_residuoc_ini(const real& rcini) { _residuoc_ini = rcini; }
|
||
|
||
TSelect_ammoces_smask() : TAutomask("ce1301b") { }
|
||
};
|
||
|
||
|
||
bool TForce_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
bool ok = TRUE;
|
||
switch (o.dlg())
|
||
{
|
||
case F_CATEGORIA:
|
||
ditta_cespiti().on_category_event(o, e, jolly);
|
||
break;
|
||
|
||
case F_FORZATURA_Q_F: //gestione reset dei vari checkbox di forzatura
|
||
if (e==fe_modify && o.get()=="X" && get(F_FORZATURA_P_F)=="X")
|
||
reset(F_FORZATURA_P_F);
|
||
break;
|
||
|
||
case F_FORZATURA_P_F:
|
||
if (e==fe_modify && o.get()=="X" && get(F_FORZATURA_Q_F)=="X")
|
||
reset(F_FORZATURA_Q_F);
|
||
break;
|
||
|
||
case F_FORZATURA_Q_C:
|
||
if (e==fe_modify && o.get()=="X" && get(F_FORZATURA_P_C)=="X")
|
||
reset(F_FORZATURA_P_C);
|
||
break;
|
||
|
||
case F_FORZATURA_P_C:
|
||
if (e==fe_modify && o.get()=="X" && get(F_FORZATURA_Q_C)=="X")
|
||
reset(F_FORZATURA_Q_C);
|
||
break;
|
||
|
||
case F_AMMNOR_F: // controlla che residuof sia < della somma dei campi quota fiscali (al variare di
|
||
case F_AMMACC_F: // ognuno dei campi quota componenti, in modo che in caso di errore il campo sia
|
||
case F_AMMANT_F: // subito identificato
|
||
case F_QUOTE_PERSE:
|
||
case F_PRIVATO:
|
||
case F_QUOTE_PRIV:
|
||
if (e==fe_close||e==fe_modify)
|
||
{
|
||
real sumf = get_real(F_AMMNOR_F)+get_real(F_AMMACC_F)+get_real(F_AMMANT_F)+get_real(F_QUOTE_PERSE)+get_real(F_PRIVATO)+get_real(F_QUOTE_PRIV);
|
||
if (sumf > _residuof_ini)
|
||
return error_box("Attenzione: l'ammortamento richiesto supera il residuo fiscale del cespite");
|
||
}
|
||
break;
|
||
case F_AMMNOR_C: // controlla che residuoc sia < della somma dei campi quota civilistici
|
||
case F_AMMACC_C:
|
||
case F_AMMANT_C:
|
||
if (e==fe_close||e==fe_modify)
|
||
{
|
||
real sumc = get_real(F_AMMNOR_C)+get_real(F_AMMACC_C)+get_real(F_AMMANT_C);
|
||
if (sumc > _residuoc_ini)
|
||
return error_box("Attenzione: l'ammortamento richiesto supera il residuo civilistico del cespite");
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return ok;
|
||
} */
|
||
|
||
//-----------------------------------------------------------------------------------------------------------------------//
|
||
//Applicazione
|
||
class TSelect_ammoces : public TRelation_application
|
||
{
|
||
TRelation* _ammce;
|
||
|
||
TSelect_ammoces_qmask* _qmask;
|
||
// TSelect_ammoces_smask* _smask;
|
||
|
||
private:
|
||
void protect_fields(TMask& m, TToken_string& enabling) const;
|
||
void init_mask(TMask& m);
|
||
void update_amm(const TMask& m);
|
||
|
||
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;
|
||
|
||
virtual void init_query_mode(TMask& m);
|
||
virtual void init_modify_mode(TMask& m);
|
||
virtual int write(const TMask& m);
|
||
virtual int rewrite(const TMask& m);
|
||
|
||
};
|
||
|
||
bool TSelect_ammoces::changing_mask(int)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
TMask* TSelect_ammoces::get_mask(int mode)
|
||
{
|
||
// return mode == MODE_QUERY ? (TMask*)_qmask : (TMask*)_smask;
|
||
return mode == MODE_QUERY ? (TMask*)_qmask : (TMask*)_qmask;
|
||
}
|
||
|
||
TRelation* TSelect_ammoces::get_relation() const
|
||
{
|
||
return _ammce;
|
||
}
|
||
|
||
void TSelect_ammoces::init_query_mode(TMask& m)
|
||
{
|
||
ditta_cespiti().init_mask(m);
|
||
}
|
||
|
||
void TSelect_ammoces::init_mask(TMask& m)
|
||
{
|
||
TDitta_cespiti& dc = ditta_cespiti(); //se il bollato dell'esercizio <20> stato stampato inibisce il REGISTRA
|
||
dc.init_mask(m);
|
||
const bool can_edit = !dc.bollato_stampato() ;
|
||
m.enable(DLG_SAVEREC, can_edit);
|
||
m.enable(DLG_DELREC, can_edit);
|
||
|
||
/* _smask->set_stato_attivita(_qmask->stato_attivita()); //copia lo stato attivit<69> della precedente
|
||
|
||
_qmask->calc_res(TRUE); //calcola residuo precedente (prec=TRUE)
|
||
_smask->set_residuof_ini(_qmask->get_residuof()); //memorizza i residui precedenti nella maschera (non a video)
|
||
_smask->set_residuoc_ini(_qmask->get_residuoc());
|
||
|
||
_qmask->calc_res(FALSE); // ricalcola il residuo fiscale e civilistico in forzatura (prec=FALSE)
|
||
_smask->set(F_RESIDUO_F, _qmask->get_residuof()); //prende il residuo fiscale (civilistico) del cespite calcolato
|
||
_smask->set(F_RESIDUO_C, _qmask->get_residuoc()); //nella maschera di selezione e lo mette nella maschera di forzatura
|
||
*/}
|
||
|
||
|
||
void TSelect_ammoces::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 TSelect_ammoces::init_modify_mode(TMask& m)
|
||
{
|
||
init_mask(m);
|
||
|
||
/* const bool accendiforzatura=_smask->stato_attivita()!=1;
|
||
m.enable(F_FORZATURA_Q_F, accendiforzatura); //abilita i checks della forzatura quando il bollato NON <20> stampato
|
||
m.enable(F_FORZATURA_P_F, accendiforzatura);
|
||
m.enable(F_FORZATURA_Q_C, accendiforzatura);
|
||
m.enable(F_FORZATURA_P_C, accendiforzatura);
|
||
|
||
if (accendiforzatura) //se lo stato attivit<69> lascia liberi di forzare, controlla se il tipocespite fa altrettanto...
|
||
{
|
||
TCespite ces(m.get(F_IDCESPITE));
|
||
const TRectype& cac = ces.categoria();
|
||
switch (ces.tipo())
|
||
{
|
||
case tc_immateriale:
|
||
if (cac.get_int("I1")!=0)
|
||
{
|
||
m.disable(F_FORZATURA_P_F);
|
||
m.disable(F_FORZATURA_P_C);
|
||
}
|
||
break;
|
||
|
||
case tc_pluriennale:
|
||
if (cac.get_int("I2")==3)
|
||
{
|
||
m.disable(F_FORZATURA_P_F);
|
||
m.disable(F_FORZATURA_P_C);
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
// aggiornamento della colonna dei valori risultanti
|
||
m.set(F_RIS_AMMNOR_F, m.get_real(F_AMMNOR_F));
|
||
m.set(F_RIS_AMMACC_F, m.get_real(F_AMMACC_F));
|
||
m.set(F_RIS_AMMANT_F, m.get_real(F_AMMANT_F));
|
||
m.set(F_RIS_QUOTE_PERSE, m.get_real(F_QUOTE_PERSE));
|
||
m.set(F_RIS_PRIVATO, m.get_real(F_PRIVATO));
|
||
m.set(F_RIS_QUOTE_PRIV, m.get_real(F_QUOTE_PRIV));
|
||
|
||
m.set(F_RIS_AMMNOR_C, m.get_real(F_AMMNOR_C));
|
||
m.set(F_RIS_AMMACC_C, m.get_real(F_AMMACC_C));
|
||
m.set(F_RIS_AMMANT_C, m.get_real(F_AMMANT_C)); */
|
||
}
|
||
|
||
// funzione per il ricalcolo degli ammortamenti dopo la forzatura
|
||
void TSelect_ammoces::update_amm(const TMask& m)
|
||
{
|
||
TCespite ces(m.get(F_IDCESPITE));
|
||
TDate fine_es = m.get_date(F_FINE_ES);
|
||
ces.calc_amm(1, FALSE, fine_es);
|
||
ces.calc_amm(2, FALSE, fine_es);
|
||
}
|
||
|
||
|
||
//funzione per il ricalcolo automatico dei valori degli ammortamenti dopo la forzatura (in caso di prima forzatura)
|
||
int TSelect_ammoces::write(const TMask& m)
|
||
{
|
||
int err = TRelation_application::write(m);
|
||
if (err==NOERR)
|
||
update_amm(m);
|
||
return err;
|
||
}
|
||
|
||
//funzione per il ricalcolo automatico dei valori degli ammortamenti dopo la forzatura
|
||
int TSelect_ammoces::rewrite(const TMask& m)
|
||
{
|
||
int err = TRelation_application::rewrite(m);
|
||
if (err==NOERR)
|
||
update_amm(m);
|
||
return err;
|
||
}
|
||
|
||
bool TSelect_ammoces::user_create()
|
||
{
|
||
open_files(LF_TABCOM, LF_TAB, LF_CESPI, LF_SALCE, LF_AMMCE, 0);
|
||
_ammce = new TRelation (LF_AMMCE); // relazione principale su AMMCE
|
||
TString expr;
|
||
expr << "IDCESPITE==IDCESPITE|CODES==CODES|TPSALDO==TPSALDO|TPAMM==2"; //seconda relazione su AMMCE
|
||
_ammce->add(LF_AMMCE, expr, 1, 0, 69); //69 <20> l'alias di AMMCE
|
||
_ammce->write_enable(-69); //abilita la scrittura su secondo AMMCE
|
||
_ammce->add(LF_CESPI, "IDCESPITE==IDCESPITE"); //estende la relazione con CESPI
|
||
|
||
_qmask = new TSelect_ammoces_qmask;
|
||
// _smask = new TForce_mask;
|
||
return TRUE;
|
||
}
|
||
|
||
bool TSelect_ammoces::user_destroy()
|
||
{
|
||
// delete _smask;
|
||
delete _qmask;
|
||
delete _ammce;
|
||
return TRUE;
|
||
}
|
||
|
||
int ce1300(int argc, char* argv[])
|
||
{
|
||
TSelect_ammoces a;
|
||
a.run(argc, argv, "Scelta ammortamento per cespite");
|
||
return 0;
|
||
}
|
||
|