<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\ClaimPdf42\Form\Type\Admin;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class ClaimHistoryType.
*/
class ClaimHistoryType extends AbstractType
{
/** @var EccubeConfig */
private $eccubeConfig;
/** @var EntityManagerInterface */
private $entityManager;
/**
* ClaimPdfType constructor.
*
* @param EccubeConfig $eccubeConfig
* @param EntityManagerInterface $entityManager
*/
public function __construct(EccubeConfig $eccubeConfig, EntityManagerInterface $entityManager)
{
$this->eccubeConfig = $eccubeConfig;
$this->entityManager = $entityManager;
}
/**
* Build config type form.
*
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
dump('ClaimHistoryType');
$config = $this->eccubeConfig;
$builder
->add('issue_date', DateType::class, [
'widget' => 'single_text',
'input' => 'datetime',
'required' => true,
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
'data' => new \DateTime(),
'constraints' => [
new Assert\NotBlank(),
new Assert\Range([
'min'=> '0003-01-01',
'minMessage' => 'form_error.out_of_range',
]),
],
'attr' => [
'data-target' => '#'.$this->getBlockPrefix().'_issue_date',
'data-toggle' => 'datetimepicker',
],
])
->add('orderdatetime_st', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['readonly' => 'readonly'],
])
->add('orderdatetime_en', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['readonly' => 'readonly'],
])
->add('orderids', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['readonly' => 'readonly'],
'constraints' => [
new Assert\NotBlank(),
],
])
->add('ids', TextType::class, [
'required' => false,
'attr' => ['readonly' => 'readonly'],
'constraints' => [
new Assert\NotBlank(),
],
])
->add('outputkbn', ChoiceType::class, [
'choices' => [
'admin.order.delivery_note_outputkbn_nouhin' => $config['eccube_claim_pdf_output_kbn_nouhin'],
'admin.order.delivery_note_outputkbn_nouhin_shipping' => $config['eccube_claim_pdf_output_kbn_nouhin_shipping'],
'admin.order.delivery_note_outputkbn_nouhin_otodoke' => $config['eccube_claim_pdf_output_kbn_nouhin_otodoke'],
'admin.order.delivery_note_outputkbn_seikyu' => $config['eccube_claim_pdf_output_kbn_seikyu'],
'admin.order.delivery_note_outputkbn_seikyu_matome' => $config['eccube_claim_pdf_output_kbn_seikyu_matome'],
'admin.order.delivery_note_outputkbn_seikyu_matome_company' => $config['eccube_claim_pdf_output_kbn_seikyu_matome_company'],
'admin.order.delivery_note_outputkbn_ryosyu' => $config['eccube_claim_pdf_output_kbn_ryosyu'],
],
'expanded' => true,
'multiple' => false,
'required' => false,
'mapped' => false,
'placeholder' => false,
])
->add('title', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('download_kind', ChoiceType::class, [
'choices' => [
'admin.order.delivery_note_output_format__file' => 1,
'admin.order.delivery_note_output_format__browser' => 2,
],
'expanded' => false,
'multiple' => false,
'required' => false,
'mapped' => false,
'placeholder' => false,
])
// メッセージ
->add('message1', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message2', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message3', TextType::class, [
'required' => false,
'mapped' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 振込先情報要素
->add('hurikomi_bank', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('hurikomi_bank_siten', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('hurikomi_bank_kouza', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('hurikomi_free_area', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 納品書[受注番号別]関連隠し要素
->add('title_nouhin', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('message1_nouhin', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message2_nouhin', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message3_nouhin', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 納品書[出荷番号別]関連隠し要素
->add('title_nouhin_shipping', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('message1_nouhin_shipping', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message2_nouhin_shipping', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message3_nouhin_shipping', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 納品書(お届け先)関連隠し要素
->add('title_otodoke', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('message1_otodoke', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message2_otodoke', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message3_otodoke', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 請求書関連隠し要素
->add('title_seikyu', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('message1_seikyu', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message2_seikyu', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
->add('message3_seikyu', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_claim_pdf_message_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_claim_pdf_message_len']]),
],
'trim' => false,
])
// 領収書・宛名出力形式
->add('ryosyu_atena', ChoiceType::class, [
'choices' => [
'admin.order.delivery_note_ryosyu_format__history_customer_name' => $config['eccube_claim_pdf_output_atena_kbn_customer_name'],
'admin.order.delivery_note_ryosyu_format__company_name' => $config['eccube_claim_pdf_output_atena_kbn_company_name'],
'admin.order.delivery_note_ryosyu_format__history_customer_company_name' => $config['eccube_claim_pdf_output_atena_kbn_customer_company_name'],
],
'expanded' => true,
'multiple' => false,
'required' => true,
'mapped' => false,
'placeholder' => false,
])
// 宛名 会社名@hanari
->add('ryosyu_add_company', TextType::class, [
'required' => false,
'mapped' => false,
])
// 宛名
->add('ryosyu_add_name', TextType::class, [
'required' => false,
'mapped' => false,
])
// 備考
->add('note1', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('note2', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('note3', TextType::class, [
'required' => false,
'attr' => ['maxlength' => $config['eccube_stext_len']],
'constraints' => [
new Assert\Length(['max' => $config['eccube_stext_len']]),
],
])
->add('default', CheckboxType::class, [
'label' => 'admin.order.delivery_note_save_input',
'required' => false,
])
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
$data = $form->getData();
if (!isset($data['ids']) || !is_string($data['ids'])) {
return;
}
$ids = explode(',', $data['ids']);
$qb = $this->entityManager->createQueryBuilder();
$qb->select('count(s.id)')
->from('Eccube\\Entity\\Shipping', 's')
->where($qb->expr()->in('s.id', ':ids'))
->setParameter('ids', $ids);
$actual = $qb->getQuery()->getSingleScalarResult();
$expected = count($ids);
if ($actual != $expected) {
$form['ids']->addError(
new FormError(trans('admin.order.delivery_note_parameter_error'))
);
}
});
}
/**
* Get name method (form factory name).
*
* @return string
*/
public function getName()
{
return 'admin_claim_pdf';
}
}