Aumentati controlli di consistenza dei registri e causali

git-svn-id: svn://10.65.10.50/trunk@193 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-09-08 14:25:10 +00:00
parent f3ffdbbad6
commit d17c842cdc
13 changed files with 156 additions and 125 deletions

View File

@ -96,7 +96,7 @@ public:
Riga_rcaus::Riga_rcaus (TConto& tc,const char * df, char tipocf, char sez,
const char * des, const char * desagg,
bool rigaiva, const char * codiva)
: TToken_string(80)
: TToken_string(128)
{
add(df); add(tipocf);
// add(tc.tipo());
@ -127,7 +127,8 @@ public:
void TRighe_rcaus::ClearDescr()
{
for (int i=0; i < items(); i++) {
for (int i=0; i < items(); i++)
{
Riga_rcaus *r = (Riga_rcaus*)objptr(i);
if (r) r->add("", 0);
}
@ -137,7 +138,8 @@ void TRighe_rcaus::clear(int row)
{
Riga_rcaus *r = (Riga_rcaus*)objptr(row);
if (r) {
if (r)
{
r->add("", 1); r->add(0, 2); r->add(0, 3);
r->add(0L, 4); r->add("", 5); r->add("", 6);
r->add("", 7); r->add("", 8); r->add("", 9);
@ -149,7 +151,8 @@ void TRighe_rcaus::set_descr(int i, const char * dfi, char tipocf)
Riga_rcaus *r = (Riga_rcaus*)objptr(i);
TConto tc;
if (r == NULL) {
if (r == NULL)
{
r = new Riga_rcaus (tc,dfi,tipocf);
add(r,i);
}
@ -243,10 +246,8 @@ bool CG0500_application::leggi_riga(int r, KEY k)
if (k == K_ENTER)
{
TToken_string &riga = app()->ss().row(r);
int g = riga.get_int(3);
int c = riga.get_int(4);
long s = riga.get_long(5);
if (g == 0 && c == 0 && s == 0L) // riga azzerata
const int g = riga.get_int(3);
if (g == 0) // riga azzerata
{
riga.add("", 1); // pulisco tipo C/F
riga.add("", 5); // pulisco Dare/Avere
@ -307,7 +308,8 @@ bool CG0500_application::tipodoc_hndl (TMask_field& f, KEY k)
if (val.not_empty() && val != "IN" && val != "PG" && val != "AN")
{
if (salda_conto()) {
if (salda_conto())
{
f.mask().hide(F_TIPO_MOV_2);
f.mask().show(F_TIPO_MOV_1);
}

View File

@ -365,11 +365,10 @@ void TPrimanota_application::init_modify_mode(TMask& m)
}
bool TPrimanota_application::get_conto(int r, TConto& c) const
bool TPrimanota_application::get_conto(const TRectype& r, TConto& c) const
{
const TRectype& cg = _rel->cg(r);
c.set(cg.get_int("GRUPPO"), cg.get_int("CONTO"),
cg.get_long("SOTTOCONTO"), cg.get_char("TIPOC"));
c.set(r.get_int("GRUPPO"), r.get_int("CONTO"),
r.get_long("SOTTOCONTO"), r.get_char("TIPOC"));
return c.ok();
}
@ -424,11 +423,11 @@ int TPrimanota_application::read(TMask& m)
_saldi.set_num_ulmov(m.get_long(F_NUMREG));
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
TToken_string riga(180);
TToken_string riga(255);
for (int i = 0; i < _rel->cg_items(); i++)
{
TRectype& r = _rel->cg(i);
const TRectype& r = _rel->cg(i);
riga.cut(0); // Vuota la riga
const int rcontr = r.get_int("RCONTR") -1;
@ -443,7 +442,7 @@ int TPrimanota_application::read(TMask& m)
TImporto import(sezione, im);
import.add_to(riga); // Dare/Avere 101-102
TConto conto; get_conto(i, conto);
TConto conto; get_conto(r, conto);
riga.add(conto.string(0x3)); // Conto 103-107
if (conto.ok())
_saldi.aggiorna(conto, im, sezione, FALSE);
@ -453,7 +452,7 @@ int TPrimanota_application::read(TMask& m)
if (rcontr >= 0 && rcontr < _rel->cg_items())
{
get_conto(rcontr, conto);
get_conto(_rel->cg(rcontr), conto);
riga.add(conto.string(0x3)); // Contropartita 110-114
}
else riga.add(" | | | | ");
@ -489,35 +488,13 @@ int TPrimanota_application::read(TMask& m)
riga.add(r.get("CODIVA")); // IVA 102
riga.add(r.get("TIPODET")); // Detrazione 103
riga.add(r.get("IMPOSTA")); // Imposta 104
riga.add(r.get("TIPOCR")); // C/R 105
int rigaimp = solaiva ? 0 : r.get_int("RIGAIMP");
if (rigaimp > 0)
{
const int r = rigaimp-1;
if (r < cgs.items())
{
TToken_string& s = cgs.row(r);
riga.add(s.get(2)); // Tipo conto 106
for (int i = 0; i < 4; i++)
riga.add(s.get()); // Gruppo|Conto|Sottoconto|Descrizione
}
else
{
error_box("Riga imponibile %d errata nella riga iva %d", rigaimp, i+1);
rigaimp = 0;
}
}
else
{
riga.add(r.get("TIPOC")); // TIPO 106
riga.add(r.get("GRUPPO")); // GRUPPO 107
riga.add(r.get("CONTO")); // CONTO 108
riga.add(r.get("SOTTOCONTO")); // SOTTOCONTO 109
rigaimp = -1;
}
TConto c; get_conto(r, c);
if (c.ok())
c.add_to(riga, -1, 0x7); // 105-110
else
riga.add(" | | | | | ");
if (rigaimp != 0) riga.add(" | | | | ");
ivas.row(i) = riga;
}

View File

@ -189,17 +189,6 @@ BEGIN
PROMPT 1 9 "Registro IVA "
FLAGS "DG"
FIELD LF_MOV->REG
/*
USE REG SELECT I0 < 3
INPUT CODTAB[1,4] F_ANNOIVA SELECT
INPUT CODTAB[5,7] F_CODREG
DISPLAY "Anno" CODTAB[1,4]
DISPLAY "Codice" CODTAB[5,7]
DISPLAY "Tipo" I0
DISPLAY "Descrizione@50" S0
OUTPUT F_CODREG CODTAB[5,7]
CHECKTYPE NORMAL
*/
END
NUMBER F_PROTIVA 5
@ -219,7 +208,7 @@ END
STRING F_CLIFO 1
BEGIN
PROMPT 0 10 ""
FIELD LF_MOV->TIPO
FIELD TIPO
FLAGS "H"
END
@ -374,6 +363,7 @@ END
STRING F_CODPAG 4
BEGIN
PROMPT 60 11 "Pagamento "
FIELD CODPAG
USE %CPG
INPUT CODTAB F_CODPAG
DISPLAY "Codice" CODTAB

View File

@ -1,13 +1,33 @@
#include <xvtmacro.h>
#include <tabutil.h>
#include "cg2101.h"
#include "cg2103.h"
#include <lffiles.h>
#include <mov.h>
#include <rmov.h>
#include <rmoviva.h>
// Calcola l'anno di esercizio di una data
// Certified 99%
int date2esc(const TDate& d, int* prevesc)
{
if (prevesc) *prevesc = 0;
TTable esc("ESC");
for (int err = esc.first(); err == NOERR; err = esc.next())
{
const TDate ia(esc.get("D0")); // Data inizio esercizio
const TDate fa(esc.get("D1")); // Data fine esercizio
const anno = esc.get_int("CODTAB");
if (d >= ia && d <= fa)
return anno;
if (prevesc) *prevesc = anno;
}
return 0;
}
///////////////////////////////////////////////////////////
// Movimento di prima nota
///////////////////////////////////////////////////////////
@ -77,7 +97,7 @@ int TMovimentoPN::read_mov_rows()
int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate)
{
int err = file()->read(op, lockop, atdate);
if (err == NOERR) err = read_mov_rows();
if (err == NOERR) err = read_mov_rows();
return err;
}
@ -193,7 +213,7 @@ int TMovimentoPN::write(bool force, TDate&)
if (err == NOERR)
{
const TDate datareg(r.get("DATAREG"));
TLibro_giornale gio(datareg.year());
TLibro_giornale gio(date2esc(datareg));
gio.update(0L, datareg); // Aggiorna data registrazione sul libro giornale
if (reg.not_empty())

View File

@ -1,16 +1,21 @@
#ifndef __CG2101_H
#define __CG2101_H
#ifndef __RELATION_H
#include <relation.h>
#endif
int date2esc(const TDate& d, int* prevesc = NULL);
class TMovimentoPN : public TRelation
{
// class TMovimentoPN : public TRelation
// @END
// @DPRIV
TArray _cg, _iva;
int _oldcg, _oldiva;
real _balance;
TArray _cg, _iva;
int _oldcg, _oldiva;
real _balance;
// @END
protected:
@ -18,7 +23,7 @@ protected:
int write_rec(bool re, const TRectype&r, TLocalisamfile* f);
int cancella(TLocalisamfile* f, int da, int a);
int registra(bool re, bool force);
int read_mov_rows();
int read_mov_rows();
// @END
public:
@ -42,3 +47,5 @@ public:
TMovimentoPN();
virtual ~TMovimentoPN() {}
};
#endif

View File

@ -16,7 +16,7 @@ inline TPrimanota_application& app()
///////////////////////////////////////////////////////////
// Determina il tipo IVA da causale+anno
// Certified 50%
// Certified 100%
TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva)
{
TipoIVA i = iva_errata;
@ -33,24 +33,6 @@ TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva)
return i;
}
// Calcola l'anno di esercizio di una data
// Certified 99%
int TPrimanota_application::date2esc(const TDate& d, int* prevesc)
{
if (prevesc) *prevesc = 0;
TTable esc("ESC");
for (int err = esc.first(); err == NOERR; err = esc.next())
{
const TDate ia(esc.get("D0")); // Data inizio esercizio
const TDate fa(esc.get("D1")); // Data fine esercizio
const anno = esc.get_int("CODTAB");
if (d >= ia && d <= fa)
return anno;
if (prevesc) *prevesc = anno;
}
return 0;
}
// Calcolo della percentuale di un dato codice IVA
// Certified 99%
const real& TPrimanota_application::cod2IVA(const TMask& m)
@ -782,6 +764,7 @@ bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key)
if (ok)
f.mask().stop_run(K_INS); // Entra in modo inserimento
}
else return FALSE;
}
return TRUE;
@ -799,6 +782,9 @@ bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key)
const int ann = f.mask().get_int(F_ANNOIVA);
const char* cau = f.get();
TCausale c(cau, ann);
if (!c.ok()) return FALSE;
ok = app().causale().similar(c);
if (!ok)
{
@ -838,35 +824,41 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
if (!ok)
return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae);
const TLibro_giornale& gio = app().giornale();
const TDate ljp(gio.global_last_print());
if (dr <= ljp)
return f.error_box("La data dell'operazione e' antecedente alla data\n"
"dell'ultima stampa del libro giornale: %s", ljp.string());
if (dr < gio.last_reg())
warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n"
"sul libro giornale del %d",
gio.last_reg().string(), ae);
if (!m.query_mode() && app().iva() != nessuna_iva)
if (f.dirty() || f.mask().query_mode())
{
const TLibro_giornale& gio = app().giornale();
const TDate ljp(gio.global_last_print());
if (dr <= ljp)
return f.error_box("La data dell'operazione e' antecedente alla data\n"
"dell'ultima stampa del libro giornale: %s", ljp.string());
if (dr < gio.last_reg())
warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n"
"sul libro giornale del %d",
gio.last_reg().string(), ae);
if (m.query_mode())
app().read_caus(m.get(F_CODCAUS), dr.year());
TRegistro& reg = app().causale().reg();
const TString16 codreg(reg.name());
if (reg.year() != dr.year())
if (codreg.not_empty())
{
const bool ok = reg.read(codreg, dr.year());
if (!ok) return FALSE;
}
if (dr <= reg.last_print())
return error_box("La data dell'operazione e' antecedente al %s, ultima\n"
"data di stampa del registro '%s' dell'anno %d",
reg.last_print().string(), (const char*)codreg, dr.year());
if (dr < reg.last_reg())
warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n"
"sul registro '%s' dell'anno %d",
reg.last_reg().string(), (const char*)codreg, dr.year());
if (reg.year() != dr.year())
{
const bool ok = reg.read(codreg, dr.year());
if (!ok) return FALSE;
}
if (dr <= reg.last_print())
return error_box("La data dell'operazione e' antecedente al %s, ultima\n"
"data di stampa del registro '%s' dell'anno %d",
reg.last_print().string(), (const char*)codreg, dr.year());
if (dr < reg.last_reg())
warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione\n"
"sul registro '%s' dell'anno %d",
reg.last_reg().string(), (const char*)codreg, dr.year());
}
}
}
return ok;
@ -1024,6 +1016,7 @@ void TPrimanota_application::add_cgs_tot(TMask& m)
// Creazione/Aggiornamento riga totale
const int pos = type2pos('T');
set_cgs_row(pos, real2imp(tot, 'T'), c, "Totale documento", 'T');
calcola_saldo();
}

View File

@ -95,7 +95,7 @@ protected:
TMask* load_mask(int n);
TMask& occas_mask() { return *load_mask(3); }
bool get_conto(int r, TConto& c) const;
bool get_conto(const TRectype& r, TConto& c) const;
void put_conto(TRectype& r, const TConto& c) const;
void mask2rel(const TMask& m);
@ -115,7 +115,6 @@ protected:
static int type2pos(char tipo);
static const real& cod2IVA(const TMask& m);
static real scorpora(real& imponibile, const real& percentuale);
static int date2esc(const TDate& d, int* prev = NULL);
static bool detraibile(int tipodet);
int bill2contr(const TConto& c, char sezione) const;

View File

@ -329,6 +329,17 @@ const char* TCausale::causale_inc_imm() const
const char* TCausale::tipo_doc() const
{ return _rec.ok() ? _rec.get("TIPODOC") : ""; }
bool TCausale::ok() const
{
if (iva() == iva_errata)
return FALSE;
if (corrispettivi() != reg().corrispettivi())
return error_box("Tipo documento e registro incongruenti per i corrispettivi");
return TRUE;
}
char TCausale::sezione(int riga) const
{
const TRectype& r = row(riga);
@ -361,20 +372,24 @@ TipoIVA TCausale::iva() const
{
TipoIVA i = nessuna_iva;
if (ok())
{
TString tipodoc(_rec.get("TIPODOC"));
if (tipodoc.not_empty())
TString16 tipodoc(_rec.get("TIPODOC"));
if (tipodoc.not_empty())
{
TTable tpd("%TPD");
tpd.put("CODTAB", tipodoc);
if (tpd.read() == NOERR)
{
TTable tpd("%TPD");
tpd.put("CODTAB", tipodoc);
if (tpd.read() == NOERR)
i = (TipoIVA)tpd.get_int("I0"); // IVA acquisti, vendite, generica
const TipoIVA ri = _reg.iva();
if (i == iva_generica)
i = ri;
if (i != ri)
{
i = (TipoIVA)tpd.get_int("I0"); // IVA acquisti, vendite, generica
if (i == iva_generica)
i = _reg.iva();
((TCausale*)this)->_corrisp = tpd.get_bool("B0"); // Ricorda flag per la prossima volta
}
error_box("Tipo documento incompatibile con tipo registro");
i = iva_errata;
}
((TCausale*)this)->_corrisp = tpd.get_bool("B0"); // Ricorda flag per la prossima volta
}
}
((TCausale*)this)->_iva = i; // Ricorda IVA per la prossima volta

View File

@ -90,11 +90,11 @@ public:
const char* causale_inc_imm() const;
const char* tipo_doc() const;
TRegistro& reg() { return _reg; }
TRegistro& reg() const { return (TRegistro&)_reg; }
TipoIVA iva() const;
bool corrispettivi() const;
virtual bool ok() const { return !_rec.empty(); }
virtual bool ok() const;
bool similar(const TCausale& c) const;
char sezione(int riga) const;

View File

@ -72,6 +72,8 @@ BEGIN
OUTPUT 107 DESCR
ADD RUN CG0 -0
CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 2 101 102
MESSAGE DIRTY,106|DIRTY,206|DIRTY,306
WARNING "Conto inesistente o mancante sulla riga contabile"
END
@ -222,7 +224,9 @@ BEGIN
OUTPUT 112 CONTO
OUTPUT 114 DESCR
ADD RUN CG0 -0
MESSAGE DIRTY,113|DIRTY,213|DIRTY,313
CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 3 113 213 313
END
NUMBER 113 6

View File

@ -41,6 +41,8 @@ BEGIN
OUTPUT 110 DESCR
OUTPUT 105 TIPOSPRIC
ADD RUN cg0 -0
MESSAGE DIRTY,109|DIRTY,209|DIRTY,309
VALIDATE REQIF_FUNC 1 101
CHECKTYPE NORMAL
WARNING "Conto inesistente nella riga IVA"
END

View File

@ -11,12 +11,13 @@
// Certified 100%
TConto::TConto(int g, int c, long s, char t, const char* d)
: _tipo(toupper(t)), _gruppo(g), _conto(c), _sottoconto(s),
_descrizione(d)
_descrizione(d), _tipo_cr(-1)
{}
// Certified 90%
TConto::TConto(TToken_string& s, int from, int mode)
: _tipo_cr(-1)
{
const char* first = s.get(from);
if (mode & 0x1)
@ -54,13 +55,15 @@ TConto& TConto::set(int g, int c, long s, char t, const char* d)
const TConto& TConto::add_to(TToken_string& ts, int from, int mode)
{
if (mode & 0x4)
ts.add(_tipo_cr, from++);
if (mode & 0x1)
ts.add(_tipo, from++);
ts.add(_gruppo, from++);
ts.add(_conto, from++);
ts.add(_sottoconto, from++);
if (mode & 0x2)
ts.add(descrizione(), from);
ts.add(descrizione(), from++);
return *this;
}
@ -114,7 +117,10 @@ const char* TConto::describe()
_tipo = (c < ' ') ? ' ' : c; // Force correct type
}
if (_tipo == ' ')
{
desc = pcon.get("DESCR");
_tipo_cr = pcon.get_int("TIPOSPRIC");
}
}
}
if (_tipo == 'C' || _tipo == 'F')
@ -147,6 +153,7 @@ bool TConto::read(TRectype &r)
{
r = pcon.curr();
_descrizione = r.get("DESCR");
_tipo_cr = r.get_int("TIPOSPRIC");
}
else
r.zero();
@ -168,16 +175,29 @@ const TString& TConto::descrizione()
return _descrizione;
}
int TConto::tipo_cr()
{
if (_tipo_cr < 0)
{
_descrizione = "";
descrizione();
}
return _tipo_cr;
}
// Certified 99% (uses __tmp_string)
const char* TConto::string(int mode)
{
TFixed_string s(&__tmp_string[128], 80);
s.cut(0);
if (mode & 0x4)
s << tipo_cr() << '|';
if (mode & 0x1)
s << _tipo << '|';
s << _gruppo << '|' << _conto << '|' << _sottoconto;
if (mode & 0x2) s << '|' << descrizione();
if (mode & 0x2)
s << '|' << descrizione();
return s;
}

View File

@ -17,6 +17,7 @@ class TConto : public TSortable
int _gruppo, _conto;
long _sottoconto; // Sottoconto, codice cliente o fornitore
TString80 _descrizione; // Vuota fino alla chiamata di describe
int _tipo_cr;
real _dare, _avere;
real _darepro, _averepro;
real _saldo;
@ -49,6 +50,7 @@ public:
long sottoconto() const { return _sottoconto; }
const TString& descrizione();
int TConto::tipo_cr();
bool read(TRectype& r);
const char* string(int mode = 0);