diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e31451f049b..73ac189adee 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2011 Juanjo Menent - * Copyright (C) 2011 Jean Heimburger + * Copyright (C) 2011 Jean Heimburger * * 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 @@ -582,6 +582,9 @@ class Commande extends CommonObject } if (! $remise) $remise=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(); @@ -593,7 +596,7 @@ class Commande extends CommonObject $sql.= ", entity"; $sql.= ")"; $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->db->escape($this->note)."'"; $sql.= ", '".$this->db->escape($this->note_public)."'"; @@ -2402,7 +2405,7 @@ class Commande extends CommonObject function LibStatut($statut,$facturee,$mode) { global $langs; -print 'x'.$statut.'-'.$facturee; + //print 'x'.$statut.'-'.$facturee; if ($mode == 0) { if ($statut==-1) return $langs->trans('StatusOrderCanceled'); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 008ecee3220..7bbda87d30d 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -351,14 +351,10 @@ if ($action == 'add' && $user->rights->commande->creer) { $result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external'); - if ($result > 0) - { - $error=0; - } - else + if ($result < 0) { $mesg = '
'.$langs->trans("ErrorFailedToAddContact").'
'; - $error=1; + $error++; } } diff --git a/htdocs/paypal/ajaxtransaction.php b/htdocs/paypal/ajaxtransaction.php index 70757509fb2..c802274e4fc 100644 --- a/htdocs/paypal/ajaxtransaction.php +++ b/htdocs/paypal/ajaxtransaction.php @@ -60,9 +60,11 @@ dol_syslog(join(',',$_GET)); 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); + + // Create customer if not exists $ret = $soc->fetchObjectFromRefExt($soc->table_element,$_SESSION[$_GET['transaction_id']]['PAYERID']); 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'])) { + $error=0; + // Parse element/subelement (ex: project_task) $element = $subelement = $_GET['element']; if (preg_match('/^([^_]+)_([^_]+)/i',$_GET['element'],$regs)) @@ -152,7 +157,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti $db->begin(); - $object->date_commande = dol_now(); + $object->date = dol_now(); $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; $object->contactid = $contact->id; @@ -160,28 +165,64 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti if ($object_id > 0) { $i=0; - while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i])) + + // Add element lines + while (isset($_SESSION[$_GET['transaction_id']]["L_NAME".$i])) { $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]; - echo 'ref='.$product->ref.' label='.$product->libelle.'
'; + if ($ret > 0) + { + $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++; } - - $db->commit(); } else { - $db->rollback(); + $error++; } + + if ($object_id > 0 && ! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } } + // Return element id echo 'socid='.$soc->id; - // Create element (order or bill) /* foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) { diff --git a/htdocs/paypal/ajaxtransactiondetails.php b/htdocs/paypal/ajaxtransactiondetails.php deleted file mode 100644 index b1c939743d5..00000000000 --- a/htdocs/paypal/ajaxtransactiondetails.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * 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 ''."\n"; - -//print ''."\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.'
'; - } - - //print json_encode($resArray); -} - -//print ""; -//print ""; -?> \ No newline at end of file diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php index 182626505db..c823c75d4a7 100644 --- a/htdocs/paypal/transaction.php +++ b/htdocs/paypal/transaction.php @@ -127,7 +127,7 @@ llxHeader(); buttons: { 'transnoentities('Create'); ?>': function() { $.get( "/paypal/ajaxtransaction.php", { - action: 'create', + action: 'add', element: 'order', transaction_id: id_value }, diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ce423163812..cc25b482075 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1019,46 +1019,47 @@ class Product extends CommonObject { $result = $this->db->fetch_array($result); - $this->id = $result["rowid"]; - $this->ref = $result["ref"]; - $this->libelle = $result["label"]; - $this->description = $result["description"]; - $this->note = $result["note"]; - $this->customcode = $result["customcode"]; - $this->country_id = $result["fk_country"]; - $this->country_code = getCountry($this->country_id,2,$this->db); - $this->price = $result["price"]; - $this->price_ttc = $result["price_ttc"]; - $this->price_min = $result["price_min"]; - $this->price_min_ttc = $result["price_min_ttc"]; - $this->price_base_type = $result["price_base_type"]; - $this->tva_tx = $result["tva_tx"]; + $this->id = $result["rowid"]; + $this->ref = $result["ref"]; + $this->libelle = $result["label"]; // TODO deprecated + $this->label = $result["label"]; + $this->description = $result["description"]; + $this->note = $result["note"]; + $this->customcode = $result["customcode"]; + $this->country_id = $result["fk_country"]; + $this->country_code = getCountry($this->country_id,2,$this->db); + $this->price = $result["price"]; + $this->price_ttc = $result["price_ttc"]; + $this->price_min = $result["price_min"]; + $this->price_min_ttc = $result["price_min_ttc"]; + $this->price_base_type = $result["price_base_type"]; + $this->tva_tx = $result["tva_tx"]; //! French VAT NPR - $this->tva_npr = $result["tva_npr"]; + $this->tva_npr = $result["tva_npr"]; //! Spanish local taxes - $this->localtax1_tx = $result["localtax1_tx"]; - $this->localtax2_tx = $result["localtax2_tx"]; + $this->localtax1_tx = $result["localtax1_tx"]; + $this->localtax2_tx = $result["localtax2_tx"]; - $this->type = $result["fk_product_type"]; - $this->status = $result["tosell"]; - $this->status_buy = $result["tobuy"]; - $this->finished = $result["finished"]; - $this->hidden = $result["hidden"]; - $this->duration = $result["duration"]; - $this->duration_value = substr($result["duration"],0,dol_strlen($result["duration"])-1); - $this->duration_unit = substr($result["duration"],-1); - $this->seuil_stock_alerte = $result["seuil_stock_alerte"]; - $this->canvas = $result["canvas"]; - $this->weight = $result["weight"]; - $this->weight_units = $result["weight_units"]; - $this->length = $result["length"]; - $this->length_units = $result["length_units"]; - $this->surface = $result["surface"]; - $this->surface_units = $result["surface_units"]; - $this->volume = $result["volume"]; - $this->volume_units = $result["volume_units"]; - $this->barcode = $result["barcode"]; - $this->barcode_type = $result["fk_barcode_type"]; + $this->type = $result["fk_product_type"]; + $this->status = $result["tosell"]; + $this->status_buy = $result["tobuy"]; + $this->finished = $result["finished"]; + $this->hidden = $result["hidden"]; + $this->duration = $result["duration"]; + $this->duration_value = substr($result["duration"],0,dol_strlen($result["duration"])-1); + $this->duration_unit = substr($result["duration"],-1); + $this->seuil_stock_alerte = $result["seuil_stock_alerte"]; + $this->canvas = $result["canvas"]; + $this->weight = $result["weight"]; + $this->weight_units = $result["weight_units"]; + $this->length = $result["length"]; + $this->length_units = $result["length_units"]; + $this->surface = $result["surface"]; + $this->surface_units = $result["surface_units"]; + $this->volume = $result["volume"]; + $this->volume_units = $result["volume_units"]; + $this->barcode = $result["barcode"]; + $this->barcode_type = $result["fk_barcode_type"]; $this->accountancy_code_buy = $result["accountancy_code_buy"]; $this->accountancy_code_sell= $result["accountancy_code_sell"];