Patch level :
Files correlati : fe0.exe Ricompilazione Demo : [ ] Commento : Terminate (per ora) modifiche a gestione note di variazione git-svn-id: svn://10.65.10.50/branches/R_10_00@22434 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
ebc7983a16
commit
a3f110a82f
237
fe/fe0100.cpp
237
fe/fe0100.cpp
@ -1,6 +1,7 @@
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <defmask.h>
|
||||
#include <modaut.h>
|
||||
#include <progind.h>
|
||||
#include <recarray.h>
|
||||
#include <textset.h>
|
||||
@ -465,13 +466,13 @@ void TDati_rilevanti_trc::create_fields(int tipo, TAS400_recordset& recset)
|
||||
add_field( 2, 2,12,11, "Partita IVA", PI);
|
||||
add_field( 3,13,28,16, "Codice Fiscale", CF);
|
||||
add_field( 4,29,36, 8, "Data dell'operazione", DT, "", OBBLIG);
|
||||
add_field( 5,37,51,10, "Numero della Nota di Variazione", AN, "", OBBLIG);
|
||||
add_field( 5,37,51,15, "Numero della Nota di Variazione", AN, "", OBBLIG);
|
||||
add_field( 6,52,60, 9, "Imponibile Nota di Variazione", NU);
|
||||
add_field( 7,61,69, 9, "Imposta Nota di Variazione", NU);
|
||||
add_field( 8,70,77, 8, "Data della Fattura da rettificare", DT, "", OBBLIG);
|
||||
add_field( 9,78,92,15, "Numero della Fattura da rettificare", AN, "", OBBLIG);
|
||||
add_field(10,93,93, 9, "Variazione imponib. (Debito/Credito)",AN);
|
||||
add_field(11,94,94, 9, "Variazione imposta (Debito/Credito)", AN);
|
||||
add_field(10,93,93, 1, "Variazione imponib. (Debito/Credito)",AN);
|
||||
add_field(11,94,94, 1, "Variazione imposta (Debito/Credito)", AN);
|
||||
|
||||
add_field(11,95,1797,1703, "Filler", AN);
|
||||
add_field(12,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
||||
@ -495,8 +496,8 @@ void TDati_rilevanti_trc::create_fields(int tipo, TAS400_recordset& recset)
|
||||
add_field(15,274,282, 9, "Imposta Nota di Variazione", NU);
|
||||
add_field(16,283,290, 8, "Data della Fattura da rettificare", DT, "", OBBLIG);
|
||||
add_field(17,291,305,15, "Numero della Fattura da rettificare", AN, "", OBBLIG);
|
||||
add_field(18,306,306, 9, "Variazione imponib. (Debito/Credito)",AN);
|
||||
add_field(19,307,307, 9, "Variazione imposta (Debito/Credito)", AN);
|
||||
add_field(18,306,306, 1, "Variazione imponib. (Debito/Credito)",AN);
|
||||
add_field(19,307,307, 1, "Variazione imposta (Debito/Credito)", AN);
|
||||
|
||||
add_field(20,308,1797,1490, "Filler", AN);
|
||||
add_field(21,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
||||
@ -566,32 +567,32 @@ void TDati_rilevanti_set::add_control_rec(int zon, int num_inv, int tot_inv)
|
||||
|
||||
TString4 tipo; tipo << zon;
|
||||
new_rec(tipo);
|
||||
set(6, ditta.codice_fiscale());
|
||||
set(7, ditta.partita_IVA());
|
||||
set(7, ditta.codice_fiscale());
|
||||
set(8, ditta.partita_IVA());
|
||||
|
||||
if (ditta.giuridica())
|
||||
{
|
||||
TString den;
|
||||
set(8, ditta.ragione_sociale());
|
||||
set(9, ditta.comune_residenza());
|
||||
set(10, ditta.provincia_residenza());
|
||||
set( 9, ditta.ragione_sociale());
|
||||
set(10, ditta.comune_residenza());
|
||||
set(11, ditta.provincia_residenza());
|
||||
}
|
||||
else
|
||||
{
|
||||
set(11, ditta.cognome());
|
||||
set(12, ditta.nome());
|
||||
set(13, ditta.sesso());
|
||||
set(14, ditta.data_nascita());
|
||||
set(15, ditta.comune_nascita());
|
||||
set(16, ditta.provincia_nascita());
|
||||
set(12, ditta.cognome());
|
||||
set(13, ditta.nome());
|
||||
set(14, ditta.sesso());
|
||||
set(15, ditta.data_nascita());
|
||||
set(16, ditta.comune_nascita());
|
||||
set(17, ditta.provincia_nascita());
|
||||
}
|
||||
set(17, _anno);
|
||||
set(18, _anno);
|
||||
|
||||
if (tot_inv < 1) tot_inv = 1;
|
||||
if (num_inv <= 0) num_inv = 1;
|
||||
if (num_inv > tot_inv) num_inv = tot_inv;
|
||||
set(19, num_inv);
|
||||
set(20, tot_inv);
|
||||
set(20, num_inv);
|
||||
set(21, tot_inv);
|
||||
}
|
||||
|
||||
bool TDati_rilevanti_set::split(const TFilename& name, const TRecnotype maxalleg)
|
||||
@ -683,13 +684,14 @@ protected:
|
||||
TRecnotype nuovo_progr() const;
|
||||
bool check_rows(bool show_error);
|
||||
|
||||
bool send_nc(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
|
||||
bool send_nota_variazione(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
|
||||
bool send_fatt(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
|
||||
bool send_rec(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
|
||||
TExclusion_mode segnala_movimento(const TRectype& mov, TExclusion_mode motivo);
|
||||
bool is_nota_variazione(const TRectype& mov) const;
|
||||
real importo_limite(int anno) const;
|
||||
void elabora_note(const TArray& note, TFast_isamfile& falleg, long& nprog);
|
||||
long fattura_associata(long numreg_var) const;
|
||||
|
||||
public:
|
||||
TRecnotype genera_alleg();
|
||||
@ -800,21 +802,52 @@ TExclusion_mode TDati_rilevanti_msk::validate_mov(const TRectype& mov)
|
||||
|
||||
bool TDati_rilevanti_msk::is_nota_variazione(const TRectype& mov) const
|
||||
{
|
||||
const int tipomov = mov.get_int(MOV_TIPOMOV);
|
||||
if (tipomov == 2) // Nota di credito/debito per saldaconto
|
||||
return true;
|
||||
|
||||
const TString& tipodoc = mov.get(MOV_TIPODOC);
|
||||
if (tipodoc == "NC" || tipodoc == "ND") // Nota di credito/debito senza saldaconto
|
||||
return true;
|
||||
|
||||
const real totdoc = mov.get_real(MOV_TOTDOC);
|
||||
if (totdoc < ZERO)
|
||||
return true;
|
||||
|
||||
const int tipomov = mov.get_int(MOV_TIPOMOV);
|
||||
if (tipomov == 2)
|
||||
return true;
|
||||
|
||||
const TString& tipodoc = mov.get(MOV_TIPODOC);
|
||||
if (tipodoc == "NC" || tipodoc == "ND")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
long TDati_rilevanti_msk::fattura_associata(long numreg_var) const
|
||||
{
|
||||
long numreg_fatt = 0;
|
||||
if (main_app().has_module(SCAUT))
|
||||
{
|
||||
TLocalisamfile partite(LF_PARTITE);
|
||||
TRectype& part = partite.curr();
|
||||
partite.setkey(2);
|
||||
part.put(PART_NREG, numreg_var);
|
||||
part.put(PART_NUMRIG, 1);
|
||||
if (partite.read() == NOERR) // Ho trovato la partita ora cerco la fattura di riferimento
|
||||
{
|
||||
int nriga = part.get_int(PART_NRIGA);
|
||||
part.zero(PART_NRIGA); // Uso il record come chiave per leggere l'intera partita
|
||||
TRecord_array partita(part, PART_NRIGA);
|
||||
for (nriga = partita.pred_row(nriga); nriga >= 1; nriga = partita.pred_row(nriga))
|
||||
{
|
||||
const TRectype& riga = partita.row(nriga);
|
||||
const int tipomov = riga.get_int(PART_TIPOMOV);
|
||||
const long nreg_part = riga.get_long(PART_NREG);
|
||||
if (tipomov == 1 && nreg_part > 0) // Fattura
|
||||
{
|
||||
numreg_fatt = nreg_part;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return numreg_fatt;
|
||||
}
|
||||
|
||||
bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr,
|
||||
const real& importo, const real& imposta, int tipope)
|
||||
{
|
||||
@ -822,6 +855,7 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
|
||||
const int anno = mov.get_int(MOV_ANNOIVA);
|
||||
const long numreg_mov = mov.get_long(MOV_NUMREG);
|
||||
|
||||
const bool is_variazione = importo < ZERO || is_nota_variazione(mov);
|
||||
long num_fatt = 0; // Numero di registrazione rettificabile
|
||||
long num_rett = 0; // Numero di registrazione rettificata
|
||||
|
||||
@ -862,70 +896,39 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
|
||||
else
|
||||
{
|
||||
// Gestione note di credito
|
||||
if (importo < ZERO || is_nota_variazione(mov))
|
||||
if (is_variazione)
|
||||
{
|
||||
TLocalisamfile partite(LF_PARTITE);
|
||||
TRectype& part = partite.curr();
|
||||
partite.setkey(2);
|
||||
part.put(PART_NREG, numreg_mov);
|
||||
part.put(PART_NUMRIG, 1);
|
||||
if (partite.read() == NOERR) // Ho trovato la partita ora cerco la fattura di riferimento
|
||||
num_fatt = fattura_associata(numreg_mov);
|
||||
if (num_fatt > 0 && num_fatt < INVALID_NUMREG)
|
||||
{
|
||||
int nriga = part.get_int(PART_NRIGA);
|
||||
part.zero(PART_NRIGA); // Uso il record come chiave per leggere l'intera partita
|
||||
TRecord_array partita(part, PART_NRIGA);
|
||||
for (nriga = partita.pred_row(nriga); nriga >= 1; nriga = partita.pred_row(nriga))
|
||||
TLocalisamfile recset(LF_ALLEG);
|
||||
recset.setkey(3);
|
||||
recset.put(ALL_NUMREG, num_fatt);
|
||||
if (recset.read(_isgteq) == NOERR && recset.get_long(ALL_NUMREG) == num_fatt)
|
||||
{
|
||||
const TRectype& riga = partita.row(nriga);
|
||||
const int tipomov = riga.get_int(PART_TIPOMOV);
|
||||
const long nreg_part = riga.get_long(PART_NREG);
|
||||
if (tipomov == 1 && nreg_part > 0) // Fattura
|
||||
const TDate data_fatt = recset.get(ALL_DATAREG);
|
||||
const int anno_fatt = data_fatt.year();
|
||||
num_rett = num_fatt; // Memorizzo comunque il numero fattura da rettificare
|
||||
|
||||
if (anno_fatt == anno) // Se sono dello stesso anno vario la fattura e non registro la nota di variazione
|
||||
{
|
||||
num_fatt = nreg_part;
|
||||
|
||||
TLocalisamfile recset(LF_ALLEG);
|
||||
recset.setkey(3);
|
||||
recset.put(ALL_NUMREG, num_fatt);
|
||||
if (recset.read(_isgteq) == NOERR && recset.get_long(ALL_NUMREG) == num_fatt)
|
||||
update_existing_row = true;
|
||||
alleg = recset.curr();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (anno_fatt < 2010 || anno_fatt > anno)
|
||||
{
|
||||
const TDate data_fatt = riga.get(PART_DATAREG);
|
||||
const int anno_fatt = data_fatt.year();
|
||||
num_rett = num_fatt; // Memorizzo comunque il numero fattura da rettificare
|
||||
|
||||
if (anno_fatt == anno) // Se sono dello stesso anno vario la fattura e non registro la nota di variazione
|
||||
{
|
||||
update_existing_row = true;
|
||||
alleg = recset.curr();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (anno_fatt < 2010 || anno_fatt > anno)
|
||||
{
|
||||
num_rett = 0;
|
||||
_why = em_data_limite; // Non pertinente
|
||||
}
|
||||
else
|
||||
{
|
||||
// Variazione di fattura non rilevante
|
||||
if (_why == em_incluso && abs(importo) < importo_limite(anno))
|
||||
_why = em_importo_limite;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Variazione di fattura non rilevante
|
||||
if (_why == em_incluso && abs(importo) < importo_limite(anno))
|
||||
_why = em_importo_limite;
|
||||
num_rett = 0;
|
||||
_why = em_data_limite; // Non pertinente
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* tipocf = part.get_char(PART_TIPOCF) == 'F' ? TR("Fornitore") : TR("Cliente");
|
||||
const long codcf = part.get_long(PART_SOTTOCONTO);
|
||||
TString msg; msg.format(FR("%s %6ld - Nota di variazione %7ld "), tipocf, codcf, numreg_mov);
|
||||
const char* tipocf = mov.get_char(MOV_TIPO) == 'F' ? TR("Fornitore") : TR("Cliente");
|
||||
const long codcf = mov.get_long(MOV_CODCF);
|
||||
TString msg; msg.format(FR("%s %6ld - Nota di variazione %ld "), tipocf, codcf, numreg_mov);
|
||||
|
||||
if (num_rett > 0)
|
||||
{
|
||||
@ -938,16 +941,10 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num_fatt <= 0)
|
||||
{
|
||||
num_rett = INVALID_NUMREG;
|
||||
msg << TR("NON associata a nessuna fattura!");
|
||||
_log->log(1, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
num_rett = num_fatt;
|
||||
}
|
||||
// Variazione di fattura non rilevante: considero importo della variazione
|
||||
if (_why == em_incluso && abs(importo) < importo_limite(anno))
|
||||
_why = em_importo_limite;
|
||||
num_rett = INVALID_NUMREG;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1003,11 +1000,9 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
|
||||
_why = em_importo_limite; // Contratto inutile :-)
|
||||
}
|
||||
} else
|
||||
if (num_rett > 0)
|
||||
if (is_variazione)
|
||||
{
|
||||
alleg.put(ALL_NUMRETT, num_rett);
|
||||
if (num_rett >= INVALID_NUMREG && _why == em_incluso)
|
||||
_why = em_altro;
|
||||
}
|
||||
|
||||
alleg.put(ALL_IGNORA, int(_why));
|
||||
@ -1253,33 +1248,41 @@ bool TDati_rilevanti_msk::elabora_alleg()
|
||||
return prog > 1;
|
||||
}
|
||||
|
||||
bool TDati_rilevanti_msk::send_nc(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
|
||||
bool TDati_rilevanti_msk::send_nota_variazione(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
|
||||
{
|
||||
const long num_rett = alleg.get(ALL_NUMRETT).as_int();
|
||||
if (num_rett <= 0 || num_rett >= INVALID_NUMREG)
|
||||
return false;
|
||||
const TDate datareg = alleg.get(ALL_DATAREG).as_date();
|
||||
const long numreg = alleg.get(ALL_NUMREG).as_int();
|
||||
|
||||
TRectype rec_fatt(LF_MOV);
|
||||
TRectype rec_nota(LF_MOV);
|
||||
TDate data_fatt(31, 12, datareg.year());
|
||||
TString16 num_fatt;
|
||||
|
||||
TLocalisamfile mov(LF_MOV);
|
||||
mov.put(MOV_NUMREG, num_rett);
|
||||
if (mov.read() == NOERR)
|
||||
rec_fatt = mov.curr();
|
||||
else
|
||||
return false;
|
||||
TRectype& rec_nota = mov.curr();
|
||||
|
||||
const long num_rett = alleg.get(ALL_NUMRETT).as_int();
|
||||
if (num_rett > 0 && num_rett < INVALID_NUMREG)
|
||||
{
|
||||
mov.put(MOV_NUMREG, num_rett);
|
||||
if (mov.read() == NOERR)
|
||||
{
|
||||
data_fatt = mov.get(MOV_DATAREG);
|
||||
num_fatt = mov.get(MOV_NUMDOC);
|
||||
}
|
||||
}
|
||||
|
||||
const long numreg = alleg.get(ALL_NUMREG).as_int();
|
||||
mov.put(MOV_NUMREG, numreg);
|
||||
if (mov.read() == NOERR)
|
||||
rec_nota = mov.curr();
|
||||
if (mov.read() != NOERR)
|
||||
{
|
||||
CHECKD(false, "Registrazione fantasma ", numreg);
|
||||
return false;
|
||||
}
|
||||
|
||||
const TAnagrafica anag(alleg.cursor()->curr());
|
||||
|
||||
real imponibile = alleg.get(ALL_IMPORTO).as_real();
|
||||
real imposta = alleg.get(ALL_IMPOSTA).as_real();
|
||||
|
||||
const char tipocf = rec_fatt.get_char(MOV_TIPO);
|
||||
const char tipocf = rec_nota.get_char(MOV_TIPO);
|
||||
char segno_imponibile = tipocf == 'C' ? 'D' : 'C'; // Normalmente sono negative e quindi a debito del dichiarante
|
||||
char segno_imposta = segno_imponibile;
|
||||
|
||||
@ -1311,12 +1314,12 @@ bool TDati_rilevanti_msk::send_nc(const TISAM_recordset& alleg, TDati_rilevanti_
|
||||
operaz.set(10, anag.stato_estero());
|
||||
operaz.set(11, EMPTY_STRING); // TBI? Indirizzo estero
|
||||
}
|
||||
operaz.set(12, alleg.get(ALL_DATAREG));
|
||||
operaz.set(12, datareg);
|
||||
operaz.set(13, rec_nota.get(MOV_NUMDOC).left(15));
|
||||
operaz.set(14, imponibile);
|
||||
operaz.set(15, imposta);
|
||||
operaz.set(16, rec_fatt.get_date(MOV_DATAREG));
|
||||
operaz.set(17, rec_fatt.get(MOV_NUMDOC).left(15));
|
||||
operaz.set(16, data_fatt);
|
||||
operaz.set(17, num_fatt);
|
||||
operaz.set(18, segno_imponibile);
|
||||
operaz.set(19, segno_imposta);
|
||||
}
|
||||
@ -1328,12 +1331,12 @@ bool TDati_rilevanti_msk::send_nc(const TISAM_recordset& alleg, TDati_rilevanti_
|
||||
else
|
||||
operaz.set(3, anag.codice_fiscale());
|
||||
|
||||
operaz.set(4, alleg.get(ALL_DATAREG));
|
||||
operaz.set(4, datareg);
|
||||
operaz.set(5, rec_nota.get(MOV_NUMDOC).left(15));
|
||||
operaz.set(6, imponibile);
|
||||
operaz.set(7, imposta);
|
||||
operaz.set(8, rec_fatt.get_date(MOV_DATAREG));
|
||||
operaz.set(9, rec_fatt.get(MOV_NUMDOC).left(15));
|
||||
operaz.set(8, data_fatt);
|
||||
operaz.set(9, num_fatt);
|
||||
operaz.set(10, segno_imponibile);
|
||||
operaz.set(11, segno_imposta);
|
||||
}
|
||||
@ -1420,7 +1423,7 @@ bool TDati_rilevanti_msk::send_fatt(const TISAM_recordset& alleg, TDati_rilevant
|
||||
bool TDati_rilevanti_msk::send_rec(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
|
||||
{
|
||||
const long numrett = alleg.get(ALL_NUMRETT).as_int();
|
||||
return numrett > 0 ? send_nc(alleg, operaz) : send_fatt(alleg, operaz);
|
||||
return numrett > 0 ? send_nota_variazione(alleg, operaz) : send_fatt(alleg, operaz);
|
||||
}
|
||||
|
||||
// Genera file per invio telematico
|
||||
|
Loading…
x
Reference in New Issue
Block a user