add collection changes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user