Jump to content

Recommended Posts

Ok, I wrote this program about a year ago, it worked great for the year until I found out that I had to exclude tax on certain sku numbers...... So now what I am trying to do is figure out how to exclude tax from certain elements in the total and subtotal.

 

I started by adding a field to the sku_codes table in the db called sku_taxable, it is a field that either has a 1 or a 0 in it, 1 for taxable, 0 for not taxable.  so now i'm trying to write a conditional statement but i dont think thats the best course of action to go by.  Any help would be greatly appreciated on how to make this work, becuase i truely lost myself with this script.

 

 

 
<?php
$title = "View Invoice";
include("includes/header.php");
 
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
 
$invoice_number = $_GET['id'];
 
// Select MYSQL Database
mysql_select_db("terra_elegante_operations", $con);
 
// ALL QUERIES FOR CREDIT THAT NEEDS TO BE APPLIED 
 
// Query the deposit
$deposit_query2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-00")
or die(mysql_error());
 
if ($row = mysql_fetch_array($deposit_query2))
{
$deposit = $row['price_each'];
} else {
$deposit = 0;
}
 
// Query the (Senior Citizen Discount - 01-02)
$senior_discount_query_2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-02")
or die(mysql_error());
 
if ($row = mysql_fetch_array($senior_discount_query_2))
{
$senior_discount = $row['price_each'];
} else {
$senior_discount = 0;
}
 
// Query the (Promotional Discount - 03-00)
$promo_discount_query_2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 03-00")
or die(mysql_error());
 
if ($row = mysql_fetch_array($promo_discount_query_2))
{
$promo_discount = $row['price_each'];
} else {
$promo_discount = 0;
}
 
// / END ALL QUERIES FOR CREDIT THAT NEEDS TO BE APPLIED
 
// Query invoice number
$query_client_invoice = mysql_query("SELECT * from client_invoices where invoice_number = $invoice_number");
 
// Assign Variables from client_invoices table.
$row = mysql_fetch_array($query_client_invoice);
$account_number = $row['account_number'];
$invoice_date = $row['invoice_date'];
$invoice_status = $row['invoice_status'];
$due_date = $row['due_date'];
 
 
// Query Client Information
$query_client_information = mysql_query("SELECT * FROM client_information where account_number = $account_number");
 
// Assign Variables from client_information table.
$row = mysql_fetch_array($query_client_information);
$name_first = $row['name_first'];
$name_last = $row['name_last'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zipcode = $row['zipcode'];
$telephone = $row['telephone'];
$telephone_alt = $row['telephone_alt'];
$email = $row['email'];
?>
 
<table border="0" cellspacing="0" cellpadding="0" width="100%" bordercolor="#000000">
  <tr>
    <td><font face="verdana" size="2" color="#000000"><b><?php echo "<a class='bubble_nav' href='edit_invoice.php?id=$invoice_number'>EDIT INVOICE</a>"; ?>  |  <?php echo "<a class='bubble_nav' href='print_invoice.php?id=$invoice_number' target='_blank'>PRINT INVOICE</a>"; ?></b></font></td>
  </tr>
</table>
<!-- Invoice Heading - Account #, Invoice #, Name, Address, Telephone #'s -->
<br />
<table border="0" cellspacing="0" cellpadding="2" width="100%" bordercolor="#000000">
  <tr>
    <td colspan="4" align="left"><font face="verdana" size="3" color="#000000"><b><u>Invoice Date: <?php echo $invoice_date; ?></u></b></font></td>
  </tr>
    <td width="20%"><font face="verdana" size="2" color="#000000">Account Number:</font></td>
    <td width="40%"><font face="verdana" size="2" color="#000000"><?php echo "<a class=\"bubble_nav\" href='show_client.php?id=$account_number'>$account_number</a\>"; ?></font></td>
    <td width="20%"><font face="verdana" size="2" color="#000000">Telephone</font></td>
    <td width="20%"><font face="verdana" size="2" color="#000000"><?php echo $telephone; ?></font></td>
  </tr>
  <tr>
    <td><font face="verdana" size="2" color="#000000">Invoice Number:</font></td>
    <td><font face="verdana" size="2" color="#000000"><?php echo $invoice_number; ?></font></td>
    <td><font face="verdana" size="2" color="#000000">Telephone Alt</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $telephone_alt ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><br /><?php echo $name_last; ?> , <?php echo $name_first; ?></font></td>
    <td align="left" valign="bottom" colspan="2" rowspan="3"><font face="verdana" size="3" color="#000000"><b>Status: <?php echo $invoice_status ?></b><br />Due Date:<?php echo $due_date; ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $address ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $city; ?>, <?php echo $state; ?> <?php echo $zipcode; ?></font></td>
  </tr>
</table>
<!-- / End Invoice Heading -->
 
<!-- Begin Invoice Entries SQL & Table Structure -->
 
<br /><br /><br />
<!-- Out of the while loop / Top of table -->
<table bgcolor="#000000" border="0" cellspacing="1" cellpadding="2" width="100%" bordercolor="#000000">
  <tr bgcolor="#CCCCCC">
    <td align="center" width="5%"><font face="verdana" size="2" color="#000000"><b>QTY</b></font></td>
    <td align="center" width="10%"><font face="verdana" size="2" color="#000000"><b>SKU</b></font></td>
    <td align="center" width="30%"><font face="verdana" size="2" color="#000000"><b>DESCRIPTION</b></font></td>
    <td align="center" width="25%"><font face="verdana" size="2" color="#000000"><b>LOCATION</b></font></td>
    <td align="center"width="15%"><font face="verdana" size="2" color="#000000"><b>EACH</b></font></td>
    <td align="center" width="15%"><font face="verdana" size="2" color="#000000"><b>TOTAL</b></font></td>
  </tr>
<?php
// Query the deposit
$deposit_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($deposit_query))
{
$deposit  = $row['price_each'];
$deposit_location  = $row['location'];
$deposit_description = $row['sku_description'];
$deposit_quantity  = $row['quantity'];
$deposit_sku  = $row['sku'];
 
?>
  <tr bgcolor="#c2f48c">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>$<?php echo $deposit; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>$<?php echo $deposit; ?></b></i></font></td>
  </tr>
<?php
 
}
// Query the Senior Discount
$senior_discount_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 02-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($senior_discount_query))
 
{
$senior_discount  = $row['price_each'];
$senior_discount_location  = $row['location'];
$senior_discount_description = $row['sku_description'];
$senior_discount_quantity  = $row['quantity'];
$senior_discount_sku  = $row['sku'];
 
?>
  <tr bgcolor="#f8ec66">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $senior_discount; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $senior_discount; ?></b></i></font></td>
  </tr>
<?php
}
 
// Query the Promotional Discount
$promo_discount_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 03-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($promo_discount_query))
 
{
$promo_discount  = $row['price_each'];
$promo_discount_location  = $row['location'];
$promo_discount_description = $row['sku_description'];
$promo_discount_quantity  = $row['quantity'];
$promo_discount_sku  = $row['sku'];
 
?>
  <tr bgcolor="#f9c364">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $promo_discount; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $promo_discount; ?></b></i></font></td>
  </tr>
<?php
}
 
 
// Query Invoice records from tables : invoice_entries, sku_codes
$query_invoice_entries = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 01-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 02-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 03-00")
or die(mysql_error());
 
// Math variable assignments
$price_each_subtotal = 0;
 
// Begin While Loop of invoice records
while($row = mysql_fetch_array($query_invoice_entries))
 
{
 
$quantity = $row['quantity'];
$sku_number = $row['sku_number'];
$location = $row['location'];
$price_each = $row['price_each'];
$sku_description = $row['sku_description'];
$sku_taxable = $row['sku_taxable'];
 
 
if ($sku_taxable=1) {$taxable;} else if ($sku_taxable=0) {$not_taxable;}
 
 
 
 
// Math, Number Format Variables
$price_each_subtotal += ($quantity * $price_each);
$price_each_subtotal_self = ($quantity * $price_each);
 
 
 
?>
  <tr bgcolor="#ffffff">
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $quantity; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $sku_number; ?></font></td>
     <td align="left"><font face="verdana" size="1" color="#000000"><?php echo $sku_description; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $location; ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each_subtotal_self,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
   </tr>
<?php 
 } 
 
// Total Mathematics
 
// New Subtotal Math
 
 
 
 
 
// Subtotal Math
$subtotal_no_deposit = ($price_each_subtotal);
 
 
 
// Discounts
$discount_1 = ($subtotal_no_deposit * $senior_discount);
$discount_2 = ($subtotal_no_deposit * $promo_discount);
$senior_discount_extract = ($subtotal_no_deposit - $discount_1);
$promo_discount_extract = ($subtotal_no_deposit - $discount_2);
 
$total_discounts = (($senior_discount_extract + $promo_discount_extract) - $subtotal_no_deposit);
 
// Tax Math
$subtotal_tax = ($total_discounts * 0.07);
$deposit_tax = ($deposit * 0.07);
 
// Identify $tax
$tax = ($subtotal_tax);
 
// Final Total Math
$subtotal = ($total_discounts);
 
$total = ($subtotal + $tax - $deposit);
 
?>
<!-- / End invoice Entries SQL & Table Structure -->
<!-- End table outside of the while loop -->
<!-- Close entry table -->
</table>
<br />
<!-- Open Sub Total, Tax, Total Table -->
<table border="0" align="right" cellspacing="1" cellpadding="3" width="30%" bordercolor="#000000" bgcolor="#000000">
  <tr bgcolor="#ffffff">
    <td width="15%" align="right"><font face="verdana" size="1" color="#000000">SUB TOTAL :</font></td>
    <td width="15%" align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($subtotal,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
  </tr>
  <tr bgcolor="#ffffff">
    <td align="right"><font face="verdana" size="1" color="#000000">TAX :</font></td>
    <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($tax,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
  </tr>
  <tr bgcolor="#ffffff">
    <td align="right"><font face="verdana" size="2" color="#000000"><b>TOTAL DUE :</b></font></td>
    <td align="right"><font face="verdana" size="2" color="#000000"><b>$<?php echo number_format($total,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></b></font></td>
  </tr>
</table>
 
<br /><br /><br /><br />
 
 
<!-- / End Invoice Entries SQL & Table Structure ->
 
<?php
include("includes/footer.php");
?>

You need to have two different subtotal values. One that totals the taxable items, and one that totals the non taxable items. Then to get the final total you just add them together along with the appropriate tax.

// Begin While Loop of invoice records
$taxableSubtotal = $nontaxableSubtotal = 0;
while($row = mysql_fetch_array($query_invoice_entries))
{
$quantity = $row['quantity'];
$sku_number = $row['sku_number'];
$location = $row['location'];
$price_each = $row['price_each'];
$sku_description = $row['sku_description'];
$sku_taxable = $row['sku_taxable'];

$price = $quantity*$price_each;
if ($sku_taxable==1){
$taxableSubtotal = $price;
}
else {
$nontaxableSubtotal = $price;
}

//...
}

$finalTotal = $taxableSubtotal*$taxRate + $nontaxableSubtotal;

I just figured that out and I think I got it working now, least till a new problem with it arises.  here ill show you what I did.

its not as clean as yours though lol.  i gotta really clean the code on this script up, it seems like there is a lot of redundancy on it.

 

 

 
<?php
$title = "View Invoice";
include("includes/header.php");
 
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
 
$invoice_number = $_GET['id'];
 
// Select MYSQL Database
mysql_select_db("terra_elegante_operations", $con);
 
// ALL QUERIES FOR CREDIT THAT NEEDS TO BE APPLIED 
 
// Query the deposit
$deposit_query2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-00")
or die(mysql_error());
 
if ($row = mysql_fetch_array($deposit_query2))
{
$deposit = $row['price_each'];
} else {
$deposit = 0;
}
 
// Query the (Senior Citizen Discount - 01-02)
$senior_discount_query_2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-02")
or die(mysql_error());
 
if ($row = mysql_fetch_array($senior_discount_query_2))
{
$senior_discount = $row['price_each'];
} else {
$senior_discount = 0;
}
 
// Query the (Promotional Discount - 03-00)
$promo_discount_query_2 = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 03-00")
or die(mysql_error());
 
if ($row = mysql_fetch_array($promo_discount_query_2))
{
$promo_discount = $row['price_each'];
} else {
$promo_discount = 0;
}
 
// / END ALL QUERIES FOR CREDIT THAT NEEDS TO BE APPLIED
 
// Query invoice number
$query_client_invoice = mysql_query("SELECT * from client_invoices where invoice_number = $invoice_number");
 
// Assign Variables from client_invoices table.
$row = mysql_fetch_array($query_client_invoice);
$account_number = $row['account_number'];
$invoice_date = $row['invoice_date'];
$invoice_status = $row['invoice_status'];
$due_date = $row['due_date'];
 
 
// Query Client Information
$query_client_information = mysql_query("SELECT * FROM client_information where account_number = $account_number");
 
// Assign Variables from client_information table.
$row = mysql_fetch_array($query_client_information);
$name_first = $row['name_first'];
$name_last = $row['name_last'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zipcode = $row['zipcode'];
$telephone = $row['telephone'];
$telephone_alt = $row['telephone_alt'];
$email = $row['email'];
?>
 
<table border="0" cellspacing="0" cellpadding="0" width="100%" bordercolor="#000000">
  <tr>
    <td><font face="verdana" size="2" color="#000000"><b><?php echo "<a class='bubble_nav' href='edit_invoice.php?id=$invoice_number'>EDIT INVOICE</a>"; ?>  |  <?php echo "<a class='bubble_nav' href='print_invoice.php?id=$invoice_number' target='_blank'>PRINT INVOICE</a>"; ?></b></font></td>
  </tr>
</table>
<!-- Invoice Heading - Account #, Invoice #, Name, Address, Telephone #'s -->
<br />
<table border="0" cellspacing="0" cellpadding="2" width="100%" bordercolor="#000000">
  <tr>
    <td colspan="4" align="left"><font face="verdana" size="3" color="#000000"><b><u>Invoice Date: <?php echo $invoice_date; ?></u></b></font></td>
  </tr>
    <td width="20%"><font face="verdana" size="2" color="#000000">Account Number:</font></td>
    <td width="40%"><font face="verdana" size="2" color="#000000"><?php echo "<a class=\"bubble_nav\" href='show_client.php?id=$account_number'>$account_number</a\>"; ?></font></td>
    <td width="20%"><font face="verdana" size="2" color="#000000">Telephone</font></td>
    <td width="20%"><font face="verdana" size="2" color="#000000"><?php echo $telephone; ?></font></td>
  </tr>
  <tr>
    <td><font face="verdana" size="2" color="#000000">Invoice Number:</font></td>
    <td><font face="verdana" size="2" color="#000000"><?php echo $invoice_number; ?></font></td>
    <td><font face="verdana" size="2" color="#000000">Telephone Alt</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $telephone_alt ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><br /><?php echo $name_last; ?> , <?php echo $name_first; ?></font></td>
    <td align="left" valign="bottom" colspan="2" rowspan="3"><font face="verdana" size="3" color="#000000"><b>Status: <?php echo $invoice_status ?></b><br />Due Date:<?php echo $due_date; ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $address ?></font></td>
  </tr>
  <tr>
    <td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $city; ?>, <?php echo $state; ?> <?php echo $zipcode; ?></font></td>
  </tr>
</table>
<!-- / End Invoice Heading -->
 
<!-- Begin Invoice Entries SQL & Table Structure -->
 
<br /><br /><br />
<!-- Out of the while loop / Top of table -->
<table bgcolor="#000000" border="0" cellspacing="1" cellpadding="2" width="100%" bordercolor="#000000">
  <tr bgcolor="#CCCCCC">
    <td align="center" width="5%"><font face="verdana" size="2" color="#000000"><b>QTY</b></font></td>
    <td align="center" width="10%"><font face="verdana" size="2" color="#000000"><b>SKU</b></font></td>
    <td align="center" width="30%"><font face="verdana" size="2" color="#000000"><b>DESCRIPTION</b></font></td>
    <td align="center" width="25%"><font face="verdana" size="2" color="#000000"><b>LOCATION</b></font></td>
    <td align="center"width="15%"><font face="verdana" size="2" color="#000000"><b>EACH</b></font></td>
    <td align="center" width="15%"><font face="verdana" size="2" color="#000000"><b>TOTAL</b></font></td>
  </tr>
<?php
// Query the deposit
$deposit_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 01-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($deposit_query))
{
$deposit  = $row['price_each'];
$deposit_location  = $row['location'];
$deposit_description = $row['sku_description'];
$deposit_quantity  = $row['quantity'];
$deposit_sku  = $row['sku'];
 
?>
  <tr bgcolor="#c2f48c">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $deposit_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>$<?php echo $deposit; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>$<?php echo $deposit; ?></b></i></font></td>
  </tr>
<?php
 
}
// Query the Senior Discount
$senior_discount_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 02-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($senior_discount_query))
 
{
$senior_discount  = $row['price_each'];
$senior_discount_location  = $row['location'];
$senior_discount_description = $row['sku_description'];
$senior_discount_quantity  = $row['quantity'];
$senior_discount_sku  = $row['sku'];
 
?>
  <tr bgcolor="#f8ec66">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $senior_discount_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $senior_discount; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $senior_discount; ?></b></i></font></td>
  </tr>
<?php
}
 
// Query the Promotional Discount
$promo_discount_query = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku = 03-00")
or die(mysql_error());
 
while($row = mysql_fetch_array($promo_discount_query))
 
{
$promo_discount  = $row['price_each'];
$promo_discount_location  = $row['location'];
$promo_discount_description = $row['sku_description'];
$promo_discount_quantity  = $row['quantity'];
$promo_discount_sku  = $row['sku'];
 
?>
  <tr bgcolor="#f9c364">
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_quantity; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_sku ?></b></i></font></td>
<td><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_description; ?></b></i></font></td>
<td align="center"><font face="verdana" size="1" color="#000000"><i><b><?php echo $promo_discount_location; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $promo_discount; ?></b></i></font></td>
<td align="right"><font face="verdana" size="1" color="#000000"><i><b>%<?php echo $promo_discount; ?></b></i></font></td>
  </tr>
<?php
}
// NEW CODE HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
// Query Invoice records from tables : invoice_entries, sku_codes THAT ARE TAX EXEMPT!
$query_invoice_entries = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 01-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 02-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 03-00 AND sku_codes.sku_taxable = 0")
or die(mysql_error());
 
// Math variable assignments
$price_each_not_taxable_subtotal = 0;
 
// Begin While Loop of invoice records
while($row = mysql_fetch_array($query_invoice_entries))
 
{
 
$quantity = $row['quantity'];
$sku_number = $row['sku_number'];
$location = $row['location'];
$price_each = $row['price_each'];
$sku_description = $row['sku_description'];
$sku_taxable = $row['sku_taxable'];
 
 
 
 
 
// Math, Number Format Variables
$price_each_not_taxable_subtotal += ($quantity * $price_each);
$price_each_not_taxable_subtotal_self = ($quantity * $price_each);
 
 
 
?>
  <tr bgcolor="#ffffff">
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $quantity; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $sku_number; ?></font></td>
     <td align="left"><font face="verdana" size="1" color="#000000"><?php echo $sku_description; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $location; ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each_not_taxable_subtotal_self,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
   </tr>
<?php 
 } 
 
 
 // Query Invoice records from tables : invoice_entries, sku_codes THAT ARE NOT TAX EXEMPT!
$query_invoice_entries = mysql_query("SELECT * FROM invoice_entries, sku_codes WHERE invoice_entries.invoice_number = $invoice_number AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 01-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 02-00 AND invoice_entries.sku_number = sku_codes.sku AND sku_codes.sku != 03-00 AND sku_codes.sku_taxable = 1")
or die(mysql_error());
 
// Math variable assignments
$price_each_subtotal = 0;
 
// Begin While Loop of invoice records
while($row = mysql_fetch_array($query_invoice_entries))
 
{
 
$quantity = $row['quantity'];
$sku_number = $row['sku_number'];
$location = $row['location'];
$price_each = $row['price_each'];
$sku_description = $row['sku_description'];
$sku_taxable = $row['sku_taxable'];
 
 
 
 
 
 
// Math, Number Format Variables
$price_each_subtotal += ($quantity * $price_each);
$price_each_subtotal_self = ($quantity * $price_each);
 
 
 
?>
  <tr bgcolor="#ffffff">
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $quantity; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $sku_number; ?></font></td>
     <td align="left"><font face="verdana" size="1" color="#000000"><?php echo $sku_description; ?></font></td>
     <td align="center"><font face="verdana" size="1" color="#000000"><?php echo $location; ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
     <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($price_each_subtotal_self,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
   </tr>
<?php 
 } 
 
 
 
// Total Mathematics
 
// New Subtotal Math
$non_taxable_subtotal = ($price_each_not_taxable_subtotal);
 
 
 
 
// Subtotal Math
$subtotal_no_deposit = ($price_each_subtotal);
 
 
 
// Discounts
$discount_1 = ($subtotal_no_deposit * $senior_discount);
$discount_2 = ($subtotal_no_deposit * $promo_discount);
$senior_discount_extract = ($subtotal_no_deposit - $discount_1);
$promo_discount_extract = ($subtotal_no_deposit - $discount_2);
 
$total_discounts = (($senior_discount_extract + $promo_discount_extract) - $subtotal_no_deposit);
 
// Tax Math
$subtotal_tax = ($total_discounts * 0.07);
$deposit_tax = ($deposit * 0.07);
 
// Identify $tax
$tax = ($subtotal_tax);
 
// Final Total Math
$subtotal = ($total_discounts + $non_taxable_subtotal);
 
$total = ($subtotal + $tax - $deposit);
 
?>
<!-- / End invoice Entries SQL & Table Structure -->
<!-- End table outside of the while loop -->
<!-- Close entry table -->
</table>
<br />
<!-- Open Sub Total, Tax, Total Table -->
<table border="0" align="right" cellspacing="1" cellpadding="3" width="30%" bordercolor="#000000" bgcolor="#000000">
  <tr bgcolor="#ffffff">
    <td width="15%" align="right"><font face="verdana" size="1" color="#000000">SUB TOTAL :</font></td>
    <td width="15%" align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($subtotal,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
  </tr>
  <tr bgcolor="#ffffff">
    <td align="right"><font face="verdana" size="1" color="#000000">TAX :</font></td>
    <td align="right"><font face="verdana" size="1" color="#000000">$<?php echo number_format($tax,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></font></td>
  </tr>
  <tr bgcolor="#ffffff">
    <td align="right"><font face="verdana" size="2" color="#000000"><b>TOTAL DUE :</b></font></td>
    <td align="right"><font face="verdana" size="2" color="#000000"><b>$<?php echo number_format($total,$decimals = 2, $dec_point = '.', $thousands_sep = ','); ?></b></font></td>
  </tr>
</table>
 
<br /><br /><br /><br />
 
 
<!-- / End Invoice Entries SQL & Table Structure ->
 
<?php
include("includes/footer.php");
?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.