2019-02-27 18:10:56 +01:00
|
|
|
|
#include "fplib.h"
|
|
|
|
|
#include "execp.h"
|
|
|
|
|
|
|
|
|
|
class TExternal_app;
|
|
|
|
|
|
2019-03-01 16:53:01 +01:00
|
|
|
|
void TFp_mail_sender::set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf, TString mail, bool accord, TString ragsoc, bool sent)
|
2019-02-27 18:10:56 +01:00
|
|
|
|
{
|
|
|
|
|
_anno = anno;
|
|
|
|
|
_codnum = codnum;
|
|
|
|
|
_tipodoc = &cached_tipodoc(tipodoc);
|
|
|
|
|
_ndoc = ndoc;
|
|
|
|
|
_codcf = codcf;
|
2019-02-28 18:11:38 +01:00
|
|
|
|
_mail = mail;
|
2019-03-01 16:53:01 +01:00
|
|
|
|
_accord = accord;
|
|
|
|
|
_ragsoc = ragsoc;
|
|
|
|
|
_sent = sent;
|
2019-02-28 18:11:38 +01:00
|
|
|
|
_pdf_name.cut(0) << SLASH << _anno << '_' << _codnum << '_' << _ndoc << ".pdf";
|
2019-02-27 18:10:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TFp_mail_sender::genera_pdf()
|
|
|
|
|
{
|
|
|
|
|
static TString commandline;
|
2019-02-28 18:11:38 +01:00
|
|
|
|
|
|
|
|
|
commandline.cut(0) << "ve1 -2 " << _codnum << ' ' << _anno
|
|
|
|
|
<< " D " << _ndoc << " X P 1 D"; // X: stampa su disco, P: provvisorio, 1: 1 copia, D: disabilita archiviazione
|
|
|
|
|
|
2019-02-27 18:10:56 +01:00
|
|
|
|
TExternal_app interattivo(commandline);
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
2019-02-27 18:10:56 +01:00
|
|
|
|
if (interattivo.run() != NOERR)
|
|
|
|
|
{
|
|
|
|
|
TString msgerr = "Fallita generazione PDF documento ";
|
2019-02-28 18:11:38 +01:00
|
|
|
|
msgerr << _codnum << ' ' << _anno << " D " << _ndoc;
|
2019-02-27 18:10:56 +01:00
|
|
|
|
error_box(msgerr);
|
2019-02-28 18:11:38 +01:00
|
|
|
|
return false;
|
2019-02-27 18:10:56 +01:00
|
|
|
|
}
|
2019-02-28 18:11:38 +01:00
|
|
|
|
|
|
|
|
|
TFilename pdf;
|
|
|
|
|
_pdf_path.cut(0) << pdf.tempdir();
|
2019-03-04 11:40:12 +01:00
|
|
|
|
pdf.cut(0) << _pdf_path << _pdf_name;
|
2019-02-28 18:11:38 +01:00
|
|
|
|
if (!pdf.exist()) {
|
|
|
|
|
error_box("Attenzione! Non <20> stato possibile generare il PDF");
|
|
|
|
|
return false;
|
2019-02-27 18:10:56 +01:00
|
|
|
|
}
|
2019-02-28 18:11:38 +01:00
|
|
|
|
return true;
|
2019-02-27 18:10:56 +01:00
|
|
|
|
}
|
2019-02-28 18:11:38 +01:00
|
|
|
|
|
|
|
|
|
// Creo se non c'<27> il pdf e lo allego alla mail per l'invio
|
2019-03-07 10:38:43 +01:00
|
|
|
|
bool TFp_mail_sender::send(const TString& msg)
|
2019-02-27 18:10:56 +01:00
|
|
|
|
{
|
2019-03-01 16:53:01 +01:00
|
|
|
|
// Controllo per sicurezza quando si prova a rifare l'invio di una fattura gi<67> spedita
|
|
|
|
|
if (_sent)
|
|
|
|
|
{
|
|
|
|
|
if(_error == -1)
|
|
|
|
|
_error = custom_box("ATTENZIONE fattura gi<67> spedita. Reinviare?", "S<EFBFBD> a tutti", "No", "Annulla");
|
|
|
|
|
|
|
|
|
|
if (_error == K_NO)
|
|
|
|
|
_error = -1;
|
|
|
|
|
if (_error == -1 || _error == K_SPACE)
|
2019-03-04 11:40:12 +01:00
|
|
|
|
return false; // Gestione decisione se inviare tutte quelle gia inviate o no (singola) o annullare (tutte)
|
2019-03-01 16:53:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
if (_alleg && !_mail.blank() && _accord)
|
|
|
|
|
{
|
2019-02-28 18:11:38 +01:00
|
|
|
|
_pdf_path = fp_settings().get_fld_dest_usr(); // Cartella dove ci sono i pdf generati
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
2019-02-28 18:11:38 +01:00
|
|
|
|
TFilename pdf; pdf << _pdf_path << _pdf_name;
|
2019-02-27 18:10:56 +01:00
|
|
|
|
|
2019-03-01 16:53:01 +01:00
|
|
|
|
const int pdf_exist = pdf.exist();
|
2019-02-28 18:11:38 +01:00
|
|
|
|
if (pdf_exist)
|
2019-04-29 11:44:21 +02:00
|
|
|
|
ok = spotlite_send_mail(pdf, msg); // -> Invio mail con PDF gi<67> esistente
|
2019-03-01 16:53:01 +01:00
|
|
|
|
else if (genera_pdf()) // Genero pdf se non esiste gi<67> (in tempdir)
|
|
|
|
|
{ // Manda gi<67> un messaggio di errore generazione se fallisce la generazione
|
2019-02-28 18:11:38 +01:00
|
|
|
|
TFilename newf_pdf; newf_pdf << _pdf_path << _pdf_name;
|
2019-03-07 10:38:43 +01:00
|
|
|
|
ok = spotlite_send_mail(newf_pdf, msg);
|
2019-02-28 18:11:38 +01:00
|
|
|
|
}
|
2019-03-01 16:53:01 +01:00
|
|
|
|
else {
|
2019-03-07 10:38:43 +01:00
|
|
|
|
TString msg_err; msg_err << "Inviare lo stesso la mail senza il pdf allegato?";
|
|
|
|
|
if (noyes_box(msg_err)) // Se la generazione fallisce chiedo se procedere lo stesso
|
|
|
|
|
ok = spotlite_send_mail(msg); // Se s<>, procedo con mail senza pdf
|
2019-03-01 16:53:01 +01:00
|
|
|
|
} // Se no, esco senza inviare
|
2019-02-28 18:11:38 +01:00
|
|
|
|
}
|
2019-03-01 16:53:01 +01:00
|
|
|
|
else if (!_alleg && _accord)
|
2019-03-07 10:38:43 +01:00
|
|
|
|
ok = spotlite_send_mail(msg);
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
|
|
|
|
if(ok)
|
2019-02-28 18:11:38 +01:00
|
|
|
|
{
|
2019-03-01 16:53:01 +01:00
|
|
|
|
TDocumento fdoc('D', _anno, _codnum, _ndoc);
|
|
|
|
|
TString hfatt, bfatt;
|
|
|
|
|
TPaf_record paf0100f("PAF0100F");
|
|
|
|
|
TString query;
|
|
|
|
|
if (chiave_paf(fdoc, hfatt, bfatt) && paf0100f.search(nullptr, hfatt, bfatt))
|
|
|
|
|
{
|
|
|
|
|
query << "UPDATE PAF0100F SET P1_ERRINT = 'S' WHERE P1_KEYHEADERFATT = '" << hfatt << "' AND P1_KEYBODYFATT = '" << bfatt << "'";
|
|
|
|
|
fp_db().sq_set_exec(query);
|
|
|
|
|
fp_db().sq_commit();
|
|
|
|
|
}
|
|
|
|
|
#ifdef DBG
|
|
|
|
|
else
|
|
|
|
|
error_box("Attenzione non <20> stato possibile trovare il documento");
|
|
|
|
|
#endif
|
2019-02-28 18:11:38 +01:00
|
|
|
|
}
|
2019-03-01 16:53:01 +01:00
|
|
|
|
return ok;
|
2019-02-28 18:11:38 +01:00
|
|
|
|
}
|
2019-02-27 18:10:56 +01:00
|
|
|
|
|
2019-02-28 18:11:38 +01:00
|
|
|
|
bool TFp_mail_sender::get_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn,
|
|
|
|
|
TString& subj, TString& text, TToken_string& attach, short& ui)
|
|
|
|
|
{
|
2019-03-01 16:53:01 +01:00
|
|
|
|
to.cut(0) << _mail;
|
|
|
|
|
// to.cut(0) << "spalacino@sirio-is.it";
|
2019-02-28 18:11:38 +01:00
|
|
|
|
const TDocumento doc('D', _anno, _codnum, _ndoc);
|
|
|
|
|
doc.riferimento(subj);
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
2019-02-28 18:11:38 +01:00
|
|
|
|
subj << "Notifica Mancata Consegna Fattura n. " << _ndoc
|
|
|
|
|
<< ' ' << prefix().firm().ragione_sociale();
|
2019-02-27 18:10:56 +01:00
|
|
|
|
|
2019-02-28 18:11:38 +01:00
|
|
|
|
TString saluti = esc(ini_get_string(CONFIG_USER, "Mail", "Signature"));
|
|
|
|
|
if (saluti.full())
|
|
|
|
|
{
|
|
|
|
|
if (saluti.find('\n') < 0 && fexist(saluti))
|
|
|
|
|
{
|
|
|
|
|
TScanner s(saluti);
|
|
|
|
|
while (!s.eof())
|
|
|
|
|
text << s.line() << '\n';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
text << saluti << '\n';
|
2019-02-27 18:10:56 +01:00
|
|
|
|
}
|
2019-02-28 18:11:38 +01:00
|
|
|
|
else
|
|
|
|
|
text << "Cordiali Saluti " << prefix().firm().ragione_sociale();
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
2019-02-28 18:11:38 +01:00
|
|
|
|
text.trim();
|
|
|
|
|
if (to.full())
|
|
|
|
|
ui &= ~0x1; // No user interface
|
2019-03-01 16:53:01 +01:00
|
|
|
|
ui |= 0x2; // Query receipt
|
2019-02-28 18:11:38 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Funzione per spedire un pdf via mail
|
2019-03-07 10:38:43 +01:00
|
|
|
|
bool TFp_mail_sender::spotlite_send_mail(const TFilename& pdf, const TString& msg)
|
2019-02-28 18:11:38 +01:00
|
|
|
|
{
|
|
|
|
|
TToken_string to(15, ';'), cc(15, ';'), ccn(15, ';'), attach(pdf, ';');
|
2019-03-07 10:38:43 +01:00
|
|
|
|
TString subj;
|
|
|
|
|
TString text; text << msg << "\n\n";
|
2019-02-28 18:11:38 +01:00
|
|
|
|
short flags = 0x1; // UI
|
|
|
|
|
|
|
|
|
|
bool ok = get_mail(to, cc, ccn, subj, text, attach, flags);
|
|
|
|
|
if (subj.blank())
|
|
|
|
|
subj.cut(0) << "Invio di " << pdf.name();
|
|
|
|
|
if (!(flags & 0x1) && to.empty_items() && cc.empty_items() && ccn.empty_items())
|
|
|
|
|
flags |= 0x1; // Forza UI in assenza di destinatari
|
|
|
|
|
static bool usePower = ini_get_bool(CONFIG_USER, "Mail", "Powershell");
|
|
|
|
|
ok = (usePower ? xvt_powermail_send(to, cc, ccn, subj, text, attach, flags, user()) :
|
|
|
|
|
xvt_mail_send(to, cc, ccn, subj, text, attach, flags)) != 0;
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 10:38:43 +01:00
|
|
|
|
bool TFp_mail_sender::spotlite_send_mail(const TString& msg)
|
2019-02-28 18:11:38 +01:00
|
|
|
|
{
|
|
|
|
|
TToken_string to(15, ';'), cc(15, ';'), ccn(15, ';'), attach(15, ';');
|
2019-03-07 10:38:43 +01:00
|
|
|
|
TString subj;
|
|
|
|
|
TString text; text << msg << "\n\n";
|
2019-02-28 18:11:38 +01:00
|
|
|
|
short flags = 0x1; // UI
|
|
|
|
|
|
|
|
|
|
bool ok = get_mail(to, cc, ccn, subj, text, attach, flags);
|
|
|
|
|
if (subj.blank())
|
|
|
|
|
subj.cut(0) << "Notifica Mancata Consegna Fattura ";
|
|
|
|
|
if (!(flags & 0x1) && to.empty_items() && cc.empty_items() && ccn.empty_items())
|
|
|
|
|
flags |= 0x1; // Forza UI in assenza di destinatari
|
|
|
|
|
static bool usePower = ini_get_bool(CONFIG_USER, "Mail", "Powershell");
|
|
|
|
|
ok = (usePower ? xvt_powermail_send(to, cc, ccn, subj, text, attach, flags, user()) :
|
|
|
|
|
xvt_mail_send(to, cc, ccn, subj, text, attach, flags)) != 0;
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
2019-03-01 16:53:01 +01:00
|
|
|
|
|
|
|
|
|
bool TFp_mail_sender::set_alleg(const bool allega_fat)
|
|
|
|
|
{
|
|
|
|
|
_alleg = allega_fat;
|
|
|
|
|
return _alleg;
|
|
|
|
|
}
|