Fix: uniformize code (in progress)

This commit is contained in:
Regis Houssin 2012-07-20 09:57:50 +02:00
parent 9f3f3703e3
commit fafd79a0f8
37 changed files with 337 additions and 380 deletions

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -12,28 +12,26 @@
* 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.
* or see http://www.gnu.org/
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /marges/admin/marges.php
* \ingroup marges
* \brief Page to setup advanced extra fields module
* \version $Id:$
* \file /htdocs/admin/margin.php
* \ingroup margin
* \brief Page to setup margin module
*/
$res=@include("../main.inc.php"); // For root directory
include("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT."/margin/lib/margins.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
$langs->load("admin");
$langs->load("marges");
$langs->load("margins");
if (!$user->admin)
accessforbidden();
if (! $user->admin) accessforbidden();
$action=GETPOST('action','alpha');
/*
@ -67,7 +65,7 @@ if (preg_match('/del_(.*)/',$action,$reg))
}
}
if ($_POST["action"] == 'remises')
if ($action == 'remises')
{
if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0)
{
@ -79,7 +77,7 @@ if ($_POST["action"] == 'remises')
}
}
if ($_POST["action"] == 'typemarges')
if ($action == 'typemarges')
{
if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0)
{
@ -102,7 +100,7 @@ $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToM
print_fiche_titre($langs->trans("margesSetup"),$linkback,'setup');
$head = marges_admin_prepare_head($adh);
$head = marges_admin_prepare_head();
dol_fiche_head($head, 'parameters', $langs->trans("marges"), 0, 'company');
@ -120,7 +118,7 @@ print '</tr>';
$var=true;
$form = new Form($db);
// GLOBAL DISCOUNT MANAGEMENT
$var=!$var;
print "<form method=\"post\" action=\"marges.php\">";
@ -130,11 +128,11 @@ print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("MARGIN_TYPE").'</td>';
print '<td align="right">'.$langs->trans('MargeBrute');
print ' <input type="radio" name="MARGIN_TYPE" value="1" ';
if ($conf->global->MARGIN_TYPE == '1')
if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')
print 'checked ';
print '/><br/>'.$langs->trans('MargeNette');
print ' <input type="radio" name="MARGIN_TYPE" value="2" ';
if ($conf->global->MARGIN_TYPE == '2')
if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '2')
print 'checked ';
print '/>';
print '</td>';
@ -152,17 +150,17 @@ print '<td>'.$langs->trans("DisplayMarginRates").'</td>';
print '<td colspan="2" align="center">';
if ($conf->use_javascript_ajax)
if (! empty($conf->use_javascript_ajax))
{
print ajax_constantonoff('DISPLAY_MARGIN_RATES');
}
else
{
if($conf->global->DISPLAY_MARGIN_RATES == 0)
if (empty($conf->global->DISPLAY_MARGIN_RATES))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else if($conf->global->DISPLAY_MARGIN_RATES == 1)
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
@ -178,17 +176,17 @@ print '<td>'.$langs->trans("DisplayMarkRates").'</td>';
print '<td colspan="2" align="center">';
if ($conf->use_javascript_ajax)
if (! empty($conf->use_javascript_ajax))
{
print ajax_constantonoff('DISPLAY_MARK_RATES');
}
else
{
if($conf->global->DISPLAY_MARK_RATES == 0)
if (empty($conf->global->DISPLAY_MARK_RATES))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else if($conf->global->DISPLAY_MARK_RATES == 1)
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
@ -200,17 +198,17 @@ print '<tr>';
print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>';
print '<td colspan="2" align="center">';
if ($conf->use_javascript_ajax)
if (! empty($conf->use_javascript_ajax))
{
print ajax_constantonoff('ForceBuyingPriceIfNull');
}
else
{
if($conf->global->ForceBuyingPriceIfNull == 0)
if (empty($conf->global->ForceBuyingPriceIfNull))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else if($conf->global->ForceBuyingPriceIfNull == 1)
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
@ -229,15 +227,15 @@ print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
print '<td align="left">';
print '<select name="MARGIN_METHODE_FOR_DISCOUNT" >';
print '<option value="1" ';
if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1')
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1')
print 'selected ';
print '>'.$langs->trans('UseDiscountAsProduct').'</option>';
print '<option value="2" ';
if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2')
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2')
print 'selected ';
print '>'.$langs->trans('UseDiscountAsService').'</option>';
print '<option value="3" ';
if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3')
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3')
print 'selected ';
print '>'.$langs->trans('UseDiscountOnTotal').'</option>';
print '</select>';
@ -253,8 +251,6 @@ print '</table>';
print '<br>';
llxFooter();
$db->close();
llxFooter('$Date: 2011/07/31 22:23:21 $ - $Revision: 1.6 $');
?>

View File

@ -79,7 +79,7 @@ clearstatcache();
$workflowcodes=array(
'WORKFLOW_PROPAL_AUTOCREATE_ORDER'=>array('enabled'=>($conf->propal->enabled && $conf->commande->enabled), 'picto'=>'order'),
'WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL'=>array('enabled'=>($conf->propal->enabled && $conf->commande->enabled), 'picto'=>'order'),
'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array('enabled'=>($conf->commande->enabled && $conf->facture->enabled), 'picto'=>'bill'),
'WORKFLOW_ORDER_AUTOCREATE_INVOICE'=>array('enabled'=>($conf->commande->enabled && $conf->facture->enabled), 'picto'=>'bill'),
'WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER'=>array('enabled'=>($conf->facture->enabled && $conf->commande->enabled), 'picto'=>'bill'),
);

View File

@ -38,7 +38,7 @@ require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php');
require_once(DOL_DOCUMENT_ROOT."/core/modules/propale/modules_propale.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
if (! empty($conf->projet->enabled)) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
$langs->load('companies');
$langs->load('propal');
@ -46,8 +46,8 @@ $langs->load('compta');
$langs->load('bills');
$langs->load('orders');
$langs->load('products');
if ($conf->marges->enabled)
$langs->load('marges');
if (! empty($conf->margin->enabled))
$langs->load('margins');
$id=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
@ -456,7 +456,7 @@ else if ($action == 'setstatut' && $user->rights->propale->cloturer)
/*
* Add file in email form
*/
if ($_POST['addfile'])
if (GETPOST('addfile'))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
@ -1556,13 +1556,13 @@ if (empty($reshook) && ! empty($extrafields->attribute_label))
}
}
// Amount HT
// Amount HT
print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
print '<td align="right" nowrap><b>'.price($object->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td>';
// Margin Infos
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
print '<td valign="top" width="50%" rowspan="4">';
$object->displayMarginInfos();
print '</td>';
@ -1644,7 +1644,7 @@ if ($object->statut == 0 && $user->rights->propale->creer)
// Add free products/services
$object->formAddFreeProduct(0,$mysoc,$soc,$hookmanager);
// Add predefined products/services
if ($conf->product->enabled || $conf->service->enabled)
{

View File

@ -32,8 +32,7 @@
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
require_once(DOL_DOCUMENT_ROOT ."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT ."/contact/class/contact.class.php");
require_once(DOL_DOCUMENT_ROOT ."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT ."/margin/lib/margins.lib.php");
/**
* \class Propal
@ -401,7 +400,7 @@ class Propal extends CommonObject
// infos marge
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
// Mise en option de la ligne
//if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty) $ligne->special_code=3;
if (empty($qty) && empty($special_code)) $this->line->special_code=3;
@ -536,7 +535,7 @@ class Propal extends CommonObject
// infos marge
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
// TODO deprecated
$this->line->price=$price;
$this->line->remise=$remise;
@ -2464,7 +2463,7 @@ class PropaleLigne
var $fk_remise_except;
var $rang = 0;
var $fk_fournprice;
var $pa_ht;
var $marge_tx;
@ -2597,13 +2596,13 @@ class PropaleLigne
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
}
// Check parameters
if ($this->product_type < 0) return -1;
@ -2735,8 +2734,8 @@ class PropaleLigne
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);

View File

@ -28,8 +28,7 @@
*/
include_once(DOL_DOCUMENT_ROOT."/core/class/commonorder.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT ."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT ."/margin/lib/margins.lib.php");
/**
* \class Commande
@ -2240,7 +2239,7 @@ class Commande extends CommonOrder
// infos marge
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
// TODO deprecated
$this->line->price=$price;
$this->line->remise=$remise;
@ -2998,13 +2997,13 @@ class OrderLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
}
// Check parameters
if ($this->product_type < 0) return -1;
@ -3106,8 +3105,8 @@ class OrderLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);

View File

@ -49,8 +49,8 @@ $langs->load('bills');
$langs->load('propal');
$langs->load('deliveries');
$langs->load('products');
if ($conf->marges->enabled)
$langs->load('marges');
if (! empty($conf->margin->enabled))
$langs->load('margins');
$id = (GETPOST('id','int')?GETPOST('id','int'):GETPOST("orderid"));
$ref = GETPOST('ref');
@ -1989,7 +1989,7 @@ else
print '<td>'.$langs->trans('Currency'.$conf->currency).'</td>';
// Margin Infos
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
print '<td valign="top" width="50%" rowspan="4">';
$object->displayMarginInfos();
print '</td>';

View File

@ -51,8 +51,8 @@ $langs->load('bills');
$langs->load('companies');
$langs->load('products');
$langs->load('main');
if ($conf->marges->enabled)
$langs->load('marges');
if (! empty($conf->margin->enabled))
$langs->load('margins');
$mesg='';
$errors=array();
@ -2766,7 +2766,7 @@ else if ($id > 0 || ! empty($ref))
print '</table>';
// Margin Infos
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
print '<br>';
$object->displayMarginInfos($object->statut > 0);
}

View File

@ -33,8 +33,7 @@
include_once(DOL_DOCUMENT_ROOT."/core/class/commoninvoice.class.php");
require_once(DOL_DOCUMENT_ROOT ."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT ."/societe/class/client.class.php");
require_once(DOL_DOCUMENT_ROOT ."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT ."/margin/lib/margins.lib.php");
/**
@ -1888,7 +1887,7 @@ class Facture extends CommonInvoice
$qty=price2num($qty);
$pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc);
$pa_ht=price2num($pa_ht);
$pa_ht=price2num($pa_ht);
$txtva=price2num($txtva);
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
@ -3105,7 +3104,7 @@ class FactureLigne
var $remise_percent; // % de la remise ligne (example 20%)
var $fk_remise_except; // Link to line into llx_remise_except
var $rang = 0;
var $fk_fournprice;
var $pa_ht;
var $marge_tx;
@ -3265,13 +3264,13 @@ class FactureLigne
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
}
// Check parameters
if ($this->product_type < 0) return -1;
@ -3427,8 +3426,8 @@ class FactureLigne
if ($this->product_type < 0) return -1;
if (empty($this->pa_ht)) $this->pa_ht=0;
// si prix d'achat non renseigné et utilisé pour calcul des marges alors prix achat = prix vente (idem pour remises)
// si prix d'achat non renseign<EFBFBD> et utilis<69> pour calcul des marges alors prix achat = prix vente (idem pour remises)
if ($this->pa_ht == 0) {
if ($this->subprice < 0 || ($conf->global->CalculateMarginsOnLinesWithoutBuyingPrice == 1))
$this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);

View File

@ -2533,7 +2533,7 @@ abstract class CommonObject
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>';
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
if ($conf->global->MARGIN_TYPE == "1")
print '<td align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
else
@ -2870,20 +2870,20 @@ abstract class CommonObject
if ($conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
$line->pa_ht += $product->fourn_unitcharges;
}
// si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente
// si prix d'achat non renseign<EFBFBD> et devrait l'<27>tre, alors prix achat = prix vente
if ((!isset($line->pa_ht) || $line->pa_ht == 0) && ($conf->global->ForceBuyingPriceIfNull == 1)) {
$line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100));
}
// calcul des marges
if(isset($line->fk_remise_except)) { // remise
if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit
if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale consid<EFBFBD>r<EFBFBD>e comme produit
$marginInfos['pa_products'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
$marginInfos['pv_products'] += $line->subprice * (1 - $line->remise_percent / 100);
$marginInfos['pa_total'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
$marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
}
elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale consid<EFBFBD>r<EFBFBD>e comme service
$marginInfos['pa_services'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);
$marginInfos['pv_services'] += $line->subprice * (1 - ($line->remise_percent / 100));
$marginInfos['pa_total'] += ($line->pa_ht != 0)?$line->pa_ht:$line->subprice * (1 - $line->remise_percent / 100);

View File

@ -328,8 +328,8 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
});
</script>';
$out.= '<span id="set_'.$code.'" class="linkobject '.($conf->global->$code?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';
$out.= '<span id="del_'.$code.'" class="linkobject '.($conf->global->$code?'':'hideobject').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>';
$out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';
$out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>';
return $out;
}

View File

@ -115,8 +115,8 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $txlocalta
if ($txlocaltax2>0)
{
$result[15] = price2num(($result[6] * ( 1 + ( $txlocaltax2 / 100))) - $result[6], 'MT');
$result[10] = price2num(($result[0] * ( 1 + ( $txlocaltax2 / 100))) - $result[0], 'MT');
$result[15] = price2num(($result[6] * ( 1 + ( $txlocaltax2 / 100))) - $result[6], 'MT');
$result[10] = price2num(($result[0] * ( 1 + ( $txlocaltax2 / 100))) - $result[0], 'MT');
$result[12] = price2num(($result[3] * ( 1 + ( $txlocaltax2 / 100))) - $pu, 'MT');
//If Country is Spain, localtax2 (IRPF) will be subtracted

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -12,196 +12,173 @@
* 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.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \defgroup mymodule Module MyModule
/** \defgroup margin Module Margin
* \brief Example of a module descriptor.
* Such a file must be copied into htdocs/includes/module directory.
*/
/**
* \file htdocs/includes/modules/modMyModule.class.php
* \ingroup mymodule
* \brief Description and activation file for module MyModule
* \version $Id: modMyModule.class.php,v 1.26 2008/12/15 18:27:00 eldy Exp $
* \file htdocs/includes/modules/modMargin.class.php
* \ingroup margin
* \brief Description and activation file for module Margin
*/
include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
/** \class modMyModule
* \brief Description and activation class for module MyModule
/**
* \class modMargin
* \brief Description and activation class for module Margin
*/
class modMarges extends DolibarrModules
class modMargin extends DolibarrModules
{
/**
* \brief Constructor. Define names, constants, directories, boxes, permissions
* \param DB Database handler
*/
function modMarges($DB)
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $DB;
$this->db = $db;
// Id for module (must be unique).
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
$this->numero = 59000;
// Key text used to identify module (for permissions, menus, etc...)
$this->rights_class = 'Marges';
$this->rights_class = 'margin';
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
$this->family = "financial";
// It is used to group modules in module setup page
$this->family = "financial";
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = mb_ereg_replace('^mod','',get_class($this), "i");
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Gestion des marges";
$this->description = "Margin management";
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = '2.0';
$this->version = 'dolibarr';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Where to store the module in setup page (0=common,1=interface,2=other)
$this->special = 0;
// Name of png file (without png) used for this module.
// Png file must be in theme/yourtheme/img directory under name object_pictovalue.png.
$this->picto='marges@marges';
// Png file must be in theme/yourtheme/img directory under name object_pictovalue.png.
$this->picto='marges';
// Data directories to create when module is enabled.
$this->dirs = array();
//$this->dirs[0] = DOL_DATA_ROOT.'/Marges';
//$this->dirs[1] = DOL_DATA_ROOT.'/mymodule/temp;
// Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'.
$this->style_sheet = '/custom/marges/css/marges.css';
$this->dirs = array('/margin/temp');
// Config pages. Put here list of php page names stored in admmin directory used to setup module.
$this->config_page_url = array("marges.php");
$this->config_page_url = array("margin.php");
// Dependencies
$this->depends = array("modPropale", "modProduct"); // List of modules id that must be enabled if this module is enabled
$this->requiredby = array(); // List of modules id to disable if this one is disabled
$this->phpmin = array(4,1); // Minimum version of PHP required by module
$this->need_dolibarr_version = array(3,1); // Minimum version of Dolibarr required by module
$this->langfiles = array("marges");
$this->phpmin = array(5,1); // Minimum version of PHP required by module
$this->need_dolibarr_version = array(3,2); // Minimum version of Dolibarr required by module
$this->langfiles = array("margins");
// Constants
$this->const = array(); // List of particular constants to add when module is enabled
//$this->const = array( 0=>array('MAIN_MODULE_MARGES_HOOKS', 'chaine', 'propalcard', 'Hooks list for displaying Marges data on entity lists', 0, 'current', 1) );
// New pages on tabs
$this->tabs = array(
'product:+marges:Marges:marges:/marges/tabs/productMargins.php?id=__ID__',
'thirdparty:+marges:Marges:marges:/marges/tabs/thirdpartyMargins.php?socid=__ID__',
);
// Boxes
$this->boxes = array(); // List of boxes
$r=0;
// Add here list of php file(s) stored in includes/boxes that contains class to show a box.
// Example:
//$this->boxes[$r][1] = "myboxa.php";
//$r++;
//$this->boxes[$r][1] = "myboxb.php";
//$r++;
'product:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/productMargins.php?id=__ID__',
'thirdparty:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/thirdpartyMargins.php?socid=__ID__'
);
// Boxes
$this->boxes = array(); // List of boxes
$r=0;
// Permissions
$this->rights = array(); // Permission array used by this module
$r=0;
// Add here list of permission defined by an id, a label, a boolean and two constant strings.
// Example:
// $this->rights[$r][0] = 2000; // Permission id (must not be already used)
// $this->rights[$r][1] = 'Permision label'; // Permission label
// $this->rights[$r][3] = 1; // Permission by default for new user (0/1)
// $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
// $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
// $r++;
// Main menu entries
$this->menu = array(); // List of menus to add
$r = 0;
// left menu entry
$this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
// left menu entry
$this->menu[$r]=array(
'fk_menu'=>0, // Put 0 if this is a top menu
'type'=>'top', // This is a Top menu entry
'titre'=>'Margins',
'mainmenu'=>'margins',
'leftmenu'=>'1', // Use 1 if you also want to add left menu entries using this descriptor. Use 0 if left menu entries are defined in a file pre.inc.php (old school).
'url'=>'/marges/index.php',
'langs'=>'marges', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'url'=>'/margin/index.php',
'langs'=>'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
$r++;
// top menu entry
$this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
// top menu entry
$this->menu[$r]=array(
'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
'type'=>'left', // This is a Left menu entry
'titre'=>'ProductMargins',
'mainmenu'=>'margins',
'url'=>'/marges/productMargins.php',
'langs'=>'marges', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'url'=>'/margin/productMargins.php',
'langs'=>'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users,1=external users, 2=both
$r++;
$r++;
$this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
$this->menu[$r]=array(
'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
'type'=>'left', // This is a Left menu entry
'titre'=>'CustomerMargins',
'mainmenu'=>'margins',
'url'=>'/marges/customerMargins.php',
'langs'=>'marges', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'url'=>'/margin/customerMargins.php',
'langs'=>'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>200,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users,1=external users, 2=both
$r++;
$r++;
$this->menu[$r]=array( 'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
$this->menu[$r]=array(
'fk_menu'=>'r=0', // Use r=value where r is index key used for the parent menu entry (higher parent must be a top menu entry)
'type'=>'left', // This is a Left menu entry
'titre'=>'AgentMargins',
'mainmenu'=>'margins',
'url'=>'/marges/agentMargins.php',
'langs'=>'marges', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'url'=>'/margin/agentMargins.php',
'langs'=>'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>300,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users,1=external users, 2=both
$r++;
}
$r++;
}
/**
* \brief Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories.
* \return int 1 if OK, 0 if KO
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories.
*
* @return int 1 if OK, 0 if KO
*/
function init()
{
$sql = array();
$result=$this->load_tables();
return $this->_init($sql);
}
/**
* \brief Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted.
* \return int 1 if OK, 0 if KO
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted.
*
* @return int 1 if OK, 0 if KO
*/
function remove()
{
@ -210,17 +187,18 @@ class modMarges extends DolibarrModules
return $this->_remove($sql);
}
/**
* \brief Create tables and keys required by module
* Files mymodule.sql and mymodule.key.sql with create table and create keys
* commands must be stored in directory /mymodule/sql/
* This function is called by this->init.
* \return int <=0 if KO, >0 if OK
*/
function load_tables()
* Create tables and keys required by module
* Files mymodule.sql and mymodule.key.sql with create table and create keys
* commands must be stored in directory /mymodule/sql/
* This function is called by this->init.
*
* @return int <=0 if KO, >0 if OK
*/
function load_tables()
{
//return $this->_load_tables('/marges/sql/');
//return $this->_load_tables();
}
}

View File

@ -35,7 +35,7 @@
<td align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
<?php
$colspan = 4;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
<?php
@ -85,7 +85,7 @@ if ($conf->marges->enabled) {
<td align="right" nowrap><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" name="remise_percent">%</td>
<?php
$colspan = 4;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right"><input type="text" size="5" name="np_buying_price" value="<?php echo (isset($_POST["np_buying_price"])?$_POST["np_buying_price"]:''); ?>"></td>
<?php
@ -104,7 +104,7 @@ if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
$colspan = 10;
else
$colspan = 9;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
if($conf->global->DISPLAY_MARGIN_RATES)
$colspan++;
if($conf->global->DISPLAY_MARK_RATES)

View File

@ -75,7 +75,7 @@
</td>
<?php
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right"><input type="text" size="5" name="buying_price" value="<?php echo price($line->pa_ht,0,'',0); ?>"></td>
<?php

View File

@ -85,7 +85,7 @@
<td>&nbsp;</td>
<?php }
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right" nowrap="nowrap"><?php echo price($line->pa_ht); ?></td>
<?php if($conf->global->DISPLAY_MARGIN_RATES) {?>

View File

@ -42,7 +42,7 @@
<td align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
<?php
$colspan = 4;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
<?php
@ -92,7 +92,7 @@ jQuery(document).ready(function() {
<td align="right" nowrap><input type="text" size="1" name="remise_percent" value="<?php echo $buyer->remise_client; ?>">%</td>
<?php
$colspan = 4;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right">
<select id="np_fournprice" name="np_fournprice" style="display: none;"></select>
@ -113,7 +113,7 @@ if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
$colspan = 10;
else
$colspan = 9;
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
if($conf->global->DISPLAY_MARGIN_RATES)
$colspan++;
if($conf->global->DISPLAY_MARK_RATES)
@ -134,7 +134,7 @@ if ($conf->marges->enabled) {
</form>
<?php
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<script type="text/javascript">
$("#idprod").change(function() {

View File

@ -84,7 +84,7 @@
<?php } ?>
</td>
<?php
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right">
<select id="fournprice" name="fournprice"></select>
@ -112,7 +112,7 @@ if ($conf->marges->enabled) {
</tr>
<?php } ?></form>
<?php
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<script type="text/javascript">
$(document).ready(function() {

View File

@ -54,7 +54,7 @@
<td>&nbsp;</td>
<?php }
if ($conf->marges->enabled) {
if (! empty($conf->margin->enabled)) {
?>
<td align="right" nowrap="nowrap"><?php echo price($line->pa_ht); ?></td>
<?php if($conf->global->DISPLAY_MARGIN_RATES) {?>

View File

@ -1,4 +1,4 @@
# Dolibarr language file - fr_FR - marges
# Dolibarr language file - fr_FR - margins
CHARSET=UTF-8
Margin=Marge
@ -12,7 +12,7 @@ DisplayMarginRates=Afficher les taux de marge
DisplayMarkRates=Afficher les taux de marque
InputPrice=Saisir un prix
marges=Gestion des marges
margin=Gestion des marges
margesSetup=Paramétrage de la gestion des marges
MarginDetails=Détails des marges réalisées

View File

@ -1,3 +0,0 @@
div.mainmenu.margins {
background : url('../img/marges.png') no-repeat 20px 0;
}

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,25 +16,24 @@
*/
/**
* \file htdocs/custom/marges/agentMargins.php
* \ingroup marges
* \file htdocs/margin/agentMargins.php
* \ingroup margin
* \brief Page des marges par agent commercial
* \version $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
*/
require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/margin/lib/margins.lib.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("products");
$langs->load("marges");
$langs->load("margins");
// Security check
$agentid = isset($_REQUEST["agentid"])?$_REQUEST["agentid"]:'';
$agentid = GETPOST('agentid','int');
$mesg = '';
@ -54,7 +53,7 @@ if (!empty($_POST['enddatemonth']))
/*
* View
*/
$userstatic = new User($db);
$companystatic = new Societe($db);
$invoicestatic=new Facture($db);
@ -65,13 +64,13 @@ llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Agents"));
$text=$langs->trans("Margins");
print_fiche_titre($text);
// Show tabs
$head=marges_prepare_head($user);
$titre=$langs->trans("Margins");
$picto='marges@marges';
dol_fiche_head($head, 'agentMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<table class="border" width="100%">';
@ -81,7 +80,7 @@ if ($agentid > 0) {
print '<td colspan="4">';
print $form->select_dolusers($selected=$agentid,$htmlname='agentid',$show_empty=1,$exclude='',$disabled=0,$include='',$enableonly='');
print '</td></tr>';
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="s.nom";
}
@ -94,7 +93,7 @@ else {
if (! $sortfield) $sortfield="u.login";
}
// Date début
// Start date
print '<td>'.$langs->trans('StartDate').'</td>';
print '<td width="20%">';
$form->select_date($startdate,'startdate','','',1,"sel",1,1);
@ -132,7 +131,7 @@ print '</form>';
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, s.client, sc.fk_user as agent,";
$sql.= " u.login,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@ -166,12 +165,12 @@ if ($result)
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',$num,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
if ($agentid > 0)
if ($agentid > 0)
print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$_REQUEST["agentid"],'align="center"',$sortfield,$sortorder);
else
print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.login","","&amp;agentid=".$_REQUEST["agentid"],'align="center"',$sortfield,$sortorder);
@ -253,22 +252,20 @@ else
}
$db->free($result);
llxFooter();
$db->close();
llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
?>
<script type="text/javascript">
$(document).ready(function() {
$("#agentid").change(function() {
$("#agentid").change(function() {
$("div.fiche form").submit();
});
$("#totalMargin").html("<?php echo price($totalMargin); ?>");
$("#marginRate").html("<?php echo (($marginRate === '')?'n/a':price($marginRate)."%"); ?>");
$("#markRate").html("<?php echo (($markRate === '')?'n/a':price($markRate)."%"); ?>");
});
</script>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,26 +16,25 @@
*/
/**
* \file htdocs/custom/marges/customerMargins.php
* \ingroup marges
* \file htdocs/margin/customerMargins.php
* \ingroup margin
* \brief Page des marges par client
* \version $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
*/
require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/margin/lib/margins.lib.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("products");
$langs->load("marges");
$langs->load("margins");
// Security check
$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$socid = GETPOST('socid','int');
if (! empty($user->societe_id)) $socid=$user->societe_id;
$result = restrictedArea($user, 'societe','','');
@ -57,7 +56,7 @@ if (!empty($_POST['enddatemonth']))
/*
* View
*/
$companystatic = new Societe($db);
$invoicestatic=new Facture($db);
@ -67,13 +66,13 @@ llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Clients"));
$text=$langs->trans("Margins");
print_fiche_titre($text);
// Show tabs
$head=marges_prepare_head($user);
$titre=$langs->trans("Margins");
$picto='marges@marges';
dol_fiche_head($head, 'customerMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<table class="border" width="100%">';
@ -89,7 +88,7 @@ if ($socid > 0) {
print '<td colspan="4">';
$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid', $filter='client=1',$showempty=1, $showtype=0, $forcecombo=1);
print '</td></tr>';
$client = true;
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="f.datef";
@ -104,7 +103,7 @@ if (!$client) {
if (! $sortfield) $sortfield="s.nom";
}
// Date début
// Start date
print '<td>'.$langs->trans('StartDate').'</td>';
print '<td width="20%">';
$form->select_date($startdate,'startdate','','',1,"sel",1,1);
@ -141,7 +140,7 @@ print '</form>';
$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, s.client,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@ -163,7 +162,7 @@ else
$sql.= " GROUP BY s.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
{
@ -171,7 +170,7 @@ if ($result)
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',$num,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
@ -264,24 +263,22 @@ else
}
$db->free($result);
llxFooter();
$db->close();
llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
?>
<script type="text/javascript">
$(document).ready(function() {
$("div.fiche form input.button['type=submit']").hide();
$("#socid").change(function() {
$("#socid").change(function() {
$("div.fiche form").submit();
});
$("#totalMargin").html("<?php echo price($totalMargin); ?>");
$("#marginRate").html("<?php echo (($marginRate === '')?'n/a':price($marginRate)."%"); ?>");
$("#markRate").html("<?php echo (($markRate === '')?'n/a':price($markRate)."%"); ?>");
});
</script>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,9 +16,9 @@
*/
/**
* \file htdocs/custom/marges/index.php
* \ingroup product marges
* \brief Page d'index du module marges
* \file htdocs/margin/index.php
* \ingroup product margins
* \brief Page d'index du module margin
*/
require("./productMargins.php");

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -12,16 +12,13 @@
* 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.
* or see http://www.gnu.org/
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /marges/lib/marges.lib.php
* \ingroup marges
* \brief Library for common marges functions
* \version $Id:$
* \file /htdocs/margin/lib/margins.lib.php
* \ingroup margin
* \brief Library for common margin functions
*/
/**
@ -31,20 +28,20 @@
function marges_admin_prepare_head()
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = dol_buildpath("/marges/admin/marges.php",1);
$head[$h][0] = DOL_URL_ROOT."/admin/margin.php";
$head[$h][1] = $langs->trans("Parameters");
$head[$h][2] = 'parameters';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'margesadmin');
complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin');
return $head;
}
@ -57,17 +54,17 @@ function marges_prepare_head($user)
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/marges/productMargins.php";
$head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php";
$head[$h][1] = $langs->trans("ProductMargins");
$head[$h][2] = 'productMargins';
$h++;
$head[$h][0] = DOL_URL_ROOT."/marges/customerMargins.php";
$head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php";
$head[$h][1] = $langs->trans("CustomerMargins");
$head[$h][2] = 'customerMargins';
$h++;
$head[$h][0] = DOL_URL_ROOT."/marges/agentMargins.php";
$head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php";
$head[$h][1] = $langs->trans("AgentMargins");
$head[$h][2] = 'agentMargins';
$h++;
@ -77,32 +74,35 @@ function marges_prepare_head($user)
function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht) {
global $db, $conf;
if($fk_pa > 0) {
require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php";
$product = new ProductFournisseur($db);
if ($product->fetch_product_fournisseur_price($fk_pa)) {
$paht_ret = $product->fourn_unitprice;
if ($conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
$paht_ret += $product->fourn_unitcharges;
}
else
$paht_ret = $paht;
}
else
$paht_ret = $paht;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php');
// calcul pu_ht remisés
$tabprice=calcul_price_total(1, $pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT', $objp->info_bits);
$marge_tx_ret='';
$marque_tx_ret='';
if($fk_pa > 0) {
require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php";
$product = new ProductFournisseur($db);
if ($product->fetch_product_fournisseur_price($fk_pa)) {
$paht_ret = $product->fourn_unitprice;
if ($conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
$paht_ret += $product->fourn_unitcharges;
}
else
$paht_ret = $paht;
}
else
$paht_ret = $paht;
require_once(DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php');
// calcul pu_ht remisés
$tabprice=calcul_price_total(1, $pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT');
$pu_ht_remise = $tabprice[0];
// calcul taux marge
if ($paht_ret != 0)
$marge_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $paht_ret, 3);
if ($paht_ret != 0)
$marge_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $paht_ret, 3);
// calcul taux marque
if ($pu_ht_remise != 0)
$marque_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $pu_ht_remise, 3);
$marque_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $pu_ht_remise, 3);
return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
}
?>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,31 +16,32 @@
*/
/**
* \file htdocs/custom/marges/productMargins.php
* \ingroup marges
* \file htdocs/margin/productMargins.php
* \ingroup margin
* \brief Page des marges par produit
* \version $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
*/
require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/marges/lib/marges.lib.php");
require_once(DOL_DOCUMENT_ROOT."/margin/lib/margins.lib.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("products");
$langs->load("marges");
$langs->load("margins");
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
// Security check
if (isset($_REQUEST["id"]) || isset($_REQUEST["ref"]))
{
$id = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["ref"])?$_REQUEST["ref"]:'');
}
$fieldid = isset($_REQUEST["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
if (! empty($user->societe_id)) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
$mesg = '';
@ -60,7 +61,7 @@ if (!empty($_POST['enddatemonth']))
/*
* View
*/
$product_static = new Product($db);
$invoicestatic=new Facture($db);
@ -77,7 +78,7 @@ $head=marges_prepare_head($user);
$titre=$langs->trans("Margins");
$picto='marges@marges';
dol_fiche_head($head, 'productMargins', $titre, 0, $picto);
print '<form method="post" name="sel">';
print '<table class="border" width="100%">';
@ -93,7 +94,7 @@ if ($id > 0) {
print '<tr><td width="20%">'.$langs->trans('AllProducts').'</td>';
print '<td colspan="4"><input type="checkbox" id="all" /></td></tr>';
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="f.datef";
}
@ -106,7 +107,7 @@ else {
if (! $sortfield) $sortfield="p.ref";
}
// Date début
// Start date
print '<td>'.$langs->trans('StartDate').'</td>';
print '<td width="20%">';
$form->select_date($startdate,'startdate','','',1,"sel",1,1);
@ -143,7 +144,7 @@ print '</form>';
$sql = "SELECT distinct d.fk_product, p.label, p.rowid, p.fk_product_type, p.ref,";
$sql.= " f.facnumber, f.total as total_ht,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.subprice * d.qty * (1 - d.remise_percent / 100)) as selling_price,";
$sql.= " sum(d.buy_price_ht * d.qty) as buying_price, sum(((d.subprice * (1 - d.remise_percent / 100)) - d.buy_price_ht) * d.qty) as marge," ;
$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
@ -167,7 +168,7 @@ else
$sql.= " GROUP BY d.fk_product";
$sql.= " ORDER BY $sortfield $sortorder ";
$sql.= $db->plimit($conf->liste_limit +1, $offset);
$result = $db->query($sql);
if ($result)
{
@ -175,7 +176,7 @@ if ($result)
print '<br>';
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
@ -271,26 +272,24 @@ else
}
$db->free($result);
llxFooter();
$db->close();
llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
?>
<script type="text/javascript">
$(document).ready(function() {
$("#all").change(function() {
$("#id").val('').change();
});
$("#id").change(function() {
$("div.fiche form").submit();
$("#id").change(function() {
$("div.fiche form").submit();
});
$("#totalMargin").html("<?php echo price($totalMargin); ?>");
$("#marginRate").html("<?php echo (($marginRate === '')?'n/a':price($marginRate)."%"); ?>");
$("#markRate").html("<?php echo (($markRate === '')?'n/a':price($markRate)."%"); ?>");
});
</script>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,10 +16,9 @@
*/
/**
* \file htdocs/custom/marges/tabs/productMargins.php
* \ingroup product marges
* \file htdocs/margin/tabs/productMargins.php
* \ingroup product margins
* \brief Page des marges des factures clients pour un produit
* \version $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
*/
require("../../main.inc.php");
@ -30,16 +29,20 @@ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("products");
$langs->load("marges");
$langs->load("margins");
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
// Security check
if (isset($_GET["id"]) || isset($_GET["ref"]))
{
$id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:'');
}
$fieldid = isset($_GET["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
if (! empty($user->societe_id)) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
$object = new Product($db);
$mesg = '';
@ -60,29 +63,23 @@ if (! $sortfield) $sortfield="f.datef";
$invoicestatic=new Facture($db);
$html = new Form($db);
$form = new Form($db);
if ($_GET["id"] || $_GET["ref"])
if ($id > 0 || ! empty($ref))
{
$product = new Product($db);
if ($_GET["ref"])
{
$result = $product->fetch('',$_GET["ref"]);
$_GET["id"]=$product->id;
}
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
$result = $object->fetch($id, $ref);
llxHeader("","",$langs->trans("CardProduct".$product->type));
llxHeader("","",$langs->trans("CardProduct".$object->type));
/*
* En mode visu
*/
if ($result > 0)
{
$head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type);
$picto=($product->type==1?'service':'product');
$head=product_prepare_head($object, $user);
$titre=$langs->trans("CardProduct".$object->type);
$picto=($object->type==1?'service':'product');
dol_fiche_head($head, 'marges', $titre, 0, $picto);
print '<table class="border" width="100%">';
@ -90,43 +87,43 @@ if ($_GET["id"] || $_GET["ref"])
// Reference
print '<tr>';
print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $html->showrefnav($product,'ref','',1,'ref');
print $form->showrefnav($object,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td>';
print '</tr>';
// Status (to sell)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')'.'</td><td colspan="3">';
print $product->getLibStatut(2,0);
print $object->getLibStatut(2,0);
print '</td></tr>';
// Status (to buy)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')'.'</td><td colspan="3">';
print $product->getLibStatut(2,1);
print $object->getLibStatut(2,1);
print '</td></tr>';
// Total Margin
print '<tr style="font-weight: bold"><td>'.$langs->trans("TotalMargin").'</td><td colspan="3">';
print '<span id="totalMargin"></span>'; // set by jquery (see below)
print '</td></tr>';
// Margin Rate
if ($conf->global->DISPLAY_MARGIN_RATES) {
print '<tr style="font-weight: bold"><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
print '<span id="marginRate"></span>'; // set by jquery (see below)
print '</td></tr>';
}
// Mark Rate
if ($conf->global->DISPLAY_MARK_RATES) {
print '<tr style="font-weight: bold"><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
print '<span id="markRate"></span>'; // set by jquery (see below)
print '</td></tr>';
}
print "</table>";
print '</div>';
@ -144,7 +141,7 @@ if ($_GET["id"] || $_GET["ref"])
$sql.= " AND f.fk_statut > 0";
$sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND d.fk_facture = f.rowid";
$sql.= " AND d.fk_product =".$product->id;
$sql.= " AND d.fk_product =".$object->id;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = $socid";
$sql.= " ORDER BY $sortfield $sortorder ";
@ -155,7 +152,7 @@ if ($_GET["id"] || $_GET["ref"])
{
$num = $db->num_rows($result);
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&amp;id=$object->id",$sortfield,$sortorder,'',$num,0,'');
$i = 0;
print "<table class=\"noborder\" width=\"100%\">";
@ -248,9 +245,9 @@ else
dol_print_error();
}
llxFooter();
$db->close();
llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
?>
<script type="text/javascript">
$(document).ready(function() {

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
/* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.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
@ -16,10 +16,9 @@
*/
/**
* \file htdocs/custom/marges/tabs/thirdpartyMargins.php
* \ingroup product marges
* \file htdocs/margin/tabs/thirdpartyMargins.php
* \ingroup product margins
* \brief Page des marges des factures clients pour un tiers
* \version $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
*/
require("../../main.inc.php");
@ -30,11 +29,11 @@ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
$langs->load("companies");
$langs->load("bills");
$langs->load("products");
$langs->load("marges");
$langs->load("margins");
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$socid = GETPOST('socid','int');
if (! empty($user->societe_id)) $socid=$user->societe_id;
$result = restrictedArea($user, 'societe','','');
@ -62,7 +61,7 @@ $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Margins"),$help_url);
if ($socid > 0)
{
{
$societe = new Societe($db, $socid);
$societe->fetch($socid);
@ -108,21 +107,21 @@ if ($socid > 0)
print '<tr style="font-weight: bold"><td>'.$langs->trans("TotalMargin").'</td><td colspan="3">';
print '<span id="totalMargin"></span>'; // set by jquery (see below)
print '</td></tr>';
// Margin Rate
if ($conf->global->DISPLAY_MARGIN_RATES) {
print '<tr style="font-weight: bold"><td>'.$langs->trans("MarginRate").'</td><td colspan="3">';
print '<span id="marginRate"></span>'; // set by jquery (see below)
print '</td></tr>';
}
// Mark Rate
if ($conf->global->DISPLAY_MARK_RATES) {
print '<tr style="font-weight: bold"><td>'.$langs->trans("MarkRate").'</td><td colspan="3">';
print '<span id="markRate"></span>'; // set by jquery (see below)
print '</td></tr>';
}
print "</table>";
print '</div>';
@ -234,9 +233,9 @@ else
dol_print_error();
}
llxFooter();
$db->close();
llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
?>
<script type="text/javascript">
$(document).ready(function() {

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 579 B

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B