Minor fixes in paypal translaction list

This commit is contained in:
Laurent Destailleur 2011-05-21 16:30:16 +00:00
parent 065cf89b72
commit a52bd5f06c
2 changed files with 79 additions and 54 deletions

View File

@ -63,7 +63,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
if ($_GET['action'] == 'add') if ($_GET['action'] == 'add')
{ {
$soc = new Societe($db); $soc = new Societe($db);
// Create customer if not exists // 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)
@ -77,7 +77,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
} }
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
$modCodeClient = new $module; $modCodeClient = new $module;
// Create customer and return rowid // Create customer and return rowid
$soc->ref_ext = $_SESSION[$_GET['transaction_id']]['PAYERID']; $soc->ref_ext = $_SESSION[$_GET['transaction_id']]['PAYERID'];
$soc->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_SESSION[$_GET['transaction_id']]['FIRSTNAME'].' '.$_SESSION[$_GET['transaction_id']]['LASTNAME']):trim($_SESSION[$_GET['transaction_id']]['LASTNAME'].' '.$_SESSION[$_GET['transaction_id']]['FIRSTNAME']); $soc->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_SESSION[$_GET['transaction_id']]['FIRSTNAME'].' '.$_SESSION[$_GET['transaction_id']]['LASTNAME']):trim($_SESSION[$_GET['transaction_id']]['LASTNAME'].' '.$_SESSION[$_GET['transaction_id']]['FIRSTNAME']);
@ -92,7 +92,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$soc->tva_assuj = 1; $soc->tva_assuj = 1;
$soc->client = 1; $soc->client = 1;
$soc->particulier = 1; $soc->particulier = 1;
$db->begin(); $db->begin();
$result = $soc->create($user); $result = $soc->create($user);
if ($result >= 0) if ($result >= 0)
@ -100,7 +100,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
if ($soc->particulier) if ($soc->particulier)
{ {
$contact=new Contact($db); $contact=new Contact($db);
$contact->civilite_id = $soc->civilite_id; $contact->civilite_id = $soc->civilite_id;
$contact->name=$soc->nom_particulier; $contact->name=$soc->nom_particulier;
$contact->firstname=$soc->prenom; $contact->firstname=$soc->prenom;
@ -114,11 +114,11 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$contact->status=1; $contact->status=1;
$contact->email=$soc->email; $contact->email=$soc->email;
$contact->priv=0; $contact->priv=0;
$result=$contact->create($user); $result=$contact->create($user);
} }
} }
if ($result >= 0) if ($result >= 0)
{ {
$db->commit(); $db->commit();
@ -131,12 +131,12 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
echo $langs->trans($soc->error); echo $langs->trans($soc->error);
} }
} }
// Add element (order, bill, etc.) // 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; $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))
@ -151,30 +151,31 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$classname = ucfirst($subelement); $classname = ucfirst($subelement);
$object = new $classname($db); $object = new $classname($db);
$object->socid=$soc->id; $object->socid=$soc->id;
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$db->begin(); $db->begin();
$object->date = dol_now(); $object->date = dol_now();
$object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY'];
$object_id = $object->create($user); $object_id = $object->create($user);
if ($object_id > 0) if ($object_id > 0)
{ {
$i=0; $i=0;
// Add element lines // 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);
$ret = $product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]); $ret = $product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]);
if ($ret > 0) if ($ret > 0)
{ {
$product_type=($product->product_type?$product->product_type:0); $product_type=($product->product_type?$product->product_type:0);
$result = $object->addline( $result = $object->addline(
$object_id, $object_id,
$product->description, $product->description,
@ -193,17 +194,17 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
'', '',
$product_type $product_type
); );
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
break; break;
} }
} }
$i++; $i++;
} }
// Insert default contacts // Insert default contacts
/* /*
if ($contact->id > 0) if ($contact->id > 0)
@ -217,7 +218,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
{ {
$error++; $error++;
} }
if ($object_id > 0 && ! $error) if ($object_id > 0 && ! $error)
{ {
$db->commit(); $db->commit();
@ -230,27 +231,27 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
// Return element id // Return element id
echo $object->getNomUrl(0,0,1); echo $object->getNomUrl(0,0,1);
/* /*
foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) foreach ($_SESSION[$_GET['transaction_id']] as $key => $value)
{ {
echo $key.': '.$value.'<br />'; echo $key.': '.$value.'<br />';
} }
*/ */
} }
else if ($_GET['action'] == 'showdetails') else if ($_GET['action'] == 'showdetails')
{ {
// For paypal request optimization // For paypal request optimization
if (! isset($_SESSION[$_GET['transaction_id']]) ) $_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']); if (! isset($_SESSION[$_GET['transaction_id']]) ) $_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']);
$var=true; $var=true;
echo '<table style="noboardernopading" width="100%">'; echo '<table style="noboardernopading" width="100%">';
echo '<tr class="liste_titre">'; echo '<tr class="liste_titre">';
echo '<td colspan="2">'.$langs->trans('CustomerDetails').'</td>'; echo '<td colspan="2">'.$langs->trans('ThirdParty').'</td>';
echo '</tr>'; echo '</tr>';
$var=!$var; $var=!$var;
echo '<tr '.$bc[$var].'><td>'.$langs->trans('LastName').': </td><td>'.$_SESSION[$_GET['transaction_id']]['LASTNAME'].'</td></tr>'; echo '<tr '.$bc[$var].'><td>'.$langs->trans('LastName').': </td><td>'.$_SESSION[$_GET['transaction_id']]['LASTNAME'].'</td></tr>';
$var=!$var; $var=!$var;
@ -265,36 +266,36 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
echo '<tr '.$bc[$var].'><td>'.$langs->trans('Email').': </td><td>'.$_SESSION[$_GET['transaction_id']]['EMAIL'].'</td>'; echo '<tr '.$bc[$var].'><td>'.$langs->trans('Email').': </td><td>'.$_SESSION[$_GET['transaction_id']]['EMAIL'].'</td>';
$var=!$var; $var=!$var;
echo '<tr '.$bc[$var].'><td>'.$langs->trans('Date').': </td><td>'.dol_print_date(dol_stringtotime($_SESSION[$_GET['transaction_id']]['ORDERTIME']),'dayhour').'</td>'; echo '<tr '.$bc[$var].'><td>'.$langs->trans('Date').': </td><td>'.dol_print_date(dol_stringtotime($_SESSION[$_GET['transaction_id']]['ORDERTIME']),'dayhour').'</td>';
echo '</table>'; echo '</table>';
$i=0; $i=0;
echo '<table style="noboardernopading" width="100%">'; echo '<table style="noboardernopading" width="100%">';
echo '<tr class="liste_titre">'; echo '<tr class="liste_titre">';
echo '<td>'.$langs->trans('Ref').'</td>'; echo '<td>'.$langs->trans('Ref').'</td>';
echo '<td>'.$langs->trans('Label').'</td>'; echo '<td>'.$langs->trans('Label').'</td>';
echo '<td>'.$langs->trans('Qty').'</td>'; echo '<td>'.$langs->trans('Qty').'</td>';
echo '</tr>'; echo '</tr>';
while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i])) while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i]))
{ {
$var=!$var; $var=!$var;
echo '<tr '.$bc[$var].'>'; echo '<tr '.$bc[$var].'>';
echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i].'</td>'; echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i].'</td>';
echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_NAME".$i].'</td>'; echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_NAME".$i].'</td>';
echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_QTY".$i].'</td>'; echo '<td>'.$_SESSION[$_GET['transaction_id']]["L_QTY".$i].'</td>';
echo '</tr>'; echo '</tr>';
$i++; $i++;
} }
echo '</table>'; echo '</table>';
/* /*
echo '<br />'; echo '<br />';
foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) foreach ($_SESSION[$_GET['transaction_id']] as $key => $value)
{ {
echo $key.': '.$value.'<br />'; echo $key.': '.$value.'<br />';

View File

@ -24,10 +24,13 @@
*/ */
require("../main.inc.php"); require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT.'/lib/date.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php');
require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php"); require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php");
$langs->load("paypal"); $langs->load("paypal");
$langs->load("paybox");
$langs->load("companies");
// Security check // Security check
$result=restrictedArea($user,'paypal','','','transaction'); $result=restrictedArea($user,'paypal','','','transaction');
@ -58,11 +61,13 @@ $errors='';
$nvpStr=''; $nvpStr='';
$now=dol_now();
if(isset($startDateStr) && ! empty($startDateStr)) { if(isset($startDateStr) && ! empty($startDateStr)) {
$start_date_str = $startDateStr; $start_date_str = $startDateStr;
$start_time = dol_stringtotime($start_date_str); $start_time = dol_stringtotime($start_date_str);
} else { } else {
$start_time = dol_now()-2592000; // 30 days $start_time = dol_time_plus_duree($now,-1,'m'); // 30 days
$start_date_str = dol_print_date($start_time,'day'); $start_date_str = dol_print_date($start_time,'day');
} }
@ -71,22 +76,40 @@ $nvpStr.="&STARTDATE=$iso_start";
if(isset($endDateStr) && ! empty($endDateStr)) { if(isset($endDateStr) && ! empty($endDateStr)) {
$end_date_str = $endDateStr; $end_date_str = $endDateStr;
$end_time = dol_stringtotime($end_date_str); $end_time = dol_stringtotime($end_date_str);
} else { } else {
$end_time = dol_now(); $end_time = $now;
$end_date_str = dol_print_date($end_time,'day'); $end_date_str = dol_print_date($end_time,'day');
} }
$iso_end = dol_print_date($end_time,'dayhourrfc'); $iso_end = dol_print_date($end_time,'dayhourrfc');
$nvpStr.="&ENDDATE=$iso_end"; $nvpStr.="&ENDDATE=".$iso_end;
if(isset($transactionID) && ! empty($transactionID)) { if(isset($transactionID) && ! empty($transactionID)) {
$nvpStr.="&TRANSACTIONID=$transactionID"; $nvpStr.="&TRANSACTIONID=$transactionID";
} }
llxHeader(); llxHeader();
dol_htmloutput_errors('',$errors);
print_fiche_titre(' - '.$langs->trans('PaypalTransaction'), '', 'paypal_logo@paypal');
print '<br />';
if (empty($conf->global->PAYPAL_API_USER) || empty($conf->global->PAYPAL_API_PASSWORD)
|| empty($conf->global->PAYPAL_API_SIGNATURE))
{
$langs->load("errors");
print $langs->trans("ErrorModuleSetupNotComplete");
llxFooter();
exit;
}
?> ?>
<script> <script>
@ -125,7 +148,11 @@ llxHeader();
modal: true, modal: true,
width: 500, width: 500,
buttons: { buttons: {
'<?php echo $langs->transnoentities('Create'); ?>': function() { '<?php
if ($conf->commande->enabled)
{
$langs->load("orders");
echo $langs->transnoentities('CreateOrder'); ?>': function() {
$.get( "<?php echo DOL_URL_ROOT; ?>/paypal/ajaxtransaction.php", { $.get( "<?php echo DOL_URL_ROOT; ?>/paypal/ajaxtransaction.php", {
action: 'add', action: 'add',
element: 'order', element: 'order',
@ -139,7 +166,9 @@ llxHeader();
location.href=elementurl; location.href=elementurl;
}); });
}, },
'<?php echo $langs->transnoentities('Cancel'); ?>': function() { '<?php
}
echo $langs->transnoentities('Cancel'); ?>': function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
} }
@ -160,11 +189,11 @@ if (! empty($nvpStr))
{ {
$resArray=hash_call("TransactionSearch",$nvpStr); $resArray=hash_call("TransactionSearch",$nvpStr);
//var_dump($resArray); //var_dump($resArray);
if (is_array($resArray)) if (is_array($resArray))
{ {
$reqArray=$_SESSION['nvpReqArray']; $reqArray=$_SESSION['nvpReqArray'];
$ack = strtoupper($resArray["ACK"]); $ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING") if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING")
{ {
@ -174,11 +203,6 @@ if (! empty($nvpStr))
} }
} }
dol_htmloutput_errors('',$errors);
print_fiche_titre(' - '.$langs->trans('PaypalTransaction'), '', 'paypal_logo@paypal');
print '<br />';
// Search parameters // Search parameters
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'; print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
@ -196,7 +220,7 @@ print '<input type="text" id="endDateStr" name="endDateStr" maxlength="20" size=
print $langs->trans('Ref').': '; print $langs->trans('Ref').': ';
print '<input type="text" name="transactionID" />&nbsp;'; print '<input type="text" name="transactionID" />&nbsp;';
print '<input type="submit" value="'.$langs->trans('Send').'" />'; print '<input type="submit" class="button" value="'.$langs->trans('Send').'" />';
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
@ -216,7 +240,7 @@ print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'','',''.$s
print '</tr>'; print '</tr>';
$var=true; $var=true;
if(! isset($resArray["L_TRANSACTIONID0"])) if(! isset($resArray["L_TRANSACTIONID0"]))
{ {
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -226,11 +250,11 @@ if(! isset($resArray["L_TRANSACTIONID0"]))
else else
{ {
$i=0; $i=0;
while (isset($resArray["L_TRANSACTIONID".$i])) while (isset($resArray["L_TRANSACTIONID".$i]))
{ {
$var=!$var; $var=!$var;
$transactionID = $resArray["L_TRANSACTIONID".$i]; $transactionID = $resArray["L_TRANSACTIONID".$i];
$timeStamp = dol_stringtotime($resArray["L_TIMESTAMP".$i]); $timeStamp = dol_stringtotime($resArray["L_TIMESTAMP".$i]);
$payerName = $resArray["L_NAME".$i]; $payerName = $resArray["L_NAME".$i];
@ -239,7 +263,7 @@ else
$netamount = $resArray["L_NETAMT".$i]; $netamount = $resArray["L_NETAMT".$i];
$currency = $resArray["L_CURRENCYCODE".$i]; $currency = $resArray["L_CURRENCYCODE".$i];
$status = $resArray["L_STATUS".$i]; $status = $resArray["L_STATUS".$i];
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td><div id="'.$transactionID.'" class="paypal_link" style="font-weight:bold;cursor:pointer;">'.$transactionID.'</div></td>'; print '<td><div id="'.$transactionID.'" class="paypal_link" style="font-weight:bold;cursor:pointer;">'.$transactionID.'</div></td>';
print '<td align="left">'.$payerName.'</td>'; print '<td align="left">'.$payerName.'</td>';
@ -249,11 +273,11 @@ else
print '<td align="right">'.$netamount.' '.$currency.'</td>'; print '<td align="right">'.$netamount.' '.$currency.'</td>';
print '<td align="right">'.$status.'</td>'; print '<td align="right">'.$status.'</td>';
print '</tr>'; print '</tr>';
$i++; $i++;
} }
} }
print '</table>'; print '</table>';
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');