Qual: Uniformize code

Doc: Doxygen
This commit is contained in:
Laurent Destailleur 2010-08-18 07:28:12 +00:00
parent b7da077da6
commit fdc13a2480
4 changed files with 163 additions and 144 deletions

View File

@ -266,7 +266,7 @@ class Propal extends CommonObject
}
/**
* \brief Add new line in database
* Add a proposal line into database (linked to product/service or not)
* \param propalid Id de la propale
* \param desc Description de la ligne
* \param pu_ht Prix unitaire
@ -279,8 +279,10 @@ class Propal extends CommonObject
* \param price_base_type HT or TTC
* \param pu_ttc Prix unitaire TTC
* \param info_bits Bits de type de lignes
* \param type Type of line (product, service)
* \param rang Position of line
* \return int >0 if OK, <0 if KO
* \see add_product
* @see add_product
* \remarks 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)
@ -293,28 +295,35 @@ class Propal extends CommonObject
dol_syslog("Propal::Addline propalid=$propalid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type");
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;
$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;
}
// Check parameters
if ($type < 0) return -1;
if ($this->statut == 0)
{
$this->db->begin();
// Clean parameters
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (empty($qty)) $qty=0; // If 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;
}
// 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
@ -325,7 +334,7 @@ class Propal extends CommonObject
$total_ttc = $tabprice[2];
$total_localtax1 = $tabprice[9];
$total_localtax2 = $tabprice[10];
// Rang to use
$rangtouse = $rang;
if ($rangtouse == -1)
@ -423,29 +432,18 @@ class Propal extends CommonObject
dol_syslog("Propal::UpdateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
// Clean parameters
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
$pu = price2num($pu);
$txtva = price2num($txtva);
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
if ($this->statut == 0)
{
$this->db->begin();
// Nettoyage param<61>tres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
/*
if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty)
{
$qty=0;
$remise_percent=0;
}
else if (! $qty)
{
$qty=1;
}
*/
$pu = price2num($pu);
$txtva = price2num($txtva);
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
// 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
@ -502,7 +500,7 @@ class Propal extends CommonObject
// Fin appel triggers
}
$this->db->commit();
$this->db->commit();
return $result;
}
else
@ -1414,7 +1412,7 @@ class Propal extends CommonObject
* \param limit For pagination
* \param offset For pagination
* \param sortfield Sort criteria
* \param sortorder Sort order
* \param sortorder Sort order
* \return int -1 if KO, array with result if OK
*/
function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datep', $sortorder='DESC')
@ -1463,7 +1461,7 @@ class Propal extends CommonObject
}
else
{
dol_print_error($this->db);
dol_print_error($this->db);
return -1;
}
}
@ -2260,19 +2258,23 @@ class PropaleLigne
*/
function insert()
{
global $conf;
global $conf;
dol_syslog("PropaleLigne::insert rang=".$this->rang);
$this->db->begin();
// Clean parameters
if (! $this->remise) $this->remise=0;
if (! $this->remise_percent) $this->remise_percent=0;
if (! $this->info_bits) $this->info_bits=0;
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->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;
// Check parameters
if ($this->type < 0) return -1;
if ($this->product_type < 0) return -1;
$this->db->begin();
// Insert line into database
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';

View File

@ -804,27 +804,28 @@ class Commande extends CommonObject
/**
* \brief Add a line
* \param commandeid Id de la commande
* \param desc Description de la ligne
* \param pu_ht Prix unitaire HT
* \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)
* \return int >0 si ok, <0 si ko
* \see add_product
* \remarks 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
* 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 si ok, <0 si ko
* @see add_product
* @remarks 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)
*/
@ -838,6 +839,7 @@ class Commande extends CommonObject
if (empty($remise_percent)) $remise_percent=0;
if (empty($qty)) $qty=0;
if (empty($info_bits)) $info_bits=0;
if (empty($rang)) $rang=0;
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
@ -873,7 +875,7 @@ class Commande extends CommonObject
$total_ttc = $tabprice[2];
$total_localtax1 = $tabprice[9];
$total_localtax2 = $tabprice[10];
// Rang to use
$rangtouse = $rang;
if ($rangtouse == -1)
@ -2624,8 +2626,15 @@ class OrderLine
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->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;
$this->db->begin();
// Check parameters
if ($this->product_type < 0) return -1;
$this->db->begin();
// Insertion dans base de la ligne
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';

View File

@ -1565,7 +1565,7 @@ class Facture extends CommonObject
/**
* \brief Add an invoice line into database (linked to product/service or not)
* Add an invoice line into database (linked to product/service or not)
* \param facid Id de la facture
* \param desc Description de la ligne
* \param pu_ht Prix unitaire HT
@ -1583,6 +1583,7 @@ class Facture extends CommonObject
* \param price_base_type HT or TTC
* \param pu_ttc Prix unitaire TTC
* \param type Type of line (0=product, 1=service)
* \param rang Position of line
* \return int >0 if OK, <0 if KO
* \remarks 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
@ -1594,6 +1595,30 @@ class Facture extends CommonObject
dol_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,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($ventil)) $ventil=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;
}
// Check parameters
if ($type < 0) return -1;
@ -1601,28 +1626,6 @@ class Facture extends CommonObject
{
$this->db->begin();
// Clean parameters
if (empty($remise_percent)) $remise_percent=0;
if (empty($qty)) $qty=0;
if (empty($ventil)) $ventil=0;
if (empty($info_bits)) $info_bits=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;
}
// 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
@ -1633,7 +1636,7 @@ class Facture extends CommonObject
$total_ttc = $tabprice[2];
$total_localtax1 = $tabprice[9];
$total_localtax2 = $tabprice[10];
// Rang to use
$rangtouse = $rang;
if ($rangtouse == -1)
@ -2640,8 +2643,8 @@ class Facture extends CommonObject
$sql.= ' WHERE fk_facture = '.$this->id;
$sql.= ' AND traite = 0';
$resql=$this->db->query($sql);
if ($resql)
$resql=$this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
if ($row[0] == 0)
@ -3024,16 +3027,20 @@ class FactureLigne
dol_syslog("FactureLigne::Insert rang=".$this->rang, LOG_DEBUG);
// Clean parameters
$this->desc=trim($this->desc);
if (empty($this->subprice)) $this->subprice=0;
if (empty($this->price)) $this->price=0;
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
$this->desc=trim($this->desc);
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->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->subprice)) $this->subprice=0;
if (empty($this->price)) $this->price=0;
// Check parameters
if ($this->product_type < 0) return -1;
// Check parameters
if ($this->product_type < 0) return -1;
$this->db->begin();

View File

@ -35,7 +35,7 @@ class CommonObject
{
// Instantiate classes of thirdparty module
var $objModules=array();
/**
* \brief Check if ref is used.
* \return int <0 if KO, 0 if not found, >0 if found
@ -802,7 +802,8 @@ class CommonObject
}
/**
* \brief Get max value for rang
* Get max value used for position of line (rang)
* @result int Max value of rang in table of lines
*/
function line_max()
{
@ -1143,7 +1144,7 @@ class CommonObject
print $sql;
}
}
/**
* Instantiate hooks of thirdparty module
* @param $type Type of hook
@ -1151,7 +1152,7 @@ class CommonObject
function callHooks($type='objectcard')
{
global $conf;
foreach($conf->hooks_modules as $module => $hooks)
{
if ($conf->$module->enabled && in_array($type,$hooks))
@ -1165,13 +1166,13 @@ class CommonObject
{
require_once(DOL_DOCUMENT_ROOT.'/'.$module.'/lib/'.$module.'.lib.php');
}
$classname = ucfirst($module);
$this->objModules[] = new $classname($this->db);
}
}
}
/**
* Show add predefined products/services form
*/
@ -1182,7 +1183,7 @@ class CommonObject
include(DOL_DOCUMENT_ROOT.'/core/tpl/addpredefinedproductform.tpl.php');
}
/**
* Show add free products/services form
*/
@ -1220,15 +1221,15 @@ class CommonObject
return $num;
}
}
/**
* Return HTML table with title list
* TODO mettre le html dans un template
* TODO mettre le html dans un template
*/
function print_title_list()
{
global $conf,$langs;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Description').'</td>';
if ($conf->global->PRODUIT_USE_MARKUP) print '<td align="right" width="80">'.$langs->trans('Markup').'</td>';
@ -1240,7 +1241,7 @@ class CommonObject
print '<td width="48" colspan="3">&nbsp;</td>';
print "</tr>\n";
}
/**
* Return HTML with object lines list
* @param lines Object lines
@ -1250,51 +1251,51 @@ class CommonObject
$num = count($lines);
$var = true;
$i = 0;
foreach ($lines as $line)
{
$var=!$var;
$this->printLine($line,$var,$num,$i,$dateSelector);
$i++;
}
}
/**
* Return HTML with selected object line
* @param line Selected object line
* TODO mettre le html dans un template
* TODO mettre le html dans un template
*/
function printLine($line,$var=true,$num=0,$i=0,$dateSelector=0)
{
global $conf,$langs,$user;
global $html,$bc;
$element = $this->element;
// TODO uniformiser
if ($element == 'propal') $element = 'propale';
// Show product and description
$type=$line->product_type?$line->product_type:$line->fk_product_type;
// 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;
// Ligne en mode visu
if ($_GET['action'] != 'editline' || $_GET['lineid'] != $line->id)
{
print '<tr '.$bc[$var].'>';
// Produit
if ($line->fk_product > 0)
{
$product_static = new Product($db);
print '<td>';
print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne;
// Show product and description
$product_static->type=$line->fk_product_type;
$product_static->id=$line->fk_product;
@ -1304,16 +1305,16 @@ class CommonObject
$text.= ' - '.$line->product_label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
print $html->textwithtooltip($text,$description,3,'','',$i);
// Show range
print_date_range($line->date_start, $line->date_end);
// Add description in form
if ($conf->global->PRODUIT_DESC_IN_FORM)
{
print ($line->description && $line->description!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->description):'';
}
print '</td>';
}
else
@ -1349,7 +1350,7 @@ class CommonObject
}
print "</td>\n";
}
// TODO a déplacer dans classe module marge
/*
if ($conf->global->PRODUIT_USE_MARKUP && $conf->use_javascript_ajax)
@ -1408,10 +1409,10 @@ class CommonObject
// VAT Rate
print '<td align="right" nowrap="nowrap">'.vatrate($line->tva_tx,'%',$line->info_bits).'</td>';
// U.P HT
print '<td align="right" nowrap="nowrap">'.price($line->subprice)."</td>\n";
// Qty
print '<td align="right" nowrap="nowrap">';
if ((($line->info_bits & 2) != 2) && $line->special_code != 3)
@ -1420,7 +1421,7 @@ class CommonObject
}
else print '&nbsp;';
print '</td>';
// Remise percent (negative or positive)
if (!empty($line->remise_percent) && $line->special_code != 3)
{
@ -1430,7 +1431,7 @@ class CommonObject
{
print '<td>&nbsp;</td>';
}
// Montant total HT
if ($line->special_code == 3)
{
@ -1441,7 +1442,7 @@ class CommonObject
{
print '<td align="right" nowrap="nowrap">'.price($line->total_ht)."</td>\n";
}
// Icone d'edition et suppression
if ($this->statut == 0 && $user->rights->$element->creer)
{
@ -1483,10 +1484,10 @@ class CommonObject
{
print '<td colspan="3">&nbsp;</td>';
}
print '</tr>';
}
// Ligne en mode update
if ($this->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["lineid"] == $line->id)
{
@ -1525,10 +1526,10 @@ class CommonObject
}
}
print '</td>';
// TODO a déplacer dans classe module marge
//if ($conf->global->PRODUIT_USE_MARKUP) print '<td align="right">'.vatrate($line->marge_tx).'%</td>';
print '<td align="right">';
print $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits);
print '</td>';
@ -1550,7 +1551,7 @@ class CommonObject
print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
print '</tr>' . "\n";
// Start and end dates selector
if ($conf->service->enabled && $dateSelector)
{
@ -1562,7 +1563,7 @@ class CommonObject
print '</td>';
print '</tr>';
}
print "</form>\n";
}
}