From c2696996791a72e05db356035512902a4143bbd4 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Sat, 5 May 2018 13:33:34 +0100 Subject: [PATCH] Add model_pdf to warehouse module --- htdocs/core/modules/modStock.class.php | 83 ++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index ca518ed8851..2cb53a52da4 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -60,7 +60,7 @@ class modStock extends DolibarrModules $this->picto='stock'; // Data directories to create when module is enabled - $this->dirs = array(); + $this->dirs = array("/stock/temp"); $this->config_page_url = array("stock.php"); @@ -70,9 +70,38 @@ class modStock extends DolibarrModules $this->langfiles = array("stocks"); // Constants - $this->const = array( - 0=>array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1) - ); + $this->const = array(); + $r=0; + + $this->const[$r] = array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1); + + $r++; + $this->const[$r][0] = "STOCK_ADDON_PDF"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "Standard"; + $this->const[$r][3] = 'Name of PDF model of stock'; + $this->const[$r][4] = 0; + + $r++; + $this->const[$r][0] = "MOUVEMENT_ADDON_PDF"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "StdMouvement"; + $this->const[$r][3] = 'Name of PDF model of stock mouvement'; + $this->const[$r][4] = 0; + + $r++; + $this->const[$r][0] = "STOCK_ADDON_PDF_ODT_PATH"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks"; + $this->const[$r][3] = ""; + $this->const[$r][4] = 0; + + $r++; + $this->const[$r][0] = "MOUVEMENT_ADDON_PDF_ODT_PATH"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/stocks/mouvements"; + $this->const[$r][3] = ""; + $this->const[$r][4] = 0; // Boxes $this->boxes = array(); @@ -266,4 +295,50 @@ class modStock extends DolibarrModules ); } + + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function init($options='') + { + global $conf,$langs; + + // Permissions + $this->remove($options); + + //ODT template + $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/stock/template_stock.odt'; + $dirodt=DOL_DATA_ROOT.'/doctemplates/stock'; + $dest=$dirodt.'/template_stock.odt'; + + if (file_exists($src) && ! file_exists($dest)) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + dol_mkdir($dirodt); + $result=dol_copy($src,$dest,0,0); + if ($result < 0) + { + $langs->load("errors"); + $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest); + return 0; + } + } + + $sql = array(); + + $sql = array( + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'stock' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','stock',".$conf->entity.")", + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'mouvement' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."','mouvement',".$conf->entity.")", + ); + + return $this->_init($sql,$options); + } }