haroon.mansha
Registered User.
- Local time
- Tomorrow, 02:44
- Joined
- Jun 6, 2013
- Messages
- 106
Ok I will show photo of Excel file then you can easily understand.
As you see above I want to get purchased and sold are to seperate . As query is union it shows in same column
DATE PURCHASES/SOLD RECEIPT ISSUE
01/01/2014 APPLE STORE 100 0
02/01/2014 DREAMSTORE 100 0
01/02/2014 MR.ABC 0 100
02/02/2014 MR.XYZ 0 100
SELECT DateofReceipt as DateA,purchasesFrom as Purchase_Sold, Receipt, 0 as Issue FROM tblReceipts
UNION
SELECT DateofIssue as DateA,IssuesTo as Purchase_Sold, 0 as Receipt, Issue FROM tblIssues
Check if below pseudocode gives some guidelines :
ThanksCode:SELECT DateofReceipt as DateA,purchasesFrom as Purchase_Sold, Receipt, 0 as Issue FROM tblReceipts UNION SELECT DateofIssue as DateA,IssuesTo as Purchase_Sold, 0 as Receipt, Issue FROM tblIssues
'---------------------------------------------------------------------------------------
' Procedure : QuantityAllocated
' Author : mellon
' Date : 2014-08-10
' Purpose : The purpose of this function is to calculate the Quantity
'of Product Allocated by looking at the count of Product for SalesInv and
'Purchase Batch.
'There are a number of conditions these are identified based on the OP's code
'
'see if there is Product to satisfy the Sale
'1)
' IF SalesInv start >= PurchaseBatchStart AND SRunTot <= PRunTot
' THEN QuantityAllocated = SRun - Sop + 1
'2)
' IF SalesInv start >= PurchaseBatchStart AND SRunTot > PRunTot
' THEN QuantityAllocated = PRun - Sop + 1
'3)
' IF SalesInv start >= PurchaseBatchStart AND SRunTot > PRunTot
' THEN QuantityAllocated = PRun - Sop + 1
'4)
'OTHERWISE QuantityAllocated = 0
' -----------------------------------------------------------------
'This function is called in QryBatchAllocation.
'
'SQL for QryBatchAllocation
'
'SELECT Products.ProductDesc, Sales.SDate, Sales.SInv, Sales.SQty,
'Sales.SPrice, [SRuntot]-[SQty]+1 AS Sopn, Sales.SRunTot,
'QryPurchaseExtended.BatchNo, QryPurchaseExtended.PDate,
'QryPurchaseExtended.PPrice, QryPurchaseExtended.Popn,
'QryPurchaseExtended.PRunTot,
'QuantityAllocated([popn],[pruntot],[sopn],[sruntot]) AS QtyAlloc
'FROM Products INNER JOIN (Sales LEFT JOIN QryPurchaseExtended ON
'Sales.Product = QryPurchaseExtended.Product) ON
'Products.ProductId = Sales.Product
'WHERE (((Sales.SDate) Between [forms]![frmReports]![FDate] And
'[forms]![frmReports]![TDate]) AND
'(([SRuntot]-[SQty]+1) Between [popn] And [pruntot])) OR
'(((Sales.SDate) Between [forms]![frmReports]![FDate] And
'[forms]![frmReports]![TDate]) AND
'((Sales.SRunTot) Between [popn] And [pruntot])) OR
'(((Sales.SDate) Between [forms]![frmReports]![FDate] And
'[forms]![frmReports]![TDate]) AND (([SRuntot]-[SQty]+1)<[popn]) AND
'((Sales.SRunTot)>[pruntot]))
'ORDER BY Products.ProductDesc, Sales.SDate, Sales.SInv,
'QryPurchaseExtended.PDate;
'---------------------------------------------------------------------------------------
'Parameters:
' Pop is the Popn===count of Product in Batch based on Purchase RunningTotal
' PRun is the Product running total in Purchase
' Sop is the Sopn ===count of Product in SInv based on Sales running total
' SRun is the Sales Running Total
'
'
Function QuantityAllocated(Pop As Long, PRun As Long, Sop As Long, SRun As Long) As Long
10 On Error GoTo QuantityAllocated_Error
'see if there is Product to satisfy the Sale
' IF SalesInv start >= PurchaseBatchStart AND SRunTot <= PRunTot
' THEN QuantityAllocated = SRun - Sop + 1
20 If Sop >= Pop And SRun <= PRun Then
30 QuantityAllocated = SRun - Sop + 1
' IF SalesInv start < PurchaseBatchStart AND SRunTot <= PRunTot
' THEN QuantityAllocated = SRun - Pop + 1
40 ElseIf Sop < Pop And SRun <= PRun Then
50 QuantityAllocated = SRun - Pop + 1
' IF SalesInv start >= PurchaseBatchStart AND SRunTot > PRunTot
' THEN QuantityAllocated = PRun - Sop + 1
60 ElseIf Sop >= Pop And SRun > PRun Then
70 QuantityAllocated = PRun - Sop + 1
80 Else
'OTHERWISE QuantityAllocated = 0
90 QuantityAllocated = 0
100 End If
110 On Error GoTo 0
120 Exit Function
QuantityAllocated_Error:
130 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure QuantityAllocated of Module Module1"
End Function
so subtract 125 from 100 and find a difference of -25. Create a sale record of batch 1001 for 100. Move to the next batch record and apply the remaining 25. That leaves a balance of 25 which is then sold by the second sale transaction.Batch no. Quantity. Date.
1001. 100. 01/01/2014
1002. 50. 02/01/2014
Now supposingly sales as follows
Date. Quantity invoice no
05/01/2014. 125 1
10/01/3014. 25. 2
Hi all
There no idea coming to my mind to how to perform me. That is what I need.
Suppose I have purchase table with following data
Batch no. Quantity. Date.
1001. 100. 01/01/2014
1002. 50. 02/01/2014
Now supposingly sales as follows
Date. Quantity invoice no
05/01/2014. 125 1
10/01/3014. 25. 2
Now the batch reports result I need as follows
Sales. Invoice no 1 100. Batch 1001
25. Batch. 1002
Invoice no 2. 25. Batch 1002
Thanks in advance