最近、同僚の 1 人がオープンソースのスクリプトを請求システムにインストールしました。目的は、顧客のサービスの支払いが遅れた場合に、サービスの次の期日を再計算することです。たとえば、サービスの期限が 2012 年 11 月 20 日で、翌日に停止され、2012 年 11 月 25 日に支払いが行われたとします。このスクリプトは、次の期日を 2012 年 12 月 25 日に更新するはずですが、何らかの理由で (毎月) 日付を 2012 年 12 月 25 日から 2013 年 1 月 25 日に変更しています。
問題は $month 変数の処理方法にあると思いますが、どこに問題があるのか よくわかりません。
function calculate_postpone_due_date($billingcycle)
{
switch($billingcycle)
{
case "Monthly": $months = 1; break;
case "Quarterly": $months = 3; break;
case "Semi-Annually": $months = 6; break;
case "Annually": $months = 12; break;
case "Biennially": $months = 24; break;
case "Triennially": $months = 32; break;
default: $months = 0; break;
}
//we return FALSE for any other billing cycles: "One Time", "Free Account" etc, they are not recurring
if ($months == 0)
return FALSE;
//a bit complex calculation based on day of the month
//exactly like native whmcs logic do
$year = date("Y");
$month = date("m");
$day = date("d");
for ($i=1; $i<=$months; $i++)
{
$month++;
if ($month == 13)
{
$month = 1;
$year++;
}
}
if (checkdate("$month", $day, $year))
{
return "$year-$month-$day";
}
else
{
//getting last day of the month
$last_day = date("t", mktime(0, 0, 0, $month, 1, $year));
return "$year-$month-$last_day";
}
}