Add inventory changes ( tax, net purchase price

This commit is contained in:
Roland Schneider 2017-01-06 18:24:43 +01:00
parent 6de07dac93
commit f3d00953c8
16 changed files with 547 additions and 287 deletions

View File

@ -81,7 +81,11 @@ class InventoryItemController extends Controller
['item_count_sold', 'Eladott mennyiség (db)'], ['item_count_sold', 'Eladott mennyiség (db)'],
['item_count_in', 'Beszerzett mennyiség (db)'], ['item_count_in', 'Beszerzett mennyiség (db)'],
['item_count', 'Leltározott mennyiség (db)'], ['item_count', 'Leltározott mennyiség (db)'],
['item_difference', 'Különbség (db)'], ['item_purchase_price_net', 'Nettó beszerezési ár (Ft)'],
['item_net_stock_money', 'Nettó készlet érték (Ft)'],
['item_stock_missing_count', 'Különbség (db)'],
['item_price_brutto', 'Bruttó eladási ár (Ft)'],
['item_stock_missing_money', 'Leltár hiány (Ft)'],
['item_count_system', 'Rendszer szerinti mennyiség (db)'], ['item_count_system', 'Rendszer szerinti mennyiség (db)'],
]; ];
$cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']; $cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'];
@ -121,11 +125,13 @@ class InventoryItemController extends Controller
// 'name' => 'Verdana' // 'name' => 'Verdana'
foreach (range('A', 'I') as $columnID) { foreach (range('A', 'N') as $columnID) {
$sheet->getColumnDimension($columnID)->setAutoSize(true); $sheet->getColumnDimension($columnID)->setAutoSize(true);
$sheet->getStyle($columnID . '1')->applyFromArray($styleArray); $sheet->getStyle($columnID . '1')->applyFromArray($styleArray);
} }
$sheet->freezePane( "N2" );
// Redirect output to a clients web browser (Excel5) // Redirect output to a clients web browser (Excel5)
header('Content-Type: application/vnd.ms-excel'); header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="leltar.xls"'); header('Content-Disposition: attachment;filename="leltar.xls"');
@ -191,32 +197,18 @@ class InventoryItemController extends Controller
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$inventory = Inventory::findOne($model->id_inventory); $inventory = Inventory::findOne($model->id_inventory);
if (!$inventory->isOpen()) { if (!$inventory->isOpen()) {
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->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->recalculateTotalPriceBrutto();
$model->save(false); $model->save(false);
\Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db'); \Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db');
// $prev = Url::previous("inventory-item-index");
$next = InventoryItem::findNextItemAlphabetical($model->id_inventory_item); $next = InventoryItem::findNextItemAlphabetical($model->id_inventory_item);
if ( isset($_POST['_next']) && isset($next)){ if ( isset($_POST['_next']) && isset($next)){
return $this->redirect(['inventory-item/update', 'id' => $next]); return $this->redirect(['inventory-item/update', 'id' => $next]);
}else{ }else{
return $this->redirect(['index', 'id' => $inventory->id_inventory]); return $this->redirect(['index', 'id' => $inventory->id_inventory]);
} }
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
@ -226,11 +218,11 @@ class InventoryItemController extends Controller
} }
/** /**
* @param null $idInventory the id of the inventory
* @param integer $id the inventory item id * @param integer $id the inventory item id
* @return string * @return string
* @throws Exception * @throws Exception
* @throws NotAcceptableHttpException * @throws NotAcceptableHttpException
* @throws NotFoundHttpException
*/ */
public function actionUpdateItem($idInventory = null,$id = null) public function actionUpdateItem($idInventory = null,$id = null)
{ {
@ -269,7 +261,6 @@ class InventoryItemController extends Controller
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->recalculateTotalPriceBrutto();
if ( $model->save(false) ){ if ( $model->save(false) ){
\Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db'); \Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db');

View File

@ -123,16 +123,14 @@ class InventoryItemForm extends Model{
$item->price_brutto = $this->product->sale_price; $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;
$item->tax = $this->product->tax;
$item->purchase_price_net = $this->product->purchase_net_price;
}else{ }else{
$item->id_inventory_group = $this->inventoryGroup->id_inventory_group; $item->id_inventory_group = $this->inventoryGroup->id_inventory_group;
$item->type = InventoryItem::$TYPE_INVENTORY_GROUP; $item->type = InventoryItem::$TYPE_INVENTORY_GROUP;
} }
$item->id_inventory = $this->inventory->id_inventory; $item->id_inventory = $this->inventory->id_inventory;
$item->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

@ -2,7 +2,6 @@
namespace backend\models; namespace backend\models;
use Yii;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use common\models\InventoryItem; use common\models\InventoryItem;
@ -72,8 +71,10 @@ class InventoryItemSearch extends InventoryItem
'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.price_brutto as item_price_brutto',
'inventory_item.total_price_brutto as item_total_price_brutto', 'inventory_item.purchase_price_net as item_purchase_price_net',
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'), 'inventory_item.net_stock_money as item_net_stock_money',
'inventory_item.stock_missing_count as item_stock_missing_count',
'inventory_item.stock_missing_money as item_stock_missing_money'
]); ]);
$query->from(InventoryItem::tableName()); $query->from(InventoryItem::tableName());
@ -91,11 +92,7 @@ class InventoryItemSearch extends InventoryItem
$this->load($params); $this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$dataProvider = new ActiveDataProvider( $dataProvider = new ActiveDataProvider(
['query' => $query , ['query' => $query ,
@ -117,13 +114,21 @@ class InventoryItemSearch extends InventoryItem
['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_price_brutto', 'item_price_brutto'],
['item_total_price_brutto', 'item_total_price_brutto'], ['item_purchase_price_net', 'item_purchase_price_net'],
['item_stock_missing_count', 'item_stock_missing_count'],
['item_stock_missing_money', 'item_stock_missing_money'],
]) ])
, ,
] ]
] ]
); );
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
$query->where('0=1');
return $dataProvider;
}
if ( !empty($this->item_type) && is_numeric($this->item_id) ){ if ( !empty($this->item_type) && is_numeric($this->item_id) ){
if ( $this->item_type == 'product'){ if ( $this->item_type == 'product'){

View File

@ -115,18 +115,24 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
[ [
'attribute' => 'inventory_prev_name', 'attribute' => 'inventory_prev_name',
'label' => 'Utolsó leltár', 'label' => 'Utolsó leltár',
'contentOptions' => ['class' => 'col-b'] 'contentOptions' => ['class' => '']
], ],
[ [
'attribute' => 'item_count_system', 'attribute' => 'item_count_system',
'label' => 'Rendszer szerinti mennyiség (db)', 'label' => 'Rendszer szerinti mennyiség (db)',
'contentOptions' => ['class' => 'numeric'] 'contentOptions' => ['class' => 'numeric']
],
[
'attribute' => 'item_purchase_price_net',
'label' => 'Nettó beszerezési ár',
'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_count', 'attribute' => 'item_count',
'label' => 'Leltározott mennyiség (db)', 'label' => 'Leltározott mennyiség (db)',
'contentOptions' => ['class' => 'numeric col-b'] 'contentOptions' => ['class' => 'numeric ']
], ],
[ [
@ -138,7 +144,7 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
[ [
'attribute' => 'item_count_in', 'attribute' => 'item_count_in',
'label' => 'Beszerzett mennyiség (db)', 'label' => 'Beszerzett mennyiség (db)',
'contentOptions' => ['class' => 'numeric col-b' ] 'contentOptions' => ['class' => 'numeric ' ]
], ],
[ [
@ -148,9 +154,9 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
], ],
[ [
'attribute' => 'item_difference', 'attribute' => 'item_stock_missing_count',
'label' => 'Különbség (db)', 'label' => 'Különbség (db)',
'contentOptions' => ['class' => 'numeric col-b'] 'contentOptions' => ['class' => 'numeric ']
], ],
[ [
@ -159,13 +165,12 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
'contentOptions' => ['class' => 'numeric'] 'contentOptions' => ['class' => 'numeric']
], ],
[ [
'attribute' => 'item_total_price_brutto', 'attribute' => 'item_stock_missing_money',
'label' => 'Összeg (Ft)', 'label' => 'Leltár hiány (Ft)',
'contentOptions' => ['class' => 'numeric col-b'] 'contentOptions' => ['class' => 'numeric ']
], ]
]; ];
if ($model->isOpen()) { if ($model->isOpen()) {
$columns[] = ['class' => 'yii\grid\ActionColumn', $columns[] = ['class' => 'yii\grid\ActionColumn',
'template' => '{update}', 'template' => '{update}',
@ -187,6 +192,28 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
]; ];
} }
$i = 0;
foreach ($columns as $col){
$value = "";
if ( !isset($col["contentOptions"])){
$col["contentOptions"] = [];
}
if ( isset($col["contentOptions"]["class"])){
$value = $col["contentOptions"]["class"];
}
if ( $i % 2 == 1){
$columns[$i]["contentOptions"]["class"] = $value . " col-b";
}else{
$columns[$i]["contentOptions"]["class"] = $value . " col-a";
}
$i++;
}
echo GridView::widget([ echo GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => $columns 'columns' => $columns

View File

@ -40,6 +40,8 @@ $inventory_groups = ['' => ''] + ArrayHelper::map($inventory_groups, "id_invent
<?= $form->field($model, 'profit_margins')->textInput() ?> <?= $form->field($model, 'profit_margins')->textInput() ?>
<?= $form->field($model, 'tax')->textInput() ?>
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product', "Active") ]) ?> <?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product', "Active") ]) ?>
<?= $form->field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/product', "Max 255 character")) ?> <?= $form->field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/product', "Max 255 character")) ?>

View File

@ -37,6 +37,7 @@ $this->params['breadcrumbs'][] = $this->title;
'product_number', 'product_number',
'barcode', 'barcode',
'sale_price', 'sale_price',
'tax',
[ [
'attribute' => 'status', 'attribute' => 'status',
'value' => 'statusHuman', 'value' => 'statusHuman',

View File

@ -29,6 +29,7 @@ $this->params['breadcrumbs'][] = $this->title;
'purchase_price', 'purchase_price',
'sale_price', 'sale_price',
'profit_margins', 'profit_margins',
'tax',
'statusHuman', 'statusHuman',
'stock', 'stock',
[ [

View File

@ -26,11 +26,16 @@ 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 $price_brutto * @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
* @property mixed productName * @property mixed productName
* @property mixed product * @property mixed product
* @property integer tax
* @property integer purchase_price_net
* @property integer net_stock_money
* @property integer stock_missing_count
* @property integer stock_missing_money
* @property \common\models\InventoryGroup inventoryGroup
*/ */
class InventoryItem extends BaseFitnessActiveRecord class InventoryItem extends BaseFitnessActiveRecord
{ {
@ -133,6 +138,7 @@ class InventoryItem extends BaseFitnessActiveRecord
return $result; return $result;
} }
public function getInventoryGroupName(){ public function getInventoryGroupName(){
$result = ""; $result = "";
@ -159,32 +165,6 @@ class InventoryItem extends BaseFitnessActiveRecord
return $name; return $name;
} }
public function getDifference(){
$diff = $this->count - ( $this->count_prev + $this->count_in - $this->count_sold );
return $diff;
}
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 static function findNextItemAlphabetical($id_inventory_item){ public static function findNextItemAlphabetical($id_inventory_item){
$inventoryItem = InventoryItem::findOne($id_inventory_item); $inventoryItem = InventoryItem::findOne($id_inventory_item);
@ -227,6 +207,65 @@ class InventoryItem extends BaseFitnessActiveRecord
return null; return null;
} }
/**
* Recalculate the next values:
*
netto készlet érték
leltárhiány db
leltárhiány összeg
*
* @param boolean $insert whether this method called while inserting a record.
* If false, it means the method is called while updating a record.
* @return boolean whether the insertion or updating should continue.
* If false, the insertion or updating will be cancelled.
*/
public function beforeSave($insert)
{
$result = parent::beforeSave($insert);
if ( $result ){
if ( !isset($this->id_inventory_group) ){
$count = 0;
$purchase_price_net = 0;
$count_prev = 0;
$count_in = 0;
$count_sold = 0;
$price = 0;
if (isset($price) && is_numeric($price)){
$price = $this->price_brutto;
}
if ( isset($this->count)){
$count = $this->count;
}
if ( isset($this->purchase_price_net)){
$purchase_price_net = $this->purchase_price_net;
}
if ( isset($this->count_prev) ){
$count_prev = $this->count_prev;
}
if ( isset($this->count_in)){
$count_in = $this->count_in;
}
if ( isset($this->count_sold)){
$count_sold = $this->count_sold;
}
//netto készlet érték
$this->net_stock_money = $count * $purchase_price_net;
//leltárhiány db
$this->stock_missing_count = $this->count - ($count_prev + $count_in - $count_sold) ;
//leltárhiány összeg
$this->stock_missing_money = $price * $this->stock_missing_count;
}
}
return $result;
}
public function afterSave($insert, $changedAttributes){ public function afterSave($insert, $changedAttributes){
if ( !$insert ){ if ( !$insert ){

View File

@ -2,9 +2,9 @@
namespace common\models; namespace common\models;
use common\components\Helper;
use Yii; use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use common\components\Helper;
/** /**
* This is the model class for table "product". * This is the model class for table "product".
@ -18,13 +18,16 @@ use common\components\Helper;
* @property integer $purchase_price * @property integer $purchase_price
* @property integer $sale_price * @property integer $sale_price
* @property integer $profit_margins * @property integer $profit_margins
* @property integer $tax
* @property integer $purchase_net_price
* @property integer $status * @property integer $status
* @property integer $stock * @property integer $stock
* @property string $description * @property string $description
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
*/ */
class Product extends \common\models\BaseFitnessActiveRecord { class Product extends \common\models\BaseFitnessActiveRecord
{
const STATUS_DELETED = 0; const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10; const STATUS_ACTIVE = 10;
@ -46,7 +49,7 @@ class Product extends \common\models\BaseFitnessActiveRecord {
{ {
return [ return [
[['id_product_category', 'id_account', 'name'], 'required'], [['id_product_category', 'id_account', 'name'], 'required'],
[['id_inventory_group', 'id_product_category', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'], [['id_inventory_group', 'id_product_category', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status', 'tax'], 'integer'],
[['product_number', 'barcode'], 'string', 'max' => 20], [['product_number', 'barcode'], 'string', 'max' => 20],
[['product_number', 'barcode'], 'filter', 'filter' => 'trim', 'skipOnArray' => true], [['product_number', 'barcode'], 'filter', 'filter' => 'trim', 'skipOnArray' => true],
[['name'], 'string', 'max' => 128], [['name'], 'string', 'max' => 128],
@ -55,15 +58,18 @@ class Product extends \common\models\BaseFitnessActiveRecord {
// [['barcode'], 'unique' ], // [['barcode'], 'unique' ],
// a1 and a2 need to be unique together, only a1 will receive error message // a1 and a2 need to be unique together, only a1 will receive error message
// ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']] // ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]
[['barcode','product_number'], 'filter', 'filter' => function($value){return Helper::fixAsciiChars($value);}], [['barcode', 'product_number'], 'filter', 'filter' => function ($value) {
return Helper::fixAsciiChars($value);
}],
['barcode', 'unique', 'targetAttribute' => ['id_account', 'barcode']], ['barcode', 'unique', 'targetAttribute' => ['id_account', 'barcode']],
['product_number', 'unique', 'targetAttribute' => ['id_account', 'product_number']], ['product_number', 'unique', 'targetAttribute' => ['id_account', 'product_number']],
]; ];
} }
public function validateAscii($attribute,$params){ public function validateAscii($attribute, $params)
if ( !$this->hasErrors($this->$attribute)){ {
if (!$this->hasErrors($this->$attribute)) {
$this->attribute = Helper::fixAsciiChars($this->attributes); $this->attribute = Helper::fixAsciiChars($this->attributes);
} }
} }
@ -84,6 +90,8 @@ class Product extends \common\models\BaseFitnessActiveRecord {
'profit_margins' => Yii::t('common/product', 'Profit Margins'), 'profit_margins' => Yii::t('common/product', 'Profit Margins'),
'status' => Yii::t('common/product', 'Status'), 'status' => Yii::t('common/product', 'Status'),
'name' => Yii::t('common/product', 'Name'), 'name' => Yii::t('common/product', 'Name'),
'tax' => Yii::t('common/product', 'Adó(%)'),
'stock' => Yii::t('common/product', 'Raktáron'),
'description' => Yii::t('common/product', 'Description'), 'description' => Yii::t('common/product', 'Description'),
'created_at' => Yii::t('common/product', 'Created At'), 'created_at' => Yii::t('common/product', 'Created At'),
'updated_at' => Yii::t('common/product', 'Updated At'), 'updated_at' => Yii::t('common/product', 'Updated At'),
@ -92,51 +100,63 @@ class Product extends \common\models\BaseFitnessActiveRecord {
} }
public function getAccount() { public function getAccount()
return $this->hasOne ( Account::className (), [ {
return $this->hasOne(Account::className(), [
'id_account' => 'id_account' 'id_account' => 'id_account'
] ); ]);
} }
public function getAccountName() {
public function getAccountName()
{
return $this->account->name; return $this->account->name;
} }
public function getInventoryGroup() { public function getInventoryGroup()
return $this->hasOne ( InventoryGroup::className (), [ {
return $this->hasOne(InventoryGroup::className(), [
'id_inventory_group' => 'id_inventory_group' 'id_inventory_group' => 'id_inventory_group'
] ); ]);
} }
public function getInventoryGroupName() {
public function getInventoryGroupName()
{
$result = ""; $result = "";
$inventoryGroup = $this->inventoryGroup; $inventoryGroup = $this->inventoryGroup;
if ( isset($inventoryGroup)){ if (isset($inventoryGroup)) {
$result = $inventoryGroup->name; $result = $inventoryGroup->name;
} }
return $result; return $result;
} }
public function getProductCategory() { public function getProductCategory()
return $this->hasOne ( ProductCategory::className (), [ {
return $this->hasOne(ProductCategory::className(), [
'id_product_category' => 'id_product_category' 'id_product_category' => 'id_product_category'
] ); ]);
} }
public function getProductCategoryName() {
public function getProductCategoryName()
{
return $this->productCategory->name; return $this->productCategory->name;
} }
/** /**
* @formatter:on * @formatter:on
*/ */
static function statuses() { static function statuses()
{
return [ return [
self::STATUS_ACTIVE => Yii::t ( 'common/product', 'Active' ), self::STATUS_ACTIVE => Yii::t('common/product', 'Active'),
self::STATUS_DELETED => Yii::t ( 'common/product', 'Inactive' ) self::STATUS_DELETED => Yii::t('common/product', 'Inactive')
]; ];
} }
public function getStatusHuman() {
public function getStatusHuman()
{
$result = null; $result = null;
$s = self::statuses ( ); $s = self::statuses();
if (array_key_exists ( $this->status, $s )) { if (array_key_exists($this->status, $s)) {
$result = $s [$this->status]; $result = $s [$this->status];
} }
return $result; return $result;
@ -145,13 +165,14 @@ class Product extends \common\models\BaseFitnessActiveRecord {
/** /**
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive * $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
* */ * */
public static function read($forceIncludeObjectWithId = null){ public static function read($forceIncludeObjectWithId = null)
{
$warehouses = null; $warehouses = null;
if ( $forceIncludeObjectWithId == null){ if ($forceIncludeObjectWithId == null) {
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC])->all(); $warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC])->all();
}else{ } else {
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC])->all(); $warehouses = Product::find()->andWhere(['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId]])->orderBy(['product.name' => SORT_ASC])->all();
} }
return $warehouses; return $warehouses;
@ -160,20 +181,21 @@ class Product extends \common\models\BaseFitnessActiveRecord {
/** /**
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive * $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
* */ * */
public static function readForDefaultAccount($forceIncludeObjectWithId = null){ public static function readForDefaultAccount($forceIncludeObjectWithId = null)
{
$result = null; $result = null;
$account = Account::readDefault(); $account = Account::readDefault();
if ( $forceIncludeObjectWithId == null){ if ($forceIncludeObjectWithId == null) {
$query = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC]); $query = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC]);
if ( Helper::isProductVisibilityAccount() && $account ) if (Helper::isProductVisibilityAccount() && $account)
$query->andWhere(["product.id_account" => $account]); $query->andWhere(["product.id_account" => $account]);
$result = $query->all(); $result = $query->all();
}else{ } else {
$query = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC]); $query = Product::find()->andWhere(['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId]])->orderBy(['product.name' => SORT_ASC]);
if ( Helper::isProductVisibilityAccount() && $account ) if (Helper::isProductVisibilityAccount() && $account)
$query->andWhere(["product.id_account" => $account]); $query->andWhere(["product.id_account" => $account]);
$result = $query->all(); $result = $query->all();
@ -183,34 +205,35 @@ class Product extends \common\models\BaseFitnessActiveRecord {
return $result; return $result;
} }
public static function findProduct($query, $account = null){ public static function findProduct($query, $account = null)
$result = []; {
$product = null; $product = null;
$query = Product::find() $query = Product::find()
->andWhere( ->andWhere(
['or', ['or',
['product_number' => $query ], ['product_number' => $query],
['barcode' => $query ], ['barcode' => $query],
] ]
)->andWhere(['status' =>Product::STATUS_ACTIVE]); )->andWhere(['status' => Product::STATUS_ACTIVE]);
if ( Helper::isProductVisibilityAccount() && $account ){ if (Helper::isProductVisibilityAccount() && $account) {
$query->andFilterWhere(['product.id_account' => $account]); $query->andFilterWhere(['product.id_account' => $account]);
} }
$products = $query->all(); $products = $query->all();
if ( count($products) == 1 ){ if (count($products) == 1) {
$product = $products[0]; $product = $products[0];
} }
return $product; return $product;
} }
public static function modelToArray($product,$default = null){ public static function modelToArray($product, $default = null)
{
if ( $product == null ){ if ($product == null) {
return $default; return $default;
} }
@ -230,9 +253,10 @@ class Product extends \common\models\BaseFitnessActiveRecord {
]); ]);
} }
public static function modelToMapIdName($product,$default = null){ public static function modelToMapIdName($product, $default = null)
{
if ( $product == null ){ if ($product == null) {
return $default; return $default;
} }
@ -244,9 +268,10 @@ class Product extends \common\models\BaseFitnessActiveRecord {
]); ]);
} }
public static function modelToMapIdNameLong($product,$default = null){ public static function modelToMapIdNameLong($product, $default = null)
{
if ( $product == null ){ if ($product == null) {
return $default; return $default;
} }
@ -254,46 +279,73 @@ class Product extends \common\models\BaseFitnessActiveRecord {
'common\models\Product' => [ 'common\models\Product' => [
'id_product', 'id_product',
'name' => function ($product) { 'name' => function ($product) {
return $product->name . " - " .$product->productCategoryName . " (" . $product->accountName . ")"; return $product->name . " - " . $product->productCategoryName . " (" . $product->accountName . ")";
}, },
], ],
]); ]);
} }
public static function sellProduct($product,$count){ public static function sellProduct($product, $count)
{
$product->stock = $product->stock - $count; $product->stock = $product->stock - $count;
} }
public static function readProductsNotPartOfInventoryGroup( $id_account = null ){ public static function readProductsNotPartOfInventoryGroup($id_account = null)
{
$query = Product::find(); $query = Product::find();
$query->andWhere("id_inventory_group is null"); $query->andWhere("id_inventory_group is null");
$query->andWhere(['status' => Product::STATUS_ACTIVE]); $query->andWhere(['status' => Product::STATUS_ACTIVE]);
return $query->all(); return $query->all();
} }
public static function readInventoryGroups(){ public static function readInventoryGroups()
{
$query = InventoryGroup::find(); $query = InventoryGroup::find();
$query->andWhere(['status' => Product::STATUS_ACTIVE]); $query->andWhere(['status' => Product::STATUS_ACTIVE]);
return $query->all(); return $query->all();
} }
public static function buildProductAndInventoryGroupList($id_account = null){ public static function buildProductAndInventoryGroupList($id_account = null)
{
$productOptions = []; $productOptions = [];
$products = Product::readProductsNotPartOfInventoryGroup($id_account); $products = Product::readProductsNotPartOfInventoryGroup($id_account);
$inventoryGroups = Product::readInventoryGroups(); $inventoryGroups = Product::readInventoryGroups();
foreach ($products as $product ){ foreach ($products as $product) {
$productOptions[]= [ 'type' =>'product', 'id' => $product->id_product ,'name' => $product->name . " (Termék/" .$product->productCategoryName ."/" . $product->accountName .")" ]; $productOptions[] = ['type' => 'product', 'id' => $product->id_product, 'name' => $product->name . " (Termék/" . $product->productCategoryName . "/" . $product->accountName . ")"];
} }
foreach ($inventoryGroups as $inventoryGroup ){ foreach ($inventoryGroups as $inventoryGroup) {
$productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ]; $productOptions[] = ['type' => 'group', 'id' => $inventoryGroup->id_inventory_group, 'name' => $inventoryGroup->name . "/Termékcsoport"];
} }
return $productOptions; return $productOptions;
} }
public function beforeSave($insert)
{
$result = parent::beforeSave($insert);
if ($result) {
//automatically set net price
//net price = purchase_price -(purchase_price * tax /100)
$purchase_price_brutto = 0;
$tax = 0;
if (isset($this->purchase_price)) {
$purchase_price_brutto = $this->purchase_price;
}
if (isset($this->tax)) {
$tax = $this->tax;
}
$this->purchase_net_price = $purchase_price_brutto - ($purchase_price_brutto * $tax / 100);
}
return $result;
}
} }

View File

@ -40,6 +40,7 @@ use yii\web\NotAcceptableHttpException;
* @property integer $id_customer * @property integer $id_customer
* @property int|string paid_by * @property int|string paid_by
* @property int payment_method * @property int payment_method
* @property \common\models\Ticket ticket
*/ */
class Transfer extends \common\models\BaseFitnessActiveRecord { class Transfer extends \common\models\BaseFitnessActiveRecord {
const TYPE_PRODUCT = 10; const TYPE_PRODUCT = 10;
@ -597,7 +598,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
public function beforeDelete() { public function beforeDelete() {
parent::beforeDelete (); parent::beforeDelete ();
if ($this->type == Transfer::TYPE_TICKET) { if ($this->type == Transfer::TYPE_TICKET) {
/** @noinspection PhpUndefinedFieldInspection */
$ticket = $this->ticket; $ticket = $this->ticket;
if ($ticket != null) { if ($ticket != null) {
$ticket->delete (); $ticket->delete ();

View File

@ -54,7 +54,6 @@ class InventoryConsoleController extends Controller{
$item->count_sold = $products; $item->count_sold = $products;
$item->recalculateTotalPriceBrutto();
echo $item->price_brutto . " - ". $item->productName ."\n"; echo $item->price_brutto . " - ". $item->productName ."\n";

View File

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

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m170103_175608_alter__product__add__column__purchase_net_price extends Migration
{
public function up()
{
$this->addColumn("product", "purchase_net_price", "int default 0");
$this->execute("update product set purchase_net_price = purchase_price - FLOOR( purchase_price * tax / 100 )");
}
public function down()
{
echo "m170103_175608_alter__product__add__column__purchase_net_price cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,32 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m170104_054306_alter__table__product__set_products__tax__18 extends Migration
{
public function up()
{
$this->execute("update product set tax = 18 where name = 'Zabcsók';");
$this->execute("update product set tax = 18 where name = 'Mabaker zabszelet';");
$this->execute("update product set purchase_net_price = purchase_price - FLOOR( purchase_price * tax / 100 )");
}
public function down()
{
echo "m170104_054306_alter__table__product__set_products__tax__18 cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,50 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m170104_063931_alter__table__inventory__item__add__tax__net_stock_valu__sotck_missing extends Migration
{
public function up()
{
$this->addColumn("inventory_item", "tax", "int default 0");
$this->addColumn("inventory_item", "net_stock_money", "int default 0");
$this->addColumn("inventory_item", "purchase_price_net", "int default 0");
$this->addColumn("inventory_item", "stock_missing_money", "int default 0");
$this->addColumn("inventory_item", "stock_missing_count", "int default 0");
$sql = "UPDATE inventory_item AS i
INNER JOIN product AS p ON p.id_product = i.id_product
SET
i.tax = p.tax,
i.purchase_price_net = p.purchase_net_price,
i.net_stock_money = i.count * p.purchase_net_price,
i.stock_missing_count = (coalesce(i.count,0) - ( coalesce(i.count_prev,0) + coalesce(i.count_in,0) - coalesce(i.count_sold,0) )),
i.stock_missing_money = i.price_brutto * (coalesce(i.count,0) - ( coalesce(i.count_prev,0) + coalesce(i.count_in,0) - coalesce(i.count_sold,0) ))
WHERE i.id_inventory_group is null ";
$this->execute($sql);
}
public function down()
{
echo "m170104_063931_alter__table__inventory__item__add__tax__net_stock_valu__sotck_missing cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -161,6 +161,8 @@ class TicketController extends FrontendController
public function actionDelete($id) public function actionDelete($id)
{ {
$ticket = $this->findModel($id); $ticket = $this->findModel($id);
/** @var \common\models\Transfer $transfer */
$transfer = Transfer::find()->andWhere(['transfer.type' => Transfer::TYPE_TICKET]) $transfer = Transfer::find()->andWhere(['transfer.type' => Transfer::TYPE_TICKET])
->andWhere(['transfer.id_object' => $ticket->id_ticket]) ->andWhere(['transfer.id_object' => $ticket->id_ticket])
->one(); ->one();