Browse Source

Vue Compteurs Ok

Ghislain Loaec 5 years ago
parent
commit
a8e261857b
3 changed files with 294 additions and 2 deletions
  1. 0
    1
      class/phcp.class.php
  2. 30
    1
      class/societe.class.php
  3. 264
    0
      compteurs.php

+ 0
- 1
class/phcp.class.php View File

@@ -138,7 +138,6 @@ class Phcp extends CommonObject
138 138
 
139 139
         
140 140
 		$sql.= ")";
141
- echo $sql;
142 141
 		$this->db->begin();
143 142
 
144 143
 	   	dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);

+ 30
- 1
class/societe.class.php View File

@@ -1,8 +1,37 @@
1 1
 <?php
2 2
 require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
3
+require_once(DOL_DOCUMENT_ROOT."/photocopies/class/phcp.class.php");
3 4
 
4 5
 class CSociete extends Societe {
5 6
 
7
+    function fetch($id){
8
+      $r = parent::fetch($id);
9
+      $this->phcps = array();
10
+      
11
+      $sql = "SELECT";
12
+		  $sql.= " t.rowid";
13
+      $sql.= " FROM ".MAIN_DB_PREFIX."phcp as t";
14
+      $sql.= " WHERE t.fk_societe = ".$this->id;
15
+
16
+    	dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
17
+      $resql=$this->db->query($sql);
18
+      if ($resql){
19
+        if ($num = $this->db->num_rows($resql)){
20
+          $i = 0;
21
+          while ($i < $num){
22
+            $obj = $this->db->fetch_object($resql);
23
+            if ($obj){
24
+              $phcp = new Phcp($this->db);
25
+              $phcp->fetch($obj->rowid);
26
+              $this->phcps[]= $phcp;
27
+            }
28
+            $i++;
29
+          }
30
+        }
31
+      }
32
+      return $r;
33
+    }
34
+
6 35
     function all(){
7 36
       global $conf, $langs;
8 37
       $sql = "SELECT";
@@ -19,7 +48,7 @@ class CSociete extends Societe {
19 48
           while ($i < $num){
20 49
             $obj = $this->db->fetch_object($resql);
21 50
             if ($obj){
22
-              $societe = new Societe($this->db);
51
+              $societe = new CSociete($this->db);
23 52
               $societe->fetch($obj->rowid);
24 53
               $list[]= $societe;
25 54
             }

+ 264
- 0
compteurs.php View File

@@ -0,0 +1,264 @@
1
+<?php
2
+$res=0;
3
+if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
4
+if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
5
+if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
6
+if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php';     // Used on dev env only
7
+if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
8
+if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php';   // Used on dev env only
9
+if (! $res) die("Include of main fails");
10
+// Change this following line to use the correct relative path from htdocs
11
+dol_include_once('/photocopies/class/phcp.class.php');
12
+dol_include_once('/photocopies/class/societe.class.php');
13
+
14
+// Load traductions files requiredby by page
15
+$langs->load("companies");
16
+$langs->load("other");
17
+
18
+// Get parameters
19
+$id			  = GETPOST('id','int');
20
+$action		= GETPOST('action','alpha') ?: 'list';
21
+$myparam	= GETPOST('myparam','alpha');
22
+$url      = DOL_URL_ROOT."/photocopies/phcp.php";
23
+$phcp     = null;
24
+$title    = null;
25
+
26
+/*******************************************************************
27
+* ACTIONS
28
+*
29
+* Put here all code to do according to value of "action" parameter
30
+********************************************************************/
31
+
32
+$societe = new CSociete($db);
33
+if($id) $societe->fetch($id);
34
+else $societe->initAsSpecimen();
35
+
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 
63
+    $action = 'list';
64
+}
65
+
66
+switch($action){
67
+  case 'new': $title = "Nouveau Photocopieur"; llxHeader('',$title,''); break;
68
+  case 'edit': $title = "Modifier Photocopieur"; llxHeader('',$title,''); break;
69
+  case 'list': $title = "Compteurs"; llxHeader('',$title,''); break;
70
+  case 'show': $title = "Photocopieur : ".$phcp->nom; llxHeader('',$title,''); break;
71
+}
72
+
73
+//===============================[TEMPLATE]=====================================
74
+if($phcp && $phcp->error){
75
+?>
76
+<script type="text/javascript">
77
+  $(document).ready(function(){
78
+    $.jnotify("<?= $phcp->error ?>", "error");
79
+  })
80
+</script>
81
+<?php } ?>
82
+
83
+<div class="fiche">
84
+  <table width="100%" border="0" style="margin-bottom: 2px;" class="notopnoleftnoright" summary="">
85
+    <tbody>
86
+      <tr>
87
+        <td width="40" valign="middle" align="left" class="nobordernopadding hideonsmartphone">
88
+          <img border="0" id="pictotitle" title="" alt="" src="/dolibarr/theme/auguria/img/title.png">
89
+        </td>
90
+        <td valign="middle" class="nobordernopadding">
91
+          <div class="titre"><?= $title ?></div>
92
+        </td>
93
+      </tr>
94
+    </tbody>
95
+  </table>
96
+
97
+  <div class="fichecenter">
98
+    <!--div class="fichethirdleft"-->
99
+
100
+<?php
101
+//------------------------------------------------------------------------------
102
+if (($action == 'new') || ($action == 'edit')){
103
+?>
104
+  <form action="<?= $url."?action=".($action=='new'?'create':'update') ?>" method="POST">
105
+    <?php if($id){ ?><input type="hidden" name="id" value="<?= $id ?>" /><?php } ?>
106
+    <table width="100%" class="border">
107
+      <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>
144
+      </tbody>
145
+    </table>
146
+    <div class="tabsAction">
147
+      <div class="inline-block divButAction">
148
+        <input type="submit" class="butAction" value="<?= $action=='new'?'Créer':'Modifier' ?>" />
149
+      </div>
150
+    </div>
151
+  </form>
152
+<?php
153
+} 
154
+//------------------------------------------------------------------------------
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
+else { ?>
205
+  <table class="border" width="100%">
206
+    <thead>
207
+      <tr class="liste_titre">
208
+        <th>Ref.</th>
209
+        <th>Client</th>
210
+        <th>Photocopieurs</th>
211
+        <th>&nbsp;</th>
212
+      </tr>
213
+    </thead>
214
+    <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%">
223
+            <a href="<?= $url.'?id='.$s->id.'&action=show' ?>">
224
+              <?= $s->nom ?>
225
+            </a>
226
+          </td>
227
+          <td>
228
+            <table class="border" width="100%">
229
+              <tbody>
230
+                <?php foreach($s->phcps as $phcp){ ?>
231
+                  <tr>
232
+                    <td width="30%"><?= $phcp->ref ?> - <?= $phcp->nom ?></td>
233
+                    <td>
234
+                      <table class="border" width="100%">
235
+                        <tbody>
236
+                          <?php foreach($phcp->phcp_type->products as $product){ ?>
237
+                            <tr>
238
+                              <td width="80%"><?= $product->ref ?> - <?= $product->label ?></td>
239
+                              <td>1000</td>
240
+                            </tr>
241
+                          <?php } ?>
242
+                        </tbody>
243
+                      </table>
244
+                    </td>
245
+                  </tr>
246
+                <?php } ?>
247
+              </tbody>
248
+            </table>
249
+          </td>
250
+          <td align="center"><a href="<?= $url.'?id='.$p->id.'&action=delete' ?>">Edit</a></td>
251
+        </tr>
252
+      <?php } ?>
253
+    </tbody>
254
+  </table>
255
+<?php } ?>
256
+    <!--/div-->
257
+  </div>
258
+</div> 
259
+
260
+<?php
261
+  // End of page
262
+  llxFooter();
263
+  $db->close();
264
+?>