2007-03-06 13:59:25 +00:00
|
|
|
#include "cg3.h"
|
2007-09-17 15:33:04 +00:00
|
|
|
#include "cg2103.h"
|
2007-03-06 13:59:25 +00:00
|
|
|
#include "cg3900a.h"
|
|
|
|
|
|
|
|
#include <applicat.h>
|
|
|
|
#include <automask.h>
|
|
|
|
#include <defmask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <recarray.h>
|
|
|
|
#include <reprint.h>
|
2007-03-30 13:51:17 +00:00
|
|
|
#include <reputils.h>
|
2007-03-06 13:59:25 +00:00
|
|
|
#include <textset.h>
|
2007-03-30 13:51:17 +00:00
|
|
|
#include <validate.h>
|
2008-03-11 16:48:19 +00:00
|
|
|
#include <utility.h>
|
2007-03-06 13:59:25 +00:00
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
#include <anafis.h>
|
|
|
|
#include <anagr.h>
|
|
|
|
#include <anagiu.h>
|
2007-03-06 13:59:25 +00:00
|
|
|
#include <causali.h>
|
|
|
|
#include <clifo.h>
|
|
|
|
#include <comuni.h>
|
|
|
|
#include <mov.h>
|
2007-03-30 13:51:17 +00:00
|
|
|
#include <nditte.h>
|
2007-09-17 15:33:04 +00:00
|
|
|
#include <occas.h>
|
2007-03-06 13:59:25 +00:00
|
|
|
#include <rmoviva.h>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAllegato_info
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct TAllegato_importi : public TObject
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
real _imp, _iva; // Imponibile ed imposta
|
|
|
|
real _impNI, _impES, _ivaNE; // Non imponibili, esenti, Non esposti
|
|
|
|
real _ind; // Valore indecifrabile valido solo per i fornitori fino al 2008
|
|
|
|
real _impNA; // Pattumiera per tutti valori NON in allegato
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
bool is_not_null(bool strict) const;
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
bool TAllegato_importi::is_not_null(bool strict) const
|
|
|
|
{
|
|
|
|
if (!strict && !_impNA.is_zero())
|
|
|
|
return true;
|
|
|
|
return !(_imp.is_zero() && _iva.is_zero() && _ind.is_zero() &&
|
|
|
|
_impNI.is_zero() && _impES.is_zero() && _ivaNE.is_zero());
|
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
class TAllegato_info : public TObject
|
|
|
|
{
|
|
|
|
char _tipo;
|
|
|
|
long _codice;
|
2007-09-17 15:33:04 +00:00
|
|
|
TString80 _occas; // Eventuale codice cliente occasionale
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
TAllegato_importi _curr, _prec;
|
|
|
|
|
|
|
|
public:
|
2007-09-17 15:33:04 +00:00
|
|
|
bool occasionale() const { return _tipo == 'C' && _occas.full(); }
|
2007-03-06 13:59:25 +00:00
|
|
|
char tipo() const { return _tipo; }
|
2007-10-08 13:57:37 +00:00
|
|
|
long codice() const { return _codice; }
|
|
|
|
const TString & occas_code() const { return _occas;}
|
2007-09-17 15:33:04 +00:00
|
|
|
TVariant get(const TString& field) const;
|
|
|
|
void key(TString& str) const;
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
TAllegato_importi& importi(bool prec) { return prec ? _prec : _curr; }
|
|
|
|
const TAllegato_importi& importi(bool prec) const { return prec ? _prec : _curr; }
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
bool is_not_null(bool strict) const { return _curr.is_not_null(strict) || _prec.is_not_null(strict); }
|
2007-10-08 13:57:37 +00:00
|
|
|
void set_codice(long codice, const char* occas) { _codice = codice; _occas = occas; }
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TAllegato_info(const TRecordset& mov);
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Legge un campo dal record virtuale del cliente / fornitore
|
|
|
|
TVariant TAllegato_info::get(const TString& field) const
|
|
|
|
{
|
|
|
|
TVariant var;
|
|
|
|
|
|
|
|
if (field.starts_with("C_") || field.starts_with("P_"))
|
|
|
|
{
|
|
|
|
const bool anno_prec = field[0] == 'P';
|
|
|
|
const TAllegato_importi& allimp = importi(anno_prec);
|
|
|
|
if (allimp.is_not_null(false))
|
|
|
|
{
|
|
|
|
const TString& impfield = field.mid(2);
|
|
|
|
real euro;
|
|
|
|
if (impfield == "IMP")
|
|
|
|
euro = allimp._imp; else
|
|
|
|
if (impfield == "IVA")
|
|
|
|
euro = allimp._iva; else
|
|
|
|
if (impfield == "NI")
|
|
|
|
euro = allimp._impNI; else
|
|
|
|
if (impfield == "ES")
|
|
|
|
euro = allimp._impES; else
|
|
|
|
if (impfield == "NE")
|
|
|
|
euro = allimp._ivaNE; else
|
|
|
|
if (impfield == "IND")
|
|
|
|
euro = allimp._ind; else
|
|
|
|
if (impfield == "NA")
|
|
|
|
euro = allimp._impNA;
|
|
|
|
euro.round(0);
|
|
|
|
var = euro;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (field == CLI_TIPOCF)
|
|
|
|
{
|
|
|
|
const char t[2] = { _tipo, '\0' };
|
|
|
|
var = t;
|
|
|
|
} else
|
|
|
|
if (field == CLI_CODCF)
|
|
|
|
{
|
|
|
|
var = _codice;
|
|
|
|
} else
|
|
|
|
if (field == COM_DENCOM || field == COM_PROVCOM)
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
TToken_string key;
|
|
|
|
key << get(CLI_STATOCF);
|
|
|
|
const bool italy = key.blank() || key == "IT";
|
|
|
|
key << '|' << get(CLI_COMCF);
|
2007-09-17 15:33:04 +00:00
|
|
|
var = cache().get(LF_COMUNI, key, field);
|
2008-03-11 16:48:19 +00:00
|
|
|
if (var.is_empty() && italy) // Ritento col CAP per gli Italiani
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
key = " |";
|
|
|
|
key << cap2comune(get(CLI_CAPCF).as_string(), get(CLI_LOCCF).as_string());
|
|
|
|
var = cache().get(LF_COMUNI, key, field);
|
|
|
|
}
|
2008-03-11 16:48:19 +00:00
|
|
|
if (var.is_empty() && field == COM_PROVCOM)
|
|
|
|
{
|
|
|
|
if (!italy || key.get_char(1) == 'Z')
|
|
|
|
var = "EE";
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (occasionale())
|
|
|
|
{
|
|
|
|
const TRectype& occas = cache().get(LF_OCCAS, _occas);
|
|
|
|
|
|
|
|
// Tratto a parte COFI e PAIV degli occasionali
|
|
|
|
if (field == CLI_COFI || field == CLI_PAIV)
|
|
|
|
{
|
|
|
|
// Questi campi sono nel tracciato solo dalla versione 3.1 in poi
|
|
|
|
if (occas.type(field) != _nullfld)
|
|
|
|
var = occas.get(field);
|
|
|
|
|
|
|
|
/* Troppo astuto per "Sirio il Dragone"
|
|
|
|
// Se non compilato cerco di desumerlo da codice occasionale
|
|
|
|
if (var.is_empty())
|
|
|
|
{
|
|
|
|
if (field == CLI_COFI)
|
|
|
|
{
|
|
|
|
if (cf_check("", _occas))
|
|
|
|
var = _occas;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pi_check("", _occas))
|
|
|
|
var = _occas;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else // Tutti gli altri campi a parte COFI e PAIV
|
|
|
|
{
|
|
|
|
// Converto opportunamente il nome del campo da CLIFO ad OCCAS
|
|
|
|
const char* const cli[] = { CLI_RAGSOC, CLI_STATOCF, CLI_COMCF, CLI_STATOPAIV,
|
|
|
|
CLI_INDCF, CLI_CAPCF, CLI_LOCCF, NULL, };
|
|
|
|
const char* const occ[] = { OCC_RAGSOC, OCC_STATO, OCC_COM, OCC_STATO,
|
|
|
|
OCC_INDIR, OCC_CAP, OCC_LOCALITA, NULL, };
|
|
|
|
for (int f = 0; cli[f]; f++)
|
|
|
|
{
|
|
|
|
if (field == cli[f])
|
|
|
|
{
|
|
|
|
var = occas.get(occ[f]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Clienti/Fornitori "normali" (non occasionali)
|
|
|
|
{
|
|
|
|
TString16 key; key.format("%c|%ld", _tipo, _codice);
|
|
|
|
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
|
|
|
var = clifo.get(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAllegato_info::key(TString& tmp) const
|
|
|
|
{
|
|
|
|
tmp = get(CLI_PAIV).as_string();
|
|
|
|
if (tmp.blank())
|
|
|
|
{
|
|
|
|
tmp = get(CLI_COFI).as_string();
|
|
|
|
if (tmp.blank())
|
2008-03-11 16:48:19 +00:00
|
|
|
tmp.cut(0) << _codice;
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
|
|
|
tmp.insert(_tipo == 'F' ? "F|" : "C|");
|
|
|
|
}
|
|
|
|
|
|
|
|
TAllegato_info::TAllegato_info(const TRecordset& mov)
|
|
|
|
: _tipo(mov.get(MOV_TIPO).as_string()[0]),
|
|
|
|
_codice(mov.get(MOV_CODCF).as_int()),
|
|
|
|
_occas(mov.get(MOV_OCFPI).as_string())
|
|
|
|
{
|
|
|
|
CHECK(_tipo == 'C' || _tipo == 'F', "Tipo C/F errato");
|
|
|
|
CHECKD(_codice > 0, "Codice C/F errato ", _codice);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAllegati_set
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAllegati_set : public TAS400_recordset
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const TString& comune(const TRectype& clifo, const char* field) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void add(const TAllegato_info& info);
|
|
|
|
TAllegati_set();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TAllegati_set::add(const TAllegato_info& info)
|
|
|
|
{
|
|
|
|
new_rec();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < columns(); i++)
|
|
|
|
{
|
2007-03-07 11:02:06 +00:00
|
|
|
const TString& field = column_info(i)._name;
|
2007-09-17 15:33:04 +00:00
|
|
|
set(field, info.get(field));
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TAllegati_set::TAllegati_set()
|
|
|
|
: TAS400_recordset("AS400(512)")
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const char* const campi[] = { CLI_TIPOCF, CLI_CODCF, CLI_RAGSOC, CLI_COFI, CLI_PAIV,
|
|
|
|
CLI_INDCF, CLI_CIVCF, CLI_CAPCF, CLI_LOCCF, CLI_COMCF,
|
|
|
|
NULL };
|
2007-03-06 13:59:25 +00:00
|
|
|
TRectype clifo(LF_CLIFO);
|
|
|
|
for (int i = 0; campi[i]; i++)
|
|
|
|
{
|
|
|
|
const char* f = campi[i];
|
|
|
|
create_field(f, -1, clifo.length(f), clifo.type(f));
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
create_field(COM_DENCOM, -1, 50, _alfafld);
|
|
|
|
create_field(COM_PROVCOM, -1, 2, _alfafld);
|
2007-03-06 13:59:25 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 2; j++)
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
create_field(j ? "P_IMP" : "C_IMP", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_IVA" : "C_IVA", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_IND" : "C_IND", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_NI" : "C_NI", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_ES" : "C_ES", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_NE" : "C_NE", -1, 16, _longfld);
|
|
|
|
create_field(j ? "P_NA" : "C_NA", -1, 16, _longfld);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPadoaSchioppa_set
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
enum TPs_type { AN, CF, DT, NU, PI, PR };
|
|
|
|
enum TPs_campi_non_posizionali { npCode = 8, npValue = 16, npSize = 24, npCount = 70 };
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
class TPadoaSchioppa_set : public TAS400_recordset
|
|
|
|
{
|
|
|
|
void add_field(const int trc, int da, int a, int lung, const char* name,
|
2007-09-17 15:33:04 +00:00
|
|
|
TPs_type ft, bool required = false, const char* def = NULL);
|
2007-03-30 13:51:17 +00:00
|
|
|
void add_trc(int trc);
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
protected:
|
2008-03-11 16:48:19 +00:00
|
|
|
int primo_campo_libero(); // Posizione primo campo libero per record 1 e 2
|
|
|
|
void init_trc(); // Constructor helper
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
public:
|
|
|
|
long new_rec(int tiporec); // 0, 1, 2, 3, 9, -1 (1 o 2 a seconda del tipo corrente)
|
|
|
|
const TString& curr_row() const { return row(-1); }
|
|
|
|
|
|
|
|
// Campi posizionali (record 0, 3 e 9)
|
|
|
|
bool set(const char* name, const TVariant& value);
|
|
|
|
bool set(const char* name, const TString& value);
|
|
|
|
bool set(const char* name, const TDate& value);
|
|
|
|
|
|
|
|
// Campi non posizionali (record 1 e 2)
|
|
|
|
bool set(int fldcode, const TString& val);
|
|
|
|
bool set(int fldcode, long val);
|
|
|
|
bool set(int fldcode, const TVariant& val);
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
TPadoaSchioppa_set();
|
2008-03-11 16:48:19 +00:00
|
|
|
TPadoaSchioppa_set(const TFilename& name);
|
2007-03-30 13:51:17 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
long TPadoaSchioppa_set::new_rec(int tiporec)
|
|
|
|
{
|
|
|
|
if (tiporec < 0)
|
|
|
|
{
|
|
|
|
tiporec = atoi(rec_type());
|
|
|
|
CHECKD(tiporec == 1 || tiporec == 2, "Tipo record non duplicabile ", tiporec);
|
|
|
|
}
|
|
|
|
CHECKD(tiporec >= 0 && tiporec <= 3 || tiporec == 9, "Tipo record errato ", tiporec);
|
|
|
|
char tr[2] = { '0'+tiporec, '\0' };
|
|
|
|
return TAS400_recordset::new_rec(tr);
|
|
|
|
}
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
void TPadoaSchioppa_set::add_field(int trc, int da, int a, int lung, const char* name,
|
2007-09-17 15:33:04 +00:00
|
|
|
TPs_type tc, bool required, const char* def)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
|
|
|
CHECKS(da > 0 && a >= da, "Posizioni incoerenti sul campo ", name);
|
|
|
|
CHECKS(lung == a-da+1, "Lunghezza incoerente sul campo ", name);
|
|
|
|
|
|
|
|
TString80 field; field.format("%d.%s", trc, (const char*)name);
|
2007-09-17 15:33:04 +00:00
|
|
|
TFieldtypes ft = _alfafld;
|
|
|
|
switch (tc)
|
|
|
|
{
|
|
|
|
case DT:
|
|
|
|
CHECKS(lung == 8, "Lunghezza incoerente data ", name);
|
|
|
|
ft = _longzerofld;
|
|
|
|
break;
|
|
|
|
case NU:
|
|
|
|
ft = _longfld;
|
|
|
|
break;
|
|
|
|
case CF:
|
|
|
|
CHECKS(lung == 16, "Lunghezza incoerente codice fiscale ", name);
|
|
|
|
ft = _alfafld;
|
|
|
|
break;
|
|
|
|
case PI:
|
|
|
|
CHECKS(lung == 11, "Lunghezza incoerente partita IVA ", name);
|
|
|
|
ft = _longzerofld;
|
|
|
|
break;
|
|
|
|
case PR:
|
|
|
|
CHECKS(lung == 2, "Lunghezza incoerente provincia ", name);
|
|
|
|
ft = _alfafld;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ft = _alfafld;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
bool ok = false;
|
|
|
|
if (def && *def)
|
|
|
|
ok = create_field(field, da-1, lung, ft, required, TVariant(def));
|
|
|
|
else
|
|
|
|
ok = create_field(field, da-1, lung, ft, required);
|
|
|
|
CHECKS(ok, "Impossibile creare il campo ", (const char*)field);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPadoaSchioppa_set::add_trc(int trc)
|
|
|
|
{
|
|
|
|
TString4 str; str << trc;
|
|
|
|
add_field(trc, 1, 1, 1, "TipoRecord", NU, true, str);
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
switch (trc)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
case 0: // Testata
|
|
|
|
case 9: // Coda
|
2007-09-28 08:37:07 +00:00
|
|
|
add_field(trc, 2, 4, 3, "IndentificativoFornitura", AN, true, "ECF");
|
2008-03-11 16:48:19 +00:00
|
|
|
add_field(trc, 5, 6, 2, "IdentificativoAnno" , NU, true, "00");
|
2007-09-28 08:37:07 +00:00
|
|
|
add_field(trc, 7, 8, 2, "CodiceFornitura" , NU, true, "38");
|
|
|
|
add_field(trc, 9, 24, 16, "CodiceFiscale" , CF, true);
|
|
|
|
add_field(trc, 25, 35, 11, "PartitaIVA" , PI, true);
|
|
|
|
add_field(trc, 36, 61, 26, "Cognome" , AN); // Persone fisiche
|
|
|
|
add_field(trc, 62, 86, 25, "Nome" , AN);
|
|
|
|
add_field(trc, 87, 87, 1, "Sesso" , AN);
|
|
|
|
add_field(trc, 88, 95, 8, "DataNascita" , DT);
|
|
|
|
add_field(trc, 96, 135, 40, "ComuneNascita" , AN);
|
|
|
|
add_field(trc, 136, 137, 2, "ProvinciaNascita" , PR);
|
|
|
|
add_field(trc, 138, 207, 70, "Denominazione" , AN); // Persone NON fisiche
|
|
|
|
add_field(trc, 208, 247, 40, "ComuneSedeLegale" , AN);
|
|
|
|
add_field(trc, 248, 249, 2, "ProvinciaSedeLegale" , AN);
|
|
|
|
add_field(trc, 250, 265, 16, "CodiceSoggettoObbligato" , CF);
|
|
|
|
add_field(trc, 266, 269, 4, "AnnoRiferimento" , NU, true);
|
|
|
|
add_field(trc, 270, 273, 4, "ProgressivoTelematico" , NU);
|
|
|
|
add_field(trc, 274, 277, 4, "NumeroTotaleInvii" , NU);
|
|
|
|
add_field(trc, 278, 293, 16, "CodiceIntermediario" , CF);
|
|
|
|
add_field(trc, 294, 298, 5, "NumeroIscrizioneAlboCAF" , NU);
|
|
|
|
add_field(trc, 299, 299, 1, "ImpegnoAllaTrasmissione" , NU);
|
|
|
|
add_field(trc, 300, 307, 8, "DataImpegno" , DT);
|
2007-09-17 15:33:04 +00:00
|
|
|
break;
|
|
|
|
case 1: // Clienti
|
|
|
|
case 2: // Fornitori
|
|
|
|
// NESSUN CAMPO POSIZIONALE!
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
add_field(trc, 2, 9, 8, "Clienti" , NU); // 2
|
|
|
|
add_field(trc, 10, 17, 8, "Fornitori" , NU);
|
|
|
|
add_field(trc, 18, 37, 20, "CL004001" , NU); // 4
|
|
|
|
add_field(trc, 38, 57, 20, "CL004002" , NU);
|
|
|
|
add_field(trc, 58, 77, 20, "CL005001" , NU);
|
|
|
|
add_field(trc, 78, 97, 20, "CL006001" , NU);
|
|
|
|
add_field(trc, 98, 117, 20, "CL007001" , NU);
|
|
|
|
add_field(trc, 118, 137, 20, "CL008001" , NU); // 9
|
|
|
|
add_field(trc, 138, 157, 20, "CL008002" , NU);
|
|
|
|
add_field(trc, 158, 177, 20, "CL009001" , NU);
|
|
|
|
add_field(trc, 178, 197, 20, "CL010001" , NU);
|
|
|
|
add_field(trc, 198, 217, 20, "CL011001" , NU); // 13
|
|
|
|
add_field(trc, 218, 237, 20, "FR004001" , NU); // 14
|
|
|
|
add_field(trc, 238, 257, 20, "FR004002" , NU);
|
|
|
|
add_field(trc, 258, 277, 20, "FR005001" , NU);
|
|
|
|
add_field(trc, 278, 297, 20, "FR006001" , NU);
|
|
|
|
add_field(trc, 298, 317, 20, "FR007001" , NU);
|
|
|
|
add_field(trc, 318, 337, 20, "FR008001" , NU);
|
|
|
|
add_field(trc, 338, 357, 20, "FR009001" , NU); // 20
|
|
|
|
add_field(trc, 358, 377, 20, "FR009002" , NU);
|
|
|
|
add_field(trc, 378, 397, 20, "FR010001" , NU);
|
|
|
|
add_field(trc, 398, 417, 20, "FR011001" , NU);
|
|
|
|
add_field(trc, 418, 437, 20, "FR012001" , NU);
|
|
|
|
add_field(trc, 438, 457, 20, "FR013001" , NU); // 25
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CHECKD(false, "Tipo record non valido ", trc);
|
|
|
|
break;
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
add_field(trc,1798,1798, 1, "CarattereControllo" , AN, true, "A");
|
2007-09-17 15:33:04 +00:00
|
|
|
add_field(trc,1799,1800, 2, "FineRiga" , AN, true, "\r\n"); // 0D 0A
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
int TPadoaSchioppa_set::primo_campo_libero()
|
|
|
|
{
|
|
|
|
const TToken_string& curr = row(-1); // Record corrente
|
|
|
|
int i = 0, pos = 1;
|
|
|
|
for (i = 0; i < npCount; i++, pos += npSize) // Scandice i 70 campi non posizionali
|
|
|
|
{
|
|
|
|
// if (curr.mid(pos, fld_size).blank())
|
|
|
|
if (curr[pos] == ' ' && curr[pos+npSize-1] == ' ') // Campo vuoto!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= npCount) // Non c'e' piu' posto!
|
|
|
|
{
|
|
|
|
new_rec(-1); // Creo un nuovo record del tipo corrente (1 o 2)
|
|
|
|
pos = 1; // Vado a colpo "sicuro"
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPadoaSchioppa_set::set(const char* name, const TVariant& value)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
|
|
|
bool ok = false;
|
2007-09-17 15:33:04 +00:00
|
|
|
const int tiporec = atoi(rec_type());
|
|
|
|
if (tiporec == 1 || tiporec == 2) // Gestione campi non posizionali
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
CHECKS(name!=NULL && strlen(name) == npCode,
|
|
|
|
"Lunghezza nome campo non posizionale errata ", name);
|
|
|
|
CHECKS((tiporec==1 && *name=='C') || (tiporec==2 && *name=='F'),
|
|
|
|
"Campo non posizionale incompatibile col tipo record (1/2=C/F) ", name);
|
|
|
|
const long codice = atol(name+2);
|
|
|
|
CHECKS(codice >= 1001 && codice <= 13001, "Campo non posizionale errato ", name);
|
|
|
|
if (value.is_empty())
|
|
|
|
{
|
|
|
|
ok = codice > 4000;
|
|
|
|
CHECKS(ok, "Campo obbligatorio non specificato ", name);
|
|
|
|
return ok;
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const int pos = primo_campo_libero();
|
|
|
|
TString80 str = name;
|
|
|
|
if (codice < 4000) // Campi alfanumerici (1001,2001,3001) allineati a sinistra
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
str << value.as_string();
|
|
|
|
str.rpad(npSize);
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
else
|
2007-09-17 15:33:04 +00:00
|
|
|
{ // Importi interi allineati a destra
|
|
|
|
real r = value.as_real();
|
|
|
|
r.round(0); // Inutile in quanto gia' arrotondato all'origine: ma non si sa mai
|
|
|
|
str << r.string(npValue, 0);
|
|
|
|
}
|
|
|
|
CHECKS(str.len() == npSize, "Lunghezza campo non posizionale codice(8)+valore(16) <> 24 ", (const char*)str);
|
|
|
|
row(-1).overwrite(str, pos, npSize);
|
|
|
|
ok = true;
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// Gestisco le date solo nei record 0,3,9
|
2007-03-30 13:51:17 +00:00
|
|
|
if (value.is_date() && !value.is_empty())
|
|
|
|
{
|
|
|
|
const TDate date = value.as_date();
|
|
|
|
TString8 str;
|
|
|
|
str.format("%02d%02d%04d", date.day(), date.month(), date.year());
|
|
|
|
ok = TAS400_recordset::set(name, TVariant(str));
|
|
|
|
}
|
|
|
|
else
|
2007-09-27 15:32:02 +00:00
|
|
|
{
|
|
|
|
if (value.is_string())
|
|
|
|
{
|
|
|
|
TString80 str = value.as_string();
|
|
|
|
str.upper();
|
|
|
|
ok = TAS400_recordset::set(name, TVariant(str));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = TAS400_recordset::set(name, value);
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
CHECKS(ok, "Campo non valido ", name);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
bool TPadoaSchioppa_set::set(const char* name, const TString& value)
|
|
|
|
{
|
|
|
|
return set(name, value.full() ? TVariant(value) : NULL_VARIANT);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPadoaSchioppa_set::set(const char* name, const TDate& value)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return set(name, value.ok() ? TVariant(value) : NULL_VARIANT);
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Usata per 1001, 2001 e 3001
|
|
|
|
bool TPadoaSchioppa_set::set(int fldcode, const TString& val)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
CHECKD(fldcode >= 1001 && fldcode <= 3001, "Codice campo non valido ", fldcode);
|
2007-09-17 15:33:04 +00:00
|
|
|
CHECKD(val.full(), "Campo non posizionale vuoto ", fldcode);
|
|
|
|
|
|
|
|
const int tiporec = atoi(rec_type());
|
|
|
|
|
|
|
|
TString8 field;
|
|
|
|
field.format("%2s%06d", tiporec == 1 ? "CL" : "FR", fldcode);
|
|
|
|
return set(field, val);
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Usata solo per 1001
|
|
|
|
bool TPadoaSchioppa_set::set(int fldcode, long val)
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
CHECKD(fldcode == 1001, "Codice campo non valido ", fldcode);
|
2007-09-17 15:33:04 +00:00
|
|
|
CHECKD(val > 0, "Campo non posizionale vuoto ", fldcode);
|
|
|
|
TString16 value;
|
|
|
|
value.format("%16ld", val);
|
|
|
|
return set(fldcode, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Usata dal 4001 in poi
|
|
|
|
bool TPadoaSchioppa_set::set(int fldcode, const TVariant& val)
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
CHECKD(fldcode >= 4001 && fldcode <= 13001, "Codice campo non valido ", fldcode);
|
2007-09-17 15:33:04 +00:00
|
|
|
if (val.is_zero())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const int tiporec = atoi(rec_type());
|
|
|
|
TString8 field;
|
|
|
|
field.format("%2s%06d", tiporec == 1 ? "CL" : "FR", fldcode);
|
|
|
|
return set(field, val);
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
void TPadoaSchioppa_set::init_trc()
|
|
|
|
{
|
|
|
|
add_trc(0);
|
|
|
|
add_trc(1);
|
|
|
|
add_trc(2);
|
|
|
|
add_trc(3);
|
|
|
|
add_trc(9);
|
|
|
|
}
|
|
|
|
|
|
|
|
TPadoaSchioppa_set::TPadoaSchioppa_set()
|
|
|
|
: TAS400_recordset("AS400(1800,1)")
|
|
|
|
{
|
|
|
|
init_trc();
|
|
|
|
}
|
|
|
|
|
|
|
|
TPadoaSchioppa_set::TPadoaSchioppa_set(const TFilename& name)
|
|
|
|
: TAS400_recordset("AS400(1800,1)")
|
|
|
|
{
|
|
|
|
init_trc();
|
|
|
|
load_file(name);
|
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
2007-09-17 15:33:04 +00:00
|
|
|
// TCodiva_cache
|
2007-03-06 13:59:25 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
class TCodiva_cache : public TCache
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
|
|
|
public:
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCodiceIVA& codiva(const char* codice);
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TObject* TCodiva_cache::key2obj(const char* key)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return new TCodiceIVA(key);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCodiceIVA& TCodiva_cache::codiva(const char* codice)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return *(TCodiceIVA*)objptr(codice);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2007-09-17 15:33:04 +00:00
|
|
|
// TCusali_cache
|
2007-03-06 13:59:25 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
class TCausali_cache : public TCache
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
|
|
|
public:
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCausale& causale(const char* codice, int annoiva);
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TObject* TCausali_cache::key2obj(const char* key)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// Metodo bastardo per evitare TToken_string temporanee "a randa"
|
|
|
|
// sfrutto chiave a lunghezza fissa
|
|
|
|
const int anno = atoi(key);
|
|
|
|
const char* codice = key+5;
|
|
|
|
TCausale* pcaus = new TCausale(codice, anno);
|
|
|
|
return pcaus;
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCausale& TCausali_cache::causale(const char* codice, int annoiva)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// Metodo bastardo per evitare TToken_string temporanee "a randa"
|
|
|
|
// creo chiave a lunghezza fissa anno+codice = 9999|AAA
|
|
|
|
TString8 key;
|
|
|
|
key.format("%04d|%s", annoiva, codice);
|
|
|
|
return *(const TCausale*)objptr(key);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAlleg_report
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAlleg_report : public TReport
|
|
|
|
{
|
2007-10-08 13:57:37 +00:00
|
|
|
TAssoc_array _vars;
|
2007-03-06 13:59:25 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool use_mask() { return false; }
|
2007-10-08 13:57:37 +00:00
|
|
|
virtual bool set_usr_val(const TString& name, const TVariant& var);
|
2007-03-06 13:59:25 +00:00
|
|
|
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
|
|
|
|
|
|
|
public:
|
2007-10-08 13:57:37 +00:00
|
|
|
TAlleg_report(TRecordset* rs, const TMask& am, bool hide_not_alleg = false);
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
2007-10-08 13:57:37 +00:00
|
|
|
bool TAlleg_report::set_usr_val(const TString& name, const TVariant& var)
|
|
|
|
{
|
|
|
|
if (!TReport::set_usr_val(name, var))
|
|
|
|
_vars.add(name, new TVariant(var));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
bool TAlleg_report::get_usr_val(const TString& name, TVariant& var) const
|
|
|
|
{
|
2007-10-08 13:57:37 +00:00
|
|
|
if (name[0] == '#')
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-10-08 13:57:37 +00:00
|
|
|
TVariant* v = (TVariant*)_vars.objptr(name);
|
|
|
|
if (v != NULL)
|
|
|
|
{
|
|
|
|
var = *v;
|
|
|
|
return true;
|
|
|
|
}
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
return TReport::get_usr_val(name, var);
|
|
|
|
}
|
|
|
|
|
2007-10-08 13:57:37 +00:00
|
|
|
TAlleg_report::TAlleg_report(TRecordset* rs, const TMask& am, bool hide_not_alleg)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
|
|
|
load("cg3900a");
|
2007-10-08 13:57:37 +00:00
|
|
|
mask2report(am);
|
|
|
|
TString4 filtro;
|
|
|
|
|
|
|
|
if (!hide_not_alleg)
|
|
|
|
filtro = am.get(F_FILTRO);
|
|
|
|
set_usr_val("#FILTRO", TVariant(filtro));
|
|
|
|
|
|
|
|
|
|
|
|
if (hide_not_alleg)
|
|
|
|
{
|
|
|
|
const char* const fields[] = { "H0.107", "B1.107", "B1.207", "F1.107", "F1.207", NULL };
|
|
|
|
for (int i = 0; fields[i]; i++)
|
|
|
|
{
|
|
|
|
TReport_field* rf = field(fields[i]);
|
|
|
|
if (rf != NULL)
|
|
|
|
rf->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
set_recordset(rs);
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAlleg_log
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAlleg_log : public TLog_report
|
|
|
|
{
|
|
|
|
bool _red_alert;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool log(int severity, const char* msg);
|
|
|
|
bool red_alert() const { return _red_alert; }
|
|
|
|
TAlleg_log() : TLog_report(TR("Errori riscontrati")), _red_alert(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TAlleg_log::log(int severity, const char* msg)
|
|
|
|
{
|
|
|
|
if (severity > 0)
|
|
|
|
_red_alert = true;
|
|
|
|
return TLog_report::log(severity, msg);
|
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAlleg_mask
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAlleg_mask : public TAutomask
|
|
|
|
{
|
|
|
|
TCodiva_cache _codiva;
|
2007-09-17 15:33:04 +00:00
|
|
|
TCausali_cache _causali;
|
2007-03-06 13:59:25 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
protected: // TAutomask
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2007-09-28 10:13:18 +00:00
|
|
|
virtual void on_firm_change();
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
protected: // Elaborazione
|
|
|
|
const TRectype& contribuente() const;
|
2007-03-06 13:59:25 +00:00
|
|
|
bool documento_corrispettivi(const TString& tipodoc) const;
|
2007-09-17 15:33:04 +00:00
|
|
|
int imp_iva(char tipocf, bool non_esposti, const TRecordset& riga, real& imp, real& iva);
|
|
|
|
real indetraibile_al(const TRecordset& riga, bool prorata100) const;
|
2008-03-11 16:48:19 +00:00
|
|
|
bool scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi, bool invio, bool ministeriale);
|
2007-03-30 13:51:17 +00:00
|
|
|
TRecordset* new_recordset(char tipocf = ' ', bool strict = false);
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
void log_error(const char* ragsoc, const char* msg1, const char* msg2,
|
2008-03-11 16:48:19 +00:00
|
|
|
TAlleg_log& errlog, int severity = 2);
|
2007-09-17 15:33:04 +00:00
|
|
|
void log_error(const TRecordset& clifo, const char* msg1, const char* msg2,
|
2008-03-11 16:48:19 +00:00
|
|
|
TAlleg_log& errlog, int severity = 2);
|
2007-09-17 15:33:04 +00:00
|
|
|
void copia_importo(const TRecordset& clifo, const char* fldname,
|
|
|
|
TPadoaSchioppa_set& pss, int fldcode) const;
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
protected: // Generazione
|
|
|
|
bool build_output_name(TFilename& fname) const;
|
|
|
|
void add_0_9(int trc, TPadoaSchioppa_set& pss, TAlleg_log& log);
|
|
|
|
void add_1_2(int trc, TRecordset& clifo, TPadoaSchioppa_set& pss, TAlleg_log& log);
|
2007-09-17 15:33:04 +00:00
|
|
|
void add_3(TPadoaSchioppa_set& pss);
|
2008-03-11 16:48:19 +00:00
|
|
|
bool show_errors(TAlleg_log& log) const;
|
2007-03-30 13:51:17 +00:00
|
|
|
void generazione();
|
2007-03-06 13:59:25 +00:00
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
protected: // Fusione
|
|
|
|
bool test_file(const TFilename& name, TString& error) const;
|
|
|
|
void import_clifo(const TFilename& name, TAssoc_array& clips, TAssoc_array& forps, TAlleg_log& log);
|
|
|
|
TRecnotype export_clifo(int tiporec, TAssoc_array& clifo, TAllegati_set& all, TPadoaSchioppa_set& pss);
|
|
|
|
void fusione();
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
public:
|
|
|
|
TAlleg_mask();
|
2007-09-17 15:33:04 +00:00
|
|
|
~TAlleg_mask();
|
2007-03-06 13:59:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool TAlleg_mask::documento_corrispettivi(const TString& tipodoc) const
|
|
|
|
{
|
|
|
|
const TRectype& tpd = cache().get("%TPD", tipodoc);
|
2007-09-17 15:33:04 +00:00
|
|
|
bool corrisp = tpd.get_bool("B0");
|
2007-03-06 13:59:25 +00:00
|
|
|
if (corrisp)
|
|
|
|
{
|
|
|
|
const int natura_doc = tpd.get_int("I0");
|
|
|
|
corrisp = natura_doc == 1 || natura_doc == 9;
|
|
|
|
}
|
|
|
|
return corrisp;
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
int TAlleg_mask::imp_iva(char tipocf, bool non_esposti, const TRecordset& riga, real& imp, real& iva)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// Estraggo imponibile ed imposta dalla riga IVA ed
|
|
|
|
// inizialmente fingo che non ci sia una parte indetraibile
|
|
|
|
imp = riga.get(RMI_IMPONIBILE).as_real();
|
|
|
|
iva = riga.get(RMI_IMPOSTA).as_real();
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
int allegato = 0;
|
|
|
|
if (non_esposti)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
allegato = 4;
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const TString& codice = riga.get(RMI_CODIVA).as_string();
|
|
|
|
const TCodiceIVA& codiva = _codiva.codiva(codice);
|
|
|
|
allegato = codiva.allegato(tipocf);
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (allegato == 5 && get_int(F_ANNO) >= 2008) // FR005001 non esiste piu' nel 2008
|
|
|
|
allegato = 1;
|
|
|
|
}
|
2007-03-06 13:59:25 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (allegato != 1 && !iva.is_zero()) // Succede col Reverse Charge
|
|
|
|
{
|
|
|
|
imp += iva;
|
|
|
|
iva = ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return allegato;
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
bool TAlleg_mask::scan_iva_rows(const TRecordset& mov, TAssoc_array& clifi,
|
|
|
|
bool invio, bool ministeriale)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
// Informazioni base sul cliente in testata: vengono ignorati gli importi
|
|
|
|
const TAllegato_info clifo(mov);
|
2007-10-08 13:57:37 +00:00
|
|
|
const int tipalleg = clifo.get(CLI_ALLEG).as_int();
|
2007-09-17 15:33:04 +00:00
|
|
|
|
2007-10-08 13:57:37 +00:00
|
|
|
if (invio)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
2007-10-08 13:57:37 +00:00
|
|
|
// Ignoro da subito chi non va in allegato
|
|
|
|
if (tipalleg != 0 && tipalleg != 4)
|
|
|
|
return false;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Gli occasionali meritano solo di essere ignorati
|
|
|
|
if (clifo.occasionale())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const TVariant stato = clifo.get(CLI_STATOPAIV);
|
|
|
|
if (!stato.is_empty() && stato.as_string() != "IT") // Scarto gli esteri
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-08 13:57:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Per efficienza andrebbe nella funzione chiamante
|
|
|
|
const int filtro = get_int(F_FILTRO);
|
|
|
|
if (filtro >= 0 && tipalleg != filtro)
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TString80 clifo_key; clifo.key(clifo_key);
|
2007-03-30 13:51:17 +00:00
|
|
|
TAllegato_info* ai = (TAllegato_info*)clifi.objptr(clifo_key);
|
2007-03-06 13:59:25 +00:00
|
|
|
if (ai == NULL)
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
ai = new TAllegato_info(mov);
|
2007-03-30 13:51:17 +00:00
|
|
|
clifi.add(clifo_key, ai);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
2007-10-08 13:57:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Se questa partita IVA esiste gia' deve prevalere la ragione sociale con tipalleg=0
|
|
|
|
if (tipalleg == 0)
|
|
|
|
{
|
|
|
|
const long codcf = clifo.codice(); // Codice corrente
|
|
|
|
const long old_codcf = ai->codice(); // Codice su fornitura
|
|
|
|
if (codcf != old_codcf)
|
|
|
|
ai->set_codice(codcf, clifo.occas_code());
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 13:59:25 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TDate datareg = mov.get(MOV_DATAREG).as_date();
|
|
|
|
const TDate datadoc = mov.get(MOV_DATADOC).as_date();
|
|
|
|
const int anno = get_int(F_ANNO);;
|
|
|
|
const int annoiva = datareg.year();
|
2007-03-30 13:51:17 +00:00
|
|
|
const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCausale& caus = _causali.causale(codcaus, annoiva);
|
|
|
|
const bool movintra = caus.intra();
|
|
|
|
const int reg_spec = caus.regime_speciale();
|
2007-03-30 13:51:17 +00:00
|
|
|
const bool reverse_charge = (reg_spec == 13) || (reg_spec == 50) || (reg_spec == 51);
|
2007-09-17 15:33:04 +00:00
|
|
|
const bool non_esposti = movintra || reverse_charge;
|
|
|
|
const bool prorata100 = caus.reg().prorata100(annoiva);
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
TISAM_recordset righe_iva("USE RMOVIVA\nFROM NUMREG=#NR\nTO NUMREG=#NR");
|
|
|
|
righe_iva.set_var("#NR", mov.get(MOV_NUMREG));
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
real imponibile, imposta, indecifrabile;
|
2007-03-06 13:59:25 +00:00
|
|
|
for (bool ok = righe_iva.move_first(); ok; ok = righe_iva.move_next())
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
bool anno_prec = false;
|
|
|
|
if (ministeriale)
|
|
|
|
anno_prec = righe_iva.get(RMI_NAVP).as_bool();
|
|
|
|
else
|
|
|
|
anno_prec = datadoc.year() == anno-1; // Serve per quadrature
|
|
|
|
TAllegato_importi& allimp = ai->importi(anno_prec);
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const int allegato = imp_iva(clifo.tipo(), non_esposti, righe_iva, imponibile, imposta);
|
2007-03-06 13:59:25 +00:00
|
|
|
switch (allegato)
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
case 1: allimp._imp += imponibile; allimp._iva += imposta; break;
|
2007-03-06 13:59:25 +00:00
|
|
|
case 2: allimp._impNI += imponibile; break;
|
|
|
|
case 3: allimp._impES += imponibile; break;
|
2007-09-17 15:33:04 +00:00
|
|
|
case 4: allimp._ivaNE += imponibile; break; // Importi con IVA non esposta
|
|
|
|
case 5: allimp._ind += imponibile; break; // Importi INDecifrabili
|
|
|
|
default: allimp._impNA += imponibile; break; // same as case 0
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
return true;
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
2007-10-08 13:57:37 +00:00
|
|
|
// algo: R=data Registrazione; D=data Documento
|
|
|
|
TRecordset* TAlleg_mask::new_recordset(char tipocf, bool invio)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
const bool ministeriale = get(F_ALGO) == "D";
|
2007-09-17 15:33:04 +00:00
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
// Compito: tradurre in ISAM la seguente query:
|
|
|
|
// SELECT * FROM MOV
|
2007-10-08 13:57:37 +00:00
|
|
|
// WHERE TIPO=#TYPE AND ANNOIVA=#ANNO
|
2007-03-06 13:59:25 +00:00
|
|
|
// ORDER BY TIPO,CODCF;
|
2007-10-08 13:57:37 +00:00
|
|
|
TString query = "USE MOV KEY 3"; // La chiave 3 e' TIPO+CODCF+DATAREG+NUMREG
|
|
|
|
query << "\nSELECT ";
|
2008-03-11 16:48:19 +00:00
|
|
|
if (ministeriale)
|
2007-10-08 13:57:37 +00:00
|
|
|
query << "(ANNOIVA>=#ANNO)"; // Seleziona dall'anno desiderato in poi
|
|
|
|
else
|
|
|
|
query << "(ANNOIVA==#ANNO)"; // Seleziona solo l'anno desiderato
|
2007-09-17 15:33:04 +00:00
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
query << "\nFROM TIPO=#TYPE CODCF=1"; // Salta tutti movimenti senza CODCF
|
|
|
|
query << "\nTO TIPO=#TYPE"; // Inutile dire CODCF=999999
|
|
|
|
TISAM_recordset mov(query);
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
if (tipocf <= ' ') tipocf = get(F_TIPO)[0];
|
2007-10-08 13:57:37 +00:00
|
|
|
|
|
|
|
const char tipo[2] = { tipocf, '\0' };
|
2007-03-06 13:59:25 +00:00
|
|
|
const int anno = get_int(F_ANNO);
|
2007-10-08 13:57:37 +00:00
|
|
|
|
|
|
|
mov.set_var("#ANNO", TVariant(long(anno)));
|
2007-03-06 13:59:25 +00:00
|
|
|
mov.set_var("#TYPE", TVariant(tipo));
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TRecnotype movs = mov.items();
|
2007-03-30 13:51:17 +00:00
|
|
|
TString msg;
|
2007-10-08 13:57:37 +00:00
|
|
|
msg << TR("Elaborazione") << ' ' << movs << ' ' << TR("Movimenti") << ' '
|
2007-09-17 15:33:04 +00:00
|
|
|
<< (tipocf == 'C' ? TR("Clienti") : TR("Fornitori"));
|
|
|
|
TProgind pi(movs, msg, true, true);
|
|
|
|
|
|
|
|
TAssoc_array clifi;
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
for (bool ok = mov.move_first(); ok; ok = mov.move_next())
|
|
|
|
{
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const int annoiva = mov.get(MOV_ANNOIVA).as_int();
|
2007-03-06 13:59:25 +00:00
|
|
|
const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
|
2007-09-17 15:33:04 +00:00
|
|
|
const TCausale& caus = _causali.causale(codcaus, annoiva);
|
|
|
|
|
|
|
|
if (caus.esclusione_allegati()) // Controllo il flag di esclusione dagli allegati
|
2007-03-06 13:59:25 +00:00
|
|
|
continue;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Scarta trasferimento movimenti intra prima del 2008
|
2007-10-08 13:57:37 +00:00
|
|
|
if (invio && anno < 2008 && caus.intra())
|
2007-09-17 15:33:04 +00:00
|
|
|
continue;
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
// Controllo inutilmente anche il tipo documento
|
2008-03-11 16:48:19 +00:00
|
|
|
const TString& tipodoc = caus.tipodoc();
|
2007-03-06 13:59:25 +00:00
|
|
|
if (documento_corrispettivi(tipodoc))
|
|
|
|
continue;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Controllo se registro e' compatibile
|
|
|
|
const TRegistro& reg = caus.reg();
|
|
|
|
if (reg.corrispettivi())
|
2007-03-30 13:51:17 +00:00
|
|
|
continue;
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
const TipoIVA tipoiva = reg.iva();
|
|
|
|
bool keep = tipoiva == iva_vendite || tipoiva == iva_acquisti; // Voglio solo registri IVA
|
|
|
|
if (keep)
|
2007-03-30 13:51:17 +00:00
|
|
|
keep = (tipocf == 'C') ^ (tipoiva == iva_acquisti); // compatibile
|
2007-09-17 15:33:04 +00:00
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
if (keep && ministeriale)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
const int annodoc = mov.get(MOV_DATADOC).as_date().year();
|
|
|
|
const bool is_nota = (tipodoc=="NC") || (tipodoc=="ND");
|
2007-10-08 13:57:37 +00:00
|
|
|
keep = (annodoc == anno) ; // || (is_nota && (annodoc == anno-1));
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
if (!keep)
|
|
|
|
continue;
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
scan_iva_rows(mov, clifi, invio, ministeriale);
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TAllegati_set* hullygully = new TAllegati_set;
|
2007-03-30 13:51:17 +00:00
|
|
|
FOR_EACH_ASSOC_OBJECT(clifi, h, k, o)
|
|
|
|
{
|
|
|
|
const TAllegato_info& ai = *(TAllegato_info*)o;
|
2007-10-08 13:57:37 +00:00
|
|
|
if (ai.is_not_null(invio))
|
2007-03-30 13:51:17 +00:00
|
|
|
hullygully->add(ai);
|
|
|
|
}
|
2007-03-06 13:59:25 +00:00
|
|
|
hullygully->sort();
|
|
|
|
|
|
|
|
return hullygully;
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TRectype& TAlleg_mask::contribuente() const
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
|
|
|
const char tipoa = prefix().firm().get(NDT_TIPOA)[0];
|
|
|
|
const long codanagr = prefix().firm().get_long(NDT_CODANAGR);
|
|
|
|
TToken_string key;
|
|
|
|
key.add(tipoa, 0); key.add(codanagr, 1);
|
|
|
|
const TRectype& anag = cache().get(LF_ANAG, key);
|
2007-09-17 15:33:04 +00:00
|
|
|
return anag;
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
void TAlleg_mask::add_0_9(int trc, TPadoaSchioppa_set& pss, TAlleg_log& log)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
pss.new_rec(trc);
|
|
|
|
|
|
|
|
const TRectype& anag = contribuente();
|
|
|
|
const char tipoa = anag.get_char(ANA_TIPOA);
|
|
|
|
const long codanagr = anag.get_long(ANA_CODANAGR);
|
2007-10-08 13:57:37 +00:00
|
|
|
const TString ragsoc = anag.get(ANA_RAGSOC); // Non fidarsi ad usare TString&
|
2007-03-30 13:51:17 +00:00
|
|
|
|
|
|
|
TString16 pariva = anag.get(ANA_PAIV); pariva.right_just(11, '0');
|
|
|
|
if (!pi_check("", pariva))
|
2007-10-08 13:57:37 +00:00
|
|
|
log_error(ragsoc, TR("*** Ditta con partita IVA errata"), pariva, log, 2);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pariva[0] == '8' || pariva[0] == '9')
|
2008-03-11 16:48:19 +00:00
|
|
|
log_error(ragsoc, TR("* Verificare esenzione dall'invio degli elenchi"), pariva, log, 2);
|
2007-10-08 13:57:37 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
const TString16 codfis = anag.get(ANA_COFI);
|
|
|
|
if (!cf_check("", codfis))
|
2007-10-08 13:57:37 +00:00
|
|
|
log_error(ragsoc, TR("** Ditta con codice fiscale errato"), codfis, log, 2);
|
2007-03-30 13:51:17 +00:00
|
|
|
|
|
|
|
pss.set("CodiceFiscale", codfis.full() ? codfis : pariva);
|
|
|
|
pss.set("PartitaIVA", pariva.full() ? pariva : codfis);
|
|
|
|
if (tipoa == 'F')
|
|
|
|
{
|
2007-10-08 13:57:37 +00:00
|
|
|
pss.set("Cognome", ragsoc.left(30));
|
|
|
|
pss.set("Nome", ragsoc.mid(30));
|
2007-03-30 13:51:17 +00:00
|
|
|
|
|
|
|
const TRectype& anafis = cache().get(LF_ANAGFIS, codanagr);
|
|
|
|
pss.set("Sesso", anafis.get(ANF_SESSO));
|
|
|
|
pss.set("DataNascita", anafis.get_date(ANF_DATANASC));
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString4 stato = anafis.get(ANF_STATONASC);
|
|
|
|
const TString4 comun = anafis.get(ANF_COMNASC);
|
|
|
|
TString8 key; key << stato << '|' << comun;
|
2007-03-30 13:51:17 +00:00
|
|
|
const TRectype& comnas = cache().get(LF_COMUNI, key);
|
|
|
|
pss.set("ComuneNascita", comnas.get(COM_DENCOM));
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
if (stato.full() || comun[0] >= 'Z') // Nato all'estero
|
|
|
|
pss.set("ProvinciaNascita", TVariant("EE"));
|
|
|
|
else
|
|
|
|
pss.set("ProvinciaNascita", comnas.get(COM_PROVCOM));
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString4 stato = anag.get(ANA_STATORES);
|
|
|
|
const TString4 comun = anag.get(ANA_COMRES);
|
|
|
|
TString8 key; key << stato << '|' << comun;
|
2007-03-30 13:51:17 +00:00
|
|
|
const TRectype& comres = cache().get(LF_COMUNI, key);
|
|
|
|
|
2007-10-08 13:57:37 +00:00
|
|
|
pss.set("Denominazione", ragsoc);
|
2007-03-30 13:51:17 +00:00
|
|
|
pss.set("ComuneSedeLegale", comres.get(COM_DENCOM));
|
|
|
|
pss.set("ProvinciaSedeLegale", comres.get(COM_PROVCOM));
|
|
|
|
}
|
2008-03-11 16:48:19 +00:00
|
|
|
|
|
|
|
const long anno = get_int(F_ANNO);
|
|
|
|
pss.set("IdentificativoAnno", TVariant(anno-2006L)); // 00=2006, 01=2007, 02=2008, ...
|
|
|
|
pss.set("AnnoRiferimento", TVariant(anno)); // 2006, 2007, 2008, ...
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
// Compilare solo se diverso da dichiarante
|
2007-09-27 15:32:02 +00:00
|
|
|
pss.set("CodiceSoggettoObbligato", get(F_SOGG));
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
// Dati dell'intermediario che si cucca 50 Euro senza fare una mazza!
|
2007-09-27 15:32:02 +00:00
|
|
|
const TString& inter = get(F_INTR);
|
2008-03-26 14:17:46 +00:00
|
|
|
if (inter.full() && codfis != inter)
|
2007-09-27 15:32:02 +00:00
|
|
|
{
|
|
|
|
pss.set("CodiceIntermediario" , inter);
|
|
|
|
pss.set("NumeroIscrizioneAlboCAF", get(F_CAF));
|
|
|
|
pss.set("ImpegnoAllaTrasmissione", get(F_COMP));
|
|
|
|
pss.set("DataImpegno", get_date(F_DATA));
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
void TAlleg_mask::add_3(TPadoaSchioppa_set& pss)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
long num_cli = 0;
|
|
|
|
long num_for = 0;
|
|
|
|
TAssoc_array totali;
|
|
|
|
TString8 code;
|
|
|
|
|
|
|
|
for (bool ok = pss.move_first(); ok; ok = pss.move_next())
|
|
|
|
{
|
|
|
|
const int tipo = atoi(pss.rec_type());
|
|
|
|
if (tipo == 1 || tipo == 2)
|
|
|
|
{
|
|
|
|
const TString& curr = pss.curr_row();
|
|
|
|
int pos = 1;
|
|
|
|
// Scansione dei 70 campi non posizionali
|
|
|
|
for (int i = 0; i < npCount; i++, pos += npSize)
|
|
|
|
{
|
|
|
|
code = curr.mid(pos, npCode); // Codice campo
|
|
|
|
if (code.blank()) // Campo nullo = Fine record, "certamente" ultimo di questo tipo
|
|
|
|
break;
|
|
|
|
const int subcode = atoi(code.mid(2)); // CL004001 -> 4001
|
|
|
|
if (subcode == 1001) // Numero progressivo ...
|
|
|
|
{
|
|
|
|
if (tipo == 1) // ... cliente
|
|
|
|
num_cli++;
|
|
|
|
else
|
|
|
|
num_for++; // ... fornitore
|
|
|
|
} else
|
|
|
|
if (subcode >= 4001 && subcode <= 13001) // Cosidera solo gli importi
|
|
|
|
{
|
|
|
|
real* tot = (real*)totali.objptr(code);
|
|
|
|
if (tot == NULL)
|
|
|
|
{
|
|
|
|
tot = new real;
|
|
|
|
totali.add(code, tot);
|
|
|
|
}
|
|
|
|
const real val(curr.mid(pos+npCode, npValue)); // Importo sicuramente NON nullo
|
|
|
|
*tot += val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pss.new_rec(3);
|
|
|
|
pss.set("Clienti", TVariant(num_cli));
|
|
|
|
pss.set("Fornitori", TVariant(num_for));
|
|
|
|
FOR_EACH_ASSOC_OBJECT(totali, hash, key, v)
|
|
|
|
{
|
|
|
|
const real& val = *(real*)v;
|
|
|
|
pss.set(key, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::copia_importo(const TRecordset& clifo, const char* fldname,
|
|
|
|
TPadoaSchioppa_set& pss, int fldcode) const
|
|
|
|
{
|
|
|
|
const TVariant& val = clifo.get(fldname);
|
|
|
|
if (!val.is_zero())
|
|
|
|
{
|
|
|
|
CHECKS(!val.is_string(), "Campo importo di tipo errato", fldname);
|
|
|
|
pss.set(fldcode, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::log_error(const char* ragsoc, const char* msg1, const char* msg2,
|
2008-03-11 16:48:19 +00:00
|
|
|
TAlleg_log& errlog, int severity)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
TString str;
|
2007-09-27 15:32:02 +00:00
|
|
|
str << ragsoc << " - " << msg1;
|
2007-09-17 15:33:04 +00:00
|
|
|
if (msg2 && *msg2)
|
|
|
|
str << " : " << msg2;
|
|
|
|
errlog.log(severity, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::log_error(const TRecordset& clifo, const char* msg1, const char* msg2,
|
2008-03-11 16:48:19 +00:00
|
|
|
TAlleg_log& errlog, int severity)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
2007-09-27 15:32:02 +00:00
|
|
|
TString str;
|
2007-10-08 13:57:37 +00:00
|
|
|
str << clifo.get("#RECORD.NUMBER") << ". "
|
|
|
|
<< clifo.get(CLI_TIPOCF) << clifo.get(CLI_CODCF)
|
2007-09-27 15:32:02 +00:00
|
|
|
<< ' ' << clifo.get(CLI_RAGSOC);
|
2008-03-26 10:05:48 +00:00
|
|
|
str.strip_double_spaces();
|
2007-09-27 15:32:02 +00:00
|
|
|
log_error(str, msg1, msg2, errlog, severity);
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
void TAlleg_mask::add_1_2(int trc, TRecordset& clifo, TPadoaSchioppa_set& pss, TAlleg_log& log)
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
|
|
const bool coffee = get_bool(F_COFI); // Codice fiscale voluto o obbligatorio
|
|
|
|
|
|
|
|
long np = 0; // Prossimo numero progressivo clifo
|
2007-03-30 13:51:17 +00:00
|
|
|
for (bool ok = clifo.move_first(); ok; ok = clifo.move_next())
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (np == 0) // Se sto per scrivere il primo elemento ...
|
|
|
|
pss.new_rec(trc); // ... creo un nuovo record per accoglierlo
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
pss.set(1001, ++np); // Incremento il numero progressivo
|
|
|
|
|
|
|
|
// Gestione automagica del codice fiscale e della partita IVA
|
2007-03-30 13:51:17 +00:00
|
|
|
TString16 paiv = clifo.get(CLI_PAIV).as_string(); paiv.trim();
|
2007-09-17 15:33:04 +00:00
|
|
|
if (paiv.full() && real::is_natural(paiv))
|
2007-03-30 13:51:17 +00:00
|
|
|
paiv.right_just(11, '0');
|
|
|
|
|
|
|
|
TString16 cofi = clifo.get(CLI_COFI).as_string(); cofi.trim();
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
/* Troppo astuto per "Sirio il Dragone"
|
|
|
|
|
|
|
|
// Se il codice fiscale e' vuoto prendo la partita IVA numerica
|
|
|
|
if (cofi.blank() && pi_check("", paiv))
|
2007-03-30 13:51:17 +00:00
|
|
|
cofi = paiv;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
// Se la partita IVA e' vuota ed il codice fiscale e' numerico ...
|
|
|
|
if (paiv.blank() && pi_check("", cofi))
|
|
|
|
paiv = cofi; // ... allora copia nella partita IVA il codice fiscale
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Voglio o devo salvare il codice fiscale del tizio
|
|
|
|
if (coffee)
|
|
|
|
{
|
|
|
|
if (cofi.blank())
|
|
|
|
{
|
|
|
|
log_error(clifo, TR("* Codice fiscale mancante"), cofi, log, 2);
|
|
|
|
}
|
|
|
|
else
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (!real::is_natural(cofi) && !cf_check("", cofi))
|
|
|
|
log_error(clifo, TR("** Codice fiscale errato"), cofi, log, 1);
|
|
|
|
pss.set(2001, cofi); // Codice fiscale (obbligatorio dal 2008)
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (real::is_null(paiv))
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (anno < 2008 || cofi.blank())
|
|
|
|
log_error(clifo, TR("** Partita IVA mancante"), NULL, log, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!pi_check("", paiv))
|
|
|
|
log_error(clifo, TR("** Partita IVA errata"), paiv, log, 1);
|
2007-10-08 13:57:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (paiv[0] == '8' || paiv[0] == '9')
|
2008-03-11 16:48:19 +00:00
|
|
|
log_error(clifo, TR("* Verificare esclusione della Partita IVA"), paiv, log, 1);
|
2007-10-08 13:57:37 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
pss.set(3001, paiv); // Partita IVA (obbligatoria dal 2006)
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (trc == 1) // Clienti
|
|
|
|
{
|
|
|
|
// Importi anno corrente
|
|
|
|
copia_importo(clifo, "C_IMP", pss, 4001);
|
|
|
|
copia_importo(clifo, "C_IVA", pss, 4002);
|
|
|
|
copia_importo(clifo, "C_NI" , pss, 5001);
|
|
|
|
copia_importo(clifo, "C_ES" , pss, 6001);
|
|
|
|
copia_importo(clifo, "C_NE" , pss, 7001);
|
|
|
|
|
|
|
|
// Importi anno precedente
|
|
|
|
copia_importo(clifo, "P_IMP", pss, 8001);
|
|
|
|
copia_importo(clifo, "P_IVA", pss, 8002);
|
|
|
|
copia_importo(clifo, "P_NI" , pss, 9001);
|
|
|
|
copia_importo(clifo, "P_ES" , pss,10001);
|
|
|
|
copia_importo(clifo, "P_NE" , pss,11001);
|
|
|
|
}
|
|
|
|
else // Fornitori
|
|
|
|
{
|
|
|
|
// Importi anno corrente
|
|
|
|
copia_importo(clifo, "C_IMP", pss, 4001);
|
|
|
|
copia_importo(clifo, "C_IVA", pss, 4002);
|
|
|
|
copia_importo(clifo, "C_IND", pss, 5001); // Indecifrabile
|
|
|
|
copia_importo(clifo, "C_NI" , pss, 6001);
|
|
|
|
copia_importo(clifo, "C_ES" , pss, 7001);
|
|
|
|
copia_importo(clifo, "C_NE" , pss, 8001);
|
|
|
|
|
|
|
|
// Importi anno precedente
|
|
|
|
copia_importo(clifo, "P_IMP", pss, 9001);
|
|
|
|
copia_importo(clifo, "P_IVA", pss, 9002);
|
|
|
|
copia_importo(clifo, "P_IND", pss,10001);
|
|
|
|
copia_importo(clifo, "P_NI" , pss,11001);
|
|
|
|
copia_importo(clifo, "P_ES" , pss,12001);
|
|
|
|
copia_importo(clifo, "P_NE" , pss,13001);
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
bool TAlleg_mask::show_errors(TAlleg_log& log) const
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
if (yesno_box(TR("Sono stati rilevati errori sulla fornitura:\nSi desidera visualizzarli?")))
|
|
|
|
{
|
|
|
|
TReport_book errbuc;
|
|
|
|
errbuc.add(log);
|
|
|
|
errbuc.preview();
|
|
|
|
}
|
|
|
|
return yesno_box(TR("Si desidera generare ugualmente la fornitura?"));
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
// Pulisce e normalizza un nome di file
|
|
|
|
static bool normalize_name(TFilename& name)
|
|
|
|
{
|
|
|
|
name.trim();
|
|
|
|
if (name.not_empty())
|
|
|
|
{
|
|
|
|
name.lower();
|
|
|
|
name.replace('\\', '/');
|
|
|
|
}
|
|
|
|
return name.not_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Estrae un nome di file pulito da una riga di spreadsheet
|
|
|
|
static bool row2name(const TToken_string& row, TFilename& name)
|
|
|
|
{
|
|
|
|
row.get(0, name);
|
|
|
|
return normalize_name(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAlleg_mask::build_output_name(TFilename& fname) const
|
|
|
|
{
|
|
|
|
fname = get(F_DIR);
|
|
|
|
fname.add(get(F_NAME));
|
|
|
|
return normalize_name(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::generazione()
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
TPadoaSchioppa_set pss;
|
2008-03-11 16:48:19 +00:00
|
|
|
TAlleg_log log;
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
add_0_9(0, pss, log); // Testa
|
2007-03-30 13:51:17 +00:00
|
|
|
|
|
|
|
TRecordset* cli = new_recordset('C', true);
|
2008-03-11 16:48:19 +00:00
|
|
|
if (cli != NULL && cli->items())
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
log.log(0, TR("CLIENTI"));
|
|
|
|
add_1_2(1, *cli, pss, log); // Clienti
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
TRecordset* acq = new_recordset('F', true);
|
|
|
|
if (acq != NULL && acq->items() > 0)
|
2007-03-30 13:51:17 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
log.log(0, TR("FORNITORI"));
|
2008-03-11 16:48:19 +00:00
|
|
|
add_1_2(2, *acq, pss, log); // Fornitori
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
add_3(pss); // Totali Clienti e Fornitori
|
|
|
|
|
|
|
|
add_0_9(9, pss, log); // Piede (= Testa)
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-27 15:32:02 +00:00
|
|
|
bool go_on = true;
|
2008-03-11 16:48:19 +00:00
|
|
|
if (log.red_alert())
|
|
|
|
go_on = show_errors(log);
|
|
|
|
if (go_on)
|
|
|
|
{
|
|
|
|
TFilename fname;
|
|
|
|
if (build_output_name(fname))
|
|
|
|
pss.save_as(fname);
|
|
|
|
|
|
|
|
TReport_book book;
|
|
|
|
TAlleg_report clirep(cli, *this, true);
|
|
|
|
book.add(clirep);
|
|
|
|
TAlleg_report acqrep(acq, *this, true);
|
|
|
|
book.add(acqrep);
|
|
|
|
book.preview();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete cli;
|
|
|
|
delete acq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::import_clifo(const TFilename& name,
|
|
|
|
TAssoc_array& clips, TAssoc_array& forps,
|
|
|
|
TAlleg_log& log)
|
|
|
|
{
|
|
|
|
TString error;
|
|
|
|
if (test_file(name, error))
|
2007-09-17 15:33:04 +00:00
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
TPadoaSchioppa_set inps(name);
|
|
|
|
|
|
|
|
TProgind pi(inps.items(), name, true, true);
|
|
|
|
TAssoc_array* cur_clifo = NULL;
|
|
|
|
for (bool ok = inps.move_first(); ok; ok = inps.move_next())
|
2007-09-27 15:32:02 +00:00
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
const int trc = inps.rec_type()[0]-'0';
|
|
|
|
if (trc == 1 || trc == 2)
|
|
|
|
{
|
|
|
|
TAssoc_array& clifo = trc == 1 ? clips : forps;
|
|
|
|
int i = 0, pos = 1;
|
|
|
|
const TString& rec = inps.curr_row();
|
|
|
|
for (i = 0; i < npCount; i++, pos += npSize) // Scandisce i 70 campi non posizionali
|
|
|
|
{
|
|
|
|
const TString& fld = rec.mid(pos, npSize);
|
|
|
|
const TString8 code = fld.mid(2,6);
|
|
|
|
const int ncode = atoi(code);
|
|
|
|
if (ncode > 1000)
|
|
|
|
{
|
|
|
|
switch (ncode)
|
|
|
|
{
|
|
|
|
case 1001: // Inizia una nuova anagrafica
|
|
|
|
cur_clifo = NULL;
|
|
|
|
break;
|
|
|
|
case 3001: // Ho trovato la Partita IVA della nuova anagrafica
|
|
|
|
if (cur_clifo == NULL)
|
|
|
|
{
|
|
|
|
// Cerco l'anagrafica corrispondente alla Partita IVA
|
|
|
|
const TString16 piva = fld.mid(8);
|
|
|
|
cur_clifo = (TAssoc_array*)clifo.objptr(piva);
|
|
|
|
if (cur_clifo == NULL) // Se non la trovo ...
|
|
|
|
{
|
|
|
|
cur_clifo = new TAssoc_array; // ... allora la creo nuova
|
|
|
|
clifo.add(piva, cur_clifo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log.log(2, "Dati inconsistenti");
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
if (cur_clifo != NULL)
|
|
|
|
{
|
|
|
|
if (ncode > 4000) // Importi
|
|
|
|
{
|
|
|
|
const real imp = fld.mid(8);
|
|
|
|
const TVariant value(imp); // Impossibile fondere con riga precedente :-?
|
|
|
|
TVariant* tot = (TVariant*)cur_clifo->objptr(code);
|
|
|
|
if (tot != NULL)
|
|
|
|
tot->add(value); // Incremento importo precedente
|
|
|
|
else
|
|
|
|
cur_clifo->add(code, value); // Creo nuovo importo
|
|
|
|
}
|
|
|
|
else // Non importi: praticamente solo Codice Fiscale
|
|
|
|
{
|
|
|
|
const TVariant value(fld.mid(8));
|
|
|
|
cur_clifo->add(code, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log.log(2, "Dati inconsistenti");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2007-09-27 15:32:02 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
2008-03-11 16:48:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.replace('\n', ' ');
|
|
|
|
log.log(1, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TRecnotype TAlleg_mask::export_clifo(int tiporec, TAssoc_array& clifo,
|
|
|
|
TAllegati_set& all, TPadoaSchioppa_set& pss)
|
|
|
|
{
|
|
|
|
TRecnotype count = 0;
|
|
|
|
if (!clifo.empty())
|
|
|
|
{
|
|
|
|
pss.new_rec(tiporec);
|
|
|
|
FOR_EACH_ASSOC_OBJECT(clifo, cash, ckey, cobj)
|
|
|
|
{
|
|
|
|
const TVariant piva = ckey;
|
|
|
|
pss.set(1001, ++count);
|
|
|
|
pss.set(3001, piva.as_string());
|
|
|
|
|
|
|
|
all.new_rec();
|
|
|
|
all.set(CLI_TIPOCF, tiporec == 1 ? "C" : "F");
|
|
|
|
all.set(CLI_CODCF, count);
|
|
|
|
all.set(CLI_PAIV, piva);
|
|
|
|
|
|
|
|
TString80 str = tiporec == 1 ? TR("Cliente") : TR("Fornitore");
|
|
|
|
str << ' ' << count;
|
|
|
|
all.set(CLI_RAGSOC, (const char*)str);
|
|
|
|
|
|
|
|
TAssoc_array& data = *(TAssoc_array*)cobj;
|
|
|
|
FOR_EACH_ASSOC_OBJECT(data, dash, dkey, dobj)
|
|
|
|
{
|
|
|
|
const int code = atoi(dkey);
|
|
|
|
const TVariant& var = *(TVariant*)dobj;
|
|
|
|
if (code > 4000)
|
|
|
|
{
|
|
|
|
pss.set(code, var);
|
|
|
|
if (tiporec == 1) // Clienti
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case 4001: all.set("C_IMP", var); break;
|
|
|
|
case 4002: all.set("C_IVA", var); break;
|
|
|
|
case 5001: all.set("C_NI", var); break;
|
|
|
|
case 6001: all.set("C_ES", var); break;
|
|
|
|
case 7001: all.set("C_NE", var); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Fornitori
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case 4001: all.set("C_IMP", var); break;
|
|
|
|
case 4002: all.set("C_IVA", var); break;
|
|
|
|
case 5001: all.set("C_IND", var); break;
|
|
|
|
case 6001: all.set("C_NI", var); break;
|
|
|
|
case 7001: all.set("C_ES", var); break;
|
|
|
|
case 8001: all.set("C_NE", var); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (code != 1001 && code != 3001) // Gia' scritti da prima
|
|
|
|
pss.set(code, var.as_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAlleg_mask::fusione()
|
|
|
|
{
|
|
|
|
TPadoaSchioppa_set pss;
|
|
|
|
TAlleg_log log;
|
|
|
|
|
|
|
|
add_0_9(0, pss, log); // Testa
|
|
|
|
|
|
|
|
TAssoc_array clips, forps;
|
|
|
|
TSheet_field& sheet = sfield(F_FUSION);
|
|
|
|
TFilename name;
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row) if (row2name(*row, name))
|
|
|
|
{
|
|
|
|
TString error;
|
|
|
|
if (test_file(name, error))
|
|
|
|
import_clifo(name, clips, forps, log);
|
|
|
|
else
|
|
|
|
log.log(1, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAllegati_set* all = new TAllegati_set;
|
|
|
|
export_clifo(1, clips, *all, pss); // Clienti
|
|
|
|
export_clifo(2, forps, *all, pss); // Fornitori
|
|
|
|
|
|
|
|
add_3(pss); // Totali Clienti e Fornitori
|
|
|
|
add_0_9(9, pss, log); // Piede (= Testa)
|
|
|
|
|
|
|
|
bool go_on = all->items() > 0;
|
|
|
|
if (log.red_alert())
|
|
|
|
go_on = show_errors(log);
|
2007-03-30 13:51:17 +00:00
|
|
|
|
2007-09-27 15:32:02 +00:00
|
|
|
if (go_on)
|
|
|
|
{
|
2008-03-11 16:48:19 +00:00
|
|
|
TFilename fname;
|
|
|
|
if (build_output_name(fname))
|
2007-09-27 15:32:02 +00:00
|
|
|
pss.save_as(fname);
|
|
|
|
|
2008-03-11 16:48:19 +00:00
|
|
|
TReport_book book;
|
|
|
|
TAlleg_report rep(all, *this, true);
|
|
|
|
book.add(rep);
|
2007-09-27 15:32:02 +00:00
|
|
|
book.preview();
|
|
|
|
}
|
2008-03-11 16:48:19 +00:00
|
|
|
else
|
|
|
|
delete all;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAlleg_mask::test_file(const TFilename& name, TString& error) const
|
|
|
|
{
|
|
|
|
TToken_string errors(80, ';');
|
|
|
|
|
|
|
|
error.cut(0);
|
|
|
|
if (!name.exist())
|
|
|
|
errors = TR("non e' accessibile o inesistente");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TFixed_string ecf_ext("ecf");
|
|
|
|
if (ecf_ext.compare(name.ext(), true) != 0)
|
|
|
|
errors.add(TR("non ha un'estensione valida (ECF)"));
|
|
|
|
|
|
|
|
TFilename outname; build_output_name(outname);
|
|
|
|
if (name == outname)
|
|
|
|
errors.add(TR("ha lo stesso nome del file totale"));
|
|
|
|
|
|
|
|
const long sz = fsize(name);
|
|
|
|
if (sz % 1800)
|
|
|
|
errors.add(TR("non ha una dimensione valida (multipla di 1800)"));
|
|
|
|
|
|
|
|
ifstream ecf_file(name);
|
|
|
|
TString4 head; head.spaces();
|
|
|
|
ecf_file.read(head.get_buffer(), head.size());
|
|
|
|
if (!head.starts_with("0ECF"))
|
|
|
|
errors.add(TR("non ha un record di testata valido (0ECF)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errors.full())
|
|
|
|
{
|
|
|
|
error << '\'' << name << "' " << TR("non e' una fornitura valida")
|
|
|
|
<< ":\n" << errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.empty();
|
2007-03-30 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
bool TAlleg_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
case F_ANNO:
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
{
|
2007-09-27 15:32:02 +00:00
|
|
|
int anno = atoi(o.get());
|
|
|
|
if (anno < 2006)
|
|
|
|
{
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
anno = oggi.year()-1;
|
|
|
|
set(F_ANNO, anno);
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
if (anno >= 2008)
|
|
|
|
{
|
|
|
|
set(F_COFI, "X");
|
|
|
|
disable(F_COFI);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enable(F_COFI);
|
|
|
|
}
|
|
|
|
break;
|
2007-09-27 15:32:02 +00:00
|
|
|
case F_DIR:
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
{
|
|
|
|
if (o.empty())
|
|
|
|
{
|
|
|
|
TFilename fdir; fdir.tempdir();
|
|
|
|
o.set(fdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_NAME:
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
{
|
2007-09-28 10:13:18 +00:00
|
|
|
if (e == fe_init || o.empty())
|
2007-09-27 15:32:02 +00:00
|
|
|
{
|
|
|
|
const TRectype& anag = contribuente();
|
|
|
|
TFilename ecf = anag.get(ANA_PAIV);
|
|
|
|
ecf.right_just(11, '0');
|
|
|
|
ecf << "_ECF00.ecf";
|
|
|
|
set(F_NAME, ecf);
|
|
|
|
o.set(ecf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_CONT:
|
|
|
|
if (e == fe_init)
|
|
|
|
{
|
|
|
|
const TRectype& anag = contribuente();
|
|
|
|
o.set(anag.get(ANA_COFI));
|
|
|
|
o.disable();
|
2007-10-08 13:57:37 +00:00
|
|
|
set(F_PIVA, anag.get(ANA_PAIV));
|
2007-09-27 15:32:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_INTR:
|
|
|
|
if (e == fe_init && o.empty())
|
|
|
|
{
|
|
|
|
TString16 key = prefix().firm().get(NDT_FIRMAT);
|
|
|
|
if (key.full())
|
|
|
|
{
|
|
|
|
key.insert("F|");
|
|
|
|
o.set(cache().get(LF_ANAG, key, ANA_COFI));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_CAF:
|
|
|
|
if (o.empty())
|
|
|
|
{
|
|
|
|
if (e == fe_init)
|
|
|
|
o.set(prefix().firm().get(NDT_INTCAF));
|
|
|
|
}
|
|
|
|
break;
|
2007-03-06 13:59:25 +00:00
|
|
|
case DLG_SELECT:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
2007-03-07 11:02:06 +00:00
|
|
|
TRecordset* rs = new_recordset();
|
|
|
|
TRecordset_sheet sheet(*rs, TR("Elenco di controllo"), 0x8);
|
|
|
|
while (sheet.run() == K_ENTER)
|
2007-03-06 13:59:25 +00:00
|
|
|
{
|
2007-03-07 11:02:06 +00:00
|
|
|
const long sel = sheet.selected();
|
|
|
|
TToken_string& row = sheet.row(sel);
|
|
|
|
TRectype clifo(LF_CLIFO);
|
|
|
|
clifo.put(CLI_TIPOCF, row.get(0));
|
|
|
|
clifo.put(CLI_CODCF, row.get(1));
|
|
|
|
clifo.edit();
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
2007-03-07 11:02:06 +00:00
|
|
|
delete rs;
|
2007-03-06 13:59:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLG_EDIT:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
TRecordset* rs = new_recordset();
|
2007-09-27 15:32:02 +00:00
|
|
|
TFilename fname = get(F_DIR);
|
|
|
|
fname.add("clifo.xls");
|
2007-03-06 13:59:25 +00:00
|
|
|
if (rs->save_as(fname, fmt_silk))
|
|
|
|
xvt_sys_goto_url(fname, "open");
|
|
|
|
delete rs;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLG_PRINT:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
TRecordset* rs = new_recordset();
|
2007-10-08 13:57:37 +00:00
|
|
|
TAlleg_report rep(rs, *this);
|
2007-03-06 13:59:25 +00:00
|
|
|
TReport_book book;
|
|
|
|
book.add(rep);
|
|
|
|
book.print_or_preview();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-30 13:51:17 +00:00
|
|
|
case DLG_ELABORA:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
2007-09-27 15:32:02 +00:00
|
|
|
if (check_fields())
|
2008-03-11 16:48:19 +00:00
|
|
|
{
|
|
|
|
if (curr_page() == 0)
|
2007-09-27 15:32:02 +00:00
|
|
|
generazione();
|
2008-03-11 16:48:19 +00:00
|
|
|
else
|
|
|
|
fusione();
|
|
|
|
}
|
2007-03-30 13:51:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-11 16:48:19 +00:00
|
|
|
case F_FUSION:
|
|
|
|
if (e == se_notify_modify)
|
|
|
|
{
|
|
|
|
TFilename name;
|
|
|
|
if (row2name(((TSheet_field&)o).row(jolly), name))
|
|
|
|
{
|
|
|
|
TString error;
|
|
|
|
if (!test_file(name, error))
|
|
|
|
return error_box(error);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (e == fe_close)
|
|
|
|
{
|
|
|
|
TSheet_field& s = (TSheet_field&)o;
|
|
|
|
TString error;
|
|
|
|
TFilename name1, name2;
|
|
|
|
FOR_EACH_SHEET_ROW(s, i, row1) if (row2name(*row1, name1))
|
|
|
|
{
|
|
|
|
if (!test_file(name1, error))
|
|
|
|
return error_box(error);
|
|
|
|
|
|
|
|
FOR_EACH_SHEET_ROW(s, j, row2) if (j > i && row2name(*row2, name2))
|
|
|
|
{
|
|
|
|
if (name1 == name2)
|
|
|
|
{
|
|
|
|
error.format("La riga %d e' duplicata nella riga %d", i+1, j+1);
|
|
|
|
return error_box(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-03-06 13:59:25 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-28 10:13:18 +00:00
|
|
|
void TAlleg_mask::on_firm_change()
|
|
|
|
{
|
|
|
|
set(F_NAME, "", 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-06 13:59:25 +00:00
|
|
|
TAlleg_mask::TAlleg_mask() : TAutomask("cg3900a")
|
2007-09-27 15:32:02 +00:00
|
|
|
{ }
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
TAlleg_mask::~TAlleg_mask()
|
2007-09-27 15:32:02 +00:00
|
|
|
{
|
|
|
|
save_profile();
|
2007-03-06 13:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TClifo_alleg_app
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TClifo_alleg_app : public TSkeleton_application
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void main_loop();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TClifo_alleg_app::main_loop()
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// Roba anagrafica
|
|
|
|
open_files(LF_ANAG, LF_ANAGFIS, LF_COMUNI, LF_NDITTE, LF_OCCAS, LF_TAB, LF_TABCOM, 0);
|
|
|
|
// Roba contabile
|
|
|
|
open_files(LF_CAUSALI, LF_CLIFO, LF_MOV, LF_RMOVIVA, 0);
|
2007-03-06 13:59:25 +00:00
|
|
|
TAlleg_mask m;
|
|
|
|
m.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
int cg3900(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TClifo_alleg_app app;
|
2007-09-28 08:37:07 +00:00
|
|
|
app.run(argc, argv, TR("Elenco clienti/fornitori"));
|
2007-03-06 13:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|