d355c40138
git-svn-id: svn://10.65.10.50/trunk@12018 c028cbd2-c16b-5b4b-a496-9718f37d4682
527 lines
13 KiB
C++
Executable File
527 lines
13 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <defmask.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <sheet.h>
|
|
|
|
#include "cgsaldac.h"
|
|
|
|
#include <clifo.h>
|
|
#include <mov.h>
|
|
#include <nditte.h>
|
|
#include <pconti.h>
|
|
#include <rmov.h>
|
|
#include <rmoviva.h>
|
|
|
|
#ifndef FOR_EACH_FILE_RECORD
|
|
|
|
#define FOR_EACH_FILE_RECORD(isamfile) \
|
|
for (int _e##isamfile = isamfile.first(); \
|
|
_e##isamfile == NOERR; \
|
|
_e##isamfile = isamfile.next())
|
|
|
|
#endif
|
|
|
|
class TElimina_zoppi : public TSkeleton_application
|
|
{
|
|
// TArray _files;
|
|
TArray _decoders;
|
|
|
|
protected:
|
|
static bool test_row_file(int rmov, TString_array& arr);
|
|
static bool test_scrow_file(int rmov, TString_array& arr);
|
|
static bool test_head_file(TString_array& arr);
|
|
|
|
static int kill_game(long numreg, int numrig);
|
|
static int kill_pagsca(long recno, int lfile);
|
|
static int kill_row(long numreg, char tipor, int numrig);
|
|
|
|
static bool firm_handler(TMask_field& f, KEY k);
|
|
static bool select_handler(TMask_field& f, KEY k);
|
|
|
|
public:
|
|
const char* app_name() const {return TR("Righe prima nota errate");}
|
|
const char* decode(int num, const char* key, const char* field);
|
|
virtual void main_loop();
|
|
};
|
|
|
|
inline TElimina_zoppi& app() { return (TElimina_zoppi&)main_app(); }
|
|
|
|
bool TElimina_zoppi::firm_handler(TMask_field& f, KEY k)
|
|
{
|
|
bool ok = TRUE;
|
|
if (k == K_F9)
|
|
{
|
|
TArray_sheet sheet(-1, -1, 70, 20, TR("Scelta ditta"), HR("Codice|Ragione Sociale@50"));
|
|
TToken_string row;
|
|
TLocalisamfile ditte(LF_NDITTE);
|
|
|
|
FOR_EACH_FILE_RECORD(ditte)
|
|
{
|
|
const long cod = ditte.get_long(NDT_CODDITTA);
|
|
if (prefix().exist(cod))
|
|
{
|
|
row.cut(0);
|
|
row.add(cod);
|
|
row.add(ditte.get(NDT_RAGSOC));
|
|
|
|
const long pos = sheet.add(row);
|
|
if (cod == prefix().get_codditta())
|
|
sheet.select(pos);
|
|
}
|
|
}
|
|
if (sheet.run() == K_ENTER)
|
|
{
|
|
f.set(sheet.row().get(0));
|
|
k = K_TAB;
|
|
}
|
|
}
|
|
if (k == K_ENTER || k == K_TAB && f.focusdirty())
|
|
{
|
|
long cod = atol(f.get());
|
|
ok = prefix().exist(cod);
|
|
if (ok)
|
|
prefix().set_codditta(cod);
|
|
else
|
|
f.error_box(FR("La ditta %05ld non e' attivata per la contabilita'"), cod);
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
const char* TElimina_zoppi::decode(int num, const char* key, const char* field)
|
|
{
|
|
TDecoder* dec = (TDecoder*)_decoders.objptr(num);
|
|
if (dec == NULL)
|
|
{
|
|
dec = new TDecoder(num, field);
|
|
_decoders.add(dec);
|
|
}
|
|
return dec->decode(key);
|
|
}
|
|
|
|
bool TElimina_zoppi::test_row_file(int lf_rmov, TString_array& arr)
|
|
{
|
|
bool ok = TRUE;
|
|
TLocalisamfile mov(LF_MOV);
|
|
TLocalisamfile row(lf_rmov);
|
|
|
|
TString msg;
|
|
switch (lf_rmov)
|
|
{
|
|
case LF_RMOV : msg = TR("Controllo righe contabili"); break;
|
|
case LF_RMOVIVA: msg = TR("Controllo righe iva"); break;
|
|
case LF_PARTITE: msg = TR("Controllo righe saldaconto"); break;
|
|
default: CHECKD(0, "Invalid row file %d", lf_rmov); break;
|
|
}
|
|
msg << ": 0";
|
|
|
|
TProgind pi(row.items(), msg, TRUE, TRUE);
|
|
TToken_string riga, descr;
|
|
|
|
long reg, last_reg = 0, found = 0;
|
|
bool reg_killed = FALSE;
|
|
|
|
char tipo;
|
|
int gruppo, conto;
|
|
long sottoconto;
|
|
|
|
FOR_EACH_FILE_RECORD(row)
|
|
{
|
|
if (pi.iscancelled())
|
|
{
|
|
ok = FALSE;
|
|
break;
|
|
}
|
|
pi.addstatus(1);
|
|
|
|
if (lf_rmov == LF_PARTITE)
|
|
reg = row.get_long(PART_NREG);
|
|
else
|
|
reg = row.get_long(MOV_NUMREG);
|
|
|
|
if (reg != last_reg)
|
|
{
|
|
if (reg > 0)
|
|
{
|
|
mov.put(MOV_NUMREG, reg);
|
|
reg_killed = mov.read() != NOERR;
|
|
}
|
|
else
|
|
reg_killed = lf_rmov != LF_PARTITE;
|
|
last_reg = reg;
|
|
}
|
|
if (reg_killed)
|
|
{
|
|
found++;
|
|
const int colon = msg.find(':');
|
|
msg.cut(colon+2);
|
|
msg << found;
|
|
pi.set_text(msg);
|
|
|
|
switch (lf_rmov)
|
|
{
|
|
case LF_RMOV :
|
|
riga.format(" |%6ld|C%4d", reg, row.get_int(RMV_NUMRIG));
|
|
riga.add(row.get(RMV_ANNOES));
|
|
riga.add(row.get_real(RMV_IMPORTO).string("."));
|
|
riga << ' ' << row.get(RMV_SEZIONE);
|
|
break;
|
|
case LF_RMOVIVA:
|
|
riga.format(" |%6ld|I%4d", reg, row.get_int(RMI_NUMRIG));
|
|
riga.add(row.get(RMI_ANNOES));
|
|
riga.add(row.get_real(RMI_IMPONIBILE).string("."));
|
|
riga << " ";
|
|
break;
|
|
case LF_PARTITE:
|
|
riga.format(" |%6ld|P%4d", reg, row.get_int(PART_NRIGA));
|
|
riga.add(row.get(PART_ANNO));
|
|
riga.add(row.get_real(PART_IMPORTO).string("."));
|
|
riga << ' ' << row.get(PART_SEZ);
|
|
break;
|
|
default: CHECKD(0, "Invalid row file %d", lf_rmov); break;
|
|
};
|
|
|
|
descr.cut(0);
|
|
if (lf_rmov == LF_PARTITE)
|
|
{
|
|
tipo = row.get_char(PART_TIPOCF);
|
|
gruppo = row.get_int(PART_GRUPPOCL);
|
|
conto = row.get_int(PART_CONTOCL);
|
|
sottoconto = row.get_long(PART_SOTTOCONTO);
|
|
descr = row.get(PART_DESCR);
|
|
}
|
|
else
|
|
{
|
|
tipo = row.get_char(RMV_TIPOC);
|
|
gruppo = row.get_int(RMV_GRUPPO);
|
|
conto = row.get_int(RMV_CONTO);
|
|
sottoconto = row.get_long(RMV_SOTTOCONTO);
|
|
if (lf_rmov == LF_RMOV)
|
|
descr = row.get(PART_DESCR);
|
|
}
|
|
riga.add(gruppo);
|
|
riga.add(conto);
|
|
riga.add(sottoconto);
|
|
|
|
if (descr.empty())
|
|
{
|
|
if (tipo == 'C' || tipo == 'F')
|
|
{
|
|
descr << tipo << '|' << sottoconto;
|
|
descr = app().decode(LF_CLIFO, descr, CLI_RAGSOC);
|
|
}
|
|
else
|
|
{
|
|
descr << gruppo << '|' << conto << '|' << sottoconto;
|
|
descr = app().decode(LF_PCON, descr, PCN_DESCR);
|
|
}
|
|
}
|
|
riga.add(descr);
|
|
arr.add(riga);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TElimina_zoppi::test_scrow_file(int lf_pagsca, TString_array& arr)
|
|
{
|
|
bool ok = TRUE;
|
|
TLocalisamfile pagsca(lf_pagsca);
|
|
long found = 0;
|
|
|
|
TString msg;
|
|
msg << TR("Controllo righe ");
|
|
switch (lf_pagsca)
|
|
{
|
|
case LF_SCADENZE: msg << TR("scadenze"); break;
|
|
case LF_PAGSCA : msg << TR("pagamento"); break;
|
|
default: CHECKD(0, "Invalid row file %d", lf_pagsca); break;
|
|
}
|
|
msg << ": 0";
|
|
msg.center_just(50);
|
|
|
|
TProgind pi(pagsca.items(), msg, TRUE, TRUE, 50);
|
|
TToken_string riga, descr;
|
|
|
|
FOR_EACH_FILE_RECORD(pagsca)
|
|
{
|
|
if (pi.iscancelled())
|
|
{
|
|
ok = FALSE;
|
|
break;
|
|
}
|
|
pi.addstatus(1);
|
|
|
|
bool to_kill = FALSE;
|
|
if (pagsca.get_int(SCAD_NRIGA) <= 0 ||
|
|
pagsca.get_int(SCAD_NRATA) <= 0)
|
|
to_kill = TRUE;
|
|
if (lf_pagsca == LF_PAGSCA && pagsca.get_int(PAGSCA_NRIGP) <= 0)
|
|
to_kill = TRUE;
|
|
|
|
if (to_kill)
|
|
{
|
|
found++;
|
|
const int colon = msg.find(':');
|
|
msg.cut(colon+2);
|
|
msg << found;
|
|
pi.set_text(msg);
|
|
|
|
riga.format(" |%6ld", pagsca.recno());
|
|
if (lf_pagsca == LF_SCADENZE)
|
|
riga.add("S");
|
|
else
|
|
riga.add("G");
|
|
riga << lf_pagsca;
|
|
|
|
riga.add(pagsca.get(SCAD_ANNO));
|
|
riga.add(TR("Partita ")); riga << pagsca.get(SCAD_NUMPART);
|
|
riga.add(pagsca.get(SCAD_GRUPPO));
|
|
riga.add(pagsca.get(SCAD_CONTO));
|
|
riga.add(pagsca.get(SCAD_SOTTOCONTO));
|
|
if (lf_pagsca == LF_SCADENZE)
|
|
riga.add(TR("Riga scadenze inconsistente"));
|
|
else
|
|
riga.add(TR("Riga pagamenti inconsistente"));
|
|
arr.add(riga);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TElimina_zoppi::test_head_file(TString_array& arr)
|
|
{
|
|
bool ok = TRUE;
|
|
TLocalisamfile mov(LF_MOV);
|
|
TLocalisamfile rmov(LF_RMOV);
|
|
TLocalisamfile rmoviva(LF_RMOVIVA);
|
|
|
|
TString msg;
|
|
msg << TR("Controllo testate di prima nota: 0");
|
|
msg.center_just(50);
|
|
|
|
TProgind pi(mov.items(), msg, TRUE, TRUE, 50);
|
|
TToken_string riga, descr;
|
|
|
|
FOR_EACH_FILE_RECORD(mov)
|
|
{
|
|
if (pi.iscancelled())
|
|
{
|
|
ok = FALSE;
|
|
break;
|
|
}
|
|
pi.addstatus(1);
|
|
|
|
long reg = mov.get_long(MOV_NUMREG);
|
|
int rmov_err = NOERR;
|
|
int rmoviva_err = NOERR;
|
|
if (reg > 0)
|
|
{
|
|
rmov.put(RMV_NUMREG, reg);
|
|
rmov.put(RMV_NUMRIG, 1);
|
|
rmov_err = rmov.read();
|
|
rmoviva.put(RMI_NUMREG, reg);
|
|
rmoviva.put(RMI_NUMRIG, 1);
|
|
rmoviva_err = rmoviva.read();
|
|
}
|
|
if (reg == 0 || (rmov_err != NOERR && rmoviva_err != NOERR))
|
|
{
|
|
riga.format(" |%6ld|T", reg);
|
|
riga.add(mov.get(MOV_ANNOES));
|
|
riga.add(mov.get_real(MOV_TOTDOC).string("."));
|
|
riga << " | | ";
|
|
riga.add(mov.get(MOV_CODCF));
|
|
descr = mov.get(MOV_DESCR);
|
|
if (descr.empty())
|
|
{
|
|
char tipo = mov.get_char(MOV_TIPO);
|
|
if (tipo == 'C' || tipo == 'F')
|
|
{
|
|
descr << tipo << '|' << mov.get(MOV_CODCF);
|
|
descr = app().decode(LF_CLIFO, descr, CLI_RAGSOC);
|
|
}
|
|
}
|
|
riga.add(descr);
|
|
arr.add(riga);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
int TElimina_zoppi::kill_game(long numreg, int numrig)
|
|
{
|
|
TPartite_array games;
|
|
games.add_numreg(numreg);
|
|
for (TPartita* game = games.first(); game; game = games.next())
|
|
{
|
|
bool update = FALSE;
|
|
const int fattura = game->prima_fattura(numreg);
|
|
if (fattura > 0)
|
|
{
|
|
game->scollega_pagamenti(fattura, 1);
|
|
game->rimuovi_riga(fattura);
|
|
update = TRUE;
|
|
}
|
|
|
|
const int rigapag = game->primo_pagamento(numreg);
|
|
if (rigapag > 0)
|
|
{
|
|
int p;
|
|
|
|
for (p = game->last(); p > 0; p = game->pred(p))
|
|
{
|
|
TRiga_partite& part = game->riga(p);
|
|
if (part.is_fattura())
|
|
{
|
|
for (int r = part.rate(); r > 0; r--)
|
|
{
|
|
TRiga_scadenze& scad = part.rata(r);
|
|
for (int s = scad.last(); s > 0; s = scad.pred(s))
|
|
{
|
|
const TRiga_partite& sum = game->riga(s);
|
|
if (sum.get_long(PART_NREG) == numreg)
|
|
{
|
|
game->elimina_pagamento(p, r, s);
|
|
update = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
TRecord_array& unas = game->unassigned();
|
|
for (int u = unas.last_row(); u > 0; u = unas.pred_row(u))
|
|
{
|
|
const TRiga_partite& sum = game->riga(u);
|
|
if (sum.get_long(PART_NREG) == numreg)
|
|
{
|
|
game->elimina_pagamento(TPartita::UNASSIGNED, 0, u);
|
|
update = TRUE;
|
|
}
|
|
}
|
|
|
|
// Elimina le righe sopravvissute
|
|
for (p = game->last(); p > 0; p = game->pred(p))
|
|
{
|
|
TRiga_partite& part = game->riga(p);
|
|
if (part.get_long(PART_NREG) == numreg)
|
|
{
|
|
game->rimuovi_riga(p);
|
|
update = TRUE;
|
|
}
|
|
}
|
|
}
|
|
if (update)
|
|
game->rewrite();
|
|
}
|
|
return NOERR;
|
|
}
|
|
|
|
int TElimina_zoppi::kill_pagsca(long recno, int lfile)
|
|
{
|
|
CHECK(lfile == LF_SCADENZE || lfile == LF_PAGSCA, "Invalid file");
|
|
TLocalisamfile pagsca(lfile);
|
|
int err = pagsca.readat(recno);
|
|
if (err == NOERR)
|
|
err = pagsca.remove();
|
|
return err;
|
|
}
|
|
|
|
int TElimina_zoppi::kill_row(long numreg, char tipor, int numrig)
|
|
{
|
|
int lf = 0;
|
|
switch (tipor)
|
|
{
|
|
case 'C': lf = LF_RMOV; break;
|
|
case 'I': lf = LF_RMOVIVA; break;
|
|
case 'T': lf = LF_MOV; break;
|
|
case 'P': return kill_game(numreg, numrig);
|
|
case 'S':
|
|
case 'G': return kill_pagsca(numreg, numrig);
|
|
default : break;
|
|
}
|
|
|
|
TLocalisamfile rmov(lf);
|
|
rmov.put(RMV_NUMREG, numreg);
|
|
if (lf != LF_MOV)
|
|
rmov.put(RMV_NUMRIG, numrig);
|
|
int err = rmov.read();
|
|
if (err == NOERR)
|
|
err = rmov.remove();
|
|
return err;
|
|
}
|
|
|
|
bool TElimina_zoppi::select_handler(TMask_field& f, KEY k)
|
|
{
|
|
bool ok = TRUE;
|
|
if (k == K_SPACE)
|
|
{
|
|
TArray_sheet sheet(-1, -1, 76, 20, app().app_name(), HR("@1|Codice@6|Riga@5|Anno@R|Importo@20R|Grp@R|Cnt@R|Sottoc@R|Descrizione@50"));
|
|
TString_array& arr = sheet.rows_array();
|
|
ok = test_row_file(LF_RMOV, arr);
|
|
if (ok)
|
|
ok = test_row_file(LF_RMOVIVA, arr);
|
|
if (ok)
|
|
ok = test_head_file(arr);
|
|
if (ok)
|
|
ok = test_row_file(LF_PARTITE, arr);
|
|
if (ok)
|
|
ok = test_scrow_file(LF_SCADENZE, arr);
|
|
if (ok)
|
|
ok = test_scrow_file(LF_PAGSCA, arr);
|
|
if (ok)
|
|
arr.sort();
|
|
if (ok && sheet.run() == K_ENTER)
|
|
{
|
|
const long total = sheet.checked();
|
|
if (total > 0 &&
|
|
yesno_box(FR("Confermare l'eliminazione di %ld righe."), total))
|
|
{
|
|
TProgind pi(total, TR("Eliminazione righe..."), TRUE, TRUE);
|
|
FOR_EACH_ARRAY_ROW(arr, i, riga)
|
|
{
|
|
if (sheet.checked(i))
|
|
{
|
|
if (pi.iscancelled())
|
|
break;
|
|
pi.addstatus(1);
|
|
|
|
TString16 str = riga->get(2);
|
|
char tipor = str[0];
|
|
int numrig = atoi(str.mid(1));
|
|
kill_row(riga->get_long(1), tipor, numrig);
|
|
}
|
|
}
|
|
message_box(TR("Si consiglia di eseguire il ricalcolo\ndei saldi dal menu di prima nota."));
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
void TElimina_zoppi::main_loop()
|
|
{
|
|
open_files(LF_CLIFO, LF_NDITTE, LF_PCON, LF_MOV, LF_RMOV, LF_RMOVIVA, LF_PARTITE, LF_SCADENZE, LF_PAGSCA, 0);
|
|
|
|
TMask m(app_name(), 1, 30, 5);
|
|
m.add_number(DLG_USER, 0, TR("Codice ditta "), 1, 1, 5, "BUF");
|
|
m.add_button(DLG_SELECT, 0, "", -12, -1, 10, 2);
|
|
m.add_button(DLG_QUIT, 0, "", -22, -1, 10, 2);
|
|
m.set_handler(DLG_USER, firm_handler);
|
|
m.set_handler(DLG_SELECT, select_handler);
|
|
|
|
while (m.run() != K_QUIT);
|
|
}
|
|
|
|
int elimina_zoppi(int argc, char* argv[])
|
|
{
|
|
TElimina_zoppi ez;
|
|
ez.run(argc, argv, ez.app_name());
|
|
return 0;
|
|
}
|