add inventory total price, rename procurement purchase price

This commit is contained in:
Roland Schneider 2016-04-04 20:40:55 +02:00
parent a2dcdab49c
commit 5942a5f9f5
7 changed files with 97 additions and 15 deletions

View File

@ -183,9 +183,14 @@ class InventoryItemController extends Controller
throw new NotAcceptableHttpException("A leltár elem nem található"); throw new NotAcceptableHttpException("A leltár elem nem található");
} }
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->recalculateTotalPriceBrutto();
$model->save(false);
$prev = Url::previous("inventory-item-index"); $prev = Url::previous("inventory-item-index");
if ( isset($prev)){ if ( isset($prev)){
return $this->redirect($prev); return $this->redirect($prev);
}else{ }else{

View File

@ -119,6 +119,7 @@ class InventoryItemForm extends Model{
$item->id_user = \Yii::$app->user->id; $item->id_user = \Yii::$app->user->id;
if ( $this->type == 'product'){ if ( $this->type == 'product'){
$item->price_brutto = $this->product->sale_price;
$item->type = InventoryItem::$TYPE_PRODUCT; $item->type = InventoryItem::$TYPE_PRODUCT;
$item->id_product = $this->product->id_product; $item->id_product = $this->product->id_product;
}else{ }else{
@ -127,6 +128,10 @@ class InventoryItemForm extends Model{
} }
$item->id_inventory = $this->inventory->id_inventory; $item->id_inventory = $this->inventory->id_inventory;
$model->recalculateTotalPriceBrutto();
if ( !$item->save(false) ){ if ( !$item->save(false) ){
throw new \Exception("Nem sikerült a leltár végrehajtása"); throw new \Exception("Nem sikerült a leltár végrehajtása");
} }

View File

@ -71,6 +71,8 @@ class InventoryItemSearch extends InventoryItem
'inventory.created_at as inventory_created_at', 'inventory.created_at as inventory_created_at',
'inventory_prev.id_inventory as inventory_prev_id_inventory', 'inventory_prev.id_inventory as inventory_prev_id_inventory',
'inventory_prev.name as inventory_prev_name', 'inventory_prev.name as inventory_prev_name',
'inventory_item.price_brutto as item_price_brutto',
'inventory_item.total_price_brutto as item_total_price_brutto',
new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'), new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'),
]); ]);
@ -114,6 +116,8 @@ class InventoryItemSearch extends InventoryItem
['inventory.id_inventory', 'inventory_id_inventory'], ['inventory.id_inventory', 'inventory_id_inventory'],
['inventory.name', 'inventory_name'], ['inventory.name', 'inventory_name'],
['inventory_prev_name', 'inventory_prev_name'], ['inventory_prev_name', 'inventory_prev_name'],
['item_price_brutto', 'item_price_brutto'],
['item_total_price_brutto', 'item_total_price_brutto'],
]) ])
, ,
] ]

View File

@ -22,6 +22,22 @@ $options['products'] = $productOptions;
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
?> ?>
<style>
.table th{
white-space: normal;
}
.table td{
white-space: normal;
}
.table td.numeric{
width: 110px;
text-align: right;
}
</style>
<div class="inventory-item-index"> <div class="inventory-item-index">
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
@ -86,56 +102,61 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
<?php <?php
$columns = [ $columns = [
[
'attribute' => 'item_created_at',
'label' => 'Létrehozva',
'format' => 'datetime'
],
[ [
'attribute' => 'item_name', 'attribute' => 'item_name',
'label' => 'Név', 'label' => 'Név',
],
[
'attribute' => 'user_username',
'label' => 'Felhasználó',
], ],
[ [
'attribute' => 'inventory_prev_name', 'attribute' => 'inventory_prev_name',
'label' => 'Utolsó leltár' 'label' => 'Utolsó leltár'
], ],
[ [
'attribute' => 'item_count_system', 'attribute' => 'item_count_system',
'label' => 'Rendszer szerinti mennyiség (db)', 'label' => 'Rendszer szerinti mennyiség (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_count', 'attribute' => 'item_count',
'label' => 'Leltározott mennyiség (db)', 'label' => 'Leltározott mennyiség (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_count_prev', 'attribute' => 'item_count_prev',
'label' => 'Előzö leltár (db)' 'label' => 'Előzö leltár (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_count_in', 'attribute' => 'item_count_in',
'label' => 'Beszerzett mennyiség (db)' 'label' => 'Beszerzett mennyiség (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_count_sold', 'attribute' => 'item_count_sold',
'label' => 'Eladott mennyiség (db)', 'label' => 'Eladott mennyiség (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_difference', 'attribute' => 'item_difference',
'label' => 'Különbség (db)', 'label' => 'Különbség (db)',
'contentOptions' => ['class' => 'numeric']
], ],
[
'attribute' => 'item_price_brutto',
'label' => 'Eladási ár (Ft)',
'contentOptions' => ['class' => 'numeric']
],
[
'attribute' => 'item_total_price_brutto',
'label' => 'Összeg (Ft)',
'contentOptions' => ['class' => 'numeric']
],
]; ];

View File

@ -33,7 +33,7 @@ return [
'Procurement' => 'Beszerzés', 'Procurement' => 'Beszerzés',
'Procurements' => 'Beszerzések', 'Procurements' => 'Beszerzések',
'Product name, product number or barcode' => 'Termék neve, termék száma vagy vonalkód', 'Product name, product number or barcode' => 'Termék neve, termék száma vagy vonalkód',
'Purchase Price' => 'Beszerzési ár', 'Purchase Price' => 'Bevételezési ár(össz.)',
'Search' => 'Keresés', 'Search' => 'Keresés',
'Stock' => 'Beszerzés előtti raktárkészlet', 'Stock' => 'Beszerzés előtti raktárkészlet',
'Update' => 'Módosítás', 'Update' => 'Módosítás',

View File

@ -24,6 +24,8 @@ use common\components\ProductAwareBehavior;
* @property integer $id_user * @property integer $id_user
* @property integer $id_inventory_item_prev * @property integer $id_inventory_item_prev
* @property integer $id_user * @property integer $id_user
* @property integer $price_brutto
* @property integer $total_price_brutto
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
*/ */
@ -155,6 +157,20 @@ class InventoryItem extends BaseFitnessActiveRecord
} }
public function recalculateTotalPriceBrutto(){
$diff = $this->difference;
if (!isset($diff) || !is_numeric($diff)){
$diff = 0;
}
$price = $this->price_brutto;
if (!isset($price) || !is_numeric($price)){
$price = 0;
}
$this->total_price_brutto = $price * $diff;
}
public function afterSave($insert, $changedAttributes){ public function afterSave($insert, $changedAttributes){
if ( !$insert ){ if ( !$insert ){
// if ( $this->type == 'product'){ // if ( $this->type == 'product'){

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160404_053858_alter__table__inventory_item_add__price__brutto extends Migration
{
public function up()
{
$this->addColumn("inventory_item", "price_brutto", "int default 0");
$this->addColumn("inventory_item", "total_price_brutto", "int default 0");
}
public function down()
{
echo "m160404_053858_alter__table__inventory_item_add__price__brutto cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}