a92ca91767
Files correlati : ha2.exe ha2100a.msk Ricompilazione Demo : [ ] Commento : Gestione invio definitivo e forzature su file PRIVAT git-svn-id: svn://10.65.10.50/branches/R_10_00@22520 c028cbd2-c16b-5b4b-a496-9718f37d4682
279 lines
8.4 KiB
C++
Executable File
279 lines
8.4 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <recset.h>
|
||
#include <reputils.h>
|
||
#include <textset.h>
|
||
#include <utility.h>
|
||
|
||
#include <doc.h>
|
||
#include <rdoc.h>
|
||
//#include "../mg/codcorr.h"
|
||
#include "../cg/cglib01.h"
|
||
#include "../ve/velib.h"
|
||
|
||
#include "halib.h"
|
||
|
||
#include "ha2.h"
|
||
#include "ha2100a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TAutomask
|
||
///////////////////////////////////////////////////////////
|
||
class THardy_esselunga_mask : public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
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)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////////
|
||
// Recordset per file privat
|
||
/////////////////////////////////////////////////////////////
|
||
class TPrivat_recordset : public TAS400_recordset
|
||
{
|
||
public:
|
||
TPrivat_recordset(const TString4 dipendenza);
|
||
};
|
||
|
||
TPrivat_recordset::TPrivat_recordset(const TString4 dipendenza)
|
||
: TAS400_recordset("AS400(53)")
|
||
{
|
||
TConfig config(CONFIG_DITTA, "ha");
|
||
const TString16 cod_hardy = config.get("Esselunga_CodHardy");
|
||
create_field("CDC", -1, 3, _intzerofld); // centro di costo
|
||
create_field("CODART", -1, 6, _longzerofld); // codice articolo
|
||
create_field("CODFORN", -1, 6, _longzerofld, true, TVariant(cod_hardy)); // codice fornitore
|
||
create_field("TIPOBOLLA", -1, 1, _alfafld, true, TVariant("A")); // tipo bolla
|
||
create_field("NUMBOLLA", -1, 12, _alfafld); // numero bolla
|
||
create_field("DATABOLLA", -1, 8, _longzerofld); // data bolla
|
||
create_field("QTACONS", -1, 7, _alfafld); // qta consegnata
|
||
create_field("QTARESA", -1, 7, _alfafld); // qta resa
|
||
create_field("CODDIP", -1, 1, _alfafld, true, TVariant(dipendenza)); // codice dipendenza
|
||
create_field("FINE-REC", -1, 2, _alfafld, true, TVariant("\r\n")); // a capo
|
||
}
|
||
|
||
///////////////////////////////////////
|
||
// TSkeleton_application
|
||
///////////////////////////////////////
|
||
class THardy_esselunga : public TSkeleton_application
|
||
{
|
||
protected:
|
||
long genera_recordset(const TMask& mask, TISAM_recordset& recset);
|
||
void elabora(const TMask& mask);
|
||
void check_date(const TDate& datafine, TDate& dataini);
|
||
long check_cliente(const long codcf, const TString4 dipendenza);
|
||
TFilename scrivi_testata(const TMask& mask);
|
||
|
||
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;
|
||
query << "USE DOC KEY 3\n";
|
||
|
||
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;
|
||
filt_expr << " SELECT";
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
codnum = row->get(0);
|
||
if (codnum.not_empty())
|
||
{
|
||
filt_expr << " (CODNUM=\"";
|
||
filt_expr << codnum << "\") ||";
|
||
}
|
||
}
|
||
filt_expr.rtrim(2);
|
||
query << filt_expr;
|
||
}
|
||
query << "\nFROM DATADOC=#DATAINI PROVV='D' ANNO=#ANNO";
|
||
query << "\nTO DATADOC=#DATAFIN PROVV='D' ANNO=#ANNO";
|
||
|
||
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();
|
||
}
|
||
|
||
TFilename THardy_esselunga::scrivi_testata(const TMask& mask)
|
||
{
|
||
TConfig config(CONFIG_DITTA, "ha");
|
||
TFilename file_privat = config.get("Esselunga_PrivatPath");
|
||
|
||
const TString& dipendenza = mask.get(F_DIPENDENZA);
|
||
if (dipendenza[0] == 'D')
|
||
file_privat.add("CDMI");
|
||
else
|
||
file_privat.add("CDFI");
|
||
file_privat.ext("txt");
|
||
ofstream file_output(file_privat);
|
||
TString record(260);
|
||
// tipo record/filler/tot_record/progr_record
|
||
record = "PVT*?*001001";
|
||
// nome del file
|
||
record << file_privat.name();
|
||
// identificativo mittente
|
||
record.overwrite(config.get("Esselunga_PIvaHardy"), 85);
|
||
record.overwrite(config.get("Esselunga_TipoEmissione"), 120);
|
||
// identificativo destinatario
|
||
record.overwrite(config.get("Esselunga_PIvaEsselunga"), 138);
|
||
record.overwrite(config.get("Esselunga_TipoEmissione"), 173);
|
||
// formato (Ascii)
|
||
record.overwrite("A", 191);
|
||
// identificativo univoco del documento
|
||
record.overwrite("0000000000000001", 243);
|
||
file_output << record << endl;
|
||
file_output.close();
|
||
return file_privat;
|
||
}
|
||
|
||
void THardy_esselunga::elabora(const TMask& mask)
|
||
{
|
||
TLog_report log;
|
||
const TString4 dipendenza = mask.get(F_DIPENDENZA);
|
||
TFilename file_privat = scrivi_testata(mask);
|
||
TISAM_recordset recset("");
|
||
const long items = genera_recordset(mask, recset);
|
||
if (items == 0)
|
||
log.log(1, "Non esistono documenti che soddisfano i parametri selezionati.");
|
||
|
||
// memorizzo su campo virtuale che il doc. e' stato inviato
|
||
const bool definitivo = mask.get_bool(F_DEFINITIVO);
|
||
const bool forzatura = mask.get_bool(F_FORZATURA);
|
||
|
||
// lettura dei documenti da recordset
|
||
TProgind pi(recset.items(), TR("Elaborazione documenti in corso..."), true, true);
|
||
TPrivat_recordset privat(dipendenza);
|
||
TCodArtEsselunga_cache cache_ca;
|
||
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
|
||
const long codcf_esselunga = check_cliente(codcf, dipendenza);
|
||
if ( codcf_esselunga > 0)
|
||
{
|
||
TDocumento doc(recset.cursor()->curr());
|
||
|
||
if (!forzatura && doc.get_bool("HA_PRIVAT"))
|
||
continue; // Scarta documenti gi<67> inviati
|
||
|
||
// passo tutte le righe del documento all'AS400recordset
|
||
TString16 numdoc;
|
||
const TString& num = doc.numerazione();
|
||
numdoc.format("%012d",doc.numero());
|
||
numdoc << cache().get("%NUM", num, "S7");
|
||
numdoc.strip("/");
|
||
numdoc = numdoc.right(12);
|
||
FOR_EACH_PHYSICAL_RDOC(doc, r, rigadoc)
|
||
{
|
||
const TString& codart = rigadoc->get(RDOC_CODART);
|
||
const TString& codart_esselunga = cache_ca.decode(codart);
|
||
if (codart_esselunga.full())
|
||
{
|
||
privat.new_rec("");
|
||
privat.set("CDC", TVariant(codcf_esselunga));
|
||
privat.set("CODART", codart_esselunga);
|
||
privat.set("NUMBOLLA", numdoc);
|
||
privat.set("DATABOLLA", recset.get(DOC_DATADOC));
|
||
real qta = rigadoc->get_real(RDOC_QTA);
|
||
TString16 qtastr = qta.string(8,2,'0');
|
||
qtastr.strip(".");
|
||
privat.set("QTACONS", qtastr);
|
||
privat.set("QTARESA", "0000000");
|
||
}
|
||
} //FOR_EACH...
|
||
if (definitivo)
|
||
{
|
||
doc.put("HA_PRIVAT", "X");
|
||
doc.rewrite();
|
||
}
|
||
} // if check_cliente...
|
||
} //for (bool ok = recset.move_first()...
|
||
|
||
TFilename tempfile;
|
||
tempfile.temp();
|
||
privat.save_as(tempfile, fmt_text);
|
||
fcopy(tempfile, file_privat, true);
|
||
log.print_or_preview();
|
||
}
|
||
|
||
long THardy_esselunga::check_cliente(const long codcf, const TString4 dipendenza)
|
||
{
|
||
long codcf_hardy = -1;
|
||
TString8 key; key << codcf;
|
||
const TRectype& rec_cliente = cache().get("&CEL", key);
|
||
const bool invio = rec_cliente.get_bool("B0");
|
||
if (invio)
|
||
{
|
||
const char dip_cliente = rec_cliente.get("S1")[0];
|
||
if (dip_cliente == dipendenza[0])
|
||
codcf_hardy = rec_cliente.get_long("I0");
|
||
}
|
||
return codcf_hardy;
|
||
}
|
||
|
||
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, TR("Esselunga: generazione file Privat"));
|
||
return 0;
|
||
} |