diff --git a/ChangeLog b/ChangeLog index dc79f3a44c1..2dfff9a6e0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,24 +5,26 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.2 compared to 3.1 ***** For users: -- New: task #11243: Show quantity into stocks for each sub-products into the sub-product tab -- New: task #10500: Option to choose if professional id are unique -- New: Add hidden option FOURN_PRODUCT_AVAILABILITY -- New: task #11123: Add best supplier price +- New: Can edit customer discounts from invoice create and edit card. +- New: task #11243: Show quantity into stocks for each sub-products into the sub-product tab. +- New: task #10500: Option to choose if professional id are unique. +- New: Add hidden option FOURN_PRODUCT_AVAILABILITY. +- New: task #11123: Add best supplier price. - New: Enhancement in styles. -- New: task #11289 : Modify third party accountancy code generator aquarium -- New: task #10606 : more comprehensive message error -- New: task #11278 : Option into point of sale module to add services in list +- New: task #11289 : Modify third party accountancy code generator aquarium. +- New: task #10606 : more comprehensive message error. +- New: task #11278 : Option into point of sale module to add services in list. - New: task #11261 : Add an entry into menu called "New shipment". -- New: Make option MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT available by default +- New: Make option MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT available by default. - New: Can build PDF in USLetter format or canada format. For developers: - Qual: Removed no more used external libraries. - Qual: Cleaned a lot of dead code. - Qual: Parent templates classes were moved as abstract classes. -- Qual: Added more "hooks" +- Qual: Add more "hooks". - Qual: Add "canvas" feature to overwrite page of thirdparty, contact, product with yours. +- More OOP (usage of "abstract", "static", ...), unifformize constructors. ***** ChangeLog for 3.1 compared to 3.0 ***** diff --git a/htdocs/accountancy/class/accountancysystem.class.php b/htdocs/accountancy/class/accountancysystem.class.php index e1da0c851a6..0dbad6754b1 100644 --- a/htdocs/accountancy/class/accountancysystem.class.php +++ b/htdocs/accountancy/class/accountancysystem.class.php @@ -40,21 +40,21 @@ class AccountancySystem /** - * \brief Constructor of class - * \param DB Database handler - * \param id Id compte (0 by default) + * Constructor + * + * @param DoliDB $DB Database handler */ - function AccountancySystem($DB, $id=0) + function AccountancySystem($DB) { $this->db = $DB; - $this->id = $id ; } /** - * \brief Insert accountancy system name into database - * \param user User making insert - * \return int <0 if KO, Id of line if OK + * Insert accountancy system name into database + * + * @param User $user User making insert + * @return int <0 if KO, Id of line if OK */ function create($user) { diff --git a/htdocs/bookmarks/class/bookmark.class.php b/htdocs/bookmarks/class/bookmark.class.php index afe18f165b8..6bfd0b6c286 100644 --- a/htdocs/bookmarks/class/bookmark.class.php +++ b/htdocs/bookmarks/class/bookmark.class.php @@ -41,15 +41,13 @@ class Bookmark /** - * Constructor - * - * @param DoliDB $db Handler for Database Access - * @param int $id Bookmark Id + * Constructor + * + * @param DoliDB $DB Database handler */ - function Bookmark($db, $id=-1) + function Bookmark($db) { $this->db = $db; - $this->id = $id; } /** diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index 683d9cc8f70..5b1ab4595bd 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -70,7 +70,7 @@ class Facturation { /** - * Constructor + * Constructor */ public function Facturation() { diff --git a/htdocs/cashdesk/facturation_verif.php b/htdocs/cashdesk/facturation_verif.php index 4530b2031b6..8d28f73439d 100644 --- a/htdocs/cashdesk/facturation_verif.php +++ b/htdocs/cashdesk/facturation_verif.php @@ -68,12 +68,13 @@ switch ( $_GET['action'] ) { $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; $productid = $ret['rowid']; - + $societe = new Societe($db); $societe->fetch($thirdpartyid); - - $product = new Product($db, $productid); - + + $product = new Product($db); + $product->fetch($productid); + if(isset($product->multiprices[$societe->price_level])) { $ret['price'] = $product->multiprices_ttc[$societe->price_level]; @@ -82,9 +83,9 @@ switch ( $_GET['action'] ) // $product->multiprices_base_type[$societe->price_level]; $ret['tva_tx'] = $product->multiprices_tva_tx[$societe->price_level]; } - } + } /** end add Ditto */ - + $obj_facturation->id( $ret['rowid'] ); $obj_facturation->ref( $ret['ref'] ); $obj_facturation->stock( $ret['reel'] ); diff --git a/htdocs/cashdesk/tpl/liste_articles.tpl.php b/htdocs/cashdesk/tpl/liste_articles.tpl.php index 78e4b60867e..61c3b283183 100644 --- a/htdocs/cashdesk/tpl/liste_articles.tpl.php +++ b/htdocs/cashdesk/tpl/liste_articles.tpl.php @@ -64,7 +64,8 @@ along with this program. If not, see . /** add Ditto for MultiPrix*/ if($conf->global->PRODUIT_MULTIPRICES) { - $product = new Product($db, $ret[$i]['id']); + $product = new Product($db); + $product->fetch($ret[$i]['id']); if(isset($product->multiprices[$societe->price_level])) { diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 7173ad4f122..2bffb92b113 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -55,23 +55,23 @@ class Categorie /** - * Constructor + * Constructor * - * @param DB acces base de donnees - * @param id id de la categorie + * @param DoliDB $DB Database handler + * @param int $id Id of category to fetch during init */ function Categorie($DB, $id=-1) { $this->db = $DB; $this->id = $id; - if ($id != -1) $this->fetch ($this->id); + if ($id != -1) $this->fetch($this->id); } /** * Load category into memory from database * - * @param id id of category + * @param int $id Id of category */ function fetch($id) { @@ -216,7 +216,7 @@ class Categorie $this->description=trim($this->description); $this->parentId = ($this->id_mere) != "" ? intval($this->id_mere) : 0; $this->visible = ($this->visible) != "" ? intval($this->visible) : 0; - + if ($this->already_exists()) { $this->error=$langs->trans("ImpossibleUpdateCat"); diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 2ce4e6e5f5f..acb12159f9e 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -105,12 +105,8 @@ llxHeader("","",$langs->trans("Categories")); print_fiche_titre($langs->trans("ModifCat")); -if ($mesg) -{ - print '
'; - print $mesg; - print '
'; -} +dol_htmloutput_errors($mesg); + $categorie = new Categorie($db, $id); $html = new Form($db); diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 98cb3494a8b..4c0049d8cb0 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -84,14 +84,16 @@ if ($_POST['action'] == 'setcustomeraccountancycode') if ($_GET["action"] == 'attribute_prefix' && $user->rights->societe->creer) { - $societe = new Societe($db, $_GET["socid"]); + $societe = new Societe($db); + $societe->fetch($_GET["socid"]); $societe->attribute_prefix($db, $_GET["socid"]); } // conditions de reglement if ($_POST["action"] == 'setconditions' && $user->rights->societe->creer) { - $societe = new Societe($db, $_GET["socid"]); + $societe = new Societe($db); + $societe->fetch($_GET["socid"]); $societe->cond_reglement=$_POST['cond_reglement_id']; $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET cond_reglement='".$_POST['cond_reglement_id']; $sql.= "' WHERE rowid='".$_GET["socid"]."'"; @@ -101,7 +103,8 @@ if ($_POST["action"] == 'setconditions' && $user->rights->societe->creer) // mode de reglement if ($_POST["action"] == 'setmode' && $user->rights->societe->creer) { - $societe = new Societe($db, $_GET["socid"]); + $societe = new Societe($db); + $societe->fetch($_GET["socid"]); $societe->mode_reglement=$_POST['mode_reglement_id']; $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET mode_reglement='".$_POST['mode_reglement_id']; $sql.= "' WHERE rowid='".$_GET["socid"]."'"; @@ -111,7 +114,8 @@ if ($_POST["action"] == 'setmode' && $user->rights->societe->creer) // assujetissement a la TVA if ($_POST["action"] == 'setassujtva' && $user->rights->societe->creer) { - $societe = new Societe($db, $_GET["socid"]); + $societe = new Societe($db); + $societe->fetch($_GET["socid"]); $societe->tva_assuj=$_POST['assujtva_value']; $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$socid."'"; $result = $db->query($sql); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index b9fe58eed1f..5b2d1522d62 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -661,7 +661,7 @@ if ($_POST['action'] == "addline" && $user->rights->propale->creer) // Ecrase $txtva par celui du produit if ($_POST['idprod']) { - $prod = new Product($db, $_POST['idprod']); + $prod = new Product($db); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php index 56a229b63ac..a7556454a3c 100644 --- a/htdocs/comm/propal/apercu.php +++ b/htdocs/comm/propal/apercu.php @@ -62,7 +62,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $object->socid); + $soc = new Societe($db); $soc->fetch($object->socid); $head = propal_prepare_head($object); diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 2f00edaac72..a6e818a07ac 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -138,7 +138,7 @@ if ($id > 0 || ! empty($ref)) $propal = New Propal($db); if ( $propal->fetch($id,$ref) > 0) { - $soc = new Societe($db, $propal->socid); + $soc = new Societe($db); $soc->fetch($propal->socid); diff --git a/htdocs/comm/prospect/fiche.php b/htdocs/comm/prospect/fiche.php index 2b33767f889..47463460abe 100644 --- a/htdocs/comm/prospect/fiche.php +++ b/htdocs/comm/prospect/fiche.php @@ -55,7 +55,8 @@ if ($_GET["action"] == 'cstc') // set prospect level if ($_POST["action"] == 'setprospectlevel' && $user->rights->societe->creer) { - $societe = new Societe($db, $_GET["socid"]); + $societe = new Societe($db); + $societe->fetch($_GET["socid"]); $societe->fk_prospectlevel=$_POST['prospect_level_id']; $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_prospectlevel='".$_POST['prospect_level_id']; $sql.= "' WHERE rowid='".$_GET["socid"]."'"; diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php index b460d1176ff..348e0000ba7 100644 --- a/htdocs/commande/apercu.php +++ b/htdocs/commande/apercu.php @@ -65,7 +65,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $object->socid); + $soc = new Societe($db); $soc->fetch($object->socid); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 8066a72121c..e999090bb21 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -99,10 +99,11 @@ class Commande extends CommonObject /** - * \brief Constructeur - * \param DB Handler d'acces base + * Constructor + * + * @param DoliDB $DB Database handler */ - function Commande($DB, $socid="", $commandeid=0) + function Commande($DB) { global $langs; $langs->load('orders'); @@ -1152,7 +1153,8 @@ class Commande extends CommonObject /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) { - $prod = new Product($this->db, $idproduct); + $prod = new Product($this->db); + $prod->fetch($idproduct); $prod -> get_sousproduits_arbo (); $prods_arbo = $prod->get_each_prod(); if(sizeof($prods_arbo) > 0) diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index f77d771e3f6..4d4d240500e 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -134,7 +134,7 @@ if ($id > 0 || ! empty($ref)) $commande = new Commande($db); if ( $commande->fetch($_GET['id'],$_GET['ref']) > 0) { - $soc = new Societe($db, $commande->socid); + $soc = new Societe($db); $soc->fetch($commande->socid); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 13e012ba97c..0f2a2c5651d 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -510,7 +510,7 @@ if ($action == 'addline' && $user->rights->commande->creer) // Ecrase $base_price_type par celui du produit if ($_POST['idprod']) { - $prod = new Product($db, $_POST['idprod']); + $prod = new Product($db); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); diff --git a/htdocs/commande/info.php b/htdocs/commande/info.php index 0582d7f6ecb..cc09dbeac21 100644 --- a/htdocs/commande/info.php +++ b/htdocs/commande/info.php @@ -49,7 +49,7 @@ llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES $commande = new Commande($db); $commande->fetch($_GET["id"]); $commande->info($_GET["id"]); -$soc = new Societe($db, $commande->socid); +$soc = new Societe($db); $soc->fetch($commande->socid); $head = commande_prepare_head($commande); diff --git a/htdocs/commande/note.php b/htdocs/commande/note.php index 68b08227398..343b5d38e2b 100644 --- a/htdocs/commande/note.php +++ b/htdocs/commande/note.php @@ -85,7 +85,7 @@ $html = new Form($db); if ($id > 0 || ! empty($ref)) { - $soc = new Societe($db, $commande->socid); + $soc = new Societe($db); $soc->fetch($commande->socid); $head = commande_prepare_head($commande); diff --git a/htdocs/compta/bank/class/bankcateg.class.php b/htdocs/compta/bank/class/bankcateg.class.php index 8f420ea51e5..32b341c3276 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -36,94 +36,96 @@ */ class BankCateg // extends CommonObject { - var $db; //!< To store db handler - var $error; //!< To return error code (or message) - var $errors=array(); //!< To return several error codes (or messages) - //var $element='bank_categ'; //!< Id that identify managed objects - //var $table_element='bank_categ'; //!< Name of table without prefix where object is stored + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + //var $element='bank_categ'; //!< Id that identify managed objects + //var $table_element='bank_categ'; //!< Name of table without prefix where object is stored - var $id; + var $id; - var $label; + var $label; /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function BankCateg($DB) { - $this->db = $DB; - return 1; + $this->db = $DB; + return 1; } /** - * \brief Create in database - * \param user User that create - * \param notrigger 0=launch triggers after, 1=disable triggers - * \return int <0 if KO, Id of created object if OK + * Create in database + * + * @param user User that create + * @param notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, Id of created object if OK */ function create($user, $notrigger=0) { - global $conf, $langs; - $error=0; + global $conf, $langs; + $error=0; - // Clean parameters - if (isset($this->label)) $this->label=trim($this->label); + // Clean parameters + if (isset($this->label)) $this->label=trim($this->label); - // Check parameters - // Put here code to add control on parameters values + // Check parameters + // Put here code to add control on parameters values - // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ ("; - $sql.= "label"; - $sql.= ", entity"; - $sql.= ") VALUES ("; - $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").""; - $sql.= ", ".$conf->entity; - $sql.= ")"; + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ ("; + $sql.= "label"; + $sql.= ", entity"; + $sql.= ") VALUES ("; + $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").""; + $sql.= ", ".$conf->entity; + $sql.= ")"; - $this->db->begin(); + $this->db->begin(); - dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - if (! $error) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_categ"); + if (! $error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_categ"); - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. - //// Call triggers - //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } } // Commit or rollback if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); return $this->id; - } + } } @@ -134,36 +136,36 @@ class BankCateg // extends CommonObject */ function fetch($id) { - global $langs,$conf; + global $langs,$conf; - $sql = "SELECT"; - $sql.= " t.rowid,"; - $sql.= " t.label"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as t"; - $sql.= " WHERE t.rowid = ".$id; - $sql.= " AND t.entity = ".$conf->entity; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.label"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as t"; + $sql.= " WHERE t.rowid = ".$id; + $sql.= " AND t.entity = ".$conf->entity; - dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) { - $obj = $this->db->fetch_object($resql); + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->label = $obj->label; + $this->id = $obj->rowid; + $this->label = $obj->label; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; } - $this->db->free($resql); - - return 1; - } - else - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); - return -1; - } } @@ -175,185 +177,185 @@ class BankCateg // extends CommonObject */ function update($user=0, $notrigger=0) { - global $conf, $langs; - $error=0; + global $conf, $langs; + $error=0; - // Clean parameters - if (isset($this->label)) $this->label=trim($this->label); + // Clean parameters + if (isset($this->label)) $this->label=trim($this->label); - // Check parameters - // Put here code to add control on parameters values + // Check parameters + // Put here code to add control on parameters values - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."bank_categ SET"; - $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").""; - $sql.= " WHERE rowid=".$this->id; - $sql.= " AND entity = ".$conf->entity; + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."bank_categ SET"; + $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").""; + $sql.= " WHERE rowid=".$this->id; + $sql.= " AND entity = ".$conf->entity; - $this->db->begin(); + $this->db->begin(); - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. - //// Call triggers - //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } - } + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } } - /** - * \brief Delete object in database + /** + * \brief Delete object in database * \param user User that delete * \param notrigger 0=launch triggers after, 1=disable triggers - * \return int <0 if KO, >0 if OK - */ - function delete($user, $notrigger=0) - { - global $conf, $langs; - $error=0; + * \return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; - $sql.= " WHERE rowid=".$this->id; - $sql.= " AND entity = ".$conf->entity; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; + $sql.= " WHERE rowid=".$this->id; + $sql.= " AND entity = ".$conf->entity; - $this->db->begin(); + $this->db->begin(); - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. - //// Call triggers - //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } - } + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } - } + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } - /** - * \brief Load an object from its id and create a new one in database - * \param fromid Id of object to clone - * \return int New id of clone - */ - function createFromClone($fromid) - { - global $user,$langs; + /** + * \brief Load an object from its id and create a new one in database + * \param fromid Id of object to clone + * \return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; - $error=0; + $error=0; - $object=new Bank_categ($this->db); + $object=new Bank_categ($this->db); - $this->db->begin(); + $this->db->begin(); - // Load source object - $object->fetch($fromid); - $object->id=0; - $object->statut=0; + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; - // Clear fields - // ... + // Clear fields + // ... - // Create clone - $result=$object->create($user); + // Create clone + $result=$object->create($user); - // Other options - if ($result < 0) - { - $this->error=$object->error; - $error++; - } + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } - if (! $error) - { + if (! $error) + { - } + } - // End - if (! $error) - { - $this->db->commit(); - return $object->id; - } - else - { - $this->db->rollback(); - return -1; - } - } + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } - /** - * \brief Initialise object with example values - * \remarks id must be 0 if object instance is a specimen. - */ - function initAsSpecimen() - { - $this->id=0; + /** + * \brief Initialise object with example values + * \remarks id must be 0 if object instance is a specimen. + */ + function initAsSpecimen() + { + $this->id=0; - $this->label=''; + $this->label=''; - } + } } ?> diff --git a/htdocs/compta/clients.php b/htdocs/compta/clients.php index a04d049d318..da534537bed 100644 --- a/htdocs/compta/clients.php +++ b/htdocs/compta/clients.php @@ -63,7 +63,8 @@ $thirdpartystatic=new Societe($db); if ($action == 'attribute_prefix') { - $societe = new Societe($db, $socid); + $societe = new Societe($db); + $societe->fetch($socid); $societe->attribute_prefix($db, $socid); } diff --git a/htdocs/compta/deplacement/note.php b/htdocs/compta/deplacement/note.php index 2e07c713dfa..2ef51313192 100644 --- a/htdocs/compta/deplacement/note.php +++ b/htdocs/compta/deplacement/note.php @@ -102,7 +102,7 @@ if ($id > 0 || ! empty($ref)) $trip = new Deplacement($db); $trip->fetch($id,$ref); - $soc = new Societe($db, $trip->socid); + $soc = new Societe($db); $soc->fetch($trip->socid); $h=0; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 0019765095f..ce03fde199f 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -903,7 +903,7 @@ if (($action == 'addline' || $action == 'addline_predef') && $user->rights->fact // Ecrase $base_price_type par celui du produit if ($_POST['idprod']) { - $prod = new Product($db, $_POST['idprod']); + $prod = new Product($db); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); @@ -1884,7 +1884,7 @@ else $result=$object->fetch_thirdparty(); - $soc = new Societe($db, $object->socid); + $soc = new Societe($db); $soc->fetch($object->socid); $totalpaye = $object->getSommePaiement(); diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index cbc544f193b..aebabed12d3 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -63,7 +63,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $object->socid); + $soc = new Societe($db); $soc->fetch($object->socid); $author = new User($db); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5ee4c1142bf..5b313e49850 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -372,7 +372,7 @@ class Facture extends CommonObject { if ($_facrec->lines[$i]->fk_product) { - $prod = new Product($this->db, $_facrec->lines[$i]->fk_product); + $prod = new Product($this->db); $res=$prod->fetch($_facrec->lines[$i]->fk_product); } $tva_tx = get_default_tva($mysoc,$soc,$prod->id); diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index c5e9e456e88..381d643fdbb 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -337,7 +337,7 @@ else if ($fac->fetch($facid, $user->societe_id) > 0) { - $soc = new Societe($db, $fac->socid); + $soc = new Societe($db); $soc->fetch($fac->socid); $author = new User($db); $author->fetch($fac->user_author); diff --git a/htdocs/compta/facture/info.php b/htdocs/compta/facture/info.php index 50821b3fea0..5f04fda1944 100644 --- a/htdocs/compta/facture/info.php +++ b/htdocs/compta/facture/info.php @@ -41,7 +41,7 @@ $fac = new Facture($db); $fac->fetch($_GET["facid"]); $fac->info($_GET["facid"]); -$soc = new Societe($db, $fac->socid); +$soc = new Societe($db); $soc->fetch($fac->socid); $head = facture_prepare_head($fac); diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php index 7fdf45eab26..6fbb1b18049 100644 --- a/htdocs/compta/facture/note.php +++ b/htdocs/compta/facture/note.php @@ -100,7 +100,7 @@ if ($id > 0 || ! empty($ref)) $fac = new Facture($db); $fac->fetch($id,$ref); - $soc = new Societe($db, $fac->socid); + $soc = new Societe($db); $soc->fetch($fac->socid); $head = facture_prepare_head($fac); diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 0818f95f458..1e1feb3dbe0 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -105,7 +105,7 @@ if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"]) { if ($mesg) print $mesg.'
'; - $soc = new Societe($db, $fac->socid); + $soc = new Societe($db); $soc->fetch($fac->socid); $totalpaye = $fac->getSommePaiement(); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 571563521d7..b3b689d5737 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -44,9 +44,9 @@ class RemiseCheque extends CommonObject var $errno; /** - * Constructor + * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $DB Database handler */ function RemiseCheque($DB) { diff --git a/htdocs/compta/prelevement/class/bon-prelevement.class.php b/htdocs/compta/prelevement/class/bon-prelevement.class.php index b8f20830aca..c29a0d77d36 100644 --- a/htdocs/compta/prelevement/class/bon-prelevement.class.php +++ b/htdocs/compta/prelevement/class/bon-prelevement.class.php @@ -50,14 +50,16 @@ class BonPrelevement extends CommonObject var $statut; // 0-Wait, 1-Trans, 2-Done var $labelstatut=array(); - /** - * Class constructor - * @param DB data base handler access - * @param filename filename - */ + + /** + * Constructor + * + * @param DoliDB $DB Database handler + * @param string $filename Filename of withdraw receipt + */ function BonPrelevement($DB, $filename='') { - global $conf,$langs; + global $conf,$langs; $error = 0; $this->db = $DB; @@ -84,26 +86,26 @@ class BonPrelevement extends CommonObject $this->_fetched = 0; - $langs->load("withdrawals"); - $this->labelstatut[0]=$langs->trans("StatusWaiting"); - $this->labelstatut[1]=$langs->trans("StatusTrans"); - $this->labelstatut[2]=$langs->trans("StatusCredited"); + $langs->load("withdrawals"); + $this->labelstatut[0]=$langs->trans("StatusWaiting"); + $this->labelstatut[1]=$langs->trans("StatusTrans"); + $this->labelstatut[2]=$langs->trans("StatusCredited"); return 1; } - /** - * Add facture to withdrawal - * @param facture_id id invoice to add - * @param client_id id invoice customer - * @param client_nom name of cliente - * @param amount amount of invoice - * @param code_banque code of bank withdrawal - * @param code_guichet code of bank's office - * @param number bank account number - * @param number_key number key of account number - * @return int >0 if OK, <0 if KO - */ + /** + * Add facture to withdrawal + * @param facture_id id invoice to add + * @param client_id id invoice customer + * @param client_nom name of cliente + * @param amount amount of invoice + * @param code_banque code of bank withdrawal + * @param code_guichet code of bank's office + * @param number bank account number + * @param number_key number key of account number + * @return int >0 if OK, <0 if KO + */ function AddFacture($facture_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key) { $result = 0; @@ -150,17 +152,17 @@ class BonPrelevement extends CommonObject } /** - * Add line to withdrawal - * @param ligne_id id line to add - * @param client_id id invoice customer - * @param client_nom name of cliente - * @param amount amount of invoice - * @param code_banque code of bank withdrawal - * @param code_guichet code of bank's office - * @param number bank account number - * @param number_key number key of account number - * @return int >0 if OK, <0 if KO - */ + * Add line to withdrawal + * @param ligne_id id line to add + * @param client_id id invoice customer + * @param client_nom name of cliente + * @param amount amount of invoice + * @param code_banque code of bank withdrawal + * @param code_guichet code of bank's office + * @param number bank account number + * @param number_key number key of account number + * @return int >0 if OK, <0 if KO + */ function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key) { $result = -1; @@ -231,10 +233,10 @@ class BonPrelevement extends CommonObject } /** - * Read errors - * @param error id of error - * @return array of errors - */ + * Read errors + * @param error id of error + * @return array of errors + */ function ReadError($error) { $errors = array(); @@ -244,14 +246,14 @@ class BonPrelevement extends CommonObject return $errors[abs($error)]; } - /** - * Get object and lines from database - * @param rowid id of object to load - * @return int >0 if OK, <0 if KO - */ + /** + * Get object and lines from database + * @param rowid id of object to load + * @return int >0 if OK, <0 if KO + */ function fetch($rowid) { - global $conf; + global $conf; $sql = "SELECT p.rowid, p.ref, p.amount, p.note"; $sql.= ", p.datec as dc"; @@ -381,15 +383,15 @@ class BonPrelevement extends CommonObject } } - /** - * Set withdrawal to creditet status - * @param user id of user - * @param date date of action - * @return int >0 if OK, <0 if KO - */ + /** + * Set withdrawal to creditet status + * @param user id of user + * @param date date of action + * @return int >0 if OK, <0 if KO + */ function set_infocredit($user, $date) { - global $conf,$langs; + global $conf,$langs; $error == 0; @@ -414,104 +416,104 @@ class BonPrelevement extends CommonObject $subject = $langs->trans("InfoCreditSubject", $this->ref); $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date,'dayhour')); - //Add payment of withdrawal into bank - $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; - $facs = array(); - $amounts = array(); + //Add payment of withdrawal into bank + $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; + $facs = array(); + $amounts = array(); - $facs = $this->_get_list_factures(); + $facs = $this->_get_list_factures(); - for ($i = 0 ; $i < sizeof($facs) ; $i++) - { - $fac = new Facture($this->db); - $fac->fetch($facs[$i]); - $amounts[$fac->id] = $fac->total_ttc; - $result = $fac->set_paid($user); - } - $paiement = new Paiement($this->db); - $paiement->datepaye = $date ; - $paiement->amounts = $amounts; - $paiement->paiementid = 3; // - $paiement->num_paiement = $this->ref ; + for ($i = 0 ; $i < sizeof($facs) ; $i++) + { + $fac = new Facture($this->db); + $fac->fetch($facs[$i]); + $amounts[$fac->id] = $fac->total_ttc; + $result = $fac->set_paid($user); + } + $paiement = new Paiement($this->db); + $paiement->datepaye = $date ; + $paiement->amounts = $amounts; + $paiement->paiementid = 3; // + $paiement->num_paiement = $this->ref ; - $paiement_id = $paiement->create($user); - if ($paiement_id < 0) - { - dol_syslog("BonPrelevement::set_credite AddPayment Error"); - $error++; - } - else - { - $result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount); - if ($result < 0) - { - dol_syslog("BonPrelevement::set_credite AddPaymentToBank Error"); - $error++; - } - } - // Update prelevement line - // TODO: Translate to ligne-prelevement.class.php - $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; - $sql.= " SET statut = 2"; - $sql.= " WHERE fk_prelevement_bons = ".$this->id; + $paiement_id = $paiement->create($user); + if ($paiement_id < 0) + { + dol_syslog("BonPrelevement::set_credite AddPayment Error"); + $error++; + } + else + { + $result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount); + if ($result < 0) + { + dol_syslog("BonPrelevement::set_credite AddPaymentToBank Error"); + $error++; + } + } + // Update prelevement line + // TODO: Translate to ligne-prelevement.class.php + $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; + $sql.= " SET statut = 2"; + $sql.= " WHERE fk_prelevement_bons = ".$this->id; - if (! $this->db->query($sql)) - { - dol_syslog("BonPrelevement::set_credite Update lines Error"); - $error++; - } + if (! $this->db->query($sql)) + { + dol_syslog("BonPrelevement::set_credite Update lines Error"); + $error++; + } - } - else - { - dol_syslog("BonPrelevement::set_infocredit Update Bons Error"); - $error++; - } + } + else + { + dol_syslog("BonPrelevement::set_infocredit Update Bons Error"); + $error++; + } - /* - * End of procedure - * + /* + * End of procedure + * */ - if ($error == 0) - { - $this->db->commit(); - return 0; - } - else - { - $this->db->rollback(); - dol_syslog("bon-prelevment::set_infocredit ROLLBACK "); - return -1; - } - } - else - { - dol_syslog("bon-prelevement::set_infocredit 1025 Open SQL transaction impossible "); - return -1025; - } - } - else - { - dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans "); - return -1027; - } - } - else - { - return -1026; - } - } + if ($error == 0) + { + $this->db->commit(); + return 0; + } + else + { + $this->db->rollback(); + dol_syslog("bon-prelevment::set_infocredit ROLLBACK "); + return -1; + } + } + else + { + dol_syslog("bon-prelevement::set_infocredit 1025 Open SQL transaction impossible "); + return -1025; + } + } + else + { + dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans "); + return -1027; + } + } + else + { + return -1026; + } + } /** - * Set withdrawal to transmited status - * @param user id of user - * @param date date of action - * @param method method of transmision to bank - * @return int >0 if OK, <0 if KO - */ + * Set withdrawal to transmited status + * @param user id of user + * @param date date of action + * @param method method of transmision to bank + * @return int >0 if OK, <0 if KO + */ function set_infotrans($user, $date, $method) { - global $conf,$langs; + global $conf,$langs; $error == 0; dol_syslog("bon-prelevement::set_infotrans Start",LOG_INFO); @@ -570,12 +572,12 @@ class BonPrelevement extends CommonObject } /** - * Get invoice list - * @return array id of invoices - */ + * Get invoice list + * @return array id of invoices + */ function _get_list_factures() { - global $conf; + global $conf; $arr = array(); @@ -623,7 +625,7 @@ class BonPrelevement extends CommonObject */ function SommeAPrelever() { - global $conf; + global $conf; $sql = "SELECT sum(f.total_ttc)"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; @@ -661,7 +663,7 @@ class BonPrelevement extends CommonObject */ function NbFactureAPrelever($banque=0,$agence=0) { - global $conf; + global $conf; $sql = "SELECT count(f.rowid)"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -776,7 +778,7 @@ class BonPrelevement extends CommonObject if (! $error) { // Check RIB - $i = 0; + $i = 0; dol_syslog("Start RIB check"); if (sizeof($factures) > 0) @@ -820,33 +822,33 @@ class BonPrelevement extends CommonObject } } - $ok=0; + $ok=0; // Withdraw invoices in factures_prev array $out=sizeof($factures_prev)." invoices will be withdrawn."; - //print $out."\n"; - dol_syslog($out); + //print $out."\n"; + dol_syslog($out); - if (sizeof($factures_prev) > 0) - { - if ($mode=='real') - { - $ok=1; - } - else - { - print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n"; - } - } + if (sizeof($factures_prev) > 0) + { + if ($mode=='real') + { + $ok=1; + } + else + { + print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n"; + } + } if ($ok) { - /* - * We are in real mode. - * We create withdraw receipt and build withdraw into disk - */ + /* + * We are in real mode. + * We create withdraw receipt and build withdraw into disk + */ $this->db->begin(); /* @@ -862,7 +864,7 @@ class BonPrelevement extends CommonObject $sql.= " WHERE ref LIKE '".$ref."%'"; $sql.= " AND entity = ".$conf->entity; - dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); + dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -888,7 +890,7 @@ class BonPrelevement extends CommonObject $sql.= ", '".$this->db->idate(mktime())."'"; $sql.= ")"; - dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); + dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -913,165 +915,165 @@ class BonPrelevement extends CommonObject * Creation process * */ - if (!$error) - { - if (sizeof($factures_prev) > 0) - { - foreach ($factures_prev as $fac) - { - // Fetch invoice - $fact = new Facture($this->db); - $fact->fetch($fac[0]); - /* - * Add standing order - * - * - * $fac[3] : banque - * $fac[4] : guichet - * $fac[5] : number - * $fac[6] : cle rib - * $fac[7] : amount - * $fac[8] : client nom - * $fac[2] : client id - */ - $ri = $bonprev->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], - $fac[3], $fac[4], $fac[5], $fac[6]); - if ($ri <> 0) - { - $error++; - } + if (!$error) + { + if (sizeof($factures_prev) > 0) + { + foreach ($factures_prev as $fac) + { + // Fetch invoice + $fact = new Facture($this->db); + $fact->fetch($fac[0]); + /* + * Add standing order + * + * + * $fac[3] : banque + * $fac[4] : guichet + * $fac[5] : number + * $fac[6] : cle rib + * $fac[7] : amount + * $fac[8] : client nom + * $fac[2] : client id + */ + $ri = $bonprev->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], + $fac[3], $fac[4], $fac[5], $fac[6]); + if ($ri <> 0) + { + $error++; + } - /* - * Update orders - * - */ - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; - $sql.= " SET traite = 1"; - $sql.= ", date_traite = ".$this->db->idate(mktime()); - $sql.= ", fk_prelevement_bons = ".$prev_id; - $sql.= " WHERE rowid = ".$fac[1]; + /* + * Update orders + * + */ + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; + $sql.= " SET traite = 1"; + $sql.= ", date_traite = ".$this->db->idate(mktime()); + $sql.= ", fk_prelevement_bons = ".$prev_id; + $sql.= " WHERE rowid = ".$fac[1]; - dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { + dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { - } - else - { - $error++; - dol_syslog("Erreur mise a jour des demandes"); - dol_syslog($this->db->error()); - } + } + else + { + $error++; + dol_syslog("Erreur mise a jour des demandes"); + dol_syslog($this->db->error()); + } - } + } - } + } - } + } - if (!$error) - { - /* - * Withdraw receipt - */ + if (!$error) + { + /* + * Withdraw receipt + */ - dol_syslog("Debut prelevement - Nombre de factures ".sizeof($factures_prev)); + dol_syslog("Debut prelevement - Nombre de factures ".sizeof($factures_prev)); - if (sizeof($factures_prev) > 0) - { - $bonprev->date_echeance = $datetimeprev; - $bonprev->reference_remise = $ref; + if (sizeof($factures_prev) > 0) + { + $bonprev->date_echeance = $datetimeprev; + $bonprev->reference_remise = $ref; - $bonprev->numero_national_emetteur = $conf->global->PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR; - $bonprev->raison_sociale = $conf->global->PRELEVEMENT_RAISON_SOCIALE; + $bonprev->numero_national_emetteur = $conf->global->PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR; + $bonprev->raison_sociale = $conf->global->PRELEVEMENT_RAISON_SOCIALE; - $bonprev->emetteur_code_banque = $conf->global->PRELEVEMENT_CODE_BANQUE; - $bonprev->emetteur_code_guichet = $conf->global->PRELEVEMENT_CODE_GUICHET; - $bonprev->emetteur_numero_compte = $conf->global->PRELEVEMENT_NUMERO_COMPTE; - $bonprev->emetteur_number_key = $conf->global->PRELEVEMENT_NUMBER_KEY; + $bonprev->emetteur_code_banque = $conf->global->PRELEVEMENT_CODE_BANQUE; + $bonprev->emetteur_code_guichet = $conf->global->PRELEVEMENT_CODE_GUICHET; + $bonprev->emetteur_numero_compte = $conf->global->PRELEVEMENT_NUMERO_COMPTE; + $bonprev->emetteur_number_key = $conf->global->PRELEVEMENT_NUMBER_KEY; - $bonprev->factures = $factures_prev_id; + $bonprev->factures = $factures_prev_id; - //Build file - $bonprev->generate(); - } - dol_syslog( $filebonprev ) ; - dol_syslog("Fin prelevement"); - } + //Build file + $bonprev->generate(); + } + dol_syslog( $filebonprev ) ; + dol_syslog("Fin prelevement"); + } - /* - * Update total - * - */ + /* + * Update total + * + */ - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; - $sql.= " SET amount = ".price2num($bonprev->total); - $sql.= " WHERE rowid = ".$prev_id; - $sql.= " AND entity = ".$conf->entity; + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; + $sql.= " SET amount = ".price2num($bonprev->total); + $sql.= " WHERE rowid = ".$prev_id; + $sql.= " AND entity = ".$conf->entity; - dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $error++; - dol_syslog("Erreur mise a jour du total - $sql"); - } + dol_syslog("Bon-Prelevement::Create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + dol_syslog("Erreur mise a jour du total - $sql"); + } - /* - * Rollback or Commit - * - */ - if (!$error) - { - $this->db->commit(); - } - else - { - $this->db->rollback(); - dol_syslog("Error",LOG_ERROR); - } + /* + * Rollback or Commit + * + */ + if (!$error) + { + $this->db->commit(); + } + else + { + $this->db->rollback(); + dol_syslog("Error",LOG_ERROR); + } - return sizeof($factures_prev); - } - else - { - return 0; - } - } - - - /** - * Returns clickable name (with picto) - * @param withpicto link with picto - * @param option link target - * @return string URL of target - */ - function getNomUrl($withpicto=0,$option='') - { - global $langs; - - $result=''; - - $lien = ''; - $lienfin=''; - - if ($option == 'xxx') - { - $lien = ''; - $lienfin=''; - } - - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowWithdraw"),'payment').$lienfin.' '); - $result.=$lien.$this->ref.$lienfin; - return $result; - } + return sizeof($factures_prev); + } + else + { + return 0; + } + } /** - * Delete a notification def by id - * @param rowid id of notification - * @return int 0 if OK, <0 if KO - */ + * Returns clickable name (with picto) + * @param withpicto link with picto + * @param option link target + * @return string URL of target + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + if ($option == 'xxx') + { + $lien = ''; + $lienfin=''; + } + + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowWithdraw"),'payment').$lienfin.' '); + $result.=$lien.$this->ref.$lienfin; + return $result; + } + + + /** + * Delete a notification def by id + * @param rowid id of notification + * @return int 0 if OK, <0 if KO + */ function DeleteNotificationById($rowid) { $result = 0; @@ -1090,17 +1092,17 @@ class BonPrelevement extends CommonObject } /** - * Delete a notification - * @param user notification user - * @param action notification action - * @return int >0 if OK, <0 if KO - */ + * Delete a notification + * @param user notification user + * @param action notification action + * @return int >0 if OK, <0 if KO + */ function DeleteNotification($user, $action) { $result = 0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; - $sql .= " WHERE fk_user=".$user." AND fk_action=".$action; + $sql .= " WHERE fk_user=".$user." AND fk_action=".$action; if ($this->db->query($sql)) { @@ -1113,19 +1115,19 @@ class BonPrelevement extends CommonObject } /** - * Add a notification - * @param user notification user - * @param action notification action - * @return int 0 if OK, <0 if KO - */ + * Add a notification + * @param user notification user + * @param action notification action + * @return int 0 if OK, <0 if KO + */ function AddNotification($db, $user, $action) { $result = 0; if ($this->DeleteNotification($user, $action) == 0) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)"; - $sql .= " VALUES (".$db->idate(mktime()).",".$user.", 'NULL', 'NULL', ".$action.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)"; + $sql .= " VALUES (".$db->idate(mktime()).",".$user.", 'NULL', 'NULL', ".$action.")"; dol_syslog("adnotiff: ".$sql); if ($this->db->query($sql)) @@ -1144,18 +1146,18 @@ class BonPrelevement extends CommonObject /** - * Generate a withdrawal file - * Generation Formats: - * France: CFONB - * Spain: AEB19 (if external module EsAEB is enabled) - * Others: Warning message - * File is generated with name this->filename - * @return int 0 if OK, <0 if KO - */ + * Generate a withdrawal file + * Generation Formats: + * France: CFONB + * Spain: AEB19 (if external module EsAEB is enabled) + * Others: Warning message + * File is generated with name this->filename + * @return int 0 if OK, <0 if KO + */ //TODO: Optimize code to read lines in a single function function Generate() { - global $conf,$langs,$mysoc; + global $conf,$langs,$mysoc; $result = 0; @@ -1166,207 +1168,207 @@ class BonPrelevement extends CommonObject //Build file for Spain if ($mysoc->pays_code=='ES') { - if ($conf->esaeb->enabled) - { - //Head - $esaeb19 = new AEB19DocWritter; - $esaeb19->configuraPresentador($this->numero_national_emetteur,$conf->global->ESAEB_SUFIX_PRESENTADOR,$this->raison_sociale,$this->emetteur_code_banque,$this->emetteur_code_guichet); - $idOrdenante = $esaeb19->agregaOrdenante($this->numero_national_emetteur,$conf->global->ESAEB_SUFIX_ORDENANTE,$this->raison_sociale,$this->emetteur_code_banque,$this->emetteur_code_guichet, $this->emetteur_number_key, $this->emetteur_numero_compte); - $this->total = 0; - $sql = "SELECT pl.rowid, pl.client_nom, pl.code_banque, pl.code_guichet, pl.cle_rib, pl.number, pl.amount,"; - $sql.= " f.facnumber, pf.fk_facture"; - $sql.= " FROM"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql.= " ".MAIN_DB_PREFIX."facture as f,"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql.= " AND pf.fk_facture = f.rowid"; + if ($conf->esaeb->enabled) + { + //Head + $esaeb19 = new AEB19DocWritter; + $esaeb19->configuraPresentador($this->numero_national_emetteur,$conf->global->ESAEB_SUFIX_PRESENTADOR,$this->raison_sociale,$this->emetteur_code_banque,$this->emetteur_code_guichet); + $idOrdenante = $esaeb19->agregaOrdenante($this->numero_national_emetteur,$conf->global->ESAEB_SUFIX_ORDENANTE,$this->raison_sociale,$this->emetteur_code_banque,$this->emetteur_code_guichet, $this->emetteur_number_key, $this->emetteur_numero_compte); + $this->total = 0; + $sql = "SELECT pl.rowid, pl.client_nom, pl.code_banque, pl.code_guichet, pl.cle_rib, pl.number, pl.amount,"; + $sql.= " f.facnumber, pf.fk_facture"; + $sql.= " FROM"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; + $sql.= " ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; + $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; + $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; + $sql.= " AND pf.fk_facture = f.rowid"; - //Lines - $i = 0; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); + //Lines + $i = 0; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); - $esaeb19->agregaRecibo($idOrdenante, + $esaeb19->agregaRecibo($idOrdenante, "idcliente".$i+1, - $obj->client_nom, - $obj->code_banque, - $obj->code_guichet, - $obj->cle_rib, - $obj->number, - $obj->amount, + $obj->client_nom, + $obj->code_banque, + $obj->code_guichet, + $obj->cle_rib, + $obj->number, + $obj->amount, "Fra.".$obj->facnumber." ".$obj->amount); - $this->total = $this->total + $obj->amount; + $this->total = $this->total + $obj->amount; - $i++; - } - } + $i++; + } + } - else - { - $result = -2; - } + else + { + $result = -2; + } - fputs ($this->file, $esaeb19->generaRemesa()); - } - else - { - $this->total = 0; - $sql = "SELECT pl.amount"; - $sql.= " FROM"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql.= " ".MAIN_DB_PREFIX."facture as f,"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql.= " AND pf.fk_facture = f.rowid"; + fputs ($this->file, $esaeb19->generaRemesa()); + } + else + { + $this->total = 0; + $sql = "SELECT pl.amount"; + $sql.= " FROM"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; + $sql.= " ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; + $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; + $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; + $sql.= " AND pf.fk_facture = f.rowid"; - //Lines - $i = 0; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); + //Lines + $i = 0; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $this->total = $this->total + $obj->amount; - $i++; - } - } - else - { - $result = -2; - } - $langs->load('withdrawals'); - fputs ($this->file, $langs->trans('WithdrawalFileNotCapable')); - } + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $this->total = $this->total + $obj->amount; + $i++; + } + } + else + { + $result = -2; + } + $langs->load('withdrawals'); + fputs ($this->file, $langs->trans('WithdrawalFileNotCapable')); + } } //Build file for France elseif ($mysoc->pays_code=='FR') { - /* - * En-tete Emetteur - */ - $this->EnregEmetteur(); + /* + * En-tete Emetteur + */ + $this->EnregEmetteur(); - /* - * Lines - */ - $this->total = 0; + /* + * Lines + */ + $this->total = 0; - $sql = "SELECT pl.rowid, pl.client_nom, pl.code_banque, pl.code_guichet, pl.number, pl.amount,"; - $sql.= " f.facnumber, pf.fk_facture"; - $sql.= " FROM"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql.= " ".MAIN_DB_PREFIX."facture as f,"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql.= " AND pf.fk_facture = f.rowid"; + $sql = "SELECT pl.rowid, pl.client_nom, pl.code_banque, pl.code_guichet, pl.number, pl.amount,"; + $sql.= " f.facnumber, pf.fk_facture"; + $sql.= " FROM"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; + $sql.= " ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; + $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; + $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; + $sql.= " AND pf.fk_facture = f.rowid"; - $i = 0; + $i = 0; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); - while ($i < $num) - { - $row = $this->db->fetch_row($resql); + while ($i < $num) + { + $row = $this->db->fetch_row($resql); - $this->EnregDestinataire($row[0], - $row[1], - $row[2], - $row[3], - $row[4], - $row[5], - $row[6], - $row[7]); + $this->EnregDestinataire($row[0], + $row[1], + $row[2], + $row[3], + $row[4], + $row[5], + $row[6], + $row[7]); - $this->total = $this->total + $row[5]; + $this->total = $this->total + $row[5]; - $i++; - } - } - else - { - $result = -2; - } + $i++; + } + } + else + { + $result = -2; + } - /* - * Pied de page total - */ + /* + * Pied de page total + */ - $this->EnregTotal($this->total); + $this->EnregTotal($this->total); } //Build file for Other Countries with unknow format - else + else { - $this->total = 0; - $sql = "SELECT pl.amount"; - $sql.= " FROM"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql.= " ".MAIN_DB_PREFIX."facture as f,"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql.= " AND pf.fk_facture = f.rowid"; + $this->total = 0; + $sql = "SELECT pl.amount"; + $sql.= " FROM"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; + $sql.= " ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; + $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; + $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; + $sql.= " AND pf.fk_facture = f.rowid"; - //Lines - $i = 0; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); + //Lines + $i = 0; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $this->total = $this->total + $obj->amount; - $i++; - } - } - else - { - $result = -2; - } - $langs->load('withdrawals'); - fputs ($this->file, $langs->trans('WithdrawalFileNotCapable')); + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $this->total = $this->total + $obj->amount; + $i++; + } + } + else + { + $result = -2; + } + $langs->load('withdrawals'); + fputs ($this->file, $langs->trans('WithdrawalFileNotCapable')); } fclose($this->file); - if (! empty($conf->global->MAIN_UMASK)) - @chmod($this->file, octdec($conf->global->MAIN_UMASK)); - return $result; + if (! empty($conf->global->MAIN_UMASK)) + @chmod($this->file, octdec($conf->global->MAIN_UMASK)); + return $result; } /** - * Write recipient of request (customer) - * @param rowid id of line - * @param client_nom name of customer - * @param rib_banque code of bank - * @param rib_guichet code of bank office - * @param rib_number bank account - * @param amount amount - * @param facnumber ref of invoice - * @param facid id of invoice - */ + * Write recipient of request (customer) + * @param rowid id of line + * @param client_nom name of customer + * @param rib_banque code of bank + * @param rib_guichet code of bank office + * @param rib_number bank account + * @param amount amount + * @param facnumber ref of invoice + * @param facid id of invoice + */ function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $facnumber, $facid) { fputs ($this->file, "06"); @@ -1426,8 +1428,8 @@ class BonPrelevement extends CommonObject /** - * Write sender of request (me) - */ + * Write sender of request (me) + */ function EnregEmetteur() { fputs ($this->file, "03"); @@ -1490,9 +1492,9 @@ class BonPrelevement extends CommonObject } /** - * Write end - * @param total total amount - */ + * Write end + * @param total total amount + */ function EnregTotal($total) { fputs ($this->file, "08"); @@ -1548,51 +1550,51 @@ class BonPrelevement extends CommonObject fputs ($this->file, "\n"); } -/** - * Return status label of object - * @param mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto - * @return string Label - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->statut,$mode); - } + /** + * Return status label of object + * @param mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } - /** - * Return status label for a status - * @param statut id statut - * @param mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto - * @return string Label - */ - function LibStatut($statut,$mode=0) - { - global $langs; + /** + * Return status label for a status + * @param statut id statut + * @param mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto + * @return string Label + */ + function LibStatut($statut,$mode=0) + { + global $langs; - if ($mode == 0) - { - return $langs->trans($this->labelstatut[$statut]); - } + if ($mode == 0) + { + return $langs->trans($this->labelstatut[$statut]); + } - if ($mode == 1) - { - if ($statut==0) return img_picto($langs->trans($this->labelstatut[$statut]),'statut0').' '.$langs->trans($this->labelstatut[$statut]); - if ($statut==1) return img_picto($langs->trans($this->labelstatut[$statut]),'statut1').' '.$langs->trans($this->labelstatut[$statut]); - if ($statut==2) return img_picto($langs->trans($this->labelstatut[$statut]),'statut4').' '.$langs->trans($this->labelstatut[$statut]); - } - if ($mode == 2) - { - if ($statut==0) return img_picto($langs->trans($this->labelstatut[$statut]),'statut0'); - if ($statut==1) return img_picto($langs->trans($this->labelstatut[$statut]),'statut1'); - if ($statut==2) return img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); - } + if ($mode == 1) + { + if ($statut==0) return img_picto($langs->trans($this->labelstatut[$statut]),'statut0').' '.$langs->trans($this->labelstatut[$statut]); + if ($statut==1) return img_picto($langs->trans($this->labelstatut[$statut]),'statut1').' '.$langs->trans($this->labelstatut[$statut]); + if ($statut==2) return img_picto($langs->trans($this->labelstatut[$statut]),'statut4').' '.$langs->trans($this->labelstatut[$statut]); + } + if ($mode == 2) + { + if ($statut==0) return img_picto($langs->trans($this->labelstatut[$statut]),'statut0'); + if ($statut==1) return img_picto($langs->trans($this->labelstatut[$statut]),'statut1'); + if ($statut==2) return img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); + } - if ($mode == 3) - { - if ($statut==0) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut0'); - if ($statut==1) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut1'); - if ($statut==2) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); - } - } + if ($mode == 3) + { + if ($statut==0) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut0'); + if ($statut==1) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut1'); + if ($statut==2) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); + } + } } diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 52a4966d540..a344f8fb774 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -53,8 +53,9 @@ class PaymentSocialContribution extends CommonObject var $fk_user_modif; /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function PaymentSocialContribution($DB) { @@ -63,10 +64,11 @@ class PaymentSocialContribution extends CommonObject } /** - * Create payment of social contribution into database. - * Use this->amounts to have list of lines for the payment - * @param user User making payment - * @return int <0 if KO, id of payment if OK + * Create payment of social contribution into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @return int <0 if KO, id of payment if OK */ function create($user) { diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 8417972d104..264a18deb54 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -56,8 +56,9 @@ class Tva extends CommonObject /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Tva($DB) { @@ -67,9 +68,10 @@ class Tva extends CommonObject /** - * \brief Create in database - * \param user User that create - * \return int <0 si ko, >0 si ok + * Create in database + * + * @param User $user User that create + * @return int <0 if KO, >0 if OK */ function create($user) { diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 8397528f648..3de4ff37be5 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -45,10 +45,11 @@ abstract class ActionsContactCardCommon /** * Constructor - * @param DB Handler acces base de donnees - * @param targmetmodule Name of directory of module where canvas is stored - * @param canvas Name of canvas - * @param card Name of tab (sub-canvas) + * + * @param DoliDB $DB Handler acces base de donnees + * @param string $targmetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param streing $card Name of tab (sub-canvas) */ function ActionsContactCardCommon($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/contact/canvas/default/actions_contactcard_default.class.php b/htdocs/contact/canvas/default/actions_contactcard_default.class.php index 9b293eccb48..1575e120a6e 100644 --- a/htdocs/contact/canvas/default/actions_contactcard_default.class.php +++ b/htdocs/contact/canvas/default/actions_contactcard_default.class.php @@ -36,10 +36,11 @@ class ActionsContactCardDefault extends ActionsContactCardCommon /** * Constructor - * @param DB Handler acces base de donnees - * @param targmetmodule Name of directory of module where canvas is stored - * @param canvas Name of canvas - * @param card Name of tab (sub-canvas) + * + * @param DoliDB $DB Handler acces base de donnees + * @param string $targmetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsContactCardDefault($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index d7dedea8b5b..c52e6a7e96e 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -80,8 +80,9 @@ class Contact extends CommonObject /** - * Constructor of class Contact - * @param DB Habler d'acces base + * Constructor + * + * @param DoliDB $DB Database handler */ function Contact($DB) { @@ -89,9 +90,10 @@ class Contact extends CommonObject } /** - * Add a contact into database - * @param user Object user that create - * @return int <0 if KO, >0 if OK + * Add a contact into database + * + * @param User $user Object user that create + * @return int <0 if KO, >0 if OK */ function create($user) { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 62fd4a42fd6..efc8faabf60 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -72,8 +72,9 @@ class Contrat extends CommonObject /** - * Constructor of classe - * @param DB Databse handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Contrat($DB) { diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 82d536d36b3..89a29e67c4c 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -109,7 +109,7 @@ llxHeader("","",$langs->trans("CardProduct".$product->type)); if ($contrat->id) { - $soc = new Societe($db, $contrat->societe->id); + $soc = new Societe($db); $soc->fetch($contrat->societe->id); if ( $error_msg ) diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 413a5ea4612..f25b6b08bb1 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -233,7 +233,7 @@ if ($action == 'addline' && $user->rights->contrat->creer) // Ecrase $base_price_type par celui du produit if ($_POST['idprod']) { - $prod = new Product($db, $_POST['idprod']); + $prod = new Product($db); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); diff --git a/htdocs/contrat/note.php b/htdocs/contrat/note.php index 310c0493886..748b309286d 100644 --- a/htdocs/contrat/note.php +++ b/htdocs/contrat/note.php @@ -92,9 +92,9 @@ $html = new Form($db); if ($_GET["id"]) { - if ($mesg) print $mesg; + dol_htmloutput_mesg($mesg); - $soc = new Societe($db, $contrat->societe->id); + $soc = new Societe($db); $soc->fetch($contrat->societe->id); $head = contract_prepare_head($contrat); diff --git a/htdocs/core/class/canvas.class.php b/htdocs/core/class/canvas.class.php index 9d637305dd7..4664d2a1188 100644 --- a/htdocs/core/class/canvas.class.php +++ b/htdocs/core/class/canvas.class.php @@ -48,8 +48,8 @@ class Canvas /** * Constructor * - * @param DB Database handler - * @param action Action ('create', 'view', 'edit') + * @param DoliDB $DB Database handler + * @param string $action Action ('create', 'view', 'edit') */ function Canvas($DB, $action='view') { diff --git a/htdocs/core/class/cookie.class.php b/htdocs/core/class/cookie.class.php index b129fd8a9ad..74b22aff19e 100644 --- a/htdocs/core/class/cookie.class.php +++ b/htdocs/core/class/cookie.class.php @@ -39,8 +39,9 @@ class DolCookie var $cookie; /** - * \brief Constructor - * \param key Personnal key + * Constructor + * + * @param string $key Personnal key */ function DolCookie($key = '') { @@ -53,7 +54,7 @@ class DolCookie /** - * \brief Encrypt en create the cookie + * Encrypt en create the cookie */ function cryptCookie() { diff --git a/htdocs/core/class/events.class.php b/htdocs/core/class/events.class.php index eaa3fb0a6f6..4e1ec677cef 100644 --- a/htdocs/core/class/events.class.php +++ b/htdocs/core/class/events.class.php @@ -89,8 +89,9 @@ class Events // extends CommonObject /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Events($DB) { @@ -100,9 +101,9 @@ class Events // extends CommonObject /** - * \brief Create in database - * \param user User that create - * \return int <0 si ko, >0 si ok + * Create in database + * @param User $user User that create + * @return int <0 if KO, >0 if OK */ function create($user) { diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index cc2746a5526..25eaa6bcf54 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -44,8 +44,9 @@ class ExtraFields /** - * Constructor - * @param DB base de donnees + * Constructor + * + * @param DoliDB $DB Database handler */ function ExtraFields($DB) { @@ -405,7 +406,7 @@ class ExtraFields function showInputField($key,$value,$moreparam='') { global $conf; - + $label=$this->attribute_label[$key]; $type=$this->attribute_type[$key]; $size=$this->attribute_size[$key]; @@ -427,7 +428,7 @@ class ExtraFields $showsize=round($size); if ($showsize > 48) $showsize=48; } - + if ($type == 'varchar') { $out=''; diff --git a/htdocs/core/class/genericobject.class.php b/htdocs/core/class/genericobject.class.php index 0849f31b0e5..de4511f8283 100755 --- a/htdocs/core/class/genericobject.class.php +++ b/htdocs/core/class/genericobject.class.php @@ -33,9 +33,9 @@ class GenericObject extends CommonObject var $db; /** - * Class constructor + * Constructor * - * @param DoliDB $db Data base handler access + * @param DoliDB $DB Database handler */ function GenericObject($db) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e9a2241021a..4378a42455e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -55,8 +55,9 @@ class Form /** - * Constructor - * @param $DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Form($DB) { @@ -65,6 +66,7 @@ class Form /** * Output key field for an editable field + * * @param text Text of label * @param htmlname Name of select field * @param preselected Preselected value for parameter diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 56081253519..207de988a4f 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -35,8 +35,9 @@ class FormActions /** - * Constructor - * @param DB Database access handler + * Constructor + * + * @param DoliDB $DB Database handler */ function FormActions($DB) { @@ -48,6 +49,7 @@ class FormActions /** * Show list of action status + * * @param formname Name of form where select in included * @param selected Preselected value * @param canedit 1=can edit, 0=read only diff --git a/htdocs/core/class/html.formadmin.class.php b/htdocs/core/class/html.formadmin.class.php index 07ffffbef63..03c619fb00f 100644 --- a/htdocs/core/class/html.formadmin.class.php +++ b/htdocs/core/class/html.formadmin.class.php @@ -35,8 +35,9 @@ class FormAdmin /** - * \brief Constructor - * \param DB handler d'acces base de donnee + * Constructor + * + * @param DoliDB $DB Database handler */ function FormAdmin($DB) { @@ -46,7 +47,8 @@ class FormAdmin } /** - * Output list with available languages. + * Output list with available languages + * * @deprecated Use select_language instead * @param selected Langue pre-selectionnee * @param htmlname Nom de la zone select diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index b770f293f4a..340977969b8 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -37,8 +37,9 @@ class FormFile /** - * Constructor - * @param DB handler d'acces base de donnee + * Constructor + * + * @param DoliDB $DB Database handler */ function FormFile($DB) { diff --git a/htdocs/core/class/html.formsms.class.php b/htdocs/core/class/html.formsms.class.php index 2afb7ecce04..7334b3682e6 100755 --- a/htdocs/core/class/html.formsms.class.php +++ b/htdocs/core/class/html.formsms.class.php @@ -61,7 +61,8 @@ class FormSms /** * Constructor - * @param DB handler d'acces base de donnee + * + * @param DoliDB $DB Database handler */ function FormSms($DB) { diff --git a/htdocs/core/class/interfaces.class.php b/htdocs/core/class/interfaces.class.php index 16472aedbc5..86837c476b7 100644 --- a/htdocs/core/class/interfaces.class.php +++ b/htdocs/core/class/interfaces.class.php @@ -31,264 +31,265 @@ class Interfaces { - var $dir; // Directory with all core and external triggers files - var $errors = array(); // Array for errors + var $dir; // Directory with all core and external triggers files + var $errors = array(); // Array for errors - /** - * \brief Constructor. - * \param DB Database handler - */ - function Interfaces($DB) - { - $this->db = $DB ; - } + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ + function Interfaces($DB) + { + $this->db = $DB ; + } - /** - * \brief Fonction appelee lors du declenchement d'un evenement Dolibarr. - * Cette fonction declenche tous les triggers trouves actifs. - * \param action Trigger event code - * \param object Objet concern - * \param user Objet user - * \param lang Objet lang - * \param conf Objet conf - * \return int Nb of triggers ran if no error, -Nb of triggers with errors otherwise. - */ - function run_triggers($action,$object,$user,$langs,$conf) - { - // Check parameters - if (! is_object($object) || ! is_object($conf)) // Error - { - dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_ERROR); - return -1; - } - if (! is_object($user) || ! is_object($langs)) // Warning - { - dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING); - } + /** + * \brief Fonction appelee lors du declenchement d'un evenement Dolibarr. + * Cette fonction declenche tous les triggers trouves actifs. + * \param action Trigger event code + * \param object Objet concern + * \param user Objet user + * \param lang Objet lang + * \param conf Objet conf + * \return int Nb of triggers ran if no error, -Nb of triggers with errors otherwise. + */ + function run_triggers($action,$object,$user,$langs,$conf) + { + // Check parameters + if (! is_object($object) || ! is_object($conf)) // Error + { + dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_ERROR); + return -1; + } + if (! is_object($user) || ! is_object($langs)) // Warning + { + dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING); + } - foreach($conf->triggers_modules as $reldir) - { - $dir=dol_buildpath($reldir,0); - //print "xx".$dir;exit; + foreach($conf->triggers_modules as $reldir) + { + $dir=dol_buildpath($reldir,0); + //print "xx".$dir;exit; - // Check if directory exists - if (!is_dir($dir)) continue; + // Check if directory exists + if (!is_dir($dir)) continue; - $handle=opendir($dir); - $modules = array(); - $nbfile = $nbtotal = $nbok = $nbko = 0; + $handle=opendir($dir); + $modules = array(); + $nbfile = $nbtotal = $nbok = $nbko = 0; if (is_resource($handle)) { - while (($file = readdir($handle))!==false) - { - if (is_readable($dir."/".$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php$/i',$file,$reg)) - { - $nbfile++; + while (($file = readdir($handle))!==false) + { + if (is_readable($dir."/".$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php$/i',$file,$reg)) + { + $nbfile++; - $modName = "Interface".ucfirst($reg[2]); - //print "file=$file"; print "modName=$modName"; exit; - if (in_array($modName,$modules)) - { - $langs->load("errors"); - dol_syslog("Interface::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/"),LOG_ERR); - continue; - } + $modName = "Interface".ucfirst($reg[2]); + //print "file=$file"; print "modName=$modName"; exit; + if (in_array($modName,$modules)) + { + $langs->load("errors"); + dol_syslog("Interface::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/"),LOG_ERR); + continue; + } - // Check if trigger file is disabled by name - if (preg_match('/NORUN$/i',$file)) - { - continue; - } - // Check if trigger file is for a particular module - $qualified=true; - if (strtolower($reg[1]) != 'all') - { - $module=preg_replace('/^mod/i','',$reg[1]); - $constparam='MAIN_MODULE_'.strtoupper($module); - if (empty($conf->global->$constparam)) $qualified=false; - } + // Check if trigger file is disabled by name + if (preg_match('/NORUN$/i',$file)) + { + continue; + } + // Check if trigger file is for a particular module + $qualified=true; + if (strtolower($reg[1]) != 'all') + { + $module=preg_replace('/^mod/i','',$reg[1]); + $constparam='MAIN_MODULE_'.strtoupper($module); + if (empty($conf->global->$constparam)) $qualified=false; + } - if (! $qualified) - { - dol_syslog("Interfaces::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO); - continue; - } + if (! $qualified) + { + dol_syslog("Interfaces::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO); + continue; + } - include_once($dir."/".$file); - $objMod = new $modName($this->db); - $i=0; - if ($objMod) - { - // Bypass if workflow module is enabled and if the trigger asked to be disable in such case - if (! empty($conf->workflow->enabled) && ! empty($objMod->disabled_if_workflow)) - { - dol_syslog("Interfaces::run_triggers action=".$action." Bypass triggers for file '".$file."'",LOG_INFO); - continue; - } + include_once($dir."/".$file); + $objMod = new $modName($this->db); + $i=0; + if ($objMod) + { + // Bypass if workflow module is enabled and if the trigger asked to be disable in such case + if (! empty($conf->workflow->enabled) && ! empty($objMod->disabled_if_workflow)) + { + dol_syslog("Interfaces::run_triggers action=".$action." Bypass triggers for file '".$file."'",LOG_INFO); + continue; + } - dol_syslog("Interfaces::run_triggers action=".$action." Launch triggers for file '".$file."'",LOG_INFO); + dol_syslog("Interfaces::run_triggers action=".$action." Launch triggers for file '".$file."'",LOG_INFO); - $modules[$i] = $modName; - //dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO); - $result=$objMod->run_trigger($action,$object,$user,$langs,$conf); - if ($result > 0) - { - // Action OK - $nbtotal++; - $nbok++; - } - if ($result == 0) - { - // Aucune action faite - $nbtotal++; - } - if ($result < 0) - { - // Action KO - $nbtotal++; - $nbko++; - $this->errors[]=$objMod->error; - } - $i++; - } - else - { - dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERROR); - } - } - } - closedir($handle); + $modules[$i] = $modName; + //dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO); + $result=$objMod->run_trigger($action,$object,$user,$langs,$conf); + if ($result > 0) + { + // Action OK + $nbtotal++; + $nbok++; + } + if ($result == 0) + { + // Aucune action faite + $nbtotal++; + } + if ($result < 0) + { + // Action KO + $nbtotal++; + $nbko++; + $this->errors[]=$objMod->error; + } + $i++; + } + else + { + dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERROR); + } + } + } + closedir($handle); } - } + } - if ($nbko) - { - dol_syslog("Interfaces::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR); - return -$nbko; - } - else - { - //dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG); - return $nbok; - } - } + if ($nbko) + { + dol_syslog("Interfaces::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR); + return -$nbko; + } + else + { + //dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG); + return $nbok; + } + } - /** - * Return list of triggers. Function used by admin page htdoc/admin/triggers - * @param workflow 0=Return all triggers, 1=Return only triggers not disabled if workflow module activated - * @return array Array list of triggers - */ - function getTriggersList($workflow=0) - { - global $conf, $langs; + /** + * Return list of triggers. Function used by admin page htdoc/admin/triggers + * @param workflow 0=Return all triggers, 1=Return only triggers not disabled if workflow module activated + * @return array Array list of triggers + */ + function getTriggersList($workflow=0) + { + global $conf, $langs; - $html = new Form($this->db); + $html = new Form($this->db); - $files = array(); - $modules = array(); - $orders = array(); - $i = 0; + $files = array(); + $modules = array(); + $orders = array(); + $i = 0; - foreach($conf->triggers_modules as $reldir) - { - $dir=dol_buildpath($reldir,0); - //print "xx".$dir;exit; + foreach($conf->triggers_modules as $reldir) + { + $dir=dol_buildpath($reldir,0); + //print "xx".$dir;exit; - // Check if directory exists - if (!is_dir($dir)) continue; + // Check if directory exists + if (!is_dir($dir)) continue; - $handle=opendir($dir); + $handle=opendir($dir); if (is_resource($handle)) { - while (($file = readdir($handle))!==false) - { - if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg)) - { - $modName = 'Interface'.ucfirst($reg[2]); - //print "file=$file"; print "modName=$modName"; exit; - if (in_array($modName,$modules)) - { - $langs->load("errors"); - print '
'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'
'; - $objMod = new $modName($this->db); + while (($file = readdir($handle))!==false) + { + if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg)) + { + $modName = 'Interface'.ucfirst($reg[2]); + //print "file=$file"; print "modName=$modName"; exit; + if (in_array($modName,$modules)) + { + $langs->load("errors"); + print '
'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'
'; + $objMod = new $modName($this->db); - $modules[$i] = $modName; - $files[$i] = $file; - $orders[$i] = $objMod->family; // Tri par famille - $i++; - } - else - { - include_once($dir.'/'.$file); - $objMod = new $modName($this->db); + $modules[$i] = $modName; + $files[$i] = $file; + $orders[$i] = $objMod->family; // Tri par famille + $i++; + } + else + { + include_once($dir.'/'.$file); + $objMod = new $modName($this->db); - $modules[$i] = $modName; - $files[$i] = $file; - $orders[$i] = $objMod->family; // Tri par famille - $i++; - } - } - } - closedir($handle); + $modules[$i] = $modName; + $files[$i] = $file; + $orders[$i] = $objMod->family; // Tri par famille + $i++; + } + } + } + closedir($handle); } - } + } - asort($orders); + asort($orders); - $triggers = array(); - $j = 0; + $triggers = array(); + $j = 0; - // Loop on each trigger - foreach ($orders as $key => $value) - { - $modName = $modules[$key]; - if ($modName) - { - $objMod = new $modName($this->db); - // Bypass if workflow module is enabled and if the trigger is compatible - if ($workflow && ! empty($objMod->disabled_if_workflow)) continue; - } + // Loop on each trigger + foreach ($orders as $key => $value) + { + $modName = $modules[$key]; + if ($modName) + { + $objMod = new $modName($this->db); + // Bypass if workflow module is enabled and if the trigger is compatible + if ($workflow && ! empty($objMod->disabled_if_workflow)) continue; + } - // Define disabledbyname and disabledbymodule - $disabledbyname=0; - $disabledbymodule=1; - $module=''; - if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1; - if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg)) - { - // Check if trigger file is for a particular module - $module=preg_replace('/^mod/i','',$reg[1]); - $constparam='MAIN_MODULE_'.strtoupper($module); - if (strtolower($reg[1]) == 'all') $disabledbymodule=0; - else if (empty($conf->global->$constparam)) $disabledbymodule=2; - } + // Define disabledbyname and disabledbymodule + $disabledbyname=0; + $disabledbymodule=1; + $module=''; + if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1; + if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg)) + { + // Check if trigger file is for a particular module + $module=preg_replace('/^mod/i','',$reg[1]); + $constparam='MAIN_MODULE_'.strtoupper($module); + if (strtolower($reg[1]) == 'all') $disabledbymodule=0; + else if (empty($conf->global->$constparam)) $disabledbymodule=2; + } - $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic'); - $triggers[$j]['file'] = $files[$key]; - $triggers[$j]['version'] = $objMod->getVersion(); - $triggers[$j]['status'] = img_picto($langs->trans("Active"),'tick'); - if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = " "; + $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic'); + $triggers[$j]['file'] = $files[$key]; + $triggers[$j]['version'] = $objMod->getVersion(); + $triggers[$j]['status'] = img_picto($langs->trans("Active"),'tick'); + if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = " "; - $text =''.$langs->trans("Description").':
'; - $text.=$objMod->getDesc().'
'; - $text.='
'.$langs->trans("Status").':
'; - if ($disabledbyname == 1) - { - $text.=$langs->trans("TriggerDisabledByName").'
'; - if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; - } - else - { - if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'
'; - if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'
'; - if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; - } + $text =''.$langs->trans("Description").':
'; + $text.=$objMod->getDesc().'
'; + $text.='
'.$langs->trans("Status").':
'; + if ($disabledbyname == 1) + { + $text.=$langs->trans("TriggerDisabledByName").'
'; + if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; + } + else + { + if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'
'; + if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'
'; + if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; + } - $triggers[$j]['info'] = $html->textwithpicto('',$text); - $j++; - } - return $triggers; - } + $triggers[$j]['info'] = $html->textwithpicto('',$text); + $j++; + } + return $triggers; + } } ?> diff --git a/htdocs/core/class/menu.class.php b/htdocs/core/class/menu.class.php index c659029047c..2705ac28999 100644 --- a/htdocs/core/class/menu.class.php +++ b/htdocs/core/class/menu.class.php @@ -32,7 +32,7 @@ class Menu { var $liste; /** - * \brief Constructor for class menu + * Constructor */ function Menu() { diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 33e66798f0e..a1e604c8a25 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -56,10 +56,11 @@ class Menubase /** - * Constructor - * @param DB Database handler - * @param menu_handler - * @param type + * Constructor + * + * @param DoliDB $DB Database handler + * @param string $menu_handler + * @param string $type */ function Menubase($DB,$menu_handler='',$type='') { @@ -72,8 +73,9 @@ class Menubase /** * Create menu entry into database - * @param user User that create - * @return int <0 if KO, Id of record if OK + * + * @param User $user User that create + * @return int <0 if KO, Id of record if OK */ function create($user=0) { diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 155ca106014..a998f3ecf30 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -55,11 +55,12 @@ 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_c_action_trigger - * \param socid Id of third party - * \return string Message + * 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_c_action_trigger + * @param socid Id of third party + * @return string Message */ function confirmMessage($action,$socid) { diff --git a/htdocs/core/class/rssparser.class.php b/htdocs/core/class/rssparser.class.php index 22bd31910dc..cc144e2332c 100755 --- a/htdocs/core/class/rssparser.class.php +++ b/htdocs/core/class/rssparser.class.php @@ -59,7 +59,9 @@ class RssParser /** - * Constructor + * Constructor + * + * @param DoliDB $DB Database handler */ public function RssParser($db) { diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index cf969c828ac..ca4e526c877 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -47,10 +47,9 @@ class Translate { /** - * Constructor + * Constructor * - * @param dir Force directory that contains /langs subdirectory (value is sometine '..' like into install/* pages - * or support/* pages). + * @param dir Force directory that contains /langs subdirectory (value is sometine '..' like into install/* pages or support/* pages). * @param conf Object with Dolibarr configuration */ function Translate($dir = "",$conf) diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index 4d43b4608d8..9d45c5f7017 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -52,8 +52,9 @@ class EcmDirectory // extends CommonObject /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function EcmDirectory($DB) { @@ -63,9 +64,10 @@ class EcmDirectory // extends CommonObject /** - * Create record into database - * @param user User that create - * @return int <0 if KO, >0 if OK + * Create record into database + * + * @param User $user User that create + * @return int <0 if KO, >0 if OK */ function create($user) { diff --git a/htdocs/fichinter/apercu.php b/htdocs/fichinter/apercu.php index 220f140759e..b58b40c9e3e 100644 --- a/htdocs/fichinter/apercu.php +++ b/htdocs/fichinter/apercu.php @@ -55,7 +55,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $object->socid); + $soc = new Societe($db); $soc->fetch($object->socid); $head = fichinter_prepare_head($object); @@ -65,14 +65,14 @@ if ($id > 0 || ! empty($ref)) * Fiche intervention */ print ''; - + // Ref print '"; print ''; - + $nbrow=4; print '"; - + // Client print ""; print ''; print ''; - + // Statut print ''; print "\n"; print ''; - + // Date print ''; print "\n"; print ''; - + print '
'.$langs->trans("Ref")."'.$object->ref.''; - + /* * Documents */ @@ -83,39 +83,39 @@ if ($id > 0 || ! empty($ref)) $filedetail = $filepath . $objectref . "-detail.pdf"; $relativepath = "${objectref}/${objectref}.pdf"; $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; - + // Chemin vers png apercus $fileimage = $file.".png"; // Si PDF d'1 page $fileimagebis = $file."-0.png"; // Si PDF de plus d'1 page - + $var=true; - + // Si fichier PDF existe if (file_exists($file)) { $encfile = urlencode($file); print_titre($langs->trans("Documents")); print ''; - + print ""; - + print ''; print ''; print ''; print ''; - + // Si fichier detail PDF existe if (file_exists($filedetail)) { print ""; - + print ''; print ''; print ''; print ''; } print "
".$langs->trans("Intervention")." PDF'.$object->ref.'.pdf'.dol_print_size(dol_filesize($file)).''.dol_print_date(dol_filemtime($file),'dayhour').'
Fiche d'intervention detaillee'.$object->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
\n"; - + // Conversion du PDF en image png si fichier png non existant if (! file_exists($fileimage) && ! file_exists($fileimagebis)) { @@ -131,26 +131,26 @@ if ($id > 0 || ! empty($ref)) } } } - + print "
".$langs->trans("Customer")."'; print ''.$soc->nom.''; print '
'.$langs->trans("Status").'".$object->getLibStatut(4)."
'.$langs->trans("Date").'".dol_print_date($object->date,"daytext")."
'; } else diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index f31e67ca1d0..c72d3515fb9 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -59,9 +59,9 @@ class Fichinter extends CommonObject var $lines = array(); /** - * Class constructor + * Constructor * - * @param DoliDB $DB Data base handler access + * @param DoliDB $DB Database handler */ function Fichinter($DB) { diff --git a/htdocs/fichinter/contact.php b/htdocs/fichinter/contact.php index 93f7c29158a..efcb52e1d28 100644 --- a/htdocs/fichinter/contact.php +++ b/htdocs/fichinter/contact.php @@ -128,10 +128,10 @@ dol_htmloutput_mesg($mesg); $id = $_GET["id"]; if ($id > 0) { - $fichinter = New Fichinter($db); + $fichinter = new Fichinter($db); if ($fichinter->fetch($_GET['id']) > 0) { - $soc = new Societe($db, $fichinter->socid); + $soc = new Societe($db); $soc->fetch($fichinter->socid); diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php index 3b011cf072b..9522f726256 100644 --- a/htdocs/fichinter/document.php +++ b/htdocs/fichinter/document.php @@ -111,7 +111,7 @@ if ($object->id) { $object->fetch_thirdparty(); - $soc = new Societe($db, $object->societe->id); + $soc = new Societe($db); $soc->fetch($object->societe->id); if ( $error_msg ) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 4b08e91e18e..833561c4591 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -36,1758 +36,1758 @@ require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); */ class CommandeFournisseur extends Commande { - var $id ; - var $db ; - var $error; - - var $element='order_supplier'; - var $table_element='commande_fournisseur'; - var $table_element_line = 'commande_fournisseurdet'; - var $fk_element = 'fk_commande'; - var $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe - - var $ref; // TODO deprecated - var $product_ref; - var $ref_supplier; - var $brouillon; - var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially - // -> 7=Canceled/Never received -> (reopen) 3=Process runing - // -> 6=Canceled -> (reopen) 2=Approved - // -> 9=Refused -> (reopen) 1=Validated - var $socid; - var $fourn_id; - var $date; - var $date_commande; - var $total_ht; - var $total_tva; - var $total_localtax1; // Total Local tax 1 - var $total_localtax2; // Total Local tax 2 - var $total_ttc; - var $source; - var $note; - var $note_public; - var $model_pdf; - var $fk_project; - var $cond_reglement_id; - var $cond_reglement_code; - var $mode_reglement_id; - var $mode_reglement_code; - - - /** Constructeur - * @param DB Handler d'acces aux bases de donnees - */ - function CommandeFournisseur($DB) - { - $this->db = $DB; - $this->products = array(); - $this->lines = array(); - - // List of language codes for status - $this->statuts[0] = 'StatusOrderDraft'; - $this->statuts[1] = 'StatusOrderValidated'; - $this->statuts[2] = 'StatusOrderApproved'; - $this->statuts[3] = 'StatusOrderOnProcess'; - $this->statuts[4] = 'StatusOrderReceivedPartially'; - $this->statuts[5] = 'StatusOrderReceivedAll'; - $this->statuts[6] = 'StatusOrderCanceled'; - $this->statuts[7] = 'StatusOrderCanceled'; - $this->statuts[9] = 'StatusOrderRefused'; - } - - - /** - * Get object and lines from database - * @param id Id of order to load - * @param ref Ref of object - * @return int >0 if OK, <0 if KO - */ - function fetch($id,$ref='') - { - global $conf; - - // Check parameters - if (empty($id) && empty($ref)) return -1; - - $sql = "SELECT c.rowid, c.ref, c.date_creation, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,"; - $sql.= " c.localtax1, c.localtax2, "; - $sql.= " c.date_commande as date_commande, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_projet as fk_project, c.remise_percent, c.source, c.fk_methode_commande,"; - $sql.= " c.note, c.note_public, c.model_pdf,"; - $sql.= " cm.libelle as methode_commande,"; - $sql.= " cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle,"; - $sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_methode_commande"; - $sql.= " WHERE c.entity = ".$conf->entity; - if ($ref) $sql.= " AND c.ref='".$ref."'"; - else $sql.= " AND c.rowid=".$id; - - dol_syslog("CommandeFournisseur::fetch sql=".$sql,LOG_DEBUG); - $resql = $this->db->query($sql) ; - if ($resql) - { - $obj = $this->db->fetch_object($resql); - if (! $obj) return -1; - - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->socid = $obj->fk_soc; - $this->fourn_id = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->user_author_id = $obj->fk_user_author; - $this->total_ht = $obj->total_ht; - $this->total_tva = $obj->tva; - $this->total_localtax1 = $obj->localtax1; - $this->total_localtax2 = $obj->localtax2; - $this->total_ttc = $obj->total_ttc; - $this->date_commande = $this->db->jdate($obj->date_commande); // date a laquelle la commande a ete transmise - $this->date = $this->db->jdate($obj->date_creation); - $this->remise_percent = $obj->remise_percent; - $this->methode_commande_id = $obj->fk_methode_commande; - $this->methode_commande = $obj->methode_commande; - - $this->source = $obj->source; - $this->facturee = $obj->facture; - $this->fk_project = $obj->fk_project; - $this->cond_reglement_id = $obj->fk_cond_reglement; - $this->cond_reglement_code = $obj->cond_reglement_code; - $this->cond_reglement = $obj->cond_reglement_libelle; - $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; - $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->mode_reglement_code = $obj->mode_reglement_code; - $this->mode_reglement = $obj->mode_reglement_libelle; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - $this->modelpdf = $obj->model_pdf; - - $this->db->free($resql); - - if ($this->statut == 0) $this->brouillon = 1; - - - $sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description,"; - $sql.= " l.qty,"; - $sql.= " l.tva_tx, l.remise_percent, l.subprice,"; - $sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,"; - $sql.= " l.total_ht, l.total_tva, l.total_ttc,"; - $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; - $sql.= " WHERE l.fk_commande = ".$this->id; - $sql.= " ORDER BY l.rowid"; - //print $sql; - - dol_syslog("CommandeFournisseur::fetch get lines sql=".$sql,LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - - while ($i < $num) - { - $objp = $this->db->fetch_object($result); - - $line = new CommandeFournisseurLigne($this->db); - - $line->id = $objp->rowid; - $line->desc = $objp->description; // Description ligne - $line->description = $objp->description; // Description ligne - $line->qty = $objp->qty; - $line->tva_tx = $objp->tva_tx; - $line->localtax1_tx = $objp->localtax1_tx; - $line->localtax2_tx = $objp->localtax2_tx; - $line->subprice = $objp->subprice; - $line->remise_percent = $objp->remise_percent; - $line->total_ht = $objp->total_ht; - $line->total_tva = $objp->total_tva; - $line->total_localtax1 = $objp->total_localtax1; - $line->total_localtax2 = $objp->total_localtax2; - $line->total_ttc = $objp->total_ttc; - $line->product_type = $objp->product_type; - - $line->fk_product = $objp->fk_product; // Id du produit - $line->libelle = $objp->label; // Label produit - $line->product_desc = $objp->product_desc; // Description produit - - $line->ref = $objp->product_ref; // TODO deprecated - $line->product_ref = $objp->product_ref; // Internal reference - $line->ref_fourn = $objp->ref_supplier; // TODO deprecated - $line->ref_supplier = $objp->ref_supplier; // Reference supplier - - $this->lines[$i] = $line; - - $i++; - } - $this->db->free($result); - - return 1; - } - else - { - $this->error=$this->db->error()." sql=".$sql; - dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); - return -1; - } - } - else - { - $this->error=$this->db->error()." sql=".$sql; - dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); - return -1; - } - } - - /** - * Add a line in log table - * @param user User making action - * @param statut Status of order - * @param datelog Date of change - * @param comment Comment - * @return int <0 if KO, >0 if OK - */ - function log($user, $statut, $datelog, $comment='') - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_log (datelog, fk_commande, fk_statut, fk_user, comment)"; - $sql.= " VALUES (".$this->db->idate($datelog).",".$this->id.", ".$statut.", "; - $sql.= $user->id.", "; - $sql.= ($comment?"'".$this->db->escape($comment)."'":'null'); - $sql.= ")"; - - dol_syslog("FournisseurCommande::log sql=".$sql, LOG_DEBUG); - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("FournisseurCommande::log ".$this->error, LOG_ERR); - return -1; - } - } - - /** - * Validate an order - * @param user Utilisateur qui valide - */ - function valid($user) - { - global $langs,$conf; - require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); - - $error=0; - - dol_syslog("CommandeFournisseur::Valid"); - $result = 0; - if ($user->rights->fournisseur->commande->valider) - { - $this->db->begin(); - - // Definition du nom de modele de numerotation de commande - $soc = new Societe($this->db); - $soc->fetch($this->fourn_id); - - // Check if object has a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { - $num = $this->getNextNumRef($soc); - } - else - { - $num = $this->ref; - } - - $sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET ref='".$num."'"; - $sql.= ", fk_statut = 1"; - $sql.= ", date_valid=".$this->db->idate(mktime()); - $sql.= ", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut = 0"; - - $resql=$this->db->query($sql); - if (! $resql) - { - dol_syslog("CommandeFournisseur::valid() Echec update - 10 - sql=".$sql, LOG_ERR); - dol_print_error($this->db); - $error++; - } - - if (! $error) - { - // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { - // On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref) - // afin de ne pas perdre les fichiers attaches - $oldref = dol_sanitizeFileName($this->ref); - $newref = dol_sanitizeFileName($num); - $dirsource = $conf->fournisseur->dir_output.'/commande/'.$oldref; - $dirdest = $conf->fournisseur->dir_output.'/commande/'.$newref; - if (file_exists($dirsource)) - { - dol_syslog("CommandeFournisseur::valid() rename dir ".$dirsource." into ".$dirdest); - - if (@rename($dirsource, $dirdest)) - { - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($dirdest.'/'.$oldref.'.*'); - } - } - } - } - - if (! $error) - { - $result = 1; - $this->log($user, 1, time()); // Statut 1 - $this->ref = $num; - } - - if (! $error) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR); - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - $this->error='Not Authorized'; - dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR); - return -1; - } - } - - /** - * Set draft status - * @param user Object user that modify - * @return int <0 if KO, >0 if OK - */ - function set_draft($user) - { - global $conf,$langs; - - $error=0; - - // Protection - if ($this->statut == 0) - { - dol_syslog("CommandeFournisseur::set_draft already draft status", LOG_WARNING); - return 0; - } - - if (! $user->rights->fournisseur->commande->valider) - { - $this->error='Permission denied'; - return -1; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET fk_statut = 0"; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog("CommandeFournisseur::set_draft sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - // If stock is incremented on validate order, we must redecrement it - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) - { - require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - - for ($i = 0 ; $i < sizeof($this->lines) ; $i++) - { - if ($this->lines[$i]->fk_product > 0) - { - $mouvP = new MouvementStock($this->db); - // We increment stock of product (and sub-products) - $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot - $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); - if ($result < 0) { $error++; } - } - } - - if (!$error) - { - $this->statut=0; - $this->db->commit(); - return $result; - } - else - { - $this->error=$mouvP->error; - $this->db->rollback(); - return $result; - } - } - - $this->statut=0; - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - dol_syslog($this->error, LOG_ERR); - return -1; - } - } - - /** - * Return label of the status of object - * @param mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label - * @return string Label - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->statut,$mode); - } - - /** - * Return label of a status - * @param statut Id statut - * @param mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto - * @return string Label of status - */ - function LibStatut($statut,$mode=0) - { - global $langs; - $langs->load('orders'); - - // List of language codes for status - $statutshort[0] = 'StatusOrderDraftShort'; - $statutshort[1] = 'StatusOrderValidatedShort'; - $statutshort[2] = 'StatusOrderApprovedShort'; - $statutshort[3] = 'StatusOrderOnProcessShort'; - $statutshort[4] = 'StatusOrderReceivedPartiallyShort'; - $statutshort[5] = 'StatusOrderReceivedAllShort'; - $statutshort[6] = 'StatusOrderCanceledShort'; - $statutshort[7] = 'StatusOrderCanceledShort'; - $statutshort[9] = 'StatusOrderRefusedShort'; - - if ($mode == 0) - { - return $langs->trans($this->statuts[$statut]); - } - if ($mode == 1) - { - return $langs->trans($statutshort[$statut]); - } - if ($mode == 2) - { - return $langs->trans($this->statuts[$statut]); - } - if ($mode == 3) - { - if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0'); - if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut1'); - if ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6'); - if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); - if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); - } - if ($mode == 4) - { - if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); - if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]); - if ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); - if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); - if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); - if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); - if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); - if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); - } - if ($mode == 5) - { - if ($statut==0) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0'); - if ($statut==1) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1'); - if ($statut==2) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==3) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==4) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); - if ($statut==5) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6'); - if ($statut==6 || $statut==7) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); - if ($statut==9) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); - } - } - - - /** - * Renvoie nom clicable (avec eventuellement le picto) - * @param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - * @param option Sur quoi pointe le lien - * @return string Chaine avec URL - */ - function getNomUrl($withpicto=0,$option='') - { - global $langs; - - $result=''; - - $lien = ''; - $lienfin=''; - - $picto='order'; - $label=$langs->trans("ShowOrder").': '.$this->ref; - - if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); - if ($withpicto && $withpicto != 2) $result.=' '; - $result.=$lien.$this->ref.$lienfin; - return $result; - } - - - /** - * Renvoie la reference de commande suivante non utilisee en fonction du modele - * de numerotation actif defini dans COMMANDE_SUPPLIER_ADDON - * @param soc objet societe - * @return string reference libre pour la facture - */ - function getNextNumRef($soc) - { - global $db, $langs, $conf; - $langs->load("orders"); - - $dir = DOL_DOCUMENT_ROOT .'/includes/modules/supplier_order/'; - - if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON)) - { - $file = $conf->global->COMMANDE_SUPPLIER_ADDON.'.php'; - - if (is_readable($dir.'/'.$file)) - { - // Definition du nom de modele de numerotation de commande fournisseur - $modName=$conf->global->COMMANDE_SUPPLIER_ADDON; - require_once($dir.'/'.$file); - - // Recuperation de la nouvelle reference - $objMod = new $modName($this->db); - - $numref = ""; - $numref = $objMod->commande_get_num($soc,$this); - - if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db,"CommandeFournisseur::getNextNumRef ".$obj->error); - return -1; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON); - return -2; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_NotDefined"); - return -3; - } - } - - /** - * Accept an order - * @param user Object user - * @return int <0 if KO, >0 if OK - */ - function approve($user) - { - global $langs,$conf; - - $error=0; - - dol_syslog("CommandeFournisseur::Approve"); - - if ($user->rights->fournisseur->commande->approuver) - { - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 2"; - $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 1 ;"; - - if ($this->db->query($sql)) - { - $result = 0; - $this->log($user, 2, time()); // Statut 2 - - // If stock is incremented on validate order, we must increment it - if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) - { - require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - - for ($i = 0 ; $i < sizeof($this->lines) ; $i++) - { - // Product with reference - if ($this->lines[$i]->fk_product > 0) - { - $mouvP = new MouvementStock($this->db); - // We decrement stock of product (and sub-products) - $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot - $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); - if ($result < 0) { $error++; } - } - } - } - - if ($error == 0) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_APPROVE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - if ($error == 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog("CommandeFournisseur::Approve Error ",$this->error, LOG_ERR); - return -1; - } - } - else - { - dol_syslog("CommandeFournisseur::Approve Not Authorized", LOG_ERR); - } - return -1; - } - - /** - * Refuse an order - * @param user User making action - */ - function refuse($user) - { - global $conf, $langs; - - dol_syslog("CommandeFournisseur::Refuse"); - $result = 0; - if ($user->rights->fournisseur->commande->approuver) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 9"; - $sql .= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql)) - { - $result = 0; - $this->log($user, 9, time()); - - if ($error == 0) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_REFUSE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - } - else - { - dol_syslog("CommandeFournisseur::Refuse Error -1"); - $result = -1; - } - } - else - { - dol_syslog("CommandeFournisseur::Refuse Not Authorized"); - } - return $result ; - } - - /** - * Cancel an approved order. - * L'annulation se fait apres l'approbation - * @param user User making action - */ - function Cancel($user) - { - global $langs,$conf; - - //dol_syslog("CommandeFournisseur::Cancel"); - $result = 0; - if ($user->rights->fournisseur->commande->commander) - { - $statut = 6; - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".$statut; - $sql .= " WHERE rowid = ".$this->id; - dol_syslog("CommandeFournisseur::Cancel sql=".$sql); - if ($this->db->query($sql)) - { - $result = 0; - $this->log($user, $statut, time()); - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_CANCEL',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - if ($error == 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog("CommandeFournisseur::Cancel ".$this->error); - return -1; - } - } - else - { - dol_syslog("CommandeFournisseur::Cancel Not Authorized"); - return -1; - } - } - - - /** - * Send a supplier order to supplier - * @param user User making change - * @param date Date - * @param methode Method - * @param comment Comment - * @return int <0 if KO, >0 if OK - */ - function commande($user, $date, $methode, $comment='') - { - dol_syslog("CommandeFournisseur::Commande"); - $result = 0; - if ($user->rights->fournisseur->commande->commander) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 3, fk_methode_commande=".$methode.",date_commande=".$this->db->idate("$date"); - $sql .= " WHERE rowid = ".$this->id; - - dol_syslog("CommandeFournisseur::Commande sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - $result = 0; - $this->log($user, 3, $date, $comment); - } - else - { - dol_syslog("CommandeFournisseur::Commande Error -1", LOG_ERR); - $result = -1; - } - } - else - { - dol_syslog("CommandeFournisseur::Commande User not Authorized", LOG_ERR); - } - return $result ; - } - - /** - * Create order with draft status - * @param user User making creation - * @return int <0 if KO, Id of supplier order if OK - */ - function create($user) - { - global $langs,$conf; - - $this->db->begin(); - - $now=dol_now(); - - /* On positionne en mode brouillon la commande */ - $this->brouillon = 1; - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur ("; - $sql.= "ref"; - $sql.= ", entity"; - $sql.= ", fk_soc"; - $sql.= ", date_creation"; - $sql.= ", fk_user_author"; - $sql.= ", fk_statut"; - $sql.= ", source"; - $sql.= ", model_pdf"; - //$sql.= ", fk_mode_reglement"; - $sql.= ") "; - $sql.= " VALUES ("; - $sql.= "''"; - $sql.= ", ".$conf->entity; - $sql.= ", ".$this->socid; - $sql.= ", ".$this->db->idate($now); - $sql.= ", ".$user->id; - $sql.= ", 0"; - $sql.= ", 0"; - $sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'"; - //$sql.= ", ".$this->mode_reglement_id; - $sql.= ")"; - - dol_syslog("CommandeFournisseur::Create sql=".$sql); - if ( $this->db->query($sql) ) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET ref='(PROV".$this->id.")'"; - $sql.= " WHERE rowid=".$this->id; - dol_syslog("CommandeFournisseur::Create sql=".$sql); - if ($this->db->query($sql)) - { - // On logue creation pour historique - $this->log($user, 0, time()); - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error(); - dol_syslog("CommandeFournisseur::Create: Failed -2 - ".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } - else - { - $this->error=$this->db->error(); - dol_syslog("CommandeFournisseur::Create: Failed -1 - ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - - /** - * Add order line - * @param desc Description - * @param pu_ht Unit price - * @param qty Quantity - * @param txtva Taux tva - * @param txlocaltax1 Localtax1 tax - * @param txlocaltax2 Localtax2 tax - * @param fk_product Id produit - * @param fk_prod_fourn_price Id supplier price - * @param fourn_ref Supplier reference - * @param remise_percent Remise - * @param price_base_type HT or TTC - * @param pu_ttc Unit price TTC - * @param type Type of line (0=product, 1=service) - * @return int <=0 if KO, >0 if OK - */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $type=0) - { - global $langs,$mysoc; - - dol_syslog("FournisseurCommande::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type"); - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); - - // Clean parameters - if (! $qty) $qty=1; - if (! $info_bits) $info_bits=0; - if (empty($txtva)) $txtva=0; - if (empty($txlocaltax1)) $txlocaltax1=0; - if (empty($txlocaltax2)) $txlocaltax2=0; - - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - $pu_ht=price2num($pu_ht); - $pu_ttc=price2num($pu_ttc); - $txtva = price2num($txtva); - $txlocaltax1 = price2num($txlocaltax1); - $txlocaltax2 = price2num($txlocaltax2); - if ($price_base_type=='HT') - { - $pu=$pu_ht; - } - else - { - $pu=$pu_ttc; - } - $desc=trim($desc); - - - // Check parameters - if ($qty < 1 && ! $fk_product) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Product")); - return -1; - } - if ($type < 0) return -1; - - - if ($this->statut == 0) - { - $this->db->begin(); - - if ($fk_product > 0) - { - $prod = new Product($this->db, $fk_product); - if ($prod->fetch($fk_product) > 0) - { - $result=$prod->get_buyprice($fk_prod_fourn_price,$qty,$fk_product,$fourn_ref); - if ($result > 0) - { - $label = $prod->libelle; - $pu = $prod->fourn_pu; - $ref = $prod->ref_fourn; - $product_type = $prod->type; - } - if ($result == 0 || $result == -1) - { - $this->error="No price found for this quantity. Quantity may be too low ?"; - $this->db->rollback(); - dol_syslog("FournisseurCommande::addline result=".$result." - ".$this->error, LOG_DEBUG); - return -1; - } - if ($result < -1) - { - $this->error=$prod->error; - $this->db->rollback(); - dol_syslog("Fournisseur.commande::addline result=".$result." - ".$this->error, LOG_ERR); - return -1; - } - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - else - { - $product_type = $type; - } - - // Calcul du total TTC et de la TVA pour la ligne a partir de - // qty, pu, remise_percent et txtva - // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker - // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. - $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits); - $total_ht = $tabprice[0]; - $total_tva = $tabprice[1]; - $total_ttc = $tabprice[2]; - $total_localtax1 = $tabprice[9]; - $total_localtax2 = $tabprice[10]; - - $subprice = price2num($pu,'MU'); - - // TODO A virer - // Anciens indicateurs: $price, $remise (a ne plus utiliser) - $remise = 0; - if ($remise_percent > 0) - { - $remise = round(($pu * $remise_percent / 100), 2); - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; - $sql.= " (fk_commande,label, description,"; - $sql.= " fk_product, product_type,"; - $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref,"; - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc"; - $sql.= ")"; - $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; - if ($fk_product) { $sql.= $fk_product.","; } - else { $sql.= "null,"; } - $sql.= "'".$product_type."',"; - $sql.= "'".$qty."', ".$txtva.", ".$txlocaltax1.", ".$txlocaltax2.", ".$remise_percent.",'".price2num($subprice,'MU')."','".price2num($remise)."','".$ref."',"; - $sql.= "'".price2num($total_ht)."',"; - $sql.= "'".price2num($total_tva)."',"; - $sql.= "'".price2num($total_localtax1)."',"; - $sql.= "'".price2num($total_localtax2)."',"; - $sql.= "'".price2num($total_ttc)."'"; - $sql.= ")"; - - dol_syslog('FournisseurCommande::addline sql='.$sql); - $resql=$this->db->query($sql); - //print $sql; - if ($resql) - { - $this->update_price(); - - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - dol_syslog('FournisseurCommande::addline '.$this->error, LOG_ERR); - return -1; - } - } - } - - - /** - * Add a product into a stock warehouse. - * @param $user User object making change - * @param $product Id of product to dispatch - * @param $qty Qty to dispatch - * @param $entrepot Id of warehouse to add product - * @param $price Price for PMP value calculation - * @param $comment Comment for stock movement - * @return int <0 if KO, >0 if OK - */ - function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='') - { - global $conf; - $error = 0; - require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php"; - - // Check parameters - if ($entrepot <= 0 || $qty <= 0) - { - $this->error='BadValueForParameter'; - return -1; - } - - $now=dol_now(); - - if (($this->statut == 3 || $this->statut == 4 || $this->statut == 5)) - { - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch "; - $sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec) VALUES "; - $sql.= " ('".$this->id."','".$product."','".$qty."',".($entrepot>0?"'".$entrepot."'":"null").",'".$user->id."','".$this->db->idate($now)."')"; - - dol_syslog("CommandeFournisseur::DispatchProduct sql=".$sql); - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $error++; - } - - // Si module stock gere et que incrementation faite depuis un dispatching en stock - if (!$error && $entrepot > 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) - { - $mouv = new MouvementStock($this->db); - if ($product > 0) - { - $result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment); - if ($result < 0) - { - $this->error=$mouv->error; - dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR); - $error++; - } - } - $i++; - } - - if ($error == 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - else - { - $this->error='BadStatusForObject'; - return -2; - } - } - - /** - * Delete line - * @param idligne - */ - function deleteline($idligne) - { - if ($this->statut == 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idligne; - $resql=$this->db->query($sql); - - dol_syslog("Fournisseur.commande.class::deleteline sql=".$sql); - if ($resql) - { - $result=$this->update_price(); - return 0; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - else - { - return -1; - } - } - - /** - * Delete an order - * @return int <0 if KO, >0 if OK - */ - function delete() - { - global $langs,$conf; - - $err = 0; - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ; - dol_syslog("FournisseurCommande::delete sql=".$sql, LOG_DEBUG); - if (! $this->db->query($sql) ) - { - $err++; - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id; - dol_syslog("FournisseurCommande::delete sql=".$sql, LOG_DEBUG); - if ($resql = $this->db->query($sql) ) - { - if ($this->db->affected_rows($resql) < 1) - { - $err++; - } - } - else - { - $err++; - } - - if ($err == 0) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - dol_syslog("CommandeFournisseur::delete : Success"); - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - - /** - * Return list of order methods - */ - function get_methodes_commande() - { - $sql = "SELECT rowid, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_input_method"; - $sql.= " WHERE active = 1"; - - $resql=$this->db->query($sql); - if ($resql) - { - $i = 0; - $num = $this->db->num_rows($resql); - $this->methodes_commande = array(); - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - - $this->methodes_commande[$row[0]] = $row[1]; - - $i++; - } - return 0; - } - else - { - return -1; - } - } - - /** - * Change les conditions de reglement de la commande - * @param cond_reglement_id Id de la nouvelle condition de reglement - * @return int >0 si ok, <0 si ko - */ - function cond_reglement($cond_reglement_id) - { - dol_syslog('CommandeFournisseur::cond_reglement('.$cond_reglement_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; - $sql .= ' SET fk_cond_reglement = '.$cond_reglement_id; - $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) - { - $this->cond_reglement_id = $cond_reglement_id; - return 1; - } - else - { - dol_syslog('CommandeFournisseur::cond_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('CommandeFournisseur::cond_reglement, etat commande incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - /** - * Change le mode de reglement - * @param mode_reglement_id Id du nouveau mode - * @return int >0 if OK, <0 if KO - */ - function mode_reglement($mode_reglement_id) - { - dol_syslog('CommandeFournisseur::mode_reglement('.$mode_reglement_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; - $sql .= ' SET fk_mode_reglement = '.$mode_reglement_id; - $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) - { - $this->mode_reglement_id = $mode_reglement_id; - return 1; - } - else - { - dol_syslog('CommandeFournisseur::mode_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('CommandeFournisseur::mode_reglement, etat commande incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - /** - * Set a delivery in database for this supplier order - * @param user User that input data - * @param date Date of reception - * @param type Type of receipt - * @param comment Comment - */ - function Livraison($user, $date, $type, $comment) - { - $result = 0; - - dol_syslog("CommandeFournisseur::Livraison"); - - if ($user->rights->fournisseur->commande->receptionner) - { - if ($type == 'par') $statut = 4; - if ($type == 'tot') $statut = 5; - if ($type == 'nev') $statut = 7; - if ($type == 'can') $statut = 7; - - if ($statut == 4 or $statut == 5 or $statut == 7) - { - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET fk_statut = ".$statut; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut IN (3,4)"; // Process running or Partially received - - dol_syslog("CommandeFournisseur::Livraison sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $result = 0; - $result=$this->log($user, $statut, $date, $comment); - - $this->db->commit(); - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - dol_syslog("CommandeFournisseur::Livraison Error ".$this->error, LOG_ERR); - $result = -1; - } - } - else - { - dol_syslog("CommandeFournisseur::Livraison Error -2", LOG_ERR); - $result = -2; - } - } - else - { - dol_syslog("CommandeFournisseur::Livraison Not Authorized"); - $result = -3; - } - return $result ; - } - - /** - * Cree la commande depuis une propale existante - * @param user Utilisateur qui cree - * @param idc Id de la propale qui sert de modele - * @param comclientid Id thirdparty - */ - function updateFromCommandeClient($user, $idc, $comclientid) - { - $comclient = new Commande($this->db); - $comclient->fetch($comclientid); - - $this->id = $idc; - - $this->lines = array(); - - for ($i = 0 ; $i < sizeof($comclient->lines) ; $i++) - { - $prod = new Product($this->db, $comclient->lines[$i]->fk_product); - if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) - { - $libelle = $prod->libelle; - $ref = $prod->ref; - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; - $sql .= " (fk_commande,label,description,fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)"; - $sql .= " VALUES (".$idc.", '" . $this->db->escape($libelle) . "','" . $this->db->escape($comclient->lines[$i]->desc) . "'"; - $sql .= ",".$comclient->lines[$i]->fk_product.",'".price2num($comclient->lines[$i]->price)."'"; - $sql .= ", '".$comclient->lines[$i]->qty."', ".$comclient->lines[$i]->tva_tx.", ".$comclient->lines[$i]->localtax1_tx.", ".$comclient->lines[$i]->localtax2_tx.", ".$comclient->lines[$i]->remise_percent; - $sql .= ", '".price2num($comclient->lines[$i]->subprice)."','0','".$ref."') ;"; - if ( $this->db->query( $sql) ) - { - $this->update_price(); - } - } - - return 1; - } - - - /** - * Update notes - * @param user - * @param note - * @param note_public - * @return int <0 if KO, >=0 if OK - * TODO Use instead update_note_public and update_note - */ - function UpdateNote($user, $note, $note_public) - { - // Clean parameters - $note=trim($note); - $note_public=trim($note_public); - - $result = 0; - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET note ='".$this->db->escape($note)."',"; - $sql.= " note_public ='".$this->db->escape($note_public)."'"; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog("CommandeFournisseur::UpdateNote sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $result = 0; - } - else - { - $this->error=$this->db->error(); - dol_syslog("CommandeFournisseur::UpdateNote ".$this->error, LOG_ERR); - $result = -1; - } - - return $result ; - } - - /** - * Get list of user that can approve an order - */ - function ReadApprobators() - { - global $conf; - - $this->approbs = array(); - - $sql = "SELECT u.name, u.firstname, u.email"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql.= " , ".MAIN_DB_PREFIX."user_rights as ur"; - $sql.= " WHERE u.rowid = ur.fk_user"; - $sql.= " AND u.entity = ".$conf->entity; - $sql.= " AND ur.fk_id = 184"; - - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $this->approbs[$i] = $row; - $i++; - } - - $this->db->free($resql); - } - else - { - dol_syslog("ReadApprobators Erreur", LOG_ERR); - } - } - - - /** - * Tag order with a particular status - * @param user Object user that change status - * @param status New status - * @return int <0 if KO, >0 if OK - */ - function setStatus($user,$status) - { - global $conf,$langs; - $error=0; - - $this->db->begin(); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; - $sql.= ' SET fk_statut='.$status; - $sql.= ' WHERE rowid = '.$this->id; - - dol_syslog("CommandeFournisseur::setStatus sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - - } - else - { - $error++; - $this->error=$this->db->lasterror(); - dol_syslog("CommandeFournisseur::setStatus ".$this->error); - } - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - - /** - * Update line - * @param rowid Id de la ligne de facture - * @param desc Description de la ligne - * @param pu Prix unitaire - * @param qty Quantity - * @param remise_percent Pourcentage de remise de la ligne - * @param tva_tx Taux TVA - * @param localtax1_tx Localtax1 tax - * @param localtax2_tx Localtax2 tax - * @param price_base_type Type of price base - * @param info_bits Miscellanous informations - * @param type Type of line (0=product, 1=service) - * @return int < 0 if error, > 0 if ok - */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0) - { - dol_syslog("CommandeFournisseur::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type"); - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); - - if ($this->brouillon) - { - $this->db->begin(); - - // Clean parameters - if (empty($qty)) $qty=0; - if (empty($info_bits)) $info_bits=0; - if (empty($txtva)) $txtva=0; - if (empty($txlocaltax1)) $txlocaltax1=0; - if (empty($txlocaltax2)) $txlocaltax2=0; - if (empty($remise)) $remise=0; - if (empty($remise_percent)) $remise_percent=0; - - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - if (! $qty) $qty=1; - $pu = price2num($pu); - $txtva=price2num($txtva); - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - - // Check parameters - if ($type < 0) return -1; - - // Calcul du total TTC et de la TVA pour la ligne a partir de - // qty, pu, remise_percent et txtva - // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker - // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. - $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits); - $total_ht = $tabprice[0]; - $total_tva = $tabprice[1]; - $total_ttc = $tabprice[2]; - $total_localtax1 = $tabprice[9]; - $total_localtax2 = $tabprice[10]; - - // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) - $subprice = $pu; - $remise = 0; - if ($remise_percent > 0) - { - $remise = round(($pu * $remise_percent / 100),2); - } - $subprice = price2num($subprice); - - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; - $sql.= " description='".$this->db->escape($desc)."'"; - $sql.= ",subprice='".price2num($subprice)."'"; - $sql.= ",remise='".price2num($remise)."'"; - $sql.= ",remise_percent='".price2num($remise_percent)."'"; - $sql.= ",tva_tx='".price2num($txtva)."'"; - $sql.= ",localtax1_tx='".price2num($txlocaltax1)."'"; - $sql.= ",localtax2_tx='".price2num($txlocaltax2)."'"; - $sql.= ",qty='".price2num($qty)."'"; - if ($date_end) { $sql.= ",date_start='$date_end'"; } - else { $sql.=',date_start=null'; } - if ($date_end) { $sql.= ",date_end='$date_end'"; } - else { $sql.=',date_end=null'; } - $sql.= ",info_bits='".$info_bits."'"; - $sql.= ",total_ht='".price2num($total_ht)."'"; - $sql.= ",total_tva='".price2num($total_tva)."'"; - $sql.= ",total_localtax1='".price2num($total_localtax1)."'"; - $sql.= ",total_localtax2='".price2num($total_localtax2)."'"; - $sql.= ",total_ttc='".price2num($total_ttc)."'"; - $sql.= ",product_type='".$type."'"; - $sql.= " WHERE rowid = ".$rowid; - - dol_syslog("CommandeFournisseur::updateline sql=".$sql); - $result = $this->db->query( $sql); - if ($result > 0) - { - // Mise a jour info denormalisees au niveau facture - $this->update_price(); - - $this->db->commit(); - return $result; - } - else - { - $this->error=$this->db->error(); - dol_syslog("CommandeFournisseur::updateline ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - else - { - $this->error="Order status makes operation forbidden"; - dol_syslog("CommandeFournisseur::updateline ".$this->error, LOG_ERR); - return -2; - } - } - - - /** - * Initialise an example of instance with random values - * Used to build previews or test instances - */ - function initAsSpecimen() - { - global $user,$langs,$conf; - - dol_syslog("CommandeFournisseur::initAsSpecimen"); - - $now=dol_now(); - - // Charge tableau des produits prodids - $prodids = array(); - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity = ".$conf->entity; - - $resql = $this->db->query($sql); - if ($resql) - { - $num_prods = $this->db->num_rows($resql); - $i = 0; - while ($i < $num_prods) - { - $i++; - $row = $this->db->fetch_row($resql); - $prodids[$i] = $row[0]; - } - } - - // Initialise parametres - $this->id=0; - $this->ref = 'SPECIMEN'; - $this->specimen=1; - $this->socid = 1; - $this->date = $now; - $this->date_commande = $now; - $this->date_lim_reglement=$this->date+3600*24*30; - $this->cond_reglement_code = 'RECEP'; - $this->mode_reglement_code = 'CHQ'; - $this->note_public='This is a comment (public)'; - $this->note='This is a comment (private)'; - // Lines - $nbp = 5; - $xnbp = 0; - while ($xnbp < $nbp) - { - $line=new CommandeFournisseurLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->qty=1; - $line->subprice=100; - $line->price=100; - $line->tva_tx=19.6; - $line->localtax1_tx=0; - $line->localtax2_tx=0; - if ($xnbp == 2) - { - $line->total_ht=50; - $line->total_ttc=59.8; - $line->total_tva=9.8; - $line->remise_percent=50; - } - else - { - $line->total_ht=100; - $line->total_ttc=119.6; - $line->total_tva=19.6; - $line->remise_percent=00; - } - $line->ref_fourn='SUPPLIER_REF_'.$xnbp; - $prodid = rand(1, $num_prods); - $line->fk_product=$prodids[$prodid]; - - $this->lines[$xnbp]=$line; - - $this->total_ht += $line->total_ht; - $this->total_tva += $line->total_tva; - $this->total_ttc += $line->total_ttc; - - $xnbp++; - } - } - - /** - * Load indicators for dashboard (this->nbtodo and this->nbtodolate) - * - * @param user Objet user - * @return int <0 if KO, >0 if OK - */ - function load_board($user) - { - global $conf, $user; - - $now=gmmktime(); - - $this->nbtodo=$this->nbtodolate=0; - $clause = " WHERE"; - - $sql = "SELECT c.rowid, c.date_creation as datec, c.fk_statut"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - if (!$user->rights->societe->client->voir && !$user->societe_id) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc"; - $sql.= " WHERE sc.fk_user = " .$user->id; - $clause = " AND"; - } - $sql.= $clause." c.entity = ".$conf->entity; - $sql.= " AND (c.fk_statut BETWEEN 1 AND 2)"; - if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; - - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj=$this->db->fetch_object($resql)) - { - $this->nbtodo++; - if ($obj->fk_statut != 3 && $this->db->jdate($obj->datec) < ($now - $conf->commande->fournisseur->warning_delay)) $this->nbtodolate++; - } - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } + var $id ; + var $db ; + var $error; + + var $element='order_supplier'; + var $table_element='commande_fournisseur'; + var $table_element_line = 'commande_fournisseurdet'; + var $fk_element = 'fk_commande'; + var $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + + var $ref; // TODO deprecated + var $product_ref; + var $ref_supplier; + var $brouillon; + var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially + // -> 7=Canceled/Never received -> (reopen) 3=Process runing + // -> 6=Canceled -> (reopen) 2=Approved + // -> 9=Refused -> (reopen) 1=Validated + var $socid; + var $fourn_id; + var $date; + var $date_commande; + var $total_ht; + var $total_tva; + var $total_localtax1; // Total Local tax 1 + var $total_localtax2; // Total Local tax 2 + var $total_ttc; + var $source; + var $note; + var $note_public; + var $model_pdf; + var $fk_project; + var $cond_reglement_id; + var $cond_reglement_code; + var $mode_reglement_id; + var $mode_reglement_code; + + + /** Constructeur + * @param DB Handler d'acces aux bases de donnees + */ + function CommandeFournisseur($DB) + { + $this->db = $DB; + $this->products = array(); + $this->lines = array(); + + // List of language codes for status + $this->statuts[0] = 'StatusOrderDraft'; + $this->statuts[1] = 'StatusOrderValidated'; + $this->statuts[2] = 'StatusOrderApproved'; + $this->statuts[3] = 'StatusOrderOnProcess'; + $this->statuts[4] = 'StatusOrderReceivedPartially'; + $this->statuts[5] = 'StatusOrderReceivedAll'; + $this->statuts[6] = 'StatusOrderCanceled'; + $this->statuts[7] = 'StatusOrderCanceled'; + $this->statuts[9] = 'StatusOrderRefused'; + } + + + /** + * Get object and lines from database + * @param id Id of order to load + * @param ref Ref of object + * @return int >0 if OK, <0 if KO + */ + function fetch($id,$ref='') + { + global $conf; + + // Check parameters + if (empty($id) && empty($ref)) return -1; + + $sql = "SELECT c.rowid, c.ref, c.date_creation, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,"; + $sql.= " c.localtax1, c.localtax2, "; + $sql.= " c.date_commande as date_commande, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_projet as fk_project, c.remise_percent, c.source, c.fk_methode_commande,"; + $sql.= " c.note, c.note_public, c.model_pdf,"; + $sql.= " cm.libelle as methode_commande,"; + $sql.= " cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle,"; + $sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON (c.fk_mode_reglement = p.id)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_methode_commande"; + $sql.= " WHERE c.entity = ".$conf->entity; + if ($ref) $sql.= " AND c.ref='".$ref."'"; + else $sql.= " AND c.rowid=".$id; + + dol_syslog("CommandeFournisseur::fetch sql=".$sql,LOG_DEBUG); + $resql = $this->db->query($sql) ; + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if (! $obj) return -1; + + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->socid = $obj->fk_soc; + $this->fourn_id = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->user_author_id = $obj->fk_user_author; + $this->total_ht = $obj->total_ht; + $this->total_tva = $obj->tva; + $this->total_localtax1 = $obj->localtax1; + $this->total_localtax2 = $obj->localtax2; + $this->total_ttc = $obj->total_ttc; + $this->date_commande = $this->db->jdate($obj->date_commande); // date a laquelle la commande a ete transmise + $this->date = $this->db->jdate($obj->date_creation); + $this->remise_percent = $obj->remise_percent; + $this->methode_commande_id = $obj->fk_methode_commande; + $this->methode_commande = $obj->methode_commande; + + $this->source = $obj->source; + $this->facturee = $obj->facture; + $this->fk_project = $obj->fk_project; + $this->cond_reglement_id = $obj->fk_cond_reglement; + $this->cond_reglement_code = $obj->cond_reglement_code; + $this->cond_reglement = $obj->cond_reglement_libelle; + $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + $this->modelpdf = $obj->model_pdf; + + $this->db->free($resql); + + if ($this->statut == 0) $this->brouillon = 1; + + + $sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description,"; + $sql.= " l.qty,"; + $sql.= " l.tva_tx, l.remise_percent, l.subprice,"; + $sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,"; + $sql.= " l.total_ht, l.total_tva, l.total_ttc,"; + $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; + $sql.= " WHERE l.fk_commande = ".$this->id; + $sql.= " ORDER BY l.rowid"; + //print $sql; + + dol_syslog("CommandeFournisseur::fetch get lines sql=".$sql,LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $objp = $this->db->fetch_object($result); + + $line = new CommandeFournisseurLigne($this->db); + + $line->id = $objp->rowid; + $line->desc = $objp->description; // Description ligne + $line->description = $objp->description; // Description ligne + $line->qty = $objp->qty; + $line->tva_tx = $objp->tva_tx; + $line->localtax1_tx = $objp->localtax1_tx; + $line->localtax2_tx = $objp->localtax2_tx; + $line->subprice = $objp->subprice; + $line->remise_percent = $objp->remise_percent; + $line->total_ht = $objp->total_ht; + $line->total_tva = $objp->total_tva; + $line->total_localtax1 = $objp->total_localtax1; + $line->total_localtax2 = $objp->total_localtax2; + $line->total_ttc = $objp->total_ttc; + $line->product_type = $objp->product_type; + + $line->fk_product = $objp->fk_product; // Id du produit + $line->libelle = $objp->label; // Label produit + $line->product_desc = $objp->product_desc; // Description produit + + $line->ref = $objp->product_ref; // TODO deprecated + $line->product_ref = $objp->product_ref; // Internal reference + $line->ref_fourn = $objp->ref_supplier; // TODO deprecated + $line->ref_supplier = $objp->ref_supplier; // Reference supplier + + $this->lines[$i] = $line; + + $i++; + } + $this->db->free($result); + + return 1; + } + else + { + $this->error=$this->db->error()." sql=".$sql; + dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); + return -1; + } + } + else + { + $this->error=$this->db->error()." sql=".$sql; + dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Add a line in log table + * @param user User making action + * @param statut Status of order + * @param datelog Date of change + * @param comment Comment + * @return int <0 if KO, >0 if OK + */ + function log($user, $statut, $datelog, $comment='') + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_log (datelog, fk_commande, fk_statut, fk_user, comment)"; + $sql.= " VALUES (".$this->db->idate($datelog).",".$this->id.", ".$statut.", "; + $sql.= $user->id.", "; + $sql.= ($comment?"'".$this->db->escape($comment)."'":'null'); + $sql.= ")"; + + dol_syslog("FournisseurCommande::log sql=".$sql, LOG_DEBUG); + if ( $this->db->query($sql) ) + { + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("FournisseurCommande::log ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Validate an order + * @param user Utilisateur qui valide + */ + function valid($user) + { + global $langs,$conf; + require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); + + $error=0; + + dol_syslog("CommandeFournisseur::Valid"); + $result = 0; + if ($user->rights->fournisseur->commande->valider) + { + $this->db->begin(); + + // Definition du nom de modele de numerotation de commande + $soc = new Societe($this->db); + $soc->fetch($this->fourn_id); + + // Check if object has a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + $num = $this->getNextNumRef($soc); + } + else + { + $num = $this->ref; + } + + $sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " SET ref='".$num."'"; + $sql.= ", fk_statut = 1"; + $sql.= ", date_valid=".$this->db->idate(mktime()); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut = 0"; + + $resql=$this->db->query($sql); + if (! $resql) + { + dol_syslog("CommandeFournisseur::valid() Echec update - 10 - sql=".$sql, LOG_ERR); + dol_print_error($this->db); + $error++; + } + + if (! $error) + { + // Rename directory if dir was a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + // On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref) + // afin de ne pas perdre les fichiers attaches + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); + $dirsource = $conf->fournisseur->dir_output.'/commande/'.$oldref; + $dirdest = $conf->fournisseur->dir_output.'/commande/'.$newref; + if (file_exists($dirsource)) + { + dol_syslog("CommandeFournisseur::valid() rename dir ".$dirsource." into ".$dirdest); + + if (@rename($dirsource, $dirdest)) + { + dol_syslog("Rename ok"); + // Suppression ancien fichier PDF dans nouveau rep + dol_delete_file($dirdest.'/'.$oldref.'.*'); + } + } + } + } + + if (! $error) + { + $result = 1; + $this->log($user, 1, time()); // Statut 1 + $this->ref = $num; + } + + if (! $error) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_VALIDATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR); + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + $this->error='Not Authorized'; + dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Set draft status + * @param user Object user that modify + * @return int <0 if KO, >0 if OK + */ + function set_draft($user) + { + global $conf,$langs; + + $error=0; + + // Protection + if ($this->statut == 0) + { + dol_syslog("CommandeFournisseur::set_draft already draft status", LOG_WARNING); + return 0; + } + + if (! $user->rights->fournisseur->commande->valider) + { + $this->error='Permission denied'; + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " SET fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("CommandeFournisseur::set_draft sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + // If stock is incremented on validate order, we must redecrement it + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) + { + require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + + for ($i = 0 ; $i < sizeof($this->lines) ; $i++) + { + if ($this->lines[$i]->fk_product > 0) + { + $mouvP = new MouvementStock($this->db); + // We increment stock of product (and sub-products) + $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot + $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); + if ($result < 0) { $error++; } + } + } + + if (!$error) + { + $this->statut=0; + $this->db->commit(); + return $result; + } + else + { + $this->error=$mouvP->error; + $this->db->rollback(); + return $result; + } + } + + $this->statut=0; + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + dol_syslog($this->error, LOG_ERR); + return -1; + } + } + + /** + * Return label of the status of object + * @param mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } + + /** + * Return label of a status + * @param statut Id statut + * @param mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto + * @return string Label of status + */ + function LibStatut($statut,$mode=0) + { + global $langs; + $langs->load('orders'); + + // List of language codes for status + $statutshort[0] = 'StatusOrderDraftShort'; + $statutshort[1] = 'StatusOrderValidatedShort'; + $statutshort[2] = 'StatusOrderApprovedShort'; + $statutshort[3] = 'StatusOrderOnProcessShort'; + $statutshort[4] = 'StatusOrderReceivedPartiallyShort'; + $statutshort[5] = 'StatusOrderReceivedAllShort'; + $statutshort[6] = 'StatusOrderCanceledShort'; + $statutshort[7] = 'StatusOrderCanceledShort'; + $statutshort[9] = 'StatusOrderRefusedShort'; + + if ($mode == 0) + { + return $langs->trans($this->statuts[$statut]); + } + if ($mode == 1) + { + return $langs->trans($statutshort[$statut]); + } + if ($mode == 2) + { + return $langs->trans($this->statuts[$statut]); + } + if ($mode == 3) + { + if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0'); + if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut1'); + if ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6'); + if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); + } + if ($mode == 4) + { + if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]); + if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]); + if ($statut==2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); + if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); + if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); + if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); + if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); + if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); + } + if ($mode == 5) + { + if ($statut==0) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0'); + if ($statut==1) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1'); + if ($statut==2) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==3) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==4) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); + if ($statut==5) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6'); + if ($statut==6 || $statut==7) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==9) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); + } + } + + + /** + * Renvoie nom clicable (avec eventuellement le picto) + * @param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * @param option Sur quoi pointe le lien + * @return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + $picto='order'; + $label=$langs->trans("ShowOrder").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + $result.=$lien.$this->ref.$lienfin; + return $result; + } + + + /** + * Renvoie la reference de commande suivante non utilisee en fonction du modele + * de numerotation actif defini dans COMMANDE_SUPPLIER_ADDON + * @param soc objet societe + * @return string reference libre pour la facture + */ + function getNextNumRef($soc) + { + global $db, $langs, $conf; + $langs->load("orders"); + + $dir = DOL_DOCUMENT_ROOT .'/includes/modules/supplier_order/'; + + if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON)) + { + $file = $conf->global->COMMANDE_SUPPLIER_ADDON.'.php'; + + if (is_readable($dir.'/'.$file)) + { + // Definition du nom de modele de numerotation de commande fournisseur + $modName=$conf->global->COMMANDE_SUPPLIER_ADDON; + require_once($dir.'/'.$file); + + // Recuperation de la nouvelle reference + $objMod = new $modName($this->db); + + $numref = ""; + $numref = $objMod->commande_get_num($soc,$this); + + if ( $numref != "") + { + return $numref; + } + else + { + dol_print_error($db,"CommandeFournisseur::getNextNumRef ".$obj->error); + return -1; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_FailedToLoad_COMMANDE_SUPPLIER_ADDON_File",$conf->global->COMMANDE_SUPPLIER_ADDON); + return -2; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_NotDefined"); + return -3; + } + } + + /** + * Accept an order + * @param user Object user + * @return int <0 if KO, >0 if OK + */ + function approve($user) + { + global $langs,$conf; + + $error=0; + + dol_syslog("CommandeFournisseur::Approve"); + + if ($user->rights->fournisseur->commande->approuver) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 2"; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 1 ;"; + + if ($this->db->query($sql)) + { + $result = 0; + $this->log($user, 2, time()); // Statut 2 + + // If stock is incremented on validate order, we must increment it + if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) + { + require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + + for ($i = 0 ; $i < sizeof($this->lines) ; $i++) + { + // Product with reference + if ($this->lines[$i]->fk_product > 0) + { + $mouvP = new MouvementStock($this->db); + // We decrement stock of product (and sub-products) + $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot + $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); + if ($result < 0) { $error++; } + } + } + } + + if ($error == 0) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_APPROVE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if ($error == 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("CommandeFournisseur::Approve Error ",$this->error, LOG_ERR); + return -1; + } + } + else + { + dol_syslog("CommandeFournisseur::Approve Not Authorized", LOG_ERR); + } + return -1; + } + + /** + * Refuse an order + * @param user User making action + */ + function refuse($user) + { + global $conf, $langs; + + dol_syslog("CommandeFournisseur::Refuse"); + $result = 0; + if ($user->rights->fournisseur->commande->approuver) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 9"; + $sql .= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + $result = 0; + $this->log($user, 9, time()); + + if ($error == 0) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_REFUSE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + } + else + { + dol_syslog("CommandeFournisseur::Refuse Error -1"); + $result = -1; + } + } + else + { + dol_syslog("CommandeFournisseur::Refuse Not Authorized"); + } + return $result ; + } + + /** + * Cancel an approved order. + * L'annulation se fait apres l'approbation + * @param user User making action + */ + function Cancel($user) + { + global $langs,$conf; + + //dol_syslog("CommandeFournisseur::Cancel"); + $result = 0; + if ($user->rights->fournisseur->commande->commander) + { + $statut = 6; + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".$statut; + $sql .= " WHERE rowid = ".$this->id; + dol_syslog("CommandeFournisseur::Cancel sql=".$sql); + if ($this->db->query($sql)) + { + $result = 0; + $this->log($user, $statut, time()); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_CANCEL',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + if ($error == 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("CommandeFournisseur::Cancel ".$this->error); + return -1; + } + } + else + { + dol_syslog("CommandeFournisseur::Cancel Not Authorized"); + return -1; + } + } + + + /** + * Send a supplier order to supplier + * @param user User making change + * @param date Date + * @param methode Method + * @param comment Comment + * @return int <0 if KO, >0 if OK + */ + function commande($user, $date, $methode, $comment='') + { + dol_syslog("CommandeFournisseur::Commande"); + $result = 0; + if ($user->rights->fournisseur->commande->commander) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 3, fk_methode_commande=".$methode.",date_commande=".$this->db->idate("$date"); + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog("CommandeFournisseur::Commande sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + $result = 0; + $this->log($user, 3, $date, $comment); + } + else + { + dol_syslog("CommandeFournisseur::Commande Error -1", LOG_ERR); + $result = -1; + } + } + else + { + dol_syslog("CommandeFournisseur::Commande User not Authorized", LOG_ERR); + } + return $result ; + } + + /** + * Create order with draft status + * @param user User making creation + * @return int <0 if KO, Id of supplier order if OK + */ + function create($user) + { + global $langs,$conf; + + $this->db->begin(); + + $now=dol_now(); + + /* On positionne en mode brouillon la commande */ + $this->brouillon = 1; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur ("; + $sql.= "ref"; + $sql.= ", entity"; + $sql.= ", fk_soc"; + $sql.= ", date_creation"; + $sql.= ", fk_user_author"; + $sql.= ", fk_statut"; + $sql.= ", source"; + $sql.= ", model_pdf"; + //$sql.= ", fk_mode_reglement"; + $sql.= ") "; + $sql.= " VALUES ("; + $sql.= "''"; + $sql.= ", ".$conf->entity; + $sql.= ", ".$this->socid; + $sql.= ", ".$this->db->idate($now); + $sql.= ", ".$user->id; + $sql.= ", 0"; + $sql.= ", 0"; + $sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'"; + //$sql.= ", ".$this->mode_reglement_id; + $sql.= ")"; + + dol_syslog("CommandeFournisseur::Create sql=".$sql); + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " SET ref='(PROV".$this->id.")'"; + $sql.= " WHERE rowid=".$this->id; + dol_syslog("CommandeFournisseur::Create sql=".$sql); + if ($this->db->query($sql)) + { + // On logue creation pour historique + $this->log($user, 0, time()); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + dol_syslog("CommandeFournisseur::Create: Failed -2 - ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error(); + dol_syslog("CommandeFournisseur::Create: Failed -1 - ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + + /** + * Add order line + * @param desc Description + * @param pu_ht Unit price + * @param qty Quantity + * @param txtva Taux tva + * @param txlocaltax1 Localtax1 tax + * @param txlocaltax2 Localtax2 tax + * @param fk_product Id produit + * @param fk_prod_fourn_price Id supplier price + * @param fourn_ref Supplier reference + * @param remise_percent Remise + * @param price_base_type HT or TTC + * @param pu_ttc Unit price TTC + * @param type Type of line (0=product, 1=service) + * @return int <=0 if KO, >0 if OK + */ + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $type=0) + { + global $langs,$mysoc; + + dol_syslog("FournisseurCommande::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type"); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + + // Clean parameters + if (! $qty) $qty=1; + if (! $info_bits) $info_bits=0; + if (empty($txtva)) $txtva=0; + if (empty($txlocaltax1)) $txlocaltax1=0; + if (empty($txlocaltax2)) $txlocaltax2=0; + + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + $pu_ht=price2num($pu_ht); + $pu_ttc=price2num($pu_ttc); + $txtva = price2num($txtva); + $txlocaltax1 = price2num($txlocaltax1); + $txlocaltax2 = price2num($txlocaltax2); + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } + $desc=trim($desc); + + + // Check parameters + if ($qty < 1 && ! $fk_product) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Product")); + return -1; + } + if ($type < 0) return -1; + + + if ($this->statut == 0) + { + $this->db->begin(); + + if ($fk_product > 0) + { + $prod = new Product($this->db, $fk_product); + if ($prod->fetch($fk_product) > 0) + { + $result=$prod->get_buyprice($fk_prod_fourn_price,$qty,$fk_product,$fourn_ref); + if ($result > 0) + { + $label = $prod->libelle; + $pu = $prod->fourn_pu; + $ref = $prod->ref_fourn; + $product_type = $prod->type; + } + if ($result == 0 || $result == -1) + { + $this->error="No price found for this quantity. Quantity may be too low ?"; + $this->db->rollback(); + dol_syslog("FournisseurCommande::addline result=".$result." - ".$this->error, LOG_DEBUG); + return -1; + } + if ($result < -1) + { + $this->error=$prod->error; + $this->db->rollback(); + dol_syslog("Fournisseur.commande::addline result=".$result." - ".$this->error, LOG_ERR); + return -1; + } + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + else + { + $product_type = $type; + } + + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker + // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + $total_localtax1 = $tabprice[9]; + $total_localtax2 = $tabprice[10]; + + $subprice = price2num($pu,'MU'); + + // TODO A virer + // Anciens indicateurs: $price, $remise (a ne plus utiliser) + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($pu * $remise_percent / 100), 2); + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; + $sql.= " (fk_commande,label, description,"; + $sql.= " fk_product, product_type,"; + $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref,"; + $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc"; + $sql.= ")"; + $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; + if ($fk_product) { $sql.= $fk_product.","; } + else { $sql.= "null,"; } + $sql.= "'".$product_type."',"; + $sql.= "'".$qty."', ".$txtva.", ".$txlocaltax1.", ".$txlocaltax2.", ".$remise_percent.",'".price2num($subprice,'MU')."','".price2num($remise)."','".$ref."',"; + $sql.= "'".price2num($total_ht)."',"; + $sql.= "'".price2num($total_tva)."',"; + $sql.= "'".price2num($total_localtax1)."',"; + $sql.= "'".price2num($total_localtax2)."',"; + $sql.= "'".price2num($total_ttc)."'"; + $sql.= ")"; + + dol_syslog('FournisseurCommande::addline sql='.$sql); + $resql=$this->db->query($sql); + //print $sql; + if ($resql) + { + $this->update_price(); + + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + dol_syslog('FournisseurCommande::addline '.$this->error, LOG_ERR); + return -1; + } + } + } + + + /** + * Add a product into a stock warehouse. + * @param $user User object making change + * @param $product Id of product to dispatch + * @param $qty Qty to dispatch + * @param $entrepot Id of warehouse to add product + * @param $price Price for PMP value calculation + * @param $comment Comment for stock movement + * @return int <0 if KO, >0 if OK + */ + function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='') + { + global $conf; + $error = 0; + require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php"; + + // Check parameters + if ($entrepot <= 0 || $qty <= 0) + { + $this->error='BadValueForParameter'; + return -1; + } + + $now=dol_now(); + + if (($this->statut == 3 || $this->statut == 4 || $this->statut == 5)) + { + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch "; + $sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec) VALUES "; + $sql.= " ('".$this->id."','".$product."','".$qty."',".($entrepot>0?"'".$entrepot."'":"null").",'".$user->id."','".$this->db->idate($now)."')"; + + dol_syslog("CommandeFournisseur::DispatchProduct sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $error++; + } + + // Si module stock gere et que incrementation faite depuis un dispatching en stock + if (!$error && $entrepot > 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) + { + $mouv = new MouvementStock($this->db); + if ($product > 0) + { + $result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment); + if ($result < 0) + { + $this->error=$mouv->error; + dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR); + $error++; + } + } + $i++; + } + + if ($error == 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error='BadStatusForObject'; + return -2; + } + } + + /** + * Delete line + * @param idligne + */ + function deleteline($idligne) + { + if ($this->statut == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idligne; + $resql=$this->db->query($sql); + + dol_syslog("Fournisseur.commande.class::deleteline sql=".$sql); + if ($resql) + { + $result=$this->update_price(); + return 0; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + else + { + return -1; + } + } + + /** + * Delete an order + * @return int <0 if KO, >0 if OK + */ + function delete() + { + global $langs,$conf; + + $err = 0; + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ; + dol_syslog("FournisseurCommande::delete sql=".$sql, LOG_DEBUG); + if (! $this->db->query($sql) ) + { + $err++; + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id; + dol_syslog("FournisseurCommande::delete sql=".$sql, LOG_DEBUG); + if ($resql = $this->db->query($sql) ) + { + if ($this->db->affected_rows($resql) < 1) + { + $err++; + } + } + else + { + $err++; + } + + if ($err == 0) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + dol_syslog("CommandeFournisseur::delete : Success"); + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Return list of order methods + */ + function get_methodes_commande() + { + $sql = "SELECT rowid, libelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_input_method"; + $sql.= " WHERE active = 1"; + + $resql=$this->db->query($sql); + if ($resql) + { + $i = 0; + $num = $this->db->num_rows($resql); + $this->methodes_commande = array(); + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + + $this->methodes_commande[$row[0]] = $row[1]; + + $i++; + } + return 0; + } + else + { + return -1; + } + } + + /** + * Change les conditions de reglement de la commande + * @param cond_reglement_id Id de la nouvelle condition de reglement + * @return int >0 si ok, <0 si ko + */ + function cond_reglement($cond_reglement_id) + { + dol_syslog('CommandeFournisseur::cond_reglement('.$cond_reglement_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; + $sql .= ' SET fk_cond_reglement = '.$cond_reglement_id; + $sql .= ' WHERE rowid='.$this->id; + if ( $this->db->query($sql) ) + { + $this->cond_reglement_id = $cond_reglement_id; + return 1; + } + else + { + dol_syslog('CommandeFournisseur::cond_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('CommandeFournisseur::cond_reglement, etat commande incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + /** + * Change le mode de reglement + * @param mode_reglement_id Id du nouveau mode + * @return int >0 if OK, <0 if KO + */ + function mode_reglement($mode_reglement_id) + { + dol_syslog('CommandeFournisseur::mode_reglement('.$mode_reglement_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; + $sql .= ' SET fk_mode_reglement = '.$mode_reglement_id; + $sql .= ' WHERE rowid='.$this->id; + if ( $this->db->query($sql) ) + { + $this->mode_reglement_id = $mode_reglement_id; + return 1; + } + else + { + dol_syslog('CommandeFournisseur::mode_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('CommandeFournisseur::mode_reglement, etat commande incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + /** + * Set a delivery in database for this supplier order + * @param user User that input data + * @param date Date of reception + * @param type Type of receipt + * @param comment Comment + */ + function Livraison($user, $date, $type, $comment) + { + $result = 0; + + dol_syslog("CommandeFournisseur::Livraison"); + + if ($user->rights->fournisseur->commande->receptionner) + { + if ($type == 'par') $statut = 4; + if ($type == 'tot') $statut = 5; + if ($type == 'nev') $statut = 7; + if ($type == 'can') $statut = 7; + + if ($statut == 4 or $statut == 5 or $statut == 7) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " SET fk_statut = ".$statut; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut IN (3,4)"; // Process running or Partially received + + dol_syslog("CommandeFournisseur::Livraison sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $result = 0; + $result=$this->log($user, $statut, $date, $comment); + + $this->db->commit(); + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("CommandeFournisseur::Livraison Error ".$this->error, LOG_ERR); + $result = -1; + } + } + else + { + dol_syslog("CommandeFournisseur::Livraison Error -2", LOG_ERR); + $result = -2; + } + } + else + { + dol_syslog("CommandeFournisseur::Livraison Not Authorized"); + $result = -3; + } + return $result ; + } + + /** + * Cree la commande depuis une propale existante + * @param user Utilisateur qui cree + * @param idc Id de la propale qui sert de modele + * @param comclientid Id thirdparty + */ + function updateFromCommandeClient($user, $idc, $comclientid) + { + $comclient = new Commande($this->db); + $comclient->fetch($comclientid); + + $this->id = $idc; + + $this->lines = array(); + + for ($i = 0 ; $i < sizeof($comclient->lines) ; $i++) + { + $prod = new Product($this->db); + if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) + { + $libelle = $prod->libelle; + $ref = $prod->ref; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; + $sql .= " (fk_commande,label,description,fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)"; + $sql .= " VALUES (".$idc.", '" . $this->db->escape($libelle) . "','" . $this->db->escape($comclient->lines[$i]->desc) . "'"; + $sql .= ",".$comclient->lines[$i]->fk_product.",'".price2num($comclient->lines[$i]->price)."'"; + $sql .= ", '".$comclient->lines[$i]->qty."', ".$comclient->lines[$i]->tva_tx.", ".$comclient->lines[$i]->localtax1_tx.", ".$comclient->lines[$i]->localtax2_tx.", ".$comclient->lines[$i]->remise_percent; + $sql .= ", '".price2num($comclient->lines[$i]->subprice)."','0','".$ref."') ;"; + if ( $this->db->query( $sql) ) + { + $this->update_price(); + } + } + + return 1; + } + + + /** + * Update notes + * @param user + * @param note + * @param note_public + * @return int <0 if KO, >=0 if OK + * TODO Use instead update_note_public and update_note + */ + function UpdateNote($user, $note, $note_public) + { + // Clean parameters + $note=trim($note); + $note_public=trim($note_public); + + $result = 0; + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " SET note ='".$this->db->escape($note)."',"; + $sql.= " note_public ='".$this->db->escape($note_public)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("CommandeFournisseur::UpdateNote sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $result = 0; + } + else + { + $this->error=$this->db->error(); + dol_syslog("CommandeFournisseur::UpdateNote ".$this->error, LOG_ERR); + $result = -1; + } + + return $result ; + } + + /** + * Get list of user that can approve an order + */ + function ReadApprobators() + { + global $conf; + + $this->approbs = array(); + + $sql = "SELECT u.name, u.firstname, u.email"; + $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql.= " , ".MAIN_DB_PREFIX."user_rights as ur"; + $sql.= " WHERE u.rowid = ur.fk_user"; + $sql.= " AND u.entity = ".$conf->entity; + $sql.= " AND ur.fk_id = 184"; + + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $this->approbs[$i] = $row; + $i++; + } + + $this->db->free($resql); + } + else + { + dol_syslog("ReadApprobators Erreur", LOG_ERR); + } + } + + + /** + * Tag order with a particular status + * @param user Object user that change status + * @param status New status + * @return int <0 if KO, >0 if OK + */ + function setStatus($user,$status) + { + global $conf,$langs; + $error=0; + + $this->db->begin(); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; + $sql.= ' SET fk_statut='.$status; + $sql.= ' WHERE rowid = '.$this->id; + + dol_syslog("CommandeFournisseur::setStatus sql=".$sql); + $resql = $this->db->query($sql); + if ($resql) + { + + } + else + { + $error++; + $this->error=$this->db->lasterror(); + dol_syslog("CommandeFournisseur::setStatus ".$this->error); + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Update line + * @param rowid Id de la ligne de facture + * @param desc Description de la ligne + * @param pu Prix unitaire + * @param qty Quantity + * @param remise_percent Pourcentage de remise de la ligne + * @param tva_tx Taux TVA + * @param localtax1_tx Localtax1 tax + * @param localtax2_tx Localtax2 tax + * @param price_base_type Type of price base + * @param info_bits Miscellanous informations + * @param type Type of line (0=product, 1=service) + * @return int < 0 if error, > 0 if ok + */ + function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0) + { + dol_syslog("CommandeFournisseur::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type"); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + + if ($this->brouillon) + { + $this->db->begin(); + + // Clean parameters + if (empty($qty)) $qty=0; + if (empty($info_bits)) $info_bits=0; + if (empty($txtva)) $txtva=0; + if (empty($txlocaltax1)) $txlocaltax1=0; + if (empty($txlocaltax2)) $txlocaltax2=0; + if (empty($remise)) $remise=0; + if (empty($remise_percent)) $remise_percent=0; + + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + if (! $qty) $qty=1; + $pu = price2num($pu); + $txtva=price2num($txtva); + $txlocaltax1=price2num($txlocaltax1); + $txlocaltax2=price2num($txlocaltax2); + + // Check parameters + if ($type < 0) return -1; + + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker + // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + $total_localtax1 = $tabprice[9]; + $total_localtax2 = $tabprice[10]; + + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) + $subprice = $pu; + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($pu * $remise_percent / 100),2); + } + $subprice = price2num($subprice); + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; + $sql.= " description='".$this->db->escape($desc)."'"; + $sql.= ",subprice='".price2num($subprice)."'"; + $sql.= ",remise='".price2num($remise)."'"; + $sql.= ",remise_percent='".price2num($remise_percent)."'"; + $sql.= ",tva_tx='".price2num($txtva)."'"; + $sql.= ",localtax1_tx='".price2num($txlocaltax1)."'"; + $sql.= ",localtax2_tx='".price2num($txlocaltax2)."'"; + $sql.= ",qty='".price2num($qty)."'"; + if ($date_end) { $sql.= ",date_start='$date_end'"; } + else { $sql.=',date_start=null'; } + if ($date_end) { $sql.= ",date_end='$date_end'"; } + else { $sql.=',date_end=null'; } + $sql.= ",info_bits='".$info_bits."'"; + $sql.= ",total_ht='".price2num($total_ht)."'"; + $sql.= ",total_tva='".price2num($total_tva)."'"; + $sql.= ",total_localtax1='".price2num($total_localtax1)."'"; + $sql.= ",total_localtax2='".price2num($total_localtax2)."'"; + $sql.= ",total_ttc='".price2num($total_ttc)."'"; + $sql.= ",product_type='".$type."'"; + $sql.= " WHERE rowid = ".$rowid; + + dol_syslog("CommandeFournisseur::updateline sql=".$sql); + $result = $this->db->query( $sql); + if ($result > 0) + { + // Mise a jour info denormalisees au niveau facture + $this->update_price(); + + $this->db->commit(); + return $result; + } + else + { + $this->error=$this->db->error(); + dol_syslog("CommandeFournisseur::updateline ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + else + { + $this->error="Order status makes operation forbidden"; + dol_syslog("CommandeFournisseur::updateline ".$this->error, LOG_ERR); + return -2; + } + } + + + /** + * Initialise an example of instance with random values + * Used to build previews or test instances + */ + function initAsSpecimen() + { + global $user,$langs,$conf; + + dol_syslog("CommandeFournisseur::initAsSpecimen"); + + $now=dol_now(); + + // Charge tableau des produits prodids + $prodids = array(); + + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."product"; + $sql.= " WHERE entity = ".$conf->entity; + + $resql = $this->db->query($sql); + if ($resql) + { + $num_prods = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_prods) + { + $i++; + $row = $this->db->fetch_row($resql); + $prodids[$i] = $row[0]; + } + } + + // Initialise parametres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $this->socid = 1; + $this->date = $now; + $this->date_commande = $now; + $this->date_lim_reglement=$this->date+3600*24*30; + $this->cond_reglement_code = 'RECEP'; + $this->mode_reglement_code = 'CHQ'; + $this->note_public='This is a comment (public)'; + $this->note='This is a comment (private)'; + // Lines + $nbp = 5; + $xnbp = 0; + while ($xnbp < $nbp) + { + $line=new CommandeFournisseurLigne($this->db); + $line->desc=$langs->trans("Description")." ".$xnbp; + $line->qty=1; + $line->subprice=100; + $line->price=100; + $line->tva_tx=19.6; + $line->localtax1_tx=0; + $line->localtax2_tx=0; + if ($xnbp == 2) + { + $line->total_ht=50; + $line->total_ttc=59.8; + $line->total_tva=9.8; + $line->remise_percent=50; + } + else + { + $line->total_ht=100; + $line->total_ttc=119.6; + $line->total_tva=19.6; + $line->remise_percent=00; + } + $line->ref_fourn='SUPPLIER_REF_'.$xnbp; + $prodid = rand(1, $num_prods); + $line->fk_product=$prodids[$prodid]; + + $this->lines[$xnbp]=$line; + + $this->total_ht += $line->total_ht; + $this->total_tva += $line->total_tva; + $this->total_ttc += $line->total_ttc; + + $xnbp++; + } + } + + /** + * Load indicators for dashboard (this->nbtodo and this->nbtodolate) + * + * @param user Objet user + * @return int <0 if KO, >0 if OK + */ + function load_board($user) + { + global $conf, $user; + + $now=gmmktime(); + + $this->nbtodo=$this->nbtodolate=0; + $clause = " WHERE"; + + $sql = "SELECT c.rowid, c.date_creation as datec, c.fk_statut"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; + if (!$user->rights->societe->client->voir && !$user->societe_id) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc"; + $sql.= " WHERE sc.fk_user = " .$user->id; + $clause = " AND"; + } + $sql.= $clause." c.entity = ".$conf->entity; + $sql.= " AND (c.fk_statut BETWEEN 1 AND 2)"; + if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; + + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj=$this->db->fetch_object($resql)) + { + $this->nbtodo++; + if ($obj->fk_statut != 3 && $this->db->jdate($obj->datec) < ($now - $conf->commande->fournisseur->warning_delay)) $this->nbtodolate++; + } + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } } @@ -1798,121 +1798,124 @@ class CommandeFournisseur extends Commande */ class CommandeFournisseurLigne extends OrderLine { - // From llx_commandedet - var $qty; - var $tva_tx; - var $localtax1_tx; - var $localtax2_tx; - var $subprice; - var $remise_percent; - var $desc; // Description ligne - var $fk_product; // Id of predefined product - var $product_type = 0; // Type 0 = product, 1 = Service - var $total_ht; - var $total_tva; - var $total_localtax1; - var $total_localtax2; - var $total_ttc; + // From llx_commandedet + var $qty; + var $tva_tx; + var $localtax1_tx; + var $localtax2_tx; + var $subprice; + var $remise_percent; + var $desc; // Description ligne + var $fk_product; // Id of predefined product + var $product_type = 0; // Type 0 = product, 1 = Service + var $total_ht; + var $total_tva; + var $total_localtax1; + var $total_localtax2; + var $total_ttc; - // From llx_product - var $libelle; // Label produit - var $product_desc; // Description produit + // From llx_product + var $libelle; // Label produit + var $product_desc; // Description produit - // From llx_product_fournisseur - var $ref_fourn; // Ref supplier + // From llx_product_fournisseur + var $ref_fourn; // Ref supplier - /** - * Constructor - */ - function CommandeFournisseurLigne($DB) - { - $this->db= $DB; - } + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ + function CommandeFournisseurLigne($DB) + { + $this->db= $DB; + } - /** - * Load line order - * @param rowid id line order - */ - function fetch($rowid) - { - $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx,'; - $sql.= ' cd.localtax1_tx, cd.localtax2_tx,'; - $sql.= ' cd.remise, cd.remise_percent, cd.subprice,'; - $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,'; - $sql.= ' cd.total_localtax1, cd.local_localtax2,'; - $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; - $sql.= ' WHERE cd.rowid = '.$rowid; - $result = $this->db->query($sql); - if ($result) - { - $objp = $this->db->fetch_object($result); - $this->rowid = $objp->rowid; - $this->fk_commande = $objp->fk_commande; - $this->desc = $objp->description; - $this->qty = $objp->qty; - $this->subprice = $objp->subprice; - $this->tva_tx = $objp->tva_tx; - $this->localtax1_tx = $objp->localtax1_tx; - $this->localtax2_tx = $objp->localtax2_tx; - $this->remise = $objp->remise; - $this->remise_percent = $objp->remise_percent; - $this->fk_product = $objp->fk_product; - $this->info_bits = $objp->info_bits; - $this->total_ht = $objp->total_ht; - $this->total_tva = $objp->total_tva; - $this->total_localtax1 = $objp->total_localtax1; - $this->total_localtax2 = $objp->total_localtax2; - $this->total_ttc = $objp->total_ttc; - $this->product_type = $objp->product_type; + /** + * Load line order + * + * @param int $rowid id line order + */ + function fetch($rowid) + { + $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx,'; + $sql.= ' cd.localtax1_tx, cd.localtax2_tx,'; + $sql.= ' cd.remise, cd.remise_percent, cd.subprice,'; + $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,'; + $sql.= ' cd.total_localtax1, cd.local_localtax2,'; + $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; + $sql.= ' WHERE cd.rowid = '.$rowid; + $result = $this->db->query($sql); + if ($result) + { + $objp = $this->db->fetch_object($result); + $this->rowid = $objp->rowid; + $this->fk_commande = $objp->fk_commande; + $this->desc = $objp->description; + $this->qty = $objp->qty; + $this->subprice = $objp->subprice; + $this->tva_tx = $objp->tva_tx; + $this->localtax1_tx = $objp->localtax1_tx; + $this->localtax2_tx = $objp->localtax2_tx; + $this->remise = $objp->remise; + $this->remise_percent = $objp->remise_percent; + $this->fk_product = $objp->fk_product; + $this->info_bits = $objp->info_bits; + $this->total_ht = $objp->total_ht; + $this->total_tva = $objp->total_tva; + $this->total_localtax1 = $objp->total_localtax1; + $this->total_localtax2 = $objp->total_localtax2; + $this->total_ttc = $objp->total_ttc; + $this->product_type = $objp->product_type; - $this->ref = $objp->product_ref; - $this->product_libelle = $objp->product_libelle; - $this->product_desc = $objp->product_desc; + $this->ref = $objp->product_ref; + $this->product_libelle = $objp->product_libelle; + $this->product_desc = $objp->product_desc; - $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } - /** - * Mise a jour de l'objet ligne de commande en base - * @return int <0 si ko, >0 si ok - */ - function update_total() - { - $this->db->begin(); + /** + * Mise a jour de l'objet ligne de commande en base + * @return int <0 si ko, >0 si ok + */ + function update_total() + { + $this->db->begin(); - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; - $sql.= " total_ht='".price2num($this->total_ht)."'"; - $sql.= ",total_tva='".price2num($this->total_tva)."'"; - $sql.= ",total_localtax1='".price2num($this->total_localtax1)."'"; - $sql.= ",total_localtax2='".price2num($this->total_localtax2)."'"; - $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; - $sql.= " WHERE rowid = ".$this->rowid; + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; + $sql.= " total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_localtax1='".price2num($this->total_localtax1)."'"; + $sql.= ",total_localtax2='".price2num($this->total_localtax2)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("CommandeFournisseurLigne.class.php::update_total sql=$sql"); + dol_syslog("CommandeFournisseurLigne.class.php::update_total sql=$sql"); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("CommandeFournisseurLigne.class.php::update_total Error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("CommandeFournisseurLigne.class.php::update_total Error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } } ?> diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 4e926f6f367..cb9a77b15b9 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -84,12 +84,11 @@ class FactureFournisseur extends Facture /** - * Constructor - * @param DB Database access handler - * @param socid Id societe ('' par defaut) - * @param facid Id facture ('' par defaut) + * Constructor + * + * @param DoliDB $DB Database handler */ - function FactureFournisseur($DB, $socid='', $facid='') + function FactureFournisseur($DB) { $this->db = $DB ; @@ -112,8 +111,9 @@ class FactureFournisseur extends Facture /** * Create supplier invoice into database - * @param user object utilisateur qui cree - * @return int id facture si ok, < 0 si erreur + * + * @param User $user object utilisateur qui cree + * @return int id facture si ok, < 0 si erreur */ function create($user) { diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 921276052f5..f3bb9c3a7f5 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -49,7 +49,9 @@ class ProductFournisseur extends Product /** - * Constructor + * Constructor + * + * @param DoliDB $DB Database handler */ function ProductFournisseur($db) { diff --git a/htdocs/fourn/commande/contact.php b/htdocs/fourn/commande/contact.php index 2e634a2f403..d51ced68c18 100644 --- a/htdocs/fourn/commande/contact.php +++ b/htdocs/fourn/commande/contact.php @@ -135,7 +135,7 @@ if ($id > 0 || ! empty($ref)) $commande = new CommandeFournisseur($db); if ( $commande->fetch($_GET['id'],$_GET['ref']) > 0) { - $soc = new Societe($db, $commande->socid); + $soc = new Societe($db); $soc->fetch($commande->socid); diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index cf4a5a568d9..acac34251f2 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -374,7 +374,8 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) if ($_GET['action'] == 'del_ligne') { - $facfou = new FactureFournisseur($db,'',$_GET['facid']); + $facfou = new FactureFournisseur($db); + $facfou->fetch($_GET['facid']); $facfou->deleteline($_GET['lineid']); $_GET['action'] = 'edit'; } @@ -432,7 +433,7 @@ if ($_REQUEST['action'] == 'update_line') if ($_GET['action'] == 'addline') { - $facfou = new FactureFournisseur($db, '', $_GET['facid']); + $facfou = new FactureFournisseur($db); $ret=$facfou->fetch($_GET['facid']); if ($ret < 0) { @@ -540,7 +541,7 @@ if ($_GET['action'] == 'addline') if ($_POST['action'] == 'classin') { - $facture = new FactureFournisseur($db,'',$_GET['facid']); + $facture = new FactureFournisseur($db); $facture->fetch($_GET['facid']); $result=$facture->setProject($_POST['projectid']); } diff --git a/htdocs/fourn/facture/info.php b/htdocs/fourn/facture/info.php index d6ba59305c2..8b755976cb3 100644 --- a/htdocs/fourn/facture/info.php +++ b/htdocs/fourn/facture/info.php @@ -48,7 +48,7 @@ llxHeader(); $fac = new FactureFournisseur($db); $fac->fetch($_GET["facid"]); $fac->info($_GET["facid"]); -$soc = new Societe($db, $fac->socid); +$soc = new Societe($db); $soc->fetch($fac->socid); $head = facturefourn_prepare_head($fac); diff --git a/htdocs/includes/boxes/box_actions.php b/htdocs/includes/boxes/box_actions.php index 3af0cac08bb..1b27b7dceb9 100644 --- a/htdocs/includes/boxes/box_actions.php +++ b/htdocs/includes/boxes/box_actions.php @@ -41,7 +41,7 @@ class box_actions extends ModeleBoxes { /** - * Constructor + * Constructor */ function box_actions() { diff --git a/htdocs/includes/boxes/box_comptes.php b/htdocs/includes/boxes/box_comptes.php index 999a99b7ae4..86648746411 100644 --- a/htdocs/includes/boxes/box_comptes.php +++ b/htdocs/includes/boxes/box_comptes.php @@ -41,7 +41,7 @@ class box_comptes extends ModeleBoxes { /** - * \brief Constructor for class + * Constructor */ function box_comptes() { @@ -52,8 +52,9 @@ class box_comptes extends ModeleBoxes { } /** - * \brief Load data into info_box_contents array to show array later. - * \param $max Maximum number of records to load + * Load data into info_box_contents array to show array later. + * + * @param $max Maximum number of records to load */ function loadBox($max=5) { diff --git a/htdocs/includes/menus/smartphone/smartphone_frontoffice.php b/htdocs/includes/menus/smartphone/smartphone_frontoffice.php index 61bcee72327..85129ff8d21 100755 --- a/htdocs/includes/menus/smartphone/smartphone_frontoffice.php +++ b/htdocs/includes/menus/smartphone/smartphone_frontoffice.php @@ -34,8 +34,9 @@ class MenuSmart { /** - * Constructor - * @param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function MenuSmart($db) { @@ -45,6 +46,7 @@ class MenuSmart { /** * Show menu + * * @param limitmenuto To limit menu to a top or left menu value */ function showmenu($limitmenuto) diff --git a/htdocs/includes/menus/standard/auguria_backoffice.php b/htdocs/includes/menus/standard/auguria_backoffice.php index b8ee62505b1..7c5d669f069 100644 --- a/htdocs/includes/menus/standard/auguria_backoffice.php +++ b/htdocs/includes/menus/standard/auguria_backoffice.php @@ -76,10 +76,11 @@ class MenuLeft { /** - * Constructor - * @param db Database handler - * @param menu_array Table of menu entries to show before entries of menu handler - * @param menu_array_after Table of menu entries to show after entries of menu handler + * Constructor + * + * @param DoliDB $DB Database handler + * @param menu_array Table of menu entries to show before entries of menu handler + * @param menu_array_after Table of menu entries to show after entries of menu handler * */ function MenuLeft($db,&$menu_array,&$menu_array_after) @@ -91,8 +92,9 @@ class MenuLeft { /** - * \brief Show menu - * \return int Number of menu entries shown + * Show menu + * + * @return int Number of menu entries shown */ function showmenu() { diff --git a/htdocs/includes/menus/standard/auguria_frontoffice.php b/htdocs/includes/menus/standard/auguria_frontoffice.php index c56ba7680bf..abd3e3a8be8 100644 --- a/htdocs/includes/menus/standard/auguria_frontoffice.php +++ b/htdocs/includes/menus/standard/auguria_frontoffice.php @@ -78,6 +78,7 @@ class MenuLeft { /** * Constructor + * * @param db Database handler * @param menu_array Table of menu entries to show before entries of menu handler * @param menu_array_after Table of menu entries to show after entries of menu handler @@ -91,8 +92,9 @@ class MenuLeft { /** - * \brief Show menu - * \return int Number of menu entries shown + * Show menu + * + * @return int Number of menu entries shown */ function showmenu() { diff --git a/htdocs/includes/menus/standard/eldy_backoffice.php b/htdocs/includes/menus/standard/eldy_backoffice.php index 0633cfdeb2b..6d70dbb97d8 100644 --- a/htdocs/includes/menus/standard/eldy_backoffice.php +++ b/htdocs/includes/menus/standard/eldy_backoffice.php @@ -32,7 +32,7 @@ * \brief Class to manage top menu Eldy (for internal users) */ class MenuTop { - + var $db; var $require_left=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier var $hideifnotallowed=0; // Put 0 for back office menu, 1 for front office menu @@ -75,6 +75,7 @@ class MenuLeft { /** * Constructor + * * @param db Database handler * @param menu_array Table of menu entries to show before entries of menu handler * @param menu_array_after Table of menu entries to show after entries of menu handler @@ -88,8 +89,9 @@ class MenuLeft { /** - * \brief Show menu - * \return int Number of menu entries shown + * Show menu + * + * @return int Number of menu entries shown */ function showmenu() { diff --git a/htdocs/includes/menus/standard/eldy_frontoffice.php b/htdocs/includes/menus/standard/eldy_frontoffice.php index dfc196798e2..7821add41f3 100644 --- a/htdocs/includes/menus/standard/eldy_frontoffice.php +++ b/htdocs/includes/menus/standard/eldy_frontoffice.php @@ -75,6 +75,7 @@ class MenuLeft { /** * Constructor + * * @param db Database handler * @param menu_array Table of menu entries to show before entries of menu handler * @param menu_array_after Table of menu entries to show after entries of menu handler @@ -88,8 +89,9 @@ class MenuLeft { /** - * \brief Show menu - * \return int Number of menu entries shown + * Show menu + * + * @return int Number of menu entries shown */ function showmenu() { diff --git a/htdocs/includes/menus/standard/empty.php b/htdocs/includes/menus/standard/empty.php index d5abfed2ec2..c25699f7625 100644 --- a/htdocs/includes/menus/standard/empty.php +++ b/htdocs/includes/menus/standard/empty.php @@ -33,8 +33,9 @@ class MenuTop { /** - * Constructor - * @param db Dabatase handler + * Constructor + * + * @param DoliDB $DB Database handler */ function MenuTop($db) { @@ -122,6 +123,7 @@ class MenuLeft { /** * Constructor + * * @param db Database handler * @param menu_array Table of menu entries to show before entries of menu handler * @param menu_array_after Table of menu entries to show after entries of menu handler @@ -135,7 +137,7 @@ class MenuLeft { /** - * \brief Show menu + * Show menu */ function showmenu() { diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php index 3fed4170ab9..10e9770a23f 100644 --- a/htdocs/includes/modules/DolibarrModules.class.php +++ b/htdocs/includes/modules/DolibarrModules.class.php @@ -53,9 +53,9 @@ abstract class DolibarrModules /** - * Constructor - * - * @param DB Database access handler + * Constructor + * + * @param DoliDB $DB Database handler */ function DolibarrModules($DB) { diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index 98ae43eff54..f3619e0d992 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -239,7 +239,7 @@ function commande_delete_preview($db, $commandeid, $commanderef='') if (!$commanderef) { - $com = new Commande($db,"",$commandeid); + $com = new Commande($db); $com->fetch($commandeid); $commanderef = $com->ref; } diff --git a/htdocs/includes/modules/commande/pdf_einstein.modules.php b/htdocs/includes/modules/commande/pdf_einstein.modules.php index 9dbf79ca815..fa268dd4da8 100644 --- a/htdocs/includes/modules/commande/pdf_einstein.modules.php +++ b/htdocs/includes/modules/commande/pdf_einstein.modules.php @@ -59,9 +59,9 @@ class pdf_einstein extends ModelePDFCommandes /** - * Constructor - * - * @param DoliDb $db Database access handler + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_einstein($db) { diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php index 4ef09ad9bcb..7c412c0f900 100644 --- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php @@ -40,8 +40,9 @@ Class pdf_expedition_merou extends ModelePdfExpedition /** - * \brief Constructor - * \param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_expedition_merou($db=0) { diff --git a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php index 4fb4176a3b7..04f72a5e824 100644 --- a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -43,8 +43,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures /** - * \brief Constructor - * \param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function doc_generic_invoice_odt($db) { diff --git a/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php b/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php index 10ae9ed0c58..16331c1c0a3 100755 --- a/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/doc/pdf_crabe.modules.php @@ -60,8 +60,9 @@ class pdf_crabe extends ModelePDFFactures /** - * Constructor - * @param db Database access handler + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_crabe($db) { diff --git a/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php b/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php index 520d032c2a1..d398bda4ee6 100755 --- a/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/doc/pdf_oursin.modules.php @@ -50,7 +50,7 @@ class pdf_oursin extends ModelePDFFactures /** * Constructor * - * @param DoliDB $db Handler access data base + * @param DoliDB $DB Database handler */ function pdf_oursin($db) { diff --git a/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php index df079a81dca..78e85a430b8 100644 --- a/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php +++ b/htdocs/includes/modules/livraison/pdf/pdf_sirocco.modules.php @@ -37,8 +37,10 @@ require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php'); class pdf_sirocco extends ModelePDFDeliveryOrder { - /** \brief Constructor - * \param db Database handler + /** + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_sirocco($db) { diff --git a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php index bad672fdd74..0086417abe5 100644 --- a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php +++ b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php @@ -42,8 +42,9 @@ class pdf_typhon extends ModelePDFDeliveryOrder var $emetteur; // Objet societe qui emet /** - * \brief Constructor - * \param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_typhon($db) { diff --git a/htdocs/includes/modules/mailings/example.modules.php b/htdocs/includes/modules/mailings/example.modules.php index d9197f37d22..47d7029c8db 100644 --- a/htdocs/includes/modules/mailings/example.modules.php +++ b/htdocs/includes/modules/mailings/example.modules.php @@ -39,6 +39,11 @@ class mailing_example extends MailingTargets // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ function mailing_example($DB) { $this->db=$DB; diff --git a/htdocs/includes/modules/mailings/framboise.modules.php b/htdocs/includes/modules/mailings/framboise.modules.php index f0491b648d9..c54814c0654 100644 --- a/htdocs/includes/modules/mailings/framboise.modules.php +++ b/htdocs/includes/modules/mailings/framboise.modules.php @@ -37,7 +37,11 @@ class mailing_framboise extends MailingTargets var $db; - // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ function mailing_framboise($DB) { $this->db=$DB; diff --git a/htdocs/includes/modules/mailings/thirdparties_services_expired.modules.php b/htdocs/includes/modules/mailings/thirdparties_services_expired.modules.php index 0a6e92522b8..4e28e85f6b6 100755 --- a/htdocs/includes/modules/mailings/thirdparties_services_expired.modules.php +++ b/htdocs/includes/modules/mailings/thirdparties_services_expired.modules.php @@ -34,10 +34,10 @@ class mailing_thirdparties_services_expired extends MailingTargets /** - * Constructor + * Constructor * - * @param $DB - * @return mailing_thirdparties_services_expired + * @param DoliDB $DB Database handler + * @return mailing_thirdparties_services_expired */ function mailing_thirdparties_services_expired($DB) { diff --git a/htdocs/includes/modules/member/cards/pdf_standard.class.php b/htdocs/includes/modules/member/cards/pdf_standard.class.php index 256fda958e3..c16ebe3539a 100644 --- a/htdocs/includes/modules/member/cards/pdf_standard.class.php +++ b/htdocs/includes/modules/member/cards/pdf_standard.class.php @@ -96,7 +96,9 @@ class pdf_standard { /** - * Constructor + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_standard($db) { diff --git a/htdocs/includes/modules/member/labels/pdf_standardlabel.class.php b/htdocs/includes/modules/member/labels/pdf_standardlabel.class.php index f79522ec312..1028b040b63 100644 --- a/htdocs/includes/modules/member/labels/pdf_standardlabel.class.php +++ b/htdocs/includes/modules/member/labels/pdf_standardlabel.class.php @@ -97,7 +97,9 @@ class pdf_standardlabel { /** - * Constructor + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_standard($db) { diff --git a/htdocs/includes/modules/modPaybox.class.php b/htdocs/includes/modules/modPaybox.class.php index 35a2c1cb58f..059c30fb70b 100644 --- a/htdocs/includes/modules/modPaybox.class.php +++ b/htdocs/includes/modules/modPaybox.class.php @@ -32,135 +32,136 @@ include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); class modPayBox extends DolibarrModules { /** - * \brief Constructor. Define names, constants, directories, boxes, permissions - * \param DB Database handler - */ - function modPayBox($DB) - { - $this->db = $DB; + * Constructor. Define names, constants, directories, boxes, permissions + * + * @param DoliDB $DB Database handler + */ + function modPayBox($DB) + { + $this->db = $DB; - // Id for module (must be unique). - // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). - $this->numero = 50000; - // Key text used to identify module (for permissions, menus, etc...) - $this->rights_class = 'paybox'; + // Id for module (must be unique). + // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). + $this->numero = 50000; + // Key text used to identify module (for permissions, menus, etc...) + $this->rights_class = 'paybox'; - // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' - // It is used to group modules in module setup page - $this->family = "other"; - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) - $this->name = preg_replace('/^mod/i','',get_class($this)); - // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) - $this->description = "Module to offer an online payment page by credit card with PayBox"; - // Possible values for version are: 'development', 'experimental', 'dolibarr' or version - $this->version = 'dolibarr'; - // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); - // Where to store the module in setup page (0=common,1=interface,2=other) - $this->special = 1; - // Name of image file used for this module. - // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' - // If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png' - $this->picto='paybox@paybox'; + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' + // It is used to group modules in module setup page + $this->family = "other"; + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) + $this->name = preg_replace('/^mod/i','',get_class($this)); + // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) + $this->description = "Module to offer an online payment page by credit card with PayBox"; + // Possible values for version are: 'development', 'experimental', 'dolibarr' or version + $this->version = 'dolibarr'; + // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + // Where to store the module in setup page (0=common,1=interface,2=other) + $this->special = 1; + // Name of image file used for this module. + // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' + // If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png' + $this->picto='paybox@paybox'; - // Data directories to create when module is enabled. - $this->dirs = array('/paybox/temp'); + // Data directories to create when module is enabled. + $this->dirs = array('/paybox/temp'); - // Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'. - $this->style_sheet = ''; + // Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'. + $this->style_sheet = ''; - // Config pages. Put here list of php page names stored in admmin directory used to setup module. - $this->config_page_url = array("paybox.php@paybox"); + // Config pages. Put here list of php page names stored in admmin directory used to setup module. + $this->config_page_url = array("paybox.php@paybox"); - // Dependencies - $this->depends = array(); // List of modules id that must be enabled if this module is enabled - $this->requiredby = array(); // List of modules id to disable if this one is disabled - $this->phpmin = array(4,1); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(2,6); // Minimum version of Dolibarr required by module - $this->langfiles = array("paybox"); + // Dependencies + $this->depends = array(); // List of modules id that must be enabled if this module is enabled + $this->requiredby = array(); // List of modules id to disable if this one is disabled + $this->phpmin = array(4,1); // Minimum version of PHP required by module + $this->need_dolibarr_version = array(2,6); // Minimum version of Dolibarr required by module + $this->langfiles = array("paybox"); - // Constants - $this->const = array(); // List of particular constants to add when module is enabled - //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0), - // 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) ); + // Constants + $this->const = array(); // List of particular constants to add when module is enabled + //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0), + // 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) ); - // New pages on tabs - $this->tabs = array(); + // New pages on tabs + $this->tabs = array(); - // Boxes - $this->boxes = array(); // List of boxes - $r=0; + // Boxes + $this->boxes = array(); // List of boxes + $r=0; - // Add here list of php file(s) stored in includes/boxes that contains class to show a box. - // Example: + // Add here list of php file(s) stored in includes/boxes that contains class to show a box. + // Example: //$this->boxes[$r][1] = "myboxa.php"; - //$r++; + //$r++; //$this->boxes[$r][1] = "myboxb.php"; - //$r++; + //$r++; - // Permissions - $this->rights = array(); // Permission array used by this module - $r=0; + // Permissions + $this->rights = array(); // Permission array used by this module + $r=0; - // Add here list of permission defined by an id, a label, a boolean and two constant strings. - // Example: - // $this->rights[$r][0] = 2000; // Permission id (must not be already used) - // $this->rights[$r][1] = 'Permision label'; // Permission label - // $this->rights[$r][3] = 1; // Permission by default for new user (0/1) - // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - // $r++; + // Add here list of permission defined by an id, a label, a boolean and two constant strings. + // Example: + // $this->rights[$r][0] = 2000; // Permission id (must not be already used) + // $this->rights[$r][1] = 'Permision label'; // Permission label + // $this->rights[$r][3] = 1; // Permission by default for new user (0/1) + // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + // $r++; - // Main menu entries - $this->menus = array(); // List of menus to add - $r=0; + // Main menu entries + $this->menus = array(); // List of menus to add + $r=0; - // Add here entries to declare new menus - // Example to declare the Top Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu - // 'type'=>'top', // This is a Top menu entry - // 'titre'=>'MyModule top menu', - // 'mainmenu'=>'mymodule', - // 'leftmenu'=>'1', // Use 1 if you also want to add left menu entries using this descriptor. Use 0 if left menu entries are defined in a file pre.inc.php (old school). - // 'url'=>'/mymodule/pagetop.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - // - // Example to declare a Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) - // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 1', - // 'mainmenu'=>'mymodule', - // 'url'=>'/mymodule/pagelevel1.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - // - // Example to declare another Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=1', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) - // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 2', - // 'mainmenu'=>'mymodule', - // 'url'=>'/mymodule/pagelevel2.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; + // Add here entries to declare new menus + // Example to declare the Top Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu + // 'type'=>'top', // This is a Top menu entry + // 'titre'=>'MyModule top menu', + // 'mainmenu'=>'mymodule', + // 'leftmenu'=>'1', // Use 1 if you also want to add left menu entries using this descriptor. Use 0 if left menu entries are defined in a file pre.inc.php (old school). + // 'url'=>'/mymodule/pagetop.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + // + // Example to declare a Left Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // 'type'=>'left', // This is a Left menu entry + // 'titre'=>'MyModule left menu 1', + // 'mainmenu'=>'mymodule', + // 'url'=>'/mymodule/pagelevel1.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + // + // Example to declare another Left Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'r=1', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // 'type'=>'left', // This is a Left menu entry + // 'titre'=>'MyModule left menu 2', + // 'mainmenu'=>'mymodule', + // 'url'=>'/mymodule/pagelevel2.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; - // Exports + // Exports $r=1; // Example: @@ -168,54 +169,54 @@ class modPayBox extends DolibarrModules // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found) // $this->export_permission[$r]=array(array("facture","facture","export")); // $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'); - // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'); + // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'); // $this->export_sql_start[$r]='SELECT DISTINCT '; // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)'; - // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; - // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; + // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; + // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; // $r++; - } + } - /** + /** * \brief 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. - * \return int 1 if OK, 0 if KO + * \return int 1 if OK, 0 if KO */ - function init() - { - $sql = array(); + function init() + { + $sql = array(); - $result=$this->load_tables(); + $result=$this->load_tables(); - return $this->_init($sql); - } + return $this->_init($sql); + } - /** - * \brief Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted. - * \return int 1 if OK, 0 if KO - */ - function remove() - { - $sql = array(); + /** + * \brief Function called when module is disabled. + * Remove from database constants, boxes and permissions from Dolibarr database. + * Data directories are not deleted. + * \return int 1 if OK, 0 if KO + */ + function remove() + { + $sql = array(); - return $this->_remove($sql); - } + return $this->_remove($sql); + } - /** - * \brief Create tables and keys required by module - * Files mymodule.sql and mymodule.key.sql with create table and create keys - * commands must be stored in directory /mymodule/sql/ - * This function is called by this->init. - * \return int <=0 if KO, >0 if OK - */ - function load_tables() - { - return $this->_load_tables(''); - } + /** + * \brief Create tables and keys required by module + * Files mymodule.sql and mymodule.key.sql with create table and create keys + * commands must be stored in directory /mymodule/sql/ + * This function is called by this->init. + * \return int <=0 if KO, >0 if OK + */ + function load_tables() + { + return $this->_load_tables(''); + } } ?> diff --git a/htdocs/includes/modules/modPaypal.class.php b/htdocs/includes/modules/modPaypal.class.php index 2f45bfc2910..b7914787162 100644 --- a/htdocs/includes/modules/modPaypal.class.php +++ b/htdocs/includes/modules/modPaypal.class.php @@ -33,126 +33,127 @@ include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); class modPaypal extends DolibarrModules { /** - * \brief Constructor. Define names, constants, directories, boxes, permissions - * \param DB Database handler - */ - function modPaypal($DB) - { - $this->db = $DB; + * Constructor. Define names, constants, directories, boxes, permissions + * + * @param DoliDB $DB Database handler + */ + function modPaypal($DB) + { + $this->db = $DB; - // Id for module (must be unique). - // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). - $this->numero = 50200; - // Key text used to identify module (for permissions, menus, etc...) - $this->rights_class = 'paypal'; + // Id for module (must be unique). + // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). + $this->numero = 50200; + // Key text used to identify module (for permissions, menus, etc...) + $this->rights_class = 'paypal'; - // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' - // It is used to group modules in module setup page - $this->family = "other"; - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) - $this->name = preg_replace('/^mod/i','',get_class($this)); - // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) - $this->description = "Module to offer an online payment page with PayPal"; - // Possible values for version are: 'development', 'experimental', 'dolibarr' or version - $this->version = 'dolibarr'; - // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); - // Where to store the module in setup page (0=common,1=interface,2=other) - $this->special = 1; - // Name of image file used for this module. - // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' - // If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png' - $this->picto='paypal@paypal'; + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' + // It is used to group modules in module setup page + $this->family = "other"; + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) + $this->name = preg_replace('/^mod/i','',get_class($this)); + // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) + $this->description = "Module to offer an online payment page with PayPal"; + // Possible values for version are: 'development', 'experimental', 'dolibarr' or version + $this->version = 'dolibarr'; + // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + // Where to store the module in setup page (0=common,1=interface,2=other) + $this->special = 1; + // Name of image file used for this module. + // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' + // If file is in module/img directory, use this->picto=DOL_URL_ROOT.'/module/img/file.png' + $this->picto='paypal@paypal'; - // Data directories to create when module is enabled. - $this->dirs = array('/paypal/temp'); + // Data directories to create when module is enabled. + $this->dirs = array('/paypal/temp'); - // Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'. - $this->style_sheet = ''; + // Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'. + $this->style_sheet = ''; - // Config pages. Put here list of php page names stored in admmin directory used to setup module. - $this->config_page_url = array("paypal.php@paypal"); + // Config pages. Put here list of php page names stored in admmin directory used to setup module. + $this->config_page_url = array("paypal.php@paypal"); - // Dependencies - $this->depends = array(); // List of modules id that must be enabled if this module is enabled - $this->requiredby = array('modPaypalPlus'); // List of modules id to disable if this one is disabled - $this->phpmin = array(4,1); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(3,0,-2); // Minimum version of Dolibarr required by module - $this->langfiles = array("paypal"); + // Dependencies + $this->depends = array(); // List of modules id that must be enabled if this module is enabled + $this->requiredby = array('modPaypalPlus'); // List of modules id to disable if this one is disabled + $this->phpmin = array(4,1); // Minimum version of PHP required by module + $this->need_dolibarr_version = array(3,0,-2); // Minimum version of Dolibarr required by module + $this->langfiles = array("paypal"); - // Constants - $this->const = array(); // List of particular constants to add when module is enabled - //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0), - // 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) ); + // Constants + $this->const = array(); // List of particular constants to add when module is enabled + //Example: $this->const=array(0=>array('MODULE_MY_NEW_CONST1','chaine','myvalue','This is a constant to add',0), + // 1=>array('MODULE_MY_NEW_CONST2','chaine','myvalue','This is another constant to add',0) ); - // New pages on tabs - $this->tabs = array(); + // New pages on tabs + $this->tabs = array(); - // Boxes - $this->boxes = array(); // List of boxes - $r=0; + // Boxes + $this->boxes = array(); // List of boxes + $r=0; - // Add here list of php file(s) stored in includes/boxes that contains class to show a box. - // Example: + // Add here list of php file(s) stored in includes/boxes that contains class to show a box. + // Example: //$this->boxes[$r][1] = "myboxa.php"; - //$r++; + //$r++; //$this->boxes[$r][1] = "myboxb.php"; - //$r++; + //$r++; - // Permissions - $this->rights = array(); // Permission array used by this module - $r=0; + // Permissions + $this->rights = array(); // Permission array used by this module + $r=0; - // Main menu entries - $this->menus = array(); // List of menus to add - $r=0; + // Main menu entries + $this->menus = array(); // List of menus to add + $r=0; - // Add here entries to declare new menus - // Example to declare the Top Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu - // 'type'=>'top', // This is a Top menu entry - // 'titre'=>'MyModule top menu', - // 'mainmenu'=>'mymodule', - // 'leftmenu'=>'1', // Use 1 if you also want to add left menu entries using this descriptor. Use 0 if left menu entries are defined in a file pre.inc.php (old school). - // 'url'=>'/mymodule/pagetop.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - // - // Example to declare a Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) - // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 1', - // 'mainmenu'=>'mymodule', - // 'url'=>'/mymodule/pagelevel1.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; - // - // Example to declare another Left Menu entry: - // $this->menu[$r]=array( 'fk_menu'=>'r=1', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) - // 'type'=>'left', // This is a Left menu entry - // 'titre'=>'MyModule left menu 2', - // 'mainmenu'=>'mymodule', - // 'url'=>'/mymodule/pagelevel2.php', - // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - // 'position'=>100, - // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules - // 'target'=>'', - // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both - // $r++; + // Add here entries to declare new menus + // Example to declare the Top Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu + // 'type'=>'top', // This is a Top menu entry + // 'titre'=>'MyModule top menu', + // 'mainmenu'=>'mymodule', + // 'leftmenu'=>'1', // Use 1 if you also want to add left menu entries using this descriptor. Use 0 if left menu entries are defined in a file pre.inc.php (old school). + // 'url'=>'/mymodule/pagetop.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + // + // Example to declare a Left Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // 'type'=>'left', // This is a Left menu entry + // 'titre'=>'MyModule left menu 1', + // 'mainmenu'=>'mymodule', + // 'url'=>'/mymodule/pagelevel1.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; + // + // Example to declare another Left Menu entry: + // $this->menu[$r]=array( 'fk_menu'=>'r=1', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry) + // 'type'=>'left', // This is a Left menu entry + // 'titre'=>'MyModule left menu 2', + // 'mainmenu'=>'mymodule', + // 'url'=>'/mymodule/pagelevel2.php', + // 'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. + // 'position'=>100, + // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules + // 'target'=>'', + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + // $r++; - // Exports + // Exports $r=1; // Example: @@ -160,54 +161,54 @@ class modPaypal extends DolibarrModules // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found) // $this->export_permission[$r]=array(array("facture","facture","export")); // $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'); - // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'); + // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'); // $this->export_sql_start[$r]='SELECT DISTINCT '; // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)'; - // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; - // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; + // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; + // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; // $r++; - } + } - /** + /** * \brief 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. - * \return int 1 if OK, 0 if KO + * \return int 1 if OK, 0 if KO */ - function init() - { - $sql = array(); + function init() + { + $sql = array(); - $result=$this->load_tables(); + $result=$this->load_tables(); - return $this->_init($sql); - } + return $this->_init($sql); + } - /** - * \brief Function called when module is disabled. - * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted. - * \return int 1 if OK, 0 if KO - */ - function remove() - { - $sql = array(); + /** + * \brief Function called when module is disabled. + * Remove from database constants, boxes and permissions from Dolibarr database. + * Data directories are not deleted. + * \return int 1 if OK, 0 if KO + */ + function remove() + { + $sql = array(); - return $this->_remove($sql); - } + return $this->_remove($sql); + } - /** - * \brief Create tables and keys required by module - * Files mymodule.sql and mymodule.key.sql with create table and create keys - * commands must be stored in directory /mymodule/sql/ - * This function is called by this->init. - * \return int <=0 if KO, >0 if OK - */ - function load_tables() - { - return $this->_load_tables(''); - } + /** + * \brief Create tables and keys required by module + * Files mymodule.sql and mymodule.key.sql with create table and create keys + * commands must be stored in directory /mymodule/sql/ + * This function is called by this->init. + * \return int <=0 if KO, >0 if OK + */ + function load_tables() + { + return $this->_load_tables(''); + } } ?> diff --git a/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php b/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php index 83d6c176b80..73c9f7031cd 100644 --- a/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php +++ b/htdocs/includes/modules/project/pdf/pdf_baleine.modules.php @@ -40,8 +40,9 @@ class pdf_baleine extends ModelePDFProjects var $emetteur; // Objet societe qui emet /** - * \brief Constructor - * \param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function pdf_baleine($db) { diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php index f3cf3f0f340..32c2ef1b9ef 100644 --- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php +++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php @@ -43,8 +43,8 @@ class pdf_propale_azur extends ModelePDFPropales /** * Constructor - * - * @param db Database access handler + * + * @param DoliDB $DB Database handler */ function pdf_propale_azur($db) { diff --git a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php index 8676356106b..97c3078f8c2 100644 --- a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php +++ b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php @@ -44,7 +44,7 @@ class pdf_propale_jaune extends ModelePDFPropales /** * Constructor * - * @param DoliDB $db Handler access data base + * @param DoliDB $DB Database handler */ function pdf_propale_jaune($db) { diff --git a/htdocs/includes/modules/security/generate/modGeneratePassNone.class.php b/htdocs/includes/modules/security/generate/modGeneratePassNone.class.php index c6d0c79b85f..b2298725ac5 100644 --- a/htdocs/includes/modules/security/generate/modGeneratePassNone.class.php +++ b/htdocs/includes/modules/security/generate/modGeneratePassNone.class.php @@ -41,11 +41,12 @@ class modGeneratePassNone extends ModeleGenPassword /** - * \brief Constructor - * \param db Database handler - * \param conf Handler de conf - * \param lang Handler de langue - * \param user Handler du user connecte + * Constructor + * + * @param DoliDB $DB Database handler + * @param conf Handler de conf + * @param lang Handler de langue + * @param user Handler du user connecte */ function modGeneratePassNone($db, $conf, $langs, $user) { diff --git a/htdocs/includes/modules/security/generate/modGeneratePassStandard.class.php b/htdocs/includes/modules/security/generate/modGeneratePassStandard.class.php index e3323cfda80..33cb97171e3 100644 --- a/htdocs/includes/modules/security/generate/modGeneratePassStandard.class.php +++ b/htdocs/includes/modules/security/generate/modGeneratePassStandard.class.php @@ -41,11 +41,12 @@ class modGeneratePassStandard extends ModeleGenPassword /** - * \brief Constructor - * \param db Database handler - * \param conf Handler de conf - * \param lang Handler de langue - * \param user Handler du user connecte + * Constructor + * + * @param DoliDB $DB Database handler + * @param conf Handler de conf + * @param lang Handler de langue + * @param user Handler du user connecte */ function modGeneratePassStandard($db, $conf, $langs, $user) { diff --git a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php index f35ae1c4a7e..e14aed7ff5d 100644 --- a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php @@ -41,8 +41,9 @@ class doc_generic_odt extends ModeleThirdPartyDoc /** - * \brief Constructor - * \param db Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function doc_generic_odt($db) { diff --git a/htdocs/includes/modules/societe/mod_codeclient_elephant.php b/htdocs/includes/modules/societe/mod_codeclient_elephant.php index a65747078c0..0a89878b64d 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/includes/modules/societe/mod_codeclient_elephant.php @@ -47,7 +47,8 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode var $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} - /** Constructor + /** + * Constructor */ function mod_codeclient_elephant() { diff --git a/htdocs/includes/modules/societe/mod_codeclient_leopard.php b/htdocs/includes/modules/societe/mod_codeclient_leopard.php index cb6d108533f..8a425a929ad 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_leopard.php +++ b/htdocs/includes/modules/societe/mod_codeclient_leopard.php @@ -48,7 +48,8 @@ class mod_codeclient_leopard extends ModeleThirdPartyCode var $code_auto; // Numerotation automatique - /** Constructor + /** + * Constructor */ function mod_codeclient_leopard() { diff --git a/htdocs/includes/modules/societe/mod_codeclient_monkey.php b/htdocs/includes/modules/societe/mod_codeclient_monkey.php index c432a7013e6..c4238280536 100644 --- a/htdocs/includes/modules/societe/mod_codeclient_monkey.php +++ b/htdocs/includes/modules/societe/mod_codeclient_monkey.php @@ -44,7 +44,8 @@ class mod_codeclient_monkey extends ModeleThirdPartyCode var $prefixsupplier='SU'; - /** Constructor classe + /** + * Constructor */ function mod_codeclient_monkey() { diff --git a/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php b/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php index fbb39b04581..0cbd6a2d166 100755 --- a/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php +++ b/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php @@ -128,7 +128,7 @@ function supplier_invoice_delete_preview($db, $objectid) global $langs,$conf; require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); - $comfourn = new FactureFournisseur($db,"",$objectid); + $comfourn = new FactureFournisseur($db); $comfourn->fetch($objectid); $client = new Societe($db); $client->fetch($comfourn->socid); diff --git a/htdocs/includes/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/includes/modules/supplier_invoice/pdf/pdf_canelle.modules.php index f640f3c6f90..747f3c50a36 100755 --- a/htdocs/includes/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/includes/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -58,7 +58,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices /** * Constructor * - * @param DoliDB $db Handler access data base + * @param DoliDB $DB Database handler */ function pdf_canelle($db,$object) { diff --git a/htdocs/includes/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/includes/modules/supplier_order/pdf/pdf_muscadet.modules.php index bfc6ca8a4a3..606a1bf264a 100644 --- a/htdocs/includes/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/includes/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -60,7 +60,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders /** * Constructor * - * @param DoliDB $db Handler access data base + * @param DoliDB $DB Database handler */ function pdf_muscadet($db) { diff --git a/htdocs/lib/antivir.class.php b/htdocs/lib/antivir.class.php index 4a438a567ad..4ec45f0d359 100644 --- a/htdocs/lib/antivir.class.php +++ b/htdocs/lib/antivir.class.php @@ -37,10 +37,10 @@ class AntiVir var $db; /** - * Constructor + * Constructor * - * @param $db - * @return AntiVir + * @param DoliDB $DB Database handler + * @return AntiVir */ function AntiVir($db) { diff --git a/htdocs/lib/dolgeoip.class.php b/htdocs/lib/dolgeoip.class.php index 534a53286da..08192ca0167 100644 --- a/htdocs/lib/dolgeoip.class.php +++ b/htdocs/lib/dolgeoip.class.php @@ -40,7 +40,7 @@ class DolGeoIP * * @param $type 'country' or 'city' * @param $datfile Data file - * @return GeoIP + * @return GeoIP */ function DolGeoIP($type,$datfile) { diff --git a/htdocs/lib/google.class.php b/htdocs/lib/google.class.php index d40b2d4a024..ce0423c715d 100644 --- a/htdocs/lib/google.class.php +++ b/htdocs/lib/google.class.php @@ -30,8 +30,8 @@ class GoogleAPI /** * Constructor * - * @param db Database handler - * @param string Google key + * @param DoliDB $db Database handler + * @param string $key Google key * @return GoogleAPI */ function GoogleAPI($DB,$key) diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php index 219ce12f8b2..097ac3583c0 100644 --- a/htdocs/lib/ldap.class.php +++ b/htdocs/lib/ldap.class.php @@ -100,9 +100,9 @@ class Ldap */ var $result; + /** - * Constructor- creates a new instance of the authentication class - * + * Constructor */ function Ldap () { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c45be1664d6..806c1972a46 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -141,12 +141,11 @@ class Product extends CommonObject /** - * Constructor + * Constructor * - * @param DB Handler acces base de donnees - * @param id Id produit (0 par defaut) + * @param DoliDB $DB Database handler */ - function Product($DB, $id=0) + function Product($DB) { global $langs; @@ -158,8 +157,6 @@ class Product extends CommonObject $this->stock_reel = 0; $this->seuil_stock_alerte = 0; $this->canvas = ''; - - if ($this->id > 0) $this->fetch($this->id); } /** diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 0a73a481810..d527e97e7e6 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -51,8 +51,9 @@ class Entrepot extends CommonObject var $pays_id; /** - * Constructor - * @param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Entrepot($DB) { @@ -65,6 +66,7 @@ class Entrepot extends CommonObject /** * Creation d'un entrepot en base + * * @param Objet user qui cree l'entrepot */ function create($user) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 69af834d0d3..3f2f31006ad 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -30,9 +30,13 @@ */ class MouvementStock { + var $error; + var $db; + /** - * Constructor - * @param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function MouvementStock($DB) { diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index df752dd0b25..4cbc7624121 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -55,8 +55,9 @@ class Project extends CommonObject var $statuts; /** - * Constructor of class - * @param DB Database access handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Project($DB) { diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 086fdae5955..31c6cd86168 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -65,8 +65,9 @@ class Task extends CommonObject /** - * \brief Constructor - * \param DB Database handler + * Constructor + * + * @param DoliDB $DB Database handler */ function Task($DB) { diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index fcb39a66b56..0c3a029574e 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -47,7 +47,9 @@ class CompanyBankAccount extends Account var $adresse_proprio; /** - * Constructor + * Constructor + * + * @param DoliDB $DB Database handler */ function CompanyBankAccount($DB) { @@ -63,7 +65,6 @@ class CompanyBankAccount extends Account /** * Create bank information record - * */ function create() { diff --git a/htdocs/societe/socnote.php b/htdocs/societe/socnote.php index 7f33bfe62a4..0cb56f317fd 100644 --- a/htdocs/societe/socnote.php +++ b/htdocs/societe/socnote.php @@ -65,7 +65,7 @@ llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Notes"),$help_url) if ($socid > 0) { - $societe = new Societe($db, $socid); + $societe = new Societe($db); $societe->fetch($socid); /*