src/Form/ShipmentType.php line 603
<?php
namespace App\Form;
use App\Entity\Shipment;
use App\Entity\Country;
use App\Entity\PhoneType;
use App\Entity\ProductType;
use App\Entity\DescribeShipment;
use App\Entity\PickupShipment;
use App\Entity\AddressBook;
use App\Entity\Customer;
use App\Entity\Courier;
use App\Entity\DutyPayer;
use App\Entity\PaymentOptions;
use App\Entity\Services;
use App\Repository\CountryRepository;
use App\Repository\PhoneTypeRepository;
use App\Repository\DescribeShipmentRepository;
use App\Repository\PickupShipmentRepository;
use App\Repository\AddressBookRepository;
use App\Repository\CustomerRepository;
use App\Repository\CourierRepository;
use App\Repository\DutyPayerRepository;
use App\Repository\PaymentOptionsRepository;
use App\Repository\ServicesRepository;
use App\Repository\ProductTypeRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class ShipmentType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('fromAddressBook', EntityType::class, [
// looks for choices from this entity
'class' => AddressBook::class,
'query_builder' => function (AddressBookRepository $er) {
if($this->security->getUser() === null)
{
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
}
else if(!in_array('ROLE_CUSTOMER', $this->security->getUser()->getRoles()))
{
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
}
else
{
return $er->createQueryBuilder('v')
->innerJoin('v.createdBy', 'u')
->Where('u.customer = '.$this->security->getUser()->getCustomer()->getId())
->orderBy('v.name', 'ASC');
}
},
// uses the User.username property as the visible option string
'choice_label'=> function ($addressBook) {
return $addressBook->getName(). ', ' .$addressBook->getCompany() . ', ' . $addressBook->getCountry()->getName().', '.$addressBook->getAddress().', '.$addressBook->getAddressTwo().', '.$addressBook->getPostalCode().', '.$addressBook->getCity();
},
'placeholder' => 'Select a Address Book...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'From Address Book',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('fromName',TextType::class, [
'attr' => ['autofocus' => true,
'class' => 'form-control'
],
'label' => 'Name',
])
->add('fromCompany', TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Company',
])
->add('fromCountry', EntityType::class, [
// looks for choices from this entity
'class' => Country::class,
'query_builder' => function (CountryRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Country...',
'attr' => [
'class' => 'form-control',
'style' => 'width:100%;',
],
'label' => 'Country',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('fromAddress',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Address'
])
->add('fromAddressTwo',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 2',
])
->add('fromAddressThree',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 3',
])
->add('fromPostalCode',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Postal Code',
])
->add('fromCity',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'City',
])
->add('fromState',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'State',
])
->add('fromEmail',EmailType::class, [
'label' => 'Email' ,
'attr' => ['class' => 'form-control'],
'required' => false,
])
// ->add('fromPhoneType', EntityType::class, [
// // looks for choices from this entity
// 'class' => PhoneType::class,
// 'query_builder' => function (PhoneTypeRepository $er) {
// return $er->createQueryBuilder('v')
// ->orderBy('v.name', 'ASC');
// },
// // uses the User.username property as the visible option string
// 'choice_label' => 'name',
// 'attr' => [
// 'class' => 'form-control',
// ],
// 'label' => 'Phone Type',
// // used to render a select box, check boxes or radios
// // 'multiple' => true,
// // 'expanded' => true,
// ])
// ->add('fromPhoneCode',TextType::class, [
// 'label' => 'Code' ,
// 'attr' => ['class' => 'form-control'],
// ])
// ->add('fromPhone',TextType::class, [
// 'attr' => ['class' => 'form-control'],
// 'label' => 'Phone No',
// ])
->add('fromEori', ChoiceType::class, [
'choices' => [
'EORI' => 'EORI',
'GSTN' => 'GSTN',
],
'attr' => ['class' => 'form-control'],
'label' => 'From Type',
// 'expanded' => true,
// 'multiple' => false,
])
->add('fromEroino',TextType::class, [
'required' => false,
'label' => 'Number' ,
'attr' => ['class' => 'form-control'],
])
->add('fromVatTax',TextType::class, [
'required' => false,
'label' => 'VAT/Tax Id' ,
'attr' => ['class' => 'form-control'],
])
->add('toAddressBook', EntityType::class, [
// looks for choices from this entity
'class' => AddressBook::class,
'query_builder' => function (AddressBookRepository $er) {
if($this->security->getUser() === null)
{
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
}
if(!in_array('ROLE_CUSTOMER', $this->security->getUser()->getRoles()))
{
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
}
else
{
return $er->createQueryBuilder('v')
->innerJoin('v.createdBy', 'u')
->Where('u.customer = '.$this->security->getUser()->getCustomer()->getId())
->orderBy('v.name', 'ASC');
}
},
// uses the User.username property as the visible option string
'choice_label'=> function ($addressBook) {
return $addressBook->getName(). ', ' .$addressBook->getCompany() . ', ' . $addressBook->getCountry()->getName().', '.$addressBook->getAddress().', '.$addressBook->getAddressTwo().', '.$addressBook->getPostalCode().', '.$addressBook->getCity();
},
'placeholder' => 'Select a Address Book...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'To Address Book',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('toName',TextType::class, [
'attr' => ['autofocus' => true,
'class' => 'form-control'
],
'label' => 'Name',
])
->add('toCompany',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Company',
])
->add('toCountry', EntityType::class, [
// looks for choices from this entity
'class' => Country::class,
'query_builder' => function (CountryRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Country...',
'attr' => [
'class' => 'form-control',
'style' => 'width:100%;',
],
'label' => 'Country',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('toAddress',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Address',
])
->add('toAddressTwo',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 2',
])
->add('toAddressThree',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 3',
])
->add('toPostalCode',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Postal Code',
])
->add('toCity',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'City',
])
->add('toState',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'State',
])
->add('toEmail',EmailType::class, [
'label' => 'Email' ,
'attr' => ['class' => 'form-control'],
'required' => false,
])
// ->add('toPhoneType', EntityType::class, [
// // looks for choices from this entity
// 'class' => PhoneType::class,
// 'query_builder' => function (PhoneTypeRepository $er) {
// return $er->createQueryBuilder('v')
// ->orderBy('v.name', 'ASC');
// },
// // uses the User.username property as the visible option string
// 'choice_label' => 'name',
// 'attr' => [
// 'class' => 'form-control',
// ],
// 'label' => 'Phone Type',
// // used to render a select box, check boxes or radios
// // 'multiple' => true,
// // 'expanded' => true,
// ])
// ->add('toPhoneCode',TextType::class, [
// 'label' => 'Code' ,
// 'attr' => ['class' => 'form-control'],
// 'label' => 'Phone Code',
// ])
// ->add('toPhone',TextType::class, [
// 'attr' => ['class' => 'form-control'],
// 'label' => 'Phone No',
// ])
->add('toEori', ChoiceType::class, [
'choices' => [
'EORI' => 'EORI',
'GSTN' => 'GSTN',
],
'attr' => ['class' => 'form-control'],
'label' => 'To Type',
// 'expanded' => true,
// 'multiple' => false,
])
->add('toEorino',TextType::class, [
'required' => false,
'label' => 'Number' ,
'attr' => ['class' => 'form-control'],
])
->add('toVatTax',TextType::class, [
'required' => false,
'label' => 'VAT/Tax Id' ,
'attr' => ['class' => 'form-control'],
])
->add('saveFromAb', CheckboxType::class, [
'label' => 'Save this data in the Address Book for future use.',
'required' => false,
])
->add('saveToAb', CheckboxType::class, [
'label' => 'Save this data in the Address Book for future use.',
'required' => false,
])
->add('shipmentDate', DateType::class, [
'attr' => ['class' => 'form-control',
'style' => 'line-height:20px;'],
'widget' => 'single_text',
'empty_data' => null,
'label' => 'Shipment Date',
])
->add('mawbNo', TextType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Mawb No',
])
->add('hawbNo', TextType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Hawb No',
'required' => false,
])
->add('manualHawb', CheckboxType::class, [
'label' => 'Manual Hawb',
'required' => false,
])
->add('courier', EntityType::class, [
// looks for choices from this entity
'class' => Courier::class,
'query_builder' => function (CourierRepository $er) {
if($this->security->getUser() === null)
{
return $er->createQueryBuilder('v')
->where('v.userCompany = 1')
->orderBy('v.name', 'ASC');
}
else
{
return $er->createQueryBuilder('v')
->where('v.userCompany = '.$this->security->getUser()->getUserCompany()->getId())
->orderBy('v.name', 'ASC');
}
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Courier...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Services Through',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('courierHawbno', TextType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Courier Hawb No',
'required' => false,
])
->add('shipmentType', ChoiceType::class, [
'choices' => [
'Export' => '1',
'Import' => '2',
],
'constraints' => [
new Choice([
'choices' => ['1', '2'],
'message' => 'Please select a valid option.',
]),
],
'expanded' => true,
'multiple' => false,
'label' => false,
])
->add('productType', EntityType::class, [
'class' => ProductType::class,
'query_builder' => function (ProductTypeRepository $er) {
return $er->createQueryBuilder('v')
->where('v.type = 1')
->orderBy('v.name', 'ASC');
},
'choice_label' => function ($ProductType) {
return $ProductType->getName();
},
'expanded' => true,
'multiple' => false,
'label' => false,
])
->add('describeShipment', EntityType::class, [
// looks for choices from this entity
'class' => DescribeShipment::class,
'query_builder' => function (DescribeShipmentRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Describe Shipment...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'What is the purpose of your shipment?',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('expedite', CheckboxType::class, [
'label' => 'Expedite / Cash Rate Applicable',
'required' => false,
])
->add('itemSummary', TextareaType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Summarize the contents of your shipment(in details)',
'required' => false,
])
->add('customsInvoice', ChoiceType::class, [
'choices' => [
'Create Invoice' => '1',
'Use My Own Invoice' => '0',
],
'required' => false,
'expanded' => true,
'multiple' => false,
'label' => false,
])
->add('invoiceNo',TextType::class, [
'attr' => ['class' => 'form-control'],
'required' => false,
])
->add('additionalInvoiceInfo', TextareaType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Additional Invoice Information (Remarks)',
'required' => false,
])
->add('imagePath', FileType::class, [
'label' => 'Invoice Documents',
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => false,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'image/*',
'application/pdf',
'application/x-pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
'mimeTypesMessage' => 'Please upload a PDF / Image / Word / Excel File',
])
],
])
->add('customer', EntityType::class, [
// looks for choices from this entity
'class' => Customer::class,
'query_builder' => function (CustomerRepository $er) {
if($this->security->getUser() === null)
{
return $er->createQueryBuilder('v')
->where('v.userCompany = 1')
->orderBy('v.name', 'ASC');
}
else if(!in_array('ROLE_CUSTOMER', $this->security->getUser()->getRoles()))
{
return $er->createQueryBuilder('v')
->where('v.userCompany = '.$this->security->getUser()->getUserCompany()->getId())
->orderBy('v.name', 'ASC');
}
else
{
return $er->createQueryBuilder('v')
->Where('v.id = '.$this->security->getUser()->getCustomer()->getId())
->orderBy('v.name', 'ASC');
}
},
// uses the User.username property as the visible option string
'choice_label'=> function ($customer) {
return $customer->getAccountNo(). ' - ' .$customer->getName() ;
},
'placeholder' => 'Select a Customer...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Who will pay the transport charge?',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('dutyPayer', EntityType::class, [
// looks for choices from this entity
'class' => DutyPayer::class,
'query_builder' => function (DutyPayerRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Payer...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Who will pay Duty & Tax?',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('dutyAccountno',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Third Party Account No',
'required' => false,
])
->add('paymentOptions', EntityType::class, [
// looks for choices from this entity
'class' => PaymentOptions::class,
'query_builder' => function (PaymentOptionsRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Options...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Payment Options',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('servicese', EntityType::class, [
// looks for choices from this entity
'class' => Services::class,
'query_builder' => function (ServicesRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Services...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Services',
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('schedulePickup', ChoiceType::class, [
'choices' => [
'Yes - Schedule Pickup' => '1',
'NO' => '0',
],
'expanded' => true,
'multiple' => false,
'label' => false,
])
->add('pickupDate', DateTimeType::class, [
'attr' => ['class' => 'form-control',
'style' => 'line-height:20px;'],
'widget' => 'single_text',
'label' => 'Pickup Date Time',
'required' => false,
])
->add('pickupShipment', EntityType::class, [
// looks for choices from this entity
'class' => PickupShipment::class,
'query_builder' => function (PickupShipmentRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Pickup Shipment...',
'attr' => [
'class' => 'form-control select-tags',
'style' => 'width:100%;',
],
'label' => 'Where should the courier pickup the shipment?',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('pickupWeight', NumberType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Total Pickup Weight (KG)',
'required' => false,
])
->add('instructions', TextareaType::class, [
'attr' => ['class' => 'form-control',
],
'label' => 'Instructions for the Courier',
'required' => false,
])
->add('pickupName',TextType::class, [
'attr' => ['autofocus' => true,
'class' => 'form-control'
],
'label' => 'Name',
'required' => false,
])
->add('pickupCompany',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Company',
'required' => false,
])
->add('pickupCountry', EntityType::class, [
// looks for choices from this entity
'class' => Country::class,
'query_builder' => function (CountryRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Select a Country...',
'attr' => [
'class' => 'form-control',
'style' => 'width:100%;',
],
'label' => 'Country',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('pickupAddress',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Address',
'required' => false,
])
->add('pickupAddressTwo',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 2',
])
->add('pickupAddressThree',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'Address 3',
])
->add('pickupPostalCode',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Postal Code',
'required' => false,
])
->add('pickupCity',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'City',
'required' => false,
])
->add('pickupState',TextType::class, [
'required' => false,
'attr' => ['class' => 'form-control'],
'label' => 'State',
])
->add('pickupEmail',EmailType::class, [
'label' => 'Email' ,
'attr' => ['class' => 'form-control'],
'required' => false,
])
->add('pickupPhoneType', EntityType::class, [
// looks for choices from this entity
'class' => PhoneType::class,
'query_builder' => function (PhoneTypeRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.name', 'ASC');
},
// uses the User.username property as the visible option string
'choice_label' => 'name',
'placeholder' => 'Phone Type...',
'attr' => [
'class' => 'form-control',
],
'label' => 'Phone Type',
'required' => false,
// used to render a select box, check boxes or radios
// 'multiple' => true,
// 'expanded' => true,
])
->add('pickupPhoneCode',TextType::class, [
'label' => 'Code' ,
'attr' => ['class' => 'form-control'],
'label' => 'Phone Code',
'required' => false,
])
->add('pickupPhone',TextType::class, [
'attr' => ['class' => 'form-control'],
'label' => 'Phone No',
'required' => false,
])
->add('shipmentReferences', CollectionType::class, [
'entry_type' => ShipmentReferenceType::class,
'entry_options' => ['label' => false],
'by_reference'=>false,
'allow_add' => true,
'allow_delete'=>true,
'label' => false,
])
->add('shipmentItems', CollectionType::class, [
'entry_type' => ShipmentItemsType::class,
'entry_options' => ['label' => false],
'by_reference'=>false,
'allow_add' => true,
'allow_delete'=>true,
'label' => false,
])
->add('shipmentPackagings', CollectionType::class, [
'entry_type' => ShipmentPackagingType::class,
'entry_options' => ['label' => false],
'by_reference'=>false,
'allow_add' => true,
'allow_delete'=>true,
'label' => false,
])
->add('fromPhoneDetails', CollectionType::class, [
'entry_type' => FromPhoneDetailsType::class,
'entry_options' => ['label' => false],
'by_reference'=>false,
'allow_add' => true,
'allow_delete'=>true,
'label' => false,
])
->add('toPhoneDetails', CollectionType::class, [
'entry_type' => ToPhoneDetailsType::class,
'entry_options' => ['label' => false],
'by_reference'=>false,
'allow_add' => true,
'allow_delete'=>true,
'label' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Shipment::class,
]);
}
}