/**
  * 
  */
 public function actionSetDelivered($custBox)
 {
     $CustBox = UserBox::model()->findByPk($custBox);
     if ($CustBox) {
         $CustBox->status = UserBox::STATUS_DELIVERED;
         $CustBox->save();
         Yii::app()->user->setFlash('success', "Customer box has been set to Delivered.");
     } else {
         Yii::app()->user->setFlash('success', "Could not find the given Customer Box");
     }
     $this->redirect(array('userBoxes', 'date' => $CustBox->Box->delivery_date_id));
 }
Exemple #2
0
	<?php 
$form = $this->beginWidget('application.widgets.SnapActiveForm', array('id' => 'extras-form', 'enableAjaxValidation' => false));
?>
	<div class="large-3 columns products order">
		<?php 
if ($Customer) {
    ?>
		<h2>Your order (<?php 
    echo SnapFormat::currency($Customer->totalByDeliveryDate($DeliveryDate->id));
    ?>
)</h2>
		
		<div class="items row list-view">
		<?php 
    foreach ($DeliveryDate->MergedBoxes as $Box) {
        $UserBox = UserBox::findUserBox($DeliveryDate->id, $Box->size_id, Yii::app()->user->user_id);
        if (!$UserBox) {
            continue;
        }
        $quantity = $UserBox ? $UserBox->quantity : 0;
        ?>
		
			<div class="view large-12 columns">
				<div class="row">
					<div class="large-4 columns">
						<div class="image">
						<?php 
        if (!empty($Box->BoxSize->image)) {
            ?>
							<?php 
            echo CHtml::image($this->createUrl('boxSize/image', array('id' => $Box->BoxSize->id)));
 /**
  * Move a customer box to the selected box
  * @param integer $from the ID of the box to move a customer box from
  * @param integer $to the ID of the box to move a customer box to
  * @param integer $cust the ID of the customer to move, if not specified a random customer will be chosen
  */
 public function actionMoveBox($from, $to, $cust = null)
 {
     if ($cust) {
         $CustBoxFrom = UserBox::model()->findByPk($cust);
     } else {
         $CustBoxFrom = UserBox::random($from);
     }
     $CustBoxFrom->box_id = $to;
     $CustBoxFrom->save();
     $this->redirect(array('boxItem/create', 'date' => $CustBoxFrom->Box->delivery_date_id));
 }
 public function actionUpdateDeliveryCosts()
 {
     /*
     		$sql=
     			'SELECT cb.user_box_id, w.date, cw.week_id, cb.user_id, b.box_price, cb.delivery_cost, l.location_delivery_value, l.is_pickup
     			FROM `user_boxes` cb
     			INNER JOIN boxes b ON cb.box_id = b.box_id
     			INNER JOIN customer_weeks cw ON b.week_id = cw.week_id
     			INNER JOIN locations l ON cw.customer_location_id = l.location_id
     			INNER JOIN weeks w ON b.week_id = w.week_id
     			WHERE delivery_cost != location_delivery_value
     			AND date > NOW()';
     		
     		$connection=Yii::app()->db; 
     		$dataReader=$connection->createCommand($sql)->query();
     		foreach($dataReader as $row)
     		{
     			$custBoxId=$row['user_box_id'];
     			$delivery=$row['location_delivery_value'];
     			$upSql="UPDATE customer_box SET delivery_cost=$delivery WHERE user_box_id=$custBoxId;";
     			echo $upSql.'<br />';
     			//$connection->createCommand($upSql)->execute();
     		}
     */
     $CustBoxes = UserBox::model()->with(array('Box' => array('with' => array('DeliveryDate'))))->findAll('DeliveryDate.date > NOW()');
     $n = 0;
     foreach ($CustBoxes as $CustBox) {
         $CustDeliveryDate = Order::model()->findByAttributes(array('user_id' => $CustBox->user_id, 'delivery_date_id' => $CustBox->Box->delivery_date_id));
         if ($CustBox->delivery_cost != $CustDeliveryDate->Location->location_delivery_value) {
             $User = $CustBox->Customer->User;
             echo "<p>Customer {$User->id}: {$User->full_name} ({$CustBox->delivery_cost} - {$CustDeliveryDate->Location->location_delivery_value})</p>";
             $upSql = "UPDATE customer_box SET delivery_cost={$CustDeliveryDate->Location->location_delivery_value} WHERE user_box_id={$CustBox->user_box_id};";
             $n++;
         }
     }
     echo "<p><strong>count: {$n}</strong></p>";
 }
 public function actionGenerateCustomerListPdf($date)
 {
     $CustBoxes = UserBox::model()->with(array('Box' => array('with' => array('BoxSize')), 'User'))->findAll(array('condition' => 'delivery_date_id=' . $date . ' AND (status=' . UserBox::STATUS_APPROVED . ' OR status=' . UserBox::STATUS_DELIVERED . ')', 'order' => 'User.first_name'));
     $mPDF1 = Yii::app()->ePdf->mpdf();
     $mPDF1->SetTitle('Customer list');
     $stylesheet = file_get_contents(Yii::getPathOfAlias('web.themes.boxomatic.admin.css') . '/pdf.css');
     $mPDF1->WriteHTML($stylesheet, 1);
     //		$this->renderPartial('customer_list_pdf', array('CustBoxes'=>$CustBoxes));
     $mPDF1->WriteHTML($this->renderPartial('customer_list_pdf', array('CustBoxes' => $CustBoxes), true));
     $mPDF1->Output();
 }
 /**
  * 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 = UserBox::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * 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));
 }
Exemple #8
0
;
    </script>
</div>
<div class="row">
    <div id="customerList" class="col-md-9">
        <?php 
$this->beginWidget('bootstrap.widgets.BsPanel', array('title' => 'Boxes', 'titleTag' => 'h3'));
?>
        <?php 
$dataProvider = $SelectedDeliveryDate ? $UserBoxes->boxSearch($SelectedDeliveryDate->id) : $UserBoxes->boxSearch(-1);
?>
        <?php 
$pageSize = Yii::app()->user->getState('pageSize', 10);
?>
        <?php 
$this->widget('bootstrap.widgets.BsGridView', array('id' => 'customer-list-grid', 'cssFile' => '', 'dataProvider' => $dataProvider, 'filter' => $UserBoxes, 'summaryText' => 'Displaying {start}-{end} of {count} result(s). ' . CHtml::dropDownList('pageSize', $pageSize, array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100), array('class' => 'change-pageSize')) . ' rows per page', 'columns' => array('user_box_id', array('name' => 'customer_full_name', 'type' => 'raw', 'value' => 'CHtml::link($data->User->full_name,array("user/view","id"=>$data->user_id))'), array('name' => 'User.balance', 'value' => 'SnapFormat::currency($data->User->balance)'), array('name' => 'customer_box_price', 'value' => 'SnapFormat::currency($data->Box->box_price + $data->delivery_cost)', 'filter' => CHtml::listData(BoxSize::model()->findAll(), 'box_size_price', 'box_size_name')), array('name' => 'status', 'value' => '$data->status_text', 'filter' => UserBox::model()->statusOptions), array('class' => 'bootstrap.widgets.BsButtonColumn', 'header' => 'Actions', 'template' => '{login}{process}{cancel}{set_approved}{set_delivered}', 'buttons' => array('login' => array('label' => '<i class="glyphicon glyphicon-user"></i>', 'url' => 'array("user/loginAs","id"=>$data->user_id)', 'options' => array('title' => 'Login As')), 'process' => array('label' => '<i class="glyphicon glyphicon-cog"></i>', 'url' => 'array("boxItem/processCustBox","custBox"=>$data->user_box_id)', 'visible' => '$data->status==UserBox::STATUS_DECLINED', 'options' => array('title' => 'Process')), 'cancel' => array('url' => 'array("boxItem/refund","custBox"=>$data->user_box_id)', 'visible' => '$data->status==UserBox::STATUS_APPROVED', 'label' => '<i class="glyphicon glyphicon-remove"></i>', 'options' => array('confirm' => 'Are you sure you want to refund this box?', 'title' => 'Cancel & Refund')), 'set_approved' => array('url' => 'array("boxItem/setApproved","custBox"=>$data->user_box_id)', 'visible' => '$data->status==UserBox::STATUS_DELIVERED', 'label' => '<i class="glyphicon glyphicon-check"></i>', 'options' => array('confirm' => 'Are you sure you want to set this box to Approved?', 'title' => 'Set Approved')), 'set_delivered' => array('url' => 'array("boxItem/setDelivered","custBox"=>$data->user_box_id)', 'visible' => '$data->status==UserBox::STATUS_APPROVED', 'label' => '<i class="glyphicon glyphicon-thumbs-up"></i>', 'options' => array('confirm' => 'Are you sure you want to set this box to Collected/Delivered?', 'title' => 'Set Delivered')))))));
?>
        <?php 
$this->endWidget();
?>

        <?php 
$this->beginWidget('bootstrap.widgets.BsPanel', array('title' => 'Order Items'));
?>
        <?php 
$this->widget('bootstrap.widgets.BsGridView', array('id' => 'customer-extras-grid', 'cssFile' => '', 'dataProvider' => $CDDsWithExtras, 'filter' => $CDD, 'summaryText' => 'Displaying {start}-{end} of {count} result(s). ' . CHtml::dropDownList('pageSize', $pageSize, array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100), array('class' => 'change-pageSize')) . ' rows per page', 'columns' => array(array('name' => 'customer_user_id', 'value' => '$data->User->id'), array('name' => 'search_full_name', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::value($data,"User.full_name"),array("user/view","id"=>$data->User->id))'), array('name' => 'User.balance', 'value' => 'SnapFormat::currency($data->User->balance)'), array('name' => 'extras_total', 'value' => 'SnapFormat::currency($data->extras_total)', 'filter' => false), array('name' => 'extras_item_names', 'value' => 'substr($data->extras_item_names,0,20)."..."'), array('name' => 'status', 'value' => '$data->status_text', 'filter' => Order::model()->statusOptions), array('class' => 'bootstrap.widgets.BsButtonColumn', 'header' => 'Actions', 'template' => '{login}{process}{cancel}{set_approved}{set_delivered}', 'buttons' => array('login' => array('label' => '<i class="glyphicon glyphicon-user"></i>', 'url' => 'array("user/loginAs","id"=>$data->User->id)', 'options' => array('title' => 'Login As')), 'process' => array('label' => '<i class="glyphicon glyphicon-cog"></i>', 'url' => 'array("boxItem/processCustExtras","cdd"=>$data->id)', 'visible' => '$data->status==Order::STATUS_DECLINED', 'options' => array('title' => 'Process')), 'cancel' => array('url' => 'array("customer/refundExtras","cdd"=>$data->id)', 'visible' => '$data->status==Order::STATUS_APPROVED', 'label' => '<i class="glyphicon glyphicon-cancel"></i>', 'options' => array('confirm' => 'Are you sure you want to refund this order?', 'title' => 'Cancel & Refund')), 'set_approved' => array('url' => 'array("customer/setExtrasApproved","cdd"=>$data->id)', 'visible' => '$data->status==Order::STATUS_DELIVERED', 'label' => '<i class="glyphicon glyphicon-check"></i>', 'options' => array('confirm' => 'Are you sure you want to set this box to Approved?', 'title' => 'Set Approved')), 'set_delivered' => array('url' => 'array("customer/setExtrasApproved","cdd"=>$data->id)', 'visible' => '$data->status==Order::STATUS_APPROVED', 'label' => '<i class="glyphicon glyphicon-thumbs-up"></i>', 'options' => array('confirm' => 'Are you sure you want to set this box to Collected/Delivered?', 'title' => 'Set Delivered')))))));
?>
        <?php 
$this->endWidget();
?>
    </div>
 public function getFulfilled_order_total()
 {
     $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays');
     $customerId = Yii::app()->user->user_id;
     $deliveryDateDeadline = date('Y-m-d', strtotime('+' . $deadlineDays . ' days'));
     $criteria = new CDbCriteria();
     $criteria->with = array('Box.DeliveryDate');
     $criteria->condition = 'date<=:deliveryDateDeadline AND user_id=:customerId';
     $criteria->params = array(':deliveryDateDeadline' => $deliveryDateDeadline, ':customerId' => $customerId);
     $criteria->select = 'SUM((box_price * quantity) + (delivery_cost * quantity)) as fulfilled_total';
     $result = UserBox::model()->with('Box')->find($criteria);
     return $result ? $result->fulfilled_total : 0;
 }