add inventory admin fix, add procurement update
This commit is contained in:
@@ -119,9 +119,11 @@ class InventoryItemForm extends Model{
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
$item->type = InventoryItem::$TYPE_PRODUCT;
|
||||
$item->id_product = $this->product->id_product;
|
||||
}else{
|
||||
$item->id_inventory_group = $this->inventoryGroup->id_inventory_group;
|
||||
$item->type = InventoryItem::$TYPE_INVENTORY_GROUP;
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
|
||||
49
backend/models/ProcurementUpdate.php
Normal file
49
backend/models/ProcurementUpdate.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace backend\models;
|
||||
|
||||
|
||||
|
||||
use common\models\Procurement;
|
||||
use common\models\Product;
|
||||
use yii\helpers\VarDumper;
|
||||
use common\models\Log;
|
||||
|
||||
|
||||
class ProcurementUpdate extends Procurement{
|
||||
|
||||
private $oldCount;
|
||||
|
||||
public function rules( ) {
|
||||
return [
|
||||
[ ['count', 'purchase_price' ], 'integer'],
|
||||
[ ['count', 'purchase_price' ], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeSave($insert){
|
||||
if ( !$insert ){
|
||||
$changed = $this->getOldAttribute('count');
|
||||
// VarDumper::dump($changed);
|
||||
// VarDumper::dump($this->getDirtyAttributes(['count']));
|
||||
$this->oldCount = $this->getOldAttribute('count');
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
$product = Product::findOne($this->id_product);
|
||||
|
||||
$product->stock = $product->stock - $this->oldCount + $this->count;
|
||||
|
||||
$product->save(false);
|
||||
|
||||
Log::log([
|
||||
'id_product' => $this->product->id_product,
|
||||
'type' =>Log::$TYPE_PROCUREMENT_UPDATE,
|
||||
'message' => "Beszerzés(#".$this->id_procurement.") módosítva. Beszerzett mennyiség: " . $this->oldCount . " > " .$this->count,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -33,12 +33,15 @@ class TransferLaterSearch extends Transfer
|
||||
|
||||
public $total_money;
|
||||
|
||||
public $output;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['output' ] ,'safe'],
|
||||
[[ 'id_ticket_type','id_user'], 'integer'],
|
||||
[[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
@@ -72,11 +75,13 @@ class TransferLaterSearch extends Transfer
|
||||
'transfer.money as transfer_money',
|
||||
'transfer.status as transfer_status',
|
||||
'user.username as user_username',
|
||||
'customer.id_customer as customer_id_customer',
|
||||
'customer.name as customer_name',
|
||||
'ticket_type.name as ticket_type_name',
|
||||
'product.name as product_name',
|
||||
'ticket.start as ticket_start',
|
||||
'ticket.end as ticket_end',
|
||||
'ticket.comment as ticket_comment',
|
||||
]);
|
||||
$query->from("transfer");
|
||||
$query->innerJoin('user', " user.id = transfer.id_user");
|
||||
@@ -89,10 +94,15 @@ class TransferLaterSearch extends Transfer
|
||||
$query->andWhere(["transfer.payment_method" => Transfer::PAYMENT_METHOD_TRANSFER_LATER ]);
|
||||
|
||||
$query->andWhere(['transfer.status' => Transfer::STATUS_NOT_PAID]);
|
||||
|
||||
|
||||
$this->load($params);
|
||||
|
||||
$valid = $this->validate();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' =>[
|
||||
'pagination' => $this->output == 'pdf' ? false : [],
|
||||
'sort' => [
|
||||
'defaultOrder' =>[
|
||||
'transfer_created_at' => SORT_DESC
|
||||
],
|
||||
@@ -106,22 +116,18 @@ class TransferLaterSearch extends Transfer
|
||||
['product_name'],
|
||||
['ticket_start'],
|
||||
['ticket_end'],
|
||||
['ticket_comment'],
|
||||
])
|
||||
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
// $query->addSelect( ['*' ]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
if (!$valid) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
$query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query->andFilterWhere([
|
||||
|
||||
Reference in New Issue
Block a user