3eca115437
Files correlati : lv2 Ricompilazione Demo : [ ] Commento : D. Acquisizione dati da conta pezzi 1) 1-Ignora 2-Somma 3-Sostituisci 2) Se alla fine dico no generazione interrotta e non terminata 3) Creare un file output.old /output1.old per ognuno di quelli presi vuoto 5) Finita la generazione delle bolle mi rimane appesa lultima bolla fatta (da accordi forzo la chiusura del programma) 6)Buoni di ritiro che numero ha dato? 7) Messaggio con numero di documenti generati git-svn-id: svn://10.65.10.50/trunk@19620 c028cbd2-c16b-5b4b-a496-9718f37d4682
969 lines
27 KiB
C++
Executable File
969 lines
27 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <reputils.h>
|
||
#include <reprint.h>
|
||
#include <urldefid.h>
|
||
#include <utility.h>
|
||
|
||
#include "lvlib.h"
|
||
#include "../ve/velib.h"
|
||
|
||
#include "lvcondv.h"
|
||
#include "lvrcondv.h"
|
||
#include "lvrconsplan.h"
|
||
|
||
#include "lv2600a.h"
|
||
|
||
/////////////////////////////
|
||
//// TARTICOLI_KEY ////
|
||
/////////////////////////////
|
||
|
||
//classe TArticoli_key
|
||
class TArticoli_key: public TToken_string
|
||
{
|
||
public:
|
||
const long codcf();
|
||
const char* codart();
|
||
const TDate data();
|
||
|
||
TArticoli_key(long codcf, TString& codart, TDate& data);
|
||
TArticoli_key(const char* key);
|
||
};
|
||
|
||
//CODCF: metodo che restituisce il codcf dalla TToken_string chiave degli articoli
|
||
const long TArticoli_key::codcf()
|
||
{
|
||
return get_int(0);
|
||
}
|
||
|
||
//CODART: metodo che restituisce il codart dalla TToken_string chiave degli articoli
|
||
const char* TArticoli_key::codart()
|
||
{
|
||
return get(1);
|
||
}
|
||
|
||
//DATA: metodo che restituisce la data dalla TToken_string chiave degli articoli
|
||
const TDate TArticoli_key::data()
|
||
{
|
||
return (TDate)get(2);
|
||
}
|
||
|
||
//metodi costruttori
|
||
TArticoli_key::TArticoli_key(long codcf, TString& codart, TDate& data)
|
||
{
|
||
add(codcf);
|
||
add(codart.trim());
|
||
add(data.date2ansi());
|
||
}
|
||
|
||
TArticoli_key::TArticoli_key(const char* key):TToken_string(key)
|
||
{
|
||
}
|
||
|
||
//////////////////////////////
|
||
//// TDOCUMENTI_KEY ////
|
||
//////////////////////////////
|
||
|
||
//classe TDocumenti_key
|
||
class TDocumenti_key: public TToken_string
|
||
{
|
||
public:
|
||
const char* codnum();
|
||
const int anno();
|
||
const long ndoc();
|
||
const int idriga();
|
||
const long codcf();
|
||
const char* codart();
|
||
const TDate data();
|
||
|
||
TDocumenti_key(int anno, long ndoc, int idriga, long codcf, TString& codart, TDate& data);
|
||
TDocumenti_key(const char* key);
|
||
};
|
||
|
||
//CODNUM: metodo che restituisce il codnum dalla TToken_string chiave dei documenti
|
||
const char* TDocumenti_key::codnum()
|
||
{
|
||
return get(0);
|
||
}
|
||
|
||
//ANNO: metodo che restituisce l'anno dalla TToken_string chiave dei documenti
|
||
const int TDocumenti_key::anno()
|
||
{
|
||
return get_int(1);
|
||
}
|
||
|
||
//NDOC: metodo che restituisce il numero documento dalla TToken_string chiave dei documenti
|
||
const long TDocumenti_key::ndoc()
|
||
{
|
||
return get_int(2);
|
||
}
|
||
|
||
//IDRIGA: metodo che restituisce l'idriga dalla TToken_string chiave dei documenti
|
||
const int TDocumenti_key::idriga()
|
||
{
|
||
return get_int(3);
|
||
}
|
||
|
||
//CODCF: metodo che restituisce il codcf dalla TToken_string chiave dei documenti
|
||
const long TDocumenti_key::codcf()
|
||
{
|
||
return get_int(4);
|
||
}
|
||
|
||
//CODART: metodo che restituisce il codart dalla TToken_string chiave dei documenti
|
||
const char* TDocumenti_key::codart()
|
||
{
|
||
return get(5);
|
||
}
|
||
|
||
//DATA: metodo che restituisce la data dalla TToken_string chiave dei documenti
|
||
const TDate TDocumenti_key::data()
|
||
{
|
||
return (TDate)get(6);
|
||
}
|
||
|
||
//metodi costruttori
|
||
TDocumenti_key::TDocumenti_key(int anno, long ndoc, int idriga, long codcf, TString& codart, TDate& data)
|
||
{
|
||
add(ini_get_string(CONFIG_DITTA, "lv", "NUM_RIT(0)"));
|
||
add(anno);
|
||
add(ndoc);
|
||
add(idriga);
|
||
add(codcf);
|
||
add(codart.trim());
|
||
add(data.date2ansi());
|
||
}
|
||
|
||
TDocumenti_key::TDocumenti_key(const char* key):TToken_string(key)
|
||
{
|
||
}
|
||
|
||
//////////////////////////////////
|
||
//// TQUANTITA_CONATATE ////
|
||
//////////////////////////////////
|
||
|
||
//classe TQuantita_contate
|
||
class TQuantita_contate: public TObject
|
||
{
|
||
long _numpezzi;
|
||
long _numrotti;
|
||
|
||
public:
|
||
const long get_pezzi() const;
|
||
const long get_rotti() const;
|
||
|
||
void set_pezzi(const long qta);
|
||
void set_rotti(const long qta);
|
||
|
||
void add_pezzi(const long qta);
|
||
void add_rotti(const long qta);
|
||
|
||
bool is_empty();
|
||
|
||
TQuantita_contate(long pezzi = 0, long rotti = 0);
|
||
};
|
||
|
||
//GET_PEZZI: metodo che restituisce il numero di pezzi contati
|
||
const long TQuantita_contate::get_pezzi() const
|
||
{
|
||
return _numpezzi;
|
||
}
|
||
|
||
//GET_ROTTI: metodo che restituisce il numero di pezzi rotti contati
|
||
const long TQuantita_contate::get_rotti() const
|
||
{
|
||
return _numrotti;
|
||
}
|
||
|
||
//SET_PEZZI: metodo che setta il numero di pezzi contati
|
||
void TQuantita_contate::set_pezzi(const long qta)
|
||
{
|
||
_numpezzi = qta;
|
||
}
|
||
|
||
//SET_ROTTI: metodo che setta il numero di pezzi rotti contati
|
||
void TQuantita_contate::set_rotti(const long qta)
|
||
{
|
||
_numrotti = qta;
|
||
}
|
||
|
||
//ADD_PEZZI: metodo che somma i pezzi contati alla quanti<74> che gi<67> esisteva
|
||
void TQuantita_contate::add_pezzi(const long qta)
|
||
{
|
||
_numpezzi += qta;
|
||
}
|
||
|
||
//ADD_PEZZI: metodo che somma i pezzi rotti contati alla quanti<74> che gi<67> esisteva
|
||
void TQuantita_contate::add_rotti(const long qta)
|
||
{
|
||
_numrotti += qta;
|
||
}
|
||
|
||
//IS_EMPTY: metodo che resituisce true se entrambe le quantit<69> sono a zero
|
||
bool TQuantita_contate::is_empty()
|
||
{
|
||
return _numpezzi == 0 && _numrotti == 0;
|
||
}
|
||
|
||
//metodo costruttore
|
||
TQuantita_contate::TQuantita_contate(long pezzi, long rotti)
|
||
{
|
||
set_pezzi(pezzi);
|
||
set_rotti(rotti);
|
||
}
|
||
|
||
/////////////////////////////////
|
||
//// TARTICOLI_CONTATI ////
|
||
/////////////////////////////////
|
||
|
||
|
||
//classe TArticoli_contati
|
||
class TArticoli_contati: public TAssoc_array
|
||
{
|
||
public:
|
||
TQuantita_contate* quantita(long codcf, TString& codart, TDate& data, bool create = false);
|
||
};
|
||
|
||
//QUANTITA: metodo che cerca nel TAssoc_array le quantit<69> contate in base ai parametri passati
|
||
//e lo crea in automatico se il parametro create vale "true"
|
||
TQuantita_contate* TArticoli_contati::quantita(long codcf, TString& codart, TDate& data, bool create)
|
||
{
|
||
TArticoli_key key(codcf, codart, data);
|
||
|
||
TQuantita_contate* qc = (TQuantita_contate*)objptr(key);
|
||
|
||
if(qc == NULL && create)
|
||
{
|
||
qc = new TQuantita_contate();
|
||
add(key, qc);
|
||
}
|
||
return qc;
|
||
}
|
||
|
||
|
||
/////////////////////////////////
|
||
//// TACQUISIZIONE_MSK ////
|
||
/////////////////////////////////
|
||
|
||
//classe TAcquisizione_msk
|
||
class TAcquisizione_msk: public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o,TField_event e,long jolly);
|
||
public:
|
||
TAcquisizione_msk();
|
||
};
|
||
|
||
//ON_FIELD_EVENT: metodo che gestisce gli eventi sui campi della maschera
|
||
bool TAcquisizione_msk::on_field_event(TOperable_field& f,TField_event e,long jolly)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
//metodo costruttore che precarica i campi di interesse sulla maschera
|
||
TAcquisizione_msk::TAcquisizione_msk():TAutomask("lv2600a")
|
||
{
|
||
TConfig configlv(CONFIG_DITTA, "lv");
|
||
|
||
const TString& path = configlv.get("PathContapezzi");
|
||
set(F_PATH, path);
|
||
|
||
TSheet_field& sheet = sfield(F_SHEET_NAME);
|
||
for (int i = 0; ; i++)
|
||
{
|
||
TString nomefile = configlv.get("FileName", NULL, i);
|
||
if (nomefile.empty())
|
||
break;
|
||
|
||
TToken_string& row = sheet.row(-1);
|
||
row.add(nomefile);
|
||
}
|
||
|
||
sheet.force_update();
|
||
}
|
||
|
||
///////////////////////////////////
|
||
//// TACQUISIZIONE_CACHE ////
|
||
///////////////////////////////////
|
||
|
||
//classe TAcquisizione_cache
|
||
class TAcquisizione_cache : public TCache
|
||
{
|
||
TString4 _codnum, _tipodoc, _stato;
|
||
long _ndoc;
|
||
|
||
protected:
|
||
virtual void discarding(const THash_object* obj);
|
||
virtual TObject* key2obj(const char* key);
|
||
|
||
public:
|
||
TDocumento& doc(const TDate& gg, const long cc);
|
||
TAcquisizione_cache();
|
||
};
|
||
|
||
//DISCARDING: metodo che salva un documento sul disco prima di eliminarlo dalla cache
|
||
void TAcquisizione_cache::discarding(const THash_object* obj)
|
||
{
|
||
TDocumento& doc = (TDocumento&)obj->obj();
|
||
int err = doc.rewrite();
|
||
}
|
||
|
||
//KEY2OBJ: metodo che sceglie il documento giusto da disco in modo da poterlo continuare, o lo crea se non c'<27>
|
||
TObject* TAcquisizione_cache::key2obj(const char* key)
|
||
{
|
||
TToken_string chiave(key);
|
||
TDate datadoc = chiave.get();
|
||
const TDate datagen(TODAY);
|
||
TDate dadata = datadoc;
|
||
TDate adata = datagen;
|
||
adata.addmonth();
|
||
const long codcf = chiave.get_long();
|
||
|
||
if(_ndoc == 0)
|
||
{
|
||
TString query2;
|
||
query2 << "USE DOC\n"
|
||
<< "FROM PROVV=\"D\" ANNO=" << datadoc.year() << " CODNUM=\"" << _codnum << "\"\n"
|
||
<< "TO PROVV=\"D\" ANNO=" << datadoc.year() << " CODNUM=\"" << _codnum << "\"";
|
||
TISAM_recordset sporco(query2);
|
||
sporco.move_last();
|
||
_ndoc = sporco.get(DOC_NDOC).as_int();
|
||
}
|
||
|
||
TString query = "USE DOC KEY 2\n";
|
||
query << "SELECT (TIPODOC=\"" << _tipodoc << "\")&&(STATO=\"" << _stato <<"\")\n";
|
||
query << "FROM TIPOCF=C CODCF=" << codcf << " PROVV=D ANNO=" << datadoc.year() << " DATADOC=" << datadoc << " CODNUM=" << _codnum << "\n";
|
||
query << "TO TIPOCF=C CODCF=" << codcf << " PROVV=D ANNO=" << datadoc.year() << " DATADOC=" << datadoc << " CODNUM=" << _codnum << "\n";
|
||
TISAM_recordset rset(query);
|
||
|
||
TDocumento* doc = NULL;
|
||
|
||
if (rset.move_first())
|
||
doc = new TDocumento(rset.cursor()->curr());
|
||
else
|
||
{
|
||
TLaundry_contract cont(codcf, 0, datadoc);
|
||
const TString8 codcont = cont.get(LVCONDV_CODCONT);
|
||
|
||
TString query1 = "USE LVRCONSPLAN KEY 3\n";
|
||
query1 << "FROM CODCF=" << codcf << " CODCONT=" << codcont << " DTCONS=#DADATA\n";
|
||
query1 << "TO CODCF=" << codcf << " CODCONT=" << codcont << " DTCONS=#ADATA\n";
|
||
TISAM_recordset consegne(query1);
|
||
consegne.set_var("#DADATA", ++dadata);
|
||
consegne.set_var("#ADATA", adata);
|
||
consegne.move_first();
|
||
const TDate dataprco = consegne.get(LVRCONSPLAN_DTCONS).as_date();
|
||
|
||
//recupero il codpag
|
||
TToken_string key;
|
||
key.add('C');
|
||
key.add(codcf);
|
||
const TString4 codpag = cache().get(LF_CLIFO, key, CLI_CODPAG);
|
||
|
||
//reupero la cuasale di magazzino di testata
|
||
const TString16 causmag = cache().get("%TIP", _tipodoc, "S9");
|
||
|
||
doc = new TDocumento('D', datadoc.year(), _codnum, ++_ndoc);
|
||
doc->put(DOC_TIPODOC, _tipodoc);
|
||
doc->put(DOC_STATO, _stato);
|
||
doc->put(DOC_DATADOC, datadoc);
|
||
doc->put(DOC_TIPOCF, 'C');
|
||
doc->put(DOC_CODCF, codcf);
|
||
doc->put(DOC_CODCONT, codcont);
|
||
doc->put(DOC_CODPAG, codpag);
|
||
doc->put(DOC_CAUSMAG, causmag);
|
||
doc->put("DATACON", datadoc); //data conteggio
|
||
doc->put("DATAGEN", datagen); //data generazione del documento
|
||
doc->put("DATAPRCO", dataprco); //data prevista consegna
|
||
}
|
||
return doc;
|
||
}
|
||
|
||
//DOC: metodo che restituisce un puntatore ad un documento identificato dalla coppia data - cliente
|
||
TDocumento& TAcquisizione_cache::doc(const TDate& gg, const long cc)
|
||
{
|
||
TString16 key;
|
||
key << gg.date2ansi() << '|' << cc;
|
||
return *(TDocumento*)objptr(key);
|
||
}
|
||
|
||
//metodo costruttore di una cache di 17 elementi
|
||
TAcquisizione_cache::TAcquisizione_cache() : TCache(17)
|
||
{
|
||
_codnum = ini_get_string(CONFIG_DITTA, "lv", "NUM_RIT(0)");
|
||
_tipodoc = ini_get_string(CONFIG_DITTA, "lv", "TIPODOC_RIT(0)");
|
||
_stato = cache().get("%TIP", _tipodoc, "S2").left(1);
|
||
|
||
_ndoc = 0;
|
||
}
|
||
|
||
///////////////////////////////////
|
||
//// TCONFRONTO_CACHE ////
|
||
///////////////////////////////////
|
||
|
||
//classe TConfronto_cache
|
||
class TConfronto_cache : public TCache
|
||
{
|
||
TString4 _codnum, _tipodoc, _stato;
|
||
|
||
protected:
|
||
virtual void discarding(const THash_object* obj);
|
||
virtual TObject* key2obj(const char* key);
|
||
|
||
public:
|
||
TDocumento& doc(const TDate& gg, const long cc);
|
||
TConfronto_cache();
|
||
};
|
||
|
||
//DISCARDING: metodo che salva un documento sul disco prima di eliminarlo dalla cache
|
||
void TConfronto_cache::discarding(const THash_object* obj)
|
||
{
|
||
TDocumento& doc = (TDocumento&)obj->obj();
|
||
if (!doc.empty())
|
||
int err = doc.rewrite();
|
||
}
|
||
|
||
//KEY2OBJ: metodo che sceglie il documento giusto da disco in modo da poterlo continuare, o lo crea se non c'<27>
|
||
TObject* TConfronto_cache::key2obj(const char* key)
|
||
{
|
||
TToken_string chiave(key);
|
||
TDate datadoc = chiave.get();
|
||
const TDate datagen(TODAY);
|
||
TDate adata = datagen;
|
||
adata.addmonth();
|
||
const long codcf = chiave.get_long();
|
||
|
||
TString query = "USE DOC KEY 2\n";
|
||
query << "SELECT (TIPODOC=\"" << _tipodoc << "\")&&(STATO=\"" << _stato <<"\")\n";
|
||
query << "FROM TIPOCF=C CODCF=" << codcf << " PROVV=D ANNO=" << datadoc.year() << " DATADOC=" << datadoc << " CODNUM=" << _codnum << "\n";
|
||
query << "TO TIPOCF=C CODCF=" << codcf << " PROVV=D ANNO=" << datadoc.year() << " DATADOC=" << datadoc << " CODNUM=" << _codnum << "\n";
|
||
TISAM_recordset rset(query);
|
||
|
||
TDocumento* doc = NULL;
|
||
|
||
if (rset.move_first())
|
||
doc = new TDocumento(rset.cursor()->curr());
|
||
else
|
||
doc = new TDocumento();
|
||
|
||
return doc;
|
||
}
|
||
|
||
//DOC: metodo che restituisce un puntatore ad un documento identificato dalla coppia data - cliente
|
||
TDocumento& TConfronto_cache::doc(const TDate& gg, const long cc)
|
||
{
|
||
TString16 key;
|
||
key << gg.date2ansi() << '|' << cc;
|
||
return *(TDocumento*)objptr(key);
|
||
}
|
||
|
||
//metodo costruttore di una cache di 17 elementi
|
||
TConfronto_cache::TConfronto_cache() : TCache(17)
|
||
{
|
||
_codnum = ini_get_string(CONFIG_DITTA, "lv", "NUM_RIT(0)");
|
||
_tipodoc = ini_get_string(CONFIG_DITTA, "lv", "TIPODOC_RIT(0)");
|
||
_stato = cache().get("%TIP", _tipodoc, "S2").left(1);
|
||
}
|
||
|
||
////////////////////////////////////////////
|
||
//// TACQUISIZIONE_LAVANDERIE_APP ////
|
||
////////////////////////////////////////////
|
||
|
||
//classe TAcquisizione_lavanderie_app
|
||
class TAcquisizione_lavanderie_app : public TSkeleton_application
|
||
{
|
||
TAcquisizione_msk* _msk;
|
||
TString4 _auto;
|
||
TString4 _gr;
|
||
|
||
protected:
|
||
virtual bool create();
|
||
virtual bool destroy();
|
||
|
||
bool elabora_file(const TString& file, TLog_report &rep, TArticoli_contati& articoli, int& nrighe, int& nrsalt);
|
||
void controlla_documenti(TLog_report& rep, TArticoli_contati& articoli, TAssoc_array& documenti);
|
||
void genera_documenti(TLog_report& rep, TAssoc_array& documenti);
|
||
void sposta_file(const TString& file);
|
||
|
||
public:
|
||
bool transfer();
|
||
virtual void main_loop();
|
||
};
|
||
|
||
//CREATE: metodo costruttore
|
||
bool TAcquisizione_lavanderie_app::create()
|
||
{
|
||
_msk = new TAcquisizione_msk();
|
||
TSheet_field& sheet = _msk->sfield(F_SHEET_NAME);
|
||
sheet.set_auto_append();
|
||
|
||
//se ho pi<70> di un parametro, allora lo sto lanciando da linea di comando, e ne devo tenere conto
|
||
if (argc() > 2)
|
||
{
|
||
_auto = argv(2);
|
||
_auto = _auto.right(1);
|
||
|
||
_gr = argv(3);
|
||
_gr = _gr.right(1);
|
||
|
||
}
|
||
else
|
||
{
|
||
_auto = "N";
|
||
_gr = "";
|
||
}
|
||
|
||
if (_gr == "S" || _gr.empty())
|
||
_msk->set(F_RICGIRI, "X");
|
||
else
|
||
_msk->set(F_RICGIRI, "");
|
||
|
||
open_files(LF_DOC, LF_RIGHEDOC);
|
||
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
//DESTROY: metodo distruttore
|
||
bool TAcquisizione_lavanderie_app::destroy()
|
||
{
|
||
delete _msk;
|
||
return TApplication::destroy();
|
||
}
|
||
|
||
//ELABORA_FILE: metodo che effettivamente fa l'elaborazione del file
|
||
bool TAcquisizione_lavanderie_app::elabora_file(const TString& file, TLog_report& rep, TArticoli_contati& articoli, int& nrighe, int& nrsalt)
|
||
{
|
||
//scandisco il file solo se esiste
|
||
TFilename strname = file;
|
||
|
||
TScanner s(file);
|
||
while (s.ok())
|
||
{
|
||
TString80 riga = s.line();
|
||
if (riga.blank())
|
||
continue;
|
||
|
||
TDate datadoc;
|
||
long codcf = 0; TString8 codcf_str;
|
||
TString80 codart;
|
||
long qta;
|
||
long rotti;
|
||
long ndoc = 0;
|
||
TString16 tipo_conteggio;
|
||
TString80 operatore;
|
||
|
||
//controllo quale tracciato record devo seguire
|
||
if (riga.len() == 34) // -> MONTANARI
|
||
{
|
||
nrighe += 1;
|
||
//leggo i campi dalla riga del file
|
||
const int d = atoi(riga.mid(0,2));
|
||
const int m = atoi(riga.mid(2,2));
|
||
const int y = atoi(riga.mid(4,4));
|
||
if (d > 0 && d <= 31 && m > 0 && m <= 12 && y > 2000)
|
||
{
|
||
datadoc = TDate(d, m, y);
|
||
if (datadoc < _msk->get_date(F_DADATA) || datadoc > _msk->get_date(F_ADATA))
|
||
{
|
||
nrsalt += 1;
|
||
continue;
|
||
}
|
||
|
||
codcf_str = riga.mid(8,6); codcf = atol(codcf_str);
|
||
codart = riga.mid(14,8);
|
||
qta = atol(riga.mid(22,6));
|
||
rotti = atol(riga.mid(28,6));
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
else if (riga.len() == 121) // ->SKEMA
|
||
{
|
||
//leggo i campi dalla riga del file
|
||
const int y = atoi(riga.mid(0,4));
|
||
const int m = atoi(riga.mid(4,2));
|
||
const int d = atoi(riga.mid(6,2));
|
||
if (d > 0 && d <= 31 && m > 0 && m <= 12 && y > 2000)
|
||
{
|
||
codcf_str = riga.mid(28,20); codcf = atol(codcf_str);
|
||
datadoc = TDate(d, m, y);
|
||
codart = riga.mid(8,20);
|
||
qta = atoi(riga.mid(48,11));
|
||
ndoc = atoi(riga.mid(59,11));
|
||
|
||
switch (atoi(riga.mid(70,11)))
|
||
{
|
||
case 1: tipo_conteggio = "Automatico"; break;
|
||
case 2: tipo_conteggio = "Manuale"; break;
|
||
case 3: tipo_conteggio = "Scarto"; break;
|
||
default: break;
|
||
}
|
||
operatore = riga.mid(81,40);
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
|
||
TQuantita_contate* qc = articoli.quantita(codcf, codart.trim(), datadoc, true);
|
||
|
||
//se la chiave <20> gi<67> presente nel TAssoc_array, chiedi cosa fare delle quantit<69>
|
||
//altrimenti aggiungila con la rispettiva al TAssoc_array con la quantit<69> appena conteggiata
|
||
if (!qc->is_empty())
|
||
{
|
||
TString str;
|
||
str << "ATTENZIONE: <20> gi<67> presente un conteggio per il cliente " << codcf << " sull'articolo " << codart << "\n"
|
||
<< "Quantit<EFBFBD> conteggio attuale: " << qta << " Quantit<69> conteggio precedente: " << qc->get_pezzi() << "\n"
|
||
<< "Si desidera sommare le quantit<69>?\n"
|
||
<< "(SI -> Somma NO -> Ignora Conteggio ANNULLA -> Sosituisci il conteggio precedente)\n";
|
||
|
||
KEY k = yesnocancel_box(str);
|
||
|
||
switch (k)
|
||
{
|
||
case K_YES: qc->add_pezzi(qta); qc->add_rotti(rotti); break; //sommo le quantit<69>
|
||
case K_NO: break; //lascio tutto com'<27>
|
||
default: qc->set_pezzi(qta); qc->set_rotti(rotti); break; //sostituisco le quantit<69>
|
||
}
|
||
}
|
||
else
|
||
{
|
||
qc->set_pezzi(qta);
|
||
qc->set_rotti(rotti);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//CONTROLLA_DOCUMENTI: metodo che si occupa di controllare se i dati che sto inserendo in questo momento sono
|
||
//gi<67> stati inseriti in documenti precedenti, chiedendo cosa fare di volta in volta
|
||
void TAcquisizione_lavanderie_app::controlla_documenti(TLog_report& rep, TArticoli_contati& articoli, TAssoc_array& documenti)
|
||
{
|
||
TConfronto_cache ca;
|
||
bool found = false;
|
||
FOR_EACH_ASSOC_OBJECT(articoli, obj, key, itm)
|
||
{
|
||
TArticoli_key keyart(key);
|
||
const TQuantita_contate* qc = (TQuantita_contate*)itm;
|
||
|
||
//recupero i dati dalla chiave del TAssoc_array degli articoli
|
||
int codcf = keyart.codcf();
|
||
TString80 codart = keyart.codart();
|
||
TDate datadoc = keyart.data();
|
||
|
||
//recupero i dati dal contenuto del TAssoc_array degli articoli
|
||
TQuantita_contate* quantita = new TQuantita_contate(0, 0);
|
||
quantita->set_pezzi(qc->get_pezzi());
|
||
quantita->set_rotti(qc->get_rotti());
|
||
|
||
TDocumento& doc = ca.doc(datadoc, codcf);
|
||
if (doc.empty())
|
||
{
|
||
//preparo la chiave per il TAssoc_array dei documenti
|
||
TDocumenti_key keydoc(datadoc.year(), 0, 0, codcf, codart, datadoc);
|
||
|
||
//aggiungo la riga corrispondente
|
||
documenti.add(keydoc, quantita);
|
||
}
|
||
else
|
||
{
|
||
int idriga;
|
||
for (idriga = 1; idriga <= doc.rows(); idriga++)
|
||
{
|
||
//cerco se esiste gi<67> una riga sul documento selezionato per quell'articolo
|
||
TRiga_documento& rdoc = doc[idriga];
|
||
TString80 codart_doc = rdoc.get(RDOC_CODART); codart_doc.trim();
|
||
|
||
if (codart_doc == codart)
|
||
{
|
||
found = true;
|
||
|
||
TString str;
|
||
str << "ATTENZIONE: <20> gi<67> presente un buono di ritiro per il cliente " << codcf << " sull'articolo " << codart << "\n"
|
||
<< "Quantit<EFBFBD> conteggio: " << quantita->get_pezzi() << " Quantit<69> buono di ritiro: " << rdoc.get_int(RDOC_QTAGG1) << "\n"
|
||
<< "Si desidera sommare le quantit<69>?\n"
|
||
<< "(SI -> Somma NO -> Ignora Conteggio ANNULLA -> Modifica Buono)\n";
|
||
|
||
KEY k = yesnocancel_box(str);
|
||
|
||
switch (k)
|
||
{
|
||
case K_YES: quantita->add_pezzi(rdoc.get_int(RDOC_QTAGG1)); quantita->add_rotti(rdoc.get_int(RDOC_QTA)); break; //sommo le quantit<69>
|
||
case K_NO: quantita->set_pezzi(rdoc.get_int(RDOC_QTAGG1)); quantita->set_rotti(rdoc.get_int(RDOC_QTA)); break; //lascio tutto com'<27>
|
||
default: break; //sostituisco le quantit<69>
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!found)
|
||
idriga = 0;
|
||
//preparo la chiave per il TAssoc_array dei documenti
|
||
TDocumenti_key keydoc(datadoc.year(), doc.get_long(DOC_NDOC), idriga, codcf, codart, datadoc);
|
||
|
||
documenti.add(keydoc, quantita);
|
||
}
|
||
}
|
||
ca.destroy();
|
||
}
|
||
|
||
//metodo che effettivamente genera i buoni di ritiro, se l'utente ha confermato la sua intenzione a crearli
|
||
void TAcquisizione_lavanderie_app::genera_documenti(TLog_report& rep, TAssoc_array& documenti)
|
||
{
|
||
TAcquisizione_cache ca;
|
||
|
||
const bool giri = _msk->get_bool(F_RICGIRI);
|
||
FOR_EACH_ASSOC_OBJECT(documenti, obj, key, itm)
|
||
{
|
||
TDocumenti_key keydoc(key);
|
||
const TString4 codnum = keydoc.codnum();
|
||
const int anno = keydoc.anno();
|
||
const int ndoc = keydoc.ndoc();
|
||
const int idriga = keydoc.idriga();
|
||
const int codcf = keydoc.codcf();
|
||
const TString80 codart = keydoc.codart();
|
||
const TDate datadoc = keydoc.data();
|
||
|
||
TQuantita_contate* qc = (TQuantita_contate*)itm;
|
||
const long qtacon = qc->get_pezzi();;
|
||
const long qtarotti = qc->get_rotti();
|
||
|
||
TLaundry_contract cont(codcf, 0, datadoc);
|
||
const TString8 codcont = cont.get(LVCONDV_CODCONT);
|
||
|
||
TDate oggi(TODAY);
|
||
|
||
TDocumento& doc = ca.doc(datadoc, codcf);
|
||
if (!giri)
|
||
doc.put("DATAPRCO", oggi);
|
||
|
||
if (doc.rows() > 0 && (idriga > 0 && idriga <= doc.rows()))
|
||
{
|
||
TRiga_documento& rdoc = doc[idriga];
|
||
rdoc.put(RDOC_QTAGG1, qtacon);
|
||
rdoc.put(RDOC_QTA, qtarotti);
|
||
}
|
||
else
|
||
{
|
||
const TRectype& anamag = cache().get(LF_ANAMAG, codart);
|
||
|
||
TRiga_documento& rdoc = doc.new_row("22");
|
||
rdoc.put(RDOC_CODART, codart);
|
||
rdoc.put(RDOC_DESCR, anamag.get(ANAMAG_DESCR));
|
||
rdoc.put(RDOC_CODARTMAG, codart);
|
||
rdoc.put(RDOC_CHECKED, 'X');
|
||
rdoc.put(RDOC_CODAGG1, ini_get_string(CONFIG_DITTA, "lv", "CAUSLAV"));
|
||
rdoc.put(RDOC_QTAGG1, qtacon);
|
||
rdoc.put(RDOC_QTA, qtarotti);
|
||
rdoc.put(RDOC_CODIVA, anamag.get(ANAMAG_CODIVA));
|
||
}
|
||
|
||
if (!doc.get_date("DATAPRCO").ok() && giri)
|
||
{
|
||
TString msg;
|
||
msg << TR("Il documento ") << doc.get(DOC_NDOC) << TR(" del ") << doc.get(DOC_DATADOC)
|
||
<< TR(" del cliente ") << codcf << TR(" non ha data di prevista consegna.");
|
||
rep.log(1,msg);
|
||
}
|
||
}
|
||
|
||
if (ca.empty())
|
||
{
|
||
warning_box(TR("ATTENZIONE: il file importato non ha generato nessun documento; controllare che il tracciato record sia coerente"));
|
||
return;
|
||
}
|
||
else
|
||
ca.destroy();
|
||
}
|
||
|
||
//SPOSTA_FILE: metodo che sposta cambiando nome i file elaborati durante la generazione dei buoni
|
||
void TAcquisizione_lavanderie_app::sposta_file(const TString& file)
|
||
{
|
||
TFilename fileori = file;
|
||
TFilename path = fileori.path();
|
||
path.add("elaborati");
|
||
make_dir(path);
|
||
|
||
TString strname;
|
||
strname.format("%06d_%06d_%s", TDate(TODAY).date2ansi(), daytime(), (const char*)fileori.name());
|
||
TFilename filedest = path;
|
||
filedest.add(strname);
|
||
|
||
//se la ciopia <20> andata a buon fine, creo un file .old vuoto e cancello il file .dat
|
||
if (fcopy(fileori, filedest))
|
||
{
|
||
TFilename fileold;
|
||
fileold = fileori.path();
|
||
|
||
TString strn = fileori.name_only();
|
||
strn << ".old";
|
||
|
||
fileold.add(strn);
|
||
|
||
fclose(fopen(fileold, "w"));
|
||
|
||
fileori.fremove();
|
||
}
|
||
}
|
||
|
||
//TRANSFER: metodo che scorre i campi nome e, se sono pieni, richiama il metodo
|
||
//ELABORA_FILE(), che effettivamente fa l'elaborazione
|
||
bool TAcquisizione_lavanderie_app::transfer()
|
||
{
|
||
//prendo il path dalla maschera
|
||
const TString& path = _msk->get(F_PATH);
|
||
TSheet_field& sheet = _msk->sfield(F_SHEET_NAME);
|
||
TFilename file;
|
||
|
||
TLog_report logrep("Aquisizione da contapezzi");
|
||
logrep.kill_duplicates(true);
|
||
|
||
TArticoli_contati articoli;
|
||
TAssoc_array documenti;
|
||
int nrighe = 0;
|
||
int nrsalt = 0;
|
||
|
||
//per ogni riga dello sheet, leggo il suo contenuto, se contiene dei caratteri jolly
|
||
//preparo la lista dei file che soddisfano la maschera in quella directory e li elaboro
|
||
//tutti, altrimenti elaboro esattamente il file che <20> scritto sullo sheet
|
||
bool elaborato = false;
|
||
FOR_EACH_SHEET_ROW(sheet, r1, row1)
|
||
{
|
||
if(row1->full())
|
||
{
|
||
if (row1->find('/') >= 0 || row1->find('\\') >= 0)
|
||
file = *row1;
|
||
else
|
||
{
|
||
file = path;
|
||
file.add(*row1);
|
||
}
|
||
|
||
bool esiste = false;
|
||
|
||
if (file.find('*') >= 0 || file.find('?') >= 0)
|
||
{
|
||
TString_array lista_file;
|
||
list_files(file, lista_file);
|
||
|
||
FOR_EACH_ARRAY_ROW(lista_file, r2, row2)
|
||
{
|
||
TFilename strname = *row2;
|
||
if (strname.exist())
|
||
{
|
||
esiste = true;
|
||
elaborato = elabora_file(*row2, logrep, articoli, nrighe, nrsalt);
|
||
}
|
||
}
|
||
|
||
}
|
||
else if(file.exist())
|
||
{
|
||
esiste = true;
|
||
elaborato = elabora_file(file, logrep, articoli, nrighe, nrsalt);
|
||
}
|
||
|
||
if (!esiste)
|
||
{
|
||
TString str;
|
||
str << "ATTENZIONE: non <20> stato trovato nessun file da elaborare";
|
||
warning_box(str);
|
||
}
|
||
}
|
||
}
|
||
|
||
if(elaborato)
|
||
{
|
||
controlla_documenti(logrep, articoli, documenti);
|
||
|
||
bool genera = false;
|
||
|
||
if (nrsalt > 0)
|
||
{
|
||
TString str;
|
||
str << "Sono stati ricevuti " << nrighe << " record, di cui " << nrighe - nrsalt << " sono stati elaborati correttamente"
|
||
<< " e " << nrsalt << " ignorati.\nSi desidera procedere con la generazione dei buoni di ritiro?";
|
||
|
||
if (yesno_box(str))
|
||
genera = true;
|
||
}
|
||
|
||
if (nrsalt == 0 || genera)
|
||
{
|
||
|
||
genera_documenti(logrep, documenti);
|
||
|
||
//diagnostica
|
||
TString str;
|
||
if (documenti.items() > 1)
|
||
str << "Sono stati generati " << documenti.items() << " buoni di ritiro.";
|
||
else
|
||
str << "E' stato generato " << documenti.items() << " buono di ritiro.";
|
||
|
||
message_box(str);
|
||
|
||
FOR_EACH_SHEET_ROW(sheet, r1, row1)
|
||
{
|
||
if(row1->full())
|
||
{
|
||
if (row1->find('/') >= 0 || row1->find('\\') >= 0)
|
||
file = *row1;
|
||
else
|
||
{
|
||
file = path;
|
||
file.add(*row1);
|
||
}
|
||
|
||
if (file.find('*') >= 0 || file.find('?') >= 0)
|
||
{
|
||
TString_array lista_file;
|
||
list_files(file, lista_file);
|
||
|
||
FOR_EACH_ARRAY_ROW(lista_file, r2, row2)
|
||
{
|
||
TFilename strname(*row2);
|
||
if (strname.exist())
|
||
sposta_file(*row2);
|
||
}
|
||
}
|
||
else if (file.exist())
|
||
sposta_file(file);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (_auto == "A")
|
||
_msk->send_key(K_SPACE, DLG_QUIT);
|
||
else
|
||
{
|
||
TReport_book buc;
|
||
buc.add(logrep);
|
||
if (buc.pages() > 0)
|
||
buc.preview();
|
||
else
|
||
if (genera)
|
||
message_box(TR("Generazione terminata"));
|
||
else
|
||
message_box(TR("Generazione interrotta"));
|
||
_msk->send_key(K_SPACE, DLG_QUIT);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
void TAcquisizione_lavanderie_app::main_loop()
|
||
{
|
||
//lo lancio in automatico da linea di comando
|
||
if (_auto == "A")
|
||
_msk->send_key(K_SPACE, DLG_OK);
|
||
while (_msk->run() == K_ENTER)
|
||
transfer();
|
||
}
|
||
|
||
int lv2600(int argc, char *argv[])
|
||
{
|
||
TAcquisizione_lavanderie_app a;
|
||
a.run (argc, argv, "Acquisizione bolle di rientro/ritiro");
|
||
return TRUE;
|
||
}
|