Files correlati : Ricompilazione Demo : [ ] Commento :stampa bilancio di commessa; commit di sicurezza;comincia a stampare le commesse in modo "umano" git-svn-id: svn://10.65.10.50/trunk@14140 c028cbd2-c16b-5b4b-a496-9718f37d4682
457 lines
12 KiB
C++
Executable File
457 lines
12 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <reprint.h>
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
#include "ca3.h"
|
|
#include "ca3800.h"
|
|
#include "calib01.h"
|
|
#include "calib02.h"
|
|
#include "commesse.h"
|
|
#include "panapdc.h"
|
|
#include "pconana.h"
|
|
#include "saldana.h"
|
|
|
|
////////////////////////////////////////////////////////
|
|
// MASCHERA
|
|
////////////////////////////////////////////////////////
|
|
class TPrint_bilancio_cms_mask : public TAnal_report_mask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
const TString& get_report_class() const;
|
|
bool test_compatible_report();
|
|
|
|
public:
|
|
TPrint_bilancio_cms_mask();
|
|
virtual ~TPrint_bilancio_cms_mask() {}
|
|
};
|
|
|
|
const TString& TPrint_bilancio_cms_mask::get_report_class() const
|
|
{
|
|
TString& classe = get_tmp_string();
|
|
classe = "ca3800a";
|
|
return classe;
|
|
}
|
|
|
|
bool TPrint_bilancio_cms_mask::test_compatible_report()
|
|
{
|
|
const TString& cls = get_report_class();
|
|
const TString& name = get(F_REPORT);
|
|
bool ok = name.not_empty();
|
|
if (ok)
|
|
{
|
|
TReport rep;
|
|
ok = rep.load(name);
|
|
if (ok)
|
|
{
|
|
const TString& classe = rep.get_class();
|
|
ok = classe == cls;
|
|
}
|
|
}
|
|
if (!ok)
|
|
{
|
|
set(F_REPORT, cls);
|
|
TFilename path = cls;
|
|
path.ext("rep");
|
|
ok = path.custom_path();
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TPrint_bilancio_cms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_REPORT:
|
|
if (e == fe_button)
|
|
{
|
|
const TString8 lib = get_report_class();
|
|
TFilename path = o.get();
|
|
if (select_custom_file(path, "rep", lib))
|
|
{
|
|
path = path.name();
|
|
path.ext("");
|
|
o.set(path);
|
|
}
|
|
} else
|
|
if (e == fe_close)
|
|
{
|
|
if (!test_compatible_report())
|
|
return error_box(TR("Impossibile trovare un report compatibile"));
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return TAnal_report_mask::on_field_event(o, e, jolly);
|
|
}
|
|
|
|
|
|
TPrint_bilancio_cms_mask::TPrint_bilancio_cms_mask()
|
|
:TAnal_report_mask("ca3800")
|
|
{
|
|
TConfig& cfg = ca_config();
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
const TMultilevel_code_info& pconana_info = ca_multilevel_code_info(LF_PCONANA);
|
|
const int pconana_levels = pconana_info.levels();
|
|
|
|
int prefix = cfg.get_int("PdcPrefix");
|
|
if (prefix >= pconana_levels)
|
|
prefix = pconana_levels-1;
|
|
|
|
// Controllo se voglio (e posso) usare il conto analitico come prefisso di quello contabile
|
|
if (use_pdcc && prefix > 0)
|
|
{
|
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
|
const int levels = info.levels();
|
|
if (levels >= 2 && prefix < levels && esistono_riclassificazioni())
|
|
{
|
|
ca_create_fields(*this, 0, LF_PCONANA, 1, 13, F_PRE1, F_PREDES1, 0x0, PCONANA_CODCONTO);
|
|
|
|
// Nascondi i campi che non fanno parte del prefisso
|
|
for (int i = 0; i < levels; i++)
|
|
{
|
|
if (i < prefix)
|
|
{
|
|
field(F_PRE1 + i).check_type(CHECK_REQUIRED);
|
|
field(F_PRE1 + i).set_group(6);
|
|
field(F_PREDES1 + i).set_group(6);
|
|
}
|
|
else
|
|
{
|
|
field(F_PRE1 + i).hide();
|
|
field(F_PREDES1 + i).hide();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// setta gli handlers a tutti i campi generati della maschera;senza questa chiamata la on_field_event
|
|
// non puo' funzionare sui campi generati!!!
|
|
set_handlers();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
// CACHE INDICATORI BILANCIO
|
|
///////////////////////////////////////////////////////////////
|
|
class TIndbil_cache : public TCache
|
|
{
|
|
bool _usepdcc;
|
|
TString80 _prefix;
|
|
|
|
protected:
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
public:
|
|
int get_indbil(const TString& conto);
|
|
void set_prefix(const char* prefix);
|
|
TIndbil_cache();
|
|
|
|
};
|
|
|
|
TObject* TIndbil_cache::key2obj(const char* key)
|
|
{
|
|
TString80 conto = key;
|
|
if (_usepdcc)
|
|
{
|
|
TLocalisamfile panapdc(LF_PANAPDC);
|
|
panapdc.setkey(2);
|
|
const int gr = atoi(conto.left(3));
|
|
const int co = atoi(conto.mid(3,3));
|
|
const long so = atol(conto.mid(6,6));
|
|
|
|
TRectype& panapdrec = panapdc.curr();
|
|
for (int i = 2; i >= 0; i--)
|
|
{
|
|
panapdrec.zero();
|
|
panapdrec.put(PANAPDC_GRUPPO, gr);
|
|
if (i > 0)
|
|
panapdrec.put(PANAPDC_CONTO, co);
|
|
if (i == 2)
|
|
panapdrec.put(PANAPDC_SOTTOCONTO, so);
|
|
|
|
//occhio al prefisso!
|
|
panapdrec.put(PANAPDC_CODCONTO, _prefix);
|
|
|
|
if (panapdc.read(_isgteq) == NOERR)
|
|
{
|
|
bool found = panapdrec.get_int(PANAPDC_GRUPPO) == gr;
|
|
if (found)
|
|
found = panapdrec.get_int(PANAPDC_CONTO) == (i > 0 ? co : 0);
|
|
if (found)
|
|
found = panapdrec.get_long(PANAPDC_SOTTOCONTO) == (i > 1 ? so : 0L);
|
|
if (found && _prefix.full())
|
|
found = panapdrec.get(PANAPDC_CODCONTO).starts_with(_prefix);
|
|
|
|
if (found)
|
|
{
|
|
conto = panapdrec.get(PANAPDC_CODCONTO);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//se non trova il corrispondente conto analitico azzera il conto per il prossimo giro
|
|
if (i < 0)
|
|
conto.cut(0);
|
|
}
|
|
//conto analitico
|
|
TAnal_bill bill(conto);
|
|
int indbil = bill.indicatore_bilancio();
|
|
TString* ib = new TString4;
|
|
*ib << indbil;
|
|
return ib;
|
|
}
|
|
|
|
int TIndbil_cache::get_indbil(const TString& conto)
|
|
{
|
|
TString* ib = (TString*)objptr(conto);
|
|
return ib ? atoi(*ib) : 0;
|
|
}
|
|
|
|
void TIndbil_cache::set_prefix(const char* prefix)
|
|
{
|
|
if (_prefix != prefix)
|
|
{
|
|
_prefix = prefix;
|
|
destroy();
|
|
}
|
|
}
|
|
|
|
TIndbil_cache::TIndbil_cache()
|
|
{
|
|
TConfig& cfg = ca_config();
|
|
_usepdcc = cfg.get_bool("UsePdcc");
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
// RECORDSET
|
|
///////////////////////////////////////////////////////////////
|
|
class TPrint_bilancio_cms_recordset : public TRecordset
|
|
{
|
|
TArray _righe;
|
|
TRecnotype _curr;
|
|
TArray _colonne;
|
|
TIndbil_cache _indicatori;
|
|
|
|
private:
|
|
int _anno;
|
|
bool _vitaintera, _use_fasi;
|
|
char _tipostima;
|
|
|
|
protected:
|
|
virtual TRecnotype items() const { return _righe.items(); }
|
|
virtual bool move_to(TRecnotype pos);
|
|
virtual TRecnotype current_row() const { return _curr; }
|
|
virtual void requery();
|
|
virtual const TString& query_text() const { return EMPTY_STRING; }
|
|
virtual unsigned int columns() const { return _colonne.items(); }
|
|
virtual const TRecordset_column_info& column_info(unsigned int column) const { return (TRecordset_column_info&) _colonne[column]; }
|
|
virtual const TVariant& get(unsigned int column) const;
|
|
virtual const TVariant& get(const char* column_name) const;
|
|
|
|
public:
|
|
virtual void set_filter(const TPrint_bilancio_cms_mask& msk);
|
|
};
|
|
|
|
|
|
bool TPrint_bilancio_cms_recordset::move_to(TRecnotype pos)
|
|
{
|
|
_curr = pos;
|
|
return pos >= 0 && pos < items();
|
|
}
|
|
|
|
void TPrint_bilancio_cms_recordset::requery()
|
|
{
|
|
//prende le date di inizio e fine dell'eserizio selezionato sulla maschera
|
|
TEsercizi_contabili esc;
|
|
TDate datainiesc, datafinesc;
|
|
esc.code2range(_anno, datainiesc, datafinesc);
|
|
|
|
//deve procedere al confronto tra le date inizio-fine esercizio e quelle inizio-fine commessa..
|
|
//..per spostare il record in esame nell'array corretto
|
|
TAssoc_array cms[4];
|
|
|
|
TString query;
|
|
query = "USE SALDANA";
|
|
//stampa standard non a vita intera
|
|
if (!_vitaintera)
|
|
query << "\nTO ANNO=" << _anno;
|
|
|
|
TISAM_recordset saldana(query);
|
|
for (bool ok = saldana.move_first(); ok; ok = saldana.move_next())
|
|
{
|
|
const TString& conto = saldana.get(SALDANA_CONTO).as_string();
|
|
//trova l'indicatore di bilancio
|
|
const int indbil = _indicatori.get_indbil(conto);
|
|
|
|
if (indbil == 3 || indbil == 4)
|
|
{
|
|
const TString& codcms = saldana.get(SALDANA_COMMESSA).as_string();
|
|
const TString& fase = saldana.get(SALDANA_FASE).as_string();
|
|
|
|
const TRectype& rec_commesse = cache().get(LF_COMMESSE, codcms);
|
|
|
|
const TDate dataini = rec_commesse.get(COMMESSE_DATAINIZIO);
|
|
const TDate datafine = rec_commesse.get(COMMESSE_DATAFINE);
|
|
//e' inutile considerare le commesse terminate prima dell'esercizio selezionato..
|
|
//..cioe' nel passato oppure che iniziano nel futuro!
|
|
if (datafine >= datainiesc && dataini <= datafinesc)
|
|
{
|
|
int indice = datafine <= datafinesc ? 0 : 2;
|
|
if (dataini >= datainiesc)
|
|
indice++;
|
|
|
|
TString80 chiave = codcms;
|
|
if (_use_fasi)
|
|
chiave << '|' << fase;
|
|
|
|
//cerca se la commessa (e l'eventuale fase) esistono gia' nell'assocarray delle commesse
|
|
TAssoc_array* riga_array = (TAssoc_array*)cms[indice].objptr(chiave);
|
|
//se non esiste la crea!
|
|
if (riga_array == NULL)
|
|
{
|
|
riga_array = new TAssoc_array;
|
|
|
|
TString4 str_indice; //l'indice va stringato per l'assoc_array
|
|
str_indice << indice;
|
|
|
|
riga_array->add("LEVEL", str_indice);
|
|
riga_array->add("CODCMS", codcms);
|
|
riga_array->add("FASE", fase);
|
|
riga_array->add("DESCRIZ", rec_commesse.get(COMMESSE_DESCRIZ));
|
|
|
|
//aggiunge la riga all'array-ino
|
|
cms[indice].add(chiave, riga_array);
|
|
}
|
|
} //if (datafine >= datainiesc &&...
|
|
|
|
} //if (indbil == 3 ||...
|
|
|
|
}
|
|
//merging dei 4 arrayini cms nell'arrayone _righe da mandare in stampa
|
|
_righe.destroy();
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
TAssoc_array& a = cms[i];
|
|
FOR_EACH_ASSOC_OBJECT(a, h, k, r)
|
|
_righe.add(h->remove_obj()); // Copia nella destinazione la riga corrente
|
|
}
|
|
}
|
|
|
|
const TVariant& TPrint_bilancio_cms_recordset::get(unsigned int column) const
|
|
{
|
|
return NULL_VARIANT;
|
|
}
|
|
|
|
const TVariant& TPrint_bilancio_cms_recordset::get(const char* column_name) const
|
|
{
|
|
if (_curr >= 0 && _curr < items())
|
|
{
|
|
if (*column_name == '#')
|
|
column_name++;
|
|
|
|
TVariant& var = get_tmp_var();
|
|
if (strcmp(column_name, "ANNO") == 0)
|
|
{
|
|
var.set(_anno);
|
|
}
|
|
else
|
|
{
|
|
TAssoc_array& riga = (TAssoc_array&)_righe[_curr];
|
|
const TString* val = (TString*)riga.objptr(column_name);
|
|
if (val)
|
|
var.set(*val);
|
|
}
|
|
return var;
|
|
}
|
|
return NULL_VARIANT;
|
|
}
|
|
|
|
|
|
void TPrint_bilancio_cms_recordset::set_filter(const TPrint_bilancio_cms_mask& msk)
|
|
{
|
|
//tira su un po' di parametri dalla maschera...
|
|
_anno = msk.get_int(F_ESERCIZIO);
|
|
_tipostima = msk.get(F_TIPOSTIMA)[0];
|
|
_vitaintera = msk.get_bool(F_VITAINTERA);
|
|
_use_fasi = msk.get_bool(F_FASI);
|
|
//prende anche il prefix
|
|
TString80 prefix;
|
|
for (short id = F_PRE1; id <= F_PRE3 && msk.id2pos(id) > 0; id++)
|
|
prefix << msk.get(id);
|
|
|
|
_indicatori.set_prefix(prefix);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
// REPORT
|
|
////////////////////////////////////////////////////////
|
|
class TPrint_bilancio_cms_rep : public TAnal_report
|
|
{
|
|
|
|
protected:
|
|
virtual bool set_recordset();
|
|
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
|
|
|
public:
|
|
void set_filter(const TPrint_bilancio_cms_mask& msk);
|
|
};
|
|
|
|
bool TPrint_bilancio_cms_rep::get_usr_val(const TString& name, TVariant& var) const
|
|
{
|
|
return TAnal_report::get_usr_val(name, var);
|
|
}
|
|
|
|
bool TPrint_bilancio_cms_rep::set_recordset()
|
|
{
|
|
TPrint_bilancio_cms_recordset* rs = new TPrint_bilancio_cms_recordset();
|
|
return TAnal_report::set_recordset(rs);
|
|
}
|
|
|
|
void TPrint_bilancio_cms_rep::set_filter(const TPrint_bilancio_cms_mask& msk)
|
|
{
|
|
TPrint_bilancio_cms_recordset* recset = new TPrint_bilancio_cms_recordset();
|
|
|
|
recset->set_filter(msk);
|
|
TAnal_report::set_recordset(recset);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
// APPLICAZIONE
|
|
////////////////////////////////////////////////////////
|
|
class TPrint_bilancio_cms : public TSkeleton_application
|
|
{
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void TPrint_bilancio_cms::main_loop()
|
|
{
|
|
TPrint_bilancio_cms_mask mask;
|
|
while (mask.run() == K_ENTER)
|
|
{
|
|
//report e book dei report
|
|
TReport_book book;
|
|
TString path = mask.get(F_REPORT);
|
|
if (path.empty())
|
|
path = "ca3800a";
|
|
TPrint_bilancio_cms_rep rep;
|
|
rep.load(path);
|
|
|
|
rep.set_filter(mask);
|
|
book.add(rep);
|
|
book.print_or_preview();
|
|
}
|
|
}
|
|
|
|
int ca3800(int argc, char* argv[])
|
|
{
|
|
TPrint_bilancio_cms a;
|
|
a.run(argc, argv, TR("Stampa bilancio di commessa"));
|
|
return 0;
|
|
}
|