us-dop-api/assets/templates/components/institution_history.html.tmpl
2024-07-21 11:30:05 -04:00

125 lines
4.2 KiB
Cheetah

{{ define "card-history" }}
{{ if ne .InstRequested "" }}
{{ $inst := .InstRequested }}
{{ range .Results }}
<div class="card">
<p class="inst-name">
{{ .Institution.Name }}
<span class="institucion">{{ $inst }}</span>
</p>
<a class="inst-link" href="/api/instituciones/{{ .Institution.Name }}/history?ta=4&tf=week&format=html">{{ .Institution.Name }}</a>
</div>
{{ end }}
{{ end }}
{{ end }}
<!-- definicion de lista -->
{{ define "list-history" }}
{{ if ne .InstRequested "" }}
{{ $inst := .InstRequested }}
<div>
<p>{{ $inst }}</p>
<ul>
{{ range $idx, $obj := .Results }}
<li class="lista item-{{ $idx }}">
<p class="inst-name">
<span class="compra inst list">Compra: RD. {{ $obj.Compra }} </span>
<span class="venta inst list">Venta: RD. {{ $obj.Venta }} </span>
<span class="time inst list">Fecha: {{ $obj.Parsed }} </span>
<span class="parser inst list">Parser: {{ $obj.Parser }} </span>
</p>
</li>
{{ end }}
</ul>
</div>
{{ end }}
{{ end }}
<!-- crate table -->
{{ define "table-history" }}
{{ if ne .InstRequested "" }}
<table class="inst {{ .InstRequested }}" name="{{ .InstRequested }}">
<caption>Historico de precios para {{ .InstRequested }} los precios se encuentran en la moneda local de Republica Dominicana RD.</caption>
<thead>
<tr>
<!-- <th>Nombre</th> -->
<th>Compra</th>
<th>+/-</th>
<th>Venta</th>
<th>+/-</th>
<th>Fecha</th>
<th class="table-parser" hidden="true">Parser</th>
</tr>
</thead>
<tbody>
{{ $acumComp := 0.0 }}
{{ $acumVent := 0.0 }}
{{ $actualComp := 0.0 }}
{{ $actualVent := 0.0 }}
{{ $antComp := 0.0 }}
{{ $antVent := 0.0 }}
{{ range $idx, $obj := .Results }}
<tr class="row-{{ $idx }}">
<td>
{{ if eq $idx 0}}
{{ $actualComp = $obj.Compra }}
{{ $actualVent = $obj.Venta }}
{{ end }}
<span id="row-{{ $idx }}-compra" class="compra amount">{{ $obj.Compra | printf "%0.2f"}}</span>
</td>
<td >
{{ if ne $antComp 0.0 }}
{{ $tmpVarCompra := mult $obj.Compra -1.0 | add $antComp}}
<span class="compra diff {{if gt $tmpVarCompra 0.0 }} green {{ else if lt $tmpVarCompra 0.0 }} red {{end}}">{{ $tmpVarCompra | printf "%10.2f" }} </span>
{{ end }}
</td>
<td>
<span id="row-{{ $idx }}-venta" class="venta amount">{{ $obj.Venta | printf "%0.2f" }}</span></td>
<td >
{{ if ne $antVent 0.0 }}
{{ $tmpVarVenta := mult $obj.Venta -1.0 | add $antVent }}
<span class="venta diff {{if gt $tmpVarVenta 0.0 }} green {{ else if lt $tmpVarVenta 0.0 }} red {{end}}">{{ $tmpVarVenta | printf "%10.2f" }}</span>
{{ end }}
</td>
<td> <span class="fecha">{{ $obj.Parsed }}</span></td>
<td class="table-parser" hidden="true">{{ $obj.Parser }}</td>
</tr>
{{ $acumComp = add $acumComp $obj.Compra }}
{{ $acumVent = add $acumVent $obj.Venta }}
{{ $antComp = $obj.Compra }}
{{ $antVent = $obj.Venta }}
{{ end }}
{{ if le (len .Results) 0 }}
<tr>
<th>Error</th><td>Sin historico en este periodo</td>
</tr>
{{end}}
</tbody>
<tfoot>
<!-- Calculo de la acumulacion de los distintos valores media y diferencia -->
<!-- solo muestra footer si el nunero de celdas es mayor a 1 -->
{{if gt (len .Results) 1 }}
<tr>
<th>C Media</th>
{{ $mediaComp := len .Results | div $acumComp}}
{{ $diffMediaCompra:= mult $actualComp -1.0 | add $mediaComp | mult -1.0 }}
<td><span class="compra media">{{ $mediaComp | printf "%.2f" }}</span></td>
<th>V Media</th>
{{ $mediaVent := len .Results | div $acumVent }}
{{ $diffMediaVent := mult $actualVent -1.0 | add $mediaVent | mult -1.0}}
<td><span class="venta media">{{ $mediaVent | printf "%.2f" }}</span></td>
</tr>
<tr>
<th id="inst-table-dcompra-header">C Diff </th>
<td id="inst-table-dcompra-data"><span class="compra media diff {{if gt $diffMediaCompra 0.0 }} green {{ else }}red{{end}}"> {{ $diffMediaCompra | printf "%0.3f" }}</span></td>
<th id="inst-table-dventa-header">V Diff</th>
<td id="inst-table-dventa-data"> <span class="venta media diff {{if gt $diffMediaVent 0.0 }} green {{ else }}red{{end}}">{{ $diffMediaVent | printf "%0.3f" }}</span></td>
</tr>
{{ end }}
</tfoot>
</table>
{{ end}}
{{ end }}