From 411b3415eb4033220137f2e7676025e3cb4a8f27 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Sep 2011 17:08:02 +0000 Subject: [PATCH] Doxygen --- htdocs/comm/action/class/actioncomm.class.php | 2 + .../comm/action/class/cactioncomm.class.php | 188 +- htdocs/comm/propal/class/propal.class.php | 10 +- htdocs/commande/class/commande.class.php | 6132 +++++++++-------- htdocs/compta/facture/class/facture.class.php | 14 +- htdocs/core/class/commonobject.class.php | 42 +- htdocs/core/class/cookie.class.php | 23 +- htdocs/core/class/smtps.class.php | 1020 +-- .../class/fournisseur.commande.class.php | 14 +- htdocs/includes/boxes/box_external_rss.php | 8 +- .../modules/commande/modules_commande.php | 29 +- .../modules/facture/modules_facture.php | 22 +- .../modules/member/labels/modules_labels.php | 20 +- .../modules/propale/modules_propale.php | 20 +- .../modules_facturefournisseur.php | 19 +- .../modules_commandefournisseur.php | 26 +- htdocs/install/etape1.php | 6 +- htdocs/lib/antivir.class.php | 3 +- htdocs/lib/databases/mssql.lib.php | 19 +- htdocs/lib/databases/mysql.lib.php | 19 +- htdocs/lib/databases/mysqli.lib.php | 27 +- htdocs/lib/databases/pgsql.lib.php | 21 +- htdocs/lib/doleditor.class.php | 26 +- htdocs/lib/functions.lib.php | 46 +- htdocs/lib/pdf.lib.php | 143 +- htdocs/lib/sendings.lib.php | 4 +- htdocs/lib/xcal.lib.php | 2 +- htdocs/main.inc.php | 39 +- .../product/actions_card_product.class.php | 8 +- .../service/actions_card_service.class.php | 8 +- .../canvas/actions_card_common.class.php | 8 +- .../default/actions_card_default.class.php | 8 +- .../actions_card_individual.class.php | 8 +- htdocs/societe/class/address.class.php | 37 +- 34 files changed, 3586 insertions(+), 4435 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 87c4dab887b..4ae874dee76 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -601,10 +601,12 @@ class ActionComm extends CommonObject /** * Renvoie nom clicable (avec eventuellement le picto) * Utilise $this->id, $this->code et $this->label + * * @param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul * @param maxlength Nombre de caracteres max dans libelle * @param classname Force style class on a link * @param option ''=Link to action,'birthday'=Link to contact + * @param overwritepicto 1=Overwrite picto * @return string Chaine avec URL */ function getNomUrl($withpicto=0,$maxlength=0,$classname='',$option='',$overwritepicto='') diff --git a/htdocs/comm/action/class/cactioncomm.class.php b/htdocs/comm/action/class/cactioncomm.class.php index 70ffcd4c813..6c5bac7db5b 100644 --- a/htdocs/comm/action/class/cactioncomm.class.php +++ b/htdocs/comm/action/class/cactioncomm.class.php @@ -27,42 +27,44 @@ * \class CActionComm * \brief Class to manage different types of events */ -class CActionComm { - var $db; +class CActionComm +{ + var $error; + var $db; - var $id; + var $id; - var $code; - var $type; - var $libelle; - var $active; + var $code; + var $type; + var $libelle; + var $active; - var $error; - - var $type_actions=array(); + var $type_actions=array(); - /** - * \brief Constructeur - * \param DB Handler d'acces base de donnee - */ - function CActionComm($DB) + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ + function CActionComm($DB) { - $this->db = $DB; + $this->db = $DB; } - /** - * \brief Charge l'objet type d'action depuis la base - * \param id id ou code du type d'action a recuperer - * \return int 1=ok, 0=aucune action, -1=erreur - */ - function fetch($id) + /** + * Charge l'objet type d'action depuis la base + * + * @param id id ou code du type d'action a recuperer + * @return int 1=ok, 0=aucune action, -1=erreur + */ + function fetch($id) { $sql = "SELECT id, code, type, libelle, active"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; - if (is_numeric($id)) $sql.= " WHERE id=".$id; - else $sql.= " WHERE code='".$id."'"; + if (is_numeric($id)) $sql.= " WHERE id=".$id; + else $sql.= " WHERE code='".$id."'"; $resql=$this->db->query($sql); if ($resql) @@ -93,82 +95,84 @@ class CActionComm { } } - /** - * Return list of event types - * @param active 1 or 0 to filter on event state active or not ('' bu default = no filter) - * @return array Array of all event types if OK, <0 if KO - */ - function liste_array($active='',$idorcode='id') - { - global $langs,$conf; - $langs->load("commercial"); + /** + * Return list of event types + * + * @param int $active 1 or 0 to filter on event state active or not ('' bu default = no filter) + * @param string $idorcode 'id' or 'code' + * @return array Array of all event types if OK, <0 if KO + */ + function liste_array($active='',$idorcode='id') + { + global $langs,$conf; + $langs->load("commercial"); - $repid = array(); - $repcode = array(); + $repid = array(); + $repcode = array(); - $sql = "SELECT id, code, libelle, module"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; - if ($active != '') - { - $sql.=" WHERE active=".$active; - } - $sql.= " ORDER BY module, position"; + $sql = "SELECT id, code, libelle, module"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; + if ($active != '') + { + $sql.=" WHERE active=".$active; + } + $sql.= " ORDER BY module, position"; - dol_syslog("CActionComm::liste_array sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $nump = $this->db->num_rows($resql); - if ($nump) - { - $i = 0; - while ($i < $nump) - { - $obj = $this->db->fetch_object($resql); - $qualified=1; - if ($obj->module) - { - if ($obj->module == 'invoice' && ! $conf->facture->enabled) $qualified=0; - if ($obj->module == 'order' && ! $conf->commande->enabled) $qualified=0; - if ($obj->module == 'propal' && ! $conf->propal->enabled) $qualified=0; + dol_syslog("CActionComm::liste_array sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $nump = $this->db->num_rows($resql); + if ($nump) + { + $i = 0; + while ($i < $nump) + { + $obj = $this->db->fetch_object($resql); + $qualified=1; + if ($obj->module) + { + if ($obj->module == 'invoice' && ! $conf->facture->enabled) $qualified=0; + if ($obj->module == 'order' && ! $conf->commande->enabled) $qualified=0; + if ($obj->module == 'propal' && ! $conf->propal->enabled) $qualified=0; if ($obj->module == 'invoice_supplier' && ! $conf->fournisseur->enabled) $qualified=0; if ($obj->module == 'order_supplier' && ! $conf->fournisseur->enabled) $qualified=0; - } - if ($qualified) - { - $transcode=$langs->trans("Action".$obj->code); - $repid[$obj->id] = ($transcode!="Action".$obj->code?$transcode:$langs->trans($obj->libelle)); - $repcode[$obj->code] = ($transcode!="Action".$obj->code?$transcode:$langs->trans($obj->libelle)); - } - $i++; - } - } - if ($idorcode == 'id') $this->liste_array=$repid; - if ($idorcode == 'code') $this->liste_array=$repcode; - return $this->liste_array; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } + } + if ($qualified) + { + $transcode=$langs->trans("Action".$obj->code); + $repid[$obj->id] = ($transcode!="Action".$obj->code?$transcode:$langs->trans($obj->libelle)); + $repcode[$obj->code] = ($transcode!="Action".$obj->code?$transcode:$langs->trans($obj->libelle)); + } + $i++; + } + } + if ($idorcode == 'id') $this->liste_array=$repid; + if ($idorcode == 'code') $this->liste_array=$repcode; + return $this->liste_array; + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } - /** - * \brief Renvoie le nom sous forme d'un libelle traduit d'un type d'action - * \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 Libelle du type d'action - */ - function getNomUrl($withpicto=0) - { - global $langs; + /** + * Renvoie le nom sous forme d'un libelle traduit d'un type d'action + * + * @param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * @return string Libelle du type d'action + */ + function getNomUrl($withpicto=0) + { + global $langs; - // Check if translation available - $transcode=$langs->trans("Action".$this->code); - if ($transcode != "Action".$this->code) return $transcode; - } + // Check if translation available + $transcode=$langs->trans("Action".$this->code); + if ($transcode != "Action".$this->code) return $transcode; + } } ?> diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 2352de1e27b..b7ee7f6bb06 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -820,10 +820,12 @@ class Propal extends CommonObject /** * Load an object from its id and create a new one in database - * @param fromid Id of object to clone - * @param invertdetail Reverse sign of amounts for lines - * @param socid Id of thirdparty - * @return int New id of clone + * + * @param int $fromid Id of object to clone + * @param int $invertdetail Reverse sign of amounts for lines + * @param int $socid Id of thirdparty + * @param HookManager $hookmanager Hook manager instance + * @return int New id of clone */ function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e999090bb21..28869e76fca 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -35,2737 +35,2751 @@ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); */ class Commande extends CommonObject { - var $db; - var $error; - var $element='commande'; - var $table_element='commande'; - var $table_element_line = 'commandedet'; - var $class_element_line = 'OrderLine'; - 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 $id ; - - var $socid; // Id client - var $client; // Objet societe client (a charger par fetch_client) - - var $ref; - var $ref_client; - var $ref_ext; - var $ref_int; - var $contactid; - var $fk_project; - var $statut; // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) - - var $facturee; // Facturee ou non - var $brouillon; - var $cond_reglement_id; - var $cond_reglement_code; - var $mode_reglement_id; - var $mode_reglement_code; - var $availability_id; - var $availability_code; - var $demand_reason_id; - var $demand_reason_code; - var $fk_delivery_address; - var $adresse; - var $date; // Date commande - var $date_commande; // Date commande (deprecated) - var $date_livraison; // Date livraison souhaitee - var $fk_remise_except; - var $remise_percent; - var $total_ht; // Total net of tax - var $total_ttc; // Total with tax - var $total_tva; // Total VAT - var $total_localtax1; // Total Local tax 1 - var $total_localtax2; // Total Local tax 2 - var $remise_absolue; - var $modelpdf; - var $info_bits; - var $rang; - var $special_code; - var $source; // Origin of order - - var $origin; - var $origin_id; - - var $user_author_id; - - var $lines = array(); - - // Pour board - var $nbtodo; - var $nbtodolate; - - - /** - * Constructor - * - * @param DoliDB $DB Database handler - */ - function Commande($DB) - { - global $langs; - $langs->load('orders'); - $this->db = $DB; - $this->socid = $socid; - $this->id = $commandeid; - - $this->remise = 0; - $this->remise_percent = 0; - - $this->products = array(); - } - - /** - * \brief Renvoie la reference de commande suivante non utilisee en fonction du module - * de numerotation actif defini dans COMMANDE_ADDON - * \param soc objet societe - * \return string reference libre pour la commande - */ - function getNextNumRef($soc) - { - global $db, $langs, $conf; - $langs->load("order"); - - $dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande"; - - if (! empty($conf->global->COMMANDE_ADDON)) - { - $file = $conf->global->COMMANDE_ADDON.".php"; - - // Chargement de la classe de numerotation - $classname = $conf->global->COMMANDE_ADDON; - - $result=include_once($dir.'/'.$file); - if ($result) - { - $obj = new $classname(); - $numref = ""; - $numref = $obj->getNextValue($soc,$this); - - if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db,"Commande::getNextNumRef ".$obj->error); - return ""; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); - return ""; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); - return ""; - } - } - - - /** - * \brief Validate order - * \param user User making status change - * \return int <=0 if OK, >0 if KO - */ - function valid($user) - { - global $conf,$langs; - require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); - - $error=0; - - // Protection - if ($this->statut == 1) - { - dol_syslog("Commande::valid no draft status", LOG_WARNING); - return 0; - } - - if (! $user->rights->commande->valider) - { - $this->error='Permission denied'; - dol_syslog("Commande::valid ".$this->error, LOG_ERR); - return -1; - } - - $now=dol_now(); - - $this->db->begin(); - - // Definition du nom de module de numerotation de commande - $soc = new Societe($this->db); - $soc->fetch($this->socid); - - // Class of company linked to order - $result=$soc->set_as_client(); - - // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) - { - $num = $this->getNextNumRef($soc); - } - else - { - $num = $this->ref; - } - - // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET ref = '".$num."'"; - $sql.= ", fk_statut = 1"; - $sql.= ", date_valid=".$this->db->idate($now); - $sql.= ", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog("Commande::valid() sql=".$sql); - $resql=$this->db->query($sql); - if (! $resql) - { - dol_syslog("Commande::valid() Echec update - 10 - sql=".$sql, LOG_ERR); - dol_print_error($this->db); - $error++; - } - - if (! $error) - { - // If stock is incremented on validate order, we must increment it - if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) - { - require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - $langs->load("agenda"); - - // Loop on each line - for ($i = 0 ; $i < sizeof($this->lines) ; $i++) - { - 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->livraison($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); - if ($result < 0) { $error++; } - } - } - } - } - - if (! $error) - { - $this->oldref=''; - - // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { - // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) - // afin de ne pas perdre les fichiers attaches - $comref = dol_sanitizeFileName($this->ref); - $snum = dol_sanitizeFileName($num); - $dirsource = $conf->commande->dir_output.'/'.$comref; - $dirdest = $conf->commande->dir_output.'/'.$snum; - if (file_exists($dirsource)) - { - dol_syslog("Commande::valid() rename dir ".$dirsource." into ".$dirdest); - - if (@rename($dirsource, $dirdest)) - { - $this->oldref = $comref; - - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'.*'); - } - } - } - } - - // Set new ref and current status - if (! $error) - { - $this->ref = $num; - $this->statut = 1; - } - - 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_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } - - /** - * \brief 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) - { - return 0; - } - - if (! $user->rights->commande->valider) - { - $this->error='Permission denied'; - return -1; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET fk_statut = 0"; - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - // If stock is decremented on validate order, we must reincrement it - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) - { - require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - $langs->load("agenda"); - - 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; - } - } - - - /** - * Tag the order as validated (opened) - * Function used when order is reopend after being closed. - * @param user Object user that change status - * @return int <0 if KO, 0 if nothing is done, >0 if OK - */ - function set_reopen($user) - { - global $conf,$langs; - $error=0; - - if ($this->statut != 3) - { - return 0; - } - - $this->db->begin(); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET fk_statut=1, facture=0'; - $sql.= ' WHERE rowid = '.$this->id; - - dol_syslog("Commande::set_reopen sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0); - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('BILL_REOPEN',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - else - { - $error++; - $this->error=$this->db->error(); - dol_print_error($this->db); - } - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - - /** - * Close order - * @param user Objet user that close - * @return int <0 if KO, >0 if OK - */ - function cloture($user) - { - global $conf, $langs; - - $error=0; - - if ($user->rights->commande->valider) - { - $this->db->begin(); - - $now=dol_now(); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET fk_statut = 3,'; - $sql.= ' fk_user_cloture = '.$user->id.','; - $sql.= ' date_cloture = '.$this->db->idate($now); - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; - - if ($this->db->query($sql)) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_CLOSE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - if (! $error) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog($this->error, LOG_ERR); - - $this->db->rollback(); - return -1; - } - } - } - - /** - * \brief Cancel an order - * \return int <0 if KO, >0 if OK - * \remarks If stock is decremented on order validation, we must reincrement it - */ - function cancel($user) - { - global $conf; - - $error=0; - - if ($user->rights->commande->valider) - { - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET fk_statut = -1"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut = 1"; - - dol_syslog("Commande::cancel sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - // If stock is decremented on validate order, we must reincrement it - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) - { - require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - $langs->load("agenda"); - - 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) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_CANCEL',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - if (! $error) - { - $this->statut=-1; - $this->db->commit(); - return 1; - } - else - { - $this->error=$mouvP->error; - $this->db->rollback(); - return -1; - } - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - dol_syslog($this->error, LOG_ERR); - return -1; - } - } - } - - /** - * Create order - * Note that this->ref can be set or empty. If empty, we will use "(PROV)" - * @param user Objet user that make creation - * @param notrigger Disable all triggers - * @return int <0 if KO, >0 if OK - */ - function create($user, $notrigger=0) - { - global $conf,$langs,$mysoc; - $error=0; - - // Clean parameters - $this->brouillon = 1; // On positionne en mode brouillon la commande - - dol_syslog("Commande::create user=".$user->id); - - // Check parameters - $soc = new Societe($this->db); - $result=$soc->fetch($this->socid); - if ($result < 0) - { - $this->error="Failed to fetch company"; - dol_syslog("Commande::create ".$this->error, LOG_ERR); - return -2; - } - if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source")); - dol_syslog("Commande::create ".$this->error, LOG_ERR); - return -1; - } - if (! $remise) $remise=0; - if (! $this->fk_project) $this->fk_project = 0; - - // $date_commande is deprecated - $date = ($this->date_commande ? $this->date_commande : $this->date); - - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande ("; - $sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client, ref_int"; - $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_demand_reason, date_livraison, fk_adresse_livraison"; - $sql.= ", remise_absolue, remise_percent"; - $sql.= ", entity"; - $sql.= ")"; - $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->fk_project; - $sql.= ", ".$this->db->idate($date); - $sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null'); - $sql.= ", '".$this->db->escape($this->note)."'"; - $sql.= ", '".$this->db->escape($this->note_public)."'"; - $sql.= ", '".$this->db->escape($this->ref_client)."'"; - $sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null"); - $sql.= ", '".$this->modelpdf."'"; - $sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null"); - $sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null"); - $sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null"); - $sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null"); - $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); - $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL'); - $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); - $sql.= ", '".$this->remise_percent."'"; - $sql.= ", ".$conf->entity; - $sql.= ")"; - - dol_syslog("Commande::create sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande'); - - if ($this->id) - { - $fk_parent_line=0; - $num=sizeof($this->lines); - - /* - * Insertion du detail des produits dans la base - */ - for ($i=0;$i<$num;$i++) - { - // Reset fk_parent_line for no child products and special product - if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) { - $fk_parent_line = 0; - } - - $result = $this->addline( - $this->id, - $this->lines[$i]->desc, - $this->lines[$i]->subprice, - $this->lines[$i]->qty, - $this->lines[$i]->tva_tx, - $this->lines[$i]->localtax1_tx, - $this->lines[$i]->localtax2_tx, - $this->lines[$i]->fk_product, - $this->lines[$i]->remise_percent, - $this->lines[$i]->info_bits, - $this->lines[$i]->fk_remise_except, + var $db; + var $error; + var $element='commande'; + var $table_element='commande'; + var $table_element_line = 'commandedet'; + var $class_element_line = 'OrderLine'; + 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 $id ; + + var $socid; // Id client + var $client; // Objet societe client (a charger par fetch_client) + + var $ref; + var $ref_client; + var $ref_ext; + var $ref_int; + var $contactid; + var $fk_project; + var $statut; // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) + + var $facturee; // Facturee ou non + var $brouillon; + var $cond_reglement_id; + var $cond_reglement_code; + var $mode_reglement_id; + var $mode_reglement_code; + var $availability_id; + var $availability_code; + var $demand_reason_id; + var $demand_reason_code; + var $fk_delivery_address; + var $adresse; + var $date; // Date commande + var $date_commande; // Date commande (deprecated) + var $date_livraison; // Date livraison souhaitee + var $fk_remise_except; + var $remise_percent; + var $total_ht; // Total net of tax + var $total_ttc; // Total with tax + var $total_tva; // Total VAT + var $total_localtax1; // Total Local tax 1 + var $total_localtax2; // Total Local tax 2 + var $remise_absolue; + var $modelpdf; + var $info_bits; + var $rang; + var $special_code; + var $source; // Origin of order + + var $origin; + var $origin_id; + + var $user_author_id; + + var $lines = array(); + + // Pour board + var $nbtodo; + var $nbtodolate; + + + /** + * Constructor + * + * @param DoliDB $DB Database handler + */ + function Commande($DB) + { + global $langs; + $langs->load('orders'); + $this->db = $DB; + $this->socid = $socid; + $this->id = $commandeid; + + $this->remise = 0; + $this->remise_percent = 0; + + $this->products = array(); + } + + /** + * \brief Renvoie la reference de commande suivante non utilisee en fonction du module + * de numerotation actif defini dans COMMANDE_ADDON + * \param soc objet societe + * \return string reference libre pour la commande + */ + function getNextNumRef($soc) + { + global $db, $langs, $conf; + $langs->load("order"); + + $dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande"; + + if (! empty($conf->global->COMMANDE_ADDON)) + { + $file = $conf->global->COMMANDE_ADDON.".php"; + + // Chargement de la classe de numerotation + $classname = $conf->global->COMMANDE_ADDON; + + $result=include_once($dir.'/'.$file); + if ($result) + { + $obj = new $classname(); + $numref = ""; + $numref = $obj->getNextValue($soc,$this); + + if ( $numref != "") + { + return $numref; + } + else + { + dol_print_error($db,"Commande::getNextNumRef ".$obj->error); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); + return ""; + } + } + + + /** + * \brief Validate order + * \param user User making status change + * \return int <=0 if OK, >0 if KO + */ + function valid($user) + { + global $conf,$langs; + require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); + + $error=0; + + // Protection + if ($this->statut == 1) + { + dol_syslog("Commande::valid no draft status", LOG_WARNING); + return 0; + } + + if (! $user->rights->commande->valider) + { + $this->error='Permission denied'; + dol_syslog("Commande::valid ".$this->error, LOG_ERR); + return -1; + } + + $now=dol_now(); + + $this->db->begin(); + + // Definition du nom de module de numerotation de commande + $soc = new Societe($this->db); + $soc->fetch($this->socid); + + // Class of company linked to order + $result=$soc->set_as_client(); + + // Define new ref + if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) + { + $num = $this->getNextNumRef($soc); + } + else + { + $num = $this->ref; + } + + // Validate + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET ref = '".$num."'"; + $sql.= ", fk_statut = 1"; + $sql.= ", date_valid=".$this->db->idate($now); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("Commande::valid() sql=".$sql); + $resql=$this->db->query($sql); + if (! $resql) + { + dol_syslog("Commande::valid() Echec update - 10 - sql=".$sql, LOG_ERR); + dol_print_error($this->db); + $error++; + } + + if (! $error) + { + // If stock is incremented on validate order, we must increment it + if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) + { + require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); + + // Loop on each line + for ($i = 0 ; $i < sizeof($this->lines) ; $i++) + { + 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->livraison($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); + if ($result < 0) { $error++; } + } + } + } + } + + if (! $error) + { + $this->oldref=''; + + // Rename directory if dir was a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) + // afin de ne pas perdre les fichiers attaches + $comref = dol_sanitizeFileName($this->ref); + $snum = dol_sanitizeFileName($num); + $dirsource = $conf->commande->dir_output.'/'.$comref; + $dirdest = $conf->commande->dir_output.'/'.$snum; + if (file_exists($dirsource)) + { + dol_syslog("Commande::valid() rename dir ".$dirsource." into ".$dirdest); + + if (@rename($dirsource, $dirdest)) + { + $this->oldref = $comref; + + dol_syslog("Rename ok"); + // Suppression ancien fichier PDF dans nouveau rep + dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'.*'); + } + } + } + } + + // Set new ref and current status + if (! $error) + { + $this->ref = $num; + $this->statut = 1; + } + + 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_VALIDATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + + /** + * \brief 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) + { + return 0; + } + + if (! $user->rights->commande->valider) + { + $this->error='Permission denied'; + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + // If stock is decremented on validate order, we must reincrement it + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) + { + require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); + + 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; + } + } + + + /** + * Tag the order as validated (opened) + * Function used when order is reopend after being closed. + * @param user Object user that change status + * @return int <0 if KO, 0 if nothing is done, >0 if OK + */ + function set_reopen($user) + { + global $conf,$langs; + $error=0; + + if ($this->statut != 3) + { + return 0; + } + + $this->db->begin(); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql.= ' SET fk_statut=1, facture=0'; + $sql.= ' WHERE rowid = '.$this->id; + + dol_syslog("Commande::set_reopen sql=".$sql); + $resql = $this->db->query($sql); + if ($resql) + { + $this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('BILL_REOPEN',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + else + { + $error++; + $this->error=$this->db->error(); + dol_print_error($this->db); + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Close order + * @param user Objet user that close + * @return int <0 if KO, >0 if OK + */ + function cloture($user) + { + global $conf, $langs; + + $error=0; + + if ($user->rights->commande->valider) + { + $this->db->begin(); + + $now=dol_now(); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql.= ' SET fk_statut = 3,'; + $sql.= ' fk_user_cloture = '.$user->id.','; + $sql.= ' date_cloture = '.$this->db->idate($now); + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; + + if ($this->db->query($sql)) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_CLOSE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog($this->error, LOG_ERR); + + $this->db->rollback(); + return -1; + } + } + } + + /** + * \brief Cancel an order + * \return int <0 if KO, >0 if OK + * \remarks If stock is decremented on order validation, we must reincrement it + */ + function cancel($user) + { + global $conf; + + $error=0; + + if ($user->rights->commande->valider) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = -1"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut = 1"; + + dol_syslog("Commande::cancel sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + // If stock is decremented on validate order, we must reincrement it + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) + { + require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); + + 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) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_CANCEL',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if (! $error) + { + $this->statut=-1; + $this->db->commit(); + return 1; + } + else + { + $this->error=$mouvP->error; + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + dol_syslog($this->error, LOG_ERR); + return -1; + } + } + } + + /** + * Create order + * Note that this->ref can be set or empty. If empty, we will use "(PROV)" + * @param user Objet user that make creation + * @param notrigger Disable all triggers + * @return int <0 if KO, >0 if OK + */ + function create($user, $notrigger=0) + { + global $conf,$langs,$mysoc; + $error=0; + + // Clean parameters + $this->brouillon = 1; // On positionne en mode brouillon la commande + + dol_syslog("Commande::create user=".$user->id); + + // Check parameters + $soc = new Societe($this->db); + $result=$soc->fetch($this->socid); + if ($result < 0) + { + $this->error="Failed to fetch company"; + dol_syslog("Commande::create ".$this->error, LOG_ERR); + return -2; + } + if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source")); + dol_syslog("Commande::create ".$this->error, LOG_ERR); + return -1; + } + if (! $remise) $remise=0; + if (! $this->fk_project) $this->fk_project = 0; + + // $date_commande is deprecated + $date = ($this->date_commande ? $this->date_commande : $this->date); + + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande ("; + $sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client, ref_int"; + $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_demand_reason, date_livraison, fk_adresse_livraison"; + $sql.= ", remise_absolue, remise_percent"; + $sql.= ", entity"; + $sql.= ")"; + $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->fk_project; + $sql.= ", ".$this->db->idate($date); + $sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null'); + $sql.= ", '".$this->db->escape($this->note)."'"; + $sql.= ", '".$this->db->escape($this->note_public)."'"; + $sql.= ", '".$this->db->escape($this->ref_client)."'"; + $sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null"); + $sql.= ", '".$this->modelpdf."'"; + $sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null"); + $sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null"); + $sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null"); + $sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null"); + $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); + $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL'); + $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); + $sql.= ", '".$this->remise_percent."'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; + + dol_syslog("Commande::create sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande'); + + if ($this->id) + { + $fk_parent_line=0; + $num=sizeof($this->lines); + + /* + * Insertion du detail des produits dans la base + */ + for ($i=0;$i<$num;$i++) + { + // Reset fk_parent_line for no child products and special product + if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) { + $fk_parent_line = 0; + } + + $result = $this->addline( + $this->id, + $this->lines[$i]->desc, + $this->lines[$i]->subprice, + $this->lines[$i]->qty, + $this->lines[$i]->tva_tx, + $this->lines[$i]->localtax1_tx, + $this->lines[$i]->localtax2_tx, + $this->lines[$i]->fk_product, + $this->lines[$i]->remise_percent, + $this->lines[$i]->info_bits, + $this->lines[$i]->fk_remise_except, 'HT', - 0, - $this->lines[$i]->date_start, - $this->lines[$i]->date_end, - $this->lines[$i]->product_type, - $this->lines[$i]->rang, - $this->lines[$i]->special_code, - $fk_parent_line - ); - if ($result < 0) - { - $this->error=$this->db->lasterror(); - dol_print_error($this->db); - $this->db->rollback(); - return -1; - } - // Defined the new fk_parent_line - if ($result > 0 && $this->lines[$i]->product_type == 9) { - $fk_parent_line = $result; - } - } - - // Mise a jour ref - $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; - if ($this->db->query($sql)) - { - if ($this->id) - { - $this->ref="(PROV".$this->id.")"; - - // Add linked object - if ($this->origin && $this->origin_id) - { - $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); - } - - // TODO mutualiser - if ($this->origin == 'propal' && $this->origin_id) - { - // On recupere les differents contact interne et externe - $prop = new Propal($this->db, $this->socid, $this->origin_id); - - // On recupere le commercial suivi propale - $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); - - if ($this->userid) - { - //On passe le commercial suivi propale en commercial suivi commande - $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); - } - - // On recupere le contact client suivi propale - $this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); - - if ($this->contactid) - { - //On passe le contact client suivi propale en contact client suivi commande - $this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); - } - } - } - - if (! $notrigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - $this->db->commit(); - return $this->id; - } - else - { - $this->db->rollback(); - return -1; - } - } - } - else - { - dol_print_error($this->db); - $this->db->rollback(); - return -1; - } - } - - - /** - * Load an object from its id and create a new one in database - * @param fromid Id of object to clone - * @param invertdetail Reverse sign of amounts for lines - * @param socid Id of thirdparty - * @return int New id of clone - */ - function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) - { - global $conf,$user,$langs; - - $error=0; - - $object=new Commande($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - $objFrom = $object; - - // Change socid if needed - if (! empty($socid) && $socid != $object->socid) - { - $objsoc = new Societe($this->db); - - if ($objsoc->fetch($socid)>0) - { - $object->socid = $objsoc->id; - $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); - $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $object->fk_project = ''; - $object->fk_delivery_address = ''; - } - - // TODO Change product price if multi-prices - } - - $object->id=0; - $object->statut=0; - - // Clear fields - $object->user_author_id = $user->id; - $object->user_valid = ''; - $object->date_creation = ''; - $object->date_validation = ''; - $object->ref_client = ''; - - // Create clone - $result=$object->create($user); - - // Other options - if ($result < 0) - { - $this->error=$object->error; - $error++; - } - - if (! $error) - { - // Hook of thirdparty module - if (is_object($hookmanager)) - { - $parameters=array('objFrom'=>$objFrom); - $reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) $error++; - } - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('ORDER_CLONE',$object,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - // End - if (! $error) - { - $this->db->commit(); - return $object->id; - } - else - { - $this->db->rollback(); - return -1; - } - } - - - /** - * Load an object from a proposal and create a new order into database - * @param object Object source - * @return int <0 if KO, 0 if nothing done, 1 if OK - */ - function createFromProposal($object,$hookmanager=false) - { - global $conf,$user,$langs; - - $error=0; - - // Signed proposal - if ($object->statut == 2) - { - $this->date_commande = dol_now(); - $this->source = 0; - - for ($i = 0 ; $i < sizeof($object->lines) ; $i++) - { - $line = new OrderLine($this->db); - - $line->libelle = $object->lines[$i]->libelle; - $line->desc = $object->lines[$i]->desc; - $line->price = $object->lines[$i]->price; - $line->subprice = $object->lines[$i]->subprice; - $line->tva_tx = $object->lines[$i]->tva_tx; - $line->localtax1_tx = $object->lines[$i]->localtax1_tx; - $line->localtax2_tx = $object->lines[$i]->localtax2_tx; - $line->qty = $object->lines[$i]->qty; - $line->fk_remise_except = $object->lines[$i]->fk_remise_except; - $line->remise_percent = $object->lines[$i]->remise_percent; - $line->fk_product = $object->lines[$i]->fk_product; - $line->info_bits = $object->lines[$i]->info_bits; - $line->product_type = $object->lines[$i]->product_type; - $line->rang = $object->lines[$i]->rang; - $line->special_code = $object->lines[$i]->special_code; - $line->fk_parent_line = $object->lines[$i]->fk_parent_line; - - $this->lines[$i] = $line; - } - - $this->socid = $object->socid; - $this->fk_project = $object->fk_project; - $this->cond_reglement_id = $object->cond_reglement_id; - $this->mode_reglement_id = $object->mode_reglement_id; - $this->availability_id = $object->availability_id; - $this->demand_reason_id = $object->demand_reason_id; - $this->date_livraison = $object->date_livraison; - $this->fk_delivery_address = $object->fk_delivery_address; - $this->contact_id = $object->contactid; - $this->ref_client = $object->ref_client; - $this->note = $object->note; - $this->note_public = $object->note_public; - - $this->origin = $object->element; - $this->origin_id = $object->id; - - $ret = $this->create($user); - - if ($ret > 0) - { - // Hook of thirdparty module - if (is_object($hookmanager)) - { - $parameters=array('objFrom'=>$object); - $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) $error++; - } - - if (! $error) - { - // Ne pas passer par la commande provisoire - if ($conf->global->COMMANDE_VALID_AFTER_CLOSE_PROPAL == 1) - { - $this->fetch($ret); - $this->valid($user); - } - return 1; - } - else return -1; - } - else return -1; - } - else return 0; - } - - - /** - * Add an order line into database (linked to product/service or not) - * @param commandeid Id of line - * @param desc Description of line - * @param pu_ht Unit price (without tax) - * @param qty Quantite - * @param txtva Taux de tva force, sinon -1 - * @param txlocaltax1 Local tax 1 rate - * @param txlocaltax2 Local tax 2 rate - * @param fk_product Id du produit/service predefini - * @param remise_percent Pourcentage de remise de la ligne - * @param info_bits Bits de type de lignes - * @param fk_remise_except Id remise - * @param price_base_type HT or TTC - * @param pu_ttc Prix unitaire TTC - * @param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * @param type Type of line (0=product, 1=service) - * @param rang Position of line - * @return int >0 if OK, <0 if KO - * @see add_product - * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel - * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini - * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) - * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) - */ - function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0) - { - dol_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type", LOG_DEBUG); - - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); - - // Clean parameters - if (empty($remise_percent)) $remise_percent=0; - if (empty($qty)) $qty=0; - if (empty($info_bits)) $info_bits=0; - if (empty($rang)) $rang=0; - if (empty($txtva)) $txtva=0; - if (empty($txlocaltax1)) $txlocaltax1=0; - if (empty($txlocaltax2)) $txlocaltax2=0; - if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=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 ($type < 0) return -1; - - if ($this->statut == 0) - { - $this->db->begin(); - - // 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]; - - // Rang to use - $rangtouse = $rang; - if ($rangtouse == -1) - { - $rangmax = $this->line_max($fk_parent_line); - $rangtouse = $rangmax + 1; - } - - // TODO A virer - // Anciens indicateurs: $price, $remise (a ne plus utiliser) - $price = $pu; - $remise = 0; - if ($remise_percent > 0) - { - $remise = round(($pu * $remise_percent / 100), 2); - $price = $pu - $remise; - } - - // Insert line - $this->line=new OrderLine($this->db); - - $this->line->fk_commande=$commandeid; - $this->line->desc=$desc; - $this->line->qty=$qty; - $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$txlocaltax1; - $this->line->localtax2_tx=$txlocaltax2; - $this->line->fk_product=$fk_product; - $this->line->fk_remise_except=$fk_remise_except; - $this->line->remise_percent=$remise_percent; - $this->line->subprice=$pu_ht; - $this->line->rang=$rangtouse; - $this->line->info_bits=$info_bits; - $this->line->total_ht=$total_ht; - $this->line->total_tva=$total_tva; - $this->line->total_localtax1=$total_localtax1; - $this->line->total_localtax2=$total_localtax2; - $this->line->total_ttc=$total_ttc; - $this->line->product_type=$type; - $this->line->special_code=$special_code; - $this->line->fk_parent_line=$fk_parent_line; - - $this->line->date_start=$date_start; - $this->line->date_end=$date_end; - - // TODO Ne plus utiliser - $this->line->price=$price; - $this->line->remise=$remise; - - $result=$this->line->insert(); - if ($result > 0) - { - // Reorder if child line - if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); - - // Mise a jour informations denormalisees au niveau de la commande meme - $this->id=$commandeid; // TODO A virer - $result=$this->update_price(1); - if ($result > 0) - { - $this->db->commit(); - return $this->line->rowid; - } - else - { - $this->db->rollback(); - return -1; - } - } - else - { - $this->error=$this->line->error; - dol_syslog("Commande::addline error=".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } - } - - - /** - * Add line into array - * $this->client doit etre charge - * @param idproduct Id du produit a ajouter - * @param qty Quantite - * @param remise_percent Remise relative effectuee sur le produit - * @param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * @return void - * TODO Remplacer les appels a cette fonction par generation objet Ligne - * insere dans tableau $this->products - */ - function add_product($idproduct, $qty, $remise_percent=0, $date_start='', $date_end='') - { - global $conf, $mysoc; - - if (! $qty) $qty = 1; - - if ($idproduct > 0) - { - $prod=new Product($this->db); - $prod->fetch($idproduct); - - $tva_tx = get_default_tva($mysoc,$this->client,$prod->id); - $localtax1_tx=get_localtax($tva_tx,1,$this->client); - $localtax2_tx=get_localtax($tva_tx,2,$this->client); - // multiprix - if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level) - $price = $prod->multiprices[$this->client->price_level]; - else - $price = $prod->price; - - $line=new OrderLine($this->db); - - $line->fk_product=$idproduct; - $line->desc=$prod->description; - $line->qty=$qty; - $line->subprice=$price; - $line->remise_percent=$remise_percent; - $line->tva_tx=$tva_tx; - $line->localtax1_tx=$localtax1_tx; - $line->localtax2_tx=$localtax2_tx; - $line->ref=$prod->ref; - $line->libelle=$prod->libelle; - $line->product_desc=$prod->description; - - // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Save the start and end date of the line in the object - if ($date_start) { $line->date_start = $date_start; } - if ($date_end) { $line->date_end = $date_end; } - - $this->lines[] = $line; - - /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE - if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) - { - $prod = new Product($this->db); - $prod->fetch($idproduct); - $prod -> get_sousproduits_arbo (); - $prods_arbo = $prod->get_each_prod(); - if(sizeof($prods_arbo) > 0) - { - foreach($prods_arbo as $key => $value) - { - // print "id : ".$value[1].' :qty: '.$value[0].'
'; - if(! in_array($value[1],$this->products)) - $this->add_product($value[1], $value[0]); - - } - } - - } - **/ - } - } - - - /** - * Get object and lines from database - * @param id Id of object to load - * @param ref Ref of object - * @param ref_ext External reference of object - * @param ref_int Internal reference of other object - * @return int >0 if OK, <0 if KO - */ - function fetch($id, $ref='', $ref_ext='', $ref_int='') - { - global $conf; - - // Check parameters - if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; - - $sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut'; - $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason'; - $sql.= ', c.date_commande'; - $sql.= ', c.date_livraison'; - $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee'; - $sql.= ', c.note, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison'; - $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; - $sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc'; - $sql.= ', ca.code as availability_code'; - $sql.= ', dr.code as demand_reason_code'; - $sql.= ', el.fk_source'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commande 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_availability as ca ON (c.fk_availability = ca.rowid)'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_demand_reason = ca.rowid)'; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = c.rowid AND el.targettype = '".$this->element."'"; - $sql.= " WHERE c.entity = ".$conf->entity; - if ($id) $sql.= " AND c.rowid=".$id; - if ($ref) $sql.= " AND c.ref='".$this->db->escape($ref)."'"; - if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; - if ($ref_int) $sql.= " AND c.ref_int='".$this->db->escape($ref_int)."'"; - - dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); - $result = $this->db->query($sql) ; - if ($result) - { - $obj = $this->db->fetch_object($result); - if ($obj) - { - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->ref_client = $obj->ref_client; - $this->ref_ext = $obj->ref_ext; - $this->ref_int = $obj->ref_int; - $this->socid = $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->total_tva; - $this->total_localtax1 = $obj->total_localtax1; - $this->total_localtax2 = $obj->total_localtax2; - $this->total_ttc = $obj->total_ttc; - $this->date = $this->db->jdate($obj->date_commande); - $this->date_commande = $this->db->jdate($obj->date_commande); - $this->remise = $obj->remise; - $this->remise_percent = $obj->remise_percent; - $this->remise_absolue = $obj->remise_absolue; - $this->source = $obj->source; - $this->facturee = $obj->facturee; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - $this->fk_project = $obj->fk_projet; - $this->modelpdf = $obj->model_pdf; - $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->mode_reglement_code = $obj->mode_reglement_code; - $this->mode_reglement = $obj->mode_reglement_libelle; - $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->availability_id = $obj->fk_availability; - $this->availability_code = $obj->availability_code; - $this->demand_reason_id = $obj->fk_demand_reason; - $this->demand_reason_code = $obj->demand_reason_code; - $this->date_livraison = $this->db->jdate($obj->date_livraison); - $this->fk_delivery_address = $obj->fk_adresse_livraison; - $this->propale_id = $obj->fk_source; - - $this->lines = array(); - - if ($this->statut == 0) $this->brouillon = 1; - - $this->db->free(); - - if ($this->propale_id) - { - $sqlp = "SELECT ref"; - $sqlp.= " FROM ".MAIN_DB_PREFIX."propal"; - $sqlp.= " WHERE rowid = ".$this->propale_id; - - $resqlprop = $this->db->query($sqlp); - - if ($resqlprop) - { - $objp = $this->db->fetch_object($resqlprop); - $this->propale_ref = $objp->ref; - $this->db->free($resqlprop); - } - } - - /* - * Lignes - */ - $result=$this->fetch_lines(); - if ($result < 0) - { - return -3; - } - return 1; - } - else - { - dol_syslog('Commande::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); - $this->error='Order with id '.$rowid.' not found sql='.$sql; - return -2; - } - } - else - { - dol_syslog('Commande::Fetch Error rowid='.$rowid.' Erreur dans fetch de la commande'); - $this->error=$this->db->error(); - return -1; - } - } - - - /** - * Ajout d'une ligne remise fixe dans la commande, en base - * @param idremise Id de la remise fixe - * @return int >0 si ok, <0 si ko - */ - function insert_discount($idremise) - { - global $langs; - - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); - include_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'); - - $this->db->begin(); - - $remise=new DiscountAbsolute($this->db); - $result=$remise->fetch($idremise); - - if ($result > 0) - { - if ($remise->fk_facture) // Protection against multiple submission - { - $this->error=$langs->trans("ErrorDiscountAlreadyUsed"); - $this->db->rollback(); - return -5; - } - - $line = new OrderLine($this->db); - - $line->fk_commande=$this->id; - $line->fk_remise_except=$remise->id; - $line->desc=$remise->description; // Description ligne - $line->tva_tx=$remise->tva_tx; - $line->subprice=-$remise->amount_ht; - $line->price=-$remise->amount_ht; - $line->fk_product=0; // Id produit predefini - $line->qty=1; - $line->remise=0; - $line->remise_percent=0; - $line->rang=-1; - $line->info_bits=2; - - $line->total_ht = -$remise->amount_ht; - $line->total_tva = -$remise->amount_tva; - $line->total_ttc = -$remise->amount_ttc; - - $result=$line->insert(); - if ($result > 0) - { - $result=$this->update_price(1); - if ($result > 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - else - { - $this->error=$line->error; - $this->db->rollback(); - return -2; - } - } - else - { - $this->db->rollback(); - return -2; - } - } - - - /** - * Load array lines - * @param only_product Return only physical products - * @return int <0 if KO, >0 if OK - */ - function fetch_lines($only_product=0) - { - $this->lines=array(); - - $sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,'; - $sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits, l.special_code,'; - $sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,'; - $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)'; - $sql.= ' WHERE l.fk_commande = '.$this->id; - if ($only_product) $sql .= ' AND p.fk_product_type = 0'; - $sql .= ' ORDER BY l.rang'; - - dol_syslog("Commande::fetch_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 OrderLine($this->db); - - $line->rowid = $objp->rowid; // \deprecated - $line->id = $objp->rowid; - $line->fk_commande = $objp->fk_commande; - $line->commande_id = $objp->fk_commande; // \deprecated - $line->desc = $objp->description; // Description ligne - $line->product_type = $objp->product_type; - $line->qty = $objp->qty; - $line->tva_tx = $objp->tva_tx; - $line->localtax1_tx = $objp->localtax1_tx; - $line->localtax2_tx = $objp->localtax2_tx; - $line->total_ht = $objp->total_ht; - $line->total_ttc = $objp->total_ttc; - $line->total_tva = $objp->total_tva; - $line->total_localtax1 = $objp->total_localtax1; - $line->total_localtax2 = $objp->total_localtax2; - $line->subprice = $objp->subprice; - $line->fk_remise_except = $objp->fk_remise_except; - $line->remise_percent = $objp->remise_percent; - $line->price = $objp->price; - $line->fk_product = $objp->fk_product; - $line->marge_tx = $objp->marge_tx; - $line->marque_tx = $objp->marque_tx; - $line->rang = $objp->rang; - $line->info_bits = $objp->info_bits; - $line->special_code = $objp->special_code; - $line->fk_parent_line = $objp->fk_parent_line; - - $line->ref = $objp->product_ref; // TODO deprecated - $line->product_ref = $objp->product_ref; - $line->libelle = $objp->product_label; // TODO deprecated - $line->product_label = $objp->product_label; - $line->product_desc = $objp->product_desc; // Description produit - $line->fk_product_type = $objp->fk_product_type; // Produit ou service - - $line->date_start = $this->db->jdate($objp->date_start); - $line->date_end = $this->db->jdate($objp->date_end); - - $this->lines[$i] = $line; - - $i++; - } - $this->db->free($result); - - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog('Commande::fetch_lines: Error '.$this->error, LOG_ERR); - return -3; - } - } - - - /** - * Return number of line with type product. - * @return int <0 if KO, Nbr of product lines if OK - */ - function getNbOfProductsLines() - { - $nb=0; - foreach($this->lines as $line) - { - if ($line->fk_product_type == 0) $nb++; - } - return $nb; - } - - /** - * Load array this->expeditions of nb of products sent by line in order - * @param filtre_statut Filter on status - * @return int <0 if KO, Nb of lines found if OK - * TODO deprecated, move to Shipping class - */ - function loadExpeditions($filtre_statut=-1) - { - $num=0; - $this->expeditions = array(); - - $sql = 'SELECT cd.rowid, cd.fk_product,'; - $sql.= ' sum(ed.qty) as qty'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed,'; - if ($filtre_statut >= 0) $sql.= ' '.MAIN_DB_PREFIX.'expedition as e,'; - $sql.= ' '.MAIN_DB_PREFIX.'commandedet as cd'; - $sql.= ' WHERE'; - if ($filtre_statut >= 0) $sql.= ' ed.fk_expedition = e.rowid AND'; - $sql.= ' ed.fk_origin_line = cd.rowid'; - $sql.= ' AND cd.fk_commande =' .$this->id; - if ($filtre_statut >= 0) $sql.=' AND e.fk_statut = '.$filtre_statut; - $sql.= ' GROUP BY cd.rowid, cd.fk_product'; - //print $sql; - - dol_syslog("Commande::loadExpeditions sql=".$sql,LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($result); - $this->expeditions[$obj->rowid] = $obj->qty; - $i++; - } - $this->db->free(); - return $num; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("Commande::loadExpeditions ".$this->error,LOG_ERR); - return -1; - } - - } - - /** - * Renvoie un tableau avec nombre de lignes d'expeditions - * TODO deprecated, move to Shipping class - */ - function nb_expedition() - { - $sql = 'SELECT count(*)'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'expedition as e'; - $sql.= ', '.MAIN_DB_PREFIX.'element_element as el'; - $sql.= ' WHERE el.fk_source = '.$this->id; - $sql.= " AND el.fk_target = e.rowid"; - $sql.= " AND el.targettype = 'shipping'"; - - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - return $row[0]; - } - else dol_print_error($this->db); - } - - /** - * Renvoie un tableau avec les livraisons par ligne - * @param filtre_statut Filtre sur statut - * @return int 0 si OK, <0 si KO - * TODO deprecated, move to Shipping class - */ - function livraison_array($filtre_statut=-1) - { - $delivery = new Livraison($this->db); - $deliveryArray = $delivery->livraison_array($filtre_statut); - return $deliveryArray; - } - - /** - * Renvoie un tableau avec les stocks restant par produit - * @param filtre_statut Filtre sur statut - * @return int 0 si OK, <0 si KO - * TODO FONCTION NON FINIE A FINIR - */ - function stock_array($filtre_statut=-1) - { - $this->stocks = array(); - - // Tableau des id de produit de la commande - - - // Recherche total en stock pour chaque produit - if (sizeof($array_of_product)) - { - $sql = "SELECT fk_product, sum(ps.reel) as total"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql.= " WHERE ps.fk_product in (".join(',',$array_of_product).")"; - $sql.= ' GROUP BY fk_product '; - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($result); - $this->stocks[$obj->fk_product] = $obj->total; - $i++; - } - $this->db->free(); - } - } - return 0; - } - - /** - * Delete an order line - * @param lineid Id of line to delete - * @return int >0 if OK, 0 if nothing to do, <0 if KO - */ - function deleteline($lineid) - { - global $user; - - if ($this->statut == 0) - { - $this->db->begin(); - - $sql = "SELECT fk_product, qty"; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE rowid = ".$lineid; - - $result = $this->db->query($sql); - if ($result) - { - $obj = $this->db->fetch_object($result); - - if ($obj) - { - $product = new Product($this->db); - $product->id = $obj->fk_product; - - // Delete line - $line = new OrderLine($this->db); - - // For triggers - $line->fetch($lineid); - - if ($line->delete() > 0) - { - $result=$this->update_price(1); - - if ($result > 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(); - return -1; - } - } - else - { - $this->db->rollback(); - return 0; - } - } - else - { - $this->db->rollback(); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - return -1; - } - } - - /** - * Applique une remise relative - * @param user User qui positionne la remise - * @param remise - * @return int <0 if KO, >0 if OK - */ - function set_remise($user, $remise) - { - $remise=trim($remise)?trim($remise):0; - - if ($user->rights->commande->creer) - { - $remise=price2num($remise); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET remise_percent = '.$remise; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; - - if ($this->db->query($sql)) - { - $this->remise_percent = $remise; - $this->update_price(1); - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - } - - - /** - * Applique une remise absolue - * @param user User qui positionne la remise - * @param remise - * @return int <0 if KO, >0 if OK - */ - function set_remise_absolue($user, $remise) - { - $remise=trim($remise)?trim($remise):0; - - if ($user->rights->commande->creer) - { - $remise=price2num($remise); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET remise_absolue = '.$remise; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; - - dol_syslog("Commande::set_remise_absolue sql=$sql"); - - if ($this->db->query($sql)) - { - $this->remise_absolue = $remise; - $this->update_price(1); - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - } - - - /** - * Set the order date - * @param user Object user making change - * @param date Date - * @return int <0 if KO, >0 if OK - */ - function set_date($user, $date) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null'); - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - dol_syslog("Commande::set_date sql=$sql",LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->date = $date; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_date ".$this->error,LOG_ERR); - return -1; - } - } - else - { - return -2; - } - } - - /** - * Set the planned delivery date - * @param user Objet utilisateur qui modifie - * @param date_livraison Date de livraison - * @return int <0 si ko, >0 si ok - */ - function set_date_livraison($user, $date_livraison) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); - $sql.= " WHERE rowid = ".$this->id; - - dol_syslog("Commande::set_date_livraison sql=".$sql,LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $this->date_livraison = $date_livraison; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_date_livraison ".$this->error,LOG_ERR); - return -1; - } - } - else - { - return -2; - } - } - - /** - * Set address - * @param user Object user making change - * @param fk_address Adress of delivery - * @return int <0 ig KO, >0 if Ok - */ - function set_adresse_livraison($user, $fk_address) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_adresse_livraison = '".$fk_address."'"; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - if ($this->db->query($sql) ) - { - $this->fk_delivery_address = $fk_address; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_adresse_livraison Erreur SQL"); - return -1; - } - } - } - - /** - * Set availability - * @param user Object user making change - * @param id If of availability delay - * @return int <0 if KO, >0 if OK - */ - function set_availability($user, $id) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; - $sql.= " SET fk_availability = '".$id."'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql)) - { - $this->fk_availability = $id; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_availability Erreur SQL"); - return -1; - } - } - } - - /** - * Set source of demand - * @param user Object user making change - * @param id Id of source - * @return int <0 if KO, >0 if OK - */ - function set_demand_reason($user, $id) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; - $sql.= " SET fk_demand_reason = '".$id."'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql)) - { - $this->fk_demand_reason = $id; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Commande::set_demand_reason Erreur SQL"); - return -1; - } - } - } - - /** - * \brief Return list of orders (eventuelly filtered on a user) into an array - * \param brouillon 0=non brouillon, 1=brouillon - * \param user Objet user de filtre - * \return int -1 if KO, array with result if OK - */ - function liste_array($brouillon=0, $user='') - { - global $conf; - - $ga = array(); - - $sql = "SELECT s.nom, s.rowid, c.rowid, c.ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; - $sql.= " WHERE c.entity = ".$conf->entity; - $sql.= " AND c.fk_soc = s.rowid"; - if ($brouillon) $sql.= " AND c.fk_statut = 0"; - if ($user) $sql.= " AND c.fk_user_author <> ".$user->id; - $sql .= " ORDER BY c.date_commande DESC"; - - $result=$this->db->query($sql); - if ($result) - { - $numc = $this->db->num_rows($result); - if ($numc) - { - $i = 0; - while ($i < $numc) - { - $obj = $this->db->fetch_object($result); - - $ga[$obj->rowid] = $obj->ref; - $i++; - } - } - return $ga; - } - else - { - dol_print_error($this->db); - return -1; - } - } - - /** - * Change les conditions de reglement de la commande - * @param cond_reglement_id Id de la nouvelle condition de reglement - * @return int >0 if OK, <0 if KO - */ - function cond_reglement($cond_reglement_id) - { - dol_syslog('Commande::cond_reglement('.$cond_reglement_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $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('Commande::cond_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('Commande::cond_reglement, etat commande incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - - /** - * \brief Change le mode de reglement - * \param mode Id du nouveau mode - * \return int >0 si ok, <0 si ko - */ - function mode_reglement($mode_reglement_id) - { - dol_syslog('Commande::mode_reglement('.$mode_reglement_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $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('Commande::mode_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('Commande::mode_reglement, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - /** - * Change le delai de livraison - * @param availability_id Id du nouveau mode - * @return int >0 if OK, <0 if KO - */ - function availability($availability_id) - { - dol_syslog('Commande::availability('.$availability_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql .= ' SET fk_availability = '.$availability_id; - $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) - { - $this->availability_id = $availability_id; - return 1; - } - else - { - dol_syslog('Commande::availability Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('Commande::availability, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - /** - * \brief Change la source de la demande - * \param mode Id du nouveau mode - * \return int >0 si ok, <0 si ko - */ - function demand_reason($demand_reason_id) - { - dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); - if ($this->statut >= 0) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql .= ' SET fk_demand_reason = '.$demand_reason_id; - $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) - { - $this->demand_reason_id = $demand_reason_id; - return 1; - } - else - { - dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; - } - } - else - { - dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; - return -2; - } - } - - /** - * \brief Set customer ref - * \param user User that make change - * \param ref_client Customer ref - * \return int <0 if KO, >0 if OK - */ - function set_ref_client($user, $ref_client) - { - if ($user->rights->commande->creer) - { - dol_syslog('Commande::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET'; - $sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); - $sql.= ' WHERE rowid = '.$this->id; - - if ($this->db->query($sql) ) - { - $this->ref_client = $ref_client; - return 1; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog('Commande::set_ref_client Erreur '.$this->error.' - '.$sql, LOG_ERR); - return -2; - } - } - else - { - return -1; - } - } - - - /** - * \brief Classe la commande comme facturee - * \return int <0 si ko, >0 si ok - */ - function classer_facturee() - { - global $conf; - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; - $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;'; - if ($this->db->query($sql) ) - { - if (($conf->global->PROPALE_CLASSIFIED_INVOICED_WITH_ORDER == 1) && $this->propale_id) - { - $propal = new Propal($this->db); - $propal->fetch($this->propale_id); - $propal->classer_facturee(); - } - return 1; - } - else - { - dol_print_error($this->db); - return -1; - } - } - - - /** - * Update a line in database - * - * @param rowid Id of line to update - * @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 txlocaltax1 Local tax 1 rate - * @param txlocaltax2 Local tax 2 rate - * @param price_base_type HT or TTC - * @param info_bits Miscellaneous informations on line - * @param date_start Start date of the line - * @param date_end End date of the line - * @param type Type of line (0=product, 1=service) - * @return int < 0 if KO, > 0 if OK - */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $txlocaltax1=0,$txlocaltax2=0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0) - { - global $conf; - - dol_syslog("CustomerOrder::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $date_start, $date_end, $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); - $pu = price2num($pu); - $txtva=price2num($txtva); - $txlocaltax1=price2num($txtlocaltax1); - $txlocaltax2=price2num($txtlocaltax2); - - // 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) - $price = $pu; - $subprice = $pu; - $remise = 0; - if ($remise_percent > 0) - { - $remise = round(($pu * $remise_percent / 100),2); - $price = ($pu - $remise); - } - - // Update line - $this->line=new OrderLine($this->db); - - // Stock previous line records - $staticline=new OrderLine($this->db); - $staticline->fetch($rowid); - $this->line->oldline = $staticline; - - $this->line->rowid=$rowid; - $this->line->desc=$desc; - $this->line->qty=$qty; - $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$txlocaltax1; - $this->line->localtax2_tx=$txlocaltax2; - $this->line->remise_percent=$remise_percent; - $this->line->subprice=$subprice; - $this->line->info_bits=$info_bits; - $this->line->total_ht=$total_ht; - $this->line->total_tva=$total_tva; - $this->line->total_localtax1=$total_localtax1; - $this->line->total_localtax2=$total_localtax2; - $this->line->total_ttc=$total_ttc; - $this->line->date_start=$date_start; - $this->line->date_end=$date_end; - $this->line->product_type=$type; - $this->line->fk_parent_line=$fk_parent_line; - $this->line->skip_update_total=$skip_update_total; - - // TODO deprecated - $this->line->price=$price; - $this->line->remise=$remise; - - $result=$this->line->update(); - if ($result > 0) - { - // Mise a jour info denormalisees - $this->update_price(1); - - $this->db->commit(); - return $result; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - dol_syslog("CustomerOrder::UpdateLine Error=".$this->error, LOG_ERR); - return -1; - } - } - else - { - $this->error="CustomerOrder::Updateline Order status makes operation forbidden"; - return -2; - } - } - - - /** - * Delete the customer order - * @param user User object - * @return int <=0 if KO, >0 if OK - */ - function delete($user) - { - global $conf, $langs; - require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); - - $err = 0; - - $this->db->begin(); - - // Delete order details - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id; - dol_syslog("Commande::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $err++; - } - - // Delete order - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; - dol_syslog("Commande::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $err++; - } - - // Delete linked object - // TODO deplacer dans le common - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - dol_syslog("Commande::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $err++; - } - - // Delete linked contacts - $res = $this->delete_linked_contact(); - if ($res < 0) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $err++; - } - - // On efface le repertoire de pdf provisoire - $comref = dol_sanitizeFileName($this->ref); - if ($conf->commande->dir_output) - { - $dir = $conf->commande->dir_output . "/" . $comref ; - $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; - if (file_exists($file)) - { - commande_delete_preview($this->db, $this->id, $this->ref); - - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - $this->db->rollback(); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - $this->db->rollback(); - return 0; - } - } - } - - 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_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - - - /** - * 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 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 IN (1,2,3) AND c.facture = 0"; - 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->client->warning_delay)) $this->nbtodolate++; - } - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - - /** - * \brief Return source label of order - * \return string Label - */ - function getLabelSource() - { - global $langs; - - $label=$langs->trans('OrderSource'.$this->source); - - if ($label == 'OrderSource') return ''; - return $label; - } - - /** - * \brief Retourne le libelle du statut de la commande - * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * \return string Libelle - */ - function getLibStatut($mode) - { - return $this->LibStatut($this->statut,$this->facturee,$mode); - } - - /** - * Renvoi le libelle d'un statut donne - * @param statut Id statut - * @param facturee Si facturee - * @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @return string Label of status - */ - function LibStatut($statut,$facturee,$mode) - { - global $langs; - //print 'x'.$statut.'-'.$facturee; - if ($mode == 0) - { - if ($statut==-1) return $langs->trans('StatusOrderCanceled'); - if ($statut==0) return $langs->trans('StatusOrderDraft'); - if ($statut==1) return $langs->trans('StatusOrderValidated'); - if ($statut==2) return $langs->trans('StatusOrderSentShort'); - if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBill'); - if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessed'); - } - if ($mode == 1) - { - if ($statut==-1) return $langs->trans('StatusOrderCanceledShort'); - if ($statut==0) return $langs->trans('StatusOrderDraftShort'); - if ($statut==1) return $langs->trans('StatusOrderValidatedShort'); - if ($statut==2) return $langs->trans('StatusOrderSentShort'); - if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBillShort'); - if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessed'); - } - if ($mode == 2) - { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceledShort'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraftShort'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidatedShort'); - if ($statut==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3').' '.$langs->trans('StatusOrderSentShort'); - if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort'); - if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort'); - } - if ($mode == 3) - { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); - if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3'); - if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7'); - if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6'); - } - if ($mode == 4) - { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceled'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraft'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidated'); - if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3').' '.$langs->trans('StatusOrderOnProcess'); - if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill'); - if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed'); - } - if ($mode == 5) - { - if ($statut==-1) return $langs->trans('StatusOrderCanceledShort').' '.img_picto($langs->trans('StatusOrderCanceled'),'statut5'); - if ($statut==0) return $langs->trans('StatusOrderDraftShort').' '.img_picto($langs->trans('StatusOrderDraft'),'statut0'); - if ($statut==1) return $langs->trans('StatusOrderValidatedShort').' '.img_picto($langs->trans('StatusOrderValidated'),'statut1'); - if ($statut==2) return $langs->trans('StatusOrderSentShort').' '.img_picto($langs->trans('StatusOrderOnProcess'),'statut3'); - if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBillShort').' '.img_picto($langs->trans('StatusOrderToBill'),'statut7'); - if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessedShort').' '.img_picto($langs->trans('StatusOrderProcessed'),'statut6'); - } - } - - - /** - * Return clicable link of object (with eventually picto) - * @param withpicto Add picto into link - * @param option Where point the link - * @param max Max length to show - * @param short Use short labels - * @return string String with URL - */ - function getNomUrl($withpicto=0,$option=0,$max=0,$short=0) - { - global $conf, $langs; - - $result=''; - - if ($conf->expedition->enabled && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; - else $url = DOL_URL_ROOT.'/commande/fiche.php?id='.$this->id; - - if ($short) return $url; - - $linkstart = ''; - $linkend=''; - - $picto='order'; - $label=$langs->trans("ShowOrder").': '.$this->ref; - - if ($withpicto) $result.=($linkstart.img_object($label,$picto).$linkend); - if ($withpicto && $withpicto != 2) $result.=' '; - $result.=$linkstart.$this->ref.$linkend; - return $result; - } - - - /** - * \brief Charge les informations d'ordre info dans l'objet commande - * \param id Id de la commande a charger - */ - function info($id) - { - $sql = 'SELECT c.rowid, date_creation as datec, tms as datem,'; - $sql.= ' date_valid as datev,'; - $sql.= ' date_cloture as datecloture,'; - $sql.= ' fk_user_author, fk_user_valid, fk_user_cloture'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; - $sql.= ' WHERE c.rowid = '.$id; - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - if ($obj->fk_user_author) - { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; - } - - if ($obj->fk_user_valid) - { - $vuser = new User($this->db); - $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; - } - - if ($obj->fk_user_cloture) - { - $cluser = new User($this->db); - $cluser->fetch($obj->fk_user_cloture); - $this->user_cloture = $cluser; - } - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datem); - $this->date_validation = $this->db->jdate($obj->datev); - $this->date_cloture = $this->db->jdate($obj->datecloture); - } - - $this->db->free($result); - - } - else - { - dol_print_error($this->db); - } - } - - - /** - * Initialise an example of instance with random values - * Used to build previews or test instances - */ - function initAsSpecimen() - { - global $user,$langs,$conf; - - dol_syslog(get_class($this)."::initAsSpecimen"); - - // 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 = time(); - $this->date_lim_reglement=$this->date+3600*24*30; - $this->cond_reglement_code = 'RECEP'; - $this->mode_reglement_code = 'CHQ'; - $this->availability_code = 'DSP'; - $this->demand_reason_code = 'SRC_00'; - $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 OrderLine($this->db); - - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->qty=1; - $line->subprice=100; - $line->price=100; - $line->tva_tx=19.6; - 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; - } - $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++; - } - } - - - /** - * Charge indicateurs this->nb de tableau de bord - * - * @return int <0 si ko, >0 si ok - */ - function load_state_board() - { - global $conf, $user; - - $this->nb=array(); - $clause = "WHERE"; - - $sql = "SELECT count(co.rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande as co"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$user->societe_id) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; - $sql.= " WHERE sc.fk_user = " .$user->id; - $clause = "AND"; - } - $sql.= " ".$clause." co.entity = ".$conf->entity; - - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj=$this->db->fetch_object($resql)) - { - $this->nb["orders"]=$obj->nb; - } - return 1; - } - else - { - dol_print_error($this->db); - $this->error=$this->db->error(); - return -1; - } - } - - /** - * Return an array of order lines - */ - function getLinesArray() - { - $lines = array(); - - $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, '; - $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,l.rang,l.special_code,'; - $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; - $sql.= ' l.date_start,'; - $sql.= ' l.date_end,'; - $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, '; - $sql.= ' p.description as product_desc'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet 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.rang ASC, l.rowid'; - - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $this->lines[$i]->id = $obj->rowid; - $this->lines[$i]->description = $obj->description; - $this->lines[$i]->fk_product = $obj->fk_product; - $this->lines[$i]->ref = $obj->ref; - $this->lines[$i]->product_label = $obj->product_label; - $this->lines[$i]->product_desc = $obj->product_desc; - $this->lines[$i]->fk_product_type = $obj->fk_product_type; - $this->lines[$i]->product_type = $obj->product_type; - $this->lines[$i]->qty = $obj->qty; - $this->lines[$i]->subprice = $obj->subprice; - $this->lines[$i]->fk_remise_except = $obj->fk_remise_except; - $this->lines[$i]->remise_percent = $obj->remise_percent; - $this->lines[$i]->tva_tx = $obj->tva_tx; - $this->lines[$i]->info_bits = $obj->info_bits; - $this->lines[$i]->total_ht = $obj->total_ht; - $this->lines[$i]->total_tva = $obj->total_tva; - $this->lines[$i]->total_ttc = $obj->total_ttc; - $this->lines[$i]->special_code = $obj->special_code; - $this->lines[$i]->rang = $obj->rang; - $this->lines[$i]->date_start = $this->db->jdate($obj->date_start); - $this->lines[$i]->date_end = $this->db->jdate($obj->date_end); - - $i++; - } - - $this->db->free($resql); - - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("Error sql=$sql, error=".$this->error,LOG_ERR); - return -1; - } - } + 0, + $this->lines[$i]->date_start, + $this->lines[$i]->date_end, + $this->lines[$i]->product_type, + $this->lines[$i]->rang, + $this->lines[$i]->special_code, + $fk_parent_line + ); + if ($result < 0) + { + $this->error=$this->db->lasterror(); + dol_print_error($this->db); + $this->db->rollback(); + return -1; + } + // Defined the new fk_parent_line + if ($result > 0 && $this->lines[$i]->product_type == 9) { + $fk_parent_line = $result; + } + } + + // Mise a jour ref + $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; + if ($this->db->query($sql)) + { + if ($this->id) + { + $this->ref="(PROV".$this->id.")"; + + // Add linked object + if ($this->origin && $this->origin_id) + { + $ret = $this->add_object_linked(); + if (! $ret) dol_print_error($this->db); + } + + // TODO mutualiser + if ($this->origin == 'propal' && $this->origin_id) + { + // On recupere les differents contact interne et externe + $prop = new Propal($this->db, $this->socid, $this->origin_id); + + // On recupere le commercial suivi propale + $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); + + if ($this->userid) + { + //On passe le commercial suivi propale en commercial suivi commande + $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); + } + + // On recupere le contact client suivi propale + $this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); + + if ($this->contactid) + { + //On passe le contact client suivi propale en contact client suivi commande + $this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); + } + } + } + + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + } + else + { + dol_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * @param int $invertdetail Reverse sign of amounts for lines + * @param int $socid Id of thirdparty + * @param HookManager $hookmanager Hook manager instance + * @return int New id of clone + */ + function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) + { + global $conf,$user,$langs; + + $error=0; + + $object=new Commande($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $objFrom = $object; + + // Change socid if needed + if (! empty($socid) && $socid != $object->socid) + { + $objsoc = new Societe($this->db); + + if ($objsoc->fetch($socid)>0) + { + $object->socid = $objsoc->id; + $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $object->fk_project = ''; + $object->fk_delivery_address = ''; + } + + // TODO Change product price if multi-prices + } + + $object->id=0; + $object->statut=0; + + // Clear fields + $object->user_author_id = $user->id; + $object->user_valid = ''; + $object->date_creation = ''; + $object->date_validation = ''; + $object->ref_client = ''; + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $parameters=array('objFrom'=>$objFrom); + $reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_CLONE',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Load an object from a proposal and create a new order into database + * + * @param Object $object Object source + * @param HookManager $hookmanager Hook manager instance + * @return int <0 if KO, 0 if nothing done, 1 if OK + */ + function createFromProposal($object,$hookmanager=false) + { + global $conf,$user,$langs; + + $error=0; + + // Signed proposal + if ($object->statut == 2) + { + $this->date_commande = dol_now(); + $this->source = 0; + + for ($i = 0 ; $i < sizeof($object->lines) ; $i++) + { + $line = new OrderLine($this->db); + + $line->libelle = $object->lines[$i]->libelle; + $line->desc = $object->lines[$i]->desc; + $line->price = $object->lines[$i]->price; + $line->subprice = $object->lines[$i]->subprice; + $line->tva_tx = $object->lines[$i]->tva_tx; + $line->localtax1_tx = $object->lines[$i]->localtax1_tx; + $line->localtax2_tx = $object->lines[$i]->localtax2_tx; + $line->qty = $object->lines[$i]->qty; + $line->fk_remise_except = $object->lines[$i]->fk_remise_except; + $line->remise_percent = $object->lines[$i]->remise_percent; + $line->fk_product = $object->lines[$i]->fk_product; + $line->info_bits = $object->lines[$i]->info_bits; + $line->product_type = $object->lines[$i]->product_type; + $line->rang = $object->lines[$i]->rang; + $line->special_code = $object->lines[$i]->special_code; + $line->fk_parent_line = $object->lines[$i]->fk_parent_line; + + $this->lines[$i] = $line; + } + + $this->socid = $object->socid; + $this->fk_project = $object->fk_project; + $this->cond_reglement_id = $object->cond_reglement_id; + $this->mode_reglement_id = $object->mode_reglement_id; + $this->availability_id = $object->availability_id; + $this->demand_reason_id = $object->demand_reason_id; + $this->date_livraison = $object->date_livraison; + $this->fk_delivery_address = $object->fk_delivery_address; + $this->contact_id = $object->contactid; + $this->ref_client = $object->ref_client; + $this->note = $object->note; + $this->note_public = $object->note_public; + + $this->origin = $object->element; + $this->origin_id = $object->id; + + $ret = $this->create($user); + + if ($ret > 0) + { + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $parameters=array('objFrom'=>$object); + $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } + + if (! $error) + { + // Ne pas passer par la commande provisoire + if ($conf->global->COMMANDE_VALID_AFTER_CLOSE_PROPAL == 1) + { + $this->fetch($ret); + $this->valid($user); + } + return 1; + } + else return -1; + } + else return -1; + } + else return 0; + } + + + /** + * Add an order line into database (linked to product/service or not) + * @param commandeid Id of line + * @param desc Description of line + * @param pu_ht Unit price (without tax) + * @param qty Quantite + * @param txtva Taux de tva force, sinon -1 + * @param txlocaltax1 Local tax 1 rate + * @param txlocaltax2 Local tax 2 rate + * @param fk_product Id du produit/service predefini + * @param remise_percent Pourcentage de remise de la ligne + * @param info_bits Bits de type de lignes + * @param fk_remise_except Id remise + * @param price_base_type HT or TTC + * @param pu_ttc Prix unitaire TTC + * @param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @param type Type of line (0=product, 1=service) + * @param rang Position of line + * @return int >0 if OK, <0 if KO + * @see add_product + * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini + * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) + * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) + */ + function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0) + { + dol_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type", LOG_DEBUG); + + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + + // Clean parameters + if (empty($remise_percent)) $remise_percent=0; + if (empty($qty)) $qty=0; + if (empty($info_bits)) $info_bits=0; + if (empty($rang)) $rang=0; + if (empty($txtva)) $txtva=0; + if (empty($txlocaltax1)) $txlocaltax1=0; + if (empty($txlocaltax2)) $txlocaltax2=0; + if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=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 ($type < 0) return -1; + + if ($this->statut == 0) + { + $this->db->begin(); + + // 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]; + + // Rang to use + $rangtouse = $rang; + if ($rangtouse == -1) + { + $rangmax = $this->line_max($fk_parent_line); + $rangtouse = $rangmax + 1; + } + + // TODO A virer + // Anciens indicateurs: $price, $remise (a ne plus utiliser) + $price = $pu; + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; + } + + // Insert line + $this->line=new OrderLine($this->db); + + $this->line->fk_commande=$commandeid; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->fk_product=$fk_product; + $this->line->fk_remise_except=$fk_remise_except; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$pu_ht; + $this->line->rang=$rangtouse; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->product_type=$type; + $this->line->special_code=$special_code; + $this->line->fk_parent_line=$fk_parent_line; + + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + + // TODO Ne plus utiliser + $this->line->price=$price; + $this->line->remise=$remise; + + $result=$this->line->insert(); + if ($result > 0) + { + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); + + // Mise a jour informations denormalisees au niveau de la commande meme + $this->id=$commandeid; // TODO A virer + $result=$this->update_price(1); + if ($result > 0) + { + $this->db->commit(); + return $this->line->rowid; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->line->error; + dol_syslog("Commande::addline error=".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } + } + + + /** + * Add line into array + * $this->client doit etre charge + * @param idproduct Id du produit a ajouter + * @param qty Quantite + * @param remise_percent Remise relative effectuee sur le produit + * @param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @return void + * TODO Remplacer les appels a cette fonction par generation objet Ligne + * insere dans tableau $this->products + */ + function add_product($idproduct, $qty, $remise_percent=0, $date_start='', $date_end='') + { + global $conf, $mysoc; + + if (! $qty) $qty = 1; + + if ($idproduct > 0) + { + $prod=new Product($this->db); + $prod->fetch($idproduct); + + $tva_tx = get_default_tva($mysoc,$this->client,$prod->id); + $localtax1_tx=get_localtax($tva_tx,1,$this->client); + $localtax2_tx=get_localtax($tva_tx,2,$this->client); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES && $this->client->price_level) + $price = $prod->multiprices[$this->client->price_level]; + else + $price = $prod->price; + + $line=new OrderLine($this->db); + + $line->fk_product=$idproduct; + $line->desc=$prod->description; + $line->qty=$qty; + $line->subprice=$price; + $line->remise_percent=$remise_percent; + $line->tva_tx=$tva_tx; + $line->localtax1_tx=$localtax1_tx; + $line->localtax2_tx=$localtax2_tx; + $line->ref=$prod->ref; + $line->libelle=$prod->libelle; + $line->product_desc=$prod->description; + + // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + // Save the start and end date of the line in the object + if ($date_start) { $line->date_start = $date_start; } + if ($date_end) { $line->date_end = $date_end; } + + $this->lines[] = $line; + + /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE + if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) + { + $prod = new Product($this->db); + $prod->fetch($idproduct); + $prod -> get_sousproduits_arbo (); + $prods_arbo = $prod->get_each_prod(); + if(sizeof($prods_arbo) > 0) + { + foreach($prods_arbo as $key => $value) + { + // print "id : ".$value[1].' :qty: '.$value[0].'
'; + if(! in_array($value[1],$this->products)) + $this->add_product($value[1], $value[0]); + + } + } + + } + **/ + } + } + + + /** + * Get object and lines from database + * @param id Id of object to load + * @param ref Ref of object + * @param ref_ext External reference of object + * @param ref_int Internal reference of other object + * @return int >0 if OK, <0 if KO + */ + function fetch($id, $ref='', $ref_ext='', $ref_int='') + { + global $conf; + + // Check parameters + if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; + + $sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut'; + $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason'; + $sql.= ', c.date_commande'; + $sql.= ', c.date_livraison'; + $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee'; + $sql.= ', c.note, c.note_public, c.ref_client, c.ref_ext, c.ref_int, c.model_pdf, c.fk_adresse_livraison'; + $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; + $sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc'; + $sql.= ', ca.code as availability_code'; + $sql.= ', dr.code as demand_reason_code'; + $sql.= ', el.fk_source'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commande 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_availability as ca ON (c.fk_availability = ca.rowid)'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_demand_reason = ca.rowid)'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = c.rowid AND el.targettype = '".$this->element."'"; + $sql.= " WHERE c.entity = ".$conf->entity; + if ($id) $sql.= " AND c.rowid=".$id; + if ($ref) $sql.= " AND c.ref='".$this->db->escape($ref)."'"; + if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; + if ($ref_int) $sql.= " AND c.ref_int='".$this->db->escape($ref_int)."'"; + + dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); + $result = $this->db->query($sql) ; + if ($result) + { + $obj = $this->db->fetch_object($result); + if ($obj) + { + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->ref_client = $obj->ref_client; + $this->ref_ext = $obj->ref_ext; + $this->ref_int = $obj->ref_int; + $this->socid = $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->total_tva; + $this->total_localtax1 = $obj->total_localtax1; + $this->total_localtax2 = $obj->total_localtax2; + $this->total_ttc = $obj->total_ttc; + $this->date = $this->db->jdate($obj->date_commande); + $this->date_commande = $this->db->jdate($obj->date_commande); + $this->remise = $obj->remise; + $this->remise_percent = $obj->remise_percent; + $this->remise_absolue = $obj->remise_absolue; + $this->source = $obj->source; + $this->facturee = $obj->facturee; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + $this->fk_project = $obj->fk_projet; + $this->modelpdf = $obj->model_pdf; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; + $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->availability_id = $obj->fk_availability; + $this->availability_code = $obj->availability_code; + $this->demand_reason_id = $obj->fk_demand_reason; + $this->demand_reason_code = $obj->demand_reason_code; + $this->date_livraison = $this->db->jdate($obj->date_livraison); + $this->fk_delivery_address = $obj->fk_adresse_livraison; + $this->propale_id = $obj->fk_source; + + $this->lines = array(); + + if ($this->statut == 0) $this->brouillon = 1; + + $this->db->free(); + + if ($this->propale_id) + { + $sqlp = "SELECT ref"; + $sqlp.= " FROM ".MAIN_DB_PREFIX."propal"; + $sqlp.= " WHERE rowid = ".$this->propale_id; + + $resqlprop = $this->db->query($sqlp); + + if ($resqlprop) + { + $objp = $this->db->fetch_object($resqlprop); + $this->propale_ref = $objp->ref; + $this->db->free($resqlprop); + } + } + + /* + * Lignes + */ + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } + return 1; + } + else + { + dol_syslog('Commande::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); + $this->error='Order with id '.$rowid.' not found sql='.$sql; + return -2; + } + } + else + { + dol_syslog('Commande::Fetch Error rowid='.$rowid.' Erreur dans fetch de la commande'); + $this->error=$this->db->error(); + return -1; + } + } + + + /** + * Ajout d'une ligne remise fixe dans la commande, en base + * @param idremise Id de la remise fixe + * @return int >0 si ok, <0 si ko + */ + function insert_discount($idremise) + { + global $langs; + + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + include_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'); + + $this->db->begin(); + + $remise=new DiscountAbsolute($this->db); + $result=$remise->fetch($idremise); + + if ($result > 0) + { + if ($remise->fk_facture) // Protection against multiple submission + { + $this->error=$langs->trans("ErrorDiscountAlreadyUsed"); + $this->db->rollback(); + return -5; + } + + $line = new OrderLine($this->db); + + $line->fk_commande=$this->id; + $line->fk_remise_except=$remise->id; + $line->desc=$remise->description; // Description ligne + $line->tva_tx=$remise->tva_tx; + $line->subprice=-$remise->amount_ht; + $line->price=-$remise->amount_ht; + $line->fk_product=0; // Id produit predefini + $line->qty=1; + $line->remise=0; + $line->remise_percent=0; + $line->rang=-1; + $line->info_bits=2; + + $line->total_ht = -$remise->amount_ht; + $line->total_tva = -$remise->amount_tva; + $line->total_ttc = -$remise->amount_ttc; + + $result=$line->insert(); + if ($result > 0) + { + $result=$this->update_price(1); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$line->error; + $this->db->rollback(); + return -2; + } + } + else + { + $this->db->rollback(); + return -2; + } + } + + + /** + * Load array lines + * @param only_product Return only physical products + * @return int <0 if KO, >0 if OK + */ + function fetch_lines($only_product=0) + { + $this->lines=array(); + + $sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,'; + $sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits, l.special_code,'; + $sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,'; + $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)'; + $sql.= ' WHERE l.fk_commande = '.$this->id; + if ($only_product) $sql .= ' AND p.fk_product_type = 0'; + $sql .= ' ORDER BY l.rang'; + + dol_syslog("Commande::fetch_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 OrderLine($this->db); + + $line->rowid = $objp->rowid; // \deprecated + $line->id = $objp->rowid; + $line->fk_commande = $objp->fk_commande; + $line->commande_id = $objp->fk_commande; // \deprecated + $line->desc = $objp->description; // Description ligne + $line->product_type = $objp->product_type; + $line->qty = $objp->qty; + $line->tva_tx = $objp->tva_tx; + $line->localtax1_tx = $objp->localtax1_tx; + $line->localtax2_tx = $objp->localtax2_tx; + $line->total_ht = $objp->total_ht; + $line->total_ttc = $objp->total_ttc; + $line->total_tva = $objp->total_tva; + $line->total_localtax1 = $objp->total_localtax1; + $line->total_localtax2 = $objp->total_localtax2; + $line->subprice = $objp->subprice; + $line->fk_remise_except = $objp->fk_remise_except; + $line->remise_percent = $objp->remise_percent; + $line->price = $objp->price; + $line->fk_product = $objp->fk_product; + $line->marge_tx = $objp->marge_tx; + $line->marque_tx = $objp->marque_tx; + $line->rang = $objp->rang; + $line->info_bits = $objp->info_bits; + $line->special_code = $objp->special_code; + $line->fk_parent_line = $objp->fk_parent_line; + + $line->ref = $objp->product_ref; // TODO deprecated + $line->product_ref = $objp->product_ref; + $line->libelle = $objp->product_label; // TODO deprecated + $line->product_label = $objp->product_label; + $line->product_desc = $objp->product_desc; // Description produit + $line->fk_product_type = $objp->fk_product_type; // Produit ou service + + $line->date_start = $this->db->jdate($objp->date_start); + $line->date_end = $this->db->jdate($objp->date_end); + + $this->lines[$i] = $line; + + $i++; + } + $this->db->free($result); + + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog('Commande::fetch_lines: Error '.$this->error, LOG_ERR); + return -3; + } + } + + + /** + * Return number of line with type product. + * @return int <0 if KO, Nbr of product lines if OK + */ + function getNbOfProductsLines() + { + $nb=0; + foreach($this->lines as $line) + { + if ($line->fk_product_type == 0) $nb++; + } + return $nb; + } + + /** + * Load array this->expeditions of nb of products sent by line in order + * @param filtre_statut Filter on status + * @return int <0 if KO, Nb of lines found if OK + * TODO deprecated, move to Shipping class + */ + function loadExpeditions($filtre_statut=-1) + { + $num=0; + $this->expeditions = array(); + + $sql = 'SELECT cd.rowid, cd.fk_product,'; + $sql.= ' sum(ed.qty) as qty'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed,'; + if ($filtre_statut >= 0) $sql.= ' '.MAIN_DB_PREFIX.'expedition as e,'; + $sql.= ' '.MAIN_DB_PREFIX.'commandedet as cd'; + $sql.= ' WHERE'; + if ($filtre_statut >= 0) $sql.= ' ed.fk_expedition = e.rowid AND'; + $sql.= ' ed.fk_origin_line = cd.rowid'; + $sql.= ' AND cd.fk_commande =' .$this->id; + if ($filtre_statut >= 0) $sql.=' AND e.fk_statut = '.$filtre_statut; + $sql.= ' GROUP BY cd.rowid, cd.fk_product'; + //print $sql; + + dol_syslog("Commande::loadExpeditions sql=".$sql,LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $this->expeditions[$obj->rowid] = $obj->qty; + $i++; + } + $this->db->free(); + return $num; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("Commande::loadExpeditions ".$this->error,LOG_ERR); + return -1; + } + + } + + /** + * Renvoie un tableau avec nombre de lignes d'expeditions + * TODO deprecated, move to Shipping class + */ + function nb_expedition() + { + $sql = 'SELECT count(*)'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'expedition as e'; + $sql.= ', '.MAIN_DB_PREFIX.'element_element as el'; + $sql.= ' WHERE el.fk_source = '.$this->id; + $sql.= " AND el.fk_target = e.rowid"; + $sql.= " AND el.targettype = 'shipping'"; + + $resql = $this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_row($resql); + return $row[0]; + } + else dol_print_error($this->db); + } + + /** + * Renvoie un tableau avec les livraisons par ligne + * @param filtre_statut Filtre sur statut + * @return int 0 si OK, <0 si KO + * TODO deprecated, move to Shipping class + */ + function livraison_array($filtre_statut=-1) + { + $delivery = new Livraison($this->db); + $deliveryArray = $delivery->livraison_array($filtre_statut); + return $deliveryArray; + } + + /** + * Renvoie un tableau avec les stocks restant par produit + * @param filtre_statut Filtre sur statut + * @return int 0 si OK, <0 si KO + * TODO FONCTION NON FINIE A FINIR + */ + function stock_array($filtre_statut=-1) + { + $this->stocks = array(); + + // Tableau des id de produit de la commande + + + // Recherche total en stock pour chaque produit + if (sizeof($array_of_product)) + { + $sql = "SELECT fk_product, sum(ps.reel) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; + $sql.= " WHERE ps.fk_product in (".join(',',$array_of_product).")"; + $sql.= ' GROUP BY fk_product '; + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $this->stocks[$obj->fk_product] = $obj->total; + $i++; + } + $this->db->free(); + } + } + return 0; + } + + /** + * Delete an order line + * @param lineid Id of line to delete + * @return int >0 if OK, 0 if nothing to do, <0 if KO + */ + function deleteline($lineid) + { + global $user; + + if ($this->statut == 0) + { + $this->db->begin(); + + $sql = "SELECT fk_product, qty"; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; + $sql.= " WHERE rowid = ".$lineid; + + $result = $this->db->query($sql); + if ($result) + { + $obj = $this->db->fetch_object($result); + + if ($obj) + { + $product = new Product($this->db); + $product->id = $obj->fk_product; + + // Delete line + $line = new OrderLine($this->db); + + // For triggers + $line->fetch($lineid); + + if ($line->delete() > 0) + { + $result=$this->update_price(1); + + if ($result > 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(); + return -1; + } + } + else + { + $this->db->rollback(); + return 0; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + return -1; + } + } + + /** + * Applique une remise relative + * + * @param User $user User qui positionne la remise + * @param float $remise Discount (percent) + * @return int <0 if KO, >0 if OK + */ + function set_remise($user, $remise) + { + $remise=trim($remise)?trim($remise):0; + + if ($user->rights->commande->creer) + { + $remise=price2num($remise); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql.= ' SET remise_percent = '.$remise; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + + if ($this->db->query($sql)) + { + $this->remise_percent = $remise; + $this->update_price(1); + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + } + + + /** + * Applique une remise absolue + * + * @param User $user User qui positionne la remise + * @param float $remise Discount + * @return int <0 if KO, >0 if OK + */ + function set_remise_absolue($user, $remise) + { + $remise=trim($remise)?trim($remise):0; + + if ($user->rights->commande->creer) + { + $remise=price2num($remise); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql.= ' SET remise_absolue = '.$remise; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + + dol_syslog("Commande::set_remise_absolue sql=$sql"); + + if ($this->db->query($sql)) + { + $this->remise_absolue = $remise; + $this->update_price(1); + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + } + + + /** + * Set the order date + * + * @param user Object user making change + * @param date Date + * @return int <0 if KO, >0 if OK + */ + function set_date($user, $date) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null'); + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + dol_syslog("Commande::set_date sql=$sql",LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->date = $date; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_date ".$this->error,LOG_ERR); + return -1; + } + } + else + { + return -2; + } + } + + /** + * Set the planned delivery date + * + * @param user Objet utilisateur qui modifie + * @param date_livraison Date de livraison + * @return int <0 si ko, >0 si ok + */ + function set_date_livraison($user, $date_livraison) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog("Commande::set_date_livraison sql=".$sql,LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->date_livraison = $date_livraison; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_date_livraison ".$this->error,LOG_ERR); + return -1; + } + } + else + { + return -2; + } + } + + /** + * Set address + * + * @param user Object user making change + * @param fk_address Adress of delivery + * @return int <0 ig KO, >0 if Ok + */ + function set_adresse_livraison($user, $fk_address) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_adresse_livraison = '".$fk_address."'"; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + if ($this->db->query($sql) ) + { + $this->fk_delivery_address = $fk_address; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_adresse_livraison Erreur SQL"); + return -1; + } + } + } + + /** + * Set availability + * + * @param user Object user making change + * @param id If of availability delay + * @return int <0 if KO, >0 if OK + */ + function set_availability($user, $id) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; + $sql.= " SET fk_availability = '".$id."'"; + $sql.= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + $this->fk_availability = $id; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_availability Erreur SQL"); + return -1; + } + } + } + + /** + * Set source of demand + * + * @param user Object user making change + * @param id Id of source + * @return int <0 if KO, >0 if OK + */ + function set_demand_reason($user, $id) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; + $sql.= " SET fk_demand_reason = '".$id."'"; + $sql.= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + $this->fk_demand_reason = $id; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_demand_reason Erreur SQL"); + return -1; + } + } + } + + /** + * Return list of orders (eventuelly filtered on a user) into an array + * + * @param brouillon 0=non brouillon, 1=brouillon + * @param user Objet user de filtre + * @return int -1 if KO, array with result if OK + */ + function liste_array($brouillon=0, $user='') + { + global $conf; + + $ga = array(); + + $sql = "SELECT s.nom, s.rowid, c.rowid, c.ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; + $sql.= " WHERE c.entity = ".$conf->entity; + $sql.= " AND c.fk_soc = s.rowid"; + if ($brouillon) $sql.= " AND c.fk_statut = 0"; + if ($user) $sql.= " AND c.fk_user_author <> ".$user->id; + $sql .= " ORDER BY c.date_commande DESC"; + + $result=$this->db->query($sql); + if ($result) + { + $numc = $this->db->num_rows($result); + if ($numc) + { + $i = 0; + while ($i < $numc) + { + $obj = $this->db->fetch_object($result); + + $ga[$obj->rowid] = $obj->ref; + $i++; + } + } + return $ga; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + /** + * Change les conditions de reglement de la commande + * + * @param cond_reglement_id Id de la nouvelle condition de reglement + * @return int >0 if OK, <0 if KO + */ + function cond_reglement($cond_reglement_id) + { + dol_syslog('Commande::cond_reglement('.$cond_reglement_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $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('Commande::cond_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('Commande::cond_reglement, etat commande incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + + /** + * Change le mode de reglement + * + * @param mode Id du nouveau mode + * @return int >0 si ok, <0 si ko + */ + function mode_reglement($mode_reglement_id) + { + dol_syslog('Commande::mode_reglement('.$mode_reglement_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $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('Commande::mode_reglement Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('Commande::mode_reglement, etat facture incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + /** + * Change le delai de livraison + * @param availability_id Id du nouveau mode + * @return int >0 if OK, <0 if KO + */ + function availability($availability_id) + { + dol_syslog('Commande::availability('.$availability_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql .= ' SET fk_availability = '.$availability_id; + $sql .= ' WHERE rowid='.$this->id; + if ( $this->db->query($sql) ) + { + $this->availability_id = $availability_id; + return 1; + } + else + { + dol_syslog('Commande::availability Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('Commande::availability, etat facture incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + /** + * \brief Change la source de la demande + * \param mode Id du nouveau mode + * \return int >0 si ok, <0 si ko + */ + function demand_reason($demand_reason_id) + { + dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql .= ' SET fk_demand_reason = '.$demand_reason_id; + $sql .= ' WHERE rowid='.$this->id; + if ( $this->db->query($sql) ) + { + $this->demand_reason_id = $demand_reason_id; + return 1; + } + else + { + dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + + /** + * \brief Set customer ref + * \param user User that make change + * \param ref_client Customer ref + * \return int <0 if KO, >0 if OK + */ + function set_ref_client($user, $ref_client) + { + if ($user->rights->commande->creer) + { + dol_syslog('Commande::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET'; + $sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); + $sql.= ' WHERE rowid = '.$this->id; + + if ($this->db->query($sql) ) + { + $this->ref_client = $ref_client; + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog('Commande::set_ref_client Erreur '.$this->error.' - '.$sql, LOG_ERR); + return -2; + } + } + else + { + return -1; + } + } + + + /** + * \brief Classe la commande comme facturee + * \return int <0 si ko, >0 si ok + */ + function classer_facturee() + { + global $conf; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;'; + if ($this->db->query($sql) ) + { + if (($conf->global->PROPALE_CLASSIFIED_INVOICED_WITH_ORDER == 1) && $this->propale_id) + { + $propal = new Propal($this->db); + $propal->fetch($this->propale_id); + $propal->classer_facturee(); + } + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + + /** + * Update a line in database + * + * @param rowid Id of line to update + * @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 txlocaltax1 Local tax 1 rate + * @param txlocaltax2 Local tax 2 rate + * @param price_base_type HT or TTC + * @param info_bits Miscellaneous informations on line + * @param date_start Start date of the line + * @param date_end End date of the line + * @param type Type of line (0=product, 1=service) + * @return int < 0 if KO, > 0 if OK + */ + function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva, $txlocaltax1=0,$txlocaltax2=0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0) + { + global $conf; + + dol_syslog("CustomerOrder::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $date_start, $date_end, $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); + $pu = price2num($pu); + $txtva=price2num($txtva); + $txlocaltax1=price2num($txtlocaltax1); + $txlocaltax2=price2num($txtlocaltax2); + + // 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) + $price = $pu; + $subprice = $pu; + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($pu * $remise_percent / 100),2); + $price = ($pu - $remise); + } + + // Update line + $this->line=new OrderLine($this->db); + + // Stock previous line records + $staticline=new OrderLine($this->db); + $staticline->fetch($rowid); + $this->line->oldline = $staticline; + + $this->line->rowid=$rowid; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$subprice; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + $this->line->product_type=$type; + $this->line->fk_parent_line=$fk_parent_line; + $this->line->skip_update_total=$skip_update_total; + + // TODO deprecated + $this->line->price=$price; + $this->line->remise=$remise; + + $result=$this->line->update(); + if ($result > 0) + { + // Mise a jour info denormalisees + $this->update_price(1); + + $this->db->commit(); + return $result; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + dol_syslog("CustomerOrder::UpdateLine Error=".$this->error, LOG_ERR); + return -1; + } + } + else + { + $this->error="CustomerOrder::Updateline Order status makes operation forbidden"; + return -2; + } + } + + + /** + * Delete the customer order + * @param user User object + * @return int <=0 if KO, >0 if OK + */ + function delete($user) + { + global $conf, $langs; + require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); + + $err = 0; + + $this->db->begin(); + + // Delete order details + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id; + dol_syslog("Commande::delete sql=".$sql); + if (! $this->db->query($sql) ) + { + dol_syslog("CustomerOrder::delete error", LOG_ERR); + $err++; + } + + // Delete order + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; + dol_syslog("Commande::delete sql=".$sql); + if (! $this->db->query($sql) ) + { + dol_syslog("CustomerOrder::delete error", LOG_ERR); + $err++; + } + + // Delete linked object + // TODO deplacer dans le common + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = '".$this->element."'"; + dol_syslog("Commande::delete sql=".$sql); + if (! $this->db->query($sql) ) + { + dol_syslog("CustomerOrder::delete error", LOG_ERR); + $err++; + } + + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) + { + dol_syslog("CustomerOrder::delete error", LOG_ERR); + $err++; + } + + // On efface le repertoire de pdf provisoire + $comref = dol_sanitizeFileName($this->ref); + if ($conf->commande->dir_output) + { + $dir = $conf->commande->dir_output . "/" . $comref ; + $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; + if (file_exists($file)) + { + commande_delete_preview($this->db, $this->id, $this->ref); + + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + $this->db->rollback(); + return 0; + } + } + } + + 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_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * 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 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 IN (1,2,3) AND c.facture = 0"; + 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->client->warning_delay)) $this->nbtodolate++; + } + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + + /** + * \brief Return source label of order + * \return string Label + */ + function getLabelSource() + { + global $langs; + + $label=$langs->trans('OrderSource'.$this->source); + + if ($label == 'OrderSource') return ''; + return $label; + } + + /** + * \brief Retourne le libelle du statut de la commande + * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * \return string Libelle + */ + function getLibStatut($mode) + { + return $this->LibStatut($this->statut,$this->facturee,$mode); + } + + /** + * Renvoi le libelle d'un statut donne + * @param statut Id statut + * @param facturee Si facturee + * @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function LibStatut($statut,$facturee,$mode) + { + global $langs; + //print 'x'.$statut.'-'.$facturee; + if ($mode == 0) + { + if ($statut==-1) return $langs->trans('StatusOrderCanceled'); + if ($statut==0) return $langs->trans('StatusOrderDraft'); + if ($statut==1) return $langs->trans('StatusOrderValidated'); + if ($statut==2) return $langs->trans('StatusOrderSentShort'); + if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBill'); + if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessed'); + } + if ($mode == 1) + { + if ($statut==-1) return $langs->trans('StatusOrderCanceledShort'); + if ($statut==0) return $langs->trans('StatusOrderDraftShort'); + if ($statut==1) return $langs->trans('StatusOrderValidatedShort'); + if ($statut==2) return $langs->trans('StatusOrderSentShort'); + if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBillShort'); + if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessed'); + } + if ($mode == 2) + { + if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceledShort'); + if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraftShort'); + if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidatedShort'); + if ($statut==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3').' '.$langs->trans('StatusOrderSentShort'); + if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort'); + if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort'); + } + if ($mode == 3) + { + if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); + if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); + if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); + if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3'); + if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7'); + if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6'); + } + if ($mode == 4) + { + if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceled'); + if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraft'); + if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidated'); + if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3').' '.$langs->trans('StatusOrderOnProcess'); + if ($statut==3 && ! $facturee) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill'); + if ($statut==3 && $facturee) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed'); + } + if ($mode == 5) + { + if ($statut==-1) return $langs->trans('StatusOrderCanceledShort').' '.img_picto($langs->trans('StatusOrderCanceled'),'statut5'); + if ($statut==0) return $langs->trans('StatusOrderDraftShort').' '.img_picto($langs->trans('StatusOrderDraft'),'statut0'); + if ($statut==1) return $langs->trans('StatusOrderValidatedShort').' '.img_picto($langs->trans('StatusOrderValidated'),'statut1'); + if ($statut==2) return $langs->trans('StatusOrderSentShort').' '.img_picto($langs->trans('StatusOrderOnProcess'),'statut3'); + if ($statut==3 && ! $facturee) return $langs->trans('StatusOrderToBillShort').' '.img_picto($langs->trans('StatusOrderToBill'),'statut7'); + if ($statut==3 && $facturee) return $langs->trans('StatusOrderProcessedShort').' '.img_picto($langs->trans('StatusOrderProcessed'),'statut6'); + } + } + + + /** + * Return clicable link of object (with eventually picto) + * @param withpicto Add picto into link + * @param option Where point the link + * @param max Max length to show + * @param short Use short labels + * @return string String with URL + */ + function getNomUrl($withpicto=0,$option=0,$max=0,$short=0) + { + global $conf, $langs; + + $result=''; + + if ($conf->expedition->enabled && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; + else $url = DOL_URL_ROOT.'/commande/fiche.php?id='.$this->id; + + if ($short) return $url; + + $linkstart = ''; + $linkend=''; + + $picto='order'; + $label=$langs->trans("ShowOrder").': '.$this->ref; + + if ($withpicto) $result.=($linkstart.img_object($label,$picto).$linkend); + if ($withpicto && $withpicto != 2) $result.=' '; + $result.=$linkstart.$this->ref.$linkend; + return $result; + } + + + /** + * \brief Charge les informations d'ordre info dans l'objet commande + * \param id Id de la commande a charger + */ + function info($id) + { + $sql = 'SELECT c.rowid, date_creation as datec, tms as datem,'; + $sql.= ' date_valid as datev,'; + $sql.= ' date_cloture as datecloture,'; + $sql.= ' fk_user_author, fk_user_valid, fk_user_cloture'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; + $sql.= ' WHERE c.rowid = '.$id; + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db); + $cluser->fetch($obj->fk_user_cloture); + $this->user_cloture = $cluser; + } + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + $this->date_validation = $this->db->jdate($obj->datev); + $this->date_cloture = $this->db->jdate($obj->datecloture); + } + + $this->db->free($result); + + } + else + { + dol_print_error($this->db); + } + } + + + /** + * Initialise an example of instance with random values + * Used to build previews or test instances + */ + function initAsSpecimen() + { + global $user,$langs,$conf; + + dol_syslog(get_class($this)."::initAsSpecimen"); + + // 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 = time(); + $this->date_lim_reglement=$this->date+3600*24*30; + $this->cond_reglement_code = 'RECEP'; + $this->mode_reglement_code = 'CHQ'; + $this->availability_code = 'DSP'; + $this->demand_reason_code = 'SRC_00'; + $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 OrderLine($this->db); + + $line->desc=$langs->trans("Description")." ".$xnbp; + $line->qty=1; + $line->subprice=100; + $line->price=100; + $line->tva_tx=19.6; + 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; + } + $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++; + } + } + + + /** + * Charge indicateurs this->nb de tableau de bord + * + * @return int <0 si ko, >0 si ok + */ + function load_state_board() + { + global $conf, $user; + + $this->nb=array(); + $clause = "WHERE"; + + $sql = "SELECT count(co.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande as co"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid"; + if (!$user->rights->societe->client->voir && !$user->societe_id) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql.= " WHERE sc.fk_user = " .$user->id; + $clause = "AND"; + } + $sql.= " ".$clause." co.entity = ".$conf->entity; + + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj=$this->db->fetch_object($resql)) + { + $this->nb["orders"]=$obj->nb; + } + return 1; + } + else + { + dol_print_error($this->db); + $this->error=$this->db->error(); + return -1; + } + } + + /** + * Return an array of order lines + */ + function getLinesArray() + { + $lines = array(); + + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, '; + $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,l.rang,l.special_code,'; + $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.date_start,'; + $sql.= ' l.date_end,'; + $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, '; + $sql.= ' p.description as product_desc'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet 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.rang ASC, l.rowid'; + + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $this->lines[$i]->id = $obj->rowid; + $this->lines[$i]->description = $obj->description; + $this->lines[$i]->fk_product = $obj->fk_product; + $this->lines[$i]->ref = $obj->ref; + $this->lines[$i]->product_label = $obj->product_label; + $this->lines[$i]->product_desc = $obj->product_desc; + $this->lines[$i]->fk_product_type = $obj->fk_product_type; + $this->lines[$i]->product_type = $obj->product_type; + $this->lines[$i]->qty = $obj->qty; + $this->lines[$i]->subprice = $obj->subprice; + $this->lines[$i]->fk_remise_except = $obj->fk_remise_except; + $this->lines[$i]->remise_percent = $obj->remise_percent; + $this->lines[$i]->tva_tx = $obj->tva_tx; + $this->lines[$i]->info_bits = $obj->info_bits; + $this->lines[$i]->total_ht = $obj->total_ht; + $this->lines[$i]->total_tva = $obj->total_tva; + $this->lines[$i]->total_ttc = $obj->total_ttc; + $this->lines[$i]->special_code = $obj->special_code; + $this->lines[$i]->rang = $obj->rang; + $this->lines[$i]->date_start = $this->db->jdate($obj->date_start); + $this->lines[$i]->date_end = $this->db->jdate($obj->date_end); + + $i++; + } + + $this->db->free($resql); + + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Error sql=$sql, error=".$this->error,LOG_ERR); + return -1; + } + } } @@ -2776,375 +2790,375 @@ class Commande extends CommonObject */ class OrderLine { - var $db; - var $error; + var $db; + var $error; - var $oldline; + var $oldline; - // From llx_commandedet - var $rowid; - var $fk_parent_line; - var $fk_facture; - var $desc; // Description ligne - var $fk_product; // Id produit predefini - var $product_type = 0; // Type 0 = product, 1 = Service + // From llx_commandedet + var $rowid; + var $fk_parent_line; + var $fk_facture; + var $desc; // Description ligne + var $fk_product; // Id produit predefini + var $product_type = 0; // Type 0 = product, 1 = Service - var $qty; // Quantity (example 2) - var $tva_tx; // VAT Rate for product/service (example 19.6) - var $localtax1_tx; // Local tax 1 - var $localtax2_tx; // Local tax 2 - var $subprice; // U.P. HT (example 100) - var $remise_percent; // % for line discount (example 20%) - var $rang = 0; - var $marge_tx; - var $marque_tx; - var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR - // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - var $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne - var $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne - var $total_localtax1; // Total local tax 1 for the line - var $total_localtax2; // Total local tax 2 for the line - var $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne + var $qty; // Quantity (example 2) + var $tva_tx; // VAT Rate for product/service (example 19.6) + var $localtax1_tx; // Local tax 1 + var $localtax2_tx; // Local tax 2 + var $subprice; // U.P. HT (example 100) + var $remise_percent; // % for line discount (example 20%) + var $rang = 0; + var $marge_tx; + var $marque_tx; + var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR + // Bit 1: 0 ligne normale - 1 si ligne de remise fixe + var $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne + var $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne + var $total_localtax1; // Total local tax 1 for the line + var $total_localtax2; // Total local tax 2 for the line + var $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne - // Ne plus utiliser - var $remise; - var $price; + // Ne plus utiliser + var $remise; + var $price; - // From llx_product - var $ref; // Reference produit - var $product_libelle; // Label produit - var $product_desc; // Description produit + // From llx_product + var $ref; // Reference produit + var $product_libelle; // Label produit + var $product_desc; // Description produit - // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - // Start and end date of the line - var $date_start; - var $date_end; + // Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + // Start and end date of the line + var $date_start; + var $date_end; - var $skip_update_total; // Skip update price total for special lines + var $skip_update_total; // Skip update price total for special lines - /** - * Constructor - * - * @param DB handler d'acces base de donnee - */ - function OrderLine($DB) - { - $this->db= $DB; - } + /** + * Constructor + * + * @param DB handler d'acces base de donnee + */ + function OrderLine($DB) + { + $this->db= $DB; + } - /** - * Load line order - * - * @param rowid id line order - */ - function fetch($rowid) - { - $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_parent_line, cd.fk_product, cd.product_type, cd.description, cd.price, cd.qty, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx,'; - $sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,'; - $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.marge_tx, cd.marque_tx, cd.rang, cd.special_code,'; - $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,'; - $sql.= ' cd.date_start, cd.date_end'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet 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->fk_parent_line = $objp->fk_parent_line; - $this->desc = $objp->description; - $this->qty = $objp->qty; - $this->price = $objp->price; - $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_remise_except = $objp->fk_remise_except; - $this->fk_product = $objp->fk_product; - $this->product_type = $objp->product_type; - $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->marge_tx = $objp->marge_tx; - $this->marque_tx = $objp->marque_tx; - $this->special_code = $objp->special_code; - $this->rang = $objp->rang; + /** + * Load line order + * + * @param rowid id line order + */ + function fetch($rowid) + { + $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_parent_line, cd.fk_product, cd.product_type, cd.description, cd.price, cd.qty, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx,'; + $sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,'; + $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.marge_tx, cd.marque_tx, cd.rang, cd.special_code,'; + $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,'; + $sql.= ' cd.date_start, cd.date_end'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet 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->fk_parent_line = $objp->fk_parent_line; + $this->desc = $objp->description; + $this->qty = $objp->qty; + $this->price = $objp->price; + $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_remise_except = $objp->fk_remise_except; + $this->fk_product = $objp->fk_product; + $this->product_type = $objp->product_type; + $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->marge_tx = $objp->marge_tx; + $this->marque_tx = $objp->marque_tx; + $this->special_code = $objp->special_code; + $this->rang = $objp->rang; - $this->ref = $objp->product_ref; // deprecated - $this->product_ref = $objp->product_ref; - $this->libelle = $objp->product_libelle; // deprecated - $this->product_label = $objp->product_libelle; - $this->product_desc = $objp->product_desc; + $this->ref = $objp->product_ref; // deprecated + $this->product_ref = $objp->product_ref; + $this->libelle = $objp->product_libelle; // deprecated + $this->product_label = $objp->product_libelle; + $this->product_desc = $objp->product_desc; - $this->date_start = $this->db->jdate($objp->date_start); - $this->date_end = $this->db->jdate($objp->date_end); + $this->date_start = $this->db->jdate($objp->date_start); + $this->date_end = $this->db->jdate($objp->date_end); - $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } - /** - * Delete line in database - * - * @return int <0 si ko, >0 si ok - */ - function delete() - { - global $conf, $user, $langs; + /** + * Delete line in database + * + * @return int <0 si ko, >0 si ok + */ + function delete() + { + global $conf, $user, $langs; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->rowid."';"; + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->rowid."';"; - dol_syslog("OrderLine::delete sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + dol_syslog("OrderLine::delete sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers - return 1; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("OrderLine::delete ".$this->error, LOG_ERR); - return -1; - } - } + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("OrderLine::delete ".$this->error, LOG_ERR); + return -1; + } + } - /** - * Insert line into database - * - * @param notrigger 1 = disable triggers - * @return int <0 if KO, >0 if OK - */ - function insert($notrigger=0) - { - global $langs, $conf, $user; + /** + * Insert line into database + * + * @param notrigger 1 = disable triggers + * @return int <0 if KO, >0 if OK + */ + function insert($notrigger=0) + { + global $langs, $conf, $user; - dol_syslog("OrderLine::insert rang=".$this->rang); + dol_syslog("OrderLine::insert rang=".$this->rang); - // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx=0; - if (empty($this->localtax1_tx)) $this->localtax1_tx=0; - if (empty($this->localtax2_tx)) $this->localtax2_tx=0; - if (empty($this->total_localtax1)) $this->total_localtax1=0; - if (empty($this->total_localtax2)) $this->total_localtax2=0; - if (empty($this->rang)) $this->rang=0; - if (empty($this->remise)) $this->remise=0; - if (empty($this->remise_percent)) $this->remise_percent=0; - if (empty($this->info_bits)) $this->info_bits=0; - if (empty($this->special_code)) $this->special_code=0; - if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + // Clean parameters + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->special_code)) $this->special_code=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; - // Check parameters - if ($this->product_type < 0) return -1; + // Check parameters + if ($this->product_type < 0) return -1; - $this->db->begin(); + $this->db->begin(); - // Insertion dans base de la ligne - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; - $sql.= ' (fk_commande, fk_parent_line, description, qty, tva_tx, localtax1_tx, localtax2_tx,'; - $sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,'; - $sql.= ' special_code, rang, marge_tx, marque_tx,'; - $sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end)'; - $sql.= " VALUES (".$this->fk_commande.","; - $sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").","; - $sql.= " '".$this->db->escape($this->desc)."',"; - $sql.= " '".price2num($this->qty)."',"; - $sql.= " '".price2num($this->tva_tx)."',"; - $sql.= " '".price2num($this->localtax1_tx)."',"; - $sql.= " '".price2num($this->localtax2_tx)."',"; - if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } - else { $sql.='null,'; } - $sql.= " '".$this->product_type."',"; - $sql.= " '".price2num($this->remise_percent)."',"; - $sql.= " ".($this->subprice!=''?"'".price2num($this->subprice)."'":"null").","; - $sql.= " ".($this->price!=''?"'".price2num($this->price)."'":"null").","; - $sql.= " '".price2num($this->remise)."',"; - if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; - else $sql.= 'null,'; - $sql.= ' '.$this->special_code.','; - $sql.= ' '.$this->rang.','; - if (isset($this->marge_tx)) $sql.= ' '.$this->marge_tx.','; - else $sql.= ' null,'; - if (isset($this->marque_tx)) $sql.= ' '.$this->marque_tx.','; - else $sql.= ' null,'; - $sql.= " '".$this->info_bits."',"; - $sql.= " '".price2num($this->total_ht)."',"; - $sql.= " '".price2num($this->total_tva)."',"; - $sql.= " '".price2num($this->total_localtax1)."',"; - $sql.= " '".price2num($this->total_localtax2)."',"; - $sql.= " '".price2num($this->total_ttc)."',"; - if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; } - else { $sql.='null,'; } - if ($this->date_end) { $sql.= "'".$this->db->idate($this->date_end)."'"; } - else { $sql.='null'; } - $sql.= ')'; + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; + $sql.= ' (fk_commande, fk_parent_line, description, qty, tva_tx, localtax1_tx, localtax2_tx,'; + $sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,'; + $sql.= ' special_code, rang, marge_tx, marque_tx,'; + $sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end)'; + $sql.= " VALUES (".$this->fk_commande.","; + $sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").","; + $sql.= " '".$this->db->escape($this->desc)."',"; + $sql.= " '".price2num($this->qty)."',"; + $sql.= " '".price2num($this->tva_tx)."',"; + $sql.= " '".price2num($this->localtax1_tx)."',"; + $sql.= " '".price2num($this->localtax2_tx)."',"; + if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } + else { $sql.='null,'; } + $sql.= " '".$this->product_type."',"; + $sql.= " '".price2num($this->remise_percent)."',"; + $sql.= " ".($this->subprice!=''?"'".price2num($this->subprice)."'":"null").","; + $sql.= " ".($this->price!=''?"'".price2num($this->price)."'":"null").","; + $sql.= " '".price2num($this->remise)."',"; + if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; + else $sql.= 'null,'; + $sql.= ' '.$this->special_code.','; + $sql.= ' '.$this->rang.','; + if (isset($this->marge_tx)) $sql.= ' '.$this->marge_tx.','; + else $sql.= ' null,'; + if (isset($this->marque_tx)) $sql.= ' '.$this->marque_tx.','; + else $sql.= ' null,'; + $sql.= " '".$this->info_bits."',"; + $sql.= " '".price2num($this->total_ht)."',"; + $sql.= " '".price2num($this->total_tva)."',"; + $sql.= " '".price2num($this->total_localtax1)."',"; + $sql.= " '".price2num($this->total_localtax2)."',"; + $sql.= " '".price2num($this->total_ttc)."',"; + if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; } + else { $sql.='null,'; } + if ($this->date_end) { $sql.= "'".$this->db->idate($this->date_end)."'"; } + else { $sql.='null'; } + $sql.= ')'; - dol_syslog("OrderLine::insert sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet'); + dol_syslog("OrderLine::insert sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet'); - if (! $notrigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('LINEORDER_INSERT',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LINEORDER_INSERT',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("OrderLine::insert Error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("OrderLine::insert Error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } - /** - * Mise a jour de l'objet ligne de commande en base - * - * @return int <0 si ko, >0 si ok - */ - function update($notrigger=0) - { - global $conf,$langs,$user; + /** + * Mise a jour de l'objet ligne de commande en base + * + * @return int <0 si ko, >0 si ok + */ + function update($notrigger=0) + { + global $conf,$langs,$user; - // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx=0; - if (empty($this->localtax1_tx)) $this->localtax1_tx=0; - if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + // Clean parameters + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; if (empty($this->qty)) $this->qty=0; - if (empty($this->total_localtax1)) $this->total_localtax1=0; - if (empty($this->total_localtax2)) $this->total_localtax2=0; - if (empty($this->marque_tx)) $this->marque_tx=0; - if (empty($this->marge_tx)) $this->marge_tx=0; - if (empty($this->remise)) $this->remise=0; - if (empty($this->remise_percent)) $this->remise_percent=0; - if (empty($this->info_bits)) $this->info_bits=0; - if (empty($this->product_type)) $this->product_type=0; - if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->marque_tx)) $this->marque_tx=0; + if (empty($this->marge_tx)) $this->marge_tx=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->product_type)) $this->product_type=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; - $this->db->begin(); + $this->db->begin(); - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET"; - $sql.= " description='".$this->db->escape($this->desc)."'"; - $sql.= " , tva_tx=".price2num($this->tva_tx); - $sql.= " , localtax1_tx=".price2num($this->localtax1_tx); - $sql.= " , localtax2_tx=".price2num($this->localtax2_tx); - $sql.= " , qty=".price2num($this->qty); - $sql.= " , subprice=".price2num($this->subprice).""; - $sql.= " , remise_percent=".price2num($this->remise_percent).""; - $sql.= " , price=".price2num($this->price).""; // TODO A virer - $sql.= " , remise=".price2num($this->remise).""; // TODO A virer - $sql.= " , info_bits='".$this->info_bits."'"; - if (empty($this->skip_update_total)) - { - $sql.= " , total_ht=".price2num($this->total_ht).""; - $sql.= " , total_tva=".price2num($this->total_tva).""; - $sql.= " , total_ttc=".price2num($this->total_ttc).""; - } - $sql.= " , total_localtax1=".price2num($this->total_localtax1); - $sql.= " , total_localtax2=".price2num($this->total_localtax2); - $sql.= " , info_bits=".$this->info_bits; - if ($this->date_start) { $sql.= " , date_start='".$this->db->idate($this->date_start)."'"; } - else { $sql.=' , date_start=null'; } - if ($this->date_end) { $sql.= " , date_end='".$this->db->idate($this->date_end)."'"; } - $sql.= " , product_type=".$this->product_type; - $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET"; + $sql.= " description='".$this->db->escape($this->desc)."'"; + $sql.= " , tva_tx=".price2num($this->tva_tx); + $sql.= " , localtax1_tx=".price2num($this->localtax1_tx); + $sql.= " , localtax2_tx=".price2num($this->localtax2_tx); + $sql.= " , qty=".price2num($this->qty); + $sql.= " , subprice=".price2num($this->subprice).""; + $sql.= " , remise_percent=".price2num($this->remise_percent).""; + $sql.= " , price=".price2num($this->price).""; // TODO A virer + $sql.= " , remise=".price2num($this->remise).""; // TODO A virer + $sql.= " , info_bits='".$this->info_bits."'"; + if (empty($this->skip_update_total)) + { + $sql.= " , total_ht=".price2num($this->total_ht).""; + $sql.= " , total_tva=".price2num($this->total_tva).""; + $sql.= " , total_ttc=".price2num($this->total_ttc).""; + } + $sql.= " , total_localtax1=".price2num($this->total_localtax1); + $sql.= " , total_localtax2=".price2num($this->total_localtax2); + $sql.= " , info_bits=".$this->info_bits; + if ($this->date_start) { $sql.= " , date_start='".$this->db->idate($this->date_start)."'"; } + else { $sql.=' , date_start=null'; } + if ($this->date_end) { $sql.= " , date_end='".$this->db->idate($this->date_end)."'"; } + $sql.= " , product_type=".$this->product_type; + $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); - $sql.= " WHERE rowid = ".$this->rowid; + $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("OrderLine::update sql=$sql"); + dol_syslog("OrderLine::update sql=$sql"); - $resql=$this->db->query($sql); - if ($resql) - { - if (! $notrigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result = $interface->run_triggers('LINEORDER_UPDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } + $resql=$this->db->query($sql); + if ($resql) + { + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result = $interface->run_triggers('LINEORDER_UPDATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("OrderLine::update Error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -2; - } - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("OrderLine::update Error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } - /** - * 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(); - // Clean parameters - if (empty($this->total_localtax1)) $this->total_localtax1=0; - if (empty($this->total_localtax2)) $this->total_localtax2=0; + // Clean parameters + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet 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."commandedet 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("OrderLine::update_total sql=$sql"); + dol_syslog("OrderLine::update_total sql=$sql"); - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("OrderLine::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("OrderLine::update_total Error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -2; + } + } } ?> diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5b313e49850..01880a204ac 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -512,9 +512,10 @@ class Facture extends CommonObject /** * Load an object from its id and create a new one in database * - * @param fromid Id of object to clone - * @param invertdetail Reverse sign of amounts for lines - * @return int New id of clone + * @param int $fromid Id of object to clone + * @param int $invertdetail Reverse sign of amounts for lines + * @param HookManager $hookmanager Hook manager instance + * @return int New id of clone */ function createFromClone($fromid,$invertdetail=0,$hookmanager=false) { @@ -598,10 +599,11 @@ class Facture extends CommonObject } /** - * Load an object from an order and create a new invoice into database + * Load an object from an order and create a new invoice into database * - * @param object Object source - * @return int <0 if KO, 0 if nothing done, 1 if OK + * @param Object $object Object source + * @param HookManager $hookmanager Hook manager instance + * @return int <0 if KO, 0 if nothing done, 1 if OK */ function createFromOrder($object, $hookmanager=false) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0795a760fbd..1854eef87c1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -40,9 +40,9 @@ abstract class CommonObject /** - * Check if ref is used. + * Check if ref is used. * - * @return int <0 if KO, 0 if not found, >0 if found + * @return int <0 if KO, 0 if not found, >0 if found */ function verifyNumRef() { @@ -68,13 +68,13 @@ abstract class CommonObject } /** - * Add a link between element $this->element and a contact + * Add a link between element $this->element and a contact * - * @param fk_socpeople Id of contact to link - * @param type_contact Type of contact (code or id) - * @param source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) - * @param notrigger Disable all triggers - * @return int <0 if KO, >0 if OK + * @param fk_socpeople Id of contact to link + * @param type_contact Type of contact (code or id) + * @param source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) + * @param notrigger Disable all triggers + * @return int <0 if KO, >0 if OK */ function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) { @@ -259,10 +259,10 @@ abstract class CommonObject /** * Get array of all contacts for an object * - * @param statut int Status of lines to get (-1=all) - * @param source string Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) - * @param int list 0:Return array contains all properties, 1:Return array contains just id - * @return array Array of contacts + * @param int $statut Status of lines to get (-1=all) + * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) + * @param int $list 0:Return array contains all properties, 1:Return array contains just id + * @return array Array of contacts */ function liste_contact($statut=-1,$source='external',$list=0) { @@ -713,8 +713,8 @@ abstract class CommonObject /** * Link element with a project * - * @param projid Project id to link element to - * @return int <0 if KO, >0 if OK + * @param int $projectid Project id to link element to + * @return int <0 if KO, >0 if OK */ function setProject($projectid) { @@ -1662,9 +1662,11 @@ abstract class CommonObject * Show add predefined products/services form * TODO Edit templates to use global variables and include them directly in controller call * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. - * @param $dateSelector 1=Show also date range input fields - * @param $seller Object thirdparty who sell - * @param $buyer Object thirdparty who buy + * + * @param int $dateSelector 1=Show also date range input fields + * @param Societe $seller Object thirdparty who sell + * @param Societe $buyer Object thirdparty who buy + * @param HookManager $hookmanager Hook manager instance */ function formAddPredefinedProduct($dateSelector,$seller,$buyer,$hookmanager=false) { @@ -1679,7 +1681,11 @@ abstract class CommonObject * Show add free products/services form * TODO Edit templates to use global variables and include them directly in controller call * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. - * @param $dateSelector 1=Show also date range input fields + * + * @param int $dateSelector 1=Show also date range input fields + * @param Societe $seller Object thirdparty who sell + * @param Societe $buyer Object thirdparty who buy + * @param HookManager $hookmanager Hook manager instance */ function formAddFreeProduct($dateSelector,$seller,$buyer,$hookmanager=false) { diff --git a/htdocs/core/class/cookie.class.php b/htdocs/core/class/cookie.class.php index 74b22aff19e..098c52f118c 100644 --- a/htdocs/core/class/cookie.class.php +++ b/htdocs/core/class/cookie.class.php @@ -41,7 +41,7 @@ class DolCookie /** * Constructor * - * @param string $key Personnal key + * @param string $key Personnal key */ function DolCookie($key = '') { @@ -75,7 +75,7 @@ class DolCookie } /** - * \brief Decrypt the cookie + * Decrypt the cookie */ function decryptCookie() { @@ -97,9 +97,14 @@ class DolCookie } /** - * \brief Set and create the cookie - * \param cookie Cookie name - * \param value Cookie value + * Set and create the cookie + * + * @param string $cookie Cookie name + * @param string $value Cookie value + * @param string $expire Expiration + * @param string $path Path of cookie + * @param string $domaine Domain name + * @param int $secure 0 or 1 */ function _setCookie($cookie, $value, $expire=0, $path="/", $domain="", $secure=0) { @@ -116,10 +121,10 @@ class DolCookie } /** - * \brief Get the cookie - * \param cookie Cookie name - * \param value Cookie value - * \return decryptValue Decrypted value + * Get the cookie + * + * @param string $cookie Cookie name + * @return string Decrypted value */ function _getCookie($cookie) { diff --git a/htdocs/core/class/smtps.class.php b/htdocs/core/class/smtps.class.php index 24ad42c7a78..461dd78bd32 100755 --- a/htdocs/core/class/smtps.class.php +++ b/htdocs/core/class/smtps.class.php @@ -1,6 +1,7 @@ [with a *lot* of help!] * @author Laurent Destailleur * @author Regis Houssin @@ -36,19 +28,10 @@ * @license GNU General Public Licence */ -/** - * \file htdocs/core/class/smtps.class.php - * \brief File of class to manage SMTPS email sending - */ - - -// ============================================================= -// ** Class Constants - /** * Version number of Class */ -define('SMTPs_VER', '1.15', false); +define('SMTPs_VER', '1.16', false); /** * SMTPs Success value @@ -60,10 +43,6 @@ define('SMTPs_SUCCEED', true, false); */ define('SMTPs_FAIL', false, false); - -// ============================================================= -// ** Error codes and messages - /** * Improper parameters */ @@ -79,211 +58,77 @@ define('SMTPs_INVALID_PARAMETERS', 50, false); */ class SMTPs { - // ============================================================= - // ** Class Properties - /** - * Property private string $_smtpsHost - * - * @property private string Host Name or IP of SMTP Server to use - * @name $_smtpsHost - * - * Host Name or IP of SMTP Server to use. Default value of 'localhost' - * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * + * Host Name or IP of SMTP Server to use */ var $_smtpsHost = 'localhost'; /** - * Property private int $_smtpsPort - * - * @property private int SMTP Server Port definition. 25 is default value - * @name var_name - * * SMTP Server Port definition. 25 is default value * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsPort = '25'; /** - * Property private string $_smtpsID - * - * @property private string Secure SMTP Server access ID - * @name $_smtpsID - * * Secure SMTP Server access ID * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsID = null; /** - * Property private string var $_smtpsPW - * - * @property private string Secure SMTP Server access Password - * @name var $_smtpsPW - * * Secure SMTP Server access Password * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsPW = null; /** - * Property private string var $_msgFrom - * - * @property private string Who sent the Message - * @name var $_msgFrom - * * Who sent the Message * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * */ var $_msgFrom = null; /** - * Property private string var $_msgReplyTo - * - * @property private string Where are replies and errors to be sent to - * @name var $_msgReplyTo - * * Where are replies and errors to be sent to * This can be defined via a INI file or via a setter method - * - * @access private - * @static - * @since 1.0 - * */ var $_msgReplyTo = null; /** - * Property private array var $_msgRecipients - * - * @property private array Who will the Message be sent to; TO, CC, BCC - * @name var $_msgRecipients - * * Who will the Message be sent to; TO, CC, BCC * Multi-diminsional array containg addresses the message will * be sent TO, CC or BCC - * - * @access private - * @static - * @since 1.0 - * */ var $_msgRecipients = null; /** - * Property private string var $_msgSubject - * - * @property private string Message Subject - * @name var $_msgSubject - * * Message Subject - * - * @access private - * @static - * @since 1.0 - * */ var $_msgSubject = null; /** - * Property private string var $_msgContent - * - * @property private string Message Content - * @name var $_msgContent - * * Message Content - * - * @access private - * @static - * @since 1.0 - * */ var $_msgContent = null; /** - * Property private string var $_msgXheader - * - * @property private array Custom X-Headers - * @name var $_msgXheader - * * Custom X-Headers - * - * @access private - * @static - * @since 1.0 - * */ var $_msgXheader = null; /** - * Property private string var $_smtpsCharSet - * - * @property private string Character set - * @name var $_smtpsCharSet - * * Character set * Defaulted to 'iso-8859-1' - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsCharSet = 'iso-8859-1'; /** - * Property private int var $_msgSensitivity - * - * @property private string Message Sensitivity - * @name var $_msgSensitivity - * * Message Sensitivity * Defaults to ZERO - None - * - * @access private - * @static - * @since 1.0 - * */ var $_msgSensitivity = 0; /** - * Property private array var $_arySensitivity - * - * @property private array Sensitivity string values - * @name var $_arySensitivity - * * Message Sensitivity - * - * @access private - * @static - * @since 1.0 - * */ var $_arySensitivity = array ( false, 'Personal', @@ -291,33 +136,13 @@ class SMTPs 'Company Confidential' ); /** - * Property private int var $_msgPriority - * - * @property private int Message Priority - * @name var $_msgPriority - * * Message Sensitivity * Defaults to 3 - Normal - * - * @access private - * @static - * @since 1.0 - * */ var $_msgPriority = 3; /** - * Property private array var $_aryPriority - * - * @property private array Priority string values - * @name var $_aryPriority - * * Message Priority - * - * @access private - * @static - * @since 1.0 - * */ var $_aryPriority = array ( 'Bulk', 'Highest', @@ -327,33 +152,13 @@ class SMTPs 'Lowest' ); /** - * Property private string var $_smtpsTransEncodeType - * - * @property private string Character set - * @name var $_smtpsTransEncode - * * Content-Transfer-Encoding * Defaulted to 0 - 7bit - * - * @access private - * @static - * @since 1.15 - * */ var $_smtpsTransEncodeType = 0; /** - * Property private string var $_smtpsTransEncodeTypes - * - * @property private string Character set - * @name var $_smtpsTransEncodeTypes - * * Content-Transfer-Encoding - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII '8bit', // 8-bit coding with line termination characters @@ -364,160 +169,70 @@ class SMTPs 'uuencode' ); // UUENCODE encoding /** - * Property private string var $_smtpsTransEncode - * - * @property private string Character set - * @name var $_smtpsTransEncode - * * Content-Transfer-Encoding * Defaulted to '7bit' - * - * @access private - * @static - * @since 1.15 - * @deprecated - * */ var $_smtpsTransEncode = '7bit'; /** - * Property private string var $_smtpsBoundary - * - * @property private string Boundary String for MIME seperation - * @name var $_smtpsBoundary - * * Boundary String for MIME seperation - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsBoundary = null; /** - * Property private int var $_transportType - * - * @property private int Determines the method inwhich the message are to be sent. - * @name var $_transportType - * * Determines the method inwhich the message are to be sent. * - 'sockets' [0] - conect via network to SMTP server - default * - 'pipe [1] - use UNIX path to EXE * - 'phpmail [2] - use the PHP built-in mail function - * * NOTE: Only 'sockets' is implemented - * - * @access private - * @static - * @since 1.8 - * */ var $_transportType = 0; /** - * Property private string var $_mailPath - * - * @property private string Path to the sendmail execuable - * @name var $_mailPath - * * If '$_transportType' is set to '1', then this variable is used * to define the UNIX file system path to the sendmail execuable - * - * @access private - * @static - * @since 1.8 - * */ var $_mailPath = '/usr/lib/sendmail'; /** - * Property private int var $_smtpTimeout - * - * @property private int Sets the SMTP server timeout in seconds. - * @name var $_smtpTimeout - * * Sets the SMTP server timeout in seconds. - * - * @access private - * @static - * @since 1.8 - * */ var $_smtpTimeout = 10; /** - * Property private int var $_smtpMD5 - * - * @property private boolean Determines whether to calculate message MD5 checksum. - * @name var $_smtpMD5 - * * Determines whether to calculate message MD5 checksum. - * - * @access private - * @static - * @since 1.15 - * */ var $_smtpMD5 = false; /** - * Property private array var $_smtpsErrors - * - * @property private array Class error codes and messages - * @name var $_smtpsErrors - * * Class error codes and messages - * - * @access private - * @static - * @since 1.0 - * */ var $_smtpsErrors = null; /** - * Property private boolean var $_log_level - * - * @property private integer Defines Log Level - * @name var $_log_level - * * Defines log level * 0 - no logging * 1 - connectivity logging * 2 - message generation logging * 3 - detail logging - * - * @access private - * @static - * @since 1.15 - * */ var $_log_level = 0; /** - * Property private boolean var $_debug - * - * @property private boolean Place Class in" debug" mode - * @name var $_debug - * * Place Class in" debug" mode - * - * @access private - * @static - * @since 1.8 - * */ var $_debug = false; - // DOL_CHANGE LDR var $log = ''; var $_errorsTo = ''; var $_deliveryReceipt = 0; - function setDeliveryReceipt( $_val = 0 ) + + + + function setDeliveryReceipt($_val = 0) { $this->_deliveryReceipt = $_val; } @@ -527,10 +242,10 @@ class SMTPs return $this->_deliveryReceipt; } - function setErrorsTo ( $_strErrorsTo ) + function setErrorsTo($_strErrorsTo) { if ( $_strErrorsTo ) - $this->_errorsTo = $this->_strip_email ( $_strErrorsTo ); + $this->_errorsTo = $this->_strip_email($_strErrorsTo); } function getErrorsTo ( $_part = true ) @@ -548,7 +263,7 @@ class SMTPs // ============================================================= - function setDebug ( $_vDebug = false ) + function setDebug( $_vDebug = false ) { $this->_debug = $_vDebug; } @@ -556,22 +271,10 @@ class SMTPs // ** Class methods /** - * Method public void buildRCPTlist( void ) - * * build RECIPIENT List, all addresses who will recieve this message - * - * @name buildRCPTlist() - * - * @final - * @access public - * - * @since 1.0 - * + * * @param void * @return void - * - * @TODO - * */ function buildRCPTlist() { @@ -580,33 +283,14 @@ class SMTPs } /** - * Method private bool _server_connect( void ) - * * Attempt a connection to mail server * - * @name _server_connect() - * - * @final - * @access private - * - * @since 1.14 - * * @param void * @return mixed $_retVal Boolean indicating success or failure on connection - * - * @TODO - * Modify method to generate log of Class to Mail Server communication - * */ function _server_connect() { - /** - * Default return value - * - * @var mixed $_retVal Indicates if Object was created or not - * @access private - * @static - */ + // Default return value $_retVal = true; // We have to make sure the HOST given is valid @@ -657,23 +341,10 @@ class SMTPs } /** - * Method private bool _server_authenticate( void ) - * * Attempt mail server authentication for a secure connection * - * @name _server_authenticate() - * - * @final - * @access private - * - * @since 1.14 - * * @param void * @return mixed $_retVal Boolean indicating success or failure of authentication - * - * @TODO - * Modify method to generate log of Class to Mail Server communication - * */ function _server_authenticate() { @@ -706,35 +377,17 @@ class SMTPs } /** - * Method public void sendMsg( void ) - * * Now send the message * - * @name sendMsg() - * - * @final - * @access public - * - * @since 1.0 - * * @param boolean $_bolTestMsg whether to run this method in 'Test' mode. * @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server. * @return mixed void * $_strMsg If this is run in 'Test' mode, the actual message structure will be returned - * - * @TODO - * Modify method to generate log of Class to Mail Server communication - * Impliment use of new parameters - * */ function sendMsg ( $_bolTestMsg = false, $_bolDebug = false ) { /** * Default return value - * - * @var mixed $_retVal Indicates if Object was created or not - * @access private - * @static */ $_retVal = false; @@ -772,7 +425,7 @@ class SMTPs foreach ( $this->get_RCPT_list() as $_address ) { /* - * @TODO + * TODO * After each 'RCPT TO:' is sent, we need to make sure it was kosher, * if not, the whole message will fail * If any email address fails, we will need to RESET the connection, @@ -806,8 +459,6 @@ class SMTPs // ** Basic System configuration /** - * Method public void setConfig( mixed ) - * * setConfig() is used to populate select class properties from either * a user defined INI file or the systems 'php.ini' file * @@ -829,41 +480,20 @@ class SMTPs * second time, with a path to a user INI file for other properties to be * defined. * - * @name setConfig() - * - * @final - * @access public - * - * @since 1.0 - * * @param mixed $_strConfigPath path to config file or VOID * @return void - * */ function setConfig ( $_strConfigPath = null ) { /** - * Default return value - * * Returns constructed SELECT Object string or boolean upon failure * Default value is set at TRUE - * - * @var mixed $_retVal Indicates if Object was created or not - * @access private - * @static */ $_retVal = true; // if we have a path... if ( ! empty ($_strConfigPath) ) { - /* - * @TODO The error supression around the INCLUDE has to be replaced with - * a 'real' file validation sequence. - * If there is anything wrong with the 'code' in the INI file - * the app will fail right here without any indication of the issue. - * - */ // If the path is not valid, this will NOT generate an error, // it will simply return FALSE. if ( ! @include ( $_strConfigPath ) ) @@ -893,31 +523,15 @@ class SMTPs } /** - * Method public void setTransportType( int ) - * * Determines the method inwhich the messages are to be sent. * - 'sockets' [0] - conect via network to SMTP server * - 'pipe [1] - use UNIX path to EXE * - 'phpmail [2] - use the PHP built-in mail function * - * NOTE: Not yet implemented - * - * @name setTransportType() - * - * @uses Class property $_transportType - * @final - * @access public - * - * @since 1.8 - * * @param int $_type Interger value representing Mail Transport Type * @return void - * - * @TODO - * This feature is not yet implemented - * */ - function setTransportType ( $_type = 0 ) + function setTransportType($_type = 0) { if ( ( is_numeric ($_type) ) && ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) @@ -925,52 +539,27 @@ class SMTPs } /** - * Method public int getTransportType( void ) - * * Return the method inwhich the message is to be sent. * - 'sockets' [0] - conect via network to SMTP server * - 'pipe [1] - use UNIX path to EXE * - 'phpmail [2] - use the PHP built-in mail function * - * NOTE: Not yet implemented - * - * @name getTransportType() - * - * @uses Class property $_transportType - * @final - * @access public - * - * @since 1.8 - * * @param void * @return int $_strHost Host Name or IP of the Mail Server to use - * */ - function getTransportType () + function getTransportType() { return $this->_transportType; } /** - * Method public void setMailPath( string ) - * * Path to the sendmail execuable * - * NOTE: Not yet implemented - * - * @name setMailPath() - * - * @uses Class property $_mailPath - * @final - * @access public - * - * @since 1.8 - * * @param string $_path Path to the sendmail execuable * @return void * */ - function setMailPath ( $_path ) + function setMailPath($_path) { // This feature is not yet implemented return true; @@ -980,24 +569,12 @@ class SMTPs } /** - * Method public void setHost( string ) - * * Defines the Host Name or IP of the Mail Server to use. * This is defaulted to 'localhost' - * * This is used only with 'socket' based mail transmission * - * @name setHost() - * - * @uses Class property $_smtpsHost - * @final - * @access public - * - * @since 1.0 - * * @param string $_strHost Host Name or IP of the Mail Server to use * @return void - * */ function setHost ( $_strHost ) { @@ -1006,23 +583,11 @@ class SMTPs } /** - * Method public string getHost( void ) - * * Retrieves the Host Name or IP of the Mail Server to use - * * This is used only with 'socket' based mail transmission * - * @name getHost() - * - * @uses Class property $_smtpsHost - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_strHost Host Name or IP of the Mail Server to use - * */ function getHost () { @@ -1030,24 +595,12 @@ class SMTPs } /** - * Method public void setPort( int ) - * * Defines the Port Number of the Mail Server to use * This is defaulted to '25' - * * This is used only with 'socket' based mail transmission * - * @name setPort() - * - * @uses Class property $_smtpsPort - * @final - * @access public - * - * @since 1.0 - * * @param int $_smtpsPort Port Number of the Mail Server to use * @return void - * */ function setPort ( $_intPort ) { @@ -1057,23 +610,11 @@ class SMTPs } /** - * Method public string getPort( void ) - * * Retrieves the Port Number of the Mail Server to use - * * This is used only with 'socket' based mail transmission * - * @name getPort() - * - * @uses Class property $_smtpsPort - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_smtpsPort Port Number of the Mail Server to use - * */ function getPort () { @@ -1081,21 +622,10 @@ class SMTPs } /** - * Method public void setID( string ) - * * User Name for authentication on Mail Server * - * @name setID() - * - * @uses Class property $_smtpsID - * @final - * @access public - * - * @since 1.0 - * * @param string $_strID User Name for authentication on Mail Server * @return void - * */ function setID ( $_strID ) { @@ -1103,21 +633,10 @@ class SMTPs } /** - * Method public string getID( void ) - * * Retrieves the User Name for authentication on Mail Server * - * @name getID() - * - * @uses Class property $_smtpsPort - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string _smtpsID User Name for authentication on Mail Server - * */ function getID () { @@ -1125,21 +644,10 @@ class SMTPs } /** - * Method public void setPW( string ) - * * User Password for authentication on Mail Server * - * @name setPW() - * - * @uses Class property $_smtpsPW - * @final - * @access public - * - * @since 1.0 - * * @param string $_strPW User Password for authentication on Mail Server * @return void - * */ function setPW ( $_strPW ) { @@ -1147,21 +655,10 @@ class SMTPs } /** - * Method public string getPW( void ) - * * Retrieves the User Password for authentication on Mail Server * - * @name getPW() - * - * @uses Class property $_smtpsPW - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_smtpsPW User Password for authentication on Mail Server - * */ function getPW () { @@ -1169,22 +666,11 @@ class SMTPs } /** - * Method public void setCharSet( string ) - * * Character set used for current message * Character set is defaulted to 'iso-8859-1'; * - * @name setCharSet() - * - * @uses Class property $_smtpsCharSet - * @final - * @access public - * - * @since 1.0 - * * @param string $_strCharSet Character set used for current message * @return void - * */ function setCharSet ( $_strCharSet ) { @@ -1193,21 +679,10 @@ class SMTPs } /** - * Method public string getCharSet( void ) - * * Retrieves the Character set used for current message * - * @name getCharSet() - * - * @uses Class property $_smtpsCharSet - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_smtpsCharSet Character set used for current message - * */ function getCharSet () { @@ -1215,11 +690,8 @@ class SMTPs } /** - * Method public void setTransEncode( string ) - * * Content-Transfer-Encoding, Defaulted to '7bit' * This can be changed for 2byte characers sets - * * Known Encode Types * - 7bit Simple 7-bit ASCII * - 8bit 8-bit coding with line termination characters @@ -1229,18 +701,8 @@ class SMTPs * - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" * - uuencode UUENCODE encoding * - * @name setTransEncode() - * - * @uses Class property $_smtpsTransEncode - * @final - * @access public - * - * @since 1.15 - * @deprecated - * * @param string $_strTransEncode Content-Transfer-Encoding * @return void - * */ function setTransEncode ( $_strTransEncode ) { @@ -1249,22 +711,10 @@ class SMTPs } /** - * Method public string getTransEncode( void ) - * * Retrieves the Content-Transfer-Encoding * - * @name getTransEncode() - * - * @uses Class property $_smtpsCharSet - * @final - * @access public - * - * @since 1.15 - * @deprecated - * * @param void * @return string $_smtpsTransEncode Content-Transfer-Encoding - * */ function getTransEncode () { @@ -1272,11 +722,8 @@ class SMTPs } /** - * Method public void setTransEncodeType( int ) - * * Content-Transfer-Encoding, Defaulted to '0' [ZERO] * This can be changed for 2byte characers sets - * * Known Encode Types * - [0] 7bit Simple 7-bit ASCII * - [1] 8bit 8-bit coding with line termination characters @@ -1286,44 +733,24 @@ class SMTPs * - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" * - [6] uuencode UUENCODE encoding * - * @name setTransEncodeType() - * - * @uses Class property $_smtpsTransEncodeType - * @uses Class property $_smtpsTransEncodeTypes - * @final - * @access public - * - * @since 1.15 - * * @param string $_strTransEncodeType Content-Transfer-Encoding * @return void * */ - function setTransEncodeType ( $_strTransEncodeType ) + function setTransEncodeType($_strTransEncodeType) { - if ( array_search ( $_strTransEncodeType, $this->_smtpsTransEncodeTypes ) ) + if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) $this->_smtpsTransEncodeType = $_strTransEncodeType; } /** - * Method public string getTransEncodeType( void ) - * * Retrieves the Content-Transfer-Encoding * - * @name getTransEncodeType() - * - * @uses Class property $_smtpsTransEncodeType - * @uses Class property $_smtpsTransEncodeTypes - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_smtpsTransEncode Content-Transfer-Encoding * */ - function getTransEncodeType () + function getTransEncodeType() { return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType]; } @@ -1332,21 +759,10 @@ class SMTPs // ** Message Construction /** - * Method public void setFrom( string ) - * * FROM Address from which mail will be sent * - * @name setFrom() - * - * @uses Class property $_msgFrom - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgFrom Address from which mail will be sent * @return void - * */ function setFrom ( $_strFrom ) { @@ -1355,21 +771,10 @@ class SMTPs } /** - * Method public string getFrom( void ) - * * Retrieves the Address from which mail will be sent * - * @name getFrom() - * - * @uses Class property $_msgFrom - * @final - * @access public - * - * @since 1.0 - * * @param boolean $_strip To "strip" 'Real name' from address * @return string $_msgFrom Address from which mail will be sent - * */ function getFrom ( $_part = true ) { @@ -1385,22 +790,12 @@ class SMTPs /** - * Method private array _buildAddrList( void ) - * * Inserts given addresses into structured format. * This method takes a list of given addresses, via an array * or a COMMA delimted string, and inserts them into a highly * structured array. This array is designed to remove duplicate * addresses and to sort them by Domain. * - * @name _buildAddrList() - * - * @uses Class property $_msgRecipients - * @final - * @access private - * - * @since 1.0 - * * @param string $_type TO, CC, or BCC lists to add addrresses into * @param mixed $_addrList Array or COMMA delimited string of addresses * @return void @@ -1463,15 +858,11 @@ class SMTPs } /** - * Method private array _strip_email( string ) - * * Returns an array of the various parts of an email address - * * This assumes a well formed address: * - "Real name" * - "Real Name" is optional * - if "Real Name" does not exist, the angle brackets are optional - * * This will split an email address into 4 or 5 parts. * - $_aryEmail[org] = orignal string * - $_aryEmail[real] = "real name" - if there is one @@ -1479,18 +870,10 @@ class SMTPs * - $_aryEmail[host] = "domain.tld" * - $_aryEmail[user] = "userName" * - * @name _strip_email() - * - * @final - * @access private - * - * @since 1.0 - * * @param void * @return array $_aryEmail An array of the various parts of an email address - * */ - function _strip_email ( $_strAddr ) + function _strip_email($_strAddr) { // Keep the orginal $_aryEmail['org'] = $_strAddr; @@ -1526,40 +909,17 @@ class SMTPs } /** - * Method public array get_RCPT_list( void ) - * * Returns an array of bares addresses for use with 'RCPT TO:' - * * This is a "build as you go" method. Each time this method is called * the underlaying array is destroyed and reconstructed. * - * @name get_RCPT_list() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param void * @return array $_RCPT_list Returns an array of bares addresses - * */ function get_RCPT_list() { /** - * Variable local array $_RCPT_list - * * An array of bares addresses for use with 'RCPT TO:' - * - * Reset this array each time this method is called. - * - * @var array $_RCPT_list 'RCPT TO:' address list - * @access private - * @static - * @final - * - * @since 1.8 */ unset ( $_RCPT_list ); @@ -1580,21 +940,10 @@ class SMTPs } /** - * Method public array get_email_list( string ) - * * Returns an array of addresses for a specific type; TO, CC or BCC * - * @name get_email_list() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param mixed $_which Which collection of adresses to return * @return array $_RCPT_list Array of emaill address - * */ function get_email_list( $_which = null ) { @@ -1642,21 +991,10 @@ class SMTPs } /** - * Method public void setTO( string ) - * * TO Address[es] inwhich to send mail to * - * @name setTO() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param mixed $_addrTo TO Address[es] inwhich to send mail to * @return void - * */ function setTO ( $_addrTo ) { @@ -1665,21 +1003,10 @@ class SMTPs } /** - * Method public string getTo( void ) - * * Retrieves the TO Address[es] inwhich to send mail to * - * @name getTo() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgRecipients TO Address[es] inwhich to send mail to - * */ function getTo () { @@ -1687,21 +1014,10 @@ class SMTPs } /** - * Method public void setCC( string ) - * * CC Address[es] inwhich to send mail to * - * @name setCC() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgRecipients CC Address[es] inwhich to send mail to * @return void - * */ function setCC ( $_strCC ) { @@ -1710,21 +1026,10 @@ class SMTPs } /** - * Method public string getCC( void ) - * * Retrieves the CC Address[es] inwhich to send mail to * - * @name getCC() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgRecipients CC Address[es] inwhich to send mail to - * */ function getCC () { @@ -1732,21 +1037,10 @@ class SMTPs } /** - * Method public void setBCC( string ) - * * BCC Address[es] inwhich to send mail to * - * @name setBCC() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgRecipients BCC Address[es] inwhich to send mail to * @return void - * */ function setBCC ( $_strBCC ) { @@ -1755,21 +1049,10 @@ class SMTPs } /** - * Method public string getBCC( void ) - * * Retrieves the BCC Address[es] inwhich to send mail to * - * @name getBCC() - * - * @uses Class property $_msgRecipients - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgRecipients BCC Address[es] inwhich to send mail to - * */ function getBCC () { @@ -1777,21 +1060,10 @@ class SMTPs } /** - * Method public void setSubject( string ) - * * Message Subject * - * @name setSubject() - * - * @uses Class property $_msgSubject - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgSubject Message Subject * @return void - * */ function setSubject ( $_strSubject = '' ) { @@ -1800,21 +1072,10 @@ class SMTPs } /** - * Method public string getSubject( void ) - * * Retrieves the Message Subject * - * @name getSubject() - * - * @uses Class property $_msgSubject - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgSubject Message Subject - * */ function getSubject () { @@ -1822,28 +1083,10 @@ class SMTPs } /** - * Method public string getHeader( void ) - * * Constructes and returns message header * - * @name getHeader() - * - * @uses Class method getFrom() The FROM address - * @uses Class method getTO() The TO address[es] - * @uses Class method getCC() The CC address[es] - * @uses Class method getBCC() The BCC address[es] - * @uses Class method getSubject() The Message Subject - * @uses Class method getSensitivity() Message Sensitivity - * @uses Class method getPriority() Message Priority - * - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string Complete message header - * */ function getHeader() { @@ -1888,21 +1131,10 @@ class SMTPs } /** - * Method public void setBodyContent( string, string ) - * * Message Content * - * @name setBodyContent() - * - * @uses Class property $_msgContent - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgContent Message Content * @return void - * */ function setBodyContent ( $strContent, $strType = 'plain' ) { @@ -1929,21 +1161,10 @@ class SMTPs } /** - * Method public string getBodyContent( void ) - * * Retrieves the Message Content * - * @name getBodyContent() - * - * @uses Class property $_msgContent - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgContent Message Content - * */ function getBodyContent () { @@ -1986,7 +1207,7 @@ class SMTPs // NOTE: This was 'multipart/alternative', but Windows based // mail servers have issues with this. /* - * @TODO Investigate "nested" boundary message parts + * TODO Investigate "nested" boundary message parts */ //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n"; $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary() . '"' . "\r\n"; @@ -2077,23 +1298,13 @@ class SMTPs } /** - * Method public void setAttachment( string, string, string ) - * * File attachments are added to the content array as sub-arrays, * allowing for multiple attachments for each outbound email * - * @name setBodyContent() - * - * @final - * @access public - * - * @since 1.0 - * * @param string $strContent File data to attach to message * @param string $strFileName File Name to give to attachment * @param string $strMimeType File Mime Type of attachment * @return void - * */ function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown') { @@ -2114,8 +1325,6 @@ class SMTPs // DOL_CHANGE LDR /** - * Method public void setImageInline( string ) - * * Image attachments are added to the content array as sub-arrays, * allowing for multiple images for each outbound email * @@ -2124,7 +1333,6 @@ class SMTPs * @param string $strMimeType Image Mime Type of attachment * @param string $strImageCid CID * @return void - * */ function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown') { @@ -2143,8 +1351,6 @@ class SMTPs /** - * Method public void setSensitivity( string ) - * * Message Content Sensitivity * Message Sensitivity values: * - [0] None - default @@ -2152,17 +1358,8 @@ class SMTPs * - [2] Private * - [3] Company Confidential * - * @name setSensitivity() - * - * @uses Class property $_msgSensitivity - * @final - * @access public - * - * @since 1.0 - * * @param string $_value Message Sensitivity * @return void - * */ function setSensitivity($_value = 0) { @@ -2172,8 +1369,6 @@ class SMTPs } /** - * Method public string getSensitivity( void ) - * * Returns Message Content Sensitivity string * Message Sensitivity values: * - [0] None - default @@ -2181,18 +1376,8 @@ class SMTPs * - [2] Private * - [3] Company Confidential * - * @name getSensitivity() - * - * @uses Class property $_msgSensitivity - * @uses Class property $_arySensitivity - * @final - * @access public - * - * @since 1.0 - * * @param string $_msgSensitivity Message Sensitivity * @return void - * */ function getSensitivity() { @@ -2200,8 +1385,6 @@ class SMTPs } /** - * Method public void setPriority( int ) - * * Message Content Priority * Message Priority values: * - [0] 'Bulk' @@ -2211,17 +1394,8 @@ class SMTPs * - [4] 'Low' * - [5] 'Lowest' * - * @name setPriority() - * - * @uses Class property $_msgPriority - * @final - * @access public - * - * @since 1.0 - * * @param string $_value Message Priority * @return void - * */ function setPriority ( $_value = 3 ) { @@ -2231,8 +1405,6 @@ class SMTPs } /** - * Method public string getPriority( void ) - * * Message Content Priority * Message Priority values: * - [0] 'Bulk' @@ -2242,18 +1414,8 @@ class SMTPs * - [4] 'Low' * - [5] 'Lowest' * - * @name getPriority() - * - * @uses Class property $_msgPriority - * @uses Class property $_aryPriority - * @final - * @access public - * - * @since 1.0 - * * @param string $_value Message Priority * @return void - * */ function getPriority() { @@ -2263,21 +1425,10 @@ class SMTPs } /** - * Method public void setMD5flag( boolean ) - * * Set flag which determines whether to calculate message MD5 checksum. * - * @name setMD5flag() - * - * @uses Class property $_smtpMD5 - * @final - * @access public - * - * @since 1.14 - * * @param string $_value Message Priority * @return void - * */ function setMD5flag ( $_flag = false ) { @@ -2285,21 +1436,10 @@ class SMTPs } /** - * Method public boolean getMD5flag( void ) - * * Gets flag which determines whether to calculate message MD5 checksum. * - * @name getMD5flag() - * - * @uses Class property $_smtpMD5 - * @final - * @access public - * - * @since 1.14 - * * @param void * @return string $_value Message Priority - * */ function getMD5flag ( ) { @@ -2307,23 +1447,12 @@ class SMTPs } /** - * Method public void setXheader( string ) - * * Message X-Header Content * This is a simple "insert". Whatever is given will be placed * "as is" into the Xheader array. * - * @name setXheader() - * - * @uses Class property $_msgXheader - * @final - * @access public - * - * @since 1.0 - * * @param string $strXdata Message X-Header Content * @return void - * */ function setXheader ( $strXdata ) { @@ -2332,21 +1461,10 @@ class SMTPs } /** - * Method public string getXheader( void ) - * * Retrieves the Message X-Header Content * - * @name getXheader() - * - * @uses Class property $_msgContent - * @final - * @access public - * - * @since 1.0 - * * @param void * @return string $_msgContent Message X-Header Content - * */ function getXheader () { @@ -2354,21 +1472,10 @@ class SMTPs } /** - * Method private void _setBoundary( string ) - * * Generates Random string for MIME message Boundary * - * @name _setBoundary() - * - * @uses Class property $_smtpsBoundary - * @final - * @access private - * - * @since 1.0 - * * @param void * @return void - * */ function _setBoundary() { @@ -2376,21 +1483,10 @@ class SMTPs } /** - * Method private string _getBoundary( void ) - * * Retrieves the MIME message Boundary * - * @name _getBoundary() - * - * @uses Class property $_smtpsBoundary - * @final - * @access private - * - * @since 1.0 - * * @param void * @return string $_smtpsBoundary MIME message Boundary - * */ function _getBoundary() { @@ -2407,14 +1503,8 @@ class SMTPs function server_parse($socket, $response) { /** - * Default return value - * * Returns constructed SELECT Object string or boolean upon failure * Default value is set at TRUE - * - * @var mixed $_retVal Indicates if Object was created or not - * @access private - * @static */ $_retVal = true; @@ -2452,22 +1542,11 @@ class SMTPs // ** Error handling methods /** - * Method private void _setErr( int code, string message ) - * * Defines errors codes and messages for Class * - * @name _setErr() - * - * @uses Class property $_smtpsErrors - * @final - * @access private - * - * @since 1.8 - * * @param int $_errNum Error Code Number * @param string $_errMsg Error Message * @return void - * */ function _setErr ( $_errNum, $_errMsg ) { @@ -2476,21 +1555,10 @@ class SMTPs } /** - * Method private string getErrors ( void ) - * * Returns errors codes and messages for Class * - * @name _setErr() - * - * @uses Class property $_smtpsErrors - * @final - * @access private - * - * @since 1.8 - * * @param void * @return string $_errMsg Error Message - * */ function getErrors() { @@ -2513,59 +1581,49 @@ class SMTPs // ** CSV Version Control Info /** - * $Log: smtps.class.php,v $ - * Revision 1.3 2011/09/12 07:49:59 eldy + * Revision 2011/09/12 07:49:59 eldy * Doxygen * - * Revision 1.2 2011/09/06 06:53:53 hregis + * Revision 2011/09/06 06:53:53 hregis * Fix: use dol_hash instead md5 php function * - * Revision 1.1 2011/09/03 00:14:27 eldy + * Revision 2011/09/03 00:14:27 eldy * Doxygen * - * Revision 1.4 2011/08/28 14:24:23 eldy + * Revision 2011/08/28 14:24:23 eldy * Doxygen * - * Revision 1.3 2011/08/27 19:15:41 hregis - * Fix: remove obsolete tags - * - * Revision 1.2 2011/08/26 23:40:48 eldy - * Qual: vcard is not really an external project but now a specific dolibarr class file, so i moved it into core/class - * - * Revision 1.1 2011/08/26 23:19:54 eldy - * Qual: smtps is not really an external project but now a specific dolibarr class file, so i moved it into core/class - * - * Revision 1.15 2011/07/12 22:19:02 eldy + * Revision 2011/07/12 22:19:02 eldy * Fix: Attachment fails if content was empty * - * Revision 1.14 2011/06/20 23:17:50 hregis + * Revision 2011/06/20 23:17:50 hregis * Fix: use best structure of mail * - * Revision 1.13 2010/04/13 20:58:37 eldy + * Revision 2010/04/13 20:58:37 eldy * Fix: Can provide ip address on smtps. Better error reporting. * - * Revision 1.12 2010/04/13 20:30:25 eldy + * Revision 2010/04/13 20:30:25 eldy * Fix: Can provide ip address on smtps. Better error reporting. * - * Revision 1.11 2010/01/12 13:02:07 hregis + * Revision 2010/01/12 13:02:07 hregis * Fix: missing attach-files * - * Revision 1.10 2009/11/01 14:16:30 eldy + * Revision 2009/11/01 14:16:30 eldy * Fix: Sending mail with SMTPS was not working. * - * Revision 1.9 2009/10/20 13:14:47 hregis + * Revision 2009/10/20 13:14:47 hregis * Fix: function "split" is deprecated since php 5.3.0 * - * Revision 1.8 2009/05/13 19:10:07 eldy + * Revision 2009/05/13 19:10:07 eldy * New: Can use inline images.Everything seems to work with thunderbird and webmail gmail. New to be tested on other mail browsers. * - * Revision 1.7 2009/05/13 14:49:30 eldy + * Revision 2009/05/13 14:49:30 eldy * Fix: Make code so much simpler and solve a lot of problem with new version. * - * Revision 1.2 2009/02/09 00:04:35 eldy + * Revision 2009/02/09 00:04:35 eldy * Added support for SMTPS protocol * - * Revision 1.1 2008/04/16 23:11:45 eldy + * Revision 2008/04/16 23:11:45 eldy * New: Add action "Test server connectivity" * * Revision 1.18 2007/01/12 22:17:08 ongardie @@ -2606,7 +1664,7 @@ class SMTPs * Revision 1.12 2005/08/20 12:04:30 braverock * - remove potentially binary characters from Message-ID * - add getHost to get the hostname of the mailserver - * - @todo add username to Message-ID header + * - add username to Message-ID header * * Revision 1.11 2005/08/20 11:49:48 braverock * - fix typos in boundary diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 833561c4591..96cc54be32d 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1431,10 +1431,11 @@ class CommandeFournisseur extends Commande /** * Update notes - * @param user - * @param note - * @param note_public - * @return int <0 if KO, >=0 if OK + * + * @param User $user Object user + * @param string $note Private note + * @param string $note_public Public note + * @return int <0 if KO, >=0 if OK * TODO Use instead update_note_public and update_note */ function UpdateNote($user, $note, $note_public) @@ -1548,14 +1549,15 @@ class CommandeFournisseur extends Commande /** * 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 localtax1 Localtax1 tax + * @param localtax2 Localtax2 tax * @param price_base_type Type of price base * @param info_bits Miscellanous informations * @param type Type of line (0=product, 1=service) diff --git a/htdocs/includes/boxes/box_external_rss.php b/htdocs/includes/boxes/box_external_rss.php index 70a7dc3cc0e..b57c5fa99e4 100644 --- a/htdocs/includes/boxes/box_external_rss.php +++ b/htdocs/includes/boxes/box_external_rss.php @@ -58,10 +58,10 @@ class box_external_rss extends ModeleBoxes { /** * Load information for box into memory to show them later with this->showBox method. * - * @param $max Max numbe rof records to load - * @param $cachedelay Delay we accept for cache file + * @param int $max Max numbe rof records to load + * @param int $cachedelay Delay we accept for cache file */ - function loadBox($max=5, $cachdelay=3600) + function loadBox($max=5, $cachedelay=3600) { global $user, $langs, $conf; $langs->load("boxes"); @@ -80,7 +80,7 @@ class box_external_rss extends ModeleBoxes { $url=@constant("EXTERNAL_RSS_URLRSS_".$site); $rssparser=new RssParser($db); - $result = $rssparser->parser($url, $this->max, $cachdelay, $conf->externalrss->dir_temp); + $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp); // INFO on channel $description=$rssparser->getDescription(); diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index f3619e0d992..dfd948bd4d8 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -42,7 +42,8 @@ abstract class ModelePDFCommandes extends CommonDocGenerator /** * Return list of active generation modules - * @param $db Database handler + * + * @param DoliDB $db Database handler */ function liste_modeles($db) { @@ -70,6 +71,7 @@ class ModeleNumRefCommandes var $error=''; /** Return if a module can be used or not + * * @return boolean true if module can be used */ function isEnabled() @@ -78,6 +80,7 @@ class ModeleNumRefCommandes } /** Renvoie la description par defaut du modele de numerotation + * * @return string Texte descripif */ function info() @@ -88,6 +91,7 @@ class ModeleNumRefCommandes } /** Renvoie un exemple de numerotation + * * @return string Example */ function getExample() @@ -98,6 +102,7 @@ class ModeleNumRefCommandes } /** Test si les numeros deja en vigueur dans la base ne provoquent pas de conflits qui empecheraient cette numerotation de fonctionner. + * * @return boolean false si conflit, true si ok */ function canBeActivated() @@ -106,6 +111,7 @@ class ModeleNumRefCommandes } /** Renvoie prochaine valeur attribuee + * * @return string Valeur */ function getNextValue() @@ -115,6 +121,7 @@ class ModeleNumRefCommandes } /** Renvoie version du module numerotation + * * @return string Valeur */ function getVersion() @@ -131,15 +138,17 @@ class ModeleNumRefCommandes /** - * Cree un bon de commande sur disque en fonction d'un modele - * @param db data base object - * @param object object order - * @param modele force le modele a utiliser ('' to not force) - * @param outputlangs objet lang a utiliser pour traduction - * @param hidedetails Hide details of lines - * @param hidedesc Hide description - * @param hideref Hide ref - * @return int 0 if KO, 1 if OK + * Create a document onto disk accordign to template module. + * + * @param DoliDB $db Database handler + * @param Object $object Object order + * @param string $modele Force le modele a utiliser ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param HookManager $hookmanager Hook manager instance + * @return int 0 if KO, 1 if OK */ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { diff --git a/htdocs/includes/modules/facture/modules_facture.php b/htdocs/includes/modules/facture/modules_facture.php index 2a5de802404..99e265d3d9c 100644 --- a/htdocs/includes/modules/facture/modules_facture.php +++ b/htdocs/includes/modules/facture/modules_facture.php @@ -130,16 +130,18 @@ class ModeleNumRefFactures /** - * Cree une facture sur le disque en fonction du modele de FACTURE_ADDON_PDF - * @param db objet base de donnees - * @param object Object invoice - * @param message message - * @param modele force le modele a utiliser ('' to not force) - * @param outputlangs objet lang a utiliser pour traduction - * @param hidedetails Hide details of lines - * @param hidedesc Hide description - * @param hideref Hide ref - * @return int <0 if KO, >0 if OK + * Create a document onto disk accordign to template module. + * + * @param DoliDB $db Database handler + * @param Object $object Object invoice + * @param string $message message + * @param string $modele Force le modele a utiliser ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param HookManager $hookmanager Hook manager instance + * @return int <0 if KO, >0 if OK */ function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { diff --git a/htdocs/includes/modules/member/labels/modules_labels.php b/htdocs/includes/modules/member/labels/modules_labels.php index d1346cd1b6a..1bd63add071 100644 --- a/htdocs/includes/modules/member/labels/modules_labels.php +++ b/htdocs/includes/modules/member/labels/modules_labels.php @@ -39,8 +39,9 @@ class ModelePDFLabels /** - * \brief Return list of active generation modules - * \param $db Database handler + * Return list of active generation modules + * + * @param DoliDB $db Database handler */ function liste_modeles($db) { @@ -58,13 +59,14 @@ class ModelePDFLabels /** - * \brief Cree un fichier de cartes de visites en fonction du modele de ADHERENT_CARDS_ADDON_PDF - * \param db objet base de donnee - * \param id id de la facture a creer - * \param message message - * \param modele force le modele a utiliser ('' to not force) - * \param outputlangs objet lang a utiliser pour traduction - * \return int <0 if KO, >0 if OK + * Create a document onto disk accordign to template module + * + * @param DoliDB $db objet base de donnee + * @param int $id id de la facture a creer + * @param string $message message + * @param string $modele force le modele a utiliser ('' to not force) + * @param string $outputlangs objet lang a utiliser pour traduction + * @return int <0 if KO, >0 if OK */ function members_label_pdf_create($db, $arrayofmembers, $modele, $outputlangs) { diff --git a/htdocs/includes/modules/propale/modules_propale.php b/htdocs/includes/modules/propale/modules_propale.php index 536066a3f18..0ae70be6e0e 100644 --- a/htdocs/includes/modules/propale/modules_propale.php +++ b/htdocs/includes/modules/propale/modules_propale.php @@ -128,15 +128,17 @@ class ModeleNumRefPropales /** - * Cree une propale sur disque en fonction du modele de PROPALE_ADDON_PDF - * @param db Database handler - * @param object Object proposal - * @param modele Force model to use ('' to not force) - * @param outputlangs Object langs to use for output - * @param hidedetails Hide details of lines - * @param hidedesc Hide description - * @param hideref Hide ref - * @return int 0 if KO, 1 if OK + * Create a document onto disk accordign to template module. + * + * @param DoliDB $db Database handler + * @param Object $object Object proposal + * @param string $modele Force model to use ('' to not force) + * @param Translate $outputlangs Object langs to use for output + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param HookManager $hookmanager Hook manager instance + * @return int 0 if KO, 1 if OK */ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { diff --git a/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php b/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php index 0cbd6a2d166..4db49f84484 100755 --- a/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php +++ b/htdocs/includes/modules/supplier_invoice/modules_facturefournisseur.php @@ -34,8 +34,9 @@ abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator /** - * \brief Return list of active generation modules - * \param $db Database handler + * Return list of active generation modules + * + * @param DoliDB $db Database handler */ function liste_modeles($db) { @@ -53,12 +54,14 @@ abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator } /** - * Create object on disk - * @param db objet base de donnee - * @param object object supplier invoice - * @param model force le modele a utiliser ('' to not force) - * @param outputlangs objet lang a utiliser pour traduction - * @return int 0 si KO, 1 si OK + * Create object on disk. + * + * @param DoliDB $db objet base de donnee + * @param Object $object object supplier invoice + * @param string $model force le modele a utiliser ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param HookManager $hookmanager Hook manager instance + * @return int 0 if KO, 1 if OK */ function supplier_invoice_pdf_create($db, $object, $model, $outputlangs) { diff --git a/htdocs/includes/modules/supplier_order/modules_commandefournisseur.php b/htdocs/includes/modules/supplier_order/modules_commandefournisseur.php index 743d2f9bd45..37bdfb7d965 100644 --- a/htdocs/includes/modules/supplier_order/modules_commandefournisseur.php +++ b/htdocs/includes/modules/supplier_order/modules_commandefournisseur.php @@ -70,6 +70,7 @@ class ModeleNumRefSuppliersOrders var $error=''; /** Return if a module can be used or not + * * @return boolean true if module can be used */ function isEnabled() @@ -78,6 +79,7 @@ class ModeleNumRefSuppliersOrders } /** Renvoie la description par defaut du modele de numerotation + * * @return string Texte descripif */ function info() @@ -88,6 +90,7 @@ class ModeleNumRefSuppliersOrders } /** Renvoie un exemple de numerotation + * * @return string Example */ function getExample() @@ -98,6 +101,7 @@ class ModeleNumRefSuppliersOrders } /** Test si les numeros deja en vigueur dans la base ne provoquent pas de conflits qui empecheraient cette numerotation de fonctionner. + * * @return boolean false si conflit, true si ok */ function canBeActivated() @@ -106,6 +110,7 @@ class ModeleNumRefSuppliersOrders } /** Renvoie prochaine valeur attribuee + * * @return string Valeur */ function getNextValue() @@ -115,6 +120,7 @@ class ModeleNumRefSuppliersOrders } /** Renvoie version du module numerotation + * * @return string Valeur */ function getVersion() @@ -131,15 +137,17 @@ class ModeleNumRefSuppliersOrders /** - * Cree un bon de commande sur disque en fonction d'un modele - * @param db data base object - * @param object object order - * @param modele force le modele a utiliser ('' to not force) - * @param outputlangs objet lang a utiliser pour traduction - * @param hidedetails Hide details of lines - * @param hidedesc Hide description - * @param hideref Hide ref - * @return int 0 if KO, 1 if OK + * Create a document onto disk accordign to template module. + * + * @param DoliDB $db data base object + * @param Object $object object order + * @param string $modele force le modele a utiliser ('' to not force) + * @param Translate $outputlangs Objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param HookManager $hookmanager Hook manager instance + * @return int 0 if KO, 1 if OK */ function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) { diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index 3b839d817e3..74255c7c1f8 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -673,7 +673,8 @@ pFooter($error,$setuplang,'jsinfo'); /** * Create main file. No particular permissions are set by installer. * - * @param mainfile Path to conf file to generate/update + * @param string $mainfile Full path name of main file to generate/update + * @param string $main_dir Full path name to main.inc.php file */ function write_main_file($mainfile,$main_dir) { @@ -693,7 +694,8 @@ function write_main_file($mainfile,$main_dir) /** * Create master file. No particular permissions are set by installer. * - * @param masterfile Path to conf file to generate/update + * @param string $masterfile Full path name of master file to generate/update + * @param string $main_dir Full path name to master.inc.php file */ function write_master_file($masterfile,$main_dir) { diff --git a/htdocs/lib/antivir.class.php b/htdocs/lib/antivir.class.php index 4ec45f0d359..cbf71e70839 100644 --- a/htdocs/lib/antivir.class.php +++ b/htdocs/lib/antivir.class.php @@ -39,7 +39,7 @@ class AntiVir /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler * @return AntiVir */ function AntiVir($db) @@ -50,6 +50,7 @@ class AntiVir /** * Scan a file with antivirus. * This function runs the command defined in setup. This antivirus command must return 0 if OK. + * * @param file File to scan * @return int <0 if KO (-98 if error, -99 if virus), 0 if OK */ diff --git a/htdocs/lib/databases/mssql.lib.php b/htdocs/lib/databases/mssql.lib.php index e65412d6200..dd2abfc881f 100644 --- a/htdocs/lib/databases/mssql.lib.php +++ b/htdocs/lib/databases/mssql.lib.php @@ -800,15 +800,16 @@ class DoliDb } /** - \brief Cree une table - \param table Nom de la table - \param fields Tableau associatif [nom champ][tableau des descriptions] - \param primary_key Nom du champ qui sera la clef primaire - \param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur - \param fulltext Tableau des Nom de champs qui seront indexes en fulltext - \param key Tableau des champs cles noms => valeur - \param type Type de la table - \return int <0 si KO, >=0 si OK + * Create a table into database + * + * @param string $table Nom de la table + * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param string $primary_key Nom du champ qui sera la clef primaire + * @param string $type Type de la table + * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur + * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext + * @param string $keys Tableau des champs cles noms => valeur + * @return int <0 if KO, >=0 if OK */ function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="") { diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index bef1c28db4c..b3c6815fa54 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -842,15 +842,16 @@ class DoliDb } /** - * \brief Cree une table - * \param table Nom de la table - * \param fields Tableau associatif [nom champ][tableau des descriptions] - * \param primary_key Nom du champ qui sera la clef primaire - * \param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur - * \param fulltext Tableau des Nom de champs qui seront indexes en fulltext - * \param key Tableau des champs cles noms => valeur - * \param type Type de la table - * \return int <0 si KO, >=0 si OK + * Create a table into database + * + * @param string $table Nom de la table + * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param string $primary_key Nom du champ qui sera la clef primaire + * @param string $type Type de la table + * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur + * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext + * @param string $keys Tableau des champs cles noms => valeur + * @return int <0 if KO, >=0 if OK */ function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="") { diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index b39d03a7de6..bb8b82859e4 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -687,9 +687,10 @@ class DoliDb } /** - * \brief Recupere l'id genere par le dernier INSERT. - * \param tab Nom de la table concernee par l'insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql - * \return int id + * Recupere l'id genere par le dernier INSERT. + * + * @param tab Nom de la table concernee par l'insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql + * @return int id */ function last_insert_id($tab) { @@ -699,6 +700,7 @@ class DoliDb /** * Encrypt sensitive data in database * Warning: This function includes the escape, so it must use direct value + * * @param fieldorvalue Field name or value to encrypt * @param withQuotes Return string with quotes * @return return XXX(field) or XXX('value') or field or 'value' @@ -852,15 +854,16 @@ class DoliDb } /** - * \brief Cree une table - * \param table Nom de la table - * \param fields Tableau associatif [nom champ][tableau des descriptions] - * \param primary_key Nom du champ qui sera la clef primaire - * \param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur - * \param fulltext Tableau des Nom de champs qui seront indexes en fulltext - * \param key Tableau des champs cles noms => valeur - * \param type Type de la table - * \return int <0 si KO, >=0 si OK + * Create a table into database + * + * @param string $table Nom de la table + * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param string $primary_key Nom du champ qui sera la clef primaire + * @param string $type Type de la table + * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur + * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext + * @param string $keys Tableau des champs cles noms => valeur + * @return int <0 if KO, >=0 if OK */ function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="") { diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index a0d2548028f..9632004091e 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -989,17 +989,16 @@ class DoliDb /** - * Cree une table + * Create a table into database * - * @param table Nom de la table - * @param fields Tableau associatif [nom champ][tableau des descriptions] - * @param primary_key Nom du champ qui sera la clef primaire - * @param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur - * @param fulltext Tableau des Nom de champs qui seront indexes en fulltext - * @param key Tableau des champs cles noms => valeur - * @param type Type de la table - * @return int <0 si KO, >=0 si OK - * TODO + * @param string $table Nom de la table + * @param array $fields Tableau associatif [nom champ][tableau des descriptions] + * @param string $primary_key Nom du champ qui sera la clef primaire + * @param string $type Type de la table + * @param array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur + * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext + * @param string $keys Tableau des champs cles noms => valeur + * @return int <0 if KO, >=0 if OK */ function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="") { @@ -1060,7 +1059,7 @@ class DoliDb $sql .=") type=".$type; dol_syslog($sql,LOG_DEBUG); - if(! $this -> query($sql)) + if(! $this->query($sql)) return -1; else return 1; diff --git a/htdocs/lib/doleditor.class.php b/htdocs/lib/doleditor.class.php index dd17de84744..d7219283079 100644 --- a/htdocs/lib/doleditor.class.php +++ b/htdocs/lib/doleditor.class.php @@ -48,19 +48,19 @@ class DolEditor /** * Create an object to build an HTML area to edit a large string content * - * @param htmlname HTML name of WYSIWIG form - * @param content Content of WYSIWIG form - * @param width Width in pixel of edit area (auto by default) - * @param height Height in pixel of edit area (200px by default) - * @param toolbarname Name of bar set to use ('Full', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_mailings') - * @param toolbarlocation Where bar is stored : - * 'In' each window has its own toolbar - * 'Out:name' share toolbar into the div called 'name' - * @param toolbarstartexpanded Bar is visible or not at start - * @param uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content. - * @param okforextandededitor True=Allow usage of extended editor tool (like fckeditor) - * @param rows Size of rows for textarea tool - * @param cols Size of cols for textarea tool + * @param string $htmlname HTML name of WYSIWIG form + * @param string $content Content of WYSIWIG form + * @param int $width Width in pixel of edit area (auto by default) + * @param int $height Height in pixel of edit area (200px by default) + * @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_mailings') + * @param string $toolbarlocation Where bar is stored : + * 'In' each window has its own toolbar + * 'Out:name' share toolbar into the div called 'name' + * @param boolean $toolbarstartexpanded Bar is visible or not at start + * @param int $uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content. + * @param int $okforextendededitor True=Allow usage of extended editor tool (like fckeditor) + * @param int $rows Size of rows for textarea tool + * @param int $cols Size of cols for textarea tool */ function DolEditor($htmlname,$content,$width='',$height=200,$toolbarname='Basic',$toolbarlocation='In',$toolbarstartexpanded=false,$uselocalbrowser=true,$okforextendededitor=true,$rows=0,$cols=0) { diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 454502c4235..2fa52305e0f 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1586,13 +1586,13 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8') /** * Show a picto called object_picto (generic function) * - * @param alt Text of alt on image - * @param picto Name of image to show object_picto (example: user, group, action, bill, contract, propal, product, ...) - * For external modules use imagename@mymodule to search into directory "img" of module. - * @param options Add more attribute on img tag - * @param pictoisfullpath If 1, image path is a full path - * @return string Return img tag - * @see img_picto, img_picto_common + * @param string $alt Text of alt on image + * @param string $picto Name of image to show object_picto (example: user, group, action, bill, contract, propal, product, ...) + * For external modules use imagename@mymodule to search into directory "img" of module. + * @param string $options Add more attribute on img tag + * @param int $pictoisfullpath If 1, image path is a full path + * @return string Return img tag + * @see #img_picto, #img_picto_common */ function img_object($alt, $picto, $options='', $pictoisfullpath=0) { @@ -1624,16 +1624,16 @@ function img_object($alt, $picto, $options='', $pictoisfullpath=0) /** * Show picto whatever it's its name (generic function) * - * @param alt Text on alt and title of image - * @param picto Name of image file to show ('filenew', ...) - * If no extension provided, we use '.png'. Image must be stored into theme/xxx/img directory. - * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img - * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img - * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1) - * @param options Add more attribute on img tag (For example 'style="float: right"') - * @param pictoisfullpath If 1, image path is a full path - * @return string Return img tag - * @see img_object, img_picto_common + * @param string $alt Text on alt and title of image + * @param string $picto Name of image file to show ('filenew', ...) + * If no extension provided, we use '.png'. Image must be stored into theme/xxx/img directory. + * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img + * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img + * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1) + * @param string $options Add more attribute on img tag (For example 'style="float: right"') + * @param int $pictoisfullpath If 1, image path is a full path + * @return string Return img tag + * @see #img_object, #img_picto_common */ function img_picto($alt, $picto, $options='', $pictoisfullpath=0) { @@ -1665,12 +1665,12 @@ function img_picto($alt, $picto, $options='', $pictoisfullpath=0) /** * Show picto (generic function) * - * @param alt Text on alt and title of image - * @param picto Name of image file to show (If no extension provided, we use '.png'). Image must be stored into htdocs/theme/common directory. - * @param options Add more attribute on img tag - * @param pictoisfullpath If 1, image path is a full path - * @return string Return img tag - * @see img_object, img_picto + * @param string $alt Text on alt and title of image + * @param string $picto Name of image file to show (If no extension provided, we use '.png'). Image must be stored into htdocs/theme/common directory. + * @param string $options Add more attribute on img tag + * @param int $pictoisfullpath If 1, image path is a full path + * @return string Return img tag + * @see #img_object, #img_picto */ function img_picto_common($alt, $picto, $options='', $pictoisfullpath=0) { diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php index e0d2f0566b7..8735706696b 100644 --- a/htdocs/lib/pdf.lib.php +++ b/htdocs/lib/pdf.lib.php @@ -724,6 +724,7 @@ function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hide /** * Return line description translated in outputlangs and encoded in UTF8 + * * @param object Object * @param i Current line number * @param outputlangs Object langs for output @@ -856,9 +857,12 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl /** * Return line num - * @param object Object - * @param $i Current line number - * @param outputlangs Object langs for output + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -877,9 +881,12 @@ function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0,$hookmanager=fals /** * Return line product ref - * @param object Object - * @param $i Current line number - * @param outputlang Object lang for output + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -897,9 +904,12 @@ function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0,$hookmanager=fals /** * Return line ref_supplier - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -917,13 +927,12 @@ function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0,$hookman /** * Return line vat rate - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -942,13 +951,12 @@ function pdf_getlinevatrate($object,$i,$outputlangs,$hidedetails=0,$hookmanager= /** * Return line unit price excluding tax - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -967,13 +975,12 @@ function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanage /** * Return line quantity - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -995,13 +1002,12 @@ function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0,$hookmanager=fals /** * Return line quantity asked - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -1023,13 +1029,12 @@ function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0,$hookmanage /** * Return line quantity shipped - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -1051,13 +1056,12 @@ function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0,$hookmana /** * Return line keep to ship quantity - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -1079,13 +1083,12 @@ function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0,$hookm /** * Return line remise percent - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -1109,13 +1112,12 @@ function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0,$hookma /** * Return line total excluding tax - * @param object Object - * @param i Current line number - * @param outputlangs Object langs for output - * @param hidedetails Hide value - * 0 = no - * 1 = yes - * 2 = just special lines + * + * @param Object $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @param HookManager $hookmanager Hook manager instance */ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanager=false) { @@ -1141,9 +1143,11 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0,$hookman /** * Return total quantity of products and/or services - * @param object Object - * @param type Type of line (all=all, 0=product, 1=service, 9=other) - * @param outputlangs Object langs for output + * + * @param Object $object Object + * @param string $type Type + * @param Translate $outputlangs Object langs for output + * @param HookManager $hookmanager Hook manager instance */ function pdf_getTotalQty($object,$type='',$outputlangs,$hookmanager=false) { @@ -1182,8 +1186,9 @@ function pdf_getTotalQty($object,$type='',$outputlangs,$hookmanager=false) /** * Convert a currency code into its symbol + * * @param pdf PDF object - * @param currency_code + * @param currency_code Currency code * @param string Currency symbol encoded into UTF8 */ function pdf_getCurrencySymbol(&$pdf, $currency_code) diff --git a/htdocs/lib/sendings.lib.php b/htdocs/lib/sendings.lib.php index 6f474edc24f..0ee728e22ec 100644 --- a/htdocs/lib/sendings.lib.php +++ b/htdocs/lib/sendings.lib.php @@ -92,7 +92,9 @@ function delivery_prepare_head($object) /** * List sendings and receive receipts * - * @param $option + * @param string $origin Origin + * @param int $origin_id Origin id + * @param string $filter Filter * @return */ function show_list_sending_receive($origin='commande',$origin_id,$filter='') diff --git a/htdocs/lib/xcal.lib.php b/htdocs/lib/xcal.lib.php index 6801ddcff3f..a25c3490bc9 100644 --- a/htdocs/lib/xcal.lib.php +++ b/htdocs/lib/xcal.lib.php @@ -481,7 +481,7 @@ function CalEncode($line) * Encode into vcal format * * @param string $str String to convert - * @param int forcal 1=For cal + * @param int $forcal 1=For cal * @return string String converted */ function QPEncode($str,$forcal=0) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 43d5dc40b8d..05465a782c3 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -62,8 +62,13 @@ if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 } } -// Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST) -function test_sql_and_script_inject($val,$get) +/** + * Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST) + * + * @param string $val Value + * @param string $get 1=GET, 0=POST + */ +function test_sql_and_script_inject($val, $get) { $sql_inj = 0; // For SQL Injection @@ -80,8 +85,13 @@ function test_sql_and_script_inject($val,$get) if ($get) $sql_inj += preg_match('/"/i', $val); // We refused " in GET parameters value return $sql_inj; } -// Security: Return true if OK, false otherwise -function analyse_sql_and_script(&$var,$get) +/** + * Security: Return true if OK, false otherwise + * + * @param string $var Variable name + * @param string $get 1=GET, 0=POST + */ +function analyse_sql_and_script(&$var, $get) { if (is_array($var)) { @@ -638,10 +648,10 @@ if (! defined('NOLOGIN')) $conf->theme=$user->conf->MAIN_THEME; $conf->css = "/theme/".$conf->theme."/style.css.php"; } - + // If theme support optim like flip-hide left menu and we use a smartphone, we force it if (! empty($conf->global->MAIN_SMARTPHONE_OPTIM) && $conf->browser->phone && $conf->theme == 'eldy') $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT='forced'; - + // Set javascript option if (! GETPOST('nojs')) // If javascript was not disabled on URL { @@ -815,7 +825,6 @@ function top_httphead() * * @param string $head Optionnal head lines * @param string $title HTML title - * @param string $help_url Link to online url help to show on left menu * @param int $disablejs More content into html header * @param int $disablehead More content into html header * @param array $arrayofjs Array of complementary js files @@ -1057,14 +1066,14 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs /** * Show an HTML header + a BODY + The top menu bar * - * @param string head Lines in the HEAD - * @param string title Title of web page - * @param string target Target to use in menu links - * @param int disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax) - * @param int disablehead Do not output head section - * @param array arrayofjs Array of js files to add in header - * @param array arrayofcss Array of css files to add in header - * @param string morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) + * @param string $head Lines in the HEAD + * @param string $title Title of web page + * @param string $target Target to use in menu links + * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax) + * @param int $disablehead Do not output head section + * @param array $arrayofjs Array of js files to add in header + * @param array $arrayofcss Array of css files to add in header + * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) */ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index d0354155633..5df3cd303c1 100755 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.class.php @@ -43,10 +43,10 @@ class ActionsCardProduct extends Product /** * Constructor * - * @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) + * @param DoliDB $DB Handler acces base de donnees + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsCardIndividual($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/product/canvas/service/actions_card_service.class.php b/htdocs/product/canvas/service/actions_card_service.class.php index 5b162b43891..be3a65185f6 100755 --- a/htdocs/product/canvas/service/actions_card_service.class.php +++ b/htdocs/product/canvas/service/actions_card_service.class.php @@ -43,10 +43,10 @@ class ActionsCardService extends Product /** * Constructor * - * @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) + * @param DoliDB $DB Handler acces base de donnees + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsCardIndividual($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 0d16d09f571..7add0d7b62c 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -47,10 +47,10 @@ abstract class ActionsCardCommon /** * Constructor * - * @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) + * @param DoliDB $DB Database handler + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsCardCommon($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/societe/canvas/default/actions_card_default.class.php b/htdocs/societe/canvas/default/actions_card_default.class.php index 839b88704ab..ed95c25e722 100644 --- a/htdocs/societe/canvas/default/actions_card_default.class.php +++ b/htdocs/societe/canvas/default/actions_card_default.class.php @@ -37,10 +37,10 @@ class ActionsCardDefault extends ActionsCardCommon /** * Constructor * - * @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) + * @param DoliDB $DB Handler acces base de donnees + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsCardDefault($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/societe/canvas/individual/actions_card_individual.class.php b/htdocs/societe/canvas/individual/actions_card_individual.class.php index f717eb7bd6a..e1db7a5efef 100644 --- a/htdocs/societe/canvas/individual/actions_card_individual.class.php +++ b/htdocs/societe/canvas/individual/actions_card_individual.class.php @@ -36,10 +36,10 @@ class ActionsCardIndividual extends ActionsCardCommon /** * Constructor * - * @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) + * @param DoliDB $DB Handler acces base de donnees + * @param string $targetmodule Name of directory of module where canvas is stored + * @param string $canvas Name of canvas + * @param string $card Name of tab (sub-canvas) */ function ActionsCardIndividual($DB,$targetmodule,$canvas,$card) { diff --git a/htdocs/societe/class/address.class.php b/htdocs/societe/class/address.class.php index 3f713b2d459..21f8d27db13 100644 --- a/htdocs/societe/class/address.class.php +++ b/htdocs/societe/class/address.class.php @@ -64,11 +64,12 @@ class Address } /** - * \brief Cree l'adresse de la societe en base - * \param user Objet utilisateur qui demande la creation - * \return int 0 si ok, < 0 si erreur + * Create address into database + * + * @param socid Company socid + * @param user Object user making creation + * @return int 0 if OK, < 0 if KO */ - function create($socid, $user='') { global $langs,$conf; @@ -135,8 +136,9 @@ class Address /** - * \brief Verification lors de la modification de l'adresse - * \return 0 si ok, < 0 en cas d'erreur + * Verification lors de la modification de l'adresse + * + * @return int 0 if OK, <0 if KO */ function verify() { @@ -153,10 +155,12 @@ class Address /** - * \brief Mise a jour des parametres de l'adresse - * \param id id address - * \param user Utilisateur qui demande la mise a jour - * \return int <0 si ko, >=0 si ok + * Mise a jour des parametres de l'adresse + * + * @param id id address + * @param socid id third party + * @param user Utilisateur qui demande la mise a jour + * @return int <0 si ko, >=0 si ok */ function update($id, $socid, $user='') { @@ -401,8 +405,10 @@ class Address /** - * \brief Suppression d'une adresse - * \param id id de la societe a supprimer + * Suppression d'une adresse + * + * @param id id de la societe a supprimer + * @param socid id third party */ function delete($id,$socid) { @@ -421,9 +427,10 @@ class Address } - /* - * \brief Charge les informations d'ordre info dans l'objet societe - * \param id id de la societe a charger + /** + * Charge les informations d'ordre info dans l'objet societe + * + * @param id id de la societe a charger */ function info($id) {