/**
* 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=Purchaseproduct::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
Exemple #2
0
 private function addorupdatePurchaseLineItems($order, $postedData, &$rolproducts){
     $this->deletePurchaselitemsByPurchase($order->id);
     $totalamount = 0;
     $totaltaxamount = 0;
     foreach($postedData->purchaseproducts as $ordprod){
         $qnty = $ordprod->quantity;
         $vldqnty = (is_numeric($qnty) && $qnty > 0);
         if(!$vldqnty){
             continue;
         }
         $prd = \Product::find($ordprod->product_id);
         if(!$prd){
             continue;
         }
         if($prd->rol >= ($prd->stock + $qnty)){
             $rolproducts[] = $prd->name;
         }
         $unit_cp = $ordprod->unit_cp;
         $amount = $qnty * $unit_cp;
         $taxamount = $amount * $prd->taxper / 100 ;
         $attributes = array(
                 "purchase_id" => $order->id,
                 "product_id" => $ordprod->product_id,
                 "quantity" => $ordprod->quantity,
                 "unit_cp" => $unit_cp,
                 "amount" => $amount,
                 "tax" => $taxamount,
                 );
         $data = \Purchaseproduct::create($attributes);
         $totalamount += $amount;
         $totaltaxamount += $taxamount;
         if($this->enablestock){
             $newstock= $prd->stock + $qnty;
             $attributes = array(
                 "stock" => $newstock,
                 "stockvalue" => $newstock * $unit_cp);
             $prd->update_attributes($attributes);
         }
     }
     //updating order amounts with lineitems
     $taxper = $totaltaxamount / $amount * 100.0;//average tax % on this order
     $this->updateAmntTaxInPurchase($order, $totalamount, $taxper, $totaltaxamount);
 }