diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 059d8dffd4a956a247149cce3fbcfb208bef4f1c..f8655c7c850891a5250200e4c20e2becfe605f27 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -584,7 +584,7 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ $object->fetch_thirdparty(); $object->fetch_lines(); - if (! $object->paye) // protection against multiple submit + if (!empty($object->paye)) // protection against multiple submit { // Boucle sur chaque taux de tva $i=0; @@ -601,8 +601,7 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ if ($object->type == 2) $discount->description='(CREDIT_NOTE)'; elseif ($object->type == 3) $discount->description='(DEPOSIT)'; else { - $this->error="CantConvertToReducAnInvoiceOfThisType"; - return -1; + setEventMessage($langs->trans('CantConvertToReducAnInvoiceOfThisType'),'errors'); } $discount->tva_tx=abs($object->total_ttc); $discount->fk_soc=$object->socid; @@ -617,6 +616,7 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ $discount->tva_tx=abs($tva_tx); $result=$discount->create($user); + if ($result < 0) { $error++; @@ -624,24 +624,24 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ } } - if (! $error) + if (empty($error)) { // Classe facture $result=$object->set_paid($user); - if ($result > 0) + if ($result >= 0) { //$mesgs[]='OK'.$discount->id; $db->commit(); } else { - $mesgs[]='<div class="error">'.$object->error.'</div>'; + setEventMessage($object->error,'errors'); $db->rollback(); } } else { - $mesgs[]='<div class="error">'.$discount->error.'</div>'; + setEventMessage($discount->error,'errors'); $db->rollback(); } } @@ -3687,7 +3687,7 @@ else if ($id > 0 || ! empty($ref)) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a></div>'; } // For deposit invoice - if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer) + if ($object->type == 3 && $object->statut == 2 && $resteapayer == 0 && $user->rights->facture->creer && empty($discount->id)) { print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a></div>'; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 53adade47ab81418cf44bc4e1e3489828f065f2f..76b54bbe613598eaea05f9a01b3d05df1dc07e6a 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1471,6 +1471,7 @@ class Facture extends CommonInvoice if ($close_note) $sql.= ", close_note='".$this->db->escape($close_note)."'"; $sql.= ' WHERE rowid = '.$this->id; + dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -1486,8 +1487,7 @@ class Facture extends CommonInvoice else { $error++; - $this->error=$this->db->error(); - dol_print_error($this->db); + $this->error=$this->db->lasterror(); } if (! $error) diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 468530303b8cdf3d14588aa779122f2c84ee5a47..ede7615a65a1d60ca1135594e240b9ec36581520 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -154,7 +154,7 @@ class DiscountAbsolute $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " fk_facture_source"; $sql.= ")"; - $sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now()).", ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; + $sql.= " VALUES ('".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= ")"; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 28d83897b37bdcf8b990562ca9edef9c1df14f63..ea3be87aaeed5ba34e93e1c19960808a5240b09a 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -270,7 +270,7 @@ class modSociete extends DolibarrModules $this->export_TypeFields_array[$r]=array('s.nom'=>"Text",'s.status'=>"Number",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.code_compta'=>"Text",'s.code_compta_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'p.libelle'=>"List:c_pays:libelle:libelle",'p.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Number",'s.note_private'=>"Text",'s.note_public'=>"Text",'t.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','st.code'=>'List:c_stcomm:libelle:code','d.nom'=>'Text'); $this->export_entities_array[$r]=array(); // We define here only fields that use another picto // Add extra fields - $sql="SELECT name, label, type FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe'"; + $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe'"; $resql=$this->db->query($sql); if ($resql) // This can fail when class is used on old database (during migration for example) {