From 800e5a22091df13930efdf74d27031e763daa7e7 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 12 Sep 2023 02:50:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=9C=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/OrderPdf.php | 29 +++++++++++++ Form/Type/OrderPdfType.php | 8 ++++ Repository/OrderPdfRepository.php | 1 + .../Plugin.OrderPdf.Entity.OrderPdf.dcm.yml | 4 ++ .../migration/Version20230912014925.php | 33 +++++++++++++++ Resource/template/admin/order_pdf.twig | 9 ++++ Service/OrderPdfService.php | 41 ++++++++++++++++++- 7 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 Resource/doctrine/migration/Version20230912014925.php diff --git a/Entity/OrderPdf.php b/Entity/OrderPdf.php index 1db9ad5..65ddfab 100644 --- a/Entity/OrderPdf.php +++ b/Entity/OrderPdf.php @@ -67,6 +67,11 @@ class OrderPdf extends AbstractEntity */ private $note3; + /** + * @var string + */ + private $invoice_registration_num; + /** * @var bool */ @@ -327,6 +332,30 @@ public function setNote3($note3) return $this; } + /** + * Get invoice_registration_num. + * + * @return string + */ + public function getInvoiceRegistrationNum() + { + return $this->invoice_registration_num; + } + + /** + * Set invoice_registration_num. + * + * @param string $invoice_registration_num + * + * @return OrderPdf + */ + public function setInvoiceRegistrationNum($invoice_registration_num) + { + $this->invoice_registration_num = $invoice_registration_num; + + return $this; + } + /** * Set default to save. * diff --git a/Form/Type/OrderPdfType.php b/Form/Type/OrderPdfType.php index 0ad8e17..2ad9428 100644 --- a/Form/Type/OrderPdfType.php +++ b/Form/Type/OrderPdfType.php @@ -78,6 +78,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) new Assert\Length(array('max' => $config['stext_len'])), ), )) + ->add('invoice_registration_num', 'text', array( + 'label' => '適格請求書発行事業者登録番号', + 'required' => false, + 'attr' => array('maxlength' => 14), + 'constraints' => array( + new Assert\Length(array('max' => $config['stext_len'])), + ), + )) // メッセージ ->add('message1', 'text', array( 'label' => '1行目', diff --git a/Repository/OrderPdfRepository.php b/Repository/OrderPdfRepository.php index 6b395a6..277006a 100644 --- a/Repository/OrderPdfRepository.php +++ b/Repository/OrderPdfRepository.php @@ -45,6 +45,7 @@ public function save(array $arrData) $OrderPdf->setId($Member->getId()) ->setTitle($arrData['title']) + ->setInvoiceRegistrationNum($arrData['invoice_registration_num']) ->setMessage1($arrData['message1']) ->setMessage2($arrData['message2']) ->setMessage3($arrData['message3']) diff --git a/Resource/doctrine/Plugin.OrderPdf.Entity.OrderPdf.dcm.yml b/Resource/doctrine/Plugin.OrderPdf.Entity.OrderPdf.dcm.yml index ea800b3..c0e9897 100644 --- a/Resource/doctrine/Plugin.OrderPdf.Entity.OrderPdf.dcm.yml +++ b/Resource/doctrine/Plugin.OrderPdf.Entity.OrderPdf.dcm.yml @@ -38,6 +38,10 @@ Plugin\OrderPdf\Entity\OrderPdf: type: string length: 50 nullable: true + invoice_registration_num: + type: string + length: 20 + nullable: true del_flg: type: smallint nullable: false diff --git a/Resource/doctrine/migration/Version20230912014925.php b/Resource/doctrine/migration/Version20230912014925.php new file mode 100644 index 0000000..7e762b1 --- /dev/null +++ b/Resource/doctrine/migration/Version20230912014925.php @@ -0,0 +1,33 @@ +getTable('plg_order_pdf'); + if (!$t->hasColumn('invoice_registration_num')) { + $t->addColumn('invoice_registration_num', 'string', array('NotNull' => false, 'length' => 20)); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + + } +} diff --git a/Resource/template/admin/order_pdf.twig b/Resource/template/admin/order_pdf.twig index 0c322de..9a73bba 100644 --- a/Resource/template/admin/order_pdf.twig +++ b/Resource/template/admin/order_pdf.twig @@ -56,6 +56,15 @@ {{ form_errors(form.title) }} + {#インボイス登録番号#} +
+ {{ form_label(form.invoice_registration_num) }} +
+ {{ form_widget(form.invoice_registration_num) }} + {{ form_errors(form.invoice_registration_num) }} +
+
+ {#メッセージ#}
diff --git a/Service/OrderPdfService.php b/Service/OrderPdfService.php index fef8725..2e3db7b 100644 --- a/Service/OrderPdfService.php +++ b/Service/OrderPdfService.php @@ -174,7 +174,7 @@ public function makePdf(array $formData) $this->renderTitle($formData['title']); // 店舗情報を描画する - $this->renderShopData(); + $this->renderShopData($formData); // 注文情報を描画する $this->renderOrderData($order); @@ -248,7 +248,7 @@ protected function addPdfPage() * PDFに店舗情報を設定する * ショップ名、ロゴ画像以外はdtb_helpに登録されたデータを使用する. */ - protected function renderShopData() + protected function renderShopData($formData = []) { // 基準座標を設定する $this->setBasePosition(); @@ -293,6 +293,12 @@ protected function renderShopData() $userPath = $this->app['config']['template_realdir'].'/../admin/OrderPdf/'.$logoFile; $logoFilePath = file_exists($userPath) ? $userPath : $originalPath; $this->Image($logoFilePath, 124, 46, 40); + + // インボイス登録番号 + if ($formData['invoice_registration_num']) { + $text = '登録番号: '.$formData['invoice_registration_num']; + $this->lfText(125, 87, $text, 8); + } } /** @@ -427,6 +433,8 @@ protected function renderOrderDetailData(Order $Order) // 受注詳細情報 // ========================================= $i = 0; + $arrTaxableTotal = []; + $defaultTaxRule = $this->app['eccube.repository.tax_rule']->getByRule(); /* @var OrderDetail $OrderDetail */ foreach ($Order->getOrderDetails() as $OrderDetail) { // class categoryの生成 @@ -445,6 +453,12 @@ protected function renderOrderDetailData(Order $Order) // product $arrOrder[$i][0] = sprintf('%s / %s / %s', $OrderDetail->getProductName(), $OrderDetail->getProductCode(), $classCategory); + + // 標準税率より低い税率は軽減税率として※を付与する + if ($defaultTaxRule->getTaxRate() > $OrderDetail->getTaxRate()) { + $arrOrder[$i][0] .= ' ※'; + } + // 購入数量 $arrOrder[$i][1] = number_format($OrderDetail->getQuantity()); // 税込金額(単価) @@ -452,6 +466,11 @@ protected function renderOrderDetailData(Order $Order) // 小計(商品毎) $arrOrder[$i][3] = number_format($OrderDetail->getTotalPrice()).self::MONETARY_UNIT; + if (array_key_exists($OrderDetail->getTaxRate(), $arrTaxableTotal) === false) { + $arrTaxableTotal[$OrderDetail->getTaxRate()] = 0; + } + $arrTaxableTotal[$OrderDetail->getTaxRate()] += $OrderDetail->getTotalPrice(); + ++$i; } @@ -474,12 +493,14 @@ protected function renderOrderDetailData(Order $Order) $arrOrder[$i][1] = ''; $arrOrder[$i][2] = '送料'; $arrOrder[$i][3] = number_format($Order->getDeliveryFeeTotal()).self::MONETARY_UNIT; + $arrTaxableTotal[$defaultTaxRule->getTaxRate()] += $Order->getDeliveryFeeTotal(); ++$i; $arrOrder[$i][0] = ''; $arrOrder[$i][1] = ''; $arrOrder[$i][2] = '手数料'; $arrOrder[$i][3] = number_format($Order->getCharge()).self::MONETARY_UNIT; + $arrTaxableTotal[$defaultTaxRule->getTaxRate()] += $Order->getCharge(); ++$i; $arrOrder[$i][0] = ''; @@ -495,6 +516,22 @@ protected function renderOrderDetailData(Order $Order) // PDFに設定する $this->setFancyTable($this->labelCell, $arrOrder, $this->widthCell); + + $this->SetLineWidth(.3); + $this->SetFont(self::FONT_SJIS, '', 6); + + $this->Cell(0, 0, '', 0, 1, 'C', 0, ''); + // 行頭近くの場合、表示崩れがあるためもう一個字下げする + if (270 <= $this->GetY()) { + $this->Cell(0, 0, '', 0, 1, 'C', 0, ''); + } + $width = array_reduce($this->widthCell, function ($n, $w) { + return $n + $w; + }); + $this->SetX(20); + + $message = $this->app['eccube.service.tax_rule']->getTaxDetail($arrTaxableTotal, $Order->getDiscount()); + $this->MultiCell($width, 4, $message, 0, 'R', 0, ''); } /**