Files correlati : cg7.exe cg7200a.rep cg2.exe Ricompilazione Demo : [ ] Commento : 0001887: lista movimenti per imponibile Manca la colonna non soggetto 0001888: prima nota Dopo l'installazione delle patch di ieri, sulla prima videata della prima nota è apparso un campo 'contabilità separata' non ho istruzioni su questa nuova funzionalità ma aprendo la tabella mi va in errore git-svn-id: svn://10.65.10.50/branches/R_10_00@22390 c028cbd2-c16b-5b4b-a496-9718f37d4682
318 lines
10 KiB
C++
Executable File
318 lines
10 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <report.h>
|
||
#include <textset.h>
|
||
|
||
#include <clifo.h>
|
||
#include <mov.h>
|
||
#include <occas.h>
|
||
#include <rmoviva.h>
|
||
|
||
#include "cglib01.h"
|
||
#include "cg7200a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Recordset
|
||
///////////////////////////////////////////////////////////
|
||
class TPrint_x_imponibile_recordset : public TAS400_recordset
|
||
{
|
||
public:
|
||
TPrint_x_imponibile_recordset();
|
||
};
|
||
|
||
TPrint_x_imponibile_recordset::TPrint_x_imponibile_recordset()
|
||
: TAS400_recordset("AS400(512)")
|
||
{
|
||
//const char* name, int pos, int len, TFieldtypes t = _alfafld, bool required = false, const TVariant& def = NULL_VARIANT
|
||
//campi da LF_MOV
|
||
create_field("Numreg", -1, 7, _longfld, true);
|
||
create_field("Datareg", -1, 8, _datefld, true);
|
||
create_field("Datadoc", -1, 8, _datefld, true);
|
||
create_field("Numdoc", -1, 7, _alfafld, true);
|
||
create_field("Tipodoc", -1, 2, _alfafld, true);
|
||
create_field("Codcaus", -1, 3, _alfafld, true);
|
||
create_field("Descr", -1, 50, _alfafld, false);
|
||
create_field("Reg", -1, 3, _alfafld, true);
|
||
create_field("Protiva", -1, 6, _longfld, true);
|
||
create_field("Tipo", -1, 1, _alfafld, true);
|
||
create_field("Totdoc", -1, 18, _realfld, true);
|
||
//campi da LF_CLIFO
|
||
create_field("Codcf", -1, 6, _longfld, true);
|
||
create_field("Ragsoc", -1, 50, _alfafld, true);
|
||
create_field("Piva", -1, 13, _alfafld, false);
|
||
create_field("Cofi", -1, 16, _alfafld, false);
|
||
create_field("Stato", -1, 40, _alfafld, false);
|
||
//campi da LF_RMOVIVA
|
||
create_field("Imponibile", -1, 18, _realfld, true);
|
||
create_field("Imposta", -1, 18, _realfld, false);
|
||
create_field("Imponibile_no", -1, 18, _realfld, false); // normale
|
||
create_field("Imponibile_ni", -1, 18, _realfld, false); // non imponibile
|
||
create_field("Imponibile_es", -1, 18, _realfld, false); // esente
|
||
create_field("Imponibile_ne", -1, 18, _realfld, false); // non esposta
|
||
create_field("Imponibile_ns", -1, 18, _realfld, false); // non soggetto
|
||
create_field("Imponibile_ma", -1, 18, _realfld, false); // margine
|
||
}
|
||
///////////////////////////////////////////////////////////
|
||
// Report
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPrint_x_imponibile_report : public TReport
|
||
{
|
||
protected:
|
||
virtual bool use_mask() { return false; }
|
||
|
||
public:
|
||
TPrint_x_imponibile_report();
|
||
};
|
||
|
||
TPrint_x_imponibile_report::TPrint_x_imponibile_report()
|
||
{
|
||
load("cg7200a");
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Maschera
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPrint_x_imponibile_mask : public TAutomask
|
||
{
|
||
real _limite;
|
||
|
||
protected:
|
||
bool convalida_clifo(const char tipocf, const long codcf);
|
||
bool aggiungi_movimento(const TRectype& rec, TPrint_x_imponibile_recordset& output_recordset);
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
void elabora();
|
||
TPrint_x_imponibile_mask();
|
||
};
|
||
|
||
bool TPrint_x_imponibile_mask::convalida_clifo(const char tipocf, const long codcf)
|
||
{
|
||
// Non eseguo voutamente i test propri del modulo FE
|
||
return codcf > 0L && (tipocf == 'C' || tipocf == 'F');
|
||
}
|
||
|
||
bool TPrint_x_imponibile_mask::aggiungi_movimento(const TRectype& rec, TPrint_x_imponibile_recordset& output_recordset)
|
||
{
|
||
//controlla se il clifo <20> da considerare o meno nella stampa
|
||
const char tipocf = rec.get_char(MOV_TIPO);
|
||
const long codcf = rec.get_long(MOV_CODCF);
|
||
if (!convalida_clifo(tipocf, codcf))
|
||
return false;
|
||
|
||
//se il cliente ha superato l'esame di ammissione si parte!
|
||
|
||
const TString& keytok = rec.get(MOV_NUMREG);
|
||
TRecord_array righe_iva(keytok, LF_RMOVIVA);
|
||
|
||
real tot_imponibile, tot_imposta;
|
||
real tot_impon_no, tot_impon_ni, tot_impon_es, tot_impon_ne, tot_impon_ns, tot_impon_ma;
|
||
|
||
TString4 tipoiva; //dichiarata qui perch<63> serve nella scrittura dell' output_recordset
|
||
|
||
//calcolo di imponibile ed imposta di tutte le righe iva del movimento
|
||
for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r))
|
||
{
|
||
const TRectype& rmi = righe_iva.row(r);
|
||
const real imponibile = rmi.get_real(RMI_IMPONIBILE);
|
||
const real imposta = rmi.get_real(RMI_IMPOSTA);
|
||
|
||
TCodiceIVA ci(rmi.get(RMI_CODIVA));
|
||
switch(ci.allegato(tipocf))
|
||
{
|
||
case 0: tot_impon_ns += imponibile; break;
|
||
case 2: tot_impon_ni += imponibile; break;
|
||
case 3: tot_impon_es += imponibile; break;
|
||
case 4: tot_impon_ne += imponibile; break;
|
||
case 5: tot_impon_ma += imponibile; break;
|
||
default: tot_impon_no += imponibile; break;
|
||
}
|
||
tot_imponibile += imponibile;
|
||
tot_imposta += imposta;
|
||
}
|
||
|
||
if (abs(tot_imponibile) > _limite)
|
||
{
|
||
output_recordset.new_rec("");
|
||
|
||
output_recordset.set("Numreg", rec.get_long(MOV_NUMREG));
|
||
output_recordset.set("Datareg", rec.get_date(MOV_DATAREG));
|
||
output_recordset.set("Datadoc", rec.get_date(MOV_DATADOC));
|
||
output_recordset.set("Numdoc", rec.get_long(MOV_NUMDOC));
|
||
output_recordset.set("Tipodoc", rec.get(MOV_TIPODOC));
|
||
output_recordset.set("Codcaus", rec.get(MOV_CODCAUS));
|
||
output_recordset.set("Descr", rec.get(MOV_DESCR));
|
||
output_recordset.set("Reg", rec.get(MOV_REG));
|
||
output_recordset.set("Protiva", rec.get_long(MOV_PROTIVA));
|
||
output_recordset.set("Tipo", rec.get(MOV_TIPO));
|
||
output_recordset.set("Codcf", codcf);
|
||
TString80 ragsoc, stato;
|
||
TString16 piva, cofi;
|
||
const TString16 ocfpi = rec.get(MOV_OCFPI); // <20> uno stupido cliente occasionale?
|
||
if (ocfpi.full())
|
||
{
|
||
const TRectype& rec_occas = cache().get(LF_OCCAS, ocfpi);
|
||
ragsoc = rec_occas.get(OCC_RAGSOC);
|
||
piva = rec_occas.get(OCC_PAIV);
|
||
cofi = rec_occas.get(OCC_COFI);
|
||
stato = cache().get("%STA", rec_occas.get(OCC_STATO), "S0");
|
||
}
|
||
else
|
||
{
|
||
TToken_string key_clifo;
|
||
key_clifo.add(rec.get(MOV_TIPO));
|
||
key_clifo.add(codcf);
|
||
const TRectype& rec_clifo = cache().get(LF_CLIFO, key_clifo);
|
||
ragsoc = rec_clifo.get(CLI_RAGSOC);
|
||
piva = rec_clifo.get(CLI_PAIV);
|
||
cofi = rec_clifo.get(CLI_COFI);
|
||
stato = cache().get("%STA", rec_clifo.get(CLI_STATOCF), "S0");
|
||
}
|
||
output_recordset.set("Ragsoc", ragsoc);
|
||
output_recordset.set("Piva", piva);
|
||
output_recordset.set("Cofi", cofi);
|
||
output_recordset.set("Stato", stato);
|
||
|
||
output_recordset.set("Totdoc", rec.get_real(MOV_TOTDOC));
|
||
output_recordset.set("Imponibile", tot_imponibile);
|
||
output_recordset.set("Imposta", tot_imposta);
|
||
output_recordset.set("Imponibile_no", tot_impon_no);
|
||
output_recordset.set("Imponibile_ni", tot_impon_ni);
|
||
output_recordset.set("Imponibile_es", tot_impon_es);
|
||
output_recordset.set("Imponibile_ne", tot_impon_ne);
|
||
output_recordset.set("Imponibile_ns", tot_impon_ns);
|
||
output_recordset.set("Imponibile_ma", tot_impon_ma);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
void TPrint_x_imponibile_mask::elabora()
|
||
{
|
||
const char tipodate = get(F_TIPODATE)[0];
|
||
const TString& tipoelenco = get(F_TIPOELENCO);
|
||
const long codcf = get_long(F_CODCF);
|
||
const bool clifo_spec = codcf > 0L;
|
||
|
||
const TDate dataini = get_date(F_DATAINI);
|
||
const TDate datafine = get_date(F_DATAFIN);
|
||
|
||
_limite = get_real(F_LIMITE);
|
||
|
||
TString query;
|
||
|
||
query << "USE MOV KEY 2";
|
||
query << "\nSELECT (TIPO=#TIPO)";
|
||
if (clifo_spec)
|
||
query << "&&(CODCF=#CODCF)";
|
||
if (tipodate == 'D') //per data 'D'ocumento
|
||
{
|
||
query << "&&(BETWEEN(DATADOC,#DATAINI,#DATAFINE))";
|
||
query << "\nBY TIPO CODCF NUMREG";
|
||
query << "\nFROM DATAREG=#DATAINI";
|
||
TDate datadoc_fine = datafine;
|
||
datadoc_fine.addyear(2);
|
||
query << "\nTO DATAREG=" << datadoc_fine;
|
||
}
|
||
else //per data 'R'egistrazione
|
||
{
|
||
query << "\nBY TIPO CODCF NUMREG";
|
||
query << "\nFROM DATAREG=#DATAINI";
|
||
query << "\nTO DATAREG=#DATAFINE";
|
||
}
|
||
//recordset con tutti i movimenti contabili di campo che soddisfano la query
|
||
TISAM_recordset movimenti_recset(query);
|
||
|
||
movimenti_recset.set_var("#TIPO", tipoelenco);
|
||
movimenti_recset.set_var("#CODCF", codcf);
|
||
|
||
movimenti_recset.set_var("#DATAINI", dataini);
|
||
movimenti_recset.set_var("#DATAFINE", datafine);
|
||
|
||
const long movimenti_recset_items = movimenti_recset.items();
|
||
//recordset di output su cui scrivere i record validi da mandare in stampa!
|
||
TPrint_x_imponibile_recordset* output_recordset = new TPrint_x_imponibile_recordset;
|
||
|
||
if (movimenti_recset_items > 0) // Provoca la chiusura della TProgind durante l'anteprima successiva
|
||
{
|
||
//solita progind per intrattenere l'utonto
|
||
TProgind pi(movimenti_recset_items, TR("Scansione movimenti in corso..."), true, true);
|
||
|
||
//giro su tutti i movimenti contabili che soddisfano la query
|
||
for (bool ok = movimenti_recset.move_first(); ok; ok = movimenti_recset.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
|
||
//metodo che decide se aggiungere i dati di un movimento all'output recordset
|
||
//al suo interno ci sono tutti i filtri di legge!
|
||
aggiungi_movimento(movimenti_recset.cursor()->curr(), *output_recordset);
|
||
}
|
||
}
|
||
|
||
#ifdef DBG
|
||
output_recordset->save_as("D:/dati/crpa/cazzone.xls", fmt_html);
|
||
#endif
|
||
|
||
//appiccia il recordset al report
|
||
TPrint_x_imponibile_report rep;
|
||
rep.set_recordset(output_recordset);
|
||
rep.mask2report(*this);
|
||
rep.preview();
|
||
|
||
}
|
||
|
||
bool TPrint_x_imponibile_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_DATASTAMPA:
|
||
if (e == fe_init)
|
||
{
|
||
TDate ds = o.get(); ds.addyear(-1);
|
||
TDate dal(1, 1, ds.year());
|
||
TDate al(31,12, ds.year());
|
||
set(F_DATAINI, dal);
|
||
set(F_DATAFIN, al);
|
||
}
|
||
break;
|
||
default: break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TPrint_x_imponibile_mask::TPrint_x_imponibile_mask() : TAutomask("cg7200a")
|
||
{ }
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Applicazione
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPrint_x_imponibile : public TSkeleton_application
|
||
{
|
||
protected:
|
||
|
||
public:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
|
||
void TPrint_x_imponibile::main_loop()
|
||
{
|
||
TPrint_x_imponibile_mask mask;
|
||
while (mask.run() == K_ENTER)
|
||
mask.elabora();
|
||
}
|
||
|
||
int cg7200(int argc, char* argv[])
|
||
{
|
||
TPrint_x_imponibile app;
|
||
app.run(argc, argv, TR("Lista movimenti per imponibile"));
|
||
return 0;
|
||
}
|