Primo debug
Esplosione dei tab git-svn-id: svn://10.65.10.50/trunk@4708 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
710569854d
commit
d7dd466831
508
mg/mglib02.cpp
508
mg/mglib02.cpp
@ -3,9 +3,9 @@
|
||||
#include "mag.h"
|
||||
#include <mask.h>
|
||||
|
||||
// libreira per i movimenti
|
||||
// libreria per i movimenti
|
||||
|
||||
char * TNome_valorizz[]= {
|
||||
char * Nome_valorizz[]= {
|
||||
"Ultimo costo", "Media ultimi costi", "Prezzo di listino",
|
||||
"Costo standard", "Costo medio" ,
|
||||
"FIFO annuale", "LIFO annuale",
|
||||
@ -112,46 +112,46 @@ const TString & TArticolo::descrizione(const char* lingua) const
|
||||
|
||||
void TArticolo::update_ultcosti(real costo,TDate data)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool TArticolo::unlock()
|
||||
{
|
||||
bool rv;
|
||||
bool rv;
|
||||
if (*(const char *)_codice)
|
||||
{
|
||||
TLocalisamfile anag(LF_ANAMAG);
|
||||
anag.curr()=*this;
|
||||
rv=(anag.read(_isequal,_unlock)==NOERR);
|
||||
return rv;
|
||||
}
|
||||
return FALSE;
|
||||
{
|
||||
TLocalisamfile anag(LF_ANAMAG);
|
||||
anag.curr()=*this;
|
||||
rv=(anag.read(_isequal,_unlock)==NOERR);
|
||||
return rv;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool TArticolo::lock_and_prompt()
|
||||
{
|
||||
TString mess;
|
||||
mess << "Il record di anagrafica dell'articolo ''"<< codice() << "'' risulta essere già in uso.\n Interrompo ?";
|
||||
TTimed_breakbox bbox((const char *)mess,10);
|
||||
do {
|
||||
TLocalisamfile anag(LF_ANAMAG);
|
||||
anag.curr()=*this;
|
||||
if (anag.read(_isequal,_testandlock)==NOERR)
|
||||
return TRUE;
|
||||
} while (bbox.run()!=K_ESC);
|
||||
return FALSE;
|
||||
TString mess;
|
||||
mess << "Il record di anagrafica dell'articolo ''"<< codice() << "'' risulta essere già in uso.\n Interrompo ?";
|
||||
TTimed_breakbox bbox((const char *)mess,10);
|
||||
do {
|
||||
TLocalisamfile anag(LF_ANAMAG);
|
||||
anag.curr()=*this;
|
||||
if (anag.read(_isequal,_testandlock)==NOERR)
|
||||
return TRUE;
|
||||
} while (bbox.run()!=K_ESC);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -159,9 +159,9 @@ TArticolo::TArticolo(const char* codice)
|
||||
: TMultiple_rectype(LF_ANAMAG)
|
||||
|
||||
{
|
||||
add_file(LF_UMART,"NRIGA");
|
||||
add_file(LF_CODCORR,"NRIGA");
|
||||
add_file(LF_DESLIN,"NRIGA");
|
||||
add_file(LF_UMART,"NRIGA");
|
||||
add_file(LF_CODCORR,"NRIGA");
|
||||
add_file(LF_DESLIN,"NRIGA");
|
||||
_codice = new TRecfield(*this, ANAMAG_CODART);
|
||||
if (codice && *codice)
|
||||
read(codice);
|
||||
@ -311,7 +311,7 @@ HIDDEN int last_esercizio = -1;
|
||||
real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
||||
{
|
||||
|
||||
if (last_esercizio != atoi(annoes))
|
||||
if (last_esercizio == atoi(annoes))
|
||||
{
|
||||
const real costo = get_real(ANAMAG_ULTCOS1);
|
||||
return costo == ZERO ? costo_standard(annoes) : costo;
|
||||
@ -319,6 +319,7 @@ real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
||||
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;
|
||||
}
|
||||
@ -326,7 +327,7 @@ real TArticolo_giacenza::ultimo_costo(const char * annoes) const
|
||||
|
||||
real TArticolo_giacenza::media_costi(const char * annoes) const
|
||||
{
|
||||
if (last_esercizio != atoi(annoes))
|
||||
if (last_esercizio == atoi(annoes))
|
||||
{
|
||||
real costo = get_real(ANAMAG_ULTCOS1);
|
||||
|
||||
@ -336,6 +337,7 @@ real TArticolo_giacenza::media_costi(const char * annoes) const
|
||||
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);
|
||||
|
||||
@ -346,7 +348,7 @@ real TArticolo_giacenza::media_costi(const char * annoes) const
|
||||
|
||||
real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven, const char * codlist) const
|
||||
{
|
||||
if (last_esercizio != atoi(annoes))
|
||||
if (last_esercizio == atoi(annoes))
|
||||
{
|
||||
static TString16 f;
|
||||
if (f.empty())
|
||||
@ -356,7 +358,7 @@ real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven
|
||||
else
|
||||
{
|
||||
const int index = find_storico(annoes, annoes);
|
||||
|
||||
if (index < 0 ) return ZERO;
|
||||
return storico(annoes).row(index).get_real(STOMAG_PRZLIST);
|
||||
}
|
||||
}
|
||||
@ -364,11 +366,12 @@ real TArticolo_giacenza::prezzo_listino(const char * annoes, const char * catven
|
||||
real TArticolo_giacenza::costo_standard(const char * annoes) const
|
||||
{
|
||||
|
||||
if (last_esercizio != atoi(annoes))
|
||||
if (last_esercizio == atoi(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);
|
||||
}
|
||||
}
|
||||
@ -389,6 +392,7 @@ real TArticolo_giacenza::costo_medio(const char * annoes, const char * codmag, c
|
||||
return acq == ZERO ? costo_standard(annoes) : valacq / acq;
|
||||
}
|
||||
|
||||
|
||||
real TArticolo_giacenza::LIFO_annuale(const char * annoes, const char * codmag, const char * livello,
|
||||
bool giacenza_effettiva, bool valorizza_componenti) const
|
||||
{
|
||||
@ -585,8 +589,8 @@ real TArticolo_giacenza::LIFO_ragionieristico(const char * annoes, const char *
|
||||
TArticolo_giacenza::TArticolo_giacenza(const char* codice)
|
||||
: TArticolo(codice)
|
||||
{
|
||||
add_file(LF_MAG,"NRIGA");
|
||||
add_file(LF_STOMAG,"NRIGA");
|
||||
add_file(LF_MAG,"NRIGA");
|
||||
add_file(LF_STOMAG,"NRIGA");
|
||||
if (last_esercizio < 0 )
|
||||
{
|
||||
TEsercizi_contabili e;
|
||||
@ -626,18 +630,18 @@ 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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -648,8 +652,8 @@ bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const r
|
||||
{
|
||||
_condv.setkey( 1 );
|
||||
|
||||
if (_condv.get("COD").empty())
|
||||
return FALSE;
|
||||
if (_condv.get("COD").empty())
|
||||
return FALSE;
|
||||
switch( tiporicerca )
|
||||
{
|
||||
case A_CONTRATTI:
|
||||
@ -671,7 +675,7 @@ bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const r
|
||||
}
|
||||
if( _condv.read( ) == NOERR )
|
||||
{
|
||||
// si posiziona sulla riga
|
||||
// si posiziona sulla riga
|
||||
const bool gest_scagl = _condv.get_bool("GESTSCAGL");
|
||||
const TString16 seqricrighe( _condv.get( "SEQRIC" ) );
|
||||
bool found = FALSE;
|
||||
@ -743,7 +747,7 @@ bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const r
|
||||
}
|
||||
_rcondv.read(rec);
|
||||
}
|
||||
_prezzo = _rcondv.get_real("PREZZO");
|
||||
_prezzo = _rcondv.get_real("PREZZO");
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@ -753,32 +757,32 @@ bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const r
|
||||
|
||||
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);
|
||||
_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,"","");
|
||||
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);
|
||||
put_condv("C",codcontr,"",tipocf,codcf);
|
||||
}
|
||||
void TCondizione_vendita::put_offerta(const char * codoff)
|
||||
{
|
||||
put_condv("C",codoff,"","","");
|
||||
put_condv("C",codoff,"","","");
|
||||
}
|
||||
|
||||
|
||||
TCondizione_vendita::TCondizione_vendita(TConfig * ditta,
|
||||
TLocalisamfile * anamag, TLocalisamfile * umart)
|
||||
TLocalisamfile * anamag, TLocalisamfile * umart)
|
||||
: _condv(LF_CONDV), _rcondv(LF_RCONDV),
|
||||
_sconti( LF_SCONTI ),
|
||||
_anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE)
|
||||
@ -829,14 +833,14 @@ int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo)
|
||||
|
||||
|
||||
TCausale_magazzino::TCausale_magazzino(const char * codice):
|
||||
TRectype(LF_TAB)
|
||||
TRectype(LF_TAB)
|
||||
{
|
||||
TTable f("CAU");
|
||||
f.put("CODTAB",codice);
|
||||
if (f.read() != NOERR)
|
||||
zero();
|
||||
else
|
||||
*this=(TCausale_magazzino &)f.curr();
|
||||
TTable f("CAU");
|
||||
f.put("CODTAB",codice);
|
||||
if (f.read() != NOERR)
|
||||
zero();
|
||||
else
|
||||
*this=(TCausale_magazzino &)f.curr();
|
||||
}
|
||||
TCausale_magazzino::~TCausale_magazzino()
|
||||
{
|
||||
@ -871,7 +875,7 @@ TMov_mag::~TMov_mag()
|
||||
// valuta il valore della chiave per un nuovo record
|
||||
bool TMov_mag::renum()
|
||||
{
|
||||
put("NUMREG",get_next_key());
|
||||
put("NUMREG",get_next_key());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -960,22 +964,22 @@ const char *TMov_mag::get_next_key()
|
||||
int TMov_mag::force_update_bal()
|
||||
{
|
||||
int res;
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
|
||||
// reset delle strutture per il controlli delle variazioni dei saldi
|
||||
_codcaus=get("CODCAUS");
|
||||
_annoes=get("ANNOES");
|
||||
lines_to_add.destroy();
|
||||
lines_to_subtract.destroy();
|
||||
// memorizza le variazioni
|
||||
for (int i=0; i<rows(); i++) {
|
||||
l_key=line2key(i+1);
|
||||
l_data=line2data(i+1);
|
||||
((TMov_mag *)this)->insert_line(l_key,l_data);
|
||||
}
|
||||
res=update_balances();
|
||||
return res;
|
||||
TToken_string l_key;
|
||||
TLine_movmag l_data;
|
||||
|
||||
// reset delle strutture per il controlli delle variazioni dei saldi
|
||||
_codcaus=get("CODCAUS");
|
||||
_annoes=get("ANNOES");
|
||||
lines_to_add.destroy();
|
||||
lines_to_subtract.destroy();
|
||||
// memorizza le variazioni
|
||||
for (int i=0; i<rows(); i++) {
|
||||
l_key=line2key(i+1);
|
||||
l_data=line2data(i+1);
|
||||
((TMov_mag *)this)->insert_line(l_key,l_data);
|
||||
}
|
||||
res=update_balances();
|
||||
return res;
|
||||
}
|
||||
|
||||
TLine_movmag TMov_mag::line2data(int numriga) const
|
||||
@ -1067,11 +1071,11 @@ bool TMov_mag::lock_anamag(const char *codart)
|
||||
|
||||
void TMov_mag::giac_putkey(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key)
|
||||
{
|
||||
mag.zero(' ');
|
||||
mag.put("ANNOES",annoes);
|
||||
mag.put("CODMAG",key2field(curr_key,"CODMAG"));
|
||||
mag.put("CODART",key2field(curr_key,"CODART"));
|
||||
mag.put("LIVELLO",key2field(curr_key,"LIVGIAC"));
|
||||
mag.zero(' ');
|
||||
mag.put("ANNOES",annoes);
|
||||
mag.put("CODMAG",key2field(curr_key,"CODMAG"));
|
||||
mag.put("CODART",key2field(curr_key,"CODART"));
|
||||
mag.put("LIVELLO",key2field(curr_key,"LIVGIAC"));
|
||||
}
|
||||
|
||||
|
||||
@ -1093,112 +1097,112 @@ int TMov_mag::update_balances() const
|
||||
keys_to_add.sort();
|
||||
TToken_string * curr_key=(TToken_string *)keys_to_add.first_item();
|
||||
|
||||
while (curr_key) {
|
||||
TArticolo_giacenza articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
TLine_movmag & line_mov=(TLine_movmag &)lines_to_add[*curr_key];
|
||||
articolo.update_ultcosti(line_mov.prezzo,get_date("DATACOMP"));
|
||||
// lock gained
|
||||
giac_putkey(mag,get("ANNOES"),*curr_key);
|
||||
if (mag.read()!=NOERR) {
|
||||
// non trovato: aggiungo
|
||||
giac_putkey(mag,get("ANNOES"),*curr_key);
|
||||
mag.put("NRIGA",1+articolo.mag(get("ANNOES")).rows());
|
||||
mag.write();
|
||||
}
|
||||
// modifica questo record (e lo sblocca)
|
||||
update_balances(mag.curr(),line_mov,get("CODCAUS"),+1);
|
||||
/*// ottimizzazione :(cerca di sfruttare la lettura fatta per un eventuale saldo vecchio)
|
||||
// ciò causa la modifica dell'oggetto TMov_mag (il metodo non è più const)
|
||||
if (_annoes == get("ANNOES")
|
||||
&& lines_to_subtract.is_key(*curr_key)) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
((TMov_mag *)this)->lines_to_add.remove(*curr_key);
|
||||
((TMov_mag *)this)->lines_to_subtract.remove(*curr_key);
|
||||
}*/
|
||||
mag.rewrite();
|
||||
// conclude la TRANSAZIONE prima di sbloccare il record dell'articolo
|
||||
TToken_string *rem_key=(TToken_string *)keys_to_remove.first_item();
|
||||
while ( rem_key) {
|
||||
if (key2field(*rem_key,"CODART")==key2field(*curr_key,"CODART")) {
|
||||
giac_putkey(mag,_annoes,*rem_key);
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*rem_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
keys_to_remove.remove_item();
|
||||
}
|
||||
rem_key=(TToken_string *)keys_to_remove.succ_item();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
updated_bal=FALSE;
|
||||
}
|
||||
curr_key=(TToken_string *)keys_to_add.succ_item();
|
||||
}
|
||||
// togli i saldi vecchi
|
||||
while (curr_key) {
|
||||
TArticolo_giacenza articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
TLine_movmag & line_mov=(TLine_movmag &)lines_to_add[*curr_key];
|
||||
articolo.update_ultcosti(line_mov.prezzo,get_date("DATACOMP"));
|
||||
// lock gained
|
||||
giac_putkey(mag,get("ANNOES"),*curr_key);
|
||||
if (mag.read()!=NOERR) {
|
||||
// non trovato: aggiungo
|
||||
giac_putkey(mag,get("ANNOES"),*curr_key);
|
||||
mag.put("NRIGA",1+articolo.mag(get("ANNOES")).rows());
|
||||
mag.write();
|
||||
}
|
||||
// modifica questo record (e lo sblocca)
|
||||
update_balances(mag.curr(),line_mov,get("CODCAUS"),+1);
|
||||
/*// ottimizzazione :(cerca di sfruttare la lettura fatta per un eventuale saldo vecchio)
|
||||
// ciò causa la modifica dell'oggetto TMov_mag (il metodo non è più const)
|
||||
if (_annoes == get("ANNOES")
|
||||
&& lines_to_subtract.is_key(*curr_key)) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
((TMov_mag *)this)->lines_to_add.remove(*curr_key);
|
||||
((TMov_mag *)this)->lines_to_subtract.remove(*curr_key);
|
||||
}*/
|
||||
mag.rewrite();
|
||||
// conclude la TRANSAZIONE prima di sbloccare il record dell'articolo
|
||||
TToken_string *rem_key=(TToken_string *)keys_to_remove.first_item();
|
||||
while ( rem_key) {
|
||||
if (key2field(*rem_key,"CODART")==key2field(*curr_key,"CODART")) {
|
||||
giac_putkey(mag,_annoes,*rem_key);
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*rem_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
keys_to_remove.remove_item();
|
||||
}
|
||||
rem_key=(TToken_string *)keys_to_remove.succ_item();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
updated_bal=FALSE;
|
||||
}
|
||||
curr_key=(TToken_string *)keys_to_add.succ_item();
|
||||
}
|
||||
// togli i saldi vecchi
|
||||
curr_key=(TToken_string *)keys_to_remove.first_item();
|
||||
|
||||
while (curr_key) {
|
||||
TArticolo articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
giac_putkey(mag,_annoes,*curr_key);
|
||||
// modifica questo record (e lo sblocca)
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
updated_bal=FALSE;
|
||||
}
|
||||
curr_key=(TToken_string *)keys_to_remove.succ_item();
|
||||
}
|
||||
if (!updated_bal) {
|
||||
// saldi non aggiornati
|
||||
warning_box("I saldi di magazzino non sono stati del tutto aggiornati. \nProcedere ad una operazione di ''Ricostruzione saldi''");
|
||||
}
|
||||
return updated_bal;
|
||||
while (curr_key) {
|
||||
TArticolo articolo(key2field(*curr_key,"CODART"));
|
||||
if (articolo.lock_and_prompt()) {
|
||||
giac_putkey(mag,_annoes,*curr_key);
|
||||
// modifica questo record (e lo sblocca)
|
||||
if (mag.read()==NOERR) {
|
||||
update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1);
|
||||
mag.rewrite();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
updated_bal=FALSE;
|
||||
}
|
||||
curr_key=(TToken_string *)keys_to_remove.succ_item();
|
||||
}
|
||||
if (!updated_bal) {
|
||||
// saldi non aggiornati
|
||||
warning_box("I saldi di magazzino non sono stati del tutto aggiornati. \nProcedere ad una operazione di ''Ricostruzione saldi''");
|
||||
}
|
||||
return updated_bal;
|
||||
}
|
||||
|
||||
// aggiorna i saldi del record corrente
|
||||
// in base alla causale e alla modifica fatta (con segno + o -)
|
||||
int TMov_mag::update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int rett_sign) const
|
||||
{
|
||||
TCausale_magazzino caus(codcaus);
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
real diff,diff_val;
|
||||
umart.setkey(2);
|
||||
umart.put(UMART_CODART,magrec.get(MAG_CODART));
|
||||
umart.put(UMART_UM , l.um);
|
||||
umart.read();
|
||||
real fc=umart.get_real("FC");
|
||||
TCausale_magazzino caus(codcaus);
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
real diff,diff_val;
|
||||
umart.setkey(2);
|
||||
umart.put(UMART_CODART,magrec.get(MAG_CODART));
|
||||
umart.put(UMART_UM , l.um);
|
||||
umart.read();
|
||||
real fc=umart.get_real("FC");
|
||||
|
||||
diff=fc*rett_sign*l.quant;
|
||||
diff_val=rett_sign*l.quant*l.prezzo;
|
||||
update_balance(magrec,"GIAC",diff*caus.sgn(s_giac)); // update ..
|
||||
update_balance(magrec,"ACQ",diff*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"VALACQ",diff_val*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"ENT",diff*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VALENT",diff_val*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VEN",diff*caus.sgn(s_ven));
|
||||
update_balance(magrec,"VALVEN",diff_val*caus.sgn(s_ven));
|
||||
update_balance(magrec,"USC",diff*caus.sgn(s_usc));
|
||||
update_balance(magrec,"VALUSC",diff_val*caus.sgn(s_usc));
|
||||
update_balance(magrec,"ORDC",diff*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"VALORDC",diff_val*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"ORDF",diff*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"VALORDF",diff_val*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"RIM",diff*caus.sgn(s_rim));
|
||||
update_balance(magrec,"VALRIM",diff_val*caus.sgn(s_rim));
|
||||
update_balance(magrec,"SCARTI",diff*caus.sgn(s_scart));
|
||||
update_balance(magrec,"VALSCARTI",diff_val*caus.sgn(s_scart));
|
||||
update_balance(magrec,"INCL",diff*caus.sgn(s_incl));
|
||||
update_balance(magrec,"ACL",diff*caus.sgn(s_acl));
|
||||
update_balance(magrec,"PRODCOMP",diff*caus.sgn(s_prodc));
|
||||
update_balance(magrec,"PRODFIN",diff*caus.sgn(s_prodf));
|
||||
update_balance(magrec,"NLABEL",diff*caus.sgn(s_label));
|
||||
return 0;
|
||||
diff=fc*rett_sign*l.quant;
|
||||
diff_val=rett_sign*l.quant*l.prezzo;
|
||||
update_balance(magrec,"GIAC",diff*caus.sgn(s_giac)); // update ..
|
||||
update_balance(magrec,"ACQ",diff*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"VALACQ",diff_val*caus.sgn(s_acq)); // update ..
|
||||
update_balance(magrec,"ENT",diff*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VALENT",diff_val*caus.sgn(s_ent));
|
||||
update_balance(magrec,"VEN",diff*caus.sgn(s_ven));
|
||||
update_balance(magrec,"VALVEN",diff_val*caus.sgn(s_ven));
|
||||
update_balance(magrec,"USC",diff*caus.sgn(s_usc));
|
||||
update_balance(magrec,"VALUSC",diff_val*caus.sgn(s_usc));
|
||||
update_balance(magrec,"ORDC",diff*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"VALORDC",diff_val*caus.sgn(s_ordc));
|
||||
update_balance(magrec,"ORDF",diff*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"VALORDF",diff_val*caus.sgn(s_ordf));
|
||||
update_balance(magrec,"RIM",diff*caus.sgn(s_rim));
|
||||
update_balance(magrec,"VALRIM",diff_val*caus.sgn(s_rim));
|
||||
update_balance(magrec,"SCARTI",diff*caus.sgn(s_scart));
|
||||
update_balance(magrec,"VALSCARTI",diff_val*caus.sgn(s_scart));
|
||||
update_balance(magrec,"INCL",diff*caus.sgn(s_incl));
|
||||
update_balance(magrec,"ACL",diff*caus.sgn(s_acl));
|
||||
update_balance(magrec,"PRODCOMP",diff*caus.sgn(s_prodc));
|
||||
update_balance(magrec,"PRODFIN",diff*caus.sgn(s_prodf));
|
||||
update_balance(magrec,"NLABEL",diff*caus.sgn(s_label));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1218,68 +1222,68 @@ int TMov_mag::codice_esercizio(TDate &d)
|
||||
//**********************
|
||||
bool rebuild_balances(TString16 annoes, bool reset_giac)
|
||||
{
|
||||
TArray used_files;
|
||||
used_files.add(new TLocalisamfile(LF_RMOVMAG),LF_RMOVMAG);
|
||||
used_files.add(new TLocalisamfile(LF_MOVMAG),LF_MOVMAG);
|
||||
used_files.add(new TTable("CAU"),5);
|
||||
TArray used_files;
|
||||
used_files.add(new TLocalisamfile(LF_RMOVMAG),LF_RMOVMAG);
|
||||
used_files.add(new TLocalisamfile(LF_MOVMAG),LF_MOVMAG);
|
||||
used_files.add(new TTable("CAU"),5);
|
||||
TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino
|
||||
|
||||
// relazione con un solo file (LF_MOVMAG) ma col record Head_Body
|
||||
// relazione con un solo file (LF_MOVMAG) ma col record Head_Body
|
||||
TRelation rel(LF_MOVMAG);
|
||||
rel.lfile().set_curr(m_m);
|
||||
int ok=TRUE;
|
||||
TLocalisamfile mag(LF_MAG);
|
||||
if (reset_giac) {
|
||||
// azzera tutte giacenze (ciclo sulle giacenze)
|
||||
mag.put("ANNOES",annoes);
|
||||
mag.read(_isgteq);
|
||||
while (!mag.eof() && annoes==mag.get("ANNOES"))
|
||||
{
|
||||
TString currcode(mag.get("CODART"));
|
||||
TArticolo articolo(currcode);
|
||||
if (articolo.lock_and_prompt())
|
||||
{
|
||||
while (!mag.eof() && currcode==mag.get("CODART"))
|
||||
{
|
||||
mag.put("ACQ",0);mag.put("VALACQ",0);
|
||||
mag.put("ENT",0);mag.put("VALENT",0);
|
||||
mag.put("VEN",0);mag.put("VALVEN",0);
|
||||
mag.put("USC",0);mag.put("VALUSC",0);
|
||||
mag.put("ORDF",0);mag.put("VALORDF",0);
|
||||
mag.put("ORDC",0);mag.put("VALORDC",0);
|
||||
mag.put("SCARTI",0);mag.put("VALSCARTI",0);
|
||||
mag.put("GIAC",0);
|
||||
mag.put("PRODCOMP",0);
|
||||
mag.put("PRODFIN",0);
|
||||
mag.put("INCL",0);
|
||||
mag.put("ACL",0);
|
||||
mag.put("NLABEL",0);
|
||||
mag.rewrite();
|
||||
mag.next();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
ok=FALSE;
|
||||
mag.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ricostruisce i saldi (ciclo sui movimenti)
|
||||
TString filterexpr;
|
||||
filterexpr << LF_MOVMAG << "->ANNOES==" << annoes;
|
||||
TCursor cur(&rel,filterexpr); // cursore filtrato
|
||||
int ok=TRUE;
|
||||
TLocalisamfile mag(LF_MAG);
|
||||
if (reset_giac) {
|
||||
// azzera tutte giacenze (ciclo sulle giacenze)
|
||||
mag.put("ANNOES",annoes);
|
||||
mag.read(_isgteq);
|
||||
while (!mag.eof() && annoes==mag.get("ANNOES"))
|
||||
{
|
||||
TString currcode(mag.get("CODART"));
|
||||
TArticolo articolo(currcode);
|
||||
if (articolo.lock_and_prompt())
|
||||
{
|
||||
while (!mag.eof() && currcode==mag.get("CODART"))
|
||||
{
|
||||
mag.put("ACQ",0);mag.put("VALACQ",0);
|
||||
mag.put("ENT",0);mag.put("VALENT",0);
|
||||
mag.put("VEN",0);mag.put("VALVEN",0);
|
||||
mag.put("USC",0);mag.put("VALUSC",0);
|
||||
mag.put("ORDF",0);mag.put("VALORDF",0);
|
||||
mag.put("ORDC",0);mag.put("VALORDC",0);
|
||||
mag.put("SCARTI",0);mag.put("VALSCARTI",0);
|
||||
mag.put("GIAC",0);
|
||||
mag.put("PRODCOMP",0);
|
||||
mag.put("PRODFIN",0);
|
||||
mag.put("INCL",0);
|
||||
mag.put("ACL",0);
|
||||
mag.put("NLABEL",0);
|
||||
mag.rewrite();
|
||||
mag.next();
|
||||
}
|
||||
articolo.unlock();
|
||||
} else {
|
||||
ok=FALSE;
|
||||
mag.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ricostruisce i saldi (ciclo sui movimenti)
|
||||
TString filterexpr;
|
||||
filterexpr << LF_MOVMAG << "->ANNOES==" << annoes;
|
||||
TCursor cur(&rel,filterexpr); // cursore filtrato
|
||||
|
||||
for (int i=0; i<cur.objects(); i++)
|
||||
{
|
||||
cur=i;
|
||||
TMov_mag & mov_rec=(TMov_mag &)cur.file().curr();
|
||||
if (!mov_rec.force_update_bal())
|
||||
ok=FALSE;
|
||||
}
|
||||
for (int i=0; i<cur.objects(); i++)
|
||||
{
|
||||
cur=i;
|
||||
TMov_mag & mov_rec=(TMov_mag &)cur.file().curr();
|
||||
if (!mov_rec.force_update_bal())
|
||||
ok=FALSE;
|
||||
}
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user