diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index cbd39e4416f..6a58f10fd4f 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1396,13 +1396,13 @@ if ($id > 0 || ! empty($ref))
if (! empty($module->lines))
{
- print_title_list();
+ $propal->print_title_list();
$module->printObjectList($propal, $lines, $sublines);
}
else if (! empty($lines) )
{
- print_title_list();
- print_lines_list($propal, $lines);
+ $propal->print_title_list();
+ $propal->printLinesList($lines);
}
}
}
@@ -1412,8 +1412,8 @@ if ($id > 0 || ! empty($ref))
if (! empty($lines) )
{
- print_title_list();
- print_lines_list($propal, $lines);
+ $propal->print_title_list();
+ $propal->printLinesList($lines);
}
}
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 6ed3121079d..188ee09952d 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -2388,6 +2388,72 @@ class Commande extends CommonObject
return -1;
}
}
+
+ /**
+ * \brief Return an array of order lines
+ * \param option 0=No filter on rang, 1=filter on rang <> 0, 2=filter on rang=0
+ */
+ function getLinesArray($option=0)
+ {
+ $lines = array();
+
+ $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, ';
+ $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,l.rang,';
+ $sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
+ $sql.= ' l.date_start,';
+ $sql.= ' l.date_end,';
+ $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, ';
+ $sql.= ' p.description as product_desc';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
+ $sql.= ' WHERE l.fk_commande = '.$this->id;
+ if ($option == 1) $sql.= ' AND l.rang <> 0';
+ if ($option == 2) $sql.= ' AND l.rang = 0';
+ $sql.= ' ORDER BY l.rang ASC, l.rowid';
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $lines[$i]->id = $obj->rowid;
+ $lines[$i]->description = $obj->description;
+ $lines[$i]->fk_product = $obj->fk_product;
+ $lines[$i]->ref = $obj->ref;
+ $lines[$i]->product_label = $obj->product_label;
+ $lines[$i]->product_desc = $obj->product_desc;
+ $lines[$i]->fk_product_type = $obj->fk_product_type;
+ $lines[$i]->product_type = $obj->product_type;
+ $lines[$i]->qty = $obj->qty;
+ $lines[$i]->subprice = $obj->subprice;
+ $lines[$i]->fk_remise_except = $obj->fk_remise_except;
+ $lines[$i]->remise_percent = $obj->remise_percent;
+ $lines[$i]->tva_tx = $obj->tva_tx;
+ $lines[$i]->info_bits = $obj->info_bits;
+ $lines[$i]->total_ht = $obj->total_ht;
+ $lines[$i]->total_tva = $obj->total_tva;
+ $lines[$i]->total_ttc = $obj->total_ttc;
+ $lines[$i]->special_code = $obj->special_code;
+ $lines[$i]->rang = $obj->rang;
+ $lines[$i]->date_start = $this->db->jdate($obj->date_start);
+ $lines[$i]->date_end = $this->db->jdate($obj->date_end);
+
+ $i++;
+ }
+ $this->db->free($resql);
+ }
+ else
+ {
+ dol_print_error($this->db);
+ }
+
+ return $lines;
+ }
}
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index fafbac00590..a6bc9a4f22d 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -60,11 +60,28 @@ $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
$mesg=isset($_GET['mesg'])?$_GET['mesg']:'';
+// Instantiate hooks of thirdparty module
+if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
+{
+ $hooks = new Commande($db);
+ $hooks->callHooks('objectcard');
+}
+
/******************************************************************************/
/* Actions */
/******************************************************************************/
+// Hook of thirdparty module
+if (! empty($hooks->objModules))
+{
+ foreach($hooks->objModules as $module)
+ {
+ $module->getObjectActions($hooks);
+ $mesg = $module->error;
+ }
+}
+
// Action clone object
if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
{
@@ -380,7 +397,7 @@ if ($_POST['action'] == 'addline' && $user->rights->commande->creer)
$ret=$commande->fetch_thirdparty();
// Clean parameters
- $suffixe = $_POST['idprod'] ? '_prod' : '';
+ $suffixe = $_POST['idprod'] ? '_predef' : '';
$date_start=dol_mktime(0, 0, 0, $_POST['date_start'.$suffixe.'month'], $_POST['date_start'.$suffixe.'day'], $_POST['date_start'.$suffixe.'year']);
$date_end=dol_mktime(0, 0, 0, $_POST['date_end'.$suffixe.'month'], $_POST['date_end'.$suffixe.'day'], $_POST['date_end'.$suffixe.'year']);
$price_base_type = 'HT';
@@ -1657,6 +1674,44 @@ else
/*
* Lines
*/
+
+ print '
';
+
+ // Hook of thirdparty module
+ if (! empty($hooks->objModules))
+ {
+ foreach($hooks->objModules as $module)
+ {
+ $lines = $commande->getLinesArray(1);
+
+ $module->getObjectList($commande);
+ $sublines = $commande->getLinesArray(2);
+
+ if (! empty($module->lines))
+ {
+ $commande->print_title_list();
+ $module->printObjectList($commande, $lines, $sublines,1);
+ }
+ else if (! empty($lines) )
+ {
+ $commande->print_title_list();
+ $commande->printLinesList($lines,1);
+ }
+ }
+ }
+ else
+ {
+ $lines = $commande->getLinesArray(0);
+
+ if (! empty($lines) )
+ {
+ $commande->print_title_list();
+ $commande->printLinesList($lines,1);
+ }
+ }
+
+
+ /*
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, ';
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
@@ -1931,21 +1986,35 @@ else
{
dol_print_error($db);
}
+ */
/*
* Form to add new line
*/
- if ($commande->statut == 0 && $user->rights->commande->creer && $_GET["action"] <> 'editline')
+ if ($commande->statut == 0 && $user->rights->commande->creer)
{
- $var=true;
-
- $commande->showAddFreeProductForm(1);
-
- // Add predefined products/services
- if ($conf->product->enabled || $conf->service->enabled)
+ if (! preg_match('/editline|edit_/',$_GET["action"]))
{
- $var=!$var;
- $commande->showAddPredefinedProductForm(1);
+ $var=true;
+
+ $commande->showAddFreeProductForm(1);
+
+ // Add predefined products/services
+ if ($conf->product->enabled || $conf->service->enabled)
+ {
+ $var=!$var;
+ $commande->showAddPredefinedProductForm(1);
+ }
+
+ // Hook of thirdparty module
+ if (! empty($hooks->objModules))
+ {
+ foreach($hooks->objModules as $module)
+ {
+ $var=!$var;
+ $module->formAddObject($commande);
+ }
+ }
}
}
print '
';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 38a660c53d7..04bbf0546a4 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1222,6 +1222,350 @@ class CommonObject
return $num;
}
}
+
+ /**
+ * Return HTML table with title list
+ */
+ function print_title_list()
+ {
+ global $conf,$langs;
+
+ print '';
+ print '| '.$langs->trans('Description').' | ';
+ if ($conf->global->PRODUIT_USE_MARKUP) print ''.$langs->trans('Markup').' | ';
+ print ''.$langs->trans('VAT').' | ';
+ print ''.$langs->trans('PriceUHT').' | ';
+ print ''.$langs->trans('Qty').' | ';
+ print ''.$langs->trans('ReductionShort').' | ';
+ print ''.$langs->trans('TotalHTShort').' | ';
+ print ' | ';
+ print "
\n";
+ }
+
+ /**
+ * Return HTML with object lines list
+ * @param lines Object lines
+ */
+ function printLinesList($lines,$dateSelector=0)
+ {
+ $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
+ */
+ 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 '';
+
+ // Produit
+ if ($line->fk_product > 0)
+ {
+ $product_static = new Product($db);
+
+ print '';
+ print ''; // ancre pour retourner sur la ligne;
+
+ // Show product and description
+ $product_static->type=$line->fk_product_type;
+ $product_static->id=$line->fk_product;
+ $product_static->ref=$line->ref;
+ $product_static->libelle=$line->product_label;
+ $text=$product_static->getNomUrl(1);
+ $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)?' '.dol_htmlentitiesbr($line->description):'';
+ }
+
+ print ' | ';
+ }
+ else
+ {
+ print '';
+ print ''; // ancre pour retourner sur la ligne
+ if (($line->info_bits & 2) == 2)
+ {
+ print '';
+ print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
+ print '';
+ if ($line->description)
+ {
+ if ($line->description == '(CREDIT_NOTE)')
+ {
+ $discount=new DiscountAbsolute($db);
+ $discount->fetch($line->fk_remise_except);
+ print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
+ }
+ else
+ {
+ print ' - '.nl2br($line->description);
+ }
+ }
+ }
+ else
+ {
+ if ($type==1) $text = img_object($langs->trans('Service'),'service');
+ else $text = img_object($langs->trans('Product'),'product');
+ print $text.' '.nl2br($line->description);
+ // Show range
+ print_date_range($line->date_start,$line->date_end);
+ }
+ print " | \n";
+ }
+
+ // TODO a déplacer dans classe module marge
+ /*
+ if ($conf->global->PRODUIT_USE_MARKUP && $conf->use_javascript_ajax)
+ {
+ $formMarkup = ''."\n";
+ $formMarkup.= ajax_updaterWithID("rate".$i,"markup","sellingprice_ht".$i,DOL_URL_ROOT."/product/ajaxproducts.php","&count=".$i,"working")."\n";
+
+
+ print ''."\n";
+
+ print ' '."\n";
+ print $formMarkup."\n";
+ print ' '."\n";
+
+ print '';
+ print ' | ';
+ }
+ */
+
+ // VAT Rate
+ print ''.vatrate($line->tva_tx,'%',$line->info_bits).' | ';
+
+ // U.P HT
+ print ''.price($line->subprice)." | \n";
+
+ // Qty
+ print '';
+ if ((($line->info_bits & 2) != 2) && $line->special_code != 3)
+ {
+ print $line->qty;
+ }
+ else print ' ';
+ print ' | ';
+
+ // Remise percent (negative or positive)
+ if (!empty($line->remise_percent) && $line->special_code != 3)
+ {
+ print ''.dol_print_reduction($line->remise_percent,$langs)." | \n";
+ }
+ else
+ {
+ print ' | ';
+ }
+
+ // Montant total HT
+ if ($line->special_code == 3)
+ {
+ // Si ligne en option
+ print ''.$langs->trans('Option').' | ';
+ }
+ else
+ {
+ print ''.price($line->total_ht)." | \n";
+ }
+
+ // Icone d'edition et suppression
+ if ($this->statut == 0 && $user->rights->$element->creer)
+ {
+ print '';
+ if (($line->info_bits & 2) == 2)
+ {
+ // Ligne remise predefinie, on permet pas modif
+ }
+ else
+ {
+ print 'id.'&action=editline&lineid='.$line->id.'#'.$line->id.'">';
+ print img_edit();
+ print '';
+ }
+ print ' | ';
+ print '';
+ print 'id.'&action=ask_deleteline&lineid='.$line->id.'">';
+ print img_delete();
+ print ' | ';
+ if ($num > 1)
+ {
+ print '';
+ if ($i > 0)
+ {
+ print 'id.'&action=up&rowid='.$line->id.'">';
+ print img_up();
+ print '';
+ }
+ if ($i < $num-1)
+ {
+ print 'id.'&action=down&rowid='.$line->id.'">';
+ print img_down();
+ print '';
+ }
+ print ' | ';
+ }
+ }
+ else
+ {
+ print ' | ';
+ }
+
+ print '
';
+ }
+
+ // Ligne en mode update
+ if ($this->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["lineid"] == $line->id)
+ {
+ print '\n";
+ }
+ }
}
diff --git a/htdocs/lib/propal.lib.php b/htdocs/lib/propal.lib.php
index 4e6646104b5..8e58530a590 100644
--- a/htdocs/lib/propal.lib.php
+++ b/htdocs/lib/propal.lib.php
@@ -111,335 +111,5 @@ function propal_prepare_head($propal)
return $head;
}
-/**
- * \brief Return HTML table with title list
- * \param propal Object propal
- * \param lines Array of propal lines
- */
-function print_title_list()
-{
- global $conf,$langs;
-
- print '';
- print '| '.$langs->trans('Description').' | ';
- if ($conf->global->PRODUIT_USE_MARKUP) print ''.$langs->trans('Markup').' | ';
- print ''.$langs->trans('VAT').' | ';
- print ''.$langs->trans('PriceUHT').' | ';
- print ''.$langs->trans('Qty').' | ';
- print ''.$langs->trans('ReductionShort').' | ';
- print ''.$langs->trans('TotalHTShort').' | ';
- print ' | ';
- print "
\n";
-}
-
-/**
- * \brief Return HTML with proposal lines
- * \param propal Object proposal
- * \param lines Proposal lines
- */
-function print_lines_list($propal,$lines)
-{
- $num = count($lines);
- $var = true;
- $i = 0;
-
- foreach ($lines as $line)
- {
- $var=!$var;
-
- print_line($propal,$line,$var,$num,$i);
-
- $i++;
- }
-}
-
-/**
- * \brief Return HTML with selected proposal line
- * \param propal Object proposal
- * \param line Selected proposal line
- */
-function print_line($propal,$line,$var=true,$num=0,$i=0)
-{
- global $db;
- global $conf,$langs,$user;
- global $html,$bc;
-
- // 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 '';
-
- // Produit
- if ($line->fk_product > 0)
- {
- $product_static = new Product($db);
-
- print '';
- print ''; // ancre pour retourner sur la ligne;
-
- // Show product and description
- $product_static->type=$line->fk_product_type;
- $product_static->id=$line->fk_product;
- $product_static->ref=$line->ref;
- $product_static->libelle=$line->product_label;
- $text=$product_static->getNomUrl(1);
- $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)?' '.dol_htmlentitiesbr($line->description):'';
- }
-
- print ' | ';
- }
- else
- {
- print '';
- print ''; // ancre pour retourner sur la ligne
- if (($line->info_bits & 2) == 2)
- {
- print '';
- print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
- print '';
- if ($line->description)
- {
- if ($line->description == '(CREDIT_NOTE)')
- {
- $discount=new DiscountAbsolute($db);
- $discount->fetch($line->fk_remise_except);
- print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
- }
- else
- {
- print ' - '.nl2br($line->description);
- }
- }
- }
- else
- {
- if ($type==1) $text = img_object($langs->trans('Service'),'service');
- else $text = img_object($langs->trans('Product'),'product');
- print $text.' '.nl2br($line->description);
- // Show range
- print_date_range($line->date_start,$line->date_end);
- }
- print " | \n";
- }
-
- if ($conf->global->PRODUIT_USE_MARKUP && $conf->use_javascript_ajax)
- {
- // TODO a déplacer dans classe module marge
- $formMarkup = ''."\n";
- $formMarkup.= ajax_updaterWithID("rate".$i,"markup","sellingprice_ht".$i,DOL_URL_ROOT."/product/ajaxproducts.php","&count=".$i,"working")."\n";
-
-
- print ''."\n";
-
- print ' '."\n";
- print $formMarkup."\n";
- print ' '."\n";
-
- print '';
- print ' | ';
- }
-
- // VAT Rate
- print ''.vatrate($line->tva_tx,'%',$line->info_bits).' | ';
-
- // U.P HT
- print ''.price($line->subprice)." | \n";
-
- // Qty
- print '';
- if ((($line->info_bits & 2) != 2) && $line->special_code != 3)
- {
- print $line->qty;
- }
- else print ' ';
- print ' | ';
-
- // Remise percent (negative or positive)
- if (!empty($line->remise_percent) && $line->special_code != 3)
- {
- print ''.dol_print_reduction($line->remise_percent,$langs)." | \n";
- }
- else
- {
- print ' | ';
- }
-
- // Montant total HT
- if ($line->special_code == 3)
- {
- // Si ligne en option
- print ''.$langs->trans('Option').' | ';
- }
- else
- {
- print ''.price($line->total_ht)." | \n";
- }
-
- // Icone d'edition et suppression
- if ($propal->statut == 0 && $user->rights->propale->creer)
- {
- print '';
- if (($line->info_bits & 2) == 2)
- {
- // Ligne remise predefinie, on permet pas modif
- }
- else
- {
- print 'id.'&action=editline&lineid='.$line->id.'#'.$line->id.'">';
- print img_edit();
- print '';
- }
- print ' | ';
- print '';
- print 'id.'&action=ask_deleteline&lineid='.$line->id.'">';
- print img_delete();
- print ' | ';
- if ($num > 1)
- {
- print '';
- if ($i > 0)
- {
- print 'id.'&action=up&rowid='.$line->id.'">';
- print img_up();
- print '';
- }
- if ($i < $num-1)
- {
- print 'id.'&action=down&rowid='.$line->id.'">';
- print img_down();
- print '';
- }
- print ' | ';
- }
- }
- else
- {
- print ' | ';
- }
-
- print '
';
- }
-
- // Ligne en mode update
- if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["lineid"] == $line->id)
- {
- print '\n";
- }
-}
?>
\ No newline at end of file