2011-03-21 16:57:29 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <automask.h>
|
2011-03-25 15:20:29 +00:00
|
|
|
|
#include <progind.h>
|
2011-03-23 16:19:49 +00:00
|
|
|
|
#include <recarray.h>
|
|
|
|
|
#include <relation.h>
|
2011-03-21 16:57:29 +00:00
|
|
|
|
#include <report.h>
|
2011-03-25 15:20:29 +00:00
|
|
|
|
#include <textset.h>
|
2011-03-21 16:57:29 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
#include <clifo.h>
|
2011-03-23 16:19:49 +00:00
|
|
|
|
#include <mov.h>
|
2011-03-30 13:16:41 +00:00
|
|
|
|
#include <occas.h>
|
2011-03-23 16:19:49 +00:00
|
|
|
|
#include <rmoviva.h>
|
2011-06-21 15:01:30 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
#include "cglib01.h"
|
|
|
|
|
#include "cg7200a.h"
|
2011-03-21 16:57:29 +00:00
|
|
|
|
|
2011-03-23 16:19:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Recordset
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2011-03-25 15:20:29 +00:00
|
|
|
|
class TPrint_x_imponibile_recordset : public TAS400_recordset
|
2011-03-23 16:19:49 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2011-03-25 15:20:29 +00:00
|
|
|
|
TPrint_x_imponibile_recordset();
|
2011-03-23 16:19:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
TPrint_x_imponibile_recordset::TPrint_x_imponibile_recordset()
|
|
|
|
|
: TAS400_recordset("AS400(512)")
|
2011-03-23 16:19:49 +00:00
|
|
|
|
{
|
2011-03-25 15:20:29 +00:00
|
|
|
|
//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);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
create_field("Totdoc", -1, 18, _realfld, true);
|
|
|
|
|
//campi da LF_CLIFO
|
2011-03-25 15:20:29 +00:00
|
|
|
|
create_field("Codcf", -1, 6, _longfld, true);
|
2011-03-30 13:16:41 +00:00
|
|
|
|
create_field("Ragsoc", -1, 50, _alfafld, true);
|
2011-03-30 13:37:00 +00:00
|
|
|
|
create_field("Piva", -1, 13, _alfafld, false);
|
|
|
|
|
create_field("Cofi", -1, 16, _alfafld, false);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
create_field("Stato", -1, 40, _alfafld, false);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
//campi da LF_RMOVIVA
|
|
|
|
|
create_field("Imponibile", -1, 18, _realfld, true);
|
|
|
|
|
create_field("Imposta", -1, 18, _realfld, false);
|
2011-07-11 10:26:12 +00:00
|
|
|
|
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
|
2011-03-23 16:19:49 +00:00
|
|
|
|
}
|
2011-03-21 16:57:29 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// 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
|
|
|
|
|
{
|
2011-07-06 15:36:32 +00:00
|
|
|
|
real _limite;
|
|
|
|
|
|
2011-03-21 16:57:29 +00:00
|
|
|
|
protected:
|
2011-03-25 15:20:29 +00:00
|
|
|
|
bool convalida_clifo(const char tipocf, const long codcf);
|
|
|
|
|
bool aggiungi_movimento(const TRectype& rec, TPrint_x_imponibile_recordset& output_recordset);
|
2011-03-21 16:57:29 +00:00
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void elabora();
|
|
|
|
|
TPrint_x_imponibile_mask();
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
bool TPrint_x_imponibile_mask::convalida_clifo(const char tipocf, const long codcf)
|
|
|
|
|
{
|
2011-07-06 15:36:32 +00:00
|
|
|
|
// Non eseguo voutamente i test propri del modulo FE
|
|
|
|
|
return codcf > 0L && (tipocf == 'C' || tipocf == 'F');
|
2011-03-25 15:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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!
|
2011-07-06 15:36:32 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
const TString& keytok = rec.get(MOV_NUMREG);
|
|
|
|
|
TRecord_array righe_iva(keytok, LF_RMOVIVA);
|
|
|
|
|
|
2011-07-06 15:36:32 +00:00
|
|
|
|
real tot_imponibile, tot_imposta;
|
2011-07-11 10:26:12 +00:00
|
|
|
|
real tot_impon_no, tot_impon_ni, tot_impon_es, tot_impon_ne, tot_impon_ns, tot_impon_ma;
|
2011-07-06 15:36:32 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
const real imponibile = rmi.get_real(RMI_IMPONIBILE);
|
|
|
|
|
const real imposta = rmi.get_real(RMI_IMPOSTA);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
|
2011-07-06 15:36:32 +00:00
|
|
|
|
TCodiceIVA ci(rmi.get(RMI_CODIVA));
|
|
|
|
|
switch(ci.allegato(tipocf))
|
2011-03-25 15:20:29 +00:00
|
|
|
|
{
|
2011-07-11 10:26:12 +00:00
|
|
|
|
case 0: tot_impon_ns += imponibile; break;
|
2011-07-06 15:36:32 +00:00
|
|
|
|
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;
|
2011-03-25 15:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
tot_imponibile += imponibile;
|
|
|
|
|
tot_imposta += imposta;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 15:41:19 +00:00
|
|
|
|
if (abs(tot_imponibile) >= _limite)
|
2011-03-25 15:20:29 +00:00
|
|
|
|
{
|
|
|
|
|
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));
|
2011-07-06 15:36:32 +00:00
|
|
|
|
output_recordset.set("Tipodoc", rec.get(MOV_TIPODOC));
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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));
|
2011-03-30 11:13:10 +00:00
|
|
|
|
output_recordset.set("Tipo", rec.get(MOV_TIPO));
|
2011-03-25 15:20:29 +00:00
|
|
|
|
output_recordset.set("Codcf", codcf);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
TString80 ragsoc, stato;
|
2011-03-30 13:37:00 +00:00
|
|
|
|
TString16 piva, cofi;
|
2011-06-21 15:01:30 +00:00
|
|
|
|
const TString16 ocfpi = rec.get(MOV_OCFPI); // <20> uno stupido cliente occasionale?
|
2011-03-30 13:16:41 +00:00
|
|
|
|
if (ocfpi.full())
|
|
|
|
|
{
|
2011-03-30 13:37:00 +00:00
|
|
|
|
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);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
stato = cache().get("%STA", rec_occas.get(OCC_STATO), "S0");
|
2011-03-30 13:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TToken_string key_clifo;
|
|
|
|
|
key_clifo.add(rec.get(MOV_TIPO));
|
|
|
|
|
key_clifo.add(codcf);
|
2011-03-30 13:37:00 +00:00
|
|
|
|
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);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
stato = cache().get("%STA", rec_clifo.get(CLI_STATOCF), "S0");
|
2011-03-30 13:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
output_recordset.set("Ragsoc", ragsoc);
|
2011-03-30 13:37:00 +00:00
|
|
|
|
output_recordset.set("Piva", piva);
|
|
|
|
|
output_recordset.set("Cofi", cofi);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
output_recordset.set("Stato", stato);
|
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
output_recordset.set("Imponibile_ne", tot_impon_ne);
|
2011-07-11 10:26:12 +00:00
|
|
|
|
output_recordset.set("Imponibile_ns", tot_impon_ns);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
output_recordset.set("Imponibile_ma", tot_impon_ma);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-03-21 16:57:29 +00:00
|
|
|
|
|
|
|
|
|
void TPrint_x_imponibile_mask::elabora()
|
|
|
|
|
{
|
|
|
|
|
const char tipodate = get(F_TIPODATE)[0];
|
2011-03-25 15:20:29 +00:00
|
|
|
|
const TString& tipoelenco = get(F_TIPOELENCO);
|
2011-03-21 16:57:29 +00:00
|
|
|
|
const long codcf = get_long(F_CODCF);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
const bool clifo_spec = codcf > 0L;
|
2011-07-06 15:36:32 +00:00
|
|
|
|
|
2011-03-28 10:31:47 +00:00
|
|
|
|
const TDate dataini = get_date(F_DATAINI);
|
|
|
|
|
const TDate datafine = get_date(F_DATAFIN);
|
2011-07-06 15:36:32 +00:00
|
|
|
|
|
|
|
|
|
_limite = get_real(F_LIMITE);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
|
2011-03-21 16:57:29 +00:00
|
|
|
|
TString query;
|
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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
|
2011-03-21 16:57:29 +00:00
|
|
|
|
{
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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);
|
2011-03-22 16:47:42 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
movimenti_recset.set_var("#TIPO", tipoelenco);
|
|
|
|
|
movimenti_recset.set_var("#CODCF", codcf);
|
|
|
|
|
|
|
|
|
|
movimenti_recset.set_var("#DATAINI", dataini);
|
|
|
|
|
movimenti_recset.set_var("#DATAFINE", datafine);
|
2011-03-22 16:47:42 +00:00
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2011-07-06 15:36:32 +00:00
|
|
|
|
if (movimenti_recset_items > 0) // Provoca la chiusura della TProgind durante l'anteprima successiva
|
2011-03-21 16:57:29 +00:00
|
|
|
|
{
|
2011-07-06 15:36:32 +00:00
|
|
|
|
//solita progind per intrattenere l'utonto
|
|
|
|
|
TProgind pi(movimenti_recset_items, TR("Scansione movimenti in corso..."), true, true);
|
2011-03-25 15:20:29 +00:00
|
|
|
|
|
2011-07-06 15:36:32 +00:00
|
|
|
|
//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);
|
|
|
|
|
}
|
2011-03-21 16:57:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 15:20:29 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
output_recordset->save_as("D:/dati/crpa/cazzone.xls", fmt_html);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//appiccia il recordset al report
|
2011-03-21 16:57:29 +00:00
|
|
|
|
TPrint_x_imponibile_report rep;
|
2011-03-25 15:20:29 +00:00
|
|
|
|
rep.set_recordset(output_recordset);
|
2011-03-22 16:47:42 +00:00
|
|
|
|
rep.mask2report(*this);
|
|
|
|
|
rep.preview();
|
2011-03-21 16:57:29 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_x_imponibile_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
2011-03-22 16:47:42 +00:00
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
2011-07-06 15:36:32 +00:00
|
|
|
|
case F_DATASTAMPA:
|
|
|
|
|
if (e == fe_init)
|
2011-03-22 16:47:42 +00:00
|
|
|
|
{
|
2011-07-06 15:36:32 +00:00
|
|
|
|
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);
|
2011-03-22 16:47:42 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2011-07-06 15:36:32 +00:00
|
|
|
|
default: break;
|
2011-03-22 16:47:42 +00:00
|
|
|
|
}
|
2011-03-21 16:57:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPrint_x_imponibile_mask::TPrint_x_imponibile_mask() : TAutomask("cg7200a")
|
2011-07-11 10:26:12 +00:00
|
|
|
|
{ }
|
2011-03-21 16:57:29 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Applicazione
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-07-06 15:36:32 +00:00
|
|
|
|
class TPrint_x_imponibile : public TSkeleton_application
|
2011-03-21 16:57:29 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2011-03-28 10:45:29 +00:00
|
|
|
|
app.run(argc, argv, TR("Lista movimenti per imponibile"));
|
2011-03-21 16:57:29 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|