270 lines
7.0 KiB
C++
Executable File
270 lines
7.0 KiB
C++
Executable File
|
|
#include "halib.h"
|
|
|
|
TString4 TContratto_premi::_tipo_ant;
|
|
TString4 TContratto_premi::_tipo_post;
|
|
TString4 TContratto_premi::_tipo_rifa;
|
|
TString4 TContratto_premi::_tipo_nolo;
|
|
|
|
//metodi della TContratto_premi
|
|
char TContratto_premi::tipo_contratto() const
|
|
{
|
|
//i tipi contratto vengono caricati solo al primo accesso, in modo da non dover rileggere tutte le volte..
|
|
//..il file di configurazione
|
|
if (_tipo_ant.blank())
|
|
{
|
|
TConfig config(CONFIG_DITTA, "ha");
|
|
_tipo_ant = config.get("CoAntTip");
|
|
_tipo_post = config.get("CoPostTip");
|
|
_tipo_rifa = config.get("CoRifaTip");
|
|
_tipo_nolo = config.get("CoNoloTip");
|
|
}
|
|
|
|
//ritorna il tipo contratto come carattere; se non lo trova -> tipo 'P'osticipo perchè..
|
|
//..è il tipo meno pericoloso (comunque non dovrebbe mai accadere in quanto il tipo è..
|
|
//..obbligatorio sia in immissione contratto che in configurazione modulo)
|
|
const TString& tipo_doc = get(DOC_TIPODOC);
|
|
if (tipo_doc == _tipo_ant)
|
|
return 'A';
|
|
if (tipo_doc == _tipo_rifa)
|
|
return 'R';
|
|
if (tipo_doc == _tipo_nolo)
|
|
return 'N';
|
|
return 'P';
|
|
}
|
|
|
|
char TContratto_premi::frequenza() const
|
|
{
|
|
char f = get_char(DOC_CATVEN);
|
|
if (f < 'A')
|
|
{
|
|
const TString& tipo_doc = get(DOC_TIPODOC);
|
|
f = tipo_doc == _tipo_nolo ? 'M' : 'A';
|
|
}
|
|
return f;
|
|
}
|
|
|
|
bool TContratto_premi::data_valida(const TDate& datadoc) const
|
|
{
|
|
const TDate i = data_inizio();
|
|
if (i.ok() && datadoc < i)
|
|
return false;
|
|
|
|
const TDate f = data_fine();
|
|
if (f.ok() && datadoc > f)
|
|
return false;
|
|
|
|
const TDate r = data_recesso();
|
|
if (r.ok() && datadoc > r)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
long TContratto_premi::codcf_fatt() const
|
|
{
|
|
long cod = get_long(DOC_DOC2);
|
|
if (cod <= 0)
|
|
cod = codcf();
|
|
return cod;
|
|
}
|
|
|
|
TContratto_premi::TContratto_premi(char provv, int anno, const char* codnum, long ndoc)
|
|
: TDocumento(provv, anno, codnum, ndoc)
|
|
{}
|
|
|
|
TContratto_premi::TContratto_premi(const TRectype& rec_doc)
|
|
: TDocumento(rec_doc)
|
|
{}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TCodArtEsselunga_cache
|
|
///////////////////////////////////////////////////////////
|
|
|
|
TObject* TCodArtEsselunga_cache::key2obj(const char* key)
|
|
{
|
|
if (key && *key)
|
|
{
|
|
TToken_string code(key);
|
|
TString80 codart; code.get(0, codart);
|
|
if (codart.full())
|
|
{
|
|
const TString& codcf = ini_get_string(CONFIG_DITTA, "ha", "Esselunga_CodEsselunga");
|
|
TISAM_recordset codcorr("USE CODCORR\nSELECT CODCF=#CODCF\nFROM CODART=#COD\nTO CODART=#COD");
|
|
codcorr.set_var("#COD", TVariant(codart));
|
|
codcorr.set_var("#CODCF", TVariant(codcf));
|
|
if (codcorr.move_first())
|
|
return new TString80(codcorr.get(CODCORR_CODARTALT).as_string());
|
|
}
|
|
}
|
|
return new TString4;
|
|
}
|
|
|
|
const TString& TCodArtEsselunga_cache::decode(const TString& codart)
|
|
{
|
|
return *(const TString*)objptr(codart);
|
|
}
|
|
|
|
TObject* TCodArtEsselungaUM_cache::key2obj(const char* key)
|
|
{
|
|
if (key && *key)
|
|
{
|
|
TToken_string code(key);
|
|
TCodice_articolo codart; code.get(0, codart);
|
|
if (codart.full())
|
|
{
|
|
const TString& codcf = ini_get_string(CONFIG_DITTA, "ha", "Esselunga_CodEsselunga");
|
|
TISAM_recordset codcorr("USE CODCORR\nSELECT CODCF=#CODCF\nFROM CODART=#COD\nTO CODART=#COD");
|
|
codcorr.set_var("#COD", TVariant(codart));
|
|
codcorr.set_var("#CODCF", TVariant(codcf));
|
|
if (codcorr.move_first())
|
|
return new TString4(codcorr.get(CODCORR_UM).as_string());
|
|
}
|
|
}
|
|
return new TString4;
|
|
}
|
|
|
|
const TString& TCodArtEsselungaUM_cache::decode(const TString& codart)
|
|
{
|
|
return *(const TString*)objptr(codart);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// Metodi di utility
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
real hd_find_sconto(const TString& str_sconto)
|
|
{
|
|
real val_perc;
|
|
if (str_sconto.full())
|
|
{
|
|
TString goodexp;
|
|
if (scontoexpr2perc(str_sconto, false, goodexp, val_perc))
|
|
{
|
|
val_perc = CENTO - (val_perc * CENTO);
|
|
val_perc *= CENTO;
|
|
val_perc.round();
|
|
}
|
|
}
|
|
return val_perc;
|
|
}
|
|
|
|
// Trova il codice agente Hardy (lungo 3) del cliente Campo
|
|
const TString& hd_find_codag(long codcf)
|
|
{
|
|
TString8 key_cfven;
|
|
key_cfven.format("C|%ld", codcf);
|
|
const TString& codag = cache().get(LF_CFVEN, key_cfven, CFV_CODAG);
|
|
return codag.right(3); //il loro codagente è lungo 3!!!
|
|
}
|
|
|
|
//il dio dei programmatori ci perdoni!
|
|
const TString& hd_format_date8(const TDate& data)
|
|
{
|
|
const int day = data.day();
|
|
const int month = data.month();
|
|
const int year = data.year();
|
|
TString& str_data = get_tmp_string();
|
|
str_data.format("%02d%02d%04d", day, month, year);
|
|
return str_data;
|
|
}
|
|
|
|
const TString& hd_format_date6(const TDate& data)
|
|
{
|
|
const int day = data.day();
|
|
const int month = data.month();
|
|
const int year = data.year();
|
|
TString& str_data = get_tmp_string();
|
|
str_data.format("%02d%02d%02d", day, month, year%100);
|
|
return str_data;
|
|
}
|
|
|
|
const TDate upload_format_date6(const TString& str_data)
|
|
{
|
|
int anno = 2000 + atoi(str_data.right(2));
|
|
const int mese = atoi(str_data.mid(2,2));
|
|
const int giorno = atoi(str_data.left(2));
|
|
TDate data(giorno, mese, anno);
|
|
return data;
|
|
}
|
|
|
|
// determina codice cliente campo a partire da codice hardy in base alle regole dettatemi da Robbi
|
|
|
|
long hd_key2cli(const TString& key)
|
|
{
|
|
const long cod_hardy = atol(key.mid(3,6));
|
|
const char first = key[0];
|
|
long codcf = 0;
|
|
switch (first)
|
|
{
|
|
case 'H':
|
|
codcf = 130000+cod_hardy;
|
|
break;
|
|
case 'P':
|
|
codcf = 140000+cod_hardy;
|
|
break;
|
|
case '0':
|
|
{
|
|
const char second = key[1];
|
|
if (second == '1')
|
|
codcf = 120000+cod_hardy;
|
|
else if (second == '0')
|
|
{
|
|
const char third = key[2];
|
|
if (third == '4')
|
|
codcf = 110000+cod_hardy;
|
|
else if (third == '3')
|
|
codcf = 100000+cod_hardy;
|
|
else if (third == '2')
|
|
codcf = 200000+cod_hardy;
|
|
else
|
|
codcf = cod_hardy;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
codcf = cod_hardy;
|
|
}
|
|
if (codcf > 999999)
|
|
codcf = 0;
|
|
return codcf;
|
|
}
|
|
|
|
// determina codice fornitore campo a partire da codice hardy in base alle regole dettatemi da Robbi
|
|
|
|
long hd_key2for(const TString& key)
|
|
{
|
|
const long codcf = atol(key.mid(3,6));
|
|
return codcf;
|
|
}
|
|
|
|
// determina tipoc, gruppo, conto e sottoconto a partire da tipoconto e idconto hardy
|
|
void hd_key2conto(const TString& key, int& gr, int& co, long& so)
|
|
{
|
|
gr = atoi(key.mid(1,2));
|
|
co = atoi(key.mid(3,2));
|
|
so = atol(key.mid(5,3));
|
|
}
|
|
|
|
const TString& hd_get_next_att_key(const TString& codart)
|
|
{
|
|
if (codart.full())
|
|
{
|
|
CHECKS(codart.len() <= 5, "Ma che cavolo di codice articolo mi stai passando Willis?", (const char*)codart);
|
|
TString query;
|
|
query << "USE &ATT";
|
|
query << "\nFROM CODTAB=#CODTAB";
|
|
query << "\nTO CODTAB=#CODTAB";
|
|
TISAM_recordset recset(query);
|
|
recset.set_var("#CODTAB", codart);
|
|
long last_prog = 0;
|
|
if (recset.move_last())
|
|
last_prog = recset.get("CODTAB[6,12]").as_int();
|
|
|
|
TString& codtab = get_tmp_string();
|
|
codtab.format("%-5s%07d", (const char*)codart, last_prog + 1);
|
|
return codtab;
|
|
}
|
|
return EMPTY_STRING;
|
|
}
|