Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 1208 git-svn-id: svn://10.65.10.50/trunk@17106 c028cbd2-c16b-5b4b-a496-9718f37d4682
1676 lines
40 KiB
C++
Executable File
1676 lines
40 KiB
C++
Executable File
#include "vdlib.h"
|
||
|
||
#include "../ve/velib.h"
|
||
#include "../ve/sconti.h"
|
||
#include "../mg/mglib.h"
|
||
|
||
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <execp.h>
|
||
#include <agasys.h>
|
||
#include <utility.h>
|
||
|
||
#include "../mg/anamag.h"
|
||
#include <clifo.h>
|
||
#include "../ve/vepriv.h"
|
||
#include "../ve/ve0100.h"
|
||
#include "../ve/veini.h"
|
||
#include "../ve/veuml.h"
|
||
#include "../ve/veuml1.h"
|
||
#include "../ve/verig.h"
|
||
|
||
#include <user.h>
|
||
#include "vd0700a.h"
|
||
#include "vd0700b.h"
|
||
#include "vdconf.h"
|
||
#include "turni.h"
|
||
|
||
class TScontrino_mask;
|
||
|
||
class TPerms_mask : public TAutomask
|
||
{
|
||
public:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
TPerms_mask() : TAutomask("vd0700b") {}
|
||
virtual ~TPerms_mask() { }
|
||
};
|
||
|
||
bool TPerms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_PASSWORD:
|
||
if (e == fe_modify)
|
||
{
|
||
const TString & user = get(F_USERNAME);
|
||
const TRectype & rec = cache().get(LF_USER, user);
|
||
const TString & pwd = rec.get(USR_PASSWORD);
|
||
const TString pass = get(F_PASSWORD);
|
||
const bool ok = !rec.empty() && pass == decode(pwd);
|
||
|
||
enable(DLG_OK, ok);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
class TChiusura_scontrino_mask : public TAutomask
|
||
{
|
||
int _items;
|
||
TString_array _codpag;
|
||
TString_array _labpag;
|
||
TTipo_pag _tipo[9];
|
||
TBit_array _contanti;
|
||
TBit_array _resto;
|
||
|
||
public:
|
||
const TString & codpag(int i);
|
||
const TString & labpag(int i);
|
||
TTipo_pag tipo(int i) { return _tipo[i];}
|
||
|
||
bool is_contanti(int i) { return _contanti[i - 1];}
|
||
bool has_resto(int i) { return _resto[i - 1];}
|
||
real calcola_saldo();
|
||
real calcola_resto();
|
||
void init(TConfig & d);
|
||
void update_doc(TScontrino_mask & m, const TTurno_vendita & t, bool chiudi = true);
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
void reset_mask(int ncassa, const TDate & data, const real & cassa_attuale, const TDocumento & doc);
|
||
|
||
TChiusura_scontrino_mask() : TAutomask("vd0700a"), _items(0) {}
|
||
virtual ~TChiusura_scontrino_mask() {}
|
||
};
|
||
|
||
const TString & TChiusura_scontrino_mask::codpag(int i)
|
||
{
|
||
i--;
|
||
if (i < _items)
|
||
return _codpag.row(i);
|
||
else
|
||
return EMPTY_STRING;
|
||
}
|
||
|
||
const TString & TChiusura_scontrino_mask::labpag(int i)
|
||
{
|
||
i--;
|
||
if (i < _items)
|
||
return _labpag.row(i);
|
||
else
|
||
return EMPTY_STRING;
|
||
}
|
||
|
||
// Definizione della classe dell'applicazione motore
|
||
class TScontrino_application : public TMotore_application
|
||
{
|
||
TTurno_vendita *_turno;
|
||
TOperatore * _cassiere;
|
||
TOperatore * _responsabile;
|
||
TString8 _negozio;
|
||
TString8 _numdoc;
|
||
TString8 _tipodoc;
|
||
TString8 _codlist;
|
||
TString8 _numdocf;
|
||
TString8 _tipodocf;
|
||
TString8 _codcaus;
|
||
TString8 _codmag;
|
||
TString8 _codmagc;
|
||
TString80 _cassa_app;
|
||
TString80 _cassa_dir;
|
||
TString _bye_bye;
|
||
bool _doppio_zero;
|
||
char _print_type;
|
||
bool _chk_doc;
|
||
bool _barcode_peso_var;
|
||
bool _peso_var;
|
||
char _qta_char;
|
||
int _npag;
|
||
int _ncassa;
|
||
int _cassetto;
|
||
int _def_qta;
|
||
TChiusura_scontrino_mask *_chiusura;
|
||
TScontrino_mask * _sc_mask;
|
||
TString_array _tv_labels;
|
||
TString_array _tv_cmds;
|
||
|
||
protected:
|
||
virtual bool user_create( );
|
||
virtual bool user_destroy( );
|
||
virtual bool menu(MENU_TAG mt);
|
||
virtual TMask* get_mask( int mode );
|
||
virtual const char* get_next_key( );
|
||
virtual void init_query_mode(TMask& m);
|
||
virtual void init_modify_mode( TMask& m );
|
||
virtual void init_insert_mode( TMask& m );
|
||
virtual bool save_and_new() const { return true; }
|
||
virtual bool has_filtered_cursor() const { return false; }
|
||
int read( TMask& m );
|
||
void update_doc( const TMask& m );
|
||
int write( const TMask& m );
|
||
virtual TDocumento_mask & edit_mask() const { CHECK( _sc_mask, "Maschera di edit nulla!" ); return (TDocumento_mask &) *_sc_mask; }
|
||
|
||
// Operazione
|
||
public:
|
||
TChiusura_scontrino_mask & chiusura() { return *_chiusura;}
|
||
void print_wincor();
|
||
void print_multiprinter_logic();
|
||
void print_multiprinter_nettuna();
|
||
virtual void print();
|
||
int ncassa() const { return _ncassa;}
|
||
int def_qta() const { return _def_qta;}
|
||
char qta_char() const { return _qta_char ;}
|
||
const TString & numdoc() const { return _numdoc;}
|
||
const TString & codlist() const { return _codlist;}
|
||
const TString & numdocf() const { return _numdocf;}
|
||
const TString & tipodocf() const { return _tipodocf;}
|
||
const TString & codmag() const { return _codmag;}
|
||
const TString & codmagc() const { return _codmagc;}
|
||
const TString & negozio() const { return _negozio;}
|
||
const TString_array & tv_cmds() const {return _tv_cmds;}
|
||
const TString_array & tv_labels() const {return _tv_labels;}
|
||
const TOperatore & curr_user() const { return _responsabile != NULL ? *_responsabile : *_cassiere;}
|
||
bool set_responsabile(const char * user);
|
||
void set_authorizations(TMask & m);
|
||
|
||
TTurno_vendita & turno() { return *_turno;}
|
||
|
||
TScontrino_application() : _sc_mask(NULL), _turno(NULL), _chiusura(NULL),
|
||
_cassiere(NULL), _responsabile(NULL) {}
|
||
virtual ~TScontrino_application();
|
||
};
|
||
|
||
inline TScontrino_application& sapp() { return (TScontrino_application &) main_app(); }
|
||
|
||
class TScontrino_mask : public TDocumento_mask
|
||
{
|
||
int _row_to_remove;
|
||
TToken_string _deleted_rows;
|
||
|
||
protected:
|
||
static bool scodart_handler( TMask_field& f, KEY key );
|
||
static bool sqta_handler( TMask_field& f, KEY key );
|
||
static bool sprezzo_handler( TMask_field& f, KEY key );
|
||
static bool turno_handler( TMask_field& f, KEY key );
|
||
static bool chiudi_handler( TMask_field& f, KEY key );
|
||
static bool sospendi_handler( TMask_field& f, KEY key );
|
||
static bool search_chiusi_handler(TMask_field& f, KEY key);
|
||
static bool search_sospesi_handler(TMask_field& f, KEY key);
|
||
static bool tasti_veloci_handler(TMask_field& f, KEY key);
|
||
static bool perms_handler( TMask_field& f, KEY key );
|
||
static bool ss_notify(TSheet_field& ss, int r, KEY key);
|
||
static bool check_perms(TDocumento & doc, TSheet_field & s, TDocumento_mask & m, int nrow);
|
||
static bool search_art_handler( TMask_field& f, KEY key );
|
||
|
||
public:
|
||
void set_row_to_remove(int r) { _row_to_remove = r;}
|
||
virtual void on_idle();
|
||
void show_giacenza();
|
||
|
||
virtual TVariable_mask * riga_mask(int numriga);
|
||
virtual bool is_omaggio_enabled() { return sapp().curr_user().can_change_omaggi();}
|
||
TToken_string & deleted_rows() { return _deleted_rows;}
|
||
|
||
|
||
TScontrino_mask(const char* tipodoc);
|
||
virtual ~TScontrino_mask() {}
|
||
};
|
||
|
||
TScontrino_mask::TScontrino_mask(const char* tipodoc)
|
||
:TDocumento_mask(tipodoc), _row_to_remove(0),
|
||
_deleted_rows("", '<EFBFBD>')
|
||
{
|
||
set_handler(DLG_TURNO, turno_handler);
|
||
set_handler(DLG_CHIUDI, chiudi_handler);
|
||
set_handler(DLG_SAVEREC, sospendi_handler);
|
||
set_handler(DLG_RICSOSP, search_sospesi_handler);
|
||
set_handler(DLG_RICCHIUSI, search_chiusi_handler);
|
||
set_handler(DLG_PERMS, perms_handler);
|
||
set_handler(F_CODSEARCH, search_art_handler);
|
||
if (id2pos(F_CODLIST) < 0)
|
||
add_string(F_CODLIST, 0, "Listino", 60, 60, 4, "HP");
|
||
for (short id = F_FUNC1; id <= F_FUNC8; id++)
|
||
{
|
||
const TString & label = sapp().tv_labels().row(id - F_FUNC1);
|
||
|
||
if (label.full())
|
||
{
|
||
TButton_field & b = (TButton_field &) field(id);
|
||
TFilename img(label);
|
||
|
||
if (TImage::build_filename(img))
|
||
b.set_bmp(img);
|
||
else
|
||
b.set_prompt(label);
|
||
b.set_handler(tasti_veloci_handler);
|
||
}
|
||
else
|
||
hide(id);
|
||
}
|
||
sfield(F_SHEET).set_notify( ss_notify );
|
||
sfield(F_SHEET).set_auto_append();
|
||
}
|
||
|
||
bool TScontrino_mask::check_perms(TDocumento & doc, TSheet_field & s, TDocumento_mask & m, int nrow)
|
||
{
|
||
bool ok = true;
|
||
if (nrow > 0 && nrow <= doc.physical_rows())
|
||
doc[nrow].autosave(s);
|
||
if (m.is_calculated_page(m.curr_page()))
|
||
m.update_progs();
|
||
|
||
const real totale = doc.totale_doc();
|
||
|
||
if (totale > sapp().curr_user().max_scontrino())
|
||
ok = error_box(FR("Scontrino di valore (%s) superiore al massimo (%s) consentito"), totale.string(), sapp().curr_user().max_scontrino().string());
|
||
|
||
const real abbuono = doc.get_real("SCONTOD");
|
||
|
||
if (ok && abbuono > sapp().curr_user().max_abbuono())
|
||
ok= error_box(FR("Abbuono (%s) superiore al massimo (%s) consentito"), abbuono.string(), sapp().curr_user().max_abbuono().string());
|
||
|
||
if (ok && nrow > 0 && nrow <= doc.physical_rows())
|
||
{
|
||
TRiga_documento & riga = doc[nrow];
|
||
|
||
const real qta = riga.get_real(RDOC_QTA);
|
||
|
||
if (ok && qta < 0 && !sapp().curr_user().can_resi())
|
||
ok = error_box(TR("Reso non possibile"));
|
||
|
||
TString ge;
|
||
real psconto;
|
||
|
||
scontoexpr2perc(riga.get(RDOC_SCONTO), false, ge, psconto);
|
||
psconto = CENTO * (1 - psconto);
|
||
if (ok && psconto > sapp().curr_user().max_sconto())
|
||
ok = error_box(FR("Percentuale di sconto (%s) superiore al massimo (%s) consentito"), psconto.string(), sapp().curr_user().max_sconto().string());
|
||
|
||
if (ok && !sapp().curr_user().can_sotto_costo())
|
||
{
|
||
const TRectype & anamag = cache().get(LF_ANAMAG, riga.get(RDOC_CODARTMAG));
|
||
const real prezzo = riga.get_real(RDOC_PREZZOL);
|
||
real costo = anamag.get_real(ANAMAG_ULTCOS1);
|
||
|
||
riga.iva().lordo(costo);
|
||
if (!anamag.empty() && prezzo < costo)
|
||
ok = error_box(FR("Non e' possibile vendere sottocosto (%s < %s)"), prezzo.string(), costo.string());
|
||
}
|
||
}
|
||
m.enable(DLG_CHIUDI, ok);
|
||
return ok;
|
||
}
|
||
|
||
void TScontrino_mask::show_giacenza()
|
||
{
|
||
TString codart = get(F_CODSEARCH);
|
||
real giac, disp;
|
||
|
||
if (codart.full())
|
||
{
|
||
const TString& annoes = get(F_ANNO);
|
||
TArticolo_giacenza art(codart);
|
||
|
||
giac = art.disponibilita(annoes, sapp().codmag(), "", true);
|
||
disp = art.disponibilita(annoes, sapp().codmag(), "", false);
|
||
}
|
||
set(F_CURGIAC, giac.string());
|
||
set(F_CURDISP, disp.string());
|
||
}
|
||
|
||
bool TScontrino_mask::ss_notify( TSheet_field& ss, int r, KEY key )
|
||
{
|
||
TScontrino_mask& m = (TScontrino_mask&)ss.mask();
|
||
CHECK(&m == &app().curr_mask(), "Cast dal cas");
|
||
|
||
TDocumento& doc = m.doc();
|
||
|
||
switch (key)
|
||
{
|
||
case K_DEL:
|
||
{
|
||
const TRiga_documento & riga = doc[r + 1];
|
||
|
||
if (riga.is_omaggio() && !sapp().curr_user().can_change_omaggi())
|
||
return false;
|
||
|
||
TString row = ss.row(r);
|
||
|
||
row.replace('|', '!'),
|
||
m.deleted_rows().add(row);
|
||
|
||
}
|
||
break;
|
||
case K_CTRL + K_DEL:
|
||
{
|
||
check_perms(doc, ss, m, 0);
|
||
return true;
|
||
}
|
||
break;
|
||
case K_CTRL + K_INS:
|
||
{
|
||
TRiga_documento& riga = doc[r + 1];
|
||
|
||
if (riga.is_merce())
|
||
{
|
||
bool update = false;
|
||
const int quant = sapp().def_qta();
|
||
const TString & codmag = sapp().codmag();
|
||
const TString & codmagc = sapp().codmagc();
|
||
|
||
if (quant > 0)
|
||
{
|
||
riga.put(RDOC_QTA, quant);
|
||
update = true;
|
||
}
|
||
if (codmag.full())
|
||
{
|
||
riga.put(RDOC_CODMAG, codmag);
|
||
update = true;
|
||
}
|
||
if (codmagc.full())
|
||
{
|
||
riga.put(RDOC_CODMAGC, codmagc);
|
||
update = true;
|
||
}
|
||
if (update)
|
||
riga.autoload(ss);
|
||
}
|
||
}
|
||
break;
|
||
case K_CTRL + K_TAB:
|
||
if (r > 0)
|
||
{
|
||
TRiga_documento& riga_prec = doc[r];
|
||
TRiga_documento& riga = doc[r + 1];
|
||
|
||
if (riga.get(RDOC_CODART).full())
|
||
{
|
||
if (riga_prec.get(RDOC_CODART) == riga.get(RDOC_CODART) &&
|
||
riga_prec.get(RDOC_LIVELLO) == riga.get(RDOC_LIVELLO) &&
|
||
riga_prec.get(RDOC_UMQTA) == riga.get(RDOC_UMQTA) &&
|
||
riga_prec.get_real(RDOC_PREZZO) == riga.get_real(RDOC_PREZZO) &&
|
||
riga_prec.get(RDOC_SCONTO) == riga.get(RDOC_SCONTO))
|
||
{
|
||
m.set_row_to_remove(r);
|
||
}
|
||
else
|
||
if (r < ss.items() - 1)
|
||
{
|
||
TRiga_documento& riga_succ = doc[r + 2];
|
||
|
||
if (riga_succ.get(RDOC_CODART) == riga.get(RDOC_CODART) &&
|
||
riga_prec.get(RDOC_LIVELLO) == riga.get(RDOC_LIVELLO) &&
|
||
riga_succ.get(RDOC_UMQTA) == riga.get(RDOC_UMQTA) &&
|
||
riga_succ.get_real(RDOC_PREZZO) == riga.get_real(RDOC_PREZZO) &&
|
||
riga_succ.get(RDOC_SCONTO) == riga.get(RDOC_SCONTO))
|
||
m.set_row_to_remove(r + 1);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case K_ENTER:
|
||
case K_INS:
|
||
{
|
||
if (!check_perms(doc, ss, m, r + 1))
|
||
return false;
|
||
if (ss.items() == 0)
|
||
{
|
||
const long ora = daytime();
|
||
|
||
doc.put(TRN_INIZIO, ora);
|
||
m.deleted_rows().cut(0);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return TDocumento_mask::ss_notify(ss, r, key);
|
||
}
|
||
|
||
bool TScontrino_mask::turno_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
return sapp().turno().chiudi();
|
||
return true;
|
||
}
|
||
|
||
void TScontrino_mask::on_idle()
|
||
{
|
||
if (_row_to_remove > 0)
|
||
{
|
||
TSheet_field & ss = sfield(F_SHEET);
|
||
int selected = ss.selected();
|
||
TDocumento& d = doc();
|
||
TRiga_documento& riga_prec = d[_row_to_remove];
|
||
TRiga_documento& riga = d[_row_to_remove + 1];
|
||
|
||
real qta = riga_prec.get_real(RDOC_QTA);
|
||
|
||
qta += riga.get_real(RDOC_QTA);
|
||
riga_prec.put(RDOC_QTA, qta);
|
||
riga_prec.autoload(ss);
|
||
ss.update_mask(_row_to_remove - 1);
|
||
ss.destroy(_row_to_remove);
|
||
d.destroy_row(_row_to_remove + 1, true);
|
||
ss.force_update();
|
||
if (selected >= _row_to_remove)
|
||
selected--;
|
||
if (selected >= ss.items())
|
||
selected = ss.items() -1 ;
|
||
ss.select(selected);
|
||
_row_to_remove = 0;
|
||
}
|
||
TDocumento_mask::on_idle();
|
||
}
|
||
|
||
TVariable_mask * TScontrino_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 *) maskrighe().objptr(name);
|
||
|
||
if (m == NULL)
|
||
{
|
||
m = TDocumento_mask::riga_mask(numriga);
|
||
|
||
if ( m != NULL)
|
||
{
|
||
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_CODART, scodart_handler );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ( int pos = m->id2pos(FR_QTA) >= 0)
|
||
m->set_handler(FR_QTA, sqta_handler);
|
||
if ( int pos = m->id2pos(FR_PREZZO) >= 0)
|
||
m->set_handler(FR_PREZZO, sprezzo_handler);
|
||
}
|
||
}
|
||
return m;
|
||
|
||
}
|
||
|
||
bool TScontrino_mask::search_art_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (f.to_check(key))
|
||
{
|
||
TScontrino_mask & mask = (TScontrino_mask &) f.mask();
|
||
|
||
mask.show_giacenza();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TScontrino_mask::scodart_handler(TMask_field& f, KEY key )
|
||
{
|
||
if (f.to_check(key))
|
||
{
|
||
const TString & val = f.get();
|
||
const int pos = val.find(sapp().qta_char());
|
||
|
||
if (pos >= 0)
|
||
{
|
||
TMask& row_mask = f.mask();
|
||
const TString80 qta = val.left(pos);
|
||
const TString80 cod = val.mid(pos + 1);
|
||
|
||
row_mask.set(FR_CODART, cod, 0x3);
|
||
row_mask.set(FR_QTA, qta, 0x3);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
const bool ok = ::codart_handler(f, key);
|
||
|
||
if (ok && f.to_check(key, false))
|
||
{
|
||
TMask& row_mask = f.mask();
|
||
TSheet_field& s = *row_mask.get_sheet();
|
||
TDocumento_mask & mask = (TDocumento_mask &) s.mask();
|
||
const int srow = s.selected();
|
||
const int drow = srow + 1;
|
||
|
||
s.update_row(srow);
|
||
mask.doc()[drow].autosave(s);
|
||
mask.update_progs();
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TScontrino_mask::sqta_handler(TMask_field& f, KEY key )
|
||
{
|
||
if (f.to_check(key, false))
|
||
{
|
||
TMask& row_mask = f.mask();
|
||
TSheet_field& s = *row_mask.get_sheet();
|
||
TDocumento_mask & mask = (TDocumento_mask &) s.mask();
|
||
const int srow = s.selected();
|
||
const int drow = srow + 1;
|
||
|
||
s.update_row(srow);
|
||
mask.doc()[drow].autosave(s);
|
||
mask.update_progs();
|
||
}
|
||
return ::qta_handler(f, key);
|
||
|
||
}
|
||
|
||
bool TScontrino_mask::sprezzo_handler(TMask_field& f, KEY key )
|
||
{
|
||
if (f.to_check(key, false))
|
||
{
|
||
TMask& row_mask = f.mask();
|
||
TSheet_field& s = *row_mask.get_sheet();
|
||
TDocumento_mask & mask = (TDocumento_mask &) s.mask();
|
||
const int srow = s.selected();
|
||
const int drow = srow + 1;
|
||
|
||
s.update_row(srow);
|
||
mask.doc()[drow].autosave(s);
|
||
mask.update_progs();
|
||
}
|
||
return true;
|
||
|
||
}
|
||
|
||
bool TScontrino_mask::chiudi_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TChiusura_scontrino_mask & mask = sapp().chiusura();
|
||
TTurno_vendita & turno = sapp().turno();
|
||
TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
|
||
TDocumento & doc = docmask.doc();
|
||
|
||
mask.reset_mask(sapp().ncassa(), docmask.get_date(F_DATADOC), turno.cassa_attuale(), doc);
|
||
mask.show(-2, sapp().curr_user().can_invoice());
|
||
mask.show(-3, sapp().curr_user().can_invoice());
|
||
if (mask.run() == K_ENTER)
|
||
{
|
||
do
|
||
{
|
||
sapp().print();
|
||
} while (yesno_box(TR("Vuoi ristampare lo scontrino")));
|
||
|
||
const real & saldo = mask.get_real(F_SALDO);
|
||
const long ndoc = doc.get_long(DOC_NDOC);
|
||
|
||
turno.aggiorna(ndoc, saldo);
|
||
|
||
const TString & num = sapp().numdocf();
|
||
const TString & tipo = sapp().tipodocf();
|
||
|
||
if (mask.get_bool(F_DAFATT) && num.full() && tipo.full())
|
||
{
|
||
TDocumento_mask m(tipo);
|
||
TDocumento & fatt = m.doc();
|
||
TFilename ini_file; ini_file.temp(NULL, "ini");
|
||
|
||
fatt.put(DOC_CODNUM, num);
|
||
fatt.put(DOC_ANNO, doc.get(DOC_ANNO));
|
||
fatt.put(DOC_PROVV, doc.get(DOC_PROVV));
|
||
fatt.renum_ndoc();
|
||
fatt.copy_contents(doc);
|
||
fatt.stato(fatt.tipo().stato_finale_inserimento());
|
||
fatt.put(DOC_TIPODOC, tipo);
|
||
fatt.put(DOC_TIPOCF, mask.get(F_TIPOCFC));
|
||
fatt.put(DOC_CODCF, mask.get(F_CODCFC));
|
||
|
||
for (int i = 1; i <= fatt.physical_rows(); i++)
|
||
fatt[i].set_original_rdoc_key(doc[i]);
|
||
m.doc2mask();
|
||
{
|
||
TConfig ini(ini_file, "Transaction");
|
||
char mode[2] = { TM_INTERACTIVE, '\0' };
|
||
|
||
ini.set("Action", TRANSACTION_INSERT);
|
||
ini.set("Mode", mode);
|
||
sapp().mask2ini(m, ini);
|
||
TString_array p;
|
||
TString val;
|
||
|
||
ini.list_paragraphs(p);
|
||
FOR_EACH_ARRAY_ROW(p, rp, par)
|
||
{
|
||
TAssoc_array & v =ini.list_variables(*par);
|
||
|
||
FOR_EACH_ASSOC_STRING(v, obj, key, vr)
|
||
{
|
||
const TString16 var(key);
|
||
if (var == DOC_CODLIST ||
|
||
var == DOC_CODVAL ||
|
||
var == DOC_DATACAMBIO ||
|
||
var == DOC_CAMBIO)
|
||
continue;
|
||
val = vr;
|
||
val.strip("\"");
|
||
|
||
if (val.blank())
|
||
ini.remove(var);
|
||
}
|
||
}
|
||
}
|
||
|
||
TString cmd("ve0 -1 -i"); cmd << ini_file;
|
||
TExternal_app app(cmd);
|
||
|
||
app.run();
|
||
|
||
{
|
||
TConfig ini(ini_file, "Transaction");
|
||
|
||
if (ini.get("Result") != "OK")
|
||
mask.set(F_CODCFC, "");
|
||
}
|
||
}
|
||
mask.update_doc(docmask, turno);
|
||
docmask.stop_run(K_SAVE);
|
||
}
|
||
else
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
static bool chiusi_filter(const TRelation* r)
|
||
{
|
||
return r->curr().get("USERNAME") == sapp().turno().user();
|
||
}
|
||
|
||
bool TScontrino_mask::sospendi_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
const TTurno_vendita & turno = sapp().turno();
|
||
TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
|
||
TChiusura_scontrino_mask & mask = sapp().chiusura();
|
||
mask.update_doc(docmask, turno, false);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TScontrino_mask::search_chiusi_handler(TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TScontrino_mask & m = (TScontrino_mask &) f.mask();
|
||
TRectype filtrec(LF_DOC);
|
||
|
||
filtrec.put(DOC_PROVV, m.get(F_PROVV));
|
||
filtrec.put(DOC_ANNO, m.get(F_ANNO));
|
||
filtrec.put(DOC_CODNUM, m.get(F_CODNUM));
|
||
|
||
TRelation rel(LF_DOC);
|
||
|
||
rel.lfile().set_curr(new TDocumento);
|
||
|
||
TSorted_cursor cur(&rel, "NDOC-", "", 1, &filtrec, &filtrec);
|
||
TString80 filt; filt.format("(STATO>=\"%c\")&&(TIPODOC==\"%s\")&&(CODCF==\"\")", m.doc().tipo().stato_chiuso(), (const char *) m.get(F_TIPODOC));
|
||
|
||
cur.setfilter(filt);
|
||
cur.set_filterfunction(chiusi_filter);
|
||
TCursor_sheet sheet(&cur, "ANNO|CODNUM|NDOC|DATADOC|CODVAL|G1:TOTDOC",
|
||
"Documento",
|
||
"Anno|Numeraz|Doc.numero|Data\nDocumento@10|Valuta|Totale\nDocumento@18V",
|
||
0, 1);
|
||
if (sheet.run() == K_ENTER)
|
||
{
|
||
const TString16 ndoc = sheet.row(-1).get(2);
|
||
TDate oggi(TODAY);
|
||
|
||
m.set(F_PROVV, "D");
|
||
f.mask().set(F_ANNO, oggi.year());
|
||
m.set(F_CODNUM, sapp().numdoc());
|
||
m.set(F_NDOC, ndoc);
|
||
m.stop_run(K_AUTO_ENTER);
|
||
m.enable(DLG_CHIUDI);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
static bool sospesi_filter(const TRelation* r)
|
||
{
|
||
return r->curr().get_long(TRN_PROGR) == sapp().turno().nturno();
|
||
}
|
||
|
||
bool TScontrino_mask::search_sospesi_handler(TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TScontrino_mask & m = (TScontrino_mask &) f.mask();
|
||
TRectype filtrec(LF_DOC);
|
||
|
||
filtrec.put(DOC_PROVV, m.get(F_PROVV));
|
||
filtrec.put(DOC_ANNO, m.get(F_ANNO));
|
||
filtrec.put(DOC_CODNUM, m.get(F_CODNUM));
|
||
|
||
TRelation rel(LF_DOC);
|
||
|
||
rel.lfile().set_curr(new TDocumento);
|
||
|
||
TCursor cur(&rel, "", 1, &filtrec, &filtrec);
|
||
TString80 filt; filt.format("(STATO<\"%c\")&&(TIPODOC==\"%s\")", m.doc().tipo().stato_chiuso(), (const char *) m.get(F_TIPODOC));
|
||
|
||
cur.setfilter(filt);
|
||
cur.set_filterfunction(sospesi_filter);
|
||
TCursor_sheet sheet(&cur, "ANNO|CODNUM|NDOC|DATADOC|CODVAL|G1:TOTDOC",
|
||
"Documento",
|
||
"Anno|Numeraz|Doc.numero|Data\nDocumento@10|Valuta|Totale\nDocumento@18V",
|
||
0, 1);
|
||
if (sheet.run() == K_ENTER)
|
||
{
|
||
const TString16 ndoc = sheet.row(-1).get(2);
|
||
TDate oggi(TODAY);
|
||
|
||
m.set(F_PROVV, "D");
|
||
f.mask().set(F_ANNO, oggi.year());
|
||
m.set(F_CODNUM, sapp().numdoc());
|
||
m.set(F_NDOC, ndoc);
|
||
m.stop_run(K_AUTO_ENTER);
|
||
m.enable(DLG_CHIUDI);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool TScontrino_mask::tasti_veloci_handler(TMask_field& f, KEY key)
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
const TString & cmd = sapp().tv_cmds().row(f.dlg() - F_FUNC1);
|
||
|
||
if (cmd.full())
|
||
{
|
||
TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
|
||
TSheet_field & sf = docmask.sfield(F_SHEET);
|
||
int r = sf.items() == 0 ? 0 : sf.selected() + 1;
|
||
|
||
if (docmask.ss_notify(sf, r, K_INS))
|
||
{
|
||
r = sf.insert(r, false, false);
|
||
if (r >= 0)
|
||
{
|
||
docmask.ss_notify(sf, r, K_CTRL + K_INS);
|
||
TToken_string & row = sf.row(r);
|
||
TDocumento & doc = docmask.doc();
|
||
TRiga_documento & rdoc = doc[r + 1];
|
||
|
||
rdoc.put(RDOC_CODART, cmd);
|
||
rdoc.zero(RDOC_CHECKED);
|
||
rdoc.autoload(sf);
|
||
sf.check_row(r);
|
||
rdoc.autosave(sf);
|
||
sf.force_update();
|
||
sf.select(r);
|
||
sf.set_focus();
|
||
sf.set_dirty();
|
||
docmask.ss_notify(sf, r, K_ENTER);
|
||
docmask.update_progs();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool TScontrino_mask::perms_handler( TMask_field& f, KEY key )
|
||
{
|
||
if (key == K_SPACE)
|
||
{
|
||
TPerms_mask m;
|
||
|
||
if (m.run() == K_ENTER)
|
||
{
|
||
if (sapp().set_responsabile(m.get(F_USERNAME)))
|
||
{
|
||
sapp().set_authorizations(f.mask());
|
||
f.mask().sfield(F_SHEET).force_update();
|
||
|
||
TString super(m.get(F_USERNAME)) ;
|
||
|
||
if (super == sapp().turno().user())
|
||
super.cut(0);
|
||
sapp().turno().set_superuser(super);
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TChiusura_scontrino_mask::init(TConfig & d)
|
||
{
|
||
TString8 codpag(d.get("CODPAG", NULL, 1));
|
||
while (codpag.full() && _items <= 8)
|
||
{
|
||
const int last = _items;
|
||
_items++;
|
||
_codpag.add(codpag);
|
||
const TString & desc = d.get("LABPAG", NULL, _items);
|
||
_labpag.add(desc);
|
||
field(F_INC01 + _items - 1).set_prompt(desc);
|
||
field(F_INC01 + _items - 1).enable();
|
||
|
||
TPagamento p(codpag);
|
||
TTipo_pag t = p.tipo_rata(0);
|
||
_tipo[_items] = t;
|
||
|
||
_resto.set(last, d.get_bool("RESTO", NULL, _items));
|
||
_contanti.set(last, _resto[last] || (t == _rim_dir));
|
||
|
||
codpag = d.get("CODPAG", NULL, _items + 1);
|
||
}
|
||
for (int i = _items; i < 8; i++)
|
||
field(F_INC01 + i).hide();
|
||
}
|
||
|
||
void TChiusura_scontrino_mask::update_doc(TScontrino_mask & m, const TTurno_vendita & t, bool chiudi)
|
||
{
|
||
TDocumento & doc = m.doc();
|
||
const char stato = doc.tipo().stato_chiuso();
|
||
|
||
doc.put(TRN_CODCASSA, t.ncassa());
|
||
doc.put(TRN_PROGR, t.nturno());
|
||
doc.put(TRN_USERNAME, t.user());
|
||
doc.put("TEMPUSERNAME", t.superuser());
|
||
TToken_string del(doc.get("DELETED_ROWS"), '<EFBFBD>');
|
||
|
||
del.add(m.deleted_rows());
|
||
doc.put("DELETED_ROWS", del);
|
||
if (chiudi)
|
||
{
|
||
const long ora = daytime();
|
||
|
||
doc.stato(stato);
|
||
m.set(F_STATO, doc.get(DOC_STATO));
|
||
doc.put(TRN_INC01, get(F_INC01));
|
||
doc.put(TRN_INC02, get(F_INC02));
|
||
doc.put(TRN_INC03, get(F_INC03));
|
||
doc.put(TRN_INC04, get(F_INC04));
|
||
doc.put(TRN_INC05, get(F_INC05));
|
||
doc.put(TRN_INC06, get(F_INC06));
|
||
doc.put(TRN_INC07, get(F_INC07));
|
||
doc.put(TRN_INC08, get(F_INC08));
|
||
doc.put(TRN_RESTI, get(F_RESTO));
|
||
doc.put(TRN_FINE, ora);
|
||
doc.put("NEGOZIO", sapp().negozio());
|
||
const long codcf = get_long(F_CODCFC);
|
||
|
||
if (codcf > 0L)
|
||
{
|
||
doc.put(DOC_TIPOCF, get(F_TIPOCFC));
|
||
doc.put(DOC_CODCF, codcf);
|
||
}
|
||
}
|
||
}
|
||
|
||
real TChiusura_scontrino_mask::calcola_saldo()
|
||
{
|
||
real saldo = get_real(F_CASSAINI) - get_real(F_RESTO);
|
||
int i = 1;
|
||
|
||
for (short id = F_INC01; id <= F_INC08; id++, i++)
|
||
if (is_contanti(i))
|
||
saldo += get_real(id);
|
||
return saldo;
|
||
}
|
||
|
||
real TChiusura_scontrino_mask::calcola_resto()
|
||
{
|
||
real resto = -get_real(F_TOTDOC);
|
||
int i = 1;
|
||
|
||
for (short id = F_INC01; id <= F_INC08; id++, i++)
|
||
resto += get_real(id);
|
||
enable(DLG_OK, resto >= ZERO);
|
||
return resto > ZERO ? resto : ZERO;
|
||
}
|
||
|
||
bool TChiusura_scontrino_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_INC01:
|
||
case F_INC02:
|
||
case F_INC03:
|
||
case F_INC04:
|
||
case F_INC05:
|
||
case F_INC06:
|
||
case F_INC07:
|
||
case F_INC08:
|
||
if (e == fe_modify)
|
||
{
|
||
if (!has_resto(o.dlg() - F_INC01 + 1))
|
||
{
|
||
real valore = get_real(o.dlg());
|
||
real residuo = get_real(F_TOTDOC);
|
||
int i = 1;
|
||
|
||
for (short id = F_INC01; id <= F_INC08; id++, i++)
|
||
if (!has_resto(i))
|
||
residuo -= get_real(id);
|
||
if (residuo < ZERO)
|
||
{
|
||
valore += residuo;
|
||
if (valore < ZERO)
|
||
valore = ZERO;
|
||
message_box("Importo senza resto non permesso");
|
||
o.set(valore.string());
|
||
}
|
||
}
|
||
const real resto = calcola_resto();
|
||
set(F_RESTO, resto);
|
||
const real saldo = calcola_saldo();
|
||
set(F_SALDO, saldo);
|
||
}
|
||
break;
|
||
case F_CODCFC:
|
||
enable(DLG_OK, field(DLG_OK).enabled() || o.get().full());
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TChiusura_scontrino_mask::reset_mask(int ncassa, const TDate & data, const real & cassa_attuale, const TDocumento & doc)
|
||
{
|
||
const bool aperto = !doc.chiuso();
|
||
|
||
reset();
|
||
set(F_CASSA, ncassa);
|
||
set(F_DATA, data);
|
||
set(F_TOTDOC, doc.totale_doc());
|
||
if (aperto)
|
||
set(F_CASSAINI, cassa_attuale);
|
||
|
||
enable(F_SALDO, aperto);
|
||
for (short i = F_INC01 ; i<= F_INC08; i++)
|
||
if (field(i).shown())
|
||
{
|
||
TString f; f.format("INC%02d", i - F_INC01 +1);
|
||
|
||
set(i, doc.get(f));
|
||
field(i).enable(aperto);
|
||
}
|
||
|
||
set(F_RESTO, doc.get(TRN_RESTI));
|
||
|
||
const bool da_fatturare = doc.get(DOC_CODCF).blank();
|
||
|
||
enable(-3, da_fatturare);
|
||
disable(DLG_OK);
|
||
}
|
||
|
||
TScontrino_application::~TScontrino_application()
|
||
{
|
||
delete _turno;
|
||
delete _chiusura;
|
||
if (_sc_mask != NULL)
|
||
delete _sc_mask;
|
||
if (_cassiere != NULL)
|
||
delete _cassiere;
|
||
if (_responsabile != NULL)
|
||
delete _responsabile;
|
||
}
|
||
|
||
bool TScontrino_application::set_responsabile(const char * user)
|
||
{
|
||
_responsabile = new TOperatore(user);
|
||
if (!_responsabile->ok())
|
||
{
|
||
delete _responsabile;
|
||
_responsabile = NULL;
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TMask* TScontrino_application::get_mask( int mode )
|
||
{
|
||
return _sc_mask;
|
||
}
|
||
|
||
bool TScontrino_application::user_create( )
|
||
{
|
||
const bool ok = TMotore_application::user_create();
|
||
|
||
TConfig d(CONFIG_DITTA);
|
||
|
||
_turno = new TTurno_vendita;
|
||
_chiusura = new TChiusura_scontrino_mask;
|
||
|
||
_negozio = d.get("NEGOZIO");
|
||
_numdoc = d.get("CODNUM");
|
||
_tipodoc = d.get("TIPODOC");
|
||
_codlist = d.get("CODLIST");
|
||
_numdocf = d.get("CODNUMF");
|
||
_tipodocf = d.get("TIPODOCF");
|
||
_chk_doc = d.get_bool("CHECKDOC");
|
||
_barcode_peso_var = d.get_bool("BARPVAR");
|
||
_peso_var = d.get_bool("CODPVAR");
|
||
_qta_char = d.get_char("QTACHAR", NULL, -1, ')');
|
||
|
||
_chiusura->init(d);
|
||
|
||
|
||
TConfig w(CONFIG_WST);
|
||
|
||
_ncassa = w.get_int("NCASSA");
|
||
_cassetto = w.get_int("NCASSETTO");
|
||
|
||
TString8 wrk = w.get("CODLIST");
|
||
|
||
if (wrk.full())
|
||
_codlist = wrk;
|
||
wrk = w.get("CODNUMF");
|
||
if (wrk.full())
|
||
_numdocf = wrk;
|
||
wrk = w.get("TIPODOCF");
|
||
if (wrk.full())
|
||
_tipodocf = wrk;
|
||
_print_type = w.get_char("TIPOSTSC");
|
||
|
||
_cassa_dir = w.get("CASSADIR");
|
||
_cassa_app = w.get("CASSAAPP");
|
||
_def_qta = w.get_int("QTADEF");
|
||
|
||
for (int i = 1; i <= 8; i++)
|
||
{
|
||
_tv_labels.add(w.get("TVLABEL", "", i));
|
||
_tv_cmds.add(w.get("TVCMD", "", i));
|
||
}
|
||
_bye_bye = w.get("BYEBYE");
|
||
_doppio_zero = w.get_bool("DoppioZero", NULL, -1, false);
|
||
|
||
_sc_mask = new TScontrino_mask(_tipodoc);
|
||
|
||
TTipo_documento t(_tipodoc);
|
||
|
||
_codcaus = t.caus_mov();
|
||
if (_codcaus.full())
|
||
{
|
||
TCausale_magazzino c(_codcaus);
|
||
TString8 stdcodmag(_sc_mask->stdmag());
|
||
|
||
stdcodmag.left_just(3);
|
||
stdcodmag << _sc_mask->stddep();
|
||
_codmag = c.default_magdep();
|
||
if (_codmag.blank())
|
||
_codmag = stdcodmag;
|
||
if (c.caus_collegata().full())
|
||
{
|
||
TCausale_magazzino cc(c.caus_collegata());
|
||
_codmagc = cc.default_magdep();
|
||
if (_codmagc.blank())
|
||
_codmagc = stdcodmag;
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TScontrino_application::user_destroy()
|
||
{
|
||
const bool ok = TMotore_application::user_destroy();
|
||
return ok;
|
||
}
|
||
|
||
bool TScontrino_application::menu(MENU_TAG mt)
|
||
{
|
||
return TMotore_application::menu(mt);
|
||
}
|
||
|
||
const char* TScontrino_application::get_next_key( )
|
||
{
|
||
TCodice_numerazione cod_num(_numdoc);
|
||
|
||
// Se per questa numerazione h abilitata le numerazione automatica
|
||
if( cod_num.auto_num())
|
||
{
|
||
TLocalisamfile doc(LF_DOC);
|
||
TDate oggi(TODAY);
|
||
|
||
doc.zero();
|
||
doc.put("CODNUM", cod_num.codice());
|
||
doc.put("ANNO", oggi.year());
|
||
doc.put("PROVV", "D");
|
||
|
||
TRectype cmp_rec(doc.curr()); // record campione
|
||
|
||
doc.put( "NDOC", 9999999L );
|
||
if (doc.read(_isgreat) == NOERR)
|
||
doc.prev();
|
||
else
|
||
doc.last();
|
||
|
||
const long num = ((doc.curr() == cmp_rec) ? doc.get_long( "NDOC" ) : 0) + 1;
|
||
|
||
return (format( "%d|%ld", F_NDOC, num));
|
||
}
|
||
return "";
|
||
}
|
||
|
||
void TScontrino_application::set_authorizations(TMask & m)
|
||
{
|
||
TSheet_field & sf = m.sfield(F_SHEET);
|
||
const int items = sf.items();
|
||
|
||
sf.enable_column(FR_PREZZO, curr_user().can_change_price());
|
||
sf.enable_column(FR_SCONTO, curr_user().can_change_sconti());
|
||
for (int i = 0; i < items; i++)
|
||
sf.check_row(i);
|
||
sf.force_update();
|
||
|
||
m.enable(DLG_RICCHIUSI, sapp().curr_user().can_invoice());
|
||
}
|
||
|
||
void TScontrino_application::init_query_mode( TMask& m )
|
||
{
|
||
|
||
if (_turno->chiuso())
|
||
if (!_turno->apri())
|
||
exit(0);// verificare
|
||
if (_cassiere != NULL)
|
||
delete _cassiere;
|
||
_cassiere = new TOperatore(_turno->user());
|
||
if (_responsabile != NULL)
|
||
{
|
||
delete _responsabile;
|
||
_responsabile = NULL;
|
||
}
|
||
_turno->set_superuser();
|
||
set_mode(MODE_INS);
|
||
TDate oggi(TODAY);
|
||
|
||
m.set(F_PROVV, "D");
|
||
m.set(F_ANNO, oggi.year());
|
||
m.set(F_CODNUM, _numdoc);
|
||
m.set(F_TIPODOC, _tipodoc);
|
||
m.set(F_DATADOC, oggi);
|
||
m.set(F_CODLIST, _codlist);
|
||
m.set(F_CAUSMAG, _codcaus);
|
||
|
||
|
||
TToken_string key(get_next_key());
|
||
const long numdoc = key.get_long(1);
|
||
|
||
m.set(F_NDOC, numdoc);
|
||
|
||
TScontrino_mask & dm = (TScontrino_mask &) m;
|
||
TDocumento & doc = dm.doc();
|
||
|
||
doc.zero();
|
||
dm.mask2doc();
|
||
|
||
doc.stato(doc.tipo().stato_finale_inserimento());
|
||
m.set(F_STATO, doc.get(DOC_STATO));
|
||
m.enable(DLG_RICSOSP);
|
||
m.enable(DLG_CHIUDI, !turno().riaperto());
|
||
set_authorizations(m);
|
||
}
|
||
|
||
void TScontrino_application::init_insert_mode( TMask& m )
|
||
{
|
||
init_query_mode(m);
|
||
}
|
||
|
||
void TScontrino_application::init_modify_mode( TMask& m )
|
||
{
|
||
m.disable(DLG_RICCHIUSI);
|
||
m.disable(DLG_RICSOSP);
|
||
set_authorizations(m);
|
||
}
|
||
|
||
int TScontrino_application::read( TMask& m )
|
||
{
|
||
return TMotore_application::read(m);
|
||
}
|
||
|
||
int TScontrino_application::write( const TMask& m ) // C 90
|
||
{
|
||
int err = NOERR;
|
||
TDocumento & doc = ((TScontrino_mask & )m).doc();
|
||
if (doc.physical_rows() > 0)
|
||
{
|
||
err = TMotore_application::write(m);
|
||
if (err == NOERR)
|
||
doc = (TDocumento&) get_relation()->curr();
|
||
}
|
||
return err;
|
||
}
|
||
|
||
void TScontrino_application::print_wincor()
|
||
{
|
||
const char* const server = "Sidcomm95";
|
||
const char* const topic = server; // Ignoranza totale delle regole di buona programmazione DDE!
|
||
|
||
const unsigned int conn = aga_dde_connect("localhost", server, topic);
|
||
if (conn == 0)
|
||
{
|
||
error_box(FR("Impossibile stabilire una comunicazione DDE con %s"), server);
|
||
return;
|
||
}
|
||
|
||
TString80 cmd, tmp;
|
||
TScontrino_mask & m = (TScontrino_mask & ) edit_mask();
|
||
TDocumento & doc = m.doc();
|
||
const TString & cofi = doc.clifor().get(CLI_COFI);
|
||
|
||
if (cofi.full())
|
||
{
|
||
cmd = "[CODF,";
|
||
cmd << cofi << ']';
|
||
aga_dde_execute(conn, cmd);
|
||
}
|
||
|
||
const int text_len = 18;
|
||
TParagraph_string para("", text_len);
|
||
const int rows = doc.physical_rows();
|
||
|
||
for (int r = 1; r <= rows; r++)
|
||
{
|
||
const TRiga_documento& riga = doc[r];
|
||
|
||
if (riga.is_merce())
|
||
{
|
||
cmd = "[PLU,";
|
||
tmp = riga.get(RDOC_DESCR);
|
||
tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')');
|
||
para = tmp;
|
||
cmd << para.get(0);
|
||
|
||
real price = riga.get_real(RDOC_PREZZOL);
|
||
tmp = price.string(text_len, 2); tmp.trim();
|
||
if (tmp.ends_with(".00") && _doppio_zero)
|
||
tmp.strip(".");
|
||
cmd << ',' << tmp;
|
||
|
||
const TRectype & anamag = cache().get(LF_ANAMAG, riga.get(RDOC_CODARTMAG));
|
||
int rep = riga.get_int(ANAMAG_REPARTO);
|
||
|
||
if (rep <= 0 || rep > 25)
|
||
rep = 1;
|
||
cmd << ',' << rep;
|
||
|
||
real qta = riga.get(RDOC_QTA);
|
||
|
||
tmp = qta.string(10, 5); tmp.trim();
|
||
cmd << ',' << tmp << ']';
|
||
|
||
aga_dde_execute(conn, cmd);
|
||
}
|
||
}
|
||
|
||
para = _bye_bye; // ARRIVEDERCI E GRAZIE!
|
||
for (int i = 1; i <= 2; i++)
|
||
{
|
||
tmp = para.get();
|
||
if (tmp.full())
|
||
{
|
||
tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')');
|
||
cmd.format("[TXT%d,%s]", i, (const char*)tmp);
|
||
aga_dde_execute(conn, cmd);
|
||
}
|
||
}
|
||
|
||
real max;
|
||
TTipo_pag tmax = _rim_dir;
|
||
|
||
for (int j = 1; j <= 8; j++)
|
||
{
|
||
const real & val = _chiusura->get_real(F_INC01 + j - 1);
|
||
|
||
if (max < val)
|
||
{
|
||
max = val;
|
||
tmax = _chiusura->tipo(j);
|
||
}
|
||
}
|
||
switch (tmax)
|
||
{
|
||
case _tratta :
|
||
case _ric_ban :
|
||
case _tratta_acc :
|
||
case _rid :
|
||
case _bonfico :
|
||
tmp = "CRT";
|
||
break;
|
||
case _cessione : // assegno
|
||
tmp = "ASS";
|
||
break;
|
||
case _paghero : // Ticket / Buoni
|
||
tmp = "TICK";
|
||
break;
|
||
case _let_cred : // carta di credito
|
||
tmp = "CARD";
|
||
break;
|
||
case _rim_dir :
|
||
default :
|
||
tmp = "CASH";
|
||
break;
|
||
}
|
||
cmd.cut(0) << '[' << tmp << ']';
|
||
aga_dde_execute(conn, cmd);
|
||
|
||
aga_dde_terminate(conn);
|
||
}
|
||
|
||
void TScontrino_application::print_multiprinter_nettuna()
|
||
{
|
||
TString80 cmd, tmp;
|
||
TScontrino_mask & m = (TScontrino_mask & ) edit_mask();
|
||
TDocumento & doc = m.doc();
|
||
const int text_len = 18;
|
||
TParagraph_string para("", text_len);
|
||
const int rows = doc.physical_rows();
|
||
TCond_vendita cv(NULL, NULL);
|
||
TFilename sc_file;
|
||
|
||
sc_file.temp(NULL, "txt");
|
||
|
||
{
|
||
ofstream f(sc_file);
|
||
|
||
for (int r = 1; r <= rows; r++)
|
||
{
|
||
const TRiga_documento& riga = doc[r];
|
||
|
||
if (riga.is_merce())
|
||
{
|
||
real qta = riga.get(RDOC_QTA);
|
||
const bool storno = qta < ZERO;
|
||
cmd = storno ? "STOR;" : "VEND;";
|
||
para = riga.get(RDOC_DESCR);
|
||
cmd << para.get(0) << ";";
|
||
|
||
real price = riga.get_real(RDOC_PREZZOL);
|
||
tmp = price.stringa(18, 2); tmp.trim();
|
||
cmd << tmp << ";";
|
||
qta = abs(qta);
|
||
tmp = qta.stringa(10, 5); tmp.trim();
|
||
cmd << tmp << ";";
|
||
|
||
const TRectype & anamag = cache().get(LF_ANAMAG, riga.get(RDOC_CODARTMAG));
|
||
int rep = riga.get_int(ANAMAG_REPARTO);
|
||
|
||
if (rep <= 0 || rep > 25)
|
||
rep = 1;
|
||
cmd << rep << '\n';
|
||
}
|
||
else
|
||
if (riga.is_sconto())
|
||
{
|
||
real val;
|
||
bool magg = false;
|
||
|
||
if (riga.is_sconto_perc())
|
||
{
|
||
cv.set_sconto(riga.get(RDOC_SCONTO));
|
||
val = cv.sconto_val() * CENTO;
|
||
magg = val < ZERO;
|
||
val = abs(val);
|
||
cmd = magg ? "MAG%" : "SCO%";
|
||
}
|
||
else
|
||
{
|
||
val = riga.get_real(RDOC_PREZZO);
|
||
magg = val < ZERO;
|
||
val = abs(val);
|
||
cmd = magg ? "MAGV" : "SCOV";
|
||
}
|
||
tmp = val.stringa(18, 2); tmp.trim();
|
||
cmd << tmp << '\n';
|
||
}
|
||
f << cmd;
|
||
}
|
||
|
||
para = _bye_bye; // ARRIVEDERCI E GRAZIE!
|
||
for (tmp = para.get(); tmp.full(); tmp = para.get())
|
||
{
|
||
if (tmp.full())
|
||
{
|
||
cmd.format("DESC;%s\n", (const char*)tmp);
|
||
f << cmd;
|
||
}
|
||
}
|
||
|
||
for (int j = 1; j <= 8; j++)
|
||
{
|
||
const real & val = _chiusura->get_real(F_INC01 + j - 1);
|
||
|
||
if (val > ZERO)
|
||
{
|
||
tmp = val.stringa(18, 2); tmp.trim();
|
||
int tipo = 1;
|
||
switch (_chiusura->tipo(j))
|
||
{
|
||
case _tratta :
|
||
case _ric_ban :
|
||
case _tratta_acc :
|
||
case _rid :
|
||
case _bonfico :
|
||
tipo = 5;
|
||
break;
|
||
case _cessione : // assegno
|
||
tipo = 2;
|
||
break;
|
||
case _paghero : // Ticket / Buoni
|
||
tipo = 6;
|
||
break;
|
||
case _let_cred : // carta di credito
|
||
tipo = 4;
|
||
break;
|
||
case _rim_dir :
|
||
default :
|
||
tipo = 1;
|
||
break;
|
||
}
|
||
cmd.format("PAGA;%s;%s;%d\n" , (const char *) tmp, (const char *) _chiusura->labpag(j), tipo);
|
||
f << cmd;
|
||
}
|
||
}
|
||
}
|
||
TFilename app(_cassa_dir);
|
||
|
||
app.add(_cassa_app);
|
||
cmd = app ; cmd << " " << sc_file;
|
||
|
||
TExternal_app stampa(cmd);
|
||
|
||
stampa.run();
|
||
remove_file(sc_file);
|
||
}
|
||
|
||
void TScontrino_application::print_multiprinter_logic()
|
||
{
|
||
TString80 cmd, tmp;
|
||
TScontrino_mask & m = (TScontrino_mask & ) edit_mask();
|
||
TDocumento & doc = m.doc();
|
||
const int text_len = 18;
|
||
TParagraph_string para("", text_len);
|
||
const int rows = doc.physical_rows();
|
||
TCond_vendita cv(NULL, NULL);
|
||
TFilename sc_file;
|
||
|
||
sc_file.temp(NULL, "txt");
|
||
|
||
{
|
||
ofstream f(sc_file);
|
||
|
||
for (int r = 1; r <= rows; r++)
|
||
{
|
||
const TRiga_documento& riga = doc[r];
|
||
|
||
if (riga.is_merce())
|
||
{
|
||
real qta = riga.get(RDOC_QTA);
|
||
const bool storno = qta < ZERO;
|
||
cmd = storno ? "STOR;" : "VEND;";
|
||
para = riga.get(RDOC_DESCR);
|
||
cmd << para.get(0) << ";";
|
||
|
||
real price = riga.get_real(RDOC_PREZZOL);
|
||
tmp = price.stringa(18, 2); tmp.trim();
|
||
cmd << tmp << ";";
|
||
qta = abs(qta);
|
||
tmp = qta.stringa(10, 5); tmp.trim();
|
||
cmd << tmp << ";";
|
||
|
||
const TRectype & anamag = cache().get(LF_ANAMAG, riga.get(RDOC_CODARTMAG));
|
||
int rep = riga.get_int(ANAMAG_REPARTO);
|
||
|
||
if (rep <= 0 || rep > 25)
|
||
rep = 1;
|
||
cmd << rep << '\n';
|
||
}
|
||
else
|
||
if (riga.is_sconto())
|
||
{
|
||
real perc;
|
||
real val;
|
||
bool magg = false;
|
||
|
||
if (riga.is_sconto_perc())
|
||
{
|
||
cv.set_sconto(riga.get(RDOC_SCONTO));
|
||
perc = cv.sconto_val() * CENTO;
|
||
magg = perc < ZERO;
|
||
perc = abs(perc);
|
||
}
|
||
else
|
||
{
|
||
val = riga.get_real(RDOC_PREZZO);
|
||
magg = val < ZERO;
|
||
val = abs(val);
|
||
}
|
||
cmd = magg ? "MAGG" : "SCON";
|
||
para = riga.get(RDOC_DESCR);
|
||
cmd << para.get(0) << ";";
|
||
tmp = perc.stringa(6, 2); tmp.trim();
|
||
cmd << tmp << ";";
|
||
tmp = val.stringa(18, 2); tmp.trim();
|
||
cmd << tmp << '\n';
|
||
}
|
||
f << cmd;
|
||
}
|
||
|
||
para = _bye_bye; // ARRIVEDERCI E GRAZIE!
|
||
for (tmp = para.get(); tmp.full(); tmp = para.get())
|
||
{
|
||
if (tmp.full())
|
||
{
|
||
cmd.format("DESC;%s\n", (const char*)tmp);
|
||
f << cmd;
|
||
}
|
||
}
|
||
|
||
const TString & cofi = doc.clifor().get(CLI_COFI);
|
||
|
||
if (cofi.full())
|
||
{
|
||
cmd.format("CODF;%s\n", (const char*)cofi);
|
||
f << cmd;
|
||
}
|
||
for (int j = 1; j <= 8; j++)
|
||
{
|
||
const real & val = _chiusura->get_real(F_INC01 + j - 1);
|
||
|
||
if (val > ZERO)
|
||
{
|
||
tmp = val.stringa(18, 2); tmp.trim();
|
||
cmd.format("PAGA;%s;%s\n" , (const char *) tmp, (const char *) _chiusura->labpag(j));
|
||
f << cmd;
|
||
}
|
||
}
|
||
}
|
||
TFilename app(_cassa_dir);
|
||
|
||
app.add(_cassa_app);
|
||
cmd = app ; cmd << " " << sc_file;
|
||
|
||
TExternal_app stampa(cmd);
|
||
|
||
stampa.run();
|
||
remove_file(sc_file);
|
||
}
|
||
|
||
void TScontrino_application::print()
|
||
{
|
||
switch (_print_type)
|
||
{
|
||
case ' ':
|
||
TMotore_application::print();
|
||
break;
|
||
case 'E':
|
||
if (_cassa_app.full())
|
||
{
|
||
TFilename sc_file;
|
||
TFilename app(_cassa_dir);
|
||
TString cmd; cmd;
|
||
|
||
app.add(_cassa_app);
|
||
sc_file.temp(NULL, "txt");
|
||
|
||
TDocumento_mask & mask = (TDocumento_mask &) edit_mask();
|
||
TConfig ini(sc_file);
|
||
|
||
mask2ini(mask, ini);
|
||
cmd << app << " -i" << sc_file;
|
||
|
||
TExternal_app stampa(cmd);
|
||
|
||
stampa.run();
|
||
}
|
||
break;
|
||
case 'R': // Wincor
|
||
print_wincor();
|
||
break;
|
||
case 'L': // Multiprinter Logic, Crf Open, EJ, PJ
|
||
print_multiprinter_logic();
|
||
break;
|
||
case 'N': // Multiprinter Nettuna
|
||
print_multiprinter_nettuna();
|
||
break;
|
||
default: //
|
||
TMotore_application::print();
|
||
break;
|
||
}
|
||
}
|
||
|
||
int vd0700( int argc, char* argv[])
|
||
{
|
||
TScontrino_application a;
|
||
|
||
a.run( argc, argv, TR("Vendita a banco"));
|
||
return 0;
|
||
}
|