From 8585286150d00086a4f5991358a7d596b733c1b4 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Wed, 5 Oct 2016 07:56:50 +0200 Subject: [PATCH 1/2] add non cash money display to account state --- .../accountstate/AccountStateWidget.php | 16 +- common/models/AccountState.php | 62 +-- common/models/Currency.php | 13 +- common/models/Discount.php | 60 ++- common/models/Ticket.php | 48 +- common/models/Transfer.php | 456 +++++++++++------- ...ccount_state_add_column_non_cash_money.php | 30 ++ .../controllers/AccountStateController.php | 48 +- 8 files changed, 454 insertions(+), 279 deletions(-) create mode 100644 console/migrations/m161004_062500_alter__table__account_state_add_column_non_cash_money.php diff --git a/common/components/accountstate/AccountStateWidget.php b/common/components/accountstate/AccountStateWidget.php index c368403..eca630a 100644 --- a/common/components/accountstate/AccountStateWidget.php +++ b/common/components/accountstate/AccountStateWidget.php @@ -1,16 +1,12 @@ 'money', 'value' => \Yii::$app->formatter->asInteger($this->model->money) ." Ft", ], + [ + 'attribute' => 'non_cash_money', + 'label' => 'Készpénz alapú forgalom', + 'value' => \Yii::$app->formatter->asInteger($this->model->collection_money) ." Ft", + ], + [ + 'attribute' => 'non_cash_money', + 'label' => 'Nem készpénz alapú forgalom', + 'value' => \Yii::$app->formatter->asInteger($this->model->non_cash_money) ." Ft", + ], 'user.username', [ 'attribute' => 'start_date', diff --git a/common/models/AccountState.php b/common/models/AccountState.php index 0ec2689..8d3c8e8 100644 --- a/common/models/AccountState.php +++ b/common/models/AccountState.php @@ -2,9 +2,9 @@ namespace common\models; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use yii\helpers\ArrayHelper; -use yii\behaviors\TimestampBehavior; /** * This is the model class for table "account_state". @@ -29,8 +29,9 @@ use yii\behaviors\TimestampBehavior; * @property integer $collection_money * @property string $created_at * @property string $updated_at + * @property int non_cash_money */ -class AccountState extends \common\models\BaseFitnessActiveRecord +class AccountState extends BaseFitnessActiveRecord { const TYPE_OPEN = 10; @@ -38,17 +39,7 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public $start_date; - /** - * @inheritdoc - */ -// public function behaviors() -// { -// return [[ -// 'class' => TimestampBehavior::className(), -// 'value' => function(){ return date('Y-m-d H:i' ); } -// ] ]; -// } - + /** * @inheritdoc */ @@ -138,7 +129,9 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public function getAccountName(){ $result = ""; - $account = $this->account; + /** @noinspection PhpUndefinedFieldInspection */ + /** @var \common\models\Account $account */ + $account = $this->account; if (isset($account)){ $result = $account->name; } @@ -156,7 +149,8 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public function getUserName(){ $result = ""; - $user = $this->user; + /** @noinspection PhpUndefinedFieldInspection */ + $user = $this->user; if (isset($this->user)){ $result = $user->username; } @@ -188,14 +182,14 @@ class AccountState extends \common\models\BaseFitnessActiveRecord } return $result; } - + /** * Read last accountstates * @param $type int the type of accountstate to load * @param $user $id of user to load the account - * @return common\models\AccountState - * - * */ + * @param \common\models\Account|null $account + * @return AccountState + */ public static function readLast($type, $user = null,$account = null){ $result = null; $query = AccountState::find(); @@ -224,20 +218,23 @@ class AccountState extends \common\models\BaseFitnessActiveRecord $start = null; $end = null; $prev = null; - $this->prev_money = 0; + /** @noinspection PhpUndefinedFieldInspection */ + $this->prev_money = 0; if ( $this->type == AccountState::TYPE_CLOSE){ $lastOpen = AccountState::readLast(AccountState::TYPE_OPEN,\Yii::$app->user->id, $this->id_account); if ( $lastOpen != null ){ $start = $lastOpen->created_at; - $this->prev_state = $lastOpen->id_account_state; - $this->prev_money = $lastOpen->money; + /** @noinspection PhpUndefinedFieldInspection */ + $this->prev_state = $lastOpen->id_account_state; + /** @noinspection PhpUndefinedFieldInspection */ + $this->prev_money = $lastOpen->money; } $end = date('Y-m-d H:i:s' ); // $end = Yii::$app->formatter->asDatetime(strtotime("now"), "php:Y-m-d H:i:s"); - $this->collection_money = Transfer::readPaid($start, $end, Yii::$app->user->id); - + $this->collection_money = Transfer::readPaidCash($start, $end, Yii::$app->user->id); + $this->non_cash_money = Transfer::readPaidNonCash($start, $end, Yii::$app->user->id); } } @@ -248,7 +245,8 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public function hasDifferenceToPrevState(){ $result = false; if ( $this->type == self::TYPE_CLOSE){ - $result = ( $this->prev_money + $this->collection_money) != $this->money; + /** @noinspection PhpUndefinedFieldInspection */ + $result = ( $this->prev_money + $this->collection_money) != $this->money; } return $result; } @@ -256,7 +254,8 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public function hasPlus(){ $result = false; if ( $this->type == self::TYPE_CLOSE){ - $result = ( $this->prev_money + $this->collection_money) < $this->money; + /** @noinspection PhpUndefinedFieldInspection */ + $result = ( $this->prev_money + $this->collection_money) < $this->money; } return $result; } @@ -264,18 +263,21 @@ class AccountState extends \common\models\BaseFitnessActiveRecord public function hasMinus(){ $result = false; if ( $this->type == self::TYPE_CLOSE){ - $result =( $this->prev_money + $this->collection_money) > $this->money; + /** @noinspection PhpUndefinedFieldInspection */ + $result =( $this->prev_money + $this->collection_money) > $this->money; } return $result; } public function getSignedDiff(){ - $result = $this->money - ( $this->prev_money + $this->collection_money); + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->money - ( $this->prev_money + $this->collection_money); return $result; } public function getExpected(){ - $result = $this->prev_money + $this->collection_money ; + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->prev_money + $this->collection_money ; return $result; } diff --git a/common/models/Currency.php b/common/models/Currency.php index c169e1f..06d3504 100644 --- a/common/models/Currency.php +++ b/common/models/Currency.php @@ -2,7 +2,8 @@ namespace common\models; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; /** * This is the model class for table "currency". @@ -14,7 +15,7 @@ use Yii; * @property string $created_at * @property string $updated_at */ -class Currency extends \common\models\BaseFitnessActiveRecord +class Currency extends BaseFitnessActiveRecord { /** * @inheritdoc @@ -51,11 +52,13 @@ class Currency extends \common\models\BaseFitnessActiveRecord 'updated_at' => Yii::t('common/currency', 'Updated At'), ]; } - + /** * @param integer $money - * @param common\models\Currency $currency - * */ + * @param \common\models\Currency $currency + * + * @return float + */ public static function applyCurrency( $money,$currency ) { $result = $money / $currency; return $result; diff --git a/common/models/Discount.php b/common/models/Discount.php index f5cc1f9..6ee89b4 100644 --- a/common/models/Discount.php +++ b/common/models/Discount.php @@ -2,7 +2,8 @@ namespace common\models; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use yii\behaviors\TimestampBehavior; use yii\helpers\ArrayHelper; @@ -18,6 +19,7 @@ use yii\helpers\ArrayHelper; * @property integer $ticket_enabled * @property string $created_at * @property string $updated_at + * @property mixed id_discount */ class Discount extends \yii\db\ActiveRecord { @@ -86,7 +88,7 @@ class Discount extends \yii\db\ActiveRecord public function getStatusHuman(){ $result = null; - $s = self::statuses($this->status); + $s = self::statuses(); if ( array_key_exists($this->status, $s)){ $result = $s[$this->status]; } @@ -101,41 +103,59 @@ class Discount extends \yii\db\ActiveRecord public function getTypeHuman(){ $result = null; - $s = self::types($this->type); + $s = self::types(); if ( array_key_exists($this->type, $s)){ $result = $s[$this->type]; } return $result; } - - public function getProcutEnabledHuman(){ + + /** + * @return string + */ + public function getProcutEnabledHuman(){ return $this->product_enabled == 1 ? 'Igen' : 'Nem'; } - - public function getTicketEnabledHuman(){ + + /** + * @return string + */ + public function getTicketEnabledHuman(){ return $this->ticket_enabled == 1 ? 'Igen' : 'Nem'; } - - public static function read(){ + + /** + * @return array|\yii\db\ActiveRecord[] + */ + public static function read(){ return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE ])->all(); } - - - public static function readProductDiscounts(){ + + + /** + * @return array|\yii\db\ActiveRecord[] + */ + public static function readProductDiscounts(){ return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE , 'product_enabled' => 1 ])->all(); } - - public static function readTicketDiscounts(){ + + /** + * @return array|\yii\db\ActiveRecord[] + */ + public static function readTicketDiscounts(){ return Discount::find()->andWhere([ 'status' => self::STATUS_ACTIVE , 'ticket_enabled' => 1 ])->all(); } - - /** - * @param integer $money - * @param common\models\Discount $discount - * */ + + /** + * @param integer $money + * @param \common\models\Discount $discount + * + * @return int + */ public static function applyDiscount($money,$discount){ - $result = $money; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = $money; $valueOfDiscount = floor( $money * $discount->value / 100 ); $result = $money - $valueOfDiscount; return $result; diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 8f9dd1e..02f4437 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -29,6 +29,7 @@ use common\components\Helper; * @property string $comment * @property string $created_at * @property string $updated_at + * @property int id_contract */ class Ticket extends \common\models\BaseFitnessActiveRecord { @@ -133,7 +134,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord public function getCardNumber(){ $result = ""; - $card = $this->card; + /** @noinspection PhpUndefinedFieldInspection */ + $card = $this->card; if ( isset($card)){ $result = $card->number; } @@ -146,7 +148,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord public function getCustomerName(){ $result = ""; - $customer = $this->customer; + /** @noinspection PhpUndefinedFieldInspection */ + $customer = $this->customer; if ( isset($customer)){ $result = $customer->name; } @@ -171,23 +174,28 @@ class Ticket extends \common\models\BaseFitnessActiveRecord } public function getAccountName() { $result = ""; - $account = $this->account; + /** @noinspection PhpUndefinedFieldInspection */ + /** @var \common\models\Account $account */ + $account = $this->account; if ( isset($account) ){ - $result = $this->account->name; + $result = $account->name; } return $result; } public function getDiscountName() { $result = ""; - $discount = $this->discount; + /** @noinspection PhpUndefinedFieldInspection */ + /** @var \common\models\Discount $discount */ + $discount = $this->discount; if ( isset($discount) ){ - $result = $this->discount->name; + $result = $discount->name; } return $result; } public function getTicketTypeName() { $result = ""; - $ticketType = $this->ticketType; + /** @noinspection PhpUndefinedFieldInspection */ + $ticketType = $this->ticketType; if ( isset($ticketType) ){ $result = $ticketType->name; } @@ -195,17 +203,20 @@ class Ticket extends \common\models\BaseFitnessActiveRecord } public function getUserName() { $result = ""; - $user = $this->user; + /** @noinspection PhpUndefinedFieldInspection */ + $user = $this->user; if ( isset($user) ){ $result = $user->username; } return $result; } - - - /** - * @param common\models\Card $card the card to which we are looking for - * */ + + + /** + * @param \common\models\Card $card the card to which we are looking for + * + * @return array|\yii\db\ActiveRecord[] + */ public static function readActive($card){ if ( $card == null ) @@ -224,9 +235,12 @@ class Ticket extends \common\models\BaseFitnessActiveRecord return $result; } - /** - * @param common\models\Card $card the card to which we are looking for - * */ + + /** + * @param \common\models\Card $card the card to which we are looking for + * + * @return array|\yii\db\ActiveRecord[] + */ public static function readUnpaid($card){ if ( $card == null ) @@ -326,7 +340,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord /** * Apply request * - * @var common\models\TicketInstallmentRequest $request megbízás + * @var \common\models\TicketInstallmentRequest $request megbízás * */ public function applyTicketInstallmentRequest( $request ) { //ha csoportos beszedéses diff --git a/common/models/Transfer.php b/common/models/Transfer.php index ecea9f7..6e8f619 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -14,6 +14,7 @@ use yii\db\Query; use yii\db\Expression; use common\components\RoleDefinition; use common\components\Helper; +use yii\web\NotAcceptableHttpException; /** * This is the model class for table "transfer". @@ -37,6 +38,8 @@ use common\components\Helper; * @property integer $direction * @property string $paid_at * @property integer $id_customer + * @property int|string paid_by + * @property int payment_method */ class Transfer extends \common\models\BaseFitnessActiveRecord { const TYPE_PRODUCT = 10; @@ -205,7 +208,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } public function getPaidByName() { $result = ""; - $user = $this->paidByUser; + /** @noinspection PhpUndefinedFieldInspection */ + $user = $this->paidByUser; if (isset ( $this->paidByUser )) { $result = $user->username; } @@ -215,17 +219,21 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { public function getObjectName() { $result = ""; if ($this->type == Transfer::TYPE_TICKET) { - $result = $this->ticketName; + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->ticketName; } else if ($this->type == Transfer::TYPE_PRODUCT) { - $result = $this->productName; + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->productName; } else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) { - $result = $this->moneyMovement->humanType; + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->moneyMovement->humanType; } return $result; } public function getUserName() { $result = ""; - $user = $this->user; + /** @noinspection PhpUndefinedFieldInspection */ + $user = $this->user; if (isset ( $this->user )) { $result = $user->username; } @@ -234,7 +242,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } public function getProductName() { $result = ""; - $product = $this->product; + /** @noinspection PhpUndefinedFieldInspection */ + $product = $this->product; if (isset ( $product )) { $result = $product->name; } @@ -243,16 +252,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } public function getTicketName() { $result = ""; - $ticket = $this->ticket; + /** @noinspection PhpUndefinedFieldInspection */ + /** @var \common\models\Ticket $ticket */ + $ticket = $this->ticket; if (isset ( $ticket )) { - $result = $this->ticket->ticketTypeName; + /** @noinspection PhpUndefinedFieldInspection */ + $result = $this->ticket->ticketTypeName; } return $result; } public function getAccountName() { $result = ""; - $account = $this->account; + /** @noinspection PhpUndefinedFieldInspection */ + $account = $this->account; if (isset ( $account )) { $result = $account->name; } @@ -272,7 +285,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } public function getSaleName() { $result = ""; - $sale = $this->sale; + /** @noinspection PhpUndefinedFieldInspection */ + $sale = $this->sale; if (isset ( $sale )) { $result = $sale->name; } @@ -305,22 +319,27 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $s .= $this->count; $s .= " " . Yii::t ( 'frontend/transfer', 'pieces' ) . " "; - $s .= $this->product->name; + /** @noinspection PhpUndefinedFieldInspection */ + $s .= $this->product->name; $s .= " - "; - $s .= $this->account->name; + /** @noinspection PhpUndefinedFieldInspection */ + $s .= $this->account->name; return $s; } - - /** - * - * @param $account common\models\Account - * @param $discount common\models\Discount - * @param $currency common\models\Currency - * @param $product common\models\Product - * @param $customer common\models\Customer - * - */ + + /** + * + * @param $sale + * @param $account \common\models\Account + * @param $discount \common\models\Discount + * @param $currency \common\models\Currency + * @param $count + * @param $product \common\models\Product + * @param int $status + * @param $customer \common\models\Customer + * @return Transfer + */ public static function createProductTransfer($sale, $account, $discount, $currency, $count, $product, $status = Transfer::STATUS_PAID, $customer = null) { $transfer = new Transfer (); @@ -333,8 +352,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $transfer->count = $count; $totalPrice = $totalPrice * $count; - - if (isset ( $discount )) { + + /** @var \common\models\Discount $discount */ + if (isset ( $discount )) { $transfer->id_discount = $discount->id_discount; $totalPrice = Discount::applyDiscount ( $totalPrice, $discount ); } @@ -357,15 +377,15 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return $transfer; } - - /** - * - * @param $account common\models\Account - * @param $discount common\models\Discount - * @param $currency common\models\Currency - * @param $moneyMovement common\models\MoneyMovement - * - */ + + /** + * + * @param $account \common\models\Account + * @param $moneyMovement \common\models\MoneyMovement + * @return Transfer + * @internal param Discount $discount + * @internal param Currency $currency + */ public static function createMoneyMovementOutTransfer($account, $moneyMovement) { $transfer = new Transfer (); $transfer->payment_method = Transfer::PAYMENT_METHOD_CASH; @@ -388,14 +408,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return $transfer; } - /** - * - * @param $account common\models\Account - * @param $discount common\models\Discount - * @param $currency common\models\Currency - * @param $ticket common\models\Ticket - * - */ + + /** + * + * @param $account \common\models\Account + * @param $discount \common\models\Discount + * @param $currency \common\models\Currency + * @param $count int + * @param $ticket \common\models\Ticket + * + * @param int $status + * @return Transfer + */ public static function createTicketTransfer($account, $discount, $currency, $count, $ticket, $status = Transfer::STATUS_NOT_PAID) { $transfer = new Transfer (); @@ -412,15 +436,17 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $totalPrice = $totalPrice * $count; if (isset ( $discount )) { + /** @var \common\models\Discount $discount */ $transfer->id_discount = $discount->id_discount; - $totalPrice = Discount::applyDiscount ( $totalPrice, $discount ); + $totalPrice = Discount::applyDiscount ( $totalPrice, $discount ); } $transfer->money = $totalPrice; if (isset ( $currency )) { $transfer->rate = $currency->rate; - $transfer->money_currency = Currency::applyCurrency ( $totalPrice, $currency ); + /** @var \common\models\Currency $currency */ + $transfer->money_currency = Currency::applyCurrency ( $totalPrice, $currency ); } $transfer->id_account = $account->id_account; @@ -464,6 +490,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } else if ($transfer->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) { return "Pénzmozgás"; } + return "-"; } ] ] ); @@ -490,8 +517,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return $result; } public static function readUserSoldTransfers($user) { - $transfers = [ ]; - $query = Transfer::find (); $query->innerJoin ( "user_sold_item", "user_sold_item.id_transfer = transfer.id_transfer" ); @@ -501,9 +526,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { 'user_sold_item.id_user' => $user->id ] ); } - $transfers = $query->all (); + return $query->all (); - return $transfers; } public static function readCustomerCart($customer) { $transfers = [ ]; @@ -573,16 +597,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { public function beforeDelete() { parent::beforeDelete (); if ($this->type == Transfer::TYPE_TICKET) { - $ticket = $this->ticket; + /** @noinspection PhpUndefinedFieldInspection */ + $ticket = $this->ticket; if ($ticket != null) { $ticket->delete (); } } else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) { - $mm = $this->moneyMovement; + /** @noinspection PhpUndefinedFieldInspection */ + $mm = $this->moneyMovement; $mm->delete (); } else if ($this->type == Transfer::TYPE_PRODUCT) { - $sale = $this->sale; - $product = $this->product; + /** @noinspection PhpUndefinedFieldInspection */ + $sale = $this->sale; + /** @noinspection PhpUndefinedFieldInspection */ + $product = $this->product; $product->stock = $product->stock + $this->count; @@ -599,39 +627,45 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return true; } - - /** - * - * @param string $mode - * The mode to load - * Available modes - * - * - * - */ + + /** + * + * @param string $mode + * The mode to load + * Available modes + * + * + * + * @param $start + * @param $end + * @param $idUser + * @param $types + * @param $idAccount + * @return Query + */ public static function mkTotalQuery($mode, $start, $end, $idUser, $types, $idAccount) { $query = new Query (); @@ -698,7 +732,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return $query; } - public static function notInInterval($query, $field, $start, $end) { + + /** + * @param \yii\db\Query $query + * @param string $field + * @param string $start + * @param string $end + */ + public static function notInInterval($query, $field, $start, $end) { $query->andFilterWhere ( [ 'or', [ @@ -713,7 +754,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { ] ] ); } - public static function notPaid($query, $field, $start, $end) { + + /** + * @param \yii\db\Query $query + * @param string $field + * @param string $start + * @param string $end + */ + public static function notPaid($query, $field, $start, $end) { $query->andFilterWhere ( [ 'or', [ @@ -731,7 +779,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { ] ] ); } - public static function inInterval($query, $field, $start, $end) { + + /** + * @param \yii\db\Query $query + * @param string $field + * @param string $start + * @param string $end + */ + public static function inInterval($query, $field, $start, $end) { $query->andFilterWhere ( [ '>=', $field, @@ -743,15 +798,19 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $end ] ); } - - /** - * - * Parse query results so, that all available account will be display, even then , if $queryResult does not contain any result for the given account - * - * @param mixed $queryResult - * an array, wchic contains items. each item has to key - value pairs: [ id_account => 0, money => 0 ] - * - */ + + /** + * + * Parse query results so, that all available account will be display, even then , if $queryResult does not contain any result for the given account + * + * @param mixed $queryResult + * an array, wchic contains items. each item has to key - value pairs: [ id_account => 0, money => 0 ] + * + * @param $accounts + * @param $accountMap + * @param $idAccount + * @return array + */ public static function mkTotalsResultWithAllAvailableAccount($queryResult, $accounts, $accountMap, $idAccount) { $totals = [ ]; $totals ['total'] = 0; @@ -789,22 +848,38 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { } return $result; } - - /** - * create and execute a "total" query - */ + + /** + * create and execute a "total" query + * @param $mode + * @param $start + * @param $end + * @param $idUser + * @param $types + * @param $idAccount + * @return array + */ public static function exTotalQuery($mode, $start, $end, $idUser, $types, $idAccount) { $query = self::mkTotalQuery ( $mode, $start, $end, $idUser, $types, $idAccount ); $command = $query->createCommand (); $result = $command->queryAll (); return $result; } - - /** - * find all transfers which were paid in the period - */ + + /** + * find all transfers which were paid in the period + * @param $start + * @param $end + * @param $idUser + * @param $types + * @param $idAccount + * @param $accounts + * @param $accountMap + * @return array + */ public static function mkPaidAtTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) { - $result = [ ]; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = [ ]; $queryResult = self::exTotalQuery ( 'paid_at', $start, $end, $idUser, $types, $idAccount ); $result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount ); return $result; @@ -814,7 +889,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { * find all transfers in the period ( doesn't matter if paid or not ) */ public static function mkCreatedAtTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) { - $result = [ ]; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = [ ]; $queryResult = self::exTotalQuery ( 'created_at', $start, $end, $idUser, $types, $idAccount ); $result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount ); return $result; @@ -824,7 +900,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { * find transfers which were created but not paid in the period */ public static function mkCreatedAtNotPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) { - $result = [ ]; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = [ ]; $queryResult = self::exTotalQuery ( 'created_at_not_paid', $start, $end, $idUser, $types, $idAccount ); $result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount ); return $result; @@ -834,17 +911,27 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { * find transfers which were created and paid in the period */ public static function mkCreatedAtPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) { - $result = [ ]; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = [ ]; $queryResult = self::exTotalQuery ( 'created_at_paid', $start, $end, $idUser, $types, $idAccount ); $result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount ); return $result; } - - /** - * find transfers, where depth was paid - */ + + /** + * find transfers, where depth was paid + * @param $start + * @param $end + * @param $idUser + * @param $types + * @param $idAccount + * @param $accounts + * @param $accountMap + * @return array + */ public static function mkPaidAtNotCreatedAtPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) { - $result = [ ]; + /** @noinspection PhpUnusedLocalVariableInspection */ + $result = [ ]; $queryResult = self::exTotalQuery ( 'paid_at_not_created_at', $start, $end, $idUser, $types, $idAccount ); $result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount ); return $result; @@ -860,17 +947,21 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { return $result; } - - /** - * Ezt a függvényt használjuk a zárások összegének kiszámolására! - * A számolás csak a következő feltételekkel bíró tranzakciókat - * tartalmazza: - * - trazakció típus: common\models\Account::TYPE_ALL - * - tranzakció fizetési módja: készpénz - * - tranzakció státusza: fizetve - * - - */ - public static function readPaid($start, $end, $idUser) { + + /** + * Ezt a függvényt használjuk a zárások összegének kiszámolására! + * A számolás csak a következő feltételekkel bíró tranzakciókat + * tartalmazza: + * - trazakció típus: common\models\Account::TYPE_ALL + * - tranzakció fizetési módja: készpénz + * - tranzakció státusza: fizetve + * - + * @param $start + * @param $end + * @param $idUser + * @return bool|string + */ + public static function readPaidCash($start, $end, $idUser) { $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 transfer_money' @@ -880,51 +971,35 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $query->andWhere ( [ 'transfer.paid_by' => $idUser ] ); - - $created_condition = [ + + $created_condition = [ 'and', - [ - '>=', - 'transfer.created_at', - $start - ], - [ - '<', - 'transfer.created_at', - $end - ] + [ '>=', 'transfer.created_at', $start ], + [ '<', 'transfer.created_at', $end ] ]; - $paid_condition = [ + + $paid_condition = [ 'and', - [ - '>=', - 'transfer.paid_at', - $start - ], - [ - '<', - 'transfer.paid_at', - $end - ] + [ '>=', 'transfer.paid_at', $start ], + [ '<', 'transfer.paid_at', $end ] ]; - - $query->andFilterWhere ( [ + + $query->andFilterWhere ( [ 'or', $created_condition, $paid_condition ] ); - $query->andWhere ( [ - 'transfer.status' => Transfer::STATUS_PAID + + $query->andWhere ( [ + 'transfer.status' => Transfer::STATUS_PAID, + 'account.type' => Account::TYPE_ALL , + 'transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH ] ); - $query->andWhere ( [ - 'account.type' => Account::TYPE_ALL - ] ); - $query->andWhere ( [ - 'transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH - ] ); - - return $query->scalar (); + + return $query->scalar (); } + + public function storno() { $this->status = Transfer::STATUS_STORNO; $this->save ( false ); @@ -944,14 +1019,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { // storno contract } else if ($this->type == Transfer::TYPE_PRODUCT) { - $sale = $this->sale; - $product = $this->sale->product; + /** @noinspection PhpUndefinedFieldInspection */ + $sale = $this->sale; + /** @noinspection PhpUndefinedFieldInspection */ + /** @var \common\models\Product $product */ + $product = $this->sale->product; $product->stock = $product->stock + $this->count; $product->save ( false ); $sale->status = Sale::STATUS_DELETED; $sale->save ( false ); } else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) { - $mm = $this->moneyMovement; + /** @noinspection PhpUndefinedFieldInspection */ + $mm = $this->moneyMovement; $mm->status = MoneyMovement::STATUS_STORNO; $mm->save ( false ); } @@ -963,7 +1042,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { 'id_transfer' => $this->id_transfer ] ); } - public function unstorono() { + + /** + * @throws \yii\web\NotAcceptableHttpException + */ + public function unstorono() { if ($this->type != Transfer::TYPE_TICKET) { throw new NotAcceptableHttpException ( "Csak bérletet lehet visszaállítani" ); } @@ -989,7 +1072,52 @@ class Transfer extends \common\models\BaseFitnessActiveRecord { $item->id_transfer = $this->id_transfer; $item->save ( false ); } - + + + /** + * @param $start $start date + * @param $end $end date + * @param $idUser $user + * @return bool|string + */ + public static function readPaidNonCash($start, $end, $idUser) { + $query = (new Query()); + $query->select ( [ + 'coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN . ' then transfer.money else -1 * transfer.money end ),0) AS transfer_money' + ] ); + $query->from ( 'transfer' ); + $query->innerJoin ( "account", "account.id_account = transfer.id_account" ); + $query->andWhere ( [ + 'transfer.paid_by' => $idUser + ] ); + + $created_condition = [ + 'and', + [ '>=', 'transfer.created_at', $start ], + [ '<', 'transfer.created_at', $end ] + ]; + + $paid_condition = [ + 'and', + [ '>=', 'transfer.paid_at', $start ], + [ '<', 'transfer.paid_at', $end ] + ]; + + $query->andFilterWhere ( [ + 'or', + $created_condition, + $paid_condition + ] ); + + $query->andWhere ( [ + 'transfer.status' => Transfer::STATUS_PAID, + 'account.type' => Account::TYPE_ALL + ] ); + + $query->andWhere(['<>' ,'transfer.payment_method', Transfer::PAYMENT_METHOD_CASH ]); + + return $query->scalar (); + } public function payout($id_account = null) { diff --git a/console/migrations/m161004_062500_alter__table__account_state_add_column_non_cash_money.php b/console/migrations/m161004_062500_alter__table__account_state_add_column_non_cash_money.php new file mode 100644 index 0000000..22ad1fb --- /dev/null +++ b/console/migrations/m161004_062500_alter__table__account_state_add_column_non_cash_money.php @@ -0,0 +1,30 @@ +addColumn("account_state", "non_cash_money", "int default 0"); + } + + public function down() + { + echo "m161004_062500_alter__table__account_state_add_column_non_cash_money cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index e2038a1..d712bd4 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -4,7 +4,8 @@ namespace frontend\controllers; use common\components\DateUtil; use frontend\models\AccountstateSearchToday; -use Yii; +use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + Yii; use common\models\AccountState; use frontend\models\AccountstateSearch; use yii\web\Controller; @@ -201,7 +202,7 @@ class AccountStateController extends Controller { $total += $cassaOpen->money; $openDate = $cassaOpen->created_at; } - $total += Transfer::readPaid($openDate, date('Y-m-d H:i:s'), \Yii::$app->user->id); + $total += Transfer::readPaidCash($openDate, date('Y-m-d H:i:s'), \Yii::$app->user->id); return $total; } @@ -227,41 +228,7 @@ class AccountStateController extends Controller { throw new NotFoundHttpException ( 'The requested page does not exist.' ); } } - /** - * Creates a new AccountState model. - * If creation is successful, the browser will be redirected to the 'view' page. - * - * @return mixed public function actionCreate() - * { - * $model = new AccountState(); - * - * if ($model->load(Yii::$app->request->post()) && $model->save()) { - * return $this->redirect(['view', 'id' => $model->id_account_state]); - * } else { - * return $this->render('create', [ - * 'model' => $model, - * ]); - * } - * } - */ - /** - * Updates an existing AccountState model. - * If update is successful, the browser will be redirected to the 'view' page. - * - * @param integer $id - * @return mixed public function actionUpdate($id) - * { - * $model = $this->findModel($id); - * - * if ($model->load(Yii::$app->request->post()) && $model->save()) { - * return $this->redirect(['view', 'id' => $model->id_account_state]); - * } else { - * return $this->render('update', [ - * 'model' => $model, - * ]); - * } - * } - */ + /** * Deletes an existing AccountState model. * If deletion is successful, the browser will be redirected to the 'index' page. @@ -321,7 +288,8 @@ class AccountStateController extends Controller { $mpdf->useSubstitutions=false; $mpdf->simpleTables = true; $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); - $mpdf->setFooter('{PAGENO} / {nb}'); + /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + $mpdf->setFooter('{PAGENO} / {nb}'); $stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css $mpdf->WriteHTML($stylesheet,1); @@ -331,10 +299,12 @@ class AccountStateController extends Controller { 'model' => $accountState, 'details' => $details ])); + /** @noinspection SpellCheckingInspection */ $type = $accountState->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras"; $dt= "_letrehozva_".date("Ymd_His"). "_" . $user->username; $fn= $type .$dt.".pdf"; $mpdf->Output($fn, 'D'); + exit(0); } else { @@ -378,6 +348,7 @@ class AccountStateController extends Controller { $mpdf->useSubstitutions=false; $mpdf->simpleTables = true; $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); + /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ $mpdf->setFooter('{PAGENO} / {nb}'); $stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css @@ -391,6 +362,7 @@ class AccountStateController extends Controller { 'model' => $accountState, 'details' => $details ])); + /** @noinspection SpellCheckingInspection */ $type = $accountState->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras"; $dt= "_letrehozva_".date("Ymd_His"). "_" . $user->username; $fn= $type .$dt.".pdf"; From 90c598f8c6c0bf8af1e7961c39d83eaafb04189a Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 21 Oct 2016 20:39:02 +0200 Subject: [PATCH 2/2] add editable account on reception/customer-cart, add towel handling --- backend/models/LogSearch.php | 2 +- backend/models/TransferSearch.php | 9 +- backend/views/common/_customer_tab.php | 2 +- backend/views/transfer/_search.php | 4 +- common/components/TransferPayout.php | 33 +++-- common/models/Card.php | 1 + common/models/CardSearch.php | 17 ++- common/models/Customer.php | 2 + common/models/Log.php | 2 + .../controllers/DetstaConsoleController.php | 5 +- ...ble__customer__add__column_towel_count.php | 29 ++++ frontend/controllers/CustomerController.php | 30 +++- frontend/controllers/LogController.php | 84 +++++++++++ frontend/controllers/TransferController.php | 6 + frontend/models/CustomerCartForm.php | 54 ++++++-- frontend/models/LogSearch.php | 130 ++++++++++++++++++ frontend/models/TowelForm.php | 116 ++++++++++++++++ frontend/views/card/_search.php | 3 + frontend/views/card/index.php | 12 +- frontend/views/common/_customer_tab.php | 3 +- frontend/views/common/_reception_customer.php | 4 + frontend/views/common/_reception_menu.php | 23 ++++ frontend/views/common/_reception_ticket.php | 19 +++ frontend/views/log/_search.php | 50 +++++++ frontend/views/log/index.php | 38 +++++ frontend/views/transfer/customercart.php | 8 +- 26 files changed, 649 insertions(+), 37 deletions(-) create mode 100644 console/migrations/m161017_054129_alter__table__customer__add__column_towel_count.php create mode 100644 frontend/controllers/LogController.php create mode 100644 frontend/models/LogSearch.php create mode 100644 frontend/models/TowelForm.php create mode 100644 frontend/views/log/_search.php create mode 100644 frontend/views/log/index.php diff --git a/backend/models/LogSearch.php b/backend/models/LogSearch.php index 2d5d049..5087cd3 100644 --- a/backend/models/LogSearch.php +++ b/backend/models/LogSearch.php @@ -19,7 +19,7 @@ class LogSearch extends Log public $end; public $timestampStart; public $timestampEnd; - + /** * @inheritdoc */ diff --git a/backend/models/TransferSearch.php b/backend/models/TransferSearch.php index f9de562..a399425 100644 --- a/backend/models/TransferSearch.php +++ b/backend/models/TransferSearch.php @@ -48,7 +48,7 @@ class TransferSearch extends Transfer public function rules() { return [ - [['id_account', 'id_user', 'type', 'status', 'payment_method'], 'integer'], + [['id_account', 'id_user', 'type', 'status', 'payment_method','paid_by'], 'integer'], [['customer_name','output','transfer_name', 'card_number' ], 'safe'], // [[ 'searchObjectName' ], 'string'], // [[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], @@ -189,7 +189,12 @@ class TransferSearch extends Transfer $query->andFilterWhere([ 'or', ['transfer.id_user' => $this->id_user], - ['transfer.paid_by' => $this->id_user], + ]); + } + if (isset($this->paid_by)) { + $query->andFilterWhere([ + 'or', + ['transfer.paid_by' => $this->paid_by], ]); } diff --git a/backend/views/common/_customer_tab.php b/backend/views/common/_customer_tab.php index ed955f8..685b805 100644 --- a/backend/views/common/_customer_tab.php +++ b/backend/views/common/_customer_tab.php @@ -21,7 +21,7 @@ $items = [ [ 'Befizetések', ['ticket/index-customer', 'id' => $customer->id_customer ]], [ 'Kulcsok', ['key/index-customer','id' => $customer->id_customer ]], [ 'Szerződések', ['contract/index-customer', 'id' => $customer->id_customer ]], -// [ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]], +// [ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]], ]; diff --git a/backend/views/transfer/_search.php b/backend/views/transfer/_search.php index e5a41bc..1693ce0 100644 --- a/backend/views/transfer/_search.php +++ b/backend/views/transfer/_search.php @@ -69,7 +69,9 @@ use kartik\widgets\DateTimePicker; field($model, 'card_number')->label("Kártya szám") ?>
-
+ field($model, 'paid_by')->dropDownList( ['' => Yii::t('common/transfer', 'All')] +ArrayHelper::map($users,'id' , 'username') ) + ->label("Fizette")?> +
diff --git a/common/components/TransferPayout.php b/common/components/TransferPayout.php index ad85b99..fde871e 100644 --- a/common/components/TransferPayout.php +++ b/common/components/TransferPayout.php @@ -30,10 +30,11 @@ class TransferPayout extends \yii\base\Object{ /**Ha a fizetési módot meg szeretnél változtatni*/ public $overridePaymentMethod = null; - - - - + + /**Ha a fizetési Kasszát meg szeretné változtatni. + * Fizetési kasszát csak bankártyásra lehet változtatni*/ + public $overrideIdAccount = null; + public function payout(){ @@ -85,15 +86,21 @@ class TransferPayout extends \yii\base\Object{ $transfer->paid_by = $this->idUser; $transfer->status = Transfer::STATUS_PAID; $transfer->paid_at = date('Y-m-d H:i:s' ); - - $account = $transfer->account; - - if ( isset($account )){ - /**Ha a tranzakció eredet kasszája látható típusu, akkor változtathatjuk az atuális kasszára. Különben nem*/ - if ($account->type == Account::TYPE_ALL){ - $transfer->id_account = Account::readDefault(); - } - } + + if ( isset($this->overrideIdAccount) && !empty($this->overrideIdAccount)){ + $transfer->id_account = $this->overrideIdAccount; + }else{ + $account = $transfer->account; + + if ( isset($account )){ + /**Ha a tranzakció eredeti kasszája látható típusú, akkor változtathatjuk az atuális kasszára. Különben nem*/ + if ($account->type == Account::TYPE_ALL){ + $transfer->id_account = Account::readDefault(); + } + } + } + + \Yii::info("fizetési mód: " . $this->overridePaymentMethod); diff --git a/common/models/Card.php b/common/models/Card.php index 7b87adc..7d96b6e 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -16,6 +16,7 @@ use common\components\Helper; * @property string $created_at * @property string $updated_at * @property int flag_out + * @property \common\models\Customer $customer relation */ class Card extends \common\models\BaseFitnessActiveRecord { diff --git a/common/models/CardSearch.php b/common/models/CardSearch.php index f08b026..3636d63 100644 --- a/common/models/CardSearch.php +++ b/common/models/CardSearch.php @@ -16,6 +16,7 @@ class CardSearch extends Card { public $customerName; + public $towel; /** * @inheritdoc */ @@ -23,7 +24,8 @@ class CardSearch extends Card { return [ ['customerName','string','max' =>200], - ['number','string','max' =>200] + ['number','string','max' =>200], + ['towel','integer'] ]; } @@ -40,7 +42,8 @@ class CardSearch extends Card return ArrayHelper::merge(parent::attributeLabels(), [ 'card_number' => 'Kártya szám', - 'customerName' => 'Vendég' + 'customerName' => 'Vendég', + 'towel' => 'Törölköző' ] ); @@ -57,7 +60,7 @@ class CardSearch extends Card { $query = new Query(); - $query->select(['card.id_card as card_id_card', 'card.number as card_number' , 'customer.name as customer_name', 'customer.email as customer_email','customer.phone as customer_phone']); + $query->select(['card.id_card as card_id_card', 'card.number as card_number' , 'customer.name as customer_name', 'customer.email as customer_email','customer.phone as customer_phone','customer.towel_count as towel_count']); $query->from('card'); $query->innerJoin('customer','card.id_card = customer.id_customer_card'); $query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card'); @@ -85,6 +88,10 @@ class CardSearch extends Card 'asc' => ['customer.email' => SORT_ASC ], 'desc' => ['customer.email' => SORT_DESC], ], + 'towel_count' => [ + 'asc' => ['customer.towel_count' => SORT_ASC ], + 'desc' => ['customer.towel_count' => SORT_DESC], + ], ], 'defaultOrder' =>[ 'customer_name' => SORT_ASC, @@ -115,6 +122,10 @@ class CardSearch extends Card ]); } + if ( isset($this->towel) && !empty($this->towel)){ + $query->andWhere(['>','customer.towel_count',0]); + } + $query->andFilterWhere(['like', 'customer.name', $this->customerName]); return $dataProvider; diff --git a/common/models/Customer.php b/common/models/Customer.php index c533445..03c707a 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -29,6 +29,7 @@ use Yii; * @property string $updated_at * @property \common\models\Card card * @property integer status + * @property integer towel_count * @property \common\models\User user * @property mixed bank_account */ @@ -47,6 +48,7 @@ class Customer extends BaseFitnessActiveRecord public $photo_data; + /** * @inheritdoc */ diff --git a/common/models/Log.php b/common/models/Log.php index ba10419..e9f0243 100644 --- a/common/models/Log.php +++ b/common/models/Log.php @@ -51,6 +51,8 @@ class Log extends BaseFitnessActiveRecord public static $TYPE_NEWSLETTER_SEND_END = 160; public static $TYPE_KEY_ASSIGN = 170; public static $TYPE_KEY_UNASSIGN = 180; + public static $TYPE_TOWEL_IN = 190; + public static $TYPE_TOWEL_OUT = 200; /** * @inheritdoc diff --git a/console/controllers/DetstaConsoleController.php b/console/controllers/DetstaConsoleController.php index 1a1ff52..3ae6600 100644 --- a/console/controllers/DetstaConsoleController.php +++ b/console/controllers/DetstaConsoleController.php @@ -99,8 +99,11 @@ class DetstaConsoleController extends Controller $content = $detsta->toString(); - file_put_contents('c:\tmp\detsta.txt', $content); + $fn = 'c:\tmp\detsta.txt'; + file_put_contents($fn , $content); + echo "File saved: " . $fn; + } /** diff --git a/console/migrations/m161017_054129_alter__table__customer__add__column_towel_count.php b/console/migrations/m161017_054129_alter__table__customer__add__column_towel_count.php new file mode 100644 index 0000000..355f490 --- /dev/null +++ b/console/migrations/m161017_054129_alter__table__customer__add__column_towel_count.php @@ -0,0 +1,29 @@ +addColumn("customer", "towel_count", "int default 0"); + } + + public function down() + { + echo "m161017_054129_alter__table__customer__add__column_towel_count cannot be reverted.\n"; + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 19cbcdb..90f081d 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -2,6 +2,7 @@ namespace frontend\controllers; +use frontend\models\TowelForm; use Yii; use common\models\Customer; use frontend\models\ReceptionForm; @@ -35,7 +36,7 @@ class CustomerController extends Controller ], 'access' => [ 'class' => \yii\filters\AccessControl::className(), - 'only' => ['create', 'update','reception','contract'], + 'only' => ['create', 'update','reception','contract','towel'], 'rules' => [ // allow authenticated users [ @@ -91,8 +92,9 @@ class CustomerController extends Controller */ /** * Displays a single Customer model. - * @param integer $id + * @param null $number * @return mixed + * @internal param int $id */ /* public function actionView($id) @@ -102,6 +104,26 @@ class CustomerController extends Controller ]); } */ + + public function actionTowel($number = null) + { + $model = new TowelForm(); + if ($model->load(Yii::$app->request->post()) ) { + if ( $model->save() ){ + if ( $model->direction == 'in'){ + \Yii::$app->session->setFlash ( 'success', 'Törölköző(k) visszaadva!' ); + }else{ + \Yii::$app->session->setFlash ( 'success', 'Törölköző(k) kiadva!' ); + } + }else{ + \Yii::$app->session->setFlash ( 'danger', 'Sikertelen törölköző művelet' ); + } + } + return $this->redirect(['customer/reception', 'number' => $number ]); + + + } + /** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. @@ -216,8 +238,8 @@ class CustomerController extends Controller $model->save(false); } } - - + + // s diff --git a/frontend/controllers/LogController.php b/frontend/controllers/LogController.php new file mode 100644 index 0000000..65487c2 --- /dev/null +++ b/frontend/controllers/LogController.php @@ -0,0 +1,84 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'only' => ['towel'], + 'rules' => [ + // allow authenticated users + [ + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; + } + + /** + * Lists all Log models. + * @param $id_card + * @return mixed + * @throws \Yii\web\NotFoundHttpException + */ + public function actionTowel($id_card) { + $card = Card::findOne ( $id_card ); + + if (! isset ( $card )) + throw new NotFoundHttpException ( 'A bérlet nem található' ); + + $searchModel = new LogSearch (); + $searchModel->card = $card; + $searchModel->customer = $card->customer; + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + + + + /** + * Finds the Log model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * @return Log the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) { + if (($model = Log::findOne ( $id )) !== null) { + return $model; + } else { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + } +} diff --git a/frontend/controllers/TransferController.php b/frontend/controllers/TransferController.php index ffa954d..1a1e985 100644 --- a/frontend/controllers/TransferController.php +++ b/frontend/controllers/TransferController.php @@ -401,6 +401,11 @@ class TransferController extends Controller return $this->redirect(['account/select']); } + $hiddenAccounts = Account::find() + ->andWhere(['type' => Account::TYPE_VALUE_HIDDEN]) + ->andWhere(['status' => Account::STATUS_ACTIVE])->all(); + + $customer = null; $card = Card::findOne($id_card); if ($card != null ) @@ -413,6 +418,7 @@ class TransferController extends Controller $model = new CustomerCartForm(); $model->customer = $customer; + $model->hiddenAccounts = $hiddenAccounts; if ($model->load(Yii::$app->request->post()) && $model->payout()) { return $this->redirect(['customer-cart','id_card' => $model->customer->card->id_card]); } diff --git a/frontend/models/CustomerCartForm.php b/frontend/models/CustomerCartForm.php index 8fa730b..d7d7d2b 100644 --- a/frontend/models/CustomerCartForm.php +++ b/frontend/models/CustomerCartForm.php @@ -20,7 +20,8 @@ class CustomerCartForm extends Model public $money = 0; public $selected = []; public $customer; - + public $hiddenAccounts; + public $id_account; /** * @inheritdoc */ @@ -28,7 +29,7 @@ class CustomerCartForm extends Model { return [ ['selected', 'each', 'rule' => ['integer']], - [['money' ,'payment_method'],'integer'], + [['money' ,'payment_method' ,'id_account' ],'integer'], [['payment_method'],'validatePaymentMethod'], ]; } @@ -44,15 +45,45 @@ class CustomerCartForm extends Model public function validatePaymentMethod( $attribute, $params ){ if ( !empty($this->payment_method)){ -// echo $this->payment_method; $arr = Transfer::paymentMethods(); if ( !array_key_exists($this->payment_method, $arr) ){ $this->addError($attribute, "Érvénytelen fizetési mód"); } } } - - + + public function validateIdAccount( $attribute, $params ){ + if ( !empty($this->id_account)){ + $account = $this->loadAvailableOverrideAccounts($this->id_account); + if ( !isset($account) ){ + $this->addError($attribute, "Érvénytelen kassza"); + } + } + } + + + private function loadAvailableOverrideAccounts($id_account = null){ + $accounts = null; + $query = Account::find(); + + $query->innerJoinWith('userAccountAssignments'); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]); + $query->andWhere(['status' => Account::STATUS_ACTIVE])->all(); + + if ( isset($id_account)){ + $query->andWhere(['account.id_account' => $id_account]); + } + + + $query->orderBy( ['name' => SORT_ASC]); + + + $accounts = $query->all(); + return $accounts; + + + } + public function payout(){ $valid = $this->validate(); @@ -71,6 +102,7 @@ class CustomerCartForm extends Model 'idAccount' => Account::readDefault (), 'cartType' => 'customer', 'overridePaymentMethod' => $this->payment_method, + 'overrideIdAccount' => $this->id_account, 'idCustomer' => $this->customer->id_customer ] ); @@ -82,10 +114,10 @@ class CustomerCartForm extends Model } catch ( Exception $e ) { $transaction->rollback (); - Yii::error ( "faled to save :" . $e->getMessage () ); + Yii::error ( "failed to save :" . $e->getMessage () ); } catch ( \Exception $e ) { $transaction->rollback (); - Yii::error ( "faled to save :" . $e->getMessage () ); + Yii::error ( "failed to save :" . $e->getMessage () ); } return false; @@ -100,7 +132,13 @@ class CustomerCartForm extends Model $item->payment_method = $this->payment_method; } } - + + public function changeAccount($item){ + if ( !empty($this->id_account)){ + $item->id_account = $this->id_account; + } + } + public function run(){ $this->readTransfers(); } diff --git a/frontend/models/LogSearch.php b/frontend/models/LogSearch.php new file mode 100644 index 0000000..e083085 --- /dev/null +++ b/frontend/models/LogSearch.php @@ -0,0 +1,130 @@ +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' ], + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = new Query(); + $query->select([ + 'log.id_log as log_id_log', + 'log.created_at as log_created_at', + 'log.message as log_message', + 'user.username as user_username', + 'customer.name as customer_name', + new Expression("case when log.type = " .Log::$TYPE_TOWEL_IN ." then 'Visszaad' ". + " when log.type = ". Log::$TYPE_TOWEL_OUT . " then 'Bérel' ". + " else '-' end as log_type") + + ]); + $query->from("log"); + $query->leftJoin("user"," user.id = log.id_user"); + $query->leftJoin("customer"," customer.id_customer = log.id_customer"); + + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'sort' =>[ + 'defaultOrder' => [ 'log_created_at' => SORT_DESC], + 'attributes' => Helper::mkYiiSortItems([ + ['log_id_log'], + ['log_created_at'], + ['log_message'], + ['log_app'], + ['log_app'], + ['user_username'], + ['customer_name'], + ['log_type'], + + ]) + + ] + ]); + + $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; + } + + $query->andFilterWhere(['>=', 'log.created_at', $this->timestampStart]); + $query->andFilterWhere(['<', 'log.created_at', $this->timestampEnd]); + + $query->andFilterWhere([ + 'id_log' => $this->id_log, + 'type' => $this->type, + 'id_user' => $this->id_user, + 'id_transfer' => $this->id_transfer, + 'id_money_movement' => $this->id_money_movement, + 'id_ticket' => $this->id_ticket, + 'id_sale' => $this->id_sale, + 'id_customer' => $this->id_customer, + 'id_account' => $this->id_account, + 'id_account_state' => $this->id_account_state, + 'id_key' => $this->id_key, + 'id_product' => $this->id_product, + 'id_door_log' => $this->id_door_log, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['like', 'message', $this->message]) + ->andFilterWhere(['like', 'url', $this->url]) + ->andFilterWhere(['like', 'app', $this->app]); + + + $query->andWhere(['in', 'log.type',[Log::$TYPE_TOWEL_IN,Log::$TYPE_TOWEL_OUT]]); + $query->andWhere([ '=', 'customer.id_customer' , $this->customer->id_customer]); + + return $dataProvider; + } +} diff --git a/frontend/models/TowelForm.php b/frontend/models/TowelForm.php new file mode 100644 index 0000000..d795247 --- /dev/null +++ b/frontend/models/TowelForm.php @@ -0,0 +1,116 @@ + 1, 'max' => 10 ], + [['number','direction'], 'safe' ], + [['count', 'number'], 'required'], + [['number'],'validateCard' ], + + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + ]; + } + + public function validateCard($a,$params){ + + $this->number = Helper::fixAsciiChars( $this->number ); + + $query = Card::find(); + $query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card'); + $query->leftJoin("key", 'key.id_key = card_key_assignment.id_key'); + + $query->andWhere(['or', + ['and',[ 'in','card.number' , [$this->number]],"trim(coalesce(card.number, '')) <>'' " ], + ['and', ['in','card.rfid_key' ,[ $this->number] ],"trim(coalesce(card.rfid_key, '')) <>'' "], + ['and',[ 'in','key.number' , [$this->number]],"trim(coalesce(key.number, '')) <>'' " ], + ['and', ['in','key.rfid_key' ,[ $this->number] ],"trim(coalesce(key.rfid_key, '')) <>'' "] + + ]); + + $this->card = $query->one(); + + if ( $this->card != null ){ + $this->customer = $this->card->customer; + } + + if ( !isset($this->customer)){ + $this->addError($a,"A megadott vendég nem található"); + } + + } + + + + private function updateTowelCount(){ + $count = $this->count; + if ( isset($this->direction) && $this->direction == 'in'){ + $count = $this->customer->towel_count - $count; + $log_type = Log::$TYPE_TOWEL_IN; + }else{ + $count = $this->customer->towel_count + $count; + $log_type = Log::$TYPE_TOWEL_OUT; + } + + $count = max(0, $count ); + + $this->customer->towel_count = $count; + $result = $this->customer->save(false); + if ( $result ){ + Log::log([ + 'type' => $log_type, + 'message' => '' .$this->customer->towel_count, + 'id_customer' => $this->customer->id_customer + ]); + } + return $result; + } + + public function save(){ + if ( $this->validate()){ + return $this->updateTowelCount(); + } + return false; + } + +} diff --git a/frontend/views/card/_search.php b/frontend/views/card/_search.php index f2c5a4c..c5269cd 100644 --- a/frontend/views/card/_search.php +++ b/frontend/views/card/_search.php @@ -27,6 +27,9 @@ use yii\widgets\ActiveForm;
field($model, 'number')->label("Kártya/kulcs szám") ?>
+
+ field($model, 'towel')->dropDownList( ['' => "Mind" , '1' => "Bérel Törölközőt"] ) ?> +
diff --git a/frontend/views/card/index.php b/frontend/views/card/index.php index 1e509ab..49f2c71 100644 --- a/frontend/views/card/index.php +++ b/frontend/views/card/index.php @@ -38,6 +38,10 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'customer_email', 'label' => 'E-mail', ], + [ + 'attribute' => 'towel_count', + 'label' => 'Törölköző (db)', + ], // [ // 'attribute' => 'customer.name', // 'value' => 'customer.name', @@ -45,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title; ['class' => 'yii\grid\ActionColumn', - 'template' => '{ticket} {product} {ticket_history} {keys} {contract}', + 'template' => '{ticket} {product} {ticket_history} {keys} {contract} {towel}', 'buttons' => [ 'ticket' => function ($url, $model, $key) { return Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ]) ; @@ -61,6 +65,9 @@ $this->params['breadcrumbs'][] = $this->title; }, 'contract' => function ($url, $model, $key) { return Html::a('Szerződések', $url, ['class'=> 'btn btn-xs btn-success' ]) ; + }, + 'towel' => function ($url, $model, $key) { + return Html::a('Törölközők', $url, ['class'=> 'btn btn-xs btn-success' ]) ; }, ], 'urlCreator' => function ($action, $model, $key, $index){ @@ -75,6 +82,9 @@ $this->params['breadcrumbs'][] = $this->title; $url = Url::to(['key/index','id_card' => $model['card_id_card']]); }else if ( 'contract' == $action ){ $url = Url::to(['contract/index','id_card' => $model['card_id_card']]); + }else if ( 'towel' == $action ){ + $start = Yii::$app->formatter->asDatetime(strtotime('today UTC')); + $url = Url::to(['log/towel','id_card' => $model['card_id_card'] ,'LogSearch[start]' =>$start ]); } return $url; } diff --git a/frontend/views/common/_customer_tab.php b/frontend/views/common/_customer_tab.php index e45a3c0..b40b0f9 100644 --- a/frontend/views/common/_customer_tab.php +++ b/frontend/views/common/_customer_tab.php @@ -7,7 +7,7 @@ use yii\helpers\Url; $route = \Yii::$app->controller->id .'/'. \Yii::$app->controller->action->id; - +$todayDateTime = Yii::$app->formatter->asDatetime(strtotime('today UTC')); @@ -22,6 +22,7 @@ $items = [ [ 'Szerződések', ['contract/index', 'id_card' => $card->id_card ]], [ 'Kosár', ['transfer/customer-cart', 'id_card' => $card->id_card ]], [ 'Kártya', ['card/info', 'id_card' => $card->id_card ]], + [ 'Törölköző Bérlés', ['log/towel', 'id_card' => $card->id_card , 'LogSearch[start]' => $todayDateTime ]], ]; diff --git a/frontend/views/common/_reception_customer.php b/frontend/views/common/_reception_customer.php index 89eb646..29262a3 100644 --- a/frontend/views/common/_reception_customer.php +++ b/frontend/views/common/_reception_customer.php @@ -36,6 +36,10 @@ if ( $model->isCardWithCustomer() ){ 'label' => 'Telefon', 'value' => $model->customer->phone ], + [ + 'label' => 'Kiadott törölközők', + 'value' => $model->customer->towel_count + ], [ 'label' => 'Kulcsok', 'value' => diff --git a/frontend/views/common/_reception_menu.php b/frontend/views/common/_reception_menu.php index 0c62153..1824bd4 100644 --- a/frontend/views/common/_reception_menu.php +++ b/frontend/views/common/_reception_menu.php @@ -81,5 +81,28 @@ $card = $model->card;
+customer) ) { ?> + ['customer/towel', 'number' => $model->getCardNumber()], + 'method' => 'post', + ]); ?> +
+
+ getCardNumber())?> + "form-control", 'placeholder' =>'Törölköző darab' ,'type' => 'number']) ?> + +
+
+
+
+ 'TowelForm[direction]', 'value' => 'out', 'class' => 'btn btn-primary btn-block']) ?> +
+
+ 'TowelForm[direction]', 'value' => 'in', 'class' => 'btn btn-primary btn-block']) ?> +
+ +
+ + diff --git a/frontend/views/common/_reception_ticket.php b/frontend/views/common/_reception_ticket.php index a468b91..d60a594 100644 --- a/frontend/views/common/_reception_ticket.php +++ b/frontend/views/common/_reception_ticket.php @@ -136,4 +136,23 @@ if ( isset( $model->unpaidTickets ) ) { } +if ( isset($model->customer)){ + + if ( $model->customer->towel_count > 0 ){ + $towelText = "Kiadott törölközők (db):" . $model->customer->towel_count; + $towelClass = "alert alert-danger"; + }else{ + $towelText = "Nincs kiadott törölköző"; + $towelClass = "alert alert-success"; + } + + + echo Html::beginTag("div",['class'=> $towelClass, "role"=>"alert"]); + echo Html::beginTag("strong",[ ]); + echo $towelText; + echo Html::endTag("strong"); + echo Html::endTag("div"); + +} + ?> \ No newline at end of file diff --git a/frontend/views/log/_search.php b/frontend/views/log/_search.php new file mode 100644 index 0000000..4df2290 --- /dev/null +++ b/frontend/views/log/_search.php @@ -0,0 +1,50 @@ + + + diff --git a/frontend/views/log/index.php b/frontend/views/log/index.php new file mode 100644 index 0000000..7243d91 --- /dev/null +++ b/frontend/views/log/index.php @@ -0,0 +1,38 @@ +title = Yii::t('common/log', 'Törölköző bérlés történet'); +$this->params['breadcrumbs'][] = $this->title; +?> + $searchModel->card])?> +
+

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + $dataProvider, + 'columns' => [ + [ + 'attribute' => "log_created_at", + 'label' => "Dátum idő", + ], + [ + 'attribute' => "log_type", + 'label' => "Esemény", + ], + [ + 'attribute' => "log_message", + 'label' => "Db", + ], + [ + 'attribute' => "user_username", + 'label' => "Felhasználó", + ], + ], + ]); ?> +
diff --git a/frontend/views/transfer/customercart.php b/frontend/views/transfer/customercart.php index fd05e47..65f2b1f 100644 --- a/frontend/views/transfer/customercart.php +++ b/frontend/views/transfer/customercart.php @@ -32,7 +32,13 @@ $this->registerJs ( 'new TransferCustomerCart( '. json_encode($options).');' );
-field($model, 'payment_method')->dropDownList( ['' => 'Aktuális'] + Transfer::paymentMethods())->label("Fizetése mód") ?> +field($model, 'payment_method')->dropDownList( ['' => 'Aktuális fizetési mód'] + Transfer::paymentMethods())->label("Fizetése mód") ?> +field($model, 'id_account') + ->dropDownList( ['' => 'Aktuális kassza'] + array_reduce( $model->hiddenAccounts, function( $result, $item ){ + $result[$item->id_account] = $item->name; + return $result; + } ,array()) ) + ->label("Kassza") ?>
Összesen: