diff --git a/package.json b/package.json index 3060803..169f1f5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/public/javascripts/import-manager.js b/public/javascripts/import-manager.js index a8e7e16..c90a518 100644 --- a/public/javascripts/import-manager.js +++ b/public/javascripts/import-manager.js @@ -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); @@ -48,6 +50,41 @@ $(function(){ } }); + $.get("/properties", function(data, status){ + console.log(data.data); + $('#property-select').append(''); + $.each(data.data, function(key, value){ + console.log(value); + console.log(value.id); + console.log(value.address_street); + $('#property-select').append(''); + }); + 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(''); + if($(this).val() !== 'Select Property') { + $.get("/properties/" + $(this).val() + "/units", function(data, status){ + $.each(data.data[0].PropertyUnits, function(key, value){ + $('#unit-select').append(''); + }); + 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(); @@ -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 diff --git a/routes/file.js b/routes/file.js index ed9b467..992657c 100644 --- a/routes/file.js +++ b/routes/file.js @@ -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){ diff --git a/views/import.ejs b/views/import.ejs index 1318a00..e399b06 100644 --- a/views/import.ejs +++ b/views/import.ejs @@ -16,6 +16,16 @@