Inovice Items

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Inovice Items

Post by AhmedBR » 2013-10-17 01:18

I am working on an Invoicing table (I used the simple invoicing of Ahmad as a Guide, was really nice to have this as a reference THANK YOU)

Well I ran into this little problem:
The invoice details where showing as IDs instead of the actual data when printing the Invoice (Master Detail printing).

Here is the solution:
Instead of this:

Code: Select all

$id=makeSafe($_POST['SelectedID']);
				$footer="<script>\$('invoiceItems').innerHTML='<br><br><table cellpadding=\"3\" cellspacing=\"0\">";
				$footer.='<tr><td class="TableHeaderPrint">Product</td><td class="TableHeaderPrint">Net Weight</td><td class="TableHeaderPrint">Gross Weight</td><td class="TableHeaderPrint">Carton Number</td></tr>';
				
				$res=sql("select Product, NetWeight, GrossWeight, CartonNumber from Invoice_Details where IDLet='$id' order by ID",$eo);
				while($row=mysql_fetch_row($res)){
					$footer.='<tr>';
					$footer.='<td class="TableBodyPrint">'.$row[0].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[1].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[2].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[3].'</td>';
					$footer.='</tr>';
				}

				$footer.="</table>';";
				$footer.='</script>';
It becomes like this:

Code: Select all

				$id=makeSafe($_POST['SelectedID']);
				$footer="<script>\$('invoiceItems').innerHTML='<br><br><table cellpadding=\"3\" cellspacing=\"0\">";
				$footer.='<tr><td class="TableHeaderPrint">Product</td><td class="TableHeaderPrint">Net Weight</td><td class="TableHeaderPrint">Gross Weight</td><td class="TableHeaderPrint">Carton Number</td></tr>';
				
				$res=sql("select  (Select Product from Products where Products.ProductID = Invoice_Details.Product limit 1) as Product, NetWeight, GrossWeight, CartonNumber from Invoice_Details where IDLet='$id' order by ID",$eo);
				while($row=mysql_fetch_row($res)){
					$footer.='<tr>';
					$footer.='<td class="TableBodyPrint">'.$row[0].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[1].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[2].'</td>';
					$footer.='<td class="TableBodyPrint" align="right">'.$row[3].'</td>';
					$footer.='</tr>';
				}

				$footer.="</table>';";
				$footer.='</script>';
Be careful since this is sub query or query within query and known to be slow, I am going to change it to a join which is a lot faster, but I thought to share it anyway, as in some cases this would be the only easy options.
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Inovice Items

Post by AhmedBR » 2013-10-17 01:19

Just to make it easier the change is in this line only:

Code: Select all

 $res=sql("select  (Select Product from Products where Products.ProductID = Invoice_Details.Product limit 1) as Product, NetWeight, GrossWeight, CartonNumber from Invoice_Details where IDLet='$id' order by ID",$eo);
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

Post Reply