瀏覽代碼

Rename document PDF on download

Mathieu Moulin 1 年之前
父節點
當前提交
36c1f82b1b
共有 2 個文件被更改,包括 39 次插入0 次删除
  1. 38 0
      class/actions_mmidocuments.class.php
  2. 1 0
      core/modules/modMMIDocuments.class.php

+ 38 - 0
class/actions_mmidocuments.class.php

@@ -241,4 +241,42 @@ class ActionsMMIDocuments extends MMI_Actions_1_0
 			return -1;
 		}
 	}
+
+	function downloadDocument($parameters, &$object, &$action, $hookmanager)
+	{
+		global $langs, $user, $conf;
+		
+		$error = '';
+
+		if ($this->in_context($parameters, 'document')) {
+			//var_dump($parameters); die();
+			if (in_array($parameters['modulepart'], ['propal', 'commande', 'facture'])
+				&& !empty($parameters['refname']) && $parameters['original_file'] == $parameters['refname'].'/'.$parameters['refname'].'.pdf'
+				&& !empty($conf->global->MMIDOCUMENT_PDF_RENAME)) {
+				global $db;
+				if ($parameters['modulepart'] == 'propal') {
+					require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
+					$object = new Propal($db);
+				}
+				elseif ($parameters['modulepart'] == 'commande') {
+					require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
+					$object = new Commande($db);
+				}
+				elseif ($parameters['modulepart'] == 'facture') {
+					require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+					$object = new Facture($db);
+				}
+				$object->fetch(NULL, $parameters['refname']);
+				//var_dump($object); die();
+				$parameters['filename'] = $object->pdf_filename().'.pdf';
+			}
+		}
+
+		if (!$error) {
+			return isset($ret) ?$ret :0; // or return 1 to replace standard code
+		} else {
+			$this->errors[] = $error;
+			return -1;
+		}
+	}
 }

+ 1 - 0
core/modules/modMMIDocuments.class.php

@@ -117,6 +117,7 @@ class modMMIDocuments extends DolibarrModules
 			// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
 			'hooks' => array(
 				'pdfgeneration',
+				'document',
 				//   'data' => array(
 				//       'hookcontext1',
 				//       'hookcontext2',