] ; | ] ; | ||||
$deadlinesArray = [ | $deadlinesArray = [ | ||||
24 => 'Minuit', | |||||
23 => '23h', | 23 => '23h', | ||||
22 => '22h', | 22 => '22h', | ||||
21 => '21h', | 21 => '21h', |
return $distributionsArray; | return $distributionsArray; | ||||
} | } | ||||
public static function filterDistributionsByDateDelay($distributionsArray) | |||||
{ | |||||
$producer = GlobalParam::getCurrentProducer() ; | |||||
$dateToday = date('Y-m-d') ; | |||||
foreach($distributionsArray as $keyDistribution => $distribution) { | |||||
$dateDistribution = $distribution->date ; | |||||
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))) ; | |||||
$fieldDayDistributionDelay = 'order_delay_'.$dayDistribution ; | |||||
$fieldDayDistributionDeadline = 'order_deadline_'.$dayDistribution ; | |||||
$delay = $producer->order_delay ; | |||||
$deadline = $producer->order_deadline ; | |||||
if($producer->$fieldDayDistributionDelay) { | |||||
$delay = $producer->$fieldDayDistributionDelay ; | |||||
} | |||||
if($producer->$fieldDayDistributionDeadline) { | |||||
$deadline = $producer->$fieldDayDistributionDeadline ; | |||||
} | |||||
$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60) , 0); | |||||
if(date('H') >= $deadline) { | |||||
$countDaysTodayDistribution -- ; | |||||
} | |||||
if($countDaysTodayDistribution < $delay) { | |||||
unset($distributionsArray[$keyDistribution]) ; | |||||
} | |||||
} | |||||
$newDistributionsArray = [] ; | |||||
foreach($distributionsArray as $distribution) { | |||||
$newDistributionsArray[] = $distribution ; | |||||
} | |||||
return $newDistributionsArray ; | |||||
} | |||||
/** | /** | ||||
* Lie un produit aux jours de distribution futurs. | * Lie un produit aux jours de distribution futurs. | ||||
* | * |
return $userProducer; | return $userProducer; | ||||
} | } | ||||
/** | |||||
* Retourne la date la plus proche où il est possible de commander. | |||||
* Attention, cette méthode ne garantit pas qu'une distribution a été initialisée | |||||
* à cette date. | |||||
* | |||||
* @return string | |||||
*/ | |||||
public function getEarliestDateOrder() | |||||
{ | |||||
$deadline = 20; | |||||
$earliestDateOrder = date('Y-m-d'); | |||||
if ($this->order_deadline) { | |||||
$deadline = $this->order_deadline; | |||||
} | |||||
if (date('H') >= $deadline) { | |||||
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay) * (24 * 60 * 60)); | |||||
} else { | |||||
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay - 1) * (24 * 60 * 60)); | |||||
} | |||||
return $earliestDateOrder; | |||||
} | |||||
/** | /** | ||||
* Retourne le chemin vers le fichier contenant la clé secrète d'API de Payplug | * Retourne le chemin vers le fichier contenant la clé secrète d'API de Payplug | ||||
* | * |
{ | { | ||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); | ||||
$params = [ | $params = [ | ||||
':date_earliest_order' => $producer->getEarliestDateOrder(), | |||||
':date_earliest_order' => date('Y-m-d'), | |||||
':date_begin' => date('Y-m-d', strtotime($this->date_begin)), | ':date_begin' => date('Y-m-d', strtotime($this->date_begin)), | ||||
':id_producer' => GlobalParam::getCurrentProducerId() | ':id_producer' => GlobalParam::getCurrentProducerId() | ||||
]; | ]; | ||||
->where('id_producer = :id_producer') | ->where('id_producer = :id_producer') | ||||
->andWhere('date >= :date_begin') | ->andWhere('date >= :date_begin') | ||||
->andWhere('date >= :date_earliest_order'); | ->andWhere('date >= :date_earliest_order'); | ||||
$incomingDistributions = Distribution::filterDistributionsByDateDelay($incomingDistributions) ; | |||||
if ($this->date_end) { | if ($this->date_end) { | ||||
$incomingDistributions->andWhere('date < :date_end'); | $incomingDistributions->andWhere('date < :date_end'); |
if (isset($order->id_distribution)) { | if (isset($order->id_distribution)) { | ||||
// date de commande | // date de commande | ||||
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one(); | $distribution = Distribution::find()->where(['id' => $order->id_distribution])->one(); | ||||
$date = $this->getProducer()->getEarliestDateOrder(); | |||||
if ($order->getState() != Order::STATE_OPEN) { | if ($order->getState() != Order::STATE_OPEN) { | ||||
$errorDate = true; | $errorDate = true; | ||||
]; | ]; | ||||
// Distributions | // Distributions | ||||
$dateMini = $producer->getEarliestDateOrder(); | |||||
$dateMini = date('Y-m-d') ; | |||||
$distributionsArray = Distribution::searchAll([ | $distributionsArray = Distribution::searchAll([ | ||||
'active' => 1 | 'active' => 1 | ||||
'conditions' => ['date > :date'], | 'conditions' => ['date > :date'], | ||||
'params' => [':date' => $dateMini], | 'params' => [':date' => $dateMini], | ||||
]); | ]); | ||||
$distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray) ; | |||||
$json['distributions'] = $distributionsArray; | $json['distributions'] = $distributionsArray; | ||||
// Commandes de l'utilisateur | // Commandes de l'utilisateur |
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | ||||
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | ||||
}) ; | }) ; | ||||
} | } | ||||
} | } | ||||
var orders = [] ; | var orders = [] ; | ||||
} | } | ||||
if(orders.length) { | if(orders.length) { | ||||
for(var i= 0; i < orders.length; i++) { | for(var i= 0; i < orders.length; i++) { | ||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
backgroundColor: '#FF7F00' | |||||
}, | |||||
contentStyle: { | |||||
color: 'white' | |||||
}, | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total), | |||||
hideIndicator: true | |||||
}, | |||||
dates: orders[i].date_distribution, | |||||
}) ; | |||||
arrayDate = orders[i].date_distribution.split('-') ; | |||||
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) ; | |||||
if(app.isAvailableDate(dateOrder)) { | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
backgroundColor: '#FF7F00' | |||||
}, | |||||
contentStyle: { | |||||
color: 'white' | |||||
}, | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total), | |||||
hideIndicator: true | |||||
}, | |||||
dates: orders[i].date_distribution, | |||||
}) ; | |||||
} | |||||
} | } | ||||
} | } | ||||
return true ; | return true ; | ||||
} | } | ||||
} | } | ||||
return false ; | return false ; | ||||
}, | }, | ||||
pointSaleClick: function(event) { | pointSaleClick: function(event) { |