add non cash money display to account state

This commit is contained in:
2016-10-05 07:56:50 +02:00
parent 7975d6ffc9
commit 8585286150
8 changed files with 454 additions and 279 deletions

View File

@@ -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;
}