/**
     * Creates a new model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     */
    public function actionCreate()
    {
        $model = new Productstockhistory;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

        if ( isset( $_POST['Productstockhistory'] ) )
        {
            $model->attributes = $_POST['Productstockhistory'];
            if ( $model->save() )
                $this->redirect( array( 'view', 'id' => $model->id ) );
        }

        $this->render( 'create', array(
            'model' => $model,
        ) );
    }
 public function updateStockchangeHistory($productprice, $oldstock)
 {
     $date = date($this->datetimemysqlformatYMDHIS);
     $prdid = $productprice->product_id;
     $prdprcid = $productprice->id;
     $newstock = $productprice->stock;
     $history = new Productstockhistory;
     $history->product_id = $prdid;
     $history->productprice_id = $prdprcid;
     $history->updationdate = $date;
     $history->beforeupdation = $oldstock;
     $history->afterupdation = $newstock;
     $history->updatedqnty = $newstock - $oldstock;
     return $history->save();
 }