5e9b747386
git-svn-id: svn://10.65.10.50/trunk@275 c028cbd2-c16b-5b4b-a496-9718f37d4682
941 lines
21 KiB
C++
Executable File
941 lines
21 KiB
C++
Executable File
// ba3700.cpp - Tabella condizioni di pagamento
|
|
|
|
#include <applicat.h>
|
|
#include <mask.h>
|
|
#include <msksheet.h>
|
|
#include <relapp.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
#include <config.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba3700.h"
|
|
#include "nditte.h"
|
|
|
|
#define ALIAS 1
|
|
|
|
class Riga_tabrpg : public TToken_string
|
|
{
|
|
public:
|
|
const TString& operator = (const TString& s)
|
|
{return TToken_string::operator=(s);}
|
|
Riga_tabrpg (long,const char*,const char*,const char*);
|
|
};
|
|
|
|
Riga_tabrpg::Riga_tabrpg(long num_giorni,const char* perc,const char* tipo_pag, const char* ulter_class)
|
|
: TToken_string(80)
|
|
{
|
|
add(num_giorni); add(perc); add(tipo_pag); add(ulter_class);
|
|
}
|
|
|
|
class TRighe_tabrpg : public TArray
|
|
{
|
|
public:
|
|
void add_riga(long=0l,const char* percent="",const char* tipo_pagam="",
|
|
const char* ult_class="");
|
|
|
|
TRighe_tabrpg() {}
|
|
};
|
|
|
|
void TRighe_tabrpg::add_riga(long num_giorni,const char* perc, const char* tipo_pag,const char* ulter_class)
|
|
{
|
|
add(new Riga_tabrpg(num_giorni,perc,tipo_pag,ulter_class));
|
|
}
|
|
|
|
|
|
class BA3700_application : public TRelation_application
|
|
{
|
|
static bool intervallo_rate (TMask_field& f, KEY k);
|
|
static bool rate_differenziate (TMask_field& f, KEY k);
|
|
static bool tipo_prima_rata (TMask_field& f, KEY k);
|
|
static bool numero_rate (TMask_field& f, KEY k);
|
|
static bool mese_commerciale (TMask_field& f, KEY k);
|
|
static bool riga_sheet(int r, KEY k);
|
|
|
|
TRelation * _rel;
|
|
TMask * _msk;
|
|
TBit_array _righe_gia_presenti;
|
|
|
|
int _mode; // Modo maschera corrente
|
|
TRighe_tabrpg _righe_tabrpg;
|
|
long _interv_rate, _numero_rate;
|
|
int _riga;
|
|
|
|
void read_tabrpg (TMask&);
|
|
bool fill_sheet (TMask&);
|
|
void togli_dal_file (const TString&);
|
|
void calcola_percentuale (TMask& m);
|
|
bool ricalcola_numero_giorni (TMask_field& f, KEY k);
|
|
bool ricalcolo_percentuale (TMask_field& f, KEY k);
|
|
void tipo_pagamento (TMask_field& f, KEY k);
|
|
void ulteriore_riclass (TMask_field& f, KEY k);
|
|
|
|
protected:
|
|
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
|
|
virtual TRelation* get_relation() const { return _rel; }
|
|
virtual TMask* get_mask(int mode);
|
|
virtual bool changing_mask(int mode) {return FALSE; }
|
|
virtual bool remove();
|
|
|
|
virtual void init_modify_mode(TMask&);
|
|
virtual void init_insert_mode(TMask&);
|
|
virtual int rewrite(const TMask& m);
|
|
virtual int write(const TMask& m);
|
|
virtual int read(TMask& m);
|
|
|
|
int cancella(long items);
|
|
|
|
public:
|
|
|
|
TMask * main_mask() { return _msk; }
|
|
BA3700_application() : TRelation_application() {}
|
|
virtual ~BA3700_application() {}
|
|
};
|
|
|
|
|
|
HIDDEN BA3700_application * app() { return (BA3700_application*) MainApp(); }
|
|
|
|
TMask* BA3700_application::get_mask(int mode)
|
|
{
|
|
return _msk;
|
|
}
|
|
|
|
void BA3700_application::togli_dal_file(const TString& cod_pag)
|
|
{
|
|
long i;
|
|
TTable& tab_rpg = (TTable&)_rel->lfile(-ALIAS);
|
|
long last = _righe_gia_presenti.last_one();
|
|
long start = _righe_gia_presenti.first_one();
|
|
TString16 dep;
|
|
|
|
for (i=start; i<=last; i++)
|
|
{
|
|
if (_righe_gia_presenti[i])
|
|
{
|
|
tab_rpg.zero();
|
|
dep.format ("%-4s%3d", (const char*) cod_pag, i);
|
|
tab_rpg.put("CODTAB", dep);
|
|
tab_rpg.remove();
|
|
}
|
|
}
|
|
}
|
|
|
|
void BA3700_application::read_tabrpg(TMask& m)
|
|
{
|
|
long numero_giorni, num_giorni_prima_rata;
|
|
TString tipo_pagamento;
|
|
TString percentuale, cod_pag, ult_class;
|
|
bool ok = FALSE;
|
|
TTable& tab_rpg = (TTable&)_rel->lfile(-ALIAS);
|
|
long numrig;
|
|
int i = 0;
|
|
|
|
_numero_rate = 0;
|
|
|
|
cod_pag = m.get(F_CODICE);
|
|
|
|
_rel->update();
|
|
|
|
_righe_gia_presenti.reset();
|
|
|
|
ok = _rel->is_first_match(-ALIAS);
|
|
|
|
while (ok)
|
|
{
|
|
TRecfield num (tab_rpg.curr(),"CODTAB",4,6);
|
|
numrig = long(num);
|
|
numero_giorni = tab_rpg.get_long("I0");
|
|
percentuale = tab_rpg.get ("R0");
|
|
tipo_pagamento = tab_rpg.get ("S0");
|
|
ult_class = tab_rpg.get ("S1");
|
|
|
|
if (i == 0) //Sono sulla prima rata
|
|
num_giorni_prima_rata = numero_giorni;
|
|
|
|
if (i == 1) //Sono sulla seconda rata
|
|
_interv_rate = numero_giorni - num_giorni_prima_rata;
|
|
|
|
_righe_tabrpg.add_riga(numero_giorni,percentuale,tipo_pagamento,ult_class);
|
|
_righe_gia_presenti.set(numrig);
|
|
ok = _rel->next_match(-ALIAS);
|
|
i++;
|
|
}
|
|
_numero_rate = i;
|
|
}
|
|
|
|
bool BA3700_application::fill_sheet(TMask& m)
|
|
{
|
|
long items;
|
|
|
|
_righe_tabrpg.destroy();
|
|
|
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_RPG);
|
|
cs.reset();
|
|
|
|
read_tabrpg(m);
|
|
|
|
items = _righe_tabrpg.items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string &riga = cs.row(i);
|
|
|
|
riga.cut(0);
|
|
riga = (Riga_tabrpg&)_righe_tabrpg[i];
|
|
}
|
|
|
|
bool rate_diff = m.get_bool(F_RATE_DIFF);
|
|
|
|
if (!rate_diff)
|
|
calcola_percentuale(m);
|
|
|
|
cs.force_update();
|
|
|
|
_righe_tabrpg.destroy();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void BA3700_application::init_insert_mode(TMask& m)
|
|
{
|
|
_interv_rate = 0;
|
|
}
|
|
|
|
void BA3700_application::init_modify_mode(TMask& m)
|
|
{
|
|
bool rate_differenziate = FALSE;
|
|
|
|
rate_differenziate = m.get_bool(F_RATE_DIFF);
|
|
|
|
if (rate_differenziate)
|
|
_interv_rate = 0;
|
|
}
|
|
|
|
bool BA3700_application::rate_differenziate(TMask_field& f, KEY k)
|
|
{
|
|
long items;
|
|
|
|
TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
bool rate_diff = f.mask().get_bool(F_RATE_DIFF);
|
|
|
|
if (k == K_SPACE)
|
|
{
|
|
if (rate_diff)
|
|
{
|
|
f.mask().disable(F_NUM_RATE);
|
|
f.mask().disable(F_INT_RATE);
|
|
|
|
for (int i = 1; i < items; i++)
|
|
{
|
|
if (i == 1)
|
|
cs.enable_cell(i,1);
|
|
|
|
if (i >= 2)
|
|
cs.enable_cell(i,-1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
f.mask().enable(F_NUM_RATE);
|
|
f.mask().enable(F_INT_RATE);
|
|
|
|
f.mask().set(F_NUM_RATE, items);
|
|
f.mask().set(F_INT_RATE, app()->_interv_rate);
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
|
|
if (i == 1)
|
|
cs.disable_cell(i,1);
|
|
|
|
if (i >= 2)
|
|
cs.disable_cell(i,-1);
|
|
}
|
|
}
|
|
cs.force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::intervallo_rate(TMask_field& f, KEY k)
|
|
{
|
|
bool mese_comm = FALSE;
|
|
long numero_giorni, num_giorni, items, interv_rate;
|
|
|
|
if (f.to_check(k))
|
|
{
|
|
mese_comm = f.mask().get_bool(F_MESECOMM);
|
|
interv_rate = f.mask().get_long(F_INT_RATE);
|
|
|
|
if (mese_comm)
|
|
{
|
|
if ((interv_rate % 30) != 0)
|
|
{
|
|
f.error_box("L' intervallo tra rate successive deve essere un multiplo di 30, perche' e' stato selezionato il mese commerciale");
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if (i >= 1)
|
|
{
|
|
numero_giorni = num_giorni + interv_rate;
|
|
TString ng (format("%4d", numero_giorni));
|
|
riga.add(ng, 0);
|
|
}
|
|
|
|
num_giorni = atol(riga.get(0));
|
|
}
|
|
cs.force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::tipo_prima_rata(TMask_field& f, KEY k)
|
|
{
|
|
char tipo_rata;
|
|
long items;
|
|
|
|
TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
bool rate_diff = f.mask().get_bool(F_RATE_DIFF);
|
|
|
|
if (f.to_check(k, TRUE))
|
|
{
|
|
tipo_rata = f.mask().get(F_TIPO_PRIMA_RATA)[0];
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if ((tipo_rata == '1') || (tipo_rata == '2') || (tipo_rata == '3'))
|
|
{
|
|
|
|
if (i == 0)
|
|
{
|
|
riga.add("0.00", 1);
|
|
cs.disable_cell(i,1);
|
|
}
|
|
else
|
|
{
|
|
if (rate_diff)
|
|
cs.enable_cell(i,1);
|
|
else
|
|
if (i == 0)
|
|
cs.enable_cell(i,1);
|
|
}
|
|
}
|
|
else
|
|
if ((tipo_rata == '4') || (tipo_rata == '5') || (tipo_rata == '6'))
|
|
{
|
|
|
|
if (i == 0)
|
|
riga.add("100.00", 1);
|
|
|
|
if (i >= 1)
|
|
riga.add("0.00", 1);
|
|
|
|
cs.disable_cell(i,1);
|
|
}
|
|
else
|
|
{
|
|
if (tipo_rata == 0)
|
|
if (rate_diff)
|
|
cs.enable_cell(i,1);
|
|
else
|
|
if (i == 0)
|
|
cs.enable_cell(i,1);
|
|
}
|
|
}
|
|
if (rate_diff)
|
|
{
|
|
TString perc_str;
|
|
real percentuale;
|
|
|
|
long items = cs.items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
perc_str = riga.get(1);
|
|
real perc(perc_str);
|
|
percentuale += perc;
|
|
}
|
|
|
|
if (percentuale != 100)
|
|
{
|
|
f.error_box("La somma delle percentuali di tutte le rate deve essere 100");
|
|
return FALSE;
|
|
}
|
|
}
|
|
else
|
|
app()->calcola_percentuale(f.mask());
|
|
cs.force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::numero_rate(TMask_field& f, KEY k)
|
|
{
|
|
long items, num_giorni, numero_giorni;
|
|
TString perc_str;
|
|
real perc,percentuale,perc_rimasta;
|
|
|
|
TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
if (f.to_check(k))
|
|
{
|
|
long numero_rate = f.mask().get_long(F_NUM_RATE);
|
|
char tipo_rata = f.mask().get (F_TIPO_PRIMA_RATA)[0];
|
|
long interv_rate = f.mask().get_long(F_INT_RATE);
|
|
|
|
if (numero_rate == 0)
|
|
{
|
|
f.error_box("Valore non consentito ! Deve esistere almeno la prima rata.");
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
if (items < numero_rate)
|
|
{
|
|
TToken_string& riga_app = cs.row((int)items - 1); //Mi posiziono sull'ultima rata
|
|
|
|
num_giorni = atol(riga_app.get(0));
|
|
|
|
for (long i = items; i < numero_rate; i++)
|
|
{
|
|
TToken_string& riga = cs.row((int)i);
|
|
|
|
riga.cut(0);
|
|
riga = riga_app;
|
|
numero_giorni = num_giorni + interv_rate;
|
|
TString ng (format("%4d", numero_giorni));
|
|
riga.add(ng, 0);
|
|
num_giorni = atol(riga.get(0));
|
|
|
|
if (i == 1l)
|
|
cs.disable_cell((int)i,1);
|
|
|
|
else if (i >= 2l)
|
|
cs.disable_cell((int)i,-1);
|
|
|
|
// cs.disable_cell(i,-1);
|
|
}
|
|
}
|
|
else
|
|
if (items > numero_rate)
|
|
{
|
|
TToken_string& riga_appI = cs.row(0); //Mi posiziono sulla prima rata
|
|
TToken_string& riga_appII = cs.row(1); //Mi posiziono sulla seconda rata ***
|
|
|
|
num_giorni = atol(riga_appI.get(0));
|
|
|
|
cs.reset();
|
|
|
|
for (int i = 0; i < numero_rate; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if (i == 0) // ***
|
|
{ //Ricopio i dati della prima rata nella prima rata
|
|
riga.cut(0); // ***
|
|
riga = riga_appI; // ***
|
|
}
|
|
|
|
if (i > 0)
|
|
{
|
|
riga.cut(0);
|
|
riga = riga_appII; //Ricopio i dati della seconda rata in tutte le altre
|
|
numero_giorni = num_giorni + interv_rate;
|
|
TString ng (format("%4d", numero_giorni));
|
|
riga.add(ng, 0);
|
|
}
|
|
num_giorni = atol(riga.get(0));
|
|
|
|
|
|
if (i == 1)
|
|
cs.disable_cell(i,1);
|
|
if (i >=2)
|
|
cs.disable_cell(i,-1);
|
|
}
|
|
}
|
|
}
|
|
|
|
items = numero_rate;
|
|
|
|
for (int i = 0; i<items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if (i == 0)
|
|
{
|
|
perc_str = riga.get(1);
|
|
real perc(perc_str);
|
|
if ((((tipo_rata!='1')||(tipo_rata!='2')||(tipo_rata!='3'))&&(perc>0))
|
|
||(((tipo_rata=='1')||(tipo_rata=='2')||(tipo_rata=='3'))&&(perc==0)))
|
|
{
|
|
perc_rimasta = 100 - perc;
|
|
percentuale = perc_rimasta / (numero_rate - 1);
|
|
}
|
|
}
|
|
|
|
if (i >= 1)
|
|
{
|
|
TString perc = percentuale.string();
|
|
riga.add(perc, 1);
|
|
}
|
|
}
|
|
cs.force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::mese_commerciale(TMask_field& f, KEY k)
|
|
{
|
|
long interv_rate;
|
|
|
|
if (k == K_SPACE)
|
|
{
|
|
bool mese_comm = f.mask().get_bool(F_MESECOMM);
|
|
bool rate_diff = f.mask().get_bool(F_RATE_DIFF);
|
|
|
|
if (!rate_diff)
|
|
{
|
|
if (mese_comm)
|
|
{
|
|
interv_rate = f.mask().get_long(F_INT_RATE);
|
|
if ((interv_rate % 30) != 0)
|
|
{
|
|
f.error_box("L' intervallo tra rate successive deve essere un multiplo di 30, perche' e' stato selezionato il mese commerciale");
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void BA3700_application::calcola_percentuale(TMask& m)
|
|
{
|
|
TString perc_str;
|
|
real perc_rimasta, percentuale;
|
|
long items;
|
|
|
|
// TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_RPG);
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
for (int i = 0; i<items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if (i == 0)
|
|
{
|
|
perc_str = riga.get(1);
|
|
real perc(perc_str);
|
|
perc_rimasta = 100 - perc;
|
|
percentuale = perc_rimasta / (_numero_rate - 1);
|
|
}
|
|
|
|
if (i >= 1)
|
|
{
|
|
TString perc = percentuale.string();
|
|
riga.add(perc, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool BA3700_application::ricalcolo_percentuale(TMask_field& f, KEY k)
|
|
{
|
|
// TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
long items = cs.items();
|
|
|
|
if (f.mask().mode() == MODE_QUERY)
|
|
return TRUE;
|
|
|
|
if (k == K_ENTER)
|
|
{
|
|
bool rate_diff = app()->main_mask()->get_bool(F_RATE_DIFF);
|
|
if (rate_diff)
|
|
{
|
|
TString perc_str;
|
|
real percentuale;
|
|
|
|
long items = cs.items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
perc_str = riga.get(1);
|
|
real perc(perc_str);
|
|
percentuale += perc;
|
|
}
|
|
|
|
if (percentuale != 100)
|
|
{
|
|
f.error_box("La somma delle percentuali di tutte le rate deve essere 100");
|
|
return FALSE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_riga == 0)
|
|
{
|
|
app()->_numero_rate = items;
|
|
app()->calcola_percentuale(f.mask());
|
|
}
|
|
}
|
|
|
|
cs.force_update();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::ricalcola_numero_giorni(TMask_field& f, KEY k)
|
|
{
|
|
long items, ng, giorni;
|
|
|
|
// TSheet_field& cs = (TSheet_field&)f.mask().field(F_SHEET_RPG);
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
if (f.mask().mode() == MODE_QUERY)
|
|
return TRUE;
|
|
|
|
if (k == K_ENTER)
|
|
{
|
|
bool mese_comm = app()->main_mask()->get_bool(F_MESECOMM);
|
|
bool rate_diff = app()->main_mask()->get_bool(F_RATE_DIFF);
|
|
|
|
if (!rate_diff)
|
|
{
|
|
if (app()->_riga == 0)
|
|
{
|
|
TToken_string& riga_app = cs.row(0);
|
|
giorni = atol(riga_app.get(0));
|
|
|
|
long interv_rate = app()->main_mask()->get_long(F_INT_RATE);
|
|
|
|
if (mese_comm)
|
|
{
|
|
if ((giorni % 30) != 0)
|
|
{
|
|
f.error_box("Il numero di giorni deve essere un multiplo di 30, perche' e' stato selezionato il mese commerciale");
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
for (int i = 1; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
ng = giorni + interv_rate;
|
|
TString ngiorni (format("%4d", ng));
|
|
riga.add(ngiorni, 0);
|
|
|
|
giorni = atol(riga.get(0));
|
|
}
|
|
}
|
|
|
|
if (app()->_riga == 1)
|
|
{
|
|
long gg_I_rata, interv_rate;
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
if (i == 0)
|
|
gg_I_rata = atol(riga.get(0));
|
|
|
|
if (i == 1)
|
|
{
|
|
giorni = atol(riga.get(0));
|
|
|
|
if (mese_comm)
|
|
{
|
|
if ((giorni % 30) != 0)
|
|
{
|
|
f.error_box("Il numero di giorni deve essere un multiplo di 30, perche' e' stato selezionato il mese commerciale");
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
interv_rate = giorni - gg_I_rata;
|
|
}
|
|
|
|
if (i >= 2)
|
|
{
|
|
ng = giorni + interv_rate;
|
|
TString ngiorni (format("%4d", ng));
|
|
riga.add(ngiorni, 0);
|
|
giorni = atol(riga.get(0));
|
|
}
|
|
}
|
|
}
|
|
cs.force_update();
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void BA3700_application::tipo_pagamento(TMask_field& f, KEY k)
|
|
{
|
|
long items;
|
|
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
if (k == K_ENTER)
|
|
{
|
|
bool rate_diff = app()->main_mask()->get_bool(F_RATE_DIFF);
|
|
|
|
if (!rate_diff)
|
|
{
|
|
if (app()->_riga == 1)
|
|
{
|
|
TToken_string& riga_app = cs.row(1);
|
|
TString tp_pag = riga_app.get(2);
|
|
|
|
for (int i = 2; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
riga.add(tp_pag, 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void BA3700_application::ulteriore_riclass(TMask_field& f, KEY k)
|
|
{
|
|
long items;
|
|
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
items = cs.items();
|
|
|
|
if (k == K_ENTER)
|
|
{
|
|
bool rate_diff = app()->main_mask()->get_bool(F_RATE_DIFF);
|
|
|
|
if (!rate_diff)
|
|
{
|
|
if (app()->_riga == 1)
|
|
{
|
|
TToken_string& riga_app = cs.row(1);
|
|
TString ult_riclass = riga_app.get(3);
|
|
|
|
for (int i = 2; i < items; i++)
|
|
{
|
|
TToken_string& riga = cs.row(i);
|
|
|
|
riga.add(ult_riclass, 3);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool BA3700_application::riga_sheet(int r, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
app()->_riga = r;
|
|
|
|
TSheet_field& cs = (TSheet_field&)app()->main_mask()->field(F_SHEET_RPG);
|
|
TMask_field& fld = cs.sheet_mask().field(101);
|
|
|
|
TMask_field& ftp = cs.sheet_mask().field(103);
|
|
app()->tipo_pagamento(ftp,k);
|
|
|
|
TMask_field& fuc = cs.sheet_mask().field(104);
|
|
app()->ulteriore_riclass(fuc,k);
|
|
|
|
TMask_field& f = cs.sheet_mask().field(102);
|
|
|
|
if ((app()->ricalcola_numero_giorni(fld,k))&&(app()->ricalcolo_percentuale(f,k)))
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
int BA3700_application::rewrite(const TMask& m)
|
|
{
|
|
long items;
|
|
TTable& tab_rpg = (TTable&)_rel->lfile(-ALIAS);
|
|
TString dep;
|
|
|
|
TString cod_pag = m.get(F_CODICE);
|
|
|
|
m.autosave(_rel);
|
|
|
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_RPG);
|
|
|
|
items = cs.items();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string &riga = cs.row(i);
|
|
TString codtab (format("%-4s%3d",(const char*)cod_pag,i));
|
|
long numero_giorni = atol(riga.get(0));
|
|
if (numero_giorni != 0)
|
|
{
|
|
tab_rpg.put ("CODTAB", codtab);
|
|
tab_rpg.put ("I0", numero_giorni);
|
|
tab_rpg.put ("R0", riga.get());
|
|
dep = riga.get();
|
|
if (dep != "")
|
|
tab_rpg.put ("S0", dep);
|
|
dep = riga.get();
|
|
if (dep != "")
|
|
tab_rpg.put ("S1", dep);
|
|
|
|
if (_righe_gia_presenti[i])
|
|
{
|
|
tab_rpg.rewrite();
|
|
_righe_gia_presenti.reset(i);
|
|
}
|
|
else
|
|
tab_rpg.write();
|
|
}
|
|
}
|
|
togli_dal_file(cod_pag);
|
|
return _rel->rewrite();
|
|
}
|
|
|
|
int BA3700_application::write(const TMask& m)
|
|
{
|
|
long items;
|
|
TTable& tab_rpg = (TTable&)_rel->lfile(-ALIAS);
|
|
TString dep;
|
|
|
|
TString cod_pag = m.get(F_CODICE);
|
|
|
|
m.autosave(_rel);
|
|
|
|
TSheet_field& cs = (TSheet_field&)m.field(F_SHEET_RPG);
|
|
|
|
items = cs.items();
|
|
|
|
tab_rpg.zero();
|
|
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TToken_string &riga = cs.row(i);
|
|
TString codtab (format("%-4s%3d",(const char*)cod_pag,i));
|
|
long numero_giorni = atol(riga.get(0));
|
|
if (numero_giorni != 0)
|
|
{
|
|
tab_rpg.put ("CODTAB", codtab);
|
|
tab_rpg.put ("I0", numero_giorni);
|
|
tab_rpg.put ("R0", riga.get());
|
|
dep = riga.get();
|
|
if (dep != "")
|
|
tab_rpg.put ("S0", dep);
|
|
dep = riga.get();
|
|
if (dep != "")
|
|
tab_rpg.put ("S1", dep);
|
|
tab_rpg.write();
|
|
}
|
|
}
|
|
return _rel->write();
|
|
}
|
|
|
|
bool BA3700_application::remove()
|
|
{
|
|
TSheet_field& cs = (TSheet_field&)_msk->field(F_SHEET_RPG);
|
|
cancella(cs.items());
|
|
TRelation_application::remove();
|
|
return TRUE;
|
|
}
|
|
|
|
int BA3700_application::cancella(long items)
|
|
{
|
|
TTable& tab_rpg = (TTable&)_rel->lfile(-ALIAS);
|
|
TRecfield an (tab_rpg.curr(),"CODTAB",0,3);
|
|
TString cod_pag,dep;
|
|
|
|
cod_pag = (const char*)(an);
|
|
|
|
for (long i = 0; i < items; i++)
|
|
{
|
|
tab_rpg.zero();
|
|
dep = format ("%-4s", (const char*) cod_pag);
|
|
dep << format ("%3d" , i);
|
|
tab_rpg.put("CODTAB", dep);
|
|
if (tab_rpg.read(_isequal, _lock) == NOERR)
|
|
tab_rpg.remove();
|
|
}
|
|
return tab_rpg.status();
|
|
}
|
|
|
|
int BA3700_application::read(TMask& m)
|
|
{
|
|
m.autoload(_rel);
|
|
fill_sheet(m);
|
|
|
|
return NOERR;
|
|
}
|
|
|
|
bool BA3700_application::user_create()
|
|
{
|
|
_rel = new TRelation (TAB_CPG);
|
|
|
|
//E' stato usato un solo = perche' altrimenti per come sono fatte le lib. vi
|
|
//sono problemi di allineamento all' interno di relation.cpp.
|
|
|
|
_rel->add(TAB_RPG, "CODTAB[1,4]=CODTAB" ,1, 0, ALIAS); //-4 = alias,perche'le
|
|
//due tabelle sono entrambe in TABCOM.dta
|
|
|
|
_interv_rate = 0;
|
|
|
|
_msk = new TMask("ba3700a");
|
|
|
|
_msk->set_handler (F_INT_RATE , intervallo_rate);
|
|
_msk->set_handler (F_RATE_DIFF , rate_differenziate);
|
|
_msk->set_handler (F_TIPO_PRIMA_RATA , tipo_prima_rata);
|
|
_msk->set_handler (F_NUM_RATE , numero_rate);
|
|
_msk->set_handler (F_MESECOMM , mese_commerciale);
|
|
|
|
TSheet_field& cs = (TSheet_field&)_msk->field(F_SHEET_RPG);
|
|
// cs.sheet_mask().set_handler (102 , ricalcolo_percentuale);
|
|
// cs.sheet_mask().set_handler (101 , ricalcola_numero_giorni);
|
|
cs.set_notify (riga_sheet);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3700_application::user_destroy()
|
|
{
|
|
delete _msk;
|
|
delete _rel;
|
|
return TRUE;
|
|
}
|
|
|
|
int ba3700(int argc, char* argv[])
|
|
{
|
|
BA3700_application a;
|
|
a.run(argc, argv, "Tabella condizioni di pagamento");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|