2005-02-17 18:13:12 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <assoc.h>
|
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <currency.h>
|
2005-11-29 14:03:44 +00:00
|
|
|
|
#include <defmask.h>
|
2005-02-17 18:13:12 +00:00
|
|
|
|
#include <filetext.h>
|
|
|
|
|
#include <msksheet.h>
|
|
|
|
|
#include <printer.h>
|
2005-12-20 12:44:06 +00:00
|
|
|
|
#include <progind.h>
|
2005-02-17 18:13:12 +00:00
|
|
|
|
#include <recarray.h>
|
2006-06-21 10:02:45 +00:00
|
|
|
|
#include <recset.h>
|
2005-02-17 18:13:12 +00:00
|
|
|
|
#include <relation.h>
|
|
|
|
|
#include <sort.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include "cg7.h"
|
|
|
|
|
#include "cg7200a.h"
|
2005-11-03 18:38:07 +00:00
|
|
|
|
#include "cglib01.h"
|
2005-11-29 14:03:44 +00:00
|
|
|
|
#include "cg2101.h"
|
|
|
|
|
#include "cg2103.h"
|
|
|
|
|
#include "cgsaldac.h"
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
|
|
|
|
#include <mov.h>
|
|
|
|
|
#include <rmov.h>
|
|
|
|
|
#include <rmoviva.h>
|
2005-05-16 23:44:23 +00:00
|
|
|
|
#include <pagsca.h>
|
|
|
|
|
#include <partite.h>
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
#include "../ca/calib01.h"
|
|
|
|
|
#include "../ca/movana.h"
|
|
|
|
|
#include "../ca/rmovana.h"
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
class TInvioP_file: public TFile_text
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
|
|
|
|
|
|
|
|
|
|
public:
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file(const TString& file_name);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
virtual ~TInvioP_file() { }
|
|
|
|
|
};
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file::TInvioP_file(const TString& file_name)
|
|
|
|
|
: TFile_text(file_name, "proforma.ini")
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
// MASCHERA
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
class TInvioP_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2005-11-29 14:03:44 +00:00
|
|
|
|
void config_loader(TSheet_field& sf, const char* paragrafo);
|
|
|
|
|
void config_setter(TSheet_field& sf, const char* paragrafo);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
public:
|
|
|
|
|
TInvioP_mask();
|
2005-02-17 18:13:12 +00:00
|
|
|
|
virtual ~TInvioP_mask(){};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TInvioP_mask::TInvioP_mask() :TAutomask ("cg7200a")
|
|
|
|
|
{
|
2005-11-29 14:03:44 +00:00
|
|
|
|
config_loader(sfield(F_PDCC), "Pdcc");
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2005-11-29 14:03:44 +00:00
|
|
|
|
case DLG_SAVEREC:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
config_setter(sfield(F_PDCC), "Pdcc");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-11-29 14:03:44 +00:00
|
|
|
|
return true;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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
|
2006-06-12 17:50:50 +00:00
|
|
|
|
TFilename configname = "ca3600a.ini";
|
2005-11-29 14:03:44 +00:00
|
|
|
|
configname.custom_path();
|
|
|
|
|
TConfig configfile(configname, paragrafo);
|
|
|
|
|
|
|
|
|
|
TString_array conti;
|
|
|
|
|
|
2005-11-30 16:16:01 +00:00
|
|
|
|
int first_enabled_row = -1;
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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);
|
2005-11-30 16:16:01 +00:00
|
|
|
|
TString pippo = sf.row(i);
|
|
|
|
|
pippo = pippo.left(1); //disabilita le righe di tipo C e P che riguardano la sola stampa..
|
2006-06-21 10:14:45 +00:00
|
|
|
|
/* if (pippo == "C" || pippo == "P") //..del pagato
|
2005-11-30 16:16:01 +00:00
|
|
|
|
sf.disable_row(i);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (first_enabled_row < 0) //se la riga non e' C o P deve incrementare il contatore della..
|
|
|
|
|
first_enabled_row = i; //..prima riga disabilitata
|
2006-06-21 10:14:45 +00:00
|
|
|
|
}*/
|
2005-11-29 14:03:44 +00:00
|
|
|
|
}
|
2005-11-30 16:16:01 +00:00
|
|
|
|
if (first_enabled_row >= 0) //se il contatore della prima riga disabilitata e' stato..
|
|
|
|
|
sf.select(first_enabled_row); //..incrementato, sposta il focus alla prima riga abile
|
2005-11-29 14:03:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TInvioP_mask::config_setter(TSheet_field& sf, const char* paragrafo)
|
|
|
|
|
{
|
2006-06-12 17:50:50 +00:00
|
|
|
|
TFilename configname = "ca3600a.ini";
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-15 18:22:01 +00:00
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
// STRUCT (saldo di 1 conto)
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
struct TInvioP_saldo : public TObject
|
|
|
|
|
{
|
|
|
|
|
TString16 _zio;
|
|
|
|
|
TImporto _importo;
|
|
|
|
|
|
|
|
|
|
TInvioP_saldo(const TRectype& r);
|
|
|
|
|
TInvioP_saldo(const TString& zio, const TImporto& importo);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TInvioP_saldo::TInvioP_saldo(const TRectype& r)
|
|
|
|
|
{
|
|
|
|
|
const TBill zio(r);
|
|
|
|
|
_zio = zio.string(0x8);
|
|
|
|
|
|
|
|
|
|
const char sezione = r.get_char(RMV_SEZIONE);
|
|
|
|
|
const real imp = r.get_real(RMV_IMPORTO);
|
|
|
|
|
_importo.set(sezione, imp);
|
|
|
|
|
_importo.normalize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TInvioP_saldo::TInvioP_saldo(const TString& zio, const TImporto& importo)
|
|
|
|
|
: _zio(zio), _importo(importo)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
// SALDI MOVIMENTO CONTABILE
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
class TInvioP_saldi_cg : public TArray
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
//prende l'oggetto i-esimo (in questo caso un TInvioP_saldo) e ritorna il conto di tale oggetto
|
|
|
|
|
const TString& conto(int i) { return ((TInvioP_saldo*)objptr(i))->_zio; }
|
|
|
|
|
//stessa roba ma per l'importo
|
|
|
|
|
TImporto& importo(int i) { return ((TInvioP_saldo*)objptr(i))->_importo; }
|
|
|
|
|
bool sottrai_importo(const TString& conto, const TImporto& importo);
|
|
|
|
|
void somma(const TRectype& rmov);
|
|
|
|
|
void sottrai(const TRectype& rmovana);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TInvioP_saldi_cg::somma(const TRectype& rmov)
|
|
|
|
|
{
|
|
|
|
|
TInvioP_saldo* s = new TInvioP_saldo(rmov);
|
|
|
|
|
add(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TInvioP_saldi_cg::sottrai_importo(const TString& zio, const TImporto& imp)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
//caso fortunato
|
|
|
|
|
//scandisce gli elementi dell'array;se ne trova uno (k-esimo) con conto ed importo coincidenti..
|
|
|
|
|
//..con quelli passati al metodo, azzera l'importo di tale elemento dell'array
|
|
|
|
|
for (k = 0; k < items(); k++)
|
|
|
|
|
{
|
|
|
|
|
if (conto(k) == zio && importo(k) == imp)
|
|
|
|
|
{
|
|
|
|
|
importo(k).set('D', ZERO);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//caso sfortunato
|
|
|
|
|
//in questo caso gli importi dell'elemento k-esimo dell'array e passato al metodo NON coincidono
|
|
|
|
|
TImporto residuo = imp;
|
|
|
|
|
int ultima_riga_buona = -1;
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < items() && !residuo.is_zero(); k++)
|
|
|
|
|
{
|
|
|
|
|
if (conto(k) == zio)
|
|
|
|
|
{
|
|
|
|
|
TImporto& val = importo(k);
|
|
|
|
|
residuo.normalize(val.sezione());
|
|
|
|
|
if (residuo >= val)
|
|
|
|
|
{
|
|
|
|
|
residuo -= val;
|
|
|
|
|
val.set('D', ZERO);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
val -= residuo;
|
|
|
|
|
residuo.set('D', ZERO);
|
|
|
|
|
}
|
|
|
|
|
ultima_riga_buona = k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//alla fine del ciclo sull'array resta un residuo non nullo..
|
|
|
|
|
if (!residuo.is_zero())
|
|
|
|
|
{
|
|
|
|
|
residuo.normalize();
|
|
|
|
|
residuo.swap_section();
|
|
|
|
|
if (ultima_riga_buona >= 0)
|
|
|
|
|
importo(ultima_riga_buona) += residuo;
|
|
|
|
|
// else
|
|
|
|
|
// add(new TInvioP_saldo(zio, residuo));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TInvioP_saldi_cg::sottrai(const TRectype& rmovana)
|
|
|
|
|
{
|
|
|
|
|
//adesso tocca alle righe contabili senza commessa
|
|
|
|
|
const int gruppo = atoi(rmovana.get(RMOVANA_CODCONTO).left(3));
|
|
|
|
|
const int conto = atoi(rmovana.get(RMOVANA_CODCONTO).mid(3,3));
|
|
|
|
|
const long sottoconto = atol(rmovana.get(RMOVANA_CODCONTO).mid(6,6));
|
|
|
|
|
|
|
|
|
|
const TBill zio(gruppo, conto, sottoconto);
|
|
|
|
|
|
|
|
|
|
const TImporto importo(rmovana.get_char(RMOVANA_SEZIONE), rmovana.get_real(RMOVANA_IMPORTO));
|
|
|
|
|
sottrai_importo(zio.string(0x8), importo);
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
// APPLICAZIONE
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
class TInvioP : public TSkeleton_application
|
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TCursor* _cur;
|
|
|
|
|
TInvioP_mask* _msk;
|
|
|
|
|
TDate _dataini, _datafin;
|
|
|
|
|
long _nregcosto, _nregpag;
|
2006-06-15 11:56:35 +00:00
|
|
|
|
bool _chiusa;
|
2005-11-03 18:38:07 +00:00
|
|
|
|
real _importo;
|
|
|
|
|
TConfig* _configfile;
|
2006-06-21 10:02:45 +00:00
|
|
|
|
TAssoc_array _fiscali,_sociali, _costi, _pagamenti; //array che contengono i conti
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual bool create(void);
|
|
|
|
|
virtual bool destroy(void);
|
|
|
|
|
virtual void main_loop() ;
|
|
|
|
|
void invio_proforma();
|
2005-11-03 18:38:07 +00:00
|
|
|
|
bool i_proforma_movimenti();
|
|
|
|
|
bool i_proforma_righe(TCursor& cur, TInvioP_file* trasfile);
|
|
|
|
|
bool i_proforma_pagamenti();
|
2005-02-17 18:13:12 +00:00
|
|
|
|
bool i_proforma_clifor(char tipocf = 'C');
|
|
|
|
|
bool i_proforma_conti();
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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;
|
2006-06-21 10:02:45 +00:00
|
|
|
|
int cerca_pagamento(const TBill& bill) const;
|
|
|
|
|
int cerca_costo(const TBill& bill) const;
|
2005-11-29 14:03:44 +00:00
|
|
|
|
bool test_swap(TCausale& caus, bool ritsoc) const;
|
|
|
|
|
real calcola_pagamento(TRectype& curpag_rec);
|
2005-12-20 12:44:06 +00:00
|
|
|
|
bool sottrai_iva(TMovimentoPN& pn, const TRectype& rigaiva);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
void stringa_grcosot(TRecord_text& recrighe, const TString& zio);
|
2005-11-29 14:03:44 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
public:
|
2005-05-16 23:44:23 +00:00
|
|
|
|
const real get_importo() {return _importo;};
|
2006-06-15 11:56:35 +00:00
|
|
|
|
const long get_nregcosto() const {return _nregcosto;};
|
|
|
|
|
const long get_nregpag() const {return _nregpag;};
|
|
|
|
|
const bool get_chiusa() const {return _chiusa;};
|
2005-12-22 13:49:09 +00:00
|
|
|
|
const TString& get_vocespesa(const TString& zio) const;
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* apri_file(const char* nome);
|
|
|
|
|
void chiudi_file(TInvioP_file* trasfile);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2005-03-03 15:42:04 +00:00
|
|
|
|
else if (code == "_TELEFONO")
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
|
|
|
|
valore = str;
|
2005-03-03 15:42:04 +00:00
|
|
|
|
valore.trim();
|
|
|
|
|
str = cur.curr().get("PTEL");
|
|
|
|
|
valore << str;
|
|
|
|
|
valore.trim();
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
2005-05-16 23:44:23 +00:00
|
|
|
|
else if (code == "_RAGSOC")
|
|
|
|
|
{
|
|
|
|
|
valore = str;
|
2005-10-05 17:03:14 +00:00
|
|
|
|
valore = valore.strip_double_spaces();
|
2005-05-16 23:44:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if (code == "_FLAG")
|
|
|
|
|
{
|
2006-06-15 11:56:35 +00:00
|
|
|
|
const bool chiusa = app().get_chiusa();
|
|
|
|
|
if (chiusa)
|
|
|
|
|
valore = "S";
|
|
|
|
|
else
|
|
|
|
|
valore = "A";
|
2005-05-16 23:44:23 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (code == "_NREGCOSTO")
|
|
|
|
|
{
|
2006-06-15 11:56:35 +00:00
|
|
|
|
valore.format("%ld", app().get_nregcosto());
|
2005-05-16 23:44:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if (code == "_NREGPAG")
|
|
|
|
|
{
|
2006-06-15 11:56:35 +00:00
|
|
|
|
valore.format("%ld", app().get_nregpag());
|
2005-05-16 23:44:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if (code == "_IMPORTO")
|
|
|
|
|
{
|
|
|
|
|
valore = app().get_importo().string();
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
else NFCHECK("Macro non definita: %s", (const char *)code);
|
|
|
|
|
str = valore;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* TInvioP::apri_file(const char* nome)
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TFilename filename = _msk->get(F_DESTINAZIONE);
|
|
|
|
|
filename.add(nome);
|
|
|
|
|
filename.ext("txt");
|
|
|
|
|
if (filename.exist())
|
|
|
|
|
remove(filename);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* trasfile = new TInvioP_file(filename);
|
|
|
|
|
trasfile->open(filename,'w');
|
|
|
|
|
trasfile->force_record_separator();
|
|
|
|
|
return trasfile;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
void TInvioP::chiudi_file(TInvioP_file* trasfile)
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
trasfile->close();
|
|
|
|
|
delete trasfile;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-12-22 13:49:09 +00:00
|
|
|
|
const TString& TInvioP::get_vocespesa(const TString& zio) const
|
2005-11-18 10:40:20 +00:00
|
|
|
|
{
|
2005-12-22 13:49:09 +00:00
|
|
|
|
TConfig configfile("cg7200a.ini", "OPZIONI");
|
|
|
|
|
const TString16 confstringa = configfile.get("CONFSTRINGA");
|
2005-11-18 10:40:20 +00:00
|
|
|
|
const int len = confstringa.len();
|
2005-12-22 13:49:09 +00:00
|
|
|
|
|
2005-11-18 10:40:20 +00:00
|
|
|
|
TLocalisamfile panapdc(LF_PANAPDC);
|
|
|
|
|
panapdc.zero();
|
|
|
|
|
panapdc.setkey(2);
|
2005-12-22 13:49:09 +00:00
|
|
|
|
panapdc.put("GRUPPO", atoi(zio.mid(0,3)));
|
|
|
|
|
panapdc.put("CONTO", atoi(zio.mid(3,3)));
|
|
|
|
|
panapdc.put("SOTTOCONTO", atol(zio.mid(6,6)));
|
|
|
|
|
const TRectype r(panapdc.curr());
|
|
|
|
|
|
2005-11-18 10:40:20 +00:00
|
|
|
|
for (panapdc.read(); !panapdc.eof(); panapdc.next())
|
|
|
|
|
{
|
2005-12-22 13:49:09 +00:00
|
|
|
|
if (panapdc.curr() != r)
|
|
|
|
|
break;
|
2005-11-18 10:40:20 +00:00
|
|
|
|
const TString& codconto = panapdc.get("CODCONTO");
|
2005-12-22 13:49:09 +00:00
|
|
|
|
if (codconto.starts_with(confstringa))
|
|
|
|
|
return codconto.mid(len);
|
2005-11-18 10:40:20 +00:00
|
|
|
|
}
|
2005-12-22 13:49:09 +00:00
|
|
|
|
return EMPTY_STRING;
|
2005-11-18 10:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
bool TInvioP::i_proforma_conti()
|
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* trasfile = apri_file("pianocon");
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TRelation rel(LF_PCON);
|
|
|
|
|
TCursor cur(&rel);
|
|
|
|
|
const long cur_items = cur.items();
|
|
|
|
|
if (cur_items != 0)
|
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TProgind pi(cur_items, "Trasferimento conti...", true, true);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
cur.freeze();
|
|
|
|
|
TRectype& cur_rec = cur.curr();
|
|
|
|
|
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
if (pi.iscancelled())
|
|
|
|
|
break;
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TRecord_text rec;
|
|
|
|
|
rec.set_type("P");
|
2005-11-03 18:38:07 +00:00
|
|
|
|
trasfile->autoload(rec, cur);
|
|
|
|
|
trasfile->write(rec);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
chiudi_file(trasfile);
|
|
|
|
|
return true;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
bool TInvioP::i_proforma_movimenti()
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
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
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TRectype da(LF_MOV);
|
|
|
|
|
TRectype a(LF_MOV);
|
|
|
|
|
da.put(MOV_DATAREG, _dataini);
|
|
|
|
|
a.put(MOV_DATAREG, _datafin);
|
|
|
|
|
TRelation rel(LF_MOV);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
rel.add(LF_CAUSALI, "CODCAUS==CODCAUS");
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
|
|
|
|
TCursor cur(&rel, "", 2, &da, &a); //chiave per data
|
2005-02-17 18:13:12 +00:00
|
|
|
|
|
|
|
|
|
const long cur_items = cur.items();
|
|
|
|
|
if (cur_items != 0)
|
2005-11-03 18:38:07 +00:00
|
|
|
|
{
|
|
|
|
|
//prepara i record di tipo testata da scrivere
|
|
|
|
|
TRecord_text rec;
|
|
|
|
|
rec.set_type("T");
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TProgind pi(cur_items, "Trasferimento movimenti...", true, true);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
cur.freeze();
|
2005-11-03 18:38:07 +00:00
|
|
|
|
const TRectype& cur_rec = cur.curr();
|
2005-02-17 18:13:12 +00:00
|
|
|
|
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
2005-11-03 18:38:07 +00:00
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
if (pi.iscancelled())
|
|
|
|
|
break;
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
//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);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
chiudi_file(trasfilerighe);
|
|
|
|
|
chiudi_file(trasfile);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TInvioP::i_proforma_righe(TCursor& cur, TInvioP_file* trasfilerighe)
|
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
//---- righe movimenti ----
|
2005-12-15 18:22:01 +00:00
|
|
|
|
TInvioP_saldi_cg conti_importi;
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
//Creo un movimento PN (con numreg = a quello del mov)che servira' un po' dovunque
|
2005-12-15 18:22:01 +00:00
|
|
|
|
TMovimentoPN pn;
|
2005-12-20 12:44:06 +00:00
|
|
|
|
pn.curr() = cur.curr();
|
2005-12-15 18:22:01 +00:00
|
|
|
|
if (pn.read() == NOERR)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < pn.cg_items(); j++)
|
|
|
|
|
conti_importi.somma(pn.cg(j));
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TRecord_text recrighe; //istanzia il tipo record corretto da scrivere sul trasfilerighe
|
|
|
|
|
recrighe.set_type("R");
|
|
|
|
|
|
|
|
|
|
TAnal_mov analmov(cur.curr()); //..istanzia il movimento analitico con numregcg=numreg del mov
|
|
|
|
|
const long analrighe_items = analmov.body().rows();
|
|
|
|
|
|
|
|
|
|
if (analrighe_items > 0) //se il movana ha righe..
|
2005-05-16 23:44:23 +00:00
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TRelation rel_rmovana(LF_RMOVANA); //crea una relazione sulle righe anali cui aggiunge mov e movana
|
|
|
|
|
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG");
|
|
|
|
|
rel_rmovana.add(LF_MOV, "NUMREG==NUMREGCG", 1, LF_MOVANA);
|
|
|
|
|
TCursor cur_rmovana(&rel_rmovana); //crea il cursore sulle righe analitiche che serve per poter usare la autoload
|
|
|
|
|
cur_rmovana.curr(LF_MOVANA) = analmov;
|
|
|
|
|
cur_rmovana.curr(LF_MOV) = cur.curr();
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= analrighe_items; i++)
|
|
|
|
|
{
|
|
|
|
|
//..e scandisce le righe
|
|
|
|
|
const TRectype& riga = analmov.body().row(i);
|
|
|
|
|
//inganna il cursore passandogli la riga analitica in esame (bastardo!)
|
|
|
|
|
cur_rmovana.curr() = riga;
|
|
|
|
|
//carica le righe analitiche
|
|
|
|
|
trasfilerighe->autoload(recrighe, cur_rmovana);
|
2006-06-12 17:50:50 +00:00
|
|
|
|
//toglie le righe contabili corrispondenti che sono appena state aggiunte con la autoload (sarebbero..
|
2005-12-20 12:44:06 +00:00
|
|
|
|
//..duplicate se non lo facesse!!!)
|
|
|
|
|
conti_importi.sottrai(riga);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
|
|
|
|
|
//procedura orrenda per eliminare gli zeri dai gr/co/sot e passarli come stringhe!
|
2005-12-22 13:49:09 +00:00
|
|
|
|
const TString16 zio = cur_rmovana.curr().get(RMOVANA_CODCONTO);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
stringa_grcosot(recrighe, zio);
|
|
|
|
|
|
2005-12-22 13:49:09 +00:00
|
|
|
|
//procedura per ricavare la voce di spesa
|
|
|
|
|
const TString& vocespesa = get_vocespesa(zio);
|
|
|
|
|
recrighe.add(vocespesa, 14);
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
//scrive sul file di trasferimento (alla faccia della semplicita'!)
|
|
|
|
|
trasfilerighe->write(recrighe);
|
|
|
|
|
}
|
2005-05-16 23:44:23 +00:00
|
|
|
|
}
|
2005-12-15 18:22:01 +00:00
|
|
|
|
//prende le righe contabili che non sono state eliminate dalle analitiche nelle sottrai(riga)..
|
|
|
|
|
//..in modo da passare anche quelle (in caso contrario sarebbero andati perduti gli importi di..
|
|
|
|
|
//..tali righe che non avevano commessa!)
|
2005-12-20 12:44:06 +00:00
|
|
|
|
const long conti_importi_items = conti_importi.items();
|
2005-12-15 18:22:01 +00:00
|
|
|
|
TString workstring; //stringa di lavoro che serve nel ciclo sotto
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < conti_importi_items; i++)
|
2005-12-15 18:22:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!conti_importi.importo(i).is_zero())
|
|
|
|
|
{
|
|
|
|
|
//aggiunge i valori ai campi uno ad uno perch<63> non ha un cursore per fare l'autoload
|
|
|
|
|
recrighe.destroy();
|
2005-12-20 12:44:06 +00:00
|
|
|
|
recrighe.add(pn.curr().get(MOV_NUMREG), 0); //numreg
|
2005-12-15 18:22:01 +00:00
|
|
|
|
workstring = "N";
|
|
|
|
|
recrighe.add(workstring, 1); //rigaiva
|
|
|
|
|
TImporto& imp = conti_importi.importo(i);
|
2005-12-20 12:44:06 +00:00
|
|
|
|
workstring.cut(0) << imp.sezione();
|
2005-12-21 17:01:37 +00:00
|
|
|
|
recrighe.add(workstring, 2); //sezione
|
|
|
|
|
//procedura orrenda per eliminare gli zeri dai gr/co/sot e passarli come stringhe!
|
2005-12-15 18:22:01 +00:00
|
|
|
|
const TString& zio = conti_importi.conto(i);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
stringa_grcosot(recrighe, zio);
|
|
|
|
|
|
|
|
|
|
const TString tipocf = pn.curr().get(MOV_TIPO);
|
|
|
|
|
recrighe.add(tipocf, 6); //tipocf
|
|
|
|
|
|
|
|
|
|
//procedura per stringare il codice clifo
|
|
|
|
|
if (tipocf > ' ')
|
|
|
|
|
{
|
|
|
|
|
const long codcf = pn.curr().get_long(MOV_CODCF);
|
|
|
|
|
TString cf;
|
|
|
|
|
cf.format("%ld", codcf);
|
|
|
|
|
recrighe.add(cf, 7); //codcf
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
recrighe.add("", 7); //codcf
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-15 18:22:01 +00:00
|
|
|
|
recrighe.add(pn.curr().get(RMV_DESCR), 8); //descrizione
|
|
|
|
|
recrighe.add(imp.valore().string(), 9); //importo
|
2005-12-16 13:33:54 +00:00
|
|
|
|
|
2005-12-22 13:49:09 +00:00
|
|
|
|
//procedura per ricavare la voce di spesa
|
|
|
|
|
const TString& vocespesa = get_vocespesa(zio);
|
|
|
|
|
recrighe.add(vocespesa, 14);
|
|
|
|
|
|
2005-12-16 13:33:54 +00:00
|
|
|
|
//e finalmente scrive le righe avanzate...
|
|
|
|
|
trasfilerighe->write(recrighe);
|
2005-12-15 18:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
//---- righe iva ----
|
|
|
|
|
//adesso tocca alle righe iva...e sara' un casino indicibile!
|
2005-12-15 18:22:01 +00:00
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
//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
|
2005-12-20 12:44:06 +00:00
|
|
|
|
for (int j = 0; j < pn.iva_items(); j++)
|
2005-11-03 18:38:07 +00:00
|
|
|
|
{
|
|
|
|
|
//prende il conto e lo mette nell'assoc_array dei conti (notare che, essendo un assoc_array,..
|
|
|
|
|
//..non vengono inseriti doppioni! mitico!!)
|
|
|
|
|
TBill conto;
|
2005-12-20 12:44:06 +00:00
|
|
|
|
conto.get(pn.iva(j));
|
|
|
|
|
const char* codconto = conto.string(0x8);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
//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;
|
2005-12-20 12:44:06 +00:00
|
|
|
|
//aggiunge all'assoc_array conti il suo elemento assoc_array codivae..ha un assoc_array..
|
2005-11-03 18:38:07 +00:00
|
|
|
|
//..di assoc_array!
|
|
|
|
|
conti.add(codconto, codivae);
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
const TString4 codiva = pn.iva(j).get(RMI_CODIVA); //prende il codice iva dalla riga iva
|
2005-11-07 16:39:17 +00:00
|
|
|
|
//aggiungere qui eventuale codice intero di indetraibilita'
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
//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
|
2005-12-20 12:44:06 +00:00
|
|
|
|
*tot_imp += pn.iva(j).get_real(RMI_IMPONIBILE);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
//aggiungere qui eventuale imposta
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-07 16:39:17 +00:00
|
|
|
|
TRecord_text recrigheiva; //istanzia il tipo record corretto da scrivere sul trasfilerighe
|
|
|
|
|
recrigheiva.set_type("I");
|
|
|
|
|
int nrighe = 0;
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TRelation rel_rmoviva(LF_RMOVIVA);
|
|
|
|
|
rel_rmoviva.add(LF_MOV, "NUMREG==NUMREG");
|
|
|
|
|
TCursor cur_rmoviva(&rel_rmoviva);
|
|
|
|
|
cur_rmoviva.curr(LF_MOV) = cur.curr();
|
|
|
|
|
|
|
|
|
|
const long analrigheiva_items = analmov.body().rows();
|
|
|
|
|
|
|
|
|
|
for (i = 1; i <= analrigheiva_items; i++)
|
2005-11-03 18:38:07 +00:00
|
|
|
|
{
|
|
|
|
|
//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
|
|
|
|
|
|
2005-11-07 16:39:17 +00:00
|
|
|
|
//se ha almeno un codice iva associato a questo conto nell'assoc_array dei conti..
|
2005-11-03 18:38:07 +00:00
|
|
|
|
if (codivae != NULL)
|
|
|
|
|
{
|
2005-11-07 16:39:17 +00:00
|
|
|
|
//..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());
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
|
|
|
|
FOR_EACH_ASSOC_OBJECT((*codivae), h, k, imp)
|
2005-11-07 16:39:17 +00:00
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
const real& imp_iva = *(real*)imp;
|
|
|
|
|
distributore.add(imp_iva);
|
2005-11-07 16:39:17 +00:00
|
|
|
|
}
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
|
|
|
|
//crea una riga iva dal cursore, con numreg = numreg della testata del mov originale
|
|
|
|
|
TRectype& rigaiva = cur_rmoviva.curr(LF_RMOVIVA);
|
|
|
|
|
rigaiva.put(RMI_NUMREG, pn.curr().get(MOV_NUMREG));
|
|
|
|
|
|
|
|
|
|
//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));
|
|
|
|
|
const TBill zio(rigaiva);
|
|
|
|
|
rigaiva.put(RMI_TIPOC, zio.tipo());
|
|
|
|
|
rigaiva.put(RMI_IMPONIBILE, distributore.get());
|
|
|
|
|
rigaiva.put(RMI_CODIVA, ki);
|
|
|
|
|
|
|
|
|
|
//deve sottrarre gli importi trovati dalle righe iva originali
|
|
|
|
|
sottrai_iva(pn, rigaiva);
|
|
|
|
|
|
|
|
|
|
//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_rmoviva);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
|
|
|
|
|
//procedura ignorante per stringare il codice clifo
|
|
|
|
|
if (zio.tipo() > ' ')
|
|
|
|
|
{
|
|
|
|
|
const long sottoconto = zio.sottoconto();
|
|
|
|
|
TString cf;
|
|
|
|
|
cf.format("%ld", sottoconto);
|
|
|
|
|
recrigheiva.add(cf, 7);
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
recrigheiva.add(riga.get(RMOVANA_DESCR).left(40), 8); //descrizione riga iva = riga anale corrente
|
|
|
|
|
recrigheiva.add(riga.get(RMOVANA_CODCMS), 13); //commessa presa dalla riga analitica corrente
|
2005-12-22 13:49:09 +00:00
|
|
|
|
|
|
|
|
|
//procedura per ricavare la voce di spesa
|
|
|
|
|
TString uncle = zio.string(0x8);
|
|
|
|
|
const TString& vocespesa = get_vocespesa(uncle);
|
|
|
|
|
recrighe.add(vocespesa, 14);
|
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
trasfilerighe->write(recrigheiva);
|
|
|
|
|
}
|
|
|
|
|
} //if(codivae!=..
|
|
|
|
|
} //for(analmov.rows..
|
2005-11-07 16:39:17 +00:00
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
const long righeiva_items = pn.iva_items();
|
|
|
|
|
if (righeiva_items > 0)
|
|
|
|
|
{
|
|
|
|
|
//deve trasferire le righe iva rimaste dopo la sottrazione degli importi dovuti alle righe analitiche
|
|
|
|
|
for (int k = 0; k < righeiva_items; k++)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& riga = pn.iva(k);
|
|
|
|
|
if (!riga.get_real(RMI_IMPOSTA).is_zero())
|
|
|
|
|
{
|
|
|
|
|
const TBill uncle(riga);
|
|
|
|
|
cur_rmoviva.curr() = riga;
|
|
|
|
|
trasfilerighe->autoload(recrigheiva, cur_rmoviva);
|
2005-12-21 17:01:37 +00:00
|
|
|
|
recrigheiva.add(uncle.tipo(), 6); //tipocf
|
2005-12-20 12:44:06 +00:00
|
|
|
|
recrigheiva.add(uncle.descrizione().left(40), 8); //descrizione della riga iva = descrizione conto
|
2005-12-22 13:49:09 +00:00
|
|
|
|
//procedura per ricavare la voce di spesa
|
|
|
|
|
TString zio = uncle.string(0x8);
|
|
|
|
|
const TString& vocespesa = get_vocespesa(zio);
|
|
|
|
|
recrighe.add(vocespesa, 14);
|
2005-12-20 12:44:06 +00:00
|
|
|
|
trasfilerighe->write(recrigheiva);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TInvioP::sottrai_iva(TMovimentoPN& pn, const TRectype& rigaiva)
|
|
|
|
|
{
|
|
|
|
|
const TBill zio(rigaiva);
|
|
|
|
|
const real imposta = rigaiva.get_real(RMI_IMPOSTA);
|
|
|
|
|
|
|
|
|
|
int k;
|
|
|
|
|
//caso fortunato
|
|
|
|
|
//scandisce gli elementi dell'array;se ne trova uno (k-esimo) con conto ed importo coincidenti..
|
|
|
|
|
//..con quelli passati al metodo, azzera l'importo di tale elemento dell'array
|
|
|
|
|
for (k = 0; k < pn.iva_items(); k++)
|
|
|
|
|
{
|
|
|
|
|
TRectype& iva_k = pn.iva(k);
|
|
|
|
|
const TBill conto_k(iva_k);
|
|
|
|
|
const real imposta_k = iva_k.get_real(RMI_IMPOSTA);
|
|
|
|
|
if (conto_k == zio && imposta_k == imposta)
|
|
|
|
|
{
|
|
|
|
|
iva_k.zero(RMI_IMPOSTA);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//caso sfortunato
|
|
|
|
|
//in questo caso gli importi dell'elemento k-esimo dell'array e passato al metodo NON coincidono
|
|
|
|
|
real residuo = imposta;
|
|
|
|
|
int ultima_riga_buona = -1;
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < pn.iva_items() && !residuo.is_zero(); k++)
|
|
|
|
|
{
|
|
|
|
|
TRectype& iva_k = pn.iva(k);
|
|
|
|
|
const TBill conto_k(iva_k);
|
|
|
|
|
|
|
|
|
|
if (conto_k == zio)
|
|
|
|
|
{
|
|
|
|
|
const real imposta_k = iva_k.get_real(RMI_IMPOSTA);
|
|
|
|
|
if (residuo >= imposta_k)
|
|
|
|
|
{
|
|
|
|
|
residuo -= imposta_k;
|
|
|
|
|
iva_k.zero(RMI_IMPOSTA);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iva_k.put(RMI_IMPOSTA, imposta_k - residuo);
|
|
|
|
|
residuo = ZERO;
|
|
|
|
|
}
|
|
|
|
|
ultima_riga_buona = k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//alla fine del ciclo sull'array resta un residuo non nullo..
|
|
|
|
|
if (!residuo.is_zero())
|
|
|
|
|
{
|
|
|
|
|
if (ultima_riga_buona >= 0)
|
|
|
|
|
{
|
|
|
|
|
TRectype& iva_k = pn.iva(k);
|
|
|
|
|
iva_k.put(RMI_IMPOSTA, -residuo);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-12-21 17:01:37 +00:00
|
|
|
|
void TInvioP::stringa_grcosot(TRecord_text& recrighe, const TString& zio)
|
|
|
|
|
{
|
|
|
|
|
TString8 grcosot;
|
|
|
|
|
long gcs = 0;
|
|
|
|
|
|
|
|
|
|
gcs = atoi(zio.left(3));
|
|
|
|
|
grcosot.format("%d", gcs);
|
|
|
|
|
recrighe.add(grcosot, 3); //gruppo
|
|
|
|
|
|
|
|
|
|
gcs = atoi(zio.mid(3,3));
|
|
|
|
|
grcosot.format("%d", gcs);
|
|
|
|
|
recrighe.add(grcosot, 4); //conto
|
|
|
|
|
|
|
|
|
|
gcs = atoi(zio.mid(6,6));
|
|
|
|
|
grcosot.format("%d", gcs);
|
|
|
|
|
recrighe.add(grcosot, 5); //sottoconto
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-21 10:02:45 +00:00
|
|
|
|
int TInvioP::cerca_costo(const TBill& bill) const
|
|
|
|
|
{
|
|
|
|
|
if (cerca_conto(bill, _costi, 'C'))
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TInvioP::cerca_pagamento(const TBill& bill) const
|
|
|
|
|
{
|
|
|
|
|
if (cerca_conto(bill, _pagamenti, 'P'))
|
|
|
|
|
return 2;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2006-06-12 17:50:50 +00:00
|
|
|
|
TConfig conti("ca3600a.ini","Pdcc"); //paragrafo da scandire nell'ini
|
2005-11-29 14:03:44 +00:00
|
|
|
|
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);
|
2006-06-15 12:48:18 +00:00
|
|
|
|
const TString& tipodet = rmoviva.get(RMI_TIPODET);
|
2005-11-29 14:03:44 +00:00
|
|
|
|
|
|
|
|
|
imponibile += importo;
|
2006-06-15 12:48:18 +00:00
|
|
|
|
if (tipodet.full())
|
|
|
|
|
imponibile += iva;
|
|
|
|
|
else
|
|
|
|
|
imposta += iva;
|
2005-11-29 14:03:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
totdoc = totale_documento(pn.curr()); //tot doc con ritenute fiscali + ritenute sociali (da stampare)
|
|
|
|
|
} //if pn.iva_items()..
|
2006-06-21 10:02:45 +00:00
|
|
|
|
else //movimento NON iva
|
2005-11-29 14:03:44 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
2006-06-12 17:50:50 +00:00
|
|
|
|
{
|
2005-11-29 14:03:44 +00:00
|
|
|
|
if (cerca_fiscali(conto) || cerca_sociali(conto))
|
|
|
|
|
totdoc -= importo.valore(); //valore da stampare nella colonna Tot.fattura con ritenute
|
2006-06-12 17:50:50 +00:00
|
|
|
|
else
|
2005-11-29 14:03:44 +00:00
|
|
|
|
{
|
2006-06-12 17:50:50 +00:00
|
|
|
|
if (rmov.get_char(RMV_ROWTYPE) != 'T' && conto.indicatore_bilancio() != 5)
|
|
|
|
|
{
|
|
|
|
|
imponibile += importo.valore();
|
|
|
|
|
totdoc += importo.valore();
|
|
|
|
|
}
|
2005-11-29 14:03:44 +00:00
|
|
|
|
}
|
2006-06-12 17:50:50 +00:00
|
|
|
|
} //else di if (conto.tipo()
|
|
|
|
|
} //for (int i = 0...
|
|
|
|
|
//tanti calcoli per nulla?
|
|
|
|
|
const real totdoc_testata = totale_documento(pn.curr());
|
|
|
|
|
if (totdoc_testata != ZERO)
|
|
|
|
|
totdoc = totdoc_testata;
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
} //end di else pn.iva_items()...
|
|
|
|
|
|
2006-06-21 10:02:45 +00:00
|
|
|
|
//calcolo finale del pagato
|
|
|
|
|
real percentuale = totpagato /totdoc;
|
|
|
|
|
totpagato = imponibile * percentuale;
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return totpagato;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
bool TInvioP::i_proforma_pagamenti()
|
2005-02-17 18:13:12 +00:00
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* trasfilepag = apri_file("pagament");
|
|
|
|
|
|
2005-11-29 14:03:44 +00:00
|
|
|
|
TRectype da(LF_MOV);
|
|
|
|
|
TRectype a(LF_MOV);
|
2006-06-12 17:50:50 +00:00
|
|
|
|
da.put(MOV_DATAREG, _dataini);
|
|
|
|
|
a.put(MOV_DATAREG, _datafin);
|
2005-11-29 14:03:44 +00:00
|
|
|
|
TRelation rel(LF_MOV);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
rel.add(LF_CAUSALI, "CODCAUS==CODCAUS");
|
2005-11-29 14:03:44 +00:00
|
|
|
|
TCursor cur(&rel, "", 2, &da, &a);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
const long cur_items = cur.items();
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
if (cur_items != 0)
|
2005-11-29 14:03:44 +00:00
|
|
|
|
{
|
|
|
|
|
//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');
|
2006-06-21 10:14:45 +00:00
|
|
|
|
lettura_conti(_costi, 'C');
|
|
|
|
|
lettura_conti(_pagamenti, 'P');
|
2005-11-29 14:03:44 +00:00
|
|
|
|
|
2005-12-20 12:44:06 +00:00
|
|
|
|
TProgind pi(cur_items, "Trasferimento pagamenti...", true, true);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
cur.freeze();
|
|
|
|
|
TRectype& cur_rec = cur.curr();
|
|
|
|
|
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
2005-11-03 18:38:07 +00:00
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
if (pi.iscancelled())
|
|
|
|
|
break;
|
|
|
|
|
|
2006-06-21 10:02:45 +00:00
|
|
|
|
//pagamenti saldacontati! vedi l'else per quelli non saldacontati
|
2005-11-29 14:03:44 +00:00
|
|
|
|
const char tipomov = cur_rec.get(MOV_TIPOMOV)[0];
|
|
|
|
|
if (tipomov == '3' || tipomov == '2' || tipomov == '6')
|
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
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))
|
2005-05-16 23:44:23 +00:00
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
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;
|
2005-11-29 14:03:44 +00:00
|
|
|
|
const real importo_pagato = calcola_pagamento(curpag_rec); //aggiunta nuova!!!
|
|
|
|
|
somma += importo_pagato;
|
2005-11-03 18:38:07 +00:00
|
|
|
|
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;
|
2006-06-15 11:56:35 +00:00
|
|
|
|
_chiusa = partita.get_bool(PART_CHIUSA);
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TRecord_text recpag;
|
|
|
|
|
recpag.set_type("G");
|
|
|
|
|
trasfilepag->autoload(recpag, curpag);
|
|
|
|
|
trasfilepag->write(recpag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//if curpag_items..
|
|
|
|
|
}//for curpart =..
|
|
|
|
|
}//if curpart_items..
|
2006-06-21 10:02:45 +00:00
|
|
|
|
|
|
|
|
|
}//if tipomov ==..
|
|
|
|
|
else //tocca ai pagamenti NON saldacontati (procedura analoga a quella della stampa del pagato)
|
|
|
|
|
{
|
|
|
|
|
const long numregcg = cur_rec.get_long(MOV_NUMREG);
|
|
|
|
|
|
|
|
|
|
//cerca un record di MOVANA che abbia numregcg = nreg;usa il nuovo metodo fighissimo..
|
|
|
|
|
//..con la isam query
|
|
|
|
|
TString& query = get_tmp_string();
|
|
|
|
|
query << "USE MOVANA KEY 3\n";
|
|
|
|
|
query << "FROM NUMREGCG=" << numregcg << "\n";
|
|
|
|
|
query << "TO NUMREGCG=" << numregcg;
|
|
|
|
|
|
|
|
|
|
TISAM_recordset movana(query);
|
|
|
|
|
const TRecnotype items = movana.items();
|
|
|
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
|
{
|
|
|
|
|
if (items > 1)
|
|
|
|
|
error_box(TR("Esiste piu' di un movimento analitico collegato al movimento contabile %ld"),numregcg);
|
|
|
|
|
|
|
|
|
|
movana.move_last(); //si posiziona sul record corretto
|
|
|
|
|
|
|
|
|
|
//crea il movana legato al mov
|
|
|
|
|
const TAnal_mov anal_mov(cur_rec);
|
|
|
|
|
const TRecord_array& anal_rows = anal_mov.body();
|
|
|
|
|
|
|
|
|
|
for (int j = 1; j <= anal_rows.rows(); j++) //scansiona righe analitiche..
|
|
|
|
|
{
|
|
|
|
|
const TRectype& anal_row = anal_rows[j];
|
|
|
|
|
|
|
|
|
|
//prende il conto sulla riga analitica e lo confronta con quelli della configurazione
|
|
|
|
|
const TString& conto_riga_analitica = anal_row.get(RMOVANA_CODCONTO);
|
|
|
|
|
const int gruppo_anal = atoi(conto_riga_analitica.left(3));
|
|
|
|
|
const int conto_anal = atoi(conto_riga_analitica.mid(3,3));
|
|
|
|
|
const long sottoconto_anal = atol(conto_riga_analitica.mid(6,6));
|
|
|
|
|
|
|
|
|
|
const TBill conto(gruppo_anal, conto_anal, sottoconto_anal);
|
|
|
|
|
int tipo = cerca_costo(conto) || cerca_pagamento(conto);
|
|
|
|
|
if (tipo > 0)
|
|
|
|
|
{
|
|
|
|
|
const char sezione = anal_row.get_char(RMOVANA_SEZIONE);
|
|
|
|
|
const real valore = anal_row.get_real(RMOVANA_IMPORTO);
|
|
|
|
|
TImporto imp(sezione, valore);
|
|
|
|
|
|
|
|
|
|
switch (tipo)
|
|
|
|
|
{
|
|
|
|
|
case 1:imp.normalize('D');break;
|
|
|
|
|
case 2:imp.normalize('A');break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
_nregpag = numregcg;
|
|
|
|
|
_nregcosto = numregcg;
|
|
|
|
|
_importo = imp.valore();
|
|
|
|
|
_chiusa = true;
|
|
|
|
|
|
|
|
|
|
//e finalmente aggiunge il record al file di esportazione
|
|
|
|
|
TRecord_text recpag;
|
|
|
|
|
recpag.set_type("G");
|
|
|
|
|
trasfilepag->autoload(recpag, *movana.cursor());
|
|
|
|
|
trasfilepag->write(recpag);
|
|
|
|
|
} //if (tipo > 0..
|
|
|
|
|
|
|
|
|
|
} //for(j<anal_rows...
|
|
|
|
|
} //if(items>0...
|
|
|
|
|
|
|
|
|
|
} //else if tipomov ==..
|
|
|
|
|
|
2005-11-03 18:38:07 +00:00
|
|
|
|
}//for cur =..
|
|
|
|
|
}//if cur_items..
|
|
|
|
|
|
|
|
|
|
chiudi_file(trasfilepag);
|
|
|
|
|
return true;
|
2005-05-16 23:44:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
bool TInvioP::i_proforma_clifor(char tipocf)
|
|
|
|
|
{
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TInvioP_file* trasfile = NULL;
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
|
|
|
|
TString progind_string = "Trasferimento ";
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
if (tipocf == 'C')
|
2005-12-20 12:44:06 +00:00
|
|
|
|
{
|
2005-11-07 16:39:17 +00:00
|
|
|
|
trasfile = apri_file("clienti");
|
2005-12-20 12:44:06 +00:00
|
|
|
|
progind_string << "clienti";
|
|
|
|
|
}
|
2005-02-17 18:13:12 +00:00
|
|
|
|
else
|
2005-12-20 12:44:06 +00:00
|
|
|
|
{
|
2005-11-07 16:39:17 +00:00
|
|
|
|
trasfile = apri_file("fornit");
|
2005-12-20 12:44:06 +00:00
|
|
|
|
progind_string << "fornitori";
|
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TString80 filtro = "";
|
|
|
|
|
filtro.format("TIPOCF == \"%c\"", tipocf);
|
|
|
|
|
TRelation rel(LF_CLIFO);
|
2005-03-03 15:42:04 +00:00
|
|
|
|
rel.add(LF_COMUNI, "STATO==STATOCF|COM==COMCF", 1);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TCursor cur(&rel, filtro);
|
|
|
|
|
const long cur_items = cur.items();
|
2005-12-20 12:44:06 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
if (cur_items != 0)
|
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
progind_string << "...";
|
|
|
|
|
TProgind pi(cur_items, progind_string, true, true);
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
cur.freeze();
|
|
|
|
|
TRectype& cur_rec = cur.curr();
|
|
|
|
|
for (cur = 0; cur.pos() < cur_items; ++(cur))
|
|
|
|
|
{
|
2005-12-20 12:44:06 +00:00
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
if (pi.iscancelled())
|
|
|
|
|
break;
|
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
TRecord_text rec;
|
|
|
|
|
rec.set_type("C");
|
2005-11-03 18:38:07 +00:00
|
|
|
|
trasfile->autoload(rec, cur);
|
|
|
|
|
trasfile->write(rec);
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2005-11-07 16:39:17 +00:00
|
|
|
|
//il programma si puo' usare SOLO se in contabilita' analitica si usa il piano dei conti contabile
|
2005-11-03 18:38:07 +00:00
|
|
|
|
TConfig& cfg = ca_config();
|
|
|
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
|
if (!use_pdcc)
|
2005-11-07 16:39:17 +00:00
|
|
|
|
{
|
|
|
|
|
error_box(TR("Programma funzionante SOLO se in contabilita' analitica si usa il piano dei conti contabile"));
|
2005-11-03 18:38:07 +00:00
|
|
|
|
return;
|
2005-11-07 16:39:17 +00:00
|
|
|
|
}
|
2005-11-03 18:38:07 +00:00
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
}
|
2005-02-17 18:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cg7200(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
TInvioP a;
|
2005-11-03 18:38:07 +00:00
|
|
|
|
a.run(argc, argv, "Invio dati contabilit<69> a Proforma");
|
2006-01-09 01:15:53 +00:00
|
|
|
|
|
2005-02-17 18:13:12 +00:00
|
|
|
|
return 0;
|
2006-01-09 01:15:53 +00:00
|
|
|
|
}
|