diff --git a/ef/ef0100.cpp b/ef/ef0100.cpp index 6a5b97136..c78769f52 100755 --- a/ef/ef0100.cpp +++ b/ef/ef0100.cpp @@ -11,9 +11,8 @@ #include "ef0.h" #include "ef0100.h" #include "ef0101.h" - -//Classe per la gestione di effetti con metodi -// standard di: inserimento, modifica, cancellazione. +// Classe per la gestione di effetti con metodi standard di: +// inserimento, modifica, cancellazione. class TVariazione_effetti: public TRelation_application { TMask *_msk; @@ -45,14 +44,17 @@ public: virtual ~TVariazione_effetti() {}; }; +// restituisce un riferimento all' applicazione inline TVariazione_effetti& app() {return (TVariazione_effetti&)main_app();} - +// quando si va in query mode resetta i due campi della maschera void TVariazione_effetti::init_query_mode(TMask&) { _msk->reset(F_TOTIMP); _msk->reset(F_TOTIMPVAL); } - +// quando si va in insert mode resetta i due campi della maschera, +// inserisce una riga vuota nello sheet e setta il flag dirty dello sheet +// per forzare l'utente all'inserimento di una riga void TVariazione_effetti::init_insert_mode(TMask&) { _msk->reset(F_TOTIMP); @@ -61,8 +63,7 @@ void TVariazione_effetti::init_insert_mode(TMask&) righe_sheet().row(0)=riga; righe_sheet().set_dirty(); } - -//Ritorna il prossimo numero valido di chiave +// ritorna il prossimo numero valido di chiave const char* TVariazione_effetti::get_next_key() { TLocalisamfile& effetti=_rel->lfile(); @@ -77,33 +78,27 @@ const char* TVariazione_effetti::get_next_key() } return format("%d|%ld",F_NPROGTR,nprogtr); } - -//Ritorna un riferimento allo sheet dei cessionari +// ritorna un riferimento allo sheet dei cessionari TSheet_field& TVariazione_effetti::cess_sheet() const { TSheet_field& o_sheet = (TSheet_field&)_msk->field(F_SHEET_EFF); return o_sheet; } - -//Ritorna un riferimento allo sheet delle righe +// ritorna un riferimento allo sheet delle righe TSheet_field& TVariazione_effetti::righe_sheet() const { TSheet_field& r_sheet = (TSheet_field&)_msk->field(F_SHEET_RIGHE); return r_sheet; } - -//Metodo che permette di scivere su file i dati inseriti nella maschera; -// comune a write e rewrite +// metodo che permette di scivere su file i dati inseriti nella maschera; +// comune alla write e alla rewrite void TVariazione_effetti::common_f(const TMask& m) { long nprogtr = m.get_long(F_NPROGTR); - m.autosave(*_rel); _effetto->head() = _rel->curr(); - TSheet_field& shcess = cess_sheet(); TSheet_field& shrighe = righe_sheet(); - int items = shcess.items(); _effetto->destroy_rows_c(); int ii = 0; @@ -122,7 +117,6 @@ void TVariazione_effetti::common_f(const TMask& m) rec.put(CES_COM, row.get()); ii++; } - items = shrighe.items(); _effetto->destroy_rows_r(); ii = 0; @@ -150,24 +144,23 @@ void TVariazione_effetti::common_f(const TMask& m) } _effetto->renum(_effetto->numero()); } - +// carica nella maschera i dati dai files int TVariazione_effetti::read(TMask& m) { m.autoload(*_rel); + TLocalisamfile f(LF_EFFETTI); int err = _rel->status(); if (err == NOERR) { - err = _effetto->read(_rel->curr()); + err = _effetto->read(f, _rel->curr()); if (err == NOERR) { TString16 codcom(3); TToken_string riga(80); - TSheet_field& shcess = cess_sheet(); shcess.reset(); TSheet_field& shrighe = righe_sheet(); shrighe.reset(); - int items = _effetto->rows_c(); for (int i = 1; i <= items; i++) { @@ -183,7 +176,6 @@ int TVariazione_effetti::read(TMask& m) if (_com->read() == NOERR) riga.add(_com->get(COM_DENCOM)); shcess.row(i-1)=riga; } - items = _effetto->rows_r(); for (i = 1; i <= items; i++) { @@ -205,25 +197,28 @@ int TVariazione_effetti::read(TMask& m) } return err; } - +// riscrive i dati su file int TVariazione_effetti::rewrite(const TMask& m) { - common_f(m); - return _effetto->rewrite(); + common_f(m); + TLocalisamfile f(LF_EFFETTI); + return _effetto->rewrite(f); } - +// scrive i dati su file int TVariazione_effetti::write(const TMask& m) { - common_f(m); - int err = _effetto->write(); - if (err == NOERR) - _rel->read(); // per posizionare correttamente la relazione + common_f(m); + TLocalisamfile f(LF_EFFETTI); + int err = _effetto->write(f); + if (err == NOERR) + _rel->read();// rilegge per posizionare correttamente la relazione return err; } - +// rimuove i dati dell'effetto bool TVariazione_effetti::remove() -{ - return _effetto->remove() == NOERR; +{ + TLocalisamfile f(LF_EFFETTI); + return _effetto->remove(f) == NOERR; } bool TVariazione_effetti::user_create() @@ -240,7 +235,6 @@ bool TVariazione_effetti::user_create() righe_sheet().set_notify(impeff_notify); return TRUE; } - bool TVariazione_effetti::user_destroy() { delete _msk; @@ -251,16 +245,14 @@ bool TVariazione_effetti::user_destroy() delete _com; return TRUE; } - -//Permette di effettuare il controllo sul fatto che venga inserita almeno una -// riga per un effetto +// handler che permette di effettuare il controllo sul fatto che venga inserita +// almeno una riga per un effetto bool TVariazione_effetti::handle_sheet(TMask_field &f, KEY k) { TMask& m = f.mask(); const int mode = m.mode(); if ( k==K_ENTER && (mode== MODE_INS || mode== MODE_MOD) ) { - TSheet_field& sf = (TSheet_field&)m.field(F_SHEET_RIGHE); int items = sf.items(); bool found=FALSE; @@ -278,9 +270,8 @@ bool TVariazione_effetti::handle_sheet(TMask_field &f, KEY k) } return TRUE; } - -//Permette il controllo sulla abilitazione dei campi collegati al codice -// valuta +// handler che permette il controllo sulla abilitazione dei campi collegati +// al codice valuta bool TVariazione_effetti::codval_handler(TMask_field& f, KEY k) { TMask &m = f.mask(); @@ -290,14 +281,16 @@ bool TVariazione_effetti::codval_handler(TMask_field& f, KEY k) const bool condition = (val == "LIT" || val.empty()); m.enable(-1,!condition); TSheet_field& sf = (TSheet_field&)m.field(F_SHEET_RIGHE); - if (condition){ + if (condition) + { m.reset(-1); m.reset(F_TOTIMPVAL); int items = sf.items(); - for (int i= 0; i < items; i++){ - TToken_string& row = sf.row(i); - row.add(" ", 2); - row.add(" ", 3); + for (int i= 0; i < items; i++) + { + TToken_string& row = sf.row(i); + row.add(" ", 2); + row.add(" ", 3); } } sf.enable_column(F_IMPFATTVAL, !condition); @@ -306,7 +299,8 @@ bool TVariazione_effetti::codval_handler(TMask_field& f, KEY k) } return TRUE; } - +// funzione chiamata dal notify dello sheet per effettuare il calcolo degli importi totali +// (in lire ed in valuta) dell'effetto void TVariazione_effetti::calcola_totali() { TMask* m = app()._msk; @@ -324,7 +318,8 @@ void TVariazione_effetti::calcola_totali() m->set(F_TOTIMP, impeff); m->set(F_TOTIMPVAL, impeffval); } - +// notify per il calcolo dei totali dell'effetto e per il controllo che non vengano eliminate +// tutte le righe dell'effetto, almeno una deve rimanere bool TVariazione_effetti::impeff_notify(TSheet_field& s, int r, KEY key) { if (s.to_check(key, TRUE)) calcola_totali(); diff --git a/ef/ef0100a.uml b/ef/ef0100a.uml index 4b5b297e1..b77434d9a 100755 --- a/ef/ef0100a.uml +++ b/ef/ef0100a.uml @@ -44,14 +44,6 @@ BEGIN INPUT CODCF F_CODCF DISPLAY "Ragione sociale@60" RAGSOC DISPLAY "Codice" CODCF -/* - DISPLAY "Codice cliente" CODCF - DISPLAY "Nr. progressivo" NPROGTR - DISPLAY "Data scadenza" DATASCAD - DISPLAY "Tipo distinta" TIPODIST - DISPLAY "Nr. distinta" NDIST - COPY OUTPUT F_NPROGTR -*/ OUTPUT F_CODCF CODCF OUTPUT F_CFRAGSOC RAGSOC CHECKTYPE REQUIRED @@ -61,17 +53,10 @@ STRING F_CFRAGSOC 50 BEGIN PROMPT 26 3 "" USE LF_CLIFO KEY 2 - //JOIN LF_EFFETTI TO LF_CLIFO KEY 2 INTO CODCF==CODCF INPUT TIPOCF "C" INPUT RAGSOC F_CFRAGSOC DISPLAY "Ragione sociale@60" RAGSOC DISPLAY "Codice" CODCF - /* - DISPLAY "Nr. progressivo" LF_EFFETTI->NPROGTR - DISPLAY "Data scadenza" LF_EFFETTI->DATASCAD - DISPLAY "Tipo distinta" LF_EFFETTI->TIPODIST - DISPLAY "Nr. distinta" LF_EFFETTI->NDIST - */ COPY OUTPUT F_CODCF CHECKTYPE REQUIRED END @@ -88,7 +73,6 @@ BEGIN DISPLAY "Data scadenza" DATASCAD DISPLAY "Nr. progressivo" NPROGTR DISPLAY "Codice cliente" CODCF - DISPLAY "Tipo pag." TIPOPAG DISPLAY "Nr. distinta" NDIST DISPLAY "Tipo distinta" TIPODIST COPY OUTPUT F_NPROGTR diff --git a/ef/ef0101.cpp b/ef/ef0101.cpp index b0d63cf34..86472871d 100755 --- a/ef/ef0101.cpp +++ b/ef/ef0101.cpp @@ -2,35 +2,35 @@ #include "reffetti.h" #include "cession.h" #include "ef0101.h" - +// costruttore di default TEffetto::TEffetto() : TRectype(LF_EFFETTI), _righe(LF_REFFETTI, "NRIGATR"), _cess(LF_CESS, "NRIGA") { } - +// costuisce l'effetto con il record passato TEffetto::TEffetto(TRectype& rec) : TRectype(LF_EFFETTI), _righe(LF_REFFETTI, "NRIGATR"), _cess(LF_CESS, "NRIGA") -{ - read(rec); +{ + TLocalisamfile f(LF_EFFETTI); + read(f,rec); } - +//setta i campi per la prima chiave (nprogtr) del file void TEffetto::put_key(TRectype& rec, long numeff) const { CHECKD(numeff >= 0, "Numero effetto non valido ", numeff); rec.put("NPROGTR",numeff); } - +//setta i campi per la quarta chiave (tipodist+ndist+nrigadist) del file void TEffetto::put_key(TRectype& rec,char tipodist, long ndist, long nrigadist) { - CHECK(tipodist == 'I' || tipodist == 'S' || tipodist == 'B', "Tipo distinta"); + CHECK(tipodist == 'I' || tipodist == 'S' || tipodist == 'B' || tipodist == 0, "Tipo distinta"); CHECKD(ndist >= 0, "Numero distinta non valido ", ndist); CHECKD(nrigadist >= 0, "Numero riga distinta non valido ", nrigadist); - rec.put("TIPODIST", tipodist); rec.put("NDIST", ndist); rec.put("NRIGADIST", nrigadist); } - +// ritorna la prossima chiave utilizzabile (il prossimo numero progressivo) long TEffetto::get_next_key(const long codcf) const { static long n = 0; @@ -39,9 +39,7 @@ long TEffetto::get_next_key(const long codcf) const TLocalisamfile eff(LF_EFFETTI); TRectype& curr = eff.curr(); put_key(curr, 9999999L); - const int err = eff.read(_isgreat); - if (err != _isemptyfile) { if (err == NOERR) @@ -53,7 +51,7 @@ long TEffetto::get_next_key(const long codcf) const n++; return n; } - +// rinumera la chiave 1 long TEffetto::renum(long numeff) { if (numeff <= 0) @@ -68,7 +66,18 @@ long TEffetto::renum(long numeff) return numeff; } -int TEffetto::read(TLocalisamfile &f, const TRectype& r) +// restituisce il prossimo effetto +int TEffetto::next(TBaseisamfile& f) +{ + const int err = f.next(); + *this = f.curr(); + return err; +} + + +// permette di leggere il record passato nel file passato, comune alla lettura +// per chiave 1 e per chiave 4 +int TEffetto::leggi(TLocalisamfile &f, const TRectype& r) { int err = TRectype::read(f); const long nu = numero(); @@ -97,42 +106,40 @@ int TEffetto::read(TLocalisamfile &f, const TRectype& r) } return err; } - -int TEffetto::read(const TRectype& rec) +// legge il record passato, con chiave 1 +int TEffetto::read(TLocalisamfile& f, const TRectype& rec) { - TLocalisamfile eff(LF_EFFETTI); head() = rec; - return read(eff, rec); + return leggi(f, rec); } - -int TEffetto::read(char tipodist, long ndist, long nrigadist) +// legge l'effetto usando la chiave 4 +int TEffetto::read(TLocalisamfile& f, char tipodist, long ndist, long nrigadist) { - TLocalisamfile eff(LF_EFFETTI); - eff.setkey(4); + f.setkey(4); TRectype rec(LF_EFFETTI); - put_key(rec, tipodist,ndist, nrigadist); + put_key(rec, tipodist, ndist, nrigadist); head() = rec; - int err = read(eff, rec); + int err = leggi(f, rec); + /*if (err == _iskeynotfound) + err = f.next();*/ return err; } - -int TEffetto::write(bool force) +// scrive l'effetto, sempre usando la chiave 1 +int TEffetto::write(TLocalisamfile& f, bool force) { const bool nuovo = numero() <= 0; // E' nuovo! if (nuovo && force) // quindi ... force = FALSE; // ... non fare la rewrite - - TLocalisamfile eff(LF_EFFETTI); - eff.setkey(1); + f.setkey(1);//per evitare problemi in quanto la chiave 4 e' duplicabile int err = NOERR; if (force) { if ((err=_righe.write(force)) == NOERR) err= _cess.write(force); if (err == NOERR) { - err = TRectype::rewrite(eff); + err = TRectype::rewrite(f); if (err != NOERR) - err = TRectype::write(eff); + err = TRectype::write(f); } } else @@ -144,42 +151,28 @@ int TEffetto::write(bool force) myself.renum(); do { - err = TRectype::write(eff); + err = TRectype::write(f); if (err == _isreinsert) myself.renum(); } while (err == _isreinsert); } else { - err = TRectype::write(eff); + err = TRectype::write(f); if (err != NOERR) - err = TRectype::rewrite(eff); + err = TRectype::rewrite(f); } if (err == NOERR) if ((err=_righe.write(force)) == NOERR) err= _cess.write(force); } return err; } - -int TEffetto::remove()const +// rimuove l'effetto +int TEffetto::remove(TLocalisamfile& f)const { - TLocalisamfile eff(LF_EFFETTI); int err; if ((err=_righe.remove()) == NOERR) err= _cess.remove(); if (err == NOERR) - err = TRectype::remove(eff); + err = TRectype::remove(f); return err; -} - - - - - - - - - - - - - +} \ No newline at end of file diff --git a/ef/ef0101.h b/ef/ef0101.h index 162038ee0..314d1b285 100755 --- a/ef/ef0101.h +++ b/ef/ef0101.h @@ -1,74 +1,74 @@ #ifndef __RELATION_H #include #endif - class TEffetto:public TRectype { - TRecord_array _righe,_cess; + TRecord_array _righe,// righe dell'effetto + _cess;// cessionari dell'effetto protected: // ritorna la prossima chiave - long get_next_key(const long codcf) const; - int read(TLocalisamfile& f, const TRectype& rec); - + long get_next_key(const long codcf) const; + // permette di leggere il record passato nel file passato + int leggi(TLocalisamfile& f, const TRectype& rec); public: - // rinumera le chiavi + // rinumera la chiave 1 long renum(long numeff = 0); - // ritorna la testata dell'effetto - const TRectype& head() const - { return *this; } - // ritorna la testata dell'effetto - TRectype& head() - { return *this; } - TRecord_array& righe() {return _righe;} + // ritorna un riferimento alla testata dell'effetto + const TRectype& head() const { return *this; } + // ritorna un riferimento alla testata dell'effetto + TRectype& head() { return *this; } + // ritorna un riferimento alle righe dell'effetto + TRecord_array& righe() {return _righe;} + // ritorna un riferimento ai cessionari dell'effetto TRecord_array& cess() {return _cess;} // ritorna la riga i_esima dei cessionari - TRectype& row_c(int i, bool create=FALSE) - { return _cess.row(i,create); } + TRectype& row_c(int i, bool create=FALSE) { return _cess.row(i,create); } // ritorna la riga i delle righe - TRectype& row_r(int i, bool create=FALSE) - { return _righe.row(i,create); } + TRectype& row_r(int i, bool create=FALSE) { return _righe.row(i,create); } // ritorna il numero delle righe presenti nelle righe effetto - int rows_r() const - { return _righe.rows(); } + int rows_r() const { return _righe.rows(); } // ritorna il numero delle righe presenti nei cessionari - int rows_c() const - { return _cess.rows(); } + int rows_c() const { return _cess.rows(); } // elimina l'elemento riga nella posizione n nelle righe effetto - bool destroy_row_r(int n, bool pack = FALSE) - { return _righe.destroy_row(n, pack); } + bool destroy_row_r(int n, bool pack = FALSE) { return _righe.destroy_row(n, pack); } // elimina tutti gli elementi riga nelle righe effetto - void destroy_rows_r() - { _righe.destroy_rows(); } + void destroy_rows_r() { _righe.destroy_rows(); } // elimina l'elemento riga nella posizione n nei cessionari - bool destroy_row_c(int n, bool pack = FALSE) - { return _cess.destroy_row(n, pack); } + bool destroy_row_c(int n, bool pack = FALSE) { return _cess.destroy_row(n, pack); } // elimina tutti gli elementi riga nei cessionari - void destroy_rows_c() - { _cess.destroy_rows(); } - int read(const TRectype& rec); - int read(char tipodist, long ndist, long nrigadist); - int write(bool force=FALSE); - int rewrite() - { return write(TRUE); } - int remove()const; - long numero() const - { return get_long("NPROGTR"); } - long codicec() const - { return get_long("CODCF"); } - TDate datasc() const - { return get_date("DATASCAD"); } - char tipodist() const - { return get_char("TIPODIST"); } - long ndist() const - { return get_long("NDIST"); } - long nrgdist() const - { return get_long("NRIGADIST"); } + void destroy_rows_c() { _cess.destroy_rows(); } + // legge il record passato, con chiave 1 + // restituisce il prossimo effetto + int next(TBaseisamfile& f); + int read(TLocalisamfile& f, const TRectype& rec); + // legge il record passato, con chiave 4 + int read(TLocalisamfile& f, char tipodist, long ndist, long nrigadist); + // scrive l'effetto, sempre usando la chiave 1 + int write(TLocalisamfile& f, bool force = FALSE); + // riscrive l'effetto + int rewrite(TLocalisamfile& f) { return write(f, TRUE); } + // rimuove l'effetto + int remove(TLocalisamfile& f)const; + // restituisce il numero progressivo dell'effetto estraendolo dal record + long numero() const { return get_long("NPROGTR"); } + // restituisce il codice del cliente intestatario dell'effetto estraendolo dal record + long codicec() const { return get_long("CODCF"); } + // restituisce la data di scadenza dell'effetto estraendola dal record + TDate datasc() const { return get_date("DATASCAD"); } + // restituisce il tipo di distinta a cui appartiene l'effetto estraendolo dal record + char tipodist() const { return get_char("TIPODIST"); } + // restituisce il numero della distinta a cui appartiene l'effetto estraendolo dal record + long ndist() const { return get_long("NDIST"); } + // restituisce il numero della riga distinta a cui appartiene l'effetto estraendolo dal record + long nrgdist() const { return get_long("NRIGADIST"); } //setta i campi per la quarta chiave del file void put_key(TRectype& rec,char tipodist, long ndist, long nrigadist = 0); //setta i campi per la prima chiave del file void put_key(TRectype& rec,long numeff) const; - - TEffetto(); - TEffetto(TRectype& rec); + // costruttore di default + TEffetto(); + // costuisce l'effetto con il record passato + TEffetto(TRectype& rec); + // distruttore di default virtual ~TEffetto() {} -}; +}; \ No newline at end of file diff --git a/ef/ef0300.cpp b/ef/ef0300.cpp index 9ddb8f780..50327558c 100755 --- a/ef/ef0300.cpp +++ b/ef/ef0300.cpp @@ -16,33 +16,52 @@ class TVariazione_distinte: public TRelation_application { TMask *_msk, *_m2; TDistinta *_distinta; - TRelation *_rel; - TLocalisamfile *_reff, *_cession; + TRelation *_rel; + TLocalisamfile *_reff, *_cession, *_clifo; protected: virtual void init_query_mode(TMask&); - virtual void init_insert_mode(TMask&); + virtual void init_insert_mode(TMask&); + virtual void init_modify_mode(TMask&); + virtual const char* get_next_key(); + virtual int read(TMask& m); virtual int rewrite(const TMask& m); virtual int write(const TMask& m); - virtual bool remove(char tipodist, long ndist); + virtual bool remove(); + virtual TMask* get_mask(int mode) {return _msk;} - virtual bool changing_mask(int mode) {return FALSE;} - static bool aggiungi_handler(TMask_field& f, KEY k); - static bool elimina_handler(TMask_field& f, KEY k); - static bool impdist_notify(TSheet_field& s, int r, KEY key); - static bool m2_handler(TMask& m, KEY key); + virtual bool changing_mask(int mode) {return FALSE;} + + static bool codval_handler(TMask_field& f, KEY k); + static bool importo_handler(TMask_field& f, KEY k); + static bool imp_aut_handler(TMask_field& f, KEY k); + static bool impdist_notify(TSheet_field& s, int r, KEY key); + static bool imp_notify(TSheet_field& s, int r, KEY key); static bool conferma_handler(TMask_field& f, KEY k); static bool annulla_handler(TMask_field& f, KEY k); - static void calcola_totale(); + static bool from_data_handler(TMask_field& f, KEY k); + static bool to_data_handler(TMask_field& f, KEY k); + static bool ordina_handler(TMask_field& f, KEY k); + + static void calcola_totale(); + static void calcola(); + static void aggiungi(); static void carica_riba(); + static void ord_data(); + static void ord_fatt(); + TSheet_field& righe_sheet() const; TSheet_field& righe_sel_sheet() const; + bool cerca(long num); + bool user_create(); bool user_destroy(); + void aggiorna(); - void elimina(TString16 tipodist, long ndist) ; + void elimina(); + TToken_string* common_f(const TMask& m); public: virtual TRelation* get_relation() const {return _rel;} @@ -57,6 +76,8 @@ inline TVariazione_distinte& app() void TVariazione_distinte::init_query_mode(TMask&) { + _msk->enable(F_NUMBER); + _msk->enable(F_TIPODIST); _msk->reset(F_TOTIMP); _msk->reset(F_TOTIMPVAL); } @@ -65,28 +86,46 @@ void TVariazione_distinte::init_insert_mode(TMask&) { _msk->reset(F_TOTIMP); _msk->reset(F_TOTIMPVAL); - TToken_string riga("|||||||||||"); - righe_sheet().row(0)= riga; - righe_sheet().set_dirty(); - righe_sel_sheet().row(0)= riga; - righe_sel_sheet().set_dirty(); + + _msk->enable(F_TOTIMPVAL); + _msk->enable(F_CODVAL); + + _msk->disable(F_NUMBER); + _msk->disable(F_TIPODIST); } -//Ritorna il prossimo numero valido di chiave +void TVariazione_distinte::init_modify_mode(TMask&) +{ + _msk->disable(F_NUMBER); + _msk->disable(F_TIPODIST); +} + +//Ritorna il prossimo numero di distanta valido const char* TVariazione_distinte::get_next_key() -{ - TLocalisamfile& effetti = _rel->lfile();; - long ndist=1L; - if ( !effetti.empty() ) - { - effetti.zero(); - effetti.setkey(4); - effetti.last(); - if ( effetti.good() ) - ndist+=effetti.get_long(EFF_NDIST); +{ + long ndist = 1L; + TLocalisamfile& effetti = _rel->lfile(); + effetti.zero(); + effetti.put("NDIST",ndist); + effetti.setkey(4); + int err = effetti.read(_isgteq); + + if ( (err == _iskeynotfound) || (err == _iseof) ) //se non esiste alcuna distinta: + { // il numero sarà 1 + err == NOERR; + return format("%d|%ld", F_NUMBER, ndist); } - return format("%d|%ld",F_NUMBER,ndist); -} + + while (err == NOERR) //se esitono già delle distinte: + { // le leggo tutte e ne prendo il + effetti.setkey(4); // numero, al verificarsi della fine file + err = effetti.next(); // ho l'ultimo numero utilizzato + long n = effetti.get_long("NDIST"); // incrementandolo avrò il numero che cercavo. + if (n > ndist) + ndist = n; + } + return format("%d|%ld",F_NUMBER,++ndist); +} //Ritorna un riferimento allo sheet degli effetti (righe) nella distinta TSheet_field& TVariazione_distinte::righe_sheet() const @@ -108,25 +147,26 @@ bool TVariazione_distinte::cerca(long num) bool trovato = FALSE; int items = _distinta->items(); TArray& righedist = _distinta->righe(); + for (int i = 0; i < items; i++)//ciclo sugli elementi dell'array - { + { //se l'array è vuoto non trova nulla ed esce subito TEffetto& eff = (TEffetto&)righedist[i]; long num_eff = eff.get_long("NPROGTR"); if (num_eff == num) { trovato = TRUE; - continue; - } + break; + } } return trovato; } //Metodo che permette di scivere sull'array gli effetti presenti nello sheet -// comune a write e rewrite void TVariazione_distinte::aggiorna() { TSheet_field& shrighe = righe_sheet(); int items = shrighe.items(); + for (int i = 0; i < items; i++) { TToken_string& row = shrighe.row(i); @@ -147,46 +187,18 @@ void TVariazione_distinte::aggiorna() } } -//Metodo che permette di eliminare il collegamento tra effetto e distinta per gli -//effetti che non fanno parte dell'array -void TVariazione_distinte::elimina(TString16 tipodist, long ndist) -{ - TLocalisamfile eff(LF_EFFETTI); - eff.put("TIPODIST",tipodist); - eff.put("NDIST",ndist); - eff.read(_isgteq); - TString16 t = eff.get("TIPODIST"); - long n = eff.get_long("NDIST"); - long num =eff.get_long("NPROGTR"); - while ((t==tipodist)&&(n==ndist)) - { - if (!cerca(num)) - { - eff.zero("TIPODIST"); - eff.zero("NDIST"); - eff.zero("DATADIST"); - eff.zero("NRIGADIST"); - eff.zero("CODABIP"); - eff.zero("CODCABP"); - eff.rewrite(); - } - eff.next(); - t = eff.get_char("TIPODIST"); - n = eff.get_long("NDIST"); - } -} - -//Metodo che permette di scivere su file i dati inseriti nella maschera; -// comune a write e rewrite +//Metodo che permette di prendere i dati dalla maschera e metterli in una TToken_string +//che servirà per passare i dati alla write della distinta TToken_string* TVariazione_distinte::common_f(const TMask& m) { - TString16 tipodist = m.get(F_TIPODIST); + char tipodist = m.get(F_TIPODIST)[0]; long ndist = m.get_long(F_NUMBER); TDate datadist = (TDate)m.get(F_DATA); long codabi = m.get_long(F_CODABIP); long codcab = m.get_long(F_CODCABP); - elimina(tipodist, ndist); + m.autosave(*_rel); + TToken_string* datidist= new TToken_string; datidist->cut(0); datidist->add(tipodist); @@ -197,13 +209,15 @@ TToken_string* TVariazione_distinte::common_f(const TMask& m) return datidist; } + int TVariazione_distinte::read(TMask& m) { m.autoload(*_rel); int err = _rel->status(); + if (err == NOERR) { - err = _distinta->reset(); + err = _distinta->reset(); //resetto l'array che contiene gli effetti nella distinta err = _distinta->read(_rel->curr()); if (err == NOERR) { @@ -212,14 +226,21 @@ int TVariazione_distinte::read(TMask& m) shrighe.reset(); int items = _distinta->items(); TArray& righedist = _distinta->righe(); - for (int i = 0; i < items; i++) + + for (int i = 0; i < items; i++) // carico tutti gli effetti della distinta nello sheet { TEffetto& eff = (TEffetto&)righedist[i]; riga.cut(0); - riga.add(FALSE); + riga.add(' '); riga.add(eff.get(EFF_NPROGTR)); - riga.add(eff.get(EFF_DATASCAD)); - riga.add(eff.get(EFF_CODCF)); + riga.add(eff.get(EFF_DATASCAD)); + + long codcf = eff.get_long(EFF_CODCF); //prendo la ragione sociale del cliente + _clifo->zero(); //conoscendone il codice + _clifo->put("TIPOCF", 'C'); + _clifo->put("CODCF", codcf); + if (_clifo->read() == NOERR) riga.add(_clifo->get("RAGSOC")); + if (eff.rows_r() == 1) //se l'effetto contiene solo una riga metto i { //riferimenti al documento ed al numero di rata const TRectype& rec_r = eff.row_r(1); @@ -232,17 +253,23 @@ int TVariazione_distinte::read(TMask& m) riga.add(("Varie")); riga.add(("Varie")); riga.add(("Varie")); - } + } + TString codval(3); //gestisco il controllo sulla presenza o meno di una valuta codval = eff.get(EFF_CODVAL); - const bool condition = (codval.empty()); - m.enable(F_CODVAL, !condition); - m.enable(F_TOTIMPVAL, !condition); - if (!condition) - m.set(F_CODVAL, codval); + if (i == 0) + { + const bool condition = (codval.empty() || codval == "LIT"); + m.enable(F_CODVAL, !condition); + m.enable(F_TOTIMPVAL, !condition); + if (!condition) + m.set(F_CODVAL, codval); + } riga.add(codval); + riga.add(eff.get(EFF_IMPORTO)); riga.add(eff.get(EFF_IMPORTOVAL)); + shrighe.row(i) = riga; } } @@ -250,24 +277,130 @@ int TVariazione_distinte::read(TMask& m) return err; } +//Si prendono tutte le righe dello sheet e si controlla il primo campo se e' a true si distrugge +// la riga e si aggiorna il file. +// GLI EFFETTI PRESENTI NELLO SHEET DEVONO GIA ESSERE STATI REGISTRATI. +void TVariazione_distinte::elimina() +{ + TEffetto eff; + TLocalisamfile file(LF_EFFETTI); + char tipodist = _msk->get(F_TIPODIST)[0]; + long ndist = _msk->get_long(F_NUMBER); + TDistinta* distinta = app()._distinta; + TSheet_field& sf = (TSheet_field&)_msk->field(F_SHEET_RIBA); + bool condition = FALSE, deleted = FALSE; + TArray& righedist = distinta->righe(); + + for (int i = 0, k = i+1; i < sf.items(); i++, k++)//ciclo sugli elementi dello sheet + { + if (deleted) i--; //per posizionarsi correttamente sulla prima riga dello sheet + + if (sf.items() == 1) + { + error_box("IMPOSSIBILE CANCELLARE: La distinta deve contenere almeno un effetto!"); + break; + } + + TToken_string& row = sf.row(i); + condition = *row.get(0) == 'X'; + + if (condition) + { + long num = row.get_long(1); + + for (int j = 0; j < distinta->items(); j++)//ciclo sugli elementi dell'array + { + TEffetto& eff = (TEffetto&)righedist[j]; + long num_eff = eff.get_long("NPROGTR"); + if (num_eff == num) + { + righedist.destroy(j,TRUE); + break; + } + } + + sf.destroy(i); deleted = TRUE; + eff.read(file, tipodist, ndist, k); + eff.zero("TIPODIST"); + eff.zero("NDIST"); + eff.zero("DATADIST"); + eff.zero("NRIGADIST"); + eff.zero("CODABIP"); + eff.zero("CODCABP"); + eff.rewrite(file); + } + else deleted = FALSE; + } +} + int TVariazione_distinte::rewrite(const TMask& m) { - aggiorna(); - return _distinta->rewrite(common_f(m)); + TSheet_field& sf = righe_sheet(); + bool condition = FALSE; + + for (int i = 0; i < sf.items(); i++) + { + TToken_string& row = sf.row(i); + if (condition = *row.get(0) == 'X') break; + } + + if (condition) + if (yesno_box("Vuoi veramete eliminare gli effetti selezionati")) + elimina(); //elimino gli effetti nello sheet che sono selezionati con la "X" + + int err = _distinta->reset(); //resetto l'array che contiene gli effetti nella distinta + char tipodist = m.get(F_TIPODIST)[0]; + long ndist = m.get_long(F_NUMBER); + + aggiorna(); + + err = _distinta->rewrite(common_f(m)); + if (err == NOERR) + { //riposiziono la relazione + _rel->lfile().setkey(4); + TRectype& curr = _rel->curr(); + curr.put("TIPODIST", tipodist); + curr. put("NDIST", ndist); + curr. put("NRIGADIST", 1); + _rel->read(); + } + return err; } int TVariazione_distinte::write(const TMask& m) { - aggiorna(); - return _distinta->write(TRUE, common_f(m)); -} - -bool TVariazione_distinte::remove(char tipodist, long ndist) -{ - return _distinta->remove(tipodist, ndist) == NOERR; + int err = _distinta->reset(); //resetto l'array che contiene gli effetti nella distinta + char tipodist = m.get(F_TIPODIST)[0]; + long ndist = m.get_long(F_NUMBER); + + aggiorna(); + + err = _distinta->write(TRUE, common_f(m)); + + if (err == NOERR) + { //riposiziono la relazione + _rel->lfile().setkey(4); + TRectype& curr = _rel->curr(); + curr.put("TIPODIST", tipodist); + curr. put("NDIST", ndist); + curr. put("NRIGADIST", 1); + _rel->read(); + } + return err; +} + +//Metodo che permette di eliminare una distinta, l'eliminazione consiste nell'andare a togliere +// dagli effetti presenti i dati ad essa relativi. +bool TVariazione_distinte::remove() +{ + TMask* m = app()._msk; + char tipodist = m->get(F_TIPODIST)[0]; + long ndist = m->get_long(F_NUMBER); + + int err = _distinta->remove(tipodist, ndist) == NOERR; + return err; } - bool TVariazione_distinte::user_create() { _msk = new TMask("ef0300a"); @@ -275,14 +408,23 @@ bool TVariazione_distinte::user_create() _rel = new TRelation(LF_EFFETTI); _reff = new TLocalisamfile(LF_REFFETTI); _cession = new TLocalisamfile(LF_CESS); + _clifo = new TLocalisamfile(LF_CLIFO); _distinta = new TDistinta; - set_search_field(F_NUMBER); - _msk->set_handler(B_AGGIUNGI, aggiungi_handler); - _msk->set_handler(B_ELIMINA, elimina_handler); + + set_search_field(F_NUMBER); //setto il campo di ricerca della distinta + + _msk->set_handler(F_CODVAL, codval_handler); + _msk->set_handler(F_IMP, importo_handler); + _m2->set_handler(F_TOTIMPDIST, imp_aut_handler); _m2->set_handler(DLG_OK, conferma_handler); - _m2->set_handler(DLG_CANCEL, annulla_handler); - _m2->set_handler(m2_handler); - righe_sheet().set_notify(impdist_notify); + _m2->set_handler(DLG_CANCEL, annulla_handler); + _m2->set_handler(F_DADATA, from_data_handler); + _m2->set_handler(F_ADATA, to_data_handler); + _m2->set_handler(F_TIPORD, ordina_handler); + + righe_sheet().set_notify(impdist_notify); + righe_sel_sheet().set_notify(imp_notify); + return TRUE; } @@ -292,37 +434,45 @@ bool TVariazione_distinte::user_destroy() delete _m2; delete _rel; delete _reff; - delete _cession; + delete _cession; + delete _clifo; delete _distinta; + return TRUE; } -//Permette di gestire lo sheet per la selezione delle riba da aggiungere alla distinta +//Permette di caricare lo sheet per la selezione delle riba da aggiungere alla distinta: +// vengono presi tutti gli effetti sul file LF_EFFETTI che non hanno ancora un riferimento ad +// una distinta void TVariazione_distinte::carica_riba() -{ - TLocalisamfile f(LF_EFFETTI); - TRectype rec = f.curr(); - f.setkey(4); - f.put("TIPODIST",""); - f.put("NDIST",0); - f.put("NRIGADIST",0); - f.read(_isgteq); - TString16 t = rec.get("TIPODIST"); - long n = rec.get_long("NDIST"); +{ + char tipodist = 0; + long ndist = 0; + long nrigadist = 0; + TEffetto eff; + TLocalisamfile f(LF_EFFETTI); + TLocalisamfile * clifo = app()._clifo; + TToken_string riga(80); + TMask* m2 = app()._m2; + m2->reset(); + TSheet_field& sf = (TSheet_field&)m2->field(F_SHEET); + sf.reset(); + int err, i = 0; - int i = 0; - while ((t.empty())&&(n==0)) - { - TToken_string riga(80); - TMask* m2 = app()._m2; - TSheet_field& sf = (TSheet_field&)m2->field(F_SHEET); - sf.reset(); + err = eff.read(f, tipodist, ndist, nrigadist); + while ( (err == NOERR) && (tipodist == 0) ) + { //carico tutti gli effetti che soddisfano alla condizio nello sheet riga.cut(0); - riga.add(FALSE); - riga.add(rec.get(EFF_NPROGTR)); - riga.add(rec.get(EFF_DATASCAD)); - riga.add(rec.get(EFF_CODCF)); - TEffetto eff(rec); + riga.add(' '); + riga.add(eff.get(EFF_NPROGTR)); + riga.add(eff.get(EFF_DATASCAD)); + + long codcf = eff.get_long(EFF_CODCF); + clifo->zero(); + clifo->put("TIPOCF", 'C'); + clifo->put("CODCF", codcf); + if (clifo->read() == NOERR) riga.add(clifo->get("RAGSOC")); + if (eff.rows_r() == 1) //se l'effetto contiene solo una riga metto i { //riferimenti al documento ed al numero di rata const TRectype& rec_r = eff.row_r(1); @@ -336,73 +486,308 @@ void TVariazione_distinte::carica_riba() riga.add(("Varie")); riga.add(("Varie")); } - riga.add(rec.get(EFF_CODVAL)); - riga.add(rec.get(EFF_IMPORTO)); - riga.add(rec.get(EFF_IMPORTOVAL)); + + riga.add(eff.get(EFF_CODVAL)); + riga.add(eff.get(EFF_IMPORTO)); + riga.add(eff.get(EFF_IMPORTOVAL)); + sf.row(i) = riga; - f.next(); - t = rec.get("TIPODIST"); - n = rec.get_long("NDIST"); i++; + f.setkey(4); + err = eff.next(f); + tipodist = eff.get("TIPODIST")[0]; } } -//handler per gestire la pressione del bottone aggiungi della maschera principale(ef0300a) -bool TVariazione_distinte::aggiungi_handler(TMask_field& f, KEY k) +//Handler che permette il controllo sulla abilitazione dei campi collegati +// al codice valuta +bool TVariazione_distinte::codval_handler(TMask_field& f, KEY k) { - if (k==K_SPACE) - { - TMask &m = f.mask(); - m.close(); - TMask* m2 = app()._m2; - m2->open(); - } - return TRUE; -} + TMask &m = f.mask(); + TString val(f.get()); -//handler per gestire la pressione del bottone elimina della maschera principale(ef0300a) -bool TVariazione_distinte::elimina_handler(TMask_field& f, KEY k) -{ - if (k==K_SPACE) - f.yesno_box("Vuoi veramente eliminare gli effetti"); - // SE SI ELIMINARE DALLO SHEET GLI EFFETTI SELEZIONATI (LA RIMOZIONE FISICA SARA' FATTA AL - // MOMENTO DELLA REGISTRAZIONE, SE NO NON FACCIO NULLA - return TRUE; -} - -//handler per gestire la pressione del bottone conferma della maschera per l'aggiunta delle riba(ef0300c) -bool TVariazione_distinte::conferma_handler(TMask_field& f, KEY k) -{ - if (k==K_ENTER) - { - TMask &m = f.mask(); - TMask* m2 = app()._msk; - m.close(); - m2->open(); - } - return TRUE; -} - -//handler della maschera per l'aggiunta delle riba(ef0300c) -bool TVariazione_distinte::m2_handler(TMask& m, KEY k) -{ - if (k==K_ENTER) - carica_riba(); + if (f.to_check(k, TRUE)) + { + const bool condition = (val == "LIT" || val.empty()); + m.enable(F_TOTIMPVAL,!condition); + if (condition) + m.reset(F_TOTIMPVAL); + } return TRUE; } -//handler per gestire la pressione del bottone annulla della maschera per l'aggiunta delle riba(ef0300c) -bool TVariazione_distinte::annulla_handler(TMask_field& f, KEY k) -{ - TMask &m = f.mask(); - TMask* m2 = app()._msk; - m.close(); - m2->open(); +//Handler per gestire il caricamento degli effetti nella distinta in automatico +// relativamente ad un importo fissato (per la maschera princiapale) +bool TVariazione_distinte::importo_handler(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + TSheet_field& sf_riba = (TSheet_field&)m.field(F_SHEET_RIBA); + + if (f.to_check(k, TRUE)) + { + const int mode = m.mode(); + if( mode == MODE_INS || mode == MODE_MOD ) + { + TMask* m2 = app()._m2; + long imp_pres = m.get_long(F_TOTIMP); + long imp = m.get_long(F_IMP); + long impdist = imp - imp_pres; + + if (impdist > 0) + { + app().begin_wait(); + carica_riba(); + app().end_wait(); + m2->reset(F_TOTIMPDIST); + m2->reset(F_IMPSEL); + m2->set(F_TOTIMPDIST, impdist); + m2->run(); + } + + if (impdist < 0) + error_box("Il valore di presentazione non può superare l'importo della distinta"); + } + } + sf_riba.force_update(); + sf_riba.set_dirty(); + return TRUE; +} + +//Handler per gestire il caricamento degli effetti nella distinta in automatico +// relativamente ad un importo fissato (per la maschera secondaria) +bool TVariazione_distinte::imp_aut_handler(TMask_field& f, KEY k) +{ + TMask& m2 = f.mask(); + + if (f.to_check(k, TRUE)) + { + TMask* m = app()._msk; + TSheet_field& sf = (TSheet_field&)m2.field(F_SHEET); + TSheet_field& sf_riba = (TSheet_field&)m->field(F_SHEET_RIBA); + long impdist = m->get_long(F_IMP) - m->get_long(F_TOTIMP); + long tot_imp_dist = m2.get_long(F_TOTIMPDIST), impsel = 0; + + if (tot_imp_dist != 0 && impdist != 0) + { + TString val = m->get(F_CODVAL); + int items = sf.items(); + + for(int i = 0; i < items; i++) + { + TToken_string& row = sf.row(i); + TString codval = row.get(7); + + if (codval == " " || codval == "LIT")//se la valuta non appare o è lire + codval.trim(); //faccio in modo che vengano presi gli effetti con valuta inesistente + + long imp = row.get_long(8); + + if ((imp <= tot_imp_dist) && ((impsel+imp) <= tot_imp_dist)) + { + if ((sf_riba.items() == 0) && (val.empty()|| val == "LIT"))//se non è stata specificata una valuta si prende quella del + { //primo effetto che si carica nella distinta + m->set(F_CODVAL, codval); + val = m->get(F_CODVAL); + } + + if (codval == val) + { + row.add('X',0);//seleziono l'effetto poichè soddisfa alle condizione richieste + impsel += imp; + } + } + + if (impsel <= tot_imp_dist) continue; + else break; + } + sf.force_update(); + calcola(); + } + } + return TRUE; +} + + +//Handler per gestire la pressione del bottone conferma della maschera per l'aggiunta delle +// riba (ef0300c) +bool TVariazione_distinte::conferma_handler(TMask_field& f, KEY k) +{ + TMask* msk = app()._msk; + TSheet_field& sf_riba = (TSheet_field&)msk->field(F_SHEET_RIBA); + + if (k==K_ENTER) + { + TMask& m = f.mask(); + m.close(); + TSheet_field& sf = (TSheet_field&)m.field(F_SHEET); + int items = sf.items(); + bool condition = FALSE; + + for (int i = 0; i < items; i++) + { + TToken_string& row = sf.row(i); + condition = *row.get(0)== 'X'; + + if (condition) + { + row[0] = ' '; + sf_riba.row(-1) = row; + } + } + } + sf_riba.force_update(); + calcola_totale(); return TRUE; } -//Calcola i totali relativi alla distinta (totale in lire e totale in valuta(se presente)) +//Handler per gestire la pressione del bottone annulla della maschera per l'aggiunta delle riba +// (ef0300c) +bool TVariazione_distinte::annulla_handler(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + m.close(); + return TRUE; +} + +//Handler per gestire la scelta per data +bool TVariazione_distinte::from_data_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + TMask& m = f.mask(); + if (!f.get().empty()) + { + bool deleted = FALSE; + TDate data = m.get_date(F_DADATA); + TSheet_field& sf = (TSheet_field&)m.field(F_SHEET); + + for(int i = 0; i < sf.items(); i++) + { + if (deleted) i--; + TToken_string& row = sf.row(i); + TDate data_sh = (TDate)row.get(2); + if (data_sh < data) + { + sf.destroy(i); + deleted = TRUE; + } + else deleted = FALSE; + } + } + } + return TRUE; +} + +//Handler per gestire la scelta per data +bool TVariazione_distinte::to_data_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + TMask& m = f.mask(); + if (!f.get().empty()) + { + bool deleted = FALSE; + TDate data = m.get_date(F_ADATA); + TSheet_field& sf = (TSheet_field&)m.field(F_SHEET); + + for(int i = 0; i < sf.items(); i++) + { + if (deleted) i--; + TToken_string& row = sf.row(i); + TDate data_sh = (TDate)row.get(2); + if (data_sh > data) + { + sf.destroy(i); + deleted = TRUE; + } + else deleted = FALSE; + } + } + } + return TRUE; +} +//COMPARE FUNCTION per l'ordinamento per data degli effetti presenti nello sheet +HIDDEN int confronta_data(const TObject** o1, const TObject** o2) +{ + int val; + TToken_string* s1 = (TToken_string*) *o1; + TToken_string* s2 = (TToken_string*) *o2; + TDate data1 = s1->get(2); + TDate data2 = s2->get(2); + if (data1 == data2) + val = 0; + else + val = (data1 > data2) ? +1 : -1; + return val; +} + +//Handler per gestire l'ordinamento per data degli effetti presenti nello sheet +void TVariazione_distinte::ord_data() +{ + TMask* m = app()._m2; + TSheet_field& sf = (TSheet_field&)m->field(F_SHEET); + TArray& effetti = sf.rows_array(); + app().begin_wait(); + effetti.sort(confronta_data); + app().end_wait(); + sf.force_update(); +} + +//COMPARE FUNCTION per l'ordinamento per numero e data fattura degli effetti presenti nello sheet +HIDDEN int confronta_fatt(const TObject** o1, const TObject** o2) +{ + int val; + TToken_string* s1 = (TToken_string*) *o1; + TToken_string* s2 = (TToken_string*) *o2; + long num1 = s1->get_long(4); + long num2 = s2->get_long(4); + TDate data1 = s1->get(5); + TDate data2 = s2->get(5); + if (num1 != num2) + { + val = (num1 > num2) ? +1 : -1; + return val; + } + if (data1 == data2) + { + val = 0; + return val; + } + else + { + val = (data1 > data2) ? +1 : -1; + return val; + } +} + +//Handler per gestire l'ordinamento per numero e data fattura degli effetti presenti nello sheet +void TVariazione_distinte::ord_fatt() +{ + TMask* m = app()._m2; + TSheet_field& sf = (TSheet_field&)m->field(F_SHEET); + TArray& effetti = sf.rows_array(); + app().begin_wait(); + effetti.sort(confronta_fatt); + app().end_wait(); + sf.force_update(); +} + +//Handler per gestire i diversi ordinamenti +bool TVariazione_distinte::ordina_handler(TMask_field& f, KEY k) +{ + if (f.to_check(k, TRUE)) + { + char ord = f.get()[0]; + if (ord == 'S')//ordino gli effetti nello sheet per data + ord_data(); + if (ord == 'F') + ord_fatt();//ordino gli effetti nello sheet per fattura + } + return TRUE; +} + +//Metodo che calcola i totali relativi alla distinta (totale in lire e totale in valuta(se presente)) void TVariazione_distinte::calcola_totale() { TMask* m = app()._msk; @@ -412,25 +797,81 @@ void TVariazione_distinte::calcola_totale() for (int i = 0; i < items; i++) { TToken_string& row = sf.row(i); + bool condition = *row.get(0) == 'X'; + if (condition) + { + imp = row.get(8); + impdist -= imp; + impval = row.get(9); + impdistval -= impval; + } imp = row.get(8); impdist += imp; impval = row.get(9); - impdistval += impval; + impdistval += impval; } m->set(F_TOTIMP, impdist); m->set(F_TOTIMPVAL, impdistval); + m->set(F_IMP, impdist); } -//Notify per il calcolo dei totali relativi alla distinta +//Metodo che calcola i totali relativi alla selezione effetti per la distinta +void TVariazione_distinte::calcola() +{ + TMask* m2 = app()._m2; + TMask* m = app()._msk; + TSheet_field& sf = (TSheet_field&)m2->field(F_SHEET); + int items = sf.items(); + real imp, impsel; + long imp_pres = m->get_long(F_TOTIMP); + long importo = m->get_long(F_IMP); + long impdist = importo - imp_pres; + if (impdist == 0) + m2->set(F_TOTIMPDIST, importo); + for (int i = 0; i < items; i++) + { + TToken_string& row = sf.row(i); + bool condition = *row.get(0) == 'X'; + if (condition) + { + imp = row.get(8); + impsel += imp; + m2->set(F_IMPSEL, impsel); + if (impdist == 0 && imp_pres == 0) + m2->set(F_TOTIMPDIST, impsel); + /*if (impdist != 0 && imp_pres != 0) + m2->set(F_TOTIMPDIST, imp_pres+impsel);*/ + } + } +} + +//Handler per il calcolo dei totali relativi alla selezione effetti per la distinta +bool TVariazione_distinte::imp_notify(TSheet_field& s, int r, KEY key) +{ + if (s.to_check(key, TRUE)) + calcola(); + return TRUE; +} + +//Metodo che permette di aggiungere effetti alla distinta caricandoli tra quelli non ancora assegnati +void TVariazione_distinte::aggiungi() +{ + TMask* m2 = app()._m2; + app().begin_wait(); + carica_riba(); + app().end_wait(); + m2->reset(F_TOTIMPDIST); + m2->reset(F_IMPSEL); + m2->run(); +} + +//Handler per il calcolo dei totali relativi alla distinta bool TVariazione_distinte::impdist_notify(TSheet_field& s, int r, KEY key) { if (s.to_check(key, TRUE)) calcola_totale(); - if (key == K_DEL && s.items()==1) - { - error_box("IMPOSSIBILE CANCELLARE: La distinta deve contenere almeno un effetto!"); - return FALSE; - } + if (key == K_INS) + aggiungi(); return TRUE; } diff --git a/ef/ef0300.h b/ef/ef0300.h index eb6832b56..8558e227b 100755 --- a/ef/ef0300.h +++ b/ef/ef0300.h @@ -11,12 +11,12 @@ #define F_DENBANP 105 #define F_CODABIP 106 #define F_CODCABP 107 -#define F_TOTIMP 108 -#define F_TOTIMPVAL 109 -#define F_CODVAL 110 -#define F_SHEET_RIBA 111 -#define B_AGGIUNGI 112 -#define B_ELIMINA 113 +#define F_TOTIMP 108 +#define F_IMP 109 +#define F_TOTIMPVAL 110 +#define F_CODVAL 111 +#define F_SHEET_RIBA 112 + // Identificatori campi per lo spreadsheet Righe Distinta @@ -37,6 +37,8 @@ #define F_DADATA 101 #define F_ADATA 102 #define F_TIPORD 103 -#define F_SHEET 104 +#define F_SHEET 104 +#define F_TOTIMPDIST 105 +#define F_IMPSEL 106 #endif // __EF0300.H diff --git a/ef/ef0300a.uml b/ef/ef0300a.uml index fa32b2d85..53a765416 100755 --- a/ef/ef0300a.uml +++ b/ef/ef0300a.uml @@ -1,21 +1,19 @@ #include "ef0300.h" TOOLBAR "" 0 20 0 2 - #include - ENDPAGE PAGE "Gestione Distinte" 0 -1 0 19 -GROUPBOX DLG_NULL 78 9 +GROUPBOX DLG_NULL 78 10 BEGIN PROMPT 1 0 "" END LIST F_TIPODIST 19 BEGIN - PROMPT 2 1 "Tipo Distinta " + PROMPT 2 1 "Tipo Distinta " KEY 4 FIELD LF_EFFETTI->TIPODIST ITEM "I|All'incasso" @@ -24,8 +22,8 @@ BEGIN END LIST F_NUMBERRIGA 10 -BEGIN - PROMPT 1 60 "Numero Riga Distinta" +BEGIN + PROMPT 1 60 "Numero Riga Distinta " KEY 4 FIELD LF_EFFETTI->NRIGADIST ITEM "1|PRIMA RIGA" @@ -33,51 +31,51 @@ BEGIN END NUMBER F_NUMBER 7 -BEGIN - PROMPT 48 1 "Numero Distinta " +BEGIN + PROMPT 48 1 "Numero Distinta " FIELD LF_EFFETTI->NDIST FLAGS "R" KEY 4 USE LF_EFFETTI KEY 4 SELECT NRIGADIST = 1 + INPUT NDIST F_NUMBER INPUT TIPODIST F_TIPODIST - INPUT NDIST F_NUMBER INPUT NRIGADIST F_NUMBERRIGA - DISPLAY "Tipo distinta" TIPODIST DISPLAY "Nr. distinta" NDIST - //DISPLAY "Nr. riga distinta" NRIGADIST + DISPLAY "Tipo distinta" TIPODIST + OUTPUT F_NUMBER NDIST OUTPUT F_TIPODIST TIPODIST - OUTPUT F_NUMBER NDIST OUTPUT F_NUMBERRIGA NRIGADIST CHECKTYPE REQUIRED END DATE F_DATA -BEGIN - PROMPT 2 2 "Data Distinta " +BEGIN + PROMPT 2 2 "Data Distinta " FIELD LF_EFFETTI->DATADIST END TEXT DLG_NULL -BEGIN - PROMPT 2 3 "Banca di Presentazione " +BEGIN + PROMPT 2 3 "Banca di Presentazione " END STRING F_DENBANP 50 BEGIN - PROMPT 25 3 "" + PROMPT 26 3 "" FLAGS "U" USE %BAN KEY 2 - INPUT S0 F_DENBANP - DISPLAY "Codice ABI" CODTAB[1,5] + INPUT S0 F_DENBANP DISPLAY "Denominazione@50" S0 + DISPLAY "Codice ABI" CODTAB[1,5] + DISPLAY "Codice CAB" CODTAB[6,10] OUTPUT F_DENBANP S0 OUTPUT F_CODABIP CODTAB[1,5] OUTPUT F_CODCABP CODTAB[6,10] -END - +END + NUMBER F_CODABIP 5 0 BEGIN - PROMPT 14 4 "Codice ABI " + PROMPT 15 4 "Codice ABI " FIELD LF_EFFETTI->CODABIP FLAGS "RZ" USE %BAN KEY 1 SELECT CODTAB ?= "?????" @@ -85,50 +83,62 @@ BEGIN DISPLAY "Codice ABI" CODTAB[1,5] DISPLAY "Denominazione@50" S0 OUTPUT F_CODABIP CODTAB[1,5] - OUTPUT F_CODCABP CODTAB[6,10] - OUTPUT F_DENBANP S0 - CHECKTYPE NORMAL + OUTPUT F_CODCABP CODTAB[6,10] + CHECKTYPE REQUIRED WARNING "Codice ABI assente" END NUMBER F_CODCABP 5 0 BEGIN - PROMPT 14 5 "Codice CAB " + PROMPT 15 5 "Codice CAB " FIELD LF_EFFETTI->CODCABP FLAGS "RZ" - USE %BAN KEY 1 SELECT CODTAB ?= "??????????" - INPUT CODTAB[1,5] F_CODABIP - INPUT CODTAB[6,10] F_CODCABP + USE %BAN KEY 1 SELECT CODTAB ?= "??????????" + INPUT CODTAB[1,5] F_CODABIP + INPUT CODTAB[6,10] F_CODCABP DISPLAY "Codice ABI" CODTAB[1,5] DISPLAY "Codice CAB" CODTAB[6,10] - DISPLAY "Denominazione@50" S0 + DISPLAY "Denominazione@50" S0 OUTPUT F_CODABIP CODTAB[1,5] OUTPUT F_CODCABP CODTAB[6,10] OUTPUT F_DENBANP S0 - CHECKTYPE NORMAL + CHECKTYPE REQUIRED VALIDATE REQIF_FUNC 1 F_CODCABP WARNING "Banca assente" END NUMBER F_TOTIMP 18 2 BEGIN - PROMPT 2 6 "Valore Distinta " + PROMPT 2 6 "Valore di presentazione " +END + +NUMBER F_IMP 18 2 +BEGIN + PROMPT 2 7 "Importo Distinta " + NUM_EXPR #F_IMP>=#F_TOTIMP + WARNING "Il valore di presentazione non puo' superare l'importo della distinta" END NUMBER F_TOTIMPVAL 18 3 -BEGIN - PROMPT 2 7 "Valore Distinta Val. " +BEGIN + PROMPT 2 8 "Valore di pres. in val. " END -STTING F_CODVAL 8 +STRING F_CODVAL 3 BEGIN - PROMPT 48 7 "Codice Valuta " + PROMPT 48 8 "Codice Valuta " + FLAGS "UZ" + USE %VAL + INPUT CODTAB F_CODVAL + DISPLAY "Codice" CODTAB + DISPLAY "Nome@50" S0 + OUTPUT F_CODVAL CODTAB END -SPREADSHEET F_SHEET_RIBA 78 8 +SPREADSHEET F_SHEET_RIBA 78 10 BEGIN PROMPT 1 10 "RIGHE DISTINTA" - ITEM " " + ITEM "" ITEM "Nr. Ri.Ba." ITEM "Scadenza" ITEM "Cliente@50" @@ -140,20 +150,6 @@ BEGIN ITEM "Importo Val." END -BUTTON B_AGGIUNGI 10 2 -BEGIN - PROMPT -12 -2 "~AGGIUNGI" - PICTURE BMP_NEWREC - PICTURE BMP_NEWRECDN -END - -BUTTON B_ELIMINA 10 2 -BEGIN - PROMPT -22 -2 "~ELIMINA" - PICTURE BMP_DELREC - PICTURE BMP_DELRECDN -END - ENDPAGE ENDMASK diff --git a/ef/ef0300b.uml b/ef/ef0300b.uml index 199d491b6..a4c536b5a 100755 --- a/ef/ef0300b.uml +++ b/ef/ef0300b.uml @@ -85,6 +85,7 @@ BUTTON DLG_DELREC 9 2 BEGIN PROMPT -33 -1 "Elimina" MESSAGE EXIT, K_DEL + FLAGS "H" END ENDPAGE diff --git a/ef/ef0300c.uml b/ef/ef0300c.uml index 36d6da548..18721dd1e 100755 --- a/ef/ef0300c.uml +++ b/ef/ef0300c.uml @@ -1,6 +1,6 @@ #include "ef0300.h" -PAGE "Aggiungi Effetti alla Distinta" -1 -1 78 18 +PAGE "Aggiungi Effetti alla Distinta" -1 -1 78 20 GROUPBOX DLG_NULL 60 3 BEGIN @@ -10,15 +10,11 @@ END DATE F_DADATA BEGIN PROMPT 2 2 "Dalla Data " - FIELD LF_EFFETTI->DATASCAD - CHECKTYPE NORMAL END DATE F_ADATA BEGIN PROMPT 30 2 "Alla Data " - FIELD LF_EFFETTI->DATASCAD - CHECKTYPE NORMAL END LIST F_TIPORD 14 @@ -29,10 +25,10 @@ BEGIN ITEM "F|Fattura " END -SPREADSHEET F_SHEET 74 8 +SPREADSHEET F_SHEET 74 12 BEGIN - PROMPT 2 6 "EFFETTI SELEZIONABILI" - ITEM " " + PROMPT 2 5 "EFFETTI SELEZIONABILI" + ITEM "" ITEM "Nr. Ri.Ba." ITEM "Scadenza" ITEM "Cliente@50" @@ -44,6 +40,16 @@ BEGIN ITEM "Importo Val." END +NUMBER F_TOTIMPDIST 18 2 +BEGIN + PROMPT 2 18 "Importo " +END + +NUMBER F_IMPSEL 18 2 +BEGIN + PROMPT 37 18 "Importo Selezionato " +END + BUTTON DLG_OK 9 2 BEGIN PROMPT -12 -1 "" diff --git a/ef/ef0301.cpp b/ef/ef0301.cpp index 841ba21ef..a136d8783 100755 --- a/ef/ef0301.cpp +++ b/ef/ef0301.cpp @@ -16,17 +16,17 @@ TDistinta::TDistinta(const char tipo, const long numero) int TDistinta::read(const char tipo, const long numero) { int err = NOERR; - CHECK(tipo!='\0' && numero>0,"Can't read distinta from NULL elements"); - + CHECK(tipo!='\0' && numero > 0,"Can't read distinta from NULL elements"); + TLocalisamfile f(LF_EFFETTI); for (int i=0; err == NOERR ; i++) { TEffetto* effetto = new TEffetto; - err = effetto->read(tipo, numero, i+1); + err = effetto->read(f, tipo, numero, i+1); if (err == NOERR) _righe_dist.add(effetto); } - if ((_righe_dist.items()>0)||(err == _iseof)) - err = NOERR; + if ((_righe_dist.items()>0)||(err == _iseof) ) + err = NOERR; return err; } @@ -42,6 +42,7 @@ int TDistinta::write(bool force, TToken_string* dati_dist) { int err = NOERR; const int elem = items(); + TLocalisamfile f(LF_EFFETTI); for (int i=0; iget_long()); effetto.put("NRIGADIST", i+1); - err = effetto.rewrite(); + err = effetto.rewrite(f); } return err; } int TDistinta::remove(char tipodist, long ndist) { - int err= NOERR; - err = reset() == NOERR; - //rimuovo dal file effetti - TLocalisamfile eff(LF_EFFETTI); - eff.put("TIPODIST",tipodist); - eff.put("NDIST",ndist); - eff.read(_isgteq); - char t = eff.get_char("TIPODIST"); - long n = eff.get_long("NDIST"); - while ((t==tipodist)&&(n==ndist)) + int err; + //elimino dal file + TLocalisamfile file(LF_EFFETTI); + for (int i = 0; i < items(); i++) { - eff.zero("TIPODIST"); - eff.zero("NDIST"); - eff.zero("DATADIST"); - eff.zero("NRIGADIST"); - eff.zero("CODABIP"); - eff.zero("CODCABP"); - eff.rewrite(); - eff.next(); - t = eff.get_char("TIPODIST"); - n = eff.get_long("NDIST"); + TEffetto& effetto = (TEffetto&)_righe_dist[i]; + err = effetto.read(file, tipodist,ndist,i+1); + effetto.zero("TIPODIST"); + effetto.zero("NDIST"); + effetto.zero("DATADIST"); + effetto.zero("NRIGADIST"); + effetto.zero("CODABIP"); + effetto.zero("CODCABP"); + err = effetto.rewrite(file); } + reset(); return err; }