campo-sirio/src/li/li0100.cpp
Alessandro Bonazzi 568a79875b Patch level : 12.0 996
Files correlati     : limenu.men li0.exe li0700a.msk
Commento            :

Aggiunto programma per la ricostruzione del plafond.
2020-09-21 16:33:57 +02:00

271 lines
6.4 KiB
C++

#include <automask.h>
#include <relapp.h>
#include <utility.h>
#include <toolfld.h> // TButton_tool
#include <urldefid.h> // ID Bottoni
#include <doc.h>
#include "../ve/velib.h"
#include "../ve/velib04.h"
#include "lilib01.h"
#include "li0.h"
#include "li0100a.h"
#include "li0700a.h"
#define PLA_COLS 10 // n° colonne di lettere di intento
#define PLNPR(x) (START_PLA + x * 2)
#define PLIMP(x) (START_PLA + x * 2 + 1)
/* Utility ***********************/
HIDDEN bool key_handler(TMask& m, KEY k)
{
// Per ora facciamo che il SHIFT+F12 attiva sempre il campo 3
if (k == K_SHIFT+K_F12)
m.enable(DLG_OK);
return true;
}
/*****************************************************************/
class TVisLI_mask : public TAutomask
{
private:
void next_page(int p);
bool _filter_changed;
int _plColumns;
void addRow(TSheet_field& sheet, const TDocumento &d);
public:
void load_sheet();
void setFilterChanged() { _filter_changed = true; }
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
void load_config();
TVisLI_mask();
};
TVisLI_mask::TVisLI_mask() : TAutomask("li0100a"), _filter_changed(true)
{
if(get(F_DATAFIN).empty())
set(F_DATAFIN, TDate(TODAY));
set_handler(key_handler);
disable(DLG_OK);
}
void TVisLI_mask::load_sheet()
{
_filter_changed = false;
TSheet_field& sheet = sfield(F_RIGHE);
TLista_documenti din;
int anno = get_int(F_ANNO);
TDate dal = get_date(F_DATAINI);
TDate al = get_date(F_DATAFIN);
long dacodcf = get_long(F_DACODCF);
long acodcf = get_long(F_ACODCF);
TCursor cli(new TRelation(LF_CLIFO));
TRectype from(cli.curr());
TRectype to(cli.curr());
anno = today.year();
if (!dal.ok())
dal.set_start_year(anno);
if (!al.ok())
al.set_end_year(anno);
if (dacodcf > 0L)
{
from.put(CLI_TIPOCF, "C");
from.put(CLI_CODCF, dacodcf);
}
if (acodcf > 0L)
{
to.put(CLI_TIPOCF, "C");
to.put(CLI_CODCF, acodcf);
}
cli.setregion(from, to);
const int items = cli.items();
sheet.destroy();
for (cli = 0L; cli.pos() < items; ++cli)
{
din.read('D', 'C', cli.curr().get_long(CLI_CODCF), anno, tipi(), stati(), dal, al);
const int ndocs = din.items();
; for (int d = 0; d < ndocs; d++)
addRow(sheet, din[d]);
}
sheet.force_update();
}
void TVisLI_mask::addRow(TSheet_field& sheet, const TDocumento &d)
{
// Per ogni documento che aggiungo valuto quante lettere di intento utilizzo.
// Ogni lettera di intento utilizzerà 2 colonne:
// Num protocollo e QTA utilizzata
// Controllo preventivo che abbia effettivamente il plafond sul documento
TToken_string plafs(d.get(DOC_PLAFOND), ',');
if (plafs.full())
{
const int r = sheet.set_row_cell(A_DATADOC,d.get(DOC_DATADOC)); // Data documento
sheet.set_row_cell(A_ANNO, d.get_int(DOC_ANNO),r); // Anno documento
sheet.set_row_cell(A_NUMDOC, d.get_long(DOC_NDOC), r); // Numero documento
sheet.set_row_cell(A_CODNUM, d.get(DOC_CODNUM), r); // Tipo documento
sheet.set_row_cell(A_TIPODOC, d.get(DOC_TIPODOC), r); // Stato documento
sheet.set_row_cell(A_STATODOC, d.get(DOC_STATO), r); // Tipo cliente
sheet.set_row_cell(A_TIPOCF, "C", r); // Codice cliente
sheet.set_row_cell(A_CODCF, d.get(DOC_CODCF), r); // Ragione Sociale
sheet.set_row_cell(A_RAGSOC, d.clifor().get(CLI_RAGSOC), r);
// Totale documento
sheet.set_row_cell(A_TOTDOC, d.totale_doc(), r);
const int nplafs = plafs.items();
for (int i = 0; i < nplafs && i < PLA_COLS; i++)
{
TToken_string plaf(plafs.get(i));
sheet.set_row_cell(PLNPR(i), plaf.get(_plnumprot), r); // _plnumprot
sheet.set_row_cell(PLIMP(i), plaf.get(_plimporto), r); // _plimporto
}
}
}
void TVisLI_mask::next_page(int p)
{
TAutomask::next_page(p);
if (_filter_changed && curr_win() == sfield(F_RIGHE).parent())
load_sheet();
}
bool TVisLI_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
const short id = o.dlg();
switch(id)
{
case F_ANNO:
if (e == fe_init)
{
o.set(today.year());
load_config();
}
break;
case F_TIPORIC:
if( e == fe_modify)
{
const bool on = o.get() == "D";
enable(F_NUMPROT, !on);
for(int i = F_DACODCF; i <= F_ARAGSOC; i++)
{
enable(i, on);
reset(i);
}
}
break;
case DLG_RECALC:
if(e == fe_button)
next_page(1);
break;
case DLG_OK:
{
// Creo una maschera che richiede la data
TMask sto("li0700a");
// Lancio la maschera
sto.disable(F_ANNO_STO);
sto.disable(F_FROM_CLI);
sto.disable(F_TO_CLI);
sto.set(F_ANNO_STO, get_int(F_ANNO));
sto.set(F_FROM_CLI, get_long(F_DACODCF));
sto.set(F_TO_CLI, get_long(F_ACODCF));
if (sto.run() == K_ENTER)
genera_li_storico(sto.get_int(F_ANNO_STO), sto.get_long(F_FROM_CLI), sto.get_long(F_TO_CLI));
return false;
break;
}
case DLG_USER:
if (e == fe_button || e == fe_init)
{
// 1: PROVV+ANNO+CODNUM+NDOC
const long anno = o.mask().get_long(A_ANNO);
const TString codnum = o.mask().get(A_CODNUM);
const long numdoc = o.mask().get_long(A_NUMDOC);
const bool enab = numdoc > 0;
if (e == fe_button && enab)
{
o.disable(); // Tecnica anti doppio click!
TDocumento doc('D', anno, codnum, numdoc);
doc.edit();
o.enable();
}
else
o.enable(enab);
}
default:
break;
}
if (e == fe_modify && jolly == 0 && id >= F_TIPORIC && id <= F_ARAGSOC)
setFilterChanged();
return true;
}
void TVisLI_mask::load_config()
{
TToken_string tipidoc(ini_get_string(CONFIG_DITTA, "li", "TIPIDOC"));
TSheet_field &docs = sfield(DOCUMENTI_STATO);
docs.destroy();
for (int i = 0; i < tipidoc.items(); i++)
{
TString td = tipidoc.get(i);
TToken_string stati(ini_get_string(CONFIG_DITTA, "li", td));
for (int j = 0; j < stati.items(); j++)
{
TToken_string s(stati.get(j), ',');
const int r = docs.set_row_cell(F_TIPODOC_C, td);
docs.set_row_cell(F_STATODOCDA_C, s.get(0), r);
docs.set_row_cell(F_STATODOCA_C, s.get(1), r);
}
}
docs.force_update();
}
class TVisLI_app : public TSkeleton_application
{
public:
void main_loop();
};
void TVisLI_app::main_loop()
{
open_files(LF_LETINT, LF_DOC, LF_RIGHEDOC);
TVisLI_mask m;
while (m.run() == K_ENTER);
}
int li0100(int argc, char* argv[])
{
TVisLI_app a;
a.run(argc, argv, TR("Riferimenti lettere/Documento"));
return 0;
}