Advertisement
0re5ama

reports

Sep 9th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1. ---- PAN Status Report -----
  2. select b."PAN", get_nep_date(br."EntryDate"::date) as Date, count(brd."Id") as fileCount, fus."Name" as Status
  3. from "BillingRegister"."BillingRegisters" br
  4. join "BillingRegister"."Branches" b
  5. on b."Id" = br."BranchId"
  6. join "BillingRegister"."BillingRegisterDetails" brd
  7. on brd."BillingRegisterId" = br."Id"
  8. join "BillingRegister"."FileUploadStatus" fus
  9. on fus."Id" = br."BRStatusId"
  10. group by b."PAN", br."EntryDate", fus."Name"
  11.  
  12.  
  13.  
  14. ----- File Status Report ------
  15. select fus."Id", fus."Name" as "Status", count(brd."Id")
  16. from "BillingRegister"."BillingRegisterDetails" brd
  17. join "BillingRegister"."FileUploadStatus" fus
  18. on brd."StatusId" = fus."Id"
  19. group by fus."Id", fus."Name"
  20.  
  21.  
  22. ----- BillingRegister Report ------
  23.  
  24. select br."Id"
  25. from "BillingRegister"."BillingRegisters" br
  26. join "BillingRegister"."Branches" b
  27. on b."Id" = br."BranchId"
  28. where b."PAN" in (
  29. WITH RECURSIVE q AS (
  30. SELECT "OfficeCode"
  31. from "Security"."Offices"
  32. where "OfficeCode" = :offcode
  33. UNION ALL
  34. SELECT t1."OfficeCode"
  35. from q c
  36. JOIN "Security"."Offices" t1
  37. ON t1."ParentId" = c."OfficeCode"
  38. )
  39. select op."Pan"::varchar(9) from q
  40. join "Security"."OfficePan" op
  41. on op."OfficeCode" = q."OfficeCode"
  42. )
  43. and br."MonthId" = 4
  44. and br."Id" not in (select "BillingRegisterId" from "BillingRegister"."BillingRegisterDetails")
  45.  
  46.  
  47.  
  48. select
  49. get_nep_date(entry_date::date), count(pan) as uploaded_pan,
  50. sum(tot_uploaded_files) as tot_uploaded_files,
  51. sum(pending) as pending,
  52. sum(processing) as processing,
  53. sum(success) as success,
  54. sum(err) as err,
  55. sum(reuploaded) as reuploaded,
  56. sum(
  57. case
  58. when sales >= 1 and purchase >= 1 then 1
  59. else 0
  60. end
  61. ) as uploaded_both_files
  62. from (
  63. WITH RECURSIVE q AS (
  64. SELECT "OfficeCode"
  65. from "Security"."Offices"
  66. where "OfficeCode" = :offcode
  67. UNION ALL
  68. SELECT t1."OfficeCode"
  69. from q c
  70. JOIN "Security"."Offices" t1
  71. ON t1."ParentId" = c."OfficeCode"
  72. )
  73. select br."EntryDate"::varchar(10) as entry_date, b."PAN" as pan, sum(
  74. case brd."StatusId"
  75. when 7 then 0
  76. else 1
  77. end
  78. ) as tot_uploaded_files,
  79. sum(
  80. case brd."StatusId"
  81. when 1 then 1
  82. else 0
  83. end
  84. ) as pending,
  85. sum(
  86. case brd."StatusId"
  87. when 2 then 1
  88. else 0
  89. end
  90. ) as processing,
  91. sum(
  92. case brd."StatusId"
  93. when 4 then 1
  94. else 0
  95. end
  96. ) as success,
  97. sum(
  98. case brd."StatusId"
  99. when 5 then 1
  100. else 0
  101. end
  102. ) as err,
  103. sum(
  104. case brd."StatusId"
  105. when 7 then 1
  106. else 0
  107. end
  108. ) as reuploaded,
  109. sum(
  110. case brd."BillingRegisterTypeId"
  111. when 1 then 1
  112. else 0
  113. end
  114. ) as sales,
  115. sum(
  116. case brd."BillingRegisterTypeId"
  117. when 2 then 1
  118. else 0
  119. end
  120. ) as purchase
  121. from "BillingRegister"."BillingRegisters" br
  122. join "BillingRegister"."BillingRegisterDetails" brd
  123. on brd."BillingRegisterId" = br."Id"
  124. join "BillingRegister"."Branches" b
  125. on b."Id" = br."BranchId"
  126. join "Security"."OfficePan" op
  127. on op."Pan"::varchar(9) = b."PAN"
  128. join q
  129. on q."OfficeCode" = op."OfficeCode"
  130. where br."FiscalYearId" = :fyid
  131. and (:monthid is null or br."MonthId" = :monthid)
  132. group by br."EntryDate", b."PAN"
  133. ) as tbl
  134. group by entry_date
  135. order by entry_date asc;
  136.  
  137.  
  138. ----------- pan wise report ----------
  139.  
  140. select
  141. pan,
  142. sales_status."Name" as "SalesStatus",
  143. "EntryDate" as "SalesDate",
  144. purchase_status."Name" as "PurchaseStatus",
  145. "EntryDate" as "PurchaseDate",
  146. sales_ret_status."Name" as "SalesReturnStatus",
  147. "EntryDate" as "SalesReturnDate",
  148. purchase_ret_status."Name" as "PurchaseReturnStatus",
  149. "EntryDate" as "PurchaseReturnDate"
  150. from (
  151. WITH RECURSIVE q AS (
  152. SELECT "OfficeCode"
  153. from "Security"."Offices"
  154. where "OfficeCode" = :offcode
  155. UNION ALL
  156. SELECT t1."OfficeCode"
  157. from q c
  158. JOIN "Security"."Offices" t1
  159. ON t1."ParentId" = c."OfficeCode"
  160. )
  161. select
  162. b."PAN" as pan,
  163. max(case
  164. when brd."BillingRegisterTypeId" = 1 then brd."Id"
  165. else null
  166. end) as "Sales",
  167. max(case
  168. when brd."BillingRegisterTypeId" = 2 then brd."Id"
  169. else null
  170. end) as "Purchase",
  171. max(case
  172. when brd."BillingRegisterTypeId" = 3 then brd."Id"
  173. else null
  174. end) as "SalesReturn",
  175. max(case
  176. when brd."BillingRegisterTypeId" = 4 then brd."Id"
  177. else null
  178. end) as "PurchaseReturn",
  179. br."EntryDate"
  180. from "BillingRegister"."BillingRegisters" br
  181. left outer join "BillingRegister"."BillingRegisterDetails" brd
  182. on brd."BillingRegisterId" = br."Id"
  183. left outer join "BillingRegister"."FileUploadStatus" fus
  184. on fus."Id" = brd."StatusId"
  185. join "BillingRegister"."Branches" b
  186. on b."Id" = br."BranchId"
  187. join "Security"."OfficePan" op
  188. on op."Pan"::varchar(9) = b."PAN"
  189. join q
  190. on q."OfficeCode" = op."OfficeCode"
  191. where br."FiscalYearId" = :fyid
  192. and (:monthid is null or br."MonthId" = :monthid)
  193. and brd."StatusId" <> 7
  194. group by b."PAN", br."EntryDate"
  195. ) as tbl
  196. left outer join "BillingRegister"."BillingRegisterDetails" sales
  197. on sales."Id" = tbl."Sales"
  198. left outer join "BillingRegister"."FileUploadStatus" sales_status
  199. on sales."StatusId" = sales_status."Id"
  200. left outer join "BillingRegister"."BillingRegisterDetails" purchase
  201. on purchase."Id" = tbl."Purchase"
  202. left outer join "BillingRegister"."FileUploadStatus" purchase_status
  203. on purchase."StatusId" = purchase_status."Id"
  204. left outer join "BillingRegister"."BillingRegisterDetails" sales_ret
  205. on sales_ret."Id" = tbl."SalesReturn"
  206. left outer join "BillingRegister"."FileUploadStatus" sales_ret_status
  207. on sales_ret."StatusId" = sales_ret_status."Id"
  208. left outer join "BillingRegister"."BillingRegisterDetails" purchase_ret
  209. on purchase_ret."Id" = tbl."PurchaseReturn"
  210. left outer join "BillingRegister"."FileUploadStatus" purchase_ret_status
  211. on purchase_ret."StatusId" = purchase_ret_status."Id";
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219. ----------------------------xxxxxxxxxxxxxxxx
  220.  
  221. show data_directory;
  222.  
  223. select "SellerPAN", "UUID", "InvoiceNo", get_nep_date("BillDate"::date), "TotalAmount", "TotalPayableAmount" from "BillingRegister"."SalesRegisters" sr
  224. where "BranchId" = 1;
  225.  
  226.  
  227.  
  228. select top 1 "EntryDate") from "BillingRegister"."BillingRegisters" br
  229. order by "EntryDate" desc;
  230.  
  231.  
  232.  
  233. select * from "BillingRegister"."BillingRegisterDetails" brd
  234. where "BillingRegisterId" = 555;
  235.  
  236.  
  237. select * from "BillingRegister"."PurchaseRegisterDumps" prd
  238. where "BillingRegisterDetailId" = 941;
  239.  
  240. select * from "BillingRegister"."PurchaseRegisters" pr
  241. where "BRDetId" = 1409
  242.  
  243. delete from "BillingRegister"."BillingRegisters"
  244. where "Id" = 225;
  245.  
  246. select * from "BillingRegister"."BillingRegisterDetails" brd
  247.  
  248.  
  249.  
  250. select * from "BillingRegister"."BillingRegisterDetails" brd
  251. join "BillingRegister"."SalesRegisterDumps" srd
  252. on srd."BillingRegisterDetailId" = brd."Id"
  253. where brd."StatusId" = 2
  254.  
  255.  
  256. select * from "BillingRegister"."BillingRegisterDetails" brd
  257. where "StatusId" = 1
  258. order by "Id";
  259.  
  260.  
  261. select * from "BillingRegister"."BillingRegisters" br
  262. where "BRStatusId" = 4
  263.  
  264.  
  265. select * from "BillingRegister"."BillingRegisterDetails" brd
  266. where "StatusId" = 2
  267.  
  268.  
  269.  
  270. select * from "BillingRegister"."SalesRegisterDumps"
  271. where "BillingRegisterDetailId" in (
  272. 578,
  273. 639,
  274. 698,
  275. 725
  276. )
  277.  
  278. update "BillingRegister"."BillingRegisterDetails"
  279. set "StatusId" = 1
  280. where "Id" <= 546;
  281.  
  282.  
  283. update "BillingRegister"."BillingRegisters" set "BRStatusId" = 1 where "Id" <= 456
  284.  
  285.  
  286. select * from "BillingRegister"."BillingRegisterDetails" brd
  287. where "BillingRegisterId" = 285
  288.  
  289. select * from "BillingRegister"."BillingRegisters" br where "Id" = 479
  290.  
  291.  
  292. select "FileName" from "BillingRegister"."BillingRegisterDetails" brd
  293.  
  294.  
  295. select * from "BillingRegister"."BillingRegisters" br
  296. where "Id" = 502
  297.  
  298.  
  299. select count("Id") from "BillingRegister"."BillingRegisterDetails" brd
  300. where "StatusId" = 1
  301.  
  302. insert into "BillingRegister"."BillingRegisterDetails"
  303. ("FileName", "BillingRegisterTypeId", "BillingRegisterId", "StatusId", "Name", "Issues")
  304. values ('a65c211c-091e-4ed2-9eed-1058d7d1223a.xlsx', 1, 171, 1, null, null);
  305.  
  306. select * from "BillingRegister"."BillingRegisterDetails" brd where "FileName" = 'a65c211c-091e-4ed2-9eed-1058d7d1223a.xlsx'
  307.  
  308. select * from "BillingRegister"."BillingRegisters" where "Id" = 171;
  309.  
  310.  
  311. select * from "BillingRegister"."BillingRegisters" br
  312. where "BranchId" in (select "Id" from "BillingRegister"."Branches" b where b."PAN" = '601178395')
  313.  
  314.  
  315. select * from "BillingRegister"."BillingRegisters" br
  316. join "BillingRegister"."Branches" b
  317. on b."Id" = br."BranchId"
  318. where b."PAN" = '301342340'
  319.  
  320. select * from "BillingRegister"."BillingRegisters" br
  321. join "BillingRegister"."Branches" b
  322. on b."Id" = br."BranchId"
  323. where b."PAN" = '601178395'
  324.  
  325.  
  326. update "BillingRegister"."BillingRegisterDetails" set
  327.  
  328.  
  329. select * from
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement