Files correlati : ps6362.exe Commento : Programma di esportazione bolle major
282 lines
8.9 KiB
C++
282 lines
8.9 KiB
C++
#include "flexform_xml.h"
|
|
|
|
#include <config.h>
|
|
#include <date.h>
|
|
#include <lffiles.h>
|
|
#include <progind.h>
|
|
#include <reputils.h>
|
|
|
|
#include "../ve/velib04.h"
|
|
|
|
#define RDOC_RIFFLEX "RIFFLEX"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Flexform DDT export
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
void TFlexform_xml_ddt::add_row(TXmlItem & outdoc, const TRiga_documento & rdoc, TLog_report * log)
|
|
{
|
|
const TString cod_art = rdoc.get(RDOC_CODARTMAG); // Codice Flexform.
|
|
const TArticolo & art = cached_article(cod_art);
|
|
const TString cod_art_flex = art.get(ANAMAG_CODPMS);
|
|
TString descr = rdoc.get(RDOC_DESCR);
|
|
const TString num_ordine = rdoc.get(RDOC_NDOC);
|
|
const int nrow = rdoc.get_int(RDOC_NRIGA);
|
|
TToken_string refs(rdoc.get(RDOC_ORIGINAL_ROWS), ',');
|
|
TToken_string ref_qta(rdoc.get(RDOC_ORIGINAL_QTAROWS), ',');
|
|
TString_array ref_rows;
|
|
|
|
ref_rows.tok2arr(refs);
|
|
if (rdoc.sola_descrizione())
|
|
{
|
|
TXmlItem & row = outdoc.AddChild("MG_MOVMAGR");
|
|
TXmlItem & datarow = row.AddChild("datarow");
|
|
|
|
datarow.AddEnclosedText("ind_tiporiga", rdoc.tipo().is_descrizione() ? "D" : "A");
|
|
if (rdoc.get_bool(RDOC_DESCLUNGA))
|
|
descr << rdoc.get(RDOC_DESCEST);
|
|
datarow.AddEnclosedText("des_articolo_riga", descr);
|
|
}
|
|
else
|
|
{
|
|
FOR_EACH_ARRAY_ROW(ref_rows, r, tok)
|
|
{
|
|
TXmlItem & row = outdoc.AddChild("MG_MOVMAGR");
|
|
TXmlItem & datarow = row.AddChild("datarow");
|
|
|
|
datarow.AddEnclosedText("ind_tiporiga", rdoc.tipo().is_descrizione() ? "D" : "A");
|
|
if (rdoc.get_bool(RDOC_DESCLUNGA))
|
|
descr << rdoc.get(RDOC_DESCEST);
|
|
datarow.AddEnclosedText("des_articolo_riga", descr);
|
|
if (cod_art_flex.full())
|
|
{
|
|
TString msg = TR("Articolo : ");
|
|
|
|
msg << cod_art << TR(" codificato come : ") << cod_art_flex;
|
|
MSG_ARTICOLO(num_ordine, nrow, msg, false)
|
|
}
|
|
else
|
|
{
|
|
TString msg = TR("Codice articolo flexform non trovato per l'articolo :");
|
|
|
|
msg << cod_art;
|
|
MSG_ARTICOLO(num_ordine, nrow, msg, true)
|
|
}
|
|
datarow.AddEnclosedText("cod_art", cod_art_flex);
|
|
datarow.AddEnclosedText("qta_merce", ref_qta.get());
|
|
// datarow.AddEnclosedText("qta_merce", rdoc.get(RDOC_QTA));
|
|
|
|
const TRectype & rdoc_ref = cache().get(LF_RIGHEDOC, *tok); // ORC | 2020 | D | 3 | 8
|
|
TRecfield riffld((TRectype &) rdoc_ref, "RG1:" RDOC_RIFFLEX);
|
|
const TString riford = (const char *)riffld;
|
|
|
|
datarow.AddEnclosedText("des_campo_libero6", riford);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void TFlexform_xml_ddt::add_doc(const TDocumento & doc, TLog_report * log)
|
|
{
|
|
TXmlItem & ddt = AddChild("DOC_UNICO");
|
|
TXmlItem & testata = ddt.AddChild("MG_MOVMAGT");
|
|
TXmlItem & datarowt = testata.AddChild("datarow");
|
|
TFormatted_date datadoc = doc.get_date(DOC_DATADOC); datadoc.set_format("1444/");
|
|
TString msg(TR("Esportazione")); msg << doc.get_long(DOC_NDOC);
|
|
|
|
XML_MSG(msg);
|
|
datarowt.AddEnclosedText("dat_doc", datadoc.string());
|
|
datarowt.AddEnclosedText("des_num_doc", doc.get(DOC_NDOC));
|
|
|
|
FOR_EACH_RDOC(doc, i, rdoc)
|
|
add_row(testata, *rdoc, log);
|
|
}
|
|
|
|
void TFlexform_xml_ddt::export_docs(const TString & codnum, long codcli, int year, long from, long to, TLog_report * log)
|
|
{
|
|
TLista_documenti docs;
|
|
TString header("Esportazione ddt");
|
|
TCodice_numerazione num_ddt(codnum);
|
|
TToken_string tipi; //("*"); // = num_ddt.tipi_doc();
|
|
const int items = tipi.items();
|
|
TToken_string stati; // ("*");
|
|
const int ndocs = docs.read('D', 'C', codcli, year, tipi, stati, nulldate, nulldate, codnum, from, to);
|
|
|
|
if (ndocs > 0)
|
|
{
|
|
TProgress_monitor bar(ndocs, header);
|
|
|
|
for (int n = 0; n < ndocs && bar.add_status(); n++)
|
|
{
|
|
const TDocumento & doc = docs[n];
|
|
|
|
add_doc(doc, log);
|
|
}
|
|
export_doc();
|
|
}
|
|
}
|
|
|
|
TFlexform_xml_ddt::TFlexform_xml_ddt(const char* xml_name) : TEsa_xml(xml_name)
|
|
{
|
|
// <ESA_IMPORT Source=? CreationDate=? InstanceGuid=? FileVersion="1" />
|
|
SetTag("ESA_IMPORT");
|
|
SetAttr("Source", cache().get(LF_NDITTE, prefix().get_codditta(), "RAGSOC"));
|
|
|
|
SetAttr("CreationDate", today.string(full, '/'));
|
|
SetAttr("InstanceGuid", xvt_GUID());
|
|
SetAttr("FileVersion", 1);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Flexform Ordini export
|
|
///////////////////////////////////////////////////////////
|
|
|
|
const TString & TFlexform_xml_ordini::flexart2codart(const TString& cod_art_flexform)
|
|
{
|
|
const TRectype & anamag = cache().get(LF_ANAMAG, cod_art_flexform, 4);
|
|
|
|
return anamag.get(ANAMAG_CODART);
|
|
}
|
|
|
|
void TFlexform_xml_ordini::add_row(long id_ordine, const int nrow,
|
|
TDocumento & doc, const TXmlItem * row,
|
|
TLog_report * log)
|
|
{
|
|
TString4 tiporiga;
|
|
TString des_articolo_riga;
|
|
|
|
if (!row->GetEnclosedText("ind_tiporiga", tiporiga))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "ind_tiporiga");
|
|
if (!row->GetEnclosedText("des_articolo_riga", des_articolo_riga))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "des_articolo_riga");
|
|
|
|
TRiga_documento& d_row = doc.new_row(tiporiga == "D" ? "05" : "01");
|
|
|
|
d_row.put(RDOC_DESCR, des_articolo_riga);
|
|
if (tiporiga != "D")
|
|
{
|
|
TString cod_art;
|
|
real qta_merce;
|
|
TDate dat_evas_riga;
|
|
TString des_campo_libero6;
|
|
|
|
if (!row->GetEnclosedText("cod_art", cod_art))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "cod_art");
|
|
|
|
const TString cod_art_major = flexart2codart(cod_art);
|
|
const bool original_art_exist = cache().get(LF_ANAMAG, cod_art).full();
|
|
|
|
if (cod_art_major.full() || original_art_exist)
|
|
{
|
|
TString msg = TR("Articolo flexform : ");
|
|
|
|
msg << cod_art;
|
|
if (cod_art_major.full())
|
|
msg << TR(" codificato come : ") << cod_art_major;
|
|
MSG_ARTICOLO(id_ordine, nrow, msg, false);
|
|
}
|
|
else
|
|
{
|
|
TString msg = TR("Codice articolo flexform : ");
|
|
|
|
msg << cod_art << TR(" non trovato");
|
|
MSG_ARTICOLO(id_ordine, nrow, msg, true);
|
|
}
|
|
if (!row->GetEnclosedReal("qta_merce", qta_merce))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "qta_merce");
|
|
if (!row->GetEnclosedDate("dat_evas_riga", dat_evas_riga))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "dat_evas_riga");
|
|
if (!row->GetEnclosedText("des_campo_libero6", des_campo_libero6))
|
|
XML_TAG_NOT_FOUND(id_ordine, nrow, "des_campo_libero6");
|
|
d_row.put(RDOC_CODART, cod_art_major.full() ? cod_art_major : cod_art);
|
|
|
|
const TArticolo & art = cached_article(d_row.get(RDOC_CODART));
|
|
|
|
d_row.put(RDOC_UMQTA, art.first_um());
|
|
d_row.put(RDOC_QTA, qta_merce);
|
|
d_row.put(RDOC_DATACONS, dat_evas_riga);
|
|
d_row.put("RIFFLEX", des_campo_libero6);
|
|
d_row.put("IDORDFLEX", id_ordine);
|
|
}
|
|
}
|
|
|
|
bool TFlexform_xml_ordini::create_doc()
|
|
{
|
|
bool ok = false;
|
|
|
|
if (import_doc())
|
|
{
|
|
TLog_report * log = _log;
|
|
//const TXmlItem * first = FindFirstChild("ORDINE_IMPEGNO");
|
|
int n = 0;
|
|
|
|
for (TXmlItem * ord = GetChild(n); ord != nullptr; ord = GetChild(++n))
|
|
{
|
|
long id_ordine;
|
|
|
|
if (ord->GetTag() == "ORDINE_IMPEGNO")
|
|
{
|
|
if (ord->GetAttr("TipoOperazione") != "Insert")
|
|
XML_ERROR(TR("il Tipo Operazione deve essere Insert."));
|
|
|
|
const TXmlItem * ordine = ord->FindFirstChild("OR_ORDINIT");
|
|
|
|
if (ordine != nullptr)
|
|
{
|
|
const TXmlItem * testata = ordine->FindFirstChild("datarow");
|
|
|
|
if (testata->GetEnclosedLong("des_num_esterno", id_ordine))
|
|
{
|
|
TDate dat_doc_esterno;
|
|
TDate dat_evasione;
|
|
|
|
if (!testata->GetEnclosedDate("dat_doc_esterno", dat_doc_esterno))
|
|
XML_TAG_NOT_FOUND(id_ordine, 0, "N.ro ordine");
|
|
if (!testata->GetEnclosedDate("dat_evasione", dat_evasione))
|
|
XML_TAG_NOT_FOUND(id_ordine, 0, "N.ro ordine");
|
|
// "sig_serie_esterno"
|
|
TDocumento doc('D', dat_doc_esterno.year(), _codnum, -1);
|
|
TString msg(TR("Importazione documento ")); msg << id_ordine;
|
|
|
|
XML_MSG(msg);
|
|
doc.put(DOC_TIPODOC, _codnum);
|
|
doc.put(DOC_STATO, "2");
|
|
doc.put(DOC_DATADOC, dat_doc_esterno);
|
|
doc.put(DOC_TIPOCF, "C");
|
|
doc.put(DOC_CODCF, _codcli_flex);
|
|
doc.put(DOC_DATACONS, dat_evasione);
|
|
|
|
const int nrow = ordine->GetChildren();
|
|
|
|
for (int i = 1; i < nrow; i++)
|
|
{
|
|
const TXmlItem * row = ordine->GetChild(i);
|
|
|
|
if (row->GetTag() == "OR_ORDINIR")
|
|
{
|
|
const TXmlItem * data = row->FindFirstChild("datarow");
|
|
|
|
if (data != nullptr)
|
|
add_row(id_ordine, i, doc, data, log);
|
|
else
|
|
XML_ROW_NOT_FOUND(id_ordine, i);
|
|
}
|
|
else
|
|
XML_ROW_NOT_FOUND(id_ordine, i);
|
|
}
|
|
ok = doc.write() == NOERR;
|
|
}
|
|
else
|
|
XML_TAG_NOT_FOUND(id_ordine, 0, "N.ro ordine");
|
|
}
|
|
else
|
|
XML_NOT_FOUND("Testata");
|
|
}
|
|
else
|
|
XML_NOT_FOUND("ORDINE_IMPEGNO");
|
|
}
|
|
}
|
|
return ok;
|
|
} |