Failed Conditions
Push — dev/payment-errors ( d6d2cc )
by Kiyotaka
11:23
created

OrderPdfService   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 662
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 662
rs 8.898
c 0
b 0
f 0
wmc 43
lcom 1
cbo 9

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 32 1
B makePdf() 0 63 5
A outputPdf() 0 4 1
A getPdfFileName() 0 12 3
A Footer() 0 4 1
A addPdfPage() 0 11 1
A renderShopData() 0 27 2
A renderMessageData() 0 6 1
A renderEtcData() 0 20 1
A renderTitle() 0 17 1
A renderOrderData() 0 53 3
B renderOrderDetailData() 0 87 7
A lfText() 0 12 1
B setFancyTable() 0 76 7
A setBasePosition() 0 11 3
A setDefaultData() 0 15 3
A backupFont() 0 7 1
A restoreFont() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like OrderPdfService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OrderPdfService, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service;
15
16
use Eccube\Common\EccubeConfig;
17
use Eccube\Entity\BaseInfo;
18
use Eccube\Entity\OrderItem;
19
use Eccube\Entity\Shipping;
20
use Eccube\Repository\BaseInfoRepository;
21
use Eccube\Repository\OrderPdfRepository;
22
use Eccube\Repository\OrderRepository;
23
use Eccube\Repository\ShippingRepository;
24
use Eccube\Twig\Extension\EccubeExtension;
25
use setasign\Fpdi\TcpdfFpdi;
26
27
/**
28
 * Class OrderPdfService.
29
 * Do export pdf function.
30
 */
31
class OrderPdfService extends TcpdfFpdi
32
{
33
    /** @var OrderRepository */
34
    protected $orderRepository;
35
36
    /** @var ShippingRepository */
37
    protected $shippingRepository;
38
39
    /** @var OrderPdfRepository */
40
    protected $orderPdfRepository;
41
42
    /** @var TaxRuleService */
43
    protected $taxRuleService;
44
45
    /**
46
     * @var EccubeConfig
47
     */
48
    private $eccubeConfig;
49
50
    /**
51
     * @var EccubeExtension
52
     */
53
    private $eccubeExtension;
54
55
    // ====================================
56
    // 定数宣言
57
    // ====================================
58
59
    /** ダウンロードするPDFファイルのデフォルト名 */
60
    const DEFAULT_PDF_FILE_NAME = 'nouhinsyo.pdf';
61
62
    /** FONT ゴシック */
63
    const FONT_GOTHIC = 'kozgopromedium';
64
    /** FONT 明朝 */
65
    const FONT_SJIS = 'kozminproregular';
66
67
    // ====================================
68
    // 変数宣言
69
    // ====================================
70
71
    /** @var BaseInfo */
72
    public $baseInfoRepository;
73
74
    /** 購入詳細情報 ラベル配列
75
     * @var array
76
     */
77
    private $labelCell = [];
78
79
    /*** 購入詳細情報 幅サイズ配列
80
     * @var array
81
     */
82
    private $widthCell = [];
83
84
    /** 最後に処理した注文番号 @var string */
85
    private $lastOrderId = null;
86
87
    // --------------------------------------
88
    // Font情報のバックアップデータ
89
    /** @var string フォント名 */
90
    private $bakFontFamily;
91
    /** @var string フォントスタイル */
92
    private $bakFontStyle;
93
    /** @var string フォントサイズ */
94
    private $bakFontSize;
95
    // --------------------------------------
96
97
    // lfTextのoffset
98
    private $baseOffsetX = 0;
99
    private $baseOffsetY = -4;
100
101
    /** ダウンロードファイル名 @var string */
102
    private $downloadFileName = null;
103
104
    /** 発行日 @var string */
105
    private $issueDate = '';
106
107
    /**
108
     * OrderPdfService constructor.
109
     *
110
     * @param EccubeConfig $eccubeConfig
111
     * @param OrderRepository $orderRepository
112
     * @param ShippingRepository $shippingRepository
113
     * @param TaxRuleService $taxRuleService
114
     * @param BaseInfoRepository $baseInfoRepository
115
     */
116
    public function __construct(EccubeConfig $eccubeConfig, OrderRepository $orderRepository, ShippingRepository $shippingRepository, TaxRuleService $taxRuleService, BaseInfoRepository $baseInfoRepository, EccubeExtension $eccubeExtension)
117
    {
118
        $this->eccubeConfig = $eccubeConfig;
119
        $this->baseInfoRepository = $baseInfoRepository->get();
120
        $this->orderRepository = $orderRepository;
121
        $this->shippingRepository = $shippingRepository;
122
        $this->taxRuleService = $taxRuleService;
123
        $this->eccubeExtension = $eccubeExtension;
124
        parent::__construct();
125
126
        // 購入詳細情報の設定を行う
127
        // 動的に入れ替えることはない
128
        $this->labelCell[] = '商品名 / 商品コード';
129
        $this->labelCell[] = '数量';
130
        $this->labelCell[] = '単価';
131
        $this->labelCell[] = '金額(税込)';
132
        $this->widthCell = [110.3, 12, 21.7, 24.5];
133
134
        // Fontの設定しておかないと文字化けを起こす
135
        $this->SetFont(self::FONT_SJIS);
136
137
        // PDFの余白(上左右)を設定
138
        $this->SetMargins(15, 20);
139
140
        // ヘッダーの出力を無効化
141
        $this->setPrintHeader(false);
142
143
        // フッターの出力を無効化
144
        $this->setPrintFooter(true);
145
        $this->setFooterMargin();
146
        $this->setFooterFont([self::FONT_SJIS, '', 8]);
147
    }
148
149
    /**
150
     * 注文情報からPDFファイルを作成する.
151
     *
152
     * @param array $formData
153
     *                        [KEY]
154
     *                        ids: 注文番号
155
     *                        issue_date: 発行日
156
     *                        title: タイトル
157
     *                        message1: メッセージ1行目
158
     *                        message2: メッセージ2行目
159
     *                        message3: メッセージ3行目
160
     *                        note1: 備考1行目
161
     *                        note2: 備考2行目
162
     *                        note3: 備考3行目
163
     *
164
     * @return bool
165
     */
166
    public function makePdf(array $formData)
167
    {
168
        // 発行日の設定
169
        $this->issueDate = '作成日: '.$formData['issue_date']->format('Y年m月d日');
170
        // ダウンロードファイル名の初期化
171
        $this->downloadFileName = null;
172
173
        // データが空であれば終了
174
        if (!$formData['ids']) {
175
            return false;
176
        }
177
178
        // 出荷番号をStringからarrayに変換
179
        $ids = explode(',', $formData['ids']);
180
181
        // 空文字列の場合のデフォルトメッセージを設定する
182
        $this->setDefaultData($formData);
183
184
        foreach ($ids as $id) {
185
            $this->lastOrderId = $id;
186
187
            // 出荷番号から出荷情報を取得する
188
            /** @var Shipping $Shipping */
189
            $Shipping = $this->shippingRepository->find($id);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $Shipping is correct as $this->shippingRepository->find($id) (which targets Doctrine\ORM\EntityRepository::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
190
            if (!$Shipping) {
191
                // 出荷情報の取得ができなかった場合
192
                continue;
193
            }
194
195
            // テンプレートファイルを読み込む
196
            $Order = $Shipping->getOrder();
197
            if ($Order->isMultiple()) {
198
                // 複数配送の時は読み込むテンプレートファイルを変更する
199
                $userPath = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/nouhinsyo_multiple.pdf';
200
            } else {
201
                $userPath = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/nouhinsyo.pdf';
202
            }
203
            $this->setSourceFile($userPath);
204
205
            // PDFにページを追加する
206
            $this->addPdfPage();
207
208
            // タイトルを描画する
209
            $this->renderTitle($formData['title']);
210
211
            // 店舗情報を描画する
212
            $this->renderShopData();
213
214
            // 注文情報を描画する
215
            $this->renderOrderData($Shipping);
216
217
            // メッセージを描画する
218
            $this->renderMessageData($formData);
219
220
            // 出荷詳細情報を描画する
221
            $this->renderOrderDetailData($Shipping);
222
223
            // 備考を描画する
224
            $this->renderEtcData($formData);
225
        }
226
227
        return true;
228
    }
229
230
    /**
231
     * PDFファイルを出力する.
232
     *
233
     * @return string|mixed
234
     */
235
    public function outputPdf()
236
    {
237
        return $this->Output($this->getPdfFileName(), 'S');
238
    }
239
240
    /**
241
     * PDFファイル名を取得する
242
     * PDFが1枚の時は注文番号をファイル名につける.
243
     *
244
     * @return string ファイル名
245
     */
246
    public function getPdfFileName()
247
    {
248
        if (!is_null($this->downloadFileName)) {
249
            return $this->downloadFileName;
250
        }
251
        $this->downloadFileName = self::DEFAULT_PDF_FILE_NAME;
252
        if ($this->PageNo() == 1) {
253
            $this->downloadFileName = 'nouhinsyo-No'.$this->lastOrderId.'.pdf';
254
        }
255
256
        return $this->downloadFileName;
257
    }
258
259
    /**
260
     * フッターに発行日を出力する.
261
     */
262
    public function Footer()
263
    {
264
        $this->Cell(0, 0, $this->issueDate, 0, 0, 'R');
265
    }
266
267
    /**
268
     * 作成するPDFのテンプレートファイルを指定する.
269
     */
270
    protected function addPdfPage()
271
    {
272
        // ページを追加
273
        $this->AddPage();
274
275
        // テンプレートに使うテンプレートファイルのページ番号を取得
276
        $tplIdx = $this->importPage(1);
277
278
        // テンプレートに使うテンプレートファイルのページ番号を指定
279
        $this->useTemplate($tplIdx, null, null, null, null, true);
280
    }
281
282
    /**
283
     * PDFに店舗情報を設定する
284
     * ショップ名、ロゴ画像以外はdtb_helpに登録されたデータを使用する.
285
     */
286
    protected function renderShopData()
287
    {
288
        // 基準座標を設定する
289
        $this->setBasePosition();
290
291
        // ショップ名
292
        $this->lfText(125, 60, $this->baseInfoRepository->getShopName(), 8, 'B');
293
294
        // 都道府県+所在地
295
        $text = $this->baseInfoRepository->getAddr01();
296
        $this->lfText(125, 65, $text, 8);
297
        $this->lfText(125, 69, $this->baseInfoRepository->getAddr02(), 8);
298
299
        // 電話番号
300
        $text = 'TEL: '.$this->baseInfoRepository->getPhoneNumber();
301
        $this->lfText(125, 72, $text, 8); //TEL・FAX
302
303
        // メールアドレス
304
        if (strlen($this->baseInfoRepository->getEmail01()) > 0) {
305
            $text = 'Email: '.$this->baseInfoRepository->getEmail01();
306
            $this->lfText(125, 75, $text, 8); // Email
307
        }
308
309
        // ロゴ画像(app配下のロゴ画像を優先して読み込む)
310
        $logoFile = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/logo.png';
311
        $this->Image($logoFile, 124, 46, 40);
312
    }
313
314
    /**
315
     * メッセージを設定する.
316
     *
317
     * @param array $formData
318
     */
319
    protected function renderMessageData(array $formData)
320
    {
321
        $this->lfText(27, 70, $formData['message1'], 8); //メッセージ1
322
        $this->lfText(27, 74, $formData['message2'], 8); //メッセージ2
323
        $this->lfText(27, 78, $formData['message3'], 8); //メッセージ3
324
    }
325
326
    /**
327
     * PDFに備考を設定数.
328
     *
329
     * @param array $formData
330
     */
331
    protected function renderEtcData(array $formData)
332
    {
333
        // フォント情報のバックアップ
334
        $this->backupFont();
335
336
        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
337
338
        $this->SetFont(self::FONT_GOTHIC, 'B', 9);
339
        $this->MultiCell(0, 6, '< 備考 >', 'T', 2, 'L', 0, '');
340
341
        $this->SetFont(self::FONT_SJIS, '', 8);
342
343
        $this->Ln();
344
        // rtrimを行う
345
        $text = preg_replace('/\s+$/us', '', $formData['note1']."\n".$formData['note2']."\n".$formData['note3']);
346
        $this->MultiCell(0, 4, $text, '', 2, 'L', 0, '');
347
348
        // フォント情報の復元
349
        $this->restoreFont();
350
    }
351
352
    /**
353
     * タイトルをPDFに描画する.
354
     *
355
     * @param string $title
356
     */
357
    protected function renderTitle($title)
358
    {
359
        // 基準座標を設定する
360
        $this->setBasePosition();
361
362
        // フォント情報のバックアップ
363
        $this->backupFont();
364
365
        //文書タイトル(納品書・請求書)
366
        $this->SetFont(self::FONT_GOTHIC, '', 15);
367
        $this->Cell(0, 10, $title, 0, 2, 'C', 0, '');
368
        $this->Cell(0, 66, '', 0, 2, 'R', 0, '');
369
        $this->Cell(5, 0, '', 0, 0, 'R', 0, '');
370
371
        // フォント情報の復元
372
        $this->restoreFont();
373
    }
374
375
    /**
376
     * 購入者情報を設定する.
377
     *
378
     * @param Shipping $Shipping
379
     */
380
    protected function renderOrderData(Shipping $Shipping)
381
    {
382
        // 基準座標を設定する
383
        $this->setBasePosition();
384
385
        // フォント情報のバックアップ
386
        $this->backupFont();
387
388
        // =========================================
389
        // 購入者情報部
390
        // =========================================
391
392
        $Order = $Shipping->getOrder();
393
394
        // 購入者都道府県+住所1
395
        // $text = $Order->getPref().$Order->getAddr01();
396
        $text = $Shipping->getPref().$Shipping->getAddr01();
397
        $this->lfText(27, 47, $text, 10);
398
        $this->lfText(27, 51, $Shipping->getAddr02(), 10); //購入者住所2
399
400
        // 購入者氏名
401
        $text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
402
        $this->lfText(27, 59, $text, 11);
403
404
        // =========================================
405
        // お買い上げ明細部
406
        // =========================================
407
        $this->SetFont(self::FONT_SJIS, '', 10);
408
409
        //ご注文日
410
        $orderDate = $Order->getCreateDate()->format('Y/m/d H:i');
411
        if ($Order->getOrderDate()) {
412
            $orderDate = $Order->getOrderDate()->format('Y/m/d H:i');
413
        }
414
415
        $this->lfText(25, 125, $orderDate, 10);
416
        //注文番号
417
        $this->lfText(25, 135, $Order->getOrderNo(), 10);
418
419
        // 総合計金額
420
        if (!$Order->isMultiple()) {
421
            $this->SetFont(self::FONT_SJIS, 'B', 15);
422
            $paymentTotalText = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
423
424
            $this->setBasePosition(120, 95.5);
425
            $this->Cell(5, 7, '', 0, 0, '', 0, '');
426
            $this->Cell(67, 8, $paymentTotalText, 0, 2, 'R', 0, '');
427
            $this->Cell(0, 45, '', 0, 2, '', 0, '');
428
        }
429
430
        // フォント情報の復元
431
        $this->restoreFont();
432
    }
433
434
    /**
435
     * 購入商品詳細情報を設定する.
436
     *
437
     * @param Shipping $Shipping
438
     */
439
    protected function renderOrderDetailData(Shipping $Shipping)
440
    {
441
        $arrOrder = [];
442
        // テーブルの微調整を行うための購入商品詳細情報をarrayに変換する
443
444
        // =========================================
445
        // 受注詳細情報
446
        // =========================================
447
        $i = 0;
448
        /* @var OrderItem $OrderItem */
449
        foreach ($Shipping->getOrderItems() as $OrderItem) {
450
            // class categoryの生成
451
            $classCategory = '';
452
            /** @var OrderItem $OrderItem */
453
            if ($OrderItem->getClassCategoryName1()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $OrderItem->getClassCategoryName1() of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
454
                $classCategory .= ' [ '.$OrderItem->getClassCategoryName1();
455
                if ($OrderItem->getClassCategoryName2() == '') {
456
                    $classCategory .= ' ]';
457
                } else {
458
                    $classCategory .= ' * '.$OrderItem->getClassCategoryName2().' ]';
459
                }
460
            }
461
462
            // product
463
            $productName = $OrderItem->getProductName();
464
            if (null !== $OrderItem->getProductCode()) {
465
                $productName .= ' / '.$OrderItem->getProductName();
466
            }
467
            if ($classCategory) {
468
                $productName .= ' / '.$classCategory;
469
            }
470
            $arrOrder[$i][0] = $productName;
471
            // 購入数量
472
            $arrOrder[$i][1] = number_format($OrderItem->getQuantity());
473
            // 税込金額(単価)
474
            $arrOrder[$i][2] = $this->eccubeExtension->getPriceFilter($OrderItem->getPrice());
475
            // 小計(商品毎)
476
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($OrderItem->getTotalPrice());
477
478
            ++$i;
479
        }
480
481
        $Order = $Shipping->getOrder();
482
483
        if (!$Order->isMultiple()) {
484
            // =========================================
485
            // 小計
486
            // =========================================
487
            $arrOrder[$i][0] = '';
488
            $arrOrder[$i][1] = '';
489
            $arrOrder[$i][2] = '';
490
            $arrOrder[$i][3] = '';
491
492
            ++$i;
493
            $arrOrder[$i][0] = '';
494
            $arrOrder[$i][1] = '';
495
            $arrOrder[$i][2] = '商品合計';
496
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getSubtotal());
497
498
            ++$i;
499
            $arrOrder[$i][0] = '';
500
            $arrOrder[$i][1] = '';
501
            $arrOrder[$i][2] = '送料';
502
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getDeliveryFeeTotal());
503
504
            ++$i;
505
            $arrOrder[$i][0] = '';
506
            $arrOrder[$i][1] = '';
507
            $arrOrder[$i][2] = '手数料';
508
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getCharge());
509
510
            ++$i;
511
            $arrOrder[$i][0] = '';
512
            $arrOrder[$i][1] = '';
513
            $arrOrder[$i][2] = '値引き';
514
            $arrOrder[$i][3] = '- '.$this->eccubeExtension->getPriceFilter($Order->getDiscount());
515
516
            ++$i;
517
            $arrOrder[$i][0] = '';
518
            $arrOrder[$i][1] = '';
519
            $arrOrder[$i][2] = '請求金額';
520
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
521
        }
522
523
        // PDFに設定する
524
        $this->setFancyTable($this->labelCell, $arrOrder, $this->widthCell);
525
    }
526
527
    /**
528
     * PDFへのテキスト書き込み
529
     *
530
     * @param int    $x     X座標
531
     * @param int    $y     Y座標
532
     * @param string $text  テキスト
533
     * @param int    $size  フォントサイズ
534
     * @param string $style フォントスタイル
535
     */
536
    protected function lfText($x, $y, $text, $size = 0, $style = '')
537
    {
538
        // 退避
539
        $bakFontStyle = $this->FontStyle;
540
        $bakFontSize = $this->FontSizePt;
541
542
        $this->SetFont('', $style, $size);
543
        $this->Text($x + $this->baseOffsetX, $y + $this->baseOffsetY, $text);
544
545
        // 復元
546
        $this->SetFont('', $bakFontStyle, $bakFontSize);
547
    }
548
549
    /**
550
     * Colored table.
551
     *
552
     * TODO: 後の列の高さが大きい場合、表示が乱れる。
553
     *
554
     * @param array $header 出力するラベル名一覧
555
     * @param array $data   出力するデータ
556
     * @param array $w      出力するセル幅一覧
557
     */
558
    protected function setFancyTable($header, $data, $w)
559
    {
560
        // フォント情報のバックアップ
561
        $this->backupFont();
562
563
        // 開始座標の設定
564
        $this->setBasePosition(0, 149);
565
566
        // Colors, line width and bold font
567
        $this->SetFillColor(216, 216, 216);
568
        $this->SetTextColor(0);
569
        $this->SetDrawColor(0, 0, 0);
570
        $this->SetLineWidth(.3);
571
        $this->SetFont(self::FONT_SJIS, 'B', 8);
572
        $this->SetFont('', 'B');
573
574
        // Header
575
        $this->Cell(5, 7, '', 0, 0, '', 0, '');
576
        $count = count($header);
577
        for ($i = 0; $i < $count; ++$i) {
578
            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
579
        }
580
        $this->Ln();
581
582
        // Color and font restoration
583
        $this->SetFillColor(235, 235, 235);
584
        $this->SetTextColor(0);
585
        $this->SetFont('');
586
        // Data
587
        $fill = 0;
588
        $h = 4;
589
        foreach ($data as $row) {
590
            // 行のの処理
591
            $i = 0;
592
            $h = 4;
593
            $this->Cell(5, $h, '', 0, 0, '', 0, '');
594
595
            // Cellの高さを保持
596
            $cellHeight = 0;
597
            foreach ($row as $col) {
598
                // 列の処理
599
                // TODO: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。
600
                // テキストの整列を指定する
601
                $align = ($i == 0) ? 'L' : 'R';
602
603
                // セル高さが最大値を保持する
604
                if ($h >= $cellHeight) {
605
                    $cellHeight = $h;
606
                }
607
608
                // 最終列の場合は次の行へ移動
609
                // (0: 右へ移動(既定)/1: 次の行へ移動/2: 下へ移動)
610
                $ln = ($i == (count($row) - 1)) ? 1 : 0;
611
612
                $this->MultiCell(
613
                    $w[$i], // セル幅
614
                    $cellHeight, // セルの最小の高さ
615
                    $col, // 文字列
616
                    1, // 境界線の描画方法を指定
617
                    $align, // テキストの整列
618
                    $fill, // 背景の塗つぶし指定
619
                    $ln                 // 出力後のカーソルの移動方法
620
                );
621
                $h = $this->getLastH();
622
623
                ++$i;
624
            }
625
            $fill = !$fill;
626
        }
627
        $this->Cell(5, $h, '', 0, 0, '', 0, '');
628
        $this->Cell(array_sum($w), 0, '', 'T');
629
        $this->SetFillColor(255);
630
631
        // フォント情報の復元
632
        $this->restoreFont();
633
    }
634
635
    /**
636
     * 基準座標を設定する.
637
     *
638
     * @param int $x
639
     * @param int $y
640
     */
641
    protected function setBasePosition($x = null, $y = null)
642
    {
643
        // 現在のマージンを取得する
644
        $result = $this->getMargins();
645
646
        // 基準座標を指定する
647
        $actualX = is_null($x) ? $result['left'] : $x;
648
        $this->SetX($actualX);
649
        $actualY = is_null($y) ? $result['top'] : $y;
650
        $this->SetY($actualY);
651
    }
652
653
    /**
654
     * データが設定されていない場合にデフォルト値を設定する.
655
     *
656
     * @param array $formData
657
     */
658
    protected function setDefaultData(array &$formData)
659
    {
660
        $defaultList = [
661
            'title' => trans('admin.order.delivery_note_title__default'),
662
            'message1' => trans('admin.order.delivery_note_message__default1'),
663
            'message2' => trans('admin.order.delivery_note_message__default2'),
664
            'message3' => trans('admin.order.delivery_note_message__default3'),
665
        ];
666
667
        foreach ($defaultList as $key => $value) {
668
            if (is_null($formData[$key])) {
669
                $formData[$key] = $value;
670
            }
671
        }
672
    }
673
674
    /**
675
     * Font情報のバックアップ.
676
     */
677
    protected function backupFont()
678
    {
679
        // フォント情報のバックアップ
680
        $this->bakFontFamily = $this->FontFamily;
681
        $this->bakFontStyle = $this->FontStyle;
682
        $this->bakFontSize = $this->FontSizePt;
683
    }
684
685
    /**
686
     * Font情報の復元.
687
     */
688
    protected function restoreFont()
689
    {
690
        $this->SetFont($this->bakFontFamily, $this->bakFontStyle, $this->bakFontSize);
691
    }
692
}
693