public function index(Application $app, Request $request, $id = null)
{
$TargetTaxRule = null;
if ($id == null) {
$TargetTaxRule = $app['eccube.repository.tax_rule']->newTaxRule();
} else {
$TargetTaxRule = $app['eccube.repository.tax_rule']->find($id);
if (is_null($TargetTaxRule)) {
throw new NotFoundHttpException();
}
}
/** @var $BaseInfo \Eccube\Entity\BaseInfo */
$BaseInfo = $app['eccube.repository.base_info']->get();
$builder = $app['form.factory']->createBuilder('tax_rule', $TargetTaxRule);
$builder->get('option_product_tax_rule')->setData($BaseInfo->getOptionProductTaxRule());
if ($TargetTaxRule->isDefaultTaxRule()) {
// 基本税率設定は適用日時の変更は行わない
$builder = $builder->remove('apply_date');
}
$event = new EventArgs(array('builder' => $builder, 'BaseInfo' => $BaseInfo, 'TargetTaxRule' => $TargetTaxRule), $request);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_TAX_RULE_INDEX_INITIALIZE, $event);
/* @var $form \Symfony\Component\Form\FormInterface */
$form = $builder->getForm();
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($this->isValid($app['orm.em'], $form)) {
$app['orm.em']->persist($TargetTaxRule);
$app['orm.em']->flush();
$event = new EventArgs(array('form' => $form, 'BaseInfo' => $BaseInfo, 'TargetTaxRule' => $TargetTaxRule), $request);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_TAX_RULE_INDEX_COMPLETE, $event);
$app->addSuccess('admin.shop.tax.save.complete', 'admin');
return $app->redirect($app->url('admin_setting_shop_tax'));
}
}
// 共通税率一覧
$TaxRules = $app['eccube.repository.tax_rule']->getList();
return $app->render('Setting/Shop/tax_rule.twig', array('TargetTaxRule' => $TargetTaxRule, 'TaxRules' => $TaxRules, 'form' => $form->createView()));
}