Completed
Pull Request — 4.0 (#4736)
by chihiro
04:53
created

OrderPdfService::renderOrderData()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 4.0009

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 1
dl 0
loc 62
ccs 25
cts 26
cp 0.9615
crap 4.0009
rs 8.829
c 0
b 0
f 0

How to fix   Long Method   

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->getPref().$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
        if (null !== $Shipping->getCompanyName()) {
417 3
            // 会社名
418 3
            $text = $Shipping->getCompanyName();
419 3
            $this->lfText(27, 57, $text, 11);
420 3
            // 氏名
421
            $text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
422
            $this->lfText(27, 63, $text, 11);
423 3
        } else {
424
            $text = $Shipping->getName01().' '.$Shipping->getName02().' 様';
425
            $this->lfText(27, 59, $text, 11);
426
        }
427
428
        // =========================================
429
        // お買い上げ明細部
430
        // =========================================
431 3
        $this->SetFont(self::FONT_SJIS, '', 10);
432
433 3
        //ご注文日
434
        $orderDate = $Order->getCreateDate()->format('Y/m/d H:i');
435
        if ($Order->getOrderDate()) {
436
            $orderDate = $Order->getOrderDate()->format('Y/m/d H:i');
437
        }
438
439 3
        $this->lfText(25, 125, $orderDate, 10);
440
        //注文番号
441 3
        $this->lfText(25, 135, $Order->getOrderNo(), 10);
442
443 3
        // 総合計金額
444
        if (!$Order->isMultiple()) {
445 3
            $this->SetFont(self::FONT_SJIS, 'B', 15);
446 3
            $paymentTotalText = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
447 3
448 1
            $this->setBasePosition(120, 95.5);
449
            $this->Cell(5, 7, '', 0, 0, '', 0, '');
450 2
            $this->Cell(67, 8, $paymentTotalText, 0, 2, 'R', 0, '');
451
            $this->Cell(0, 45, '', 0, 2, '', 0, '');
452
        }
453
454
        // フォント情報の復元
455 3
        $this->restoreFont();
456
    }
457 3
458
    /**
459 3
     * 購入商品詳細情報を設定する.
460
     *
461 3
     * @param Shipping $Shipping
462
     */
463 3
    protected function renderOrderDetailData(Shipping $Shipping)
464
    {
465
        $arrOrder = [];
466 3
        // テーブルの微調整を行うための購入商品詳細情報をarrayに変換する
467
468
        // =========================================
469
        // 受注詳細情報
470
        // =========================================
471 3
        $i = 0;
472 3
        $isShowReducedTaxMess = false;
473 3
        $Order = $Shipping->getOrder();
474 3
        /* @var OrderItem $OrderItem */
475
        foreach ($Shipping->getOrderItems() as $OrderItem) {
476 3
            if (!$Order->isMultiple() && !$OrderItem->isProduct()) {
477 3
                continue;
478 3
            }
479 3
            // class categoryの生成
480 3
            $classCategory = '';
481
            /** @var OrderItem $OrderItem */
482 3
            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...
483 3
                $classCategory .= ' [ '.$OrderItem->getClassCategoryName1();
484 3
                if ($OrderItem->getClassCategoryName2() == '') {
485 3
                    $classCategory .= ' ]';
486 3
                } else {
487
                    $classCategory .= ' * '.$OrderItem->getClassCategoryName2().' ]';
488 3
                }
489 3
            }
490 3
491 3
            // product
492 3
            $productName = $OrderItem->getProductName();
493
            if (null !== $OrderItem->getProductCode()) {
494 3
                $productName .= ' / '.$OrderItem->getProductCode();
495 3
            }
496 3
            if ($classCategory) {
497 3
                $productName .= ' / '.$classCategory;
498 3
            }
499
            if ($this->taxExtension->isReducedTaxRate($OrderItem)) {
500 3
                $productName .= ' ※';
501 3
                $isShowReducedTaxMess = true;
502 3
            }
503 3
            $arrOrder[$i][0] = $productName;
504 3
            // 購入数量
505
            $arrOrder[$i][1] = number_format($OrderItem->getQuantity());
506
            // 税込金額(単価)
507 3
            $arrOrder[$i][2] = $this->eccubeExtension->getPriceFilter($OrderItem->getPrice());
508
            // 小計(商品毎)
509
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($OrderItem->getTotalPrice());
510
511
            ++$i;
512
        }
513
514
        if (!$Order->isMultiple()) {
515
            // =========================================
516
            // 小計
517
            // =========================================
518
            $arrOrder[$i][0] = '';
519 3
            $arrOrder[$i][1] = '';
520
            $arrOrder[$i][2] = '';
521
            $arrOrder[$i][3] = '';
522 3
523 3
            ++$i;
524
            $arrOrder[$i][0] = '';
525 3
            $arrOrder[$i][1] = '';
526 3
            $arrOrder[$i][2] = '商品合計';
527
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getSubtotal());
528
529 3
            ++$i;
530
            $arrOrder[$i][0] = '';
531
            $arrOrder[$i][1] = '';
532
            $arrOrder[$i][2] = '送料';
533
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getDeliveryFeeTotal());
534
535
            ++$i;
536
            $arrOrder[$i][0] = '';
537
            $arrOrder[$i][1] = '';
538
            $arrOrder[$i][2] = '手数料';
539
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getCharge());
540
541 3
            ++$i;
542
            $arrOrder[$i][0] = '';
543
            $arrOrder[$i][1] = '';
544 3
            $arrOrder[$i][2] = '値引き';
545
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getTaxableDiscount());
546
547 3
            ++$i;
548
            $arrOrder[$i][0] = '';
549
            $arrOrder[$i][1] = '';
550 3
            $arrOrder[$i][2] = '';
551 3
            $arrOrder[$i][3] = '';
552 3
553 3
            ++$i;
554 3
            $arrOrder[$i][0] = '';
555 3
            $arrOrder[$i][1] = '';
556
            $arrOrder[$i][2] = '合計';
557
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getTaxableTotal());
558 3
559 3
            foreach ($Order->getTaxableTotalByTaxRate() as $rate => $total) {
560 3
                ++$i;
561 3
                $arrOrder[$i][0] = '';
562
                $arrOrder[$i][1] = '';
563 3
                $arrOrder[$i][2] = '('.$rate.'%対象)';
564
                $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($total);
565
            }
566 3
567 3
            ++$i;
568 3
            $arrOrder[$i][0] = '';
569
            $arrOrder[$i][1] = '';
570 3
            $arrOrder[$i][2] = '';
571 3
            $arrOrder[$i][3] = '';
572 3
573
            foreach($Order->getTaxFreeDiscountItems() as $Item) {
574 3
                ++$i;
575 3
                $arrOrder[$i][0] = '';
576 3
                $arrOrder[$i][1] = '';
577
                $arrOrder[$i][2] = $Item->getProductName();
578
                $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Item->getTotalPrice());
579 3
            }
580 3
581
            ++$i;
582
            $arrOrder[$i][0] = '';
583
            $arrOrder[$i][1] = '';
584 3
            $arrOrder[$i][2] = '請求金額';
585
            $arrOrder[$i][3] = $this->eccubeExtension->getPriceFilter($Order->getPaymentTotal());
586
587 3
            if ($isShowReducedTaxMess) {
588 3
                ++$i;
589
                $arrOrder[$i][0] = '※は軽減税率対象商品です。';
590
                $arrOrder[$i][1] = '';
591
                $arrOrder[$i][2] = '';
592
                $arrOrder[$i][3] = '';
593 3
            }
594
        }
595 3
596 3
        // PDFに設定する
597 3
        $this->setFancyTable($this->labelCell, $arrOrder, $this->widthCell);
598 3
    }
599 3
600 3
    /**
601 3
     * PDFへのテキスト書き込み
602 3
     *
603
     * @param int    $x     X座標
604 3
     * @param int    $y     Y座標
605
     * @param string $text  テキスト
606 3
     * @param int    $size  フォントサイズ
607
     * @param string $style フォントスタイル
608 3
     */
609
    protected function lfText($x, $y, $text, $size = 0, $style = '')
610 3
    {
611 3
        // 退避
612 3
        $bakFontStyle = $this->FontStyle;
613
        $bakFontSize = $this->FontSizePt;
614
615 3
        $this->SetFont('', $style, $size);
616
        $this->Text($x + $this->baseOffsetX, $y + $this->baseOffsetY, $text);
617
618
        // 復元
619
        $this->SetFont('', $bakFontStyle, $bakFontSize);
620
    }
621
622
    /**
623
     * Colored table.
624 3
     *
625
     * TODO: 後の列の高さが大きい場合、表示が乱れる。
626
     *
627 3
     * @param array $header 出力するラベル名一覧
628
     * @param array $data   出力するデータ
629
     * @param array $w      出力するセル幅一覧
630 3
     */
631 3
    protected function setFancyTable($header, $data, $w)
632 3
    {
633 3
        // フォント情報のバックアップ
634
        $this->backupFont();
635
636
        // 開始座標の設定
637
        $this->setBasePosition(0, 149);
638
639
        // Colors, line width and bold font
640
        $this->SetFillColor(216, 216, 216);
641 3
        $this->SetTextColor(0);
642
        $this->SetDrawColor(0, 0, 0);
643
        $this->SetLineWidth(.3);
644 3
        $this->SetFont(self::FONT_SJIS, 'B', 8);
645 3
        $this->SetFont('', 'B');
646 3
647 3
        // Header
648
        $this->Cell(5, 7, '', 0, 0, '', 0, '');
649
        $count = count($header);
650 3
        for ($i = 0; $i < $count; ++$i) {
651 3
            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
652 3
        }
653
        $this->Ln();
654
655
        // Color and font restoration
656
        $this->SetFillColor(235, 235, 235);
657
        $this->SetTextColor(0);
658
        $this->SetFont('');
659
        // Data
660 3
        $fill = 0;
661
        $h = 4;
662
        foreach ($data as $row) {
663 3
            // 行のの処理
664 3
            $i = 0;
665 3
            $h = 4;
666
            $this->Cell(5, $h, '', 0, 0, '', 0, '');
667
668
            // Cellの高さを保持
669
            $cellHeight = 0;
670
            foreach ($row as $col) {
671 3
                // 列の処理
672
                // TODO: 汎用的ではない処理。この指定は呼び出し元で行うようにしたい。
673 3
                // テキストの整列を指定する
674
                $align = ($i == 0) ? 'L' : 'R';
675
676
                // セル高さが最大値を保持する
677
                if ($h >= $cellHeight) {
678
                    $cellHeight = $h;
679
                }
680
681
                // 最終列の場合は次の行へ移動
682
                // (0: 右へ移動(既定)/1: 次の行へ移動/2: 下へ移動)
683
                $ln = ($i == (count($row) - 1)) ? 1 : 0;
684
685
                $this->MultiCell(
686
                    $w[$i], // セル幅
687
                    $cellHeight, // セルの最小の高さ
688
                    $col, // 文字列
689
                    1, // 境界線の描画方法を指定
690
                    $align, // テキストの整列
691
                    $fill, // 背景の塗つぶし指定
692
                    $ln                 // 出力後のカーソルの移動方法
693
                );
694
                $h = $this->getLastH();
695
696
                ++$i;
697
            }
698
            $fill = !$fill;
699
        }
700
        $this->Cell(5, $h, '', 0, 0, '', 0, '');
701
        $this->Cell(array_sum($w), 0, '', 'T');
702
        $this->SetFillColor(255);
703
704
        // フォント情報の復元
705
        $this->restoreFont();
706
    }
707
708
    /**
709
     * 基準座標を設定する.
710
     *
711
     * @param int $x
712
     * @param int $y
713
     */
714
    protected function setBasePosition($x = null, $y = null)
715
    {
716
        // 現在のマージンを取得する
717
        $result = $this->getMargins();
718
719
        // 基準座標を指定する
720
        $actualX = is_null($x) ? $result['left'] : $x;
721
        $this->SetX($actualX);
722
        $actualY = is_null($y) ? $result['top'] : $y;
723
        $this->SetY($actualY);
724
    }
725
726
    /**
727
     * データが設定されていない場合にデフォルト値を設定する.
728
     *
729
     * @param array $formData
730
     */
731
    protected function setDefaultData(array &$formData)
732
    {
733
        $defaultList = [
734
            'title' => trans('admin.order.delivery_note_title__default'),
735
            'message1' => trans('admin.order.delivery_note_message__default1'),
736
            'message2' => trans('admin.order.delivery_note_message__default2'),
737
            'message3' => trans('admin.order.delivery_note_message__default3'),
738
        ];
739
740
        foreach ($defaultList as $key => $value) {
741
            if (is_null($formData[$key])) {
742
                $formData[$key] = $value;
743
            }
744
        }
745
    }
746
747
    /**
748
     * Font情報のバックアップ.
749
     */
750
    protected function backupFont()
751
    {
752
        // フォント情報のバックアップ
753
        $this->bakFontFamily = $this->FontFamily;
754
        $this->bakFontStyle = $this->FontStyle;
755
        $this->bakFontSize = $this->FontSizePt;
756
    }
757
758
    /**
759
     * Font情報の復元.
760
     */
761
    protected function restoreFont()
762
    {
763
        $this->SetFont($this->bakFontFamily, $this->bakFontStyle, $this->bakFontSize);
764
    }
765
}
766