163 lines
3.5 KiB
C++
Executable File
163 lines
3.5 KiB
C++
Executable File
#include "rilib01.h"
|
|
#include <automask.h>
|
|
#include <applicat.h>
|
|
#include <recset.h>
|
|
#include <reputils.h>
|
|
#include <utility.h>
|
|
|
|
#include "../cg/cglib02.h"
|
|
|
|
#include "ri0.h"
|
|
#include "ri0400a.h"
|
|
#include "rilib01.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TRicl_mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TRicl_mask : public TAutomask
|
|
{
|
|
protected:
|
|
void update_date_to();
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TRicl_mask() : TAutomask("ri0400a") { }
|
|
};
|
|
|
|
void TRicl_mask::update_date_to()
|
|
{
|
|
const TDate dal = get_date(F_DAL);
|
|
if (dal.ok())
|
|
{
|
|
TEsercizi_contabili & es = esercizi();
|
|
es.update();
|
|
|
|
const TString& codper = get(F_PER);
|
|
const TRectype& per = cache().get("&PER", codper);
|
|
|
|
TDate al = dal;
|
|
int nper = get_int(F_NPER);
|
|
if (nper <= 0)
|
|
nper = 1;
|
|
al += per.get_int("I0") * nper;
|
|
al += per.get_int("I1") * 7 * nper;
|
|
al.addmonth(per.get_int("I2") * nper);
|
|
al.addyear(per.get_int("I3") * nper);
|
|
if (al > dal)
|
|
--al;
|
|
else
|
|
al = dal;
|
|
set(F_AL, al);
|
|
}
|
|
}
|
|
|
|
bool TRicl_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
const short id = o.dlg();
|
|
switch (id)
|
|
{
|
|
case F_PER:
|
|
case F_NPER:
|
|
if (e == fe_modify)
|
|
update_date_to();
|
|
break;
|
|
case F_ESER:
|
|
case F_DAL:
|
|
if (e == fe_modify)
|
|
{
|
|
TMask & m = o.mask();
|
|
const int eser = m.get_int(F_ESER);
|
|
const TDate dal = m.get_date(F_DAL);
|
|
|
|
if (dal.ok() && eser != 0)
|
|
{
|
|
TEsercizi_contabili & es = esercizi();
|
|
es.update();
|
|
const int anno = es.esercizio(eser).inizio().year();
|
|
|
|
if (anno != dal.year())
|
|
return o.error_box("La data di inizio deve appartenere all'esercizio specificato");
|
|
}
|
|
update_date_to();
|
|
}
|
|
else
|
|
if (e == fe_close)
|
|
{
|
|
TMask & m = o.mask();
|
|
|
|
if (m.get(F_ESER).empty() && (m.get(F_DAL).empty() || m.get(F_AL).empty()))
|
|
return o.error_box(TR("E' necessario specificare o il codice esercizio oppure\nle date limite"));
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
class TRicl_saldi : public TSkeleton_application
|
|
{
|
|
TRicl_mask *_mask;
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void TRicl_saldi::main_loop()
|
|
{
|
|
TFilename output_file;
|
|
if (argc() == 2)
|
|
{
|
|
TRicl_mask mask;
|
|
while (mask.run() != K_QUIT)
|
|
{
|
|
output_file = mask.get(F_OUTPUT);
|
|
const TFixed_string ext(output_file.ext());
|
|
const TRecordsetExportFormat fmt = ext == "txt" ? fmt_as400 : fmt_unknown;
|
|
|
|
if (mask.get(F_RICL).full())
|
|
{
|
|
TSaldi_ricl_recordset recset(mask);
|
|
recset.save_as(output_file, fmt);
|
|
}
|
|
else
|
|
{
|
|
TSaldi_conti_recordset recset(mask);
|
|
recset.save_as(output_file, fmt);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TConfig c(argv(2));
|
|
const TString16 codricl(c.get("CodRicl"));
|
|
const TString16 codper(c.get("CodPer"));
|
|
const int nper = c.get_int("NumeroPer");
|
|
const TDate dal(c.get("Dal"));
|
|
const bool provv = c.get_bool("Provvisori");
|
|
const bool all = c.get_bool("Struttura");
|
|
const bool progr = c.get_bool("Prograssivi");
|
|
|
|
output_file = c.get("Output");
|
|
if (codricl.full())
|
|
{
|
|
TSaldi_ricl_recordset recset(codricl, codper, nper, dal, provv, all, progr);
|
|
recset.save_as(output_file);
|
|
}
|
|
else
|
|
{
|
|
TSaldi_conti_recordset recset(codper, nper, dal, provv, all, progr);
|
|
recset.save_as(output_file);
|
|
}
|
|
}
|
|
}
|
|
|
|
int ri0400 (int argc, char* argv[])
|
|
{
|
|
TRicl_saldi main_app;
|
|
main_app.run(argc, argv, TR("Riclassificazione saldi"));
|
|
return true;
|
|
}
|