Upload files
This commit is contained in:
4
ui/resources/routes/importar.php
Normal file
4
ui/resources/routes/importar.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Controller\Importar;
|
||||
|
||||
$app->get('/importar[/]', Importar::class);
|
92
ui/resources/views/importar.blade.php
Normal file
92
ui/resources/views/importar.blade.php
Normal file
@ -0,0 +1,92 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Importar
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<h1>Importar</h1>
|
||||
<form class="ui form" action="#" method="post" id="importar_form" enctype="multipart/form-data">
|
||||
<div class="two wide field">
|
||||
<label>Fecha</label>
|
||||
<div class="ui date calendar">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha" />
|
||||
<i class="calendar outline icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Cuenta</label>
|
||||
<select name="cuenta"></select>
|
||||
</div>
|
||||
<div class="inline field">
|
||||
<input type="file" name="archivo" style="display: none;" />
|
||||
<div class="ui labeled icon input" id="archivo_btn">
|
||||
<div class="ui label">Archivo</div>
|
||||
<input type="text" readonly="" />
|
||||
<i class="search icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button">Importar</button>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
function getCuentas() {
|
||||
sendGet(_urls.api + '/cuentas').then((data) => {
|
||||
if (data.cuentas === null || data.cuentas.length === 0) {
|
||||
return
|
||||
}
|
||||
const select = $("select[name='cuenta']")
|
||||
let values = []
|
||||
$.each(data.cuentas, (i, el) => {
|
||||
const nombre = [el.nombre, el.categoria.nombre].join(' - ')
|
||||
values.push({
|
||||
name: nombre,
|
||||
value: el.id,
|
||||
text: nombre
|
||||
})
|
||||
})
|
||||
select.dropdown({values})
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
getCuentas()
|
||||
const today = new Date()
|
||||
const start = new Date(today.getFullYear(), today.getMonth() - 1)
|
||||
$('.ui.calendar').calendar({
|
||||
type: 'month',
|
||||
initialDate: start,
|
||||
maxDate: start,
|
||||
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
|
||||
monthsShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
|
||||
formatter: {
|
||||
date: function(date, settings) {
|
||||
if (!date) return ''
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
return [year, month].join('-')
|
||||
}
|
||||
}
|
||||
})
|
||||
$('#archivo_btn').css('cursor', 'pointer').click(() => {
|
||||
$("[name='archivo']").trigger('click')
|
||||
})
|
||||
$("[name='archivo']").change((e) => {
|
||||
const arch = $(e.currentTarget)
|
||||
const filename = arch[0].files[0].name
|
||||
$('#archivo_btn').find('input').val(filename)
|
||||
})
|
||||
$('#importar_form').submit((e) => {
|
||||
e.preventDefault()
|
||||
const data = new FormData(e.currentTarget)
|
||||
sendPost(_urls.api + '/import', data, true).then((resp) => {
|
||||
console.debug(resp)
|
||||
})
|
||||
return false
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -2,6 +2,7 @@
|
||||
<a class="item" href="{{$urls->base}}">Inicio</a>
|
||||
@include('layout.body.menu.cuentas')
|
||||
@include('layout.body.menu.categorias')
|
||||
<a class="item" href="{{$urls->base}}/importar">Importar</a>
|
||||
<div class="right menu">
|
||||
<a class="item" href="{{$urls->base}}config">Config</a>
|
||||
</div>
|
||||
|
@ -7,7 +7,18 @@
|
||||
base: '{{$urls->base}}',
|
||||
api: '{{$urls->api}}'
|
||||
}
|
||||
function buildAjax(url, method) {
|
||||
function buildAjax(url, method, files=false) {
|
||||
if (files) {
|
||||
return {
|
||||
url: url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + API_KEY
|
||||
},
|
||||
method: method,
|
||||
processData: false,
|
||||
contentType: false
|
||||
}
|
||||
}
|
||||
return {
|
||||
url: url,
|
||||
headers: {
|
||||
@ -21,8 +32,8 @@
|
||||
let ajax_obj = buildAjax(url, 'GET')
|
||||
return $.ajax(ajax_obj)
|
||||
}
|
||||
function sendPost(url, data) {
|
||||
let ajax_obj = buildAjax(url, 'POST')
|
||||
function sendPost(url, data, files=false) {
|
||||
let ajax_obj = buildAjax(url, 'POST', files)
|
||||
ajax_obj['data'] = data
|
||||
return $.ajax(ajax_obj)
|
||||
}
|
||||
|
Reference in New Issue
Block a user