campo-sirio/src/ve/ve1700.cpp

484 lines
13 KiB
C++
Raw Normal View History

// freeze
// valuta
// output
// librerie
// 99999
//////////////////////////////////////////////////////////////
// Stampa documenti
//////////////////////////////////////////////////////////////
#include <applicat.h>
#include <automask.h>
#include <config.h>
#include <defmask.h>
#include <progind.h>
#include <reprint.h>
#include <sheet.h>
#include <toolfld.h>
#include "velib07.h"
#include "sconti.h"
#include "ve1700.h"
#include <comuni.h>
#include <nditte.h>
//////////////////////////////////////////////////////////////////////////////////////////////
// classe TListaDoc_application customizzata dalla TApplication per l'applicazione principale
//////////////////////////////////////////////////////////////////////////////////////////////
class TStampa_lista_docs_mask : public TAutomask
{
TCursor_sheet _clifo;
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TCursor_sheet & clifo() { return _clifo; }
long select_cod_range(long from, long to);
void reset_choices();
void set_choice_limits();
void build_clifo_list();
TStampa_lista_docs_mask();
virtual ~TStampa_lista_docs_mask() {}
};
long TStampa_lista_docs_mask::select_cod_range(long from, long to)
{
TWait_cursor hourglass;
if (from < 0L)
from = _clifo.row(_clifo.selected()).get_long(1);
if (to < 0L)
to = _clifo.row(_clifo.selected()).get_long(1);
else
if (to == 0L)
to = 999999L;
for (int i = 0; i < _clifo.items(); i++)
{
TToken_string& c = _clifo.row(i);
const long cod = c.get_long(1);
if (cod >= from && cod <= to)
_clifo.check(i);
else
_clifo.uncheck(i);
}
set_choice_limits();
return _clifo.checked();
}
void TStampa_lista_docs_mask::set_choice_limits()
{
long first = 999999L, last = -1L;
for (int i = 0; i < _clifo.items(); i++)
{
if (_clifo.checked(i))
{
const long cf = _clifo.row(i).get_long(1);
if (first > cf)
first = cf;
if (last < cf)
last = cf;
}
}
if (first != -1)
set(F_CODFR, first);
if (last != -1)
set(F_CODTO, last);
set(F_SELECTED, _clifo.checked());
}
void TStampa_lista_docs_mask::build_clifo_list()
{
// Semplice ed efficace
TRectype rec(LF_CLIFO);
rec.put(CLI_TIPOCF, get(F_TIPOCF));
_clifo.cursor()->setregion(rec, rec);
}
void TStampa_lista_docs_mask::reset_choices()
{
reset(F_SELECTED);
reset(F_CODFR);
reset(F_CODTO);
_clifo.check(-1, false);
}
bool TStampa_lista_docs_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_TIPOCF:
if (e == fe_modify)
{
TWait_cursor hourglass;
reset_choices();
build_clifo_list();
}
break;
case F_CODFR :
if (e == fe_button)
{
_clifo.disable_check();
_clifo.disable(DLG_USER);
if (_clifo.run() == K_ENTER)
select_cod_range(-1, o.mask().get_long(F_CODTO));
_clifo.enable(DLG_USER);
}
else
if (e == fe_modify)
select_cod_range(o.get_long(), o.mask().get_long(F_CODTO));
break;
case F_CODTO :
if (e == fe_button)
{
_clifo.disable_check();
_clifo.disable(DLG_USER);
if (_clifo.run() == K_ENTER)
select_cod_range(o.mask().get_long(F_CODFR), -1);
_clifo.enable(DLG_USER);
}
else
if (e == fe_modify)
select_cod_range(o.mask().get_long(F_CODFR), o.get_long());
break;
case BUT_SEL:
if (e == fe_button)
{
_clifo.enable_check();
if (_clifo.run() == K_ENTER)
set_choice_limits();
}
break;
case BUT_ANN:
if (e == fe_button)
reset_choices();
break;
case 102:
if (e == fe_button)
{
TSheet_field & s = sfield(F_SHEETNUMS);
TToken_string & row = s.row(s.selected());
TArray_sheet as(-1,-1,70,20,TR("Tipi documento"),HR("Codice|Descrizione@50")); //costruisce uno sheet di selezione dei tipi doc
const TCodice_numerazione& cn = cached_numerazione(row.get(1));
for (int t = cn.ntipi_doc()-1; t >= 0; t--)
{
const TString4 tipodoc = cn.tipo_doc(t);
TToken_string row; //classica token_string con codice e descrizione del tipodoc: questa viene scelta nella tabella
row.add(tipodoc); //dei tipi docs %TIP
row.add(cache().get("%TIP", tipodoc, "S0"));
as.add(row); //..e viene aggiunta allo sheet di selezione
}
if (as.run() != K_ESC)
{
TToken_string& riga = as.row(-1); //setta sul campo a maschera il codice della riga selezionata di as
o.set(riga.get(0));
}
}
else
if (e == fe_close && o.get().full())
{
TSheet_field & s = sfield(F_SHEETNUMS);
TToken_string & row = s.row(s.selected());
const TCodice_numerazione& cn = cached_numerazione(row.get(s.cid2index(101)));
for (int t = cn.ntipi_doc()-1; t >= 0; t--)
{
const TString& tipodoc = cn.tipo_doc(t);
if (tipodoc == o.get())
return true;
}
return o.error_box(FR("Tipo documento non valido per la numerazione %s"), (const char*)cn.codice());
}
break;
default: break;
}
return true;
}
TStampa_lista_docs_mask::TStampa_lista_docs_mask()
: TAutomask("ve1600a"),
_clifo(new TCursor(new TRelation(LF_CLIFO)),
" |CODCF|RAGSOC", TR("Selezione Clienti/Fornitori"),
HR("@1|Codice@6R|Descrizione@50"), 0, 1)
{
((TButton_tool&)field(DLG_PREVIEW)).set_exit_key('A');
}
///////////////////////////////////////////////////////////
// TLista_documenti_recordset
///////////////////////////////////////////////////////////
static void add_term(TString & expr, const char * term1, const char * op, const char * term2,
const bool string = true, const bool and = true, const bool is_string = true)
{
if (expr.full())
expr << (and ? "&&" : "||");
if (is_string)
{
if (!string)
expr << "STR";
}
else
if (string)
expr << "VAL";
expr << '(' << term1 << op << term2 << ')';
}
static void add_expr(TString & expr, const char * subexpr, const bool string = true,
const bool and = true, const bool is_string = true)
{
if (subexpr && *subexpr)
{
if (expr.full())
expr << (and ? "&&" : "||");
if (is_string)
{
if (!string)
expr << "STR";
}
else
if (string)
expr << "VAL";
expr << '(' << subexpr << ')';
}
}
static const char * stringify(TString & s)
{
s.insert("\"");
s << '"';
return s;
}
class TLista_documenti_recordset : public TDocument_recordset
{
TStampa_lista_docs_mask * _m;
static TAssoc_array _clifo_sel; // Assoc array con solo i cli/fo selezionati. Facilita il filter...
protected:
virtual TCursor* cursor() const;
static bool filter_clifo(const TRelation* r);
public:
TLista_documenti_recordset(const char* use, TStampa_lista_docs_mask * m) : TDocument_recordset(use), _m(m) {}
virtual ~TLista_documenti_recordset() { }
};
TAssoc_array TLista_documenti_recordset::_clifo_sel; // Assoc array con solo i cli/fo selezionati. Facilita il filter...
bool TLista_documenti_recordset::filter_clifo(const TRelation* r)
{
const long codcf = r->curr().get_long(CLI_CODCF);
TString8 key; key.format("%06ld", codcf);
return _clifo_sel.is_key(key);
}
TCursor* TLista_documenti_recordset::cursor() const
{
const bool to_create = !valid_cursor();
TCursor * cur = TDocument_recordset::cursor();
if (to_create && cur != NULL)
{
TStampa_lista_docs_mask & m = *_m;
TCursor_sheet & clifo = m.clifo();
cur->setkey(3);
((TLista_documenti_recordset *) this)->set_firmval(m.get_int(F_SELVAL) == 3);
// Compone la lista dei clienti/forntitori selezionati
_clifo_sel.destroy();
TString16 key;
const long items = clifo.items();
for (long i = 0L; i<items; i++)
if (clifo.checked(i))
{
key.format("%06ld", clifo.row(i).get_long(1)); // Formatta il codice
_clifo_sel.add(key, NULL);
}
cur->set_filterfunction(clifo.checked() > 0 ? filter_clifo : NULL);
// NB: se _clifo_sel non contiene nulla, non viene effettuato alcun filter su CLI/FO (non setta la funzione!!)
TString filter(cur->filter());
TString val = m.get(F_TIPOCF);
const int selval = m.get_int(F_SELVAL);
::add_term(filter, DOC_TIPOCF, "==", stringify(val));
val = m.get(F_ANNO);
::add_term(filter, DOC_ANNO, "==", stringify(val));
val = m.get(F_PROVV);
::add_term(filter, DOC_PROVV, "==", stringify(val));
if (selval == 1) //In Lire
{
TString16 firm_val(TCurrency::get_firm_val());
if (firm_val.full())
::add_term(filter, "(" DOC_CODVAL, "==", stringify(firm_val));
::add_term(filter, DOC_CODVAL, "==", "\"\")", true, false);
}
else
if (selval == 2) // nella valuta specificata
{
val = m.get(F_VALUTA);
::add_term(filter, DOC_CODVAL, "==", stringify(val));
}
// Compone l'espressione filter...
// prende tutte le righe dello spreasheet che non sono totalmente vuote:
// (CODNUM=="xxx"&&(STATO=="x"||STATO=="y"||STATO=="z"...)) ---> questo per una singola riga...
// se vi sono piu' righe, lo si ripete aggiungendo prima un bellissimo "||"
TSheet_field& sf = m.sfield(F_SHEETNUMS);
const int rows = sf.items();
TString docfilter;
TString from_num("ZZZZ");
TString to_num;
for (int j=0; j<rows; j++)
{
TToken_string& riga = sf.row(j);
if (riga.empty())
break;
TString16 str(riga.get(0));
TString statofilter;
if (str.full())
{
::add_term(docfilter, DOC_CODNUM, "==", stringify(str));
if (from_num > str)
from_num = str;
if (to_num < str)
to_num = str;
}
str = riga.get();
if (str.full())
::add_term(docfilter, DOC_TIPODOC, "==", stringify(str));
for (int k = 2; k <= 7; k++) // Famme vede' li stati generali... Aho' A BURINO! Che e' la Rivoluzione Francese?
{
TString4 c = riga.get(k);
if (c.full())
::add_term(statofilter, DOC_STATO, "==", stringify(c), true, false);
}
::add_expr(docfilter, statofilter);
}
::add_expr(filter, docfilter);
TRectype from(LF_DOC);
TRectype to(from);
TDate da = m.get_date(F_DA_DATADOC);
TDate a = m.get_date(F_A_DATADOC);
const int anno = m.get_int(F_ANNO);
if (!da.ok())
da = TDate(1, 1, anno);
if (!a.ok())
a = TDate(31, 12, anno);
from.put(DOC_DATADOC, da);
to.put(DOC_DATADOC, a);
val = m.get(F_ANNO);
from.put(DOC_ANNO, val);
to.put(DOC_ANNO, val);
val = m.get(F_PROVV);
from.put(DOC_PROVV, val);
to.put(DOC_PROVV, val);
from.put(DOC_CODNUM, from_num);
to.put(DOC_CODNUM, to_num);
cur->freeze(false);
cur->setregion(from, to);
cur->setfilter(filter);
const TRecnotype it = cur->items();
cur->freeze();
if (it > 0L)
*cur = 0L;
}
return cur;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// classe TListaDoc_application customizzata dalla TApplication per l'applicazione principale
//////////////////////////////////////////////////////////////////////////////////////////////
// Chiavi di ordinamento LF_DOC:
// Chiave 1: ordinamento per Provvisorio + Anno + Codice numerazione + Numero documento
// Chiave 3: ordinamento per Data documento + Provvisorio + Anno + Codice numerazione + Numero documento
class TLista_documenti_report : public TDocument_report
{
/* TString _codnum; // codice di numerazione
char _provv; // stampa documenti provvisiori o definitivi (D o P)
int _anno; // anno della documentazione
int _ncopie; // numero di copie per ogni documento
long _dalnum, _alnum; // estremi di numerazione dei documenti
TDate _dadata, _adata; // estremi di data dei documenti */
TStampa_lista_docs_mask * _m;
protected:
bool set_recordset(const TString& query);
public:
TLista_documenti_report(TStampa_lista_docs_mask * m) : _m(m) {}
};
bool TLista_documenti_report::set_recordset(const TString& query)
{
return TReport::set_recordset(new TLista_documenti_recordset(query, _m));
}
//////////////////////////////////////////////////////////////////////////////////////////////
// classe TListaDoc_application customizzata dalla TApplication per l'applicazione principale
//////////////////////////////////////////////////////////////////////////////////////////////
class TListaDoc_application: public TSkeleton_application
{
protected:
virtual bool create();
virtual void main_loop();
public:
TListaDoc_application() {};
virtual ~TListaDoc_application() {};
};
bool TListaDoc_application::create()
{
return TSkeleton_application::create();
}
void TListaDoc_application::main_loop()
{
TStampa_lista_docs_mask m;
TLista_documenti_report report(&m);
m.set(F_REPORT, "ve16001");
while (m.run() != K_QUIT)
{
TReport_book book;
TFilename report_name = m.get(F_REPORT);
if (report_name.blank())
report_name = "ve16001";
report.load(report_name);
book.add(report);
if (book.pages() > 0)
book.print_or_preview();
m.set(F_REPORT, "ve16001");
}
}
// Do all the work!
int ve1700(int argc, char* argv[])
{
TListaDoc_application a;
a.run(argc, argv, TR("Lista documenti"));
return 0;
}