diff --git a/pe/pe0400.cpp b/pe/pe0400.cpp index 19f0ab936..105b61312 100755 --- a/pe/pe0400.cpp +++ b/pe/pe0400.cpp @@ -1,6 +1,7 @@ #include #include +#include "../ve/sconti.h" #include "../ve/ve0100.h" #include "../ve/veini.h" #include "../ve/veuml.h" @@ -43,6 +44,7 @@ protected: static bool pe_codart_handler(TMask_field& f, KEY k); static bool pe_qta_handler(TMask_field& f, KEY k); static bool pe_k_handler(TMask_field& f, KEY k); + static bool pe_prezzo_handler(TMask_field& f, KEY k); static bool ss_notify(TSheet_field& ss, int r, KEY key); @@ -55,7 +57,6 @@ public: static bool pe_espandi_riga_handler(TMask_field& f, KEY k); static bool pe_copia_handler(TMask_field& f, KEY k); static bool pe_incolla_handler(TMask_field& f, KEY k); - static bool pe_usek_handler(TMask_field& f, KEY k); virtual void user_set_handler( short fieldid, int index); virtual void user_set_row_handler(TMask& rm, short field, int index); @@ -142,7 +143,7 @@ bool TGestione_preventivo_msk::ss_notify(TSheet_field& ss, int r, KEY key) short id; sh.enable_cell(r, sh.cid2index(FR_PREZZO), price_enabled); - sh.enable_cell(r, sh.cid2index(FR_JOLLY2), price_enabled && mask.get_bool(F_USEK)); +// sh.enable_cell(r, sh.cid2index(FR_JOLLY2), price_enabled && mask.get_bool(F_USEK)); sh.enable_cell(r, sh.cid2index(FR_JOLLY3), price_enabled); for (id = FR_CDC1; id < FR_CDC12; id++) sh.enable_cell(r, sh.cid2index(id), prodfin); @@ -180,7 +181,7 @@ bool TGestione_preventivo_msk::ss_notify(TSheet_field& ss, int r, KEY key) if (next_level > level) { sh.disable_cell(father_sheet_row, sh.cid2index(FR_PREZZO)); - sh.disable_cell(father_sheet_row, sh.cid2index(FR_JOLLY2) || !mask.get_bool(F_USEK)); +// sh.disable_cell(father_sheet_row, sh.cid2index(FR_JOLLY2) || !mask.get_bool(F_USEK)); sh.disable_cell(father_sheet_row, sh.cid2index(FR_JOLLY3)); father_row.zero(RDOC_PREZZO); father_row.zero(RDOC_K); @@ -264,7 +265,7 @@ TVariable_mask * TGestione_preventivo_msk::riga_mask(int numriga) m->set_handler(FR_CODART, pe_codart_handler); m->set_handler(FR_QTA, pe_qta_handler); - m->set_handler(FR_PREZZO, pe_k_handler); + m->set_handler(FR_PREZZO, pe_prezzo_handler); m->set_handler(FR_JOLLY2, pe_k_handler); tree.set_field(RDOC_TREE); k.set_field(RDOC_K); @@ -292,7 +293,7 @@ void TGestione_preventivo_msk::doc2mask(bool reload_clifo, bool force_load, bool const bool price_enabled = (i + 1 == d.physical_rows()) || (level >= d[i + 2].get_int(RDOC_LEVEL)); s.enable_cell(i, s.cid2index(FR_PREZZO), price_enabled); - s.enable_cell(i, s.cid2index(FR_JOLLY2), price_enabled && has_k); +// s.enable_cell(i, s.cid2index(FR_JOLLY2), price_enabled && has_k); s.enable_cell(i, s.cid2index(FR_JOLLY3), price_enabled); for (short id = FR_CDC1; id < FR_CDC12; id++) s.enable_cell(i, s.cid2index(id), prodfin); @@ -444,7 +445,7 @@ bool TGestione_preventivo_msk::pe_incolla_handler(TMask_field& f, KEY k) return ok; } -bool TGestione_preventivo_msk::pe_usek_handler(TMask_field& f, KEY k) +/*bool TGestione_preventivo_msk::pe_usek_handler(TMask_field& f, KEY k) { if (k == K_SPACE) { @@ -466,7 +467,7 @@ bool TGestione_preventivo_msk::pe_usek_handler(TMask_field& f, KEY k) sh.force_update(); } return true; -} +} */ /////////////////////// // HANDLER DI RIGA // @@ -476,11 +477,13 @@ bool TGestione_preventivo_msk::pe_codart_handler(TMask_field& f, KEY k) { TMask& row_mask = f.mask(); bool ok = codart_handler( f, k ); + TSheet_field * sh = row_mask.get_sheet(); if (ok && sh != NULL && k == K_TAB && f.focusdirty()) { TGestione_preventivo_msk & mask = (TGestione_preventivo_msk &) sh->mask(); + const bool has_k = mask.get_bool(F_USEK); TDocumento & doc = mask.doc(); bool update = false; const int r = sh->selected(); @@ -493,7 +496,7 @@ bool TGestione_preventivo_msk::pe_codart_handler(TMask_field& f, KEY k) const TArticolo_giacenza & art = cached_article(codart); const real costo = art.get_real(mask._field_costo); - if (row_mask.field(FR_JOLLY2).enabled()) + if (has_k) { const real ric = art.get(ANAMAG_PERCRIC); TString80 k; @@ -513,7 +516,6 @@ bool TGestione_preventivo_msk::pe_codart_handler(TMask_field& f, KEY k) } row_mask.set(FR_JOLLY3, costo); } - const bool has_k = mask.get_bool(F_USEK); if (has_k || !row_mask.field(FR_PREZZO).enabled()) row_mask.set(FR_PREZZO, ""); @@ -548,7 +550,7 @@ bool TGestione_preventivo_msk::pe_codart_handler(TMask_field& f, KEY k) short id; sh->enable_cell(i - 1, sh->cid2index(FR_PREZZO), price_enabled); - sh->enable_cell(i - 1, sh->cid2index(FR_JOLLY2), price_enabled && has_k); +// sh->enable_cell(i - 1, sh->cid2index(FR_JOLLY2), price_enabled && has_k); sh->enable_cell(i - 1, sh->cid2index(FR_JOLLY3), price_enabled); const TString& codart = row.get(RDOC_CODARTMAG); @@ -671,37 +673,105 @@ bool TGestione_preventivo_msk::pe_qta_handler(TMask_field& f, KEY k) } void TGestione_preventivo_msk::update_prezzo_vendita(TMask & row_mask) { - if (row_mask.get(FR_PREZZO).blank()) - { - real costo = row_mask.get(FR_JOLLY3); - TString k(row_mask.get(FR_JOLLY2)); - TString ge; - real perc; - TSheet_field * sh = row_mask.get_sheet(); - const int r = sh->selected(); + real costo = row_mask.get(FR_JOLLY3); + TString k(row_mask.get(FR_JOLLY2)); + TString ge; + real perc; + TSheet_field * sh = row_mask.get_sheet(); + const int r = sh->selected(); - if (k.blank()) - k = get(F_K); - if (scontoexpr2perc(k, false, ge, perc)) - costo *= (2 - perc); - - TCurrency_documento prezzo(costo, doc(), true); - row_mask.set(FR_PREZZO, prezzo.get_num().string()); - } + if (k.blank()) + k = get(F_K); + if (scontoexpr2perc(k, false, ge, perc)) + costo *= (real(2.00) - perc); + + TCurrency_documento prezzo(costo, doc(), true); + row_mask.set(FR_PREZZO, prezzo.get_num().string()); } bool TGestione_preventivo_msk::pe_k_handler(TMask_field& f, KEY k) { TMask& row_mask = f.mask(); TSheet_field * sh = row_mask.get_sheet(); + const bool last_level = row_mask.field(FR_JOLLY3).enabled(); - if (row_mask.field(FR_JOLLY3).enabled() && sh != NULL && k == K_TAB && f.focusdirty()) + if (sh == NULL) + return true; + + TGestione_preventivo_msk & mask = (TGestione_preventivo_msk &) sh->mask(); + + if (last_level) { - TGestione_preventivo_msk & mask = (TGestione_preventivo_msk &) sh->mask(); - - mask.update_prezzo_vendita(row_mask); + if ((k == K_TAB && f.focusdirty()) || k == K_F8) + mask.update_prezzo_vendita(row_mask); } - return TRUE; + else + if (k == K_F8) + { + const TString k(row_mask.get(FR_JOLLY2)); + const int r = sh->selected(); + TDocumento & doc = mask.doc(); + const int start_level = doc[r + 1].get_int(RDOC_LEVEL); + TString ge; + real perc; + + row_mask.reset(FR_JOLLY2); + for (int i = r + 2; i <= doc.physical_rows(); i++) + { + TRiga_documento & row = doc[i]; + const int level = row.get_int(RDOC_LEVEL); + + if (level <= start_level) + break; + if (sh->cell_enabled(i -1, sh->cid2index(FR_PREZZO))) + { + TToken_string & shrow = sh->row(i - 1); + + row.put(RDOC_K, k); + shrow.add(k, sh->cid2index(FR_JOLLY2)); + TString row_k(k); + + if (row_k.blank()) + row_k = mask.get(F_K); + + real val = row.get_real(RDOC_COSTO); + + if (scontoexpr2perc(row_k, false, ge, perc)) + val *= (2 - perc); + TCurrency_documento prezzo(val, doc, true); + row.put(RDOC_PREZZO, prezzo.get_num()); + shrow.add(prezzo.get_num().string(), sh->cid2index(FR_PREZZO)); + } + } + sh->force_update(); + } + + return true; +} + +bool TGestione_preventivo_msk::pe_prezzo_handler(TMask_field& f, KEY k) +{ + TMask& row_mask = f.mask(); + const bool last_level = row_mask.field(FR_JOLLY3).enabled(); + + if (last_level && k == K_F8) + { + TSheet_field * sh = row_mask.get_sheet(); + + if (sh != NULL) + { + TGestione_preventivo_msk & mask = (TGestione_preventivo_msk &) sh->mask(); + TDocumento & doc = mask.doc(); + const int row = sh->selected(); + TCond_vendita & condv = mask.condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + condv.ricerca(); + doc[row].put(RDOC_PREZZO, row_mask.get(FR_PREZZO)); + } + } + return true; } //metodo che setta gli handler sui campi di riga @@ -776,7 +846,7 @@ TMask* TGestione_preventivo_app::get_mask( int mode ) TBoolean_field & fk = m->add_boolean(F_USEK, sh.page(), "", 2, y); fk.set_field(DOC_USEK); - m->set_handler(F_USEK, TGestione_preventivo_msk::pe_usek_handler); +// m->set_handler(F_USEK, TGestione_preventivo_msk::pe_usek_handler); TToken_string * fk_false = fk.message(0, true); TToken_string * fk_true = fk.message(1, true);