Corretto aggiornamento statistiche dei documenti

git-svn-id: svn://10.65.10.50/branches/R_10_00@22856 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2013-05-06 08:57:55 +00:00
parent 1985494e93
commit 7dbfb5ffc9
2 changed files with 33 additions and 27 deletions

View File

@ -1106,9 +1106,9 @@ public:
TDoc_key(const int anno, const TString& codnum, const long ndoc, const char provv = 'D'); TDoc_key(const int anno, const TString& codnum, const long ndoc, const char provv = 'D');
TDoc_key(const TRectype& rec); TDoc_key(const TRectype& rec);
TDoc_key(const char* key):TToken_string(key){} TDoc_key(const char* key) : TToken_string(key) {}
TDoc_key(const TToken_string& key):TToken_string(key){} TDoc_key(const TToken_string& key) : TToken_string(key) {}
TDoc_key(const TDoc_key& key):TToken_string(key){} TDoc_key(const TDoc_key& key) : TToken_string(key) {}
TDoc_key() {} TDoc_key() {}
}; };

View File

@ -248,8 +248,8 @@ void TDocumento::init()
add_file(LF_RIGHEDOC, RDOC_NRIGA); add_file(LF_RIGHEDOC, RDOC_NRIGA);
set_memo_fld("G1"); set_memo_fld("G1");
_tipocf = new TRecfield(*this, DOC_TIPOCF); _tipocf = new TRecfield(*this, DOC_TIPOCF);
_codcf = new TRecfield(*this, DOC_CODCF); _codcf = new TRecfield(*this, DOC_CODCF);
_cod_occas = new TRecfield(*this, DOC_OCFPI); _cod_occas = new TRecfield(*this, DOC_OCFPI);
_sconto = _esenzione = NULL; _sconto = _esenzione = NULL;
@ -310,10 +310,11 @@ const TString& TDocumento::codiva_bolli() const
void TDocumento::check_modules() void TDocumento::check_modules()
{ {
if (_has_mag == 3) if (_has_mag == 3)
{ {
_has_mag = dongle().active(MGAUT); const TDongle& din = dongle();
_has_stat_ven = dongle().active(SVAUT); _has_mag = din.active(MGAUT);
_has_provv = dongle().active(PRAUT); _has_stat_ven = din.active(SVAUT);
_has_provv = din.active(PRAUT);
} }
} }
@ -779,7 +780,7 @@ TRiga_documento& TDocumento::new_row(const char *tipo)
int TDocumento::read(TBaseisamfile& f, word op, word lockop) int TDocumento::read(TBaseisamfile& f, word op, word lockop)
{ {
int err = TMultiple_rectype::read(f, op ,lockop); int err = TMultiple_rectype::read(f, op, lockop);
_cli_for.zero(); _cli_for.zero();
_occas.zero(); _occas.zero();
@ -789,26 +790,30 @@ int TDocumento::read(TBaseisamfile& f, word op, word lockop)
set_riga_esenzione(); set_riga_esenzione();
_stato_originale = stato(); _stato_originale = stato();
if (err == NOERR && tipo_valido() && tipo().statistiche() && _has_stat_ven) if (err == NOERR && _has_stat_ven && tipo_valido() && tipo().statistiche() )
{ {
TString80 key(get(DOC_PROVV)); key << get(DOC_ANNO); key << get(DOC_CODNUM); key << get(DOC_NDOC); const TDoc_key key(head());
TObject* o = _docs_to_agg.objptr(key); TObject* o = _docs_to_agg.objptr(key);
const bool is_nota_credito = tipo().nota_credito(); const bool is_nota_credito = tipo().nota_credito();
if ( lockop >= _lock && o == NULL) if (lockop >= _lock && o == NULL)
{ {
TStats_agg * st_agg = new TStats_agg; TStats_agg* st_agg = new TStats_agg;
for (int i = physical_rows(); i > 0; i--) for (int i = physical_rows(); i > 0; i--)
{
if (is_nota_credito) if (is_nota_credito)
st_agg->add(row(i)); st_agg->add(row(i));
else else
st_agg->sub(row(i)); st_agg->sub(row(i));
}
_docs_to_agg.add(key, st_agg, true); _docs_to_agg.add(key, st_agg, true);
} }
else else
{
if (lockop == _unlock && o != NULL) if (lockop == _unlock && o != NULL)
_docs_to_agg.remove(key); _docs_to_agg.remove(key);
}
} }
_old_agente.cut(0); _old_agente.cut(0);
@ -1169,7 +1174,7 @@ int TDocumento::write_rewrite(TBaseisamfile & f, bool re) const
myself.update_raee(); myself.update_raee();
myself.set_row_ids(); myself.set_row_ids();
const bool check_movmag = dongle().active(MGAUT) && tipo().mov_mag(); const bool check_movmag = _has_mag && tipo().mov_mag();
if (check_movmag) if (check_movmag)
{ {
const bool do_movmag = tipo().stato_with_mov_mag(stato_doc) && get(DOC_CAUSMAG).not_empty(); const bool do_movmag = tipo().stato_with_mov_mag(stato_doc) && get(DOC_CAUSMAG).not_empty();
@ -1503,10 +1508,10 @@ int TDocumento::write_rewrite(TBaseisamfile & f, bool re) const
} }
if (_has_provv && tipo().provvigioni() && tipo().stato_provvigioni() <= stato()) if (_has_provv && tipo().provvigioni() && tipo().stato_provvigioni() <= stato())
myself.update_provvigioni(false); myself.update_provvigioni(false);
if (tipo().statistiche() && _has_stat_ven) if (_has_stat_ven && tipo().statistiche())
{ {
TString80 key(get(DOC_PROVV)); key << get(DOC_ANNO); key << get(DOC_CODNUM); key << get(DOC_NDOC); const TDoc_key key(myself.head());
TStats_agg * st_agg = (TStats_agg *) _docs_to_agg.objptr(key); TStats_agg* st_agg = (TStats_agg*)_docs_to_agg.objptr(key);
const bool is_nota_credito = tipo().nota_credito(); const bool is_nota_credito = tipo().nota_credito();
if (st_agg == NULL) if (st_agg == NULL)
@ -1514,19 +1519,22 @@ int TDocumento::write_rewrite(TBaseisamfile & f, bool re) const
st_agg = new TStats_agg; st_agg = new TStats_agg;
_docs_to_agg.add(key, st_agg, true); _docs_to_agg.add(key, st_agg, true);
} }
int i;
for (i = physical_rows(); i > 0; i--) for (int i = physical_rows(); i > 0; i--)
{
if (is_nota_credito) if (is_nota_credito)
st_agg->sub(myself.row(i)); st_agg->sub(myself.row(i));
else else
st_agg->add(myself.row(i)); st_agg->add(myself.row(i));
}
st_agg->update(); st_agg->update();
for (i = physical_rows(); i > 0; i--) for (int i = physical_rows(); i > 0; i--)
{
if (is_nota_credito) if (is_nota_credito)
st_agg->add(myself.row(i)); st_agg->add(myself.row(i));
else else
st_agg->sub(myself.row(i)); st_agg->sub(myself.row(i));
}
} }
} }
return err; return err;
@ -1536,7 +1544,7 @@ int TDocumento::remove(TBaseisamfile& f) const
{ {
if (!cancellabile() && !yesno_box("Documento non cancellabile,\nContinuare ugualmente")) if (!cancellabile() && !yesno_box("Documento non cancellabile,\nContinuare ugualmente"))
return NOERR; return NOERR;
const bool check_movmag = dongle().active(MGAUT) && tipo().mov_mag(); const bool check_movmag = _has_mag && tipo().mov_mag();
const bool doc_bloccato = bloccato(); const bool doc_bloccato = bloccato();
if (check_movmag) if (check_movmag)
@ -1564,11 +1572,10 @@ int TDocumento::remove(TBaseisamfile& f) const
} }
if (!doc_bloccato) if (!doc_bloccato)
{ {
if (tipo().statistiche() && _has_stat_ven) if (_has_stat_ven && tipo().statistiche())
{ {
TString80 key(get(DOC_PROVV)); key << get(DOC_ANNO); key << get(DOC_CODNUM); key << get(DOC_NDOC); const TDoc_key key(head());
TStats_agg * st_agg = (TStats_agg *) _docs_to_agg.objptr(key); TStats_agg* st_agg = (TStats_agg*)_docs_to_agg.objptr(key);
if (st_agg != NULL) if (st_agg != NULL)
{ {
st_agg->update(); st_agg->update();
@ -1578,7 +1585,6 @@ int TDocumento::remove(TBaseisamfile& f) const
if (_has_provv && tipo().provvigioni()) if (_has_provv && tipo().provvigioni())
{ {
TDocumento& myself = *((TDocumento *)this); TDocumento& myself = *((TDocumento *)this);
myself.update_provvigioni(true); myself.update_provvigioni(true);
} }
} }