From 1b212725156e33adc3c5809b6f406376a8968636 Mon Sep 17 00:00:00 2001 From: augusto Date: Fri, 6 Jun 1997 16:36:35 +0000 Subject: [PATCH] Redistribuite le funzioni di magazzino nelle librerie e unico .h git-svn-id: svn://10.65.10.50/trunk@4545 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- mg/mglib.h | 610 ++++++++++++++++++++++++++++++++ mg/mglib01.cpp | 893 ++++------------------------------------------- mg/mglib02.cpp | 930 +++++++++++++++++++++++++++++++++++++------------ mg/mglib03.cpp | 238 +++++++++++++ mg/mglib06.cpp | 555 +++++++++++++++++++++++++++++ 5 files changed, 2164 insertions(+), 1062 deletions(-) create mode 100755 mg/mglib.h create mode 100755 mg/mglib03.cpp create mode 100755 mg/mglib06.cpp diff --git a/mg/mglib.h b/mg/mglib.h new file mode 100755 index 000000000..8890895a3 --- /dev/null +++ b/mg/mglib.h @@ -0,0 +1,610 @@ +// ******************************* +// LIBRERIA di magazzino +// ******************************* +#ifndef __MGLIB_H +#define __MGLIB_H + +#ifndef __RELATION_H +#include +#endif +#ifndef __RECARRAY_H +#include +#endif +#ifndef __VARREC_H +#include +#endif +#ifndef __MSKSHEET_H +#include +#endif +#ifndef __FORM_H +#include "form.h" +#endif +#ifndef __ANAMAG_H +#include "anamag.h" +#endif +#ifndef __UMART_H +#include "umart.h" +#endif +#ifndef __CODCORR_H +#include "codcorr.h" +#endif +#ifndef __DESLIN_H +#include "deslin.h" +#endif +#ifndef __MAG_H +#include "mag.h" +#endif +#ifndef __STOMAG_H +#include "stomag.h" +#endif + +#include + +#include "..\cg\cglib.h" + +/*class TMultiple_rectype ; +//************************************** +// classe per il controllo dei record composti da una testata e N file di righe +// è implementato come un TRectype che contiene anche un TRecord_array +// +class TMultiple_rectype : public TAuto_variable_rectype +{ + enum { maxfiles = 20}; + // @ cmember Array di TRecord array per le righe + TArray _files; // + // @ cmember flag indicatore di record nuovo + bool _nuovo; + // @ cmember numero di file righe + short _nfiles; + // @ cmember file delle righe + int _logicnums[maxfiles]; + // @ cmember Array di nomi di campo "numeratore" delle righe + TString_array _numfields; + +protected: + const TArray & files() const { return _files;} + // @ cmember funzione per costruire la chiave delle righe + virtual void set_body_key(TRectype & rowrec) pure; + // @ cmember renumber la chiave del corpo + virtual long renum(long numdoc = -1) { return -1; } + virtual TRectype & get_body_record(int logicnum = 0) { return *(new TRectype(logicnum ? logicnum : _logicnums[0])); } + virtual void load_rows_file(int logicnum); + // @cmember Ritorna l'indice di

del numero logico passato + int log2ind(int logicnum) const; + virtual int find(int logicnum, const char * fieldname, const char * s, int from = 0, bool reverse = FALSE) const ; + virtual int write_rewrite(TBaseisamfile& f, bool re = FALSE) const; + void remove_body(int logicnum); + +public: + //*********************** + // struttura + // @ cmember restituisce il record di testata + const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento + // @ cmember restituisce il record di testata + TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento + + + // @ cmember restituisce il record array del corpo + TRecord_array & body(int logicnum = 0) const; + // @ cmember restituisce il numero di record nel corpo + int rows(int logicnum = 0) const { return body(logicnum).rows(); } + + // @ cmember restituisce il record n-esimo del del corpo + virtual const TRecord_array & operator[](int logicnum) const { return (const TRecord_array &)((TMultiple_rectype *)this)->body(logicnum); } + // @ cmember restituisce il record n-esimo del del corpo + virtual TRecord_array & operator[](int logicnum) { return (TRecord_array &)body(logicnum); } + + bool destroy_row(int n, bool pack = FALSE, int logicnum = 0) { return body(logicnum).destroy_row(n, pack); } + void destroy_rows(int logicnum = 0) { body(logicnum).destroy_rows(); } + + //*********************** + // record e I/O + virtual void dirty_fields() {} + virtual void set_fields(TAuto_variable_rectype & rec) {} + virtual void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); } + + virtual void renum_key(const char * kfield,const char * val); + virtual TRectype & operator =(const TRectype & r); + virtual TRectype & operator =(const char * r); + virtual void zero(char c = '\0'); + + virtual int read(TRectype & rec, word op = _isequal, word lockop = _nolock); + virtual int read(word op = _isequal, word lockop = _nolock) { return read(*this, op, lockop); } + int read(TBaseisamfile & f, word op = _isequal, word lockop = _nolock) { return read(f.curr(), op, lockop); } + + virtual int write(TBaseisamfile& f) const + { return write_rewrite(f);} + virtual int rewrite(TBaseisamfile& f) const + { return write_rewrite(f,TRUE);} + virtual int remove(TBaseisamfile& f) const; + + int write() const { TBaseisamfile f(num()); return write(f);} + int rewrite() const { TBaseisamfile f(num()); return rewrite(f);} + int remove() const { TBaseisamfile f(num()); return remove(f);} + + + void add_file(int logicnum, const char * numfield); + //************************** + // @ cmember costruttore dal numero del file + TMultiple_rectype(int hfn); + // @ cmember costruttore dal file + TMultiple_rectype(const TBaseisamfile* file); + // @ cmember costruttore dal record + TMultiple_rectype(const TRectype & rec); + // @ cmember costruttore di copia + TMultiple_rectype(const TMultiple_rectype& r); + virtual ~TMultiple_rectype() {} +}; + +*/ + + + + +char * TNome_valorizz[]; + +typedef enum { + valorizz_ultcos , valorizz_mediacos , valorizz_przlist , + valorizz_coststd , valorizz_costmedio , + valorizz_FIFOa , valorizz_LIFOa , + valorizz_FIFO , valorizz_LIFO, + valorizz_FIFOr , valorizz_LIFOr +} TTipo_valorizz; + +class TArticolo : public TMultiple_rectype +{ + TRecfield * _codice; + +protected: + virtual const TString & get_str(const char* fieldname) const ; + virtual void set_body_key(TRectype & rowrec); + +public: + + virtual int read(const char * cod, word op = _isequal, word lockop = _nolock); + virtual int read(TRectype & rec, word op = _isequal, word lockop = _nolock) { return read( rec.get(ANAMAG_CODART), op, lockop); } + + TObject* dup() const { return new TArticolo(codice()); } + + const TString codice() const { return (const char *) *_codice;} + const TString& descrizione(const char * lingua = NULL) const; + + bool unlock() ; + bool lock_and_prompt() ; + void update_ultcosti(real costo,TDate data) ; + + int find_um(const char * um, int from = 0) const { return find(LF_UMART, UMART_UM, um, from); } + int find_deslin(const char * deslin, int from = 0) const { return find(LF_DESLIN, DESLIN_CODLIN, deslin, from); } + int find_codcorr(const char * codcorr, int from = 0) const { return find(LF_CODCORR, CODCORR_CODARTALT, codcorr, from); } + TRecord_array & um() const { return body(LF_UMART); } + TRecord_array & deslin() const { return body(LF_DESLIN); } + TRecord_array & codcorr() const { return body(LF_CODCORR); } + + TArticolo(const char* codice = NULL); + TArticolo(const TRectype& rec); + virtual ~TArticolo(); +}; + +class TArticolo_giacenza : public TArticolo +{ + TString16 _anno_mag; + TString16 _anno_sto; + +protected: + virtual const TString & get_str(const char* fieldname) const ; + virtual void set_body_key(TRectype & rowrec); + void set_anno_mag (const char * anno = NULL); + void set_anno_sto (const char * anno = NULL); + void reset_anno_mag () { set_anno_mag();} + void reset_anno_sto () { set_anno_sto();} + +public: + + TObject* dup() const { return new TArticolo_giacenza(codice()); } + virtual void zero(char c = '\0'); + + int find_mag(const char * annoes, const char * codmag = NULL, const char * livello = NULL, int from = 0) const ; + int find_storico(const char * annoesrif, const char * annoes = NULL, int from = 0) const; + TRecord_array & mag(const char * annoes) const; + TRecord_array & storico(const char * annoesrif) const; + + real ultimo_costo(const char * annoes) const; + real media_costi(const char * annoes) const; + real prezzo_listino(const char * annoes, const char * catven ,const char * codlist) const; + real costo_standard(const char * annoes) const; + real costo_medio(const char * annoes, const char * codmag, const char * livello) const; + real LIFO_annuale(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + real FIFO_annuale(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + real LIFO(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + real FIFO(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + real LIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + real FIFO_ragionieristico(const char * annoes, const char * codmag, const char * livello, + bool giacenza_effettiva = TRUE, bool valorizza_componenti = TRUE) const; + + TArticolo_giacenza(const char* codice = NULL); + TArticolo_giacenza(const TRectype& rec); + virtual ~TArticolo_giacenza() {} +}; + +class THead_lines_record ; +//************************************** +// classe per il controllo dei record composti da una testata e N righe +// è implementato come un TRectype che contiene anche un TRecord_array +// +class THead_lines_record : public TAuto_variable_rectype { + + // @ cmember Array di TRectype per le righe + TRecord_array * _rows; // + // @ cmember flag indicatore di record nuovo + bool _nuovo; + // @ cmember file principale + int _file; + // @ cmember file delle righe + int _rfile; + // @ cmember nome del campo "numeratore" delle righe + TString _numfield; + + +protected: + // @ cmember restituisce la riga del corpo + virtual TRectype & row(int index) const; + virtual void put_str(const char* fieldname, const char* val); + // @ cmember funzione per estrarre dal record della testata la chiave delle righe + virtual void copy_linekey(const TRectype & headrecord, TRectype & linesrecord)=0; + // @ cmember renumer la chiave del corpo + virtual long renum(long numdoc=-1)=0; + + int write_rewrite(TBaseisamfile& f ,bool re = FALSE) const ; +public: + //*********************** + // struttura + // @ cmember restituisce il record di testata + const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento + // @ cmember restituisce il record di testata + TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento + + // @ cmember restituisce il numero di record nel corpo + int rows() const { return _rows->rows(); } + // @ cmember restituisce il record array del corpo + TRecord_array * rows_record() { return _rows; } + + // @ cmember restituisce il record n-esimo del del corpo + virtual const TRectype& operator[](int index) const + { return (const TRectype&)((THead_lines_record *)this)->row(index); } + // @ cmember restituisce il record n-esimo del del corpo + virtual TRectype& operator[](int index) + { return (TRectype&)row(index); } + + TRectype & insert_row(int row, const char *tipo = NULL); + TRectype & new_row(const char *tipo = NULL); + bool destroy_row(int n, bool pack = FALSE) { return _rows->destroy_row(n, pack); } + void destroy_rows() { _rows->destroy_rows(); } + + //*********************** + // record e I/O + virtual void dirty_fields(); + + virtual const char *get_next_key() =0 ; + virtual void renum_key(const char * kfield,const char * val); + virtual TRectype & operator =(const TRectype & r); + virtual TRectype & operator =(const char * r); + virtual void zero(const char * fieldname); + virtual void zero(char c = '\0'); + + void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); } + virtual void set_fields(TAuto_variable_rectype & rec); + + virtual int readat(TBaseisamfile& f, TRecnotype nrec, word lockop= _nolock); + virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock); + + virtual int write(TBaseisamfile& f) const ; + virtual int rewrite(TBaseisamfile& f) const ; + virtual int remove(TBaseisamfile& f) const ; + + //************************** + // @ cmember costruttore dal numero del file + THead_lines_record(int hfn, int rfn,const char *numfield); + // @ cmember costruttore dal file + THead_lines_record(const TBaseisamfile* head_file,int rfn,const char *numfield); + // @ cmember costruttore dal record + THead_lines_record(const TRectype & r,int rfn,const char *numfield); + // @ cmember costruttore di copia + THead_lines_record(const THead_lines_record& r); + virtual ~THead_lines_record(); +}; + + +// ************************************** +// ************************************** +// ************************************** +// fine classi da portare in libreria: + +// ******************************* +// LIBRERIA DI utility del magazzino +// ******************************* +//#include "..\ve\velib03.h" + + +#define MANY_MAG_LEV 10 +#define MAX_GIAC_LEVEL 4 +class TMag_livelli { + bool _enabled[MANY_MAG_LEV]; + int _code_lenght[MANY_MAG_LEV]; + TString _name[MANY_MAG_LEV]; + TString _picture[MANY_MAG_LEV]; + int _last_level; + +public: + int last_level() const {return _last_level;}; // Ritorna il numero di livelli abilitati + const bool enabled(int levnum=1); // Ritorna se il livello è abilitato + const TString & name(int levnum); // Ritorna il nome (descrizione) di quel livello + const TString & picture(int levnum);// Ritorna la stringa di picture per i codici gruppo di quel livello + const int code_lenght(int levnum); // Ritorna la lunghezza dei codici gruppo di quel livello + const int packed_lenght(int levnum); // Ritorna la lunghezza del codice compatto fino a quel livello + + void pack_grpcode(TString & pc, const TString &codlev, const int levnum); // Inserisce il codice del gruppo del livello levnum in pc + TString unpack_grpcode(const TString & pc, const int levnum); // Estrae il codice del gruppo del livello levnum da pc + TString build_tabcode(const TString & pc, const int levnum); + + TMag_livelli(const char *tabname); // costruttore + ~TMag_livelli() {}; // distruttore +}; + + + +// ******************************* +// ******************************* +// riconoscimento di metacaratteri +class TR_automa; +class TMetachar { + TR_automa * _au; + TString _language; + char _metach_mand[10]; + char _metach_opz[10]; + + void set_language(const char * language); // setta l'automa che ricosce il linguaggio passato + void add_tran(int statenum,unsigned char symbol,int next);// aggiunge le transizioni all'automa +public: + const char * language() const; // restituisce la stringa di metacaratteri del linguaggio riconosciuto + bool recognized(const char * pattern); + + bool has_opzchars(const char * pattern); + bool has_mandchars(const char * pattern); + + int maxstrlen(const char * pattern) const; + const char *mand_chars() {return _metach_mand;}; + const char *opz_chars() {return _metach_opz;}; + TMetachar(const char * str); + TMetachar(); + ~TMetachar(); +}; + +// ********************* +// classe che incapsula le causali di magazzino (record della tabella CAU) +typedef enum { + s_giac, + s_acq,s_ent, + s_ven,s_usc, + s_ordc,s_ordf, + s_acl,s_incl, + s_prodc,s_prodf, + s_rim, + s_scart, + s_label +} TTipo_saldomag; + +class TCausale_magazzino : public TRectype { +public: + const char * get_descr() {return get("S0");} + const char get_tipoprz() {return get_char("S6");} + const char get_tipomov() {return get_char("S7");} + const char * get_raggfisc() {return get("S8");} + int sgn(TTipo_saldomag fieldname) ; + TCausale_magazzino(const char * codice); + ~TCausale_magazzino(); +}; + +class TLine_movmag ; // convenience... + +// dati della linea di movimento di magazzino +class TLine_movmag : public TObject { +public: + TString16 um; + real quant; + real prezzo; + int operator==(TLine_movmag &); + + virtual TObject* dup() const {return new TLine_movmag(*this);}; + + TLine_movmag() {}; + TLine_movmag(const TLine_movmag &); + virtual ~TLine_movmag() {}; +}; + +// classe per la definizione dei movimenti di magazzino +// ( un movimento (testata+righe) == un oggetto TMov_mag ) +class TMov_mag : public TMultiple_rectype { + + // + TString16 _codcaus; + TString16 _annoes; + // + TString16 _nextcod; + // + TAssoc_array lines_to_add; + TAssoc_array lines_to_subtract; + +protected: + virtual void set_body_key(TRectype & rowrec); + virtual bool renum(); // rinumerazione ; + + // ************ gestione saldi + // @member: compone le parti chiave + dati a partire dalla riga dello sheet + void line2key_data(int numriga, TToken_string &key,TLine_movmag &rest) const; + // @member: compone la chiave a partire dalla riga dello sheet + TToken_string line2key(int numriga) const; + // @member: compone la dati a partire dalla riga dello sheet + TLine_movmag line2data(int numriga) const; + // @member: estrae dalla Tokenstring della chiave i valori corrispondenti ai campi del file + static TString key2field(TToken_string &key,const char * f); + // @member: memorizza la linea come "da togliere" + int delete_line(TToken_string &key,TLine_movmag &rest); + // @member: memorizza la linea come "da aggiungere" + int insert_line(TToken_string &key,TLine_movmag &rest); + // @member: effettua l'aggiornamento dei saldi relativi alle giacenze interessate al movimento + int update_balances() const; + // @member: effettua l'aggiornamento dei saldi di una giacenza + int update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int sign) const; + // @member: effettua l'aggiornamento di un saldo di una giacenza + void update_balance(TRectype & magrec, const char * fieldname, real diff) const; + + static void giac_putkey(TLocalisamfile & mag,TString16 annoes,TToken_string curr_key); + static bool lock_anamag(const char *codart); + static bool unlock_anamag(const char *codart) ; + +public: +// IO ad alto livello + const char *get_next_key() ; + virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock); + virtual int remove(TBaseisamfile& f) const ; + virtual int write(TBaseisamfile& f) const ; + virtual int rewrite(TBaseisamfile& f) const ; + int force_update_bal(); + + // + int codice_esercizio(TDate &d); + // costruttori e distruttori + TMov_mag(bool autoload=FALSE); + virtual ~TMov_mag(); + +}; + +bool rebuild_balances(TString16 annoes, bool reset_giac=FALSE); + +#define FORM_MAXGIACLEV 4 // numero di livelli giacenza nel form +#define FORM_MAXARTLEV 8 // numero di livelli codice nel form +#define UNKNOWN_NAME "-" + +class TForm_stampemg : public TForm +{ + bool _permag; + int _fromlivgiac,_tolivgiac,_fromlivart,_tolivart; + bool _sottocatmer; + TMag_livelli * _giaclev,*_artlev; + TDecoder *_giacgrp,*_artgrp; + bool setdettaglio(bool show, int fromlivart,int livart,int fromlivgiac,int livgiac,bool dettgiac); + void add_giaclev(TString &levname); + +public: + void gruppogiac(TForm_item &cf, TToken_string &s); + void gruppoart(TForm_item &cf, TToken_string &s); + bool validate(TForm_item &cf, TToken_string &s); + void setcatmer(bool catmer,bool sottoc=FALSE); + bool setdett_perart(int fromlivart,int livart,int fromlivgiac,int livgiac,bool showmag, bool showdep); + bool setdett_permag(int fromlivart,int livart,int fromlivgiac,int livgiac,bool showmag, bool showdep,bool showdett); + TForm_stampemg(const char *name,const char *code) ; + ~TForm_stampemg(); +}; + + +#include "..\ve\sconti.h" + +class TCondizione_vendita : public TObject +{ + TString80 _sconto; + TString16 _codiva; + bool _ivarid; + real _prezzo; + real _provv; + real _molt_sconto; + TCliFor * _clifo; + TLocalisamfile _condv; + TLocalisamfile _rcondv; + TLocalisamfile _sconti; + TLocalisamfile * _anamag; // file passato e posizionato esternamente + TLocalisamfile * _umart; // file passato e posizionato esternamente + TConfig * _config_ditta; + bool _load_mask; + + bool cerca(int tiporicerca,const char * cod, const real & qta); + +protected: + + TRectype & testa() const { return (_condv.curr()); } + TRectype & riga() const { return (_rcondv.curr()); } + TLocalisamfile & anamag() const { CHECK(_anamag, "Anagrafica di magazzino non inizializzata") ; return *_anamag; } + TLocalisamfile & umart() const { CHECK(_umart, "Anagrafica di unita' di misura magazzino non inizializzata") ; return *_umart; } + +public: + real get_prezzo() const { return _prezzo; } + + TConfig &config_ditta() const { return *_config_ditta; } + void set_config( TConfig & ditta){ _config_ditta = &ditta; } + void set_anamag(TLocalisamfile & anamag) { _anamag = &anamag; } + void set_umart(TLocalisamfile & umart) { _umart = &umart; } + + bool gestum() const { return _condv.get_bool("GESTUM"); } + + // prepara la ricerca + void put_condv(const char *tipocv,const char * codcv,const char *catven,const char *tipocf,const char *codcf); + void put_listino(const char * codlist,const char *catven); + void put_contratto(const char * codcontr,const char *tipocf,const char *codcf); + void put_offerta(const char * codoff); + // ricerca il codice + bool ricerca(const char * cod,const real & qta=0) ; + + TCondizione_vendita(TConfig * _ditta = NULL, TLocalisamfile * anamag = NULL, TLocalisamfile * umart = NULL); + ~TCondizione_vendita() {} +}; + + +#define TIPOREG_VEN 1 +#define TIPOREG_ACQ 2 +#define TIPOREG_IVA 3 +#define TIPOREG_INCPAG 4 +#define TIPOREG_GIO 5 +#define TIPOREG_LIBSOC 6 +#define TIPOREG_CESPIT 7 +#define TIPOREG_INVENT 8 +#define TIPOREG_GIOMAG 9 + +class TRegistro_std : public TRectype +{ + TString80 _intest; + +protected: + bool read(const char* cod, int year); + +public: + int year() const; + const TString& code() const ; + + const TString & descr() const { return get("S0"); } + int tipo() const { return get_int("I0"); } + + const TString & cod_intest() const { return get("S7"); } + const TString intest() const; + const TString & luogo_conserv() const { return get("S1"); } + int pag_stampate() const{ return get_int("I1"); } + int pag_numerate() const{ return get_int("I2"); } + TDate vidimazione() const { return get_date("D0"); } + TDate scadenza() const { return get_date("D1"); } + TDate last_print() const { return get_date("D3"); } + bool stampa_intditta() const { return get_bool("B9"); } + + void set_pag_stampate(int p) { put("I1",p); } + void set_last_print(TDate &d) { put("D3",d); } + + bool write(bool re) const ; + bool rewrite() const {return write(TRUE);} + + TRegistro_std(const char* code = "", int year = 0); + virtual ~TRegistro_std() {} +}; + +#endif //__MGLIB_H diff --git a/mg/mglib01.cpp b/mg/mglib01.cpp index fd4ffbff8..6aed13609 100755 --- a/mg/mglib01.cpp +++ b/mg/mglib01.cpp @@ -8,287 +8,10 @@ #include #include -#include "mglib01.h" -#include "mglib02.h" +#include "mglib.h" #include "anamag.h" #include "umart.h" #include "mag.h" -#include "..\cg\cglib.h" - -// ************************************** -// ************************************** -// ************************************** -// *** classi per la libreria -// *** -//***** -// THead_lines_record -// metodi protected -void THead_lines_record::renum_key(const char * kfield,const char * val) -{ - TRectype::renum_key(kfield, val); // Aggiorna testata - _rows->renum_key(kfield, val); // Aggiorna righe -} - -TRectype & THead_lines_record::row(int index) const // riga del corpo -{ - if (index > _rows->rows() || index < 0) - CHECKD(FALSE, "Riga non esistente ", index); - return _rows->row(index, FALSE); -} - -void THead_lines_record::put_str(const char* fieldname, const char* val) -{ - TString v(val); - // cambio - //if (strcmp(fieldname, "TIPODOC") == 0 && TRectype::get("TIPODOC") != v) - //{ - // TAuto_variable_rectype::put_str(fieldname, v); - // reset_fields(*this); - // set_fields(*this); - //} - //else - { - TAuto_variable_rectype::put_str(fieldname, v); - dirty_fields(); - } -} - -//***** -// metodi public -THead_lines_record::THead_lines_record(int hfn, int rfn,const char *numfield): - TAuto_variable_rectype(hfn), - _file(hfn), - _rfile(rfn), - _numfield(numfield) -{ - _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe -} - -THead_lines_record::THead_lines_record(const TBaseisamfile* i,int rfn,const char *numfield): - TAuto_variable_rectype(i), - _numfield(numfield) -{ - _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe -} - -THead_lines_record::THead_lines_record(const TRectype & r,int rfn,const char *numfield): - TAuto_variable_rectype(r), - _numfield(numfield) -{ - _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe -} - -// @doc INTERNAL - -// @mfunc costruttore di copia -THead_lines_record::THead_lines_record(const THead_lines_record& r): - TAuto_variable_rectype((TAuto_variable_rectype &)r) -{ - // copia.. - _rows= new TRecord_array(* r._rows); // inizializza il record array delle righe - _nuovo=r._nuovo; - _file=r._file; // file principale - _rfile=r._rfile; // file delle righe - _numfield=r._numfield; -} - -THead_lines_record::~THead_lines_record() -{ - delete _rows; -} - - -// setta a dirty i campi -void THead_lines_record::dirty_fields() -{ -} - -TRectype & THead_lines_record::operator =(const TRectype & r) -{ - TRectype::operator=(r); - reset_fields(*this); - set_fields(*this); - return *this; -} - -TRectype & THead_lines_record::operator =(const char * r) -{ - TRectype::operator=(r); - reset_fields(*this); - set_fields(*this); - return *this; -} - -void THead_lines_record::zero(const char * fieldname) -{ - // resetta il record righe solo se ..... -// if (strcmp(fieldname, "TIPODOC") == 0) - reset_fields(*this); - TAuto_variable_rectype::zero(fieldname); - dirty_fields(); -} - -void THead_lines_record::zero(char c) -{ - reset_fields(*this); - TAuto_variable_rectype::zero(c); -} - - -// settaggio campi variabili -void THead_lines_record::set_fields(TAuto_variable_rectype & rec) -{ -} - - -int THead_lines_record::read(TBaseisamfile& f, word op, word lockop) -{ - TRectype line_key(_rfile); - - int err = TRectype::read(f,op,lockop); - - copy_linekey(head(),line_key); - if (err == NOERR) - { - _nuovo = FALSE; - _rows->read(line_key); //ok - } - else - { - // nuovo oggetto: resetta tutto - _nuovo = TRUE; - destroy_rows(); - _rows->set_key((TRectype *)(line_key.dup())); // ok - } - return err; -} - -int THead_lines_record::readat(TBaseisamfile& f, TRecnotype nrec, word lockop) -{ - TRectype line_key(_rfile); - - int err = TRectype::readat(f,nrec,lockop); - - if (err == NOERR) - { - _nuovo = FALSE; - _rows->read(line_key); //ok - } - else - { - // nuovo oggetto: resetta tutto - _nuovo = TRUE; - destroy_rows(); - _rows->set_key((TRectype *)(line_key.dup())); // ok - } - return err; -} - - -/*int THead_lines_record::read(const TRectype& rec) -{ - head() = rec; - TRectype line_key(_rows->key()); - - copy_linekey(head(),line_key); - - TLocalisamfile afile(_file); - int err = TRectype::read(afile); - if (err == NOERR) - { - _nuovo = FALSE; - _rows->read(line_key); //ok - } - else - { - // nuovo oggetto: resetta tutto - _nuovo = TRUE; - head() = rec; - destroy_rows(); - _rows->set_key(&line_key); // ok - } - return err; -} -*/ -int THead_lines_record::write(TBaseisamfile& f) const -{ - return write_rewrite(f,FALSE); -} - -int THead_lines_record::rewrite(TBaseisamfile& f) const -{ - return write_rewrite(f,TRUE); -} - - -int THead_lines_record::write_rewrite(TBaseisamfile& f,bool re ) const -{ - const bool nuovo = _nuovo; // E' nuovo di zecca! - if (nuovo && re) // quindi ... - re = FALSE; // ... non fare la rewrite - - int err = NOERR; - if (re) - { - // rewrite: - err = _rows->write(re); - if (err == NOERR) - { - err = TRectype::rewrite(f); - if (err != NOERR) - err = TRectype::write(f); - } - } - else - { - // write: - if (nuovo) - { - //THead_lines_record &myself=*this; - //if (numero() <= 0) - // myself.renum(); - do - { - err = TRectype::write(f); - if (err == _isreinsert) // usa il flag _nuovo per decidere se - ((THead_lines_record *)this)->renum(); - } while (err == _isreinsert); - ((THead_lines_record *)this)->_nuovo = FALSE; - } - else - { - err = TRectype::write(f); - if (err != NOERR) - err = TRectype::rewrite(f); - } - if (err == NOERR) - err = _rows->write(re); - } - return err; -} - - -int THead_lines_record::remove(TBaseisamfile& f) const -{ - int err = _rows->remove(); - if (err == NOERR) - err = TRectype::remove(f); - return err; -} - - -// ********************************** -// ********************************** -// ********************************** -// ********************************** -// fine classi per la libreria - - - - - - - @@ -390,6 +113,68 @@ TString TMag_livelli::build_tabcode(const TString & pc, const int levnum) // ******************************* // ******************************* +#define MAXSIMBOLS 256 +#define MAXSTATES 25 +class TStateset { + unsigned char _container[MAXSTATES]; + int _current; +public: + TStateset & empty(); + TStateset & enclose(int e); + TStateset & singleton(int e); + TStateset & cap(TStateset & s); + int get_first() ; + int get_next() ; + bool is_empty() const; + bool is_member(int e) const; + TStateset(); + ~TStateset() {}; +}; + +struct TAutoma_state { + short _transaction[MAXSIMBOLS]; + TString16 * _label; + bool _final; +}; + +// ******************************* +// ******************************* +// automa per il riconoscimento di metacaratteri +class TR_automa { + TAutoma_state st[MAXSTATES]; + short _maxstate; +protected: + TStateset union_of_closures(TStateset &s); + + bool is_final(int statenum) const; + bool is_final(TStateset states) const; + + TR_automa & set_label(int statenum, const char *label); + bool is_state(int statenum); + const char *label(int statenum); + int label2state(const char * label); + + void del_trans(int statenum,unsigned char symbol); + int trans_to(int statenum,unsigned char symbol); + bool _isdeterministic; + +public: + TR_automa & reset_state(int statenum=-1); + + void add_tran(int statenum,unsigned char symbol,int next);// aggiunge una transizione + int add_state(const char * label);// aggiunge uno stato + TR_automa & set_final(int statenum,bool v=TRUE); // pone lo stato come finale + + bool is_deterministic() {return _isdeterministic;}; // + bool recognized(const char * s); // tenta di riconoscere la stringa passata + + TR_automa(TR_automa *a=NULL,bool makedet=FALSE); // duplica un automa (e lo rende deterministico) + ~TR_automa(); + static void set2label(const TStateset ss,TString16 & label); + static void label2set(const TString16 & label,TStateset & ss); + +}; + // ******************************* TStateset::TStateset() @@ -891,557 +676,5 @@ TMetachar::~TMetachar () // ************************************** // *** classi per il magazzino // *** -long giac_last_item(const char * annoes, const char *codart) -{ - long r=0; - TLocalisamfile mag(LF_MAG); - mag.put("ANNOES",annoes); - mag.put("CODART",codart); - mag.put("NRIGA",1); - if (mag.read()==NOERR) - { - do { - r=mag.get_long("NRIGA"); - } while (mag.next()==NOERR && mag.get("CODART")==codart); - } - return r; -} - -// ********************* -// movimenti di magazzino - -// causali - -int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) -{ - switch (tiposaldo) { - case s_giac: - return get_int("I0"); - case s_acq: - return get_int("I1"); - case s_ent: - return get_int("I2"); - case s_ven: - return get_int("I3"); - case s_usc: - return get_int("I4"); - case s_ordc: - return get_int("I5"); - case s_ordf: - return get_int("I6"); - case s_incl: - return get_int("I7"); - case s_acl: - return get_int("I8"); - case s_prodc: - return get_int("I9"); - case s_prodf: - return get_int("I10"); - case s_rim: - return get_int("I11"); - case s_scart: - return get_int("I12"); - case s_label: - return get_int("I13"); - default: - return 0; - } -} -TCausale_magazzino::TCausale_magazzino(const char * codice): - TRectype(LF_TAB) -{ - TTable f("CAU"); - f.put("CODTAB",codice); - if (f.read() != NOERR) - zero(); - else - *this=(TCausale_magazzino &)f.curr(); -} -TCausale_magazzino::~TCausale_magazzino() -{ -} - -// movimenti -TLine_movmag ::TLine_movmag(const TLine_movmag &l) -{ - um=l.um; - quant=l.quant; - prezzo=l.prezzo; -} - -int TLine_movmag::operator==(TLine_movmag &l) -{ - return (um==l.um)&&(quant==l.quant)&&(prezzo==l.prezzo); -} - - - -TMov_mag::TMov_mag() : - THead_lines_record(LF_MOVMAG,LF_RMOVMAG,"NRIG"), - lines_to_add(), lines_to_subtract() -{ -} - -TMov_mag::~TMov_mag() -{ -} -//void TMov_mag::dirty_fields() -//{ -//} - -// rinumerazione automatica: numdoc>=0 -// (con creazione nuova chiave) -long TMov_mag::renum(long numdoc) -{ - if (numdoc <= 0) - numdoc = atoi(get_next_key()); - char num[16]; sprintf(num, "%ld", numdoc); - renum_key("NUMREG", num); // Aggiorna testata - return numdoc; -} - -// copia la chiave dal file principale a quello delle righe -void TMov_mag::copy_linekey(const TRectype & headrec, TRectype & linesrec) -{ - // ...qui basta una put tra Rectype.... - linesrec.put("NUMREG",headrec.get("NUMREG")) ; -} - -int TMov_mag::read(TBaseisamfile& f, word op , word lockop) -{ - TToken_string l_key; - TLine_movmag l_data; - - int res=THead_lines_record::read(f,op,lockop); - // reset delle strutture per il controlli delle variazioni dei saldi - _codcaus=get("CODCAUS"); - _annoes=get("ANNOES"); - lines_to_add.destroy(); - lines_to_subtract.destroy(); - for (int i=0; iinsert_line(l_key,l_data); - } - res=update_balances(); - return res; -} - -int TMov_mag::write(TBaseisamfile& f) const -{ - int res; - TToken_string l_key; - TLine_movmag l_data; - // memorizza le variazioni - for (int i=0; iinsert_line(l_key,l_data); - } - if ((res=THead_lines_record::write(f))==NOERR ) - // effettua la variazione dei saldi - res=update_balances(); - return res; -} - -int TMov_mag::rewrite(TBaseisamfile& f) const -{ - int res; - TToken_string l_key; - TLine_movmag l_data; - // memorizza le variazioni - for (int i=0; iinsert_line(l_key,l_data); - } - if ((res=THead_lines_record::rewrite(f))==NOERR ) - // effettua la variazione dei saldi - res=update_balances(); - return res; -} - -const char *TMov_mag::get_next_key() -{ - TLocalisamfile f(LF_MOVMAG); - f.last(); - int a=atoi(f.get("NUMREG"))+1; - return _nextcod.format("%d",a); -} - - -// settaggio campi variabili -//void TMov_mag::set_fields(TAuto_variable_rectype & rec) -//{ -//} - - -//******* -// gestione delle variazione dei saldi -// -// -TLine_movmag TMov_mag::line2data(int numriga) const -{ - TLine_movmag rest; - rest.um=row(numriga).get("UM"); - rest.quant=(const char *)row(numriga).get("QUANT"); - rest.prezzo=(const char *)row(numriga).get("PREZZO"); - return rest; -} - -TToken_string TMov_mag::line2key(int numriga) const -{ - TToken_string key; - key.add(row(numriga).get("CODART")); - key.add(row(numriga).get("CODMAG")); - key.add(row(numriga).get("LIVGIAC")); - return key; -} - -TString TMov_mag::key2field(TToken_string &key,const char *fieldname) -{ - if (strcmp(fieldname,"CODART")==0) - return key.get(0); - if (strcmp(fieldname,"CODMAG")==0) - return key.get(1); - if (strcmp(fieldname,"LIVGIAC")==0) - return key.get(2); - CHECKS(FALSE, "Nome di campo non appartenente al file righe mov ", fieldname); - return ""; -} - - -int TMov_mag::insert_line(TToken_string &k,TLine_movmag &r) -{ - if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) { - lines_to_add.add(k,r); - } else { - if (lines_to_subtract.is_key(k)&& (TLine_movmag &)lines_to_subtract[k]==r) - // modifica annullata - lines_to_subtract.remove(k); - else - // linea modificata - lines_to_add.add(k,r); - } - return 0; -} - -int TMov_mag::delete_line(TToken_string &k,TLine_movmag &r) -{ - if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) { - lines_to_subtract.add(k,r); - } else { - if (lines_to_add.is_key(k)&& r==(TLine_movmag &)lines_to_add[k] ) - // modifica annullata - lines_to_add.remove(k); - else - // linea modificata - lines_to_subtract.add(k,r); - } - return 0; -} - -bool TMov_mag::unlock_anamag(const char *codart) -{ - TLocalisamfile anamag(LF_ANAMAG); - anamag.put("CODART",codart); - return (anamag.read(_isequal,_unlock)==NOERR); -} - -bool TMov_mag::lock_anamag(const char *codart) -{ - TLocalisamfile anamag(LF_ANAMAG); - anamag.put("CODART",codart); - bool insert_new=TRUE; - TString mess; - mess << "Il record di anagrafica dell'articolo ''"<< codart << "'' risulta essere già in uso.\n Interrompo ?"; - TTimed_breakbox bbox((const char *)mess,10); - do { - if (anamag.read(_isequal,_testandlock)==NOERR) - return TRUE; - } while (bbox.run()!=K_ESC); - return FALSE; -} - - -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")); -} - - -// aggiorna tutti i saldi in base alle modifiche fatte. -// il lock su anagrafica dovrebbe garantire il lock su tutte le -// giacenze dell'articolo -int TMov_mag::update_balances() const -{ - bool updated_bal=TRUE; - TLocalisamfile mag(LF_MAG); - mag.setkey(2); - - - TString_array keys_to_add,keys_to_remove; - ((TMov_mag *)this)->lines_to_add.get_keys(keys_to_add); - ((TMov_mag *)this)->lines_to_subtract.get_keys(keys_to_remove); - - // aggiunge i saldi nuovi - keys_to_add.sort(); - TToken_string * curr_key=(TToken_string *)keys_to_add.first_item(); - - while (curr_key) { - TArticolo 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",giac_last_item(get("ANNOES"),key2field(*curr_key,"CODART"))+1); - 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; -} - -// 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"); - - 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; -} - - -void TMov_mag::update_balance(TRectype & magrec, const char * fieldname, real diff) const -{ - magrec.put(fieldname,magrec.get_int(fieldname)+diff); -} - -HIDDEN TEsercizi_contabili _esercizi; - -int TMov_mag::codice_esercizio(TDate &d) -{ - return _esercizi.date2esc(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); - TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino - - // 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 - - for (int i=0; iput("CODART",codart); - rv=(anamag->read(_isequal,_unlock)==NOERR); - delete anamag; - anamag=NULL; - return rv; - } - return TRUE; -} - -bool lock_anamag(const char *codart) -{ - if (!anamag) - anamag = new TLocalisamfile(LF_ANAMAG); - anamag->put("CODART",codart); - bool insert_new=TRUE; - TString mess; - mess << "Il record di anagrafica dell'articolo ''"<< codart << "'' risulta essere già in uso.\n Interrompo ?"; - TTimed_breakbox bbox((const char *)mess,10); - do { - if (anamag->read(_isequal,_testandlock)==NOERR) - return TRUE; - } while (bbox.run()!=K_ESC); - return FALSE; -} - diff --git a/mg/mglib02.cpp b/mg/mglib02.cpp index 3cfd5f97e..5cda519d9 100755 --- a/mg/mglib02.cpp +++ b/mg/mglib02.cpp @@ -1,6 +1,9 @@ -#include "mglib02.h" +#include "mglib.h" +#include "anamag.h" +#include "mag.h" #include -#include "../cg/cglib.h" + +// libreira per i movimenti char * TNome_valorizz[]= { "Ultimo costo", "Media ultimi costi", "Prezzo di listino", @@ -10,237 +13,11 @@ char * TNome_valorizz[]= { "FIFO Ragionieristico", "LIFO Ragionieristico" } ; -/*bool TArticolo::load_um() -{ - const int index = log2ind(logicnum); - TRectype & rec = get_body_record(logicnum); - - set_body_key(rec); - TRecord_array * r = new TRecord_array(logicnum, (TString &) _numfields[index]); - _files.add( r, index); -}*/ - -int TMultiple_rectype::find(int logicnum, const char * fieldname, const char * s, int from, bool reverse) const -{ - const TRecord_array & recarray = body(logicnum); - const int last = recarray.last_row(); - const int len = s ? strlen(s) : 0; - - if (reverse) - { - if (from > 0) - { - if (len == 0) - return from - 1; - for (int i = recarray.pred_row(from); i > 0; i = recarray.pred_row(i)) - if (((TRectype &)recarray[i]).get(fieldname) == s) - return i; - } - } - else - { - if (last > from) - { - if (len == 0) - return from + 1; - for (int i = recarray.succ_row(from); i <= last; i = recarray.succ_row(i)) - if (((TRectype &)recarray[i]).get(fieldname) == s) - return i; - } - } - return -1; -} - -int TMultiple_rectype::write_rewrite(TBaseisamfile & f, bool re) const -{ - int err = NOERR; - - if (_nuovo && re) // E' nuovo di zecca! quindi ... - re = FALSE; // ... non fare la rewrite - - if (re) - { - for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) - { - TRecord_array * r = (TRecord_array *) _files.objptr(i); - if (r) - err = r->write(re); - } - // rewrite: - if (err == NOERR) - { - err = TRectype::rewrite(f); - if (err != NOERR) - err = TRectype::write(f); - } - } - else - { - // write: - if (_nuovo) - { - do - { - err = TRectype::write(f); - if (err == _isreinsert) // usa il flag _nuovo per decidere se - ((TMultiple_rectype *)this)->renum(); - } while (err == _isreinsert); - ((TMultiple_rectype *)this)->_nuovo = FALSE; - } - else - { - err = TRectype::write(f); - if (err != NOERR) - err = TRectype::rewrite(f); - } - for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) - { - TRecord_array * r = (TRecord_array *)_files.objptr(i); - if (r) - err = r->write(re); - } - } - return err; -} - -void TMultiple_rectype::remove_body(int logicnum) -{ - const int index = log2ind(logicnum); - - if (_files.objptr(index) != NULL) - _files.remove(index); -} - -int TMultiple_rectype::log2ind(int logicnum) const -{ - if (logicnum == 0) - return 0; - for (int i = _nfiles - 1; i >= 0 ; i--) - if (_logicnums[i] == logicnum) - return i; - NFCHECK("Can't find file %d in multiple record", logicnum); - return 0; -} - -void TMultiple_rectype::load_rows_file(int logicnum) -{ - const int index = log2ind(logicnum); - TRectype & rec = get_body_record(logicnum); - - set_body_key(rec); - TRecord_array * r = new TRecord_array(logicnum, (TString &) _numfields[index]); - _files.add( r, index); -} - -TRecord_array & TMultiple_rectype::body(int logicnum) const -{ - const int index = log2ind(logicnum); - - if (_files.objptr(index) == NULL) - ((TMultiple_rectype *) this)->load_rows_file(logicnum); - return (TRecord_array &) _files[index]; -} - -void TMultiple_rectype::renum_key(const char * kfield,const char * val) -{ - TRectype::renum_key(kfield, val); // Aggiorna testata - for (int i = _nfiles - 1; i >= 0 ; i--) - body(_logicnums[i]).renum_key(kfield, val); // Aggiorna righe -} - - -TRectype & TMultiple_rectype::operator =(const TRectype & r) -{ - TRectype::operator=(r); - reset_fields(*this); - set_fields(*this); - return *this; -} - -TRectype & TMultiple_rectype::operator =(const char * r) -{ - TRectype::operator=(r); - reset_fields(*this); - set_fields(*this); - return *this; -} - -void TMultiple_rectype::zero(char c) -{ - reset_fields(*this); - TAuto_variable_rectype::zero(c); - for (int i = _nfiles - 1; i >= 0 ; i--) - if (_files.objptr(i) != NULL) - _files.remove(i); -} - - -int TMultiple_rectype::read(TRectype & rec, word op, word lockop) -{ - TLocalisamfile f(num()); - - *this = rec; - - int err = TRectype::read(f, op, lockop); - - for (int i = _nfiles - 1; i >= 0 ; i--) - if (_files.objptr(i) != NULL) - _files.remove(i); - _nuovo = err != NOERR; - return err; -} - -int TMultiple_rectype::remove(TBaseisamfile & f) const -{ - int err = NOERR; - - for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) - { - TRecord_array & r = body(_logicnums[i]); - r.remove(); - } - if (err == NOERR) - err = TRectype::remove(f); - return err; -} - -// @doc INTERNAL -TMultiple_rectype::TMultiple_rectype(int hfn) - : TAuto_variable_rectype(hfn), _nuovo(TRUE), _nfiles(0) -{ -} - - // @ cmember costruttore dal file -void TMultiple_rectype::add_file(int logicnum, const char * numfield) -{ - CHECK(_nfiles < maxfiles, "Too many files added"); - _logicnums[_nfiles] = logicnum; - _numfields.add(numfield, _nfiles++); -} - -TMultiple_rectype::TMultiple_rectype(const TBaseisamfile* file) - :TAuto_variable_rectype(file), _nuovo(TRUE), _nfiles(0) -{ -} - - // @ cmember costruttore dal record -TMultiple_rectype::TMultiple_rectype(const TRectype & rec) - :TAuto_variable_rectype(rec), _nuovo(TRUE), _nfiles(0) -{ -} - -// @mfunc costruttore di copia -TMultiple_rectype::TMultiple_rectype(const TMultiple_rectype& r) - :TAuto_variable_rectype(r), _files(r._files) -{ - // copia.. - _nuovo=r._nuovo; - _nfiles=r._nfiles; // file delle righe - _numfields=r._numfields; -} HIDDEN TString16 _mg_null_str; + + const TString & TArticolo::get_str(const char* fieldname) const { if (*fieldname != '#') @@ -356,7 +133,7 @@ bool TArticolo::unlock() if (*(const char *)_codice) { TLocalisamfile anag(LF_ANAMAG); - anag.set_curr(this); + anag.curr()=*this; rv=(anag.read(_isequal,_unlock)==NOERR); return rv; } @@ -370,7 +147,7 @@ bool TArticolo::lock_and_prompt() TTimed_breakbox bbox((const char *)mess,10); do { TLocalisamfile anag(LF_ANAMAG); - anag.set_curr(this); + anag.curr()=*this; if (anag.read(_isequal,_testandlock)==NOERR) return TRUE; } while (bbox.run()!=K_ESC); @@ -382,6 +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"); _codice = new TRecfield(*this, ANAMAG_CODART); if (codice && *codice) read(codice); @@ -398,6 +178,11 @@ TArticolo::~TArticolo() delete _codice; } +// ***************** +// + + + const TString & TArticolo_giacenza::get_str(const char* fieldname) const { if (*fieldname != '#') @@ -800,6 +585,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"); if (last_esercizio < 0 ) { TEsercizi_contabili e; @@ -820,3 +607,682 @@ TArticolo_giacenza::TArticolo_giacenza(const TRectype& rec) } +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "..\ve\velib01.h" +#include "..\ve\sconti.h" +#include "..\ve\veconf.h" + + +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; + } + return cerca(tiporic,codice, qta); +} + + +bool TCondizione_vendita::cerca( int tiporicerca, const char * codriga , const real & qta) +{ + if( config_ditta().get_bool( "GES", "ve", tiporicerca ) ) + { + _condv.setkey( 1 ); + + if (_condv.get("COD").empty()) + return FALSE; + switch( tiporicerca ) + { + case A_CONTRATTI: + { + } + break; + case A_LISTINI: + { + _condv.put("TIPOCF", ""); + _condv.put("CODCF", ""); + if( !config_ditta().get_bool("GESLISCV", "ve")) + _condv.put("CATVEN", ""); + } + break; + case A_OFFERTE: + { + } + break; + } + if( _condv.read( ) == NOERR ) + { + // si posiziona sulla riga + const bool gest_scagl = _condv.get_bool("GESTSCAGL"); + const TString16 seqricrighe( _condv.get( "SEQRIC" ) ); + bool found = FALSE; + + for( int i = 0; !found && i < seqricrighe.len( ); i ++ ) + { + _rcondv.zero( ); + _rcondv.put( "TIPO", _condv.get( "TIPO")); + _rcondv.put( "CATVEN", _condv.get( "CATVEN")); + _rcondv.put( "TIPOCF", _condv.get( "TIPOCF")); + _rcondv.put( "CODCF", _condv.get( "CODCF")); + _rcondv.put("COD", _condv.get("COD")); + if (gest_scagl) + _rcondv.put("NSCAGL", 1); + + char ricerca = seqricrighe[ i ]; + _rcondv.put( "TIPORIGA", ricerca ); + switch( ricerca ) + { + case 'A': + { + _rcondv.put( "CODRIGA", codriga); + if (_rcondv.read() != NOERR && + _rcondv.prev() == NOERR && + _rcondv.get("TIPORIGA")[0] == 'A') + { + const TString cod_found(_rcondv.get("CODRIGA")); + return cod_found.compare(codriga, cod_found.len()) == 0; + } + } + break; + case 'R': + _rcondv.put("CODRIGA", anamag().get( "RAGGFIS")); + _rcondv.read(); + break; + case 'S': + { + _rcondv.put( "CODRIGA", anamag().get("GRMERC")); + _rcondv.read( ); + } + break; + case 'G': + { + _rcondv.put( "CODRIGA", anamag().get("GRMERC").left(3)); + _rcondv.read( ); + } + break; + default: + break; + } + found = _rcondv.good(); + } + // individua lo scaglione corretto in base alla quantita' + if (found && gest_scagl) + { + TRectype rec(_rcondv.curr()); + int last_scagl = 0; + int scagl = _rcondv.get_int("NSCAGL"); + real qta_lim(_rcondv.get_real("QLIM")); + while (_rcondv.good() && scagl > last_scagl && qta_lim > ZERO && qta > qta_lim) + { + if (_rcondv.next() == NOERR) + { + last_scagl = scagl; + scagl = _rcondv.get_int("NSCAGL"); + qta_lim =_rcondv.get_real("QLIM"); + rec = _rcondv.curr(); + } + } + _rcondv.read(rec); + } + _prezzo = _rcondv.get_real("PREZZO"); + return found; + } + } + // Ricerca fallita + return FALSE; +} + +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); +} + +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,"",""); +} +void TCondizione_vendita::put_contratto(const char * codcontr,const char *tipocf,const char *codcf) +{ + put_condv("C",codcontr,"",tipocf,codcf); +} +void TCondizione_vendita::put_offerta(const char * codoff) +{ + put_condv("C",codoff,"","",""); +} + + +TCondizione_vendita::TCondizione_vendita(TConfig * ditta, + TLocalisamfile * anamag, TLocalisamfile * umart) + : _condv(LF_CONDV), _rcondv(LF_RCONDV), + _sconti( LF_SCONTI ), + _anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE) +{ +} + + +// ********************* +// movimenti di magazzino + +// causali + +int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) +{ + switch (tiposaldo) { + case s_giac: + return get_int("I0"); + case s_acq: + return get_int("I1"); + case s_ent: + return get_int("I2"); + case s_ven: + return get_int("I3"); + case s_usc: + return get_int("I4"); + case s_ordc: + return get_int("I5"); + case s_ordf: + return get_int("I6"); + case s_incl: + return get_int("I7"); + case s_acl: + return get_int("I8"); + case s_prodc: + return get_int("I9"); + case s_prodf: + return get_int("I10"); + case s_rim: + return get_int("I11"); + case s_scart: + return get_int("I12"); + case s_label: + return get_int("I13"); + default: + return 0; + } +} + + +TCausale_magazzino::TCausale_magazzino(const char * codice): + TRectype(LF_TAB) +{ + TTable f("CAU"); + f.put("CODTAB",codice); + if (f.read() != NOERR) + zero(); + else + *this=(TCausale_magazzino &)f.curr(); +} +TCausale_magazzino::~TCausale_magazzino() +{ +} + +// movimenti +TLine_movmag ::TLine_movmag(const TLine_movmag &l) +{ + um=l.um; + quant=l.quant; + prezzo=l.prezzo; +} + +int TLine_movmag::operator==(TLine_movmag &l) +{ + return (um==l.um)&&(quant==l.quant)&&(prezzo==l.prezzo); +} + + + +TMov_mag::TMov_mag(bool autoload_rows) : + TMultiple_rectype(LF_MOVMAG), + lines_to_add(), lines_to_subtract() +{ + add_file(LF_RMOVMAG,"NRIG",autoload_rows); +} + +TMov_mag::~TMov_mag() +{ +} + +// valuta il valore della chiave per un nuovo record +bool TMov_mag::renum() +{ + put("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("NUMREG",get("NUMREG")) ; +} + +int TMov_mag::read(TBaseisamfile& f, word op , word lockop) +{ + TToken_string l_key; + TLine_movmag l_data; + + int res=TMultiple_rectype::read(f,op,lockop); + + // reset delle strutture per il controlli delle variazioni dei saldi + _codcaus=get("CODCAUS"); + _annoes=get("ANNOES"); + lines_to_add.destroy(); + lines_to_subtract.destroy(); + for (int i=0; iinsert_line(l_key,l_data); + } + if ((res=TMultiple_rectype::write(f))==NOERR ) + // effettua la variazione dei saldi + res=update_balances(); + return res; +} + +int TMov_mag::rewrite(TBaseisamfile& f) const +{ + int res; + TToken_string l_key; + TLine_movmag l_data; + // memorizza le variazioni + for (int i=0; iinsert_line(l_key,l_data); + } + if ((res=TMultiple_rectype::rewrite(f))==NOERR ) + // effettua la variazione dei saldi + res=update_balances(); + return res; +} + +const char *TMov_mag::get_next_key() +{ + TLocalisamfile f(LF_MOVMAG); + f.last(); + int a=atoi(f.get("NUMREG"))+1; + return _nextcod.format("%d",a); +} + +//******* +// gestione delle variazione dei saldi +// +// +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; iinsert_line(l_key,l_data); + } + res=update_balances(); + return res; +} + +TLine_movmag TMov_mag::line2data(int numriga) const +{ + TLine_movmag rest; + rest.um =(const char *)body().row(numriga).get("UM"); + rest.quant =(const char *)body().row(numriga).get("QUANT"); + rest.prezzo=(const char *)body().row(numriga).get("PREZZO"); + return rest; +} + +TToken_string TMov_mag::line2key(int numriga) const +{ + TToken_string key; + TString16 nr; + nr << numriga; + key.add(body().row(numriga).get("CODART")); + key.add(body().row(numriga).get("CODMAG")); + key.add(body().row(numriga).get("LIVGIAC")); + key.add(nr); + return key; +} + +TString TMov_mag::key2field(TToken_string &key,const char *fieldname) +{ + if (strcmp(fieldname,"CODART")==0) + return key.get(0); + if (strcmp(fieldname,"CODMAG")==0) + return key.get(1); + if (strcmp(fieldname,"LIVGIAC")==0) + return key.get(2); + CHECKS(FALSE, "Nome di campo non appartenente al file righe mov ", fieldname); + return ""; +} + + +int TMov_mag::insert_line(TToken_string &k,TLine_movmag &r) +{ + if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) { + lines_to_add.add(k,r); + } else { + if (lines_to_subtract.is_key(k)&& (TLine_movmag &)lines_to_subtract[k]==r) + // modifica annullata + lines_to_subtract.remove(k); + else + // linea modificata + lines_to_add.add(k,r); + } + return 0; +} + +int TMov_mag::delete_line(TToken_string &k,TLine_movmag &r) +{ + if (_codcaus != get("CODCAUS") || _annoes != get("ANNOES")) { + lines_to_subtract.add(k,r); + } else { + if (lines_to_add.is_key(k)&& r==(TLine_movmag &)lines_to_add[k] ) + // modifica annullata + lines_to_add.remove(k); + else + // linea modificata + lines_to_subtract.add(k,r); + } + return 0; +} + +bool TMov_mag::unlock_anamag(const char *codart) +{ + TLocalisamfile anamag(LF_ANAMAG); + anamag.put("CODART",codart); + return (anamag.read(_isequal,_unlock)==NOERR); +} + +bool TMov_mag::lock_anamag(const char *codart) +{ + TLocalisamfile anamag(LF_ANAMAG); + anamag.put("CODART",codart); + bool insert_new=TRUE; + TString mess; + mess << "Il record di anagrafica dell'articolo ''"<< codart << "'' risulta essere già in uso.\n Interrompo ?"; + TTimed_breakbox bbox((const char *)mess,10); + do { + if (anamag.read(_isequal,_testandlock)==NOERR) + return TRUE; + } while (bbox.run()!=K_ESC); + return FALSE; +} + + +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")); +} + + +// aggiorna tutti i saldi in base alle modifiche fatte. +// il lock su anagrafica dovrebbe garantire il lock su tutte le +// giacenze dell'articolo +int TMov_mag::update_balances() const +{ + bool updated_bal=TRUE; + TLocalisamfile mag(LF_MAG); + mag.setkey(2); + + + TString_array keys_to_add,keys_to_remove; + ((TMov_mag *)this)->lines_to_add.get_keys(keys_to_add); + ((TMov_mag *)this)->lines_to_subtract.get_keys(keys_to_remove); + + // aggiunge i saldi nuovi + 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 + 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; +} + +// 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"); + + 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; +} + + +void TMov_mag::update_balance(TRectype & magrec, const char * fieldname, real diff) const +{ + magrec.put(fieldname,magrec.get_int(fieldname)+diff); +} + +HIDDEN TEsercizi_contabili _esercizi; + +int TMov_mag::codice_esercizio(TDate &d) +{ + return _esercizi.date2esc(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); + TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino + + // 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 + + for (int i=0; iunpack_grpcode(relation()->lfile(LF_MAG).get("LIVELLO"),lv); + if (piece.not_empty()) { + levname << '/' << piece ; + } + } while (++lv< (_tolivgiac ? _tolivgiac: _giaclev->last_level()) ); +} + + +void TForm_stampemg::gruppogiac(TForm_item &cf, TToken_string &s) +{ + TString valore,levname; + int livello=atoi(s.get()); + + if (_fromlivgiac) { + levname=relation()->lfile(LF_MAG).get("CODART"); + if (_fromlivgiac>1) { + add_giaclev(levname); + } + } + levname << ' ' << _giaclev->name(livello) ; + valore=_giacgrp->decode(_giaclev->build_tabcode(relation()->lfile(LF_MAG).get("LIVELLO"),livello)); + if (valore.empty()) + valore=UNKNOWN_NAME; + cf.set(levname << ' ' << valore); +} + + +void TForm_stampemg::gruppoart(TForm_item &cf, TToken_string &s) +{ + int lv=atoi(s.get()); + TString valore; + + valore=_artgrp->decode(_artlev->build_tabcode(relation()->lfile(LF_ANAMAG).get("CODART"),lv)); + if (valore.not_empty()) + cf.set(valore); + else + cf.set(UNKNOWN_NAME); +} + +bool TForm_stampemg::validate(TForm_item &cf, TToken_string &s) +{ + const TString code(s.get(0)); // prende il primo parametro, il codice del messaggio + TString subcode; + TString valore,levname; + + if (code=="_USER") { + subcode=s.get(); + + if (subcode=="GRUPPOGIAC") { + /* + int lv=atoi(s.get()); + do { + valore=_giaclev->build_tabcode(relation()->lfile(LF_MAG).get("LIVELLO"),lv); + } while (--lv>0 && valore==""); + if (valore!="") + levname=_giaclev->name(lv+1) ; + else + levname="giacenza"; + cf.set(levname << ' ' << _giacgrp->decode(valore)); + */ + gruppogiac(cf,s); + } + if (subcode=="GRUPPOART") { + /* + int lv=atoi(s.get()); + do { + valore=_artlev->build_tabcode(relation()->lfile(LF_ANAMAG).get("CODART"),lv); + } while (--lv>0 && valore==""); + cf.set(_artgrp->decode(valore)); + */ + gruppoart(cf,s); + } + if (subcode=="CODGRUPPOART") { + int lv=atoi(s.get()); + do { + valore=relation()->lfile(LF_ANAMAG).get("CODART"); + valore.cut(_artlev->packed_lenght(lv)); + } while (--lv>0 && valore==""); + cf.set(valore); + + } + if (subcode=="CATMER") { + valore=relation()->lfile(_sottocatmer ? -401 : -400).get("S0"); + cf.set(valore); + } + if (subcode=="CODCATMER") { + valore=relation()->lfile(LF_ANAMAG).get("GRMERC"); + valore.cut(_sottocatmer ? 5:3); + cf.set(valore); + } + if (subcode=="LIVELLIGIAC") { + int lv=_tolivgiac; + valore=""; + do { + const TString & piece = _giaclev->unpack_grpcode(relation()->lfile(LF_MAG).get("LIVELLO"),lv+1); + if (piece.not_empty()) { + if (valore.not_empty()) + valore << '/'; + valore << piece ; + } + } while (lv++<_giaclev->last_level()); + if (valore!="") + levname=_giaclev->name(_tolivgiac+1); + else + levname="Giacenza"; + cf.set(levname << ' ' << valore); + } + return TRUE; + } else + return TForm::validate(cf, s); +} + +void TForm_stampemg::setcatmer(bool catmer,bool sottoc) +{ + TForm_subsection &s=((TForm_subsection &)find_field('B',odd_page,"GRUPPI_CATMER")); + TString cond("GRMERC"); + if (catmer) + cond << "[1," << (sottoc ? 5 : 3) <<']'; + else + cond ="CODART[1,1]"; + s.setcondition(cond,_strexpr); + _sottocatmer=sottoc; +} + +bool TForm_stampemg::setdett_perart(int fromlivart,int livart,int fromlivgiac,int livgiac,bool showmag, bool showdep) +{ + find_field('B',odd_page,"H_MAGAZZINO").show(showmag && showdep); + find_field('B',odd_page,"TOT_MAGAZZINO").show(showmag); + find_field('B',odd_page,"H_DEPOSITO").show(FALSE); + find_field('B',odd_page,"TOT_DEPOSITO").show(showdep); + return setdettaglio(TRUE,fromlivart,livart,fromlivgiac,livgiac,showmag||showdep); +} + +bool TForm_stampemg::setdett_permag(int fromlivart,int livart,int fromlivgiac,int livgiac,bool showmag, bool showdep,bool showdett) +{ + find_field('B',odd_page,"H_MAGAZZINO").show(showmag && (showdep) ); + find_field('B',odd_page,"TOT_MAGAZZINO").show(showmag); + find_field('B',odd_page,"H_DEPOSITO").show(showdep && showdett); + find_field('B',odd_page,"TOT_DEPOSITO").show(showdep); + return setdettaglio(showdett,fromlivart,livart,fromlivgiac,livgiac,FALSE); +} + +bool TForm_stampemg::setdettaglio(bool show, int fromlivart,int livart,int fromlivgiac,int livgiac,bool dettgiac) +{ + _fromlivart=fromlivart; + _fromlivgiac=fromlivgiac; + _tolivart=livart; + _tolivgiac=livgiac; + // *********** + int i, tolivart,tolivgiac; + // abilita le sezioni dei livelli di codice + TForm_subsection &s1=(TForm_subsection &)find_field('B',odd_page,"H_ARTICOLO"); + TForm_subsection &s2=(TForm_subsection &)find_field('B',odd_page,"TOT_ARTICOLO"); + if (fromlivgiac==0 && (livart==0 ||livart==_artlev->last_level())) { + s1.show(show && livart<_artlev->last_level() || dettgiac); + s2.show(show); + } else { + s1.hide(); + s2.hide(); + } + tolivart =min(( livart ? livart :_artlev->last_level()),_artlev->last_level()-1) ; + tolivgiac=livgiac ? livgiac :_giaclev->last_level(); + for (i=1; i<=FORM_MAXARTLEV; i++) + { + TString sname("TOT_GART"); + sname << i; + TForm_subsection &s1=(TForm_subsection &)find_field('B',odd_page,sname); + s1.show(show && i>=fromlivart && i<=tolivart && fromlivgiac==0); + sname="H_GCODART"; + sname << i; + TForm_subsection &s2=(TForm_subsection &)find_field('B',odd_page,sname); + s2.show(show && i>=fromlivart && + (itolivart || livgiac || dettgiac))) && fromlivgiac==0); + } + // abilita le sezioni del codice livelli giacenza + for (i=1; i<=FORM_MAXGIACLEV; i++) + { + TString sname("TOT_GLIVGIAC"); + sname << i; + TForm_subsection &s1=(TForm_subsection &)find_field('B',odd_page,sname); + s1.show(show && i>=fromlivgiac && (i<=tolivgiac) && livart==0); + sname="H_GLIVGIAC"; + sname << i; + TForm_subsection &s2=(TForm_subsection &)find_field('B',odd_page,sname); + s2.show(show && i>=fromlivgiac && (ipacked_lenght(i) <<']'; + s.setcondition(cond,_strexpr); + } + // sezioni livello codice + for (i=fromlivart;i<=tolivart ; i++) { + TString sname("GRUPPI_CODART"); + sname << i; + TForm_subsection &s=(TForm_subsection &)find_field('B',odd_page,sname); + TString cond(s.condition()); + cond << '[' << (i==1 ? 1:_artlev->packed_lenght(i-1))<<',' << _artlev->packed_lenght(i) <<']'; + s.setcondition(cond,_strexpr); + } + + return TRUE; +} + + +TForm_stampemg::TForm_stampemg(const char *name,const char *code) + : TForm(name,code) +{ + _giaclev= new TMag_livelli("FCG"); + _artlev= new TMag_livelli("FCA"); + _giacgrp= new TDecoder("GCG"); + _artgrp= new TDecoder("GCA"); + _fromlivgiac=_tolivgiac=0; + _fromlivart=_tolivart=0; +} +TForm_stampemg::~TForm_stampemg() +{ + delete _giaclev; + delete _artlev; + delete _giacgrp; + delete _artgrp; +} diff --git a/mg/mglib06.cpp b/mg/mglib06.cpp new file mode 100755 index 000000000..1b306b059 --- /dev/null +++ b/mg/mglib06.cpp @@ -0,0 +1,555 @@ +// ************************************** +// ************************************** +// ************************************** +// *** classi per la libreria +// *** +//***** +#include "mglib.h" + + + +int TMultiple_rectype::find(int logicnum, const char * fieldname, const char * s, int from, bool reverse) const +{ + const TRecord_array & recarray = body(logicnum); + const int last = recarray.last_row(); + const int len = s ? strlen(s) : 0; + + if (reverse) + { + if (from > 0) + { + if (len == 0) + return from - 1; + for (int i = recarray.pred_row(from); i > 0; i = recarray.pred_row(i)) + if (((TRectype &)recarray[i]).get(fieldname) == s) + return i; + } + } + else + { + if (last > from) + { + if (len == 0) + return from + 1; + for (int i = recarray.succ_row(from); i <= last; i = recarray.succ_row(i)) + if (((TRectype &)recarray[i]).get(fieldname) == s) + return i; + } + } + return -1; +} + +int TMultiple_rectype::write_rewrite(TBaseisamfile & f, bool re) const +{ + int err = NOERR; + + if (_nuovo && re) // E' nuovo di zecca! quindi ... + re = FALSE; // ... non fare la rewrite + + if (re) + { + for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) + { + TRecord_array * r = (TRecord_array *) _files.objptr(i); + if (r) + err = r->write(re); + } + // rewrite: + if (err == NOERR) + { + err = TRectype::rewrite(f); + if (err != NOERR) + err = TRectype::write(f); + } + } + else + { + // write: + if (_nuovo) + { + do + { + err = TRectype::write(f); + if (err == _isreinsert) // usa il flag _nuovo per decidere se + ((TMultiple_rectype *)this)->renum(); + } while (err == _isreinsert); + ((TMultiple_rectype *)this)->_nuovo = FALSE; + } + else + { + err = TRectype::write(f); + if (err != NOERR) + err = TRectype::rewrite(f); + } + for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) + { + TRecord_array * r = (TRecord_array *)_files.objptr(i); + if (r) + err = r->write(re); + } + } + return err; +} + +void TMultiple_rectype::remove_body(int logicnum) +{ + const int index = log2ind(logicnum); + + if (_files.objptr(index) != NULL) + _files.remove(index); +} + +int TMultiple_rectype::log2ind(int logicnum) const +{ + if (logicnum == 0) + return 0; + for (int i = _nfiles - 1; i >= 0 ; i--) + if (_logicnums[i] == logicnum) + return i; + NFCHECK("Can't find file %d in multiple record", logicnum); + return 0; +} + +void TMultiple_rectype::load_rows_file(int logicnum) +{ + const int index = log2ind(logicnum); + TRectype & rec = get_body_record(logicnum); + + set_body_key(rec); + TRecord_array * r = new TRecord_array(logicnum, (TString &) _numfields[index]); + _files.add( r, index); +} + +TRecord_array & TMultiple_rectype::body(int logicnum) const +{ + const int index = log2ind(logicnum); + + if (_files.objptr(index) == NULL) + ((TMultiple_rectype *) this)->load_rows_file(logicnum); + return (TRecord_array &) _files[index]; +} + +void TMultiple_rectype::renum_key(const char * kfield,const char * val) +{ + TRectype::renum_key(kfield, val); // Aggiorna testata + for (int i = _nfiles - 1; i >= 0 ; i--) + body(_logicnums[i]).renum_key(kfield, val); // Aggiorna righe +} + + +TRectype & TMultiple_rectype::operator =(const TRectype & r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +TRectype & TMultiple_rectype::operator =(const char * r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +void TMultiple_rectype::zero(char c) +{ + reset_fields(*this); + TAuto_variable_rectype::zero(c); + for (int i = _nfiles - 1; i >= 0 ; i--) + if (_files.objptr(i) != NULL) + _files.remove(i); +} + + +int TMultiple_rectype::read(TRectype & rec, word op, word lockop) +{ + TLocalisamfile f(num()); + + *this = rec; + + int err = TRectype::read(f, op, lockop); + + for (int i = _nfiles - 1; i >= 0 ; i--) + if (_files.objptr(i) != NULL) + _files.remove(i); + _nuovo = err != NOERR; + return err; +} + +int TMultiple_rectype::remove(TBaseisamfile & f) const +{ + int err = NOERR; + + for (int i = _nfiles - 1; err == NOERR && i >= 0 ; i--) + { + TRecord_array & r = body(_logicnums[i]); + r.remove(); + } + if (err == NOERR) + err = TRectype::remove(f); + return err; +} + +// @doc INTERNAL +TMultiple_rectype::TMultiple_rectype(int hfn) + : TAuto_variable_rectype(hfn), _nuovo(TRUE), _nfiles(0) +{ +} + + // @ cmember costruttore dal file +void TMultiple_rectype::add_file(int logicnum, const char * numfield) +{ + CHECK(_nfiles < maxfiles, "Too many files added"); + _logicnums[_nfiles] = logicnum; + _numfields.add(numfield, _nfiles++); +} + +TMultiple_rectype::TMultiple_rectype(const TBaseisamfile* file) + :TAuto_variable_rectype(file), _nuovo(TRUE), _nfiles(0) +{ +} + + // @ cmember costruttore dal record +TMultiple_rectype::TMultiple_rectype(const TRectype & rec) + :TAuto_variable_rectype(rec), _nuovo(TRUE), _nfiles(0) +{ +} + +// @mfunc costruttore di copia +TMultiple_rectype::TMultiple_rectype(const TMultiple_rectype& r) + :TAuto_variable_rectype(r), _files(r._files) +{ + // copia.. + _nuovo=r._nuovo; + _nfiles=r._nfiles; // file delle righe + _numfields=r._numfields; +} + + +// THead_lines_record +// metodi protected + +void THead_lines_record::renum_key(const char * kfield,const char * val) +{ + TRectype::renum_key(kfield, val); // Aggiorna testata + _rows->renum_key(kfield, val); // Aggiorna righe +} + +TRectype & THead_lines_record::row(int index) const // riga del corpo +{ + if (index > _rows->rows() || index < 0) + CHECKD(FALSE, "Riga non esistente ", index); + return _rows->row(index, FALSE); +} + +void THead_lines_record::put_str(const char* fieldname, const char* val) +{ + TString v(val); + // cambio + //if (strcmp(fieldname, "TIPODOC") == 0 && TRectype::get("TIPODOC") != v) + //{ + // TAuto_variable_rectype::put_str(fieldname, v); + // reset_fields(*this); + // set_fields(*this); + //} + //else + { + TAuto_variable_rectype::put_str(fieldname, v); + dirty_fields(); + } +} + +//***** +// metodi public +THead_lines_record::THead_lines_record(int hfn, int rfn,const char *numfield): + TAuto_variable_rectype(hfn), + _file(hfn), + _rfile(rfn), + _numfield(numfield) +{ + _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe +} + +THead_lines_record::THead_lines_record(const TBaseisamfile* i,int rfn,const char *numfield): + TAuto_variable_rectype(i), + _numfield(numfield) +{ + _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe +} + +THead_lines_record::THead_lines_record(const TRectype & r,int rfn,const char *numfield): + TAuto_variable_rectype(r), + _numfield(numfield) +{ + _rows= new TRecord_array(rfn,numfield); // inizializza il record array delle righe +} + +// @doc INTERNAL + +// @mfunc costruttore di copia +THead_lines_record::THead_lines_record(const THead_lines_record& r): + TAuto_variable_rectype((TAuto_variable_rectype &)r) +{ + // copia.. + _rows= new TRecord_array(* r._rows); // inizializza il record array delle righe + _nuovo=r._nuovo; + _file=r._file; // file principale + _rfile=r._rfile; // file delle righe + _numfield=r._numfield; +} + +THead_lines_record::~THead_lines_record() +{ + delete _rows; +} + + +// setta a dirty i campi +void THead_lines_record::dirty_fields() +{ +} + +TRectype & THead_lines_record::operator =(const TRectype & r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +TRectype & THead_lines_record::operator =(const char * r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +void THead_lines_record::zero(const char * fieldname) +{ + // resetta il record righe solo se ..... +// if (strcmp(fieldname, "TIPODOC") == 0) + reset_fields(*this); + TAuto_variable_rectype::zero(fieldname); + dirty_fields(); +} + +void THead_lines_record::zero(char c) +{ + reset_fields(*this); + TAuto_variable_rectype::zero(c); +} + + +// settaggio campi variabili +void THead_lines_record::set_fields(TAuto_variable_rectype & rec) +{ +} + + +int THead_lines_record::read(TBaseisamfile& f, word op, word lockop) +{ + TRectype line_key(_rfile); + + int err = TRectype::read(f,op,lockop); + + copy_linekey(head(),line_key); + if (err == NOERR) + { + _nuovo = FALSE; + _rows->read(line_key); //ok + } + else + { + // nuovo oggetto: resetta tutto + _nuovo = TRUE; + destroy_rows(); + _rows->set_key((TRectype *)(line_key.dup())); // ok + } + return err; +} + +int THead_lines_record::readat(TBaseisamfile& f, TRecnotype nrec, word lockop) +{ + TRectype line_key(_rfile); + + int err = TRectype::readat(f,nrec,lockop); + + if (err == NOERR) + { + _nuovo = FALSE; + _rows->read(line_key); //ok + } + else + { + // nuovo oggetto: resetta tutto + _nuovo = TRUE; + destroy_rows(); + _rows->set_key((TRectype *)(line_key.dup())); // ok + } + return err; +} + + +/*int THead_lines_record::read(const TRectype& rec) +{ + head() = rec; + TRectype line_key(_rows->key()); + + copy_linekey(head(),line_key); + + TLocalisamfile afile(_file); + int err = TRectype::read(afile); + if (err == NOERR) + { + _nuovo = FALSE; + _rows->read(line_key); //ok + } + else + { + // nuovo oggetto: resetta tutto + _nuovo = TRUE; + head() = rec; + destroy_rows(); + _rows->set_key(&line_key); // ok + } + return err; +} +*/ +int THead_lines_record::write(TBaseisamfile& f) const +{ + return write_rewrite(f,FALSE); +} + +int THead_lines_record::rewrite(TBaseisamfile& f) const +{ + return write_rewrite(f,TRUE); +} + + +int THead_lines_record::write_rewrite(TBaseisamfile& f,bool re ) const +{ + const bool nuovo = _nuovo; // E' nuovo di zecca! + if (nuovo && re) // quindi ... + re = FALSE; // ... non fare la rewrite + + int err = NOERR; + if (re) + { + // rewrite: + err = _rows->write(re); + if (err == NOERR) + { + err = TRectype::rewrite(f); + if (err != NOERR) + err = TRectype::write(f); + } + } + else + { + // write: + if (nuovo) + { + //THead_lines_record &myself=*this; + //if (numero() <= 0) + // myself.renum(); + do + { + err = TRectype::write(f); + if (err == _isreinsert) // usa il flag _nuovo per decidere se + ((THead_lines_record *)this)->renum(); + } while (err == _isreinsert); + ((THead_lines_record *)this)->_nuovo = FALSE; + } + else + { + err = TRectype::write(f); + if (err != NOERR) + err = TRectype::rewrite(f); + } + if (err == NOERR) + err = _rows->write(re); + } + return err; +} + + +int THead_lines_record::remove(TBaseisamfile& f) const +{ + int err = _rows->remove(); + if (err == NOERR) + err = TRectype::remove(f); + return err; +} + + +// ************************************************ +// TEMP!!!!!!!!!!!!!!!! + +TRegistro_std::TRegistro_std(const char* cod, int year) : TRectype(LF_TAB) +{ + if (!read(cod, year)) + fatal_box("Il codice richiesto non è stato trovato nei registri"); + TTable itl("%ITL"); + itl.put("CODTAB",cod_intest()); + itl.read(); + _intest=itl.get("S0"); +} + +bool TRegistro_std::read(const char* cod, int year) +{ + if (year <= 0) + { + const TDate oggi(TODAY); + year = oggi.year(); + } + + int err = ~NOERR; + + TTable reg("REG"); + reg.setkey(1); + if (cod && *cod > ' ') + { + TString16 chiave; chiave.format("%04d%s", year, cod); + reg.put("CODTAB", chiave); + err = reg.read(); + } + *((TRectype *)this) = reg.curr(); + + return err == NOERR; +} + +bool TRegistro_std::write(bool rewrite) const +{ + int err = ~NOERR; + TTable reg("REG"); + + reg.set_curr((TRectype *)this); + if (rewrite) + err = reg.rewrite(); + else + err = reg.write(); + return err == NOERR; +} + + + +int TRegistro_std::year() const +{ + TString16 anno(get("CODTAB")); + anno.cut(4); + return atoi(anno); +} + + +const TString& TRegistro_std::code() const +{ + return get("CODTAB").mid(4); +} + +const TString TRegistro_std::intest() const +{ + return _intest; +}