SENDING SUMMARY OF BILL TO USER EMAIL


Check your existing record that you want to use. Design a database table for that and use Gii to create model, search model, views and controllers. Arrange data, add columns and import to database. Make sure it has a column from user table (foreign key) such as user_id.

mailingfeerecord-csv.png

Create a php view file where you will combine html and add parameters in php.

<?php $this->beginBody() ?>
<title>Mailing Fee Bill</title>
 </head>
 <body>

<?php 
 $totalamount = 0;

foreach ($stu as $amt){
 $totalamount += $amt['total'];
 }
 ?>
 
 Dear <?php echo $stu[0]->studentFirstName.' '.$stu[0]->studentLastName.' :'; ?><br/><br/>

Our records indicate that payment in your account is overdue in the amount of <b> PHP <?= $totalamount?> </b>. If the amount has already been paid, please disregard this notice.

<br/><br/><br/>

<?php echo '<table style="padding: 10px;text-align: left; border: 1px solid black;">'; ?>
 <?php foreach ($stu as $student){

 echo '<tr style="border-bottom: 5px solid black;"><td><h4> School Year: '.$student->acadYear.' - '.$student->semester.'</h4><td></tr>';
 
 echo '<tr>
 <td style="padding: 10px;text-align: left;">Date</td>
 <td style="padding: 10px;text-align: left;">Type of Exam</td>
 <td style="padding: 10px;text-align: left;">Inbound</td>
 <td style="padding: 15px;text-align: left;">Outbound</td>
 <td style="padding: 15px;text-align: left;">Total</td>
 </tr>';
 echo '<tr>
 <td style="padding: 10px;text-align: left;">'.$student->date.'</td>';
 echo '<td style="padding: 10px;text-align: left;">'.$student->examType.'</td>';
 echo '<td style="padding: 10px;text-align: left;">'.$student->inbound.'</td>';
 echo '<td style="padding: 10px;text-align: left;">'.$student->outbound.'</td>';
 echo '</tr>
 <tr>
 <td style="padding: 10px;text-align: left;">'.$student->dateFinal.'</td>';
 echo '<td style="padding: 10px;text-align: left;">Final Exam</td>
 <td style="padding: 10px;text-align: left;">'.$student->inboundFinal.'</td>';
 echo '<td style="padding: 10px;text-align: left;">'.$student->outboundFinal.'</td>';
 echo '<td style="padding: 10px;text-align: left;">'.$student->total.'</td>';
 echo '</tr>
 <tr></tr>
 <tr>
 <td style="padding: 10px;text-align: left;"></td>
 <td style="padding: 10px;text-align: left;"></td>
 <td style="padding: 10px;text-align: left;"></td>
 <td style="padding: 10px;text-align: left;"></td>';
 echo '</tr>';

;}
 echo '</table>';
 echo '<br/><br/><h2> TOTAL AMOUNT: PHP '.$totalamount.'</h2>
 <br/>If there is a problem regarding the enclosed bill, please contact us. You may send us an email at osa.system.2018@gmail.com. <br/>
 <br/>Thank you very much!<br/><br/><br/>';
 ?>

<?php $this->endBody() ?> </body> </html> <?php $this->endPage() ?>

Add a send function to the controller. Call the models and use find for specifying conditions. Call Yii mailer and pass the view php path and model you searched.

public function actionSend($id){

$stu = Mailingfeerecord::find()
 ->where(['studentuser_user_id'=>$id, 'status'=>'unpaid'])
 ->all();

$students= User::findOne($id);

Yii::$app->mailer
 ->compose(['html' => '@app/views/mail/mailingfee-bill'], ['stu'=>$stu])
 ->setFrom('osa.system.2018@gmail.com')
 ->setTo($students->email)
 ->setSubject('Mailing Fee Bill from OSA System')
->send();

return $this->goHome();
}

Add this as action column to your $gridcolumn. For now, use a download glyphicon for the send email icon.

[

'class' => 'kartik\grid\ActionColumn',
 'template' => '{send} {view} {update} {delete}',
 'buttons' => [
 'send' => function ($url, $model) {
 return Html::a(
 '<span class="glyphicon glyphicon-arrow-down"></span>',
 ['mailingfeerecord/send', 'id' => $model->studentuser_user_id],
 [
 'title' => 'Send bill as email',
 'data-pjax' => '0',
 'data-confirm' => 'Are you sure you want to send bill to this user?',
 ]);
 }, ], 

],

Here’s a preview of the interface.

summary-by-student-with-send-email-action-column.png

Here’s a screenshot of the email sent to user.

bill-sent-to-user-email

Post a Comment

0 Comments