Skip to content

Commit

Permalink
Merge pull request #241 from vektor-inc/fix/unit-total
Browse files Browse the repository at this point in the history
単位未入力の場合に合計金額が 0 になる不具合を修正
  • Loading branch information
kurudrive authored May 16, 2024
2 parents 10f5da8 + df12dc6 commit 169bce6
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function bill_vektor_invoice_each_tax( $post ) {
// すべてが埋まっていない行は算出対象外に
if ( ! empty( $bill_item['name'] ) &&
! empty( $bill_item['count'] ) &&
! empty( $bill_item['unit'] ) &&
// ! empty( $bill_item['unit'] ) &&
! empty( $bill_item['price'] ) &&
! empty( $bill_item['tax-rate'] ) &&
! empty( $bill_item['tax-type'] )
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: kurudrive,vektor-inc,rickaddison7634
Tested up to: 6.3
Requires PHP: 7.2
Stable tag: 1.11.2
Stable tag: 1.11.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -13,6 +13,9 @@ GitHub : https://github.com/vektor-inc/BillVektor

== Changelog ==

1.11.3
[ 不具合修正 ] 単位が未入力だと合計金額が 0円になるなる不具合を修正

1.11.2
[ 仕様変更 ] 単位未入力の場合でも数値を表示するように変更
[ 微調整 ] 編集画面での税込 / 税抜及び消費税率の状態を見やすく
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Theme Name: BillVektor
Description:
Author: Vektor,Inc.
Author URI:
Version:1.11.2
Version:1.11.3
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
8 changes: 6 additions & 2 deletions template-parts/doc/table-price.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@
$form_item_tax_rate = $item_tax_rate !== '0%' ? $item_tax_rate : __( '非課税', 'bill-vektor' );

// 対象品目の合計税込金額
$item_total = bill_vektor_invoice_full_plice( $item_price_total, $item_tax_value );
$item_total = bill_vektor_invoice_full_plice( $item_price_total, $item_tax_value );
$item_total_unit = '';
if ( ! empty( $bill_item['unit'] ) ) {
$item_total_unit = $bill_item['unit'];
}
$item_total_print = '¥ ' . number_format( $item_total, $digits );

?>
<td><?php echo esc_html( $bill_item_name ); ?></td>
<td class="text-center" id="bill-item-count-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $item_count ); ?></td>
<td class="text-center"><?php echo esc_html( $bill_item['unit'] ); ?></td>
<td class="text-center"><?php echo esc_html( $item_total_unit ); ?></td>
<td class="price"><?php echo esc_html( $item_price_print ); ?></td>
<td class="price"><?php echo esc_html( $item_price_total_print ); ?></td>
<td class="price"><?php echo esc_html( $form_item_tax_rate ); ?></td>
Expand Down
118 changes: 118 additions & 0 deletions tests/test-invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,122 @@ public function test_bill_vektor_invoice_total_tax() {
}
}

/**
* 合計金額テスト
*/
public function test_bill_vektor_invoice_total_tax__unit() {

print PHP_EOL;
print '------------------------------------' . PHP_EOL;
print 'test_bill_vektor_invoice_total_tax__unit' . PHP_EOL;
print '------------------------------------' . PHP_EOL;
print PHP_EOL;

$post_data = array(
'post_title' => 'test',
'post_content' => 'test',
'post_status' => 'publish',
'post_type' => 'post',
);

$test_array = array(
array(
'test_name' => 'とりあえず動くか確認',
'custom_fields' => array(
'bill_items' => array(
array(
'name' => 'test',
'count' => 1,
'unit' => '',
'price' => 10000,
'tax-rate' => '10%',
'tax-type' => 'tax_excluded',
),
),
'bill_tax_rate' => 10, // old_tax_rate
'bill_tax_type' => 'tax_included', // old_tax_type
'bill_tax_fraction' => 'floor',
),
'expected' => 11000,
),
array(
'test_name' => '単位が空の場合',
'custom_fields' => array(
'bill_items' => array(
array(
'name' => 'test',
'count' => 1,
'unit' => '',
'price' => 10000,
'tax-rate' => '10%',
'tax-type' => 'tax_excluded',
),
),
'bill_tax_fraction' => 'floor',
),
'expected' => 11000,
),
array(
'test_name' => '旧設定で税抜きだが 個別項目で税込み -> 税込みで計算される',
'custom_fields' => array(
'bill_items' => array(
array(
'name' => 'test',
'count' => 1,
'unit' => '',
'price' => 11000,
'tax-rate' => '10%',
'tax-type' => 'tax_included',
),
),
'bill_tax_rate' => 10, // old_tax_rate
'bill_tax_type' => 'tax_excluded', // old_tax_type
'bill_tax_fraction' => 'floor',
),
'expected' => 11000,
),
array(
'test_name' => '10%税込 + 8%税込',
'custom_fields' => array(
'bill_items' => array(
array(
'name' => 'test',
'count' => 1,
'unit' => '',
'price' => 11000,
'tax-rate' => '10%',
'tax-type' => 'tax_included',
),
array(
'name' => 'test',
'count' => 1,
'unit' => '',
'price' => 10800,
'tax-rate' => '8%',
'tax-type' => 'tax_included',
),
),
'bill_tax_fraction' => 'floor',
),
'expected' => 21800,
),

);

foreach ( $test_array as $test_item ) {
$post_id = wp_insert_post( $post_data );
foreach ( $test_item['custom_fields'] as $key => $value ) {
update_post_meta( $post_id, $key, $value );
}
$post = get_post( $post_id );
$actual = bill_vektor_invoice_total_tax( $post );
print PHP_EOL;
print 'test_name :' . $actual . PHP_EOL;
print 'actual :' . $actual . PHP_EOL;
print 'expected :' . $test_item['expected'] . PHP_EOL;
$this->assertEquals( $test_item['expected'], $actual );
wp_delete_post( $post_id, true );
}
}

}

0 comments on commit 169bce6

Please sign in to comment.