Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kurudrive committed May 16, 2024
1 parent ed6e1dc commit 2eb82b8
Showing 1 changed file with 53 additions and 59 deletions.
112 changes: 53 additions & 59 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?php
/*
bill_form_post_value()
bill_form_post_value()
8桁の数字で保存されているデータをUnixタイムスタンプに変換
bill_raw_date()
bill_raw_date()
bill_item_number()
bill_item_price_total()
bill_item_number()
bill_item_price_total()
書類の税抜き合計
bill_total_no_tax()
bill_total_no_tax()
消費税を計算
bill_tax()
消費税を計算
bill_tax()
Chack post type info
bill_get_post_type()
Chack post type info
bill_get_post_type()
bill_get_terms()
bill_get_terms()
/*-------------------------------------------*/


function bill_form_post_value( $post_field, $type = false ) {
$value = '';
global $post;
$value = '';
global $post;
if ( isset( $post_field ) && $post_field ) {
if ( isset( $type ) && $type == 'textarea' ) {
// n2brはフォームにbrがそのまま入ってしまうので入れない
Expand All @@ -35,7 +35,7 @@ function bill_form_post_value( $post_field, $type = false ) {
} elseif ( isset( $post->$post_field ) && $post->$post_field ) {
$value = $post->$post_field;
}
return $value;
return $value;
}


Expand Down Expand Up @@ -73,7 +73,6 @@ function bill_vektor_invoice_unit_plice( $price, $tax_rate, $tax_type ) {
}

return $unit_price;

}

/**
Expand All @@ -84,7 +83,6 @@ function bill_vektor_invoice_total_plice( $unit_price, $count ) {
$total_price = $unit_price * $count;

return $total_price;

}

/**
Expand All @@ -95,7 +93,6 @@ function bill_vektor_invoice_tax_plice( $total_price, $tax_rate ) {
$tax_price = $total_price * $tax_rate;

return $tax_price;

}

/**
Expand All @@ -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 ) {
Expand All @@ -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 ) {
Expand All @@ -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 );
Expand All @@ -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;
Expand All @@ -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'];
}

Expand All @@ -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() {

Expand All @@ -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
/*-------------------------------------------*/
Expand All @@ -314,7 +308,7 @@ function bill_get_post_type() {
/*
-------------------------------------------*/
/*
bill_get_terms()
bill_get_terms()
/*-------------------------------------------*/
function bill_get_terms() {
global $post;
Expand All @@ -337,21 +331,21 @@ 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 );
}
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;
} else {
echo '御中';
}
}
}
}

0 comments on commit 2eb82b8

Please sign in to comment.