/** * Manages all models. */ public function actionIndex($cat = null) { if (!$cat) { $cat = SnapUtil::config('boxomatic/supplier_product_feature_category'); } $BoxoCart = new BoxoCart(); if (isset($_GET['set-date'])) { $BoxoCart->setDelivery_date_id($_GET['set-date']); } if (isset($_POST['BoxoCart']['location_id'])) { $BoxoCart->location_id = $_POST['BoxoCart']['location_id']; $this->refresh(); } if (isset($_POST['Order']) && isset($_POST['add_to_cart'])) { if ($BoxoCart->addItems($_POST['Order'])) { Yii::app()->user->setFlash('success', 'Item added to cart.'); #redirect to category if ($cat == 'box') { $this->redirect(array('shop/index', 'date' => Yii::app()->request->getParam('date'), 'cat' => SnapUtil::config('boxomatic/redirectBoxCategory'))); } } $this->refresh(); } if (isset($_POST['Order']) && (isset($_POST['update_cart']) || isset($_POST['checkout']))) { if ($BoxoCart->updateItems($_POST['Order'])) { Yii::app()->user->setFlash('success', 'Cart updated.'); } if (isset($_POST['checkout'])) { $this->redirect(array('shop/checkout')); } $this->refresh(); } $userId = Yii::app()->user->id; $User = BoxomaticUser::model()->findByPk($userId); $Category = Category::model()->findByPk($cat); $DeliveryDate = false; $dpProducts = false; $Location = $BoxoCart->Location; if ($Location) { if (!$BoxoCart->DeliveryDate) { $DeliveryDate = $BoxoCart->getNextDeliveryDate(); } else { $DeliveryDate = $BoxoCart->DeliveryDate; } $BoxoCart->setDelivery_date_id($DeliveryDate->id); $products = SupplierProduct::getAvailableItems($DeliveryDate->id, $cat); $dpProducts = new CActiveDataProvider('SupplierProduct'); $dpProducts->setData($products); } $this->render('index', array('dpProducts' => $dpProducts, 'DeliveryDate' => $DeliveryDate, 'Category' => $Category, 'Customer' => $User, 'curCat' => $cat, 'BoxoCart' => $BoxoCart, 'Location' => $Location)); }
<?php echo CHtml::label('Supplier', 'Supplier', array('class' => 'col-lg-2')); ?> <div class="col-lg-10 "> <?php echo CHtml::dropDownList('Supplier', Yii::app()->request->getPost('Supplier'), Supplier::getDropdownListItems(), array('prompt' => ' - Select - ', 'class' => 'form-control')); ?> </div> </div> <div class="form-group"> <?php echo CHtml::label('Produce Type', 'SupplierProduct', array('class' => 'col-lg-2')); ?> <div class="col-lg-10 "> <?php echo CHtml::dropDownList('SupplierProduct', Yii::app()->request->getPost('SupplierProduct'), SupplierProduct::getDropdownListItems(), array('prompt' => ' - Select - ', 'class' => 'form-control')); ?> </div> </div> <div class="form-group"> <?php echo CHtml::label('Organic Status', 'organicStatus', array('class' => 'col-lg-2')); ?> <div class="col-lg-10 "> <?php echo CHtml::dropDownList('organicStatus', Yii::app()->request->getPost('organicStatus'), Supplier::getOSDropdownListItems(), array('prompt' => ' - Select - ', 'class' => 'form-control')); ?> </div> </div> <div class="form-group"> <div class="col-lg-10 col-lg-offset-2">
/** * 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)); }
/** * @param type $DDs Array of DeliveryDate objects */ public function repeatCurrentOrder($DDs) { $SPs = isset($this->_SupplierProduct[$this->delivery_date_id]) ? $this->_SupplierProduct[$this->delivery_date_id] : array(); $UBs = isset($this->_UserBox[$this->delivery_date_id]) ? $this->_UserBox[$this->delivery_date_id] : array(); $allOk = true; foreach ($DDs as $DD) { //Clear the current order unset($this->_SupplierProduct[$DD->id]); unset($this->_UserBox[$DD->id]); //Repopulate the order foreach ($SPs as $id => $qty) { $Product = SupplierProduct::model()->findByPk($id); $availTo = strtotime($Product->customer_available_to); $availFrom = strtotime($Product->customer_available_from); $curDate = strtotime($DD->date); if ($curDate < $availTo && $curDate > $availFrom) { $this->_SupplierProduct[$DD->id][$id] = $qty; } else { $allOk = false; } } foreach ($UBs as $id => $qty) { //Find the equivalent box type for the current date $CopyBox = Box::model()->findByAttributes(array('box_id' => $id)); $NewBox = Box::model()->findByAttributes(array('size_id' => $CopyBox->size_id, 'delivery_date_id' => $DD->id)); if ($NewBox) { $this->_UserBox[$DD->id][$NewBox->box_id] = $qty; } else { Yii::app()->user->setFlash('warning', 'A box has been removed from your future orders.'); } } } $this->_user->setState('boxocart.SupplierProduct', $this->_SupplierProduct); $this->_user->setState('boxocart.UserBox', $this->_UserBox); return $allOk; }
<div class="form-group"> <div class="col-md-12"> <div class="row"> <div class="col-md-2"> <?php echo BsHtml::activeDropDownList($SPP, 'supplier_product_id', SupplierProduct::getDropdownListItems($supplier_id), array('class' => 'chosen', 'prompt' => '- Select -', 'name' => 'SupplierPurchaseProducts[' . $SPP->id . '][supplier_product_id]')); ?> </div> <div class="col-md-2"> <?php echo BsHtml::activeTextField($SPP, 'quantity', array('name' => 'SupplierPurchaseProducts[' . $SPP->id . '][quantity]')); ?> </div> <div class="col-md-2"> <?php echo BsHtml::activeTextField($SPP, 'price', array('name' => 'SupplierPurchaseProducts[' . $SPP->id . '][price]')); ?> </div> <?php if ($SPP->Product) { ?> <div class="col-md-2"> <?php echo BsHtml::activeDateField($SPP->Product, 'customer_available_from', array('name' => 'SupplierProducts[' . $SPP->supplier_product_id . '][customer_available_from]')); ?> </div> <div class="col-md-2"> <?php echo BsHtml::activeDateField($SPP->Product, 'customer_available_to', array('name' => 'SupplierProducts[' . $SPP->supplier_product_id . '][customer_available_to]')); ?>
private function _doUpdate(&$model) { $SupplierProduct = new SupplierProduct(); if (isset($_POST['SupplierProduct']) && !empty($_POST['SupplierProduct']['name'])) { $SupplierProduct->attributes = $_POST['SupplierProduct']; $SupplierProduct->supplier_id = $_POST['supplier_id']; $SupplierProduct->save(); } if (isset($_POST['SupplierPurchase'])) { $model->attributes = $_POST['SupplierPurchase']; if (!empty($SupplierProduct->id)) { $model->supplier_product_id = $SupplierProduct->id; } if ($model->save()) { $this->redirect(array('admin', 'id' => $model->id)); } } }
<?php foreach ($model->Products as $SPP) { ?> <?php echo $this->renderPartial('_spp_form', array('SPP' => $SPP, 'supplier_id' => $model->supplier_id)); ?> <?php } ?> </div> <div id="add-product-form"> <div class="form-group"> <div class="col-md-2"> <?php echo BsHtml::dropDownList('supplier_product_id', null, SupplierProduct::getDropdownListItems($model->supplier_id), array('class' => 'chosen', 'prompt' => '- Select -')); ?> </div> <div class="col-md-6"> <?php echo BsHtml::submitButton('Add Product', array('class' => 'add-product', 'name' => 'add_product')); ?> <!-- Button trigger modal --> <button class="btn btn-default" data-toggle="modal" data-target="#sp-form"> Create New Product </button> </div> </div> </div> <hr />
public function actionGetListItems($supplierId = null) { $items = SupplierProduct::getDropdownListItems($supplierId); echo json_encode($items); exit; }
/** * @param integer $id the ID of the model to be displayed */ public function actionDontWant($id, $cat = null, $product = null, $like = null) { $model = $this->loadModel($id); if (!Yii::app()->user->checkAccess('Admin') && $model->id != Yii::app()->user->id) { throw new CHttpException(403, 'Access Denied.'); } if (!$cat) { $cat = SnapUtil::config('boxomatic/supplier_product_feature_category'); } if ($product) { $model->DontWant = array_merge($model->DontWant, array($product)); $model->save(); $model->refresh(); } if ($like) { $newArr = array(); foreach ($model->DontWant as $Product) { if ($Product->id != $like) { $newArr[] = $Product->id; } } $model->DontWant = $newArr; $model->save(); $model->refresh(); } $Category = Category::model()->findByPk($cat); if ($cat == Category::uncategorisedCategory) { $SupplierProducts = SupplierProduct::getUncategorised(); } else { $SupplierProducts = $Category->SupplierProducts; } $dontWantIds = array(); foreach ($model->DontWant as $SP) { $dontWantIds[$SP->id] = $SP; } $this->render('dont_want', array('model' => $model, 'curCat' => $cat, 'Category' => $Category, 'SupplierProducts' => $SupplierProducts, 'dontWantIds' => $dontWantIds)); }
/** * 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 = SupplierProduct::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }