From 3299e5f88906bab19d6d53aa86ead716d4bd2648 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 26 Mar 2017 19:13:10 +0200 Subject: [PATCH 001/279] PRODUCT_PRICE_SUPPLIER_NO_LOG test inverted if PRODUCT_PRICE_SUPPLIER_NO_LOG is empty, no log is stored if PRODUCT_PRICE_SUPPLIER_NO_LOG is not empty log is stored they are inversion @eldy maybe add more field in this table --- htdocs/fourn/class/fournisseur.product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index eaff46ddc2c..94034408e49 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -310,7 +310,7 @@ class ProductFournisseur extends Product $error++; } - if (! $error && ! empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) { + if (! $error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) { // Add record into log table $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price_log("; $sql .= "datec, fk_product_fournisseur,fk_user,price,quantity)"; From d8018f7937c2ae4c9a499df2eae9591876461735 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 26 Mar 2017 19:16:19 +0200 Subject: [PATCH 002/279] add trigger on product price add/update --- .../product/class/productcustomerprice.class.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index fd36c55dcf9..9c2ce3e99d2 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -669,15 +669,12 @@ class Productcustomerprice extends CommonObject if (! $error) { if (! $notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - // // Call triggers - // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - // $interface=new Interfaces($this->db); - // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - // if ($result < 0) { $error++; $this->errors=$interface->errors; } - // // End call triggers + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('CUSTOMER_PRODUCT_SELLPRICE_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // End call triggers } } From d60f1d8402a085c54953af11471016f0383689a7 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 26 Mar 2017 19:29:16 +0200 Subject: [PATCH 003/279] add price_level on product_customer_price_log fk_soc can be 0 when generic price is stored on log --- htdocs/install/mysql/tables/llx_product_customer_price_log.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_product_customer_price_log.sql b/htdocs/install/mysql/tables/llx_product_customer_price_log.sql index 699060cdc98..1d728dd2486 100644 --- a/htdocs/install/mysql/tables/llx_product_customer_price_log.sql +++ b/htdocs/install/mysql/tables/llx_product_customer_price_log.sql @@ -24,7 +24,8 @@ create table llx_product_customer_price_log entity integer DEFAULT 1 NOT NULL, -- multi company id datec datetime, fk_product integer NOT NULL, - fk_soc integer NOT NULL, + fk_soc integer DEFAULT 0 NOT NULL, + price_level smallint NULL DEFAULT 1, price double(24,8) DEFAULT 0, price_ttc double(24,8) DEFAULT 0, price_min double(24,8) DEFAULT 0, From 9871bc3d9a006e6275eebbdaf6c0a6f78ad1bc92 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 26 Mar 2017 19:35:00 +0200 Subject: [PATCH 004/279] Update 5.0.0-6.0.0.sql --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 25145dc7cfe..bdc2630a4c4 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -25,6 +25,8 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); +ALTER TABLE llx_product_customer_price_log ADD COLUMN price_level smallint default 1; + ALTER TABLE llx_ecm_files ADD COLUMN ref varchar(128) AFTER rowid; ALTER TABLE llx_ecm_files CHANGE COLUMN fullpath filepath varchar(255); ALTER TABLE llx_ecm_files CHANGE COLUMN filepath filepath varchar(255); From dcc3febf6f99fdcc70580aee153bd41396a7c3a7 Mon Sep 17 00:00:00 2001 From: Darkjeff Date: Thu, 20 Jul 2017 18:22:53 +0200 Subject: [PATCH 005/279] add bookkkeeping in report turnover --- htdocs/compta/stats/index.php | 42 +++++++++++++++++++++++++++++----- htdocs/langs/fr_FR/compta.lang | 1 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 19c106a44dc..0c4a16edf7b 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -1,7 +1,8 @@ - * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2017 Olivier Geffroy * * 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 @@ -62,6 +63,7 @@ if ($modecompta=="CREANCES-DETTES") $nom=$langs->trans("SalesTurnover"); $calcmode=$langs->trans("CalcModeDebt"); $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode",'','').')'; $period="$year_start - $year_end"; $periodlink=($year_start?"".img_previous()." ".img_next()."":""); $description=$langs->trans("RulesCADue"); @@ -70,10 +72,12 @@ if ($modecompta=="CREANCES-DETTES") $builddate=time(); //$exportlink=$langs->trans("NotYetAvailable"); } -else { +else if ($modecompta=="RECETTES-DEPENSES") +{ $nom=$langs->trans("SalesTurnover"); $calcmode=$langs->trans("CalcModeEngagement"); $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + $calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode",'','').')'; $period="$year_start - $year_end"; $periodlink=($year_start?"".img_previous()." ".img_next()."":""); $description=$langs->trans("RulesCAIn"); @@ -81,6 +85,20 @@ else { $builddate=time(); //$exportlink=$langs->trans("NotYetAvailable"); } +else if ($modecompta=="BOOKKEEPING") +{ + $nom=$langs->trans("BookkeepingTurnover"); + $calcmode=$langs->trans("CalcModeBookkeeping"); + $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $period="$year_start - $year_end"; + $periodlink=($year_start?"".img_previous()." ".img_next()."":""); + $description=$langs->trans("RulesCABookkeeping"); + $description.= $langs->trans("DepositsAreIncluded"); + $builddate=time(); + //$exportlink=$langs->trans("NotYetAvailable"); +} + $moreparam=array(); if (! empty($modecompta)) $moreparam['modecompta']=$modecompta; report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam,$calcmode); @@ -98,8 +116,10 @@ if ($modecompta == 'CREANCES-DETTES') $sql.= " WHERE f.fk_statut in (1,2)"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; else $sql.= " AND f.type IN (0,1,2,3,5)"; + $sql.= " AND f.entity = ".$conf->entity; +if ($socid) $sql.= " AND f.fk_soc = ".$socid; } -else +else if ($modecompta=="RECETTES-DEPENSES") { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les @@ -111,9 +131,19 @@ else $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= " WHERE p.rowid = pf.fk_paiement"; $sql.= " AND pf.fk_facture = f.rowid"; -} -$sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; +} +else if ($modecompta=="BOOKKEEPING") +{ + $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b"; + $sql.= " WHERE b.numero_compte IN (SELECT a.account_number" ; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_account as a"; + $sql.= " WHERE a.fk_accounting_category = 1 ) " ; // todo sql with accounting category, but we need to define category in turnover +} + + $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -481,7 +511,7 @@ print ''; $i++; } - print "Facture a encaisser : ".price($total_ttc_Rac)."<-- bug ici car n'exclut pas le deja r�gl� des factures partiellement r�gl�es"; + print "Facture a encaisser : ".price($total_ttc_Rac)."<-- bug ici car n'exclut pas le deja r?gl? des factures partiellement r?gl?es"; } $db->free($resql); } diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index ae51312a5f7..067a349aefd 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -130,6 +130,7 @@ AnnualByCompaniesDueDebtMode=Bilan des recettes et dépenses, détail par tiers AnnualByCompaniesInputOutputMode=Bilan des recettes et dépenses, détail par tiers SeeReportInInputOutputMode=Cliquer sur %sRecettes-Dépenses%s dit comptabilité de caisse pour un calcul sur les paiements effectivement réalisés SeeReportInDueDebtMode=Cliquer sur %sCréances-Dettes%s dit comptabilité d'engagement pour un calcul sur les factures émises +SeeReportInBookkeepingMode=Cliquer sur %sGrand Livre%s dit comptabilité avance pour un calcul sur les factures dans le grand livre RulesAmountWithTaxIncluded=- Les montants affichés sont les montants taxe incluse RulesResultDue=- Il comprend les factures impayées, les dépenses, la TVA, les dons qu'elles soient payées ou non. Il comprend également les salaires versés.
- Il est basé sur la date de validation de factures et de la TVA et à la date prévue pour les dépenses. Pour les salaires définis avec le module de salaire, la date de paiement de la valeur est utilisée. RulesResultInOut=- Il comprend les paiements réels effectués sur les factures, les dépenses, la TVA et les salaires.
- Il est basé sur les dates de paiement des factures, les dépenses, la TVA et les salaires. La date du don pour le don. From 2be75420caaf2e95a29585d3f73ae24194dd592e Mon Sep 17 00:00:00 2001 From: altatof Date: Mon, 7 Aug 2017 10:21:38 +0200 Subject: [PATCH 006/279] FIX : supplier id was not passed to hooks --- htdocs/fourn/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index d3c0fa7357d..ee6ac67412a 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -66,7 +66,7 @@ $hookmanager->initHooks(array('suppliercard','globalcard')); * Action */ -$parameters=array('socid'=>$socid); +$parameters=array('id'=>$id); $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); From 0bf4ac6fb3d592d5fc0d8d06535fd6b562e742dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Aug 2017 20:06:26 +0200 Subject: [PATCH 007/279] Add missing field fk_supplier_proposal --- htdocs/install/mysql/migration/3.9.0-4.0.0.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index f1c94f346cf..8880f3fae97 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -34,6 +34,7 @@ ALTER TABLE llx_product_customer_price ADD COLUMN localtax1_type varchar(10) NO ALTER TABLE llx_product_customer_price ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx; ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0' after localtax1_tx; ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx; +ALTER TABLE llx_supplier_proposaldet CHANGE COLUMN fk_askpricesupplier fk_supplier_proposal integer NOT NULL; ALTER TABLE llx_opensurvey_sondage ADD COLUMN status integer DEFAULT 1 after date_fin; From ca3cdfabec0886fbf24c2545a5b821bcf5f769ef Mon Sep 17 00:00:00 2001 From: fappels Date: Wed, 9 Aug 2017 14:15:26 +0200 Subject: [PATCH 008/279] FIX Best buy price calculation Best buy price also depends on buy discount. --- htdocs/fourn/class/fournisseur.product.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 34a11663e2a..4d155bbce5f 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -581,7 +581,8 @@ class ProductFournisseur extends Product foreach($record_array as $record) { $fourn_price = $record["price"]; - $fourn_unitprice = $record["unitprice"]; + // discount calculated buy price + $fourn_unitprice = $record["unitprice"] * (1 - $record["remise_percent"] / 100) + $record["unitcharges"] - $record["remise"]; if (!empty($conf->dynamicprices->enabled) && !empty($record["fk_supplier_price_expression"])) { $prod_supplier = new ProductFournisseur($this->db); $prod_supplier->product_fourn_price_id = $record["product_fourn_price_id"]; @@ -613,7 +614,7 @@ class ProductFournisseur extends Product $this->fourn_qty = $record["quantity"]; $this->fourn_remise_percent = $record["remise_percent"]; $this->fourn_remise = $record["remise"]; - $this->fourn_unitprice = $fourn_unitprice; + $this->fourn_unitprice = $record["unitprice"]; $this->fourn_charges = $record["charges"]; // deprecated $this->fourn_unitcharges = $record["unitcharges"]; // deprecated $this->fourn_tva_tx = $record["tva_tx"]; @@ -622,7 +623,7 @@ class ProductFournisseur extends Product $this->delivery_time_days = $record["delivery_time_days"]; $this->fk_supplier_price_expression = $record["fk_supplier_price_expression"]; $this->id = $prodid; - $min = $this->fourn_unitprice; + $min = $fourn_unitprice; } } } From 34a7c7667d442cc4374cf840c969dcbd30ed1c94 Mon Sep 17 00:00:00 2001 From: Norbert Penel Date: Fri, 11 Aug 2017 14:40:29 +0200 Subject: [PATCH 009/279] Add Dolistore module Explore and find dolistore modules directly in your Dolibarr --- htdocs/dolistore/ajax/image.php | 65 + .../class/PSWebServiceLibrary.class.php | 409 ++++ htdocs/dolistore/class/dolistore.class.php | 308 +++ htdocs/dolistore/class/init.php | 72 + .../core/modules/modDolistore.class.php | 159 ++ htdocs/dolistore/css/dolistore.css | 234 ++ htdocs/dolistore/img/Download-128.png | Bin 0 -> 761 bytes htdocs/dolistore/img/NoImageAvailable.png | Bin 0 -> 11231 bytes htdocs/dolistore/img/compatible.png | Bin 0 -> 2147 bytes htdocs/dolistore/img/dolistore.png | Bin 0 -> 11317 bytes htdocs/dolistore/img/follow.png | Bin 0 -> 2869 bytes htdocs/dolistore/img/object_dolistore.png | Bin 0 -> 1851 bytes htdocs/dolistore/index.php | 115 + htdocs/dolistore/js/dolistore.js.php | 79 + htdocs/dolistore/js/fancybox/blank.gif | Bin 0 -> 43 bytes .../js/fancybox/fancybox_loading.gif | Bin 0 -> 6567 bytes .../js/fancybox/fancybox_loading@2x.gif | Bin 0 -> 13984 bytes .../js/fancybox/fancybox_overlay.png | Bin 0 -> 1003 bytes .../dolistore/js/fancybox/fancybox_sprite.png | Bin 0 -> 1362 bytes .../js/fancybox/fancybox_sprite@2x.png | Bin 0 -> 6553 bytes .../js/fancybox/helpers/fancybox_buttons.png | Bin 0 -> 1080 bytes .../helpers/jquery.fancybox-buttons.css | 97 + .../helpers/jquery.fancybox-buttons.js | 122 + .../fancybox/helpers/jquery.fancybox-media.js | 201 ++ .../helpers/jquery.fancybox-thumbs.css | 55 + .../helpers/jquery.fancybox-thumbs.js | 165 ++ .../dolistore/js/fancybox/jquery.fancybox.css | 275 +++ .../dolistore/js/fancybox/jquery.fancybox.js | 2018 +++++++++++++++++ .../js/fancybox/jquery.fancybox.pack.js | 46 + htdocs/dolistore/langs/de_DE/dolistore.lang | 22 + htdocs/dolistore/langs/en_EN/dolistore.lang | 22 + htdocs/dolistore/langs/es_ES/dolistore.lang | 22 + htdocs/dolistore/langs/fr_FR/dolistore.lang | 22 + htdocs/dolistore/langs/it_IT/dolistore.lang | 22 + 34 files changed, 4530 insertions(+) create mode 100644 htdocs/dolistore/ajax/image.php create mode 100644 htdocs/dolistore/class/PSWebServiceLibrary.class.php create mode 100644 htdocs/dolistore/class/dolistore.class.php create mode 100644 htdocs/dolistore/class/init.php create mode 100644 htdocs/dolistore/core/modules/modDolistore.class.php create mode 100644 htdocs/dolistore/css/dolistore.css create mode 100644 htdocs/dolistore/img/Download-128.png create mode 100644 htdocs/dolistore/img/NoImageAvailable.png create mode 100644 htdocs/dolistore/img/compatible.png create mode 100644 htdocs/dolistore/img/dolistore.png create mode 100644 htdocs/dolistore/img/follow.png create mode 100644 htdocs/dolistore/img/object_dolistore.png create mode 100644 htdocs/dolistore/index.php create mode 100644 htdocs/dolistore/js/dolistore.js.php create mode 100644 htdocs/dolistore/js/fancybox/blank.gif create mode 100644 htdocs/dolistore/js/fancybox/fancybox_loading.gif create mode 100644 htdocs/dolistore/js/fancybox/fancybox_loading@2x.gif create mode 100644 htdocs/dolistore/js/fancybox/fancybox_overlay.png create mode 100644 htdocs/dolistore/js/fancybox/fancybox_sprite.png create mode 100644 htdocs/dolistore/js/fancybox/fancybox_sprite@2x.png create mode 100644 htdocs/dolistore/js/fancybox/helpers/fancybox_buttons.png create mode 100644 htdocs/dolistore/js/fancybox/helpers/jquery.fancybox-buttons.css create mode 100644 htdocs/dolistore/js/fancybox/helpers/jquery.fancybox-buttons.js create mode 100644 htdocs/dolistore/js/fancybox/helpers/jquery.fancybox-media.js create mode 100644 htdocs/dolistore/js/fancybox/helpers/jquery.fancybox-thumbs.css create mode 100644 htdocs/dolistore/js/fancybox/helpers/jquery.fancybox-thumbs.js create mode 100644 htdocs/dolistore/js/fancybox/jquery.fancybox.css create mode 100644 htdocs/dolistore/js/fancybox/jquery.fancybox.js create mode 100644 htdocs/dolistore/js/fancybox/jquery.fancybox.pack.js create mode 100644 htdocs/dolistore/langs/de_DE/dolistore.lang create mode 100644 htdocs/dolistore/langs/en_EN/dolistore.lang create mode 100644 htdocs/dolistore/langs/es_ES/dolistore.lang create mode 100644 htdocs/dolistore/langs/fr_FR/dolistore.lang create mode 100644 htdocs/dolistore/langs/it_IT/dolistore.lang diff --git a/htdocs/dolistore/ajax/image.php b/htdocs/dolistore/ajax/image.php new file mode 100644 index 00000000000..5bc6c9f2f0f --- /dev/null +++ b/htdocs/dolistore/ajax/image.php @@ -0,0 +1,65 @@ +. + * + * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); + * it under the terms of the GNU General Public License as published bypliance with the License. + * the Free Software Foundation; either version 3 of the License, or + * + * 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, see . + * or see http://www.gnu.org/ + */ + +if (!defined('REQUIRE_JQUERY_BLOCKUI')) define('REQUIRE_JQUERY_BLOCKUI', 1); +/** + * \file htdocs/commande/info.php + * \ingroup commande + * \brief Page des informations d'une commande + */ +$res = 0; +if (!$res && file_exists("../main.inc.php")) $res = @include("../main.inc.php"); +if (!$res && file_exists("../../main.inc.php")) $res = @include("../../main.inc.php"); +if (!$res && file_exists("../../../main.inc.php")) $res = @include("../../../main.inc.php"); +if (!$res && file_exists("../../../../main.inc.php")) $res = @include("../../../../main.inc.php"); +if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) + $res = @include("../../../../../dolibarr/htdocs/main.inc.php"); // Used on dev env only +if (!$res) die("Include of main fails"); + +// CORE + +global $lang, $user, $conf; + + +dol_include_once('/dolistore/class/dolistore.class.php'); +$dolistore = new Dolistore(); + +$id_product = GETPOST('id_product', 'int'); +$id_image = GETPOST('id_image', 'int'); +// quality : image resize with this in the URL : "cart_default", "home_default", "large_default", "medium_default", "small_default", "thickbox_default" +$quality = GETPOST('quality', 'alpha'); + +try { + $url = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/images/products/'.$id_product.'/'.$id_image.'/'.$quality; + $api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $dolistore->debug_api); + //echo $url; + $request = $api->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); + header('Content-type:image'); + print $request['response']; +} catch (PrestaShopWebserviceException $e) { + // Here we are dealing with errors + $trace = $e->getTrace(); + if ($trace[0]['args'][0] == 404) die('Bad ID'); + else if ($trace[0]['args'][0] == 401) die('Bad auth key'); + else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); +} \ No newline at end of file diff --git a/htdocs/dolistore/class/PSWebServiceLibrary.class.php b/htdocs/dolistore/class/PSWebServiceLibrary.class.php new file mode 100644 index 00000000000..8f55f6fd323 --- /dev/null +++ b/htdocs/dolistore/class/PSWebServiceLibrary.class.php @@ -0,0 +1,409 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +* PrestaShop Webservice Library +* @package PrestaShopWebservice +*/ + +/** + * @package PrestaShopWebservice + */ +class PrestaShopWebservice +{ + + /** @var string Shop URL */ + protected $url; + + /** @var string Authentification key */ + protected $key; + + /** @var boolean is debug activated */ + protected $debug; + + /** @var string PS version */ + protected $version; + + /** @var array compatible versions of PrestaShop Webservice */ + const psCompatibleVersionsMin = '1.4.0.0'; + const psCompatibleVersionsMax = '1.6.99.99'; + + /** + * PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated + * + * getMessage(); + * } + * ?> + * + * @param string $url Root URL for the shop + * @param string $key Authentification key + * @param mixed $debug Debug mode Activated (true) or deactivated (false) + */ + function __construct($url, $key, $debug = true) { + if (!extension_loaded('curl')) + throw new PrestaShopWebserviceException('Please activate the PHP extension \'curl\' to allow use of PrestaShop webservice library'); + $this->url = $url; + $this->key = $key; + $this->debug = $debug; + $this->version = 'unknown'; + } + + /** + * Take the status code and throw an exception if the server didn't return 200 or 201 code + * @param int $status_code Status code of an HTTP return + */ + protected function checkStatusCode($status_code) + { + $error_label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.'; + switch($status_code) + { + case 200: case 201: break; + case 204: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'No content'));break; + case 400: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Bad Request'));break; + case 401: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Unauthorized'));break; + case 404: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Not Found'));break; + case 405: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Method Not Allowed'));break; + case 500: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Internal Server Error'));break; + default: throw new PrestaShopWebserviceException('This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $status_code); + } + } + /** + * Handles a CURL request to PrestaShop Webservice. Can throw exception. + * @param string $url Resource name + * @param mixed $curl_params CURL parameters (sent to curl_set_opt) + * @return array status_code, response + */ + public function executeRequest($url, $curl_params = array()) + { + $defaultParams = array( + CURLOPT_HEADER => TRUE, + CURLOPT_RETURNTRANSFER => TRUE, + CURLINFO_HEADER_OUT => TRUE, + CURLOPT_HTTPAUTH => CURLAUTH_BASIC, + CURLOPT_USERPWD => $this->key.':', + CURLOPT_HTTPHEADER => array( 'Expect:' ) + ); + + $session = curl_init($url); + + $curl_options = array(); + foreach ($defaultParams as $defkey => $defval) + { + if (isset($curl_params[$defkey])) + $curl_options[$defkey] = $curl_params[$defkey]; + else + $curl_options[$defkey] = $defaultParams[$defkey]; + } + foreach ($curl_params as $defkey => $defval) + if (!isset($curl_options[$defkey])) + $curl_options[$defkey] = $curl_params[$defkey]; + + curl_setopt_array($session, $curl_options); + $response = curl_exec($session); + + $index = strpos($response, "\r\n\r\n"); + if ($index === false && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') + throw new PrestaShopWebserviceException('Bad HTTP response'); + + $header = substr($response, 0, $index); + $body = substr($response, $index + 4); + + $headerArrayTmp = explode("\n", $header); + + $headerArray = array(); + foreach ($headerArrayTmp as &$headerItem) + { + $tmp = explode(':', $headerItem); + $tmp = array_map('trim', $tmp); + if (count($tmp) == 2) + $headerArray[$tmp[0]] = $tmp[1]; + } + + if (array_key_exists('PSWS-Version', $headerArray)) + { + $this->version = $headerArray['PSWS-Version']; + if ( + version_compare(PrestaShopWebservice::psCompatibleVersionsMin, $headerArray['PSWS-Version']) == 1 || + version_compare(PrestaShopWebservice::psCompatibleVersionsMax, $headerArray['PSWS-Version']) == -1 + ) + throw new PrestaShopWebserviceException('This library is not compatible with this version of PrestaShop. Please upgrade/downgrade this library'); + } + + if ($this->debug) + { + $this->printDebug('HTTP REQUEST HEADER', curl_getinfo($session, CURLINFO_HEADER_OUT)); + $this->printDebug('HTTP RESPONSE HEADER', $header); + + } + $status_code = curl_getinfo($session, CURLINFO_HTTP_CODE); + if ($status_code === 0) + throw new PrestaShopWebserviceException('CURL Error: '.curl_error($session)); + curl_close($session); + if ($this->debug) + { + if ($curl_params[CURLOPT_CUSTOMREQUEST] == 'PUT' || $curl_params[CURLOPT_CUSTOMREQUEST] == 'POST') + $this->printDebug('XML SENT', urldecode($curl_params[CURLOPT_POSTFIELDS])); + if ($curl_params[CURLOPT_CUSTOMREQUEST] != 'DELETE' && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') + $this->printDebug('RETURN HTTP BODY', $body); + } + return array('status_code' => $status_code, 'response' => $body, 'header' => $header); + } + + public function printDebug($title, $content) + { + echo '
'.$title.'
'.htmlentities($content).'
'; + } + + public function getVersion() + { + return $this->version; + } + + /** + * Load XML from string. Can throw exception + * @param string $response String from a CURL response + * @return SimpleXMLElement status_code, response + */ + protected function parseXML($response) + { + if ($response != '') + { + libxml_clear_errors(); + libxml_use_internal_errors(true); + $xml = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); + if (libxml_get_errors()) + { + $msg = var_export(libxml_get_errors(), true); + libxml_clear_errors(); + throw new PrestaShopWebserviceException('HTTP XML response is not parsable: '.$msg); + } + return $xml; + } + else + throw new PrestaShopWebserviceException('HTTP response is empty'); + } + + /** + * Add (POST) a resource + *

Unique parameter must take :

+ * 'resource' => Resource name
+ * 'postXml' => Full XML string to add resource

+ * Examples are given in the tutorial

+ * @param array $options + * @return SimpleXMLElement status_code, response + */ + public function add($options) + { + $xml = ''; + + if (isset($options['resource'], $options['postXml']) || isset($options['url'], $options['postXml'])) + { + $url = (isset($options['resource']) ? $this->url.'/api/'.$options['resource'] : $options['url']); + $xml = $options['postXml']; + if (isset($options['id_shop'])) + $url .= '&id_shop='.$options['id_shop']; + if (isset($options['id_group_shop'])) + $url .= '&id_group_shop='.$options['id_group_shop']; + } + else + throw new PrestaShopWebserviceException('Bad parameters given'); + $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $xml)); + + self::checkStatusCode($request['status_code']); + return self::parseXML($request['response']); + } + + /** + * Retrieve (GET) a resource + *

Unique parameter must take :

+ * 'url' => Full URL for a GET request of Webservice (ex: http://mystore.com/api/customers/1/)
+ * OR
+ * 'resource' => Resource name,
+ * 'id' => ID of a resource you want to get

+ *

+ * + * get(array('resource' => 'orders', 'id' => 1)); + * // Here in $xml, a SimpleXMLElement object you can parse + * foreach ($xml->children()->children() as $attName => $attValue) + * echo $attName.' = '.$attValue.'
'; + * } + * catch (PrestaShopWebserviceException $ex) + * { + * echo 'Error : '.$ex->getMessage(); + * } + * ?> + *
+ * @param array $options Array representing resource to get. + * @return SimpleXMLElement status_code, response + */ + public function get($options) + { + if (isset($options['url'])) + $url = $options['url']; + elseif (isset($options['resource'])) + { + $url = $this->url.'/api/'.$options['resource']; + $url_params = array(); + if (isset($options['id'])) + $url .= '/'.$options['id']; + + $params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop'); + foreach ($params as $p) + foreach ($options as $k => $o) + if (strpos($k, $p) !== false) + $url_params[$k] = $options[$k]; + if (count($url_params) > 0) + $url .= '?'.http_build_query($url_params); + } + else + throw new PrestaShopWebserviceException('Bad parameters given '); + + $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); + self::checkStatusCode($request['status_code']);// check the response validity + return self::parseXML($request['response']); + } + + /** + * Head method (HEAD) a resource + * + * @param array $options Array representing resource for head request. + * @return SimpleXMLElement status_code, response + */ + public function head($options) + { + if (isset($options['url'])) + $url = $options['url']; + elseif (isset($options['resource'])) + { + $url = $this->url.'/api/'.$options['resource']; + $url_params = array(); + if (isset($options['id'])) + $url .= '/'.$options['id']; + + $params = array('filter', 'display', 'sort', 'limit'); + foreach ($params as $p) + foreach ($options as $k => $o) + if (strpos($k, $p) !== false) + $url_params[$k] = $options[$k]; + if (count($url_params) > 0) + $url .= '?'.http_build_query($url_params); + } + else + throw new PrestaShopWebserviceException('Bad parameters given'); + $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'HEAD', CURLOPT_NOBODY => true)); + self::checkStatusCode($request['status_code']);// check the response validity + return $request['header']; + } + /** + * Edit (PUT) a resource + *

Unique parameter must take :

+ * 'resource' => Resource name ,
+ * 'id' => ID of a resource you want to edit,
+ * 'putXml' => Modified XML string of a resource

+ * Examples are given in the tutorial

+ * @param array $options Array representing resource to edit. + */ + public function edit($options) + { + $xml = ''; + if (isset($options['url'])) + $url = $options['url']; + elseif ((isset($options['resource'], $options['id']) || isset($options['url'])) && $options['putXml']) + { + $url = (isset($options['url']) ? $options['url'] : $this->url.'/api/'.$options['resource'].'/'.$options['id']); + $xml = $options['putXml']; + if (isset($options['id_shop'])) + $url .= '&id_shop='.$options['id_shop']; + if (isset($options['id_group_shop'])) + $url .= '&id_group_shop='.$options['id_group_shop']; + } + else + throw new PrestaShopWebserviceException('Bad parameters given'); + + $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $xml)); + self::checkStatusCode($request['status_code']);// check the response validity + return self::parseXML($request['response']); + } + + /** + * Delete (DELETE) a resource. + * Unique parameter must take :

+ * 'resource' => Resource name
+ * 'id' => ID or array which contains IDs of a resource(s) you want to delete

+ * + * delete(array('resource' => 'orders', 'id' => 1)); + * // Following code will not be executed if an exception is thrown. + * echo 'Successfully deleted.'; + * } + * catch (PrestaShopWebserviceException $ex) + * { + * echo 'Error : '.$ex->getMessage(); + * } + * ?> + * + * @param array $options Array representing resource to delete. + */ + public function delete($options) + { + if (isset($options['url'])) + $url = $options['url']; + elseif (isset($options['resource']) && isset($options['id'])) + if (is_array($options['id'])) + $url = $this->url.'/api/'.$options['resource'].'/?id=['.implode(',', $options['id']).']'; + else + $url = $this->url.'/api/'.$options['resource'].'/'.$options['id']; + if (isset($options['id_shop'])) + $url .= '&id_shop='.$options['id_shop']; + if (isset($options['id_group_shop'])) + $url .= '&id_group_shop='.$options['id_group_shop']; + $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'DELETE')); + self::checkStatusCode($request['status_code']);// check the response validity + return true; + } + + +} + +/** + * @package PrestaShopWebservice + */ +class PrestaShopWebserviceException extends Exception { } \ No newline at end of file diff --git a/htdocs/dolistore/class/dolistore.class.php b/htdocs/dolistore/class/dolistore.class.php new file mode 100644 index 00000000000..35900d66f7d --- /dev/null +++ b/htdocs/dolistore/class/dolistore.class.php @@ -0,0 +1,308 @@ +. + * + * This program is free software; you can redistribute it and/or modifyion 2.0 (the "License"); + * it under the terms of the GNU General Public License as published bypliance with the License. + * the Free Software Foundation; either version 3 of the License, or + * + * 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, see . + * or see http://www.gnu.org/ + */ +dol_include_once('/core/lib/admin.lib.php'); +dol_include_once('/dolistore/class/PSWebServiceLibrary.class.php'); + +class Dolistore extends DolistoreModel +{ + // params + public $start // beginning of pagination + , $end // end of pagination + , $per_page // pagination: display per page + , $categorie // the current categorie + , $search // the search keywords + // setups + , $url // the url of this page + , $shop_url // the url of the shop + , $vat_rate // the vat rate used in the shop (prices are provided without vat) + , $lang // the integer representing the lang in the store + , $debug_api; // usefull if no dialog + + function __construct($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0)) + { + global $conf, $langs; + + $this->start = $options['start']; + $this->end = $options['end']; + $this->per_page = $options['per_page']; + $this->categorie = $options['categorie']; + $this->search = $options['search']; + + $this->url = dol_buildpath('/dolistore/index.php', 2); + $this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product='; + $this->vat_rate = 1.2; // 20% de TVA + $this->debug_api = false; + + if ($this->end == 0) { + $this->end = $this->per_page; + } + + $lang = explode('_', $langs->defaultlang); + $lang = $lang[0]; + $lang_array = ['fr', 'en', 'es', 'it', 'de']; + if (!in_array($lang, $lang_array)) { + $lang = 'en'; + } + $this->lang = array_search($lang, $lang_array) + 1; // 1=fr 2=en ... + + try { + $this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api); + + // Here we set the option array for the Webservice : we want products resources + $opt = array(); + $opt['resource'] = 'products'; + // make a search to limit the id returned. + if ($this->search != '') { + $opt2 = array(); + $opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->products->children() as $product) { + $products[] = (int) $product['id']; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } elseif ($this->categorie != 0) { + $opt2 = array(); + $opt2['resource'] = 'categories'; + $opt2['id'] = $this->categorie; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->category->associations->products->children() as $product) { + $products[] = (int) $product->id; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } + $opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]'; + $opt['sort'] = 'id_desc'; + $opt['filter[active]'] = '[1]'; + $opt['limit'] = "$this->start,$this->end"; + // Call + $xml = $this->api->get($opt); + $this->products = $xml->products->children(); + + + // Here we set the option array for the Webservice : we want categories resources + $opt = array(); + $opt['resource'] = 'categories'; + $opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]'; + $opt['sort'] = 'id_asc'; + // Call + $xml = $this->api->get($opt); + $this->categories = $xml->categories->children(); + } catch (PrestaShopWebserviceException $e) { + // Here we are dealing with errors + $trace = $e->getTrace(); + if ($trace[0]['args'][0] == 404) die('Bad ID'); + else if ($trace[0]['args'][0] == 401) die('Bad auth key'); + else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); + } + } + + function get_previous_url() + { + $param_array = array(); + if ($this->start < $this->per_page) { + $sub = 0; + } else { + $sub = $this->per_page; + } + $param_array['start'] = $this->start - $sub; + $param_array['end'] = $this->end - $sub; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."?$param"; + } + + function get_next_url() + { + $param_array = array(); + if (count($this->products) < $this->per_page) { + $add = 0; + } else { + $add = $this->per_page; + } + $param_array['start'] = $this->start + $add; + $param_array['end'] = $this->end + $add; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."?$param"; + } + + function version_compare($v1, $v2) + { + $v1 = explode('.', $v1); + $v2 = explode('.', $v2); + $ret = 0; + $level = 0; + $count1 = count($v1); + $count2 = count($v2); + $maxcount = max($count1, $count2); + while ($level < $maxcount) { + $operande1 = isset($v1[$level]) ? $v1[$level] : 'x'; + $operande2 = isset($v2[$level]) ? $v2[$level] : 'x'; + $level++; + if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') { + break; + } + if ($operande1 < $operande2) { + $ret = -$level; + break; + } + if ($operande1 > $operande2) { + $ret = $level; + break; + } + } + //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'
'."\n"; + return $ret; + } +} + +class DolistoreModel +{ + + function get_categories($parent = 0) + { + if (!isset($this->categories)) die('not possible'); + if ($parent != 0) { + $html = '