Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 83.31 KB | None | 0 0
  1. Use Payroll
  2.  
  3. --Salaries11
  4. --Allowances
  5. --Leave
  6. --Superannuation
  7.  
  8. Declare @Report_Fortnight_Number varchar(10)    = 'FT-01'
  9.  
  10. --Declare the Table for the storage of the Job Numbers and Account
  11.     Declare
  12.         @tmp_Job_Numbers table
  13.             (
  14.                 Column_Number   varchar(10),
  15.                 Job_Id          int Identity(0,1) Primary Key,
  16.                 Job_Number      varchar(10),
  17.                 Job_Name        varchar(250),
  18.                 Job_Area        varchar(250),
  19.                 Job_Account_Number_Main     varchar(10),
  20.                 Job_Account_Number_Payroll  varchar(10),
  21.                 Job_Account_Name            varchar(250),
  22.                 Job_Account_Structure_L01   varchar(250),
  23.                 Job_Account_Structure_L02   varchar(250),
  24.                 Job_Account_Structure_L03   varchar(250),
  25.                 Job_Account_Amount          money
  26.             )
  27.  
  28.     Insert Into
  29.         @tmp_Job_Numbers
  30.             (
  31.                 Column_Number,
  32.                 Job_Number,
  33.                 Job_Name,
  34.                 Job_Area,
  35.                 Job_Account_Number_Main,
  36.                 Job_Account_Number_Payroll,
  37.                 Job_Account_Name,
  38.                 Job_Account_Structure_L01,
  39.                 Job_Account_Structure_L02,
  40.                 Job_Account_Structure_L03
  41.             )
  42.         Values
  43.             ('Column_006','HA','Hours for Allocation','','','','','','',''),
  44.             ('Column_007','J01','Council Corporate','All','10222010','10222011','Salaries','Corporate','Operating Expenditure','Staff Costs'),
  45.             ('Column_008','J02','Link Administration','All','13210010','13210011','Leisure Administration Operating','Leisure Services','Operating Expenditure','Operating'),
  46.             ('Column_009','J03','WHS','All','10222210','10222211','Occupation Health & Safety','Corporate','Operating Expenditure','Staff Costs'),
  47.             ('Column_010','J04','Financial Services','All','10215011','10215011','Financial Services','','',''),
  48.             ('Column_011','J05','Customer Service','All','10219191','10219191','Customer Service','','',''),
  49.             ('Column_012','J06','GIS & Asset Management','All','14215091','14215091','Salaries','Corporate','Operating Expenditure','Staff Costs'),
  50.             ('Column_013','J07','N/A','All','','','','','',''),
  51.             ('Column_014','J08','Community Forums','All','11210120','11210121','Community Forums Expenses','','',''),
  52.             ('Column_015','J09','Sport & Recreation Dev','All','11210420','11210421','Sport & Recreation Development','','',''),
  53.             ('Column_016','J10','Governance','Council','10219070','10219071','Elected Members Running Expenses','Corporate','Operating Expenditure','Corporate Operating'),
  54.             ('Column_017','J11','Services SA','Council','10220020','10220021','Services SA Expenses','Corporate','Operating Expenditure','Commercial Operating'),
  55.             ('Column_018','J12','Government Housing','Council','10220060','10220061','Government Houses Expenses','Corporate','Operating Expenditure','Commercial Operating'),
  56.             ('Column_019','J13','Information Technology','Council','10223010','10223011','Computer Maintenance & Support','Corporate','Operating Expenditure','IT Operating'),
  57.             ('Column_020','J14','Television','Council','11210240','11210241','Television Maintenance Work','Community','Operating Expenditure','Community Expenses'),
  58.             ('Column_021','J15','Business Support','Council','11210300','11210301','Business Support','Community','Operating Expenditure','Community Expenses'),
  59.             ('Column_022','J16','Tourism Support','Council','11210340','11210341','Tourism & Area Promo','Community','Operating Expenditure','Community Expenses'),
  60.             ('Column_023','J17','Youth Support','Council','11210390','11210391','Youth Development Expenses','Community','Operating Expenditure','Community Expenses'),
  61.             ('Column_024','J18','Festival Events','Council','11210010','11210011','Festivals Support','Community','Operating Expenditure','Community Expenses'),
  62.             ('Column_025','J19','Arts and Cultural Support','Council','11210030','11210031','Arts & Cultural Support','Community','Operating Expenditure','Community Expenses'),
  63.             ('Column_026','J20','Main Street Activities','Council','11210070','11210071','Main Street Activities','Community','Operating Expenditure','Community Expenses'),
  64.             ('Column_027','J21','Community Board','Council','11210100','11210101','Community Board Running Expenses','Community','Operating Expenditure','Community Expenses'),
  65.             ('Column_028','J22','Community Radio','Council','11210210','11210211','Community Radio','Community','Operating Expenditure','Community Expenses'),
  66.             ('Column_029','J23','Community Newspaper','Council','11210220','11210221','The Monitor Community Communications','Community','Operating Expenditure','Community Expenses'),
  67.             ('Column_030','J24','Community General','Council','11210280','11210281','Community Other Expenses','Community','Operating Expenditure','Community Expenses'),
  68.             ('Column_031','J25','Ovals','Council','13213030','13213031','Oval Surface Main Maintenance','Leisure Services','Operating Expenditure','Oval Expenses'),
  69.             ('Column_032','J26','Garbage Collection','Council','14210010','14210011','Residential Garbage Collection','Works','Operating Expenditure','Refuse Collection'),
  70.             ('Column_033','J27','Recycling Collection','Council','14210030','14210031','Recycling Collection','Works','Operating Expenditure','Refuse Collection'),
  71.             ('Column_034','J28','Waste Disposal','Council','14211020','14211021','Transfer Station Maintenance & Running','Works','Operating Expenditure','Waste Disposal'),
  72.             ('Column_035','J29','Street Cleaning','Council','14212010','14212011','Street Cleaning Expenses','Works','Operating Expenditure','Street Cleaning'),
  73.             ('Column_036','J30','Pest Insects','Council','14213010','14213011','Pests Insects Expenses','Works','Operating Expenditure','Other Environmental Services'),
  74.             ('Column_037','J31','Pest Plants','Council','14213020','14213021','Pests Plants Expenses','Works','Operating Expenditure','Other Environmental Services'),
  75.             ('Column_038','J32','Environment','Council','14213030','14213031','Other Environmental Expenses','Works','Operating Expenditure','Other Environmental Services'),
  76.             ('Column_039','J33','Public Conveniences','Council','14214010','14214011','Public Convenience Richardson Place','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  77.             ('Column_040','J34','Parks & Gardens','Council','14214040','14214041','Parks Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  78.             ('Column_041','J35','Playgrounds','Council','14214060','14214061','Playgrounds Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  79.             ('Column_042','J36','Golf Course','Council','14214120','14214121','Golf Club Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  80.             ('Column_043','J37','Streetscaping','Council','14215020','14215021','Streetscaping General','Works','Operating Expenditure','Streetscaping Maintenance'),
  81.             ('Column_044','J38','Tree Trim','Council','14215070','14215071','Tree Trim','Works','Operating Expenditure','Streetscaping Maintenance'),
  82.             ('Column_045','J39','Works General','Council','14215080','14215081','Other Infrastructure Expenses','Works','Operating Expenditure','Streetscaping Maintenance'),
  83.             ('Column_046','J40','Street Lighting','Council','14216010','14216011','Street Lighting Expenses','Works','Operating Expenditure','Street Lighting Expenses'),
  84.             ('Column_047','J41','Roads & Streets','Council','14217010','14217011','Seal Patching','Works','Operating Expenditure','Roads & Streets Maintenance'),
  85.             ('Column_048','J42','Footpaths','Council','14218020','14218021','General Footpaths Maintenance','Works','Operating Expenditure','Footpath Maintenance'),
  86.             ('Column_049','J43','Stormwater','Council','14219010','14219011','Stormwater Other Expenses','Works','Operating Expenditure','Stormwater Maintenance'),
  87.             ('Column_050','J44','Building','Council','15210020','15210021','Building Other Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  88.             ('Column_051','J45','Planning','Council','15210040','15210041','Town Planning Other Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  89.             ('Column_052','J46','Dogs','Council','15210100','15210101','Dog Control','Regulatory Services','Operating Expenditure','Expenses'),
  90.             ('Column_053','J47','Cats','Council','15210110','15210111','Cat Control','Regulatory Services','Operating Expenditure','Expenses'),
  91.             ('Column_054','J48','Health','Council','15210160','15210161','Health Consultants','Regulatory Services','Operating Expenditure','Expenses'),
  92.             ('Column_055','J49','Parking','Council','15210190','15210191','Parking Control','Regulatory Services','Operating Expenditure','Expenses'),
  93.             ('Column_056','J50','Other Regulatory','Council','15210200','15210201','Other Regulatory Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  94.             ('Column_057','J51','Power','Council','20215010','20215011','Electricity Operating','Power','Operating Expenditure','Electricity Operating'),
  95.             ('Column_058','J52','Water','Council','30214010','30214011','Water Operating','Water','Operating Expenditure','Operating'),
  96.             ('Column_059','J53','Sewer','Council','40214010','40214011','Sewer Operating','Sewer','Operating Expenditure','Operating'),
  97.             ('Column_060','J54','N/A','Council','','','','','',''),
  98.             ('Column_061','J55','N/A','Council','','','','','',''),
  99.             ('Column_062','J56','N/A','Council','','','','','',''),
  100.             ('Column_063','J57','N/A','Council','','','','','',''),
  101.             ('Column_064','J58','N/A','Council','','','','','',''),
  102.             ('Column_065','J59','N/A','Council','','','','','',''),
  103.             ('Column_066','J60','Art Gallery','Link','12210030','12210031','Art Gallery Operating','Cultural Services','Operating Expenditure','Operating'),
  104.             ('Column_067','J61','Cafe','Link','12210040','12210041','Cafe Operating','Cultural Services','Operating Expenditure','Operating'),
  105.             ('Column_068','J62','Cinema','Link','12210050','12210051','Cinema Operating','Cultural Services','Operating Expenditure','Operating'),
  106.             ('Column_069','J63','Creche','Link','13210060','13210061','Creche Operating','Leisure Services','Operating Expenditure','Operating'),
  107.             ('Column_070','J64','Functions','Link','12210020','12210021','Functions Operating','Cultural Services','Operating Expenditure','Operating'),
  108.             ('Column_071','J65','Gym','Link','13210030','13210031','Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  109.             ('Column_072','J66','Kiosk','Link','13210020','13210021','Kiosk Operating','Leisure Services','Operating Expenditure','Operating'),
  110.             ('Column_073','J67','Leisure Events','Link','13210080','13210081','Leisure Events Operating','Leisure Services','Operating Expenditure','Operating'),
  111.             ('Column_074','J68','Library','Link','12210090','12210091','Library Operating','Cultural Services','Operating Expenditure','Operating'),
  112.             ('Column_075','J69','Nippy Gym','Link','13210070','13210071','Nippy Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  113.             ('Column_076','J70','Pool','Link','13210040','13210041','Pool Operating','Leisure Services','Operating Expenditure','Operating'),
  114.             ('Column_077','J71','Sports and Recreation','Link','13210050','13210051','Sports & Recreation Operating','Leisure Services','Operating Expenditure','Operating'),
  115.             ('Column_078','J72','Toy Library','Link','12210080','12210081','Toy Library Operating','Cultural Services','Operating Expenditure','Operating'),
  116.             ('Column_079','J73','Visitors Information Centre','Link','12210060','12210061','VIC Operating','Cultural Services','Operating Expenditure','Operating'),
  117.             ('Column_080','J74','N/A','Link','','','','','',''),
  118.             ('Column_081','J75','Meter Reading - Power','Council','50017110','50017110','Meter Reading - Power','','',''),
  119.             ('Column_082','J76','Meter Reading - Water','Council','50017110','50017110','Meter Reading - Water','','',''),
  120.  
  121.             ('Column_083','J77','Maintenance - Council Office','Link','10210010','10210011','Office Building Maintenance','','',''),
  122.             ('Column_084','J78','Maintenance - Culture Centre','Link','12211010','12211011','Cultural Centre Building Maintenance','','',''),
  123.             ('Column_085','J79','Maintennace - Leisure Centre','Link','13211010','13211011','Leisure Centre Building Maintenance','','',''),
  124.             ('Column_086','J80','Maintenance - Other Buildings','Link','10211070','10211071','Other Building Maintenance','','',''),
  125.  
  126.             ('Column_087','J81','Special - Group Fitness','Link','13210030','13210031','Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  127.             ('Column_088','J82','Special - Swim School','Link','13210040','13210041','Pool Operating','Leisure Services','Operating Expenditure','Operating'),
  128.             ('Column_089','J83','N/A','Link','','','','','',''),
  129.             ('Column_090','J84','N/A','Link','','','','','',''),
  130.             ('Column_091','J85','N/A','Link','','','','','',''),
  131.             ('Column_092','J86','N/A','Link','','','','','',''),
  132.             ('Column_093','J87','N/A','Link','','','','','',''),
  133.             ('Column_094','J88','N/A','Link','','','','','',''),
  134.             ('Column_095','J89','N/A','Link','','','','','',''),
  135.             ('Column_096','J90','N/A','Link','','','','','','')
  136.            
  137. Declare
  138.         @tmp_Job_Numbers_Leave table
  139.             (
  140.                 Column_Number   varchar(10),
  141.                 Job_Id          int Identity(0,1) Primary Key,
  142.                 Job_Number      varchar(10),
  143.                 Job_Name        varchar(250),
  144.                 Job_Area        varchar(250),
  145.                 Job_Account_Number_Main     varchar(10),
  146.                 Job_Account_Number_Payroll  varchar(10),
  147.                 Job_Account_Name            varchar(250),
  148.                 Job_Account_Structure_L01   varchar(250),
  149.                 Job_Account_Structure_L02   varchar(250),
  150.                 Job_Account_Structure_L03   varchar(250),
  151.                 Job_Account_Amount          money
  152.             )
  153.  
  154.     Insert Into
  155.         @tmp_Job_Numbers_Leave
  156.             (
  157.                 Column_Number,
  158.                 Job_Number,
  159.                 Job_Name,
  160.                 Job_Area,
  161.                 Job_Account_Number_Main,
  162.                 Job_Account_Number_Payroll,
  163.                 Job_Account_Name,
  164.                 Job_Account_Structure_L01,
  165.                 Job_Account_Structure_L02,
  166.                 Job_Account_Structure_L03
  167.             )
  168.         Values
  169.             ('Column_006','HA','Hours for Allocation','','','','','','',''),
  170.             ('Column_007','J01','Council Corporate - Leave Allocation','All','10222010','10222011','Salaries','Corporate','Operating Expenditure','Staff Costs'),
  171.             ('Column_008','J02','Link Administration - Leave Allocation','All','13210010','13210011','Leisure Administration Operating','Leisure Services','Operating Expenditure','Operating'),
  172.             ('Column_009','J03','WHS - Leave Allocation','All','10222210','10222211','Occupation Health & Safety','Corporate','Operating Expenditure','Staff Costs'),
  173.             ('Column_010','J04','Financial Services - Leave Allocation','All','10215011','10215011','Financial Services','','',''),
  174.             ('Column_011','J05','Customer Service - Leave Allocation','All','10219191','10219191','Customer Service','','',''),
  175.             ('Column_012','J06','GIS & Asset Management - Leave Allocation','All','14215091','14215091','Salaries','Corporate','Operating Expenditure','Staff Costs'),
  176.             ('Column_013','J07','N/A','All','','','','','',''),
  177.             ('Column_014','J08','Community Forums - Leave Allocation','All','11210120','11210121','Community Forums Expenses','','',''),
  178.             ('Column_015','J09','Sport & Recreation Dev - Leave Allocation','All','11210420','11210421','Sport & Recreation Development','','',''),
  179.             ('Column_016','J10','Governance - Leave Allocation','Council','10219070','10219071','Elected Members Running Expenses','Corporate','Operating Expenditure','Corporate Operating'),
  180.             ('Column_017','J11','Services SA - Leave Allocation','Council','10220020','10220021','Services SA Expenses','Corporate','Operating Expenditure','Commercial Operating'),
  181.             ('Column_018','J12','Government Housing - Leave Allocation','Council','10220060','10220061','Government Houses Expenses','Corporate','Operating Expenditure','Commercial Operating'),
  182.             ('Column_019','J13','Information Technology - Leave Allocation','Council','10223010','10223011','Computer Maintenance & Support','Corporate','Operating Expenditure','IT Operating'),
  183.             ('Column_020','J14','Television - Leave Allocation','Council','11210240','11210241','Television Maintenance Work','Community','Operating Expenditure','Community Expenses'),
  184.             ('Column_021','J15','Business Support - Leave Allocation','Council','11210300','11210301','Business Support','Community','Operating Expenditure','Community Expenses'),
  185.             ('Column_022','J16','Tourism Support - Leave Allocation','Council','11210340','11210341','Tourism & Area Promo','Community','Operating Expenditure','Community Expenses'),
  186.             ('Column_023','J17','Youth Support - Leave Allocation','Council','11210390','11210391','Youth Development Expenses','Community','Operating Expenditure','Community Expenses'),
  187.             ('Column_024','J18','Festival Events - Leave Allocation','Council','11210010','11210011','Festivals Support','Community','Operating Expenditure','Community Expenses'),
  188.             ('Column_025','J19','Arts and Cultural Support - Leave Allocation','Council','11210030','11210031','Arts & Cultural Support','Community','Operating Expenditure','Community Expenses'),
  189.             ('Column_026','J20','Main Street Activities - Leave Allocation','Council','11210070','11210071','Main Street Activities','Community','Operating Expenditure','Community Expenses'),
  190.             ('Column_027','J21','Community Board - Leave Allocation','Council','11210100','11210101','Community Board Running Expenses','Community','Operating Expenditure','Community Expenses'),
  191.             ('Column_028','J22','Community Radio - Leave Allocation','Council','11210210','11210211','Community Radio','Community','Operating Expenditure','Community Expenses'),
  192.             ('Column_029','J23','Community Newspaper - Leave Allocation','Council','11210220','11210221','The Monitor Community Communications','Community','Operating Expenditure','Community Expenses'),
  193.             ('Column_030','J24','Community General - Leave Allocation','Council','11210280','11210281','Community Other Expenses','Community','Operating Expenditure','Community Expenses'),
  194.             ('Column_031','J25','Ovals - Leave Allocation','Council','13213030','13213031','Oval Surface Main Maintenance','Leisure Services','Operating Expenditure','Oval Expenses'),
  195.             ('Column_032','J26','Garbage Collection - Leave Allocation','Council','14210010','14210011','Residential Garbage Collection','Works','Operating Expenditure','Refuse Collection'),
  196.             ('Column_033','J27','Recycling Collection - Leave Allocation','Council','14210030','14210031','Recycling Collection','Works','Operating Expenditure','Refuse Collection'),
  197.             ('Column_034','J28','Waste Disposal - Leave Allocation','Council','14211020','14211021','Transfer Station Maintenance & Running','Works','Operating Expenditure','Waste Disposal'),
  198.             ('Column_035','J29','Street Cleaning - Leave Allocation','Council','14212010','14212011','Street Cleaning Expenses','Works','Operating Expenditure','Street Cleaning'),
  199.             ('Column_036','J30','Pest Insects - Leave Allocation','Council','14213010','14213011','Pests Insects Expenses','Works','Operating Expenditure','Other Environmental Services'),
  200.             ('Column_037','J31','Pest Plants - Leave Allocation','Council','14213020','14213021','Pests Plants Expenses','Works','Operating Expenditure','Other Environmental Services'),
  201.             ('Column_038','J32','Environment - Leave Allocation','Council','14213030','14213031','Other Environmental Expenses','Works','Operating Expenditure','Other Environmental Services'),
  202.             ('Column_039','J33','Public Conveniences - Leave Allocation','Council','14214010','14214011','Public Convenience Richardson Place','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  203.             ('Column_040','J34','Parks & Gardens - Leave Allocation','Council','14214040','14214041','Parks Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  204.             ('Column_041','J35','Playgrounds - Leave Allocation','Council','14214060','14214061','Playgrounds Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  205.             ('Column_042','J36','Golf Course - Leave Allocation','Council','14214120','14214121','Golf Club Maintenance','Works','Operating Expenditure','Parks & Gardens Maintenance'),
  206.             ('Column_043','J37','Streetscaping - Leave Allocation','Council','14215020','14215021','Streetscaping General','Works','Operating Expenditure','Streetscaping Maintenance'),
  207.             ('Column_044','J38','Tree Trim - Leave Allocation','Council','14215070','14215071','Tree Trim','Works','Operating Expenditure','Streetscaping Maintenance'),
  208.             ('Column_045','J39','Works General - Leave Allocation','Council','14215080','14215081','Other Infrastructure Expenses','Works','Operating Expenditure','Streetscaping Maintenance'),
  209.             ('Column_046','J40','Street Lighting - Leave Allocation','Council','14216010','14216011','Street Lighting Expenses','Works','Operating Expenditure','Street Lighting Expenses'),
  210.             ('Column_047','J41','Roads & Streets - Leave Allocation','Council','14217010','14217011','Seal Patching','Works','Operating Expenditure','Roads & Streets Maintenance'),
  211.             ('Column_048','J42','Footpaths - Leave Allocation','Council','14218020','14218021','General Footpaths Maintenance','Works','Operating Expenditure','Footpath Maintenance'),
  212.             ('Column_049','J43','Stormwater - Leave Allocation','Council','14219010','14219011','Stormwater Other Expenses','Works','Operating Expenditure','Stormwater Maintenance'),
  213.             ('Column_050','J44','Building - Leave Allocation','Council','15210020','15210021','Building Other Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  214.             ('Column_051','J45','Planning - Leave Allocation','Council','15210040','15210041','Town Planning Other Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  215.             ('Column_052','J46','Dogs - Leave Allocation','Council','15210100','15210101','Dog Control','Regulatory Services','Operating Expenditure','Expenses'),
  216.             ('Column_053','J47','Cats - Leave Allocation','Council','15210110','15210111','Cat Control','Regulatory Services','Operating Expenditure','Expenses'),
  217.             ('Column_054','J48','Health - Leave Allocation','Council','15210160','15210161','Health Consultants','Regulatory Services','Operating Expenditure','Expenses'),
  218.             ('Column_055','J49','Parking - Leave Allocation','Council','15210190','15210191','Parking Control','Regulatory Services','Operating Expenditure','Expenses'),
  219.             ('Column_056','J50','Other Regulatory - Leave Allocation','Council','15210200','15210201','Other Regulatory Expenses','Regulatory Services','Operating Expenditure','Expenses'),
  220.             ('Column_057','J51','Power - Leave Allocation','Council','20215010','20215011','Electricity Operating','Power','Operating Expenditure','Electricity Operating'),
  221.             ('Column_058','J52','Water - Leave Allocation','Council','30214010','30214011','Water Operating','Water','Operating Expenditure','Operating'),
  222.             ('Column_059','J53','Sewer - Leave Allocation','Council','40214010','40214011','Sewer Operating','Sewer','Operating Expenditure','Operating'),
  223.             ('Column_060','J54','N/A','Council','','','','','',''),
  224.             ('Column_061','J55','N/A','Council','','','','','',''),
  225.             ('Column_062','J56','N/A','Council','','','','','',''),
  226.             ('Column_063','J57','N/A','Council','','','','','',''),
  227.             ('Column_064','J58','N/A','Council','','','','','',''),
  228.             ('Column_065','J59','N/A','Council','','','','','',''),
  229.             ('Column_066','J60','Art Gallery - Leave Allocation','Link','12210030','12210031','Art Gallery Operating','Cultural Services','Operating Expenditure','Operating'),
  230.             ('Column_067','J61','Cafe - Leave Allocation','Link','12210040','12210041','Cafe Operating','Cultural Services','Operating Expenditure','Operating'),
  231.             ('Column_068','J62','Cinema - Leave Allocation','Link','12210050','12210051','Cinema Operating','Cultural Services','Operating Expenditure','Operating'),
  232.             ('Column_069','J63','Creche - Leave Allocation','Link','13210060','13210061','Creche Operating','Leisure Services','Operating Expenditure','Operating'),
  233.             ('Column_070','J64','Functions - Leave Allocation','Link','12210020','12210021','Functions Operating','Cultural Services','Operating Expenditure','Operating'),
  234.             ('Column_071','J65','Gym - Leave Allocation','Link','13210030','13210031','Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  235.             ('Column_072','J66','Kiosk - Leave Allocation','Link','13210020','13210021','Kiosk Operating','Leisure Services','Operating Expenditure','Operating'),
  236.             ('Column_073','J67','Leisure Events - Leave Allocation','Link','13210080','13210081','Leisure Events Operating','Leisure Services','Operating Expenditure','Operating'),
  237.             ('Column_074','J68','Library - Leave Allocation','Link','12210090','12210091','Library Operating','Cultural Services','Operating Expenditure','Operating'),
  238.             ('Column_075','J69','Nippy Gym - Leave Allocation','Link','13210070','13210071','Nippy Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  239.             ('Column_076','J70','Pool - Leave Allocation','Link','13210040','13210041','Pool Operating','Leisure Services','Operating Expenditure','Operating'),
  240.             ('Column_077','J71','Sports and Recreation - Leave Allocation','Link','13210050','13210051','Sports & Recreation Operating','Leisure Services','Operating Expenditure','Operating'),
  241.             ('Column_078','J72','Toy Library - Leave Allocation','Link','12210080','12210081','Toy Library Operating','Cultural Services','Operating Expenditure','Operating'),
  242.             ('Column_079','J73','Visitors Information Centre - Leave Allocation','Link','12210060','12210061','VIC Operating','Cultural Services','Operating Expenditure','Operating'),
  243.             ('Column_080','J74','N/A','Link','','','','','',''),
  244.             ('Column_081','J75','Meter Reading - Power - Leave Allocation','Council','50017110','50017110','Meter Reading - Power','','',''),
  245.             ('Column_082','J76','Meter Reading - Water - Leave Allocation','Council','50017110','50017110','Meter Reading - Water','','',''),
  246.  
  247.             ('Column_083','J77','Maintenance - Council Office - Leave Allocation','Link','10210010','10210011','Office Building Maintenance','','',''),
  248.             ('Column_084','J78','Maintenance - Culture Centre - Leave Allocation','Link','12211010','12211011','Cultural Centre Building Maintenance','','',''),
  249.             ('Column_085','J79','Maintennace - Leisure Centre - Leave Allocation','Link','13211010','13211011','Leisure Centre Building Maintenance','','',''),
  250.             ('Column_086','J80','Maintenance - Other Buildings - Leave Allocation','Link','10211070','10211071','Other Building Maintenance','','',''),
  251.  
  252.             ('Column_087','J81','Special - Group Fitness - Leave Allocation','Link','13210030','13210031','Gym Operating','Leisure Services','Operating Expenditure','Operating'),
  253.             ('Column_088','J82','Special - Swim School - Leave Allocation','Link','13210040','13210041','Pool Operating','Leisure Services','Operating Expenditure','Operating'),
  254.             ('Column_089','J83','N/A','Link','','','','','',''),
  255.             ('Column_090','J84','N/A','Link','','','','','',''),
  256.             ('Column_091','J85','N/A','Link','','','','','',''),
  257.             ('Column_092','J86','N/A','Link','','','','','',''),
  258.             ('Column_093','J87','N/A','Link','','','','','',''),
  259.             ('Column_094','J88','N/A','Link','','','','','',''),
  260.             ('Column_095','J89','N/A','Link','','','','','',''),
  261.             ('Column_096','J90','N/A','Link','','','','','','')
  262.  
  263. --Declare the Table for the storage of the Job Numbers and Account
  264.     Declare
  265.         @tmp_Job_Numbers_Other table
  266.             (
  267.                 Column_Number   varchar(10),
  268.                 Job_Id          int Identity(0,1) Primary Key,
  269.                 Job_Number      varchar(10),
  270.                 Job_Name        varchar(250),
  271.                 Job_Area        varchar(250),
  272.                 Job_Account_Number_Main     varchar(10),
  273.                 Job_Account_Number_Payroll  varchar(10),
  274.                 Job_Account_Name            varchar(250),
  275.                 Job_Account_Structure_L01   varchar(250),
  276.                 Job_Account_Structure_L02   varchar(250),
  277.                 Job_Account_Structure_L03   varchar(250),
  278.                 Job_Account_Amount          money
  279.             )
  280.  
  281.     Insert Into
  282.         @tmp_Job_Numbers_Other
  283.             (
  284.                 Column_Number,
  285.                 Job_Number,
  286.                 Job_Name,
  287.                 Job_Area,
  288.                 Job_Account_Number_Main,
  289.                 Job_Account_Number_Payroll,
  290.                 Job_Account_Name,
  291.                 Job_Account_Structure_L01,
  292.                 Job_Account_Structure_L02,
  293.                 Job_Account_Structure_L03
  294.             )
  295.         Values
  296.             ('Column_006','HA','Hours for Allocation','','','','','','',''),
  297.             ('Column_007','J01','Council Corporate - Other Payments','All','10222010','10222011','Salaries','Corporate','Operating Expenditure','Staff Costs')
  298.                    
  299. --Declare Temp Table
  300.     Declare
  301.         @tmp_Fortnights table
  302.             (
  303.                 Fortnight_Id        int Identity(0,1) Primary Key,
  304.                 Fortnight_Financial_Year    varchar(10),
  305.                 Fortnight_Number    varchar(10),
  306.                 Fortnight_Start smalldatetime,
  307.                 Fortnight_Finish    smalldatetime
  308.             )
  309.     Insert Into
  310.         @tmp_Fortnights
  311.             (
  312.                 Fortnight_Financial_Year,
  313.                 Fortnight_Number,
  314.                 Fortnight_Start,
  315.                 Fortnight_Finish
  316.             )
  317.         Values
  318.             --('2015-2016','FT-00','2015-06-11','2015-06-24'),
  319.             --('2015-2016','FT-01','2015-06-25','2015-07-08'),
  320.             --('2015-2016','FT-02','2015-07-09','2015-07-22'),
  321.             --('2015-2016','FT-03','2015-07-23','2015-08-05'),
  322.             --('2015-2016','FT-04','2015-08-06','2015-08-19'),
  323.             --('2015-2016','FT-05','2015-08-20','2015-09-02'),
  324.             --('2015-2016','FT-06','2015-09-03','2015-09-16'),
  325.             --('2015-2016','FT-07','2015-09-17','2015-09-30'),
  326.             --('2015-2016','FT-08','2015-10-01','2015-10-14'),
  327.             --('2015-2016','FT-09','2015-10-15','2015-10-28'),
  328.             --('2015-2016','FT-10','2015-10-29','2015-11-11'),
  329.             --('2015-2016','FT-11','2015-11-12','2015-11-25'),
  330.             --('2015-2016','FT-12','2015-11-26','2015-12-09'),
  331.             --('2015-2016','FT-13','2015-12-10','2015-12-23'),
  332.             --('2015-2016','FT-14','2015-12-24','2016-01-06'),
  333.             --('2015-2016','FT-15','2016-01-07','2016-01-20'),
  334.             --('2015-2016','FT-16','2016-01-21','2016-02-03'),
  335.             --('2015-2016','FT-17','2016-02-04','2016-02-17'),
  336.             --('2015-2016','FT-18','2016-02-18','2016-03-02'),
  337.             --('2015-2016','FT-19','2016-03-03','2016-03-16'),
  338.             --('2015-2016','FT-20','2016-03-17','2016-03-30'),
  339.             --('2015-2016','FT-21','2016-03-31','2016-04-13'),
  340.             --('2015-2016','FT-22','2016-04-14','2016-04-27'),
  341.             --('2015-2016','FT-23','2016-04-28','2016-05-11'),
  342.             --('2015-2016','FT-24','2016-05-12','2016-05-25'),
  343.             --('2015-2016','FT-25','2016-05-26','2016-06-08'),
  344.             --('2015-2016','FT-26','2016-06-09','2016-06-22'),
  345.             --('2016-2017','FT-00','2016-06-09','2016-06-22'),
  346.             --('2016-2017','FT-01','2016-06-23','2016-07-06'),
  347.             --('2016-2017','FT-02','2016-07-07','2016-07-20'),
  348.             --('2016-2017','FT-03','2016-07-21','2016-08-03'),
  349.             --('2016-2017','FT-04','2016-08-04','2016-08-17'),
  350.             --('2016-2017','FT-05','2016-08-18','2016-08-31'),
  351.             --('2016-2017','FT-06','2016-09-01','2016-09-14'),
  352.             --('2016-2017','FT-07','2016-09-15','2016-09-28'),
  353.             --('2016-2017','FT-08','2016-09-29','2016-10-12'),
  354.             --('2016-2017','FT-09','2016-10-13','2016-10-26'),
  355.             --('2016-2017','FT-10','2016-10-27','2016-11-09'),
  356.             --('2016-2017','FT-11','2016-11-10','2016-11-23'),
  357.             --('2016-2017','FT-12','2016-11-24','2016-12-07'),
  358.             --('2016-2017','FT-13','2016-12-08','2016-12-21'),
  359.             --('2016-2017','FT-14','2016-12-22','2017-01-04'),
  360.             --('2016-2017','FT-15','2017-01-05','2017-01-18'),
  361.             --('2016-2017','FT-16','2017-01-19','2017-02-01'),
  362.             --('2016-2017','FT-17','2017-02-02','2017-02-15'),
  363.             --('2016-2017','FT-18','2017-02-16','2017-03-01'),
  364.             --('2016-2017','FT-19','2017-03-02','2017-03-15'),
  365.             --('2016-2017','FT-20','2017-03-16','2017-03-29'),
  366.             --('2016-2017','FT-21','2017-03-30','2017-04-12'),
  367.             --('2016-2017','FT-22','2017-04-13','2017-04-26'),
  368.             --('2016-2017','FT-23','2017-04-27','2017-05-10'),
  369.             --('2016-2017','FT-24','2017-05-11','2017-05-24'),
  370.             --('2016-2017','FT-25','2017-05-25','2017-06-07'),
  371.             --('2016-2017','FT-26','2017-06-08','2017-06-21')
  372.             --('2017-2018','FT-00','2017-06-08','2017-06-21'),
  373.             --('2017-2018','FT-01','2017-06-22','2017-07-05'),
  374.             --('2017-2018','FT-02','2017-07-06','2017-07-19'),
  375.             --('2017-2018','FT-03','2017-07-20','2017-08-02'),
  376.             --('2017-2018','FT-04','2017-08-03','2017-08-16'),
  377.             --('2017-2018','FT-05','2017-08-17','2017-08-30'),
  378.             --('2017-2018','FT-06','2017-08-31','2017-09-13'),
  379.             --('2017-2018','FT-07','2017-09-14','2017-09-27'),
  380.             --('2017-2018','FT-08','2017-09-28','2017-10-11'),
  381.             --('2017-2018','FT-09','2017-10-12','2017-10-25'),
  382.             --('2017-2018','FT-10','2017-10-26','2017-11-08'),
  383.             --('2017-2018','FT-11','2017-11-09','2017-11-22'),
  384.             --('2017-2018','FT-12','2017-11-23','2017-12-06'),
  385.             --('2017-2018','FT-13','2017-12-07','2017-12-20'),
  386.             --('2017-2018','FT-14','2017-12-21','2018-01-03'),
  387.             --('2017-2018','FT-15','2018-01-04','2018-01-17'),
  388.             --('2017-2018','FT-16','2018-01-18','2018-01-31'),
  389.             --('2017-2018','FT-17','2018-02-01','2018-02-14'),
  390.             --('2017-2018','FT-18','2018-02-15','2018-02-28'),
  391.             --('2017-2018','FT-19','2018-03-01','2018-03-14'),
  392.             --('2017-2018','FT-20','2018-03-15','2018-03-28'),
  393.             --('2017-2018','FT-21','2018-03-29','2018-04-11'),
  394.             --('2017-2018','FT-22','2018-04-12','2018-04-25'),
  395.             --('2017-2018','FT-23','2018-04-26','2018-05-09'),
  396.             --('2017-2018','FT-24','2018-05-10','2018-05-23'),
  397.             --('2017-2018','FT-25','2018-05-24','2018-06-06'),
  398.             --('2017-2018','FT-26','2018-06-07','2018-06-20')
  399.             ('2018-2019','FT-00','2018-06-07','2018-06-20'),
  400.             ('2018-2019','FT-01','2018-06-21','2018-07-04'),
  401.             ('2018-2019','FT-02','2018-07-05','2018-07-18'),
  402.             ('2018-2019','FT-03','2018-07-19','2018-08-01'),
  403.             ('2018-2019','FT-04','2018-08-02','2018-08-15'),
  404.             ('2018-2019','FT-05','2018-08-16','2018-08-29'),
  405.             ('2018-2019','FT-06','2018-08-30','2018-09-12'),
  406.             ('2018-2019','FT-07','2018-09-13','2018-09-26'),
  407.             ('2018-2019','FT-08','2018-09-27','2018-10-10'),
  408.             ('2018-2019','FT-09','2018-10-11','2018-10-24'),
  409.             ('2018-2019','FT-10','2018-10-25','2018-11-07'),
  410.             ('2018-2019','FT-11','2018-11-08','2018-11-21'),
  411.             ('2018-2019','FT-12','2018-11-22','2018-12-05'),
  412.             ('2018-2019','FT-13','2018-12-06','2018-12-19'),
  413.             ('2018-2019','FT-14','2018-12-20','2019-01-02'),
  414.             ('2018-2019','FT-15','2019-01-03','2019-01-16'),
  415.             ('2018-2019','FT-16','2019-01-17','2019-01-30'),
  416.             ('2018-2019','FT-17','2019-01-31','2019-02-13'),
  417.             ('2018-2019','FT-18','2019-02-14','2019-02-27'),
  418.             ('2018-2019','FT-19','2019-02-28','2019-03-13'),
  419.             ('2018-2019','FT-20','2019-03-14','2019-03-27'),
  420.             ('2018-2019','FT-21','2019-03-28','2019-04-10'),
  421.             ('2018-2019','FT-22','2019-04-11','2019-04-24'),
  422.             ('2018-2019','FT-23','2019-04-25','2019-05-08'),
  423.             ('2018-2019','FT-24','2019-05-09','2019-05-22'),
  424.             ('2018-2019','FT-25','2019-05-23','2019-06-05'),
  425.             ('2018-2019','FT-26','2019-06-06','2019-06-19')
  426.  
  427. --Ok now go and correct the date and time to
  428.     Update
  429.         @tmp_Fortnights
  430.             Set
  431.                 Fortnight_Finish = dateadd(MINUTE, -1, dateadd(DAY, 1, Fortnight_Finish))
  432.  
  433. --Decare the report FT
  434.     Declare @Report_Fortnight_Id int = (Select Fortnight_Id From @tmp_Fortnights Where Fortnight_Number = @Report_Fortnight_Number)
  435.  
  436. --Drop off the Import Table
  437.     If object_id('dbo.RDC_Payroll_Allocation_Import') IS NOT NULL
  438.         Begin
  439.             Truncate Table dbo.RDC_Payroll_Allocation_Import
  440.         End
  441.  
  442.     If OBJECT_ID('tempdb..#RDC_sp_Payroll_Employee_Job') IS NOT NULL
  443.         Begin
  444.             Drop Table #RDC_sp_Payroll_Employee_Job
  445.         End
  446.  
  447.     If OBJECT_ID('tempdb..#RDC_sp_Payroll_Employee_Payrun') IS NOT NULL
  448.         Begin
  449.             Drop Table #RDC_sp_Payroll_Employee_Payrun
  450.         End
  451.        
  452. --Import RD_Payroll_Allocation_Import */
  453.     Declare     @iS_Input_Table_Name                varchar(MAX)    = 'RDC_Payroll_Allocation_Import',
  454.                 @iS_Input_Table_Column_Count        int             = 96,
  455.                 @iS_Input_File_Path_Name            varchar(MAX)    = 'C:\Temp\RDC_Payroll_Allocation_Import.txt'
  456.  
  457.     Execute dbo.iS_procedure_Import_Bulk @iS_Input_Table_Name, @iS_Input_Table_Column_Count, @iS_Input_File_Path_Name --Perform the procedure
  458. --Now go an create the temp tables
  459.     Create Table
  460.         #RDC_sp_Payroll_Employee_Job
  461.             (
  462.                 Emyploee_Job_Id int Identity(1,1) Primary Key,
  463.                 Fortnight_Id    int,
  464.                 Employee_Id     int,
  465.                 Employee_Number int,
  466.                 Job_Id          int,
  467.                 Job_Allocation_Hours        decimal(38,2)   default(0),
  468.                 Job_Allocation_Percent      decimal(38,8)   default(0),
  469.                 Job_Allocation_Amount       money   default(0),
  470.                 Job_Budget_Percent          decimal(38,8)   default(0),
  471.                 Job_Budget_Amount           money   default(0),
  472.                 Job_Other_Amount            money   default(0),
  473.                 Job_Total_Amount            As convert(money,
  474.                                                 (
  475.                                                     round(Job_Allocation_Amount + Job_Budget_Amount + Job_Other_Amount,2)
  476.                                                 ))
  477.             )
  478.     Create Table
  479.         #RDC_sp_Payroll_Employee_Payrun
  480.             (
  481.                 Employee_Payrun_Id  int Identity(1,1) Primary Key,
  482.                 Fortnight_Id    int,
  483.                 Employee_Id     int,
  484.                 Payrun_Amount_Salaries          money default(0),
  485.                 Payrun_Amount_Allowances        money default(0),
  486.                 Payrun_Amount_Leave             money default(0),
  487.                 Payrun_Amount_Superannuation    money default(0),
  488.                
  489.                 Payrun_Amount_Other             money default(0),
  490.                
  491.                 Payrun_Allocation_Amount        As convert(money,
  492.                                                     (
  493.                                                         Case
  494.                                                             When (Payrun_Amount_Salaries = 0)
  495.                                                                 Then (0)
  496.                                                                 Else round((Payrun_Amount_Salaries + ((Payrun_Amount_Allowances + Payrun_Amount_Superannuation) * (Payrun_Amount_Salaries / (Payrun_Amount_Salaries + Payrun_Amount_Leave)))),2)
  497.                                                                 End
  498.                                                     )),
  499.                 Payrun_Budget_Amount            As convert(money,
  500.                                                     (
  501.                                                         Case
  502.                                                             When (Payrun_Amount_Leave = 0)
  503.                                                                 Then
  504.                                                                     (
  505.                                                                         Case
  506.                                                                             When (Payrun_Amount_Salaries = 0)
  507.                                                                             Then (Payrun_Amount_Salaries + Payrun_Amount_Allowances + Payrun_Amount_Leave + Payrun_Amount_Superannuation)
  508.                                                                             Else (0)
  509.                                                                             End
  510.                                                                     )
  511.                                                                 Else
  512.                                                                     (
  513.                                                                         --Case
  514.                                                                             --When (Payrun_Amount_Salaries = 0)
  515.                                                                             --Then (Payrun_Amount_Salaries + Payrun_Amount_Allowances + Payrun_Amount_Leave + Payrun_Amount_Superannuation)
  516.                                                                             --Else (
  517.                                                                             round((Payrun_Amount_Leave + ((Payrun_Amount_Allowances + Payrun_Amount_Superannuation) * (Payrun_Amount_Leave / (Payrun_Amount_Salaries + Payrun_Amount_Leave)))),2)
  518.                                                                             --)
  519.                                                                             --End
  520.                                                                     )
  521.                                                                 End
  522.                                                     ))
  523.                
  524.             )
  525. --Now go and insert the data
  526.     Insert Into
  527.         #RDC_sp_Payroll_Employee_Job
  528.             (
  529.                 Fortnight_Id,
  530.                 Employee_Id,
  531.                 Employee_Number,
  532.                 Job_Id,
  533.                 Job_Allocation_Hours
  534.             )
  535.         Select
  536.             tmp_Fortnights.Fortnight_Id As Fortnight_Id,
  537.             tmp_Employee.EmployeeID     As Employee_Id,
  538.             tmp_Import.Staff_Number     As Employee_Number,
  539.             tmp_Job_Numbers.Job_Id      As Job_Id,
  540.             tmp_Import.Column_Details   As Job_Hours
  541.             From
  542.                 (
  543.                     Select
  544.                         ID          As Import_Id,
  545.                         --Column_001,
  546.                         --Column_002,
  547.                         Column_003  As Staff_Number,
  548.                         Column_004  As Staff_Name,
  549.                         Column_005  As Fortnight_Number,
  550.                         tmp_Unpivot.Column_Number,
  551.                         tmp_Unpivot.Column_Details
  552.                         From
  553.                             dbo.RDC_Payroll_Allocation_Import
  554.                             Unpivot
  555.                                 (
  556.                                     Column_Details
  557.                                         For Column_Number
  558.                                         In
  559.                                                 (
  560.                                                     Column_006,
  561.                                                     Column_007,
  562.                                                     Column_008,
  563.                                                     Column_009,
  564.                                                     Column_010,
  565.                                                     Column_011,
  566.                                                     Column_012,
  567.                                                     Column_013,
  568.                                                     Column_014,
  569.                                                     Column_015,
  570.                                                     Column_016,
  571.                                                     Column_017,
  572.                                                     Column_018,
  573.                                                     Column_019,
  574.                                                     Column_020,
  575.                                                     Column_021,
  576.                                                     Column_022,
  577.                                                     Column_023,
  578.                                                     Column_024,
  579.                                                     Column_025,
  580.                                                     Column_026,
  581.                                                     Column_027,
  582.                                                     Column_028,
  583.                                                     Column_029,
  584.                                                     Column_030,
  585.                                                     Column_031,
  586.                                                     Column_032,
  587.                                                     Column_033,
  588.                                                     Column_034,
  589.                                                     Column_035,
  590.                                                     Column_036,
  591.                                                     Column_037,
  592.                                                     Column_038,
  593.                                                     Column_039,
  594.                                                     Column_040,
  595.                                                     Column_041,
  596.                                                     Column_042,
  597.                                                     Column_043,
  598.                                                     Column_044,
  599.                                                     Column_045,
  600.                                                     Column_046,
  601.                                                     Column_047,
  602.                                                     Column_048,
  603.                                                     Column_049,
  604.                                                     Column_050,
  605.                                                     Column_051,
  606.                                                     Column_052,
  607.                                                     Column_053,
  608.                                                     Column_054,
  609.                                                     Column_055,
  610.                                                     Column_056,
  611.                                                     Column_057,
  612.                                                     Column_058,
  613.                                                     Column_059,
  614.                                                     Column_060,
  615.                                                     Column_061,
  616.                                                     Column_062,
  617.                                                     Column_063,
  618.                                                     Column_064,
  619.                                                     Column_065,
  620.                                                     Column_066,
  621.                                                     Column_067,
  622.                                                     Column_068,
  623.                                                     Column_069,
  624.                                                     Column_070,
  625.                                                     Column_071,
  626.                                                     Column_072,
  627.                                                     Column_073,
  628.                                                     Column_074,
  629.                                                     Column_075,
  630.                                                     Column_076,
  631.                                                     Column_077,
  632.                                                     Column_078,
  633.                                                     Column_079,
  634.                                                     Column_080,
  635.                                                     Column_081,
  636.                                                     Column_082,
  637.                                                     Column_083,
  638.                                                     Column_084,
  639.                                                     Column_085,
  640.                                                     Column_086,
  641.                                                     Column_087,
  642.                                                     Column_088,
  643.                                                     Column_089,
  644.                                                     Column_090,
  645.                                                     Column_091,
  646.                                                     Column_092,
  647.                                                     Column_093,
  648.                                                     Column_094,
  649.                                                     Column_095,
  650.                                                     Column_096
  651.                                                 )  
  652.                                 ) tmp_Unpivot
  653.                         Where ID != 0
  654.                 ) tmp_Import
  655.                     Left Join @tmp_Fortnights tmp_Fortnights On tmp_Import.Fortnight_Number = tmp_Fortnights.Fortnight_Number
  656.                     Inner Join @tmp_Job_Numbers tmp_Job_Numbers On tmp_Import.Column_Number = tmp_Job_Numbers.Column_Number
  657.                     Left Join dbo.Employee tmp_Employee On tmp_Import.Staff_Number = tmp_Employee.Number
  658. --Temp Fix for Budget Allocation
  659.     Declare @tmp_Employee_Budget table
  660.         (
  661.             Employee_Budget_Id int Identity(1,1) Primary Key,
  662.             Employee_Name   varchar(250),
  663.             Employee_Number int,
  664.             J01 decimal(38,8),
  665.             J02 decimal(38,8),
  666.             J03 decimal(38,8),
  667.             J04 decimal(38,8),
  668.             J05 decimal(38,8),
  669.             J06 decimal(38,8),
  670.             J07 decimal(38,8),
  671.             J08 decimal(38,8),
  672.             J09 decimal(38,8),
  673.             J10 decimal(38,8),
  674.             J11 decimal(38,8),
  675.             J12 decimal(38,8),
  676.             J13 decimal(38,8),
  677.             J14 decimal(38,8),
  678.             J15 decimal(38,8),
  679.             J16 decimal(38,8),
  680.             J17 decimal(38,8),
  681.             J18 decimal(38,8),
  682.             J19 decimal(38,8),
  683.             J20 decimal(38,8),
  684.             J21 decimal(38,8),
  685.             J22 decimal(38,8),
  686.             J23 decimal(38,8),
  687.             J24 decimal(38,8),
  688.             J25 decimal(38,8),
  689.             J26 decimal(38,8),
  690.             J27 decimal(38,8),
  691.             J28 decimal(38,8),
  692.             J29 decimal(38,8),
  693.             J30 decimal(38,8),
  694.             J31 decimal(38,8),
  695.             J32 decimal(38,8),
  696.             J33 decimal(38,8),
  697.             J34 decimal(38,8),
  698.             J35 decimal(38,8),
  699.             J36 decimal(38,8),
  700.             J37 decimal(38,8),
  701.             J38 decimal(38,8),
  702.             J39 decimal(38,8),
  703.             J40 decimal(38,8),
  704.             J41 decimal(38,8),
  705.             J42 decimal(38,8),
  706.             J43 decimal(38,8),
  707.             J44 decimal(38,8),
  708.             J45 decimal(38,8),
  709.             J46 decimal(38,8),
  710.             J47 decimal(38,8),
  711.             J48 decimal(38,8),
  712.             J49 decimal(38,8),
  713.             J50 decimal(38,8),
  714.             J51 decimal(38,8),
  715.             J52 decimal(38,8),
  716.             J53 decimal(38,8),
  717.             J54 decimal(38,8),
  718.             J55 decimal(38,8),
  719.             J56 decimal(38,8),
  720.             J57 decimal(38,8),
  721.             J58 decimal(38,8),
  722.             J59 decimal(38,8),
  723.             J60 decimal(38,8),
  724.             J61 decimal(38,8),
  725.             J62 decimal(38,8),
  726.             J63 decimal(38,8),
  727.             J64 decimal(38,8),
  728.             J65 decimal(38,8),
  729.             J66 decimal(38,8),
  730.             J67 decimal(38,8),
  731.             J68 decimal(38,8),
  732.             J69 decimal(38,8),
  733.             J70 decimal(38,8),
  734.             J71 decimal(38,8),
  735.             J72 decimal(38,8),
  736.             J73 decimal(38,8),
  737.             J74 decimal(38,8),
  738.             J75 decimal(38,8),
  739.             J76 decimal(38,8),
  740.             J77 decimal(38,8),
  741.             J78 decimal(38,8),
  742.             J79 decimal(38,8),
  743.             J80 decimal(38,8)
  744.         )
  745.  
  746.     Insert Into
  747.         @tmp_Employee_Budget
  748.             (
  749.                 Employee_Name,
  750.                 Employee_Number,
  751.                 J01,
  752.                 J02,
  753.                 J03,
  754.                 J04,
  755.                 J05,
  756.                 J06,
  757.                 J07,
  758.                 J08,
  759.                 J09,
  760.                 J10,
  761.                 J11,
  762.                 J12,
  763.                 J13,
  764.                 J14,
  765.                 J15,
  766.                 J16,
  767.                 J17,
  768.                 J18,
  769.                 J19,
  770.                 J20,
  771.                 J21,
  772.                 J22,
  773.                 J23,
  774.                 J24,
  775.                 J25,
  776.                 J26,
  777.                 J27,
  778.                 J28,
  779.                 J29,
  780.                 J30,
  781.                 J31,
  782.                 J32,
  783.                 J33,
  784.                 J34,
  785.                 J35,
  786.                 J36,
  787.                 J37,
  788.                 J38,
  789.                 J39,
  790.                 J40,
  791.                 J41,
  792.                 J42,
  793.                 J43,
  794.                 J44,
  795.                 J45,
  796.                 J46,
  797.                 J47,
  798.                 J48,
  799.                 J49,
  800.                 J50,
  801.                 J51,
  802.                 J52,
  803.                 J53,
  804.                 J54,
  805.                 J55,
  806.                 J56,
  807.                 J57,
  808.                 J58,
  809.                 J59,
  810.                 J60,
  811.                 J61,
  812.                 J62,
  813.                 J63,
  814.                 J64,
  815.                 J65,
  816.                 J66,
  817.                 J67,
  818.                 J68,
  819.                 J69,
  820.                 J70,
  821.                 J71,
  822.                 J72,
  823.                 J73,
  824.                 J74,
  825.                 J75,
  826.                 J76,
  827.                 J77,
  828.                 J78,
  829.                 J79,
  830.                 J80
  831.             )
  832.         Values
  833.  
  834. ('Alicia Lee',139,0,0.84,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.16,0,0,0,0,0,0,0,0,0,0),
  835. ('Allie Thomas',98,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  836. ('Amanda Astri',231,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  837. ('Anjana Prajapati',241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0),
  838. ('Anni Giles',99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.03,0,0,0,0,0,0,0,0.26,0,0.71,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  879. ('Stuart Edwards',235,0.45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.22,0.22,0.11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  880. ('David Williams',263,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.25,0.25,0.25,0.25),
  881. ('Michelle Smith',201,0,0,0,0,0,0,0,0.2,0.8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  882. ('Rebecca Mackey',272,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
  883. ('Dandong Zheng',261,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
  884.  
  885.     Update
  886.         #RDC_sp_Payroll_Employee_Job
  887.             Set
  888.                 Job_Budget_Percent = isnull(tmp_Employee_Budget.Job_Percent,0)
  889.             From
  890.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  891.                     Inner Join @tmp_Job_Numbers tmp_Job_Numbers On tmp_Employee_Job.Job_Id = tmp_Job_Numbers.Job_Id
  892.                         Outer Apply
  893.                             (
  894.                             Select
  895.                                 *
  896.                                 From
  897.                                     (
  898.                                     Select
  899.                                         tmp_Employee.EmployeeID,
  900.                                         tmp_UnPivot.*
  901.                                         From
  902.                                             @tmp_Employee_Budget
  903.                                             Unpivot
  904.                                                 (
  905.                                                     Job_Percent
  906.                                                         For Job_Number
  907.                                                         In
  908.                                                                 (
  909.                                                                     J01,
  910.                                                                     J02,
  911.                                                                     J03,
  912.                                                                     J04,
  913.                                                                     J05,
  914.                                                                     J06,
  915.                                                                     J07,
  916.                                                                     J08,
  917.                                                                     J09,
  918.                                                                     J10,
  919.                                                                     J11,
  920.                                                                     J12,
  921.                                                                     J13,
  922.                                                                     J14,
  923.                                                                     J15,
  924.                                                                     J16,
  925.                                                                     J17,
  926.                                                                     J18,
  927.                                                                     J19,
  928.                                                                     J20,
  929.                                                                     J21,
  930.                                                                     J22,
  931.                                                                     J23,
  932.                                                                     J24,
  933.                                                                     J25,
  934.                                                                     J26,
  935.                                                                     J27,
  936.                                                                     J28,
  937.                                                                     J29,
  938.                                                                     J30,
  939.                                                                     J31,
  940.                                                                     J32,
  941.                                                                     J33,
  942.                                                                     J34,
  943.                                                                     J35,
  944.                                                                     J36,
  945.                                                                     J37,
  946.                                                                     J38,
  947.                                                                     J39,
  948.                                                                     J40,
  949.                                                                     J41,
  950.                                                                     J42,
  951.                                                                     J43,
  952.                                                                     J44,
  953.                                                                     J45,
  954.                                                                     J46,
  955.                                                                     J47,
  956.                                                                     J48,
  957.                                                                     J49,
  958.                                                                     J50,
  959.                                                                     J51,
  960.                                                                     J52,
  961.                                                                     J53,
  962.                                                                     J54,
  963.                                                                     J55,
  964.                                                                     J56,
  965.                                                                     J57,
  966.                                                                     J58,
  967.                                                                     J59,
  968.                                                                     J60,
  969.                                                                     J61,
  970.                                                                     J62,
  971.                                                                     J63,
  972.                                                                     J64,
  973.                                                                     J65,
  974.                                                                     J66,
  975.                                                                     J67,
  976.                                                                     J68,
  977.                                                                     J69,
  978.                                                                     J70,
  979.                                                                     J71,
  980.                                                                     J72,
  981.                                                                     J73,
  982.                                                                     J74,
  983.                                                                     J75,
  984.                                                                     J76,
  985.                                                                     J77,
  986.                                                                     J78,
  987.                                                                     J79,
  988.                                                                     J80
  989.                                                                 )
  990.                                                 ) tmp_UnPivot
  991.                                             Inner Join dbo.Employee tmp_Employee On tmp_UnPivot.Employee_Number = tmp_Employee.Number
  992.                                 ) tmp_Employee_Budget
  993.                             Where
  994.                                 tmp_Employee_Budget.EmployeeID = tmp_Employee_Job.Employee_Id
  995.                                 And tmp_Employee_Budget.Job_Number = tmp_Job_Numbers.Job_Number
  996.                                
  997.                     ) tmp_Employee_Budget
  998.  
  999. --Now go and get the payrun summary for fortnights
  1000.     Insert Into
  1001.         #RDC_sp_Payroll_Employee_Payrun
  1002.             (
  1003.                 Fortnight_Id,
  1004.                 Employee_Id,
  1005.                 Payrun_Amount_Salaries,
  1006.                 Payrun_Amount_Allowances,
  1007.                 Payrun_Amount_Leave,
  1008.                 Payrun_Amount_Superannuation,
  1009.                 Payrun_Amount_Other
  1010.             )
  1011.         Select
  1012.             tmp_Fortnights.Fortnight_Id,
  1013.             tmp_Employee_Payrun.EmployeeID,
  1014.             tmp_Employee_Payrun.Payrun_Amount_Salaries,
  1015.             tmp_Employee_Payrun.Payrun_Amount_Allowances,
  1016.             tmp_Employee_Payrun.Payrun_Amount_Leave,
  1017.             tmp_Employee_Payrun.Payrun_Amount_Superannuation,
  1018.             tmp_Employee_Payrun.Payrun_Amount_Other
  1019.             From
  1020.                 @tmp_Fortnights tmp_Fortnights
  1021.                     Outer Apply
  1022.                         (
  1023.                             Select
  1024.                                 EmployeeID,
  1025.                                 sum(Payrun_Amount_Salaries)         As Payrun_Amount_Salaries,
  1026.                                 sum(Payrun_Amount_Allowances)       As Payrun_Amount_Allowances,
  1027.                                 sum(Payrun_Amount_Leave)            As Payrun_Amount_Leave,
  1028.                                 sum(Payrun_Amount_Superannuation)   As Payrun_Amount_Superannuation,
  1029.                                 sum(Payrun_Amount_Other)            As Payrun_Amount_Other
  1030.                                 From
  1031.                                     (
  1032.                                         Select
  1033.                                             tmp_Payrun.PayrunID,                           
  1034.                                             tmp_Employee.EmployeeID,
  1035.                                             isnull(tmp_Payrun_Salaries.Amount,0)        As Payrun_Amount_Salaries,
  1036.                                             isnull(tmp_Payrun_Allowances.Amount,0)      As Payrun_Amount_Allowances,
  1037.                                             isnull(tmp_Payrun_Leave.Amount,0)           As Payrun_Amount_Leave,
  1038.                                             isnull(tmp_Payrun_Superannuation.Amount,0)  As Payrun_Amount_Superannuation,
  1039.                                             isnull(tmp_Payrun_Other.Amount,0)           As Payrun_Amount_Other 
  1040.                                             From
  1041.                                                 dbo.Payrun tmp_Payrun
  1042.                                                     Inner Join dbo.EmployeePayrun tmp_Employee_Payrun On tmp_Payrun.PayrunID = tmp_Employee_Payrun.PayrunID
  1043.                                                         Inner Join dbo.Employee tmp_Employee On tmp_Employee_Payrun.EmployeeID = tmp_Employee.EmployeeID
  1044.                                                         Outer Apply
  1045.                                                             (
  1046.                                                                 Select
  1047.                                                                     sum(Amount) As Amount
  1048.                                                                     From
  1049.                                                                         dbo.PayrunDetails tmp_Payrun_Details
  1050.                                                                     Where
  1051.                                                                         tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1052.                                                                         And tmp_Payrun_Details.Type = 0
  1053.                                                                         And tmp_Payrun.Type = 0
  1054.                                                             ) tmp_Payrun_Salaries
  1055.                                                         Outer Apply
  1056.                                                             (
  1057.                                                                 Select
  1058.                                                                     sum(Amount) As Amount
  1059.                                                                     From
  1060.                                                                         dbo.PayrunDetails tmp_Payrun_Details
  1061.                                                                     Where
  1062.                                                                         tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1063.                                                                         And tmp_Payrun_Details.Type = 2
  1064.                                                                         And tmp_Payrun.Type = 0
  1065.                                                             ) tmp_Payrun_Allowances
  1066.                                                         Outer Apply
  1067.                                                             (
  1068.                                                                 Select
  1069.                                                                     sum(Amount) As Amount
  1070.                                                                     From
  1071.                                                                         dbo.PayrunDetails tmp_Payrun_Details
  1072.                                                                     Where
  1073.                                                                         tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1074.                                                                         And tmp_Payrun_Details.Type = 3
  1075.                                                                         And tmp_Payrun.Type = 0
  1076.                                                             ) tmp_Payrun_Leave
  1077.                                                         Outer Apply
  1078.                                                             (
  1079.                                                                 Select
  1080.                                                                     sum(Amount) As Amount
  1081.                                                                     From
  1082.                                                                         dbo.PayrunDetails tmp_Payrun_Details
  1083.                                                                     Where
  1084.                                                                         tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1085.                                                                         And tmp_Payrun_Details.Type = 9
  1086.                                                                         And tmp_Payrun.Type = 0
  1087.                                                             ) tmp_Payrun_Superannuation
  1088.                                                         Outer Apply
  1089.                                                             (
  1090.                                                                 Select
  1091.                                                                     sum(Amount) As Amount
  1092.                                                                     From
  1093.                                                                         dbo.PayrunDetails tmp_Payrun_Details
  1094.                                                                     Where
  1095.                                                                         tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1096.                                                                         And tmp_Payrun_Details.Type In (0,2,3,9)
  1097.                                                                         And tmp_Payrun.Type != 0
  1098.                                                             ) tmp_Payrun_Other
  1099.                                             Where
  1100.                                                 tmp_Payrun.PayrunBeginning >= tmp_Fortnights.Fortnight_Start
  1101.                                                 And tmp_Payrun.PayrunEnding <= tmp_Fortnights.Fortnight_Finish
  1102.                                     ) tmp_Employee_Payrun
  1103.                                         Group By
  1104.                                             EmployeeID
  1105.                         ) tmp_Employee_Payrun
  1106.                 Where
  1107.                     tmp_Fortnights.Fortnight_Id = @Report_Fortnight_Id
  1108.                     --Where
  1109.                     --  tmp_Employee_Payrun.EmployeeID IS NOT NULL
  1110.  
  1111. --Go and catch all the employess not allocated
  1112.     Insert Into
  1113.         #RDC_sp_Payroll_Employee_Job
  1114.             (
  1115.                 Fortnight_Id,
  1116.                 Employee_Id,
  1117.                 Employee_Number,
  1118.                 Job_Id,
  1119.                 Job_Allocation_Hours,
  1120.                 Job_Allocation_Percent,
  1121.                 Job_Allocation_Amount,
  1122.                 Job_Budget_Percent,
  1123.                 Job_Budget_Amount
  1124.                
  1125.             )
  1126.     Select
  1127.         @Report_Fortnight_Id,
  1128.         tmp_Employee.EmployeeID,
  1129.         tmp_Employee.Number,
  1130.         tmp_Job_Numbers.Job_Id,
  1131.         0,
  1132.         0,
  1133.         0,
  1134.         0,
  1135.         0
  1136.         From
  1137.             (
  1138.                 Select Distinct
  1139.                     Employee_Id
  1140.                     From
  1141.                         #RDC_sp_Payroll_Employee_Payrun tmp_Payrun
  1142.                     Where
  1143.                         tmp_Payrun.Employee_Id Not In
  1144.                             (
  1145.                                 Select Distinct
  1146.                                     Employee_Id
  1147.                                     From
  1148.                                         #RDC_sp_Payroll_Employee_Job
  1149.                             )
  1150.             ) tmp_Employee_List
  1151.                 Inner Join dbo.Employee tmp_Employee On tmp_Employee_List.Employee_Id = tmp_Employee.EmployeeId
  1152.                 Outer Apply
  1153.                     (
  1154.                         Select
  1155.                             *
  1156.                             From
  1157.                                 @tmp_Job_Numbers tmp_Job_Numbers
  1158.                     ) tmp_Job_Numbers
  1159.  
  1160.  
  1161.        
  1162. --Ok new go and calculate the job number percent
  1163.     Update
  1164.         #RDC_sp_Payroll_Employee_Job
  1165.             Set
  1166.                 Job_Allocation_Percent = Job_Allocation_Hours / isnull(Job_Allocation_Hours_Sum,0)
  1167.             From
  1168.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1169.                     Outer Apply
  1170.                         (
  1171.                             Select
  1172.                                 --Fortnight_Id,
  1173.                                 --Employee_Id,
  1174.                                 isnull(sum(Job_Allocation_Hours),0) As Job_Allocation_Hours_Sum
  1175.                                 From
  1176.                                     #RDC_sp_Payroll_Employee_Job tmp_Percent
  1177.                                 Where
  1178.                                     tmp_Percent.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1179.                                     And tmp_Percent.Employee_Id = tmp_Employee_Job.Employee_Id
  1180.                                     And tmp_Percent.Job_Id != 0
  1181.                         ) tmp_Percent
  1182.             Where
  1183.                 tmp_Employee_Job.Job_Allocation_Hours != 0
  1184.                 And tmp_Percent.Job_Allocation_Hours_Sum != 0
  1185.  
  1186. --Ok we have the job numbers for budget go and update the master job number    
  1187.     Update
  1188.         #RDC_sp_Payroll_Employee_Job
  1189.             Set
  1190.                 Job_Allocation_Percent = 1 - isnull(tmp_Percent.Job_Allocation_Percent_Sum,0)
  1191.             From
  1192.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1193.                     Outer Apply
  1194.                         (
  1195.                             Select
  1196.                                 --Fortnight_Id,
  1197.                                 --Employee_Id,
  1198.                                 sum(Job_Allocation_Percent) As Job_Allocation_Percent_Sum
  1199.                                 From
  1200.                                     #RDC_sp_Payroll_Employee_Job tmp_Percent
  1201.                                 Where
  1202.                                     tmp_Percent.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1203.                                     And tmp_Percent.Employee_Id = tmp_Employee_Job.Employee_Id
  1204.                                     And tmp_Percent.Job_Id Not In (0,1)
  1205.                         ) tmp_Percent
  1206.             Where
  1207.                 tmp_Employee_Job.Job_Id = 1
  1208.  
  1209. --Ok we have the job numbers for amountsgo and update the master job number    
  1210.     Update
  1211.         #RDC_sp_Payroll_Employee_Job
  1212.             Set
  1213.                 Job_Budget_Percent = 1 - isnull(tmp_Percent.Job_Budget_Percent_Sum,0)
  1214.             From
  1215.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1216.                     Outer Apply
  1217.                         (
  1218.                             Select
  1219.                                 --Fortnight_Id,
  1220.                                 --Employee_Id,
  1221.                                 sum(Job_Budget_Percent) As Job_Budget_Percent_Sum
  1222.                                 From
  1223.                                     #RDC_sp_Payroll_Employee_Job tmp_Percent
  1224.                                 Where
  1225.                                     tmp_Percent.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1226.                                     And tmp_Percent.Employee_Id = tmp_Employee_Job.Employee_Id
  1227.                                     And tmp_Percent.Job_Id Not In (0,1)
  1228.                         ) tmp_Percent
  1229.             Where
  1230.                 tmp_Employee_Job.Job_Id = 1
  1231.  
  1232. --Now go and update The Amounts
  1233.     Update
  1234.         #RDC_sp_Payroll_Employee_Job
  1235.             Set
  1236.                 Job_Allocation_Amount = isnull(tmp_Employee_Payrun.Job_Allocation_Amount,0),
  1237.                 Job_Budget_Amount = isnull(tmp_Employee_Payrun.Job_Budget_Amount,0)
  1238.             From
  1239.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1240.                     Outer Apply
  1241.                         (
  1242.                             Select
  1243.                                 round((tmp_Employee_Payrun.Payrun_Allocation_Amount * tmp_Employee_Job.Job_Allocation_Percent),2)   As Job_Allocation_Amount,
  1244.                                 round((tmp_Employee_Payrun.Payrun_Budget_Amount * tmp_Employee_Job.Job_Budget_Percent),2)           As Job_Budget_Amount
  1245.                                 From
  1246.                                     #RDC_sp_Payroll_Employee_Payrun tmp_Employee_Payrun
  1247.                                 Where
  1248.                                     tmp_Employee_Payrun.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1249.                                     And tmp_Employee_Payrun.Employee_Id = tmp_Employee_Job.Employee_Id
  1250.                         ) tmp_Employee_Payrun
  1251.  
  1252.  
  1253.  
  1254.  
  1255. --Now go and update The Amounts
  1256.     Update
  1257.         #RDC_sp_Payroll_Employee_Job
  1258.             Set
  1259.                 Job_Other_Amount = isnull(tmp_Employee_Payrun.Job_Other_Amount,0)
  1260.             From
  1261.                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1262.                     Outer Apply
  1263.                         (
  1264.                             Select
  1265.                                 round((tmp_Employee_Payrun.Payrun_Amount_Other),2)  As Job_Other_Amount
  1266.                                 From
  1267.                                     #RDC_sp_Payroll_Employee_Payrun tmp_Employee_Payrun
  1268.                                 Where
  1269.                                     tmp_Employee_Payrun.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1270.                                     And tmp_Employee_Payrun.Employee_Id = tmp_Employee_Job.Employee_Id
  1271.                         ) tmp_Employee_Payrun
  1272.                 Where
  1273.                     tmp_Employee_Job.Job_Id = 1
  1274.  
  1275. --Now go and select get the amounts against the accounts
  1276.     Update
  1277.         @tmp_Job_Numbers
  1278.             Set
  1279.                 Job_Account_Amount = isnull(tmp_Employee_Job.Job_Total_Amount,0)
  1280.             From
  1281.                 @tmp_Job_Numbers tmp_Job_Numbers
  1282.                 Outer Apply
  1283.                     (
  1284.                         Select
  1285.                             sum(Job_Allocation_Amount)  As Job_Allocation_Amount,
  1286.                             sum(Job_Budget_Amount)      As Job_Budget_Amount,
  1287.                             sum(Job_Total_Amount)       As Job_Total_Amount
  1288.                             From
  1289.                                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1290.                             Where
  1291.                                 tmp_Employee_Job.Job_Id = tmp_Job_Numbers.Job_Id
  1292.                                 And tmp_Employee_Job.Fortnight_Id = @Report_Fortnight_Id
  1293.                     ) tmp_Employee_Job
  1294.                    
  1295.  
  1296. --Now go and get the job number summary
  1297.     Select
  1298.         Job_Id,
  1299.         Job_Number,
  1300.         Job_Name,  
  1301.         Job_Area,
  1302.         Job_Account_Number_Main,
  1303.         Job_Account_Number_Payroll,
  1304.         Job_Account_Amount
  1305.         From
  1306.             @tmp_Job_Numbers tmp_Job_Numbers
  1307.         Where
  1308.             tmp_Job_Numbers.Job_Id != 0
  1309.         Order By
  1310.             Job_Number
  1311.            
  1312. --Now go and select the employees
  1313.     Select
  1314.         tmp_Employee.EmployeeID     As Employee_Id,
  1315.         tmp_Employee.Number         As Employee_Number,
  1316.         tmp_Employee.Name           As Employee_Name,
  1317.         tmp_Employee_Payrun.Payrun_Amount_Salaries,
  1318.         tmp_Employee_Payrun.Payrun_Amount_Allowances,
  1319.         tmp_Employee_Payrun.Payrun_Amount_Leave,
  1320.         tmp_Employee_Payrun.Payrun_Amount_Superannuation,
  1321.         tmp_Employee_Payrun.Payrun_Allocation_Amount,
  1322.         tmp_Employee_Payrun.Payrun_Budget_Amount,
  1323.         tmp_Employee_Payrun.Payrun_Amount_Other,
  1324.         tmp_Employee_Payrun.Payrun_Allocation_Amount + tmp_Employee_Payrun.Payrun_Budget_Amount + tmp_Employee_Payrun.Payrun_Amount_Other
  1325.         From
  1326.             #RDC_sp_Payroll_Employee_Payrun tmp_Employee_Payrun
  1327.                 Inner Join dbo.Employee tmp_Employee On tmp_Employee_Payrun.Employee_Id = tmp_Employee.EmployeeID
  1328.         Where
  1329.             tmp_Employee_Payrun.Fortnight_Id = @Report_Fortnight_Id
  1330.         Order By
  1331.             tmp_Employee.Number
  1332.  
  1333. --Ok now go and get the allocations for the job numbers
  1334.     Select
  1335.         tmp_Employee.EmployeeID             As Employee_Id,
  1336.         tmp_Employee.Number                 As Employee_Number,
  1337.         tmp_Employee.Name                   As Employee_Name,
  1338.                                             [J01],
  1339.                                             [J02],
  1340.                                             [J03],
  1341.                                             [J04],
  1342.                                             [J05],
  1343.                                             [J06],
  1344.                                             [J07],
  1345.                                             [J08],
  1346.                                             [J09],
  1347.                                             [J10],
  1348.                                             [J11],
  1349.                                             [J12],
  1350.                                             [J13],
  1351.                                             [J14],
  1352.                                             [J15],
  1353.                                             [J16],
  1354.                                             [J17],
  1355.                                             [J18],
  1356.                                             [J19],
  1357.                                             [J20],
  1358.                                             [J21],
  1359.                                             [J22],
  1360.                                             [J23],
  1361.                                             [J24],
  1362.                                             [J25],
  1363.                                             [J26],
  1364.                                             [J27],
  1365.                                             [J28],
  1366.                                             [J29],
  1367.                                             [J30],
  1368.                                             [J31],
  1369.                                             [J32],
  1370.                                             [J33],
  1371.                                             [J34],
  1372.                                             [J35],
  1373.                                             [J36],
  1374.                                             [J37],
  1375.                                             [J38],
  1376.                                             [J39],
  1377.                                             [J40],
  1378.                                             [J41],
  1379.                                             [J42],
  1380.                                             [J43],
  1381.                                             [J44],
  1382.                                             [J45],
  1383.                                             [J46],
  1384.                                             [J47],
  1385.                                             [J48],
  1386.                                             [J49],
  1387.                                             [J50],
  1388.                                             [J51],
  1389.                                             [J52],
  1390.                                             [J53],
  1391.                                             [J54],
  1392.                                             [J55],
  1393.                                             [J56],
  1394.                                             [J57],
  1395.                                             [J58],
  1396.                                             [J59],
  1397.                                             [J60],
  1398.                                             [J61],
  1399.                                             [J62],
  1400.                                             [J63],
  1401.                                             [J64],
  1402.                                             [J65],
  1403.                                             [J66],
  1404.                                             [J67],
  1405.                                             [J68],
  1406.                                             [J69],
  1407.                                             [J70],
  1408.                                             [J71],
  1409.                                             [J72],
  1410.                                             [J73],
  1411.                                             [J74],
  1412.                                             [J75],
  1413.                                             [J76],
  1414.                                             [J77],
  1415.                                             [J78],
  1416.                                             [J79],
  1417.                                             [J80],
  1418.                                             [J81],
  1419.                                             [J82],
  1420.                                             [J83],
  1421.                                             [J84],
  1422.                                             [J85],
  1423.                                             [J86],
  1424.                                             [J87],
  1425.                                             [J88],
  1426.                                             [J89],
  1427.                                             [J90]
  1428.         From
  1429.             (
  1430.                 Select
  1431.                     tmp_Employee_Job.Employee_Id,
  1432.                     tmp_Job_Numbers.Job_Number,
  1433.                     tmp_Employee_Job.Job_Total_Amount
  1434.                     From
  1435.                         #RDC_sp_Payroll_Employee_Payrun tmp_Employee_Payrun
  1436.                             Inner Join #RDC_sp_Payroll_Employee_Job tmp_Employee_Job On tmp_Employee_Payrun.Employee_Id = tmp_Employee_Job.Employee_Id And tmp_Employee_Payrun.Fortnight_Id = tmp_Employee_Job.Fortnight_Id
  1437.                                 Inner Join @tmp_Job_Numbers tmp_Job_Numbers On tmp_Employee_Job.Job_Id = tmp_Job_Numbers.Job_Id
  1438.                             Inner Join dbo.Employee tmp_Employee On tmp_Employee_Payrun.Employee_Id = tmp_Employee.EmployeeID
  1439.                     Where
  1440.                         tmp_Employee_Payrun.Fortnight_Id = @Report_Fortnight_Id
  1441.             ) tmp_Employee_Job
  1442.                 Pivot
  1443.                     (
  1444.                         sum(Job_Total_Amount)
  1445.                             For
  1446.                                 Job_Number
  1447.                                     In
  1448.                                         (
  1449.                                             [J01],
  1450.                                             [J02],
  1451.                                             [J03],
  1452.                                             [J04],
  1453.                                             [J05],
  1454.                                             [J06],
  1455.                                             [J07],
  1456.                                             [J08],
  1457.                                             [J09],
  1458.                                             [J10],
  1459.                                             [J11],
  1460.                                             [J12],
  1461.                                             [J13],
  1462.                                             [J14],
  1463.                                             [J15],
  1464.                                             [J16],
  1465.                                             [J17],
  1466.                                             [J18],
  1467.                                             [J19],
  1468.                                             [J20],
  1469.                                             [J21],
  1470.                                             [J22],
  1471.                                             [J23],
  1472.                                             [J24],
  1473.                                             [J25],
  1474.                                             [J26],
  1475.                                             [J27],
  1476.                                             [J28],
  1477.                                             [J29],
  1478.                                             [J30],
  1479.                                             [J31],
  1480.                                             [J32],
  1481.                                             [J33],
  1482.                                             [J34],
  1483.                                             [J35],
  1484.                                             [J36],
  1485.                                             [J37],
  1486.                                             [J38],
  1487.                                             [J39],
  1488.                                             [J40],
  1489.                                             [J41],
  1490.                                             [J42],
  1491.                                             [J43],
  1492.                                             [J44],
  1493.                                             [J45],
  1494.                                             [J46],
  1495.                                             [J47],
  1496.                                             [J48],
  1497.                                             [J49],
  1498.                                             [J50],
  1499.                                             [J51],
  1500.                                             [J52],
  1501.                                             [J53],
  1502.                                             [J54],
  1503.                                             [J55],
  1504.                                             [J56],
  1505.                                             [J57],
  1506.                                             [J58],
  1507.                                             [J59],
  1508.                                             [J60],
  1509.                                             [J61],
  1510.                                             [J62],
  1511.                                             [J63],
  1512.                                             [J64],
  1513.                                             [J65],
  1514.                                             [J66],
  1515.                                             [J67],
  1516.                                             [J68],
  1517.                                             [J69],
  1518.                                             [J70],
  1519.                                             [J71],
  1520.                                             [J72],
  1521.                                             [J73],
  1522.                                             [J74],
  1523.                                             [J75],
  1524.                                             [J76],
  1525.                                             [J77],
  1526.                                             [J78],
  1527.                                             [J79],
  1528.                                             [J80],
  1529.                                             [J81],
  1530.                                             [J82],
  1531.                                             [J83],
  1532.                                             [J84],
  1533.                                             [J85],
  1534.                                             [J86],
  1535.                                             [J87],
  1536.                                             [J88],
  1537.                                             [J89],
  1538.                                             [J90]
  1539.                                         )
  1540.                     ) tmp_Pivot
  1541.                 Inner Join dbo.Employee tmp_Employee On tmp_Pivot.Employee_Id = tmp_Employee.EmployeeId
  1542.  
  1543. Update
  1544.         @tmp_Job_Numbers
  1545.             Set
  1546.                 Job_Account_Amount = isnull(tmp_Employee_Job.Job_Allocation_Amount,0)
  1547.                    
  1548.             From
  1549.                 @tmp_Job_Numbers tmp_Job_Numbers
  1550.                 Outer Apply
  1551.                     (
  1552.                         Select
  1553.                             sum(Job_Allocation_Amount)  As Job_Allocation_Amount
  1554.                             --sum(Job_Budget_Amount)        As Job_Budget_Amount,
  1555.                             --sum(Job_Total_Amount)     As Job_Total_Amount
  1556.                             From
  1557.                                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1558.                             Where
  1559.                                 tmp_Employee_Job.Job_Id = tmp_Job_Numbers.Job_Id
  1560.                                 And tmp_Employee_Job.Fortnight_Id = @Report_Fortnight_Id
  1561.                     ) tmp_Employee_Job
  1562.  
  1563.                
  1564. Update
  1565.         @tmp_Job_Numbers_Leave
  1566.             Set
  1567.                 Job_Account_Amount = isnull(tmp_Employee_Job.Job_Budget_Amount,0)
  1568.             From
  1569.                 @tmp_Job_Numbers_Leave tmp_Job_Numbers_Leave
  1570.                 Outer Apply
  1571.                     (
  1572.                         Select
  1573.                             --sum(Job_Allocation_Amount)    As Job_Allocation_Amount
  1574.                             sum(Job_Budget_Amount)      As Job_Budget_Amount
  1575.                             --sum(Job_Other_Amount)     As Job_Other_Amount
  1576.                             From
  1577.                                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1578.                             Where
  1579.                                 tmp_Employee_Job.Job_Id = tmp_Job_Numbers_Leave.Job_Id
  1580.                                 And tmp_Employee_Job.Fortnight_Id = @Report_Fortnight_Id
  1581.                     ) tmp_Employee_Job
  1582.                    
  1583. Update
  1584.         @tmp_Job_Numbers_Other
  1585.             Set
  1586.                 Job_Account_Amount = isnull(tmp_Employee_Job.Job_Other_Amount,0)
  1587.             From
  1588.                 @tmp_Job_Numbers_Other tmp_Job_Numbers_Other
  1589.                 Outer Apply
  1590.                     (
  1591.                         Select
  1592.                             --sum(Job_Allocation_Amount)    As Job_Allocation_Amount
  1593.                             --sum(Job_Budget_Amount)        As Job_Budget_Amount,
  1594.                             sum(Job_Other_Amount)       As Job_Other_Amount
  1595.                             From
  1596.                                 #RDC_sp_Payroll_Employee_Job tmp_Employee_Job
  1597.                             Where
  1598.                                 tmp_Employee_Job.Job_Id = tmp_Job_Numbers_Other.Job_Id
  1599.                                 And tmp_Employee_Job.Fortnight_Id = @Report_Fortnight_Id
  1600.                     ) tmp_Employee_Job
  1601.  
  1602. insert into @tmp_Job_Numbers
  1603.             (
  1604.                 Column_Number,
  1605.                 Job_Number,
  1606.                 Job_Name,
  1607.                 Job_Area,
  1608.                 Job_Account_Number_Main,
  1609.                 Job_Account_Number_Payroll,
  1610.                 Job_Account_Name,
  1611.                 Job_Account_Structure_L01,
  1612.                 Job_Account_Structure_L02,
  1613.                 Job_Account_Structure_L03,
  1614.                 Job_Account_Amount
  1615.             )
  1616.             SELECT Column_Number,
  1617.                 Job_Number,
  1618.                 Job_Name,
  1619.                 Job_Area,
  1620.                 Job_Account_Number_Main,
  1621.                 Job_Account_Number_Payroll,
  1622.                 Job_Account_Name,
  1623.                 Job_Account_Structure_L01,
  1624.                 Job_Account_Structure_L02,
  1625.                 Job_Account_Structure_L03,
  1626.                 Job_Account_Amount
  1627.                 FROM @tmp_Job_Numbers_Leave
  1628. insert into @tmp_Job_Numbers
  1629.             (
  1630.                 Column_Number,
  1631.                 Job_Number,
  1632.                 Job_Name,
  1633.                 Job_Area,
  1634.                 Job_Account_Number_Main,
  1635.                 Job_Account_Number_Payroll,
  1636.                 Job_Account_Name,
  1637.                 Job_Account_Structure_L01,
  1638.                 Job_Account_Structure_L02,
  1639.                 Job_Account_Structure_L03,
  1640.                 Job_Account_Amount
  1641.             )
  1642.             SELECT Column_Number,
  1643.                 Job_Number,
  1644.                 Job_Name,
  1645.                 Job_Area,
  1646.                 Job_Account_Number_Main,
  1647.                 Job_Account_Number_Payroll,
  1648.                 Job_Account_Name,
  1649.                 Job_Account_Structure_L01,
  1650.                 Job_Account_Structure_L02,
  1651.                 Job_Account_Structure_L03,
  1652.                 Job_Account_Amount
  1653.                 FROM @tmp_Job_Numbers_Other
  1654. --Ok now go and balance out the job allocations for the journal
  1655. --  Update
  1656. --      @tmp_Job_Numbers
  1657. --          Set
  1658. --              Job_Account_Amount = 0 - isnull(tmp_Job_Numbers_Total.Job_Account_Amount,0)
  1659. --          From
  1660. --              @tmp_Job_Numbers tmp_Job_Numbers
  1661. --              Outer Apply
  1662. --                  (
  1663. --                      Select
  1664. --                          sum(Job_Account_Amount) As Job_Account_Amount
  1665. --                          From
  1666. --                              @tmp_Job_Numbers tmp_Job_Numbers_Total
  1667. --                          Where
  1668. --                              tmp_Job_Numbers_Total.Job_Id != 0
  1669. --                  ) tmp_Job_Numbers_Total
  1670. --          Where
  1671. --              Job_Id = 0
  1672.  
  1673.             --Ok now go and balance out the job allocations for the journal
  1674.     Update
  1675.         @tmp_Job_Numbers
  1676.             Set
  1677.                 Job_Account_Amount = 0 - isnull(tmp_Job_Numbers_Total.Job_Account_Amount,0)
  1678.             From
  1679.                 @tmp_Job_Numbers tmp_Job_Numbers
  1680.                 Outer Apply
  1681.                     (
  1682.                         Select
  1683.                             sum(Job_Account_Amount) As Job_Account_Amount
  1684.                             From
  1685.                                 @tmp_Job_Numbers tmp_Job_Numbers_Total
  1686.                             Where
  1687.                                 tmp_Job_Numbers_Total.Job_Id != 0
  1688.                     ) tmp_Job_Numbers_Total
  1689.             Where
  1690.                 Job_Id = 0 
  1691.  
  1692. --Ok now go and select the journal
  1693.     Select
  1694.         *
  1695.         From
  1696.             (
  1697.                 Select
  1698.                     tmp_Job_Numbers.Job_Account_Number_Payroll                                          As Posting_Account,
  1699.                     'ESALWAGE'                                                                          As Posting_Line_Item,
  1700.                     convert(varchar(10), dateadd(Day, 1, tmp_Fortnight.Fortnight_Finish), 103)          As Posting_Date,
  1701.                     'Jnl'                                                                               As Posting_Type,
  1702.                     tmp_Fortnight.Fortnight_Financial_Year + ' - ' + tmp_Fortnight.Fortnight_Number     As Posting_Reference,
  1703.                     'Payrun - ' + tmp_Fortnight.Fortnight_Financial_Year + ' - ' + tmp_Fortnight.Fortnight_Number + ' - ' + convert(varchar(10), dateadd(Day, 1, tmp_Fortnight.Fortnight_Finish), 103)  As Posting_Description,
  1704.                     tmp_Job_Numbers.Job_Number + ' - ' + tmp_Job_Numbers.Job_Name                       As Posting_Notes,
  1705.                     tmp_Job_Numbers.Job_Account_Amount                                                  As Posting_Amount,
  1706.                     1                                                                                   As Posting_Quantity
  1707.                     From
  1708.                         @tmp_Job_Numbers tmp_Job_Numbers
  1709.                         Outer Apply
  1710.                             (
  1711.                                 Select
  1712.                                     *
  1713.                                     From
  1714.                                         @tmp_Fortnights tmp_Fortnight
  1715.                                     Where
  1716.                                         tmp_Fortnight.Fortnight_Id = @Report_Fortnight_Id
  1717.                             ) tmp_Fortnight
  1718.                     Where
  1719.                         tmp_Job_Numbers.Job_Account_Number_Main != ''
  1720.                 Union All
  1721.                 Select
  1722.                     '10222011'                                                                          As Posting_Account,
  1723.                     'ESALWAGE'                                                                          As Posting_Line_Item,
  1724.                     convert(varchar(10), dateadd(Day, 1, tmp_Fortnight.Fortnight_Finish), 103)          As Posting_Date,
  1725.                     'Jnl'                                                                               As Posting_Type,
  1726.                     tmp_Fortnight.Fortnight_Financial_Year + ' - ' + tmp_Fortnight.Fortnight_Number     As Posting_Reference,
  1727.                     'Payrun - ' + tmp_Fortnight.Fortnight_Financial_Year + ' - ' + tmp_Fortnight.Fortnight_Number + ' - ' + convert(varchar(10), dateadd(Day, 1, tmp_Fortnight.Fortnight_Finish), 103)  As Posting_Description,
  1728.                     'J01 - Payrun Reallocation'                                                         As Posting_Notes,
  1729.                     tmp_Job_Numbers.Job_Account_Amount                                                  As Posting_Amount,
  1730.                     1                                                                                   As Posting_Quantity
  1731.                     From
  1732.                         @tmp_Job_Numbers tmp_Job_Numbers
  1733.                         Outer Apply
  1734.                             (
  1735.                                 Select
  1736.                                     *
  1737.                                     From
  1738.                                         @tmp_Fortnights tmp_Fortnight
  1739.                                     Where
  1740.                                         tmp_Fortnight.Fortnight_Id = @Report_Fortnight_Id
  1741.                             ) tmp_Fortnight
  1742.                     Where
  1743.                         tmp_Job_Numbers.Job_Id = 0
  1744.             ) tmp_Journal
  1745.         Order By
  1746.             tmp_Journal.Posting_Notes
  1747.  
  1748.  
  1749.  
  1750.  
  1751.             --Pivot
  1752.             --  (
  1753.             --      sum(Job_Total_Amount)
  1754.             --          For
  1755.             --              Job_Number
  1756.             --                  In
  1757.             --                      (
  1758.             --                          [J-01]
  1759.             --                      )
  1760.                        
  1761.             --  ) tmp_Pivot
  1762. ----Select
  1763. ----    convert(varchar(100), getdate(), 103)
  1764. ----Account Line Item   Posting Date    Posting Type    Reference   Description Notes   Amount  Quantity
  1765. ----50011010    NAOTHER 30/06/2015  Jnl     Depreciation 2014-2015 - Land       0.00    1
  1766.  
  1767. --Select * From #RDC_sp_Payroll_Employee_Job
  1768. --ESALWAGE
  1769.  
  1770.  
  1771. --Select
  1772. --  *
  1773. --  From
  1774. --      #RDC_sp_Payroll_Employee_Job
  1775. --  Where
  1776. --      Job_Id = 1
  1777.  
  1778. --Select
  1779. --  *
  1780. --  From
  1781. --      #RDC_sp_Payroll_Employee_Payrun
  1782.            
  1783.     --Select
  1784.     --  *
  1785.     --  From
  1786.     --      dbo.Payrun tmp_Payrun
  1787.     --          Outer Apply
  1788.     --              (
  1789.     --                  Select Top(1)
  1790.     --                      *
  1791.     --                      From   
  1792.     --                          @tmp_Fortnights tmp_Select_Fortnight
  1793.     --                      Where
  1794.     --                          tmp_Payrun.PayrunBeginning >= tmp_Select_Fortnight.Fortnight_Start
  1795.     --                          And tmp_Payrun.PayrunEnding <= tmp_Select_Fortnight.Fortnight_Finish
  1796.     --              ) tmp_Select_Fortnight
  1797.     --  Where
  1798.     --      FinancialYearID >= 36
  1799.  
  1800. --Select
  1801. --  tmp_Payrun.PayrunID,
  1802. --  tmp_Payrun.FinancialYearID,
  1803. --  tmp_Payrun.Number,
  1804. --  tmp_Payrun.Name,
  1805. --  tmp_Payrun.PayrunBeginning,
  1806. --  tmp_Payrun.PayrunEnding,
  1807. --  tmp_Payrun.PayDate,
  1808.    
  1809. --  tmp_Employee.EmployeeID,
  1810. --  tmp_Employee.Number,
  1811. --  tmp_Employee.Name,
  1812.    
  1813. --  isnull(tmp_Payrun_Salaries.Amount,0)        As Payrun_Amount_Salaries,
  1814.    
  1815. --  isnull(tmp_Payrun_Allowances.Amount,0)      As Payrun_Amount_Allowances,
  1816.    
  1817. --  isnull(tmp_Payrun_Leave.Amount,0)           As Payrun_Amount_Leave,
  1818.    
  1819. --  isnull(tmp_Payrun_Superannuation.Amount,0)  As Payrun_Amount_Superannuation
  1820.    
  1821. --  From
  1822. --      dbo.Payrun tmp_Payrun
  1823. --          Inner Join dbo.EmployeePayrun tmp_Employee_Payrun On tmp_Payrun.PayrunID = tmp_Employee_Payrun.PayrunID
  1824. --              Inner Join dbo.Employee tmp_Employee On tmp_Employee_Payrun.EmployeeID = tmp_Employee.EmployeeID
  1825. --              Outer Apply
  1826. --                  (
  1827. --                      Select
  1828. --                          sum(Amount) As Amount
  1829. --                          From
  1830. --                              dbo.PayrunDetails tmp_Payrun_Details
  1831. --                          Where
  1832. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1833. --                              And tmp_Payrun_Details.Type = 0
  1834. --                  ) tmp_Payrun_Salaries
  1835. --              Outer Apply
  1836. --                  (
  1837. --                      Select
  1838. --                          sum(Amount) As Amount
  1839. --                          From
  1840. --                              dbo.PayrunDetails tmp_Payrun_Details
  1841. --                          Where
  1842. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1843. --                              And tmp_Payrun_Details.Type = 2
  1844. --                  ) tmp_Payrun_Allowances
  1845. --              Outer Apply
  1846. --                  (
  1847. --                      Select
  1848. --                          sum(Amount) As Amount
  1849. --                          From
  1850. --                              dbo.PayrunDetails tmp_Payrun_Details
  1851. --                          Where
  1852. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1853. --                              And tmp_Payrun_Details.Type = 3
  1854. --                  ) tmp_Payrun_Leave
  1855. --              Outer Apply
  1856. --                  (
  1857. --                      Select
  1858. --                          sum(Amount) As Amount
  1859. --                          From
  1860. --                              dbo.PayrunDetails tmp_Payrun_Details
  1861. --                          Where
  1862. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1863. --                              And tmp_Payrun_Details.Type = 9
  1864. --                  ) tmp_Payrun_Superannuation
  1865. --  Where
  1866. --      tmp_Employee.EmployeeID = 77
  1867.    
  1868.    
  1869.    
  1870. Go
  1871.  
  1872.  
  1873.  
  1874. Return
  1875.  
  1876.  
  1877.  
  1878.     --Select
  1879.     --  *
  1880.     --  From
  1881.     --      @tmp_Fortnights
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887. --Select
  1888. --  tmp_Payrun.PayrunID,
  1889. --  tmp_Payrun.FinancialYearID,
  1890. --  tmp_Payrun.Number,
  1891. --  tmp_Payrun.Name,
  1892. --  tmp_Payrun.PayrunBeginning,
  1893. --  tmp_Payrun.PayrunEnding,
  1894. --  tmp_Payrun.PayDate,
  1895. -- 
  1896. --  tmp_Employee.EmployeeID,
  1897. --  tmp_Employee.Number,
  1898. --  tmp_Employee.Name,
  1899. -- 
  1900. --  isnull(tmp_Payrun_Salaries.Amount,0)        As Payrun_Amount_Salaries,
  1901. -- 
  1902. --  isnull(tmp_Payrun_Allowances.Amount,0)      As Payrun_Amount_Allowances,
  1903. -- 
  1904. --  isnull(tmp_Payrun_Leave.Amount,0)           As Payrun_Amount_Leave,
  1905. -- 
  1906. --  isnull(tmp_Payrun_Superannuation.Amount,0)  As Payrun_Amount_Superannuation
  1907. -- 
  1908. --  From
  1909. --      dbo.Payrun tmp_Payrun
  1910. --          Inner Join dbo.EmployeePayrun tmp_Employee_Payrun On tmp_Payrun.PayrunID = tmp_Employee_Payrun.PayrunID
  1911. --              Inner Join dbo.Employee tmp_Employee On tmp_Employee_Payrun.EmployeeID = tmp_Employee.EmployeeID
  1912. --              Outer Apply
  1913. --                  (
  1914. --                      Select
  1915. --                          sum(Amount) As Amount
  1916. --                          From
  1917. --                              dbo.PayrunDetails tmp_Payrun_Details
  1918. --                          Where
  1919. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1920. --                              And tmp_Payrun_Details.Type = 0
  1921. --                  ) tmp_Payrun_Salaries
  1922. --              Outer Apply
  1923. --                  (
  1924. --                      Select
  1925. --                          sum(Amount) As Amount
  1926. --                          From
  1927. --                              dbo.PayrunDetails tmp_Payrun_Details
  1928. --                          Where
  1929. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1930. --                              And tmp_Payrun_Details.Type = 2
  1931. --                  ) tmp_Payrun_Allowances
  1932. --              Outer Apply
  1933. --                  (
  1934. --                      Select
  1935. --                          sum(Amount) As Amount
  1936. --                          From
  1937. --                              dbo.PayrunDetails tmp_Payrun_Details
  1938. --                          Where
  1939. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1940. --                              And tmp_Payrun_Details.Type = 3
  1941. --                  ) tmp_Payrun_Leave
  1942. --              Outer Apply
  1943. --                  (
  1944. --                      Select
  1945. --                          sum(Amount) As Amount
  1946. --                          From
  1947. --                              dbo.PayrunDetails tmp_Payrun_Details
  1948. --                          Where
  1949. --                              tmp_Payrun_Details.EmployeePayrunID = tmp_Employee_Payrun.EmployeePayrunID
  1950. --                              And tmp_Payrun_Details.Type = 9
  1951. --                  ) tmp_Payrun_Superannuation
  1952. --  Where
  1953. --      tmp_Employee.EmployeeID = 77
  1954. --
  1955. --Select
  1956. --  *
  1957. --  From
  1958. --      dbo.Employee
  1959.        
  1960.        
  1961.  
  1962.  
  1963. --Select
  1964. --  convert(varchar(100), getdate(), 103)
  1965. --Account   Line Item   Posting Date    Posting Type    Reference   Description Notes   Amount  Quantity
  1966. --50011010  NAOTHER 30/06/2015  Jnl     Depreciation 2014-2015 - Land       0.00    1
  1967.  
  1968.  
  1969. --ESALWAGE
  1970.  
  1971. --Select
  1972. --  Employee_Id,
  1973. --  sum(Job_Allocation_Percent),
  1974. --  sum(Job_Budget_Percent)
  1975. --  From
  1976. --      #RDC_sp_Payroll_Employee_Job
  1977. --  Where
  1978. --      Fortnight_Id = 6
  1979. --  Group By
  1980. --      Employee_Id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement