{% extends "@ApplicationInternit/ContentBundle/Resources/views/template/standard_layout.html.twig" %}
{% block javascripts %}
{{ parent() }}
<script href="{{ asset('/bundles/applicationinternitcontent/js/multiple-select.min.js') }}"></script>
<script src="{{ asset('/bundles/applicationinternitcontent/js/canonical.js') }}"></script>
<style>
@keyframes spin {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
.kpz-control {
display: flex;
justify-content: center;
}
.kpz-open-selector {
border: 0;
background: transparent;
}
.formulario .fieldset {
display: flex;
flex-direction: column;
}
.kpz-broker-header {
padding-left: 50px;
padding-right: 14px;
display: grid;
gap: 1rem;
grid-template-columns: 2.5fr 1fr 1fr;
}
.kpz-broker-header p{
font-size: 14px;
font-weight: bold;
}
.kpz-broker-select {
flex: 1;
position: relative;
padding-left: 50px;
}
.kpz-broker-select .loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: spin 1s linear infinite;
}
.kpz-broker-select-content {
overflow: auto;
max-height: 400px;
}
.kpz-broker-select-item-real-state-container {
display: grid;
gap: 1rem;
height: 70px;
align-items: center;
grid-template-columns: 2.5fr 1fr 1fr;
border-top: 2px solid #ffffff;
}
.kpz-broker-select-item-real-state {
display:flex;
gap: 1rem;
align-items: center;
}
.kpz-broker-select-item-real-state i {
font-size: 17px;
}
.kpz-broker-select-item-real-state span {
font-size: 13px;
}
.kpz-realstate-percent {
font-size: 13px;
margin-left: auto;
}
.kpz-broker-select-item {
overflow: hidden;
max-height: 70px;
}
.kpz-broker-select-item.active {
max-height: 100%;
}
.kpz-open-selector:disabled {
cursor: not-allowed;
}
.kpz-open-selector svg {
transition: all .6s
}
.kpz-broker-select-item.active .kpz-open-selector svg {
transform: rotate(180deg);
}
.kpz-broker-select-item-brokers-item {
display: grid;
gap: 1rem;
height: 50px;
align-items: center;
grid-template-columns: 2.5fr 1fr 1fr;
border-top: 2px solid #ffffff;
}
.kpz-broker-select-item-broker {
display:flex;
gap: 1rem;
align-items: center;
}
.kpz-broker-select-item-brokers-item i {
font-size: 17px;
color: #9a4e22;
}
.kpz-broker-select-item-brokers-item span {
font-size: 13px;
}
</style>
<script type="text/javascript">
function copyToken() {
/* Get the text field */
copyText = document.getElementById("tokenIntegration");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
/* Copy the text inside the text field */
document.execCommand("copy");
}
$(document).ready(function() {
const activeBrokers = [];
{% for corretor in obj.productUsers %}
activeBrokers.push('{{ corretor.realEstate.id }}:{{ corretor.user.id }}');
{% endfor %}
const multipleSelect = document.querySelector(".broker-select");
function buildContent(realStates) {
const realStatePercents = {{ obj.realStatePercentByName|json_encode|raw }};
return `
<div class="kpz-broker-select-content">
${realStates.reduce((realStatesHTML, currentRealState) => realStatesHTML + `
<div class="kpz-broker-select-item">
<div class="kpz-broker-select-item-real-state-container">
<div class="kpz-broker-select-item-real-state">
<i class="fa fa-building"></i>
<span>${currentRealState.name}</span>
<div class="kpz-realstate-percent">
<input type="number" name="{{ form.vars.name }}[realStatePercents][${convertToCanonical(currentRealState.name)}][percent]" id="realStatePercent-${convertToCanonical(currentRealState.name)}" value="${realStatePercents[currentRealState.name]}" min="0" max="100" />
%
</div>
</div>
<div class="kpz-control">
<input type="checkbox" class="kpz-select-all" />
</div>
<div class="kpz-control">
<button type="button" class="kpz-open-selector"><svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="#000000" viewBox="0 0 256 256"><path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"></path></svg></button>
</div>
</div>
<div class="kpz-broker-select-item-brokers">
${currentRealState.brokers.reduce((brokerHTML, currentBroker) => brokerHTML + `
<div class="kpz-broker-select-item-brokers-item">
<div class="kpz-broker-select-item-broker">
<i class="far fa-user"></i>
<span>${currentBroker.label}</span>
</div>
<div></div>
<div class="kpz-control">
<input data-value="${currentBroker.value}" type="checkbox" class="kpz-select-one"/>
</div>
</div>
`, "")}
</div>
</div>
`, "")}
</div>
`
}
function toggleSelector() {
const container = this.parentElement.parentElement.parentElement;
container.classList.toggle("active");
}
function verifyAllMarked(target) {
const container = target.parentElement.parentElement.parentElement.parentElement;
const selector = container.querySelector(".kpz-select-all");
const isAllActive = [...container.querySelectorAll(".kpz-select-one")].every(item => item.checked);
if(isAllActive) {
selector.checked = true;
container.querySelector(".kpz-open-selector").disabled = true;
container.classList.remove("active");
}
}
function selectOne() {
const value = this.dataset.value;
multipleSelect.querySelector(`option[value='${value}']`).selected = this.checked;
verifyAllMarked(this);
console.log("LOG: ", this.dataset.value, this.checked ? "Marcado": "Desmarcado");
}
function selectAll() {
const container = this.parentElement.parentElement.parentElement;
container.querySelectorAll(".kpz-select-one").forEach(item => {
item.checked = this.checked;
item.dispatchEvent(new Event('change', { bubbles: true }));
})
container.querySelector(".kpz-open-selector").disabled = this.checked;
if(this.checked) {
container.classList.remove("active");
}
}
function initActions() {
// Adicionar Eventos
document.querySelectorAll(".kpz-broker-select-item").forEach((item) => {
item.querySelector(".kpz-open-selector").addEventListener("click", toggleSelector);
item.querySelector(".kpz-select-all").addEventListener("change", selectAll);
item.querySelectorAll(".kpz-select-one").forEach(item => item.addEventListener("change", selectOne));
})
// Iniciar Dados
activeBrokers.forEach(item => {
const broker = document.querySelector(`.kpz-broker-select-item .kpz-select-one[data-value='${item}']`)
broker.checked = true;
broker.dispatchEvent(new Event('change', { bubbles: true }));
})
}
if(multipleSelect) {
multipleSelect.classList.add("hidden");
const contentContainer = document.querySelector(".kpz-broker-select");
const realStates = [...multipleSelect.querySelectorAll("optgroup")].map(realEstate => ({
name: realEstate.label,
brokers: [...realEstate.querySelectorAll("option")].map(broker => ({
label: broker.textContent,
value: broker.value
}))
}));
const html = buildContent(realStates);
contentContainer.innerHTML = html;
initActions();
}
$('#js-submit-form').click(function(e){
var error = 0;
var msg = 'Campos obrigatórios não preenchidos:\n';
$(':input[required]').each(function(){
$(this).css('border','2px solid green');
if($(this).val() == ''){
msg += '\n' + $(this).next().text();
$(this).css('border','2px solid red');
if(error == 0)
{
$(this).focus();
}
error = 1;
}
});
if(error == 1) {
alert('Campos obrigatórios não foram preenchidos.');
return false;
}
});
});
</script>
{# <script type="text/javascript" src="{{ asset('bundles/applicationinternitlead/js/product-edit.js') }}"></script> #}
{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('/bundles/applicationinternitcontent/css/formularios.css') }}"/>
<link rel="stylesheet" href="{{ asset('/bundles/applicationinternitcontent/css/productBundle.css') }}"/>
<link rel="stylesheet" href="{{ asset('/bundles/applicationinternitcontent/css/multiple-select.min.css') }}"/>
{% endblock %}
{% block sonata_admin_actions %}
sdfsdfsdfsdfsdf
{% endblock %}
{% block title %}
Edição de campanha
{% endblock %}
{% block sonata_admin_content %}
<div class="meusDados">
{% for flashMessage in app.session.flashbag.get('flash_create_success') %}
<div class="caixa-resposta">
<div class="resposta active" id="r-sucess">
<i class="far fa-check-circle"></i>
<p>Salvo com sucesso</p>
</div>
</div>
{% endfor %}
{% for flashMessage in app.session.flashbag.get('flash_create_error') %}
<div class="caixa-resposta">
<div class="resposta active" id="r-error">
<i class="far fa-times-circle"></i>
<p>{{ flashMessage|raw }}</p>
</div>
</div>
{% endfor %}
<div class="titleDefault">
<div class="group">
<h3>Editar Campanha</h3>
<a class="btn-voltar" href="{{ path('admin_internit_lead_product_list')}}"><i class="fas fa-arrow-left"></i>Voltar</a>
</div>
</div>
<div class="contentProductCreate edit">
{{ form_start(form) }}
<div class="boxDefault">
<div class="my-custom-class-for-errors">
{{ form_errors(form) }}
</div>
<div class="formulario">
<div class="fieldset">
<div class="flex">
<div class="col inputBox">
{{ form_widget(form.name) }}
{{ form_label(form.name) }}
</div>
</div>
<div class="flex">
<div class="col inputBox">
{{ form_widget(form.email) }}
{{ form_label(form.email) }}
</div>
</div>
<div class="flex">
<div class="col inputBox">
{{ form_widget(form.description) }}
{{ form_label(form.description) }}
</div>
</div>
<div class="flex">
<div class="col inputBox">
<input readonly id="tokenIntegration" type="text" value="{{ obj.token }}">
<label for="token">Código para implementação:</label>
</div>
</div>
<div class="row row-space">
<div class="col-md-3">
<div class="col inputBox">
{{ form_widget(form.fidelityDays) }}
{{ form_label(form.fidelityDays) }}
</div>
</div>
<div class="col-md-3">
<div class="col inputBox">
{{ form_widget(form.vivaReal) }}
{{ form_label(form.vivaReal) }}
</div>
</div>
<div class="col-md-3">
<div class="col inputBox">
{{ form_widget(form.zap) }}
{{ form_label(form.zap) }}
</div>
</div>
<div class="col-md-3">
<div class="col inputBox">
{{ form_widget(form.olx) }}
{{ form_label(form.olx) }}
</div>
</div>
</div>
<br>
<div class="flex btns-create">
<div class="flex buttons-create" id="" onclick="copyToken()">
<i class="far fa-copy"></i>
<input type="button" class="" value="Copiar Código">
</div>
<button class="flex buttons-create" type="submit" id="js-submit-form">
<i class="far fa-save"></i>
<span>Salvar</span>
</button>
</div>
</div>
</div>
</div>
<div class="boxDefault">
<div class="formulario h-100">
<div class="fieldset h-100">
<p class="text-imob">Selecioner a imobiliaria/corretor para recebimento dos leads em rodizio.</p>
{{ form_label(form.productUsers) }}
{{ form_widget(form.productUsers) }}
<div class="kpz-broker-header">
<p>Imobiliária</p>
<p class="text-center">Enviar Todos</p>
<p class="text-center">Escolher Corretor</p>
</div>
<div class="kpz-broker-select">
<svg class="loading" xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#757575" viewBox="0 0 256 256"><path d="M232,128a104,104,0,0,1-208,0c0-41,23.81-78.36,60.66-95.27a8,8,0,0,1,6.68,14.54C60.15,61.59,40,93.27,40,128a88,88,0,0,0,176,0c0-34.73-20.15-66.41-51.34-80.73a8,8,0,0,1,6.68-14.54C208.19,49.64,232,87,232,128Z"></path></svg>
</div>
</div>
</div>
</div>
<div style="display:none;">{{ form_widget(form.realStatePercents) }}</div>
{{ form_end(form) }}
</div>
</div>
<div class="meusDados" style="margin-top: 20px;">
<div class="titleDefault col-12">
<div class="row">
<div class="col-8">
<h3>Imobiliárias Ativas </h3>
<span class="" style="font-size: 15px">Listagem de Imobiliárias regularmente ativas na campanha e suas estatísticas.</span>
</div>
<div class="col-4 text-right">
<h3>Próximo a receber:</h3>
<h5><b>{{ next['imob'] }}</b></h5>
</div>
<div class="col-12">
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr style="font-size: 16px">
<th scope="col">#</th>
<th scope="col">id</th>
<th scope="col">Imobiliária</th>
<th scope="col">Porcentagem %</th>
<th scope="col">Leads Recebidos</th>
<th scope="col">Leads Recebidos + Extra Leads</th>
<th scope="col">Extra Leads</th>
<th scope="col">Ver Corretores</th>
<th scope="col">Primeiro recebido:</th>
<th scope="col">Ultimo recebido</th>
</tr>
</thead>
<tbody>
{% set totalLeads = 0 %}
{% set totalLeadsExtra = 0 %}
{% for index,realState in obj.getRealStateProductInfo %}
{% if realState['percent'] != 0 %}
{% set totalLeads = totalLeads + realState['qtdLeads'] %}
{% set totalLeadsExtra = totalLeadsExtra + realState['extraLeads'] %}
<tr style="font-size: 16px">
<th scope="row">{{ index+1 }}</th>
<th scope="row">{{ realState['id'] }}</th>
<td>{{ realState['name'] }}</td>
<td><b>{{ realState['percent'] }}</b>%</td>
<td><b>{{ realState['qtdLeads'] }}</b> Leads</td>
<td><b>{{ realState['qtdLeads'] + realState['extraLeads'] }}</b> Leads</td>
<td>
<b>{{ realState['extraLeads'] }}</b> Leads
<a type="button" data-toggle="modal" data-target="#modalExtraLead-{{ realState['id'] }}">
<i class="fas fa-edit"></i>
</a>
</td>
<td class="text-center">
<a href="javascript:void(0)" onclick="openCorretorList({{ realState['id'] }})">
<b>Corretores ({{ realState['corretores']|length }})</b>
</a>
</td>
<td><b>{{ realState['firstLead']|date('d/m/Y H:i:s') }}</b> </td>
<td><b>{{ realState['lastLead']|date('d/m/Y H:i:s') }}</b> </td>
</tr>
<div class="modal fade" id="modalExtraLead-{{ realState['id'] }}" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ realState['name'] }} - Leads Extra</h5>
</div>
<div class="modal-body">
<br>
<form action="{{ path('admin_internit_lead_product_saveExtraLeads') }}" method="get">
<input type="hidden" name="realStateId" value="{{ realState['id'] }}">
<input type="hidden" name="product" value="{{ obj.id }}">
<div class="form-group">
<label style="font-size: 12px">Extra Leads</label>
<input type="number" class="form-control" name="extraLeads" value="{{ realState['extraLeads'] }}">
<small class="form-text text-muted" style="font-size: 10px">Quantidade de leads a serem adicionados a imobiliária de modo a auxiliar na contabilidade das informações</small>
</div>
<br><br>
<div class="float-right">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
<button type="submit" class="btn btn-primary">Atualizar</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
<div class="col-10">
<h3>Total de Leads Recebidos: <b>{{ totalLeads }}</b></h3>
<h3>Total de Leads + Extra Recebidos: <b>{{ totalLeads+totalLeadsExtra }}</b></h3>
</div>
<div class="col-2">
<a href="{{ path('admin_internit_lead_product_exportLog', {'id': obj.id} )}}" class="btn-export"><i class="fas fa-arrow-down"></i>Exportar Logs</a>
<a href="{{ path('admin_internit_lead_product_exportLogSended', {'id': obj.id} )}}" class="btn-export"><i class="fas fa-arrow-down"></i>Exportar Logs Distribuição</a>
</div>
{% for index,realState in obj.getRealStateProductInfo %}
<div class="col-12 allCorretoresList" id="corretor-list-{{ realState['id'] }}" style="display: none">
<hr>
<br>
<div class="row">
<div class="col-6">
<h3> Corretores Ativos - <b>{{ realState['name'] }}</b></h3>
</div>
{% set lastPosition = 0 %}
{% for index,corretor in realState['corretores'] %}
{% set lastPosition = index %}
{% endfor %}
{% set nextPosition = realState['turn'] %}
{% if nextPosition > lastPosition %}
{% set nextPosition = 0 %}
{% endif %}
<div class="col-6 text-right" >
<h3> Próximo da fila - (<b>{{ nextPosition + 1 }}</b>)</h3>
</div>
</div>
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr style="font-size: 16px">
<th scope="col">Posição na fila</th>
<th scope="col">Nome</th>
<th scope="col">Email</th>
<th scope="col">Qtd Leads Recebidos</th>
</tr>
</thead>
<tbody>
{% for index,corretor in realState['corretores'] %}
<tr style="font-size: 16px">
<th scope="row">{{ index + 1 }}</th>
<th scope="row">{{ corretor['name'] }}</th>
<th scope="row">{{ corretor['email'] }}</th>
<th scope="row">{{ corretor['qtdLeads'] }}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
</div>
</div>
</div>
<script>
let openCorretorList = (realStateId)=>{
let div = $(`#corretor-list-${realStateId}`)
let allCorretores = $(`.allCorretoresList`)
if(div.css('display') === 'none') {
allCorretores.css('display', 'none')
div.css('display', 'block')
}else{
allCorretores.css('display', 'none')
}
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight;
}
</script>
{% endblock %}