71b5ac0e10
Files correlati :ve0.exe Ricompilazione Demo : [ ] Commento :sistemata la nascita di righe vuote al posto di quelle cancellate nei documenti (2a puntata) git-svn-id: svn://10.65.10.50/trunk@14848 c028cbd2-c16b-5b4b-a496-9718f37d4682
3109 lines
77 KiB
C++
Executable File
3109 lines
77 KiB
C++
Executable File
#include <automask.h>
|
||
#include <colmask.h>
|
||
#include <dongle.h>
|
||
#include <execp.h>
|
||
#include <modaut.h>
|
||
#include <sheet.h>
|
||
#include <smartcard.h>
|
||
#include <tabutil.h>
|
||
#include <tree.h>
|
||
#include <postman.h>
|
||
#include <urldefid.h>
|
||
#include <utility.h>
|
||
|
||
#include "velib04.h"
|
||
#include "vepriv.h"
|
||
#include "verig.h"
|
||
|
||
#include "ve0100.h"
|
||
#include "ve0100b1.h"
|
||
#include "ve0100C.h"
|
||
#include "ve0100o.h"
|
||
#include "veuml.h"
|
||
#include "veuml1.h"
|
||
#include "veini.h"
|
||
#include "sconti.h"
|
||
|
||
class TOriginal_row_mask : public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
virtual bool on_key(KEY key);
|
||
|
||
public:
|
||
TOriginal_row_mask() : TAutomask("ve0100c") { }
|
||
};
|
||
|
||
bool TOriginal_row_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
bool TOriginal_row_mask::on_key(KEY key)
|
||
{
|
||
if (key == K_SHIFT + K_F12)
|
||
enable(-1);
|
||
return TAutomask::on_key(key);
|
||
}
|
||
|
||
|
||
TDocumento_mask::TDocumento_mask(const char* td)
|
||
: TVariable_mask(), _progs_page(-1),
|
||
_condv(NULL), _smartcard(NULL),
|
||
_last_cdc_dlg(-1), _last_cms_dlg(-1)
|
||
|
||
{
|
||
CHECK(strlen(td) <= 4, "TDocumento_mask(TipoDocumento) not (MaskName)");
|
||
|
||
{
|
||
TMagazzini m;
|
||
|
||
_ges_mag = m.gestmag();
|
||
_ges_dep = m.gestdep();
|
||
_std_mag = m.standardmag();
|
||
_std_dep = m.standarddep();
|
||
}
|
||
_doc.set_tipo(td);
|
||
const TString16 mname = _doc.tipo().mask_name();
|
||
read_mask(mname, 0, MAX_PAGES);
|
||
|
||
_sheet = &sfield(F_SHEET);
|
||
_sheet->set_handler( ss_handler );
|
||
_sheet->set_notify( ss_notify );
|
||
_sheet->set_append(FALSE);
|
||
|
||
TList_field& listbox = (TList_field&)field(F_LBTIPORIGA);
|
||
|
||
TTipo_documento& tdoc = (TTipo_documento&)_doc.tipo();
|
||
TToken_string& keys = (TToken_string&)tdoc.keys_descrs()[0];
|
||
TToken_string& descrs = (TToken_string&)tdoc.keys_descrs()[1];
|
||
listbox.replace_items(keys, descrs);
|
||
|
||
// Controlla se deve generare la pagina di analitica
|
||
if (dongle().active(CAAUT) || dongle().active(CMAUT))
|
||
insert_anal_page();
|
||
|
||
configura_sheet(*_sheet);
|
||
|
||
((TVariable_sheet_field*)_sheet)->set_getmask( ss_getmask );
|
||
if (_doc.tipo().clifo_optional())
|
||
{
|
||
field(F_CODCF).check_type(CHECK_NORMAL);
|
||
field(F_RAGSOC).check_type(CHECK_NORMAL);
|
||
}
|
||
|
||
int i;
|
||
for (i = fields() - 1; i >= 0; i--)
|
||
{
|
||
TMask_field & f = fld(i);
|
||
if (f.is_operable())
|
||
f.set_handler(universal_handler);
|
||
}
|
||
|
||
set_field_handler( F_OCCASEDIT, occas_handler );
|
||
set_field_handler( F_CODCF, clifo_handler );
|
||
set_field_handler( F_CODPAG, condpag_hndl );
|
||
set_field_handler( F_DATAINSC, condpag_hndl );
|
||
set_field_handler( F_CODNOTE, note_hndl );
|
||
set_field_handler( F_DATADOC, data_hndl );
|
||
set_field_handler( F_CODLIST, codlist_handler );
|
||
set_field_handler( F_CODLIST1, codlist_handler );
|
||
set_field_handler( F_CODCONT, codcont_handler );
|
||
set_field_handler( F_CODCONT1, codcont_handler );
|
||
set_field_handler( F_CODCAMP, codcamp_handler );
|
||
set_field_handler( F_CODVAL, codval_handler );
|
||
set_field_handler( F_CODVAL1, codval_handler );
|
||
set_field_handler( F_NUMDOCRIF, datadocrif_handler);
|
||
set_field_handler( F_DATADOCRIF, datadocrif_handler);
|
||
set_handler( DLG_ELABORA, elabora_handler );
|
||
set_handler( DLG_PRINT, print_handler );
|
||
|
||
const TString_array& handlers = tdoc.handlers();
|
||
int numhandler = handlers.items();
|
||
|
||
for (i = 0; i < numhandler; i ++ )
|
||
{
|
||
TToken_string& riga = (TToken_string&) handlers[i];
|
||
|
||
user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) );
|
||
}
|
||
|
||
_livelli_giac = new TCodgiac_livelli;
|
||
|
||
for (i = 4; i > 0; i--)
|
||
{
|
||
const short pos = _sheet->cid2index(FR_LIV1 + i -1);
|
||
if (_livelli_giac->enabled(i))
|
||
{
|
||
const TString & header = _livelli_giac->name(i);
|
||
const int len = header.len() + 1;
|
||
const int f_len = _livelli_giac->code_length(i);
|
||
_sheet->set_column_header(pos, header);
|
||
_sheet->set_column_width(pos, (len > f_len ? len : f_len) * 8);
|
||
}
|
||
else
|
||
{
|
||
_sheet->sheet_mask().hide(FR_LIV1 + i -1);
|
||
_sheet->delete_column(pos);
|
||
}
|
||
}
|
||
|
||
// configurazione campi
|
||
|
||
TConfig cfg(CONFIG_DITTA, "ve");
|
||
const bool gesval = cfg.get_bool("GESVAL");
|
||
const bool gescambi = cfg.get_bool("GESVALAC");
|
||
|
||
if (gesval)
|
||
{
|
||
const bool enable_controeuro = cfg.get_bool("CONTROEURO");
|
||
|
||
enable(F_CONTROEURO, enable_controeuro);
|
||
show(F_CODVAL, !gescambi);
|
||
show(F_DATACAMBIO, !gescambi);
|
||
show(F_NOMEVAL, !gescambi);
|
||
show(F_CODVAL1, gescambi);
|
||
show(F_DATACAMBIO1, gescambi);
|
||
show(F_NOMEVAL1, gescambi);
|
||
show(F_CAMBIO);
|
||
}
|
||
else
|
||
{
|
||
disable(F_CODVAL);
|
||
disable(F_DATACAMBIO);
|
||
disable(F_CONTROEURO);
|
||
disable(F_NOMEVAL);
|
||
hide(F_CODVAL1);
|
||
hide(F_DATACAMBIO1);
|
||
hide(F_NOMEVAL1);
|
||
disable(F_CAMBIO);
|
||
}
|
||
|
||
const bool geslin = cfg.get_bool("GESLIN");
|
||
|
||
enable(F_CODLIN, geslin);
|
||
enable(F_DESLIN, geslin);
|
||
|
||
const bool geslis = cfg.get_bool("GES", NULL, 1);
|
||
const bool gesliscatven = cfg.get_bool("GESLISCV");
|
||
|
||
if (geslis)
|
||
{
|
||
show(F_CODLIST, !gesliscatven);
|
||
show(F_CODLIST1, gesliscatven);
|
||
}
|
||
else
|
||
{
|
||
disable(F_CODLIST);
|
||
hide(F_CODLIST1);
|
||
}
|
||
|
||
const bool gescontr = cfg.get_bool("GES", "ve", 2);
|
||
const bool gescontrcli = cfg.get_bool("GESCONCC");
|
||
|
||
if (gescontr)
|
||
{
|
||
show(F_CODCONT1, gescontrcli);
|
||
show(F_CODCONT, !gescontrcli);
|
||
}
|
||
else
|
||
{
|
||
disable(F_CODCONT);
|
||
hide(F_CODCONT1);
|
||
}
|
||
|
||
const bool gesoff = cfg.get_bool("GES", "ve", 3);
|
||
enable(F_CODCAMP, gesoff);
|
||
|
||
const bool gessco = cfg.get_char("GESSCO") != 'N';
|
||
enable(F_SCONTOPERC, gessco);
|
||
|
||
const bool gesage = cfg.get_bool("GESAGE");
|
||
enable(F_CODAG, gesage);
|
||
enable(F_DESAG, gesage);
|
||
enable(F_CODAGVIS, gesage);
|
||
enable(F_DESAGVIS, gesage);
|
||
|
||
const bool has_movmag = dongle().active(MGAUT) && _doc.tipo().mov_mag();
|
||
int pos = id2pos(F_CAUSMAG);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
pos = id2pos(F_DESCRMAG);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
pos = id2pos(F_CAUSMAGC);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
pos = id2pos(F_DESCRMAGC);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
pos = id2pos(F_CURGIAC);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
pos = id2pos(F_CURDISP);
|
||
if (pos >= 0)
|
||
fld(pos).show(has_movmag);
|
||
|
||
for (i = fields() - 1; i >= 0; i--)
|
||
{
|
||
const TMask_field& f = fld(i);
|
||
|
||
const int p = f.page();
|
||
|
||
if (f.dlg() > BASE_PIEDE)
|
||
_calculated_pages.set(p);
|
||
}
|
||
}
|
||
|
||
TDocumento_mask::~TDocumento_mask()
|
||
{
|
||
if (_condv)
|
||
delete _condv;
|
||
if (_livelli_giac)
|
||
delete _livelli_giac;
|
||
if (_smartcard)
|
||
delete _smartcard;
|
||
}
|
||
|
||
int TDocumento_mask::insert_anal_fields(TMask& m, int page, int lf, int& y,
|
||
short& dlg, short& dlgd, bool required)
|
||
{
|
||
const int h = ca_create_fields(m, page, lf, 2, y, dlg, dlgd);
|
||
|
||
const bool main_mask = m.id2pos(F_SHEET) > 0;
|
||
|
||
for (int i = 0; i < h; i++)
|
||
{
|
||
TEdit_field& fld = m.efield(dlg+i);
|
||
int logic = lf;
|
||
if (logic == LF_FASI)
|
||
{
|
||
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
||
if (fasinfo.parent() != 0)
|
||
{
|
||
const TMultilevel_code_info& parinfo = ca_multilevel_code_info(fasinfo.parent());
|
||
if (i < parinfo.levels())
|
||
logic = fasinfo.parent();
|
||
}
|
||
}
|
||
|
||
const char* fieldname = NULL;
|
||
switch(logic)
|
||
{
|
||
case LF_COMMESSE: fieldname = DOC_CODCMS; break;
|
||
case LF_FASI : fieldname = DOC_FASCMS; break;
|
||
default : fieldname = DOC_CODCOSTO; break;
|
||
}
|
||
TFieldref* f = (TFieldref*)fld.field();
|
||
f->set_name(fieldname);
|
||
|
||
fld.check_type(required ? CHECK_REQUIRED : CHECK_NORMAL);
|
||
|
||
TEdit_field& dfld = m.efield(dlgd+i);
|
||
dfld.set_field(EMPTY_STRING); // Toglie campi che fan saltare gli output!
|
||
|
||
if (main_mask)
|
||
{
|
||
TSheet_field& sf = sfield(F_SHEET);
|
||
const TString head = fld.prompt();
|
||
const int colid = FR_CDC1+(fld.dlg()-F_CDC1);
|
||
sf.set_column_header(colid, head);
|
||
if (fld.size() > head.len())
|
||
sf.set_column_width(colid, fld.size()*8); // XI_FU_MULTIPLE
|
||
|
||
TMask& sm = sf.sheet_mask();
|
||
TString80 str; str << *fld.field();
|
||
sm.efield(colid).set_field(str); // Ricopia il campo nella maschera di riga per poterlo salvare!
|
||
}
|
||
}
|
||
|
||
y += h+1;
|
||
dlg += h; dlgd += h;
|
||
return h;
|
||
}
|
||
|
||
void TDocumento_mask::insert_anal_page()
|
||
{
|
||
int newpage = win2page(_sheet->parent());
|
||
if (newpage == 0)
|
||
newpage++;
|
||
insert_page("Pagina", newpage); // Inserisce una pagina vuota con un titolo a caso
|
||
|
||
// Rinumera i titoli di tutte le pagine
|
||
const int lastpage = win2page(fld(fields()-1).parent()); // Calcola in numero dell'ultima pagina
|
||
TToken_string caption;
|
||
int i;
|
||
for (i = 0; i <= lastpage; i++)
|
||
{
|
||
TString16 tag = TR("Pag.");
|
||
tag << (i+1); // Calcola il titolo di ogni pagina
|
||
caption.add(tag);
|
||
}
|
||
set_caption(caption); // Setta tutti i titoli contemporaneamente
|
||
|
||
add_groupbox(DLG_NULL, newpage, "", 1, 0, 78, 6);
|
||
add_string(DLG_NULL, newpage, TR("Cod. num. "), 2, 1, 4, "D").set_group(2);
|
||
add_string(DLG_NULL, newpage, "", 24, 1, 50, "D").set_group(3);
|
||
add_string(DLG_NULL, newpage, TR("Tipo doc. "), 2, 2, 4, "D").set_group(4);
|
||
add_string(DLG_NULL, newpage, "", 24, 2, 50, "D").set_group(5);
|
||
add_number(DLG_NULL, newpage, TR("Esercizio "), 2, 3, 4, "D").set_group(9);
|
||
add_number(DLG_NULL, newpage, TR("Numero doc. "), 24, 3, 6, "D").set_group(6);
|
||
add_date(DLG_NULL, newpage, TR("Data "), 46, 3, "D").set_group(7);
|
||
add_string(DLG_NULL, newpage, TR("Stato "), 67, 3, 1, "D").set_group(8);
|
||
add_number(DLG_NULL, newpage, TR("Cliente "), 2, 4, 6, "D").set_group(10);
|
||
add_string(DLG_NULL, newpage, "", 24, 4, 50, "D").set_group(11);
|
||
|
||
add_groupbox(DLG_NULL, newpage, TR("Contabilita' Analitica"), 1, 6, 78, 14);
|
||
|
||
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
||
const bool use_fsc = fasinfo.levels() > 0;
|
||
TConfig& ini = ca_config();
|
||
const bool fsc_req = use_fsc && ini.get_bool("FscRequired");
|
||
|
||
int y = 7;
|
||
short dlg = F_CDC1; // id del primo campo da generare
|
||
short dlgd = F_DESCDC1;
|
||
|
||
for (i = 0; i < 2; i++)
|
||
{
|
||
const TString& level = ini.get("Level", NULL, i+1); // Legge il livello 1 o 2
|
||
if (level == "CDC") // Crea centro di costo
|
||
{
|
||
if (use_fsc && fasinfo.parent() == LF_CDC)
|
||
insert_anal_fields(*this, newpage, LF_FASI, y, dlg, dlgd, fsc_req);
|
||
else
|
||
{
|
||
const bool cdc_req = ini.get_bool("CdcRequired");
|
||
|
||
insert_anal_fields(*this, newpage, LF_CDC, y, dlg, dlgd, cdc_req);
|
||
_last_cdc_dlg = dlg - 1;
|
||
}
|
||
} else
|
||
if (level == "CMS") // Crea commessa
|
||
{
|
||
if (use_fsc && fasinfo.parent() == LF_COMMESSE)
|
||
insert_anal_fields(*this, newpage, LF_FASI, y, dlg, dlgd, fsc_req);
|
||
else
|
||
{
|
||
const bool cms_req = ini.get_bool("CmsRequired");
|
||
|
||
insert_anal_fields(*this, newpage, LF_COMMESSE, y, dlg, dlgd, cms_req);
|
||
_last_cms_dlg = dlg - 1;
|
||
}
|
||
}
|
||
}
|
||
if (use_fsc && fasinfo.parent() <= 0)
|
||
insert_anal_fields(*this, newpage, LF_FASI, y, dlg, dlgd, fsc_req);
|
||
}
|
||
|
||
void TDocumento_mask::configura_sheet(TSheet_field& sheet)
|
||
{
|
||
TBit_array to_delete(MAX_COLUMNS);
|
||
to_delete.set();
|
||
const TTipo_documento& tdoc = _doc.tipo();
|
||
const TString_array& sheet_columns = tdoc.sheet_columns();
|
||
const int ncols = sheet_columns.items();
|
||
|
||
TToken_string colonne;
|
||
int i;
|
||
|
||
colonne = "0";
|
||
for (i = 0; i < ncols; i ++ )
|
||
{
|
||
TToken_string& sheet_col = (TToken_string&)sheet_columns.row(i);
|
||
const int field_id = sheet_col.get_int(0);
|
||
const int coltomove = sheet.cid2index(field_id);
|
||
to_delete.reset(coltomove);
|
||
|
||
const TString80 descr(sheet_col.get(1));
|
||
if (descr.not_empty() )
|
||
sheet.set_column_header( field_id, descr);
|
||
|
||
const int size = sheet_col.get_int(2) * 8; // XI_FU_MULTIPLE
|
||
if (size != 0)
|
||
sheet.set_column_width( field_id, size);
|
||
|
||
if (field_id != FR_LORDO || tdoc.calcolo_lordo())
|
||
colonne.add(field_id);
|
||
}
|
||
|
||
if (tdoc.calcolo_lordo())
|
||
to_delete.reset(0L);
|
||
else
|
||
to_delete.set(0L);
|
||
to_delete.reset(1);
|
||
|
||
if (!to_delete[sheet.cid2index(FR_CODDEP)])
|
||
sheet.enable_column(FR_CODDEP, _ges_dep && _ges_mag);
|
||
if (!to_delete[sheet.cid2index(FR_CODMAG)])
|
||
sheet.enable_column(FR_CODMAG, _ges_mag);
|
||
if (!to_delete[sheet.cid2index(FR_CODDEPC)])
|
||
sheet.enable_column(FR_CODDEPC, _ges_dep && _ges_mag);
|
||
if (!to_delete[sheet.cid2index(FR_CODMAGC)])
|
||
sheet.enable_column(FR_CODMAGC, _ges_mag);
|
||
to_delete.set(sheet.cid2index(FR_CODARTMAG));
|
||
to_delete.set(sheet.cid2index(FR_CHECKED));
|
||
|
||
const bool ca_active = dongle().active(CMAUT) || dongle().active(CAAUT);
|
||
if (ca_active)
|
||
{
|
||
const TMultilevel_code_info& cdc = ca_multilevel_code_info(LF_CDC);
|
||
const TMultilevel_code_info& cms = ca_multilevel_code_info(LF_COMMESSE);
|
||
const TMultilevel_code_info& fas = ca_multilevel_code_info(LF_FASI);
|
||
const int levels = cdc.levels() + cms.levels() + fas.levels();
|
||
for (short cid = FR_CDC1; cid <= FR_CDC12; cid++)
|
||
{
|
||
const int level = cid-FR_CDC1;
|
||
to_delete.set(sheet.cid2index(cid), level >= levels);
|
||
if (level < levels)
|
||
colonne.add(cid);
|
||
}
|
||
}
|
||
|
||
for ( i = MAX_COLUMNS - 1; i >= 0; i-- )
|
||
{
|
||
if( to_delete[i] )
|
||
{
|
||
sheet.enable_column( i + FIRST_FIELD, FALSE);
|
||
sheet.delete_column( i + FIRST_FIELD);
|
||
}
|
||
}
|
||
|
||
if (!sheet.user_saved_columns_order())
|
||
sheet.set_columns_order(&colonne);
|
||
}
|
||
|
||
TCond_vendita& TDocumento_mask::condv() const
|
||
{
|
||
if (_condv == NULL)
|
||
{
|
||
TDocumento_mask* myself = (TDocumento_mask*)this;
|
||
myself->_condv = new TCond_vendita(myself, NULL);
|
||
}
|
||
return *_condv;
|
||
}
|
||
|
||
void TDocumento_mask::update_progs(bool stop_run)
|
||
{
|
||
static bool updating_progs = false;
|
||
|
||
if (!updating_progs)
|
||
{
|
||
updating_progs = true;
|
||
TWait_cursor hourglass;
|
||
const int page = curr_page();
|
||
const int last_field = fields() - 1;
|
||
int f;
|
||
|
||
for (f = last_field; f >= 0; f--)
|
||
{
|
||
const TMask_field & mf = fld(f);
|
||
const TFieldref * fr = mf.field();
|
||
|
||
if (fr)
|
||
_doc.put(fr->name(), mf.get());
|
||
}
|
||
|
||
_doc.set_riga_esenzione();
|
||
|
||
for (f = last_field; f >= 0; f--)
|
||
{
|
||
const TMask_field & mf = fld(f);
|
||
const int id = mf.dlg();
|
||
const int field_page = mf.page();
|
||
|
||
if ((page == field_page || stop_run) && id > BASE_PIEDE)
|
||
{
|
||
const TFieldref* recfld = mf.field();
|
||
if (recfld != NULL)
|
||
{
|
||
const TString & name = recfld->name();
|
||
const TString& val = _doc.get(name);
|
||
set(id, val, true);
|
||
}
|
||
}
|
||
}
|
||
updating_progs = false;
|
||
}
|
||
}
|
||
|
||
void TDocumento_mask::next_page(int p)
|
||
{
|
||
TMask::next_page(p);
|
||
|
||
if (is_calculated_page(curr_page()))
|
||
update_progs();
|
||
}
|
||
|
||
void TDocumento_mask::start_run()
|
||
{
|
||
TSmart_card * s = smartcard();
|
||
|
||
if (s != NULL)
|
||
{
|
||
if (edit_mode() && s->with_card(*this))
|
||
disable(DLG_SAVEREC);
|
||
if (s->card_connected())
|
||
{
|
||
disable(F_CODCF);
|
||
disable(F_RAGSOC);
|
||
s->disable_prot_fields(*this);
|
||
if (s->with_card(*this))
|
||
enable(DLG_SAVEREC);
|
||
|
||
smartcard_error err = s->read();
|
||
if (err == no_smarterror)
|
||
s->card2mask(*this);
|
||
else
|
||
s->display_error(err);
|
||
}
|
||
}
|
||
TVariable_mask::start_run();
|
||
}
|
||
|
||
bool TDocumento_mask::stop_run(KEY key)
|
||
{
|
||
if (key != K_ESC && key != K_QUIT)
|
||
update_progs(true);
|
||
else
|
||
if (key == K_ESC)
|
||
{
|
||
TSmart_card * s = smartcard();
|
||
|
||
if (s != NULL)
|
||
{
|
||
if (s->card_connected())
|
||
{
|
||
s->disconnect_card();
|
||
enable(F_CODCF);
|
||
enable(F_RAGSOC);
|
||
}
|
||
}
|
||
}
|
||
|
||
return TVariable_mask::stop_run(key);
|
||
}
|
||
|
||
bool TDocumento_mask::on_key(KEY key)
|
||
{
|
||
if (key == K_SHIFT + K_F12)
|
||
{
|
||
TRelation r(LF_DOC);
|
||
r.curr()=doc();
|
||
if (!doc().bloccato() && ::user_can_write(&r))
|
||
{
|
||
TMask_field& stato = field(F_STATO);
|
||
stato.enable();
|
||
enable(DLG_SAVEREC);
|
||
enable(DLG_DELREC);
|
||
TSmart_card * s = smartcard();
|
||
|
||
if (s != NULL && s->card_connected())
|
||
s->enable_prot_fields(*this);
|
||
}
|
||
else
|
||
warning_box("L'utente %s non puo' modificare questo documento",
|
||
(const char*)user());
|
||
return TRUE;
|
||
}
|
||
else
|
||
if (key == K_F7)
|
||
{
|
||
const TSheet_field & sf = sfield(F_SHEET);
|
||
TDocumento & d = doc();
|
||
TRiga_documento & riga = d[sf.selected() + 1];
|
||
TOriginal_row_mask sm;
|
||
const TRectype * or_row = riga.find_original_rdoc();
|
||
|
||
if (or_row != NULL)
|
||
{
|
||
sm.set(F_DACODNUM, or_row->get(RDOC_CODNUM));
|
||
sm.set(F_DAANNO, or_row->get(RDOC_ANNO));
|
||
sm.set(F_DAPROVV, or_row->get(RDOC_PROVV));
|
||
sm.set(F_DANDOC, or_row->get(RDOC_NDOC));
|
||
sm.set(F_DANRIGA, or_row->get(RDOC_NRIGA));
|
||
sm.disable(-1);
|
||
}
|
||
|
||
if (sm.run() == K_ENTER && sm.field(F_DACODNUM).enabled())
|
||
{
|
||
TToken_string key(sm.get(F_DACODNUM));
|
||
key.add(sm.get(F_DAANNO));
|
||
key.add(sm.get(F_DAPROVV));
|
||
key.add(sm.get(F_DANDOC));
|
||
key.add(sm.get(F_DANRIGA));
|
||
|
||
const TRectype & or_row_mod = cache().get(LF_RIGHEDOC, key);
|
||
if (or_row_mod.empty())
|
||
riga.reset_original_rdoc_key();
|
||
else
|
||
riga.set_original_rdoc_key(or_row_mod);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
return TVariable_mask::on_key(key);
|
||
}
|
||
|
||
void TDocumento_mask::occ2mask()
|
||
{
|
||
const TOccasionale& o = doc().occas();
|
||
|
||
reset(F_COFI);
|
||
reset(F_PAIVA);
|
||
set(F_OCFPI, o.get(OCC_CFPI));
|
||
const TString & ragsoc = o.get(OCC_RAGSOC);
|
||
set(F_RAGSOC, ragsoc);
|
||
set(F_RAGSOCSP, ragsoc);
|
||
const TString & indir = o.get(OCC_INDIR);
|
||
set(F_INDCF, indir);
|
||
set(F_INDSP, indir);
|
||
const TString & civ = o.get(OCC_CIV);
|
||
set(F_CIVCF, civ);
|
||
set(F_CIVSP, civ);
|
||
const TString & cap = o.get(OCC_CAP);
|
||
set(F_CAPCF, cap);
|
||
set(F_CAPSP, cap);
|
||
const TString & com = o.get(OCC_COM);
|
||
set(F_COMCF, com);
|
||
set( F_COMSP, com);
|
||
const TString & stato = o.get(OCC_STATO);
|
||
set(F_STATOCF, stato);
|
||
set( F_STATOSP, stato);
|
||
if (id2pos(F_CODINDSP) >= 0)
|
||
reset(F_CODINDSP);
|
||
// Sugli occasionali non c'<27> la localit<69>
|
||
const TString & localita = o.get(OCC_LOCALITA);
|
||
set(F_LOCALITACF, localita);
|
||
set(F_LOCALITASP, localita);
|
||
check_field(F_COMSP);
|
||
check_field(F_STATOSP);
|
||
}
|
||
|
||
void TDocumento_mask::cli2mask()
|
||
{
|
||
TCli_for & c = doc().clifor();
|
||
|
||
const bool onload = !is_running();
|
||
|
||
// Setta i campi che appartengono al file LF_CLIFO
|
||
const bool occas = c.occasionale();
|
||
|
||
show(F_OCCASEDIT, occas);
|
||
if (!occas)
|
||
reset(F_OCFPI);
|
||
show(F_OCFPI, occas);
|
||
// In forse per l'Occasionale, sicuri per il Normale
|
||
show(F_COFI, !occas);
|
||
show(F_STATOPAIVA, !occas);
|
||
show(F_PAIVA, !occas);
|
||
set(F_RAGSOC, c.get(CLI_RAGSOC));
|
||
enable(F_RAGSOC, !occas);
|
||
|
||
const TRectype & ven_rec = c.vendite();
|
||
|
||
if(!onload)
|
||
{
|
||
short pos = id2pos(F_CODVAL);
|
||
const TString16 codval = c.get(CLI_CODVAL); // Attenzione: Non usare TString& qui!
|
||
|
||
if (pos >= 0)
|
||
set(F_CODVAL, codval, TRUE);
|
||
pos = id2pos(F_CODVAL1);
|
||
if (pos >= 0)
|
||
set(F_CODVAL1, codval, TRUE);
|
||
pos = id2pos(F_CODLIN);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).set(c.get(CLI_CODLIN));
|
||
set(F_CODPAG, c.get(CLI_CODPAG));
|
||
set(F_CODABIA, c.get(CLI_CODABI));
|
||
set(F_CODCABA, c.get(CLI_CODCAB));
|
||
if (id2pos(F_IBAN_STATO) > 0)
|
||
{
|
||
const TString80 iban = c.get(CLI_IBAN);
|
||
set(F_IBAN, iban);
|
||
efield(F_IBAN_STATO).validate(K_TAB);
|
||
if (iban.not_empty())
|
||
{
|
||
set(F_IBAN_STATO, iban.left(2));
|
||
set(F_IBAN_CHECK, iban.mid(2,2));
|
||
set(F_BBAN , iban.mid(4));
|
||
set(F_BBAN_CIN , iban.mid(4,1));
|
||
set(F_BBAN_ABI , iban.mid(5,5));
|
||
set(F_BBAN_CAB , iban.mid(10,5));
|
||
set(F_BBAN_CONTO, iban.mid(15,12));
|
||
}
|
||
}
|
||
// Setta i campi che appartengono al file LF_CFVEN
|
||
set(F_CODABIP, ven_rec.get(CFV_CODABIPR));
|
||
set(F_CODCABP, ven_rec.get(CFV_CODCABPR));
|
||
set(F_RAGGR, ven_rec.get(CFV_RAGGDOC));
|
||
set(F_RAGGREFF, ven_rec.get(CFV_RAGGEFF));
|
||
set(F_CODINDSP, ven_rec.get(CFV_CODINDSP));
|
||
set(F_CODAG, ven_rec.get(CFV_CODAG));
|
||
set(F_CODSPMEZZO, ven_rec.get(CFV_CODSPMEZZO));
|
||
set(F_CODPORTO, ven_rec.get(CFV_CODPORTO));
|
||
set(F_CODNOTESP1, ven_rec.get(CFV_CODNOTESP1));
|
||
set(F_CODNOTESP2, ven_rec.get(CFV_CODNOTESP2));
|
||
set(F_CODNOTE, ven_rec.get(CFV_CODNOTE));
|
||
set(F_CODVETT1, ven_rec.get(CFV_CODVETT1));
|
||
set(F_CODVETT2, ven_rec.get(CFV_CODVETT2));
|
||
set(F_CODVETT3, ven_rec.get(CFV_CODVETT3));
|
||
set(F_SPESEINC, ven_rec.get(CFV_PERCSPINC));
|
||
set(F_ADDBOLLI, ven_rec.get(CFV_ADDBOLLI));
|
||
set(F_CATVEN, ven_rec.get(CFV_CATVEN));
|
||
pos = id2pos(F_CODLIST);
|
||
const TString16 codlist = ven_rec.get(CFV_CODLIST);
|
||
if (pos >= 0 && fld(pos).active())
|
||
{
|
||
TEdit_field & f = (TEdit_field&) fld(pos);
|
||
|
||
f.set(codlist);
|
||
f.check();
|
||
f.on_hit();
|
||
}
|
||
pos = id2pos(F_CODLIST1);
|
||
if (pos >= 0 && fld(pos).active())
|
||
{
|
||
TEdit_field & f = (TEdit_field&) fld(pos);
|
||
|
||
f.set(codlist);
|
||
f.check();
|
||
f.on_hit();
|
||
}
|
||
pos = id2pos(F_CODAG);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).set(ven_rec.get(CFV_CODAG));
|
||
set(F_CODZON, ven_rec.get(CFV_CODZONA));
|
||
set(F_RAGGR, ven_rec.get(CFV_RAGGDOC));
|
||
sconto_testa2mask();
|
||
spese2mask();
|
||
}
|
||
enable( F_CODINDSP , !occas);
|
||
if (occas)
|
||
occ2mask();
|
||
else
|
||
{
|
||
set(F_COFI, c.get(CLI_COFI));
|
||
set(F_INDCF, c.get(CLI_INDCF));
|
||
set(F_CIVCF, c.get(CLI_CIVCF));
|
||
set(F_STATOPAIVA, c.get(CLI_STATOPAIV));
|
||
set(F_PAIVA, c.get(CLI_PAIV));
|
||
set(F_LOCALITACF, c.get(CLI_LOCCF));
|
||
set(F_CAPCF, c.get(CLI_CAPCF));
|
||
set(F_COMCF, c.get(CLI_COMCF));
|
||
set(F_STATOCF, c.get(CLI_STATOCF));
|
||
check_field( F_CODINDSP );
|
||
}
|
||
const TString16 newcodval(get(F_CODVAL));
|
||
|
||
short pos = id2pos(F_CAMBIO);
|
||
if ((pos >= 0) && newcodval.empty())
|
||
fld(pos).reset();
|
||
pos = id2pos(F_CODVAL);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check(STARTING_CHECK);
|
||
pos = id2pos(F_CODVAL1);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check(STARTING_CHECK);
|
||
check_field(F_COMCF);
|
||
check_field(F_STATOCF);
|
||
check_field( F_CODPAG );
|
||
pos = id2pos(F_CODLIN);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check();
|
||
check_field( F_CODCABA );
|
||
pos = id2pos(F_CODLIST);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check();
|
||
pos = id2pos(F_CODLIST1);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check();
|
||
check_field( F_CODCABP );
|
||
pos = id2pos(F_CODAG);
|
||
if (pos >= 0 && fld(pos).active())
|
||
fld(pos).check();
|
||
check_field( F_CODSPMEZZO );
|
||
check_field( F_CODPORTO );
|
||
check_field( F_CODNOTESP1 );
|
||
check_field( F_CODNOTESP2 );
|
||
check_field( F_CODNOTE );
|
||
check_field( F_CODVETT1 );
|
||
check_field( F_CODVETT2 );
|
||
check_field( F_CODVETT3 );
|
||
check_field( F_CATVEN );
|
||
check_field( F_CODZON );
|
||
|
||
const bool contr_enabled = ven_rec.get_bool(CFV_GESTCONTR);
|
||
bool gescontr = FALSE;
|
||
if (contr_enabled)
|
||
{
|
||
TConfig ditta(CONFIG_DITTA, "ve");
|
||
gescontr = ditta.get_bool("GES", "ve", 2);
|
||
}
|
||
|
||
enable(F_CODCONT1, contr_enabled && gescontr);
|
||
enable(F_CODCONT, contr_enabled && gescontr);
|
||
}
|
||
|
||
void TDocumento_mask::sconto_testa2mask()
|
||
{
|
||
TCli_for & c = doc().clifor();
|
||
TConfig ditta(CONFIG_DITTA, "ve");
|
||
const char tipogestione = ditta.get("GESSCO", "ve")[ 0 ];
|
||
switch( tipogestione )
|
||
{
|
||
case 'N': // Sconti non gestiti: pussa via!
|
||
break;
|
||
case 'P': // Percentuale su anagrafica cliente
|
||
set( F_SCONTOPERC, c.vendite().get(CFV_SCONTO));
|
||
break;
|
||
case 'T': // Gestione tabella sconti
|
||
{
|
||
const TString16 codsconto(c.vendite().get(CFV_CODSCC));
|
||
|
||
if (codsconto.not_empty())
|
||
{
|
||
TTable sconti("%SCC");
|
||
sconti.setkey(1);
|
||
sconti.zero();
|
||
sconti.put("CODTAB", codsconto);
|
||
if (sconti.read( ) == NOERR)
|
||
set(F_SCONTOPERC, sconti.get("S1"));
|
||
}
|
||
}
|
||
break;
|
||
case 'A': // Gestione archivio sconti
|
||
{
|
||
TString16 cod;
|
||
const TRectype & ven_rec = c.vendite();
|
||
TLocalisamfile sconti(LF_SCONTI );
|
||
|
||
sconti.setkey(1);
|
||
sconti.zero();
|
||
sconti.put("TIPO", "I");
|
||
if(ditta.get_bool("SCOKEY", "ve", 1))
|
||
sconti.put("CODCAT", ven_rec.get(CFV_CATVEN));
|
||
if(ditta.get_bool("SCOKEY", "ve", 2))
|
||
cod.format("%-2s", (const char *)ven_rec.get(CFV_CODSCC));
|
||
else
|
||
cod = " ";
|
||
if( ditta.get_bool("SCOKEY", "ve", 3))
|
||
{
|
||
TString8 cz; cz.format("%-2s", (const char*)ven_rec.get(CFV_CODZONA));
|
||
cod << cz;
|
||
}
|
||
else
|
||
cod << " ";
|
||
if( ditta.get_bool("SCOKEY", "ve", 4))
|
||
cod << c.get(CLI_CODPAG);
|
||
sconti.put("CODART", cod);
|
||
if(sconti.read() == NOERR)
|
||
set(F_SCONTOPERC, sconti.get( "SCONTO"));
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return;
|
||
}
|
||
|
||
void TDocumento_mask::spese2mask()
|
||
{
|
||
TSheet_field & sh = (TSheet_field &) field(F_SHEET);
|
||
TCli_for & c = doc().clifor();
|
||
|
||
TString16 name("CODSP0");
|
||
TString_array spese;
|
||
const TRectype & ven_rec = c.vendite();
|
||
for (int i = 1; i <= 4; i++)
|
||
{
|
||
name.rtrim(1); name << i;
|
||
const TString16 s(ven_rec.get(name));
|
||
|
||
if (s.not_empty())
|
||
spese.add(s);
|
||
}
|
||
|
||
doc().put(DOC_SPESEUPD, false);
|
||
doc().put(DOC_CODVAL, get(F_CODVAL));
|
||
doc().put(DOC_CAMBIO, get(F_CAMBIO));
|
||
doc().put(DOC_CONTROEURO, get(F_CONTROEURO));
|
||
|
||
doc().update_spese_aut(spese, FALSE, &sh);
|
||
sh.force_update();
|
||
}
|
||
|
||
void TDocumento_mask::reset_masks(const TString& tipo_doc)
|
||
{
|
||
static TString16 last_tipo_doc;
|
||
|
||
if (tipo_doc != last_tipo_doc)
|
||
{
|
||
FOR_EACH_ASSOC_OBJECT(_maskriga, h, k, o)
|
||
{
|
||
TMask* m = (TMask*)o;
|
||
m->enable_default();
|
||
if (!_sheet->exist_column(FR_PREZZO))
|
||
m->hide(FR_PREZZO);
|
||
}
|
||
last_tipo_doc = tipo_doc;
|
||
}
|
||
}
|
||
|
||
void TDocumento_mask::doc2mask(bool reload_clifo)
|
||
{
|
||
TSheet_field& s = sfield(F_SHEET);
|
||
s.destroy( );
|
||
|
||
for (int p = fields()-1; p >= 0; p--)
|
||
{
|
||
TMask_field& f = fld(p);
|
||
const TFieldref* fr = f.field();
|
||
if (fr)
|
||
f.set(fr->read(doc()));
|
||
else
|
||
f.reset();
|
||
}
|
||
|
||
if (reload_clifo)
|
||
cli2mask();
|
||
|
||
const int righe = doc().physical_rows();
|
||
for (int i = 0; i < righe; i++)
|
||
{
|
||
s.insert(-1, FALSE);
|
||
s.row(i); // qui verificare
|
||
doc()[i+1].autoload(s);
|
||
s.check_row(i, 0x2);
|
||
}
|
||
|
||
reset_masks(get(F_TIPODOC));
|
||
|
||
s.force_update();
|
||
}
|
||
|
||
void TDocumento_mask::mask2doc()
|
||
{
|
||
for (int p = fields()-1; p >= 0; p--)
|
||
{
|
||
TMask_field& f = fld(p);
|
||
const TFieldref* fr = f.field();
|
||
if (fr)
|
||
fr->write(f.get(), doc());
|
||
}
|
||
}
|
||
|
||
TVariable_mask* TDocumento_mask::riga_mask(int numriga)
|
||
{
|
||
const TRiga_documento& riga = doc()[numriga + 1];
|
||
const TTipo_riga_documento& tiporiga = riga.tipo();
|
||
TString16 name; tiporiga.mask_name(name);
|
||
|
||
TVariable_mask* m = (TVariable_mask*)_maskriga.objptr(name);
|
||
if (m == NULL)
|
||
{
|
||
m = new TVariable_mask(name);
|
||
|
||
_maskriga.add(name, m);
|
||
|
||
TFilename proname; tiporiga.profile_name(proname);
|
||
TConfig pro( proname, "HANDLERS" );
|
||
|
||
const int numhandler = pro.get_int( "NHANDLER", "HANDLERS" );
|
||
for(int i = 1; i <= numhandler; i++)
|
||
{
|
||
TString8 chiave; chiave.format("%d", i );
|
||
TToken_string riga(pro.get(chiave, "HANDLERS"));
|
||
row_set_handler( *m, riga.get_int(0), riga.get_int(1) );
|
||
}
|
||
|
||
m->set_handler(FR_TIPORIGA, tipo_riga_handler);
|
||
m->set_handler( FR_QTA, qta_handler );
|
||
m->set_handler( FR_UMQTA, um_handler );
|
||
m->set_handler( FR_DATACONS, dcons_handler);
|
||
TList_field & htr = lfield(F_LBTIPORIGA);
|
||
const TString codes(htr.get_codes());
|
||
const TString values(htr.get_values());
|
||
|
||
m->lfield(FR_TIPORIGA).replace_items(codes, values);
|
||
|
||
const int pos = m->id2pos(FR_CODART);
|
||
if (pos >= 0)
|
||
{
|
||
const TMask_field & f = m->field(FR_CODART);
|
||
if (f.is_edit())
|
||
{
|
||
TBrowse * browse = ((TEdit_field &) f).browse();
|
||
const char tipo_r = tiporiga.tipo();
|
||
|
||
if (browse )
|
||
{
|
||
const TCursor * cur = browse->cursor();
|
||
if (cur)
|
||
{
|
||
const int num = cur->file().num();
|
||
if (num == LF_ANAMAG || num == LF_CODCORR)
|
||
{
|
||
m->set_handler( FR_CODMAG, codmag_handler );
|
||
m->set_handler( FR_CODMAGC, codmag_coll_handler );
|
||
m->set_handler( FR_CODART, codart_handler );
|
||
m->set_handler( FR_LIV1, liv_handler );
|
||
m->set_handler( FR_LIV2, liv_handler );
|
||
m->set_handler( FR_LIV3, liv_handler );
|
||
m->set_handler( FR_LIV4, liv_handler );
|
||
m->set_handler( FR_UMQTA, umart_handler );
|
||
m->set_handler( FR_CODARTMAG, codartmag_handler );
|
||
m->set_handler( FR_DESCR, descr_handler );
|
||
m->set_handler( FR_QTA, qtaart_handler );
|
||
if (livelli().autoinsert(1))
|
||
m->field(FR_LIV1).check_type(CHECK_NONE);
|
||
if (livelli().autoinsert(2))
|
||
m->field(FR_LIV2).check_type(CHECK_NONE);
|
||
if (livelli().autoinsert(3))
|
||
m->field(FR_LIV3).check_type(CHECK_NONE);
|
||
if (livelli().autoinsert(4))
|
||
m->field(FR_LIV4).check_type(CHECK_NONE);
|
||
}
|
||
else
|
||
if (tipo_r == RIGA_SPESEDOC || tipo_r == RIGA_PRESTAZIONI ||
|
||
tipo_r == RIGA_RISORSE || tipo_r == RIGA_ATTREZZATURE)
|
||
m->set_handler( FR_CODART, sppr_handler );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
m->set_handler(FR_QTAEVASA, qta_evasa_handler);
|
||
m->set_handler(FR_CAUS, causmag_handler);
|
||
|
||
if (m->id2pos(FR_CODIVA) >= 0)
|
||
{
|
||
m->set_handler(FR_CODIVA, iva_handler);
|
||
const TString& tipiva = doc().tipo().tipi_iva_validi();
|
||
if (tipiva.not_empty())
|
||
{
|
||
TBrowse& browse = *(m->efield(FR_CODIVA)).browse();
|
||
TString filter = browse.get_filter();
|
||
|
||
bool close_filter = FALSE;
|
||
if (filter.not_empty())
|
||
{
|
||
filter.insert("(");
|
||
filter << ")&&(";
|
||
close_filter = TRUE;
|
||
}
|
||
bool firstor = TRUE;
|
||
for (int i = tipiva.len()-1; i >= 0; i--) if (tipiva[i] != ' ')
|
||
{
|
||
if (firstor)
|
||
firstor = FALSE;
|
||
else
|
||
filter << "||";
|
||
filter << "(S1==\"";
|
||
switch(i)
|
||
{
|
||
case 1: filter << "VE"; break;
|
||
case 2: filter << "ES"; break;
|
||
case 3: filter << "NI"; break;
|
||
case 4: filter << "NS"; break;
|
||
default: break;
|
||
}
|
||
filter << "\")";
|
||
}
|
||
if (close_filter) filter << ')';
|
||
browse.set_filter(filter);
|
||
}
|
||
m->set_handler(DLG_USER, link_handler);
|
||
}
|
||
|
||
bool ca_active = dongle().active(CMAUT) || dongle().active(CAAUT); // Qualsiasi cosa analitica va bene
|
||
ca_active &= !(riga.is_descrizione() || riga.is_omaggio() || riga.is_sconto()); // Ignora 'ste righe
|
||
if (ca_active)
|
||
{
|
||
const int page = m->win2page(m->fld(m->fields()-1).parent()); // Calcolo bastardo dell'ultima pagina
|
||
|
||
TConfig& ini = ca_config();
|
||
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
||
const bool use_fsc = fasinfo.levels() > 0;
|
||
|
||
int y = 1;
|
||
int i;
|
||
short dlg = FR_CDC1; // id del primo campo da generare
|
||
short dlgd = FR_DESCDC1;
|
||
|
||
for (i = 0; i < 2; i++)
|
||
{
|
||
const TString& level = ini.get("Level", NULL, i+1); // Legge il livello 1 o 2
|
||
if (level == "CDC") // Crea centro di costo
|
||
{
|
||
if (use_fsc && fasinfo.parent() == LF_CDC)
|
||
insert_anal_fields(*m, page, LF_FASI, y, dlg, dlgd, false);
|
||
else
|
||
{
|
||
insert_anal_fields(*m, page, LF_CDC, y, dlg, dlgd, false);
|
||
m->set_handler( dlg - 1, cdc_mag_handler);
|
||
}
|
||
|
||
} else
|
||
if (level == "CMS") // Crea commessa
|
||
{
|
||
if (use_fsc && fasinfo.parent() == LF_COMMESSE)
|
||
insert_anal_fields(*m, page, LF_FASI, y, dlg, dlgd, false);
|
||
else
|
||
{
|
||
insert_anal_fields(*m, page, LF_COMMESSE, y, dlg, dlgd, false);
|
||
m->set_handler( dlg - 1, cms_mag_handler);
|
||
}
|
||
}
|
||
}
|
||
if (use_fsc && fasinfo.parent() <= 0)
|
||
insert_anal_fields(*m, page, LF_FASI, y, dlg, dlgd, false);
|
||
}
|
||
}
|
||
|
||
m->set_sheet(&sfield(F_SHEET));
|
||
|
||
int pos = m->id2pos(FR_PREZZO);
|
||
if (pos >= 0)
|
||
{
|
||
TEditable_field & f =((TEditable_field &) m->fld(pos));
|
||
f.reset_driver(F_CODVAL);
|
||
f.add_driver(-F_CODVAL);
|
||
}
|
||
|
||
pos = m->id2pos(FR_IMPFISSO);
|
||
if (pos >= 0)
|
||
{
|
||
TEditable_field & f =((TEditable_field &) m->fld(pos));
|
||
f.reset_driver();
|
||
f.add_driver(-F_CODVAL);
|
||
}
|
||
|
||
return m;
|
||
|
||
}
|
||
|
||
void TDocumento_mask::update_giacenza()
|
||
{
|
||
if (id2pos(F_CURGIAC)<0 || !is_running())
|
||
return;
|
||
|
||
TSheet_field& sf = sfield(F_SHEET);
|
||
TToken_string& row = sf.row(sf.selected());
|
||
TString codart = row.get(sf.cid2index(FR_CODARTMAG));
|
||
TString16 causmag = row.get(sf.cid2index(FR_CAUS));
|
||
|
||
if (causmag.blank())
|
||
causmag = get(F_CAUSMAG);
|
||
|
||
const TCausale_magazzino c(causmag);
|
||
|
||
if (causmag.full() && c.scarica_alternativi())
|
||
{
|
||
const TString& alt = cache().get(LF_ANAMAG, codart, ANAMAG_CODARTALT);
|
||
if (alt.full())
|
||
codart = alt;
|
||
}
|
||
|
||
real giac, disp;
|
||
if (codart.full())
|
||
{
|
||
TString8 codmag = row.get(sf.cid2index(FR_CODMAG));
|
||
if (codmag.full())
|
||
{
|
||
const TString4 coddep = row.get(sf.cid2index(FR_CODDEP));
|
||
if (coddep.full())
|
||
codmag << coddep;
|
||
}
|
||
else
|
||
{ // Cerca di determinare il magazzino di default, se manca sulla riga
|
||
if (causmag.full())
|
||
{
|
||
const TCausale_magazzino c(causmag);
|
||
|
||
if (c.has_default_mag())
|
||
{
|
||
codmag = c.default_mag();
|
||
if (c.has_default_dep())
|
||
codmag << c.default_dep();
|
||
}
|
||
}
|
||
}
|
||
|
||
TString16 livello;
|
||
|
||
for (int i = 0; i < 4; i++)
|
||
{
|
||
const char* liv = row.get(sf.cid2index(FR_LIV1+i));
|
||
if (*liv > ' ')
|
||
livello << liv;
|
||
else
|
||
break;
|
||
}
|
||
|
||
const TString8 annoes = get(F_ANNO);
|
||
TArticolo_giacenza art(codart);
|
||
giac = art.disponibilita(annoes, codmag, livello, TRUE);
|
||
disp = art.disponibilita(annoes, codmag, livello, FALSE);
|
||
|
||
const TString4 um = row.get(sf.cid2index(FR_UMQTA));
|
||
art.convert_to_um(giac, um);
|
||
art.convert_to_um(disp, um);
|
||
}
|
||
|
||
set(F_CURGIAC, giac.string());
|
||
set(F_CURDISP, disp.string());
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Handlers and notifiers
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool TDocumento_mask::ss_handler(TMask_field& f, KEY key)
|
||
{
|
||
bool ok = TRUE;
|
||
if (key == K_ENTER && f.mask().insert_mode())
|
||
{
|
||
TSheet_field& ss = (TSheet_field&)f;
|
||
if (!app().is_transaction() && ss.items() == 0)
|
||
ok = yesno_box("Il documento e' privo di righe:\n"
|
||
"Si desidera continuare ugualmente?");
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key )
|
||
{
|
||
static bool selecting = false;
|
||
|
||
TDocumento_mask& m = (TDocumento_mask&)ss.mask();
|
||
TDocumento& doc = m.doc();
|
||
|
||
switch (key)
|
||
{
|
||
case K_ENTER: // modifica
|
||
{
|
||
TRiga_documento& riga = doc[r + 1];
|
||
riga.autosave(ss);
|
||
|
||
if (m.is_calculated_page(m.curr_page()))
|
||
m.update_progs();
|
||
}
|
||
break;
|
||
case K_DEL: // Cancellazione
|
||
{
|
||
doc.destroy_row(r + 1, TRUE);
|
||
if (r < doc.rows())
|
||
{
|
||
TRiga_documento & riga = doc[r + 1];
|
||
if (riga.is_omaggio() && riga.is_generata())
|
||
{
|
||
ss.destroy(r + 1);
|
||
doc.destroy_row(r + 1, TRUE);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case K_INS: // Inserimento
|
||
{
|
||
if (r < doc.rows())
|
||
{
|
||
TRiga_documento & riga = doc[r + 1];
|
||
if (riga.is_omaggio() && riga.is_generata())
|
||
return FALSE;
|
||
}
|
||
doc.insert_row(r + 1, m.get( F_LBTIPORIGA ));
|
||
}
|
||
break;
|
||
case K_CTRL + K_INS:
|
||
{
|
||
const TRectype& ven_rec = doc.clifor().vendite();
|
||
TString8 s = ven_rec.get(CFV_CODMAG);
|
||
if (s.full())
|
||
{
|
||
s.left_just(3);
|
||
s << ven_rec.get(CFV_CODDEP);
|
||
}
|
||
else
|
||
{
|
||
s = m.get(F_CAUSMAG);
|
||
if (s.full())
|
||
{
|
||
s = cache().get("%CAU", s, "S10");
|
||
if (s.blank())
|
||
{
|
||
s = m._std_mag;
|
||
s.left_just(3);
|
||
s << m._std_dep;
|
||
}
|
||
}
|
||
}
|
||
TRiga_documento& riga = doc[r + 1];
|
||
riga.put(RDOC_CODMAG, s);
|
||
riga.autoload(ss);
|
||
ss.check_row(r);
|
||
riga.tipo().set_defaults(ss, r + 1);
|
||
}
|
||
break;
|
||
case K_TAB: // ingresso nella riga
|
||
if (!selecting && m.is_running())
|
||
{
|
||
m.update_giacenza();
|
||
const TRectype& rdoc = doc[r + 1];
|
||
set_curr_um(rdoc.get(RDOC_UMQTA));
|
||
const bool on = rdoc.get(RDOC_DACODNUM).not_empty();
|
||
ss.sheet_mask().enable(DLG_USER, on);
|
||
|
||
if (rdoc.get(RDOC_CODART).empty() && rdoc.get(RDOC_DESCR).empty())
|
||
{
|
||
selecting = true; // semaforo per impedire l'evento di selezione doppio
|
||
ss.select(r, 1, false);
|
||
selecting = false;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
// Funzione che dato il profilo di riga ottiene la maschera
|
||
// Serve per ottenere una maschera diversa per ogni riga
|
||
TMask* TDocumento_mask::ss_getmask(int numriga, TMask& fullmask)
|
||
{
|
||
TSheet_field* sf = fullmask.get_sheet();
|
||
TDocumento_mask& m = (TDocumento_mask&)sf->mask();
|
||
const TDocumento& doc = m.doc();
|
||
|
||
if (numriga < doc.physical_rows())
|
||
return m.riga_mask(numriga);
|
||
else
|
||
return &fullmask;
|
||
}
|
||
|
||
bool TDocumento_mask::occas_code_handler(TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_TAB && f.focusdirty())
|
||
{
|
||
const char* code = f.get();
|
||
if (*code)
|
||
{
|
||
TRelation occas(LF_OCCAS);
|
||
occas.lfile().put("CFPI", code);
|
||
if (occas.read(_isequal) == NOERR)
|
||
{
|
||
TMask& m = f.mask();
|
||
m.autoload(occas);
|
||
m.send_key(K_TAB, O_COMUNE); // Forza decodifica comuni
|
||
m.send_key(K_TAB, O_COMUNENAS);
|
||
}
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::occas_handler( TMask_field& f, KEY key )
|
||
{
|
||
TDocumento_mask & m = (TDocumento_mask &)f.mask();
|
||
if ( key == K_SPACE && m.is_running( ) )
|
||
{
|
||
TDocumento& doc = m.doc();
|
||
TOccasionale& occ = doc.occas();
|
||
|
||
TMask occas_mask("ve0100o");
|
||
occas_mask.set_handler( O_CODICE, occas_code_handler );
|
||
|
||
for (int i = occas_mask.fields() - 1; i >= 0; i--)
|
||
{
|
||
TMask_field & f = occas_mask.fld(i);
|
||
const TFieldref * c = f.field();
|
||
if (c)
|
||
f.set(c->read(occ));
|
||
}
|
||
if (occas_mask.run() != K_ESC)
|
||
{
|
||
const TString ocfpi(occas_mask.get(O_CODICE));
|
||
doc.put("OCFPI", ocfpi);
|
||
m.set(F_OCFPI, ocfpi);
|
||
|
||
for (int i = occas_mask.fields() - 1; i >= 0; i--)
|
||
{
|
||
const TMask_field& f = occas_mask.fld(i);
|
||
const TFieldref* c = f.field();
|
||
if (c)
|
||
{
|
||
const char* val = f.get();
|
||
c->write(val, occ);
|
||
}
|
||
}
|
||
m.occ2mask();
|
||
}
|
||
f.set_focus( );
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::clifo_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key != K_ENTER && f.to_check(key, true))
|
||
{
|
||
TDocumento_mask & m = (TDocumento_mask &) f.mask();
|
||
TDocumento & d = m.doc();
|
||
|
||
TTipo_documento& tdoc = (TTipo_documento&) d.tipo();
|
||
d.put(DOC_TIPOCF, tdoc.tipocf());
|
||
d.put(DOC_CODCF, f.get());
|
||
|
||
TCli_for & cli_for = d.clifor();
|
||
cli_for.put(CLI_CODCF, ""); // force reload
|
||
|
||
if ( cli_for.get_bool(CLI_SOSPESO) )
|
||
return f.error_box( "Il codice '%ld' e' sospeso e non puo' essere utilizzato", atol(f.get()));
|
||
|
||
if (f.focusdirty())
|
||
d.spese_updated() = false;
|
||
|
||
m.cli2mask();
|
||
|
||
if (cli_for.occasionale())
|
||
{
|
||
TOccasionale& occas = d.occas();
|
||
if(m.id2pos(F_OCCASEDIT) > 0 && f.to_check(key) && *(occas.codice()) == '\0')
|
||
m.send_key( K_SPACE, F_OCCASEDIT ); // Lancia maschera occasionali
|
||
}
|
||
else
|
||
d.zero(DOC_OCFPI);
|
||
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
void TDocumento_mask::highlight(COLOR high_back_color, COLOR high_color)
|
||
{
|
||
TSheet_field & sf = sfield(F_SHEET);
|
||
const int items = sf.items();
|
||
|
||
for (int i = 0 ; i < items; i++)
|
||
{
|
||
const bool on = doc()[i + 1].linked();
|
||
|
||
COLOR back = on ? high_back_color : NORMAL_BACK_COLOR;
|
||
COLOR fore = on ? high_color : NORMAL_COLOR;
|
||
|
||
sf.set_back_and_fore_color(back, fore, i);
|
||
sf.force_update(i);
|
||
}
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TLista_elaborazioni
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TLista_elaborazioni : public TObject // velib04
|
||
{
|
||
TAssoc_array * _elab;
|
||
|
||
protected:
|
||
void read();
|
||
|
||
public:
|
||
TElaborazione & operator [](const char * key) const;
|
||
int select(TString_array & result, const char * tipo_iniziale = NULL, const char * stato_iniziale = NULL, const char * tipo_finale = NULL, const char * stato_finale = NULL);
|
||
void update();
|
||
TLista_elaborazioni() : _elab(NULL) {}
|
||
virtual ~TLista_elaborazioni();
|
||
};
|
||
|
||
void TLista_elaborazioni::read()
|
||
{
|
||
if (_elab == NULL)
|
||
{
|
||
_elab = new TAssoc_array();
|
||
|
||
TTable eld("%ELD");
|
||
|
||
for (int err = eld.first(); err == NOERR; err = eld.next())
|
||
{
|
||
TElaborazione * el = NULL;
|
||
switch (eld.curr().get_int("I0"))
|
||
{
|
||
case _esterna :
|
||
el = new TElaborazione_esterna(eld.curr());
|
||
break;
|
||
case _consegna_ordini:
|
||
el = new TConsegna_ordini(eld.curr());
|
||
break;
|
||
case _fatturazione_bolle :
|
||
el = new TFatturazione_bolle(eld.curr());
|
||
break;
|
||
case _contabilizzazione :
|
||
el = new TContabilizzazione(eld.curr());
|
||
break;
|
||
case _copia_documento :
|
||
el = new TCopia_documento(eld.curr());
|
||
break;
|
||
case _generazione_effetti :
|
||
el = new TGenerazione_effetti(eld.curr());
|
||
break;
|
||
case _consuntivazione_produzione :
|
||
el = new TConsuntivazione_produzione(eld.curr());
|
||
break;
|
||
case _contabilizzazione_analitica :
|
||
el = new TContabilizzazione_analitica(eld.curr());
|
||
break;
|
||
default :
|
||
break;
|
||
}
|
||
_elab->add(el->codice(), el);
|
||
}
|
||
}
|
||
}
|
||
|
||
int TLista_elaborazioni::select(TString_array & result, const char * tipo_iniziale, const char * stato_iniziale, const char * tipo_finale, const char * stato_finale)
|
||
{
|
||
read();
|
||
_elab->restart();
|
||
result.destroy();
|
||
for (TElaborazione * el = (TElaborazione *)_elab->get(); el ; el = (TElaborazione *) _elab->get())
|
||
{
|
||
bool ok = FALSE;
|
||
TString ti;
|
||
if ((tipo_iniziale && *tipo_iniziale) && (stato_iniziale && *stato_iniziale))
|
||
for (int i = 0; !ok && i < TElaborazione::_max_tipi_doc_elab; i++)
|
||
{
|
||
ti = el->tipo_iniziale(i);
|
||
const char si = el->stato_iniziale(i);
|
||
ok |= ti == tipo_iniziale &&
|
||
si == *stato_iniziale;
|
||
}
|
||
else
|
||
ok = TRUE;
|
||
if ((tipo_finale && *tipo_finale) && (stato_finale && *stato_finale))
|
||
ok &= el->tipo_finale() == tipo_finale &&
|
||
el->stato_finale() == stato_finale;
|
||
if (ok)
|
||
result.add(el->codice());
|
||
}
|
||
return result.items();
|
||
}
|
||
|
||
TElaborazione & TLista_elaborazioni::operator [](const char * key) const
|
||
{
|
||
((TLista_elaborazioni *)this)->read();
|
||
return (TElaborazione &) (*_elab)[key];
|
||
}
|
||
|
||
void TLista_elaborazioni::update()
|
||
{
|
||
delete _elab; _elab = NULL;
|
||
read();
|
||
}
|
||
|
||
TLista_elaborazioni::~TLista_elaborazioni()
|
||
{
|
||
if (_elab)
|
||
delete _elab;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDocument_tree
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TDocument_tree : public TBidirectional_tree
|
||
{
|
||
TRelation* _relation;
|
||
TCursor* _cursor;
|
||
TToken_string _curnode;
|
||
bool _multiple_selection;
|
||
TAssoc_array _selected_docs;
|
||
TString _selected;
|
||
|
||
|
||
protected:
|
||
virtual void node2id(const TObject* node, TString& id) const;
|
||
bool on_head() const;
|
||
bool on_row() const;
|
||
|
||
void format_field(const TRectype& rec, const TString& field, TString& str) const;
|
||
void append_custom_fields(const TTipo_documento& tipo, const TRectype& rec, TString& str) const;
|
||
|
||
public:
|
||
void multiple_selection(bool on);
|
||
bool multiple_selection() const { return _multiple_selection;}
|
||
bool node_selected(const TObject* node = NULL) const;
|
||
void select_node(const TObject* node = NULL, bool on = true);
|
||
real select_doc(long numdoc);
|
||
void build_doc_list(TLista_documenti & docs);
|
||
void unselect_node(const TObject* node) { select_node(node, false);}
|
||
virtual bool goto_root();
|
||
virtual bool goto_firstson();
|
||
virtual bool goto_rbrother();
|
||
virtual bool goto_node(const TString &id);
|
||
virtual bool has_son() const;
|
||
virtual bool has_rbrother() const;
|
||
virtual bool has_father() const;
|
||
virtual bool has_lbrother() const;
|
||
virtual bool goto_father();
|
||
virtual bool goto_lbrother();
|
||
virtual TObject* curr_node() const { return &(TToken_string&)_curnode; }
|
||
virtual bool get_description(TString& str) const;
|
||
virtual TImage* image(bool selected) const;
|
||
|
||
void select(TString & id) { _selected = id;}
|
||
const TString & selected() const { return _selected;}
|
||
|
||
const TRectype& testata() const;
|
||
const TRectype& riga() const;
|
||
const TRectype& record() const;
|
||
const real totale_doc() const { TDocumento d(testata()); return d.totale_doc();}
|
||
|
||
void set_cursor(char tipocf, long codcf, int anno, const char* filter, FILTERFUNCTION ff = NULL);
|
||
TCursor* get_cursor() { return _cursor; }
|
||
|
||
TDocument_tree();
|
||
~TDocument_tree();
|
||
};
|
||
|
||
const TRectype& TDocument_tree::testata() const
|
||
{
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
const TRecnotype pos = me._curnode.get_long(0);
|
||
if (_cursor->pos() != pos || _relation->curr(LF_RIGHEDOC).empty())
|
||
*me._cursor = pos;
|
||
return _relation->curr();
|
||
}
|
||
|
||
const TRectype& TDocument_tree::riga() const
|
||
{
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
const TRectype& rec = _relation->curr(LF_RIGHEDOC);
|
||
const TRecnotype pos = me._curnode.get_long(0);
|
||
const int nriga = me._curnode.get_int(1);
|
||
if (_cursor->pos() != pos || rec.get_int(RDOC_NRIGA) > nriga)
|
||
*me._cursor = pos;
|
||
for (int i = rec.get_int(RDOC_NRIGA); i < nriga; i++)
|
||
_relation->next_match(LF_RIGHEDOC);
|
||
return rec;
|
||
}
|
||
|
||
const TRectype& TDocument_tree::record() const
|
||
{
|
||
return on_row() ? riga() : testata();
|
||
}
|
||
|
||
void TDocument_tree::node2id(const TObject* node, TString& id) const
|
||
{
|
||
id = *(TString*)node;
|
||
}
|
||
|
||
bool TDocument_tree::on_head() const
|
||
{
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
return me._curnode.get_int(1) == 0;
|
||
}
|
||
|
||
bool TDocument_tree::on_row() const
|
||
{
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
return me._curnode.get_int(1) > 0;
|
||
}
|
||
|
||
void TDocument_tree::multiple_selection(bool on)
|
||
{
|
||
_multiple_selection = on;
|
||
if (!_multiple_selection)
|
||
_selected_docs.destroy();
|
||
|
||
}
|
||
|
||
bool TDocument_tree::node_selected(const TObject* node) const
|
||
{
|
||
TToken_string id;
|
||
|
||
if (node == NULL)
|
||
node = curr_node();
|
||
|
||
node2id(node, id);
|
||
id = id.get(0);
|
||
return _selected_docs.is_key(id);
|
||
}
|
||
|
||
void TDocument_tree::select_node(const TObject* node, bool on)
|
||
{
|
||
TToken_string id;
|
||
|
||
if (node == NULL)
|
||
node = curr_node();
|
||
|
||
node2id(node, id);
|
||
id = id.get(0);
|
||
if (on)
|
||
_selected_docs.add(id);
|
||
else
|
||
_selected_docs.remove(id);
|
||
select(id);
|
||
}
|
||
|
||
bool find_doc(TTree& tree, void* jolly, word flags)
|
||
{
|
||
TDocument_tree & t = (TDocument_tree &) tree;
|
||
if (!t.node_selected())
|
||
{
|
||
t.select_node();
|
||
real & val = *((real *) jolly);
|
||
val = t.totale_doc();
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
real TDocument_tree::select_doc(long numdoc)
|
||
|
||
{
|
||
real val;
|
||
if (goto_root())
|
||
scan_depth_first(find_doc, (void *) &val, SCAN_PRE_ORDER | SCAN_IGNORING_LEAVES);
|
||
return val;
|
||
}
|
||
|
||
bool add_to_list(TTree& tree, void* jolly, word flags)
|
||
{
|
||
TDocument_tree & t = (TDocument_tree &) tree;
|
||
if (t.node_selected())
|
||
{
|
||
TLista_documenti & docs = *((TLista_documenti *) jolly);
|
||
|
||
docs.add(new TDocumento(t.testata()));
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void TDocument_tree::build_doc_list(TLista_documenti & docs)
|
||
|
||
{
|
||
if (goto_root())
|
||
scan_depth_first(add_to_list, (void *) &docs, SCAN_PRE_ORDER | SCAN_IGNORING_LEAVES);
|
||
}
|
||
|
||
bool TDocument_tree::goto_root()
|
||
{
|
||
const bool ok = _cursor != NULL && _cursor->items()>0;
|
||
_curnode = ok ? "0" : "";
|
||
*_cursor = 0;
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::goto_firstson()
|
||
{
|
||
bool ok = has_son();
|
||
if (ok)
|
||
_curnode.add(1,1);
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::goto_rbrother()
|
||
{
|
||
bool ok = has_rbrother();
|
||
if (ok)
|
||
{
|
||
if (on_head())
|
||
{
|
||
const long pos = _curnode.get_long(0);
|
||
_curnode.add(pos+1, 0);
|
||
}
|
||
else
|
||
{
|
||
const int nriga = _curnode.get_int(1);
|
||
_curnode.add(nriga+1, 1);
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::goto_node(const TString &id)
|
||
{
|
||
_curnode = id;
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocument_tree::has_son() const
|
||
{
|
||
bool ok = on_head();
|
||
if (ok)
|
||
{
|
||
testata();
|
||
const TRectype& rec = _relation->curr(LF_RIGHEDOC);
|
||
ok = rec.get_int(RDOC_NRIGA) > 0;
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::has_rbrother() const
|
||
{
|
||
bool ok = FALSE;
|
||
if (on_head())
|
||
{
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
const long pos = me._curnode.get_long(0);
|
||
ok = pos < _cursor->items()-1;
|
||
}
|
||
else
|
||
{
|
||
riga(); // Posizionati sulla riga corrente
|
||
ok = _relation->next_match(LF_RIGHEDOC);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::has_father() const
|
||
{
|
||
return on_row();
|
||
}
|
||
|
||
bool TDocument_tree::has_lbrother() const
|
||
{
|
||
bool ok = FALSE;
|
||
TDocument_tree& me = (TDocument_tree&)*this;
|
||
if (on_head())
|
||
{
|
||
const long pos = me._curnode.get_long(0);
|
||
ok = pos > 0L;
|
||
}
|
||
else
|
||
{
|
||
const int nriga = me._curnode.get_int(1);
|
||
ok = nriga > 1;
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::goto_father()
|
||
{
|
||
bool ok = on_row();
|
||
if (ok)
|
||
_curnode.add(0, 1);
|
||
return ok;
|
||
}
|
||
|
||
bool TDocument_tree::goto_lbrother()
|
||
{
|
||
bool ok = has_lbrother();
|
||
if (ok)
|
||
{
|
||
if (on_head())
|
||
{
|
||
const long pos = _curnode.get_long(0);
|
||
_curnode.add(pos-1, 0);
|
||
}
|
||
else
|
||
{
|
||
const int nriga = _curnode.get_int(1);
|
||
_curnode.add(nriga-1, 1);
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
void TDocument_tree::format_field(const TRectype& rec, const TString& field, TString& str) const
|
||
{
|
||
const TFieldref fld(field, rec.num());
|
||
const TString& value = fld.read(rec);
|
||
const TFieldtypes ft = rec.type(fld.name());
|
||
if (ft == _realfld)
|
||
{
|
||
const int len = rec.length(fld.name());
|
||
const int ndec = rec.ndec(fld.name());
|
||
TString8 pic; pic.format(".%d", ndec);
|
||
const real r(value);
|
||
str = r.string(pic);
|
||
str.right_just(len);
|
||
}
|
||
else
|
||
str = value;
|
||
}
|
||
|
||
void TDocument_tree::append_custom_fields(const TTipo_documento& tipo, const TRectype& rec, TString& str) const
|
||
{
|
||
const TString& format = rec.num() == LF_DOC ? tipo.stringa_descrizione_documento()
|
||
: tipo.stringa_descrizione_riga();
|
||
if (format.not_empty())
|
||
{
|
||
str << ' ';
|
||
int ch = -1;
|
||
TString tmp;
|
||
for (int ap = format.find('{'); ap >= 0; ap = format.find('{', ch+1))
|
||
{
|
||
str << format.sub(ch+1, ap);
|
||
ch = format.find('}', ap);
|
||
const TString16 field = format.sub(ap+1, ch);
|
||
if (!field.blank())
|
||
{
|
||
format_field(rec, field, tmp);
|
||
str << tmp;
|
||
}
|
||
}
|
||
str << format.mid(ch+1);
|
||
}
|
||
}
|
||
|
||
TImage* TDocument_tree::image(bool selected) const
|
||
{
|
||
if (on_row())
|
||
{
|
||
const TRectype& rec = riga();
|
||
if (rec.get_bool(RDOC_RIGAEVASA))
|
||
return get_res_image(BMP_STOP);
|
||
}
|
||
else
|
||
if (multiple_selection())
|
||
{
|
||
const bool sel = node_selected();
|
||
|
||
if (sel)
|
||
{
|
||
if (selected)
|
||
return get_res_image(BMP_DIRDNSEL);
|
||
else
|
||
return get_res_image(BMP_DIRSEL);
|
||
}
|
||
}
|
||
return TTree::image(selected);
|
||
}
|
||
|
||
bool TDocument_tree::get_description(TString& str) const
|
||
{
|
||
if (on_head())
|
||
{
|
||
const TRectype& rec = testata();
|
||
str = rec.get(DOC_ANNO);
|
||
str << ' ' << rec.get(DOC_CODNUM);
|
||
TString16 tmp;
|
||
tmp.format("%6ld", rec.get_long(DOC_NDOC));
|
||
str << ' ' << tmp << ' ' << rec.get(DOC_DATADOC);
|
||
const char tipocf = rec.get_char(DOC_TIPOCF);
|
||
const long codcf = rec.get_long(DOC_CODCF);
|
||
tmp.format(" %c%6ld ", tipocf, codcf);
|
||
str << tmp;
|
||
tmp.format("%c|%6ld", tipocf, codcf);
|
||
str << cache().get(LF_CLIFO, tmp, CLI_RAGSOC);
|
||
str.left_just(63);
|
||
|
||
const TString& tipodoc = rec.get(DOC_TIPODOC);
|
||
const TTipo_documento& tipo = TDocumento::tipo(tipodoc);
|
||
append_custom_fields(tipo, rec, str);
|
||
}
|
||
else
|
||
{
|
||
const TRectype& rec = riga();
|
||
const TRectype& testata = _relation->curr();
|
||
|
||
const TString80 codart = rec.get(RDOC_CODART);
|
||
str = codart;
|
||
str.left_just(21);
|
||
str << rec.get(RDOC_DESCR).left(30);
|
||
str.left_just(52);
|
||
|
||
const TString& tipodoc = testata.get(DOC_TIPODOC);
|
||
const TTipo_documento& tipo = TDocumento::tipo(tipodoc);
|
||
if (codart.not_empty())
|
||
{
|
||
const real qta = rec.get_real(tipo.field_qta());
|
||
str << qta.string("###.###.##@,@@@");
|
||
|
||
if (tipo.is_ordine())
|
||
{
|
||
const real qta_evasa = rec.get_real(tipo.field_qtaevasa());
|
||
const real residuo = qta_evasa < qta ? (qta-qta_evasa) : ZERO;
|
||
str << residuo.string("###.###.##@,@@@");
|
||
}
|
||
append_custom_fields(tipo, rec, str);
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
void TDocument_tree::set_cursor(char tipocf, long codcf, int anno, const char* filter, FILTERFUNCTION ff)
|
||
{
|
||
if (_relation == NULL)
|
||
{
|
||
_relation = new TRelation(LF_DOC);
|
||
_relation->add(LF_RIGHEDOC, "PROVV==PROVV|ANNO==ANNO|CODNUM==CODNUM|NDOC==NDOC");
|
||
}
|
||
if (_cursor == NULL)
|
||
{
|
||
_cursor = new TCursor(_relation, "", 2);
|
||
}
|
||
TRectype& rec = _relation->curr();
|
||
rec.zero();
|
||
rec.put(DOC_TIPOCF, tipocf);
|
||
rec.put(DOC_CODCF, codcf);
|
||
rec.put(DOC_PROVV, "D");
|
||
rec.put(DOC_ANNO, anno);
|
||
_cursor->freeze(FALSE);
|
||
_cursor->setfilter(""); // Force cursor rebuild
|
||
_cursor->setfilter(filter);
|
||
_cursor->setregion(rec, rec);
|
||
const long items = _cursor->items();
|
||
_cursor->freeze(TRUE);
|
||
|
||
goto_root();
|
||
if (items <= 3)
|
||
expand_all();
|
||
}
|
||
|
||
TDocument_tree::TDocument_tree()
|
||
: _relation(NULL), _cursor(NULL), _multiple_selection(false)
|
||
|
||
{
|
||
}
|
||
|
||
TDocument_tree::~TDocument_tree()
|
||
{
|
||
if (_cursor)
|
||
delete _cursor;
|
||
if (_relation)
|
||
delete _relation;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TElabora_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TElabora_mask : public TAutomask
|
||
{
|
||
TDocumento_mask* _main;
|
||
TLista_elaborazioni _elab;
|
||
TDocument_tree _tree;
|
||
int _check_fld;
|
||
|
||
TElaborazione* _last_elab;
|
||
|
||
// @access Protected Member
|
||
protected:
|
||
TString _art_filter, _liv_filter;
|
||
static TElabora_mask* _myself;
|
||
static bool article_filter(const TRelation* rel);
|
||
|
||
void add_valuta_filter(TString& filter) const;
|
||
|
||
void docrif_search();
|
||
int update_list();
|
||
void update_ndoc_filter(bool is_tipo_elaborazione = FALSE);
|
||
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
// @access Public Member
|
||
public:
|
||
bool elabora();
|
||
TElaborazione* curr_elab();
|
||
|
||
// @cmember Costruttore (crea la maschera leggendo la descrizione dal file .msk)
|
||
TElabora_mask(TDocumento_mask& main_mask);
|
||
// @cmember Distruttore
|
||
virtual ~TElabora_mask() {}
|
||
};
|
||
|
||
TElabora_mask* TElabora_mask::_myself = NULL;
|
||
|
||
bool TElabora_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_CODART:
|
||
case F_CODNUM_ELAB:
|
||
if (e == fe_modify)
|
||
update_ndoc_filter();
|
||
break;
|
||
case F_TYPE:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
int ne = update_list();
|
||
if (e == fe_init && ne == 0) // Riprova a cambiare flag e ricostruire la lista
|
||
{
|
||
set(F_TYPE, "X");
|
||
ne = update_list();
|
||
if (ne == 0)
|
||
set(F_TYPE, "");
|
||
}
|
||
update_ndoc_filter(TRUE);
|
||
const bool add_to_doc = o.get().not_empty();
|
||
TElaborazione * e = curr_elab();
|
||
const bool external = e != NULL && e->tipo() == _esterna;
|
||
const bool is_search = o.get().empty() || field(F_CODCF_ELAB).empty() || external;
|
||
|
||
o.mask().field(F_NDOC_ELAB).check_type(is_search ? CHECK_SEARCH : CHECK_NORMAL);
|
||
_tree.multiple_selection(add_to_doc);
|
||
bool check_tot = false;
|
||
if (add_to_doc)
|
||
{
|
||
if (_check_fld < -1)
|
||
{
|
||
_check_fld = -1;
|
||
const TString_array& handlers = _main->doc().tipo().handlers();
|
||
const int items = handlers.items();
|
||
|
||
for (int i = 0; i < items; i ++ )
|
||
{
|
||
TToken_string& riga = (TToken_string&) handlers[i];
|
||
|
||
if (riga.get_int(1) == 2)
|
||
_check_fld = riga.get_int(0);
|
||
}
|
||
}
|
||
check_tot = _check_fld >= 0;
|
||
}
|
||
if (!add_to_doc)
|
||
o.mask().set(F_TOTSEL, "");
|
||
o.mask().show(-GRP_CHK, check_tot);
|
||
if (check_tot)
|
||
o.mask().set(F_TOTVAL, _main->get(_check_fld));
|
||
}
|
||
break;
|
||
case F_STATODOC_ELAB:
|
||
case F_TIPODOC_ELAB:
|
||
if (e == fe_modify)
|
||
{
|
||
update_list();
|
||
update_ndoc_filter();
|
||
}
|
||
break;
|
||
case F_ELAB:
|
||
if (e == fe_modify)
|
||
update_ndoc_filter(TRUE);
|
||
break;
|
||
case F_ANNO_ELAB:
|
||
if (e == fe_modify)
|
||
update_ndoc_filter();
|
||
break;
|
||
case F_NUMDOCRIF_ELAB:
|
||
if (e == fe_button)
|
||
docrif_search();
|
||
break;
|
||
case F_NDOC_ELAB:
|
||
if ((e == fe_modify || e == fe_close) && o.check_type() == CHECK_SEARCH && !o.empty())
|
||
{
|
||
TToken_string key;
|
||
key.add("D"); key.add(get(F_ANNO_ELAB));
|
||
key.add(get(F_CODNUM_ELAB)); key.add(o.get());
|
||
const TRectype& rec = cache().get(LF_DOC, key);
|
||
bool ok = !rec.empty(); // Verifica esistenza documento
|
||
|
||
if (ok)
|
||
{
|
||
TCursor* c = _tree.get_cursor();
|
||
c->curr() = rec;
|
||
ok = c->test(_isequal) == NOERR; // Verifica compatibilit<69> documento
|
||
}
|
||
if (!ok)
|
||
return error_box(((TEdit_field&)o).get_warning());
|
||
}
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
const long ndoc = atol(o.get());
|
||
|
||
if (ndoc > 0L)
|
||
{
|
||
real val = _tree.select_doc(ndoc);
|
||
if (val != ZERO)
|
||
{
|
||
val += o.mask().get_real(F_TOTSEL);
|
||
o.mask().set(F_TOTSEL, val);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
|
||
case F_ROWS:
|
||
if (e == fe_modify && is_running())
|
||
{
|
||
TString id;
|
||
|
||
_tree.curr_id(id);
|
||
_tree.select(id);
|
||
if (is_running() && !_tree.multiple_selection())
|
||
{
|
||
TCursor* c = _tree.get_cursor();
|
||
if (c != NULL && c->items() > 0)
|
||
{
|
||
const TRectype& head = _tree.testata();
|
||
set(F_DATADOC_ELAB, head.get(DOC_DATADOC)); // Anch'essa nella chiave 2!
|
||
set(F_ANNO_ELAB, head.get(DOC_ANNO));
|
||
set(F_CODNUM_ELAB, head.get(DOC_CODNUM), 2); // Check but not hit
|
||
set(F_NDOC_ELAB, head.get(DOC_NDOC));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
if (e == fe_select)
|
||
{
|
||
if (_tree.multiple_selection())
|
||
{
|
||
const bool on = !_tree.node_selected();
|
||
_tree.select_node(NULL, on);
|
||
if (_check_fld >= 0)
|
||
{
|
||
real val = get_real(F_TOTSEL);
|
||
if (on)
|
||
val += _tree.totale_doc();
|
||
else
|
||
{
|
||
val -= _tree.totale_doc();
|
||
if (_tree.testata().get_long(DOC_NDOC) == o.mask().get_long(F_NDOC_ELAB))
|
||
o.mask().set(F_NDOC_ELAB, "");
|
||
}
|
||
set(F_TOTSEL, val);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case DLG_LINK:
|
||
if (e == fe_button)
|
||
{
|
||
_tree.goto_node(_tree.selected());
|
||
const TRectype & rec = _tree.testata();
|
||
|
||
if (!rec.empty())
|
||
{
|
||
TFilename tempfile;
|
||
|
||
tempfile.temp("ve0");
|
||
tempfile.ext("ini");
|
||
|
||
{
|
||
TConfig configfile(tempfile);
|
||
|
||
configfile.set("Action", "Modify", "Transaction");
|
||
configfile.set("NDOC", rec.get(DOC_NDOC), "33");
|
||
configfile.set(DOC_PROVV, rec.get(DOC_PROVV), "33");
|
||
configfile.set(DOC_ANNO, rec.get(DOC_ANNO), "33");
|
||
configfile.set(DOC_CODNUM, rec.get(DOC_CODNUM), "33");
|
||
}
|
||
|
||
TString commandline;
|
||
|
||
commandline.format("ve0 -0 /i%s",(const char*)tempfile);
|
||
|
||
TExternal_app ve(commandline);
|
||
ve.run();
|
||
|
||
remove_file(tempfile);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
int TElabora_mask::update_list()
|
||
{
|
||
TString_array elabs;
|
||
const TString16 tipo(_main->get(F_TIPODOC));
|
||
const TString16 stato(_main->get(F_STATO));
|
||
const TString16 tipo_elab(get(F_TIPODOC_ELAB));
|
||
const TString16 stato_elab(get(F_STATODOC_ELAB));
|
||
const bool from_elab = !get_bool(F_TYPE);
|
||
int items = 0;
|
||
|
||
if (from_elab)
|
||
{
|
||
items = _elab.select(elabs, tipo, stato,"","") ;
|
||
field(F_ANNO_ELAB).check_type(CHECK_REQUIRED);
|
||
}
|
||
else
|
||
{
|
||
field(F_ANNO_ELAB).check_type(CHECK_NONE);
|
||
items = _elab.select(elabs, tipo_elab, stato_elab, tipo, stato);
|
||
}
|
||
|
||
TList_field & f = (TList_field &) field(F_ELAB);
|
||
TToken_string codes;
|
||
TToken_string descrs;
|
||
for (int i = 0; i < items; i++)
|
||
{
|
||
const TElaborazione& e = _elab[elabs.row(i)];
|
||
|
||
if (!from_elab)
|
||
{
|
||
// AO20123: Impedire contabilizzazione all'indietro!
|
||
if (e.tipo() == _contabilizzazione || e.tipo() == _generazione_effetti)
|
||
continue;
|
||
}
|
||
|
||
codes.add(e.codice());
|
||
descrs.add(e.descrizione());
|
||
}
|
||
|
||
items = codes.items(); // Conta elementi veramente aggiunti
|
||
const bool ok = items > 0;
|
||
enable(DLG_OK, ok);
|
||
enable(F_ELAB, ok);
|
||
|
||
if (codes != f.get_codes())
|
||
f.replace_items(codes, descrs);
|
||
const TElaborazione * e = curr_elab();
|
||
if (e != NULL && e->tipo() == _consegna_ordini)
|
||
show(-GRP_ART);
|
||
else
|
||
{
|
||
reset(-GRP_ART);
|
||
hide(-GRP_ART);
|
||
}
|
||
|
||
return items;
|
||
}
|
||
|
||
bool TElabora_mask::elabora()
|
||
{
|
||
bool update_mask = FALSE;
|
||
|
||
TLista_documenti in;
|
||
TLista_documenti out;
|
||
TDocumento& app_doc = ((TDocumento_mask *)_main)->doc();
|
||
const long numdoc = field(F_NDOC_ELAB).active() ? get_long(F_NDOC_ELAB) : app_doc.get_long(DOC_NDOC);
|
||
const bool update_header = get_bool(F_UPDATE_HEADER);
|
||
const bool from_elab = !get_bool(F_TYPE);
|
||
TElaborazione * e = curr_elab();
|
||
|
||
if (e == NULL)
|
||
return FALSE;
|
||
|
||
if (e->tipo() == _consegna_ordini)
|
||
{
|
||
TParametri_elaborazione& p = e->params();
|
||
p.set("ARTICOLO", get(F_CODART));
|
||
p.set("UM", get(F_UMQTA));
|
||
p.set("QUANTITA", get(F_QTA));
|
||
}
|
||
if (from_elab)
|
||
{
|
||
const char provv = get(F_PROVV_ELAB)[0];
|
||
const int anno = get_int(F_ANNO_ELAB);
|
||
const TString& codnum = get(F_CODNUM_ELAB);
|
||
const TString& tipo = get(F_TIPODOC_ELAB);
|
||
const TString& stato = get(F_STATODOC_ELAB);
|
||
|
||
if (anno <= 0 || codnum.blank() || tipo.blank() || stato.blank())
|
||
return false;
|
||
|
||
TDocumento* newdoc = new TDocumento(provv, anno, codnum, numdoc);
|
||
TDocumento& d = *newdoc;
|
||
|
||
if (numdoc <= 0)
|
||
{
|
||
TDocumento::copy_data(d.head(), app_doc.head());
|
||
d.put(DOC_TIPODOC, tipo);
|
||
d.put(DOC_STATO, stato);
|
||
|
||
const TDate datadoc = d.get_date(DOC_DATADOC);
|
||
const TDate datainsc = d.get_date(DOC_DATAINSC);
|
||
const bool equal = !datainsc.ok() || datadoc == datainsc;
|
||
|
||
d.put(DOC_DATADOC, get(F_DATADOC_ELAB));
|
||
if (equal)
|
||
d.zero(DOC_DATAINSC);
|
||
|
||
const TTipo_documento & t = d.tipo();
|
||
|
||
if (t.mov_mag())
|
||
d.put(DOC_CAUSMAG, t.caus_mov());
|
||
else
|
||
d.zero(DOC_CAUSMAG);
|
||
}
|
||
in.add(app_doc);
|
||
out.add(d);
|
||
if (e->elabora(in, out, TDate(TODAY), TRUE))
|
||
{
|
||
if (out[0] != d)
|
||
out.rewrite();
|
||
if (app_doc != in[0])
|
||
{
|
||
in.rewrite();
|
||
app_doc = in[0];
|
||
update_mask = TRUE;
|
||
}
|
||
}
|
||
delete newdoc;
|
||
|
||
}
|
||
else
|
||
{
|
||
_tree.build_doc_list(in);
|
||
char provv = get(F_PROVV_ELAB)[0];
|
||
int anno = get_int(F_ANNO_ELAB);
|
||
TString16 codnum(get(F_CODNUM_ELAB));
|
||
long ndoc = get_long(F_NDOC_ELAB);
|
||
|
||
if (ndoc > 0L && !in.find(provv, anno, codnum, ndoc))
|
||
{
|
||
TDocumento* d = new TDocumento(provv, anno, codnum, ndoc);
|
||
|
||
in.add(d);
|
||
}
|
||
if (update_header)
|
||
{
|
||
const TString16 tipo_doc(app_doc.get(DOC_TIPODOC));
|
||
const TString16 caus_mag(app_doc.get(DOC_CAUSMAG));
|
||
const long movmag = app_doc.get_long(DOC_MOVMAG);
|
||
const TDate datadoc = app_doc.get_date(DOC_DATADOC);
|
||
const TDate datainsc = app_doc.get_date(DOC_DATAINSC);
|
||
const char stato = app_doc.stato();
|
||
|
||
TDocumento::copy_data(app_doc.head(), in[0].head());
|
||
|
||
app_doc.put(DOC_TIPODOC, tipo_doc);
|
||
app_doc.put(DOC_CAUSMAG, caus_mag);
|
||
app_doc.put(DOC_MOVMAG, movmag);
|
||
app_doc.put(DOC_DATADOC, datadoc);
|
||
app_doc.put(DOC_DATAINSC, datainsc);
|
||
app_doc.put(DOC_STATO, stato);
|
||
}
|
||
out.add(app_doc);
|
||
if (e->elabora(in, out, TDate(TODAY), TRUE))
|
||
{
|
||
if (out[0] != app_doc)
|
||
{
|
||
out.rewrite();
|
||
app_doc.read(out[0].head());
|
||
update_mask = TRUE;
|
||
}
|
||
in.rewrite();
|
||
}
|
||
const TString8 num_in = e->codice_numerazione_iniziale();
|
||
set(F_CODNUM_ELAB, num_in);
|
||
set(F_NDOC_ELAB, "");
|
||
set(F_NUMDOCRIF_ELAB, "");
|
||
}
|
||
if (e->tipo() == _consegna_ordini)
|
||
{
|
||
TParametri_elaborazione& p = e->params();
|
||
if (p.get("ARTICOLO").not_empty())
|
||
{
|
||
real qta = get_real(F_QTA);
|
||
if (qta > ZERO)
|
||
{
|
||
const real qta_evasa = p.get_real("QUANTITA");
|
||
qta -= qta_evasa;
|
||
set(F_QTA, qta);
|
||
}
|
||
}
|
||
}
|
||
|
||
// delete newdoc;
|
||
|
||
// Azzera l'anno in caso di ordini
|
||
if (in.items() > 0 && in[0].is_ordine())
|
||
{
|
||
reset(F_ANNO_ELAB);
|
||
update_mask = TRUE;
|
||
}
|
||
|
||
if (update_mask)
|
||
update_ndoc_filter();
|
||
|
||
return update_mask;
|
||
}
|
||
|
||
TElaborazione * TElabora_mask::curr_elab()
|
||
{
|
||
const TString16 cod_elab(get(F_ELAB));
|
||
return cod_elab.not_empty() ? &_elab[cod_elab] : NULL;
|
||
}
|
||
|
||
bool TElabora_mask::article_filter(const TRelation* rel)
|
||
{
|
||
bool yes = FALSE;
|
||
TElabora_mask& m = *_myself;
|
||
TLocalisamfile rdoc(LF_RIGHEDOC);
|
||
rdoc.put(RDOC_CODNUM, rel->curr().get(DOC_CODNUM));
|
||
rdoc.put(RDOC_ANNO, rel->curr().get(DOC_ANNO));
|
||
rdoc.put(RDOC_PROVV, rel->curr().get(DOC_PROVV));
|
||
rdoc.put(RDOC_NDOC, rel->curr().get(DOC_NDOC));
|
||
rdoc.put(RDOC_NRIGA, 1);
|
||
int next_riga = 1;
|
||
for (int err = rdoc.read(); err == NOERR; err = rdoc.next())
|
||
{
|
||
const int nriga = rdoc.get_int(RDOC_NRIGA);
|
||
if (nriga != next_riga)
|
||
break;
|
||
next_riga++;
|
||
const bool evasa= rdoc.get_bool(RDOC_RIGAEVASA);
|
||
const TString& codart = rdoc.get(RDOC_CODART);
|
||
if (!evasa && codart == m._art_filter)
|
||
{
|
||
yes = TRUE;
|
||
break;
|
||
}
|
||
}
|
||
return yes;
|
||
}
|
||
|
||
void TElabora_mask::add_valuta_filter(TString& filter) const
|
||
{
|
||
TString16 valuta = get(F_CODVAL_ELAB);
|
||
if (::is_firm_value(valuta))
|
||
{
|
||
filter << "((CODVAL==\"" << valuta << "\")";
|
||
if (valuta.empty())
|
||
valuta = TCurrency::get_firm_val();
|
||
else
|
||
valuta.cut(0);
|
||
filter << "||(CODVAL==\"" << valuta << "\"))";
|
||
}
|
||
else
|
||
filter << "(CODVAL==\"" << valuta << "\")";
|
||
}
|
||
|
||
void TElabora_mask::update_ndoc_filter(bool is_tipo_elaborazione)
|
||
{
|
||
TString filter;
|
||
add_valuta_filter(filter);
|
||
|
||
TElaborazione * e = curr_elab();
|
||
const bool elab_changed = e != _last_elab;
|
||
_last_elab = e;
|
||
|
||
const bool aggiungi_doc_att = get_bool(F_TYPE);
|
||
enable(-1, aggiungi_doc_att);
|
||
if (!aggiungi_doc_att && is_tipo_elaborazione )
|
||
reset(-1);
|
||
|
||
const bool enable_group_doc = e != NULL && e->tipo() != _generazione_effetti && e->tipo() != _contabilizzazione;
|
||
show(-GRP_DOC, enable_group_doc);
|
||
|
||
if (e != NULL)
|
||
{
|
||
if (aggiungi_doc_att)
|
||
{
|
||
const bool agg_test = e->aggiorna_testata_se_vuoto() && _main->sfield(F_SHEET).items() == 0;
|
||
set(F_UPDATE_HEADER, agg_test ? "X" : "");
|
||
const TString8 num_in = e->codice_numerazione_iniziale();
|
||
if (elab_changed)
|
||
{
|
||
const TString16 tipo_in(e->tipo_iniziale(0));
|
||
const char stato_in = e->stato_iniziale(0);
|
||
|
||
set(F_CODNUM_ELAB, num_in);
|
||
field(F_CODNUM_ELAB).check();
|
||
set(F_TIPODOC_ELAB , tipo_in);
|
||
field(F_TIPODOC_ELAB).check();
|
||
TString8 si; si << stato_in;
|
||
set(F_STATODOC_ELAB, si);
|
||
field(F_STATODOC_ELAB).check();
|
||
|
||
// Azzero anno di elaaborazione quando ho a che fare con degli ordini
|
||
const TTipo_documento& tipodocin = _main->doc().tipo(tipo_in);
|
||
if (tipodocin.is_ordine())
|
||
reset(F_ANNO_ELAB);
|
||
}
|
||
|
||
if (!field(F_TIPODOC_ELAB).empty())
|
||
{
|
||
const TString16 tipo(get(F_TIPODOC_ELAB));
|
||
TString80 td; td.format("&&(TIPODOC==\"%s\")", (const char *)tipo);
|
||
filter << td;
|
||
const TString& stato = get(F_STATODOC_ELAB);
|
||
if (stato.not_empty())
|
||
{
|
||
filter << "&&(STATO==\"" << stato << "\")";
|
||
}
|
||
else
|
||
{
|
||
bool almost_one = FALSE;
|
||
|
||
for (int i = 0; i < TElaborazione::_max_tipi_doc_elab; i++)
|
||
{
|
||
const TString16 tipo_in(e->tipo_iniziale(i));
|
||
const char stato_in = e->stato_iniziale(i);
|
||
|
||
if (tipo == tipo_in && stato_in > '0')
|
||
{
|
||
if (almost_one)
|
||
filter << "||";
|
||
else
|
||
filter << "&&(";
|
||
almost_one = TRUE;
|
||
|
||
filter << "(STATO==\"" << stato_in << "\")";
|
||
}
|
||
}
|
||
if (almost_one)
|
||
filter << ')';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bool almost_one = FALSE;
|
||
|
||
for (int i = 0; i < TElaborazione::_max_tipi_doc_elab; i++)
|
||
{
|
||
const TString16 tipo_in(e->tipo_iniziale(i));
|
||
if (tipo_in.not_empty())
|
||
{
|
||
if (almost_one)
|
||
filter << "||";
|
||
else
|
||
filter << "&&(";
|
||
almost_one = TRUE;
|
||
filter << "((TIPODOC==\"" << tipo_in << "\")";
|
||
|
||
const char stato_in[2] = { e->stato_iniziale(i), '\0' };
|
||
if (stato_in[0] > '0')
|
||
filter << "&&(STATO==\"" << stato_in << "\")";
|
||
filter << ')';
|
||
}
|
||
}
|
||
if (almost_one)
|
||
filter << ')';
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const TString4 tipo_fin(e->tipo_finale());
|
||
const TString4 stato_fin(e->stato_finale());
|
||
|
||
set(F_UPDATE_HEADER, "");
|
||
filter << "&&";
|
||
if (stato_fin != "0")
|
||
filter << '(';
|
||
filter << "(TIPODOC==\"" << tipo_fin << "\")";
|
||
if (stato_fin != "0")
|
||
filter << "&&(STATO==\"" << stato_fin << "\"))";
|
||
|
||
if (is_tipo_elaborazione)
|
||
{
|
||
const TString16 num_fin(e->codice_numerazione_finale());
|
||
set(F_CODNUM_ELAB, num_fin);
|
||
field(F_CODNUM_ELAB).check();
|
||
set(F_TIPODOC_ELAB, tipo_fin);
|
||
field(F_TIPODOC_ELAB).check();
|
||
set(F_STATODOC_ELAB, stato_fin);
|
||
field(F_STATODOC_ELAB).check();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!field(F_CODNUM_ELAB).empty())
|
||
{
|
||
TString80 cn; cn.format("&&(CODNUM==\"%s\")", (const char*)get(F_CODNUM_ELAB));
|
||
filter << cn;
|
||
}
|
||
|
||
TBrowse& brew = *efield(F_NDOC_ELAB).browse();
|
||
brew.set_filter(filter);
|
||
|
||
_art_filter = get(F_CODART);
|
||
|
||
TCursor* cursor = brew.cursor();
|
||
if (_art_filter.not_empty() && aggiungi_doc_att)
|
||
cursor->set_filterfunction(article_filter);
|
||
else
|
||
cursor->set_filterfunction(NULL);
|
||
|
||
TTree_field& tf = tfield(F_ROWS);
|
||
if (!field(F_TIPODOC_ELAB).empty() && e != NULL)
|
||
{
|
||
tf.set_tree(&_tree);
|
||
TToken_string header(256, '\n');
|
||
header.add("Anno Num. N. Data Cli/For Ragione Sociale");
|
||
header.add(" Codice Articolo Descrizione Riga ");
|
||
if (aggiungi_doc_att && e->tipo() == _consegna_ordini)
|
||
header << "Da Evadere Residuo";
|
||
else
|
||
header << " Quantit<69>";
|
||
tf.set_header(header);
|
||
|
||
if (aggiungi_doc_att && _art_filter.not_empty())
|
||
_tree.set_cursor(get(F_TIPOCF_ELAB)[0], get_long(F_CODCF_ELAB), get_int(F_ANNO_ELAB), filter, article_filter);
|
||
else
|
||
_tree.set_cursor(get(F_TIPOCF_ELAB)[0], get_long(F_CODCF_ELAB), get_int(F_ANNO_ELAB), filter);
|
||
|
||
if (aggiungi_doc_att) // GF20059
|
||
{
|
||
TCursor& cur = *_tree.get_cursor();
|
||
if (cur.items() == 1) // Propone l'unico documento possibile
|
||
{
|
||
cur = 0L;
|
||
const TRectype& curr = cur.curr();
|
||
set(F_ANNO_ELAB, curr.get(DOC_ANNO));
|
||
set(F_NDOC_ELAB, curr.get(DOC_NDOC));
|
||
set(F_CODNUM_ELAB, curr.get(DOC_CODNUM), 2); // Check but not hit
|
||
set(F_DATADOC_ELAB, curr.get(DOC_DATADOC));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
tf.set_tree(NULL);
|
||
tf.win().force_update();
|
||
}
|
||
|
||
void TElabora_mask::docrif_search()
|
||
{
|
||
TRectype filtrec(LF_DOC);
|
||
filtrec.put(DOC_TIPOCF, get(F_TIPOCF_ELAB));
|
||
filtrec.put(DOC_CODCF, get(F_CODCF_ELAB));
|
||
filtrec.put(DOC_PROVV, get(F_PROVV_ELAB));
|
||
filtrec.put(DOC_ANNO, get(F_ANNO_ELAB));
|
||
|
||
TRelation rel(LF_DOC);
|
||
rel.add(LF_CLIFO, "TIPOCF==TIPOCF|CODCF==CODCF");
|
||
TSorted_cursor cur(&rel, "TIPOCF|CODCF|PROVV|ANNO|CODNUM|NUMDOCRIF", "", 2, &filtrec, &filtrec);
|
||
TString flt(256);
|
||
if (!field(F_CODNUM_ELAB).empty())
|
||
flt << "(CODNUM==\"" << get(F_CODNUM_ELAB) << "\")&&";
|
||
if (!field(F_TIPODOC_ELAB).empty())
|
||
flt << "(TIPODOC==\"" << get(F_TIPODOC_ELAB) << "\")&&";
|
||
if (!field(F_STATODOC_ELAB).empty())
|
||
flt << "(STATO==\"" << get(F_STATODOC_ELAB) << "\")&&";
|
||
add_valuta_filter(flt); flt << "&&";
|
||
TEdit_field& f = efield(F_NUMDOCRIF_ELAB);
|
||
if (!f.empty())
|
||
flt << "(NUMDOCRIF==\"" << f.get() << "\")&&";
|
||
flt.rtrim(2); // Togli gli ultimi &&
|
||
|
||
cur.setfilter(flt);
|
||
|
||
TToken_string fields = "ANNO|CODNUM|TIPODOC|NUMDOCRIF|STATO|DATADOCRIF|DOC1|DOC2|DOC3|NDOC|20->RAGSOC";
|
||
TCursor_sheet sheet(&cur, fields,
|
||
"Documento di riferimento",
|
||
"Anno|Num.|Tipo|Docum.Rif.|Stato|Data@10|Docum.Rif.1|Docum.Rif.2|Docum.Rif.3|Documento|Ragione Sociale@50",
|
||
0, 1);
|
||
if (sheet.run() == K_ENTER)
|
||
{
|
||
const int nrifpos = fields.get_pos("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);
|
||
set(F_NDOC_ELAB, ndoc);
|
||
const int codnumpos = fields.get_pos("CODNUM");
|
||
const TString16 codnum = sheet.row(-1).get(codnumpos);
|
||
set(F_CODNUM_ELAB, codnum, TRUE);
|
||
}
|
||
}
|
||
|
||
TElabora_mask::TElabora_mask(TDocumento_mask& main_mask)
|
||
: TAutomask("ve0100b"), _main(&main_mask), _last_elab(NULL), _check_fld(-883)
|
||
{
|
||
_myself = this;
|
||
|
||
const TDate oggi(TODAY);
|
||
set(F_ANNO_ELAB, oggi.year()); //anno della datadoc proposta (risolve bug 0000331)
|
||
set(F_TIPOCF_ELAB, _main->get(F_TIPOCF));
|
||
set(F_CODCF_ELAB, _main->get(F_CODCF));
|
||
set(F_CODVAL_ELAB, _main->get(F_CODVAL));
|
||
}
|
||
|
||
bool TDocumento_mask::elabora_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TDocumento_mask& m = (TDocumento_mask&)f.mask();
|
||
m.update_progs();
|
||
if (m.check_fields()) // Check values
|
||
{
|
||
TElabora_mask* selection = new TElabora_mask(m); // No woman no stack
|
||
bool do_checks = false;
|
||
const char stato_iniziale = m.doc().stato();
|
||
|
||
while (selection->run() == K_ENTER)
|
||
{
|
||
m.mask2doc();
|
||
const bool processed = selection->elabora();
|
||
do_checks |= processed;
|
||
if (m.doc().stato() != stato_iniziale)
|
||
break;
|
||
if (processed)
|
||
{
|
||
m.doc2mask(FALSE);
|
||
TSheet_field& ss = m.sfield(F_SHEET);
|
||
for (int i = 0; i < ss.items(); i++)
|
||
{
|
||
m.ss_notify(ss,i,K_TAB);
|
||
m.ss_notify(ss,i,K_SPACE);
|
||
m.ss_notify(ss,i,K_ENTER);
|
||
}
|
||
}
|
||
if (!m.get_bool(F_TYPE)) // non aggiunge al documento attuale
|
||
break;
|
||
}
|
||
if (do_checks)
|
||
{
|
||
// Provoca decodifiche necessarie
|
||
const int tutti = m.fields();
|
||
int i;
|
||
for (i = 0; i < tutti; i++)
|
||
{
|
||
TMask_field& f = m.fld(i);
|
||
if (f.dlg() <= BASE_PIEDE)
|
||
f.check(STARTING_CHECK);
|
||
}
|
||
for (i = tutti-1; i >= 0; i--)
|
||
m.fld(i).set_dirty(FALSE);
|
||
}
|
||
delete selection;
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDocumento_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool TDocumento_mask::print_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
main_app().print();
|
||
return TRUE;
|
||
}
|
||
|
||
void TDocumento_mask::set_field_handler(short fieldid, CONTROL_HANDLER handler)
|
||
{
|
||
_handlers.add((TObject *)handler, fieldid);
|
||
}
|
||
|
||
void TDocumento_mask::user_set_handler(int fieldid, int index)
|
||
{
|
||
switch( index )
|
||
{
|
||
case 1:
|
||
set_field_handler(fieldid, ora_hndl);
|
||
break;
|
||
case 2:
|
||
set_field_handler(fieldid, totdoc_hndl);
|
||
break;
|
||
case 3:
|
||
set_field_handler(fieldid, numdocrif_hndl);
|
||
break;
|
||
case 4:
|
||
{
|
||
_smartcard = new TSmart_card();
|
||
if (_smartcard->type() != no_smartcard)
|
||
{
|
||
set_field_handler(fieldid, smart_hndl);
|
||
set_handler(fieldid, universal_handler);
|
||
}
|
||
else
|
||
{
|
||
disable(fieldid);
|
||
delete _smartcard;
|
||
_smartcard = NULL;
|
||
}
|
||
}
|
||
break;
|
||
case 5:
|
||
set_field_handler(fieldid, dummy_hndl);
|
||
break;
|
||
default:
|
||
CHECK( FALSE, "Tentativo di installare un handler non definito" );
|
||
break;
|
||
}
|
||
}
|
||
|
||
bool TDocumento_mask::call_handler( TMask_field& f, KEY key)
|
||
{
|
||
const short id = f.dlg();
|
||
|
||
CONTROL_HANDLER h = (CONTROL_HANDLER) _handlers.objptr(id);
|
||
|
||
if (h != NULL)
|
||
return h(f, key);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::universal_handler( TMask_field& f, KEY key)
|
||
{
|
||
TDocumento_mask & m = (TDocumento_mask &)f.mask();
|
||
static int last_page = -1;
|
||
static bool calculated = false;
|
||
|
||
bool ok = m.call_handler(f, key);
|
||
|
||
if (ok && key == K_TAB && f.focusdirty())
|
||
{
|
||
const int page = m.curr_page();
|
||
if (last_page != page)
|
||
{
|
||
calculated = m.is_calculated_page(page);
|
||
last_page = page;
|
||
}
|
||
if (calculated)
|
||
m.update_progs();
|
||
}
|
||
|
||
return ok;
|
||
}
|
||
|
||
bool TDocumento_mask::anno_handler( TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_TAB && f.to_check(key, TRUE))
|
||
app().update_navigation_bar();
|
||
return true;
|
||
}
|
||
|
||
bool TDocumento_mask::num_handler( TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_TAB && f.to_check(key, TRUE))
|
||
{
|
||
// Ottengo la maschera
|
||
TMask& m = f.mask();
|
||
|
||
TTable & tabnum = ((TTable &) ((TEdit_field &)f).browse()->cursor()->file());
|
||
if ( tabnum.good())
|
||
{
|
||
TCodice_numerazione cod_num(tabnum.curr());
|
||
m.set( F_DESNUM, cod_num.descrizione());
|
||
// Propone il primo tipo di documento come default
|
||
if (m.field(F_TIPODOC).empty() || f.focusdirty())
|
||
{
|
||
m.set( F_TIPODOC, cod_num.tipo_doc(0));
|
||
m.send_key( K_TAB, F_TIPODOC );
|
||
}
|
||
// Se per questa numerazione e' abilitata le numerazione provvisoria
|
||
if (cod_num.num_provv())
|
||
{
|
||
// Setta di default la numerazione provvisoria
|
||
m.set( F_PROVV, "P" );
|
||
// Abilita il campo per la selezione della numerazione
|
||
m.enable( F_PROVV );
|
||
}
|
||
else // Altrimenti ...
|
||
{
|
||
// Setta la numerazione a definitiva
|
||
m.set( F_PROVV, "D" );
|
||
// Disabilita il campo per la selezione della numerazione
|
||
m.disable( F_PROVV );
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m.set( F_DESNUM, "" );
|
||
m.set( F_TIPODOC, "" );
|
||
}
|
||
|
||
app().update_navigation_bar();
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::tip_handler( TMask_field& f, KEY key )
|
||
{
|
||
TDocumento_mask& m = (TDocumento_mask&)f.mask( );
|
||
if ( key == K_TAB && m.is_running() && m.get(F_TIPODOC).not_empty())
|
||
{
|
||
TCodice_numerazione cod_num(m.get(F_CODNUM));
|
||
const TString& tipo = f.get();
|
||
int last = cod_num.ntipi_doc();
|
||
for (int i = 0; i < last; i++ )
|
||
{
|
||
const TString16 curtipo(cod_num.tipo_doc(i));
|
||
if (curtipo == tipo)
|
||
return TRUE;
|
||
}
|
||
return f.error_box( "Tipo non valido per la numerazione selezionata!" );
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::codlist_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_TAB && f.focusdirty())
|
||
{
|
||
TLocalisamfile & list = ((TEdit_field &) f).browse()->cursor()->file();
|
||
const TDate datadoc(f.mask().get(F_DATADOC));
|
||
const TDate datascad(list.get_date("VALFIN"));
|
||
|
||
if (datascad.ok() && datadoc > datascad)
|
||
{
|
||
const TString16 codsucc(list.get("CODLISSUCC"));
|
||
|
||
if (codsucc.empty())
|
||
return error_box("Listino scaduto il %s", datascad.string());
|
||
else
|
||
{
|
||
f.set(codsucc);
|
||
f.set_focusdirty();
|
||
((TEdit_field &)f).check();
|
||
}
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::codcont_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_TAB && f.focusdirty())
|
||
{
|
||
TLocalisamfile & cont = ((TEdit_field &) f).browse()->cursor()->file();
|
||
const TDate datadoc(f.mask().get(F_DATADOC));
|
||
const TDate datascad(cont.get_date("VALFIN"));
|
||
|
||
if (datascad.ok() && datadoc > datascad)
|
||
return error_box("Contratto scaduto il %s", datascad.string());
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::codcamp_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_TAB && f.focusdirty())
|
||
{
|
||
TLocalisamfile & camp = ((TEdit_field &) f).browse()->cursor()->file();
|
||
const TDate datadoc(f.mask().get(F_DATADOC));
|
||
const TDate datascad(camp.get_date("VALFIN"));
|
||
|
||
if (datascad.ok() && datadoc > datascad)
|
||
return error_box("Offerta scaduta il %s", datascad.string());
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
bool TDocumento_mask::datacambio_handler( TMask_field& f, KEY key )
|
||
{
|
||
TMask& m = f.mask();
|
||
if (key == K_TAB && m.field(F_CAMBIO).empty())
|
||
{
|
||
const TString& codval = m.get(F_CODVAL1);
|
||
if (is_true_value(codval))
|
||
{
|
||
const TRectype& rec = cache().get("%VAL", codval);
|
||
m.set(F_CAMBIO, rec.get("S4"));
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TDocumento_mask::codval_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_TAB && f.focusdirty() && !f.empty())
|
||
{
|
||
TMask& m = f.mask();
|
||
|
||
// Cerco un cambio per la data specificata, se non lo trovo lo invento
|
||
TDate datacam = m.get_date(F_DATACAMBIO);
|
||
if (!datacam.ok())
|
||
{
|
||
datacam = m.get_date(F_DATADOC);
|
||
m.set(F_DATACAMBIO, datacam);
|
||
m.set(F_DATACAMBIO1, datacam);
|
||
}
|
||
TExchange exc(f.get());
|
||
exchange_type et;
|
||
real cambio = exc.get_change(et); // Determino il cambio standard ed il "Contro-Euro"
|
||
TString16 key;
|
||
key.format("%-3s%s", (const char*)f.get(), (const char*)datacam.string(ANSI));
|
||
const real giornaliero(cache().get("CAM", key, "S4"));
|
||
if (!giornaliero.is_zero())
|
||
cambio = giornaliero; // Ho trovato un cambio per il giorno!
|
||
m.set(F_CAMBIO, cambio);
|
||
m.set(F_CONTROEURO, et == _exchange_contro ? "X" : "");
|
||
|
||
m.sfield(F_SHEET).force_update(); // Aggiorna punti decimali degli importi
|
||
}
|
||
return TRUE;
|
||
} |