From be26c5224300ed476881001d0c229c6c988ba1c0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 24 May 2011 17:28:58 +0000 Subject: [PATCH] Works on paypal module New: add trigger for fee treatment --- htdocs/compta/paiement.php | 34 ++++++++++--------- .../compta/paiement/class/paiement.class.php | 20 ++++++++--- .../interface_all_Demo.class.php-NORUN | 8 +++-- ...terface_modPaypal_PaypalWorkflow.class.php | 11 +++++- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index c190fe3398d..c1137d75e19 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -36,12 +36,15 @@ $langs->load('companies'); $langs->load('bills'); $langs->load('banks'); -$facid=isset($_GET['facid'])?$_GET['facid']:$_POST['facid']; -$socname=isset($_GET['socname'])?$_GET['socname']:$_POST['socname']; +$action = GETPOST('action'); +$confirm = GETPOST('confirm'); -$sortfield = isset($_GET['sortfield'])?$_GET['sortfield']:$_POST['sortfield']; -$sortorder = isset($_GET['sortorder'])?$_GET['sortorder']:$_POST['sortorder']; -$page=isset($_GET['page'])?$_GET['page']:$_POST['page']; +$facid = GETPOST('facid'); +$socname = GETPOST('socname'); + +$sortfield = GETPOST('sortfield'); +$sortorder = GETPOST('sortorder'); +$page = GETPOST('page'); $amounts=array(); $amountsresttopay=array(); @@ -59,7 +62,7 @@ if ($user->societe_id > 0) /* * Action add_paiement et confirm_paiement */ -if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement' && $_POST['confirm']=='yes')) +if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error = 0; @@ -124,12 +127,11 @@ if ($_POST['action'] == 'add_paiement' || ($_POST['action'] == 'confirm_paiement /* * Action add_paiement */ -if ($_POST['action'] == 'add_paiement') +if ($action == 'add_paiement') { if ($error) { - $_POST['action']=''; - $_GET['action'] = 'create'; + $action = 'create'; } // Le reste propre a cette action s'affiche en bas de page. } @@ -137,7 +139,7 @@ if ($_POST['action'] == 'add_paiement') /* * Action confirm_paiement */ -if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') +if ($action == 'confirm_paiement' && $confirm == 'yes') { $error=0; @@ -209,7 +211,7 @@ llxHeader(); $html=new Form($db); -if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_POST['action'] == 'add_paiement') +if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { $facture = new Facture($db); $result=$facture->fetch($facid); @@ -234,7 +236,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P } // Initialize data for confirmation (this is used because data can be change during confirmation) - if ($_POST["action"] == 'add_paiement') + if ($action == 'add_paiement') { $i=0; @@ -311,7 +313,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P { print ''.$langs->trans('AmountPayment').''; print ''; - if ($_POST["action"] == 'add_paiement') + if ($action == 'add_paiement') { print ''; print ''; @@ -554,7 +556,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P $namef = 'amount_'.$objp->facid; $namef = 'amount_'.$objp->facid; - if ($_POST["action"] != 'add_paiement') + if ($action != 'add_paiement') { if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) { @@ -619,7 +621,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P // Bouton Enregistrer - if ($_POST["action"] != 'add_paiement') + if ($action != 'add_paiement') { // print ''; print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); @@ -636,7 +638,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P } // Form to confirm payment - if ($_POST["action"] == 'add_paiement') + if ($action == 'add_paiement') { $preselectedchoice=$addwarning?'no':'yes'; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 9cec181e645..14e6f1829e7 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -51,6 +51,7 @@ class Paiement extends CommonObject var $num_paiement; // Numero du CHQ, VIR, etc... var $bank_account; // Id compte bancaire du paiement var $bank_line; // Id de la ligne d'ecriture bancaire + var $fk_account; // Id of bank account var $note; // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...) // fk_paiement dans llx_paiement_facture est le rowid du paiement @@ -334,21 +335,22 @@ class Paiement extends CommonObject * @param emetteur_banque Name of bank * @return int <0 if KO, bank_line_id if OK */ - function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque,$notrigger=0) { - global $conf; + global $conf,$langs,$user; $error=0; $bank_line_id=0; + $this->fk_account=$accountid; if ($conf->banque->enabled) { require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); - dol_syslog("$user->id,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque"); + dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque"); $acc = new Account($this->db); - $acc->fetch($accountid); + $acc->fetch($this->fk_account); $totalamount=$this->amount; if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility @@ -428,6 +430,16 @@ class Paiement extends CommonObject } } } + + if (! $error && ! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PAYMENT_ADD_TO_BANK',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } } else { diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN index 662c7400875..b2b1668dc7a 100644 --- a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN +++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2010 Regis Houssin +/* Copyright (C) 2005-2011 Laurent Destailleur + * Copyright (C) 2005-2011 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 @@ -360,6 +360,10 @@ class InterfaceDemo dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'PAYMENT_SUPPLIER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PAYMENT_ADD_TO_BANK') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } diff --git a/htdocs/paypal/inc/triggers/interface_modPaypal_PaypalWorkflow.class.php b/htdocs/paypal/inc/triggers/interface_modPaypal_PaypalWorkflow.class.php index 4bb5e20879d..603fbb2aa50 100644 --- a/htdocs/paypal/inc/triggers/interface_modPaypal_PaypalWorkflow.class.php +++ b/htdocs/paypal/inc/triggers/interface_modPaypal_PaypalWorkflow.class.php @@ -97,8 +97,17 @@ class InterfacePaypalWorkflow { // Mettre ici le code a executer en reaction de l'action // Les donnees de l'action sont stockees dans $object - + + // Add Paypal fee + if ($action == 'PAYMENT_ADD_TO_BANK') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->rowid); + + //var_dump($object); + // use num_paiement and fk_account + + } return 0; }