#include "cg3.h" #include "cg3900a.h" #include "cglib01.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /////////////////////////////////////////////////////////// // TAllegato_info /////////////////////////////////////////////////////////// struct TAllegato_importi : public TObject { real _imp, _iva, _impNI, _impES, _ivaNE, _impNA; bool is_not_null() const { return !(_imp.is_zero() && _iva.is_zero() && _impNI.is_zero() && _impES.is_zero() && _ivaNE.is_zero()); } }; class TAllegato_info : public TObject { char _tipo; long _codice; TAllegato_importi _curr, _prec; public: char tipo() const { return _tipo; } long codice() const { return _codice; } const TRectype& clifo() const; TAllegato_importi& importi(bool prec) { return prec ? _prec : _curr; } const TAllegato_importi& importi(bool prec) const { return prec ? _prec : _curr; } bool is_not_null() const { return _curr.is_not_null() || _prec.is_not_null(); } TAllegato_info(char tipo, long codcf) : _tipo(tipo), _codice(codcf) { } TAllegato_info(const TRectype& rec); }; /////////////////////////////////////////////////////////// // TAllegati_set /////////////////////////////////////////////////////////// class TAllegati_set : public TAS400_recordset { protected: const TString& comune(const TRectype& clifo, const char* field) const; public: void add(const TAllegato_info& info); TAllegati_set(); }; const TString& TAllegati_set::comune(const TRectype& clifo, const char* field) const { TString8 key; key << clifo.get(CLI_STATOCF) << '|' << clifo.get(CLI_COMCF); const TString& s1 = cache().get(LF_COMUNI, key, field); if (s1.full()) return s1; key = " |"; key << cap2comune(clifo.get(CLI_CAPCF), clifo.get(CLI_LOCCF)); return cache().get(LF_COMUNI, key, field); } void TAllegati_set::add(const TAllegato_info& info) { new_rec(); const TRectype& clifo = info.clifo(); for (unsigned int i = 0; i < columns(); i++) { const TString& field = column_info(i)._name; if (clifo.type(field) != _nullfld) set(field, TVariant(clifo.get(field))); else { if (field == "COMUNE") { const TVariant var = comune(clifo, COM_DENCOM); set(field, var); } else if (field == "PROVINCIA") { const TVariant var = comune(clifo, COM_PROVCOM); set(field, var); } else { if (field.starts_with("C_") || field.starts_with("P_")) { const TAllegato_importi& allimp = info.importi(field[0] == 'P'); const TString& impfield = field.mid(2); if (impfield == "IMP") set(field, allimp._imp); else if (impfield == "IVA") set(field, allimp._iva); else if (impfield == "NI") set(field, allimp._impNI); else if (impfield == "ES") set(field, allimp._impES); else if (impfield == "NE") set(field, allimp._ivaNE); else if (impfield == "NA") set(field, allimp._impNA); } } } } } TAllegati_set::TAllegati_set() : TAS400_recordset("AS400(512)") { const char* const campi[] = { CLI_TIPOCF, CLI_CODCF, CLI_RAGSOC, CLI_COFI, CLI_PAIV, CLI_INDCF, CLI_CIVCF, CLI_CAPCF, CLI_LOCCF, CLI_COMCF, NULL }; TRectype clifo(LF_CLIFO); for (int i = 0; campi[i]; i++) { const char* f = campi[i]; create_field(f, -1, clifo.length(f), clifo.type(f)); } create_field("COMUNE", -1, 50, _alfafld); create_field("PROVINCIA", -1, 2, _alfafld); for (int j = 0; j < 2; j++) { create_field(j ? "P_IMP" : "C_IMP", -1, 15, _realfld); create_field(j ? "P_IVA" : "C_IVA", -1, 15, _realfld); create_field(j ? "P_NI" : "C_NI", -1, 15, _realfld); create_field(j ? "P_ES" : "C_ES", -1, 15, _realfld); create_field(j ? "P_NE" : "C_NE", -1, 15, _realfld); create_field(j ? "P_NA" : "C_NA", -1, 15, _realfld); } } const TRectype& TAllegato_info::clifo() const { TString16 key; key.format("%c|%ld", tipo(), codice()); return cache().get(LF_CLIFO, key); } TAllegato_info::TAllegato_info(const TRectype& rec) : _tipo(rec.get_char(CLI_TIPOCF)), _codice(rec.get_long(CLI_CODCF)) { } /////////////////////////////////////////////////////////// // TPadoaSchioppa_set /////////////////////////////////////////////////////////// class TPadoaSchioppa_set : public TAS400_recordset { protected: enum TPs_type { AN, NU }; void add_field(const int trc, int da, int a, int lung, const char* name, TPs_type nu, bool required = false, const char* def = NULL); void add_multi(const int trc, int da, int a, int lung, const char* name, int index, TPs_type nu, bool required = false, const char* def = NULL); void add_trc(int trc); public: bool set(const char* name, const TVariant& value, int idx = 0); bool set(const char* name, const TString& value, int idx = 0); bool set(const char* name, const TDate& value, int idx = 0); TPadoaSchioppa_set(); }; void TPadoaSchioppa_set::add_field(int trc, int da, int a, int lung, const char* name, TPs_type nu, bool required, const char* def) { CHECKS(da > 0 && a >= da, "Posizioni incoerenti sul campo ", name); CHECKS(lung == a-da+1, "Lunghezza incoerente sul campo ", name); TString80 field; field.format("%d.%s", trc, (const char*)name); const TFieldtypes ft = nu == NU ? _longzerofld : _alfafld; bool ok = false; if (def && *def) ok = create_field(field, da-1, lung, ft, required, TVariant(def)); else ok = create_field(field, da-1, lung, ft, required); CHECKS(ok, "Impossibile creare il campo ", (const char*)field); } void TPadoaSchioppa_set::add_multi(int trc, int da, int a, int lung, const char* name, int idx, TPs_type nu, bool required, const char* def) { CHECKD(trc == 1 || trc == 2, "Invalid record type ", trc); CHECKD(idx >= 1 && idx <= 8, "Invalid field index ", idx); TString80 field; field.format("%s(%d)", (const char*)name, idx); const int delta = trc == 1 ? 200*(idx-1) : 200*(idx-1); da += delta; a += delta; add_field(trc, da, a, lung, field, nu, required, def); } void TPadoaSchioppa_set::add_trc(int trc) { TString4 str; str << trc; add_field(trc, 1, 1, 1, "TipoRecord", NU, true, str); if (trc == 0 || trc == 9) // 0=Testata 9=Coda { add_field(trc, 2, 6, 5, "IndentificativoFornitura", AN, true, "CLIFO"); add_field(trc, 7, 8, 2, "CodiceFornitura" , NU, true, "38"); add_field(trc, 9, 24, 16, "CodiceFiscale" , AN, true); add_field(trc, 25, 35, 11, "PartitaIVA" , AN, true); add_field(trc, 36, 61, 26, "Cognome" , AN); add_field(trc, 62, 86, 25, "Nome" , AN); add_field(trc, 87, 87, 1, "Sesso" , AN); add_field(trc, 88, 95, 8, "DataNascita" , NU); add_field(trc, 96, 135, 40, "ComuneNascita" , AN); add_field(trc, 136, 137, 2, "ProvinciaNascita" , AN); add_field(trc, 138, 207, 70, "Denominazione" , AN); add_field(trc, 208, 247, 40, "ComuneSedeLegale" , AN); add_field(trc, 248, 249, 2, "ProvinciaSedeLegale" , AN); add_field(trc, 250, 253, 4, "AnnoRiferimento" , NU, true); add_field(trc, 254, 269, 16, "CodiceFiscaleFornitore" , AN); add_field(trc, 270, 286, 17, "ProtocolloTelematico" , AN); } else if (trc == 1 || trc == 2) // 1=Clienti 2=Fornitori { for (int i = 1; i <= 8; i++) { add_multi(trc, 2, 17, 16, "CodiceFiscale" , i, AN, false); // true dal 2007 add_multi(trc, 18, 28, 11, "PartitaIVA" , i, AN, true); add_multi(trc, 29, 29, 1, "SegnoImponibili" , i, AN, true, "+"); add_multi(trc, 30, 41, 12, "Imponibili" , i, NU, false); add_multi(trc, 42, 42, 1, "SegnoImpostaAfferente" , i, AN, true, "+"); add_multi(trc, 43, 54, 12, "ImpostaAfferente" , i, NU, false); add_multi(trc, 55, 55, 1, "SegnoNonImponibili" , i, AN, true, "+"); add_multi(trc, 56, 67, 12, "NonImponibili" , i, NU, false); add_multi(trc, 68, 68, 1, "SegnoEsenti" , i, AN, true, "+"); add_multi(trc, 69, 80, 12, "Esenti" , i, NU, false); add_multi(trc, 81, 81, 1, "SegnoIVANonEsposta" , i, AN, true, "+"); add_multi(trc, 82, 93, 12, "IVANonEsposta" , i, NU, false); add_multi(trc, 94, 94, 1, "SegnoImponibiliP" , i, AN, true, "+"); add_multi(trc, 95,106, 12, "ImponibiliP" , i, NU, false); add_multi(trc,107,107, 1, "SegnoImpostaAfferenteP", i, AN, true, "+"); add_multi(trc,108,119, 12, "ImpostaAfferenteP" , i, NU, false); add_multi(trc,120,120, 1, "SegnoNonImponibiliP" , i, AN, true, "+"); add_multi(trc,121,132, 12, "NonImponibiliP" , i, NU, false); add_multi(trc,133,133, 1, "SegnoEsentiP" , i, AN, true, "+"); add_multi(trc,134,145, 12, "EsentiP" , i, NU, false); add_multi(trc,146,146, 1, "SegnoIVANonEspostaP" , i, AN, true, "+"); add_multi(trc,147,158, 12, "IVANonEspostaP" , i, NU, false); add_multi(trc,201,201, 1, "TerminazioneElemento" , i, AN, true, "*"); } } add_field(trc,1798,1798, 1, "CarattereControllo" , AN, true, "A"); add_field(trc,1799,1800, 2, "FineRiga" , AN, true, "\n\r"); } TPadoaSchioppa_set::TPadoaSchioppa_set() : TAS400_recordset("AS400(1800,1)") { add_trc(0); add_trc(1); add_trc(2); add_trc(9); } bool TPadoaSchioppa_set::set(const char* name, const TVariant& value, int idx) { bool ok = false; if (idx > 0) { TString80 field = name; field << '(' << idx << ')'; // Gestisco solo qui gli importi in quanto non esistono importi con indice == 0 if (value.is_real()) { // Gestiamo solo fino a 2 miliardi di Euro! const long val = value.as_real().integer(); ok = TAS400_recordset::set(field, TVariant(labs(val))); if (ok && val < 0) { field.insert("Segno", field.find('(')); ok = TAS400_recordset::set(field, TVariant("-")); } } else ok = TAS400_recordset::set(field, value); CHECKS(ok, "Campo non valido ", (const char*)field); } else { // Gestisco solo qui le date in quanto non esistono date con indice != 0 if (value.is_date() && !value.is_empty()) { const TDate date = value.as_date(); TString8 str; str.format("%02d%02d%04d", date.day(), date.month(), date.year()); ok = TAS400_recordset::set(name, TVariant(str)); } else ok = TAS400_recordset::set(name, value); CHECKS(ok, "Campo non valido ", name); } return ok; } bool TPadoaSchioppa_set::set(const char* name, const TString& value, int idx) { return set(name, value.full() ? TVariant(value) : NULL_VARIANT, idx); } bool TPadoaSchioppa_set::set(const char* name, const TDate& value, int idx) { return set(name, value.ok() ? TVariant(value) : NULL_VARIANT, idx); } /////////////////////////////////////////////////////////// // TRegistri_cache /////////////////////////////////////////////////////////// class TRegistri_cache : public TCache { protected: virtual TObject* key2obj(const char* key); public: const TRegistro& registro(const char* codice, int anno); }; // key = AAAA|REG TObject* TRegistri_cache::key2obj(const char* key) { const int anno = atoi(key); const char* reg = key+5; return new TRegistro(reg, anno); } const TRegistro& TRegistri_cache::registro(const char* codice, int anno) { TString8 key; key.format("%04d|%s", anno, codice); return *(TRegistro*)objptr(key); } /////////////////////////////////////////////////////////// // TCodiva_cache /////////////////////////////////////////////////////////// class TCodiva_cache : public TCache { protected: virtual TObject* key2obj(const char* key); public: const TCodiceIVA& codiva(const char* codice); }; TObject* TCodiva_cache::key2obj(const char* key) { return new TCodiceIVA(key); } const TCodiceIVA& TCodiva_cache::codiva(const char* codice) { return *(TCodiceIVA*)objptr(codice); } /////////////////////////////////////////////////////////// // TAlleg_report /////////////////////////////////////////////////////////// class TAlleg_report : public TReport { int _anno; protected: virtual bool use_mask() { return false; } virtual bool get_usr_val(const TString& name, TVariant& var) const; public: TAlleg_report(TRecordset* rs, int anno); }; bool TAlleg_report::get_usr_val(const TString& name, TVariant& var) const { if (name == "ANNO") { var.set(_anno); return true; } if (name == "PREC") { var.set(_anno-1); return true; } return TReport::get_usr_val(name, var); } TAlleg_report::TAlleg_report(TRecordset* rs, int anno) : _anno(anno) { load("cg3900a"); set_recordset(rs); } /////////////////////////////////////////////////////////// // TAlleg_mask /////////////////////////////////////////////////////////// class TAlleg_mask : public TAutomask { TRegistri_cache _registri; TCodiva_cache _codiva; protected: bool documento_corrispettivi(const TString& tipodoc) const; void scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi, bool strict); TRecordset* new_recordset(char tipocf = ' ', bool strict = false); void add_0_9(int trc, TPadoaSchioppa_set& pss, TLog_report& log) const; void add_1_2(int trc, TRecordset& clifo, TPadoaSchioppa_set& pss, TLog_report& log) const; void generazione(); public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); TAlleg_mask(); }; bool TAlleg_mask::documento_corrispettivi(const TString& tipodoc) const { const TRectype& tpd = cache().get("%TPD", tipodoc); bool corrisp = tpd.get_bool ("B0"); if (corrisp) { const int natura_doc = tpd.get_int("I0"); corrisp = natura_doc == 1 || natura_doc == 9; } return corrisp; } void TAlleg_mask::scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi, bool strict) { TToken_string clifo_key; clifo_key << mov.get(MOV_TIPO) << '|' << mov.get(MOV_CODCF); const TRectype& clifo = cache().get(LF_CLIFO, clifo_key); if (strict) { const TString& stato = clifo.get(CLI_STATOPAIV); if (stato.full() && stato != "IT") // Scarto gli esteri return; } const char tipocf = clifo_key[0]; const int tipalleg = clifo.get_int(CLI_ALLEG); const long codalleg = clifo.get_long(CLI_CODALLEG); // Se sto generando un file ministeriale ignoro da subito chi non va in allegato if (strict && !(tipalleg == 0 || (tipalleg == 4 && codalleg > 0))) return; if (tipalleg == 4 && codalleg > 0) // Se il cliente ha un diverso codice per allegato ... clifo_key.add(codalleg, 1); // ... aggiorno codice clifo in allegato TAllegato_info* ai = (TAllegato_info*)clifi.objptr(clifo_key); if (ai == NULL) { ai = new TAllegato_info(clifo); clifi.add(clifo_key, ai); } const TString& codcaus = mov.get(MOV_CODCAUS).as_string(); const TRectype& caus = cache().get(LF_CAUSALI, codcaus); const bool movintra = caus.get_bool(CAU_INTRACOM); const int reg_spec = caus.get_int(CAU_REGSPIVA); const bool reverse_charge = (reg_spec == 13) || (reg_spec == 50) || (reg_spec == 51); const TDate datareg = mov.get(MOV_DATAREG).as_date(); const TDate datadoc = mov.get(MOV_DATADOC).as_date(); TAllegato_importi& allimp = ai->importi(datadoc.year() < datareg.year()); TISAM_recordset righe_iva("USE RMOVIVA\nFROM NUMREG=#NR\nTO NUMREG=#NR"); righe_iva.set_var("#NR", mov.get(MOV_NUMREG)); for (bool ok = righe_iva.move_first(); ok; ok = righe_iva.move_next()) { const TString& codice = righe_iva.get(RMI_CODIVA).as_string(); const TCodiceIVA& codiva = _codiva.codiva(codice); const int allegato = codiva.allegato(tipocf); const real imponibile = righe_iva.get(RMI_IMPONIBILE).as_real(); const real imposta = righe_iva.get(RMI_IMPOSTA).as_real(); switch (allegato) { case 1: allimp._imp += imponibile; if (movintra || reverse_charge) // IVA non esposta in fattura allimp._ivaNE += imposta; else allimp._iva += imposta; break; case 2: allimp._impNI += imponibile; break; case 3: allimp._impES += imponibile; break; default: allimp._impNA += imponibile; break; } } } TRecordset* TAlleg_mask::new_recordset(char tipocf, bool strict) { // Compito: tradurre in ISAM la seguente query: // SELECT * FROM MOV // WHERE TIPO=#TYPE AND ANNOIVA=#YEAR // ORDER BY TIPO,CODCF; TString query = "USE MOV KEY 3"; // La chiave 3 e' TIPO+CODCF+DATAREG+NUMREG query << "\nSELECT ANNOIVA=#YEAR"; // Seleziona solo l'anno desiderato query << "\nFROM TIPO=#TYPE CODCF=1"; // Salta tutti movimenti senza CODCF query << "\nTO TIPO=#TYPE"; // Inutile dire CODCF=999999 TISAM_recordset mov(query); TAssoc_array clifi; if (tipocf <= ' ') tipocf = get(F_TIPO)[0]; const char tipo[2] = { tipocf, '\0' }; const int anno = get_int(F_ANNO); mov.set_var("#YEAR", TVariant(long(anno))); mov.set_var("#TYPE", TVariant(tipo)); TString msg; msg << TR("Scansione movimenti") << ' ' << (tipocf == 'C' ? TR("Clienti") : TR("Fornitori")); msg << " (" << mov.items() << ")"; TProgind pi(mov.items(), msg, true, true); for (bool ok = mov.move_first(); ok; ok = mov.move_next()) { if (!pi.addstatus(1)) break; // Controllo se registro e' compatibile const TString& codreg = mov.get(MOV_REG).as_string(); const TRegistro& reg = _registri.registro(codreg, anno); if (reg.corrispettivi()) continue; const TString& codcaus = mov.get(MOV_CODCAUS).as_string(); const TRectype& caus = cache().get(LF_CAUSALI, codcaus); if (caus.get_bool(CAU_ALLEG)) // Controllo il flag di esclusione dagli allegati continue; // Controllo inutilmente anche il tipo documento const TString& tipodoc = caus.get(CAU_TIPODOC); if (documento_corrispettivi(tipodoc)) continue; // Scarta trasferimento movimenti intra if (strict && caus.get_bool(CAU_INTRACOM)) continue; const TipoIVA tipoiva = reg.iva(); bool keep = tipoiva == iva_vendite || tipoiva == iva_acquisti; // Voglio solo registri IVA if (keep) keep = (tipocf == 'C') ^ (tipoiva == iva_acquisti); // compatibile if (!keep) continue; const TVariant& occas = mov.get(MOV_OCFPI); if (!occas.is_empty()) // Ignoro i clienti occasionali continue; scan_iva_rows(mov, clifi, strict); } TAllegati_set* hullygully = new TAllegati_set; FOR_EACH_ASSOC_OBJECT(clifi, h, k, o) { const TAllegato_info& ai = *(TAllegato_info*)o; if (ai.is_not_null()) hullygully->add(ai); } hullygully->sort(); return hullygully; } void TAlleg_mask::add_0_9(int trc, TPadoaSchioppa_set& pss, TLog_report& log) const { pss.new_rec(trc == 0 ? "0" : "9"); const char tipoa = prefix().firm().get(NDT_TIPOA)[0]; const long codanagr = prefix().firm().get_long(NDT_CODANAGR); TToken_string key; key.add(tipoa, 0); key.add(codanagr, 1); const TRectype& anag = cache().get(LF_ANAG, key); TString16 pariva = anag.get(ANA_PAIV); pariva.right_just(11, '0'); if (!pi_check("", pariva)) { TString msg; msg << anag.get(CLI_RAGSOC) << ": " << TR("Partita IVA errata") << ' ' << pariva; log.log(2, msg); } const TString& codfis = anag.get(ANA_COFI); pss.set("CodiceFiscale", codfis.full() ? codfis : pariva); pss.set("PartitaIVA", pariva.full() ? pariva : codfis); if (tipoa == 'F') { pss.set("Cognome", anag.get(ANA_RAGSOC).left(30)); pss.set("Nome", anag.get(ANA_RAGSOC).mid(30)); const TRectype& anafis = cache().get(LF_ANAGFIS, codanagr); pss.set("Sesso", anafis.get(ANF_SESSO)); pss.set("DataNascita", anafis.get_date(ANF_DATANASC)); key.add(anafis.get(ANF_STATONASC), 0); key.add(anafis.get(ANF_COMNASC), 1); const TRectype& comnas = cache().get(LF_COMUNI, key); pss.set("ComuneNascita", comnas.get(COM_DENCOM)); pss.set("ProvinciaNascita", comnas.get(COM_PROVCOM)); } else { key.add(anag.get(ANA_STATORES), 0); key.add(anag.get(ANA_COMRES), 1); const TRectype& comres = cache().get(LF_COMUNI, key); pss.set("Denominazione", anag.get(ANA_RAGSOC)); pss.set("ComuneSedeLegale", comres.get(COM_DENCOM)); pss.set("ProvinciaSedeLegale", comres.get(COM_PROVCOM)); } pss.set("AnnoRiferimento", get(F_ANNO)); pss.set("CodiceFiscaleFornitore", codfis); } void TAlleg_mask::add_1_2(int trc, TRecordset& clifo, TPadoaSchioppa_set& pss, TLog_report& log) const { int idx = 0; // Indice del cliente all'interno del record [1,8] for (bool ok = clifo.move_first(); ok; ok = clifo.move_next()) { if (++idx > 8) // Incremento indice del cliente o fornitore, se debordo dal limite ... idx = 1; // ... allora ricomincio da 1 if (idx == 1) // Se sto per scrivere il primo elemento ... pss.new_rec(trc == 1 ? "1" : "2"); // ... creo un nuovo record per accogliere i prossimi 8 TString16 paiv = clifo.get(CLI_PAIV).as_string(); paiv.trim(); if (paiv.full()) paiv.right_just(11, '0'); TString16 cofi = clifo.get(CLI_COFI).as_string(); cofi.trim(); if (cofi.blank() && !real::is_null(paiv)) // Se il codice fiscale e' vuoto prendo la partita IVA { cofi = paiv; } else { // Se la partita IVA e' vuota ed il codice fiscale e' numerico ... if (paiv.blank() && pi_check("", cofi)) paiv = cofi; // ... allora copia nella partita IVA il codice fiscale if (!real::is_natural(cofi) && !cf_check("", cofi)) { TString msg = clifo.get(CLI_RAGSOC).as_string(); msg.trim(); msg << ": " << TR("Codice fiscale errato") << ' ' << cofi; log.log(1, msg); } } if (real::is_null(paiv) || !pi_check("", paiv)) { TString msg = clifo.get(CLI_RAGSOC).as_string(); msg.trim(); msg << ": " << TR("Partita IVA errata") << ' ' << paiv; log.log(2, msg); if (real::is_null(paiv)) paiv = "99999999999"; // Evita errore fatale } pss.set("CodiceFiscale", cofi, idx); pss.set("PartitaIVA", paiv, idx); pss.set("Imponibili", clifo.get("C_IMP"), idx); pss.set("ImpostaAfferente", clifo.get("C_IVA"), idx); pss.set("NonImponibili", clifo.get("C_NI"), idx); pss.set("Esenti", clifo.get("C_ES"), idx); pss.set("IVANonEsposta", clifo.get("C_NE"), idx); } } void TAlleg_mask::generazione() { TReport_book book; TLog_report log("Errori riscontrati"); TPadoaSchioppa_set pss; add_0_9(0, pss, log); TRecordset* cli = new_recordset('C', true); if (cli != NULL) { add_1_2(1, *cli, pss, log); TAlleg_report rep(cli, get_int(F_ANNO)); book.add(rep); } TRecordset* ven = new_recordset('F', true); if (ven != NULL) { add_1_2(2, *ven, pss, log); TAlleg_report rep(ven, get_int(F_ANNO)); book.add(rep); } add_0_9(9, pss, log); pss.save_as(get(F_NAME)); book.add(log); book.preview(); } bool TAlleg_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_SELECT: if (e == fe_button) { TRecordset* rs = new_recordset(); TRecordset_sheet sheet(*rs, TR("Elenco di controllo"), 0x8); while (sheet.run() == K_ENTER) { const long sel = sheet.selected(); TToken_string& row = sheet.row(sel); TRectype clifo(LF_CLIFO); clifo.put(CLI_TIPOCF, row.get(0)); clifo.put(CLI_CODCF, row.get(1)); clifo.edit(); } delete rs; return false; } break; case DLG_EDIT: if (e == fe_button) { TRecordset* rs = new_recordset(); TFilename fname = get(F_NAME); if (fname.blank()) { fname.tempdir(); fname.add("clifo"); } fname.ext("xls"); if (rs->save_as(fname, fmt_silk)) xvt_sys_goto_url(fname, "open"); delete rs; return false; } break; case DLG_PRINT: if (e == fe_button) { TRecordset* rs = new_recordset(); TAlleg_report rep(rs, get_int(F_ANNO)); TReport_book book; book.add(rep); book.print_or_preview(); return false; } break; case DLG_ELABORA: if (e == fe_button) { generazione(); return false; } break; default: break; } return true; } TAlleg_mask::TAlleg_mask() : TAutomask("cg3900a") { const TDate oggi(TODAY); set(F_ANNO, oggi.year()-1); TFilename fname; fname.tempdir(); fname.add("clifo"); set(F_NAME, fname); } /////////////////////////////////////////////////////////// // TClifo_alleg_app /////////////////////////////////////////////////////////// class TClifo_alleg_app : public TSkeleton_application { public: virtual void main_loop(); }; void TClifo_alleg_app::main_loop() { open_files(LF_ANAG, LF_ANAGFIS, LF_COMUNI, LF_TAB, 0); // Roba anagrafica open_files(LF_CAUSALI, LF_CLIFO, LF_MOV, LF_RMOVIVA, 0); // Roba contabile TAlleg_mask m; m.run(); } int cg3900(int argc, char* argv[]) { TClifo_alleg_app app; app.run(argc, argv, TR("Elenco clienti/fornitori in allegato")); return 0; }