campo-sirio/ps/pg0001300.cpp
luca 063b45782c Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :


git-svn-id: svn://10.65.10.50/trunk@16033 c028cbd2-c16b-5b4b-a496-9718f37d4682
2008-01-23 09:37:37 +00:00

402 lines
17 KiB
C++
Executable File
Raw Blame History

#include "pg0001.h"
#include "pg0001300a.h"
#include <applicat.h>
#include <automask.h>
#include <config.h>
#include <diction.h>
#include <relation.h>
#include <progind.h>
#include <reprint.h>
#include <reputils.h>
#include <textset.h>
///////////////////////////////////////////////////////////
// TCSV_recset
///////////////////////////////////////////////////////////
class TCSV_recset : public TCSV_recordset
{
protected:
public:
TCSV_recset(const char * query) : TCSV_recordset(TString("CSV(;)\n") << query) {}
};
///////////////////////////////////////////////////////////
// TFixed_recset
///////////////////////////////////////////////////////////
real var2fixed2(const TVariant & v)
{
TString s(v.as_string());
s.replace(',', '.');
real r(s);
r *= CENTO;
return r;
}
class TFixed_recset : public TAS400_recordset
{
private:
void add_field(const char* name = "Filler", int from = -1, int len = 0,
char tipo = 'a', const char* def = NULL);
public:
bool set(int column, const TVariant& var);
TFixed_recset();
};
void TFixed_recset::add_field(const char* name, int from, int len, char tipo, const char* def)
{
const bool required = false;
const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
const int pos = from - 1;
if (def && *def)
{
CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
TVariant var(def); var.convert_to(t);
create_field(name, pos, len, t, required, var);
}
else
create_field(name, pos, len, t, required);
}
bool TFixed_recset::set(int column, const TVariant& var)
{
switch (column)
{
case 0:
return TAS400_recordset::set("NPROG", var); // 0 - numero progressivo
break;
case 1:
return TAS400_recordset::set("NFAT", var); // 1 - numero di fattura
break;
case 2:
return TAS400_recordset::set("ANNO", var); // 2 - anno
break;
case 3:
return TAS400_recordset::set("DATAFAT", var); // 3 - data fattura
break;
case 4:
return TAS400_recordset::set("DF1", var); // 4 - data fattura
break;
case 5:
return TAS400_recordset::set("RAGSOC", var); // 5 - ragione sociale
break;
case 6:
return TAS400_recordset::set("L0", var); // 6 - libero
break;
case 7:
return TAS400_recordset::set("IMPON", var2fixed2(var)); // 7 - 2 decimali imponibile
break;
case 8:
return TAS400_recordset::set("L1", var2fixed2(var)); // 8 - 2 decimali
break;
case 9:
return TAS400_recordset::set("L2", var2fixed2(var)); // 9 - 2 decimali
break;
case 10:
return TAS400_recordset::set("RITACC", var2fixed2(var)); // 10 - 2 decimali ritenuta d'acconto
break;
case 11:
return TAS400_recordset::set("TOTFAT", var2fixed2(var)); // 11 - 2 decimali totale fattura
break;
case 12:
return TAS400_recordset::set("L3", var); // 12 - libero
break;
case 13:
return TAS400_recordset::set("L4", var); // 13 - libero
break;
case 14:
return TAS400_recordset::set("L5", var); // 14 - libero
break;
case 15:
return TAS400_recordset::set("DATADOC", var); // 15 - data documento
break;
case 16:
return TAS400_recordset::set("C0", var); // 16 - vero - falso
break;
case 17:
return TAS400_recordset::set("C1", var); // 17 - E
break;
case 18:
return TAS400_recordset::set("C2", var); // 18 - Contanti - Bancomat
break;
case 19:
return TAS400_recordset::set("GT", var); // 19 - gt
break;
case 20:
return TAS400_recordset::set("L6", var); // 20 - libero
break;
case 21:
return TAS400_recordset::set("BOLLO", var2fixed2(var)); // 21 - 2 decimali Valore Bollo
break;
case 22:
return TAS400_recordset::set("DATA", var); // 22 - Data di creazione file movimenti
break;
case 23:
return TAS400_recordset::set("L7", var); // 23 - libero
break;
case 24:
return TAS400_recordset::set("COGNOME", var); // 24 - Cognome o Ragione Sociale
break;
case 25:
return TAS400_recordset::set("NOME", var); // 25 - Nome o Seguito ragione sociale
break;
case 26:
return TAS400_recordset::set("CODFIS", var); // 26 - Codice fiscale
break;
case 27:
return TAS400_recordset::set("PIVA", var); // 27 - Partita I.v.a.
break;
case 28:
return TAS400_recordset::set("INDIR", var); // 28 - Indirizzo
break;
case 29:
return TAS400_recordset::set("CITTA", var); // 29 - Citt<74>
break;
case 30:
return TAS400_recordset::set("PROV", var); // 30 - Provincia
break;
case 31:
return TAS400_recordset::set("CAP", var); // 31 - C.A.P.
break;
case 32:
return TAS400_recordset::set("TIPOERS", var); // 32 - P= persona fisica o D = Ditta
break;
case 33:
return TAS400_recordset::set("SESSO", var); // 33 - F=Femmina M=Maschio
break;
case 34:
return TAS400_recordset::set("L8", var); // 34 - libero
break;
case 35:
return TAS400_recordset::set("L9", var); // 35 - libero
break;
case 36:
return TAS400_recordset::set("L10", var); // 36 - libero
break;
default:
break;
}
return false;
}
TFixed_recset::TFixed_recset()
: TAS400_recordset("AS400(386)\n")
{
const char a = 'a';
const char n = 'n';
add_field("NPROG", 1, 6, n); // 0 - numero progressivo
add_field("NFAT", 7, 8, n); // 1 - numero di fattura
add_field("ANNO", 15, 4, n); // 2 - anno
add_field("DATAFAT", 19, 10, a); // 3 - data fattura
add_field("DF1", 29, 10, a); // 4 - data fattura
add_field("RAGSOC", 39, 40, a); // 5 - ragione sociale
add_field("L0", 79, 9, a); // 6 - libero
add_field("IMPON", 88, 11, n); // 7 - 2 decimali imponibile
add_field("L1", 99, 11, n); // 8 - 2 decimali
add_field("L2", 110, 11, n); // 9 - 2 decimali
add_field("RITACC", 121, 11, n); // 10 - 2 decimali ritenuta d'acconto
add_field("TOTFAT", 132, 11, n); // 11 - 2 decimali totale fattura
add_field("L3", 143, 1, n); // 12 - libero
add_field("L4", 144, 1, n); // 13 - libero
add_field("L5", 145,1, n); // 14 - libero
add_field("DATADOC", 146, 10, a); // 15 - data documento
add_field("C0", 156, 10, a); // 16 - vero - falso
add_field("C1", 166, 1, a); // 17 - E
add_field("C2", 167, 15, a); // 18 - Contanti - Bancomat
add_field("GT", 182, 2, a); // 19 - gt
add_field("L6", 184, 10, a); // 20 - libero
add_field("BOLLO", 194, 10, n); // 21 - 2 decimali Valore Bollo
add_field("DATA", 204, 10, a); // 22 - Data di creazione file movimenti
add_field("L7", 214, 10, a); // 23 - libero
add_field("COGNOME", 224, 30, a); // 24 - Cognome o Ragione Sociale
add_field("NOME", 254, 19, a); // 25 - Nome o Seguito ragione sociale
add_field("CODFIS", 273, 16, a); // 26 - Codice fiscale
add_field("PIVA", 289, 11, n); // 27 - Partita I.v.a.
add_field("INDIR", 300, 35, a); // 28 - Indirizzo
add_field("CITTA", 335, 20, a); // 29 - Citt<74>
add_field("PROV", 355, 2, a); // 30 - Provincia
add_field("CAP", 357, 5, n); // 31 - C.A.P.
add_field("TIPOERS", 362, 1, a); // 32 - P= persona fisica o D = Ditta
add_field("SESSO", 363, 1, a); // 32 - F=Femmina M=Maschio
add_field("L8", 364, 7, n); // 33 - libero
add_field("L9", 371, 7, n); // 34 - libero
add_field("L10", 378, 7, n); // 35 - libero
add_field("FINE-RECORD", 385, 2, a, "\r\n"); // 36 - end of record
}
///////////////////////////////////////////////////////////
// TLandi_mask
///////////////////////////////////////////////////////////
class TLandi_mask : public TAutomask
{
private:
void serialize(bool bSave);
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TLandi_mask();
virtual ~TLandi_mask();
};
TLandi_mask::TLandi_mask() : TAutomask("pg0001300a")
{
serialize(false);
}
TLandi_mask::~TLandi_mask()
{
serialize(true);
}
bool TLandi_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
{
return TRUE;
}
HIDDEN bool browse_file_handler(TMask_field& f, KEY k)
{
if (k == K_F9)
{
FILE_SPEC fs; memset(&fs, 0, sizeof(FILE_SPEC));
strcpy(fs.type, "");
strcpy(fs.name, f.get());
xvt_fsys_get_default_dir(&fs.dir);
xvt_fsys_save_dir();
if (xvt_dm_post_file_open(&fs, TR("Selezione file")) == FL_OK)
{
TFilename n;
xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(n.size()), n.size());
n.add(fs.name);
f.set(n);
}
xvt_fsys_restore_dir();
f.set_focus();
}
return true;
}
void TLandi_mask::serialize(bool bSave)
{
const char* defpar = "ps";
TConfig ini(CONFIG_DITTA, defpar);
for (int i = fields()-1; i >= 0; i--)
{
TMask_field& f = fld(i);
const TFieldref* fr = f.field();
if (fr != NULL)
{
if (bSave)
fr->write(ini, defpar, f.get());
else
f.set(fr->read(ini, defpar));
}
}
}
///////////////////////////////////////////////////////////
// TLandi_converter
///////////////////////////////////////////////////////////
class TLandi_converter : public TSkeleton_application
{
TLandi_mask * _mask;
TLog_report * _log;
protected:
virtual bool create() { return TSkeleton_application::create ();}
virtual bool destroy();
virtual void main_loop();
virtual TMask & get_mask();
virtual const char * extra_modules() const {return "ba";}
public:
TLandi_converter() : _mask(NULL) {}
};
TLandi_converter& app() { return (TLandi_converter&)main_app(); }
bool TLandi_converter::destroy()
{
delete _mask;
return TApplication::destroy();
}
TMask & TLandi_converter::get_mask()
{
if (_mask == NULL)
_mask = new TLandi_mask;
return * _mask;
}
void TLandi_converter::main_loop()
{
TMask & m = get_mask();
while (m.run() == K_ENTER)
{
const char* const title = TR("Conversione da formato Excel a Colonne fisse");
bool errors_logged = false;
TString query("CSV(\";\")\nSELECT * FROM ");
TFilename name = m.get(F_INPATH);
name.add(m.get(F_INFILE));
query << name;
TCSV_recordset input(query);
// const int ncols = input.columns();
TFixed_recset output;
_log = new TLog_report(title);
input.move_first();
for (bool ok = input.move_next(); ok ; ok = input.move_next())
{
output.new_rec("");
for (int i = 0; i < 36; i++)
{
const TVariant &var = input.get(i);
output.set(i, var);
}
}
TReport_book book;
book.add(*_log);
book.preview();
bool save = true;
if (errors_logged)
{
save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
"Si desidera creare i documenti ugualmente?"));
}
if (save)
{
name = m.get(F_PATH);
name.add(m.get(F_FILE));
output.save_as(name, fmt_text);
}
delete _log;
_log = NULL;
}
}
int pg0001300(int argc, char* argv[])
{
TLandi_converter app;
app.run(argc, argv, "Conversione Landi");
return 0;
}