724a33cfb4
Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione aga 1.7 patch 413 git-svn-id: svn://10.65.10.50/trunk@10856 c028cbd2-c16b-5b4b-a496-9718f37d4682
477 lines
12 KiB
C++
Executable File
477 lines
12 KiB
C++
Executable File
// Programma per la gestione e la stampa della dichiarazione periodica IVA
|
|
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <currency.h>
|
|
#include <form.h>
|
|
#include <prefix.h>
|
|
#include <recarray.h>
|
|
#include <sheet.h>
|
|
#include <tabutil.h>
|
|
|
|
#include <nditte.h>
|
|
|
|
#include "cg5700.h"
|
|
#include "cglib03.h"
|
|
|
|
class TDich_periodica_selfirm_mask : public TAutomask
|
|
{
|
|
TArray_sheet * _ditte;
|
|
TString_array _nomiditte;
|
|
int _year;
|
|
|
|
protected:
|
|
bool select_button();
|
|
void build_nomiditte();
|
|
void build_ditte_sheet();
|
|
|
|
public:
|
|
const int get_year() const { return _year; }
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
TDich_periodica_selfirm_mask();
|
|
virtual ~TDich_periodica_selfirm_mask();
|
|
};
|
|
|
|
TDich_periodica_selfirm_mask::TDich_periodica_selfirm_mask() : TAutomask("cg5700a")
|
|
{
|
|
_ditte = new TArray_sheet(-1, -1, -4, -4, "Selezione Ditte",
|
|
"Cod.@5|Ragione Sociale@50");
|
|
TDate oggi(TODAY);
|
|
|
|
_year = oggi.year();
|
|
|
|
build_nomiditte();
|
|
build_ditte_sheet();
|
|
}
|
|
|
|
TDich_periodica_selfirm_mask::~TDich_periodica_selfirm_mask()
|
|
{
|
|
delete _ditte;
|
|
}
|
|
|
|
void TDich_periodica_selfirm_mask::build_nomiditte()
|
|
{
|
|
TString cod;
|
|
TLocalisamfile dt(LF_NDITTE);
|
|
|
|
_nomiditte.destroy();
|
|
|
|
for (dt.first(); !dt.eof(); dt.next())
|
|
{
|
|
const long codditta = dt.get_long("CODDITTA");
|
|
bool good = prefix().exist(codditta);
|
|
if (good)
|
|
{
|
|
TToken_string* d = new TToken_string(64);
|
|
d->add(codditta);
|
|
d->add(dt.get("RAGSOC"));
|
|
_nomiditte.add(d);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDich_periodica_selfirm_mask::build_ditte_sheet()
|
|
{
|
|
_ditte->destroy();
|
|
long prima = -1;
|
|
|
|
for (int i = 0; i < _nomiditte.items(); i++)
|
|
{
|
|
TToken_string* d = new TToken_string(_nomiditte.row(i));
|
|
const long pos = _ditte->add(d);
|
|
const char vers = d->get_char(2);
|
|
const bool selectable = vers != '?';
|
|
_ditte->enable_row(pos, selectable);
|
|
if (selectable && prima < 0)
|
|
_ditte->select(prima = pos);
|
|
}
|
|
}
|
|
|
|
bool TDich_periodica_selfirm_mask::select_button()
|
|
{
|
|
if (_ditte->run() == K_ENTER)
|
|
{
|
|
TToken_string& row = _ditte->row(_ditte->selected());
|
|
set(F_CODDITTA, row.get(0));
|
|
set(F_RAGSOC, row.get(1));
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
bool TDich_periodica_selfirm_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_CODDITTA:
|
|
if (e == fe_button)
|
|
return select_button();
|
|
|
|
if (e == fe_modify)
|
|
{
|
|
bool found = FALSE;
|
|
TString16 ditta = o.get();
|
|
for (int i = 0; i < _ditte->items(); i++)
|
|
{
|
|
TToken_string& row = _ditte->row(i);
|
|
if (ditta == row.get(0))
|
|
{
|
|
if (_ditte->row_enabled(i))
|
|
{
|
|
set(F_CODDITTA, row.get(0));
|
|
set(F_RAGSOC, row.get(1));
|
|
found = TRUE;
|
|
}
|
|
else
|
|
{
|
|
warning_box("Non sono definiti i parametri liquidazione per la ditta %ld",
|
|
atol(ditta));
|
|
o.reset();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (!found)
|
|
o.reset();
|
|
return found;
|
|
}
|
|
break;
|
|
case F_RAGSOC:
|
|
if (e == fe_button)
|
|
return select_button();
|
|
if (e == fe_modify)
|
|
{
|
|
bool found = FALSE;
|
|
TString16 ditta = o.get();
|
|
for (int i = 0; i < _ditte->items(); i++)
|
|
{
|
|
TToken_string& row = _ditte->row(i);
|
|
TString ts(row.get(1));
|
|
if (ts.find(ditta) != -1)
|
|
{
|
|
if (_ditte->row_enabled(i))
|
|
{
|
|
set(F_CODDITTA, row.get(0));
|
|
set(F_RAGSOC, row.get(1));
|
|
found = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!found) o.reset();
|
|
return found;
|
|
}
|
|
break;
|
|
case F_YEAR:
|
|
if (e == fe_modify)
|
|
{
|
|
_year = atoi(o.get());
|
|
build_nomiditte();
|
|
build_ditte_sheet();
|
|
set(F_CODDITTA, "");
|
|
set(F_RAGSOC, "");
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool change_prompt(TString& p, int year)
|
|
{
|
|
bool changed = FALSE;
|
|
if (p.left(2) == "VP")
|
|
{
|
|
const int vp = atoi(p.mid(2,2));
|
|
if (year >= 2001)
|
|
{
|
|
if (vp >= 5)
|
|
{
|
|
switch (vp)
|
|
{
|
|
case 6:
|
|
p = "VP11 - IVA detratta per il periodo";
|
|
break;
|
|
case 9:
|
|
p = "VP14 - IVA non versata o in eccesso da dich. prec.";
|
|
break;
|
|
default:
|
|
TString4 n;
|
|
n.format("%2d", vp+5);
|
|
p.overwrite(n, 2);
|
|
break;
|
|
}
|
|
changed = TRUE;
|
|
}
|
|
}
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
|
|
class TDich_periodica_iva_form : public TForm
|
|
{
|
|
public:
|
|
TDich_periodica_iva_form(int anno);
|
|
};
|
|
|
|
TDich_periodica_iva_form::TDich_periodica_iva_form(int anno) : TForm("cg5700a")
|
|
{
|
|
if (anno > 2000)
|
|
{
|
|
TPrint_section& b = section('B', odd_page);
|
|
TString p;
|
|
for (int i = b.fields()-1; i > 0; i--)
|
|
{
|
|
TForm_item& f = b.field(i);
|
|
p = f.prompt();
|
|
if (change_prompt(p, anno))
|
|
f.set_prompt(p);
|
|
}
|
|
}
|
|
}
|
|
|
|
class TDich_periodica_iva_mask : public TAutomask
|
|
{
|
|
TDich_periodica_selfirm_mask * _sf;
|
|
bool _dirty_versament, // Sporco versamento...
|
|
_is_euro; // importi in euro
|
|
protected:
|
|
void read_iva_data();
|
|
|
|
public:
|
|
void set_prospect();
|
|
void print_prospect();
|
|
virtual bool on_key(KEY k);
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
TDich_periodica_iva_mask(TDich_periodica_selfirm_mask *m);
|
|
virtual ~TDich_periodica_iva_mask() {};
|
|
};
|
|
|
|
TDich_periodica_iva_mask::TDich_periodica_iva_mask(TDich_periodica_selfirm_mask *m)
|
|
: TAutomask("cg5700b")
|
|
{
|
|
_sf = m;
|
|
|
|
const int anno = _sf->get_int(F_YEAR);
|
|
if (anno > 2000)
|
|
{
|
|
TString p;
|
|
for (int i = fields()-1; i > 0; i--)
|
|
{
|
|
TMask_field& f = fld(i);
|
|
p = f.prompt();
|
|
if (change_prompt(p, anno))
|
|
f.set_prompt(p);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDich_periodica_iva_mask::read_iva_data()
|
|
{
|
|
TTable lim("LIM");
|
|
TTable lam("LAM");
|
|
|
|
TString16 key;
|
|
key.format("%4d13", _sf->get_year());
|
|
lim.put("CODTAB", key);
|
|
lam.put("CODTAB", key);
|
|
|
|
const bool good = lim.read() == NOERR;
|
|
|
|
if (good && lim.get_bool("B0"))
|
|
{
|
|
lam.read();
|
|
|
|
TString descrizione(120);
|
|
descrizione = lim.get("S0");
|
|
descrizione << lim.get("S1");
|
|
const bool exclude_sign = descrizione.find("$$") >= 0 || descrizione.find(">>") >= 0;
|
|
|
|
real cd1_1 = ZERO;
|
|
real cd1_2 = ZERO;
|
|
real cd1_3 = ZERO;
|
|
real cd1_4 = ZERO;
|
|
real cd2_1 = ZERO;
|
|
real cd2_2 = ZERO;
|
|
real cd2_3 = ZERO;
|
|
real cd2_4 = ZERO;
|
|
real cd3_1 = ZERO;
|
|
real cd3_2 = ZERO;
|
|
|
|
TTable pum("PUM");
|
|
key.format("%04d",_sf->get_year());
|
|
pum.put("CODTAB", key);
|
|
for (int err = pum.read(_isgteq); err == NOERR; err= pum.next())
|
|
{
|
|
const TString16 codtab = pum.get("CODTAB");
|
|
|
|
const TString& anno = codtab.left(4);
|
|
if (anno != key)
|
|
break;
|
|
if (codtab.right(2) != "13") // Solo annuale
|
|
continue;
|
|
|
|
cd1_1 += pum.get_real("R14");
|
|
cd1_2 += pum.get_real("R15");
|
|
cd1_3 += pum.get_real("R16");
|
|
cd1_4 += pum.get_real("R17");
|
|
cd2_1 += pum.get_real("R18");
|
|
cd2_2 += pum.get_real("R19");
|
|
cd2_3 += pum.get_real("R20");
|
|
cd2_4 += pum.get_real("R21");
|
|
cd3_1 += pum.get_real("R22");
|
|
cd3_2 += pum.get_real("R23");
|
|
}
|
|
|
|
const real rettifica = lim.get_real("R5"); // Rettifiche
|
|
|
|
real cd4 = lam.get_real("R0"); // Iva esigibile per il periodo
|
|
if (rettifica > ZERO)
|
|
cd4 += rettifica;
|
|
|
|
real cd5 = lam.get_real("R1"); // Iva che si detrae per il periodo
|
|
if (rettifica < ZERO && !exclude_sign)
|
|
cd5 += abs(rettifica);
|
|
|
|
const real cd6 = cd4 - cd5; // IVA a debito o credito per il periodo
|
|
real cd6_1, cd6_2;
|
|
if (cd6 >= ZERO)
|
|
cd6_1 = cd6;
|
|
else
|
|
cd6_2 = -cd6;
|
|
|
|
set(F_CD1_1, cd1_1); set(F_CD1_2, cd1_2); set(F_CD1_3, cd1_3); set(F_CD1_4, cd1_4);
|
|
set(F_CD2_1, cd2_1); set(F_CD2_2, cd2_2); set(F_CD2_3, cd2_3); set(F_CD2_4, cd2_4);
|
|
set(F_CD3_1, cd3_1); set(F_CD3_2, cd3_2);
|
|
set(F_CD4, cd4); set(F_CD5, cd5);
|
|
set(F_CD6_1, cd6_1); set(F_CD6_2, cd6_2);
|
|
}
|
|
else
|
|
error_box("Risultati liquidazione non presenti o da ricalcolare per il periodo richiesto.");
|
|
}
|
|
|
|
void TDich_periodica_iva_mask::print_prospect()
|
|
{
|
|
const int anno = _sf->get_int(F_YEAR);
|
|
TDich_periodica_iva_form frm(anno);
|
|
|
|
frm.find_field('B', odd_page, FF_YEAR).set(get(F_YEAR));
|
|
|
|
frm.find_field('B', odd_page, FF_CD1_1).set(get(F_CD1_1));
|
|
frm.find_field('B', odd_page, FF_CD1_2).set(get(F_CD1_2));
|
|
frm.find_field('B', odd_page, FF_CD1_3).set(get(F_CD1_3));
|
|
frm.find_field('B', odd_page, FF_CD1_4).set(get(F_CD1_4));
|
|
|
|
frm.find_field('B', odd_page, FF_CD2_1).set(get(F_CD2_1));
|
|
frm.find_field('B', odd_page, FF_CD2_2).set(get(F_CD2_2));
|
|
frm.find_field('B', odd_page, FF_CD2_3).set(get(F_CD2_3));
|
|
frm.find_field('B', odd_page, FF_CD2_4).set(get(F_CD2_4));
|
|
|
|
frm.find_field('B', odd_page, FF_CD3_1).set(get(F_CD3_1));
|
|
frm.find_field('B', odd_page, FF_CD3_2).set(get(F_CD3_2));
|
|
|
|
frm.find_field('B', odd_page, FF_CD4).set(get(F_CD4));
|
|
frm.find_field('B', odd_page, FF_CD5).set(get(F_CD5));
|
|
|
|
frm.find_field('B', odd_page, FF_CD6_1).set(get(F_CD6_1));
|
|
frm.find_field('B', odd_page, FF_CD6_2).set(get(F_CD6_2));
|
|
|
|
TRectype f(LF_NDITTE);
|
|
f.put(NDT_CODDITTA, get(F_CODDITTA));
|
|
TRectype t(f);
|
|
|
|
frm.cursor()->setregion(f,t);
|
|
frm.print();
|
|
}
|
|
|
|
void TDich_periodica_iva_mask::set_prospect()
|
|
{
|
|
CHECK(_sf, "Invalid mask");
|
|
|
|
_dirty_versament = FALSE;
|
|
|
|
const int anno = _sf->get_year();
|
|
const long ditta = _sf->get_long(F_CODDITTA);
|
|
|
|
set(F_YEAR, anno);
|
|
set(F_CODDITTA, ditta);
|
|
set(F_RAGSOC, _sf->get(F_RAGSOC));
|
|
|
|
TFirm frm(ditta);
|
|
|
|
TIva_round ir;
|
|
ir.set_default_iva_mode(anno, FALSE, ditta);
|
|
|
|
read_iva_data();
|
|
}
|
|
|
|
bool TDich_periodica_iva_mask::on_key(KEY k)
|
|
{
|
|
return TAutomask::on_key(k);
|
|
}
|
|
|
|
bool TDich_periodica_iva_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
class TDich_periodica_iva_app : public TSkeleton_application
|
|
{
|
|
protected:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
public:
|
|
virtual bool firm_change_enabled() const { return FALSE; }
|
|
TDich_periodica_iva_app () {};
|
|
virtual ~TDich_periodica_iva_app () {};
|
|
};
|
|
|
|
bool TDich_periodica_iva_app::create()
|
|
{
|
|
open_files(LF_TAB, LF_TABCOM, LF_NDITTE, 0);
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TDich_periodica_iva_app::destroy()
|
|
{
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TDich_periodica_iva_app::main_loop()
|
|
{
|
|
const long ditta = get_firm();
|
|
|
|
TDich_periodica_selfirm_mask* m1 = new TDich_periodica_selfirm_mask();
|
|
while (m1->run() != K_QUIT)
|
|
{
|
|
if (m1->get(F_CODDITTA).empty() || m1->get(F_RAGSOC).empty())
|
|
{
|
|
error_box("Selezionare una ditta");
|
|
continue;
|
|
}
|
|
|
|
set_firm(m1->get_long(F_CODDITTA));
|
|
|
|
TDich_periodica_iva_mask* m2 = new TDich_periodica_iva_mask(m1);
|
|
m2->reset();
|
|
m2->enable_default();
|
|
m2->set_prospect();
|
|
if (m2->run() == K_ENTER)
|
|
m2->print_prospect();
|
|
delete m2;
|
|
}
|
|
delete m1;
|
|
|
|
set_firm(ditta);
|
|
}
|
|
|
|
int cg5700(int argc, char* argv[])
|
|
{
|
|
TDich_periodica_iva_app a;
|
|
a.run(argc, argv, "Comunicazione annuale IVA");
|
|
return 0;
|
|
}
|