Files correlati : f90.exe Commento : - ESTRAZIONE: - Aggiunto flag esportazione cartacei. - Aggiunta pagina a 'Apri estrazione' per vedere i risultati dell'estrazione (se un mov e' stato saltato e perche'. - Corretta esportazione su tabella F9IVA. - Modificato riconoscimento categoria documentale (da caus cont e tipodoc). - Modificato flag ha vendite esterne in abilita controllo doc elettronici per vendite. - Modificata diagnostica vendite: sono xml solo quegli per italiani, controllo se c'e' il documento elettronico inviato solo se c'e' il flag di controllo vendite. - Aggiunte informazioni di statistica per controllo estrazione. - TABELLA CATEGORIE DOCUMENTALI: - Aggiunta colonna tipodocumento alla tabella delle cat. documentali. - Aggiunto richiamo per causali contabili e per tipi documento. - GESTIONE FILE CARTACEI: - Aggiunto pulsante configurazione (inseririmento estensioni file, cartella doc cartacei). - Modificata finestrella apri file aggiungendo campo per richiamare il movimento da associare. - Aggiunta eliminazione file: i file vengono spostati temporaneamente e eliminati automaticamente dopo un mese. - Implementato caricamento tabella elenco file caricati. - Implementato effettivo caricamento associazione con scrittura su db del file (aggiunto file).
435 lines
12 KiB
C++
435 lines
12 KiB
C++
#include "f90.h"
|
|
|
|
#include <Windows.h>
|
|
#include <vector>
|
|
#include <set>
|
|
#include <map>
|
|
|
|
#include "applicat.h"
|
|
#include "automask.h"
|
|
#include "f90300a.h"
|
|
#include "urldefid.h"
|
|
#include "utility.h"
|
|
#include "f90300b.h"
|
|
#include "mov.h"
|
|
#include "isam.h"
|
|
#include "f9cart.h"
|
|
|
|
#define INI_ESTENSIONI "DOCUMENTI_EXT"
|
|
#define TABMOD_CARTDIR "S0"
|
|
#define F9_ADDRCART "ADDRCART"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TImport_msk
|
|
|
|
class TImport_msk : public TMask
|
|
{
|
|
friend class TGestione_doc_cartacei_f9_msk;
|
|
|
|
static bool ok_handler(TMask_field& field, KEY key)
|
|
{
|
|
field.mask().send_key(K_ENTER, DLG_OK);
|
|
return true;
|
|
}
|
|
|
|
public:
|
|
TImport_msk() : TMask("f90300b") { }
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TGestione_doc_cartacei_f9_msk
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class TGestione_doc_cartacei_f9_msk : public TAutomask
|
|
{
|
|
struct doc_cart_t
|
|
{
|
|
TString filename;
|
|
TString loaddate;
|
|
TString numreg;
|
|
TString user;
|
|
};
|
|
TString _addr_cart; // Indirizzo cartella doc. cartacei F9
|
|
std::unique_ptr<std::set<TString>> _extensions; // todo: controllare che con TString funzioni l'ordinamento, quindi la find
|
|
std::unique_ptr<TImport_msk> _import_msk;
|
|
std::map<TString, doc_cart_t> _list_file;
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
|
|
|
static void check_deleted();
|
|
bool check_file_exist(const TString& file) const;
|
|
void delete_file();
|
|
bool doc_already_exists(_In_ const TFilename& file, _Out_ TString& numreg) const;
|
|
void fill();
|
|
static TString get_addrcart();
|
|
static TToken_string& get_valid_extensions();
|
|
void load_extensions();
|
|
bool load_file(const TFilename& file, const TString& numreg);
|
|
void open_config_win() const;
|
|
void open_import_win();
|
|
bool verify_extension(const TFilename& file);
|
|
|
|
public:
|
|
TGestione_doc_cartacei_f9_msk();
|
|
};
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
if(e == se_query_add || e == se_query_del || e == se_query_modify)
|
|
return false;
|
|
|
|
switch (o.dlg())
|
|
{
|
|
case B_IMPORT:
|
|
if (e == fe_button)
|
|
open_import_win();
|
|
break;
|
|
case B_DELETE:
|
|
if (e == fe_button)
|
|
delete_file();
|
|
break;
|
|
case B_CONFIG:
|
|
if (e == fe_button)
|
|
open_config_win();
|
|
default: break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::check_deleted()
|
|
{
|
|
// Controllo che non ci siano file nella cartella eliminati da piu' di un mese, altrimenti li elimino
|
|
TString_array result;
|
|
TString s = get_addrcart(); s << "eliminati\\";
|
|
list_files(s, result);
|
|
FOR_EACH_ARRAY_ITEM(result, nr, file)
|
|
{
|
|
const char* deletedfile = *(TString*)(file);
|
|
HANDLE h_file = CreateFile(deletedfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
FILETIME last_access_time;
|
|
SYSTEMTIME time;
|
|
bool flag = false;
|
|
if (h_file != INVALID_HANDLE_VALUE)
|
|
{
|
|
if(GetFileTime(h_file, NULL, &last_access_time, NULL))
|
|
{
|
|
FileTimeToSystemTime(&last_access_time, &time);
|
|
TDate today = TDate(TODAY);
|
|
if(time.wMonth < (unsigned short)today.month() - 1 ||
|
|
time.wMonth == (unsigned short)today.month() - 1 && time.wDay <= (unsigned short)today.day())
|
|
{
|
|
flag = true;
|
|
CloseHandle(h_file);
|
|
DeleteFile(deletedfile);
|
|
}
|
|
}
|
|
}
|
|
if(!flag)
|
|
CloseHandle(h_file);
|
|
}
|
|
}
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::check_file_exist(const TString& file) const
|
|
{
|
|
TFilename path(_addr_cart);
|
|
path.slash_terminate() << file;
|
|
return path.exist();
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::delete_file()
|
|
{
|
|
TSheet_field& sf = sfield(S_IMPORTED);
|
|
FOR_EACH_SHEET_ROW(sf, nr, row)
|
|
{
|
|
if (row->starts_with("X"))
|
|
{
|
|
TLocalisamfile f9cart(LF_F9CART);
|
|
f9cart.setkey(2);
|
|
const char* filename = row->get(cid2index(F_FILENAME));
|
|
const char* numreg = row->get(cid2index(104));
|
|
f9cart.put(F9C_FILENAME, filename);
|
|
f9cart.put(F9C_NUMREG, numreg);
|
|
f9cart.read();
|
|
TFilename filecart = get_addrcart(); filecart << filename;
|
|
TFilename deleted = get_addrcart(); deleted << "eliminati" << SLASH;
|
|
if (!deleted.exist())
|
|
make_dir(deleted);
|
|
deleted << filename;
|
|
if (deleted.exist())
|
|
DeleteFile(deleted);
|
|
if (!MoveFile(filecart, deleted))
|
|
warning_box(TString("Attenzione:") << " non e' stato possibile rimuovere questo file: " << filecart);
|
|
else
|
|
f9cart.remove();
|
|
}
|
|
}
|
|
fill();
|
|
}
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::doc_already_exists(const TFilename& file, TString& numreg) const
|
|
{
|
|
const auto it = _list_file.find(file);
|
|
if (it != _list_file.end())
|
|
{
|
|
numreg = it->second.numreg;
|
|
return true;
|
|
}
|
|
numreg = "";
|
|
return false;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::fill()
|
|
{
|
|
TLocalisamfile files(LF_F9CART);
|
|
TLocalisamfile mov(LF_MOV);
|
|
TSheet_field& sf = sfield(S_IMPORTED);
|
|
sf.hide();
|
|
sf.destroy();
|
|
_list_file.clear();
|
|
std::vector<TString> file_err;
|
|
if(files.first() == NOERR)
|
|
{
|
|
do
|
|
{
|
|
const TString& namefile = files.get(F9C_FILENAME);
|
|
if(!check_file_exist(namefile))
|
|
file_err.emplace_back(namefile);
|
|
const TString& numreg = files.get(F9C_NUMREG);
|
|
TString datamov, caus, numdoc, nprot, descrmov;
|
|
mov.zero();
|
|
mov.put(MOV_NUMREG, numreg);
|
|
if(mov.read() == NOERR)
|
|
{
|
|
datamov = mov.get(MOV_DATAREG);
|
|
caus = mov.get(MOV_CODCAUS);
|
|
numdoc = mov.get(MOV_NUMDOCEXT);
|
|
if(numdoc.empty()) numdoc = mov.get(MOV_NUMDOC);
|
|
nprot = mov.get(MOV_PROTIVA);
|
|
descrmov = mov.get(MOV_DESCR);
|
|
}
|
|
TToken_string& r = sf.row(-1);
|
|
r.add(" ", 0); // F_SEL
|
|
r.add(namefile); // F_FILENAME
|
|
r.add(files.get(F9C_LOADDATE)); // F_DATACARIC
|
|
r.add(numreg); // F_NUMREG
|
|
r.add(datamov); // F_DATAMOV
|
|
r.add(caus); // F_CAUS
|
|
r.add(numdoc); // F_NUMDOC
|
|
r.add(nprot); // F_NPROTOCOL
|
|
r.add(descrmov); // F_DESCRMOV
|
|
|
|
_list_file.insert({ namefile, { namefile, files.get(F9C_LOADDATE), numreg, files.get(F9C_USER) } });
|
|
} while (files.next() == NOERR);
|
|
sf.force_update();
|
|
}
|
|
sf.show();
|
|
}
|
|
|
|
TString TGestione_doc_cartacei_f9_msk::get_addrcart()
|
|
{
|
|
return ini_get_string(CONFIG_DITTA, "F9", F9_ADDRCART);
|
|
}
|
|
|
|
TToken_string& TGestione_doc_cartacei_f9_msk::get_valid_extensions()
|
|
{
|
|
static TToken_string ext(ini_get_string(CONFIG_DITTA, "F9", "DOCUMENTI_EXT"), ',');
|
|
if (ext.items() == 0)
|
|
{
|
|
ext = ".pdf, .doc, .docx, .xls, .xlsx, .jpg, .jpeg, .png";
|
|
ini_set_string(CONFIG_DITTA, "F9", INI_ESTENSIONI, ext);
|
|
}
|
|
ext.replace(" ", "");
|
|
return ext;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::load_extensions()
|
|
{
|
|
if (_extensions == nullptr)
|
|
{
|
|
_extensions = std::make_unique<std::set<TString>>();
|
|
TToken_string& ext = get_valid_extensions();
|
|
for (int i = 0; i < ext.items(); ++i)
|
|
{
|
|
TString e = ext.get(i);
|
|
if (!e.empty())
|
|
{
|
|
if (e.starts_with("."))
|
|
e.ltrim(1);
|
|
_extensions->insert(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::load_file(const TFilename& file, const TString& numreg)
|
|
{
|
|
TString numreg_old;
|
|
if(doc_already_exists(file, numreg_old))
|
|
{
|
|
error_box(TString("Attenzione:") << "esiste gia' un documento con questo nome associato al num. di registrazione " << numreg_old);
|
|
return false;
|
|
}
|
|
|
|
TLocalisamfile f9cart(LF_F9CART);
|
|
f9cart.put(F9C_FILENAME, file.name());
|
|
f9cart.put(F9C_LOADDATE, TDate(TODAY));
|
|
f9cart.put(F9C_NUMREG, numreg);
|
|
#ifdef DBG
|
|
const TString n_user = user();
|
|
if (n_user.empty())
|
|
message_box("Attenzione nome utente vuoto!");
|
|
f9cart.put(F9C_USER, n_user);
|
|
#else
|
|
f9cart.put(F9C_USER, user());
|
|
#endif
|
|
TFilename fdestin = get_addrcart();
|
|
const TString filename = file.name();
|
|
fdestin << filename;
|
|
const bool ok = CopyFile(file, fdestin, true);
|
|
if (!ok)
|
|
{
|
|
if(fdestin.exist())
|
|
warning_box("Errore nel copiare il file nella cartella di destinazione.\nEsiste gia' un file con questo nome.");
|
|
else
|
|
warning_box("Errore nel copiare il file nella cartella di destinazione. Ritentare.");
|
|
f9cart.zero();
|
|
return false;
|
|
}
|
|
f9cart.write();
|
|
f9cart.rewrite();
|
|
return true;
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::open_config_win() const
|
|
{
|
|
static std::unique_ptr<TMask> msk;
|
|
if(msk == nullptr)
|
|
{
|
|
msk = std::make_unique<TMask>("Configurazione", 1, 78, 14);
|
|
msk->add_button_tool(DLG_OK, "Conferma", TOOL_OK);
|
|
msk->add_button_tool(DLG_NULL, "", 0);
|
|
msk->add_button_tool(DLG_QUIT, "Esci", TOOL_QUIT);
|
|
|
|
msk->add_groupbox(DLG_NULL, 0, "", 1, 0, 76, 4, "");
|
|
msk->add_static (DLG_NULL, 0, "@BInserire estensioni file riconosciute, separate da virgola.", 2, 1);
|
|
msk->add_string (101, 0, "Estensioni:", 2, 2, 255, "", 60);
|
|
msk->add_groupbox(DLG_NULL, 0, "@BCartella documenti cartacei", 1, 4, 76, 4);
|
|
msk->add_static (DLG_NULL, 0, "@BInserire nome cartella, all'interno della area dati della ditta", 2, 5);
|
|
msk->add_string (102, 0, "", 2, 6, 64, "", 30);
|
|
|
|
msk->set(101, ini_get_string(CONFIG_DITTA, "F9", INI_ESTENSIONI));
|
|
TString s = ini_get_string(CONFIG_DITTA, "F9", F9_ADDRCART);
|
|
s.rtrim(1);
|
|
s.ltrim(s.rfind('\\') + 1);
|
|
msk->set(102, s);
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
if (msk->run() != K_ENTER)
|
|
{
|
|
if (msk->get(102).empty())
|
|
{
|
|
warning_box("Si prega di inserire il nome della cartella per i documenti cartacei.");
|
|
continue;
|
|
}
|
|
else break;
|
|
}
|
|
ini_set_string(CONFIG_DITTA, "F9", INI_ESTENSIONI, msk->get(101));
|
|
TString dir = msk->get(102);
|
|
if (dir.empty())
|
|
{
|
|
if(yesno_box("Nome cartella vuoto.\nCreare cartella con nome 'Cartacei_F9'?"))
|
|
msk->set(102, dir = "Cartacei_F9");
|
|
else continue;
|
|
}
|
|
|
|
TFilename path(prefix().get_studio());
|
|
path.slash_terminate() << dir;
|
|
path.slash_terminate();
|
|
if (!path.exist())
|
|
{
|
|
if (dir == "Cartacei_F9" || yesno_box("Il percorso indicato e' inesistente.\nCreare la cartella con questo nome?"))
|
|
{
|
|
if (!make_dir(path))
|
|
{
|
|
warning_box("Impossibile creare il percorso specificato.");
|
|
continue;
|
|
}
|
|
}
|
|
else continue;
|
|
}
|
|
ini_set_string(CONFIG_DITTA, "F9", F9_ADDRCART, path);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
void TGestione_doc_cartacei_f9_msk::open_import_win()
|
|
{
|
|
if(_import_msk == nullptr)
|
|
_import_msk = make_unique<TImport_msk>();
|
|
while(_import_msk->run() == K_ENTER)
|
|
{
|
|
const TString& file = _import_msk->get(F_IMPADDRESS);
|
|
const TString& numreg = _import_msk->get(F_IMPNUMREG);
|
|
if (!file.empty())
|
|
{
|
|
TFilename f(file);
|
|
if (verify_extension(f))
|
|
{
|
|
if (load_file(f, numreg))
|
|
message_box("File caricato.");
|
|
}
|
|
else
|
|
warning_box("Questo file e' in un formato non accettato.");
|
|
}
|
|
}
|
|
fill();
|
|
}
|
|
|
|
bool TGestione_doc_cartacei_f9_msk::verify_extension(const TFilename& file)
|
|
{
|
|
load_extensions();
|
|
return _extensions->find(file.ext()) != _extensions->end();
|
|
}
|
|
|
|
TGestione_doc_cartacei_f9_msk::TGestione_doc_cartacei_f9_msk(): TAutomask("f90300a"), _addr_cart(get_addrcart())
|
|
{
|
|
if (_addr_cart.empty())
|
|
{
|
|
message_box("Inserire nome cartella documenti cartacei.");
|
|
open_config_win();
|
|
}
|
|
check_deleted();
|
|
fill();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// TGestione_doc_cartacei_f9_app
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class TGestione_doc_cartacei_f9_app : public TSkeleton_application
|
|
{
|
|
void main_loop() override
|
|
{
|
|
TGestione_doc_cartacei_f9_msk msk;
|
|
while (msk.run() == K_ENTER)
|
|
{ }
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
int f90300(const int argc, char* argv[])
|
|
{
|
|
TGestione_doc_cartacei_f9_app app;
|
|
app.run(argc, argv, "Gestione documenti cartacei");
|
|
return 0;
|
|
}
|