Fix: more open for external modules and less intrusive

This commit is contained in:
Regis Houssin 2010-12-17 10:08:31 +00:00
parent f559e6573e
commit 3545ed51c5
4 changed files with 189 additions and 152 deletions

View File

@ -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 "</form>\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 '<br>';
print_titre($title);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right">'.$langs->trans('VAT').'</td>';
print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right">'.$langs->trans('Qty').'</td>';
print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
// 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 '<tr '.$bc[$var].'><td>';
if (($objp->info_bits & 2) == 2)
{
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$propal->socid.'">';
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
print '</a>';
}
else if ($objp->prodid)
{
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->prodid.'">';
print ($objp->fk_product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'));
print ' '.$objp->ref.'</a>';
print $objp->product?' - '.$objp->product:'';
// Dates
if ($date_start || $date_end)
{
print_date_range($date_start,$date_end);
}
}
else
{
print ($objp->product_type == -1 ? '&nbsp;' : ($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 "</td>\n";
print '<td>';
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 '&nbsp;';
}
print '</td>';
print '<td align="right">'.vatrate($objp->tva_tx).'%</td>';
print '<td align="right">'.price($objp->subprice).'</td>';
print '<td align="right">';
print (($objp->info_bits & 2) != 2) ? $objp->qty : '&nbsp;';
print '</td>';
print '<td align="right">';
print (($objp->info_bits & 2) != 2) ? $objp->remise_percent.'%' : '&nbsp;';
print '</td>';
print '</tr>';
$i++;
}
}
else
{
dol_print_error($db);
}
$objectsrc->printOriginTitleList();
$objectsrc->printOriginLinesList($object);
print '</table>';
}

View File

@ -1535,6 +1535,126 @@ class CommonObject
}
}
/**
* Return HTML table with origin title list
*/
function printOriginTitleList()
{
global $langs;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right">'.$langs->trans('VAT').'</td>';
print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right">'.$langs->trans('Qty').'</td>';
print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
}
/**
* 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 ? '&nbsp;' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
$this->tpl['label'].= ($line->label ? '&nbsp;'.$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'] = '&nbsp;';
}
$this->tpl['vat_rate'] = vatrate($line->tva_tx);
$this->tpl['price'] = price($line->subprice);
$this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
$this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? $line->remise_percent.'%' : '&nbsp;';
include(DOL_DOCUMENT_ROOT.'/core/tpl/originproductline.tpl.php');
}
}
?>

View File

@ -0,0 +1,31 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
*
* 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$
*/
?>
<!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
<tr <?php echo $bc[$var]; ?>>
<td><?php echo $this->tpl['label']; ?></td>
<td><?php echo $this->tpl['description']; ?></td>
<td align="right"><?php echo $this->tpl['vat_rate']; ?>%</td>
<td align="right"><?php echo $this->tpl['price']; ?></td>
<td align="right"><?php echo $this->tpl['qty']; ?></td>
<td align="right"><?php echo $this->tpl['remise_percent']; ?></td>
</tr>
<!-- END PHP TEMPLATE predefinedproductline_view.tpl.php -->

View File

@ -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;
}