Skip to content

Commit

Permalink
Enable selection of property and unit for assigning the imported stat…
Browse files Browse the repository at this point in the history
…ement to the unit.
  • Loading branch information
wsapiens committed Jun 23, 2024
1 parent 95dbe42 commit 15e2a37
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spark-property-manager",
"version": "1.1.20",
"version": "1.1.21",
"description": "Spark Real Estate Management Application",
"main": "./bin/server.js",
"scripts": {
Expand Down
40 changes: 39 additions & 1 deletion public/javascripts/import-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ $(function(){
$('#nav-payment').removeClass('active');
$('#nav-user').removeClass('active');

$('#property-select').find('option').remove();
$('#unit-select').find('option').remove();
$('#method-select').find('option').remove();
$.get("/payments/methods", function(data, status){
console.log(data.data);
Expand All @@ -48,6 +50,41 @@ $(function(){
}
});

$.get("/properties", function(data, status){
console.log(data.data);
$('#property-select').append('<option>Select Property</option>');
$.each(data.data, function(key, value){
console.log(value);
console.log(value.id);
console.log(value.address_street);
$('#property-select').append('<option value=' + value.id + '>'
+ value.address_street + ', '
+ value.address_city + ', '
+ value.address_state + ' '
+ value.address_zip
+ '</option>');
});
if(data.data.length > 0) {
$('#property-select option:first').attr("selected",true);
}
//$('#property-select').val($('#property-select option:first').val());
});

$('#property-select').on('change', function() {
$('#unit-select').find('option').remove();
$('#unit-select').append('<option>Select Unit</option>');
if($(this).val() !== 'Select Property') {
$.get("/properties/" + $(this).val() + "/units", function(data, status){
$.each(data.data[0].PropertyUnits, function(key, value){
$('#unit-select').append('<option value=' + value.id + '>' + value.name + '</option>');
});
if(data.data && data.data.length === 0) {
$('#unit-select').val($('#unit-select option:first').val()).change();
}
});
}
});

$('#submit-button').on('click', function() {
var token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var filterColumn = $('#filter-column-number').val();
Expand Down Expand Up @@ -239,10 +276,11 @@ $(function(){

$('#upload-button').on('click', function() {
var methodId = $('#method-select').val();
var unitId = $('#unit-select').val();
if(methodId.toLowerCase().indexOf("select") === -1) {
$.ajax({
// Your server script to process the upload
url: '/file/statement/' + methodId + '?tzId=' + Intl.DateTimeFormat().resolvedOptions().timeZone,
url: '/file/statement/' + methodId + '?tzId=' + Intl.DateTimeFormat().resolvedOptions().timeZone + '&unitId=' + unitId,
type: 'POST',

// Form data
Expand Down
3 changes: 3 additions & 0 deletions routes/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ router.post('/statement/:methodId', upload.single('statement'), function(req, re
}]
}).then(properties => {
defaultUnitId = properties[0].PropertyUnits[0].id;
if(req.query.unitId !== null ) {
defaultUnitId = req.query.unitId;
}

csv.parseFile(req.file.path)
.on("data", function(data){
Expand Down
10 changes: 10 additions & 0 deletions views/import.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
<h1 class="h4"><%= title %></h1>
<br>
<form id="file-upload-form" enctype="multipart/form-data">
<label for="property-select" class="select ui-select">Property:</label>
<select class="form-select" name="select-native-1" id="property-select">
<option value="1">Select Property</option>
</select>
<br>
<label for="unit-select" class="select ui-select">Unit:</label>
<select class="form-select" name="select-native-1" id="unit-select">
<option value="1">Select Unit</option>
</select>
<br>
<label for="method-select" class="select ui-select">Payment Method:</label>
<select class="form-select" name="select-native-1" id="method-select">
<option value="1">Select Payment Method</option>
Expand Down

0 comments on commit 15e2a37

Please sign in to comment.