From bb3ed6bd912516ae4c40e3838e05bef1f60be121 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Dec 2008 02:44:59 +0000 Subject: [PATCH] Fix: Invoice creation from order --- htdocs/commande/commande.class.php | 9 ++++-- htdocs/compta/facture.php | 9 ++++-- htdocs/facture.class.php | 4 +-- htdocs/lib/functions.lib.php | 49 ++++++++++++++++++++++-------- htdocs/product.class.php | 2 +- htdocs/propal.class.php | 6 ++-- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index e6885a5908d..132f4e7b43b 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -65,6 +65,9 @@ class Commande extends CommonObject 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 $remise_absolue; var $modelpdf; var $info_bits; @@ -813,13 +816,13 @@ class Commande extends CommonObject /** - * \brief Recupere de la base les caracteristiques d'une commande + * \brief Load an order from database * \param rowid id de la commande a recuperer */ function fetch($id) { $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, c.fk_cond_reglement, c.fk_mode_reglement'; + $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.fk_cond_reglement, c.fk_mode_reglement'; $sql.= ', '.$this->db->pdate('c.date_commande').' as date_commande'; $sql.= ', '.$this->db->pdate('c.date_livraison').' as date_livraison'; $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee'; @@ -848,7 +851,7 @@ class Commande extends CommonObject $this->statut = $obj->fk_statut; $this->user_author_id = $obj->fk_user_author; $this->total_ht = $obj->total_ht; - $this->total_tva = $obj->tva; + $this->total_tva = $obj->total_tva; $this->total_ttc = $obj->total_ttc; $this->date = $obj->date_commande; $this->remise = $obj->remise; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 94a78d45a64..300ce0f91e6 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -693,7 +693,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) if ($facid > 0) { - $comm = New Commande($db); + $comm = new Commande($db); if ( $comm->fetch($_POST['commandeid']) ) { $comm->fetch_lines(); @@ -702,6 +702,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) { $desc=($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); + // Should use a function using total_ht, total_ttc and total_vat $result = $facture->addline( $facid, $desc, @@ -1632,6 +1633,7 @@ if ($_GET['action'] == 'create') if ($_GET['propalid'] > 0) { + print "\n"; print ''."\n"; print ''."\n"; print ''."\n"; @@ -1646,9 +1648,11 @@ if ($_GET['action'] == 'create') } elseif ($_GET['commandeid'] > 0) { + print "\n"; + print "\n"; print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; //print ''."\n"; //print ''."\n"; print ''; @@ -1665,6 +1669,7 @@ if ($_GET['action'] == 'create') $contrat->remise_percent=$remise_percent; $contrat->update_price(); + print "\n"; print ''."\n"; print ''."\n"; print ''."\n"; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 94e84413384..70a50962716 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1424,7 +1424,7 @@ class Facture extends CommonObject // Nettoyage parametres if (! $qty) $qty = 1; - dolibarr_syslog("Facture.class::add_product $idproduct, $qty, $remise_percent, $date_start, $date_end"); + dolibarr_syslog("Facture::add_product $idproduct, $qty, $remise_percent, $date_start, $date_end", LOG_DEBUG); if ($idproduct > 0) { @@ -1511,7 +1511,7 @@ class Facture extends CommonObject $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; $total_ttc = $tabprice[2]; - + // \TODO A virer // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 836bd9f5fae..6ca2ad78ac1 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2039,12 +2039,12 @@ function dol_delete_dir_recursive($dir,$count=0) /** - * \brief Fonction qui retourne un taux de tva format� pour visualisation - * \remarks Fonction utilis�e dans les pdf et les pages html + * \brief Fonction qui retourne un taux de tva formate pour visualisation + * \remarks Fonction utilisee dans les pdf et les pages html * \param rate Rate value to format (19.6 19,6 19.6% 19,6%,...) * \param foundpercent Add a percent % sign in output * \param info_bits Miscellanous information on vat - * \return string Chaine avec montant format� (19,6 ou 19,6% ou 8.5% * + * \return string Chaine avec montant formate (19,6 ou 19,6% ou 8.5% *) */ function vatrate($rate,$addpercent=false,$info_bits=0) { @@ -2130,15 +2130,15 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $rounding=2) } /** - * \brief Fonction qui retourne un numerique conforme SQL, depuis un montant au - * format utilisateur. + * \brief Fonction qui retourne un numerique conforme SQL, depuis un montant issu d'une saisie + * utilisateur. * \remarks Fonction a appeler sur montants saisis avant un insert en base * \param amount Montant a formater * \param rounding 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) * 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT) * 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN) * ''=No rounding - * \return string Montant au format numerique PHP et SQL (Exemple: '99.99999') + * \return string Montant au format numerique universel et SQL (Exemple: '99.99999') * \seealso price Fonction inverse de price2num */ function price2num($amount,$rounding='',$alreadysqlnb=-1) @@ -2153,27 +2153,50 @@ function price2num($amount,$rounding='',$alreadysqlnb=-1) if ($langs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->trans("SeparatorDecimal"); if ($langs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->trans("SeparatorThousand"); - //print 'x'.$dec.$thousand.'-'; + // Define nbofdec + $nbofdec=max(0,strlen($amount-intval($amount))-2); + + // Convert value to universal number format (no thousand separator, '.' as decimal separator) if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format { + //print 'ZZ'.$nbofdec.'=>'.$amount.'
'; + + // Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number + // to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup. + $amount=number_format($amount,$nbofdec,$dec,$thousand); + //print "QQ".$amount.'
'; + + // Now make replace (the main goal of function) if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users - $amount=str_replace(' ','',$amount); // To avoid spaces + $amount=str_replace(' ','',$amount); // To avoid spaces $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is . $amount=str_replace($dec,'.',$amount); } + + // Now if rounding required if ($rounding) { - if ($rounding == 'MU') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_UNIT); - elseif ($rounding == 'MT') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_TOT); - elseif ($rounding == 'MS') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_SHOWN); - else $amount='ErrorBadParameterProvidedToFunction'; + $nbofdectoround=''; + if ($rounding == 'MU') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT; + elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT; + elseif ($rounding == 'MS') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_SHOWN; + if ($nbofdectoround) $amount = round($amount,$nbofdectoround); + else return 'ErrorBadParameterProvidedToFunction'; + //print 'ZZ'.$nbofdec.'-'.$nbofdectoround.'=>'.$amount.'
'; + + // Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number + // to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup. + $amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand + //print "RR".$amount.'
'; + // Always make replace because each math function (like round) replace // with local values and we want a number that has a SQL string format x.y if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users - $amount=str_replace(' ','',$amount); // To avoid spaces + $amount=str_replace(' ','',$amount); // To avoid spaces $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is . $amount=str_replace($dec,'.',$amount); } + return $amount; } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 0f2f308b9a1..f2cf977e7f8 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2090,7 +2090,7 @@ class Product extends CommonObject $lien = ''; $lienfin=''; $newref=$this->ref; - if ($maxlength) $newref=dolibarr_trunc($newref,$maxlength); + if ($maxlength) $newref=dolibarr_trunc($newref,$maxlength,'middle'); if ($withpicto) { if ($this->type == 0) $result.=($lien.img_object($langs->trans("ShowProduct").' '.$this->ref,'product').$lienfin.' '); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 7a8bdfd80a2..9905ad0e211 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -65,9 +65,9 @@ class Propal extends CommonObject var $date_livraison; var $fin_validite; - var $price; // Total HT - var $tva; // Total TVA - var $total; // Total TTC + var $price; // Total net of tax + var $tva; // Total VAT + var $total; // Total with tax var $cond_reglement_id; var $cond_reglement_code; var $mode_reglement_id;