2010-01-03 20:29:32 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <automask.h>
|
2016-04-15 08:17:44 +00:00
|
|
|
|
#include <config.h>
|
2010-01-03 20:29:32 +00:00
|
|
|
|
#include <execp.h>
|
|
|
|
|
#include <progind.h>
|
2016-04-15 08:17:44 +00:00
|
|
|
|
#include <sheet.h>
|
2010-01-03 20:29:32 +00:00
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
|
|
|
|
|
#include "lv4.h"
|
|
|
|
|
#include "lv4100.h"
|
|
|
|
|
#include "lv4100a.h"
|
|
|
|
|
|
|
|
|
|
#include <pconti.h>
|
|
|
|
|
#include <mov.h>
|
|
|
|
|
#include <rmov.h>
|
|
|
|
|
#include <rmoviva.h>
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
#define CGC_DITTA_PK 0
|
|
|
|
|
#define CGC_TIPO 1
|
|
|
|
|
#define CGC_GRUPPO 2
|
|
|
|
|
#define CGC_CONTO 3
|
|
|
|
|
#define CGC_SOTTOCONTO 4
|
|
|
|
|
#define CGC_ANNO 5
|
|
|
|
|
#define CGC_VALUTA 6
|
|
|
|
|
#define CGC_CREAZIONE 7
|
|
|
|
|
#define CGC_PROGR_DARE 8
|
|
|
|
|
#define CGC_PROGR_AVERE 9
|
|
|
|
|
#define CGC_SALDO_APERTURA 10
|
|
|
|
|
#define CGC_SALDO_CHIUSURA 11
|
|
|
|
|
#define CGC_ULT_PAG_PART 12
|
|
|
|
|
#define CGC_DARE_PARTITARIO 13
|
|
|
|
|
#define CGC_AVERE_PARTITARIO 14
|
|
|
|
|
#define CGC_DATAAGG_PARTITARIO 15
|
|
|
|
|
|
2010-01-07 16:52:33 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TImporta_cogeco_recset
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
real TImporta_cogeco_recset::get_real(int idx) const
|
2010-01-03 20:29:32 +00:00
|
|
|
|
{
|
2010-01-05 14:32:48 +00:00
|
|
|
|
TString80 imp = get(idx).as_string();
|
|
|
|
|
imp.strip(".");
|
|
|
|
|
imp.replace(',', '.');
|
|
|
|
|
return real(imp);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 16:52:33 +00:00
|
|
|
|
bool TImporta_cogeco_recset::get_bill(TBill& bill, int idx_gruppo) const
|
2010-01-05 14:32:48 +00:00
|
|
|
|
{
|
2010-01-07 16:52:33 +00:00
|
|
|
|
const int g = get(idx_gruppo).as_int();
|
|
|
|
|
const int c = get(idx_gruppo+1).as_int();
|
|
|
|
|
const long s = get(idx_gruppo+2).as_int();
|
2010-01-05 14:32:48 +00:00
|
|
|
|
bill.set(g, c, s);
|
|
|
|
|
return bill.ok();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 16:52:33 +00:00
|
|
|
|
TDate TImporta_cogeco_recset::get_date(int idx) const
|
|
|
|
|
{
|
|
|
|
|
int gg, mm, aaaa;
|
|
|
|
|
const TString& str = get(idx).as_string();
|
|
|
|
|
if (sscanf(str, "%2d/%2d/%4d", &gg, &mm, &aaaa) == 3 && gg > 0 && mm > 0 && aaaa > 2000)
|
|
|
|
|
return TDate(gg, mm, aaaa);
|
|
|
|
|
return TDate();
|
|
|
|
|
}
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TAutomask
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TImporta_saldi_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TImporta_saldi_mask();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TImporta_saldi_mask::TImporta_saldi_mask() :TAutomask ("lv4100a")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImporta_saldi_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (f.dlg())
|
|
|
|
|
{
|
|
|
|
|
//giochetto per avere la lista dei files validi nella directory di trasferimento!
|
|
|
|
|
case F_NAME:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"),
|
|
|
|
|
"File@32");
|
|
|
|
|
TFilename path = get(F_PATH);
|
|
|
|
|
path.add("*.txt"); //files delle testate
|
|
|
|
|
list_files(path, as.rows_array());
|
|
|
|
|
TFilename name;
|
|
|
|
|
FOR_EACH_ARRAY_ROW(as.rows_array(), i, row)
|
|
|
|
|
{
|
|
|
|
|
name = *row;
|
|
|
|
|
*row = name.name();
|
|
|
|
|
}
|
|
|
|
|
if (as.run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
f.set(as.row(as.selected()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
// TSkeleton_application
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
class TImporta_saldi : public TSkeleton_application
|
|
|
|
|
{
|
2010-01-05 14:32:48 +00:00
|
|
|
|
TImporta_saldi_mask* _msk;
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
protected:
|
|
|
|
|
void set_rmov(TConfig& conf, const int nrow, const TImporto& imp,
|
|
|
|
|
const TBill& bill) const;
|
|
|
|
|
void delete_ini(const TFilename& outdir) const;
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual bool create();
|
|
|
|
|
virtual bool destroy();
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
void transfer(const TFilename& file);
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
void TImporta_saldi::set_rmov(TConfig& conf, const int nrow, const TImporto& imp,
|
|
|
|
|
const TBill& bill) const
|
|
|
|
|
{
|
|
|
|
|
TString8 paragraph;
|
|
|
|
|
paragraph.format("%d,%d", LF_RMOV, nrow);
|
|
|
|
|
conf.set_paragraph(paragraph);
|
|
|
|
|
|
|
|
|
|
const char strsez[2] = {imp.sezione(), '\0'};
|
|
|
|
|
conf.set(RMV_SEZIONE, strsez);
|
|
|
|
|
conf.set(RMV_IMPORTO, imp.valore().string());
|
|
|
|
|
conf.set(RMV_GRUPPO, bill.gruppo());
|
|
|
|
|
conf.set(RMV_CONTO, bill.conto());
|
|
|
|
|
conf.set(RMV_SOTTOCONTO, bill.sottoconto());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TImporta_saldi::delete_ini(const TFilename& outdir) const
|
|
|
|
|
{
|
|
|
|
|
if (outdir.exist())
|
|
|
|
|
{
|
|
|
|
|
for (int ntran=1;;ntran++)
|
|
|
|
|
{
|
|
|
|
|
TFilename temp(outdir);
|
|
|
|
|
temp.add(format("lv41%05ld.ini", ntran++));
|
|
|
|
|
if (!temp.fremove())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
make_dir(outdir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-03 20:29:32 +00:00
|
|
|
|
void TImporta_saldi::transfer(const TFilename& file)
|
|
|
|
|
{
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const TFilename outdir(_msk->get(F_PATHOUT));
|
2010-01-03 20:29:32 +00:00
|
|
|
|
TImporta_cogeco_recset s(file);
|
|
|
|
|
TProgind pi(s.items(),"Importazione saldi in corso ...",true,true);
|
|
|
|
|
TConfig * conf = NULL;
|
2010-01-21 14:00:10 +00:00
|
|
|
|
TFilename filename;
|
2010-01-03 20:29:32 +00:00
|
|
|
|
long ntran = 1L;
|
|
|
|
|
int nrow = 1;
|
|
|
|
|
int anno = 0;
|
|
|
|
|
TString8 reg;
|
|
|
|
|
TDate dataop = _msk->get_date(F_DATAMOV);
|
|
|
|
|
TImporto totmov;
|
|
|
|
|
TConfig cditta(CONFIG_DITTA, "cg");
|
|
|
|
|
const TString4 ctypes("GCF");
|
|
|
|
|
const TString8 causale = cditta.get("CoCaAp");
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const TBill conto_ap(cditta.get_int("CsBiApG"),
|
|
|
|
|
cditta.get_int("CsBiApC"),
|
|
|
|
|
cditta.get_long("CsBiApS"));
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
|
|
|
|
int lastgruppo = 0;
|
|
|
|
|
const int codes = _msk->get_int(F_ANNOES);
|
|
|
|
|
const long ditta = _msk->get_long(F_CODITTA);
|
|
|
|
|
const TEsercizi_contabili esc;
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
delete_ini(outdir);
|
|
|
|
|
|
|
|
|
|
for (bool ok=s.move_to(1);ok;ok=s.move_next())
|
2010-01-03 20:29:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const long dt = s.get(CGC_DITTA_PK).as_int();
|
2010-01-03 20:29:32 +00:00
|
|
|
|
if (ditta != dt)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const int es = s.get(CGC_ANNO).as_int();
|
2010-01-03 20:29:32 +00:00
|
|
|
|
if (codes != es)
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
if (ctypes.find(s.get(CGC_TIPO).as_string()[0]) < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
TBill bill;
|
2010-01-07 16:52:33 +00:00
|
|
|
|
if (!s.get_bill(bill, CGC_GRUPPO))
|
2010-01-05 14:32:48 +00:00
|
|
|
|
continue;
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
if (lastgruppo != bill.gruppo() || nrow >= 99)
|
2010-01-03 20:29:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (conf != NULL)
|
|
|
|
|
{
|
2010-01-21 14:00:10 +00:00
|
|
|
|
const bool null_mov = (nrow==1);
|
|
|
|
|
if (!null_mov)
|
|
|
|
|
set_rmov(*conf, nrow++, totmov, conto_ap);
|
2010-01-03 20:29:32 +00:00
|
|
|
|
delete conf;
|
2010-01-05 14:32:48 +00:00
|
|
|
|
conf = NULL;
|
2010-01-21 14:00:10 +00:00
|
|
|
|
totmov.reset();
|
|
|
|
|
if (null_mov)
|
|
|
|
|
{
|
|
|
|
|
remove_file(filename);
|
|
|
|
|
ntran--;
|
|
|
|
|
}
|
2010-01-03 20:29:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 14:00:10 +00:00
|
|
|
|
filename = outdir;
|
|
|
|
|
filename.add(format("lv41%05ld.ini", ntran++));
|
|
|
|
|
conf = new TConfig(filename);
|
2010-01-03 20:29:32 +00:00
|
|
|
|
conf->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini
|
|
|
|
|
conf->set("Action","INSERT");
|
|
|
|
|
conf->set("Mode","AUTO");
|
|
|
|
|
|
|
|
|
|
conf->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
|
|
|
|
|
conf->set(MOV_CODCAUS, causale);
|
|
|
|
|
conf->set(MOV_DATAREG, dataop.stringa());
|
2010-01-05 14:32:48 +00:00
|
|
|
|
conf->set(MOV_DESCR, TR("Ripresa Saldi"));
|
2010-01-03 20:29:32 +00:00
|
|
|
|
nrow = 1;
|
2010-01-05 14:32:48 +00:00
|
|
|
|
lastgruppo = bill.gruppo();
|
2010-01-03 20:29:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const real val = s.get_real(CGC_SALDO_APERTURA);
|
2010-01-03 20:29:32 +00:00
|
|
|
|
TImporto impmov(val > ZERO ? 'D' : 'A', abs(val));
|
2010-01-05 14:32:48 +00:00
|
|
|
|
const TImporto pdare('D', s.get_real(CGC_PROGR_DARE));
|
|
|
|
|
const TImporto pavere('A', s.get_real(CGC_PROGR_AVERE));
|
2010-01-03 20:29:32 +00:00
|
|
|
|
|
|
|
|
|
impmov += pdare;
|
|
|
|
|
impmov += pavere;
|
|
|
|
|
|
2010-01-05 14:32:48 +00:00
|
|
|
|
if (!impmov.is_zero())
|
2010-01-03 20:29:32 +00:00
|
|
|
|
{
|
2010-01-05 14:32:48 +00:00
|
|
|
|
set_rmov(*conf, nrow++, impmov, bill);
|
2010-01-03 20:29:32 +00:00
|
|
|
|
totmov -= impmov;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (conf != NULL)
|
|
|
|
|
{
|
2010-01-21 14:00:10 +00:00
|
|
|
|
const bool null_mov = (nrow==1);
|
|
|
|
|
if (!null_mov)
|
|
|
|
|
set_rmov(*conf, nrow++, totmov, conto_ap);
|
2010-01-03 20:29:32 +00:00
|
|
|
|
delete conf;
|
2010-01-21 14:00:10 +00:00
|
|
|
|
conf = NULL;
|
|
|
|
|
totmov.reset();
|
|
|
|
|
if (null_mov)
|
|
|
|
|
{
|
|
|
|
|
remove_file(filename);
|
|
|
|
|
ntran--;
|
|
|
|
|
}
|
2010-01-03 20:29:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran -1))
|
|
|
|
|
{
|
2010-01-05 14:32:48 +00:00
|
|
|
|
TFilename app = outdir;
|
|
|
|
|
app.add("lv41*.ini");
|
|
|
|
|
app.insert("cg2 -0 -i");
|
2010-01-03 20:29:32 +00:00
|
|
|
|
TExternal_app primanota(app);
|
|
|
|
|
primanota.run(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImporta_saldi::create()
|
|
|
|
|
{
|
2010-01-08 09:56:26 +00:00
|
|
|
|
_msk = new TImporta_saldi_mask();
|
2010-01-03 20:29:32 +00:00
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImporta_saldi::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete _msk;
|
|
|
|
|
return TApplication::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TImporta_saldi::main_loop()
|
|
|
|
|
{
|
|
|
|
|
KEY tasto;
|
|
|
|
|
tasto = _msk->run();
|
|
|
|
|
if (tasto == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
//genero il nome del file da caricare
|
|
|
|
|
TFilename name = _msk->get(F_PATH);
|
|
|
|
|
name.add(_msk->get(F_NAME));
|
|
|
|
|
transfer(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int lv4100 (int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TImporta_saldi main_app;
|
2010-01-05 14:32:48 +00:00
|
|
|
|
main_app.run(argc, argv, TR("Importazione contabilit<69> COGECO"));
|
2010-01-03 20:29:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|