Files correlati : Ricompilazione Demo : [ ] Commento : Riportata 01.04 patch 414 git-svn-id: svn://10.65.10.50/trunk@8260 c028cbd2-c16b-5b4b-a496-9718f37d4682
952 lines
27 KiB
C++
Executable File
952 lines
27 KiB
C++
Executable File
#include <defmask.h>
|
|
#include <progind.h>
|
|
#include <tabutil.h>
|
|
|
|
#include "velib.h"
|
|
#include "vepriv.h"
|
|
|
|
#ifndef __VERIG_H
|
|
#include "verig.h"
|
|
#endif
|
|
|
|
#ifndef __VEUML1_H
|
|
#include "veuml1.h"
|
|
#endif
|
|
|
|
#ifndef __VEINI_H
|
|
#include "veini.h"
|
|
#endif
|
|
|
|
#ifndef __SCONTI_H
|
|
#include "sconti.h"
|
|
#endif
|
|
|
|
#ifndef __MGLIB_H
|
|
#include "../mg/mglib.h"
|
|
#endif
|
|
|
|
#ifndef __DBLIB_H
|
|
#include "../db/dblib.h"
|
|
#endif
|
|
|
|
#include "../mg/anamag.h"
|
|
#include "../mg/codcorr.h"
|
|
#include "../mg/deslin.h"
|
|
#include "../mg/umart.h"
|
|
#define MAX_VIS_RATE 5
|
|
|
|
bool ora_hndl( TMask_field& field, KEY key )
|
|
|
|
{
|
|
if (field.to_check(key))
|
|
{
|
|
TFixed_string ora( field.get( ), 6 );
|
|
|
|
ora.trim( );
|
|
if (ora.not_empty() || field.required() )
|
|
{
|
|
if ( isdigit( ora[ 0 ] ) )
|
|
{
|
|
if ( ora[ 2 ] != ':')
|
|
{
|
|
if ( ora.len( ) > 4 )
|
|
ora.overwrite( ":", 2 );
|
|
else
|
|
ora.insert( ":", 2 );
|
|
}
|
|
}
|
|
const bool ok = ((isdigit(ora[0]))&&(isdigit(ora[1]))&&(isdigit(ora[3]))&&(isdigit(ora[4]))) &&
|
|
((atoi(&(ora[0]))<24)&&(atoi(&(ora[3]))<60));
|
|
if (ok )
|
|
field.set((ora));
|
|
else
|
|
return error_box("Ora errata o formato non valido");
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool dummy_hndl(TMask_field& field, KEY key)
|
|
{
|
|
warning_box( "Al campo %d è arrivato un KEY %d", field.dlg( ), key );
|
|
return TRUE;
|
|
}
|
|
|
|
// Handler per il calcolo delle date di pagamento
|
|
bool condpag_hndl( TMask_field& field, KEY key )
|
|
{
|
|
TDocumento_mask& m = (TDocumento_mask &) field.mask( );
|
|
|
|
if ( field.to_check(key) || (key == K_TAB && !m.is_running()))
|
|
{
|
|
const TString& condpag = m.get(F_CODPAG);
|
|
if (condpag.not_empty())
|
|
{
|
|
TDocumento& doc = m.doc();
|
|
// Aggiorna dati necessari per determinare il pagamento
|
|
doc.put(DOC_CODPAG, condpag);
|
|
doc.put(DOC_DATADOC, m.get(F_DATADOC));
|
|
doc.put(DOC_DATAINSC, m.get(F_DATAINSC));
|
|
doc.put(DOC_TIPOCF, m.get(F_TIPOCF));
|
|
doc.put(DOC_CODCF, m.get(F_CODCF));
|
|
TPagamento& pag = doc.pagamento();
|
|
pag.set_total(100, 10, 10);
|
|
pag.set_rate_auto();
|
|
|
|
int numrate = pag.n_rate( );
|
|
for(int i = 0; i < MAX_VIS_RATE; i++)
|
|
{
|
|
if (i < numrate)
|
|
{
|
|
m.show(F_DATASCAD1+i);
|
|
m.set(F_DATASCAD1+i, pag.data_rata(i));
|
|
}
|
|
else
|
|
m.hide(F_DATASCAD1+i);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool note_hndl( TMask_field& f, KEY key )
|
|
{
|
|
TDocumento_mask & m = (TDocumento_mask &) f.mask();
|
|
|
|
if (key == K_TAB && (f.focusdirty() || !m.is_running()))
|
|
{
|
|
TTable & note = (TTable &) ((TEdit_field &) f).browse()->cursor()->file();
|
|
note.setkey(1);
|
|
const TString16 cod(f.get());
|
|
|
|
if (cod != note.get("CODTAB"))
|
|
{
|
|
note.zero();
|
|
note.put("CODTAB", cod);
|
|
if (note.read() != NOERR)
|
|
note.zero();
|
|
}
|
|
if (m.doc().modificabile() && m.field(DLG_SAVEREC).enabled())
|
|
{
|
|
const bool reg_disabled = note.get_bool("B0");
|
|
|
|
if (reg_disabled)
|
|
message_box("Registrazione disbilitata : %s", (const char *) note.get("S0"));
|
|
m.enable(DLG_SAVEREC, !reg_disabled);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// Handler per il calcolo delle date di pagamento
|
|
bool data_hndl( TMask_field& field, KEY key )
|
|
{
|
|
TDocumento_mask& m = (TDocumento_mask &) field.mask( );
|
|
if (field.to_check(key))
|
|
{
|
|
if (m.id2pos(F_DATAINSC) >= 0)
|
|
{
|
|
TEdit_field & e = m.efield(F_DATAINSC);
|
|
e.set_dirty();
|
|
e.on_hit();
|
|
}
|
|
|
|
if (m.id2pos(F_DATACAMBIO1) >= 0)
|
|
m.set(F_DATACAMBIO1, field.get(), TRUE);
|
|
}
|
|
if (field.to_check(key,TRUE))
|
|
{
|
|
const TCodice_numerazione codnum(m.get(F_CODNUM));
|
|
if (codnum.dont_test_datadoc())
|
|
return TRUE;
|
|
|
|
TLocalisamfile doc(LF_DOC);
|
|
TDate datadoc(m.get(F_DATADOC));
|
|
|
|
doc.curr() = m.doc().head();
|
|
bool same_key = FALSE;
|
|
|
|
doc.read();
|
|
if (doc.eof() || doc.prev() == NOERR)
|
|
{
|
|
TDate dataprev = doc.get_date(DOC_DATADOC);
|
|
same_key = doc.curr().same_key(m.doc().head(), 1, 1);
|
|
if (!same_key)
|
|
{
|
|
TDate oggi(TODAY);
|
|
dataprev = oggi;
|
|
}
|
|
|
|
if (!datadoc.ok())
|
|
{
|
|
datadoc = dataprev;
|
|
field.set(dataprev.string());
|
|
}
|
|
|
|
if (same_key && datadoc < dataprev)
|
|
return field.error_box("Data documento inferiore alla data del documento precedente");
|
|
}
|
|
|
|
doc.curr() = m.doc().head();
|
|
doc.read(_isgreat);
|
|
same_key = doc.curr().same_key(m.doc().head(), 1, 1);
|
|
if (doc.good() && same_key && datadoc > doc.get_date(DOC_DATADOC))
|
|
return field.error_box("Data documento superiore alla data del documento successivo");
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// handler delle righe
|
|
|
|
void row_set_handler( TMask& m, const int field, const int index )
|
|
{
|
|
switch ( index )
|
|
{
|
|
case 1:
|
|
m.set_handler( field, dummy_hndl );
|
|
break;
|
|
default:
|
|
yesnofatal_box( FALSE, "Funzione di handler sulla riga non definita( %d ).", index );
|
|
}
|
|
}
|
|
|
|
HIDDEN TString16 curr_um;
|
|
HIDDEN real curr_fc(1.0);
|
|
|
|
bool iva_handler( TMask_field& f, KEY key )
|
|
{
|
|
TDocumento_mask & mask = (TDocumento_mask &) f.mask().get_sheet()->mask();
|
|
|
|
if (key == 0 || (key == K_ENTER && f.get().empty()))
|
|
{
|
|
const TString16 codiva = mask.condv().clifo().vendite().get(CFV_ASSFIS);
|
|
|
|
if (codiva.not_empty())
|
|
f.set(codiva);
|
|
f.check();
|
|
}
|
|
|
|
if (key == K_ENTER && f.focusdirty() && f.get().empty())
|
|
{
|
|
TMask & row_mask = f.mask();
|
|
const int r = f.mask().get_sheet()->selected() + 1;
|
|
TRiga_documento& riga = mask.doc()[r];
|
|
|
|
const int pos_ai = row_mask.id2pos(FR_ADDIVA);
|
|
bool addiva = FALSE;
|
|
|
|
if (pos_ai >= 0)
|
|
addiva = row_mask.fld(pos_ai).get() == "X"; // Controlla le righe Omaggio solo se e' settato l'addebito IVA
|
|
|
|
const bool check = riga.is_merce() || riga.is_spese() || riga.is_prestazione() ||
|
|
(riga.is_omaggio() && addiva);
|
|
|
|
if (check)
|
|
{
|
|
const int pos_p = row_mask.id2pos(FR_PREZZO);
|
|
const int pos_q = row_mask.id2pos(FR_QTA);
|
|
const bool pe = pos_p >= 0 && row_mask.fld(pos_p).enabled();
|
|
const bool qe = pos_q >= 0 && row_mask.fld(pos_q).enabled();
|
|
const bool pf = pe && row_mask.fld(pos_p).get().not_empty();
|
|
const bool qf = qe && row_mask.fld(pos_q).get().not_empty();
|
|
|
|
bool required = FALSE;
|
|
|
|
if (pf && !(qe && !qf))
|
|
required = TRUE;
|
|
|
|
if (required)
|
|
return f.error_box("Il codice IVA e' obbligatorio.");
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool codmag_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (f.to_check(key, TRUE))
|
|
{
|
|
TMask& row_mask = f.mask();
|
|
TSheet_field& sf = *row_mask.get_sheet();
|
|
TDocumento_mask& docmask = (TDocumento_mask&)sf.mask();
|
|
|
|
if (sf.column_enabled(sf.cid2index(FR_CODDEP)))
|
|
{
|
|
const int pos = row_mask.id2pos(FR_CODDEP);
|
|
const TString & val = f.get();
|
|
|
|
if (pos >= 0 && val.not_empty())
|
|
{
|
|
TTable & mag = (TTable &)((TEdit_field &) f).browse()->cursor()->file();
|
|
const TString &codmag = mag.get("CODTAB");
|
|
if (codmag != val)
|
|
{
|
|
mag.put("CODTAB", val);
|
|
if (mag.read() != NOERR)
|
|
mag.zero();
|
|
}
|
|
const bool active = mag.get_bool("B0");
|
|
row_mask.fld(pos).enable(active);
|
|
if (!active)
|
|
row_mask.fld(pos).reset();
|
|
}
|
|
}
|
|
|
|
docmask.update_giacenza();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool codmag_coll_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (f.to_check(key, TRUE))
|
|
{
|
|
TMask& row_mask = f.mask();
|
|
|
|
if (row_mask.get_sheet()->column_enabled( ((TSheet_field &)f).cid2index(FR_CODDEPC)))
|
|
{
|
|
const int pos = row_mask.id2pos(FR_CODDEPC);
|
|
const TString & val = f.get();
|
|
|
|
if (pos >= 0 && val.not_empty())
|
|
{
|
|
TTable & mag = (TTable &)((TEdit_field &) f).browse()->cursor()->file();
|
|
const TString &codmag = mag.get("CODTAB");
|
|
if (codmag != val)
|
|
{
|
|
mag.put("CODTAB", val);
|
|
if (mag.read() != NOERR)
|
|
mag.zero();
|
|
}
|
|
const bool active = mag.get_bool("B0");
|
|
row_mask.fld(pos).enable(active);
|
|
if (!active)
|
|
row_mask.fld(pos).reset();
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void upd_colli_peso_tara(TMask & m, TRectype & a)
|
|
{
|
|
real qta = m.get_real(FR_QTA) * curr_fc;
|
|
|
|
int pos = m.id2pos(FR_NCOLLI);
|
|
if (pos >= 0)
|
|
{
|
|
real ppcollo = a.get_real(ANAMAG_PPCOLLO);
|
|
if (ppcollo != ZERO)
|
|
{
|
|
real ncolli = qta / ppcollo;
|
|
|
|
ncolli.ceil(0);
|
|
m.fld(pos).set(ncolli.string());
|
|
}
|
|
}
|
|
pos = m.id2pos(FR_TARA);
|
|
if (pos >= 0)
|
|
{
|
|
const real tara = qta * a.get_real(ANAMAG_PESO);
|
|
|
|
m.fld(pos).set(tara.string());
|
|
}
|
|
pos = m.id2pos(FR_PNETTO);
|
|
if (pos >= 0)
|
|
{
|
|
const real peso = qta * a.get_real(ANAMAG_TARA);
|
|
|
|
m.fld(pos).set(peso.string());
|
|
}
|
|
}
|
|
|
|
bool codart_handler(TMask_field& f, KEY key )
|
|
{
|
|
TMask& row_mask = f.mask();
|
|
TDocumento_mask& mask = (TDocumento_mask &) row_mask.get_sheet()->mask();
|
|
TSheet_field& sh = (TSheet_field &)mask.field(F_SHEET);
|
|
const int current_doc_row = sh.selected() + 1;
|
|
|
|
if (f.to_check(key, TRUE))
|
|
{
|
|
if (f.get().not_empty())
|
|
row_mask.enable(FR_LIV1);
|
|
else
|
|
{
|
|
row_mask.reset(FR_LIV1);
|
|
row_mask.disable(FR_LIV1);
|
|
}
|
|
row_mask.field(FR_LIV1).on_hit();
|
|
}
|
|
|
|
if (key == K_TAB && (f.focusdirty() || row_mask.get(FR_CHECKED).empty()))
|
|
{
|
|
TCond_vendita & condv = mask.condv();
|
|
|
|
condv.set_testa(&mask);
|
|
condv.set_riga(&row_mask);
|
|
|
|
// TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file();
|
|
// TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file();
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
TLocalisamfile umart(LF_UMART);
|
|
|
|
// condv.set_anamag(anamag);
|
|
// condv.set_umart(umart);
|
|
|
|
TString80 codart(f.get());
|
|
anamag.setkey(1);
|
|
anamag.put(ANAMAG_CODART, codart);
|
|
bool found = anamag.read() == NOERR;
|
|
if (found)
|
|
row_mask.set(FR_CODARTMAG, codart, TRUE);
|
|
else
|
|
{
|
|
TLocalisamfile codalt(LF_CODCORR);
|
|
|
|
codalt.setkey(2);
|
|
codalt.put(CODCORR_CODARTALT, codart);
|
|
if (codalt.read() == NOERR)
|
|
{
|
|
codart = codalt.get(CODCORR_CODART);
|
|
anamag.zero();
|
|
anamag.put(ANAMAG_CODART, codart);
|
|
found = anamag.read() == NOERR;
|
|
if (found)
|
|
row_mask.set(FR_CODARTMAG, codart, TRUE);
|
|
}
|
|
}
|
|
row_mask.set(FR_CHECKED, "X");
|
|
if (!found)
|
|
row_mask.set(FR_CODARTMAG, "", TRUE);
|
|
else
|
|
{
|
|
const TString16 lingua = mask.get(F_CODLIN);
|
|
const TString codart(row_mask.get(FR_CODARTMAG));
|
|
TString desc(anamag.get("DESCR"));
|
|
|
|
if (mask.doc()[current_doc_row].is_omaggio())
|
|
{
|
|
static TString80 dicitura_omaggio("---");
|
|
|
|
if (dicitura_omaggio == "---")
|
|
{
|
|
TConfig c(CONFIG_STUDIO);
|
|
|
|
dicitura_omaggio = c.get("DESOMAGGI");
|
|
if (dicitura_omaggio.empty())
|
|
dicitura_omaggio = "(OMAGGIO)";
|
|
}
|
|
desc << " " << dicitura_omaggio;
|
|
}
|
|
if (lingua.not_empty())
|
|
{
|
|
TLocalisamfile deslin(LF_DESLIN);
|
|
|
|
deslin.setkey(2);
|
|
deslin.put(DESLIN_CODART, codart);
|
|
deslin.put(DESLIN_CODLIN, lingua);
|
|
if (deslin.read() == NOERR)
|
|
desc << '\n' << deslin.get(DESLIN_DESCR);
|
|
}
|
|
|
|
TString descest(anamag.get("DESCRAGG"));
|
|
if (descest.not_empty())
|
|
desc << "\n" << descest;
|
|
|
|
row_mask.set(FR_DESCR, desc);
|
|
|
|
umart.setkey(1);
|
|
umart.zero();
|
|
umart.put(UMART_CODART, codart);
|
|
if (umart.read(_isgteq) == NOERR && codart == umart.get(UMART_CODART))
|
|
{
|
|
curr_um = umart.get(UMART_UM);
|
|
curr_fc = umart.get_real(UMART_FC);
|
|
}
|
|
else
|
|
{
|
|
curr_um.cut(0);
|
|
curr_fc = 1.0;
|
|
}
|
|
row_mask.set(FR_UMQTA, curr_um);
|
|
upd_colli_peso_tara(row_mask, anamag.curr());
|
|
}
|
|
|
|
condv.ricerca();
|
|
const int pos = row_mask.id2pos(FR_CODIVA);
|
|
|
|
if (pos >= 0)
|
|
iva_handler(row_mask.fld(pos), 0);
|
|
}
|
|
else
|
|
if (key == K_F8 && !sh.sheet_mask().is_running())
|
|
{
|
|
static bool explode_db = 3;
|
|
static bool valcomp = FALSE;
|
|
static bool matbase = TRUE;
|
|
static TExplosion_grouping raggart = RAGGR_EXP_NONE;
|
|
static bool elrorig = FALSE;
|
|
static int livello = 1;
|
|
static int ordin = 0;
|
|
|
|
if (explode_db > 2)
|
|
{
|
|
TConfig d(CONFIG_DITTA);
|
|
|
|
explode_db = d.get_bool("EXPLODEDB", "ve");
|
|
valcomp = d.get_bool("VALCOMP", "ve");
|
|
matbase = d.get_bool("TIPOESPL", "ve");
|
|
raggart = (TExplosion_grouping) d.get_int("RAGGART", "ve");
|
|
livello = d.get_int("LIVESPL", "ve");
|
|
elrorig = d.get_bool("ELRORIG", "ve");
|
|
ordin = d.get_int("ORDDB", "ve");
|
|
}
|
|
if (explode_db && !sh.sheet_mask().is_running())
|
|
{
|
|
TCodice_articolo a(f.get());
|
|
const TCodice_um um = row_mask.get(FR_UMQTA);
|
|
real qta_fin = row_mask.get_real(FR_QTA);
|
|
TQuantita qta(a, um, qta_fin);
|
|
qta.convert2umbase();
|
|
qta_fin = qta.val();
|
|
|
|
TDistinta_tree db;
|
|
TArray components;
|
|
|
|
db.set_root(a);
|
|
|
|
const int items = db.explode(components, matbase, raggart, livello, "A", ordin);
|
|
if (items > 0)
|
|
{
|
|
|
|
TProgind pi(items, "Esplosione in corso...",FALSE, TRUE);
|
|
int row = current_doc_row;
|
|
TDocumento & doc = mask.doc();
|
|
TRiga_documento & curr_row = doc[current_doc_row];
|
|
const TString16 tiporiga(curr_row.tipo().codice());
|
|
|
|
sh.update_row(current_doc_row - 1);
|
|
curr_row.autosave(sh);
|
|
|
|
|
|
TString_array& str_arr = sh.rows_array();
|
|
|
|
for (int i = components.first(); i < items; i = components.succ(i))
|
|
{
|
|
pi.addstatus(1L);
|
|
TRiga_esplosione & r = (TRiga_esplosione &) components[i];
|
|
TRiga_documento & new_row = doc.insert_row(row + 1, tiporiga);
|
|
//sh.insert(row, FALSE);
|
|
str_arr.insert(new TToken_string, row);
|
|
|
|
TDocumento::copy_data(new_row, curr_row);
|
|
new_row.put(RDOC_CODART, r.articolo());
|
|
new_row.put(RDOC_CODARTMAG, r.articolo());
|
|
new_row.zero(RDOC_DESCR);
|
|
new_row.put(RDOC_DESCLUNGA, "X");
|
|
new_row.zero(RDOC_DESCEST);
|
|
new_row.put(RDOC_CHECKED, "");
|
|
new_row.put(RDOC_UMQTA, r.um());
|
|
new_row.put(RDOC_QTA, r.val() * qta_fin);
|
|
new_row.autoload(sh);
|
|
sh.check_row(row++);
|
|
new_row.autosave(sh);
|
|
if (!valcomp)
|
|
{
|
|
new_row.zero(RDOC_PREZZO);
|
|
new_row.autoload(sh);
|
|
}
|
|
}
|
|
if (elrorig)
|
|
{
|
|
doc.destroy_row(current_doc_row, TRUE);
|
|
sh.destroy(current_doc_row - 1, FALSE);
|
|
row--;
|
|
}
|
|
else
|
|
if (valcomp)
|
|
{
|
|
curr_row.zero(RDOC_PREZZO);
|
|
curr_row.autoload(sh);
|
|
}
|
|
sh.force_update();
|
|
sh.select(row-1);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool codartmag_handler( TMask_field& f, KEY key )
|
|
{
|
|
bool to_check = key == K_TAB && f.focusdirty();
|
|
TMask & m = f.mask();
|
|
|
|
if (!to_check)
|
|
{
|
|
TSheet_field * s = m.get_sheet();
|
|
if (s)
|
|
to_check = !s->mask().is_running();
|
|
}
|
|
if (to_check)
|
|
{
|
|
const bool artmag = f.get().not_empty();
|
|
|
|
m.show(FR_UMQTA, artmag);
|
|
m.show(FR_UMQTA2, !artmag);
|
|
|
|
TDocumento_mask& mask=(TDocumento_mask&)m.get_sheet()->mask();
|
|
mask.update_giacenza();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool liv_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (key == K_TAB && f.focusdirty() && !f.get().empty())
|
|
{
|
|
TDocumento_mask & mask=(TDocumento_mask &) f.mask().get_sheet()->mask();
|
|
const int levnum=f.dlg()-FR_LIV1+1;
|
|
// Se e' abilitato l'autoinserimento del livello di giacenza...
|
|
if (mask.livelli().autoinsert(levnum))
|
|
mask.livelli().autoinsert(levnum, f);
|
|
}
|
|
|
|
if (f.to_check(key, TRUE))
|
|
{
|
|
if (f.dlg() < FR_LIV4)
|
|
{
|
|
TMask& row_mask = f.mask();
|
|
TMask_field & next = row_mask.field(f.dlg() + 1);
|
|
if (f.get().not_empty())
|
|
next.enable();
|
|
else
|
|
{
|
|
next.reset();
|
|
next.disable();
|
|
}
|
|
next.on_hit();
|
|
}
|
|
TDocumento_mask& mask=(TDocumento_mask&)f.mask().get_sheet()->mask();
|
|
mask.update_giacenza();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void set_curr_um(const TMask & m)
|
|
{
|
|
curr_um = m.get(FR_UMQTA);
|
|
curr_fc = -1.0;
|
|
}
|
|
|
|
bool umart_handler( TMask_field& f, KEY key )
|
|
{
|
|
// Se qualcuno cerca di modificare la maschera
|
|
if ( key == K_TAB && f.focusdirty())
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask();
|
|
// TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file();
|
|
// TLocalisamfile & umart = ((TEdit_field &) f).browse()->cursor()->file();
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
TLocalisamfile umart(LF_UMART);
|
|
TCond_vendita & condv = mask.condv();
|
|
|
|
// condv.set_testa(&mask);
|
|
condv.set_riga(&row_mask);
|
|
// condv.set_anamag(anamag);
|
|
// condv.set_umart(umart);
|
|
|
|
const TString16 um(f.get());
|
|
real fc(1.0);
|
|
|
|
if (um.not_empty() && curr_um.not_empty() && um != curr_um)
|
|
{
|
|
umart.setkey(2);
|
|
umart.put(UMART_CODART, row_mask.get(FR_CODARTMAG));
|
|
umart.put(UMART_UM, um);
|
|
if (umart.read() == NOERR)
|
|
{
|
|
real qta(row_mask.get_real(FR_QTA));
|
|
fc = umart.get_real(UMART_FC);
|
|
if (curr_fc < ZERO)
|
|
{
|
|
umart.put(UMART_CODART, row_mask.get(FR_CODARTMAG));
|
|
umart.put(UMART_UM, curr_um);
|
|
if (umart.read() == NOERR)
|
|
curr_fc = umart.get_real(UMART_FC);
|
|
else
|
|
curr_fc = 1.0;
|
|
}
|
|
qta *= curr_fc;
|
|
qta /= fc;
|
|
qta.round(5);
|
|
row_mask.set(FR_QTA, qta);
|
|
qta = row_mask.get_real(FR_QTAEVASA);
|
|
qta *= curr_fc;
|
|
qta /= fc;
|
|
qta.round(5);
|
|
row_mask.set(FR_QTAEVASA, qta);
|
|
}
|
|
|
|
}
|
|
curr_um = um;
|
|
curr_fc = fc;
|
|
condv.ricerca(TRUE);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool um_handler( TMask_field& f, KEY key )
|
|
{
|
|
// Se qualcuno cerca di modificare la maschera
|
|
if ( key == K_TAB && f.focusdirty())
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask();
|
|
TTable & ums = (TTable &) ((TEdit_field &) f).browse()->cursor()->file();
|
|
|
|
const TString16 um(f.get());
|
|
real fc(1.0);
|
|
|
|
if (um.not_empty() && curr_um.not_empty() && um != curr_um)
|
|
{
|
|
ums.put("CODTAB", curr_um);
|
|
if (ums.read() == NOERR)
|
|
{
|
|
real qta(row_mask.get_real(FR_QTA));
|
|
const TString16 umsrif0(ums.get("S7"));
|
|
const real fc0 = ums.get_real("R10");
|
|
if (um == umsrif0)
|
|
fc = fc0;
|
|
else
|
|
{
|
|
ums.put("CODTAB", um);
|
|
if (ums.read() == NOERR)
|
|
{
|
|
const real fc1 = ums.get_real("R10");
|
|
const TString16 umsrif1(ums.get("S7"));
|
|
|
|
|
|
if (fc1 > ZERO)
|
|
{
|
|
if (curr_um == umsrif1)
|
|
fc = 1 / fc1;
|
|
else
|
|
if (umsrif0 == ums.get("S7"))
|
|
fc = fc0 / ums.get_real("R10");
|
|
}
|
|
}
|
|
}
|
|
qta *= fc;
|
|
qta.round(5);
|
|
row_mask.set(FR_QTA, qta);
|
|
qta = row_mask.get_real(FR_QTAEVASA);
|
|
qta *= fc;
|
|
qta.round(5);
|
|
row_mask.set(FR_QTAEVASA, qta);
|
|
}
|
|
|
|
}
|
|
curr_um = um;
|
|
curr_fc = fc;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool descr_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
{
|
|
const TString s(f.get());
|
|
if (s.find('\n') < 0)
|
|
{
|
|
// TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file();
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
anamag.zero();
|
|
anamag.setkey(2);
|
|
anamag.put(ANAMAG_DESCR, ((TZoom_field &) f).get_first_line());
|
|
if (anamag.read() == NOERR)
|
|
{
|
|
f.mask().set(FR_CODART, anamag.get(ANAMAG_CODART));
|
|
f.mask().field(FR_CODART).set_dirty();
|
|
f.mask().check_field(FR_CODART);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool qtaart_handler( TMask_field& f, KEY key )
|
|
{
|
|
// Se qualcuno cerca di modificare la maschera
|
|
if ( key == K_TAB && f.focusdirty())
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask();
|
|
// TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file();
|
|
// TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file();
|
|
TCond_vendita & condv = mask.condv();
|
|
|
|
// condv.set_testa(&mask);
|
|
condv.set_riga(&row_mask);
|
|
// condv.set_anamag(anamag);
|
|
// condv.set_umart(umart);
|
|
condv.ricerca(FALSE, TRUE);
|
|
const TString & codart = row_mask.get(FR_CODARTMAG);
|
|
|
|
if (codart.not_empty())
|
|
{
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
|
|
anamag.put(ANAMAG_CODART, codart);
|
|
if (anamag.read() == NOERR)
|
|
upd_colli_peso_tara(row_mask, anamag.curr());
|
|
}
|
|
|
|
return qta_handler(f, key);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool qta_handler( TMask_field& f, KEY key )
|
|
{
|
|
// Se qualcuno cerca di modificare la maschera
|
|
if ( key == K_TAB && f.focusdirty())
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
const real qta_evasa = row_mask.get_real(FR_QTAEVASA);
|
|
const real qta(f.get());
|
|
|
|
if (qta_evasa > 0 && qta_evasa >= qta)
|
|
{
|
|
row_mask.set(FR_RIGAEVASA, "X");
|
|
row_mask.disable(FR_RIGAEVASA);
|
|
}
|
|
else
|
|
row_mask.enable(FR_RIGAEVASA);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool qta_evasa_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
const real qta_evasa(f.get());
|
|
const real qta = row_mask.get_real(FR_QTA);
|
|
|
|
if (qta_evasa > 0 && qta_evasa >= qta)
|
|
{
|
|
row_mask.set(FR_RIGAEVASA, "X");
|
|
row_mask.disable(FR_RIGAEVASA);
|
|
}
|
|
else
|
|
row_mask.enable(FR_RIGAEVASA);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool causmag_handler( TMask_field& f, KEY key )
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
TMask& row_mask = f.mask( );
|
|
TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask();
|
|
TString16 causmag(f.get());
|
|
if (causmag.empty())
|
|
causmag = mask.get(F_CAUSMAG);
|
|
|
|
TCausale_magazzino c(cache().get("%CAU", causmag));
|
|
if (c.empty())
|
|
{
|
|
cache().discard("%CAU", causmag);
|
|
} else {
|
|
if (c.has_default_mag() && row_mask.get(FR_CODMAG).empty())
|
|
{
|
|
row_mask.set(FR_CODMAG, c.default_mag(), TRUE);
|
|
row_mask.set(FR_CODDEPC, "", TRUE);
|
|
}
|
|
if (c.has_default_dep() && row_mask.get(FR_CODDEP).empty())
|
|
row_mask.set(FR_CODDEP, c.default_dep(), TRUE);
|
|
if (!c.caus_collegata().empty())
|
|
{
|
|
c = cache().get("%CAU", c.caus_collegata());
|
|
if (c.has_default_mag() && row_mask.get(FR_CODMAGC).empty())
|
|
{
|
|
row_mask.set(FR_CODMAGC, c.default_mag(), TRUE);
|
|
row_mask.set(FR_CODDEPC, "", TRUE);
|
|
}
|
|
if (c.has_default_dep() && row_mask.get(FR_CODDEPC).empty())
|
|
row_mask.set(FR_CODDEPC, c.default_dep(), TRUE);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool sppr_handler( TMask_field& f, KEY key )
|
|
{
|
|
TMask& row_mask = f.mask();
|
|
|
|
if (key == K_TAB && (f.focusdirty() || row_mask.get(FR_DESCR).empty()))
|
|
{
|
|
const int pos = row_mask.id2pos(FR_PREZZO);
|
|
|
|
if (pos >= 0)
|
|
{
|
|
TMask & mask = row_mask.get_sheet()->mask();
|
|
TRectype & spprrec = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file().curr();
|
|
|
|
if (spprrec.get("CODTAB") == row_mask.get(FR_CODART))
|
|
{
|
|
const char tipo = spprrec.get_char("S6");
|
|
const bool qta_val_fl = tipo == 'Q';
|
|
const bool perc_fl = tipo == 'P';
|
|
|
|
short pos = row_mask.id2pos(FR_UMQTASP);
|
|
if (pos >= 0)
|
|
row_mask.fld(pos).enable(!perc_fl);
|
|
pos = row_mask.id2pos(FR_PREZZO);
|
|
if (pos >= 0)
|
|
row_mask.fld(pos).enable(!perc_fl);
|
|
pos = row_mask.id2pos(FR_SCONTO);
|
|
if (pos >= 0)
|
|
row_mask.fld(pos).enable(!perc_fl);
|
|
pos = row_mask.id2pos(FR_QTA);
|
|
if (pos >= 0)
|
|
{
|
|
row_mask.fld(pos).show(!perc_fl);
|
|
row_mask.fld(pos).enable(qta_val_fl);
|
|
}
|
|
pos = row_mask.id2pos(FR_PERCSP);
|
|
if (pos >= 0)
|
|
{
|
|
row_mask.fld(pos).show(perc_fl);
|
|
row_mask.fld(pos).enable(perc_fl);
|
|
}
|
|
|
|
if (!perc_fl)
|
|
{
|
|
const real cambio = mask.get(F_CAMBIO);
|
|
real prezzo = row_mask.get(FR_PREZZO);
|
|
const TString16 doc_valuta(mask.get(F_CODVAL));
|
|
sppr_calc(spprrec, doc_valuta, cambio, prezzo);
|
|
row_mask.set(FR_PREZZO, prezzo);
|
|
|
|
}
|
|
const int posiva = row_mask.id2pos(FR_CODIVA);
|
|
|
|
if (posiva >= 0)
|
|
iva_handler(row_mask.fld(posiva), 0);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|