Location: PHPKode > projects > QUICKLYWEB > quicklyweb/admin/enterinvoice.php
<?
# Enter invoice displays a form that allows the entry of an invoice, and handles
# the submission
session_start();

require("quicklyweb.php");
require("security/secure.php");

$Now = date("Y-m-d");

beginDocument($lEnterInvoice, $_SESSION['sess_user']);

if (session_is_registered("CustID")){ 
	} else {
//	session_register("CustID");
//	$CustID = $_POST['CustomerID'];
		$_SESSION['CustID'] = $_POST['CustomerID'];

	}

if ($_POST['action'] == "Finished") {
$myarray = $_POST['itemarray'];
//print_r(array_values ($_POST['itemarray']));
	$result = DBQuery("INSERT into Invoices (InvoiceID, CustomerID, DateBilled, Status, Sent) VALUES ('','$_POST[CustomerID]','$Now','Open','No')",$db);
	checkDBerror($db);
	$insertid = mysql_insert_id();
$a = 0;
		$arraycount = count($_POST['itemarray']['Description']);
			while($a < $arraycount) {
				$taxresult = DBquery("SELECT A.Quantity FROM TaxInfo A, Customers B WHERE (A.TaxInfoID = B.TaxID) AND (B.CustomerID = '$_POST[CustomerID]')", $db);
				checkDBError($db);
					while ($config = DBfetch_array($taxresult))
						{
						$tax = ($config["Quantity"]/100) * $myarray['Amount'][$a];
						$Taxes = sprintf("%.2f", $tax);
					}
	//				echo $Taxes;
	/*				if ($Taxes == "") {
					} else {
						$Taxes='0';
					}
	*/
				$description = $myarray['Description'][$a];
				$amount = $myarray['Amount'][$a];
				$result = DBQuery("INSERT into InvoiceItems VALUES ('','$insertid','$description','$amount','$Taxes')",$db);
			$a++;
			}

	PostDBReport($result, $lInvoiceUpdate, 'showprofile.php', "CustomerID", "$_POST[CustomerID]", 'Customer '.$_POST["CustomerID"], $db);
	die;
}

if ($_POST['action'] == "additem") {
	$db = getDBConnection();
	$Amount = str_replace(",", "", trim($_POST['Amount']));
	
	$inv_array .= $_POST['Description'];
	$inv_array .= $_POST['Amount'];
	$inv_array .= $myTaxes;
	$count_inv = count($itemarray);
	
	if ($_POST['ChargeTax'] == 'yes') {
		$taxresult = DBquery("SELECT A.TaxRate FROM Taxes A, Customers B WHERE (A.TaxID = B.TaxID) AND (B.CustomerID = '$_POST[CustomerID]')", $db);
		checkDBError($db);
		while ($config = DBfetch_array($taxresult))
		{
		$tax = $config["TaxRate"] * $Amount;
		$myTaxes = sprintf("%.2f", $tax);
		} 
	} else 	{
			$Taxes='0';
			}
}

	$Now = date("Y-m-d");
	beginPrettyTable("2", "$lEnterInvoice : New");
		printf("<tr><td class='header'><center>$lDescription</center></td>\n");
		printf("<td class='header'><center>$lAmount</center></td>\n");
		printf("<td class='header'><center>$lTaxCharge</center></td>\n");
		printf("<td class='header'><center>$lActions</center></td></tr>\n");

$myarray = $_POST['itemarray'];
$arrcount =	count($_POST['itemarray']['Description']);
				printf("\n<form name='enterinvoice' method='POST' action='$_SERVER[PHP_SELF]'>\n");
				printf("<input type='hidden' name='CustomerID' value='$_POST[CustomerID]'>\n");
$i=0;
		while ($i < $arrcount) {
			if ($myarray['DeleteItem'][$i] == 'yes') {
				$myarray['DeleteItem'][$i] = "";
				} elseif ($myarray['Description'][$i] == "") {
			} else {
 	  			echo "<tr><td><textarea name='itemarray[Description][]' cols='48' rows='5' wrap='physical'>".$myarray['Description'][$i]."</textarea></td>\n";
				echo "<td><input type='text' name='itemarray[Amount][]' value='".$myarray[Amount][$i]."'></td>\n";
				printf("<td><input type='checkbox' name='itemarray[DeleteItem][]' value='yes'> Delete</td></tr>\n");
				}
				$i++;
			}
# Now add a blank row for next Item.
# Creating a multi-dimensional array to hold the data before putting it
# into the DB.

				printf("<tr><td><textarea name='itemarray[Description][]' cols='48' rows='5' wrap='physical'></textarea></td>\n");
	  			printf("<td><input type='text' name='itemarray[Amount][]' value=''></td>\n");
				printf("<td><button type='submit' name='action' value='submit'>Submit</button></td></tr></form>\n");

		
		
		printf("\n<form name='enterinvoice' method='POST' action='$_SERVER[PHP_SELF]'>\n");
		printf("<tr><td colspan='3'><input type='hidden' name='CustomerID' value='$_POST[CustomerID]'>\n");
		$h=0;
$arrcount = count($_POST['itemarray']['Description']);
		while ($h < $arrcount) {
			if ($myarray['DeleteItem'][$i] == 'yes') {
				$myarray['DeleteItem'][$i] = "";
				} elseif ($myarray['Description'][$h] == "") {
			} else {
 	  			echo "<input type='hidden' name='itemarray[Description][]' value='".$myarray['Description'][$h]."'>\n";
				echo "<input type='hidden' name='itemarray[Amount][]' value='".$myarray['Amount'][$h]."'>\n";
				}
				$h++;
			}
		printf("<button type='submit' name='action' value='Finished'>Finished</button></td></tr></form>\n");
		printf("<tr><td colspan='3'>Click finish when your ready to send the invoice</td></tr>\n");
		endPrettyTable();
		endDocument();
?>
Return current item: QUICKLYWEB