Browse Source

Grosses modifs

Mathieu Moulin 3 years ago
parent
commit
b2ee80e2d0

+ 132 - 0
src/list/products.inc.php

@@ -0,0 +1,132 @@
+<form method="GET">
+<input type="hidden" name="t" value="products" />
+<table>
+<tr>
+	<th align="left">Afficher les photos</th>
+	<td><input type="checkbox" name="photos" value="1"<?php if (!isset($_GET['photos'])) $_GET['photos']=0; if ($_GET['photos']) echo ' checked="checked"'; ?> /></td>
+</tr>
+<tr>
+	<th>Allergènes</th>
+	<td><select name="aller[]" multiple>
+	<?php
+	$sql = 'SELECT f.id_feature, f.id_feature_value, fl.value
+		FROM ps_feature_value f
+		LEFT JOIN ps_feature_value_lang fl ON fl.id_feature_value=f.id_feature_value AND fl.id_lang=1
+		WHERE f.id_feature=11';
+	$q = DB::p_select($sql);
+	$aller = [];
+	while($row=$q->fetch_assoc()) {
+		$aller[$row['id_feature_value']] = $row['value'];
+		echo '<option value="'.$row['id_feature_value'].'"'.(isset($_GET['aller']) && in_array($row['id_feature_value'], $_GET['aller']) ?' selected' :'').'>'.$row['value'].'</option>';
+	}
+	?>
+	</select></td>
+</tr>
+<tr>
+	<th align="left">Limiter à Max produits</th>
+	<td><input type="text" name="limit" value="<?php if(!isset($_GET['limit']) ||!is_numeric($_GET['limit'])) $_GET['limit']=10; echo $_GET['limit']; ?>" /></td>
+</tr>
+<tr>
+	<th>&nbsp;</th>
+	<td><input type="submit" value="GO" /></td>
+</tr>
+</table>
+</form>
+<?php
+
+$sql = '(SELECT p.id_product, 0 as id_product_attribute, i.id_image, p.reference, pl.name, p.weight, p.wholesale_price, p.price, IF(px.reduction_type="amount", p.price+px.price*px.reduction, 0) as price_pro, s.quantity, GROUP_CONCAT(DISTINCT CONCAT(sl.dluo, "&nbsp;(", sl.stock, ")") SEPARATOR ";") dluo, cl.name category_name, col.name country_name, GROUP_CONCAT(DISTINCT fl.value SEPARATOR ";") features
+	FROM ps_product p
+	INNER JOIN ps_product_lang pl ON pl.id_product=p.id_product AND pl.id_lang=1
+	LEFT JOIN ps_product_attribute pa ON pa.id_product=p.id_product
+	LEFT JOIN ps_image i ON i.id_product=p.id_product
+	LEFT JOIN ps_stock_available s ON s.id_product=p.id_product AND s.id_product_attribute=0
+	LEFT JOIN ps_products_dlc_dluo sl ON sl.id_product=p.id_product AND sl.id_combinaison=0 AND sl.is_current_stock>0
+	LEFT JOIN ps_category c ON c.id_category=p.id_category_default
+	LEFT JOIN ps_category_lang cl ON cl.id_category=c.id_category AND cl.id_lang=1
+	LEFT JOIN ps_address sa ON sa.id_supplier=p.id_supplier
+	LEFT JOIN ps_country_lang col ON col.id_country=sa.id_country AND col.id_lang=1
+	LEFT JOIN ps_feature_product fp ON fp.id_product=p.id_product
+	LEFT JOIN ps_feature_value f ON f.id_feature_value=fp.id_feature_value AND f.id_feature=11
+	LEFT JOIN ps_feature_value_lang fl ON fl.id_feature_value=f.id_feature_value AND fl.id_lang=1
+	LEFT JOIN ps_specific_price px ON px.id_product=p.id_product AND px.id_product_attribute=0 AND px.id_group=5
+	WHERE p.active=1 AND pa.id_product_attribute IS NULL
+	GROUP BY p.id_product)
+	UNION
+	(SELECT p.id_product, pa.id_product_attribute, pi.id_image, pa.reference, pl.name, pa.weight, pa.wholesale_price, pa.price, IF(px.reduction_type="amount", pa.price+px.price*px.reduction, 0) as price_pro, s.quantity, GROUP_CONCAT(DISTINCT CONCAT(sl.dluo, "&nbsp;(", sl.stock, ")") SEPARATOR "; ") dluo, cl.name category_name, col.name country_name, GROUP_CONCAT(DISTINCT fl.value SEPARATOR "; ") features
+	FROM ps_product p
+	INNER JOIN ps_product_lang pl ON pl.id_product=p.id_product AND pl.id_lang=1
+	INNER JOIN ps_product_attribute pa ON pa.id_product=p.id_product
+	LEFT JOIN ps_image i ON i.id_product=p.id_product
+	LEFT JOIN ps_product_attribute_image pi ON pi.id_product_attribute=pa.id_product_attribute
+	LEFT JOIN ps_stock_available s ON s.id_product=p.id_product AND s.id_product_attribute=pa.id_product_attribute
+	LEFT JOIN ps_products_dlc_dluo sl ON sl.id_product=p.id_product AND sl.id_combinaison=pa.id_product_attribute AND sl.is_current_stock>0
+	LEFT JOIN ps_category c ON c.id_category=p.id_category_default
+	LEFT JOIN ps_category_lang cl ON cl.id_category=c.id_category AND cl.id_lang=1
+	LEFT JOIN ps_address sa ON sa.id_supplier=p.id_supplier
+	LEFT JOIN ps_country_lang col ON col.id_country=sa.id_country AND col.id_lang=1
+	LEFT JOIN ps_feature_product fp ON fp.id_product=p.id_product
+	LEFT JOIN ps_feature_value f ON f.id_feature_value=fp.id_feature_value AND f.id_feature=11
+	LEFT JOIN ps_feature_value_lang fl ON fl.id_feature_value=f.id_feature_value AND fl.id_lang=1
+	LEFT JOIN ps_specific_price px ON px.id_product=p.id_product AND px.id_product_attribute=pa.id_product_attribute AND px.id_group=5
+	WHERE p.active=1
+	GROUP BY pa.id_product_attribute)
+	ORDER BY name
+	'.(!empty($_GET['limit']) ?'LIMIT '.$_GET['limit'] :'').'
+	';
+$q = DB::p_select($sql);
+
+?>
+<table border="1">
+<thead>
+<tr>
+<?php if(!empty($_GET['photos'])) { ?>
+	<th>Photo</th>
+<?php } ?>
+	<th>ID prod/decl</th>
+	<th>Réf.</th>
+	<th>Libellé</th>
+	<th>Poids</th>
+	<th>Unité cond.</th>
+	<th>Cond. Vente</th>
+	<th>Prix achat HT</th>
+	<th>Prix vente PUB HT</th>
+	<th>Prix vente PRO HT</th>
+	<th>Stock</th>
+	<th>DDM</th>
+	<th>Allergènes</th>
+	<?php foreach($aller as $i=>$j) {
+	echo '<th>'.$j.'</th>';
+	} ?>
+	<th>Catégorie</th>
+	<th>FR</th>
+</tr>
+</thead>
+<tbody>
+<?php
+while($row=$q->fetch_assoc()) {
+	echo '<tr>';
+	if (!empty($_GET['photos']))
+		echo '<td>'.($row['id_image'] ?'<img src="https://'.P_DOMAIN.'/'.$row['id_image'].'-home_default/photo.jpg" height="100" />' :'').'</td>';
+	echo '<td align="right">#'.$row['id_product'].'/'.$row['id_product_attribute'].'</td>';
+	echo '<td align="right">'.$row['reference'].'</td>';
+	echo '<td>'.$row['name'].'</td>';
+	echo '<td align="right">'.str_replace('.', ',', $row['weight']).'</td>';
+	echo '<td></td>';
+	echo '<td></td>';
+	echo '<td align="right">'.str_replace('.', ',', round($row['wholesale_price'], 2)).'</td>';
+	echo '<td align="right">'.str_replace('.', ',', round($row['price'], 2)).'</td>';
+	echo '<td align="right">'.str_replace('.', ',', round($row['price_pro'], 2)).'</td>';
+	echo '<td align="right">'.$row['quantity'].'</td>';
+	echo '<td>'.$row['dluo'].'</td>';
+	echo '<td>'.$row['features'].'</td>';
+	foreach($aller as $i=>$j) {
+		echo '<td>'.(is_numeric(strpos($row['features'], $j)) ?$j :'').'</td>';
+	}
+	//echo '<td>'.$row['features'].'</td>';
+	echo '<td>'.$row['category_name'].'</td>';
+	echo '<td>'.$row['country_name'].'</td>';
+	echo '</tr>';
+}
+?>
+</tbody>
+</table>

+ 48 - 0
src/manual/product.inc.php

@@ -0,0 +1,48 @@
+<form method="GET">
+<input type="hidden" name="t" value="product" />
+<input type="text" name="q" value="<?php if (isset($_GET['q'])) echo $q=$_GET['q']; ?>" />
+<input type="submit" value="Chercher" />
+</form>
+<?php
+
+if (!empty($q)) {
+	$sql = '(SELECT p.id_product, 0 as id_product_attribute, p.reference, pl.name
+		FROM ps_product p
+		INNER JOIN ps_product_lang pl ON pl.id_product=p.id_product
+		LEFT JOIN ps_product_attribute pa ON pa.id_product=p.id_product
+		WHERE pl.name LIKE "%'.$q.'%" OR p.reference LIKE "'.$q.'"
+			AND pa.id_product_attribute IS NULL
+		GROUP BY p.id_product)
+		UNION
+		(SELECT p.id_product, pa.id_product_attribute, pa.reference, pl.name
+		FROM ps_product p
+		INNER JOIN ps_product_lang pl ON pl.id_product=p.id_product
+		INNER JOIN ps_product_attribute pa ON pa.id_product=p.id_product
+		WHERE pl.name LIKE "%'.$q.'%" OR pa.reference LIKE "'.$q.'"
+		GROUP BY pa.id_product_attribute)';
+	$q = DB::p_select($sql);
+	if ($q->num_rows) {
+		echo '<p>Prestashop : '.$q->num_rows.' produits</p>';
+		echo '<table border="1">';
+			echo '<tr>';
+			echo '<td>ID prod.</td>';
+			echo '<td>ID decl.</td>';
+			echo '<td>Réf.</td>';
+			echo '<td>Nom</td>';
+			echo '</tr>';
+		echo '<thead>';
+		echo '</thead>';
+		echo '<tbody>';
+		while($row=$q->fetch_assoc()) {
+			echo '<tr>';
+			echo '<td>'.$row['id_product'].'</td>';
+			echo '<td>'.$row['id_product_attribute'].'</td>';
+			echo '<td>'.$row['reference'].'</td>';
+			echo '<td>'.$row['name'].'</td>';
+			echo '<td><a href="?t=product&tname='.($row['id_product_attribute'] ?'product_attribute' :'product').'&oid='.($row['id_product_attribute'] ?$row['id_product_attribute'] :$row['id_product']).'">Synchro P=>D</a></td>';
+			echo '</tr>';
+		}
+		echo '</tbody>';
+		echo '</table>';
+	}
+}

+ 17 - 0
src/repair/product.inc.php

@@ -1 +1,18 @@
 <?php
+
+// Dédoublonnage product_extrafields
+if (isset($_GET['extrafields'])) {
+	$sql = 'SELECT fk_object, MIN(rowid)
+		FROM llx_product_extrafields
+		GROUP BY fk_object
+		HAVING COUNT(*) >= 2';
+	$q = DB::d_select($sql);
+	while(list($id, $rowid)=$q->fetch_row()) {
+		$sql = 'DELETE FROM llx_product_extrafields
+			WHERE rowid='.$rowid;
+		if (isset($_GET['go']))
+			DB::d_delete($sql);
+		else
+			echo '<p>'.$sql.'</p>';
+	}
+}

+ 3 - 3
src/repair/product_lot.inc.php

@@ -32,7 +32,7 @@ $sql = 'SELECT p.rowid k_product, s.rowid k_product_stock, p.label, p.stock, s.r
 	HAVING p.stock != s.reel OR p.stock != SUM(IF(sl.qty IS NOT NULL, sl.qty, 0))  
 	ORDER BY `diff` DESC';
 $q = DB::d_select($sql);
-if (false) while($row=$q->fetch_assoc()) {
+if (isset($_GET['recalcul'])) while($row=$q->fetch_assoc()) {
 	$sql = 'UPDATE llx_product
 		SET stock='.$row['qty'].'
 		WHERE rowid='.$row['k_product'];
@@ -57,7 +57,7 @@ $sql = 'SELECT l.rowid, l.fk_product, l.batch, l.eatby, l.sellby, s.rowid s_rowi
 	LEFT JOIN llx_product_batch sl ON sl.fk_product_stock=s.rowid AND sl.batch=l.batch
 	WHERE s.rowid IS NULL OR sl.rowid IS NULL';
 $q = DB::d_select($sql);
-if (false) while ($row=$q->fetch_assoc()) {
+if (isset($_GET['deleted'])) while ($row=$q->fetch_assoc()) {
 	var_dump($row);
 	echo '<br />';
 
@@ -96,7 +96,7 @@ $sql = 'SELECT l.rowid
 	LEFT JOIN llx_product_batch sl ON sl.fk_product_stock=s.rowid AND sl.batch=l.batch
 	WHERE (l.tms >= "'.$date.' 00:00:00" OR sl.tms >= "'.$date.' 00:00:00")';
 $q = DB::d_select($sql);
-if (true) while ($row=$q->fetch_assoc()) {
+if (isset($_GET['refresh'])) while ($row=$q->fetch_assoc()) {
 	var_dump($row);
 	if (isset($_GET['go']))
 		sync::_action('product_lot', 'dp', 'osync', 'product_lot', $row['rowid']);

+ 42 - 42
src/repair/stock.inc.php

@@ -2,51 +2,51 @@
 
 // Stock supprimé P=>D
 
-$sql = 'SELECT p.rowid k_product
-	FROM llx_product p
-	LEFT JOIN llx_product_stock s ON s.fk_product=p.rowid AND s.fk_entrepot=1
-	WHERE s.rowid IS NULL';
-$q = DB::d_select($sql);
-if (true) while ($row=$q->fetch_assoc()) {
-	var_dump($row);
-	echo '<br />';
+if (isset($_GET['deleted'])) {
+	$sql = 'SELECT p.rowid k_product
+		FROM llx_product p
+		LEFT JOIN llx_product_stock s ON s.fk_product=p.rowid AND s.fk_entrepot=1
+		WHERE s.rowid IS NULL';
+	$q = DB::d_select($sql);
+	while ($row=$q->fetch_assoc()) {
+		var_dump($row);
+		echo '<br />';
 
-	$o = sync::d_o_oid('product', 'product', $row['k_product']);
-	var_dump($o);
-	echo '<br />';
-	if (!empty($o)) {
-		if ($o['p_tref']=='product')
-			$sql = 'SELECT *
-			FROM ps_stock_available
-			WHERE id_product='.$o['p_oid'].' AND id_product_attribute=0';
-		elseif ($o['p_tref']=='product_attribute')
-			$sql = 'SELECT *
-			FROM ps_stock_available s
-			INNER JOIN ps_product_attribute pa ON pa.id_product_attribute=s.id_product_attribute AND pa.id_product=s.id_product
-			WHERE pa.id_product_attribute='.$o['p_oid'];
-		else
-			continue;
+		$o = sync::d_o_oid('product', 'product', $row['k_product']);
+		var_dump($o);
+		echo '<br />';
+		if (!empty($o)) {
+			if ($o['p_tref']=='product')
+				$sql = 'SELECT *
+				FROM ps_stock_available
+				WHERE id_product='.$o['p_oid'].' AND id_product_attribute=0';
+			elseif ($o['p_tref']=='product_attribute')
+				$sql = 'SELECT *
+				FROM ps_stock_available s
+				INNER JOIN ps_product_attribute pa ON pa.id_product_attribute=s.id_product_attribute AND pa.id_product=s.id_product
+				WHERE pa.id_product_attribute='.$o['p_oid'];
+			else
+				continue;
 
-		$q2 = DB::p_select($sql);
-		// Dans la pratique, un seul enregistrement
-		while ($row2=$q2->fetch_assoc()) {
-			var_dump($row2);
-			$o = sync::p_o_oid('stock', 'stock_available', $row2['id_stock_available']);
-			if (!empty($o)) {
-				$sql = 'INSERT INTO llx_product_stock
-					(rowid, tms, fk_product, fk_entrepot, reel, import_key)
-					VALUES
-					('.$o['d_oid'].', NOW(), '.$row['k_product'].', 1, 0, NULL)';
-				if (isset($_GET['go']))
-					DB::d_insert($sql);
-				else
-					echo '<p>'.$sql.'</p>';
+			$q2 = DB::p_select($sql);
+			// Dans la pratique, un seul enregistrement
+			while ($row2=$q2->fetch_assoc()) {
+				var_dump($row2);
+				$o = sync::p_o_oid('stock', 'stock_available', $row2['id_stock_available']);
+				if (!empty($o)) {
+					$sql = 'INSERT INTO llx_product_stock
+						(rowid, tms, fk_product, fk_entrepot, reel, import_key)
+						VALUES
+						('.$o['d_oid'].', NOW(), '.$row['k_product'].', 1, 0, NULL)';
+					if (isset($_GET['go']))
+						DB::d_insert($sql);
+					else
+						echo '<p>'.$sql.'</p>';
+				}
 			}
 		}
-	}
-	else {
-		echo '<p>ERREUR MANQUE CORRESPONDANCE LOT</p>';
+		else {
+			echo '<p>ERREUR MANQUE CORRESPONDANCE LOT</p>';
+		}
 	}
 }
-
-die();

+ 58 - 0
src/send/devis_form.inc.php

@@ -0,0 +1,58 @@
+<?php
+
+if (empty($_GET['id']) || !is_numeric($id=$_GET['id']))
+    die('NIET');
+
+$sql = 'SELECT *
+    FROM ps_gformrequest
+    WHERE id_gformrequest='.$id;
+$q = DB::p_select($sql);
+while($row=$q->fetch_assoc()) {
+    //var_dump($row);
+    // id request
+    $row['id_gformrequest'];
+    // id modèle form
+    $row['id_gformbuilderpro'];
+    // email client sender
+    $row['sender'];
+    // subject : nom form
+    $row['subject'];
+    // date
+    $row['date_add'];
+    // IP
+    $row['user_id'];
+    // json request
+    $request = json_decode($row['jsonrequest'], true);
+    var_dump($request);
+
+    $fields_input = [
+        'gender',
+        'lastname',
+        'firstname',
+        'address',
+        'postalcode',
+        'city',
+        'email',
+        'phone1',
+        'phone2',
+        'demand', // détails texte
+    ];
+    $a = [];
+    foreach($fields_input as $fieldname)
+        $a[$fieldname] = $request['{'.$fieldname.'_input}'];
+    $fields = [
+        'product_name', // label product
+        'input_98873', // Label Pays
+        'fileupload_80661', // contient un nom de fichier présent dans upload/ à mettre dans 
+    ];
+    $a = [];
+    foreach($fields as $fieldname)
+        $a[$fieldname] = $request['{'.$fieldname.'}'];
+
+    var_dump($a);
+
+    $data_map = [
+        '',
+    ];
+
+}

+ 6 - 3
src/sync/customer/common.inc.php

@@ -8,13 +8,16 @@ class sync_customer extends sync
 const MODEL_NAME = 'customer';
 const MODEL_ID = 14;
 const MAP_ID = 4;
-const D_TABLE_MAIN = 'societe';
-const D_TABLE_MAIN_REF = 'code_client';
+
 const P_TABLE_MAIN = 'customer';
 const P_TABLE_MAIN_ID = 'id_customer';
 
+const D_TABLE_MAIN = 'societe';
+const D_TABLE_MAIN_REF = 'code_client';
+const D_REF_CODE = 'CU';
+const D_REF_LENGTH = 6;
+const D_REF_DATE = true;
 protected static $nb;
-const D_CODE = 'CU';
 
 function d_data($otype, $oid)
 {

+ 5 - 1
src/sync/db.inc.php

@@ -220,7 +220,11 @@ public static function d_update_row($tablename, $data, $params, $data_orig=[])
 	// Limit to updated data
 	if (!empty($data_orig)) {
 		foreach($data as $i=>$j) {
-			if($j===$data_orig[$i] || (is_numeric($j) && is_numeric($data_orig[$i]) && $j==$data_orig[$i])) {
+			if($j===$data_orig[$i]) {
+				unset($data[$i]);
+				unset($data_orig[$i]);
+			}
+			elseif(is_numeric($j) && is_numeric($data_orig[$i]) && ((float)$j==(float)$data_orig[$i] || round($j, 8)==round($data_orig[$i], 8))) {
 				unset($data[$i]);
 				unset($data_orig[$i]);
 			}

+ 7 - 4
src/sync/order/common.inc.php

@@ -8,13 +8,16 @@ class sync_order extends sync
 const MODEL_NAME = 'order';
 const MODEL_ID = 15;
 const MAP_ID = 8;
-const D_TABLE_MAIN = 'commande';
-const D_TABLE_MAIN_REF = 'ref';
+
 const P_TABLE_MAIN = 'orders';
 const P_TABLE_MAIN_ID = 'id_order';
 
+const D_TABLE_MAIN = 'commande';
+const D_TABLE_MAIN_REF = 'ref';
+const D_REF_CODE = 'CO';
+const D_REF_LENGTH = 6;
+const D_REF_DATE = true;
 protected static $nb;
-const D_CODE = 'CO';
 
 protected static $_d_status = [
 	//-3 => 'Pas assez de stock',
@@ -146,7 +149,7 @@ function p_customer_insert(&$p_data)
 		'ape' => NULL,
 		'firstname' => 'Anonymous',
 		'lastname' => 'Deleted Recovered',
-		'email' => 'anonymous@'.P_DOMAIN,
+		'email' => 'anonymous@'.EMAIL_DOMAIN,
 		'passwd' => '',
 		'last_passwd_gen' => NULL,
 		'birthday' => '0000-00-00',

+ 2 - 5
src/sync/order/pd.inc.php

@@ -38,12 +38,9 @@ public function pd_insert_more(&$o, &$d_data, &$p_data)
 public function pd_update_more(&$o, &$d_data_map, &$d_data_map_create, &$d_data, &$p_data)
 {
 	$id = $o['d_oid'];
-	
+
 	// commande_extrafields
-	if (!empty($d_data['commande_extrafields']))
-		DB::d_update_row('commande_extrafields', $d_data_map['commande_extrafields'], ['rowid'=>$d_data['commande_extrafields']['rowid']], $d_data['commande_extrafields']);
-	else
-		DB::d_insert_row('commande_extrafields', array_merge($d_data_map_create['commande_extrafields'], $d_data_map['commande_extrafields'], ['fk_object'=>$id]));
+	static::d_update_row('commande_extrafields', ['fk_object'=>$id], $d_data_map, $d_data_map_create, $d_data);
 
 	// Product details
 	if (!empty($p_data['order_detail'])) foreach($p_data['order_detail'] as $row) {

+ 10 - 2
src/sync/order_detail/pd.inc.php

@@ -36,6 +36,7 @@ public function osync($o)
 public function pd_insert_more(&$o, &$d_data, &$p_data)
 {
 	$id = $o['d_oid'];
+
 	// Pack produit => élatement
 	var_dump($p_data);
 	if ($o['p_tref']='order_detail' && !empty($p_data['product']['cache_is_pack'])) {
@@ -60,13 +61,16 @@ public function pd_insert_more(&$o, &$d_data, &$p_data)
 			$d_map_row = $this->map_create_pack($o, $row2);
 			var_dump($d_map_row);
 			$oid = DB::d_insert_row('commandedet', $d_map_row['commandedet']);
-			$oid = DB::d_insert_row('commandedet_extrafields', array_merge($d_map_row['commandedet_extrafields'], ['fk_object'=>$oid]));
+			$oid2 = DB::d_insert_row('commandedet_extrafields', array_merge($d_map_row['commandedet_extrafields'], ['fk_object'=>$oid]));
 		}
 	}
 }
 public function pd_update_more(&$o, &$d_data_map, &$d_data_map_create, &$d_data, &$p_data)
 {
-	//$this->pd_insert_more($o, $d_data_map, $p_data);
+	$id = $o['d_oid'];
+
+	// commandedet_extrafields
+	static::d_update_row('commandedet_extrafields', ['fk_object'=>$id], $d_data_map, $d_data_map_create, $d_data);
 }
 
 // -- MAPPING --
@@ -93,6 +97,10 @@ public function map_update(&$o, &$p_data, &$d_data=[])
 				'multicurrency_total_ttc' => $p_data['order_detail']['total_price_tax_incl'],
 			],
 		];
+
+		if (ECOTAX) {
+			$d_data_map['commandedet_extrafields']['ecotaxdeee'] = $p_data['order_detail']['ecotax'];
+		}
 	}
 	elseif ($o['p_tref']=='order_cart_rule') {
 		$row = $p_data['order_cart_rule'];

+ 5 - 0
src/sync/product/common.inc.php

@@ -12,6 +12,11 @@ const MAP_SIMPLE_ID = 1;
 const MAP_COMBI_ID = 2;
 
 const D_TABLE_MAIN = 'product';
+const D_TABLE_MAIN_REF = 'ref';
+const D_REF_CODE = 'PI';
+const D_REF_LENGTH = 5;
+const D_REF_DATE = false;
+protected static $nb;
 
 const P_TABLE_MAIN = 'product';
 const P_SIMPLE_TABLE_MAIN = 'product';

+ 25 - 13
src/sync/product/dp.inc.php

@@ -42,6 +42,7 @@ public function osync($o)
 
 public function dp_update_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data, &$d_data)
 {
+	var_dump('dp_update_more()'); var_dump($o);
 	// Produit simple
 	if ($o['p_tref']=='product')
 		return $this->dp_update_simple_more($o, $p_data_map, $p_data_map_create, $p_data, $d_data);
@@ -52,7 +53,11 @@ public function dp_update_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data,
 
 public function dp_update_common_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data, &$d_data)
 {
-	$id = $o['p_oid'];
+	if ($o['p_tref']=='product')
+		$id = $o['p_oid'];
+	// Forcément créé depuis Presta et donc déjà sync dans ce cas
+	elseif ($o['p_tref']=='product_attribute')
+		$id = $p_data['product']['id_product'];
 	
 	// category_product (par defaut)
 	if (empty($p_data['category_product']) && isset($p_data_map_create['category_product'])) {
@@ -123,7 +128,7 @@ public function dp_update_simple_more(&$o, &$p_data_map, &$p_data_map_create, &$
 	}
 }
 
-public function dp_update_combie_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data, &$d_data)
+public function dp_update_combi_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data, &$d_data)
 {
 	$this->dp_update_common_more($o, $p_data_map, $p_data_map_create, $p_data, $d_data);
 
@@ -138,7 +143,13 @@ public function dp_update_combie_more(&$o, &$p_data_map, &$p_data_map_create, &$
 
 public function dp_map_create(&$o, &$d_data)
 {
-	return $this->map_create_simple($o, $d_data);
+	if (empty($o['p_tref']))
+		$o['p_tref'] = static::P_TABLE_MAIN;
+	
+	if ($o['p_tref']=='product')
+		return $this->map_create_simple($o, $d_data);
+	elseif ($o['p_tref']=='product_attribute')
+		return []; //$this->map_create_combi($o, $d_data);
 }
 public function map_create_simple(&$o, &$d_data)
 {
@@ -267,15 +278,16 @@ public function map_create_simple(&$o, &$d_data)
 
 public function dp_map_update(&$o, &$d_data, &$p_data=[])
 {
-	if ($o['d_tref']=='product')
+	var_dump('dp_map_update()'); var_dump($o);
+	if ($o['p_tref']=='product')
 		return $this->map_update_simple($o, $d_data, $p_data);
-	elseif ($o['d_tref']=='product_attribute')
+	elseif ($o['p_tref']=='product_attribute')
 		return $this->map_update_combi($o, $d_data, $p_data);
 }
 
 public function map_update_simple(&$o, &$d_data, &$p_data=[])
 {
-	$tms = max((isset($p_data['product']['date_upd']) ?$p_data['product']['date_upd'] :'0000-00-00') :$d_data['product']['tms']);
+	$tms = max((isset($p_data['product']['date_upd']) ?$p_data['product']['date_upd'] :'0000-00-00'), $d_data['product']['tms']);
 	
 	$p_data_map = [
 		'product' => [
@@ -340,11 +352,11 @@ public function map_update_simple(&$o, &$d_data, &$p_data=[])
 			//'id_shop' => static::P_ID_SHOP,
 			//'id_lang' => static::P_ID_LANG,
 			//'description' => html_entity_decode($d_data['product']['description']),
-			'link_rewrite' => static::_dp_map_link_rewrite($d_data),
+			//'link_rewrite' => static::_dp_map_link_rewrite($d_data),
 			//'meta_description' => html_entity_decode($d_data['product']['description']),
 			//'meta_keywords' => '',
 			//'meta_title' => html_entity_decode($d_data['product']['label']),
-			'name' => html_entity_decode($d_data['product']['label']),
+			//'name' => html_entity_decode($d_data['product']['label']),
 			//'available_now' => '',
 			//'available_later' => '',
 			//'delivery_in_stock' => '',
@@ -415,7 +427,7 @@ public function map_update_simple(&$o, &$d_data, &$p_data=[])
 
 public function map_update_combi(&$o, &$d_data, &$p_data=[])
 {
-	$tms = max((isset($p_data['product']['date_upd']) ?$p_data['product']['date_upd'] :'0000-00-00') :$d_data['product']['tms']);
+	$tms = max((isset($p_data['product']['date_upd']) ?$p_data['product']['date_upd'] :'0000-00-00'), $d_data['product']['tms']);
 	
 	$p_data_map = [
 		'product' => [
@@ -602,19 +614,19 @@ public static function _dp_map_id_tax_rules_group(&$orig_data, &$dest_tree=[])
 }
 public static function _dp_map_ean13(&$orig_data, &$dest_tree=[])
 {
-	return ($orig_data['product']['fk_barcode_type']==2) ?substr($orig_data['product']['barcode'], 0, 13) :NULL;
+	return ($orig_data['product']['fk_barcode_type']==2) ?substr($orig_data['product']['barcode'], 0, 13) :'';
 }
 public static function _dp_map_ean8(&$orig_data, &$dest_tree=[])
 {
-	return ($orig_data['product']['fk_barcode_type']==1) ?$orig_data['product']['barcode'] :NULL;
+	return ($orig_data['product']['fk_barcode_type']==1) ?$orig_data['product']['barcode'] :'';
 }
 public static function _dp_map_isbn(&$orig_data, &$dest_tree=[])
 {
-	return ($orig_data['product']['fk_barcode_type']==4) ?$orig_data['product']['barcode'] :NULL;
+	return ($orig_data['product']['fk_barcode_type']==4) ?$orig_data['product']['barcode'] :'';
 }
 public static function _dp_map_upc(&$orig_data, &$dest_tree=[])
 {
-	return ($orig_data['product']['fk_barcode_type']==3) ?$orig_data['product']['barcode'] :NULL;
+	return ($orig_data['product']['fk_barcode_type']==3) ?$orig_data['product']['barcode'] :'';
 }
 public static function _dp_map_link_rewrite(&$orig_data, &$dest_tree=[])
 {

+ 167 - 39
src/sync/product/pd.inc.php

@@ -12,8 +12,9 @@ public function execute_osync($otype, $oid)
 
 public function execute_create($otype, $oid)
 {
+	// Si produit maître avec déclinaisons, on synchronise toutes les déclinaisons
 	if ($otype=='product' && $this->check_combi($oid)) {
-		return false;
+		$this->pd_osync_decl($oid);
 	}
 	
 	return $this->pd_create($otype, $oid);
@@ -41,9 +42,6 @@ public function pd_insert_more(&$o, &$d_data_map, &$p_data)
 	// Un seul cas de $otype/$d_tref dans Doli
 	$id = $o['d_oid'];
 
-	// product_extrafields
-	static::d_insert_row('product_extrafields', ['fk_object' => $id], $d_data_map);
-
 	//var_dump($p_data);
 
 	// stock_available
@@ -65,7 +63,32 @@ public function pd_update_more(&$o, &$d_data_map, &$d_data_map_create, &$d_data,
 	$id = $o['d_oid'];
 	$p_id = $p_data['product']['id_product'];
 	$pa_id = (!empty($p_data['product_attribute']) ?$p_data['product_attribute']['id_product_attribute'] :0);
+
+	// Set Prestashop reference from Dolibarr
+	if ($pa_id && (empty($p_data['product_attribute']['reference']) || $p_data['product_attribute']['reference']=='NEW')) {
+		// Si réf déjà exisatante on récup
+		if (!empty($d_data['product']['ref']))
+			$ref = $d_data['product']['ref'];
+		else
+			$ref = $d_data_map_create['product']['ref'];
+		$sql = 'UPDATE ps_product_attribute
+			SET reference="'.$ref.'"
+			WHERE id_product_attribute='.$pa_id;
+		DB::p_update($sql);
+	}
+	elseif (empty($pa_id) && (empty($p_data['product']['reference']) || $p_data['product']['reference']=='NEW')) {
+		// Si réf déjà exisatante on récup
+		if (!empty($d_data['product']['ref']))
+			$ref = $d_data['product']['ref'];
+		else
+			$ref = $d_data_map_create['product']['ref'];
+		$sql = 'UPDATE ps_product
+			SET reference="'.$ref.'"
+			WHERE id_product='.$p_id;
+		DB::p_update($sql);
+	}
 	
+	// Adds row in product_price if updated
 	if(isset($d_data['product']) && (
 		($d_data['product']['price'] != $d_data_map['product']['price'])
 		|| ($d_data['product']['tva_tx'] != $d_data_map['product']['tva_tx'])
@@ -155,13 +178,45 @@ public function pd_update_more(&$o, &$d_data_map, &$d_data_map_create, &$d_data,
 	// product_supplier
 	if (!empty($p_data['product_supplier'])) foreach($p_data['product_supplier'] as $row)
 		static::_action('supplier_price', 'pd', 'osync', 'product_supplier', $row['id_product_supplier']);
+	
+	// Déclinaisons
+	if (empty($pa_id))
+		$this->pd_osync_decl($p_id);
 }
 
-public function pd_image_sync($o, $p_data)
+public function pd_osync_decl($oid)
+{
+	$ok = false;
+	$sql = 'SELECT p.id_product_attribute
+		FROM ps_product_attribute p
+		WHERE p.id_product='.$oid;
+	$q = DB::p_select($sql);
+	$ok = false;
+	while(list($pa_id)=$q->fetch_row()) {
+		if (static::_action('product', 'pd', 'osync', 'product_attribute', $pa_id))
+			$ok = true;
+	}
+	if ($ok)
+		static::_notif_ts('product', 'product', $oid);
+	return;
+}
+
+public function pd_image_sync(&$o, &$p_data)
 {
 	$p_id = $p_data['product']['id_product'];
 	$pa_id = (!empty($p_data['product_attribute']) ?$p_data['product_attribute']['id_product_attribute'] :0);
 	
+	if ($pa_id) {
+		$sql = 'SELECT id_image
+			FROM ps_product_attribute_image
+			WHERE id_product_attribute='.$pa_id;
+		$q = DB::p_select($sql);
+		while($row=$q->fetch_assoc()) {
+			if ($this->image_sync($p_data, $row['id_image']))
+				return;
+		}
+	}
+
 	// Image
 	$sql = 'SELECT id_image
 		FROM ps_image
@@ -170,31 +225,50 @@ public function pd_image_sync($o, $p_data)
 		LIMIT 1';
 	$q = DB::p_select($sql);
 	
-	foreach($q as $row) {
-		$i_id = $row['id_image'];
-		$p_filename = $i_id.'.jpg';
-		$p_folder = P_FOLDER_ROOT.'/img/p';
-		$n = strlen($i_id);
-		for($i=0; $i<$n; $i++)
-			$p_folder .= '/'.substr($i_id, $i, 1);
-		var_dump($p_f=$p_folder.'/'.$p_filename);
-		if (file_exists($p_f=$p_folder.'/'.$p_filename)) {
-			//var_dump($p_f);
-			if (!empty($p_data['product_attribute']))
-				$ref = $p_data['product_attribute']['reference'];
-			else
-				$ref = $p_data['product']['reference'];
-			if (empty($ref))
-				break;
-			$d_filename = $ref.'-'.$i_id.'.jpg';
-			$d_folder = D_FOLDER_ROOT.'/documents/produit/'.$ref;
-			if (!file_exists($d_folder))
-				mkdir($d_folder);
-			$d_f = $d_folder.'/'.$d_filename;
-			var_dump($d_f);
-			exec("rsync -a \"$p_f\" \"$d_f\"");
+	while($row=$q->fetch_assoc()) {
+		$this->image_sync($p_data, $row['id_image']);
+	}
+}
+
+public function image_sync(&$p_data, $i_id)
+{
+	$p_filename = $i_id.'.jpg';
+	$p_folder = P_FOLDER_ROOT.'/img/p';
+
+	$n = strlen($i_id);
+	for($i=0; $i<$n; $i++)
+		$p_folder .= '/'.substr($i_id, $i, 1);
+
+	var_dump($p_f=$p_folder.'/'.$p_filename);
+
+	if (file_exists($p_f=$p_folder.'/'.$p_filename)) {
+		//var_dump($p_f);
+		if (!empty($p_data['product_attribute']))
+			$ref = $p_data['product_attribute']['reference'];
+		else
+			$ref = $p_data['product']['reference'];
+		if (empty($ref))
+			return;
+
+		$d_filename = $ref.'-'.$i_id.'.jpg';
+		$d_folder = D_FOLDER_ROOT.'/documents/produit/'.$ref;
+		if (!file_exists($d_folder))
+			mkdir($d_folder);
+		$d_f = $d_folder.'/'.$d_filename;
+		var_dump($d_f);
+		exec("rsync -a \"$p_f\" \"$d_f\"");
+
+		// Suppression ancienne image
+		$fp = opendir($d_folder);
+		while($filename=readdir($fp)) {
+			if (!in_array($filename, ['.', '..', $d_filename])) {
+				var_dump('DELETE : '.$filename);
+				unlink($d_folder.'/'.$filename);
+			}
 		}
+		return true;
 	}
+
 }
 
 // -- MAPPING --
@@ -214,9 +288,16 @@ public function pd_map_update_simple(&$o, &$p_data, &$d_data=[])
 	$tva_tx = static::_pd_map_tva_taux($p_data);
 	$tms = max($p_data['product']['date_upd'], (isset($d_data['product']['tms']) ?$d_data['product']['tms'] :0));
 
+	// product_supplier
+	if (!empty($p_data['product_supplier'])) foreach($p_data['product_supplier'] as $row) {
+		if ($p_data['product']['id_supplier']==$row['id_supplier'])
+			$supplier_ref = $row['product_supplier_reference'];
+	}
+
 	$d_data_map = [
 		'product' => [
-			'ref' => $p_data['product']['reference'],
+			'label' => $p_data['product_lang']['name'],
+			'description' => str_replace(['<p>', '</p>', '<br />'], ['', "\r\n", "\r\n"], strip_tags($p_data['product_lang']['description_short'], '<p><br>').(isset($p_data['garantie']) ?"GARANTIE : ".strip_tags($p_data['garantie']['content'], '<p><br>') :'')),
 			'tms' => $tms,
 			'cost_price' => $p_data['product']['wholesale_price'],
 			'price' => $p_data['product']['price'],
@@ -231,10 +312,24 @@ public function pd_map_update_simple(&$o, &$p_data, &$d_data=[])
 			'p_active' => $p_data['product']['active'],
 			'p_available_for_order' => $p_data['product']['available_for_order'],
 			'p_online_only' => $p_data['product']['online_only'],
-			'garantie' => (isset($p_data['garantie']) ?$p_data['garantie']['content'] :''),
+			'garantie' => (isset($p_data['garantie']) ?substr(strip_tags($p_data['garantie']['content']), 0, 255) :''),
+			'fk_soc_fournisseur' => static::_pd_map_fk('supplier', 'supplier', $p_data['product']['id_supplier']),
+			'supplier_ref' => (!empty($supplier_ref) ?$supplier_ref :NULL),
 		],
 	];
 
+	// Référence non nulle !
+	if (!empty($p_data['product']['reference']) && $p_data['product']['reference']!='NEW')
+		$d_data_map['product']['ref'] = $p_data['product']['reference'];
+
+	if (PUBLIC_PRICE) {
+		$d_data_map['product_extrafields']['public_price'] = (!empty($p_data['product']['recommended_public_price']) ?round($p_data['product']['recommended_public_price'], 2) :NULL);
+	}
+
+	if (ECOTAX) {
+		$d_data_map['product_extrafields']['ecotaxdeee'] = (!empty($p_data['product']['ecotax']) ?$p_data['product']['ecotax'] :NULL);
+	}
+
 	// Pack
 	$d_data_map['product_association'] = [];
 	if (isset($p_data['pack'])) {
@@ -257,7 +352,7 @@ public function pd_map_update_simple(&$o, &$p_data, &$d_data=[])
 	return $d_data_map;
 }
 public function pd_map_update_combi(&$o, &$p_data, &$d_data=[])
-{
+{	
 	$tva_tx = static::_pd_map_tva_taux($p_data);
 	$tms = max($p_data['product_attribute']['date_upd'], $p_data['product']['date_upd'], (isset($d_data['product']['tms']) ?$d_data['product']['tms'] :0));
 
@@ -267,10 +362,16 @@ public function pd_map_update_combi(&$o, &$p_data, &$d_data=[])
 		$attributes[] = static::$_p_attribute[$row['id_attribute']];
 	$attribute_names = implode(', ', $attributes);
 
+	// product_supplier
+	if (!empty($p_data['product_supplier'])) foreach($p_data['product_supplier'] as $row) {
+		if ($p_data['product']['id_supplier']==$row['id_supplier'])
+			$supplier_ref = $row['product_supplier_reference'];
+	}
+
 	$d_data_map = [
 		'product' => [
-			'ref' => $p_data['product_attribute']['reference'],
 			'label' => $p_data['product_lang']['name'].' - '.$attribute_names,
+			'description' => str_replace(['<p>', '</p>', '<br />'], ['', "\r\n", "\r\n"], strip_tags($p_data['product_lang']['description_short'], '<p><br>').(isset($p_data['garantie']) ?"GARANTIE : ".strip_tags($p_data['garantie']['content'], '<p><br>') :'')),
 			'tms' => $tms,
 			'cost_price' => $p_data['product_attribute']['wholesale_price'],
 			'price' => ($p_data['product']['price']+$p_data['product_attribute']['price']),
@@ -285,9 +386,23 @@ public function pd_map_update_combi(&$o, &$p_data, &$d_data=[])
 			'p_active' => $p_data['product']['active'],
 			'p_available_for_order' => $p_data['product']['available_for_order'],
 			'p_online_only' => $p_data['product']['online_only'],
-			'garantie' => (isset($p_data['garantie']) ?$p_data['garantie']['content'] :''),
+			'garantie' => (isset($p_data['garantie']) ?substr(strip_tags($p_data['garantie']['content']), 0, 255) :''),
+			'fk_soc_fournisseur' => static::_pd_map_fk('supplier', 'supplier', $p_data['product']['id_supplier']),
+			'supplier_ref' => (!empty($supplier_ref) ?$supplier_ref :NULL),
 		],
 	];
+
+	// Référence non nulle !
+	if (!empty($p_data['product_attribute']['reference']) && $p_data['product_attribute']['reference']!='NEW')
+		$d_data_map['product']['ref'] = $p_data['product_attribute']['reference'];
+
+	if (PUBLIC_PRICE) {
+		$d_data_map['product_extrafields']['public_price'] = (!empty($p_data['product_attribute']['recommended_public_price']) ?round($p_data['product_attribute']['recommended_public_price'], 2) :NULL);
+	}
+
+	if (ECOTAX) {
+		$d_data_map['product_extrafields']['ecotaxdeee'] = (!empty($p_data['product_attribute']['ecotax']) ?$p_data['product_attribute']['ecotax'] :NULL);
+	}
 	
 	return $d_data_map;
 }
@@ -306,13 +421,21 @@ public function pd_map_create_common(&$o, &$p_data)
 }
 public function pd_map_create_simple(&$o, &$p_data)
 {
+	// Le produit doit être enregistré proprement dans Prestashop
+	if (empty($p_data['product']['state']))
+		return;
+
+	// On doit spécifier qu'on veut créer la réf
 	if (empty($p_data['product']['reference']))
 		return;
 
+	$ref = ($p_data['product']['reference']!='NEW' ?$p_data['product']['reference'] :static::d_ref());
+	//var_dump($ref); die();
+
 	$d_data_map = [
 		'product' => [
 			//'rowid' => '',
-			'ref' => $p_data['product']['reference'],
+			'ref' => $ref,
 			'entity' => 1,
 			'ref_ext' => NULL,
 			'datec' => $p_data['product']['date_add'],
@@ -404,15 +527,20 @@ public function pd_map_create_simple(&$o, &$p_data)
 
 public function pd_map_create_combi(&$o, &$p_data)
 {
-	if (empty($p_data['product_attribute']['reference'])) {
-		sync_error("ERROR ".__METHOD__."($o[p_tref], $o[p_oid]) : missing reference");
+	// Le produit doit être enregistré proprement dans Prestashop
+	if (empty($p_data['product']['state']))
 		return;
-	}
-	
+
+	// On doit spécifier qu'on veut créer la réf
+	if (empty($p_data['product_attribute']['reference']))
+		return;
+
+	$ref = ($p_data['product_attribute']['reference']!='NEW' ?$p_data['product_attribute']['reference'] :static::d_ref());
+
 	$d_data_map = [
 		'product' => [
 			//'rowid' => '',
-			'ref' => $p_data['product_attribute']['reference'],
+			'ref' => $ref,
 			'entity' => 1,
 			'ref_ext' => NULL,
 			'datec' => max($p_data['product_attribute']['date_upd'], $p_data['product']['date_add']),

+ 4 - 0
src/sync/product_lot/common.inc.php

@@ -8,9 +8,13 @@ class sync_product_lot extends sync
 const MODEL_NAME='product_lot';
 const MODEL_ID = 9;
 const MAP_ID = 7;
+
 const D_TABLE_MAIN = 'product_lot';
+const D_TABLE_Q = ['batch'];
+
 const P_TABLE_MAIN = 'products_dlc_dluo';
 const P_TABLE_MAIN_ID = 'id';
+const P_TABLE_Q = ['numero_lot'];
 
 function d_data($otype, $oid)
 {

+ 65 - 18
src/sync/product_lot/dp.inc.php

@@ -29,17 +29,59 @@ public function osync($o)
 
 public function dp_update_more(&$o, &$p_data_map, &$p_data_map_create, &$p_data, &$d_data)
 {
-	// Décalage is_current_stock si on passe à 0
-	if (!empty($p_data['products_dlc_dluo'])) if ($p_data_map['products_dlc_dluo']['stock']==0 && $p_data['products_dlc_dluo']['stock']>0 && $p_data['products_dlc_dluo']['is_current_stock']==1) {
-		$sql = 'UPDATE ps_products_dlc_dluo
-			SET is_current_stock=0
-			WHERE id='.$o['p_oid'];
-		DB::p_update($sql);
-
-		$sql = 'UPDATE ps_products_dlc_dluo
-			SET is_current_stock=is_current_stock-1
-			WHERE id_product='.$p_data['products_dlc_dluo']['id_product'].' AND id_combinaison='.$p_data['products_dlc_dluo']['id_combinaison'].' AND is_current_stock>1';
-		DB::p_update($sql);
+	// Mise à jour is_current_stock
+	if (!empty($p_data['products_dlc_dluo'])) {
+		// Plus de stock : >0 => 0
+		if ($p_data_map['products_dlc_dluo']['stock']==0 && $p_data['products_dlc_dluo']['stock']>0) {
+			// Mise à 0 is_current_stock
+			$sql = 'UPDATE ps_products_dlc_dluo
+				SET is_current_stock=0
+				WHERE id='.$o['p_oid'];
+			DB::p_update($sql);
+			
+			// Décalage is_current_stock si on passe à 0
+			if ($p_data['products_dlc_dluo']['is_current_stock']>=1) {
+				$sql = 'UPDATE ps_products_dlc_dluo
+					SET is_current_stock=is_current_stock-1
+					WHERE id_product='.$p_data['products_dlc_dluo']['id_product'].' AND id_combinaison='.$p_data['products_dlc_dluo']['id_combinaison'].' AND is_current_stock>'.$p_data['products_dlc_dluo']['is_current_stock'];
+				DB::p_update($sql);
+			}
+		}
+		// Remise en stock : Stock 0 => >0
+		elseif ($p_data_map['products_dlc_dluo']['stock']>0 && $p_data['products_dlc_dluo']['stock']==0) {
+			// Recherche nouvel emplacement (ordre dluo)
+			$sql = 'SELECT id, is_current_stock, dlc, dluo
+				FROM ps_products_dlc_dluo
+				WHERE id_product='.$p_data['products_dlc_dluo']['id_product'].' AND id_combinaison='.$p_data['products_dlc_dluo']['id_combinaison'].' AND is_current_stock>0
+				ORDER BY is_current_stock';
+			$q = DB::p_select($sql);
+			$is_current_stock = 1;
+			while($row=$q->fetch_assoc()) {
+				// Remplacement
+				if ($p_data_map['products_dlc_dluo']['dluo']<$row['dluo']) {
+					$is_current_stock = $row['is_current_stock'];
+					// Décalage
+					$sql = 'UPDATE ps_products_dlc_dluo
+						SET is_current_stock=is_current_stock+1
+						WHERE id_product='.$p_data['products_dlc_dluo']['id_product'].' AND id_combinaison='.$p_data['products_dlc_dluo']['id_combinaison'].' AND is_current_stock>='.$is_current_stock;
+					DB::p_update($sql);
+					break;
+				}
+				// On laisse identique
+				elseif ($row['id']==$p_data['products_dlc_dluo']['id']) {
+					$is_current_stock = $row['is_current_stock'];
+					break;
+				}
+				// Suite
+				$is_current_stock = $row['is_current_stock']+1;
+			}
+			if ($is_current_stock != $p_data['products_dlc_dluo']['is_current_stock']) {
+				$sql = 'UPDATE ps_products_dlc_dluo
+					SET is_current_stock='.$is_current_stock.'
+					WHERE id='.$o['p_oid'];
+				DB::p_update($sql);
+			}
+		}
 	}
 
 	// Synchro stock global
@@ -79,13 +121,18 @@ public function map_create(&$o, &$d_data)
 	//var_dump($product);
 
 	// Position actuelle !
-	$rows = DB::p_get_rows('products_dlc_dluo', ['id_product'=>$product['id_product'], 'id_combinaison'=>$product['id_product_attribute']]);
-	$position = 1;
-	if (is_array($rows)) {
-		// @todo analyser et vérifier afin qu'on ait bien les bonnes valeurs...
-		foreach($rows as $row)
-			if ($row['is_current_stock']>0 && ($position <= $row['is_current_stock']))
-				$position = $row['is_current_stock']+1;
+	if ($d_data['product_batch']['qty']>0) {
+		$rows = DB::p_get_rows('products_dlc_dluo', ['id_product'=>$product['id_product'], 'id_combinaison'=>$product['id_product_attribute']]);
+		$position = 1;
+		if (is_array($rows)) {
+			// @todo analyser et vérifier afin qu'on ait bien les bonnes valeurs...
+			foreach($rows as $row)
+				if ($row['is_current_stock']>0 && ($position <= $row['is_current_stock']))
+					$position = $row['is_current_stock']+1;
+		}
+	}
+	else {
+		$position = 0;
 	}
 	//var_dump($position); var_dump($rows); die();
 

+ 3 - 1
src/sync/product_lot/pd.inc.php

@@ -43,7 +43,9 @@ public function pd_update_more(&$o, &$d_data_map, &$d_data_map_create, &$d_data,
 	$id = $o['d_oid'];
 	// @todo
 	
-	static::d_update_row('product_lot_extrafields', (!empty($d_data['product_lot_extrafields']) ?['rowid'=>$d_data['product_lot_extrafields']['rowid']] :['fk_object' => $id]), $d_data_map, $d_data_map_create, $d_data);
+	// product_lot_extrafields
+	static::d_update_row('product_lot_extrafields', ['fk_object'=>$id], $d_data_map, $d_data_map_create, $d_data);
+	
 	static::d_update_row('product_batch', (!empty($d_data['product_batch']) ?['rowid'=>$d_data['product_batch']['rowid']] :[]), $d_data_map, $d_data_map_create, $d_data);
 }
 

+ 8 - 2
src/sync/stock/dp.inc.php

@@ -7,11 +7,15 @@ class sync_stock_dp extends sync_stock
 
 public function execute_osync($otype, $oid)
 {
+	if (!STOCK_SYNC)
+		return;
 	return $this->dp_execute_osync($otype, $oid);
 }
 
 public function execute_create($otype, $oid)
 {
+	if (!STOCK_SYNC)
+		return;
 	return $this->create($otype, $oid);
 }
 
@@ -40,11 +44,13 @@ public function d_reserved_qty(&$o, &$d_data)
 	$fk_product = $d_data['product_stock']['fk_product'];
 
 	// Commandes brouilons et validées
-	// c.fk_statut IN (0, 1, 2) => brouillons, validés, envoi en cours
+	// c.fk_statut IN (0, 1, 2) => brouillons, validés, envoi en cours (brouillons aussi afin  !)
 	$sql = 'SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb, COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty
 		FROM llx_commandedet as cd
 		INNER JOIN llx_commande as c ON c.rowid = cd.fk_commande
-		WHERE cd.fk_product = '.$fk_product.' AND c.fk_statut in (0, 1, 2)';
+		LEFT JOIN llx_commande_extrafields c2 ON c2.fk_object=c.rowid
+		LEFT JOIN llx_ps_order_state st ON st.id_order_state=c2.p_state
+		WHERE cd.fk_product = '.$fk_product.' AND (c.fk_statut in (1, 2) OR (c.fk_statut=0 AND st.statut >= 1))';
 	$q = DB::d_select($sql);
 	if (!empty($cmd_row = $q->fetch_assoc()))
 		$qty += $cmd_row['qty'];

+ 4 - 0
src/sync/stock/pd.inc.php

@@ -7,11 +7,15 @@ class sync_stock_pd extends sync_stock
 
 public function execute_osync($otype, $oid)
 {
+	if (!STOCK_SYNC)
+		return;
 	return $this->pd_execute_osync($otype, $oid);
 }
 
 public function execute_create($otype, $oid)
 {
+	if (!STOCK_SYNC)
+		return;
 	return $this->create($otype, $oid);
 }
 

+ 6 - 3
src/sync/supplier/common.inc.php

@@ -8,13 +8,16 @@ class sync_supplier extends sync
 const MODEL_NAME = 'supplier';
 const MODEL_ID = 8;
 const MAP_ID = 3;
-const D_TABLE_MAIN = 'societe';
-const D_TABLE_MAIN_REF = 'code_fournisseur';
+
 const P_TABLE_MAIN = 'supplier';
 const P_TABLE_MAIN_ID = 'id_supplier';
 
+const D_TABLE_MAIN = 'societe';
+const D_TABLE_MAIN_REF = 'code_fournisseur';
+const D_REF_CODE = 'SU';
+const D_REF_LENGTH = 6;
+const D_REF_DATE = true;
 protected static $nb;
-const D_CODE = 'SU';
 
 function d_data($otype, $oid)
 {

+ 2 - 0
src/sync/supplier/pd.inc.php

@@ -164,6 +164,8 @@ public function map_create(&$o, &$p_data)
 		//'commandedet' => [],
 	];
 
+	//var_dump($d_data_map); die();
+
 	return $d_data_map;
 }
 

+ 17 - 2
src/sync/supplier_price/pd.inc.php

@@ -62,6 +62,10 @@ public function map_update(&$o, &$p_data, &$d_data=[])
 				'packaging' => 1,
 				'multicurrency_unitprice' => $p_data['product_supplier']['product_supplier_price_te'],
 			],
+			'product_extrafields' => [
+				//'fk_object' => static::_pd_map_fk_product($p_data),
+				'supplier_ref' => static::_pd_ref_fourn($p_data),
+			],
 		];
 	}
 
@@ -149,6 +153,17 @@ public static function _dp_map_tva_taux(&$orig_data, &$dest_tree=[])
 }
 
 public static function _pd_ref_fourn(&$orig_data, &$dest_tree=[])
+{
+	return (!empty($ref=static::_pd_ref_fourn_real($orig_data, $dest_tree)))
+		?$ref
+		:(
+			!empty($orig_data['product_attribute'])
+			?$orig_data['product_attribute']['reference']
+			:$orig_data['product']['reference']
+		);
+}
+
+public static function _pd_ref_fourn_real(&$orig_data, &$dest_tree=[])
 {
 	return (
 		!empty($orig_data['product_supplier']['product_supplier_reference'])
@@ -158,12 +173,12 @@ public static function _pd_ref_fourn(&$orig_data, &$dest_tree=[])
 			?(
 				!empty($orig_data['product_attribute']['ean13'])
 				?$orig_data['product_attribute']['ean13']
-				:$orig_data['product_attribute']['reference']
+				:NULL
 			)
 			:(
 				!empty($orig_data['product']['ean13'])
 				?$orig_data['product']['ean13']
-				:$orig_data['product']['reference']
+				:NULL
 			)
 		)
 	);

+ 53 - 40
src/sync/sync.inc.php

@@ -110,7 +110,7 @@ protected static function _attributes_load()
 		WHERE al.id_lang='.static::P_ID_LANG.' AND agl.id_lang='.static::P_ID_LANG ;
 	$q = DB::p_select($sql);
 	while($row=$q->fetch_assoc())
-		static::$_p_attribute[$row['id_attribute']] = $row['name2'].': '.$row['name'];
+		static::$_p_attribute[$row['id_attribute']] = ($row['name2'] ?$row['name2'].': ' :'').$row['name'];
 	//var_dump(static::$_p_attribute);
 }
 
@@ -312,16 +312,19 @@ public static function _slugify($text, string $divider='-')
 
 //protected static $nb;
 
-public static function _d_ref_nb($tablename, $fieldname, $str)
+public static function _d_ref_nb($tablename, $fieldname, $str, $length=6, $date_aff=true)
 {
 	$sql = 'SELECT rowid, MAX('.$fieldname.')
 		FROM llx_'.$tablename.'
-		WHERE '.$fieldname.' REGEXP "'.$str.'[0-9]{4}-[0-9]{6}"';
+		WHERE '.$fieldname.' REGEXP "'.$str.($date_aff ?'[0-9]{4}' :'').'-[0-9]{'.$length.'}"';
 	$q = DB::d_select($sql);
 	if ($q->num_rows) {
 		list($id, $ref) = $q->fetch_row();
-		$nb = (int)substr($ref, 7);
-		//var_dump($id); var_dump($ref); var_dump($date);
+		//var_dump($id); var_dump($ref);
+		if ($ref)
+			$nb = (int)substr($ref, strlen($str.($date_aff ?'YYMM' :''))+1);
+		else
+			$nb = 0;
 	}
 	else {
 		$nb = 0;
@@ -332,23 +335,26 @@ public static function _d_ref_nb($tablename, $fieldname, $str)
 }
 public static function d_ref_nb()
 {
-	static::$nb = static::_d_ref_nb(static::D_TABLE_MAIN, static::D_TABLE_MAIN_REF, static::D_CODE);
+	static::$nb = static::_d_ref_nb(static::D_TABLE_MAIN, static::D_TABLE_MAIN_REF, static::D_REF_CODE, static::D_REF_LENGTH, static::D_REF_DATE);
 	return static::$nb;
 }
 
-public static function _d_ref($date, $nb, $str)
+public static function _d_ref($nb, $str, $length=6, $date=NULL)
 {
 	$nb++;
-	for ($i=strlen($nb); $i<6; $i++)
+	for ($i=strlen($nb); $i<$length; $i++)
 		$nb = '0'.$nb;
-	$ref = $str.substr($date, 2, 2).substr($date, 5, 2).'-'.$nb;
+
+	$ref = $str.($date ?substr($date, 2, 2).substr($date, 5, 2) :'').'-'.$nb;
 	
 	return $ref;
 }
-public static function d_ref($date)
+public static function d_ref($date=NULL)
 {
 	$nb = static::d_ref_nb();
-	return static::_d_ref($date, $nb, static::D_CODE);
+	if (static::D_REF_DATE && empty($date))
+		$date = date('Y-m-d');
+	return static::_d_ref($nb, static::D_REF_CODE, static::D_REF_LENGTH, $date);
 }
 
 
@@ -356,6 +362,9 @@ public static function d_ref($date)
 
 public static function _dp_map_fk($modelname, $tablename, $id)
 {
+	if (empty($id))
+		return;
+	
 	if (!($o = static::d_o_oid($modelname, $tablename, $id))) {
 		$o = static::_action($modelname, 'dp', 'create', $tablename, $id);
 	}
@@ -366,6 +375,9 @@ public static function _dp_map_fk($modelname, $tablename, $id)
 }
 public static function _pd_map_fk($modelname, $tablename, $id)
 {
+	if (empty($id))
+		return;
+
 	if (!($o = static::p_o_oid($modelname, $tablename, $id))) {
 		$o = static::_action($modelname, 'pd', 'create', $tablename, $id);
 	}
@@ -376,6 +388,19 @@ public static function _pd_map_fk($modelname, $tablename, $id)
 }
 
 
+// -- NOTIF Sync TS --
+
+public static function _notif_ts($type, $otype, $oid)
+{
+	$date = date('Y-m-d H:i:s');
+	$sql = 'UPDATE `_sync`
+		SET `sync_ts`=NOW()
+		WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$otype.'" AND `t_oid`="'.$oid.'" AND `action` IN ("create", "osync")
+			AND `sync_ts` IS NULL AND `ts` <= "'.$date.'"';
+	return ($type=='p' ?DB::p_update($sql) :DB::d_update($sql));
+}
+
+
 // -- PD COMMON METHODS --
 
 
@@ -461,12 +486,7 @@ public function pd_create($otype, $oid)
 	$this->pd_update_more($o, $d_data_map_update, $d_data_map_create, $d_data, $p_data);
 
 	// Sync notif ts
-	$date = date('Y-m-d H:i:s');
-	$sql = 'UPDATE `_sync`
-		SET `sync_ts`=NOW()
-		WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$otype.'" AND `t_oid`="'.$oid.'" AND `action` IN ("create", "osync")
-			AND `sync_ts` IS NULL AND `ts` <= "'.$date.'"';
-	DB::p_update($sql);
+	static::_notif_ts('p', $otype, $oid);
 	
 	return $o;
 }
@@ -475,7 +495,8 @@ public function pd_insert_more(&$o, &$d_data_map, &$p_data)
 }
 public function pd_map_create(&$o, &$p_data)
 {
-	$o['d_tref'] = static::D_TABLE_MAIN;
+	if (empty($o['d_tref']))
+		$o['d_tref'] = static::D_TABLE_MAIN;
 	
 	return $this->map_create($o, $p_data);
 }
@@ -527,12 +548,7 @@ public function dp_create($otype, $oid)
 	$this->dp_update_more($o, $p_data_map_update, $p_data_map_create, $p_data, $d_data);
 	
 	// Sync notif ts
-	$date = date('Y-m-d H:i:s');
-	$sql = 'UPDATE `_sync`
-		SET `sync_ts`=NOW()
-		WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$o['d_tref'].'" AND `t_oid`="'.$o['d_oid'].'" AND `action` IN ("create", "osync")
-			AND `sync_ts` IS NULL AND `ts` <= "'.$date.'"';
-	DB::d_update($sql);
+	static::_notif_ts('d', $otype, $oid);
 
 	return $o;
 }
@@ -541,7 +557,8 @@ public function dp_insert_more(&$o, &$p_data_map, &$d_data)
 }
 public function dp_map_create(&$o, &$d_data)
 {
-	$o['p_tref'] = static::P_TABLE_MAIN;
+	if (empty($o['p_tref']))
+		$o['p_tref'] = static::P_TABLE_MAIN;
 	
 	return $this->map_create($o, $d_data);
 }
@@ -550,6 +567,7 @@ public function dp_map_create(&$o, &$d_data)
 public function pd_osync($o)
 {
 	var_dump($o);
+	
 	// Récupère données source
 	$p_data = $this->p_data($o['p_tref'], $o['p_oid']);
 	var_dump($p_data);
@@ -578,13 +596,7 @@ public function pd_osync($o)
 	$this->pd_update_more($o, $d_data_map, $d_data_map_create, $d_data, $p_data);
 
 	// Sync notif ts
-	$date = date('Y-m-d H:i:s');
-	$sql = 'UPDATE `_sync`
-		SET `sync_ts`=NOW()
-		WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$o['p_tref'].'" AND `t_oid`="'.$o['p_oid'].'" AND `action` IN ("create", "osync")
-			AND `sync_ts` IS NULL AND `ts` <= "'.$date.'"';
-	//trigger_error($sql);
-	DB::p_update($sql);
+	static::_notif_ts('p', $o['p_tref'], $o['p_oid']);
 	
 	return $o;
 }
@@ -598,7 +610,8 @@ public function pd_map_update(&$o, &$p_data, &$d_data=[])
 
 public function dp_osync($o)
 {
-
+	var_dump($o);
+	
 	// Récupère données source
 	$d_data = $this->d_data($o['d_tref'], $o['d_oid']);
 	var_dump($d_data);
@@ -611,6 +624,9 @@ public function dp_osync($o)
 	$p_data = $this->p_data($o['p_tref'], $o['p_oid']);
 	var_dump($p_data);
 	
+	//die();
+	//var_dump('dp_osync()'); var_dump($o);
+	
 	// Construit update
 	$p_data_map = $this->dp_map_update($o, $d_data, $p_data);
 	var_dump($p_data_map);
@@ -619,19 +635,14 @@ public function dp_osync($o)
 	$p_data_map_create = $this->dp_map_create($o, $d_data);
 
 	// Update base
+	var_dump('before base sync::p_update_row()'); var_dump($o);
 	static::p_update_row($o['p_tref'], [static::P_TABLE_ID[$o['p_tref']]=>$o['p_oid']], $p_data_map, $p_data_map_create, $p_data);
 
 	// Update more
 	$this->dp_update_more($o, $p_data_map, $p_data_map_create, $p_data, $d_data);
 	
 	// Sync notif ts
-	$date = date('Y-m-d H:i:s');
-	$sql = 'UPDATE `_sync`
-		SET `sync_ts`=NOW()
-		WHERE `type`="'.static::MODEL_NAME.'" AND `t_name`="'.$o['d_tref'].'" AND `t_oid`="'.$o['d_oid'].'" AND `action` IN ("create", "osync")
-			AND `sync_ts` IS NULL AND `ts` <= "'.$date.'"';
-	//var_dump(get_called_class()); var_dump($sql);
-	DB::d_update($sql);
+	static::_notif_ts('d', $o['d_tref'], $o['d_oid']);
 	
 	return $o;
 }
@@ -663,6 +674,8 @@ public function dp_delete($otype, $oid)
 {
 	$o = static::d_o_oid(static::MODEL_NAME, $otype, $oid);
 	if (!empty($o)) {
+		if (empty(static::P_TABLE_ID[$o['p_tref']]))
+			return;
 		//DB::d_delete_row($o['d_tref']], ['rowid'=>$o['d_oid']]);
 		DB::p_delete_row($o['p_tref'], [static::P_TABLE_ID[$o['p_tref']]=>$o['p_oid']]);
 		$sql = 'DELETE FROM _objects WHERE id='.$o['id'];

+ 160 - 32
src/update/product.inc.php

@@ -1,48 +1,176 @@
 <?php
 
-die();
-
-$file = file('../tmp/product.csv');
-$h = $row = explode(',', array_shift($file));
-var_dump($h);
-foreach($file as $l) {
-	$row = explode(',', $l);
-	var_dump($row);
-	
-	// product_attribute
-	if ($row[2]) {
-		$sql = 'UPDATE ps_product_attribute
-			SET wholesale_price='.$row[7].'
-			WHERE id_product_attribute='.$row[2];
+// Mise à jour prix d'achat depuis fichier
+if (isset($_GET['supplier_price'])) {
+	$file = file('../tmp/product.csv');
+	$h = $row = explode(',', array_shift($file));
+	var_dump($h);
+	foreach($file as $l) {
+		$row = explode(',', $l);
+		var_dump($row);
+		
+		// product_attribute
+		if ($row[2]) {
+			$sql = 'UPDATE ps_product_attribute
+				SET wholesale_price='.$row[7].'
+				WHERE id_product_attribute='.$row[2];
+			if (isset($_GET['go']))
+				DB::p_update($sql);
+			else
+				echo '<p>'.$sql.'</p>';
+		}
+		// product
+		else {
+			$sql = 'UPDATE ps_product
+				SET wholesale_price='.$row[7].'
+				WHERE id_product='.$row[1];
+			if (isset($_GET['go']))
+				DB::p_update($sql);
+			else
+				echo '<p>'.$sql.'</p>';
+			
+			$sql = 'UPDATE ps_product_shop
+				SET wholesale_price='.$row[7].'
+				WHERE id_product='.$row[1];
+			if (isset($_GET['go']))
+				DB::p_update($sql);
+			else
+				echo '<p>'.$sql.'</p>';
+		}
+		
+		$sql = 'UPDATE ps_product_supplier
+			SET product_supplier_price_te='.$row[5].'
+			WHERE id_product_supplier='.$row[0];
 		if (isset($_GET['go']))
 			DB::p_update($sql);
 		else
 			echo '<p>'.$sql.'</p>';
 	}
-	// product
-	else {
-		$sql = 'UPDATE ps_product
-			SET wholesale_price='.$row[7].'
-			WHERE id_product='.$row[1];
+}
+
+// Mise à jour rowid table product Dolibarr
+if (isset($_GET['rowid'])) {
+	//$id = 2501;
+	$id = 1841;
+
+	$sql = 'SELECT *
+		FROM `llx_product`
+		WHERE rowid>=3000'; // >=3000
+	$q = DB::d_select($sql);
+	while($row=$q->fetch_assoc()) {
+		$id++;
+
+		echo '<p>PRODUCT ROWID '.$row['rowid'].' REF '.$row['ref'].'</p>';
+		// Recherche Synchro
+		$sql = 'SELECT 1
+			FROM `_objects_d`
+			WHERE tid=1 AND oid='.$row['rowid'];
+		$q2 = DB::o_select($sql);
+		if (!$q2->num_rows) {
+			echo '<p>ERROR NO SYNC fk_product '.$row['rowid'].'</p>';
+			continue;
+		}
+
+
+		// Modif ref pour s'en sortir
+		$sql = 'UPDATE `llx_product`
+			SET ref=CONCAT(ref,"-DEBUG"), barcode=NULL
+			WHERE rowid='.$row['rowid'];
 		if (isset($_GET['go']))
-			DB::p_update($sql);
+			DB::d_update($sql);
 		else
 			echo '<p>'.$sql.'</p>';
+
+		// Insertion nouvelle ligne
+		$sql = 'INSERT INTO `llx_product`
+			(`rowid`, `ref`, `barcode`';
+		foreach($row as $i=>$j) if (!in_array($i, ['rowid', 'ref', 'barcode']))
+				$sql .= ', `'.$i.'`';
+		$sql .= ') SELECT '.$id.', "'.$row['ref'].'", '.(is_null($row['barcode']) ?'NULL' :'"'.$row['barcode'].'"');
+		foreach($row as $i=>$j) if (!in_array($i, ['rowid', 'ref', 'barcode']))
+			$sql .= ', `'.$i.'`';
+		$sql .= ' FROM `llx_product` WHERE rowid='.$row['rowid'];
+		if (isset($_GET['go']))
+			DB::d_insert($sql);
+		else
+			echo '<p>'.$sql.'</p>';
+
+		// Mise à jour tables connectées
 		
-		$sql = 'UPDATE ps_product_shop
-			SET wholesale_price='.$row[7].'
-			WHERE id_product='.$row[1];
+		foreach(['bom_bom', 'bom_bomline', 'categorie_product', 'commandedet', 'commande_fournisseurdet', 'commande_fournisseur_dispatch', 'contratdet', 'deliverydet', 'facturedet', 'facturedet_rec', 'facture_fourn_det', 'fichinterdet_rec', 'inventory', 'inventorydet', 'mrp_mo', 'mrp_production', 'product_customer_price', 'product_customer_price_log', 'product_fournisseur_price', 'product_lang', 'product_lot', 'product_perentity', 'product_price', 'product_stock', 'product_warehouse_properties', 'propaldet', 'propal_merge_pdf_product', 'stock_mouvement', 'supplier_proposaldet'] as $tablename) {
+			// Nbre rows concernés
+			$sql = 'SELECT *
+				FROM llx_'.$tablename.'
+				WHERE fk_product='.$row['rowid'];
+			$q2 = DB::d_select($sql);
+
+			// Modifications
+			$sql = 'UPDATE llx_'.$tablename.'
+				SET fk_product='.$id.' WHERE fk_product='.$row['rowid'];
+			if (isset($_GET['go']))
+				DB::d_update($sql);
+			else
+				echo '<p>'.$sql.'</p>';
+		}
+
+		// product_association
+		$tablename = 'product_association';
+		// Nbre rows concernés
+		$sql = 'SELECT *
+			FROM llx_'.$tablename.'
+			WHERE fk_product_pere='.$row['rowid'];
+		$q2 = DB::d_select($sql);
+		// Modifications
+		$sql = 'UPDATE llx_'.$tablename.'
+			SET fk_product_pere='.$id.' WHERE fk_product_pere='.$row['rowid'];
 		if (isset($_GET['go']))
-			DB::p_update($sql);
+			DB::d_update($sql);
+		else
+			echo '<p>'.$sql.'</p>';
+		// Nbre rows concernés
+		$sql = 'SELECT *
+			FROM llx_'.$tablename.'
+			WHERE fk_product_fils='.$row['rowid'];
+		$q2 = DB::d_select($sql);
+		// Modifications
+		$sql = 'UPDATE llx_'.$tablename.'
+			SET fk_product_fils='.$id.' WHERE fk_product_fils='.$row['rowid'];
+		if (isset($_GET['go']))
+			DB::d_update($sql);
 		else
 			echo '<p>'.$sql.'</p>';
+
+		// product_attribute_combination
+		$tablename = 'product_attribute_combination';
+		// Nbre rows concernés
+		$sql = 'SELECT *
+			FROM llx_'.$tablename.'
+			WHERE fk_product_parent='.$row['rowid'];
+		$q2 = DB::d_select($sql);
+		// Nbre rows concernés
+		$sql = 'SELECT *
+			FROM llx_'.$tablename.'
+			WHERE fk_product_child='.$row['rowid'];
+		$q2 = DB::d_select($sql);
+
+		// Suppression ancienne ligne
+		$sql = 'DELETE FROM `llx_product`
+			WHERE rowid='.$row['rowid'];
+		if (isset($_GET['go']))
+			DB::d_update($sql);
+		else
+			echo '<p>'.$sql.'</p>';
+
+		// Synchro
+		$sql = 'UPDATE `_objects_d`
+			SET oid='.$id.'
+			WHERE tid=1 AND oid='.$row['rowid'];
+		if (isset($_GET['go']))
+			DB::o_update($sql);
+		else
+			echo '<p>'.$sql.'</p>';
+
+		// STOP TEST
+		//break;
 	}
-	
-	$sql = 'UPDATE ps_product_supplier
-		SET product_supplier_price_te='.$row[5].'
-		WHERE id_product_supplier='.$row[0];
-	if (isset($_GET['go']))
-		DB::p_update($sql);
-	else
-		echo '<p>'.$sql.'</p>';
 }

+ 18 - 0
web/list.php

@@ -0,0 +1,18 @@
+<?php
+
+require_once "bootstrap.inc.php";
+require_once('../src/sync/common.inc.php');
+
+$options = ['products'];
+
+echo '<p>';
+foreach($options as $option)
+	echo '<a href="?t='.$option.'">'.$option.'</a> | ';
+echo '</p>';
+
+if (empty($_GET['t']))
+	die('param t required');
+	
+if (in_array($_GET['t'], $options))
+	require_once('../src/list/'.$_GET['t'].'.inc.php');
+

+ 18 - 0
web/manual.php

@@ -0,0 +1,18 @@
+<?php
+
+require_once "bootstrap.inc.php";
+require_once('../src/sync/common.inc.php');
+
+$options = ['supplier', 'product', 'product_lot', 'supplier_price', 'customer', 'address', 'order'];
+
+echo '<p>';
+foreach($options as $option)
+	echo '<a href="?t='.$option.'">'.$option.'</a> | ';
+echo '</p>';
+
+if (empty($_GET['t']))
+	die('param t required');
+	
+if (in_array($_GET['t'], $options))
+	require_once('../src/manual/'.$_GET['t'].'.inc.php');
+

+ 0 - 0
web/phpinfo_lemathou.php → web/phpinfo_mmi.php


+ 18 - 0
web/send.php

@@ -0,0 +1,18 @@
+<?php
+
+require_once "bootstrap.inc.php";
+require_once('../src/sync/common.inc.php');
+
+$options = ['devis_form'];
+
+echo '<p>';
+foreach($options as $option)
+	echo '<a href="?t='.$option.'">'.$option.'</a> | ';
+echo '</p>';
+
+if (empty($_GET['t']))
+	die('param t required');
+	
+if (in_array($_GET['t'], $options))
+	require_once('../src/send/'.$_GET['t'].'.inc.php');
+