documents.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. /**
  4. * @var string $type_string
  5. */
  6. use App\Enums\DocumentTypes;
  7. use RuntimeException;
  8. $core = Core::getInstance();
  9. $user = $core->getUser();
  10. $user->requireAdmin();
  11. switch($type_string) {
  12. case "invoices":
  13. $title = __("Invoices");
  14. $type = DocumentTypes::INVOICE;
  15. $singular = __("%s invoice");
  16. $plural = __("%s invoices");
  17. break;
  18. case "goods-in":
  19. $title = __("Goods-In");
  20. $type = DocumentTypes::GOODS_IN;
  21. $singular = __("%s goods-in documents");
  22. $plural = __("%s goods-in documents");
  23. break;
  24. case "arus":
  25. $title = __("ARUs");
  26. $type = DocumentTypes::ADVANCE_REPLACEMENT_UNIT;
  27. $singular = __("%s ARU");
  28. $plural = __("%s ARUs");
  29. break;
  30. default:
  31. throw new RuntimeException(__("Invalid type string."));
  32. }
  33. $core->addBreadcrumb("/$type_string", $title);
  34. $type_name = DocumentTypes::enumToText($type);
  35. $nvp = [
  36. "type" => $type,
  37. "dts_deleted" => null
  38. ];
  39. $count = Document::count($nvp);
  40. $pagination = new Pagination($count);
  41. $pagination->setTerms($singular, $plural);
  42. $documents = Document::query($nvp, [
  43. "sort" => "id",
  44. "order" => "desc",
  45. "offset" => $pagination->getOffset(),
  46. "limit" => $pagination->getPageSize()
  47. ]);
  48. $core->addScript("/js/new-document-modal.js");
  49. View::include("header");
  50. View::include("documents", compact("title", "type", "documents", "pagination", "type_name"));
  51. View::include("modals/new_document");
  52. View::include("footer");