diff --git a/inc/template-tags.php b/inc/template-tags.php index e06e6b0..2891306 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -1,30 +1,30 @@ $post_field ) && $post->$post_field ) { $value = $post->$post_field; } - return $value; + return $value; } @@ -73,7 +73,6 @@ function bill_vektor_invoice_unit_plice( $price, $tax_rate, $tax_type ) { } return $unit_price; - } /** @@ -84,7 +83,6 @@ function bill_vektor_invoice_total_plice( $unit_price, $count ) { $total_price = $unit_price * $count; return $total_price; - } /** @@ -95,7 +93,6 @@ function bill_vektor_invoice_tax_plice( $total_price, $tax_rate ) { $tax_price = $total_price * $tax_rate; return $tax_price; - } /** @@ -106,16 +103,15 @@ function bill_vektor_invoice_full_plice( $total_price, $tax_price ) { $full_price = $total_price + $tax_price; return $full_price; - } /** * 消費税率を処理 - * + * * @param string $tax_rate 現在設定されている税率 - * @param int $old_tax_rate 過去に設定された全項目一括指定の税率 + * @param int $old_tax_rate 過去に設定された全項目一括指定の税率 * @param string $post_date 投稿日時 - * + * * @return string $tax_rate 税率 */ function bill_vektor_fix_tax_rate( $old_tax_rate, $post_date ) { @@ -139,10 +135,10 @@ function bill_vektor_fix_tax_rate( $old_tax_rate, $post_date ) { /** * 税込・税抜を処理 - * + * * @param string $tax_type 現在設定されている税込・税抜 * @param string $old_tax_type 過去に設定された税込・税抜 - * + * * @return string $tax_type 税込・税抜 */ function bill_vektor_fix_tax_type( $old_tax_type ) { @@ -163,7 +159,7 @@ function bill_vektor_invoice_each_tax( $post ) { // 消費税率の配列 $tax_array = bill_vektor_tax_array(); // 税率ごとに税込み金額・消費税額・合計金額を算出した配列を初期化 - $tax_total = array(); + $tax_total = array(); $final_tax_total = array(); // 古い消費税率 $old_tax_rate = get_post_meta( $post->ID, 'bill_tax_rate', true ); @@ -187,71 +183,69 @@ function bill_vektor_invoice_each_tax( $post ) { } // すべてが埋まっていない行は算出対象外に - if ( - ! empty( $bill_item['name'] ) && + if ( ! empty( $bill_item['name'] ) && ! empty( $bill_item['count'] ) && ! empty( $bill_item['unit'] ) && ! empty( $bill_item['price'] ) && ! empty( $bill_item['tax-rate'] ) && - ! empty( $bill_item['tax-type'] ) + ! empty( $bill_item['tax-type'] ) ) { // 税率ごとのループ - foreach( $tax_array as $tax_rate ) { + foreach ( $tax_array as $tax_rate ) { // 税率のループとカスタムフィールドのループが同じ値の場合 if ( $bill_item['tax-rate'] === $tax_rate ) { // 税率を数値に変換 - $item_tax_rate = 0.01 * intval( str_replace( '%', '', $bill_item['tax-rate'] ) ); + $item_tax_rate = 0.01 * intval( str_replace( '%', '', $bill_item['tax-rate'] ) ); // 単価を数値に変換 $item_price = bill_vektor_invoice_unit_plice( bill_item_number( $bill_item['price'] ), $item_tax_rate, $bill_item['tax-type'] ); - - // 個数を数値に変換 + + // 個数を数値に変換 $item_count = bill_item_number( $bill_item['count'] ); // 上記3つが数値なら if ( is_numeric( $item_count ) && is_numeric( $item_price ) && is_numeric( $item_tax_rate ) ) { // 合計金額を算出 - $item_total = bill_vektor_invoice_total_plice( $item_price, $item_count ); + $item_total = bill_vektor_invoice_total_plice( $item_price, $item_count ); // 品目ごとの消費税額 $item_tax_value = bill_vektor_invoice_tax_plice( $item_total, $item_tax_rate ); // 品目ごとの税込合計金額 $item_tax_total = bill_vektor_invoice_full_plice( $item_total, $item_tax_value ); // 税率何%の対象か - $tax_total[$tax_rate]['rate'] = $bill_item['tax-rate'] . '対象'; + $tax_total[ $tax_rate ]['rate'] = $bill_item['tax-rate'] . '対象'; // 対象税率の税抜き合計金額 - $tax_total[$tax_rate]['price'] = ! empty( $tax_total[$tax_rate]['price'] ) ? $tax_total[$tax_rate]['price'] + $item_total : $item_total; + $tax_total[ $tax_rate ]['price'] = ! empty( $tax_total[ $tax_rate ]['price'] ) ? $tax_total[ $tax_rate ]['price'] + $item_total : $item_total; // 対象税率の消費税額 - $tax_total[$tax_rate]['tax'] = ! empty( $tax_total[$tax_rate]['tax'] ) ? $tax_total[$tax_rate]['tax'] + $item_tax_value : $item_tax_value; + $tax_total[ $tax_rate ]['tax'] = ! empty( $tax_total[ $tax_rate ]['tax'] ) ? $tax_total[ $tax_rate ]['tax'] + $item_tax_value : $item_tax_value; } } } } } // 出来上がった配列の消費税と合計金額を調整 - foreach( $tax_total as $tax_key => $tax_value ) { + foreach ( $tax_total as $tax_key => $tax_value ) { // 消費税の丸め処理 // $tax_fraction には floor, round, ceil のいずれかが入っているので call_user_func でその関数を直接呼び出している - $tax_total[$tax_key]['tax'] = call_user_func( $tax_fraction, $tax_value['tax'] ); + $tax_total[ $tax_key ]['tax'] = call_user_func( $tax_fraction, $tax_value['tax'] ); // 税抜金額と消費税から税込み金額を算出 - $tax_total[$tax_key]['total'] = $tax_value['price'] + $tax_total[$tax_key]['tax']; + $tax_total[ $tax_key ]['total'] = $tax_value['price'] + $tax_total[ $tax_key ]['tax']; } // 税率の高い順に一応並び替え - foreach( $tax_array as $tax_rate ) { - if ( - ! empty ( $tax_total[$tax_rate]['rate'] ) && - ! empty ( $tax_total[$tax_rate]['price'] ) && - ! empty ( $tax_total[$tax_rate]['tax'] || 0.0 === $tax_total[$tax_rate]['tax'] ) && - ! empty ( $tax_total[$tax_rate]['total'] ) && - $tax_rate . '対象' === $tax_total[$tax_rate]['rate'] + foreach ( $tax_array as $tax_rate ) { + if ( ! empty( $tax_total[ $tax_rate ]['rate'] ) && + ! empty( $tax_total[ $tax_rate ]['price'] ) && + ! empty( $tax_total[ $tax_rate ]['tax'] || 0.0 === $tax_total[ $tax_rate ]['tax'] ) && + ! empty( $tax_total[ $tax_rate ]['total'] ) && + $tax_rate . '対象' === $tax_total[ $tax_rate ]['rate'] ) { - $final_tax_total[$tax_rate]['rate'] = $tax_total[$tax_rate]['rate']; - $final_tax_total[$tax_rate]['price'] = $tax_total[$tax_rate]['price']; - $final_tax_total[$tax_rate]['tax'] = $tax_total[$tax_rate]['tax']; - $final_tax_total[$tax_rate]['total'] = $tax_total[$tax_rate]['total']; + $final_tax_total[ $tax_rate ]['rate'] = $tax_total[ $tax_rate ]['rate']; + $final_tax_total[ $tax_rate ]['price'] = $tax_total[ $tax_rate ]['price']; + $final_tax_total[ $tax_rate ]['tax'] = $tax_total[ $tax_rate ]['tax']; + $final_tax_total[ $tax_rate ]['total'] = $tax_total[ $tax_rate ]['total']; } } $tax_total = $final_tax_total; @@ -267,8 +261,8 @@ function bill_vektor_invoice_total_tax( $post ) { $total_array = bill_vektor_invoice_each_tax( $post ); $bill_total = 0; - foreach( $total_array as $tax_value ) { - //var_dump($tax_value); + foreach ( $total_array as $tax_value ) { + // var_dump($tax_value); $bill_total = $bill_total + $tax_value['total']; } @@ -277,7 +271,7 @@ function bill_vektor_invoice_total_tax( $post ) { /* Chack post type info - bill_get_post_type() + bill_get_post_type() /*-------------------------------------------*/ function bill_get_post_type() { @@ -297,9 +291,9 @@ function bill_get_post_type() { $post_type['slug'] = 'post'; } - if( !post_type_exists( $post_type['slug'] ) ) { - $post_type['slug'] = "post"; - } + if ( ! post_type_exists( $post_type['slug'] ) ) { + $post_type['slug'] = 'post'; + } // Get post type name /*-------------------------------------------*/ @@ -314,7 +308,7 @@ function bill_get_post_type() { /* -------------------------------------------*/ /* - bill_get_terms() + bill_get_terms() /*-------------------------------------------*/ function bill_get_terms() { global $post; @@ -337,7 +331,7 @@ function bill_get_terms() { } function bill_get_client_name( $post ) { - if ( $post->bill_client_name_manual ){ + if ( $post->bill_client_name_manual ) { $client_name = $post->bill_client_name_manual; } else { $client_name = get_the_title( $post->bill_client ); @@ -345,8 +339,8 @@ function bill_get_client_name( $post ) { return $client_name; } -function bill_get_client_honorific( $post ){ - if ( empty( $post->bill_client_name_manual ) ){ +function bill_get_client_honorific( $post ) { + if ( empty( $post->bill_client_name_manual ) ) { $client_honorific = esc_html( get_post_meta( $post->bill_client, 'client_honorific', true ) ); if ( $client_honorific ) { echo $client_honorific; @@ -354,4 +348,4 @@ function bill_get_client_honorific( $post ){ echo '御中'; } } -} \ No newline at end of file +}