git-svn-id: svn://10.65.10.50/branches/R_10_00@22689 c028cbd2-c16b-5b4b-a496-9718f37d4682
261 lines
6.1 KiB
C++
261 lines
6.1 KiB
C++
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <colors.h>
|
|
#include <recarray.h>
|
|
#include <dongle.h>
|
|
#include <progind.h>
|
|
#include <recset.h>
|
|
#include <relation.h>
|
|
|
|
#include "ve2800.h"
|
|
#include "../mg/anamag.h"
|
|
#include "rcondv.h"
|
|
|
|
////////////////////////////////////////////////////////
|
|
// MASCHERA
|
|
////////////////////////////////////////////////////////
|
|
|
|
class TRicarico_listini_mask : public TAutomask
|
|
{
|
|
TBit_array _dirty;
|
|
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
void load();
|
|
void save();
|
|
void save_if_dirty();
|
|
void set_dirty(TOperable_field& o);
|
|
|
|
public:
|
|
TRicarico_listini_mask() : TAutomask("ve2800a") {}
|
|
};
|
|
|
|
void TRicarico_listini_mask::set_dirty(TOperable_field& o)
|
|
{
|
|
if (is_running())
|
|
{
|
|
TSheet_field& s = sfield(F_LISTINO);
|
|
const int row = s.selected();
|
|
if (!_dirty[row])
|
|
{
|
|
const int col = (o.dlg() % 100) - 1;
|
|
s.set_back_and_fore_color(EASY_RIDER_COLOR, NORMAL_COLOR, row, col);
|
|
_dirty.set(row);
|
|
enable(DLG_SAVEREC);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TRicarico_listini_mask::save()
|
|
{
|
|
TSheet_field& s = sfield(F_LISTINO);
|
|
|
|
TFast_isamfile anamag(LF_ANAMAG);
|
|
TFast_isamfile rcondv(LF_RCONDV);
|
|
|
|
TProgind pi(s.items(), TR("Salvataggio modifiche"), false, true);
|
|
FOR_EACH_SHEET_ROW(s, r, row) if (_dirty[r])
|
|
{
|
|
if (!pi.setstatus(r))
|
|
break;
|
|
|
|
const TString& codlis = get(F_CODLIS);
|
|
const TString80 codart = row->get(s.cid2index(F_CODART));
|
|
|
|
anamag.put(ANAMAG_CODART, codart);
|
|
if (anamag.read() == NOERR)
|
|
{
|
|
anamag.put(ANAMAG_ULTCOS1, row->get(s.cid2index(F_COSTO)));
|
|
anamag.put(ANAMAG_USER3, row->get(s.cid2index(F_RICARICO)));
|
|
anamag.rewrite();
|
|
}
|
|
|
|
rcondv.zero();
|
|
rcondv.put(RCONDV_TIPO, "L");
|
|
rcondv.put(RCONDV_COD, codlis);
|
|
rcondv.put(RCONDV_TIPORIGA, "A");
|
|
rcondv.put(RCONDV_CODRIGA, codart);
|
|
if (rcondv.read() == NOERR)
|
|
{
|
|
rcondv.put(RCONDV_PREZZO, row->get(s.cid2index(F_OLDPRICE)));
|
|
rcondv.rewrite();
|
|
}
|
|
}
|
|
_dirty.reset();
|
|
disable(DLG_SAVEREC);
|
|
}
|
|
|
|
void TRicarico_listini_mask::save_if_dirty()
|
|
{
|
|
const long n = _dirty.ones();
|
|
if (n > 0 && yesno_box(FR("Si desiderano registrare le %ld righe modificate?"), n))
|
|
save();
|
|
}
|
|
|
|
void TRicarico_listini_mask::load()
|
|
{
|
|
TSheet_field& s = sfield(F_LISTINO);
|
|
TMask& sm = s.sheet_mask();
|
|
|
|
s.destroy();
|
|
|
|
TString query;
|
|
query << "USE RCONDV";
|
|
|
|
if (!field(F_FILTRIC).empty())
|
|
query << " SELECT ANAMAG.USER3==\"" << get(F_FILTRIC) << '"';
|
|
|
|
query << "\nJOIN ANAMAG INTO CODART==CODRIGA";
|
|
query << "\nFROM TIPO=L COD=#COD TIPORIGA=A";
|
|
if (!field(F_FROMCOD).empty())
|
|
query << " CODRIGA=" << get(F_FROMCOD);
|
|
|
|
query << "\nTO TIPO=L COD=#COD TIPORIGA=A";
|
|
if (!field(F_TOCOD).empty())
|
|
query << " CODRIGA=" << get(F_TOCOD);
|
|
|
|
TISAM_recordset rcondv(query);
|
|
rcondv.set_var("#COD", get(F_CODLIS));
|
|
|
|
TProgind pi(rcondv.items(), TR("Caricamento..."), false, true);
|
|
const TRelation& rel = *rcondv.cursor()->relation();
|
|
for (bool ok = rcondv.move_first(); ok; ok = rcondv.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
FOR_EACH_MASK_FIELD(sm, i, f) if (f->field())
|
|
{
|
|
const char* val = f->field()->read(rel);
|
|
f->set(val);
|
|
}
|
|
TToken_string& r = s.row(-1);
|
|
if (r.empty()) // Dummy test
|
|
{
|
|
sm.field(F_RICARICO).on_hit();
|
|
sm.field(F_OLDPRICE).on_hit();
|
|
sm.field(F_NEWPRICE).on_hit();
|
|
FOR_EACH_MASK_FIELD(sm, i, f)
|
|
{
|
|
const short id = f->dlg();
|
|
if (id >= 101 && id < 200)
|
|
r.add(f->get(), (id % 100) -1);
|
|
}
|
|
}
|
|
}
|
|
s.force_update();
|
|
_dirty.reset();
|
|
disable(DLG_SAVEREC);
|
|
}
|
|
|
|
bool TRicarico_listini_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_CODLIS:
|
|
case F_FILTRIC:
|
|
case F_FROMCOD:
|
|
case F_TOCOD:
|
|
if (e == fe_modify)
|
|
{
|
|
save_if_dirty();
|
|
load();
|
|
}
|
|
break;
|
|
case F_COSTO:
|
|
case F_RICARICO:
|
|
if (e == fe_modify && jolly)
|
|
{
|
|
TSheet_field& s = sfield(F_LISTINO);
|
|
TMask& sm = s.sheet_mask();
|
|
const real costo = sm.get(F_COSTO);
|
|
real price = 0.10;
|
|
if (costo > 0.03)
|
|
{
|
|
const real ricarico = cache().get("&RIC", sm.get(F_RICARICO), "R0");
|
|
price = costo * (CENTO + ricarico) / CENTO;
|
|
}
|
|
sm.set(F_NEWPRICE, price, 0x3);
|
|
set_dirty(o);
|
|
}
|
|
break;
|
|
case F_OLDPRICE:
|
|
case F_NEWPRICE:
|
|
if (e == fe_modify && jolly)
|
|
{
|
|
TMask& sm = o.mask();
|
|
const real costo = sm.get(F_COSTO);
|
|
const real sconto = sm.get(F_SCONTO);
|
|
const real prezzo = o.get();
|
|
real scontato = prezzo * (CENTO - sconto) / CENTO;
|
|
scontato.round(2);
|
|
real margine = (scontato > ZERO) ? CENTO * (scontato - costo) / scontato : ZERO;
|
|
sm.set(o.dlg() + (F_NEWMARGIN-F_NEWPRICE), margine, 0x3);
|
|
set_dirty(o);
|
|
|
|
const real oldprice = sm.get(F_OLDPRICE);
|
|
if (oldprice> ZERO)
|
|
{
|
|
const real newprice = sm.get(F_NEWPRICE);
|
|
const real delta = (newprice - oldprice) * CENTO / oldprice;
|
|
sm.set(F_DELTAPRICE, delta);
|
|
}
|
|
const real deltam = sm.get_real(F_NEWMARGIN) - sm.get_real(F_OLDMARGIN);
|
|
sm.set(F_DELTAMARGIN, deltam);
|
|
}
|
|
break;
|
|
case DLG_SAVEREC:
|
|
if (e == fe_button && jolly == 0 && _dirty.first_one() >= 0)
|
|
{
|
|
save();
|
|
load();
|
|
}
|
|
break;
|
|
case DLG_CANCEL:
|
|
case DLG_QUIT:
|
|
if (e == fe_button && jolly == 0)
|
|
save_if_dirty();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
// APPLICAZIONE
|
|
////////////////////////////////////////////////////////
|
|
|
|
class TRicarico_listini : public TSkeleton_application
|
|
{
|
|
protected:
|
|
virtual bool create();
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
|
|
void TRicarico_listini::main_loop()
|
|
{
|
|
TRicarico_listini_mask mask;
|
|
while (mask.run() == K_ENTER);
|
|
}
|
|
|
|
bool TRicarico_listini::create()
|
|
{
|
|
Tdninst dninst;
|
|
if (!dninst.can_I_run(true))
|
|
return error_box(TR("Programma non autorizzato!"));
|
|
TSheet_field::set_line_number_width(4);
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
int ve2800(int argc, char* argv[])
|
|
{
|
|
TRicarico_listini a;
|
|
a.run(argc, argv, TR("Ricarico Listini"));
|
|
return 0;
|
|
}
|
|
|