1995-10-25 09:46:13 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <urldefid.h>
|
|
|
|
#include <saldi.h>
|
|
|
|
#include <pconti.h>
|
|
|
|
#include <partite.h>
|
|
|
|
#include <scadenze.h>
|
|
|
|
#include <pagsca.h>
|
|
|
|
#include <lffiles.h>
|
|
|
|
#include <relation.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include "../cg/conto.h"
|
|
|
|
#include "../cg/pagament.h"
|
|
|
|
#include "../cg/cglib.h"
|
|
|
|
|
|
|
|
#include "sc1200.h"
|
|
|
|
|
|
|
|
class TCreatepart_app : public TApplication
|
|
|
|
{
|
|
|
|
TLocalisamfile* _conti;
|
|
|
|
TLocalisamfile* _partite;
|
|
|
|
TLocalisamfile* _scadenze;
|
|
|
|
TLocalisamfile* _pagsca;
|
|
|
|
|
|
|
|
int _anno;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
|
|
|
virtual bool menu(MENU_TAG m);
|
|
|
|
|
|
|
|
bool zap_partite();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
int is_clifo(int g, int c, char& cf, int& indbil);
|
|
|
|
TCreatepart_app() {}
|
|
|
|
virtual ~TCreatepart_app() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool TCreatepart_app::create()
|
|
|
|
{
|
|
|
|
TApplication::create();
|
|
|
|
|
|
|
|
_conti = new TLocalisamfile(LF_PCON);
|
|
|
|
_partite = new TLocalisamfile(LF_PARTITE);
|
|
|
|
_scadenze = new TLocalisamfile(LF_SCADENZE);
|
|
|
|
_pagsca = new TLocalisamfile(LF_PAGSCA);
|
|
|
|
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCreatepart_app::destroy()
|
|
|
|
{
|
|
|
|
delete _conti;
|
|
|
|
delete _partite;
|
|
|
|
delete _scadenze;
|
|
|
|
delete _pagsca;
|
|
|
|
|
|
|
|
return TApplication::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TCreatepart_app::zap_partite()
|
|
|
|
{
|
|
|
|
bool first = TRUE;
|
|
|
|
for (_partite->first(); !_partite->eof(); _partite->next())
|
|
|
|
{
|
|
|
|
// ignora saldaconto altri esercizi
|
|
|
|
if (_partite->get_long(PART_ANNO) != _anno)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
bool ok = yesno_box("Il saldaconto per l'esercizio scelto non e' vuoto."
|
|
|
|
" La procedura lo azzera completamente."
|
|
|
|
" Si desidera proseguire?");
|
|
|
|
if (ok)
|
|
|
|
ok = yesno_box("Confermare l'azzeramento del saldaconto esistente");
|
|
|
|
if (!ok) return FALSE;
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gos = TRUE;
|
|
|
|
bool goi = TRUE;
|
|
|
|
|
|
|
|
for (int i = 1; gos || goi ; i++)
|
|
|
|
{
|
|
|
|
// zappa scadenze
|
|
|
|
if (gos)
|
|
|
|
{
|
|
|
|
_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 (gos = (_scadenze->read() == NOERR))
|
|
|
|
_scadenze->remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// zappa pagamenti
|
|
|
|
if (goi)
|
|
|
|
{
|
|
|
|
_pagsca->zero();
|
|
|
|
_pagsca->put(PAGSCA_ANNO, _partite->get(PART_ANNO));
|
|
|
|
_pagsca->put(PAGSCA_NUMPART, _partite->get(PART_NUMPART));
|
|
|
|
_pagsca->put(PAGSCA_NRIGP, i+1);
|
|
|
|
|
|
|
|
if (goi = (_pagsca->read() == NOERR))
|
|
|
|
_pagsca->remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_partite->remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TCreatepart_app::is_clifo(int g, int c, char& cf, int& indbil)
|
|
|
|
{
|
|
|
|
// deve ritornare QUANTI sono i conti in cui appare lo stesso
|
|
|
|
// cliente; se piu' di uno deve creare n rate, una per cliente
|
|
|
|
|
|
|
|
_conti->zero();
|
|
|
|
_conti->put(PCN_GRUPPO, g);
|
|
|
|
_conti->put(PCN_CONTO, c);
|
|
|
|
if (_conti->read() != NOERR)
|
|
|
|
{
|
|
|
|
warning_box("Piano dei conti disallineato con archivio saldi: esecuzione interrotta");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_conti->get(PCN_TMCF).empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cf = _conti->get_char(PCN_TMCF);
|
|
|
|
indbil = _conti->get_int(PCN_INDBIL);
|
|
|
|
long cl = _conti->get_long(PCN_SOTTOCONTO);
|
|
|
|
|
|
|
|
// cerca tutti i conti in cui compare lo stesso cliente o
|
|
|
|
// fornitore
|
|
|
|
int ncli = 0;
|
|
|
|
|
|
|
|
for (_conti->first(); !_conti->eof(); _conti->next())
|
|
|
|
{
|
|
|
|
if (_conti->get_char(PCN_TMCF) == cf &&
|
|
|
|
_conti->get_long(PCN_SOTTOCONTO) == cl)
|
|
|
|
ncli++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ncli;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TCreatepart_app::menu(MENU_TAG)
|
|
|
|
{
|
|
|
|
TMask m("sc1200a");
|
|
|
|
TRelation saldi(LF_SALDI);
|
|
|
|
saldi.zero();
|
|
|
|
|
|
|
|
TDate today(TODAY);
|
|
|
|
TString80 desccl = "Apertura clienti al "; desccl << today.string();
|
|
|
|
TString80 descfo = "Apertura fornitori al "; descfo << today.string();
|
|
|
|
|
|
|
|
m.set(F_DESCCL, desccl);
|
|
|
|
m.set(F_DESCFO, descfo);
|
|
|
|
|
|
|
|
while (m.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
_anno = m.get_int(F_ANNO);
|
|
|
|
desccl = m.get(F_DESCCL);
|
|
|
|
descfo = m.get(F_DESCFO);
|
|
|
|
int n_part = 0;
|
|
|
|
m.set(F_NUMPART, n_part);
|
|
|
|
|
|
|
|
// sputtana tutto il saldaculo
|
|
|
|
if (!zap_partite()) break;
|
|
|
|
|
|
|
|
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;
|
|
|
|
// determina ultima partita; la prima volta,
|
|
|
|
// se ce n'e' chiedi se si vuole cancellare
|
|
|
|
long last_partita = 1l;
|
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
{
|
|
|
|
begin_wait();
|
|
|
|
|
|
|
|
TProgind prind(items, "Creazione saldaconto", FALSE, TRUE,45);
|
|
|
|
|
|
|
|
int hw = 0;
|
|
|
|
for (cur = 0, hw = 0 ; cur.pos() < items; ++cur, hw++)
|
|
|
|
{
|
|
|
|
char cf; int nclienti;
|
|
|
|
int gruppo = cur.curr().get_int(SLD_GRUPPO);
|
|
|
|
int conto = cur.curr().get_int(SLD_CONTO);
|
|
|
|
long sottoc = cur.curr().get_long(SLD_SOTTOCONTO);
|
|
|
|
|
|
|
|
int indbil;
|
|
|
|
|
|
|
|
nclienti = is_clifo(gruppo, conto, cf, indbil);
|
|
|
|
if (nclienti > 0)
|
|
|
|
{
|
|
|
|
TSaldo sld;
|
|
|
|
|
|
|
|
// ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente
|
|
|
|
if (!sld.ultima_immissione_verifica(_anno, gruppo, conto, sottoc, indbil, 1))
|
|
|
|
{
|
|
|
|
// non movimentato: se e' conto patrimoniale....
|
|
|
|
if (!(indbil == 1 || indbil == 2 || indbil == 5))
|
|
|
|
{
|
|
|
|
prind.addstatus(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// .. vedi saldo esercizio precedente, altrimenti inkul
|
|
|
|
sld.saldofin_esprec(_anno, gruppo, conto, sottoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// genera importo con sezione appropriata
|
|
|
|
TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), sld.saldoini());
|
|
|
|
TImporto pdare('D', sld.prgdare());
|
|
|
|
TImporto pavere('A', sld.prgavere());
|
|
|
|
|
|
|
|
saldo += pdare;
|
|
|
|
saldo += pavere;
|
|
|
|
saldo.normalize();
|
|
|
|
|
|
|
|
// (whew)
|
|
|
|
|
|
|
|
if (!saldo.is_zero())
|
|
|
|
{
|
|
|
|
TString16 id;
|
|
|
|
real val(saldo.valore());
|
|
|
|
|
|
|
|
// TPagamento pag(codpag, today.string());
|
|
|
|
// pag.set_total(val, ZERO, ZERO);
|
|
|
|
// pag.set_rate_auto();
|
|
|
|
|
|
|
|
// apri partita dimmerda
|
|
|
|
id << format("*%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, today);
|
|
|
|
_partite->put(PART_DATADOC, today);
|
|
|
|
_partite->put(PART_SEZ, saldo.sezione());
|
|
|
|
_partite->put(PART_IMPORTO, saldo.valore());
|
|
|
|
_partite->put(PART_CODVAL, "LIT");
|
|
|
|
_partite->put(PART_TIPOCF, cf);
|
|
|
|
_partite->put(PART_GRUPPOCL, gruppo);
|
|
|
|
_partite->put(PART_CONTOCL, conto);
|
|
|
|
_partite->put(PART_SOTTOCONTO,sottoc);
|
|
|
|
_partite->put(PART_DESCR, cf == 'C' ? desccl : descfo);
|
|
|
|
|
|
|
|
// _partite->put(PART_CODPAG, codpag);
|
|
|
|
|
|
|
|
// cazzata dare/avere/fare/baciare/cagare
|
|
|
|
int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 3) :
|
|
|
|
(saldo.sezione() == 'D' ? 3 : 1));
|
|
|
|
|
|
|
|
_partite->put(PART_TIPOMOV, tipo);
|
|
|
|
_partite->write();
|
|
|
|
|
|
|
|
if (tipo == 1)
|
|
|
|
{
|
|
|
|
// apri scadenze dimmerda: tante quanti clienti ci sono
|
|
|
|
for (int i = 0; i < nclienti; i++)
|
|
|
|
{
|
|
|
|
_scadenze->zero();
|
|
|
|
_scadenze->put(SCAD_ANNO, _anno);
|
|
|
|
_scadenze->put(SCAD_NUMPART, id);
|
|
|
|
_scadenze->put(SCAD_NRATA, i+1);
|
|
|
|
_scadenze->put(SCAD_IMPORTO, val/real((double)nclienti));
|
|
|
|
_scadenze->put(SCAD_TIPOCF, cf);
|
|
|
|
_scadenze->put(SCAD_SOTTOCONTO, sottoc);
|
|
|
|
|
|
|
|
// oldies and goldies
|
|
|
|
// not removed, you know why
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// _scadenze->put(SCAD_CODPAG, codpag);
|
|
|
|
// _scadenze->put(SCAD_ULTCLASS, pag.ulc_rata(i));
|
|
|
|
// _scadenze->put(SCAD_TIPOPAG, pag.tipo_rata(i));
|
|
|
|
// _scadenze->put(SCAD_DATASCAD, pag.data_rata(i));
|
|
|
|
// _scadenze->put(SCAD_GRUPPO, gruppo);
|
|
|
|
// _scadenze->put(SCAD_CONTO, conto);
|
|
|
|
|
|
|
|
_scadenze->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// apri insoluto
|
|
|
|
for (int i = 0; i < nclienti; i++)
|
|
|
|
{
|
|
|
|
_pagsca->zero();
|
|
|
|
_pagsca->put(PAGSCA_ANNO, _anno);
|
|
|
|
_pagsca->put(PAGSCA_NUMPART, id);
|
|
|
|
_pagsca->put(PAGSCA_NRIGP, i+1);
|
|
|
|
_pagsca->put(PAGSCA_IMPORTO, val/real((double)nclienti));
|
|
|
|
_pagsca->put(PAGSCA_TIPOC, cf);
|
|
|
|
_pagsca->put(PAGSCA_SOTTOCONTO, sottoc);
|
|
|
|
_pagsca->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n_part++;
|
|
|
|
m.set(F_NUMPART, format("%d",n_part));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prind.addstatus(1);
|
|
|
|
}
|
|
|
|
end_wait();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
message_box("Nessun saldo presente per l'esercizio %d", _anno);
|
|
|
|
} // while run
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sc1200(int argc, char** argv)
|
|
|
|
{
|
|
|
|
TCreatepart_app a;
|
|
|
|
a.run(argc, argv, "Apertura scadenze da saldi contabili");
|
|
|
|
return 0;
|
|
|
|
}
|