Aggiunti versamenti effettuati in prospetto liquidazione git-svn-id: svn://10.65.10.50/trunk@857 c028cbd2-c16b-5b4b-a496-9718f37d4682
629 lines
15 KiB
C++
Executable File
629 lines
15 KiB
C++
Executable File
#include "cg5500.h"
|
|
|
|
#include <browfile.h>
|
|
#include <prefix.h>
|
|
#include <msksheet.h>
|
|
#include <mailbox.h>
|
|
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <urldefid.h>
|
|
|
|
#include "cg5500a.h"
|
|
|
|
const char* Visliq_app::itoname(int m)
|
|
{
|
|
const char* mn;
|
|
if (_freqviva == "M")
|
|
return itom(m);
|
|
|
|
switch(m)
|
|
{
|
|
case 3:
|
|
mn = "1 Trimestre";
|
|
break;
|
|
case 6:
|
|
mn = "2 Trimestre";
|
|
break;
|
|
case 9:
|
|
mn = "3 Trimestre";
|
|
break;
|
|
case 12:
|
|
mn = "4 Trimestre";
|
|
break;
|
|
}
|
|
|
|
return mn;
|
|
}
|
|
|
|
void Visliq_app::set_freqviva()
|
|
{
|
|
if (look_lia())
|
|
_freqviva = _lia->get("S7");
|
|
else
|
|
{
|
|
TLocalisamfile ditte(LF_NDITTE,TRUE);
|
|
ditte.zero();
|
|
ditte.put("CODDITTA", get_firm());
|
|
ditte.read();
|
|
_freqviva = ditte.get("FREQVIVA");
|
|
}
|
|
}
|
|
|
|
bool Visliq_app::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
_del = new TTable("%DEL");
|
|
_lia = new TTable("LIA");
|
|
_lim = new TTable("LIM");
|
|
_del_r = &(_del->curr());
|
|
_lim_r = &(_lim->curr());
|
|
_del_ditta = new TRecfield(*_del_r,"CODTAB",0,4);
|
|
_del_anno = new TRecfield(*_del_r,"CODTAB",5,8);
|
|
_del_mese = new TRecfield(*_del_r,"CODTAB",9,10);
|
|
_del_tipo = new TRecfield(*_del_r,"CODTAB",11,11);
|
|
_lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3);
|
|
_lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6);
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool Visliq_app::destroy()
|
|
{
|
|
delete _lim_mese;
|
|
delete _lim_anno;
|
|
delete _del_tipo;
|
|
delete _del_mese;
|
|
delete _del_ditta;
|
|
delete _lim_r;
|
|
delete _del_r;
|
|
delete _lim;
|
|
delete _del;
|
|
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
|
|
void Visliq_app::set_mask_freq(TMask& m)
|
|
{
|
|
if (_freqviva == "M")
|
|
{
|
|
m.show(F_MONTHS);
|
|
m.hide(F_TRIMS);
|
|
}
|
|
else
|
|
{
|
|
m.hide(F_MONTHS);
|
|
m.show(F_TRIMS);
|
|
}
|
|
}
|
|
|
|
|
|
bool Visliq_app::sheet_action(int r, KEY k)
|
|
{
|
|
// non si possono cancellare o aggiungere righe
|
|
return (k != K_DEL && k != K_INS);
|
|
}
|
|
|
|
|
|
|
|
const char* Visliq_app::link_handler(TMask& m,
|
|
int n, const char* txt, bool doubleclick)
|
|
{
|
|
// con click visualizza, con double click modifica
|
|
TString st(txt);
|
|
bool iscred = FALSE;
|
|
static int group;
|
|
int firstfoc;
|
|
|
|
if (group != 0) m.hide(group);
|
|
|
|
if (st.find("rimborso") != -1)
|
|
{ group = -1; firstfoc = F_RIMBORSO; }
|
|
else if (st.find("debito") != -1 || st.find("credito") != -1)
|
|
{ group = -2; firstfoc = F_RETTIFICA; }
|
|
else if (st.find("acconto") != -1)
|
|
{ group = -3; firstfoc = F_ACCONTO; }
|
|
|
|
m.show(group);
|
|
m.enable(group);
|
|
|
|
if (doubleclick) m.field(firstfoc).set_focus();
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
bool Visliq_app::menu(MENU_TAG m)
|
|
{
|
|
if (m == BAR_ITEM(1))
|
|
return vis_liq();
|
|
|
|
return TApplication::menu(m);
|
|
}
|
|
|
|
// handlers
|
|
bool Visliq_app::set_ditta(TMask_field& f, KEY k)
|
|
{
|
|
long ditta = atol(f.get());
|
|
|
|
if (ditta <= 0) return k != K_ENTER;
|
|
|
|
if (!prefhndl->exist(ditta))
|
|
{
|
|
warning_box("Archivi ditta %l non presenti!", ditta);
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
main_app().set_firm(ditta);
|
|
((Visliq_app&)main_app()).set_freqviva();
|
|
}
|
|
((Visliq_app&)main_app()).set_mask_freq(f.mask());
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool Visliq_app::set_anno(TMask_field& f, KEY k)
|
|
{
|
|
((Visliq_app&)main_app()).set_year(atoi(f.get()));
|
|
((Visliq_app&)main_app()).set_freqviva();
|
|
((Visliq_app&)main_app()).set_mask_freq(f.mask());
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool Visliq_app::sel_mese_sh1 (TMask_field& f, KEY k)
|
|
{
|
|
if (k != K_SPACE) return TRUE;
|
|
|
|
TMask& m = *(((Visliq_app&)main_app()).get_main_mask());
|
|
TSheet_field& sh = (TSheet_field&)m.field(F_VISLIQ1);
|
|
int month = sh.selected()+1;
|
|
TToken_string& tt = sh.row(sh.selected());
|
|
if (sh.items() == 4) month *= 3;
|
|
((Visliq_app&)main_app()).vis_one(month);
|
|
((Visliq_app&)main_app()).look_lim(month);
|
|
((Visliq_app&)main_app()).update_sheet_row(tt);
|
|
TMask& sm = sh.sheet_mask();
|
|
|
|
sm.field(103).set(tt.get(2));
|
|
sm.field(104).set(tt.get(3));
|
|
sm.field(105).set(tt.get(4));
|
|
sm.field(106).set(tt.get(5));
|
|
sm.field(107).set(tt.get(6));
|
|
|
|
sh.force_update();
|
|
return TRUE;
|
|
}
|
|
|
|
bool Visliq_app::sel_mese_sh2 (TMask_field& f, KEY k)
|
|
{
|
|
if (k != K_SPACE) return TRUE;
|
|
|
|
TMask& m = *(((Visliq_app&)main_app()).get_main_mask());
|
|
TSheet_field& sh = (TSheet_field&)m.field(F_VISLIQ2);
|
|
int month = sh.selected()+1;
|
|
if (sh.items() == 4) month *= 3;
|
|
((Visliq_app&)main_app()).vis_one(month);
|
|
return TRUE;
|
|
}
|
|
|
|
void Visliq_app::update_sheet_row(TToken_string& t)
|
|
{
|
|
// t.add(abs(_lim->get_real("R0")).string(),2);
|
|
// t.add((_lim->get_real("R0")).sign() > 0 ? "D" : "C", 3);
|
|
t.add((_lim->get_real("R1")).string(),4);
|
|
t.add(abs(_lim->get_real("R5")).string(),5);
|
|
t.add((_lim->get_real("R5")).sign() > 0 ? "D" : "C", 6);
|
|
}
|
|
|
|
bool Visliq_app::vis_liq()
|
|
{
|
|
long ditta = get_firm();
|
|
set_freqviva();
|
|
|
|
TMask m("cg5500a");
|
|
|
|
m.set_handler(F_CODDITTA, set_ditta);
|
|
m.set_handler(F_YEAR, set_anno);
|
|
|
|
set_mask_freq(m);
|
|
_year = m.get_int(F_YEAR);
|
|
|
|
while (m.run() != K_ESC)
|
|
{
|
|
int month = m.get_int(_freqviva == "M" ? F_MONTHS : F_TRIMS);
|
|
if (month == 0)
|
|
vis_all();
|
|
else
|
|
vis_one(month);
|
|
}
|
|
|
|
set_firm(ditta);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
bool Visliq_app::vis_all()
|
|
{
|
|
if (!look_lia())
|
|
return FALSE;
|
|
|
|
// mask diverse per trimestrale e annuale
|
|
TMask m(_freqviva == "M" ? "cg5500b" : "cg5500c");
|
|
|
|
TString abi(5);
|
|
TString cab(5);
|
|
TString cnc(5);
|
|
|
|
_mask = &m;
|
|
|
|
TSheet_field& sh = (TSheet_field&)m.field(F_VISLIQ1);
|
|
TSheet_field& sv = (TSheet_field&)m.field(F_VISLIQ2);
|
|
|
|
// disabilita aggiunta/eliminazione righe
|
|
sh.set_notify(sheet_action);
|
|
sv.set_notify(sheet_action);
|
|
|
|
sh.sheet_mask().set_handler(101,sel_mese_sh1);
|
|
sv.sheet_mask().set_handler(101,sel_mese_sh2);
|
|
|
|
m.field(F_CREDPREC).set(_lia->get_real("R0").string());
|
|
|
|
// set sheet
|
|
for (int i = 1; i <= 12; i++)
|
|
{
|
|
|
|
if (!is_month_ok(i) || !look_lim(i))
|
|
continue;
|
|
|
|
TToken_string* tt = new TToken_string(80);
|
|
|
|
tt->add(""); // questo e' il bottone
|
|
tt->add(itoname(i));
|
|
tt->add(abs(_lim->get_real("R0")).string());
|
|
tt->add(_lim->get_real("R0").sign() < 0 ? "C" : "D");
|
|
tt->add(_lim->get_real("R1").string());
|
|
tt->add(abs(_lim->get_real("R5")).string());
|
|
tt->add(_lim->get_real("R5").sign() < 0 ? "C" : "D");
|
|
|
|
sh.row(i-1) = (*tt);
|
|
}
|
|
|
|
// calcola versamenti
|
|
real versamenti[13];
|
|
TDate date[13];
|
|
|
|
for (_del->first(); !_del->eof(); _del->next())
|
|
{
|
|
if (atol(*_del_ditta) != get_firm() ||
|
|
atoi(*_del_anno) != _year)
|
|
continue;
|
|
|
|
// uso solo deleghe normali (tipo == 1) e acconti (tipo == 7)
|
|
int tipod = atoi(*_del_tipo);
|
|
if (tipod != 1 || tipod != 7)
|
|
continue;
|
|
|
|
// somma versamenti nel mese adeguato
|
|
int m = atoi(*_del_mese);
|
|
|
|
if (m >= 12)
|
|
m = tipod == 7 ? 12 : 13;
|
|
|
|
versamenti[m-1] += _del->get_real("R0");
|
|
date[m-1] = _del->get_date("D0");
|
|
abi = _del->get("S7");
|
|
cab = _del->get("S8");
|
|
cnc = _del->get("S9");
|
|
}
|
|
|
|
TString nomemese(26);
|
|
|
|
for (i = 1; i <= 13; i++)
|
|
{
|
|
if (!is_month_ok(i))
|
|
continue;
|
|
|
|
TToken_string* tt = new TToken_string(80);
|
|
nomemese = itoname(i == 13 ? 12 : i);
|
|
|
|
if (i == 12) nomemese << " acconto";
|
|
if (i == 13) nomemese << " saldo";
|
|
|
|
tt->add(""); // questo e' il bottone
|
|
tt->add(nomemese); // mese
|
|
tt->add(date[i-1].string()); // data vers.
|
|
tt->add(abi); // azienda
|
|
tt->add(cab); // dipendenza
|
|
tt->add(cnc); // concessionaria
|
|
tt->add(versamenti[i-1].string());// versamenti
|
|
tt->add(versamenti[i-1].sign() < 0 ? "C" : "D"); // debito/credito (che senso ha?)
|
|
|
|
sv.row(i-1) = (*tt);
|
|
}
|
|
|
|
sh.disable();
|
|
sv.disable();
|
|
|
|
m.run();
|
|
_mask = NULL;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool Visliq_app::vis_one(int m)
|
|
{
|
|
begin_wait();
|
|
TMask msk("cg5500d");
|
|
bool recorded = FALSE;
|
|
|
|
// ricalcolo liquidazione TMessage msg;
|
|
TFilename f;
|
|
f.temp("prliq");
|
|
|
|
TToken_string body(36);
|
|
body.add(_year);
|
|
body.add(m);
|
|
body.add(get_firm());
|
|
body.add("V"); // visualizzazione: no ff alla fine, zeri stampati
|
|
body.add("");
|
|
body.add(f);
|
|
|
|
TMessage msg("cg4 -2", "RCL", body);
|
|
msg.send();
|
|
|
|
TBrowsefile_field& brw = (TBrowsefile_field&)msk.field(F_VISFLQ);
|
|
brw.set_link_handler(link_handler);
|
|
brw.enable_link("Modifica: ", 'r');
|
|
|
|
look_lim(m);
|
|
real rimborso = _lim->get_real("R1");
|
|
real rettifica = _lim->get_real("R5");
|
|
TString desc1(_lim->get("S0"));
|
|
TString desc2(_lim->get("S1"));
|
|
real acconto;
|
|
|
|
if (m == 12)
|
|
{
|
|
look_lia();
|
|
acconto = _lia->get_real("R4");
|
|
}
|
|
|
|
msk.field(F_RIMBORSO).set(rimborso.string());
|
|
if (rettifica.sign() < 0)
|
|
{
|
|
msk.field(F_RETTIFICA).set(abs(rettifica).string());
|
|
msk.field(F_DEBCRE).set("C");
|
|
}
|
|
else
|
|
{
|
|
msk.field(F_RETTIFICA).set(rettifica.string());
|
|
msk.field(F_DEBCRE).set("D");
|
|
}
|
|
|
|
msk.field(F_DESCR1).set(desc1);
|
|
msk.field(F_DESCR2).set(desc1);
|
|
msk.field(F_ACCONTO).set(acconto.string());
|
|
|
|
long line;
|
|
TExternal_app liq("cg4 -2");
|
|
{
|
|
end_wait();
|
|
TProgind(10l,"Estrazione liquidazione: prego attendere", FALSE,FALSE);
|
|
liq.run();
|
|
|
|
if (liq.error())
|
|
{
|
|
beep();
|
|
return FALSE;
|
|
}
|
|
begin_wait();
|
|
line = brw.set_text(f, "CALCOLO LIQUIDAZIONE D'IMPOSTA");
|
|
brw.goto_pos(brw.lines()-16l, 9);
|
|
|
|
real risultato = _lim->get_real("R0");
|
|
risultato += (rimborso + rettifica - acconto);
|
|
|
|
TViswin* vsw = brw.vis_win();
|
|
long ll, ll2, lvers = -1; int x;
|
|
|
|
int isdebt = risultato.sign();
|
|
long lrisd = vsw->search("RISULTATO", x, line, TRUE); // RISULTATO a debito
|
|
long lrisc = vsw->search("RISULTATO", x, lrisd+1l, TRUE); // credito
|
|
if (risultato.sign())
|
|
lvers = vsw->search(isdebt < 0 ? "CREDITO ATTUALE" : "IVA DA VERSARE",
|
|
x, line, TRUE);
|
|
|
|
real risc(real::ita2eng(brw.get_text(lrisc,58,15)));
|
|
real risd(real::ita2eng(brw.get_text(lrisd,75,15)));
|
|
|
|
if (lrisd == -1l || lrisc == -1l) return FALSE;
|
|
if (lvers == -1l) lvers = lrisc+1l;
|
|
|
|
bool write_lia = FALSE, write_lim = FALSE;
|
|
end_wait();
|
|
|
|
for(;;)
|
|
{
|
|
KEY k = msk.run();
|
|
|
|
if (k == K_INS || k == K_SAVE) // TBI registra: dovra' essere RICALCOLA
|
|
{
|
|
real n_acconto (msk.get(F_ACCONTO));
|
|
real n_rimborso (msk.get(F_RIMBORSO));
|
|
real n_rettifica(msk.get(F_RETTIFICA));
|
|
TString n_desc1 (msk.get(F_DESCR1));
|
|
TString n_desc2 (msk.get(F_DESCR2));
|
|
|
|
if (msk.field(F_RETTIFICA).dirty() || msk.field(F_DEBCRE).dirty())
|
|
{
|
|
ll = vsw->search("Rettifiche IVA a credito",x,line,TRUE);
|
|
ll2 = vsw->search("Rettifiche IVA a debito", x,line,TRUE);
|
|
|
|
if (ll != -1 && ll2 != -1)
|
|
{
|
|
if (msk.get(F_DEBCRE) == "D")
|
|
{
|
|
vsw->replace(ll2, n_rettifica.string("###.###.###.###"), 75);
|
|
vsw->replace(ll, " ", 58);
|
|
}
|
|
else
|
|
{
|
|
vsw->replace(ll, n_rettifica.string("###.###.###.### "), 58);
|
|
vsw->replace(ll2, " ", 75);
|
|
}
|
|
|
|
risultato -= rettifica; // vecchia rettifica
|
|
|
|
// scorporo vecchia
|
|
if (rettifica.sign() > 0)
|
|
risd -= rettifica;
|
|
else
|
|
risc += rettifica;
|
|
|
|
// incorporo nuova
|
|
if (msk.get(F_DEBCRE) == "C")
|
|
{
|
|
risc += n_rettifica;
|
|
n_rettifica = -n_rettifica;
|
|
}
|
|
else
|
|
{
|
|
risd += n_rettifica;
|
|
}
|
|
|
|
risultato += n_rettifica;
|
|
|
|
vsw->replace(lrisc, risc.string("###.###.###.###"), 58);
|
|
vsw->replace(lrisd, risd.string("###.###.###.###"), 75);
|
|
|
|
_lim->put("R5", n_rettifica);
|
|
_lim->put("S7", msk.get(F_DEBCRE));
|
|
|
|
set_risultato(vsw, lvers, risultato);
|
|
|
|
// altro giro, altro regalo
|
|
rettifica = n_rettifica;
|
|
}
|
|
write_lim = TRUE;
|
|
}
|
|
if (msk.field(F_ACCONTO).dirty())
|
|
{
|
|
ll = vsw->search("Versamento acconto dicembre",x,line,TRUE);
|
|
if (ll != -1)
|
|
vsw->replace(ll, n_acconto.string("###.###.###.###"), 58);
|
|
write_lia = TRUE;
|
|
risultato += acconto;
|
|
risultato -= n_acconto;
|
|
risc -= acconto;
|
|
risc += n_acconto;
|
|
_lia->put("R4", n_acconto);
|
|
vsw->replace(lrisc, risc.string("###.###.###.###"), 58);
|
|
set_risultato(vsw, lvers, risultato);
|
|
}
|
|
if (msk.field(F_RIMBORSO).dirty())
|
|
{
|
|
ll = vsw->search("Iva chiesta a rimborso",x,line,TRUE);
|
|
if (ll != -1)
|
|
vsw->replace(ll, n_rimborso.string("###.###.###.###"), 75);
|
|
write_lim = TRUE;
|
|
risultato -= rimborso;
|
|
risultato += n_rimborso;
|
|
risd -= rimborso;
|
|
risd += n_rimborso;
|
|
_lim->put("R1", n_rimborso);
|
|
vsw->replace(lrisd, risd.string("###.###.###.###"), 75);
|
|
set_risultato(vsw, lvers, risultato);
|
|
}
|
|
|
|
if (msk.field(F_DESCR1).dirty())
|
|
{
|
|
_lim->put("S0", n_desc1);
|
|
write_lim = TRUE;
|
|
}
|
|
if (msk.field(F_DESCR1).dirty())
|
|
{
|
|
_lim->put("S1", n_desc2);
|
|
write_lim = TRUE;
|
|
}
|
|
|
|
// TBI abilitare ricalcolo liquidazione
|
|
|
|
if (write_lia && k == K_SAVE)
|
|
_lia->rewrite();
|
|
|
|
if ((write_lim || write_lia) && k == K_SAVE)
|
|
{
|
|
_lim->put("B0", "");
|
|
_lim->rewrite();
|
|
}
|
|
|
|
if (k == K_SAVE) recorded = TRUE;
|
|
|
|
if (write_lim || write_lia)
|
|
vsw->refresh();
|
|
}
|
|
else if (k == K_QUIT)
|
|
{
|
|
if ((write_lim || write_lia) && !recorded)
|
|
{
|
|
KEY kk = yesnocancel_box("Modifiche non registrate: salvare?");
|
|
if (kk == K_NO)
|
|
break;
|
|
else if (kk == K_YES)
|
|
{
|
|
if (write_lia)
|
|
{
|
|
_lia->rewrite();
|
|
_lim->put("B0", "");
|
|
_lim->rewrite();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else break;
|
|
}
|
|
else if (k == K_ESC) break;
|
|
}
|
|
}
|
|
|
|
remove(f);
|
|
|
|
return recorded;
|
|
}
|
|
|
|
void Visliq_app::set_risultato(TViswin* vsw, long line, real& r)
|
|
{
|
|
TString256 ln;
|
|
ln.spaces();
|
|
|
|
// does not gestisc interessi e riporti debito < 50000
|
|
|
|
if (r.sign() < 0)
|
|
{
|
|
ln.overwrite("CREDITO ATTUALE", 23);
|
|
ln.overwrite(abs(r).string("###.###.###.###"), 58);
|
|
}
|
|
else if (r.sign() > 0)
|
|
{
|
|
ln.overwrite("IVA DA VERSARE", 23);
|
|
ln.overwrite(r.string("###.###.###.###"), 75);
|
|
}
|
|
vsw->replace(line, ln, 0);
|
|
}
|
|
|
|
int cg5500(int argc, char* argv[])
|
|
{
|
|
Visliq_app app;
|
|
app.run(argc, argv, "Visualizzazione Liquidazione");
|
|
return 0;
|
|
}
|