Patch level : 12.0 no-patch
Files correlati : fp Commento : Implementato programma per invio mail mancata consegna
This commit is contained in:
parent
4417f38f35
commit
72373dfb8e
@ -313,16 +313,14 @@ bool TMancati_mask::check_doc_filter(const TDocumentoEsteso& d) const
|
||||
|
||||
class TMancati_app : public TSkeleton_application
|
||||
{
|
||||
int _anno;
|
||||
TString16 _codnum, _tipodoc;
|
||||
long _ndoc, _codcf;
|
||||
char _tipocf;
|
||||
//int _anno;
|
||||
//TString16 _codnum, _tipodoc;
|
||||
//long _ndoc, _codcf;
|
||||
//char _tipocf;
|
||||
|
||||
void set_next_pdf(const int anno, const TFixed_string& codnum, const TFixed_string& tipodoc, const long ndoc, const long codcf);
|
||||
bool get_next_pdf(int anno, long ditta, const char* codnum, long ndoc, long codcf, TFilename& pdf) const override;
|
||||
bool get_next_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn, TString& subj, TString& text,
|
||||
TToken_string& attach, short& ui) const override;
|
||||
bool get_mail_address(TToken_string& to, TToken_string& cc) const;
|
||||
//void set_next_pdf(const int anno, const TFixed_string& codnum, const TFixed_string& tipodoc, const long ndoc, const long codcf);
|
||||
//bool get_next_pdf(int anno, long ditta, const char* codnum, long ndoc, long codcf, TFilename& pdf) const override;
|
||||
//bool get_mail_address(TToken_string& to, TToken_string& cc) const;
|
||||
|
||||
public:
|
||||
virtual bool create();
|
||||
@ -343,20 +341,20 @@ void TMancati_app::main_loop()
|
||||
|
||||
FOR_EACH_ARRAY_ROW(sht, r, riga)
|
||||
{
|
||||
//if (!pi.add_status(1))
|
||||
//break;
|
||||
|
||||
if (riga->starts_with("X"))
|
||||
if (riga->starts_with("X") && riga->get(mask.sfield(F_DOCS).cid2index(S_BYMAIL)))
|
||||
{
|
||||
const int anno = riga->get_int(mask.sfield(F_DOCS).cid2index(S_ANNO));
|
||||
const long ndoc = riga->get_long(mask.sfield(F_DOCS).cid2index(S_NDOC));
|
||||
const TFixed_string codnum(riga->get(mask.sfield(F_DOCS).cid2index(S_CODNUM)));
|
||||
const TFixed_string tipodoc(riga->get(mask.sfield(F_DOCS).cid2index(S_TIPODOC)));
|
||||
const long codcf = riga->get_long(mask.sfield(F_DOCS).cid2index(S_CLIENTE));
|
||||
|
||||
|
||||
mail_sender.set_doc(anno, ndoc, codnum, tipodoc, codcf);
|
||||
const TString mail = riga->get_long(mask.sfield(F_DOCS).cid2index(S_DOCMAIL));
|
||||
bool pdf;
|
||||
mail_sender.set_doc(anno, ndoc, codnum, tipodoc, codcf, mail);
|
||||
mail_sender.send();
|
||||
|
||||
riga->add("", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,6 +374,7 @@ bool TMancati_app::create()
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void TMancati_app::set_next_pdf(const int anno, const TFixed_string& codnum, const TFixed_string& tipodoc, const long ndoc, const long codcf)
|
||||
{
|
||||
_anno = anno;
|
||||
@ -395,48 +394,6 @@ bool TMancati_app::get_next_pdf(int anno, long ditta, const char* codnum, long n
|
||||
}
|
||||
|
||||
|
||||
bool TMancati_app::get_next_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn,
|
||||
TString& subj, TString& text, TToken_string& attach, short& ui) const
|
||||
{
|
||||
bool ok = TApplication::get_next_mail(to, cc, ccn, subj, text, attach, ui);
|
||||
|
||||
if (_ndoc > 0L)
|
||||
{
|
||||
ok = get_mail_address(to, cc);
|
||||
if (ok)
|
||||
{
|
||||
const TDocumento doc('D', _anno, _codnum, _ndoc);
|
||||
doc.riferimento(subj);
|
||||
if (subj.blank())
|
||||
subj = doc.tipo().descrizione();
|
||||
subj << ' ' << _ndoc << TR(" del ") << doc.get(DOC_DATADOC)
|
||||
<< ' ' << prefix().firm().ragione_sociale();
|
||||
|
||||
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';
|
||||
}
|
||||
else
|
||||
{
|
||||
text << TR("Cordiali Saluti ") << prefix().firm().ragione_sociale();
|
||||
}
|
||||
text.trim();
|
||||
if (to.full())
|
||||
ui &= ~0x1; // No user interface
|
||||
ui |= 0x2; // Query receipt
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TMancati_app::get_mail_address(TToken_string& to, TToken_string& cc) const
|
||||
{
|
||||
if (_tipodoc.full())
|
||||
@ -481,6 +438,7 @@ bool TMancati_app::get_mail_address(TToken_string& to, TToken_string& cc) const
|
||||
}
|
||||
return to.full();
|
||||
}
|
||||
*/
|
||||
|
||||
bool TMancati_app::destroy()
|
||||
{
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <cg2103.h>
|
||||
|
||||
#define SQL_FLD "sql/"
|
||||
enum { no_pdf = -1, pdf_ok = 0, no_alleg = -2};
|
||||
|
||||
// Ritorna la connessione al DB paf secondo i parametri impostati nel programma di configurazione
|
||||
SSimple_query& fp_db();
|
||||
@ -307,19 +308,23 @@ public:
|
||||
};
|
||||
class TFp_mail_sender
|
||||
{
|
||||
int _anno;
|
||||
TString16 _codnum;
|
||||
int _anno;
|
||||
TString16 _codnum;
|
||||
const TTipo_documento* _tipodoc;
|
||||
long _ndoc, _codcf;
|
||||
long _ndoc, _codcf;
|
||||
TString _mail, _pdf_path, _pdf_name;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
void set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf);
|
||||
void set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf, TString mail);
|
||||
bool genera_pdf();
|
||||
void send();
|
||||
bool get_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn, TString& subj, TString& text, TToken_string& attach, short& flags);
|
||||
bool spotlite_send_mail(const TFilename& pdf);
|
||||
bool spotlite_send_mail();
|
||||
|
||||
TFp_mail_sender() { }
|
||||
TFp_mail_sender(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf)
|
||||
{ set_doc(anno, ndoc, codnum, tipodoc, codcf); }
|
||||
TFp_mail_sender(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf, TString mail)
|
||||
{ set_doc(anno, ndoc, codnum, tipodoc, codcf, mail); }
|
||||
};
|
||||
#endif // __FPLIB_H
|
||||
|
@ -1,53 +1,150 @@
|
||||
#include "fplib.h"
|
||||
#include "execp.h"
|
||||
#include <spotlite.h>
|
||||
#include <xvt_env.h>
|
||||
#include "modaut.h"
|
||||
|
||||
class TExternal_app;
|
||||
|
||||
void TFp_mail_sender::set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf)
|
||||
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)
|
||||
{
|
||||
_anno = anno;
|
||||
_codnum = codnum;
|
||||
_tipodoc = &cached_tipodoc(tipodoc);
|
||||
_ndoc = ndoc;
|
||||
_codcf = codcf;
|
||||
_mail = mail;
|
||||
_pdf_name.cut(0) << SLASH << _anno << '_' << _codnum << '_' << _ndoc << ".pdf";
|
||||
}
|
||||
|
||||
bool TFp_mail_sender::genera_pdf()
|
||||
{
|
||||
static TString commandline;
|
||||
commandline.cut(0) << "ve1 -2 " << doc.get(DOC_CODNUM) << ' ' << doc.get(DOC_ANNO)
|
||||
<< ' ' << doc.get(DOC_PROVV) << ' ' << doc.get(DOC_NDOC) << " X P 1 D"; // X: stampa su disco, P: provvisorio, 1: 1 copia, D: disabilita archiviazione
|
||||
|
||||
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
|
||||
|
||||
TExternal_app interattivo(commandline);
|
||||
if (interattivo.run() != NOERR)
|
||||
{
|
||||
TString msgerr = "Fallita generazione PDF documento ";
|
||||
msgerr << doc.get(DOC_CODNUM) << ' ' << doc.get(DOC_ANNO)
|
||||
<< ' ' << doc.get(DOC_PROVV) << ' ' << doc.get(DOC_NDOC);
|
||||
msgerr << _codnum << ' ' << _anno << " D " << _ndoc;
|
||||
error_box(msgerr);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DBG
|
||||
TFilename pdf;
|
||||
_pdf_path.cut(0) << "C:\\campo12\\temp\\admin";
|
||||
#else
|
||||
TFilename pdf;
|
||||
_pdf_path.cut(0) << pdf.tempdir();
|
||||
#endif
|
||||
pdf << _pdf_path << _pdf_name;
|
||||
if (!pdf.exist()) {
|
||||
error_box("Attenzione! Non è stato possibile generare il PDF");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Creo se non c'è il pdf e lo allego alla mail per l'invio
|
||||
void TFp_mail_sender::send()
|
||||
{
|
||||
bool main_prof = false;
|
||||
if (fp_settings().get_allega_fat()) {
|
||||
_pdf_path = fp_settings().get_fld_dest_usr(); // Cartella dove ci sono i pdf generati
|
||||
|
||||
TFilename pdf; pdf << _pdf_path << _pdf_name;
|
||||
|
||||
int pdf_exist = pdf.exist();
|
||||
bool new_f = false; // Bool. se creo un nuovo pdf (in tempdir)
|
||||
if (pdf_exist)
|
||||
spotlite_send_mail(pdf); // -> Invio mail con PDF già esistente
|
||||
else if( !((new_f = genera_pdf())) ) // Genero pdf se non esiste già
|
||||
{ // Manda già un messaggio di errore generazione se fallisce la generazione
|
||||
bool send_no_pdf = noyes_box("Inviare lo stesso la mail senza il pdf allegato?"); // Se la generazione fallisce chiedo se procedere lo stesso
|
||||
if (!send_no_pdf)
|
||||
return; // Esco se non voglio inviare mail senza pdf
|
||||
spotlite_send_mail(); // Se no, procedo con mail senza pdf
|
||||
}
|
||||
else if(new_f) {
|
||||
TFilename newf_pdf; newf_pdf << _pdf_path << _pdf_name;
|
||||
spotlite_send_mail(newf_pdf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TFilename pdf; pdf.tempdir();
|
||||
pdf << SLASH << doc.get(DOC_ANNO) << '_' << doc.get(DOC_CODNUM) << '_' << doc.get(DOC_NDOC) << ".pdf";
|
||||
if (!pdf.exist() && !yesno_box("Attenzione! Non è stato possibile creare il pdf, continuare?"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!add_row_alleg(pdf, nprogr, paf2600f))
|
||||
return false;
|
||||
error_box("Non è possibile allegare fattura pdf in allegato:\nAllega in fattura disabilitato nelle impostazioni.");
|
||||
}
|
||||
}
|
||||
void TFp_mail_sender::send()
|
||||
|
||||
bool TFp_mail_sender::get_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn,
|
||||
TString& subj, TString& text, TToken_string& attach, short& ui)
|
||||
{
|
||||
TFilename mail;
|
||||
if (fp_settings().get_allega_fat()) {
|
||||
TString fld_pdf = fp_settings().get_fld_dest_usr(); // Cartella dove ci sono i pdf generati
|
||||
|
||||
//se lo trovo ce l'ho già altrimenti devo generarlo
|
||||
genera_pdf();
|
||||
|
||||
|
||||
//to.cut(0) << _mail;
|
||||
to.cut(0) << "spalacino@sirio-is.it";
|
||||
const TDocumento doc('D', _anno, _codnum, _ndoc);
|
||||
doc.riferimento(subj);
|
||||
if (subj.blank())
|
||||
subj = doc.tipo().descrizione();
|
||||
subj << "Notifica Mancata Consegna Fattura n. " << _ndoc
|
||||
<< ' ' << prefix().firm().ragione_sociale();
|
||||
|
||||
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';
|
||||
}
|
||||
_tipodoc->mail_print_profile(mail);
|
||||
}
|
||||
else
|
||||
{
|
||||
text << "Cordiali Saluti " << prefix().firm().ragione_sociale();
|
||||
}
|
||||
text.trim();
|
||||
if (to.full())
|
||||
ui &= ~0x1; // No user interface
|
||||
ui |= 0x2; // Query receipt
|
||||
return true;
|
||||
}
|
||||
// Funzione per spedire un pdf via mail
|
||||
bool TFp_mail_sender::spotlite_send_mail(const TFilename& pdf)
|
||||
{
|
||||
TToken_string to(15, ';'), cc(15, ';'), ccn(15, ';'), attach(pdf, ';');
|
||||
TString subj, text;
|
||||
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;
|
||||
}
|
||||
|
||||
bool TFp_mail_sender::spotlite_send_mail()
|
||||
{
|
||||
TToken_string to(15, ';'), cc(15, ';'), ccn(15, ';'), attach(15, ';');
|
||||
TString subj, text;
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user