Files correlati : Ricompilazione Demo : [ ] Commento : Prima versione delle stampe ordini: stampa per numero/data, per cli/fo, per agente, per Articolo git-svn-id: svn://10.65.10.50/trunk@6780 c028cbd2-c16b-5b4b-a496-9718f37d4682
1018 lines
29 KiB
C++
Executable File
1018 lines
29 KiB
C++
Executable File
// Stampa ordini
|
|
#include <applicat.h>
|
|
#include <mask.h>
|
|
#include <form.h>
|
|
#include <printer.h>
|
|
#include <tabutil.h>
|
|
#include "../ve/velib.h"
|
|
#include "../mg/mglib.h"
|
|
|
|
#include <doc.h>
|
|
#include <rdoc.h>
|
|
#include "or1100a.h"
|
|
|
|
// Tipi di stampa per selezionare il form
|
|
enum tipo_stampa {
|
|
numero, // or1100a.frm
|
|
clifo, // or1100b.frm
|
|
agente, // or1100d.frm
|
|
articolo // or1100c.frm
|
|
};
|
|
|
|
// Tipi di ordinamento
|
|
enum tipo_ord {
|
|
num_doc, // ordinamento per numero documento
|
|
data_doc // ordinamento per data documento
|
|
};
|
|
|
|
|
|
class _TTotale_valuta : public TObject
|
|
{
|
|
real _totord, _totres;
|
|
int _secnum;
|
|
public:
|
|
real& totord() { return _totord;}
|
|
real& totres() { return _totres;}
|
|
int& secnum() { return _secnum;}
|
|
_TTotale_valuta () {};
|
|
};
|
|
|
|
// Form per la stampa ordini
|
|
class TOrdine_form : public TForm
|
|
{
|
|
int _level;
|
|
bool _detail_mag, _detail_dep;
|
|
TCodgiac_livelli * _codgiac;
|
|
TTable *_fcg;
|
|
TArticolo *_art;
|
|
TAssoc_array _totvaluta;
|
|
|
|
protected:
|
|
virtual bool validate(TForm_item &, TToken_string &); // gestione dei messaggi estesi nei campi
|
|
public:
|
|
void set_options(int lev, bool mag, bool dep) { _level = lev; _detail_mag = mag; _detail_dep = dep;}
|
|
TOrdine_form(const char* name);
|
|
virtual ~TOrdine_form() ;
|
|
};
|
|
|
|
TOrdine_form::TOrdine_form(const char* name) : TForm(name)
|
|
{
|
|
_art = new TArticolo;
|
|
_fcg = new TTable("FCG");
|
|
_codgiac = new TCodgiac_livelli;
|
|
}
|
|
|
|
TOrdine_form::~TOrdine_form()
|
|
{
|
|
delete _art;
|
|
delete _fcg;
|
|
delete _codgiac;
|
|
}
|
|
|
|
bool TOrdine_form::validate(TForm_item &cf, TToken_string &s)
|
|
{
|
|
const TString code(s.get(0));
|
|
|
|
if (code == "_ORDINE")
|
|
{
|
|
TLocalisamfile& rdoc = cf.form().cursor()->file(LF_RIGHEDOC);
|
|
TLocalisamfile& doc = cf.form().cursor()->file(LF_DOC);
|
|
// Add custom messages here
|
|
// All the following messages takes 1 parameter: the field number to set
|
|
TString action(s.get(1));
|
|
|
|
if (action == "DESCRIZIONE")
|
|
{
|
|
// Scrive: Cod articolo/cod livello1/cod livello2/.../denominazione ultimo livello codifica /cod mag /cod dep
|
|
TString codart,livello, coddep, codmag;
|
|
codart = rdoc.get(RDOC_CODART);
|
|
if (_level > 0)
|
|
livello = rdoc.get(RDOC_LIVELLO);
|
|
if (livello.not_empty())
|
|
{
|
|
for (int lev=1; lev <= _level; lev++)
|
|
{
|
|
if (!_codgiac->enabled(lev))
|
|
continue;
|
|
const int starts = _codgiac->code_start(lev) -1;
|
|
const int length = _codgiac->code_length(lev);
|
|
codart << "/";
|
|
codart << livello.mid(starts,length);
|
|
}
|
|
codart << " " << _codgiac->name(_level);
|
|
codart << " " << _codgiac->group_descr(livello,_level);
|
|
}
|
|
|
|
codmag = rdoc.get(RDOC_CODMAG).left(3);
|
|
coddep = rdoc.get(RDOC_CODMAG).right(2);
|
|
if (_detail_mag && codmag.not_empty())
|
|
codart << " Mag. " << codmag;
|
|
if (_detail_dep && coddep.not_empty())
|
|
codart << " Dep. " << coddep;
|
|
|
|
cf.set(codart);
|
|
}
|
|
else
|
|
if (action == "SELECTUM")
|
|
{
|
|
TString um(rdoc.get(RDOC_UMQTA));
|
|
TString cur_um(cf.find_field("407").get());
|
|
|
|
if (cur_um.empty()) // Se l'unita' di misura non e' ancora stata settata prende quella principale
|
|
cf.set(um);
|
|
else
|
|
if (cur_um != um) // Se c'e' ma e' diversa dalla prec. allora setta l'unita' di misura su quella principale
|
|
if (_art->read(rdoc.get(RDOC_CODART)) == NOERR)
|
|
{
|
|
// Converte i totali q.ta evasa e ordinata nella unita' di misura principale
|
|
const real fc = _art->um().row(_art->find_um(cur_um)).get("FCONV");
|
|
TForm_item& qo = cf.find_field("408");
|
|
TForm_item& qe = cf.find_field("409");
|
|
real qtaor(qo.get());
|
|
real qtaev(qe.get());
|
|
|
|
qtaor *= fc;
|
|
qtaev *= fc;
|
|
qo.set(qtaor.string());
|
|
qe.set(qtaev.string());
|
|
|
|
cf.set(_art->um().row(1).get("UM")); // UM principale
|
|
}
|
|
// hmmm.. TBI:
|
|
// Riga merce non a magazzino o non e' possibile reperire l'UM principale per art.
|
|
// non posso interrompere la sezione di stampa da qui, e neppure cambiare il raggruppamento...
|
|
// This seems to be a great dilemma... For now leave it as is: Somme dure e crude di quantita'
|
|
}
|
|
else
|
|
if (action == "CONVUM") // Converte cazzilli quantitativi nella unita' di misura corrente
|
|
{
|
|
TString um(rdoc.get(RDOC_UMQTA));
|
|
TString cur_um(cf.find_field("407").get());
|
|
|
|
if (cur_um != um)
|
|
if (_art->read(rdoc.get(RDOC_CODART)) == NOERR)
|
|
{
|
|
const real fc = _art->um().row(_art->find_um(cur_um)).get("FCONV");
|
|
real qt(cf.get());
|
|
qt *= fc;
|
|
cf.set(qt.string());
|
|
}
|
|
}
|
|
else
|
|
if (action == "VALTABLE") // Comandi per stampa riepilogo per valuta
|
|
{
|
|
TString subcommand(s.get(2));
|
|
if (subcommand == "RESET")
|
|
{
|
|
_totvaluta.destroy();
|
|
cf.find_field("TOTVAL1").disable();
|
|
cf.find_field("TOTVAL2").disable();
|
|
cf.find_field("TOTVAL3").disable();
|
|
cf.find_field("TOTVAL4").disable();
|
|
}
|
|
else
|
|
{
|
|
const int valute = _totvaluta.items();
|
|
TString codval(doc.get(DOC_CODVAL));
|
|
const bool is_key = _totvaluta.is_key(codval);
|
|
const bool is_new = !is_key && valute < 4;
|
|
|
|
if (is_new) // Aggiunge l'elemento se non c'e'
|
|
_totvaluta.add(codval,(_TTotale_valuta*)new _TTotale_valuta,is_key);
|
|
// Controlla/stampa al massimo 4 valute
|
|
if (is_key || is_new)
|
|
{
|
|
_TTotale_valuta& tv = (_TTotale_valuta&)_totvaluta[codval];
|
|
const bool is_valord = subcommand == "VALORD";
|
|
real& r = is_valord ? tv.totord() : tv.totres();
|
|
TString s_id;
|
|
int i_id;
|
|
|
|
// Abilita la sezione corrispondente e setta i valori all'interno
|
|
if (!is_key)
|
|
{
|
|
TString16 sec_name = "TOTVAL";
|
|
sec_name << valute+1;
|
|
tv.secnum() = valute+1;
|
|
cf.find_field(sec_name).enable();
|
|
// Setta anche il codice valuta
|
|
i_id = 53 + valute*10;
|
|
s_id.format("%d",i_id);
|
|
cf.find_field(s_id).set(codval);
|
|
if (valute == 0)
|
|
{
|
|
i_id--;
|
|
s_id.format("%d",i_id);
|
|
cf.find_field(s_id).set("Totali");
|
|
}
|
|
}
|
|
const int sn = tv.secnum();
|
|
i_id = is_valord ? 55 : 56;
|
|
|
|
i_id += (sn-1)*10;
|
|
s_id.format("%d",i_id);
|
|
r += ((real) cf.get()); // Somma il valore corrente
|
|
cf.find_field(s_id).set(r.string());
|
|
}
|
|
}
|
|
}
|
|
//Ignore any other command
|
|
}
|
|
return TForm::validate(cf, s);
|
|
}
|
|
|
|
// Applicazione di stampa
|
|
|
|
class TStampa_ordini : public TSkeleton_application
|
|
{
|
|
TMask * _m;
|
|
TOrdine_form * _frm;
|
|
TTable * _fcg;
|
|
tipo_stampa _tipo;
|
|
TCodgiac_livelli *_codgiac;
|
|
TString _codnum;
|
|
int _anno;
|
|
char _provv, _tipocf,
|
|
_TEA_ord, _TEA_rord; // Tipi ordini/righe 'T'utti/'E'vasi/'A'perti
|
|
tipo_ord _order;
|
|
bool _detail_rows, _detail_doc, _detail_cli, _detail_mag, _detail_dep;
|
|
int _detail_level; //0..4 0 = Articoli 4 = FCG #4 Maximum detail level
|
|
TString _from_age, _to_age,
|
|
_from_art, _to_art,
|
|
_from_mag, _to_mag,
|
|
_from_dep, _to_dep;
|
|
TString_array
|
|
_from_giac, _to_giac;
|
|
long _from_ndoc, _to_ndoc,
|
|
_from_cf, _to_cf;
|
|
TDate _from_date, _to_date,
|
|
_from_cons, _to_cons;
|
|
TArray _file;
|
|
|
|
protected:
|
|
void open_files(int logicnum, ...);
|
|
static bool stato_handler(TMask_field& f, KEY k);
|
|
static bool detail_handler(TMask_field& f, KEY k);
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
void filter_for_number();
|
|
void filter_for_clifo_agent();
|
|
void filter_for_articolo();
|
|
public:
|
|
TStampa_ordini() {};
|
|
virtual ~TStampa_ordini() {};
|
|
};
|
|
|
|
inline TStampa_ordini& app() { return (TStampa_ordini&) main_app();}
|
|
|
|
void TStampa_ordini::open_files(int logicnum, ...)
|
|
{
|
|
va_list marker;
|
|
va_start(marker, logicnum);
|
|
while (logicnum > 0)
|
|
{
|
|
CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
|
|
_file.add(new TLocalisamfile(logicnum), logicnum);
|
|
logicnum = va_arg(marker, int);
|
|
}
|
|
}
|
|
|
|
bool TStampa_ordini::stato_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (f.to_check(k))
|
|
{
|
|
TMask& m = f.mask();
|
|
const char v = f.get()[0];
|
|
const bool b = m.get_bool(F_DETTAGLIO);
|
|
if (v == 'E' && b) // Se si seleziona la stampa degli ordini totalmente evasi ha senso stampare solo le righe evase, cioe' tutte
|
|
{
|
|
m.set(F_STATORORD, "T");
|
|
m.disable(F_STATORORD);
|
|
}
|
|
else
|
|
if (b) // Qualsiasi altro tipo di stampa dettaglio righe puo' essere selezionata
|
|
m.enable(F_STATORORD);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampa_ordini::detail_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
const bool b = m.get_bool(F_DETTAGLIO);
|
|
const tipo_stampa tipo = (tipo_stampa) m.get_int(F_TIPO);
|
|
|
|
if (tipo != numero)
|
|
{
|
|
m.enable(-GR_DETAIL,b);
|
|
m.enable(F_STATOORD,!b);
|
|
if (tipo != articolo)
|
|
m.set(F_DETAIL_BY_DOC, !b ? "" : "X");
|
|
}
|
|
else
|
|
{
|
|
m.enable(-GR_ART,b);
|
|
m.enable(-GR_MAG,b);
|
|
m.enable(F_STATORORD,b);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampa_ordini::create()
|
|
{
|
|
open_files(LF_OCCAS, LF_CLIFO, LF_INDSP, LF_CFVEN, LF_MOVMAG, LF_RMOVMAG, 0);
|
|
_m = new TMask ("or1100a");
|
|
_m->set_handler(F_STATOORD, stato_handler);
|
|
_m->set_handler(F_DETTAGLIO, detail_handler);
|
|
_fcg = new TTable("FCG");
|
|
_codgiac = new TCodgiac_livelli;
|
|
if (!_codgiac->enabled())
|
|
{
|
|
_m->hide(F_DETAIL_LEV);
|
|
_m->hide(-GR_GIAC);
|
|
}
|
|
|
|
short id = F_GIAC1;
|
|
int l = 5;
|
|
for (_fcg->first(); _fcg->good(); _fcg->next(), id+=4)
|
|
_m->set(id, _fcg->get("CODTAB"));
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TStampa_ordini::destroy()
|
|
{
|
|
delete _m;
|
|
delete _fcg;
|
|
delete _codgiac;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TStampa_ordini::filter_for_number()
|
|
{
|
|
CHECK(_frm, "Form non valido");
|
|
|
|
TCursor* cur = _frm->cursor();
|
|
|
|
TDocumento *doc = new TDocumento; // Don't delete it
|
|
cur->file().set_curr(doc);
|
|
cur->file(LF_RIGHEDOC).set_curr(new TRiga_documento(doc));
|
|
cur->setkey(_order == num_doc ? 1 : 3); // Selezione per numero doc o data emissione
|
|
|
|
TRectype f(LF_DOC), t(LF_DOC);
|
|
TString filter_expr,s;
|
|
|
|
filter_expr << "(TIPOCF==\"" << _tipocf << "\")";
|
|
if (_order == num_doc)
|
|
{
|
|
f.put(DOC_PROVV, _provv);
|
|
f.put(DOC_ANNO, _anno);
|
|
f.put(DOC_CODNUM, _codnum);
|
|
t = f;
|
|
f.put(DOC_NDOC, _from_ndoc);
|
|
t.put(DOC_NDOC, _to_ndoc);
|
|
}
|
|
else
|
|
{
|
|
f.put(DOC_DATADOC, _from_date);
|
|
t.put(DOC_DATADOC, _to_date);
|
|
filter_expr << " && (PROVV==\"" << _provv << "\")";
|
|
filter_expr << " && (ANNO==\"" << _anno << "\")";
|
|
filter_expr << " && (CODNUM==\"" << _codnum << "\")";
|
|
}
|
|
cur->setregion(f,t);
|
|
|
|
if (_TEA_ord == 'E')
|
|
filter_expr << " && (DOCEVASO==\"X\")";
|
|
else
|
|
if (_TEA_ord == 'A')
|
|
filter_expr << " && (DOCEVASO!=\"X\")";
|
|
|
|
if (_from_cons.ok())
|
|
{
|
|
filter_expr << "&&";
|
|
s.format("(ANSI(DATACONS)>=\"%s\")",
|
|
(const char*)_from_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
if (_to_cons.ok())
|
|
{
|
|
filter_expr << "&&";
|
|
s.format("(ANSI(DATACONS)<=\"%s\")",
|
|
(const char*)_to_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
|
|
cur->setfilter(filter_expr);
|
|
|
|
if (_detail_rows)
|
|
{
|
|
for (short i = 6; i<=8; i++)
|
|
_frm->find_field('B', odd_page, i).show();
|
|
_frm->find_field('B', odd_page, "DET").show(); // Visualizza la sottosezione
|
|
TForm_subsection& ssec = (TForm_subsection&)_frm->find_field('B', odd_page, "RIGHE"); // Sottosezione padre
|
|
|
|
// Applica gli altri filtri alla sezione
|
|
TString cond;
|
|
if (_TEA_rord == 'E')
|
|
s.format("(%d->RIGAEVASA==\"X\")",LF_RIGHEDOC);
|
|
else
|
|
if (_TEA_rord == 'A')
|
|
s.format("(%d->RIGAEVASA!=\"X\")",LF_RIGHEDOC);
|
|
|
|
cond << s;
|
|
|
|
// Setta i range per la data di consegna
|
|
if (_from_cons.ok())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(ANSI(%d->DATACONS)>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_cons.string(ANSI));
|
|
cond << s;
|
|
}
|
|
if (_to_cons.ok())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(ANSI(%d->DATACONS)<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_cons.string(ANSI));
|
|
cond << s;
|
|
}
|
|
|
|
// Setta i range per il codice magazzino
|
|
if (_from_mag.not_empty())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(%d->CODMAG>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_mag);
|
|
cond << s;
|
|
}
|
|
if (_to_mag.not_empty())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(%d->CODMAG<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_mag);
|
|
cond << s;
|
|
}
|
|
|
|
// Setta i range per il codice articolo
|
|
if (_from_art.not_empty())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(%d->CODART>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_art);
|
|
cond << s;
|
|
}
|
|
if (_to_art.not_empty())
|
|
{
|
|
if (s.not_empty())
|
|
cond << "&&";
|
|
s.format("(%d->CODART<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_art);
|
|
cond << s;
|
|
}
|
|
|
|
if (s.not_empty())
|
|
ssec.setcondition(cond, _strexpr);
|
|
}
|
|
}
|
|
|
|
void TStampa_ordini::filter_for_clifo_agent()
|
|
{
|
|
CHECK(_frm, "Form non valido");
|
|
|
|
const bool is_for_cli = _tipo == clifo;
|
|
|
|
TString s, ws,lev_str, mag_str;
|
|
TSorted_cursor* cur = (TSorted_cursor*)_frm->cursor();
|
|
|
|
TDocumento *doc = new TDocumento;
|
|
cur->file(LF_DOC).set_curr(doc);
|
|
cur->file(LF_RIGHEDOC).set_curr(new TRiga_documento(doc));
|
|
if (_detail_rows && !_detail_doc) // Cambia l'ordinamento se si vuol dettagliare per articolo e non per documento
|
|
{
|
|
if (_detail_level > 0)
|
|
lev_str.format("LIVELLO[1,%d]",_codgiac->packed_length(_detail_level));
|
|
if (_detail_mag)
|
|
mag_str.format("CODMAG[1,3]");
|
|
if (_detail_dep)
|
|
mag_str.format("CODMAG");
|
|
|
|
if (!is_for_cli)
|
|
s.format("%d->CODAG|",LF_DOC);
|
|
if (is_for_cli || _detail_cli)
|
|
{
|
|
ws.format("%d->TIPOCF|%d->CODCF|",LF_DOC, LF_DOC);
|
|
s << ws;
|
|
}
|
|
s << "CODART|";
|
|
if (lev_str.not_empty())
|
|
s << lev_str << "|";
|
|
if (mag_str.not_empty())
|
|
s << mag_str << "|";
|
|
s << "DATACONS";
|
|
cur->change_order(s);
|
|
}
|
|
//Mo setto li filtri, altrimenti stampa tutto er file de' righe documento
|
|
TRectype f(LF_RIGHEDOC), t(LF_RIGHEDOC);
|
|
TString filter_expr;
|
|
|
|
f.put(DOC_PROVV, _provv);
|
|
f.put(DOC_ANNO, _anno);
|
|
f.put(DOC_CODNUM, _codnum);
|
|
t = f;
|
|
cur->setregion(f,t); // This is the region...
|
|
|
|
s.format("(%d->TIPOCF==\"",LF_DOC);
|
|
filter_expr << s << _tipocf << "\")"; // Nel caso di stampa per agenti e' sempre "C"
|
|
|
|
// Filtro su Cli/Fo od agente
|
|
if (is_for_cli)
|
|
{
|
|
if (_from_cf > 0L)
|
|
{
|
|
s.format("&&(STR(NUM(%d->CODCF)>=%ld))", LF_DOC, _from_cf);
|
|
filter_expr << s;
|
|
}
|
|
|
|
if (_to_cf > 0L)
|
|
{
|
|
s.format("&&(STR(NUM(%d->CODCF)<=%ld))", LF_DOC, _to_cf);
|
|
filter_expr << s;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_from_age.not_empty())
|
|
{
|
|
s.format("&&(%d->CODAG>=%ld)", LF_DOC, (const char*)_from_age);
|
|
filter_expr << s;
|
|
}
|
|
|
|
if (_to_age.not_empty())
|
|
{
|
|
s.format("&&(%d->CODAG)<=%ld)", LF_DOC, _to_age);
|
|
filter_expr << s;
|
|
}
|
|
}
|
|
|
|
|
|
// Filtro sulla data ordine...
|
|
if (_from_date.ok())
|
|
{
|
|
s.format("&&(ANSI(%d->DATADOC)>=\"%s\")", LF_DOC,
|
|
(const char*)_from_date.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
if (_to_date.ok())
|
|
{
|
|
s.format("&&(ANSI(%d->DATADOC)<=\"%s\")", LF_DOC,
|
|
(const char*)_to_date.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
|
|
// Filtro sulla data consegna...
|
|
if (_from_cons.ok())
|
|
{
|
|
s.format("&&(ANSI(DATACONS)>=\"%s\")",
|
|
(const char*)_from_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
if (_to_cons.ok())
|
|
{
|
|
s.format("&&(ANSI(DATACONS)<=\"%s\")",
|
|
(const char*)_to_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
|
|
if (_detail_rows)
|
|
{
|
|
// Setta i range per il codice articolo
|
|
if (_from_art.not_empty())
|
|
{
|
|
s.format("&&(%d->CODART>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_art);
|
|
filter_expr << s;
|
|
}
|
|
if (_to_art.not_empty())
|
|
{
|
|
filter_expr << "&&";
|
|
s.format("(%d->CODART<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_art);
|
|
filter_expr << s;
|
|
}
|
|
// Setta i range per i livelli di giacenza (da 1 a 4)
|
|
if (_detail_level > 0)
|
|
for (int lev=1, index=0; lev <= _detail_level; lev++)
|
|
{
|
|
if (!_codgiac->enabled(lev))
|
|
continue;
|
|
TString& from = (TString&) _from_giac[index];
|
|
TString& to = (TString&) _to_giac[index++];
|
|
const int starts = _codgiac->code_start(lev);
|
|
const int ends = starts+_codgiac->code_length(lev);
|
|
if (from.not_empty())
|
|
{
|
|
s.format("&&(%d->LIVELLO[%d,%d]>=\"%s\")",
|
|
LF_RIGHEDOC,starts,ends,(const char*)from);
|
|
filter_expr << s;
|
|
}
|
|
if (to.not_empty())
|
|
{
|
|
s.format("&&(%d->LIVELLO[%d,%d]<=\"%s\")",
|
|
LF_RIGHEDOC,starts,ends,(const char*)to);
|
|
filter_expr << s;
|
|
}
|
|
}
|
|
// Setta i range per il codice magazzino (deposito incluso)
|
|
if (_from_mag.not_empty())
|
|
{
|
|
s.format("&&(%d->CODMAG>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_mag);
|
|
filter_expr << s;
|
|
}
|
|
if (_to_mag.not_empty())
|
|
{
|
|
s.format("&&(%d->CODMAG<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_mag);
|
|
filter_expr << s;
|
|
}
|
|
}
|
|
|
|
s = "";
|
|
if (!_detail_rows)
|
|
{
|
|
if (_TEA_ord == 'E')
|
|
s.format("&&(%d->DOCEVASO==\"X\")",LF_DOC);
|
|
else
|
|
if (_TEA_ord == 'A')
|
|
s.format("&&(%d->DOCEVASO!=\"X\")",LF_DOC);
|
|
}
|
|
else
|
|
{
|
|
if (_TEA_rord == 'E')
|
|
s.format("(%d->RIGAEVASA==\"X\")",LF_RIGHEDOC);
|
|
else
|
|
if (_TEA_rord == 'A')
|
|
s.format("(%d->RIGAEVASA!=\"X\")",LF_RIGHEDOC);
|
|
}
|
|
|
|
if (s.not_empty())
|
|
filter_expr << s;
|
|
|
|
cur->setfilter(filter_expr,TRUE);
|
|
|
|
// Alla fine setta i campi da vedere
|
|
if (!is_for_cli && _detail_cli)
|
|
{
|
|
// Solo stampa per agenti: se si e' settato il distinguo per clienti
|
|
// mostra l'intestazione prima di ogni cambio cliente
|
|
TForm_subsection& ssec = (TForm_subsection&) _frm->find_field('B', odd_page, "HCLIENTI");
|
|
ssec.enable();
|
|
}
|
|
|
|
if (!_detail_rows || _detail_doc) // Stampa distinguendo per documento e non per righe articolo...
|
|
{
|
|
TForm_subsection& ssec = (TForm_subsection&) _frm->find_field('B', odd_page, "DOCUMENTI");
|
|
if (!is_for_cli && _detail_doc)
|
|
ssec.enable(); // Se stampa per agenti e dettaglia documenti per cliente abilita la sezione
|
|
else
|
|
{ // Se stampa per cli/fo abilita i campi corrispondenti al distinguo per documento (valuta, residuo evaso ecc...)
|
|
ssec.printsection().find_field(101).show();
|
|
for (short id = 102; id <= 106; id++)
|
|
ssec.printsection().find_field(id).enable();
|
|
}
|
|
}
|
|
|
|
if (_detail_rows) // Stampa dettaglio righe...
|
|
{
|
|
for (short i = 7; i<=9; i++)
|
|
_frm->find_field('B', odd_page, i).show(); // Aggiunge le colonne di dettaglio
|
|
// dulcis in fundo (Dulcinea mia adorata), si abilita la sezione RIGHEART
|
|
// anziche' RIGHEDOC nel qual caso sia stato specificato il raggruppamento per Articoli (e sotto-opzioni)
|
|
if (!_detail_doc) // Se la stampa deve distinguere e dettagliare per articoli e non per documenti...
|
|
{
|
|
TString cond;
|
|
TForm_item& ff = _frm->find_field('B', odd_page, "RIGHEDOC");
|
|
ff.y() = 1;
|
|
|
|
if (!is_for_cli) // Abilita la sottosezione principale se stampa per agenti
|
|
{
|
|
TForm_subsection& ssec = (TForm_subsection&) _frm->find_field('B', odd_page, "ARTCLI");
|
|
ssec.enable();
|
|
if (_detail_cli) // Se e' abilitata la distinzione per clienti setta l'espressione di raggruppamento
|
|
{
|
|
cond = ssec.condition();
|
|
cond << LF_CLIFO << "->TIPOCF+" << LF_CLIFO << "->CODCF";
|
|
ssec.setcondition(cond, _strexpr);
|
|
}
|
|
}
|
|
|
|
// Setta la condizione di raggruppamento principale per articoli (comune alla stampa per cli/fo e per agenti)
|
|
TForm_subsection& ssec = (TForm_subsection&) _frm->find_field('B', odd_page, "RIGHEART");
|
|
ssec.enable();
|
|
cond = ssec.condition();
|
|
if (lev_str.not_empty())
|
|
cond << "+" << lev_str;
|
|
if (mag_str.not_empty())
|
|
cond << "+" << mag_str;
|
|
ssec.setcondition(cond, _strexpr);
|
|
|
|
if (is_for_cli)
|
|
{ // I seguenti campi non necessitano di abilitazione se la stampa e' per agente
|
|
TForm_subsection& dsec = (TForm_subsection&) _frm->find_field('B', odd_page, "DOCUMENTI");
|
|
for (short id = 401; id <= 409; id++)
|
|
dsec.printsection().find_field(id).enable();
|
|
}
|
|
}
|
|
else
|
|
_frm->find_field('B', odd_page, "RIGHEDOC").enable(); // Abilita la sezione di dettaglio righe PER DOCUMENTO
|
|
}
|
|
}
|
|
|
|
void TStampa_ordini::filter_for_articolo()
|
|
{
|
|
CHECK(_frm, "Form non valido");
|
|
|
|
TString s, ws,lev_str, mag_str;
|
|
TSorted_cursor* cur = (TSorted_cursor*)_frm->cursor();
|
|
|
|
if (_detail_level > 0)
|
|
lev_str.format("LIVELLO[1,%d]",_codgiac->packed_length(_detail_level));
|
|
if (_detail_mag)
|
|
mag_str.format("CODMAG[1,3]");
|
|
if (_detail_dep)
|
|
mag_str.format("CODMAG");
|
|
|
|
s << "CODART|";
|
|
if (lev_str.not_empty())
|
|
s << lev_str << "|";
|
|
if (mag_str.not_empty())
|
|
s << mag_str << "|";
|
|
s << "DATACONS";
|
|
cur->change_order(s); // Setta l'ordine
|
|
|
|
|
|
TDocumento *doc = new TDocumento;
|
|
cur->file(LF_DOC).set_curr(doc);
|
|
cur->file(LF_RIGHEDOC).set_curr(new TRiga_documento(doc));
|
|
|
|
TRectype f(LF_RIGHEDOC), t(LF_RIGHEDOC);
|
|
TString filter_expr;
|
|
|
|
f.put(DOC_PROVV, _provv);
|
|
f.put(DOC_ANNO, _anno);
|
|
f.put(DOC_CODNUM, _codnum);
|
|
t = f;
|
|
cur->setregion(f,t); // This is the region...
|
|
|
|
s.format("(%d->TIPOCF==\"",LF_DOC);
|
|
filter_expr << s << _tipocf << "\")"; // Nel caso di stampa per agenti e' sempre "C"
|
|
|
|
// Filtro su Cli/Fo
|
|
if (_from_cf > 0L)
|
|
{
|
|
s.format("&&(STR(NUM(%d->CODCF)>=%ld))", LF_DOC, _from_cf);
|
|
filter_expr << s;
|
|
}
|
|
|
|
if (_to_cf > 0L)
|
|
{
|
|
s.format("&&(STR(NUM(%d->CODCF)<=%ld))", LF_DOC, _to_cf);
|
|
filter_expr << s;
|
|
}
|
|
// Filtro sulla data ordine...
|
|
if (_from_date.ok())
|
|
{
|
|
s.format("&&(ANSI(%d->DATADOC)>=\"%s\")", LF_DOC,
|
|
(const char*)_from_date.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
if (_to_date.ok())
|
|
{
|
|
s.format("&&(ANSI(%d->DATADOC)<=\"%s\")", LF_DOC,
|
|
(const char*)_to_date.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
|
|
// Filtro sulla data consegna...
|
|
if (_from_cons.ok())
|
|
{
|
|
s.format("&&(ANSI(DATACONS)>=\"%s\")",
|
|
(const char*)_from_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
if (_to_cons.ok())
|
|
{
|
|
s.format("&&(ANSI(DATACONS)<=\"%s\")",
|
|
(const char*)_to_cons.string(ANSI));
|
|
filter_expr << s;
|
|
}
|
|
|
|
if (_from_art.not_empty())
|
|
{
|
|
s.format("&&(%d->CODART>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_art);
|
|
filter_expr << s;
|
|
}
|
|
if (_to_art.not_empty())
|
|
{
|
|
filter_expr << "&&";
|
|
s.format("(%d->CODART<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_art);
|
|
filter_expr << s;
|
|
}
|
|
// Setta i range per i livelli di giacenza (da 1 a 4)
|
|
if (_detail_level > 0)
|
|
for (int lev=1, index=0; lev <= _detail_level; lev++)
|
|
{
|
|
if (!_codgiac->enabled(lev))
|
|
continue;
|
|
TString& from = (TString&) _from_giac[index];
|
|
TString& to = (TString&) _to_giac[index++];
|
|
const int starts = _codgiac->code_start(lev);
|
|
const int ends = starts+_codgiac->code_length(lev);
|
|
if (from.not_empty())
|
|
{
|
|
s.format("&&(%d->LIVELLO[%d,%d]>=\"%s\")",
|
|
LF_RIGHEDOC,starts,ends,(const char*)from);
|
|
filter_expr << s;
|
|
}
|
|
if (to.not_empty())
|
|
{
|
|
s.format("&&(%d->LIVELLO[%d,%d]<=\"%s\")",
|
|
LF_RIGHEDOC,starts,ends,(const char*)to);
|
|
filter_expr << s;
|
|
}
|
|
}
|
|
// Setta i range per il codice magazzino (deposito incluso)
|
|
if (_from_mag.not_empty())
|
|
{
|
|
s.format("&&(%d->CODMAG>=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_from_mag);
|
|
filter_expr << s;
|
|
}
|
|
if (_to_mag.not_empty())
|
|
{
|
|
s.format("&&(%d->CODMAG<=\"%s\")",
|
|
LF_RIGHEDOC, (const char*)_to_mag);
|
|
filter_expr << s;
|
|
}
|
|
|
|
s = "";
|
|
if (_TEA_rord == 'E')
|
|
s.format("(%d->RIGAEVASA==\"X\")",LF_RIGHEDOC);
|
|
else
|
|
if (_TEA_rord == 'A')
|
|
s.format("(%d->RIGAEVASA!=\"X\")",LF_RIGHEDOC);
|
|
|
|
if (s.not_empty())
|
|
filter_expr << s;
|
|
|
|
cur->setfilter(filter_expr,TRUE); // Setta il filtro e serra i ranghi
|
|
|
|
// Setta la condizione di raggruppamento principale per articoli (comune alla stampa per cli/fo e per agenti)
|
|
TForm_subsection& ssec = (TForm_subsection&) _frm->find_field('B', odd_page, "ARTICOLI");
|
|
ssec.enable();
|
|
s = ssec.condition();
|
|
if (lev_str.not_empty())
|
|
s << "+" << lev_str;
|
|
if (mag_str.not_empty())
|
|
s << "+" << mag_str;
|
|
ssec.setcondition(s, _strexpr);
|
|
|
|
for (short id = 401; id <= 409; id++)
|
|
_frm->find_field('B',odd_page,id).enable();
|
|
}
|
|
|
|
void TStampa_ordini::main_loop()
|
|
{
|
|
TString form_name;
|
|
|
|
while (_m->run()!=K_QUIT)
|
|
{
|
|
// selezione tipo di stampa per il form appropriato
|
|
_tipo = (tipo_stampa) _m->get_int(F_TIPO);
|
|
_codnum = _m->get(F_CODNUM);
|
|
_provv = _m->get(F_PROVV)[0];
|
|
_anno = _m->get_int(F_ANNO);
|
|
_order = _m->get(F_DATA_O_NUM)[0] == 'N' ? num_doc : data_doc;
|
|
_from_ndoc = _m->get_long(F_NDOCFROM);
|
|
_to_ndoc = _m->get_long(F_NDOCTO);
|
|
_from_date = _m->get_date(F_EMISFROM);
|
|
_to_date = _m->get_date(F_EMISTO);
|
|
_from_cons = _m->get_date(F_CONSFROM);
|
|
_to_cons = _m->get_date(F_CONSTO);
|
|
_from_age = _m->get(F_AGEFROM);
|
|
_to_age = _m->get(F_AGETO);
|
|
_from_cf = _m->get_long(F_CFFROM);
|
|
_to_cf = _m->get_long(F_CFTO);
|
|
_from_mag = _m->get(F_MAGFROM);
|
|
_to_mag = _m->get(F_MAGTO);
|
|
_from_dep = _m->get(F_DEPFROM);
|
|
_to_dep = _m->get(F_DEPTO);
|
|
if (_from_mag.not_empty())
|
|
_from_mag.left_just(3);
|
|
if (_to_mag.not_empty())
|
|
_to_mag.left_just(3);
|
|
_from_mag << _from_dep;
|
|
_to_mag << _to_dep;
|
|
|
|
_from_art = _m->get(F_ARTFROM);
|
|
_to_art = _m->get(F_ARTTO);
|
|
|
|
_from_giac.destroy();
|
|
_to_giac.destroy();
|
|
_from_giac.add(_m->get(F_GIAC1_FROM),0);
|
|
_to_giac.add(_m->get(F_GIAC1_TO),0);
|
|
_from_giac.add(_m->get(F_GIAC2_FROM),1);
|
|
_to_giac.add(_m->get(F_GIAC2_TO),1);
|
|
_from_giac.add(_m->get(F_GIAC3_FROM),2);
|
|
_to_giac.add(_m->get(F_GIAC3_TO),2);
|
|
_from_giac.add(_m->get(F_GIAC4_FROM),3);
|
|
_to_giac.add(_m->get(F_GIAC4_TO),3);
|
|
|
|
if (!_from_date.ok())
|
|
_from_date = botime;
|
|
if (!_to_date.ok())
|
|
_to_date = eotime;
|
|
_tipocf = _m->get(F_TIPOCF)[0];
|
|
_detail_rows = _m->get_bool(F_DETTAGLIO);
|
|
_detail_doc = _m->get_bool(F_DETAIL_BY_DOC);
|
|
_detail_cli = _m->get_bool(F_DETAIL_BY_CLI);
|
|
_detail_mag = _m->get_bool(F_DETAIL_MAG);
|
|
_detail_dep = _m->get_bool(F_DETAIL_DEP);
|
|
_detail_level = _m->get_int(F_DETAIL_LEV);
|
|
|
|
_TEA_ord = _m->get(F_STATOORD)[0];
|
|
_TEA_rord = _m->get(F_STATORORD)[0];
|
|
|
|
switch (_tipo)
|
|
{
|
|
case clifo:
|
|
form_name = "or1100b";
|
|
break;
|
|
case agente:
|
|
form_name = "or1100c";
|
|
break;
|
|
case articolo:
|
|
form_name = "or1100d";
|
|
break;
|
|
default:
|
|
form_name = "or1100a";
|
|
break;
|
|
}
|
|
|
|
_frm = new TOrdine_form(form_name);
|
|
_frm->set_options(_detail_level, _detail_mag, _detail_dep);
|
|
// Selezione cursore & filtro
|
|
switch (_tipo)
|
|
{
|
|
case clifo:
|
|
case agente:
|
|
filter_for_clifo_agent();
|
|
break;
|
|
case articolo:
|
|
filter_for_articolo();
|
|
break;
|
|
default:
|
|
filter_for_number();
|
|
break;
|
|
}
|
|
|
|
|
|
const int hh = 6;
|
|
const int fh = 1;
|
|
const int fl = printer().formlen();
|
|
|
|
int rows[4]; // Righe orizzontali
|
|
rows[0] = hh-2;
|
|
rows[1] = hh;
|
|
rows[2] = fl-1;
|
|
rows[3] = 0;
|
|
_frm->genera_intestazioni(odd_page, hh-1);
|
|
_frm->genera_fincatura(odd_page, hh-2, fl-1, rows);
|
|
|
|
// stampa
|
|
if (_frm->cursor()->items() > 0)
|
|
_frm->print();
|
|
delete _frm;
|
|
_m->reset();
|
|
}
|
|
}
|
|
|
|
int or1100(int argc, char** argv)
|
|
{
|
|
TStampa_ordini a;
|
|
a.run(argc,argv,"Stampa ordini");
|
|
return 0;
|
|
}
|