Fotter location not always corect on report printout.

Post

Posted
Rating:
#1 (In Topic #1571)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
hi Everyone,

As I am running a lot of text based reports on my system I have come up with a way to create the reports myself (I am always open to how to do reports quicker if that means using the report.2 with in gambas then sure but someone will have to show me a example of how it works)

below is the full code from my "Current System Stock Price Report - **Active Product Only**" Report

Code (gambas)

  1.                    Public BOPrinterWidth As Integer = 118
  2.        Public ReportNumberOfLinesPerPage As Integer = 74
  3.        Public ReportNumberOfLineAvaliabe As Integer = 0
  4.           Public ReportNumberOflinesUsed As Integer = 0
  5.                  Public ReportPageNumber As Integer = 1
  6.  
  7. ' Gambas module file
  8.  
  9.             ReportName As String = "Current System Stock Price Report - **Active Product Only**"
  10.         DisplayMessage As String = Null
  11.     Const FooterHeight As Integer = 2
  12.  
  13. Public Sub CurrentSystemPriceReport_Process(ReportType As String, UseStockControl As Integer)
  14.     DisplayMessage &= "Processing Current Product Pricing" & gb.crlf
  15.     DisplayMessage &= "for STOCK CONTROLED ENABLED Products" & gb.crlf
  16.     DisplayMessage &= "only" & gb.crlf
  17.     DisplayMessage &= gb.crlf
  18.     DisplayMessage &= "Please wait..."
  19.    
  20.     frmProcesingRequest.labSystemMessage.Text = DisplayMessage
  21.     frmbackground.Workspace1.Add(frmProcesingRequest, 0)            
  22.     Wait 0.01          
  23.  
  24.  
  25. ReportNumberOfLineAvaliabe = ReportNumberOfLinesPerPage - 4
  26.  
  27.     ReportPageNumber = 1
  28.     ProcessReport_CurrentStock(ReportType, UseStockControl)
  29.  
  30. Private Sub ProcessReport_CurrentStock(ReportType As String, UseStockControl As Integer)
  31.     Dim SalelocationNumbers As New String[9999]
  32.  
  33.     BackOfficeReportModule.SetReportHeader(Global.ReportSiteName, "Printed On " & Format(Now, "ddddd d mmmm yyyy"), ReportName, 1)
  34.  
  35.     'get all the Sale locations into memory so they can be looped through
  36.     GetSaleLocations()
  37.  
  38.     Global.BODataResult = Global.$DBBackOfficeCon.Exec(Global.BackOfficeQuery)  
  39.    
  40.     If Global.BODataResult.Count > 0 Then
  41.         Global.RowCount = 0
  42.        
  43.         For Each Global.BODataResult
  44.             SalelocationNumbers[Global.RowCount] = Global.BODataResult!deptnumber & "|" & Global.BODataResult!deptname
  45.             Global.RowCount += 1
  46.         Next
  47.  
  48.         GetDataFromDatabase(SalelocationNumbers, UseStockControl)
  49.     End If
  50.  
  51.     BackOfficeReportModule.PrintReportFunction(ReportType, ReportName)
  52.  
  53. Private Sub GetDataFromDatabase(SalelocationNumbers As String[], UseStockControl As Integer)
  54.     Dim SQLCommandLocal As String = Null
  55.     Dim LocalRow As Integer = 0
  56.  
  57.     For LocalRow = 0 To GetSaleLocationsCount()
  58.         If SalelocationNumbers[LocalRow] <> "" Then
  59.             Dim SaleLocationID As String[] = Split(SalelocationNumbers[LocalRow], "|")
  60.  
  61.             SQLCommandLocal = Null
  62.             SQLCommandLocal &= "Select "
  63.             SQLCommandLocal &= "barcodenumber, "
  64.             SQLCommandLocal &= "UPPER(posdescription) as posdescription, "
  65.             SQLCommandLocal &= "LPAD(salelocation, 4, '0') as salelocation, "
  66.             SQLCommandLocal &= "concat('£', format(retailprice,2)) as retailprice "
  67.             SQLCommandLocal &= "from producttable "
  68.            
  69.             Select Case UseStockControl
  70.                 Case 0 ' No Stock
  71.                     SQLCommandLocal &= "where salelocation='" & Format(Val(SaleLocationID[0]), "0000") & "' "
  72.                
  73.                 Case 1 ' Stock
  74.                     SQLCommandLocal &= "where salelocation='" & Format(Val(SaleLocationID[0]), "0000") & "' AND stockcontrolyn='1' "            
  75.             End Select
  76.  
  77.             SQLCommandLocal &= "AND itemstatus ='1' "
  78.             SQLCommandLocal &= "ORDER BY barcodenumber ASC;"
  79.                
  80.             Global.BODataResult = Global.$DBBackOfficeCon.Exec(SQLCommandLocal)
  81.  
  82.             If Global.BODataResult.Count > 0 Then
  83.                 PrintDepartmentHeader(Format(Val(SaleLocationID[0]), "0000"), SaleLocationID[1])                
  84.                 For Each Global.BODataResult
  85.                     Dim SysID As String = Trim(Global.BODataResult!barcodenumber)
  86.                     Dim PoSDe As String = Mid(Trim(Global.BODataResult!posdescription), 1, 34)
  87.                     Dim StkLe As String = Null
  88.                        
  89.                     If Global.BODataResult!retailprice = "£0.00" Then
  90.                         StkLe = "OPEN"
  91.                     Else
  92.                         StkLe = Global.BODataResult!retailprice    
  93.                     End If                    
  94.                
  95.                     Select Case .ReportNumberOflinesUsed
  96.                         Case To .ReportNumberOfLineAvaliabe
  97.                             PrintDeptProducts(SysID, PoSDe, StkLe)
  98.                             .ReportNumberOflinesUsed += 1
  99.                         Case Else
  100.                             'reset the line count - start a new page
  101.                             PadToEndOfPage ' * UPDATED: Pad lines before footer
  102.                             BackOfficeReportModule.SetReportFooter(frmbackground.labUserName.Caption, "Page " & .ReportPageNumber)
  103.  
  104.                             .ReportNumberOflinesUsed = 0
  105.  
  106.                             BackOfficeReportModule.SetReportHeader(Global.ReportSiteName, "Printed On " & Format(Now, "ddddd d mmmm yyyy"), ReportName, 0)
  107.                             PrintDepartmentHeader(Format(Val(SaleLocationID[0]), "0000"), SaleLocationID[1])
  108.                             .ReportPageNumber += 1
  109.                             PrintDeptProducts(SysID, PoSDe, StkLe)
  110.                             .ReportNumberOflinesUsed += 1
  111.                     End Select
  112.                 Next                    
  113.                 .BackOfficeReportData &= "~"
  114.             End If
  115.         End If
  116.     Next
  117.    
  118.     PadToEndOfPage ' * UPDATED: Pad remaining lines before final footer
  119.     BackOfficeReportModule.SetReportFooter(frmbackground.labUserName.Caption, "Page " & .ReportPageNumber)
  120.  
  121. Private Sub PrintDepartmentHeader(DeptNumber As String, DeptName As String)
  122.     Dim ReportHeader As String = DeptNumber & " " & DeptName
  123.  
  124.     .BackOfficeReportData &= ReportHeader & "~"
  125.     .BackOfficeReportData &= String(.BOPrinterWidth, "-") & "~"
  126.     PrintDeptProducts("PRODUCT", "POS", "SYSTEM")
  127.     PrintDeptProducts("BARCODE", "DESCRIPTION", "PRICE")
  128.     .BackOfficeReportData &= String(.BOPrinterWidth, "-") & "~"
  129.     .ReportNumberOflinesUsed += 5
  130.  
  131. Private Sub PrintDeptProducts(SystemID As String, PoSDescription As String, SystemPrice As String)
  132.     .BackOfficeReportData &= String.PadRight(SystemID, 20, " ")
  133.     .BackOfficeReportData &= string.PadRight(PoSDescription, 80, " ")
  134.  
  135.     Dim ChrSpace As Integer = (.BOPrinterWidth - 20 - 80)
  136.     Dim SpaceNeeded As Integer = (ChrSpace - SystemPrice.Len)    
  137.    
  138.     .BackOfficeReportData &= Space(SpaceNeeded) & SystemPrice & "~"
  139.  
  140.     frmProcesingRequest.labSystemMessage2.Caption = SystemID & " " & PoSDescription
  141.     frmProcesingRequest.Refresh
  142.     Wait 0.001
  143.  
  144. Private Sub GetSaleLocations()
  145.     Global.BackOfficeQuery = Null
  146.     Global.BackOfficeQuery &= "Select "
  147.     Global.BackOfficeQuery &= "deptnumber, "
  148.     Global.BackOfficeQuery &= "UPPER(deptname) as deptname "
  149.     Global.BackOfficeQuery &= "from salelocationtable "
  150.     Global.BackOfficeQuery &= "order by deptnumber ASC;"
  151.  
  152. Private Function GetSaleLocationsCount() As Integer
  153.     Global.BackOfficeQuery = Null
  154.     Global.BackOfficeQuery &= "Select "
  155.     Global.BackOfficeQuery &= "deptnumber, "
  156.     Global.BackOfficeQuery &= "UPPER(deptname) as deptname "
  157.     Global.BackOfficeQuery &= "from salelocationtable "
  158.     Global.BackOfficeQuery &= "order by deptnumber ASC;"
  159.     Global.BODataResult = Global.$DBBackOfficeCon.Exec(Global.BackOfficeQuery)
  160.     Return (Global.BODataResult.Count - 1)
  161.  
  162.  
  163. Private Sub PadToEndOfPage()
  164.    While .ReportNumberOflinesUsed < (.ReportNumberOfLinesPerPage - FooterHeight)
  165.     .BackOfficeReportData &= "~"
  166.     .ReportNumberOflinesUsed += 1
  167.   Wend
  168.  
  169.  

This is the output from the above code https://algpos.co.uk/pdf/ReportV2_noformating.pdf

the Footer is not always being aligned at the bottom of the page

I would like the reports to look like this https://algpos.co.uk/pdf/ReportV2.pdf

I have been looking at this all week and I am hoping a fresh set of eyes can see where I have gone wrong. and Show me what I am missing (as I am sure it is Something VERY simple that I am overlooking)

Kind Regards to all who help me

Andrew
Online now: No Back to the top

Post

Posted
Rating:
#2
Trainee
 Hi

In your routine, PadToEndOfPage() dont  you have to compare with ReportNumberOfLineAvaliabe .

Regards
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

gbAmainie said

Hi
In your routine, PadToEndOfPage() dont  you have to compare with ReportNumberOfLineAvaliabe .
Regards

I'm not sure to be honest I have gotten myself into a right mix up

Here are my basics I started with

I can get 79 lines in total on the A4 page

my header always uses 5 lines (the one with the store name and report type on it) and the footer always uses 2 line.

so in my mind I have 72 lines i can use for the report (79 - 5 - 2 = 72)

BUT i would love to have it not cut the items off half way for example

where it would start a new sub header (0001 etc)

I am more then happy to scrap this methold of report generating if someone know how to do a simpler one.
Online now: No Back to the top
1 guest and 0 members have just viewed this.