a2a967d125
git-svn-id: svn://10.65.10.50/trunk@4573 c028cbd2-c16b-5b4b-a496-9718f37d4682
726 lines
24 KiB
C++
Executable File
726 lines
24 KiB
C++
Executable File
#include <relapp.h>
|
|
#include <tabutil.h>
|
|
#include <msksheet.h>
|
|
#include <recarray.h>
|
|
#include <assoc.h>
|
|
#include <checks.h>
|
|
#include <defmask.h>
|
|
#include <modaut.h>
|
|
#include "velib.h"
|
|
#include "..\mg\mglib.h"
|
|
#include "..\mg\stomag.h"
|
|
#include "ve2400.h"
|
|
|
|
|
|
// maschera dell'anagrafica di magazzino
|
|
class TMask_anamag: public TMask {
|
|
TRelation * _rel; // relazione principale
|
|
|
|
TMag_livelli * livelli_giac;// oggetto handler per i livelli di giacenza
|
|
TMag_livelli * livelli_art;// oggetto handler per i livelli di anagraficca
|
|
TMetachar * metac;
|
|
int last_annogiac;
|
|
int last_annosto;
|
|
|
|
static bool handle_codice(TMask_field &, KEY); // handler del campo codice articolo
|
|
static bool handle_livart(TMask_field &, KEY); // handler dei campi codice articolo (livelli)
|
|
static bool handle_anno(TMask_field &, KEY); // handler del campo anno delle giacenze
|
|
static bool handle_stoanno(TMask_field &, KEY); // handler del campo anno delle giacenze
|
|
static bool handle_sheet_um(TMask_field &, KEY); // handler dello sheet delle unità di misura
|
|
static bool notify_sheet_um(TSheet_field & s, int r, KEY k); // handler dello sheet delle unità di misura
|
|
static bool handle_sheet_deslin(TMask_field &, KEY); // handler dello sheet delle descrizioni in lingua
|
|
static bool handle_sheet_cod(TMask_field &, KEY); // handler dello sheet dei codici alternativi
|
|
static bool handle_sheetgiac(TMask_field &, KEY); // handler dello sheet giacenze
|
|
static bool handle_sheetstomag(TMask_field &, KEY); // handler dello sheet storico giacenze
|
|
static bool handle_sheet_um_um(TMask_field &, KEY); // handler del campo UM dello sheet delle unità di misura
|
|
static bool handle_sheet_um_price(TMask_field &, KEY); // handler del campo PREZZO e PREZZO_LORDO dello sheet delle unità di misura
|
|
|
|
static void sheetgiac_get(TSheet_field &fld_righe, int item);
|
|
static void sheetgiac_put(TSheet_field &fld_righe, int item);
|
|
static void sheetsto_get(TSheet_field &fld_righe, int item);
|
|
static void sheetsto_put(TSheet_field &fld_righe, int item);
|
|
|
|
void clear_info_sto();
|
|
bool info_sto_dirty();
|
|
public:
|
|
TMask_anamag(TRelation * rel, bool enable_mag, bool enable_artliv);
|
|
virtual ~TMask_anamag();
|
|
|
|
};
|
|
|
|
|
|
// costruttore della maschera anagrafica di magazzino
|
|
TMask_anamag::TMask_anamag(TRelation * rel, bool enable_mag, bool enable_artliv) : TMask("ve2400")
|
|
{
|
|
_rel=rel;
|
|
// imposta il riconoscimento dei caratteri del formato dell'ultima parte dell'articolo
|
|
TString80 format("");
|
|
TTable _tabfca("FCA");
|
|
if (_tabfca.last()==NOERR) {
|
|
format = _tabfca.get("S1");
|
|
}
|
|
metac = new TMetachar(format);
|
|
// imposta il puntatore al gestore livelli giacenze
|
|
livelli_giac= new TMag_livelli("FCG");
|
|
livelli_art= new TMag_livelli("FCA");
|
|
// imposta il valore dell'anno per le giacenze
|
|
last_annogiac=-1;
|
|
last_annosto=-1;
|
|
|
|
set_handler(F_ANNO, handle_anno);
|
|
set_handler(F_STOANNO, handle_stoanno);
|
|
set_handler(F_SHEETUM, handle_sheet_um);
|
|
((TSheet_field &)field(F_SHEETUM)).set_notify(notify_sheet_um);
|
|
set_handler(F_SHEETDESLIN, handle_sheet_deslin);
|
|
set_handler(F_SHEETCOD, handle_sheet_cod);
|
|
set_handler(F_SHEETGIAC, handle_sheetgiac);
|
|
((TSheet_field &)field(F_SHEETGIAC)).set_userget(sheetgiac_get);
|
|
((TSheet_field &)field(F_SHEETGIAC)).set_userput(sheetgiac_put);
|
|
set_handler(F_SHEETSTOMAG, handle_sheetstomag);
|
|
((TSheet_field &)field(F_SHEETSTOMAG)).set_userget(sheetsto_get);
|
|
((TSheet_field &)field(F_SHEETSTOMAG)).set_userput(sheetsto_put);
|
|
|
|
|
|
TSheet_field &f= (TSheet_field &)field(F_SHEETUM);
|
|
TMask &fm= f.sheet_mask();
|
|
fm.set_handler(FS_CODUM, handle_sheet_um_um);
|
|
fm.set_handler(FS_PREZZO, handle_sheet_um_price);
|
|
fm.set_handler(FS_PREZZO_LORDO, handle_sheet_um_price);
|
|
|
|
// Abilita la pagina delle giacenze
|
|
if (enable_mag)
|
|
{
|
|
enable_page(4,TRUE);
|
|
// setta i campi della maschera
|
|
// per la pagina giacenze
|
|
TSheet_field &fld_giac= (TSheet_field &)field(F_SHEETGIAC);
|
|
// disabilita le colonne quando non sono utilizzati i livelli di giacenza
|
|
for (int i=0; i<4; i++)
|
|
{
|
|
if (livelli_giac->enabled(1+i)) {
|
|
fld_giac.sheet_mask().field(F_LIV1+i).show();
|
|
fld_giac.set_column_header(fld_giac.cid2index(F_LIV1+i),livelli_giac->name(1+i));
|
|
fld_giac.sheet_mask().field(F_LIV1+i).set_prompt(livelli_giac->name(1+i));
|
|
} else {
|
|
fld_giac.sheet_mask().field(F_LIV1+i).hide();
|
|
fld_giac.delete_column(fld_giac.cid2index(F_LIV1+i));
|
|
}
|
|
}
|
|
// disabilita la colonna numero distinte
|
|
if (0) {
|
|
fld_giac.delete_column(fld_giac.cid2index(F_NDIST));
|
|
fld_giac.sheet_mask().field(F_NDIST).enable(FALSE);
|
|
}
|
|
// abilita la gestione delle ubicazioni (manuale/su tabella)
|
|
if (1) {
|
|
fld_giac.sheet_mask().field(F_UBICAZ).show(FALSE);
|
|
fld_giac.sheet_mask().field(F_UBICAZD).show(FALSE);
|
|
fld_giac.sheet_mask().field(F_UBICAZ2).show(TRUE);
|
|
} else {
|
|
fld_giac.sheet_mask().field(F_UBICAZ).show(TRUE);
|
|
fld_giac.sheet_mask().field(F_UBICAZD).show(TRUE);
|
|
fld_giac.sheet_mask().field(F_UBICAZ2).show(FALSE);
|
|
}
|
|
} else {
|
|
enable_page(4,FALSE);
|
|
}
|
|
// abilita la visualizzazione dei campi distinti per i livelli articolo
|
|
if (enable_artliv)
|
|
{
|
|
field(F_CODART).hide();
|
|
field(F_GCA).hide();
|
|
|
|
for (int i=0; i<3; i++)
|
|
{
|
|
// versione con campi predefiniti sulla maschera
|
|
if (livelli_art->enabled(1+i)) {
|
|
field(F_LIVART1+i).show();
|
|
field(F_LIVART1+livelli_giac->last_level()-1).check_type(1+i==livelli_art->last_level() ? CHECK_NONE : CHECK_REQUIRED);
|
|
((TEdit_field&)field(F_LIVART1+livelli_giac->last_level()-1)).set_width(livelli_art->code_lenght(1+i));
|
|
set_handler(F_LIVART1+i, handle_livart);
|
|
} else {
|
|
field(F_LIVART1+i).hide();
|
|
field(F_LIVART1+livelli_giac->last_level()-1).check_type(CHECK_NONE);
|
|
}
|
|
}
|
|
} else {
|
|
if (livelli_art->enabled())
|
|
{
|
|
set_handler(F_CODART, handle_codice);
|
|
for (int i=0; i<9; i++)
|
|
field(F_LIVART1+i).hide();
|
|
} else
|
|
if (!livelli_art->enabled(2))
|
|
// .. nasconde il pulsante dei livelli
|
|
field(F_GCA).hide();
|
|
}
|
|
}
|
|
|
|
void TMask_anamag::sheetsto_put(TSheet_field &sheet_sto, int item)
|
|
{
|
|
if (item>1) return;
|
|
TMask_anamag & m=(TMask_anamag & )sheet_sto.mask();
|
|
TRectype & first_rec=sheet_sto.record()->row(1,TRUE);
|
|
first_rec.put(STOMAG_ULTCOS1,m.get_real(F_STOULTCOS1 ));
|
|
first_rec.put(STOMAG_ULTCOS2,m.get_real(F_STOULTCOS2 ));
|
|
first_rec.put(STOMAG_COSTSTD,m.get_real(F_STOCOSTOSTD ));
|
|
first_rec.put(STOMAG_COSTOMEDIO,m.get_real(F_STOCOSTOMEDIO ));
|
|
first_rec.put(STOMAG_CATVEN,m.get(F_STOCATVEN ));
|
|
first_rec.put(STOMAG_CODLISTINO,m.get(F_STOCODLIST));
|
|
first_rec.put(STOMAG_PRZLIST,m.get(F_STOPREZZOLIST ));
|
|
}
|
|
|
|
void TMask_anamag::sheetsto_get(TSheet_field &sheet_sto, int item)
|
|
{
|
|
if (item>1) return;
|
|
TMask_anamag & m=(TMask_anamag &) sheet_sto.mask();
|
|
TRectype & first_rec=sheet_sto.record()->row(1,TRUE);
|
|
m.set(F_STOULTCOS1, first_rec.get_real(STOMAG_ULTCOS1));
|
|
m.set(F_STOULTCOS2, first_rec.get_real(STOMAG_ULTCOS2 ));
|
|
m.set(F_STOCOSTOSTD, first_rec.get_real( STOMAG_COSTSTD ));
|
|
m.set(F_STOCOSTOMEDIO, first_rec.get_real(STOMAG_COSTOMEDIO));
|
|
m.set(F_STOCATVEN , first_rec.get(STOMAG_CATVEN));
|
|
m.set(F_STOCODLIST , first_rec.get(STOMAG_CODLISTINO));
|
|
m.set(F_STOPREZZOLIST ,first_rec.get(STOMAG_PRZLIST));
|
|
}
|
|
|
|
bool TMask_anamag::info_sto_dirty()
|
|
{
|
|
return
|
|
field(F_STOULTCOS1).dirty() ||
|
|
field(F_STOULTCOS2).dirty() ||
|
|
field(F_STOCOSTOSTD).dirty() ||
|
|
field(F_STOCOSTOMEDIO).dirty()||
|
|
field(F_STOCATVEN ).dirty()||
|
|
field(F_STOCODLIST).dirty()||
|
|
field(F_STOPREZZOLIST).dirty();
|
|
}
|
|
|
|
|
|
void TMask_anamag::clear_info_sto()
|
|
{
|
|
reset(F_STOULTCOS1);
|
|
reset(F_STOULTCOS2);
|
|
reset(F_STOCOSTOSTD);
|
|
reset(F_STOCOSTOMEDIO);
|
|
reset(F_STOCATVEN );
|
|
reset(F_STOCODLIST);
|
|
reset(F_STOPREZZOLIST);
|
|
}
|
|
|
|
|
|
TMask_anamag::~TMask_anamag()
|
|
{
|
|
delete livelli_art;
|
|
delete livelli_giac;
|
|
}
|
|
|
|
|
|
// HANDLER DEL CODICE: controlla la corrispondenza al formato previsto
|
|
bool TMask_anamag::handle_codice(TMask_field &fld, KEY k)
|
|
{
|
|
TMask_anamag &mask=(TMask_anamag &)fld.mask();
|
|
|
|
|
|
TString codepart;
|
|
if (k == K_TAB && !fld.get().blank()) {
|
|
int l;
|
|
TTable _tabgrp("GCA");
|
|
for (l=1; l<mask.livelli_art->last_level(); l++) {
|
|
codepart="";
|
|
codepart << l << mask.livelli_art->unpack_grpcode(fld.get(),l);
|
|
_tabgrp.zero();
|
|
_tabgrp.put("CODTAB", codepart);
|
|
if (_tabgrp.read()!=NOERR) {
|
|
fld.error_box("'%s' non appartiene a '%s'",(const char *)codepart.mid(1),(const char *)mask.livelli_art->name(l));
|
|
return(FALSE);
|
|
}
|
|
}
|
|
codepart=mask.livelli_art->unpack_grpcode(fld.get(),mask.livelli_art->last_level());
|
|
if (codepart.blank()) {
|
|
fld.error_box("Il codice articolo non può essere vuoto");
|
|
return(FALSE);
|
|
}
|
|
if (!mask.metac->recognized(codepart)) {
|
|
fld.error_box("Il codice articolo non corrisponde al formato previsto \n('%s' ?? '%s')",(const char *)codepart,(const char *)mask.metac->language());
|
|
return(FALSE);
|
|
}
|
|
}
|
|
return(TRUE);
|
|
}
|
|
|
|
// HANDLER DEL CODICE: controlla la corrispondenza al formato previsto
|
|
bool TMask_anamag::handle_livart(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_TAB && fld.focusdirty())
|
|
{
|
|
TMask_anamag & m=(TMask_anamag & )fld.mask();
|
|
TString s(m.field(F_CODART).get());
|
|
m.livelli_art->pack_grpcode(s,fld.get(),fld.dlg()-F_LIVART1+1);
|
|
m.field(F_CODART).set(s);
|
|
if (fld.dlg()-F_LIVART1+1==m.livelli_art->last_level() && fld.get().blank()) {
|
|
|
|
fld.error_box("Il codice articolo non può essere lasciato in bianco");
|
|
return FALSE;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_anno(TMask_field &fld, KEY k)
|
|
{
|
|
TMask_anamag &mask=(TMask_anamag &)fld.mask();
|
|
|
|
|
|
if (k == K_TAB)
|
|
{
|
|
TSheet_field &fld_giac= (TSheet_field &)mask.field(F_SHEETGIAC);
|
|
|
|
if (mask.last_annogiac>0 && mask.last_annogiac!=fld.mask().get_int(F_ANNO)) {
|
|
if (fld_giac.dirty() && handle_sheetgiac(fld_giac,K_ENTER)) {
|
|
if (fld.yesno_box("Vuoi salvare le righe di giacenza per l'anno %d",mask.last_annogiac )) {
|
|
fld_giac.autosave(*mask._rel);
|
|
fld_giac.record()->rewrite();
|
|
}
|
|
}
|
|
mask.field(F_ANNORIF).set(fld.get());
|
|
// rilegge le giacenze relative a quell'anno ed aggiorna il layout
|
|
fld_giac.record()->read(*fld_giac.putkey(*mask._rel));
|
|
fld_giac.autoload(*mask._rel);
|
|
fld_giac.force_update();
|
|
}
|
|
mask.last_annogiac=mask.get_int(F_ANNO);
|
|
}
|
|
return(TRUE);
|
|
}
|
|
|
|
|
|
bool TMask_anamag::handle_stoanno(TMask_field &fld, KEY k)
|
|
{
|
|
TMask_anamag &mask=(TMask_anamag &)fld.mask();
|
|
|
|
if (k == K_TAB)
|
|
{
|
|
TSheet_field &fld_stomag= (TSheet_field &)fld.mask().field(F_SHEETSTOMAG);
|
|
|
|
if (mask.last_annosto>0 && mask.last_annosto!=fld.mask().get_int(F_STOANNO))
|
|
{
|
|
if ((mask.field(F_SHEETSTOMAG).dirty() || mask.info_sto_dirty()) &&
|
|
handle_sheetstomag(fld_stomag,K_ENTER) &&
|
|
fld_stomag.items()>0 )
|
|
{
|
|
if (fld.yesno_box("Vuoi salvare le righe di storico per l'anno %d",mask.last_annosto)) {
|
|
fld_stomag.autosave(*mask._rel);
|
|
fld_stomag.record()->write(TRUE);
|
|
}
|
|
}
|
|
mask.field(F_STOANNORIF).set(fld.get());
|
|
// rilegge lo storico relativo a quell'anno ed aggiorna il layout
|
|
mask.clear_info_sto();
|
|
fld_stomag.record()->read(*fld_stomag.putkey(*mask._rel));
|
|
fld_stomag.autoload(*mask._rel);
|
|
fld_stomag.force_update();
|
|
}
|
|
mask.last_annosto=mask.get_int(F_STOANNO);
|
|
}
|
|
return(TRUE);
|
|
}
|
|
|
|
|
|
bool TMask_anamag::handle_sheet_um(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_ENTER)
|
|
{
|
|
TSheet_field &f= (TSheet_field &)fld; // typecast del campo al suo sheet corrispondente
|
|
const int items = f.items();
|
|
if (items > 0)
|
|
{
|
|
TAssoc_array v; // istanzia l'hash table per il controllo di univocità
|
|
for (int i= 0; i<items; i++)
|
|
{
|
|
const TString16 um(f.cell(i,0));
|
|
|
|
if (um.empty())
|
|
return error_box("Le unita' di misura non possono essere vuote");
|
|
if (v.add(um))
|
|
return error_box("Le unità di misura devono essere diverse tra loro"); // aggiunge all'hash table l'elemento 0 (primo) della riga corrente e controlla che non esista già
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::notify_sheet_um(TSheet_field &s, int r, KEY k)
|
|
{
|
|
if (k == K_TAB)
|
|
s.sheet_mask().enable(DLG_DELREC, r > 0);
|
|
TMask_field &mf=s.sheet_mask().field(DLG_DELREC);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheet_deslin(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_ENTER)
|
|
{
|
|
TSheet_field &f= (TSheet_field &)fld; // typecast del campo al suo sheet corrispondente
|
|
const int items = f.items();
|
|
|
|
if (items > 0)
|
|
{
|
|
TAssoc_array v; // istanzia l'hash table per il controllo di univocità
|
|
|
|
for (int i= 0; i < items; i++)
|
|
{
|
|
const TString16 codlin(f.cell(i,0));
|
|
|
|
if (codlin.empty())
|
|
return error_box("I codici lingua non possono essere vuoti");
|
|
if (v.add(codlin))
|
|
return error_box("I codici lingua devono essere diversi tra loro"); // aggiunge all'hash table l'elemento 0 (primo) della riga corrente e controlla che non esista già
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheet_cod(TMask_field &fld, KEY k)
|
|
{
|
|
if (k==K_ENTER)
|
|
{
|
|
TSheet_field &f= (TSheet_field &)fld; // typecast del campo al suo sheet corrispondente
|
|
const int items = f.items();
|
|
|
|
if (items > 0)
|
|
{
|
|
TMask &m= fld.mask(); // prende la maschere d'origine del campo
|
|
TAssoc_array v; // istanzia l'hash table per il controllo di univocità
|
|
|
|
v.add(m.get(F_CODART)); // aggiunge all'hash table il codice articolo originale
|
|
for (int i= 0; i< items; i++)
|
|
{
|
|
const TString80 codart(f.cell(i,0));
|
|
|
|
if (codart.empty())
|
|
return error_box("I codici alternativi non possono essere vuoti");
|
|
if (v.add(codart))
|
|
return error_box("I codici alternativi devono essere diversi tra loro e dal codice dell'articolo"); // aggiunge all'hash table l'elemento 0 (primo) della riga corrente e controlla che non esista già
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheetgiac(TMask_field &fld, KEY k)
|
|
{
|
|
if (k==K_ENTER)
|
|
{
|
|
TSheet_field &f=(TSheet_field &)fld;
|
|
const int items = f.items();
|
|
|
|
if (items > 0)
|
|
{
|
|
TMask &m= f.mask(); // prende la maschere d'origine del campo
|
|
TAssoc_array v; // istanzia l'hash table per il controllo di univocità
|
|
|
|
for (int i= 0; i< items; i++)
|
|
{
|
|
TString codgiac(f.cell(i,F_CODMAG-FIRST_FIELD));
|
|
codgiac << f.cell(i,F_CODDEP-FIRST_FIELD);
|
|
codgiac << f.cell(i,F_LIV1-FIRST_FIELD);
|
|
codgiac << f.cell(i,F_LIV2-FIRST_FIELD);
|
|
codgiac << f.cell(i,F_LIV3-FIRST_FIELD);
|
|
codgiac << f.cell(i,F_LIV4-FIRST_FIELD);
|
|
|
|
if (codgiac.empty())
|
|
return error_box("I codici delle giacenze non possono essere vuoti");
|
|
// aggiunge all'hash table l'elemento 0 (primo) della riga corrente e controlla che non esista già
|
|
if (v.add(codgiac))
|
|
return error_box("Esistono due righe con lo stesso codice di giacenza");
|
|
// ordina le righe per livello+codmag
|
|
}
|
|
// ordina le righe per livello+codmag
|
|
// f.rows_array().sort();
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheetstomag(TMask_field &fld, KEY k)
|
|
{
|
|
if (k==K_ENTER)
|
|
{
|
|
TSheet_field & f=(TSheet_field &)fld;
|
|
const int items = f.items();
|
|
|
|
if (items > 0)
|
|
{
|
|
TMask &m= f.mask(); // prende la maschere d'origine del campo
|
|
TAssoc_array v; // istanzia l'hash table per il controllo di univocità
|
|
for (int i= 0; i< items; i++)
|
|
{
|
|
TString codeser(f.cell(i,F_STOANNOES-FIRST_FIELD));
|
|
if (codeser.empty())
|
|
return error_box("I codici degli esercizi non possono essere vuoti");
|
|
// aggiunge all'hash table l'elemento 0 (primo) della riga corrente e controlla che non esista già
|
|
if (v.add(codeser))
|
|
return error_box("La composizione delle rimananenze deve far riferimento a esercizi tutti diversi tra loro");
|
|
}
|
|
}
|
|
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheet_um_um(TMask_field &fld, KEY k)
|
|
{
|
|
if (fld.focusdirty() && k == K_TAB)
|
|
{
|
|
TMask &m = fld.mask(); // prende la maschera d'origine del campo (maschera dello sheet)
|
|
const TString16 curr_um(fld.get()); // prende il contenuto del campo corrente (unità di misura corrente)
|
|
|
|
if (curr_um.not_empty()) // se il codice dell'unità di misura è vuoto non viene fatto alcun calcolo
|
|
{
|
|
TSheet_field *f= m.get_sheet(); // prende lo sheet d'origine della maschera del campo
|
|
|
|
CHECK(f != NULL, "Il puntatore allo sheet è nullo");
|
|
if (f->selected() > 0)
|
|
{
|
|
|
|
// ALGORITMO DI PRECALCOLO DEL RAPPORTO DELLE UNITA' DI MISURA NELLO SHEET
|
|
//
|
|
// SHEET:
|
|
// -----
|
|
// riga u.m. f.c.
|
|
// 1) KM 1 -> kilometri (you), riferiti al metro (your) con f.c. 1000 (your_fc)
|
|
// ... ... ...
|
|
// ...) MM X -> millimetri (me), riferiti al metro (my) con f.c. 0,001 (my_fc)
|
|
//
|
|
// se (your==my) allora X=(my_fc/your_fc) ...chiaro, no!? :-)
|
|
|
|
TTable t("%UMS");
|
|
real x; // fattore di conversione dell'unità di misura corrente
|
|
const TString16 first_um(f->row(0).get(0)); // prende l'unità di misura di rapporto (dalla prima linea dello sheet)
|
|
|
|
t.zero();
|
|
t.put("CODTAB", curr_um);
|
|
if (t.read() == NOERR)
|
|
{
|
|
const TString16 rif_um(t.get("S7")); // prende l'unità di misura di riferimento dell'unità di misura corrente
|
|
x = t.get_real("R10"); // prende il suo fattore di conversione
|
|
|
|
if (rif_um != first_um)
|
|
{
|
|
t.zero();
|
|
t.put("CODTAB", first_um);
|
|
if (t.read() == NOERR)
|
|
{
|
|
TString16 first_um_rif(t.get("S7")); // prende l'unità di misura di riferimento dell'unità di misura di rapporto
|
|
const real first_um_rif_fc(t.get_real("R10")); // prende il suo fattore di conversione
|
|
if (first_um_rif == rif_um)
|
|
{
|
|
x /= first_um_rif_fc; // calcola il rapporto tra i fattori di conversione
|
|
x.round(5); // arrotonda il risultato a 5 decimali
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (x == ZERO)
|
|
x = 1.00;
|
|
m.set(FS_FCUM, x); // il risultato viene scritto nel campo del fattore di conversione
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMask_anamag::handle_sheet_um_price(TMask_field &f, KEY k)
|
|
{
|
|
if (f.to_check(k,TRUE))
|
|
{
|
|
TMask& m = f.mask();
|
|
TString codiva= m.get_sheet()->mask().get(F_CODIVA);// recuper il codice IVA dalla maschera principale
|
|
real netto = 0.0;
|
|
real lordo = 0.0;
|
|
|
|
if (f.dlg() == FS_PREZZO)
|
|
{
|
|
netto = real(m.get(FS_PREZZO));
|
|
lordo = netto2lordo(netto,codiva);
|
|
m.set(FS_PREZZO_LORDO,lordo.string());
|
|
}
|
|
else
|
|
{
|
|
lordo = real(m.get(FS_PREZZO_LORDO));
|
|
real prec_lordo = lordo;
|
|
netto = lordo2netto(lordo,codiva);
|
|
if (lordo != prec_lordo)
|
|
{
|
|
warning_box("Scorporando l'iva dal prezzo lordo si e' dovuto\n"
|
|
"correggere quest'ultimo a causa di arrotondamenti.");
|
|
m.set(FS_PREZZO_LORDO,lordo.string());
|
|
}
|
|
m.set(FS_PREZZO,netto.string());
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
void TMask_anamag::sheetgiac_get(TSheet_field &fld_righe, int item)
|
|
{
|
|
TMask_anamag &m=(TMask_anamag &)fld_righe.mask();
|
|
// prende il record della riga corrente dal record array
|
|
TRectype &rec= fld_righe.record()->row(item, TRUE);
|
|
TToken_string &row= fld_righe.row(item-1);
|
|
// codici di livello
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,1),fld_righe.cid2index(F_LIV1) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,2),fld_righe.cid2index(F_LIV2) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,3),fld_righe.cid2index(F_LIV3) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,4),fld_righe.cid2index(F_LIV4) );
|
|
}
|
|
|
|
|
|
// item varies from 1 to items()
|
|
void TMask_anamag::sheetgiac_put(TSheet_field &fld_righe, int item)
|
|
{
|
|
TMask_anamag &m=(TMask_anamag &)fld_righe.mask();
|
|
TToken_string &row= fld_righe.row(item-1);
|
|
|
|
TRectype &recrighe= fld_righe.record()->row(item, TRUE);
|
|
// codici livello
|
|
if (m.livelli_giac->enabled()) {
|
|
TString16 packedcode;
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV1)),1);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV2)),2);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV3)),3);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV4)),4);
|
|
recrighe.put("LIVELLO", packedcode);
|
|
}
|
|
}
|
|
|
|
|
|
// ******************************
|
|
// applicazione
|
|
class TAnagrafica_magazzino : public TRelation_application {
|
|
TMask_anamag *_msk; // maschera principale
|
|
TRelation *_rel; // relazione principale di un solo file (anagrafiche di magazzino)
|
|
TRecord_array *_linee_rec_um; // record array di accoppiamento delle unità di misura
|
|
TRecord_array *_linee_rec_deslin; // record array di accoppiamento delle descrizioni in lingua con il primo sheet
|
|
TRecord_array *_linee_rec_cod; // record array di accoppiamento delle codici corrispondenti con il secondo sheet
|
|
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
virtual TMask *get_mask(int) { return _msk; }
|
|
virtual bool changing_mask(int) { return FALSE; }
|
|
virtual TRelation *get_relation() const { return _rel; }
|
|
virtual void init_insert_mode(TMask &);
|
|
|
|
virtual int read(TMask& m);
|
|
virtual bool remove();
|
|
virtual int write(const TMask& m);
|
|
virtual int rewrite(const TMask& m);
|
|
|
|
public:
|
|
TAnagrafica_magazzino() {}
|
|
virtual ~TAnagrafica_magazzino() {}
|
|
};
|
|
|
|
inline TAnagrafica_magazzino& app() { return (TAnagrafica_magazzino&) main_app(); }
|
|
|
|
bool TAnagrafica_magazzino::user_create()
|
|
{
|
|
|
|
// crea l'oggetto per i parametri di livello giacenza
|
|
// apre la maschera e dispone gli sheet
|
|
_rel= new TRelation(LF_ANAMAG);
|
|
_linee_rec_um= new TRecord_array(LF_UMART, "NRIGA");
|
|
_linee_rec_deslin= new TRecord_array(LF_DESLIN, "NRIGA");
|
|
_linee_rec_cod= new TRecord_array(LF_CODCORR, "NRIGA");
|
|
|
|
_msk= new TMask_anamag(_rel,has_module(MGAUT),FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TAnagrafica_magazzino::user_destroy()
|
|
{
|
|
delete _linee_rec_cod;
|
|
delete _linee_rec_deslin;
|
|
delete _linee_rec_um;
|
|
|
|
delete _rel;
|
|
delete _msk;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
int TAnagrafica_magazzino::read(TMask& m)
|
|
{
|
|
int err= TRelation_application::read(m);
|
|
if (err == NOERR)
|
|
{
|
|
// LETTURA SHEET STORICO MAGAZZINO IN AUTOMATICO
|
|
/*TSheet_field &fld_stomag= (TSheet_field &)m.field(F_SHEETSTOMAG); // prende il sheet delle unità di misura
|
|
fld_stomag.sheet_mask().field(F_STOCODART).set(m.field(F_CODART).get()); */
|
|
|
|
// *****************************
|
|
// LETTURA SHEET UNITA' DI MISURA
|
|
|
|
TSheet_field &fld_um= (TSheet_field &)m.field(F_SHEETUM); // prende il sheet delle unità di misura
|
|
if (fld_um.items() == 0)
|
|
((TToken_string &)fld_um.row(0)) = "|1"; // aggiunge una riga allo sheet
|
|
else
|
|
((TToken_string &)fld_um.row(0)).add("1",1); // forza la prima unita' di misura a 1
|
|
fld_um.disable_cell(0, 1); // mette in sola lettura il secondo campo della prima riga (il fattore di conversione della prima U.M. è fisso a 1)
|
|
fld_um.force_update(0); // aggiorna lo stato della riga 0
|
|
|
|
// preleva le info di storico (prezzi, ultcosti, ecc)
|
|
} // no errors in TRelation_application::read(m);
|
|
return err;
|
|
}
|
|
|
|
bool TAnagrafica_magazzino::remove()
|
|
|
|
{
|
|
return TRelation_application::remove();
|
|
}
|
|
|
|
int TAnagrafica_magazzino::write(const TMask& m)
|
|
{
|
|
return TRelation_application::write(m);
|
|
}
|
|
|
|
int TAnagrafica_magazzino::rewrite(const TMask& m)
|
|
{
|
|
return TRelation_application::rewrite(m);
|
|
}
|
|
|
|
void TAnagrafica_magazzino::init_insert_mode(TMask &m)
|
|
{
|
|
TSheet_field &f= (TSheet_field &)m.field(F_SHEETUM);
|
|
if (f.items()==0)
|
|
{
|
|
((TToken_string &)f.row(0)) = "|1"; // aggiunge una riga allo sheet
|
|
f.disable_cell(0, 1); // mette in sola lettura il secondo campo della prima riga (il fattore di conversione della prima U.M. è fisso a 1)
|
|
f.force_update(0); // aggiorna lo stato della riga 0
|
|
}
|
|
}
|
|
|
|
// ************************
|
|
//
|
|
int ve2400(int argc, char* argv[])
|
|
{
|
|
TAnagrafica_magazzino a;
|
|
|
|
a.run(argc, argv, "Anagrafica di magazzino");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|