#include #include #include #include #include #include #include #include "ci0.h" #include "cilib.h" #include "ci0400.h" #include "ci0400a.h" #include "ci0400b.h" #include "..\ve\velib04.h" #include /////////////////////////////////////////////////////////// // TImmissioneDocumenti_app /////////////////////////////////////////////////////////// // Inizializzazioni void TImmissioneDocumenti_app::init_tabs() { TImmissioneDocumenti_mask & m = mask(); m.filters().destroy(); m.ordered().reset(); TConfig configfile(CONFIG_DITTA, "ci"); int items = 0; TToken_string pagenames; while (items == 0 || configfile.exist("Descr",items)) { pagenames.add(configfile.get("Descr", NULL, items, "Fatture")); m.filters().add(configfile.get("Filter", NULL, items, "F01")); m.insert().set(items, configfile.get_bool("InsertRemain", NULL, items)); m.modify().set(items, configfile.get_bool("ModifyRemain", NULL, items)); m.doc_coll().set(items, configfile.get_bool("DocColl", NULL, items)); m.num_coll().add(configfile.get("NumColl", NULL, items), items); m.tipo_coll().add(configfile.get("TipoColl", NULL, items), items); m.stato_coll().add(configfile.get("StatoColl", NULL, items), items); m.var_coll().add(configfile.get("Var", NULL, items), items); m.mod_coll().set(items, configfile.get_bool("ModColl", NULL, items)); m.del_closed().set(items, configfile.get_bool("DeleteClosed", NULL, items)); m.activate_almanac(F_AL01 + items, items, TDate(TODAY)); items++; } m.disable_page(items); m.set_caption(pagenames); } void TImmissioneDocumenti_app::init_flags() { TImmissioneDocumenti_mask & m = mask(); const int items = m.filters().items(); TDate currdate; TDate currstart; m.ordered().reset(); for(int i = 0; i < items; i++) { TString filter; filter << "(ANNO==\"" << _year << "\")" << "&&" << "(CODNUM==\"" << m.filters().row(i) << "\")"; TRelation relation(LF_DOC); TSorted_cursor cursor(&relation, "DATADOC", filter); TCodice_numerazione c(m.filters().row(i)); if (!c.dont_test_datadoc()) m.ordered().set(i); const int items = cursor.items(); if (m.flags().items()>i) ((TBit_array&) m.flags()[i]).reset(); else m.flags().add(new TBit_array(366),i); TBit_array & fl = (TBit_array&) m.flags()[i]; TDate caput_anni(1, 1, _year); for (cursor = 0; cursor.pos() < items; ++cursor) { const TDate datadoc = relation.lfile().get_date(DOC_DATADOC); if (datadoc.year() == caput_anni.year()) fl.set(datadoc - caput_anni, 1); } caput_anni += fl.last_one(); m.almanac(i).set_insert_date(m.ordered()[i] ? caput_anni : botime); } } // Overrides bool TImmissioneDocumenti_app::create() { open_files(LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, LF_DESLIN, LF_CODCORR, LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_INDSP, LF_OCCAS, LF_PCON, LF_MOV, LF_STOMAG, LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0); _mask = new TImmissioneDocumenti_mask(); init_tabs(); init_flags(); return TSkeleton_application::create(); } bool TImmissioneDocumenti_app::destroy() { delete _mask; return TSkeleton_application::destroy(); } void TImmissioneDocumenti_app::main_loop() { while (_mask->run() != K_QUIT); } // Chiamate dalla maschera void TImmissioneDocumenti_app::change_year(int newyear, bool init_flg) { _year = newyear; if (init_flg) init_flags(); } bool TImmissioneDocumenti_app::has_documents(int currpage, TDate& day) { const int year = day.year(); if (year != _year) change_year(year, true); const TDate caput_anni(1, 1, _year); return (((TBit_array&) _mask->flags()[currpage])[day - caput_anni]); } /////////////////////////////////////////////////////////// // TImmissioneDocumenti_mask /////////////////////////////////////////////////////////// // Routines Proprietarie void TImmissioneDocumenti_mask::next_page(int p) { TMask::next_page(p); const int k = (p < 1000) ? curr_page() : p-1000; enable(DLG_DELREC, del_closed()[k]); } void TImmissioneDocumenti_mask::open_day_mask(const TDate & date) { TDate d(date); if (!d.ok()) d = curr_almanac().selected_date(); const int currpage = curr_page(); const TString & codnum = filters().row(currpage); TString filter; filter << "(ANSI(DATADOC)==\"" << d.string(ANSI) << "\")" << "&&" << "(CODNUM==\"" << codnum << "\")"; TRelation relation(LF_DOC); relation.add(LF_CLIFO, "TIPOCF==TIPOCF|CODCF==CODCF"); TCursor cursor(&relation, filter); if (!almanac().can_insert(d) && is_date_void(currpage, d)) return; TCursor_sheet sheet(&cursor, "ANNO|CODNUM|TIPODOC|NUMDOCRIF|STATO|DATADOCRIF|NDOC|20->RAGSOC", TR("Selezione documenti"), HR("Anno|Num.|Tipo|Docum.Rif.|Stato|Data@10|Documento|Ragione Sociale@50"), almanac().can_insert(date) ? 0x02|0x04 : 0x04, 3); TList_field& fl = sheet.add_list(101, 0, "Tipo documento ", 1, 1, 60); TToken_string codes; TToken_string values; TCodice_numerazione c(codnum); const int items = c.ntipi_doc(); for (int i = 0; i < items; i++) { const TString16 codtipo(c.tipo_doc(i)); const TTipo_documento t(codtipo); codes.add(codtipo); TString80 str; str << codtipo << " - " << t.descrizione(); values.add(str); } fl.replace_items(codes, values); fl.enable(items > 1); KEY exitval; while ((exitval = sheet.run()) != K_ESC) { switch(exitval) { case K_ENTER: call_ve0(exitval, relation, date, codnum, EMPTY_STRING, currpage); break; case K_DEL: call_ve0(exitval, relation, date, codnum); break; case K_INS: { const TString16 tipo(sheet.get(101)); call_ve0(exitval, relation, date, codnum, tipo, currpage); } break; default: break; } } update_current_calendar(date.year()); } void TImmissioneDocumenti_mask::update_current_calendar(int year) { TDate caput_anni(1, 1, year); const int currpage = curr_page(); TBit_array & dayfl = (TBit_array&) flags()[currpage]; TString filter; dayfl.reset(); filter.cut(0); filter << "(ANNO==\"" << year << "\")" << "&&" << "(CODNUM==\"" << filters().row(currpage) << "\")"; TRelation relation(LF_DOC); TCursor cursor(&relation, filter); cursor.setfilter(filter); const int doc_items = cursor.items(); for (cursor = 0; cursor.pos() < doc_items; ++cursor) { const TDate datadoc = relation.lfile().get_date(DOC_DATADOC); if (datadoc.year() == year) dayfl.set(datadoc - caput_anni, 1); } if (ordered()[currpage]) { caput_anni += dayfl.last_one(); almanac(currpage).set_insert_date(caput_anni); } almanac().force_update(); } void TImmissioneDocumenti_mask::call_ve0(int exitval, TRelation& relation, const TDate& date, const TString& codnum, const TString& doctype, byte currpage) { TFilename tempfile; tempfile.temp("", "ini"); { TConfig configfile(tempfile); switch(exitval) { case K_ENTER: configfile.set("Action", "Modify", "Transaction"); if (modify()[currpage]) configfile.set("Mode", "R", "Transaction"); configfile.set("NDOC", relation.lfile().get(DOC_NDOC), "33"); break; case K_DEL: configfile.set("Action", "Delete", "Transaction"); configfile.set("NDOC", relation.lfile().get(DOC_NDOC), "33"); break; case K_INS: configfile.set("Action", "Insert", "Transaction"); if (insert()[currpage]) configfile.set("Mode", "R", "Transaction"); configfile.set("DATADOC", date.string(), "33"); break; default: break; } configfile.set(DOC_PROVV, "D", "33"); configfile.set(DOC_ANNO, date.year(), "33"); configfile.set(DOC_CODNUM, codnum, "33"); configfile.set(DOC_TIPODOC, doctype, "33"); } TString commandline; commandline.format("ve0 -0 /i%s",(const char*)tempfile); TExternal_app ve(commandline); ve.run(); if (doc_coll()[currpage]) { TDocumento doc; TLocalisamfile documenti(LF_DOC); long recno; long ndoc_coll = 0L; bool new_doc = false; { TConfig configfile(tempfile); recno = configfile.get_long("Record", "Transaction"); if (recno > 0L) { doc.head().readat(documenti, recno); doc.read(); const TString16 num_coll(num_coll().row(currpage)); const TString16 tipo_coll(tipo_coll().row(currpage)); const TString16 stato_coll(stato_coll().row(currpage)); const long ndoc = doc.get_long(DOC_NDOC); TLocalisamfile rdoc(LF_RIGHEDOC); rdoc.setkey(4); rdoc.put(RDOC_DAPROVV, "D"); rdoc.put(RDOC_DAANNO, date.year()); rdoc.put(RDOC_DACODNUM, codnum); rdoc.put(RDOC_DANDOC, ndoc); new_doc = rdoc.read(_isgteq) != NOERR; if (!new_doc) { bool new_doc = (rdoc.get(RDOC_DAPROVV) != "D"); new_doc |= (rdoc.get_int(RDOC_DAANNO) != date.year()); new_doc |= (rdoc.get(RDOC_DACODNUM) != codnum); new_doc |= (rdoc.get_long(RDOC_DANDOC) != ndoc); if (!new_doc) ndoc_coll = rdoc.get_long(RDOC_NDOC); } configfile.set(DOC_CODNUM, num_coll, "33"); configfile.set(DOC_TIPODOC, tipo_coll, "33"); if (exitval == K_DEL) configfile.set("Action", "Delete", "Transaction"); else { TDocumento doc_coll('D', date.year(), num_coll, ndoc_coll); configfile.set("Action", "Modify", "Transaction"); configfile.set("Mode", "", "Transaction"); configfile.set_paragraph("33"); configfile.remove("STATO"); // creato dalla transazione precedente ??? if (new_doc) { TToken_string var(var_coll().row(currpage), ' '); doc_coll.copy_contents(doc); for (const char * field = var.get(0); field && *field; field = var.get()) doc_coll.zero(field); doc_coll.put(DOC_STATO, stato_coll); doc_coll.write(); ndoc_coll = doc_coll.get_long(DOC_NDOC); } else { TString_array vals; TToken_string var(var_coll().row(currpage), ' '); const char * field; var.add(DOC_STATO); for (field = var.get(0); field && *field; field = var.get()) vals.add(doc_coll.get(field)); doc_coll.copy_contents(doc); int i = 0; for (field = var.get(0); field && *field; field = var.get()) doc_coll.put(field, vals.row(i++)); doc_coll.rewrite(); if (!mod_coll()[currpage]) ndoc_coll = 0L; } } configfile.set(DOC_NDOC, ndoc_coll, "33"); } } if (ndoc_coll > 0L) ve.run(); } remove_file(tempfile); } // Richiami all'applicazione void TImmissioneDocumenti_mask::change_year(int newyear) { immissione_documenti_app().change_year(newyear); } bool TImmissioneDocumenti_mask::is_date_void(int currpage, TDate& cdate) { return !(immissione_documenti_app().has_documents(currpage, cdate)); } bool delete_closed(const TRelation& rel, void* pJolly) { TDocumento & doc = (TDocumento &) rel.lfile().curr(); const int rows = doc.physical_rows(); bool closed = true; TBit_array rows2delete; for (int i = 1; i <= rows; i++) { const char t = doc[i].tipo().tipo(); if (t == RIGA_SCONTI || t == RIGA_OMAGGI || t == RIGA_DESCRIZIONI) continue; const TString & codcms = doc[i].codice_commessa(); const TRectype & cms = cache().get(LF_COMMESSE, codcms); const bool closed_row = cms.get_bool("CHIUSA"); rows2delete.set(i, closed_row); closed &= closed_row; } if (closed) { doc.stato('9'); doc.remove(); } else if (rows2delete.first_one() >= 0) { for (int i = rows; i >= 1 ; i--) { if (rows2delete[i]) doc.destroy_row(i, true); } doc.rewrite(); } return true; } bool TImmissioneDocumenti_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_DELREC: if (e == fe_button) { TString descr; TMask selection("ci0400b"); const int pos = id2pos(31000 + 100 * curr_page()); if (pos >= 0) descr = fld(pos).prompt(); if (selection.run() == K_ENTER && yesno_box("Attenzione !! vuoi cancellare i documenti %s\n delle commesse chiuse", (const char *) descr) && yesno_box("Attenzione !! vuoi veramente cancellare i documenti %s\n delle commesse chiuse", (const char *) descr)) { TRectype from(LF_DOC); const TDate fromdate = selection.get_date(F_DA_DATA); if (fromdate.ok()) from.put(DOC_DATADOC, fromdate); TRectype to(LF_DOC); const TDate todate = selection.get_date(F_A_DATA); if (todate.ok()) to.put(DOC_DATADOC, todate); TString filter; filter.format("CODNUM==\"%s\"", (const char *) filters().row(curr_page())); TCursor d(new TRelation(LF_DOC), filter, 3, &from, &to); d.relation()->lfile().set_curr(new TDocumento()); d.scan(delete_closed, NULL, "Cancellazione documenti commesse chiuse"); update_current_calendar(selected_day().year()); } } break; default: TAlmanac_mask::on_field_event(o, e, jolly); break; } return true; } /////////////////////////////////////////////////////////// // Main /////////////////////////////////////////////////////////// int ci0400(int argc, char* argv[]) { TImmissioneDocumenti_app a ; a.run(argc, argv, TR("Immissione Documenti")); return 0; }