add discount to product sell js
This commit is contained in:
@@ -65,7 +65,7 @@ class DiscountController extends Controller
|
||||
$model->status = Discount::STATUS_ACTIVE;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_warehouse]);
|
||||
return $this->redirect(['view', 'id' => $model->id_discount]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
@@ -84,7 +84,7 @@ class DiscountController extends Controller
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_warehouse]);
|
||||
return $this->redirect(['view', 'id' => $model->id_discount]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
|
||||
@@ -18,7 +18,7 @@ class DiscountSearch extends Discount
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_warehouse', 'status', 'type', 'value'], 'integer'],
|
||||
[['id_discount', 'status', 'type', 'value'], 'integer'],
|
||||
[['name', 'created_at', 'updated_at'], 'safe'],
|
||||
];
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class DiscountSearch extends Discount
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_warehouse' => $this->id_warehouse,
|
||||
'id_discount' => $this->id_discount,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
'value' => $this->value,
|
||||
|
||||
@@ -9,7 +9,7 @@ $this->title = Yii::t('common/discount', 'Update {modelClass}: ', [
|
||||
'modelClass' => 'Discount',
|
||||
]) . ' ' . $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_warehouse]];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_discount]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/discount', 'Update');
|
||||
?>
|
||||
<div class="discount-update">
|
||||
|
||||
@@ -15,9 +15,9 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/discount', 'Update'), ['update', 'id' => $model->id_warehouse], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a(Yii::t('common/discount', 'Update'), ['update', 'id' => $model->id_discount], ['class' => 'btn btn-primary']) ?>
|
||||
<?php
|
||||
/* Html::a(Yii::t('common/discount', 'Delete'), ['delete', 'id' => $model->id_warehouse], [
|
||||
/* Html::a(Yii::t('common/discount', 'Delete'), ['delete', 'id' => $model->id_discount], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/discount', 'Are you sure you want to delete this item?'),
|
||||
|
||||
16
common/components/Helper.php
Normal file
16
common/components/Helper.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use yii\base\InvalidConfigException;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
class Helper
|
||||
{
|
||||
|
||||
public static function hufRound($m){
|
||||
$result = round($m/5, 0) * 5;
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -237,7 +237,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
* @param $currency common\models\Currency
|
||||
* @param $product common\models\Product
|
||||
* */
|
||||
public static function createProductTransfer($account, $discount, $currency, $count,$product ){
|
||||
public static function createProductTransfer($account, $discount, $currency, $count,$product , $status = Transfer::STATUS_PAID){
|
||||
$transfer = new Transfer();
|
||||
|
||||
$transfer->type = Transfer::TYPE_PRODUCT;
|
||||
@@ -262,6 +262,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
$transfer->money_currency = Currency::applyCurrency($totalPrice, $currency);
|
||||
}
|
||||
|
||||
$transfer->direction = Transfer::DIRECTION_IN;
|
||||
$transfer->status = $status;
|
||||
|
||||
$transfer->id_account = $account->id_account;
|
||||
|
||||
return $transfer;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m151020_164936_alter__table__discount__timestamps extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->alterColumn('discount', 'created_at', 'datetime' );
|
||||
$this->alterColumn('discount', 'updated_at', 'datetime' );
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m151020_164936_alter__table__discount__timestamps cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -60,7 +60,6 @@ class ProductSaleForm extends Model
|
||||
[['id_currency' ], 'validateCurrency'],
|
||||
[['id_account' ], 'validateAccount'],
|
||||
[['id_discount' ], 'validateDiscount'],
|
||||
[['id_discount' ], 'validateDiscount'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -130,6 +129,10 @@ class ProductSaleForm extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
// protected function applyDiscount(){
|
||||
// Discount::applyDiscount($this->, $discount);
|
||||
// }
|
||||
|
||||
protected function saveTransfer(){
|
||||
|
||||
$this->transfer = Transfer::createProductTransfer($this->account, $this->discount, $this->currency, $this->count, $this->product);
|
||||
|
||||
@@ -368,7 +368,7 @@ function ProductSell(o){
|
||||
function findDiscount(id_discount){
|
||||
var discount;
|
||||
discount = null;
|
||||
$.each( app.defaults.discounts , function(e,i){
|
||||
$.each( app.defaults.discounts , function(i,e){
|
||||
if ( e.id_discount == id_discount ){
|
||||
discount = e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user