add inventory item changes

This commit is contained in:
2016-09-07 07:42:43 +02:00
parent 59c8099530
commit 179b47c454
8 changed files with 181 additions and 30 deletions

View File

@@ -20,6 +20,8 @@ use common\components\Helper;
* @property string $name
* @property string $created_at
* @property string $updated_at
* @property mixed userName
* @property mixed accountName
*/
class Inventory extends \common\models\BaseFitnessActiveRecord
{

View File

@@ -2,10 +2,12 @@
namespace common\models;
use Yii;
use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
Yii;
use yii\db\Expression;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use common\components\UserAwareBehavior;
use common\components\Helper;
use common\components\ProductAwareBehavior;
/**
@@ -28,6 +30,7 @@ use common\components\ProductAwareBehavior;
* @property string $created_at
* @property string $updated_at
* @property mixed productName
* @property mixed product
*/
class InventoryItem extends BaseFitnessActiveRecord
{
@@ -36,7 +39,8 @@ class InventoryItem extends BaseFitnessActiveRecord
public static $TYPE_INVENTORY_GROUP = 20;
public static $UPDATE_COUNT = "
public static /** @noinspection SqlResolve */
$UPDATE_COUNT = "
UPDATE product as p1
inner JOIN ( select inventory_item.id_product as id_product , inventory_item.count as count
from inventory_item
@@ -113,7 +117,11 @@ class InventoryItem extends BaseFitnessActiveRecord
public function getInventoryGroup(){
return $this->hasOne( Product::className() , [ 'id_inventory_group' => 'id_inventory_group' ]);
}
public function getInventoryItemPrev(){
return $this->hasOne( InventoryItem::className(),['id_inventory_item' => 'id_inventory_item_prev'] );
}
public function getProductName(){
$result = "";
@@ -136,10 +144,12 @@ class InventoryItem extends BaseFitnessActiveRecord
return $result;
}
public function getName(){
$name = "";
/**
* @return string
*/
public function getName(){
if ( isset($this->id_product )){
$name = $this->getProductName();
}else{
@@ -170,7 +180,54 @@ class InventoryItem extends BaseFitnessActiveRecord
$this->total_price_brutto = $price * $diff;
}
public static function findNextItemAlphabetical($id_inventory_item){
$inventoryItem = InventoryItem::findOne($id_inventory_item);
$id_inventory = $inventoryItem->id_inventory;
$currentItemId = $id_inventory_item;
$query = new Query();
$query->select([
'inventory_item.id_inventory_item as inventory_item_id_inventory',
new Expression(
"case when inventory_item.type = " .InventoryItem::$TYPE_PRODUCT . " then product.name else inventory_group.name end as name"
)
]);
$query->from('inventory_item');
$query->leftJoin("product", 'product.id_product = inventory_item.id_product and inventory_item.type =' .InventoryItem::$TYPE_PRODUCT);
$query->leftJoin("inventory_group", 'inventory_group.id_inventory_group = inventory_item.id_product and inventory_item.type =' .InventoryItem::$TYPE_INVENTORY_GROUP);
$query->andWhere(['id_inventory' => $id_inventory]);
$query->orderBy("name");
$result = $query->all();
$currentItemIndex = null;
$size = count($result);
for ( $i = 0; $i < $size; $i++ ){
$item = $result[$i];
$id = $item['inventory_item_id_inventory'];
if ( $id == $currentItemId ){
$currentItemIndex = $i;
break;
}
}
if ( isset( $currentItemIndex ) ){
$next = ($currentItemIndex +1 );
if ($size > $next){
return $result[$next]['inventory_item_id_inventory'];
}
}
return null;
}
public function afterSave($insert, $changedAttributes){
if ( !$insert ){
// if ( $this->type == 'product'){