2011-06-05 17:03:25 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <real.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include "pg0002100a.h"
|
|
|
|
|
#include <doc.h>
|
|
|
|
|
#include <rdoc.h>
|
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
#include "../ve/velib.h"
|
|
|
|
|
#include "../ve/velib04.h"
|
|
|
|
|
|
|
|
|
|
// TAutomask
|
|
|
|
|
|
|
|
|
|
class TAggiorna_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
void serialize(bool bSave);
|
|
|
|
|
protected:
|
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
public:
|
|
|
|
|
TAggiorna_mask() : TAutomask("pg0002100a") {}
|
|
|
|
|
virtual ~TAggiorna_mask() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TAggiorna_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_RICARICO :
|
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
TMask & m = o.mask();
|
|
|
|
|
TArticolo & art = cached_article(m.get(F_CODART));
|
2011-06-08 10:02:31 +00:00
|
|
|
|
TCodiceIVA c(art.get(ANAMAG_CODIVA));
|
2011-06-05 17:03:25 +00:00
|
|
|
|
real costo(m.get(F_COSTO));
|
|
|
|
|
const real perc = cache().get("CVE", m.get(F_RICARICO), "R2");
|
|
|
|
|
real prezzo = costo * ( UNO + (perc / CENTO));
|
|
|
|
|
|
2011-06-08 10:02:31 +00:00
|
|
|
|
prezzo = c.lordo(prezzo, 20);
|
|
|
|
|
prezzo.round(0);
|
|
|
|
|
m.set(F_PREZZOL, prezzo, 0x3);
|
2011-06-05 17:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_PREZZO :
|
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
TMask & m = o.mask();
|
|
|
|
|
TArticolo & art = cached_article(m.get(F_CODART));
|
|
|
|
|
real prezzo(o.get());
|
|
|
|
|
TCodiceIVA c(art.get(ANAMAG_CODIVA));
|
|
|
|
|
|
|
|
|
|
prezzo = c.lordo(prezzo, 20);
|
|
|
|
|
prezzo.round(TCurrency::get_firm_dec(true));
|
|
|
|
|
m.set(F_PREZZOL, prezzo);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_PREZZOL :
|
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
TMask & m = o.mask();
|
|
|
|
|
TArticolo & art = cached_article(m.get(F_CODART));
|
|
|
|
|
real prezzo(o.get());
|
|
|
|
|
TCodiceIVA c(art.get(ANAMAG_CODIVA));
|
|
|
|
|
|
|
|
|
|
c.scorpora(prezzo, 20);
|
|
|
|
|
prezzo.round(TCurrency::get_firm_dec(true));
|
|
|
|
|
m.set(F_PREZZO, prezzo);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TAggiorna_prezzi : public TSkeleton_application
|
|
|
|
|
{
|
|
|
|
|
TDocumento * _doc;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual const char * extra_modules() const { return "ba"; }
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
const TDocumento & doc() { return *_doc; }
|
|
|
|
|
void aggiorna(TMask & m);
|
|
|
|
|
bool set_params(TMask & m);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// restituisce un riferimento all' applicazione
|
|
|
|
|
inline TAggiorna_prezzi & app() { return (TAggiorna_prezzi &) main_app();}
|
|
|
|
|
|
|
|
|
|
void TAggiorna_prezzi::aggiorna(TMask & m)
|
|
|
|
|
{
|
|
|
|
|
TSheet_field & sh = m.sfield(F_SHEET);
|
|
|
|
|
const int nrows = doc().physical_rows();
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= nrows; i++)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_documento & rdoc = doc()[i];
|
|
|
|
|
const TString & codart = rdoc.get(RDOC_CODARTMAG);
|
|
|
|
|
|
|
|
|
|
if (codart.full())
|
|
|
|
|
{
|
|
|
|
|
TToken_string & row = sh.row(-1);
|
|
|
|
|
|
|
|
|
|
row.add(codart, sh.cid2index(F_CODART));
|
|
|
|
|
row.add(rdoc.get(RDOC_UMQTA), sh.cid2index(F_UM));
|
|
|
|
|
const real costo = rdoc.get_real(RDOC_PREZZO);
|
|
|
|
|
row.add(costo.string(), sh.cid2index(F_COSTO));
|
|
|
|
|
TArticolo & art = cached_article(codart);
|
|
|
|
|
const TString4 ric = doc().clifor().vendite().get(CFV_CATVEN);
|
|
|
|
|
row.add(ric, sh.cid2index(F_RICARICO));
|
|
|
|
|
const real perc = cache().get("CVE", ric, "R2");
|
|
|
|
|
real prezzo = costo * ( UNO + (perc / CENTO));
|
|
|
|
|
|
|
|
|
|
TCodiceIVA c(art.get(ANAMAG_CODIVA));
|
|
|
|
|
|
|
|
|
|
prezzo = c.lordo(prezzo, 20);
|
2011-06-08 10:02:31 +00:00
|
|
|
|
prezzo.round(0);
|
2011-06-05 17:03:25 +00:00
|
|
|
|
row.add(prezzo.string(), sh.cid2index(F_PREZZOL));
|
2011-06-08 10:02:31 +00:00
|
|
|
|
|
|
|
|
|
c.scorpora(prezzo, 20);
|
|
|
|
|
prezzo.round(TCurrency::get_firm_dec(true));
|
|
|
|
|
row.add(prezzo.string(), sh.cid2index(F_PREZZO));
|
2011-06-05 17:03:25 +00:00
|
|
|
|
row.add(art.get(ANAMAG_DESCR), sh.cid2index(F_DESART));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m.run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
const int shrows = sh.items();
|
|
|
|
|
TLocalisamfile f(LF_UMART);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < shrows; i++)
|
|
|
|
|
{
|
|
|
|
|
TToken_string & row = sh.row(i);
|
|
|
|
|
TArticolo & art = cached_article(row.get(sh.cid2index(F_CODART)));
|
|
|
|
|
real prezzo(row.get(sh.cid2index(F_PREZZO)));
|
|
|
|
|
|
|
|
|
|
art.convert_to_um(prezzo, EMPTY_STRING, row.get(sh.cid2index(F_UM)));
|
|
|
|
|
prezzo.round(TCurrency::get_firm_dec(true));
|
|
|
|
|
art.set_prezzo_vendita(prezzo);
|
|
|
|
|
art.um().row(1).rewrite(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDocumento & d = (TDocumento &)doc();
|
|
|
|
|
TElaborazione_esterna e(d.tipo().elaborazione());
|
|
|
|
|
|
|
|
|
|
d.stato(e.stato_finale_doc_iniziale()[0]);
|
|
|
|
|
d.rewrite();
|
|
|
|
|
const TFixed_string arg = argv(2);
|
|
|
|
|
TConfig c(arg.mid(2), "Transaction");
|
|
|
|
|
|
|
|
|
|
c.set("Result", "OUDOC");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TAggiorna_prezzi::set_params(TMask & m)
|
|
|
|
|
{
|
|
|
|
|
const TFixed_string arg = argv(2);
|
|
|
|
|
if ((arg[0] != '-' && arg[0] != '/') || (arg[1] != 'i' && arg[1] != 'I'))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TString ini_name = arg.mid(2);
|
|
|
|
|
|
|
|
|
|
//controlla che il file su cui deve scrivere ci sia; se non c'<27> d<> una segnalazione di errore
|
|
|
|
|
if (!fexist(ini_name))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TString4 para; para.format("%d", LF_DOC);
|
|
|
|
|
TConfig ini(ini_name, para);
|
|
|
|
|
|
|
|
|
|
const char provv = ini.get(DOC_PROVV)[0];
|
|
|
|
|
const int anno = ini.get_int(DOC_ANNO);
|
|
|
|
|
const TString4 codnum = ini.get(DOC_CODNUM);
|
|
|
|
|
const long ndoc = ini.get_long(DOC_NDOC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_doc = new TDocumento(provv, anno, codnum,ndoc);
|
|
|
|
|
|
|
|
|
|
m.set(F_PROVV, provv);
|
|
|
|
|
m.set(F_ANNO, anno);
|
|
|
|
|
m.set(F_CODNUM, codnum, 0x3);
|
|
|
|
|
m.set(F_NDOC, ndoc, 0x3);
|
|
|
|
|
|
|
|
|
|
return _doc != NULL && _doc->physical_rows() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TAggiorna_prezzi::main_loop() //definizione della member function main_loop, della classe TAggiorna_prezzi
|
|
|
|
|
{
|
|
|
|
|
open_files(LF_DOC, LF_RIGHEDOC, LF_UMART, 0);
|
|
|
|
|
if (argc() > 2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
TAggiorna_mask m;
|
|
|
|
|
|
|
|
|
|
if (set_params(m))
|
|
|
|
|
aggiorna(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////// Esecuzione del programma ///////////
|
|
|
|
|
|
|
|
|
|
int pg0002100(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TAggiorna_prezzi app;
|
|
|
|
|
app.run(argc,argv,"Generazione etichette");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|