When I try to generate XML file the output give me eror.
[text]
Fatal error: Uncaught exception 'DOMException' with message 'Invalid Character Error' in
C:\xampp\htdocs\invoices\Copyofgeneratorxml.php:17 Stack trace: #0
C:\xampp\htdocs\invoices\Copyofgeneratorxml.php(17): DOMDocument->createAttribute('Brand Name') #1
C:\xampp\htdocs\invoices\Copyofgeneratorxml.php(128): adda() #2 {main} thrown in
C:\xampp\htdocs\invoices\Copyofgeneratorxml.php on line 17
[/text]
this is my code:
Code: Select all
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<?php
function add($doc, $parent, $key, $value)
{
$attr = $parent->appendChild($doc->createAttribute($key));
$attr->appendChild($doc->createTextNode($value));
}
function adda($doc, $parent, $array)
{
foreach ($array as $key=>$value)
{
$attr = $parent->appendChild($doc->createAttribute($key));
$attr->appendChild($doc->createTextNode($value));
}
}
set_time_limit(9600);
//error_reporting(0);
// Includes
include("include/numbertotext.php");
include("include/html_to_doc.inc.php");
include("list.php");
include("config/db.php");
// Variables
$document_id = $_REQUEST['document_id'];
$division = $_REQUEST['division'];
$iss_to = $_REQUEST['iss_to'];
$iss_by = $_REQUEST['iss_by'];
if ($iss_by == "1 bb.txt") { $hotel = "bb"; }
if ($iss_by == "2 aa.txt") { $hotel = "aa"; }
//$iss_to = file_get_contents("issuers/$iss_to");
//$iss_by = file_get_contents("issuers/$iss_by");
//$iss_to = nl2br($iss_to);
//$iss_by = nl2br($iss_by);
$d_iss_to = explode('<br />',"$iss_to");
$d_iss_by = explode('<br />',"$iss_by");
$rep = $_REQUEST['rep'];
$contribution = $_REQUEST['contribution'];
$database = $_REQUEST['database'];
if ($database == 1) { $ibase_host='888'; }
if ($database == 2) { $ibase_host='888'; }
if ($database == 3) { $ibase_host='888'; }
if ($database == 4) { $ibase_host='888'; }
if ($database == 5) { $ibase_host='888b'; }
$type_document = $_REQUEST['type_document'];
if ($type_document == 1) { $type_document="Debit_Invoice" ; }
if ($type_document == 2) { $type_document="CreditInvoice" ; }
$brand_name = $_REQUEST['brand_name'];
if ($brand_name == 1) { $brand_name="***" ; }
if ($brand_name == 2) { $brand_name="*****" ; }
//Functions
insert_db($document_id,$division,$ibase_host,$type_document,$brand_name);
//Get Document Main Values
$query = "SELECT * FROM invoices WHERE doc_num = $document_id";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$main_doc_date = $row['doc_date'];
$arrival = $row['arrival'];
}
function approx( $value, $dec = 2 ) {
$value += 0.0;
$unit = floor( $value * pow( 10, $dec + 1 ) ) / 10;
$round = round( $unit );
return $round / pow( 10, $dec );
}
//ob_start();
$doc = new DOMDocument();
$doc->formatOutput = true;
$invoice = $doc->createElement( "Invoice" );
$doc->appendChild($invoice);
$header = $doc->createElement( "Header" );
$invoice->appendChild($header);
adda($doc, $header, array(
"Ref" => $document_id,
"Type" => $type_document,
"Date" => $main_doc_date,
"Currency" => "EUR",
"TaxIncluded" => "true",
"OnlyArchive" => "false"
));
$supplier = $doc->createElement( "Supplier" );
$invoice->appendChild($supplier);
adda($doc, $supplier, array(
"SupplierID" => "***",
"Company" => "***",
"TaxID" => "***",
"Address" => "***",
"City" => "***",
"ZIP" => "***",
"Country" => "***"
));
$client = $doc->createElement( "Client" );
$invoice->appendChild($client);
adda($doc, $client, array(
"ClientID" => "***",
"Brand Name" => $brand_name,
"TaxID" => "***",
"Address" => "***",
"City" => "***",
"ZIP" => "***",
"Country" => "***"
));
$lineItems = $doc->createElement( "LineItems" );
$invoice->appendChild($lineItems);
$query = "SELECT distinct vaucher_num FROM invoices WHERE doc_num = $document_id";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$select_num = $row['vaucher_num'];
$query4 = "SELECT * FROM invoices WHERE doc_num = '$document_id' AND vaucher_num = '$select_num'";
$result4 = mysql_query($query4) or die('Query failed : ' . mysql_error());
while ($row4 = mysql_fetch_array($result4, MYSQL_ASSOC)) {
$vaucher_num = $row4['vaucher_num'];
$titular_name = $row4['titular_name'];
$departure = $row4['departure'];
$adults = $row4['adult_count'];
$children = $row4['child_count'];
$cf = 0;
$total_cf = 0;
}
$total_adults = $total_adults + $adults;
$total_children = $total_children + $children;
$total_price = 0;
$nights = 0;
$query3 = "SELECT * FROM invoices WHERE doc_num = $document_id AND vaucher_num='$vaucher_num'";
$result3 = mysql_query($query3) or die('Query failed: ' . mysql_error());
while ($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)) {
$qty = $row3['qty'];
$price_c = $row3['price'];
$tot_price = $qty * $price_c;
$total_price = $total_price + $tot_price / $division;
$total_price=number_format($total_price, 2, '.', '');
$t_pr = $t_pr + $total_price;
$nights++;
}
$total_nights = $total_nights + $nights;
$total = 0;
$query1 = "SELECT distinct line_name,qty,price FROM invoices WHERE doc_num = $document_id AND vaucher_num= '$vaucher_num'";
$result1 = mysql_query($query1) or die('Query failed: ' . mysql_error());
while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$line_name = $row1['line_name'];
$price = $row1['price'];
$qty = 0;
$query2 = "SELECT * FROM invoices WHERE doc_num = '$document_id' AND vaucher_num='$vaucher_num' AND line_name='$line_name' AND price = $price";
$result2 = mysql_query($query2) or die('Query failed: ' . mysql_error());
while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) {
$qty = $qty + $row2['qty'];
}
$price = $price / $division;
$price=number_format($price, 2, '.', '');
$total = $qty * $price;
$total = approx($total);
//$total=number_format($total, 2, '.', '');
// 1st Price
$price=number_format($price, 2, '.', '');
$grand_total = $grand_total + $total;
//$grand_total=number_format($grand_total, 2, '.', '');
$item = $doc->createElement( "Item" );
$lineItems->appendChild($item);
adda($doc, $item, array(
"ClientBookingRef" => $vaucher_num,
"Quantity" => $qty,
"UnitPrice" => $price,
"GrossTotal" => $total,
"LineTotal" => $total - $total * ( ( $rep + $contribution ) / 100 )
));
$lineDiscounts = $doc->createElement( "LineDiscounts" );
$item->appendChild($lineDiscounts);
if ($rep > 0)
{
$discount1 = $doc->createElement( "Discount" );
adda($doc, $discount1, array(
"Type" => "REP",
"Rate" => $rep,
"Amount" => $total * ($rep / 100)
));
$lineDiscounts->appendChild($discount1);
}
if ($contribution > 0)
{
$discount2 = $doc->createElement( "Discount" );
adda($doc, $discount2, array(
"Type" => "Contribution",
"Rate" => $contribution,
"Amount" => $total * ($contribution / 100)
));
$lineDiscounts->appendChild($discount2);
}
$LineTaxes = $doc->createElement( "LineTaxes" );
$item->appendChild($LineTaxes);
$Taxes = $doc->createElement ( "Taxes" );
$LineTaxes->appendChild($Taxes);
adda($doc, $Taxes, array (
"Type" => "VAT",
"TaxebleAmount" => "0.00",
"Rate" => "0.00",
"Amount" => "0.00"
));
$serviceData = $doc->createElement( "ServicesData" );
$item->appendChild($serviceData);
$service = $doc->createElement( "Service" );
$serviceData->appendChild($service);
adda($doc, $service, array(
"PaxLeader" => $titular_name,
"PaxNumber" => $adults + $children,
"AdultsNumber" => $adults,
"KidsNumber" => $children,
"BeginDate" => $arrival,
"EndDate" => $departure,
"RoomCategory" => $line_name
));
} }
$totalSummary = $doc->createElement( "TotalSummary" );
$invoice->appendChild($totalSummary);
$_discounts = $grand_total * (( $rep + $contribution ) / 100);
$_subTotal = $grand_total - $_discounts;
$_invoiceTotal = $_subTotal;
adda($doc, $totalSummary, array(
"GrossTotal" => $grand_total,
"Discounts" => $_discounts,
"SubTotal" => $_subTotal,
"Tax" => "0",
"InvoiceTotal" => $_invoiceTotal
));
//$grand_total = $grand_total - $brochure - $rep;
print $doc->saveXML();
?>