Failed Conditions
Push — 4.0 ( f3e983...d5d6e1 )
by Ryo
22s queued 10s
created

OrderPdfService::renderOrderDetailData()   C

Complexity

Conditions 10
Paths 50

Size

Total Lines 130

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 67
CRAP Score 10

Importance

Changes 0
Metric Value
cc 10
nc 50
nop 1
dl 0
loc 130
ccs 67
cts 67
cp 1
crap 10
rs 6.1333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.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 Eccube\Twig\Extension\TaxExtension;
26
use setasign\Fpdi\TcpdfFpdi;
27
28
/**
29
 * Class OrderPdfService.
30
 * Do export pdf function.
31
 */
32
class OrderPdfService extends TcpdfFpdi
0 ignored issues
show
Deprecated Code introduced by
The class setasign\Fpdi\TcpdfFpdi has been deprecated with message: Class was moved to \setasign\Fpdi\Tcpdf\Fpdi

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
{
34
    /** @var OrderRepository */
35
    protected $orderRepository;
36
37
    /** @var ShippingRepository */
38
    protected $shippingRepository;
39
40
    /** @var OrderPdfRepository */
41
    protected $orderPdfRepository;
42
43
    /** @var TaxRuleService */
44
    protected $taxRuleService;
45
46
    /**
47
     * @var EccubeConfig
48
     */
49
    private $eccubeConfig;
50
51
    /**
52
     * @var EccubeExtension
53
     */
54
    private $eccubeExtension;
55
56
    /**
57
     * @var TaxExtension
58
     */
59
    private $taxExtension;
60
61
    // ====================================
62
    // 定数宣言
63
    // ====================================
64
65
    /** ダウンロードするPDFファイルのデフォルト名 */
66
    const DEFAULT_PDF_FILE_NAME = 'nouhinsyo.pdf';
67
68
    /** FONT ゴシック */
69
    const FONT_GOTHIC = 'kozgopromedium';
70
    /** FONT 明朝 */
71
    const FONT_SJIS = 'kozminproregular';
72
73
    // ====================================
74
    // 変数宣言
75
    // ====================================
76
77
    /** @var BaseInfo */
78
    public $baseInfoRepository;
79
80
    /** 購入詳細情報 ラベル配列
81
     * @var array
82
     */
83
    private $labelCell = [];
84
85
    /*** 購入詳細情報 幅サイズ配列
86
     * @var array
87
     */
88
    private $widthCell = [];
89
90
    /** 最後に処理した注文番号 @var string */
91
    private $lastOrderId = null;
92
93
    // --------------------------------------
94
    // Font情報のバックアップデータ
95
    /** @var string フォント名 */
96
    private $bakFontFamily;
97
    /** @var string フォントスタイル */
98
    private $bakFontStyle;
99
    /** @var string フォントサイズ */
100
    private $bakFontSize;
101
    // --------------------------------------
102
103
    // lfTextのoffset
104
    private $baseOffsetX = 0;
105
    private $baseOffsetY = -4;
106
107
    /** ダウンロードファイル名 @var string */
108
    private $downloadFileName = null;
109
110
    /** 発行日 @var string */
111
    private $issueDate = '';
112
113
    /**
114
     * OrderPdfService constructor.
115
     * @param EccubeConfig $eccubeConfig
116
     * @param OrderRepository $orderRepository
117 28
     * @param ShippingRepository $shippingRepository
118
     * @param TaxRuleService $taxRuleService
119 28
     * @param BaseInfoRepository $baseInfoRepository
120 28
     * @param EccubeExtension $eccubeExtension
121 28
     * @param TaxExtension $taxExtension
122 28
     * @throws \Exception
123 28
     */
124 28
    public function __construct(EccubeConfig $eccubeConfig, OrderRepository $orderRepository, ShippingRepository $shippingRepository, TaxRuleService $taxRuleService, BaseInfoRepository $baseInfoRepository, EccubeExtension $eccubeExtension, TaxExtension $taxExtension)
125 28
    {
126
        $this->eccubeConfig = $eccubeConfig;
127
        $this->baseInfoRepository = $baseInfoRepository->get();
128
        $this->orderRepository = $orderRepository;
129 28
        $this->shippingRepository = $shippingRepository;
130 28
        $this->taxRuleService = $taxRuleService;
131 28
        $this->eccubeExtension = $eccubeExtension;
132 28
        $this->taxExtension = $taxExtension;
133 28
134
        parent::__construct();
135
136 28
        // 購入詳細情報の設定を行う
137
        // 動的に入れ替えることはない
138
        $this->labelCell[] = '商品名 / 商品コード';
139 28
        $this->labelCell[] = '数量';
140
        $this->labelCell[] = '単価';
141
        $this->labelCell[] = '金額(税込)';
142 28
        $this->widthCell = [110.3, 12, 21.7, 24.5];
143
144
        // Fontの設定しておかないと文字化けを起こす
145 28
        $this->SetFont(self::FONT_SJIS);
146 28
147 28
        // PDFの余白(上左右)を設定
148
        $this->SetMargins(15, 20);
149
150
        // ヘッダーの出力を無効化
151
        $this->setPrintHeader(false);
152
153
        // フッターの出力を無効化
154
        $this->setPrintFooter(true);
155
        $this->setFooterMargin();
156
        $this->setFooterFont([self::FONT_SJIS, '', 8]);
157
    }
158
159
    /**
160
     * 注文情報からPDFファイルを作成する.
161
     *
162
     * @param array $formData
163
     *                        [KEY]
164
     *                        ids: 注文番号
165
     *                        issue_date: 発行日
166
     *                        title: タイトル
167 3
     *                        message1: メッセージ1行目
168
     *                        message2: メッセージ2行目
169
     *                        message3: メッセージ3行目
170 3
     *                        note1: 備考1行目
171
     *                        note2: 備考2行目
172 3
     *                        note3: 備考3行目
173
     *
174
     * @return bool
175 3
     */
176
    public function makePdf(array $formData)
177
    {
178
        // 発行日の設定
179
        $this->issueDate = '作成日: '.$formData['issue_date']->format('Y年m月d日');
180 3
        // ダウンロードファイル名の初期化
181
        $this->downloadFileName = null;
182
183 3
        // データが空であれば終了
184
        if (!$formData['ids']) {
185
            return false;
186 3
        }
187 3
188
        // 出荷番号をStringからarrayに変換
189 3
        $ids = explode(',', $formData['ids']);
190 3
191
        // 空文字列の場合のデフォルトメッセージを設定する
192
        $this->setDefaultData($formData);
193
194 3
        foreach ($ids as $id) {
195 3
            $this->lastOrderId = $id;
196
197
            // 出荷番号から出荷情報を取得する
198
            /** @var Shipping $Shipping */
199
            $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...
200
            if (!$Shipping) {
201 3
                // 出荷情報の取得ができなかった場合
202
                continue;
203
            }
204 3
205
            // テンプレートファイルを読み込む
206
            $Order = $Shipping->getOrder();
207 3
            if ($Order->isMultiple()) {
208
                // 複数配送の時は読み込むテンプレートファイルを変更する
209
                $userPath = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/nouhinsyo_multiple.pdf';
210 3
            } else {
211
                $userPath = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/nouhinsyo.pdf';
212
            }
213 3
            $this->setSourceFile($userPath);
214
215
            // PDFにページを追加する
216 3
            $this->addPdfPage();
217
218
            // タイトルを描画する
219 3
            $this->renderTitle($formData['title']);
220
221
            // 店舗情報を描画する
222 3
            $this->renderShopData();
223
224
            // 注文情報を描画する
225
            $this->renderOrderData($Shipping);
226
227
            // メッセージを描画する
228
            $this->renderMessageData($formData);
229
230 3
            // 出荷詳細情報を描画する
231
            $this->renderOrderDetailData($Shipping);
232 3
233
            // 備考を描画する
234
            $this->renderEtcData($formData);
235
        }
236
237
        return true;
238
    }
239
240
    /**
241 3
     * PDFファイルを出力する.
242
     *
243 3
     * @return string|mixed
244 3
     */
245
    public function outputPdf()
246 3
    {
247 3
        return $this->Output($this->getPdfFileName(), 'S');
248 3
    }
249
250
    /**
251 3
     * PDFファイル名を取得する
252
     * PDFが1枚の時は注文番号をファイル名につける.
253
     *
254
     * @return string ファイル名
255
     */
256
    public function getPdfFileName()
257 3
    {
258
        if (!is_null($this->downloadFileName)) {
259 3
            return $this->downloadFileName;
260
        }
261
        $this->downloadFileName = self::DEFAULT_PDF_FILE_NAME;
262
        if ($this->PageNo() == 1) {
263
            $this->downloadFileName = 'nouhinsyo-No'.$this->lastOrderId.'.pdf';
264
        }
265 3
266
        return $this->downloadFileName;
267
    }
268 3
269
    /**
270
     * フッターに発行日を出力する.
271 3
     */
272
    public function Footer()
273
    {
274 3
        $this->Cell(0, 0, $this->issueDate, 0, 0, 'R');
275
    }
276
277
    /**
278
     * 作成するPDFのテンプレートファイルを指定する.
279
     */
280
    protected function addPdfPage()
281 3
    {
282
        // ページを追加
283
        $this->AddPage();
284 3
285
        // テンプレートに使うテンプレートファイルのページ番号を取得
286
        $tplIdx = $this->importPage(1);
287 3
288
        // テンプレートに使うテンプレートファイルのページ番号を指定
289
        $this->useTemplate($tplIdx, null, null, null, null, true);
290 3
    }
291 3
292 3
    /**
293
     * PDFに店舗情報を設定する
294
     * ショップ名、ロゴ画像以外はdtb_helpに登録されたデータを使用する.
295 3
     */
296 3
    protected function renderShopData()
297
    {
298
        // 基準座標を設定する
299 3
        $this->setBasePosition();
300 3
301 3
        // ショップ名
302
        $this->lfText(125, 60, $this->baseInfoRepository->getShopName(), 8, 'B');
303
304
        // 都道府県+所在地
305 3
        $text = $this->baseInfoRepository->getAddr01();
306 3
        $this->lfText(125, 65, $text, 8);
307
        $this->lfText(125, 69, $this->baseInfoRepository->getAddr02(), 8);
308
309
        // 電話番号
310
        $text = 'TEL: '.$this->baseInfoRepository->getPhoneNumber();
311
        $this->lfText(125, 72, $text, 8); //TEL・FAX
312
313
        // メールアドレス
314 3
        if (strlen($this->baseInfoRepository->getEmail01()) > 0) {
315
            $text = 'Email: '.$this->baseInfoRepository->getEmail01();
316 3
            $this->lfText(125, 75, $text, 8); // Email
317 3
        }
318 3
319
        // user_dataにlogo.pngが配置されている場合は優先的に読み込む
320
        $logoFile = $this->eccubeConfig->get('eccube_html_dir').'/user_data/assets/pdf/logo.png';
321
322
        if (!file_exists($logoFile)) {
323
            $logoFile = $this->eccubeConfig->get('eccube_html_admin_dir').'/assets/pdf/logo.png';
324
        }
325
326 3
        $this->Image($logoFile, 124, 46, 40);
327
    }
328
329 3
    /**
330
     * メッセージを設定する.
331 3
     *
332
     * @param array $formData
333 3
     */
334 3
    protected function renderMessageData(array $formData)
335
    {
336 3
        $this->lfText(27, 70, $formData['message1'], 8); //メッセージ1
337
        $this->lfText(27, 74, $formData['message2'], 8); //メッセージ2
338 3
        $this->lfText(27, 78, $formData['message3'], 8); //メッセージ3
339
    }
340 3
341 3
    /**
342
     * PDFに備考を設定数.
343
     *
344 3
     * @param array $formData
345
     */
346
    protected function renderEtcData(array $formData)
347
    {
348
        // フォント情報のバックアップ
349
        $this->backupFont();
350
351
        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
352 3
353
        $this->SetFont(self::FONT_GOTHIC, 'B', 9);
354
        $this->MultiCell(0, 6, '< 備考 >', 'T', 2, 'L', 0, '');
355 3
356
        $this->SetFont(self::FONT_SJIS, '', 8);
357
358 3
        $this->Ln();
359
        // rtrimを行う
360
        $text = preg_replace('/\s+$/us', '', $formData['note1']."\n".$formData['note2']."\n".$formData['note3']);
361 3
        $this->MultiCell(0, 4, $text, '', 2, 'L', 0, '');
362 3
363 3
        // フォント情報の復元
364 3
        $this->restoreFont();
365
    }
366
367 3
    /**
368
     * タイトルをPDFに描画する.
369
     *
370
     * @param string $title
371
     */
372
    protected function renderTitle($title)
373
    {
374
        // 基準座標を設定する
375 3
        $this->setBasePosition();
376
377
        // フォント情報のバックアップ
378 3
        $this->backupFont();
379
380
        //文書タイトル(納品書・請求書)
381 3
        $this->SetFont(self::FONT_GOTHIC, '', 15);
382
        $this->Cell(0, 10, $title, 0, 2, 'C', 0, '');
383
        $this->Cell(0, 66, '', 0, 2, 'R', 0, '');
384
        $this->Cell(5, 0, '', 0, 0, 'R', 0, '');
385
386
        // フォント情報の復元
387 3
        $this->restoreFont();
388
    }
389
390 3
    /**
391 3
     * 購入者情報を設定する.
392 3
     *
393
     * @param Shipping $Shipping
394
     */
395 3
    protected function renderOrderData(Shipping $Shipping)
396 3
    {
397
        // 基準座標を設定する
398
        $this->setBasePosition();
399
400
        // フォント情報のバックアップ
401 3
        $this->backupFont();
402
403
        // =========================================
404 3
        // 購入者情報部
405 3
        // =========================================
406
407
        $Order = $Shipping->getOrder();
408
409 3
        // 購入者都道府県+住所1
410
        // $text = $Order->getPref().$Order->getAddr01();
411 3
        $text = $Shipping->getPref().$Shipping->getAddr01();
412
        $this->lfText(27, 47, $text, 10);
413
        $this->lfText(27, 51, $Shipping->getAddr02(), 10); //購入者住所2
414 3
415 3
        // 購入者氏名
416
        $text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
417 3
        $this->lfText(27, 59, $text, 11);
418 3
419 3
        // =========================================
420 3
        // お買い上げ明細部
421
        // =========================================
422
        $this->SetFont(self::FONT_SJIS, '', 10);
423 3
424
        //ご注文日
425
        $orderDate = $Order->getCreateDate()->format('Y/m/d H:i');
426
        if ($Order->getOrderDate()) {
427
            $orderDate = $Order->getOrderDate()->format('Y/m/d H:i');
428
        }
429
430
        $this->lfText(25, 125, $orderDate, 10);
431 3
        //注文番号
432
        $this->lfText(25, 135, $Order->getOrderNo(), 10);
433 3
434
        // 総合計金額
435
        if (!$Order->isMultiple()) {
436
            $this->SetFont(self::FONT_SJIS, 'B', 15);
437
            $paymentTotalText = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
438
439 3
            $this->setBasePosition(120, 95.5);
440
            $this->Cell(5, 7, '', 0, 0, '', 0, '');
441 3
            $this->Cell(67, 8, $paymentTotalText, 0, 2, 'R', 0, '');
442
            $this->Cell(0, 45, '', 0, 2, '', 0, '');
443 3
        }
444
445 3
        // フォント情報の復元
446 3
        $this->restoreFont();
447 3
    }
448 1
449
    /**
450 2
     * 購入商品詳細情報を設定する.
451
     *
452
     * @param Shipping $Shipping
453
     */
454
    protected function renderOrderDetailData(Shipping $Shipping)
455 3
    {
456
        $arrOrder = [];
457 3
        // テーブルの微調整を行うための購入商品詳細情報をarrayに変換する
458
459 3
        // =========================================
460
        // 受注詳細情報
461 3
        // =========================================
462
        $i = 0;
463 3
        /* @var OrderItem $OrderItem */
464
        foreach ($Shipping->getOrderItems() as $OrderItem) {
465
            // class categoryの生成
466 3
            $classCategory = '';
467
            /** @var OrderItem $OrderItem */
468
            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...
469
                $classCategory .= ' [ '.$OrderItem->getClassCategoryName1();
470
                if ($OrderItem->getClassCategoryName2() == '') {
471 3
                    $classCategory .= ' ]';
472 3
                } else {
473 3
                    $classCategory .= ' * '.$OrderItem->getClassCategoryName2().' ]';
474 3
                }
475
            }
476 3
477 3
            // product
478 3
            $productName = $OrderItem->getProductName();
479 3
            if (null !== $OrderItem->getProductCode()) {
480 3
                $productName .= ' / '.$OrderItem->getProductCode();
481
            }
482 3
            if ($classCategory) {
483 3
                $productName .= ' / '.$classCategory;
484 3
            }
485 3
            if ($this->taxExtension->isReducedTaxRate($OrderItem)) {
486 3
                $productName .= ' ※';
487
            }
488 3
            $arrOrder[$i][0] = $productName;
489 3
            // 購入数量
490 3
            $arrOrder[$i][1] = number_format($OrderItem->getQuantity());
491 3
            // 税込金額(単価)
492 3
            $arrOrder[$i][2] = $this->eccubeExtension->getPriceFilter($OrderItem->getPrice());
493
            // 小計(商品毎)
494 3
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($OrderItem->getTotalPrice());
495 3
496 3
            ++$i;
497 3
        }
498 3
499
        $Order = $Shipping->getOrder();
500 3
501 3
        if (!$Order->isMultiple()) {
502 3
            // =========================================
503 3
            // 小計
504 3
            // =========================================
505
            $arrOrder[$i][0] = '';
506
            $arrOrder[$i][1] = '';
507 3
            $arrOrder[$i][2] = '';
508
            $arrOrder[$i][3] = '';
509
510
            ++$i;
511
            $arrOrder[$i][0] = '';
512
            $arrOrder[$i][1] = '';
513
            $arrOrder[$i][2] = '商品合計';
514
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getSubtotal());
515
516
            ++$i;
517
            $arrOrder[$i][0] = '';
518
            $arrOrder[$i][1] = '';
519 3
            $arrOrder[$i][2] = '送料';
520
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getDeliveryFeeTotal());
521
522 3
            ++$i;
523 3
            $arrOrder[$i][0] = '';
524
            $arrOrder[$i][1] = '';
525 3
            $arrOrder[$i][2] = '手数料';
526 3
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getCharge());
527
528
            ++$i;
529 3
            $arrOrder[$i][0] = '';
530
            $arrOrder[$i][1] = '';
531
            $arrOrder[$i][2] = '値引き';
532
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getTaxableDiscount());
533
534
            ++$i;
535
            $arrOrder[$i][0] = '';
536
            $arrOrder[$i][1] = '';
537
            $arrOrder[$i][2] = '';
538
            $arrOrder[$i][3] = '';
539
540
            ++$i;
541 3
            $arrOrder[$i][0] = '';
542
            $arrOrder[$i][1] = '';
543
            $arrOrder[$i][2] = '合計';
544 3
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getTaxableTotal());
545
546
            foreach ($Order->getTaxableTotalByTaxRate() as $rate => $total) {
547 3
                ++$i;
548
                $arrOrder[$i][0] = '';
549
                $arrOrder[$i][1] = '';
550 3
                $arrOrder[$i][2] = '('.$rate.'%対象)';
551 3
                $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($total);
552 3
            }
553 3
554 3
            ++$i;
555 3
            $arrOrder[$i][0] = '';
556
            $arrOrder[$i][1] = '';
557
            $arrOrder[$i][2] = '';
558 3
            $arrOrder[$i][3] = '';
559 3
560 3
            foreach($Order->getTaxFreeDiscountItems() as $Item) {
561 3
                ++$i;
562
                $arrOrder[$i][0] = '';
563 3
                $arrOrder[$i][1] = '';
564
                $arrOrder[$i][2] = $Item->getProductName();
565
                $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Item->getTotalPrice());
566 3
            }
567 3
568 3
            ++$i;
569
            $arrOrder[$i][0] = '';
570 3
            $arrOrder[$i][1] = '';
571 3
            $arrOrder[$i][2] = '請求金額';
572 3
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
573
574 3
            ++$i;
575 3
            $arrOrder[$i][0] = '※は軽減税率対象商品です。';
576 3
            $arrOrder[$i][1] = '';
577
            $arrOrder[$i][2] = '';
578
            $arrOrder[$i][3] = '';
579 3
        }
580 3
581
        // PDFに設定する
582
        $this->setFancyTable($this->labelCell, $arrOrder, $this->widthCell);
583
    }
584 3
585
    /**
586
     * PDFへのテキスト書き込み
587 3
     *
588 3
     * @param int    $x     X座標
589
     * @param int    $y     Y座標
590
     * @param string $text  テキスト
591
     * @param int    $size  フォントサイズ
592
     * @param string $style フォントスタイル
593 3
     */
594
    protected function lfText($x, $y, $text, $size = 0, $style = '')
595 3
    {
596 3
        // 退避
597 3
        $bakFontStyle = $this->FontStyle;
598 3
        $bakFontSize = $this->FontSizePt;
599 3
600 3
        $this->SetFont('', $style, $size);
601 3
        $this->Text($x + $this->baseOffsetX, $y + $this->baseOffsetY, $text);
602 3
603
        // 復元
604 3
        $this->SetFont('', $bakFontStyle, $bakFontSize);
605
    }
606 3
607
    /**
608 3
     * Colored table.
609
     *
610 3
     * TODO: 後の列の高さが大きい場合、表示が乱れる。
611 3
     *
612 3
     * @param array $header 出力するラベル名一覧
613
     * @param array $data   出力するデータ
614
     * @param array $w      出力するセル幅一覧
615 3
     */
616
    protected function setFancyTable($header, $data, $w)
617
    {
618
        // フォント情報のバックアップ
619
        $this->backupFont();
620
621
        // 開始座標の設定
622
        $this->setBasePosition(0, 149);
623
624 3
        // Colors, line width and bold font
625
        $this->SetFillColor(216, 216, 216);
626
        $this->SetTextColor(0);
627 3
        $this->SetDrawColor(0, 0, 0);
628
        $this->SetLineWidth(.3);
629
        $this->SetFont(self::FONT_SJIS, 'B', 8);
630 3
        $this->SetFont('', 'B');
631 3
632 3
        // Header
633 3
        $this->Cell(5, 7, '', 0, 0, '', 0, '');
634
        $count = count($header);
635
        for ($i = 0; $i < $count; ++$i) {
636
            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
637
        }
638
        $this->Ln();
639
640
        // Color and font restoration
641 3
        $this->SetFillColor(235, 235, 235);
642
        $this->SetTextColor(0);
643
        $this->SetFont('');
644 3
        // Data
645 3
        $fill = 0;
646 3
        $h = 4;
647 3
        foreach ($data as $row) {
648
            // 行のの処理
649
            $i = 0;
650 3
            $h = 4;
651 3
            $this->Cell(5, $h, '', 0, 0, '', 0, '');
652 3
653
            // Cellの高さを保持
654
            $cellHeight = 0;
655
            foreach ($row as $col) {
656
                // 列の処理
657
                // TODO: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。
658
                // テキストの整列を指定する
659
                $align = ($i == 0) ? 'L' : 'R';
660 3
661
                // セル高さが最大値を保持する
662
                if ($h >= $cellHeight) {
663 3
                    $cellHeight = $h;
664 3
                }
665 3
666
                // 最終列の場合は次の行へ移動
667
                // (0: 右へ移動(既定)/1: 次の行へ移動/2: 下へ移動)
668
                $ln = ($i == (count($row) - 1)) ? 1 : 0;
669
670
                $this->MultiCell(
671 3
                    $w[$i], // セル幅
672
                    $cellHeight, // セルの最小の高さ
673 3
                    $col, // 文字列
674
                    1, // 境界線の描画方法を指定
675
                    $align, // テキストの整列
676
                    $fill, // 背景の塗つぶし指定
677
                    $ln                 // 出力後のカーソルの移動方法
678
                );
679
                $h = $this->getLastH();
680
681
                ++$i;
682
            }
683
            $fill = !$fill;
684
        }
685
        $this->Cell(5, $h, '', 0, 0, '', 0, '');
686
        $this->Cell(array_sum($w), 0, '', 'T');
687
        $this->SetFillColor(255);
688
689
        // フォント情報の復元
690
        $this->restoreFont();
691
    }
692
693
    /**
694
     * 基準座標を設定する.
695
     *
696
     * @param int $x
697
     * @param int $y
698
     */
699
    protected function setBasePosition($x = null, $y = null)
700
    {
701
        // 現在のマージンを取得する
702
        $result = $this->getMargins();
703
704
        // 基準座標を指定する
705
        $actualX = is_null($x) ? $result['left'] : $x;
706
        $this->SetX($actualX);
707
        $actualY = is_null($y) ? $result['top'] : $y;
708
        $this->SetY($actualY);
709
    }
710
711
    /**
712
     * データが設定されていない場合にデフォルト値を設定する.
713
     *
714
     * @param array $formData
715
     */
716
    protected function setDefaultData(array &$formData)
717
    {
718
        $defaultList = [
719
            'title' => trans('admin.order.delivery_note_title__default'),
720
            'message1' => trans('admin.order.delivery_note_message__default1'),
721
            'message2' => trans('admin.order.delivery_note_message__default2'),
722
            'message3' => trans('admin.order.delivery_note_message__default3'),
723
        ];
724
725
        foreach ($defaultList as $key => $value) {
726
            if (is_null($formData[$key])) {
727
                $formData[$key] = $value;
728
            }
729
        }
730
    }
731
732
    /**
733
     * Font情報のバックアップ.
734
     */
735
    protected function backupFont()
736
    {
737
        // フォント情報のバックアップ
738
        $this->bakFontFamily = $this->FontFamily;
739
        $this->bakFontStyle = $this->FontStyle;
740
        $this->bakFontSize = $this->FontSizePt;
741
    }
742
743
    /**
744
     * Font情報の復元.
745
     */
746
    protected function restoreFont()
747
    {
748
        $this->SetFont($this->bakFontFamily, $this->bakFontStyle, $this->bakFontSize);
749
    }
750
}
751