<?php
namespace App\Form;
use App\Entity\Payment;
use App\Entity\PaymentMethod;
use App\Enum\PaymentStatus;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PaymentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('amount', NumberType::class, [
'label' => 'amount',
'scale' => 4,
'html5' => false,
'attr' => [
'placeholder' => 'enterAmount',
'class' => 'mask-money'
],
])
->add('paymentStatus', ChoiceType::class, [
'choices' => PaymentStatus::cases(),
'choice_label' => fn(PaymentStatus $status) => $status->getTranslationKey(),
'required' => true,
'placeholder' => 'selectPaymentStatus',
'mapped' => false,
])
->add('paymentDate', DateType::class, [
'label' => 'paymentDate',
'widget' => 'single_text',
'html5' => true,
'data' => new \DateTime(),
])
->add('dueDate', DateType::class, [
'label' => 'dueDate',
'widget' => 'single_text',
'html5' => true,
'data' => new \DateTime(),
])
->add('paymentMethod', EntityType::class, [
'placeholder' => 'selectPaymentMethod',
'class' => PaymentMethod::class,
'label' => 'paymentMethod',
'choice_label' => fn(PaymentMethod $method) => $method->getName(),
])
->add('description', TextareaType::class, [
'label' => 'description',
])
->add('voucherCode', TextType::class, [
'label' => 'Hediye Çeki Kodu',
'mapped' => false,
'required' => false,
'attr' => [
'placeholder' => 'Çek Kodunu Giriniz',
'style' => 'display: none;', // Initially hidden
],
'label_attr' => [
'style' => 'display: none;', // Initially hidden
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Payment::class,
]);
}
}