From 6d56cc196b7ee7a100d3cb9ec5c969d45765df13 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 22 May 2011 18:12:42 +0000 Subject: [PATCH] Works on paypal module Fix: better error management --- htdocs/commande/class/commande.class.php | 7 +- htdocs/compta/facture/class/facture.class.php | 24 +++-- htdocs/langs/en_US/errors.lang | 3 +- htdocs/langs/en_US/paypal.lang | 2 + htdocs/langs/fr_FR/errors.lang | 3 +- htdocs/langs/fr_FR/paypal.lang | 2 + htdocs/paypal/ajaxtransaction.php | 87 ++++++++++--------- htdocs/paypal/transaction.php | 52 ++++++++--- 8 files changed, 107 insertions(+), 73 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 911a792b974..c892bed8fcd 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2469,16 +2469,15 @@ class Commande extends CommonObject * @param option Where point the link * @return string String with URL */ - function getNomUrl($withpicto=0,$option=0,$short=0) + function getNomUrl($withpicto=0,$option=0,$max=0,$short=0) { global $conf, $langs; $result=''; - $file = '/commande/fiche.php'; - if ($conf->expedition->enabled && ($option == 1 || $option == 2)) $file = '/expedition/shipment.php'; + if ($conf->expedition->enabled && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; + else $url = DOL_URL_ROOT.'/commande/fiche.php?id='.$this->id; - $url = DOL_URL_ROOT.$file.'?id='.$this->id; if ($short) return $url; $linkstart = ''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7213407e3d2..f1d8ac37005 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -151,6 +151,7 @@ class Facture extends CommonObject $this->note=trim($this->note); $this->note_public=trim($this->note_public); if (! $this->remise) $this->remise = 0; + if (! $this->cond_reglement_id) $this->cond_reglement_id = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; @@ -605,22 +606,19 @@ class Facture extends CommonObject * @param max Maxlength of ref * @return string String with URL */ - function getNomUrl($withpicto=0,$option='',$max=0) + function getNomUrl($withpicto=0,$option='',$max=0,$short=0) { global $langs; $result=''; - if ($option == 'withdraw') - { - $lien = ''; - $lienfin=''; - } - else - { - $lien = ''; - $lienfin=''; - } + if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id; + else $url = DOL_URL_ROOT.'/compta/facture.php?facid='.$this->id; + + if ($short) return $url; + + $linkstart=''; + $linkend=''; $picto='bill'; if ($this->type == 1) $picto.='r'; // Replacement invoice @@ -632,9 +630,9 @@ class Facture extends CommonObject if ($this->type == 2) $label=$langs->trans("ShowInvoiceAvoir").': '.$this->ref; if ($this->type == 3) $label=$langs->trans("ShowInvoiceDeposit").': '.$this->ref; - if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto) $result.=($linkstart.img_object($label,$picto).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.($max?dol_trunc($this->ref,$max):$this->ref).$lienfin; + if ($withpicto != 2) $result.=$linkstart.($max?dol_trunc($this->ref,$max):$this->ref).$linkend; return $result; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 1c916e84fc9..9ba8b66c18b 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -78,4 +78,5 @@ ErrorModuleSetupNotComplete=Setup of module looks to be uncomplete. Go on Setup ErrorBadMask=Error on mask ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number ErrorBadMaskBadRazMonth=Error, bad reset value -ErrorSelectAtLeastOne=Error. Select at least one entry. \ No newline at end of file +ErrorSelectAtLeastOne=Error. Select at least one entry. +ErrorProductWithRefNotExist=Product with reference '%s' don't exist \ No newline at end of file diff --git a/htdocs/langs/en_US/paypal.lang b/htdocs/langs/en_US/paypal.lang index 39b8f13b1a6..d524dae162f 100644 --- a/htdocs/langs/en_US/paypal.lang +++ b/htdocs/langs/en_US/paypal.lang @@ -18,7 +18,9 @@ PAYPAL_CSS_URL=Optionnal Url of CSS style sheet on payment page ThisIsTransactionId=This is id of transaction: %s PaypalTransactionDesc=This options allows you to import Paypal payments in Dolibarr as orders, invoices, etc ... PaypalEnableThisTool=Enable this functionnality +Verified=Verified Unverified=Unverified +Confirmed=Confirmed Unconfirmed=Unconfirmed GrossAmount=Gross amount FeeAmount=Fee amount diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 120ebfa1860..5e4823b8d1a 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -79,4 +79,5 @@ ErrorModuleSetupNotComplete=La configuration du module semble incomplète. Aller ErrorBadMask=Erreur sur le masque ErrorBadMaskFailedToLocatePosOfSequence=Erreur, masque sans numéro de séquence ErrorBadMaskBadRazMonth=Erreur, mauvais valeur de remise à zéro -ErrorSelectAtLeastOne=Erreur. Sélectionnez au moins une entrée. \ No newline at end of file +ErrorSelectAtLeastOne=Erreur. Sélectionnez au moins une entrée. +ErrorProductWithRefNotExist=La référence produit '%s' n'existe pas \ No newline at end of file diff --git a/htdocs/langs/fr_FR/paypal.lang b/htdocs/langs/fr_FR/paypal.lang index 0a3dea1ddee..389f9c6ed37 100644 --- a/htdocs/langs/fr_FR/paypal.lang +++ b/htdocs/langs/fr_FR/paypal.lang @@ -18,7 +18,9 @@ PAYPAL_CSS_URL=Url optionnelle de la feuille de style CSS de la page de paiement ThisIsTransactionId=Voici l'identifiant de la transaction: %s PaypalTransactionDesc=Ces options permettent d'importer des paiements Paypal dans Dolibarr en tant que commandes, factures, etc... PaypalEnableThisTool=Activer ces fonctionnalités +Verified=Vérifié Unverified=Non vérifié +Confirmed=Confirmée Unconfirmed=Non confirmée GrossAmount=Montant brut FeeAmount=Frais Paypal diff --git a/htdocs/paypal/ajaxtransaction.php b/htdocs/paypal/ajaxtransaction.php index 1899a5929e0..7623cee1515 100644 --- a/htdocs/paypal/ajaxtransaction.php +++ b/htdocs/paypal/ajaxtransaction.php @@ -64,6 +64,9 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti { $soc = new Societe($db); + $error=0; + $return_arr = array(); + // Create customer if not exists $ret = $soc->fetchObjectFromRefExt($soc->table_element,$_SESSION[$_GET['transaction_id']]['PAYERID']); if ($ret < 0) @@ -116,27 +119,34 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti $contact->priv=0; $result=$contact->create($user); + if ($result < 0) + { + $langs->load("errors"); + $return_arr['error'] = 'Contact::create '.$langs->trans($contact->error); + $error++; + } } } + else + { + $langs->load("errors"); + $return_arr['error'] = 'Societe::create '.$langs->trans($soc->error); + $error++; + } - if ($result >= 0) + if (! $error) { $db->commit(); } else { $db->rollback(); - $langs->load("errors"); - echo $langs->trans($contact->error); - echo $langs->trans($soc->error); } } // Add element (order, bill, etc.) - if ($soc->id > 0 && isset($_GET['element']) && ! empty($_GET['element'])) + if (! $error && $soc->id > 0 && isset($_GET['element']) && ! empty($_GET['element'])) { - $error=0; - // Parse element/subelement (ex: project_task) $element = $subelement = $_GET['element']; if (preg_match('/^([^_]+)_([^_]+)/i',$_GET['element'],$regs)) @@ -146,6 +156,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti } // For compatibility if ($element == 'order') { $element = $subelement = 'commande'; } + if ($element == 'invoice') { $element = 'compta/facture'; $subelement = 'facture'; } dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); @@ -173,63 +184,52 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti if ($ret > 0) { + $qty=$_SESSION[$_GET['transaction_id']]["L_QTY".$i]; $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 ($subelement == 'commande') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,0,0,'HT',0,'','',$product_type); + if ($subelement == 'facture') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,'','',0,0,0,'HT',0,$product_type); + + $result = $object->addline($fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9],$fields[10],$fields[11],$fields[12],$fields[13],$fields[14],$fields[15],$fields[16]); if ($result < 0) { $error++; + $langs->load("errors"); + $return_arr['error'] = ucfirst($subelement).'::addline '.$langs->trans($object->error); break; } } + else + { + $error++; + $langs->load("errors"); + $return_arr['error'].= $langs->trans('ErrorProductWithRefNotExist', $_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]).'
'; + } $i++; } - - // Insert default contacts - /* - if ($contact->id > 0) - { - $result=$object->add_contact($contact->id,'CUSTOMER','external'); - if ($result < 0) $error++; - } - */ } else { - $error++; + $langs->load("errors"); + $return_arr['error'] = ucfirst($subelement).'::create '.$langs->trans($object->error); + $error++; } - + if ($object_id > 0 && ! $error) { $db->commit(); + $return_arr['elementurl'] = $object->getNomUrl(0,'',0,1); } else { $db->rollback(); } } + + echo json_encode($return_arr); - // Return element id - echo $object->getNomUrl(0,0,1); /* foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) { @@ -267,9 +267,14 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti echo ''.$langs->trans('Date').''.dol_print_date(dol_stringtotime($_SESSION[$_GET['transaction_id']]['ORDERTIME']),'dayhour').''; $var=!$var; - echo ''.$langs->trans('PAYERSTATUS').''.$langs->trans(ucfirst($_SESSION[$_GET['transaction_id']]['PAYERSTATUS'])).''; + $payerstatus=strtolower($_SESSION[$_GET['transaction_id']]['PAYERSTATUS']); + $img_payerstatus=($payerstatus=='verified' ? img_tick($langs->trans(ucfirst($payerstatus))) : img_warning($langs->trans(ucfirst($payerstatus))) ); + echo ''.$langs->trans('PAYERSTATUS').''.$img_payerstatus.''; + $var=!$var; - echo ''.$langs->trans('ADDRESSSTATUS').''.$langs->trans(ucfirst($_SESSION[$_GET['transaction_id']]['ADDRESSSTATUS'])).''; + $addressstatus=strtolower($_SESSION[$_GET['transaction_id']]['ADDRESSSTATUS']); + $img_addressstatus=($addressstatus=='confirmed' ? img_tick($langs->trans(ucfirst($addressstatus))) : img_warning($langs->trans(ucfirst($addressstatus))) ); + echo ''.$langs->trans('ADDRESSSTATUS').''.$img_addressstatus.''; $shipamount=($_SESSION[$_GET['transaction_id']]['SHIPPINGAMT']?$_SESSION[$_GET['transaction_id']]['SHIPPINGAMT']:$_SESSION[$_GET['transaction_id']]['SHIPAMOUNT']); $var=!$var; diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php index f7bad49e279..0d318e29c12 100644 --- a/htdocs/paypal/transaction.php +++ b/htdocs/paypal/transaction.php @@ -148,27 +148,53 @@ if (empty($conf->global->PAYPAL_API_USER) || empty($conf->global->PAYPAL_API_PAS modal: true, width: 500, buttons: { - 'commande->enabled) { - $langs->load("orders"); - echo $langs->transnoentities('CreateOrder'); ?>': function() { - $.get( "/paypal/ajaxtransaction.php", { + $langs->load("orders"); ?> + 'transnoentities('CreateOrder'); ?>': function() { + $.getJSON( "/paypal/ajaxtransaction.php", { action: 'add', element: 'order', transaction_id: id_value }, - function(elementurl) { - if ($.jnotify) { - $.jnotify("trans('PleaseBePatient'); ?>", 500); - } - $( "div #paypal-details" ).dialog( "close" ); - location.href=elementurl; + function(response) { + $.each(response, function(key,value) { + if (key == 'error') { + $.jnotify(value, "error", true); + } else { + $.jnotify("trans('PleaseBePatient'); ?>", 500); + $( "div #paypal-details" ).dialog( "close" ); + location.href=value; + } + }); }); }, - 'transnoentities('Cancel'); ?>': function() { + + facture->enabled) + { + $langs->load("bills"); ?> + 'transnoentities('CreateBill'); ?>': function() { + $.getJSON( "/paypal/ajaxtransaction.php", { + action: 'add', + element: 'invoice', + transaction_id: id_value + }, + function(response) { + $.each(response, function(key,value) { + if (key == 'error') { + $.jnotify(value, "error", true); + } else { + $.jnotify("trans('PleaseBePatient'); ?>", 500); + $( "div #paypal-details" ).dialog( "close" ); + location.href=value; + } + }); + }); + }, + + 'transnoentities('Cancel'); ?>': function() { $( this ).dialog( "close" ); } }