add money movement type 'in', add daily transfers
This commit is contained in:
parent
1bcc435ab6
commit
72fc139674
@ -28,5 +28,6 @@ return [
|
||||
'Update' => 'Módosítás',
|
||||
'Update {modelClass}: ' => '{modelClass} módosítás: ',
|
||||
'pieces' => 'db',
|
||||
'Transfers Summary' => 'Bevétel'
|
||||
'Transfers Summary' => 'Bevétel',
|
||||
'Daily transfers' => 'Napi bevételek'
|
||||
];
|
||||
|
||||
@ -27,6 +27,7 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
const TYPE_OUT = 10;
|
||||
const TYPE_IN = 20;
|
||||
|
||||
public $_account;
|
||||
|
||||
@ -47,7 +48,7 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
'value' => function(){ return date('Y-m-d H:i:s' , time()); }
|
||||
],
|
||||
[
|
||||
'class' => AccountAwareBehavior::className(),
|
||||
@ -65,10 +66,11 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
[['id_account', 'name', 'money'], 'required'],
|
||||
[['id_account' , 'money'], 'integer'],
|
||||
[['id_account' , 'money'], 'integer' , 'min' => 0],
|
||||
[['name'], 'string', 'max' => 64],
|
||||
[['comment'], 'string', 'max' => 255],
|
||||
[['id_account'], 'validateAccount'],
|
||||
[['type'] , 'in','range' => array_keys(MoneyMovement::types())],
|
||||
];
|
||||
}
|
||||
|
||||
@ -91,6 +93,7 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
'id_user' => Yii::t('common/money-movement', 'Id User'),
|
||||
'name' => Yii::t('common/money-movement', 'Name'),
|
||||
'type' => Yii::t('common/money-movement', 'Type'),
|
||||
'humanType' => Yii::t('common/money-movement', 'Type'),
|
||||
'money' => Yii::t('common/money-movement', 'Money'),
|
||||
'comment' => Yii::t('common/money-movement', 'Comment'),
|
||||
'created_at' => Yii::t('common/money-movement', 'Created At'),
|
||||
@ -100,6 +103,7 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
if ( $insert) {
|
||||
@ -114,4 +118,26 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
$transfer->save();
|
||||
}
|
||||
|
||||
public static function types(){
|
||||
return [
|
||||
self::TYPE_IN => "Betét",
|
||||
self::TYPE_OUT => "Kivét",
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public static function typeName($type){
|
||||
$types = MoneyMovement::types();
|
||||
$result = "";
|
||||
if ( array_key_exists($type, $types)){
|
||||
$result = $types[$type];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getHumanType(){
|
||||
return self::typeName($this->type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -118,9 +118,9 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
$warehouses = null;
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->all();
|
||||
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC])->all();
|
||||
}else{
|
||||
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->all();
|
||||
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC])->all();
|
||||
}
|
||||
|
||||
return $warehouses;
|
||||
|
||||
@ -247,6 +247,19 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public static function toSignedMoney($dir,$money){
|
||||
$m = 1;
|
||||
$result = $money;
|
||||
if ( $dir == Transfer::DIRECTION_OUT ){
|
||||
$m = -1;
|
||||
}
|
||||
|
||||
$result = $result * $m;
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function toProductSoldString(){
|
||||
$s = "";
|
||||
@ -315,7 +328,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
$transfer->type = Transfer::TYPE_MONEY_MOVEMENT_OUT;
|
||||
$transfer->status = Transfer::STATUS_PAID;
|
||||
$transfer->direction = Transfer::DIRECTION_OUT;
|
||||
if ( $moneyMovement->type == MoneyMovement::TYPE_OUT){
|
||||
$transfer->direction = Transfer::DIRECTION_OUT;
|
||||
}else if ( $moneyMovement->type == MoneyMovement::TYPE_IN ){
|
||||
$transfer->direction = Transfer::DIRECTION_IN;
|
||||
}
|
||||
$transfer->count = null;
|
||||
|
||||
$transfer->id_object = $moneyMovement->id_money_movement;
|
||||
|
||||
@ -67,6 +67,7 @@ class FrontendMenuStructure{
|
||||
['label' => Yii::t('frontend/account-state','Open account state'), 'url' => ['/account-state/open'] ],
|
||||
['label' => Yii::t('frontend/account-state','Close account state'), 'url' => ['/account-state/close'] ],
|
||||
['label' => Yii::t('frontend/money-movement','Money movements'), 'url' => [ '/money-movement/index', 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow ] ],
|
||||
['label' => Yii::t('frontend/transfer','Daily transfers'), 'url' => [ '/transfer/list', 'TransferListSearch[start]' => $this->start, 'TransferListSearch[end]' => $this->tomorrow ] ],
|
||||
];
|
||||
|
||||
if ( $isadmin || Yii::$app->user->can('reception.transfers') ){
|
||||
|
||||
@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use frontend\models\TransferMoneyMovementSearch;
|
||||
use common\models\Account;
|
||||
use frontend\models\TransferListSearch;
|
||||
|
||||
/**
|
||||
* TransferController implements the CRUD actions for Transfer model.
|
||||
@ -55,13 +56,31 @@ class TransferController extends Controller
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
$searchModel->totalsTransfers(Yii::$app->request->queryParams);
|
||||
|
||||
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Transfer models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionList()
|
||||
{
|
||||
$searchModel = new TransferListSearch();
|
||||
$searchModel->accounts = Account::read();
|
||||
$searchModel->load(Yii::$app->request->queryParams);
|
||||
|
||||
$searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
|
||||
return $this->render('list', [
|
||||
'searchModel' => $searchModel,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,6 +95,7 @@ class TransferController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Transfer model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
|
||||
375
frontend/models/TransferListSearch.php
Normal file
375
frontend/models/TransferListSearch.php
Normal file
@ -0,0 +1,375 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Transfer;
|
||||
use yii\base\Object;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\models\Account;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\MoneyMovement;
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
class TransferListSearch extends Transfer
|
||||
{
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
// public $totalsCreatedAt = ['total' => 0, 'accounts' =>[] ];
|
||||
// public $totalsCreatedAtNotPaid= ['total' => 0, 'accounts' =>[]];
|
||||
// public $totalsCreatedAtPaid= ['total' => 0, 'accounts' =>[]];
|
||||
// public $totalsPaidAt= ['total' => 0, 'accounts' =>[]];
|
||||
// public $totalsPaidAtNotCreatedAt= ['total' => 0, 'accounts' =>[]];
|
||||
|
||||
|
||||
public $totals;
|
||||
|
||||
public $accounts;
|
||||
|
||||
public $types;
|
||||
|
||||
|
||||
/**
|
||||
* all money gained with ticket sell
|
||||
* */
|
||||
public $ticketMoney;
|
||||
/**
|
||||
* all money gained with product sell
|
||||
* */
|
||||
public $productMoney;
|
||||
/**
|
||||
* all money gained with product sell grouped by category
|
||||
* */
|
||||
public $productMoneies;
|
||||
/**
|
||||
* all money lost by money movement
|
||||
* */
|
||||
public $moneyMovementMoneis;
|
||||
public $moneyMovementMoney;
|
||||
/**
|
||||
* total gained money
|
||||
* */
|
||||
public $total;
|
||||
|
||||
/**
|
||||
* ticket sale statisitc
|
||||
* */
|
||||
public $ticketStats;
|
||||
|
||||
/**
|
||||
* money movements by type
|
||||
* */
|
||||
public $moneyMovementsByType;
|
||||
|
||||
public $tickets;
|
||||
/**
|
||||
* all product transfer
|
||||
* */
|
||||
public $products;
|
||||
public $moneyMovements;
|
||||
|
||||
public $productsByCategory;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
|
||||
[[ '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' ],
|
||||
|
||||
[ [ 'id_account' ] , 'integer'],
|
||||
['types', 'each', 'rule' => ['integer']],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = Transfer::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$this->load($params);
|
||||
|
||||
|
||||
if (!$this->validate()) {
|
||||
}
|
||||
|
||||
$this->readTicketMoney();
|
||||
$this->readProductsMoney();
|
||||
$this->readMoneyMovementMoney();
|
||||
$this->calcTotal();
|
||||
|
||||
$this->readProductsByCategory();
|
||||
$this->readProductsByCategoryDetailed();
|
||||
$this->readTicketStas();
|
||||
$this->readMoneyMovementsStats();
|
||||
|
||||
|
||||
$this->readTickets();
|
||||
$this->readProducts();
|
||||
$this->readMoneyMovements();
|
||||
|
||||
}
|
||||
|
||||
protected function calcTotal(){
|
||||
$this->total = 0;
|
||||
$this->total += $this->ticketMoney;
|
||||
$this->total += $this->productMoney;
|
||||
$this->total += $this->moneyMovementMoneis;
|
||||
}
|
||||
|
||||
|
||||
protected function addQueryFilters($query){
|
||||
$query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' );
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
|
||||
|
||||
$query->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $this->id_account,
|
||||
'transfer.type' => $this->type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
]);
|
||||
|
||||
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
|
||||
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];
|
||||
|
||||
|
||||
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
|
||||
|
||||
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readTicketStas(){
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['ticket_type.name as ticket_type_name' , 'coalesce(sum(abs(transfer.count)),0) AS ticket_count', 'coalesce(sum(abs(transfer.money)),0) AS ticket_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||
$query->innerJoin("ticket", "ticket.id_ticket = transfer.id_object");
|
||||
$query->innerJoin("ticket_type", "ticket.id_ticket_type = ticket_type.id_ticket_type");
|
||||
|
||||
$query->groupBy(['ticket_type.id_ticket_type','ticket_type.name']);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
|
||||
$this->ticketStats = $query->all();
|
||||
}
|
||||
|
||||
|
||||
protected function readTicketMoney(){
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([' coalesce(sum(abs(transfer.money)),0) AS ticket_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||
$query->innerJoin("ticket", "ticket.id_ticket = transfer.id_object");
|
||||
$this->addQueryFilters($query);
|
||||
$this->ticketMoney = $query->scalar();
|
||||
}
|
||||
|
||||
protected function readProductsByCategory(){
|
||||
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['coalesce(sum(transfer.money),0) AS product_money', 'coalesce(sum(transfer.count),0) as category_count', 'product_category.name as category_name']);
|
||||
$query->from('transfer');
|
||||
$query->groupBy(['product_category.id_product_category','product_category.name']);
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||
$query->innerJoin("product_category", "product.id_product_category = product_category.id_product_category");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->productMoneies = $query->all();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readProductsByCategoryDetailed(){
|
||||
|
||||
$formatted = [];
|
||||
$formatted['categories'] = [];
|
||||
$formatted['total'] = 0;
|
||||
$prevCategory = null;
|
||||
$curCategory = null;
|
||||
|
||||
$category = null;
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['product_category.id_product_category as product_category_id','product_category.name as product_category_name', 'product.name as product_name' ,'coalesce(sum(transfer.money),0) AS product_money', 'coalesce(sum(transfer.count),0) as product_count']);
|
||||
$query->from('transfer');
|
||||
$query->groupBy(['product.id_product','product.name','product_category.id_product_category','product_category.name']);
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||
$query->innerJoin("product_category", "product.id_product_category = product_category.id_product_category");
|
||||
$query->orderBy(['product_category.name' => SORT_ASC,'product.name' => SORT_ASC]);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$result = $query->all();
|
||||
|
||||
foreach ($result as $row){
|
||||
$curCategory = $row['product_category_id'];
|
||||
if ( $curCategory != $prevCategory ){
|
||||
//store last category
|
||||
if ( $category != null ){
|
||||
$formatted['categories'][] = $category;
|
||||
}
|
||||
$prevCategory = $curCategory;
|
||||
//create new category
|
||||
$category = [];
|
||||
$category['category'] = [];
|
||||
$category['category']['name'] = $row['product_category_name'];
|
||||
$category['category']['id'] = $row['product_category_id'];
|
||||
$category['products'] = [];
|
||||
$category['total'] = 0;
|
||||
|
||||
}
|
||||
$category['products'][] = $row;
|
||||
$category['total'] += $row['product_money'];
|
||||
$formatted['total'] += $row['product_money'];
|
||||
|
||||
}
|
||||
|
||||
if ( $category != null ){
|
||||
$formatted['categories'][]= $category;
|
||||
}
|
||||
|
||||
$this->productsByCategory = $formatted;
|
||||
|
||||
}
|
||||
|
||||
protected function readProductsMoney(){
|
||||
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['coalesce(sum(transfer.money),0) AS product_money' ]);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->productMoney = $query->scalar();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readMoneyMovementMoney(){
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([' coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN. ' then transfer.money else -1 * transfer.money end ),0) AS money_movement_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
|
||||
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->moneyMovementMoneis = $query->scalar();
|
||||
}
|
||||
protected function readMoneyMovementsStats(){
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([ 'money_movement.type as money_movement_type', ' coalesce(count(transfer.id_transfer),0) AS money_movement_count', 'coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN. ' then transfer.money else -1 * transfer.money end ),0) AS money_movement_money']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
|
||||
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");
|
||||
$query->groupBy(['money_movement.type']);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->moneyMovementsByType = $query->all();
|
||||
for ($i = 0; $i < count($this->moneyMovementsByType) ;$i++ ){
|
||||
$this->moneyMovementsByType[$i]['name'] = MoneyMovement::typeName($this->moneyMovementsByType[$i]['money_movement_type']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function readTickets(){
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['account.name as account_name','ticket_type.name as ticket_type_name' , 'transfer.count AS ticket_count', 'transfer.money AS ticket_money','transfer.item_price AS ticket_item_price', 'transfer.created_at as ticket_created_at','transfer.paid_at as ticket_paid_at']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||
$query->innerJoin("ticket", "ticket.id_ticket = transfer.id_object");
|
||||
$query->innerJoin("ticket_type", "ticket.id_ticket_type = ticket_type.id_ticket_type");
|
||||
$query->innerJoin("account", "transfer.id_account = account.id_account");
|
||||
$query->orderBy(['transfer.created_at' => SORT_ASC]);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
|
||||
$this->tickets = $query->all();
|
||||
|
||||
for ($i = 0; $i < count($this->tickets) ;$i++ ){
|
||||
$this->tickets[$i]['ticket_created_at'] = Yii::$app->formatter->asDatetime($this->tickets[$i]['ticket_created_at'], 'yyyy.MM.dd HH:mm:ss');
|
||||
$this->tickets[$i]['ticket_paid_at'] = empty($this->tickets[$i]['ticket_paid_at'] ) ? '-' : Yii::$app->formatter->asDatetime($this->tickets[$i]['ticket_paid_at'], 'yyyy.MM.dd HH:mm:ss');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function readProducts(){
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([ 'account.name as account_name' , 'product_category.name as product_category_name', 'product.name as product_name', 'transfer.money AS product_money', 'transfer.count AS product_count', 'transfer.money AS product_money','transfer.item_price AS product_item_price', 'transfer.created_at as product_created_at','transfer.paid_at as product_paid_at']);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||
$query->innerJoin("product_category", "product.id_product_category = product_category.id_product_category");
|
||||
$query->innerJoin("account", "transfer.id_account = account.id_account");
|
||||
$query->orderBy(['transfer.created_at' => SORT_ASC]);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->products = $query->all();
|
||||
|
||||
for ($i = 0; $i < count($this->products) ;$i++ ){
|
||||
$this->products[$i]['product_created_at'] = Yii::$app->formatter->asDatetime($this->products[$i]['product_created_at'], 'yyyy.MM.dd HH:mm:ss');
|
||||
$this->products[$i]['product_paid_at'] = empty($this->products[$i]['product_paid_at'] ) ? '-' : Yii::$app->formatter->asDatetime($this->products[$i]['product_paid_at'], 'yyyy.MM.dd HH:mm:ss');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function readMoneyMovements(){
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select([ 'account.name as account_name', 'transfer.direction as transfer_direction' ,'money_movement.type as money_movement_type', 'transfer.money AS money_movement_money', 'money_movement.name as money_movement_name','transfer.created_at as money_movement_created_at', ]);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_MONEY_MOVEMENT_OUT]);
|
||||
$query->innerJoin("money_movement", "money_movement.id_money_movement = transfer.id_object");
|
||||
$query->innerJoin("account", "transfer.id_account = account.id_account");
|
||||
$query->orderBy(['transfer.created_at' => SORT_ASC]);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->moneyMovements = $query->all();
|
||||
|
||||
for ($i = 0; $i < count($this->moneyMovements) ;$i++ ){
|
||||
$this->moneyMovements[$i]['money_movement_type_name'] = MoneyMovement::typeName($this->moneyMovements[$i]['money_movement_type']);
|
||||
$this->moneyMovements[$i]['money_movement_created_at'] = Yii::$app->formatter->asDatetime($this->moneyMovements[$i]['money_movement_created_at'], 'yyyy.MM.dd HH:mm:ss');
|
||||
$this->moneyMovements[$i]['signed_money'] = Transfer::toSignedMoney($this->moneyMovements[$i]['transfer_direction'],$this->moneyMovements[$i]['money_movement_money']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use frontend\components\HtmlHelper;
|
||||
use common\models\MoneyMovement;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\MoneyMovement */
|
||||
@ -18,6 +19,8 @@ $accountOptions = HtmlHelper::mkAccountOptions($accounts);
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
|
||||
|
||||
<?= $form->field($model, 'type')->dropDownList(MoneyMovement::types()) ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
|
||||
@ -25,6 +25,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
'accountName',
|
||||
'userName',
|
||||
[
|
||||
'attribute' => 'type',
|
||||
'value' =>'humanType'
|
||||
],
|
||||
'name',
|
||||
'money',
|
||||
'created_at:datetime',
|
||||
|
||||
@ -78,6 +78,8 @@ $this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale');
|
||||
.table-transfers .product-money{
|
||||
width: 100px;
|
||||
}
|
||||
.typeahead.dropdown-menu{
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
59
frontend/views/transfer/_search_list.php
Normal file
59
frontend/views/transfer/_search_list.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use kartik\widgets\DatePicker;
|
||||
use frontend\components\HtmlHelper;
|
||||
use common\models\Transfer;
|
||||
use kartik\widgets\DateTimePicker;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\TransferSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
$accountOptions = ['' =>'Mind']+ HtmlHelper::mkAccountOptions( $model->accounts );
|
||||
?>
|
||||
|
||||
<div class="transfer-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['list'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'start')->widget(DateTimePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
]
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'end') ->widget(DateTimePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd hh:ii'
|
||||
]
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
379
frontend/views/transfer/list.php
Normal file
379
frontend/views/transfer/list.php
Normal file
@ -0,0 +1,379 @@
|
||||
<?php
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\widgets\ListView;
|
||||
use yii\base\Widget;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel common\models\TransferSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t ( 'frontend/transfer', 'Daily transfers' );
|
||||
$this->params ['breadcrumbs'] [] = $this->title;
|
||||
?>
|
||||
<style>
|
||||
.dl-transfer {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.item-transfer {
|
||||
border: 1px solid #b4b4b4;
|
||||
margin-top: 12px;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
td.count, td.money{
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
td.name{
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
.table-category-product td.name{
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
.table-category-product td.count{
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.table-category-product td.money{
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="transfer-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php echo $this->render('_search_list', ['model' => $searchModel]); ?>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" class="active"><a href="#big"
|
||||
aria-controls="big" role="tab" data-toggle="tab">Egyszerű összesítő</a></li>
|
||||
<li role="presentation"><a href="#medium" aria-controls="medium"
|
||||
role="tab" data-toggle="tab">Közepes összesítő</a></li>
|
||||
<li role="presentation"><a href="#detailed" aria-controls="detailed"
|
||||
role="tab" data-toggle="tab">Részletes összesítő</a></li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="big">
|
||||
<h2>Egyszerű összesítés</h2>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Bérletek</th>
|
||||
<td class="money"><?php echo $searchModel->ticketMoney?> FT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Termékek</th>
|
||||
<td class="money"><?php echo $searchModel->productMoney?> FT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Pénzmozgások</th>
|
||||
<td class="money"><?php echo $searchModel->moneyMovementMoneis?> FT</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Végösszeg</th>
|
||||
<td class="money"><span style='border-bottom: 1px solid black'><?php echo $searchModel->total?> FT</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="medium">
|
||||
<h2>Közepes összesítés</h2>
|
||||
|
||||
<h3>Bérletek típus szerint</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Bérlet típus</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $searchModel->ticketStats as $ticketStat ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="name"><?php echo $ticketStat['ticket_type_name'] ?></td>
|
||||
<td class="count"><?php echo $ticketStat['ticket_count']?> Db</td>
|
||||
<td class="money"><?php echo $ticketStat['ticket_money']?> FT</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->ticketMoney; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<h3>Termékek kategória szerint</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Termék kategória</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $searchModel->productMoneies as $pm ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="name"><?php echo $pm['category_name'] ?></td>
|
||||
<td class="count"><?php echo $pm['category_count']?> Db</td>
|
||||
<td class="money"><?php echo $pm['product_money']?> FT</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->productMoney; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>Termékek kategória szerint részletes</h3>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
foreach($searchModel->productsByCategory['categories'] as $categoryHolder ){
|
||||
|
||||
$products = $categoryHolder['products'];
|
||||
?>
|
||||
<h4><?php echo $categoryHolder['category']['name']?></h4>
|
||||
|
||||
<table class="table table-bordered table-striped table-summary table-category-product">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Termék</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $products as $p){?>
|
||||
|
||||
<tr>
|
||||
<td class='name'><?php echo $p['product_name'] ?></td>
|
||||
<td class='count'><?php echo $p['product_count'] ?> Db</td>
|
||||
<td class='money'><?php echo $p['product_money']?> FT</td>
|
||||
</tr>
|
||||
|
||||
<?php }?>
|
||||
<tr class="warning">
|
||||
<td><?php echo "Összesen" ?></td>
|
||||
<td><?php ?></td>
|
||||
<td class='money'><?php echo $categoryHolder['total']?> FT</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen:
|
||||
<?php
|
||||
echo $searchModel->productsByCategory['total'];
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>Pénzmozgások típus szerint</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Pénzmozgás típus</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $searchModel->moneyMovementsByType as $mmStat ) {
|
||||
?>
|
||||
<tr>
|
||||
<td class="name"><?php echo $mmStat['name'] ?></td>
|
||||
<td class="count"><?php echo $mmStat['money_movement_count']?> Db</td>
|
||||
<td class="money"><?php echo $mmStat['money_movement_money']?> FT</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->moneyMovementMoneis; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline; font-weight: bold;">
|
||||
Végösszeg: <?php echo $searchModel->total; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="detailed">
|
||||
<h2>Részletes összesítés</h2>
|
||||
<h3>Bérletek</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kiadva</th>
|
||||
<th>Fizetve</th>
|
||||
<th>Kassza</th>
|
||||
<th>Bérlet típus</th>
|
||||
<th>Egység ár</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($searchModel->tickets as $t ){?>
|
||||
<tr>
|
||||
<td><?php echo $t['ticket_created_at']?> </td>
|
||||
<td><?php echo $t['ticket_paid_at']?> </td>
|
||||
<td><?php echo $t['account_name']?> </td>
|
||||
<td><?php echo $t['ticket_type_name'] ?></td>
|
||||
<td class='money'><?php echo $t['ticket_item_price']?> Ft</td>
|
||||
<td class='count'><?php echo $t['ticket_count']?> Db</td>
|
||||
<td class='money'><?php echo $t['ticket_money']?> FT</td>
|
||||
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if ( count($searchModel->tickets ) == 0 ) {
|
||||
?>
|
||||
Nincs találat
|
||||
<?php
|
||||
}else{?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->ticketMoney; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h3>Termék eladások</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kiadva</th>
|
||||
<th>Fizetve</th>
|
||||
<th>Kassza</th>
|
||||
<th>Kategória</th>
|
||||
<th>Termék</th>
|
||||
<th>Egység ár</th>
|
||||
<th>Mennyiség</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($searchModel->products as $p ){?>
|
||||
<tr>
|
||||
<td><?php echo $p['product_created_at']?> </td>
|
||||
<td><?php echo $p['product_paid_at']?> </td>
|
||||
<td><?php echo $p['account_name']?> </td>
|
||||
<td><?php echo $p['product_category_name'] ?></td>
|
||||
<td><?php echo $p['product_name'] ?></td>
|
||||
<td class='money'><?php echo $p['product_item_price']?> Ft</td>
|
||||
<td class='count'><?php echo $p['product_count']?> Db</td>
|
||||
<td class='money'><?php echo $p['product_money']?> FT</td>
|
||||
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if ( count($searchModel->products ) == 0 ) {
|
||||
?>
|
||||
Nincs találat
|
||||
<?php
|
||||
}else{?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->productMoney; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>Pénzmozgások</h3>
|
||||
<table class="table table-bordered table-striped table-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Dátum</th>
|
||||
<th>Kassza</th>
|
||||
<th>Név</th>
|
||||
<th>Típus</th>
|
||||
<th>Összeg</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($searchModel->moneyMovements as $p ){?>
|
||||
<tr>
|
||||
<td><?php echo $p['money_movement_created_at']?> </td>
|
||||
<td><?php echo $p['account_name']?> </td>
|
||||
<td><?php echo $p['money_movement_name'] ?></td>
|
||||
<td><?php echo $p['money_movement_type_name'] ?></td>
|
||||
<td class='money'><?php echo $p['signed_money']?> Ft</td>
|
||||
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if ( count($searchModel->moneyMovements ) == 0 ) {
|
||||
?>
|
||||
Nincs találat
|
||||
<?php
|
||||
}else{?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline;">
|
||||
Összesen: <?php echo $searchModel->moneyMovementMoneis; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right" style="text-decoration: underline; font-weight: bold;">
|
||||
Végösszeg: <?php echo $searchModel->total; ?> Ft
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@ -538,7 +538,7 @@ function ProductSell(o){
|
||||
var $input = $('#product_search');
|
||||
$input.typeahead({source: app.defaults.products,
|
||||
autoSelect: true,
|
||||
items: 12,
|
||||
items: 20,
|
||||
minLength: 3,
|
||||
// displayText: function (item){
|
||||
// return item.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user