Patch level : 10.0 nopatch
Files correlati : pd6342.exe Ricompilazione Demo : [ ] Commento Habilita ripartizione ricorsiva step 2 git-svn-id: svn://10.65.10.50/branches/R_10_00@20928 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
cc982cfdf9
commit
f7efda87b4
@ -58,10 +58,10 @@ public:
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TCSV_recordset
|
||||
// TCSV_recordset
|
||||
// Classe per file di testo con campi separati da virgola (o altro separatore)
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class TCSV_recordset : public TText_recordset
|
||||
{
|
||||
char _separator;
|
||||
|
243
ps/pd6342300.cpp
243
ps/pd6342300.cpp
@ -1,6 +1,8 @@
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <colors.h>
|
||||
#include <defmask.h>
|
||||
#include <progind.h>
|
||||
#include <recarray.h>
|
||||
#include <relation.h>
|
||||
#include <textset.h>
|
||||
@ -53,18 +55,20 @@ bool TRib_movanal_msk::on_field_event(TOperable_field& o, TField_event e, long j
|
||||
return TAnal_report_mask::on_field_event(o, e, jolly);
|
||||
}
|
||||
|
||||
TRib_movanal_msk::TRib_movanal_msk() : TAnal_report_mask("ca2200a")
|
||||
TRib_movanal_msk::TRib_movanal_msk() : TAnal_report_mask("pd6342300a")
|
||||
{
|
||||
}
|
||||
|
||||
class TCSV_recset : public TCSV_recordset
|
||||
{
|
||||
public:
|
||||
bool save_as_html(const char* path);
|
||||
TCSV_recset(TAssoc_array & calc);
|
||||
};
|
||||
|
||||
TCSV_recset::TCSV_recset(TAssoc_array & calc) : TCSV_recordset(TString("CSV(;)\n"))
|
||||
TCSV_recset::TCSV_recset(TAssoc_array & calc) : TCSV_recordset("CSV(;)\n")
|
||||
{
|
||||
set_separator(';');
|
||||
TAssoc_array kcol;
|
||||
TString_array rowkeys;
|
||||
TString_array colkeys;
|
||||
@ -78,37 +82,38 @@ TCSV_recset::TCSV_recset(TAssoc_array & calc) : TCSV_recordset(TString("CSV(;)\n
|
||||
kcol.add(colkey);
|
||||
}
|
||||
rowkeys.sort();
|
||||
krow.get_keys(colkeys);
|
||||
kcol.get_keys(colkeys);
|
||||
colkeys.sort();
|
||||
create_columns(colkeys.items() + 1);
|
||||
destroy_column();
|
||||
|
||||
const int ncols = columns();
|
||||
const int ncols = colkeys.items();
|
||||
const int nrows = rowkeys.items();
|
||||
TString colname(20);
|
||||
|
||||
TRecordset_column_info & c = (TRecordset_column_info &) column_info(0);
|
||||
|
||||
c._name = "Key";
|
||||
create_column("Key");
|
||||
new_rec("");
|
||||
for (int i= 1; i < ncols; i++)
|
||||
{
|
||||
TRecordset_column_info & c = (TRecordset_column_info &) column_info(i);
|
||||
|
||||
c._name = colkeys.row(i);
|
||||
c._name.ltrim(5);
|
||||
colname = colkeys.row(i - 1);
|
||||
colname.replace(',', ' ');
|
||||
colname.strip_double_spaces();
|
||||
create_column(colname);
|
||||
set(i, colname);
|
||||
}
|
||||
for (int i= 0; i < ncols; i++)
|
||||
for (int i= 0; i < nrows; i++)
|
||||
{
|
||||
new_rec("");
|
||||
TString rowkey = rowkeys.row(i);
|
||||
TAssoc_array * row = (TAssoc_array *) calc.objptr(rowkey);
|
||||
|
||||
rowkey.ltrim(5);
|
||||
rowkey.replace(',', ' ');
|
||||
rowkey.strip_double_spaces();
|
||||
set(0, rowkey);
|
||||
if (row != NULL)
|
||||
{
|
||||
for (int j= 1; j < ncols; j++)
|
||||
{
|
||||
const TRecordset_column_info & c = column_info(i);
|
||||
const real * val = (const real *) row->objptr(c._name);
|
||||
const real * val = (const real *) row->objptr(colkeys.row(j - 1));
|
||||
if (val != NULL)
|
||||
set(j, *val);
|
||||
}
|
||||
@ -116,6 +121,119 @@ TCSV_recset::TCSV_recset(TAssoc_array & calc) : TCSV_recordset(TString("CSV(;)\n
|
||||
}
|
||||
}
|
||||
|
||||
bool TCSV_recset::save_as_html(const char* path)
|
||||
{
|
||||
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
|
||||
ofstream out(path);
|
||||
out << "<html>" << endl;
|
||||
save_html_head(out, main_app().title());
|
||||
out << "<body>" << endl;
|
||||
|
||||
TString qry; parsed_text(qry);
|
||||
if (qry.full())
|
||||
{
|
||||
for (int i = qry.find('\n'); i > 0; i = qry.find('\n', i+1))
|
||||
qry.insert("<br/>", i+1);
|
||||
out << "<p><b>" << qry << "</b></p>" << endl;
|
||||
}
|
||||
|
||||
out << "<table border=\"1\">";
|
||||
out << " <caption>" << main_app().title() << "</caption>" << endl;
|
||||
|
||||
const unsigned int cols = columns();
|
||||
if (cols > 0)
|
||||
{
|
||||
out << " <thead>" << endl;
|
||||
for (unsigned int c = 0; c < cols; c++)
|
||||
{
|
||||
const TRecordset_column_info& ci = column_info(c);
|
||||
out << " <col ";
|
||||
switch (ci._type)
|
||||
{
|
||||
case _intfld :
|
||||
case _longfld:
|
||||
case _realfld: out << "align=\"right\""; break;
|
||||
case _boolfld: out << "align=\"center\""; break;
|
||||
default : out << "style=\"mso-number-format:\\@\""; break;
|
||||
}
|
||||
out << " />" << endl;
|
||||
}
|
||||
|
||||
TXmlItem tr; tr.SetTag("tr");
|
||||
tr.SetColorAttr("bgcolor", BTN_BACK_COLOR);
|
||||
tr.Write(out, 2);
|
||||
out << endl;
|
||||
|
||||
for (unsigned int c = 0; c < cols; c++)
|
||||
{
|
||||
const TRecordset_column_info& ci = column_info(c);
|
||||
TToken_string header(ci._name, '\n');
|
||||
TString str;
|
||||
FOR_EACH_TOKEN(header, tok)
|
||||
{
|
||||
if (str.not_empty())
|
||||
str << "<br/>";
|
||||
str << tok;
|
||||
}
|
||||
out << " <th>" << str << "</th>" << endl;
|
||||
}
|
||||
out << " </tr>" << endl;
|
||||
out << " </thead>" << endl;
|
||||
}
|
||||
|
||||
out << " <tbody>" << endl;
|
||||
TString val;
|
||||
for (bool ok = move_first(); ok; ok = move_next())
|
||||
{
|
||||
if (!pi.addstatus(1))
|
||||
break;
|
||||
|
||||
out << " <tr>" << endl;
|
||||
for (unsigned int c = 0; c < cols; c++)
|
||||
{
|
||||
const TRecordset_column_info& ci = column_info(c);
|
||||
out << " <td>";
|
||||
switch (ci._type)
|
||||
{
|
||||
case _intfld:
|
||||
case _longfld:
|
||||
{
|
||||
const long r = get(c).as_int();
|
||||
val.cut(0);
|
||||
if (r != 0)
|
||||
val << r;
|
||||
}
|
||||
break;
|
||||
case _realfld:
|
||||
{
|
||||
const real r = get(c).as_real();
|
||||
if (r.is_zero())
|
||||
val.cut(0);
|
||||
else
|
||||
val = r.stringe();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
get(c).as_string(val);
|
||||
break;
|
||||
}
|
||||
if (val.full())
|
||||
{
|
||||
val.rtrim();
|
||||
out << val;
|
||||
}
|
||||
out << "</td>" << endl;
|
||||
}
|
||||
out << " </tr>" << endl;
|
||||
}
|
||||
out << " </tbody>" << endl;
|
||||
out << "</table>" << endl;
|
||||
out << "</body>" << endl;
|
||||
out << "</html>" << endl;
|
||||
|
||||
return !pi.iscancelled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// APPLICAZIONE
|
||||
//--------------------------------------------------------------------
|
||||
@ -126,10 +244,11 @@ class TRib_movanal_app : public TSkeleton_application
|
||||
TAssoc_array _calc;
|
||||
|
||||
protected:
|
||||
virtual const char * extra_modules() const {return "ca";}
|
||||
virtual void main_loop();
|
||||
|
||||
bool elabora_righe(TAnal_mov& anal_mov, TRecord_array& input_rows, TRecord_array& output_rows);
|
||||
bool ripartizione(const TAnal_ripartizioni_batch& rrip, const TRectype& rec, const TToken_string& path, TRecord_array& output_rows, TArray & output_paths);
|
||||
bool ripartizione(const TAnal_ripartizioni_batch& rrip, const TRectype& rec, const TToken_string& path_item, TRecord_array& output_rows, TArray & output_paths);
|
||||
bool pareggio(TAnal_mov& anal_mov, const TAnal_ripartizioni_batch& rrip, const TRectype& rec, const TToken_string& path, TRecord_array& output_rows, TArray & output_paths);
|
||||
|
||||
public:
|
||||
@ -171,30 +290,45 @@ bool TRib_movanal_app::pareggio(TAnal_mov& anal_mov, const TAnal_ripartizioni_ba
|
||||
return ho_pareggiato;
|
||||
}
|
||||
|
||||
bool TRib_movanal_app::ripartizione(const TAnal_ripartizioni_batch& rrip, const TRectype& rec, const TToken_string& path, TRecord_array& output_rows, TArray & output_paths)
|
||||
bool TRib_movanal_app::ripartizione(const TAnal_ripartizioni_batch& rrip, const TRectype& rec, const TToken_string& path_item, TRecord_array& output_rows, TArray & output_paths)
|
||||
{
|
||||
bool ho_ripartito = false;
|
||||
// Importo totale da distribuire arrotondato ai decimali della valuta di conto
|
||||
const real importo = rec.get_real(RMOVANA_IMPORTO);
|
||||
const char sez = rec.get_char(RMOVANA_SEZIONE);
|
||||
TGeneric_distrib distrib(importo, TCurrency::get_firm_dec());
|
||||
TToken_string rowkey("Code", ',');
|
||||
TToken_string rowkey("", ',');
|
||||
|
||||
rowkey.add(rec.get(RMOVANA_CODCCOSTO));
|
||||
rowkey.add(rec.get(RMOVANA_CODCMS));
|
||||
rowkey.add(rec.get(RMOVANA_CODFASE));
|
||||
rowkey.add(rec.get(RMOVANA_CODCONTO));
|
||||
// rowkey.add(rec.get(RMOVANA_CODCONTO));
|
||||
TToken_string browkey = rowkey;
|
||||
|
||||
TAssoc_array * row = (TAssoc_array *)_calc.objptr(rowkey);
|
||||
TAssoc_array * row = (TAssoc_array *)_calc.objptr(browkey);
|
||||
|
||||
if (row == NULL)
|
||||
row = (TAssoc_array *) _calc.add(rowkey, new TAssoc_array);
|
||||
_calc.add(browkey, row = new TAssoc_array);
|
||||
|
||||
real * value = (real *) row->objptr(rowkey);
|
||||
real * value = (real *) row->objptr(browkey);
|
||||
|
||||
if (value == NULL)
|
||||
value = (real *) row->add(rowkey, new real);
|
||||
row->add(rowkey, value = new real);
|
||||
|
||||
*value -= importo;
|
||||
*value = *value + (sez == 'D' ? importo : -importo);
|
||||
|
||||
rowkey.add("Rip");
|
||||
row = (TAssoc_array *)_calc.objptr(rowkey);
|
||||
|
||||
if (row == NULL)
|
||||
_calc.add(rowkey, row = new TAssoc_array);
|
||||
|
||||
value = (real *) row->objptr(rowkey);
|
||||
|
||||
if (value == NULL)
|
||||
row->add(rowkey, value = new real);
|
||||
|
||||
*value = *value + (sez == 'D' ? -importo : importo);
|
||||
// Calcolo tutte le percentuali da ripartire
|
||||
int i;
|
||||
const int righe_ripartizione = rrip.rows();
|
||||
@ -230,25 +364,30 @@ bool TRib_movanal_app::ripartizione(const TAnal_ripartizioni_batch& rrip, const
|
||||
ca_copia_campo(rec, RMOVANA_CODCCORI, *newrec, RMOVANA_CODCONTORI);
|
||||
}
|
||||
//e mette nei campi std i valori che trova nelle righe ripartizione
|
||||
ca_copia_campo(rrip[i], RRIP_CODCOSTO, *newrec, RMOVANA_CODCCOSTO);
|
||||
|
||||
ca_copia_campo(rrip[i], RRIP_CODCOSTO, *newrec, RMOVANA_CODCCOSTO);
|
||||
ca_copia_campo(rrip[i], RRIP_CODCMS, *newrec, RMOVANA_CODCMS);
|
||||
ca_copia_campo(rrip[i], RRIP_CODFASE, *newrec, RMOVANA_CODFASE);
|
||||
ca_copia_campo(rrip[i], RRIP_CODCONTO, *newrec, RMOVANA_CODCONTO);
|
||||
TToken_string ripkey("", ',');
|
||||
|
||||
output_rows.add_row(newrec);
|
||||
output_paths.add(path);
|
||||
TToken_string ripkey("Code", ',');
|
||||
ripkey.add(newrec->get(RMOVANA_CODCCOSTO));
|
||||
ripkey.add(newrec->get(RMOVANA_CODCMS));
|
||||
ripkey.add(newrec->get(RMOVANA_CODFASE));
|
||||
// ripkey.add(newrec->get(RMOVANA_CODCONTO));
|
||||
|
||||
ripkey.add(rec.get(RMOVANA_CODCCOSTO));
|
||||
ripkey.add(rec.get(RMOVANA_CODCMS));
|
||||
ripkey.add(rec.get(RMOVANA_CODFASE));
|
||||
ripkey.add(rec.get(RMOVANA_CODCONTO));
|
||||
int r = output_rows.add_row(newrec);
|
||||
TToken_string * rowpath = (TToken_string *) output_paths.objptr(r);
|
||||
|
||||
if (rowpath == NULL)
|
||||
output_paths.add(rowpath = new TToken_string, r);
|
||||
rowpath->add(path_item);
|
||||
|
||||
real * value = (real *) row->objptr(ripkey);
|
||||
|
||||
if (value == NULL)
|
||||
value = (real *) row->add(ripkey, new real);
|
||||
*value += imp;
|
||||
row->add(ripkey, value = new real);
|
||||
*value = *value + (sez == 'D' ? imp : -imp);
|
||||
|
||||
ho_ripartito = true;
|
||||
} //if(imp!=ZERO)...
|
||||
@ -271,7 +410,9 @@ bool TRib_movanal_app::elabora_righe(TAnal_mov& anal_mov, TRecord_array& input_r
|
||||
while (loop++ < 50)
|
||||
{
|
||||
bool modified = false;
|
||||
for (int r = 1; r <= input_rows.rows(); r++)
|
||||
const int nrows = input_rows.rows();
|
||||
|
||||
for (int r = 1; r <= nrows; r++)
|
||||
{
|
||||
const TRectype& rec = input_rows.row(r);
|
||||
TAnal_bill zio(rec);
|
||||
@ -279,10 +420,10 @@ bool TRib_movanal_app::elabora_righe(TAnal_mov& anal_mov, TRecord_array& input_r
|
||||
|
||||
//ripartizione batch: passa il conto perche' per prima cosa provera' una ripartizione di tipo 'P' con chiave 3; se non..
|
||||
//..ci riuscira', provera' da solo (metodi della TCache_ripartizioni) le ripartizioni di tipo 'B' con chiave 4.
|
||||
const TAnal_ripartizioni_batch& rrip = _cache_rip.righe(zio, annoes, rmovana_indbil, tipomov);
|
||||
const TAnal_ripartizioni_batch& rrip = _cache_rip.righe(zio, annoes, rmovana_indbil, tipomov);
|
||||
if (input_paths.objptr(r) == NULL)
|
||||
input_paths.add(new TToken_string, r);
|
||||
const TToken_string & input_path = (TToken_string &) input_paths[r];
|
||||
TToken_string & input_path = (TToken_string &) input_paths[r];
|
||||
const char tiporip = rrip.tiporip();
|
||||
|
||||
//ci sono righe di ripartizione
|
||||
@ -290,23 +431,26 @@ bool TRib_movanal_app::elabora_righe(TAnal_mov& anal_mov, TRecord_array& input_r
|
||||
bool ripartisci = righe_ripartizione > 0;
|
||||
|
||||
//se ci sono righe di ripartizione/pareggio si va a ripartire!
|
||||
TToken_string path_item("Code", ',');
|
||||
TToken_string path_item("", ',');
|
||||
|
||||
path_item.add(rec.get(RRIP_CODCOSTO));
|
||||
path_item.add(rec.get(RRIP_CODCMS));
|
||||
path_item.add(rec.get(RRIP_CODFASE));
|
||||
path_item.add(rec.get(RRIP_CODCONTO));
|
||||
path_item.add(rec.get(RMOVANA_CODCCOSTO));
|
||||
path_item.add(rec.get(RMOVANA_CODCMS));
|
||||
path_item.add(rec.get(RMOVANA_CODFASE));
|
||||
path_item.add(rec.get(RMOVANA_CODCONTO));
|
||||
|
||||
if (rec.get(RMOVANA_CODCMS) == "0101")
|
||||
int i = 1;
|
||||
|
||||
if (ripartisci)
|
||||
ripartisci = input_path.find(path_item) < 0;
|
||||
if (ripartisci)
|
||||
input_path.add(path_item);
|
||||
if (ripartisci)
|
||||
{
|
||||
input_paths.add(path_item);
|
||||
switch (tiporip)
|
||||
{
|
||||
//procedura di ripartizione batch 'B' originale; se tiporip=='P' invece ci vuole il pareggio del movana
|
||||
case 'B':
|
||||
modified |= ripartizione(rrip, rec, input_path, output_rows, output_paths);
|
||||
modified |= ripartizione(rrip, rec, path_item, output_rows, output_paths);
|
||||
break;
|
||||
case 'P':
|
||||
modified |= pareggio(anal_mov, rrip, rec, input_path, output_rows, output_paths);
|
||||
@ -320,14 +464,13 @@ bool TRib_movanal_app::elabora_righe(TAnal_mov& anal_mov, TRecord_array& input_r
|
||||
TRectype* newrec = new TRectype(rec);
|
||||
newrec->put(RMOVANA_NUMRIG, output_rows.rows() + 1);
|
||||
output_rows.add_row(newrec);
|
||||
output_paths.add(input_path, output_rows.rows() + 1);
|
||||
}
|
||||
} //for(int r=1; r<=input_rows.rows()...
|
||||
} //for(int r=1; r<=nrows...
|
||||
if (modified)
|
||||
{
|
||||
ho_cambiato_qualchecosa = true;
|
||||
input_rows = output_rows;
|
||||
input_paths = output_paths;
|
||||
// input_paths = output_paths;
|
||||
}
|
||||
else
|
||||
break;
|
||||
@ -468,7 +611,7 @@ void TRib_movanal_app::main_loop()
|
||||
{
|
||||
TCSV_recset recset(_calc);
|
||||
|
||||
recset.save_as(fname);
|
||||
recset.save_as_html(fname);
|
||||
}
|
||||
} //if(run)...
|
||||
}
|
||||
|
@ -83,19 +83,20 @@ BEGIN
|
||||
PROMPT 2 7 "Blocca movimenti elaborati (DEFINITIVO e vale solo per ripartizione)"
|
||||
END
|
||||
|
||||
GROUPBOX DLG_NULL 78 8
|
||||
GROUPBOX DLG_NULL 78 4
|
||||
BEGIN
|
||||
PROMPT 1 8 "@bFoglio Excel del calcolo"
|
||||
PROMPT 1 9 "@bFoglio Excel del calcolo"
|
||||
END
|
||||
|
||||
STRING F_PATH 255 50
|
||||
BEGIN
|
||||
PROMPT 2 9 "Cartella "
|
||||
PROMPT 2 10 "Cartella "
|
||||
DSELECT
|
||||
END
|
||||
|
||||
STRING F_NAME 255 50
|
||||
BEGIN
|
||||
PROMPT 2 10 "File "
|
||||
PROMPT 2 11 "File "
|
||||
FSELECT "*.xls"
|
||||
END
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user