diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 1651407d746..565e63fd749 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -125,8 +125,8 @@ class FactureRec extends Facture $sql.= ", '".$facsrc->socid."'"; $sql.= ", ".$conf->entity; $sql.= ", ".$this->db->idate($now); - $sql.= ", '".$facsrc->amount."'"; - $sql.= ", '".$facsrc->remise."'"; + $sql.= ", ".(!empty($facsrc->amount)?$facsrc->amount:'0'); + $sql.= ", ".(!empty($facsrc->remise)?$this->remise:'0'); $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL"); $sql.= ", '".$user->id."'"; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index dc438d2b929..bb37d9eeeb8 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1286,7 +1286,6 @@ class Project extends CommonObject */ function select_element($Tablename) { - global $db; $projectkey="fk_projet"; switch ($Tablename) @@ -1316,25 +1315,27 @@ class Project extends CommonObject } $sql.= " ORDER BY ref DESC"; - dol_syslog("Project.Lib::select_element sql=".$sql); + dol_syslog(get_class($this).'::select_element sql='.$sql,LOG_DEBUG); - $resql=$db->query($sql); + $resql=$this->db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $this->db->num_rows($resql); $i = 0; if ($num > 0) { $sellist = ''; } return $sellist ; + + $this->db->free($resql); } } @@ -1347,8 +1348,8 @@ class Project extends CommonObject */ function update_element($TableName, $ElementSelectId) { - global $db; - $sql="update ".MAIN_DB_PREFIX.$TableName; + $sql="UPDATE ".MAIN_DB_PREFIX.$TableName; + if ($TableName=="actioncomm") { $sql.= " SET fk_project=".$this->id; @@ -1359,7 +1360,17 @@ class Project extends CommonObject $sql.= " SET fk_projet=".$this->id; $sql.= " WHERE rowid=".$ElementSelectId; } - $resql=$db->query($sql); + + dol_syslog(get_class($this)."::update_element sql=" . $sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::update_element error : " . $this->error, LOG_ERR); + return -1; + }else { + return 1; + } + } } diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index e47c36fa191..3f686bdecaf 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -46,8 +46,10 @@ if (! empty($conf->commande->enabled)) $langs->load("orders"); if (! empty($conf->propal->enabled)) $langs->load("propal"); if (! empty($conf->ficheinter->enabled)) $langs->load("interventions"); -$projectid=GETPOST('id'); -$ref=GETPOST('ref'); +$projectid=GETPOST('id','int'); +$ref=GETPOST('ref','alpha'); +$action=GETPOST('action','alpha'); + if ($projectid == '' && $ref == '') { dol_print_error('','Bad parameter'); @@ -62,6 +64,8 @@ if ($ref) { $project->fetch(0,$ref); $projectid=$project->id; +}else { + $project->fetch($projectid); } // Security check @@ -82,7 +86,7 @@ $form = new Form($db); $userstatic=new User($db); $project = new Project($db); -$project->fetch($_GET["id"],$_GET["ref"]); +$project->fetch($projectid,$ref); $project->societe->fetch($project->societe->id); // To verify role of users @@ -191,7 +195,10 @@ if ($action=="addelement") { $tablename = GETPOST("tablename"); $elementselectid = GETPOST("elementselect"); - $project->update_element($tablename, $elementselectid); + $result=$project->update_element($tablename, $elementselectid); + if ($result<0) { + setEventMessage($mailchimp->error,'errors'); + } } foreach ($listofreferent as $key => $value)