Files correlati : pd6342 Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@21752 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			460 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			460 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <colors.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <textset.h>
 | 
						|
 | 
						|
#include "pd6342500a.h"
 | 
						|
#include "../ca/calib01.h"
 | 
						|
#include "../ca/calib02.h"
 | 
						|
#include "../ca/commesse.h"
 | 
						|
#include "../ca/fasi.h"
 | 
						|
#include "../ca/pconana.h"
 | 
						|
#include "../ca/saldana.h"
 | 
						|
#include "../ve/velib.h"
 | 
						|
 | 
						|
#define FIRST_ROW 5
 | 
						|
#define FIRST_COL 2
 | 
						|
 | 
						|
#define CHAR_RANGE ('Z' - 'A' + 1)
 | 
						|
#define ROW2SHEET(r) (FIRST_ROW + r)
 | 
						|
 | 
						|
const COLOR header_back[] = {COLOR_CADETBLUE, COLOR_GREEN, COLOR_BLUE, COLOR_GREY, COLOR_SALMON, COLOR_YELLOW} ;
 | 
						|
 | 
						|
static const char * col2string(int col)
 | 
						|
{
 | 
						|
	TString & tmp = get_tmp_string(4);
 | 
						|
 | 
						|
	int c2 = col + FIRST_COL;
 | 
						|
	int c1 = c2 / CHAR_RANGE - 1;
 | 
						|
 | 
						|
	if (c1 >= 0)
 | 
						|
	{
 | 
						|
		tmp << (char) (c1 + 'A');
 | 
						|
		c2 %= CHAR_RANGE;
 | 
						|
	}
 | 
						|
	tmp << (char) (c2 + 'A');
 | 
						|
	return tmp;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
static const char * stringify(TString & s)
 | 
						|
{
 | 
						|
	s.insert("\"");
 | 
						|
	s << '"';
 | 
						|
	return s;
 | 
						|
}
 | 
						|
 | 
						|
bool _english_excel = false;
 | 
						|
 | 
						|
static const TString& sum_formula(int ci, int ri, int cf, int rf) 
 | 
						|
{
 | 
						|
  TString& tmp = get_tmp_string();
 | 
						|
  tmp << '=' << (_english_excel ? "SUM" : "SOMMA") << '(' 
 | 
						|
      << col2string(ci) << ROW2SHEET(ri) << ':'
 | 
						|
      << col2string(cf) << ROW2SHEET(rf) << ')';
 | 
						|
  return tmp;
 | 
						|
}
 | 
						|
 | 
						|
class TBilancio_recset : public TCSV_recordset
 | 
						|
{
 | 
						|
	int dett_length;
 | 
						|
	int tot_lenght;
 | 
						|
	TBit_array _tot_rows;
 | 
						|
	TBit_array _tot_rows_ind;
 | 
						|
	TBit_array _tot_gen;
 | 
						|
	TRecnotype _tot_fin;
 | 
						|
	int _group[200];
 | 
						|
 | 
						|
public:
 | 
						|
	TBit_array & tot_rows() { return _tot_rows;}
 | 
						|
	TBit_array & tot_gen() { return _tot_gen;}
 | 
						|
	virtual bool get_attr(int column, TAttributes & attr, bool header  = false) const;
 | 
						|
 | 
						|
  TBilancio_recset(const TMask & m);
 | 
						|
};
 | 
						|
 | 
						|
bool TBilancio_recset::get_attr(int column, TAttributes & attr, bool header) const
 | 
						|
{
 | 
						|
	const TRecnotype  rowno = current_row();
 | 
						|
 | 
						|
	if ((rowno == 0L || header))
 | 
						|
	{
 | 
						|
		if (column > 1)
 | 
						|
		{
 | 
						|
      COLOR bkg = COLOR_RED;
 | 
						|
      if ((unsigned int)column < columns() - 1)
 | 
						|
      {
 | 
						|
        const int header_colors = sizeof(header_back) / sizeof(header_back[0]);
 | 
						|
        bkg = header_back[_group[column-2] % header_colors];
 | 
						|
      }
 | 
						|
      COLOR frg = (grayed_color(bkg)&0xFF)>0x80 ? COLOR_BLACK : COLOR_WHITE;
 | 
						|
 | 
						|
      attr.set_background(bkg);
 | 
						|
      attr.set_foreground(frg);
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		else
 | 
						|
			return false;
 | 
						|
	}
 | 
						|
	else
 | 
						|
		if (_tot_rows[rowno] ||	_tot_rows_ind[rowno])
 | 
						|
		{
 | 
						|
				attr.set_background(COLOR_CADETBLUE);
 | 
						|
				attr.set_foreground(COLOR_BLACK);
 | 
						|
				return true;
 | 
						|
		}
 | 
						|
		else
 | 
						|
			if (_tot_gen[rowno])
 | 
						|
			{
 | 
						|
				attr.set_background(COLOR_YELLOW);
 | 
						|
				attr.set_foreground(COLOR_BLACK);
 | 
						|
				return true;
 | 
						|
			}
 | 
						|
			else
 | 
						|
				if (_tot_fin == rowno)
 | 
						|
				{
 | 
						|
					attr.set_background(COLOR_RED);
 | 
						|
					attr.set_foreground(COLOR_BLACK);
 | 
						|
					return true;
 | 
						|
				}
 | 
						|
	return TCSV_recordset::get_attr(column, attr);
 | 
						|
}
 | 
						|
 | 
						|
TBilancio_recset::TBilancio_recset(const TMask & m) : TCSV_recordset("CSV(;)\n")
 | 
						|
{
 | 
						|
	set_separator(';');
 | 
						|
  _english_excel = m.get_bool(F_INGLESE);
 | 
						|
 | 
						|
	TString esercizio = m.get(F_ANNO);
 | 
						|
	const TDate al = m.get_date(F_ADATA);
 | 
						|
 | 
						|
	const TDate & dal = esercizi().esercizio(m.get_int(F_ANNO)).inizio();
 | 
						|
	word tipo =  _saldanal_consuntivo ;
 | 
						|
 | 
						|
	if (!al.ok())
 | 
						|
		tipo |= _saldanal_ultima_imm;
 | 
						|
 | 
						|
	TAssoc_array kcol;
 | 
						|
	TString_array colkeys;
 | 
						|
	TAssoc_array krow;
 | 
						|
	TString_array rowkeys;
 | 
						|
	TToken_string key;
 | 
						|
	TString codcms;
 | 
						|
	TString codfase;
 | 
						|
	TString colname(30);
 | 
						|
	TString conto;
 | 
						|
	TString last_conto;
 | 
						|
	const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
 | 
						|
	TString query;
 | 
						|
  query << "USE " << LF_SALDANA < "\n";
 | 
						|
	query << "FROM " << SALDANA_ANNO << "=" << stringify(esercizio) <<  "\n";
 | 
						|
  query << "TO  " << SALDANA_ANNO << "="   << stringify(esercizio);
 | 
						|
 | 
						|
  TISAM_recordset recset(query);
 | 
						|
	
 | 
						|
	const int tot_length = info.len(0) + info.len(1);
 | 
						|
	const int dett_length = tot_length + info.len(2);
 | 
						|
 | 
						|
	for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						|
	{
 | 
						|
		const TString & cms = recset.get(SALDANA_COMMESSA).as_string();
 | 
						|
 | 
						|
		if (cms.full())
 | 
						|
		{
 | 
						|
			key = cms;
 | 
						|
			
 | 
						|
			const TString & fsc = recset.get(SALDANA_FASE).as_string();
 | 
						|
 | 
						|
			if (fsc.full())
 | 
						|
			{
 | 
						|
				key.add(fsc);
 | 
						|
				if (kcol.objptr(key) == NULL)
 | 
						|
					kcol.add(key, key);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		const TString & bill = recset.get(SALDANA_CONTO).as_string();
 | 
						|
		if (bill.full() && krow.objptr(bill) == NULL)
 | 
						|
			krow.add(bill, bill);
 | 
						|
	}
 | 
						|
	kcol.get_keys(colkeys);
 | 
						|
	colkeys.sort();
 | 
						|
	krow.get_keys(rowkeys);
 | 
						|
	rowkeys.sort();
 | 
						|
	destroy_column();
 | 
						|
 | 
						|
	const int ncols = colkeys.items();
 | 
						|
 | 
						|
	create_column("Conto");
 | 
						|
	create_column("Descrizione");
 | 
						|
 | 
						|
	TToken_string cmskey = colkeys.row(0);
 | 
						|
	TString last_cms = cmskey.get(0);
 | 
						|
	int group = 0;
 | 
						|
 | 
						|
	for (int i = 0; i < ncols; i++)
 | 
						|
	{
 | 
						|
		cmskey = colkeys.row(i);
 | 
						|
		TString cms = cmskey.get(0);
 | 
						|
		if (last_cms != cms)
 | 
						|
		{
 | 
						|
			last_cms = cms;
 | 
						|
			group++;
 | 
						|
		}
 | 
						|
		_group[i] = group;										
 | 
						|
		colname = cmskey;
 | 
						|
		colname.replace('|', '-');
 | 
						|
		create_column(colname, _realfld);
 | 
						|
	}
 | 
						|
	create_column("Totale", _realfld);
 | 
						|
 | 
						|
	TRecnotype sheet_row = new_rec("");
 | 
						|
	TString descr;
 | 
						|
 | 
						|
	for (int c  = 0; c < ncols; c++)
 | 
						|
	{
 | 
						|
		cmskey = colkeys.row(c);
 | 
						|
		const TString cms = cmskey.get(0);
 | 
						|
		const TString fase = cmskey.get();
 | 
						|
	
 | 
						|
		descr.cut(0);
 | 
						|
		descr <<  cache().get(LF_COMMESSE, cms, COMMESSE_DESCRIZ);
 | 
						|
		descr <<  "-" << cache().get(LF_FASI, cmskey, FASI_DESCRIZ);
 | 
						|
		set(c + 2, descr);
 | 
						|
	}
 | 
						|
	set(ncols + 2, "          ");
 | 
						|
	
 | 
						|
	long start_rec = -1;
 | 
						|
	const int nrows = rowkeys.items();
 | 
						|
	TProgind p(nrows * 2, TR("Calcolo Saldi")); 
 | 
						|
	TAnal_bill bill;
 | 
						|
 | 
						|
	for (int r = 0; r < nrows; r++)
 | 
						|
	{
 | 
						|
		if (!p.addstatus(1))
 | 
						|
      break;
 | 
						|
		conto = rowkeys.row(r);
 | 
						|
		conto = conto.left(dett_length);
 | 
						|
		bill.set_conto(conto);
 | 
						|
		if (conto.left(tot_length) !=	last_conto.left(tot_length))
 | 
						|
		{
 | 
						|
			if (start_rec != -1)
 | 
						|
			{
 | 
						|
				sheet_row = new_rec();
 | 
						|
				set(0, last_conto.left(tot_length));
 | 
						|
				set(1, cache().get(LF_PCONANA, last_conto.left(tot_length), PCONANA_DESCR));
 | 
						|
				for (int i = 0; i < ncols - 1; i++)
 | 
						|
          set(i+2, sum_formula(i, start_rec, i, sheet_row-1));
 | 
						|
 | 
						|
        set(ncols+2, sum_formula(0, sheet_row, ncols-1, sheet_row));
 | 
						|
 | 
						|
				_tot_rows.set(sheet_row);
 | 
						|
				new_rec();
 | 
						|
			}
 | 
						|
			start_rec = sheet_row + 1;
 | 
						|
			last_conto = conto;
 | 
						|
		}
 | 
						|
		sheet_row = new_rec();
 | 
						|
		set(0, conto);
 | 
						|
		set(1, cache().get(LF_PCONANA, conto, PCONANA_DESCR));
 | 
						|
		for (int c = 0; c < ncols; c++)
 | 
						|
		{
 | 
						|
			TToken_string & colkey = colkeys.row(c);
 | 
						|
 | 
						|
			bill.set_commessa(colkey.get(0));
 | 
						|
			bill.set_fase(colkey.get());
 | 
						|
			const TSaldanal & saldo = ca_saldo(bill, dal, al, tipo);
 | 
						|
			TImporto imp = saldo._ini;
 | 
						|
			imp += saldo._dare;
 | 
						|
			imp += saldo._avere;
 | 
						|
			
 | 
						|
			imp -= saldo._iniind;
 | 
						|
			imp -= saldo._dareind;
 | 
						|
			imp -= saldo._avereind;
 | 
						|
      if (!imp.is_zero())
 | 
						|
      {
 | 
						|
			  imp.normalize('A');
 | 
						|
			  set(c + 2, imp.valore());
 | 
						|
      }
 | 
						|
		}
 | 
						|
    set(ncols + 2, sum_formula(0, sheet_row, ncols-1, sheet_row));
 | 
						|
	}
 | 
						|
	if (start_rec != -1)
 | 
						|
	{
 | 
						|
		sheet_row = new_rec();
 | 
						|
		set(0, last_conto.left(tot_length));
 | 
						|
		set(1, cache().get(LF_PCONANA, last_conto.left(tot_length), PCONANA_DESCR));
 | 
						|
		for (int i = 0; i < ncols - 1; i++)
 | 
						|
      set(i + 2, sum_formula(i, start_rec, i, sheet_row-1));
 | 
						|
 | 
						|
    set(ncols + 2, sum_formula(0, sheet_row, ncols-1, sheet_row));
 | 
						|
 | 
						|
		_tot_rows.set(sheet_row);
 | 
						|
		new_rec();
 | 
						|
	}
 | 
						|
	sheet_row = new_rec() ;
 | 
						|
	set(1, "Totale Diretti");
 | 
						|
  TString expr;
 | 
						|
	for (int c = 0; c < ncols; c++)
 | 
						|
	{
 | 
						|
    expr.cut(0);
 | 
						|
		for (int j = _tot_rows.first_one(); j <= _tot_rows.last_one(); j++)
 | 
						|
			if (_tot_rows[j])
 | 
						|
				expr << ((j == _tot_rows.first_one()) ? '=' : '+') << col2string(c) << ROW2SHEET(j);
 | 
						|
		set(c + 2, expr);
 | 
						|
		set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
	}
 | 
						|
	_tot_gen.set(sheet_row);
 | 
						|
	new_rec();
 | 
						|
 | 
						|
 	start_rec = -1;
 | 
						|
	last_conto.cut(0);
 | 
						|
	for (int r = 0; r < nrows; r++)
 | 
						|
	{
 | 
						|
		if (!p.addstatus(1L))
 | 
						|
      break;
 | 
						|
		conto = rowkeys.row(r);
 | 
						|
		conto = conto.left(dett_length);
 | 
						|
		bill.set_conto(conto);
 | 
						|
		if (conto.left(tot_length) !=	last_conto.left(tot_length))
 | 
						|
		{
 | 
						|
			if (start_rec != -1)
 | 
						|
			{
 | 
						|
				sheet_row = new_rec();
 | 
						|
				set(0, last_conto.left(tot_length));
 | 
						|
				set(1, cache().get(LF_PCONANA, last_conto.left(tot_length), PCONANA_DESCR));
 | 
						|
				for (int i = 0; i < ncols - 1; i++)
 | 
						|
					set(i + 2, sum_formula(i, start_rec, i,sheet_row-1));
 | 
						|
				set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
				_tot_rows_ind.set(sheet_row);
 | 
						|
				new_rec();
 | 
						|
			}
 | 
						|
			start_rec = sheet_row + 1;
 | 
						|
			last_conto = conto;
 | 
						|
		}
 | 
						|
		sheet_row = new_rec();
 | 
						|
		set(0, conto);
 | 
						|
		set(1, cache().get(LF_PCONANA, conto, PCONANA_DESCR));
 | 
						|
		for (int c = 0; c < ncols; c++)
 | 
						|
		{
 | 
						|
			TToken_string & colkey = colkeys.row(c);
 | 
						|
 | 
						|
			bill.set_commessa(colkey.get(0));
 | 
						|
			bill.set_fase(colkey.get());
 | 
						|
			const TSaldanal & saldo = ca_saldo(bill, dal, al, tipo);
 | 
						|
			TImporto imp = saldo._iniind;
 | 
						|
			imp += saldo._dareind;
 | 
						|
			imp += saldo._avereind;
 | 
						|
      if (!imp.is_zero())
 | 
						|
      {
 | 
						|
			  imp.normalize('A');
 | 
						|
			  set(c + 2, imp.valore());
 | 
						|
      }
 | 
						|
		}
 | 
						|
		set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
	}
 | 
						|
	if (start_rec != -1)
 | 
						|
	{
 | 
						|
		sheet_row = new_rec();
 | 
						|
		set(0, last_conto.left(tot_length));
 | 
						|
		set(1, cache().get(LF_PCONANA, last_conto.left(tot_length), PCONANA_DESCR));
 | 
						|
		for (int i = 0; i < ncols - 1; i++)
 | 
						|
			set(i + 2, sum_formula(i, start_rec, i,sheet_row-1));
 | 
						|
		set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
		_tot_rows_ind.set(sheet_row);
 | 
						|
		new_rec();
 | 
						|
	}
 | 
						|
	sheet_row = new_rec();
 | 
						|
	set(1, "Totale Indiretti");
 | 
						|
	for (int c = 0; c < ncols; c++)
 | 
						|
	{
 | 
						|
		TString expr;
 | 
						|
 | 
						|
		for (int j = _tot_rows_ind.first_one(); j <= _tot_rows_ind.last_one(); j++)
 | 
						|
			if (_tot_rows_ind[j])
 | 
						|
				expr << ((j == _tot_rows_ind.first_one()) ? '=' : '+') << col2string(c) << ROW2SHEET(j);
 | 
						|
		set(c + 2, expr);
 | 
						|
	}
 | 
						|
	set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
	_tot_gen.set(sheet_row);
 | 
						|
	new_rec();
 | 
						|
	sheet_row = new_rec();
 | 
						|
	set(1, "Totale");
 | 
						|
	for (int c = 0; c < ncols; c++)
 | 
						|
	{
 | 
						|
		TString expr;
 | 
						|
 | 
						|
		for (int j = _tot_gen.first_one(); j <= _tot_gen.last_one(); j++)
 | 
						|
			if (_tot_gen[j])
 | 
						|
				expr << ((j == _tot_gen.first_one()) ? '=' : '+') << col2string(c) << ROW2SHEET(j);
 | 
						|
		set(c + 2, expr);
 | 
						|
	}
 | 
						|
	set(ncols + 2, sum_formula(0, sheet_row, ncols - 1,sheet_row));
 | 
						|
	_tot_fin = sheet_row;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TSaldi_ana_msk
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TSaldi_ana_msk: public TAutomask
 | 
						|
{
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
	TSaldi_ana_msk() : TAutomask("pd6342500a") {}
 | 
						|
};
 | 
						|
 | 
						|
bool TSaldi_ana_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{ 
 | 
						|
  switch(o.dlg())
 | 
						|
  { 
 | 
						|
  case DLG_FINDREC:
 | 
						|
  default:  break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TSaldi_ana_app
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TSaldi_ana_app: public TSkeleton_application
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool check_autorization() const {return false;}
 | 
						|
  virtual const char * extra_modules() const {return "ca";}
 | 
						|
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TSaldi_ana_app::main_loop()
 | 
						|
{
 | 
						|
  TSaldi_ana_msk m;
 | 
						|
	bool running = true;
 | 
						|
 | 
						|
  while(m.run() == K_ENTER)
 | 
						|
	{
 | 
						|
		TBilancio_recset b(m);
 | 
						|
		TFilename fname(m.get(F_PATH));
 | 
						|
		
 | 
						|
		fname.add(m.get(F_NAME));
 | 
						|
		if (fname.full())
 | 
						|
    {
 | 
						|
			b.save_as(fname, fmt_unknown);
 | 
						|
      xvt_sys_goto_url(fname, "open");
 | 
						|
    }
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
int pd6342500(int argc, char* argv[])
 | 
						|
{  
 | 
						|
  TSaldi_ana_app app;
 | 
						|
  app.run(argc, argv, TR("Saldi Analitici"));
 | 
						|
  return 0;
 | 
						|
}
 |