cg1300.cpp Aggiunta gestione movimenti zoppi git-svn-id: svn://10.65.10.50/trunk@6077 c028cbd2-c16b-5b4b-a496-9718f37d4682
283 lines
7.0 KiB
C++
Executable File
283 lines
7.0 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <sheet.h>
|
|
#include <urldefid.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
|
|
|
|
const char* const APPNAME = "Righe prima nota errate";
|
|
|
|
class TElimina_zoppi : public TSkeleton_application
|
|
{
|
|
TArray _files;
|
|
TArray _decoders;
|
|
|
|
protected:
|
|
static bool test_file(int rmov, TString_array& arr);
|
|
static int kill_row(long numreg, const char* codrig);
|
|
|
|
static bool firm_handler(TMask_field& f, KEY k);
|
|
static bool select_handler(TMask_field& f, KEY k);
|
|
|
|
protected:
|
|
void open_files(int logicnum, ...);
|
|
TLocalisamfile& file(int num);
|
|
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, "Scelta ditta", "Codice|Ragione Sociale@50");
|
|
TToken_string row;
|
|
|
|
TLocalisamfile& ditte = app().file(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("La ditta %05ld non e' attivata per la contabilita'", cod);
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
void TElimina_zoppi::open_files(int logicnum, ...)
|
|
{
|
|
va_list marker;
|
|
va_start(marker, logicnum);
|
|
while (logicnum > 0)
|
|
{
|
|
CHECKD(_files.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
|
|
_files.add(new TLocalisamfile(logicnum), logicnum);
|
|
logicnum = va_arg(marker, int);
|
|
}
|
|
}
|
|
|
|
TLocalisamfile& TElimina_zoppi::file(int num)
|
|
{
|
|
TLocalisamfile* isam = (TLocalisamfile*)_files.objptr(num);
|
|
if (isam == NULL)
|
|
{
|
|
open_files(num, 0);
|
|
isam = (TLocalisamfile*)_files.objptr(num);
|
|
}
|
|
return *isam;
|
|
}
|
|
|
|
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_file(int lf_rmov, TString_array& arr)
|
|
{
|
|
bool ok = TRUE;
|
|
TLocalisamfile& mov = app().file(LF_MOV);
|
|
TLocalisamfile& rmov = app().file(lf_rmov);
|
|
|
|
TString msg;
|
|
msg << "Controllo righe ";
|
|
if (lf_rmov == LF_RMOV)
|
|
msg << "contabili";
|
|
else
|
|
msg << "iva";
|
|
msg << ": 0";
|
|
msg.center_just(50);
|
|
|
|
TProgind pi(rmov.items(), msg, TRUE, TRUE, 50);
|
|
TToken_string riga, descr;
|
|
|
|
long reg, last_reg, found = 0;
|
|
bool reg_killed = TRUE;
|
|
int gruppo, conto;
|
|
long sottoconto;
|
|
|
|
FOR_EACH_FILE_RECORD(rmov)
|
|
{
|
|
if (pi.iscancelled())
|
|
{
|
|
ok = FALSE;
|
|
break;
|
|
}
|
|
pi.addstatus(1);
|
|
|
|
reg = rmov.get_long(MOV_NUMREG);
|
|
if (reg != last_reg)
|
|
{
|
|
mov.put(MOV_NUMREG, reg);
|
|
reg_killed = mov.read() != NOERR;
|
|
last_reg = reg;
|
|
}
|
|
if (reg_killed)
|
|
{
|
|
found++;
|
|
const int colon = msg.find(':');
|
|
msg.cut(colon+2);
|
|
msg << found;
|
|
pi.set_text(msg);
|
|
|
|
const int numrig = rmov.get_int(RMV_NUMRIG);
|
|
riga.format(" |%6ld|%c%3d", reg, (lf_rmov == LF_RMOV) ? 'C' : 'I', numrig);
|
|
riga.add(rmov.get(RMV_ANNOES));
|
|
if (lf_rmov == LF_RMOV)
|
|
{
|
|
riga.add(rmov.get_real(RMV_IMPORTO).string("."));
|
|
riga << ' ' << rmov.get(RMV_SEZIONE);
|
|
}
|
|
else
|
|
{
|
|
riga.add(rmov.get_real(RMI_IMPONIBILE).string("."));
|
|
riga << " ";
|
|
}
|
|
riga.add(gruppo = rmov.get_int(RMV_GRUPPO));
|
|
riga.add(conto = rmov.get_int(RMV_CONTO));
|
|
riga.add(sottoconto = rmov.get_long(RMV_SOTTOCONTO));
|
|
|
|
if (lf_rmov == LF_RMOV)
|
|
descr = rmov.get(RMV_DESCR);
|
|
else
|
|
descr.cut(0);
|
|
if (descr.empty())
|
|
{
|
|
char tipo = rmov.get_char(RMV_TIPOC);
|
|
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;
|
|
}
|
|
|
|
int TElimina_zoppi::kill_row(long numreg, const char* codrig)
|
|
{
|
|
const int lf_rmov = *codrig == 'I' ? LF_RMOVIVA : LF_RMOV;
|
|
TLocalisamfile& rmov= app().file(lf_rmov);
|
|
rmov.put(RMV_NUMREG, numreg);
|
|
rmov.put(RMV_NUMRIG, codrig+1);
|
|
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, APPNAME, "@1|Codice@6|Riga|Anno|Importo@20R|Grp@R|Cnt@R|Sottoc@R|Descrizione@50");
|
|
TString_array& arr = sheet.rows_array();
|
|
ok = test_file(LF_RMOV, arr);
|
|
if (ok)
|
|
ok = test_file(LF_RMOVIVA, arr);
|
|
arr.sort();
|
|
|
|
if (ok && sheet.run() == K_ENTER)
|
|
{
|
|
const long total = sheet.checked();
|
|
if (total > 0 &&
|
|
yesno_box("Confermare l'eliminazione di %ld righe di prima nota.", total))
|
|
{
|
|
TProgind pi(total, "Eliminazione righe...", TRUE, TRUE);
|
|
FOR_EACH_ARRAY_ROW(arr, i, riga)
|
|
{
|
|
if (sheet.checked(i))
|
|
{
|
|
if (pi.iscancelled())
|
|
break;
|
|
pi.addstatus(1);
|
|
|
|
long reg = riga->get_long(1);
|
|
kill_row(reg, riga->get(2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
void TElimina_zoppi::main_loop()
|
|
{
|
|
open_files(LF_CLIFO, LF_NDITTE, LF_PCON, 0);
|
|
open_files(LF_MOV, LF_RMOV, LF_RMOVIVA, 0);
|
|
|
|
TMask m(APPNAME, 1, 30, 5);
|
|
m.add_number(DLG_USER, 0, "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, APPNAME);
|
|
return 0;
|
|
} |