b0ab13f0fc
git-svn-id: svn://10.65.10.50/trunk@4 c028cbd2-c16b-5b4b-a496-9718f37d4682
728 lines
19 KiB
C++
Executable File
728 lines
19 KiB
C++
Executable File
#include <config.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
|
|
#include "cg2100.h"
|
|
#include "cg2102.h"
|
|
|
|
// Nomi dei campi
|
|
#include <mov.h>
|
|
#include <causali.h>
|
|
#include <rcausali.h>
|
|
|
|
|
|
TPrimanota_application::TPrimanota_application()
|
|
: _rel(NULL), _lastreg(0), _mode(0), _iva(nessuna_iva)
|
|
{
|
|
memset(_msk, 0, sizeof(_msk));
|
|
}
|
|
|
|
|
|
TMask* TPrimanota_application::load_mask(int n)
|
|
{
|
|
if (_msk[n] != NULL)
|
|
return _msk[n];
|
|
|
|
TFilename name("cg2100"); name << char(n == 3 ? 'o' : 'a'+n);
|
|
TMask* m = new TMask(name);
|
|
|
|
switch (n)
|
|
{
|
|
case 0:
|
|
m->set_handler(F_NUMREG, num_handler);
|
|
m->set_handler(F_CODCAUS, caus_query_handler);
|
|
m->set_handler(F_DATAREG, datareg_handler);
|
|
m->set_handler(F_DATACOMP, datacomp_handler);
|
|
{
|
|
TConfig c(CONFIG_STUDIO, "cg");
|
|
const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus
|
|
m->first_focus(dr ? F_DATAREG : F_CODCAUS);
|
|
}
|
|
break;
|
|
case 1:
|
|
m->set_handler(F_VISVAL, visval_handler);
|
|
m->set_handler(F_DESCR, descr_handler);
|
|
break;
|
|
case 2:
|
|
m->set_handler(F_CODREG, reg_handler);
|
|
m->set_handler(F_CLIENTE, clifo_handler);
|
|
m->set_handler(F_FORNITORE, clifo_handler);
|
|
m->set_handler(F_TOTALE, totale_handler);
|
|
m->set_handler(F_RITFIS, ritfis_handler);
|
|
m->set_handler(F_RITSOC, ritsoc_handler);
|
|
m->set_handler(F_VISVAL, visval_handler);
|
|
m->set_handler(F_OCCASEDIT, occas_handler);
|
|
m->set_handler(F_SOLAIVA, solaiva_handler);
|
|
m->set_handler(F_SHEETIVA, iva_handler);
|
|
{
|
|
TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA);
|
|
is.set_notify(iva_notify);
|
|
is.sheet_mask().set_handler(101, imponibile_handler);
|
|
is.sheet_mask().set_handler(102, codiva_handler);
|
|
is.sheet_mask().set_handler(103, imposta_handler);
|
|
is.sheet_mask().set_handler(108, conto_handler);
|
|
is.sheet_mask().set_handler(109, suspended_handler);
|
|
is.sheet_mask().set_handler(209, suspended_handler);
|
|
is.sheet_mask().set_handler(309, suspended_handler);
|
|
}
|
|
break;
|
|
case 3:
|
|
m->set_handler(O_CODICE, occas_code_handler);
|
|
break;
|
|
default:
|
|
CHECKD(0, "Che cavolo di maschera e' la ", n);
|
|
break;
|
|
}
|
|
if (n == 1 || n == 2)
|
|
{
|
|
m->set_handler(F_DATAREG, datareg_handler);
|
|
m->set_handler(F_DATACOMP, datacomp_handler);
|
|
m->set_handler(F_CODCAUS, caus_modify_handler);
|
|
m->set_handler(F_SHEETCG, cg_handler);
|
|
{
|
|
TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG);
|
|
cg.set_notify(cg_notify);
|
|
TMask& cgm = cg.sheet_mask();
|
|
cgm.set_handler(101, dareavere_handler);
|
|
cgm.set_handler(102, dareavere_handler);
|
|
cgm.set_handler(105, suspended_handler);
|
|
cgm.set_handler(106, suspended_handler);
|
|
cgm.set_handler(206, suspended_handler);
|
|
cgm.set_handler(306, suspended_handler);
|
|
cgm.set_handler(112, suspended_handler);
|
|
cgm.set_handler(113, suspended_handler);
|
|
cgm.set_handler(213, suspended_handler);
|
|
cgm.set_handler(313, suspended_handler);
|
|
}
|
|
}
|
|
|
|
return _msk[n] = m;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::user_create()
|
|
{
|
|
_tabcom = new TLocalisamfile(LF_TABCOM);
|
|
_tab = new TLocalisamfile(LF_TAB);
|
|
_caus = new TLocalisamfile(LF_CAUSALI);
|
|
_rcaus = new TLocalisamfile(LF_RCAUSALI);
|
|
_clifo = new TLocalisamfile(LF_CLIFO);
|
|
_pcon = new TLocalisamfile(LF_PCON);
|
|
_attiv = new TLocalisamfile(LF_ATTIV);
|
|
_saldo = new TLocalisamfile(LF_SALDI);
|
|
_comuni = new TLocalisamfile(LF_COMUNI);
|
|
_occas = new TLocalisamfile(LF_OCCAS);
|
|
_nditte = new TLocalisamfile(LF_NDITTE);
|
|
|
|
_rel = new TMovimentoPN;
|
|
_rel->lfile()->last();
|
|
_lastreg = _rel->lfile()->get_long(MOV_NUMREG); // Init last registration number
|
|
|
|
set_search_field(F_NUMREG); // Set field for default search
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::user_destroy()
|
|
{
|
|
if (_msk[3] != NULL) delete _msk[3];
|
|
if (_msk[2] != NULL) delete _msk[2];
|
|
if (_msk[1] != NULL) delete _msk[1];
|
|
if (_msk[0] != NULL) delete _msk[0];
|
|
|
|
delete _rel;
|
|
delete _nditte;
|
|
delete _occas;
|
|
delete _comuni;
|
|
delete _saldo;
|
|
delete _attiv;
|
|
delete _pcon;
|
|
delete _clifo;
|
|
delete _rcaus;
|
|
delete _caus;
|
|
delete _tab;
|
|
delete _tabcom;
|
|
return TRUE;
|
|
}
|
|
|
|
// Legge la causale di codice cod ed il relativo registro dell'anno year
|
|
// Certified 99%
|
|
bool TPrimanota_application::read_caus(const char* cod, int year)
|
|
{
|
|
const bool ok = causale().read(cod, year);
|
|
if (ok)
|
|
{
|
|
TMask& m = *load_mask(_iva == nessuna_iva ? 1 : 2);
|
|
|
|
TEdit_field& nd = (TEdit_field&)m.field(F_NUMDOC); // Numero documento obbligatorio?
|
|
nd.check_type(_causale.num_doc() ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
|
|
TEdit_field& dd = (TEdit_field&)m.field(F_DATADOC); // Data documento obbligatoria?
|
|
dd.check_type(_causale.data_doc() ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::changing_mask(int mode)
|
|
{
|
|
if (mode == MODE_QUERY)
|
|
return _mode != MODE_QUERY;
|
|
|
|
TipoIVA oliva = _iva;
|
|
|
|
_iva = nessuna_iva;
|
|
|
|
TString16 causale;
|
|
// TString16 registro;
|
|
int annoes = 0, annoiva = 0;
|
|
|
|
switch (mode)
|
|
{
|
|
case MODE_INS:
|
|
annoes = _msk[0]->get_int(F_ANNOES);
|
|
annoiva = _msk[0]->get_int(F_ANNOIVA);
|
|
causale = _msk[0]->get(F_CODCAUS);
|
|
read_caus(causale, annoiva);
|
|
break;
|
|
case MODE_MOD:
|
|
annoes = _rel->lfile()->get_int("ANNOES");
|
|
annoiva = _rel->lfile()->get_int("ANNOIVA");
|
|
causale = _rel->lfile()->get("CODCAUS");
|
|
giornale().read(annoes);
|
|
// registro = _rel->lfile()->get("REG");
|
|
// _causale.read(causale, 0);
|
|
// _causale.reg().read(registro, annoiva);
|
|
read_caus(causale, annoiva);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
_iva = _causale.iva();
|
|
|
|
return _mode == MODE_QUERY || _iva != oliva;
|
|
}
|
|
|
|
|
|
TMask* TPrimanota_application::get_mask(int mode)
|
|
{
|
|
_mode = mode;
|
|
const int m = (mode == MODE_QUERY) ? 0 : (iva() == nessuna_iva ? 1 : 2);
|
|
return load_mask(m);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_mask(TMask& m)
|
|
{
|
|
fill_sheet(m);
|
|
|
|
// Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_VISVAL (GROUP 3)
|
|
m.send_key(K_SHIFT+K_CTRL+(_causale.valuta() ? 's' : 'h'), -3);
|
|
m.set(F_VISVAL, _causale.valuta() ? "X" : " ");
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
/*
|
|
TString16 fil; fil = "I0="; fil << (_iva == iva_acquisti ? '2' : '1');
|
|
TEdit_field& f = (TEdit_field&)m.field(F_CODREG);
|
|
f.browse()->cursor()->filter(fil);
|
|
*/
|
|
const int g = (_iva == iva_acquisti) ? 2 : 1;
|
|
m.send_key(K_SHIFT+K_CTRL+'s', -g); // if iva_vendite show group 1
|
|
m.send_key(K_SHIFT+K_CTRL+'h', g-3); // hide group 2
|
|
|
|
const bool intra = _causale.intra();
|
|
m.show(F_CORRLIRE, intra);
|
|
|
|
const bool corrval = intra && _causale.corrval();
|
|
m.show(F_CORRVALUTA, corrval);
|
|
}
|
|
|
|
m.disable(DLG_NEWREC);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_query_mode(TMask& m)
|
|
{
|
|
m.enable(DLG_NEWREC);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::fill_sheet(TMask& m) const
|
|
{
|
|
TSheet_field& cgs = (TSheet_field&)m.field(F_SHEETCG);
|
|
for (int r = cgs.items(); r < 16; r++)
|
|
cgs.row(r);
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA);
|
|
for (r = ivas.items(); r < 16; r++) ivas.row(r);
|
|
ivas.enable_column(4, _iva == iva_acquisti);
|
|
}
|
|
}
|
|
|
|
|
|
// Ritorna il prossimo numero di registrazione libero
|
|
// Certified 100%
|
|
const char* TPrimanota_application::get_next_key()
|
|
{
|
|
return format("%d|%ld", F_NUMREG, _lastreg+1);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_insert_mode(TMask& m)
|
|
{
|
|
m.set(F_DATAREG, _msk[0]->get(F_DATAREG));
|
|
m.set(F_DATACOMP, _msk[0]->get(F_DATACOMP));
|
|
m.set(F_ANNOES, _msk[0]->get(F_ANNOES));
|
|
m.set(F_ANNOIVA, _msk[0]->get(F_ANNOIVA));
|
|
occas_mask().reset();
|
|
|
|
init_mask(m);
|
|
_saldi.reset(); // Inizializza saldi
|
|
_saldi.set_movprovv(_rel->lfile()->get_char("PROVVIS") > ' ' ? TRUE : FALSE);
|
|
_saldi.set_movap(_causale.apertura());
|
|
_saldi.set_anno_es(m.get_int(F_ANNOES));
|
|
_saldi.set_num_ulmov(m.get_long(F_NUMREG));
|
|
_saldi.set_data_ulmov(TDate(m.get(F_DATAREG)));
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
const long protiva = causale().reg().protocol();
|
|
m.set(F_PROTIVA, protiva+1);
|
|
|
|
TMask_field& vv = m.field(F_VISVAL);
|
|
if (vv.active() && vv.get() == "X") // Se e' un movimento in valuta
|
|
{
|
|
const bool ok = m.field(F_VALUTA).on_key(K_F9); // Richiedi valuta
|
|
vv.set(ok ? "X" : " ");
|
|
if (ok) vv.on_hit(); // Cambia decimali
|
|
}
|
|
}
|
|
|
|
if (m.get(F_CODCAUS).empty()) return;
|
|
|
|
TString80 desc;
|
|
for (int i = 1; i < _causale.size(); i++)
|
|
{
|
|
TRectype* rcaus = (TRectype*)_causale.objptr(i);
|
|
if (rcaus == NULL) continue; // Evita eventuali righe nulle
|
|
|
|
const int nriga = rcaus->get_int(RCA_NRIGA);
|
|
if (nriga < 1) continue; // Considera solo righe reali (non riempimenti)
|
|
|
|
TConto tc; _causale.bill(nriga, tc);
|
|
if (tc.conto() < 1) continue; // Considera solo conti validi
|
|
|
|
desc = rcaus->get(RCA_DESC);
|
|
|
|
if (iva() == nessuna_iva)
|
|
{
|
|
set_cgs_row(-1,ZERO,tc,desc,' ');
|
|
}
|
|
else
|
|
{
|
|
if (nriga == 3 || nriga == 4 || nriga == 8 || nriga == 9)
|
|
continue; // Conti per IVA detraibile e non, ritenute sociali e fiscali
|
|
|
|
const bool rigaiva = rcaus->get_bool(RCA_RIGAIVA);
|
|
if (nriga == 2 || (nriga >= 5 && nriga <= 7) || rigaiva)
|
|
{
|
|
const TString16 codiva(rcaus->get(RCA_CODIVA));
|
|
set_ivas_row(-1,codiva,tc,desc);
|
|
}
|
|
else
|
|
{
|
|
const char tipo = nriga < 2 ? 'T' : ' ';
|
|
set_cgs_row(-1,ZERO,tc,desc,tipo);
|
|
|
|
if (nriga == 1 && tc.tipo() > ' ' && tc.sottoconto() > 0)
|
|
m.set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_modify_mode(TMask& m)
|
|
{
|
|
init_mask(m);
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::get_conto(int r, TConto& c) const
|
|
{
|
|
const TRectype& cg = _rel->cg(r);
|
|
c.set(cg.get_int("GRUPPO"), cg.get_int("CONTO"),
|
|
cg.get_long("SOTTOCONTO"), cg.get_char("TIPOC"));
|
|
return c.ok();
|
|
}
|
|
|
|
|
|
int TPrimanota_application::read(TMask& m)
|
|
{
|
|
m.autoload(_rel);
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
const TString16 occode(_rel->lfile()->get("OCFPI"));
|
|
occas_mask().set(O_CODICE, occode);
|
|
|
|
const char clifo = toupper(m.get(F_CLIFO)[0]);
|
|
|
|
if (_iva == iva_acquisti && clifo == 'C')
|
|
error_box("Registrazione di acquisto attribuita ad un cliente"); else
|
|
if (_iva == iva_vendite && clifo == 'F')
|
|
error_box("Registrazione di vendita attribuita ad un fornitore");
|
|
|
|
if (_iva == iva_vendite)
|
|
{
|
|
TEdit_field& f = (TEdit_field&)m.field(F_CLIENTE);
|
|
f.check_type(clifo == 'C' ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
}
|
|
}
|
|
|
|
TSheet_field& cgs = (TSheet_field&)m.field(F_SHEETCG);
|
|
cgs.reset();
|
|
|
|
_saldi.reset(); // Azzera saldi
|
|
_saldi.set_movprovv(_rel->lfile()->get_char("PROVVIS") > ' ' ? TRUE : FALSE);
|
|
_saldi.set_movap(_causale.apertura());
|
|
_saldi.set_anno_es(m.get_int(F_ANNOES));
|
|
_saldi.set_num_ulmov(m.get_long(F_NUMREG));
|
|
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
|
|
|
|
TToken_string riga(180);
|
|
|
|
for (int i = 0; i < _rel->cg_items(); i++)
|
|
{
|
|
TRectype& r = _rel->cg(i);
|
|
riga.cut(0); // Vuota la riga
|
|
|
|
const real im(r.get_real("IMPORTO"));
|
|
const char sezione = toupper(r.get_char("SEZIONE"));
|
|
const int rcontr = r.get_int("RCONTR") -1;
|
|
#ifdef DBG
|
|
if (rcontr < -1 || rcontr >= _rel->cg_items() || rcontr == i)
|
|
error_box("La riga %d non puo' avere per contropartita la %d", i+1, rcontr+1);
|
|
#endif
|
|
const bool dare = sezione == 'D';
|
|
riga.add(dare ? im.string() : " "); // Dare 101
|
|
riga.add(dare ? " " : im.string()); // Avere 102
|
|
|
|
TConto conto; get_conto(i, conto);
|
|
riga.add(conto.string(0x3)); // Conto 103-107
|
|
if (conto.ok())
|
|
_saldi.aggiorna(conto, im, sezione, FALSE);
|
|
|
|
riga.add(""); // Codice descrizione 108
|
|
riga.add(r.get("DESCR")); // Descrizione riga 109
|
|
|
|
if (rcontr >= 0 && rcontr < _rel->cg_items())
|
|
{
|
|
get_conto(rcontr, conto);
|
|
riga.add(conto.string(0x3)); // Contropartita 110-114
|
|
}
|
|
else riga.add(" | | | | ");
|
|
|
|
const char* tipo = r.get("ROWTYPE"); // Tipo di riga 115
|
|
riga.add(tipo);
|
|
|
|
cgs.row(i) = riga;
|
|
disable_cgs_cells(i, *tipo);
|
|
}
|
|
|
|
if (_iva == nessuna_iva)
|
|
return _rel->status();
|
|
|
|
const bool solaiva = i == 0;
|
|
m.set(F_SOLAIVA, solaiva ? "X" : " ");
|
|
m.field(F_SOLAIVA).on_hit();
|
|
|
|
TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA);
|
|
ivas.reset();
|
|
|
|
for (i = 0; i < _rel->iva_items(); i++)
|
|
{
|
|
TRectype& r = _rel->iva(i);
|
|
riga.cut(0);
|
|
|
|
riga.add(r.get("IMPONIBILE")); // Imponibile 101
|
|
riga.add(r.get("CODIVA")); // IVA 102
|
|
riga.add(r.get("IMPOSTA")); // Imposta 103
|
|
riga.add(r.get("TIPOCR")); // C/R 104
|
|
riga.add(r.get("TIPODET")); // Detrazione 105
|
|
|
|
int rigaimp = solaiva ? 0 : r.get_int("RIGAIMP");
|
|
if (rigaimp > 0)
|
|
{
|
|
const int r = rigaimp-1;
|
|
if (r < cgs.items())
|
|
{
|
|
TToken_string& s = cgs.row(r);
|
|
riga.add(s.get(2)); // Tipo conto 106
|
|
for (int i = 0; i < 4; i++)
|
|
riga.add(s.get()); // Gruppo|Conto|Sottoconto|Descrizione
|
|
}
|
|
else
|
|
{
|
|
error_box("Riga imponibile %d errata nella riga iva %d", rigaimp, i+1);
|
|
rigaimp = 0;
|
|
}
|
|
}
|
|
if (rigaimp < 1) riga.add(" | | | | ");
|
|
ivas.row(i) = riga;
|
|
}
|
|
|
|
TMask_field& vv = m.field(F_VISVAL);
|
|
if (vv.active()) vv.on_hit();
|
|
|
|
return _rel->status();
|
|
}
|
|
|
|
|
|
|
|
void TPrimanota_application::mask2rel(const TMask& m)
|
|
{
|
|
_rel->lfile()->zero();
|
|
m.autosave(_rel);
|
|
|
|
const long numreg = m.get_long(F_NUMREG);
|
|
const TDate datareg(m.get(F_DATAREG));
|
|
const int annoes = (int) m.get_long(F_ANNOES);
|
|
|
|
_saldi.set_movprovv(m.get_bool(F_PROVVISORIO));
|
|
_saldi.set_movap(_causale.apertura());
|
|
_saldi.set_anno_es(annoes);
|
|
|
|
_rel->destroy_rows(); // Destroy all records
|
|
cgs_pack(); // Destroy all null rows
|
|
|
|
TArray& rows = cgs().rows_array();
|
|
int cur = 1;
|
|
|
|
// Controlla se e' un movimento con righe contabili
|
|
if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA))
|
|
for (int i = 0; i < rows.items(); i++)
|
|
{
|
|
TToken_string& row = (TToken_string&)rows[i];
|
|
|
|
TRectype &r = _rel->cg(cur-1);
|
|
r.zero();
|
|
r.put("NUMREG", numreg);
|
|
r.put("ANNOES", annoes);
|
|
r.put("DATAREG", datareg);
|
|
r.put("NUMRIG", cur);
|
|
|
|
char sezione = 'D';
|
|
|
|
const char* n = row.get(0);
|
|
real val0(n); // Dare
|
|
n = row.get();
|
|
real val1(n); // Avere
|
|
|
|
if (val0.is_zero())
|
|
{
|
|
sezione = 'A';
|
|
val0 = val1;
|
|
}
|
|
|
|
r.put("IMPORTO", val0); // Importo
|
|
r.put("SEZIONE", sezione); // Sezione
|
|
|
|
const TConto conto(row, -1, 0x3);
|
|
if (conto.ok())
|
|
_saldi.aggiorna(conto, val0, sezione, TRUE);
|
|
|
|
r.put("TIPOC", conto.tipo()); // Conto
|
|
r.put("GRUPPO", conto.gruppo());
|
|
r.put("CONTO", conto.conto());
|
|
r.put("SOTTOCONTO", conto.sottoconto());
|
|
|
|
row.get(); // Codice descrizione
|
|
r.put("DESCR", row.get()); // Descrizione riga
|
|
|
|
int rcontr = 0; // Riga contropartita
|
|
const TConto contro(row, -1, 0x3); // Conto contropartita
|
|
if (contro.ok())
|
|
{
|
|
rcontr = bill2contr(contro, sezione)+1;
|
|
if (rcontr < 1)
|
|
{
|
|
warning_box("La riga contabile %d non ha una contropartita", cur);
|
|
rcontr = 0;
|
|
}
|
|
}
|
|
r.put("RCONTR", rcontr); // Contropartita
|
|
r.put("ROWTYPE", row.get());
|
|
cur++;
|
|
}
|
|
|
|
if (_iva == nessuna_iva) return;
|
|
|
|
int err = ~NOERR;
|
|
if (m.get_bool(F_OCCASIONALE))
|
|
{
|
|
TRelation occas(LF_OCCAS);
|
|
const TMask& om = occas_mask();
|
|
om.autosave(&occas);
|
|
|
|
err = occas.write();
|
|
if (err == _isreinsert)
|
|
err = occas.rewrite();
|
|
|
|
if (err == NOERR)
|
|
_rel->lfile()->put("OCFPI", occas_mask().get(O_CODICE));
|
|
else
|
|
error_box("Errore di scrittura sul file dei clienti/fornitori occasionali: %d", err);
|
|
}
|
|
if (err) _rel->lfile()->zero("OCFPI");
|
|
|
|
TArray& irows = ivas().rows_array();
|
|
cur = 1;
|
|
for (int i = 0; i < irows.items(); i++)
|
|
{
|
|
TToken_string& row = (TToken_string&)irows[i];
|
|
if (row.empty_items())
|
|
continue;
|
|
|
|
TRectype &r = _rel->iva(cur-1);
|
|
r.zero();
|
|
r.put("ANNOES", annoes);
|
|
r.put("NUMREG", numreg);
|
|
r.put("NUMRIG", cur);
|
|
|
|
const char* imponibile = row.get(0);
|
|
r.put("IMPONIBILE", imponibile);
|
|
r.put("CODIVA", row.get());
|
|
|
|
const char* imposta = row.get();
|
|
r.put("IMPOSTA", imposta);
|
|
|
|
r.put("TIPOCR", row.get());
|
|
r.put("TIPODET", row.get());
|
|
|
|
const TConto c(row, -1, 0x1);
|
|
const int rimp = bill2pos(c, 'I')+1;
|
|
r.put("RIGAIMP", rimp);
|
|
cur++;
|
|
}
|
|
|
|
// Resetta il flag di calcolato sulla liquidazione IVA del mese di registrazione
|
|
const TDate d(m.get(F_DATAREG));
|
|
TString16 chiave; chiave << d.year() << d.month();
|
|
TTable lim("LIM");
|
|
lim.put("CODTAB", chiave);
|
|
if (lim.read() == NOERR)
|
|
{
|
|
const bool calcolato = lim.get_bool("B0");
|
|
if (calcolato)
|
|
{
|
|
lim.put("B0", FALSE);
|
|
lim.rewrite();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int TPrimanota_application::write(const TMask& m)
|
|
{
|
|
const long numreg = m.get_long(F_NUMREG);
|
|
if (numreg > _lastreg) _lastreg = numreg;
|
|
|
|
mask2rel(m);
|
|
const int err = _rel->write(TRUE);
|
|
if (err == NOERR)
|
|
{
|
|
_saldi.registra();
|
|
const TString16 causimm(_causale.causale_inc_imm());
|
|
if (causimm.not_empty())
|
|
genera_incasso(causimm);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::rewrite(const TMask& m)
|
|
{
|
|
mask2rel(m);
|
|
const int err = _rel->rewrite(TRUE);
|
|
if (err == NOERR)
|
|
_saldi.registra();
|
|
return err;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::remove()
|
|
{
|
|
const bool ok = TRelation_application::remove();
|
|
if (ok)
|
|
_saldi.registra();
|
|
return ok;
|
|
}
|
|
|
|
|
|
void TPrimanota_application::genera_incasso(const char* causimm)
|
|
{
|
|
TMask m("cg2100i");
|
|
m.set_handler(F_DATAREG, datareg_handler);
|
|
m.set_handler(F_DATACOMP, datacomp_handler);
|
|
|
|
TFilename tmp; tmp.temp(); // File temporaneo di scambio
|
|
_msk[2]->set_workfile(tmp);
|
|
_msk[2]->save(); // Copia la maschera principale ...
|
|
m.set_workfile(tmp);
|
|
m.load(); // ... nella maschera di incasso
|
|
::remove(tmp); // Cancella file temporaneo
|
|
|
|
const TCausale caus(causimm); // Causale da usare
|
|
m.set(F_NUMREG, ++_lastreg); // Incrementa numero di registrazione
|
|
m.set(F_CODCAUS, causimm); // Cambia causale e ...
|
|
m.set(F_TIPODOC, caus.tipo_doc()); // relativo tipo documento
|
|
|
|
if (m.run() == K_SAVE)
|
|
{
|
|
TMovimentoPN inc; // Nuovo movimento di incasso immediato
|
|
|
|
TRectype r(_rel->cg(0)); // Copia la prima riga contabile
|
|
m.autosave(&inc);
|
|
|
|
inc.lfile()->put("REG", ""); // Annulla eventuale registro IVA
|
|
|
|
const real imp(m.get(F_TOTALE));
|
|
const char sez = r.get_char("SEZIONE");
|
|
|
|
r.put("NUMREG", _lastreg);
|
|
r.put("NUMRIG", 1);
|
|
r.put("IMPORTO", imp);
|
|
r.put("ROWTYPE", ' ');
|
|
r.put("SEZIONE", sez == 'A' ? 'D' : 'A');
|
|
inc.cg(0) = r;
|
|
|
|
TConto conto; caus.bill(2, conto); // Conto della seconda riga della causale
|
|
|
|
r.put("TIPOC", conto.tipo());
|
|
r.put("GRUPPO", conto.gruppo());
|
|
r.put("CONTO", conto.conto());
|
|
r.put("SOTTOCONTO", conto.sottoconto());
|
|
|
|
r.put("NUMRIG", 2);
|
|
r.put("SEZIONE", sez);
|
|
inc.cg(1) = r;
|
|
|
|
while (inc.write() == _isreinsert) // In caso di riscrittura
|
|
inc.lfile()->put("NUMREG", ++_lastreg); // Incrementa numero registrazione
|
|
}
|
|
}
|
|
|
|
|
|
int cg2100 (int argc, char** argv)
|
|
{
|
|
TPrimanota_application a;
|
|
a.run(argc, argv, "Prima nota");
|
|
return 0;
|
|
}
|