USE [AL_QALAM_LIVE]
GO

/****** Object:  View [dbo].[view_MRQ_LIST]    Script Date: 7/31/2020 4:43:46 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO





ALTER VIEW [dbo].[view_MRQ_LIST]
AS
SELECT        ROW_NUMBER() OVER (PARTITION BY [InvoiceType]
ORDER BY [InvoiceType]) row_num, c.AdditionalInfo1 AS CompanyShortForm,c.Name as Company, invoicedate,i.Shipperid as shipperid,
 i.KeyField AS keyfield, '' AS CreateByUserName, InvoiceType,invoiceid, deliverydate, 
narration, g.Name AS Department, g.godownid AS supplier, 
c.godownid AS godownid, InvoiceStatus,
(Case when InvoiceStatus=1 then 'Pending' when InvoiceStatus=2 then 'Accepted' when InvoiceStatus=3 then 'Rejected' when InvoiceStatus=4 then 'Closed'  else '' end) as OrderStatus,
 '' AS col_Action, billno, totalamount, 
discountamount, totaltaxamount AS taxamount, netamount, shippingmethod, ispriceinclusivetax, 
ispriceperunit, vatoption, ReferenceInvoiceID,
    (SELECT        Keyfield
      FROM            InvoiceMaster AS im
      WHERE        im.InvoiceID = i.ReferenceInvoiceID) AS ReferenceInvoiceNo, PurchaseLedgerID, VATLedgerID, i.SupplierID AS supplierid,
	  i.CreateLog as CreateLog,i.EditLog as EditLog,i.DeleteLog as DeleteLog
FROM            InvoiceMaster AS i LEFT OUTER JOIN
                         godowns AS g ON i.Shipperid = g.GodownID INNER JOIN
                         godowns AS c ON c.GodownID = i.GodownID





GO

