Ranish666

changes in sql 2021-05-25

May 25th, 2021 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 13.91 KB | None | 0 0
  1. go
  2. Alter proc [dbo].[purhase]                    
  3. @referenceno nvarchar(max),                      
  4. @ledgerid nvarchar(max),                      
  5. @vendorbillno nvarchar(max),                      
  6. @fromdate datetime,                      
  7. @todate datetime,                      
  8. @purchasetype nvarchar(max)                
  9.      
  10. as                
  11.      
  12. if (@referenceno<>'')                    
  13. BEGIN                    
  14.    select   row_number()  OVER ( order by pm.PurchaseMasterID) as 'Sno',                      
  15.   (convert(decimal(18,2),isnull(pm.BillAmt,0))-convert(decimal(18,2),isnull(pm.nettotalamt,0)))as CashDisc ,                      
  16.    pm.TaxAmt, pm.Type, pm.mode,                      
  17. pm.PurchaseMasterID, pm.ccamt, isnull(pm.billdisamt,0) as billdisamt,                    
  18. pm.AdjustmentAmt, tu.strName,                      
  19. pm.referenceno,pm.vendorbillno,                      
  20. convert(decimal(18,2),isnull(pm.nettotalamt,0))as nettotalamt,                      
  21. al.ledgername,tu.strUsername,                      
  22. convert(decimal(18,2),isnull(pm.BillAmt,0))as BillAmt,                      
  23. convert(decimal(18,2),isnull(pm.DIscAmt,0))as DIscAmt,                
  24.      
  25. case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(datetime, pm.Entrytime),0)                    
  26.  else (select  [dbo].StringSplit( pm.Entrytime,'/',101)) end as EntrytimeReport,                
  27. --convert(date,pm.Entrytime),20)as Entrytime,                
  28. pm.type,                
  29.      
  30. --convert(varchar(10),  
  31. --convert(date,pm.Billdate),20)as Billdate,
  32. case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(date, pm.Billdate),0)
  33. else (select  [dbo].StringSplit( pm.Billdate,'/',101)) end as BilldateReport    
  34. from tblpurchasemaster pm            
  35. left join tbl_AccountLedger al on al.ledgerId=pm.AccountledgerID
  36. left join tbluser tu on tu.intUserId=pm.UserID    
  37. where
  38. al.ledgerid in (select ID from dbo.CSVToTable(@ledgerid)) and  
  39. pm.referenceno= @referenceno and      
  40. pm.VendorBillNo=(case when @vendorbillno='' then pm.VendorBillNo else @vendorbillno end)  and
  41. pm.Type in (select value from udf_SplitVariable(@purchasetype,','))                
  42.      
  43. ORDER BY PM.PurchaseMasterID DESC                    
  44. END              
  45.      
  46. ELSE              
  47.      
  48. BEGIN  
  49.  select   row_number()  OVER ( order by pm.PurchaseMasterID) as 'Sno',        
  50.   (convert(decimal(18,2),isnull(pm.BillAmt,0))-convert(decimal(18,2),isnull(pm.nettotalamt,0)))as CashDisc ,  
  51.   isnull( pm.TaxAmt,0) as TaxAmt, pm.Type, pm.mode,
  52. pm.PurchaseMasterID, isnull( pm.ccamt,0) as ccamt ,isnull(pm.billdisamt,0) as billdisamt,
  53.  isnull( pm.AdjustmentAmt,0) as AdjustmentAmt, tu.strName,    
  54. pm.referenceno,pm.vendorbillno,              
  55. convert(decimal(18,2),isnull(pm.nettotalamt,0))as nettotalamt,  
  56. al.ledgername,tu.strUsername,        
  57. convert(decimal(18,2),isnull(pm.BillAmt,0))as BillAmt,    
  58. convert(decimal(18,2),isnull(pm.DIscAmt,0))as DIscAmt,  
  59. case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(date, pm.Billdate),0)  
  60.  else (select  [dbo].StringSplit( pm.Billdate,'/',101)) end as EntrytimeReport,
  61. --convert(date,pm.Entrytime),20)as Entrytime,      
  62. pm.type,                
  63. --convert(varchar(10),        
  64. --convert(date,pm.Billdate),20)as Billdate,  
  65. case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(date, pm.Billdate),0)  
  66.  else (select  [dbo].StringSplit( pm.Billdate,'/',101)) end as BilldateReport
  67. from tblpurchasemaster pm                
  68.      
  69. left join tbl_AccountLedger al on al.ledgerId=pm.AccountledgerID  
  70. left join tbluser tu on tu.intUserId=pm.UserID    
  71. where
  72. al.ledgerid in (select ID from dbo.CSVToTable(@ledgerid)) and      
  73. pm.referenceno=(case when @referenceno='' then pm.referenceno else @referenceno end) and  
  74. pm.VendorBillNo=(case when @vendorbillno='' then pm.VendorBillNo else @vendorbillno end) and  
  75. convert(date,pm.billdate) between convert(date,@fromdate) and convert(date,@todate) and  
  76. pm.Type in (select value from udf_SplitVariable(@purchasetype,','))  
  77. ORDER BY PM.PurchaseMasterID DESC              
  78.      
  79. END
  80. go
  81. Alter proc [dbo].[SpGetAllCounterBillingReports]          
  82. @billingType nvarchar(max),              
  83.  @Type nvarchar(250),                
  84.  @strBillno nvarchar(max),                
  85.  @todate datetime =NULL,                
  86.  @patientID nvarchar(max),                
  87.  @BillMode varchar(25),                
  88.  @fromdate datetime =NULL,                
  89.  @strUsername nvarchar(500),                
  90.  @acid nvarchar(max) ,      
  91.  @recvLedger nvarchar(max)      
  92.        
  93.  as                
  94.        
  95.  begin                
  96.        
  97. create table #acid ( id int,ledgerName nvarchar(255))                                
  98.   insert into #acid (id,ledgerName)                                
  99.   select ledgerId,ledgerName from tbl_AccountLedger                                
  100.   where ledgerId in ( select * from dbo.CSVToTable(@acid))              
  101.              
  102. create table #recvLedger ( id int,ledgerName nvarchar(255))                                
  103.   insert into #recvLedger (id,ledgerName)                                
  104.   select ledgerId,ledgerName from tbl_AccountLedger                                
  105.   where ledgerId in ( select * from dbo.CSVToTable(@recvLedger+',0'))          
  106.        
  107.  if (@fromdate  IS null)          
  108.        
  109.  begin              
  110.  select   row_number()  OVER ( order by tb.BillingMasterID desc ) as 'Sno',  
  111.     tb.BillingMasterID as BillingMasterID,        
  112.      case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(datetime, tb.EntryTime),0)    
  113.     else tb.bsentrydate end as ReportDate,    
  114.     tb.strbillno,    
  115.     te.strPatientID,  
  116.     tp.srtfname,      
  117.     tp.strlName,  
  118.     tb.Narration as narration,  
  119.    (tb.total + tb.DiscountAmt - tb.taxAmt)  as subTotal,    
  120.     case when tb.TaxAmt<>0 then(  case when tb.Type in ('Counter Return','Counter Sale')    
  121.     then tb.total-tb.TaxAmt else tb.total-tb.TaxAmt end) else 0 end  TaxableAmt,    
  122.     isnull( tb.total,0) as TotalAmt,  
  123.     isnull((tb.total)-tb.BillDiscount-tb.TaxAmt,0) as total,  
  124.     tb.DiscountAmt,  
  125.     tb.taxAmt,    
  126.     tb.BillDiscount,  
  127.     tb.receiveAmt,    
  128.     (case when  tb.Type='Deposit' then 'Counter Deposit'    
  129.    when tb.Type='Return' then 'Deposit Refund'      
  130.    when tb.Type='Due' then 'Counter Clearance' else tb.Type end) as Type,    
  131.     ta.ledgerName,        
  132.   taa.ledgerName as RecvLedger,      
  133.     tb.BillingType,      
  134.     tu.strusername from tblBillingMaster tb  with(nolock)    
  135.     inner join tblencounter te with(nolock) on tb.strEncounterID=te.strEncounterID    
  136.     inner join tblpaitentinfo tp with(nolock) on tp.patientID=te.strPatientID  
  137.     inner join #acid ta with(nolock) on ta.id= tb.AcLedgerID                
  138.     left join #recvLedger taa with(nolock)  on taa.id= tb.ReceiveLedgerID      
  139.     inner join tblUser tu with(nolock) on tu.intUserId=tb.UserID  
  140.  WHERE convert(date,tb.EntryTime) = CONVERT(date,GETDATE())  
  141.     and tb.Type in ('Counter Sale','Counter Return','Deposit','Return','Due')    
  142.    order by  tb.BillingMasterID desc          
  143.        
  144. end          
  145.        
  146. else          
  147.        
  148. begin      
  149.    select   row_number()  OVER ( order by tb.BillingMasterID  desc ) as 'Sno',    
  150.     tb.BillingMasterID,      
  151.   case when dbo.ReportDateBySetting('16')='English' then convert(varchar,convert(datetime, tb.EntryTime),0)    
  152.     else tb.bsentrydate end as ReportDate,      
  153.     tb.strbillno,      
  154.     te.strPatientID,  
  155.     tp.srtfname,    
  156.     tp.strlName,    
  157.      tb.Narration as narration,    
  158.    (tb.total + tb.DiscountAmt - tb.taxAmt)  as subTotal,  
  159.     case when tb.TaxAmt<>0 then(  case when tb.Type in ('Counter Return','Counter Sale')  
  160.     then tb.total-tb.TaxAmt else tb.total-tb.TaxAmt end) else 0 end  TaxableAmt,    
  161.     isnull( tb.total,0) as TotalAmt,        
  162.     isnull((tb.total)-tb.BillDiscount-tb.TaxAmt,0) as total,      
  163.     tb.DiscountAmt,    
  164.     tb.taxAmt,      
  165.     tb.BillDiscount,  
  166.     tb.receiveAmt,      
  167.    (case when  tb.Type='Deposit' then 'Counter Deposit'      
  168.    when tb.Type='Return' then 'Deposit Refund'  
  169.    when tb.Type='Due' then 'Counter Clearance' else tb.Type end) as Type,              
  170.     ta.ledgerName,        
  171.  taa.ledgerName as RecvLedger,                
  172.     tb.BillingType,                
  173.     tu.strusername from tblBillingMaster  tb  with(nolock)                
  174.     inner join tblencounter te with(nolock) on tb.strEncounterID=te.strEncounterID                
  175.     inner join tblpaitentinfo tp with(nolock) on tp.patientID=te.strPatientID                
  176.     inner join #acid ta with(nolock) on ta.id= tb.AcLedgerID                
  177.     inner join #recvLedger  taa with(nolock) on taa.id= tb.ReceiveLedgerID                  
  178.     left join tblindexType ti with(nolock) on ti.ID=tb.VourcherTypeID                
  179.        
  180.     inner join tblUser tu on tu.intUserId=tb.UserID                
  181.        
  182.     where                
  183.        
  184.     tb.BillingType in (select value from udf_SplitVariable(@billingType,','))            
  185.       and          
  186.     tu.strUsername=(case when @strUsername=''  then  tu.strUsername else @strUsername end)      
  187.     and            
  188.     tp.patientID=(case when @patientID='' then  tp.patientID else @patientID end)  
  189.     and            
  190.     tb.Type in (select value from udf_SplitVariable(@Type,','))    
  191.     and                
  192.     tb.strbillno=(case when @strBillno='' then  tb.strbillno else @strBillno end)    
  193.     and        
  194.     tb.billingmodeid in (select * from dbo.CSVToTable(@BillMode+',0'))  
  195.    and              
  196.     convert(date,tb.EntryTime)  
  197.     between convert(date,@fromdate)    
  198.     and convert(date,@todate)    
  199.     and tb.Type in ('Counter Sale','Counter Return','Deposit','Return','Due')    
  200.         order by tb.BillingMasterID desc            
  201.        
  202. end          
  203.        
  204.  end  
  205.  go
  206.  Alter proc [dbo].[spPatientDetailsGetByBillNo]              
  207. @BillNo nvarchar(max)                    
  208. as                    
  209. begin                    
  210. DECLARE   @patientid nvarchar(max)                    
  211. declare @AcLedgerid int                    
  212. set @patientid=(select TE.strPatientID from tblBillingMaster TBM INNER JOIN tblEncounter TE                    
  213. ON TBM.strEncounterID=TE.strEncounterID where TBM.strBillno=@BillNo)                    
  214. set @AcLedgerid=(select acledgerid from tblBillingMaster where strBillno=@BillNo)                    
  215.                    
  216. SELECT                
  217.   case when TP.extra1 = '1' then gp.PatientName else TP.srtfname + ' '+ tp.strlname end as 'Name',      
  218.  --TP.srtfname +' '+ tp.strlname as 'Name',                    
  219.  Convert(varchar,TBM.entryTime,101)  as 'Date',                    
  220.  TBM.strBillno as 'InvoiceNo',                  
  221.  tbm.claimcode as 'ClaimID' ,                  
  222.  te.Policy_Num as 'PolicyNo',                  
  223.  tbm.BillingMasterID ,          
  224.  TBM.billingType as 'Type',            
  225.              
  226.   (case when  TBM.Type='Deposit' then 'Counter Deposit'              
  227.    when TBM.Type='Return' then 'Deposite Refund'              
  228.    when TBM.Type='Due' then 'Counter Clearance' else TBM.Type end) as 'VoucherType',                  
  229.  isnull( (select top 1 tbd.MasterBillNo from tblBillDetails tbd  where strbillno=@BillNo),'N/A') 'MasterBillNo',                  
  230.  (select td.DistrictName+', '+m.Municipality+' - '+tp.strAddress from tblpaitentinfo tp                      
  231. inner join tblDistrict td on tp.strdistrict=td.ID                    
  232. inner join tblMunicipality m  on m.mID=tp.[VDC/Municipality]                    
  233. where tp.patientID=@patientid)as 'Address',                    
  234.  TP.patientID as 'PatientID',                    
  235.    convert(decimal(18,2), (TBM.Total-tbm.billdiscount)) as 'NetTotal' ,                    
  236.  convert(decimal(18,2),(TBM.discountAmt + tbm.billdiscount)) as 'Discount',                    
  237.  convert(decimal(18,2),TBM.TaxAmt) as 'Tax',                    
  238. convert(decimal(18,0),TBM.ReceiveAmt) as 'Received',                    
  239.  convert(decimal(18,2),(TBM.total+TBM.DiscountAmt)-TBM.TaxAmt) as 'BillTotal',                    
  240.  TBM.Narration as narration,                    
  241.  TU.strUsername   as 'User',                    
  242.  (select top 1 tcd.strdoctorname from tblBillDetails tbd                    
  243.  inner join tblConsaltantdoctr tcd                    
  244.  on tbd.intrefer_drID=tcd.id                    
  245.  where strbillno=@BillNo) 'ReferBy',                    
  246.   ta.ledgerName as 'ACLedger',                    
  247.  (select dbo.GetpatientAge(@patientid)) +'/'+ TP.strGender   as 'AgeSex',                    
  248.  convert(decimal(18,2),( select dbo.getPreviousDepositAmt(@BillNo,@patientid,@AcLedgerid))) as 'PreDeposit',                    
  249.  convert(decimal(18,2),(((select dbo.getPreviousDepositAmt(@BillNo,@patientid,@AcLedgerid)))+((receiveAmt+billdiscount)-total)) )as 'NewDeposit',                    
  250.   TP.intmobile as 'Conatct',                
  251.  case when dbo.ReportDateBySetting('16')='English' then  
  252.  CONCAT(convert(varchar,convert(datetime,GETDATE()),111) , ' ' , FORMAT(GETDATE(),'hh:mm tt'))                
  253.  else CONCAT((select  [dbo].StringSplit( GETDATE(),'/',101)), ' ' , FORMAT(GETDATE(),'hh:mm tt') )  
  254.  end as PrintDate                
  255.                        
  256. FROM                    
  257.  tblBillingMaster TBM                    
  258.  INNER JOIN tblEncounter TE ON TBM.strEncounterID=TE.strEncounterID                    
  259.  INNER JOIN tblpaitentinfo TP ON TE.strPatientID=TP.patientID        
  260.   left join tblGeneralPatientPharmacySales gp on gp.BillNo=@BillNo  and gp.PatientID=te.strPatientID      
  261.  left JOIN tblUser TU ON TBM.UserID=TU.intUserId                    
  262.  INNER JOIN tbl_AccountLedger ta on ta.ledgerId=TBM.AcLedgerID                    
  263.  WHERE TBM.strBillno=@BillNo                    
  264.                    
  265. end      
  266. go
  267.  
Add Comment
Please, Sign In to add comment