Patch level : 10.0 patch 416

Files correlati     : lv2
Ricompilazione Demo : [ ]
Commento            :
Evitate le write di documenti che devono ancora essere popolati dalle righe; in questo modo si evitano errori in fase di riscritura degli stessi documenti


git-svn-id: svn://10.65.10.50/trunk@19209 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
luca83 2009-08-19 09:47:20 +00:00
parent 02a23e8e0c
commit eb5814e098
2 changed files with 87 additions and 26 deletions

View File

@ -45,11 +45,12 @@ class TGenera_documenti_app : public TSkeleton_application
TAssoc_array _quantita_ritirata; TAssoc_array _quantita_ritirata;
TConfig* _configlv; TConfig* _configlv;
char _buono; char _buono;
long _ndoc;
private: private:
//Metodi per la generazione dei documenti //Metodi per la generazione dei documenti
bool crea_documento(const TISAM_recordset& plan); bool crea_documento(const TISAM_recordset& plan, TLog_report& rep);
void crea_riga(const TString& codart, const char modpas, const int tplis, const bool tmp, const bool prinbo,TDocumento& doc); void crea_riga(const TString& codart, const char modpas, const int tplis, const bool tmp, const bool prinbo,TDocumento& doc, TLog_report& rep);
//Metodi per il recupero di codnum, tpdoc, stato //Metodi per il recupero di codnum, tpdoc, stato
bool numerazione_ddt(TString& codnum, TString& tpdoc, TString& statoi, TString& statof) const; bool numerazione_ddt(TString& codnum, TString& tpdoc, TString& statoi, TString& statof) const;
bool numerazione_drit(const int cod, TString& codnum, TString& tpdoc, TString& statoi, TString& statof) const; bool numerazione_drit(const int cod, TString& codnum, TString& tpdoc, TString& statoi, TString& statof) const;
@ -84,6 +85,8 @@ bool TGenera_documenti_app::create()
{ {
open_files(LF_DOC, 34, 0); open_files(LF_DOC, 34, 0);
_msk = new TGenera_documenti_mask("lv2400a"); _msk = new TGenera_documenti_mask("lv2400a");
_ndoc = 0;
_configlv = new TConfig(CONFIG_DITTA,"lv"); _configlv = new TConfig(CONFIG_DITTA,"lv");
_buono = *TApplication::argv(2); _buono = *TApplication::argv(2);
return TSkeleton_application::create(); return TSkeleton_application::create();
@ -111,7 +114,7 @@ bool TGenera_documenti_app::destroy()
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
//CREA_DOCUMENTO: metodo che crea un nuovo documento di trasporto dai dati salvati //CREA_DOCUMENTO: metodo che crea un nuovo documento di trasporto dai dati salvati
bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan) bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan, TLog_report& rep)
{ {
//recupero i dati di interesse dalla maschera //recupero i dati di interesse dalla maschera
const TDate datagen(TODAY); const TDate datagen(TODAY);
@ -155,11 +158,20 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan)
if (!numerazione_ddt(codnum, tpdoc, statoi, statof)) if (!numerazione_ddt(codnum, tpdoc, statoi, statof))
return NOERR; return NOERR;
if(_ndoc == 0)
{
TString query2;
query2 << "USE DOC\n"
<< "FROM PROVV=\"D\" ANNO=" << anno << "CODNUM=\"" << codnum << "\"\n"
<< "TO PROVV=\"D\" ANNO=" << anno << "CODNUM=\"" << codnum << "\"";
TISAM_recordset sporco(query2);
sporco.move_last();
_ndoc = sporco.get(DOC_NDOC).as_int();
}
//creo il documento corretto riempiendo i campi che già conosco //creo il documento corretto riempiendo i campi che già conosco
TDocumento doc('D',anno,codnum,0); TDocumento doc('D', anno, codnum, ++_ndoc);
doc.put(DOC_TIPODOC, tpdoc); doc.put(DOC_TIPODOC, tpdoc);
//doc.write();
//calcola tutte le quantità riportate sui documenti di ritiro, sui documenti di anticipo e sulle bolle di consegna //calcola tutte le quantità riportate sui documenti di ritiro, sui documenti di anticipo e sulle bolle di consegna
//...eventualmente modificate a mano //...eventualmente modificate a mano
@ -197,7 +209,7 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan)
FOR_EACH_ASSOC_OBJECT(_quantita,h,codart,obj) FOR_EACH_ASSOC_OBJECT(_quantita,h,codart,obj)
{ {
crea_riga(codart, modpas, tplis, false, prinbo, doc); crea_riga(codart, modpas, tplis, false, prinbo, doc, rep);
/*const TDate dadata = rcont.get(LVRCONDV_INDTTMP).as_date(); /*const TDate dadata = rcont.get(LVRCONDV_INDTTMP).as_date();
const TDate adata = rcont.get(LVRCONDV_FIDTTMP).as_date(); const TDate adata = rcont.get(LVRCONDV_FIDTTMP).as_date();
@ -206,7 +218,7 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan)
} }
if (doc.rows() > 0) if (doc.rows() > 0)
err = doc.write(); err = doc.rewrite();
else else
doc.remove(); doc.remove();
@ -224,7 +236,7 @@ bool TGenera_documenti_app::crea_documento(const TISAM_recordset& plan)
} }
//CREA_RIGA: questa funzione crea una riga merce per una bolla di consegna //CREA_RIGA: questa funzione crea una riga merce per una bolla di consegna
void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, const int tplis, const bool tmp, const bool prinbo, TDocumento& doc) void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas, const int tplis, const bool tmp, const bool prinbo, TDocumento& doc, TLog_report& rep)
{ {
const int perarr = _configlv->get_int("Perarr"); const int perarr = _configlv->get_int("Perarr");
@ -388,6 +400,17 @@ void TGenera_documenti_app::crea_riga(const TString& codart, const char modpas,
rdoc.put(RDOC_CODMAG, magazzino); rdoc.put(RDOC_CODMAG, magazzino);
rdoc.put(RDOC_CODMAGC, magazzinoc); rdoc.put(RDOC_CODMAGC, magazzinoc);
//se il record di riga contratto è vuoto aggiorno il log
if (rcont.empty())
{
TString str;
str << "L'articolo " << codart << " inserito nel documento " << doc.get(DOC_CODNUM) << "-" << doc.get(DOC_TIPODOC)
<< " numero " << doc.get(DOC_NDOC) << " in quantità " << quantita_arr
<< "non è prsente sul contratto del cliente " << codcli;
rep.log(1, str);
}
} }
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
@ -766,6 +789,9 @@ bool TGenera_documenti_app::transfer()
TString4 statof; TString4 statof;
// bool err; // bool err;
TLog_report rep("Articoli non in contratto");
rep.kill_duplicates();
numerazione_drit(0, codnum, tpdoc, statoi, statof); numerazione_drit(0, codnum, tpdoc, statoi, statof);
//instanzio un recordset che contiene tutti i documenti di interesse //instanzio un recordset che contiene tutti i documenti di interesse
@ -829,10 +855,15 @@ bool TGenera_documenti_app::transfer()
{ {
_quantita.destroy(); _quantita.destroy();
_quantita_ritirata.destroy(); _quantita_ritirata.destroy();
crea_documento(plan); crea_documento(plan, rep);
} }
} }
TReport_book buc;
buc.add(rep);
if (buc.pages() > 0)
buc.preview();
else
message_box(TR("Generazione terminata")); message_box(TR("Generazione terminata"));
return true; return true;
} }

View File

@ -68,6 +68,7 @@ TAcquisizione_msk::TAcquisizione_msk():TAutomask("lv2600a")
class TAcquisizione_cache : public TCache class TAcquisizione_cache : public TCache
{ {
TString4 _codnum, _tipodoc, _stato; TString4 _codnum, _tipodoc, _stato;
long _ndoc;
protected: protected:
virtual void discarding(const THash_object* obj); virtual void discarding(const THash_object* obj);
@ -92,9 +93,20 @@ TObject* TAcquisizione_cache::key2obj(const char* key)
const TDate datadoc = chiave.get(); const TDate datadoc = chiave.get();
const TDate datagen(TODAY); const TDate datagen(TODAY);
TDate adata = datagen; TDate adata = datagen;
adata.set_month(datagen.month() + 1); adata.addmonth();
const long codcf = chiave.get_long(); 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"; TString query = "USE DOC KEY 2\n";
query << "SELECT (TIPODOC=\"" << _tipodoc << "\" && STATO=" << _stato <<")\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 << "FROM TIPOCF=C CODCF=" << codcf << " PROVV=D ANNO=" << datadoc.year() << " DATADOC=" << datadoc << " CODNUM=" << _codnum << "\n";
@ -117,7 +129,7 @@ TObject* TAcquisizione_cache::key2obj(const char* key)
consegne.move_first(); consegne.move_first();
const TDate dataprco = consegne.get(LVRCONSPLAN_DTCONS).as_date(); const TDate dataprco = consegne.get(LVRCONSPLAN_DTCONS).as_date();
doc = new TDocumento('D',datadoc.year(),_codnum,0); doc = new TDocumento('D', datadoc.year(), _codnum, ++_ndoc);
doc->put(DOC_TIPODOC, _tipodoc); doc->put(DOC_TIPODOC, _tipodoc);
doc->put(DOC_STATO, _stato); doc->put(DOC_STATO, _stato);
doc->put(DOC_DATADOC, datadoc); doc->put(DOC_DATADOC, datadoc);
@ -127,7 +139,6 @@ TObject* TAcquisizione_cache::key2obj(const char* key)
doc->put("DATACON", datadoc); //data conteggio doc->put("DATACON", datadoc); //data conteggio
doc->put("DATAGEN", datagen); //data generazione del documento doc->put("DATAGEN", datagen); //data generazione del documento
doc->put("DATAPRCO", dataprco); //data prevista consegna doc->put("DATAPRCO", dataprco); //data prevista consegna
//doc->write(); // Scrivo subito per prenotare il numero documento
} }
return doc; return doc;
} }
@ -143,10 +154,11 @@ TDocumento& TAcquisizione_cache::doc(const TDate& gg, const long cc)
//metodo costruttore di una cache di 17 elementi //metodo costruttore di una cache di 17 elementi
TAcquisizione_cache::TAcquisizione_cache() : TCache(17) TAcquisizione_cache::TAcquisizione_cache() : TCache(17)
{ {
TConfig cfg(CONFIG_DITTA, "lv"); _codnum = ini_get_string(CONFIG_DITTA, "lv", "NUM_RIT(0)");
_codnum = cfg.get("NUM_RIT", NULL, 0); _tipodoc = ini_get_string(CONFIG_DITTA, "lv", "TIPODOC_RIT(0)");
_tipodoc = cfg.get("TIPODOC_RIT", NULL, 0); _stato = ini_get_string(CONFIG_DITTA, "lv", "STATO_RIT(0)");
_stato = cfg.get("STATO_RIT", NULL, 0);
_ndoc = 0;
} }
//////////////////////////////////////////// ////////////////////////////////////////////
@ -164,7 +176,7 @@ protected:
virtual bool create(); virtual bool create();
virtual bool destroy(); virtual bool destroy();
void elabora_file(const TString& file, bool new_file); void elabora_file(const TString& file, bool new_file, TLog_report &rep);
public: public:
@ -192,7 +204,7 @@ bool TAcquisizione_lavanderie_app::destroy()
} }
//ELABORA_FILE: metodo che effettivamente fa l'elaborazione del file, creando i documenti //ELABORA_FILE: metodo che effettivamente fa l'elaborazione del file, creando i documenti
void TAcquisizione_lavanderie_app::elabora_file(const TString& file, bool new_file) void TAcquisizione_lavanderie_app::elabora_file(const TString& file, bool new_file, TLog_report &rep)
{ {
TAcquisizione_cache ca; TAcquisizione_cache ca;
@ -277,6 +289,16 @@ void TAcquisizione_lavanderie_app::elabora_file(const TString& file, bool new_fi
default: return; default: return;
} }
} }
else
{
if (!doc.get_date("DATAPRCO").ok())
{
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);
}
}
//se voglio sovrascrivere i file, e non l'ho mai cancellato, allora svuotalo effettivamente //se voglio sovrascrivere i file, e non l'ho mai cancellato, allora svuotalo effettivamente
const TString8 numdoc = doc.get(DOC_NDOC); const TString8 numdoc = doc.get(DOC_NDOC);
@ -355,6 +377,9 @@ bool TAcquisizione_lavanderie_app::transfer()
TSheet_field& sheet = _msk->sfield(F_SHEET_NAME); TSheet_field& sheet = _msk->sfield(F_SHEET_NAME);
TFilename file; TFilename file;
TLog_report logrep("Aquisizione da contapezzi");
logrep.kill_duplicates(true);
//per ogni riga dello sheet, leggo il suo contenuto, se contiene dei caratteri jolly //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 //preparo la lista dei file che soddisfano la maschera in quella directory e li elaboro
//tutti, altrimenti elaboro esattamente il file che è scritto sullo sheet //tutti, altrimenti elaboro esattamente il file che è scritto sullo sheet
@ -376,13 +401,18 @@ bool TAcquisizione_lavanderie_app::transfer()
list_files(file, lista_file); list_files(file, lista_file);
FOR_EACH_ARRAY_ROW(lista_file, r2, row2) FOR_EACH_ARRAY_ROW(lista_file, r2, row2)
elabora_file(*row2, true); elabora_file(*row2, true, logrep);
} }
else else
elabora_file(file, true); elabora_file(file, true, logrep);
} }
} }
TReport_book buc;
buc.add(logrep);
if (buc.pages() > 0)
buc.preview();
else
message_box(TR("Generazione terminata")); message_box(TR("Generazione terminata"));
return true; return true;