Track items sold and graph profit for player shop inventory.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.0 KiB

6 years ago
  1. {% extends "layout.html" %}
  2. {% block left_top_bar %}
  3. <button class="uk-button uk-button-default uk-button-small uk-border-rounded"
  4. uk-toggle="target: #charts-container">Show/Hide Charts</button>
  5. {% endblock %}
  6. {% block center_top_bar %}
  7. <h4 class="uk-text-center">{{ product.name }}</h4>
  8. {% endblock %}
  9. {% block content %}
  10. <div id="charts-container" uk-grid hidden>
  11. <div class="uk-width-1-1">
  12. <canvas id="time-chart"></canvas>
  13. </div>
  14. </div>
  15. <table id="products" class="uk-table uk-table-small uk-table-striped uk-table-hover uk-margin-large-left">
  16. <thead>
  17. <tr>
  18. <th>Stock</th>
  19. <th>Price (Raw)</th>
  20. <th>Price (Cvt)</th>
  21. <th>Update</th>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. {% for entry in product.entries %}
  26. <tr>
  27. <td>{{ entry.stock }}</td>
  28. <td>{{ entry.raw_price }}</td>
  29. <td>A${{ entry.price }}</td>
  30. <td>{{ entry.date.isoformat() }}</td>
  31. </tr>
  32. {% endfor %}
  33. </tbody>
  34. <caption class="uk-margin-small-bottom">{{ product.entries | length }} total entries.</caption>
  35. </table>
  36. {% endblock %}
  37. {% block pagescripts %}
  38. <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.3/moment.min.js"></script>
  39. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.js"></script>
  40. <script>
  41. /* Chart.js */
  42. var item_labels = [
  43. "{{ product.name }}",
  44. ];
  45. var time_data = [
  46. {% for entry in product.entries %}
  47. {x: "{{ entry.date.isoformat() }}", y: {{ entry.stock }}},
  48. {% endfor %}
  49. ];
  50. function init_time_chart(labels, timedata) {
  51. var ctx = document.getElementById("time-chart").getContext('2d');
  52. var chart = new Chart(ctx, {
  53. type: 'line',
  54. data: {
  55. labels: labels,
  56. datasets: [
  57. {
  58. label: 'Entries',
  59. backgroundColor: 'rgb(93, 173, 226)',
  60. borderColor: 'rgb(89, 131, 227)',
  61. fill: false,
  62. data: timedata,
  63. }
  64. ],
  65. },
  66. options: {
  67. responsive: true,
  68. title: { display: true, text: 'Entries'},
  69. scales: {
  70. xAxes: [
  71. {
  72. type: 'time',
  73. distribution: 'series',
  74. display: true,
  75. scaleLabel: {
  76. display: true,
  77. labelString: 'Date'
  78. },
  79. time: {
  80. unit: 'day',
  81. unitStepSize: 1,
  82. displayFormats: {
  83. day: 'MMM D YYYY h:mm a'
  84. }
  85. },
  86. ticks: {
  87. major: {
  88. fontStyle: "bold",
  89. fontColor: "#FF0000"
  90. },
  91. source: 'data'
  92. }
  93. }
  94. ],
  95. yAxes: [
  96. {
  97. display: true,
  98. scaleLabel: {
  99. display: true,
  100. labelString: 'Stock'
  101. }
  102. }
  103. ]
  104. }
  105. }
  106. });
  107. }
  108. /* On Page Ready */
  109. document.addEventListener("DOMContentLoaded", function(event) {
  110. init_time_chart(item_labels, time_data);
  111. });
  112. </script>
  113. {% endblock %}