<?php require_once('../auth/auth.php');require_once('../auth/function.php');require_once('../auth/acid_balance.php');?>
<?php

   $g_acid  = isset($_GET['g_acid'])?$_GET['g_acid']:0;
$inacc= mysqli_query($conn,"SELECT 
  co_name,owner_name,co_phone,co_email,co_address,co_logo,bra.branch_email,bra.b_email_smtp,t.tid,t.dr_acid,t.cr_acid,t.invoice,t.date,t.amount,t.details,t.ttype,a.acid,a.ac_name,a.ac_number,em_acname
  FROM transaction t LEFT JOIN company c ON(t.coid=c.coid)
  LEFT JOIN accounts a ON(a.acid=t.dr_acid)
  LEFT JOIN user u ON(u.uid=t.userid)
  LEFT JOIN em_employee e ON(e.em_id=u.us_em_id)
   LEFT JOIN branch bra ON(bra.brid=t.brid)
  WHERE t.coid='$coid' AND t.tid ='$tid' LIMIT 1") or die(mysqli_error($conn));
$inac= mysqli_fetch_assoc($inacc);

$co_name        = $inac['co_name'];
$owner_name     = $inac['owner_name'];
$co_address     = $inac['co_address'];
$co_phone       = $inac['co_phone'];
$co_email       = $inac['co_email'];
$co_logo        = $inac['co_logo'];

$branch_email       = $inac['branch_email'];
$b_email_smtp        = $inac['b_email_smtp'];

$tid            = $inac['tid'];
$invoice        = $inac['invoice'];
$date           = $inac['date'];
$amount         = $inac['amount'];
$details        = $inac['details'];
$ttype          = $inac['ttype'];
$dr_acid        = $inac['dr_acid'];
$cr_acid        = $inac['cr_acid'];


$acid           = $inac['acid'];
$ac_name        = $inac['ac_name'];
$ac_number      = $inac['ac_number'];


$em_acname      = $inac['em_acname'];
if ($co_logo !="") {
                            $p_picture="data:image/gif;base64,$co_logo";
                        }else{
                        $p_picture="../../dist/img/a.png";
                        }

require('vendor/autoload.php');




$chbll = invbalance($acid,$date,$tid);
                        $pr_due = ($chbll)?$chbll['pr_due']:0;

                           if ($pr_due >= 0) {
                              $pr_due_bal=   money($pr_due,true).' '.'Dr';
                           } else {
                              $pr_due_bal=  money(-$pr_due,true).' '.'Cr';
                           }


 $n_balance = ($pr_due+$amount);
 if ($n_balance >= 0) {
    $last_due_bal=  money($n_balance,true).' '.'Dr';
} else {
    $last_due_bal= money(-$n_balance,true).' '.'Cr';
}



   
             $html=' <style type="text/css">body{ margin:0px;font-style: normal;font-family:SolaimanLipi,Arial, sans-serif;font-style: normal;color:#000;text-decoration:none;} </style><section class="content">
  <div class="row">
    <div class="col-md-12">
      <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
        <div class="card-header" style="padding: 3px 8px;">
          <h3 class="card-title">Money Receipt</h3>
          <div class="card-tools">
            <span id="sdf"></span>
     
            <button type="button" class="btn btn-tool" data-card-widget="remove" data-dismiss="modal">
              <i class="fas fa-times"></i>
            </button>
          </div>
        </div>       
            <div class="card-body p-1" id="m_receipt" style="overflow:hidden;position: relative;">
              <table style="width: 100%;border: 1px solid #afafaf7a;background:#fde7b46b;position: relative;" cellpadding="0" cellspacing="0">
                 <thead>
                    <tr>
                       <th style="width:2%;padding-top:5px;"></th>
                       <th class="text-left" style="width:10%;padding-top:10px;"><img class="profile-user-img img-fluid img-circle" src="'.$p_picture.'" style="width:80px;height:75px;"></th>
                       <th style="width:10%;padding-top:5px;"></th>
                       <th class="text-center" colspan="6" style="padding-top:5px;">
                         <div style="padding-right:5px;">
    

                            <sss style="font-size:18px;font-weight: 600;"> '. $co_name.' </sss><br>
                              <sss> '. $owner_name.'  </sss><br>
                              <sss>'. $co_email.' #  '. $co_phone.' </sss> <br>
                              <sss>'. $co_address.'   </sss><br>
                         </div>
                       </th>
                       <th style="width:2%;padding-top:5px;">
                         <div style="background-color: green;width: 22px;height:90px;"></div>
                       </th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th class="text-center" colspan="8">
                        <sss style="font-size:25px;font-weight: 600;">MONEY RECEIPT<sss>
                       </th>
                    </tr>
                 </thead>
                 <tbody>
                    <tr>
                       <th style="width:2%;"></th>

                       <th colspan="4" style="text-align:left">INVOICE :  '. $invoice.' </th>

                       <th colspan="4" style="text-align:left">DATE : '.date('d-m-Y | h:i:s a', strtotime($date)).'</th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="8" style="padding-top: 10px;border-bottom: 1px dotted;float:left">Received with thanks from : '. $ac_name.'</th>
                       <th style="width:2%;"></th>
                    </tr>
               
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="2" style="padding-top:10px;border-bottom: 1px dotted;">By Cash/Check No : Cash</th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;">Bank : </th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;">Date : </th>
                       <th style="width:2%;"></th>
                    </tr>   
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="5" style="padding-top:10px;border-bottom: 1px dotted;">For the purpose of : '. $details.'</th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;border-bottom: 1px dotted;">Contuct : '. $ac_number.'</th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th colspan="10">&nbsp;</th>
                    </tr>                     
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="border-bottom:1px solid grey;font-size:15px;">Previous Due : </th>
                       <th class="text-right pr-1" style="border-bottom:1px solid grey;font-size:15px;"><dt>
                         '.$pr_due_bal.' 
                              
                              
                           </dt></th>
                       <th colspan="5"></th>
                       <th style="width:2%;"></th>
                    </tr>                   
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="width:15%;border-bottom:1px solid grey;font-size:15px;">Now Payment : </th>
                       <th class="text-right pr-1" style="width:15%;border-bottom:1px solid grey;font-size:15px;"><dt> '.money($amount,true).' '.'Dr' .' </dt></th>
                       <th style="width:1%;"></th>
                       <th class="text-center" style="border-bottom: 1px dotted;"> '.$em_acname.'</th>
                       <th></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="border-bottom: 1px dotted;"></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="width:15%;border-bottom:1px solid grey;font-size:15px;">Current Due : </th>
                       <th class="text-right pr-1" style="width:15%;border-bottom:1px solid grey;font-size:15px;"><dt> '.$last_due_bal.'</dt></th>
                       <th style="width:1%;"></th>
                       <th class="text-center">Received By</th>
                       <th></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" class="text-center">Authorized signature</th>
                       <th style="width:2%;"></th>
                    </tr>                    
                 </tbody>
                 <tfoot>
                    <tr>
                       <th colspan="10">&nbsp;</th>
                    </tr>                                                     
                    <tr>
                       <th colspan="4" style="padding: 5px 15px;background:#17a2b8;color: #fff;"><dt>Powered by: <a href="https://welldiv.com" target="_blank" style="color:#fff;"> Welldiv</a></dt></th>
                       <th colspan="6" class="text-right" style="padding: 5px 15px;background: #ffc107;color: #fff;"><dt>Build your career, discover your creativity</dt></th>
                    </tr>
                 </tfoot>
              </table>
            </div>
           </div>
        </div>
   </div>
</section>


        ';
  





$mpdf=new \Mpdf\Mpdf();
$mpdf->SetHeader('Payment Vouchar| WellDiv |{PAGENO}');



$stylesheet = file_get_contents('../phpmail/media/print.css');
$stylesheet = file_get_contents('../phpmail/media/tempusdominus-bootstrap-4.min.css');
$stylesheet = file_get_contents('../phpmail/media/adminlte.min2167.css');
$stylesheet = file_get_contents('../phpmail/media/custom.css');



 $mpdf->WriteHTML($stylesheet,1);    // The parameter 1 tells that this is css/style only and no body/html/text

$mpdf->SetFooter('Powered By WellDiv ');
$mpdf->SetWatermarkText('WD');
$mpdf->showWatermarkText = true;
$mpdf->SetSubject('My Subject');

$mpdf->WriteHTML($html);
$file='../phpmail/media/'.$invoice.'.pdf';
$mpdf->output($file,'F');











use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';





//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
   // $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = $branch_email;                     //SMTP username
    $mail->Password   = $b_email_smtp;                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('welldivbd@gmail.com', 'Mailer');
    $mail->addAddress($ac_email, $ac_namaaaae);     //Add a recipient
    // $mail->addAddress('ellen@example.com');               //Name is optional
    // $mail->addReplyTo('info@example.com', 'Information');
    // $mail->addCC('cc@example.com');
    // $mail->addBCC('bcc@example.com');

    //Attachments
    $mail->addAttachment($file);         //Add attachments
    // $mail->addAttachment('../phpmail/certificate.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Dear Sir ,  '.$ac_namaaaae;












    $mail->Body    = 'This is blank file';
    $mail->AltBody = 'Powered by: Welldiv
Build your career, discover your creativity';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}





unlink($file);

?>

