Browse Source

Fix the order of Invoices and the Invoice number when adding a new invoice.

Mark Crane 13 years ago
parent
commit
98d7cba044
2 changed files with 12 additions and 11 deletions
  1. 9 6
      invoices/v_invoices.php
  2. 3 5
      invoices/v_invoices_edit.php

+ 9 - 6
invoices/v_invoices.php

@@ -52,7 +52,7 @@ require_once "includes/paging.php";
 
 	echo "<table width='100%' border='0'>\n";
 	echo "	<tr>\n";
-	echo "		<td width='50%' align=\"left\" nowrap=\"nowrap\"><b>Invoice List</b></td>\n";
+	echo "		<td width='50%' align=\"left\" nowrap=\"nowrap\"><b>Invoices</b></td>\n";
 	echo "		<td width='50%' align=\"right\">\n";
 	echo "			<input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'>\n";
 	echo "		</td>\n";
@@ -60,8 +60,7 @@ require_once "includes/paging.php";
 	echo "</table>\n";
 
 	//prepare to page the results
-		$sql = "";
-		$sql .= "SELECT count(*) as num_rows FROM v_invoices ";
+		$sql = "SELECT count(*) as num_rows FROM v_invoices ";
 		$sql .= "LEFT OUTER JOIN v_contacts ";
 		$sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
 		$sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
@@ -89,15 +88,19 @@ require_once "includes/paging.php";
 		$offset = $rows_per_page * $page; 
 
 	//get the contact list
-		$sql = "";
-		$sql .= "SELECT * FROM v_invoices ";
+		$sql = "SELECT * FROM v_invoices ";
 		$sql .= "LEFT OUTER JOIN v_contacts ";
 		$sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
 		$sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
 		if (strlen($contact_uuid) > 0) {
 			$sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
 		}
-		if (strlen($order_by)> 0) { $sql .= "order by v_invoices.$order_by $order "; }
+		if (strlen($order_by) == 0) { 
+			$sql .= "order by v_invoices.invoice_number asc ";
+		}
+		else { 
+			$sql .= "order by v_invoices.$order_by $order ";
+		}
 		$sql .= " limit $rows_per_page offset $offset ";
 		$prep_statement = $db->prepare(check_sql($sql));
 		$prep_statement->execute();

+ 3 - 5
invoices/v_invoices_edit.php

@@ -136,8 +136,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 //pre-populate the form
 	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
 		$invoice_uuid = $_GET["id"];
-		$sql = "";
-		$sql .= "select * from v_invoices ";
+		$sql = "select * from v_invoices ";
 		$sql .= "where domain_uuid = '$domain_uuid' ";
 		$sql .= "and invoice_uuid = '$invoice_uuid' ";
 		$prep_statement = $db->prepare(check_sql($sql));
@@ -159,10 +158,9 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 //get the default invoice number and contact_uuid_from
 	if ($action == "add") {
-		$sql = "";
-		$sql .= "select * from v_invoices ";
+		$sql = "select * from v_invoices ";
 		$sql .= "where domain_uuid = '$domain_uuid' ";
-		$sql .= "order by invoice_uuid desc ";
+		$sql .= "order by invoice_number desc ";
 		$sql .= "limit 1 ";
 		$prep_statement = $db->prepare(check_sql($sql));
 		if ($prep_statement) {