Patch level : 12.0 716
Files correlati : fp Commento : Correzione problemi invio mail mancate consegna
This commit is contained in:
parent
72373dfb8e
commit
1a76da72e1
@ -26,6 +26,7 @@
|
||||
|
||||
class TMancati_mask : public TAutomask
|
||||
{
|
||||
|
||||
protected:
|
||||
enum {_codnum, _tipodoc, _dastato, _astato, _tiposdi};
|
||||
|
||||
@ -40,7 +41,7 @@ protected:
|
||||
void load_all_fields();
|
||||
|
||||
bool _filter_changed;
|
||||
|
||||
friend class TMancati_app;
|
||||
public:
|
||||
TMancati_mask() : TAutomask("fp0500a"), _filter_changed(true)
|
||||
{
|
||||
@ -120,6 +121,7 @@ void TMancati_mask::fill()
|
||||
|
||||
const TDate dal = get(F_DATAINI);
|
||||
const TDate al = get(F_DATAEND);
|
||||
TString filter_selected = get(F_FATTSEL);
|
||||
|
||||
#ifdef DBG
|
||||
enable(DLG_OK);
|
||||
@ -164,23 +166,28 @@ void TMancati_mask::fill()
|
||||
if(!check_doc_filter(doc))
|
||||
continue;
|
||||
|
||||
if (!chiave_paf(doc, hfatt, bfatt) || !paf0100f.search(nullptr, hfatt, bfatt) || paf0100f.sq_get("P1_GESTIONE") != "N" && paf0100f.sq_get("P1_ERRINT") != "M")
|
||||
if (!chiave_paf(doc, hfatt, bfatt) || !paf0100f.search(nullptr, hfatt, bfatt) || paf0100f.sq_get("P1_GESTIONE") != "N" && paf0100f.sq_get("P1_ERREST") != "M")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TToken_string& row = docs.row(-1);
|
||||
row = "";
|
||||
row.add(rec.get(DOC_ANNO).as_int(), 1);
|
||||
row.add(rec.get(DOC_CODNUM).as_string());
|
||||
row.add(rec.get(DOC_TIPODOC).as_string());
|
||||
row.add(rec.get(DOC_NDOC).as_int());
|
||||
row.add(rec.get(DOC_DATADOC).as_date());
|
||||
row.add(rec.get(CFV_CODCF).as_int());
|
||||
row.add(rec.get("20." CLI_RAGSOC).as_string());
|
||||
row.add(rec.get("20." CLI_COFI).as_string());
|
||||
|
||||
row.add(rec.get("20." CLI_DOCMAIL).as_string()); // Indirizzo email
|
||||
row.add(rec.get("20." CLI_BYMAIL).as_string()); // Consenso invio email
|
||||
if (filter_selected == "" && paf0100f.sq_get("P1_ERRINT") != MANCATA_SEND
|
||||
|| filter_selected == "S" && paf0100f.sq_get("P1_ERRINT") == MANCATA_SEND
|
||||
|| filter_selected == "A")
|
||||
{
|
||||
TToken_string& row = docs.row(-1);
|
||||
row = "";
|
||||
row.add(rec.get(DOC_ANNO).as_int(), 1);
|
||||
row.add(rec.get(DOC_CODNUM).as_string());
|
||||
row.add(rec.get(DOC_TIPODOC).as_string());
|
||||
row.add(rec.get(DOC_NDOC).as_int());
|
||||
row.add(rec.get(DOC_DATADOC).as_date());
|
||||
row.add(rec.get(CFV_CODCF).as_int());
|
||||
row.add(rec.get("20." CLI_RAGSOC).as_string());
|
||||
row.add(rec.get("20." CLI_COFI).as_string());
|
||||
row.add(rec.get("20." CLI_DOCMAIL).as_string()); // Indirizzo email
|
||||
row.add(rec.get("20." CLI_BYMAIL).as_string()); // Consenso invio email
|
||||
row.add(paf0100f.sq_get("P1_ERRINT") == MANCATA_SEND? "X" : "");
|
||||
}
|
||||
}
|
||||
|
||||
docs.force_update();
|
||||
@ -313,18 +320,8 @@ 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;
|
||||
|
||||
//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();
|
||||
|
||||
virtual bool destroy();
|
||||
virtual void main_loop();
|
||||
|
||||
@ -339,22 +336,43 @@ void TMancati_app::main_loop()
|
||||
TString_array& sht = mask.sfield(F_DOCS).rows_array();
|
||||
TFp_mail_sender mail_sender;
|
||||
|
||||
if ( !mail_sender.set_alleg(fp_settings().get_allega_fat()) )
|
||||
{
|
||||
TString msg; msg << "Non è possibile allegare alla fattura:\nAllega in fattura disabilitato nelle impostazioni.\n"
|
||||
<< "Inviare lo stesso la mail\nNotifica Mancata Consegna senza allegato?";
|
||||
if (!noyes_box(msg)) // Se non sono abilitati gli allegati in fattura avviso e chiedo se procedere lo stesso
|
||||
continue; // Esco senza inviare (se risponde no)
|
||||
} // Altrimenti procedo lo stesso con l'invio mail senza pdf
|
||||
|
||||
FOR_EACH_ARRAY_ROW(sht, nr, row)
|
||||
{
|
||||
const TString mail = row->get(mask.sfield(F_DOCS).cid2index(S_DOCMAIL));
|
||||
bool accord = TString(row->get(mask.sfield(F_DOCS).cid2index(S_BYMAIL))) == "X";
|
||||
if (row->starts_with("X") && (mail.blank() || !accord)) {
|
||||
error_box("Attenzione: c'è almeno un cliente senza indirizzo email o senza il consenso per l'invio email.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FOR_EACH_ARRAY_ROW(sht, r, riga)
|
||||
{
|
||||
|
||||
if (riga->starts_with("X") && riga->get(mask.sfield(F_DOCS).cid2index(S_BYMAIL)))
|
||||
if (riga->starts_with("X"))
|
||||
{
|
||||
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));
|
||||
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();
|
||||
const TString mail = riga->get(mask.sfield(F_DOCS).cid2index(S_DOCMAIL));
|
||||
bool accord = TString(riga->get(mask.sfield(F_DOCS).cid2index(S_BYMAIL))) == "X";
|
||||
TString ragsoc = riga->get(mask.sfield(F_DOCS).cid2index(S_RAGSOC));
|
||||
bool sent = TString(riga->get(mask.sfield(F_DOCS).cid2index(S_SENT))) == "X";
|
||||
|
||||
riga->add("", 0);
|
||||
mail_sender.set_doc(anno, ndoc, codnum, tipodoc, codcf, mail, accord, ragsoc, sent);
|
||||
if (mail_sender.send()) {
|
||||
riga->add("", 0); // Se l'invio avviene con successo sfleggo la riga
|
||||
riga->add("X", 11); // E segno inviata
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
#define START_MASK 401
|
||||
#define F_DATAINI 401
|
||||
#define F_DATAEND 402
|
||||
#define F_SETDEFCOD 403
|
||||
#define F_SETCODEST 404
|
||||
#define F_VALCODEST 405
|
||||
#define F_FATTSEL 403
|
||||
#define F_SETDEFCOD 404
|
||||
#define F_SETCODEST 405
|
||||
#define F_VALCODEST 406
|
||||
#define END_MASK 499
|
||||
|
||||
|
||||
@ -27,4 +28,5 @@
|
||||
#define S_RAGSOC 108
|
||||
#define S_COFI 109
|
||||
#define S_DOCMAIL 110
|
||||
#define S_BYMAIL 111
|
||||
#define S_BYMAIL 111
|
||||
#define S_SENT 112
|
||||
|
@ -10,16 +10,8 @@ END
|
||||
|
||||
BUTTON DLG_OK 2 2
|
||||
BEGIN
|
||||
PROMPT 1 1 "Elabora"
|
||||
PICTURE TOOL_ELABORA
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
BUTTON DLG_EMAIL 10 2
|
||||
BEGIN
|
||||
PROMPT 5 1 "Mail"
|
||||
PROMPT 1 1 "Invia Mail"
|
||||
PICTURE TOOL_EMAIL
|
||||
MESSAGE EXIT,69
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
@ -43,6 +35,15 @@ BEGIN
|
||||
CHECKTYPE REQUIRED
|
||||
END
|
||||
|
||||
RADIOBUTTON F_FATTSEL 3 80
|
||||
BEGIN
|
||||
PROMPT 1 2 "Fatture da visualizzare"
|
||||
ITEM "|Non inviate"
|
||||
ITEM "S|Già spedite"
|
||||
ITEM "A|Tutte"
|
||||
FLAGS "Z"
|
||||
END
|
||||
|
||||
SPREADSHEET F_DOCUMENTI_TIPO 80 5
|
||||
BEGIN
|
||||
PROMPT 1 6 ""
|
||||
@ -71,6 +72,7 @@ BEGIN
|
||||
ITEM "Codice Fiscale@16"
|
||||
ITEM "EMail@50"
|
||||
ITEM "Consenso\ninvio@7"
|
||||
ITEM "SENT@4"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
@ -217,13 +219,19 @@ END
|
||||
|
||||
STRING S_DOCMAIL 50
|
||||
BEGIN
|
||||
PROMPT 1 6 "email"
|
||||
PROMPT 1 7 "email"
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
BOOLEAN S_BYMAIL
|
||||
BEGIN
|
||||
PROMPT 1 7 "Consenso invio email"
|
||||
PROMPT 1 8 "Consenso invio email"
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
BOOLEAN S_SENT
|
||||
BEGIN
|
||||
PROMPT 1 9 "Sent"
|
||||
FLAGS "D"
|
||||
END
|
||||
|
||||
|
@ -13,7 +13,8 @@
|
||||
#include <map>
|
||||
#include <cg2103.h>
|
||||
|
||||
#define SQL_FLD "sql/"
|
||||
#define SQL_FLD "sql/"
|
||||
#define MANCATA_SEND "S" // Se la mail di mancata consegna è già stata inviata P1_ERRINT è segnato con "S"
|
||||
enum { no_pdf = -1, pdf_ok = 0, no_alleg = -2};
|
||||
|
||||
// Ritorna la connessione al DB paf secondo i parametri impostati nel programma di configurazione
|
||||
@ -306,25 +307,34 @@ public:
|
||||
|
||||
TFP_righe_custom();
|
||||
};
|
||||
|
||||
class TFp_mail_sender
|
||||
{
|
||||
int _anno;
|
||||
TString16 _codnum;
|
||||
const TTipo_documento* _tipodoc;
|
||||
long _ndoc, _codcf;
|
||||
TString _mail, _pdf_path, _pdf_name;
|
||||
|
||||
long _ndoc;
|
||||
long _codcf;
|
||||
TString _mail;
|
||||
TString _pdf_path;
|
||||
TString _pdf_name;
|
||||
bool _alleg;
|
||||
bool _accord;
|
||||
TString _ragsoc;
|
||||
int _error;
|
||||
bool _sent;
|
||||
|
||||
public:
|
||||
void set_doc(const int anno, const long ndoc, const TFixed_string& codnum, const TFixed_string& tipodoc, const long codcf, TString mail);
|
||||
void 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);
|
||||
bool genera_pdf();
|
||||
void send();
|
||||
bool 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();
|
||||
bool set_alleg(const bool allega_fat);
|
||||
|
||||
TFp_mail_sender() { }
|
||||
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); }
|
||||
TFp_mail_sender() { _error = -1; }
|
||||
TFp_mail_sender(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)
|
||||
{ set_doc(anno, ndoc, codnum, tipodoc, codcf, mail, accord, ragsoc, sent); }
|
||||
};
|
||||
#endif // __FPLIB_H
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
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, TString mail)
|
||||
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)
|
||||
{
|
||||
_anno = anno;
|
||||
_codnum = codnum;
|
||||
@ -14,6 +14,9 @@ void TFp_mail_sender::set_doc(const int anno, const long ndoc, const TFixed_stri
|
||||
_ndoc = ndoc;
|
||||
_codcf = codcf;
|
||||
_mail = mail;
|
||||
_accord = accord;
|
||||
_ragsoc = ragsoc;
|
||||
_sent = sent;
|
||||
_pdf_name.cut(0) << SLASH << _anno << '_' << _codnum << '_' << _ndoc << ".pdf";
|
||||
}
|
||||
|
||||
@ -25,6 +28,7 @@ bool TFp_mail_sender::genera_pdf()
|
||||
<< " 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 ";
|
||||
@ -49,46 +53,73 @@ bool TFp_mail_sender::genera_pdf()
|
||||
}
|
||||
|
||||
// Creo se non c'è il pdf e lo allego alla mail per l'invio
|
||||
void TFp_mail_sender::send()
|
||||
bool TFp_mail_sender::send()
|
||||
{
|
||||
bool main_prof = false;
|
||||
if (fp_settings().get_allega_fat()) {
|
||||
// Controllo per sicurezza quando si prova a rifare l'invio di una fattura già spedita
|
||||
if (_sent)
|
||||
{
|
||||
if(_error == -1)
|
||||
_error = custom_box("ATTENZIONE fattura già spedita. Reinviare?", "Sì a tutti", "No", "Annulla");
|
||||
|
||||
if (_error == K_NO)
|
||||
_error = -1;
|
||||
if (_error == -1 || _error == K_SPACE)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ok = false;
|
||||
if (_alleg && !_mail.blank() && _accord)
|
||||
{
|
||||
_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)
|
||||
const int pdf_exist = pdf.exist();
|
||||
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) {
|
||||
ok = spotlite_send_mail(pdf); // -> Invio mail con PDF già esistente
|
||||
else if (genera_pdf()) // Genero pdf se non esiste già (in tempdir)
|
||||
{ // Manda già un messaggio di errore generazione se fallisce la generazione
|
||||
TFilename newf_pdf; newf_pdf << _pdf_path << _pdf_name;
|
||||
spotlite_send_mail(newf_pdf);
|
||||
ok = spotlite_send_mail(newf_pdf);
|
||||
}
|
||||
else {
|
||||
TString msg; msg << "Inviare lo stesso la mail senza il pdf allegato?";
|
||||
if (noyes_box(msg)) // Se la generazione fallisce chiedo se procedere lo stesso
|
||||
ok = spotlite_send_mail(); // Se sì, procedo con mail senza pdf
|
||||
} // Se no, esco senza inviare
|
||||
}
|
||||
else
|
||||
else if (!_alleg && _accord)
|
||||
ok = spotlite_send_mail();
|
||||
|
||||
if(ok)
|
||||
{
|
||||
error_box("Non è possibile allegare fattura pdf in allegato:\nAllega in fattura disabilitato nelle impostazioni.");
|
||||
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 è stato possibile trovare il documento");
|
||||
#endif
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TFp_mail_sender::get_mail(TToken_string& to, TToken_string& cc, TToken_string& ccn,
|
||||
TString& subj, TString& text, TToken_string& attach, short& ui)
|
||||
{
|
||||
|
||||
//to.cut(0) << _mail;
|
||||
to.cut(0) << "spalacino@sirio-is.it";
|
||||
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();
|
||||
|
||||
@ -105,13 +136,12 @@ bool TFp_mail_sender::get_mail(TToken_string& to, TToken_string& cc, TToken_stri
|
||||
text << saluti << '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
text << "Cordiali Saluti " << prefix().firm().ragione_sociale();
|
||||
}
|
||||
|
||||
text.trim();
|
||||
if (to.full())
|
||||
ui &= ~0x1; // No user interface
|
||||
ui |= 0x2; // Query receipt
|
||||
ui |= 0x2; // Query receipt
|
||||
return true;
|
||||
}
|
||||
// Funzione per spedire un pdf via mail
|
||||
@ -148,3 +178,9 @@ bool TFp_mail_sender::spotlite_send_mail()
|
||||
xvt_mail_send(to, cc, ccn, subj, text, attach, flags)) != 0;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TFp_mail_sender::set_alleg(const bool allega_fat)
|
||||
{
|
||||
_alleg = allega_fat;
|
||||
return _alleg;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user