add inventory total price, rename procurement purchase price
This commit is contained in:
parent
a2dcdab49c
commit
5942a5f9f5
@ -183,9 +183,14 @@ class InventoryItemController extends Controller
|
||||
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");
|
||||
|
||||
if ( isset($prev)){
|
||||
return $this->redirect($prev);
|
||||
}else{
|
||||
|
||||
@ -119,6 +119,7 @@ class InventoryItemForm extends Model{
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
$item->price_brutto = $this->product->sale_price;
|
||||
$item->type = InventoryItem::$TYPE_PRODUCT;
|
||||
$item->id_product = $this->product->id_product;
|
||||
}else{
|
||||
@ -127,6 +128,10 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
|
||||
$model->recalculateTotalPriceBrutto();
|
||||
|
||||
|
||||
if ( !$item->save(false) ){
|
||||
throw new \Exception("Nem sikerült a leltár végrehajtása");
|
||||
}
|
||||
|
||||
@ -71,6 +71,8 @@ class InventoryItemSearch extends InventoryItem
|
||||
'inventory.created_at as inventory_created_at',
|
||||
'inventory_prev.id_inventory as inventory_prev_id_inventory',
|
||||
'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'),
|
||||
]);
|
||||
|
||||
@ -114,6 +116,8 @@ class InventoryItemSearch extends InventoryItem
|
||||
['inventory.id_inventory', 'inventory_id_inventory'],
|
||||
['inventory.name', 'inventory_name'],
|
||||
['inventory_prev_name', 'inventory_prev_name'],
|
||||
['item_price_brutto', 'item_price_brutto'],
|
||||
['item_total_price_brutto', 'item_total_price_brutto'],
|
||||
])
|
||||
,
|
||||
]
|
||||
|
||||
@ -22,6 +22,22 @@ $options['products'] = $productOptions;
|
||||
$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">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
@ -86,56 +102,61 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
|
||||
<?php
|
||||
|
||||
$columns = [
|
||||
[
|
||||
'attribute' => 'item_created_at',
|
||||
'label' => 'Létrehozva',
|
||||
'format' => 'datetime'
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_name',
|
||||
'label' => 'Név',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_username',
|
||||
'label' => 'Felhasználó',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'inventory_prev_name',
|
||||
'label' => 'Utolsó leltár'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_system',
|
||||
'label' => 'Rendszer szerinti mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count',
|
||||
'label' => 'Leltározott mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_prev',
|
||||
'label' => 'Előzö leltár (db)'
|
||||
'label' => 'Előzö leltár (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_in',
|
||||
'label' => 'Beszerzett mennyiség (db)'
|
||||
'label' => 'Beszerzett mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_sold',
|
||||
'label' => 'Eladott mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_difference',
|
||||
'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']
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
|
||||
@ -33,7 +33,7 @@ return [
|
||||
'Procurement' => 'Beszerzés',
|
||||
'Procurements' => 'Beszerzések',
|
||||
'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',
|
||||
'Stock' => 'Beszerzés előtti raktárkészlet',
|
||||
'Update' => 'Módosítás',
|
||||
|
||||
@ -24,6 +24,8 @@ use common\components\ProductAwareBehavior;
|
||||
* @property integer $id_user
|
||||
* @property integer $id_inventory_item_prev
|
||||
* @property integer $id_user
|
||||
* @property integer $price_brutto
|
||||
* @property integer $total_price_brutto
|
||||
* @property string $created_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){
|
||||
if ( !$insert ){
|
||||
// if ( $this->type == 'product'){
|
||||
|
||||
@ -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()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user