Skip to content

Commit

Permalink
インボイス対応
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Sep 11, 2023
1 parent a3f692d commit 376ba62
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 2 deletions.
29 changes: 29 additions & 0 deletions Entity/OrderPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class OrderPdf extends AbstractEntity
*/
private $note3;

/**
* @var string
*/
private $invoice_registration_num;

/**
* @var bool
*/
Expand Down Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions Form/Type/OrderPdfType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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行目',
Expand Down
1 change: 1 addition & 0 deletions Repository/OrderPdfRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
4 changes: 4 additions & 0 deletions Resource/doctrine/Plugin.OrderPdf.Entity.OrderPdf.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions Resource/doctrine/migration/Version20230912014925.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20230912014925 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$t = $schema->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

}
}
9 changes: 9 additions & 0 deletions Resource/template/admin/order_pdf.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
{{ form_errors(form.title) }}
</div>
</div>
{#インボイス登録番号#}
<div class="form-group">
{{ form_label(form.invoice_registration_num) }}
<div class="col-sm-9 col-lg-10">
{{ form_widget(form.invoice_registration_num) }}
{{ form_errors(form.invoice_registration_num) }}
</div>
</div>

{#メッセージ#}
<div class="form-group">
<label class="col-sm-2 control-label">メッセージ</label>
Expand Down
41 changes: 39 additions & 2 deletions Service/OrderPdfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function makePdf(array $formData)
$this->renderTitle($formData['title']);

// 店舗情報を描画する
$this->renderShopData();
$this->renderShopData($formData);

// 注文情報を描画する
$this->renderOrderData($order);
Expand Down Expand Up @@ -248,7 +248,7 @@ protected function addPdfPage()
* PDFに店舗情報を設定する
* ショップ名、ロゴ画像以外はdtb_helpに登録されたデータを使用する.
*/
protected function renderShopData()
protected function renderShopData($formData = [])
{
// 基準座標を設定する
$this->setBasePosition();
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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の生成
Expand All @@ -445,13 +453,24 @@ 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());
// 税込金額(単価)
$arrOrder[$i][2] = number_format($OrderDetail->getPriceIncTax()).self::MONETARY_UNIT;
// 小計(商品毎)
$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->getPriceIncTax();

++$i;
}

Expand All @@ -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] = '';
Expand All @@ -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, '');
}

/**
Expand Down

0 comments on commit 376ba62

Please sign in to comment.