From b525875cc17c0645ddda519572a4f33a1f9a081b Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 22 Sep 2014 13:59:03 +0000 Subject: [PATCH] Migliorati controlli su giacenza in evasione ordini git-svn-id: svn://10.65.10.50/branches/R_10_00@22999 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ve/ve0100.cpp | 13 +++-- ve/velib04.h | 4 +- ve/velib04b.cpp | 127 ++++++++++++++++++++++++------------------- ve/velib04d.cpp | 142 +++++++++++++++++++++++++++++++++++------------- ve/velib04d.h | 17 +++--- ve/velib04d.uml | 28 ++++++++-- ve/velib06.cpp | 139 ++++++++++++++++++++++++++++++----------------- 7 files changed, 306 insertions(+), 164 deletions(-) diff --git a/ve/ve0100.cpp b/ve/ve0100.cpp index 72591e555..a1fd3a5e0 100755 --- a/ve/ve0100.cpp +++ b/ve/ve0100.cpp @@ -1075,8 +1075,7 @@ void TMotore_application::ini2mask(TConfig& ini, TMask& msk, bool query) rec.put(key, val); } - // solo la insert chiama la post_insert necessaria alla disabilitazione verifichiamo - // l'autoload ?? + // solo la insert chiama la post_insert necessaria alla disabilitazione verifichiamo l'autoload ?? f.insert(-1, FALSE); // Aggiunge la riga allo sheet @@ -1115,18 +1114,18 @@ void TMotore_application::ini2mask(TConfig& ini, TMask& msk, bool query) if (!ini.exist(RDOC_CODIVA) && !(rec.is_descrizione() || rec.is_sconto() || rec.is_sconto_perc())) { const TString4 codiva = ((TDocumento_mask &) msk).doc().codesiva(); - if (codiva.full()) rec.put(RDOC_CODIVA, codiva); } rec.autoload(f); - f.check_row(f.items() - 1, 0x2); + const int last_row = f.items() - 1; + f.check_row(last_row, 0x2); if (!checked) //se non e' checked, il record viene autosalvato (in modo che sia salvato completamente) { const TString& prezzo = ini.get(RDOC_PREZZO); if (prezzo.full()) - f.row(f.items() - 1).add(prezzo, f.cid2index(FR_PREZZO)); + f.row(last_row).add(prezzo, f.cid2index(FR_PREZZO)); rec.autosave(f); } } @@ -1144,6 +1143,10 @@ bool TMotore_application::save_and_print(bool savedoc, TPrtype mode) if (savedoc) { + TSheet_field& ss = edit_mask().sfield(F_SHEET); + if (!ss.on_key(K_ENTER)) + return already_printing = false; + if (save(false)) edit_mask().update_father_rows(false); else diff --git a/ve/velib04.h b/ve/velib04.h index bf8d50e4e..f1ea436c8 100755 --- a/ve/velib04.h +++ b/ve/velib04.h @@ -479,13 +479,13 @@ protected: // Cerca il conto di contropartita per il movimento d'anticipo error_type search_counter_bill(TDocumento& doc, const TDate& datareg); // compila la testata del movimento di anticipo - error_type compile_head_anticipo(TDocumento&); + error_type compile_head_anticipo(TDocumento& doc, const TMovimentoPN_VE& movimento); // compila le righe del movimento di anticipo error_type compile_rows_anticipo(TDocumento&); // compila e scrive il pagamento del movimento di anticipo error_type write_pagamento_anticipo(TDocumento&); // scrive il movimento di anticipo pagamento - error_type write_anticipo(TDocumento&); + error_type write_anticipo(TDocumento& doc, const TMovimentoPN_VE& movimento); // scrive il movimento INTRA error_type write_intra(TDocumento&); error_type write_anal(TDocumento& doc, const TMovimentoPN& mv); diff --git a/ve/velib04b.cpp b/ve/velib04b.cpp index b9897f5ef..5e8d3d386 100755 --- a/ve/velib04b.cpp +++ b/ve/velib04b.cpp @@ -537,9 +537,9 @@ protected: public: error_type add(const TRiga_documento& r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO); - error_type add(const TRiga_documento* r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO) { return add(*r, conto, ndec, p);} + //error_type add(const TRiga_documento* r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO) { return add(*r, conto, ndec, p);} error_type add_omaggi(const TRiga_documento& r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO); - error_type add_omaggi(const TRiga_documento* r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO) { return add_omaggi(*r, conto, ndec, p);} + //error_type add_omaggi(const TRiga_documento* r, const TBill& conto, const int ndec = ALL_DECIMALS, const real & p = UNO) { return add_omaggi(*r, conto, ndec, p);} void set_caus(TCausale * caus) { _caus = caus; } TIVA_array() {} @@ -561,10 +561,10 @@ error_type TIVA_array::add_omaggi(const TRiga_documento& r, const TBill& conto, add(r, conto, ndec, p); TRiga_documento r_storno(r); - r_storno.set_tipo("01"); + r_storno.set_tipo("01"); // Riga merce standard r_storno.put(RDOC_CODIVA, _iva_sto); - real prezzo = r_storno.get_real(RDOC_PREZZO); - prezzo = -prezzo; + const real prezzo = -r_storno.get_real(RDOC_PREZZO); + r_storno.put(RDOC_PREZZO, prezzo); if (_conto_sto.ok()) @@ -580,7 +580,7 @@ error_type TIVA_array::add(const TRiga_documento& r, const TBill& conto, const i const TTipo_riga_documento & t = r.tipo(); TString80 key; const TCodiceIVA& tiva = r.iva(); - const TString4 cod(tiva.codice()); + const TString4 cod = tiva.codice(); TBill c(conto); int ord = 0; int detr = 0; @@ -907,7 +907,7 @@ error_type TContabilizzazione::get_next_reg_num(long& nr) { // reperisce l'ultimo numero di registrazione disponibile _error = no_error; - TLocalisamfile& mov = _movimento->lfile(); + TLocalisamfile mov(LF_MOV); nr = 1L; if (mov.last() == NOERR) { @@ -2409,29 +2409,31 @@ error_type TContabilizzazione::compile_rows_mov(TDocumento& doc) if (_error != no_error) _nrow = i; } - else - if (contomat.ok() && contomat != conto && pricemat != 0) - { - TRiga_documento rlav(r); - TRiga_documento rmat(r); - const real prezzo = r.get_real(RDOC_PREZZO); - rmat.put(RDOC_PREZZO, pricemat); - rmat.zero(RDOC_SCONTO); - const real valmat = rmat.imponibile(); - const real diff = r.imponibile() - valmat; + else + { + if (contomat.ok() && contomat != conto && pricemat != 0) + { + TRiga_documento rlav(r); + TRiga_documento rmat(r); + const real prezzo = r.get_real(RDOC_PREZZO); + rmat.put(RDOC_PREZZO, pricemat); + rmat.zero(RDOC_SCONTO); + const real valmat = rmat.imponibile(); + const real diff = r.imponibile() - valmat; - rlav.put(RDOC_PREZZO, diff); - rlav.put(RDOC_QTA, 1); - rlav.zero(RDOC_SCONTO); - rmat.put(RDOC_PREZZO, valmat); - rmat.put(RDOC_QTA, 1); - rmat.zero(RDOC_SCONTO); - _righe_iva->add(rlav, conto); - _righe_iva->add(rmat, contomat); - } - else - if (conto.ok()) - _righe_iva->add(r, conto); + rlav.put(RDOC_PREZZO, diff); + rlav.put(RDOC_QTA, 1); + rlav.zero(RDOC_SCONTO); + rmat.put(RDOC_PREZZO, valmat); + rmat.put(RDOC_QTA, 1); + rmat.zero(RDOC_SCONTO); + _righe_iva->add(rlav, conto); + _righe_iva->add(rmat, contomat); + } + else + if (conto.ok()) + _righe_iva->add(r, conto); + } if (!ritenuta && r.doc().tipo().calcolo_lordo()) // Si ricorda che calcolo_lordo() e fattura_commerciale() sono esclusivi. { @@ -3154,9 +3156,10 @@ error_type TContabilizzazione::write_all(TDocumento& doc, TMovimentoPN_VE & movi if (good() && dongle().active(M77AUT) && do_770) write_percip(doc, movimento); - if (has_sc && !doc.get_real(DOC_IMPPAGATO).is_zero()) + // nella 3.1 testava solo l'importo, ma nella 10.0 testava anche has_sc, dal 2/9/2014 si torna al vecchio modo + if (!doc.get_real(DOC_IMPPAGATO).is_zero()) { - if (write_anticipo(doc) != no_error) + if (write_anticipo(doc, movimento) != no_error) movimento.remove(); // Se si è verificato un errore nella scrittura dell'anticipo rimuove il movimento di prima nota } @@ -3233,22 +3236,22 @@ error_type TContabilizzazione::write_all_re(TDocumento& doc, TMovimentoPN_VE & m change_doc_status(doc); TString msg(TR("--- Movimento contabile ")); - msg << "$[b,w]" << _movimento->curr().get_long(MOV_NUMREG) << "$[n,w]"; - msg << " del " << _movimento->curr().get(MOV_DATAREG); + msg << "$[b,w]" << movimento.curr().get_long(MOV_NUMREG) << "$[n,w]"; + msg << " del " << movimento.curr().get(MOV_DATAREG); _viswin->add_line(msg); } return no_error; } -error_type TContabilizzazione::compile_head_anticipo(TDocumento& doc) +error_type TContabilizzazione::compile_head_anticipo(TDocumento& doc, const TMovimentoPN_VE& movimento) { TString descr; TString8 codcaus = doc.clifor().vendite().get(CFV_CODCAUSINC); if (codcaus.blank()) codcaus = doc.tipo().caus_anticipo(); - const TDate datareg = _movimento->curr().get_date(MOV_DATAREG); + const TDate datareg = movimento.curr().get_date(MOV_DATAREG); if (!_caus->read(codcaus,datareg.year())) return caus_ant_error; @@ -3262,7 +3265,7 @@ error_type TContabilizzazione::compile_head_anticipo(TDocumento& doc) _anticipo = new TMovimentoPN; TRectype& head = _anticipo->curr(); - head = _movimento->curr(); // Copia tutti i campi... + head = movimento.curr(); // Copia tutti i campi... head.put(MOV_NUMREG,nr); head.zero(MOV_DATA74TER); head.put(MOV_TIPODOC,_caus->tipo_doc()); @@ -3272,27 +3275,31 @@ error_type TContabilizzazione::compile_head_anticipo(TDocumento& doc) descr << TR(" del ") << doc.get_date(DOC_DATADOC).string(); head.put(MOV_DESCR,descr); head.put(MOV_TIPOMOV,char(_caus->tipomov()+'0')); + head.zero(MOV_TIPO); + head.zero(MOV_CODCF); head.zero(MOV_REG); head.zero(MOV_PROTIVA); head.zero(MOV_CODPAG); head.zero(MOV_CORRLIRE); head.zero(MOV_CORRVALUTA); -// TString4 codval = head.get(MOV_CODVALI); -// real cambio = head.get_real(MOV_CAMBIOI); head.zero(MOV_CODVALI); head.zero(MOV_CAMBIOI); + head.zero(MOV_INVIATO); + head.zero(MOV_INVIVA); + head.zero(MOV_LIQDIFF); + head.zero(MOV_IVAXCASSA); if (sc_enabled(datareg)) { TCurrency_documento p(doc.get_real(DOC_IMPPAGATO), doc); TCurrency_documento plit(p); p.change_to_firm_val(); if (doc.in_valuta()) { - head.put(MOV_TOTDOC,plit.get_num()); - head.put(MOV_TOTDOCVAL,p.get_num()); + head.put(MOV_TOTDOC, plit.get_num()); + head.put(MOV_TOTDOCVAL, p.get_num()); } else { - head.put(MOV_TOTDOC,p.get_num()); + head.put(MOV_TOTDOC, p.get_num()); head.zero(MOV_TOTDOCVAL); } } @@ -3305,10 +3312,10 @@ error_type TContabilizzazione::compile_head_anticipo(TDocumento& doc) // Memorizza il movimento contabile di destinazione! doc.put(DOC_NUMANT, nr); // Scrive sulla testata dell'anticipo il numero di documento originale - head.put(MOV_DPROVV, doc.get(DOC_PROVV)); - head.put(MOV_DANNO, doc.get(DOC_ANNO)); + head.put(MOV_DPROVV, doc.get(DOC_PROVV)); + head.put(MOV_DANNO, doc.get(DOC_ANNO)); head.put(MOV_DCODNUM, doc.get(DOC_CODNUM)); - head.put(MOV_DNDOC, doc.get(DOC_NDOC)); + head.put(MOV_DNDOC, doc.get(DOC_NDOC)); head.put(MOV_CONTSEP, doc.get(DOC_CONTSEP)); return no_error; @@ -3628,17 +3635,17 @@ error_type TContabilizzazione::write_pagamento_anticipo(TDocumento& doc) return _error; } -error_type TContabilizzazione::write_anticipo(TDocumento& doc) +error_type TContabilizzazione::write_anticipo(TDocumento& doc, const TMovimentoPN_VE& movimento) { // Questo movimento viene scritto solo se e' stato versato un anticipo di pagamento // Crea 1 testata, 1 riga contabile e la relativa riga di pagamento sulla partita a cui fa riferimento // La testata e' praticamente la stessa del movimento appena scritto, tranne che per il numero di // protocollo, il numero di registrazione la descrizione, i totali in lire/valuta, // la condizione pagamento... - _error = no_error; + const TRectype& dbghead = movimento.curr(); - _error = compile_head_anticipo(doc); - if (_error == no_error) + _error = compile_head_anticipo(doc, movimento); + if (_error == no_error && _anticipo != NULL) { // Una volta compilata la testa... compila le righe... if (_anticipo) @@ -3655,10 +3662,11 @@ error_type TContabilizzazione::write_anticipo(TDocumento& doc) TSaldo_agg saldo; int err = NOERR; - if (doc_contabilized(doc, true)) + const long numant = doc_contabilized(doc, true); + if (numant > 0) { TMovimentoPN oldant; - oldant.curr().put(MOV_NUMREG, doc.get(DOC_NUMANT)); + oldant.curr().put(MOV_NUMREG, numant); if (oldant.read() == NOERR) aggiorna_saldi(saldo, oldant, false); err = _anticipo->rewrite(); @@ -3677,15 +3685,24 @@ error_type TContabilizzazione::write_anticipo(TDocumento& doc) err, _anticipo->curr().get_long(MOV_NUMREG)); return generic_error; } + else + { + TString msg(TR("--- Movimento di anticipo ")); + msg << "$[b,w]" << _anticipo->curr().get(MOV_NUMREG) << "$[n,w]"; + msg << TR(" del ") << _anticipo->curr().get(MOV_DATAREG); + _viswin->add_line(msg); + } aggiorna_saldi(saldo, *_anticipo, true); - - } - delete _anticipo; - _anticipo = NULL; } } - + + if (_anticipo) + { + delete _anticipo; + _anticipo = NULL; + } + return _error; } diff --git a/ve/velib04d.cpp b/ve/velib04d.cpp index 420c9be5b..8317e6855 100755 --- a/ve/velib04d.cpp +++ b/ve/velib04d.cpp @@ -11,13 +11,14 @@ class TConsegna_mask : public TAutomask { bool _ordina_per_codice; bool _ignora_descrizioni; - const TDocumento* _doc; + const TDocumento* _indoc; + const TDocumento* _outdoc; protected: virtual bool on_field_event(class TOperable_field& f, TField_event e, long jolly); public: - void doc2mask(const TDocumento& doc, const TString & articolo); + void doc2mask(const TDocumento& indoc, const TDocumento& outdoc, const TString & articolo); TConsegna_mask(int header_code = 0, bool per_codice = false, bool ignora_descrizioni = false); }; @@ -79,10 +80,10 @@ bool TConsegna_mask::on_field_event(class TOperable_field& f, TField_event e, lo row->add("X", S_RIGAEVASA-FIRST_FIELD); s.disable_cell(n, S_RIGAEVASA-FIRST_FIELD); } - if (evaso == ZERO && residuo == ZERO) + if (evaso.is_zero() && residuo.is_zero()) { const int nriga = row->get_int(S_NUMRIGA-FIRST_FIELD); - const TRiga_documento& rdoc = (*_doc)[nriga]; + const TRiga_documento& rdoc = (*_indoc)[nriga]; select = rdoc.quantita().is_zero(); } if (select) @@ -94,6 +95,59 @@ bool TConsegna_mask::on_field_event(class TOperable_field& f, TField_event e, lo case F_ROWS: if (e == se_query_add || e == se_query_del) return false; + if (e == fe_close) + { + const TString& codcausmag = _outdoc->get(DOC_CAUSMAG); + if (codcausmag.full()) + { + const TCausale_magazzino& causmag = ::cached_causale_magazzino(codcausmag); + const int segno = causmag.sgn(s_giac); + if (segno < 0) // Scala dalla giacenza? + { + TSheet_field& s = (TSheet_field&)f; + TAssoc_array giacenze; + FOR_EACH_SHEET_ROW(s, n, row) + { + const bool cons = row->get_char(0) > ' '; // E' da consegnare? + if (cons) + { + const real e = row->get(s.cid2index(S_QTADAEVADERE)); + if (!e.is_zero()) + { + TToken_string key(32, ' '); + key.add(row->get(s.cid2index(S_CODART))); + key.add(row->get(s.cid2index(S_LIVGIAC1))); + key.add(row->get(s.cid2index(S_LIVGIAC2))); + key.add(row->get(s.cid2index(S_LIVGIAC3))); + key.add(row->get(s.cid2index(S_LIVGIAC4))); + key.trim(); + real* g = (real*)giacenze.objptr(key); + if (g == NULL) + { + g = new real(row->get(s.cid2index(S_GIACENZA))); + giacenze.add(key, g); + } + *g -= e; + } + } + } + + FOR_EACH_ASSOC_OBJECT(giacenze, h, k, o) + { + const real& g = *(real*)o; + if (g < ZERO) + { + TString msg; + msg << TR("L'articolo ") << k + << TR(" avrà una giacenza di ") << g.stringa() << ":\n" + << TR("Si desidera proseguire ugualmente?"); + if (!yesno_box(msg)) + return false; + } + } + } + } + } default:break; } @@ -115,25 +169,28 @@ int rows_sort_func(TSheet_field& s, int i, int j) const short fields[] = { S_CODART, S_LIVGIAC1, S_LIVGIAC2, S_LIVGIAC3, S_LIVGIAC4, S_CODMAG, S_CODDEP, S_RIGAEVASA, S_DATACONS, S_QTARESIDUA, -1 }; + // Temporary vars + TString80 ss1, ss2; + real rr1, rr2; + int ret = 0; for (int field = 0; ret == 0 && fields[field] > 0; field++) { - if (fields[field] == S_QTARESIDUA) + const short id = fields[field]; + if (id == S_QTARESIDUA) { - real rr1, rr2; - s1.get(fields[field]-FIRST_FIELD, rr1); - s2.get(fields[field]-FIRST_FIELD, rr2); + s1.get(id-FIRST_FIELD, rr1); + s2.get(id-FIRST_FIELD, rr2); ret = rr2 < rr1 ? -1 : (rr2 > rr1 ? 1 : 0); } else { - TString80 ss1, ss2; - s1.get(fields[field]-FIRST_FIELD ,ss1); - s2.get(fields[field]-FIRST_FIELD ,ss2); - if (fields[field] == S_DATACONS) + s1.get(id-FIRST_FIELD, ss1); + s2.get(id-FIRST_FIELD, ss2); + if (id == S_DATACONS) { const TDate dd1 = ss1, dd2 = ss2; - ret = int (dd1.date2ansi() - dd2.date2ansi()); + ret = int(dd1 - dd2); } else ret = ss1.compare(ss2); @@ -142,10 +199,11 @@ int rows_sort_func(TSheet_field& s, int i, int j) return ret; } -void TConsegna_mask::doc2mask(const TDocumento& doc, const TString& articolo) +void TConsegna_mask::doc2mask(const TDocumento& indoc, const TDocumento& outdoc, const TString& articolo) { TWait_cursor hourglass; - _doc = &doc; + _indoc = &indoc; + _outdoc = &outdoc; for (int n = fields()-1; n >= 0; n--) { @@ -153,20 +211,24 @@ void TConsegna_mask::doc2mask(const TDocumento& doc, const TString& articolo) const TFieldref* fr = f.field(); if (fr != NULL) { - const TString& val = doc.get(fr->name()); + const TString& val = indoc.get(fr->name()); f.set(val); } } + + const TDate oggi(TODAY); + TEsercizi_contabili esc; + const int codes = esc.date2esc(oggi); - const bool show_evaded = doc.tipo().mostra_righe_evase_in_elaborazione(); + const bool show_evaded = indoc.tipo().mostra_righe_evase_in_elaborazione(); TSheet_field& s = sfield(F_ROWS); s.destroy(); - const int rows = doc.physical_rows(); + const int rows = indoc.physical_rows(); int rowno = 0; for (int i = 0; i < rows; i++) { - const TRiga_documento& rec = doc[i+1]; + const TRiga_documento& rec = indoc[i+1]; const real residuo = rec.qtaresidua(); const bool evasa = residuo.is_zero(); bool show_line = show_evaded || !evasa; @@ -181,12 +243,12 @@ void TConsegna_mask::doc2mask(const TDocumento& doc, const TString& articolo) r.add(" "); else r.add(residuo.string()); - r.add(" "); // Da evadere + r.add(" "); // Da evadere if (evasa) { s.disable_cell(rowno, -1); // Disbilita tutta la riga ... s.enable_cell(rowno, 0); // ... tranne il flag di consegna - r.add("X"); // La considera evasa + r.add("X"); // La considera evasa } else r.add(" "); @@ -196,20 +258,26 @@ void TConsegna_mask::doc2mask(const TDocumento& doc, const TString& articolo) const TString& livello = rec.get(RDOC_LIVELLO); for (int l = 1; l <= 4; l++) r.add(livelli_giacenza().unpack_grpcode(livello, l)); + + if (!evasa) + { + TArticolo_giacenza ag(rec.get(RDOC_CODART)); + const real giac = ag.giacenza_anno(rec.get(RDOC_CODMAG), livello, codes); + r.add(giac.string(), s.cid2index(S_GIACENZA)); + } // Reperisce data di consegna da riga o testata - const TDate row_data_cons = rec.get(RDOC_DATACONS); - if (row_data_cons.ok()) - r.add(row_data_cons); - else - r.add(doc.get_date(DOC_DATACONS)); + TDate data_cons = rec.get(RDOC_DATACONS); + if (!data_cons.ok()) + data_cons = indoc.get_date(DOC_DATACONS); + r.add(data_cons, s.cid2index(S_DATACONS)); - r.add(rec.get(RDOC_PREZZO), s.cid2index(S_PREZZO)); - r.add(rec.get(RDOC_DESCR), s.cid2index(S_DESCR)); + r.add(rec.get(RDOC_PREZZO), s.cid2index(S_PREZZO)); + r.add(rec.get(RDOC_DESCR), s.cid2index(S_DESCR)); r.add(rec.get(RDOC_TIPORIGA), s.cid2index(S_TIPORIGA)); - r.add(rec.get(RDOC_NRIGA),s.cid2index(S_NUMRIGA)); - r.add(rec.get(RDOC_CODAGG1),s.cid2index(S_CODAGG1)); - r.add(rec.get(RDOC_CODAGG2),s.cid2index(S_CODAGG2)); + r.add(rec.get(RDOC_NRIGA), s.cid2index(S_NUMRIGA)); + r.add(rec.get(RDOC_CODAGG1), s.cid2index(S_CODAGG1)); + r.add(rec.get(RDOC_CODAGG2), s.cid2index(S_CODAGG2)); rowno++; } } @@ -218,8 +286,8 @@ void TConsegna_mask::doc2mask(const TDocumento& doc, const TString& articolo) } TConsegna_mask::TConsegna_mask(int header_code, bool per_codice, bool ignora_descrizioni) - : TAutomask("velib04d"), _ordina_per_codice(per_codice), _doc(NULL), - _ignora_descrizioni(ignora_descrizioni) + : TAutomask("velib04d"), _ordina_per_codice(per_codice), _indoc(NULL), _outdoc(NULL), + _ignora_descrizioni(ignora_descrizioni) { TCodgiac_livelli cl; TSheet_field& s = sfield(F_ROWS); @@ -478,7 +546,7 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o { TDocumento& indoc = doc_in[d < items_in ? d : 0]; TDocumento& outdoc = doc_out[d < items_out ? d : 0]; - m.doc2mask(indoc, articolo); + m.doc2mask(indoc, outdoc, articolo); if (multi_evasion) { const TString& um = params().get("UM"); @@ -511,7 +579,7 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o { FOR_EACH_SHEET_ROW(s, n, row) { - one_checked = row->get_char(0) > ' '; // E' da consegnare?; + one_checked = row->get_char(0) > ' '; // E' da consegnare? if (one_checked) break; } @@ -693,7 +761,7 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o if (prezzo_da_ordine()) { //const bool doc_al_lordo = outdoc.tipo().calcolo_lordo(); - const TString& codart = outrec.get(RDOC_CODARTMAG); + const TString80 codart = outrec.get(RDOC_CODARTMAG); const TRectype& anamag = cache().get(LF_ANAMAG, codart); if (!anamag.empty()) @@ -717,7 +785,6 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o } } - TDate dc = outrec.get(RDOC_DATACONS); // Controllo che sia sempre piena la data di consegna, if (!dc.ok()) // che potrebbe venire da righe che non ce l'hanno perchè uguale alla testata! { @@ -732,7 +799,6 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o if (last_rdoc.is_descrizione() && last_rdoc.get("RIFR").full()) outdoc.destroy_row(last_row, true); } - } } } diff --git a/ve/velib04d.h b/ve/velib04d.h index c7cc9ee07..b78e1469a 100755 --- a/ve/velib04d.h +++ b/ve/velib04d.h @@ -1,7 +1,7 @@ #define S_RIGACONSEGNATA 101 #define S_QTARESIDUA 102 #define S_QTADAEVADERE 103 -#define S_RIGAEVASA 104 +#define S_RIGAEVASA 104 #define S_CODMAG 105 #define S_CODDEP 106 #define S_CODART 107 @@ -9,13 +9,14 @@ #define S_LIVGIAC2 109 #define S_LIVGIAC3 110 #define S_LIVGIAC4 111 -#define S_DATACONS 112 -#define S_PREZZO 113 -#define S_DESCR 114 -#define S_TIPORIGA 115 -#define S_NUMRIGA 116 -#define S_CODAGG1 117 -#define S_CODAGG2 118 +#define S_GIACENZA 112 +#define S_DATACONS 113 +#define S_PREZZO 114 +#define S_DESCR 115 +#define S_TIPORIGA 116 +#define S_NUMRIGA 117 +#define S_CODAGG1 118 +#define S_CODAGG2 119 #define F_CODNUM 201 #define F_DESNUM 202 diff --git a/ve/velib04d.uml b/ve/velib04d.uml index d4d164ed5..b233f04da 100755 --- a/ve/velib04d.uml +++ b/ve/velib04d.uml @@ -185,6 +185,7 @@ BEGIN ITEM "Livello 2" ITEM "Livello 3" ITEM "Livello 4" + ITEM "Giacenza@13" ITEM "Data cons." ITEM "Prezzo@15" ITEM "Descrizione@50" @@ -198,7 +199,7 @@ ENDPAGE ENDMASK -PAGE "Riga 1" -1 -1 66 15 +PAGE "Riga 1" -1 -1 66 14 GROUPBOX DLG_NULL 64 8 BEGIN @@ -304,6 +305,12 @@ BEGIN FLAGS "U" END +NUMBER S_GIACENZA 13 5 +BEGIN + PROMPT 2 11 "Giacenza " + FLAGS "D" +END + CURRENCY S_PREZZO 15 BEGIN PROMPT 41 8 "Prezzo " @@ -323,24 +330,35 @@ END STRING S_CODAGG1 20 BEGIN - PROMPT 2 11 "Cod.Aggiuntivo 1 " + PROMPT 2 -2 "Cod.Aggiuntivo 1 " FLAGS "D" END STRING S_CODAGG2 20 BEGIN - PROMPT 2 12 "Cod.Aggiuntivo 2 " + PROMPT 2 -1 "Cod.Aggiuntivo 2 " FLAGS "D" END +ENDPAGE + +TOOLBAR "topbar" 0 0 0 2 + BUTTON DLG_OK 10 2 BEGIN - PROMPT -12 -1 "" + PROMPT -13 -1 "" END +BUTTON DLG_INFO 10 2 +BEGIN + PROMPT -23 -1 "" + PICTURE TOOL_INFO +END + + BUTTON DLG_CANCEL 10 2 BEGIN - PROMPT -22 -1 "" + PROMPT -33 -1 "" END ENDPAGE diff --git a/ve/velib06.cpp b/ve/velib06.cpp index 99bc0c9a7..f71186d20 100755 --- a/ve/velib06.cpp +++ b/ve/velib06.cpp @@ -1857,13 +1857,14 @@ void TDocumento_mask::update_giacenza() bool TDocumento_mask::ss_handler(TMask_field& f, KEY key) { bool ok = true; - if (key == K_ENTER) + if (key == K_ENTER && !f.empty()) { const TSheet_field& ss = (TSheet_field&)f; TDocumento_mask& mask = (TDocumento_mask&)ss.mask(); + const short cme = mask.cms_end(); // Se la commessa in testata è vuota controllo che sia presente sulle righe - if (!ss.empty() && cme > 0 && mask.efield(cme).empty()) + if (cme > 0 && mask.efield(cme).empty()) { // Controllo se la commessa è veramente obbligatoria in base alla configurazione TConfig& ini = ca_config(); @@ -1887,10 +1888,30 @@ bool TDocumento_mask::ss_handler(TMask_field& f, KEY key) } } } - /* - if (ok && ss.empty() && mask.insert_mode() && !app().is_transaction()) - ok = yesno_box(TR("Il documento è privo di righe:\nSi desidera continuare ugualmente?")); - */ + } + if (ini_get_bool(CONFIG_DITTA, "ve", "LIVPERART")) + { + const TString& causmag = mask.get(F_CAUSMAG); + const TCausale_magazzino& c = cached_causale_magazzino(causmag); + if (c.sgn(s_giac) != 0) // Controlla il livello solo per movimenti della giacenza + { + TCodice_articolo codart, livgiac; + FOR_EACH_SHEET_ROW(ss, r, riga) + { + codart = riga->get(ss.cid2index(FR_CODART)); + livgiac = riga->get(ss.cid2index(FR_LIV1)); + if (codart.full() && livgiac.blank()) + { + const TArticolo& art = ::cached_article(codart); + if (art.get_bool(ANAMAG_LIVPERART)) + { + ok = ss.error_box("Il livello di giacenza è obbligatorio per l'articolo %s alla riga %d", + (const char*)codart, r+1); + break; + } + } + } + } } } return ok; @@ -1916,7 +1937,7 @@ bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key ) if (doc.tipo().check_double_art()) { const int rows = doc.physical_rows(); - const TString80 codart = riga.get(RDOC_CODART); + const TCodice_articolo codart = riga.get(RDOC_CODART); for (int i = 1; i <= rows; i++) if (i != r + 1 && codart == doc[i].get(RDOC_CODART)) if (!yesno_box(FR("L'articolo %s è presente alla riga %d, si desidera continuare?"), (const char*)codart, i)) @@ -1969,9 +1990,9 @@ bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key ) break; case K_CTRL + K_INS: { - TRiga_documento & riga = doc[r + 1]; - TRectype & ven_rec = doc.clifor().vendite(); - TString8 s(ven_rec.get(CFV_CODMAG)); + TRiga_documento& riga = doc[r + 1]; + TRectype& ven_rec = doc.clifor().vendite(); + TString8 s = ven_rec.get(CFV_CODMAG); const TTipo_riga_documento & t = riga.tipo(); if (s.full()) @@ -1984,7 +2005,7 @@ bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key ) s = m.get(F_CAUSMAG); if (s.full()) { - const TCausale_magazzino & c = cached_causale_magazzino(s); + const TCausale_magazzino& c = cached_causale_magazzino(s); if (!c.empty() && c.get_char("S10") > ' ') // Ignora magazzini non validi s = c.get("S10"); else @@ -2037,46 +2058,59 @@ bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key ) break; case K_CTRL + K_TAB: // uscita dalla riga { - static const bool checkgiac = ini_get_bool(CONFIG_DITTA, "ve", "LIVPERART"); - bool ok = true; - if (checkgiac) - { - TString livello; - TToken_string & row = ss.row(r); + TToken_string& row = ss.row(r); + const TCodice_articolo codart = row.get(ss.cid2index(FR_CODART)); + bool check_art = codart.full(); + if (check_art) + { + const TArticolo& rec = cached_article(codart); + check_art = rec.get_bool(ANAMAG_LIVPERART) && ini_get_bool(CONFIG_DITTA, "ve", "LIVPERART"); + } + if (check_art) + { + TCodice_articolo livello; for (int l = 0; l<4 ; l++) doc.livelli().pack_grpcode(livello, row.get(ss.cid2index(FR_LIV1+l)), l+1); - if (livello.full()) + + if (livello.full()) { - const TString80 codart(row.get(ss.cid2index(FR_CODART))); - const TRectype & rec = cache().get(LF_ANAMAG, codart); - const bool check_art = rec.get_bool(ANAMAG_LIVPERART); + TLocalisamfile fl(LF_MULTIREL); + TRectype& r = fl.curr(); - if (check_art) - { - TLocalisamfile fl(LF_MULTIREL); - TRectype & r = fl.curr(); - - r.put(MULTI_COD, "ARTLV"); - r.put(MULTI_FIRST, codart); - r.put(MULTI_SECOND, livello); + r.put(MULTI_COD, "ARTLV"); + r.put(MULTI_FIRST, codart); + r.put(MULTI_SECOND, livello); - TRectype new_rec(r); - if (fl.read() != NOERR) - { - ok = yesno_box("Il codice di giacenza %s non e' legato all' articolo. Si desidera legarlo", (const char *)livello); - if (ok) - { - r = new_rec; - const int err = new_rec.write(fl); - if (err != NOERR) - return error_box("Impossibile legare il codice di giacenza. Errore %d", err); - } - else - return false; + TRectype new_rec(r); + if (fl.read() != NOERR) + { + bool ok = yesno_box("Il codice di giacenza %s non è legato all'articolo %s.\nSi desidera legarlo?", + (const char*)livello, (const char*)codart); + if (ok) + { + r = new_rec; + const int err = new_rec.write(fl); + if (err != NOERR) + ok = error_box("Impossibile legare il codice di giacenza. Errore %d", err); } + return ok; } } + else + { + // Controlla obbligatorietà del livello solo per movimenti della giacenza + TString8 codcaus = row.get(ss.cid2index(FR_CAUS)); + if (codcaus.blank()) + codcaus = m.get(F_CAUSMAG); + if (codcaus.full()) + { + const TCausale_magazzino& caus = ::cached_causale_magazzino(codcaus); + if (caus.sgn(s_giac) != 0) + return error_box(FR("Il codice giacenza è obbligatorio per l'articolo %s"), + (const char*)codart); + } + } } } break; @@ -2096,8 +2130,7 @@ TMask* TDocumento_mask::ss_getmask(int numriga, TMask& fullmask) if (numriga < doc.physical_rows()) return m.riga_mask(numriga); - else - return &fullmask; + return &fullmask; } bool TDocumento_mask::occas_code_handler(TMask_field& f, KEY key) @@ -2912,17 +2945,21 @@ void TDocument_tree::set_cursor(char tipocf, long codcf, int anno, const TString rec.put(DOC_ANNO, anno); rec.put(DOC_CODNUM, codnum); - int key = 4; + int key = 0; // Chiave di ordinamento ignota al momento TString filtro = filter; if (allow_zero_cf) { - key = 1; + // In assenza di anno cambio chiave del cursore (4-9-2014) + key = anno > 2000 ? 1 : 5; // PROVV+ANNO+CODNUM+NDOC oppure PROVV+CODNUM+ANNO+NDOC filtro << "&&(STR((CODCF=0)||(CODCF=" << codcf << ")))"; } else { + key = 4; // TIPOCF+CODCF+ANNO+CODNUM+NDOC rec.put(DOC_TIPOCF, tipocf); rec.put(DOC_CODCF, codcf); + if (anno <= 2000 && codnum.full()) // In assenza di anno azzero CODNUM che è già nel filtro (4-9-2014) + rec.zero(DOC_CODNUM); } if (_cursor != NULL) @@ -3493,7 +3530,7 @@ void TElabora_mask::update_ndoc_filter(bool is_tipo_elaborazione) TString80 td; td.format("&&(TIPODOC==\"%s\")", (const char *)tipo); filter << td; const TString& stato = get(F_STATODOC_ELAB); - if (stato.not_empty()) + if (stato.full()) { filter << "&&(STATO==\"" << stato << "\")"; } @@ -3663,13 +3700,13 @@ void TElabora_mask::docrif_search() 0, 1); if (sheet.run() == K_ENTER) { - const int nrifpos = fields.get_pos("NUMDOCRIF"); + const int nrifpos = fields.get_pos(DOC_NUMDOCRIF); const TString16 nrif = sheet.row(-1).get(nrifpos); f.set(nrif); - const int ndocpos = fields.get_pos("NDOC"); - const TString16 ndoc = sheet.row(-1).get(ndocpos); + const int ndocpos = fields.get_pos(DOC_NDOC); + const long ndoc = sheet.row(-1).get_long(ndocpos); set(F_NDOC_ELAB, ndoc); - const int codnumpos = fields.get_pos("CODNUM"); + const int codnumpos = fields.get_pos(DOC_CODNUM); const TString4 codnum = sheet.row(-1).get(codnumpos); set(F_CODNUM_ELAB, codnum, TRUE); }