diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 84f5ab76ad5..1feb4b8bbc6 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -471,6 +471,7 @@ class FormMail if ($this->param["models"]=='propal_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendProposal"); } if ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); } if ($this->param["models"]=='supplier_order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); } + if ($this->param["models"]=='supplier_facture_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } $defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs); if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; $defaultmessage=str_replace('\n',"\n",$defaultmessage); diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index ecff8ad3ec8..17a690fb4d7 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -483,6 +483,203 @@ if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer) } } + +/********************************************************************* + * + * Mail Actions + * + **********************************************************************/ + +/* + * Add file in email form + */ +if ($_POST['addfile']) +{ + require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); + + // Set tmp user directory TODO Use a dedicated directory for temp mails files + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir = $vardir.'/temp/'; + + $mesg=dol_add_file_process($upload_dir,0,0); + + $_GET["action"]='presend'; + $_POST["action"]='presend'; +} + +/* + * Remove file in email form + */ +if (! empty($_POST['removedfile'])) +{ + require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); + + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir = $vardir.'/temp/'; + + $mesg=dol_remove_file_process($_POST['removedfile'],0); + + $_GET["action"]='presend'; + $_POST["action"]='presend'; +} + +/* + * Send mail + */ +if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) +{ + $langs->load('mails'); + + $facturefourn=new FactureFournisseur($db); + $facturefourn->fetch($_GET['facid']); + $result=$facturefourn->fetch_thirdparty(); + if ($result > 0) + { + $ref = dol_sanitizeFileName($facturefourn->ref); + $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + + if (is_readable($file)) + { + if ($_POST['sendto']) + { + // Le destinataire a ete fourni via le champ libre + $sendto = $_POST['sendto']; + $sendtoid = 0; + } + elseif ($_POST['receiver']) + { + // Le destinataire a ete fourni via la liste deroulante + if ($_POST['receiver'] < 0) // Id du tiers + { + $sendto = $facturefourn->client->email; + $sendtoid = 0; + } + else // Id du contact + { + $sendto = $facturefourn->client->contact_get_email($_POST['receiver']); + $sendtoid = $_POST['receiver']; + } + } + + if (dol_strlen($sendto)) + { + $langs->load("commercial"); + + $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; + $message = $_POST['message']; + $sendtocc = $_POST['sendtocc']; + $deliveryreceipt = $_POST['deliveryreceipt']; + + if ($_POST['action'] == 'send') + { + if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; + else $subject = $langs->transnoentities('CustomerOrder').' '.$facturefourn->ref; + $actiontypecode='AC_SUP_ORD'; + $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; + if ($message) + { + $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; + $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; + $actionmsg.=$message; + } + $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); + } + + // Create form object + include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); + $formmail = new FormMail($db); + + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Send mail + require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); + if ($mailfile->error) + { + $mesg='
'.$mailfile->error.'
'; + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + $mesg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; + + $error=0; + + // Initialisation donnees + $facturefourn->sendtoid=$sendtoid; + $facturefourn->actiontypecode=$actiontypecode; + $facturefourn->actionmsg = $actionmsg; + $facturefourn->actionmsg2= $actionmsg2; + $facturefourn->supplierorderrowid=$facturefourn->id; + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$facturefourn,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + if ($error) + { + dol_print_error($db); + } + else + { + // Redirect here + // This avoid sending mail twice if going out and then back to page + Header('Location: '.$_SERVER["PHP_SELF"].'?faid='.$facturefourn->id.'&mesg='.urlencode($mesg)); + exit; + } + } + else + { + $langs->load("other"); + $mesg='
'; + if ($mailfile->error) + { + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.='
'; + } + } + } + + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').'
'; + dol_syslog('Recipient email is empty'); + } + } + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; + dol_syslog('Failed to read file: '.$file); + } + } + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
'; + dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.'); + } + + $_GET['action'] = 'presend'; +} + /* * Build document */ @@ -1245,103 +1442,169 @@ else print ''; } - - /* - * Boutons actions - */ - - print '
'; - - // Reopen a standard paid invoice - if (($fac->type == 0 || $fac->type == 1) && ($fac->statut == 2 || $fac->statut == 3)) // A paid invoice (partially or completely) + if ($_GET['action'] != 'presend') { - if (! $facidnext && $fac->close_code != 'replaced') // Not replaced by another invoice + + /* + * Boutons actions + */ + + print '
'; + + // Reopen a standard paid invoice + if (($fac->type == 0 || $fac->type == 1) && ($fac->statut == 2 || $fac->statut == 3)) // A paid invoice (partially or completely) { - print ''.$langs->trans('ReOpen').''; + if (! $facidnext && $fac->close_code != 'replaced') // Not replaced by another invoice + { + print ''.$langs->trans('ReOpen').''; + } + else + { + print ''.$langs->trans('ReOpen').''; + } } - else + + //Modify + if ($_GET['action'] != 'edit' && $fac->statut <= 1 && $fac->getSommePaiement() <= 0 && $user->rights->fournisseur->facture->creer) { - print ''.$langs->trans('ReOpen').''; + print ''.$langs->trans('Modify').''; } - } - - if ($_GET['action'] != 'edit' && $fac->statut <= 1 && $fac->getSommePaiement() <= 0 && $user->rights->fournisseur->facture->creer) - { - print ''.$langs->trans('Modify').''; - } - - if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - print ''.$langs->trans('DoPayment').''; - } - - if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) - { - print ''.$langs->trans('ClassifyPaid').''; - - //print ''.$langs->trans('ClassifyPaid').''; - } - - if ($_GET['action'] != 'edit' && $fac->statut == 0) - { - if (sizeof($fac->lines)) + + // Send by mail + if (($fac->statut == 1 || $fac->statut == 2) && $user->rights->facture->envoyer) { - if ($user->rights->fournisseur->facture->valider) - { - print ''.$langs->trans('Validate').''; - } - else - { - print ''.$langs->trans('Validate').''; - } + print ''.$langs->trans('SendByMail').''; } - } + + + //Make payments + if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) + { + print ''.$langs->trans('DoPayment').''; + } + + //Classify paid + if ($_GET['action'] != 'edit' && $fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0) + { + print ''.$langs->trans('ClassifyPaid').''; + + //print ''.$langs->trans('ClassifyPaid').''; + } + + //Validate + if ($_GET['action'] != 'edit' && $fac->statut == 0) + { + if (sizeof($fac->lines)) + { + if ($user->rights->fournisseur->facture->valider) + { + print ''.$langs->trans('Validate').''; + } + else + { + print ''.$langs->trans('Validate').''; + } + } + } + + //Clone + if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->creer) + { + print ''.$langs->trans('ToClone').''; + } + + //Delete + if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->supprimer) + { + print ''.$langs->trans('Delete').''; + } + print '
'; + + if ($_GET['action'] != 'edit') + { + print '
'; + print ''; // ancre + + /* + * Documents generes + */ + + $facfournref=dol_sanitizeFileName($fac->ref); + $file=$conf->fournisseur->dir_output.'/facture/'. $facfournref . '/' . $facfournref . '.pdf'; + $relativepath = $facfournref.'/'.$facfournref.'.pdf'; + $filedir = $conf->fournisseur->dir_output . '/facture/' . $facfournref; + $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id; + $genallowed=$user->rights->fournisseur->facture->creer; + $delallowed=$user->rights->fournisseur->facture->supprimer; + + $somethingshown=$formfile->show_documents('facture_fournisseur',$facfournref,$filedir,$urlsource,$genallowed,$delallowed,$facture->modelpdf); + + print ''; + print '
'; + + // List of actions on element + /* + include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); + $formactions=new FormActions($db); + $somethingshown=$formactions->showactions($fac,'invoice_supplier',$socid); + */ + + print '
'; + } + } + /* + * Show mail form + */ + if ($_GET['action'] == 'presend') + { + $ref = dol_sanitizeFileName($fac->ref); + $file = $conf->fournisseur->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + + print '
'; + print_titre($langs->trans('SendBillByMail')); - if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->creer) - { - print ''.$langs->trans('ToClone').''; - } + // Cree l'objet formulaire mail + include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); + $formmail = new FormMail($db); + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; + $formmail->withtosocid=$soc->id; + $formmail->withtocc=1; + $formmail->withtoccsocid=0; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtocccsocid=0; + $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__FACREF__']=$fac->ref; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='supplier_facture_send'; + $formmail->param['facid']=$fac->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?facid='.$fac->id; - if ($_GET['action'] != 'edit' && $user->rights->fournisseur->facture->supprimer) - { - print ''.$langs->trans('Delete').''; - } - print '
'; + // Init list of files + if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,$ref.'.pdf','application/pdf'); + } - if ($_GET['action'] != 'edit') - { - print '
'; - print ''; // ancre + // Show form + $formmail->show_form(); - /* - * Documents generes - */ - - $facfournref=dol_sanitizeFileName($fac->ref); - $file=$conf->fournisseur->dir_output.'/facture/'. $facfournref . '/' . $facfournref . '.pdf'; - $relativepath = $facfournref.'/'.$facfournref.'.pdf'; - $filedir = $conf->fournisseur->dir_output . '/facture/' . $facfournref; - $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id; - $genallowed=$user->rights->fournisseur->facture->creer; - $delallowed=$user->rights->fournisseur->facture->supprimer; - - $somethingshown=$formfile->show_documents('facture_fournisseur',$facfournref,$filedir,$urlsource,$genallowed,$delallowed,$facture->modelpdf); - - print ''; - print '
'; - - // List of actions on element - /* - include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); - $formactions=new FormActions($db); - $somethingshown=$formactions->showactions($fac,'invoice_supplier',$socid); - */ - - print '
'; - } + print '
'; + } } } diff --git a/htdocs/langs/ca_ES/other.lang b/htdocs/langs/ca_ES/other.lang index ad8224b520f..caa3f3f872c 100644 --- a/htdocs/langs/ca_ES/other.lang +++ b/htdocs/langs/ca_ES/other.lang @@ -47,6 +47,7 @@ PredefinedMailContentSendInvoiceReminder=Posem en el seu coneixement que la fact PredefinedMailContentSendProposal=Us adjuntem el pressupost __PROPREF__ \n\nCordialment\n\n PredefinedMailContentSendOrder=Us adjuntem la comanda __ORDERREF__ \n\nCordialment\n\n PredefinedMailContentSendSupplierOrder=Us adjuntem la nostra comanda __ORDERREF__ \n\nCordialment\n\n +PredefinedMailContentSendSupplierInvoice=Us adjuntem la factura __FACREF__\n\nCordialment\n\n DemoDesc=Dolibarr és un programari per a la gestió de negocis (professionals o associacions), compost de mòduls funcionals independents i opcionals. Una demostració que inclogui tots aquests mòduls no té sentit perquè no utilitzarà tots els mòduls. A més, té disponibles diversos tipus de perfils de demostració. ChooseYourDemoProfil=Voleu veure el perfil de demostració que millor correspongui a la seva activitat ... DemoFundation=Gestió de membres d'una associació diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 34a76dc0419..67e944fb27b 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -47,6 +47,7 @@ PredefinedMailContentSendInvoiceReminder=We would like to warn you that the invo PredefinedMailContentSendProposal=You will find here the commercial propoal __PROPREF__\n\nSincerely\n\n PredefinedMailContentSendOrder=You will find here the order __ORDERREF__\n\nSincerely\n\n PredefinedMailContentSendSupplierOrder=You will find here our order __ORDERREF__\n\nSincerely\n\n +PredefinedMailContentSendSupplierInvoice=You will find here the invoice __FACREF__\n\nSincerely\n\n DemoDesc=Dolibarr is a compact ERP/CRM composed by several functional modules. A demo that includes all modules does not mean anything as this never occurs. So, several demo profiles are available. ChooseYourDemoProfil=Choose the demo profile that match your activity... DemoFundation=Manage members of a foundation diff --git a/htdocs/langs/es_AR/other.lang b/htdocs/langs/es_AR/other.lang index bfc973b273d..4c1a4529587 100755 --- a/htdocs/langs/es_AR/other.lang +++ b/htdocs/langs/es_AR/other.lang @@ -47,6 +47,7 @@ PredefinedMailContentSendInvoiceReminder=Ponemos en su conocimiento que la factu PredefinedMailContentSendProposal=Le adjuntamos el presupuesto __PROPREF__\n\nCordialmente\n\n PredefinedMailContentSendOrder=Le adjuntamos el el pedido __ORDERREF__\n\nCordialmente\n\n PredefinedMailContentSendSupplierOrder=Le adjuntamos nuestro pedido __ORDERREF__\n\nCordialmente\n\n +PredefinedMailContentSendSupplierInvoice=Le adjuntamos la factura __FACREF__\n\nCordialmente\n\n DemoDesc=Dolibarr es un software para la gestión de negocios (profesionales o asociaciones), compuesto de módulos funcionales independientes y opcionales. Una demostración que incluya todos estos módulos no tiene sentido porque no utilizará todos los módulos. Además, tiene disponibles varios tipos de perfiles de demostración. ChooseYourDemoProfil=Quiere ver el perfil de demostración que mejor corresponda a su actividad... DemoFundation=Gesstión de miembros de una asociación diff --git a/htdocs/langs/es_ES/other.lang b/htdocs/langs/es_ES/other.lang index 48763c4ae95..d3cebeb61ae 100644 --- a/htdocs/langs/es_ES/other.lang +++ b/htdocs/langs/es_ES/other.lang @@ -47,6 +47,7 @@ PredefinedMailContentSendInvoiceReminder=Ponemos en su conocimiento que la factu PredefinedMailContentSendProposal=Le adjuntamos el presupuesto __PROPREF__\n\nCordialmente\n\n PredefinedMailContentSendOrder=Le adjuntamos el pedido __ORDERREF__\n\nCordialmente\n\n PredefinedMailContentSendSupplierOrder=Le adjuntamos nuestro pedido __ORDERREF__\n\nCordialmente\n\n +PredefinedMailContentSendSupplierInvoice=Le adjuntamos la factura __FACREF__\n\nCordialmente\n\n DemoDesc=Dolibarr es un software para la gestión de negocios (profesionales o asociaciones), compuesto de módulos funcionales independientes y opcionales. Una demostración que incluya todos estos módulos no tiene sentido porque no utilizará todos los módulos. Además, tiene disponibles varios tipos de perfiles de demostración. ChooseYourDemoProfil=Quiere ver el perfil de demostración que mejor corresponda a su actividad... DemoFundation=Gesstión de miembros de una asociación diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index 4fe2638cef0..ca26a8ee760 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -47,6 +47,7 @@ PredefinedMailContentSendInvoiceReminder=Nous apportons à votre connaissance qu PredefinedMailContentSendProposal=Veuillez trouver ci-joint la proposition commerciale __PROPREF__\n\nCordialement\n\n PredefinedMailContentSendOrder=Veuillez trouver ci-joint la commande __ORDERREF__\n\nCordialement\n\n PredefinedMailContentSendSupplierOrder=Veuillez trouver ci-joint notre commande __ORDERREF__\n\nCordialement\n\n +PredefinedMailContentSendSupplierInvoice=Veuillez trouver ci-joint la facture __FACREF__\n\nCordialement\n\n DemoDesc=Dolibarr est un logiciel de gestion d'activité (professionnelle ou associative) composé de modules fonctionnels indépendants et optionnels. Une démonstration qui inclut tous ces modules n'a pas de sens car les modules ne sont jamais tous utilisés en même temps. Aussi, plusieurs profils type de démo sont disponibles. ChooseYourDemoProfil=Veuillez choisir le profil de démo qui correspond le mieux à votre activité... DemoFundation=Gestion des adhérents d'une association