From fafd79a0f89b06f5e465b901c6e6d548ec1f786e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 20 Jul 2012 09:57:50 +0200 Subject: [PATCH] Fix: uniformize code (in progress) --- htdocs/admin/{marges.php => margin.php} | 64 +++--- htdocs/admin/workflow.php | 2 +- htdocs/comm/propal.php | 14 +- htdocs/comm/propal/class/propal.class.php | 19 +- htdocs/commande/class/commande.class.php | 15 +- htdocs/commande/fiche.php | 6 +- htdocs/compta/facture.php | 6 +- htdocs/compta/facture/class/facture.class.php | 17 +- htdocs/core/class/commonobject.class.php | 8 +- htdocs/core/lib/ajax.lib.php | 4 +- htdocs/core/lib/price.lib.php | 4 +- ...odMarges.class.php => modMargin.class.php} | 200 ++++++++---------- .../core/tpl/freeproductline_create.tpl.php | 6 +- htdocs/core/tpl/freeproductline_edit.tpl.php | 2 +- htdocs/core/tpl/freeproductline_view.tpl.php | 2 +- .../tpl/predefinedproductline_create.tpl.php | 8 +- .../tpl/predefinedproductline_edit.tpl.php | 4 +- .../tpl/predefinedproductline_view.tpl.php | 2 +- .../langs/fr_FR/{marges.lang => margins.lang} | 4 +- htdocs/marges/css/marges.css | 3 - htdocs/{marges => margin}/agentMargins.php | 45 ++-- htdocs/{marges => margin}/customerMargins.php | 49 ++--- htdocs/{marges => margin}/index.php | 8 +- .../lib/margins.lib.php} | 72 +++---- htdocs/{marges => margin}/productMargins.php | 55 +++-- .../tabs/productMargins.php | 71 +++---- .../tabs/thirdpartyMargins.php | 27 ++- .../{marges => theme/amarok}/img/marges.png | Bin .../amarok}/img/object_marges.png | Bin htdocs/theme/auguria/img/marges.png | Bin 0 -> 1851 bytes htdocs/theme/auguria/img/object_marges.png | Bin 0 -> 579 bytes htdocs/theme/bureau2crea/img/marges.png | Bin 0 -> 1851 bytes .../theme/bureau2crea/img/object_marges.png | Bin 0 -> 579 bytes htdocs/theme/cameleo/img/marges.png | Bin 0 -> 1851 bytes htdocs/theme/cameleo/img/object_marges.png | Bin 0 -> 579 bytes htdocs/theme/eldy/img/marges.png | Bin 0 -> 1851 bytes htdocs/theme/eldy/img/object_marges.png | Bin 0 -> 579 bytes 37 files changed, 337 insertions(+), 380 deletions(-) rename htdocs/admin/{marges.php => margin.php} (81%) rename htdocs/core/modules/{modMarges.class.php => modMargin.class.php} (50%) rename htdocs/langs/fr_FR/{marges.lang => margins.lang} (95%) delete mode 100644 htdocs/marges/css/marges.css rename htdocs/{marges => margin}/agentMargins.php (92%) rename htdocs/{marges => margin}/customerMargins.php (92%) rename htdocs/{marges => margin}/index.php (77%) rename htdocs/{marges/lib/marges.lib.php => margin/lib/margins.lib.php} (58%) rename htdocs/{marges => margin}/productMargins.php (90%) rename htdocs/{marges => margin}/tabs/productMargins.php (86%) rename htdocs/{marges => margin}/tabs/thirdpartyMargins.php (95%) rename htdocs/{marges => theme/amarok}/img/marges.png (100%) rename htdocs/{marges => theme/amarok}/img/object_marges.png (100%) create mode 100644 htdocs/theme/auguria/img/marges.png create mode 100644 htdocs/theme/auguria/img/object_marges.png create mode 100644 htdocs/theme/bureau2crea/img/marges.png create mode 100644 htdocs/theme/bureau2crea/img/object_marges.png create mode 100644 htdocs/theme/cameleo/img/marges.png create mode 100644 htdocs/theme/cameleo/img/object_marges.png create mode 100644 htdocs/theme/eldy/img/marges.png create mode 100644 htdocs/theme/eldy/img/object_marges.png diff --git a/htdocs/admin/marges.php b/htdocs/admin/margin.php similarity index 81% rename from htdocs/admin/marges.php rename to htdocs/admin/margin.php index 2bc9da0d48e..b0c9e5fd510 100644 --- a/htdocs/admin/marges.php +++ b/htdocs/admin/margin.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 . */ /** - * \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=''.$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 ''; $var=true; $form = new Form($db); - + // GLOBAL DISCOUNT MANAGEMENT $var=!$var; print "
"; @@ -130,11 +128,11 @@ print ''; print ''.$langs->trans("MARGIN_TYPE").''; print ''.$langs->trans('MargeBrute'); print ' global->MARGIN_TYPE == '1') +if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') print 'checked '; print '/>
'.$langs->trans('MargeNette'); print ' global->MARGIN_TYPE == '2') +if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '2') print 'checked '; print '/>'; print ''; @@ -152,17 +150,17 @@ print ''.$langs->trans("DisplayMarginRates").''; print ''; -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 '
'.img_picto($langs->trans("Disabled"),'off').''; } - else if($conf->global->DISPLAY_MARGIN_RATES == 1) + else { print ''.img_picto($langs->trans("Enabled"),'on').''; } @@ -178,17 +176,17 @@ print ''.$langs->trans("DisplayMarkRates").''; print ''; -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 ''.img_picto($langs->trans("Disabled"),'off').''; } - else if($conf->global->DISPLAY_MARK_RATES == 1) + else { print ''.img_picto($langs->trans("Enabled"),'on').''; } @@ -200,17 +198,17 @@ print ''; print ''.$langs->trans("ForceBuyingPriceIfNull").''; print ''; -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 ''.img_picto($langs->trans("Disabled"),'off').''; } - else if($conf->global->ForceBuyingPriceIfNull == 1) + else { print ''.img_picto($langs->trans("Enabled"),'on').''; } @@ -229,15 +227,15 @@ print ''.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").''; print ''; print ''; @@ -253,8 +251,6 @@ print ''; print '
'; - +llxFooter(); $db->close(); - -llxFooter('$Date: 2011/07/31 22:23:21 $ - $Revision: 1.6 $'); ?> diff --git a/htdocs/admin/workflow.php b/htdocs/admin/workflow.php index 504b78bf147..9af07ec5e5c 100755 --- a/htdocs/admin/workflow.php +++ b/htdocs/admin/workflow.php @@ -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'), ); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index c127e4cada5..01943653763 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -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 ''.$langs->trans('AmountHT').''; print ''.price($object->total_ht).''; print ''.$langs->trans("Currency".$conf->currency).''; // Margin Infos -if ($conf->marges->enabled) { +if (! empty($conf->margin->enabled)) { print ''; $object->displayMarginInfos(); print ''; @@ -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) { diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 29cc04a477a..5adb811bdae 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -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� et utilis� 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� et utilis� 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); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f43e78a1d76..2341fde0c98 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -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� et utilis� 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� et utilis� 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); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 4c5b0d57fa8..5c00f9c6cdd 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -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 ''.$langs->trans('Currency'.$conf->currency).''; // Margin Infos - if ($conf->marges->enabled) { + if (! empty($conf->margin->enabled)) { print ''; $object->displayMarginInfos(); print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5d306dd6977..806af455da9 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -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 ''; // Margin Infos - if ($conf->marges->enabled) { + if (! empty($conf->margin->enabled)) { print '
'; $object->displayMarginInfos($object->statut > 0); } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7f2ebbafd8a..83585efc51d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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� et utilis� 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� et utilis� 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); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0685fde414b..752d904c330 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2533,7 +2533,7 @@ abstract class CommonObject print ''.$langs->trans('PriceUHT').''; print ''.$langs->trans('Qty').''; print ''.$langs->trans('ReductionShort').''; - if ($conf->marges->enabled) { + if (! empty($conf->margin->enabled)) { if ($conf->global->MARGIN_TYPE == "1") print ''.$langs->trans('BuyingPrice').''; 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� et devrait l'�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�r�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�r�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); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 21f6c427471..6c5b88ae9c4 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -328,8 +328,8 @@ function ajax_constantonoff($code,$input=array(),$entity=false) }); '; - $out.= ''.img_picto($langs->trans("Disabled"),'switch_off').''; - $out.= ''.img_picto($langs->trans("Enabled"),'switch_on').''; + $out.= ''.img_picto($langs->trans("Disabled"),'switch_off').''; + $out.= ''.img_picto($langs->trans("Enabled"),'switch_on').''; return $out; } diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index 89cb4512d13..cc1db27bf86 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -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 diff --git a/htdocs/core/modules/modMarges.class.php b/htdocs/core/modules/modMargin.class.php similarity index 50% rename from htdocs/core/modules/modMarges.class.php rename to htdocs/core/modules/modMargin.class.php index 413578597ce..94118523ed7 100644 --- a/htdocs/core/modules/modMarges.class.php +++ b/htdocs/core/modules/modMargin.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 . */ -/** \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(); } } diff --git a/htdocs/core/tpl/freeproductline_create.tpl.php b/htdocs/core/tpl/freeproductline_create.tpl.php index aaca8feab4e..d1ca8d63033 100644 --- a/htdocs/core/tpl/freeproductline_create.tpl.php +++ b/htdocs/core/tpl/freeproductline_create.tpl.php @@ -35,7 +35,7 @@ trans('ReductionShort'); ?> marges->enabled) { +if (! empty($conf->margin->enabled)) { ?> trans('BuyingPrice'); ?> marges->enabled) { % marges->enabled) { +if (! empty($conf->margin->enabled)) { ?> "> 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) diff --git a/htdocs/core/tpl/freeproductline_edit.tpl.php b/htdocs/core/tpl/freeproductline_edit.tpl.php index 6b067951401..e3df369e392 100644 --- a/htdocs/core/tpl/freeproductline_edit.tpl.php +++ b/htdocs/core/tpl/freeproductline_edit.tpl.php @@ -75,7 +75,7 @@ marges->enabled) { +if (! empty($conf->margin->enabled)) { ?>   marges->enabled) { + if (! empty($conf->margin->enabled)) { ?> pa_ht); ?> global->DISPLAY_MARGIN_RATES) {?> diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php index c4a0bebd614..5f55b18173d 100644 --- a/htdocs/core/tpl/predefinedproductline_create.tpl.php +++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php @@ -42,7 +42,7 @@ trans('ReductionShort'); ?> marges->enabled) { +if (! empty($conf->margin->enabled)) { ?> trans('BuyingPrice'); ?> % marges->enabled) { +if (! empty($conf->margin->enabled)) { ?> @@ -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) { marges->enabled) { +if (! empty($conf->margin->enabled)) { ?> \ No newline at end of file diff --git a/htdocs/marges/customerMargins.php b/htdocs/margin/customerMargins.php similarity index 92% rename from htdocs/marges/customerMargins.php rename to htdocs/margin/customerMargins.php index 13594f0aff1..14c70a63ecb 100644 --- a/htdocs/marges/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 '
'; print ''; @@ -89,7 +88,7 @@ if ($socid > 0) { print ''; - + $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 ''; print '
'; $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid', $filter='client=1',$showempty=1, $showtype=0, $forcecombo=1); print '
'.$langs->trans('StartDate').''; $form->select_date($startdate,'startdate','','',1,"sel",1,1); @@ -141,7 +140,7 @@ print ''; $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 '
'; print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&socid=$societe->id",$sortfield,$sortorder,'',$num,0,''); - + $i = 0; print ""; @@ -264,24 +263,22 @@ else } $db->free($result); + +llxFooter(); $db->close(); - -llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $'); ?> \ No newline at end of file diff --git a/htdocs/marges/index.php b/htdocs/margin/index.php similarity index 77% rename from htdocs/marges/index.php rename to htdocs/margin/index.php index ff28c32f8a0..e16f01ac6c0 100644 --- a/htdocs/marges/index.php +++ b/htdocs/margin/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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"); diff --git a/htdocs/marges/lib/marges.lib.php b/htdocs/margin/lib/margins.lib.php similarity index 58% rename from htdocs/marges/lib/marges.lib.php rename to htdocs/margin/lib/margins.lib.php index f2837a62915..77368e80455 100644 --- a/htdocs/marges/lib/marges.lib.php +++ b/htdocs/margin/lib/margins.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 . */ /** - * \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); } ?> \ No newline at end of file diff --git a/htdocs/marges/productMargins.php b/htdocs/margin/productMargins.php similarity index 90% rename from htdocs/marges/productMargins.php rename to htdocs/margin/productMargins.php index d9e5a6af2df..89b9509876e 100644 --- a/htdocs/marges/productMargins.php +++ b/htdocs/margin/productMargins.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 '
'; print '
'; @@ -93,7 +94,7 @@ if ($id > 0) { print ''; print ''; - + 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 ''; print '
'.$langs->trans('AllProducts').'
'.$langs->trans('StartDate').''; $form->select_date($startdate,'startdate','','',1,"sel",1,1); @@ -143,7 +144,7 @@ print ''; $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 '
'; print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); - + $i = 0; print ""; @@ -271,26 +272,24 @@ else } $db->free($result); + +llxFooter(); $db->close(); - -llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $'); ?> \ No newline at end of file diff --git a/htdocs/marges/tabs/productMargins.php b/htdocs/margin/tabs/productMargins.php similarity index 86% rename from htdocs/marges/tabs/productMargins.php rename to htdocs/margin/tabs/productMargins.php index 3b109b9b77c..e13e6b036d8 100644 --- a/htdocs/marges/tabs/productMargins.php +++ b/htdocs/margin/tabs/productMargins.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012 Christophe Battarel * * 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 '
'; @@ -90,43 +87,43 @@ if ($_GET["id"] || $_GET["ref"]) // Reference print ''; print ''; print ''; // Libelle - print ''; + print ''; print ''; // Status (to sell) print ''; // Status (to buy) print ''; // Total Margin print ''; - + // Margin Rate if ($conf->global->DISPLAY_MARGIN_RATES) { print ''; } - + // Mark Rate if ($conf->global->DISPLAY_MARK_RATES) { print ''; } - + print "
'.$langs->trans("Ref").''; - print $html->showrefnav($product,'ref','',1,'ref'); + print $form->showrefnav($object,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("Label").''.$object->libelle.'
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'.''; - print $product->getLibStatut(2,0); + print $object->getLibStatut(2,0); print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'.''; - print $product->getLibStatut(2,1); + print $object->getLibStatut(2,1); print '
'.$langs->trans("TotalMargin").''; print ''; // set by jquery (see below) print '
'.$langs->trans("MarginRate").''; print ''; // set by jquery (see below) print '
'.$langs->trans("MarkRate").''; print ''; // set by jquery (see below) print '
"; print ''; @@ -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"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); + print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&id=$object->id",$sortfield,$sortorder,'',$num,0,''); $i = 0; print ""; @@ -248,9 +245,9 @@ else dol_print_error(); } + +llxFooter(); $db->close(); - -llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $'); ?>