<?php
namespace App\Form\GuardianRegister;
use App\Entity\GuardianContract;
use App\Entity\GuardianRegister\GuardianRegister;
use App\Entity\GuardianRegister\GuardianRegisterChild;
use App\Entity\GuardianRegister\GuardianRegisterChildPreference;
use App\Entity\Lesson;
use App\Repository\GuardianContractRepository;
use App\Service\PriceIncreaseService;
use App\Utils\HelperUtils;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\ChoiceList;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GuardianRegisterType extends AbstractType
{
private PriceIncreaseService $priceIncreaseService;
public function __construct(PriceIncreaseService $priceIncreaseService)
{
$this->priceIncreaseService = $priceIncreaseService;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var GuardianRegister $guardianRegister */
$guardianRegister = $options['data'];
$phone = $guardianRegister->getPhone();
$countryCode = 'LT';
$countryChoices = [];
$countryChoicesAttr = [];
$countryData = HelperUtils::countryData(1);
foreach ($countryData as $countryDatum)
{
$countryChoices["{$countryDatum['country']} {$countryDatum['dialCode']}"] = "{$countryDatum['code']}";
$countryChoicesAttr["{$countryDatum['country']} {$countryDatum['dialCode']}"] = [
'data-dialcode' => "{$countryDatum['dialCode']}",
'data-digits' => "{$countryDatum['digits']}",
'data-size' => "{$countryDatum['size']}",
];
if(strpos($phone, $countryDatum['dialCode']) !== false)
{
$countryCode = $countryDatum['code'];
}
}
$builder
->add('isGuardian', null, ['label' => 'forms.labels.isGuardian'])
->add('sign', null, ['label' => 'guardian_register.sign'])
->add('currentGuardianFoundBy', ChoiceType::class,
[
'choices' => [
'EMAIL' => 'EMAIL',
'TEL' => 'TEL',
'EMAIL&TEL' => 'EMAIL&TEL',
],
'label' => 'forms.labels.currentGuardianFoundBy',
'disabled' => true,
'required' => false,
]
)
// ->add('change', SubmitType::class, ['label' => 'forms.labels.change'])
->add('comment', null, ['label' => 'forms.labels.comment'])
->add('recallAt', null, [
'label' => 'forms.labels.recall',
'widget' => 'single_text',
'html5' => true,
])
->add('email', EmailType::class, ['label' => 'forms.labels.email', 'required' => true])
->add('name', null, ['label' => 'forms.labels.firstname', 'required' => true])
->add('lastname', null, ['label' => 'forms.labels.lastname', 'required' => true])
->add('country', ChoiceType::class, [
'label' => 'forms.labels.country',
'required' => true,
'choices' => $countryChoices,
'choice_attr' => $countryChoicesAttr,
'mapped' => false,
'attr' => ['data-country' => $countryCode]
])
->add('phone', null, ['label' => 'forms.labels.phone', 'required' => true])
->add('guardianName', null, ['label' => 'forms.labels.guardianName'])
->add('guardianLastname', null, ['label' => 'forms.labels.guardianLastname'])
->add('guardianPhone', null, ['label' => 'forms.labels.guardianPhone'])
->add('guardianEmail', null, ['label' => 'forms.labels.guardianEmail'])
->add('status',
ChoiceType::class,
[
'choices' => [
GuardianRegister::STATUS_NEW['text'] => GuardianRegister::STATUS_NEW['value'],
GuardianRegister::STATUS_IGNORED['text'] => GuardianRegister::STATUS_IGNORED['value'],
GuardianRegister::STATUS_SENT['text'] => GuardianRegister::STATUS_SENT['value'],
GuardianRegister::STATUS_SLEEP['text'] => GuardianRegister::STATUS_SLEEP['value'],
GuardianRegister::STATUS_DECLINED['text'] => GuardianRegister::STATUS_DECLINED['value'],
GuardianRegister::STATUS_CONFIRMED['text'] => GuardianRegister::STATUS_CONFIRMED['value'],
GuardianRegister::STATUS_LOST['text'] => GuardianRegister::STATUS_LOST['value'],
GuardianRegister::STATUS_UNTARGETED['text'] => GuardianRegister::STATUS_UNTARGETED['value'],
//extra
GuardianRegister::STATUS_WAITING['text'] => GuardianRegister::STATUS_WAITING['value'],
GuardianRegister::STATUS_LOST_48['text'] => GuardianRegister::STATUS_LOST_48['value'],
GuardianRegister::STATUS_PAID_FIRST['text'] => GuardianRegister::STATUS_PAID_FIRST['value'],
GuardianRegister::STATUS_NOT_PAID['text'] => GuardianRegister::STATUS_NOT_PAID['value'],
GuardianRegister::STATUS_NOT_PAID_48['text'] => GuardianRegister::STATUS_NOT_PAID_48['value']
],
'label' => 'forms.labels.status'
])
// ->add('priceChange', null, ['label' => 'guardian_register.priceChange'])
->add('guardianPriceDiscount', null, ['label' => 'guardian_register.guardianPriceDiscount', 'required' => false])
->add('referralCode', null, ['label' => 'Kodas', 'required' => false])
->add('flagTrial', null, ['label' => 'forms.labels.flagTrial'])
->add('contractToken', null, ['disabled' => true, 'required' => false])
->add('guardianContract', EntityType::class, [
'class' => GuardianContract::class,
'label' => 'tutorhiring.teacherHiringContract',
'choice_label' => function(GuardianContract $contract) {
return $contract->getCreatedAt()->format('Y/m/d') . " " .$contract->getFilePath();
},
'query_builder' => function (GuardianContractRepository $er) {
return $er->createQueryBuilder('u')
->andWhere('u.comment IS NULL OR u.comment NOT LIKE :excludeCommentLikePattern')
->setParameter('excludeCommentLikePattern', $this->priceIncreaseService->getDuplicateMarkerLikePattern())
->orderBy('u.flagTrial', 'ASC')
->addOrderBy('u.createdAt', 'DESC');
},
'choice_attr' => ChoiceList::attr($this, function (?GuardianContract $guardianContract): array {
return $guardianContract ? ['data-id' => $guardianContract->getId(), 'data-trial' => $guardianContract->getFlagTrial() ? 1 : 0] : [];
}),
'required' => true
])
->add('salesPerson', null, ['label' => 'forms.labels.salesPerson', 'disabled' => true])
->add('guardianRegisterChildren', CollectionType::class, [
'entry_type' => GuardianRegisterChildType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_data' => (new GuardianRegisterChild())->setName('Vardas1')->setClass(8),
'attr' => [
'inline-add' => true,
'btn-delete-label' => 'Naikinti vaiką',
'btn-add-label' => 'Pridėti vaiką',
'class' => 'add-new',
'data-widget-tags' => 'flex-add-new with-calendar',
'data-widget-delete' => '<button class="btn btn-danger" type="button" onclick="this.parentNode.parentNode.remove()">Naikinti vaiką</button>'
],
'row_attr' => [
'class' => 'card card-body',
],
'label' => 'guardian_register.guardianRegisterChildren'
])
->add('flagManualAssignment', null, ['label' => 'Priskyrimas rankiniu būdu'])
->add('flagEarlyPayment', null, ['label' => 'Įjungti mokėjimą į priekį']);
$paymentDays = [];
for($i = 1; $i <= 28; $i++)
{
$paymentDays[$i] = $i;
}
$builder
->add('earlyPaymentDay', ChoiceType::class, [
'label' => 'Mokėjimo data',
'choices' => $paymentDays,
'required' => false
// 'row_attr' => ['style' => 'display: none;'],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => GuardianRegister::class,
]);
}
}