Files correlati : pe0.exe Ricompilazione Demo : [ ] Commento : Preventivi/incarichi (Dinamica) git-svn-id: svn://10.65.10.50/trunk@18732 c028cbd2-c16b-5b4b-a496-9718f37d4682
293 lines
6.9 KiB
C++
Executable File
293 lines
6.9 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
#include <utility.h>
|
|
|
|
#include "pe0500.h"
|
|
#include "../ve/velib.h"
|
|
#include "../ve/velib04.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TGenerazione_esecutivo
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGenerazione_esecutivo : public TCopia_documento
|
|
{
|
|
protected:
|
|
virtual void post_process_output(TLista_documenti& doc_out);
|
|
void genera_matricola(TRiga_documento & row);
|
|
|
|
public:
|
|
TGenerazione_esecutivo(const char* cod) : TCopia_documento(cod) {}
|
|
virtual ~TGenerazione_esecutivo() { }
|
|
};
|
|
|
|
void TGenerazione_esecutivo::genera_matricola(TRiga_documento & row)
|
|
{
|
|
for (int livello = 0; livello < 4; livello++)
|
|
{
|
|
TToken_string * str = row.tipo().genconf(livello);
|
|
|
|
if (str != NULL)
|
|
{
|
|
const TString codart = row.get(RDOC_CODART);
|
|
|
|
if (codart.full())
|
|
{
|
|
TString code;
|
|
const TRectype & anamag = cache().get(LF_ANAMAG, codart);
|
|
const int items = str->items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
const TString & name = str->get(i);
|
|
if (name.starts_with("PROG"))
|
|
{
|
|
TTable lv(format("LV%1d", livello + 1));
|
|
const int chars = atoi(name.after("PROG"));
|
|
|
|
lv.put("CODTAB", code);
|
|
if (lv.read(_isequal) != NOERR)
|
|
{
|
|
lv.zero();
|
|
lv.put("CODTAB", code);
|
|
lv.write();
|
|
}
|
|
const int prog = lv.get_int("I0") + 1;
|
|
lv.put("I0", prog);
|
|
lv.rewrite();
|
|
TString s; s << prog; s.lpad(chars, '0');
|
|
code << s;
|
|
}
|
|
else
|
|
if (name.starts_with("33."))
|
|
{
|
|
TFieldref fld(name.after("33."), LF_DOC);
|
|
|
|
code << fld.read(row.doc());
|
|
}
|
|
else
|
|
if (name.starts_with("34."))
|
|
{
|
|
TFieldref fld(name.after("34."), LF_RIGHEDOC);
|
|
|
|
code << fld.read(row);
|
|
}
|
|
else
|
|
if (name.starts_with("47."))
|
|
{
|
|
TFieldref fld(name.after("47."), LF_ANAMAG);
|
|
|
|
code << fld.read(anamag);
|
|
}
|
|
}
|
|
row.put(RDOC_LIVELLO, code);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGenerazione_esecutivo::post_process_output(TLista_documenti& doc_out)
|
|
{
|
|
const int items = doc_out.items();
|
|
|
|
for (int d = 0; d < items; d++)
|
|
{
|
|
const TDocumento& doc = doc_out[d];
|
|
const int rows = doc.physical_rows();
|
|
|
|
for (int r = 1; r <= rows; r++)
|
|
{
|
|
TRiga_documento & row = (TRiga_documento &)doc[r];
|
|
|
|
if (row.get_int(RDOC_LEVEL) == 0)
|
|
genera_matricola(row);
|
|
}
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TGenerazione_orsine
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGenerazione_ordine : public TCopia_documento
|
|
{
|
|
protected:
|
|
virtual void post_process_output(TLista_documenti& doc_out);
|
|
|
|
public:
|
|
TGenerazione_ordine(const char* cod) : TCopia_documento(cod) {}
|
|
virtual ~TGenerazione_ordine() { }
|
|
};
|
|
|
|
void TGenerazione_ordine::post_process_output(TLista_documenti& doc_out)
|
|
{
|
|
const int items = doc_out.items();
|
|
|
|
for (int d = 0; d < items; d++)
|
|
{
|
|
TDocumento& doc = doc_out[d];
|
|
const int rows = doc.physical_rows();
|
|
real total;
|
|
|
|
for (int r = rows; r > 0; r--)
|
|
{
|
|
TRiga_documento & row = (TRiga_documento &)doc[r];
|
|
const int level = row.get_int(RDOC_LEVEL);
|
|
|
|
if (level != 0)
|
|
{
|
|
const TString & k = row.get(RDOC_K);
|
|
TString ge;
|
|
real perc;
|
|
real importo = row.importo(true, false);
|
|
|
|
if (scontoexpr2perc(k, false, ge, perc))
|
|
importo *= (2 - perc);
|
|
total += importo;
|
|
doc.destroy_row(r, true);
|
|
}
|
|
else
|
|
{
|
|
if (total != ZERO)
|
|
{
|
|
const real qta = row.get_real(RDOC_QTA);
|
|
const real price = total / qta;
|
|
TCurrency_documento c(price, doc, true);
|
|
|
|
row.put(RDOC_PREZZO, c.get_value());
|
|
}
|
|
total = ZERO;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TGenEsecutivo mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGenEsecutivo_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TGenEsecutivo_mask() : TAutomask("pe0500a") { open(); }
|
|
};
|
|
|
|
bool TGenEsecutivo_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_FROM_FRNDOC:
|
|
case F_FROM_TONDOC:
|
|
if (e == fe_modify || e == fe_init)
|
|
{
|
|
const long docfr = get_long(F_FROM_FRNDOC);
|
|
const long docto = get_long(F_FROM_TONDOC);
|
|
if (docto > 0L && docfr > docto)
|
|
return error_box("Il documento finale non puo' essere maggiore di quello iniziale");
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Main program
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGenEsecutivo_app : public TSkeleton_application
|
|
{
|
|
|
|
protected:
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void TGenEsecutivo_app::main_loop()
|
|
{
|
|
open_files(LF_TAB, LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV,
|
|
LF_ANAMAG, LF_SCONTI, LF_UMART, LF_CLIFO, LF_CFVEN, LF_INDSP,
|
|
LF_OCCAS, LF_MOVMAG, LF_RMOVMAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, 0);
|
|
|
|
TGenEsecutivo_mask m;
|
|
while (m.run() == K_ENTER)
|
|
{
|
|
const TDate data(m.get_date(F_DATA));
|
|
TRectype rec_from(LF_DOC);
|
|
rec_from.put(DOC_ANNO, m.get(F_FROM_ANNO));
|
|
rec_from.put(DOC_CODNUM, m.get(F_FROM_NUM));
|
|
rec_from.put(DOC_PROVV, m.get(F_FROM_PROVV));
|
|
rec_from.put(DOC_NDOC, m.get(F_FROM_FRNDOC));
|
|
|
|
|
|
TRectype rec_to(rec_from);
|
|
rec_to.put(DOC_NDOC, m.get(F_FROM_TONDOC));
|
|
|
|
// Costruisce il filtro sui tipi documento selezionati
|
|
// Il pipe significa OR per le espressioni
|
|
TRelation rel(LF_DOC);
|
|
TCursor cur(&rel, "", 1, &rec_from, &rec_to);
|
|
|
|
const long tot = cur.items();
|
|
if (tot > 0L)
|
|
{
|
|
TGenerazione_esecutivo e(m.get(F_CODICE_ESEC));
|
|
TGenerazione_ordine o(m.get(F_CODICE_ORC));
|
|
|
|
e.preserve_original_row();
|
|
o.preserve_original_row();
|
|
cur.freeze();
|
|
TProgind pi(tot, "Generazione in corso...", FALSE, TRUE);
|
|
for (cur = 0; cur.pos() < tot; ++cur)
|
|
{
|
|
pi.addstatus(1);
|
|
|
|
TDocumento srcdoc(cur.curr()), newdoc;
|
|
|
|
if (e.is_document_ok(srcdoc))
|
|
{
|
|
TLista_documenti doc_in;
|
|
TLista_documenti doc_out;
|
|
|
|
doc_in.add(srcdoc);
|
|
e.elabora(doc_in, doc_out, data);
|
|
doc_in.rewrite();
|
|
doc_out.write();
|
|
doc_in.destroy(-1);
|
|
{
|
|
const TDocumento & esecutivo = doc_out[0];
|
|
for (int r = esecutivo.physical_rows(); r > 0; r--)
|
|
{
|
|
TRiga_documento & outrow = (TRiga_documento &) esecutivo[r];
|
|
const TRiga_documento & srcrow = srcdoc[r];
|
|
|
|
outrow.set_original_rdoc_key(srcrow);
|
|
}
|
|
doc_in.add(esecutivo);
|
|
}
|
|
doc_out.destroy(-1);
|
|
o.elabora(doc_in, doc_out, data);
|
|
doc_in.rewrite();
|
|
doc_out.write();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
warning_box("Nessun documento soddisfa i vincoli indicati");
|
|
}
|
|
}
|
|
|
|
int pe0500(int argc, char* argv[])
|
|
{
|
|
TGenEsecutivo_app a;
|
|
a.run(argc, argv, "Generazione Preventivi esecutivi e Ordini Clienti");
|
|
return 0;
|
|
}
|