fix account_state ( collection_money ), display product/ticket on reception only for selected account, add daily transfers (reception/admin)

This commit is contained in:
2015-12-31 13:52:22 +01:00
parent 72fc139674
commit f59eadd8cc
26 changed files with 1153 additions and 404 deletions

View File

@@ -18,7 +18,11 @@ class AccountStateBanknoteCountWidget extends Widget{
$panelStyleClas = 'panel-default';
if ( $this->model->hasDifferenceToPrevState()){
$panelStyleClas = 'panel-danger';
if ( $this->model->hasPlus()){
$panelStyleClas = 'panel-success';
}else if ( $this->model->hasMinus() ){
$panelStyleClas = 'panel-danger';
}
}
$s = "";
@@ -27,8 +31,51 @@ class AccountStateBanknoteCountWidget extends Widget{
$s .= "Kassza művelet - " . $this->model->typeName;
$s .= Html::endTag("div");
$s .= Html::beginTag("div",['class' => 'panel-body '] );
$s .= $this->generateInfoRow();
$s .= $this->generateNotes();
if ( $this->model->hasDifferenceToPrevState()){
$ft = " Ft";
$s .= DetailView::widget([
'model' => $this->model,
'template' =>"<tr><th>{label}</th><td style='text-align: right;'>{value} </td></tr>",
'attributes' => [
[
'label' => "Előző nyitás ideje",
'value' => $this->model->prevObject ? \Yii::$app->formatter->asDatetime( $this->model->prevObject->created_at) : "-",
],
[
'label' => "Előzőleg nyitott",
'value' => $this->model->prevObject ? $this->model->user->username : "-",
],
[
'label' => "Előző nyitás összege",
'value' => $this->model->prev_money.$ft
],
[
'label' => "Bevételek összesen utolsó nyitás óta",
'value' => $this->model->collection_money .$ft
],
[
'label' => "Zárás összege",
'value' => $this->model->money.$ft
],
[
'label' => "Várt összeg",
'value' => $this->model->expected.$ft
],
[
'label' => "Különbözet",
'value' => $this->model->signedDiff.$ft
],
]
]);
}
$s .= $this->generateComment();
$s .= Html::endTag("div");
$s .= Html::endTag("div");

View File

@@ -7,6 +7,7 @@ use yii\helpers\Html;
use common\models\MoneyMovement;
use yii\db\Query;
use common\models\AccountState;
use backend\models\AccountSearch;
class FrontendMenuStructure{
@@ -20,8 +21,8 @@ class FrontendMenuStructure{
public function __construct(){
$this->menuItems = [];
$this->start = Yii::$app->formatter->asDatetime( strtotime('today UTC') );
$this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') );
$this->start = \Yii::$app->formatter->asDatetime( strtotime('today') );
$this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow') );
$this->startDate = Yii::$app->formatter->asDate( strtotime('today UTC') );
$this->tomorrowDate = Yii::$app->formatter->asDate( strtotime('tomorrow UTC') );
@@ -30,7 +31,7 @@ class FrontendMenuStructure{
if ( $this->isLogged() ){
$lastAccountState = AccountState::find()->andWhere(['id_user' => Yii::$app->user->id])->orderBy(['account_state.created_at' => SORT_DESC])->limit(1)->one();
$lastAccountState = AccountState::find()->andWhere(['id_user' => Yii::$app->user->id])->andWhere(['type' => AccountState::TYPE_OPEN ])->orderBy(['account_state.created_at' => SORT_DESC])->limit(1)->one();
if ( isset($lastAccountState) ){
$this->start = Yii::$app->formatter->asDatetime(strtotime( $lastAccountState->created_at . ' UTC' ));
}

View File

@@ -84,6 +84,8 @@ class AccountStateController extends Controller
*/
public function actionClose()
{
$lastStates = AccountState::readLastForUser(AccountState::TYPE_OPEN );
$lastStates = AccountState::modelsToArray($lastStates);
$model = new AccountState();
$model->type = AccountState::TYPE_CLOSE;
$model->id_user = Yii::$app->user->id;
@@ -97,6 +99,7 @@ class AccountStateController extends Controller
return $this->render('close', [
'model' => $model,
'accounts' => $accounts,
'lastStates' => $lastStates,
]);
}
}

View File

@@ -82,7 +82,7 @@ class ProductController extends Controller
$model->customer = $this->customer;
$model->card = $this->card;
$products = Product::read();
$products = Product::readForDefaultAccount();
$products = Product::modelToMapIdName($products);
$model->products = $products;
@@ -199,7 +199,7 @@ class ProductController extends Controller
public function actionLookup($query = null)
{
$result = [];
$product = Product::findProduct($query);
$product = Product::findProduct($query, Account::readDefault());
$product = Product::modelToArray($product);
$result['product'] = $product;
@@ -207,7 +207,6 @@ class ProductController extends Controller
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
}

View File

@@ -97,7 +97,7 @@ class TicketController extends FrontendController
$discounts = Discount::read();
$ticketTypes = TicketType::read();
$ticketTypes = TicketType::read(null, Account::readDefault());
$accounts = Account::readAccounts();

View File

@@ -16,360 +16,8 @@ use common\models\MoneyMovement;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferListSearch extends Transfer
class TransferListSearch extends \common\models\TransferListSearch
{
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']);
}
}
}

View File

@@ -13,7 +13,6 @@ $this->params['breadcrumbs'][] = $this->title;
AccountStateAsset::register($this);
$options = [];
$this->registerJs ( 'new AccountState( '. json_encode($options).');' );
?>
<div class="account-state-create">

View File

@@ -68,7 +68,14 @@ AppAsset::register($this);
<div class="container">
<p class="pull-left">&copy; <?= Yii::$app->name ?> <?= Yii::$app->params['version'] ?> Fitness - WebAdmin <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
<div class="container">
<div>
Az oldalon szereplő adatok csak tájékoztató jellegűek.<br>
Az adatok helyességéért és igazságtartalmáért felelősséget nem vállalunk.<br>
Az oldal nem használható hivatalos adatforrásként.<br>
</div>
</div>
</footer>

View File

@@ -6,6 +6,7 @@ use frontend\assets\ProductSellAsset;
use frontend\components\ReceptionWidget;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
@@ -82,7 +83,7 @@ $this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale');
}
</style>
<?php echo ReceptionWidget::widget( ['form' => $receptionForm, 'route' => ['customer/reception'] ] )?>
<div class='row '>

View File

@@ -30,6 +30,7 @@ $options['clear_cart_url'] = Url::toRoute(['product/clear-list']);
$options['types'] = TicketType::modelsToArray($ticketTypes);
$options['user_cart'] = $model->userCart;
$options['customer_cart'] = $model->customerCart;
$options['selected_type'] = count($ticketTypes) > 0 ? $ticketTypes[0]->id_ticket_type : 0;
$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>

View File

@@ -1,6 +1,7 @@
<?php
use yii\helpers\Html;
use common\models\Transfer;
/* @var $this yii\web\View */
@@ -35,6 +36,9 @@ $formatter = Yii::$app->formatter;
<dl class="dl-horizontal dl-transfer">
<dt><?php echo $model->getAttributeLabel( 'type') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'transferTypeName') ?></dd>
<dt>Megnevezés</dt>
<dd><?php echo Html::getAttributeValue($model, 'objectName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_user') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'userName') ?></dd>

View File

@@ -232,6 +232,11 @@ td.name{
</div>
<div role="tabpanel" class="tab-pane" id="detailed">
<h2>Részletes összesítés</h2>
<?php
//////////////////////////
// Bérletek
////////////////////////
?>
<h3>Bérletek</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
@@ -239,6 +244,7 @@ td.name{
<th>Kiadva</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Bérlet típus</th>
<th>Egység ár</th>
<th>Mennyiség</th>
@@ -248,13 +254,14 @@ td.name{
<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>
<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['user_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 } ?>
@@ -275,6 +282,11 @@ td.name{
<?php
}
?>
<?php
//////////////////////////
// Termék eladás
////////////////////////
?>
<h3>Termék eladások</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
@@ -282,6 +294,7 @@ td.name{
<th>Kiadva</th>
<th>Fizetve</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Kategória</th>
<th>Termék</th>
<th>Egység ár</th>
@@ -295,6 +308,7 @@ td.name{
<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['user_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>
@@ -320,13 +334,18 @@ td.name{
<?php
}
?>
<?php
//////////////////////////
// Pénzmozgások
////////////////////////
?>
<h3>Pénzmozgások</h3>
<table class="table table-bordered table-striped table-summary">
<thead>
<tr>
<th>Dátum</th>
<th>Kassza</th>
<th>Felhasználó</th>
<th>Név</th>
<th>Típus</th>
<th>Összeg</th>
@@ -337,6 +356,7 @@ td.name{
<tr>
<td><?php echo $p['money_movement_created_at']?> </td>
<td><?php echo $p['account_name']?> </td>
<td><?php echo $p['user_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>