public function userExists($attribute) { $User = BoxomaticUser::model()->findByAttributes(array('email' => $this->{$attribute})); $this->User = $User; if (!$User) { $this->addError($attribute, 'Could not find user.'); } }
public function __construct() { $this->_user = Yii::app()->user; $User = isset($this->_user->id) ? BoxomaticUser::model()->findByPk($this->_user->id) : false; $this->Customer = $User; if ($User) { $this->delivery_day = $User->delivery_day; } $this->delivery_date_id = $this->_user->getState('boxocart.delivery_date_id', null); $this->_location_id = $this->_user->getState('boxocart.location_id', $User ? $User->location_id : null); $this->_SupplierProduct = $this->_user->getState('boxocart.SupplierProduct', $this->_SupplierProduct, array()); $this->_UserBox = $this->_user->getState('boxocart.UserBox', $this->_UserBox, array()); $this->_SupplierProduct_Before = $this->_user->getState('boxocart.SupplierProduct_Before', $this->_SupplierProduct_Before, array()); $this->_UserBox_Before = $this->_user->getState('boxocart.UserBox_Before', $this->_UserBox_Before, array()); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($date = null, $item = null, $supplier = null) { //The products box in the view requires the date_id to be in the URL if (!$date) { $date = DeliveryDate::getCurrentDeliveryDateId(); $this->redirect(array('boxItem/create', 'date' => $date)); } Yii::app()->user->setReturnUrl($this->createUrl('create', array('date' => $date, 'item' => $item, 'supplier' => $supplier))); $model = new BoxItem(); $SelectedDeliveryDate = null; $NewItem = null; if (isset($_POST['bc'])) { foreach ($_POST['bc'] as $boxContents) { foreach ($boxContents['BoxItem'] as $boxItem) { if (isset($boxItem['box_item_id'])) { $BoxItem = BoxItem::model()->findByPk($boxItem['box_item_id']); } else { $BoxItem = new BoxItem(); } //Delete if boxItem exists and quantity has been set to 0 if ($BoxItem && isset($boxItem['box_item_id']) && $boxItem['item_quantity'] == 0) { $BoxItem->delete(); } if ($boxItem['item_quantity'] > 0) { $BoxItem->attributes = $boxItem; $BoxItem->item_value = $boxContents['item_value']; $BoxItem->item_unit = $boxContents['item_unit']; $BoxItem->supplier_product_id = $boxContents['supplier_product_id']; if (isset($boxContents['item_name'])) { $BoxItem->item_name = $boxContents['item_name']; } $SP = $BoxItem->SupplierProduct; if (!$SP) { $SP = SupplierProduct::model()->findByAttributes(array('name' => $boxContents['item_name'], 'supplier_id' => $boxContents['supplier_id'], 'unit' => $boxContents['item_unit'])); if (!$SP) { $SP = new SupplierProduct(); } $SP->supplier_id = $boxContents['supplier_id']; if (isset($boxContents['item_name'])) { $SP->name = $boxContents['item_name']; } $SP->value = $boxContents['item_value']; $SP->unit = $boxContents['item_unit']; $SP->packing_station_id = $boxContents['packing_station_id']; $SP->available_from = 1; $SP->available_to = 12; } $SP->save(); $BoxItem->supplier_product_id = $SP->id; $BoxItem->save(); } } } } $SupplierProducts = new SupplierProduct('search'); $SupplierProducts->unsetAttributes(); // clear any default values if (isset($_GET['SupplierProduct'])) { $SupplierProducts->attributes = $_GET['SupplierProduct']; } $DeliveryDates = DeliveryDate::model()->findAll(); //$DeliveryDates=DeliveryDate::model()->findAll('date > NOW()'); //Get the boxes for the selected date $DeliveryDateBoxes = null; $SelectedDeliveryDate = DeliveryDate::model()->findByPk($date); $DeliveryDateBoxes = $SelectedDeliveryDate->MergedBoxes; //Item has been selected from inventory, if it doesn't exist in the date //Load it to be added as a new row up the top of the box item list $selectedItemId = null; if ($item) { $NewItem = SupplierProduct::model()->findByPk($item); $TmpItem = 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=:deliveryDateId', array(':itemName' => $NewItem->name, ':supplierId' => $NewItem->supplier_id, ':itemUnit' => $NewItem->unit, ':itemValue' => $NewItem->value, ':deliveryDateId' => $date)); if ($TmpItem) { $selectedItemId = $TmpItem->box_item_id; } else { foreach ($DeliveryDateBoxes as $DeliveryDateBox) { $BoxItem = new BoxItem(); $BoxItem->item_name = $NewItem->name; $BoxItem->supplier_id = $NewItem->supplier_id; $BoxItem->item_unit = $NewItem->unit; $BoxItem->item_value = $NewItem->value; $BoxItem->supplier_product_id = $NewItem->id; $BoxItem->packing_station_id = $NewItem->packing_station_id; $BoxItem->item_quantity = 1; $BoxItem->box_id = $DeliveryDateBox->box_id; $BoxItem->save(); $selectedItemId = $BoxItem->box_item_id; } } //$this->redirect(array('boxItem/create','date'=>$date)); } //User chose to add a new entry by clicking a supplier name if ($supplier) { $TmpItem = 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=:deliveryDateId', array(':itemName' => '', ':supplierId' => (int) $supplier, ':itemUnit' => 'KG', ':itemValue' => 0, ':deliveryDateId' => $date)); if ($TmpItem) { $selectedItemId = $TmpItem->box_item_id; } else { foreach ($DeliveryDateBoxes as $DeliveryDateBox) { $BoxItem = new BoxItem(); $BoxItem->item_name = ''; $BoxItem->supplier_id = (int) $supplier; $BoxItem->item_unit = 'KG'; $BoxItem->item_value = 0; $BoxItem->item_quantity = 1; $BoxItem->box_id = $DeliveryDateBox->box_id; $BoxItem->save(); $selectedItemId = $BoxItem->box_item_id; } } } $this->performAjaxValidation($model); if (isset($_POST['BoxItem'])) { if (!empty($_POST['BoxItem']['box_item_id'])) { $model = $this->loadModel($_POST['BoxItem']['box_item_id']); } $model->attributes = $_POST['BoxItem']; $model->save(); } $Customer = new BoxomaticUser('search'); $Customer->unsetAttributes(); if (isset($_GET['BoxomaticUser'])) { $Customer->attributes = $_GET['BoxomaticUser']; } $this->layout = '//layouts/full_width'; $this->render('create', array('model' => $model, 'SupplierProducts' => $SupplierProducts, 'DeliveryDates' => $DeliveryDates, 'DeliveryDateBoxes' => $DeliveryDateBoxes, 'SelectedDeliveryDate' => $SelectedDeliveryDate, 'selectedItemId' => $selectedItemId, 'Customer' => $Customer)); }
/** * Welcome message. */ public function actionWelcome() { $User = BoxomaticUser::model()->findByPk(Yii::app()->user->id); $this->render('welcome', array('User' => $User)); }
$this->page_heading = 'Customer Payments'; Yii::app()->clientScript->registerScript('initPageSize', <<<EOD \$('.change-pageSize').live('change', function() { \t\$.fn.yiiGridView.update('customer-payment-grid',{ data:{ pageSize: \$(this).val() }}) }); EOD , CClientScript::POS_READY); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('customer-payment-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n\$('.chosen').chosen();\n"); ?> <div class="form row"> <?php $form = $this->beginWidget('application.widgets.SnapActiveForm', array('id' => 'user-payment-form', 'enableAjaxValidation' => false, 'layout' => BsHtml::FORM_LAYOUT_HORIZONTAL)); ?> <div class="col-lg-9 clearfix"> <?php echo $form->dropDownListControlGroup($model, 'user_id', CHtml::listData(BoxomaticUser::model()->findAll(array('order' => 'first_name, last_name')), 'id', 'full_name_and_balance'), array('class' => 'chosen')); ?> <?php echo $form->dropDownListControlGroup($model, 'payment_type', SnapUtil::config('boxomatic/paymentTypes')); ?> <?php echo $form->dateFieldControlGroup($model, 'payment_date'); ?> <?php echo $form->textFieldControlGroup($model, 'payment_value', array('size' => 7, 'maxlength' => 7)); ?> <?php echo $form->textAreaControlGroup($model, 'payment_note'); ?> </div> <?php
/** * 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 = BoxomaticUser::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
?> <p> </p> <?php $this->beginWidget('bootstrap.widgets.BsPanel', array('title' => 'Current credit by user', 'titleTag' => 'h2')); ?> <table class="table"> <thead> <tr> <th>id</th> <th>Name</th> <th>Balance</th> </tr> </thead> <tbody> <?php $Custs = BoxomaticUser::model()->findAll(); $total = 0; foreach ($Custs as $Cust) { $bal = (double) CHtml::value($Cust, 'balance'); $total += $bal; ?> <?php if ($bal != 0) { ?> <tr> <td><?php echo CHtml::value($Cust, 'id'); ?> </td> <td><?php echo CHtml::value($Cust, 'full_name');