src/Nolimit/Inventory/Admin/InventoryItemAdmin.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Nolimit\Inventory\Admin;
  4. use Sonata\AdminBundle\Admin\AbstractAdmin;
  5. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  6. use Sonata\AdminBundle\Datagrid\ListMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Sonata\AdminBundle\Show\ShowMapper;
  9. use Sonata\Form\Type\DatePickerType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Translation\Translator;
  13. use Symfony\Component\Validator\Constraints\DateTime;
  14. final class InventoryItemAdmin extends AbstractAdmin
  15. {
  16.     protected $translationDomain 'messages';
  17.     /**
  18.      * @var Translator
  19.      */
  20.     public Translator $translate;
  21.     /**
  22.      * InventoryItemAdmin constructor.
  23.      */
  24.     public function __construct(?string $code null, ?string $class null, ?string $baseControllerName null)
  25.     {
  26.         parent::__construct($code$class$baseControllerName);
  27.         $this->translate = new Translator($this->getIdParameter('locale'));
  28.     }
  29.     protected function configureDatagridFilters(DatagridMapper $filter): void
  30.     {
  31.         $filter
  32.             ->add('productName')
  33.             ->add('quantity')
  34.             ->add('price')
  35.             ->add('dateOfPurchase')
  36.             ->add('company')
  37.             ->add('invoice')
  38.             ->add('inventoryNr')
  39.             ->add('createdAt')
  40.             ->add('updatedAt')
  41.             ;
  42.     }
  43.     protected function configureListFields(ListMapper $list): void
  44.     {
  45.         $list
  46.             ->add('productName')
  47.             ->add('quantity')
  48.             ->add('price')
  49.             ->add('company')
  50.             ->add('invoice')
  51.             ->add('dateOfPurchase','date' ,['format' => 'Y-m-d','sort_field' => ['dateOfPurchase''Desc']])
  52.             ->add('amortizationEndDate','date' ,['format' => 'Y-m-d','sort_field' => ['dateOfPurchase''Desc']])
  53.             ->add('inventoryNr')
  54.             ->add(ListMapper::NAME_ACTIONSnull, [
  55.                 'actions' => [
  56.                     'show' => [],
  57.                     'edit' => [],
  58.                     'delete' => [],
  59.                 ],
  60.             ]);
  61.     }
  62.     protected function configureFormFields(FormMapper $form): void
  63.     {
  64.         $form
  65.             ->add('productName')
  66.             ->add('quantity')
  67.             ->add('price')
  68.             ->add('dateOfPurchase'DateType::class,['required' => true'widget' => 'single_text''format' => 'Y-m-d''html5' => false])
  69.             ->add('amortizationEndDate'DateType::class, ['label'=> $this->translate->trans('Amortization End Date'),'required' => true'widget' => 'single_text','format' => 'Y-m-d''html5' => false])
  70.             ->add('company'TextType::class,['label'=> $this->translate->trans('Supplier'),'required' => true])
  71.             ->add('invoice')
  72.             ->add('inventoryNr')
  73.             ;
  74.     }
  75.     protected function configureShowFields(ShowMapper $show): void
  76.     {
  77.         $show
  78.             ->add('productName')
  79.             ->add('quantity')
  80.             ->add('price')
  81.             ->add('dateOfPurchase')
  82.             ->add('company')
  83.             ->add('invoice')
  84.             ->add('inventoryNr')
  85.             ->add('createdAt')
  86.             ->add('updatedAt')
  87.             ;
  88.     }
  89. }