campo-sirio/pe/pe0500.cpp
alex 7506d2214f Patch level : 10.0 290
Files correlati     : pe0.exe
Ricompilazione Demo : [ ]
Commento            :

Aggiunta colonna prezzo di vendita


git-svn-id: svn://10.65.10.50/trunk@18818 c028cbd2-c16b-5b4b-a496-9718f37d4682
2009-05-05 15:31:56 +00:00

306 lines
7.3 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 mat(format("VE%1d", livello + 1));
const int chars = atoi(name.after("PROG"));
mat.put("CODTAB", code);
if (mat.read(_isequal) != NOERR)
{
mat.zero();
mat.put("CODTAB", code);
mat.write();
}
const int prog = mat.get_int("I0") + 1;
mat.put("I0", prog);
mat.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 & p = row.get(RDOC_PREZZOV);
row.put(RDOC_PREZZO, p);
const real importo = row.importo(true, false);
total += importo;
}
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_num());
}
total = ZERO;
}
}
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)
doc.destroy_row(r, true);
}
}
}
///////////////////////////////////////////////////////////
// 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_rif();
o.preserve_original_rif();
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[0].put(DOC_K, doc_in[0].get(DOC_K));
doc_out.write();
doc_in.destroy(-1);
TDocumento esecutivo((const TRectype &)doc_out[0]);
doc_in.add(esecutivo);
doc_out.destroy(-1);
o.elabora(doc_in, doc_out, data);
doc_in.rewrite();
TDocumento & doc_dest = doc_out[0];
for (int r = doc_dest.physical_rows(); r > 0; r--)
{
TRiga_documento & row = (TRiga_documento &) doc_dest[r];
const TRiga_documento * r0 = (const TRiga_documento *)row.find_original_rdoc();
if (r0 != NULL)
{
const TRiga_documento * r1 = (const TRiga_documento *)r0->find_original_rdoc();
if (r1 != NULL)
row.set_original_rdoc_key(*r1);
}
}
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;
}