Skip to content

Commit

Permalink
Merge pull request #347 from fasrc/ajk_lab_summary
Browse files Browse the repository at this point in the history
Add a display, url for Lab Billing Summary
  • Loading branch information
aaronk authored Nov 4, 2024
2 parents 5bc4781 + 3a9c529 commit 0ec1f00
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ django-q.log
media/reports*
.devcontainer/*
.bin/*
test.http
215 changes: 215 additions & 0 deletions coldfront/plugins/ifx/templates/plugins/ifx/lab_billing_summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{% extends "common/base.html" %}
{% load common_tags %}
{% load crispy_forms_tags %}
{% load static %}

{% block ifx_head %}
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.5/css/dataTables.dataTables.min.css"></style>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js"></script>
<script src="https://cdn.datatables.net/2.1.5/js/dataTables.js"></script>
<script src="https://cdn.datatables.net/select/2.0.5/js/dataTables.select.js"></script>
<script src="https://cdn.datatables.net/select/2.0.5/js/select.dataTables.js"></script>
<style>
#loading {
display: none;
}
.parent-box {
display: flex;
}
.control-box {
position: relative;
float: left;
margin: 0 0.5em 0.5em 0;
display: inline-block;
align-self: flex-end;
}
.clear {
clear: both;
}
#startYear, #startMonth {
margin-right: 0.5em;
}
#toggleEmptyCellsFilter {
margin-right: 0.5em;
margin-left: 0.5em;
}
</style>
{% endblock %}

{% block title %}
Lab Billing Summary
{% endblock %}

{% block content %}
<script>
(function($){
$(document).ready(function(){
var dialog = $('#loading').dialog(
{
autoOpen: false,
height: 200,
width: 300,
modal: true,
title: 'Working...'
}
)
// Make sure the wait dialog opens for every ajax call
$(document)
.ajaxStart(function () {
dialog.dialog("open")
})
.ajaxStop(function () {
dialog.dialog("close")
});

$( "#progressbar" ).progressbar({
value: false
});

DataTable.defaults.layout = {
topStart: null,
topEnd: null,
bottomStart: null,
bottomEnd: null,
};

var labSummaryTable;

// Set start year and month to 6 months ago
const getDaysInMonth = (year, month) => new Date(year, month, 0).getDate()
const addMonths = (input, months) => {
const date = new Date(input)
date.setDate(1)
date.setMonth(date.getMonth() + months)
date.setDate(Math.min(input.getDate(), getDaysInMonth(date.getFullYear(), date.getMonth()+1)))
return date
}
function setStartYearMonth() {
const startDate = addMonths(new Date(), -6)
$("#startYear").val(startDate.getFullYear());
$("#startMonth").val(startDate.getMonth() + 1);
}

function loadTable() {
$.ajax({
url: '/ifx/api/billing/get-charge-history/',
type: 'GET',
data: {
start_year: $("#startYear").val(),
start_month: $("#startMonth").val(),
invoice_prefix: 'RC',
},
success: function(data) {
const dataObj = data

// Get the colunm names in sorted order
const columns = new Set()
Object.keys(dataObj).forEach(key => {
Object.keys(dataObj[key]).forEach(col => {
columns.add(col)
})
})
const sortedColumns = Array.from(columns).sort()
const result = []
Object.keys(dataObj).forEach(key => {
const row = [key]
sortedColumns.forEach(col => {
row.push(dataObj[key][col] || '')
})
result.push(row)
})
sortedColumns.unshift('Lab')
labSummaryTable = $("#labBillingSummary").DataTable({
layout: {
topStart: 'search',
},
paging: false,
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[ 0, "asc" ]],
data: result,
columns: sortedColumns.map(col => ({title: col})),
})
},
})
}

function filterRowsWithEmptyCells(settings, data, dataIndex) {
var row = labSummaryTable.row(dataIndex).node();
var cells = $('td', row);

if (row === null) {
return false;
}
// Check if any cell in the row is empty
for (var i = 0; i < cells.length; i++) {
if ($(cells[i]).text().trim() === '') {
return true; // Return true to display this row
}
}

return false; // Return false to hide this row
}

// Initialize the checkbox filter toggle
$('#toggleEmptyCellsFilter').on('change', function() {
if (this.checked) {
// Add the filter when the checkbox is checked
$.fn.dataTable.ext.search.push(filterRowsWithEmptyCells);
} else {
// Remove the filter when the checkbox is unchecked
$.fn.dataTable.ext.search = $.fn.dataTable.ext.search.filter(function(value) {
return value !== filterRowsWithEmptyCells;
});
}

// Redraw the table after toggling the filter
labSummaryTable.draw();
});

$('#refresh').on('click', function() {
labSummaryTable.destroy();
$('#labBillingSummary').empty();
loadTable();
})
setStartYearMonth();
loadTable();
})
})(jQuery)
</script>
<div style="font-size: 10pt;">
<h2>Lab Billing Summary</h2>
<div id="loading">
<p>
<div id="progressbar"></div>
</p>
</div>
<div class="parent-box">
<div class="control-box">
<label for="startYear">Start Year</label>
<input type="text" id="startYear" value="2024"></input>
</div>
<div class="control-box">
<label for="startYear">Start Month</label>
<input type="text" id="startMonth" value="1"></input>
</div>
<div class="control-box">
<label for="toggleEmptyCellsFilter">Only rows with empty cells</label><input type="checkbox" id="toggleEmptyCellsFilter"></input>
</div>
<div class="control-box">
<button id="refresh">Refresh</button>
</div>
<div class="clear"></div>
</div>
<div>
<table id="labBillingSummary" class="display" style="width:100%">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{% endblock %}
6 changes: 4 additions & 2 deletions coldfront/plugins/ifx/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.urls import path, include
from rest_framework import routers
from ifxbilling.views import unauthorized as unauthorized_api
from ifxbilling.views import get_orgs_with_billing
from ifxbilling.views import get_orgs_with_billing, get_charge_history
from ifxuser.views import get_org_names
from coldfront.plugins.ifx.viewsets import ColdfrontBillingRecordViewSet, ColdfrontReportRunViewSet, ColdfrontProductUsageViewSet
from coldfront.plugins.ifx.views import update_user_accounts_view, get_billing_record_list, unauthorized, report_runs, run_report, calculate_billing_month, billing_month, get_product_usages, billing_records, send_billing_record_review_notification
from coldfront.plugins.ifx.views import update_user_accounts_view, get_billing_record_list, unauthorized, report_runs, run_report, calculate_billing_month, billing_month, get_product_usages, billing_records, send_billing_record_review_notification, lab_billing_summary

router = routers.DefaultRouter()
router.register(r'billing-records', ColdfrontBillingRecordViewSet, 'billing-record')
Expand All @@ -15,6 +15,7 @@
path('api/unauthorized/', unauthorized_api),
path('api/billing/get-billing-record-list/', get_billing_record_list),
path('api/billing/get-orgs-with-billing/<str:invoice_prefix>/<int:year>/<int:month>/', get_orgs_with_billing),
path('api/billing/get-charge-history/', get_charge_history),
path('api/calculate-billing-month/<int:year>/<int:month>/', calculate_billing_month),
path('api/run-report/', run_report),
path('api/get-org-names/', get_org_names, name='get-org-names'),
Expand All @@ -26,4 +27,5 @@
path('report-runs/', report_runs, name='report-runs'),
path('billing-month/', billing_month, name='billing-month'),
path('billing-records/', billing_records, name='billing-records'),
path('lab-billing-summary/', lab_billing_summary, name='lab-billing-summary'),
]
10 changes: 10 additions & 0 deletions coldfront/plugins/ifx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,13 @@ def update_user_accounts_view(request):
)

return Response('OK')

@login_required
def lab_billing_summary(request):
'''
Show lab billing summary
'''
if not request.user.is_superuser:
raise PermissionDenied
token = request.user.auth_token.key
return render(request, 'plugins/ifx/lab_billing_summary.html', { 'auth_token': token })
2 changes: 1 addition & 1 deletion ifxbilling
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ django-tables2==2.3.4
djangorestframework==3.15.2
djangorestframework-datatables==0.7.0
ipython==7.16.3
isilon-sdk
isilon-sdk==0.3.0.1
ldap3
logging_tree==1.9
mysqlclient==2.2.0
Expand Down

0 comments on commit 0ec1f00

Please sign in to comment.