|
|
@@ -2,26 +2,175 @@ |
|
|
|
|
|
|
|
namespace Lc\CaracoleBundle\Definition\Field\Reduction; |
|
|
|
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; |
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; |
|
|
|
use Lc\CaracoleBundle\Definition\Field\AbstractFieldDefinition; |
|
|
|
use Lc\CaracoleBundle\Repository\Section\SectionStore; |
|
|
|
use Lc\CaracoleBundle\Context\MerchantContextTrait; |
|
|
|
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition; |
|
|
|
use Lc\CaracoleBundle\Field\AssociationField; |
|
|
|
use Lc\CaracoleBundle\Model\Config\TaxRateModel; |
|
|
|
use Lc\CaracoleBundle\Model\Config\UnitModel; |
|
|
|
use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore; |
|
|
|
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; |
|
|
|
use Lc\CaracoleBundle\Repository\User\GroupUserStore; |
|
|
|
use Lc\CaracoleBundle\Repository\User\UserStore; |
|
|
|
use Lc\SovBundle\Field\BooleanField; |
|
|
|
use Lc\SovBundle\Translation\TranslatorAdmin; |
|
|
|
|
|
|
|
class ReductionCatalogFieldDefinition extends AbstractFieldDefinition |
|
|
|
{ |
|
|
|
protected SectionStore $sectionStore; |
|
|
|
use MerchantContextTrait; |
|
|
|
|
|
|
|
public function __construct(TranslatorAdmin $translatorAdmin, SectionStore $sectionStore) |
|
|
|
protected GroupUserStore $groupUserStore; |
|
|
|
protected UserStore $userStore; |
|
|
|
protected ProductFamilyStore $productFamilyStore; |
|
|
|
protected ProductCategoryStore $productCategoryStore; |
|
|
|
|
|
|
|
public function __construct( |
|
|
|
TranslatorAdmin $translatorAdmin, |
|
|
|
GroupUserStore $groupUserStore, |
|
|
|
UserStore $userStore, |
|
|
|
ProductFamilyStore $productFamilyStore, |
|
|
|
ProductCategoryStore $productCategoryStore |
|
|
|
) |
|
|
|
{ |
|
|
|
parent::__construct($translatorAdmin); |
|
|
|
$this->sectionStore = $sectionStore; |
|
|
|
$this->groupUserStore = $groupUserStore; |
|
|
|
$this->userStore = $userStore; |
|
|
|
$this->productFamilyStore = $productFamilyStore; |
|
|
|
$this->productCategoryStore = $productCategoryStore; |
|
|
|
} |
|
|
|
|
|
|
|
public function configureIndex(): array |
|
|
|
{ |
|
|
|
|
|
|
|
return [ |
|
|
|
'id', |
|
|
|
'title', |
|
|
|
'value', |
|
|
|
'status', |
|
|
|
'isDisplayed' |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function configureForm(): array |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'title', |
|
|
|
'behaviorTaxRate', |
|
|
|
'unit', |
|
|
|
'value', |
|
|
|
'permanent', |
|
|
|
'dateStart', |
|
|
|
'dateEnd', |
|
|
|
'usersActive', |
|
|
|
'users', |
|
|
|
'groupUsersActive', |
|
|
|
'groupUsers', |
|
|
|
'productCategoriesActive', |
|
|
|
'productCategories', |
|
|
|
'productFamiliesActive', |
|
|
|
'productFamilies', |
|
|
|
'status', |
|
|
|
'isDisplayed' |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function configureFields(): array |
|
|
|
{ |
|
|
|
$groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->get(); |
|
|
|
$usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers(); |
|
|
|
$productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get(); |
|
|
|
$productCategoryArray = $this->productCategoryStore->setMerchant($this->merchant)->get(); |
|
|
|
|
|
|
|
return [ |
|
|
|
'title' => TextField::new('title')->setSortable(true) |
|
|
|
// @TODO : à faire |
|
|
|
'title' => TextField::new('title')->setSortable(true), |
|
|
|
'behaviorTaxRate' => ChoiceField::new('behaviorTaxRate') |
|
|
|
->setFormTypeOption('required', true) |
|
|
|
->setFormTypeOption('empty_data', TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED) |
|
|
|
->setChoices( |
|
|
|
$this->translatorAdmin->transChoices( |
|
|
|
TaxRateModel::getBehaviorTaxRateChoices(), |
|
|
|
'TaxRate', |
|
|
|
'behaviorTaxRate' |
|
|
|
) |
|
|
|
), |
|
|
|
'unit' => ChoiceField::new('unit') |
|
|
|
->setFormTypeOption('expanded', true) |
|
|
|
->setFormTypeOption('required', true) |
|
|
|
->setChoices( |
|
|
|
$this->translatorAdmin->transChoices( |
|
|
|
UnitModel::getUnitAmountChoices(), |
|
|
|
'Unit', |
|
|
|
'unit' |
|
|
|
) |
|
|
|
), |
|
|
|
'value' => NumberField::new('value')->setTemplatePath('@LcCaracole/admin/reduction/field/amount.html.twig'), |
|
|
|
'permanent' => BooleanField::new('permanent'), |
|
|
|
'dateStart' => DateTimeField::new('dateStart'), |
|
|
|
'dateEnd' => DateTimeField::new('dateEnd'), |
|
|
|
'isDisplayed'=> BooleanField::new('isDisplayed'), |
|
|
|
'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false), |
|
|
|
'groupUsers' => AssociationField::new('groupUsers') |
|
|
|
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') |
|
|
|
->setFormTypeOption('choices', $groupUserArray), |
|
|
|
|
|
|
|
'usersActive' => BooleanField::new('usersActive')->setFormTypeOption('mapped', false), |
|
|
|
|
|
|
|
'users' => AssociationField::new('users') |
|
|
|
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') |
|
|
|
->setFormTypeOption('choices', $usersArray) |
|
|
|
->setFormTypeOption( |
|
|
|
'choice_attr', |
|
|
|
function ($choice, $key, $value) { |
|
|
|
$data = array(); |
|
|
|
foreach ($choice->getGroupUsers() as $groupUser) { |
|
|
|
$data[] = '_' . $groupUser->getId() . '_'; |
|
|
|
} |
|
|
|
|
|
|
|
return ['data-group-users' => json_encode($data)]; |
|
|
|
}, |
|
|
|
), |
|
|
|
|
|
|
|
|
|
|
|
'productCategoriesActive' => BooleanField::new('productCategoriesActive')->setFormTypeOption('mapped', false), |
|
|
|
'productCategories' => AssociationField::new('productCategories') |
|
|
|
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') |
|
|
|
->setFormTypeOption('choice_label', |
|
|
|
// @TODO : attention, code dupliqué de ProductCategoriesFilter |
|
|
|
function ($category) { |
|
|
|
$isOffline = ''; |
|
|
|
if ($category->getStatus() != 1) { |
|
|
|
$isOffline = " [Hors ligne]"; |
|
|
|
} |
|
|
|
$section = ' [' . $category->getSection()->getTitle() . ']';; |
|
|
|
return $category . $section . $isOffline; |
|
|
|
}) |
|
|
|
->setFormTypeOption('choices', $productCategoryArray), |
|
|
|
|
|
|
|
|
|
|
|
'productFamiliesActive' => BooleanField::new('productFamiliesActive')->setFormTypeOption('mapped', false), |
|
|
|
'productFamilies' => AssociationField::new('productFamilies') |
|
|
|
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') |
|
|
|
->setFormTypeOption('choices', $productFamilyArray) |
|
|
|
->setFormTypeOption( |
|
|
|
'choice_attr', |
|
|
|
function ($choice, $key, $value) { |
|
|
|
$data = array(); |
|
|
|
foreach ($choice->getProductCategories() as $category) { |
|
|
|
$data[] = '_' . $category->getId() . '_'; |
|
|
|
} |
|
|
|
return [ |
|
|
|
'data-product-categories' => json_encode($data), |
|
|
|
'data-supplier' => $choice->getSupplier()->getId() |
|
|
|
]; |
|
|
|
} |
|
|
|
), |
|
|
|
'productFamily' => AssociationField::new('productFamily') |
|
|
|
->setFormTypeOption('choices', $productFamilyArray) |
|
|
|
]; |
|
|
|
} |
|
|
|
} |