From 45101fcd521aa2cba6350b450e7c14bac3625bc9 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 16 Mar 2007 21:26:26 +0000
Subject: [PATCH] Patch jean
---
htdocs/oscommerce_ws/commandes/fiche.php | 32 +++++-
htdocs/oscommerce_ws/commandes/index.php | 6 +-
.../commandes/osc_order.class.php | 24 ++++-
htdocs/oscommerce_ws/includes/configure.php | 20 +++-
htdocs/oscommerce_ws/index.php | 22 +++--
htdocs/oscommerce_ws/produits/fiche.php | 64 ++++++------
.../produits/osc_product.class.php | 31 +++++-
.../ws_server/includes/configure.php | 8 +-
.../oscommerce_ws/ws_server/ws_articles.php | 3 +-
.../oscommerce_ws/ws_server/ws_customers.php | 3 +-
htdocs/oscommerce_ws/ws_server/ws_orders.php | 97 ++++++++++---------
htdocs/oscommerce_ws/ws_server/ws_test.php | 44 ++++-----
12 files changed, 221 insertions(+), 133 deletions(-)
diff --git a/htdocs/oscommerce_ws/commandes/fiche.php b/htdocs/oscommerce_ws/commandes/fiche.php
index 722fec0a760..299cad0d23f 100644
--- a/htdocs/oscommerce_ws/commandes/fiche.php
+++ b/htdocs/oscommerce_ws/commandes/fiche.php
@@ -23,6 +23,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
require_once("../includes/configure.php");
require_once("../clients/osc_customer.class.php");
+require_once("../produits/osc_product.class.php");
llxHeader();
@@ -35,14 +36,22 @@ if ($action == '' && !$cancel) {
if ( !$result)
{
+ $osc_prod = new Osc_Product($db);
print 'Fiche commande OSC : '.$osc_order->osc_orderid.'
';
print '';
print '|
client OSC | '.$osc_order->osc_custid.' | ';
print '|
Nom client | '.$osc_order->osc_custname.' | ';
- print '|
Montant | '.$osc_order->osc_ordertotal.' | ';
+ print '|
Montant | '.convert_price($osc_order->osc_ordertotal).' | ';
print '|
Date commande | '.$osc_order->osc_orderdate.' | ';
print '|
Méthode de paiement | '.$osc_order->osc_orderpaymet.' | ';
+ print "
";
+ print '';
+ // les articles
+ for ($l=0;$l < sizeof($osc_order->osc_lines); $l++)
+ {
+ print '| '.$osc_order->osc_lines[$l]["products_id"].' | '.$osc_prod->get_productid($osc_order->osc_lines[$l]["products_id"]).' | '.$osc_order->osc_lines[$l]["products_name"].' | '.convert_price($osc_order->osc_lines[$l]["products_price"]).' | '.$osc_order->osc_lines[$l]["quantity"].' |
';
+ }
print "
";
/* ************************************************************************** */
@@ -87,7 +96,8 @@ if ($action == '' && !$cancel) {
if ( !$result )
{
$commande = $osc_order->osc2dolibarr($_GET["orderid"]);
- }
+ }
+
/* utilisation de la table de transco*/
if ($osc_order->get_orderid($osc_order->osc_orderid)>0)
{
@@ -141,8 +151,19 @@ if ($action == '' && !$cancel) {
}
}
}
-
- $id = $commande->create($user);
+// vérifier l'existence des produits commandés
+ $osc_product = new Osc_Product($db);
+ $err = 0;
+
+ for ($lig = 0; $lig < sizeof($commande->lines); $lig++)
+ {
+ if (! $commande->lines[$lig]->fk_product) $err ++;
+ }
+ if ($err > 0) {
+ print (" Des produits de la commande sont inexistants
");
+ $id =-9;
+ }
+ else $id = $commande->create($user);
if ($id > 0)
{
@@ -150,7 +171,7 @@ if ($action == '' && !$cancel) {
print '
création réussie nouvelle commande '.$id;
$res = $osc_order->transcode($osc_order->osc_orderid,$id);
print 'pour la commande osc : '.$osc_order->osc_orderid.'
';
- print '';
-print '| '.$langs->trans("Description").' | ';
+print '
| '.$langs->trans("année").' | ';
+print ''.$langs->trans("mois").' | ';
print ''.$langs->trans("Total").' |
';
// Call the WebService and store its result in $result.
$result = $client->call("get_CAmensuel",$parameters );
if ($client->fault) {
dolibarr_print_error('',"Erreur de connection ");
+ print_r($client->faultstring);
}
elseif (!($err = $client->getError()) )
{
@@ -80,8 +83,9 @@ elseif (!($err = $client->getError()) )
{
$var=!$var;
print "";
- print '| '.$result[$i][mois].' | ';
- print ''.price($result[$i][value]).' | ';
+ print ''.$result[$i][an].' | ';
+ print ''.$result[$i][mois].' | ';
+ print ''.convert_price($result[$i][value]).' | ';
print "
\n";
$i++;
@@ -127,7 +131,7 @@ elseif (!($err = $client->getError()) ) {
while ($i < $num) {
$var=!$var;
print "";
- print '| '.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.price($result[$i][value]).' | '.$result[$i][payment_method].' |
';
+ print ''.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.convert_price($result[$i][value]).' | '.$result[$i][payment_method].' | ';
$i++;
}
}
@@ -163,10 +167,10 @@ elseif (!($err = $client->getError()) ) {
$num = min($num,OSC_MAXNBCOM);
while ($i < $num) {
- print "";
- print '| '.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.price($result[$i][value]).' | '.$result[$i][payment_method].' |
';
- $i++;
$var=!$var;
+ print "";
+ print '| '.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.convert_price($result[$i][value]).' | '.$result[$i][payment_method].' |
';
+ $i++;
}
}
}
@@ -201,7 +205,7 @@ elseif (!($err = $client->getError()) ) {
while ($i < $num) {
print "";
- print '| '.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.price($result[$i][value]).' | '.$result[$i][payment_method].' |
';
+ print ''.$result[$i][orders_id].' | '.$result[$i][customers_name].' | '.convert_price($result[$i][value]).' | '.$result[$i][payment_method].' | ';
$i++;
$var=!$var;
}
@@ -240,7 +244,7 @@ elseif (!($err = $client->getError()) ) {
while ($i < $num) {
print "";
- print "| ".$result[$i][date_purchased]." | ".$result[$i][customers_name]." | ".$result[$i][delivery_country]." | ".price($result[$i][value])." | ".$result[$i][payment_method]." | ".$result[$i][orders_id]." | ".$result[$i][statut]." |
";
+ print "".$result[$i][date_purchased]." | ".$result[$i][customers_name]." | ".$result[$i][delivery_country]." | ".convert_price($result[$i][value])." | ".$result[$i][payment_method]." | ".$result[$i][orders_id]." | ".$result[$i][statut]." | ";
$i++;
$var=!$var;
}
diff --git a/htdocs/oscommerce_ws/produits/fiche.php b/htdocs/oscommerce_ws/produits/fiche.php
index 119a12a911f..27ba76fe580 100644
--- a/htdocs/oscommerce_ws/produits/fiche.php
+++ b/htdocs/oscommerce_ws/produits/fiche.php
@@ -88,17 +88,7 @@ if ($action == '' && !$cancel) {
print '
erreur 1';
// exit;
}
- /* initialisation */
- $product->ref = $osc_prod->osc_ref;
- $product->libelle = $osc_prod->osc_name;
- $product->description = $osc_prod->osc_desc;
- $product->price = $osc_prod->osc_price;
- $product->tva_tx = $osc_prod->osc_tva;
- $product->type = 0;
- $product->seuil_stock_alerte = 0; /* on force */
- /* on force */
- $product->catid = 0; /* à voir avec la gestion des catégories */
- $product->status = 1; /* en vente */
+ $product = $osc_prod->osc2dolibarr($_GET['id']);
}
/* utilisation de la table de transco*/
@@ -106,7 +96,8 @@ if ($action == '' && !$cancel) {
{
print 'Ce produit existe déjà
';
}
- else {
+ else
+ {
$id = $product->create($user);
if ($id > 0)
@@ -129,31 +120,36 @@ if ($action == '' && !$cancel) {
$_GET["action"] = "create";
$_GET["type"] = $_POST["type"];
}
- if ($id == -2)
- {
- /* la référence existe on fait un update */
- $product_control = new Product($db);
- if ($_error == 1)
- {
- print '
erreur 1';
- exit;
- }
- $id = $product_control->fetch($ref = $osc_prod->osc_ref);
+ if ($id == -2)
+ {
+ /* la référence existe on fait un update */
+ $product_control = new Product($db);
+ if ($_error == 1)
+ {
+ print '
erreur 1';
+ // exit;
+ }
+ $id = $product_control->fetch($ref = $osc_prod->osc_ref);
- if ($id > 0)
- {
- $id = $product->update($id, $user);
- if ($id > 0) {
- $id_entrepot = 1;
- $id = $product->correct_stock($id_entrepot,$osc_prod->osc_stock);
+ if ($id > 0)
+ {
+ $id = $product->update($id, $user);
+ if ($id > 0)
+ {
+ $id_entrepot = 1;
+ $id = $product->correct_stock($user, $id_entrepot,$osc_prod->osc_stock, 0);
+ }
+ else print '
Erreur update '.$product->error().'';
}
- else print '
Erreur update '.$id.'';
+ else print '
update impossible $id : '.$product_control->error().' ';
}
- else print '
update impossible $id : '.$id.' ';
- }
- }
- }
-
+ if ($id == -1)
+ {
+ print 'erreur'.$product->error().'
';
+ }
+ print ''.$langs->trans("Retour").'
';
+ }
+ }
}
llxFooter('$Date$ - $Revision$');
diff --git a/htdocs/oscommerce_ws/produits/osc_product.class.php b/htdocs/oscommerce_ws/produits/osc_product.class.php
index 2a6b752887a..adb9a72b93b 100644
--- a/htdocs/oscommerce_ws/produits/osc_product.class.php
+++ b/htdocs/oscommerce_ws/produits/osc_product.class.php
@@ -116,6 +116,35 @@ class Osc_product
return 0;
}
+// renvoie un objet commande dolibarr
+ function osc2dolibarr($osc_productid)
+ {
+
+ $result = $this->fetch($osc_productid);
+ if ( !$result )
+ {
+ $product = new Product($this->db);
+ if ($_error == 1)
+ {
+ print '
erreur 1';
+ return '';
+ }
+ /* initialisation */
+ $product->ref = $this->osc_ref;
+ $product->libelle = $this->osc_name;
+ $product->description = $this->osc_desc;
+ $product->price = convert_price($this->osc_price);
+ $product->tva_tx = $this->osc_tva;
+ $product->type = 0;
+ $product->seuil_stock_alerte = 0; /* on force */
+ /* on force */
+ $product->catid = 0; /* à voir avec la gestion des catégories */
+ $product->status = 1; /* en vente */
+
+ return $product;
+ }
+
+ }
/**
* \brief Mise à jour de la table de transition
* \param oscid Id du produit dans OsC
@@ -157,7 +186,7 @@ class Osc_product
}
return 0;
}
-// converti le client osc en client dolibarr
+// converti le produit osc en produit dolibarr
function get_productid($osc_product)
{
diff --git a/htdocs/oscommerce_ws/ws_server/includes/configure.php b/htdocs/oscommerce_ws/ws_server/includes/configure.php
index e3eec2b7272..da209f33675 100644
--- a/htdocs/oscommerce_ws/ws_server/includes/configure.php
+++ b/htdocs/oscommerce_ws/ws_server/includes/configure.php
@@ -7,10 +7,10 @@
----------------------------------------------*/
/* paramètres de connexion à OSC */
-define("OSC_DB_SERVER","");
-define("OSC_DB_SERVER_USERNAME", "");
-define("OSC_DB_SERVER_PASSWORD", "");
-define("OSC_DB_DATABASE", "");
+define("DB_SERVER","localhost");
+define("DB_SERVER_USERNAME", "root");
+define("DB_SERVER_PASSWORD", "");
+define("DB_DATABASE", "tahitirimai");
/* constantes utiles */
define("OSC_LANGUAGE_ID",1);
diff --git a/htdocs/oscommerce_ws/ws_server/ws_articles.php b/htdocs/oscommerce_ws/ws_server/ws_articles.php
index 197237390bd..4d04e3285e7 100644
--- a/htdocs/oscommerce_ws/ws_server/ws_articles.php
+++ b/htdocs/oscommerce_ws/ws_server/ws_articles.php
@@ -29,9 +29,10 @@ require_once('./lib/nusoap.php');
// Create the soap Object
$s = new soap_server;
-$ns='oscommerce';
+/* $ns='oscommerce';
$s->configureWSDL('WebServicesOSCommerceForDolibarr',$ns);
$s->wsdl->schemaTargetNamespace=$ns;
+*/
// Register a method available for clients
$s->register('get_article');
diff --git a/htdocs/oscommerce_ws/ws_server/ws_customers.php b/htdocs/oscommerce_ws/ws_server/ws_customers.php
index 6998f267225..d8db1cd5e44 100644
--- a/htdocs/oscommerce_ws/ws_server/ws_customers.php
+++ b/htdocs/oscommerce_ws/ws_server/ws_customers.php
@@ -29,9 +29,10 @@ require_once('./includes/configure.php');
// Create the soap Object
$s = new soap_server;
-$ns='oscommerce';
+/* $ns='oscommerce';
$s->configureWSDL('WebServicesOSCommerceForDolibarr',$ns);
$s->wsdl->schemaTargetNamespace=$ns;
+*/
// Register the methods available for clients
$s->register('get_Client');
diff --git a/htdocs/oscommerce_ws/ws_server/ws_orders.php b/htdocs/oscommerce_ws/ws_server/ws_orders.php
index 018896a1388..3342ed07550 100644
--- a/htdocs/oscommerce_ws/ws_server/ws_orders.php
+++ b/htdocs/oscommerce_ws/ws_server/ws_orders.php
@@ -1,4 +1,4 @@
-
*
*
@@ -19,24 +19,21 @@
* $Source$
*
*/
-set_magic_quotes_runtime(0);
-
-// Soap Server.
-require_once('./lib/nusoap.php');
+set_magic_quotes_runtime(0);
+
+// Soap Server.
+require_once('./lib/nusoap.php');
require_once('./includes/configure.php');
-
-// Create the soap Object
-$s = new soap_server;
-$ns='oscommerce';
-$s->configureWSDL('WebServicesOSCommerceForDolibarr',$ns);
-$s->wsdl->schemaTargetNamespace=$ns;
-
-// Register the methods available for clients
+
+// Create the soap Object
+$s = new soap_server;
+
+// Register the methods available for clients
$s->register('get_CAmensuel');
$s->register('get_orders');
$s->register('get_lastOrderClients');
-$s->register('get_Order');
+$s->register('get_Order');
/*----------------------------------------------
* renvoie un tableau avec le CA mensuel réalisé
@@ -44,22 +41,23 @@ $s->register('get_Order');
function get_CAmensuel() {
//on se connecte
- if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
+ if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
if (!($db = mysql_select_db(DB_DATABASE, $connexion))) return new soap_fault("Server", "MySQL 2", mysql_error());
//la requête
- $sql = "SELECT sum(t.value) as value, MONTH(o.date_purchased) as mois";
+ $sql = "SELECT sum(t.value) as value, MONTH(o.date_purchased) as mois, YEAR(o.date_purchased) as an";
$sql .= " FROM orders_total as t";
$sql .= " JOIN orders as o ON o.orders_id = t.orders_id";
- $sql .= " WHERE t.class = 'ot_subtotal' AND YEAR(o.date_purchased) = YEAR(now()) ";
- $sql .= " GROUP BY mois ORDER BY mois";
+ $sql .= " WHERE t.class = 'ot_subtotal' ";
+//AND YEAR(o.date_purchased) = YEAR(now()) ";
+ $sql .= " GROUP BY an, mois ORDER BY an desc ,mois desc limit 1,12";
if (!($resquer = mysql_query($sql,$connexion))) return new soap_fault("Server", "MySQL 3 ".$sql, mysql_error());
- switch ($numrows = mysql_numrows($resquer)) {
- case 0 :
- return new soap_fault("Server", "MySQL 4", "produit inexistant");
- break;
+ switch ($numrows = mysql_numrows($resquer)) {
+ case 0 :
+ return new soap_fault("Server", "MySQL 4", $sql);
+ break;
default :
$i = 0;
while ( $i < $numrows) {
@@ -76,7 +74,7 @@ return $result;
function get_orders($limit='', $status='') {
//on se connecte
- if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
+ if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
if (!($db = mysql_select_db(DB_DATABASE, $connexion))) return new soap_fault("Server", "MySQL 2", mysql_error());
//on recherche
@@ -90,10 +88,10 @@ if ($limit > 0) $sql .= " LIMIT ".$limit;
if (!($resquer = mysql_query($sql,$connexion))) return new soap_fault("Server", "MySQL 3 ".$sql, mysql_error());
$result ='';
- switch ($numrows = mysql_numrows($resquer)) {
- case 0 :
+ switch ($numrows = mysql_numrows($resquer)) {
+ case 0 :
//return new soap_fault("Server", "MySQL 4", "produit inexistant");
- break;
+ break;
default :
$i = 0;
while ( $i < $numrows) {
@@ -111,23 +109,23 @@ return $result;
function get_lastOrderClients($id='',$name='',$limit='') {
//on se connecte
- if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
+ if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
if (!($db = mysql_select_db(DB_DATABASE, $connexion))) return new soap_fault("Server", "MySQL 2", mysql_error());
//on recherche
$sql = "SELECT o.orders_id, o.customers_name, o.delivery_country, o.date_purchased, t.value, s.orders_status_name as statut";
$sql .= " FROM orders_total as t JOIN orders as o on o.orders_id = t.orders_id ";
$sql .= " JOIN orders_status as s on o.orders_status = s.orders_status_id and s.language_id = 1";
- $sql .= " WHERE t.class = 'ot_subtotal' order by o.date_purchased desc";
+ $sql .= " WHERE t.class = 'ot_subtotal' and o.orders_status < 5 order by o.date_purchased desc";
if ($limit > 0) $sql .= " LIMIT ".$limit;
if (!($resquer = mysql_query($sql,$connexion))) return new soap_fault("Server", "MySQL 3 ".$sql, mysql_error());
$result ='';
- switch ($numrows = mysql_numrows($resquer)) {
- case 0 :
+ switch ($numrows = mysql_numrows($resquer)) {
+ case 0 :
return new soap_fault("Server", "MySQL 4", "produit inexistant");
- break;
+ break;
default :
$i = 0;
while ( $i < $numrows) {
@@ -147,24 +145,31 @@ function get_Order($orderid="0")
{
//on se connecte
- if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
+ if (!($connexion = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD))) return new soap_fault("Server", "MySQL 1", "connection impossible");
if (!($db = mysql_select_db(DB_DATABASE, $connexion))) return new soap_fault("Server", "MySQL 2", mysql_error());
//on recherche la commande
-$sql = "SELECT o.orders_id, o.customers_name, o.customers_id, o.date_purchased, t.value, o.payment_method ";
+/*$sql = "SELECT o.orders_id, o.customers_name, o.customers_id, o.date_purchased, t.value, o.payment_method ";
$sql .= " FROM orders_total as t JOIN orders as o on o.orders_id = t.orders_id ";
$sql .= " WHERE t.class = 'ot_subtotal'";
-if ($orderid > 0) $sql .= " and o.orders_id = ".$orderid;
+*/
+$sql = "SELECT o.orders_id, o.customers_name, o.customers_id, o.date_purchased, o.payment_method, t.value as total, sum(p.value) as port, s.orders_status_name as statut ";
+$sql .= " FROM orders as o ";
+$sql .= " JOIN orders_total as t on o.orders_id = t.orders_id and t.class = 'ot_subtotal' ";
+$sql .= " JOIN orders_total as p on o.orders_id = p.orders_id and (p.class = 'ot_shipping' OR p.class = 'ot_fixed_payment_chg') ";
+$sql .= " JOIN orders_status as s on o.orders_status = s.orders_status_id and s.language_id = 1";
+$sql .= " WHERE o.orders_status < 5 "; // élimine les commandes annulées, remboursées
+if ($orderid > 0) $sql .= " AND o.orders_id = ".$orderid;
+$sql .= " GROUP BY p.orders_id ";
$sql .= " ORDER BY o.date_purchased desc";
-
if (!($resquer = mysql_query($sql,$connexion))) return new soap_fault("Server", "MySQL 3 ".$sql, mysql_error());
$result ='';
- switch ($numrows = mysql_numrows($resquer)) {
- case 0 :
- return new soap_fault("Server", "MySQL 4", "commande inexistante");
- break;
+ switch ($numrows = mysql_numrows($resquer)) {
+ case 0 :
+ return new soap_fault("Server", "MySQL 4", "commande inexistante ".$sql);
+ break;
default :
$i = 0;
while ( $i < $numrows) {
@@ -185,10 +190,10 @@ if ($orderid > 0)
if (!($resquer = mysql_query($sql,$connexion))) return new soap_fault("Server", "MySQL 3 ".$sql, mysql_error());
- switch ($numrows = mysql_numrows($resquer)) {
- case 0 :
+ switch ($numrows = mysql_numrows($resquer)) {
+ case 0 :
return new soap_fault("Server", "MySQL 5", "commande sans articles");
- break;
+ break;
default :
while ( $i < $numrows) {
@@ -203,8 +208,8 @@ mysql_close($connexion);
return $result;
}
-
-// Return the results.
+
+// Return the results.
$s->service($HTTP_RAW_POST_DATA);
-
-?>
+
+?>
diff --git a/htdocs/oscommerce_ws/ws_server/ws_test.php b/htdocs/oscommerce_ws/ws_server/ws_test.php
index a9d33d13685..d53f8f4bdac 100644
--- a/htdocs/oscommerce_ws/ws_server/ws_test.php
+++ b/htdocs/oscommerce_ws/ws_server/ws_test.php
@@ -1,25 +1,25 @@
-configureWSDL('WebServicesOSCommerceForDolibarr',$ns);
$s->wsdl->schemaTargetNamespace=$ns;
-
-// Register a method available for clients
-$s->register('hello');
-
-function hello($name){
-
-$returnedString = "Hello de Tetiaroa ".$name." !";
-return $returnedString;
-
-}
-
-// Return the results.
-$s->service($HTTP_RAW_POST_DATA);
-?>
+
+// Register a method available for clients
+$s->register('hello');
+
+function hello($name){
+
+$returnedString = "Hello de Tetiaroa ".$name." !";
+return $returnedString;
+
+}
+
+// Return the results.
+$s->service($HTTP_RAW_POST_DATA);
+?>