add collection changes
This commit is contained in:
@@ -24,6 +24,9 @@ use yii\behaviors\TimestampBehavior;
|
||||
*/
|
||||
class Collection extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
|
||||
const TYPE_RECEPTION = 10;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -86,17 +89,17 @@ class Collection extends \common\models\BaseFitnessActiveRecord
|
||||
/**
|
||||
* @param \common\models\User $user the user
|
||||
* */
|
||||
public static function readLast($user){
|
||||
public static function readLast($user,$types = [Collection::TYPE_RECEPTION]){
|
||||
$result = null;
|
||||
$query = Collection::find();
|
||||
if ( isset($user)){
|
||||
$query->andWhere($user->id);
|
||||
$query->andWhere(['id_user' =>$user->id]);
|
||||
}
|
||||
$query->andFilterWhere([ 'in', 'type' ,$types]);
|
||||
|
||||
$query->orderBy(['end' => SORT_DESC]);
|
||||
|
||||
$query->limit(1);
|
||||
|
||||
$result = $query->one();
|
||||
|
||||
return $result;
|
||||
|
||||
@@ -27,11 +27,41 @@ class CollectionCreate extends \common\models\Collection
|
||||
|
||||
public $lastCollection;
|
||||
public $accounts;
|
||||
public $accountMap;
|
||||
public $account;
|
||||
public $totals;
|
||||
|
||||
|
||||
public $timestampEnd;
|
||||
public $timestampStart;
|
||||
|
||||
|
||||
public function rules(){
|
||||
return [
|
||||
['end','required'],
|
||||
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
|
||||
[[ 'end' ], 'validateEndDate' ]
|
||||
];
|
||||
}
|
||||
|
||||
public function validateEndDate($attribute,$params){
|
||||
if ( isset($this->lastCollection)){
|
||||
if ( strtotime( $this->lastCollection->end ) >= strtotime( $this->timestampEnd ) ){
|
||||
$this->addError($attribute,Yii::t('frontend/collection' ,'End date is invalid') );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function beforeSave($insert){
|
||||
if (parent::beforeSave($insert)) {
|
||||
$this->id_user = Yii::$app->user->id;
|
||||
$this->created_by = Yii::$app->user->id;
|
||||
$paidAt = Transfer::mkPaidAtTotals($this->timestampStart, $this->timestampEnd, $this->user->id, null, $this->account->id_account, $this->accounts, $this->accountMap);
|
||||
$this->money = $paidAt['total'];
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -503,25 +503,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
|
||||
if ( $mode == 'created_at'){
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
self::inInterval($query, 'transfer.created_at', $start, $end);
|
||||
}else if ( $mode == 'paid_at'){
|
||||
$query->andFilterWhere([ '>=', 'transfer.paid_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.paid_at' , $end ] );
|
||||
self::inInterval($query, 'transfer.paid_at' , $start, $end);
|
||||
}else if ( $mode == 'created_at_not_paid'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_NOT_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
self::notPaid($query, 'transfer.paid_at', $start, $end);
|
||||
self::inInterval($query, 'transfer.created_at', $start, $end);
|
||||
}else if ( $mode == 'created_at_paid'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.created_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.created_at' , $end ] );
|
||||
self::inInterval($query, 'transfer.created_at', $start, $end);
|
||||
self::inInterval($query, 'transfer.paid_at', $start, $end);
|
||||
}else if ( $mode == 'paid_at_not_created_at'){
|
||||
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_PAID ] );
|
||||
$query->andFilterWhere([ '>=', 'transfer.paid_at' , $start ] );
|
||||
$query->andFilterWhere([ '<' , 'transfer.paid_at' , $end ] );
|
||||
|
||||
$query->andFilterWhere( ['or', [ '<', 'transfer.created_at' , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , 'transfer.created_at' , $end ] ] );
|
||||
self::inInterval($query, 'transfer.paid_at' , $start, $end);
|
||||
self::notInInterval($query, 'transfer.created_at', $start, $end);
|
||||
}
|
||||
|
||||
$query->groupBy('transfer.id_account');
|
||||
@@ -531,6 +524,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
}
|
||||
|
||||
public static function notInInterval($query ,$field , $start,$end ){
|
||||
$query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ] );
|
||||
}
|
||||
|
||||
public static function notPaid($query ,$field , $start,$end ){
|
||||
$query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ,[ "transfer.status" => Transfer::STATUS_NOT_PAID ] ] );
|
||||
}
|
||||
public static function inInterval($query ,$field , $start,$end ){
|
||||
$query->andFilterWhere([ '>=', $field , $start ] );
|
||||
$query->andFilterWhere([ '<' , $field , $end ] );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user