Beispiel #1
0
 public function getProductPriceCodeLookup()
  {
      $code = Subproductprice::model()->findAll();
      $code = CHtml::listData($code, 'code', 'code');
      return $code;
  }
     public function actionGetAllProducts()
    {
        $json = new CArJSON;
        
        $criteria=new CDbCriteria;
        $criteria->order='id asc';
        $criteria->addCondition('parent_id = 0 and status=1');
        $catwithproducts = Category::model()->findAll($criteria);
                
        $prdcondition = array('condition'=>'t.status = 1 AND product.status = 1');
        $products = Subproductprice::model()->with('product')
                                ->findAll($prdcondition);
        $prdcondition_non_mngd = array('condition'=>'t.status = 1 
            AND product.status = 1 AND t.dontsyncwithstock = 1');
        $non_mngd_products = Productprice::model()->with('product')
                                ->findAll($prdcondition_non_mngd);
        if(!empty($catwithproducts)
            && !empty($products)
        )
        {
            //$relations = array(array('categories'=>array(array('products'=>array('taxrate')))));
            $relations = array(array('categories'=>array('subproductprices')));
            $attributes = array(
                'root' => array(),//null,//array of attribute names
                'categories' => array(),
                'subproductprices' => $this->prdcolumns,
            );
            $isarray = true;
            $iskeybasedarray = true;
            $sec_cat_products = $json->toJSON($catwithproducts, 
                    $relations, $attributes, $isarray, $iskeybasedarray);

            $relations = array();
            $attributes = array(
                'root' => $this->prdcolumns,                
            );
            $isarray = true;
            $iskeybasedarray = true;
            $non_mngd_products = $json->toJSON($non_mngd_products, 
                    $relations, $attributes, $isarray, $iskeybasedarray);
            
            $relations = array();
            $attributes = array(
                'root' => array('value','label'),
            );
            $isarray = true;
            $iskeybasedarray = false;
            $allproducts_short = $json->toJSON($products, 
                    $relations, $attributes, $isarray, $iskeybasedarray);

            $customercondition = array();
            $customers = $this->getAllPeopleNoRestriction(Helper::CONST_Customer);            
            $allcustomers = CHtml::listData($customers, 'id', 'name');
            
            $dfltcustomerid = $this->getPersonByName(Helper::CONST_Walk_in_Customer);
            $data = array(
                //Helper::CONST_prdskuToIdMap => $prdskuToIdMap,
                Helper::CONST_allproducts_short => $allproducts_short,
                Helper::CONST_non_mngd_products => $non_mngd_products,
                Helper::CONST_sec_cat_products => $sec_cat_products,
                Helper::CONST_allcustomers => $allcustomers,
                Helper::CONST_default_customer_id => $dfltcustomerid
            );
            $rtnCode = Helper::CONST_Error_None;
            $message = Helper::CONST_POS_Masters;
        }
        else
        {
            $data = array(
                        Helper::CONST_allproducts_short => array(),
                        Helper::CONST_non_mngd_products => array(),
                        Helper::CONST_sec_cat_products => array(),
                        Helper::CONST_allcustomers => array(),
                        Helper::CONST_default_customer_id => -1
                    );
            $rtnCode = Helper::CONST_Error_None; 
            $message = Helper::CONST_NotFound_Message;
        }
//        $edata = $this->getJsonOfData($rtnCode, $data, $message);
//        $this->writeToCookie(Helper::CONST_sec_cat_products, $edata);        
        $this->returnJsonResponse($rtnCode, $data, $message);
    }
       public function updateProductInDB($model, $extcatid, $extimgpath, 
            $dealPrices = false, $newprices = array(), 
            $removedprices=array(), $existingprices = array()
    )
    {
           $imagepath=null;     
            $isnew = empty($model->id);
            if((!$isnew)&&($extimgpath == '')){
        $rowsqlCategory = "select imagepath from products where id=$model->id";
           $imagepath = Yii::app()->db->createCommand( $rowsqlCategory )->queryScalar();}       
        $rtn = false;
        $trans = Yii::app()->db->beginTransaction();
        try {
            if($isnew)
            {
                if($this->getEnableautoprdcode())
                {
                    $productcode = $this->generateCode(1, $model->name);
                }else{
                    $productcode = $model->code;
                }
            }else{
                $productcode = $model->code;                
            }
            $model->code = $productcode;            
            $rtn = $model->save(false,$model);
            if ( $rtn )
            {
                //$rtn = $this->saveOrUpdatePrdCat($model, $extcatid);
                if($rtn){
                    $uploadedFile=CUploadedFile::getInstance($model,'imagepath'); 
                    if(!empty($uploadedFile))  // check if uploaded file is set or not
                    {
                        $fileName = $uploadedFile->name;
                        $model->imagepath = $fileName;
                        $chk=$model->imagepath ;
                         $model->person_id = 1;
                        $rtn = $model->save();
                        $uploadedFile->saveAs($this->imageRealPath . $fileName);
                    }
                    else
                    {
                        if(!$isnew)
                        {
                            $model->person_id = 1;
                            $model->imagepath = $extimgpath;
                            $chk=$model->imagepath ;
                            //$this->performAjaxValidation($model);
                            if(count($imagepath)>0){
                            $model->imagepath =$imagepath;
                            }
                            $rtn = $model->save();
                        }
                    }
                    if($rtn){
                        // if($dealPrices)
                        // {
                            if($rtn)
                            {
		             $prdPriceForm1=array();
			     $prdPriceId=array();
	                     $criteria=new CDbCriteria;
								    $condition = ' product_id = '. '"'.$model->id.'"';
									$criteria->condition = $condition;
									$productprice = Subproductprice::model()->findAll($criteria);
									foreach ($productprice as $prdpriceid)
										{
										$prdPriceId []=$prdpriceid['id'];
										}	
                                foreach ($newprices as $newprc)
                                {				
								          if($newprc['id']>0){								  
				                          $prdPriceForm1 []=$newprc['id'];										 
                                          $condition = 'id=' .$newprc['id'];
                                           $criteria = new CDbCriteria;
                                           $criteria->condition = $condition;
                                           $productPrice = Subproductprice::model()->findAll( $criteria );
                                           $condition_prdSku='sku=' .'"'.$productPrice[0]->sku.'"';
                                           $condition_poslogSku='barcode=' .'"'.$productPrice[0]->sku.'"';
                                           $this->fillPriceFromPostToModel($productPrice[0], $newprc, true);                                          
				           $productPrice[0]->product_id = $model->id;
                                           $rtn =$productPrice[0]->save(false,null);										  
                                           $condition_prdcat = 'productprice_id=' .$newprc['id'];
                                           $command = Yii::app()->db->createCommand();
				           $command->update('masterproductcategories', array(
					'category_id'=>$newprc['category_id'],'product_id'=>$newprc['product_id']
											), $condition_prdcat, array());
						 $command->update('productprices', array(
                                       'code'=>$newprc['code'],'sku'=>$newprc['sku']
                                                                                       ), $condition_prdSku, array());
                                                 $command->update('poslogreport', array(
                                       'barcode'=>$newprc['sku']), $condition_poslogSku, array());
					
                                    }else{									
									 $prdprc = new Subproductprice;
									 $prdprc->product_id = $model->id;
                                     $this->fillPriceFromPostToModel($prdprc, $newprc, true);
                                   $rtn = $prdprc->save(false,null);
	                            $rtn = $this->saveOrUpdatePrdprcCat($prdprc, $extcatid, $model->category_id);
                                    }
									
                                    // $prdprc = new Subproductprice;
                                    // $prdprc->product_id = $model->id;
                                    // $this->fillPriceFromPostToModel($prdprc, $newprc, true);
                                    // $rtn = $prdprc->save(false,null);
                                    // if(!$rtn)
                                    // {
                                        // $this->msg = $prdprc->getErrors();
                                        // break;
                                    // }
                                    // $rtn = $this->saveOrUpdatePrdprcCat($prdprc, $extcatid, $model->category_id);
                                    if(!$rtn) break;
                                }  	//*************DELETION PART************************
								//echo json_encode($prdPriceId);
								//echo json_encode(array(count($prdPriceId),count($prdPriceForm)));exit;
								//if(count($prdPriceId)!== count($prdPriceForm1)){
								if(5!== 5){
$diff_prddb_prdfrm = array_diff($prdPriceId, $prdPriceForm1);
$j=0;
foreach ($prdPriceId as $deletePrdid){
 $isnewss = !empty($diff_prddb_prdfrm[$j]);
 if($isnewss){
    $command = Yii::app()->db->createCommand();
$command->delete('subproductprices', 'id=:id', array(':id'=>$diff_prddb_prdfrm[$j]));
$condition_prdcat = 'productprice_id=' .$diff_prddb_prdfrm[$j];
$command->delete('masterproductcategories', $condition_prdcat, array());
									   //$command->update('productcategories', $condition_prdcat, array());
}
$j++;
} 
//echo $k;exit;
}
								$trans->commit(); 
                            }
                        // }
//                        if($rtn){
//                            try{
//                                $this->setProductsLookupInState();//refresh
//                            }catch (Exception $e) {
//
//                            }
//                        }                        
                    }
                }else{
                    Yii::log("Error occurred while saving/activating product. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
                }
            } else
            {
                $model->code = null;
                $this->msg = $model->getErrors();
            }
        }catch (Exception $e) {
            $rtn = false;
            Yii::log("Error occurred while saving/activating product. Rolling back... . Failure reason as reported in exception: " . $e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__);
        }  
        return $rtn;
    }
	/**
	 * 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 $id the ID of the model to be loaded
	 * @return Subproductprice the loaded model
	 * @throws CHttpException
	 */
	public function loadModel($id)
	{
		$model=Subproductprice::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
	public function actionGetSubProductlist(){
        $postedData = $this->getPostedData();
         $productdata = Product::model()->findByPk( $postedData['productId'] );
            if(count($productdata) > 0)
        {
            $criteria = new CDbCriteria;
            $condition = 'product_id='.$postedData['productId'];
            $criteria->condition = $condition;
	    $productprice = Subproductprice::model()->findAll($criteria);
        }  
        $json = new CArJSON;            
        $relations = array();
            $attributes = array(
                'root' => array()                
            );
            $isarray = true;
              $product = $json->toJSON($productdata, $relations, $attributes, $isarray);
			     $relations = array();
            $attributes = array(
                'root' => array()				
            );
              $isarray = true;
              $productprice = $json->toJSON($productprice, $relations, $attributes, $isarray);
                $rtnCode = Helper::CONST_Error_None;
            $message = Helper::CONST_NotFound_Message;
            $criteria = new CDbCriteria;
            $criteria->select = array('id','taxname');
	    $taxrates = Taxrate::model()->findAll($criteria);
            $json = new CArJSON;            
        $relations = array();
            $attributes = array(
                'root' => array()                
            );
            $isarray = true;
              $taxrates = $json->toJSON($taxrates, $relations, $attributes, $isarray);
    $data = array(
               //Helper::CONST_prdskuToIdMap => $prdskuToIdMap,
               Helper::CONST_allproducts_short => $product,
               Helper::CONST_sec_cat_products => $productprice,'tax'=>$taxrates);
       	   $this->returnJsonResponse($rtnCode, $data, $message);
   
    }
        public function actionAdjsearch()
	{               
                $id=$_GET['id'];
                
                            $model=Subproductprice::model()->findByPk($id);
          		$this->render('Adjsearch',array(
			'model'=>$model,
		));               
	}