2011-03-01 11:27:34 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <recarray.h>
|
|
|
|
|
#include <recset.h>
|
|
|
|
|
#include <reputils.h>
|
2011-03-09 08:43:33 +00:00
|
|
|
|
#include <textset.h>
|
2011-03-01 11:27:34 +00:00
|
|
|
|
|
|
|
|
|
#include <doc.h>
|
|
|
|
|
#include <rdoc.h>
|
2011-03-09 08:43:33 +00:00
|
|
|
|
#include "../mg/codcorr.h"
|
2011-03-01 11:27:34 +00:00
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
#include "../ve/velib.h"
|
|
|
|
|
|
|
|
|
|
#include "ha2.h"
|
|
|
|
|
#include "ha2100a.h"
|
|
|
|
|
|
2011-03-09 08:43:33 +00:00
|
|
|
|
const char* const APPNAME = TR("Esselunga: generazione file Privat");
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TEsselunga_recordset: serve per potre scrivere il primo record che e' diverso dagli altri
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
class TEsselunga_recordset : public TAS400_recordset
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
//esportazione
|
|
|
|
|
void add_field(const char* name, const char* tipo, int pos, int len);
|
|
|
|
|
void insert_field(const char* name, const char* tipo, int pos, int len);
|
|
|
|
|
void add_eol_field();
|
|
|
|
|
//importazione
|
|
|
|
|
void add_trc_field(const char* tr, const char* name, const char* tipo, int pos, int len);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TEsselunga_recordset(const int rec_length);
|
|
|
|
|
};
|
2011-03-01 11:27:34 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TAutomask
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
class THardy_esselunga_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2011-03-09 08:43:33 +00:00
|
|
|
|
|
2011-03-01 11:27:34 +00:00
|
|
|
|
public:
|
|
|
|
|
THardy_esselunga_mask();
|
|
|
|
|
virtual ~THardy_esselunga_mask() {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
THardy_esselunga_mask::THardy_esselunga_mask() : TAutomask ("ha2100a")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool THardy_esselunga_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_DATAINI:
|
|
|
|
|
if (e == fe_close || e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
//se la data iniziale <20> piena -> l'anno deve essere lo stesso nelle 2 date;
|
|
|
|
|
//se invece <20> vuota -> la data iniziale viene presa come la data iniziale dell'esercizio della data finale...
|
|
|
|
|
//..ma questo qui non serve e viene rinviato alla query principale del recordset
|
|
|
|
|
const TDate datafin = get_date(F_DATAFIN);
|
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
|
const int datafin_esc = esc.date2esc(datafin);
|
|
|
|
|
|
|
|
|
|
TDate dataini = o.get();
|
|
|
|
|
if (dataini.ok())
|
|
|
|
|
{
|
|
|
|
|
const int dataini_esc = esc.date2esc(dataini);
|
|
|
|
|
if (datafin_esc != dataini_esc)
|
|
|
|
|
return error_box("Le date devono appartenere allo stesso esercizio!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 08:43:33 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TCodArtEsselunga_cache
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TCodArtEsselunga_cache : public TCache
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual TObject* key2obj(const char* key);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TCodArtEsselunga_cache() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TObject* TCodArtEsselunga_cache::key2obj(const char* key)
|
|
|
|
|
{
|
|
|
|
|
TToken_string code(key);
|
|
|
|
|
TString80 codart; code.get(0, codart);
|
|
|
|
|
TString16 codcf; code.get(1, codcf);
|
|
|
|
|
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.items()>0)
|
|
|
|
|
{
|
|
|
|
|
codcorr.move_first();
|
|
|
|
|
return new TString80(codcorr.get(CODCORR_CODARTALT).as_string());
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
// Recordset per file privat
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
class TPrivat_recordset : public TAS400_recordset
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TPrivat_recordset();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TPrivat_recordset::TPrivat_recordset()
|
|
|
|
|
: TAS400_recordset("AS400(51)")
|
|
|
|
|
{
|
|
|
|
|
create_field("CDC", -1, 3, _intfld); // centro di costo
|
|
|
|
|
create_field("CODART", -1, 6, _longfld); // codice articolo
|
|
|
|
|
create_field("CODFORN", -1, 6, _longfld); // codice fornitore
|
|
|
|
|
create_field("TIPOBOLLA", -1, 1, _alfafld); // tipo bolla
|
|
|
|
|
create_field("NUMBOLLA", -1, 12, _alfafld); // numero bolla
|
|
|
|
|
create_field("DATABOLLA", -1, 8, _longfld); // data bolla
|
|
|
|
|
create_field("QTACONS", -1, 7, _realfld); // qta consegnata
|
|
|
|
|
create_field("QTARESA", -1, 7, _realfld); // qta resa
|
|
|
|
|
create_field("CODDIP", -1, 1, _alfafld); // codice dipendenza
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-01 11:27:34 +00:00
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
// TSkeleton_application
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
class THardy_esselunga : public TSkeleton_application
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
long genera_recordset(const TMask& mask, TISAM_recordset& recset);
|
2011-03-09 08:43:33 +00:00
|
|
|
|
void elabora(const TMask& mask);
|
2011-03-01 11:27:34 +00:00
|
|
|
|
void check_date(const TDate& datafine, TDate& dataini);
|
2011-03-09 08:43:33 +00:00
|
|
|
|
long check_cliente(const long codcf);
|
2011-03-01 11:27:34 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
virtual bool create();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//metodo per ricavare la data iniziale di elaborazione qualora l'utonto non la metta e l'esercizio da usare
|
|
|
|
|
void THardy_esselunga::check_date(const TDate& datafine, TDate& dataini)
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
|
TDate datafine_tmp = datafine;
|
|
|
|
|
const int esercizio = esc.date2esc(datafine);
|
|
|
|
|
esc.code2range(esercizio, dataini, datafine_tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//metodo che filtra tutti i documenti in base ai parametri della maschera
|
|
|
|
|
long THardy_esselunga::genera_recordset(const TMask& mask, TISAM_recordset& recset)
|
|
|
|
|
{
|
|
|
|
|
TString query;
|
2011-03-09 08:43:33 +00:00
|
|
|
|
query << "USE DOC \n";
|
2011-03-01 11:27:34 +00:00
|
|
|
|
|
|
|
|
|
TString filt_expr;
|
|
|
|
|
// aggiungo alla query le condizioni sulle numerazioni selezionare da maschera
|
|
|
|
|
TSheet_field& sheet = mask.sfield(F_SHEETDOC);
|
|
|
|
|
const long items = sheet.items();
|
|
|
|
|
if (items > 0)
|
|
|
|
|
{
|
|
|
|
|
TString16 codnum;
|
2011-03-09 08:43:33 +00:00
|
|
|
|
filt_expr << " SELECT";
|
2011-03-01 11:27:34 +00:00
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
|
{
|
|
|
|
|
codnum = row->get(0);
|
|
|
|
|
if (codnum.not_empty())
|
|
|
|
|
{
|
2011-03-09 08:43:33 +00:00
|
|
|
|
filt_expr << " (CODNUM=\"";
|
|
|
|
|
filt_expr << codnum << "\") ||";
|
2011-03-01 11:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
filt_expr.rtrim(2);
|
|
|
|
|
query << filt_expr;
|
|
|
|
|
}
|
2011-03-09 08:43:33 +00:00
|
|
|
|
query << "\nFROM DATADOC=#DATAINI PROVV='D' ANNO=#ANNO";
|
|
|
|
|
query << "\nTO DATADOC=#DATAFIN PROVV='D' ANNO=#ANNO";
|
2011-03-01 11:27:34 +00:00
|
|
|
|
|
|
|
|
|
recset.set(query);
|
|
|
|
|
|
|
|
|
|
//settaggio delle variabili
|
|
|
|
|
const TDate datafin = mask.get_date(F_DATAFIN);
|
|
|
|
|
TDate dataini = mask.get_date(F_DATAINI);
|
|
|
|
|
|
|
|
|
|
//se la data iniziale <20> vuota deve coincidere con l'inizio dell'esercizio della data finale (obbligatoria!)
|
|
|
|
|
int esc = datafin.year();
|
|
|
|
|
if (!dataini.ok())
|
|
|
|
|
check_date(datafin, dataini);
|
|
|
|
|
|
|
|
|
|
recset.set_var("#ANNO", long(esc));
|
|
|
|
|
recset.set_var("#DATAINI", dataini);
|
|
|
|
|
recset.set_var("#DATAFIN", datafin);
|
|
|
|
|
return recset.items();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 08:43:33 +00:00
|
|
|
|
void THardy_esselunga::elabora(const TMask& mask)
|
2011-03-01 11:27:34 +00:00
|
|
|
|
{
|
2011-03-09 08:43:33 +00:00
|
|
|
|
TLog_report log;
|
|
|
|
|
// lettura dei dati fissi da configurazione
|
|
|
|
|
TConfig config(CONFIG_DITTA, "ha");
|
|
|
|
|
const TString16 piva_esselunga = config.get("Esselunga_PIvaEsselunga");
|
|
|
|
|
const TString16 piva_hardy = config.get("Esselunga_PIvaHardy");
|
|
|
|
|
const TString16 cod_hardy = config.get("Esselunga_CodHardy");
|
|
|
|
|
const TString16 tipo_emissione = config.get("Esselunga_TipoEmissione");
|
|
|
|
|
const TString4 dipendenza = mask.get(F_DIPENDENZA);
|
|
|
|
|
TFilename file_privat = config.get("Esselunga_Path");
|
|
|
|
|
if (dipendenza[0] == 'D')
|
|
|
|
|
file_privat.add("CDMI");
|
|
|
|
|
else
|
|
|
|
|
file_privat.add("CDFI");
|
|
|
|
|
TISAM_recordset recset("");
|
|
|
|
|
const long items = genera_recordset(mask, recset);
|
|
|
|
|
if (items == 0)
|
|
|
|
|
log.log(1, "Non esistono documenti che soddisfano i parametri selezionati.");
|
|
|
|
|
// lettura dei documenti da recordset
|
2011-03-01 11:27:34 +00:00
|
|
|
|
TProgind pi(recset.items(), TR("Elaborazione documenti in corso..."), true, true);
|
2011-03-09 08:43:33 +00:00
|
|
|
|
TPrivat_recordset privat;
|
2011-03-01 11:27:34 +00:00
|
|
|
|
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
|
|
|
|
{
|
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const long codcf = recset.get(DOC_CODCF).as_int();
|
|
|
|
|
// verificare se il cliente appartiene alla dipendenza selezionata e se ha tutti i parametri per poter essere inviato
|
2011-03-09 08:43:33 +00:00
|
|
|
|
const long codcf_esselunga = check_cliente(codcf, dipendenza);
|
|
|
|
|
if ( codcf_esselunga > 0)
|
2011-03-01 11:27:34 +00:00
|
|
|
|
{
|
|
|
|
|
TDocumento* doc = new TDocumento(recset.cursor()->curr());
|
|
|
|
|
// passo tutte le righe del documento all'AS400recordset
|
|
|
|
|
FOR_EACH_PHYSICAL_RDOC(*doc, r, rigadoc)
|
|
|
|
|
{
|
2011-03-09 08:43:33 +00:00
|
|
|
|
TString80 codart_esselunga = ""; // decodifica tramite cache()
|
|
|
|
|
privat.new_rec("");
|
|
|
|
|
privat.set("CDC", TVariant(codcf_esselunga));
|
|
|
|
|
/*
|
|
|
|
|
privat.set("CODART",
|
|
|
|
|
privat.set("CODFORN",
|
|
|
|
|
privat.set("TIPOBOLLA",
|
|
|
|
|
privat.set("NUMBOLLA",
|
|
|
|
|
privat.set("DATABOLLA",
|
|
|
|
|
privat.set("QTACONS",
|
|
|
|
|
privat.set("QTARESA",
|
|
|
|
|
*/
|
|
|
|
|
privat.set("CODDIP", TVariant(dipendenza));
|
2011-03-01 11:27:34 +00:00
|
|
|
|
} //FOR_EACH...
|
|
|
|
|
delete doc;
|
|
|
|
|
} // if check_cliente...
|
|
|
|
|
} //for (bool ok = recset.move_first()...
|
|
|
|
|
|
|
|
|
|
//se elaborazione definitiva -> cambia lo stato ai documenti di vendita elaborati, mettendolo uguale..
|
|
|
|
|
//..a quello deciso in configurazione
|
|
|
|
|
const bool definitivo = mask.get_bool(F_DEFINITIVO);
|
|
|
|
|
if (definitivo)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-03-09 08:43:33 +00:00
|
|
|
|
log.print_or_preview();
|
2011-03-01 11:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 08:43:33 +00:00
|
|
|
|
long THardy_esselunga::check_cliente(const long codcf)
|
2011-03-01 11:27:34 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void THardy_esselunga::main_loop()
|
|
|
|
|
{
|
|
|
|
|
THardy_esselunga_mask mask;
|
|
|
|
|
while (mask.run() == K_ENTER)
|
|
|
|
|
elabora(mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool THardy_esselunga::create()
|
|
|
|
|
{
|
|
|
|
|
open_files(LF_DOC, LF_RIGHEDOC, 0);
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ha2100 (int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
THardy_esselunga elabapp;
|
|
|
|
|
elabapp.run(argc, argv, APPNAME);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|