add card.flag implementation
This commit is contained in:
@@ -82,7 +82,8 @@ class DoorLogSearch extends DoorLog
|
||||
'door_log.direction as door_log_direction',
|
||||
'door_log.created_at as door_log_created_at',
|
||||
'door_log.source_app as door_log_source_app',
|
||||
'account.name as account_name'
|
||||
'account.name as account_name',
|
||||
'door_log.card_flag as door_log_card_flag',
|
||||
]);
|
||||
$query->from('door_log');
|
||||
$query->innerJoin('card','card.id_card = door_log.id_card');
|
||||
@@ -131,6 +132,10 @@ class DoorLogSearch extends DoorLog
|
||||
'account_name' =>[
|
||||
'asc' => ['account.name' => SORT_ASC ],
|
||||
'desc' => ['account.name' => SORT_DESC],
|
||||
],
|
||||
'door_log_card_flag' =>[
|
||||
'asc' => ['door_log_card_flag' => SORT_ASC ],
|
||||
'desc' => ['door_log_card_flag' => SORT_DESC],
|
||||
]
|
||||
],
|
||||
]
|
||||
|
||||
@@ -17,6 +17,7 @@ use common\models\InventoryItem;
|
||||
use yii\db\Query;
|
||||
use common\models\Procurement;
|
||||
use common\models\Transfer;
|
||||
use common\models\Sale;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
@@ -32,7 +33,7 @@ class InventoryItemForm extends Model{
|
||||
|
||||
/**common data*/
|
||||
public $inventory;
|
||||
public $lastInventory;
|
||||
public $last_inventory;
|
||||
public $id_inventory;
|
||||
public $products;
|
||||
public $inventoryGroups;
|
||||
@@ -48,6 +49,8 @@ class InventoryItemForm extends Model{
|
||||
public $product_in;
|
||||
public $product_out;
|
||||
public $product_stock;
|
||||
public $last_inventory_item;
|
||||
public $inventory_item;
|
||||
|
||||
public function rules(){
|
||||
return [
|
||||
@@ -98,9 +101,9 @@ class InventoryItemForm extends Model{
|
||||
$item->count_sold = $this->product_out;
|
||||
$item->count = $this->product_stock;
|
||||
|
||||
if ( isset( $this->lastInventoryItem ) ){
|
||||
$item->id_inventory_item_prev = $this->lastInventoryItem->id_inventory_item;
|
||||
$item->count_prev = $this->lastInventoryItem->count;
|
||||
if ( isset( $this->last_inventory_item ) ){
|
||||
$item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item;
|
||||
$item->count_prev = $this->last_inventory_item->count;
|
||||
}else{
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
@@ -112,11 +115,13 @@ class InventoryItemForm extends Model{
|
||||
}else{
|
||||
$item->id_inventory_group = $this->inventoryGroup->id_inventory_group;
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
if ( !$item->save() ){
|
||||
throw new \Exception("Nem sikerült a leltár végrehajtása");
|
||||
}
|
||||
|
||||
$this->inventory_item = $item;
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
@@ -128,8 +133,8 @@ class InventoryItemForm extends Model{
|
||||
$query->from(Procurement::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product");
|
||||
|
||||
if ( isset($this->lastInventoryItem ) ){
|
||||
$query->andWhere([ '>', 'procurement.created_at' ,$this->lastInventoryItem->created_at]);
|
||||
if ( isset($this->last_inventory_item ) ){
|
||||
$query->andWhere([ '>', 'procurement.created_at' ,$this->last_inventory_item->created_at]);
|
||||
}
|
||||
|
||||
if ( $this->type == 'product') {
|
||||
@@ -147,7 +152,8 @@ class InventoryItemForm extends Model{
|
||||
$query = new Query();
|
||||
$query->select(['sum(transfer.count) as total_sold']);
|
||||
$query->from(Transfer::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT);
|
||||
$query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT);
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = sale.id_product ");
|
||||
$query->andWhere(['in', 'transfer.status' ,[Transfer::STATUS_PAID ,Transfer::STATUS_NOT_PAID ] ]);
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
|
||||
@@ -190,9 +196,9 @@ class InventoryItemForm extends Model{
|
||||
* Load previous inventory item, if exists
|
||||
* */
|
||||
protected function loadLastInventoryItem( ){
|
||||
if ( isset( $this->lastInventory ) ){
|
||||
if ( isset( $this->last_inventory ) ){
|
||||
$query = InventoryItem::find();
|
||||
$query->andWhere(['id_inventory' => $this->lastInventory->id_inventory]);
|
||||
$query->andWhere(['id_inventory' => $this->last_inventory->id_inventory]);
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
$query->andWhere(['id_product' => $this->product->id_product]);
|
||||
@@ -200,7 +206,7 @@ class InventoryItemForm extends Model{
|
||||
$query->andWhere(['id_inventory_group' => $this->inventoryGroup->id_inventory_group]);
|
||||
}
|
||||
|
||||
$this->lastInventoryItem = $query->one();
|
||||
$this->last_inventory_item = $query->one();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,10 +229,9 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
public function loadLastInventory(){
|
||||
$query = Inventory::find();
|
||||
$query->andWhere('<', 'inventory.created_at' , $this->inventory->created_at);
|
||||
$query->andWhere(['<', 'inventory.created_at' , $this->inventory->created_at]);
|
||||
$query->orderBy(['created_at' => SORT_DESC ]);
|
||||
//$this->lastInventory =
|
||||
$query->limit(1)->all();
|
||||
$this->last_inventory =$query->limit(1)->one();
|
||||
}
|
||||
|
||||
public function loadProducts(){
|
||||
|
||||
@@ -6,12 +6,20 @@ use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\InventoryItem;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\models\User;
|
||||
use common\models\Product;
|
||||
use common\models\InventoryGroup;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* InventoryItemSearch represents the model behind the search form about `common\models\InventoryItem`.
|
||||
*/
|
||||
class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
public $inventory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -19,7 +27,6 @@ class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
return [
|
||||
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
|
||||
[['last_inventroy_at', 'created_at', 'updated_at'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,12 +48,45 @@ class InventoryItemSearch extends InventoryItem
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = InventoryItem::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$query = new Query();
|
||||
$query->select([
|
||||
'inventory_item.id_inventory_item as item_id_inventory_item',
|
||||
'inventory_item.created_at as item_created_at',
|
||||
new Expression('case when inventory_item.id_product is null then inventory_group.name else product.name end as item_name'),
|
||||
'user.username as user_username',
|
||||
'coalesce(inventory_item.count_prev ,0)as item_count_prev',
|
||||
'coalesce(inventory_item.count_in,0) as item_count_in',
|
||||
'coalesce(inventory_item.count_sold,0) as item_count_sold',
|
||||
'coalesce(inventory_item.count,0) as item_count',
|
||||
new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'),
|
||||
]);
|
||||
$query->from(InventoryItem::tableName());
|
||||
|
||||
|
||||
$query->innerJoin(User::tableName(), "user.id = inventory_item.id_user");
|
||||
$query->leftJoin(Product::tableName(), "product.id_product = inventory_item.id_product");
|
||||
$query->leftJoin(InventoryGroup::tableName(), "inventory_group.id_inventory_group = inventory_item.id_inventory_group");
|
||||
|
||||
$query->andWhere( ['id_inventory' => $this->inventory->id_inventory] );
|
||||
|
||||
$dataProvider = new ActiveDataProvider(
|
||||
['query' => $query ,
|
||||
'sort' => [
|
||||
'attributes' => Helper::mkYiiSortItems([
|
||||
['item_created_at', 'item_created_at'],
|
||||
['item_name', 'item_name'],
|
||||
['user_username', 'user_username'],
|
||||
['item_count_prev', 'item_count_prev'],
|
||||
['item_count_sold', 'item_count_sold'],
|
||||
['item_count_in', 'item_count_in'],
|
||||
['item_count', 'item_count'],
|
||||
['item_count', 'item_count'],
|
||||
['item_difference', 'item_difference'],
|
||||
])
|
||||
,
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
@@ -65,7 +105,6 @@ class InventoryItemSearch extends InventoryItem
|
||||
'id_product' => $this->id_product,
|
||||
'id_inventory_group' => $this->id_inventory_group,
|
||||
'id_user' => $this->id_user,
|
||||
'last_inventroy_at' => $this->last_inventroy_at,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user