Patch level : 12.0 no-patch

Files correlati     : ps6215.exe ps6215100a.msk
Commento            : Migliorato codice e aggiunte funzionalita' a TFixed_record
This commit is contained in:
Simone Palacino 2020-01-28 22:03:53 +01:00
parent daf7c79165
commit 1719a37695
2 changed files with 170 additions and 65 deletions

View File

@ -13,63 +13,55 @@
#include "cfven.h"
#include "sqlset.h"
#include <vector>
#include "ps6215partite.h"
#define CLIFO_RECLEN 730
#define D_ANNO 4
#define D_NUMPART 7
#define D_NRIGA 4
#define D_TIPOC 1 // ['C' | 'F'] (Cliente/Fornitore)
#define D_SOTTOCONTO 6
#define D_TIPOMOV 1
#define D_TIPOPAG 1
#define D_NREG 7
#define D_NUMRIG 3
#define D_DATAREG 8 // Formato data dd-MM-yyyy
#define D_DATADOC 8 // Formato data dd-MM-yyyy
#define D_DATAPAG 8 // Formato data dd-MM-yyyy
#define D_NUMDOC 7
#define D_REG 3
#define D_PROTIVA 5
#define D_CODCAUS 3
#define D_SEZ 1 // ['D' | 'A'] (Dare/Avere)
#define D_IMPORTO 18 // 18 con 3 decimali, segno, e virgola
#define D_IMPOSTA 18 // 18 con 3 decimali, segno, e virgola
#define D_SPESE 18 // 18 con 3 decimali, segno, e virgola
#define D_IMPTOTDOC 18 // 18 con 3 decimali, segno, e virgola
#define D_RITENUTE 18 // 18 con 3 decimali, segno, e virgola
#define D_RITSOC 18 // 18 con 3 decimali, segno, e virgola
#define D_SEZABB 1
#define D_ABBUONI 18 // 18 con 3 decimali, segno, e virgola
#define D_SEZDIFCAM 1
#define D_DIFFCAM 18 // 18 con 3 decimali, segno, e virgola
#define D_GRUPPOCL 3
#define D_CONTOCL 3
//const char* fields[] = { "ANNO", "NUMPART", "NRIGA", "TIPOC", "SOTTOCONTO", "TIPOMOV", "TIPOPAG", "NREG", "NUMRIG", "DATAREG", "DATADOC", "DATAPAG", "NUMDOC", "REG", "PROTIVA", "CODCAUS", "SEZ", "IMPORTO", "IMPOSTA", "SPESE", "IMPTOTDOC", "RITENUTE", "RITSOC", "SEZABB", "ABBUONI", "SEZDIFCAM", "DIFFCAM", "GRUPPOCL", "CONTOCL" };
const int dim_fields[] = { D_ANNO, D_NUMPART, D_NRIGA, D_TIPOC, D_SOTTOCONTO, D_TIPOMOV, D_TIPOPAG, D_NREG, D_NUMRIG, D_DATAREG, D_DATADOC, D_DATAPAG, D_NUMDOC, D_REG, D_PROTIVA, D_CODCAUS, D_SEZ, D_IMPORTO, D_IMPOSTA, D_SPESE, D_IMPTOTDOC, D_RITENUTE, D_RITSOC, D_SEZABB, D_ABBUONI, D_SEZDIFCAM, D_DIFFCAM, D_GRUPPOCL, D_CONTOCL };
class TFixed_record
{
int _items;
int* _dims;
int _tot_len;
char* _str;
int* _dims; /**< Array of the elements dimension. */
const char** _fields_name;
int _items;
char* _str; /**< Full record. */
int _tot_len; /**< \a _str dimension. */
/** Semplice controllo dell'indice degli elementi. */
bool check_index(int _Idx) const;
/** \returns la posizione reale nel record del campo all'indice \a _Idx. */
int pos(int _Idx) const;
int pos(int _Idx) const;
public:
void set_str(int _Idx, const char* _Str) const;
const char* const get_line() const { return static_cast<const char* const>(_str); }
TFixed_string operator[](int _Idx) const;
/** \returns la posizione dell'elemento che corrisponde alla colonna con il nome passato, se i nomi sono stati passati. */
int find_column(const char* field_name) const;
/** \returns il record per intero. */
const char* get_line() const { return (const char*)_str; }
/** \returns the name of the field at the given index. */
const char* get_name_field(int _Idx = 0) const;
/** Set the string \a _Str in the given position \a _Idx. */
void set_str(int _Idx, const char* _Str) const;
TFixed_record(int items = 0, const int dims[] = nullptr);
/** \returns a fixed string of the element at the index. */
TFixed_string operator[](int _Idx) const;
/** \returns a fixed string of the element of specified column name \a field_name. */
TFixed_string operator[](const char* field_name) const;
TFixed_record(int items, const int dims[]);
TFixed_record() : TFixed_record(0, nullptr) { }
TFixed_record(int items, const int dims[], const char* fields_name[]);
~TFixed_record();
};
bool TFixed_record::check_index(int _Idx) const
{
return _Idx >= 0 && _Idx <= _items;
}
int TFixed_record::pos(int _Idx) const
{
int real_idx = 0;
if (_Idx >= 0 && _Idx <= _items)
if (check_index(_Idx))
{
for (int i = 0; i < _Idx; ++i)
real_idx += _dims[i];
@ -77,6 +69,16 @@ int TFixed_record::pos(int _Idx) const
return real_idx;
}
int TFixed_record::find_column(const char* field_name) const
{
if (!_fields_name)
return -1;
for (int i = 0; i < _items; ++i)
if(strcmp(get_name_field(i), field_name) == 0)
return i;
return -1;
}
void TFixed_record::set_str(int _Idx, const char* _Str) const
{
const int p = pos(_Idx);
@ -84,11 +86,16 @@ void TFixed_record::set_str(int _Idx, const char* _Str) const
_str[i] = _Str[i - p];
}
const char* TFixed_record::get_name_field(int _Idx) const
{
return check_index(_Idx) && _fields_name ? _fields_name[_Idx] : "";
}
TFixed_string TFixed_record::operator[](int _Idx) const
{
static TFixed_string* f_str = nullptr;
delete f_str;
if (_Idx >= 0 && _Idx < _items)
if (check_index(_Idx))
{
const int p = pos(_Idx);
TString appo(_str);
@ -101,7 +108,12 @@ TFixed_string TFixed_record::operator[](int _Idx) const
return *f_str;
}
TFixed_record::TFixed_record(const int items, const int dims[]): _items(items), _tot_len(0)
TFixed_string TFixed_record::operator[](const char* field_name) const
{
return operator[](find_column(field_name));
}
TFixed_record::TFixed_record(const int items, const int dims[]) : _fields_name(nullptr), _items(items), _tot_len(0)
{
_dims = new int[items];
for (int i = 0; i < items; ++i)
@ -109,9 +121,23 @@ TFixed_record::TFixed_record(const int items, const int dims[]): _items(items),
_dims[i] = dims[i];
_tot_len += dims[i];
}
_str = new char[_tot_len + 1];
memset(_str, ' ', _tot_len + 1);
_str[_tot_len] = '\0';
_str = new char[++_tot_len];
memset(_str, ' ', _tot_len);
_str[_tot_len - 1] = '\0';
}
TFixed_record::TFixed_record(int items, const int dims[], const char* fields_name[]) : TFixed_record(items, dims)
{
_fields_name = new const char*[_items];
for(int i = 0; i < _items; ++i)
_fields_name[i] = fields_name[i];
}
TFixed_record::~TFixed_record()
{
delete[] _dims;
delete[] _fields_name;
delete[] _str;
}
///////////////////////////////////////////////////////////
@ -181,16 +207,18 @@ TComariExport_mask::TComariExport_mask() : TAutomask("ps6215100a")
void TComariExport_mask::save_all() const
{
ini_set_string(CONFIG_DITTA, "ps6215", "flddest", get(F_FLDDEST));
ini_set_string(CONFIG_DITTA, "ps6215", "clifor_bool", get(F_CLIFOR));
ini_set_string(CONFIG_DITTA, "ps6215", "flddest", get(F_FLDDEST));
ini_set_string(CONFIG_DITTA, "ps6215", "clifor_bool", get(F_CLIFOR));
ini_set_string(CONFIG_DITTA, "ps6215", "partopen_bool", get(F_PARTOPEN));
}
void TComariExport_mask::load_all()
{
TFilename temp;
temp.tempdir();
set(F_FLDDEST, ini_get_string(CONFIG_DITTA, "ps6215", "flddest", temp));
set(F_CLIFOR, ini_get_string(CONFIG_DITTA, "ps6215", "clifor_bool", "X"));
set(F_FLDDEST, ini_get_string(CONFIG_DITTA, "ps6215", "flddest", temp));
set(F_CLIFOR, ini_get_string(CONFIG_DITTA, "ps6215", "clifor_bool", "X"));
set(F_PARTOPEN, ini_get_string(CONFIG_DITTA, "ps6215", "partopen_bool", "X"));
}
///////////////////////////////////////////////////////////
@ -388,17 +416,32 @@ void TComariExport_app::export_clifo(ofstream& fout)
void TComariExport_app::export_parti(ofstream& fout)
{
TString4 last_game = ini_get_string(CONFIG_DITTA, "sc", "last_year_open_game", "2019");
const string year = (const char*)last_game;
const int y = stol(year);
const char* fields[] = {
PART_ANNO, PART_NUMPART, PART_NRIGA, PART_TIPOCF, PART_SOTTOCONTO, PART_TIPOMOV, PART_TIPOPAG, PART_NREG, PART_NUMRIG, PART_DATAREG, PART_DATADOC,
PART_DATAPAG, PART_NUMDOC, PART_REG, PART_PROTIVA, PART_CODCAUS, PART_SEZ, PART_IMPORTO, PART_IMPOSTA, PART_SPESE, PART_IMPTOTDOC, PART_RITENUTE,
PART_RITSOC, PART_SEZABB, PART_ABBUONI, PART_SEZDIFCAM, PART_DIFFCAM, PART_GRUPPOCL, PART_CONTOCL
};
const int dim_fields[] = {
D_ANNO, D_NUMPART, D_NRIGA, D_TIPOC, D_SOTTOCONTO, D_TIPOMOV, D_TIPOPAG, D_NREG, D_NUMRIG, D_DATAREG, D_DATADOC,
D_DATAPAG, D_NUMDOC, D_REG, D_PROTIVA, D_CODCAUS, D_SEZ, D_IMPORTO, D_IMPOSTA, D_SPESE, D_IMPTOTDOC, D_RITENUTE,
D_RITSOC, D_SEZABB, D_ABBUONI, D_SEZDIFCAM, D_DIFFCAM, D_GRUPPOCL, D_CONTOCL
};
TString4 last_game = ini_get_string(CONFIG_DITTA, "ps6215", "last_year_open_game", "2019");
const string year = (const char*)last_game;
const int y = stol(year);
if (y < 2000 || y > 2029)
last_game = "2019";
ini_set_string(CONFIG_DITTA, "sc", "last_game", last_game);
TString sql; sql << "SELECT ANNO, NUMPART, NRIGA, TIPOC, SOTTOCONTO, TIPOMOV, TIPOPAG, NREG, "\
"NUMRIG, DATAREG, DATADOC, DATAPAG, NUMDOC, REG, PROTIVA, CODCAUS, SEZ, IMPORTO, IMPOSTA, "\
"SPESE, IMPTOTDOC, RITENUTE, RITSOC, SEZABB, ABBUONI, SEZDIFCAM, DIFFCAM, GRUPPOCL, CONTOCL \n" <<
"FROM part WHERE CHIUSA<>'X' AND ANNO <=" << last_game << ";";
ini_set_string(CONFIG_DITTA, "ps6215", "last_game", last_game);
const int items = (int)(sizeof dim_fields / sizeof *dim_fields);
TString sql; sql << "SELECT ";
for (int i = 0; i < items - 1; ++i)
sql << fields[i] << ", ";
sql << fields[items - 1] << '\n';
sql << " FROM part WHERE CHIUSA<>'X' AND ANNO <=" << last_game << ";";
TSQL_recordset openpart(sql);
if (!openpart.items())
message_box("Non ci sono partite aperte al %s da esportare.", (const char*)last_game);
else if(openpart.move_first())
@ -408,16 +451,16 @@ void TComariExport_app::export_parti(ofstream& fout)
{
if (!bar.add_status())
break;
TFixed_record rec((int)(sizeof dim_fields / sizeof *dim_fields), dim_fields);
for (int i = 0; i < (int)(sizeof dim_fields / sizeof *dim_fields); ++i)
TFixed_record rec(items, dim_fields, fields);
for (int i = 0; i < items; ++i)
{
if (openpart.column_info(i)._type == _datefld)
{
TString ansi; ansi << TDate(openpart.get(i).as_date()).date2ansi();
if(ansi != "0")
if(ansi != "0") // Butto le date "vuote"
rec.set_str(i, ansi);
}
else if(i >= 17 && i <= 22 || i == 24 || i == 26) // reali (non so perche' ma becca come reali anche gli interi...)
else if(i >= I_IMPORTO && i <= I_RITSOC || i == I_ABBUONI || i == I_DIFFCAM) // reali (non so perche' ma becca come reali anche gli interi...)
rec.set_str(i, TString(openpart.get(i).as_real().string(18, 3, ' ')));
else
rec.set_str(i, openpart.get(i).as_string());
@ -460,13 +503,13 @@ bool TComariExport_app::export_table(const short id) const
}
name = "Clienti Fornitori";
break;
case F_PIANOCONTI:
case F_PIANOCONTI: // Not implemented
name_file = "pianoconti.txt";
path << "\\" << name_file;
ok = true;
name = "Piano dei Conti";
break;
case F_MASTRI:
case F_MASTRI: // Not implemented
name_file = "mastri.txt";
path << "\\" << name_file;
ok = true;

62
src/ps/ps6215partite.h Normal file
View File

@ -0,0 +1,62 @@
#include "partite.h"
#define D_ANNO 4
#define D_NUMPART 7
#define D_NRIGA 4
#define D_TIPOC 1 // ['C' | 'F'] (Cliente/Fornitore)
#define D_SOTTOCONTO 6
#define D_TIPOMOV 1
#define D_TIPOPAG 1
#define D_NREG 7
#define D_NUMRIG 3
#define D_DATAREG 8 // Formato data dd-MM-yyyy
#define D_DATADOC 8 // Formato data dd-MM-yyyy
#define D_DATAPAG 8 // Formato data dd-MM-yyyy
#define D_NUMDOC 7
#define D_REG 3
#define D_PROTIVA 5
#define D_CODCAUS 3
#define D_SEZ 1 // ['D' | 'A'] (Dare/Avere)
#define D_IMPORTO 18 // 18 con 3 decimali, segno, e virgola
#define D_IMPOSTA 18 // 18 con 3 decimali, segno, e virgola
#define D_SPESE 18 // 18 con 3 decimali, segno, e virgola
#define D_IMPTOTDOC 18 // 18 con 3 decimali, segno, e virgola
#define D_RITENUTE 18 // 18 con 3 decimali, segno, e virgola
#define D_RITSOC 18 // 18 con 3 decimali, segno, e virgola
#define D_SEZABB 1
#define D_ABBUONI 18 // 18 con 3 decimali, segno, e virgola
#define D_SEZDIFCAM 1
#define D_DIFFCAM 18 // 18 con 3 decimali, segno, e virgola
#define D_GRUPPOCL 3
#define D_CONTOCL 3
#define I_ANNO 0
#define I_NUMPART 1
#define I_NRIGA 2
#define I_TIPOC 3
#define I_SOTTOCONTO 4
#define I_TIPOMOV 5
#define I_TIPOPAG 6
#define I_NREG 7
#define I_NUMRIG 8
#define I_DATAREG 9
#define I_DATADOC 10
#define I_DATAPAG 11
#define I_NUMDOC 12
#define I_REG 13
#define I_PROTIVA 14
#define I_CODCAUS 15
#define I_SEZ 16
#define I_IMPORTO 17
#define I_IMPOSTA 18
#define I_SPESE 19
#define I_IMPTOTDOC 20
#define I_RITENUTE 21
#define I_RITSOC 22
#define I_SEZABB 23
#define I_ABBUONI 24
#define I_SEZDIFCAM 25
#define I_DIFFCAM 26
#define I_GRUPPOCL 27
#define I_CONTOCL 28