diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 380501940d1..39037eb00f0 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -25,7 +25,7 @@ * \ingroup commande * \brief Fichier des classes de commandes */ -require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); +include_once(DOL_DOCUMENT_ROOT."/core/class/commonorder.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); @@ -33,7 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); * \class Commande * \brief Class to manage customers orders */ -class Commande extends CommonObject +class Commande extends CommonOrder { public $element='commande'; public $table_element='commande'; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4842d8f5079..989a4d5cd19 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -29,7 +29,7 @@ * \brief File of class to manage invoices */ -require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); +include_once(DOL_DOCUMENT_ROOT."/core/class/commoninvoice.class.php"); require_once(DOL_DOCUMENT_ROOT ."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT ."/societe/class/client.class.php"); @@ -37,7 +37,7 @@ require_once(DOL_DOCUMENT_ROOT ."/societe/class/client.class.php"); /** * Class to manage invoices */ -class Facture extends CommonObject +class Facture extends CommonInvoice { public $element='facture'; public $table_element='facture'; @@ -2261,41 +2261,6 @@ class Facture extends CommonObject } } - - /** - * Return amount of payments already done - * - * @return int Amount of payment already done, <0 if KO - */ - function getSommePaiement() - { - $table='paiement_facture'; - $field='fk_facture'; - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') - { - $table='paiementfourn_facturefourn'; - $field='fk_facturefourn'; - } - - $sql = 'SELECT sum(amount) as amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$table; - $sql.= ' WHERE '.$field.' = '.$this->id; - - dol_syslog(get_class($this)."::getSommePaiement sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - $this->db->free($resql); - return $obj->amount; - } - else - { - $this->error=$this->db->lasterror(); - return -1; - } - } - /** * Return list of payments * @@ -2393,233 +2358,6 @@ class Facture extends CommonObject } } - /** - * Renvoie tableau des ids de facture avoir issus de la facture - * - * @return array Tableau d'id de factures avoirs - */ - function getListIdAvoirFromInvoice() - { - $idarray=array(); - - $sql = 'SELECT rowid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - $sql.= ' WHERE fk_facture_source = '.$this->id; - $sql.= ' AND type = 2'; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $idarray[]=$row[0]; - $i++; - } - } - else - { - dol_print_error($this->db); - } - return $idarray; - } - - /** - * Renvoie l'id de la facture qui la remplace - * - * @param string $option filtre sur statut ('', 'validated', ...) - * @return int <0 si KO, 0 si aucune facture ne remplace, id facture sinon - */ - function getIdReplacingInvoice($option='') - { - $sql = 'SELECT rowid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - $sql.= ' WHERE fk_facture_source = '.$this->id; - $sql.= ' AND type < 2'; - if ($option == 'validated') $sql.= ' AND fk_statut = 1'; - // PROTECTION BAD DATA - // Au cas ou base corrompue et qu'il y a une facture de remplacement validee - // et une autre non, on donne priorite a la validee. - // Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes - // ont cree en meme temps une facture de remplacement pour la meme facture) - $sql.= ' ORDER BY fk_statut DESC'; - - $resql=$this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - if ($obj) - { - // Si il y en a - return $obj->rowid; - } - else - { - // Si aucune facture ne remplace - return 0; - } - } - else - { - return -1; - } - } - - /** - * Retourne le libelle du type de facture - * - * @return string Libelle - */ - function getLibType() - { - global $langs; - if ($this->type == 0) return $langs->trans("InvoiceStandard"); - if ($this->type == 1) return $langs->trans("InvoiceReplacement"); - if ($this->type == 2) return $langs->trans("InvoiceAvoir"); - if ($this->type == 3) return $langs->trans("InvoiceDeposit"); - if ($this->type == 4) return $langs->trans("InvoiceProForma"); - return $langs->trans("Unknown"); - } - - - /** - * Return label of object status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto - * @param int $alreadypaid 0=No payment already done, 1=Some payments already done - * @return string Label - */ - function getLibStatut($mode=0,$alreadypaid=-1) - { - return $this->LibStatut($this->paye,$this->statut,$mode,$alreadypaid,$this->type); - } - - /** - * Renvoi le libelle d'un statut donne - * - * @param int $paye Etat paye - * @param int $statut Id statut - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @param double $alreadypaid Montant deja paye - * @param int $type Type facture - * @return string Libelle du statut - */ - function LibStatut($paye,$statut,$mode=0,$alreadypaid=-1,$type=0) - { - global $langs; - $langs->load('bills'); - - //print "$paye,$statut,$mode,$alreadypaid,$type"; - if ($mode == 0) - { - $prefix=''; - if (! $paye) - { - if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpaid'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); - if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); - return $langs->trans('Bill'.$prefix.'StatusStarted'); - } - else - { - if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); - elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted'); - else return $langs->trans('Bill'.$prefix.'StatusPaid'); - } - } - if ($mode == 1) - { - $prefix='Short'; - if (! $paye) - { - if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); - if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); - return $langs->trans('Bill'.$prefix.'StatusStarted'); - } - else - { - if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); - elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted'); - else return $langs->trans('Bill'.$prefix.'StatusPaid'); - } - } - if ($mode == 2) - { - $prefix='Short'; - if (! $paye) - { - if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); - if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPaid'); - return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted'); - } - else - { - if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); - elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusConverted'); - else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaid'); - } - } - if ($mode == 3) - { - $prefix='Short'; - if (! $paye) - { - if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7'); - if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1'); - return img_picto($langs->trans('BillStatusStarted'),'statut3'); - } - else - { - if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); - elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6'); - else return img_picto($langs->trans('BillStatusPaid'),'statut6'); - } - } - if ($mode == 4) - { - if (! $paye) - { - if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); - if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('BillStatusNotPaid'); - return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted'); - } - else - { - if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('BillStatusPaidBackOrConverted'); - elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('BillStatusConverted'); - else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('BillStatusPaid'); - } - } - if ($mode == 5) - { - $prefix='Short'; - if (! $paye) - { - if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft').' '.img_picto($langs->trans('BillStatusDraft'),'statut0'); - if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled').' '.img_picto($langs->trans('BillStatusCanceled'),'statut5'); - if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' '.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7'); - if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid').' '.img_picto($langs->trans('BillStatusNotPaid'),'statut1'); - return $langs->trans('Bill'.$prefix.'StatusStarted').' '.img_picto($langs->trans('BillStatusStarted'),'statut3'); - } - else - { - if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted').' '.img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); - elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted').' '.img_picto($langs->trans('BillStatusConverted'),'statut6'); - else return $langs->trans('Bill'.$prefix.'StatusPaid').' '.img_picto($langs->trans('BillStatusPaid'),'statut6'); - } - } - } - /** * Return next reference of invoice not already used (or last reference) * according to numbering module defined into constant FACTURE_ADDON diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 04cb8955a8a..f62f5581b5e 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -78,8 +78,8 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ $subelement = 'facture'; } - if ($user->rights->$element->creer || $user->rights->$element->write - || (isset($subelement) && ($user->rights->$element->$subelement->creer || $user->rights->$element->$subelement->write)) + if (! empty($user->rights->$element->creer) || ! empty($user->rights->$element->write) + || (isset($subelement) && (! empty($user->rights->$element->$subelement->creer) || ! empty($user->rights->$element->$subelement->write))) || ($element == 'payment' && $user->rights->facture->paiement) || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->creer)) { @@ -117,7 +117,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ { $loadcache = $form->$loadcachename; $value = $loadcache[$newvalue]; - + if (! empty($form->$loadviewname)) { $loadview = $form->$loadviewname; @@ -138,7 +138,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ $module = $regs[1]; $subelement = $regs[2]; } - + dol_include_once('/'.$module.'/class/actions_'.$subelement.'.class.php'); $classname = 'Actions'.ucfirst($subelement); $object = new $classname($db); @@ -147,7 +147,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ { $loadcache = $object->$loadcachename; $value = $loadcache[$newvalue]; - + if (! empty($object->$loadviewname)) { $loadview = $object->$loadviewname; @@ -164,7 +164,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ if (! $error) { - if (! is_object($object) || empty($savemethod)) $object = new GenericObject($db); + if ((isset($object) && ! is_object($object)) || empty($savemethod)) $object = new GenericObject($db); // Specific for add_object_linked() // TODO add a function for variable treatment @@ -172,7 +172,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ $object->ext_element = $ext_element; $object->fk_element = $fk_element; $object->element = $element; - + $ret=$object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format); if ($ret > 0) { diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php new file mode 100644 index 00000000000..aee943be4df --- /dev/null +++ b/htdocs/core/class/commoninvoice.class.php @@ -0,0 +1,293 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/commoninvoice.class.php + * \ingroup core + * \brief File of the superclass of invoices classes (customer and supplier) + */ + +require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); + +/** + * \class CommonInvoice + * \brief Superclass for invoices classes + */ +abstract class CommonInvoice extends CommonObject +{ + /** + * Return amount of payments already done + * + * @return int Amount of payment already done, <0 if KO + */ + function getSommePaiement() + { + $table='paiement_facture'; + $field='fk_facture'; + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') + { + $table='paiementfourn_facturefourn'; + $field='fk_facturefourn'; + } + + $sql = 'SELECT sum(amount) as amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$table; + $sql.= ' WHERE '.$field.' = '.$this->id; + + dol_syslog(get_class($this)."::getSommePaiement sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $this->db->free($resql); + return $obj->amount; + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } + + /** + * Renvoie tableau des ids de facture avoir issus de la facture + * + * @return array Tableau d'id de factures avoirs + */ + function getListIdAvoirFromInvoice() + { + $idarray=array(); + + $sql = 'SELECT rowid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql.= ' WHERE fk_facture_source = '.$this->id; + $sql.= ' AND type = 2'; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $idarray[]=$row[0]; + $i++; + } + } + else + { + dol_print_error($this->db); + } + return $idarray; + } + + /** + * Renvoie l'id de la facture qui la remplace + * + * @param string $option filtre sur statut ('', 'validated', ...) + * @return int <0 si KO, 0 si aucune facture ne remplace, id facture sinon + */ + function getIdReplacingInvoice($option='') + { + $sql = 'SELECT rowid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql.= ' WHERE fk_facture_source = '.$this->id; + $sql.= ' AND type < 2'; + if ($option == 'validated') $sql.= ' AND fk_statut = 1'; + // PROTECTION BAD DATA + // Au cas ou base corrompue et qu'il y a une facture de remplacement validee + // et une autre non, on donne priorite a la validee. + // Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes + // ont cree en meme temps une facture de remplacement pour la meme facture) + $sql.= ' ORDER BY fk_statut DESC'; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj) + { + // Si il y en a + return $obj->rowid; + } + else + { + // Si aucune facture ne remplace + return 0; + } + } + else + { + return -1; + } + } + + /** + * Retourne le libelle du type de facture + * + * @return string Libelle + */ + function getLibType() + { + global $langs; + if ($this->type == 0) return $langs->trans("InvoiceStandard"); + if ($this->type == 1) return $langs->trans("InvoiceReplacement"); + if ($this->type == 2) return $langs->trans("InvoiceAvoir"); + if ($this->type == 3) return $langs->trans("InvoiceDeposit"); + if ($this->type == 4) return $langs->trans("InvoiceProForma"); + return $langs->trans("Unknown"); + } + + /** + * Return label of object status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto + * @param int $alreadypaid 0=No payment already done, 1=Some payments already done + * @return string Label + */ + function getLibStatut($mode=0,$alreadypaid=-1) + { + return $this->LibStatut($this->paye,$this->statut,$mode,$alreadypaid,$this->type); + } + + /** + * Renvoi le libelle d'un statut donne + * + * @param int $paye Etat paye + * @param int $statut Id statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @param double $alreadypaid Montant deja paye + * @param int $type Type facture + * @return string Libelle du statut + */ + function LibStatut($paye,$statut,$mode=0,$alreadypaid=-1,$type=0) + { + global $langs; + $langs->load('bills'); + + //print "$paye,$statut,$mode,$alreadypaid,$type"; + if ($mode == 0) + { + $prefix=''; + if (! $paye) + { + if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpaid'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); + if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); + return $langs->trans('Bill'.$prefix.'StatusStarted'); + } + else + { + if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); + elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted'); + else return $langs->trans('Bill'.$prefix.'StatusPaid'); + } + } + if ($mode == 1) + { + $prefix='Short'; + if (! $paye) + { + if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); + if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); + return $langs->trans('Bill'.$prefix.'StatusStarted'); + } + else + { + if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); + elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted'); + else return $langs->trans('Bill'.$prefix.'StatusPaid'); + } + } + if ($mode == 2) + { + $prefix='Short'; + if (! $paye) + { + if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); + if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPaid'); + return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted'); + } + else + { + if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); + elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusConverted'); + else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaid'); + } + } + if ($mode == 3) + { + $prefix='Short'; + if (! $paye) + { + if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7'); + if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1'); + return img_picto($langs->trans('BillStatusStarted'),'statut3'); + } + else + { + if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); + elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6'); + else return img_picto($langs->trans('BillStatusPaid'),'statut6'); + } + } + if ($mode == 4) + { + if (! $paye) + { + if ($statut == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); + if ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('BillStatusNotPaid'); + return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted'); + } + else + { + if ($type == 2) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('BillStatusPaidBackOrConverted'); + elseif ($type == 3) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('BillStatusConverted'); + else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('BillStatusPaid'); + } + } + if ($mode == 5) + { + $prefix='Short'; + if (! $paye) + { + if ($statut == 0) return $langs->trans('Bill'.$prefix.'StatusDraft').' '.img_picto($langs->trans('BillStatusDraft'),'statut0'); + if (($statut == 3 || $statut == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled').' '.img_picto($langs->trans('BillStatusCanceled'),'statut5'); + if (($statut == 3 || $statut == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' '.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut7'); + if ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid').' '.img_picto($langs->trans('BillStatusNotPaid'),'statut1'); + return $langs->trans('Bill'.$prefix.'StatusStarted').' '.img_picto($langs->trans('BillStatusStarted'),'statut3'); + } + else + { + if ($type == 2) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted').' '.img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); + elseif ($type == 3) return $langs->trans('Bill'.$prefix.'StatusConverted').' '.img_picto($langs->trans('BillStatusConverted'),'statut6'); + else return $langs->trans('Bill'.$prefix.'StatusPaid').' '.img_picto($langs->trans('BillStatusPaid'),'statut6'); + } + } + } +} + +?> diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a41aee430b8..2432a9524d4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1501,23 +1501,27 @@ abstract class CommonObject $this->total_ttc += $obj->total_ttc; // Define vatrates with totals for each line and for all lines - $vatrates[$this->vatrate][]=array( - 'total_ht' =>$obj->total_ht, - 'total_tva' =>$obj->total_tva, - 'total_ttc' =>$obj->total_ttc, - 'total_localtax1'=>$obj->total_localtax1, - 'total_localtax2'=>$obj->total_localtax2 - ); - if (! isset($vatrates_alllines[$this->vatrate]['total_ht'])) $vatrates_alllines[$this->vatrate]['total_ht']=0; - if (! isset($vatrates_alllines[$this->vatrate]['total_tva'])) $vatrates_alllines[$this->vatrate]['total_tva']=0; - if (! isset($vatrates_alllines[$this->vatrate]['total_localtax1'])) $vatrates_alllines[$this->vatrate]['total_localtax1']=0; - if (! isset($vatrates_alllines[$this->vatrate]['total_localtax2'])) $vatrates_alllines[$this->vatrate]['total_localtax2']=0; - if (! isset($vatrates_alllines[$this->vatrate]['total_ttc'])) $vatrates_alllines[$this->vatrate]['total_ttc']=0; - $vatrates_alllines[$this->vatrate]['total_ht'] +=$obj->total_ht; - $vatrates_alllines[$this->vatrate]['total_tva'] +=$obj->total_tva; - $vatrates_alllines[$this->vatrate]['total_localtax1']+=$obj->total_localtax1; - $vatrates_alllines[$this->vatrate]['total_localtax2']+=$obj->total_localtax2; - $vatrates_alllines[$this->vatrate]['total_ttc'] +=$obj->total_ttc; + // TODO $vatrates and $vatrates_alllines not used ? + if (! empty($this->vatrate)) + { + $vatrates[$this->vatrate][]=array( + 'total_ht' =>$obj->total_ht, + 'total_tva' =>$obj->total_tva, + 'total_ttc' =>$obj->total_ttc, + 'total_localtax1'=>$obj->total_localtax1, + 'total_localtax2'=>$obj->total_localtax2 + ); + if (! isset($vatrates_alllines[$this->vatrate]['total_ht'])) $vatrates_alllines[$this->vatrate]['total_ht']=0; + if (! isset($vatrates_alllines[$this->vatrate]['total_tva'])) $vatrates_alllines[$this->vatrate]['total_tva']=0; + if (! isset($vatrates_alllines[$this->vatrate]['total_localtax1'])) $vatrates_alllines[$this->vatrate]['total_localtax1']=0; + if (! isset($vatrates_alllines[$this->vatrate]['total_localtax2'])) $vatrates_alllines[$this->vatrate]['total_localtax2']=0; + if (! isset($vatrates_alllines[$this->vatrate]['total_ttc'])) $vatrates_alllines[$this->vatrate]['total_ttc']=0; + $vatrates_alllines[$this->vatrate]['total_ht'] +=$obj->total_ht; + $vatrates_alllines[$this->vatrate]['total_tva'] +=$obj->total_tva; + $vatrates_alllines[$this->vatrate]['total_localtax1']+=$obj->total_localtax1; + $vatrates_alllines[$this->vatrate]['total_localtax2']+=$obj->total_localtax2; + $vatrates_alllines[$this->vatrate]['total_ttc'] +=$obj->total_ttc; + } $i++; } diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php new file mode 100644 index 00000000000..bde0cc6fc11 --- /dev/null +++ b/htdocs/core/class/commonorder.class.php @@ -0,0 +1,35 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/commonorder.class.php + * \ingroup core + * \brief File of the superclass of orders classes (customer and supplier) + */ + +require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); + +/** + * \class CommonOrder + * \brief Superclass for orders classes + */ +abstract class CommonOrder extends CommonObject +{ + +} + +?> diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 53ab7a49ddc..2ef140e2ced 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -274,7 +274,8 @@ class Form else if (preg_match('/^datepicker/',$inputType)) { $tmp=explode(':',$inputType); - $inputType=$tmp[0]; $inputOption=$tmp[1]; + $inputType=$tmp[0]; + if (! empty($tmp[1])) $inputOption=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; $out.= ''."\n"; // Use for timestamp format diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index c37c9d3926a..2b6e2c5747f 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Marc Barilley/Ocebo * Copyright (C) 2007 Franky Van Liedekerke @@ -713,6 +713,7 @@ class FormOther $out.= '"> diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 9430d5acccd..f0d306be5b5 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -26,14 +26,14 @@ * \brief File of class to manage suppliers orders */ +include_once(DOL_DOCUMENT_ROOT."/core/class/commonorder.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); -require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); /** * Class to manage predefined suppliers products */ -class CommandeFournisseur extends Commande +class CommandeFournisseur extends CommonOrder { public $element='order_supplier'; public $table_element='commande_fournisseur'; @@ -347,7 +347,7 @@ class CommandeFournisseur extends Commande if (! $error) { $this->oldref=''; - + // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { @@ -364,7 +364,7 @@ class CommandeFournisseur extends Commande if (@rename($dirsource, $dirdest)) { $this->oldref = $oldref; - + dol_syslog("Rename ok"); // Suppression ancien fichier PDF dans nouveau rep dol_delete_file($dirdest.'/'.$oldref.'.*'); @@ -1297,7 +1297,7 @@ class CommandeFournisseur extends Commande { $error++; } - + if (! $error) { // Appel des triggers @@ -1309,7 +1309,7 @@ class CommandeFournisseur extends Commande } // Fin appel triggers } - + if (! $error) { // We remove directory @@ -1337,7 +1337,7 @@ class CommandeFournisseur extends Commande } } } - + if (! $error) { dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG); @@ -1821,7 +1821,7 @@ class CommandeFournisseur extends Commande /** * Classe de gestion des lignes de commande */ -class CommandeFournisseurLigne extends OrderLine +class CommandeFournisseurLigne { // From llx_commandedet var $qty; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 45f3bf03bdc..fe3ed8f2202 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -26,14 +26,14 @@ * \brief File of class to manage suppliers invoices */ -include_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); +include_once(DOL_DOCUMENT_ROOT."/core/class/commoninvoice.class.php"); /** * \class FactureFournisseur * \brief Class to manage suppliers invoices */ -class FactureFournisseur extends Facture +class FactureFournisseur extends CommonInvoice { public $element='invoice_supplier'; public $table_element='facture_fourn'; @@ -164,7 +164,7 @@ class FactureFournisseur extends Facture // Add object linked - if (! $error && $this->id && $this->origin && $this->origin_id) + if (! $error && $this->id && ! empty($this->origin) && ! empty($this->origin_id)) { $ret = $this->add_object_linked(); if (! $ret) @@ -195,7 +195,7 @@ class FactureFournisseur extends Facture $this->lines[$i]->qty, $this->lines[$i]->fk_product, 'HT', - $this->lines[$i]->info_bits, + (! empty($this->lines[$i]->info_bits)?$this->lines[$i]->info_bits:''), $this->lines[$i]->product_type ); } @@ -1363,7 +1363,7 @@ class FactureFournisseur extends Facture // Loop on each line of new invoice foreach($object->lines as $i => $line) { - if (($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts + if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts { unset($object->lines[$i]); } diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 6908e85e2d9..3e020f463f6 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -242,9 +242,10 @@ class PaiementFourn extends Paiement * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse * + * @param int $notrigger No trigger * @return int <0 si ko, >0 si ok */ - function delete() + function delete($notrigger=0) { $bank_line_id = $this->bank_line; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index f9dd67b1608..9ac816f4db2 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -71,6 +71,7 @@ $hookmanager=new HookManager($db); $hookmanager->initHooks(array('ordersuppliercard')); $mesg=''; +$errors=array(); $object = new CommandeFournisseur($db); @@ -576,7 +577,7 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) / // Sauvegarde le dernier module choisi pour generer un document $object->fetch($id); $object->fetch_thirdparty(); - + if ($_REQUEST['model']) { $object->setDocModel($user, $_REQUEST['model']); @@ -609,7 +610,7 @@ else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer if ($object->fetch($id)) { $object->fetch_thirdparty(); - + $langs->load("other"); $upload_dir = $conf->fournisseur->commande->dir_output; $file = $upload_dir . '/' . GETPOST('file'); @@ -659,7 +660,7 @@ else if ($action == 'create' && $user->rights->fournisseur->commande->creer) /* * Add file in email form */ -if ($_POST['addfile']) +if (GETPOST('addfile')) { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); @@ -675,7 +676,7 @@ if ($_POST['addfile']) /* * Remove file in email form */ -if (! empty($_POST['removedfile'])) +if (GETPOST('removedfile')) { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); @@ -1261,11 +1262,21 @@ if ($id > 0 || ! empty($ref)) $var=!$var; // Show product and description - $type=$line->product_type?$line->product_type:$line->fk_product_type; + $type=(! empty($line->product_type)?$line->product_type:(! empty($line->fk_product_type)?$line->fk_product_type:0)); // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. - if (! empty($line->date_start)) $type=1; - if (! empty($line->date_end)) $type=1; + $date_start=''; + $date_end=''; + if (! empty($line->date_start)) + { + $date_start=$line->date_start; + $type=1; + } + if (! empty($line->date_end)) + { + $date_end=$line->date_end; + $type=1; + } // Ligne en mode visu if ($action != 'editline' || $_GET['rowid'] != $line->id) @@ -1286,7 +1297,7 @@ if ($id > 0 || ! empty($ref)) print $form->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($line->date_start,$line->date_end); + print_date_range($date_start,$date_end); // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) print ($line->description && $line->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($line->description):''; @@ -1300,7 +1311,7 @@ if ($id > 0 || ! empty($ref)) print $text.' '.nl2br($line->description); // Show range - print_date_range($line->date_start,$line->date_end); + print_date_range($date_start,$date_end); } print ''; @@ -1361,7 +1372,7 @@ if ($id > 0 || ! empty($ref)) print $form->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($line->date_start,$line->date_end); + print_date_range($date_start,$date_end); print '
'; } else @@ -1427,23 +1438,23 @@ if ($id > 0 || ! empty($ref)) require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $nbrows=ROWS_2; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('dp_desc',$_POST["dp_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor->Create(); print ''; print ''; - print $form->load_tva('tva_tx',($_POST["tva_tx"]?$_POST["tva_tx"]:-1),$soc,$mysoc); + print $form->load_tva('tva_tx',(GETPOST('tva_tx')?GETPOST('tva_tx'):-1),$soc,$mysoc); print ''; - print ''; - print ''; - print 'remise_client).'">%'; + print ''; + print ''; + print '%'; print ''; print ''; print ''; // Ajout de produits/services predefinis - if ($conf->product->enabled || $conf->service->enabled) + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { print ''; print ''; @@ -1471,13 +1482,13 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - $form->select_produits_fournisseurs($object->fourn_id,'','idprodfournprice','',$filtre); + $form->select_produits_fournisseurs($object->fourn_id,'','idprodfournprice'); - if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; + if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '
'; if (is_object($hookmanager)) { - $parameters=array('filtre'=>$filtre,'htmlname'=>'idprodfournprice'); + $parameters=array('htmlname'=>'idprodfournprice'); echo $hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action); } @@ -1485,12 +1496,12 @@ if ($id > 0 || ! empty($ref)) require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); $nbrows=ROWS_2; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('np_desc',$_POST["np_desc"],'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor=new DolEditor('np_desc',GETPOST('np_desc'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); $doleditor->Create(); print ''; - print ''; - print 'remise_client).'">%'; + print ''; + print '%'; print ''; print ''; diff --git a/htdocs/fourn/commande/index.php b/htdocs/fourn/commande/index.php index 7cabdc17b70..4ed3f9495b8 100755 --- a/htdocs/fourn/commande/index.php +++ b/htdocs/fourn/commande/index.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2005-2011 Regis Houssin - * Copyright (C) 2012-2012 Vinicius Nogueira +/* Copyright (C) 2001-2006 Rodolphe Quiedeville + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2012 Vinicius Nogueira * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); // Security check -$orderid = isset($_GET["orderid"])?$_GET["orderid"]:''; +$orderid = GETPOST('orderid'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'commande_fournisseur', $orderid,''); @@ -40,7 +40,7 @@ $langs->load("orders"); /* * View -*/ + */ llxHeader('',$langs->trans("SuppliersOrdersArea")); @@ -48,7 +48,7 @@ $commandestatic = new CommandeFournisseur($db); $userstatic=new User($db); $formfile = new FormFile($db); -print_barre_liste($langs->trans("SuppliersOrdersArea"), $page, "index.php", "", $sortfield, $sortorder, '', $num); +print_fiche_titre($langs->trans("SuppliersOrdersArea")); print ''; print ''; print "\n"; // Ref supplier - print ''; // Third party @@ -1322,7 +1324,7 @@ else } print ')'; } - if ($facidnext > 0) + if (isset($facidnext) && $facidnext > 0) { $facthatreplace=new FactureFournisseur($db); $facthatreplace->fetch($facidnext); @@ -1548,11 +1550,21 @@ else } // Show product and description - $type=$object->lines[$i]->product_type?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type; + $type=(! empty($object->lines[$i]->product_type)?$object->lines[$i]->product_type:(! empty($object->lines[$i]->fk_product_type)?$object->lines[$i]->fk_product_type:0)); // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. - if (! empty($object->lines[$i]->date_start)) $type=1; - if (! empty($object->lines[$i]->date_end)) $type=1; + $date_start=''; + $date_end=''; + if (! empty($object->lines[$i]->date_start)) + { + $date_start=$object->lines[$i]->date_start; + $type=1; + } + if (! empty($object->lines[$i]->date_end)) + { + $date_end=$object->lines[$i]->date_end; + $type=1; + } $var=!$var; @@ -1632,7 +1644,7 @@ else print $form->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($object->lines[$i]->date_start,$object->lines[$i]->date_end); + print_date_range($date_start,$date_end); // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) print ($object->lines[$i]->description && $object->lines[$i]->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($object->lines[$i]->description):''; @@ -1646,7 +1658,7 @@ else print $text.' '.nl2br($object->lines[$i]->description); // Show range - print_date_range($object->lines[$i]->date_start,$object->lines[$i]->date_end); + print_date_range($date_start,$date_end); } print ''; @@ -1723,7 +1735,7 @@ else print ''; print ''; print ''; print ''; print ''; print "\n"; diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 212e6f5db83..ec79fb6b1dc 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -262,7 +262,7 @@ if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC')) // Set default language (must be after the setValues of $conf) if (! defined('NOREQUIRETRAN')) { - $langs->setDefaultLang($conf->global->MAIN_LANG_DEFAULT); + $langs->setDefaultLang((! empty($conf->global->MAIN_LANG_DEFAULT)?$conf->global->MAIN_LANG_DEFAULT:'')); } if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR');
'; @@ -202,7 +202,7 @@ else * Draft orders */ -if ($conf->fournisseur->enabled) +if (! empty($conf->fournisseur->enabled)) { $sql = "SELECT c.rowid, c.ref, s.nom, s.rowid as socid"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; @@ -211,7 +211,7 @@ if ($conf->fournisseur->enabled) $sql.= " WHERE c.fk_soc = s.rowid"; $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.fk_statut = 0"; - if ($socid) $sql.= " AND c.fk_soc = ".$socid; + if (! empty($socid)) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $resql=$db->query($sql); @@ -307,7 +307,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX $sql.= " WHERE c.fk_soc = s.rowid"; $sql.= " AND c.entity = ".$conf->entity; //$sql.= " AND c.fk_statut > 2"; -if ($socid) $sql .= " AND c.fk_soc = ".$socid; +if (! empty($socid)) $sql .= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " ORDER BY c.tms DESC"; $sql.= $db->plimit($max, 0); diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 9c052738ea5..d902e507bd3 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -42,6 +42,7 @@ $langs->load('suppliers'); $langs->load('companies'); $mesg=''; +$errors=array(); $id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int')); $action = GETPOST("action"); $confirm = GETPOST("confirm"); @@ -52,7 +53,8 @@ $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty( $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); // Security check -if ($user->societe_id) $socid=$user->societe_id; +$socid=''; +if (! empty($user->societe_id)) $socid=$user->societe_id; $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -404,7 +406,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) // Modification d'une ligne elseif ($action == 'update_line') { - if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification + if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification { $object->fetch($id); $object->fetch_thirdparty(); @@ -420,7 +422,7 @@ elseif ($action == 'update_line') $price_base_type='TTC'; } - if ($_POST['idprod']) + if (GETPOST('idprod')) { $prod = new Product($db); $prod->fetch($_POST['idprod']); @@ -440,7 +442,7 @@ elseif ($action == 'update_line') $localtax1tx= get_localtax($_POST['tauxtva'], 1, $object->thirdparty); $localtax2tx= get_localtax($_POST['tauxtva'], 2, $object->thirdparty); - $result=$object->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $localtax1tx, $localtax2tx, $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type); + $result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1tx, $localtax2tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type); if ($result >= 0) { unset($_POST['label']); @@ -607,7 +609,7 @@ elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) } // Add file in email form -if ($_POST['addfile']) +if (GETPOST('addfile')) { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); @@ -1277,13 +1279,13 @@ else // Ref print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object,'id','',1,'rowid','ref',$morehtmlref); + print $form->showrefnav($object,'id','',1,'rowid','ref'); print '
'.$form->editfieldkey("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; - print $form->editfieldval("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)); + print '
'.$form->editfieldkey("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; + print $form->editfieldval("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)); print '
'; - print $form->load_tva('tauxtva',($_POST["tauxtva"]?$_POST["tauxtva"]:-1),$societe,$mysoc); + print $form->load_tva('tauxtva',(GETPOST('tauxtva')?GETPOST('tauxtva'):-1),$societe,$mysoc); print ''; print ''; @@ -1740,7 +1752,7 @@ else print ''; // Ajout de produits/services predefinis - if ($conf->product->enabled || $conf->service->enabled) + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { print '
'; @@ -1766,11 +1778,11 @@ else $var=! $var; print '
'; - $form->select_produits_fournisseurs($object->socid,'','idprodfournprice','',$filtre); + $form->select_produits_fournisseurs($object->socid,'','idprodfournprice'); if (is_object($hookmanager)) { - $parameters=array('filtre'=>$filtre,'htmlname'=>'idprodfournprice'); + $parameters=array('htmlname'=>'idprodfournprice'); echo $hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action); } @@ -1882,9 +1894,10 @@ else $urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id; $genallowed=$user->rights->fournisseur->facture->creer; $delallowed=$user->rights->fournisseur->facture->supprimer; + $modelpdf=(! empty($object->modelpdf)?$object->modelpdf:''); print '
'; - print $formfile->showdocuments('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,0,0,'','','',$societe->default_lang); + print $formfile->showdocuments('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,0,0,'','','',$societe->default_lang); $somethingshown=$formfile->numoffiles; /* diff --git a/htdocs/fourn/facture/impayees.php b/htdocs/fourn/facture/impayees.php index dd49c55faca..709f2079bcf 100644 --- a/htdocs/fourn/facture/impayees.php +++ b/htdocs/fourn/facture/impayees.php @@ -3,7 +3,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2012-2012 Vinicius Nogueira + * Copyright (C) 2012 Vinicius Nogueira * Copyright (C) 2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -104,9 +104,9 @@ if ($user->rights->fournisseur->facture->lire) if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql .= " AND s.rowid = ".$socid; - if ($_GET["filtre"]) + if (GETPOST('filtre')) { - $filtrearr = explode(",", $_GET["filtre"]); + $filtrearr = explode(",", GETPOST('filtre')); foreach ($filtrearr as $fil) { $filt = explode(":", $fil); @@ -116,16 +116,16 @@ if ($user->rights->fournisseur->facture->lire) if ($search_ref) { - $sql .= " AND f.rowid like '%".$search_ref."%'"; + $sql .= " AND f.rowid LIKE '%".$search_ref."%'"; } if ($search_ref_supplier) { - $sql .= " AND f.facnumber like '%".$search_ref_supplier."%'"; + $sql .= " AND f.facnumber LIKE '%".$search_ref_supplier."%'"; } if ($search_societe) { - $sql .= " AND s.nom like '%".$search_societe."%'"; + $sql .= " AND s.nom LIKE '%".$search_societe."%'"; } if ($search_montant_ht) @@ -138,9 +138,9 @@ if ($user->rights->fournisseur->facture->lire) $sql .= " AND f.total_ttc = '".$search_montant_ttc."'"; } - if (dol_strlen($_POST["sf_ref"]) > 0) + if (dol_strlen(GETPOST('sf_re')) > 0) { - $sql .= " AND f.facnumber like '%".$_POST["sf_ref"]."%'"; + $sql .= " AND f.facnumber LIKE '%".GETPOST('sf_re')."%'"; } $sql.= " GROUP BY f.facnumber, f.rowid, f.total_ht, f.total_ttc, f.datef, f.date_lim_reglement, f.paye, f.fk_statut, s.rowid, s.nom"; @@ -162,16 +162,16 @@ if ($user->rights->fournisseur->facture->lire) $param =''; if ($socid) $param.="&socid=".$socid; - + if ($search_ref) $param.='&search_ref='.urlencode($search_ref); if ($search_ref_supplier) $param.='&search_ref_supplier='.urlencode($search_ref_supplier); if ($search_societe) $param.='&search_societe='.urlencode($search_societe); if ($search_montant_ht) $param.='&search_montant_ht='.urlencode($search_montant_ht); if ($search_montant_ttc) $param.='&search_montant_ttc='.urlencode($search_montant_ttc); - + $param.=($option?"&option=".$option:""); - if ($late) $param.='&late='.urlencode($late); - $urlsource.=str_replace('&','&',$param); + if (! empty($late)) $param.='&late='.urlencode($late); + $urlsource=str_replace('&','&',$param); $titre=($socid?$langs->trans("BillsSuppliersUnpaidForCompany",$soc->nom):$langs->trans("BillsSuppliersUnpaid")); diff --git a/htdocs/fourn/facture/index.php b/htdocs/fourn/facture/index.php index 9b6ff5cb080..a6e7631fe6e 100644 --- a/htdocs/fourn/facture/index.php +++ b/htdocs/fourn/facture/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,9 +112,9 @@ if ($socid) { $sql .= " AND s.rowid = ".$socid; } -if ($_GET["filtre"]) +if (GETPOST('filtre')) { - $filtrearr = explode(",", $_GET["filtre"]); + $filtrearr = explode(",", GETPOST('filtre')); foreach ($filtrearr as $fil) { $filt = explode(":", $fil); @@ -124,11 +124,11 @@ if ($_GET["filtre"]) if (GETPOST("search_ref")) { - $sql .= " AND fac.rowid like '%".$db->escape(GETPOST("search_ref"))."%'"; + $sql .= " AND fac.rowid LIKE '%".$db->escape(GETPOST("search_ref"))."%'"; } if (GETPOST("search_ref_supplier")) { - $sql .= " AND fac.facnumber like '%".$db->escape(GETPOST("search_ref_supplier"))."%'"; + $sql .= " AND fac.facnumber LIKE '%".$db->escape(GETPOST("search_ref_supplier"))."%'"; } if ($month > 0) { @@ -143,12 +143,12 @@ else if ($year > 0) } if (GETPOST("search_libelle")) { - $sql .= " AND fac.libelle like '%".$db->escape(GETPOST("search_libelle"))."%'"; + $sql .= " AND fac.libelle LIKE '%".$db->escape(GETPOST("search_libelle"))."%'"; } if (GETPOST("search_societe")) { - $sql .= " AND s.nom like '%".$db->escape(GETPOST("search_societe"))."%'"; + $sql .= " AND s.nom LIKE '%".$db->escape(GETPOST("search_societe"))."%'"; } if (GETPOST("search_montant_ht")) @@ -268,7 +268,8 @@ if ($resql) // Affiche statut de la facture print '
'; // TODO le montant deja paye objp->am n'est pas definie - print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$objp->am); + //print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$objp->am); + print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5); print '