sell product changes

This commit is contained in:
2015-10-05 07:37:17 +02:00
parent e9f9567618
commit 36c8d37914
18 changed files with 704 additions and 141 deletions

View File

@@ -3,6 +3,7 @@
namespace common\models;
use Yii;
use yii\base\Object;
/**
* This is the model class for table "transfer".
@@ -10,6 +11,7 @@ use Yii;
* @property integer $id_transfer
* @property integer $id_discount
* @property integer $id_currency
* @property integer $id_account
* @property integer $id_object
* @property integer $status
* @property integer $type
@@ -29,6 +31,9 @@ class Transfer extends \yii\db\ActiveRecord
const TYPE_PRODUCT = 10;
const TYPE_TICKET = 20;
const STATUS_NOT_PAID = 10;
const STATUS_PAID = 20;
/**
* @inheritdoc
*/
@@ -72,4 +77,70 @@ class Transfer extends \yii\db\ActiveRecord
'updated_at' => Yii::t('common/transfer', 'Updated At'),
];
}
public function getProduct(){
return $this->hasOne( Product::className(), ["id_product" =>"id_object" ] );
}
public function getAccount(){
return $this->hasOne( Account::className(), ["id_account" =>"id_account" ] );
}
public function getCurrency(){
return $this->hasOne( Currency::className(), ["id_currency" =>"id_currency" ] );
}
public function getDiscount(){
return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
}
public function toProductSoldString(){
$s = "";
$s .= $this->count;
$s .= " " . Yii::t('frontend/transfer', 'pieces') . " ";
$s .= $this->product->name;
$s .= " - ";
$s .= $this->account->name;
return $s;
}
/**
* @param $account common\models\Account
* @param $discount common\models\Discount
* @param $currency common\models\Currency
* @param $product common\models\Product
* */
public static function createProductTransfer($account, $discount, $currency, $count,$product ){
$transfer = new Transfer();
$transfer->type = Transfer::TYPE_PRODUCT;
$transfer->id_object = $product->id_product;
$transfer->item_price = $product->sale_price;
$totalPrice = $transfer->item_price;
$transfer->count = $count;
$totalPrice = $totalPrice * $count;
if ( isset( $discount ) ){
$transfer->id_discount = $discount->id_discount;
$totalPrice = Discount::applyDiscount( $totalPrice, $discount);
}
$transfer->money = $totalPrice;
if ( isset( $currency ) ){
$transfer->rate = $currency->rate;
$transfer->money_currency = Currency::applyCurrency($totalPrice, $currency);
}
$transfer->id_account = $account->id_account;
return $transfer;
}
}