Fix: add customer_ref in propal list and clean code

This commit is contained in:
Regis Houssin 2012-04-06 11:38:13 +02:00
parent 533d862470
commit 1c2f192dd6
6 changed files with 172 additions and 293 deletions

View File

@ -104,9 +104,9 @@ if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc
if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ
if ($search_nom) $sql.= " AND s.nom like '%".$db->escape(strtolower($search_nom))."%'";
if ($search_ville) $sql.= " AND s.ville like '%".$db->escape(strtolower($search_ville))."%'";
if ($search_code) $sql.= " AND s.code_client like '%".$db->escape(strtolower($search_code))."%'";
if ($search_nom) $sql.= " AND s.nom LIKE '%".$db->escape(strtolower($search_nom))."%'";
if ($search_ville) $sql.= " AND s.ville LIKE '%".$db->escape(strtolower($search_ville))."%'";
if ($search_code) $sql.= " AND s.code_client LIKE '%".$db->escape(strtolower($search_code))."%'";
if ($search_compta) $sql .= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'";
// Insert sale filter
if ($search_sale)
@ -120,7 +120,7 @@ if ($search_categ)
}
if ($socname)
{
$sql.= " AND s.nom like '%".$db->escape(strtolower($socname))."%'";
$sql.= " AND s.nom LIKE '%".$db->escape(strtolower($socname))."%'";
$sortfield = "s.nom";
$sortorder = "ASC";
}

View File

@ -55,6 +55,7 @@ $confirm=GETPOST('confirm','alpha');
$lineid=GETPOST('lineid','int');
$search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
$search_refcustomer=GETPOST('search_refcustomer','alpha');
$search_societe=GETPOST('search_societe','alpha');
$search_montant_ht=GETPOST('search_montant_ht','alpha');
@ -1567,16 +1568,12 @@ if ($id > 0 || ! empty($ref))
include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php');
}
// TODO test using div instead of tables
//print '<div class="table" id="tablelines">';
print '<table id="tablelines" class="noborder" width="100%">';
// Show object lines
$result = $object->getLinesArray();
if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager);
//print '<table id="tablelines" class="noborder" width="100%">';
/*
* Form to add new line
*/
@ -1601,9 +1598,7 @@ if ($id > 0 || ! empty($ref))
}
}
// TODO test using div instead of tables
print '</table>';
//print '</div>';
print '</div>';
print "\n";
@ -1872,18 +1867,18 @@ else
$limit = $conf->liste_limit;
$sql = 'SELECT s.nom, s.rowid, s.client, ';
$sql.= 'p.rowid as propalid, p.total_ht, p.ref, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
$sql.= 'p.rowid as propalid, p.total_ht, p.ref, p.ref_client, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,';
if (! $user->rights->societe->client->voir && ! $socid) $sql .= " sc.fk_soc, sc.fk_user,";
$sql.= ' u.login';
$sql.= ' FROM ('.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ')';
if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid';
$sql.= ' WHERE p.fk_soc = s.rowid';
$sql.= ' AND p.entity = '.$conf->entity;
if (!$user->rights->societe->client->voir && !$socid) //restriction
if (! $user->rights->societe->client->voir && ! $socid) //restriction
{
$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
}
@ -1891,6 +1886,10 @@ else
{
$sql.= " AND p.ref LIKE '%".$db->escape(trim($search_ref))."%'";
}
if ($search_refcustomer)
{
$sql.= " AND p.ref_client LIKE '%".$db->escape(trim($search_refcustomer))."%'";
}
if ($search_societe)
{
$sql.= " AND s.nom LIKE '%".$db->escape(trim($search_societe))."%'";
@ -1944,6 +1943,7 @@ else
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('RefCustomer'),$_SERVER["PHP_SELF"],'p.ref_client','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','',$param, 'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','',$param, 'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('AmountHT'),$_SERVER["PHP_SELF"],'p.total_ht','',$param, 'align="right"',$sortfield,$sortorder);
@ -1961,11 +1961,13 @@ else
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="16" name="search_societe" value="'.$search_societe.'">';
print '</td>';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_refcustomer" value="'.$search_refcustomer.'">';
print '</td>';
print '<td class="liste_titre" colspan="1" align="center">';
print $langs->trans('Month').': <input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
print '&nbsp;'.$langs->trans('Year').': ';
$syear = $year;
//if($syear == '') $syear = date("Y");
$formother->select_year($syear,'year',1, 20, 5);
print '</td>';
print '<td class="liste_titre" colspan="1">&nbsp;</td>';
@ -2026,6 +2028,11 @@ else
print '<td>';
print $companystatic->getNomUrl(1,'customer');
print '</td>';
// Customer ref
print '<td nowrap="nowrap">';
print $objp->ref_client;
print '</td>';
// Date propale
print '<td align="center">';

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 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

View File

@ -2347,183 +2347,159 @@ abstract class CommonObject
/* This is to show array of line of details */
/**
* Return HTML table for object lines
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*
* @param string $action Action code
* @param string $seller Object of seller third party
* @param string $buyer Object of buyer third party
* @param string $selected Object line selected
* @param int $dateSelector 1=Show also date range input fields
* @param HookManager $hookmanager Hookmanager
* @return void
*/
function printObjectLines($action,$seller,$buyer,$selected=0,$dateSelector=0,$hookmanager=false)
{
global $conf,$langs;
// TODO test using div instead of tables
/*
print '<div class="table" id="tablelines">';
print '<div class="thead">';
print '<div class="tr">';
print '<div class="td firstcol">'.$langs->trans('Description').'</div>';
print '<div class="td">'.$langs->trans('VAT').'</div>';
print '<div class="td">'.$langs->trans('PriceUHT').'</div>';
print '<div class="td">'.$langs->trans('Qty').'</div>';
print '<div class="td">'.$langs->trans('ReductionShort').'</div>';
print '<div class="td">'.$langs->trans('TotalHTShort').'</div>';
print '<div class="td endcol">&nbsp;</div>';
print '<div class="td endcol">&nbsp;</div>';
print '<div class="td end">&nbsp;</div>';
print '</div></div>';
*/
print '<tr class="liste_titre nodrag nodrop">';
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
{
print '<td align="center" width="5">&nbsp;</td>';
}
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
print '<td align="right" width="50">'.$langs->trans('TotalHTShort').'</td>';
print '<td width="10">&nbsp;</td>';
print '<td width="10">&nbsp;</td>';
print '<td nowrap="nowrap">&nbsp;</td>'; // No width to allow autodim
print "</tr>\n";
$num = count($this->lines);
$var = true;
$i = 0;
//print '<div class="tbody">';
foreach ($this->lines as $line)
{
$var=!$var;
if (is_object($hookmanager) && ( ($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line) ) )
{
if (empty($line->fk_parent_line))
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected);
$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
}
}
else
{
$this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$hookmanager);
}
$i++;
}
//print '</div></div>';
}
/**
* Return HTML content of a detail line
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
*
* @param string $action GET/POST action
* @param array $line Selected object line to output
* @param string $var Is it a an odd line (true)
* @param int $num Number of line (0)
* @param int $i I
* @param int $dateSelector 1=Show also date range input fields
* @param string $seller Object of seller third party
* @param string $buyer Object of buyer third party
* @param string $selected Object line selected
* @param HookManager $hookmanager Hook manager
* @return void
/**
* Return HTML table for object lines
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*
* @param string $action Action code
* @param string $seller Object of seller third party
* @param string $buyer Object of buyer third party
* @param string $selected Object line selected
* @param int $dateSelector 1=Show also date range input fields
* @param HookManager $hookmanager Hookmanager
* @return void
*/
function printObjectLines($action,$seller,$buyer,$selected=0,$dateSelector=0,$hookmanager=false)
{
global $conf,$langs;
print '<tr class="liste_titre nodrag nodrop">';
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
{
print '<td align="center" width="5">&nbsp;</td>';
}
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
print '<td align="right" width="50">'.$langs->trans('TotalHTShort').'</td>';
print '<td width="10">&nbsp;</td>';
print '<td width="10">&nbsp;</td>';
print '<td nowrap="nowrap">&nbsp;</td>'; // No width to allow autodim
print "</tr>\n";
$num = count($this->lines);
$var = true;
$i = 0;
foreach ($this->lines as $line)
{
$var=!$var;
if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
{
if (empty($line->fk_parent_line))
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected);
$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
}
}
else
{
$this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$hookmanager);
}
$i++;
}
}
/**
* Return HTML content of a detail line
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
*
* @param string $action GET/POST action
* @param array $line Selected object line to output
* @param string $var Is it a an odd line (true)
* @param int $num Number of line (0)
* @param int $i I
* @param int $dateSelector 1=Show also date range input fields
* @param string $seller Object of seller third party
* @param string $buyer Object of buyer third party
* @param string $selected Object line selected
* @param HookManager $hookmanager Hook manager
* @return void
*/
function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$hookmanager=false)
{
global $conf,$langs,$user;
global $form,$bc,$bcdd;
$element = $this->element;
if ($element == 'propal') $element = 'propale'; // To work with non standard path
// 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 ($action != 'editline' || $selected != $line->id)
{
// Produit
if ($line->fk_product > 0)
{
$product_static = new Product($this->db);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
{
$this->fetch_thirdparty();
$prod = new Product($this->db, $line->fk_product);
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
if (empty($newlang)) $newlang=$this->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $line->product_label;
}
else {
$label = $line->product_label;
}
$product_static->type=$line->fk_product_type;
$product_static->id=$line->fk_product;
$product_static->ref=$line->ref;
$product_static->libelle=$label;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
// Use global variables + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_view.tpl.php');
//include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductlinediv_view.tpl.php');
}
else
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_view.tpl.php');
}
}
// Ligne en mode update
if ($this->statut == 0 && $action == 'editline' && $selected == $line->id)
{
if ($line->fk_product > 0)
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_edit.tpl.php');
}
else
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_edit.tpl.php');
}
}
}
// 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 ($action != 'editline' || $selected != $line->id)
{
// Produit
if ($line->fk_product > 0)
{
$product_static = new Product($this->db);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
{
$this->fetch_thirdparty();
$prod = new Product($this->db, $line->fk_product);
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
if (empty($newlang)) $newlang=$this->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $line->product_label;
}
else
{
$label = $line->product_label;
}
$product_static->type=$line->fk_product_type;
$product_static->id=$line->fk_product;
$product_static->ref=$line->ref;
$product_static->libelle=$label;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$label;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
// Use global variables + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_view.tpl.php');
}
else
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_view.tpl.php');
}
}
// Ligne en mode update
if ($this->statut == 0 && $action == 'editline' && $selected == $line->id)
{
if ($line->fk_product > 0)
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_edit.tpl.php');
}
else
{
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_edit.tpl.php');
}
}
}
/* This is to show array of line of details of source object */

View File

@ -688,7 +688,7 @@ class FormOther
$currentyear = date("Y")+$offset;
$max_year = $currentyear+$max_year;
$min_year = $currentyear-$min_year;
if(empty($selected)) $selected = $currentyear;
if(empty($selected) && empty($useempty)) $selected = $currentyear;
$out.= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
if($useempty)

View File

@ -1,104 +0,0 @@
<?php
/* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
?>
<!-- BEGIN PHP TEMPLATE predefinedproductline_view.tpl.php -->
<div class="tr pair" <?php echo 'id="row-'.$line->id.'"'; ?>>
<div class="td firstcol">
<div id="<?php echo $line->id; ?>"></div>
<?php
echo $form->textwithtooltip($text,$description,3,'','',$i,0,($line->fk_parent_line?img_picto('', 'rightarrow'):''));
// 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):'';
}
?>
</div>
<div class="td"><?php echo vatrate($line->tva_tx,'%',$line->info_bits); ?></div>
<div class="td"><?php echo price($line->subprice); ?></div>
<div class="td">
<?php if ((($line->info_bits & 2) != 2) && $line->special_code != 3) echo $line->qty;
else echo '&nbsp;'; ?>
</div>
<div class="td">
<?php if (!empty($line->remise_percent) && $line->special_code != 3) {
echo dol_print_reduction($line->remise_percent,$langs);
} else {
echo '&nbsp;';
} ?>
</div>
<div class="td">
<?php if ($line->special_code == 3) {
echo $langs->trans('Option');
} else {
echo price($line->total_ht);
} ?>
</div>
<?php if ($this->statut == 0 && $user->rights->$element->creer) { ?>
<div class="td endcol">
<?php if (($line->info_bits & 2) == 2) { ?>
<?php } else { ?>
<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=editline&amp;lineid='.$line->id.'#'.$line->id; ?>">
<?php echo img_edit(); ?>
</a>
<?php } ?>
</div>
<div class="td endcol">
<a href="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=ask_deleteline&amp;lineid='.$line->id; ?>">
<?php echo img_delete(); ?>
</a>
</div>
<?php if ($num > 1) { ?>
<div class="td end tdlineupdown">
<?php if ($i > 0) { ?>
<a class="lineupdown" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id; ?>">
<?php echo img_up(); ?>
</a>
<?php } ?>
<?php if ($i < $num-1) { ?>
<a class="lineupdown" href="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id; ?>">
<?php echo img_down(); ?>
</a>
<?php } ?>
</div>
<?php } else { ?>
<div class="td endcol tdlineupdown">&nbsp;</div>
<?php } ?>
<?php } else { ?>
<div class="td endcol">&nbsp;</div>
<div class="td endcol">&nbsp;</div>
<div class="td end">&nbsp;</div>
<?php } ?>
</div>
<!-- END PHP TEMPLATE predefinedproductline_view.tpl.php -->