Files correlati : cg2.exe Commento : - Correzione maschera cg2300a per compatibilita' con schermi piu' piccoli - Visualizzate solo registrazioni con flag liq. mese prec. - Modificate posizioni campi prima nota
289 lines
6.7 KiB
C++
289 lines
6.7 KiB
C++
#include "cg2.h"
|
||
#include "applicat.h"
|
||
#include "automask.h"
|
||
#include "cg2300a.h"
|
||
#include "cg2103.h"
|
||
#include "lffiles.h"
|
||
#include "isam.h"
|
||
#include "mov.h"
|
||
#include <map>
|
||
#include "rmov.h"
|
||
#include <vector>
|
||
#include "pconti.h"
|
||
|
||
#define INI_ANNO "riep_anno"
|
||
#define INI_MESE "riep_mese"
|
||
|
||
class TCompetenze_mask : public TAutomask
|
||
{
|
||
struct cont_contr_t
|
||
{
|
||
int gruppo;
|
||
int conto;
|
||
int s_conto;
|
||
real importo;
|
||
};
|
||
std::vector<int> _regs;
|
||
std::vector<cont_contr_t> _conts;
|
||
|
||
const char* get_ini(bool dataini) const;
|
||
|
||
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
||
|
||
// Funzione becera di ordinamento del vettore _conts
|
||
void sort_conts(bool sort_by_imp = true);
|
||
static void swap_items(cont_contr_t* it, cont_contr_t* jt);
|
||
static bool is_minor_of(cont_contr_t* jt, cont_contr_t* it);
|
||
|
||
static TString get_descr(int gruppo, int conto, int s_conto);
|
||
void fill_contc();
|
||
void fill();
|
||
|
||
public:
|
||
TCompetenze_mask() : TAutomask("cg2300a.msk") { }
|
||
};
|
||
|
||
const char* TCompetenze_mask::get_ini(bool dataini) const
|
||
{
|
||
if (dataini)
|
||
return ini_get_string(CONFIG_DITTA, "cg", INI_ANNO, "");
|
||
return ini_get_string(CONFIG_DITTA, "cg", INI_MESE, "");
|
||
}
|
||
|
||
bool TCompetenze_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case DLG_LINK:
|
||
if (e == fe_button)
|
||
if (get(F_ANNO).full() && get(F_MESE).full())
|
||
fill();
|
||
else if (get(F_ANNO).blank())
|
||
message_box("Inserire un anno");
|
||
else if (get(F_MESE).blank())
|
||
message_box("Inserire un mese");
|
||
break;
|
||
case DLG_USER:
|
||
if (e == fe_button && jolly > 0)
|
||
{
|
||
TSheet_field& sf = sfield(F_MOVS);
|
||
TToken_string& row = sf.row(sf.selected());
|
||
TRectype mov(LF_MOV);
|
||
mov.put(MOV_NUMREG, row.get(sf.cid2index(F_NUMREG)));
|
||
if (mov.edit())
|
||
fill();
|
||
}
|
||
case F_ANNO:
|
||
if (e == fe_init) set(F_ANNO, get_ini(true));
|
||
break;
|
||
case F_MESE:
|
||
if (e == fe_init)
|
||
set(F_MESE, get_ini(false));
|
||
break;
|
||
default: break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TString TCompetenze_mask::get_descr(int gruppo, int conto, int s_conto)
|
||
{
|
||
TLocalisamfile pcont(LF_PCON);
|
||
pcont.put(PCN_GRUPPO, gruppo);
|
||
pcont.put(PCN_CONTO, conto);
|
||
pcont.put(PCN_SOTTOCONTO, s_conto);
|
||
pcont.read();
|
||
return pcont.get(PCN_DESCR);
|
||
}
|
||
|
||
bool TCompetenze_mask::is_minor_of(cont_contr_t* jt, cont_contr_t* it)
|
||
{
|
||
return jt->gruppo < it->gruppo
|
||
|| (jt->gruppo == it->gruppo && jt->conto < it->conto)
|
||
|| (jt->gruppo == it->gruppo && jt->conto == it->conto
|
||
&& jt->s_conto < it->s_conto);
|
||
}
|
||
|
||
void TCompetenze_mask::swap_items(cont_contr_t* it, cont_contr_t* jt)
|
||
{
|
||
const cont_contr_t appo = *it;
|
||
*it = *jt;
|
||
*jt = appo;
|
||
}
|
||
|
||
void TCompetenze_mask::sort_conts(bool sort_by_imp)
|
||
{
|
||
// Sopra 100 rischia di essere leggermente lento?
|
||
if (1 < _conts.size() && _conts.size() < 100)
|
||
for (auto it = _conts.begin(); it != _conts.end(); ++it)
|
||
for (auto jt = (it+1); jt != _conts.end(); ++jt)
|
||
if (sort_by_imp && jt->importo > it->importo || !sort_by_imp && is_minor_of(&(*jt), &(*it)))
|
||
swap_items(&(*it), &(*jt));
|
||
}
|
||
|
||
void TCompetenze_mask::fill_contc()
|
||
{
|
||
TSheet_field& sf = sfield(F_CONTC);
|
||
TLocalisamfile rmovs(LF_RMOV);
|
||
|
||
sf.hide();
|
||
sf.reset();
|
||
|
||
_conts.clear();
|
||
// Per ogni registrazione
|
||
for (int i = 0; i < _regs.size(); ++i)
|
||
{
|
||
const int numreg = _regs[i];
|
||
rmovs.zero();
|
||
rmovs.put(RMV_NUMREG, numreg);
|
||
rmovs.put(RMV_NUMRIG, 0);
|
||
int riga = 0;
|
||
if (rmovs.read())
|
||
{
|
||
// Per ogni riga della registrazione
|
||
for (; rmovs.get_int(RMV_NUMREG) == numreg; rmovs.next())
|
||
{
|
||
const int gruppo = rmovs.get_int(RMV_GRUPPOC);
|
||
const int numcontc = rmovs.get_int(RMV_CONTOC);
|
||
const int s_conto = rmovs.get_int(RMV_SOTTOCONTOC);
|
||
const TString& tipocc = rmovs.get(RMV_TIPOCC);
|
||
const real importo(rmovs.get(RMV_IMPORTO));
|
||
|
||
if (tipocc.blank()) // Solo se il tipo di conto di contr. e' un conto, cioe' vuoto
|
||
{
|
||
// Cerco se ho gi<67> la chiave
|
||
auto it = _conts.begin();
|
||
for (; it != _conts.end(); ++it)
|
||
{
|
||
if (it->gruppo == gruppo
|
||
&& it->conto == numcontc
|
||
&& it->s_conto == s_conto)
|
||
break;
|
||
}
|
||
|
||
if (it != _conts.end())
|
||
it->importo += importo;
|
||
else
|
||
_conts.insert(_conts.end(), { gruppo, numcontc, s_conto, importo });
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
sort_conts(get(F_ORDIN) == "X");
|
||
|
||
real tot; tot = 0;
|
||
for (auto it = _conts.begin(); it != _conts.end(); ++it)
|
||
{
|
||
const int gruppo = it->gruppo;
|
||
const int conto = it->conto;
|
||
const int s_conto = it->s_conto;
|
||
const TString& descr = get_descr(gruppo, conto, s_conto);
|
||
|
||
TToken_string& row = sf.row(-1);
|
||
row.add(gruppo);
|
||
row.add(conto);
|
||
row.add(s_conto);
|
||
row.add(descr);
|
||
row.add(it->importo);
|
||
tot += it->importo;
|
||
}
|
||
|
||
sf.force_update();
|
||
sf.show();
|
||
|
||
set(F_TOT, tot);
|
||
}
|
||
|
||
void TCompetenze_mask::fill()
|
||
{
|
||
const int anno = get_int(F_ANNO);
|
||
const int mese = get_int(F_MESE);
|
||
TSheet_field& sf = sfield(F_MOVS);
|
||
TLocalisamfile movs(LF_MOV);
|
||
|
||
sf.hide();
|
||
sf.reset();
|
||
_regs.clear();
|
||
movs.setkey(2);
|
||
|
||
const TDate dataini(1, mese, anno);
|
||
TDate dataend(dataini); dataend.set_end_month();
|
||
movs.put(MOV_DATAREG, dataini);
|
||
if (movs.read() != NULL)
|
||
{
|
||
for (; movs.next() == NOERR && movs.get_date(MOV_DATAREG) <= dataend; )
|
||
{
|
||
const int month_liq = movs.get_int(MOV_MESELIQ);
|
||
const TDate datareg(movs.get(MOV_DATAREG));
|
||
const TDate datacomp(movs.get(MOV_DATACOMP));
|
||
if (month_liq != 0)
|
||
{
|
||
_regs.insert(_regs.end(), movs.get_int(MOV_NUMREG));
|
||
|
||
TToken_string& row = sf.row(-1);
|
||
row.add(movs.get(MOV_NUMREG));
|
||
row.add(datareg);
|
||
row.add(movs.get(MOV_DATADOC));
|
||
row.add(TCausale(movs.get(MOV_CODCAUS)).tipo_doc());
|
||
row.add(month_liq);
|
||
row.add(movs.get(MOV_NUMDOC));
|
||
row.add(movs.get(MOV_PROTIVA));
|
||
row.add(movs.get(MOV_DESCR));
|
||
}
|
||
}
|
||
}
|
||
sf.force_update();
|
||
sf.show();
|
||
|
||
fill_contc();
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
// TCompetenze_app
|
||
///////////////////////////////////////////////////////////////////////////////
|
||
|
||
class TCompetenze_app : public TSkeleton_application
|
||
{
|
||
TCompetenze_mask* _msk;
|
||
protected:
|
||
void set_ini(bool dataini, const TString& set) const;
|
||
void save_fields() const;
|
||
|
||
public:
|
||
void main_loop() override;
|
||
|
||
TCompetenze_app() : _msk() {};
|
||
};
|
||
|
||
void TCompetenze_app::set_ini(bool dataini, const TString& set) const
|
||
{
|
||
if (!set.empty())
|
||
{
|
||
if (dataini)
|
||
ini_set_string(CONFIG_DITTA, "cg", INI_ANNO, set);
|
||
else
|
||
ini_set_string(CONFIG_DITTA, "cg", INI_MESE, set);
|
||
}
|
||
}
|
||
|
||
void TCompetenze_app::save_fields() const
|
||
{
|
||
set_ini(true, _msk->get(F_ANNO));
|
||
set_ini(false, _msk->get(F_MESE));
|
||
}
|
||
|
||
void TCompetenze_app::main_loop()
|
||
{
|
||
_msk = new TCompetenze_mask;
|
||
while (_msk->run() == K_ENTER) {}
|
||
save_fields();
|
||
}
|
||
|
||
int cg2300(int argc, char** argv)
|
||
{
|
||
TCompetenze_app* app = new TCompetenze_app;
|
||
app->run(argc, argv, TR("Registrazioni Competenza Precedente"));
|
||
delete app;
|
||
return 0;
|
||
}
|