Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 01.05 patch 282 git-svn-id: svn://10.65.10.50/trunk@8058 c028cbd2-c16b-5b4b-a496-9718f37d4682
1407 lines
39 KiB
C++
Executable File
1407 lines
39 KiB
C++
Executable File
// oggetto TArticolo, multirecord dell'articolo di anagrafica magazzino
|
||
// oggetto TArticolo_giacenza, multirecord dell'articolo di magazzino
|
||
// oggetto TMov_Mag , multirecord del movimento di magazzino
|
||
// funzione di ricostruzione saldi
|
||
//#include <utility.h>
|
||
#include <tabutil.h>
|
||
#include <currency.h>
|
||
|
||
#include "mglib.h"
|
||
|
||
#include "anamag.h"
|
||
#include "mag.h"
|
||
|
||
#include "..\cg\cglib01.h"
|
||
#include "..\ve\veconf.h"
|
||
|
||
// libreria per i movimenti
|
||
class TTimed_skipbox: public TTimed_breakbox
|
||
{
|
||
public:
|
||
TTimed_skipbox(const char * message,int seconds,int x=40,int y=10);
|
||
~TTimed_skipbox();
|
||
};
|
||
|
||
TTimed_skipbox:: TTimed_skipbox(const char * message,int seconds,int x,int y)
|
||
: TTimed_breakbox(message,seconds,x,y)
|
||
{
|
||
hide(DLG_CANCEL);
|
||
add_button(DLG_CANCEL, 0, "Ignora", -22, -1, 12, 2,"",0);
|
||
}
|
||
|
||
TTimed_skipbox::~TTimed_skipbox()
|
||
{}
|
||
|
||
char * Nome_valorizz[]=
|
||
{
|
||
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
||
"Costo standard", "Costo medio acquisto" ,
|
||
"Costo medio ponderato" ,
|
||
"FIFO annuale", "LIFO annuale",
|
||
"FIFO", "LIFO",
|
||
"FIFO Ragionieristico", "LIFO Ragionieristico"
|
||
} ;
|
||
|
||
HIDDEN TString16 _mg_null_str;
|
||
|
||
const TString & TArticolo::get_str(const char* fieldname) const
|
||
{
|
||
if (*fieldname != '#')
|
||
return TRectype::get_str(fieldname);
|
||
char * fname = (char *) fieldname + 1;
|
||
const int logicnum = atoi(fname);
|
||
const char * op1 = strchr(fname, '_');
|
||
int index = 0;
|
||
if (op1)
|
||
{
|
||
op1=op1+1;
|
||
if (*op1 == '#')
|
||
index = atoi(fname + 1);
|
||
}
|
||
const char* op2 = strstr(fname, "->");
|
||
CHECKS(op2, "Can't find '->' in string ", fieldname);
|
||
op2=op2+2;
|
||
|
||
switch (logicnum)
|
||
{
|
||
case LF_UMART:
|
||
{
|
||
if (index == 0)
|
||
index = find_um(op1);
|
||
if (index > 0 && op2)
|
||
return um().row(index).get(op2);
|
||
}
|
||
break;
|
||
case LF_CODCORR:
|
||
{
|
||
if (index == 0)
|
||
index = find_codcorr(op1);
|
||
if (index > 0 && op2)
|
||
return codcorr().row(index).get(op2);
|
||
}
|
||
break;
|
||
case LF_DESLIN:
|
||
{
|
||
if (index == 0)
|
||
index = find_deslin(op1);
|
||
if (index > 0 && op2)
|
||
return deslin().row(index).get(op2);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return EMPTY_STRING;
|
||
}
|
||
|
||
void TArticolo::set_body_key(TRectype & rowrec)
|
||
{
|
||
const int logicnum = rowrec.num();
|
||
const TString& cod = codice();
|
||
|
||
switch (logicnum)
|
||
{
|
||
case LF_UMART:
|
||
rowrec.put(UMART_CODART, cod);
|
||
break;
|
||
case LF_DESLIN:
|
||
rowrec.put(DESLIN_CODART, cod);
|
||
break;
|
||
case LF_CODCORR:
|
||
rowrec.put(CODCORR_CODART, cod);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
int TArticolo::read(TRectype & rec, word op, word lockop)
|
||
{
|
||
const TString80 compstr(rec.get(ANAMAG_CODART));
|
||
if (op == _isequal && lockop == _nolock && codice() == compstr)
|
||
return NOERR;
|
||
|
||
put(ANAMAG_CODART, compstr);
|
||
const int err = TMultiple_rectype::read(rec, op , lockop);
|
||
|
||
if (err != NOERR)
|
||
zero();
|
||
return err;
|
||
}
|
||
|
||
int TArticolo::read(const char * cod, word op, word lockop)
|
||
{
|
||
TRectype tmp(*this);
|
||
tmp.put(ANAMAG_CODART,cod);
|
||
return read( tmp, op, lockop);
|
||
}
|
||
|
||
const TString& TArticolo::codice() const
|
||
{
|
||
((TArticolo *)this)->_codice=get(ANAMAG_CODART);
|
||
return _codice;
|
||
}
|
||
|
||
const TString & TArticolo::descrizione(const char* lingua) const
|
||
{
|
||
if (lingua && *lingua)
|
||
{
|
||
TString16 f; f.format("#%d_%s->%s", LF_DESLIN, lingua, DESLIN_DESCR);
|
||
|
||
return get(f);
|
||
}
|
||
else
|
||
return get(ANAMAG_DESCR);
|
||
}
|
||
|
||
|
||
void TArticolo::update_ultcosti(const real& costo, const TDate& data, long numreg, int _unused_)
|
||
{
|
||
const TDate data1(get_date(ANAMAG_DULTCOS1));
|
||
const TDate data2(get_date(ANAMAG_DULTCOS2));
|
||
// modificato il 2-2-99;
|
||
const long numreg1 = get_long(ANAMAG_NUMREG1);
|
||
const long numreg2 = get_long(ANAMAG_NUMREG2);
|
||
if (data >= data1 || (numreg == numreg1 && // // movimento piu' recente o aggiornamento dello stesso movimento ...
|
||
(data > data2 || (numreg > numreg2 )))) // ... e "data" superiore al penultimo
|
||
{
|
||
real costo1(get_real(ANAMAG_ULTCOS1));
|
||
put(ANAMAG_ULTCOS1,costo);
|
||
put(ANAMAG_DULTCOS1,data);
|
||
put(ANAMAG_NUMREG1,numreg);
|
||
if (numreg != numreg1 && (data > data1 || numreg > numreg1))
|
||
{
|
||
// trasforma l'ultimo costo in penultimo
|
||
put(ANAMAG_ULTCOS2,costo1);
|
||
put(ANAMAG_DULTCOS2,data1);
|
||
put(ANAMAG_NUMREG2,numreg1);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
real costo2(get_real(ANAMAG_ULTCOS2));
|
||
if (data>= data2 || numreg == numreg2 || numreg == numreg1 )
|
||
{
|
||
put(ANAMAG_DULTCOS2,data);
|
||
put(ANAMAG_ULTCOS2,costo);
|
||
put(ANAMAG_NUMREG2,numreg);
|
||
}
|
||
if (numreg == numreg1 )
|
||
{
|
||
// trasforma il penultimo costo in ultimo
|
||
put(ANAMAG_ULTCOS1,costo2);
|
||
put(ANAMAG_DULTCOS1,data2);
|
||
put(ANAMAG_NUMREG1,numreg2);
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TArticolo::unlock()
|
||
{
|
||
bool rv;
|
||
if (codice().not_empty())
|
||
{
|
||
static TLocalisamfile *anag=NULL; if (anag==NULL) anag= new TLocalisamfile(LF_ANAMAG);
|
||
rv=(anag->read(*this, _isequal,_unlock)==NOERR);
|
||
return rv;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
bool TArticolo::lock_and_prompt(const char * cod)
|
||
{
|
||
TString mess;
|
||
int err;
|
||
//const TString cod(codice());
|
||
|
||
static TLocalisamfile *anag=NULL; if (anag==NULL) anag= new TLocalisamfile(LF_ANAMAG);
|
||
do
|
||
{
|
||
put(ANAMAG_CODART, cod);
|
||
err=anag->read(*this,_isequal,_testandlock);
|
||
switch (err)
|
||
{
|
||
case NOERR:
|
||
return TRUE;
|
||
case _islocked:
|
||
{
|
||
mess.cut(0);
|
||
mess << "Il record di anagrafica\ndell'articolo ''"<< cod << "'' e' gia' usato da un altro programma. Scegliere se ritentare la lettura o ignorare l'articolo.";
|
||
break;
|
||
}
|
||
case _iskeynotfound:
|
||
mess.cut(0);
|
||
mess << "Il record di anagrafica\ndell'articolo ''"<< cod << "'' non esiste.";
|
||
error_box(mess);
|
||
return FALSE;
|
||
break;
|
||
default:
|
||
mess.cut(0);
|
||
mess << "Non riesco ad accedere al\nrecord di anagrafica dell'articolo ''"<< cod << "'' - errore " << err << ".";
|
||
}
|
||
TTimed_skipbox bbox((const char *)mess,10);
|
||
if (bbox.run()==K_ESC)
|
||
return FALSE;
|
||
} while (TRUE);
|
||
return FALSE;
|
||
}
|
||
|
||
real TArticolo::convert_to_um(const real& v, const char * to_um, const char * from_um)
|
||
{
|
||
// Se from_um non specificato significa che la qta che si desidera convertire e' in UM base
|
||
int i1, i2 = 0;
|
||
i1 = find_um(to_um);
|
||
|
||
if (from_um != NULL)
|
||
i2 = find_um(from_um);
|
||
|
||
TRecord_array& u = um();
|
||
real fc1 = i1 ? ((TRectype&)u[i1]).get_real("FC") : 1.00; // Fattore di conversione
|
||
real fc2 = i2 ? ((TRectype&)u[i2]).get_real("FC") : 1.00;
|
||
real r = (v * fc2) / fc1;
|
||
// TBI: ricerca sulla tabella UMS nel caso di um non presenti in LF_UMART
|
||
|
||
return r;
|
||
}
|
||
|
||
TArticolo::TArticolo(const char* codice)
|
||
: TMultiple_rectype(LF_ANAMAG)
|
||
|
||
{
|
||
add_file(LF_UMART,"NRIGA");
|
||
add_file(LF_CODCORR,"NRIGA");
|
||
add_file(LF_DESLIN,"NRIGA");
|
||
if (codice && *codice)
|
||
{
|
||
int err=read(codice);
|
||
if (err!=NOERR)
|
||
error_box("Impossibile leggere l'articolo %s: Errore %d",codice, err);
|
||
}
|
||
}
|
||
|
||
TArticolo::TArticolo(const TRectype& rec)
|
||
: TMultiple_rectype(rec)
|
||
{
|
||
add_file(LF_UMART,"NRIGA");
|
||
add_file(LF_CODCORR,"NRIGA");
|
||
add_file(LF_DESLIN,"NRIGA");
|
||
read(rec.get(ANAMAG_CODART));
|
||
}
|
||
|
||
TArticolo::~TArticolo()
|
||
{
|
||
}
|
||
|
||
// *****************
|
||
//
|
||
|
||
|
||
|
||
const TString & TArticolo_giacenza::get_str(const char* fieldname) const
|
||
{
|
||
if (*fieldname != '#')
|
||
return TRectype::get_str(fieldname);
|
||
char * fname = (char *) fieldname + 1;
|
||
const int logicnum = atoi(fname);
|
||
if (logicnum !=LF_MAG && logicnum !=LF_STOMAG)
|
||
return TArticolo::get_str(fieldname);
|
||
|
||
const char * op1 = strchr(fname, '_');
|
||
int index = 0;
|
||
if (op1)
|
||
{
|
||
op1=op1+1;
|
||
fname = (char *) op1;
|
||
if (*op1 == '#')
|
||
index = atoi(fname + 1);
|
||
}
|
||
const char * op2 = strchr(fname, '_');
|
||
if (op2)
|
||
{
|
||
op2=op2+1;
|
||
fname = (char *) op2 + 1;
|
||
}
|
||
const char * op3 = strchr(fname, '_');
|
||
if (op3)
|
||
op3=op3+1;
|
||
const char * op4 = strstr(fname, "->");
|
||
CHECKS(op4, "Can't find '->' in string ", fieldname);
|
||
op4=op4+2;
|
||
|
||
switch (logicnum)
|
||
{
|
||
case LF_MAG:
|
||
if (index == 0)
|
||
index = find_mag(op1, op2, op3);
|
||
if (index > 0 && op3)
|
||
return mag(op1).row(index).get(op4);
|
||
break;
|
||
case LF_STOMAG:
|
||
if (index = 0)
|
||
index = find_storico(op1, op2);
|
||
if (index > 0)
|
||
return storico(op1).row(index).get(op4);
|
||
break;
|
||
}
|
||
return EMPTY_STRING;
|
||
}
|
||
|
||
void TArticolo_giacenza::set_body_key(TRectype & rowrec)
|
||
{
|
||
const int logicnum = rowrec.num();
|
||
const char * cod = (const char *) codice();
|
||
|
||
switch (logicnum)
|
||
{
|
||
case LF_STOMAG:
|
||
rowrec.put(STOMAG_CODART, cod);
|
||
rowrec.put(STOMAG_ANNOESRIF, _anno_sto);
|
||
break;
|
||
case LF_MAG:
|
||
rowrec.put(MAG_ANNOES, _anno_mag);
|
||
rowrec.put(MAG_CODART, cod);
|
||
break;
|
||
default:
|
||
TArticolo::set_body_key(rowrec);
|
||
break;
|
||
}
|
||
}
|
||
|
||
void TArticolo_giacenza::set_anno_mag (const char * anno)
|
||
{
|
||
if (_anno_mag != anno)
|
||
remove_body(LF_MAG);
|
||
_anno_mag = anno;
|
||
}
|
||
|
||
void TArticolo_giacenza::set_anno_sto (const char * anno)
|
||
{
|
||
if (_anno_sto != anno)
|
||
remove_body(LF_STOMAG);
|
||
_anno_sto = anno;
|
||
}
|
||
|
||
void TArticolo_giacenza::zero(char c)
|
||
{
|
||
reset_anno_sto();
|
||
reset_anno_mag();
|
||
TArticolo::zero(c);
|
||
}
|
||
|
||
int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const char * livello, int from) const
|
||
{
|
||
TRecord_array & rmag = mag(annoes);
|
||
const int last = rmag.last_row();
|
||
|
||
if (last > 0 && from < last)
|
||
{
|
||
const int codmag_len = codmag ? strlen(codmag) : 0;
|
||
const int livello_len = livello ? strlen(livello) : 0;
|
||
|
||
if (codmag_len == 0 && livello_len == 0)
|
||
return from + 1;
|
||
|
||
for (int i = rmag.succ_row(from); i <= last; i = rmag.succ_row(i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
if (codmag_len == 0 || rec.get(MAG_CODMAG).compare(codmag, codmag_len) == 0)
|
||
if (livello_len == 0 || rec.get(MAG_LIVELLO).compare(livello, livello_len) == 0)
|
||
return i;
|
||
}
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
int TArticolo_giacenza::find_storico(const char * annoesrif, const char * annoes, const char * codmag, int from) const
|
||
{
|
||
TRecord_array & rsto = storico(annoesrif);
|
||
const int last = rsto.last_row();
|
||
|
||
if (last > 0 && from <= last)
|
||
{
|
||
const int codmag_len = codmag ? strlen(codmag) : 0;
|
||
|
||
if (codmag_len == 0)
|
||
return from + 1;
|
||
|
||
for (int i = rsto.succ_row(from); i <= last; i = rsto.succ_row(i))
|
||
{
|
||
const TRectype & rec = rsto.row(i);
|
||
|
||
if (rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
|
||
return i;
|
||
}
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
TRecord_array & TArticolo_giacenza::mag(const char * annoes) const
|
||
{
|
||
TString16 anno = annoes;
|
||
if (anno.blank())
|
||
{
|
||
TEsercizi_contabili ese;
|
||
anno.format("%04d", ese.last_mag());
|
||
}
|
||
((TArticolo_giacenza*)this)->set_anno_mag(anno);
|
||
return body(LF_MAG);
|
||
}
|
||
|
||
TRecord_array & TArticolo_giacenza::storico(const char * annoesrif) const
|
||
{
|
||
TString16 anno = annoesrif;
|
||
if (anno.blank())
|
||
{
|
||
TEsercizi_contabili ese;
|
||
anno.format("%04d", ese.last_mag());
|
||
}
|
||
((TArticolo_giacenza *) this)->set_anno_sto(anno);
|
||
return body(LF_STOMAG);
|
||
}
|
||
|
||
bool TArticolo_giacenza::is_last_esercizio(const char* annoes) const
|
||
{
|
||
bool yes = TRUE;
|
||
if (annoes && *annoes)
|
||
{
|
||
const int anno = atoi(annoes);
|
||
if (anno > 0)
|
||
{
|
||
TEsercizi_contabili e;
|
||
yes = !e.esercizio(anno).chiusura_mag().ok() ;
|
||
}
|
||
}
|
||
return yes;
|
||
}
|
||
|
||
bool TArticolo_giacenza::azzera_saldi(const char * cod_es)
|
||
{
|
||
TRecord_array& rec_arr = TArticolo_giacenza::mag(cod_es);
|
||
|
||
const int last = rec_arr.last_row();
|
||
for (int r = last;r > 0 ; r = rec_arr.pred_row(r)) // Scorre le righe
|
||
{
|
||
TRectype& mag = rec_arr[r];
|
||
|
||
mag.put(MAG_GIAC,0);
|
||
mag.put(MAG_RIM,0);mag.put(MAG_VALRIM,0);
|
||
mag.put(MAG_ACQ,0);mag.put(MAG_VALACQ,0);
|
||
mag.put(MAG_ENT,0);mag.put(MAG_VALENT,0);
|
||
mag.put(MAG_VEN,0);mag.put(MAG_VALVEN,0);
|
||
mag.put(MAG_USC,0);mag.put(MAG_VALUSC,0);
|
||
mag.put(MAG_ORDF,0);mag.put(MAG_VALORDF,0);
|
||
mag.put(MAG_ORDC,0);mag.put(MAG_VALORDC,0);
|
||
mag.put(MAG_SCARTI,0);mag.put(MAG_VALSCARTI,0);
|
||
mag.put(MAG_PRODCOMP,0);
|
||
mag.put(MAG_PRODFIN,0);
|
||
mag.put(MAG_INCL,0);
|
||
mag.put(MAG_ACL,0);
|
||
mag.put(MAG_NLABEL,0);
|
||
}
|
||
return rec_arr.write(TRUE) == NOERR;
|
||
}
|
||
|
||
bool TArticolo_giacenza::riporta_saldi(const char * oldes, const char* newes, const TTipo_valorizz tipo, const char* catven, const char* codlis)
|
||
{
|
||
TString codes(newes), mag, liv;
|
||
TRecord_array& rec_arr = TArticolo_giacenza::mag(oldes);
|
||
const int last = rec_arr.last_row();
|
||
real rim, val, giac, inpf, proc, icl, acl;
|
||
TCurrency currency(ZERO, "_FIRM");
|
||
|
||
rec_arr.renum_key(MAG_ANNOES, codes); // Rinumera
|
||
for (int r = last;r > 0 ; r = rec_arr.pred_row(r)) // Scorre le righe
|
||
{
|
||
TRectype& rec = rec_arr[r];
|
||
mag = rec.get(MAG_CODMAG); mag.cut(3);
|
||
liv = rec.get(MAG_LIVELLO);
|
||
giac = rec.get_real(MAG_GIAC);
|
||
inpf = rec.get_real(MAG_PRODFIN);
|
||
proc = rec.get_real(MAG_PRODCOMP);
|
||
acl = rec.get_real(MAG_ACL);
|
||
icl = rec.get_real(MAG_INCL);
|
||
rim = giac + inpf - proc + acl - icl;
|
||
switch (tipo)
|
||
{
|
||
case valorizz_costmedio:
|
||
val = costo_medio(oldes, mag, liv);
|
||
break;
|
||
case valorizz_costmediopond:
|
||
val = costo_mediopond(oldes, mag, liv);
|
||
break;
|
||
case valorizz_ultcos:
|
||
val = ultimo_costo(oldes);
|
||
break;
|
||
case valorizz_mediacos:
|
||
val = media_costi(oldes);
|
||
break;
|
||
case valorizz_przlist:
|
||
val = prezzo_listino(oldes, catven, codlis);
|
||
break;
|
||
case valorizz_coststd:
|
||
val = costo_standard(oldes);
|
||
break;
|
||
case valorizz_FIFOa:
|
||
val = FIFO_annuale(oldes, mag, liv);
|
||
break;
|
||
case valorizz_LIFOa:
|
||
val = LIFO_annuale(oldes, mag, liv);
|
||
break;
|
||
case valorizz_FIFO:
|
||
val = FIFO(oldes, mag, liv);
|
||
break;
|
||
case valorizz_LIFO:
|
||
val = LIFO(oldes, mag, liv);
|
||
break;
|
||
case valorizz_FIFOr:
|
||
val = FIFO_ragionieristico(oldes, mag, liv);
|
||
break;
|
||
case valorizz_LIFOr:
|
||
val = LIFO_ragionieristico(oldes, mag, liv);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
// Setta il prezzo al nr di decimali fissati per i prezzi della valuta corrente
|
||
if (tipo < valorizz_FIFOa)
|
||
{
|
||
currency.set_price(TRUE);
|
||
currency.set_num(val);
|
||
val = currency.string();
|
||
}
|
||
val *= rim;
|
||
|
||
// Setta l'importo al nr di decimali fissati per gli importi della valuta corrente
|
||
currency.set_price(FALSE);
|
||
currency.set_num(val);
|
||
val = currency.string();
|
||
rec.put(MAG_RIM, rim); rec.put(MAG_VALRIM, val);
|
||
rec.zero(MAG_ACQ); rec.zero(MAG_VALACQ);
|
||
rec.zero(MAG_ENT); rec.zero(MAG_VALENT);
|
||
rec.zero(MAG_VEN); rec.zero(MAG_VALVEN);
|
||
rec.zero(MAG_USC); rec.zero(MAG_VALUSC);
|
||
rec.zero(MAG_SCARTI);
|
||
}
|
||
|
||
// Scrive il pastrocchio (eventualmente sovrascrive)
|
||
return rec_arr.write(TRUE) == NOERR;
|
||
}
|
||
|
||
real TArticolo_giacenza::disponibilita(const char * annoes, const char * codmag, const char * livello, bool solo_giac) const
|
||
{
|
||
real giac;
|
||
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0;
|
||
i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
giac += rec.get_real(MAG_GIAC);
|
||
if (!solo_giac)
|
||
{
|
||
giac += rec.get_real(MAG_ORDF) - rec.get_real(MAG_ORDC);
|
||
giac += rec.get_real(MAG_PRODFIN) - rec.get_real(MAG_PRODCOMP);
|
||
}
|
||
}
|
||
return giac;
|
||
}
|
||
|
||
|
||
|
||
real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
||
{
|
||
if (is_last_esercizio(annoes))
|
||
{
|
||
const real costo = get_real(ANAMAG_ULTCOS1);
|
||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||
}
|
||
else
|
||
{
|
||
const int index = find_storico(annoes, annoes);
|
||
if (index < 0 ) return ZERO;
|
||
const real costo = storico(annoes).row(index).get_real(STOMAG_ULTCOS1);
|
||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||
}
|
||
}
|
||
|
||
real TArticolo_giacenza::media_costi(const char * annoes) const
|
||
{
|
||
if (is_last_esercizio(annoes))
|
||
{
|
||
real costo = get_real(ANAMAG_ULTCOS1);
|
||
costo = (costo + get_real(ANAMAG_ULTCOS2)) / 2.0;
|
||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||
}
|
||
else
|
||
{
|
||
const int index = find_storico(annoes, annoes);
|
||
if (index < 0 ) return ZERO;
|
||
const TRectype & rec = storico(annoes).row(index);
|
||
real costo = rec.get_real(STOMAG_ULTCOS1);
|
||
|
||
costo = (costo + rec.get_real(STOMAG_ULTCOS2)) / 2.0;
|
||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||
}
|
||
}
|
||
|
||
real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven, const char * codlist) const
|
||
{
|
||
if (is_last_esercizio(annoes))
|
||
{
|
||
TString codart=codice();
|
||
TConfig cfg(CONFIG_DITTA);
|
||
TCondizione_vendita cv(&cfg);
|
||
cv.put_listino(codlist,catven);
|
||
if (cv.ricerca(codart))
|
||
return cv.get_prezzo();
|
||
else
|
||
{
|
||
// se non lo trova, cerca nel prezzo indicato nelle UM
|
||
TString16 f;
|
||
f.format("#%d->%s", LF_UMART, UMART_PREZZO);
|
||
return get_real(f);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const int index = find_storico(annoes, annoes);
|
||
if (index < 0 ) return ZERO;
|
||
return storico(annoes).row(index).get_real(STOMAG_PRZLIST);
|
||
}
|
||
}
|
||
|
||
real TArticolo_giacenza::costo_standard(const char * annoes) const
|
||
{
|
||
if (is_last_esercizio(annoes))
|
||
return get_real(ANAMAG_COSTSTD);
|
||
else
|
||
{
|
||
const int index = find_storico(annoes, annoes);
|
||
if (index < 0 ) return ZERO;
|
||
return storico(annoes).row(index).get_real(STOMAG_COSTSTD);
|
||
}
|
||
}
|
||
|
||
|
||
real TArticolo_giacenza::costo_medio(const char * annoes, const char * codmag, const char * livello) const
|
||
{
|
||
real acq;
|
||
real valacq;
|
||
|
||
#ifdef DBG
|
||
if (strlen(codmag)>3)
|
||
NFCHECK("Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
#endif
|
||
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0;
|
||
i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
}
|
||
return acq == ZERO ? costo_standard(annoes) : valacq / acq;
|
||
}
|
||
|
||
// costo medio ponderato per periodi pari alla durata dell'esercizio
|
||
real TArticolo_giacenza::costo_mediopond(const char * annoes, const char * codmag, const char * livello) const
|
||
{
|
||
real acq;
|
||
real valacq;
|
||
|
||
#ifdef DBG
|
||
if (strlen(codmag)>3)
|
||
NFCHECK("Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
#endif
|
||
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
acq += rec.get_real(MAG_ACQ) ;
|
||
acq += rec.get_real(MAG_RIM) ;
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
valacq += rec.get_real(MAG_VALRIM);
|
||
}
|
||
return acq == ZERO ? costo_standard(annoes) : valacq / acq;
|
||
}
|
||
|
||
real TArticolo_giacenza::LIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
real rim,valrim;
|
||
real acq,valacq;
|
||
real giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
rim += rec.get_real(MAG_RIM);
|
||
valrim += rec.get_real(MAG_VALRIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
if (giacenza <= ZERO)
|
||
return ZERO;
|
||
if (giacenza > rim)
|
||
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
||
return valrim / rim;
|
||
}
|
||
|
||
|
||
real TArticolo_giacenza::FIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
real rim,valrim;
|
||
real acq,valacq;
|
||
real giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
rim += rec.get_real(MAG_RIM);
|
||
valrim += rec.get_real(MAG_VALRIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
if (giacenza <= ZERO)
|
||
return ZERO;
|
||
if (giacenza > acq)
|
||
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
||
return valacq / acq;
|
||
}
|
||
|
||
|
||
real TArticolo_giacenza::LIFO(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
real rim,valrim;
|
||
real acq,valacq;
|
||
real giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
rim += rec.get_real(MAG_RIM);
|
||
valrim += rec.get_real(MAG_VALRIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
|
||
if (giacenza <= ZERO)
|
||
return ZERO;
|
||
if (giacenza > rim)
|
||
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
||
|
||
TRecord_array & rstorico = storico(annoes);
|
||
// const int last = rstorico.last_row();
|
||
|
||
valrim=ZERO;
|
||
rim = giacenza;
|
||
for (i = find_storico(annoes, "", codmag); i > 0; i = find_storico(annoes, "", codmag, i))
|
||
{
|
||
TRectype & rec = rstorico[i];
|
||
const real qta = rec.get(STOMAG_QUANT);
|
||
|
||
if (qta > giacenza)
|
||
{
|
||
valrim += (rec.get_real(STOMAG_VALORE)) * giacenza;
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
valrim += rec.get_real(STOMAG_VALORE) * qta;
|
||
giacenza -= qta;
|
||
}
|
||
}
|
||
return valrim / rim;
|
||
}
|
||
|
||
real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
real rim,valrim;
|
||
real acq,valacq;
|
||
real giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
|
||
rim += rec.get_real(MAG_RIM);
|
||
valrim += rec.get_real(MAG_VALRIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
|
||
if (giacenza <= ZERO)
|
||
return ZERO;
|
||
if (giacenza <= acq)
|
||
{
|
||
return valacq / acq;
|
||
}
|
||
|
||
TRecord_array & rstorico = storico(annoes);
|
||
const int last = rstorico.last_row();
|
||
real res = giacenza - acq;
|
||
rim = ZERO;
|
||
valrim = ZERO;
|
||
TFixed_string cmag(codmag);
|
||
int codmag_len = codmag ? strlen(cmag) : 0;
|
||
for (i = last; i > 0; i--)
|
||
{
|
||
const TRectype & rec = rstorico.row(i);
|
||
if (codmag_len == 0 || rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
|
||
{
|
||
const real qta = rec.get(STOMAG_QUANT);
|
||
|
||
if (qta > res)
|
||
{
|
||
rim += res;
|
||
valrim += (rec.get_real(STOMAG_VALORE)) * res;
|
||
}
|
||
else
|
||
{
|
||
rim += qta;
|
||
valrim += rec.get_real(STOMAG_VALORE) * qta;
|
||
res -= qta;
|
||
}
|
||
}
|
||
}
|
||
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
||
}
|
||
|
||
real TArticolo_giacenza::FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
return ZERO; // da implementare
|
||
}
|
||
|
||
real TArticolo_giacenza::LIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
||
bool giac_eff, bool valorizza_componenti) const
|
||
{
|
||
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
return ZERO; // da implementare
|
||
}
|
||
|
||
void TArticolo_giacenza::copia_storico(TString & nuovoanno,const char * annoes,const char * codmag)
|
||
{
|
||
CHECK(codmag && *codmag,"Copia_storico: Indicare l'anno esercizio dello storico");
|
||
TEsercizi_contabili ese;
|
||
nuovoanno=ese.next(atoi(annoes));
|
||
TRecord_array & rstorico = storico(annoes);
|
||
int last=rstorico.last_row();
|
||
int codmag_len = (codmag && *codmag) ? strlen(codmag) : 0;
|
||
for (int i = rstorico.last_row(); i > 0; i--)
|
||
if (codmag_len == 0 || rstorico[i].get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
|
||
{
|
||
TRectype newrec(rstorico[i]);
|
||
newrec.put(STOMAG_ANNOESRIF,nuovoanno);
|
||
newrec.put(STOMAG_NRIGA,++last);
|
||
rstorico.insert_row(newrec);
|
||
}
|
||
}
|
||
|
||
void TArticolo_giacenza::add_storico(const char * annorif,const char * annoes,const char * codmag, const real & qta, const real & prz)
|
||
{
|
||
CHECK(codmag && *codmag,"Add_storico: Indicare l'anno esercizio dello storico");
|
||
TEsercizi_contabili ese;
|
||
TRecord_array & rstorico = storico(annoes);
|
||
for (int i=rstorico.last_row(); i>0; i--)
|
||
{
|
||
TString anno=rstorico[i].get(STOMAG_ANNOESRIF);
|
||
if (anno<=annorif)
|
||
{
|
||
TString mag=rstorico[i].get(STOMAG_CODMAG);
|
||
if (mag<=codmag)
|
||
break;
|
||
}
|
||
}
|
||
TRectype storec(LF_STOMAG);
|
||
storec.put(STOMAG_ANNOESRIF,annorif);
|
||
storec.put(STOMAG_CODART,codice());
|
||
storec.put(STOMAG_NRIGA,i+1);
|
||
storec.put(STOMAG_CODMAG,codmag);
|
||
storec.put(STOMAG_QUANT,qta);
|
||
storec.put(STOMAG_VALORE,prz);
|
||
rstorico.insert_row(storec);
|
||
}
|
||
// annoes indica l'anno dell'esercizio da chiudere
|
||
void TArticolo_giacenza::agg_storicoLIFO(const char * annoes, const char * codmag,
|
||
bool giac_eff, bool valorizza_componenti)
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
CHECK(codmag && *codmag,"Necessario indicare il magazzino");
|
||
|
||
real rim,acq,valacq,giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, ""); i > 0; i = find_mag(annoes, codmag, "", i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
rim += rec.get_real(MAG_RIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
TCurrency qta(ZERO,"_FIRM"),prz(ZERO,"_FIRM",TRUE);
|
||
|
||
TString nuovoanno;
|
||
copia_storico(nuovoanno, annoes, nuovoanno);
|
||
|
||
if (giacenza <= ZERO)
|
||
giacenza=ZERO;
|
||
if (giacenza > rim)
|
||
{
|
||
qta.set_num(giacenza-rim);
|
||
prz.set_num(valacq/acq);
|
||
add_storico(nuovoanno,annoes,codmag,qta.get_num(),prz.get_num());
|
||
return;
|
||
}
|
||
real res = rim-giacenza;
|
||
TRecord_array & rstorico = storico(nuovoanno);
|
||
for (i = find_storico(nuovoanno, "", codmag); i > 0; i = find_storico(nuovoanno, "", codmag, i))
|
||
{
|
||
TRectype & rec = rstorico[i];
|
||
const real qta_sto=rec.get_real(STOMAG_QUANT);
|
||
if (qta_sto > res)
|
||
{
|
||
qta.set_num(qta_sto-res);
|
||
rec.put(STOMAG_QUANT,qta.get_num());
|
||
break;
|
||
} else {
|
||
rstorico.destroy_row(i);
|
||
res -= qta_sto;
|
||
}
|
||
}
|
||
rstorico.pack();
|
||
}
|
||
|
||
|
||
void TArticolo_giacenza::agg_storicoFIFO(const char * annoes, const char * codmag,
|
||
bool giac_eff, bool valorizza_componenti)
|
||
{
|
||
CHECK(strlen(codmag)<=3,"Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
||
CHECK(codmag && *codmag,"Necessario indicare il magazzino");
|
||
real rim,acq,valacq,giacenza;
|
||
TRecord_array & rmag = mag(annoes);
|
||
for (int i = find_mag(annoes, codmag, ""); i > 0; i = find_mag(annoes, codmag, "", i))
|
||
{
|
||
const TRectype & rec = rmag.row(i);
|
||
rim += rec.get_real(MAG_RIM);
|
||
acq += rec.get_real(MAG_ACQ);
|
||
valacq += rec.get_real(MAG_VALACQ);
|
||
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
||
}
|
||
|
||
if (giacenza <= ZERO)
|
||
return ;
|
||
if (giacenza <= acq)
|
||
return;
|
||
TString nuovoanno;
|
||
copia_storico(nuovoanno, annoes, codmag);
|
||
|
||
TCurrency qta(ZERO,"_FIRM"),prz(ZERO,"_FIRM",TRUE);
|
||
TRecord_array & rstorico = storico(annoes);
|
||
const int last = rstorico.last_row();
|
||
real res = giacenza - acq;
|
||
for (i = find_storico(nuovoanno, "", codmag); i > 0; i = find_storico(nuovoanno, "", codmag, i))
|
||
{
|
||
TRectype & rec = rstorico[i];
|
||
const real qta_sto = rec.get(STOMAG_QUANT);
|
||
if (res > qta_sto)
|
||
{
|
||
res -= qta_sto;
|
||
} else {
|
||
if (res>ZERO)
|
||
{
|
||
qta.set_num(res);
|
||
rec.put(STOMAG_QUANT, qta.get_num());
|
||
res=ZERO;
|
||
} else {
|
||
rstorico.destroy_row(i);
|
||
}
|
||
}
|
||
}
|
||
// aggiunge la quota dell'anno in corso
|
||
qta.set_num(giacenza-rim);
|
||
prz.set_num(valacq/acq);
|
||
add_storico(nuovoanno, annoes, codmag, qta.get_num(), prz.get_num());
|
||
rstorico.pack();
|
||
}
|
||
|
||
|
||
void TArticolo_giacenza::put_ultimo_costo(const real& costo, const TDate& data)
|
||
{
|
||
TDate d = get(ANAMAG_DULTCOS1);
|
||
if (data >= d)
|
||
{
|
||
if (data > d)
|
||
{
|
||
put(ANAMAG_ULTCOS2, get(ANAMAG_ULTCOS1));
|
||
put(ANAMAG_DULTCOS2, get(ANAMAG_DULTCOS1));
|
||
}
|
||
put(ANAMAG_DULTCOS1, data);
|
||
put(ANAMAG_ULTCOS1, costo);
|
||
}
|
||
else
|
||
{
|
||
d = get(ANAMAG_DULTCOS2);
|
||
if (data >= d)
|
||
{
|
||
put(ANAMAG_ULTCOS2, costo);
|
||
put(ANAMAG_DULTCOS2, data);
|
||
}
|
||
}
|
||
}
|
||
|
||
void TArticolo_giacenza::put_costo_standard(const real& costo)
|
||
{
|
||
put(ANAMAG_COSTSTD, costo);
|
||
}
|
||
|
||
// calcola la giacenza corretta dai campi Conto Lavoro e Produzione
|
||
real TArticolo_giacenza::giacenza_corretta(const TRectype & rec ,bool giac_eff,bool valorizza_componenti) const
|
||
{
|
||
CHECK(rec.num() == LF_MAG, "Il record passato deve essere di LF_MAG");
|
||
real giacenza(rec.get_real(MAG_GIAC));
|
||
if (giac_eff)
|
||
{
|
||
giacenza += rec.get_real(MAG_INCL);
|
||
giacenza -= rec.get_real(MAG_ACL);
|
||
giacenza += valorizza_componenti ? ZERO : (rec.get_real(MAG_PRODFIN)-rec.get_real(MAG_PRODCOMP));
|
||
}
|
||
return giacenza;
|
||
}
|
||
|
||
real TArticolo_giacenza::giacenza_anno(const char* codmag,
|
||
const char* livello,
|
||
int anno) const
|
||
{
|
||
TString16 annoes;
|
||
if (anno > 0)
|
||
annoes.format("%04d", anno);
|
||
|
||
const TRecord_array& rmag = mag(annoes);
|
||
real giac;
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0;
|
||
i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype& rec = rmag.row(i);
|
||
giac += rec.get_real("GIAC");
|
||
}
|
||
return giac;
|
||
}
|
||
|
||
real TArticolo_giacenza::scorta_minima(const char* codmag,
|
||
const char* livello,
|
||
int anno) const
|
||
{
|
||
TString16 annoes;
|
||
if (anno > 0)
|
||
annoes.format("%04d", anno);
|
||
|
||
const TRecord_array& rmag = mag(annoes);
|
||
real sm;
|
||
int nmag=0;
|
||
for (int i = find_mag(annoes, codmag, livello); i > 0;
|
||
i = find_mag(annoes, codmag, livello, i))
|
||
{
|
||
const TRectype& rec = rmag.row(i);
|
||
sm += rec.get_real("SCORTAMIN");
|
||
nmag++;
|
||
}
|
||
if (nmag)
|
||
sm = sm / nmag;
|
||
return sm;
|
||
}
|
||
|
||
|
||
TArticolo_giacenza::TArticolo_giacenza(const char* codice)
|
||
: TArticolo(codice)
|
||
{
|
||
add_file(LF_MAG,"NRIGA");
|
||
add_file(LF_STOMAG,"NRIGA");
|
||
}
|
||
|
||
TArticolo_giacenza::TArticolo_giacenza(const TRectype& rec)
|
||
: TArticolo(rec)
|
||
{
|
||
add_file(LF_MAG,"NRIGA");
|
||
add_file(LF_STOMAG,"NRIGA");
|
||
}
|
||
|
||
|
||
// causali
|
||
|
||
int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) const
|
||
{
|
||
int index = -1;
|
||
switch (tiposaldo)
|
||
{
|
||
case s_giac : index = 0; break;
|
||
case s_acq : index = 2; break;
|
||
case s_ent : index = 4; break;
|
||
case s_ven : index = 6; break;
|
||
case s_usc : index = 8; break;
|
||
case s_ordc : index = 10; break;
|
||
case s_ordf : index = 12; break;
|
||
case s_incl : index = 14; break;
|
||
case s_acl : index = 16; break;
|
||
case s_prodc: index = 18; break;
|
||
case s_prodf: index = 20; break;
|
||
case s_rim : index = 22; break;
|
||
case s_scart: index = 24; break;
|
||
case s_label: index = 26; break;
|
||
case s_user1: index = 28; break;
|
||
case s_user2: index = 30; break;
|
||
case s_user3: index = 32; break;
|
||
case s_user4: index = 34; break;
|
||
case s_user5: index = 36; break;
|
||
case s_user6: index = 38; break;
|
||
default : index = -1; break;
|
||
}
|
||
|
||
int s = 0;
|
||
if (index >= 0)
|
||
{
|
||
const TString& s2 = get("S2");
|
||
s = atoi(s2.mid(index, 2));
|
||
}
|
||
return s;
|
||
}
|
||
|
||
TDecoder TCausale_magazzino::_ragg_fisc("%RFC", "S6");
|
||
|
||
bool TCausale_magazzino::is_fiscale()
|
||
{
|
||
bool rt = FALSE;
|
||
|
||
if (raggfisc().not_empty()) // Per essere fiscale deve avere il raggruppamento fiscale
|
||
{
|
||
const char tm = tipomov();
|
||
rt = tm=='S' || tm=='C'; // La causale deve essere Carico o Scarico...
|
||
if (rt)
|
||
{
|
||
const char rfc = _ragg_fisc.decode(raggfisc())[0];
|
||
rt = rfc == 'S' || rfc == 'C'; // Ed il raggruppamento deve essere Carico o Scarico
|
||
}
|
||
}
|
||
return rt;
|
||
}
|
||
|
||
|
||
TCausale_magazzino::TCausale_magazzino(const char * codice):
|
||
TRectype(LF_TABCOM)
|
||
{
|
||
/*
|
||
TTable f("%CAU");
|
||
settab("CAU");
|
||
put("CODTAB", codice);
|
||
if (TRectype::read(f) != NOERR)
|
||
zero();
|
||
*/
|
||
this->TRectype::operator =(cache().get("%CAU", codice));
|
||
}
|
||
|
||
const real CENTO=real(100.0);
|
||
|
||
bool TCondizione_vendita::ricerca(const char * codice, const real & qta)
|
||
{
|
||
int tiporic;
|
||
switch (_condv.get_char("TIPO")) {
|
||
case 'L':
|
||
tiporic=A_LISTINI;
|
||
break;
|
||
case 'C':
|
||
tiporic=A_CONTRATTI;
|
||
break;
|
||
case 'O':
|
||
tiporic=A_OFFERTE;
|
||
break;
|
||
}
|
||
return cerca(tiporic,codice, qta);
|
||
}
|
||
|
||
|
||
bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const real & qta)
|
||
{
|
||
// if (_condv.get("COD").empty())
|
||
// return FALSE;
|
||
|
||
bool found = FALSE;
|
||
|
||
if(config_ditta().get_bool("GES", "ve", tiporicerca))
|
||
{
|
||
_condv.setkey( 1 );
|
||
switch( tiporicerca )
|
||
{
|
||
case A_CONTRATTI:
|
||
{
|
||
}
|
||
break;
|
||
case A_LISTINI:
|
||
{
|
||
_condv.put("TIPOCF", "");
|
||
_condv.put("CODCF", "");
|
||
if( !config_ditta().get_bool("GESLISCV", "ve"))
|
||
_condv.put("CATVEN", "");
|
||
}
|
||
break;
|
||
case A_OFFERTE:
|
||
{
|
||
}
|
||
break;
|
||
}
|
||
if( _condv.read() == NOERR )
|
||
{
|
||
// si posiziona sulla riga
|
||
const bool gest_scagl = _condv.get_bool("GESTSCAGL");
|
||
const TString16 seqricrighe( _condv.get( "SEQRIC" ) );
|
||
|
||
for( int i = 0; !found && i < seqricrighe.len( ); i ++ )
|
||
{
|
||
_rcondv.zero( );
|
||
_rcondv.put( "TIPO", _condv.get( "TIPO"));
|
||
_rcondv.put( "CATVEN", _condv.get( "CATVEN"));
|
||
_rcondv.put( "TIPOCF", _condv.get( "TIPOCF"));
|
||
_rcondv.put( "CODCF", _condv.get( "CODCF"));
|
||
_rcondv.put("COD", _condv.get("COD"));
|
||
if (gest_scagl)
|
||
_rcondv.put("NSCAGL", 1);
|
||
|
||
char ricerca = seqricrighe[ i ];
|
||
_rcondv.put( "TIPORIGA", ricerca );
|
||
switch( ricerca )
|
||
{
|
||
case 'A':
|
||
{
|
||
_rcondv.put( "CODRIGA", codriga);
|
||
if (_rcondv.read() != NOERR &&
|
||
_rcondv.prev() == NOERR &&
|
||
_rcondv.get("TIPORIGA")[0] == 'A')
|
||
{
|
||
const TString cod_found(_rcondv.get("CODRIGA"));
|
||
found = cod_found.compare(codriga, cod_found.len()) == 0;
|
||
}
|
||
}
|
||
break;
|
||
case 'R':
|
||
_rcondv.put("CODRIGA", anamag().get( "RAGGFIS"));
|
||
_rcondv.read();
|
||
found = _rcondv.good();
|
||
break;
|
||
case 'S':
|
||
{
|
||
_rcondv.put( "CODRIGA", anamag().get("GRMERC"));
|
||
_rcondv.read( );
|
||
found = _rcondv.good();
|
||
}
|
||
break;
|
||
case 'G':
|
||
{
|
||
_rcondv.put( "CODRIGA", anamag().get("GRMERC").left(3));
|
||
_rcondv.read( );
|
||
found = _rcondv.good();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
// individua lo scaglione corretto in base alla quantita'
|
||
if (found && gest_scagl)
|
||
{
|
||
TRectype rec(_rcondv.curr());
|
||
int last_scagl = 0;
|
||
int scagl = _rcondv.get_int("NSCAGL");
|
||
real qta_lim(_rcondv.get_real("QLIM"));
|
||
while (_rcondv.good() && scagl > last_scagl && qta_lim > ZERO && qta > qta_lim)
|
||
{
|
||
if (_rcondv.next() == NOERR)
|
||
{
|
||
last_scagl = scagl;
|
||
scagl = _rcondv.get_int("NSCAGL");
|
||
qta_lim =_rcondv.get_real("QLIM");
|
||
rec = _rcondv.curr();
|
||
}
|
||
}
|
||
_rcondv.read(rec);
|
||
}
|
||
_prezzo = _rcondv.get_real("PREZZO");
|
||
}
|
||
}
|
||
|
||
if (!found)
|
||
{
|
||
/*
|
||
TLocalisamfile um(LF_UMART); // Use Frate cercone when possible!
|
||
um.put("CODART", codriga);
|
||
um.put("NRIGA", 1);
|
||
if (um.read() == NOERR)
|
||
{
|
||
_prezzo = um.get_real("PREZZO");
|
||
found = TRUE;
|
||
}
|
||
else
|
||
_prezzo = ZERO;
|
||
*/
|
||
TString80 cod; cod << codriga << "|1";
|
||
const TRectype& um = cache().get(LF_UMART, cod);
|
||
_prezzo = um.get_real("PREZZO");
|
||
found = _prezzo != ZERO;
|
||
}
|
||
|
||
return found;
|
||
}
|
||
|
||
void TCondizione_vendita::put_condv(const char *tipocv,const char *codicecv,const char *catven,const char *tipocf,const char *codcf)
|
||
{
|
||
_condv.put("TIPO",tipocv);
|
||
_condv.put("CATVEN",catven);
|
||
_condv.put("TIPOCF",tipocf);
|
||
_condv.put("CODCF",codcf);
|
||
_condv.put("COD",codicecv);
|
||
}
|
||
|
||
void TCondizione_vendita::put_listino(const char * codlist,const char *catven)
|
||
{
|
||
if( !config_ditta().get_bool("GESLISCV", "ve"))
|
||
put_condv("L",codlist,"","","");
|
||
else
|
||
put_condv("L",codlist,catven,"","");
|
||
}
|
||
void TCondizione_vendita::put_contratto(const char * codcontr,const char *tipocf,const char *codcf)
|
||
{
|
||
put_condv("C",codcontr,"",tipocf,codcf);
|
||
}
|
||
void TCondizione_vendita::put_offerta(const char * codoff)
|
||
{
|
||
put_condv("C",codoff,"","","");
|
||
}
|
||
|
||
|
||
TCondizione_vendita::TCondizione_vendita(TConfig * ditta,
|
||
TLocalisamfile * anamag, TLocalisamfile * umart)
|
||
: _condv(LF_CONDV), _rcondv(LF_RCONDV),
|
||
_sconti( LF_SCONTI ),
|
||
_anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE)
|
||
{
|
||
}
|
||
|