From 84a09808fc750e2ceac5b9ccb199d1e2e9cde1db Mon Sep 17 00:00:00 2001 From: simnandez Date: Wed, 9 May 2012 10:29:12 +0200 Subject: [PATCH 1/2] Fix:[ bug #399 ] Bad calculation of local taxes in update line products --- htdocs/core/lib/functions.lib.php | 5 ++--- htdocs/fourn/commande/fiche.php | 4 ++-- htdocs/fourn/facture/fiche.php | 30 +++++++++++++----------------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index aa9b5cff882..a745e8e10a3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2682,9 +2682,8 @@ function get_localtax($tva, $local, $societe_acheteuse="") { global $db, $conf, $mysoc; - // TODO Can we uncomment this ? - //if ($local == 1 && empty($conf->global->FACTURE_LOCAL_TAX1_OPTION)) return; - //if ($local == 2 && empty($conf->global->FACTURE_LOCAL_TAX2_OPTION)) return; + if ($local == 1 && ! $mysoc->localtax1_assuj) return 0; + if ($local == 2 && ! $mysoc->localtax2_assuj) return 0; $code_pays=$mysoc->pays_code; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index aa1e78bc447..5902fabe52b 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -176,8 +176,8 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer) $type = $productsupplier->type; // Local Taxes - $localtax1_tx= get_localtax($tva_tx, 1, $mysoc); - $localtax2_tx= get_localtax($tva_tx, 2, $mysoc); + $localtax1_tx= get_localtax($tva_tx, 1, $object->thirdparty); + $localtax2_tx= get_localtax($tva_tx, 2, $object->thirdparty); $result=$object->addline( $desc, diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 42db5712af9..ad987627352 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -2,9 +2,9 @@ /* Copyright (C) 2002-2005 Rodolphe Quiedeville * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles - * Copyright (C) 2005 Marc Barilley - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2010-2011 Juanjo Menent + * Copyright (C) 2005 Marc Barilley + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2010-2012 Juanjo Menent * * 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 @@ -413,7 +413,7 @@ elseif ($action == 'update_line') $pu=$_POST['puttc']; $price_base_type='TTC'; } - + if ($_POST['idprod']) { $prod = new Product($db); @@ -422,21 +422,17 @@ elseif ($action == 'update_line') if (trim($_POST['desc']) != trim($label)) $label=$_POST['desc']; $type = $prod->type; - $localtax1tx = $prod->localtax1_tx; - $localtax2tx = $prod->localtax2_tx; } else { - if ($object->socid) - { - $societe=new Societe($db); - $societe->fetch($object->socid); - } + $label = $_POST['desc']; $type = $_POST["type"]?$_POST["type"]:0; - $localtax1tx= get_localtax($_POST['tauxtva'], 1, $mysoc); - $localtax2tx= get_localtax($_POST['tauxtva'], 2, $mysoc); + } + + $localtax1tx= get_localtax($_POST['tauxtva'], 1, $object->thirdparty); + $localtax2tx= get_localtax($_POST['tauxtva'], 2, $object->thirdparty); $result=$object->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $localtax1tx, $localtax2tx, $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type); if ($result >= 0) @@ -471,8 +467,8 @@ elseif ($action == 'addline') $tvatx=get_default_tva($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']); - $localtax1tx= get_localtax($tvatx, 1, $mysoc); - $localtax2tx= get_localtax($tvatx, 2, $mysoc); + $localtax1tx= get_localtax($tvatx, 1, $object->thirdparty); + $localtax2tx= get_localtax($tvatx, 2, $object->thirdparty); $type = $product->type; @@ -489,8 +485,8 @@ elseif ($action == 'addline') else { $tauxtva = price2num($_POST['tauxtva']); - $localtax1tx= get_localtax($tauxtva, 1, $mysoc); - $localtax2tx= get_localtax($tauxtva, 2, $mysoc); + $localtax1tx= get_localtax($tauxtva, 1, $object->thirdparty); + $localtax2tx= get_localtax($tauxtva, 2, $object->thirdparty); if (! $_POST['dp_desc']) { From b9b2dbe9b1aae5173aa52fb0ee83ecc44b6a1a79 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 9 May 2012 12:42:37 +0200 Subject: [PATCH 2/2] Fix: more compatibility with multicompany --- ...face_20_modPaypal_PaypalWorkflow.class.php | 73 +++++++++++-------- htdocs/public/members/new.php | 8 +- htdocs/public/paypal/newpayment.php | 13 ++++ htdocs/public/paypal/paymentko.php | 12 ++- htdocs/public/paypal/paymentok.php | 12 ++- 5 files changed, 83 insertions(+), 35 deletions(-) diff --git a/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php index aacd600f478..dc577289df6 100755 --- a/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php +++ b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2012 Regis Houssin * * 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 @@ -102,35 +102,48 @@ class InterfacePaypalWorkflow if ($action == 'PAYPAL_PAYMENT_OK') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref); - - require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); - - $soc = new Societe($this->db); - - // Parse element/subelement (ex: project_task) - $element = $path = $filename = $object->source; - if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs)) - { - $element = $path = $regs[1]; - $filename = $regs[2]; - } - // For compatibility - if ($element == 'order') { $path = $filename = 'commande'; } - if ($element == 'invoice') { $path = 'compta/facture'; $filename = 'facture'; } - - dol_include_once('/'.$path.'/class/'.$filename.'.class.php'); - - $classname = ucfirst($filename); - $obj = new $classname($this->db); - - $ret = $obj->fetch('',$object->ref); - if ($ret < 0) return -1; - - // Add payer id - $soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid); - - // Add transaction id - $obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]); + + if ($object->source == 'membersubscription') + { + //require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherents.class.php"); + + // TODO add subscription treatment + } + else + { + require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); + + $soc = new Societe($this->db); + + // Parse element/subelement (ex: project_task) + $element = $path = $filename = $object->source; + if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs)) + { + $element = $path = $regs[1]; + $filename = $regs[2]; + } + // For compatibility + if ($element == 'order') { + $path = $filename = 'commande'; + } + if ($element == 'invoice') { + $path = 'compta/facture'; $filename = 'facture'; + } + + dol_include_once('/'.$path.'/class/'.$filename.'.class.php'); + + $classname = ucfirst($filename); + $obj = new $classname($this->db); + + $ret = $obj->fetch('',$object->ref); + if ($ret < 0) return -1; + + // Add payer id + $soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid); + + // Add transaction id + $obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]); + } } diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index b63a99d19a8..9a82627c3bb 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -274,12 +274,18 @@ if ($action == 'add') $urlback=DOL_MAIN_URL_ROOT.'/public/paybox/newpayment.php?from=membernewform&source=membersubscription&ref='.$adh->ref; if (price2num(GETPOST('amount'))) $urlback.='&amount='.price2num(GETPOST('amount')); if (GETPOST('email')) $urlback.='&email='.urlencode(GETPOST('email')); + if (! empty($entity)) $urlback.='&entity='.$entity; } else if ($conf->global->MEMBER_NEWFORM_PAYONLINE == 'paypal') { $urlback=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?from=membernewform&source=membersubscription&ref='.$adh->ref; if (price2num(GETPOST('amount'))) $urlback.='&amount='.price2num(GETPOST('amount')); if (GETPOST('email')) $urlback.='&email='.urlencode(GETPOST('email')); + if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) + { + $urlback.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $adh->ref, 2); + } + if (! empty($entity)) $urlback.='&entity='.$entity; } else { @@ -368,7 +374,7 @@ jQuery(document).ready(function () { // Print form print '
'."\n"; print ''; -print ''; +print ''; print ''; print '
'; diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index f2f8842843a..636af99bd30 100755 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -27,6 +27,13 @@ define("NOLOGIN",1); // This means this output page does not require to be logged. define("NOCSRFCHECK",1); // We accept to go on this page from external web site. +// For MultiCompany module +$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_int($entity)) +{ + define("DOLENTITY", $entity); +} + require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php"); @@ -113,6 +120,11 @@ if (! empty($SECUREKEY)) $urlok.='securekey='.urlencode($SECUREKEY).'&'; $urlko.='securekey='.urlencode($SECUREKEY).'&'; } +if (! empty($entity)) +{ + $urlok.='entity='.urlencode($entity).'&'; + $urlko.='entity='.urlencode($entity).'&'; +} $urlok=preg_replace('/&$/','',$urlok); // Remove last & $urlko=preg_replace('/&$/','',$urlko); // Remove last & @@ -255,6 +267,7 @@ print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; +print ''; print "\n"; print ''."\n"; print ''."\n"; diff --git a/htdocs/public/paypal/paymentko.php b/htdocs/public/paypal/paymentko.php index 57382f4309c..243716ca70f 100755 --- a/htdocs/public/paypal/paymentko.php +++ b/htdocs/public/paypal/paymentko.php @@ -1,6 +1,7 @@ - * Copyright (C) 2006-2009 Laurent Destailleur +/* Copyright (C) 2001-2002 Rodolphe Quiedeville + * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin * * 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 @@ -28,6 +29,13 @@ define("NOLOGIN",1); // This means this output page does not require to be logged. define("NOCSRFCHECK",1); // We accept to go on this page from external web site. +// For MultiCompany module +$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_int($entity)) +{ + define("DOLENTITY", $entity); +} + require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php"); diff --git a/htdocs/public/paypal/paymentok.php b/htdocs/public/paypal/paymentok.php index f121ec9f83d..d9d4cfac729 100755 --- a/htdocs/public/paypal/paymentok.php +++ b/htdocs/public/paypal/paymentok.php @@ -1,6 +1,7 @@ - * Copyright (C) 2006-2009 Laurent Destailleur +/* Copyright (C) 2001-2002 Rodolphe Quiedeville + * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin * * 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 @@ -28,6 +29,13 @@ define("NOLOGIN",1); // This means this output page does not require to be logged. define("NOCSRFCHECK",1); // We accept to go on this page from external web site. +// For MultiCompany module +$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_int($entity)) +{ + define("DOLENTITY", $entity); +} + require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php");