Advise on Cleaning up data

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Advise on Cleaning up data

Post by AndyGable »

Hi Everyone

I was wondering if someone could help with a puzzle I have

I am thinking about adding a "Clean Receipt" option on my software for when Items are voided during the sale

This is what I have at the moment

|L|1CADBURY'S CREAM EGG 40G                          £0.60 A~
|L|1FARM FRESH LSE BRAEBURN CL1 12                   £2.89 Z~
|L|1** NEXT ITEM HAS BEEN VOIDED **~
|L|1FARM FRESH LSE BRAEBURN CL1 12                  -£2.89 Z~


What I would need to do is remove the Item(s) that was originally placed on the receipt as well as the Voided one

in the above example I would need to remove

|L|1FARM FRESH LSE BRAEBURN CL1 12                   £2.89 Z~
|L|1** NEXT ITEM HAS BEEN VOIDED **~
|L|1FARM FRESH LSE BRAEBURN CL1 12                  -£2.89 Z~


so when the receipt is printed it would show like

|L|1CADBURY'S CREAM EGG 40G                          £0.60 A~


How would I do this? I know i would need to loop though the receipt file but I am not sure how I would remove the lines i need

And yes the voided format will always show the |L|1** NEXT ITEM HAS BEEN VOIDED **~ before the item that is voided.

the following is what could be shown

** Price Override **
** Next Item has been voided **
Qty @ Price (qty sale)
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Advise on Cleaning up data

Post by cogier »

Is the list of products in an array? If so, you can just delete the correct item with Array.Remove()
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Advise on Cleaning up data

Post by AndyGable »

cogier wrote: Monday 4th September 2023 2:43pm Is the list of products in an array? If so, you can just delete the correct item with Array.Remove()
At the moment the receipt data file is created each time an item is scanned.

The file is called recipit.tmp

The system is using the ~ when it reads the file in for printing as a end of line marker

I'm not sure if this is the best way to make the receipt file as the item is still showing on the main screen as being scanned and the. Voided.

I'm always open to way to improve the system.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Advise on Cleaning up data

Post by cogier »

Can you post the program so we can see how you are doing things.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Advise on Cleaning up data

Post by AndyGable »

I can not post the whole program as it's closed source but I can post the code that adds data to the receipt file if that helps.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Advise on Cleaning up data

Post by cogier »

..I can post the code that adds data to the receipt file if that helps.
Yes that would help.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Advise on Cleaning up data

Post by AndyGable »

Basically what happens the System would call FormatRecipitEntery_Single with the product name and value etc in it

FormatRecipitEntery_Single("VALUE ORANGE JUICE","£0.35","A")

Public Sub FormatRecipitEntery_Single(TextToShow As String, PriceToShow As String, VATCode As String)
    Global.SpaceNeeded = (56 - (String.Len(TextToShow) + String.Len(PriceToShow)))

    If Global.VATActive = "Yes" Then
        Global.SpaceNeeded -= 2
        CreateRecipitFile("L", "1", TextToShow & Space(Global.SpaceNeeded) & PriceToShow & " " & VATCode)
    Else
        CreateRecipitFile("L", "1", TextToShow & Space(Global.SpaceNeeded) & PriceToShow)
    End If
End


then once the spacing etc has been calculated the system then called CreateRecipitFile


Public Sub CreateRecipitFile(AligmentType As String, FontType As String, TextToUse As String)
    Dim DataToWrite As String = Null
    
    Select Case AligmentType
        Case "L"
            DataToWrite &= Global.LeftAlignText
        
        Case "C"        
            DataToWrite &= Global.CentreAlignText
        
        Case "R"
            DataToWrite &= Global.RightAlignText
    End Select
    
    Select Case FontType
        Case "1"
            DataToWrite &= Global.NormalFont 
        
        Case "2"
            DataToWrite &= Global.DoubleWidthFont
        
        Case "3"
            DataToWrite &= Global.DoubleHeightFont
        
        Case "4"
            DataToWrite &= Global.DoubleWidthHeightFont

        Case "B1"
            DataToWrite &= Global.BoldNormalFont 
        
        Case "B2"
            DataToWrite &= Global.BoldDoubleWidthFont 
        
        Case "B3"
            DataToWrite &= Global.BoldDoubleHeightFont 
        
        Case "B4"
            DataToWrite &= Global.BoldDoubleWidthHeightFont 
                
        Case "B5"
            DataToWrite &= Global.LargeDoubleWidthHeightFont

    End Select

    DataToWrite &= TextToUse & "~"
    
    If Exist(Global.RecipitFileName) = True Then
        Global.RecipitFile = Open Global.RecipitFileName For Write Append
            Print #Global.RecipitFile, gb.NewLine;
            Print #Global.RecipitFile, DataToWrite;
        Global.RecipitFile.Close
    Else
        Global.RecipitFile = Open Global.RecipitFileName For Write Create
            Print #Global.RecipitFile, DataToWrite;
        Global.RecipitFile.Close
     End If
End


The Void is the same sort of process but it would call FormatRecipitEntery_TwoLines

FormatRecipitEntery_Single("**NEXT ITEM IS VOIDED**|VALUE ORANGE JUICE","-£0.35","A")

Public Sub FormatRecipitEntery_TwoLines(TextToShow As String, PriceToShow As String, VATCode As String)
    Global.LineMessages = Split(TextToShow, "|")
    Global.SpaceNeeded = (56 - (String.Len(Global.LineMessages[1]) + String.Len(PriceToShow)))

    If Global.VATActive = "Yes" Then
        Global.SpaceNeeded -= 2
        CreateRecipitFile("L", "1", Global.LineMessages[0])
        CreateRecipitFile("L", "1", Global.LineMessages[1] & Space(Global.SpaceNeeded) & PriceToShow & " " & VATCode)
    Else
        CreateRecipitFile("L", "1", Global.LineMessages[0])
        CreateRecipitFile("L", "1", Global.LineMessages[1] & Space(Global.SpaceNeeded) & PriceToShow)
    End If
End



If you have a smarter way of doing this then I am more then happy to update the receipt function to work with the new format
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Advise on Cleaning up data

Post by cogier »

Well, that looks quite complicated.

I have looked at till receipts and if there is a credit it is clearly shown and, I think, a record should be kept. Below is a simplified piece of code showing the way I would go about this. Sorry but I have run out of time today to improve it.

' Gambas class file

sTempReceiept As New String[]
fTempValue As Float

Public Sub Form_Open()
  
  StartNewCustomer
  
End

Public Sub StartNewCustomer()
  
  sTempReceiept.Clear
  fTempValue = 0
  
  NewReceipt("CADBURY'S CREAM EGG 40G", 0.60)
  NewReceipt("FARM FRESH LSE BRAEBURN CL1 12", 2.89)
  NewReceipt("* * NEXT ITEM HAS BEEN VOIDED * *")
  NewReceipt("FARM FRESH LSE BRAEBURN CL1 12", -2.89)
  NewReceipt("EndTransaction")
  
End

Public Sub NewReceipt(sItem As String, Optional iValue As Float)
  
  Dim iLoop As Integer
  
  If sItem = "EndTransaction" Then 
    sTempReceiept.Add("Grand Total = " & Format(fTempValue, "$0.00"))
    For iLoop = 0 To sTempReceiept.Max  '' Here you could add the data to your Global.RecipitFileName
      Print sTempReceiept[iLoop]
    Next
  Else
    sTempReceiept.Add(sItem & " " & Format(iValue, "$0.00")) 
    fTempValue += iValue
  End If 
  
End

User avatar
sadams54
Posts: 143
Joined: Monday 9th July 2018 3:43am
Contact:

Re: Advise on Cleaning up data

Post by sadams54 »

I have written a Point of Sale in gambas that is used all the time. They get very complex especially when doing receipts and figuring out pricing. I am lost as to how you are doing things on this but always happy to talk private about how we can do things.
The way I handled this was since the sale is on the screen in a columnview when it is time to print the receipt I just iterate through the columnview and print. All items in the columnview are stored in a mysql database for easy retrieval including remotely. I am assuming that your sale is on the screen when you want to print. My receipt print is relatively simple this way. I may not be giving code but the concept of how to do it may be more simple allowing you to code it easier. My thought is put the original item on the sale, then the voided item would simply have a negative quantity. You can even include a "notation" item with it. Then printing a receipt would be as simple as just step through the list on screen.

cogier has helped me on a few options with my POS so this is the guy you want to listen to. He solves problems I can't.
Post Reply