Patch level : 12.0 988

Files correlati     : mg1.exe
Commento            :

Corretta ricostruzione saldi nel caso di un record di magazzino che non esisteva
This commit is contained in:
Alessandro Bonazzi 2020-08-12 14:31:44 +02:00
parent 4269035bf9
commit ec5546c047
2 changed files with 50 additions and 49 deletions

View File

@ -9,7 +9,7 @@
#include <progind.h>
#include "mglib.h"
#include "../cg/cglib01.h"
#include "../cg/cglib.h"
#include "../ve/veconf.h"
#include "anamag.h"

View File

@ -10,7 +10,7 @@
#include "clifogiac.h"
#include <cfven.h>
#include "../cg/cglib01.h"
#include "../cg/cglib.h"
#include "../db/dblib.h"
void update_balance(TRectype& rec, const char* fieldname, const real& val, const int sgn)
@ -570,7 +570,7 @@ bool TMov_mag::add_autorows() const
if (codmag.not_empty())
linea_auto->put(RMOVMAG_CODMAG, codmag);
const char * prezzo = prezzo_rauto(r);
if (prezzo != NULL)
if (prezzo != nullptr)
linea_auto->put(RMOVMAG_PREZZO, prezzo);
linea_auto->put(RMOVMAG_NRIG, r+1);
linea_auto->put(RMOVMAG_TIPORIGA, (char) riga_automatica);
@ -759,7 +759,7 @@ void TMov_mag::add_saldi(const bool plus)
TToken_string & key_mag = TSaldo_mag::key(*this, rec);
TSaldo_mag * s_mag = (TSaldo_mag*)(__cache_saldi ? __saldi_mag.objptr(key_mag) : _saldi_mag.objptr(key_mag));
if (s_mag == NULL)
if (s_mag == nullptr)
{
s_mag = new TSaldo_mag(*this, rec);
if (__cache_saldi)
@ -772,7 +772,7 @@ void TMov_mag::add_saldi(const bool plus)
const TCausale_magazzino& caus = causale(i);
TArticolo & art = articolo(i);
quant =art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
quant =art.convert_to_um(quant, EMPTY_STRING, rec.get(RMOVMAG_UM));
real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
@ -783,7 +783,7 @@ void TMov_mag::add_saldi(const bool plus)
TToken_string & key_clifo = TSaldo_mag_clifo::key(*this, rec);
TSaldo_mag_clifo * s_clifo = (TSaldo_mag_clifo*)(__cache_saldi ? __saldi_mag_clifo.objptr(key_clifo) : _saldi_mag_clifo.objptr(key_clifo));
if (s_clifo == NULL)
if (s_clifo == nullptr)
{
s_clifo = new TSaldo_mag_clifo(*this, rec);
if (__cache_saldi)
@ -838,7 +838,7 @@ bool TMov_mag::update_balances(bool lock)
const TRectype& rec = b[i];
TArticolo& art = articolo(i);
const real prezzo = art.convert_to_um(rec.get_real(RMOVMAG_PREZZO), NULL, rec.get(RMOVMAG_UM), false);
const real prezzo = art.convert_to_um(rec.get_real(RMOVMAG_PREZZO), EMPTY_STRING, rec.get(RMOVMAG_UM), false);
const long numreg = get_long(MOVMAG_NUMREG);
art.set_nuovo(false);
@ -913,7 +913,7 @@ bool TMov_mag::update_balances(bool lock)
TProgress_monitor pi(keys_clifo.items(), msg, false);
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
curr_key != nullptr; curr_key = (TToken_string*)keys_clifo.succ_item())
{
TSaldo_mag_clifo & saldo=(TSaldo_mag_clifo &)_saldi_mag_clifo[*curr_key];
const TCodice_articolo& codart = saldo.codart();
@ -963,7 +963,7 @@ void TMov_mag::update_balances(TRectype& magrec, int numrig, bool plus)
TArticolo& art = articolo(numrig);
real quant = rec.get_real(RMOVMAG_QUANT);
quant = art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
quant = art.convert_to_um(quant, EMPTY_STRING, rec.get(RMOVMAG_UM));
const real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
@ -979,7 +979,7 @@ void TMov_mag::update_balances_clifo(TRectype& cliforec, int numrig, bool plus)
const TCausale_magazzino& caus = cached_causale_magazzino(saldo.codcaus());
TArticolo & art = articolo(numrig);
quant = art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
quant = art.convert_to_um(quant, EMPTY_STRING, rec.get(RMOVMAG_UM));
real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
@ -1155,12 +1155,13 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
const char* catven, const char* codlis)
{
TSystemisamfile a(LF_MOVMAG);
if (a.open(_excllock) != NOERR)
return false;
const TEsercizi_contabili& esc = esercizi();
TBalance_params p;
p.codes = codes;
p.codesprec = esc.pred(codes);
p.closed = p.codesprec <= 0 || esc[p.codesprec].chiusura_mag().ok();
@ -1170,6 +1171,7 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
p.tipov = tipo_valorizz;
TString msg;
{
// azzera tutte giacenze (ciclo sulle giacenze)
TRelation anamag_rel(LF_ANAMAG);
@ -1194,22 +1196,7 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
msg.format(FR("Ricostruzione saldi esercizio %04d: ricalcolo dotazione iniziale..."), codes);
c.scan(rel_reset_newclifogiac, (void*)&p, msg);
}
// Compattamento giacenze dopo cancellazione
{
//prefix().close_closeable_isamfiles(); // Altrimenti segnala -69 durante la pack
// TSystemisamfile mag(LF_MAG);
// mag.pack(true, true);
/* Mi da sempre errore di compattamento
if (p.codesprec > 0)
{
TSystemisamfile clifogiac(LF_CLIFOGIAC);
clifogiac.pack(true, true);
}
*/
}
// ricostruisce i saldi (ciclo sui movimenti)
bool ok = true;
{
@ -1230,7 +1217,7 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
if (__cache_saldi && __saldi_mag.items() > 0)
{
TFast_isamfile mag(LF_MAG);
TRectype& magcurr = mag.curr();
TRectype& mag_curr = mag.curr();
TString_array keys_mag;
mag.setkey(2);
@ -1244,22 +1231,33 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
{
const TSaldo_mag& saldo = (const TSaldo_mag&)__saldi_mag[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza& art = cached_article_balances(codart);
saldo.putkey(magcurr);
if (magcurr.read(mag, _isequal) != NOERR)
{
TRecord_array& sld = art.mag(saldo.codes());
const int nriga = sld.rows() + 1;
saldo.putkey(mag_curr);
saldo.putkey(magcurr);
magcurr.put(MAG_NRIGA, nriga);
sld.add_row(magcurr);
int err = mag.write();
CHECKD(err == NOERR, "Errore di write:", err);
int readerr = mag_curr.read(mag, _isequal);
if (readerr != NOERR)
{
mag.setkey(1);
saldo.putkey(mag_curr);
mag_curr.put(MAG_NRIGA, 999);
if (mag.read(_isgteq) == NOERR)
mag.prev();
int nriga = 1;
if (mag_curr.get_int(MAG_ANNOES) == saldo.codes() &&
mag_curr.get(MAG_CODART) == saldo.codart())
nriga = mag_curr.get_int(MAG_NRIGA) + 1;
saldo.putkey(mag_curr);
mag_curr.put(MAG_NRIGA, nriga);
const int err = mag.write();
CHECKD(err == NOERR, "Mag : Errore di write:", err);
mag.setkey(2);
}
saldo.update_record(magcurr);
saldo.update_record(mag_curr);
if (mag.rewrite() != NOERR)
ok = false;
pi.add_status();
@ -1280,11 +1278,10 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
TProgress_monitor pi(keys_clifo.items(), msg, false);
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
curr_key != nullptr; curr_key = (TToken_string*)keys_clifo.succ_item())
{
TSaldo_mag_clifo & saldo = (TSaldo_mag_clifo &)__saldi_mag_clifo[*curr_key];
const TCodice_articolo& codart = saldo.codart();
TArticolo_giacenza & art = cached_article_balances(codart);
saldo.putkey(clifomag_curr);
if (clifomag.read(_isequal) != NOERR)
@ -1295,18 +1292,22 @@ bool rebuild_balances(int codes, const TTipo_valorizz tipo_valorizz,
clifomag_curr.put(CLIFOGIAC_NRIGA, 999);
if (clifomag.read(_isgteq) == NOERR)
clifomag.prev();
saldo.putkey(clifomag_curr);
int nriga = 1;
if (clifomag_curr.get_int(CLIFOGIAC_ANNOES) == saldo.codes() &&
clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart() &&
clifomag_curr.get(CLIFOGIAC_LIVELLO) == saldo.livello())
clifomag_curr.get_char(CLIFOGIAC_TIPOCF) == saldo.tipocf() &&
clifomag_curr.get(CLIFOGIAC_CODCF) == saldo.codcf() &&
clifomag_curr.get(CLIFOGIAC_INDSPED) == saldo.codindsp() &&
clifomag_curr.get(CLIFOGIAC_CODART) == saldo.codart())
nriga = clifomag_curr.get_int(CLIFOGIAC_NRIGA) + 1;
clifomag_curr.put(CLIFOGIAC_NRIGA, nriga);
clifomag.write();
const int err = clifomag.write();
CHECKD(err == NOERR, "Clifomag : Errore di write:", err);
clifomag.setkey(2);
}
saldo.update_record(clifomag_curr);