Compare commits
1 Commits
ebaf708f79
...
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;
|
||||
|
||||
|
||||
@ -13,5 +13,4 @@ interface Provider
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float;
|
||||
public function supported(string $money_symbol): bool;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Money;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
abstract class Provider implements Define\Money\Provider
|
||||
{
|
||||
public function __construct(protected LoggerInterface $logger) {}
|
||||
|
||||
protected array $supportedMap = [];
|
||||
public function supported(string $money_symbol): bool
|
||||
{
|
||||
return in_array(strtolower($money_symbol), array_keys($this->supportedMap), true);
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
facturas: () => {
|
||||
document.getElementById(this.ids.facturas).innerHTML = this.venta.draw().facturas(this.formatters)
|
||||
this.venta.watch().facturas()
|
||||
$('[data-html]').popup()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -220,47 +220,9 @@
|
||||
},
|
||||
resumen: ({no, classes, formatters}) => {
|
||||
const emptyTerreno = '<div class="ui tiny red horizontal circular label">0</div>'
|
||||
const calculoTerreno = [
|
||||
[
|
||||
`Base Terreno (${formatters.date.format(this.props.terreno.fecha)})`,
|
||||
`\$${formatters.pesos.format(this.props.terreno.valor)}`
|
||||
],
|
||||
[
|
||||
`IPC (${formatters.date.format(this.props.fecha)})`,
|
||||
`${formatters.percent.format({{ $ipc }})}%`
|
||||
],
|
||||
[
|
||||
'Prorrateo',
|
||||
`${formatters.percent.format(this.props.detalle.descuento * 100)}%`
|
||||
],
|
||||
[
|
||||
'Proporcion',
|
||||
`${(this.props.proporcion * 100).toFixed(2).replace('.', ',')}%`
|
||||
],
|
||||
[
|
||||
'Terreno Aplicado',
|
||||
`\$${formatters.pesos.format(this.props.detalle.terreno)}`
|
||||
]
|
||||
]
|
||||
const tableClasses = [
|
||||
'',
|
||||
" align='right'"
|
||||
]
|
||||
const calculoTerrenoTable = [
|
||||
'<table>'
|
||||
]
|
||||
calculoTerreno.forEach(items => {
|
||||
const row = []
|
||||
items.forEach((cell, idx) => {
|
||||
row.push(`<td${tableClasses[idx]}>${cell}</td>`)
|
||||
})
|
||||
calculoTerrenoTable.push(`<tr>${row.join('')}</tr>`)
|
||||
})
|
||||
calculoTerrenoTable.push('</table>')
|
||||
|
||||
const data = [
|
||||
no,
|
||||
'Valor con Terreno: $' + formatters.pesos.format(this.props.detalle.base) + ' - Menos valor terreno: <span data-variation="wide multiline" data-html="' + calculoTerrenoTable.join('') + '">$' + ((this.props.detalle.terreno > 0) ? formatters.pesos.format(-this.props.detalle.terreno) : emptyTerreno) + '</span><br />' +
|
||||
'Valor con Terreno: $' + formatters.pesos.format(this.props.detalle.base) + ' - Menos valor terreno: $' + ((this.props.detalle.terreno > 0) ? formatters.pesos.format(-this.props.detalle.terreno) : emptyTerreno) + '<br />' +
|
||||
'Base imponible (Neto): $' + formatters.pesos.format(this.props.detalle.neto) + '<br />' +
|
||||
'IVA: $' + formatters.pesos.format(this.props.detalle.iva) + '<br />' +
|
||||
'SUBTOTAL (Bruto): $' + formatters.pesos.format(this.props.detalle.bruto) + '<br />' +
|
||||
|
||||
@ -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: () => {
|
||||
|
||||
@ -15,24 +15,21 @@ return [
|
||||
);
|
||||
},
|
||||
Incoviba\Service\Money::class => function(ContainerInterface $container) {
|
||||
$mindicador = new Incoviba\Service\Money\MiIndicador($container->get(Psr\Log\LoggerInterface::class), new GuzzleHttp\Client([
|
||||
$mindicador = new Incoviba\Service\Money\MiIndicador(new GuzzleHttp\Client([
|
||||
'base_uri' => 'https://mindicador.cl/api/',
|
||||
'headers' => ['Accept' => 'application/json']
|
||||
]));
|
||||
$ine = new Incoviba\Service\Money\Ine($container->get(Psr\Log\LoggerInterface::class), new GuzzleHttp\Client([
|
||||
$ine = new Incoviba\Service\Money\Ine(new GuzzleHttp\Client([
|
||||
'base_uri' => 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion'
|
||||
]));
|
||||
$sii = new Incoviba\Service\Money\SII($container->get(Psr\Log\LoggerInterface::class), new GuzzleHttp\Client([
|
||||
$sii = new Incoviba\Service\Money\SII(new GuzzleHttp\Client([
|
||||
'base_uri' => 'https://www.sii.cl/valores_y_fechas/'
|
||||
]), $container->get(Incoviba\Repository\UF::class));
|
||||
$findic = new Incoviba\Service\Money\Findic($container->get(Psr\Log\LoggerInterface::class), new GuzzleHttp\Client([
|
||||
'base_uri' => 'https://findic.cl/api/'
|
||||
]));
|
||||
return new Incoviba\Service\Money($container->get(Psr\Log\LoggerInterface::class))
|
||||
->register($findic)
|
||||
->register($sii)
|
||||
->register($ine)
|
||||
->register($mindicador);
|
||||
return (new Incoviba\Service\Money($container->get(Psr\Log\LoggerInterface::class)))
|
||||
->register('uf', $mindicador)
|
||||
->register('uf', $sii)
|
||||
->register('usd', $mindicador)
|
||||
->register('ipc', $ine);
|
||||
},
|
||||
Predis\ClientInterface::class => function(ContainerInterface $container) {
|
||||
$options = [
|
||||
@ -49,7 +46,7 @@ return [
|
||||
return new Predis\Client($options);
|
||||
},
|
||||
Incoviba\Service\Contabilidad\Cartola::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Contabilidad\Cartola(
|
||||
return (new Incoviba\Service\Contabilidad\Cartola(
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
||||
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class),
|
||||
@ -58,7 +55,7 @@ return [
|
||||
$container->get(Incoviba\Repository\Contabilidad\Movimiento::class),
|
||||
$container->get(Incoviba\Service\Contabilidad\Movimiento::class),
|
||||
$container->get(Incoviba\Repository\Contabilidad\Cartola::class)
|
||||
)
|
||||
))
|
||||
->register('security', $container->get(Incoviba\Service\Contabilidad\Cartola\Security::class))
|
||||
->register('itau', $container->get(Incoviba\Service\Contabilidad\Cartola\Itau::class))
|
||||
->register('santander', $container->get(Incoviba\Service\Contabilidad\Cartola\Santander::class))
|
||||
@ -92,9 +89,9 @@ return [
|
||||
$container->get('nubox')->get('url'));
|
||||
},
|
||||
Incoviba\Service\Informe::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Informe(
|
||||
return (new Incoviba\Service\Informe(
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
$container->get('folders')->get('informes')
|
||||
$container->get('folders')->get('informes'))
|
||||
)
|
||||
->register('xlsx', Incoviba\Service\Informe\Excel::class);
|
||||
},
|
||||
@ -107,15 +104,15 @@ return [
|
||||
);
|
||||
},
|
||||
Incoviba\Service\Contabilidad\Cartola\Santander::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Contabilidad\Cartola\Santander(
|
||||
return (new Incoviba\Service\Contabilidad\Cartola\Santander(
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
)
|
||||
))
|
||||
->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\Santander\OfficeBanking::class));
|
||||
},
|
||||
Incoviba\Service\Contabilidad\Cartola\BCI::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Contabilidad\Cartola\BCI(
|
||||
return (new Incoviba\Service\Contabilidad\Cartola\BCI(
|
||||
$container->get(Psr\Log\LoggerInterface::class),
|
||||
)
|
||||
))
|
||||
->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\BCI\Mes::class));
|
||||
},
|
||||
'TokuClient' => function(ContainerInterface $container) {
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -5,13 +5,11 @@ use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class IPC
|
||||
{
|
||||
protected string $redisKey = 'ipc';
|
||||
public function __construct(protected LoggerInterface $logger, protected Redis $redisService,
|
||||
protected Money $moneyService) {}
|
||||
public function __construct(protected Redis $redisService, protected Money $moneyService) {}
|
||||
|
||||
public function get(DateTimeInterface $from, DateTimeInterface $to = new DateTimeImmutable()): float
|
||||
{
|
||||
@ -35,7 +33,7 @@ class IPC
|
||||
ksort($ipcs);
|
||||
$this->redisService->set($this->redisKey, json_encode($ipcs), 60 * 60 * 24 * 30);
|
||||
}
|
||||
return $ipcs[$dateKey] * ($ipcs[$dateKey] > 1 ? 1/100 : 1);
|
||||
return $ipcs[$dateKey];
|
||||
}
|
||||
public function readjust(float $base, DateTimeInterface $from, DateTimeInterface $to = new DateTimeImmutable()):float
|
||||
{
|
||||
|
||||
@ -8,29 +8,32 @@ use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
|
||||
class Money
|
||||
{
|
||||
const string UF = 'uf';
|
||||
const string USD = 'usd';
|
||||
const string IPC = 'ipc';
|
||||
const UF = 'uf';
|
||||
const USD = 'usd';
|
||||
const IPC = 'ipc';
|
||||
|
||||
public function __construct(protected LoggerInterface $logger) {}
|
||||
|
||||
protected array $providers = [];
|
||||
public function register(Provider $provider): Money
|
||||
protected array $providers;
|
||||
public function register(string $name, Provider $provider): Money
|
||||
{
|
||||
if (in_array($provider, $this->providers)) {
|
||||
if (isset($this->providers) and isset($this->providers[$name]) and in_array($provider, $this->providers[$name])) {
|
||||
return $this;
|
||||
}
|
||||
$this->providers []= $provider;
|
||||
if (!isset($this->providers[$name])) {
|
||||
$this->providers[$name] = [];
|
||||
}
|
||||
$this->providers[$name] []= $provider;
|
||||
return $this;
|
||||
}
|
||||
public function getProviders(string $name): array
|
||||
{
|
||||
return array_values(array_filter($this->providers, fn($provider) => $provider->supported($name)));
|
||||
return $this->providers[$name];
|
||||
}
|
||||
|
||||
public function get(string $name, DateTimeInterface $dateTime): float
|
||||
public function get(string $provider, DateTimeInterface $dateTime): float
|
||||
{
|
||||
$providers = $this->getProviders($name);
|
||||
$providers = $this->getProviders($provider);
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
return $provider->get(self::getSymbol($provider), $dateTime);
|
||||
@ -42,7 +45,7 @@ class Money
|
||||
}
|
||||
public function getUF(?DateTimeInterface $dateTime = null): float
|
||||
{
|
||||
$providers = $this->getProviders(self::UF);
|
||||
$providers = $this->getProviders('uf');
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
return $provider->get(self::UF, $dateTime);
|
||||
@ -57,13 +60,10 @@ class Money
|
||||
if ($start >= $end) {
|
||||
return 0;
|
||||
}
|
||||
$providers = $this->getProviders(self::IPC);
|
||||
$providers = $this->getProviders('ipc');
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
if (method_exists($provider, 'getVar')) {
|
||||
return $provider->getVar($start, $end);
|
||||
}
|
||||
return $provider->get(self::IPC, $end);
|
||||
return $provider->getVar($start, $end);
|
||||
} catch (EmptyResponse $exception) {
|
||||
$this->logger->notice($exception);
|
||||
}
|
||||
@ -72,7 +72,7 @@ class Money
|
||||
}
|
||||
public function getUSD(DateTimeInterface $dateTime): float
|
||||
{
|
||||
$providers = $this->getProviders(self::USD);
|
||||
$providers = $this->getProviders('usd');
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
return $provider->get(self::USD, $dateTime);
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Money;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use JsonException;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service\Money;
|
||||
|
||||
class Findic extends Ideal\Money\Provider
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected ClientInterface $client)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
protected string $url = 'https://findic.cl/api/';
|
||||
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
||||
{
|
||||
if (!$this->supported($money_symbol)) {
|
||||
throw new EmptyResponse($money_symbol);
|
||||
}
|
||||
if ($dateTime === null) {
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
return match (strtolower($money_symbol)) {
|
||||
Money::UF, Money::USD => $this->getDate(strtolower($money_symbol), $dateTime),
|
||||
Money::IPC => $this->getSum(strtolower($money_symbol), $dateTime,
|
||||
DateTimeImmutable::createFromFormat('Y-m-d',
|
||||
$dateTime->modify('-1 year')->format('Y-11-01'))),
|
||||
default => throw new EmptyResponse($money_symbol),
|
||||
};
|
||||
}
|
||||
|
||||
protected array $supportedMap = [
|
||||
Money::UF => 'uf',
|
||||
Money::IPC => 'ipc',
|
||||
Money::USD => 'dolar'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $request_uri
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function sendRequest(string $request_uri): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get($request_uri);
|
||||
} catch (ClientExceptionInterface $exception) {
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
|
||||
if ((int) floor($response->getStatusCode() / 100) !== 2) {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
$body = $response->getBody();
|
||||
try {
|
||||
$json = json_decode($body->getContents(), true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $exception) {
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
|
||||
if (!array_key_exists('serie', $json) or count($json['serie']) === 0) {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
return $json['serie'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $symbol
|
||||
* @param DateTimeInterface $dateTime
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function getDate(string $symbol, DateTimeInterface $dateTime): float
|
||||
{
|
||||
$request_uri = "{$this->supportedMap[strtolower($symbol)]}/{$dateTime->format('d-m-Y')}";
|
||||
return (float) $this->sendRequest($request_uri)[0]['valor'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $symbol
|
||||
* @param DateTimeInterface $dateTime
|
||||
* @param DateTimeInterface|null $fromDateTime
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function getSum(string $symbol, DateTimeInterface $dateTime, ?DateTimeInterface $fromDateTime = null): float
|
||||
{
|
||||
$dateTime = $dateTime->modify('last day of this month');
|
||||
$requestUri = "{$this->supportedMap[strtolower($symbol)]}/{$dateTime->format('Y')}";
|
||||
$serie = $this->sendRequest($requestUri);
|
||||
$values = array_filter($serie, fn($month) => DateTimeImmutable::createFromFormat('Y-m-d', $month['fecha']) <= $dateTime);
|
||||
$value = array_reduce($values, fn($value, $month) => $value + ((float) $month['valor']), 0.0);
|
||||
|
||||
if ($fromDateTime === null) {
|
||||
$fromDateTime = $dateTime->modify('-1 year');
|
||||
} else {
|
||||
$fromDateTime = $fromDateTime->modify('last day of this month');
|
||||
}
|
||||
$requestUri = "{$this->supportedMap[strtolower($symbol)]}/{$fromDateTime->format('Y')}";
|
||||
$serie = $this->sendRequest($requestUri);
|
||||
$values = array_filter($serie, fn($month) => DateTimeImmutable::createFromFormat('Y-m-d', $month['fecha']) > $fromDateTime);
|
||||
return array_reduce($values, fn($value, $month) => $value + ((float) $month['valor']), $value);
|
||||
}
|
||||
}
|
||||
@ -6,19 +6,14 @@ use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Service\Money;
|
||||
use Incoviba\Common\Define\Money\Provider;
|
||||
|
||||
class Ine extends Ideal\Money\Provider
|
||||
class Ine implements Provider
|
||||
{
|
||||
protected string $uri = 'https://api-calculadora.ine.cl/ServiciosCalculadoraVariacion';
|
||||
public function __construct(LoggerInterface $logger, protected ClientInterface $client)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
public function __construct(protected ClientInterface $client) {}
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
@ -26,9 +21,6 @@ class Ine extends Ideal\Money\Provider
|
||||
*/
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
||||
{
|
||||
if (!$this->supported($money_symbol)) {
|
||||
throw new EmptyResponse($money_symbol);
|
||||
}
|
||||
if ($dateTime === null) {
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
@ -37,10 +29,6 @@ class Ine extends Ideal\Money\Provider
|
||||
return $this->getVar($start, $end);
|
||||
}
|
||||
|
||||
protected array $supportedMap = [
|
||||
Money::IPC => 'ipc'
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
|
||||
@ -3,33 +3,22 @@ namespace Incoviba\Service\Money;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define\Money\Provider;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service\Money;
|
||||
|
||||
class MiIndicador extends Ideal\Money\Provider
|
||||
class MiIndicador implements Provider
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected ClientInterface $client)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
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
|
||||
{
|
||||
if (!$this->supported($money_symbol)) {
|
||||
throw new EmptyResponse($money_symbol);
|
||||
}
|
||||
$request_uri = "{$this->supportedMap[strtolower($money_symbol)]}";
|
||||
$request_uri = "{$money_symbol}";
|
||||
if ($dateTime !== null) {
|
||||
$request_uri = "{$request_uri}/{$dateTime->format('d-m-Y')}";
|
||||
$request_uri = "{$money_symbol}/{$dateTime->format('d-m-Y')}";
|
||||
}
|
||||
try {
|
||||
$response = $this->client->get($request_uri);
|
||||
@ -44,14 +33,9 @@ class MiIndicador extends Ideal\Money\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;
|
||||
}
|
||||
protected array $supportedMap = [
|
||||
Money::UF => 'uf',
|
||||
Money::IPC => 'ipc',
|
||||
Money::USD => 'dolar'
|
||||
];
|
||||
}
|
||||
|
||||
@ -6,38 +6,27 @@ use DateTimeImmutable;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Dom\HTMLDocument;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class SII extends Ideal\Money\Provider
|
||||
class SII implements Define\Money\Provider
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected ClientInterface $client,
|
||||
protected Repository\UF $ufRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
public function __construct(protected ClientInterface $client,
|
||||
protected Repository\UF $ufRepository) {}
|
||||
|
||||
public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
|
||||
{
|
||||
if (!$this->supported($money_symbol)) {
|
||||
throw new EmptyResponse("{$money_symbol} not found in " . __CLASS__);
|
||||
}
|
||||
if (strtolower($money_symbol) === Service\Money::UF) {
|
||||
if ($money_symbol === Service\Money::UF) {
|
||||
return $this->getUF($dateTime);
|
||||
}
|
||||
$class = __CLASS__;
|
||||
throw new EmptyResponse("{$money_symbol} not found in {$class}");
|
||||
}
|
||||
|
||||
protected array $supportedMap = [
|
||||
Service\Money::UF => 'uf'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param DateTimeInterface|null $dateTime
|
||||
* @return float
|
||||
|
||||
@ -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