From 82e3a8d0b9c16c744dde875a290d09f6d617f23a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20Garci=CC=81a?= <marcosgdf@gmail.com>
Date: Sun, 21 Apr 2013 14:14:30 +0200
Subject: [PATCH] New: [ task #823 ] Shipping_validate email notification

---
 ChangeLog                                     |  1 +
 ..._50_modNotification_Notification.class.php | 17 ++++++++++-
 htdocs/expedition/fiche.php                   | 30 +++++++++++++------
 htdocs/langs/en_US/other.lang                 |  1 +
 htdocs/langs/es_ES/other.lang                 |  1 +
 htdocs/langs/fr_FR/other.lang                 |  1 +
 6 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2eca52d30a7..22a4e6fde72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,7 @@ For users:
 - New: [ task #770 ] Add ODT document generation for Projects module
 - New: [ task #741 ] Add intervention box
 - New: [ task #826 ] Optionnal increase stock when deleting an invoice already validated
+- New: [ task #823 ] Shipping_validate email notification
 
 For translators:
 - Update language files.
diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php
index c2785445800..f3b10e7f1f8 100755
--- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php
+++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php
@@ -1,6 +1,7 @@
 <?php
 /* Copyright (C) 2006-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2011      Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2013      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -35,7 +36,8 @@ class InterfaceNotification
     	'PROPAL_VALIDATE',
         'FICHINTER_VALIDATE',
     	'ORDER_SUPPLIER_APPROVE',
-    	'ORDER_SUPPLIER_REFUSE'
+    	'ORDER_SUPPLIER_REFUSE',
+        'SHIPPING_VALIDATE'
    	);
 
     /**
@@ -196,6 +198,19 @@ class InterfaceNotification
             $notify = new Notify($this->db);
             $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
 		}
+        elseif ($action == 'SHIPPING_VALIDATE')
+        {
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+
+            $ref = dol_sanitizeFileName($object->ref);
+            $filepdf = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
+            if (! file_exists($filepdf)) $filepdf='';
+            $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref);
+
+
+            $notify = new Notify($this->db);
+            $notify->send($action, $object->socid, $mesg, 'expedition', $object->id, $filepdf);
+        }
 
 		// If not found
 /*
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index de3107b663f..996e41a649a 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -5,6 +5,7 @@
  * Copyright (C) 2005-2012	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2011-2012	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2013       Marcos García           <marcosgdf@gmail.com>
  *
  * 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
@@ -698,16 +699,16 @@ if ($action == 'create')
             //$lines = $object->fetch_lines(1);
             $numAsked = count($object->lines);
             
-            print '<script type="text/javascript" language="javascript">
-            jQuery(document).ready(function() {
-	            jQuery("#autofill").click(function() {';
+            print '<script type="text/javascript" language="javascript">
+            jQuery(document).ready(function() {
+	            jQuery("#autofill").click(function() {';
     	    	$i=0;
     	    	while($i < $numAsked)
     	    	{
     	    		print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
     	    		$i++;
-    	    	}
-        		print '});
+    	    	}
+        		print '});
 	            jQuery("#autoreset").click(function() {';
     	    	$i=0;
     	    	while($i < $numAsked)
@@ -716,8 +717,8 @@ if ($action == 'create')
     	    		$i++;
     	    	}
         		print '});
-        	});
-            </script>';
+        	});
+            </script>';
             
             
             print '<br>';
@@ -904,7 +905,7 @@ if ($action == 'create')
             
             print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
             
-            print '</form>';
+            print '</form>';
             
             print '<br>';
         }
@@ -974,7 +975,18 @@ else
                 {
                     $numref = $object->ref;
                 }
-                $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$numref),'confirm_valid','',0,1);
+
+                $text = $langs->trans("ConfirmValidateSending",$numref);
+
+                if (! empty($conf->notification->enabled))
+                {
+                    require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
+                    $notify=new Notify($db);
+                    $text.='<br>';
+                    $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid);
+                }
+
+                $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
                 if ($ret == 'html') print '<br>';
             }
             /*
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index 6a350078731..bb6c4873c93 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -152,6 +152,7 @@ EMailTextOrderApproved=The order %s has been approved.
 EMailTextOrderApprovedBy=The order %s has been approved by %s.
 EMailTextOrderRefused=The order %s has been refused.
 EMailTextOrderRefusedBy=The order %s has been refused by %s.
+EMailTextExpeditionValidated=The shipping %s has been validated.
 ImportedWithSet=Importation data set
 DolibarrNotification=Automatic notification
 ResizeDesc=Enter new width <b>OR</b> new height. Ratio will be kept during resizing...
diff --git a/htdocs/langs/es_ES/other.lang b/htdocs/langs/es_ES/other.lang
index 60af821e8c1..6d53b9de9cb 100644
--- a/htdocs/langs/es_ES/other.lang
+++ b/htdocs/langs/es_ES/other.lang
@@ -151,6 +151,7 @@ EMailTextOrderApproved=Pedido %s aprobado
 EMailTextOrderApprovedBy=Pedido %s aprobado por %s
 EMailTextOrderRefused=Pedido %s rechazado
 EMailTextOrderRefusedBy=Pedido %s rechazado por %s
+EMailTextExpeditionValidated=El envío %s ha sido validado.
 ImportedWithSet=Lote de importación (import key)
 DolibarrNotification=Notificación automática
 ResizeDesc=Introduzca el nuevo ancho <b>O</b> la nueva altura. La relación se conserva al cambiar el tamaño ...
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index de941e850a6..86218e219be 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -151,6 +151,7 @@ EMailTextOrderApproved=La commande %s a été approuvée.
 EMailTextOrderApprovedBy=La commande %s a été approuvée par %s.
 EMailTextOrderRefused=La commande %s a été refusée.
 EMailTextOrderRefusedBy=La commande %s a été refusée par %s.
+EMailTextExpeditionValidated=
 ImportedWithSet=Lot d'importation (Import key)
 DolibarrNotification=Notification automatique
 ResizeDesc=Entrer la nouvelle largeur <b>OU</b> la nouvelle hauteur. Le ratio est conservé lors du redimensionnement...
-- 
GitLab