Regarding Invoice Entry, i have make an invoice with 4 items invoice id is 13 Once i select the invoice No 13. without getting any payment part query retrieving exact answer the bellow screen shot and query
Query for the above Table design to retrieve records
SELECT BASE_Invoice.InvoiceId, BASE_Invoice.InvoiceDate, BASE_Invoice.PurchasingOrderNo, (CASE WHEN (BASE_Invoice.CustomerId IS NULL) THEN BASE_Invoice.CustomerId ELSE BASE_Customer.CustomerId END) AS CustomerId, (CASE WHEN (BASE_Invoice.CustomerId IS NULL) THEN BASE_Invoice.CustomerName ELSE BASE_Customer.CustomerName END) AS CustomerName, BASE_Invoice.InvoiceMethod, BASE_Invoice.Note,
BASE_Inventory.ItemNameCode, BASE_Category.CategoryId, BASE_Category.CategoryName, BASE_Inventory.ItemDescription, BASE_Unit.UnitId, BASE_Unit.UnitName, BASE_InvoiceLine.WarrantyDays,
BASE_InvoiceLine.Quantity, BASE_InvoiceLine.CostPrice, BASE_InvoiceLine.SellingPrice, BASE_InvoiceLine.ItemDiscountPercentage, BASE_InvoiceLine.ItemDiscountAmount,
BASE_InvoiceLine.TotalItemDiscount, BASE_InvoiceLine.TotalAmount
FROM BASE_Category RIGHT OUTER JOIN
BASE_Invoice INNER JOIN
BASE_InvoiceLine ON BASE_Invoice.InvoiceId = BASE_InvoiceLine.InvoiceId INNER JOIN
BASE_Inventory ON BASE_InvoiceLine.InventoryId = BASE_Inventory.InventoryId LEFT OUTER JOIN
BASE_Customer ON BASE_Invoice.CustomerId = BASE_Customer.CustomerId ON BASE_Category.CategoryId = BASE_Inventory.CategoryId LEFT OUTER JOIN
BASE_Unit ON BASE_Inventory.UnitId = BASE_Unit.UnitId
WHERE (BASE_Invoice.InvoiceId = 13)
Result:
ISSUE:
When i'm retrieving invoice data with payment details (payment tables such as cash, card, bank deposit and cheque) getting duplicate result from the above..
the bellow screen shot and query
Table structure (Table design):
Query for the above Table design to retrieve records (Issue: duplicate resutlts)
SELECT BASE_Invoice.InvoiceId, BASE_Invoice.InvoiceDate, BASE_Invoice.PurchasingOrderNo, (CASE WHEN (BASE_Invoice.CustomerId IS NULL) THEN BASE_Invoice.CustomerId ELSE BASE_Customer.CustomerId END) AS CustomerId, (CASE WHEN (BASE_Invoice.CustomerId IS NULL) THEN BASE_Invoice.CustomerName ELSE BASE_Customer.CustomerName END) AS CustomerName, BASE_Invoice.InvoiceMethod, BASE_Invoice.Note,
BASE_Invoice.GrossAmount, BASE_Invoice.TotalDiscount, BASE_Invoice.NetAmount, BASE_Invoice.InvoiceBalance, BASE_InvoiceLine.InvoiceLineId, BASE_Inventory.InventoryId,
BASE_Inventory.ItemNameCode, BASE_Category.CategoryId, BASE_Category.CategoryName, BASE_Inventory.ItemDescription, BASE_Unit.UnitId, BASE_Unit.UnitName, BASE_InvoiceLine.WarrantyDays,
BASE_InvoiceLine.Quantity, BASE_InvoiceLine.CostPrice, BASE_InvoiceLine.SellingPrice, BASE_InvoiceLine.ItemDiscountPercentage, BASE_InvoiceLine.ItemDiscountAmount,
BASE_InvoiceLine.TotalItemDiscount, BASE_InvoiceLine.TotalAmount, BASE_InvoicePaymentLine.InvoicePaymentLineId, BASE_InvoicePaymentLine.Amount AS AdvancePayment, BASE_InvoicePayment.InvoicePaymentId,
BASE_InvoicePayment.PaymentDate, BASE_InvoicePayment.InvoicePaymentMethod, BASE_InvoicePayment.IsCashPayment, BASE_CashInvoicePayment.CashInvoicePaymentId,
BASE_CashInvoicePayment.CashAmount, BASE_CashInvoicePayment.CashReceived, BASE_CashInvoicePayment.CashBalance, BASE_InvoicePayment.IsCardPayment,
BASE_CardInvoicePayment.CardInvoicePaymentId, BASE_CardInvoicePayment.CardType, BASE_CardInvoicePayment.CardNumber, BASE_CardInvoicePayment.Amount AS CardAmount,
BASE_InvoicePayment.IsBankDepositPayment, BASE_BankDepositInvoicePayment.BankDepositInvoicePaymentId, BASE_BankDepositInvoicePayment.DepositDate,
BASE_BankDepositInvoicePayment.NameOfBank AS BankDepositNameOfBank, BASE_BankDepositInvoicePayment.Branch AS BankDepositBranch, BASE_BankDepositInvoicePayment.AccountHolder, BASE_BankDepositInvoicePayment.AccountNumber,
BASE_BankDepositInvoicePayment.Amount AS BankDepositAmount, BASE_InvoicePayment.IsChequePayment, BASE_ChequeInvoicePayment.ChequeInvoicePaymentId, BASE_ChequeInvoicePayment.ChequeDate,
BASE_ChequeInvoicePayment.Narration, BASE_ChequeInvoicePayment.NameOfBank AS ChequeNameOfBank, BASE_ChequeInvoicePayment.Branch AS ChequeBranch, BASE_ChequeInvoicePayment.ChequeNumber,
BASE_ChequeInvoicePayment.Amount AS ChequeAmount
FROM BASE_Category RIGHT OUTER JOIN
BASE_CashInvoicePayment RIGHT OUTER JOIN
BASE_Invoice INNER JOIN
BASE_InvoiceLine ON BASE_Invoice.InvoiceId = BASE_InvoiceLine.InvoiceId INNER JOIN
BASE_InvoicePaymentLine ON BASE_Invoice.InvoiceId = BASE_InvoicePaymentLine.InvoiceId INNER JOIN
BASE_InvoicePayment ON BASE_InvoicePaymentLine.InvoicePaymentId = BASE_InvoicePayment.InvoicePaymentId INNER JOIN
BASE_Inventory ON BASE_InvoiceLine.InventoryId = BASE_Inventory.InventoryId LEFT OUTER JOIN
BASE_BankDepositInvoicePayment ON BASE_InvoicePayment.InvoicePaymentId = BASE_BankDepositInvoicePayment.InvoicePaymentId LEFT OUTER JOIN
BASE_ChequeInvoicePayment ON BASE_InvoicePayment.InvoicePaymentId = BASE_ChequeInvoicePayment.ChequeInvoicePaymentId LEFT OUTER JOIN
BASE_CardInvoicePayment ON BASE_InvoicePayment.InvoicePaymentId = BASE_CardInvoicePayment.InvoicePaymentId ON
BASE_CashInvoicePayment.InvoicePaymentId = BASE_InvoicePayment.InvoicePaymentId LEFT OUTER JOIN
BASE_Unit ON BASE_Inventory.UnitId = BASE_Unit.UnitId ON BASE_Category.CategoryId = BASE_Inventory.CategoryId LEFT OUTER JOIN
BASE_Customer ON BASE_Invoice.CustomerId = BASE_Customer.CustomerId
WHERE (BASE_Invoice.InvoiceId = 13)
Result: