An easy point of sale system with automatic inventory tracking. https://netsyms.biz/apps/nickelbox/
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Receipt.lib.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. class Receipt {
  8. private $lines = [];
  9. private $header = [];
  10. private $footer = [];
  11. function __construct() {
  12. }
  13. function appendLine(ReceiptLine $line) {
  14. $this->lines[] = $line;
  15. }
  16. function appendLines($lines) {
  17. foreach ($lines as $l) {
  18. $this->lines[] = $l;
  19. }
  20. }
  21. function appendHeader(ReceiptLine $line) {
  22. $this->header[] = $line;
  23. }
  24. function appendFooter(ReceiptLine $line) {
  25. $this->footer[] = $line;
  26. }
  27. function appendBreak() {
  28. $this->lines[] = new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_HR);
  29. }
  30. function appendBlank() {
  31. $this->lines[] = new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_BLANK);
  32. }
  33. function getHtml($title = "") {
  34. global $SECURE_NONCE;
  35. $html = <<<END
  36. <!DOCTYPE html>
  37. <meta charset="UTF-8">
  38. <meta name="viewport" content="width=device-width, initial-scale=1">
  39. <title>$title</title>
  40. <style nonce="$SECURE_NONCE">
  41. .flex {
  42. display: flex;
  43. justify-content: space-between;
  44. margin: 0;
  45. }
  46. .bold {
  47. font-weight: bold;
  48. }
  49. .centered {
  50. justify-content: center;
  51. }
  52. </style>
  53. END;
  54. if (count($this->header) > 0) {
  55. foreach ($this->header as $line) {
  56. $html .= $line->getHtml() . "\n";
  57. }
  58. $html .= (new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_HR))->getHtml();
  59. }
  60. foreach ($this->lines as $line) {
  61. $html .= $line->getHtml() . "\n";
  62. }
  63. if (count($this->footer) > 0) {
  64. $html .= (new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_HR))->getHtml();
  65. foreach ($this->footer as $line) {
  66. $html .= $line->getHtml() . "\n";
  67. }
  68. }
  69. return $html;
  70. }
  71. function getPlainText($width) {
  72. $lines = [];
  73. if (count($this->header) > 0) {
  74. foreach ($this->header as $line) {
  75. $lines[] = $line->getPlainText($width);
  76. }
  77. $lines[] = (new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_HR))->getPlainText($width);
  78. }
  79. foreach ($this->lines as $line) {
  80. $lines[] = $line->getPlainText($width);
  81. }
  82. if (count($this->footer) > 0) {
  83. $lines[] = (new ReceiptLine("", "", "", ReceiptLine::LINEFORMAT_HR))->getPlainText($width);
  84. foreach ($this->footer as $line) {
  85. $lines[] = $line->getPlainText($width);
  86. }
  87. }
  88. return implode("\n", $lines);
  89. }
  90. function getArray($width = 64) {
  91. $header = [];
  92. $lines = [];
  93. $footer = [];
  94. foreach ($this->header as $line) {
  95. $header[] = $line->getArray($width);
  96. }
  97. foreach ($this->lines as $line) {
  98. $lines[] = $line->getArray($width);
  99. }
  100. foreach ($this->footer as $line) {
  101. $footer[] = $line->getArray($width);
  102. }
  103. return ["header" => $header, "lines" => $lines, "footer" => $footer];
  104. }
  105. function getJson($width = 64) {
  106. return json_encode($this->getArray($width));
  107. }
  108. }