Works on paypal module

Fix: uniformize code
This commit is contained in:
Regis Houssin 2011-05-21 07:12:21 +00:00
parent 9421ff4969
commit e0fe945afd
6 changed files with 98 additions and 124 deletions

View File

@ -583,6 +583,9 @@ class Commande extends CommonObject
if (! $remise) $remise=0; if (! $remise) $remise=0;
if (! $this->fk_project) $this->fk_project = 0; if (! $this->fk_project) $this->fk_project = 0;
// $date_commande is deprecated
$date = ($this->date_commande ? $this->date_commande : $this->date);
$this->db->begin(); $this->db->begin();
@ -593,7 +596,7 @@ class Commande extends CommonObject
$sql.= ", entity"; $sql.= ", entity";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->fk_project; $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->fk_project;
$sql.= ", ".$this->db->idate($this->date_commande); $sql.= ", ".$this->db->idate($date);
$sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null'); $sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null');
$sql.= ", '".$this->db->escape($this->note)."'"; $sql.= ", '".$this->db->escape($this->note)."'";
$sql.= ", '".$this->db->escape($this->note_public)."'"; $sql.= ", '".$this->db->escape($this->note_public)."'";
@ -2402,7 +2405,7 @@ class Commande extends CommonObject
function LibStatut($statut,$facturee,$mode) function LibStatut($statut,$facturee,$mode)
{ {
global $langs; global $langs;
print 'x'.$statut.'-'.$facturee; //print 'x'.$statut.'-'.$facturee;
if ($mode == 0) if ($mode == 0)
{ {
if ($statut==-1) return $langs->trans('StatusOrderCanceled'); if ($statut==-1) return $langs->trans('StatusOrderCanceled');

View File

@ -351,14 +351,10 @@ if ($action == 'add' && $user->rights->commande->creer)
{ {
$result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external'); $result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external');
if ($result > 0) if ($result < 0)
{
$error=0;
}
else
{ {
$mesg = '<div class="error">'.$langs->trans("ErrorFailedToAddContact").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFailedToAddContact").'</div>';
$error=1; $error++;
} }
} }

View File

@ -60,9 +60,11 @@ dol_syslog(join(',',$_GET));
if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transaction_id']) && ! empty($_GET['transaction_id']) ) if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transaction_id']) && ! empty($_GET['transaction_id']) )
{ {
if ($_GET['action'] == 'create') if ($_GET['action'] == 'add')
{ {
$soc = new Societe($db); $soc = new Societe($db);
// Create customer if not exists
$ret = $soc->fetchObjectFromRefExt($soc->table_element,$_SESSION[$_GET['transaction_id']]['PAYERID']); $ret = $soc->fetchObjectFromRefExt($soc->table_element,$_SESSION[$_GET['transaction_id']]['PAYERID']);
if ($ret < 0) if ($ret < 0)
{ {
@ -130,8 +132,11 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
} }
} }
// Add element (order, bill, etc.)
if ($soc->id > 0 && isset($_GET['element']) && ! empty($_GET['element'])) if ($soc->id > 0 && isset($_GET['element']) && ! empty($_GET['element']))
{ {
$error=0;
// Parse element/subelement (ex: project_task) // Parse element/subelement (ex: project_task)
$element = $subelement = $_GET['element']; $element = $subelement = $_GET['element'];
if (preg_match('/^([^_]+)_([^_]+)/i',$_GET['element'],$regs)) if (preg_match('/^([^_]+)_([^_]+)/i',$_GET['element'],$regs))
@ -152,7 +157,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$db->begin(); $db->begin();
$object->date_commande = dol_now(); $object->date = dol_now();
$object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY'];
$object->contactid = $contact->id; $object->contactid = $contact->id;
@ -160,17 +165,53 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
if ($object_id > 0) if ($object_id > 0)
{ {
$i=0; $i=0;
// Add element lines
while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i])) while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i]))
{ {
$product = new Product($db); $product = new Product($db);
$product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]); $ret = $product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]);
//$_SESSION[$_GET['transaction_id']]["L_QTY".$i]; if ($ret > 0)
echo 'ref='.$product->ref.' label='.$product->libelle.'<br>'; {
$product_type=($product->product_type?$product->product_type:0);
$result = $object->addline(
$object_id,
$product->description,
$product->price,
$_SESSION[$_GET['transaction_id']]["L_QTY".$i],
$product->tva_tx,
$product->localtax1_tx,
$product->localtax2_tx,
$product->id,
0,
0,
0,
'HT',
0,
'',
'',
$product_type
);
if ($result < 0)
{
$error++;
break;
}
}
$i++; $i++;
} }
}
else
{
$error++;
}
if ($object_id > 0 && ! $error)
{
$db->commit(); $db->commit();
} }
else else
@ -179,9 +220,9 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
} }
} }
// Return element id
echo 'socid='.$soc->id; echo 'socid='.$soc->id;
// Create element (order or bill)
/* /*
foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) foreach ($_SESSION[$_GET['transaction_id']] as $key => $value)
{ {

View File

@ -1,67 +0,0 @@
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/paypal/ajaxtransactiondetails.php
* \brief File to return Ajax response on paypal transaction details
* \version $Id$
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
require('../main.inc.php');
require_once(DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php');
require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php");
/*
* View
*/
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
//print '<body class="nocellnopadd">'."\n";
dol_syslog(join(',',$_GET));
if (isset($_GET['transaction_id']) && ! empty($_GET['transaction_id']))
{
$resArray = GetTransactionDetails($_GET['transaction_id']);
foreach($resArray as $key => $value) {
echo $key.': '.$value.'<br />';
}
//print json_encode($resArray);
}
//print "</body>";
//print "</html>";
?>

View File

@ -127,7 +127,7 @@ llxHeader();
buttons: { buttons: {
'<?php echo $langs->transnoentities('Create'); ?>': function() { '<?php echo $langs->transnoentities('Create'); ?>': function() {
$.get( "<?php echo DOL_URL_ROOT; ?>/paypal/ajaxtransaction.php", { $.get( "<?php echo DOL_URL_ROOT; ?>/paypal/ajaxtransaction.php", {
action: 'create', action: 'add',
element: 'order', element: 'order',
transaction_id: id_value transaction_id: id_value
}, },

View File

@ -1021,7 +1021,8 @@ class Product extends CommonObject
$this->id = $result["rowid"]; $this->id = $result["rowid"];
$this->ref = $result["ref"]; $this->ref = $result["ref"];
$this->libelle = $result["label"]; $this->libelle = $result["label"]; // TODO deprecated
$this->label = $result["label"];
$this->description = $result["description"]; $this->description = $result["description"];
$this->note = $result["note"]; $this->note = $result["note"];
$this->customcode = $result["customcode"]; $this->customcode = $result["customcode"];