/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($main_item_id)
 {
     $model = new OutboundItemsHistory();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $model->main_item_id = $main_item_id;
     if (isset($_POST['OutboundItemsHistory'])) {
         $model->attributes = $_POST['OutboundItemsHistory'];
         if ($model->save()) {
             $available_quantity = $model->available_quantity_in_stock - $model->quantity_moved;
             $current_quantity = $model->current_quantity_in_stock - $model->quantity_moved;
             //$q_moved=$model->quantity_moved;
             $itemModel = Items::model()->updateByPk($model->main_item_id, array('available_quantity' => $available_quantity + $model->quantity_moved, 'current_quantity' => $current_quantity + $model->quantity_moved));
             //if($model->save())
             $this->redirect(array('view', 'id' => $model->history_id_item));
         }
     }
     $this->render('create', array('model' => $model));
     /*original
     		if(isset($_POST['OutboundItemsHistory']))
     		{
     			$model->attributes=$_POST['OutboundItemsHistory'];
     			if($model->save())
     				$this->redirect(array('view','id'=>$model->history_id_item));
     		}
     
     		$this->render('create',array(
     			'model'=>$model,
     		));*/
 }
Пример #2
0
 public function actionView()
 {
     $slug = Yii::app()->request->getParam('slug');
     $criteria = new CDbCriteria();
     $criteria->condition = 'itm_slug=:itm_slug';
     $criteria->params = array(':itm_slug' => $slug);
     $model = Items::model()->find($criteria);
     $this->render('view', array('model' => $model));
 }
Пример #3
0
 public function getIAlltems()
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     // $criteria=new CDbCriteria;
     // $criteria->compare('item_id',$this->item_id);
     // $criteria->compare('name',$this->name);
     return $Items = Items::model()->findAll();
 }
 public function actionCreate()
 {
     Yii::app()->clientScript->registerPackage('items-edit');
     if (!isset($_GET['id']) || NULL == ($model = Items::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'id' => (int) $_GET['id'])))) {
         $model = new Items();
     }
     if (isset($_POST['Items'])) {
         $model->attributes = $_POST['Items'];
         $fn = Files::model()->uploadFile('Items[image]');
         if ($fn) {
             $model->image = $fn['filename'];
         } elseif (isset($_POST['Items']['image_src'])) {
             $model->image = $_POST['Items']['image_src'];
         }
         $new = $model->isNewRecord;
         if ($model->save()) {
             $cats = isset($_POST['categories']) ? $_POST['categories'] : array();
             if (!$new && empty($cats)) {
                 ItemsCategory::model()->deleteAllByAttributes(array('item_id' => $model->id));
             } else {
                 if (!$new) {
                     $dbcats = ItemsCategory::model()->findAll('item_id=:iid', array('iid' => $model->id));
                     $ids = array();
                     foreach ($dbcats as $i => $dbc) {
                         if (false !== ($k = array_search($dbc->category_id, $cats))) {
                             unset($cats[$k]);
                             unset($dbc[$i]);
                         } else {
                             $ids[] = $dbc->category_id;
                         }
                     }
                     //deleteing corresponding categories
                     if (!empty($ids)) {
                         $ids = implode(",", $ids);
                         ItemsCategory::model()->deleteAll('item_id=:iid AND category_id IN (:cid)', array('iid' => $model->id, 'cid' => $ids));
                     }
                 }
                 if (!empty($cats)) {
                     foreach ($cats as $cat) {
                         $c = new ItemsCategory();
                         $c->attributes = array('category_id' => $cat, 'item_id' => $model->id);
                         $c->save();
                     }
                 }
             }
             Yii::app()->user->setFlash('ItemSaved', '1');
             $this->refresh();
         }
     }
     $this->render('_form', array('model' => $model));
 }
 public function actionCreate()
 {
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true);
     $items = Items::model()->findAll();
     foreach ($items as $item) {
         $doc = new Zend_Search_Lucene_Document();
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         $doc->addField(Zend_Search_Lucene_Field::keyword('part_number', CHtml::encode($item->part_number), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('name', CHtml::encode($item->name), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('description', CHtml::encode($item->description), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('barcode', CHtml::encode($item->barcode), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::float('available_quantity', CHtml::encode($item->available_quantity), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::float('current_quantity', CHtml::encode($item->current_quantity), 'utf-8'));
         $index->addDocument($doc);
     }
     $index->commit();
     echo 'Lucene index created';
 }
Пример #6
0
 public function processCart()
 {
     $cart_items = Yii::app()->session['cartItems'];
     $fabrics = array();
     $items = array();
     if (!empty($cart_items)) {
         $fabricIds = array();
         $itemIds = array();
         foreach ($cart_items as $key => $cartArr) {
             if ($key == 'fabric') {
                 foreach ($cartArr as $fabId => $fabArr) {
                     $fabricIds[] = $fabId;
                 }
             }
             if ($key == 'item') {
                 foreach ($cartArr as $itemId => $itemArr) {
                     $itemIds[] = $itemId;
                 }
             }
         }
         $fabCriteria = new CDbCriteria();
         $itmCriteria = new CDbCriteria();
         $fabIds = '';
         if (!empty($fabricIds)) {
             $fabIds = implode(',', $fabricIds);
             $fabCriteria->condition = 'fab_id in (' . $fabIds . ')';
             $fabrics = Fabrics::model()->findAll($fabCriteria);
         }
         $itmIds = '';
         if (!empty($itemIds)) {
             $itmIds = implode(',', $itemIds);
             $itmCriteria->condition = 'itm_id in (' . $itmIds . ')';
             $items = Items::model()->findAll($itmCriteria);
         }
     }
     $data['items'] = $items;
     $data['fabrics'] = $fabrics;
     return $data;
 }
<div class="form">

<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'item-on-order-form', 'enableAjaxValidation' => false));
?>

<?php 
/**COLLECTING THE DATA*/
$purchase_id = $_GET['po_id'];
$item_id = $_GET['item_id'];
$model->purchase_order_id = $purchase_id;
$model->items_id = $item_id;
//*SINCE FIRST STATUS OF ITEM IS DRAFT*//
$model->item_status = 1;
/*THIS IS FOR THE CURRENT ITEMS Which is being added*/
$itemModel = Items::model()->findByPk($item_id);
$purchaseModel = PurchaseOrder::model()->findByPk($purchase_id);
/*THIS IS To get the items which are already orrderd**/
$items_on_order_model = PurchaseOrder::model()->getItemsOnOrder($purchase_id);
$model->suppliers_id = $purchaseModel->suppliers_id;
$model->unit_price = $itemModel->sale_price;
?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

<!-- FIRST PART OF THE FORM WHICH DISPLAYS PURCHASE ORDER DETAILS --> 
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $this->created = time();
             $this->total_price = $this->unit_price * $this->quantity_ordered;
             $x = $this->unit_price;
             $itemModel = Items::model()->updateByPk($this->items_id, array('sale_price' => $x));
         } else {
             $x = $this->unit_price;
             $itemModel = Items::model()->updateByPk($this->items_id, array('sale_price' => $x));
             $this->modified = time();
         }
         return true;
     } else {
         return false;
     }
 }
 public function actionJsonSearch($keyword)
 {
     /*$model=new Items('freeSearch');
     //		$keyword=$_GET['search_data'];
     				$keyword=$_GET['search_data'];
     			//$this->render('jsonSearch', array('results' => $results));
     		//echo "key value is ".$keyword;	
     //		$this->render('jsonSearch',array('model'=>$model,
     //										 'dataProvider'=>results,
     //										 ));
     
     
     //		if(isset($_GET['search_data']))
     //		{
     			
     //			$keyword=$_GET['search_data'];
     			//$model->=$_GET['Items'];
     //	   		$this->render('admin',array(
     //			'model'=>$model,
     //			));
     //			
     			//echo "key value is ".$keyword;
     //			echo "key value is ".$keyword;
     			//$keyword=$id;
     			//$this->render('jsonSearch',array('model'=>$model,));
     //		}*/
     $model = Items::model()->freeSearch($keyword);
     //echo "I  M ".$keyword;
     $this->render('jsonSearch', array('model' => $model));
 }
Пример #10
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 = Items::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function freeSearch($keyword)
 {
     /*Creating a new criteria for search*/
     $criteria = new CDbCriteria();
     $criteria->compare('name', $keyword, true, 'OR');
     $criteria->compare('barcode', $keyword, true, 'OR');
     $criteria->compare('part_number', $keyword, true, 'OR');
     /*result limit*/
     $criteria->limit = 100;
     /*When we want to return model*/
     return Items::model()->findAll($criteria);
     /*To return active dataprovider uncomment the following code*/
     /*
     return new CActiveDataProvider($this, array(
     	'criteria'=>$criteria,
     ));
     */
 }
 public function actionUpdateStatus($id)
 {
     echo 'ID ID ' . $id;
     if (!empty($_GET['all_recieved'])) {
         $all_recieved = $_GET['all_recieved'];
     }
     if ($id == 0 && $all_recieved == 'true') {
         $purchase_id = $_GET['purchase_id'];
         echo $purchase_id;
         $items_on_order_model = PurchaseOrder::model()->getItemsOnOrder($purchase_id);
         foreach ($items_on_order_model as $ordered_items) {
             $item_id = $ordered_items->id;
             echo '<hr>ITEM IUS IS     ' . $item_id;
             if ($ordered_items->item_status == 2) {
                 ItemOnOrder::model()->updateByPk($item_id, array('item_status' => 3, 'quantity_recieved' => $ordered_items->quantity_ordered));
             }
             //end of if
         }
         //end of foreach
         $this->redirect(array('/purchaseOrder/orderRecieved/', 'id' => $purchase_id));
     } else {
         $model = $this->loadModel($id);
         $current_quantity_recieved = $model->quantity_recieved;
         if (isset($_POST['ItemOnOrder'])) {
             $model->attributes = $_POST['ItemOnOrder'];
             $status = $model->item_status;
             $diff = $model->ordered_recieved_difference;
             $model->quantity_recieved = $model->quantity_recieved + $diff;
             $quantity_recieved = $model->quantity_recieved;
             $quantity_ordered = $model->quantity_ordered;
             echo "<br> QUANTIY RECIEVED  " . $quantity_recieved;
             echo "<br> QUANTIY ORDERED  " . $quantity_ordered;
             echo "<br> DIFF  " . $diff;
             /*
              * WE have set the flag as 3 for recieved and 6 for damaged
              * we will do funny calculations based on that
              * 
              */
             if ($status == 3) {
                 $comments = $diff . ' recieved. ';
                 //$comments.=' under the purchase order number '.$model->purchaseOrder->order_number;
                 $comments .= ' Processed by ' . Yii::app()->user->name . " on " . date("d-M-y H:i") . '<br>';
                 $model->comments .= $comments;
                 if ($quantity_ordered == $quantity_recieved) {
                     $model->item_status = 3;
                     //i.e. all items are recieved
                 } elseif ($quantity_ordered > $quantity_recieved) {
                     $model->item_status = 4;
                     ////i.e. partiually recieved
                     echo "RECIEVD is  " . $model->quantity_recieved;
                 } elseif ($quantity_ordered < $quantity_recieved) {
                     $model->item_status = 2;
                     //status reset
                 } else {
                     $this->redirect(array('/purchaseOrder/orderRecieved/', 'id' => $purchase_id));
                 }
                 //end of else
             }
             //end of if of status 50
             if ($status == 6) {
                 /*THIS MEANS ALL PARTS WERE DAMAGED*/
                 if ($quantity_ordered == $quantity_recieved) {
                     $model->item_status = 6;
                 } else {
                     $model->item_status = 7;
                     //this is partially damaged item model
                 }
                 //echo 'QUANTITRY DAMAGED  '.$diff;
                 $model->quantity_damaged = $diff;
                 $model->quantity_recieved = $current_quantity_recieved;
                 //$model->quantity_recieved=0.0;
                 /*THIS IS DONE, else the system will store in quantity recieved also*/
                 //$model->quantity_recieved=$current_quantity_recieved;
                 //	echo 'QUANTITRY Recieved'.$model->quantity_recieved;
                 $comments = $diff;
                 $comments .= ' damaged. ';
                 $comments .= ' Processed by: ' . Yii::app()->user->name . " on " . date("d-M-y H:i") . '<br>';
                 $quantity_recieved = 0.0;
                 $model->comments .= $comments;
             }
             ///end of if status 51
             /*IF any quantity is recieved it wil be added to inbound and the items details will also be updated*/
             if ($quantity_recieved > 0) {
                 echo 'Logic to add in inbound';
                 $inbound_model = new InboundItemsHistory();
                 $main_item_id = $model->items_id;
                 $item_model = Items::model()->findByPk($main_item_id);
                 $current_stock = $item_model->current_quantity;
                 $available_stock = $item_model->available_quantity;
                 $quantity_moved = $quantity_recieved;
                 $inbound_model->main_item_id = $model->items_id;
                 $inbound_model->quantity_moved = $quantity_recieved;
                 $inbound_model->items_on_order_id = $model->id;
                 $inbound_model->comments .= $comments . 'Purchase Order Number =' . $model->purchaseOrder->order_number;
                 $inbound_model->available_quantity_in_stock = $quantity_moved + $available_stock;
                 $inbound_model->current_quantity_in_stock = $quantity_moved + $current_stock;
                 if ($inbound_model->save()) {
                     echo 'saved';
                     Items::model()->updateByPk($main_item_id, array('available_quantity' => $quantity_moved + $available_stock, 'current_quantity' => $quantity_moved + $current_stock));
                 } else {
                     echo 'NOT SAVING INBOUND ENTRY';
                 }
             }
             //end of logic to make entry in inbound
             if ($model->save()) {
                 $this->redirect(array('/purchaseOrder/orderRecieved/', 'id' => $model->purchase_order_id));
             }
             ///end of save
             // 			$redirect_url='/purchaseOrder/orderRecieved/'.$purchase_id;
             // 			$url=$this->createUrl($redirect_url);
             // 			$this->redirect($url);
         } else {
             $item_status = $_GET['item_status'];
             $purchase_id = $_GET['purchase_id'];
             $comments = $_GET['comments'];
             $comments .= '<br>Status Reset to On Order by: ' . Yii::app()->user->name . " on " . date("d-M-y H:i") . '<br>';
             echo 'THIS IHJS CPDE   ' . $item_status;
             ItemOnOrder::model()->updateByPk($id, array('item_status' => $item_status, 'quantity_recieved' => '0.0', 'comments' => $comments));
             $this->redirect(array('/purchaseOrder/orderRecieved/', 'id' => $purchase_id));
         }
         //end of else _POST
     }
     //end of else id=0
 }
 public function updateitemstable($id, $stockvalue)
 {
     $itemModel = Items::model()->findByPk($id);
     $itemModel->updateByPk($id, array('available_quantity' => $stockvalue, 'current_quantity' => $stockvalue));
     echo '<hr>' . $itemModel->available_quantity . "<BR>" . $itemModel->current_quantity;
 }