コード例 #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();
 }
コード例 #2
0
 /**
  * Generate Reports
  */
 public function actionSalesReport()
 {
     $xAxis = array();
     $yAxis = array();
     $series = array();
     $xAxisName = '';
     $yAxisName = '';
     $r = Yii::app()->request;
     if (isset($_POST['boxSales'])) {
         $xAxisName = 'DeliveryDate';
         $yAxisName = 'Boxes Sold';
         $dateFrom = $r->getPost($_POST['date_from'], '2012-01-01');
         $dateTo = $r->getPost($_POST['date_to'], '2020-01-01');
         //All boxes
         $sql = "SELECT d.date, count(user_box_id) as total\n\t\t\t\tFROM user_boxes cb\n\t\t\t\tJOIN boxes b ON cb.box_id=b.box_id\n\t\t\t\tJOIN delivery_dates d ON b.delivery_date_id=d.id\n\t\t\t\tWHERE \n\t\t\t\t\t(\n\t\t\t\t\t\tcb.status=" . UserBox::STATUS_APPROVED . " OR \n\t\t\t\t\t\tcb.status=" . UserBox::STATUS_DELIVERED . "\n\t\t\t\t\t)\n\t\t\t\t\tAND\n\t\t\t\t\td.date > \"{$dateFrom}\" AND\n\t\t\t\t\td.date < \"{$dateTo}\"\n\t\t\t\tGROUP BY d.date\n\t\t\t\tORDER BY d.date ASC";
         $connection = Yii::app()->db;
         $dataReader = $connection->createCommand($sql)->query();
         $allBoxesData = array();
         foreach ($dataReader as $row) {
             //multiply by 1000 for milliseconds for javascript
             $allBoxesData[] = array(strtotime($row['date']) * 1000, (int) $row['total']);
         }
         $series[] = array('name' => 'All Boxes', 'data' => $allBoxesData);
         $yAxis = array('title' => array('text' => 'Boxes Sold'), 'min' => 0);
         //Get data for each box size
         $BoxSizes = BoxSize::model()->findAll();
         foreach ($BoxSizes as $BoxSize) {
             $sql = "SELECT d.date, count(user_box_id) as total\n\t\t\t\t\tFROM user_boxes cb\n\t\t\t\t\tJOIN boxes b ON cb.box_id=b.box_id\n\t\t\t\t\tJOIN delivery_dates d ON b.delivery_date_id=d.id\n\t\t\t\t\tWHERE \n\t\t\t\t\t\tb.size_id={$BoxSize->id} AND\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tcb.status=" . UserBox::STATUS_APPROVED . " OR \n\t\t\t\t\t\t\tcb.status=" . UserBox::STATUS_DELIVERED . "\n\t\t\t\t\t\t) AND \n\t\t\t\t\t\td.date > \"{$dateFrom}\" AND\n\t\t\t\t\t\td.date < \"{$dateTo}\"\n\t\t\t\t\tGROUP BY d.date\n\t\t\t\t\tORDER BY d.date ASC";
             $dataReader = $connection->createCommand($sql)->query();
             $boxesData = array();
             foreach ($dataReader as $row) {
                 //multiply by 1000 for milliseconds for javascript
                 $boxesData[] = array(strtotime($row['date']) * 1000, (int) $row['total']);
             }
             $series[] = array('name' => $BoxSize->box_size_name . ' Boxes', 'data' => $boxesData);
         }
     }
     $this->render('reports_sales', array('xAxis' => $xAxis, 'yAxis' => $yAxis, 'xAxisName' => $xAxisName, 'yAxisName' => $yAxisName, 'series' => $series));
 }
コード例 #3
0
ファイル: _form.php プロジェクト: snapfrozen/boxomatic
<?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 
コード例 #4
0
 /**
  * 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));
 }
コード例 #5
0
ファイル: user_boxes.php プロジェクト: snapfrozen/boxomatic
;
    </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>
コード例 #6
0
 /**
  * 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 = BoxSize::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }