ขอแนวทางการคิดค่าเสื่อมทรัพย์สินหน่อยครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ขอแนวทางการคิดค่าเสื่อมทรัพย์สินหน่อยครับ

ขอแนวทางการคิดค่าเสื่อมทรัพย์สินหน่อยครับ

ราคาทรัพย์สิน 50000
เรทค่าเสื่อม 20%
วันแรกที่คิดค่าเสื่อมราคา  เช่น ซื้อวันที่ 05/01/22 คิด 31-5+1 เท่ากับ 27 วัน

สูตร(50000*20%)*(27/365) = 739.73

วันสุดท้ายที่คิด เช่น 05/01/22 คิด 5-1 เท่ากับ 4 วัน
สูตร(50000*20%)*(4/365) = 108.59

สามารถหาจำนวนวันที่เหลือ ที่ไม่เต็มเดือนได้อย่างไร
และจะให้มัน Loop หาค่าเสื่อมแต่ละปี แต่ละเดือนให้ถูกยังไงครับผม

ขอแนวทาง และวิธีการทำหน่อยครับพี่นิค ขอบคุณครับ

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
    <title>Document</title>
    <?php
     function DateDiff($strDate1,$strDate2)
     {
                return (strtotime($strDate2) - strtotime($strDate1))/  ( 60 * 60 * 24 );  // 1 day = 60*60*24
     }
     ?>
 
 
</head>
 
<body>
 
 
    <?php
    $start_date = "2022-01-05"; //วันเริ่มคิดค่าเสื่อม
    $end_date = "2027-01-05";//วันสิ้นสุดค่าเสื่อม
    $life_year = 5; //อายุใช้งาน
    $price = 50000; //ราคาทรัพย์สิน
    $rate = 20 / 100; // อัตราค่าเสื่อม 20%;
 
     $totalDay = DateDiff($start_date , $end_date)." วัน";
 
     $totalMonth = round(( $totalDay / 365) *12)." เดือน";
     $totalYear = round( $totalDay / 365)." ปี";
 
     
    $life_end = $life_year+1;
      
    $depreciation=[];
    $depreciation_price_per_year=0
 
    ?>
 
<?php
 
 
 
 
for ($i=1; $i <= $totalYear; $i++) {
    echo "<b>ปีที่ ".$i."<br></b>";
    for ($ii = 1; $ii <= 12; $ii++) { //หาค่าเสื่อมแต่ละเดือน
        if ($ii==1) {
            $date_pass = date_diff(date_create(date('Y-' . $ii . '-t')), date_create($start_date));
            $depreciation_price_per_month = ($price $rate) * ($date_pass->days / 365);
 
        }else{
            $date_pass = date_diff(date_create(date('Y-' . $ii . '-t')), date_create(date('Y-' . ($ii - 1) . '-t')));
            $depreciation_price_per_month = ($price $rate) * ($date_pass->days / 365);
        }
        if( strtotime( date('Y-m' , strtotime($start_date)) )> strtotime(date('Y-' . $ii ))){
            $depreciation_price_per_month = 0;
        }else{
            $depreciation_price_per_year += $depreciation_price_per_month;
 
        }
         echo "ค่าเสื่อม เดือน ".$ii." ".round($depreciation_price_per_month, 2)."<br>";
          
    }
    echo "รวมค่าเสื่อม ".round($depreciation_price_per_year,2)."<br>";
    echo "มูลค่าทรัพย์สิน".round($price-$depreciation_price_per_year,2)."<br>";
 
}
 
                     
         
 
                 
?>
 
 
 
 
 
</body>
 
</html>




 



ิbondsanti 02-10-2022 18:45:23

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ไม่ค่อยเข้าใจในหลักหรือสูตรการคิดค่าเสื่อมทรัพย์สินที่ถูกต้องเท่าไหร่
แต่แนวทางวิธีการคำนวณไม่น่ายากสามารถปรับได้ง่ายถ้าเข้าใจรูปแบบที่ถูกต้อง
 
ลองดูแนวทางเกี่ยวกับการจัดการวันที่เพิ่มเติมเพื่อปรับใช้จาก แนวทางด้านล่าง
รูปแบบการคำนวณค่าเสื่อมทรัพย์สิน อาจจะไม่ถูกต้อง แต่สามารถไปปรับเป็นแนวทางได้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
$start_date = "2022-01-05"; //วันเริ่มคิดค่าเสื่อม
$life_year = 5; //อายุใช้งาน
$end_date = date("Y-m-d",strtotime($start_date."+$life_year year"));
echo $end_date."<br>"; // 2027-01-05
$price = 50000; //ราคาทรัพย์สิน
$rate = 20 / 100; // อัตราค่าเสื่อม 20%;
$originalTime = new DateTimeImmutable($start_date);
$targedTime = new DateTimeImmutable($end_date);
$interval = $originalTime->diff($targedTime);
// var_dump($interval);
echo "<br>";
echo $interval->y."<br>"; // ต่างกี่ปี คิดแบบปฏิทิน
echo $interval->m."<br>"; // ต่างกี่เดือน คิดแบบปฏิทิน
echo $interval->d."<br>"; // ต่างกี่วัน คิดแบบปฏิทิน
echo $interval->days."<br>"; // ต่างกี่วันทั้งหมด
 
$totalDay = $interval->days;
$totalMonth = $interval->y*12 + $interval->m;
$totalYear = $interval->y;
 
$depreciation_price_per_day = ($price $rate) / $totalDay;
echo "ค่าเสื่อมราคาต่อวัน ".$depreciation_price_per_day." บาท/วัน<br>";
 
 
$depreciation_price_per_month = [];
$depreciation_price_per_year = [];
 
 
for($i_month=0;$i_month<=$totalMonth;$i_month++){
  $date_check = date("Y-m-01",strtotime($start_date."+$i_month month"));
  $end_date_check = date("Y-m-t",strtotime($start_date."+$i_month month"));
  $start_date_check = $date_check;
  if($i_month==0){
    $start_date_check = $start_date;
  }
  if($i_month==$totalMonth){
    $end_date_check = $end_date;
  }
  $originalTime_check = new DateTimeImmutable($start_date_check);
  $targedTime_check = new DateTimeImmutable($end_date_check);
  $interval_check = $originalTime_check->diff($targedTime_check);
  $totalDay_check = $interval_check->days+1;
 
  $depreciation_price_per_m = $totalDay_check*$depreciation_price_per_day;
  $depreciation_price_per_month[$date_check] = $depreciation_price_per_m;
 
  if(!isset($depreciation_price_per_year[date("Y",strtotime($date_check))])){
    $depreciation_price_per_year[date("Y",strtotime($date_check))]=0;
  }
  $depreciation_price_per_year[date("Y",strtotime($date_check))]+=$depreciation_price_per_m;
  echo $totalDay_check."-";
  echo $start_date_check."-".$end_date_check."-";
  echo $i_month."<br>";
  echo "ค่าเสื่อมราคาเดือน $i_month - ".$depreciation_price_per_m."<br><hr>";
}
echo "<pre>";
  print_r($depreciation_price_per_month);
  print_r($depreciation_price_per_year);
echo "</pre>";
  $depreciation_price_total = array_sum($depreciation_price_per_year);
  $depreciation_price_m_avg = $depreciation_price_total / $totalMonth;
  $depreciation_price_y_avg = $depreciation_price_total / $totalYear;
  $price_total = $price - $depreciation_price_total;
  echo "ค่าเสื่อมต่อเดือนเฉลี่ย ".$depreciation_price_m_avg."<br><hr>";
  echo "ค่าเสื่อมต่อปีเฉลี่ย ".$depreciation_price_y_avg."<br><hr>";
  echo "ค่าเสื่อมรวม ".$depreciation_price_total."<br><hr>";
  echo "มูลค่าทรัพย์สิน ".$price_total."<br><hr>";
?>


บทความแนะนำที่เกี่ยวข้อง
การใช้งานรูปแบบข้อความวันที่และเวลา กับฟังก์ชั่น strtotime() ใน phpอ่าน 56,343
ninenik 03-10-2022
 ความคิดเห็นที่ 2
ขอบคุณมากครับ พี่นิค
แล้วถ้าผม จะ insert ลง db โดยแบ่งตามปี ในลักษณะแบบตัวอย่างนี้อะครับ ต้อง Loop ยังไงครับ






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Dep</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
    <div class="container">
    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
 
<?php
$start_date = "2022-01-05"; //วันเริ่มคิดค่าเสื่อม
$life_year = 5; //อายุใช้งาน
$end_date = date("Y-m-d",strtotime($start_date."+$life_year year"));
// echo $end_date."<br>"; // 2027-01-05
$price = 50000; //ราคาทรัพย์สิน
$rate = 20 / 100; // อัตราค่าเสื่อม 20%;
$originalTime = new DateTimeImmutable($start_date);
$targedTime = new DateTimeImmutable($end_date);
$interval = $originalTime->diff($targedTime);
// var_dump($interval);
// echo "<br>";
// echo $interval->y."<br>"; // ต่างกี่ปี คิดแบบปฏิทิน
// echo $interval->m."<br>"; // ต่างกี่เดือน คิดแบบปฏิทิน
// echo $interval->d."<br>"; // ต่างกี่วัน คิดแบบปฏิทิน
// echo $interval->days."<br>"; // ต่างกี่วันทั้งหมด
  
$totalDay = $interval->days;
$totalMonth = $interval->y*12 + $interval->m;
$totalYear = $interval->y;
  
// $depreciation_price_per_day = ($price *  $rate) * ($totalDay_check/365);
// echo "ค่าเสื่อมราคาต่อวัน ".$depreciation_price_per_day." บาท/วัน<br>";
  
  
$depreciation_price_per_month = [];
$depreciation_price_per_year = [];
 
  
for($i_month=0;$i_month<=$totalMonth;$i_month++){
  $date_check = date("Y-m-01",strtotime($start_date."+$i_month month"));
  $end_date_check = date("Y-m-t",strtotime($start_date."+$i_month month"));
  $start_date_check = $date_check;
  if($i_month==0){
    $start_date_check = $start_date;
  }
  if($i_month==$totalMonth){
    $end_date_check = $end_date;
  }
  $originalTime_check = new DateTimeImmutable($start_date_check);
  $targedTime_check = new DateTimeImmutable($end_date_check);
  $interval_check = $originalTime_check->diff($targedTime_check);
  $totalDay_check = $interval_check->days+1;
  
  $depreciation_price_per_m = ($price * $rate) * ($totalDay_check/365);
  //$depreciation_price_per_month[$date_check] = $depreciation_price_per_m;
  
  if(!isset($depreciation_price_per_year[date("Y",strtotime($date_check))])){
    $depreciation_price_per_year[date("Y",strtotime($date_check))]=0;
  }
  $depreciation_price_per_month[date("Y",strtotime($date_check))][$i_month]= round($depreciation_price_per_m, 2);
  //$depreciation_price_per_year[date("Y",strtotime($date_check))]+=$depreciation_price_per_m;
  $depreciation_price_per_year[date("Y",strtotime($date_check))] += $depreciation_price_per_m;
  //   echo $totalDay_check."-";
//   echo $start_date_check."-".$end_date_check."-";
//   echo $i_month."<br>";
//   echo "ค่าเสื่อมราคาเดือน $i_month - ".$depreciation_price_per_m."<br><hr>";
 
}
echo "<pre>";
  print_r($depreciation_price_per_month);
  print_r($depreciation_price_per_year);
 
echo "</pre>";
//$depreciation_price_total = array_sum($depreciation_price_per_year);
//   $depreciation_price_m_avg = $depreciation_price_total / $totalMonth;
//   $depreciation_price_y_avg = $depreciation_price_total / $totalYear;
//   $price_total = $price - $depreciation_price_total;
//   echo "ค่าเสื่อมต่อเดือนเฉลี่ย ".$depreciation_price_m_avg."<br><hr>";
//   echo "ค่าเสื่อมต่อปีเฉลี่ย ".$depreciation_price_y_avg."<br><hr>";
//   echo "ค่าเสื่อมรวม ".$depreciation_price_total."<br><hr>";
//   echo "มูลค่าทรัพย์สิน ".$price_total."<br><hr>";
echo '<table class="table table-bordered text-center">';
echo '<thead>
<tr>';
echo '<th>year</th>';
echo '<th>m1</th>';
echo '<th>m2</th>';
echo '<th>m3</th>';
echo '<th>m4</th>';
echo '<th>m5</th>';
echo '<th>m6</th>';
echo '<th>m7</th>';
echo '<th>m8</th>';
echo '<th>m9</th>';
echo '<th>m10</th>';
echo '<th>m11</th>';
echo '<th>m12</th>';
echo '<th>Total depr</th>';
echo '</tr>
</thead>';
 
echo '<tbody>';
foreach ($depreciation_price_per_month as $k_year => $year){
   
    echo '<tr>';
    echo '<td>'.$k_year.'</td>';
 
 
    foreach ($year as $k_month => $value){
         
        echo '<td>'.$value.'</td>';
         
    }
     
 
    
    echo '</tr>';
 
 
}
 
 
echo '</tbody>';
echo '</table>';
 
?>
</div>
</body>
</html>


ิbondsanti 09-10-2022 02:44
 ความคิดเห็นที่ 3
การบันทึกข้อมูล บันทึกแค่วันที่ กับ ค่าเสื่อมของแต่ละเดือน ก็พอ 
date value
2022-01-01 => 147.86418400876
2022-02-01 => 153.34063526835
2022-03-01 => 169.7699890471
2022-04-01 => 164.29353778751
2022-05-01 => 169.7699890471
2022-06-01 => 164.29353778751


ninenik 09-10-2022
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ