Using dompdf I made a script that will print an invoice for a contractor, this works fine. There are about 10 clients in my database and they each have their own contractors anywhere from 5 to 100. I use contractor_id and client_id as primary keys.

How can I put all the contractors invoice information in an array, create a single file, and then send it to my invoice script?

I have done some research on this and I think I need to use a foreach loop with print_r but I am not sure how to set it up.

Thanks for any help.

My code is below.

<?php
// Get Payroll information
$result = mysql_query("SELECT * FROM PAYROLL WHERE payroll_id = '1' LIMIT 1");
$row = mysql_fetch_array($result) or die(mysql_error());

$today = date("Y/m/d");
$contractor_id = $row['contractor_id'];
$payroll_start_date = $row['payroll_start_date'];
$payroll_end_date = $row['payroll_end_date'];
$hours_worked = $row['hours_worked'];
$hourly_rate = $row['hourly_rate'];
$deductions = $row['deductions'];
$advance = $row['advance'];

$total_hourly = $hours_worked * $hourly_rate;
$sub_total = ($hours_worked * $hourly_rate) + $advance - $deductions;
$kb_fee = $sub_total * .05;
$total_net_pay = round($sub_total -($sub_total * .05), 2);


// Get Contractor Name
$result2 = mysql_query("SELECT first_name, last_name, client_assigned_number FROM CONTRACTORS WHERE contractor_id = '$contractor_id' LIMIT 1");
$row2 = mysql_fetch_array($result2) or die(mysql_error());

$first_name = $row2['first_name'];
$last_name = $row2['last_name'];
$client_assigned_number = $row2['client_assigned_number'];


$html = <<<EOD
<html>
<head>
<style type="text/css">
<!--
table.change_order_items { 
  font-size: 10pt;
  width: 100%;
  border-collapse: collapse;
  margin-top: 2em;
  margin-bottom: 2em;
}

table.change_order_items>tbody { 
  border: 1px solid black;
}

table.change_order_items>tbody>tr>th { 
  border-bottom: 1px solid black;
}

table.change_order_items>tbody>tr>td { 
  border-right: 1px solid black;
  padding: 0.5em;
}

td.change_order_total_col { 
  padding-right: 4pt;
  text-align: right;
}

td.change_order_unit_col { 
  padding-left: 2pt;
  text-align: left;
}


.odd_row td {
  background-color: transparent;
  border-bottom: 0.9px solid 
}

.even_row td {
  background-color: #f6f6f6;
  border-bottom: 0.9px solid #ddd;
}

-->
</style>
</head>


<!--Header-->
<table style="width: 100%;" class="header">
<tr>
<td><h1 style="text-align: right">INVOICE</h1></td>
</tr>
</table>




<!--Name & Date Section-->
<table style="width: 100%;">
<tr>
<td style="text-align: left"><?php echo '$first_name';?> <?php echo '$last_name';?></td><td style="text-align: right">Date: <?php echo '$today';?></td>
</tr>
<tr>
<td style="text-align: left"><?php echo '$client_assigned_number';?></td><td style="text-align: right">Invoice Reference: <?php echo '$row[payroll_start_date]';?> - <?php echo '$row[payroll_end_date]';?></td>
</tr>
</table>





<!--Invoice To Section-->

<table style="width: 100%;">

<tr><td style="text-align: left"><br /></td></tr>
<tr><td style="text-align: left"><strong>Invoice To</strong> <br />Knightsbridge Associates Limited<br />P.O. Box 653<br />Guernsey<br />GY1 3PT<br /></td>

<td style="text-align: right">For Professional Services to:<br />London Parking Control Ltd.<br />BM 2896 <br />London <br />WC1N 3XX<br /></td></tr>
</table>


<!--Item Description Section-->
<table class="change_order_items">

<tr><td colspan="6"><h2>For Professional Services</h2></td></tr>
<tbody>
<tr>
<th>Item</th>
<th>Description</th>
<th>Quantity</th>

<th colspan="2">Rate</th>
<th>Amount</th>
</tr>

<tr class="even_row">
<td style="text-align: center">1</td>
<td>Hours Worked</td>
<td style="text-align: center"><?php echo '$row[hours_worked]';?></td>
<td style="text-align: right; border-right-style: none;">&pound;<?php echo '$row[hourly_rate]';?></td>
<td class="change_order_unit_col" style="border-left-style: none;"></td>

<td class="change_order_total_col">&pound;<?php echo '$total_hourly';?></td>
</tr>



<tr class="odd_row">
<td style="text-align: center"></td>
<td>Pay Advance</td>
<td style="text-align: center"></td>
<td style="text-align: right; border-right-style: none;"></td>
<td class="change_order_unit_col" style="border-left-style: none;"></td>
<td class="change_order_total_col">&pound;<?php echo '$advance';?></td>
</tr>

<tr class="even_row">
<td style="text-align: center"></td>
<td>Deductions</td>
<td style="text-align: center"></td>
<td style="text-align: right; border-right-style: none;"></td>
<td class="change_order_unit_col" style="border-left-style: none;"></td>
<td class="change_order_total_col">&pound;<?php echo '$deductions';?></td>
</tr>


<tr class="odd_row">
<td style="text-align: center"></td>
<td style="text-align: right;">Sub Total</td>
<td style="text-align: center"></td>
<td style="text-align: right; border-right-style: none;"></td>
<td class="change_order_unit_col" style="border-left-style: none;"></td>
<td class="change_order_total_col">&pound;<?php echo '$sub_total';?></td>
</tr>

<tr class="odd_row">
<td style="text-align: center"></td>
<td style="text-align: right;">Less 5% Commission</td>
<td style="text-align: center"></td>
<td style="text-align: right; border-right-style: none;"></td>
<td class="change_order_unit_col" style="border-left-style: none;"></td>
<td class="change_order_total_col">&pound;<?php echo '$kb_fee';?></td>
</tr>


</tbody>




<tr>
<td colspan="3" style="text-align: right;"></td>
<td colspan="2" style="text-align: right;"><strong>GRAND TOTAL:</strong></td>
<td class="change_order_total_col"><strong>&pound;<?php echo '$total_net_pay';?></strong></td></tr>
</table>
<p><strong>THANK YOU FOR YOUR BUSINESS</strong><br />
Please advise us immediately if any of your details change or are wrong at either the above Knightsbridge<br />
Associates address, by email at admin@knightsbridgeassociates.com or by telephone on 01481 740631<br /></p>

<p><strong>PLEASE NOTE:</strong> Knightsbridge Associates are an international invoicing service. The above invoice is for services as a self employed contractor. This invoice should be retained for your refernce and for your accounts as a self employed contractor. Knightsbridge Associates take a 5% commision as a service fee. Please read the terms and conditions for using Knightsbridge Associates Ltd. as your invoicing company.</p></td>
</tr>


</body>
</html>
EOD;

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("Invoice.pdf");

?>
    Write a Reply...