diff --git a/fe/fe0100.cpp b/fe/fe0100.cpp index fdd8967ec..a9d5351d5 100755 --- a/fe/fe0100.cpp +++ b/fe/fe0100.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -1412,8 +1413,8 @@ void TDati_rilevanti_msk::enable_buttons() one_sent = recset.move_first(); } - if (id2pos(DLG_COPY) > 0) - enable(DLG_COPY, full_rows && get_long(F_CODCF) > 0 && primo_contratto().full()); + if (id2pos(DLG_COPY) > 0) // Solo 10.0 + enable(DLG_COPY, full_rows); enable(DLG_CANCEL, full_rows); enable(DLG_SAVEREC, _sheet_dirty); enable(DLG_EXPORT, full_rows); @@ -1544,31 +1545,83 @@ bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, lon case DLG_COPY: if (e == fe_button) { - TString80 contratto1 = primo_contratto(); + TSheet_field& s = sfield(F_RIGHE); + const int sel = s.selected(); + const char tipocf1 = *s.cell(sel, A_TIPOCF); + const long codcf1 = atol(s.cell(sel, A_CODCF)); + int modpag1 = atoi(s.cell(sel, A_MODPAG)); + TString80 contratto1 = s.cell(sel, A_CONTRATTO); contratto1.trim(); - if (contratto1.not_empty() && - yesno_box("Si desidera inserire il contratto '%s' nelle righe che ne sono prive?", (const char*)contratto1)) + if (contratto1.empty()) { - const TContratto contr(get(F_TIPOCF)[0], get_long(F_CODCF), contratto1); - const int modpag = contr.modalita_pagamento(); - - TSheet_field& s = sfield(F_RIGHE); - const int f = s.cid2index(A_FORZATA); - const int c = s.cid2index(A_CONTRATTO); - const int n = s.cid2index(A_NUMRETT); - const int m = s.cid2index(A_MODPAG); - TString80 contratto; - TString16 numdoc; - FOR_EACH_SHEET_ROW(s, r, row) + TMask m("fe0100c"); + m.set(F_ANNO, get(F_ANNO)); + m.set(F_TIPOCF, tipocf1 == 'F' ? "F" : "C"); + m.set(F_CODCF, codcf1); + m.set(F_RAGSOC, s.cell(sel, A_RAGSOC)); + TString16 k; k << "CONTRATTO_" << get(F_ANNO); + m.set(A_CONTRATTO, k); + k.cut(0) << "Contratto " << get(F_ANNO); + m.set(F_RAGOCC, k); + if (m.run() == K_ENTER) { - row->get(n, numdoc); - row->get(c, contratto); - if (numdoc.blank() && contratto.blank()) + contratto1 = m.get(A_CONTRATTO); + modpag1 = m.get_int(A_MODPAG); + TString80 codtab; + codtab.format("%c%6ld%s", tipocf1, codcf1, (const char*)contratto1); + TModule_table con("CON"); + con.put("CODTAB", codtab); + con.put("S0", m.get(F_RAGOCC)); + con.put("S6", modpag1); + const int err = con.write(); + if (err != NOERR) { - row->add("X", f); - row->add(modpag, m); - row->add(contratto1, c); - s.enable_cell(r, c); + if (err == _isreinsert) + { + if (!yesno_box(FR("Il contratto '%s' esiste già: si desidera continuare ugualmente?"), (const char*)contratto1)) + { + modpag1 = 1; + contratto1.cut(0); + } + } + else + { + cantwrite_box(con.description()); + modpag1 = 1; + contratto1.cut(0); + } + } + } + } + + if (modpag1 > 1 && contratto1.not_empty() && yesno_box("Si desidera applicare il contratto '%s' alle righe successive?", (const char*)contratto1)) + { + const int tcf = s.cid2index(A_TIPOCF); + const int ccf = s.cid2index(A_CODCF); + const int frz = s.cid2index(A_FORZATA); + const int con = s.cid2index(A_CONTRATTO); + const int ret = s.cid2index(A_NUMRETT); + const int mod = s.cid2index(A_MODPAG); + + TString80 contratto; + TString16 numrett; + for (int r = sel; r < s.items(); r++) + { + TToken_string& row = s.row(r); + + const char tipocf = row.get_char(tcf); + const long codcf = row.get_long(ccf); + if (tipocf != tipocf1 || codcf != codcf1) + break; // Sconfinamento in altro cliente + + row.get(ret, numrett); + row.get(con, contratto); + if (numrett.blank() && contratto.blank()) + { + row.add("X", frz); + row.add(modpag1, mod); + row.add(contratto1, con); + s.enable_cell(r, con); } } s.force_update(); diff --git a/fe/fe0100c.uml b/fe/fe0100c.uml new file mode 100644 index 000000000..bbc71f338 --- /dev/null +++ b/fe/fe0100c.uml @@ -0,0 +1,78 @@ +#include "fe0100a.h" + +PAGE "Nuovo contratto" -1 -1 56 9 + +GROUPBOX DLG_NULL 53 4 +BEGIN + PROMPT 1 0 "@bCliente" +END + +LIST F_TIPOCF 1 10 +BEGIN + PROMPT 2 1 "" + ITEM "C|Cliente" + ITEM "F|Fornitore" + FLAGS "D" +END + +NUMBER F_CODCF 6 +BEGIN + PROMPT 21 1 "" + FLAGS "D" +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 2 2 "" + FLAGS "D" +END + +GROUPBOX DLG_NULL 53 5 +BEGIN + PROMPT 1 4 "@bContratto" +END + +NUMBER F_ANNO 4 +BEGIN + PROMPT 2 5 "Anno " + FLAGS "D" +END + +STRING A_CONTRATTO 18 +BEGIN + PROMPT 17 5 "Codice " + FLAGS "U" + CHECKTYPE REQUIRED +END + +LIST A_MODPAG 1 18 +BEGIN + PROMPT 2 6 "Modalità di pagamento " + ITEM "2|2 - Frazionato" + ITEM "3|3 - Periodico" +END + +STRING F_RAGOCC 50 36 +BEGIN + PROMPT 2 7 "Descrizione " +END + +ENDPAGE + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "" +END + +BUTTON DLG_CANCEL 2 2, +BEGIN + PROMPT 1 2 "Annulla" +END + +#include + +ENDPAGE + +ENDMASK \ No newline at end of file diff --git a/fe/felib.cpp b/fe/felib.cpp index 6136c4849..fd5f4005f 100644 --- a/fe/felib.cpp +++ b/fe/felib.cpp @@ -149,7 +149,7 @@ const TString& TAnagrafica::stato_estero_UNICO() const u.format("%03d", _stato_estero); const TString& cod = cache().get("%STA", u, "S8"); // S8=UNICO S9=ISTAT if (cod.len() == 3) - u = cod; + return cod; return get_tmp_string() = u; } @@ -218,6 +218,7 @@ bool TAnagrafica::init(const TRectype& rec) if (_com_res.empty()) _com_res = rec.get(ANA_COMRES); build_ind_res(rec, ANA_INDRES, ANA_CIVRES); + _stato_estero = rec.get_int(ANA_STATORES); // Dati di nascita persone fisiche if (_tipo == 'F') @@ -249,15 +250,35 @@ bool TAnagrafica::init(const TRectype& rec) _tipo = ' '; // Non faccio assunzioni sulla persona fisica - if (rec.get_char(CLI_TIPOCF) == 'F') // Fornitore -> Percipiente + // Persona Fisica? + if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get(CLI_DATANASC).not_empty()) { const long cod = rec.get_long(CLI_CODANAGPER); if (cod > 0) init(LF_ANAG, 'F', cod); + if (rec.get(CLI_DATANASC).not_empty()) + { + _data_nasc = rec.get(CLI_DATANASC); + _tipo = 'F'; + } if (rec.get(CLI_COMNASC).not_empty()) _com_nasc = rec.get(CLI_COMNASC); - if (rec.get(CLI_DATANASC).not_empty()) - _data_nasc = rec.get(CLI_DATANASC); + if (_com_nasc.empty() && rec.get(CLI_STATONASC).not_empty()) + { + const TString80 stato = cache().get("%STA", rec.get(CLI_STATONASC), "S0"); + TISAM_recordset comuni("USE COMUNI\nFROM CODCOM=Z"); + double best = 0.75; + for (bool ok = comuni.move_first(); ok; ok = comuni.move_next()) + { + const TString& desc = comuni.get(COM_DENCOM).as_string(); + const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato); + if (score > best) + { + best = score; + _com_nasc = comuni.get(COM_COM).as_string(); + } + } + } } // Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica