1997-06-23 14:51:53 +00:00
|
|
|
|
// oggetto TArticolo, multirecord dell'articolo di anagrafica magazzino
|
|
|
|
|
// oggetto TArticolo_giacenza, multirecord dell'articolo di magazzino
|
1997-06-27 12:58:13 +00:00
|
|
|
|
// oggetto TMov_Mag , multirecord del movimento di magazzino
|
1997-06-23 14:51:53 +00:00
|
|
|
|
// funzione di ricostruzione saldi
|
1997-10-24 14:43:50 +00:00
|
|
|
|
|
1998-05-04 09:59:49 +00:00
|
|
|
|
#include <mask.h>
|
|
|
|
|
#include <progind.h>
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#include <utility.h>
|
1998-05-04 09:59:49 +00:00
|
|
|
|
#include <tabutil.h>
|
1997-10-24 14:43:50 +00:00
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
#include "mglib.h"
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#include "anamag.h"
|
|
|
|
|
#include "mag.h"
|
|
|
|
|
|
|
|
|
|
#ifndef __CGLIB01_H
|
1997-10-24 14:43:50 +00:00
|
|
|
|
#include "..\cg\cglib01.h"
|
|
|
|
|
#include "..\ve\veconf.h"
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// libreria per i movimenti
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
1998-02-18 13:46:52 +00:00
|
|
|
|
char * Nome_valorizz[]=
|
|
|
|
|
{
|
1997-06-04 14:27:02 +00:00
|
|
|
|
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
1998-08-25 18:07:30 +00:00
|
|
|
|
"Costo standard", "Costo medio acquisto" ,
|
|
|
|
|
"Costo medio ponderato" ,
|
1997-06-04 14:27:02 +00:00
|
|
|
|
"FIFO annuale", "LIFO annuale",
|
|
|
|
|
"FIFO", "LIFO",
|
|
|
|
|
"FIFO Ragionieristico", "LIFO Ragionieristico"
|
|
|
|
|
} ;
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
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;
|
1998-06-10 16:38:58 +00:00
|
|
|
|
if (op1)
|
|
|
|
|
{
|
|
|
|
|
op1=op1+1;
|
|
|
|
|
if (*op1 == '#')
|
|
|
|
|
index = atoi(fname + 1);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const char* op2 = strstr(fname, "->");
|
|
|
|
|
CHECKS(op2, "Can't find '->' in string ", fieldname);
|
1998-06-10 16:38:58 +00:00
|
|
|
|
op2=op2+2;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
|
{
|
|
|
|
|
case LF_UMART:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_um(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return um().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LF_CODCORR:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_codcorr(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return codcorr().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LF_DESLIN:
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_deslin(op1);
|
|
|
|
|
if (index > 0 && op2)
|
|
|
|
|
return deslin().row(index).get(op2);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-05-04 09:59:49 +00:00
|
|
|
|
return EMPTY_STRING;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
void TArticolo::set_body_key(TRectype & rowrec)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const int logicnum = rowrec.num();
|
1997-12-18 17:32:55 +00:00
|
|
|
|
const char * codice = (const char *) (*_codice);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
|
{
|
|
|
|
|
case LF_UMART:
|
|
|
|
|
rowrec.put(UMART_CODART, codice);
|
|
|
|
|
break;
|
|
|
|
|
case LF_DESLIN:
|
|
|
|
|
rowrec.put(DESLIN_CODART, codice);
|
|
|
|
|
break;
|
|
|
|
|
case LF_CODCORR:
|
|
|
|
|
rowrec.put(CODCORR_CODART, codice);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
int TArticolo::read(TRectype & rec, word op, word lockop)
|
|
|
|
|
{
|
1998-01-09 16:33:25 +00:00
|
|
|
|
TString compstr((const char *) *_codice);
|
|
|
|
|
if (op == _isequal && lockop == _nolock && strcmp (rec.get(ANAMAG_CODART), (const char *) (compstr)) == 0)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
return NOERR;
|
1997-06-18 15:23:13 +00:00
|
|
|
|
|
|
|
|
|
*_codice = rec.get(ANAMAG_CODART);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
const int err = TMultiple_rectype::read(rec, op , lockop);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
if (err != NOERR)
|
|
|
|
|
zero();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-18 15:23:13 +00:00
|
|
|
|
int TArticolo::read(const char * cod, word op, word lockop)
|
|
|
|
|
{
|
1998-01-09 16:33:25 +00:00
|
|
|
|
TRectype tmp(*this);
|
|
|
|
|
tmp.put(ANAMAG_CODART,cod);
|
|
|
|
|
return read( tmp, op, lockop);
|
1997-06-18 15:23:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-04 14:27:02 +00:00
|
|
|
|
|
|
|
|
|
void TArticolo::update_ultcosti(real costo,TDate data)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TDate data1(get_date(ANAMAG_DULTCOS1));
|
|
|
|
|
if (data>= data1)
|
|
|
|
|
{
|
|
|
|
|
real costo1(get_real(ANAMAG_ULTCOS1));
|
|
|
|
|
put(ANAMAG_DULTCOS1,data);
|
|
|
|
|
put(ANAMAG_ULTCOS1,costo);
|
|
|
|
|
put(ANAMAG_DULTCOS2,data1);
|
|
|
|
|
put(ANAMAG_ULTCOS2,costo1);
|
|
|
|
|
} else {
|
|
|
|
|
if (data>= get_date(ANAMAG_DULTCOS2))
|
|
|
|
|
put(ANAMAG_DULTCOS2,data);
|
|
|
|
|
put(ANAMAG_ULTCOS2,costo);
|
|
|
|
|
}
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArticolo::unlock()
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
bool rv;
|
1997-12-18 17:32:55 +00:00
|
|
|
|
if (*((const char *)*_codice))
|
1997-06-18 15:18:06 +00:00
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anag(LF_ANAMAG);
|
|
|
|
|
anag.curr()=*this;
|
|
|
|
|
rv=(anag.read(_isequal,_unlock)==NOERR);
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArticolo::lock_and_prompt()
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TString mess;
|
1998-01-09 16:33:25 +00:00
|
|
|
|
int err;
|
1997-06-18 15:18:06 +00:00
|
|
|
|
do {
|
|
|
|
|
TLocalisamfile anag(LF_ANAMAG);
|
|
|
|
|
anag.curr()=*this;
|
1998-01-09 16:33:25 +00:00
|
|
|
|
err=anag.read(_isequal,_testandlock);
|
|
|
|
|
switch (err)
|
|
|
|
|
{
|
|
|
|
|
case NOERR:
|
|
|
|
|
return TRUE;
|
|
|
|
|
case _islocked:
|
|
|
|
|
{
|
|
|
|
|
mess.cut(0);
|
|
|
|
|
mess << "Il record di anagrafica dell'articolo ''"<< codice() << "'' risulta essere gi<67> in uso.\n Interrompo ?";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
mess.cut(0);
|
|
|
|
|
mess << "Non riesco ad accedere al record di anagrafica dell'articolo ''"<< codice() << "'' \n Interrompo ?";
|
|
|
|
|
}
|
|
|
|
|
TTimed_breakbox bbox((const char *)mess,10);
|
|
|
|
|
if (bbox.run()==K_ESC)
|
|
|
|
|
return FALSE;
|
|
|
|
|
} while (TRUE);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
return FALSE;
|
1997-06-04 14:27:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
TArticolo::TArticolo(const char* codice)
|
1997-05-30 15:26:08 +00:00
|
|
|
|
: TMultiple_rectype(LF_ANAMAG)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
add_file(LF_UMART,"NRIGA");
|
|
|
|
|
add_file(LF_CODCORR,"NRIGA");
|
|
|
|
|
add_file(LF_DESLIN,"NRIGA");
|
1997-05-27 11:12:10 +00:00
|
|
|
|
_codice = new TRecfield(*this, ANAMAG_CODART);
|
|
|
|
|
if (codice && *codice)
|
|
|
|
|
read(codice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArticolo::TArticolo(const TRectype& rec)
|
1997-05-30 15:26:08 +00:00
|
|
|
|
: TMultiple_rectype(rec)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
_codice = new TRecfield(*this, ANAMAG_CODART);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArticolo::~TArticolo()
|
|
|
|
|
{
|
|
|
|
|
delete _codice;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
// *****************
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
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);
|
1998-06-10 16:38:58 +00:00
|
|
|
|
if (logicnum !=LF_MAG && logicnum !=LF_STOMAG)
|
|
|
|
|
return TArticolo::get_str(fieldname);
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const char * op1 = strchr(fname, '_');
|
|
|
|
|
int index = 0;
|
1998-06-10 16:38:58 +00:00
|
|
|
|
if (op1)
|
|
|
|
|
{
|
|
|
|
|
op1=op1+1;
|
|
|
|
|
fname = (char *) op1;
|
|
|
|
|
if (*op1 == '#')
|
|
|
|
|
index = atoi(fname + 1);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const char * op2 = strchr(fname, '_');
|
1998-06-10 16:38:58 +00:00
|
|
|
|
if (op2)
|
|
|
|
|
{
|
|
|
|
|
op2=op2+1;
|
|
|
|
|
fname = (char *) op2 + 1;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const char * op3 = strchr(fname, '_');
|
1998-06-10 16:38:58 +00:00
|
|
|
|
if (op3)
|
|
|
|
|
op3=op3+1;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const char * op4 = strstr(fname, "->");
|
|
|
|
|
CHECKS(op4, "Can't find '->' in string ", fieldname);
|
1998-06-10 16:38:58 +00:00
|
|
|
|
op4=op4+2;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
|
{
|
|
|
|
|
case LF_MAG:
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
index = find_mag(op1, op2, op3);
|
|
|
|
|
if (index > 0 && op3)
|
|
|
|
|
return mag(op1).row(index).get(op4);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
break;
|
1998-06-10 16:38:58 +00:00
|
|
|
|
case LF_STOMAG:
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (index = 0)
|
|
|
|
|
index = find_storico(op1, op2);
|
|
|
|
|
if (index > 0)
|
|
|
|
|
return storico(op1).row(index).get(op4);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1998-05-04 09:59:49 +00:00
|
|
|
|
return EMPTY_STRING;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
int TArticolo_giacenza::find_mag(const char * annoes, const char * codmag, const char * livello, int from) const
|
1997-05-30 15:26:08 +00:00
|
|
|
|
{
|
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
|
|
|
|
const int last = rmag.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
1997-12-18 17:32:55 +00:00
|
|
|
|
if (last > 0 && from <= last)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
for (int i = rmag.succ_row(from); i <= last; i = rmag.succ_row(i))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
1997-07-02 10:53:23 +00:00
|
|
|
|
int TArticolo_giacenza::find_storico(const char * annoesrif, const char * annoes, const char * codmag, int from) const
|
1997-05-30 15:26:08 +00:00
|
|
|
|
{
|
1997-07-02 10:53:23 +00:00
|
|
|
|
TRecord_array & rsto = storico(annoesrif);
|
|
|
|
|
const int last = rsto.last_row();
|
1997-12-18 17:32:55 +00:00
|
|
|
|
|
|
|
|
|
if (last > 0 && from <= last)
|
1997-07-02 10:53:23 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRecord_array & TArticolo_giacenza::mag(const char * annoes) const
|
|
|
|
|
{
|
|
|
|
|
((TArticolo_giacenza *) this)->set_anno_mag(annoes);
|
|
|
|
|
return body(LF_MAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRecord_array & TArticolo_giacenza::storico(const char * annoesrif) const
|
|
|
|
|
{
|
|
|
|
|
((TArticolo_giacenza *) this)->set_anno_sto(annoesrif);
|
|
|
|
|
return body(LF_STOMAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIDDEN int last_esercizio = -1;
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-12-18 17:32:55 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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];
|
1998-08-25 18:07:30 +00:00
|
|
|
|
mag = rec.get(MAG_CODMAG); mag.cut(3);
|
1997-12-18 17:32:55 +00:00
|
|
|
|
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;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
case valorizz_costmediopond:
|
|
|
|
|
val = costo_mediopond(oldes, mag, liv);
|
|
|
|
|
break;
|
1997-12-18 17:32:55 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
|
|
|
|
{
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
const real costo = get_real(ANAMAG_ULTCOS1);
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const real costo = storico(annoes).row(index).get_real(STOMAG_ULTCOS1);
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::media_costi(const char * annoes) const
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
real costo = get_real(ANAMAG_ULTCOS1);
|
|
|
|
|
|
|
|
|
|
costo = (costo + get_real(ANAMAG_ULTCOS2)) / 2.0;
|
|
|
|
|
return costo == ZERO ? costo_standard(annoes) : costo;
|
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-28 10:14:39 +00:00
|
|
|
|
real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven, const char * codlist) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
static TString16 f;
|
1998-06-10 16:38:58 +00:00
|
|
|
|
TConfig cfg(CONFIG_DITTA);
|
|
|
|
|
TCondizione_vendita cv(&cfg);
|
|
|
|
|
cv.put_listino(codlist,catven);
|
|
|
|
|
if (cv.ricerca(codice()))
|
|
|
|
|
return cv.get_prezzo();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// se non lo trova, cerca nel prezzo indicato nelle UM
|
1997-05-27 11:12:10 +00:00
|
|
|
|
f.format("#%d->%s", LF_UMART, UMART_PREZZO);
|
1998-06-10 16:38:58 +00:00
|
|
|
|
return get_real(f);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
return storico(annoes).row(index).get_real(STOMAG_PRZLIST);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::costo_standard(const char * annoes) const
|
|
|
|
|
{
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (last_esercizio == atoi(annoes))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
return get_real(ANAMAG_COSTSTD);
|
1997-05-30 15:26:08 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int index = find_storico(annoes, annoes);
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (index < 0 ) return ZERO;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
return storico(annoes).row(index).get_real(STOMAG_COSTSTD);
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::costo_medio(const char * annoes, const char * codmag, const char * livello) const
|
|
|
|
|
{
|
|
|
|
|
real acq;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
real valacq;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0;
|
|
|
|
|
i = find_mag(annoes, codmag, livello, i))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
|
|
|
|
}
|
|
|
|
|
return acq == ZERO ? costo_standard(annoes) : valacq / acq;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real TArticolo_giacenza::LIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
|
|
|
|
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
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,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
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,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
if (giacenza > rim)
|
|
|
|
|
return ((giacenza - rim) * (acq == ZERO ? costo_standard(annoes) : valacq / acq) + valrim) / giacenza;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rstorico = storico(annoes);
|
1997-07-02 10:53:23 +00:00
|
|
|
|
// const int last = rstorico.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim = giacenza;
|
1997-07-02 10:53:23 +00:00
|
|
|
|
for (i = find_storico(annoes, "", codmag); i > 0; i = find_storico(annoes, "", codmag, i))
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rstorico.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
const real qta = rec.get(STOMAG_QUANT);
|
|
|
|
|
|
|
|
|
|
if (qta > giacenza)
|
|
|
|
|
{
|
|
|
|
|
valrim += (rec.get_real(STOMAG_VALORE) / qta) * giacenza;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valrim += rec.get_real(STOMAG_VALORE);
|
|
|
|
|
giacenza -= qta;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return valrim / rim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::FIFO(const char * annoes, const char * codmag, const char * livello,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
1997-05-27 11:12:10 +00:00
|
|
|
|
real rim;
|
|
|
|
|
real valrim;
|
|
|
|
|
real acq;
|
|
|
|
|
real valacq;
|
|
|
|
|
real giacenza;
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rmag = mag(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (int i = find_mag(annoes, codmag, livello); i > 0; i = find_mag(annoes, codmag, livello, i))
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rmag.row(i);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
rim += rec.get_real(MAG_RIM);
|
|
|
|
|
valrim += rec.get_real(MAG_VALRIM);
|
|
|
|
|
acq += rec.get_real(MAG_ACQ);
|
|
|
|
|
valacq += rec.get_real(MAG_VALACQ);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
giacenza += giacenza_corretta(rec,giac_eff,valorizza_componenti);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (giacenza <= ZERO)
|
|
|
|
|
return ZERO;
|
|
|
|
|
if (giacenza <= acq)
|
|
|
|
|
return valacq / acq;
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TRecord_array & rstorico = storico(annoes);
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const int last = rstorico.last_row();
|
1997-05-27 11:12:10 +00:00
|
|
|
|
|
|
|
|
|
real res = giacenza - acq;
|
|
|
|
|
rim = ZERO;
|
1997-07-02 10:53:23 +00:00
|
|
|
|
valrim = ZERO;
|
|
|
|
|
TFixed_string cmag(codmag);
|
|
|
|
|
int codmag_len = codmag ? strlen(cmag) : 0;
|
1997-05-27 11:12:10 +00:00
|
|
|
|
for (i = last; i > 0; i--)
|
|
|
|
|
{
|
1997-05-30 15:26:08 +00:00
|
|
|
|
const TRectype & rec = rstorico.row(i);
|
1997-07-02 10:53:23 +00:00
|
|
|
|
if (codmag_len == 0 || rec.get(STOMAG_CODMAG).compare(codmag, codmag_len) == 0)
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1997-07-02 10:53:23 +00:00
|
|
|
|
const real qta = rec.get(STOMAG_QUANT);
|
|
|
|
|
|
|
|
|
|
if (qta > res)
|
|
|
|
|
{
|
|
|
|
|
rim += res;
|
|
|
|
|
valrim += (rec.get_real(STOMAG_VALORE) / qta) * res;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rim += qta;
|
|
|
|
|
valrim += rec.get_real(STOMAG_VALORE);
|
|
|
|
|
res -= qta;
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ((giacenza - acq) * (valrim / rim) + valacq) / giacenza;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
real TArticolo_giacenza::FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-27 11:12:10 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
1998-02-18 13:46:52 +00:00
|
|
|
|
return ZERO; // da implementare
|
1997-05-30 15:26:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TArticolo_giacenza::LIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello,
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool giac_eff, bool valorizza_componenti) const
|
1997-05-30 15:26:08 +00:00
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
|
CHECK(strlen(codmag)<=3, "Non <20> pi<70> possibile avere valorizzazione a livello di deposito");
|
1998-02-18 13:46:52 +00:00
|
|
|
|
return ZERO; // da implementare
|
1997-05-30 15:26:08 +00:00
|
|
|
|
}
|
1997-07-30 13:28:22 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// 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
|
1997-07-30 13:28:22 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK(rec.num() == LF_MAG, "Il record passato deve essere di LF_MAG");
|
|
|
|
|
real giacenza(rec.get_real(MAG_GIAC));
|
1998-08-25 18:07:30 +00:00
|
|
|
|
if (giac_eff)
|
1997-07-30 13:28:22 +00:00
|
|
|
|
{
|
|
|
|
|
giacenza += rec.get_real(MAG_INCL);
|
|
|
|
|
giacenza -= rec.get_real(MAG_ACL);
|
|
|
|
|
giacenza += valorizza_componenti ? 0 : (rec.get_real(MAG_PRODFIN)-rec.get_real(MAG_PRODCOMP));
|
|
|
|
|
}
|
|
|
|
|
return giacenza;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-05-30 15:26:08 +00:00
|
|
|
|
TArticolo_giacenza::TArticolo_giacenza(const char* codice)
|
|
|
|
|
: TArticolo(codice)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
add_file(LF_MAG,"NRIGA");
|
|
|
|
|
add_file(LF_STOMAG,"NRIGA");
|
1997-05-30 15:26:08 +00:00
|
|
|
|
if (last_esercizio < 0 )
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili e;
|
|
|
|
|
|
|
|
|
|
last_esercizio = e.last();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArticolo_giacenza::TArticolo_giacenza(const TRectype& rec)
|
|
|
|
|
: TArticolo(rec)
|
|
|
|
|
{
|
|
|
|
|
if (last_esercizio < 0 )
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili e;
|
|
|
|
|
|
|
|
|
|
last_esercizio = e.last();
|
|
|
|
|
}
|
1997-05-27 11:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-06-06 16:36:35 +00:00
|
|
|
|
const real CENTO=real(100.0);
|
|
|
|
|
|
|
|
|
|
bool TCondizione_vendita:: ricerca(const char * codice, const real & qta)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return cerca(tiporic,codice, qta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const real & qta)
|
|
|
|
|
{
|
|
|
|
|
if( config_ditta().get_bool( "GES", "ve", tiporicerca ) )
|
|
|
|
|
{
|
|
|
|
|
_condv.setkey( 1 );
|
|
|
|
|
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if (_condv.get("COD").empty())
|
|
|
|
|
return FALSE;
|
1997-06-06 16:36:35 +00:00
|
|
|
|
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 )
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
// si posiziona sulla riga
|
1997-06-06 16:36:35 +00:00
|
|
|
|
const bool gest_scagl = _condv.get_bool("GESTSCAGL");
|
|
|
|
|
const TString16 seqricrighe( _condv.get( "SEQRIC" ) );
|
|
|
|
|
bool found = FALSE;
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
return cod_found.compare(codriga, cod_found.len()) == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
_rcondv.put("CODRIGA", anamag().get( "RAGGFIS"));
|
|
|
|
|
_rcondv.read();
|
|
|
|
|
break;
|
|
|
|
|
case 'S':
|
|
|
|
|
{
|
|
|
|
|
_rcondv.put( "CODRIGA", anamag().get("GRMERC"));
|
|
|
|
|
_rcondv.read( );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'G':
|
|
|
|
|
{
|
|
|
|
|
_rcondv.put( "CODRIGA", anamag().get("GRMERC").left(3));
|
|
|
|
|
_rcondv.read( );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
found = _rcondv.good();
|
|
|
|
|
}
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
1997-06-18 15:18:06 +00:00
|
|
|
|
_prezzo = _rcondv.get_real("PREZZO");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Ricerca fallita
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCondizione_vendita::put_condv(const char *tipocv,const char *codicecv,const char *catven,const char *tipocf,const char *codcf)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
_condv.put("TIPO",tipocv);
|
|
|
|
|
_condv.put("CATVEN",catven);
|
|
|
|
|
_condv.put("TIPOCF",tipocf);
|
|
|
|
|
_condv.put("CODCF",codcf);
|
|
|
|
|
_condv.put("COD",codicecv);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TCondizione_vendita::put_listino(const char * codlist,const char *catven)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
if( !config_ditta().get_bool("GESLISCV", "ve"))
|
|
|
|
|
put_condv("L",codlist,"","","");
|
|
|
|
|
else
|
|
|
|
|
put_condv("L",codlist,catven,"","");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
void TCondizione_vendita::put_contratto(const char * codcontr,const char *tipocf,const char *codcf)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
put_condv("C",codcontr,"",tipocf,codcf);
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
void TCondizione_vendita::put_offerta(const char * codoff)
|
|
|
|
|
{
|
1997-06-18 15:18:06 +00:00
|
|
|
|
put_condv("C",codoff,"","","");
|
1997-06-06 16:36:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TCondizione_vendita::TCondizione_vendita(TConfig * ditta,
|
1997-06-18 15:18:06 +00:00
|
|
|
|
TLocalisamfile * anamag, TLocalisamfile * umart)
|
1997-06-06 16:36:35 +00:00
|
|
|
|
: _condv(LF_CONDV), _rcondv(LF_RCONDV),
|
|
|
|
|
_sconti( LF_SCONTI ),
|
|
|
|
|
_anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|