1995-03-14 11:12:51 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <urldefid.h>
|
1995-03-16 08:50:33 +00:00
|
|
|
#include <saldi.h>
|
1995-03-21 11:09:06 +00:00
|
|
|
#include <pconti.h>
|
1995-03-16 08:50:33 +00:00
|
|
|
#include <partite.h>
|
|
|
|
#include <scadenze.h>
|
1995-03-17 11:47:29 +00:00
|
|
|
#include <lffiles.h>
|
|
|
|
#include <relation.h>
|
1995-03-21 11:09:06 +00:00
|
|
|
#include <utility.h>
|
1995-03-14 11:12:51 +00:00
|
|
|
|
1995-03-21 11:09:06 +00:00
|
|
|
#include "../cg/conto.h"
|
|
|
|
#include "../cg/pagament.h"
|
1995-03-16 08:50:33 +00:00
|
|
|
#include "sc1200.h"
|
1995-03-21 11:09:06 +00:00
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
class TCreatepart_app : public TApplication
|
|
|
|
{
|
1995-03-21 11:09:06 +00:00
|
|
|
TLocalisamfile* _conti;
|
|
|
|
TLocalisamfile* _partite;
|
|
|
|
TLocalisamfile* _scadenze;
|
|
|
|
|
|
|
|
int _anno;
|
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
protected:
|
1995-03-21 11:09:06 +00:00
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
|
|
|
virtual bool menu(MENU_TAG m);
|
1995-03-21 11:09:06 +00:00
|
|
|
|
|
|
|
long get_last_partita(bool check_erase);
|
1995-03-14 11:12:51 +00:00
|
|
|
|
1995-03-21 11:09:06 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
bool is_clifo(int g, int c, char& cf);
|
|
|
|
TCreatepart_app() {}
|
|
|
|
virtual ~TCreatepart_app() {}
|
1995-03-14 11:12:51 +00:00
|
|
|
};
|
|
|
|
|
1995-03-21 11:09:06 +00:00
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
bool TCreatepart_app::create()
|
|
|
|
{
|
|
|
|
TApplication::create();
|
1995-03-21 11:09:06 +00:00
|
|
|
|
|
|
|
_conti = new TLocalisamfile(LF_PCON);
|
|
|
|
_partite = new TLocalisamfile(LF_PARTITE);
|
|
|
|
_scadenze = new TLocalisamfile(LF_SCADENZE);
|
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCreatepart_app::destroy()
|
1995-03-21 11:09:06 +00:00
|
|
|
{
|
|
|
|
delete _conti;
|
|
|
|
delete _partite;
|
|
|
|
delete _scadenze;
|
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
return TApplication::destroy();
|
|
|
|
}
|
|
|
|
|
1995-03-21 11:09:06 +00:00
|
|
|
|
|
|
|
long TCreatepart_app::get_last_partita(bool zap)
|
|
|
|
{
|
|
|
|
// ritorna il primo valore utile per partita temporanea AP;
|
|
|
|
// se ce ne sono gia' propone la cancellazione e se ok
|
|
|
|
// la esegue perfidamente
|
|
|
|
|
|
|
|
_partite->zero();
|
|
|
|
_partite->put(PART_ANNO, _anno);
|
|
|
|
_partite->put(PART_NUMPART, "AP");
|
|
|
|
|
|
|
|
long last = 0l;
|
|
|
|
bool go = _partite->read(_isgteq) == NOERR;
|
|
|
|
|
|
|
|
if (zap && go)
|
|
|
|
zap = yesno_box("Esistono gia' partite generate in base ai"
|
|
|
|
" saldi contabili. Si desidera cancellarle?");
|
|
|
|
|
|
|
|
while (go)
|
|
|
|
{
|
|
|
|
if (zap)
|
|
|
|
{
|
|
|
|
for (int i = 0; ; i++)
|
|
|
|
{
|
|
|
|
// zappa scadenze
|
|
|
|
_scadenze->zero();
|
|
|
|
_scadenze->put(SCAD_ANNO, _partite->get(PART_ANNO));
|
|
|
|
_scadenze->put(SCAD_NUMPART, _partite->get(PART_NUMPART));
|
|
|
|
_scadenze->put(SCAD_NRATA, i+1);
|
|
|
|
|
|
|
|
if (_scadenze->read() == NOERR) _scadenze->remove();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_partite->remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else last = atol(_partite->get(PART_NUMPART).mid(2)) + 1l;
|
|
|
|
|
|
|
|
go = _partite->next() == NOERR &&
|
|
|
|
_partite->get(PART_NUMPART).mid(0,2) == "AP";
|
|
|
|
}
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TCreatepart_app::is_clifo(int g, int c, char& cf)
|
|
|
|
{
|
|
|
|
static int gr = -1, ct = -1;
|
|
|
|
|
|
|
|
if (g != gr || c != ct)
|
|
|
|
{
|
|
|
|
_conti->zero();
|
|
|
|
_conti->put(PCN_GRUPPO, g);
|
|
|
|
_conti->put(PCN_CONTO, c);
|
|
|
|
if (_conti->read() != NOERR)
|
|
|
|
error_box("Piano dei conti disallineato con archivio saldi");
|
|
|
|
gr = g; ct = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_conti->get(PCN_TMCF).empty())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cf = _conti->get_char(PCN_TMCF);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
bool TCreatepart_app::menu(MENU_TAG)
|
1995-03-16 08:50:33 +00:00
|
|
|
{
|
|
|
|
TMask m("sc1200a");
|
1995-03-17 11:47:29 +00:00
|
|
|
TRelation saldi(LF_SALDI);
|
1995-03-21 11:09:06 +00:00
|
|
|
saldi.zero();
|
|
|
|
|
1995-03-17 11:47:29 +00:00
|
|
|
|
1995-03-16 08:50:33 +00:00
|
|
|
while (m.run() != K_QUIT)
|
|
|
|
{
|
1995-03-21 11:09:06 +00:00
|
|
|
int n_part = 0;
|
|
|
|
TDate data(m.get(F_DATA));
|
|
|
|
TString16 codpag(m.get(F_CODPAG));
|
|
|
|
|
|
|
|
TPagamento pag(codpag, data.string());
|
|
|
|
|
|
|
|
m.set(F_NUMPART, format("%d",n_part));
|
|
|
|
_anno = m.get_int(F_ANNO);
|
|
|
|
|
|
|
|
saldi.lfile().zero();
|
|
|
|
saldi.lfile().put(SLD_ANNOES, _anno);
|
|
|
|
|
|
|
|
TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr());
|
|
|
|
const long items = cur.items();
|
|
|
|
long npart = 0L;
|
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
{
|
|
|
|
begin_wait();
|
|
|
|
int hw = 0;
|
|
|
|
for (cur = 0, hw = 0 ; cur.pos() < items; ++cur, hw++)
|
|
|
|
{
|
|
|
|
char cf;
|
|
|
|
int gruppo = cur.curr().get_int(SLD_GRUPPO);
|
|
|
|
int conto = cur.curr().get_int(SLD_CONTO);
|
|
|
|
long sottoc = cur.curr().get_long(SLD_SOTTOCONTO);
|
1995-03-17 11:47:29 +00:00
|
|
|
|
1995-03-21 11:09:06 +00:00
|
|
|
if (is_clifo(gruppo, conto, cf))
|
|
|
|
{
|
|
|
|
TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), cur.curr().get_real(SLD_SALDO));
|
|
|
|
TImporto pdare('D', cur.curr().get_real(SLD_PDARE));
|
|
|
|
TImporto pavere('A', cur.curr().get_real(SLD_PAVERE));
|
|
|
|
|
|
|
|
saldo += pdare;
|
|
|
|
saldo += pavere;
|
|
|
|
saldo.normalize();
|
|
|
|
|
|
|
|
if (!saldo.is_zero())
|
|
|
|
{
|
|
|
|
TString16 id;
|
|
|
|
real val(saldo.valore());
|
|
|
|
|
|
|
|
pag.set_total(val, ZERO, ZERO);
|
|
|
|
pag.set_rate_auto();
|
|
|
|
|
|
|
|
// determina ultima partita; la prima volta,
|
|
|
|
// se ce n'e' chiedi se si vuole cancellare
|
|
|
|
long last_partita = get_last_partita(hw == 0);
|
|
|
|
|
|
|
|
// apri partita dimmerda
|
|
|
|
id << format("AP%05ld", last_partita);
|
|
|
|
|
|
|
|
_partite->zero();
|
|
|
|
_partite->put(PART_ANNO, _anno);
|
|
|
|
_partite->put(PART_NUMPART, id);
|
|
|
|
_partite->put(PART_NUMRIG, 1);
|
|
|
|
_partite->put(PART_NRIGA, 1);
|
|
|
|
_partite->put(PART_DATAREG, data);
|
|
|
|
_partite->put(PART_DATADOC, data);
|
|
|
|
_partite->put(PART_SEZ, saldo.sezione());
|
|
|
|
_partite->put(PART_IMPORTO, saldo.valore());
|
|
|
|
_partite->put(PART_CODPAG, codpag);
|
|
|
|
_partite->put(PART_CODVAL, "LIT");
|
|
|
|
_partite->put(PART_TIPOCF, cf);
|
|
|
|
_partite->put(PART_GRUPPO, gruppo);
|
|
|
|
_partite->put(PART_CONTO, conto);
|
|
|
|
_partite->put(PART_SOTTOCONTO,sottoc);
|
|
|
|
_partite->put(PART_DESCR, "Apertura partite da saldi contabili");
|
|
|
|
_partite->write();
|
|
|
|
|
|
|
|
// apri scadenze dimmerda
|
|
|
|
for (int i = 0; i < pag.n_rate(); i++)
|
|
|
|
{
|
|
|
|
_scadenze->zero();
|
|
|
|
_scadenze->put(SCAD_ANNO, _anno);
|
|
|
|
_scadenze->put(SCAD_NUMPART, id);
|
|
|
|
_scadenze->put(SCAD_NRATA, i+1);
|
|
|
|
_scadenze->put(SCAD_CODPAG, codpag);
|
|
|
|
_scadenze->put(SCAD_ULTCLASS, pag.ulc_rata(i));
|
|
|
|
_scadenze->put(SCAD_TIPOPAG, pag.tipo_rata(i));
|
|
|
|
_scadenze->put(SCAD_IMPORTOVAL, pag.tpay_rata(i));
|
|
|
|
_scadenze->put(SCAD_DATASCAD, pag.data_rata(i));
|
|
|
|
_scadenze->put(SCAD_TIPOCF, cf);
|
|
|
|
_scadenze->put(SCAD_GRUPPO, gruppo);
|
|
|
|
_scadenze->put(SCAD_CONTO, conto);
|
|
|
|
_scadenze->put(SCAD_SOTTOCONTO, sottoc);
|
|
|
|
_scadenze->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
n_part++;
|
|
|
|
m.set(F_NUMPART, format("%d",n_part));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end_wait();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
message_box("Nessun saldo presente per l'anno %d", _anno);
|
|
|
|
} // while run
|
|
|
|
|
1995-03-14 11:12:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sc1200(int argc, char** argv)
|
|
|
|
{
|
|
|
|
TCreatepart_app a;
|
1995-03-16 08:50:33 +00:00
|
|
|
a.run(argc, argv, "Apertura scadenze da saldi contabili");
|
1995-03-14 11:12:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|