Files correlati : Ricompilazione Demo : [ ] Commento :cominciato programma importazione movimenti bufget per il mitico Adolfo! git-svn-id: svn://10.65.10.50/trunk@14277 c028cbd2-c16b-5b4b-a496-9718f37d4682
311 lines
7.1 KiB
C++
Executable File
311 lines
7.1 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <config.h>
|
|
#include <execp.h>
|
|
#include <filetext.h>
|
|
//#include <log.h>
|
|
#include <progind.h>
|
|
#include <reprint.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
|
|
#include "../ca/movana.h"
|
|
#include "../ca/rmovana.h"
|
|
|
|
#include "crpa1a.h"
|
|
|
|
|
|
//---------------------------------
|
|
// TAutomask
|
|
//---------------------------------
|
|
class TBudget_Import_mask : public TAutomask
|
|
{
|
|
protected:
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
bool select_file_ext(const char* ext, TFilename& filename);
|
|
public:
|
|
TBudget_Import_mask();
|
|
virtual ~TBudget_Import_mask(){};
|
|
};
|
|
|
|
TBudget_Import_mask::TBudget_Import_mask() :TAutomask ("crpa1a")
|
|
{
|
|
}
|
|
|
|
bool TBudget_Import_mask::select_file_ext(const char* ext, TFilename& filename)
|
|
{
|
|
TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"),
|
|
"File@48");
|
|
TFilename path = get(F_PATH);
|
|
path.add("*");
|
|
path.ext(ext);
|
|
list_files(path, as.rows_array());
|
|
TFilename name;
|
|
FOR_EACH_ARRAY_ROW(as.rows_array(), i, row)
|
|
{
|
|
name = *row;
|
|
*row = name.name();
|
|
}
|
|
bool ok = as.run() == K_ENTER;
|
|
if (ok)
|
|
{
|
|
filename = as.row(as.selected());
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TBudget_Import_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_NAMEFILE:
|
|
if (e == fe_button)
|
|
{
|
|
TFilename name;
|
|
if (select_file_ext("csv", name))
|
|
f.set(name);
|
|
|
|
if (f.get() == get(F_LASTFILE))
|
|
return error_box(TR("File gia' importato!\nNON e' consigliabile proseguire!"));
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
//--------------------------------
|
|
// TFile_text
|
|
//--------------------------------
|
|
class TBudget_Import_file: public TFile_text
|
|
{
|
|
protected:
|
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
|
|
|
public:
|
|
TBudget_Import_file(const TString& file_name);
|
|
virtual ~TBudget_Import_file() { }
|
|
};
|
|
|
|
TBudget_Import_file::TBudget_Import_file(const TString& file_name)
|
|
: TFile_text(file_name, "crpa1.ini")
|
|
{
|
|
}
|
|
|
|
void TBudget_Import_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
|
{
|
|
const TString code(s.get(0));
|
|
TString valore = str;
|
|
if (code == "_UPPERCASE")
|
|
{
|
|
valore.upper();
|
|
}
|
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
|
str = valore;
|
|
}
|
|
|
|
|
|
//----------------------------------
|
|
// TSkeleton_application
|
|
//----------------------------------
|
|
class TBudget_Import : public TSkeleton_application
|
|
{
|
|
TBudget_Import_mask* _msk;
|
|
TBudget_Import_file* _trasfile;
|
|
TConfig* _configfile;
|
|
TRelation* _relmovana;
|
|
TRelation* _relrmovana;
|
|
TCursor* _cur;
|
|
TProgind* _prog;
|
|
TString _lastfile;
|
|
|
|
virtual const char * extra_modules() const {return "ba";}
|
|
|
|
protected:
|
|
void mask2ini();
|
|
void ini2mask();
|
|
bool transfer();
|
|
void transfer_testata(const TRecord_text& curr); //, TError_log& log);
|
|
// int crea_riga_mov(const TRecord_text& curr, TDocumento& bol, bool is_omaggio);
|
|
|
|
long get_next_key();
|
|
|
|
public:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
|
|
TBudget_Import() {}
|
|
};
|
|
|
|
|
|
|
|
long TBudget_Import::get_next_key()
|
|
{
|
|
TLocalisamfile& lfile = _relmovana->lfile();
|
|
long numreg = 1L ;
|
|
|
|
if (!lfile.empty())
|
|
{
|
|
lfile.zero() ;
|
|
lfile.setkey(1) ;
|
|
|
|
lfile.read(_isgteq);
|
|
if (lfile.good()) //se e' tutto ok,si posiziona sull'ultimo record
|
|
lfile.last();
|
|
|
|
if (lfile.good())
|
|
numreg += lfile.get_long(MOVANA_NUMREG);
|
|
}
|
|
return numreg;
|
|
}
|
|
|
|
|
|
void TBudget_Import::transfer_testata(const TRecord_text& curr) //, TError_log& log)
|
|
{
|
|
const TString codcms = curr.get(1);
|
|
const TString codconto = curr.get(2);
|
|
const real soldini = curr.get(3);
|
|
const TString16 str_dataini = curr.get(4);
|
|
const TString16 str_datafine = curr.get(5);
|
|
|
|
TString4 gg = str_dataini.left(2);
|
|
TString4 mm = str_dataini.mid(3,2);
|
|
TString4 yy = str_dataini.right(2);
|
|
yy.insert("20", 0);
|
|
const TDate dataini(atoi(gg),atoi(mm),atoi(yy));
|
|
|
|
gg = str_datafine.left(2);
|
|
mm = str_datafine.mid(3,2);
|
|
yy = str_datafine.right(2);
|
|
yy.insert("20", 0);
|
|
const TDate datafine(atoi(gg),atoi(mm),atoi(yy));
|
|
|
|
//aggiunge il movimento ai movana al primo posto libero
|
|
long numreg = get_next_key();
|
|
|
|
// creo il documento, se esiste cancello le righe perche' le ricreo successivamente
|
|
/* TDocumento& bol = _doc.doc(datadoc.year(), _numbol, num_bol);
|
|
const bool isnew = bol.rows() == 0;
|
|
|
|
if (isnew)
|
|
{
|
|
_forbidden_ndoc = 0L;
|
|
bol.put(DOC_TIPODOC, _tipobol);
|
|
bol.put(DOC_DATADOC, datadoc);
|
|
bol.put(DOC_STATO, _statobol);
|
|
bol.put("DAANNO", anno_ord);
|
|
bol.put("DANDOC", num_ord);
|
|
//legge la testata dell'ordine per avere il clifo
|
|
TDocumento& ordine = _doc.doc(anno_ord, _numord, num_ord);
|
|
const char tipocf = ordine.get_char(DOC_TIPOCF);
|
|
const long codcf = ordine.get_int(DOC_CODCF);
|
|
bol.put(DOC_TIPOCF, tipocf);
|
|
bol.put(DOC_CODCF, codcf);
|
|
_lastbol = num_bol; //aggiorna l'indicatore dell'ultima bolla trasferita
|
|
}
|
|
else
|
|
{
|
|
_forbidden_ndoc = num_bol;
|
|
TString msg;
|
|
msg.format(FR("La bolla %ld e' gia' stata trasferita"), num_bol);
|
|
log.log(1, msg);
|
|
}*/
|
|
|
|
}
|
|
|
|
bool TBudget_Import::transfer()
|
|
{
|
|
//file da trasferire
|
|
//costruire il nome del file con path
|
|
TFilename file = _msk->get(F_PATH);
|
|
file.add(_msk->get(F_NAMEFILE));
|
|
file.ext("csv");
|
|
_trasfile = new TBudget_Import_file(file);
|
|
_trasfile->open(file,'r');
|
|
|
|
//*** prima va inserito il log in libreria preparazione del log
|
|
// TError_log log;
|
|
// log.set_header(TR("Importazione movimenti"));
|
|
|
|
const long dimension = fsize(file);
|
|
TProgind pi(dimension,TR("Importazione bolle in corso..."));
|
|
|
|
int err = NOERR;
|
|
TRecord_text curr;
|
|
|
|
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
|
|
{
|
|
pi.setstatus(_trasfile->read_file()->tellg());
|
|
transfer_testata(curr); //, log);
|
|
}
|
|
_trasfile->close();
|
|
delete _trasfile;
|
|
|
|
// log.show();
|
|
_lastfile = _msk->get(F_NAMEFILE);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void TBudget_Import::mask2ini()
|
|
{
|
|
//aggiorna l'ultimo file inviato su msk e ini
|
|
_msk->set(F_LASTFILE, _lastfile);
|
|
_configfile->set_paragraph("BUDGET");
|
|
_configfile->set("PATH", _msk->get(F_PATH));
|
|
_configfile->set("LASTFILE", _lastfile);
|
|
}
|
|
|
|
void TBudget_Import::ini2mask()
|
|
{
|
|
//carica i parametri del file di configurazione
|
|
_configfile->set_paragraph("BUDGET");
|
|
TString path = _configfile->get("PATH");
|
|
_lastfile = _configfile->get("LASTFILE");
|
|
_msk->set(F_PATH, path);
|
|
_msk->set(F_LASTFILE, _lastfile);
|
|
}
|
|
|
|
|
|
bool TBudget_Import::create()
|
|
{
|
|
_configfile = new TConfig("crpa1conf.ini");
|
|
_msk = new TBudget_Import_mask();
|
|
open_files(LF_MOVANA, LF_RMOVANA, 0);
|
|
_relmovana = new TRelation(LF_MOVANA);
|
|
_relrmovana = new TRelation(LF_RMOVANA);
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TBudget_Import::destroy()
|
|
{
|
|
delete _msk;
|
|
delete _configfile;
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
void TBudget_Import::main_loop()
|
|
{
|
|
KEY tasto;
|
|
ini2mask();
|
|
tasto = _msk->run();
|
|
if (tasto == K_ENTER)
|
|
{
|
|
if (transfer())
|
|
message_box(TR("Importazione movimenti completata"));
|
|
}
|
|
mask2ini();
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TBudget_Import a;
|
|
a.run(argc, argv, TR("Importazione movimenti di budget per CRPA"));
|
|
return 0;
|
|
}
|