Files
thetool/application/Cpeprovisioning/CpeprovisioningController.php
2021-10-14 22:21:10 +02:00

62 lines
1.7 KiB
PHP

<?php
class CpeprovisioningController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
if(!$me->is(["Admin", "salespartner"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction() {
$this->layout()->setTemplate("Cpeprovisioning/Index");
$cpeproducts = [];
/*
* Get orderproducts in need of sending CPE
*/
$orders = OrderModel::search(["finish_date" => null]);
foreach($orders as $order) {
if($order->finish_after) {
// show at most 4 weeks before finish_after date
$after_ts = Layout::dateToInt($order->finish_after);
if($after_ts > date("U") + (31 * 86400)) {
$this->log->debug("Before 4 weeks before finish_after oid ".$order->id);
continue;
}
}
foreach($order->products as $orderproduct) {
$product = $orderproduct->product;
if(is_array($product->attributes) && count($product->attributes)) {
// filter out products without bras_type
if(array_key_exists("bras_type", $product->attributes) && $product->attributes['bras_type']->value) {
$cpeproducts[] = $orderproduct;
} else {
$this->log->debug("no bras_type oid ".$order->id);
continue;
}
} else {
// ignore products without attributes
$this->log->debug("no attributes oid ".$order->id);
continue;
}
}
}
//var_dump($cpeproducts);exit;
$this->layout()->set("products", $cpeproducts);
}
}