2
0
forked from Wavyzz/dolibarr

Fix: Debug module notification.

New: Can use email notification when validating proposal or orders.
This commit is contained in:
Laurent Destailleur
2010-01-09 14:48:27 +00:00
parent 5d6b814a39
commit 38e757f4ae
7 changed files with 271 additions and 231 deletions

View File

@@ -973,7 +973,27 @@ if ($id > 0 || ! empty($ref))
*/
if ($_GET['action'] == 'validate')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('ValidateProp'), $langs->trans('ConfirmValidateProp'), 'confirm_validate','',0,1);
// on verifie si l'objet est en numerotation provisoire
$ref = substr($propal->ref, 1, 4);
if ($ref == 'PROV')
{
$numref = $propal->getNextNumRef($soc);
}
else
{
$numref = $propal->ref;
}
$text=$langs->trans('ConfirmValidateProp',$numref);
if ($conf->notification->enabled)
{
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
$notify=new Notify($db);
$text.='<br>';
$text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$propal->socid);
}
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?propalid='.$propal->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1);
if ($ret == 'html') print '<br>';
}

View File

@@ -1242,18 +1242,25 @@ else
*/
if ($_GET['action'] == 'validate')
{
// on verifie si la facture est en numerotation provisoire
// on verifie si l'objet est en numerotation provisoire
$ref = substr($commande->ref, 1, 4);
if ($ref == 'PROV')
{
$num = $commande->getNextNumRef($soc);
$numref = $commande->getNextNumRef($soc);
}
else
{
$num = $commande->ref;
$numref = $commande->ref;
}
$text=$langs->trans('ConfirmValidateOrder',$num);
$text=$langs->trans('ConfirmValidateOrder',$numref);
if ($conf->notification->enabled)
{
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
$notify=new Notify($db);
$text.='<br>';
$text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$commande->socid);
}
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', '', 0, 1);
if ($ret == 'html') print '<br>';
}

View File

@@ -2060,7 +2060,7 @@ else
// Confirmation de la validation
if ($_GET['action'] == 'valid')
{
// on verifie si la facture est en numerotation provisoire
// on verifie si l'objet est en numerotation provisoire
$facref = substr($fac->ref, 1, 4);
if ($facref == 'PROV')
{
@@ -2070,21 +2070,21 @@ else
$fac->date=gmmktime();
$fac->date_lim_reglement=$fac->calculate_date_lim_reglement();
}
$numfa = $fac->getNextNumRef($soc);
$numref = $fac->getNextNumRef($soc);
//$fac->date=$savdate;
}
else
{
$numfa = $fac->ref;
$numref = $fac->ref;
}
$text=$langs->trans('ConfirmValidateBill',$numfa);
$text=$langs->trans('ConfirmValidateBill',$numref);
if ($conf->notification->enabled)
{
require_once(DOL_DOCUMENT_ROOT ."/notify.class.php");
$notify=new Notify($db);
$text.='<br>';
$text.=$notify->confirmMessage(2,$fac->socid);
$text.=$notify->confirmMessage('NOTIFY_VAL_FAC',$fac->socid);
}
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$text,'confirm_valid','',0,($conf->notification->enabled?0:2));

View File

@@ -129,11 +129,11 @@ class InterfaceNotification
$notify->send($action_notify, $object->socid, $mesg, 'order', $object->id, $filepdf);
}
elseif ($action == 'PROPOSAL_VALIDATE')
elseif ($action == 'PROPAL_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$action_notify = 'NOTIFY_VAL_PROPOSAL';
$action_notify = 'NOTIFY_VAL_PROPAL';
$ref = dol_sanitizeFileName($object->ref);
$filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf';
if (! file_exists($filepdf)) $filepdf='';

View File

@@ -33,6 +33,7 @@ ALTER TABLE llx_facture_fourn_det MODIFY COLUMN qty real;
ALTER TABLE llx_projet ADD COLUMN datee DATE AFTER dateo;
ALTER TABLE llx_notify ADD COLUMN email VARCHAR(255);
insert into llx_action_def (rowid,code,titre,description,objet_type) values (5,'NOTIFY_VAL_ORDER','Validation commande client','Executed when a customer order is validated','order');
insert into llx_action_def (rowid,code,titre,description,objet_type) values (6,'NOTIFY_VAL_PROPAL','Validation proposition client','Executed when a commercial proposal is validated','propal');

View File

@@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@@ -26,5 +27,6 @@ create table llx_notify
fk_action integer NOT NULL,
fk_contact integer NOT NULL,
objet_type varchar(24) NOT NULL,
objet_id integer NOT NULL
objet_id integer NOT NULL,
email varchar(255)
)type=innodb;

View File

@@ -61,6 +61,8 @@ class Notify
/**
* \brief Renvoie le message signalant les notifications qui auront lieu sur
* un evenement pour affichage dans texte de confirmation evenement.
* \param action Id of action in llx_action_def
* \param socid Id of third party
* \return string Message
*/
function confirmMessage($action,$socid)
@@ -76,7 +78,9 @@ class Notify
}
/**
* \brief Renvoie le nombre de notifications configures pour l'action et la societe donnee
* \brief Return number of notifications activated for action code and third party
* \param action Code of action in llx_action_def (new usage) or Id of action in llx_action_def (old usage)
* \param socid Id of third party
* \return int <0 si ko, sinon nombre de notifications definies
*/
function countDefinedNotifications($action,$socid)
@@ -87,7 +91,8 @@ class Notify
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
$sql.= " AND n.fk_soc = s.rowid";
$sql.= " AND n.fk_action = ".$action;
if (is_numeric($action)) $sql.= " AND n.fk_action = ".$action; // Old usage
else $sql.= " AND a.code = '".$action."'"; // New usage
$sql.= " AND s.rowid = ".$socid;
dol_syslog("Notify.class::countDefinedNotifications $action, $socid");
@@ -109,7 +114,7 @@ class Notify
/**
* \brief Check if notification are active for couple action/company.
* If yes, send mail and save trace into llx_notify.
* \param action Code of action to check and send (list in llx_action_def)
* \param action Code of action in llx_action_def (new usage) or Id of action in llx_action_def (old usage)
* \param socid Id of third party
* \param texte Message to send
* \param objet_type Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify.
@@ -123,25 +128,29 @@ class Notify
$langs->load("other");
$sql = "SELECT s.nom, c.email, c.rowid, c.name, c.firstname, a.titre,n.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
$sql .= " AND n.fk_soc = s.rowid";
$sql .= " AND a.code = '".$action."'";
$sql .= " AND s.rowid = ".$socid;
dol_syslog("Notify::send $action, $socid, $texte, $objet_type, $objet_id, $file");
$sql = "SELECT s.nom, c.email, c.rowid, c.name, c.firstname,";
$sql.= " a.rowid as adid, a.titre, a.code, n.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c, ".MAIN_DB_PREFIX."action_def as a, ".MAIN_DB_PREFIX."notify_def as n, ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
$sql.= " AND n.fk_soc = s.rowid";
if (is_numeric($action)) $sql.= " AND n.fk_action = ".$action; // Old usage
else $sql.= " AND a.code = '".$action."'"; // New usage
$sql .= " AND s.rowid = ".$socid;
dol_syslog("Notify::send sql=".$sql);
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
while ($i < $num) // For each notification couple defined (third party/actioncode)
{
$obj = $this->db->fetch_object($result);
$sendto = $obj->firstname . " " . $obj->name . " <".$obj->email.">";
$actiondefid = $obj->adid;
if (strlen($sendto))
{
@@ -166,8 +175,9 @@ class Notify
{
$sendto = htmlentities($sendto);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id)";
$sql.= " VALUES (".$this->db->idate(mktime()).", ".$action." ,".$obj->rowid." , '".$objet_type."', ".$objet_id.");";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
$sql.= " VALUES (".$this->db->idate(mktime()).", ".$actiondefid." ,".$obj->rowid." , '".$objet_type."', ".$objet_id.", '".addslashes($obj->email)."')";
dol_syslog("Notify::send sql=".$sql);
if (! $this->db->query($sql) )
{
dol_print_error($this->db);