Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions resources/queries/targetedms/InstrumentBilling.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
SELECT
Project.Id AS ProjectID,
Project.LabDirector AS LabDirector,
InstrumentOperator.DisplayName AS Researcher,
i.Instrument.Name AS Instrument,
Name AS RequestedBy,
i.Id AS UsageBlockID,
StartTime AS StartDate,
EndTime AS EndDate,
TIMESTAMPDIFF('SQL_TSI_HOUR', StartTime, EndTime) AS Hours,
ir.Fee,
ir.rateType.setupFee AS Setup_Cost,
TIMESTAMPDIFF('SQL_TSI_HOUR', StartTime, EndTime) * ir.Fee + ir.rateType.setupFee AS TotalCost,
iup.PaymentMethod.UWBudgetNumber AS Payment_Method,
iup.PaymentMethod.Name AS Payment_Method_Name,
iup.PercentPayment

FROM targetedms.InstrumentSchedule i
LEFT OUTER JOIN targetedms.InstrumentRate ir ON i.Instrument = ir.Instrument
LEFT OUTER JOIN targetedms.InstrumentUsagePayment iup ON i.Id = iup.InstrumentScheduleId
48 changes: 48 additions & 0 deletions resources/queries/targetedms/InstrumentBillingByMonth.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
PARAMETERS(StartBillDate TIMESTAMP)
SELECT
ProjectID,
LabDirector,
Researcher,
Instrument,
RequestedBy,
UsageBlockID,
StartDate,
EndDate,
Hours,
HoursInRange,
Fee,
Setup_Cost,
TotalCost,
Payment_Method,
Payment_Method_Name,
PercentPayment,
((HoursInRange * Fee + Setup_Cost) * PercentPayment / 100) AS AmountBilled

FROM
(SELECT
*,
TIMESTAMPDIFF('SQL_TSI_HOUR',
CASE WHEN StartDate <= StartBillDate THEN StartBillDate ELSE StartDate END,
CASE WHEN EndDate >= TIMESTAMPADD('SQL_TSI_MONTH', 1, StartBillDate) THEN TIMESTAMPADD('SQL_TSI_MONTH', 1, StartBillDate) ELSE EndDate END
) AS HoursInRange

FROM targetedms.InstrumentBilling i
WHERE (StartDate >= StartBillDate AND StartDate <= TIMESTAMPADD('SQL_TSI_MONTH', 1, StartBillDate)) OR
(EndDate >= StartBillDate AND EndDate <= TIMESTAMPADD('SQL_TSI_MONTH', 1, StartBillDate)) OR
(StartDate <= StartBillDate AND EndDate >= TIMESTAMPADD('SQL_TSI_MONTH', 1, StartBillDate))
) X
16 changes: 16 additions & 0 deletions resources/queries/targetedms/instrumentBilling.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="instrumentBilling" tableDbType="TABLE">
<columns>
<column columnName="Hours">
<formatString>0.0</formatString>
</column>
<column columnName="TotalCost">
<formatString>$#,##0.00</formatString>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<columns>
<column name="Instrument" />
<column name="LabDirector" />
<column name="Researcher" />
<column name="RequestedBy" />
<column name="StartDate" />
<column name="EndDate" />
<column name="Hours" />
<column name="TotalCost" />
<column name="Payment_Method_Name" />
<column name="PercentPayment" />
</columns>
<sorts>
<sort column="StartDate" descending="true" />
</sorts>
</customView>
16 changes: 16 additions & 0 deletions resources/queries/targetedms/instrumentBillingByMonth.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="instrumentBillingByMonth" tableDbType="TABLE">
<columns>
<column columnName="HoursInRange">
<formatString>0.0</formatString>
</column>
<column columnName="AmountBilled">
<formatString>$#,##0.00</formatString>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
18 changes: 18 additions & 0 deletions resources/queries/targetedms/instrumentSchedule.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="instrumentSchedule" tableDbType="TABLE">
<columns>
<column columnName="InstrumentOperator">
<fk>
<fkDbSchema>core</fkDbSchema>
<fkTable>Users</fkTable>
<fkColumnName>UserId</fkColumnName>
<fkDisplayColumnName>DisplayName</fkDisplayColumnName>
</fk>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
3 changes: 3 additions & 0 deletions resources/queries/targetedms/msProject.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<column columnName="Id">
<url>/targetedms-msProjectDetails.view?project=${Id}</url>
</column>
<column columnName="Title">
<url>/targetedms-msProjectDetails.view?project=${Id}</url>
</column>
</columns>
</table>
</tables>
Expand Down
19 changes: 0 additions & 19 deletions resources/queries/targetedms/paymentMethodCostSummary.query.xml

This file was deleted.

17 changes: 0 additions & 17 deletions resources/queries/targetedms/paymentMethodCostSummary.sql

This file was deleted.

4 changes: 0 additions & 4 deletions resources/queries/targetedms/userProjects.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
<tables xmlns="http://labkey.org/data/xml">
<table tableName="userProjects" tableDbType="TABLE">
<columns>
<column columnName="ViewLink">
<columnTitle></columnTitle>
<url>/targetedms-msProjectDetails.view?project=${Id}</url>
</column>
</columns>
</table>
</tables>
Expand Down
5 changes: 1 addition & 4 deletions resources/queries/targetedms/userProjects.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
SELECT
'[View]' AS ViewLink,
p.id AS Id,
p.title AS Title,
p.submitDate AS SubmitDate,
p.collaborationStatus AS CollaborationStatus
FROM projectResearcher pr
LEFT JOIN msProject p ON pr.project = p.id
GROUP BY p.id, p.title, p.submitDate, p.collaborationStatus
FROM msProject p WHERE p.id IN (SELECT project FROM projectresearcher pr WHERE pr.researcher = USERID())
26 changes: 20 additions & 6 deletions resources/schemas/targetedms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@
</columns>
</table>
<table tableName="msProject" tableDbType="TABLE">
<description>A project used for scheduling and billing instruments</description>
<columns>
<column columnName="Id"/>
<column columnName="affiliation"/>
Expand All @@ -1793,7 +1794,9 @@
<columns>
<column columnName="Id"/>
<column columnName="project"/>
<column columnName="researcher"/>
<column columnName="researcher">
<required>true</required>
</column>
<column columnName="Created"/>
<column columnName="CreatedBy"/>
<column columnName="Modified"/>
Expand All @@ -1802,12 +1805,15 @@
</columns>
</table>
<table tableName="msInstrument" tableDbType="TABLE">
<description>Instruments that can be scheduled and whose usage can be billed</description>
<columns>
<column columnName="Id"/>
<column columnName="name"/>
<column columnName="description"/>
<column columnName="active"/>
<column columnName="color"/>
<column columnName="color">
<description>HTML/CSS color description. Can be RGB like #00ee00 or a named color like "red"</description>
</column>
<column columnName="massSpec"/>
<column columnName="instrument"/>
<column columnName="Created"/>
Expand All @@ -1817,9 +1823,13 @@
<column columnName="Container"/>
</columns>
</table>
<table tableName="paymentMethod" tableDbType="TABLE">
<table tableName="paymentMethod" tableDbType="TABLE" useColumnOrder="true">
<columns>
<column columnName="Id"/>
<column columnName="name">
<required>true</required>
<inputType>text</inputType>
</column>
<column columnName="UWBudgetNumber"/>
<column columnName="budgetExpirationDate"/>
<column columnName="PONumber"/>
Expand All @@ -1837,7 +1847,6 @@
<column columnName="isCurrent"/>
<column columnName="federalFunding"/>
<column columnName="poAmount"/>
<column columnName="name"/>
<column columnName="worktag"/>
<column columnName="resourceWorktag"/>
<column columnName="resourceWorktagDescription"/>
Expand Down Expand Up @@ -1865,6 +1874,7 @@
</columns>
</table>
<table tableName="instrumentSchedule" tableDbType="TABLE">
<description>Scheduled usage of a particular instrument for particular project</description>
<columns>
<column columnName="Id"/>
<column columnName="instrument"/>
Expand All @@ -1886,7 +1896,9 @@
<column columnName="Id"/>
<column columnName="name"/>
<column columnName="description"/>
<column columnName="setupFee"/>
<column columnName="setupFee">
<formatString>$#,##0.00</formatString>
</column>
<column columnName="Created"/>
<column columnName="CreatedBy"/>
<column columnName="Modified"/>
Expand All @@ -1899,7 +1911,9 @@
<column columnName="Id"/>
<column columnName="instrument"/>
<column columnName="rateType"/>
<column columnName="fee"/>
<column columnName="fee">
<formatString>$#,##0.00</formatString>
</column>
<column columnName="Created"/>
<column columnName="CreatedBy"/>
<column columnName="Modified"/>
Expand Down
17 changes: 17 additions & 0 deletions resources/views/instrumentSchedulingAdmin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div><a href="targetedms-scheduleAllInstruments.view">All instrument calendar view</a></div>
<div><a href="targetedms-msProject.view">Your project list</a></div>

<div>&nbsp;</div>

<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=InstrumentBilling">Instrument billing report</a></div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=InstrumentBillingByMonth">Monthly instrument billing report</a></div>

<div>&nbsp;</div>

<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=MSInstrument">Edit instrument list</a> (resources that can be scheduled and billed for)</div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=rateType">Edit rate types</a> (setup fee)</div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=instrumentRate">Edit rate list</a> (assigns a setup fee and an hourly rate to instruments)</div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=MSProject">Edit project list</a></div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=projectResearcher">Edit project/researcher mapping</a> (attaches users to projects)</div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=paymentMethod">Edit payment method list</a></div>
<div><a href="query-executeQuery.view?schemaName=targetedms&query.queryName=projectPaymentMethod">Edit project/payment method mapping</a></div>
2 changes: 2 additions & 0 deletions resources/views/instrumentSchedulingAdmin.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<view xmlns="http://labkey.org/data/xml/view" title="Instrument Scheduling Admin">
</view>
6 changes: 6 additions & 0 deletions resources/views/instrumentSchedulingAdmin.webpart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<webpart xmlns="http://labkey.org/data/xml/webpart" title="Instrument Scheduling Admin">
<view name="instrumentSchedulingAdmin"/>
<locations>
<location name="body"/>
</locations>
</webpart>
15 changes: 8 additions & 7 deletions resources/views/msProject.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<div id="ms-project"></div>
<br/>
<div id="all-projects"></div>
<script type="text/javascript" nonce="<%=scriptNonce%>">
(function(){
let webpart = <%=webpartContext%>;
let config = {
renderTo: webpart.wrapperDivId,
frame: 'portal',
title: 'Your Projects',
renderTo: 'ms-project',
frame: 'none',
schemaName: 'targetedms',
queryName: 'userProjects',
containerFilter: LABKEY.Query.containerFilter.currentAndSubfolders
};
// admins can see all projects, non-admins can only see projects they are a researcher on
if (!LABKEY.user.isAdmin) {
config.filterArray = [LABKEY.Filter.create('researcher', LABKEY.user.id, LABKEY.Filter.Types.EQUAL)];
}
new LABKEY.QueryWebPart(config);

if (LABKEY.user.isAdmin) {
document.getElementById('all-projects').innerHTML = LABKEY.Utils.textLink({text: 'View all projects', href: 'query-executeQuery.view?schemaName=targetedms&query.queryName=msProject'});
}
})();
</script>
2 changes: 1 addition & 1 deletion resources/views/msProject.view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<view xmlns="http://labkey.org/data/xml/view" title="Projects">
<view xmlns="http://labkey.org/data/xml/view" title="Your Projects">
<dependencies>
<dependency path="internal/jQuery"/>
</dependencies>
Expand Down
Loading