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_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); + } + } +}