Files correlati :cg7.exe cg7200a.msk proforma.ini Ricompilazione Demo : [ ] Commento :nuovo trasferimento a Proforma della 2.2; corretto tracciato proforma.ini per tener conto dei nuovi formati dei campi dei conti; implementato calcolo ritenute sui pagamenti. git-svn-id: svn://10.65.10.50/trunk@13556 c028cbd2-c16b-5b4b-a496-9718f37d4682
837 lines
25 KiB
C++
Executable File
837 lines
25 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <assoc.h>
|
||
#include <automask.h>
|
||
#include <currency.h>
|
||
#include <defmask.h>
|
||
#include <filetext.h>
|
||
#include <msksheet.h>
|
||
#include <printer.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <sort.h>
|
||
#include <utility.h>
|
||
|
||
#include "cg7.h"
|
||
#include "cg7200a.h"
|
||
#include "cglib01.h"
|
||
#include "cg2101.h"
|
||
#include "cg2103.h"
|
||
#include "cgsaldac.h"
|
||
|
||
#include <mov.h>
|
||
#include <rmov.h>
|
||
#include <rmoviva.h>
|
||
#include <pagsca.h>
|
||
#include <partite.h>
|
||
|
||
#include "../ca/calib01.h"
|
||
#include "../ca/movana.h"
|
||
#include "../ca/rmovana.h"
|
||
|
||
class TInvioP_file: public TFile_text
|
||
{
|
||
protected:
|
||
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
||
|
||
public:
|
||
TInvioP_file(const TString& file_name);
|
||
virtual ~TInvioP_file() { }
|
||
};
|
||
|
||
TInvioP_file::TInvioP_file(const TString& file_name)
|
||
: TFile_text(file_name, "proforma.ini")
|
||
{
|
||
}
|
||
|
||
//////////////////////////////////////////////////////
|
||
// MASCHERA
|
||
//////////////////////////////////////////////////////
|
||
|
||
class TInvioP_mask : public TAutomask
|
||
{
|
||
protected:
|
||
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
void config_loader(TSheet_field& sf, const char* paragrafo);
|
||
void config_setter(TSheet_field& sf, const char* paragrafo);
|
||
|
||
public:
|
||
TInvioP_mask();
|
||
virtual ~TInvioP_mask(){};
|
||
};
|
||
|
||
TInvioP_mask::TInvioP_mask() :TAutomask ("cg7200a")
|
||
{
|
||
config_loader(sfield(F_PDCC), "Pdcc");
|
||
}
|
||
|
||
bool TInvioP_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_CODDITTA:
|
||
if (e==fe_init && o.empty())
|
||
{
|
||
set(F_CODDITTA, main_app().get_firm());
|
||
((TEdit_field&) o).check();
|
||
disable(F_CODDITTA);
|
||
}
|
||
break;
|
||
case DLG_SAVEREC:
|
||
if (e == fe_button)
|
||
{
|
||
config_setter(sfield(F_PDCC), "Pdcc");
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TInvioP_mask::config_loader(TSheet_field& sf, const char* paragrafo)
|
||
{
|
||
//carica file configurazione conti; attenzione!!!il file di configurazione in questione e' il
|
||
//medesimo del programma per la stampa del pagato in contabilita' analitica, visto che i due
|
||
//programmi necessitano degli stessi conti
|
||
TFilename configname = "ca3600.ini";
|
||
configname.custom_path();
|
||
TConfig configfile(configname, paragrafo);
|
||
|
||
TString_array conti;
|
||
|
||
int n = configfile.list_variables(conti, false, paragrafo, true);
|
||
FOR_EACH_ARRAY_ROW(conti, i, row)
|
||
{
|
||
sf.row(-1) = configfile.get(*row); //carica la riga del .ini senza il contatore
|
||
sf.check_row(i);
|
||
}
|
||
}
|
||
|
||
void TInvioP_mask::config_setter(TSheet_field& sf, const char* paragrafo)
|
||
{
|
||
TFilename configname = "ca3600.ini";
|
||
configname.custom_path();
|
||
TConfig configfile(configname, paragrafo);
|
||
|
||
configfile.remove_all(); //svuota il paragrafo sul .ini prima di ricompilarlo (se non si facesse
|
||
//non si riuscirebbero ad ammazzare le righe sul .ini
|
||
FOR_EACH_SHEET_ROW (sf, i, row)
|
||
{
|
||
TToken_string conto("");
|
||
conto.add(row->get(0));
|
||
conto.add(row->get(1));
|
||
conto.add(row->get(2));
|
||
conto.add(row->get(3));
|
||
|
||
configfile.set("conto", conto, NULL, true, i);
|
||
}
|
||
}
|
||
|
||
//////////////////////////////////////////////
|
||
// APPLICAZIONE
|
||
//////////////////////////////////////////////
|
||
|
||
class TInvioP : public TSkeleton_application
|
||
{
|
||
TCursor* _cur;
|
||
TInvioP_mask* _msk;
|
||
TDate _dataini, _datafin;
|
||
long _nregcosto, _nregpag;
|
||
real _importo;
|
||
TConfig* _configfile;
|
||
TAssoc_array _fiscali,_sociali; //array che contengono i conti
|
||
|
||
protected:
|
||
virtual bool create(void);
|
||
virtual bool destroy(void);
|
||
virtual void main_loop() ;
|
||
void invio_proforma();
|
||
bool i_proforma_movimenti();
|
||
bool i_proforma_righe(TCursor& cur, TInvioP_file* trasfile);
|
||
bool i_proforma_pagamenti();
|
||
bool i_proforma_clifor(char tipocf = 'C');
|
||
bool i_proforma_conti();
|
||
|
||
real totale_documento(const TRectype& mov) const;
|
||
void lettura_conti(TAssoc_array& assoc, const char tipoconto);
|
||
bool cerca_conto(const TBill& bill, const TAssoc_array& assoc, const char tipoconto) const;
|
||
bool cerca_fiscali(const TBill& bill) const;
|
||
bool cerca_sociali(const TBill& bill) const;
|
||
bool test_swap(TCausale& caus, bool ritsoc) const;
|
||
real calcola_pagamento(TRectype& curpag_rec);
|
||
|
||
public:
|
||
const real get_importo() {return _importo;};
|
||
const char* get_nregcosto() {return format("%d", _nregcosto);};
|
||
const char* get_nregpag() {return format("%d", _nregpag);};
|
||
const char* get_vocespesa(const int gruppo, const int conto, const long sottoc);
|
||
TInvioP_file* apri_file(const char* nome);
|
||
void chiudi_file(TInvioP_file* trasfile);
|
||
|
||
TInvioP() {};
|
||
virtual ~TInvioP() {};
|
||
};
|
||
|
||
// restituisce un riferimento all' applicazione
|
||
inline TInvioP& app() { return (TInvioP&) main_app();}
|
||
|
||
// gestione dei messaggi estesi nei campi
|
||
void TInvioP_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
|
||
{
|
||
const TString code(s.get(0));
|
||
TString valore;
|
||
if (code == "_FISSO")
|
||
{
|
||
// gestione dei campi fissi per i record delle riba
|
||
// sintassi: _FISSO,!<valore>
|
||
// dove: <valore> <20> la stringa fissa da emettere
|
||
TString in(s.get());
|
||
CHECK(in[0]=='!',"Macro _FISSO senza carattere '!'");
|
||
in.ltrim(1);
|
||
in.trim();
|
||
valore = in;
|
||
}
|
||
else if (code == "_TELEFONO")
|
||
{
|
||
valore = str;
|
||
valore.trim();
|
||
str = cur.curr().get("PTEL");
|
||
valore << str;
|
||
valore.trim();
|
||
}
|
||
else if (code == "_VOCESPESA")
|
||
{
|
||
const int gruppo = atoi(rec.get(3));
|
||
const int conto = atoi(rec.get(4));
|
||
const long sottoc = atol(rec.get(5));
|
||
valore = app().get_vocespesa(gruppo, conto, sottoc);
|
||
}
|
||
else if (code == "_RAGSOC")
|
||
{
|
||
valore = str;
|
||
valore = valore.strip_double_spaces();
|
||
}
|
||
else if (code == "_FLAG")
|
||
{
|
||
const char chiusa = str[0];
|
||
valore = (chiusa=='X') ? "S" : "A";
|
||
|
||
}
|
||
else if (code == "_NREGCOSTO")
|
||
{
|
||
valore = app().get_nregcosto();
|
||
}
|
||
else if (code == "_NREGPAG")
|
||
{
|
||
valore = app().get_nregpag();
|
||
}
|
||
else if (code == "_IMPORTO")
|
||
{
|
||
valore = app().get_importo().string();
|
||
}
|
||
|
||
else NFCHECK("Macro non definita: %s", (const char *)code);
|
||
str = valore;
|
||
}
|
||
|
||
TInvioP_file* TInvioP::apri_file(const char* nome)
|
||
{
|
||
TFilename filename = _msk->get(F_DESTINAZIONE);
|
||
filename.add(nome);
|
||
filename.ext("txt");
|
||
if (filename.exist())
|
||
remove(filename);
|
||
|
||
TInvioP_file* trasfile = new TInvioP_file(filename);
|
||
trasfile->open(filename,'w');
|
||
trasfile->force_record_separator();
|
||
return trasfile;
|
||
}
|
||
|
||
void TInvioP::chiudi_file(TInvioP_file* trasfile)
|
||
{
|
||
trasfile->close();
|
||
delete trasfile;
|
||
}
|
||
|
||
const char* TInvioP::get_vocespesa(const int gruppo,const int conto, const long sottoc)
|
||
{
|
||
TFilename configname = "cg7200a.ini"; //file configurazione della maschera
|
||
configname.custom_path();
|
||
TConfig configfile(configname);
|
||
TString80 confstringa = configfile.get("CONFSTRINGA");
|
||
confstringa.trim();
|
||
const int len = confstringa.len();
|
||
TLocalisamfile panapdc(LF_PANAPDC);
|
||
panapdc.zero();
|
||
panapdc.setkey(2);
|
||
panapdc.put("GRUPPO", gruppo);
|
||
panapdc.put("CONTO", conto);
|
||
panapdc.put("SOTTOCONTO", sottoc);
|
||
TRectype r(panapdc.curr());
|
||
for (panapdc.read(); !panapdc.eof(); panapdc.next())
|
||
{
|
||
if (panapdc.curr() != r) break;
|
||
const TString& codconto = panapdc.get("CODCONTO");
|
||
const TString& prefisso = codconto.sub(0,len-1);
|
||
if (prefisso == confstringa)
|
||
return codconto.sub(len-1);
|
||
}
|
||
return "";
|
||
}
|
||
|
||
bool TInvioP::i_proforma_conti()
|
||
{
|
||
TInvioP_file* trasfile = apri_file("pianocon");
|
||
|
||
TRelation rel(LF_PCON);
|
||
TCursor cur(&rel);
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
{
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
TRecord_text rec;
|
||
rec.set_type("P");
|
||
trasfile->autoload(rec, cur);
|
||
trasfile->write(rec);
|
||
}
|
||
}
|
||
chiudi_file(trasfile);
|
||
return true;
|
||
}
|
||
|
||
bool TInvioP::i_proforma_movimenti()
|
||
{
|
||
TInvioP_file* trasfile = apri_file("registra"); //file testate
|
||
TInvioP_file* trasfilerighe = apri_file("righe"); //file righe movimenti
|
||
|
||
//trasferimento testate movimenti (cerca direttamente sui movimenti analitici in chiave 2..
|
||
//..,cio<69> per DATACOMP e con NUMREGCG!=0
|
||
TRectype da(LF_MOVANA);
|
||
TRectype a(LF_MOVANA);
|
||
da.put(MOVANA_DATACOMP, _dataini);
|
||
a.put(MOV_DATACOMP, _datafin);
|
||
TRelation rel(LF_MOVANA);
|
||
rel.add(LF_MOV, "NUMREG==NUMREGCG");
|
||
rel.add(LF_CAUSALI, "CODCAUS==CODCAUS");
|
||
rel.add(LF_RMOVANA, "NUMREG==NUMREG");
|
||
rel.add(LF_RMOVIVA, "NUMREG==NUMREGCG");
|
||
TCursor cur(&rel, "NUMREGCG!=0", 2, &da, &a);
|
||
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
{
|
||
//prepara i record di tipo testata da scrivere
|
||
TRecord_text rec;
|
||
rec.set_type("T");
|
||
|
||
cur.freeze();
|
||
const TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
//carica e scrive il record di testata in base alle informazioni contenute nel proforma.ini
|
||
trasfile->autoload(rec, cur);
|
||
trasfile->write(rec);
|
||
//trasferisce le righe del movimento analitico corrente solo
|
||
i_proforma_righe(cur, trasfilerighe);
|
||
}
|
||
}
|
||
chiudi_file(trasfilerighe);
|
||
chiudi_file(trasfile);
|
||
return true;
|
||
}
|
||
|
||
bool TInvioP::i_proforma_righe(TCursor& cur, TInvioP_file* trasfilerighe)
|
||
{
|
||
//---- righe movimenti analitica ----
|
||
//necessita del numreg del corrente movimento analitico per poterlo istanziare e prenderne le righe
|
||
const long numreg = cur.curr().get_long(MOVANA_NUMREG);
|
||
TAnal_mov analmov(numreg); //..istanzia il movimento analitico cercato..
|
||
|
||
TRecord_text recrighe; //istanzia il tipo record corretto da scrivere sul trasfilerighe
|
||
recrighe.set_type("R");
|
||
|
||
int i;
|
||
for (i = 1; i <= analmov.body().rows(); i++)
|
||
{
|
||
//..e scandisce le righe alla ricerca di quelle con conto = gruppo/conto/sottoconto del movimento contabile
|
||
const TRectype& riga = analmov.body().row(i);
|
||
//inganno il cursore passandogli la riga analitica in esame
|
||
cur.curr(LF_RMOVANA) = riga;
|
||
|
||
trasfilerighe->autoload(recrighe, cur);
|
||
trasfilerighe->write(recrighe);
|
||
}
|
||
|
||
//---- righe iva ----
|
||
//adesso tocca alle righe iva...e sara' un casino indicibile!
|
||
const TString8 numregcg = analmov.get(MOVANA_NUMREGCG);
|
||
//record_array con le righe iva aventi il numreg = numregcg analitico
|
||
TRecord_array righeiva(numregcg, LF_RMOVIVA);
|
||
//assoc array contenente tutti i diversi conti che incontrera' nello scanning delle righe iva
|
||
TAssoc_array conti;
|
||
|
||
//scanning delle righe iva alla ricerca dei conti che compaiono
|
||
for (int j = 1; j <= righeiva.rows(); j++)
|
||
{
|
||
//prende il conto e lo mette nell'assoc_array dei conti (notare che, essendo un assoc_array,..
|
||
//..non vengono inseriti doppioni! mitico!!)
|
||
TBill conto;
|
||
conto.get(righeiva[j]);
|
||
const char* codconto = conto.string(8);
|
||
|
||
//ad ogni conto lega un assoc_array (codivae) che conterra' tutti i codici iva legati a quel..
|
||
//..conto nelle righe iva con i relativi importi
|
||
TAssoc_array* codivae = (TAssoc_array*) conti.objptr(codconto);
|
||
if (codivae == NULL) //se non esiste l'assoc_array legato al conto lo crea
|
||
{
|
||
codivae = new TAssoc_array;
|
||
//aggiunge all'assoc_array conti il suo elemento assoc_array codivae..ho un assoc_array..
|
||
//..di assoc_array!
|
||
conti.add(codconto, codivae);
|
||
}
|
||
|
||
TString16 codiva = righeiva[j].get(RMI_CODIVA); //prende il codice iva dalla riga iva
|
||
//aggiungere qui eventuale codice intero di indetraibilita'
|
||
|
||
//ad ogni codiva presente in codivae lega un importo che risultera' la somma di tutti gli..
|
||
//..importi con lo stesso conto e codice iva
|
||
real* tot_imp = (real*) codivae->objptr(codiva);
|
||
if (tot_imp == NULL) //se non esiste l'importo legato al codice iva lo crea
|
||
{
|
||
tot_imp = new real;
|
||
//aggiunge all'assoc_array codivae il suo elemento real tot_imp
|
||
codivae->add(codiva, tot_imp);
|
||
}
|
||
|
||
//accresce l'importo tot_imp relativo alla coppia codiva+codconto corrente
|
||
*tot_imp += righeiva[j].get_real(RMI_IMPONIBILE);
|
||
//aggiungere qui eventuale imposta
|
||
}
|
||
|
||
TRecord_text recrigheiva; //istanzia il tipo record corretto da scrivere sul trasfilerighe
|
||
recrigheiva.set_type("I");
|
||
int nrighe = 0;
|
||
|
||
for (i = 1; i <= analmov.body().rows(); i++)
|
||
{
|
||
//scanning delle righe analitiche per estrarne i conti e controllare se compaiono nell'assoc_array..
|
||
//..dei conti riempito con i conti trovati nelle righe iva
|
||
const TRectype& riga = analmov.body().row(i);
|
||
const TString& codconto = riga.get(RMOVANA_CODCONTO);
|
||
TAssoc_array* codivae = (TAssoc_array*) conti.objptr(codconto); //assoc_array codivae del codconto
|
||
|
||
//se ha almeno un codice iva associato a questo conto nell'assoc_array dei conti..
|
||
if (codivae != NULL)
|
||
{
|
||
//..prende l'importo della riga analitica..
|
||
real importo_riga = riga.get_real(RMOVANA_IMPORTO);
|
||
//..lo ridistribuisce secondo le percentuali iva
|
||
TGeneric_distrib distributore(importo_riga, TCurrency::get_firm_dec());
|
||
{
|
||
FOR_EACH_ASSOC_OBJECT((*codivae), h, k, imp)
|
||
{
|
||
const real& imp_iva = *(real*)imp;
|
||
distributore.add(imp_iva);
|
||
}
|
||
|
||
//crea una riga iva dal cursore, con numreg = numregcg della testata analitica originale
|
||
TRectype& rigaiva = cur.curr(LF_RMOVIVA);
|
||
rigaiva.put(RMI_NUMREG, numregcg);
|
||
|
||
//scan dell'assoc_array ridistribuito e inserimento dei valori nella riga iva appena creata
|
||
FOR_EACH_ASSOC_OBJECT((*codivae), hi, ki, impi)
|
||
{
|
||
rigaiva.put(RMI_NUMRIG, ++nrighe);
|
||
rigaiva.put(RMI_GRUPPO, codconto.mid(0,3));
|
||
rigaiva.put(RMI_CONTO, codconto.mid(3,3));
|
||
rigaiva.put(RMI_SOTTOCONTO, codconto.mid(6,6));
|
||
TBill zio(rigaiva);
|
||
rigaiva.put(RMI_TIPOC, zio.tipo());
|
||
rigaiva.put(RMI_IMPONIBILE, distributore.get());
|
||
rigaiva.put(RMI_CODIVA, ki);
|
||
|
||
//scrittura delle righe di tipo I; notare che il cur passato alla autoload altri non e'..
|
||
//..che la rigaiva appena completata
|
||
trasfilerighe->autoload(recrigheiva, cur);
|
||
trasfilerighe->write(recrigheiva);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
// Calcola il totale del documento tenendo conto del segno della prima riga e di quella delle
|
||
// ritenute sociali sulla causale
|
||
real TInvioP::totale_documento(const TRectype& mov) const
|
||
{
|
||
real tot = mov.get_real(MOV_TOTDOC); // Legge totale
|
||
const real ritfis = mov.get_real(MOV_RITFIS);
|
||
tot += ritfis; // Somma ritenute fiscali
|
||
|
||
const real ritsoc = mov.get_real(MOV_RITSOC);
|
||
|
||
if (!ritsoc.is_zero())
|
||
{
|
||
TCausale caus(mov.get(MOV_CODCAUS));
|
||
const bool swapt = test_swap(caus, false); // Totale invertito ?
|
||
const bool swaps = test_swap(caus, true); // Ritenute sociali invertite ?
|
||
if (swapt ^ swaps) // Somma ritenute sociali con segno
|
||
tot -= ritsoc;
|
||
else
|
||
tot += ritsoc;
|
||
}
|
||
|
||
return tot;
|
||
}
|
||
|
||
// Controlla sulla causale se il segno del totale documento (ritsoc=FALSE)
|
||
// o quello delle ritenute sociali (ritsoc=TRUE) e' invertito rispetto al normale
|
||
bool TInvioP::test_swap(TCausale& caus, bool ritsoc) const
|
||
{
|
||
const char sez = ritsoc ? caus.sezione_ritsoc() : caus.sezione_clifo();
|
||
const bool s = (caus.iva() == iva_vendite) ^ (sez == 'D');
|
||
return s;
|
||
}
|
||
|
||
bool TInvioP::cerca_conto(const TBill& bill, const TAssoc_array& assoc, const char tipoconto) const
|
||
{
|
||
TToken_string key(15);
|
||
key.add(tipoconto); //il primo char della tokenstring e' il tipoconto (Fiscale o Sociale)
|
||
|
||
key.add(bill.gruppo());
|
||
if (assoc.is_key(key))
|
||
return true;
|
||
|
||
key.add(bill.conto());
|
||
if (assoc.is_key(key))
|
||
return true;
|
||
|
||
key.add(bill.sottoconto());
|
||
if (assoc.is_key(key))
|
||
return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
bool TInvioP::cerca_fiscali(const TBill& bill) const
|
||
{
|
||
return cerca_conto(bill, _fiscali, 'F');
|
||
}
|
||
|
||
bool TInvioP::cerca_sociali(const TBill& bill) const
|
||
{
|
||
return cerca_conto(bill, _sociali, 'S');
|
||
}
|
||
|
||
void TInvioP::lettura_conti(TAssoc_array& assoc, const char tipoconto)
|
||
{
|
||
TConfig conti("ca3600.ini","Pdcc"); //paragrafo da scandire nell'ini
|
||
TAssoc_array& vars = conti.list_variables();
|
||
|
||
FOR_EACH_ASSOC_STRING(vars, h, k, val) //riempie l'assoc con i soli valori del paragrafo dell'ini
|
||
{
|
||
if (*val == tipoconto) //mette nell'assocarray solo i conti corrispondenti al tipoconto passato
|
||
assoc.add(val);
|
||
}
|
||
}
|
||
|
||
real TInvioP::calcola_pagamento(TRectype& curpag_rec)
|
||
{
|
||
real totpagato = curpag_rec.get_real(PAGSCA_IMPORTO) + curpag_rec.get_real(PAGSCA_RITENUTE);
|
||
|
||
//deve costruirsi la riga di partita che riguarda il documento di origine
|
||
//per prima cosa crea tale riga a partire dal pagamento, che ha una chiave lunghissima...
|
||
TToken_string key_part;
|
||
key_part.add(curpag_rec.get(PAGSCA_TIPOC));
|
||
key_part.add(curpag_rec.get(PAGSCA_GRUPPO));
|
||
key_part.add(curpag_rec.get(PAGSCA_CONTO));
|
||
key_part.add(curpag_rec.get(PAGSCA_SOTTOCONTO));
|
||
key_part.add(curpag_rec.get(PAGSCA_ANNO));
|
||
key_part.add(curpag_rec.get(PAGSCA_NUMPART));
|
||
key_part.add(curpag_rec.get(PAGSCA_NRIGA));
|
||
//..ecco il record delle partite..
|
||
const TRectype& rec_partite = cache().get(LF_PARTITE, key_part);
|
||
//..da cui prende nreg
|
||
const long nreg = rec_partite.get_long(PART_NREG);
|
||
//se nreg esiste...
|
||
if (nreg != 0)
|
||
{
|
||
TMovimentoPN pn;
|
||
pn.curr().put(MOV_NUMREG, nreg);
|
||
if (pn.read() == NOERR)
|
||
{
|
||
const TRectype& movfat = pn.curr();
|
||
|
||
//dichiariamo una serie di simpatici real utilizzati in seguito
|
||
real totdoc,imponibile,imposta;
|
||
|
||
//Le ritenute sociali invece vanno testate con la test_swap..
|
||
const real ritsoc = curpag_rec.get_real(PAGSCA_RITSOC);
|
||
|
||
if (!ritsoc.is_zero())
|
||
{
|
||
const TRectype& mov = pn.curr();
|
||
TCausale caus(mov.get(MOV_CODCAUS));
|
||
const bool swapt = test_swap(caus, false); // Totale invertito ?
|
||
const bool swaps = test_swap(caus, true); // Ritenute sociali invertite ?
|
||
if (swapt ^ swaps) // Somma ritenute sociali con segno
|
||
totpagato -= ritsoc;
|
||
else
|
||
totpagato += ritsoc;
|
||
}
|
||
//Movimenti CON SALDACONTO
|
||
//se movimento IVA..
|
||
if (pn.iva_items() > 0)
|
||
{
|
||
for (int i = 0; i < pn.iva_items(); i++)
|
||
{
|
||
const TRectype& rmoviva = pn.iva(i);
|
||
const TBill conto(rmoviva);
|
||
|
||
if (conto.indicatore_bilancio() != 5)
|
||
{
|
||
const real importo = rmoviva.get_real(RMI_IMPONIBILE);
|
||
real iva = rmoviva.get_real(RMI_IMPOSTA);
|
||
|
||
imponibile += importo;
|
||
imposta += iva;
|
||
}
|
||
}
|
||
totdoc = totale_documento(pn.curr()); //tot doc con ritenute fiscali + ritenute sociali (da stampare)
|
||
} //if pn.iva_items()..
|
||
else
|
||
{
|
||
for (int i = 0; i < pn.cg_items(); i++)
|
||
{
|
||
const TRectype& rmov = pn.cg(i);
|
||
const TBill conto(rmov);
|
||
|
||
TImporto importo(rmov.get_char(RMV_SEZIONE), rmov.get_real(RMV_IMPORTO));
|
||
importo.normalize('D');
|
||
|
||
if (conto.tipo() > ' ')
|
||
totdoc -= importo.valore();
|
||
else
|
||
if (cerca_fiscali(conto) || cerca_sociali(conto))
|
||
totdoc -= importo.valore(); //valore da stampare nella colonna Tot.fattura con ritenute
|
||
else
|
||
if (rmov.get_char(RMV_ROWTYPE) != 'T' && conto.indicatore_bilancio() != 5)
|
||
{
|
||
imponibile += importo.valore();
|
||
totdoc += importo.valore();
|
||
}
|
||
}
|
||
} //end di else pn.iva_items()...
|
||
|
||
real percentuale = imponibile / totdoc;
|
||
totpagato *= percentuale;
|
||
}
|
||
}
|
||
return totpagato;
|
||
}
|
||
|
||
bool TInvioP::i_proforma_pagamenti()
|
||
{
|
||
TInvioP_file* trasfilepag = apri_file("pagament");
|
||
|
||
TRectype da(LF_MOV);
|
||
TRectype a(LF_MOV);
|
||
da.put(MOV_DATACOMP, _dataini);
|
||
a.put(MOV_DATACOMP, _datafin);
|
||
TRelation rel(LF_MOV);
|
||
rel.add(LF_CAUSALI, "CODCAUS==CODCAUS");
|
||
TCursor cur(&rel, "", 2, &da, &a);
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
{
|
||
//se ha almeno un movimento carica lo sheet dei conti che gli servira' in seguito nel calcolo..
|
||
//..delle ritenute
|
||
lettura_conti(_fiscali, 'F');
|
||
lettura_conti(_sociali, 'S');
|
||
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
const char tipomov = cur_rec.get(MOV_TIPOMOV)[0];
|
||
if (tipomov == '3' || tipomov == '2' || tipomov == '6')
|
||
{
|
||
TRelation relpart(LF_PARTITE);
|
||
TRectype da(LF_PARTITE);
|
||
da.put(PART_NREG, cur.curr().get(MOV_NUMREG));
|
||
TCursor curpart(&relpart, "", 2, &da, &da);
|
||
const long curpart_items = curpart.items();
|
||
if (curpart_items != 0)
|
||
{
|
||
curpart.freeze();
|
||
TRectype& curpart_rec = curpart.curr();
|
||
for (curpart = 0; curpart.pos() < curpart_items; ++(curpart))
|
||
{
|
||
TRelation relpag(LF_PAGSCA);
|
||
TRectype da(LF_PAGSCA);
|
||
da.put(PAGSCA_TIPOC, curpart_rec.get(PART_TIPOCF));
|
||
da.put(PAGSCA_GRUPPO, curpart_rec.get(PART_GRUPPO));
|
||
da.put(PAGSCA_CONTO, curpart_rec.get(PART_CONTO));
|
||
da.put(PAGSCA_SOTTOCONTO, curpart_rec.get(PART_SOTTOCONTO));
|
||
da.put(PAGSCA_ANNO, curpart_rec.get(PART_ANNO));
|
||
da.put(PAGSCA_NUMPART, curpart_rec.get(PART_NUMPART));
|
||
const int nrigapart = curpart_rec.get_int(PART_NRIGA);
|
||
TString80 filtro;
|
||
filtro.format("NRIGP == %d", nrigapart);
|
||
TCursor curpag(&relpag, filtro, 1, &da, &da);
|
||
const long curpag_items = curpag.items();
|
||
if (curpag_items != 0)
|
||
{
|
||
TAssoc_array pagame;
|
||
pagame.destroy();
|
||
curpag.freeze();
|
||
TRectype& curpag_rec = curpag.curr();
|
||
for (curpag = 0; curpag.pos() < curpag_items; ++(curpag))
|
||
{
|
||
TString80 indice = curpag_rec.get(PAGSCA_ANNO);
|
||
indice << '|' << curpag_rec.get(PAGSCA_NUMPART);
|
||
indice << '|' << curpag_rec.get(PAGSCA_NRIGA);
|
||
real importo = ZERO;
|
||
bool is_key = pagame.is_key(indice);
|
||
real& somma = is_key ? (real&) pagame[indice] : importo;
|
||
const real importo_pagato = calcola_pagamento(curpag_rec); //aggiunta nuova!!!
|
||
somma += importo_pagato;
|
||
if (!is_key)
|
||
pagame.add(indice, somma);
|
||
}
|
||
|
||
// scrivo i record risultanti
|
||
real* cp;
|
||
for (cp = (real*) pagame.first_item(); cp != NULL; cp = (real*) pagame.succ_item())
|
||
{
|
||
TToken_string keypart;
|
||
keypart.add(curpart_rec.get(PART_TIPOCF));
|
||
keypart.add(curpart_rec.get(PART_GRUPPO));
|
||
keypart.add(curpart_rec.get(PART_CONTO));
|
||
keypart.add(curpart_rec.get(PART_SOTTOCONTO));
|
||
keypart.add(pagame.get_hashobj()->key());
|
||
const TRectype& partita = cache().get(LF_PARTITE, keypart);
|
||
_nregpag = cur.curr().get_long(MOV_NUMREG);
|
||
_nregcosto = partita.get_long(PART_NREG);
|
||
_importo = *cp;
|
||
TRecord_text recpag;
|
||
recpag.set_type("G");
|
||
trasfilepag->autoload(recpag, curpag);
|
||
trasfilepag->write(recpag);
|
||
}
|
||
|
||
}//if curpag_items..
|
||
}//for curpart =..
|
||
}//if curpart_items..
|
||
}//if tipomov..
|
||
}//for cur =..
|
||
}//if cur_items..
|
||
|
||
chiudi_file(trasfilepag);
|
||
return true;
|
||
}
|
||
|
||
bool TInvioP::i_proforma_clifor(char tipocf)
|
||
{
|
||
TInvioP_file* trasfile = NULL;
|
||
if (tipocf == 'C')
|
||
trasfile = apri_file("clienti");
|
||
else
|
||
trasfile = apri_file("fornit");
|
||
|
||
TString80 filtro = "";
|
||
filtro.format("TIPOCF == \"%c\"", tipocf);
|
||
TRelation rel(LF_CLIFO);
|
||
rel.add(LF_COMUNI, "STATO==STATOCF|COM==COMCF", 1);
|
||
TCursor cur(&rel, filtro);
|
||
const long cur_items = cur.items();
|
||
if (cur_items != 0)
|
||
{
|
||
cur.freeze();
|
||
TRectype& cur_rec = cur.curr();
|
||
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
||
{
|
||
TRecord_text rec;
|
||
rec.set_type("C");
|
||
trasfile->autoload(rec, cur);
|
||
trasfile->write(rec);
|
||
}
|
||
}
|
||
chiudi_file(trasfile);
|
||
return true;
|
||
}
|
||
|
||
//"metodo dei metodi":in base ai parametri della maschera esegue la procedura indicata
|
||
void TInvioP::invio_proforma()
|
||
{
|
||
if (_msk->get_bool(F_MOVIMENTI))
|
||
i_proforma_movimenti();
|
||
if (_msk->get_bool(F_PAGAMENTI))
|
||
i_proforma_pagamenti();
|
||
if (_msk->get_bool(F_CLIENTI))
|
||
i_proforma_clifor();
|
||
if (_msk->get_bool(F_FORNITORI))
|
||
i_proforma_clifor('F');
|
||
if (_msk->get_bool(F_CONTI))
|
||
i_proforma_conti();
|
||
}
|
||
|
||
bool TInvioP::create()
|
||
{
|
||
_msk = new TInvioP_mask();
|
||
_configfile = new TConfig("proforma.ini");
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
bool TInvioP::destroy()
|
||
{
|
||
if (_configfile != NULL)
|
||
delete _configfile;
|
||
delete _msk;
|
||
|
||
return TSkeleton_application::destroy();
|
||
}
|
||
|
||
void TInvioP::main_loop()
|
||
{
|
||
//il programma si puo' usare SOLO se in contabilita' analitica si usa il piano dei conti contabile
|
||
TConfig& cfg = ca_config();
|
||
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
||
if (!use_pdcc)
|
||
{
|
||
error_box(TR("Programma funzionante SOLO se in contabilita' analitica si usa il piano dei conti contabile"));
|
||
return;
|
||
}
|
||
|
||
TFilename configname = "cg7200a.ini"; //file configurazione della maschera
|
||
configname.custom_path();
|
||
TConfig configfile(configname);
|
||
_msk->set(F_DATAINI, configfile.get("DATA","OPZIONI"));
|
||
_msk->set(F_DESTINAZIONE, configfile.get("PERCORSO","OPZIONI"));
|
||
|
||
while (_msk->run()!=K_QUIT)
|
||
{
|
||
configfile.set("DATA", _msk->get_date(F_DATAFIN),"OPZIONI");
|
||
configfile.set("PERCORSO", _msk->get(F_DESTINAZIONE),"OPZIONI");
|
||
_dataini = _msk->get_date(F_DATAINI);
|
||
_datafin = _msk->get_date(F_DATAFIN);
|
||
const char tipoinvio = _msk->get(F_TIPOINVIO)[0];
|
||
if (tipoinvio == 'P')
|
||
invio_proforma(); //dopo aver preso i parametri dalla maschera chiama il "metodo dei metodi"
|
||
}
|
||
}
|
||
|
||
int cg7200(int argc, char **argv)
|
||
{
|
||
TInvioP a;
|
||
a.run(argc, argv, "Invio dati contabilit<69> a Proforma");
|
||
return 0;
|
||
}
|