From 72c4598e7799cd15cf2e393e0c7daaf5ed2719a1 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 4 Jan 2013 08:09:47 +0000 Subject: [PATCH] =?UTF-8?q?Aggiunta=20colonna=20commessa=20in=20visualizza?= =?UTF-8?q?zione=20mastrini.=20Tale=20campo=20ora=20viene=20determinato=20?= =?UTF-8?q?euristicamente=20dalla=20contabilit=C3=A0=20analitica,=20mentre?= =?UTF-8?q?=20nella=20versione=203.x=20era=20fisicamente=20nelle=20righe?= =?UTF-8?q?=20di=20prima=20nota.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://10.65.10.50/branches/R_10_00@22774 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2107.cpp | 26 ++++++--- cg/cg3600.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++----- cg/cg3600b.uml | 1 + cg/cg3900.cpp | 3 +- cg/cglib01.cpp | 9 ++++ cg/cgsaldac.cpp | 6 +++ cg/cgsaldac.h | 1 + 7 files changed, 161 insertions(+), 23 deletions(-) diff --git a/cg/cg2107.cpp b/cg/cg2107.cpp index 52e57d9e5..9465f303e 100755 --- a/cg/cg2107.cpp +++ b/cg/cg2107.cpp @@ -662,16 +662,22 @@ static int nrigp_pagamento_locale(const TSolder_tree& st) return 0; } +static bool is_lonely_nc(TPartita& game) +{ + int numrig[8]; memset(numrig, 0, sizeof(numrig)); + for (int i = game.last(); i > 0; i = game.pred(i)) + numrig[game.riga(i).tipo()]++; + return numrig[tm_fattura] == 0 && numrig[tm_nota_credito] > 0; +} + // Aggiunge una nota di credito non associata a fattura static bool add_lonely_nc(TPartita& game, TSheet_field& sheet, int rigasheet) { - const int nrigp = game.first(); - if (nrigp <= 0) + if (!is_lonely_nc(game)) return false; + const int nrigp = game.prima_riga(-1, tm_nota_credito); const TRiga_partite& riga = game.riga(nrigp); - if (riga.tipo() != tm_nota_credito) - return false; TToken_string& row = sheet.row(rigasheet); row.add(game.codice_valuta(), sheet.cid2index(S_VALUTA)); @@ -831,7 +837,7 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word /* flags */) } if (good_pag) { - if (!good_rat && nrigp > 1 && game.prima_riga(-1, tm_nota_credito) < nrigp) + if (!good_rat && nrigp > 1 && is_lonely_nc(game)) add_lonely_nc(game, sheet, sheet.items()-1); const TRiga_partite& rigp = game.riga(nrigp); @@ -877,9 +883,13 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word /* flags */) } else { - // Nota di credito non assegnata e senza pagamenti successivi - if (level == 4 && nriga == TPartita::UNASSIGNED && game.last() == game.first()) - add_lonely_nc(game, sheet, -1); + // Nota di credito non assegnata e senza pagamenti n questo movimento + if (level == 4 && nriga == TPartita::UNASSIGNED && nrigp == 0 && curr.ends_with("|1") && is_lonely_nc(game)) + { + const TImporto sld = game.calcola_saldo(true); + if (!sld.is_zero()) + add_lonely_nc(game, sheet, -1); + } } return false; } diff --git a/cg/cg3600.cpp b/cg/cg3600.cpp index cdb000a94..217019b22 100755 --- a/cg/cg3600.cpp +++ b/cg/cg3600.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,9 @@ #include #include +#include "../ca/movana.h" +#include "../ca/rmovana.h" + class TGrid_mask; class TQuery_mask : public TAutomask @@ -60,8 +64,6 @@ HIDDEN inline TMastrini_video& app() // TList /////////////////////////////////////////////////////////// -// Simpler and faster 32 bit implemetation - class TList : public TContainer { TArray _data; @@ -595,7 +597,6 @@ bool TMastrino::collapse(long rec) class TGrid_control; - class TGrid_cell : public TFixed_string { XI_EVENT* _xiev; @@ -658,7 +659,7 @@ public: class TGrid_control : public TControl { - enum grid_control_constants { MAX_COL = 128 }; + enum grid_control_constants { MAX_COL = 64 }; long _cur_rec; bool _read_only; @@ -702,9 +703,10 @@ public: bool select(long n); int visible_rows() const; - + XI_OBJ* find_column(short cid) const; byte& column_type(int c) { CHECKD(c >= 0 && c < MAX_COL, "Bad column ", c); return _type[c]; } + void show_column(short cid, bool on); void update(long n = -1); bool is_visible(long rec) const; @@ -898,7 +900,7 @@ TGrid_control::TGrid_control( CHECKD(_obj, "Can't create list control ", cid); update_tab_cid(); - int num; + int num = 0; XI_OBJ** column = xi_get_member_list(_obj, &num); for (i = 0; i < num; i++) { @@ -950,10 +952,10 @@ int TGrid_control::visible_rows() const bool TGrid_control::is_visible(long rec) const { - int first, last; + int first = 0, last = 0; xi_get_visible_rows(_obj, &first, &last); - int rows; + int rows = 0; const long* handle = xi_get_list_info(_obj, &rows); bool yes = rec >= handle[first] && rec <= handle[last]; @@ -1283,7 +1285,7 @@ bool TGrid_control::event_handler(XI_OBJ* itf, XI_EVENT *xiev) XI_OBJ* TGrid_control::find_column(short cid) const { - int num; + int num = 0; XI_OBJ** column = xi_get_member_list(_obj, &num); int i; for (i = num-1; i >= 0; i--) @@ -1296,7 +1298,7 @@ XI_OBJ* TGrid_control::find_column(short cid) const XI_OBJ* TGrid_control::find_column(const char* head) const { - int num; + int num = 0; XI_OBJ** column = xi_get_member_list(_obj, &num); TString80 text; @@ -1310,6 +1312,23 @@ XI_OBJ* TGrid_control::find_column(const char* head) const return i >= 0 ? column[i] : NULL; } +void TGrid_control::show_column(short cid, bool on) +{ + XI_OBJ* column = find_column(cid); + if (column) + { +/* Useless + dword attr = xi_get_attrib(column); + if (on) attr |= XI_ATR_VISIBLE; + else attr &= ~XI_ATR_VISIBLE; + xi_set_attrib(column, attr); // Set new attributes + update(-1); +*/ + if (!on) + xi_delete(column); + } +} + void TGrid_control::set_columns_order(TToken_string* order) { XI_OBJ* itf = get_interface(); @@ -1658,7 +1677,7 @@ void TMastrini_grid::destroy() HIDDEN const char* real2string(const real& r) { - TCurrency cur(r); + const TCurrency cur(r); return cur.string(true); } @@ -1681,7 +1700,7 @@ void TMastrini_grid::cell_request(long rec, short id, TGrid_cell& cell) XI_OBJ* col = grid().find_column(short(1000+id%1000)); if (col != NULL) { - TString head; + TString80 head; xi_get_text(col, head.get_buffer(), head.size()); cell = head; @@ -1821,6 +1840,93 @@ void TMastrini_grid::cell_request(long rec, short id, TGrid_cell& cell) } } break; + case 110: + if (riga.tipo() == riga_mastrino) + { + const TRectype& mov = _mastrino.testata(rec); + TLocalisamfile movana(LF_MOVANA); + movana.setkey(3); + movana.put(MOVANA_NUMREGCG, mov.get(MOV_NUMREG)); + if (movana.read() == NOERR) + { + const TRectype& rmov = _mastrino.riga(rec); + const TBill bill(rmov); + const TString16 codconto = bill.string(0x8); // GGGCCCSSSSSS + const TRecord_array rmovana(movana.get(MOVANA_NUMREG), LF_RMOVANA); + const int last_rmovana = rmovana.last_row(); + const real target = rmov.get(RMV_IMPORTO); + + TBit_array hits; + + if (hits.first_one() < 0) + { + // Controllo se c'è corrispondenza biunivoca tra le righe di CG e CA + const int nriga = rmov.get_int(RMV_NUMRIG); + if (nriga <= last_rmovana && rmovana.exist(nriga)) + { + const TRectype& r = rmovana.row(nriga); + if (r.get(RMOVANA_CODCONTO) == codconto && r.get_real(RMOVANA_IMPORTO) == target) + hits.set(nriga); + } + } + + if (hits.first_one() < 0) + { + // Controllo se esiste una riga che corrisponda per importo e conto analitico/contabile + for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) + { + const TRectype& r = rmovana.row(i); + if (r.get(RMOVANA_CODCONTO) == codconto) + { + const real imp = r.get(RMOVANA_IMPORTO); + if (imp == target) + { + hits.set(i); + break; + } + } + } + } + + if (hits.first_one() < 0) + { + // Faccio la somma delle righe che corrispondono per conto analitico/contabile + real total_hits; + for (int i = rmovana.first_row(); i > 0 && i <= last_rmovana; i = rmovana.succ_row(i)) + { + const TRectype& r = rmovana.row(i); + if (r.get(RMOVANA_CODCONTO) == codconto) + { + const real imp = r.get(RMOVANA_IMPORTO); + hits.set(i); + total_hits += imp; + if (total_hits >= target) + break; + } + } + } + + TString80 cms; + for (int h = hits.first_one(); h >= 0 && h <= last_rmovana; h++) if (hits[h]) + { + const TRectype& r = rmovana.row(h); + TString80 cod = r.get(RMOVANA_CODCMS); + if (cod.starts_with("00000")) + { + int i = 0; + for (i = 5; cod[i] == '0'; i++); + cod.ltrim(i); + } + if (cms.not_empty()) + cms << ' '; + cms << cod; + } + if (cms.len() >= cell.size()) + cms.cut(cell.size()-1); + cell = cms; + } + } + break; default: break; } @@ -2188,6 +2294,10 @@ TGrid_mask::TGrid_mask() set_handler(DLG_NEWREC, new_handler); set_handler(DLG_EDIT, edit_handler); set_handler(DLG_EXPORT, export_handler); + + const bool show_cms = main_app().has_module(CMAUT) || main_app().has_module(CAAUT); + if (!show_cms) + _grid->grid().show_column(1110, false); // Nasconde la commessa } TMask_field* TGrid_mask::parse_field(TScanner& sc) @@ -2525,7 +2635,9 @@ void TQuery_mask::do_query() bool TMastrini_video::create() { xvtil_statbar_set("", TRUE); - open_files(LF_RMOV, LF_MOV, LF_CAUSALI, LF_SALDI, LF_PCON, 0); + open_files(LF_CAUSALI, LF_MOV, LF_PCON, LF_RMOV, LF_SALDI, 0); + if (has_module(CMAUT)) + open_files(LF_MOVANA, LF_RMOVANA, 0); _gm = new TGrid_mask; _qm = new TQuery_mask(_gm); diff --git a/cg/cg3600b.uml b/cg/cg3600b.uml index 258036d69..e6f6ec9b4 100755 --- a/cg/cg3600b.uml +++ b/cg/cg3600b.uml @@ -90,6 +90,7 @@ BEGIN ITEM "N.Doc. \nN.Prot.@7" ITEM "Importo@17R" ITEM "Saldo Fine\nGiornata@17R" + ITEM "Commessa@20" END TEXT DLG_NULL diff --git a/cg/cg3900.cpp b/cg/cg3900.cpp index 56686cc72..b4c0a2fe2 100755 --- a/cg/cg3900.cpp +++ b/cg/cg3900.cpp @@ -724,7 +724,7 @@ protected: // Elaborazione const TRectype& contribuente() const; bool documento_corrispettivi(const TString& tipodoc) const; int imp_iva(char tipocf, bool non_esposti, const TRecordset& riga, real& imp, real& iva); - real indetraibile_al(const TRecordset& riga, bool prorata100) const; + real indetraibile_al(const TRecordset& riga) const; bool scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi, bool invio, bool ministeriale); TRecordset* new_recordset(char tipocf = ' ', bool strict = false); @@ -856,7 +856,6 @@ bool TAlleg_mask::scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi, const int reg_spec = caus.regime_speciale(); const bool reverse_charge = (reg_spec == 13) || (reg_spec == 50) || (reg_spec == 51); const bool non_esposti = vendite && (movintra || reverse_charge); - const bool prorata100 = caus.reg().prorata100(annoiva); TISAM_recordset righe_iva("USE RMOVIVA\nFROM NUMREG=#NR\nTO NUMREG=#NR"); righe_iva.set_var("#NR", mov.get(MOV_NUMREG)); diff --git a/cg/cglib01.cpp b/cg/cglib01.cpp index f05185863..ff40309e5 100755 --- a/cg/cglib01.cpp +++ b/cg/cglib01.cpp @@ -363,7 +363,16 @@ const TString& cap2comune(const TString& cap, const TString& denom) if (codone.full()) return get_tmp_string() = codone; + } else + if (cap.blank() && denom.full()) + { + TLocalisamfile comuni(LF_COMUNI); + comuni.setkey(2); + comuni.put(COM_DENCOM, denom); + if (comuni.read() == NOERR) + return comuni.get(COM_COM); } + return EMPTY_STRING; } diff --git a/cg/cgsaldac.cpp b/cg/cgsaldac.cpp index 3d3f94d5e..95e05e81d 100755 --- a/cg/cgsaldac.cpp +++ b/cg/cgsaldac.cpp @@ -238,6 +238,12 @@ void TValuta::eur2val(TImporto& imp) const eur2val(imp.valore()); } +int TValuta::decimals() const +{ + const TExchange ex(_cod, _cam); + return ex.decimals(); +} + /////////////////////////////////////////////////////////// // TRiga_scadenze /////////////////////////////////////////////////////////// diff --git a/cg/cgsaldac.h b/cg/cgsaldac.h index 9c35a7796..5e8f95c94 100755 --- a/cg/cgsaldac.h +++ b/cg/cgsaldac.h @@ -100,6 +100,7 @@ public: void get(const TMask& m, short v, short d, short c); const TValuta& operator =(const TValuta& v) { set(v); return *this; } + int decimals() const; TValuta(); TValuta(const char* cod, const TDate& dat, const real& cam);