campo-sirio/cm/cm0100.cpp
alex 1d4f4e3267 Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            : Nuovo modulo commesse


git-svn-id: svn://10.65.10.50/trunk@10473 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-09-09 14:10:14 +00:00

449 lines
13 KiB
C++
Executable File

#include <applicat.h>
#include <automask.h>
#include <form.h>
#include <printer.h>
#include <recarray.h>
#include <utility.h>
#include "cm0.h"
#include "cm0100a.h"
#include "cm0100.h"
#include "rmov.h"
#include "pconti.h"
class TForm_contixcdc : public TForm
{
public:
virtual bool validate(TForm_item &cf, TToken_string &s);
void set_testata() {set_header(1,TRUE);}
//void set_pedata() {set_footer(1,FALSE); set_footer(1,TRUE);}
TPrint_section& get_body() {return section('B', odd_page);}
TPrint_section& get_section(char s, pagetype pos) {return section(s, pos);}
TForm_contixcdc();
virtual ~TForm_contixcdc();
};
TForm_contixcdc::TForm_contixcdc() :TForm("cm0100a") //costruttore
{
}
TForm_contixcdc::~TForm_contixcdc() //distruttore
{
}
bool TForm_contixcdc::validate(TForm_item &cf, TToken_string &s)
{
return TForm::validate(cf,s); //richiama la validate standard della classe genitore
}
class TContixcdc_mask : public TAutomask
{
TRelation * _rel;
TCursor * _cur;
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TContixcdc_mask();
virtual ~TContixcdc_mask(){};
};
TContixcdc_mask::TContixcdc_mask() :TAutomask ("cm0100a")
{
}
bool TContixcdc_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_DACDC:
case F_ACDC:
if (e == fe_modify)
{
const bool on = !(field(F_DACDC).empty() && field(F_ACDC).empty());
if (!on)
{
reset(F_DAFSC);
reset(F_AFSC);
}
enable(F_DAFSC, on);
enable(F_AFSC, on);
}
break;
default: break;
}
return TRUE;
}
struct TTotali : public TObject
{
TImporto _tot_progprec, _tot_periodo, _tot_saldocont;
void azzera();
TTotali& operator += (const TTotali& t);
};
void TTotali::azzera()
{
_tot_progprec = 0;
_tot_periodo = 0;
_tot_saldocont = 0;
}
TTotali& TTotali::operator += (const TTotali& t)
{
_tot_progprec += t._tot_progprec;
_tot_periodo += t._tot_periodo;
_tot_saldocont += t._tot_saldocont;
return *this; //ritorna se stesso, quindi i valori dei totali
}
class TContixCdc : public TSkeleton_application
{
TContixcdc_mask * _mask;
TForm_contixcdc * _form;
int _codes;
TDate _dataini, _datafin;
TTotali _t_gruppo, _t_sottoc, _t_fsc, _t_cms; //sono i tre set di totali (gruppo/conto, sottoconto, commessa)
int _currgruppo, _currconto, _oldgruppo, _oldconto;
long _currsottoc, _oldsottoc;
TString _currcms, _currfsc, _oldcms, _oldfsc;
bool _saltopagina;
protected:
virtual bool create();
virtual bool destroy();
virtual void main_loop();
void print_sottoc();
void ctrl_commessa();
void print_footer_gruppo(const int gruppo, const int conto);
void print_header_gruppo(const int gruppo, const int conto);
void print_footer_commessa(const TString& cms);
void print_header_commessa(const TString& cms);
void print_footer_fase(const TString& fsc);
void print_header_fase(const TString& fsc);
void set_intestazione();
void fill_body(const TTotali& tot); //riempie il campo body con tutti i totali
void print_body(); //stampa effettivamente il body
void set_field(int id, const real& val); //mette in un campo del body odd un valore numerico
void set_field(int id, const char* val); //mette in un campo del body odd una stringa
void print_specialsection(char s, pagetype pos); // stampa una sezione qualunque (
void aggiorna_totali(const TImporto importo, const TDate data);
public:
TContixCdc() {}
};
bool TContixCdc::create()
{
open_files(LF_RMOV, 0);
_mask = new TContixcdc_mask;
_form = new TForm_contixcdc;
return TSkeleton_application::create();
}
bool TContixCdc::destroy()
{
delete _mask;
delete _form;
return TSkeleton_application::destroy();
}
void TContixCdc::print_sottoc()
{
if (_oldsottoc != -1)
{
TString16 key;
key.format("%d|%d|%ld", _oldgruppo, _oldconto, _oldsottoc);
const TRectype& pcon = cache().get(LF_PCON, key);
set_field(FR_SOTTOC, _oldsottoc);
set_field(FR_D_SOTTOC, pcon.get(PCN_DESCR));
// manca costo/ricavo
fill_body(_t_sottoc);
print_body();
}
_oldsottoc = _currsottoc;
_t_sottoc.azzera();
}
void TContixCdc::print_footer_gruppo(const int gruppo, const int conto)
{
TString16 key;
key.format("%d|%d", gruppo, conto);
TString tmp;
const TRectype& pcon = cache().get(LF_PCON, key);
tmp.format("TOTALE %d %d %s", gruppo, conto, (const char*) pcon.get(PCN_DESCR));
set_field(FR_SOTTOC, "");
set_field(FR_D_SOTTOC, tmp);
fill_body(_t_gruppo);
print_body();
}
void TContixCdc::print_header_gruppo(const int gruppo, const int conto)
{
TString tmp;
TString16 key;
key.format("%d|%d", gruppo, conto);
const TRectype& pcon = cache().get(LF_PCON, key);
tmp.format("%d %d", gruppo, conto);
_form->find_field('H', even_page, FR_GRUPPOCONTO).set(tmp);
_form->find_field('H', even_page, FR_D_GRUPPOCONTO).set(pcon.get(PCN_DESCR));
print_specialsection('H', even_page);
}
void TContixCdc::print_footer_commessa(const TString& cms)
{
TString tmp;
tmp.format("TOTALE COMMESSA %s", (const char*) cms);
set_field(FR_D_SOTTOC, tmp);
fill_body(_t_cms);
print_body();
if (_saltopagina)
printer().formfeed();
}
void TContixCdc::print_footer_fase(const TString& fsc)
{
TString tmp;
tmp.format("TOTALE FASE %s", (const char*) fsc);
set_field(FR_D_SOTTOC, tmp);
fill_body(_t_fsc);
print_body();
}
void TContixCdc::print_header_commessa(const TString& cms)
{
_form->find_field('H', odd_page, FR_CMS).set(cms);
_form->find_field('H', odd_page, FR_D_CMS).set(cache().get("CMS", cms).get("S0"));
print_specialsection('H', odd_page);
}
void TContixCdc::print_header_fase(const TString& fsc)
{
_form->find_field('H', last_page, FR_FSC).set(fsc);
_form->find_field('H', last_page, FR_D_FSC).set(cache().get("FSC", fsc).get("S0"));
print_specialsection('H', last_page);
}
void TContixCdc::set_intestazione()
{
// scrive l'header first, contenente i dati della ditta e dell'esercizio e le selezioni di stampa
_form->find_field('H', first_page, FR_ESERCIZIO).set(_mask->get(F_ANNO));
_form->find_field('H', first_page, FR_DATAINI).set(_mask->get(F_DATAINI));
_form->find_field('H', first_page, FR_DATAFIN).set(_mask->get(F_DATAFIN));
_form->find_field('H', first_page, FR_DACDC).set(_mask->get(F_DACDC));
_form->find_field('H', first_page, FR_DAFSC).set(_mask->get(F_DAFSC));
_form->find_field('H', first_page, FR_ACDC).set(_mask->get(F_ACDC));
_form->find_field('H', first_page, FR_AFSC).set(_mask->get(F_AFSC));
_form->set_testata();
}
void TContixCdc::print_body()
{
TPrint_section& body = _form->get_body();
body.update();
if (body.height() > printer().rows_left())
printer().formfeed();
for (word i = 0; i < body.height(); i++) // stampa le righe del body
printer().print(body.row(i));
}
void TContixCdc::print_specialsection(char s, pagetype pos)
{
TPrint_section& sec = _form->get_section(s, pos);
sec.update();
if (sec.height() > printer().rows_left())
printer().formfeed();
for (word i = 0; i < sec.height(); i++) // stampa le righe del body
printer().print(sec.row(i));
}
void TContixCdc::set_field(int id, const real& val)
{
_form->find_field('B', odd_page, id).set(val.string());
}
void TContixCdc::set_field(int id, const char* val)
{
_form->find_field('B', odd_page, id).set(val);
}
void TContixCdc::fill_body(const TTotali& tot)
{
// riempie il body odd, contenente i totali; lo fa chiamando la set_field per ogni campo
set_field(FR_PROGPREC, tot._tot_progprec.valore());
set_field(FR_PERIODO, tot._tot_periodo.valore());
real tempval1 = tot._tot_progprec.valore()+tot._tot_periodo.valore();
set_field(FR_PROG, tempval1);
set_field(FR_SALDOCONT, tot._tot_saldocont.valore());
}
void TContixCdc::aggiorna_totali(const TImporto importo, const TDate data)
{
if (data < _dataini)
_t_sottoc._tot_progprec+=importo;
else if (data > _datafin)
_t_sottoc._tot_saldocont+=importo;
else
_t_sottoc._tot_periodo+=importo;
}
void TContixCdc::ctrl_commessa()
{
if (_oldcms != "@@")
print_footer_commessa(_oldcms);
_t_cms.azzera();
print_header_commessa(_currcms);
_oldcms = _currcms;
}
void TContixCdc::main_loop()
{
while (_mask->run() == K_ENTER)
{
_saltopagina = _mask->get_bool(F_SALTOPAGINA); // salto pagina a fine commessa
_codes = _mask->get_int(F_ANNO); // esercizio
_dataini = _mask->get_date(F_DATAINI); // data iniziale
_datafin = _mask->get_date(F_DATAFIN); // data finale
TString80 dacdc = _mask->get(F_DACDC); // cdc/commessa iniziale
TString80 dafsc = _mask->get(F_DAFSC); // fase iniziale
TString80 acdc = _mask->get(F_ACDC); // cdc/commessa finale
TString80 afsc = _mask->get(F_AFSC); // fase finale
// relazione su rmov
TRelation relrmov(LF_RMOV);
// filtro
TString filtro = "";
if (_codes != 0)
filtro.format("ANNOES==%d", _codes);
if (dacdc.not_empty())
{
if (filtro.not_empty())
filtro << " && ";
filtro << "(CODCMS>=\"" << dacdc << "\")";
}
if (dafsc.not_empty())
{
if (filtro.not_empty())
filtro << " && ";
filtro << "(FASCMS>=\"" << dafsc << "\")";
}
if (acdc.not_empty())
{
if (filtro.not_empty())
filtro << " && ";
filtro << "(CODCMS<=\"" << acdc << "\")";
}
if (afsc.not_empty())
{
if (filtro.not_empty())
filtro << " && ";
filtro << "(FASCMS<=\"" << afsc << "\")";
}
if (filtro.empty())
filtro.format("(CODCMS!=\"\")");
else
if (dacdc.empty() && acdc.empty())
filtro << " && " << "(CODCMS!=\"\")";
TRectype darec(LF_RMOV), arec(LF_RMOV);
// servono per gruppo-conto-sottoconto
darec.zero();
arec.zero();
darec.put(RMV_GRUPPO, _mask->get_int(F_GRUPPOINI));
darec.put(RMV_CONTO, _mask->get_int(F_CONTOINI));
darec.put(RMV_SOTTOCONTO, _mask->get_long(F_SOTTOCINI));
arec.put(RMV_GRUPPO, _mask->get_int(F_GRUPPOFIN));
arec.put(RMV_CONTO, _mask->get_int(F_CONTOFIN));
arec.put(RMV_SOTTOCONTO, _mask->get_long(F_SOTTOCFIN));
// ordinamento per TSorted_cursor
TString ordin = "CODCMS|FASCMS|GRUPPO|CONTO|SOTTOCONTO|DATAREG|NUMREG|NUMRIG";
TSorted_cursor sortcur (&relrmov, ordin, filtro, 2, &darec, &arec);
sortcur.setregion(darec,arec);
sortcur.setfilter(filtro,TRUE);
long num = sortcur.items();
sortcur.freeze();
printer().open();
// setta l'intestazione del form...
set_intestazione();
TRectype currrec(LF_RMOV);
_oldcms = "@@";
_oldfsc = "@@";
_oldsottoc = -1;
_oldgruppo = -1;
_oldconto = -1;
_t_cms.azzera();
_t_fsc.azzera();
_t_gruppo.azzera();
_t_sottoc.azzera();
for (sortcur=0; sortcur.pos()<num; ++sortcur) //scansione su tutte le righe di movimento
{
const TRectype rmovrec = sortcur.curr();
_currcms = rmovrec.get(RMV_CODCMS);
_currfsc = rmovrec.get(RMV_FASCMS);
_currsottoc = rmovrec.get_long(RMV_SOTTOCONTO);
_currgruppo = rmovrec.get_int(RMV_GRUPPO);
_currconto = rmovrec.get_int(RMV_CONTO);
if ((_oldcms == _currcms) && (_oldfsc == _currfsc) && (_oldgruppo == _currgruppo) && (_oldconto == _currconto) && (_oldsottoc == _currsottoc))
{
TDate datareg = rmovrec.get_date(RMV_DATAREG);
TImporto importo(rmovrec.get_char(RMV_SEZIONE), rmovrec.get_real(RMV_IMPORTO));
aggiorna_totali(importo, datareg);
_t_gruppo+=_t_sottoc;
_t_cms+=_t_sottoc;
}
else
{
// stampo la riga del sottoconto se diverso da -1
print_sottoc();
// verifico se devo stampare il totale per gruppo
// questo accade se cambia gruppo/conto oppure se cambia commessa/fase
if ((_oldcms != _currcms) || (_oldfsc != _currfsc) || (_oldgruppo != _currgruppo) || (_oldconto != _currconto) )
{
if (_oldgruppo != -1)
print_footer_gruppo(_oldgruppo, _oldconto);
_oldgruppo = _currgruppo;
_oldconto = _currconto;
_t_gruppo.azzera();
if ((_oldcms != _currcms) || (_oldfsc != _currfsc))
{
if (_oldfsc != "@@")
print_footer_fase(_oldfsc);
_oldfsc = _currfsc;
_t_fsc.azzera();
ctrl_commessa();
print_header_fase(_currfsc);
}
print_header_gruppo(_currgruppo, _currconto);
}
}
}
if (num>0)
{
print_sottoc();
print_footer_gruppo(_currgruppo, _currconto);
print_footer_fase(_currfsc);
print_footer_commessa(_currcms);
printer().formfeed();
}
printer().close();
}
}
int cm0100(int argc, char* argv[])
{
TContixCdc a;
a.run(argc,argv,"Stampa conti per CDC/Commessa");
return 0;
}