DocumentTypes.php 907 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Enums;
  3. use RuntimeException;
  4. class DocumentTypes extends AbstractEnum {
  5. public const SALES_ORDER = 0;
  6. public const DELIVERY_NOTE = 1;
  7. public const GOODS_IN = 2;
  8. public const ADVANCE_REPLACEMENT_UNIT = 3;
  9. public const CREDIT_NOTE = 4;
  10. public static function options(): array {
  11. return [
  12. self::SALES_ORDER => __("Sales Order"),
  13. self::DELIVERY_NOTE => __("Delivery Note"),
  14. self::GOODS_IN => __("Goods-In"),
  15. self::ADVANCE_REPLACEMENT_UNIT => __("ARU"),
  16. self::CREDIT_NOTE => __("Credit Note"),
  17. ];
  18. }
  19. public static function fromRouteName(string $name): string {
  20. $map = [
  21. "sales-orders" => self::SALES_ORDER,
  22. "delivery-notes" => self::DELIVERY_NOTE,
  23. "goods-in" => self::GOODS_IN,
  24. "arus" => self::ADVANCE_REPLACEMENT_UNIT,
  25. ];
  26. if(!isset($map[$name])) {
  27. throw new RuntimeException(__("Invalid document type."));
  28. }
  29. return $map[$name];
  30. }
  31. }