Ajout patch oscommerce par ws

This commit is contained in:
Laurent Destailleur 2006-08-18 21:28:59 +00:00
parent f60eeb829f
commit cfb72166c6
4 changed files with 103 additions and 49 deletions

View File

@ -29,7 +29,7 @@ if ($action == '' && !$cancel) {
if ($_GET['custid'])
{
$osc_cust = new Osc_customer($_GET['custid']);
$osc_cust = new Osc_customer($db, $_GET['custid']);
$result = $osc_cust->fetch($_GET['custid']);
if ( !$result)
@ -75,9 +75,9 @@ if ($action == '' && !$cancel) {
*/
if (($_GET["action"] == 'import' ) && ( $_GET["custid"] != '' ) && $user->rights->produit->creer)
{
$osc_cust = new Osc_customer();
$osc_cust = new Osc_customer($db, $_GET['custid']);
$result = $osc_cust->fetch($_GET['custid']);
if ( !$result )
{
$societe = new Societe($db);
@ -109,7 +109,10 @@ if ($action == '' && !$cancel) {
if ($id == 0)
{
print '<br>création réussie nouveau client/prospect '.$id.' nom : '.$societe->nom.'</br>';
print '<br>création réussie nouveau client/prospect '.$societe->id.' nom : '.$societe->nom.'</br>';
$res = $osc_cust->transcode($osc_cust->osc_custid,$societe->id);
print '<br>transcode '.$res.' | '.$societe->id.' osc : '.$osc_cust->osc_custid.'</br>';
}
else
{
@ -134,9 +137,8 @@ if ($action == '' && !$cancel) {
{
$res = $societe->update($idp, $user);
if ($res < 0) print '<br>Erreur update '.$idp.'</br>';
$res = $osc_cust->transcode($osc_cust->custid,$idp);
$res = $osc_cust->transcode($osc_cust->custid,$idp );
if ($res < 0) print '<br>Erreur update '.$idp.'</br>';
}
else print '<br>update impossible $id : '.$idp.' </br>';
}

View File

@ -32,6 +32,7 @@
\brief Classe permettant la gestion des clients/prospects issus d'une base OSC
*/
class Osc_customer
{
var $db;
@ -56,13 +57,16 @@ class Osc_customer
* \brief Constructeur de la classe
* \param id Id client (0 par defaut)
*/
function Osc_customer($id=0) {
function Osc_customer($DB, $id=0) {
global $langs;
global $conf;
$this->osc_custid = $id ;
/* les initialisations nécessaires */
$this->db = $DB;
}
@ -133,27 +137,27 @@ class Osc_customer
* \param socidp champ société.idp
* \return int <0 si ko, >0 si ok
*/
function transcode($oscid, $socidp)
function transcode($oscid, $socidp )
{
global $conf;
print "entree transcode <br>";
/* suppression et insertion */
$sql = "DELETE FROM ".MAIN_DB_PREFIX." osc_customer WHERE osc_custid = ".$oscid;
$this->$db = $DB;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."osc_customer WHERE osc_custid = ".$oscid.";";
$result=$this->db->query($sql);
if ($result)
{
print "suppression ok ".$result;
print "suppression ok ".$sql." * ".$result;
}
else
{
print "suppression rate ".$result;
print "suppression rate ".$sql." * ".$result;
dolibarr_syslog("osc_customer::transcode echec suppression");
// $this->db->rollback();
// return -1;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX." osc_customer VALUES (".$oscid." , CURDATE() , ".$socidp.")";
$this->$db = $DB;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."osc_customer VALUES (".$oscid." , now() , ".$socidp.") ;";
$result=$this->db->query($sql);
if ($result)
{
@ -168,6 +172,16 @@ class Osc_customer
}
return 0;
}
// converti le client osc en client dolibarr
function get_clientid($osc_client)
{
$sql = "SELECT doli_socidp FROM ".MAIN_DB_PREFIX."osc_customer WHERE osc_custid = ".$osc_client.";";
$result=$this->db->query($sql);
$row = $this->db->fetch_row($resql);
// test d'erreurs
return $row[0];
}
}

View File

@ -22,6 +22,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");
llxHeader();
@ -29,7 +30,7 @@ if ($action == '' && !$cancel) {
if ($_GET["orderid"])
{
$osc_order = new Osc_order($_GET["orderid"]);
$osc_order = new Osc_order($db, $_GET["orderid"]);
$result = $osc_order->fetch($_GET["orderid"]);
if ( !$result)
@ -70,46 +71,23 @@ if ($action == '' && !$cancel) {
print "Error";
}
}
/* action Import création de l'objet product de dolibarr
/* action Import création de l'objet commande de dolibarr
*
*/
if (($_GET["action"] == 'import' ) && ( $_GET["orderid"] != '' ) && $user->rights->commande->creer)
{
$osc_order = new osc_order();
$osc_order = new osc_order($db);
$result = $osc_order->fetch($_GET["orderid"]);
print '<br>on passe 1</br>';
if ( !$result )
{
$commande = new Commande($db);
if ($_error == 1)
{
print '<br>erreur 1</br>';
exit;
}
print '<br>on passe 2</br>';
/* initialisation */
$societe->nom = $osc_order->osc_ordersoc.' '.$osc_order->osc_orderlastname;
$societe->adresse = $osc_order->osc_cutstreet;
$societe->cp = $osc_order->osc_orderpostcode;
$societe->ville = $osc_order->osc_ordercity;
$societe->departement_id = 0;
$societe->pays_code = $osc_order->osc_ordercodecountry;
$societe->tel = $osc_order->osc_ordertel;
$societe->fax = $osc_order->osc_orderfax;
$societe->email = $osc_order->osc_ordermail;
/* on force */
$societe->url = '';
$societe->siren = '';
$societe->siret = '';
$societe->ape = '';
$societe->client = 1; // mettre 0 si prospect
}
print '<br>on passe 3</br>';
$id = $societe->create($user);
$commande = $osc_order->osc2dolibarr($_GET["orderid"]);
print_r($commande);
}
$id = $commande->create($user);
if ($id > 0)
{
print '<br>création réussie nouveau client/prospect '.$id.' nom : '.$societe->nom.'</br>';
print '<br>création réussie nouvelle commande '.$id;
if ($id > 0) exit;
}
else

View File

@ -27,6 +27,11 @@
*/
require("../clients/osc_customer.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
/**
\class Osc_order
\brief Classe permettant la gestion des commandes issues d'une base OSC
@ -34,6 +39,8 @@
class Osc_order
{
var $db;
var $osc_orderid;
var $osc_custid; //identifant du client osc
var $osc_custname;
@ -41,18 +48,20 @@ class Osc_order
var $osc_ordertotal;
var $osc_orderpaymet;
var $osc_lines = array();
var $error;
/**
* \brief Constructeur de la classe
* \param id Id client (0 par defaut)
*/
function Osc_order($id=0) {
function Osc_order($DB, $id=0) {
global $langs;
$this->osc_orderid = $id ;
$this->db = $DB;
/* les initialisations nécessaires */
}
@ -102,6 +111,17 @@ class Osc_order
$this->osc_orderdate = $obj[0][date_purchased];
$this->osc_ordertotal = $obj[0][value];
$this->osc_orderpaymet = $obj[0][payment_method];
for ($i=1;$i<count($obj);$i++) {
// les lignes
$this->osc_lines[$i-1][products_id] = $obj[$i][products_id];
$this->osc_lines[$i-1][products_name] = $obj[$i][products_name];
$this->osc_lines[$i-1][products_price] = $obj[$i][products_price];
$this->osc_lines[$i-1][final_price] = $obj[$i][final_price];
$this->osc_lines[$i-1][products_tax] = $obj[$i][products_tax];
$this->osc_lines[$i-1][quantity] = $obj[$i][quantity];
}
}
else {
$this->error = 'Erreur '.$err ;
@ -109,6 +129,46 @@ class Osc_order
}
return 0;
}
// renvoie un objet commande dolibarr
function osc2dolibarr($osc_orderid)
{
$result = $this->fetch($osc_orderid);
if ( !$result )
{
$commande = new Commande($this->db);
if ($_error == 1)
{
print '<br>erreur 1</br>';
exit;
}
/* initialisation */
$oscclient = new Osc_Customer($this->db);
$clientid = $oscclient->get_clientid($this->osc_custid);
$commande->socidp = $clientid;
$commande->ref = $this->osc_orderid;
$commande->date = $this->orderdate;
/* on force */
$commande->statut = 0; //à voir
$commande->source = 0; // à vérifier
//les lignes
print "<br> nombre : " . count($this->osc_lines);
for ($i = 0; $i < sizeof($this->osc_lines);$i++) {
$commande->lines[$i]->libelle = $this->osc_lines[$i][products_id];
$commande->lines[$i]->desc = $this->osc_lines[$i][products_name];
$commande->lines[$i]->price = $this->osc_lines[$i][products_price];
$commande->lines[$i]->qty = $this->osc_lines[$i][quantity];
$commande->lines[$i]->tva_tx = $this->osc_lines[$i][products_tax];
// $commande->lines[$i]->fk_product;
$commande->lines[$i]->remise_percent = 0; // à calculer avec le finalprice
}
return $commande;
}
}
}