1995-10-30 10:20:10 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <relation.h>
|
|
|
|
|
1997-06-19 15:19:46 +00:00
|
|
|
#include "../cg/cglib02.h"
|
1997-06-20 08:53:29 +00:00
|
|
|
#include "../cg/cgsaldac.h"
|
1995-10-30 10:20:10 +00:00
|
|
|
|
|
|
|
#include "sc1200.h"
|
|
|
|
|
1997-06-20 08:53:29 +00:00
|
|
|
#include <saldi.h>
|
|
|
|
#include <pconti.h>
|
|
|
|
|
|
|
|
|
2003-04-10 14:19:30 +00:00
|
|
|
class TCreatepart_app : public TSkeleton_application
|
1995-10-30 10:20:10 +00:00
|
|
|
{
|
1995-11-17 10:30:04 +00:00
|
|
|
TEsercizi_contabili _esc;
|
1995-11-07 10:07:04 +00:00
|
|
|
bool _num_cli, _num_for;
|
1995-11-17 10:30:04 +00:00
|
|
|
TString _desccl, _descfo;
|
|
|
|
TDate _today;
|
2003-05-14 14:15:09 +00:00
|
|
|
|
1995-11-07 10:07:04 +00:00
|
|
|
protected: // Applicat
|
|
|
|
virtual void on_config_change();
|
1995-10-30 10:20:10 +00:00
|
|
|
|
|
|
|
virtual bool create();
|
2003-04-10 14:19:30 +00:00
|
|
|
virtual void main_loop();
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
protected:
|
1997-05-06 12:51:33 +00:00
|
|
|
static bool data_handler(TMask_field& f, KEY key);
|
|
|
|
|
2003-05-14 14:15:09 +00:00
|
|
|
bool is_full(int logicnum) const;
|
1995-12-04 11:06:42 +00:00
|
|
|
void zap_file(int logicnum) const;
|
|
|
|
bool zap_partite() const;
|
1996-06-28 09:41:00 +00:00
|
|
|
int crea_partite(int anno_es, int anno_rif, int next_anno_es);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
|
|
|
public:
|
1995-12-22 09:07:56 +00:00
|
|
|
char is_clifo(int g, int c, long s, int& indbil);
|
1995-11-17 10:30:04 +00:00
|
|
|
TCreatepart_app() : _today(TODAY) {}
|
1995-10-30 10:20:10 +00:00
|
|
|
virtual ~TCreatepart_app() {}
|
|
|
|
};
|
|
|
|
|
1997-05-06 12:51:33 +00:00
|
|
|
inline TCreatepart_app& app() { return (TCreatepart_app&)main_app(); }
|
1995-10-30 10:20:10 +00:00
|
|
|
|
|
|
|
bool TCreatepart_app::create()
|
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
open_files(LF_TABCOM, LF_TAB, LF_PCON, LF_SALDI, LF_PARTITE, LF_PAGSCA, LF_SCADENZE, 0);
|
1995-12-04 11:06:42 +00:00
|
|
|
|
2003-04-10 14:19:30 +00:00
|
|
|
return TSkeleton_application::create();
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 10:07:04 +00:00
|
|
|
void TCreatepart_app::on_config_change()
|
|
|
|
{
|
1995-11-09 08:09:09 +00:00
|
|
|
TConfig cd(CONFIG_DITTA, "cg");
|
1995-11-07 10:07:04 +00:00
|
|
|
_num_cli = cd.get_bool("NrCliDx");
|
|
|
|
_num_for = cd.get_bool("NrForDx");
|
1995-11-10 13:38:29 +00:00
|
|
|
TPartita::carica_allineamento();
|
1995-11-07 10:07:04 +00:00
|
|
|
}
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1997-05-06 12:51:33 +00:00
|
|
|
bool TCreatepart_app::data_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
|
|
TMask& m = f.mask();
|
|
|
|
|
|
|
|
bool ok = TRUE;
|
|
|
|
if ((key == K_TAB && (f.focusdirty() || !m.is_running())) ||
|
|
|
|
key == K_ENTER)
|
|
|
|
{
|
|
|
|
const int anno = m.get_int(F_ANNO);
|
|
|
|
const TDate oggi(f.get());
|
|
|
|
if (app()._esc.date2esc(oggi) != anno)
|
2003-04-10 14:19:30 +00:00
|
|
|
ok = f.error_box(FR("La data non appartiene all'esercizio %d"), anno);
|
1997-05-06 12:51:33 +00:00
|
|
|
|
|
|
|
if (ok && key == K_TAB)
|
|
|
|
{
|
|
|
|
TString desc(50);
|
|
|
|
TEdit_field& dc = m.efield(F_DESCCL);
|
|
|
|
if (dc.empty() || !dc.dirty())
|
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
desc = TR("Apertura clienti al "); desc << oggi;
|
1997-05-06 12:51:33 +00:00
|
|
|
dc.set(desc);
|
|
|
|
dc.set_dirty(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEdit_field& df = m.efield(F_DESCFO);
|
|
|
|
if (df.empty() || !df.dirty())
|
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
desc = TR("Apertura fornitori al "); desc << oggi;
|
1997-05-06 12:51:33 +00:00
|
|
|
df.set(desc);
|
|
|
|
df.set_dirty(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1995-12-04 11:06:42 +00:00
|
|
|
void TCreatepart_app::zap_file(int logicnum) const
|
|
|
|
{
|
|
|
|
TSystemisamfile f(logicnum);
|
2003-05-14 14:15:09 +00:00
|
|
|
f.zap();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCreatepart_app::is_full(int logicnum) const
|
|
|
|
{
|
|
|
|
TLocalisamfile f(logicnum);
|
|
|
|
const int err = f.last();
|
|
|
|
return err == NOERR;
|
1995-12-04 11:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TCreatepart_app::zap_partite() const
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
|
2003-05-14 14:15:09 +00:00
|
|
|
bool zap = is_full(LF_PARTITE);
|
1995-12-04 11:06:42 +00:00
|
|
|
if (zap)
|
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
zap = yesno_box(TR("Il saldaconto non e' vuoto.\n"
|
1995-12-04 11:06:42 +00:00
|
|
|
"La procedura lo azzera completamente.\n"
|
2003-04-10 14:19:30 +00:00
|
|
|
"Si desidera proseguire?"));
|
1995-12-04 11:06:42 +00:00
|
|
|
if (zap)
|
2003-04-10 14:19:30 +00:00
|
|
|
zap = yesno_box(TR("Confermare l'azzeramento del saldaconto esistente"));
|
1995-12-04 11:06:42 +00:00
|
|
|
|
|
|
|
if (zap)
|
1995-10-30 10:20:10 +00:00
|
|
|
{
|
1995-12-04 11:06:42 +00:00
|
|
|
zap_file(LF_PARTITE);
|
|
|
|
zap_file(LF_SCADENZE);
|
|
|
|
zap_file(LF_PAGSCA);
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
1995-12-04 11:06:42 +00:00
|
|
|
else
|
|
|
|
ok = FALSE;
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
|
|
|
|
1995-12-04 11:06:42 +00:00
|
|
|
return ok;
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-12-22 09:07:56 +00:00
|
|
|
char TCreatepart_app::is_clifo(int g, int c, long s, int& indbil)
|
1995-10-30 10:20:10 +00:00
|
|
|
{
|
2003-05-14 14:15:09 +00:00
|
|
|
TString16 key;
|
|
|
|
key.format("%d|%d|0", g, c);
|
|
|
|
const TRectype& conti = cache().get(LF_PCON, key);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
2003-04-10 14:19:30 +00:00
|
|
|
if (conti.empty())
|
1995-10-30 10:20:10 +00:00
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
warning_box(FR("Archivio saldi disallineato con il piano dei conti\n record saldi non elaborato : gruppo %d conto %d sottoconto %ld"), g, c, s);
|
1995-10-30 10:20:10 +00:00
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
|
2003-04-10 14:19:30 +00:00
|
|
|
const char cf = conti.get_char(PCN_TMCF);
|
|
|
|
indbil = conti.get_int(PCN_INDBIL);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
|
|
|
return cf;
|
|
|
|
}
|
|
|
|
|
1996-06-28 09:41:00 +00:00
|
|
|
int TCreatepart_app::crea_partite(int anno_es, int anno_rif, int next_anno_es)
|
1995-11-17 10:30:04 +00:00
|
|
|
{
|
1997-05-06 12:51:33 +00:00
|
|
|
TWait_cursor hourglass;
|
|
|
|
|
1996-06-28 09:41:00 +00:00
|
|
|
const bool check = anno_es != next_anno_es;
|
|
|
|
TRelation saldi(LF_SALDI);
|
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
saldi.curr().put(SLD_ANNOES, anno_es);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr());
|
|
|
|
const long items = cur.items();
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
if (items == 0)
|
1996-06-28 09:41:00 +00:00
|
|
|
return 0;
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-12-04 11:06:42 +00:00
|
|
|
// Apre i files per usarli con l'oggetto TPartita
|
|
|
|
TLocalisamfile partite(LF_PARTITE);
|
|
|
|
TLocalisamfile scadenze(LF_SCADENZE);
|
|
|
|
TLocalisamfile pagamenti(LF_PAGSCA);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
int n_part = 0;
|
2003-04-10 14:19:30 +00:00
|
|
|
TProgind prind(items, TR("Creazione saldaconto"), FALSE, TRUE, 45);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
for (cur = 0; cur.pos() < items; ++cur)
|
|
|
|
{
|
1995-12-01 11:49:57 +00:00
|
|
|
const int gruppo = cur.curr().get_int(SLD_GRUPPO);
|
|
|
|
const int conto = cur.curr().get_int(SLD_CONTO);
|
1995-11-17 10:30:04 +00:00
|
|
|
const long sottoc = cur.curr().get_long(SLD_SOTTOCONTO);
|
|
|
|
int indbil;
|
1995-12-22 09:07:56 +00:00
|
|
|
const char cf = is_clifo(gruppo, conto, sottoc, indbil);
|
1996-06-28 09:41:00 +00:00
|
|
|
if (check)
|
|
|
|
{
|
|
|
|
TLocalisamfile work_saldi(LF_SALDI);
|
|
|
|
work_saldi.zero();
|
|
|
|
work_saldi.put(SLD_GRUPPO, gruppo);
|
|
|
|
work_saldi.put(SLD_CONTO, conto);
|
|
|
|
work_saldi.put(SLD_SOTTOCONTO, sottoc);
|
|
|
|
work_saldi.put(SLD_ANNOES, next_anno_es);
|
|
|
|
work_saldi.put(SLD_FLSCA, "");
|
|
|
|
if (work_saldi.read() == NOERR)
|
|
|
|
continue;
|
|
|
|
}
|
1995-11-17 10:30:04 +00:00
|
|
|
if (cf > ' ')
|
|
|
|
{
|
|
|
|
TSaldo sld;
|
1996-05-30 13:53:45 +00:00
|
|
|
real s;
|
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
// ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente
|
|
|
|
if (!sld.ultima_immissione_verifica(anno_es, 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
|
1996-05-30 13:53:45 +00:00
|
|
|
s = sld.saldofin_esprec(anno_es, gruppo, conto, sottoc);
|
1995-11-17 10:30:04 +00:00
|
|
|
}
|
1996-05-30 13:53:45 +00:00
|
|
|
else
|
|
|
|
s = sld.saldo();
|
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
// genera importo con sezione appropriata
|
1996-05-30 13:53:45 +00:00
|
|
|
TImporto saldo('D', s);
|
|
|
|
saldo.normalize(); // Non togliere, serve per stabilire fattura/nota credito
|
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
if (!saldo.is_zero())
|
|
|
|
{
|
|
|
|
const TBill clifo(gruppo, conto, sottoc, cf);
|
|
|
|
TString16 numero("*");
|
|
|
|
if ((cf == 'C' && _num_cli) || (cf == 'F' && _num_for))
|
|
|
|
numero.right_just(7);
|
|
|
|
|
|
|
|
TPartita game(clifo, anno_rif, numero);
|
|
|
|
TRiga_partite& riga = game.new_row();
|
2003-04-10 14:19:30 +00:00
|
|
|
|
1996-02-26 13:49:27 +00:00
|
|
|
riga.put(PART_DATAREG, _today);
|
|
|
|
riga.put(PART_DATADOC, _today);
|
|
|
|
riga.put(PART_SEZ, saldo.sezione());
|
|
|
|
riga.put(PART_IMPORTO, saldo.valore());
|
|
|
|
riga.put(PART_IMPTOTDOC,saldo.valore());
|
1995-11-17 10:30:04 +00:00
|
|
|
riga.put(PART_DESCR, cf == 'C' ? _desccl : _descfo);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-11-17 10:30:04 +00:00
|
|
|
// cazzata dare/avere/fare/baciare/cagare
|
1996-02-26 13:49:27 +00:00
|
|
|
const tipo_movimento tipo = (cf == 'C') ^ (saldo.sezione() == 'A') ?
|
|
|
|
tm_fattura : tm_nota_credito;
|
1995-12-04 11:06:42 +00:00
|
|
|
riga.put(PART_TIPOMOV, (int)tipo);
|
1995-10-30 10:20:10 +00:00
|
|
|
|
1995-12-04 11:06:42 +00:00
|
|
|
if (tipo == tm_fattura)
|
1995-11-17 10:30:04 +00:00
|
|
|
{
|
|
|
|
TRiga_scadenze& scad = riga.new_row();
|
|
|
|
scad.put(SCAD_IMPORTO, saldo.valore());
|
|
|
|
scad.put(SCAD_DATASCAD, _today);
|
1995-12-04 11:06:42 +00:00
|
|
|
scad.put(SCAD_TIPOPAG, 1); // rimessa diretta
|
1995-11-17 10:30:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1995-12-18 10:57:32 +00:00
|
|
|
riga.put(PART_DATAPAG, _today);
|
1995-11-17 10:30:04 +00:00
|
|
|
const int r = riga.get_int(PART_NRIGA);
|
|
|
|
TRectype& unas = game.unassigned().row(r, TRUE);
|
|
|
|
unas.put(PAGSCA_IMPORTO, saldo.valore());
|
|
|
|
unas.put(PAGSCA_ACCSAL, 'A');
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
1995-11-17 10:30:04 +00:00
|
|
|
|
|
|
|
if (game.write())
|
|
|
|
n_part++;
|
|
|
|
else
|
|
|
|
{
|
2003-04-10 14:19:30 +00:00
|
|
|
error_box(FR("Impossibile scrivere la partita %d %s"),
|
1995-12-01 11:49:57 +00:00
|
|
|
anno_rif, (const char *)numero);
|
1995-11-17 10:30:04 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-10-30 10:20:10 +00:00
|
|
|
}
|
1995-11-17 10:30:04 +00:00
|
|
|
}
|
|
|
|
prind.addstatus(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_part;
|
|
|
|
}
|
|
|
|
|
2003-04-10 14:19:30 +00:00
|
|
|
void TCreatepart_app::main_loop()
|
1995-11-17 10:30:04 +00:00
|
|
|
{
|
|
|
|
TMask m("sc1200a");
|
1997-05-06 12:51:33 +00:00
|
|
|
m.set_handler(F_DATA, data_handler);
|
1995-11-17 10:30:04 +00:00
|
|
|
|
1997-05-06 12:51:33 +00:00
|
|
|
int anno_es = _esc.last();
|
2003-05-14 14:15:09 +00:00
|
|
|
|
1997-05-06 12:51:33 +00:00
|
|
|
m.set(F_ANNO, anno_es);
|
|
|
|
if (_esc.date2esc(_today) != anno_es)
|
|
|
|
_today = _esc[anno_es].inizio();
|
|
|
|
m.set(F_DATA, _today);
|
1995-11-17 10:30:04 +00:00
|
|
|
|
|
|
|
while (m.run() == K_ENTER)
|
|
|
|
{
|
1997-05-06 12:51:33 +00:00
|
|
|
anno_es = m.get_int(F_ANNO);
|
|
|
|
_today = m.get(F_DATA);
|
1995-11-17 10:30:04 +00:00
|
|
|
_desccl = m.get(F_DESCCL);
|
|
|
|
_descfo = m.get(F_DESCFO);
|
|
|
|
|
|
|
|
if (!zap_partite())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const TEsercizio& selected_es = _esc.esercizio(anno_es);
|
|
|
|
const int anno_rif = selected_es.inizio().year();
|
1996-06-28 09:41:00 +00:00
|
|
|
int n_part = crea_partite(anno_es, anno_rif, selected_es.codice());
|
|
|
|
|
|
|
|
const int pred_es = _esc.pred(anno_es);
|
|
|
|
if (pred_es > 0)
|
|
|
|
{
|
|
|
|
const int p = crea_partite(pred_es, anno_rif, selected_es.codice());
|
|
|
|
if (p > 0) n_part += p;
|
|
|
|
}
|
1995-11-17 10:30:04 +00:00
|
|
|
|
1995-12-18 10:57:32 +00:00
|
|
|
if (n_part > 0)
|
|
|
|
{
|
|
|
|
TString msg(80);
|
2003-04-10 14:19:30 +00:00
|
|
|
msg << TR("Sono state create ") << n_part << TR(" partite");
|
1995-12-18 10:57:32 +00:00
|
|
|
message_box(msg);
|
|
|
|
break;
|
|
|
|
}
|
1995-10-30 10:20:10 +00:00
|
|
|
} // while run
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sc1200(int argc, char** argv)
|
|
|
|
{
|
|
|
|
TCreatepart_app a;
|
2003-04-10 14:19:30 +00:00
|
|
|
a.run(argc, argv, TR("Apertura scadenze da saldi"));
|
1995-10-30 10:20:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|