diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 4b06a812ca2..6499e99025c 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -687,7 +687,12 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
if ($facid > 0)
{
- require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
+ if (file_exists(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php')) {
+ require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
+ } else {
+ require_once(DOL_DOCUMENT_EXTMODULE.'/'.$element.'/class/'.$subelement.'.class.php');
+ }
+
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
@@ -1385,17 +1390,23 @@ if ($_GET['action'] == 'create')
{
$projectid=GETPOST('originid');
}
- else if (in_array($element,array('order','commande','propal','contrat','contract')))
+ else
{
// For compatibility
if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
if ($element == 'contract') { $element = $subelement = 'contrat'; }
- require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
+ if (file_exists(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php')) {
+ require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
+ } else {
+ require_once(DOL_DOCUMENT_EXTMODULE.'/'.$element.'/class/'.$subelement.'.class.php');
+ }
+
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);
$objectsrc->fetch(GETPOST('originid'));
+ if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
$objectsrc->fetch_thirdparty();
$projectid = (!empty($objectsrc->fk_project)?$object->fk_project:'');
@@ -1775,155 +1786,16 @@ if ($_GET['action'] == 'create')
print "\n";
- // Try to read line from origin
- $sql='';
-
- // TODO deplacer dans la classe
- if ($_GET['origin'] == 'propal')
+ // Show origin lines
+ if (is_object($objectsrc))
{
- //$objectsrc->printOriginLinesList();
-
$title=$langs->trans('ProductsAndServices');
-
- $sql = 'SELECT pt.rowid, pt.description, pt.fk_remise_except,';
- $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.product_type, pt.info_bits,';
- $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid';
- $sql.= ' WHERE pt.fk_propal = '.$objectsrc->id;
- $sql.= ' ORDER BY pt.rang ASC, pt.rowid';
- }
- // TODO deplacer dans la classe
- if ($_GET['origin'] == 'commande')
- {
- $title=$langs->trans('Products');
-
- $sql = 'SELECT pt.rowid, pt.description, pt.fk_remise_except,';
- $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.product_type, pt.info_bits,';
- $sql.= ' pt.date_start as date_debut_prevue, pt.date_end as date_fin_prevue,';
- $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as pt';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid';
- $sql.= ' WHERE pt.fk_commande = '.$objectsrc->id;
- $sql.= ' ORDER BY pt.rowid ASC';
- }
- // TODO deplacer dans la classe
- if ($_GET['origin'] == 'contrat')
- {
- $title=$langs->trans('Services');
-
- $sql = 'SELECT pt.rowid, pt.description,';
- $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
- $sql.= ' pt.date_ouverture_prevue as date_debut_prevue, pt.date_ouverture as date_debut_reel,';
- $sql.= ' pt.date_fin_validite as date_fin_prevue, pt.date_cloture as date_fin_reel,';
- $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'contratdet as pt';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid';
- $sql.= ' WHERE pt.fk_contrat = '.$objectsrc->id;
- $sql.= ' ORDER BY pt.rowid ASC';
- }
-
- if ($sql)
- {
- print '
';
print_titre($title);
-
+
print '
';
- print '';
- print '| '.$langs->trans('Ref').' | ';
- print ''.$langs->trans('Description').' | ';
- print ''.$langs->trans('VAT').' | ';
- print ''.$langs->trans('PriceUHT').' | ';
- print ''.$langs->trans('Qty').' | ';
- print ''.$langs->trans('ReductionShort').' |
';
-
- // Lignes
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
- $var=True;
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
-
- $date_start=$objp->date_debut_prevue;
- if ($objp->date_debut_reel) $date_start=$objp->date_debut_reel;
- $date_end=$objp->date_fin_prevue;
- if ($objp->date_fin_reel) $date_end=$objp->date_fin_reel;
-
- print '| ';
- if (($objp->info_bits & 2) == 2)
- {
- print '';
- print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
- print '';
- }
- else if ($objp->prodid)
- {
- print '';
- print ($objp->fk_product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'));
- print ' '.$objp->ref.'';
- print $objp->product?' - '.$objp->product:'';
- // Dates
- if ($date_start || $date_end)
- {
- print_date_range($date_start,$date_end);
- }
- }
- else
- {
- print ($objp->product_type == -1 ? ' ' : ($objp->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
- // Dates
- if ($date_start || $date_end)
- {
- print_date_range($date_start,$date_end);
- }
- }
- print " | \n";
- print '';
- if ($objp->description)
- {
- if ($objp->description == '(CREDIT_NOTE)')
- {
- $discount=new DiscountAbsolute($db);
- $discount->fetch($objp->fk_remise_except);
- print $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
- }
- elseif ($obj->description == '(DEPOSIT)')
- {
- $discount=new DiscountAbsolute($db);
- $discount->fetch($objp->fk_remise_except);
- print $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
- }
- else
- {
- print dol_trunc($objp->description,60);
- }
- }
- else
- {
- print ' ';
- }
- print ' | ';
- print ''.vatrate($objp->tva_tx).'% | ';
- print ''.price($objp->subprice).' | ';
- print '';
- print (($objp->info_bits & 2) != 2) ? $objp->qty : ' ';
- print ' | ';
- print '';
- print (($objp->info_bits & 2) != 2) ? $objp->remise_percent.'%' : ' ';
- print ' | ';
- print '
';
- $i++;
- }
- }
- else
- {
- dol_print_error($db);
- }
+
+ $objectsrc->printOriginTitleList();
+ $objectsrc->printOriginLinesList($object);
print '
';
}
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 6e60ea84b37..b367d9c3fd4 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1535,6 +1535,126 @@ class CommonObject
}
}
+ /**
+ * Return HTML table with origin title list
+ */
+ function printOriginTitleList()
+ {
+ global $langs;
+
+ print '';
+ print '| '.$langs->trans('Ref').' | ';
+ print ''.$langs->trans('Description').' | ';
+ print ''.$langs->trans('VAT').' | ';
+ print ''.$langs->trans('PriceUHT').' | ';
+ print ''.$langs->trans('Qty').' | ';
+ print ''.$langs->trans('ReductionShort').' |
';
+ }
+
+ /**
+ * Return HTML with list of origin lines
+ */
+ function printOriginLinesList($object)
+ {
+ $num = count($this->lines);
+ $var = true;
+ $i = 0;
+
+ foreach ($this->lines as $line)
+ {
+ $var=!$var;
+
+ if ($line->product_type == 9 && ! empty($line->special_code))
+ {
+ $object->hooks[$line->special_code]->printOriginObjectLine($line,$i);
+ }
+ else
+ {
+ $this->printOriginLine($line,$var);
+ }
+
+ $i++;
+ }
+ }
+
+ /**
+ * Return HTML with origin line
+ * @param element Element type
+ * @param id Element id
+ */
+ function printOriginLine($line,$var)
+ {
+ global $langs,$bc;
+
+ //var_dump($line);
+
+ $date_start=$line->date_debut_prevue;
+ if ($line->date_debut_reel) $date_start=$line->date_debut_reel;
+ $date_end=$line->date_fin_prevue;
+ if ($line->date_fin_reel) $date_end=$line->date_fin_reel;
+
+ if (($line->info_bits & 2) == 2)
+ {
+ $discount=new DiscountAbsolute($db);
+ $discount->fk_soc = $this->socid;
+ $this->tpl['label'] = $discount->getNomUrl(0,'discount');
+ }
+ else if ($line->fk_product)
+ {
+ $productstatic = new Product($this->db);
+ $productstatic->id = $line->fk_product;
+ $productstatic->ref = $line->ref;
+ $productstatic->type = $line->fk_product_type;
+ $this->tpl['label'] = $productstatic->getNomUrl(1);
+ $this->tpl['label'].= $line->label?' - '.$line->label:'';
+ // Dates
+ if ($date_start || $date_end)
+ {
+ $this->tpl['label'].= get_date_range($date_start,$date_end);
+ }
+ }
+ else
+ {
+ $this->tpl['label'] = ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
+ $this->tpl['label'].= ($line->label ? ' '.$line->label : '');
+ // Dates
+ if ($date_start || $date_end)
+ {
+ $this->tpl['label'].= get_date_range($date_start,$date_end);
+ }
+ }
+
+ if ($line->desc)
+ {
+ if ($line->desc == '(CREDIT_NOTE)')
+ {
+ $discount=new DiscountAbsolute($this->db);
+ $discount->fetch($line->fk_remise_except);
+ $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
+ }
+ elseif ($line->desc == '(DEPOSIT)')
+ {
+ $discount=new DiscountAbsolute($this->db);
+ $discount->fetch($line->fk_remise_except);
+ $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
+ }
+ else
+ {
+ $this->tpl['description'] = dol_trunc($line->desc,60);
+ }
+ }
+ else
+ {
+ $this->tpl['description'] = ' ';
+ }
+
+ $this->tpl['vat_rate'] = vatrate($line->tva_tx);
+ $this->tpl['price'] = price($line->subprice);
+ $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' ';
+ $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? $line->remise_percent.'%' : ' ';
+
+ include(DOL_DOCUMENT_ROOT.'/core/tpl/originproductline.tpl.php');
+ }
}
?>
diff --git a/htdocs/core/tpl/originproductline.tpl.php b/htdocs/core/tpl/originproductline.tpl.php
new file mode 100644
index 00000000000..6848900cbde
--- /dev/null
+++ b/htdocs/core/tpl/originproductline.tpl.php
@@ -0,0 +1,31 @@
+
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+?>
+
+
+>
+ | tpl['label']; ?> |
+ tpl['description']; ?> |
+ tpl['vat_rate']; ?>% |
+ tpl['price']; ?> |
+ tpl['qty']; ?> |
+ tpl['remise_percent']; ?> |
+
+
\ No newline at end of file
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index edb1bc5acd3..af2821cdffa 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -3292,7 +3292,6 @@ function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='')
return $chaine;
}
-
/**
* Format output for start and end date
* @param date_start Start date
@@ -3300,23 +3299,38 @@ function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='')
* @param format Output format
*/
function print_date_range($date_start,$date_end,$format = '',$outputlangs='')
+{
+ print get_date_range($date_start,$date_end,$format,$outputlangs);
+}
+
+/**
+ * Format output for start and end date
+ * @param date_start Start date
+ * @param date_end End date
+ * @param format Output format
+ */
+function get_date_range($date_start,$date_end,$format = '',$outputlangs='')
{
global $langs;
+
+ $out='';
if (! is_object($outputlangs)) $outputlangs=$langs;
if ($date_start && $date_end)
{
- print ' ('.$outputlangs->trans('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).')';
+ $out.= ' ('.$outputlangs->trans('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).')';
}
if ($date_start && ! $date_end)
{
- print ' ('.$outputlangs->trans('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).')';
+ $out.= ' ('.$outputlangs->trans('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).')';
}
if (! $date_start && $date_end)
{
- print ' ('.$outputlangs->trans('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).')';
+ $out.= ' ('.$outputlangs->trans('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).')';
}
+
+ return $out;
}