git-svn-id: svn://10.65.10.50/branches/R_10_00@22992 c028cbd2-c16b-5b4b-a496-9718f37d4682
565 lines
15 KiB
C++
Executable File
565 lines
15 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <defmask.h>
|
||
#include <isam.h>
|
||
#include <prefix.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <recset.h>
|
||
#include <sheet.h>
|
||
#include <urldefid.h>
|
||
|
||
#include "cgsaldac.h"
|
||
|
||
#include <clifo.h>
|
||
#include <mov.h>
|
||
#include <nditte.h>
|
||
#include <pconti.h>
|
||
#include <rmov.h>
|
||
#include <rmoviva.h>
|
||
|
||
class TElimina_zoppi : public TSkeleton_application
|
||
{
|
||
TArray _decoders;
|
||
|
||
protected:
|
||
static bool test_riga_partita(const TRectype& pagsca);
|
||
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);
|
||
|
||
public:
|
||
const char* app_name() const {return TR("Righe prima nota errate");}
|
||
const char* decode(int num, const char* key, const char* field);
|
||
const char* decode(int num, long 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"));
|
||
TString_array& rows = sheet.rows_array();
|
||
prefix().firms(rows);
|
||
FOR_EACH_ARRAY_ROW(rows, r, row)
|
||
{
|
||
const long cod = row->get_long(0);
|
||
row->add(app().decode(LF_NDITTE, cod, NDT_RAGSOC));
|
||
if (cod == prefix().get_codditta())
|
||
sheet.select(r);
|
||
}
|
||
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 <20> attivata per la contabilit<69>"), 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);
|
||
}
|
||
|
||
const char* TElimina_zoppi::decode(int num, long key, const char* field)
|
||
{
|
||
TString8 k; k.format("%ld", key);
|
||
return decode(num, k, field);
|
||
}
|
||
|
||
bool TElimina_zoppi::test_row_file(int lf_rmov, TString_array& arr)
|
||
{
|
||
bool ok = true;
|
||
TLocalisamfile mov(LF_MOV);
|
||
|
||
TString8 query; query.format("USE %d", lf_rmov);
|
||
TISAM_recordset recset(query);
|
||
|
||
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";
|
||
|
||
TProgress_monitor pi(recset.items(), msg);
|
||
TToken_string riga, descr;
|
||
|
||
long reg, last_reg = 0, found = 0;
|
||
bool reg_killed = false;
|
||
|
||
char tipo;
|
||
int gruppo, conto;
|
||
long sottoconto;
|
||
|
||
const TRectype& row = recset.cursor()->curr();
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
if (!pi.add_status(1))
|
||
{
|
||
ok = false;
|
||
break;
|
||
}
|
||
|
||
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_riga_partita(const TRectype& pagsca)
|
||
{
|
||
const int nriga = pagsca.get_int(PART_NRIGA);
|
||
bool ok = nriga > 0;
|
||
|
||
if (nriga < 9999)
|
||
{
|
||
TToken_string k;
|
||
k = pagsca.get(PART_TIPOCF);
|
||
k.add(pagsca.get(PART_GRUPPO), 1);
|
||
k.add(pagsca.get(PART_CONTO), 2);
|
||
k.add(pagsca.get(PART_SOTTOCONTO), 3);
|
||
k.add(pagsca.get(PART_ANNO));
|
||
k.add(pagsca.get(PART_NUMPART));
|
||
k.add(nriga);
|
||
const int tipomov = atoi(app().decode(LF_PARTITE, k, PART_TIPOMOV));
|
||
ok = tipomov == 1;
|
||
}
|
||
|
||
return ok;
|
||
}
|
||
|
||
bool TElimina_zoppi::test_scrow_file(int lf_pagsca, TString_array& arr)
|
||
{
|
||
bool ok = true;
|
||
|
||
TString8 query; query.format("USE %d", lf_pagsca);
|
||
TISAM_recordset recset(query);
|
||
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);
|
||
|
||
TProgress_monitor pi(recset.items(), msg);
|
||
TToken_string riga, descr;
|
||
|
||
const TRectype& pagsca = recset.cursor()->curr();
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
if (!pi.add_status())
|
||
{
|
||
ok = false;
|
||
break;
|
||
}
|
||
|
||
bool to_kill = false;
|
||
if (pagsca.get_int(SCAD_NRIGA) <= 0 || pagsca.get_int(SCAD_NRATA) <= 0)
|
||
to_kill = true;
|
||
|
||
switch (lf_pagsca)
|
||
{
|
||
case LF_PAGSCA:
|
||
if (pagsca.get_int(PAGSCA_NRIGP) <= 0)
|
||
to_kill = true;
|
||
if (!test_riga_partita(pagsca))
|
||
to_kill = true;
|
||
break;
|
||
case LF_SCADENZE:
|
||
if (!test_riga_partita(pagsca))
|
||
to_kill = true;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
if (to_kill)
|
||
{
|
||
found++;
|
||
const int colon = msg.find(':');
|
||
msg.cut(colon+2);
|
||
msg << found;
|
||
pi.set_text(msg);
|
||
|
||
riga.format(" |%6ld", recset.cursor()->file().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)
|
||
{
|
||
TEsercizi_contabili esc;
|
||
|
||
bool ok = true;
|
||
TISAM_recordset recset("USE MOV");
|
||
TLocalisamfile rmov(LF_RMOV);
|
||
TLocalisamfile rmoviva(LF_RMOVIVA);
|
||
|
||
TString msg;
|
||
msg << TR("Controllo testate di prima nota: 0");
|
||
msg.center_just(50);
|
||
|
||
TProgress_monitor pi(recset.items(), msg);
|
||
TToken_string riga, descr;
|
||
const TRectype& mov = recset.cursor()->curr();
|
||
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
if (!pi.add_status())
|
||
{
|
||
ok = false;
|
||
break;
|
||
}
|
||
|
||
long reg = mov.get_long(MOV_NUMREG);
|
||
|
||
bool good = reg > 0;
|
||
if (good)
|
||
{
|
||
//int rmoviva_err = NOERR;
|
||
rmov.put(RMV_NUMREG, reg);
|
||
rmov.put(RMV_NUMRIG, 1);
|
||
int rmov_err = rmov.read();
|
||
/*rmoviva.put(RMI_NUMREG, reg);
|
||
rmoviva.put(RMI_NUMRIG, 1);
|
||
int rmoviva_err = rmoviva.read();*/
|
||
good = rmov_err == NOERR;
|
||
if (good)
|
||
{
|
||
const int annoes = mov.get_int(MOV_ANNOES);
|
||
good = annoes > 0 && esc.exist(annoes);
|
||
}
|
||
}
|
||
|
||
if (!good)
|
||
{
|
||
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();
|
||
if (err == NOERR && lf == LF_MOV)
|
||
{
|
||
// Cancella anche le righe collegate alla testata
|
||
for (int r = 1; kill_row(numreg, 'C', r) == NOERR; r++);
|
||
for (int r = 1; kill_row(numreg, 'I', r) == NOERR; r++);
|
||
}
|
||
}
|
||
return err;
|
||
}
|
||
|
||
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").set_handler(firm_handler);
|
||
m.add_button(DLG_ELABORA, 0, "", -12, -1, 10, 2, "", BMP_ELABORA).set_exit_key(K_ENTER);
|
||
m.add_button(DLG_QUIT, 0, "", -22, -1, 10, 2);
|
||
|
||
while (m.run() != K_QUIT)
|
||
{
|
||
TArray_sheet sheet(0, 0, 0, 0, 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();
|
||
bool 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 &&
|
||
delete_box(FR("Confermare l'eliminazione di %ld righe."), total))
|
||
{
|
||
TProgress_monitor pi(total, TR("Eliminazione righe..."));
|
||
FOR_EACH_ARRAY_ROW(arr, i, riga)
|
||
{
|
||
if (sheet.checked(i))
|
||
{
|
||
if (!pi.add_status())
|
||
break;
|
||
|
||
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."));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void elimina_zoppi(int argc, char* argv[])
|
||
{
|
||
TElimina_zoppi ez;
|
||
ez.run(argc, argv, ez.app_name());
|
||
}
|