#include "clifor.h" #ifndef __CONFIG_H #include "config.h" #endif #ifndef __VE0100_H #include "ve0100.h" #endif #ifndef __VE0100O_H #include "ve0100o.h" #endif #ifndef __VEINI_H #include "veini.h" #endif #ifndef __VELIB_H #include "velib.h" #endif TOccasionale::TOccasionale() : TRectype(LF_OCCAS) { _cod = new TRecfield(*this, OCC_CFPI); } TOccasionale::TOccasionale(const TRectype& r) : TRectype(r) { _cod = new TRecfield(*this, OCC_CFPI); } TRectype & TOccasionale::operator = (const TRectype& r) { return TRectype::operator=(r); } TOccasionale::~TOccasionale() { delete _cod; } int TCli_for::write_rewrite(TBaseisamfile& f, bool re) const { int err = TMultiple_rectype::write_rewrite(f, re); if (err == NOERR) { TLocalisamfile v(LF_CFVEN); TRectype & v_rec = vendite(); err = v.write(v_rec); if (err == _isreinsert) err = v.write(v_rec); } return err; } TRectype & TCli_for::vendite() const { const char t = tipo(); const long c = codice(); if (_ven_rec.empty() || t != *(const char *) (*_ven_tipo) || c != (long) *_ven_codice) { TLocalisamfile v(LF_CFVEN); ((TCli_for *)this)->_ven_rec.zero(); ((TCli_for *)this)->_ven_rec.put(CFV_TIPOCF,t); ((TCli_for *)this)->_ven_rec.put(CFV_CODCF, c); TRectype v_rec(_ven_rec); if (((TCli_for *)this)->_ven_rec.read(v) != NOERR) ((TCli_for *)this)->_ven_rec = v_rec; } return (TRectype &) _ven_rec; } int TCli_for::read(TRectype & rec, word op, word lockop) { int err = TMultiple_rectype::read(rec, op, lockop); _ven_rec.zero(); return err; } int TCli_for::read(char tipo, long codice, word op, word lockop) { zero(); put(CLI_TIPOCF, tipo); put(CLI_CODCF, codice); return TMultiple_rectype::read(op, lockop); } int TCli_for::remove(TBaseisamfile& f) const { TLocalisamfile v(LF_CFVEN); const int err = vendite().remove(v); if (err != NOERR && err != _iskeynotfound) return err; return TMultiple_rectype:: remove(f); } TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN) { _tipo = new TRecfield(*this, CLI_TIPOCF); _codice = new TRecfield(*this, CLI_CODCF); _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF); _ven_codice = new TRecfield(_ven_rec, CFV_CODCF); add_file(LF_INDSP, IND_CODIND); read(tipo, codice); } TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN) { _tipo = new TRecfield(*this, CLI_TIPOCF); _codice = new TRecfield(*this, CLI_CODCF); _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF); _ven_codice = new TRecfield(_ven_rec, CFV_CODCF); add_file(LF_INDSP, IND_CODIND); read((TRectype &) rec); } TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec) { _tipo = new TRecfield(*this, CLI_TIPOCF); _codice = new TRecfield(*this, CLI_CODCF); _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF); _ven_codice = new TRecfield(_ven_rec, CFV_CODCF); } TCli_for::~TCli_for() { delete _tipo; delete _codice; delete _ven_tipo; delete _ven_codice; } /* void TCli_for_vendite::update_mask( TMask& m, TMask & occas_mask, bool onload ) { const TString16 codval(m.get(F_CODVAL)); const TString16 datacambio(m.get(F_DATACAMBIO1)); // Setta i campi che appartengono al file LF_CLIFO const bool occas = occasionale(); m.show(F_OCCASEDIT, occas); // In forse per l'Occasionale, sicuri per il Normale m.show(F_COFI, !occas); m.show(F_STATOPAIVA, !occas); m.show(F_PAIVA, !occas); m.set(F_RAGSOC, get(CLI_RAGSOC)); m.enable(F_RAGSOC, !occas); const TRectype & ven_rec = vendite(); if(!onload) { short pos = m.id2pos(F_CODVAL); const TString & codval = get(CLI_CODVAL); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).set(codval); pos = m.id2pos(F_CODVAL1); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).set(codval); pos = m.id2pos(F_CODLIN); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).set(get(CLI_CODLIN)); m.set(F_CODPAG, get(CLI_CODPAG)); m.set(F_CODABIA, get(CLI_CODABI)); m.set(F_CODCABA, get(CLI_CODCAB)); // Setta i campi che appartengono al file LF_CFVEN m.set(F_CODABIP, ven_rec.get(CFV_CODABIPR)); m.set(F_CODCABP, ven_rec.get(CFV_CODCABPR)); m.set(F_RAGGR, ven_rec.get(CFV_RAGGDOC)); m.set(F_CODINDSP, ven_rec.get(CFV_CODINDSP)); m.set(F_CODAG, ven_rec.get(CFV_CODAG)); m.set(F_CODSPMEZZO, ven_rec.get(CFV_CODSPMEZZO)); m.set(F_CODPORTO, ven_rec.get(CFV_CODPORTO)); m.set(F_CODNOTESP1, ven_rec.get(CFV_CODNOTESP1)); m.set(F_CODNOTESP2, ven_rec.get(CFV_CODNOTESP2)); m.set(F_CODNOTE, ven_rec.get(CFV_CODNOTE)); m.set(F_CODVETT1, ven_rec.get(CFV_CODVETT1)); m.set(F_CODVETT2, ven_rec.get(CFV_CODVETT2)); m.set(F_CODVETT3, ven_rec.get(CFV_CODVETT3)); m.set(F_SPESEINC, ven_rec.get(CFV_PERCSPINC)); m.set(F_ADDBOLLI, ven_rec.get(CFV_ADDBOLLI)); m.set(F_CATVEN, ven_rec.get(CFV_CATVEN)); pos = m.id2pos(F_CODLIST); const TString & codlist = ven_rec.get(CFV_CODLIST); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).set(codlist); pos = m.id2pos(F_CODLIST1); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).set(codlist); if (m.id2pos(F_CODAG) >= 0 && m.field(F_CODAG).active()) m.set(F_CODAG, ven_rec.get(CFV_CODAG)); m.set(F_CODZON, ven_rec.get(CFV_CODZONA)); m.set(F_RAGGR, ven_rec.get(CFV_RAGGDOC)); } if (occas) { m.reset(F_COFI); m.reset(F_PAIVA); m.reset(F_LOCALITACF); m.set( F_OCFPI, occas_mask.get(O_CODICE)); m.set( F_RAGSOC, occas_mask.get(O_RAGSOC)); m.set( F_INDCF, occas_mask.get(O_INDIRIZZO)); m.set( F_CIVCF, occas_mask.get(O_NUMERO)); m.set( F_CAPCF, occas_mask.get(O_CAP)); m.set( F_COMCF, occas_mask.get(O_COMUNE)); m.set( F_STATOCF, occas_mask.get(O_STATO)); } else { occas_mask.reset(); m.set(F_COFI, get(CLI_COFI)); m.set(F_INDCF, get(CLI_INDCF)); m.set(F_CIVCF, get(CLI_CIVCF)); m.set(F_STATOPAIVA, get(CLI_STATOPAIV)); m.set(F_PAIVA, get(CLI_PAIV)); m.set(F_LOCALITACF, get(CLI_LOCCF)); m.set(F_CAPCF, get(CLI_CAPCF)); m.set(F_COMCF, get(CLI_COMCF)); m.set(F_STATOCF, get(CLI_STATOCF)); } const TString16 newcodval(m.get(F_CODVAL)); const TString16 newdatacambio(m.get(F_DATACAMBIO1)); short pos = m.id2pos(F_CAMBIO); if ((pos >= 0) && (newcodval.empty() || newdatacambio.empty())) m.fld(F_CAMBIO).reset(); pos = m.id2pos(F_CODVAL); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); pos = m.id2pos(F_CODVAL1); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); pos = m.id2pos(F_DATACAMBIO1); if (pos >= 0 && m.field(pos).active() && (codval != newcodval || datacambio != newdatacambio)) m.fld(pos).check(); m.check_field(F_COMCF); m.check_field(F_STATOCF); m.check_field( F_CODPAG ); pos = m.id2pos(F_CODLIN); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); m.check_field( F_CODCABA ); pos = m.id2pos(F_CODLIST); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); pos = m.id2pos(F_CODLIST1); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); m.check_field( F_CODCABP ); m.check_field( F_CODINDSP ); pos = m.id2pos(F_CODAG); if (pos >= 0 && m.fld(pos).active()) m.fld(pos).check(); m.check_field( F_CODSPMEZZO ); m.check_field( F_CODPORTO ); m.check_field( F_CODNOTESP1 ); m.check_field( F_CODNOTESP2 ); m.check_field( F_CODNOTE ); m.check_field( F_CODVETT1 ); m.check_field( F_CODVETT2 ); m.check_field( F_CODVETT3 ); m.check_field( F_CATVEN ); m.check_field( F_CODZON ); const bool gescontr = app().config_ditta().get_bool("GES", "ve", 2); const bool contr_enabled = ven_rec.get_bool(CFV_GESTCONTR); m.enable(F_CODCONT1, contr_enabled && gescontr); m.enable(F_CODCONT, contr_enabled && gescontr); if (!onload) { imposta_indirizzo_spedizione(m, occas_mask); imposta_sconto_testa(m); imposta_spese(m); } } void TCli_for::edita_occasionale( ) { CHECK( occasionale( ), "Impossibile editare come occasionale un cliente non occasionale!" ); _occas_mask.run( ); }; bool TCli_for::occas_code_handler(TMask_field& f, KEY key) { if (key == K_TAB) { const char* code = f.get(); if (*code) { TRelation occas(LF_OCCAS); occas.lfile().put("CFPI", code); if (occas.read(_isequal) == NOERR) { f.mask().autoload(occas); f.mask().send_key(K_TAB, O_COMUNE); // Forza decodifica comuni f.mask().send_key(K_TAB, O_COMUNENAS); } } } return TRUE; } void TCli_for_vendite::imposta_indirizzo_spedizione(TMask& m, TMask & occas_mask) { const bool occas = occasionale(); m.enable( F_CODINDSP , !occas); if (occas) { m.reset( F_CODINDSP); m.set( F_RAGSOCSP, occas_mask.get(O_RAGSOC)); m.set( F_INDSP, occas_mask.get(O_INDIRIZZO)); m.set( F_CIVSP, occas_mask.get(O_NUMERO)); // Sugli occasionali non c'è la località m.reset( F_LOCALITASP); m.set( F_CAPSP, occas_mask.get(O_CAP)); m.set( F_COMSP, occas_mask.get(O_COMUNE)); m.check_field(F_COMSP); m.set( F_STATOSP, occas_mask.get(O_STATO)); m.check_field(F_STATOSP); } } void TCli_for_vendite::imposta_sconto_testa( TMask& m ) { TConfig & ditta = app().config_ditta(); const char tipogestione = ditta.get("GESSCO", "ve")[ 0 ]; switch( tipogestione ) { case 'N': // Sconti non gestiti: pussa via! break; case 'P': // Percentuale su anagrafica cliente m.set( F_SCONTOPERC, get(CLI_SCONTO)); break; case 'T': // Gestione tabella sconti { const TString16 codsconto(vendite().get(CFV_CODSCC)); if (codsconto.not_empty()) { TTable sconti("%SCC"); sconti.setkey(1); sconti.zero(); sconti.put("CODTAB", codsconto); if (sconti.read( ) == NOERR) m.set(F_SCONTOPERC, sconti.get("S1")); } } break; case 'A': // Gestione archivio sconti { TString16 cod; const TRectype & ven_rec = vendite(); TLocalisamfile sconti(LF_SCONTI ); sconti.setkey(1); sconti.zero(); sconti.put("TIPO", "I"); if(ditta.get_bool("SCOKEY", "ve", 1)) sconti.put("CODCAT", ven_rec.get(CFV_CATVEN)); if(ditta.get_bool("SCOKEY", "ve", 2)) cod = ven_rec.get(CFV_CODSCC); else cod = " "; if( ditta.get_bool("SCOKEY", "ve", 3)) cod << ven_rec.get(CFV_CODZONA); else cod << " "; if( ditta.get_bool("SCOKEY", "ve", 4)) cod << get(CLI_CODPAG); sconti.put("CODART", cod); if(sconti.read() == NOERR) m.set(F_SCONTOPERC, sconti.get( "SCONTO")); } break; default: break; } return; } void TCli_for_vendite::imposta_spese( TMask& m ) { TSheet_field & sh = (TSheet_field &) m.field(F_SHEET); TDocumento & doc = app().doc(); TString16 name("CODSP0"); TString_array spese; for (int i = 1; i <= 4; i++) { name.rtrim(1); name << i; const TString16 s(get(name)); if (s.not_empty()) spese.add(s); } m.autosave(*app().get_relation()); doc.update_spese_aut(spese, FALSE, &sh); sh.force_update(); } */