9b5f9351b3
Files correlati : Ricompilazione Demo : [ ] Commento : Rivisto programma ripartizione cespiti (no obbligatorietà date utilizzo e percentuali) Aggiunto il programma di stampa dei cespiti in analitica (prima stesura) git-svn-id: svn://10.65.10.50/trunk@20570 c028cbd2-c16b-5b4b-a496-9718f37d4682
352 lines
9.3 KiB
C++
Executable File
352 lines
9.3 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <dongle.h>
|
||
#include <modaut.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <reprint.h>
|
||
|
||
#include "celib.h"
|
||
#include "ce2101.h"
|
||
|
||
#include "ammce.h"
|
||
#include "ammmv.h"
|
||
#include "cespi.h"
|
||
#include "movam.h"
|
||
#include "salce.h"
|
||
#include "salcecms.h"
|
||
|
||
#include "ce4.h"
|
||
#include "ce4500a.h"
|
||
|
||
////////////////////////////////////////////////////////
|
||
// MASCHERA
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_anal_cespi_mask : public TAutomask
|
||
{
|
||
bool _preview;
|
||
|
||
protected:
|
||
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
public:
|
||
bool preview() const { return _preview; }
|
||
TPrint_anal_cespi_mask();
|
||
};
|
||
|
||
|
||
bool TPrint_anal_cespi_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case DLG_PRINT:
|
||
if (e == fe_button)
|
||
_preview = false;
|
||
break;
|
||
case DLG_PREVIEW:
|
||
if (e == fe_button)
|
||
{
|
||
_preview = true;
|
||
stop_run(K_ENTER);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TPrint_anal_cespi_mask::TPrint_anal_cespi_mask() : TAutomask("ce4500a"), _preview(false)
|
||
{
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////////
|
||
// RECORDSET
|
||
///////////////////////////////////////////////////////////////
|
||
class TPrint_anal_cespi_recordset : public TISAM_recordset
|
||
{
|
||
public:
|
||
void set_filter(const TPrint_anal_cespi_mask& msk);
|
||
TPrint_anal_cespi_recordset(const TString& sql) : TISAM_recordset(sql) { }
|
||
};
|
||
|
||
|
||
//metodo per caricare i valori nel recordset dalla maschera...fighissimo!!
|
||
void TPrint_anal_cespi_recordset::set_filter(const TPrint_anal_cespi_mask& msk)
|
||
{
|
||
//magggica query
|
||
TString query = "USE SALCECMS KEY 2";
|
||
|
||
query << "\nSELECT (BETWEEN(CODCDC,#CODCDC,#CODCDC))&&(BETWEEN(CODCMS,#CODCMS,#CODCMS))&&(BETWEEN(CODFASE,#CODFASE,#CODFASE))";
|
||
|
||
//from-to sulla key 2 di salcecms
|
||
query << "\nFROM CODES=#CODES IDCESPITE=#IDCESPITE";
|
||
query << "\nTO CODES=#CODES IDCESPITE=#IDCESPITE";
|
||
|
||
//setta la nuova query nel report (che avrebbe solo USE SALCECMS KEY 2)
|
||
set(query);
|
||
|
||
//parte analitica
|
||
const int codes = msk.get_int(F_ESERCIZIO);
|
||
const TString& idcespite = msk.get(F_IDCESPITE);
|
||
const TString& codcdc = msk.get(F_CODCDC);
|
||
const TString& codcms = msk.get(F_CODCMS);
|
||
const TString& codfase = msk.get(F_CODFASE);
|
||
|
||
set_var("#CODES", long(codes));
|
||
set_var("#IDCESPITE", idcespite);
|
||
set_var("#CODCDC", codcdc);
|
||
set_var("#CODCMS", codcms);
|
||
set_var("#CODFASE", codfase);
|
||
|
||
const TRecnotype cazzo = items();
|
||
}
|
||
|
||
|
||
////////////////////////////////////////////////////////
|
||
// REPORT
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_anal_cespi_rep : public TReport
|
||
{
|
||
int _tpamm, _codes;
|
||
TString _codcdc, _codcms, _codfase;
|
||
TCespite _cespite;
|
||
|
||
protected:
|
||
real val_amm(const TRectype& rec_saldi) const;
|
||
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
||
virtual bool use_mask() { return false; }
|
||
|
||
public:
|
||
void set_filter(const TPrint_anal_cespi_mask& msk);
|
||
};
|
||
|
||
|
||
void TPrint_anal_cespi_rep::set_filter(const TPrint_anal_cespi_mask& msk)
|
||
{
|
||
//parametri presi dalla maschera; servono solo per essere riportati sul report in quanto <20>..
|
||
//..use_mask()=false; l'unico che serve per i conti <20> _tpamm (saldi cespite in base a _tpamm)
|
||
_tpamm = msk.get_int(F_SITUAZIONE);
|
||
_codcdc = msk.get(F_CODCDC);
|
||
_codcms = msk.get(F_CODCMS);
|
||
_codfase = msk.get(F_CODFASE);
|
||
|
||
TPrint_anal_cespi_recordset* rs = new TPrint_anal_cespi_recordset(EMPTY_STRING);
|
||
set_recordset(rs);
|
||
rs->set_filter(msk);
|
||
}
|
||
|
||
real TPrint_anal_cespi_rep::val_amm(const TRectype& rec_saldi) const
|
||
{
|
||
real valore = rec_saldi.get_real(SALCE_CSTO);
|
||
|
||
if (_tpamm == 1) //solo fiscale
|
||
valore -= rec_saldi.get_real(SALCE_VNONAMM06);
|
||
|
||
if (_tpamm == 2) //solo civilistico
|
||
{
|
||
valore -= rec_saldi.get_real(SALCE_VNONAMMC);
|
||
valore += rec_saldi.get_real(SALCE_RIVGC);
|
||
}
|
||
else //fiscale e/o gestionale
|
||
{
|
||
valore -= rec_saldi.get_real(SALCE_VNONAMM);
|
||
valore += rec_saldi.get_real(SALCE_RIVGF);
|
||
}
|
||
|
||
valore += rec_saldi.get_real(SALCE_RIV75);
|
||
valore += rec_saldi.get_real(SALCE_RIV83);
|
||
valore += rec_saldi.get_real(SALCE_RIV90);
|
||
valore += rec_saldi.get_real(SALCE_RIV91);
|
||
|
||
if (valore < ZERO)
|
||
valore = ZERO;
|
||
|
||
return valore;
|
||
}
|
||
|
||
//metodo per il calcolo dei campi da calcolare (ma va'!) nel report
|
||
bool TPrint_anal_cespi_rep::get_usr_val(const TString& name, TVariant& var) const
|
||
{
|
||
const TRecordset& recset = *recordset();
|
||
const TString& idcespite = recset.get(SALCECMS_IDCESPITE).as_string();
|
||
const TString& desc = cache().get(LF_CESPI, idcespite, CESPI_DESC);
|
||
const int codes = recset.get(SALCECMS_CODES).as_int();
|
||
const TString& codcdc = recset.get(SALCECMS_CODCDC).as_string();
|
||
const TString& codcms = recset.get(SALCECMS_CODCMS).as_string();
|
||
const TString& codfase = recset.get(SALCECMS_CODFASE).as_string();
|
||
const real percutil = recset.get(SALCECMS_PERCUTIL).as_real() / CENTO;
|
||
|
||
if (idcespite != _cespite.get(CESPI_IDCESPITE))
|
||
{
|
||
TCespite& c = (TCespite&)_cespite;
|
||
c.read(idcespite);
|
||
c.load_saldi(_tpamm, codes);
|
||
}
|
||
|
||
//CAMPI CESPITE
|
||
//-------------
|
||
if (name.starts_with("#DESC"))
|
||
{
|
||
var = desc;
|
||
return true;
|
||
}
|
||
|
||
if (name.starts_with("#VARIAZIONE")) //variazione del valore annuale (saldo finale - saldo iniziale)
|
||
{
|
||
const real val_fin = val_amm(_cespite.sal_pro());
|
||
const real val_ini = val_amm(_cespite.sal_ini());
|
||
var = (val_fin - val_ini) * percutil;
|
||
return true;
|
||
}
|
||
|
||
if (name == "#QAMMMV") //quote ammortamento su movimento esercizio corrente
|
||
{
|
||
real quote_ammmv;
|
||
const TArray& array_ammmv = _cespite.ammmv();
|
||
for (int i = 0; i < array_ammmv.items(); i++)
|
||
{
|
||
const TRectype& rec_ammmv = (const TRectype&)array_ammmv[i];
|
||
quote_ammmv += rec_ammmv.get_real(AMMMV_QNOR) + rec_ammmv.get_real(AMMMV_QACC) +
|
||
rec_ammmv.get_real(AMMMV_QANT) + rec_ammmv.get_real(AMMMV_QPERSE) +
|
||
rec_ammmv.get_real(AMMMV_QPPRIVATE) + rec_ammmv.get_real(AMMMV_FPRIVATO);
|
||
}
|
||
quote_ammmv *= percutil;
|
||
var = quote_ammmv;
|
||
return true;
|
||
}
|
||
|
||
if (name == "#QAMM") //quote ammortamento esercizio corrente
|
||
{
|
||
const TRectype& rec_ammce = _cespite.amm_pro();
|
||
real quote_amm = real(rec_ammce.get_real(AMMCE_QNOR) + rec_ammce.get_real(AMMCE_QACC) +
|
||
rec_ammce.get_real(AMMCE_QANT) + rec_ammce.get_real(AMMCE_QPERSE) +
|
||
rec_ammce.get_real(AMMCE_QPPRIVATE) + rec_ammce.get_real(AMMCE_FPRIVATO));
|
||
quote_amm *= percutil;
|
||
var = quote_amm;
|
||
return true;
|
||
}
|
||
|
||
if (name == "#QAMM_FPRIVATO") //fondo ammortamento privato corrente
|
||
{
|
||
const TRectype& rec_ammce = _cespite.amm_pro();
|
||
real famm = rec_ammce.get_real(AMMCE_FPRIVATO);
|
||
famm *= percutil;
|
||
var = famm;
|
||
return true;
|
||
}
|
||
|
||
if (name == "#PERCAMM") // percentuale ammortamento
|
||
{
|
||
real percamm;
|
||
real valamm = val_amm(_cespite.sal_ini());
|
||
if (valamm.is_zero()) // Non riesce a calcolare il valore ammortizzabile dei cespiti nuovi
|
||
{
|
||
const int anno_acq = _cespite.get_date(CESPI_DTCOMP).year();
|
||
if (anno_acq == codes)
|
||
{
|
||
valamm = val_amm(_cespite.sal_pro());
|
||
}
|
||
}
|
||
if (!valamm.is_zero())
|
||
{
|
||
TVariant qamm, qammmv;
|
||
get_usr_val("#QAMM", qamm);
|
||
get_usr_val("#QAMMMV", qammmv);
|
||
percamm = CENTO * (qamm.as_real() + qammmv.as_real()) / valamm;
|
||
percamm.round(1);
|
||
}
|
||
var = percamm;
|
||
return true;
|
||
}
|
||
|
||
if (name == "#CESSELIM") //cessioni elminiazioni
|
||
{
|
||
real cesselim;
|
||
const TArray& array_movam = _cespite.movam();
|
||
for (int i = 0; i < array_movam.items(); i++)
|
||
{
|
||
const TRectype& rec_movam = (const TRectype&)array_movam[i];
|
||
cesselim += rec_movam.get_real(MOVAM_QNOR) + rec_movam.get_real(MOVAM_QACC) +
|
||
rec_movam.get_real(MOVAM_QANT) + rec_movam.get_real(MOVAM_QPERSE) +
|
||
rec_movam.get_real(MOVAM_QPPRIVATE) + rec_movam.get_real(MOVAM_FPRIVATO);
|
||
}
|
||
cesselim *= percutil;
|
||
var = cesselim;
|
||
return true;
|
||
}
|
||
|
||
//CAMPI TESTATA (FILTRI)
|
||
//----------------------
|
||
if (name == "#CODCDC")
|
||
{
|
||
var.set(_codcdc);
|
||
return true;
|
||
}
|
||
if (name == "#CODCMS")
|
||
{
|
||
var.set(_codcms);
|
||
return true;
|
||
}
|
||
if (name == "#CODFASE")
|
||
{
|
||
var.set(_codfase);
|
||
return true;
|
||
}
|
||
if (name == "#SITUAZIONE") //tipo situazione da stampare in testata
|
||
{
|
||
var.set(_tpamm);
|
||
return true;
|
||
}
|
||
|
||
return TReport::get_usr_val(name, var);
|
||
}
|
||
|
||
////////////////////////////////////////////////////////
|
||
// APPLICAZIONE
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_anal_cespi : public TSkeleton_application
|
||
{
|
||
protected:
|
||
virtual bool create(void);
|
||
virtual void main_loop();
|
||
};
|
||
|
||
void TPrint_anal_cespi::main_loop()
|
||
{
|
||
TPrint_anal_cespi_mask mask;
|
||
while (mask.run() == K_ENTER)
|
||
{
|
||
//report e book dei report
|
||
TReport_book book;
|
||
TPrint_anal_cespi_rep rep;
|
||
rep.load("ce4500a");
|
||
|
||
rep.set_filter(mask);
|
||
book.add(rep);
|
||
|
||
//stampa il book dei report
|
||
if (mask.preview())
|
||
book.preview();
|
||
else
|
||
book.print();
|
||
}
|
||
}
|
||
|
||
bool TPrint_anal_cespi::create()
|
||
{
|
||
const bool has_ca = dongle().active(CAAUT);
|
||
//se la chiave non ha CA non si pu<70> proseguire!
|
||
if (!has_ca)
|
||
return error_box("Per utilizzare questo programma <20> necessaria l'attivazione del modulo Contabilt<6C> Analitica");
|
||
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
int ce4500(int argc, char* argv[])
|
||
{
|
||
TPrint_anal_cespi a;
|
||
a.run(argc, argv, TR("Stampa cespiti per analitica"));
|
||
return 0;
|
||
} |