Skip to content
Snippets Groups Projects
Commit 381d1543 authored by Regis Houssin's avatar Regis Houssin
Browse files

Works on best mutualized code

Works on MVC
parent ed74b696
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@
*/
/**
* \file htdocs/comm/propal/actions_proposal.class.php
* \file htdocs/comm/propal/class/actions_proposal.class.php
* \ingroup proposal
* \brief Fichier de la classe des actions des propales
* \version $Id$
......@@ -43,6 +43,18 @@ class ActionsProposal extends ActionsCommonObject
{
$this->db = $DB;
}
/**
* \brief Load a proposal from database and its ligne array
* \param rowid id of object to load
* \param ref Ref of proposal
* \return int >0 if OK, <0 if KO
*/
function fetch($rowid,$ref='')
{
$this->object = new Propal($this->db);
return $this->object->fetch($rowid,$ref);
}
}
......
<?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.
*/
/**
* \file htdocs/commande/class/actions_proposal.class.php
* \ingroup order
* \brief Fichier de la classe des actions des commandes clients
* \version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/core/class/actions_commonobject.class.php");
require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
/**
* \class ActionsCustomerorder
* \brief Classe permettant la gestion des actions des commandes clients
*/
class ActionsCustomerorder extends ActionsCommonObject
{
var $db;
var $object;
/**
* Constructeur de la classe
* @param DB Handler acces base de donnees
*/
function ActionsCustomerorder($DB)
{
$this->db = $DB;
}
/**
* Get object and lines from database
* @param id Id of object to load
* @param ref Ref of object
* @return int >0 if OK, <0 if KO
*/
function fetch($rowid,$ref='')
{
$this->object = new Commande($this->db);
return $this->object->fetch($rowid,$ref);
}
}
?>
\ No newline at end of file
......@@ -1387,24 +1387,24 @@ if ($_GET['action'] == 'create')
else if (in_array($element,array('order','commande','propal','contrat','contract')))
{
// For compatibility
if ($element == 'order') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
if ($element == 'order') { $element = 'commande'; $subelement = 'customerorder'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'proposal'; }
if ($element == 'contract') { $element = $subelement = 'contrat'; }
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/actions_'.$subelement.'.class.php');
$classname = 'Actions'.ucfirst($subelement);
$objectsrc = new $classname($db);
$objectsrc->fetch(GETPOST('originid'));
$objectsrc->fetch_thirdparty();
$objectsrc->object->fetch_thirdparty();
$projectid = (!empty($objectsrc->fk_project)?$object->fk_project:'');
$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
$projectid = (!empty($objectsrc->object->fk_project)?$object->fk_project:'');
$ref_client = (!empty($objectsrc->object->ref_client)?$object->ref_client:'');
$soc = $objectsrc->client;
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
$remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
$remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
$soc = $objectsrc->object->client;
$cond_reglement_id = (!empty($objectsrc->object->cond_reglement_id)?$objectsrc->object->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
$mode_reglement_id = (!empty($objectsrc->object->mode_reglement_id)?$objectsrc->object->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
$remise_percent = (!empty($objectsrc->object->remise_percent)?$objectsrc->object->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
$remise_absolue = (!empty($objectsrc->object->remise_absolue)?$objectsrc->object->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
}
}
......@@ -1656,7 +1656,7 @@ if ($_GET['action'] == 'create')
print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($objectsrc)) // Take value from source object
{
print $objectsrc->note_public;
print $objectsrc->object->note_public;
}
print '</textarea></td></tr>';
......@@ -1669,7 +1669,7 @@ if ($_GET['action'] == 'create')
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($objectsrc)) // Take value from source object
{
print $objectsrc->note;
print $objectsrc->object->note;
}
print '</textarea></td></tr>';
}
......@@ -1680,35 +1680,35 @@ if ($_GET['action'] == 'create')
if ($_GET['origin'] == 'contrat')
{
// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
$objectsrc->remise_absolue=$remise_absolue;
$objectsrc->remise_percent=$remise_percent;
$objectsrc->update_price();
$objectsrc->object->remise_absolue=$remise_absolue;
$objectsrc->object->remise_percent=$remise_percent;
$objectsrc->object->update_price();
}
print "\n<!-- ".$classname." info -->";
print "\n";
print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
print '<tr><td>'.$langs->trans($classname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
print '<input type="hidden" name="amount" value="'.$objectsrc->object->total_ht.'">'."\n";
print '<input type="hidden" name="total" value="'.$objectsrc->object->total_ttc.'">'."\n";
print '<input type="hidden" name="tva" value="'.$objectsrc->object->total_tva.'">'."\n";
print '<input type="hidden" name="origin" value="'.$objectsrc->object->element.'">';
print '<input type="hidden" name="originid" value="'.$objectsrc->object->id.'">';
print '<tr><td>'.$langs->trans($classname).'</td><td colspan="2">'.$objectsrc->object->getNomUrl(1).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->object->total_ht).'</td></tr>';
print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->object->total_tva)."</td></tr>";
if ($mysoc->pays_code=='ES')
{
if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
{
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->object->total_localtax1)."</td></tr>";
}
if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
{
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td><td colspan="2">'.price($objectsrc->object->total_localtax2)."</td></tr>";
}
}
print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->object->total_ttc)."</td></tr>";
}
else
{
......@@ -1778,10 +1778,19 @@ if ($_GET['action'] == 'create')
$sql='';
// TODO deplacer dans la classe
if ($_GET['origin'] == 'propal')
if (is_object($objectsrc))
{
//$objectsrc->printOriginLinesList();
$title=$langs->trans('ProductsAndServices');
print '<br>';
print_titre($title);
print '<table class="noborder" width="100%">';
$objectsrc->printOriginTitleList();
$objectsrc->printOriginLinesList($object);
print '</table>';
/*
$title=$langs->trans('ProductsAndServices');
$sql = 'SELECT pt.rowid, pt.description, pt.fk_remise_except,';
......@@ -1789,7 +1798,7 @@ if ($_GET['action'] == 'create')
$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.= ' WHERE pt.fk_propal = '.$objectsrc->object->id;
$sql.= ' ORDER BY pt.rang ASC, pt.rowid';
}
// TODO deplacer dans la classe
......@@ -1803,7 +1812,7 @@ if ($_GET['action'] == 'create')
$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.= ' WHERE pt.fk_commande = '.$objectsrc->object->id;
$sql.= ' ORDER BY pt.rowid ASC';
}
// TODO deplacer dans la classe
......@@ -1818,7 +1827,7 @@ if ($_GET['action'] == 'create')
$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.= ' WHERE pt.fk_contrat = '.$objectsrc->object->id;
$sql.= ' ORDER BY pt.rowid ASC';
}
......@@ -1924,7 +1933,7 @@ if ($_GET['action'] == 'create')
dol_print_error($db);
}
print '</table>';
print '</table>';*/
}
}
......
......@@ -45,6 +45,129 @@ class ActionsCommonObject
$this->db = $DB;
}
/**
* 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->object->lines);
$var = true;
$i = 0;
foreach ($this->object->lines as $line)
{
$var=!$var;
if ($line->product_type == 9 && ! empty($line->special_code))
{
$object->hooks[$line->special_code]->printObjectLine($object,$line,$num,$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=!$var;
$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;
print '<tr '.$bc[$var].'><td>';
if (($line->info_bits & 2) == 2)
{
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->socid.'">';
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
print '</a>';
}
else if ($line->fk_product)
{
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product.'">';
print ($line->fk_product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'));
print ' '.$line->ref.'</a>';
print $line->label?' - '.$line->label:'';
// Dates
if ($date_start || $date_end)
{
print_date_range($date_start,$date_end);
}
}
else
{
print ($line->product_type == -1 ? '&nbsp;' : ($line->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 ($line->desc)
{
if ($line->desc == '(CREDIT_NOTE)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
print $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
}
elseif ($line->desc == '(DEPOSIT)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
print $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
}
else
{
print dol_trunc($line->desc,60);
}
}
else
{
print '&nbsp;';
}
print '</td>';
print '<td align="right">'.vatrate($line->tva_tx).'%</td>';
print '<td align="right">'.price($line->subprice).'</td>';
print '<td align="right">';
print (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
print '</td>';
print '<td align="right">';
print (($line->info_bits & 2) != 2) ? $line->remise_percent.'%' : '&nbsp;';
print '</td>';
print '</tr>';
}
}
?>
......@@ -1504,115 +1504,6 @@ class CommonObject
}
}
/**
* Return HTML with list of origin lines
* TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
*/
function printOriginLinesList()
{
$num = count($this->lines);
$var = true;
$i = 0;
foreach ($this->lines as $line)
{
$var=!$var;
if ($line->product_type == 9 && ! empty($line->special_code))
{
//$this->hooks[$line->special_code]->printObjectLine($this,$line,$num,$i);
}
else
{
$this->printOriginLine($line,$var);
}
$i++;
}
}
/**
* Return HTML with origin line
* TODO Move this into page (into a lib.php file if mutualized. No code for output must be present into a business class).
* @param element Element type
* @param id Element id
*/
function printOriginLine($line,$var)
{
global $langs,$bc;
$var=!$var;
$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;
print '<tr '.$bc[$var].'><td>';
if (($line->info_bits & 2) == 2)
{
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->socid.'">';
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
print '</a>';
}
else if ($line->fk_product)
{
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product.'">';
print ($line->fk_product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'));
print ' '.$line->ref.'</a>';
print $line->label?' - '.$line->label:'';
// Dates
if ($date_start || $date_end)
{
print_date_range($date_start,$date_end);
}
}
else
{
print ($line->product_type == -1 ? '&nbsp;' : ($line->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 ($line->desc)
{
if ($line->desc == '(CREDIT_NOTE)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
print $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
}
elseif ($line->desc == '(DEPOSIT)')
{
$discount=new DiscountAbsolute($db);
$discount->fetch($line->fk_remise_except);
print $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
}
else
{
print dol_trunc($line->desc,60);
}
}
else
{
print '&nbsp;';
}
print '</td>';
print '<td align="right">'.vatrate($line->tva_tx).'%</td>';
print '<td align="right">'.price($line->subprice).'</td>';
print '<td align="right">';
print (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
print '</td>';
print '<td align="right">';
print (($line->info_bits & 2) != 2) ? $line->remise_percent.'%' : '&nbsp;';
print '</td>';
print '</tr>';
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment