1994-12-05 14:21:36 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
1995-05-09 13:31:10 +00:00
|
|
|
#include <tabutil.h>
|
1994-12-05 14:21:36 +00:00
|
|
|
#include <urldefid.h>
|
|
|
|
|
|
|
|
#include "cg2200.h"
|
|
|
|
#include "cg2101.h"
|
1995-05-09 13:31:10 +00:00
|
|
|
#include "cglib.h"
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
#include <causali.h>
|
1994-12-05 14:21:36 +00:00
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
|
|
|
|
|
|
|
TString& add_plural(TString& s, long num, const char* name)
|
|
|
|
{
|
|
|
|
const TFixed_string n(name);
|
|
|
|
const char last = n[n.len()-1];
|
|
|
|
|
|
|
|
if (num < 1)
|
|
|
|
{
|
|
|
|
s << "nessun";
|
|
|
|
if (toupper(last) == 'A' || toupper(n[0]) == 'Z' ||
|
|
|
|
toupper(n[0]) == 'S' && strchr("aeiouAEIOU", n[1]) == NULL)
|
|
|
|
s << tolower(last);
|
|
|
|
s << ' ' << name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s << num << ' ' << name;
|
|
|
|
if (num > 1)
|
|
|
|
s[s.len()-1] = (last == 'a') ? 'e' : 'i';
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
class TProvvisori_app : public TApplication
|
|
|
|
{
|
|
|
|
TLocalisamfile* _sal;
|
|
|
|
TLocalisamfile* _cau;
|
|
|
|
TTable* _reg;
|
|
|
|
|
|
|
|
TString16 _from_caus, _to_caus;
|
|
|
|
|
|
|
|
TSaldo_agg _saldi;
|
|
|
|
|
|
|
|
protected: // TApplication
|
1994-12-05 14:21:36 +00:00
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
|
|
|
virtual bool menu(MENU_TAG m);
|
1995-11-17 10:27:24 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static bool date_handler(TMask_field& f, KEY k);
|
1995-05-09 13:31:10 +00:00
|
|
|
|
1994-12-05 14:21:36 +00:00
|
|
|
public:
|
1995-05-09 13:31:10 +00:00
|
|
|
void inizia_saldi(const TRectype& mov);
|
|
|
|
void aggiungi_saldi(const TRectype& rmov, bool lettura);
|
|
|
|
void aggiorna_saldi();
|
|
|
|
|
|
|
|
bool confirm_provv(TCursor& cur, TProgind& pi);
|
|
|
|
bool delete_provv(TCursor& cur, TProgind& pi);
|
|
|
|
static bool filter(const TRelation* rel);
|
|
|
|
|
|
|
|
TProvvisori_app() {};
|
1994-12-05 14:21:36 +00:00
|
|
|
};
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
inline TProvvisori_app& app()
|
|
|
|
{ return (TProvvisori_app&)main_app(); }
|
|
|
|
|
|
|
|
|
|
|
|
bool TProvvisori_app::create()
|
1994-12-05 14:21:36 +00:00
|
|
|
{
|
1995-05-09 13:31:10 +00:00
|
|
|
TApplication::create();
|
|
|
|
|
|
|
|
_cau = new TLocalisamfile(LF_CAUSALI);
|
|
|
|
_sal = new TLocalisamfile(LF_SALDI);
|
|
|
|
_reg = new TTable("REG");
|
|
|
|
|
1994-12-05 14:21:36 +00:00
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
bool TProvvisori_app::destroy()
|
1994-12-05 14:21:36 +00:00
|
|
|
{
|
1995-05-09 13:31:10 +00:00
|
|
|
delete _reg;
|
|
|
|
delete _sal;
|
|
|
|
delete _cau;
|
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
return TApplication::destroy();
|
1994-12-05 14:21:36 +00:00
|
|
|
}
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
void TProvvisori_app::inizia_saldi(const TRectype& r)
|
|
|
|
{
|
|
|
|
CHECK(r.num() == LF_MOV, "Voglio un movimento");
|
|
|
|
|
|
|
|
_saldi.reset();
|
|
|
|
|
1996-05-20 09:26:39 +00:00
|
|
|
tiposal tsal = normale;
|
1995-05-09 13:31:10 +00:00
|
|
|
const TString& c = r.get(MOV_CODCAUS);
|
|
|
|
if (c.not_empty())
|
|
|
|
{
|
|
|
|
_cau->put(CAU_CODCAUS, c);
|
1996-05-20 09:26:39 +00:00
|
|
|
if (_cau->read() == NOERR)
|
|
|
|
{
|
|
|
|
if (_cau->get_char(CAU_MOVAP) == 'A') tsal = apertura;
|
|
|
|
else if (_cau->get_char(CAU_MOVAP) == 'C') tsal = chiusura;
|
|
|
|
}
|
1995-05-09 13:31:10 +00:00
|
|
|
}
|
1996-05-20 09:26:39 +00:00
|
|
|
_saldi.set_tipo_saldo(tsal);
|
1995-05-09 13:31:10 +00:00
|
|
|
|
|
|
|
_saldi.set_anno_es(r.get_int(MOV_ANNOES));
|
|
|
|
_saldi.set_num_ulmov(r.get_long(MOV_NUMREG));
|
|
|
|
_saldi.set_data_ulmov(r.get_date(MOV_DATAREG));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TProvvisori_app::aggiungi_saldi(const TRectype& r, bool lettura)
|
|
|
|
{
|
|
|
|
CHECK(r.num() == LF_RMOV, "Voglio la riga di un movimento");
|
|
|
|
|
|
|
|
TBill conto; conto.get(r);
|
|
|
|
TImporto importo(r.get_char(RMV_SEZIONE), r.get_real(RMV_IMPORTO));
|
|
|
|
|
|
|
|
_saldi.set_movprovv(lettura); // In lettura sono tutti provvisori
|
|
|
|
_saldi.aggiorna(conto, importo, !lettura); // In lettura devo sottrarre l'importo
|
|
|
|
}
|
|
|
|
|
|
|
|
void TProvvisori_app::aggiorna_saldi()
|
|
|
|
{
|
|
|
|
_saldi.registra();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TProvvisori_app::confirm_provv(TCursor& cur, TProgind& pi)
|
|
|
|
{
|
|
|
|
TLocalisamfile& mov = cur.file(LF_MOV);
|
|
|
|
TLocalisamfile rmov(LF_RMOV);
|
|
|
|
|
|
|
|
for (cur = 0; cur.pos() < cur.items(); ++cur)
|
|
|
|
{
|
|
|
|
const long numreg = mov.get_long(MOV_NUMREG);
|
|
|
|
inizia_saldi(mov.curr());
|
|
|
|
|
|
|
|
int err = cur.lock();
|
|
|
|
for (int rig = 1; err == NOERR; rig++)
|
|
|
|
{
|
|
|
|
rmov.put(RMV_NUMREG, numreg);
|
|
|
|
rmov.put(RMV_NUMRIG, rig);
|
|
|
|
if (rmov.read(_isequal, _lock) != NOERR) break;
|
|
|
|
aggiungi_saldi(rmov.curr(), TRUE);
|
|
|
|
aggiungi_saldi(rmov.curr(), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
mov.zero(MOV_PROVVIS);
|
|
|
|
err = mov.rewrite();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
aggiorna_saldi();
|
|
|
|
pi.addstatus(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != NOERR)
|
|
|
|
return error_box("Errore nella conferma del movimento %ld", numreg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TProvvisori_app::delete_provv(TCursor& cur, TProgind& pi)
|
1994-12-05 14:21:36 +00:00
|
|
|
{
|
|
|
|
TLocalisamfile& mov = cur.file(LF_MOV);
|
|
|
|
TLocalisamfile rmov(LF_RMOV);
|
|
|
|
TLocalisamfile rmoviva(LF_RMOVIVA);
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
TString256 error;
|
|
|
|
|
|
|
|
for (cur = 0; cur.pos() < cur.items(); ++cur)
|
|
|
|
{
|
|
|
|
const long numreg = mov.get_long(MOV_NUMREG);
|
|
|
|
|
1995-06-21 15:33:31 +00:00
|
|
|
mov.setkey(1); // Isam bug on remove with key != 1
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
|
|
|
int err = mov.read(_isequal, _lock);
|
|
|
|
if (err != NOERR)
|
|
|
|
return error_box("Errore %d nel bloccare il record %ld", err, numreg);
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
inizia_saldi(mov.curr());
|
|
|
|
|
|
|
|
for (int rig = 1; err == NOERR; rig++)
|
|
|
|
{
|
|
|
|
rmov.put(RMV_NUMREG, numreg);
|
|
|
|
rmov.put(RMV_NUMRIG, rig);
|
|
|
|
if (rmov.read(_isequal, _lock) != NOERR) break;
|
|
|
|
|
|
|
|
aggiungi_saldi(rmov.curr(), TRUE);
|
|
|
|
err = rmov.remove();
|
|
|
|
if (err != NOERR)
|
|
|
|
error.format("riga contabile %d", rig);
|
|
|
|
}
|
|
|
|
for (rig = 1; err == NOERR; rig++)
|
|
|
|
{
|
|
|
|
rmoviva.put(RMI_NUMREG, numreg);
|
|
|
|
rmoviva.put(RMI_NUMRIG, rig);
|
|
|
|
if (rmoviva.read(_isequal, _lock) != NOERR) break;
|
|
|
|
err = rmov.remove();
|
|
|
|
if (err != NOERR)
|
|
|
|
error.format("riga IVA %d", rig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
err = mov.remove();
|
|
|
|
if (err != NOERR)
|
|
|
|
error = "testata";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
aggiorna_saldi();
|
|
|
|
pi.addstatus(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return error_box("Errore %d nella cancellazione della %s del movimento %ld",
|
|
|
|
err, (const char*)error, numreg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TProvvisori_app::filter(const TRelation* rel)
|
1995-11-17 10:27:24 +00:00
|
|
|
{
|
|
|
|
bool ok = FALSE;
|
1995-05-09 13:31:10 +00:00
|
|
|
|
1995-11-17 10:27:24 +00:00
|
|
|
const TRectype& mov = rel->curr();
|
|
|
|
if (mov.get_char(MOV_PROVVIS) > ' ')
|
|
|
|
{
|
|
|
|
const char* caus = mov.get(MOV_CODCAUS);
|
|
|
|
ok = app()._from_caus <= caus && app()._to_caus >= caus;
|
|
|
|
}
|
1995-05-09 13:31:10 +00:00
|
|
|
|
1995-11-17 10:27:24 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deve essere specificata almeno una data (inizio o fine)
|
|
|
|
bool TProvvisori_app::date_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
if (k == K_ENTER && f.get().empty())
|
|
|
|
{
|
|
|
|
const TMask& m = f.mask();
|
|
|
|
if (m.get(F_TODATE).empty())
|
1996-05-23 15:31:54 +00:00
|
|
|
ok = f.error_box("E' necessario specificare almeno una data");
|
1995-11-17 10:27:24 +00:00
|
|
|
}
|
|
|
|
return ok;
|
1995-05-09 13:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TProvvisori_app::menu(MENU_TAG)
|
|
|
|
{
|
|
|
|
TMask m("cg2200a");
|
1995-11-17 10:27:24 +00:00
|
|
|
m.set_handler(F_FROMDATE, date_handler);
|
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
TCursor& cur = *m.efield(F_FROMDATE).browse()->cursor();
|
|
|
|
|
|
|
|
KEY key;
|
|
|
|
while ((key = m.run()) != K_QUIT)
|
1994-12-05 14:21:36 +00:00
|
|
|
{
|
1995-11-17 10:27:24 +00:00
|
|
|
TRectype from(LF_MOV);
|
|
|
|
TRectype to(LF_MOV);
|
1995-05-09 13:31:10 +00:00
|
|
|
|
|
|
|
const char* s = m.get(F_FROMDATE);
|
|
|
|
|
|
|
|
if (key == K_ENTER)
|
|
|
|
{
|
|
|
|
const TDate da(s);
|
|
|
|
const TLibro_giornale lg(da.year());
|
|
|
|
const TDate lp(lg.last_print());
|
|
|
|
if (da < lp)
|
|
|
|
{
|
|
|
|
s = lp.string();
|
|
|
|
const bool ok = yesno_box("Il libro giornale e stato stampato il %s:\n",
|
|
|
|
"Si desidera modificare la data iniziale?", s);
|
|
|
|
if (!ok) continue;
|
|
|
|
}
|
1994-12-05 14:21:36 +00:00
|
|
|
}
|
1995-05-09 13:31:10 +00:00
|
|
|
|
|
|
|
if (*s) from.put(MOV_DATAREG, s);
|
|
|
|
s = m.get(F_FROMREG);
|
|
|
|
if (*s) from.put(MOV_NUMREG, s);
|
|
|
|
_from_caus = m.get(F_FROMCAUS);
|
|
|
|
|
|
|
|
s = m.get(F_TODATE);
|
|
|
|
if (*s) to.put(MOV_DATAREG, s);
|
|
|
|
s = m.get(F_TOREG);
|
|
|
|
if (*s) to.put(MOV_NUMREG, s);
|
|
|
|
_to_caus = m.get(F_TOCAUS);
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
cur.setregion(from, to);
|
|
|
|
cur.set_filterfunction(filter);
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
const TRecnotype total = cur.items();
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
TString80 action(key == K_ENTER ? "conferma" : "cancellazione");
|
|
|
|
action << " di "; add_plural(action, total, "movimento");
|
|
|
|
|
|
|
|
TString256 caption("E' stata richiesta la ");
|
|
|
|
caption << action << '.';
|
|
|
|
|
|
|
|
if (total > 0)
|
|
|
|
{
|
|
|
|
caption << "\nSi desidera continuare?";
|
|
|
|
if (!yesno_box(caption)) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
warning_box(caption);
|
1994-12-05 14:21:36 +00:00
|
|
|
continue;
|
1995-05-09 13:31:10 +00:00
|
|
|
}
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-05-09 13:31:10 +00:00
|
|
|
action[0] = toupper(action[0]);
|
|
|
|
TProgind pi(total, action, FALSE, TRUE, 24);
|
1994-12-05 14:21:36 +00:00
|
|
|
|
1995-11-17 10:27:24 +00:00
|
|
|
cur.freeze(TRUE);
|
1995-05-09 13:31:10 +00:00
|
|
|
|
|
|
|
if (key == K_ENTER)
|
|
|
|
confirm_provv(cur, pi);
|
|
|
|
else
|
|
|
|
delete_provv(cur, pi);
|
|
|
|
|
1994-12-05 14:21:36 +00:00
|
|
|
cur.freeze(FALSE);
|
1995-05-09 13:31:10 +00:00
|
|
|
from.zero(); to.zero();
|
|
|
|
cur.setregion(from, to);
|
|
|
|
cur.set_filterfunction(NULL);
|
1995-11-17 10:27:24 +00:00
|
|
|
m.reset();
|
1994-12-05 14:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int cg2200(int argc, char** argv)
|
|
|
|
{
|
1995-05-09 13:31:10 +00:00
|
|
|
TProvvisori_app a;
|
|
|
|
a.run(argc, argv, "Gestione provvisori");
|
1994-12-05 14:21:36 +00:00
|
|
|
return 0;
|
1994-12-02 16:04:40 +00:00
|
|
|
}
|