I need advice on how to implement. I have two objects ReceiptLine and Discount. Cashier scans item and a receiptline object is added. If the added ReceiptLine object have a Discount Id then, it has to lookup in Discount object and issues discount after validation. I have problem in validation. Here is the situation, cashier scans the item as follows
ReceiptLine Objects
line1 ItemId 1835 qty 2 DiscountId 23 line2 ItemId 1515 qty 2 DiscountId 23 line3 ItemId 1835 qty 2 DiscountId 23
Discount Object Id 23
ItemId 1835 Buy 2 ItemId 1515 Buy 1
Issue Discount $1.00
Situations that Code should Handle
Cashier can scan items in any order Items Quantity can be any amount Discount only allowed if it meets Discount object requirements If the purchase goes twice or any multiple times then the discount also goes that many times
I have the following code, and don't have a clue where to go from there
Public Sub GetDiscount(ByVal newReceiptLine As ReceiptLine)
Dim discountId As Integer = newReceiptLine.DiscountId
Dim discountLine As ReceiptLine = Me.Find(Function(l As ReceiptLine) l.DiscountId = discountId)
If discountLine IsNot Nothing AndAlso discountLine.Discount IsNot Nothing Then
newReceiptLine.Discount = discountLine.Discount
Else
newReceiptLine.Discount = New Discount(discountId)
End If
newReceiptLine.Discount.IssueDiscount(Me)
End Sub
Public Sub IssueDiscount(ByVal receiptLines As ReceiptLines)
Dim discountLines As List(Of ReceiptLine) = receiptLines.FindAll(Function(l As ReceiptLine) l.DiscountId = _id)
For Each line As ReceiptLine In discountLines
Dim styleId As Integer = line.StyleId
Dim item As DiscountItem = _discountItems.Find(Function(i As DiscountItem) i.StyleId = styleId)
??????
Next
End Sub