/tests/kassa_api/get_operations.php

https://github.com/axshavan/nitrofuran · PHP · 160 lines · 152 code · 8 blank · 0 comment · 6 complexity · 70211a6164b639e2f93671460d73b2a2 MD5 · raw file

  1. <? header("Content-Type: text/html; charset=utf-8") ?>
  2. <form action="get_operations.php" method="get">
  3. <input type="text" name="login" id="login" value="<?= $_GET['login'] ? htmlspecialchars($_GET['login']) : 'admin' ?>"> <label for="login">login</label><br />
  4. <input type="text" name="password" id="password" value="<?= $_GET['password'] ? htmlspecialchars($_GET['password']) : '' ?>"> <label for="password">password</label><br />
  5. <input type="submit" value="Test">
  6. </form>
  7. <?php
  8. if($_GET['login'])
  9. {
  10. $_accounts = array();
  11. $_currencies = array();
  12. $_optypesg = array();
  13. $curl = curl_init($_SERVER['SERVER_NAME'].'/kassa/api/');
  14. curl_setopt($curl, CURLOPT_POSTFIELDS, 'login='.$_GET['login'].'&password='.$_GET['password'].'&method=getaccounts');
  15. ob_start();
  16. curl_exec($curl);
  17. $curl_res = simplexml_load_string(ob_get_clean());
  18. curl_close($curl);
  19. foreach($curl_res->accounts->account as $v)
  20. {
  21. $_accounts[(int)$v->attributes()->id] = array
  22. (
  23. 'default' => (int)$v->attributes()->default,
  24. 'active' => (int)$v->attributes()->active,
  25. 'name' => (string)$v
  26. );
  27. }
  28. $curl = curl_init($_SERVER['SERVER_NAME'].'/kassa/api/');
  29. curl_setopt($curl, CURLOPT_POSTFIELDS, 'login='.$_GET['login'].'&password='.$_GET['password'].'&method=getcurrencies');
  30. ob_start();
  31. curl_exec($curl);
  32. $curl_res = simplexml_load_string(ob_get_clean());
  33. curl_close($curl);
  34. foreach($curl_res->currencies->currency as $v)
  35. {
  36. $_currencies[(int)$v->attributes()->id] = array
  37. (
  38. 'default' => (int)$v->attributes()->default,
  39. 'symbol' => (string)$v->attributes()->symbol,
  40. 'name' => (string)$v
  41. );
  42. }
  43. $curl = curl_init($_SERVER['SERVER_NAME'].'/kassa/api/');
  44. curl_setopt($curl, CURLOPT_POSTFIELDS, 'login='.$_GET['login'].'&password='.$_GET['password'].'&method=getoptypes&group=1');
  45. ob_start();
  46. curl_exec($curl);
  47. $curl_res = simplexml_load_string(ob_get_clean());
  48. curl_close($curl);
  49. foreach($curl_res->optypegroups->optypegroup as $v)
  50. {
  51. $_optypes = array();
  52. foreach($v->optype as $vv)
  53. {
  54. $_optypes[(int)$vv->attributes()->id] = array
  55. (
  56. 'name' => (string)$vv,
  57. 'is_income' => (int)$vv->attributes()->is_income
  58. );
  59. }
  60. $_optypesg[(int)$v->attributes()->id] = array
  61. (
  62. 'name' => (string)$v->attributes()->name,
  63. 'optypes' => $_optypes
  64. );
  65. }
  66. ?>
  67. <form action="get_operations.php" method="get">
  68. <input type="hidden" name="login" value="<?= htmlspecialchars($_GET['login']) ?>">
  69. <input type="hidden" name="password" value="<?= htmlspecialchars($_GET['password']) ?>">
  70. <input type="hidden" name="filter" value="1">
  71. <input type="text" name="datefrom" id="datefrom" value="<?= $_GET['datefrom'] ? htmlspecialchars($_GET['datefrom']) : date('Y-m-d H:i:s', time() - 7 * 86400) ?>"> <label for="datefrom">Дата от</label><br />
  72. <input type="text" name="dateto" id="dateto" value="<?= $_GET['dateto'] ? htmlspecialchars($_GET['dateto']) : date('Y-m-d H:i:s') ?>"> <label for="dateto">Дата до</label><br />
  73. <select name="account" id="account">
  74. <option value="0">Все</option>
  75. <? foreach($_accounts as $k => $v): ?>
  76. <option value="<?= (int)$k ?>" <?= $_GET['account'] == $k ? 'selected="selected"' : '' ?>><?= htmlspecialchars($v['name']) ?></option>
  77. <? endforeach; ?>
  78. </select> <label for="account">Счёт</label><br />
  79. <select name="currency" id="currency">
  80. <option value="0">Все</option>
  81. <? foreach($_currencies as $k => $v): ?>
  82. <option value="<?= (int)$k ?>" <?= $_GET['currency'] == $k ? 'selected="selected"' : '' ?>><?= htmlspecialchars($v['name']) ?></option>
  83. <? endforeach; ?>
  84. </select> <label for="currency">Валюта</label><br />
  85. <select name="optypegroup" id="optypegroup">
  86. <option value="0">Все</option>
  87. <? foreach($_optypesg as $k => $v): ?>
  88. <option value="<?= (int)$k ?>" <?= $_GET['optypegroup'] == $k ? 'selected="selected"' : '' ?>><?= htmlspecialchars($v['name']) ?></option>
  89. <? endforeach; ?>
  90. </select> <label for="optypegroup">Группа типов</label><br />
  91. Типы операций по группам:<br />
  92. <? foreach($_optypesg as $k => $v): ?>
  93. <select name="optype_<?= (int)$k ?>" id="optype_<?= (int)$k ?>">
  94. <option value="0">Все</option>
  95. <? foreach($v['optypes'] as $kk => $vv): ?>
  96. <option value="<?= (int)$kk ?>" <?= $_GET['optype_'.$k] == $kk ? 'selected="selected"' : '' ?>><?= htmlspecialchars($vv['name']) ?></option>
  97. <? endforeach; ?>
  98. </select> <label for="optype_<?= (int)$k ?>"><?= htmlspecialchars($v['name']) ?></label><br />
  99. <? endforeach; ?>
  100. <br />
  101. <input type="submit" value="Test">
  102. </form>
  103. <?
  104. if($_GET['filter'])
  105. {
  106. $curl = curl_init($_SERVER['SERVER_NAME'].'/kassa/api/');
  107. $query = 'login='.$_GET['login']
  108. .'&password='.$_GET['password']
  109. .'&method=getoperations'
  110. .'&date_start='.$_GET['datefrom']
  111. .'&date_end='.$_GET['dateto']
  112. .'&account='.$_GET['account']
  113. .'&currency='.$_GET['currency']
  114. .'&optypegroup='.$_GET['optypegroup']
  115. .'&optype='.(int)$_GET['optype_'.$_GET['optypegroup']];
  116. curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
  117. ob_start();
  118. curl_exec($curl);
  119. $curl_res = ob_get_clean();
  120. curl_close($curl);
  121. echo '<pre>';
  122. print_r(htmlspecialchars($curl_res));
  123. echo '</pre>';
  124. $curl_res = simplexml_load_string($curl_res);
  125. echo '<table>
  126. <tr>
  127. <th>id</th>
  128. <th>amount</th>
  129. <th>time (timestamp)</th>
  130. <th>currency</th>
  131. <th>account</th>
  132. <th>optype</th>
  133. <th>comment</th>
  134. </tr>';
  135. foreach($curl_res->operations->operation as $v)
  136. {
  137. ?>
  138. <tr>
  139. <td><?= (int)$v->attributes()->id ?></td>
  140. <td><?= (float)$v->amount ?></td>
  141. <td><?= htmlspecialchars((string)$v->time) ?> (<?= (int)$v->time->attributes()->timestamp ?>)</td>
  142. <td><?= htmlspecialchars((string)$v->currency) ?> (<?= (int)$v->currency->attributes()->id ?>)</td>
  143. <td><?= htmlspecialchars((string)$v->account) ?> (<?= (int)$v->account->attributes()->id ?>)</td>
  144. <td><?= htmlspecialchars((string)$v->optype) ?> (<?= (int)$v->optype->attributes()->id ?>)</td>
  145. <td><?= htmlspecialchars((string)$v->comment) ?></td>
  146. </tr>
  147. <?
  148. }
  149. echo '<table>';
  150. }
  151. }
  152. ?>