add inventory admin fix, add procurement update

This commit is contained in:
2016-03-30 20:04:49 +02:00
parent 19761cb0cc
commit a12b87d3be
22 changed files with 853 additions and 245 deletions

View File

@@ -8,6 +8,7 @@ use yii\helpers\ArrayHelper;
use yii\db\Query;
use backend\models\InventoryItemForm;
use common\components\AccountAwareBehavior;
use common\components\Helper;
/**
* This is the model class for table "inventory".
@@ -15,6 +16,7 @@ use common\components\AccountAwareBehavior;
* @property integer $id_inventory
* @property integer $id_user
* @property integer $id_account
* @property integer $status
* @property string $name
* @property string $created_at
* @property string $updated_at
@@ -22,6 +24,9 @@ use common\components\AccountAwareBehavior;
class Inventory extends \common\models\BaseFitnessActiveRecord
{
public static $STATUS_OPEN = 10;
public static $STATUS_CLOSED = 20;
/**
* @inheritdoc
@@ -40,6 +45,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return [
[['name'], 'string'],
[['id_account'], 'integer'],
[['name'], 'validateOnlyClosed'],
];
}
@@ -51,6 +57,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return [
'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'),
'name' => Yii::t('common/inventory', 'Megnevezés'),
'status' => Yii::t('common/inventory', 'Státusz'),
'id_user' => Yii::t('common/inventory', 'Felhasználó'),
'id_account' => Yii::t('common/inventory', 'Kassza'),
'created_at' => Yii::t('common/inventory', 'Létrehozás'),
@@ -58,6 +65,14 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
];
}
public function validateOnlyClosed($attribute,$params){
$opened = Inventory::find()->andWhere(['status' => Inventory::$STATUS_OPEN])->all();
if ( count($opened) > 0 ){
$this->addError("name","Kérem előbb zárjon le minden másik leltárt");
}
}
/**
* @inheritdoc
*/
@@ -85,7 +100,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
// $query->andWhere("product.id_inventory_group is null");
$products = $query->all();
echo "Products found: " . count($products);
//echo "Products found: " . count($products);
$inventoryGroups = InventoryGroup::find()->all();
@@ -120,5 +135,20 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
}
public static function statuses(){
return [
Inventory::$STATUS_CLOSED => "Lezárva",
Inventory::$STATUS_OPEN => "Nyitva"
];
}
public function getStatusHuman(){
return Helper::getArrayValue(self::statuses(), $this->status, "NA");
}
public function isOpen(){
return $this->status == self::$STATUS_OPEN;
}
}

View File

@@ -32,6 +32,21 @@ class InventoryItem extends BaseFitnessActiveRecord
public static $TYPE_PRODUCT = 10;
public static $TYPE_INVENTORY_GROUP = 20;
public static $UPDATE_COUNT = "
UPDATE product as p1
inner JOIN ( select inventory_item.id_product as id_product , inventory_item.count as count
from inventory_item
where inventory_item.type = 10
and inventory_item.id_inventory = :id_inventory
and inventory_item.count is not null
) as t
on t.id_product = p1.id_product
SET p1.stock = case when t.id_product is null then ( p1.stock ) else ( t.count ) end
";
/**
* @inheritdoc
*/
@@ -142,14 +157,14 @@ class InventoryItem extends BaseFitnessActiveRecord
public function afterSave($insert, $changedAttributes){
if ( !$insert ){
if ( $this->type == 'product'){
$product = $this->product;
$product->stock = $this->count;
if ( !$product->save(false) ){
\Yii::error("Failed to save product stock");
throw new \Exception("A leltár elem mentése nem sikerült");
}
}
// if ( $this->type == 'product'){
// $product = $this->product;
// $product->stock = $this->count;
// if ( !$product->save(false) ){
// \Yii::error("Failed to save product stock");
// throw new \Exception("A leltár elem mentése nem sikerült");
// }
// }
}
}

View File

@@ -39,6 +39,7 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_LOGIN = 50;
public static $TYPE_DEFAULT_ACCOUNT= 60;
public static $TYPE_CREATE_CUSTOMER= 70;
public static $TYPE_PROCUREMENT_UPDATE = 80;
/**
* @inheritdoc
*/
@@ -90,12 +91,11 @@ class Log extends BaseFitnessActiveRecord
self::log(['type' =>self::$TYPE_INFO, 'message' => $message]);
}
public static function log( $config ){
\Yii::info( "Log :" . VarDumper::dump( $config) ) ;
$model = new Log($config);
$model->app = \Yii::$app->name;
$model->url = Url::canonical();
$model->id_user = \Yii::$app->user->id;
$model->save();
$model->save(false);
}
}