campo-sirio/cm/cm1100.cpp
luca c8cd2bf9bd Patch level :2.0 nopatch
Files correlati     :cm1 & friends
Ricompilazione Demo : [ ]
Commento            :prima stesura personalizzazione commesse CRPA


git-svn-id: svn://10.65.10.50/trunk@11658 c028cbd2-c16b-5b4b-a496-9718f37d4682
2003-12-10 12:10:52 +00:00

315 lines
7.6 KiB
C++
Executable File

#include <applicat.h>
#include <automask.h>
#include <form.h>
#include <printer.h>
#include <partite.h>
#include <mov.h>
#include <rmoviva.h>
#include "..\cg\cgsaldac.h"
#include "..\ve\velib.h"
#include "cm1100a.h"
#include "cm1100.h"
//===============================================================================================
//maschera
class TPag_per_cms_mask: public TAutomask
{
public:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
TPag_per_cms_mask():TAutomask("cm1100a") {}
};
bool TPag_per_cms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
/* switch (o.dlg())
{
default: break;
}*/
return true;
}
//===============================================================================================
//struct dei dati da passare in stampa
struct TPag_per_cms_struct : public TObject
{
long _codforn;
TDate _datapag;
TCurrency _importopagato;
TString _descrpagamento;
long _nreg;
TString _commessa;
TCurrency _importocommessa;
};
//===============================================================================================
//form
class TPag_per_cms_form : public TForm
{
TArray& _pagamenti; //puntatore all'arrayone dei pagamenti
int _curr_pag; //pagamento corrente
protected:
virtual long records() const {return _pagamenti.items();}
bool validate(TForm_item &cf, TToken_string &s);
const TPag_per_cms_struct& curr() const { return(TPag_per_cms_struct&)_pagamenti[_curr_pag]; }
public:
void print(const TMask& m);
TPag_per_cms_form(TArray& pag);
virtual ~TPag_per_cms_form();
};
bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s)
{
if (s == "_NEXTPAG")
{
_curr_pag ++; //aggiorna il contatore pagamenti quando ne trova uno sull'arrayone
return true;
}
if (s == "_CODCMS")
{
cf.set(curr()._commessa);
return true;
}
if (s == "_TOTDOC")
{
cf.set(curr()._importocommessa.get_num().string());
return true;
}
if (s == "_TOTPAG")
{
cf.set(curr()._importopagato.get_num().string());
return true;
}
return TForm::validate(cf,s);
}
void TPag_per_cms_form::print(const TMask& m)
{
TPrint_section& header = section('H', odd_page);
header.find_field(FR_DATAINI).set(m.get(F_DATAINI));
header.find_field(FR_DATAFIN).set(m.get(F_DATAFIN));
header.find_field(FR_DACDC).set(m.get(F_DACDC));
header.find_field(FR_ACDC).set(m.get(F_ACDC));
_curr_pag = 0;
TForm::print(); //chiama la vera print dopo aver azzerato il contatore
}
TPag_per_cms_form::TPag_per_cms_form(TArray& pag) :TForm ("cm1100a"), _pagamenti(pag)
{
}
TPag_per_cms_form::~TPag_per_cms_form()
{
}
//===============================================================================================
//Applicazione
class TPag_per_cms : public TSkeleton_application
{
TPag_per_cms_mask* _mask;
TPag_per_cms_form* _form;
TArray _pagamenti;
protected:
virtual void main_loop();
virtual bool create();
virtual bool destroy();
public:
long find_movimento(const TRectype& riga_pag);
void find_commesse(const long nreg, const TRectype& riga_pag, const char * tipodata);
};
long TPag_per_cms::find_movimento(const TRectype& riga_pag)
{
int n_fatture = 0; //numero di fatture trovate
int first_fatt = 0; //numero riga della prima fattura
//scan della partita dall'ultima alla prima riga
TPartita partita(riga_pag);
for (int p = partita.last(); p > 0; p = partita.pred(p))
{
const TRiga_partite& fatt = partita.riga(p);
if (fatt.is_fattura())
{
n_fatture ++;
first_fatt = p;
}
}
if (n_fatture > 1)
{
const int linea_pag = riga_pag.get_int(PART_NRIGA);
int linea_fattura = 0;
for (int f = first_fatt; (f > 0) && (f <= partita.last()) && (linea_fattura == 0); f = partita.succ(f))
{
const TRiga_partite& fatt = partita.riga(f);
if (fatt.is_fattura())
{
for (int r = 1; r <= fatt.rate(); r++)
{
const TRiga_scadenze& rata = fatt.rata(r);
if (rata.exist(linea_pag))
{
linea_fattura = f;
break;
}
}
}
}
first_fatt = linea_fattura;
}
long nreg = 0;
if (first_fatt > 0)
{
const TRiga_partite& fatt = partita.riga(first_fatt);
nreg = fatt.get_long(PART_NREG);
}
return nreg;
}
void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag, const char * tipodata)
{
TMovimentoPN pn;
pn.curr().put(MOV_NUMREG, nreg);
if (pn.read() == NOERR)
{
const real totdoc = pn.curr().get_real(MOV_TOTDOC);
const real totpagato = riga_pag.get_real(PART_IMPORTO);
const real percentuale = totpagato / totdoc;
TAssoc_array commesse;
for (int i = 0; i < pn.iva_items(); i++)
{
const TRectype& rmoviva = pn.iva(i);
const TString80 codcms = rmoviva.get(RMI_CODCMS);
if (codcms.not_empty())
{
real* imp = (real*)commesse.objptr(codcms);
if (imp == NULL)
{
imp = new real;
commesse.add(codcms, imp);
}
real importo = rmoviva.get_real(RMI_IMPONIBILE) + rmoviva.get_real(RMI_IMPOSTA);
*imp += importo;
}
}
FOR_EACH_ASSOC_OBJECT(commesse, h, k, imp)
{
const real& impcms = *(real*)imp;
TPag_per_cms_struct* ppcs = new TPag_per_cms_struct;
ppcs->_codforn = riga_pag.get_long(PART_SOTTOCONTO);
ppcs->_datapag = riga_pag.get_date(tipodata);
ppcs->_importopagato.set_num(impcms * percentuale); //pagamento nella partita
ppcs->_descrpagamento = riga_pag.get(PART_DESCR);
ppcs->_nreg = nreg;
ppcs->_commessa = k;
ppcs->_importocommessa.set_num(impcms); //importo da pagare scritto sulla fattura
_pagamenti.add(ppcs); //aggiunge il pagamento all'array dei pagamenti
}
}
}
bool TPag_per_cms::create()
{
_mask = new TPag_per_cms_mask;
_form = new TPag_per_cms_form(_pagamenti);
return TSkeleton_application::create();
}
bool TPag_per_cms::destroy()
{
delete _mask;
delete _form;
return TRUE;
}
void TPag_per_cms::main_loop()
{
while (_mask->run() == K_ENTER)
{
//costruzione filtro sulle date
const char * tipodata = PART_DATAREG;
switch(_mask->get_int(F_TIPODATA))
{
case 1:tipodata = PART_DATADOC;break;
case 2:tipodata = PART_DATAPAG;break;
default:break;
}
TString filtro = "(TIPOC==\"F\")&&(TIPOPAG>=\"3\")"; //deve essere un pagamento a fornitore!!!
const TDate dataini = _mask->get_date(F_DATAINI);
const TDate datafin = _mask->get_date(F_DATAFIN);
if (dataini.ok())
{
if (filtro.not_empty())
filtro << "&&";
TString filtrofinale;
filtrofinale.format("(ANSI(%s)>=\"%s\")", tipodata,dataini.string(ANSI));
filtro << filtrofinale;
}
if (datafin.ok())
{
if (filtro.not_empty())
filtro << "&&";
TString filtrofinale;
filtrofinale.format("(ANSI(%s)<=\"%s\")", tipodata,datafin.string(ANSI));
filtro << filtrofinale;
}
//applica il filtro ai due file della relazione
TRelation rel(LF_PARTITE);
TCursor cur(&rel, filtro);
const TRectype& riga_part_pag = cur.curr(); //riga partita pagamento
const long items = cur.items();
cur.freeze();
_pagamenti.destroy(); //azzera l'arrayone dei pagamenti
//ciclo sui pagamenti selezionati per trovare i movimenti
for (cur=0; cur.pos()<items; ++cur)
{
const long nreg = find_movimento(riga_part_pag);
if (nreg > 0)
find_commesse(nreg, riga_part_pag, tipodata);
}
_form->print(*_mask);
}
}
int cm1100(int argc, char* argv[])
{
TPag_per_cms a;
a.run(argc,argv,TR("Stampa pagato per commessa"));
return 0;
}