Example #1
0
 /**
  * Generate new delivery dates and boxes for each date
  */
 public function actionCreateFutureDeliveryDatesAndBoxes()
 {
     $weeksInAdvance = SnapUtil::config('boxomatic/autoCreateDeliveryDates');
     $latestDate = DeliveryDate::getLastEnteredDate();
     if ($latestDate) {
         $latestDate = strtotime($latestDate->date);
     } else {
         $latestDate = time();
     }
     $targetDate = strtotime('+' . $weeksInAdvance . ' weeks');
     $BoxSizes = BoxSize::model()->findAll();
     while ($latestDate <= $targetDate) {
         //			$dateStr = date('j-n-Y',$latestDate);
         //			$parts = explode('-',$dateStr);
         //			mktime(0,0,0,$parts[1],$parts[0],$parts[2]);
         foreach (SnapUtil::config('boxomatic/deliveryDateLocations') as $day => $locationIds) {
             if (!empty($locationIds)) {
                 $latestDate = strtotime('next ' . $day, $latestDate);
                 //var_dump(date('l, d-m-Y',$latestDate));
                 //$latestDateStr=date('Y-m-d',$latestDate);
                 //$latestDate=strtotime($latestDateStr . ' +1 week');
                 $newDateStr = date('Y-m-d', $latestDate);
                 $DeliveryDate = new DeliveryDate();
                 $DeliveryDate->date = $newDateStr;
                 $DeliveryDate->Locations = $locationIds;
                 $DeliveryDate->save();
                 foreach ($BoxSizes as $BoxSize) {
                     $Box = new Box();
                     $Box->size_id = $BoxSize->id;
                     $Box->box_price = $BoxSize->box_size_price;
                     $Box->delivery_date_id = $DeliveryDate->id;
                     $Box->save();
                 }
                 echo '<p>Created new delivery_date: ' . $DeliveryDate->date . '</p>';
             }
         }
     }
     echo '<p><strong>Finished.</strong></p>';
     Yii::app()->end();
 }
Example #2
0
 public function getFutureDeliveryDates()
 {
     $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
     $dayOfWeek = date('N', strtotime($this->date)) + 1;
     if ($dayOfWeek == 8) {
         $dayOfWeek = 1;
     }
     $DeliveryDates = DeliveryDate::model()->findAll("date_sub(date, interval {$deadlineDays} day) > NOW() AND DAYOFWEEK(date) = '" . $dayOfWeek . "'");
     return CHtml::listData($DeliveryDates, 'date', 'formatted_date');
 }
 /**
  * 
  */
 public function actionUserBoxes($date = null)
 {
     $DeliveryDates = DeliveryDate::model()->findAll();
     if (!$date) {
         $date = DeliveryDate::getCurrentDeliveryDateId();
     }
     $CDD = new Order('search');
     $CDD->unsetAttributes();
     if (isset($_GET['Order'])) {
         $CDD->attributes = $_GET['Order'];
     }
     $CDDsWithExtras = $CDD->extrasSearch($date);
     $SelectedDeliveryDate = DeliveryDate::model()->findByPk($date);
     $UserBoxes = new UserBox('search');
     $UserBoxes->unsetAttributes();
     // clear any default values
     if (isset($_GET['UserBox'])) {
         $UserBoxes->attributes = $_GET['UserBox'];
     }
     $this->render('user_boxes', array('SelectedDeliveryDate' => $SelectedDeliveryDate, 'DeliveryDates' => $DeliveryDates, 'UserBoxes' => $UserBoxes, 'CDDsWithExtras' => $CDDsWithExtras, 'CDD' => $CDD));
 }
Example #4
0
 /**
  * WARNING - This function assumes that the date_id is always in sync with the "date" in delivery_dates table (in regards to order)
  */
 public function getDeliveryDates($combined = false)
 {
     $ddIds = array_keys($this->_SupplierProduct);
     $ddIds = array_merge($ddIds, array_keys($this->_UserBox));
     if ($combined) {
         $ddIds = array_merge($ddIds, array_keys($this->_SupplierProduct_Before));
         $ddIds = array_merge($ddIds, array_keys($this->_UserBox_Before));
     }
     sort($ddIds);
     $DDs = array();
     foreach ($ddIds as $id) {
         $DDs[$id] = DeliveryDate::model()->findByPk($id);
     }
     return $DDs;
 }
Example #5
0
					<div class="row">
						<div class="large-4 columns">
							<?php 
echo CHtml::label('Order in advance for', 'months_advance');
?>
							<?php 
echo CHtml::dropDownList('months_advance', 1, array(1 => '1 Month', 3 => '3 Months', 6 => '6 Months'));
?>
						</div>
						<div class="large-4 columns">
							<?php 
echo CHtml::label('Starting from', 'starting_from');
?>
							<?php 
echo CHtml::dropDownList('starting_from', 1, DeliveryDate::getFutureDeliveryDates());
?>
							
						</div>
						<div class="large-4 columns">
							<?php 
echo CHtml::label('Every', 'every');
?>
							<?php 
echo CHtml::dropDownList('every', 1, array('week' => 'week', 'fortnight' => 'fortnight'));
?>
						</div>
					</div>

					<div class="row">
						<div class="large-12 columns">
Example #6
0
<?php

Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/customerbox/_form.js', CClientScript::POS_END);
?>
<div class="form">
<?php 
$form = $this->beginWidget('application.widgets.SnapActiveForm', array('id' => 'customer-box-form', 'enableAjaxValidation' => false));
?>

	<?php 
echo $form->errorSummary($model);
?>

	<?php 
$this->widget('bootstrap.widgets.BsGridView', array('id' => 'box-sizes-grid', 'dataProvider' => $Boxes->search(), 'filter' => $Boxes, 'summaryText' => '', 'selectionChanged' => 'selectBox', 'enablePagination' => false, 'enableSorting' => false, 'columns' => array(array('name' => 'size_id', 'value' => '$data->BoxSize->box_size_name', 'filter' => CHtml::listData(BoxSize::model()->findAll(), 'id', 'box_size_name')), array('name' => 'box_price', 'filter' => CHtml::listData(Boxes::model()->findAll(array('order' => 'box_price')), 'box_price', 'box_price')), array('name' => 'delivery_date_id', 'value' => 'Yii::app()->dateFormatter->format("EEE, MMM d",$data->DeliveryDate->date)', 'filter' => CHtml::listData(DeliveryDate::model()->findAll(array('order' => 'date')), 'id', 'date')))));
?>
	
	<div class="row quantity">
		<?php 
echo $form->labelEx($model, 'quantity');
?>
		<?php 
echo $form->textField($model, 'quantity', array('class' => 'number'));
?>
		<?php 
echo $form->error($model, 'quantity');
?>
	</div>
	
	<div id="selected-box">
		<?php 
 /**
  * Manages all models.
  */
 public function actionOrder($show = 4)
 {
     $model = new UserBox();
     $Customer = Customer::model()->findByPk(Yii::app()->user->user_id);
     $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
     if (isset($_GET['all'])) {
         $DeliveryDates = DeliveryDate::model()->findAll();
     } else {
         $DeliveryDates = DeliveryDate::model()->with('Boxes')->findAll(array('condition' => 'date_sub(date, interval -1 week) > NOW()', 'limit' => $show + 1));
     }
     $BoxSizes = BoxSize::model()->findAll(array('order' => 'box_size_name DESC'));
     if (isset($_POST['btn_recurring'])) {
         $monthsAdvance = (int) $_POST['months_advance'];
         $startingFrom = $_POST['starting_from'];
         $every = $_POST['every'];
         $locationId = $_POST['Customer']['delivery_location_key'];
         $custLocationId = new CDbExpression('NULL');
         if (strpos($locationId, '-')) {
             //has a customer location
             $parts = explode('-', $locationId);
             $locationId = $parts[1];
             $custLocationId = $parts[0];
         }
         $Location = Location::model()->findByPk($locationId);
         foreach ($_POST['Recurring'] as $key => $quantity) {
             $boxSizeId = str_replace('bs_', '', $key);
             $Boxes = Box::model()->with('DeliveryDate')->findAll("\n\t\t\t\t\tdate >= '{$startingFrom}' AND\n\t\t\t\t\tdate <=  date_add('{$startingFrom}', interval {$monthsAdvance} month) AND\n\t\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW() AND\n\t\t\t\t\tsize_id={$boxSizeId}");
             $n = 0;
             foreach ($Boxes as $Box) {
                 $CustBoxes = UserBox::model()->findAllByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id));
                 foreach ($CustBoxes as $CustBox) {
                     $CustBox->delete();
                 }
                 $n++;
                 if ($n % 2 == 0 && $every == 'fortnight') {
                     continue;
                 }
                 //Create extra customer box rows
                 for ($i = 0; $i < $quantity; $i++) {
                     $CustBox = new UserBox();
                     $CustBox->user_id = $Customer->user_id;
                     $CustBox->box_id = $Box->box_id;
                     $CustBox->quantity = 1;
                     $CustBox->delivery_cost = $Location->location_delivery_value;
                     $CustBox->save();
                     $CustDeliveryDate = Order::model()->findByAttributes(array('user_id' => $Customer->user_id, 'delivery_date_id' => $CustBox->Box->delivery_date_id));
                     if (!$CustDeliveryDate) {
                         $CustDeliveryDate = new Order();
                         $CustDeliveryDate->user_id = $Customer->user_id;
                         $CustDeliveryDate->delivery_date_id = $CustBox->Box->delivery_date_id;
                     }
                     $CustDeliveryDate->location_id = $locationId;
                     $CustDeliveryDate->customer_location_id = $custLocationId;
                     $CustDeliveryDate->save();
                 }
             }
         }
     }
     if (isset($_POST['btn_clear_orders'])) {
         //Get all boxes beyond the deadline date
         $Boxes = Box::model()->with('DeliveryDate')->findAll("\n\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW()");
         foreach ($Boxes as $Box) {
             $CustBox = UserBox::model()->findByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id));
             //Only create a records if an entry doesn't already exist
             if ($CustBox) {
                 $CustBox->delete();
             }
         }
     }
     if (isset($_POST['Orders'])) {
         foreach ($_POST['Orders'] as $boxId => $quantity) {
             $Box = Box::model()->findByPk($boxId);
             $CustBoxes = UserBox::model()->with('Box')->findAll(array('condition' => 'user_id=:customerId AND size_id=:sizeId AND delivery_date_id=:deliveryDateId', 'params' => array(':customerId' => $Customer->user_id, ':sizeId' => $Box->size_id, ':deliveryDateId' => $Box->delivery_date_id)));
             $curQuantity = count($CustBoxes);
             $diff = $quantity - $curQuantity;
             if ($diff > 0) {
                 //Create extra customer box rows
                 for ($i = 0; $i < $diff; $i++) {
                     $CustBox = new UserBox();
                     $CustBox->user_id = $Customer->user_id;
                     $CustBox->box_id = $boxId;
                     $CustBox->quantity = 1;
                     $CustBox->delivery_cost = $Customer->Location->location_delivery_value;
                     $CustBox->save();
                 }
             }
             if ($diff < 0) {
                 //Remove any boxes the customer no longer wants;
                 $diff = abs($diff);
                 for ($i = 0; $i < $diff; $i++) {
                     $CustBoxes[$i]->delete();
                 }
             }
         }
     }
     if (isset($_POST['CustDeliveryDates'])) {
         foreach ($_POST['CustDeliveryDates'] as $key => $locationId) {
             $CustDeliveryDate = Order::model()->findByPk($key);
             $custLocationId = new CDbExpression('NULL');
             if (strpos($locationId, '-')) {
                 //has a customer location
                 $parts = explode('-', $locationId);
                 $locationId = $parts[1];
                 $custLocationId = $parts[0];
             }
             $CustDeliveryDate->location_id = $locationId;
             $CustDeliveryDate->customer_location_id = $custLocationId;
             $CustDeliveryDate->save();
             $CustBoxesDate = UserBox::model()->with('Box')->findAll('user_id=:customerId AND Box.delivery_date_id=:dateId', array('customerId' => Yii::app()->user->user_id, 'dateId' => $CustDeliveryDate->delivery_date_id));
             foreach ($CustBoxesDate as $CustBox) {
                 $CustBox->delivery_cost = $CustDeliveryDate->Location->location_delivery_value;
                 $CustBox->save();
             }
         }
     }
     $this->render('order', array('model' => $model, 'DeliveryDates' => $DeliveryDates, 'Customer' => $Customer, 'BoxSizes' => $BoxSizes, 'deadline' => strtotime('+' . $deadlineDays . ' days'), 'show' => $show));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = DeliveryDate::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #9
0
 public function actionCheckout()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect(array('/shop/register'));
     }
     $userId = Yii::app()->user->id;
     $User = BoxomaticUser::model()->findByPk($userId);
     if (!$User->Location) {
         Yii::app()->user->setFlash('warning', 'Please set your location');
         $this->redirect(array('/user/update', 'id' => $User->id));
     }
     $DeliveryDates = DeliveryDate::model()->with('Boxes')->findAll(array('condition' => 'DATE_SUB(date, INTERVAL -1 week) > NOW() AND date < DATE_ADD(NOW(), INTERVAL 1 MONTH)'));
     $BoxoCart = new BoxoCart();
     if (isset($_GET['set-date'])) {
         $BoxoCart->setDelivery_date_id($_GET['set-date']);
     }
     $AllDeliveryDates = DeliveryDate::model()->with('Locations')->findAll('Locations.location_id = :locationId', array(':locationId' => $User->location_id));
     if (isset($_POST['btn_recurring'])) {
         //recurring order button pressed
         $NextDD = $BoxoCart->getLastDeliveryDate();
         $DDs = $BoxoCart->Location->getFutureDeliveryDates($NextDD, (int) $_POST['months_advance'], $_POST['every']);
         $allOk = $BoxoCart->repeatCurrentOrder($DDs);
         if (!$allOk) {
             Yii::app()->user->setFlash('warning', '<strong>Warning:</strong> One or more of the products are not available on the given dates and have been removed.');
         }
     }
     $this->render('checkout', array('BoxoCart' => $BoxoCart, 'DeliveryDate' => $BoxoCart->DeliveryDate, 'Customer' => $User, 'AllDeliveryDates' => $AllDeliveryDates));
 }
 /**
  * Manages all models.
  */
 public function actionOrder($date = null, $cat = null, $show = 5, $location = null)
 {
     if (!$cat) {
         $cat = SnapUtil::config('boxomatic/supplier_product_feature_category');
     }
     $customerId = Yii::app()->user->user_id;
     $Customer = Customer::model()->findByPk($customerId);
     $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
     if (!$date) {
         $date = DeliveryDate::getCurrentDeliveryDateId();
     }
     $updatedExtras = array();
     $updatedOrders = array();
     $Category = Category::model()->findByPk($cat);
     $DeliveryDate = DeliveryDate::model()->findByPk($date);
     $AllDeliveryDates = false;
     $pastDeadline = false;
     $CustDeliveryDate = false;
     if ($Customer) {
         $CustDeliveryDate = Order::model()->findByAttributes(array('delivery_date_id' => $date, 'user_id' => $customerId));
         if (!$CustDeliveryDate) {
             $CustDeliveryDate = new Order();
             $CustDeliveryDate->delivery_date_id = $date;
             $CustDeliveryDate->user_id = $customerId;
             $CustDeliveryDate->location_id = $Customer->location_id;
             $CustDeliveryDate->save();
         }
         $AllDeliveryDates = DeliveryDate::model()->with('Locations')->findAll("Locations.location_id = " . $CustDeliveryDate->location_id);
         $deadline = strtotime('+' . $deadlineDays . ' days');
         $pastDeadline = strtotime($DeliveryDate->date) < $deadline;
         if ($pastDeadline) {
             Yii::app()->user->setFlash('warning', 'Order deadline has passed, order cannot be changed.');
         }
     }
     if (!$Customer && (isset($_POST['supplier_purchases']) || isset($_POST['boxes']))) {
         Yii::app()->user->setFlash('error', 'You must register to make an order.');
         $this->redirect(array('site/register'));
     }
     if ($location) {
         $locationId = $location;
         $custLocationId = new CDbExpression('NULL');
         if (strpos($locationId, '-')) {
             //has a customer location
             $parts = explode('-', $locationId);
             $locationId = $parts[1];
             $custLocationId = $parts[0];
         }
         //$Location=Location::model()->findByPk($locationId);
         $CustDeliveryDate->location_id = $locationId;
         $CustDeliveryDate->customer_location_id = $custLocationId;
         $CustDeliveryDate->save();
         $CustDeliveryDate->refresh();
     }
     if (isset($_POST['btn_recurring'])) {
         $monthsAdvance = (int) $_POST['months_advance'];
         $startingFrom = $_POST['starting_from'];
         $every = $_POST['every'];
         $locationId = $_POST['Order']['delivery_location_key'];
         $custLocationId = new CDbExpression('NULL');
         if (strpos($locationId, '-')) {
             //has a customer location
             $parts = explode('-', $locationId);
             $locationId = $parts[1];
             $custLocationId = $parts[0];
         }
         $dayOfWeek = date('N', strtotime($CustDeliveryDate->DeliveryDate->date)) + 1;
         if ($dayOfWeek == 8) {
             $dayOfWeek = 1;
         }
         $orderedExtras = OrderItem::findCustomerExtras($customerId, $date);
         $orderedBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $date);
         $DeliveryDates = DeliveryDate::model()->findAll("\n\t\t\t\t\tdate >= '{$startingFrom}' AND\n\t\t\t\t\tdate <=  DATE_ADD('{$startingFrom}', interval {$monthsAdvance} MONTH) AND\n\t\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW() AND\n\t\t\t\t\tDAYOFWEEK(date) = '" . $dayOfWeek . "'");
         $n = 0;
         foreach ($DeliveryDates as $DD) {
             $CustDD = Order::model()->findByAttributes(array('delivery_date_id' => $DD->id, 'user_id' => $customerId));
             if (!$CustDD) {
                 $CustDD = new Order();
                 $CustDD->delivery_date_id = $DD->id;
                 $CustDD->user_id = $customerId;
                 $CustDD->location_id = $CustDeliveryDate->location_id;
                 $CustDD->save();
             }
             //Delete any extras already ordered
             $TBDExtras = OrderItem::findCustomerExtras($customerId, $DD->id);
             foreach ($TBDExtras as $TBDExtra) {
                 $TBDExtra->delete();
             }
             //Delete any extras already ordered
             $TBDBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $CustDD->delivery_date_id);
             foreach ($TBDBoxes as $TBDBox) {
                 $TBDBox->delete();
             }
             $n++;
             if ($n % 2 == 0 && $every == 'fortnight') {
                 continue;
             }
             //Copy current days order
             foreach ($orderedExtras as $orderedExt) {
                 $extra = new OrderItem();
                 //give the customer the extra
                 $extra->quantity = $orderedExt->quantity;
                 $extra->order_id = $CustDD->id;
                 $extra->supplier_purchase_id = $orderedExt->supplier_purchase_id;
                 $extra->price = $orderedExt->price;
                 $extra->packing_station_id = $orderedExt->packing_station_id;
                 $extra->name = $orderedExt->name;
                 $extra->unit = $orderedExt->unit;
                 $extra->save();
             }
             //Copy current days boxxes
             foreach ($orderedBoxes as $orderedBox) {
                 $EquivBox = Box::model()->findByAttributes(array('size_id' => $orderedBox->Box->size_id, 'delivery_date_id' => $DD->id));
                 $box = new UserBox();
                 $box->attributes = $orderedBox->attributes;
                 $box->user_box_id = null;
                 $box->box_id = $EquivBox->box_id;
                 $box->save();
             }
         }
         Yii::app()->user->setFlash('success', 'Recurring order set.');
     }
     if (isset($_POST['btn_clear_orders'])) {
         $orderedExtras = OrderItem::model()->with(array('Order' => array('with' => 'DeliveryDate')))->findAll("DATE_SUB(date, INTERVAL {$deadlineDays} DAY) > NOW() AND user_id = " . $Customer->user_id);
         foreach ($orderedExtras as $ext) {
             $ext->delete();
         }
         //Get all boxes beyond the deadline date
         $Boxes = Box::model()->with('DeliveryDate')->findAll("DATE_SUB(date, interval {$deadlineDays} day) > NOW()");
         foreach ($Boxes as $Box) {
             $CustBox = UserBox::model()->findByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id));
             if ($CustBox) {
                 $CustBox->delete();
             }
         }
     }
     if (isset($_POST['extras'])) {
         foreach ($_POST['extras'] as $id => $quantity) {
             $model = $this->loadModel($id);
             if ($model->Order->user_id == Yii::app()->user->user_id) {
                 if ($quantity == 0) {
                     $model->delete();
                 } else {
                     $model->quantity = $quantity;
                     $model->save();
                     $updatedOrders[$model->id] = $model;
                 }
             }
         }
     }
     if (isset($_POST['supplier_purchases'])) {
         foreach ($_POST['supplier_purchases'] as $purchaseId => $quantity) {
             if ($quantity == 0) {
                 continue;
             }
             $extra = OrderItem::model()->with('Order')->findByAttributes(array('supplier_purchase_id' => $purchaseId, 'order_id' => $CustDeliveryDate->id));
             if (!$extra) {
                 $extra = new OrderItem();
             }
             $Purchase = SupplierPurchase::model()->findByPk($purchaseId);
             $SupplierProduct = $Purchase->supplierProduct;
             //give the customer the extra
             $extra->quantity += $quantity;
             $extra->order_id = $CustDeliveryDate->id;
             $extra->supplier_purchase_id = $purchaseId;
             $extra->price = $Purchase->item_sales_price;
             $extra->packing_station_id = $SupplierProduct->packing_station_id;
             $extra->name = $SupplierProduct->name;
             $extra->unit = $SupplierProduct->unit;
             $updatedExtras[$extra->supplier_purchase_id] = $extra;
             $extra->save();
         }
     }
     if (isset($_POST['boxes'])) {
         foreach ($_POST['boxes'] as $boxId => $quantity) {
             $Box = Box::model()->findByPk($boxId);
             $CustBoxes = UserBox::model()->with('Box')->findAll(array('condition' => 'user_id=:customerId AND size_id=:sizeId AND delivery_date_id=:deliveryDateId', 'params' => array(':customerId' => $customerId, ':sizeId' => $Box->size_id, ':deliveryDateId' => $Box->delivery_date_id)));
             $curQuantity = count($CustBoxes);
             $diff = $quantity - $curQuantity;
             if ($diff > 0) {
                 //Create extra customer box rows
                 for ($i = 0; $i < $diff; $i++) {
                     $CustBox = new UserBox();
                     $CustBox->user_id = $customerId;
                     $CustBox->box_id = $boxId;
                     $CustBox->quantity = 1;
                     $CustBox->delivery_cost = $Customer->Location->location_delivery_value;
                     $CustBox->save();
                 }
             }
             if ($diff < 0) {
                 //Remove any boxes the customer no longer wants;
                 $diff = abs($diff);
                 for ($i = 0; $i < $diff; $i++) {
                     $CustBoxes[$i]->delete();
                 }
             }
         }
     }
     $orderedExtras = OrderItem::findCustomerExtras($customerId, $date);
     $dpOrderedExtras = new CActiveDataProvider('OrderItem');
     $dpOrderedExtras->setData($orderedExtras);
     $DeliveryDates = DeliveryDate::model()->with('Boxes')->findAll(array('condition' => 'DATE_SUB(date, INTERVAL -1 week) > NOW() AND date < DATE_ADD(NOW(), INTERVAL 1 MONTH)'));
     $this->render('order', array('pastDeadline' => $pastDeadline, 'orderedExtras' => $dpOrderedExtras, 'updatedExtras' => $updatedExtras, 'updatedOrders' => $updatedOrders, 'DeliveryDate' => $DeliveryDate, 'DeliveryDates' => $DeliveryDates, 'AllDeliveryDates' => $AllDeliveryDates, 'model' => new OrderItem(), 'Category' => $Category, 'Customer' => $Customer, 'CustDeliveryDate' => $CustDeliveryDate, 'curCat' => $cat));
 }
Example #11
0
 /**
  * This function only returns delivery days on the given day of week of the $FromDate 
  */
 public function getFutureDeliveryDates($FromDate, $advance, $every = null, $intervalType = 'MONTH')
 {
     $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
     $startingFrom = $FromDate->date;
     $dayOfWeek = date('N', strtotime($startingFrom)) + 1;
     $c = new CDbCriteria();
     $c->with = 'Locations';
     $c->addCondition('date >= :startingFrom');
     $c->addCondition('date <=  DATE_ADD(:startingFrom, interval :advance ' . $intervalType . ')');
     $c->addCondition('DAYOFWEEK(date) = :dayOfWeek');
     $c->addCondition('date_sub(date, interval :deadlineDays day) > NOW()');
     $c->addCondition('Locations.location_id = :locationId');
     $c->params = array(':startingFrom' => $startingFrom, ':advance' => $advance, ':dayOfWeek' => $dayOfWeek, ':deadlineDays' => $deadlineDays, ':locationId' => $this->location_id);
     $DDs = DeliveryDate::model()->findAll($c);
     //FB - This will break if more than 2 deliveries in one week..
     if ($every == 'fortnight') {
         foreach (range(1, count($DDs), 2) as $key) {
             unset($DDs[$key]);
         }
         $DDs = array_merge($DDs);
         //reset the keys
     }
     return $DDs;
 }
Example #12
0
 public static function getAvailableItems($dateId, $catId = null)
 {
     $DeliveryDate = DeliveryDate::model()->findByPk($dateId);
     $c = new CDbCriteria();
     $c->addCondition(":date > customer_available_from");
     $c->addCondition(":date < customer_available_to");
     $c->addCondition("available_in_shop = 1");
     $c->params = array(':date' => $DeliveryDate->date);
     if ($catId == Category::uncategorisedCategory) {
         $c->join = 'LEFT JOIN boxo_supplier_product_categories spc ON t.id = spc.supplier_product_id';
         $c->addCondition('category_id IS NULL');
     } else {
         if ($catId) {
             $c->with = "Categories";
             $c->addCondition("category_id = :catId");
             $c->params[':catId'] = $catId;
         }
     }
     return self::model()->findAll($c);
 }
Example #13
0
 /**
  * Find all customers that have no future orders 
  */
 public function findAllWithNoOrders()
 {
     $NextDelivery = DeliveryDate::model()->find(array('condition' => 'date > NOW()', 'order' => 'date ASC'));
     $criteria = new CDbCriteria();
     $criteria->with = array('User' => array('joinType' => 'INNER JOIN'), 'UserBoxes' => array('with' => array('Box' => array('with' => array('DeliveryDate' => array())))));
     $criteria->order = 'first_name ASC';
     $criteria->select = '*, COUNT(UserBoxes.user_box_id) AS total_orders, MAX(DeliveryDate.date) as last_order';
     $criteria->group = 't.user_id';
     $criteria->having = 'last_order="' . $NextDelivery->date . '"';
     //$criteria->addCondition('DeliveryDate.date < DATE_ADD(NOW(), INTERVAL 7 DAY)');
     //$criteria->addCondition('DeliveryDate.date > NOW()');
     return $this->findAll($criteria);
 }