Browse Source

Plugin ready for qualification

Ghislain Loaec 5 years ago
parent
commit
27ac159a2b

class/societephcpproduct.class.php → class/compteur.class.php View File

@@ -17,39 +17,40 @@
17 17
  */
18 18
 
19 19
 /**
20
- *  \file       dev/skeletons/societephcpproduct.class.php
20
+ *  \file       dev/skeletons/compteur.class.php
21 21
  *  \ingroup    mymodule othermodule1 othermodule2
22 22
  *  \brief      This file is an example for a CRUD class file (Create/Read/Update/Delete)
23
- *				Initialy built by build_class_from_table on 2013-09-12 16:47
23
+ *				Initialy built by build_class_from_table on 2013-09-19 10:38
24 24
  */
25 25
 
26 26
 // Put here all includes required by your class file
27 27
 require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
28
-//require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
29
-//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
28
+require_once(DOL_DOCUMENT_ROOT."/photocopies/class/phcp.class.php");
29
+require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
30 30
 
31 31
 
32 32
 /**
33 33
  *	Put here description of your class
34 34
  */
35
-class Societephcpproduct extends CommonObject
35
+class Compteur extends CommonObject
36 36
 {
37 37
 	var $db;							//!< To store db handler
38 38
 	var $error;							//!< To return error code (or message)
39 39
 	var $errors=array();				//!< To return several error codes (or messages)
40
-	var $element='societephcpproduct';			//!< Id that identify managed objects
41
-	var $table_element='societephcpproduct';		//!< Name of table without prefix where object is stored
40
+	var $element='compteur';			//!< Id that identify managed objects
41
+	var $table_element='compteur';		//!< Name of table without prefix where object is stored
42 42
 
43 43
     var $id;
44 44
     
45
-	var $societe_phcp_product_number;
46
-	var $entity;
47
-	var $ref_ext;
48
-	var $ref_int;
49
-	var $fk_phcp;
50
-	var $fk_societe;
45
+	var $ref;
46
+	var $updated_at='';
47
+	var $created_at='';
48
+	var $compteur;
49
+	var $last_compteur;
50
+  var $fk_phcp;
51
+  var $phcp;
51 52
 	var $fk_product;
52
-
53
+  var $product;
53 54
     
54 55
 
55 56
 
@@ -79,39 +80,43 @@ class Societephcpproduct extends CommonObject
79 80
 
80 81
 		// Clean parameters
81 82
         
82
-		if (isset($this->societe_phcp_product_number)) $this->societe_phcp_product_number=trim($this->societe_phcp_product_number);
83
-		if (isset($this->entity)) $this->entity=trim($this->entity);
84
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
85
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
86
-		if (isset($this->fk_phcp)) $this->fk_phcp=trim($this->fk_phcp);
87
-		if (isset($this->fk_societe)) $this->fk_societe=trim($this->fk_societe);
88
-		if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
89
-
83
+		if (isset($this->ref)) $this->ref=trim($this->ref);
84
+		if (isset($this->compteur)) $this->compteur=trim($this->compteur);
85
+		if (isset($this->last_compteur)) $this->last_compteur=trim($this->last_compteur);
86
+    if (isset($this->fk_phcp)){
87
+      $this->fk_phcp=trim($this->fk_phcp);
88
+      $this->phcp=new Phcp($this->db);
89
+      $this->phcp->fetch($this->fk_phcp);
90
+    }
91
+    if (isset($this->fk_product)){
92
+      $this->fk_product=trim($this->fk_product);
93
+      $this->product=new Product($this->db);
94
+      $this->product->fetch($this->fk_product);
95
+    }
90 96
         
91 97
 
92 98
 		// Check parameters
93 99
 		// Put here code to add control on parameters values
94 100
 
95 101
         // Insert request
96
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_phcp_product(";
102
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."compteur(";
97 103
 		
98
-		$sql.= "societe_phcp_product_number,";
99
-		$sql.= "entity,";
100
-		$sql.= "ref_ext,";
101
-		$sql.= "ref_int,";
104
+		$sql.= "ref,";
105
+		$sql.= "updated_at,";
106
+		$sql.= "created_at,";
107
+		$sql.= "compteur,";
108
+		$sql.= "last_compteur,";
102 109
 		$sql.= "fk_phcp,";
103
-		$sql.= "fk_societe,";
104 110
 		$sql.= "fk_product";
105 111
 
106 112
 		
107 113
         $sql.= ") VALUES (";
108 114
         
109
-		$sql.= " ".(! isset($this->societe_phcp_product_number)?'NULL':"'".$this->db->escape($this->societe_phcp_product_number)."'").",";
110
-		$sql.= " ".(! isset($this->entity)?'NULL':"'".$this->entity."'").",";
111
-		$sql.= " ".(! isset($this->ref_ext)?'NULL':"'".$this->db->escape($this->ref_ext)."'").",";
112
-		$sql.= " ".(! isset($this->ref_int)?'NULL':"'".$this->db->escape($this->ref_int)."'").",";
115
+		$sql.= " ".(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").",";
116
+		$sql.= " ".(! isset($this->created_at) || dol_strlen($this->created_at)==0?'NULL':$this->db->idate($this->created_at)).",";
117
+		$sql.= " ".(! isset($this->compteur)?'NULL':"'".$this->compteur."'").",";
118
+		$sql.= " ".(! isset($this->last_compteur)?'NULL':"'".$this->last_compteur."'").",";
113 119
 		$sql.= " ".(! isset($this->fk_phcp)?'NULL':"'".$this->fk_phcp."'").",";
114
-		$sql.= " ".(! isset($this->fk_societe)?'NULL':"'".$this->fk_societe."'").",";
115 120
 		$sql.= " ".(! isset($this->fk_product)?'NULL':"'".$this->fk_product."'")."";
116 121
 
117 122
         
@@ -125,7 +130,7 @@ class Societephcpproduct extends CommonObject
125 130
 
126 131
 		if (! $error)
127 132
         {
128
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_phcp_product");
133
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."compteur");
129 134
 
130 135
 			if (! $notrigger)
131 136
 			{
@@ -172,16 +177,16 @@ class Societephcpproduct extends CommonObject
172 177
         $sql = "SELECT";
173 178
 		$sql.= " t.rowid,";
174 179
 		
175
-		$sql.= " t.societe_phcp_product_number,";
176
-		$sql.= " t.entity,";
177
-		$sql.= " t.ref_ext,";
178
-		$sql.= " t.ref_int,";
180
+		$sql.= " t.ref,";
181
+		$sql.= " t.updated_at,";
182
+		$sql.= " t.created_at,";
183
+		$sql.= " t.compteur,";
184
+		$sql.= " t.last_compteur,";
179 185
 		$sql.= " t.fk_phcp,";
180
-		$sql.= " t.fk_societe,";
181 186
 		$sql.= " t.fk_product";
182 187
 
183 188
 		
184
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe_phcp_product as t";
189
+        $sql.= " FROM ".MAIN_DB_PREFIX."compteur as t";
185 190
         $sql.= " WHERE t.rowid = ".$id;
186 191
 
187 192
     	dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
@@ -194,13 +199,25 @@ class Societephcpproduct extends CommonObject
194 199
 
195 200
                 $this->id    = $obj->rowid;
196 201
                 
197
-				$this->societe_phcp_product_number = $obj->societe_phcp_product_number;
198
-				$this->entity = $obj->entity;
199
-				$this->ref_ext = $obj->ref_ext;
200
-				$this->ref_int = $obj->ref_int;
202
+				$this->ref = $obj->ref;
203
+				$this->updated_at = $this->db->jdate($obj->updated_at);
204
+				$this->created_at = $this->db->jdate($obj->created_at);
205
+				$this->compteur = $obj->compteur;
206
+				$this->last_compteur = $obj->last_compteur;
201 207
 				$this->fk_phcp = $obj->fk_phcp;
202
-				$this->fk_societe = $obj->fk_societe;
208
+        if (isset($this->fk_phcp)){
209
+          if(!isset($this->phcp)){
210
+            $this->phcp=new Phcp($this->db);
211
+            $this->phcp->fetch($this->fk_phcp);
212
+          }
213
+        }
203 214
 				$this->fk_product = $obj->fk_product;
215
+        if (isset($this->fk_product)){
216
+          if(!isset($this->product)){
217
+            $this->product=new Product($this->db);
218
+            $this->product->fetch($this->fk_product);
219
+          }
220
+        }
204 221
 
205 222
                 
206 223
             }
@@ -231,13 +248,19 @@ class Societephcpproduct extends CommonObject
231 248
 
232 249
 		// Clean parameters
233 250
         
234
-		if (isset($this->societe_phcp_product_number)) $this->societe_phcp_product_number=trim($this->societe_phcp_product_number);
235
-		if (isset($this->entity)) $this->entity=trim($this->entity);
236
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
237
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
238
-		if (isset($this->fk_phcp)) $this->fk_phcp=trim($this->fk_phcp);
239
-		if (isset($this->fk_societe)) $this->fk_societe=trim($this->fk_societe);
240
-		if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
251
+		if (isset($this->ref)) $this->ref=trim($this->ref);
252
+		//if (isset($this->compteur)) $this->compteur=trim($this->compteur);
253
+		//if (isset($this->last_compteur)) $this->last_compteur=trim($this->last_compteur);
254
+    if (isset($this->fk_phcp)){
255
+      $this->fk_phcp=trim($this->fk_phcp);
256
+      $this->phcp=new Phcp($this->db);
257
+      $this->phcp->fetch($this->fk_phcp);
258
+    }
259
+    if (isset($this->fk_product)){
260
+      $this->fk_product=trim($this->fk_product);
261
+      $this->product=new Product($this->db);
262
+      $this->product->fetch($this->fk_product);
263
+    }
241 264
 
242 265
         
243 266
 
@@ -245,14 +268,12 @@ class Societephcpproduct extends CommonObject
245 268
 		// Put here code to add a control on parameters values
246 269
 
247 270
         // Update request
248
-        $sql = "UPDATE ".MAIN_DB_PREFIX."societe_phcp_product SET";
271
+        $sql = "UPDATE ".MAIN_DB_PREFIX."compteur SET";
249 272
         
250
-		$sql.= " societe_phcp_product_number=".(isset($this->societe_phcp_product_number)?"'".$this->db->escape($this->societe_phcp_product_number)."'":"null").",";
251
-		$sql.= " entity=".(isset($this->entity)?$this->entity:"null").",";
252
-		$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
253
-		$sql.= " ref_int=".(isset($this->ref_int)?"'".$this->db->escape($this->ref_int)."'":"null").",";
273
+		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
274
+		$sql.= " compteur=".(isset($this->compteur)?$this->compteur:"null").",";
275
+		$sql.= " last_compteur=".(isset($this->last_compteur)?$this->last_compteur:"null").",";
254 276
 		$sql.= " fk_phcp=".(isset($this->fk_phcp)?$this->fk_phcp:"null").",";
255
-		$sql.= " fk_societe=".(isset($this->fk_societe)?$this->fk_societe:"null").",";
256 277
 		$sql.= " fk_product=".(isset($this->fk_product)?$this->fk_product:"null")."";
257 278
 
258 279
         
@@ -331,7 +352,7 @@ class Societephcpproduct extends CommonObject
331 352
 
332 353
 		if (! $error)
333 354
 		{
334
-    		$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_phcp_product";
355
+    		$sql = "DELETE FROM ".MAIN_DB_PREFIX."compteur";
335 356
     		$sql.= " WHERE rowid=".$this->id;
336 357
 
337 358
     		dol_syslog(get_class($this)."::delete sql=".$sql);
@@ -353,6 +374,8 @@ class Societephcpproduct extends CommonObject
353 374
 		else
354 375
 		{
355 376
 			$this->db->commit();
377
+      $this->product = null;
378
+      $this->phcp = null;
356 379
 			return 1;
357 380
 		}
358 381
 	}
@@ -371,7 +394,7 @@ class Societephcpproduct extends CommonObject
371 394
 
372 395
 		$error=0;
373 396
 
374
-		$object=new Societephcpproduct($this->db);
397
+		$object=new Compteur($this->db);
375 398
 
376 399
 		$this->db->begin();
377 400
 
@@ -423,14 +446,15 @@ class Societephcpproduct extends CommonObject
423 446
 	{
424 447
 		$this->id=0;
425 448
 		
426
-		$this->societe_phcp_product_number='';
427
-		$this->entity='';
428
-		$this->ref_ext='';
429
-		$this->ref_int='';
449
+		$this->ref='';
450
+		$this->updated_at='';
451
+		$this->created_at='';
452
+		$this->compteur='';
453
+		$this->last_compteur='';
430 454
 		$this->fk_phcp='';
431
-		$this->fk_societe='';
432 455
 		$this->fk_product='';
433
-
456
+    $this->phcp = null;
457
+    $this->product = null;
434 458
 		
435 459
 	}
436 460
 

+ 0
- 351
class/myclass.class.php View File

@@ -1,351 +0,0 @@
1
-<?php
2
-/* <one line to give the program's name and a brief idea of what it does.>
3
- * Copyright (C) <year>  <name of author>
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
-/**
20
- * 	\file		class/myclass.class.php
21
- * 	\ingroup	mymodule
22
- * 	\brief		This file is an example CRUD class file (Create/Read/Update/Delete)
23
- * 				Put some comments here
24
- */
25
-// Put here all includes required by your class file
26
-//require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
27
-//require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
28
-//require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
29
-
30
-/**
31
- * Put your class' description here
32
- */
33
-class SkeletonClass // extends CommonObject
34
-{
35
-
36
-    private $db; //!< To store db handler
37
-    public $error; //!< To return error code (or message)
38
-    public $errors = array(); //!< To return several error codes (or messages)
39
-    //public $element='skeleton';	//!< Id that identify managed objects
40
-    //public $table_element='skeleton';	//!< Name of table without prefix where object is stored
41
-    public $id;
42
-    public $prop1;
43
-    public $prop2;
44
-
45
-    /**
46
-     * Constructor
47
-     *
48
-     * 	@param	DoliDb		$db		Database handler
49
-     */
50
-    public function __construct($db)
51
-    {
52
-        $this->db = $db;
53
-
54
-        return 1;
55
-    }
56
-
57
-    /**
58
-     * Create object into database
59
-     *
60
-     * 	@param		User	$user		User that create
61
-     * 	@param		int		$notrigger	0=launch triggers after, 1=disable triggers
62
-     * 	@return		int					<0 if KO, Id of created object if OK
63
-     */
64
-    public function create($user, $notrigger = 0)
65
-    {
66
-        global $conf, $langs;
67
-        $error = 0;
68
-
69
-        // Clean parameters
70
-        if (isset($this->prop1)) {
71
-            $this->prop1 = trim($this->prop1);
72
-        }
73
-        if (isset($this->prop2)) {
74
-            $this->prop2 = trim($this->prop2);
75
-        }
76
-
77
-        // Check parameters
78
-        // Put here code to add control on parameters values
79
-        // Insert request
80
-        $sql = "INSERT INTO " . MAIN_DB_PREFIX . "mytable(";
81
-        $sql.= " field1,";
82
-        $sql.= " field2";
83
-
84
-        $sql.= ") VALUES (";
85
-        $sql.= " '" . $this->prop1 . "',";
86
-        $sql.= " '" . $this->prop2 . "'";
87
-
88
-        $sql.= ")";
89
-
90
-        $this->db->begin();
91
-
92
-        dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
93
-        $resql = $this->db->query($sql);
94
-        if (! $resql) {
95
-            $error ++;
96
-            $this->errors[] = "Error " . $this->db->lasterror();
97
-        }
98
-
99
-        if (! $error) {
100
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "mytable");
101
-
102
-            if (! $notrigger) {
103
-                // Uncomment this and change MYOBJECT to your own tag if you
104
-                // want this action call a trigger.
105
-                //// Call triggers
106
-                //include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
107
-                //$interface=new Interfaces($this->db);
108
-                //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
109
-                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
110
-                //// End call triggers
111
-            }
112
-        }
113
-
114
-        // Commit or rollback
115
-        if ($error) {
116
-            foreach ($this->errors as $errmsg) {
117
-                dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
118
-                $this->error.=($this->error ? ', ' . $errmsg : $errmsg);
119
-            }
120
-            $this->db->rollback();
121
-
122
-            return -1 * $error;
123
-        } else {
124
-            $this->db->commit();
125
-
126
-            return $this->id;
127
-        }
128
-    }
129
-
130
-    /**
131
-     * Load object in memory from database
132
-     *
133
-     * 	@param		int		$id	Id object
134
-     * 	@return		int			<0 if KO, >0 if OK
135
-     */
136
-    public function fetch($id)
137
-    {
138
-        global $langs;
139
-        $sql = "SELECT";
140
-        $sql.= " t.rowid,";
141
-        $sql.= " t.field1,";
142
-        $sql.= " t.field2";
143
-        //...
144
-        $sql.= " FROM " . MAIN_DB_PREFIX . "mytable as t";
145
-        $sql.= " WHERE t.rowid = " . $id;
146
-
147
-        dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
148
-        $resql = $this->db->query($sql);
149
-        if ($resql) {
150
-            if ($this->db->num_rows($resql)) {
151
-                $obj = $this->db->fetch_object($resql);
152
-
153
-                $this->id = $obj->rowid;
154
-                $this->prop1 = $obj->field1;
155
-                $this->prop2 = $obj->field2;
156
-                //...
157
-            }
158
-            $this->db->free($resql);
159
-
160
-            return 1;
161
-        } else {
162
-            $this->error = "Error " . $this->db->lasterror();
163
-            dol_syslog(get_class($this) . "::fetch " . $this->error, LOG_ERR);
164
-
165
-            return -1;
166
-        }
167
-    }
168
-
169
-    /**
170
-     * Update object into database
171
-     *
172
-     * 	@param		User	$user		User that modify
173
-     * 	@param		int		$notrigger	0=launch triggers after, 1=disable triggers
174
-     * 	@return		int					<0 if KO, >0 if OK
175
-     */
176
-    public function update($user = 0, $notrigger = 0)
177
-    {
178
-        global $conf, $langs;
179
-        $error = 0;
180
-
181
-        // Clean parameters
182
-        if (isset($this->prop1)) {
183
-            $this->prop1 = trim($this->prop1);
184
-        }
185
-        if (isset($this->prop2)) {
186
-            $this->prop2 = trim($this->prop2);
187
-        }
188
-
189
-        // Check parameters
190
-        // Put here code to add control on parameters values
191
-        // Update request
192
-        $sql = "UPDATE " . MAIN_DB_PREFIX . "mytable SET";
193
-        $sql.= " field1=" . (isset($this->field1) ? "'" . $this->db->escape($this->field1) . "'" : "null") . ",";
194
-        $sql.= " field2=" . (isset($this->field2) ? "'" . $this->db->escape($this->field2) . "'" : "null") . "";
195
-
196
-        $sql.= " WHERE rowid=" . $this->id;
197
-
198
-        $this->db->begin();
199
-
200
-        dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
201
-        $resql = $this->db->query($sql);
202
-        if (! $resql) {
203
-            $error ++;
204
-            $this->errors[] = "Error " . $this->db->lasterror();
205
-        }
206
-
207
-        if (! $error) {
208
-            if (! $notrigger) {
209
-                // Uncomment this and change MYOBJECT to your own tag if you
210
-                // want this action call a trigger.
211
-                //// Call triggers
212
-                //include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
213
-                //$interface=new Interfaces($this->db);
214
-                //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
215
-                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
216
-                //// End call triggers
217
-            }
218
-        }
219
-
220
-        // Commit or rollback
221
-        if ($error) {
222
-            foreach ($this->errors as $errmsg) {
223
-                dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR);
224
-                $this->error.=($this->error ? ', ' . $errmsg : $errmsg);
225
-            }
226
-            $this->db->rollback();
227
-
228
-            return -1 * $error;
229
-        } else {
230
-            $this->db->commit();
231
-
232
-            return 1;
233
-        }
234
-    }
235
-
236
-    /**
237
-     * Delete object in database
238
-     *
239
-     * 	@param		User	$user		User that delete
240
-     * 	@param		int		$notrigger	0=launch triggers after, 1=disable triggers
241
-     * 	@return		int					<0 if KO, >0 if OK
242
-     */
243
-    public function delete($user, $notrigger = 0)
244
-    {
245
-        global $conf, $langs;
246
-        $error = 0;
247
-
248
-        $this->db->begin();
249
-
250
-        if (! $error) {
251
-            if (! $notrigger) {
252
-                // Uncomment this and change MYOBJECT to your own tag if you
253
-                // want this action call a trigger.
254
-                //// Call triggers
255
-                //include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
256
-                //$interface=new Interfaces($this->db);
257
-                //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
258
-                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
259
-                //// End call triggers
260
-            }
261
-        }
262
-
263
-        if (! $error) {
264
-            $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mytable";
265
-            $sql.= " WHERE rowid=" . $this->id;
266
-
267
-            dol_syslog(get_class($this) . "::delete sql=" . $sql);
268
-            $resql = $this->db->query($sql);
269
-            if (! $resql) {
270
-                $error ++;
271
-                $this->errors[] = "Error " . $this->db->lasterror();
272
-            }
273
-        }
274
-
275
-        // Commit or rollback
276
-        if ($error) {
277
-            foreach ($this->errors as $errmsg) {
278
-                dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
279
-                $this->error.=($this->error ? ', ' . $errmsg : $errmsg);
280
-            }
281
-            $this->db->rollback();
282
-
283
-            return -1 * $error;
284
-        } else {
285
-            $this->db->commit();
286
-
287
-            return 1;
288
-        }
289
-    }
290
-
291
-    /**
292
-     * Load an object from its id and create a new one in database
293
-     *
294
-     * 	@param		int		$fromid		Id of object to clone
295
-     * 	@return		int					New id of clone
296
-     */
297
-    public function createFromClone($fromid)
298
-    {
299
-        global $user, $langs;
300
-
301
-        $error = 0;
302
-
303
-        $object = new SkeletonClass($this->db);
304
-
305
-        $this->db->begin();
306
-
307
-        // Load source object
308
-        $object->fetch($fromid);
309
-        $object->id = 0;
310
-        $object->statut = 0;
311
-
312
-        // Clear fields
313
-        // ...
314
-        // Create clone
315
-        $result = $object->create($user);
316
-
317
-        // Other options
318
-        if ($result < 0) {
319
-            $this->error = $object->error;
320
-            $error ++;
321
-        }
322
-
323
-        if (! $error) {
324
-            // Do something
325
-        }
326
-
327
-        // End
328
-        if (! $error) {
329
-            $this->db->commit();
330
-
331
-            return $object->id;
332
-        } else {
333
-            $this->db->rollback();
334
-
335
-            return -1;
336
-        }
337
-    }
338
-
339
-    /**
340
-     * Initialise object with example values
341
-     * Id must be 0 if object instance is a specimen
342
-     *
343
-     * 	@return		void
344
-     */
345
-    public function initAsSpecimen()
346
-    {
347
-        $this->id = 0;
348
-        $this->prop1 = 'prop1';
349
-        $this->prop2 = 'prop2';
350
-    }
351
-}

+ 86
- 7
class/phcp.class.php View File

@@ -26,7 +26,7 @@
26 26
 // Put here all includes required by your class file
27 27
 require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
28 28
 require_once(DOL_DOCUMENT_ROOT."/photocopies/class/phcptype.class.php");
29
-//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
29
+require_once(DOL_DOCUMENT_ROOT."/photocopies/class/compteur.class.php");
30 30
 
31 31
 
32 32
 /**
@@ -40,7 +40,7 @@ class Phcp extends CommonObject
40 40
 	var $element='phcp';			//!< Id that identify managed objects
41 41
 	var $table_element='phcp';		//!< Name of table without prefix where object is stored
42 42
 
43
-    var $id;
43
+  var $id;
44 44
     
45 45
 	var $nom;
46 46
 	var $ref;
@@ -48,7 +48,7 @@ class Phcp extends CommonObject
48 48
 	var $fk_societe;
49 49
   var $phcp_type;
50 50
   var $societe;
51
-
51
+  var $compteurs;
52 52
 
53 53
     /**
54 54
      *  Constructor
@@ -62,15 +62,57 @@ class Phcp extends CommonObject
62 62
     }
63 63
 
64 64
 
65
-    function all(){
65
+    function all($sortfield = 'p.ref', $sortorder = 'asc'){
66
+      global $conf, $langs;
67
+      $sql = "SELECT";
68
+		  $sql.= " p.rowid,";
69
+		  $sql.= " p.ref,";
70
+		  $sql.= " p.nom,";
71
+		  $sql.= " pt.ref,";
72
+		  $sql.= " pt.nom,";
73
+      $sql.= " s.nom";
74
+      $sql.= " FROM ".MAIN_DB_PREFIX."phcp as p";
75
+      //$sql.= " ".MAIN_DB_PREFIX."phcp_type as pt,";
76
+      //$sql.= " ".MAIN_DB_PREFIX."societe as s";
77
+      $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."phcp_type as pt";
78
+      $sql.= " ON pt.rowid = p.fk_phcp_type";
79
+      $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s";
80
+      $sql.= " ON s.rowid = p.fk_societe";
81
+     // $sql.= " WHERE (s.rowid = p.fk_societe OR p.fk_societe IS NULL)";
82
+     // $sql.= " AND (pt.rowid = p.fk_phcp_type AND p.fk_phcp_type IS NULL)";
83
+      $sql.= " ORDER BY ".$this->db->escape($sortfield)." ".$this->db->escape($sortorder);
84
+      $list = array();
85
+ 
86
+      dol_syslog(get_class($this)."::all sql=".$sql, LOG_DEBUG);
87
+      $resql=$this->db->query($sql);
88
+      if ($resql){
89
+        if ($num = $this->db->num_rows($resql)){
90
+          $i = 0;
91
+          while ($i < $num){
92
+            $obj = $this->db->fetch_object($resql);
93
+            if ($obj){
94
+              $phcp = new Phcp($this->db);
95
+              $phcp->fetch($obj->rowid);
96
+              $list[]= $phcp;
97
+            }
98
+            $i++;
99
+          }
100
+        }
101
+      }
102
+      return $list;
103
+    }
104
+
105
+
106
+    function no_societe(){
66 107
       global $conf, $langs;
67 108
       $sql = "SELECT";
68 109
 		  $sql.= " t.rowid";
69 110
       $sql.= " FROM ".MAIN_DB_PREFIX."phcp as t";
111
+      $sql.= " WHERE t.fk_societe IS NULL";
70 112
 
71 113
       $list = array();
72 114
 
73
-    	dol_syslog(get_class($this)."::all sql=".$sql, LOG_DEBUG);
115
+    	dol_syslog(get_class($this)."::no_societe sql=".$sql, LOG_DEBUG);
74 116
       $resql=$this->db->query($sql);
75 117
       if ($resql){
76 118
         if ($num = $this->db->num_rows($resql)){
@@ -147,6 +189,17 @@ class Phcp extends CommonObject
147 189
 		if (! $error)
148 190
         {
149 191
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."phcp");
192
+            foreach($this->phcp_type->products as $product){
193
+              $sql = "INSERT INTO ";
194
+              $sql.= MAIN_DB_PREFIX."compteur (";
195
+              $sql.= "fk_phcp, fk_product, compteur, last_compteur, last_modification";
196
+              $sql.= "VALUES ('".$this->id."','".$product->id."', '0', '0', NOW())";
197
+		          $this->db->begin();
198
+
199
+	            dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
200
+              $resql=$this->db->query($sql);
201
+              if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
202
+            }
150 203
 
151 204
 			if (! $notrigger)
152 205
 			{
@@ -226,9 +279,35 @@ class Phcp extends CommonObject
226 279
           $this->societe->fetch($this->fk_societe);
227 280
         }
228 281
 
282
+        $this->db->free($resql);
283
+        $this->compteurs = array();
284
+
285
+        $sql2 = "SELECT";
286
+        $sql2.= " c.rowid";
287
+        $sql2.= " FROM ".MAIN_DB_PREFIX."compteur as c";
288
+        $sql2.= " WHERE c.fk_phcp = ".$this->id;
289
+
290
+       	dol_syslog(get_class($this)."::fetch sql=".$sql2, LOG_DEBUG);
291
+        $resql2=$this->db->query($sql2);
292
+        if ($resql2){
293
+            $num2 = $this->db->num_rows($resql2);
294
+            $i2 = 0;
295
+            if ($num2){
296
+                while ($i2 < $num2){
297
+                    $obj2 = $this->db->fetch_object($resql2);
298
+                    if ($obj2){
299
+                       $compteur = new Compteur($this->db);
300
+                       $compteur->phcp = $this;
301
+                       $compteur->fetch($obj2->rowid);
302
+                       $this->compteurs[] = $compteur;
303
+                    }
304
+                    $i2++;
305
+                }
306
+            }
307
+        }
229 308
                 
230 309
             }
231
-            $this->db->free($resql);
310
+            $this->db->free($resql2);
232 311
 
233 312
             return 1;
234 313
         }
@@ -453,7 +532,7 @@ class Phcp extends CommonObject
453 532
     $this->phcp_type=null;
454 533
 		$this->fk_societe='';
455 534
     $this->societe=null;
456
-		
535
+		$this->compteurs=array();
457 536
 	}
458 537
 
459 538
 }

+ 0
- 429
class/phcptypeproduct.class.php View File

@@ -1,429 +0,0 @@
1
-<?php
2
-/* Copyright (C) 2007-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
3
- * Copyright (C) ---Put here your own copyright and developer email---
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
-/**
20
- *  \file       dev/skeletons/phcptypeproduct.class.php
21
- *  \ingroup    mymodule othermodule1 othermodule2
22
- *  \brief      This file is an example for a CRUD class file (Create/Read/Update/Delete)
23
- *				Initialy built by build_class_from_table on 2013-09-12 16:47
24
- */
25
-
26
-// Put here all includes required by your class file
27
-require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
28
-//require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
29
-//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
30
-
31
-
32
-/**
33
- *	Put here description of your class
34
- */
35
-class Phcptypeproduct extends CommonObject
36
-{
37
-	var $db;							//!< To store db handler
38
-	var $error;							//!< To return error code (or message)
39
-	var $errors=array();				//!< To return several error codes (or messages)
40
-	var $element='phcptypeproduct';			//!< Id that identify managed objects
41
-	var $table_element='phcptypeproduct';		//!< Name of table without prefix where object is stored
42
-
43
-    var $id;
44
-    
45
-	var $phcp_type_product_number;
46
-	var $entity;
47
-	var $ref_ext;
48
-	var $ref_int;
49
-	var $fk_phcp_type;
50
-	var $fk_product;
51
-
52
-    
53
-
54
-
55
-    /**
56
-     *  Constructor
57
-     *
58
-     *  @param	DoliDb		$db      Database handler
59
-     */
60
-    function __construct($db)
61
-    {
62
-        $this->db = $db;
63
-        return 1;
64
-    }
65
-
66
-
67
-    /**
68
-     *  Create object into database
69
-     *
70
-     *  @param	User	$user        User that creates
71
-     *  @param  int		$notrigger   0=launch triggers after, 1=disable triggers
72
-     *  @return int      		   	 <0 if KO, Id of created object if OK
73
-     */
74
-    function create($user, $notrigger=0)
75
-    {
76
-    	global $conf, $langs;
77
-		$error=0;
78
-
79
-		// Clean parameters
80
-        
81
-		if (isset($this->phcp_type_product_number)) $this->phcp_type_product_number=trim($this->phcp_type_product_number);
82
-		if (isset($this->entity)) $this->entity=trim($this->entity);
83
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
84
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
85
-		if (isset($this->fk_phcp_type)) $this->fk_phcp_type=trim($this->fk_phcp_type);
86
-		if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
87
-
88
-        
89
-
90
-		// Check parameters
91
-		// Put here code to add control on parameters values
92
-
93
-        // Insert request
94
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."phcp_type_product(";
95
-		
96
-		$sql.= "phcp_type_product_number,";
97
-		$sql.= "entity,";
98
-		$sql.= "ref_ext,";
99
-		$sql.= "ref_int,";
100
-		$sql.= "fk_phcp_type,";
101
-		$sql.= "fk_product";
102
-
103
-		
104
-        $sql.= ") VALUES (";
105
-        
106
-		$sql.= " ".(! isset($this->phcp_type_product_number)?'NULL':"'".$this->db->escape($this->phcp_type_product_number)."'").",";
107
-		$sql.= " ".(! isset($this->entity)?'NULL':"'".$this->entity."'").",";
108
-		$sql.= " ".(! isset($this->ref_ext)?'NULL':"'".$this->db->escape($this->ref_ext)."'").",";
109
-		$sql.= " ".(! isset($this->ref_int)?'NULL':"'".$this->db->escape($this->ref_int)."'").",";
110
-		$sql.= " ".(! isset($this->fk_phcp_type)?'NULL':"'".$this->fk_phcp_type."'").",";
111
-		$sql.= " ".(! isset($this->fk_product)?'NULL':"'".$this->fk_product."'")."";
112
-
113
-        
114
-		$sql.= ")";
115
-
116
-		$this->db->begin();
117
-
118
-	   	dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
119
-        $resql=$this->db->query($sql);
120
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
121
-
122
-		if (! $error)
123
-        {
124
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."phcp_type_product");
125
-
126
-			if (! $notrigger)
127
-			{
128
-	            // Uncomment this and change MYOBJECT to your own tag if you
129
-	            // want this action calls a trigger.
130
-
131
-	            //// Call triggers
132
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
133
-	            //$interface=new Interfaces($this->db);
134
-	            //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
135
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
136
-	            //// End call triggers
137
-			}
138
-        }
139
-
140
-        // Commit or rollback
141
-        if ($error)
142
-		{
143
-			foreach($this->errors as $errmsg)
144
-			{
145
-	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
146
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
147
-			}
148
-			$this->db->rollback();
149
-			return -1*$error;
150
-		}
151
-		else
152
-		{
153
-			$this->db->commit();
154
-            return $this->id;
155
-		}
156
-    }
157
-
158
-
159
-    /**
160
-     *  Load object in memory from the database
161
-     *
162
-     *  @param	int		$id    Id object
163
-     *  @return int          	<0 if KO, >0 if OK
164
-     */
165
-    function fetch($id)
166
-    {
167
-    	global $langs;
168
-        $sql = "SELECT";
169
-		$sql.= " t.rowid,";
170
-		
171
-		$sql.= " t.phcp_type_product_number,";
172
-		$sql.= " t.entity,";
173
-		$sql.= " t.ref_ext,";
174
-		$sql.= " t.ref_int,";
175
-		$sql.= " t.fk_phcp_type,";
176
-		$sql.= " t.fk_product";
177
-
178
-		
179
-        $sql.= " FROM ".MAIN_DB_PREFIX."phcp_type_product as t";
180
-        $sql.= " WHERE t.rowid = ".$id;
181
-
182
-    	dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
183
-        $resql=$this->db->query($sql);
184
-        if ($resql)
185
-        {
186
-            if ($this->db->num_rows($resql))
187
-            {
188
-                $obj = $this->db->fetch_object($resql);
189
-
190
-                $this->id    = $obj->rowid;
191
-                
192
-				$this->phcp_type_product_number = $obj->phcp_type_product_number;
193
-				$this->entity = $obj->entity;
194
-				$this->ref_ext = $obj->ref_ext;
195
-				$this->ref_int = $obj->ref_int;
196
-				$this->fk_phcp_type = $obj->fk_phcp_type;
197
-				$this->fk_product = $obj->fk_product;
198
-
199
-                
200
-            }
201
-            $this->db->free($resql);
202
-
203
-            return 1;
204
-        }
205
-        else
206
-        {
207
-      	    $this->error="Error ".$this->db->lasterror();
208
-            dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
209
-            return -1;
210
-        }
211
-    }
212
-
213
-
214
-    /**
215
-     *  Update object into database
216
-     *
217
-     *  @param	User	$user        User that modifies
218
-     *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
219
-     *  @return int     		   	 <0 if KO, >0 if OK
220
-     */
221
-    function update($user=0, $notrigger=0)
222
-    {
223
-    	global $conf, $langs;
224
-		$error=0;
225
-
226
-		// Clean parameters
227
-        
228
-		if (isset($this->phcp_type_product_number)) $this->phcp_type_product_number=trim($this->phcp_type_product_number);
229
-		if (isset($this->entity)) $this->entity=trim($this->entity);
230
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
231
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
232
-		if (isset($this->fk_phcp_type)) $this->fk_phcp_type=trim($this->fk_phcp_type);
233
-		if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
234
-
235
-        
236
-
237
-		// Check parameters
238
-		// Put here code to add a control on parameters values
239
-
240
-        // Update request
241
-        $sql = "UPDATE ".MAIN_DB_PREFIX."phcp_type_product SET";
242
-        
243
-		$sql.= " phcp_type_product_number=".(isset($this->phcp_type_product_number)?"'".$this->db->escape($this->phcp_type_product_number)."'":"null").",";
244
-		$sql.= " entity=".(isset($this->entity)?$this->entity:"null").",";
245
-		$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
246
-		$sql.= " ref_int=".(isset($this->ref_int)?"'".$this->db->escape($this->ref_int)."'":"null").",";
247
-		$sql.= " fk_phcp_type=".(isset($this->fk_phcp_type)?$this->fk_phcp_type:"null").",";
248
-		$sql.= " fk_product=".(isset($this->fk_product)?$this->fk_product:"null")."";
249
-
250
-        
251
-        $sql.= " WHERE rowid=".$this->id;
252
-
253
-		$this->db->begin();
254
-
255
-		dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
256
-        $resql = $this->db->query($sql);
257
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
258
-
259
-		if (! $error)
260
-		{
261
-			if (! $notrigger)
262
-			{
263
-	            // Uncomment this and change MYOBJECT to your own tag if you
264
-	            // want this action calls a trigger.
265
-
266
-	            //// Call triggers
267
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
268
-	            //$interface=new Interfaces($this->db);
269
-	            //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
270
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
271
-	            //// End call triggers
272
-	    	}
273
-		}
274
-
275
-        // Commit or rollback
276
-		if ($error)
277
-		{
278
-			foreach($this->errors as $errmsg)
279
-			{
280
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
281
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
282
-			}
283
-			$this->db->rollback();
284
-			return -1*$error;
285
-		}
286
-		else
287
-		{
288
-			$this->db->commit();
289
-			return 1;
290
-		}
291
-    }
292
-
293
-
294
- 	/**
295
-	 *  Delete object in database
296
-	 *
297
-     *	@param  User	$user        User that deletes
298
-     *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
299
-	 *  @return	int					 <0 if KO, >0 if OK
300
-	 */
301
-	function delete($user, $notrigger=0)
302
-	{
303
-		global $conf, $langs;
304
-		$error=0;
305
-
306
-		$this->db->begin();
307
-
308
-		if (! $error)
309
-		{
310
-			if (! $notrigger)
311
-			{
312
-				// Uncomment this and change MYOBJECT to your own tag if you
313
-		        // want this action calls a trigger.
314
-
315
-		        //// Call triggers
316
-		        //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
317
-		        //$interface=new Interfaces($this->db);
318
-		        //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
319
-		        //if ($result < 0) { $error++; $this->errors=$interface->errors; }
320
-		        //// End call triggers
321
-			}
322
-		}
323
-
324
-		if (! $error)
325
-		{
326
-    		$sql = "DELETE FROM ".MAIN_DB_PREFIX."phcp_type_product";
327
-    		$sql.= " WHERE rowid=".$this->id;
328
-
329
-    		dol_syslog(get_class($this)."::delete sql=".$sql);
330
-    		$resql = $this->db->query($sql);
331
-        	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
332
-		}
333
-
334
-        // Commit or rollback
335
-		if ($error)
336
-		{
337
-			foreach($this->errors as $errmsg)
338
-			{
339
-	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
340
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
341
-			}
342
-			$this->db->rollback();
343
-			return -1*$error;
344
-		}
345
-		else
346
-		{
347
-			$this->db->commit();
348
-			return 1;
349
-		}
350
-	}
351
-
352
-
353
-
354
-	/**
355
-	 *	Load an object from its id and create a new one in database
356
-	 *
357
-	 *	@param	int		$fromid     Id of object to clone
358
-	 * 	@return	int					New id of clone
359
-	 */
360
-	function createFromClone($fromid)
361
-	{
362
-		global $user,$langs;
363
-
364
-		$error=0;
365
-
366
-		$object=new Phcptypeproduct($this->db);
367
-
368
-		$this->db->begin();
369
-
370
-		// Load source object
371
-		$object->fetch($fromid);
372
-		$object->id=0;
373
-		$object->statut=0;
374
-
375
-		// Clear fields
376
-		// ...
377
-
378
-		// Create clone
379
-		$result=$object->create($user);
380
-
381
-		// Other options
382
-		if ($result < 0)
383
-		{
384
-			$this->error=$object->error;
385
-			$error++;
386
-		}
387
-
388
-		if (! $error)
389
-		{
390
-
391
-
392
-		}
393
-
394
-		// End
395
-		if (! $error)
396
-		{
397
-			$this->db->commit();
398
-			return $object->id;
399
-		}
400
-		else
401
-		{
402
-			$this->db->rollback();
403
-			return -1;
404
-		}
405
-	}
406
-
407
-
408
-	/**
409
-	 *	Initialise object with example values
410
-	 *	Id must be 0 if object instance is a specimen
411
-	 *
412
-	 *	@return	void
413
-	 */
414
-	function initAsSpecimen()
415
-	{
416
-		$this->id=0;
417
-		
418
-		$this->phcp_type_product_number='';
419
-		$this->entity='';
420
-		$this->ref_ext='';
421
-		$this->ref_int='';
422
-		$this->fk_phcp_type='';
423
-		$this->fk_product='';
424
-
425
-		
426
-	}
427
-
428
-}
429
-?>

+ 4
- 3
class/societe.class.php View File

@@ -32,11 +32,12 @@ class CSociete extends Societe {
32 32
       return $r;
33 33
     }
34 34
 
35
-    function all(){
35
+    function all($sortfield = "s.nom", $sortorder = "asc"){
36 36
       global $conf, $langs;
37 37
       $sql = "SELECT";
38
-		  $sql.= " t.rowid";
39
-      $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
38
+		  $sql.= " s.rowid";
39
+      $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
40
+      $sql.= " ORDER BY ".$sortfield." ".$sortorder;
40 41
 
41 42
       $list = array();
42 43
 

+ 0
- 429
class/societephcp.class.php View File

@@ -1,429 +0,0 @@
1
-<?php
2
-/* Copyright (C) 2007-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
3
- * Copyright (C) ---Put here your own copyright and developer email---
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
-/**
20
- *  \file       dev/skeletons/societephcp.class.php
21
- *  \ingroup    mymodule othermodule1 othermodule2
22
- *  \brief      This file is an example for a CRUD class file (Create/Read/Update/Delete)
23
- *				Initialy built by build_class_from_table on 2013-09-12 16:47
24
- */
25
-
26
-// Put here all includes required by your class file
27
-require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
28
-//require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
29
-//require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
30
-
31
-
32
-/**
33
- *	Put here description of your class
34
- */
35
-class Societephcp extends CommonObject
36
-{
37
-	var $db;							//!< To store db handler
38
-	var $error;							//!< To return error code (or message)
39
-	var $errors=array();				//!< To return several error codes (or messages)
40
-	var $element='societephcp';			//!< Id that identify managed objects
41
-	var $table_element='societephcp';		//!< Name of table without prefix where object is stored
42
-
43
-    var $id;
44
-    
45
-	var $societe_phcp_number;
46
-	var $entity;
47
-	var $ref_ext;
48
-	var $ref_int;
49
-	var $fk_phcp;
50
-	var $fk_societe;
51
-
52
-    
53
-
54
-
55
-    /**
56
-     *  Constructor
57
-     *
58
-     *  @param	DoliDb		$db      Database handler
59
-     */
60
-    function __construct($db)
61
-    {
62
-        $this->db = $db;
63
-        return 1;
64
-    }
65
-
66
-
67
-    /**
68
-     *  Create object into database
69
-     *
70
-     *  @param	User	$user        User that creates
71
-     *  @param  int		$notrigger   0=launch triggers after, 1=disable triggers
72
-     *  @return int      		   	 <0 if KO, Id of created object if OK
73
-     */
74
-    function create($user, $notrigger=0)
75
-    {
76
-    	global $conf, $langs;
77
-		$error=0;
78
-
79
-		// Clean parameters
80
-        
81
-		if (isset($this->societe_phcp_number)) $this->societe_phcp_number=trim($this->societe_phcp_number);
82
-		if (isset($this->entity)) $this->entity=trim($this->entity);
83
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
84
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
85
-		if (isset($this->fk_phcp)) $this->fk_phcp=trim($this->fk_phcp);
86
-		if (isset($this->fk_societe)) $this->fk_societe=trim($this->fk_societe);
87
-
88
-        
89
-
90
-		// Check parameters
91
-		// Put here code to add control on parameters values
92
-
93
-        // Insert request
94
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_phcp(";
95
-		
96
-		$sql.= "societe_phcp_number,";
97
-		$sql.= "entity,";
98
-		$sql.= "ref_ext,";
99
-		$sql.= "ref_int,";
100
-		$sql.= "fk_phcp,";
101
-		$sql.= "fk_societe";
102
-
103
-		
104
-        $sql.= ") VALUES (";
105
-        
106
-		$sql.= " ".(! isset($this->societe_phcp_number)?'NULL':"'".$this->db->escape($this->societe_phcp_number)."'").",";
107
-		$sql.= " ".(! isset($this->entity)?'NULL':"'".$this->entity."'").",";
108
-		$sql.= " ".(! isset($this->ref_ext)?'NULL':"'".$this->db->escape($this->ref_ext)."'").",";
109
-		$sql.= " ".(! isset($this->ref_int)?'NULL':"'".$this->db->escape($this->ref_int)."'").",";
110
-		$sql.= " ".(! isset($this->fk_phcp)?'NULL':"'".$this->fk_phcp."'").",";
111
-		$sql.= " ".(! isset($this->fk_societe)?'NULL':"'".$this->fk_societe."'")."";
112
-
113
-        
114
-		$sql.= ")";
115
-
116
-		$this->db->begin();
117
-
118
-	   	dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
119
-        $resql=$this->db->query($sql);
120
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
121
-
122
-		if (! $error)
123
-        {
124
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_phcp");
125
-
126
-			if (! $notrigger)
127
-			{
128
-	            // Uncomment this and change MYOBJECT to your own tag if you
129
-	            // want this action calls a trigger.
130
-
131
-	            //// Call triggers
132
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
133
-	            //$interface=new Interfaces($this->db);
134
-	            //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
135
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
136
-	            //// End call triggers
137
-			}
138
-        }
139
-
140
-        // Commit or rollback
141
-        if ($error)
142
-		{
143
-			foreach($this->errors as $errmsg)
144
-			{
145
-	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
146
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
147
-			}
148
-			$this->db->rollback();
149
-			return -1*$error;
150
-		}
151
-		else
152
-		{
153
-			$this->db->commit();
154
-            return $this->id;
155
-		}
156
-    }
157
-
158
-
159
-    /**
160
-     *  Load object in memory from the database
161
-     *
162
-     *  @param	int		$id    Id object
163
-     *  @return int          	<0 if KO, >0 if OK
164
-     */
165
-    function fetch($id)
166
-    {
167
-    	global $langs;
168
-        $sql = "SELECT";
169
-		$sql.= " t.rowid,";
170
-		
171
-		$sql.= " t.societe_phcp_number,";
172
-		$sql.= " t.entity,";
173
-		$sql.= " t.ref_ext,";
174
-		$sql.= " t.ref_int,";
175
-		$sql.= " t.fk_phcp,";
176
-		$sql.= " t.fk_societe";
177
-
178
-		
179
-        $sql.= " FROM ".MAIN_DB_PREFIX."societe_phcp as t";
180
-        $sql.= " WHERE t.rowid = ".$id;
181
-
182
-    	dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
183
-        $resql=$this->db->query($sql);
184
-        if ($resql)
185
-        {
186
-            if ($this->db->num_rows($resql))
187
-            {
188
-                $obj = $this->db->fetch_object($resql);
189
-
190
-                $this->id    = $obj->rowid;
191
-                
192
-				$this->societe_phcp_number = $obj->societe_phcp_number;
193
-				$this->entity = $obj->entity;
194
-				$this->ref_ext = $obj->ref_ext;
195
-				$this->ref_int = $obj->ref_int;
196
-				$this->fk_phcp = $obj->fk_phcp;
197
-				$this->fk_societe = $obj->fk_societe;
198
-
199
-                
200
-            }
201
-            $this->db->free($resql);
202
-
203
-            return 1;
204
-        }
205
-        else
206
-        {
207
-      	    $this->error="Error ".$this->db->lasterror();
208
-            dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
209
-            return -1;
210
-        }
211
-    }
212
-
213
-
214
-    /**
215
-     *  Update object into database
216
-     *
217
-     *  @param	User	$user        User that modifies
218
-     *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
219
-     *  @return int     		   	 <0 if KO, >0 if OK
220
-     */
221
-    function update($user=0, $notrigger=0)
222
-    {
223
-    	global $conf, $langs;
224
-		$error=0;
225
-
226
-		// Clean parameters
227
-        
228
-		if (isset($this->societe_phcp_number)) $this->societe_phcp_number=trim($this->societe_phcp_number);
229
-		if (isset($this->entity)) $this->entity=trim($this->entity);
230
-		if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
231
-		if (isset($this->ref_int)) $this->ref_int=trim($this->ref_int);
232
-		if (isset($this->fk_phcp)) $this->fk_phcp=trim($this->fk_phcp);
233
-		if (isset($this->fk_societe)) $this->fk_societe=trim($this->fk_societe);
234
-
235
-        
236
-
237
-		// Check parameters
238
-		// Put here code to add a control on parameters values
239
-
240
-        // Update request
241
-        $sql = "UPDATE ".MAIN_DB_PREFIX."societe_phcp SET";
242
-        
243
-		$sql.= " societe_phcp_number=".(isset($this->societe_phcp_number)?"'".$this->db->escape($this->societe_phcp_number)."'":"null").",";
244
-		$sql.= " entity=".(isset($this->entity)?$this->entity:"null").",";
245
-		$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
246
-		$sql.= " ref_int=".(isset($this->ref_int)?"'".$this->db->escape($this->ref_int)."'":"null").",";
247
-		$sql.= " fk_phcp=".(isset($this->fk_phcp)?$this->fk_phcp:"null").",";
248
-		$sql.= " fk_societe=".(isset($this->fk_societe)?$this->fk_societe:"null")."";
249
-
250
-        
251
-        $sql.= " WHERE rowid=".$this->id;
252
-
253
-		$this->db->begin();
254
-
255
-		dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
256
-        $resql = $this->db->query($sql);
257
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
258
-
259
-		if (! $error)
260
-		{
261
-			if (! $notrigger)
262
-			{
263
-	            // Uncomment this and change MYOBJECT to your own tag if you
264
-	            // want this action calls a trigger.
265
-
266
-	            //// Call triggers
267
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
268
-	            //$interface=new Interfaces($this->db);
269
-	            //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
270
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
271
-	            //// End call triggers
272
-	    	}
273
-		}
274
-
275
-        // Commit or rollback
276
-		if ($error)
277
-		{
278
-			foreach($this->errors as $errmsg)
279
-			{
280
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
281
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
282
-			}
283
-			$this->db->rollback();
284
-			return -1*$error;
285
-		}
286
-		else
287
-		{
288
-			$this->db->commit();
289
-			return 1;
290
-		}
291
-    }
292
-
293
-
294
- 	/**
295
-	 *  Delete object in database
296
-	 *
297
-     *	@param  User	$user        User that deletes
298
-     *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
299
-	 *  @return	int					 <0 if KO, >0 if OK
300
-	 */
301
-	function delete($user, $notrigger=0)
302
-	{
303
-		global $conf, $langs;
304
-		$error=0;
305
-
306
-		$this->db->begin();
307
-
308
-		if (! $error)
309
-		{
310
-			if (! $notrigger)
311
-			{
312
-				// Uncomment this and change MYOBJECT to your own tag if you
313
-		        // want this action calls a trigger.
314
-
315
-		        //// Call triggers
316
-		        //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
317
-		        //$interface=new Interfaces($this->db);
318
-		        //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
319
-		        //if ($result < 0) { $error++; $this->errors=$interface->errors; }
320
-		        //// End call triggers
321
-			}
322
-		}
323
-
324
-		if (! $error)
325
-		{
326
-    		$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_phcp";
327
-    		$sql.= " WHERE rowid=".$this->id;
328
-
329
-    		dol_syslog(get_class($this)."::delete sql=".$sql);
330
-    		$resql = $this->db->query($sql);
331
-        	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
332
-		}
333
-
334
-        // Commit or rollback
335
-		if ($error)
336
-		{
337
-			foreach($this->errors as $errmsg)
338
-			{
339
-	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
340
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
341
-			}
342
-			$this->db->rollback();
343
-			return -1*$error;
344
-		}
345
-		else
346
-		{
347
-			$this->db->commit();
348
-			return 1;
349
-		}
350
-	}
351
-
352
-
353
-
354
-	/**
355
-	 *	Load an object from its id and create a new one in database
356
-	 *
357
-	 *	@param	int		$fromid     Id of object to clone
358
-	 * 	@return	int					New id of clone
359
-	 */
360
-	function createFromClone($fromid)
361
-	{
362
-		global $user,$langs;
363
-
364
-		$error=0;
365
-
366
-		$object=new Societephcp($this->db);
367
-
368
-		$this->db->begin();
369
-
370
-		// Load source object
371
-		$object->fetch($fromid);
372
-		$object->id=0;
373
-		$object->statut=0;
374
-
375
-		// Clear fields
376
-		// ...
377
-
378
-		// Create clone
379
-		$result=$object->create($user);
380
-
381
-		// Other options
382
-		if ($result < 0)
383
-		{
384
-			$this->error=$object->error;
385
-			$error++;
386
-		}
387
-
388
-		if (! $error)
389
-		{
390
-
391
-
392
-		}
393
-
394
-		// End
395
-		if (! $error)
396
-		{
397
-			$this->db->commit();
398
-			return $object->id;
399
-		}
400
-		else
401
-		{
402
-			$this->db->rollback();
403
-			return -1;
404
-		}
405
-	}
406
-
407
-
408
-	/**
409
-	 *	Initialise object with example values
410
-	 *	Id must be 0 if object instance is a specimen
411
-	 *
412
-	 *	@return	void
413
-	 */
414
-	function initAsSpecimen()
415
-	{
416
-		$this->id=0;
417
-		
418
-		$this->societe_phcp_number='';
419
-		$this->entity='';
420
-		$this->ref_ext='';
421
-		$this->ref_int='';
422
-		$this->fk_phcp='';
423
-		$this->fk_societe='';
424
-
425
-		
426
-	}
427
-
428
-}
429
-?>

+ 313
- 137
compteurs.php View File

@@ -10,7 +10,7 @@ if (! $res) die("Include of main fails");
10 10
 // Change this following line to use the correct relative path from htdocs
11 11
 dol_include_once('/photocopies/class/phcp.class.php');
12 12
 dol_include_once('/photocopies/class/societe.class.php');
13
-
13
+require_once DOL_DOCUMENT_ROOT .'/core/lib/price.lib.php';
14 14
 // Load traductions files requiredby by page
15 15
 $langs->load("companies");
16 16
 $langs->load("other");
@@ -19,7 +19,7 @@ $langs->load("other");
19 19
 $id			  = GETPOST('id','int');
20 20
 $action		= GETPOST('action','alpha') ?: 'list';
21 21
 $myparam	= GETPOST('myparam','alpha');
22
-$url      = DOL_URL_ROOT."/photocopies/phcp.php";
22
+$url      = DOL_URL_ROOT."/photocopies/compteurs.php";
23 23
 $phcp     = null;
24 24
 $title    = null;
25 25
 
@@ -34,40 +34,149 @@ if($id) $societe->fetch($id);
34 34
 else $societe->initAsSpecimen();
35 35
 
36 36
 //------------------------------------------------------------------------------
37
-if ($action == 'create') {
38
-	$phcp->ref=$_POST["ref"];
39
-	$phcp->nom=$_POST["nom"];
40
-	$phcp->fk_phcp_type= $_POST["fk_phcp_type"] ?: null;
41
-	$phcp->fk_societe= $_POST["fk_societe"] ?: null;
42
-	if ($phcp->create($user) >= 0)
43
-    $action = 'show';
44
-  else
45
-    $action = 'edit';
46
-}
47
-//------------------------------------------------------------------------------
48
-elseif ($action == 'update'){
49
-	$phcp->ref=$_POST["ref"];
50
-	$phcp->nom=$_POST["nom"];
51
-	$phcp->fk_phcp_type=$_POST["fk_phcp_type"] ?: null;
52
-	$phcp->fk_societe= $_POST["fk_societe"] ?: null;
53
-	if ($phcp->update($user) >= 0)
54
-    $action = 'show';
55
-  else 
56
-    $action = 'edit';
57
-}
58
-//------------------------------------------------------------------------------
59
-elseif ($action == 'delete'){
60
-	if ($phcp->delete($user) >= 0)
61
-    $action = 'list';
62
-  else 
37
+if ($action == 'update'){
38
+  $compteurs = $_POST['compteur'];
39
+  $generate_invoice = isset($_POST['generer']);
40
+  $error = 0;
41
+  $errors = array();
42
+  $invoice = null;
43
+  $idobject=null;
44
+  //$db->begin();
45
+
46
+  if($generate_invoice){
47
+    require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
48
+    $invoice = new Facture($db);
49
+    $invoice->socid = $societe->id;
50
+    $invoice->date = dol_now();//mktime();
51
+    $invoice->note = "Facture Générée Automatiquement";
52
+    //$invoice->brouillon = 1;
53
+    $idobject = $invoice->create($user);
54
+    if ($idobject > 0){
55
+    } else {
56
+      $error++;
57
+      dol_print_error($db,$invoice->error);
58
+    }
59
+  }
60
+
61
+  foreach($compteurs as $cid => $c){
62
+    $compteur = new Compteur($db);
63
+    $compteur->fetch($cid);
64
+    if($c != '' && $c >= 0){
65
+      $compteur->last_compteur = $compteur->compteur;
66
+      $compteur->compteur = $c;
67
+    }
68
+    if($compteur->update($user) < 0){
69
+      $error++;
70
+      $errors[] = $compteur->error;
71
+    } 
72
+    elseif($generate_invoice){
73
+      $product = $compteur->product;
74
+      $txtva = $product->tva_tx ?: 0;
75
+      echo "tva_tx='$txtva'";
76
+      $mysoc = $societe;
77
+      $qty = $compteur->compteur - $compteur->last_compteur;
78
+      $pu = $product->price;
79
+      $type = $product->fk_product_type;
80
+      $remise_percent = 0;
81
+      $txlocaltax1 = 0;
82
+      $txlocaltax2 = 0;
83
+      $total_ht = 0; 
84
+      $total_tva = 0;
85
+      $total_ttc = 0;
86
+      $info_bits= 0;
87
+      $price_base_type=0;
88
+      $local_taxes_type=0;
89
+      $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc);
90
+      $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'',$localtaxes_type);
91
+      $total_ht = $tabprice[0];
92
+      $total_tva = $tabprice[1];
93
+      $total_ttc = $tabprice[2];
94
+      $total_localtax1 = $tabprice[9];
95
+      $total_localtax2 = $tabprice[10];
96
+      $pu_ht = $tabprice[3];
97
+
98
+      $date_start='';
99
+      $date_end='';
100
+
101
+/*      $line = new FactureLigne($db);
102
+      $line->fk_product = $compteur->fk_product;
103
+      $line->qty= ($qty >= 0 ? $qty : 0);
104
+      $line->tva_tx= $compteur->product->tva_tx;
105
+      $line->pu_ht= $pu_ht;
106
+      $line->remise_percent=0;
107
+      $line->total_ht=$total_ht;
108
+      $line->total_tva=$total_tva;
109
+      $line->total_ttc=$total_ttc;
110
+      $invoice->lines[]= $line; */
111
+
112
+      $result = $invoice->addline(
113
+        $idobject,
114
+        $compteur->product->label, 
115
+        $compteur->product->price, 
116
+        ($qty>0 ? $qty : 0), 
117
+        $txtva, 
118
+        0, 
119
+        0, 
120
+        $compteur->fk_product,
121
+        $remise_percent,
122
+        $date_start,
123
+        $date_end,
124
+        0,
125
+        $info_bits,
126
+        '',
127
+        $price_base_type,
128
+        $pu_ttc,
129
+        $type,
130
+        -1,
131
+        $special_code,
132
+        '',
133
+        0,
134
+        GETPOST('fk_parent_line'),
135
+        $fournprice,
136
+        $buyingprice,
137
+        $label,
138
+        $array_option
139
+      );
140
+      echo "RESULT='$result'";
141
+      //$result = $invoice->addline($compteur->product->nom, $compteur->product->price, ($newcompteur>0?$newcompteur:0), $compteur->product->tva_tx);
142
+      if($result > 0){
143
+
144
+      } else {
145
+        $error++;
146
+        //dol_print_error($db,$invoice->error);
147
+        //echo $invoice->id." - Error: '".$result."' - ".var_dump($invoice->lines)."<br />";
148
+      }
149
+    }
150
+  }
151
+
152
+  if($error){
153
+     dol_print_error($db,$invoice->error);
154
+    //$db->rollback();
155
+  } elseif($generate_invoice) {
156
+    //$db->commit();
157
+    //  $result = $invoice->validate($user);
158
+    //  if ($result > 0){
159
+        header('Location:'.DOL_URL_ROOT.'/compta/facture.php?facid='.$idobject);
160
+    //  } else {
161
+    //    $error++;
162
+          //dol_print_error($db,$invoice->error);
163
+    //  }
164
+    //$db->close();
165
+  } else {
63 166
     $action = 'list';
167
+  }
168
+  //$db->close();
64 169
 }
170
+//------------------------------------------------------------------------------
65 171
 
66 172
 switch($action){
67
-  case 'new': $title = "Nouveau Photocopieur"; llxHeader('',$title,''); break;
68
-  case 'edit': $title = "Modifier Photocopieur"; llxHeader('',$title,''); break;
173
+  case 'edit': 
174
+    if($societe->id)
175
+      $title = "Modifier compteurs client ".$societe->nom; 
176
+    else
177
+      $title = "Modifier compteurs des photocopieurs en stock";
178
+    llxHeader('',$title,''); break;
69 179
   case 'list': $title = "Compteurs"; llxHeader('',$title,''); break;
70
-  case 'show': $title = "Photocopieur : ".$phcp->nom; llxHeader('',$title,''); break;
71 180
 }
72 181
 
73 182
 //===============================[TEMPLATE]=====================================
@@ -80,6 +189,21 @@ if($phcp && $phcp->error){
80 189
 </script>
81 190
 <?php } ?>
82 191
 
192
+<script type="text/javascript">
193
+  function validate_number(evt) {
194
+    var theEvent = evt || window.event;
195
+    var key = theEvent.keyCode || theEvent.which;
196
+    if(key < 14) return true;
197
+    console.log(key);
198
+    key = String.fromCharCode( key );
199
+    var regex = /[0-9]|\./;
200
+    if( !regex.test(key) ) {
201
+      theEvent.returnValue = false;
202
+      if(theEvent.preventDefault) theEvent.preventDefault();
203
+    }
204
+  }
205
+</script>
206
+
83 207
 <div class="fiche">
84 208
   <table width="100%" border="0" style="margin-bottom: 2px;" class="notopnoleftnoright" summary="">
85 209
     <tbody>
@@ -99,127 +223,127 @@ if($phcp && $phcp->error){
99 223
 
100 224
 <?php
101 225
 //------------------------------------------------------------------------------
102
-if (($action == 'new') || ($action == 'edit')){
226
+if ($action == 'edit'){
103 227
 ?>
104
-  <form action="<?= $url."?action=".($action=='new'?'create':'update') ?>" method="POST">
105
-    <?php if($id){ ?><input type="hidden" name="id" value="<?= $id ?>" /><?php } ?>
228
+  <form action="<?= $url."?action=update" ?>" method="POST">
229
+    <input type="hidden" name="id" value="<?= $id ?>" />
106 230
     <table width="100%" class="border">
107 231
       <tbody>
108
-        <tr>
109
-          <td class="fieldrequired" width="20%"><label for="phcp_ref">Ref.</label></td>
110
-          <td><input type="text" id="phcp_ref" name="ref" value="<?= $phcp->ref ?>" placeholder="Reference" /></td>
111
-        </tr>
112
-        <tr>
113
-          <td class="fieldrequired"><label for="phcp_nom">Label du photocopieur</label></td>
114
-          <td><input name="nom" id="phcp_nom" type="text" placeholder="Label du photocopieur" value="<?= $phcp->nom ?>" /></td>
115
-        </tr>
116
-        <tr>
117
-          <td class=""><label for="phcp_type">Type de Photocopieur</label></td>
118
-          <td>
119
-            <select name="fk_phcp_type" id="phcp_type" placeholder="Type de photocopieur">
120
-              <option value="">AUCUN</option>
121
-              <?php
122
-                $phcptype = new PhcpType($db); 
123
-                foreach($phcptype->all() as $pt){
124
-              ?>
125
-                <option value="<?= $pt->id ?>" <?= intval($pt->id) == intval($phcp->fk_phcp_type) ? 'selected="selected"':'' ?>><?= $pt->nom ?></option>
126
-              <?php } ?>
127
-            </select>
128
-          </td>
129
-        </tr>
130
-        <tr>
131
-          <td class=""><label for="societe">Chez Client</label></td>
132
-          <td>
133
-            <select name="fk_societe" id="societe" placeholder="Chez Client">
134
-              <option value="">NON</option>
135
-              <?php 
136
-                $societe = new CSociete($db); 
137
-                foreach($societe->all() as $s){
138
-              ?>
139
-                <option value="<?= $s->id ?>" <?= intval($s->id) == intval($phcp->fk_societe) ? 'selected="selected"':'' ?>><?= $s->nom ?></option>
140
-              <?php } ?>
141
-            </select>
142
-          </td>
143
-        </tr>
232
+        <?php if($societe->id){ ?>
233
+          <?php foreach($societe->phcps as $phcp){ ?>
234
+            <tr>
235
+              <td>
236
+                <?= $phcp->nom ?>
237
+              </td>
238
+              <td>
239
+                <table class="border" width="100%">
240
+                  <tbody>
241
+                    <?php foreach($phcp->compteurs as $compteur){ ?>
242
+                      <tr>
243
+                        <td width="40%">
244
+                          <?= $compteur->product->label ?>
245
+                        </td>
246
+                        <td width="20%">
247
+                          <?= date("d/m/Y H:i", $compteur->updated_at) ?>
248
+                        </td>             
249
+                        <td width="15%" class="digits">
250
+                          <?= $compteur->compteur ?>
251
+                        </td>
252
+                        <td>
253
+                          <input type="number" name="compteur[<?= $compteur->id ?>]" id="compteur" placeholder="compteur" onkeypress="validate_number(event)"/>
254
+                        </td>
255
+                      </tr>
256
+                    <?php } ?>
257
+                  </tbody>
258
+                </table>
259
+              </td>
260
+            </tr>
261
+          <?php } ?>
262
+        <?php } else { ?>
263
+          <?php $phcps = new Phcp($db); ?>
264
+          <?php foreach($phcps->no_societe() as $phcp){ ?>
265
+            <tr>
266
+              <td>
267
+                <?= $phcp->nom ?>
268
+              </td>
269
+              <td>
270
+                <table class="border" width="100%">
271
+                  <tbody>
272
+                    <?php foreach($phcp->compteurs as $compteur){ ?>
273
+                      <tr>
274
+                        <td width="40%">
275
+                          <?= $compteur->product->label ?>
276
+                        </td>
277
+                        <td width="20%">
278
+                          <?= date("d/m/Y H:i", $compteur->updated_at) ?>
279
+                        </td>             
280
+                        <td width="15%" class="digits">
281
+                          <?= $compteur->compteur ?>
282
+                        </td>
283
+                        <td>
284
+                          <input type="number" name="compteur[<?= $compteur->id ?>]" id="compteur" placeholder="compteur" onkeypress="validate_number(event)" />
285
+                        </td>
286
+                      </tr>
287
+                    <?php } ?>
288
+                  </tbody>
289
+                </table>
290
+              </td>
291
+            </tr>
292
+          <?php } ?>
293
+        <?php } ?>
144 294
       </tbody>
145 295
     </table>
146 296
     <div class="tabsAction">
147 297
       <div class="inline-block divButAction">
148
-        <input type="submit" class="butAction" value="<?= $action=='new'?'Créer':'Modifier' ?>" />
298
+        <input type="submit" name="modifier" class="butAction" value="Modifier" />
299
+        <?php if($societe->id){ ?>
300
+          <input type="submit" name="generer"  class="butAction" value="Modifier et générer la facture" />
301
+        <?php } ?>
149 302
       </div>
150 303
     </div>
151 304
   </form>
152 305
 <?php
153 306
 } 
154 307
 //------------------------------------------------------------------------------
155
-elseif ($action == 'show') { 
156
-?>
157
-  <div class="tabBar">
158
-    <table width="100%" class="border">
159
-      <tbody>
160
-        <tr>
161
-          <td width="15%">Ref.</td>
162
-          <td colspan="2"><?= $phcp->ref ?></td>
163
-        </tr>
164
-        <tr>
165
-          <td>Label</td>
166
-          <td colspan="2"><?= $phcp->nom ?></td>
167
-        </tr>
168
-        <tr>
169
-          <td>Photocopieur Type</td>
170
-          <td colspan="2">
171
-            <?php if($phcp->phcp_type) { ?>
172
-              <a href="<?= DOL_URL_ROOT.'/photocopies/phcptype.php?action=show&id='.$phcp->phcp_type->id ?>">
173
-                <?= $phcp->phcp_type->ref ?> - <?= $phcp->phcp_type->nom ?>
174
-              </a>
175
-            <?php } else echo 'AUCUN' ?>
176
-          </td>
177
-        </tr>
178
-        <tr>
179
-          <td>Chez Client</td>
180
-          <td colspan="2">
181
-            <?php if($phcp->societe) { ?>
182
-              <a href="<?= DOL_URL_ROOT.'/societe/soc.php?socid='.$phcp->societe->id ?>">
183
-                <?= $phcp->societe->nom ?>
184
-              </a>
185
-            <?php } else echo 'NON' ?>
186
-          </td>
187
-        </tr>
188
-      </tbody>
189
-    </table>
190
-  </div>
191
-  <div class="tabsAction">
192
-    <div class="inline-block divButAction">
193
-      <a href="<?= $url."?id=".$phcp->id."&action=edit" ?>" class="butAction">
194
-        Modifier
195
-      </a>
196
-    </div>
197
-    <div class="inline-block divButAction">
198
-      <span class="butActionDelete" id="action-delete">Delete</span>
199
-    </div>
200
-  </div>
201
-<?php 
202
-}
203
-//------------------------------------------------------------------------------
204 308
 else { ?>
309
+  <?php
310
+    $sortfield = GETPOST('sortfield', 'alpha') ?: 's.nom';
311
+    $sortorder = GETPOST('sortorder', 'alpha') == 'desc'  ? 'DESC' : 'ASC';
312
+  ?>
313
+  <h2>Chez Client</h2>
205 314
   <table class="border" width="100%">
206 315
     <thead>
207 316
       <tr class="liste_titre">
208
-        <th>Ref.</th>
209
-        <th>Client</th>
210
-        <th>Photocopieurs</th>
317
+        <?php print_liste_field_titre($langs->trans('Client'),$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder); ?>
318
+        <th>
319
+          <table class="border" width="100%">
320
+            <thead>
321
+              <tr>
322
+                <th width="35%">Photocopieurs</th>
323
+                <th>
324
+                  <table class="border" width="100%">
325
+                    <thead>
326
+                      <tr>
327
+                        <th width="60%">Tarifs</th>
328
+                        <th>Derniere mise à jour</th>
329
+                        <th width="15%">Compteurs</th>
330
+                      </tr> 
331
+                    </thead>
332
+                  </table>
333
+                </th>
334
+              </tr>
335
+            </thead>
336
+          </table>
337
+        </th>
211 338
         <th>&nbsp;</th>
212 339
       </tr>
213 340
     </thead>
214 341
     <tbody>
215
-      <?php foreach($societe->all() as $s){ ?>
216
-        <tr>
217
-          <td>
218
-            <a href="<?= $url.'?id='.$s->id.'&action=show' ?>">
219
-              <?= $s->ref ?>
220
-            </a>
221
-          </td>
222
-          <td width="20%">
342
+      <?php $i = 0; ?>
343
+      <?php foreach($societe->all($sortfield, $sortorder) as $s){ ?>
344
+        <?php $i++; ?>
345
+        <tr class="<?= $i%2 ? 'pair' : 'impair' ?>">
346
+          <td width="15%">
223 347
             <a href="<?= $url.'?id='.$s->id.'&action=show' ?>">
224 348
               <?= $s->nom ?>
225 349
             </a>
@@ -229,14 +353,25 @@ else { ?>
229 353
               <tbody>
230 354
                 <?php foreach($s->phcps as $phcp){ ?>
231 355
                   <tr>
232
-                    <td width="30%"><?= $phcp->ref ?> - <?= $phcp->nom ?></td>
356
+                    <td width="35%">
357
+                      <a href="<?= DOL_URL_ROOT."/photocopies/phcp.php?action=show&id=".$phcp->id ?>">
358
+                        <?= $phcp->ref ?> - <?= $phcp->nom ?>
359
+                      </a>
360
+                    </td>
233 361
                     <td>
234
-                      <table class="border" width="100%">
362
+                      <table class="noborder" width="100%">
235 363
                         <tbody>
236
-                          <?php foreach($phcp->phcp_type->products as $product){ ?>
364
+                          <?php foreach($phcp->compteurs as $compteur){ ?>
237 365
                             <tr>
238
-                              <td width="80%"><?= $product->ref ?> - <?= $product->label ?></td>
239
-                              <td>1000</td>
366
+                              <td width="60%">
367
+                                <a href="<?= DOL_URL_ROOT."/product/fiche.php?id=".$compteur->product->id ?>">
368
+                                  <?= $compteur->product->ref ?> - <?= $compteur->product->label ?>
369
+                                </a>
370
+                              </td>
371
+                              <td><?= date("d/m/Y H:i", $compteur->updated_at) ?></td>
372
+                              <td width="15%" class="digits">
373
+                                <?= $compteur->compteur ?>
374
+                              </td>
240 375
                             </tr>
241 376
                           <?php } ?>
242 377
                         </tbody>
@@ -247,11 +382,52 @@ else { ?>
247 382
               </tbody>
248 383
             </table>
249 384
           </td>
250
-          <td align="center"><a href="<?= $url.'?id='.$p->id.'&action=delete' ?>">Edit</a></td>
385
+          <td align="center"><a href="<?= $url.'?id='.$s->id.'&action=edit' ?>">Edit</a></td>
251 386
         </tr>
252 387
       <?php } ?>
253 388
     </tbody>
254 389
   </table>
390
+  
391
+  <h2>Stock</h2>
392
+
393
+  <table class="border" width="100%">
394
+    <tbody>
395
+      <tr>
396
+        <td width="15%">
397
+        </td>
398
+        <td>
399
+          <table class="border" width="100%">
400
+            <tbody>
401
+              <?php $phcps = new Phcp($db); ?>
402
+              <?php foreach($phcps->no_societe() as $phcp){ ?>
403
+                <tr>
404
+                  <td width="35%">
405
+                    <a href="<?= DOL_URL_ROOT."/photocopies/phcp.php?action=show&id=".$phcp->id ?>">
406
+                      <?= $phcp->ref ?> - <?= $phcp->nom ?>
407
+                    </a>
408
+                  </td>
409
+                  <td>
410
+                    <table class="noborder" width="100%">
411
+                      <tbody>
412
+                        <?php foreach($phcp->compteurs as $compteur){ ?>
413
+                          <tr>
414
+                            <td width="60%"><?= $compteur->product->ref ?> - <?= $compteur->product->label ?></td>
415
+                            <td><?= date("d/m/Y H:i", $compteur->updated_at) ?></td>
416
+                            <td width="15%" class="digits"><?= $compteur->compteur ?></td>
417
+                          </tr>
418
+                        <?php } ?>
419
+                      </tbody>
420
+                    </table>
421
+                  </td>
422
+                </tr>
423
+              <?php } ?>
424
+            </tbody>
425
+          </table>
426
+          <td align="center"><a href="<?= $url.'?action=edit' ?>">Edit</a></td>
427
+        </td>
428
+      </tr>
429
+    </tbody>
430
+  </table>
255 431
 <?php } ?>
256 432
     <!--/div-->
257 433
   </div>

+ 4
- 4
core/modules/modPhotocopies.class.php View File

@@ -60,9 +60,9 @@ class modPhotocopies extends DolibarrModules
60 60
         // Module description
61 61
         // used if translation string 'ModuleXXXDesc' not found
62 62
         // (where XXX is value of numeric property 'numero' of module)
63
-        $this->description = "Description of module Photocopies";
63
+        $this->description = "Module pour la gestion de compteurs de photocopies";
64 64
         // Possible values for version are: 'development', 'experimental' or version
65
-        $this->version = 'development';
65
+        $this->version = '1.0.0';
66 66
         // Key used in llx_const table to save module status enabled/disabled
67 67
         // (where MYMODULE is value of property name of module in uppercase)
68 68
         $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
@@ -93,7 +93,7 @@ class modPhotocopies extends DolibarrModules
93 93
             // Set this to 1 if module has its own models directory
94 94
             //'models' => 0,
95 95
             // Set this to relative path of css if module has its own css file
96
-            'css' => '/photocopies/css/mycss.css.php',
96
+            'css' => '/photocopies/css/photocopies.css'
97 97
             // Set here all hooks context managed by module
98 98
             //'hooks' => array('hookcontext1','hookcontext2')
99 99
             // Set here all workflow context managed by module
@@ -261,7 +261,7 @@ class modPhotocopies extends DolibarrModules
261 261
         	'titre'=>'Photocopies',
262 262
         	'mainmenu'=>'photocopies',
263 263
         	'leftmenu'=>'photocopieurs',
264
-        	'url'=>'/photocopies/index.php',
264
+        	'url'=>'/photocopies/compteurs.php',
265 265
         	// Lang file to use (without .lang) by module.
266 266
         	// File must be in langs/code_CODE/ directory.
267 267
         	'langs'=>'photocopies',

+ 0
- 24
css/mycss.css.php View File

@@ -1,24 +0,0 @@
1
-<?php
2
-/* <one line to give the program's name and a brief idea of what it does.>
3
- * Copyright (C) <year>  <name of author>
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
-/**
20
- *	\file		css/mycss.css.php
21
- *	\ingroup	mymodule
22
- *	\brief		This file is an example css file
23
- *				Put some comments here
24
- */

+ 11
- 0
css/photocopies.css View File

@@ -0,0 +1,11 @@
1
+.digits {
2
+  color: #8F00FE;
3
+  font-family: Consolas,monospace;
4
+}
5
+
6
+table.noborder,
7
+table.border,
8
+table.noborder th,
9
+table.border th {
10
+  border: 0;
11
+}

BIN
img/mymodule.png View File


BIN
img/object_mymodule.png View File


BIN
img/object_photocopies.png View File


BIN
img/photocopies.png View File


+ 0
- 53
index.php View File

@@ -1,53 +0,0 @@
1
-<?php
2
-/* <one line to give the program's name and a brief idea of what it does.>
3
- * Copyright (C) <year>  <name of author>
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-$res=0;
19
-if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
20
-if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
21
-if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
22
-if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php';     // Used on dev env only
23
-if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
24
-if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
25
-if (! $res) die("Include of main fails");
26
-// Change this following line to use the correct relative path from htdocs
27
-dol_include_once('/module/class/phcp.class.php');
28
-
29
-// Load traductions files requiredby by page
30
-$langs->load("companies");
31
-$langs->load("other");
32
-
33
-// Get parameters
34
-$id			= GETPOST('id','int');
35
-$action		= GETPOST('action','alpha');
36
-$myparam	= GETPOST('myparam','alpha');
37
-
38
-// Protection if external user
39
-if ($user->societe_id > 0)
40
-{
41
-	//accessforbidden();
42
-}
43
-
44
-
45
-
46
-llxHeader('','Liste des Photocopieurs','');
47
-
48
-
49
-
50
-// End of page
51
-llxFooter();
52
-$db->close();
53
-?>

+ 1
- 1
langs/en_US/photocopies.lang View File

@@ -23,7 +23,7 @@
23 23
 Module6182Name = Photocopies
24 24
 # Module description 'ModuleXXXDesc'
25 25
 # (where XXX is value of numeric property 'numero' of module)
26
-Module6182Desc = Module pour la gestion de compteur de photocopies
26
+Module6182Desc = Module pour la gestion de compteurs de photocopies
27 27
 
28 28
 #
29 29
 # Admin page

+ 12
- 6
phcp.php View File

@@ -116,7 +116,7 @@ if (($action == 'new') || ($action == 'edit')){
116 116
         <tr>
117 117
           <td class=""><label for="phcp_type">Type de Photocopieur</label></td>
118 118
           <td>
119
-            <select name="fk_phcp_type" id="phcp_type" placeholder="Type de photocopieur">
119
+          <select name="fk_phcp_type" id="phcp_type" placeholder="Type de photocopieur" <?= $action=='edit'?'disabled="disabled"':'' ?>>
120 120
               <option value="">AUCUN</option>
121 121
               <?php
122 122
                 $phcptype = new PhcpType($db); 
@@ -202,18 +202,24 @@ elseif ($action == 'show') {
202 202
 }
203 203
 //------------------------------------------------------------------------------
204 204
 else { ?>
205
+  <?php
206
+    $sortfield = GETPOST('sortfield', 'alpha') ?: 'p.ref';
207
+    $sortorder = GETPOST('sortorder', 'alpha') == 'desc'  ? 'DESC' : 'ASC';
208
+  ?>
205 209
   <table class="noborder" width="100%">
206 210
     <thead>
207 211
       <tr class="liste_titre">
208
-        <th>Ref.</th>
209
-        <th>Photocopieur Label</th>
210
-        <th>Photocopieur Type</th>
211
-        <th>Chez Client</th>
212
+        <?php 
213
+          print_liste_field_titre($langs->trans('Ref.'),$_SERVER['PHP_SELF'],'p.ref','',$param,'',$sortfield,$sortorder);
214
+          print_liste_field_titre($langs->trans('Photocopieur Label'),$_SERVER['PHP_SELF'],'p.nom','',$param,'',$sortfield,$sortorder);
215
+          print_liste_field_titre($langs->trans('Photocopieur Type'),$_SERVER['PHP_SELF'],'pt.nom','',$param,'',$sortfield,$sortorder);
216
+          print_liste_field_titre($langs->trans('Chez Client'),$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
217
+        ?>
212 218
         <th>&nbsp;</th>
213 219
       </tr>
214 220
     </thead>
215 221
     <tbody>
216
-      <?php foreach($phcp->all() as $p){ ?>
222
+      <?php foreach($phcp->all($sortfield, $sortorder) as $p){ ?>
217 223
         <tr>
218 224
           <td>
219 225
             <a href="<?= $url.'?id='.$p->id.'&action=show' ?>">

+ 6
- 2
phcptype.php View File

@@ -249,12 +249,16 @@ elseif ($action == 'show') {
249 249
 //------------------------------------------------------------------------------
250 250
 else {
251 251
 
252
+  $sortfield = GETPOST('sortfield', 'alpha') == 'pt.nom' ? 'pt.nom' : 'pt.ref';
253
+  $sortorder = GETPOST('sortorder', 'alpha') == 'desc'  ? 'DESC' : 'ASC';
252 254
   $form= new Form($db);
253 255
   $sql = "SELECT";
254 256
   $sql.= " pt.rowid,";
255 257
   $sql.= " pt.ref,";
256 258
 	$sql.= " pt.nom";
257 259
   $sql.= " FROM ".MAIN_DB_PREFIX."phcp_type as pt";
260
+  $sql.= " ORDER BY ".$sortfield." ".$sortorder;
261
+  
258 262
 
259 263
   print '<table class="noborder" width="100%">'."\n";
260 264
   print '<tr class="liste_titre">';
@@ -273,9 +277,9 @@ else {
273 277
           while ($i < $num){
274 278
               $obj = $db->fetch_object($resql);
275 279
               if ($obj){
276
-                  print '<tr><td>';
280
+                  print '<tr><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
277 281
                   print $obj->ref;
278
-                  print '</td><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
282
+                  print '</a></td><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
279 283
                   print $obj->nom;
280 284
                   print '</a></td><td><ul>';
281 285
 

+ 39
- 25
sql/data.sql View File

@@ -16,25 +16,39 @@
16 16
 
17 17
 -- Types de photocopieurs
18 18
 insert into llx_phcp_type(rowid, ref, nom)
19
-values (1, "PTA", "Photocopieur Type A") on duplicate key update nom=values(nom);
19
+values (1, "PHCP-T-NB", "Photocopieur Noir & Blanc") on duplicate key update nom=values(nom);
20 20
 insert into llx_phcp_type(rowid, ref, nom)
21
-values (2, "PTB", "Photocopieur Type B") on duplicate key update nom=values(nom);
21
+values (2, "PHCP-T-CO", "Photocopieur Couleur") on duplicate key update nom=values(nom);
22 22
 
23 23
 -- Ressources Photocopieur
24 24
 insert into llx_phcp (rowid, ref, nom, fk_phcp_type, fk_societe) 
25
-values (1, "PA1", "Photocopieur Type A n1", 1, 1) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
25
+values (1, "PHCP-NB-1", "Photocopieur Noir & Blanc 1", 1, 1) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
26 26
 insert into llx_phcp (rowid, ref, nom, fk_phcp_type, fk_societe) 
27
-values (2, "PA2", "Photocopieur Type A n2", 1, 2) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
27
+values (2, "PHCP-NB-2", "Photocopieur Noir & Blanc 2", 1, 2) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
28 28
 insert into llx_phcp (rowid, ref, nom, fk_phcp_type, fk_societe) 
29
-values (3, "PA3", "Photocopieur Type A n3", 1, 3) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
29
+values (3, "PHCP-NB-3", "Photocopieur Noir & Blanc 3", 1, 3) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
30 30
 insert into llx_phcp (rowid, ref, nom, fk_phcp_type, fk_societe) 
31
-values (4, "PB1", "Photocopieur Type B n1", 2, 4) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
31
+values (4, "PHCP-CO-1", "Photocopieur Couleur 1", 2, 4) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
32 32
 insert into llx_phcp (rowid, ref, nom, fk_phcp_type, fk_societe) 
33
-values (5, "PB2", "Photocopieur Type B n2", 2, 1) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
33
+values (5, "PHCP-CO-2", "Photocopieur Couleur 2", 2, 1) on duplicate key update nom=values(nom), fk_phcp_type=values(fk_phcp_type), fk_societe=values(fk_societe);
34
+
35
+-- Products
36
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
37
+values (1, 'PH-A4-NB', 'Photocopie A4 Noir & Blanc', 0.01, 19.6, 1);
38
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
39
+values (2, 'PH-A4-CO', 'Photocopie A4 Couleur', 0.02, 19.6, 1);
40
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
41
+values (3, 'PH-A3-NB', 'Photocopie A3 Noir & Blanc', 0.02, 19.6, 1);
42
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
43
+values (4, 'PH-A3-CO', 'Photocopie A3 Couleur', 0.04, 19.6, 1);
44
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
45
+values (5, 'PH-A2-NB', 'Photocopie A2 Noir & Blanc', 0.04, 19.6, 1);
46
+insert into llx_product(rowid, ref, label, price, tva_tx, fk_product_type)
47
+values (6, 'PH-A2-CO', 'Photocopie A2 Couleur', 0.08, 19.6, 1);
34 48
 
35 49
 -- Type de photocopieurs avec leur tarifs
36 50
 insert into llx_phcp_type_product(rowid, fk_phcp_type, fk_product)
37
-values (1, 1, 2) on duplicate key update fk_phcp_type=values(fk_phcp_type), fk_product=values(fk_product);
51
+values (1, 1, 1) on duplicate key update fk_phcp_type=values(fk_phcp_type), fk_product=values(fk_product);
38 52
 insert into llx_phcp_type_product(rowid, fk_phcp_type, fk_product)
39 53
 values (2, 1, 3) on duplicate key update fk_phcp_type=values(fk_phcp_type), fk_product=values(fk_product);
40 54
 insert into llx_phcp_type_product(rowid, fk_phcp_type, fk_product)
@@ -47,33 +61,33 @@ insert into llx_phcp_type_product(rowid, fk_phcp_type, fk_product)
47 61
 values (6, 2, 4) on duplicate key update fk_phcp_type=values(fk_phcp_type), fk_product=values(fk_product);
48 62
 
49 63
 -- Photocopieurs et leur compteurs
50
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
51
-values (1, 1, 2, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
52
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
64
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
65
+values (1, 1, 1, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
66
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
53 67
 values (2, 1, 3, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
54
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
55
-values (3, 2, 2, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
56
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
68
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
69
+values (3, 2, 1, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
70
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
57 71
 values (4, 2, 3, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
58
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
59
-values (5, 3, 2, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
60
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
72
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
73
+values (5, 3, 1, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
74
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
61 75
 values (6, 3, 3, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
62 76
 
63
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
77
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
64 78
 values (7, 4, 1, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
65
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
79
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
66 80
 values (8, 4, 2, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
67
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
81
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
68 82
 values (9, 4, 3, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
69
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
83
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
70 84
 values (10, 4, 4, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
71
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
85
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
72 86
 values (11, 5, 1, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
73
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
87
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
74 88
 values (12, 5, 2, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
75
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
89
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
76 90
 values (13, 5, 3, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
77
-insert into llx_phcp_product(rowid, fk_phcp, fk_product, last_compteur, compteur)
91
+insert into llx_compteur(rowid, fk_phcp, fk_product, last_compteur, compteur)
78 92
 values (14, 5, 4, 0, 0) on duplicate key update fk_phcp=values(fk_phcp), fk_product=values(fk_product), last_compteur=values(last_compteur), compteur=values(compteur);
79 93
 

sql/llx_phcp_product.key.sql → sql/llx_compteur.key.sql View File

@@ -14,10 +14,10 @@
14 14
 -- You should have received a copy of the GNU General Public License
15 15
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
 
17
---ALTER TABLE llx_phcp_product ADD UNIQUE INDEX idx_phcp_product_uk_phcp_product_number (phcp_product_number, entity);
17
+--ALTER TABLE llx_compteur ADD UNIQUE INDEX idx_compteur_uk_compteur_number (compteur_number, entity);
18 18
 
19
-ALTER TABLE llx_phcp_product ADD INDEX idx_phcp_product_fk_phcp (fk_phcp);
20
-ALTER TABLE llx_phcp_product ADD INDEX idx_phcp_product_fk_product (fk_product);
19
+ALTER TABLE llx_compteur ADD INDEX idx_compteur_fk_phcp (fk_phcp);
20
+ALTER TABLE llx_compteur ADD INDEX idx_compteur_fk_product (fk_product);
21 21
 
22
-ALTER TABLE llx_phcp_product ADD CONSTRAINT fk_phcp_product_fk_phcp       FOREIGN KEY (fk_phcp) REFERENCES llx_phcp (rowid);
23
-ALTER TABLE llx_phcp_product ADD CONSTRAINT fk_phcp_product_fk_product       FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
22
+ALTER TABLE llx_compteur ADD CONSTRAINT fk_compteur_fk_phcp       FOREIGN KEY (fk_phcp) REFERENCES llx_phcp (rowid);
23
+ALTER TABLE llx_compteur ADD CONSTRAINT fk_compteur_fk_product    FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);

sql/llx_phcp_product.sql → sql/llx_compteur.sql View File

@@ -14,17 +14,19 @@
14 14
 -- You should have received a copy of the GNU General Public License
15 15
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
 
17
-create table llx_phcp_product
17
+create table llx_compteur
18 18
 (
19 19
   rowid					                            integer AUTO_INCREMENT PRIMARY KEY,
20 20
 
21 21
   ref   				                            varchar(255),							-- reference into an internal system (used by dolibarr)
22 22
 
23
-  last_modification                         date,
24 23
   compteur                                  integer,
25 24
   last_compteur                             integer,
26 25
 
27 26
   fk_phcp                                   integer,								-- reference phcp
28
-  fk_product                                integer                 -- reference produuit
27
+  fk_product                                integer,                 -- reference produuit
28
+
29
+  created_at                                 TIMESTAMP NOT NULL DEFAULT 0,
30
+  updated_at                                 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
29 31
 
30 32
 )ENGINE=innodb;