選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

compteurs.php 15KB

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