1998-08-25 18:07:30 +00:00
|
|
|
|
// oggetto TCausale_magazzino
|
|
|
|
|
// oggetto TMov_Mag , multirecord del movimento di magazzino
|
2009-03-27 10:40:23 +00:00
|
|
|
|
// funzione di ricostruzione saldi
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2004-05-18 10:44:57 +00:00
|
|
|
|
#include <diction.h>
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#include <progind.h>
|
2008-10-07 00:50:22 +00:00
|
|
|
|
#include <recset.h>
|
|
|
|
|
#include <utility.h>
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
#include "clifogiac.h"
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#include "mglib.h"
|
|
|
|
|
#include "movmag.h"
|
2001-05-02 13:40:49 +00:00
|
|
|
|
#include <cfven.h>
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
|
|
#ifndef __CGLIB01_H
|
1999-10-22 10:00:18 +00:00
|
|
|
|
#include "../cg/cglib01.h"
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef __DBLIB_H
|
1999-10-22 10:00:18 +00:00
|
|
|
|
#include "../db/dblib.h"
|
1998-08-25 18:07:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
class TSaldo_mag : public TObject
|
|
|
|
|
{
|
|
|
|
|
int _codes;
|
|
|
|
|
TString8 _codmag;
|
|
|
|
|
TCodice_articolo _codart;
|
|
|
|
|
TString16 _livello;
|
|
|
|
|
TString8 _codcaus;
|
|
|
|
|
real _quant;
|
|
|
|
|
real _valore;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
const int codes() const { return _codes;}
|
|
|
|
|
const TString& codmag() const { return _codmag; }
|
|
|
|
|
const TCodice_articolo & codart() const { return _codart; }
|
|
|
|
|
const TString& livello() const { return _livello; }
|
|
|
|
|
const TString& codcaus() const { return _codcaus; }
|
|
|
|
|
const real& quant() const { return _quant; }
|
|
|
|
|
const real& valore() const { return _valore; }
|
|
|
|
|
void set(int codes, const char * codmag, const char * codart, const char * livello, const char * codcaus);
|
|
|
|
|
int operator==(const TSaldo_mag&) const;
|
|
|
|
|
|
|
|
|
|
virtual TObject* dup() const { return new TSaldo_mag(*this); }
|
|
|
|
|
|
|
|
|
|
bool is_deletable() const { return _quant == ZERO && _valore == ZERO; }
|
|
|
|
|
static TToken_string & key(const TRectype & head, const TRectype & row);
|
|
|
|
|
void add_quant(const real & q, bool plus = true) { _quant = _quant + (plus ? q : -q); }
|
|
|
|
|
void add_valore(const real & v, bool plus = true) { _valore = _valore + (plus ? v : -v); }
|
|
|
|
|
void add(const real & q, const real & v, bool plus = true) { add_quant(q, plus); add_valore(v, plus); }
|
|
|
|
|
void sub_quant(const real & q) { add_quant(q, false); }
|
|
|
|
|
void sub_valore(const real & v) { add_valore(v, false); }
|
|
|
|
|
void sub(const real & q, const real & v) { add(q, v, false); }
|
|
|
|
|
|
|
|
|
|
TSaldo_mag(int codes, const char * codmag, const char * codart, const char * livello, const char * codcaus) {set(codes, codmag, codart, livello, codcaus);}
|
|
|
|
|
TSaldo_mag(const TRectype & head, const TRectype & row);
|
|
|
|
|
TSaldo_mag(const TSaldo_mag & s);
|
|
|
|
|
virtual ~TSaldo_mag() {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TSaldo_mag::set(int codes, const char * codmag, const char * codart, const char * livello, const char * codcaus)
|
|
|
|
|
{
|
|
|
|
|
_codes = codes;
|
|
|
|
|
_codmag = codmag;
|
|
|
|
|
_codart = codart;
|
|
|
|
|
_livello = livello;
|
|
|
|
|
_codcaus = codcaus;
|
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
int TSaldo_mag::operator==(const TSaldo_mag & s) const
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
return (_codes == s._codes) &&
|
|
|
|
|
(_codmag == s._codmag) &&
|
|
|
|
|
(_codart == s._codart) &&
|
|
|
|
|
(_livello == s._livello) &&
|
|
|
|
|
(_codcaus == s._codcaus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TToken_string & TSaldo_mag::key(const TRectype & head, const TRectype & row)
|
|
|
|
|
{
|
|
|
|
|
TToken_string& key = get_tmp_string();
|
|
|
|
|
|
|
|
|
|
key.add(head.get_int(MOVMAG_ANNOES));
|
|
|
|
|
key.add(row.get(RMOVMAG_CODMAG));
|
|
|
|
|
key.add(row.get(RMOVMAG_CODART));
|
|
|
|
|
key.add(row.get(RMOVMAG_LIVGIAC));
|
|
|
|
|
const TString & c = row.get(RMOVMAG_CODCAUS);
|
|
|
|
|
key.add(c.full() ? c : head.get(MOVMAG_CODCAUS));
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSaldo_mag::TSaldo_mag(const TRectype & head, const TRectype & row)
|
|
|
|
|
{
|
|
|
|
|
_codes = head.get_int(MOVMAG_ANNOES);
|
|
|
|
|
_codmag = row.get(RMOVMAG_CODMAG);
|
|
|
|
|
_codart = row.get(RMOVMAG_CODART);
|
|
|
|
|
_livello = row.get(RMOVMAG_LIVGIAC);
|
|
|
|
|
_codcaus = row.get(RMOVMAG_CODCAUS);
|
|
|
|
|
if (_codcaus.blank())
|
|
|
|
|
_codcaus = head.get(MOVMAG_CODCAUS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSaldo_mag::TSaldo_mag(const TSaldo_mag & s)
|
|
|
|
|
{
|
|
|
|
|
set(s._codes, s._codmag, s._codart, s._livello, s._codcaus);
|
|
|
|
|
_quant = s._quant;
|
|
|
|
|
_valore = s._valore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TSaldo_mag_clifo : public TObject
|
|
|
|
|
{
|
|
|
|
|
int _codes;
|
|
|
|
|
char _tipocf;
|
|
|
|
|
TString8 _codcf;
|
|
|
|
|
int _codindsp;
|
|
|
|
|
TCodice_articolo _codart;
|
|
|
|
|
TString16 _livello;
|
|
|
|
|
TString8 _codcaus;
|
|
|
|
|
real _quant;
|
|
|
|
|
real _valore;
|
1999-04-26 15:58:05 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
public:
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const int codes() const { return _codes;}
|
|
|
|
|
const char tipocf() const { return _tipocf;}
|
|
|
|
|
const TString& codcf() const { return _codcf; }
|
|
|
|
|
const int codindsp() const { return _codindsp;}
|
|
|
|
|
const TCodice_articolo & codart() const { return _codart; }
|
|
|
|
|
const TString& livello() const { return _livello; }
|
|
|
|
|
const TString& codcaus() const { return _codcaus; }
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const real& quant() const { return _quant; }
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const real& valore() const { return _valore; }
|
|
|
|
|
void set(int codes, char tipocf, const char * codcf, int codindsp, const char * codart, const char * livello, const char * codcaus);
|
|
|
|
|
int operator==(const TSaldo_mag_clifo&) const;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
virtual TObject* dup() const { return new TSaldo_mag_clifo(*this); }
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
bool is_deletable() const { return _quant == ZERO && _valore == ZERO; }
|
|
|
|
|
static TToken_string & key(const TRectype & head, const TRectype & row);
|
|
|
|
|
void add_quant(const real & q, bool plus = true) { _quant = _quant + (plus ? q : -q); }
|
|
|
|
|
void add_valore(const real & v, bool plus = true) { _valore = _valore + (plus ? v : -v); }
|
|
|
|
|
void add(const real & q, const real & v, bool plus = true) { add_quant(q, plus); add_valore(v, plus); }
|
|
|
|
|
void sub_quant(const real & q) { add_quant(q, false); }
|
|
|
|
|
void sub_valore(const real & v) { add_valore(v, false); }
|
|
|
|
|
void sub(const real & q, const real & v) { add(q, v, false); }
|
|
|
|
|
|
|
|
|
|
TSaldo_mag_clifo(int codes, char tipocf, const char * codcf, int codindsp, const char * codart, const char * livello, const char * codcaus);
|
|
|
|
|
TSaldo_mag_clifo(const TRectype & head, const TRectype & row);
|
|
|
|
|
TSaldo_mag_clifo(const TSaldo_mag_clifo & s);
|
|
|
|
|
virtual ~TSaldo_mag_clifo() {};
|
1998-08-25 18:07:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
void TSaldo_mag_clifo::set(int codes, char tipocf, const char * codcf, int codindsp, const char * codart, const char * livello, const char * codcaus)
|
|
|
|
|
{
|
|
|
|
|
_codes = codes;
|
|
|
|
|
_tipocf = tipocf;
|
|
|
|
|
_codcf = codcf;
|
|
|
|
|
_codart = codart;
|
|
|
|
|
_codindsp = codindsp;
|
|
|
|
|
_codart = codart;
|
|
|
|
|
_livello = livello;
|
|
|
|
|
_codcaus = codcaus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TSaldo_mag_clifo::operator==(const TSaldo_mag_clifo & s) const
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
return (_codes == s._codes) &&
|
|
|
|
|
(_tipocf == s._tipocf) &&
|
|
|
|
|
(_codcf == s._codcf) &&
|
|
|
|
|
(_codindsp == s._codindsp) &&
|
|
|
|
|
(_codart == s._codart) &&
|
|
|
|
|
(_livello == s._livello) &&
|
|
|
|
|
(_codcaus == s._codcaus);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TToken_string & TSaldo_mag_clifo::key(const TRectype & head, const TRectype & row)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TToken_string& key = get_tmp_string();
|
|
|
|
|
|
|
|
|
|
key.add(head.get_int(MOVMAG_ANNOES));
|
|
|
|
|
key.add(head.get(MOVMAG_TIPOCF));
|
|
|
|
|
key.add(head.get(MOVMAG_CODCF));
|
|
|
|
|
key.add(head.get_int(MOVMAG_CODINDSP));
|
|
|
|
|
key.add(row.get(RMOVMAG_CODART));
|
|
|
|
|
key.add(row.get(RMOVMAG_LIVGIAC));
|
|
|
|
|
const TString & c = row.get(RMOVMAG_CODCAUS);
|
|
|
|
|
key.add(c.full() ? c : head.get(MOVMAG_CODCAUS));
|
|
|
|
|
return key;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TSaldo_mag_clifo::TSaldo_mag_clifo(const TRectype & head, const TRectype & row)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
_codes = head.get_int(MOVMAG_ANNOES);
|
|
|
|
|
_tipocf = head.get_char(MOVMAG_TIPOCF);
|
|
|
|
|
_codcf = head.get(MOVMAG_CODCF);
|
|
|
|
|
_codindsp = head.get_int(MOVMAG_CODINDSP);
|
|
|
|
|
_codart = row.get(RMOVMAG_CODART);
|
|
|
|
|
_livello = row.get(RMOVMAG_LIVGIAC);
|
|
|
|
|
_codcaus = row.get(RMOVMAG_CODCAUS);
|
|
|
|
|
if (_codcaus.blank())
|
|
|
|
|
_codcaus = head.get(MOVMAG_CODCAUS);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TSaldo_mag_clifo::TSaldo_mag_clifo(const TSaldo_mag_clifo & s)
|
|
|
|
|
{
|
|
|
|
|
set(s._codes, s._tipocf, s._codcf, s._codindsp, s._codart, s._livello, s._codcaus);
|
|
|
|
|
_quant = s._quant;
|
|
|
|
|
_valore = s._valore;
|
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
|
|
// ********************************
|
|
|
|
|
// TMov_mag
|
|
|
|
|
|
|
|
|
|
TMov_mag::TMov_mag() :
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TMultiple_rectype(LF_MOVMAG)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
|
|
|
|
add_file(LF_RMOVMAG,"NRIG");
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-11 10:25:25 +00:00
|
|
|
|
TMov_mag::TMov_mag(long numreg) :
|
|
|
|
|
TMultiple_rectype(LF_MOVMAG)
|
|
|
|
|
{
|
|
|
|
|
add_file(LF_RMOVMAG,"NRIG");
|
|
|
|
|
TLocalisamfile movmag(LF_MOVMAG);
|
|
|
|
|
put(MOVMAG_NUMREG, numreg);
|
|
|
|
|
read(movmag);
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
TMov_mag::~TMov_mag()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TCausale_magazzino& TMov_mag::causale(int row) const
|
1999-04-16 12:02:04 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TRectype & rowrec = body()[row];
|
|
|
|
|
TString8 cod(rowrec.get(RMOVMAG_CODCAUS));
|
|
|
|
|
|
|
|
|
|
if (cod.blank())
|
1999-04-16 12:02:04 +00:00
|
|
|
|
cod = get(MOVMAG_CODCAUS);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
return cached_causale_magazzino(cod);
|
1999-04-16 12:02:04 +00:00
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
|
|
void TMov_mag::zero(char c)
|
|
|
|
|
{
|
|
|
|
|
TMultiple_rectype::zero(c);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
_saldi_mag.destroy();
|
|
|
|
|
_saldi_mag_clifo.destroy();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// valuta il valore della chiave per un nuovo record
|
|
|
|
|
bool TMov_mag::renum()
|
|
|
|
|
{
|
|
|
|
|
put(MOVMAG_NUMREG,get_next_key());
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copia la chiave dal file principale a quello delle righe
|
|
|
|
|
void TMov_mag::set_body_key(TRectype & rowrec)
|
|
|
|
|
{
|
|
|
|
|
rowrec.put(RMOVMAG_NUMREG,get(MOVMAG_NUMREG));
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
/*void TMov_mag::load_rows_file(int logicnum)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
1999-04-16 12:02:04 +00:00
|
|
|
|
CHECK(logicnum==LF_RMOVMAG,"L'unico file collegabile ai movimenti sono le righe");
|
|
|
|
|
TMultiple_rectype::load_rows_file(logicnum);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
int TMov_mag::read(TBaseisamfile& f, word op, word lockop)
|
|
|
|
|
{
|
|
|
|
|
_saldi_mag.destroy();
|
|
|
|
|
_saldi_mag_clifo.destroy();
|
|
|
|
|
|
|
|
|
|
const int err = TMultiple_rectype::read(f, op, lockop);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
add_saldi(false);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
int TMov_mag::remove(TBaseisamfile& f) const
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const int res = TMultiple_rectype::remove(f);
|
|
|
|
|
if (res == NOERR)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
((TMov_mag *)this)->update_balances();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TMov_mag::add_extrarows() const
|
|
|
|
|
{
|
|
|
|
|
add_autorows();
|
1999-10-22 10:00:18 +00:00
|
|
|
|
add_explrows();
|
|
|
|
|
// if (add_explrows())
|
|
|
|
|
// add_autorows();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
1999-04-16 12:02:04 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool TMov_mag::add_autorows() const
|
|
|
|
|
{
|
|
|
|
|
bool added=FALSE;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString8 codmag;
|
1999-04-16 12:02:04 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// aggiunge le righe automatiche
|
|
|
|
|
for (int r = rows(); r > 0; r--)
|
|
|
|
|
{
|
|
|
|
|
TRecord_array & b = body();
|
|
|
|
|
TRectype & row = b[r];
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TCausale_magazzino& cau = causale(r);
|
|
|
|
|
const TString& codcaus = cau.caus_collegata();
|
|
|
|
|
|
|
|
|
|
if (codcaus.not_empty())
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TCausale_magazzino& cau_coll = cached_causale_magazzino(codcaus);
|
|
|
|
|
|
|
|
|
|
if (!row.get_bool(RMOVMAG_ESPLOSA))
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
|
|
|
|
// deve esserci una riga collegata
|
|
|
|
|
if (!b.exist(r + 1) || b[r + 1].get_char(RMOVMAG_TIPORIGA) != riga_automatica)
|
|
|
|
|
{
|
|
|
|
|
// manca, la inserisco
|
|
|
|
|
TRectype * linea_auto = new TRectype(row);
|
1999-04-16 12:02:04 +00:00
|
|
|
|
|
|
|
|
|
codmag = codmag_rauto(r);
|
|
|
|
|
if (codmag.empty())
|
|
|
|
|
codmag = cau_coll.default_magdep();
|
|
|
|
|
if (codmag.not_empty())
|
1998-08-25 18:07:30 +00:00
|
|
|
|
linea_auto->put(RMOVMAG_CODMAG, codmag);
|
|
|
|
|
const char * prezzo = prezzo_rauto(r);
|
|
|
|
|
if (prezzo != NULL)
|
|
|
|
|
linea_auto->put(RMOVMAG_PREZZO, prezzo);
|
|
|
|
|
linea_auto->put(RMOVMAG_NRIG, r+1);
|
|
|
|
|
linea_auto->put(RMOVMAG_TIPORIGA, (char) riga_automatica);
|
|
|
|
|
linea_auto->put(RMOVMAG_CODCAUS, codcaus);
|
|
|
|
|
b.insert_row(linea_auto);
|
|
|
|
|
added=TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // ciclo righe
|
|
|
|
|
return added;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMov_mag::add_explrows() const
|
|
|
|
|
{
|
|
|
|
|
TDistinta_tree distinta;
|
|
|
|
|
TArray boom;
|
|
|
|
|
bool added=FALSE;
|
1999-04-16 12:02:04 +00:00
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TRecord_array& b = body();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// aggiunge le righe da explosione distinta
|
|
|
|
|
for (int r = rows(); r > 0; r--)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TRectype& row = b[r];
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TCausale_magazzino& cau = causale(r);
|
|
|
|
|
|
|
|
|
|
if (cau.esplodente() && !row.get_bool(RMOVMAG_ESPLOSA))
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TCodice_articolo codart = row.get(RMOVMAG_CODART);
|
1999-06-18 15:35:05 +00:00
|
|
|
|
const char tipo_costo = cau.get("S11")[0];
|
|
|
|
|
const int livello = cau.get_int("I0");
|
|
|
|
|
const TString4 umroot(row.get(RMOVMAG_UM));
|
2001-05-02 13:40:49 +00:00
|
|
|
|
const int rigaprec = r - 1;
|
|
|
|
|
const bool is_coll = r > 0 && b[r].get_char(RMOVMAG_TIPORIGA) == riga_automatica;
|
1999-06-18 15:35:05 +00:00
|
|
|
|
// mancano le righe, le inserisco
|
|
|
|
|
boom.destroy();
|
|
|
|
|
bool ok=distinta.set_root(row);
|
|
|
|
|
if (ok)
|
2000-05-05 15:25:49 +00:00
|
|
|
|
{
|
|
|
|
|
bool stop_prod = cau.get_bool("B4");
|
|
|
|
|
|
|
|
|
|
distinta.explode(boom, TRUE, RAGGR_EXP_NONE, livello, "A", 0, stop_prod);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
//TString codmag(codmag_rauto(r));
|
1999-06-18 15:35:05 +00:00
|
|
|
|
real prezzo(prezzo_rauto(r));
|
|
|
|
|
TRectype * linea_auto;
|
|
|
|
|
for (int newrow=0; newrow < boom.items() ; newrow++)
|
2001-05-02 13:40:49 +00:00
|
|
|
|
{
|
1999-06-18 15:35:05 +00:00
|
|
|
|
TRiga_esplosione & riga_esp=(TRiga_esplosione & )(boom[newrow]);
|
|
|
|
|
linea_auto = new TRectype(row);
|
|
|
|
|
linea_auto->put(RMOVMAG_CODART, riga_esp.articolo());
|
2004-06-08 14:59:25 +00:00
|
|
|
|
linea_auto->put(RMOVMAG_LIVGIAC, riga_esp.giacenza());
|
1999-06-18 15:35:05 +00:00
|
|
|
|
linea_auto->put(RMOVMAG_UM, riga_esp.um());
|
|
|
|
|
linea_auto->put(RMOVMAG_QUANT, riga_esp.val());
|
2009-11-16 13:45:51 +00:00
|
|
|
|
linea_auto->put(RMOVMAG_CODCAUS, cau.codice());
|
1999-10-22 10:00:18 +00:00
|
|
|
|
//if (codmag.not_empty())
|
|
|
|
|
// linea_auto->put(RMOVMAG_CODMAG, codmag);
|
1999-06-18 15:35:05 +00:00
|
|
|
|
//if (!prezzo.is_zero())
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TArticolo & articolo = cached_article(riga_esp.articolo());
|
1999-06-18 15:35:05 +00:00
|
|
|
|
if (tipo_costo == 'U')
|
|
|
|
|
prezzo = articolo.get_real(ANAMAG_ULTCOS1);
|
|
|
|
|
else
|
|
|
|
|
if (tipo_costo == 'S')
|
|
|
|
|
prezzo = articolo.get_real(ANAMAG_COSTSTD);
|
|
|
|
|
linea_auto->put(RMOVMAG_PREZZO, prezzo);
|
|
|
|
|
linea_auto->put(RMOVMAG_NRIG, r+1+newrow);
|
|
|
|
|
linea_auto->put(RMOVMAG_ESPLOSA, TRUE);
|
2001-05-02 13:40:49 +00:00
|
|
|
|
|
|
|
|
|
char coll_type = articolo.get_char(ANAMAG_COLLTYPE);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString8 codmag;
|
2001-05-02 13:40:49 +00:00
|
|
|
|
|
|
|
|
|
if (coll_type == 'M')
|
|
|
|
|
{
|
|
|
|
|
if (is_coll)
|
|
|
|
|
codmag = b[rigaprec].get(RMOVMAG_CODMAG);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (coll_type == 'F')
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString16 key("F|");
|
2001-05-02 13:40:49 +00:00
|
|
|
|
key << articolo.get(ANAMAG_CODFORN);
|
|
|
|
|
codmag = cache().get(LF_CFVEN, key, CFV_CODMAG);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (coll_type == 'A')
|
|
|
|
|
codmag = articolo.get(ANAMAG_CODMAG);
|
|
|
|
|
if (codmag.not_empty())
|
|
|
|
|
linea_auto->put(RMOVMAG_CODMAG, codmag);
|
1999-06-18 15:35:05 +00:00
|
|
|
|
b.insert_row(linea_auto);
|
|
|
|
|
added=TRUE;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
// ora ci sono, mi basta eliminare la riga "padre"
|
|
|
|
|
if (boom.items() > 0 )
|
|
|
|
|
{
|
|
|
|
|
if (boom.items() == 1 && codart == ((TRiga_esplosione &)boom[0]).articolo())
|
2004-05-18 10:44:57 +00:00
|
|
|
|
error_box(FR("Movimento di magazzino %ld:\ndistinta %s ciclica"), get_long(MOVMAG_NUMREG),(const char *)codart);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
b.destroy_row(r,TRUE);
|
|
|
|
|
}
|
|
|
|
|
else
|
2004-05-18 10:44:57 +00:00
|
|
|
|
message_box(FR("Movimento di magazzino %ld:\nimpossibile esplodere l'articolo %s"), get_long(MOVMAG_NUMREG),(const char *)codart);
|
1999-06-18 15:35:05 +00:00
|
|
|
|
}
|
2008-08-27 11:13:47 +00:00
|
|
|
|
else
|
|
|
|
|
if (b[r].get_char(RMOVMAG_TIPORIGA) == riga_automatica)
|
|
|
|
|
b.destroy_row(r,TRUE);
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
} // ciclo righe
|
|
|
|
|
return added;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TMov_mag::write(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
add_extrarows();
|
|
|
|
|
if ((res=TMultiple_rectype::write(f))==NOERR )
|
1999-04-16 12:02:04 +00:00
|
|
|
|
{
|
|
|
|
|
TMov_mag &myself=((TMov_mag &)*this);
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
myself.add_saldi();
|
|
|
|
|
myself.update_balances();
|
|
|
|
|
myself.add_saldi(false);
|
1999-04-16 12:02:04 +00:00
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TMov_mag::rewrite(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
add_extrarows();
|
|
|
|
|
if ((res=TMultiple_rectype::rewrite(f))==NOERR )
|
1999-04-16 12:02:04 +00:00
|
|
|
|
{
|
|
|
|
|
TMov_mag &myself=((TMov_mag &)*this);
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
myself.add_saldi();
|
1999-04-16 12:02:04 +00:00
|
|
|
|
myself.update_balances();
|
2008-10-07 00:50:22 +00:00
|
|
|
|
myself.add_saldi(false);
|
1999-04-16 12:02:04 +00:00
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-16 12:02:04 +00:00
|
|
|
|
const char* TMov_mag::get_next_key()
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
|
|
|
|
TLocalisamfile f(LF_MOVMAG);
|
|
|
|
|
f.last();
|
1999-04-16 12:02:04 +00:00
|
|
|
|
long a = f.get_long(MOVMAG_NUMREG)+1;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString& nextcod = get_tmp_string();
|
|
|
|
|
nextcod.format("%ld", a);
|
|
|
|
|
return nextcod;
|
1999-04-16 12:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMov_mag::key_complete()
|
|
|
|
|
{
|
|
|
|
|
const bool ok = head().get_long(MOVMAG_NUMREG) > 0L;
|
|
|
|
|
return ok;
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*******
|
|
|
|
|
// gestione delle variazione dei saldi
|
|
|
|
|
//
|
|
|
|
|
//
|
2008-10-07 00:50:22 +00:00
|
|
|
|
bool TMov_mag::force_update_bal()
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
|
|
|
|
// reset delle strutture per il controlli delle variazioni dei saldi
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TRecord_array & b = body();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
_saldi_mag.destroy();
|
|
|
|
|
_saldi_mag_clifo.destroy();
|
|
|
|
|
add_saldi();
|
|
|
|
|
return update_balances(false);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-14 00:40:30 +00:00
|
|
|
|
void TMov_mag::renum_mov(const long numreg)
|
|
|
|
|
{
|
|
|
|
|
put(MOVMAG_NUMREG, numreg);
|
|
|
|
|
renum_key();
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
// restituisce il valore dei dati
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
void TMov_mag::add_saldi(const bool plus)
|
1999-04-16 12:02:04 +00:00
|
|
|
|
{
|
2008-08-27 11:13:47 +00:00
|
|
|
|
const TRecord_array& b = body();
|
|
|
|
|
|
2008-06-11 10:58:17 +00:00
|
|
|
|
for (int i = b.last_row(); i > 0; i = b.pred_row(i))
|
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TRectype & rec = b[i];
|
|
|
|
|
TToken_string & key_mag = TSaldo_mag::key(*this, rec);
|
|
|
|
|
TSaldo_mag * s_mag = (TSaldo_mag*) _saldi_mag.objptr(key_mag);
|
|
|
|
|
|
|
|
|
|
if (s_mag == NULL)
|
|
|
|
|
{
|
|
|
|
|
s_mag = new TSaldo_mag(*this, rec);
|
|
|
|
|
_saldi_mag.add(key_mag, s_mag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real quant = rec.get_real(RMOVMAG_QUANT);
|
|
|
|
|
const TCausale_magazzino& caus = causale(i);
|
|
|
|
|
TArticolo & art = articolo(i);
|
|
|
|
|
|
|
|
|
|
quant =art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
|
|
|
|
|
|
|
|
|
|
real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
|
|
|
|
|
|
|
|
|
|
s_mag->add(quant, valore, plus);
|
|
|
|
|
|
|
|
|
|
if (caus.aggiorna_clifo()&& get_long(MOVMAG_CODCF) > 0L)
|
|
|
|
|
{
|
|
|
|
|
TToken_string & key_clifo = TSaldo_mag_clifo::key(*this, rec);
|
|
|
|
|
TSaldo_mag_clifo * s_clifo = (TSaldo_mag_clifo*) _saldi_mag_clifo.objptr(key_clifo);
|
|
|
|
|
|
|
|
|
|
if (s_clifo == NULL)
|
|
|
|
|
{
|
|
|
|
|
s_clifo = new TSaldo_mag_clifo(*this, rec);
|
|
|
|
|
_saldi_mag_clifo.add(key_clifo, s_clifo);
|
|
|
|
|
}
|
|
|
|
|
s_clifo->add(quant, valore, plus);
|
|
|
|
|
}
|
2008-06-11 10:58:17 +00:00
|
|
|
|
}
|
1999-04-16 12:02:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
bool TMov_mag::unlock_anamag(const char *codart)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
|
|
|
|
|
|
anamag.put(ANAMAG_CODART,codart);
|
|
|
|
|
return (anamag.read(_isequal,_unlock)==NOERR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMov_mag::lock_anamag(const char *codart)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
|
anamag.put(ANAMAG_CODART,codart);
|
|
|
|
|
|
1999-04-26 15:58:05 +00:00
|
|
|
|
KEY key = K_ENTER;
|
|
|
|
|
while (key != K_ESC)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (anamag.read(_isequal,_testandlock)==NOERR)
|
|
|
|
|
return TRUE;
|
1999-04-26 15:58:05 +00:00
|
|
|
|
|
|
|
|
|
TString mess;
|
2004-05-18 10:44:57 +00:00
|
|
|
|
mess << TR("Il record di anagrafica dell'articolo '")<< codart << TR("' risulta essere gi<67> in uso.");
|
2008-06-11 10:58:17 +00:00
|
|
|
|
TTimed_breakbox bbox(mess,10);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
|
|
|
|
|
key = bbox.run();
|
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
void TMov_mag::giac_putkey(TRectype& mag, const TSaldo_mag & s)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
mag.zero();
|
|
|
|
|
mag.put(MAG_ANNOES, s.codes());
|
|
|
|
|
mag.put(MAG_CODMAG, s.codmag());
|
|
|
|
|
mag.put(MAG_CODART, s.codart());
|
|
|
|
|
mag.put(MAG_LIVELLO, s.livello());
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
void TMov_mag::giac_putkey_clifo(TRectype& clifomag, const TSaldo_mag_clifo & s)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
|
|
|
|
clifomag.zero();
|
|
|
|
|
clifomag.put(CLIFOGIAC_ANNOES, s.codes());
|
|
|
|
|
clifomag.put(CLIFOGIAC_TIPOCF, s.tipocf());
|
|
|
|
|
clifomag.put(CLIFOGIAC_CODCF, s.codcf());
|
|
|
|
|
clifomag.put(CLIFOGIAC_INDSPED, s.codindsp());
|
|
|
|
|
clifomag.put(CLIFOGIAC_CODART, s.codart());
|
|
|
|
|
clifomag.put(CLIFOGIAC_LIVELLO, s.livello());
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// aggiorna tutti i saldi in base alle modifiche fatte.
|
2009-08-05 13:14:51 +00:00
|
|
|
|
// il lock su anagrafica dovrebbe garantire il lock su tutte le giacenze dell'articolo
|
2008-10-07 00:50:22 +00:00
|
|
|
|
bool TMov_mag::update_balances(bool lock)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
bool updated_bal = true;
|
2009-05-18 13:45:12 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
TLocalisamfile mag(LF_MAG);
|
2009-05-18 13:45:12 +00:00
|
|
|
|
mag.setkey(2);
|
2009-08-05 13:14:51 +00:00
|
|
|
|
TRectype& magcurr = mag.curr();
|
2009-05-18 13:45:12 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TRecord_array& b = body();
|
2009-08-05 13:14:51 +00:00
|
|
|
|
const TString8 hcodcaus = get(MOVMAG_CODCAUS);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
for (int i = b.last_row(); i > 0; i = b.pred_row(i))
|
|
|
|
|
if (causale(i).update_ultcos())
|
|
|
|
|
{
|
|
|
|
|
const TRectype & rec = b[i];
|
|
|
|
|
TArticolo & art = articolo(i);
|
|
|
|
|
if (art.lock_and_prompt(lock ? _testandlock : _nolock))
|
|
|
|
|
{
|
|
|
|
|
const real prezzo = art.convert_to_um(rec.get_real(RMOVMAG_PREZZO), NULL, rec.get(RMOVMAG_UM), false);
|
2009-08-05 13:14:51 +00:00
|
|
|
|
const long numreg = get_long(MOVMAG_NUMREG);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
art.update_ultcosti(prezzo,get_date(MOVMAG_DATACOMP), numreg, i);
|
|
|
|
|
art.rewrite();
|
|
|
|
|
}
|
|
|
|
|
else
|
2009-08-05 13:14:51 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (lock)
|
|
|
|
|
art.unlock();
|
2009-08-05 13:14:51 +00:00
|
|
|
|
}
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_saldi_mag.items() > 0)
|
|
|
|
|
{
|
|
|
|
|
TString_array keys_mag;
|
|
|
|
|
|
|
|
|
|
_saldi_mag.get_keys(keys_mag);
|
|
|
|
|
keys_mag.sort();
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
for (TToken_string* curr_key = (TToken_string*)keys_mag.first_item();
|
|
|
|
|
curr_key != NULL; curr_key = (TToken_string*)keys_mag.succ_item())
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
2009-08-05 13:14:51 +00:00
|
|
|
|
const TSaldo_mag& saldo = (const TSaldo_mag&)_saldi_mag[*curr_key];
|
|
|
|
|
const TCodice_articolo& codart = saldo.codart();
|
|
|
|
|
TArticolo_giacenza& art = cached_article_balances(codart);
|
2009-08-05 14:17:47 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (art.lock_and_prompt(lock ? _testandlock : _nolock))
|
|
|
|
|
{
|
2009-08-05 13:14:51 +00:00
|
|
|
|
giac_putkey(magcurr, saldo);
|
|
|
|
|
int err = mag.read();
|
|
|
|
|
if (err != NOERR)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
2009-08-05 13:14:51 +00:00
|
|
|
|
TRecord_array& sld = art.mag(saldo.codes());
|
|
|
|
|
const int nriga = sld.rows() + 1;
|
|
|
|
|
giac_putkey(magcurr, saldo);
|
|
|
|
|
magcurr.put(MAG_NRIGA, nriga);
|
|
|
|
|
sld.add_row(magcurr);
|
2009-08-05 14:17:47 +00:00
|
|
|
|
err = mag.write();
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balances(magcurr, saldo);
|
|
|
|
|
err = mag.rewrite();
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
updated_bal = false;
|
2008-10-07 00:50:22 +00:00
|
|
|
|
|
|
|
|
|
if (lock)
|
|
|
|
|
art.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_saldi_mag_clifo.items() > 0)
|
|
|
|
|
{
|
2009-05-18 13:45:12 +00:00
|
|
|
|
TLocalisamfile clifomag(LF_CLIFOGIAC);
|
|
|
|
|
clifomag.setkey(2);
|
2009-08-05 13:14:51 +00:00
|
|
|
|
TRectype& clifomag_curr = clifomag.curr();
|
2009-05-18 13:45:12 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TString_array keys_clifo;
|
|
|
|
|
|
|
|
|
|
_saldi_mag_clifo.get_keys(keys_clifo);
|
|
|
|
|
keys_clifo.sort();
|
|
|
|
|
|
|
|
|
|
for (TToken_string* curr_key = (TToken_string*)keys_clifo.first_item();
|
2009-08-05 13:14:51 +00:00
|
|
|
|
curr_key != NULL; curr_key = (TToken_string*)keys_clifo.succ_item())
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
|
|
|
|
TSaldo_mag_clifo & saldo=(TSaldo_mag_clifo &)_saldi_mag_clifo[*curr_key];
|
|
|
|
|
|
|
|
|
|
TArticolo_giacenza & art = cached_article_balances(saldo.codart());
|
|
|
|
|
|
|
|
|
|
if (art.lock_and_prompt(lock ? _testandlock : _nolock))
|
|
|
|
|
{
|
2009-08-05 13:14:51 +00:00
|
|
|
|
giac_putkey_clifo(clifomag_curr, saldo);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (clifomag.read() != NOERR)
|
|
|
|
|
{
|
|
|
|
|
// non trovato: aggiungo
|
2008-10-28 20:02:49 +00:00
|
|
|
|
clifomag.setkey(1);
|
2009-08-05 13:14:51 +00:00
|
|
|
|
giac_putkey_clifo(clifomag_curr, saldo);
|
|
|
|
|
clifomag_curr.put(CLIFOGIAC_NRIGA, 999);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (clifomag.read(_isgteq) == NOERR)
|
|
|
|
|
clifomag.prev();
|
|
|
|
|
int nriga = 1;
|
2009-08-05 13:14:51 +00:00
|
|
|
|
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())
|
|
|
|
|
nriga = clifomag_curr.get_int(CLIFOGIAC_NRIGA) + 1;
|
|
|
|
|
giac_putkey_clifo(clifomag_curr, saldo);
|
|
|
|
|
clifomag_curr.put(CLIFOGIAC_NRIGA, nriga);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
clifomag.write();
|
2008-10-28 20:02:49 +00:00
|
|
|
|
clifomag.setkey(2);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balances_clifo(clifomag_curr, saldo);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
clifomag.rewrite();
|
|
|
|
|
|
|
|
|
|
if (lock)
|
|
|
|
|
art.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_saldi_mag.destroy();
|
|
|
|
|
_saldi_mag_clifo.destroy();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return updated_bal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// aggiorna i saldi del record corrente
|
|
|
|
|
// in base alla causale e alla modifica fatta (con segno + o -)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
void TMov_mag::update_balances(TRectype & magrec, const TSaldo_mag & s)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TCausale_magazzino& caus = cached_causale_magazzino(s.codcaus());
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
if (caus.update_qta())
|
|
|
|
|
{
|
|
|
|
|
const real diff = s.quant();
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balance(magrec, MAG_GIAC, diff, caus.sgn(s_giac)); // update ..
|
|
|
|
|
update_balance(magrec, MAG_ACQ, diff, caus.sgn(s_acq)); // update ..
|
|
|
|
|
update_balance(magrec, MAG_ENT, diff, caus.sgn(s_ent));
|
|
|
|
|
update_balance(magrec, MAG_VEN, diff, caus.sgn(s_ven));
|
|
|
|
|
update_balance(magrec, MAG_USC, diff, caus.sgn(s_usc));
|
|
|
|
|
update_balance(magrec, MAG_ORDC, diff, caus.sgn(s_ordc));
|
|
|
|
|
update_balance(magrec, MAG_ORDF, diff, caus.sgn(s_ordf));
|
|
|
|
|
update_balance(magrec, MAG_RIM, diff, caus.sgn(s_rim));
|
|
|
|
|
update_balance(magrec, MAG_SCARTI, diff, caus.sgn(s_scart));
|
|
|
|
|
update_balance(magrec, MAG_INCL, diff, caus.sgn(s_incl));
|
|
|
|
|
update_balance(magrec, MAG_ACL, diff, caus.sgn(s_acl));
|
|
|
|
|
update_balance(magrec, MAG_PRODCOMP, diff, caus.sgn(s_prodc));
|
|
|
|
|
update_balance(magrec, MAG_PRODFIN, diff, caus.sgn(s_prodf));
|
|
|
|
|
update_balance(magrec, MAG_NLABEL, diff, caus.sgn(s_label));
|
|
|
|
|
update_balance(magrec, MAG_USER1, diff, caus.sgn(s_user1));
|
|
|
|
|
update_balance(magrec, MAG_USER2, diff, caus.sgn(s_user2));
|
|
|
|
|
update_balance(magrec, MAG_USER3, diff, caus.sgn(s_user3));
|
|
|
|
|
update_balance(magrec, MAG_USER4, diff, caus.sgn(s_user4));
|
|
|
|
|
update_balance(magrec, MAG_USER5, diff, caus.sgn(s_user5));
|
|
|
|
|
update_balance(magrec, MAG_USER6, diff, caus.sgn(s_user6));
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
if (caus.update_val())
|
2003-04-22 14:30:52 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const real diff_val = s.valore();
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balance(magrec, MAG_VALACQ, diff_val, caus.sgn(s_acq)); // update ..
|
|
|
|
|
update_balance(magrec, MAG_VALENT, diff_val, caus.sgn(s_ent));
|
|
|
|
|
update_balance(magrec, MAG_VALVEN, diff_val, caus.sgn(s_ven));
|
|
|
|
|
update_balance(magrec, MAG_VALUSC, diff_val, caus.sgn(s_usc));
|
|
|
|
|
update_balance(magrec, MAG_VALORDC, diff_val, caus.sgn(s_ordc));
|
|
|
|
|
update_balance(magrec, MAG_VALORDF, diff_val, caus.sgn(s_ordf));
|
|
|
|
|
update_balance(magrec, MAG_VALRIM, diff_val, caus.sgn(s_rim));
|
|
|
|
|
update_balance(magrec, MAG_VALSCARTI, diff_val, caus.sgn(s_scart));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL1, diff_val, caus.sgn(s_user1));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL2, diff_val, caus.sgn(s_user2));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL3, diff_val, caus.sgn(s_user3));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL4, diff_val, caus.sgn(s_user4));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL5, diff_val, caus.sgn(s_user5));
|
|
|
|
|
update_balance(magrec, MAG_USERVAL6, diff_val, caus.sgn(s_user6));
|
2003-04-22 14:30:52 +00:00
|
|
|
|
}
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
2003-04-22 14:30:52 +00:00
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
// aggiorna i saldi del record corrente
|
|
|
|
|
// in base alla causale e alla modifica fatta (con segno + o -)
|
|
|
|
|
void TMov_mag::update_balances_clifo(TRectype & clifomagrec, const TSaldo_mag_clifo & s)
|
|
|
|
|
{
|
|
|
|
|
const TCausale_magazzino& caus = cached_causale_magazzino(s.codcaus());
|
|
|
|
|
|
|
|
|
|
if (caus.update_qta())
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const real diff = s.quant();
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_GIAC, -diff, caus.sgn(s_giac)); // update ..
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_ACQ, diff, caus.sgn(s_ven)); // update ..
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_ENT, diff, caus.sgn(s_usc));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VEN, diff, caus.sgn(s_acq));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USC, diff, caus.sgn(s_ent));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_ORDC, diff, caus.sgn(s_ordf));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_ORDF, diff, caus.sgn(s_ordc));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_RIM, -diff, caus.sgn(s_rim));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_SCARTI, -diff, caus.sgn(s_scart));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_INCL, diff, caus.sgn(s_acl));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_ACL, diff, caus.sgn(s_incl));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_PRODCOMP, -diff, caus.sgn(s_prodc));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_PRODFIN, -diff, caus.sgn(s_prodf));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_DOTIN, diff, caus.sgn(s_dotin));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_DOTOD, diff, caus.sgn(s_dotod));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_DOTTM, diff, caus.sgn(s_dottm));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_CONSANNO, diff, caus.sgn(s_consanno));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER1, diff, caus.sgn(s_user1));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER2, diff, caus.sgn(s_user2));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER3, diff, caus.sgn(s_user3));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER4, diff, caus.sgn(s_user4));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER5, diff, caus.sgn(s_user5));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USER6, diff, caus.sgn(s_user6));
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
if (caus.update_val())
|
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const real diff_val = s.valore();
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALACQ, diff_val, caus.sgn(s_ven)); // update ..
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALENT, diff_val, caus.sgn(s_usc));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALVEN, diff_val, caus.sgn(s_acq));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALUSC, diff_val, caus.sgn(s_ven));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALORDC, diff_val, caus.sgn(s_ordf));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALORDF, diff_val, caus.sgn(s_ordc));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALRIM, -diff_val, caus.sgn(s_rim));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_VALSCARTI, -diff_val, caus.sgn(s_scart));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL1, diff_val, caus.sgn(s_user1));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL2, diff_val, caus.sgn(s_user2));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL3, diff_val, caus.sgn(s_user3));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL4, diff_val, caus.sgn(s_user4));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL5, diff_val, caus.sgn(s_user5));
|
|
|
|
|
update_balance(clifomagrec, CLIFOGIAC_USERVAL6, diff_val, caus.sgn(s_user6));
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
void TMov_mag::update_balances(TRectype& magrec, int numrig, bool plus)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
const TRectype & rec = body()[numrig];
|
|
|
|
|
TSaldo_mag saldo(*this, rec);
|
|
|
|
|
real quant = rec.get_real(RMOVMAG_QUANT);
|
|
|
|
|
const TCausale_magazzino& caus = cached_causale_magazzino(saldo.codcaus());
|
|
|
|
|
TArticolo & art = articolo(numrig);
|
|
|
|
|
|
|
|
|
|
quant = art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
|
|
|
|
|
|
|
|
|
|
real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
|
|
|
|
|
|
|
|
|
|
saldo.add(quant, valore, plus);
|
|
|
|
|
|
|
|
|
|
return update_balances(magrec, saldo);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-07 00:50:22 +00:00
|
|
|
|
void TMov_mag::update_balances_clifo(TRectype& cliforec, int numrig, bool plus)
|
|
|
|
|
{
|
|
|
|
|
const TRectype & rec = body()[numrig];
|
|
|
|
|
TSaldo_mag_clifo saldo(*this, rec);
|
|
|
|
|
real quant = rec.get_real(RMOVMAG_QUANT);
|
|
|
|
|
const TCausale_magazzino& caus = cached_causale_magazzino(saldo.codcaus());
|
|
|
|
|
TArticolo & art = articolo(numrig);
|
|
|
|
|
|
|
|
|
|
quant = art.convert_to_um(quant, NULL, rec.get(RMOVMAG_UM));
|
|
|
|
|
|
|
|
|
|
real valore = (quant.is_zero() && caus.update_val()) ? rec.get_real(RMOVMAG_PREZZO) : rec.get_real(RMOVMAG_PREZZO) * quant;
|
|
|
|
|
|
|
|
|
|
saldo.add(quant, valore, plus);
|
|
|
|
|
|
|
|
|
|
return update_balances_clifo(cliforec, saldo);
|
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
1999-04-16 12:02:04 +00:00
|
|
|
|
int TMov_mag::codice_esercizio(const TDate &d)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2008-10-07 00:50:22 +00:00
|
|
|
|
return esercizi().date2esc(d);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
void TMov_mag::update_balance(TRectype & rec, const char * fieldname, const real& val, const int sgn) const
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
2009-08-05 13:14:51 +00:00
|
|
|
|
if (sgn != 0)
|
|
|
|
|
{
|
|
|
|
|
if (sgn > 0)
|
|
|
|
|
rec.add(fieldname, val);
|
|
|
|
|
else
|
|
|
|
|
rec.add(fieldname, -val);
|
|
|
|
|
}
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TBalance_params
|
|
|
|
|
{
|
|
|
|
|
bool zero_giac;
|
2010-11-30 01:40:47 +00:00
|
|
|
|
bool closed;
|
2008-10-07 00:50:22 +00:00
|
|
|
|
int codes;
|
|
|
|
|
int codesprec;
|
|
|
|
|
int esprec;
|
|
|
|
|
TTipo_valorizz tipov;
|
|
|
|
|
const char * catv;
|
|
|
|
|
const char * codl;
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-27 14:21:11 +00:00
|
|
|
|
HIDDEN bool reset_giac(const TRelation& rel, void* pJolly)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
|
|
|
|
TArticolo_giacenza & articolo = (TArticolo_giacenza &) rel.lfile().curr();
|
|
|
|
|
TBalance_params & p = *((TBalance_params *)pJolly);
|
|
|
|
|
|
|
|
|
|
if (p.zero_giac)
|
2009-03-31 14:33:59 +00:00
|
|
|
|
articolo.azzera_saldi(p.codes, p.codesprec);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
else
|
|
|
|
|
articolo.riporta_saldi(p.codesprec, p.codes, p.tipov, p.catv, p.codl);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-30 01:40:47 +00:00
|
|
|
|
void reset_clifogiac(TRectype & rec, const TRectype & oldrec, bool closed)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
2009-03-27 14:21:11 +00:00
|
|
|
|
if (!oldrec.empty())
|
2008-10-07 00:50:22 +00:00
|
|
|
|
{
|
2009-03-27 00:11:07 +00:00
|
|
|
|
const real acq = oldrec.get_real(CLIFOGIAC_ACQ) + oldrec.get_real(CLIFOGIAC_RIM);
|
|
|
|
|
const real valacq = oldrec.get_real(CLIFOGIAC_VALACQ) + oldrec.get_real(CLIFOGIAC_VALRIM);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
real val = acq.is_zero() ? ZERO : valacq / acq;
|
|
|
|
|
const TPrice p(val);
|
|
|
|
|
real rim;
|
|
|
|
|
|
2009-03-27 00:11:07 +00:00
|
|
|
|
rim += oldrec.get_real(CLIFOGIAC_GIAC);
|
|
|
|
|
rim += oldrec.get_real(CLIFOGIAC_PRODFIN);
|
|
|
|
|
rim -= oldrec.get_real(CLIFOGIAC_PRODCOMP);
|
|
|
|
|
rim += oldrec.get_real(CLIFOGIAC_ACL);
|
|
|
|
|
rim -= oldrec.get_real(CLIFOGIAC_INCL);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
|
2008-11-11 16:22:53 +00:00
|
|
|
|
const real valrim = p.get_num() * rim;
|
|
|
|
|
const TCurrency c(valrim); // Arrontonda alla valuta
|
2008-10-07 00:50:22 +00:00
|
|
|
|
|
2009-03-27 00:11:07 +00:00
|
|
|
|
rec.put(CLIFOGIAC_RIM, rim); rec.put(CLIFOGIAC_VALRIM, c.get_num());
|
|
|
|
|
rec.zero(CLIFOGIAC_ACQ); rec.zero(CLIFOGIAC_VALACQ);
|
|
|
|
|
rec.zero(CLIFOGIAC_ENT); rec.zero(CLIFOGIAC_VALENT);
|
|
|
|
|
rec.zero(CLIFOGIAC_VEN); rec.zero(CLIFOGIAC_VALVEN);
|
|
|
|
|
rec.zero(CLIFOGIAC_USC); rec.zero(CLIFOGIAC_VALUSC);
|
|
|
|
|
rec.zero(CLIFOGIAC_SCARTI);
|
2010-11-30 01:40:47 +00:00
|
|
|
|
if (!riporta_ordinato() || !closed)
|
1998-08-25 18:07:30 +00:00
|
|
|
|
{
|
2010-11-30 01:40:47 +00:00
|
|
|
|
rec.zero(CLIFOGIAC_ORDF);
|
|
|
|
|
rec.zero(CLIFOGIAC_VALORDF);
|
|
|
|
|
rec.zero(CLIFOGIAC_ORDC);
|
|
|
|
|
rec.zero(CLIFOGIAC_VALORDC);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
2010-11-30 01:40:47 +00:00
|
|
|
|
if (closed)
|
|
|
|
|
{
|
|
|
|
|
rec.put(CLIFOGIAC_DOTOD, oldrec.get(CLIFOGIAC_DOTOD));
|
|
|
|
|
rec.put(CLIFOGIAC_DOTIN, oldrec.get(CLIFOGIAC_DOTIN));
|
|
|
|
|
rec.put(CLIFOGIAC_DOTTM, oldrec.get(CLIFOGIAC_DOTTM));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rec.zero(CLIFOGIAC_DOTOD);
|
|
|
|
|
rec.zero(CLIFOGIAC_DOTIN);
|
|
|
|
|
rec.zero(CLIFOGIAC_DOTTM);
|
|
|
|
|
}
|
1999-04-26 15:58:05 +00:00
|
|
|
|
}
|
2008-10-07 00:50:22 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; zero_fields[i]; i++)
|
|
|
|
|
rec.zero(zero_fields[i]);
|
2009-03-27 00:11:07 +00:00
|
|
|
|
rec.zero(CLIFOGIAC_DOTIN);
|
|
|
|
|
rec.zero(CLIFOGIAC_DOTOD);
|
|
|
|
|
rec.zero(CLIFOGIAC_DOTTM);
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
2009-03-27 14:21:11 +00:00
|
|
|
|
rec.zero(CLIFOGIAC_CONSANNO);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-30 01:40:47 +00:00
|
|
|
|
void update_clifogiac(TRectype & rec, const TRectype & oldrec)
|
|
|
|
|
{
|
|
|
|
|
if (!oldrec.empty())
|
|
|
|
|
{
|
|
|
|
|
const real acq = oldrec.get_real(CLIFOGIAC_ACQ) + oldrec.get_real(CLIFOGIAC_RIM);
|
|
|
|
|
const real valacq = oldrec.get_real(CLIFOGIAC_VALACQ) + oldrec.get_real(CLIFOGIAC_VALRIM);
|
|
|
|
|
real val = acq.is_zero() ? ZERO : valacq / acq;
|
|
|
|
|
const TPrice p(val);
|
|
|
|
|
const real rim_prec = rec.get_real(CLIFOGIAC_RIM);
|
|
|
|
|
real rim = oldrec.get_real(CLIFOGIAC_GIAC);
|
|
|
|
|
|
|
|
|
|
rim += oldrec.get_real(CLIFOGIAC_PRODFIN);
|
|
|
|
|
rim -= oldrec.get_real(CLIFOGIAC_PRODCOMP);
|
|
|
|
|
rim += oldrec.get_real(CLIFOGIAC_ACL);
|
|
|
|
|
rim -= oldrec.get_real(CLIFOGIAC_INCL);
|
|
|
|
|
|
|
|
|
|
const real valrim = p.get_num() * rim;
|
|
|
|
|
const TCurrency c(valrim); // Arrontonda alla valuta
|
|
|
|
|
|
|
|
|
|
rec.put(CLIFOGIAC_RIM, rim); rec.put(CLIFOGIAC_VALRIM, c.get_num());
|
|
|
|
|
rec.add(CLIFOGIAC_GIAC, rim - rim_prec);
|
|
|
|
|
if (riporta_ordinato())
|
|
|
|
|
{
|
|
|
|
|
rec.add(CLIFOGIAC_ORDF, oldrec.get_real(CLIFOGIAC_ORDF));
|
|
|
|
|
rec.add(CLIFOGIAC_VALORDF, oldrec.get_real(CLIFOGIAC_VALORDF));
|
|
|
|
|
rec.add(CLIFOGIAC_ORDC, oldrec.get_real(CLIFOGIAC_ORDC));
|
|
|
|
|
rec.add(CLIFOGIAC_VALORDC, oldrec.get_real(CLIFOGIAC_VALORDC));
|
|
|
|
|
}
|
|
|
|
|
rec.add(CLIFOGIAC_DOTOD, oldrec.get_real(CLIFOGIAC_DOTOD));
|
|
|
|
|
rec.add(CLIFOGIAC_DOTIN, oldrec.get_real(CLIFOGIAC_DOTIN));
|
|
|
|
|
rec.add(CLIFOGIAC_DOTTM, oldrec.get_real(CLIFOGIAC_DOTTM));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-27 14:21:11 +00:00
|
|
|
|
HIDDEN bool rel_reset_clifogiac(const TRelation& rel, void* pJolly)
|
|
|
|
|
{
|
|
|
|
|
TRectype & rec = rel.curr();
|
|
|
|
|
TBalance_params & p = *((TBalance_params *)pJolly);
|
2010-01-14 14:26:33 +00:00
|
|
|
|
TRectype newrec(rec);
|
2009-03-27 14:21:11 +00:00
|
|
|
|
|
2010-01-14 14:26:33 +00:00
|
|
|
|
newrec.put(CLIFOGIAC_ANNOES, p.codes);
|
|
|
|
|
if (newrec.read(rel.lfile()) != NOERR)
|
|
|
|
|
{
|
|
|
|
|
newrec = rec;
|
|
|
|
|
newrec.put(CLIFOGIAC_ANNOES, p.codes);
|
|
|
|
|
}
|
2010-11-30 01:40:47 +00:00
|
|
|
|
reset_clifogiac(newrec, rec, p.closed);
|
2010-01-14 14:26:33 +00:00
|
|
|
|
return newrec.write_rewrite(rel.lfile()) == NOERR;
|
2008-10-07 00:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool recalc_mov(const TRelation& rel, void* pJolly)
|
|
|
|
|
{
|
|
|
|
|
TMov_mag & mov_rec = (TMov_mag &) rel.lfile().curr();
|
|
|
|
|
bool & ok = *((bool *) pJolly);
|
|
|
|
|
|
|
|
|
|
ok = mov_rec.force_update_bal();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
TBalance_params p;
|
|
|
|
|
|
|
|
|
|
p.codes = codes;
|
|
|
|
|
p.codesprec = esercizi().pred(codes);
|
2009-08-05 13:14:51 +00:00
|
|
|
|
//p.zero_giac = p.codesprec > 0 && esercizi().esercizio(p.codesprec).chiusura_mag().ok();
|
2010-11-30 01:40:47 +00:00
|
|
|
|
p.closed = esercizi().esercizio(p.codesprec).chiusura_mag().ok();
|
2009-08-05 13:14:51 +00:00
|
|
|
|
p.zero_giac = p.codesprec <= 0 || esercizi().esercizio(p.codesprec).chiusura_mag().ok();
|
2008-10-07 00:50:22 +00:00
|
|
|
|
p.catv = catven;
|
|
|
|
|
p.codl = codlis;
|
2010-11-12 23:42:43 +00:00
|
|
|
|
p.tipov = tipo_valorizz;
|
2008-10-07 00:50:22 +00:00
|
|
|
|
|
|
|
|
|
// azzera tutte giacenze (ciclo sulle giacenze)
|
|
|
|
|
TCursor anamag_cur(new TRelation(LF_ANAMAG));
|
|
|
|
|
TString msg;
|
|
|
|
|
|
|
|
|
|
anamag_cur.relation()->lfile().set_curr(new TArticolo_giacenza());
|
|
|
|
|
anamag_cur.freeze();
|
|
|
|
|
msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento..."), codes);
|
|
|
|
|
anamag_cur.scan(reset_giac, (void *) &p, msg);
|
|
|
|
|
|
2010-01-14 14:26:33 +00:00
|
|
|
|
TString filter; filter << CLIFOGIAC_ANNOES << "==" << p.codesprec;
|
2008-10-07 00:50:22 +00:00
|
|
|
|
TCursor c(new TRelation(LF_CLIFOGIAC), filter);
|
|
|
|
|
|
|
|
|
|
msg.format(FR("Ricostruzione saldi esercizio %04d : azzeramento giacenze clienti..."), codes);
|
2009-03-27 14:21:11 +00:00
|
|
|
|
c.scan(rel_reset_clifogiac, (void *) &p, msg);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// ricostruisce i saldi (ciclo sui movimenti)
|
2008-10-07 00:50:22 +00:00
|
|
|
|
bool ok = true;
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
TRelation relmovmag(LF_MOVMAG);
|
|
|
|
|
TRectype& rec = relmovmag.curr();
|
2008-10-07 00:50:22 +00:00
|
|
|
|
rec.put(MOVMAG_ANNOES, codes);
|
|
|
|
|
|
2009-08-05 13:14:51 +00:00
|
|
|
|
TCursor mov_cur(&relmovmag ,"", 2, &rec, &rec);
|
|
|
|
|
relmovmag.lfile().set_curr(new TMov_mag());
|
2008-10-07 00:50:22 +00:00
|
|
|
|
msg.format(FR("Ricostruzione saldi esercizio %04d : ricalcolo..."), codes);
|
|
|
|
|
mov_cur.scan(recalc_mov, (void *) &ok, msg);
|
|
|
|
|
|
|
|
|
|
a.close();
|
1998-08-25 18:07:30 +00:00
|
|
|
|
return ok;
|
|
|
|
|
}
|