modif date calcul method to include we and check if the last day is a business day
This commit is contained in:
parent
6e14b286c2
commit
f4f144057d
@ -46,6 +46,17 @@ if(!class_exists('BusinessDaysCalculator')) {
|
||||
}
|
||||
}
|
||||
|
||||
public function addDaysWithCheckLastDay($howManyDays) {
|
||||
$i = 0;
|
||||
while ($i < $howManyDays) {
|
||||
$this->date->modify("+1 day");
|
||||
$i++;
|
||||
}
|
||||
if (!$this->isBusinessDay($this->date)) {
|
||||
$this->date->modify("+1 day");
|
||||
}
|
||||
}
|
||||
|
||||
public function getDate() {
|
||||
return $this->date;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ if (!class_exists('SaleDelay')) {
|
||||
return $products_final;
|
||||
}
|
||||
|
||||
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null)
|
||||
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null, $include_we =false)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$date_calcul) {
|
||||
@ -62,28 +62,38 @@ if (!class_exists('SaleDelay')) {
|
||||
foreach ($delays as $key => $delay) {
|
||||
if (!in_array($delay, array_keys($delivery_date))) {
|
||||
$delivery_date[$delay] = self::getDayDelay($delay, $cookie->id_lang);
|
||||
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul);
|
||||
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul, $include_we);
|
||||
|
||||
// exception noel
|
||||
if ($delay == 5) {
|
||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul);
|
||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul, $include_we);
|
||||
} else {
|
||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul);
|
||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul, $include_we);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $delivery_date;
|
||||
}
|
||||
|
||||
public static function getDateWithDelay($nb_day, $date)
|
||||
public static function getDateWithDelay($nb_day, $date, $include_we = false)
|
||||
{
|
||||
$calculator = new BusinessDaysCalculator(
|
||||
new DateTime($date->format('Y-m-d H:i:s')),
|
||||
array(),
|
||||
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
|
||||
);
|
||||
|
||||
$calculator->addBusinessDays($nb_day);
|
||||
if ($include_we) {
|
||||
$calculator = new BusinessDaysCalculator(
|
||||
new DateTime($date->format('Y-m-d H:i:s')),
|
||||
array(),
|
||||
[BusinessDaysCalculator::SUNDAY]
|
||||
);
|
||||
$calculator->addDaysWithCheckLastDay($nb_day);
|
||||
} else {
|
||||
$calculator = new BusinessDaysCalculator(
|
||||
new DateTime($date->format('Y-m-d H:i:s')),
|
||||
array(),
|
||||
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
|
||||
);
|
||||
$calculator->addBusinessDays($nb_day);
|
||||
}
|
||||
|
||||
return $calculator->getDate();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ProductController extends ProductControllerCore {
|
||||
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
|
||||
}
|
||||
$date = new DateTime();
|
||||
$delivery_date = SaleDelay::getDeliveryDate(array($sale->delivery_delay), null, $date);
|
||||
$delivery_date = SaleDelay::getDeliveryDate(array($sale->delivery_delay), null, $date, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,10 +484,16 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
</div>
|
||||
{if isset($delivery_date)}
|
||||
<div class="delivery-delay-estimation">
|
||||
{foreach from=$delivery_date item=date}
|
||||
{foreach from=$delivery_date key=key item=date}
|
||||
{if $key == 1}
|
||||
<p>
|
||||
<b>{$date.name}</b> : {l s='Date de réception prévue entre le'} <strong>{$date.date_start|date_format:'%d/%m/%Y'}</strong> {l s='et le'} <strong>{$date.date_end|date_format:'%d/%m/%Y'}</strong>
|
||||
</p>
|
||||
{elseif $key == 5}
|
||||
<p>
|
||||
<b>{$date.name}</b> : {l s='Livraison prévue avant le'} <strong>{l s='24/12'}</strong>
|
||||
</p>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
|
Loading…
Reference in New Issue
Block a user