2005-03-17 14:20:42 +00:00
|
|
|
#include <xvt.h>
|
|
|
|
|
|
|
|
#include "calib01.h"
|
|
|
|
#include "calib02.h"
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
#include "../include/rdoc.h"
|
|
|
|
|
2005-06-23 12:16:21 +00:00
|
|
|
#include "movana.h"
|
2005-06-29 13:04:49 +00:00
|
|
|
#include "pconana.h"
|
2005-06-23 12:16:21 +00:00
|
|
|
#include "rmovana.h"
|
|
|
|
#include "saldana.h"
|
|
|
|
|
2005-06-29 13:04:49 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPconana_recordset
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const TVariant& TPconana_recordset::get(const char* column_name) const
|
|
|
|
{
|
|
|
|
if (strncmp(column_name, "SALDO:", 6) == 0)
|
|
|
|
{
|
|
|
|
TString16 sub_field = column_name+6;
|
|
|
|
const char last = sub_field.right(1)[0];
|
|
|
|
int tipimov = 0;
|
|
|
|
switch (last)
|
|
|
|
{
|
|
|
|
case 'C': tipimov = 1; sub_field.rtrim(1); break; // Consuntivo
|
|
|
|
case 'P':
|
|
|
|
case 'V': tipimov = 6; sub_field.rtrim(1); break; // Preventivo o variazaione preventivo
|
|
|
|
default : tipimov = _tipimov; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
((TAnal_bill&)_bill).set_conto(relation()->curr().get(PCONANA_CODCONTO));
|
|
|
|
const TSaldanal& s = ca_saldo(_bill, _dal, _al, tipimov);
|
|
|
|
|
|
|
|
TVariant& var = get_tmp_var();
|
|
|
|
if (strcmp(sub_field, "INI_DARE") == 0)
|
|
|
|
{
|
|
|
|
var = s._ini.sezione() == 'D' ? s._ini.valore() : ZERO;
|
|
|
|
} else
|
|
|
|
if (strcmp(sub_field, "INI_AVERE") == 0)
|
|
|
|
{
|
|
|
|
var = s._ini.sezione() == 'A' ? s._ini.valore() : ZERO;
|
|
|
|
} else
|
|
|
|
if (strcmp(sub_field, "MOV_DARE") == 0)
|
|
|
|
{
|
|
|
|
var = s._dare.valore();
|
|
|
|
} else
|
|
|
|
if (strcmp(sub_field, "MOV_AVERE") == 0)
|
|
|
|
{
|
|
|
|
var = s._avere.valore();
|
|
|
|
} else
|
|
|
|
if (strcmp(sub_field, "FIN_DARE") == 0)
|
|
|
|
{
|
|
|
|
var = s._fin.sezione() == 'D' ? s._fin.valore() : ZERO;
|
|
|
|
} else
|
|
|
|
if (strcmp(sub_field, "FIN_AVERE") == 0)
|
|
|
|
{
|
|
|
|
var = s._fin.sezione() == 'A' ? s._fin.valore() : ZERO;
|
|
|
|
}
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
if (strcmp(column_name, "#CMSCDC") == 0)
|
|
|
|
{
|
|
|
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_FASI);
|
|
|
|
switch (info.parent())
|
|
|
|
{
|
|
|
|
case LF_CDC : column_name = "#COSTO"; break;
|
|
|
|
case LF_COMMESSE: column_name = "#COMMESSA"; break;
|
|
|
|
default : return NULL_VARIANT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strcmp(column_name, "#COSTO") == 0)
|
|
|
|
return get_tmp_var() = _bill.costo();
|
|
|
|
if (strcmp(column_name, "#COMMESSA") == 0)
|
|
|
|
return get_tmp_var() = _bill.commessa();
|
|
|
|
if (strcmp(column_name, "#FASE") == 0)
|
|
|
|
return get_tmp_var() = _bill.fase();
|
|
|
|
|
|
|
|
return TISAM_recordset::get(column_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPconana_recordset::valid_record(const TRelation& rel) const
|
|
|
|
{
|
|
|
|
if (_movimentati || _nonnulli)
|
|
|
|
{
|
|
|
|
const TString& conto = rel.curr().get(PCONANA_CODCONTO);
|
|
|
|
((TAnal_bill&)_bill).set_conto(conto);
|
|
|
|
const TSaldanal& s = ca_saldo(_bill, _dal, _al, _tipimov);
|
|
|
|
if (_movimentati && !s._movimentato)
|
|
|
|
return false;
|
|
|
|
if (_nonnulli && s._ini.is_zero() && s._dare.is_zero() && s._avere.is_zero())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TPconana_recordset* _current_recset = NULL;
|
|
|
|
|
|
|
|
bool TPconana_recordset::pianoconti_filter(const TRelation* rel)
|
|
|
|
{ return _current_recset->valid_record(*rel); }
|
|
|
|
|
|
|
|
void TPconana_recordset::set_custom_filter(TCursor& cursor) const
|
|
|
|
{
|
|
|
|
TString filter;
|
|
|
|
filter << "LEN(" << PCONANA_CODCONTO << ")==" << _contolen;
|
|
|
|
cursor.setfilter(filter);
|
|
|
|
|
|
|
|
TRectype darec(LF_PCONANA), arec(LF_PCONANA);
|
|
|
|
darec.put(PCONANA_CODCONTO, _da_conto);
|
|
|
|
arec.put(PCONANA_CODCONTO, _a_conto);
|
|
|
|
cursor.setregion(darec, arec);
|
|
|
|
|
|
|
|
if (_movimentati || _nonnulli)
|
|
|
|
{
|
|
|
|
_current_recset = this;
|
|
|
|
cursor.set_filterfunction(pianoconti_filter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cursor.set_filterfunction(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPconana_recordset::set_filter(const char* da_conto, const char* a_conto,
|
|
|
|
const char* costo, const char* commessa, const char* fase,
|
|
|
|
const TDate& dal, const TDate& al,
|
|
|
|
word tipimov, bool movimentati, bool nonnulli)
|
|
|
|
{
|
|
|
|
_contolen = 0;
|
|
|
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
|
|
|
for (int l = info.levels()-1; l >= 0; l--)
|
|
|
|
_contolen += info.len(l);
|
|
|
|
|
|
|
|
_da_conto = da_conto;
|
|
|
|
_a_conto = a_conto;
|
|
|
|
|
|
|
|
_dal = dal;
|
|
|
|
_al = al;
|
|
|
|
|
|
|
|
_tipimov= tipimov;
|
|
|
|
_movimentati = movimentati;
|
|
|
|
_nonnulli = nonnulli;
|
|
|
|
|
|
|
|
_bill.reset();
|
|
|
|
_bill.set_costo(costo);
|
|
|
|
_bill.set_commessa(commessa);
|
|
|
|
_bill.set_fase(fase);
|
|
|
|
}
|
|
|
|
|
|
|
|
TPconana_recordset::TPconana_recordset() : TISAM_recordset("USE PCONANA")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
2005-06-23 12:16:21 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnal_report
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-21 11:46:26 +00:00
|
|
|
bool TAnal_report::get_usr_val(const TString& name, TVariant& var) const
|
|
|
|
{
|
|
|
|
// CODCONTO:1, CODCMS:3, FASCMS:2, ecc...
|
|
|
|
const int namelen = name.len();
|
|
|
|
if (namelen >= 6 && name[namelen-2] == ':')
|
|
|
|
{
|
|
|
|
int logicnum = 0;
|
|
|
|
if (name.starts_with("CODCONTO:"))
|
|
|
|
logicnum = LF_PCONANA; else
|
|
|
|
if (name.starts_with("CODCMS:"))
|
|
|
|
logicnum = LF_COMMESSE; else
|
|
|
|
if (name.starts_with("CODCOSTO:"))
|
|
|
|
logicnum = LF_CDC; else
|
|
|
|
if (name.starts_with("FASCMS:"))
|
|
|
|
logicnum = LF_FASI;
|
|
|
|
if (logicnum > 0)
|
|
|
|
{
|
|
|
|
const TMultilevel_code_info& mci = ca_multilevel_code_info(logicnum);
|
|
|
|
const int level = name[namelen-1]-'1';
|
|
|
|
if (level < mci.levels())
|
|
|
|
{
|
|
|
|
TString16 fldname = name; fldname.cut(namelen-2);
|
|
|
|
TFieldref field = mci.fieldref(level);
|
|
|
|
field.set_name(fldname);
|
|
|
|
field.set_from(0);
|
|
|
|
fldname.cut(0) << field; // Trasformo il TFieldref in stringa!
|
|
|
|
get_record_field(fldname, var);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
var.set_null();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TReport::get_usr_val(name, var);
|
|
|
|
}
|
|
|
|
|
2005-03-17 14:20:42 +00:00
|
|
|
size_t TAnal_report::get_usr_words(TString_array& words) const
|
|
|
|
{
|
|
|
|
TReport::get_usr_words(words);
|
|
|
|
|
|
|
|
const char* const name[] =
|
|
|
|
{
|
|
|
|
"CA_FORMAT_COSTO",
|
|
|
|
"CA_FORMAT_COMMESSA",
|
|
|
|
"CA_FORMAT_FASE",
|
|
|
|
"CA_FORMAT_CONTO",
|
2005-03-31 23:41:34 +00:00
|
|
|
"CA_FORMAT_CMSCDC",
|
2005-03-17 14:20:42 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
((TAnal_report*)this)->_first_msg = words.items(); // Calcola il primo numero disponibile
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; name[i] != NULL; i++)
|
|
|
|
words.add(name[i]);
|
|
|
|
|
|
|
|
return words.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnal_report::msg_format(int logicnum, TVariant_stack& stack)
|
|
|
|
{
|
|
|
|
const TString& str_in = curr_field()->get().as_string();
|
|
|
|
if (str_in.not_empty())
|
|
|
|
{
|
|
|
|
TString80 separator = " ";
|
|
|
|
if (stack.items() > 0)
|
|
|
|
separator = stack.pop().as_string();
|
|
|
|
if (separator.not_empty())
|
|
|
|
{
|
|
|
|
const TMultilevel_code_info& mci = ca_multilevel_code_info(logicnum);
|
|
|
|
TString str_out;
|
|
|
|
for (int i = 0; i < mci.levels(); i++)
|
|
|
|
{
|
|
|
|
const TFieldref& fld = mci.fieldref(i);
|
|
|
|
const TString& str = str_in.sub(fld.from(), fld.to());
|
|
|
|
if (str.not_empty())
|
|
|
|
{
|
|
|
|
if (i > 0) str_out << separator;
|
|
|
|
str_out << str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr_field()->set(str_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnal_report::msg_format_costo (TVariant_stack& stack)
|
|
|
|
{ msg_format(LF_CDC, stack); }
|
|
|
|
|
|
|
|
void TAnal_report::msg_format_commessa(TVariant_stack& stack)
|
|
|
|
{ msg_format(LF_COMMESSE, stack); }
|
|
|
|
|
|
|
|
void TAnal_report::msg_format_fase (TVariant_stack& stack)
|
|
|
|
{ msg_format(LF_FASI, stack); }
|
|
|
|
|
|
|
|
void TAnal_report::msg_format_conto (TVariant_stack& stack)
|
|
|
|
{ msg_format(LF_PCONANA, stack); }
|
|
|
|
|
2005-03-31 23:41:34 +00:00
|
|
|
void TAnal_report::msg_format_commessa_costo(TVariant_stack& stack)
|
|
|
|
{
|
|
|
|
const TMultilevel_code_info& main_info = ca_multilevel_code_info(LF_FASI);
|
|
|
|
msg_format(main_info.parent(), stack);
|
|
|
|
}
|
2005-06-21 11:46:26 +00:00
|
|
|
|
|
|
|
bool TAnal_report::execute_usr_word(unsigned int opcode, TVariant_stack& stack)
|
|
|
|
{
|
|
|
|
if (opcode < _first_msg)
|
|
|
|
return TReport::execute_usr_word(opcode, stack);
|
|
|
|
opcode -= _first_msg;
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case 0 : msg_format_costo(stack); break;
|
|
|
|
case 1 : msg_format_commessa(stack); break;
|
|
|
|
case 2 : msg_format_fase(stack); break;
|
|
|
|
case 3 : msg_format_conto(stack); break;
|
|
|
|
case 4 : msg_format_commessa_costo(stack); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnal_bill
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int TAnal_bill::compare(const TSortable& s) const
|
|
|
|
{
|
|
|
|
const TAnal_bill& b = (const TAnal_bill&)s;
|
|
|
|
int cmp = _conto.compare(b._conto);
|
|
|
|
if (cmp == 0)
|
|
|
|
{
|
|
|
|
cmp = _costo.compare(b._costo);
|
|
|
|
if (cmp == 0)
|
|
|
|
{
|
|
|
|
cmp = _commessa.compare(b._commessa);
|
|
|
|
if (cmp == 0)
|
|
|
|
cmp = _fase.compare(b._fase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnal_bill::match(const TAnal_bill& b) const
|
|
|
|
{
|
|
|
|
if (b._conto.not_empty() && _conto != b._conto)
|
|
|
|
return false;
|
|
|
|
if (b._costo.not_empty() && _costo != b._costo)
|
|
|
|
return false;
|
|
|
|
if (b._commessa.not_empty() && _commessa != b._commessa)
|
|
|
|
return false;
|
|
|
|
if (b._fase.not_empty() && _fase != b._fase)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnal_bill::set_conto(const char* c)
|
|
|
|
{ _conto = c; _conto.trim(); }
|
|
|
|
|
|
|
|
void TAnal_bill::set_costo(const char* c)
|
|
|
|
{ _costo = c; _costo.trim(); }
|
|
|
|
|
|
|
|
void TAnal_bill::set_commessa(const char* c)
|
|
|
|
{ _commessa = c; _commessa.trim(); }
|
|
|
|
|
|
|
|
void TAnal_bill::set_fase(const char* c)
|
|
|
|
{ _fase = c; _fase.trim(); }
|
|
|
|
|
|
|
|
const TString& TAnal_bill::conto() const
|
|
|
|
{ return _conto; }
|
|
|
|
|
|
|
|
const TString& TAnal_bill::costo() const
|
|
|
|
{ return _costo; }
|
|
|
|
|
|
|
|
const TString& TAnal_bill::commessa() const
|
|
|
|
{ return _commessa; }
|
|
|
|
|
|
|
|
const TString& TAnal_bill::fase() const
|
|
|
|
{ return _fase; }
|
|
|
|
|
|
|
|
void TAnal_bill::reset()
|
|
|
|
{
|
|
|
|
_conto = _costo = _commessa = _fase = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnal_bill::get(const TRectype& rec)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
reset();
|
|
|
|
switch(rec.num())
|
|
|
|
{
|
|
|
|
case LF_RMOVANA:
|
|
|
|
set_conto(rec.get(RMOVANA_CODCONTO));
|
|
|
|
set_costo(rec.get(RMOVANA_CODCCOSTO));
|
|
|
|
set_commessa(rec.get(RMOVANA_CODCMS));
|
|
|
|
set_fase(rec.get(RMOVANA_CODFASE));
|
|
|
|
break;
|
|
|
|
case LF_RIGHEDOC:
|
|
|
|
set_commessa(RDOC_CODCMS);
|
|
|
|
set_fase(RDOC_FASCMS);
|
|
|
|
break;
|
|
|
|
case LF_SALDANA:
|
|
|
|
set_conto(rec.get(SALDANA_CONTO));
|
|
|
|
set_costo(rec.get(SALDANA_COSTO));
|
|
|
|
set_commessa(rec.get(SALDANA_COMMESSA));
|
|
|
|
set_fase(rec.get(SALDANA_FASE));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAnal_bill::TAnal_bill()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
TAnal_bill::TAnal_bill(const TAnal_bill& b)
|
|
|
|
{
|
|
|
|
set_conto(b.conto());
|
|
|
|
set_costo(b.costo());
|
|
|
|
set_commessa(b.commessa());
|
|
|
|
set_fase(b.fase());
|
|
|
|
}
|
|
|
|
|
|
|
|
TAnal_bill::TAnal_bill(const char* conto, const char* costo, const char* commessa, const char* fase)
|
|
|
|
{
|
|
|
|
set_conto(conto);
|
|
|
|
set_costo(costo);
|
|
|
|
set_commessa(commessa);
|
|
|
|
set_fase(fase);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAnal_bill::TAnal_bill(const TRectype& rec)
|
|
|
|
{
|
|
|
|
get(rec);
|
|
|
|
}
|
|
|
|
|
2005-06-23 12:16:21 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnal_balance
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-24 11:24:40 +00:00
|
|
|
class TAnal_balance : public TObject
|
|
|
|
{
|
|
|
|
public:
|
2005-06-27 16:35:27 +00:00
|
|
|
TImporto saldo_fine_anno(const TAnal_bill& bill, int annofin, word tipo) const;
|
|
|
|
bool saldo_movimenti(const TAnal_bill& bill, const TDate& dal, const TDate& al, word tipo, TSaldanal& s) const;
|
|
|
|
bool saldi(const TAnal_bill& bill, const TDate& dal, const TDate& al, word tipo, TSaldanal& s) const;
|
2005-06-24 11:24:40 +00:00
|
|
|
};
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
TImporto TAnal_balance::saldo_fine_anno(const TAnal_bill& b, int anno, word tipo) const
|
2005-06-23 12:16:21 +00:00
|
|
|
{
|
|
|
|
TImporto saldo;
|
|
|
|
|
|
|
|
if (anno > 0)
|
|
|
|
{
|
|
|
|
TString query, select;
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.costo().not_empty())
|
|
|
|
select << "(CODCOSTO=='" << b.costo() << "')";
|
|
|
|
if (b.commessa().not_empty())
|
2005-06-23 12:16:21 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty()) select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(CODCMS=='" << b.commessa() << "')";
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.fase().not_empty())
|
2005-06-23 12:16:21 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty()) select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(FASCMS=='" << b.fase() << "')";
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.conto().not_empty())
|
2005-06-24 15:07:14 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty()) select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(CONTO=='" << b.conto() << "')";
|
2005-06-24 15:07:14 +00:00
|
|
|
}
|
2005-06-23 12:16:21 +00:00
|
|
|
|
|
|
|
query << "USE SALDANA";
|
|
|
|
if (select.not_empty())
|
2005-06-24 15:07:14 +00:00
|
|
|
query << " SELECT " << select;
|
|
|
|
if (anno > 0)
|
|
|
|
query << "\nTO ANNO=" << anno << '\n';
|
2005-06-23 12:16:21 +00:00
|
|
|
|
|
|
|
TISAM_recordset saldini(query);
|
|
|
|
|
|
|
|
for (int i = 0; i < saldini.items(); i++)
|
|
|
|
{
|
2005-06-23 15:32:55 +00:00
|
|
|
if (tipo & 1)
|
|
|
|
{
|
|
|
|
const char sez = saldini.get(SALDANA_SEZIONE).as_string()[0];
|
|
|
|
const real imp = saldini.get(SALDANA_SALDO).as_real();
|
|
|
|
saldo += TImporto(sez, imp);
|
|
|
|
}
|
|
|
|
if (tipo & 2)
|
|
|
|
{
|
|
|
|
const char sez = saldini.get(SALDANA_SEZIONEP).as_string()[0];
|
|
|
|
const real imp = saldini.get(SALDANA_SALDOP).as_real();
|
|
|
|
saldo += TImporto(sez, imp);
|
|
|
|
}
|
|
|
|
if (tipo & 4)
|
|
|
|
{
|
|
|
|
const char sez = saldini.get(SALDANA_SEZIONEV).as_string()[0];
|
|
|
|
const real imp = saldini.get(SALDANA_SALDOV).as_real();
|
|
|
|
saldo += TImporto(sez, imp);
|
|
|
|
}
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
|
|
|
saldo.normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return saldo;
|
|
|
|
}
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
bool TAnal_balance::saldo_movimenti(const TAnal_bill& b,
|
2005-06-23 15:32:55 +00:00
|
|
|
const TDate& dal, const TDate& al, word tipo,
|
2005-06-27 16:35:27 +00:00
|
|
|
TSaldanal& s) const
|
2005-06-23 12:16:21 +00:00
|
|
|
{
|
|
|
|
TDate dataini;
|
|
|
|
if (dal.ok())
|
|
|
|
{
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
const int annoprec = esc.date2prevesc(dal);
|
|
|
|
if (annoprec > 0)
|
|
|
|
dataini = esc[annoprec].fine()+1L;
|
|
|
|
}
|
|
|
|
|
2005-06-24 15:07:14 +00:00
|
|
|
TString query, select;
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.costo().not_empty())
|
2005-06-24 15:07:14 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty())
|
|
|
|
select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(CODCOSTO==\"" << b.costo() << "\")";
|
2005-06-24 15:07:14 +00:00
|
|
|
}
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.commessa().not_empty())
|
2005-06-24 15:07:14 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty())
|
|
|
|
select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(CODCMS==\"" << b.commessa() << "\")";
|
2005-06-24 15:07:14 +00:00
|
|
|
}
|
2005-06-27 16:35:27 +00:00
|
|
|
if (b.fase().not_empty())
|
2005-06-24 15:07:14 +00:00
|
|
|
{
|
|
|
|
if (select.not_empty())
|
|
|
|
select << "&&";
|
2005-06-27 16:35:27 +00:00
|
|
|
select << "(CODFASE==\"" << b.fase() << "\")";
|
2005-06-24 15:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
query << "USE RMOVANA KEY 2\n";
|
|
|
|
if (select.not_empty())
|
|
|
|
query << "SELECT " << select << "\n";
|
2005-06-23 12:16:21 +00:00
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
// Faccio la join solo se mi serve il tipo movimento in testata
|
|
|
|
if (tipo != 0 && tipo != 7)
|
|
|
|
query << "JOIN MOVANA INTO NUMREG==NUMREG\n";
|
|
|
|
|
|
|
|
query << "FROM CODCONTO=" << b.conto();
|
2005-06-23 12:16:21 +00:00
|
|
|
if (dataini.ok())
|
2005-06-27 16:35:27 +00:00
|
|
|
query << " DATACOMP=" << dataini;
|
2005-06-23 12:16:21 +00:00
|
|
|
query << "\n";
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
query << "TO CODCONTO=" << b.conto();
|
2005-06-23 12:16:21 +00:00
|
|
|
if (al.ok())
|
2005-06-27 16:35:27 +00:00
|
|
|
query << " DATACOMP=" << al;
|
2005-06-23 12:16:21 +00:00
|
|
|
query << "\n";
|
|
|
|
|
|
|
|
TISAM_recordset rmovana(query);
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
s._movimentato = false;
|
2005-06-23 12:16:21 +00:00
|
|
|
for (int i = 0; i < rmovana.items(); i++)
|
|
|
|
{
|
|
|
|
rmovana.move_to(i);
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
// Controllo il tipo movimento solo se necessario
|
|
|
|
if (tipo != 0 && tipo != 7)
|
|
|
|
{
|
|
|
|
const char tipomov = rmovana.get("107.TIPOMOV").as_string()[0];
|
|
|
|
int ntipomov = 0;
|
|
|
|
if (tipomov == 'P')
|
|
|
|
ntipomov = 2; else
|
|
|
|
if (tipomov == 'V')
|
|
|
|
ntipomov = 4;
|
|
|
|
else
|
|
|
|
ntipomov = 1;
|
|
|
|
if ((ntipomov & tipo) == 0)
|
|
|
|
continue;
|
|
|
|
}
|
2005-06-23 15:32:55 +00:00
|
|
|
|
2005-06-24 16:40:56 +00:00
|
|
|
const TDate data = rmovana.get(RMOVANA_DATACOMP).as_date();
|
2005-06-23 12:16:21 +00:00
|
|
|
const TImporto imp(rmovana.get(RMOVANA_SEZIONE).as_string()[0],
|
|
|
|
rmovana.get(RMOVANA_IMPORTO).as_real());
|
|
|
|
if (data >= dal)
|
|
|
|
{
|
|
|
|
if (imp.sezione() == 'D')
|
2005-06-27 16:35:27 +00:00
|
|
|
s._dare += imp;
|
2005-06-23 12:16:21 +00:00
|
|
|
else
|
2005-06-27 16:35:27 +00:00
|
|
|
s._avere += imp;
|
|
|
|
s._movimentato = true;
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-27 16:35:27 +00:00
|
|
|
s._ini += imp;
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-27 16:35:27 +00:00
|
|
|
s._ini.normalize();
|
|
|
|
s._fin = s._ini;
|
|
|
|
s._fin += s._dare;
|
|
|
|
s._fin += s._avere;
|
|
|
|
s._fin.normalize();
|
|
|
|
return s._movimentato;
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
bool TAnal_balance::saldi(const TAnal_bill& bill,
|
2005-06-23 15:32:55 +00:00
|
|
|
const TDate& dal, const TDate& al, word tipo,
|
2005-06-27 16:35:27 +00:00
|
|
|
TSaldanal& s) const
|
2005-06-23 12:16:21 +00:00
|
|
|
{
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
const int annoprec = esc.date2prevesc(dal);
|
2005-06-27 16:35:27 +00:00
|
|
|
s._ini = saldo_fine_anno(bill, annoprec, tipo);
|
|
|
|
return saldo_movimenti(bill, dal, al, tipo, s);
|
2005-06-23 12:16:21 +00:00
|
|
|
}
|
2005-06-24 11:24:40 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
// TSaldi_cache
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TSaldi_cache : private TCache
|
|
|
|
{
|
2005-06-27 16:35:27 +00:00
|
|
|
TAnal_balance _bal;
|
|
|
|
|
2005-06-24 11:24:40 +00:00
|
|
|
protected:
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
|
|
|
public:
|
2005-06-27 16:35:27 +00:00
|
|
|
const TSaldanal& saldo(const TAnal_bill& bill, const TDate& dal, const TDate& al, word tipi = 0x1);
|
2005-06-24 11:24:40 +00:00
|
|
|
TSaldi_cache() : TCache(3883) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
TObject* TSaldi_cache::key2obj(const char* key)
|
|
|
|
{
|
|
|
|
TSaldanal* s = new TSaldanal;
|
|
|
|
|
|
|
|
TToken_string tok(key);
|
2005-06-27 16:35:27 +00:00
|
|
|
const TAnal_bill bill(tok.get(0), tok.get(1), tok.get(2), tok.get(3));
|
|
|
|
const TDate dal = tok.get(4); // Le get precedenti avvengono in ordine inverso!
|
2005-06-24 11:24:40 +00:00
|
|
|
const TDate al = tok.get();
|
2005-06-27 16:35:27 +00:00
|
|
|
const int tipo = tok.get_int();
|
|
|
|
s->_movimentato = _bal.saldi(bill, dal, al, tipo, *s);
|
2005-06-24 11:24:40 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
const TSaldanal& TSaldi_cache::saldo(const TAnal_bill& bill, const TDate& dal, const TDate& al, word tipi)
|
2005-06-24 11:24:40 +00:00
|
|
|
{
|
|
|
|
TToken_string key;
|
2005-06-27 16:35:27 +00:00
|
|
|
key.add(bill.conto(), 0);
|
|
|
|
key.add(bill.costo(), 1);
|
|
|
|
key.add(bill.commessa(), 2);
|
|
|
|
key.add(bill.fase(), 3);
|
2005-06-24 11:24:40 +00:00
|
|
|
key.add(dal, 4);
|
|
|
|
key.add(al, 5);
|
|
|
|
key.add(tipi, 6);
|
|
|
|
return *(const TSaldanal*)objptr(key);
|
|
|
|
}
|
|
|
|
|
2005-06-27 16:35:27 +00:00
|
|
|
const TSaldanal& ca_saldo(const TAnal_bill& bill, const TDate& dal, const TDate& al, word tipi)
|
2005-06-24 11:24:40 +00:00
|
|
|
{
|
|
|
|
static TSaldi_cache* cache = NULL;
|
2005-06-24 11:28:19 +00:00
|
|
|
if (cache == NULL)
|
2005-06-24 11:24:40 +00:00
|
|
|
cache = new TSaldi_cache;
|
2005-06-27 16:35:27 +00:00
|
|
|
return cache->saldo(bill, dal, al, tipi);
|
2005-06-24 11:24:40 +00:00
|
|
|
}
|