Patch level :
Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@21766 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
cdf74595d3
commit
a2f3ae3885
632
ha/hacnv400.cpp
632
ha/hacnv400.cpp
@ -4,41 +4,34 @@
|
||||
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <defmask.h>
|
||||
#include <execp.h>
|
||||
#include <progind.h>
|
||||
#include <reprint.h>
|
||||
#include <reputils.h>
|
||||
#include <tabutil.h>
|
||||
#include <utility.h>
|
||||
//#include <reprint.h>
|
||||
//#include <reputils.h>
|
||||
//#include <tabutil.h>
|
||||
//#include <utility.h>
|
||||
|
||||
#include "../mg/mglib.h"
|
||||
#include "../mg/movmag.h"
|
||||
#include "../mg/rmovmag.h"
|
||||
|
||||
const char* const APPNAME = TR("Conversione movimenti di magazzino");
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Movimenti
|
||||
// Movimenti di magazzino
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class THardy_movmag : public THardy_transfer
|
||||
{
|
||||
int _anno; // parametri per la query
|
||||
TDate _dadata, _adata; // parametri per la query
|
||||
TConfig* _conf; // ini in compilazione
|
||||
long _kmovcont; // movimento contabile in esame
|
||||
TArray* _righeiva; // array dele righe iva hardy
|
||||
TArray* _righecont; // array delle righe contabili hardy
|
||||
TAssoc_array* _ivaind; // array dei codici iva con % di indetraibilità
|
||||
TAssoc_array* _ivaoma; // array dei codici iva per gli omaggi
|
||||
int _protocollo; // numero protocollo del mov.mag.
|
||||
//TMov_mag _mov; // Tmov_mag per scrivere il movimento di magazzino con tutti gli annessi e connessi
|
||||
|
||||
protected:
|
||||
bool scrivi_righe();
|
||||
bool scrivi_righecont();
|
||||
bool test_movcont();
|
||||
bool conto_is_costoricavo(const int gr);
|
||||
bool test_moviva();
|
||||
void conto2campo(const TString& hd_tipoc, const TString& hd_key, TString4& tipoc, int& gr, int& co, long& so);
|
||||
void rec2ini(const TRectype& rec);
|
||||
bool scrivi_righe(TMov_mag& mov);
|
||||
bool scrivi_testata(const TRecordset& recset, TMov_mag& mov);
|
||||
void recset2rec(const TODBC_recordset& recset, TRectype& rec, const TString_array& lista_campi);
|
||||
real get_imponibile(const TRectype& rec);
|
||||
void conto2campo(const TString& hd_tipoc, const TString& hd_key, TString4& tipoc, int& gr, int& co, long& so);
|
||||
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
@ -180,494 +173,63 @@ void THardy_movmag::conto2campo(const TString& hd_tipoc, const TString& hd_key,
|
||||
}
|
||||
}
|
||||
|
||||
// verifica in configurazione se il conto è costo o ricavo
|
||||
bool THardy_movmag::conto_is_costoricavo(const int gr)
|
||||
bool THardy_movmag::scrivi_testata(const TRecordset& recset, TMov_mag& mov)
|
||||
{
|
||||
TConfig& ini = config();
|
||||
const int costi = ini.get_int("COSTI_GRUPPO", "Parametri");
|
||||
const int ricavi = ini.get_int("RICAVI_GRUPPO", "Parametri");
|
||||
return ((gr == costi) || (gr == ricavi));
|
||||
// cliente/fornitore
|
||||
const TString& key = recset.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset.get("IdContoTp").as_string();
|
||||
TString4 tipoc = " ";
|
||||
int gr, co;
|
||||
long so;
|
||||
gr = 0;
|
||||
co = 0;
|
||||
so = 0;
|
||||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||||
mov.zero();
|
||||
// posso lasciare vuoto numreg ??
|
||||
mov.put(MOVMAG_ANNOES, recset.get("Esercizio").as_int());
|
||||
mov.put(MOVMAG_DATAREG, recset.get("DataMovimento").as_string());
|
||||
mov.put(MOVMAG_DATACOMP, recset.get("DataCompetenza").as_string());
|
||||
mov.put(MOVMAG_CODCAUS, recset.get("IdCausale").as_string());
|
||||
mov.put(MOVMAG_TIPOCF, tipoc);
|
||||
mov.put(MOVMAG_CODINDSP, recset.get("IdDestinazione").as_string());
|
||||
mov.put(MOVMAG_CODCF, so);
|
||||
mov.put(MOVMAG_NUMREGST, recset.get("ProtGiornale").as_int());
|
||||
return true;
|
||||
}
|
||||
|
||||
// verifica se il movimento è iva e nel caso riempie array delle righe iva
|
||||
bool THardy_movmag::test_moviva()
|
||||
// legge righe del movmag e le scrive nel TMov_mag
|
||||
bool THardy_movmag::scrivi_righe(TMov_mag& mov)
|
||||
{
|
||||
// verifico se è un movimento iva: esiste un record in MovIvaT
|
||||
TString query;
|
||||
query << query_header();
|
||||
query << "SELECT * "
|
||||
"FROM dbo.MovIvaT "
|
||||
"WHERE KMovconT=";
|
||||
query << _kmovcont;
|
||||
TODBC_recordset recset(query);
|
||||
real totdoc = ZERO;
|
||||
long kregivat = -1;
|
||||
if (recset.items() > 0)
|
||||
{
|
||||
bool ok=recset.move_first();
|
||||
if (ok)
|
||||
{
|
||||
kregivat = recset.get("KRegivaT").as_int();
|
||||
// aggiorna_testata movimento già scritta su ini con i nuovi dati di testata
|
||||
const TString& key = recset.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset.get("IdContoTp").as_string();
|
||||
TString4 tipoc = " ";
|
||||
int gr, co;
|
||||
long so;
|
||||
gr = 0;
|
||||
co = 0;
|
||||
so = 0;
|
||||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||||
_conf->set(MOV_TIPO, tipoc);
|
||||
_conf->set(MOV_CODCF, so);
|
||||
totdoc = recset.get("TotDocumento").as_real();
|
||||
if (totdoc == ZERO)
|
||||
_conf->set("SOLAIVA", "X");
|
||||
_conf->set(MOV_TOTDOC, totdoc.string(0,2));
|
||||
}
|
||||
}
|
||||
// leggo le righe iva e costrisco array corrispondente
|
||||
TString_array lista_campi_righeiva;
|
||||
TConfig& ini = config();
|
||||
ini.list_variables(lista_campi_righeiva, true, "RMOVIVA", true);
|
||||
TString query_righe;
|
||||
query_righe << query_header();
|
||||
query_righe << "SELECT * "
|
||||
"FROM dbo.MovIva "
|
||||
"WHERE KRegivaT=";
|
||||
query_righe << kregivat;
|
||||
"FROM dbo.MovMagazzino "
|
||||
"WHERE Protocollo=";
|
||||
query_righe << _protocollo;
|
||||
TODBC_recordset recset_righe(query_righe);
|
||||
_righeiva->destroy();
|
||||
TLocalisamfile rmoviva(LF_RMOVIVA);
|
||||
TRectype& rec_rmoviva = rmoviva.curr();
|
||||
real totdoc_calc = ZERO;
|
||||
for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
|
||||
{
|
||||
recset2rec(recset_righe, rec_rmoviva, lista_campi_righeiva);
|
||||
const TString& key = recset_righe.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||||
TString4 tipoc;
|
||||
tipoc = " ";
|
||||
int gr, co;
|
||||
long so;
|
||||
gr = 0;
|
||||
co = 0;
|
||||
so = 0;
|
||||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||||
rec_rmoviva.put(RMI_TIPOC, tipoc);
|
||||
rec_rmoviva.put(RMI_GRUPPO, gr);
|
||||
rec_rmoviva.put(RMI_CONTO, co);
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, so);
|
||||
const TString& codiva = rec_rmoviva.get(RMI_CODIVA);
|
||||
const TString* codind = (TString*)_ivaind->objptr(codiva);
|
||||
if (codind != NULL)
|
||||
rec_rmoviva.put(RMI_TIPODET, *codind);
|
||||
_righeiva->add(new TRectype(rec_rmoviva));
|
||||
if (!_ivaoma->is_key(codiva))
|
||||
totdoc_calc+=recset_righe.get("Imponibile").as_real();
|
||||
totdoc_calc+=recset_righe.get("Imposta").as_real();
|
||||
}
|
||||
if (totdoc == ZERO && totdoc_calc != ZERO)
|
||||
{
|
||||
_conf->set("SOLAIVA", " ");
|
||||
_conf->set(MOV_TOTDOC, totdoc_calc.string(0,2));
|
||||
}
|
||||
return (kregivat > 0);
|
||||
}
|
||||
|
||||
// riempie array delle righe contabili
|
||||
bool THardy_movmag::test_movcont()
|
||||
{
|
||||
TString_array lista_campi_righe;
|
||||
TConfig& ini = config();
|
||||
ini.list_variables(lista_campi_righe, true, "RMOV", true);
|
||||
TString query_righe;
|
||||
query_righe << query_header();
|
||||
query_righe << "SELECT * "
|
||||
"FROM dbo.MovContabili "
|
||||
"WHERE KMovconT=";
|
||||
query_righe << _kmovcont;
|
||||
TODBC_recordset recset_righe(query_righe);
|
||||
_righecont->destroy();
|
||||
TLocalisamfile rmov(LF_RMOV);
|
||||
TLocalisamfile rmov(LF_RMOVMAG);
|
||||
TRectype& rec_rmov = rmov.curr();
|
||||
|
||||
TString8 codcaus = mov.get(MOVMAG_CODCAUS);
|
||||
for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
|
||||
{
|
||||
recset2rec(recset_righe, rec_rmov, lista_campi_righe);
|
||||
const TString& key = recset_righe.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||||
TString4 tipoc;
|
||||
tipoc = " ";
|
||||
int gr, co;
|
||||
long so;
|
||||
gr = 0;
|
||||
co = 0;
|
||||
so = 0;
|
||||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||||
TString4 sezione = "D";
|
||||
real imp_dare = recset_righe.get("Dare").as_real();
|
||||
real imp_avere = recset_righe.get("Avere").as_real();
|
||||
if (imp_dare.is_zero())
|
||||
sezione = "A";
|
||||
rec_rmov.put(RMV_SEZIONE, sezione);
|
||||
rec_rmov.put(RMV_IMPORTO, (imp_avere.is_zero() ? imp_dare : imp_avere));
|
||||
rec_rmov.put(RMV_TIPOC, tipoc);
|
||||
rec_rmov.put(RMV_GRUPPO, gr);
|
||||
rec_rmov.put(RMV_CONTO, co);
|
||||
rec_rmov.put(RMV_SOTTOCONTO, so);
|
||||
_righecont->add(new TRectype(rec_rmov));
|
||||
TRectype& rmov = mov.new_row();
|
||||
TString8 codcaus_riga = recset_righe.get("IdCausale").as_string();
|
||||
if (codcaus != codcaus_riga)
|
||||
rmov.put(RMOVMAG_CODCAUS, codcaus_riga);
|
||||
rmov.put(RMOVMAG_CODMAG, recset_righe.get("IdMagazzino1").as_string());
|
||||
rmov.put(RMOVMAG_CODART, recset_righe.get("IdProdotto").as_string());
|
||||
rmov.put(RMOVMAG_QUANT, recset_righe.get("Quantita").as_string());
|
||||
rmov.put(RMOVMAG_PREZZO, recset_righe.get("Prezzo").as_string());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// scrive il record passato sull'ini corrente
|
||||
void THardy_movmag::rec2ini(const TRectype& rec)
|
||||
{
|
||||
for (int i=0; i<rec.items(); i++)
|
||||
{
|
||||
const char* fieldname = rec.fieldname(i);
|
||||
const TString& value = rec.get(fieldname);
|
||||
if (!value.empty())
|
||||
_conf->set(fieldname, value);
|
||||
}
|
||||
}
|
||||
|
||||
// scrive su ini le righe contabili
|
||||
bool THardy_movmag::scrivi_righecont()
|
||||
{
|
||||
TString paragraph;
|
||||
int nrigac = 1;
|
||||
for (int i=0;i<_righecont->items();i++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(i);
|
||||
paragraph.format("%d,%d",LF_RMOV, nrigac++);
|
||||
_conf->set_paragraph(paragraph); // riga contabile
|
||||
rec2ini(rec_rmov);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// calcola imponibile della riga iva passata:
|
||||
// 1. se è una riga con iva indetraibile verifico il conto 4 sulla causale
|
||||
// se il conto c'è, l'imponibile è imponibile della riga
|
||||
// se il conto non c'è calcolo iva indetraibile utilizzando la % e la sommo all'imponibile
|
||||
// 2. se è una riga con iva normale, l'imponibile è imponibliie della riga
|
||||
real THardy_movmag::get_imponibile(const TRectype& rec)
|
||||
{
|
||||
real imponibile = rec.get_real(RMI_IMPONIBILE);
|
||||
const char* codiva = rec.get(RMI_CODIVA);
|
||||
if (_ivaind->is_key(codiva))
|
||||
{
|
||||
TString16 causale = get_str("IdCausale");
|
||||
causale << "|4";
|
||||
const TString& gruppo = cache().get(LF_RCAUSALI, causale, RCA_GRUPPO);
|
||||
if (gruppo.blank())
|
||||
{
|
||||
real imposta = rec.get_real(RMI_IMPOSTA);
|
||||
TString& codind = (TString&)_ivaind->find(codiva);
|
||||
real perc(cache().get("%DET", codind, "R0"));
|
||||
imposta = (imposta*perc)/CENTO + 0,01;
|
||||
imposta.round(2);
|
||||
imponibile+=imposta;
|
||||
}
|
||||
}
|
||||
return imponibile;
|
||||
}
|
||||
|
||||
// gestisce tutto il procedimento di scrittura su ini delle righe iva e contabili
|
||||
bool THardy_movmag::scrivi_righe()
|
||||
{
|
||||
const int ndec = TCurrency::get_firm_dec(false);
|
||||
TString paragraph;
|
||||
int nrigai = 1; // contatore righe iva
|
||||
|
||||
TConfig& ini = config();
|
||||
TString8 iva_esente = ini.get("IVA_ESENTE", "Parametri");
|
||||
TToken_string sconto_omaggi = ini.get("CONTO_OMAGGI", "Parametri");
|
||||
TToken_string conti_mov = ini.get("CONTI_MOV", "Parametri");
|
||||
const int gruppo_omaggi = sconto_omaggi.get_int(0);
|
||||
const int conto_omaggi = sconto_omaggi.get_int(1);
|
||||
const long sottoconto_omaggi = sconto_omaggi.get_long(2);
|
||||
real saldo;
|
||||
|
||||
// la sezione della riga 1 mi serve per verificare il segno e la sezione delle righe contabili
|
||||
TString16 causale = get_str("IdCausale");
|
||||
causale << "|1";
|
||||
const char sez_cau = (cache().get(LF_RCAUSALI, causale, RCA_SEZIONE)[0] == 'D' ? 'A' : 'D');
|
||||
bool has_iva_omaggio = false;
|
||||
|
||||
// se è un movimento iva metto in atto il meccanismo di ricerca per assegnare le aliquote ai conti
|
||||
if (_righeiva->items() > 0)
|
||||
{
|
||||
for (int i = 0; !has_iva_omaggio && i<_righeiva->items(); i++)
|
||||
has_iva_omaggio = _ivaoma->is_key(((TRectype*)_righeiva->objptr(i))->get(RMI_CODIVA));
|
||||
// primo passo: scartare le righe contabili con gruppi non presenti nella lista GRUPPI_MOV
|
||||
for (int i=_righecont->items() - 1;i>=0;i--)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(i);
|
||||
const int gruppo = rec_rmov.get_int(RMV_GRUPPO);
|
||||
const int conto = rec_rmov.get_int(RMV_CONTO);
|
||||
const long sottoconto = rec_rmov.get_long(RMV_SOTTOCONTO);
|
||||
TToken_string key;
|
||||
|
||||
key.add(gruppo);
|
||||
key.add(conto);
|
||||
|
||||
const int tipoconto = atoi(cache().get(LF_PCON, key, PCN_INDBIL));
|
||||
const bool riga_omaggio = (gruppo == gruppo_omaggi) && (conto == conto_omaggi) && (sottoconto == sottoconto_omaggi);
|
||||
const TString & descr = rec_rmov.get(RMV_DESCR);
|
||||
|
||||
// se la descrizione comincia con queste stringhe, significa che è un pagamento immediato
|
||||
// e va passata la riga contabile cosi come è
|
||||
if (descr.starts_with("S.DO DOC.") || descr.starts_with("ABB. DOC.") || descr.starts_with("ACC. DOC."))
|
||||
rec_rmov.put(RMV_ROWTYPE, "C");
|
||||
else
|
||||
if (riga_omaggio)
|
||||
{
|
||||
if (!has_iva_omaggio)
|
||||
{
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(*(TRectype*)_righeiva->objptr(0));
|
||||
// sostituisco codice iva e importo (-) e gruppo conto sottoconto
|
||||
const char sezione = rec_rmov.get_char(RMV_SEZIONE);
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
if (sezione != sez_cau)
|
||||
importo = -importo;
|
||||
saldo += importo;
|
||||
_conf->set(RMI_CODIVA, iva_esente); // codice iva esente per quadrare il movimento
|
||||
_conf->set(RMI_TIPODET, "");
|
||||
_conf->set(RMI_IMPONIBILE, importo.string(0,2)); // imponibile negativo
|
||||
_conf->set(RMI_IMPOSTA, ""); // imposta zero
|
||||
_conf->set(RMI_TIPOC, "");
|
||||
_conf->set(RMI_GRUPPO, sconto_omaggi.get(0));
|
||||
_conf->set(RMI_CONTO, sconto_omaggi.get(1));
|
||||
_conf->set(RMI_SOTTOCONTO, sconto_omaggi.get(2));
|
||||
}
|
||||
_righecont->destroy(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool found = (tipoconto == 3) || (tipoconto == 4);
|
||||
|
||||
if (!found)
|
||||
{
|
||||
TToken_string cod("", ',');
|
||||
cod.add(gruppo);
|
||||
cod.add(conto);
|
||||
cod.add(sottoconto);
|
||||
|
||||
// Provo il sottoconto ma se non riesco provo con conto e poi anche gruppo (formato -> 3,1,2 o 3,1,0 o 3,0,0)
|
||||
for (int c = 2; !found && c >= 0; c--)
|
||||
{
|
||||
found = conti_mov.get_pos(cod) >= 0;
|
||||
cod.add(0, c);
|
||||
}
|
||||
if (!found)
|
||||
_righecont->destroy(i);
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
const char sezione = rec_rmov.get_char(RMV_SEZIONE);
|
||||
if (sezione != sez_cau)
|
||||
{
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
importo = -importo;
|
||||
rec_rmov.put(RMV_SEZIONE, sez_cau);
|
||||
rec_rmov.put(RMV_IMPORTO, importo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_righecont->pack();
|
||||
const bool singola_rigacont = (_righecont->items()==1);
|
||||
// secondo passo: per ogni riga iva cerco importo uguale in righe contabili,
|
||||
// se lo trovo assegno quel codice iva al conto contabile trovato e cancello la riga iva e la riga contabile
|
||||
for (int i=0;i<_righeiva->items();i++)
|
||||
{
|
||||
TRectype& rec_rmoviva = *(TRectype*)_righeiva->objptr(i);
|
||||
const char* codiva = rec_rmoviva.get(RMI_CODIVA);
|
||||
const bool riga_omaggio = _ivaoma->is_key(codiva);
|
||||
// se le righe contabili sono 1, su tutte le righe iva metto quel conto, da brava massaia ...
|
||||
if ((!riga_omaggio) && _righecont->items()==1)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(0);
|
||||
rec_rmoviva.put(RMI_TIPOC, rec_rmov.get(RMV_TIPOC));
|
||||
rec_rmoviva.put(RMI_GRUPPO, rec_rmov.get(RMV_GRUPPO));
|
||||
rec_rmoviva.put(RMI_CONTO, rec_rmov.get(RMV_CONTO));
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, rec_rmov.get(RMV_SOTTOCONTO));
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
rec_rmoviva.zero();
|
||||
}
|
||||
else
|
||||
{
|
||||
TCodiceIVA c(codiva);
|
||||
real imponibile = get_imponibile(rec_rmoviva);
|
||||
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
const bool riga_cont = (rec_rmov.get(RMV_ROWTYPE) == "C");
|
||||
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
if ((!riga_omaggio) && (!riga_cont) && (importo <= imponibile))
|
||||
{
|
||||
const real impon = rec_rmoviva.get_real(RMI_IMPONIBILE);
|
||||
const real iva = rec_rmoviva.get_real(RMI_IMPOSTA);
|
||||
c.imposta(importo);
|
||||
rec_rmoviva.put(RMI_TIPOC, rec_rmov.get(RMV_TIPOC));
|
||||
rec_rmoviva.put(RMI_GRUPPO, rec_rmov.get(RMV_GRUPPO));
|
||||
rec_rmoviva.put(RMI_CONTO, rec_rmov.get(RMV_CONTO));
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, rec_rmov.get(RMV_SOTTOCONTO));
|
||||
real wimp = impon ;
|
||||
if (importo < imponibile)
|
||||
{
|
||||
wimp *= importo / imponibile;
|
||||
wimp.round(2);
|
||||
}
|
||||
const real wiva = c.imposta(wimp);
|
||||
if (importo < imponibile)
|
||||
{
|
||||
rec_rmoviva.put(RMI_IMPONIBILE, wimp);
|
||||
rec_rmoviva.put(RMI_IMPOSTA, wiva);
|
||||
}
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
_righecont->destroy(j, true);
|
||||
j = _righecont->items();
|
||||
if (importo == imponibile)
|
||||
rec_rmoviva.zero();
|
||||
else
|
||||
{
|
||||
rec_rmoviva.put(RMI_IMPONIBILE, impon - wimp);
|
||||
rec_rmoviva.put(RMI_IMPOSTA, iva - wiva);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_righecont->pack();
|
||||
// terzo passo: per ogni riga iva rimasta distribuisco importo su tutti i conti rimasti in righe cont.
|
||||
for (int i=0;i<_righeiva->items();i++)
|
||||
{
|
||||
TRectype& rec_rmoviva = *(TRectype*)_righeiva->objptr(i);
|
||||
if (!rec_rmoviva.empty())
|
||||
{
|
||||
const TString& codiva = rec_rmoviva.get(RMI_CODIVA);
|
||||
const bool riga_omaggio = _ivaoma->is_key(codiva);
|
||||
real imponibile = rec_rmoviva.get_real(RMI_IMPONIBILE);
|
||||
real imposta = rec_rmoviva.get_real(RMI_IMPOSTA);
|
||||
TGeneric_distrib dimponibile(imponibile, ndec);
|
||||
TGeneric_distrib dimposta(imposta, ndec);
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
const bool riga_cont = (rec_rmov.get(RMV_ROWTYPE) == "C");
|
||||
if (!riga_cont)
|
||||
{
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
dimponibile.add(importo);
|
||||
dimposta.add(importo);
|
||||
}
|
||||
}
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
const bool riga_cont = (rec_rmov.get(RMV_ROWTYPE) == "C");
|
||||
if (!riga_cont)
|
||||
{
|
||||
real importo = dimponibile.get();
|
||||
real imposta = dimposta.get();
|
||||
rec_rmoviva.put(RMI_TIPOC, rec_rmov.get(RMV_TIPOC));
|
||||
rec_rmoviva.put(RMI_GRUPPO, rec_rmov.get(RMV_GRUPPO));
|
||||
rec_rmoviva.put(RMI_CONTO, rec_rmov.get(RMV_CONTO));
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, rec_rmov.get(RMV_SOTTOCONTO));
|
||||
rec_rmoviva.put(RMI_IMPONIBILE, importo);
|
||||
rec_rmoviva.put(RMI_IMPOSTA, imposta);
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
}
|
||||
}
|
||||
// se iva utilizzata per gli omaggi, devo fare un'altra riga iva identica ma con importo avere con iva esente e gr/co/so letto da configurazione CONTO_OMAGGI
|
||||
if (riga_omaggio)
|
||||
{
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
// sostituisco codice iva e importo (-) e gruppo conto sottoconto
|
||||
imponibile = -imponibile;
|
||||
_conf->set(RMI_CODIVA, iva_esente); // codice iva esente per quadrare il movimento
|
||||
_conf->set(RMI_TIPODET, "");
|
||||
_conf->set(RMI_IMPONIBILE, imponibile.string(0,2)); // imponibile negativo
|
||||
_conf->set(RMI_IMPOSTA, ""); // imposta zero
|
||||
_conf->set(RMI_TIPOC, "");
|
||||
_conf->set(RMI_GRUPPO, sconto_omaggi.get(0));
|
||||
_conf->set(RMI_CONTO, sconto_omaggi.get(1));
|
||||
_conf->set(RMI_SOTTOCONTO, sconto_omaggi.get(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int j=_righecont->items()-1;j>=0;j--)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
const bool riga_cont = (rec_rmov.get(RMV_ROWTYPE) == "C");
|
||||
if (riga_cont)
|
||||
rec_rmov.zero(RMV_ROWTYPE);
|
||||
else
|
||||
_righecont->destroy(j, true);
|
||||
}
|
||||
if (saldo != ZERO)
|
||||
{
|
||||
TString paragraph;
|
||||
|
||||
paragraph.format("%d",LF_MOV);
|
||||
|
||||
real totdoc(_conf->get(MOV_TOTDOC, paragraph));
|
||||
totdoc += saldo;
|
||||
_conf->set(MOV_TOTDOC, totdoc.string(0,2), paragraph);
|
||||
}
|
||||
//_righecont->destroy();
|
||||
}
|
||||
// scrivo su ini le righe contabili rimaste (tutte se il mov non è iva)
|
||||
scrivi_righecont();
|
||||
return true;
|
||||
}
|
||||
|
||||
// procedura principale di conversione
|
||||
bool THardy_movmag::trasferisci()
|
||||
{
|
||||
TConfig& ini = config();
|
||||
|
||||
// creazione array delle aliquote iva con % indetraibilità e degli omaggi
|
||||
// leggere la tabella hardy AliquoteIVA
|
||||
_ivaind->destroy();
|
||||
_ivaoma->destroy();
|
||||
TString query_iva;
|
||||
query_iva << query_header();
|
||||
query_iva << "SELECT * "
|
||||
"FROM dbo.AliquoteIVA ";
|
||||
TODBC_recordset recset_iva(query_iva);
|
||||
for (bool ok=recset_iva.move_first();ok;ok=recset_iva.move_next())
|
||||
{
|
||||
const char* codiva = recset_iva.get("IdIva").as_string();
|
||||
real ind = recset_iva.get("Indetraibilita").as_real();
|
||||
const int flomaggio = recset_iva.get("FlOmaggio").as_int();
|
||||
if (ind != ZERO)
|
||||
{
|
||||
TString4 oggetto = ini.get(codiva, "Indetraibilita");
|
||||
_ivaind->add(codiva, oggetto);
|
||||
}
|
||||
if (flomaggio > 0)
|
||||
{
|
||||
real* oggetto = new real();
|
||||
_ivaoma->add(codiva, (TObject*)oggetto);
|
||||
}
|
||||
}
|
||||
|
||||
// query su testate movimenti
|
||||
TString16 dastr, astr;
|
||||
dastr.format("%4d-%2d-%2d", _dadata.year(), _dadata.month(), _dadata.day());
|
||||
@ -675,7 +237,7 @@ bool THardy_movmag::trasferisci()
|
||||
|
||||
TString query =
|
||||
"SELECT * "
|
||||
"FROM dbo.MovContabiliT "
|
||||
"FROM dbo.MovMagazzinoT "
|
||||
"WHERE Esercizio=";
|
||||
query << _anno;
|
||||
query << " AND DataMovimento>= '";
|
||||
@ -685,95 +247,21 @@ bool THardy_movmag::trasferisci()
|
||||
query << "' ORDER BY DataMovimento ";
|
||||
|
||||
TRecordset& recset = create_recordset(query);
|
||||
|
||||
TString_array lista_campi;
|
||||
ini.list_variables(lista_campi, true, "MOV", true);
|
||||
|
||||
TFilename outdir;
|
||||
outdir = ini.get("PATH", "Main");
|
||||
TFilename listfiles = outdir; listfiles.add("ha*.ini");
|
||||
TString_array transactions;
|
||||
list_files(listfiles, transactions);
|
||||
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
||||
remove(*name);
|
||||
|
||||
_conf = NULL;
|
||||
long ntran = 1L;
|
||||
TString paragraph;
|
||||
|
||||
TMov_mag mov;
|
||||
TLocalisamfile movmag(LF_MOVMAG);
|
||||
THardy_iterator hi(this);
|
||||
while (++hi)
|
||||
{
|
||||
_kmovcont = recset.get("KMovconT").as_int(); // numero movimento testata
|
||||
if (_conf != NULL)
|
||||
delete _conf;
|
||||
_conf = NULL;
|
||||
TFilename temp(outdir);
|
||||
temp.add(format("ha%06ld", ntran++));
|
||||
temp.ext("ini");
|
||||
if (temp.exist())
|
||||
temp.fremove();
|
||||
_conf = new TConfig(temp);
|
||||
_conf->set_paragraph("Transaction");
|
||||
_conf->set("Action","INSERT");
|
||||
_conf->set("Mode", "AUTO");
|
||||
paragraph.format("%d",LF_MOV);
|
||||
_conf->set_paragraph(paragraph); // testata movimento
|
||||
aggiorna_ini(*_conf, lista_campi);
|
||||
TString codcaus = _conf->get(MOV_CODCAUS);
|
||||
if (cache().get(LF_CAUSALI, codcaus, CAU_MOVAP) == "C")
|
||||
{
|
||||
const TDate d(_conf->get(MOV_DATAREG));
|
||||
const TDate datacomp(31, 12, d.year() - 1);
|
||||
|
||||
_conf->set(MOV_DATACOMP, datacomp.string());
|
||||
}
|
||||
// verifica se è un mov. iva e nel caso aggiorna testata e array righe iva
|
||||
bool iva = test_moviva();
|
||||
// legge righe contabili e aggiorna array righe cont.
|
||||
test_movcont();
|
||||
// scrive RMOV e /o RMOVIVA a partire da array righe letti da db hardy
|
||||
bool ok = scrivi_righe();
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
ntran--;
|
||||
if (temp.exist())
|
||||
temp.fremove();
|
||||
TString msg;
|
||||
msg << (iva ? TR("Il movimento iva "): TR("Il movimento contabile ")) << _kmovcont
|
||||
<< TR(" ha generato un errore, non è stato convertito ");
|
||||
log(msg, 2); // Non uso log_error per non dare messaggi fuorvianti
|
||||
}
|
||||
#ifdef DBG
|
||||
else
|
||||
{
|
||||
TString msg;
|
||||
msg << (iva ? TR("Movimento iva "): TR("Movimento contabile ")) << _kmovcont
|
||||
<< TR(" generato nel file ") << temp;
|
||||
log(msg);
|
||||
}
|
||||
#endif
|
||||
_protocollo = recset.get("Protocollo").as_int(); // numero protocollo testata
|
||||
scrivi_testata(recset, mov);
|
||||
scrivi_righe(mov);
|
||||
mov.write(movmag);
|
||||
}
|
||||
if (_conf != NULL)
|
||||
delete _conf;
|
||||
show_log();
|
||||
if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran-1))
|
||||
{
|
||||
TString app;
|
||||
app << "cg2 -0 -i" << outdir << "/ha*.ini";
|
||||
TExternal_app primanota(app);
|
||||
primanota.run(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
THardy_movmag::THardy_movmag(const int anno, const TDate dadata, const TDate adata) : _anno(anno), _dadata(dadata), _adata(adata)
|
||||
{
|
||||
_righeiva = new TArray;
|
||||
_righecont = new TArray;
|
||||
_ivaind = new TAssoc_array;
|
||||
_ivaoma = new TAssoc_array;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
@ -826,7 +314,7 @@ void TConvMovMagHardy_mask::trasferisci()
|
||||
{
|
||||
THardy_log log;
|
||||
THardy_movmag pc(anno, dadata, adata);
|
||||
pc.init(TR("Movimenti contabili"), query_header, log);
|
||||
pc.init(TR("Movimenti di magazzino"), query_header, log);
|
||||
pc.trasferisci();
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ Item_01 = "Configurazione modulo", "ha0 -1", ""
|
||||
Item_02 = "Conversione anagrafiche", "hacnv -0 /uADMIN", "F"
|
||||
Item_03 = "Conversione movimenti", "hacnv -1 /uADMIN", "F"
|
||||
Item_04 = "Conversione scadenze", "hacnv -2 /uADMIN", "F"
|
||||
Item_05 = "Conversione movimenti magazzino", "hacnv -3 /uADMIN", "F"
|
||||
|
||||
[HAMENU_006]
|
||||
Caption = "Procedura Esselunga"
|
||||
|
Loading…
x
Reference in New Issue
Block a user