php每30天计算一次滞纳金

时间:2013-11-02 06:19:45

标签: php

好的,我想知道如何每30天从我的数据库中添加1.5%的总数。如果我今天的余额是600美元而且我没有在30天内支付,它增加了1.5%,但是如果我不在60天内支付,它会在前30天的滞纳金上加1.5%。这就是我的......

if($ invoicedate< =“$ 30_date”){$ late =(1.5 / 100)* $ total; }

所以我拉了创建发票的日期,检查是否是30天或更长时间,如果是,请计算正确的“新”总计为$ late。无论多长时间,我每30天怎么做?我真的必须定义$ 60_date,$ 90_date等?

2 个答案:

答案 0 :(得分:0)

每次编程时,如果您认为需要以某种方式重复变量,那么您真正需要做的就是使用循环。

假设$ invoicedate是一个时间戳,也假设你想要每月收费,而不是30天后收费:

$lateMonths = 1;
$late = $total;
while ($invoicedate <= strtotime(date('Y-m-d') . ' - '.$lateMonths . 'month')){
    $late = 101.5 * $late;
}

答案 1 :(得分:0)

你能试试吗?

 $invoicedate = strtotime("2013/09/01");
 $TodayDate = strtotime('today');

 $timeDiff = abs($TodayDate - $invoicedate);

 $numberDays = $timeDiff/86400;  // 86400 seconds in one day

 $numberDays = intval($numberDays);

 $noOfdaysToCheck ="30";

 $total ="1000";

 if ($numberDays >= $noOfdaysToCheck){$late = (1.5 / 100) * $total; }

每30天费用计算:请更新我,这是您预期的吗?

       $invoicedate = strtotime("2013/07/01");
       $TodayDate = strtotime('today');

       $timeDiff = abs($TodayDate - $invoicedate);

       $numberDays = $timeDiff/86400;  // 86400 seconds in one day

       $numberDays = intval($numberDays);

       $noOfdaysToCheck ="30";

       $Fees ="600";

       if ($numberDays >= $noOfdaysToCheck){

              $Interval = $numberDays%$noOfdaysToCheck;

              for($i=1;$i<=$Interval;$i++){
                     $late = (1.5 / 100) * $Fees;
                     $Fees =  FeesCalc($Fees);

               }
        }

       $Fees = number_format($Fees, 2, '.', '');
       echo $Fees;

       function FeesCalc($Fees){
            $late = (1.5 / 100) * $Fees;
            return $TotalFees = $late+$Fees;

       }