Я начинающий разработчик PHP. Я использую библиотеку mPDF и пытаюсь написать код, который создаст показ нескольких значений таблицы. Проблема в том, что всегда отображается только первое значение.
Я не могу понять, как это решить. Кто-нибудь приведет меня на правильный путь? Моя логика:
- У меня есть один массив со всеми заказами; для каждого заказа я хотел бы создать PDF.
- Я зацикливаю массив и каждый раз вызываю библиотеку MPDF
Код:
<?php
require_once "clientinvoice.php";
$inNumber = $record['ginvo_client_invoice_no'];
$count = 0;
$index = 0;
foreach ($invoices as $invoice) {
$count+=$invoice['rate_with_vat'];
}
$invAmount = number_format((float)$count, 2, '.', '');
//vendor name generate
if ($_GET['showVendor']==1) {
foreach ($vendorDetails as $vendorDetail) {
if($vendorDetail['id']==$invoice['vendor_id']){
$vendor_name = $vendorDetail['first_name'];
$address_treet = $vendorDetail['address_street'];
$address_city = $vendorDetail['address_city'];
$address_state = $vendorDetail['address_state'];
$address_country =$vendorDetail['address_country'];
$postal_cod = $vendorDetail['address_postalcode'];
}
}
$vendorAddress = $vendor_name .','. $address_treet.','. $address_city.','. $address_state.','. $address_country.','. $postal_cod;
$tdClass = 'vendorDt';
}else {
$vendorAddress = '';
$tdClass = '';
}
//proforma invoice display
if ($proforma_invoice_amount>0&&$record['proforma_invoice_c'] == 'yes') {
$profomaAmount = number_format((float)$proforma_invoice_amount, '2', '.', '');
$resttoPay = $count - $profomaAmount;
$restPay = number_format((float)$resttoPay, '2', '.', '');
$proTrClass = '';
}else {
$proTrClass = 'proformaFooter';
}
if ($record['client_location_c'] == 'germany') {
$thanks = '<p>Thank you for your order';
$footerAddress = '<tr><td colspan="7" style="display:flex;justify-content:space-between;"><div class="manufacture-address"><div class="display-flex" style="text-align:center">
<div class="text-left" style="width:33%">
<p>
<span>Global Guide Services GmbH</span><br>
<span>Münchner Str. 23</span><br>
<span>D-83703 Gmund a. Tegernsee</span><br>
<span>Local Court Munich, HRB 223121</span>
</p>
</div>
<div class="text-center" style="text-align:center;width:33%;position:absolute;bottom:0px;margin-left:60%;margin-top:-12%;">
<p>
<span>Managing Director: Siavash Sartipi</span><br>
<span><i class="fa fa-phone"></i> +49 151 74327305</span><br>
<span><i class="fa fa-print"></i> +49 721 509663197</span><br>
<span>www.global-guide-services.com</span>
</p>
</div>
<div class="text-right" style="text-align:center;width:33%;position:absolute;bottom:0;right:10px;margin-top:-12%;" >
<p>
<span>VAT Nr DE 305563525</span><br>
<span>Tax Nr 139/127/50609</span><br>
<span>IBAN DE41 7001 0080 0697 1208 00</span><br>
<span>BIC/SWIFT PBNKDEFF</span>
</p>
</div>
</div></div></td></tr>';
}else {
$thanks = '<p>Intocmit de: Andreea loana</p><br/>
<div class="cnp"><span>CNP: 2950318151935</span></div>';
$footerAddress = '<tr><td colspan="7" style="text-align:center;"><div class="manufacture-address"><div class="text-center address_Raif" style="text-align:center">
<p>
<span>Account holder: <label>Global Guides Services SRL,</label> Bank:Raiffeisen</span><br>
<span>IBAN RO 92 RZBR 0000 0600 1754 9626 BIC(SWIFT):RZBRROBU</span><br>
<span>VAT: RO34622172</span><br>
</p>
</div></div></td></tr>';
}
//footer address display
$html = '
<html>
<head>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
body {
font-family: Arial, Verdana, Helvetica, sans-serif !important;
font-size: 14px !important;
background: #efefef;
-webkit-print-color-adjust: exact;
width: 960px;
line-height:1 !important;
margin: 0 auto;
}
table.report {
border-collapse: collapse;
width: 100%;
}
.invoice-head h3 {
text-transform: uppercase;
margin-bottom: 0;
font-size: 16px;
word-spacing: -2px;
padding: 5px;
}
p { margin: 0pt; }
// table.items {
// border: 0.1mm solid #000000;
// }
td { vertical-align: top; }
// .items td {
// border-left: 0.1mm solid #000000;
// border-right: 0.1mm solid #000000;
// }
table thead td { background-color: #EEEEEE;
text-align: center;
// border: 0.1mm solid #000000;
font-variant: small-caps;
}
.items td.blanktotal {
background-color: #EEEEEE;
border: 0.1mm solid #000000;
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items td.totals {
text-align: right;
border: 0.1mm solid #000000;
}
.items td.cost {
text-align: "." right;
}
.headerBorder{
border-bottom:3px solid #344d90;
}
.invoice-head {
text-align: center;
position: relative;
}
.invoice-head .invoice_head-bg {
height: 61px;
position: absolute;
z-index: -1;
width: 100%;
background: #d4d2d2;
-webkit-print-color-adjust: exact;
}
.img-gradient {
position: absolute;
right: 39px;
top: 0;
height: 250px;
width: 200px;
z-index: -1;
background: #bdc9ec;
background: -webkit-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: -o-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: -moz-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
-webkit-print-color-adjust: exact;
}
.topRight{
position:absolute;
right:60px;
top:3%;
}
.table-header th, .table-body td, .table-footer td {
padding: .70rem;
vertical-align: top;
border-top: 1px solid #eceeef;
width: 13%;
}
.text-right {
text-align: right;
font-style: initial;
}
.vendorDt{
background-color: rgba(123, 159, 234, 0.26);-webkit-print-color-adjust: exact;
}
.footer{
background: #a9b8e2;-webkit-print-color-adjust: exact;margin-top: -20% !important;margin-bottom: 50% !important;
}
.footer td{
text-transform:uppercase;text-align:right;
}
.proformaFooter{
display:none;
}
.manufacture-address {
text-align: center;
}
.invoice-details {
display: flex;
}
</style>
</head>
<body>
<!--mpdf
<htmlpageheader name="myheader">
<table width="100%" class="report">
<tr>
<td><img src="images/company_logo.png" alt="" style="width:150px"></td>
</tr></table>
<div class="headerBorder"></div>
</htmlpageheader>
<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #344d90; text-align: center; padding-top: 1mm; "> </div>
<table width="100%" class="report">
<tbody>'.$footerAddress.'</tbody>
</table>
</htmlpagefooter>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
<div class="img-gradient"> </div>
<table width="100%" style="font-family: arial;" cellpadding="0">
<tbody>
<tr>
<td colspan="3">
<div class="address-left">
<p><strong>client.invoice@global-guide-services.com</strong></p><br/>
<span>'.$record['client_name'].'</span><br>
<span>'.$record['client_address'].'</span><br>
<span>'.$record['client_address_city'].'</span><br>
<span>'.$record['client_address_state'].', '.$record['client_address_country'].'</span><br>
<span>'.$record['client_address_postalcode'].'</span><br>
<span style="font-weight:bold;margin-top:25px;">'.$clientvatId.'</span>
</div></td>
<td colspan="4" style="text-align:right">
<div class="topRight"><h3>'.$country.'</h3></div>
<div class="address-right">
<p>'.$address.'</p>
<p>
<span><i class="fa fa-phone '.$phone.'"></i>'.$record['recipient_phone_number_c'].'</span><br>
<span><i class="fa fa-print '.$fax.'"></i>'.$record['recipient_fax_number_c'].'</span>
</p>
</div></td>
</tr>
<tr><td colspan="7" style="margin-bottom:2px;"></tr>
</tbody>
<br />
<tbody>
<tr>
<div class="invoice_head-bg" style="background-color:#ccc;height:25px"></div>
<td colspan="7" style="line-height:1.50;margin-top:10% !important;text-align:center;position:relative;-webkit-print-color-adjust: exact;background-color:#ccc;">
<div class="invoice-head">
<h3 style="text-transform: uppercase;margin-bottom:0;font-size:13px;word-spacing:-2px;padding:5px;">'.$invoice_title.'</h3>
<p style="margin-top: 25px;font-size: 14px;word-spacing: 4px;">for the assignment of guided tours, assistances, tour escorts, transfers</p>
</div>
</td>
</tr>
<br />
<tr>
<td colspan="7" style="display: flex;line-height:1.75;">
<div class="invoice-details">
<div class="invoice-number">
<p><strong>Invoice number :</strong> <span>'.$record['ginvo_client_invoice_no'].'</span></p>
<p><strong>Invoice date :</strong> <span>'.$inv_date.'</span></p>
</div>
<div class="invoice-info" style="position:absolute;right:7%;top:31%;">
<span>(please invoice number and date with your payment)</span>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<br />
<table class="items" width="100%" style="" cellpadding="8" cellspacing="0">
<thead>
<tr style="background: #7d93ce;">
<th>Group Id</th>
<th>Date</th>
<th>City</th>
<th>Service</th>
<th>Duration</th>
<th>Note</th>
<th>Rate €</th>
</tr>
</thead>
<tbody>
<tr>
<td>'.$invoice['group_id'].'</td>
<td>'.$invoice['service_date'].'</td>
<td>'.$invoice['city'].'</td>
<td>'.$invoice['service'].'</td>
<td>'.$invoice['duration'].'</td>
<td>'.$invoice['notes'].'</td>
<td class="cost">€ '.$invoice['rate_with_vat'].'</td>
</tr>
<tr class='.$tdClass.'>
<td colspan="7" style="text-align:center">'.$vendorAddress.'</td>
</tr>
<!-- END ITEMS HERE -->
<tr class="footer">
<td class="text-right" colspan="6"><strong>Total Sum</strong></td>
<td class="text-right"><b>€ '.$invAmount.'</b></td>
</tr>
<div class="'.$proTrClass.'">
<tr class="footer">
<td class="text-right" colspan="6"><strong>Paid with Proforma</strong></td>
<td class="text-right"><b>€ '.$profomaAmount.'</b></td>
</tr>
<tr class="footer">
<td class="text-right" colspan="6"><strong>Rest to Pay</strong></td>
<td class="text-right"><b>€ '.$restPay.'</b></td>
</tr>
</div>
</tbody>
<tbody>
<tr>
<td colspan="7" style="text-align:right">
<div class="vat text-right">
<span>'.$reverse.'</span>
</div>
</td>
</tr>
<tr>
<td colspan="7">
<div class="invoice-include">
<p>'.$content.'</p>
</div>
</td>
</tr>
<tr>
<td colspan="7">
<div class="invoice-dueDate"><p>Our invoice falls due immediately and is to be paid in full within</p>
<div class="date"><span style="margin: 15px 40px;position:relative;right:10px;">'.$due_date.'</span></div>
</div>
</td>
</tr>
<tr>
<td colspan="7">
<div class="thanks">'.$thanks.'</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
';
//==============================================================
//==============================================================
//==============================================================
//==============================================================
//==============================================================
//==============================================================
define('_MPDF_PATH','../custom/mpdf/');
include("../custom/mpdf/mpdf.php");
$mpdf=new mPDF('c','A4','','',10,10,29,35,10,5);
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle($inNumber);
$mpdf->SetAuthor("Venkatesh");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output($inNumber.'.pdf', 'I'); exit;
exit;
?>