4dcf5f74ad
git-svn-id: svn://10.65.10.50/trunk@586 c028cbd2-c16b-5b4b-a496-9718f37d4682
944 lines
26 KiB
C++
Executable File
944 lines
26 KiB
C++
Executable File
#include <config.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <urldefid.h>
|
|
#include <execp.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];
|
|
|
|
if (n == 1 || n == 2)
|
|
{
|
|
const int d = 3-n;
|
|
if (_msk[d] != NULL)
|
|
{
|
|
delete _msk[d];
|
|
_msk[d] = NULL;
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
_savenew = !c.get_bool("Cg21SN");
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
m->set_handler(F_CODREG, reg_handler);
|
|
m->set_handler(F_PROTIVA, protiva_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_CODIVA, main_codiva_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);
|
|
TMask& ism = is.sheet_mask();
|
|
ism.set_handler(101, imponibile_handler);
|
|
ism.set_handler(102, codiva_handler);
|
|
ism.set_handler(103, detrazione_handler);
|
|
ism.set_handler(104, imposta_handler);
|
|
ism.set_handler(109, iva_sottoconto_handler);
|
|
ism.set_handler(209, sheet_clifo_handler);
|
|
ism.set_handler(309, sheet_clifo_handler);
|
|
}
|
|
_iva_showed = FALSE;
|
|
case 1:
|
|
{
|
|
m->set_handler(F_DATAREG, datareg_handler);
|
|
m->set_handler(F_DATACOMP, datacomp_handler);
|
|
m->set_handler(F_DESCR, descr_handler);
|
|
m->set_handler(F_CODCAUS, caus_modify_handler);
|
|
m->set_handler(F_SHEETCG, cg_handler);
|
|
m->set_handler(F_CAMBIO, cambio_handler);
|
|
m->set_handler(F_VISVAL, visval_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, cg_conto_handler);
|
|
cgm.set_handler(106, suspended_handler);
|
|
cgm.set_handler(206, sheet_clifo_handler);
|
|
cgm.set_handler(306, sheet_clifo_handler);
|
|
cgm.set_handler(112, suspended_handler);
|
|
cgm.set_handler(113, suspended_handler);
|
|
cgm.set_handler(213, sheet_clifo_handler);
|
|
cgm.set_handler(313, sheet_clifo_handler);
|
|
}
|
|
break;
|
|
case 3:
|
|
m->set_handler(O_CODICE, occas_code_handler);
|
|
break;
|
|
default:
|
|
CHECKD(0, "Che cavolo di maschera e' la ", n);
|
|
break;
|
|
}
|
|
|
|
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
|
|
|
|
load_mask(0);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::save_and_new() const
|
|
{ return _savenew; }
|
|
|
|
|
|
bool TPrimanota_application::user_destroy()
|
|
{
|
|
for (int m = 3; m >= 0; m--)
|
|
if (_msk[m] != NULL) delete _msk[m];
|
|
|
|
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)
|
|
{
|
|
bool ok = TRUE;
|
|
|
|
if (cod != NULL)
|
|
ok = _causale.read(cod, year);
|
|
|
|
bool nob = FALSE, dob = FALSE, sal = FALSE;
|
|
TipoIVA iva = nessuna_iva;
|
|
|
|
if (ok)
|
|
{
|
|
nob = _causale.num_doc();
|
|
dob = _causale.data_doc();
|
|
sal = gestione_saldaconto() && _causale.saldaconto();
|
|
iva = _causale.iva();
|
|
}
|
|
|
|
TMask* m = _msk[iva == nessuna_iva ? 1 : 2];
|
|
if (m == NULL) return TRUE;
|
|
|
|
m->efield(F_NUMDOC).check_type(nob ? CHECK_REQUIRED : CHECK_NORMAL); // Num. doc. obbligatorio
|
|
m->efield(F_DATADOC).check_type(dob ? CHECK_REQUIRED : CHECK_NORMAL); // Data doc. obbligatoria
|
|
|
|
|
|
if (iva != nessuna_iva)
|
|
{
|
|
const CheckType ct = sal ? CHECK_REQUIRED : CHECK_NORMAL;
|
|
m->efield(F_CODPAG).check_type(ct); // Cod. pag. obbligatorio
|
|
m->show(F_ANNORIF, sal);
|
|
m->show(F_NUMRIF, sal);
|
|
if (sal)
|
|
{
|
|
TString16 val;
|
|
if (riferimento_partita())
|
|
val = m->get(F_NUMDOC);
|
|
else
|
|
val.format("%ld", _causale.reg().protocol());
|
|
m->set(F_NUMRIF, val);
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
void TPrimanota_application::print()
|
|
{
|
|
TExternal_app stampa("cg3 -0");
|
|
stampa.run();
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::changing_mask(int mode)
|
|
{
|
|
if (mode == MODE_QUERY)
|
|
{
|
|
const bool flag = _mode != MODE_QUERY;
|
|
|
|
if (flag && _iva != nessuna_iva && !_iva_showed)
|
|
{
|
|
WINDOW w = ivas().parent();
|
|
show_window(w, TRUE);
|
|
set_front_window(w);
|
|
process_events();
|
|
show_window(w, FALSE);
|
|
_iva_showed = TRUE;
|
|
}
|
|
|
|
return flag;
|
|
}
|
|
_iva = iva_errata;
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
TMask* TPrimanota_application::get_mask(int mode)
|
|
{
|
|
int annoes = 0, annoiva = 0;
|
|
TString16 caus;
|
|
|
|
_mode = mode;
|
|
|
|
switch (mode)
|
|
{
|
|
case MODE_INS:
|
|
annoes = _msk[0]->get_int(F_ANNOES);
|
|
annoiva = _msk[0]->get_int(F_ANNOIVA);
|
|
caus = _msk[0]->get(F_CODCAUS);
|
|
break;
|
|
case MODE_MOD:
|
|
annoes = _rel->lfile().get_int("ANNOES");
|
|
annoiva = _rel->lfile().get_int("ANNOIVA");
|
|
caus = _rel->lfile().get("CODCAUS");
|
|
break;
|
|
default:
|
|
return load_mask(0);
|
|
}
|
|
|
|
giornale().read(annoes);
|
|
causale().read(caus, annoiva);
|
|
_iva = causale().iva();
|
|
|
|
return load_mask(_iva == nessuna_iva ? 1 : 2);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::read_firm_params()
|
|
{
|
|
TConfig c(CONFIG_DITTA, "cg");
|
|
_ges_val = c.get_bool("GesVal");
|
|
_ges_sal = c.get_bool("GesSal");
|
|
_rif_par = c.get_bool("RifPar");
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_mask(TMask& m)
|
|
{
|
|
disable_menu_item(M_FILE_PRINT);
|
|
|
|
read_caus(NULL, 0); // Setta campi obbligatori
|
|
fill_sheet(m);
|
|
|
|
const bool intra = _causale.intra();
|
|
const bool valintra = _causale.valintra();
|
|
const bool corrisp = _causale.corrispettivi();
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
char clig, forg;
|
|
if (_iva == iva_acquisti)
|
|
{
|
|
forg = 's';
|
|
clig = 'h';
|
|
}
|
|
else
|
|
{
|
|
forg = 'h';
|
|
clig = corrisp ? 'h' : 's';
|
|
}
|
|
m.send_key(K_SHIFT+K_CTRL+clig, -1); // GROUP 1 (clienti)
|
|
m.send_key(K_SHIFT+K_CTRL+forg, -2); // GROUP 2 (fornitori)
|
|
if (corrisp) m.hide(F_STATOPAIV);
|
|
|
|
m.show(F_CORRLIRE, intra);
|
|
|
|
const bool corrval = intra && valintra;
|
|
m.show(F_CORRVALUTA, corrval);
|
|
|
|
m.show(F_CODIVA, m.mode() == MODE_INS);
|
|
}
|
|
|
|
// Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_VISVAL (GROUP 3)
|
|
const bool valuta = valintra || (_ges_val && _causale.valuta());
|
|
m.send_key(K_SHIFT+K_CTRL+(valuta ? 's' : 'h'), -3);
|
|
if (valuta)
|
|
{
|
|
const bool ok = m.get(F_VALUTA).not_empty();
|
|
m.field(F_VISVAL).set(ok ? "X" : " ");
|
|
}
|
|
}
|
|
|
|
void TPrimanota_application::init_query_mode(TMask& m)
|
|
{
|
|
read_firm_params();
|
|
enable_menu_item(M_FILE_PRINT);
|
|
}
|
|
|
|
|
|
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()
|
|
{
|
|
TToken_string k(80);
|
|
k.add(F_NUMREG); k.add(_lastreg+1);
|
|
|
|
|
|
TMask& m = curr_mask();
|
|
if (!m.query_mode())
|
|
{
|
|
k.add(F_CODCAUS); k.add(m.get(F_CODCAUS)); // Ricopia causale
|
|
k.add(F_DATAREG); k.add(m.get(F_DATAREG)); // data operazione
|
|
k.add(F_DATACOMP); k.add(m.get(F_DATACOMP)); // competenza
|
|
k.add(F_DATADOC); k.add(m.get(F_DATADOC)); // documento
|
|
const long n = m.get_long(F_NUMDOC);
|
|
if (n > 0)
|
|
{ k.add(F_NUMDOC); k.add(n+1); } // incrementa numero documento
|
|
}
|
|
|
|
return strcpy(__tmp_string, k);
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_insert_mode(TMask& m)
|
|
{
|
|
if (iva() != nessuna_iva)
|
|
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);
|
|
}
|
|
|
|
if (m.get(F_CODCAUS).empty()) return;
|
|
|
|
for (int i = 1; i < _causale.size(); i++)
|
|
{
|
|
const 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)
|
|
|
|
TBill tc; _causale.bill(nriga, tc);
|
|
if (tc.conto() < 1) continue; // Considera solo conti validi
|
|
|
|
const char sezione = rcaus->get_char(RCA_SEZIONE);
|
|
const TImporto zero('D', ZERO);
|
|
const TString80 desc(_causale.desc_agg(i));
|
|
|
|
if (nriga == 1) m.set(F_DESCR, desc);
|
|
|
|
if (iva() == nessuna_iva)
|
|
{
|
|
const int pos = set_cgs_row(-1,zero,tc,desc,' ');
|
|
if (sezione > ' ')
|
|
cgs().disable_cell(pos, sezione == 'D' ? 1 : 0);
|
|
}
|
|
else
|
|
{
|
|
if (nriga >= 2 && nriga <= 9)
|
|
continue; // Conti per IVA detraibile e non, ritenute sociali e fiscali
|
|
|
|
const char tipo = nriga == 1 ? 'T' : ' ';
|
|
if (nriga == 1 && tc.tipo() > ' ' && tc.sottoconto() != 0)
|
|
m.set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto());
|
|
set_cgs_row(-1,zero,tc,desc,tipo);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void TPrimanota_application::init_modify_mode(TMask& m)
|
|
{
|
|
init_mask(m);
|
|
}
|
|
|
|
|
|
// Legge un conto da una riga contabile o iva di prima nota
|
|
bool TPrimanota_application::get_conto(const TRectype& r, TBill& c) const
|
|
{
|
|
c.set(r.get_int("GRUPPO"), r.get_int("CONTO"),
|
|
r.get_long("SOTTOCONTO"), r.get_char("TIPOC"));
|
|
if (r.num() == LF_RMOVIVA)
|
|
c.tipo_cr(r.get_int("TIPOCR"));
|
|
return c.ok();
|
|
}
|
|
|
|
// Scrive un conto su una riga di proma nota
|
|
void TPrimanota_application::put_conto(TRectype& r, const TBill& c) const
|
|
{
|
|
r.put("TIPOC", c.tipo());
|
|
r.put("GRUPPO", c.gruppo());
|
|
r.put("CONTO", c.conto());
|
|
r.put("SOTTOCONTO", c.sottoconto());
|
|
}
|
|
|
|
|
|
// Controlla sulla causale se il segno del totale documento (ritsoc=FALSE)
|
|
// o quello delle ritenute sociali (ritsoc=TRUE) e' invertito rispetto al normale
|
|
bool TPrimanota_application::test_swap(bool ritsoc)
|
|
{
|
|
bool s = FALSE;
|
|
|
|
const char sez = ritsoc ? causale().sezione_ritsoc() : causale().sezione_clifo();
|
|
s = (iva() == iva_vendite) ^ sez == 'D';
|
|
return s;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::read(TMask& m)
|
|
{
|
|
m.autoload(_rel);
|
|
|
|
cgs().reset();
|
|
|
|
if (_iva != nessuna_iva)
|
|
{
|
|
ivas().reset();
|
|
|
|
const TString16 occode(_rel->lfile().get("OCFPI"));
|
|
occas_mask().set(O_CODICE, occode);
|
|
|
|
const char clifo = _rel->lfile().get_char("TIPO");
|
|
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");
|
|
}
|
|
|
|
// Inizializza cambio
|
|
real cambio(_rel->lfile().get("CAMBIO"));
|
|
if (cambio < 1.0) cambio = 1.0;
|
|
m.set_exchange(FALSE, cambio);
|
|
|
|
_saldi.reset(); // Azzera saldi
|
|
_saldi.set_movprovv(_rel->lfile().get_bool("PROVVIS"));
|
|
_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(255);
|
|
|
|
for (int i = 0; i < _rel->cg_items(); i++)
|
|
{
|
|
const TRectype& r = _rel->cg(i);
|
|
riga.cut(0); // Vuota la riga
|
|
|
|
const int rcontr = r.get_int("RCONTR") -1;
|
|
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);
|
|
|
|
const real im(r.get_real("IMPORTO"));
|
|
const char sezione = toupper(r.get_char("SEZIONE"));
|
|
|
|
TImporto import(sezione, im);
|
|
import.add_to(riga); // Dare/Avere 101-102
|
|
|
|
TConto conto; get_conto(r, 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(_rel->cg(rcontr), conto);
|
|
riga.add(conto.string(0x3)); // Contropartita 110-114
|
|
}
|
|
else riga.add(" | | | | ");
|
|
|
|
const char tipo = r.get_char("ROWTYPE");
|
|
riga.add(tipo); // Tipo di riga 115
|
|
|
|
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();
|
|
|
|
const bool to_swap = test_swap(FALSE);
|
|
if (to_swap)
|
|
{
|
|
real totdoc(m.get(F_TOTALE));
|
|
totdoc = -totdoc;
|
|
m.set(F_TOTALE, totdoc.string());
|
|
}
|
|
for (i = 0; i < _rel->iva_items(); i++)
|
|
{
|
|
TRectype& r = _rel->iva(i);
|
|
riga.cut(0);
|
|
|
|
real imponibile(r.get("IMPONIBILE"));
|
|
if (to_swap) imponibile = -imponibile;
|
|
riga.add(imponibile.string()); // Imponibile 101
|
|
|
|
riga.add(r.get("CODIVA")); // IVA 102
|
|
riga.add(r.get("TIPODET")); // Detrazione 103
|
|
|
|
|
|
real imposta(r.get("IMPOSTA"));
|
|
if (to_swap) imposta = -imposta;
|
|
if (imponibile.sign() * imposta.sign() < 0)
|
|
{
|
|
warning_box("Registrazione con imponibile e imposta con segni discordi:\n"
|
|
"assegnato il segno dell'imponibile");
|
|
imposta = -imposta;
|
|
}
|
|
riga.add(imposta.string()); // Imposta 104
|
|
|
|
TBill c; get_conto(r, c);
|
|
if (c.ok())
|
|
c.add_to(riga, 4, 0x7); // 105-110
|
|
else
|
|
riga.add(" | | | | | ");
|
|
|
|
ivas().row(i) = riga;
|
|
}
|
|
|
|
return _rel->status();
|
|
}
|
|
|
|
|
|
// Trasferisce i dati da maschera a movimento di prima nota
|
|
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 = m.get_int(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();
|
|
|
|
// 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];
|
|
|
|
TImporto n; n = row;
|
|
const TConto conto(row, 2, 0x3);
|
|
_saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE);
|
|
|
|
TRectype &r = _rel->cg(i);
|
|
r.zero();
|
|
|
|
r.put("NUMREG", numreg); // Numero registrazione
|
|
r.put("ANNOES", annoes); // Anno esercizio
|
|
r.put("DATAREG", datareg); // Data di registrazione
|
|
r.put("NUMRIG", i+1); // Numero riga
|
|
|
|
r.put("SEZIONE", n.sezione()); // Sezione
|
|
r.put("IMPORTO", n.valore()); // Importo
|
|
put_conto(r, conto); // Conto
|
|
|
|
row.get(); // Codice descrizione
|
|
r.put("DESCR", row.get()); // Descrizione riga
|
|
|
|
int rcontr = 0; // Riga contropartita
|
|
const TBill contro(row, -1, 0x3); // Conto contropartita
|
|
|
|
const char tipo = row.get_char();
|
|
r.put("ROWTYPE", tipo); // Tipo riga
|
|
|
|
if (contro.ok())
|
|
{
|
|
if (tipo == 'F' || tipo == 'S') n.swap_section();
|
|
rcontr = bill2contr(contro, n.sezione())+1;
|
|
if (rcontr < 1)
|
|
{
|
|
rcontr = i == 0 ? 2 : 1;
|
|
if (!yesno_box("La riga contabile %d non ha una contropartita valida:\n"
|
|
"si desidera trasformarla nel conto della riga %d", i+1, rcontr))
|
|
rcontr = 0;
|
|
}
|
|
}
|
|
r.put("RCONTR", rcontr); // Contropartita
|
|
}
|
|
}
|
|
if (_iva == nessuna_iva) return;
|
|
|
|
if (causale().corrispettivi())
|
|
{
|
|
TRectype& rec = _rel->lfile().curr();
|
|
rec.put("TIPO", "");
|
|
rec.put("CODCF", ""); // Azzera il cliente nei movimenti dei corrispettivi
|
|
}
|
|
else
|
|
{
|
|
_rel->lfile().put("TIPO", clifo());
|
|
|
|
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");
|
|
}
|
|
|
|
const bool intra = causale().intra();
|
|
const bool to_swap = test_swap(FALSE);
|
|
if (to_swap)
|
|
{
|
|
real totale = _rel->lfile().get("TOTDOC");
|
|
totale = -totale;
|
|
_rel->lfile().put("TOTDOC", totale);
|
|
}
|
|
|
|
TArray& irows = ivas().rows_array();
|
|
for (int i = 0; i < irows.items(); i++)
|
|
{
|
|
TToken_string& row = (TToken_string&)irows[i];
|
|
if (row.empty_items())
|
|
continue;
|
|
|
|
TRectype &r = _rel->iva(i);
|
|
r.zero();
|
|
r.put("ANNOES", annoes);
|
|
r.put("NUMREG", numreg);
|
|
r.put("INTRA", intra); // Causale intra
|
|
r.put("NUMRIG", i+1);
|
|
|
|
real imponibile(row.get(0));
|
|
if (to_swap) imponibile = -imponibile;
|
|
r.put("IMPONIBILE", imponibile);
|
|
|
|
r.put("CODIVA", row.get());
|
|
r.put("TIPODET", row.get());
|
|
|
|
real imposta(row.get());
|
|
if (to_swap) imposta = -imposta;
|
|
if (imponibile.sign() * imposta.sign() < 0)
|
|
{
|
|
yesnofatal_box("Registrazione di imponibile e imposta discordi");
|
|
imposta = -imposta;
|
|
}
|
|
r.put("IMPOSTA", imposta);
|
|
|
|
r.put("TIPOCR", row.get());
|
|
|
|
const TBill c(row, -1, 0x1);
|
|
const int rimp = bill2pos(c, 'I')+1;
|
|
r.put("RIGAIMP", rimp);
|
|
put_conto(r, c);
|
|
}
|
|
}
|
|
|
|
|
|
int TPrimanota_application::write(const TMask& m)
|
|
{
|
|
const long numreg = m.get_long(F_NUMREG);
|
|
if (numreg > _lastreg) _lastreg = numreg; // Aggiorna ultima registrazione
|
|
|
|
mask2rel(m);
|
|
const int err = _rel->write(TRUE);
|
|
if (err == NOERR)
|
|
{
|
|
_saldi.registra();
|
|
|
|
if (iva() != nessuna_iva)
|
|
{
|
|
causale().reg().reread(); // Aggiorna protocollo IVA
|
|
if (!gestione_saldaconto())
|
|
{
|
|
const TString16 causimm(causale().causale_inc_imm());
|
|
if (causimm.not_empty())
|
|
genera_incasso(causimm);
|
|
}
|
|
}
|
|
|
|
if (gestione_saldaconto() && causale().saldaconto())
|
|
aggiorna_scadenzario(m);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::rewrite(const TMask& m)
|
|
{
|
|
mask2rel(m);
|
|
const int err = _rel->rewrite(TRUE);
|
|
if (err == NOERR)
|
|
_saldi.registra();
|
|
if (gestione_saldaconto() && _causale.saldaconto())
|
|
aggiorna_scadenzario(m);
|
|
return err;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::remove()
|
|
{
|
|
const bool ok = TRelation_application::remove();
|
|
if (ok)
|
|
_saldi.registra();
|
|
return ok;
|
|
}
|
|
|
|
|
|
HIDDEN bool incasso_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_ENTER)
|
|
{
|
|
TMask& m = f.mask();
|
|
TImporto tot(m.get(I_SEZIONE1)[0], (real)m.get(F_TOTALE));
|
|
|
|
for (int i = 2; i < 5; i++)
|
|
{
|
|
const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4);
|
|
const real val(m.get(sid+1));
|
|
const TImporto imp(m.get(sid)[0], val);
|
|
tot += imp;
|
|
}
|
|
if (tot.valore() != ZERO)
|
|
return f.error_box("Il movimento e' sbilaciato di %s", tot.valore().string("."));
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void TPrimanota_application::genera_incasso(const char* causimm)
|
|
{
|
|
TMask m("cg2100i");
|
|
if (iva() == iva_acquisti) m.set_caption("Movimento di pagamento immediato");
|
|
|
|
m.set_handler(F_DATAREG, datareg_handler);
|
|
m.set_handler(F_DATACOMP, datacomp_handler);
|
|
m.set_handler(F_TOTALE, incasso_handler);
|
|
|
|
TCausale caus(causimm); // Causale da usare
|
|
|
|
if (caus.data_doc()) m.efield(F_DATADOC).check_type(CHECK_REQUIRED);
|
|
if (caus.num_doc()) m.efield(F_NUMDOC).check_type(CHECK_REQUIRED);
|
|
|
|
m.set(F_DATAREG, curr_mask().get(F_DATAREG));
|
|
m.set(F_DATACOMP, curr_mask().get(F_DATACOMP));
|
|
m.set(F_DATADOC, curr_mask().get(F_DATADOC));
|
|
m.set(F_NUMDOC, curr_mask().get(F_NUMDOC));
|
|
m.set(F_NUMREG, ++_lastreg); // Incrementa numero di registrazione
|
|
m.set(F_DESCR, caus.desc_agg(1)); // Descrizione
|
|
m.set(F_CODCAUS, causimm); // Cambia causale
|
|
m.set(F_DESCRCAUS, caus.descrizione());
|
|
|
|
m.set(I_SEZIONE1, caus.sezione_clifo() == 'D' ? "D" : "A");
|
|
m.set(F_TOTALE, curr_mask().get(F_TOTALE));
|
|
|
|
m.set(F_CLIFO, _rel->cg(0).get("TIPOC"));
|
|
m.set(F_GRUPPOCLIFO, _rel->cg(0).get("GRUPPO"));
|
|
m.set(F_CONTOCLIFO, _rel->cg(0).get("CONTO"));
|
|
const TString& clifo = _rel->cg(0).get("SOTTOCONTO");
|
|
m.set(F_CLIENTE, clifo); m.set(F_FORNITORE, clifo); m.set(I_SOTTOCONTO, clifo);
|
|
|
|
TBill conto; caus.bill(2, conto); // Conto della seconda riga della causale
|
|
m.set(I_SEZIONE2, caus.sezione_clifo() == 'D' ? "A" : "D");
|
|
m.set(I_IMPORTO2, curr_mask().get(F_TOTALE));
|
|
m.set(I_GRUPPO2, conto.gruppo());
|
|
m.set(I_CONTO2, conto.conto());
|
|
m.set(I_SOTTOCONTO2, conto.sottoconto());
|
|
|
|
if (m.run() == K_SAVE)
|
|
{
|
|
TMovimentoPN inc; // Nuovo movimento di incasso immediato
|
|
|
|
m.autosave(&inc);
|
|
inc.lfile().put("TIPODOC", caus.tipo_doc()); // Tipo documento
|
|
inc.lfile().put("REG", caus.reg().name()); // Registro
|
|
|
|
const int annoes = m.get_int(F_ANNOES);
|
|
const TString16 datareg = m.get(F_DATAREG);
|
|
|
|
TRectype& r = inc.cg(0);
|
|
r.zero();
|
|
r.put("NUMREG", _lastreg);
|
|
r.put("NUMRIG", 1);
|
|
r.put("DATAREG", datareg);
|
|
r.put("ANNOES", annoes);
|
|
r.put("SEZIONE", m.get(I_SEZIONE1));
|
|
r.put("IMPORTO", m.get(F_TOTALE));
|
|
r.put("TIPOC", m.get(F_CLIFO));
|
|
r.put("GRUPPO", m.get(F_GRUPPOCLIFO));
|
|
r.put("CONTO", m.get(F_CONTOCLIFO));
|
|
|
|
short clifo_id;
|
|
switch (m.get(F_CLIFO)[0])
|
|
{
|
|
case 'C':
|
|
clifo_id = F_CLIENTE; break;
|
|
case 'F':
|
|
clifo_id = F_FORNITORE; break;
|
|
default :
|
|
clifo_id = I_SOTTOCONTO; break;
|
|
}
|
|
r.put("SOTTOCONTO", m.get(clifo_id));
|
|
|
|
r.put("DESCR", m.get(F_DESCR));
|
|
r.put("RCONTR", 2);
|
|
r.put("ROWTYPE", " ");
|
|
|
|
for (int i = 2; i < 5; i++)
|
|
{
|
|
const int sid = i == 2 ? I_SEZIONE2 : (i == 3 ? I_SEZIONE3 : I_SEZIONE4);
|
|
const char* imp = m.get(sid+1);
|
|
if (*imp == '\0') break;
|
|
|
|
TRectype& r = inc.cg(i-1);
|
|
r.zero();
|
|
r.put("IMPORTO", imp);
|
|
r.put("NUMREG", _lastreg);
|
|
r.put("NUMRIG", i);
|
|
r.put("DATAREG", datareg);
|
|
r.put("ANNOES", annoes);
|
|
r.put("SEZIONE", m.get(sid));
|
|
r.put("TIPOC", ' ');
|
|
r.put("GRUPPO", m.get(sid+2));
|
|
r.put("CONTO", m.get(sid+3));
|
|
r.put("SOTTOCONTO", m.get(sid+4));
|
|
if (i == 2)
|
|
r.put("DESCR", caus.desc_agg(2));
|
|
r.put("RCONTR", 1);
|
|
r.put("ROWTYPE", " ");
|
|
}
|
|
|
|
while (inc.write() == _isreinsert) // In caso di riscrittura
|
|
inc.lfile().put("NUMREG", ++_lastreg); // Incrementa numero registrazione
|
|
|
|
if (inc.good())
|
|
{
|
|
_saldi.reset(); // Inizializza saldi
|
|
_saldi.set_movprovv(FALSE);
|
|
_saldi.set_movap(FALSE);
|
|
_saldi.set_anno_es(m.get_int(F_ANNOES));
|
|
_saldi.set_num_ulmov(_lastreg);
|
|
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
|
|
for (int r = 0; r < i; r++)
|
|
{
|
|
const TRectype& rec = inc.cg(r);
|
|
TConto c; get_conto(rec, c);
|
|
const real im(rec.get("IMPORTO"));
|
|
const char sezione = rec.get_char("SEZIONE");
|
|
_saldi.aggiorna(c, im, sezione, TRUE);
|
|
}
|
|
_saldi.registra();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int cg2100 (int argc, char** argv)
|
|
{
|
|
TPrimanota_application a;
|
|
a.run(argc, argv, "Prima nota");
|
|
return 0;
|
|
}
|