/** * Send reminder emails to those who haven't paid for their next week's box */ public function actionSendReminderEmails() { $Customers = Customer::model()->findAllWithNoOrders(); foreach ($Customers as $Cust) { $validator = new CEmailValidator(); if ($validator->validateValue(trim($Cust->User->email))) { $User = $Cust->User; $User->auto_login_key = $User->generatePassword(50, 4); $User->update_time = new CDbExpression('NOW()'); $User->update(); $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $message = new YiiMailMessage('Running out of orders'); $message->view = 'customer_running_out_of_orders'; $message->setBody(array('Customer' => $Cust, 'User' => $User), 'text/html'); $message->addTo($Cust->User->email); $message->addBcc($adminEmail); //$message->addTo('*****@*****.**'); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (!@Yii::app()->mail->send($message)) { echo '<p style="color:red"><strong>Email failed sending to: ' . $Cust->User->email . '</strong></p>'; } else { echo '<p>Running out of orders message sent to: ' . $Cust->User->email . '</p>'; } } else { echo '<p style="color:red"><strong>Email not valid: "' . $Cust->User->email . '"</strong></p>'; } } echo '<p><strong>Finished.</strong></p>'; //Yii::app()->end(); }
/** * Returns a slated and hashed string * @param string $password The password you wish to hash * @return string A hashed and salted tstring */ public static function doHash($password) { $conf = SnapUtil::getConfig('general'); $salt = $conf['security']['salt']; $hash = hash('sha256', $password . $salt); return $hash; }
/** * Generate Reports */ public function actionCreditReport() { $xAxis = array(); $yAxis = array(); $series = array(); $xAxisName = ''; $yAxisName = ''; $tablePrefix = SnapUtil::config('boxomatic/tablePrefix'); $sql = "SELECT MIN(payment_date) FROM {$tablePrefix}user_payments WHERE payment_date != '00-00-00 00:00:00'"; $connection = Yii::app()->db; $minDate = $connection->createCommand($sql)->queryScalar(); $paymentTotals = array(); $days = 0; $timestamp = 0; while ($timestamp < time()) { $timestamp = strtotime("+ {$days} days", strtotime($minDate)); $timestampJs = $timestamp * 1000; $minDate = date('Y-m-d h:i:s', $timestamp); $sql = "SELECT SUM(payment_value) as total\n\t\t\t\tFROM {$tablePrefix}user_payments\n\t\t\t\tWHERE payment_date < '{$minDate}'"; $row = $connection->createCommand($sql)->queryRow(); $paymentTotals[] = array($timestampJs, $row['total']); $days += 7; } $series[] = array('name' => $minDate, 'data' => $paymentTotals); $yAxis = array('title' => array('text' => 'Total payments')); //print_r($series); //print_r($series2); $this->render('reports_credit', array('xAxis' => $xAxis, 'yAxis' => $yAxis, 'xAxisName' => $xAxisName, 'yAxisName' => $yAxisName, 'series' => $series)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id = null) { if (!$id) { $id = SnapUtil::config('general/site.default_menu'); } $model = $this->loadModel($id); if (isset($_POST['Menu'])) { $model->attributes = $_POST['Menu']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $homeId = SnapUtil::config('general/site.homepage_id'); $Content = Content::model()->findByPk($homeId); //Used by the admin bar $this->Content = $Content; $this->layout = '//layouts/column1'; $view = '/content/view'; if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) { $this->layout = '//layouts/content_types/' . $Content->type; } if ($this->getViewFile('/content/content_types/' . $Content->type)) { $view = '/content/content_types/' . $Content->type; } $News = Content::model()->findAllByAttributes(array('type' => 'news'), array('limit' => 4, 'order' => 'created DESC', 'condition' => '(publish_on < NOW() OR publish_on is null) AND ' . '(unpublish_on < NOW() OR unpublish_on is null) AND ' . 'published = 1')); $this->render($view, array('Content' => $Content, 'News' => $News, 'MenuItem' => false)); }
/** * Generate an image url for css background * @param SnapActiveRecord $model * @param string $attribute * @param mixed $size * @return string */ public static function activeImageUrl($model, $attribute, $size = null) { if (empty($model->{$attribute})) { return ''; } $reqArr = array('id' => $model->id, 'field' => $attribute, 'modelName' => get_class($model)); if (is_array($size)) { //It's a PHPThumb array $reqArr = array_merge($reqArr, $size); } else { if (is_string($size)) { $conf = SnapUtil::getConfig('images'); $reqArr = array_merge($reqArr, $conf['sizes'][$size]); } } return Yii::app()->controller->createUrl('/site/getImage', $reqArr); }
public function extrasSearch($date) { $tablePrefix = SnapUtil::config('boxomatic/tablePrefix'); $c = new CDbCriteria(); $c->addCondition('t.delivery_date_id = :date'); $c->select = 't.user_id, GROUP_CONCAT(oi.name SEPARATOR ", ") as extras_item_names, t.delivery_date_id, t.status, t.location_id, t.customer_location_id, t.id'; $c->params = array(':date' => $date); //$c->with doesn't work very well with CActiveDataProvider $c->join = "INNER JOIN {$tablePrefix}order_items oi ON oi.order_id = t.id"; $c->group = 't.user_id'; $c->compare('CONCAT(u.first_name, u.last_name)', $this->search_full_name, true); $c->compare('status', $this->status); $c->compare('oi.name', $this->extras_item_names, true); if (!empty($this->search_full_name)) { $c->join = 'INNER JOIN order_items oi ON oi.order_id = t.id ' . 'INNER JOIN users u ON u.id = t.user_id'; $c->compare('CONCAT(u.first_name, u.last_name)', $this->search_full_name, true); } return new CActiveDataProvider($this, array('criteria' => $c)); }
public static function doHash($password) { $salt = SnapUtil::config('general/security.salt'); $hash = hash('sha256', $password . $salt); return $hash; }
/** * Get the deadline for this date */ public function getDeadline() { $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays'); $deliveryDate = strtotime($this->date); return date('d-m-Y', strtotime('-' . $deadlineDays . ' days', $deliveryDate)); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array('Users' => array(self::MANY_MANY, 'BoxomaticUser', SnapUtil::config('boxomatic/tablePrefix') . 'user_tags(tag_id, user_id)')); }
/** * */ public function actionProcessCustExtras($cdd) { $CDD = Order::model()->findByPk($cdd); $User = $CDD->User; if ($User->balance - $CDD->extras_total > SnapUtil::config('boxomatic/minimumCredit')) { $Payment = new UserPayment(); $Payment->payment_value = -1 * $CDD->extras_total; //make price a negative value for payment table $Payment->payment_type = 'DEBIT'; $Payment->payment_date = new CDbExpression('NOW()'); $Payment->user_id = $CDD->user_id; $Payment->staff_id = Yii::app()->user->id; $note = 'Extras bought on ' . $CDD->DeliveryDate->date . ' totalling:' . SnapFormat::currency($CDD->extras_total); $Payment->payment_note = $note; $Payment->save(); $CDD->status = Order::STATUS_APPROVED; $CDD->save(); } else { Yii::app()->user->setFlash('danger', 'Not enough credit.'); } $this->redirect(array('userBoxes', 'date' => $CDD->delivery_date_id)); }
<?php $cs = Yii::app()->clientScript; $baseUrl = Yii::app()->baseUrl; $themeUrl = $baseUrl . Yii::app()->theme->baseUrl; $Paypal = Yii::app()->getModule('payPal'); $minDays = SnapUtil::config('boxomatic/minimumAdvancePayment'); ?> <div class="row"> <div class="col-md-8 col-md-offset-2 products order"> <div class="page-header"> <h1>Past Orders</h1> </div> <div id="checkout-cart" class="items list-view panel-group"> <?php /* @todo: get Order objects instead $BoxoCart->getOrders() */ foreach ($Orders as $Order) { $DD = $Order->DeliveryDate; $Location = $Order->Location; ?> <div class="panel panel-default"> <a class="panel-heading" data-toggle="collapse" data-parent="#checkout-cart" href="#collapse-<?php echo $DD->id; ?> "> <h3> <?php echo SnapFormat::date($DD->date, 'full'); ?>
public static function getMenuItemClassName() { $className = 'MenuItem'; try { $className = SnapUtil::config('general/models.MenuItem.class'); } catch (CException $e) { } return $className; }
<h1>Orders</h1> <div class="row"> <div class="large-2 columns leftCol"> <h2>Categories</h2> <ul class="categories"> <li class="<?php echo $curCat == Category::boxCategory ? 'selected' : ''; ?> "><?php echo CHtml::link('Boxes', array('OrderItem/order', 'date' => $DeliveryDate->id, 'cat' => Category::boxCategory)); ?> </li> <?php echo Category::model()->getCategoryTree(SnapUtil::config('boxomatic/supplier_product_root_id'), array('OrderItem/order', 'date' => $DeliveryDate->id), $curCat); ?> <li class="<?php echo $curCat == Category::uncategorisedCategory ? 'selected' : ''; ?> "><?php echo CHtml::link('Uncategorised', array('OrderItem/order', 'date' => $DeliveryDate->id, 'cat' => Category::uncategorisedCategory)); ?> </li> </ul> </div> <div class="large-7 columns products"> <?php if ($curCat == Category::boxCategory) { ?>
<?php if (!empty($BoxItemsContent->supplier_product_id)) { echo CHtml::value($BoxItemsContent, 'SupplierProduct.PackingStation.name'); echo CHtml::hiddenField('bc[' . $key . '][packing_station_id]', CHtml::value($BoxItemsContent, 'SupplierProduct.packing_station_id')); } else { echo CHtml::dropDownList('bc[' . $key . '][packing_station_id]', CHtml::value($BoxItemsContent, 'SupplierProduct.packing_station_id'), CHtml::listData(PackingStation::model()->findAll(), 'id', 'name')); } ?> </td> <td class="itemValue"> <?php echo CHtml::textField('bc[' . $key . '][item_value]', $BoxItemsContent->item_value, array('class' => 'currency')); ?> <?php echo CHtml::dropDownList('bc[' . $key . '][item_unit]', $BoxItemsContent->item_unit, SnapUtil::config('boxomatic/itemUnits')); ?> </td> <?php $key2 = 0; foreach ($DeliveryDateBoxes as $DeliveryDateBoxMerged) { $dateBoxIds = explode(',', $DeliveryDateBoxMerged->box_ids); foreach ($dateBoxIds as $dateBoxId) { $Box = Box::model()->findByPk($dateBoxId); $BoxItem = BoxItem::model()->with('Box')->find('item_name=:itemName AND supplier_id=:supplierId AND item_unit=:itemUnit AND item_value=:itemValue AND Box.delivery_date_id=:dateId AND Box.size_id=:sizeId AND t.box_id = ' . $Box->box_id, array(':itemName' => $BoxItemsContent->item_name, ':supplierId' => $BoxItemsContent->supplier_id, ':itemUnit' => $BoxItemsContent->item_unit, ':itemValue' => $BoxItemsContent->item_value, ':dateId' => $Box->delivery_date_id, ':sizeId' => $Box->size_id));
public function up() { $this->createTable('{{users}}', array('id' => 'pk', 'first_name' => 'string NOT NULL', 'last_name' => 'string', 'email' => 'string NOT NULL', 'password' => 'string NOT NULL', 'image' => 'string', 'bio' => 'string', 'created' => 'DATETIME', 'updated' => 'DATETIME')); $this->insert('{{users}}', array('first_name' => 'SnapCMS', 'last_name' => 'Admin', 'email' => '*****@*****.**', 'password' => SnapUtil::doHash('password'))); $this->insert('{{users}}', array('first_name' => 'SnapCMS', 'last_name' => 'Editor', 'email' => '*****@*****.**', 'password' => SnapUtil::doHash('password'))); }
/** * Displays the register page */ public function actionRegister() { $model = new User(); $vars = array(); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->scenario = 'register'; if ($model->save()) { $Customer = new Customer(); $Customer->attributes = $_POST['Customer']; $Customer->save(); if (!$Customer->Location->is_pickup) { $CustLoc = new UserLocation(); $CustLoc->user_id = $Customer->user_id; $CustLoc->location_id = $Customer->location_id; $CustLoc->address = $model->user_address; $CustLoc->address2 = $model->user_address2; $CustLoc->suburb = $model->user_suburb; $CustLoc->state = $model->user_state; $CustLoc->postcode = $model->user_postcode; $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile; $CustLoc->save(false); } $model->user_id = $Customer->user_id; $model->update(array('user_id')); $Auth = Yii::app()->authManager; $Auth->assign('customer', $model->id); //Send email $adminEmail = SnapUtil::config('boxomatic/adminEmail'); $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName'); $message = new YiiMailMessage('Welcome to ' . Yii::app()->name); $message->view = 'welcome'; $message->setBody(array('User' => $model, 'newPassword' => $_POST['User']['password']), 'text/html'); $message->addTo($adminEmail); $message->addTo($model->email); $message->setFrom(array($adminEmail => $adminEmailFromName)); if (!@Yii::app()->mail->send($message)) { $mailError = true; } $identity = new UserIdentity($model->email, $_POST['User']['password']); $identity->authenticate(); Yii::app()->user->login($identity); User::model()->updateByPk($identity->id, array('last_login_time' => new CDbExpression('NOW()'))); $this->redirect(array('customer/welcome')); } } $model->password = ''; $model->password_repeat = ''; $vars['model'] = $model; // $this->render('register',array('model'=>$model)); $this->render('register', $vars); }
<?php $cs = Yii::app()->clientScript; ?> <h1>Do not like list</h1> <p>Select the products you do not wish to appear in your box</p> <div class="row"> <div class="large-2 columns leftCol"> <h2>Categories</h2> <ul class="categories"> <?php echo Category::model()->getCategoryTree(SnapUtil::config('boxomatic/supplier_product_root_id'), array('user/dontWant', 'id' => Yii::app()->user->id), $curCat); ?> <li class="<?php echo $curCat == Category::uncategorisedCategory ? 'selected' : ''; ?> "><?php echo CHtml::link('Uncategorised', array('user/dontWant', 'id' => Yii::app()->user->id, 'cat' => Category::uncategorisedCategory)); ?> </li> </ul> </div> <div class="large-7 columns products"> <h2>Products</h2> <div class="list-view"> <div class="items row"> <?php foreach ($SupplierProducts as $Product) { ?> <div class="view large-12 columns end">
public function actionSearch() { $model = new Supplier('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Supplier'])) { $model->attributes = $_GET['Supplier']; } $criteria = new CDbCriteria(); $criteria->select = 'id,name,lattitude,longitude'; $Suppliers = $model->search(false)->getData(); //Build supplier array and supplier items in a format suitable for Mustache js $supplierArray = SnapUtil::makeArray($Suppliers); foreach ($Suppliers as $Supplier) { $supplierItems = SnapUtil::makeArray($Supplier->SupplierProducts); foreach ($supplierItems as $gi) { $supplierArray[$Supplier->id]['SupplierProducts'][] = $gi; } $supplierArray[$Supplier->id]['has_items'] = !empty($supplierArray[$Supplier->id]['SupplierProducts']) ? true : false; } echo json_encode($supplierArray); exit; }
<?php return array('varchar(%)' => 'TextField', 'text' => array('widget' => array('class' => 'vendor.ckeditorwidget.TheCKEditorWidget', 'settings' => SnapUtil::config('content.ckeditor/default'))), 'datetime' => array('widget' => array('class' => 'zii.widgets.jui.CJuiDatePicker', 'settings' => array())), 'string' => array('fieldType' => 'TextFieldControlGroup'));
/** * Returns the human readable unit label for the BoxItem */ public function getItem_unit_label() { return SnapUtil::config('boxomatic/itemUnits.' . $this->item_unit); }
/** * 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)); }
public static function getConfigArray() { return SnapUtil::getConfig('content.content_types'); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array('parent' => array(self::BELONGS_TO, 'Category', 'parent'), 'children' => array(self::HAS_MANY, 'Category', 'parent', 'order' => 'name'), 'SupplierProducts' => array(self::MANY_MANY, 'SupplierProduct', SnapUtil::config('boxomatic/tablePrefix') . 'supplier_product_categories(supplier_product_id,category_id)')); }
?> <?php } ?> <?php echo $form->textFieldControlGroup($model, 'user_phone', array('size' => 45, 'maxlength' => 45)); ?> <?php echo $form->textFieldControlGroup($model, 'user_mobile', array('size' => 45, 'maxlength' => 45)); ?> <?php echo $form->textAreaControlGroup($model, 'user_address'); ?> <?php echo $form->dropDownListControlGroup($model, 'user_state', SnapUtil::config('boxomatic/states')); ?> <?php echo $form->textFieldControlGroup($model, 'user_postcode', array('size' => 45, 'maxlength' => 45)); ?> <?php echo $form->textAreaControlGroup($model, 'notes'); ?> <div class="form-group"> <?php echo $form->label($model, 'tags', array('class' => 'control-label col-lg-2')); ?> <div class="col-lg-10"> <?php echo $form->hiddenField($model, 'tag_names');
<?php $baseUrl = $this->createFrontendUrl('/') . '/themes/boxomatic/admin'; $cs = Yii::app()->clientScript; $cs->registerScriptFile('https://maps.googleapis.com/maps/api/js?key=' . SnapUtil::config('boxomatic/googleMapKey') . '&sensor=false', CClientScript::POS_END); $cs->registerScriptFile($baseUrl . '/js/pages/supplier/map.js', CClientScript::POS_END); $default_latlong = '0.000000000000'; $this->breadcrumbs = array('Box-O-Matic' => array('/snapcms/boxomatic/index'), 'Suppliers' => array('supplier/admin'), 'Supplier Map'); $this->menu = array(); $this->page_heading = 'Suppiler'; $this->page_heading_subtext = 'Map'; ?> <script> var defaultCoordinate = '<?php echo $default_latlong; ?> '; var suppliers = <?php echo json_encode($Suppliers); ?> ; </script> <?php $this->renderPartial('_search', array('model' => $model)); ?> <p> </p> <div class="row"> <div class="col-md-9"> <?php $this->beginWidget('bootstrap.widgets.BsPanel', array('title' => 'Suppliers', 'titleTag' => 'h3'));
<?php echo $form->dropDownListControlGroup($model, 'available_to', $model->getMonthList()); ?> <?php echo $form->dateFieldControlGroup($model, 'customer_available_from', array(), array('yearRange' => date('Y') . ':2050')); ?> <?php echo $form->dateFieldControlGroup($model, 'customer_available_to', array(), array('yearRange' => date('Y') . ':2050')); ?> <?php echo $form->textFieldControlGroup($model, 'item_sales_price'); ?> <?php echo $form->checkBoxControlGroup($model, 'available_in_shop'); ?> <h3>Categories</h3> <ul class="categories"> <?php echo Category::model()->getCategoryTreeForm(SnapUtil::config('boxomatic/supplier_product_root_id'), $model); ?> </ul> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button name="new_product" type="submit" class="btn btn-primary">Add Product</button> </div> <?php $form->layout = BsHtml::FORM_LAYOUT_HORIZONTAL; BsHtml::$formLayoutHorizontalLabelClass = 'control-label col-lg-2';
/** * Generate a packing list spreadsheet for a given date_id */ public function actionGenerateOrderList($date) { $tablePrefix = SnapUtil::config('boxomatic/tablePrefix'); $sql = ' SELECT SUM(item_quantity) as total, SUM(item_quantity * item_value) as total_price, item_value, GROUP_CONCAT(DISTINCT t.box_id ORDER BY t.box_id DESC) AS box_ids, GROUP_CONCAT(DISTINCT `box_item_id` ORDER BY `BoxItems`.box_id DESC) as box_item_ids, `BoxItems`.`box_item_id`, `BoxItems`.`item_name`, `BoxItems`.`item_unit`, `Supplier`.`name` FROM `' . $tablePrefix . 'boxes` `t` LEFT OUTER JOIN `' . $tablePrefix . 'user_boxes` `UserBoxes` ON (`UserBoxes`.`box_id`=`t`.`box_id`) LEFT OUTER JOIN `' . $tablePrefix . 'box_items` `BoxItems` ON (`BoxItems`.`box_id`=`t`.`box_id`) LEFT OUTER JOIN `' . $tablePrefix . 'suppliers` `Supplier` ON (`BoxItems`.`supplier_id`=`Supplier`.`id`) WHERE ( delivery_date_id=' . $date . ' AND user_box_id is not null AND ( UserBoxes.status=' . UserBox::STATUS_APPROVED . ' OR UserBoxes.status=' . UserBox::STATUS_DELIVERED . ' ) ) GROUP BY name,item_name ORDER BY name; '; $connection = Yii::app()->db; $command = $connection->createCommand($sql); $dataReader = $command->query(); $items = $dataReader->readAll(); if (empty($items)) { echo 'No customer orders!'; exit; } $phpExcelPath = Yii::getPathOfAlias('boxomatic.external.PHPExcel'); $DateBoxes = Box::model()->with('BoxSize')->findAll(array('condition' => 'delivery_date_id = ' . $date, 'order' => 'box_size_name DESC')); //disable Yii's Autoload because it messes with PHPExcel's autoloader spl_autoload_unregister(array('YiiBase', 'autoload')); include $phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Supplier'); $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Item'); $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Total Quantity'); $objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Unit'); $objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Unit Price'); $objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Total Price'); $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $boxIds = explode(',', $items[0]['box_ids']); $pos = 6; spl_autoload_register(array('YiiBase', 'autoload')); foreach ($DateBoxes as $n => $Box) { $custCount = $Box->customerCount; $objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . '1', $Box->BoxSize->box_size_name . ' (' . $custCount . ')'); $objPHPExcel->getActiveSheet()->getColumnDimension($alpha[$pos])->setAutoSize(true); $pos++; } $objPHPExcel->getActiveSheet()->getStyle("A1:" . $alpha[$pos] . '1')->applyFromArray(array("font" => array("bold" => true))); $row = 2; foreach ($items as $item) { $objPHPExcel->getActiveSheet()->SetCellValue('A' . $row, $item['name']); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $row, $item['item_name']); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $row, $item['total']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $row, $item['item_unit']); $objPHPExcel->getActiveSheet()->SetCellValue('E' . $row, $item['item_value']); $objPHPExcel->getActiveSheet()->SetCellValue('F' . $row, $item['total_price']); $boxIds = explode(',', $item['box_ids']); $boxItemIds = explode(',', $item['box_item_ids']); $pos = 6; foreach ($DateBoxes as $Box) { $BoxItem = null; $biPos = false; $biPos = array_search($Box->box_id, $boxIds); if ($biPos !== false) { $BoxItem = BoxItem::model()->findByAttributes(array('box_id' => $Box->box_id, 'box_item_id' => $boxItemIds[$biPos])); } $quantity = $BoxItem && !empty($BoxItem->item_quantity) ? $BoxItem->item_quantity : '0'; $objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . $row, $quantity); $pos++; } $row++; } $objPHPExcel->getActiveSheet()->getColumnDimension("A")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("B")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("C")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("D")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("E")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("F")->setAutoSize(true); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Packing List'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="ordering-list-' . date('Ymd') . '"'); $objWriter->save('php://output'); exit; }
ID as your reference.<br /> Your <?php echo Yii::app()->name; ?> ID is: <strong><?php echo $Customer->bfb_id; ?> </strong>. <h3>Information for collections</h3> <p>If you are unable to pick up your box from Bellingen Greengrocers by 6pm when the store closes, please call us to arrange an alternative, or why not organise a group of friends to share the pick up :)</p> <p> --<br /> Kind regards,<br /> Box-O-Matic, Box Processing System</p> <p>Thank you for your generous support and being part of this wonderful project.</p> <p>Email: <a href="mailto:<?php echo SnapUtil::config('boxomatic/adminEmail'); ?> "><?php echo SnapUtil::config('boxomatic/adminEmail'); ?> </a></p> </body> </html>
public function getNextDeliveryDate($days = null) { $minDays = SnapUtil::config('boxomatic/minimumAdvancePayment'); $days = $days ? $days : $minDays; return $this->Location->getNextDeliveryDate($this->delivery_day, $days); }