d4f58ea1ec
git-svn-id: svn://10.65.10.50/branches/R_10_00@23027 c028cbd2-c16b-5b4b-a496-9718f37d4682
307 lines
9.8 KiB
C++
Executable File
307 lines
9.8 KiB
C++
Executable File
// ve6800.cpp: programma di contabilizzazione analitica documenti
|
|
// Orgiastica visione...
|
|
// L'oca del dubbio dalle labbra di Fernet.
|
|
//******************************************************************************
|
|
// \\\\\\\\ e *
|
|
// b \\\\\\\\ b *
|
|
// \\\\\\\\ e r d l *
|
|
// \\\\\\\\ *
|
|
// \\\\\\\\ i V o e h *
|
|
// L \\\\\\\\ *
|
|
// \\\\\\\\ b d *
|
|
// o \\\\\\\\ m a *
|
|
// +++++++++++++++++++++++++ b t *
|
|
// ++++++++++++++++++++++++++--------------------------------------------------|
|
|
// ++++++++++++++++++++++++++--------------------------------------------------|
|
|
// ++++++++++++++++++++++++ |---------------------------------------|
|
|
// u //////// u |---------------------------------------|
|
|
// ' //////// a | /\ /\ |
|
|
// //////// i | r / \ r / \ |
|
|
// a //////// \|/ / \ / \ l |
|
|
// ////////-----------------*---\ a / t \ / a \ /|
|
|
// //////// /|\ \ / \ / \ / |
|
|
// d //////// n | \ / \ / \ / |
|
|
// //////// l d | \/ a \/ l \/ |
|
|
//-----------------------------------------------------------------------------|
|
|
//
|
|
// Scared uh?
|
|
|
|
#include <automask.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
#include <sheet.h>
|
|
#include <tabutil.h>
|
|
#include <defmask.h>
|
|
|
|
#include "velib04.h"
|
|
#include "../cg/cgsaldac.h"
|
|
|
|
#include "ve6800a.h"
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
// MASCHERA
|
|
///////////////////////////////////////////////
|
|
class TContabilizzazione_analitica_mask : public TAutomask
|
|
{
|
|
TArray_sheet* _num_sheet; // TArray_sheet contenente le selezioni sui codici numerazione
|
|
TString_array _tipi_doc; // Array di stringhe contenente i tipi documenti da elaborare
|
|
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
// Costruisce lo sheet dei codici numerazione
|
|
void build_num_sheet();
|
|
|
|
public:
|
|
// Controlla se lo stato ed il tipo del documento sono validi e rispettano la selezione
|
|
bool doc_tipo_stato_ok(const TRectype& doc);
|
|
// Restituisce lo sheet con le numerazioni da elaborare
|
|
TArray_sheet& num_sheet() const { return *_num_sheet; }
|
|
// Constructor and Distructor
|
|
TContabilizzazione_analitica_mask();
|
|
~TContabilizzazione_analitica_mask();
|
|
};
|
|
|
|
TContabilizzazione_analitica_mask::TContabilizzazione_analitica_mask() : TAutomask("ve6800a")
|
|
{
|
|
_num_sheet = new TArray_sheet(-1, -1, -4, -4, "Codici numerazione", "@1|Cod. numerazione|Descrizione@50");
|
|
}
|
|
|
|
TContabilizzazione_analitica_mask::~TContabilizzazione_analitica_mask()
|
|
{
|
|
delete _num_sheet;
|
|
}
|
|
|
|
bool TContabilizzazione_analitica_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_CODICE_ELAB:
|
|
if (e == fe_modify || e == fe_init)
|
|
{
|
|
const bool full = !o.empty();
|
|
if (full)
|
|
build_num_sheet();
|
|
enable(DLG_USER, full);
|
|
enable(DLG_OK, full && _num_sheet->one_checked());
|
|
}
|
|
break;
|
|
case DLG_USER:
|
|
if (e == fe_button && _num_sheet->run())
|
|
{
|
|
// Hai selezionato qualcosa ? allora abilita il pulsante di conferma
|
|
enable(DLG_OK, _num_sheet->one_checked());
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TContabilizzazione_analitica_mask::build_num_sheet()
|
|
{
|
|
_num_sheet->destroy();
|
|
_tipi_doc.destroy();
|
|
|
|
const TContabilizzazione_analitica contanal(get(F_CODICE_ELAB));
|
|
if (!contanal.empty())
|
|
{
|
|
TToken_string t;
|
|
TString4 tipo;
|
|
for (int i = 0; i < TElaborazione::_max_tipi_doc_elab; i++)
|
|
{
|
|
tipo = contanal.tipo_iniziale(i);
|
|
if (tipo.full())
|
|
{
|
|
t = tipo;
|
|
t.add(contanal.stato_iniziale(i)); // Stato iniziale
|
|
_tipi_doc.add(t); // Aggiunge questo tipo documento alla lista
|
|
}
|
|
}
|
|
|
|
TString s1,s2,s3;
|
|
TTable num("%NUM");
|
|
for (num.first(); num.good(); num.next()) // scorre tutte le numerazioni possibili
|
|
{
|
|
TToken_string t,z;
|
|
t.add(" ");
|
|
t.add(num.get("CODTAB"));
|
|
t.add(num.get("S0"));
|
|
|
|
s2 = num.get("S2"); // reperisce i tipi documento validi per questa numerazione
|
|
|
|
for (int x = 0; x <= s2.len(); x += 4)
|
|
z.add(s2.mid(x,4));
|
|
|
|
bool found = false;
|
|
for (int i = _tipi_doc.last(); !found && i >= 0; i--)
|
|
found |= s2.find(_tipi_doc.row(i).get(0)) >= 0;
|
|
if (found)
|
|
_num_sheet->add(t);
|
|
}
|
|
|
|
if (_num_sheet->items() == 1)
|
|
_num_sheet->check(0);
|
|
}
|
|
}
|
|
|
|
bool TContabilizzazione_analitica_mask::doc_tipo_stato_ok(const TRectype& doc)
|
|
// Verifica che il tipo documento corrente esista tra i tipi previsti dalla elaborazione
|
|
// differita selezionata
|
|
{
|
|
bool found = false;
|
|
const TString4 tipo = doc.get(DOC_TIPODOC);
|
|
const char stato = doc.get_char(DOC_STATO);
|
|
const int items = _tipi_doc.items();
|
|
for (int i = 0; i < items && !found; i++)
|
|
{
|
|
TToken_string& t = _tipi_doc.row(i);
|
|
const TString4 tipox(t.get(0));
|
|
const char statox = t.get(1)[0];
|
|
if (tipo == tipox && stato == statox)
|
|
found = true;
|
|
}
|
|
return found;
|
|
}
|
|
|
|
//////////////////////////////////////////////
|
|
// APPLICAZIONE
|
|
/////////////////////////////////////////////
|
|
|
|
// TContabilizzazione_analitica
|
|
// Applicazione di contabilizzazione documenti
|
|
class TContabilizzazione_analitica_app : public TSkeleton_application
|
|
{
|
|
TContabilizzazione_analitica_mask* _msk;
|
|
|
|
protected: // TApplication
|
|
// Contabilizza i documenti
|
|
void contabilize();
|
|
|
|
public:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
};
|
|
|
|
|
|
void TContabilizzazione_analitica_app::contabilize()
|
|
{
|
|
//Prende i dati dalla maschera (date,sheet numerazioni)
|
|
const TDate data_ini = _msk->get_date(F_DATA_INI);
|
|
int year_from = data_ini.year();
|
|
const TDate data_fine = _msk->get_date(F_DATA_FIN);
|
|
int year_to = data_fine.year();
|
|
const TDate data_reg = _msk->get_date(F_DATA_REG);
|
|
TArray_sheet& num_sheet = _msk->num_sheet();
|
|
const long items = num_sheet.items();
|
|
|
|
//Relazione su LF_DOC
|
|
TRelation doc_rel(LF_DOC);
|
|
TRectype da(LF_DOC);
|
|
TRectype a(LF_DOC);
|
|
|
|
TString16 codnum;
|
|
TString msg, filt_expr;
|
|
TToken_string nums;
|
|
|
|
// Compone la lista dei documenti da elaborare
|
|
for (long i = 0L; i < items; i++) // Scorre per tutte le numerazioni dello sheet
|
|
{
|
|
if (num_sheet.checked(i)) // Costruisce una espressione sul codice numerazione: "CODNUM="x0" || CODNUM="x1" || ..."
|
|
{
|
|
codnum = num_sheet.row(i).get(1);
|
|
filt_expr << "(CODNUM=\"";
|
|
filt_expr << codnum << "\")||";
|
|
nums.add(codnum);
|
|
}
|
|
}
|
|
filt_expr.rtrim(2);
|
|
|
|
da.put(DOC_DATADOC, data_ini);
|
|
da.put(DOC_PROVV, "D");
|
|
da.put(DOC_ANNO, year_from);
|
|
a.put(DOC_DATADOC, data_fine);
|
|
a.put(DOC_PROVV, "D");
|
|
a.put(DOC_ANNO, year_to);
|
|
|
|
// Se ho una sola numerazione ottimizzo la setregion!
|
|
if (nums.items() == 1)
|
|
{
|
|
da.put(DOC_CODNUM, nums);
|
|
a.put(DOC_CODNUM, nums);
|
|
//filt_expr.cut(0); // Il filtro diventa inutile
|
|
}
|
|
|
|
// Cursore complessivo con limiti di data (chiave 3). Viene sfruttata l'ottimizzazione
|
|
// sulla costruzione dei cursori nel caso i campi presenti nell'espressione siano campi
|
|
// chiave, nel nostro caso CODNUM soddisfa i requisiti.
|
|
TCursor doc_cur(&doc_rel, filt_expr, 3, &da, &a);
|
|
const TRecnotype cur_items = doc_cur.items();
|
|
if (cur_items > 0)
|
|
{
|
|
TLista_documenti lista_in, lista_out;
|
|
|
|
doc_cur.freeze();
|
|
msg = "Selezione documenti dal ";
|
|
msg << data_ini.string() << " al ";
|
|
msg << data_fine.string();
|
|
TProgind p(cur_items, msg, false, true);
|
|
const TRectype& cur_rec = doc_cur.curr();
|
|
|
|
// Scorre tutti i documenti che rientrano nell'intervallo selezionato
|
|
for (doc_cur = 0; doc_cur.pos() < cur_items; ++doc_cur)
|
|
{
|
|
p.addstatus(1);
|
|
// controlla che il tipo documento e lo stato siano coerenti con la ELD selezionata
|
|
if (nums.get_pos(cur_rec.get(DOC_CODNUM)) >= 0 && _msk->doc_tipo_stato_ok(cur_rec))
|
|
{
|
|
TDocumento* doc = new TDocumento;
|
|
if (doc->read(doc_cur.curr()) == NOERR) // legge il documento
|
|
lista_in.add(doc); // Viene aggiunto alla lista dei documenti
|
|
else
|
|
delete doc;
|
|
}
|
|
}
|
|
//E finalmente fa l'agognata elaborazione!!!!!
|
|
TString16 elaborazione = _msk->get(F_CODICE_ELAB);
|
|
TContabilizzazione_analitica contanal(elaborazione);
|
|
contanal.elabora(lista_in, lista_out, data_reg, true);
|
|
|
|
if (contanal.processed_docs() > 0L)
|
|
message_box(FR("Totale documenti contabilizzati: %ld"), contanal.processed_docs());
|
|
}
|
|
else
|
|
warning_box(TR("Non vi sono documenti da contabilizzare per le numerazioni selezionate."));
|
|
|
|
xvtil_statbar_set("");
|
|
}
|
|
|
|
|
|
bool TContabilizzazione_analitica_app::create()
|
|
{
|
|
open_files(LF_TABCOM, LF_TAB, LF_DOC, LF_RIGHEDOC, LF_MOVANA, LF_RMOVANA, 0);
|
|
_msk = new TContabilizzazione_analitica_mask();
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TContabilizzazione_analitica_app::destroy()
|
|
{
|
|
if (_msk) delete _msk;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TContabilizzazione_analitica_app::main_loop()
|
|
{
|
|
while (_msk->run() == K_ENTER)
|
|
contabilize();
|
|
}
|
|
|
|
int ve6800 (int argc, char **argv)
|
|
{
|
|
TContabilizzazione_analitica_app a;
|
|
a.run(argc,argv, TR("Contabilizzazione analitica documenti"));
|
|
return true;
|
|
}
|