add login email sending

This commit is contained in:
2016-01-08 22:49:18 +01:00
parent 0084526094
commit b83d13ad2f
10 changed files with 292 additions and 104 deletions

View File

@@ -14,47 +14,54 @@ use common\components\DailyListing;
class AccountStateMail extends Object {
public $controller;
public $model;
public $user;
public $account;
public $message;
public $details;
public function init(){
$this->user = User::findOne($this->model->id_user);
$this->account = Account::findOne($this->model->id_account);
}
public function sednMail(){
$this->details = null;
$details = null;
if ($this->model ->isTypeClose ()) {
$prev;
if ($this->model ->type == AccountState::TYPE_CLOSE) {
if (isset ( $accountState->prev_state )) {
$prev = AccountState::findOne ( $accountState->prev_state );
if ($this->model->type == AccountState::TYPE_CLOSE) {
if (isset ( $this->model->prev_state )) {
$prev = AccountState::findOne ( $this->model->prev_state );
}
if (isset ( $prev )) {
$this->model ->start_date = $prev->created_at;
}
}
$details = new DailyListing();
$details->loadAccountState ( $this->model );
$details->readTotalEasy ();
$details->readTotalDetailed ();
$details->readTotalMedium ();
}
$this->details = new DailyListing();
$this->details->loadAccountState ( $this->model );
$this->details->readTotalEasy ();
$this->details->readTotalDetailed ();
$this->details->readTotalMedium ();
}
}
public function sednMail(){
$user = User::findOne($this->model->id_user);
$account = Account::findOne($this->model->id_account);
$subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás";
$subject .= " - " . $user->username ." - ". $account->name;
$subject .= " - " . $this->user->username ." - ". $this->account->name;
$mail = \Yii::$app->mailer->compose('account_state', [
$this->message = \Yii::$app->mailer->compose('account_state', [
'model' => $this->model,
'details' => $details
'details' => $this->details
]);
$mail->setFrom('noreplay@fitnessadmin.hu')
$this->attachPdf();
$this->message->setFrom('noreplay@fitnessadmin.hu')
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject($subject )
->send();
@@ -62,6 +69,30 @@ class AccountStateMail extends Object {
}
protected function attachPdf(){
$mpdf=new \mPDF('utf-8', 'A4-L');
$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}');
$stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($this->controller->renderPartial("@common/views/account-state/account_state_pdf", [
'model' => $this->model,
'details' => $this->details
]));
$type = $this->model->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras";
$dt= "_letrehozva_".date("Ymd_His"). "_" . $this->user->username;
$fn= $type .$dt.".pdf";
$content = $mpdf->Output($fn, 'S');
$this->message->attachContent($content, ['fileName' => $fn, 'contentType' => 'application/pdf']);
}
}