2006-07-11 13:10:51 +00:00
|
|
|
|
#include "tp0100.h"
|
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
|
#include "../ve/velib.h"
|
2006-12-13 16:22:33 +00:00
|
|
|
|
#include "../mg/codcorr.h"
|
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////
|
2006-07-11 13:10:51 +00:00
|
|
|
|
// Cache articoli
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
class TArticolo_pack : public TRectype
|
|
|
|
|
{
|
|
|
|
|
TString _cust_code, _paper_comp;
|
|
|
|
|
|
|
|
|
|
TString4 _conai_scat[CONAI_CLASSES];
|
|
|
|
|
real _conai_peso[CONAI_CLASSES];
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void set_customer_code(const TString& cc) { _cust_code = cc; }
|
|
|
|
|
const TString& customer_code() const { return _cust_code; }
|
|
|
|
|
|
|
|
|
|
void set_paper_composition(const TString& pc) { _paper_comp = pc; }
|
|
|
|
|
const TString& paper_composition() const { return _paper_comp; }
|
|
|
|
|
|
|
|
|
|
const TString& conai_subclass(TCONAI_class cc) const { CHECK_CONAI(cc); return _conai_scat[cc]; }
|
|
|
|
|
const real& conai_weight(TCONAI_class cc) const { CHECK_CONAI(cc); return _conai_peso[cc]; }
|
2009-10-06 13:01:32 +00:00
|
|
|
|
bool set_conai(TCONAI_class cc, const TString& scat, const real& weight);
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
|
|
|
|
TArticolo_pack(const TRectype& anamag);
|
|
|
|
|
TArticolo_pack();
|
|
|
|
|
};
|
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
// Assegna sottocategoria e peso di una classe CONAI solo se non vuoti
|
|
|
|
|
bool TArticolo_pack::set_conai(TCONAI_class cc, const TString& scat, const real& weight)
|
|
|
|
|
{
|
|
|
|
|
const bool ok = conai_configured_class(cc) && scat.full() && !weight.is_zero();
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
_conai_scat[cc] = scat;
|
|
|
|
|
_conai_peso[cc] = weight;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
TArticolo_pack::TArticolo_pack(const TRectype& anamag) : TRectype(anamag)
|
2009-09-24 15:28:12 +00:00
|
|
|
|
{
|
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
|
|
|
|
{
|
|
|
|
|
const TFieldref anamag_sotcat(conai_sottocat_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
const TFieldref anamag_weight(conai_peso_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
const TString4 sotcat = anamag_sotcat.read(anamag); // Usually CA40
|
|
|
|
|
const real peso = anamag_weight.read(anamag); // Should be > 0
|
|
|
|
|
set_conai(cc, sotcat, peso); // Validates all parameters
|
2009-09-24 15:28:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
TArticolo_pack::TArticolo_pack() : TRectype(LF_ANAMAG)
|
|
|
|
|
{ }
|
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
class TCache_art : public TCache_tp
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TLocalisamfile _anamag;
|
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
virtual const TString& decode(const TToken_string& tok);
|
2009-10-06 13:01:32 +00:00
|
|
|
|
int get_extra_info(const char* key, TArticolo_pack& art);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TArticolo_pack& articolo();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TCache_art(TPack_ddt* ddt) : TCache_tp(ddt), _anamag(LF_ANAMAG) {}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
int TCache_art::get_extra_info(const char* key, TArticolo_pack& art)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-10-06 13:01:32 +00:00
|
|
|
|
TString qry(512), article_code;
|
2009-09-24 15:28:12 +00:00
|
|
|
|
qry = query_header();
|
2009-10-06 13:01:32 +00:00
|
|
|
|
qry << "SELECT Paper_Composition_Group.CompDesc, Mag_Existing_Article.ArticleCustCode, Mag_Existing_Article.ArticleCode\n"
|
2006-12-13 16:22:33 +00:00
|
|
|
|
<< "FROM Mag_Existing_Article, Articles_Composition, Paper_Composition_Group\n"
|
|
|
|
|
<< "WHERE (Mag_Existing_Article.ArtCode='" << key << "') AND "
|
|
|
|
|
<< "(Mag_Existing_Article.ArticleCode=Articles_composition.ArticleCode) AND "
|
|
|
|
|
<< "(Articles_Composition.CompCode=Paper_Composition_Group.CompCode);";
|
|
|
|
|
TODBC_recordset paperset(qry);
|
2009-10-06 13:01:32 +00:00
|
|
|
|
int info = paperset.move_first() ? 1 : 0;
|
|
|
|
|
if (info)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TString pc = paperset.get(0u).as_string(); // Paper composition
|
|
|
|
|
const TString cc = paperset.get(1).as_string(); // Customer code
|
2009-10-06 13:01:32 +00:00
|
|
|
|
article_code = paperset.get(2).as_string(); // ArticleCode for Articles_environmentTax
|
|
|
|
|
article_code.trim();
|
2009-09-24 15:28:12 +00:00
|
|
|
|
art.set_customer_code(cc);
|
|
|
|
|
art.set_paper_composition(pc);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (cc.full())
|
|
|
|
|
{
|
|
|
|
|
int righe = 0;
|
|
|
|
|
bool found = false;
|
|
|
|
|
{ //per far chiudere il file CODCORR
|
|
|
|
|
TISAM_recordset alternative("USE CODCORR\nFROM CODART=#COD\nTO CODART=#COD");
|
|
|
|
|
alternative.set_var("#COD", TVariant(key));
|
|
|
|
|
righe = alternative.items();
|
|
|
|
|
for (bool ok = alternative.move_first(); ok && !found; ok = alternative.move_next())
|
|
|
|
|
found = alternative.get(CODCORR_CODARTALT).as_string() == cc;
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile codcorr(LF_CODCORR);
|
|
|
|
|
codcorr.zero();
|
|
|
|
|
codcorr.put(CODCORR_CODART, key);
|
|
|
|
|
codcorr.put(CODCORR_NRIGA, righe+1);
|
|
|
|
|
codcorr.put(CODCORR_TIPO, 'C');
|
|
|
|
|
codcorr.put(CODCORR_CODARTALT, cc);
|
|
|
|
|
test_write(codcorr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
if (article_code.full()) // Ho trovato un articolo di magazzino, carico CONAI info
|
2009-09-24 15:28:12 +00:00
|
|
|
|
{
|
2009-10-06 13:01:32 +00:00
|
|
|
|
qry = query_header();
|
|
|
|
|
qry << "SELECT SubclassCode,Weight\n"
|
|
|
|
|
<< "FROM Articles_environmentTax\n"
|
|
|
|
|
<< "WHERE Articles_environmentTax.ArticleCode=" << article_code << ';';
|
|
|
|
|
TODBC_recordset envtax(qry);
|
|
|
|
|
for (bool et = envtax.move_first(); et; et = envtax.move_next())
|
|
|
|
|
{
|
|
|
|
|
const TString& sc = envtax.get(0u).as_string();
|
|
|
|
|
const real wkg = envtax.get(1).as_real();
|
|
|
|
|
const TCONAI_class cc = conai_str2class(sc);
|
|
|
|
|
if (art.set_conai(cc, sc, wkg))
|
|
|
|
|
info = 2;
|
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
if (info == 2) // Ho trovato dati sul CONAI
|
|
|
|
|
{
|
|
|
|
|
bool update = false;
|
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
|
|
|
|
{
|
|
|
|
|
const TFieldref anamag_sotcat(conai_sottocat_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
const TFieldref anamag_weight(conai_peso_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
const TString4 sotcat = anamag_sotcat.read(art);
|
|
|
|
|
const TString8 peso = anamag_weight.read(art); // Faccio i confronti su stringa per evitare decimali impazziti
|
|
|
|
|
if (sotcat != art.conai_subclass(cc) || peso != art.conai_weight(cc).string())
|
|
|
|
|
{
|
|
|
|
|
anamag_sotcat.write(art.conai_subclass(cc), art);
|
|
|
|
|
anamag_weight.write(art.conai_weight(cc).string(), art);
|
|
|
|
|
update = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (update) // Aggiorno anagrafica se necessario
|
|
|
|
|
{
|
|
|
|
|
_anamag.curr() = art;
|
|
|
|
|
test_rewrite(_anamag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
TObject* TCache_art::key2obj(const char* key)
|
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
// Non salvo i codici vuoti presenti nelle righe descrizione
|
|
|
|
|
if (key == NULL || *key <= ' ')
|
|
|
|
|
return new TArticolo_pack; // Articolo nullo
|
|
|
|
|
|
|
|
|
|
_anamag.put(ANAMAG_CODART, key);
|
2009-10-06 13:01:32 +00:00
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
if (_anamag.read() != NOERR)
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
_anamag.zero();
|
2006-12-13 16:22:33 +00:00
|
|
|
|
_anamag.put(ANAMAG_CODART, key);
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TString& desc = get_str("ArtDesc");
|
|
|
|
|
_anamag.put(ANAMAG_DESCR, desc);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
2009-10-06 13:01:32 +00:00
|
|
|
|
TString4 conai_class = get_str("SubclassCode");
|
|
|
|
|
if (conai_class.blank())
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2009-10-06 13:01:32 +00:00
|
|
|
|
conai_class = get_str("ClassCode");
|
|
|
|
|
if (conai_class.full())
|
|
|
|
|
conai_class << 99;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Basic CONAI info
|
|
|
|
|
const TCONAI_class cc = conai_str2class(conai_class);
|
|
|
|
|
if (conai_configured_class(cc))
|
|
|
|
|
{
|
|
|
|
|
const TFieldref fld_sc(conai_sottocat_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
fld_sc.write(conai_class, _anamag.curr());
|
|
|
|
|
|
|
|
|
|
const TFieldref fld_wt(conai_peso_name(cc, LF_ANAMAG), LF_ANAMAG);
|
|
|
|
|
fld_wt.write(get_real_str("WeightETUnit"), _anamag.curr());
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
|
|
|
|
const long gruconto = get_long("AccountCode");
|
|
|
|
|
const long sottoconto = get_long("AccountSubCode");
|
|
|
|
|
_anamag.put(ANAMAG_GRUPPOV, gruconto / 1000);
|
|
|
|
|
_anamag.put(ANAMAG_CONTOV, gruconto % 1000);
|
|
|
|
|
_anamag.put(ANAMAG_SOTTOCV, sottoconto);
|
|
|
|
|
test_write(_anamag);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
|
|
|
|
TArticolo_pack* art = new TArticolo_pack(_anamag.curr());
|
2009-10-06 13:01:32 +00:00
|
|
|
|
get_extra_info(key, *art); // CustomerCode, PaperComposition, CONAI infos
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
|
|
|
|
return art;
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TArticolo_pack& TCache_art::articolo()
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString80 codart = get_str("ArtCode");
|
|
|
|
|
if (codart.empty()) // Se non ho un codice articolo lo creo in base al conto
|
|
|
|
|
{
|
|
|
|
|
const long gruconto = get_long("AccountCode");
|
|
|
|
|
const long sottoconto = get_long("AccountSubCode");
|
|
|
|
|
if (gruconto > 0 && sottoconto > 0)
|
|
|
|
|
codart << "*" << gruconto << '*' << sottoconto;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
return *(const TArticolo_pack*)objptr(codart);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TCache_art::decode(const TToken_string& tok)
|
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TArticolo_pack& rec = *(const TArticolo_pack*)objptr(tok);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
return rec.get(ANAMAG_CODART);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Cache unita' di misura degli articoli
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TCache_umart : public TCache_tp
|
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
TLocalisamfile _umart;
|
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
const TString& decode(const TToken_string& key) { return *(const TString*)objptr(key); }
|
2009-09-24 15:28:12 +00:00
|
|
|
|
TCache_umart(TPack_transfer* pt) : TCache_tp(pt), _umart(LF_UMART) {}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TObject* TCache_umart::key2obj(const char* key)
|
|
|
|
|
{
|
|
|
|
|
TToken_string code(key);
|
|
|
|
|
TString80 codart; code.get(0, codart);
|
|
|
|
|
TString4 um; code.get(1, um);
|
|
|
|
|
|
|
|
|
|
TISAM_recordset umart("USE UMART\nFROM CODART=#COD\nTO CODART=#COD");
|
|
|
|
|
umart.set_var("#COD", TVariant(codart));
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
TRecnotype i = 0;
|
|
|
|
|
for (i = 0; umart.move_to(i) && !found; i++)
|
|
|
|
|
found = umart.get("UM").as_string() == um;
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
_umart.put(UMART_CODART, codart);
|
|
|
|
|
_umart.put(UMART_NRIGA, i+1);
|
|
|
|
|
_umart.put(UMART_UM, um);
|
|
|
|
|
_umart.put(UMART_FC, 1);
|
|
|
|
|
test_write(_umart);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return code.dup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TPack_ddt
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
bool TPack_ddt::signal_row_error(const char* m)
|
|
|
|
|
{
|
|
|
|
|
const long numrig = get_long("CDocRow");
|
|
|
|
|
TString msg; msg << m << TR(" sulla riga ") << numrig;
|
|
|
|
|
return log_error(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPack_ddt::get_tipodoc(TString& codnum, TString& tipodoc)
|
|
|
|
|
{
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
|
|
const TString& book = get_str("ReceiptBook");
|
|
|
|
|
if (book.full())
|
|
|
|
|
{
|
|
|
|
|
codnum = config().get(book, "CODNUM");
|
|
|
|
|
if (codnum.blank())
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
|
|
|
|
msg << TR("Non esite una numerazione corrispondente al codice ") << book;
|
|
|
|
|
ok = log_error(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ok = log_error("Impossibile determinare la numerazione");
|
|
|
|
|
if (codnum.blank())
|
|
|
|
|
codnum = "B01"; // Uso la prima numerazione che mi viene in mente
|
|
|
|
|
|
|
|
|
|
const TString& tipo = get_str("StoreDocType");
|
|
|
|
|
if (tipo.full())
|
|
|
|
|
{
|
|
|
|
|
tipodoc = config().get(tipo, "TIPODOC");
|
|
|
|
|
if (tipodoc.blank())
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
|
|
|
|
msg << TR("Non esite un tipo documento corrispondente al codice ") << tipo;
|
|
|
|
|
ok = log_error(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ok = log_error("Impossibile determinare il tipo del documento");
|
|
|
|
|
|
|
|
|
|
if (tipodoc.blank())
|
|
|
|
|
tipodoc = codnum;
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPack_ddt::get_um_qta(TString& um, real& qta)
|
|
|
|
|
{
|
|
|
|
|
const long flag_um = get_long("FlagUMPrice");
|
|
|
|
|
|
|
|
|
|
const char* field_um = NULL;
|
|
|
|
|
const char* field_qta = NULL;
|
|
|
|
|
switch (flag_um)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
field_qta = "Quantity1";
|
|
|
|
|
field_um = "UMDesc1";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
field_qta = "Quantity2";
|
|
|
|
|
field_um = "UMDesc2";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
field_qta = "Quantity";
|
|
|
|
|
field_um = "UMDesc";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
um = decode_field("%UMS", field_um);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
qta = recordset().get(field_qta).as_real();
|
|
|
|
|
|
|
|
|
|
const bool ok = um.full();
|
|
|
|
|
if (!ok)
|
|
|
|
|
signal_row_error(TR("Impossibile determinare l'unita' di misura"));
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TRectype& TPack_ddt::get_articolo(TString& um, real& qta, TString& custcode)
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (_art == NULL)
|
|
|
|
|
_art = new TCache_art(this);
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TArticolo_pack& rec = _art->articolo();
|
2006-07-11 13:10:51 +00:00
|
|
|
|
get_um_qta(um, qta);
|
2009-09-24 15:28:12 +00:00
|
|
|
|
custcode = rec.customer_code();
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
if (!rec.empty() && um.full())
|
|
|
|
|
{
|
|
|
|
|
if (_umart == NULL)
|
|
|
|
|
_umart = new TCache_umart(this);
|
|
|
|
|
|
|
|
|
|
TToken_string key;
|
|
|
|
|
key = rec.get(ANAMAG_CODART);
|
|
|
|
|
key.add(um);
|
|
|
|
|
_umart->decode(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPack_ddt::save_doc(TDocumento* &doc, const int doccode)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
|
|
|
|
if (doc != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (write_enabled())
|
|
|
|
|
{
|
|
|
|
|
CHECK(doccode != 0, "Codice documento nullo");
|
|
|
|
|
const int err = doc->write();
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
ok = true;
|
|
|
|
|
TString cmd;
|
|
|
|
|
cmd << "UPDATE PDdT_Header SET StatusFlag=0 WHERE DocCode=" << doccode;
|
|
|
|
|
odbc_exec(cmd);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TString msg; msg.format("Errore %d durante la scrittura del documento", err);
|
|
|
|
|
ok = log_error(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete doc;
|
|
|
|
|
doc = NULL;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPack_ddt::get_clifo(char& tipocf, long& codcf)
|
|
|
|
|
{
|
|
|
|
|
tipocf = ' ';
|
|
|
|
|
codcf = 0;
|
|
|
|
|
|
|
|
|
|
const char flag = get_str("FlagCustSupp")[0];
|
|
|
|
|
TToken_string code = get_str("CodContab");
|
|
|
|
|
switch (flag)
|
|
|
|
|
{
|
|
|
|
|
case 'D':
|
|
|
|
|
case 'C': tipocf = 'C';
|
|
|
|
|
code.get(0, codcf);
|
|
|
|
|
break;
|
|
|
|
|
case 'N':
|
|
|
|
|
case 'S': tipocf = 'F';
|
|
|
|
|
code.get(0, codcf);
|
|
|
|
|
break;
|
|
|
|
|
default : break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (codcf > 0 && (tipocf == 'C' || tipocf == 'F'))
|
2009-02-14 17:13:09 +00:00
|
|
|
|
{
|
|
|
|
|
const int err = _cli.read(tipocf, codcf);
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
TString msg; msg.format("Errore %d durante la lettura del %s %ld ", err, tipocf == 'C' ? "Cliente" : "Fornitore", codcf);
|
|
|
|
|
return log_error(msg);
|
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
return true;
|
2009-02-14 17:13:09 +00:00
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
return log_error(TR("Impossibile determinare il codice del cliente/fornitore"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TPack_ddt::get_indsped() const
|
|
|
|
|
{
|
|
|
|
|
TToken_string cod_ind = get_str("DestCodContab");
|
|
|
|
|
return get_tmp_string() = cod_ind.get(1);
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
void TPack_ddt::activate_customer_code(bool cc)
|
|
|
|
|
{
|
|
|
|
|
_cust_code = cc && !cache().get("%TRI", "14").empty();
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-14 17:13:09 +00:00
|
|
|
|
const TString& TPack_ddt::get_codice_iva(const TDate& datadoc)
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
2009-02-14 17:13:09 +00:00
|
|
|
|
if (_cli.use_lettere() && _cli.read_lettera(datadoc))
|
|
|
|
|
{
|
|
|
|
|
const TString& codiva = _cli.vendite().get(CFV_ASSFIS);
|
|
|
|
|
if (codiva.full())
|
|
|
|
|
return codiva; // Codice IVA di Campo gia' decodificato!
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
2009-02-14 17:13:09 +00:00
|
|
|
|
TString8 codiva; // Codice IVA di PACK da decodificare!
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString qry(256);
|
2009-02-14 17:13:09 +00:00
|
|
|
|
qry << query_header() << "SELECT * FROM IVA WHERE IVACode=#CODIVA";
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TODBC_recordset iva(qry);
|
|
|
|
|
|
|
|
|
|
const TString& codivani = get_str("CodIvaNI");
|
|
|
|
|
if (codivani.full() && codivani != "0")
|
|
|
|
|
{
|
|
|
|
|
iva.set_var("#CODIVA", TVariant(codivani));
|
|
|
|
|
if (iva.move_first())
|
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
const TVariant& percent = iva.get("IVAValue");
|
|
|
|
|
if (percent.is_empty())
|
2006-12-13 16:22:33 +00:00
|
|
|
|
codiva = codivani;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
|
if (codiva.blank())
|
2006-12-13 16:22:33 +00:00
|
|
|
|
{
|
|
|
|
|
codiva = get_str("IVACode");
|
|
|
|
|
iva.set_var("#CODIVA", TVariant(codiva));
|
|
|
|
|
if (iva.move_first())
|
|
|
|
|
{
|
|
|
|
|
const TVariant& v = iva.get("xCode");
|
|
|
|
|
if (!v.is_empty())
|
|
|
|
|
v.as_string(codiva);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decode_value("%TPI", codiva);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TString& TPack_ddt::get_customer_reference() const
|
|
|
|
|
{
|
|
|
|
|
const TString& rcr = get_str("RowCustReference"); // Provo a leggerlo dalla riga
|
|
|
|
|
if (rcr.full())
|
|
|
|
|
return rcr;
|
|
|
|
|
const TString& hcr = get_str("CustReference"); // Provo a leggerlo dalla testata
|
|
|
|
|
return hcr;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-11 15:50:42 +00:00
|
|
|
|
bool TPack_ddt::get_paper_from_order(TString& desc) const
|
|
|
|
|
{
|
|
|
|
|
const TString16 ndoc = get_str("CDocNumber");
|
|
|
|
|
const long nrow = get_long("CDocRow");
|
|
|
|
|
if (ndoc.blank() || nrow <= 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TString qry(256);
|
|
|
|
|
qry << query_header();
|
|
|
|
|
qry << "SELECT Paper_Composition_Group.CompDesc\n"
|
|
|
|
|
"FROM CDoc_Rows, Paper_Composition_Group\n"
|
|
|
|
|
"WHERE (CDoc_Rows.DocNumber=#NDOC)AND(CDoc_Rows.RowNumber=#NROW)"
|
|
|
|
|
"AND(CDoc_Rows.CompCode=Paper_Composition_Group.CompCode)";
|
|
|
|
|
|
|
|
|
|
TODBC_recordset paper(qry);
|
|
|
|
|
paper.set_var("#NDOC", TVariant(ndoc));
|
|
|
|
|
paper.set_var("#NROW", TVariant(nrow));
|
|
|
|
|
|
|
|
|
|
if (paper.move_first())
|
|
|
|
|
desc = paper.get(0u).as_string();
|
|
|
|
|
|
|
|
|
|
return desc.full();
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
bool TPack_ddt::trasferisci()
|
|
|
|
|
{
|
2008-03-11 15:50:42 +00:00
|
|
|
|
TString query =
|
2006-07-11 13:10:51 +00:00
|
|
|
|
"SELECT DISTINCT "
|
|
|
|
|
"PDdT_Header.DocCode, PDdT_Header.StoreDocType, PDdT_Header.DocRefNumber, "
|
|
|
|
|
"PDdT_Header.DocDate, Store_Year.SyReferenceYear, PDdT_Header.CustSuppCode, "
|
|
|
|
|
"Customers_Suppliers.FlagCustSupp, Customers_Suppliers.CodContab, Customers_Suppliers.CategoryCode, Customers_Suppliers.ZoneCode, "
|
|
|
|
|
"Customers_Suppliers_1.CodContab AS AgentCode, "
|
|
|
|
|
"PDdT_Header.Change, CAMPOCurrencies.UMDesc AS Currency, "
|
|
|
|
|
"PDdT_Header.PaymentCode, PDdT_Header.ApplyEnvTax, PDdT_Header.DiscountOnPayment, "
|
|
|
|
|
"CausaliTrasporto.Code AS CodTrasporto, Porto.Code AS CodResa, CausaliTrasporto.Description1 AS TipoTrasporto, "
|
|
|
|
|
"Porto.Description1 AS TipoResa, PDdT_Header.Appearance, PDdT_Header.GrossWeight, PDdT_Header.NetWeight, "
|
2009-04-17 08:08:23 +00:00
|
|
|
|
"PDdT_Header.ShiverNumber, (select case when PDdT_Header.BankDesc is null Or [PDdT_Header].[BankDesc]<>''then "
|
|
|
|
|
"PDdT_Header.BankDesc else customers_suppliers.bankname end) AS BankDesc, PDdT_Header.CodIvaNI, "
|
2006-07-11 13:10:51 +00:00
|
|
|
|
"Customers_Suppliers_2.CustSuppCode AS DestCode, Customers_Suppliers_2.FlagCustSupp AS FlagDestCode, "
|
|
|
|
|
"Customers_Suppliers_2.CodContab AS DestCodContab, "
|
|
|
|
|
"Customers_Suppliers_2.TradeName1, Customers_Suppliers_2.Address, Customers_Suppliers_2.Locality, "
|
|
|
|
|
"Customers_Suppliers_2.ZipCode, Customers_Suppliers_2.Region, PDdT_Row.DocRow, PDdT_Row.ArtCode, "
|
2009-04-17 08:08:23 +00:00
|
|
|
|
"PDdT_Row.ArtDesc, PDdT_Row.CDocNumber, PDdT_Row.CDocRow, CDoc_Rows.CustReference AS RowCustReference, CDoc_Header.CustReference, PDdT_Row.Provv, "
|
|
|
|
|
"PDdT_Row.DiscountRowDesc, CDoc_Header.DocDate AS OrderDate, " /* "PDdT_Row.Discount2, PDdT_Row.Discount3, " */
|
2008-03-11 15:50:42 +00:00
|
|
|
|
"PDdT_Row.Quantity, Unit_Measure.UMDesc, PDdT_Row.Quantity1, Unit_Measure_1.UMDesc AS UMDesc1, "
|
2006-07-11 13:10:51 +00:00
|
|
|
|
"PDdT_Row.Quantity2, Unit_Measure_2.UMDesc AS UMDesc2, PDdT_Row.AdvanceSale, PDdT_Row.Price, "
|
|
|
|
|
"PDdT_Row.DefPrice, PDdT_Row.PriceNet, PDdT_Row.PriceNetDef, PDdT_Row.AmountNet, PDdT_Row.AmountNetDef, "
|
|
|
|
|
"PDdT_Row.Amount, PDdT_Row.AmountDef, PDdT_Row.FlagUMPrice, IVA.IVACode, PDdT_Row.AccountCode, "
|
|
|
|
|
"PDdT_Row.AccountSubCode, PDdT_Row.WeightETUnit, PDdT_Row.ClassCode, PDdT_Row.SubclassCode, "
|
2009-02-27 16:49:30 +00:00
|
|
|
|
"PDdT_Row.DDTRowType, PDdT_Header.StatusFlag, PDdT_Row.Report, PDdT_Row.FamilyCode,"
|
2007-03-06 16:37:44 +00:00
|
|
|
|
"Mag_Existing_Article.ArtType, Mag_Existing_Article.Height, Mag_Existing_Article.Width, Mag_Existing_Article.Lenght, "
|
2006-07-11 13:10:51 +00:00
|
|
|
|
"(select case when [Modalit<69> Fornitura Bancali].[Value1] is null then 1 else [Modalit<69> Fornitura Bancali].[Value1] end) AS FornituraBancali, "
|
|
|
|
|
"PDdT_Header.InvoicingType, PDdT_Header.DocProvv, PDdT_Header.ReceiptBook\n"
|
|
|
|
|
"FROM ((((((PDdT_Header LEFT JOIN Customers_Suppliers ON PDdT_Header.CustSuppCode = Customers_Suppliers.CustSuppCode) "
|
|
|
|
|
"LEFT JOIN Unit_Measure AS CAMPOCurrencies ON (CAMPOCurrencies.UMcode=PDdT_Header.CurrencyCode AND CAMPOCurrencies.UMType='9') "
|
|
|
|
|
"LEFT JOIN Customers_Suppliers AS Customers_Suppliers_1 ON PDdT_Header.AgentCode = Customers_Suppliers_1.CustSuppCode) "
|
|
|
|
|
"LEFT JOIN Porto ON PDdT_Header.PortCode = Porto.Code) "
|
|
|
|
|
"LEFT JOIN Store_Year ON PDdT_Header.DocYear = Store_Year.SyCode) "
|
|
|
|
|
"LEFT JOIN Customers_Suppliers AS Customers_Suppliers_2 ON PDdT_Header.DestCode = Customers_Suppliers_2.CustSuppCode) "
|
|
|
|
|
"LEFT JOIN CausaliTrasporto ON PDdT_Header.DocCausalCode = CausaliTrasporto.Code) "
|
|
|
|
|
"RIGHT JOIN (Mag_Existing_Article RIGHT JOIN ((CDoc_Header "
|
|
|
|
|
"RIGHT JOIN (((IVA RIGHT JOIN (((CDoc_Rows RIGHT JOIN PDdT_Row ON (CDoc_Rows.DocNumber = PDdT_Row.CDocNumber) "
|
|
|
|
|
"AND (CDoc_Rows.RowNumber = PDdT_Row.CDocRow)) "
|
|
|
|
|
"LEFT JOIN Unit_Measure ON PDdT_Row.UMQty = Unit_Measure.UMCode) "
|
|
|
|
|
"LEFT JOIN [Modalit<69> Fornitura Bancali] ON PDdT_Row.DeliveryPalletType = [Modalit<69> Fornitura Bancali].Code) "
|
|
|
|
|
"ON IVA.IVACode = PDdT_Row.IVACode) LEFT JOIN Unit_Measure AS Unit_Measure_1 ON PDdT_Row.UMQta1 = Unit_Measure_1.UMCode) "
|
|
|
|
|
"LEFT JOIN Unit_Measure AS Unit_Measure_2 ON PDdT_Row.UMQta2 = Unit_Measure_2.UMCode) "
|
|
|
|
|
"ON CDoc_Header.DocNumber = CDoc_Rows.DocNumber) "
|
|
|
|
|
"LEFT JOIN CDoc_Rows_Detail ON (CDoc_Rows.RowNumber = CDoc_Rows_Detail.RowNumber) AND "
|
|
|
|
|
"(CDoc_Rows.DocNumber = CDoc_Rows_Detail.DocNumber)) "
|
|
|
|
|
"ON Mag_Existing_Article.ArtCode = PDdT_Row.ArtCode) ON PDdT_Header.DocCode = PDdT_Row.DocCode\n"
|
|
|
|
|
"WHERE (((PDdT_Row.DDTRowType)='0' Or (PDdT_Row.DDTRowType)='2') AND "
|
|
|
|
|
"((PDdT_Header.StatusFlag)='1' OR (PDdT_Header.StatusFlag)='2' Or (PDdT_Header.StatusFlag)='3') AND "
|
|
|
|
|
"((select case when [Modalit<69> Fornitura Bancali].[Value1] is null then 1 else [Modalit<69> Fornitura Bancali].[Value1] end)=1) AND "
|
2008-03-11 15:50:42 +00:00
|
|
|
|
"((PDdT_Header.InvoicingType) Is Not Null) AND ((PDdT_Header.DocProvv)<>-1))"
|
|
|
|
|
"\nORDER BY PDdT_Header.DocRefNumber, PDdT_Row.DocRow"
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
if (_extended_discount)
|
|
|
|
|
{
|
|
|
|
|
const TFixed_string discount("PDdT_Row.DiscountRowDesc, ");
|
|
|
|
|
const int pos = query.find(discount);
|
|
|
|
|
query.insert("PDdT_Row.Discount2, PDdT_Row.Discount3, ", pos+discount.len());
|
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
TRecordset& recset = create_recordset(query);
|
|
|
|
|
|
|
|
|
|
TDocumento* doc = NULL;
|
|
|
|
|
long curr_ndoc = 0; // Numero in Campo
|
|
|
|
|
long curr_code = 0; // Numero in Pack
|
|
|
|
|
TString str; // jolly
|
|
|
|
|
|
|
|
|
|
TString last_custref;
|
|
|
|
|
|
|
|
|
|
TPack_iterator ri(this);
|
|
|
|
|
while (++ri)
|
|
|
|
|
{
|
|
|
|
|
const long code = get_long("DocCode");
|
|
|
|
|
const long ndoc = get_long("DocRefNumber");
|
|
|
|
|
const TDate datadoc = recset.get("DocDate").as_date();
|
|
|
|
|
|
|
|
|
|
if (_data_limite.ok() && datadoc > _data_limite)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (ndoc != curr_ndoc)
|
|
|
|
|
{
|
|
|
|
|
log("");
|
|
|
|
|
str.format(FR("Importazione documento %ld del %s"), ndoc, datadoc.string());
|
|
|
|
|
log(str);
|
|
|
|
|
|
|
|
|
|
save_doc(doc, curr_code);
|
|
|
|
|
curr_ndoc = ndoc;
|
|
|
|
|
curr_code = code;
|
|
|
|
|
last_custref.cut(0); // Azzera documento di riferimento
|
|
|
|
|
|
|
|
|
|
TString4 codnum, tipodoc;
|
|
|
|
|
get_tipodoc(codnum, tipodoc);
|
|
|
|
|
|
|
|
|
|
doc = new TDocumento('D', datadoc.year(), codnum, ndoc);
|
|
|
|
|
const bool isnew = doc->rows() == 0;
|
|
|
|
|
if (isnew)
|
|
|
|
|
{
|
|
|
|
|
doc->put(DOC_TIPODOC, tipodoc);
|
|
|
|
|
doc->put(DOC_STATO, 1);
|
|
|
|
|
doc->put(DOC_DATADOC, datadoc);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
doc->body().destroy_rows();
|
|
|
|
|
|
|
|
|
|
char tipocf = ' ';
|
|
|
|
|
long codcf = 0;
|
|
|
|
|
if (get_clifo(tipocf, codcf))
|
|
|
|
|
{
|
|
|
|
|
doc->put(DOC_TIPOCF, tipocf);
|
|
|
|
|
doc->put(DOC_CODCF, codcf);
|
|
|
|
|
doc->put(DOC_CODINDSP, get_indsped());
|
|
|
|
|
if (isnew)
|
|
|
|
|
{
|
|
|
|
|
TToken_string tok; tok.add(tipocf); tok.add(codcf);
|
|
|
|
|
const TRectype& cfven = cache().get(LF_CFVEN, tok);
|
|
|
|
|
doc->put(DOC_RAGGR, cfven.get(CFV_RAGGDOC));
|
|
|
|
|
doc->put(DOC_RAGGREFF, cfven.get(CFV_RAGGEFF));
|
|
|
|
|
doc->put(DOC_ADDBOLLI, cfven.get(CFV_ADDBOLLI));
|
|
|
|
|
doc->put(DOC_PERCSPINC, cfven.get(CFV_PERCSPINC));
|
|
|
|
|
|
|
|
|
|
const TRectype& clifo = cache().get(LF_CLIFO, tok);
|
|
|
|
|
doc->put(DOC_CODABIA, clifo.get(CLI_CODABI));
|
|
|
|
|
doc->put(DOC_CODCABA, clifo.get(CLI_CODCAB));
|
2010-02-19 14:43:23 +00:00
|
|
|
|
doc->put(DOC_IBAN, clifo.get(CLI_IBAN));
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
doc->put(DOC_ZONA, decode_field("ZON", "ZoneCode")); // Crea anche la zona se necessario
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
TToken_string forn_age = get_str("AgentCode");
|
|
|
|
|
doc->put(DOC_CODAG, forn_age.get(1));
|
|
|
|
|
doc->put(DOC_SCONTOPERC, get_real_str("DiscountOnPayment"));
|
|
|
|
|
|
|
|
|
|
const TString& codval = get_str("Currency");
|
|
|
|
|
if (is_firm_value(codval))
|
|
|
|
|
{
|
|
|
|
|
doc->zero(DOC_CODVAL);
|
|
|
|
|
doc->zero(DOC_CAMBIO);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
doc->put(DOC_CODVAL, codval);
|
|
|
|
|
doc->put(DOC_CAMBIO, get_real_str("Change"));
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
doc->put(DOC_CODPAG, get_str("PaymentCode")); // Il codice pagamento va' gia' bene cosi'
|
|
|
|
|
doc->put(DOC_CODPORTO, decode_field("%TPP", "PortCode")); // Codice porto decodificato tremite %TPP
|
|
|
|
|
doc->put(DOC_CODSPMEZZO, decode_field("%TPM", "CodTrasporto")); // Codice porto decodificato tremite %TPM
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_cust_ref)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TString& custref = get_customer_reference();
|
2007-03-06 16:37:44 +00:00
|
|
|
|
// Aggiungi una riga di descrizione col riferimento cliente se e' cambiato
|
2006-07-11 13:10:51 +00:00
|
|
|
|
if (custref.full() && custref != last_custref)
|
|
|
|
|
{
|
|
|
|
|
last_custref = custref;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TRiga_documento& rdoc = doc->new_row("05"); // Crea una riga descrizione
|
2006-07-11 13:10:51 +00:00
|
|
|
|
rdoc.put(RDOC_DESCR, custref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString4 um;
|
|
|
|
|
real qta;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString custcode;
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TArticolo_pack& art = get_articolo(um, qta, custcode);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TString4 rowtype = "01"; // Riga merce
|
2007-03-06 16:37:44 +00:00
|
|
|
|
bool bIsMerce = true;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (qta.is_zero())
|
|
|
|
|
{
|
2009-04-17 08:08:23 +00:00
|
|
|
|
rowtype = "05"; // Se la qta e' nulla allora e' una descrizione
|
2007-03-06 16:37:44 +00:00
|
|
|
|
bIsMerce = false;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_cust_code && custcode.full())
|
|
|
|
|
rowtype = "14";
|
|
|
|
|
}
|
|
|
|
|
TRiga_documento& rdoc = doc->new_row(rowtype); // Crea una riga del tipo appropriato
|
2007-03-06 16:37:44 +00:00
|
|
|
|
TString descr = get_str("ArtDesc");
|
|
|
|
|
|
|
|
|
|
const bool bIsSingleSheet = bIsMerce && get_long("ArtType") == 4; // Foglio singolo?
|
2008-03-11 15:50:42 +00:00
|
|
|
|
if (bIsSingleSheet)
|
2007-03-06 16:37:44 +00:00
|
|
|
|
{
|
2008-03-11 15:50:42 +00:00
|
|
|
|
if (_order_paper_info)
|
|
|
|
|
get_paper_from_order(descr);
|
|
|
|
|
|
|
|
|
|
if (bIsSingleSheet && descr.find('(') < 0) // E' un foglio singolo senza dimensioni?
|
|
|
|
|
{
|
|
|
|
|
TString80 misure;
|
|
|
|
|
misure << get_str("Height") << " x " << get_str("Width");
|
|
|
|
|
if (misure[0] > '0')
|
|
|
|
|
descr << " (" << misure << ')';
|
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
}
|
2006-12-13 16:22:33 +00:00
|
|
|
|
|
|
|
|
|
if (descr.len() <= 50)
|
|
|
|
|
rdoc.put(RDOC_DESCR, descr);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rdoc.put(RDOC_DESCR, descr.left(50));
|
|
|
|
|
rdoc.put(RDOC_DESCLUNGA, "X");
|
|
|
|
|
rdoc.put(RDOC_DESCEST, descr.mid(50));
|
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
|
|
|
|
|
if (bIsMerce) // Ho creato una riga articolo?
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
const TString& codart = art.get(ANAMAG_CODART);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
if (codart.full()) // Esistono righe merce senza articolo
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
rdoc.put(RDOC_CODART, rowtype == "01" ? codart : custcode);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
rdoc.put(RDOC_CODARTMAG, codart);
|
|
|
|
|
}
|
|
|
|
|
rdoc.put(RDOC_CHECKED, "X");
|
|
|
|
|
rdoc.put(RDOC_UMQTA, um);
|
|
|
|
|
rdoc.put(RDOC_QTA, qta);
|
2009-02-14 17:13:09 +00:00
|
|
|
|
rdoc.put(RDOC_CODIVA, get_codice_iva(doc->get_date(DOC_DATADOC)));
|
2006-07-11 13:10:51 +00:00
|
|
|
|
rdoc.put(RDOC_PREZZO, get_real_str("Price"));
|
|
|
|
|
|
2008-03-11 15:50:42 +00:00
|
|
|
|
TString sconto = get_real_str("DiscountRowDesc");
|
|
|
|
|
if (_extended_discount)
|
|
|
|
|
{
|
|
|
|
|
sconto << ' ' << get_real_str("Discount2");
|
|
|
|
|
sconto << ' ' << get_real_str("Discount3");
|
|
|
|
|
sconto.trim(); sconto.replace(' ', '+');
|
|
|
|
|
}
|
|
|
|
|
rdoc.put(RDOC_SCONTO, sconto);
|
|
|
|
|
|
|
|
|
|
rdoc.put(RDOC_PERCPROV, get_real_str("Provv"));
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
|
if (bIsSingleSheet)
|
2009-09-24 15:28:12 +00:00
|
|
|
|
rdoc.put("NUMFOGLI", get_real_str("Quantity")); // Ex QTAGG3
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
TString8 tok;
|
|
|
|
|
tok.format("%c|%ld", doc->get_char(DOC_TIPOCF), doc->get_long(DOC_CODCF));
|
|
|
|
|
const TRectype& cfven = cache().get(LF_CFVEN, tok);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
// Copia tutte le sottocategorie CONAI dall'anagrafica alla riga documento
|
|
|
|
|
real peso_imballo_anamag;
|
|
|
|
|
int pesi_anamag = 0;
|
2009-10-06 13:01:32 +00:00
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TString& cs = art.conai_subclass(cc); // Codice sottocategoria su ANAMAG
|
|
|
|
|
if (cs.full()) // la presenza della sottoclasse implica anche un peso positivo
|
|
|
|
|
{
|
|
|
|
|
const real& weight = art.conai_weight(cc); // Peso imballo su ANAMAG
|
|
|
|
|
rdoc.put(conai_sottocat_name(cc, LF_RIGHEDOC), cs);
|
|
|
|
|
rdoc.put(conai_peso_name(cc, LF_RIGHEDOC), weight); // ex QTAGG1
|
|
|
|
|
rdoc.put(conai_esenzione_name(cc, LF_RIGHEDOC),
|
|
|
|
|
cfven.get(conai_esenzione_name(cc, LF_CFVEN))); // ex QTAGG2
|
|
|
|
|
peso_imballo_anamag += weight;
|
|
|
|
|
pesi_anamag++;
|
|
|
|
|
}
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
|
|
|
|
|
// La sottocategoria della bolla prevale su quella anagrafica impostata sopra
|
2009-10-06 13:01:32 +00:00
|
|
|
|
const TString4 conai_subclass = get_str("SubclassCode");
|
|
|
|
|
const TCONAI_class ct = conai_str2class(conai_subclass);
|
|
|
|
|
if (ct == CONAI_CARTA && conai_subclass.len() == 4)
|
|
|
|
|
rdoc.put(conai_sottocat_name(ct, LF_RIGHEDOC), conai_subclass);
|
|
|
|
|
|
|
|
|
|
real peso_imballo_ddt = get_real_str("WeightETUnit");
|
|
|
|
|
if (peso_imballo_ddt.is_zero())
|
|
|
|
|
peso_imballo_ddt = peso_imballo_anamag;
|
|
|
|
|
|
|
|
|
|
if (pesi_anamag > 1) // Con imballi composti da vari materiali devo riportare o riproporzionare
|
2009-09-24 15:28:12 +00:00
|
|
|
|
{
|
2009-10-06 13:01:32 +00:00
|
|
|
|
// Arrotondo la eventuale differenza di pesi al grammo
|
|
|
|
|
real diff = peso_imballo_ddt - peso_imballo_anamag; diff.round(3);
|
|
|
|
|
// Il peso in bolla e' diverso da quello in anagrafica: devo riproporzionarli
|
|
|
|
|
if (!diff.is_zero() && !peso_imballo_ddt.is_zero())
|
|
|
|
|
{
|
|
|
|
|
TGeneric_distrib d(peso_imballo_ddt, 3);
|
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
|
|
|
|
d.add(art.conai_weight(cc));
|
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
|
|
|
|
rdoc.put(conai_peso_name(cc), d.get());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Il peso in bolla coincide con quello in anagrafica: devo riportarli
|
|
|
|
|
FOR_EACH_CONFIGURED_CONAI_CLASS(cc)
|
|
|
|
|
rdoc.put(conai_peso_name(cc), art.conai_weight(cc));
|
|
|
|
|
}
|
2009-09-24 15:28:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Caso semplice della sola carta
|
2009-10-06 13:01:32 +00:00
|
|
|
|
rdoc.put(conai_peso_name(CONAI_CARTA), peso_imballo_ddt);
|
2009-09-24 15:28:12 +00:00
|
|
|
|
}
|
2009-10-06 13:01:32 +00:00
|
|
|
|
|
2009-09-24 15:28:12 +00:00
|
|
|
|
rdoc.put("FAMILY", get_str("FamilyCode")); // Uso campo virtuale RG1:FAMILY
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
|
TString info;
|
2006-07-11 13:10:51 +00:00
|
|
|
|
if (_paper_info)
|
|
|
|
|
{
|
2009-09-24 15:28:12 +00:00
|
|
|
|
const TString& pap_comp = art.paper_composition();
|
2009-04-17 08:08:23 +00:00
|
|
|
|
if (pap_comp.full())
|
|
|
|
|
info << "\n" << pap_comp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_paper_size)
|
|
|
|
|
{
|
2006-07-11 13:10:51 +00:00
|
|
|
|
TString80 misure;
|
2009-04-17 08:08:23 +00:00
|
|
|
|
misure << get_str("Height") << 'x' << get_str("Width") << 'x' << get_str("Lenght");
|
2007-03-06 16:37:44 +00:00
|
|
|
|
if (misure[0] > '0')
|
2006-07-11 13:10:51 +00:00
|
|
|
|
info << "\nMISURE: " << misure;
|
2007-03-06 16:37:44 +00:00
|
|
|
|
}
|
2009-04-17 08:08:23 +00:00
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
|
if (_ref_info)
|
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TString& custref = get_customer_reference();
|
2006-07-11 13:10:51 +00:00
|
|
|
|
if (custref.full())
|
2009-04-17 08:08:23 +00:00
|
|
|
|
info << "\nVs. rifer.: " << custref;
|
|
|
|
|
|
|
|
|
|
TString80 docnum = get_str("CDocNumber"); docnum.trim();
|
|
|
|
|
if (docnum.full())
|
|
|
|
|
info << "\nNs. Ordine nr. " << docnum << '.' << get_str("CDocRow")
|
|
|
|
|
<< " del " << get_str("OrderDate");
|
2007-03-06 16:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info.full())
|
|
|
|
|
{
|
|
|
|
|
TString descest;
|
|
|
|
|
descest << rdoc.get(RDOC_DESCEST) << info;
|
2009-04-17 08:08:23 +00:00
|
|
|
|
descest.rtrim();
|
2007-03-06 16:37:44 +00:00
|
|
|
|
rdoc.put(RDOC_DESCLUNGA, "X");
|
|
|
|
|
rdoc.put(RDOC_DESCEST, descest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_cms_ref)
|
|
|
|
|
{
|
|
|
|
|
TString ref = get_str("CustReference").before(' '); // Leggo inizio testata es: "1203 DEL 16 02 2006"
|
|
|
|
|
if (ref.full())
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
const TString& r_ref = get_str("RowCustReference"); // Leggo dalla riga
|
|
|
|
|
if (r_ref.full())
|
2009-09-24 15:28:12 +00:00
|
|
|
|
ref << '/' << r_ref << '/' << art.customer_code();
|
2007-03-06 16:37:44 +00:00
|
|
|
|
rdoc.put(RDOC_CODCMS, ref);
|
2006-07-11 13:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-17 08:08:23 +00:00
|
|
|
|
|
|
|
|
|
save_doc(doc, curr_code); // Salva l'eventuale ultimo documento pendente
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
|
|
|
|
return write_enabled();
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-13 16:22:33 +00:00
|
|
|
|
TPack_ddt::TPack_ddt()
|
|
|
|
|
: _art(NULL), _umart(NULL),
|
2007-03-06 16:37:44 +00:00
|
|
|
|
_cust_ref(false), _paper_info(false), _ref_info(true), _cust_code(false)
|
2006-07-11 13:10:51 +00:00
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
TPack_ddt::~TPack_ddt()
|
|
|
|
|
{
|
|
|
|
|
if (_umart != NULL)
|
|
|
|
|
delete _umart;
|
|
|
|
|
if (_art != NULL)
|
|
|
|
|
delete _art;
|
|
|
|
|
}
|