campo-sirio/lv/lv2A00.cpp

145 lines
3.6 KiB
C++
Raw Normal View History

#include <applicat.h>
#include <automask.h>
#include <progind.h>
#include <recarray.h>
#include <recset.h>
#include <relation.h>
#include <reputils.h>
#include <clifo.h>
#include "lvcondv.h"
#include "lvpasplan.h"
#include "lv2a00a.h"
///////////////////////////////////////////////////////////
// TAutogiro_msk
///////////////////////////////////////////////////////////
class TAutogiro_msk : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TAutogiro_msk();
};
bool TAutogiro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
return true;
}
TAutogiro_msk::TAutogiro_msk() : TAutomask("lv2a00a")
{
// Propone itinerario senza autista
TEdit_field& g = efield(F_ITINERARIO);
TCursor& gcur = *g.browse()->cursor();
for (TRecnotype i = gcur.items()-1; i >= 0; --gcur, i--)
{
if (gcur.curr().get("S1").empty())
{
g.browse()->do_output();
break;
}
}
// Propone prima frequenza disponibile (settimanale)
TEdit_field& f = efield(F_FREQUENZA);
TCursor& fcur = *f.browse()->cursor();
if (fcur.items())
{
fcur = 0L;
f.browse()->do_output();
}
// Propone consegna e ritiro
set(F_CONSEGNA, "E");
// Preimposta i feriali
for (int d = 0; d < 5; d++)
set(F_LUNEDI+d, "X");
}
///////////////////////////////////////////////////////////
// TAutogiro_app
///////////////////////////////////////////////////////////
class TAutogiro_app : public TSkeleton_application
{
protected:
virtual void main_loop();
};
void TAutogiro_app::main_loop()
{
TAutogiro_msk msk;
while (msk.run() == K_ENTER)
{
const TDate oggi(TODAY);
TFast_isamfile pasplan(LF_LVPASPLAN);
TString query;
query << "USE LVCONDV SELECT LVPASPLAN->NRIGA!=1"
<< "\nJOIN LVPASPLAN INTO CODCF==CODCF CODCONT==CODCONT NRIGA==1";
TISAM_recordset contratti(query);
TProgress_monitor pi(contratti.items(), title());
TLog_report log;
for (bool ok = contratti.move_first(); ok; ok = contratti.move_next())
{
const long codcf = contratti.get(LVCONDV_CODCF).as_int();
if (codcf <= 0)
continue;
const TDate datasc = contratti.get(LVCONDV_DATASC).as_date();
if (datasc.ok() && datasc < oggi)
continue;
int nriga = 1;
for (int day = 0; day < 7; day++) if (msk.get_bool(F_LUNEDI+day))
{
if (nriga == 1)
{
TString8 cod; cod.format("C|%06ld", codcf);
TString msg;
msg << TR("Contratto ") << cod << '/' << contratti.get(LVCONDV_CODCONT)
<< " - " << cache().get(LF_CLIFO, cod, CLI_RAGSOC);
log.log(0, msg);
}
pasplan.zero();
pasplan.put(LVPASPLAN_CODCF, contratti.get(LVCONDV_CODCF).as_int());
pasplan.put(LVPASPLAN_CODCONT, contratti.get(LVCONDV_CODCONT).as_int());
pasplan.put(LVPASPLAN_NRIGA, nriga++);
pasplan.put(LVPASPLAN_CODITI, msk.get(F_ITINERARIO));
pasplan.put(LVPASPLAN_FREQ, msk.get(F_FREQUENZA));
pasplan.put(LVPASPLAN_MODPASS, msk.get(F_CONSEGNA));
pasplan.put(LVPASPLAN_GGCONS, day+1);
const int err = pasplan.write();
if (err != NOERR)
{
cantwrite_box(pasplan.description());
log.log(2, TR("Errore di scrittura sul file LVPASPLAN"));
contratti.move_last();
break;
}
}
if (!pi.add_status())
break;
}
log.preview();
}
}
int lv2A00(int argc, char* argv[])
{
TAutogiro_app app;
app.run(argc, argv, TR("Pianificazione da contratti"));
return 0;
}