git-svn-id: svn://10.65.10.50/branches/R_10_00@23036 c028cbd2-c16b-5b4b-a496-9718f37d4682
508 lines
13 KiB
C++
Executable File
508 lines
13 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 <recset.h>
|
|
#include <sheet.h>
|
|
#include <tabutil.h>
|
|
|
|
#include <nditte.h>
|
|
#include <rmoviva.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_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, 70, 15, TR("Selezione Ditte"),
|
|
HR("Codice@6R|Ragione Sociale@50"));
|
|
TDate oggi(TODAY);
|
|
_year = oggi.year();
|
|
|
|
build_ditte_sheet();
|
|
}
|
|
|
|
TDich_periodica_selfirm_mask::~TDich_periodica_selfirm_mask()
|
|
{
|
|
delete _ditte;
|
|
}
|
|
|
|
void TDich_periodica_selfirm_mask::build_ditte_sheet()
|
|
{
|
|
TTable pum("PUM");
|
|
|
|
_ditte->destroy();
|
|
TPointer_array firms;
|
|
TPrefix::firms(firms);
|
|
|
|
long good_company = -1;
|
|
|
|
FOR_EACH_ARRAY_ITEM(firms, i, obj)
|
|
{
|
|
TToken_string* d = new TToken_string(63);
|
|
const long codditta = firms.get_long(i);
|
|
d->add(codditta);
|
|
d->add(cache().get(LF_NDITTE, codditta, NDT_RAGSOC));
|
|
const long pos = _ditte->add(d);
|
|
|
|
pum.put("CODTAB", _year);
|
|
if (pum.read(_isgteq) == NOERR && atoi(pum.get("CODTAB").left(4)) == _year)
|
|
{
|
|
if (good_company <= 0)
|
|
good_company = pos;
|
|
}
|
|
else
|
|
_ditte->disable_row(pos);
|
|
}
|
|
|
|
if (good_company >= 0)
|
|
{
|
|
TToken_string& row = _ditte->row(good_company);
|
|
set(F_CODDITTA, row.get(0));
|
|
set(F_RAGSOC, row.get(1));
|
|
}
|
|
else
|
|
{
|
|
reset(F_CODDITTA);
|
|
reset(F_RAGSOC);
|
|
}
|
|
}
|
|
|
|
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;
|
|
const long ditta = atol(o.get());
|
|
for (long i = 0; i < _ditte->items(); i++)
|
|
{
|
|
TToken_string& row = _ditte->row(i);
|
|
if (ditta == row.get_long(0))
|
|
{
|
|
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_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_ditte_sheet();
|
|
}
|
|
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 = TR("VP11 - IVA detratta per il periodo");
|
|
break;
|
|
case 9:
|
|
p = TR("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")
|
|
{
|
|
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...
|
|
|
|
protected:
|
|
void read_iva_data();
|
|
real imposta_diff(int tipo) const;
|
|
|
|
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);
|
|
};
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
// tipo=1 vendite; 2 = acquisti
|
|
real TDich_periodica_iva_mask::imposta_diff(int tipo) const
|
|
{
|
|
real imposta;
|
|
|
|
const int anno = _sf->get_year();
|
|
const TDate data_da(1,1,anno);
|
|
const TDate data_a(31,12,anno);
|
|
|
|
TString query;
|
|
query << "USE IVADIFF SELECT (BETWEEN(DATAREGP,#DAL,#AL))&&(STR("
|
|
<< "(MOV.TOTDOC>0)&&(TIPOMOV>2)&&(MESELIQ<13)&&(TIPOIVA=" << tipo << ')'
|
|
<< "))";
|
|
query << "\nJOIN MOV INTO NUMREG==NUMREG";
|
|
TISAM_recordset id(query);
|
|
id.set_var("#DAL", data_da);
|
|
id.set_var("#AL", data_a);
|
|
|
|
for (bool ok = id.move_first(); ok; ok = id.move_next())
|
|
imposta += id.get(RMI_IMPOSTA).as_real();
|
|
return imposta;
|
|
}
|
|
|
|
void TDich_periodica_iva_mask::read_iva_data()
|
|
{
|
|
TString8 key; key.format("%4d13", _sf->get_year());
|
|
const TRectype& lim = cache().get("LIM", key);
|
|
|
|
if (lim.get_bool("B0"))
|
|
{
|
|
const TRectype & lam = cache().get("LAM", key);
|
|
|
|
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 cd1_5 = ZERO;
|
|
real cd2_1 = ZERO;
|
|
real cd2_2 = ZERO;
|
|
real cd2_3 = ZERO;
|
|
real cd2_4 = ZERO;
|
|
real cd2_5 = ZERO;
|
|
real cd3_1 = ZERO;
|
|
real cd3_2 = ZERO;
|
|
real cd3_3 = ZERO;
|
|
real cd3_4 = ZERO;
|
|
|
|
TRelation relpum("PUM");
|
|
TRectype& pum = relpum.curr();
|
|
key.format("%04d",_sf->get_year());
|
|
pum.put("CODTAB", key);
|
|
TCursor cur(&relpum, "", 1, &pum, &pum);
|
|
|
|
const TRecnotype items = cur.items();
|
|
cur.freeze();
|
|
for (cur = 0L; cur.pos() < items; ++cur)
|
|
{
|
|
const TString& codtab = pum.get("CODTAB");
|
|
const TString& annoiva = codtab.left(4);
|
|
if (annoiva != key)
|
|
break;
|
|
if (atoi(codtab.right(2)) == 13) // Solo annuale
|
|
{
|
|
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");
|
|
cd3_3 += pum.get_real("R24");
|
|
cd3_4 += pum.get_real("R25");
|
|
cd2_5 += pum.get_real("R26");
|
|
cd1_5 += pum.get_real("R27");
|
|
}
|
|
|
|
}
|
|
// Arrotondare tutto all'Euro
|
|
cd1_1.round(); cd1_2.round(); cd1_3.round(); cd1_4.round(); cd1_5.round();
|
|
cd2_1.round(); cd2_2.round(); cd2_3.round(); cd2_4.round(); cd2_5.round();
|
|
cd3_1.round(); cd3_2.round(); cd3_3.round(); cd3_3.round();
|
|
|
|
const real rettifica = lim.get_real("R5"); // Rettifiche
|
|
|
|
real cd4 = lam.get_real("R0"); // Iva esigibile per il periodo
|
|
cd4 += imposta_diff(1);
|
|
if (rettifica > ZERO)
|
|
cd4 += rettifica;
|
|
cd4.round();
|
|
|
|
real cd5 = lam.get_real("R1"); // Iva che si detrae per il periodo
|
|
cd5 += imposta_diff(2);
|
|
if (rettifica < ZERO && !exclude_sign)
|
|
cd5 += abs(rettifica);
|
|
cd5.round();
|
|
|
|
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_CD1_5, cd1_5);
|
|
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_CD2_5, cd2_5);
|
|
set(F_CD3_1, cd3_1); set(F_CD3_2, cd3_2); set(F_CD3_3, cd3_3); set(F_CD3_4, cd3_4);
|
|
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 l'anno %d.", _sf->get_year());
|
|
|
|
}
|
|
|
|
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_CD1_5).set(get(F_CD1_5));
|
|
|
|
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_CD2_5).set(get(F_CD2_5));
|
|
|
|
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_CD3_3).set(get(F_CD3_3));
|
|
frm.find_field('B', odd_page, FF_CD3_4).set(get(F_CD3_3));
|
|
|
|
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));
|
|
|
|
frm.cursor()->setregion(f,f);
|
|
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(TR("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, TR("Comunicazione annuale dati IVA"));
|
|
return 0;
|
|
} |