From 9c25312cf1540931c0526f6206ff1e39de7113bf Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 11 Mar 2016 07:41:51 +0100 Subject: [PATCH 1/3] status flag --- backend/controllers/CardController.php | 1 - backend/models/CardSearch.php | 5 +++++ backend/views/card/index.php | 9 +++++++++ common/components/Helper.php | 11 +++++++++++ common/models/Card.php | 17 +++++++++++++++++ common/models/DoorLog.php | 4 +++- common/models/Ticket.php | 5 +++-- cutler_daily.sh | 2 +- 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index 401c718..ca844b7 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -113,7 +113,6 @@ class CardController extends \backend\controllers\BackendController { */ public function actionUpdate($id) { $model = $this->findModel ( $id ); - if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { return $this->redirect ( [ 'index' diff --git a/backend/models/CardSearch.php b/backend/models/CardSearch.php index f71af90..19e8035 100644 --- a/backend/models/CardSearch.php +++ b/backend/models/CardSearch.php @@ -63,6 +63,7 @@ class CardSearch extends Card 'customer.name as customer_name' , 'customer.id_customer as customer_id_customer', 'key.number as key_number', + 'card.flag as card_flag', ]); @@ -106,6 +107,10 @@ class CardSearch extends Card 'asc' => ['key.number' => SORT_ASC ], 'desc' => ['key.number' => SORT_DESC], ], + 'card_flag' => [ + 'asc' => ['card.flag' => SORT_ASC ], + 'desc' => ['card.flag' => SORT_DESC], + ], ] ] ]); diff --git a/backend/views/card/index.php b/backend/views/card/index.php index b088d21..3c9f955 100644 --- a/backend/views/card/index.php +++ b/backend/views/card/index.php @@ -4,6 +4,8 @@ use yii\helpers\Html; use yii\grid\GridView; use common\models\Card; use yii\helpers\Url; +use common\components\Helper; +use common\models\DoorLog; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CardSearch */ @@ -66,6 +68,13 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'key_number', 'label' => 'Kulcs száma' ], + [ + 'attribute' => 'card_flag', + 'label' => 'Info', + 'value' => function ($model, $key, $index, $column){ + return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $model['card_flag'], "Ismeretlen ok"); + } + ], [ diff --git a/common/components/Helper.php b/common/components/Helper.php index ac79953..47f669b 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -368,6 +368,17 @@ class Helper { return $result; } + public static function setBit($val,$index,$bit_on){ + $flag = +$val; + if ( $bit_on ){ + $flag |= 1 << $index; + }else{ + $flag &= ~ (1 << $index); + } + return $flag; + } + + public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) { $charactersLength = strlen($characters); $randomString = ''; diff --git a/common/models/Card.php b/common/models/Card.php index 6aa549b..eda0f6a 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -12,6 +12,7 @@ use common\components\Helper; * @property string $number * @property integer $status * @property integer $type + * @property integer $flag * @property string $created_at * @property string $updated_at */ @@ -27,6 +28,9 @@ class Card extends \common\models\BaseFitnessActiveRecord const TYPE_OLD = 40; const TYPE_EMPLOYEE = 50; + + public static $FLAG_TICKET = 0; + public static $FLAG_STATUS = 1; /** * @inheritdoc */ @@ -172,4 +176,17 @@ class Card extends \common\models\BaseFitnessActiveRecord $command->execute(); } + public function beforeSave($insert) { + if (parent::beforeSave($insert)){ + $this->flag = Helper::setBit($this->flag, Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE)); + return true; + } + return false; + } + + + public function getFlagText(){ + return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->flag, "Ismeretlen"); + } + } diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 63f1fd2..1c334b2 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -143,8 +143,10 @@ class DoorLog extends \yii\db\ActiveRecord public static function getCardFlagTexts( ){ return [ - 0 => "Kártya ok", + 0 => "Kártya érvényes bérlettel", 1 => "Nincs érvényes bérlet", + 2 => "Kártya inaktív/Érvényes bérlet", + 3 => "Kártya inaktív/Nincs érvényes bérlet", ]; } diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 913f5e0..f3c4cc0 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -40,14 +40,15 @@ class Ticket extends \common\models\BaseFitnessActiveRecord left JOIN ( select distinct ticket.id_card as id_card from ticket where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) as t on t.id_card = c1.id_card - SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end"; + SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + WHERE c1.type <> 50"; public static $SQL_UPDATE_CARD = "UPDATE card as c1 left JOIN ( select distinct ticket.id_card as id_card from ticket where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) as t on t.id_card = c1.id_card SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end - WHERE c1.id_card = :id"; + WHERE c1.type <> 50 and c1.id_card = :id"; /** diff --git a/cutler_daily.sh b/cutler_daily.sh index e5f5bfe..a65f641 100644 --- a/cutler_daily.sh +++ b/cutler_daily.sh @@ -1,2 +1,2 @@ -php yii ticket/index \ No newline at end of file +php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index \ No newline at end of file From 0fc5ab01bc9760f0ca852c0937572277d15e86ef Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 11 Mar 2016 21:46:59 +0100 Subject: [PATCH 2/3] inventory changes --- backend/controllers/InventoryController.php | 6 ++- backend/models/InventoryItemForm.php | 21 +++++++++-- backend/models/InventoryItemSearch.php | 32 ++++++++++------ backend/views/inventory-item/index.php | 37 ++++++++++++++++++- backend/views/inventory/_form.php | 3 +- backend/views/inventory/index.php | 11 +++++- backend/views/inventory/view.php | 1 + common/models/Inventory.php | 7 +++- common/models/InventoryItem.php | 1 + ..._add__inventory__column__current_count.php | 31 ++++++++++++++++ ...0311_204131_add_card_current_id_ticket.php | 31 ++++++++++++++++ 11 files changed, 160 insertions(+), 21 deletions(-) create mode 100644 console/migrations/m160311_064422_add__inventory__column__name__add__inventory__column__current_count.php create mode 100644 console/migrations/m160311_204131_add_card_current_id_ticket.php diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index e9e2077..432469c 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -79,7 +79,11 @@ class InventoryController extends Controller public function actionCreate() { $model = new Inventory(); - + $user = User::findOne(\Yii::$app->user->id); + + + $model->name = 'Leltár_'.date('Ymd_His') .'_' . $user->username; + $model->id_user = \Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_inventory]); diff --git a/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php index f92cbfd..8ef2ce4 100644 --- a/backend/models/InventoryItemForm.php +++ b/backend/models/InventoryItemForm.php @@ -91,6 +91,9 @@ class InventoryItemForm extends Model{ public function save(){ if ( $this->validate()) { + + $this->loadLastInventory(); + $this->loadLastInventoryItem(); $this->loadProductIn(); $this->loadProductSold(); @@ -99,7 +102,9 @@ class InventoryItemForm extends Model{ $item = new InventoryItem(); $item->count_in = $this->product_in; $item->count_sold = $this->product_out; - $item->count = $this->product_stock; + $item->count = $this->count; + $item->count_system = $this->product_stock; + if ( isset( $this->last_inventory_item ) ){ $item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item; @@ -198,6 +203,7 @@ class InventoryItemForm extends Model{ protected function loadLastInventoryItem( ){ if ( isset( $this->last_inventory ) ){ $query = InventoryItem::find(); + $query->andWhere(['id_inventory' => $this->last_inventory->id_inventory]); if ( $this->type == 'product'){ @@ -211,8 +217,8 @@ class InventoryItemForm extends Model{ } public function read(){ + $this->loadInventory(); - $this->loadLastInventory(); $this->loadProducts(); $this->loadInventoryGroups(); @@ -229,6 +235,14 @@ class InventoryItemForm extends Model{ } public function loadLastInventory(){ $query = Inventory::find(); + $query->innerJoin(InventoryItem::tableName(),"inventory_item.id_inventory = inventory.id_inventory"); + + if ( $this->type == 'product'){ + $query->andWhere(['inventory_item.id_product' => $this->product->id_product]); + }else{ + $query->andWhere(['inventory_item.id_inventory_group' => $this->inventoryGroup->id_inventory_group]); + } + $query->andWhere(['<', 'inventory.created_at' , $this->inventory->created_at]); $query->orderBy(['created_at' => SORT_DESC ]); $this->last_inventory =$query->limit(1)->one(); @@ -265,7 +279,8 @@ class InventoryItemForm extends Model{ public function attributeLabels() { return [ - 'count' => 'Mennyiség' + 'count' => 'Mennyiség', + 'name' => "Termék/Termék csoport neve" ]; } diff --git a/backend/models/InventoryItemSearch.php b/backend/models/InventoryItemSearch.php index 58b1983..ef2ea49 100644 --- a/backend/models/InventoryItemSearch.php +++ b/backend/models/InventoryItemSearch.php @@ -12,6 +12,7 @@ use common\models\User; use common\models\Product; use common\models\InventoryGroup; use common\components\Helper; +use common\models\Inventory; /** * InventoryItemSearch represents the model behind the search form about `common\models\InventoryItem`. @@ -58,6 +59,10 @@ class InventoryItemSearch extends InventoryItem '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', + 'coalesce(inventory_item.count_system,0) as item_count_system', + 'inventory.created_at as inventory_created_at', + 'inventory_prev.id_inventory as inventory_prev_id_inventory', + 'inventory_prev.name as inventory_prev_name', new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'), ]); $query->from(InventoryItem::tableName()); @@ -66,8 +71,12 @@ class InventoryItemSearch extends InventoryItem $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->leftJoin(Inventory::tableName(), "inventory.id_inventory = inventory_item.id_inventory"); - $query->andWhere( ['id_inventory' => $this->inventory->id_inventory] ); + $query->leftJoin( "inventory_item as item_prev", "item_prev.id_inventory_item = inventory_item.id_inventory_item_prev" ); + $query->leftJoin( "inventory as inventory_prev", "inventory_prev.id_inventory = item_prev.id_inventory" ); + + $query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] ); $dataProvider = new ActiveDataProvider( ['query' => $query , @@ -82,6 +91,10 @@ class InventoryItemSearch extends InventoryItem ['item_count', 'item_count'], ['item_count', 'item_count'], ['item_difference', 'item_difference'], + ['item_count_system', 'item_count_system'], + ['inventory.id_inventory', 'inventory_id_inventory'], + ['inventory.name', 'inventory_name'], + ['inventory_prev_name', 'inventory_prev_name'], ]) , ] @@ -96,17 +109,12 @@ class InventoryItemSearch extends InventoryItem } $query->andFilterWhere([ - 'id_inventory_item' => $this->id_inventory_item, - 'id_inventory' => $this->id_inventory, - 'count_in' => $this->count_in, - 'count_sold' => $this->count_sold, - 'count' => $this->count, - 'type' => $this->type, - 'id_product' => $this->id_product, - 'id_inventory_group' => $this->id_inventory_group, - 'id_user' => $this->id_user, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, + 'inventory_item.id_inventory_item' => $this->id_inventory_item, + 'inventory_item.type' => $this->type, + 'inventory_item.id_product' => $this->id_product, + 'inventory_item.id_inventory_group' => $this->id_inventory_group, + 'inventory_item.id_user' => $this->id_user, + 'inventory_item.created_at' => $this->created_at, ]); return $dataProvider; diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 02f25ae..1be5bf8 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -20,6 +20,7 @@ $this->params['breadcrumbs'][] = $this->title; 'model' => $model, 'attributes' => [ 'id_inventory', + 'name', ['attribute'=>'id_user', 'value'=>$model->userName ], @@ -31,8 +32,32 @@ $this->params['breadcrumbs'][] = $this->title;

- $model->id_inventory], ['class' => 'btn btn-success']) ?> + $model->id_inventory], ['class' => 'btn btn-success']) ?>

+ +

+ Magyarázat: +

+

params['breadcrumbs'][] = $this->title; 'attribute' => 'user_username', 'label' => 'Felhasználó', + ], + [ + 'attribute' => 'inventory_prev_name', + 'label' => 'Utolsó leltár' + ], [ 'attribute' => 'item_count_prev', @@ -72,6 +102,11 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'item_count', 'label' => 'Leltározott mennyiség (db)', + ], + [ + 'attribute' => 'item_count_system', + 'label' => 'Rendszer szerinti mennyiség (db)', + ], [ 'attribute' => 'item_difference', diff --git a/backend/views/inventory/_form.php b/backend/views/inventory/_form.php index 0b494ff..30dea89 100644 --- a/backend/views/inventory/_form.php +++ b/backend/views/inventory/_form.php @@ -11,9 +11,10 @@ use yii\widgets\ActiveForm;
- +
+ field($model, "name")->textInput()?> isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/inventory/index.php b/backend/views/inventory/index.php index e9f0c3f..566635a 100644 --- a/backend/views/inventory/index.php +++ b/backend/views/inventory/index.php @@ -25,7 +25,8 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ 'id_inventory', - 'id_user', + 'name', + [ 'attribute' => 'id_user', "value" =>"userName" ], 'created_at:datetime', ['class' => 'yii\grid\ActionColumn', @@ -34,7 +35,13 @@ $this->params['breadcrumbs'][] = $this->title; if ( $action == 'view' ){ return Url::to(['inventory-item/index' , 'id'=> $model->id_inventory]); } - } + }, + 'buttons' =>[ + 'view' =>function ($url, $model, $key) { + return Html::a('Részletek', $url,['class' => 'btn btn-xs btn-primary', + ]) ; + } + ] ], ], diff --git a/backend/views/inventory/view.php b/backend/views/inventory/view.php index 580a5d5..6fef3cd 100644 --- a/backend/views/inventory/view.php +++ b/backend/views/inventory/view.php @@ -21,6 +21,7 @@ $this->params['breadcrumbs'][] = "Leltár"; 'model' => $model, 'attributes' => [ 'id_inventory', + 'name', ['attribute'=>'id_user', 'value'=>$model->userName ], diff --git a/common/models/Inventory.php b/common/models/Inventory.php index aaf14a0..45ed4e0 100644 --- a/common/models/Inventory.php +++ b/common/models/Inventory.php @@ -11,12 +11,15 @@ use yii\helpers\ArrayHelper; * * @property integer $id_inventory * @property integer $id_user + * @property string $name * @property string $created_at * @property string $updated_at */ class Inventory extends \common\models\BaseFitnessActiveRecord { - /** + + + /** * @inheritdoc */ public static function tableName() @@ -30,6 +33,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord public function rules() { return [ + [['name'], 'string'] ]; } @@ -40,6 +44,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'), 'id_user' => Yii::t('common/inventory', 'Felhasználó'), 'created_at' => Yii::t('common/inventory', 'Létrehozás'), 'updated_at' => Yii::t('common/inventory', 'Módosítás'), diff --git a/common/models/InventoryItem.php b/common/models/InventoryItem.php index 665d1ad..2f759ef 100644 --- a/common/models/InventoryItem.php +++ b/common/models/InventoryItem.php @@ -16,6 +16,7 @@ use common\components\Helper; * @property integer $count_sold * @property integer $count * @property integer $count_prev + * @property integer $count_system * @property integer $type * @property integer $id_product * @property integer $id_inventory_group diff --git a/console/migrations/m160311_064422_add__inventory__column__name__add__inventory__column__current_count.php b/console/migrations/m160311_064422_add__inventory__column__name__add__inventory__column__current_count.php new file mode 100644 index 0000000..1344873 --- /dev/null +++ b/console/migrations/m160311_064422_add__inventory__column__name__add__inventory__column__current_count.php @@ -0,0 +1,31 @@ +addColumn("inventory", "name", "string"); + $this->addColumn("inventory_item", "count_system", "int"); + } + + public function down() + { + echo "m160311_064422_add__inventory__column__name__add__inventory__column__current_count cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m160311_204131_add_card_current_id_ticket.php b/console/migrations/m160311_204131_add_card_current_id_ticket.php new file mode 100644 index 0000000..3c6948c --- /dev/null +++ b/console/migrations/m160311_204131_add_card_current_id_ticket.php @@ -0,0 +1,31 @@ +addColumn("door_log", "id_ticket_current", "int default null"); + $this->addColumn("card", "id_ticket_current", "int default null"); + } + + public function down() + { + echo "m160311_204131_add_card_current_id_ticket cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} From 1c090b01b020662db34708a95a6ea3cd5908f9fd Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 11 Mar 2016 21:49:07 +0100 Subject: [PATCH 3/3] change version --- changelog.txt | 3 +++ common/config/params.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 4552708..4353605 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +-0.0.53 + - inventory changes + - add id_ticket_current to card and ticket table -0.0.52 - card flag - inventory item diff --git a/common/config/params.php b/common/config/params.php index 5c51aae..1d7fbad 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.52', + 'version' => 'v0.0.53', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global