简体   繁体   English

PHP获取根据辞职日期自动续订的合同终止日期

[英]PHP get the Date of the Termination of a contract that is renewed automatically based on the Resignation date

I want to program a function that based on the given Date, get the date ($end_date) of the contract termination.我想编写一个基于给定日期的函数,获取合同终止的日期($end_date)。

And the conditions are:条件是:

On the first 3 Months after contract creation we have a grace periode.在合同创建后的前 3 个月,我们有一个宽限期。 So if we receive the contract resignation until 14 days before the end of the first 3 Months, the contract duration will not apply and the termination is valid to the last days of the first 3 months after contract creation.因此,如果我们在前 3 个月结束前 14 天收到合同辞职,合同期限将不适用,终止有效期至合同创建后前 3 个月的最后几天。

If the grace periode is gone the contract duration will apply, so the resignation is only valid if we receive it 6 months before the contract duration ends.如果宽限期结束,合同期限将适用,因此仅当我们在合同期限结束前 6 个月收到辞职才有效。 If the we receive the resignation after 6 months to the end of the contract duration, the contract will be renewed for the same contract duration.如果我们在合同期限结束后 6 个月后收到辞职信,合同将续签相同的合同期限。

I have this information:我有这个信息:

$resignation_date =  date('Y-m-d', strtotime($letter_of_resignation_received_date));

$contract_begin_date = date('Y-m-d', strtotime($contract_begin_date));

$contract_duration= 48; //This means 48 Months

1st. 1日。 condition:健康)状况:

  • If the $resignation_date is till 14 Days before ending the first 3 months after $contract_begin_date如果 $resignation_date 在 $contract_begin_date 之后的前 3 个月结束前 14 天
  • RESULT: The $end_date will be $contract_begin_date + 3 Months ($contract_duration will not apply)结果:$end_date 将为 $contract_begin_date + 3 个月($contract_duration 将不适用)
$grace_periode_date= date('Y-m-d', strtotime($contract_begin_date . ' + 3 months - 14 days'));

if ($resignation_date \< $grace_periode_date ) {
$end_date = date('Y-m-d', strtotime($contract_begin_date . ' + 3 months'));
}
  1. condition:健康)状况:
  • If the $resignation_date is already after 14 Days before ending the first 3 months after $contract_begin_date, $contract_duration will apply.如果 $resignation_date 已经在 $contract_begin_date 之后的前 3 个月结束前 14 天,$contract_duration 将适用。
  • RESULT: The $end_date will be $contract_begin_date + $contract_duration Months结果:$end_date 将为 $contract_begin_date + $contract_duration 月

    if ($resignation_date > $grace_periode_date ) {
      $end_date = date('Y-m-d', strtotime($contract_begin_date . ' + '.$contract_duration.' months'));
    }

  1. condition:健康)状况:
  • If the grace periode is gone and we received the resignation after 6 months before the contract duration ends, The contract is already renewed for the same duration.如果宽限期已经过去,并且我们在合同期限结束前 6 个月后收到辞呈,则合同已经续签了相同的期限。
  • RESULT: The $end_date will be $contract_begin_date + ($contract_duration*2) Months结果:$end_date 将为 $contract_begin_date + ($contract_duration*2) 个月

if ($resignation_date \> $grace_periode_date && $resignation_date \> date('Y-m-d', strtotime($contract_begin_date . ' + '.$contract_duration.' months - 6 months'))) {
$end_date = date('Y-m-d', strtotime($contract_begin_date . ' + '.$contract_duration.' months + '.$contract_duration.' months '));
}

All this is working good.所有这一切都运作良好。 The problem is if the contract is for exemple alerady automatically renewed for 2 times, then the way how im doing this is not the correct way.问题是如果合同例如自动续订 2 次,那么我这样做的方式是不正确的。 Im all the time based on the $contract_begin_date + the new duration.我一直基于 $contract_begin_date + 新的持续时间。

So if the contract is already renews for 2 times the 2nd.因此,如果合同已经续签 2 次,则第二次。 an 3th.第 3 个。 condition will deliver a wrong date.条件将提供错误的日期。 Because I have not the date of the last renew, i have only the contract begin date and the duration of the contract.因为我没有上次续约的日期,所以我只有合同开始日期和合同期限。

How can I get the correct end_date only using the information that I have?如何仅使用我拥有的信息获得正确的结束日期?

You need to calculate the start of the contract period in which you receive contract resignation.您需要计算您收到合同辞职的合同的开始时间。

function getContractPeriodStart($constractStartDate, $contractDurationInMonths, $targetDate)
{
    $periodEnd = strtotime($constractStartDate);
    do {
        $periodStart = $periodEnd;
        $periodEnd   = strtotime(date('Y-m-d', $periodStart) .   
                                 ' +' . $contractDurationInMonths . ' months');
    } while ($periodEnd < strtotime($targetDate));
    $return date('Y-m-d', $periodStart);
}

Here the $targetDate is the date you received the resignation.这里的$targetDate是您收到辞职信的日期。

The idea is simple: Just walk forwards through the contract periods until the end of a period is beyond the date you're interested in.这个想法很简单:只需向前浏览合同期,直到期末超出您感兴趣的日期。

After this you can use the start of the period, instead of the start of the contract for your third condition.在此之后,您可以使用期间的开始,而不是第三个条件的合同开始。

Note : Code is untested and may contain errors.注意:代码未经测试,可能包含错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM