Compare commits
1 Commits
6e32b1debc
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 742de657c5 |
@ -2,7 +2,6 @@
|
||||
namespace Incoviba\Common\Define\Cartola;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
|
||||
interface Banco
|
||||
{
|
||||
@ -10,7 +9,6 @@ interface Banco
|
||||
* Process bank movements for database inserts
|
||||
* @param UploadedFileInterface $file
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function process(UploadedFileInterface $file): array;
|
||||
|
||||
|
||||
@ -3,16 +3,10 @@ namespace Incoviba\Common\Ideal\Cartola;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
abstract class Banco extends Service implements Define\Cartola\Banco
|
||||
{
|
||||
/**
|
||||
* @param UploadedFileInterface $file
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function process(UploadedFileInterface $file): array
|
||||
{
|
||||
$filename = $this->processUploadedFile($file);
|
||||
@ -46,7 +40,6 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
||||
* Process the temp file from getFilename and remove it
|
||||
* @param string $filename
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
protected function processFile(string $filename): array
|
||||
{
|
||||
@ -95,7 +88,6 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
||||
* Translate uploaded file data to database data
|
||||
* @param string $filename
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
abstract protected function parseFile(string $filename): array;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ class Exception implements ProcessorInterface
|
||||
'trace' => $exception->getTraceAsString(),
|
||||
];
|
||||
if ($exception->getPrevious() !== null) {
|
||||
$output['previous'] = $this->processException($exception->getPrevious());
|
||||
$output['previous'] = $this->processException($exception);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -338,7 +338,6 @@
|
||||
data.errors.forEach(errorData => {
|
||||
console.error(errorData)
|
||||
})
|
||||
throw Error('Error al importar cartolas')
|
||||
}
|
||||
this.data.movimientos = data.movimientos.map(movimiento => new Movimiento(movimiento))
|
||||
this.draw().movimientos()
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
'<td colspan="3">Todas las Unidades</td>',
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button project" data-id="${project.id}">`,
|
||||
'<i class="trash icon"></i>',
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
|
||||
@ -295,66 +295,46 @@
|
||||
}
|
||||
}
|
||||
get columnsData() {
|
||||
const columnValues = {
|
||||
id: reservation => reservation.id,
|
||||
unidades: reservation => reservation.summary,
|
||||
cliente: reservation => reservation.buyer.nombreCompleto,
|
||||
fecha: reservation => this.formatters.date.format(new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)),
|
||||
oferta: reservation => `${this.formatters.ufs.format(reservation.offer)} UF`,
|
||||
valida: reservation => reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>',
|
||||
operador: reservation => reservation.broker?.name ?? '',
|
||||
};
|
||||
const tooltipVariation = 'very wide multiline'
|
||||
const tooltips = this.draw().tooltip()
|
||||
return this.reservations.map(reservation => {
|
||||
const data = {}
|
||||
Object.entries(columnValues).forEach(([key, value]) => {
|
||||
if (key in tooltips) {
|
||||
const processor = tooltips[key]
|
||||
const content = processor(reservation)//.replaceAll(' ', ' ')
|
||||
data[key] = `data-html="${content}" data-variation="${tooltipVariation}">${value(reservation)}`
|
||||
return
|
||||
}
|
||||
data[key] = value(reservation)
|
||||
})
|
||||
return data
|
||||
return this.reservations.map(reservation => {
|
||||
const date = new Date(Date.parse(reservation.date) + 24 * 60 * 60 * 1000)
|
||||
return {
|
||||
id: reservation.id,
|
||||
unidades: reservation.summary,
|
||||
cliente: reservation.buyer.nombreCompleto,
|
||||
fecha: this.formatters.date.format(date),
|
||||
oferta: `${this.formatters.ufs.format(reservation.offer)} UF`,
|
||||
valida: reservation.valid ? '<span class="ui green text">Si</span>' : '<span class="ui red text">No</span>',
|
||||
operador: reservation.broker?.name ?? '',
|
||||
}
|
||||
})
|
||||
}
|
||||
draw() {
|
||||
return {
|
||||
tbody: () => {
|
||||
if (this.reservations.length === 0) {
|
||||
this.empty()
|
||||
return
|
||||
}
|
||||
const tbody = this.component.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
this.columnsData.forEach(column => {
|
||||
const tr = document.createElement('tr')
|
||||
const contents = []
|
||||
const id = column.id
|
||||
this.columnNames.forEach(name => {
|
||||
let td = `<td>${column[name]}</td>`
|
||||
if (column[name].includes('data-content') || column[name].includes('data-html')) {
|
||||
td = `<td ${column[name]}</td>`
|
||||
}
|
||||
contents.push(td)
|
||||
})
|
||||
const actions = this.draw().actions(id)
|
||||
if (actions !== '') {
|
||||
contents.push(actions)
|
||||
}
|
||||
tr.innerHTML = contents.join("\n")
|
||||
tbody.appendChild(tr)
|
||||
})
|
||||
this.show()
|
||||
if (this.reservations.length === 0) {
|
||||
this.empty()
|
||||
return
|
||||
}
|
||||
const tbody = this.component.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
this.columnsData.forEach(column => {
|
||||
const tr = document.createElement('tr')
|
||||
const contents = []
|
||||
const id = column.id
|
||||
this.columnNames.forEach(name => {
|
||||
contents.push(`<td>${column[name]}</td>`)
|
||||
})
|
||||
const actions = this.drawActions(id)
|
||||
if (actions !== '') {
|
||||
contents.push(actions)
|
||||
}
|
||||
tr.innerHTML = contents.join("\n")
|
||||
tbody.appendChild(tr)
|
||||
})
|
||||
this.show()
|
||||
|
||||
$(this.component).find('[data-content],[data-html]').popup()
|
||||
|
||||
this.watch()
|
||||
},
|
||||
actions: id => {
|
||||
return `
|
||||
this.watch()
|
||||
}
|
||||
drawActions(id) {
|
||||
return `
|
||||
<td class="right aligned">
|
||||
<button class="ui green mini icon button approve" data-id="${id}" title="Aprobar">
|
||||
<i class="check icon"></i>
|
||||
@ -363,51 +343,6 @@
|
||||
<i class="trash icon"></i>
|
||||
</button>
|
||||
</td>`
|
||||
},
|
||||
tooltip: () => {
|
||||
return {
|
||||
oferta: reservation => {
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
|
||||
const output = []
|
||||
const table = ['<table>']
|
||||
reservation.units.forEach(unit => {
|
||||
const type = unit.unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
table.push(`<tr><td>${type.charAt(0).toUpperCase() + type.slice(1)} ${unit.unit.descripcion}:</td><td align='right'>${formatter.format(unit.value)} UF</td></tr>`)
|
||||
})
|
||||
if (reservation.broker !== null) {
|
||||
table.push('<tr><td>-----</td></tr>')
|
||||
let commission = reservation.broker.commission
|
||||
table.push(`<tr><td>Broker:</td><td align='right'>${reservation.broker.name}</td><td align='right'>(${commission})</td></tr>`)
|
||||
}
|
||||
if (reservation.promotions.length > 0) {
|
||||
table.push('<tr><td>-----</td></tr>')
|
||||
reservation.promotions.forEach(promotion => {
|
||||
let value = 0
|
||||
switch (promotion.type) {
|
||||
case {{ \Incoviba\Model\Venta\Promotion\Type::FIXED }}:
|
||||
value = `${formatter.format(promotion.amount)} UF`
|
||||
break;
|
||||
case {{ \Incoviba\Model\Venta\Promotion\Type::VARIABLE }}:
|
||||
value = `${formatter.format(promotion.amount * 100)} %`
|
||||
break;
|
||||
}
|
||||
table.push(`<tr><td>${promotion.description}:</td><td align='right'>${value}</td></tr>`)
|
||||
})
|
||||
}
|
||||
table.push('</table>')
|
||||
output.push(table.join(''))
|
||||
return output.join("<br />")
|
||||
},
|
||||
cliente: reservation => {
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
|
||||
return [
|
||||
`RUT: ${formatter.format(reservation.buyer.rut)}-${reservation.buyer.digito}`
|
||||
].join("<br />")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
watch() {
|
||||
if (Object.keys(this.actions).length === 0) {
|
||||
@ -477,10 +412,8 @@
|
||||
return row
|
||||
})
|
||||
}
|
||||
draw() {
|
||||
const draw = super.draw()
|
||||
draw.actions = (id) => {
|
||||
return `
|
||||
drawActions(id) {
|
||||
return `
|
||||
<td class="right aligned">
|
||||
<button class="ui green mini icon button edit" data-id="${id}" title="Promesar">
|
||||
<i class="right chevron icon"></i>
|
||||
@ -489,8 +422,6 @@
|
||||
<i class="trash icon"></i>
|
||||
</button>
|
||||
</td>`
|
||||
}
|
||||
return draw
|
||||
}
|
||||
actions = {
|
||||
edit: event => {
|
||||
@ -517,56 +448,6 @@
|
||||
super({component_id, formatters})
|
||||
}
|
||||
|
||||
draw() {
|
||||
const draw = super.draw()
|
||||
const tooltip = draw.tooltip()
|
||||
tooltip['valida'] = reservation => {
|
||||
const formatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
|
||||
|
||||
const output = []
|
||||
const table = [
|
||||
'<table>',
|
||||
'<thead>',
|
||||
'<tr>',
|
||||
'<th></th>',
|
||||
'<th>Base Oferta</th>',
|
||||
'<th>Precio</th>',
|
||||
'</thead>'
|
||||
]
|
||||
reservation.units.forEach(unit => {
|
||||
let type = unit.unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
type = type.charAt(0).toUpperCase() + type.slice(1)
|
||||
const base = unit.base ?? (unit.value ?? 0);
|
||||
const price = unit.unit.current_precio?.valor ?? 0
|
||||
const diff = (base - price) / price * 100
|
||||
table.push(`<tr><td>${type} ${unit.unit.descripcion}:</td><td align='right'> ${formatter.format(base)} UF</td><td align='right'>${formatter.format(price)} UF</td><td align='right'>(${formatter.format(diff)} %)</td></tr>`)
|
||||
})
|
||||
if (reservation.broker !== null) {
|
||||
table.push('<tr><td>-----</td></tr>')
|
||||
let commission = reservation.broker.commission
|
||||
table.push(`<tr><td>Broker:</td><td align='right'>${reservation.broker.name}</td><td align='right'>(${commission})</td></tr>`)
|
||||
}
|
||||
reservation.promotions.forEach(promotion => {
|
||||
let value = 0
|
||||
switch (promotion.type) {
|
||||
case {{ \Incoviba\Model\Venta\Promotion\Type::FIXED }}:
|
||||
value = `${formatter.format(promotion.amount)} UF`
|
||||
break;
|
||||
case {{ \Incoviba\Model\Venta\Promotion\Type::VARIABLE }}:
|
||||
value = `${formatter.format(promotion.amount * 100)} %`
|
||||
break;
|
||||
}
|
||||
table.push(`<tr><td>${promotion.description}:</td><td align='right'>${value}</td></tr>`)
|
||||
})
|
||||
table.push('</table>')
|
||||
output.push(table.join(''))
|
||||
return output.join("<br />")
|
||||
}
|
||||
draw['tooltip'] = () => {
|
||||
return tooltip
|
||||
}
|
||||
return draw
|
||||
}
|
||||
actions = {
|
||||
approve: event => {
|
||||
event.preventDefault()
|
||||
@ -601,12 +482,8 @@
|
||||
return data[idx]
|
||||
})
|
||||
}
|
||||
draw() {
|
||||
const draw = super.draw()
|
||||
draw.actions = (id) => {
|
||||
return ''
|
||||
}
|
||||
return draw
|
||||
drawActions(id) {
|
||||
return ''
|
||||
}
|
||||
watch() {}
|
||||
|
||||
@ -645,7 +522,7 @@
|
||||
if (json.reservations.length > 0) {
|
||||
component.set.reservations(json.reservations)
|
||||
}
|
||||
component.draw().tbody()
|
||||
component.draw()
|
||||
})
|
||||
},
|
||||
active: project_id => {
|
||||
|
||||
@ -131,41 +131,6 @@
|
||||
<h4 class="ui dividing header">Unidades <span id="add_project_name"></span></h4>
|
||||
<div class="fields" id="add_unit_buttons"></div>
|
||||
<div id="add_units"></div>
|
||||
<h4 class="ui dividing header">Forma de Pago</h4>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_pie" id="add_has_pie" />
|
||||
<label>¿Tiene Pie?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field" id="add_pie">
|
||||
<label>Pie</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="pie" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field" id="add_cuotas">
|
||||
<label>Cuotas</label>
|
||||
<input type="text" name="cuotas" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_credit" id="add_has_credit" />
|
||||
<label>¿Tiene Crédito?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field" id="add_credit">
|
||||
<label>Crédito</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="credit" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
@ -188,8 +153,7 @@
|
||||
elements: ''
|
||||
}
|
||||
data = {
|
||||
promotions: [],
|
||||
selected: []
|
||||
promotions: []
|
||||
}
|
||||
components = {
|
||||
button: null,
|
||||
@ -207,16 +171,16 @@
|
||||
this.setup()
|
||||
}
|
||||
add() {
|
||||
const idx = Math.max(this.data.selected.length, 0, Math.max(...this.data.selected) + 1)
|
||||
this.data.selected.push(idx)
|
||||
const idx = Math.max(this.data.promotions.length, 0, Math.max(...this.data.promotions) + 1)
|
||||
this.data.promotions.push(idx)
|
||||
this.draw.promotions()
|
||||
}
|
||||
reset() {
|
||||
this.data.selected = []
|
||||
this.data.promotions = []
|
||||
this.draw.promotions()
|
||||
}
|
||||
remove(idx) {
|
||||
this.data.selected = this.data.selected.filter(promotion => promotion !== idx)
|
||||
this.data.promotions = this.data.promotions.filter(promotion => promotion !== idx)
|
||||
this.draw.promotions()
|
||||
}
|
||||
draw = {
|
||||
@ -249,10 +213,7 @@
|
||||
return
|
||||
}
|
||||
this.components.button.parentElement.style.display = this.display.button
|
||||
if (this.data.selected.length === 0) {
|
||||
return
|
||||
}
|
||||
this.components.promotions.innerHTML = this.data.selected.map(idx => {
|
||||
this.components.promotions.innerHTML = this.data.promotions.map((promotion, idx) => {
|
||||
return this.draw.promotion(idx)
|
||||
}).join('')
|
||||
this.components.promotions.querySelectorAll('.dropdown').forEach(dropdown => {
|
||||
@ -401,7 +362,7 @@
|
||||
'<div class="three wide field">',
|
||||
'<label>Valor</label>',
|
||||
'<div class="ui right labeled input">',
|
||||
'<input type="text" name="add_units_value[]" placeholder="Valor" />',
|
||||
'<input type="number" name="add_units_value[]" placeholder="Valor" />',
|
||||
'<div class="ui basic label">UF</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
@ -433,101 +394,6 @@
|
||||
this.draw.buttons()
|
||||
}
|
||||
}
|
||||
class AddModalPayments {
|
||||
ids = {
|
||||
pie: {
|
||||
checkbox: 'add_has_pie',
|
||||
value: 'add_pie',
|
||||
installments: 'add_cuotas'
|
||||
},
|
||||
credit: {
|
||||
checkbox: 'add_has_credit',
|
||||
value: 'add_credit'
|
||||
}
|
||||
}
|
||||
components = {
|
||||
pie: {
|
||||
$checkbox: null,
|
||||
value: null,
|
||||
installments: null
|
||||
},
|
||||
credit: {
|
||||
$checkbox: null,
|
||||
value: null
|
||||
}
|
||||
}
|
||||
data = {
|
||||
pie: {
|
||||
value: '',
|
||||
installments: ''
|
||||
},
|
||||
credit: {
|
||||
value: ''
|
||||
}
|
||||
}
|
||||
constructor() {
|
||||
this.setup()
|
||||
}
|
||||
reset() {
|
||||
this.components.pie.$checkbox.prop('checked', false)
|
||||
this.components.pie.value.value = ''
|
||||
this.components.pie.installments.value = ''
|
||||
this.components.credit.$checkbox.prop('checked', false)
|
||||
this.components.credit.value.value = ''
|
||||
}
|
||||
show = {
|
||||
pie: () => {
|
||||
this.components.pie.value.style.display = this.data.pie.value
|
||||
this.components.pie.installments.style.display = this.data.pie.installments
|
||||
},
|
||||
credit: () => {
|
||||
this.components.credit.value.style.display = this.data.credit.value
|
||||
}
|
||||
}
|
||||
hide = {
|
||||
pie: () => {
|
||||
this.components.pie.value.style.display = 'none'
|
||||
this.components.pie.installments.style.display = 'none'
|
||||
},
|
||||
credit: () => {
|
||||
this.components.credit.value.style.display = 'none'
|
||||
},
|
||||
all: () => {
|
||||
this.hide.pie()
|
||||
this.hide.credit()
|
||||
}
|
||||
}
|
||||
setup() {
|
||||
this.components.pie.$checkbox = $(`#${this.ids.pie.checkbox}`)
|
||||
this.components.pie.value = document.getElementById(this.ids.pie.value)
|
||||
this.components.pie.installments = document.getElementById(this.ids.pie.installments)
|
||||
this.components.credit.$checkbox = $(`#${this.ids.credit.checkbox}`)
|
||||
this.components.credit.value = document.getElementById(this.ids.credit.value)
|
||||
|
||||
this.components.pie.$checkbox.checkbox()
|
||||
this.components.pie.$checkbox.change(changeEvent => {
|
||||
if (this.components.pie.$checkbox.is(':checked')) {
|
||||
this.show.pie()
|
||||
return
|
||||
}
|
||||
this.hide.pie()
|
||||
})
|
||||
this.components.credit.$checkbox.checkbox()
|
||||
this.components.credit.$checkbox.change(changeEvent => {
|
||||
if (this.components.credit.$checkbox.is(':checked')) {
|
||||
this.show.credit()
|
||||
return
|
||||
}
|
||||
this.hide.credit()
|
||||
})
|
||||
|
||||
this.data.pie.value = this.components.pie.value.style.display
|
||||
this.data.pie.installments = this.components.pie.installments.style.display
|
||||
this.data.credit.value = this.components.credit.value.style.display
|
||||
|
||||
this.hide.all()
|
||||
}
|
||||
}
|
||||
class AddReservationModal {
|
||||
ids = {
|
||||
modal: '',
|
||||
@ -563,7 +429,6 @@
|
||||
project_name: null,
|
||||
unit_buttons: null,
|
||||
units: null,
|
||||
payments: null,
|
||||
$loader: null
|
||||
}
|
||||
data = {
|
||||
@ -615,8 +480,8 @@
|
||||
this.get.promotions(project_id).then(promotions => {
|
||||
this.components.promotions.data.promotions = promotions.map(promotion => {
|
||||
return {
|
||||
text: promotion.description,
|
||||
name: promotion.description,
|
||||
text: promotion.name,
|
||||
name: promotion.name,
|
||||
value: promotion.id
|
||||
}
|
||||
})
|
||||
@ -644,7 +509,6 @@
|
||||
this.components.form.reset()
|
||||
this.components.promotions.reset()
|
||||
this.components.units.reset()
|
||||
this.components.payments.reset()
|
||||
}
|
||||
add() {
|
||||
const url = '/api/ventas/reservation/add'
|
||||
@ -660,16 +524,6 @@
|
||||
const birthdate = this.components.$birthdate.calendar('get date')
|
||||
body.set('add_buyer_birthdate', [birthdate.getFullYear(), birthdate.getMonth() + 1, birthdate.getDate()].join('-'))
|
||||
|
||||
if (this.components.payments.components.pie.$checkbox.checkbox('is unchecked')) {
|
||||
body.delete('add_pie')
|
||||
body.delete('add_cuotas')
|
||||
}
|
||||
body.delete('add_has_pie')
|
||||
if (this.components.payments.components.credit.$checkbox.checkbox('is unchecked')) {
|
||||
body.delete('add_credit')
|
||||
}
|
||||
body.delete('add_has_credit')
|
||||
|
||||
body.delete('comuna')
|
||||
body.delete('region')
|
||||
body.delete('broker')
|
||||
@ -818,9 +672,6 @@
|
||||
}
|
||||
fill = {
|
||||
user: user => {
|
||||
if (typeof user === 'undefined' || user === null) {
|
||||
return
|
||||
}
|
||||
const form = this.components.form
|
||||
form.querySelector('input[name="add_buyer_name"]').value = user.nombres || ''
|
||||
form.querySelector('input[name="add_buyer_last_name"]').value = user.apellidoPaterno || ''
|
||||
@ -902,7 +753,6 @@
|
||||
this.components.projects = document.getElementById(this.ids.projects)
|
||||
this.components.project_name = document.getElementById(this.ids.project_name)
|
||||
this.components.units = new AddModalUnits(this)
|
||||
this.components.payments = new AddModalPayments()
|
||||
|
||||
this.components.$modal.modal({
|
||||
onApprove: () => {
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
namespace Incoviba\Controller\API\Contabilidad;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
@ -118,21 +117,24 @@ class Cartolas extends Controller
|
||||
UPLOAD_ERR_CANT_WRITE => 'No se pudo escribir el archivo',
|
||||
UPLOAD_ERR_EXTENSION => 'Una extensión de PHP detuvo la subida del archivo'
|
||||
];
|
||||
if (!is_array($files['file'])) {
|
||||
$files['file'] = [$files['file']];
|
||||
$body['cuenta_id'] = [$body['cuenta_id']];
|
||||
}
|
||||
foreach ($files['file'] as $i => $file) {
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
$output['errors'] []= ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]];
|
||||
continue;
|
||||
if (is_array($files['file'])) {
|
||||
foreach ($files['file'] as $i => $file) {
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
$output['errors'] []= ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]];
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file));
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
try {
|
||||
$output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file));
|
||||
} catch (Read $exception) {
|
||||
$output['errors'] []= ['filename' => $file->getClientFilename(),
|
||||
'error' => ['message' => $exception->getMessage(), 'file' => $exception->getFile(),
|
||||
'line' => $exception->getLine()]];
|
||||
} else {
|
||||
$file = $files['file'];
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
$output['errors'][] = ['filename' => $file->getClientFilename(), 'error' => $errors[$file->getError()]];
|
||||
} else {
|
||||
try {
|
||||
$output['movimientos'] = $cartolaService->import($body['cuenta_id'], $file);
|
||||
} catch (EmptyResult) {}
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
|
||||
@ -4,11 +4,8 @@ namespace Incoviba\Controller\API\Ventas;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Exception\ServiceAction\Update;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
@ -45,7 +42,7 @@ class Escrituras
|
||||
try {
|
||||
$escrituraService->edit($venta_id, $body);
|
||||
$output['success'] = true;
|
||||
} catch (Read|Update|EmptyResult) {}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,13 +22,10 @@ class Reservation extends Common\Ideal\Model
|
||||
public function withCommission(): float
|
||||
{
|
||||
$base = 0;
|
||||
foreach ($this->units as &$unit) {
|
||||
$unitBase = $unit->value;
|
||||
foreach ($this->units as $unit) {
|
||||
foreach ($this->promotions as $promotion) {
|
||||
$unitBase = $promotion->activate()->reverse($unit->unit, $unitBase, $this->broker);
|
||||
$base += $promotion->activate()->reverse($unit['unit'], $unit['value'], $this->broker);
|
||||
}
|
||||
$unit->base = $unitBase;
|
||||
$base += $unitBase;
|
||||
}
|
||||
return $base;
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ class Datos extends Ideal\Repository
|
||||
'persona_rut', 'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||
'nacionalidad', 'ocupacion'
|
||||
], [
|
||||
$model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento->format('Y-m-d'),
|
||||
$model->persona->rut, $model->direccion?->id, $model->telefono, $model->email, $model->fechaNacimiento,
|
||||
$model->sexo, $model->estadoCivil, $model->nacionalidad, $model->ocupacion
|
||||
]);
|
||||
return $model;
|
||||
|
||||
@ -239,11 +239,7 @@ class Reservation extends Common\Ideal\Repository
|
||||
$exceptions[] = new Common\Implement\Exception\EmptyResult('No cancelled reservations', $exception);
|
||||
}
|
||||
if (count($reservations) === 0) {
|
||||
$exception = null;
|
||||
if (count($exceptions) > 0) {
|
||||
$exception = last($exceptions);
|
||||
}
|
||||
throw new Common\Implement\Exception\EmptyResult('No rejected nor cancelled reservations', $exception);
|
||||
throw new Common\Implement\Exception\EmptyResult('No rejected nor cancelled reservations', last($exceptions));
|
||||
}
|
||||
return $reservations;
|
||||
}
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use DateMalformedStringException;
|
||||
use PDOException;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Incoviba\Common\Define\Cartola\Banco;
|
||||
use Incoviba\Common\Define\Contabilidad\Exporter;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement\Exception;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Cartola extends Service
|
||||
{
|
||||
@ -35,13 +32,6 @@ class Cartola extends Service
|
||||
$this->bancos[$name] = $banco;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Contabilidad\Banco $banco
|
||||
* @param UploadedFileInterface $file
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function process(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array
|
||||
{
|
||||
return $this->bancos[strtolower($banco->nombre)]->process($file);
|
||||
@ -103,19 +93,9 @@ class Cartola extends Service
|
||||
return compact('cartola', 'movimientos');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param UploadedFileInterface $file
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function import(int $cuenta_id, UploadedFileInterface $file): array
|
||||
{
|
||||
try {
|
||||
$cuenta = $this->cuentaRepository->fetchById($cuenta_id);
|
||||
} catch (Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
$cuenta = $this->cuentaRepository->fetchById($cuenta_id);
|
||||
$movimientos = $this->process($cuenta->banco, $file);
|
||||
|
||||
$inmobiliaria = $cuenta->inmobiliaria;
|
||||
@ -126,23 +106,15 @@ class Cartola extends Service
|
||||
if (array_key_exists('centro_costo', $dataMovimiento) and $dataMovimiento['centro_costo'] !== 0) {
|
||||
$dataMovimiento['centro_costo_id'] = $dataMovimiento['centro_costo'];
|
||||
}
|
||||
try {
|
||||
$dataMovimiento['fecha'] = new DateTimeImmutable($dataMovimiento['fecha']);
|
||||
} catch (DateMalformedStringException) {
|
||||
continue;
|
||||
}
|
||||
$dataMovimiento['fecha'] = new DateTimeImmutable($dataMovimiento['fecha']);
|
||||
if (array_key_exists('rut', $dataMovimiento)) {
|
||||
if ($dataMovimiento['rut'] === '') {
|
||||
unset($dataMovimiento['rut']);
|
||||
$ruts = $this->parseRut($dataMovimiento['rut']);
|
||||
if (key_exists('rut', $ruts)) {
|
||||
$dataMovimiento['rut'] = $ruts['rut'];
|
||||
$dataMovimiento['digito'] = $ruts['digito'];
|
||||
} else {
|
||||
$ruts = $this->parseRut($dataMovimiento['rut']);
|
||||
if (key_exists('rut', $ruts)) {
|
||||
$dataMovimiento['rut'] = $ruts['rut'];
|
||||
$dataMovimiento['digito'] = $ruts['digito'];
|
||||
} else {
|
||||
$dataMovimiento['rut'] = $ruts[0]['rut'];
|
||||
$dataMovimiento['digito'] = $ruts[0]['digito'];
|
||||
}
|
||||
$dataMovimiento['rut'] = $ruts[0]['rut'];
|
||||
$dataMovimiento['digito'] = $ruts[0]['digito'];
|
||||
}
|
||||
}
|
||||
try {
|
||||
@ -161,28 +133,14 @@ class Cartola extends Service
|
||||
$fechas = array_unique(array_map(function($movimiento) {
|
||||
return $movimiento['fecha']->format('Y-m-d');
|
||||
}, $movimientos));
|
||||
if (count($fechas) === 0) {
|
||||
throw new Read(__CLASS__);
|
||||
}
|
||||
|
||||
foreach ($fechas as $dia) {
|
||||
try {
|
||||
$dayDate = new DateTimeImmutable($dia);
|
||||
} catch (DateMalformedStringException) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $dayDate);
|
||||
$this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, new DateTimeImmutable($dia));
|
||||
continue;
|
||||
} catch (Exception\EmptyResult) {}
|
||||
|
||||
$movs = array_filter($movimientos, function($movimiento) use ($dia) {
|
||||
return $movimiento['fecha']->format('Y-m-d') === $dia;
|
||||
return $movimiento['fecha'] === $dia;
|
||||
});
|
||||
if (count($movs) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cargos = array_sum(array_map(function($movimiento) {
|
||||
return $movimiento['cargo'];
|
||||
}, $movs));
|
||||
@ -195,19 +153,11 @@ class Cartola extends Service
|
||||
'abonos' => $abonos,
|
||||
'saldo' => $saldo
|
||||
];
|
||||
$this->buildCartola($cuenta, $dayDate, $cartolaData);
|
||||
$this->buildCartola($cuenta, new DateTimeImmutable($dia), $cartolaData);
|
||||
}
|
||||
|
||||
try {
|
||||
$startDate = new DateTimeImmutable(min($fechas));
|
||||
} catch (DateMalformedStringException $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
try {
|
||||
$endDate = new DateTimeImmutable(max($fechas));
|
||||
} catch (DateMalformedStringException $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
$startDate = new DateTimeImmutable(min($fechas));
|
||||
$endDate = new DateTimeImmutable(max($fechas));
|
||||
$movimientosFaltantes = $this->movimientoService->findMissing($cuenta, $addedMovimientos, $startDate, $endDate);
|
||||
$movimientosObsoletos = [];
|
||||
if (count($movimientosFaltantes) > 0) {
|
||||
|
||||
@ -3,7 +3,6 @@ namespace Incoviba\Service\Contabilidad\Cartola;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
@ -11,8 +10,8 @@ class Itau extends Banco
|
||||
{
|
||||
use isExcel;
|
||||
|
||||
const int CUENTA_CORRIENTE = 0;
|
||||
const int ULTIMOS_MOVIMIENTOS = 1;
|
||||
const CUENTA_CORRIENTE = 0;
|
||||
const ULTIMOS_MOVIMIENTOS = 1;
|
||||
|
||||
public function processMovimientosDiarios(array $movimientos): array
|
||||
{
|
||||
@ -45,12 +44,6 @@ class Itau extends Banco
|
||||
$ext = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
|
||||
return "/tmp/cartola.{$ext}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
protected function parseFile(string $filename): array
|
||||
{
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
@ -69,7 +62,7 @@ class Itau extends Banco
|
||||
break;
|
||||
}
|
||||
} catch (PhpSpreadsheet\Exception $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
$this->logger->critical($exception);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -173,11 +166,6 @@ class Itau extends Banco
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PhpSpreadsheet\Worksheet\Worksheet $sheet
|
||||
* @return int
|
||||
* @throws PhpSpreadsheet\Exception
|
||||
*/
|
||||
protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int
|
||||
{
|
||||
foreach ($sheet->getRowIterator(1, 10) as $row) {
|
||||
@ -189,7 +177,7 @@ class Itau extends Banco
|
||||
return self::ULTIMOS_MOVIMIENTOS;
|
||||
}
|
||||
}
|
||||
throw new PhpSpreadsheet\Exception('Incorrect type of Worksheet');
|
||||
throw new PhpSpreadsheet\Exception();
|
||||
}
|
||||
protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array
|
||||
{
|
||||
|
||||
@ -12,9 +12,6 @@ class MiIndicador implements Provider
|
||||
public function __construct(protected ClientInterface $client) {}
|
||||
|
||||
/**
|
||||
* @param string $money_symbol
|
||||
* @param DateTimeInterface|null $dateTime
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
||||
@ -36,7 +33,7 @@ class MiIndicador implements Provider
|
||||
$body = $response->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
|
||||
if (empty($json) or !isset($json->codigo) or !isset($json->serie) or $json->codigo !== $money_symbol or count($json->serie) === 0) {
|
||||
if (empty($json) or $json->codigo !== $money_symbol or count($json->serie) === 0) {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
return $json->serie[0]->valor;
|
||||
|
||||
@ -236,9 +236,6 @@ class Persona extends Ideal\Service
|
||||
} else {
|
||||
$newKey = substr($key, strlen('address_'));
|
||||
}
|
||||
if ($newKey === 'id') {
|
||||
continue;
|
||||
}
|
||||
$addressData[$newKey] = $value;
|
||||
}
|
||||
if (!empty($addressData)) {
|
||||
@ -261,7 +258,7 @@ class Persona extends Ideal\Service
|
||||
'birthdate' => 'fecha_nacimiento',
|
||||
];
|
||||
foreach ($data as $key => $value) {
|
||||
if (array_key_exists($key, $dataMap) and trim($value) !== '') {
|
||||
if (array_key_exists($key, $dataMap)) {
|
||||
$data[$dataMap[$key]] = $value;
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
@ -4,8 +4,6 @@ namespace Incoviba\Service\Venta;
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Exception\ServiceAction\Update;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
@ -58,15 +56,13 @@ class Escritura extends Ideal\Service
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
* @throws Read
|
||||
* @throws Update
|
||||
*/
|
||||
public function edit(int $venta_id, array $data): Model\Venta\Escritura
|
||||
{
|
||||
$venta = $this->ventaService->getById($venta_id);
|
||||
$estado = $venta->currentEstado();
|
||||
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
|
||||
throw new Update(__CLASS__);
|
||||
throw new EmptyResult('');
|
||||
}
|
||||
try {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
|
||||
@ -251,12 +251,6 @@ class Reservation extends Ideal\Service\API
|
||||
return $this->stateRepository->fetchByReservation($reservation_id);
|
||||
})
|
||||
);
|
||||
foreach ($model->units as &$unit) {
|
||||
$unit->unit = $this->unitService->getById($unit->unit->id);
|
||||
}
|
||||
foreach ($model->promotions as &$promotion) {
|
||||
$promotion = $this->promotionService->getById($promotion->id);
|
||||
}
|
||||
$model->buyer = $this->personaService->getById($model->buyer->rut);
|
||||
return $model;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user