add collection changes

This commit is contained in:
2015-11-04 08:59:20 +01:00
parent 931b83040b
commit ed9c1e77cd
12 changed files with 210 additions and 326 deletions

View File

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