From 28af2485adf2ff6cf0440e2ef787ece02de18e5a Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sat, 2 Sep 2023 00:44:21 +0900 Subject: [PATCH 01/15] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=9C=E3=82=A4?= =?UTF-8?q?=E3=82=B9=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 納品書を4.2系と同様にインボイス準拠するよう対応 - 受注完了メールの「うち消費税」の表記を削除(暫定) --- .../default/mail_templates/order_mail.tpl | 2 +- .../mobile/mail_templates/order_mail.tpl | 2 +- data/class/SC_Fpdf.php | 37 ++++++++++++++++++- data/class/helper/SC_Helper_TaxRule.php | 22 +++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/data/Smarty/templates/default/mail_templates/order_mail.tpl b/data/Smarty/templates/default/mail_templates/order_mail.tpl index b58cd99a86..5d9d58ae6e 100644 --- a/data/Smarty/templates/default/mail_templates/order_mail.tpl +++ b/data/Smarty/templates/default/mail_templates/order_mail.tpl @@ -56,7 +56,7 @@ ------------------------------------------------- -小 計 ¥ (うち消費税 ¥) +小 計 ¥ 値引き ¥ diff --git a/data/Smarty/templates/mobile/mail_templates/order_mail.tpl b/data/Smarty/templates/mobile/mail_templates/order_mail.tpl index 84de76be3d..ef2806f60a 100644 --- a/data/Smarty/templates/mobile/mail_templates/order_mail.tpl +++ b/data/Smarty/templates/mobile/mail_templates/order_mail.tpl @@ -49,7 +49,7 @@ -小 計 ¥ (うち消費税 ¥) +小 計 ¥ 値引き ¥ diff --git a/data/class/SC_Fpdf.php b/data/class/SC_Fpdf.php index 9a2b57af16..886c328372 100644 --- a/data/class/SC_Fpdf.php +++ b/data/class/SC_Fpdf.php @@ -155,6 +155,11 @@ private function setShopData() //ロゴ画像 $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png'; $this->Image($logo_file, 124, 46, 40); + + if (defined('INVOICE_REGISTRATION_NUM')) { + $text = '登録番号: '.INVOICE_REGISTRATION_NUM; + $this->lfText(125, 87, $text, 8); + } } private function setMessageData() @@ -228,6 +233,8 @@ private function setOrderData() $monetary_unit = '円'; $point_unit = 'Pt'; + $arrTaxableTotal = []; + $defaultTaxRule = SC_Helper_TaxRule_Ex::getTaxRule(); // 購入商品情報 for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) { // 購入数量 @@ -249,9 +256,18 @@ private function setOrderData() $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]'; } } + + // 標準税率より低い税率は軽減税率として※を付与 + if ($this->arrDisp['tax_rate'][$i] < $defaultTaxRule['tax_rate']) { + $arrOrder[$i][0] .= ' ※'; + } $arrOrder[$i][1] = number_format($data[0]); $arrOrder[$i][2] = number_format($data[1]).$monetary_unit; $arrOrder[$i][3] = number_format($data[2]).$monetary_unit; + if (array_key_exists($this->arrDisp['tax_rate'][$i], $arrTaxableTotal) === false) { + $arrTaxableTotal[$this->arrDisp['tax_rate'][$i]] = 0; + } + $arrTaxableTotal[$this->arrDisp['tax_rate'][$i]] += $data[2]; } $arrOrder[$i][0] = ''; @@ -270,18 +286,21 @@ private function setOrderData() $arrOrder[$i][1] = ''; $arrOrder[$i][2] = '送料'; $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit; + $arrTaxableTotal[intval($defaultTaxRule['tax_rate'])] += $this->arrDisp['deliv_fee']; $i++; $arrOrder[$i][0] = ''; $arrOrder[$i][1] = ''; $arrOrder[$i][2] = '手数料'; $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit; + $arrTaxableTotal[intval($defaultTaxRule['tax_rate'])] += $this->arrDisp['charge']; $i++; $arrOrder[$i][0] = ''; $arrOrder[$i][1] = ''; $arrOrder[$i][2] = '値引き'; - $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit; + $discount_total = ($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']; + $arrOrder[$i][3] = '- '.number_format($discount_total).$monetary_unit; $i++; $arrOrder[$i][0] = ''; @@ -311,6 +330,22 @@ private function setOrderData() } $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell); + + $this->SetLineWidth(.3); + $this->SetFont('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->width_cell, function ($n, $w) { + return $n + $w; + }); + $this->SetX(20); + + $message = SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total); + $this->MultiCell($width, 4, $message, 0, 'R', 0, ''); } /** diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index d01b50b54f..d707e5775f 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -62,6 +62,28 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr return SC_Helper_TaxRule_Ex::calcTax($price, $arrTaxRule['tax_rate'], $arrTaxRule['tax_rule'], $arrTaxRule['tax_adjust']); } + /** + * 消費税の内訳を返す. + * + * 値引額合計は税率ごとに按分する. + * + * @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額 + * @param int $discount_total 値引額合計 + */ + public static function getTaxDetail($arrTaxableTotal, $discount_total = 0): string + { + ksort($arrTaxableTotal); + $tax = []; + $taxable_total = array_sum($arrTaxableTotal); + $result = ''; + foreach ($arrTaxableTotal as $rate => $total) { + $tax = round(($total - $discount_total * $total / array_sum($arrTaxableTotal)) * ($rate / (100 + $rate))); + $result .= '('.$rate.'%対象: '.number_format(round($total)).'円 内消費税: '.number_format($tax).'円)'.PHP_EOL; + } + + return $result; + } + /** * 設定情報IDに基づいて税金付与した金額を返す * (受注データのようにルールが決まっている場合用) From 1077a191fdbc56dcb58dd43a060c35c9cf2bfa70 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sun, 3 Sep 2023 23:00:38 +0900 Subject: [PATCH 02/15] Fix reduced total --- data/class/helper/SC_Helper_TaxRule.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index d707e5775f..9ca5d95fc2 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -77,8 +77,9 @@ public static function getTaxDetail($arrTaxableTotal, $discount_total = 0): stri $taxable_total = array_sum($arrTaxableTotal); $result = ''; foreach ($arrTaxableTotal as $rate => $total) { - $tax = round(($total - $discount_total * $total / array_sum($arrTaxableTotal)) * ($rate / (100 + $rate))); - $result .= '('.$rate.'%対象: '.number_format(round($total)).'円 内消費税: '.number_format($tax).'円)'.PHP_EOL; + $reduced_total = $total - $discount_total * $total / array_sum($arrTaxableTotal); + $tax = round($reduced_total * ($rate / (100 + $rate))); + $result .= '('.$rate.'%対象: '.number_format(round($reduced_total)).'円 内消費税: '.number_format($tax).'円)'.PHP_EOL; } return $result; From 9fde0f29659f42fac53f3ef5b31cc0a8a3225c62 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sat, 9 Sep 2023 01:21:54 +0900 Subject: [PATCH 03/15] =?UTF-8?q?=E7=A8=8E=E9=A1=8D=E9=9B=86=E8=A8=88?= =?UTF-8?q?=E3=81=A8=E5=86=85=E8=A8=B3=E5=87=BA=E5=8A=9B=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/class/helper/SC_Helper_TaxRule.php | 38 ++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index 9ca5d95fc2..206d6d34cd 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -65,21 +65,51 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr /** * 消費税の内訳を返す. * + * 税率ごとに以下のような連想配列を返す. + * - total: 値引後の税込み合計金額 + * - tax: 値引後の税額 * 値引額合計は税率ごとに按分する. + * 課税規則は標準税率の設定を使用する. * * @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額 * @param int $discount_total 値引額合計 + * @return array{8?:array{total:int,tax:int}, 10?:array{total:int,tax:int}} */ - public static function getTaxDetail($arrTaxableTotal, $discount_total = 0): string + public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_total = 0): array { + $arrDefaultTaxRule = static::getTaxRule(); + ksort($arrTaxableTotal); $tax = []; $taxable_total = array_sum($arrTaxableTotal); - $result = ''; + $result = []; foreach ($arrTaxableTotal as $rate => $total) { $reduced_total = $total - $discount_total * $total / array_sum($arrTaxableTotal); - $tax = round($reduced_total * ($rate / (100 + $rate))); - $result .= '('.$rate.'%対象: '.number_format(round($reduced_total)).'円 内消費税: '.number_format($tax).'円)'.PHP_EOL; + $tax = $reduced_total * ($rate / (100 + $rate)); + $result[$rate] = [ + 'total' => intval(static::roundByCalcRule($reduced_total, $arrDefaultTaxRule['calc_rule'])), + 'tax' => intval(static::roundByCalcRule($tax, $arrDefaultTaxRule['calc_rule'])), + ]; + } + + return $result; + } + + /** + * 消費税の内訳の文字列を返す. + * + * 複数の税率がある場合は改行で区切る. + * + * @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額 + * @param int $discount_total 値引額合計 + * @return string (<税率>%対象: <値引後税込合計>円 内消費税: <値引後税額>円) + */ + public static function getTaxDetail($arrTaxableTotal, $discount_total = 0): string + { + $arrTaxPerTaxRate = static::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + $result = ''; + foreach ($arrTaxPerTaxRate as $rate => $item) { + $result .= '('.$rate .'%対象: '. number_format($item['total']).'円 内消費税: '.number_format($item['tax']).'円)'.PHP_EOL; } return $result; From 70717b99b71d54a4461fa184bd810ca937b80b49 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sat, 9 Sep 2023 01:22:48 +0900 Subject: [PATCH 04/15] Add unit test --- data/class/helper/SC_Helper_TaxRule.php | 4 +- .../SC_Helper_TaxRule_TestBase.php | 2 +- .../SC_Helper_TaxRule_getTaxDetailTest.php | 159 ++++++++++++++++++ 3 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index 206d6d34cd..44ca75158b 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -75,7 +75,7 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr * @param int $discount_total 値引額合計 * @return array{8?:array{total:int,tax:int}, 10?:array{total:int,tax:int}} */ - public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_total = 0): array + public static function getTaxPerTaxRate(array $arrTaxableTotal, $discount_total = 0) { $arrDefaultTaxRule = static::getTaxRule(); @@ -104,7 +104,7 @@ public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_to * @param int $discount_total 値引額合計 * @return string (<税率>%対象: <値引後税込合計>円 内消費税: <値引後税額>円) */ - public static function getTaxDetail($arrTaxableTotal, $discount_total = 0): string + public static function getTaxDetail($arrTaxableTotal, $discount_total = 0) { $arrTaxPerTaxRate = static::getTaxPerTaxRate($arrTaxableTotal, $discount_total); $result = ''; diff --git a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_TestBase.php b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_TestBase.php index a721eaf5ed..22691105d3 100644 --- a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_TestBase.php +++ b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_TestBase.php @@ -28,7 +28,7 @@ * @author Nobuhiko Kimoto * @version $Id$ */ -class SC_Helper_TaxRule_TestBase extends Common_TestCase +abstract class SC_Helper_TaxRule_TestBase extends Common_TestCase { /** diff --git a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php new file mode 100644 index 0000000000..1f67e12aa7 --- /dev/null +++ b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php @@ -0,0 +1,159 @@ +setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '1', + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 724431, + 8 => 65756, + ]; + $discount_total = 7159; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'total' => 65160, + 'tax' => 4827 + ], + 10 => [ + 'total' => 717868, + 'tax' => 65261 + ] + ], + $actual + ); + + self::assertSame( + '(8%対象: 65,160円 内消費税: 4,827円)'.PHP_EOL. + '(10%対象: 717,868円 内消費税: 65,261円)'.PHP_EOL, + SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total) + ); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGetTaxPerTaxRateWithFloor() + { + self::markTestSkipped('Skip this test because @runInSeparateProcess does not work properly'); + + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '2', // floor + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 724431, + 8 => 65756, + ]; + $discount_total = 7159; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'total' => 65160, + 'tax' => 4826 + ], + 10 => [ + 'total' => 717867, + 'tax' => 65260 + ] + ], + $actual + ); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGetTaxPerTaxRateWithCeil() + { + self::markTestSkipped('Skip this test because @runInSeparateProcess does not work properly'); + + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '3', // ceil + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 724431, + 8 => 65756, + ]; + $discount_total = 7159; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'total' => 65161, + 'tax' => 4827 + ], + 10 => [ + 'total' => 717868, + 'tax' => 65261 + ] + ], + $actual + ); + } + + protected function setUpTaxRule(array $taxs = []) + { + $this->objQuery->delete('dtb_tax_rule'); + foreach ($taxs as $key => $item) { + $this->objQuery->insert('dtb_tax_rule', $item); + } + } +} From c654b7037081deb0f40d0ac78eeb5ac8d0b45b67 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Wed, 13 Sep 2023 22:41:03 +0900 Subject: [PATCH 05/15] =?UTF-8?q?debian-stretch=20=E3=81=8C=20archive=20?= =?UTF-8?q?=E3=81=B8=E7=A7=BB=E5=8B=95=E3=81=97=E3=81=9F=E3=81=9F=E3=82=81?= =?UTF-8?q?=20sources.list=20=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit archive.debian.org は遅いので cloudfront の mirror を使用する --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 3c902a30f7..3e27089bac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ ARG FORCE_YES="--force-yes" RUN if [ ! -d /usr/share/man/man1 ]; then mkdir /usr/share/man/man1; fi RUN if [ ! -d /usr/share/man/man7 ]; then mkdir /usr/share/man/man7; fi +RUN sed -i s,deb.debian.org,cloudfront.debian.net/debian-archive,g /etc/apt/sources.list +RUN sed -i 's,security.debian.org,cloudfront.debian.net/debian-archive,g' /etc/apt/sources.list +RUN sed -i '/stretch-updates/d' /etc/apt/sources.list + # ext-gd: libfreetype6-dev libjpeg62-turbo-dev libpng-dev # ext-pgsql: libpq-dev # ext-zip: libzip-dev zlib1g-dev From 4a12b8bbbb209e795362f0a30ef51e503ec0d3ae Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sat, 16 Sep 2023 23:19:27 +0900 Subject: [PATCH 06/15] Add PHP8.2 --- .github/workflows/dockerbuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index e6cdd862bc..0bc9876d2f 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] steps: - name: downcase REPO From b13489369bf3448b40ddd8df4bdeafe99677497b Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sun, 17 Sep 2023 02:20:21 +0900 Subject: [PATCH 07/15] =?UTF-8?q?build-args=20=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dockerbuild.yml | 14 +++++++++++--- .github/workflows/e2e-tests.yml | 16 ++++++++++++++-- Dockerfile | 17 +++++++++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index e6cdd862bc..cfccdb5d3a 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -32,14 +32,22 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} - echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=" >> ${GITHUB_ENV} echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} + run: | + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f12c5d3442..ffd5659be2 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -109,22 +109,34 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} + run: | + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.4 }} run: | echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v3 diff --git a/Dockerfile b/Dockerfile index 3e27089bac..a5b6a7c8b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,19 @@ FROM php:${TAG} ARG GD_OPTIONS="--with-freetype --with-jpeg" ARG EXT_INSTALL_ARGS="gd zip mysqli pgsql opcache" ARG APCU="apcu" -ARG FORCE_YES="--force-yes" +ARG FORCE_YES="" +ARG APT_REPO="deb.debian.org" +ARG APT_SECURITY_REPO="security.debian.org" + # See https://github.com/debuerreotype/debuerreotype/issues/10 RUN if [ ! -d /usr/share/man/man1 ]; then mkdir /usr/share/man/man1; fi RUN if [ ! -d /usr/share/man/man7 ]; then mkdir /usr/share/man/man7; fi -RUN sed -i s,deb.debian.org,cloudfront.debian.net/debian-archive,g /etc/apt/sources.list -RUN sed -i 's,security.debian.org,cloudfront.debian.net/debian-archive,g' /etc/apt/sources.list -RUN sed -i '/stretch-updates/d' /etc/apt/sources.list +RUN sed -i s,deb.debian.org,${APT_REPO},g /etc/apt/sources.list; +RUN sed -i s,security.debian.org,${APT_SECURITY_REPO},g /etc/apt/sources.list; +RUN sed -i s,httpredir.debian.org,${APT_REPO},g /etc/apt/sources.list; # for jessie +RUN sed -i '/stretch-updates/d' /etc/apt/sources.list # for stretch +RUN sed -i '/jessie-updates/d' /etc/apt/sources.list # for jessie # ext-gd: libfreetype6-dev libjpeg62-turbo-dev libpng-dev # ext-pgsql: libpq-dev @@ -31,7 +36,7 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* RUN docker-php-ext-configure gd ${GD_OPTIONS} && docker-php-ext-install ${EXT_INSTALL_ARGS} -RUN pecl install ${APCU} && docker-php-ext-enable apcu +RUN if [[ ${APCU} ]]; then pecl install ${APCU} && docker-php-ext-enable apcu; fi # composer COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer @@ -68,4 +73,4 @@ COPY composer.lock ${ECCUBE_PREFIX}/composer.lock RUN composer install --no-scripts --no-autoloader --no-dev -d ${ECCUBE_PREFIX} COPY . ${ECCUBE_PREFIX} -RUN composer dumpautoload -o --apcu +RUN composer dumpautoload -o From 9e56bdfa17921408f9b07f3e468be0433217215b Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sun, 17 Sep 2023 02:20:21 +0900 Subject: [PATCH 08/15] =?UTF-8?q?build-args=20=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dockerbuild.yml | 26 ++++++++++++++++++++++---- .github/workflows/e2e-tests.yml | 28 ++++++++++++++++++++++++---- Dockerfile | 17 +++++++++++------ 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index e6cdd862bc..9b07fcb0fe 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -32,26 +32,42 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} - echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=" >> ${GITHUB_ENV} echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} - - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} + run: | + echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} + echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} + echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php >= 7.1 && matrix.php <= 7.3 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.4 }} run: | echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v3 @@ -97,6 +113,8 @@ jobs: GD_OPTIONS=${{ env.GD_OPTIONS }} EXT_INSTALL_ARGS=${{ env.EXT_INSTALL_ARGS }} APCU=${{ env.APCU }} + APT_REPO=${{ env.APT_REPO }} + APT_SECURITY_REPO=${{ env.APT_SECURITY_REPO }} - name: Setup to EC-CUBE env: diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f12c5d3442..27ad0e76c6 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -109,22 +109,42 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} - - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} + echo "APCU=" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + - if: ${{ matrix.php >= 7.1 && matrix.php <= 7.3 }} + run: | + echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} + echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} + echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.4 }} run: | echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v3 @@ -142,7 +162,7 @@ jobs: sudo chown -R 1001:1000 zap sudo chmod -R g+w zap sh -c 'echo "> data/config/config.php' - docker build -t ec-cube2 --build-arg PHP_VERSION_TAG="${PHP_VERSION_TAG}" --build-arg GD_OPTIONS="${GD_OPTIONS}" --build-arg EXT_INSTALL_ARGS="${EXT_INSTALL_ARGS}" --build-arg APCU="${APCU}" . + docker build -t ec-cube2 --build-arg PHP_VERSION_TAG="${PHP_VERSION_TAG}" --build-arg GD_OPTIONS="${GD_OPTIONS}" --build-arg EXT_INSTALL_ARGS="${EXT_INSTALL_ARGS}" --build-arg APCU="${APCU} APT_REPO=${{ env.APT_REPO }} APT_SECURITY_REPO=${{ env.APT_SECURITY_REPO }}" . docker tag ec-cube2 ghcr.io/ec-cube/ec-cube2-php:${PHP_VERSION_TAG}-apache TAG=${PHP_VERSION_TAG}-apache docker-compose up -d diff --git a/Dockerfile b/Dockerfile index 3e27089bac..a5b6a7c8b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,19 @@ FROM php:${TAG} ARG GD_OPTIONS="--with-freetype --with-jpeg" ARG EXT_INSTALL_ARGS="gd zip mysqli pgsql opcache" ARG APCU="apcu" -ARG FORCE_YES="--force-yes" +ARG FORCE_YES="" +ARG APT_REPO="deb.debian.org" +ARG APT_SECURITY_REPO="security.debian.org" + # See https://github.com/debuerreotype/debuerreotype/issues/10 RUN if [ ! -d /usr/share/man/man1 ]; then mkdir /usr/share/man/man1; fi RUN if [ ! -d /usr/share/man/man7 ]; then mkdir /usr/share/man/man7; fi -RUN sed -i s,deb.debian.org,cloudfront.debian.net/debian-archive,g /etc/apt/sources.list -RUN sed -i 's,security.debian.org,cloudfront.debian.net/debian-archive,g' /etc/apt/sources.list -RUN sed -i '/stretch-updates/d' /etc/apt/sources.list +RUN sed -i s,deb.debian.org,${APT_REPO},g /etc/apt/sources.list; +RUN sed -i s,security.debian.org,${APT_SECURITY_REPO},g /etc/apt/sources.list; +RUN sed -i s,httpredir.debian.org,${APT_REPO},g /etc/apt/sources.list; # for jessie +RUN sed -i '/stretch-updates/d' /etc/apt/sources.list # for stretch +RUN sed -i '/jessie-updates/d' /etc/apt/sources.list # for jessie # ext-gd: libfreetype6-dev libjpeg62-turbo-dev libpng-dev # ext-pgsql: libpq-dev @@ -31,7 +36,7 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* RUN docker-php-ext-configure gd ${GD_OPTIONS} && docker-php-ext-install ${EXT_INSTALL_ARGS} -RUN pecl install ${APCU} && docker-php-ext-enable apcu +RUN if [[ ${APCU} ]]; then pecl install ${APCU} && docker-php-ext-enable apcu; fi # composer COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer @@ -68,4 +73,4 @@ COPY composer.lock ${ECCUBE_PREFIX}/composer.lock RUN composer install --no-scripts --no-autoloader --no-dev -d ${ECCUBE_PREFIX} COPY . ${ECCUBE_PREFIX} -RUN composer dumpautoload -o --apcu +RUN composer dumpautoload -o From 0945ae107870fe1ac263c5e2d88953e0c0e945d6 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Sun, 17 Sep 2023 02:20:21 +0900 Subject: [PATCH 09/15] =?UTF-8?q?build-args=20=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dockerbuild.yml | 28 +++++++++++++++++++++++----- .github/workflows/e2e-tests.yml | 30 +++++++++++++++++++++++++----- Dockerfile | 17 +++++++++++------ 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index e6cdd862bc..dd585f1ea7 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] steps: - name: downcase REPO @@ -32,26 +32,42 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} - echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=" >> ${GITHUB_ENV} echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} - - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} + run: | + echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} + echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} + echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} + - if: ${{ matrix.php >= 7.1 && matrix.php <= 7.3 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.4 }} run: | echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v3 @@ -97,6 +113,8 @@ jobs: GD_OPTIONS=${{ env.GD_OPTIONS }} EXT_INSTALL_ARGS=${{ env.EXT_INSTALL_ARGS }} APCU=${{ env.APCU }} + APT_REPO=${{ env.APT_REPO }} + APT_SECURITY_REPO=${{ env.APT_SECURITY_REPO }} - name: Setup to EC-CUBE env: diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f12c5d3442..916cd69865 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -89,7 +89,7 @@ jobs: fail-fast: false matrix: db: [ 'pgsql', 'mysql' ] - php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + php: [ '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] include: - db: mysql dbport: '3306' @@ -109,22 +109,42 @@ jobs: run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql mbstring" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} - if: ${{ matrix.php == 5.5 || matrix.php == 5.6 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} - echo "APCU=apcu-4.0.11" >> ${GITHUB_ENV} - - if: ${{ matrix.php >= 7.0 && matrix.php <= 7.3 }} + echo "APCU=" >> ${GITHUB_ENV} + echo "FORCE_YES=--force-yes" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} + - if: ${{ matrix.php == 7.0 }} run: | echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=cloudfront.debian.net/debian-archive" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=cloudfront.debian.net/debian-archive/debian-security" >> ${GITHUB_ENV} + - if: ${{ matrix.php >= 7.1 && matrix.php <= 7.3 }} + run: | + echo "GD_OPTIONS=--with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include" >> ${GITHUB_ENV} + echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} + echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - if: ${{ matrix.php >= 7.4 }} run: | echo "GD_OPTIONS=--with-freetype --with-jpeg" >> ${GITHUB_ENV} echo "EXT_INSTALL_ARGS=gd zip mysqli pgsql opcache" >> ${GITHUB_ENV} echo "APCU=apcu" >> ${GITHUB_ENV} + echo "FORCE_YES=" >> ${GITHUB_ENV} + echo "APT_REPO=deb.debian.org" >> ${GITHUB_ENV} + echo "APT_SECURITY_REPO=security.debian.org" >> ${GITHUB_ENV} - name: Checkout uses: actions/checkout@v3 @@ -142,7 +162,7 @@ jobs: sudo chown -R 1001:1000 zap sudo chmod -R g+w zap sh -c 'echo "> data/config/config.php' - docker build -t ec-cube2 --build-arg PHP_VERSION_TAG="${PHP_VERSION_TAG}" --build-arg GD_OPTIONS="${GD_OPTIONS}" --build-arg EXT_INSTALL_ARGS="${EXT_INSTALL_ARGS}" --build-arg APCU="${APCU}" . + docker build -t ec-cube2 --build-arg PHP_VERSION_TAG="${PHP_VERSION_TAG}" --build-arg GD_OPTIONS="${GD_OPTIONS}" --build-arg EXT_INSTALL_ARGS="${EXT_INSTALL_ARGS}" --build-arg APCU="${APCU} APT_REPO=${{ env.APT_REPO }} APT_SECURITY_REPO=${{ env.APT_SECURITY_REPO }}" . docker tag ec-cube2 ghcr.io/ec-cube/ec-cube2-php:${PHP_VERSION_TAG}-apache TAG=${PHP_VERSION_TAG}-apache docker-compose up -d diff --git a/Dockerfile b/Dockerfile index 3e27089bac..a5b6a7c8b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,19 @@ FROM php:${TAG} ARG GD_OPTIONS="--with-freetype --with-jpeg" ARG EXT_INSTALL_ARGS="gd zip mysqli pgsql opcache" ARG APCU="apcu" -ARG FORCE_YES="--force-yes" +ARG FORCE_YES="" +ARG APT_REPO="deb.debian.org" +ARG APT_SECURITY_REPO="security.debian.org" + # See https://github.com/debuerreotype/debuerreotype/issues/10 RUN if [ ! -d /usr/share/man/man1 ]; then mkdir /usr/share/man/man1; fi RUN if [ ! -d /usr/share/man/man7 ]; then mkdir /usr/share/man/man7; fi -RUN sed -i s,deb.debian.org,cloudfront.debian.net/debian-archive,g /etc/apt/sources.list -RUN sed -i 's,security.debian.org,cloudfront.debian.net/debian-archive,g' /etc/apt/sources.list -RUN sed -i '/stretch-updates/d' /etc/apt/sources.list +RUN sed -i s,deb.debian.org,${APT_REPO},g /etc/apt/sources.list; +RUN sed -i s,security.debian.org,${APT_SECURITY_REPO},g /etc/apt/sources.list; +RUN sed -i s,httpredir.debian.org,${APT_REPO},g /etc/apt/sources.list; # for jessie +RUN sed -i '/stretch-updates/d' /etc/apt/sources.list # for stretch +RUN sed -i '/jessie-updates/d' /etc/apt/sources.list # for jessie # ext-gd: libfreetype6-dev libjpeg62-turbo-dev libpng-dev # ext-pgsql: libpq-dev @@ -31,7 +36,7 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* RUN docker-php-ext-configure gd ${GD_OPTIONS} && docker-php-ext-install ${EXT_INSTALL_ARGS} -RUN pecl install ${APCU} && docker-php-ext-enable apcu +RUN if [[ ${APCU} ]]; then pecl install ${APCU} && docker-php-ext-enable apcu; fi # composer COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer @@ -68,4 +73,4 @@ COPY composer.lock ${ECCUBE_PREFIX}/composer.lock RUN composer install --no-scripts --no-autoloader --no-dev -d ${ECCUBE_PREFIX} COPY . ${ECCUBE_PREFIX} -RUN composer dumpautoload -o --apcu +RUN composer dumpautoload -o From 988f46c4c761268f47b2a65d7dc88de49e7ceeda Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Wed, 20 Sep 2023 00:06:16 +0900 Subject: [PATCH 10/15] Fix Division by zero on PHP8.0+ --- data/class/helper/SC_Helper_TaxRule.php | 5 ++- .../SC_Helper_TaxRule_getTaxDetailTest.php | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index 44ca75158b..309c5e2f5f 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -84,7 +84,10 @@ public static function getTaxPerTaxRate(array $arrTaxableTotal, $discount_total $taxable_total = array_sum($arrTaxableTotal); $result = []; foreach ($arrTaxableTotal as $rate => $total) { - $reduced_total = $total - $discount_total * $total / array_sum($arrTaxableTotal); + if ($taxable_total > 0) { + $reduced_total = $total - $discount_total * $total / $taxable_total; + } + $tax = $reduced_total * ($rate / (100 + $rate)); $result[$rate] = [ 'total' => intval(static::roundByCalcRule($reduced_total, $arrDefaultTaxRule['calc_rule'])), diff --git a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php index 1f67e12aa7..d0e9112b3a 100644 --- a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php +++ b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php @@ -59,6 +59,51 @@ public function testGetTaxPerTaxRateWithRound() ); } + public function testGetTaxPerTaxRateWithZero() + { + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '1', + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 0, + 8 => 0, + ]; + $discount_total = 0; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'total' => 0, + 'tax' => 0 + ], + 10 => [ + 'total' => 0, + 'tax' => 0 + ] + ], + $actual + ); + + self::assertSame( + '(8%対象: 0円 内消費税: 0円)'.PHP_EOL. + '(10%対象: 0円 内消費税: 0円)'.PHP_EOL, + SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total) + ); + } + /** * @runInSeparateProcess * @preserveGlobalState disabled From f9e1d19269d507a1d61bd47df4a0b8bbb0a6772f Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 23 Jan 2024 14:12:57 +0900 Subject: [PATCH 11/15] Update data/class/helper/SC_Helper_TaxRule.php Co-authored-by: bbkids <58061209+bbkids@users.noreply.github.com> --- data/class/helper/SC_Helper_TaxRule.php | 43 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index 309c5e2f5f..574c9bbd0d 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -66,6 +66,7 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr * 消費税の内訳を返す. * * 税率ごとに以下のような連想配列を返す. + * - discount: 税率毎の値引額 * - total: 値引後の税込み合計金額 * - tax: 値引後の税額 * 値引額合計は税率ごとに按分する. @@ -73,28 +74,52 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr * * @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額 * @param int $discount_total 値引額合計 - * @return array{8?:array{total:int,tax:int}, 10?:array{total:int,tax:int}} + * @return array{8?:array{discount;int,total:int,tax:int}, 10?:array{discount;int,total:int,tax:int}} */ - public static function getTaxPerTaxRate(array $arrTaxableTotal, $discount_total = 0) + public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_total = 0): array { $arrDefaultTaxRule = static::getTaxRule(); ksort($arrTaxableTotal); - $tax = []; + $cf_discount = 0; $taxable_total = array_sum($arrTaxableTotal); + $divide = []; $result = []; + + // 按分後の値引額の合計(8%対象商品の按分後の値引額 + 10%対象商品の按分後の値引額)が実際の値引額より+-1円となる事への対処 + // ①按分した値引き額を四捨五入で丸める foreach ($arrTaxableTotal as $rate => $total) { - if ($taxable_total > 0) { - $reduced_total = $total - $discount_total * $total / $taxable_total; - } + $discount[$rate] = round(($discount_total * $total / $taxable_total),0); + $divide[$rate] = [ + 'discount' => intval($discount[$rate]), + ]; + $cf_discount += $divide[$rate]['discount']; + } + // ②四捨五入したとしても、四捨五入前の値引額がそれぞれ 16.5 + 75.5 の場合 →(四捨五入端数処理)→ 17 + 76 両方繰り上がる。事への対処 + $defaultTaxRule = $arrDefaultTaxRule['calc_rule']; + $diff = $discount_total - $cf_discount; + if($diff > 0) { + $divide[$defaultTaxRule]['discount'] += $diff; + } + elseif($diff < 0){ + $divide[$defaultTaxRule]['discount'] -= $diff; + } + foreach ($arrTaxableTotal as $rate => $total) { + if($rate == $defaultTaxRule){ + $discount[$rate] = $divide[$GTaxRule]['discount']; + } + else{ + $discount[$rate] = round(($discount_total * $total / $taxable_total),0); + } + $reduced_total = $total - $discount[$rate]; $tax = $reduced_total * ($rate / (100 + $rate)); $result[$rate] = [ - 'total' => intval(static::roundByCalcRule($reduced_total, $arrDefaultTaxRule['calc_rule'])), - 'tax' => intval(static::roundByCalcRule($tax, $arrDefaultTaxRule['calc_rule'])), + 'discount' => intval($discount[$rate]), + 'total' => intval($reduced_total), + 'tax' => intval(static::roundByCalcRule($tax, $defaultTaxRule)), ]; } - return $result; } From 29ed7c556e9050bf232a99011f53d7b2f41a17c9 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Wed, 24 Jan 2024 11:29:09 +0900 Subject: [PATCH 12/15] Update data/class/helper/SC_Helper_TaxRule.php Co-authored-by: bbkids <58061209+bbkids@users.noreply.github.com> --- data/class/helper/SC_Helper_TaxRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index 574c9bbd0d..b34217ab5e 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -107,7 +107,7 @@ public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_to foreach ($arrTaxableTotal as $rate => $total) { if($rate == $defaultTaxRule){ - $discount[$rate] = $divide[$GTaxRule]['discount']; + $discount[$rate] = $divide[$defaultTaxRule]['discount']; } else{ $discount[$rate] = round(($discount_total * $total / $taxable_total),0); From 61c481c17e6e0cce3baf99752084bec42f0dcfef Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 29 Jan 2024 22:34:50 +0900 Subject: [PATCH 13/15] Update data/class/SC_Fpdf.php Co-authored-by: bbkids <58061209+bbkids@users.noreply.github.com> --- data/class/SC_Fpdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/class/SC_Fpdf.php b/data/class/SC_Fpdf.php index 886c328372..fb7995fc13 100644 --- a/data/class/SC_Fpdf.php +++ b/data/class/SC_Fpdf.php @@ -345,7 +345,7 @@ private function setOrderData() $this->SetX(20); $message = SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total); - $this->MultiCell($width, 4, $message, 0, 'R', 0, ''); + $this->MultiCell($width, 4, $message, 0, 'R', ''); } /** From ae08724b83e1f1e4f50791803d15f9ffa9c9e977 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 5 Feb 2024 02:02:50 +0900 Subject: [PATCH 14/15] Fix divison by zero and format --- data/class/helper/SC_Helper_TaxRule.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/data/class/helper/SC_Helper_TaxRule.php b/data/class/helper/SC_Helper_TaxRule.php index b34217ab5e..b0b5324097 100644 --- a/data/class/helper/SC_Helper_TaxRule.php +++ b/data/class/helper/SC_Helper_TaxRule.php @@ -76,7 +76,7 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr * @param int $discount_total 値引額合計 * @return array{8?:array{discount;int,total:int,tax:int}, 10?:array{discount;int,total:int,tax:int}} */ - public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_total = 0): array + public static function getTaxPerTaxRate($arrTaxableTotal, $discount_total = 0) { $arrDefaultTaxRule = static::getTaxRule(); @@ -89,28 +89,26 @@ public static function getTaxPerTaxRate(array $arrTaxableTotal, int $discount_to // 按分後の値引額の合計(8%対象商品の按分後の値引額 + 10%対象商品の按分後の値引額)が実際の値引額より+-1円となる事への対処 // ①按分した値引き額を四捨五入で丸める foreach ($arrTaxableTotal as $rate => $total) { - $discount[$rate] = round(($discount_total * $total / $taxable_total),0); - $divide[$rate] = [ + $discount[$rate] = $taxable_total !== 0 ? round(($discount_total * $total / $taxable_total), 0) : 0; + $divide[$rate] = [ 'discount' => intval($discount[$rate]), ]; - $cf_discount += $divide[$rate]['discount']; - } + $cf_discount += $divide[$rate]['discount']; + } // ②四捨五入したとしても、四捨五入前の値引額がそれぞれ 16.5 + 75.5 の場合 →(四捨五入端数処理)→ 17 + 76 両方繰り上がる。事への対処 $defaultTaxRule = $arrDefaultTaxRule['calc_rule']; $diff = $discount_total - $cf_discount; - if($diff > 0) { + if ($diff > 0) { $divide[$defaultTaxRule]['discount'] += $diff; - } - elseif($diff < 0){ + } elseif ($diff < 0) { $divide[$defaultTaxRule]['discount'] -= $diff; } foreach ($arrTaxableTotal as $rate => $total) { - if($rate == $defaultTaxRule){ + if ($rate == $defaultTaxRule) { $discount[$rate] = $divide[$defaultTaxRule]['discount']; - } - else{ - $discount[$rate] = round(($discount_total * $total / $taxable_total),0); + } else { + $discount[$rate] = $taxable_total !== 0 ? round(($discount_total * $total / $taxable_total), 0) : 0; } $reduced_total = $total - $discount[$rate]; $tax = $reduced_total * ($rate / (100 + $rate)); From f99e6c0b3ec807229e6c62d639ddac780366dbce Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 5 Feb 2024 02:03:47 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=E5=86=8D=E7=8F=BE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see https://github.com/EC-CUBE/ec-cube2/pull/762#issuecomment-1897799676 --- .../SC_Helper_TaxRule_getTaxDetailTest.php | 168 +++++++++++++++++- 1 file changed, 166 insertions(+), 2 deletions(-) diff --git a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php index d0e9112b3a..be84e71581 100644 --- a/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php +++ b/tests/class/helper/SC_Helper_TaxRule/SC_Helper_TaxRule_getTaxDetailTest.php @@ -41,10 +41,12 @@ public function testGetTaxPerTaxRateWithRound() self::assertSame( [ 8 => [ + 'discount' => 596, 'total' => 65160, 'tax' => 4827 ], 10 => [ + 'discount' => 6563, 'total' => 717868, 'tax' => 65261 ] @@ -86,10 +88,12 @@ public function testGetTaxPerTaxRateWithZero() self::assertSame( [ 8 => [ + 'discount' => 0, 'total' => 0, 'tax' => 0 ], 10 => [ + 'discount' => 0, 'total' => 0, 'tax' => 0 ] @@ -137,16 +141,20 @@ public function testGetTaxPerTaxRateWithFloor() self::assertSame( [ 8 => [ + 'discount' => 596, 'total' => 65160, 'tax' => 4826 ], 10 => [ - 'total' => 717867, + 'discount' => 6563, + 'total' => 717868, 'tax' => 65260 ] ], $actual ); + + self::assertSame(array_sum($arrTaxableTotal) - $discount_total, $actual[8]['total'] + $actual[10]['total']); } /** @@ -182,16 +190,172 @@ public function testGetTaxPerTaxRateWithCeil() self::assertSame( [ 8 => [ - 'total' => 65161, + 'discount' => 596, + 'total' => 65160, 'tax' => 4827 ], 10 => [ + 'discount' => 6563, 'total' => 717868, 'tax' => 65261 ] ], $actual ); + + self::assertSame(array_sum($arrTaxableTotal) - $discount_total, $actual[8]['total'] + $actual[10]['total']); + } + + /** + * @see https://github.com/EC-CUBE/ec-cube2/pull/762#issuecomment-1897799676 + */ + public function testGetTaxPerTaxRateWithRound2() + { + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '1', + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 1595, + 8 => 7398, + ]; + $discount_total = 92; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'discount' => 76, + 'total' => 7322, + 'tax' => 542 + ], + 10 => [ + 'discount' => 16, + 'total' => 1579, + 'tax' => 144 + ] + ], + $actual + ); + + self::assertSame( + '(8%対象: 7,322円 内消費税: 542円)'.PHP_EOL. + '(10%対象: 1,579円 内消費税: 144円)'.PHP_EOL, + SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total) + ); + + self::assertSame(array_sum($arrTaxableTotal) - $discount_total, $actual[8]['total'] + $actual[10]['total']); + } + + /** + * @see https://github.com/EC-CUBE/ec-cube2/pull/762#issuecomment-1897799676 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGetTaxPerTaxRateWithFloor2() + { + self::markTestSkipped('Skip this test because @runInSeparateProcess does not work properly'); + + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '2', // floor + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 1595, + 8 => 7398, + ]; + $discount_total = 92; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'discount' => 76, + 'total' => 7322, + 'tax' => 542 + ], + 10 => [ + 'discount' => 16, + 'total' => 1579, + 'tax' => 143 + ] + ], + $actual + ); + + self::assertSame(array_sum($arrTaxableTotal) - $discount_total, $actual[8]['total'] + $actual[10]['total']); + } + + /** + * @see https://github.com/EC-CUBE/ec-cube2/pull/762#issuecomment-1897799676 + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGetTaxPerTaxRateWithCeil2() + { + self::markTestSkipped('Skip this test because @runInSeparateProcess does not work properly'); + + $this->setUpTaxRule([ + [ + 'tax_rule_id' => 1004, + 'apply_date' => '2019-10-01 00:00:00', + 'tax_rate' => '10', + 'calc_rule' => '3', // ceil + 'product_id' => '0', + 'product_class_id' => '0', + 'del_flg' => '0', + 'member_id' => 1, + 'create_date' => '2000-01-01 00:00:00', + 'update_date' => '2000-01-01 00:00:00', + ], + ]); + + $arrTaxableTotal = [ + 10 => 1595, + 8 => 7398, + ]; + $discount_total = 92; + + $actual = SC_Helper_TaxRule_Ex::getTaxPerTaxRate($arrTaxableTotal, $discount_total); + self::assertSame( + [ + 8 => [ + 'discount' => 76, + 'total' => 7322, + 'tax' => 543 + ], + 10 => [ + 'discount' => 16, + 'total' => 1579, + 'tax' => 144 + ] + ], + $actual + ); + + self::assertSame(array_sum($arrTaxableTotal) - $discount_total, $actual[8]['total'] + $actual[10]['total']); } protected function setUpTaxRule(array $taxs = [])