| Server IP : 54.94.228.101 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/storage/framework/views/ |
Upload File : |
<?php $__env->startSection('content'); ?>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<?php echo (isset($pedido_venda)) ? 'Editar' : 'Criar'; ?>
<small>Informações Pedido Venda</small>
</h1>
<ol class="breadcrumb">
<li><a href="<?php echo e(url('/admin')); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li><a href="<?php echo e(url('/admin/pedido-venda')); ?>">Pedido Venda</a></li>
<li class="active"><?php echo (isset($pedido_venda)) ? 'Editar' : 'Criar'; ?></li>
</ol>
</section>
<section class="content">
<form id="mainForm" class="form-horizontal" role="form" method="POST" action="<?php echo e(url('/admin/pedido-venda/save')); ?>">
<?php echo e(csrf_field()); ?>
<?php if(isset($pedido_venda)){ ?>
<input type="hidden" name="id" value="<?php echo $pedido_venda->id; ?>"/>
<?php } ?>
<div class="row">
<div class="col-lg-4">
<div class="box-form">
<div class="box-header-form">
<h4>Informações Básicas</h4>
</div>
<div class="box-body-form">
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Data / Hora *</label>
<input required type="datetime-local" name="data_fechamento" class="form-control" value="<?php echo (isset($pedido_venda)) ? str_replace(' ','T',date('Y-m-d H:i', strtotime($pedido_venda->data_fechamento))) : str_replace(' ','T',date('Y-m-d H:i')); ?>">
</div>
</div>
</div>
<?php /* ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Nome Referência *</label>
<input type="text" required name="nm_referencia" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->nm_referencia : old('nm_referencia'); ?>">
</div>
</div>
</div>
<?php */ ?>
<?php if(isset($pedido_venda)){ ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Número *</label>
<input type="text" disabled name="numero" class="form-control" value="<?php echo $pedido_venda->id; ?>">
</div>
</div>
</div>
<?php } ?>
<?php if(isset($pedido_venda)): ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Cliente *</label>
<select required name="id_cliente" class="select2 form-control">
<?php foreach ($cadastros as $cliente): ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->id_cliente == $cliente->id || isset($id_cliente) && $id_cliente == $cliente->id) ? 'selected' : ''; ?> value="<?php echo $cliente->id; ?>"><?php echo $cliente->nome.' '.$cliente->sobrenome; ?> <?php echo ($cliente->user) ? '('.$cliente->user->email.')' : ''; ?></option>
<?php endforeach ?>
</select>
</div>
</div>
</div>
<?php else: ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Cliente *</label>
<select required name="id_cliente" class="select2 form-control select2-clientes">
<option value=""></option>
</select>
</div>
</div>
</div>
<?php endif; ?>
<!-- Confraria -->
<?php if(isset($confrarias)): ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Confraria</label>
<select required name="confraria_id" class="select2 form-control">
<option value="">Nenhuma</option>
<?php $__currentLoopData = $confrarias; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $confraria): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->confraria_id == $confraria->id || isset($confraria_id) && $confraria_id == $confraria->id) ? 'selected' : ''; ?> value="<?php echo e($confraria->id); ?>"><?php echo e($confraria->nome); ?></option>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
</div>
</div>
</div>
<?php endif; ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Status *</label>
<select required <?php echo (isset($pedido_venda)) ? 'disabled' : ''; ?> name="id_status_pedido_venda" class="form-control select2">
<?php foreach ($listaStatusPDV as $status): ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->id_status_pedido_venda == $status->id) ? 'selected' : ''; ?> value="<?php echo $status->id; ?>"><?php echo $status->nome; ?></option>
<?php endforeach ?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Observações *</label>
<input type="text" required name="assunto" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->assunto : old('assunto'); ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="empresa_id" class="ffl-label">Empresa *</label>
<select id="empresa_id" required class="form-control select2" name="empresa_id">
<?php $nomeVariavel = 'array_empresa_id'; ?>
<?php foreach ($$nomeVariavel as $option): ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->empresa_id == $option->id) ? 'selected' : ''; ?> value="<?php echo $option->id; ?>"><?php echo $option->nome; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="unidade_negocio_id" class="ffl-label">Unidade *</label>
<select id="unidade_negocio_id" required class="form-control select2" name="unidade_negocio_id">
<?php foreach ($unidades as $option): ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->unidade_negocio_id == $option->id) ? 'selected' : ''; ?> value="<?php echo $option->id; ?>"><?php echo $option->nome; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="id_pedido_venda_categoria" class="ffl-label">Categoria</label>
<select id="id_pedido_venda_categoria" class="form-control select2" name="id_pedido_venda_categoria">
<option value=""></option>
<?php foreach ($categorias as $option): ?>
<option <?php echo (isset($pedido_venda) && $pedido_venda->id_pedido_venda_categoria == $option->id) ? 'selected' : ''; ?> value="<?php echo $option->id; ?>"><?php echo $option->nome; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<?php if(isset($pedido_venda) && $pedido_venda->cupom){ ?>
<div class="form-group">
<div class="col-md-12">
<div class="ffl-wrapper">
<label for="nome" class="ffl-label">Cupom</label>
<input type="text" disabled name="cupom" class="form-control" value="<?php echo $pedido_venda->cupom->cupom->codigo; ?>">
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="box-form">
<div class="box-header-form">
<h4>Ofertas</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md-12">
<div class="dynamic-list-section">
<div class="row">
<div class="col-xs-9">
<div class="row">
<div class="col-xs-12">
<select name="ofertas" id="ofertas" data-placeholder="Selecione uma oferta" class="form-control select2">
<option value=""></option>
<?php foreach ($listaOfertas as $oferta): ?>
<option data-titulo="<?php echo $oferta->titulo.' '.$oferta->sub_titulo; ?>" value="<?php echo $oferta->id; ?>" data-preco="<?php echo $oferta->preco_oferta; ?>" data-slug="<?php echo $oferta->slug; ?>"><?php echo $oferta->titulo.' '.$oferta->sub_titulo; ?> - <?php echo ($oferta->nome_canal) ? 'Canal: '.$oferta->nome_canal.' '.$oferta->subtitulo_canal.' - Período: '.date('d/m/Y', strtotime($oferta->data_inicial_canal)).' até '.date('d/m/Y', strtotime($oferta->data_final_canal)) : 'Data: '.date('d/m/Y', strtotime($oferta->data)) . ($oferta->tipo == 'S' ? ' (Semanal)' : ''); ?></option>
<?php endforeach ?>
</select>
</div>
</div>
</div>
<div class="col-xs-3">
<button type="button" class="btn btn-success btn-block" id="addOferta">Adicionar</button>
</div>
<div class="col-xs-12 hidden" id="pdv__disponibilidade">
<div class="row">
<div class="col-md-3">
<p><strong>Disponibilidade oferta: <span id="pdv__disponibilidade--oferta">0</span></strong></p>
</div>
<div class="col-md-6">
<p><strong>Disponibilidade produto: </strong>
<strong><span id="pdv__disponibilidade--produto">0</span></strong>
<span id="pdv__disponibilidade--btn_produto" class="hidden">
<button type="button" class="btn btn-success btn-sm" id="btn-oferta-produtos" data-oferta-id="">Consultar Produtos</button>
</span>
</p>
</div>
</div>
</div>
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-ofertas" class="table table-bordered">
<thead>
<tr>
<th>Oferta</th>
<th>Valor Oferta (R$)</th>
<th>Quantidade</th>
<th>Valor Total (R$)</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<?php if(isset($ofertasPdv)){ ?>
<?php foreach ($ofertasPdv as $oferta):
$valor_unitario = number_format($oferta->preco_oferta,2,'.','');
$valor_total = $valor_unitario * $oferta->quantidade_no_pedido;
$valor_total = number_format($valor_total,2,'.','');
$descAux = '';
if($oferta->agrupamento_produtos){
$descAux = ' - ';
if($oferta->produtos[0]->produto->atributosVariacao){
$atributosVariacao = $oferta->produtos[0]->produto->atributosVariacao;
$atributos = [];
foreach ($atributosVariacao as $item) {
$atributos[] = substr($item->atributo->variacao->nome, 0, 3).". {$item->atributo->nome}";
}
$descAux .= implode(" , ", $atributos);
}
}
?>
<tr id="oferta-<?php echo $oferta->id; ?>">
<input type="hidden" name="oferta-id[]" class="oferta" value="<?php echo $oferta->id; ?>"/>
<input type="hidden" name="oferta-valor-unitario[]" value="<?php echo $valor_unitario; ?>"/>
<input type="hidden" name="oferta-total[]" class="total" value="<?php echo $valor_total; ?>">
<td>
<?php echo $oferta->titulo.' '.$oferta->sub_titulo . $descAux; ?>
</td>
<td class="valor_unitario" data-unitario="<?php echo $valor_unitario; ?>">
<?php echo number_format($valor_unitario,2,',','.');?>
</td>
<td>
<input type="number" name="oferta-quantidade[]" class="form-control quantidade" value="<?php echo $oferta->quantidade_no_pedido; ?>"/>
</td>
<td class="valor_total">
<?php echo number_format($valor_total,2,',','.');?>
</td>
<td>
<button type="button" class="btn btn-danger removeOferta"><i class="fa fa-trash"></i></button>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
<?php if(!isset($pedido_venda)): ?>
<div class="box-form hidden" id="cupom-desconto">
<div class="box-header-form">
<h4>Cupom de Desconto</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md-12">
<div class="dynamic-list-section">
<div class="row">
<div class="col-xs-3">
<div class="row">
<div class="col-xs-12">
<input type="text" name="cupom" id="cupom" class="form-control" value="">
</div>
</div>
</div>
<div class="col-xs-2">
<button type="button" class="btn btn-success btn-block" id="addCupom" disabled="disabled">Aplicar Cupom</button>
</div>
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-cupom" class="table table-bordered">
<thead>
<tr>
<th>Cupom</th>
<th>Valor/Percentual Desconto</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php /*
<div class="box-form">
<div class="box-header-form">
<h4>Serviço</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md-12">
<div class="dynamic-list-section">
<div class="row">
<div class="col-md-9">
<select name="servicos" data-placeholder="Selecione um serviço" class="form-control select2">
<option value=""></option>
<?php foreach ($listaServicos as $servico): ?>
<option value="<?php echo $servico->id; ?>" data-preco="<?php echo $servico->valor_unitario; ?>" data-qtd-padrao="<?php echo $servico->quantidade_padrao; ?>" data-slug="<?php echo $servico->slug; ?>"><?php echo $servico->nome; ?></option>
<?php endforeach ?>
</select>
</div>
<div class="col-md-3">
<button type="button" class="btn btn-success btn-block" id="addServico">Adicionar</button>
</div>
</div>
<div class="row">
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-servicos" class="table table-bordered">
<thead>
<tr>
<th>Serviço</th>
<th>Valor Unitário (R$)</th>
<th>Quantidade</th>
<th>Valor Total (R$)</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<?php if(isset($pedido_venda) && count($pedido_venda->servicos)){ ?>
<?php foreach ($pedido_venda->servicos as $pdvHasServico): ?>
<tr id="servico-<?php echo $pdvHasServico->id_servico; ?>">
<input type="hidden" name="servico-edit-id[]" value="<?php echo $pdvHasServico->id_servico; ?>"/>
<input type="hidden" name="servico-edit-total[]" class="total" value="<?php echo $pdvHasServico->valor_total; ?>">
<td>
<a target="_blank" href="<?php echo url('admin/servico/edit/'.$pdvHasServico->servico->slug); ?>"><?php echo $pdvHasServico->servico->nome; ?></a>
</td>
<td class="valor_unitario" data-unitario="<?php echo $pdvHasServico->servico->valor_unitario; ?>">
<?php echo number_format($pdvHasServico->servico->valor_unitario,2,',','.'); ?>
</td>
<td>
<input type="number" name="servico-edit-quantidade[]" class="form-control quantidade" value="<?php echo $pdvHasServico->quantidade; ?>"/>
</td>
<td class="valor_total">
<?php echo number_format($pdvHasServico->valor_total,2,',','.'); ?>
</td>
<td>
<button type="button" class="btn btn-danger deleteServico"><i class="fa fa-trash"></i></button>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
*/ ?>
<?php /* ?>
<div class="box-form">
<div class="box-header-form">
<h4>Taxas</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md12">
<div class="dynamic-list-section">
<div class="col-lg-4 row pull-right"><button type="button" class="btn btn-success btn-block" id="addTaxa">Adicionar</button></div>
<div class="row">
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-taxas" class="table table-bordered">
<thead>
<tr>
<th>Nome da Taxa</th>
<th>Valor (R$)</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<?php if(isset($pedido_venda) && count($pedido_venda->taxas)){ ?>
<?php foreach ($pedido_venda->taxas as $taxa): ?>
<tr id="taxa-<?php echo $taxa->id; ?>">
<input type="hidden" name="edit-taxa-id[]" value="<?php echo $taxa->id; ?>">
<td>
<input type="text" name="edit-taxa-nome[]" class="form-control" value="<?php echo $taxa->nome; ?>">
</td>
<td class="valor">
<input type="number" name="edit-taxa-valor[]" class="form-control total" value="<?php echo $taxa->valor; ?>">
</td>
<td>
<button type="button" class="btn btn-danger deleteTaxa"><i class="fa fa-trash"></i></button>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
<?php */ ?>
<?php /* ?>
<div class="box-form">
<div class="box-header-form">
<h4>Comissões</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md12">
<div class="dynamic-list-section">
<div class="row">
<div class="col-md-8">
<select name="usuarios" data-placeholder="Selecione um usuário" class="form-control select2">
<option value=""></option>
<?php foreach ($listaUsuarios as $usuario): ?>
<option value="<?php echo $usuario->id; ?>"><?php echo $usuario->first_name.' '.$usuario->last_name; ?></option>
<?php endforeach ?>
</select>
</div>
<div class="col-md-4"><button type="button" class="btn btn-success btn-block" id="addComissao">Adicionar</button></div>
</div>
<div class="row">
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-comissoes" class="table table-bordered">
<thead>
<tr>
<th>Usuário</th>
<th>Tipo</th>
<th>Valor</th>
<th>Total (R$)</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<?php if(isset($pedido_venda->comissoes) && count($pedido_venda->comissoes)){ ?>
<?php foreach ($pedido_venda->comissoes as $comissao): ?>
<tr id="comissao-<?php echo $comissao->usuario->id; ?>">
<input type="hidden" name="comissao-edit-id[]" value="<?php echo $comissao->id; ?>">
<input type="hidden" name="comissao-edit-total[]" value="<?php echo $comissao->valor_total; ?>" class="total">
<td>
<a target="_blank" href="<?php echo url('admin/user/edit/'.$comissao->usuario->id); ?>"><?php echo $comissao->usuario->first_name.' '.$comissao->usuario->last_name; ?></a>
</td>
<td>
<select name="comissao-edit-tipo[]" class="form-control tipo">
<option <?php echo ($comissao->tipo == 'PER') ? 'selected' : ''; ?> value="PER">Percentual</option>
<option <?php echo ($comissao->tipo == 'VAL') ? 'selected' : ''; ?> value="VAL">Valor Bruto</option>
</select>
</td>
<td>
<input type="number" name="comissao-edit-valor[]" class="form-control valor" value="<?php echo $comissao->valor; ?>"/>
</td>
<td class="valor_total">
<?php echo number_format($comissao->valor_total, 2, ',', '.'); ?>
</td>
<td>
<button type="button" class="btn btn-danger deleteComissao"><i class="fa fa-trash"></i></button>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
<?php */ ?>
<?php if(isset($pedido_venda)){ ?>
<div class="box-form">
<div class="box-header-form">
<h4>Histórico</h4>
</div>
<div class="box-body-form">
<div class="form-groud">
<div class="col-md-12">
<div class="dynamic-list-section">
<div class="row">
<div class="col-md-6">
<select name="id_pedido_venda_status" id="id_pedido_venda_status" data-placeholder="Selecione um status" class="form-control select2">
<option value=""></option>
<?php foreach ($listaStatusPDV as $pedidoVendaStatus): ?>
<option value="<?php echo $pedidoVendaStatus->id; ?>"><?php echo $pedidoVendaStatus->nome; ?></option>
<?php endforeach ?>
</select>
</div>
<div class="col-md-6">
<input type="checkbox" name="notificar_cliente" id="notificar_cliente" value="1" /> Notificar Cliente
</div>
<div class="col-md-12">
<label for="comentario" class="control-label col-md-3">Comentário</label>
<textarea name="comentario" id="comentario" class="form-control"> </textarea>
</div>
</div>
<div class="row">
<div class="col-md-4">
<button type="button" class="btn btn-success btn-block" id="addHistorico">Adicionar</button>
</div>
</div>
<div class="row">
<div class="spacer"></div>
<div class="col-xs-12">
<table id="table-historico" class="table table-bordered">
<thead>
<tr>
<th>Data</th>
<th>Responsável</th>
<th>Notificar</th>
<th>Status</th>
<th>Comentário</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<?php if(isset($listaHistorico) && count($listaHistorico)){ ?>
<?php foreach ($listaHistorico as $historico): ?>
<tr id="historico-<?php echo $historico->id; ?>">
<input type="hidden" name="historico-edit-id[]" value="<?php echo $historico->id; ?>">
<td>
<?php echo date('d/m/Y H:i', strtotime($historico->data)); ?>
</td>
<td>
<?php /* ?><a target="_blank" href="<?php echo url('admin/colaborador/edit/'.$historico->colaborador->id); ?>"><?php echo $historico->colaborador->nome; ?></a><?php */ ?>
</td>
<td>
<?php echo ($historico->notificar_cliente==1?'Sim':'Não'); ?>
</td>
<td>
<?php echo $historico->status->nome; ?>
</td>
<td class="valor_total">
<?php echo nl2br($historico->comentario); ?>
</td>
<td>
<button type="button" class="btn btn-danger deleteHistorico"><i class="fa fa-trash"></i></button>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="box-form">
<div class="box-header-form">
<h4>
Meios de Pagamento
<?php if(isset($pedido_venda)){ ?>
- <?php echo ($pedido_venda->transacao_id) ? 'Cartão de Crédito' : 'Depósito'; ?>
<?php } ?>
</h4>
</div>
<div class="box-body-form">
<div id="cartoes-section" class="col-md-12">
<?php if(isset($pedido_venda) && $pedido_venda->transacao_id){ ?>
<div class="spacer"></div>
<div class="cartoes__item">
<div class="row">
<div class="col-md-8">
<h3 class="cartao-item__title"><img src="img/site/pagamento/<?php echo $pedido_venda->transaction->getCard()->brand; ?>.svg" ?> **** **** **** <?php echo $pedido_venda->transaction->getCard()->last_digits; ?></h3>
<?php if($pedido_venda->condicaoComercial){ ?>
<span><?php echo $pedido_venda->condicaoComercial->nome; ?></span>
<?php } ?>
</div>
<div class="col-md-4">
<?php
$validade = $pedido_venda->transaction->getCard()->expiration_date;
$validade_first = substr($validade, 0, 2);
$validade_last = substr($validade,2,2);
?>
<p class="validade">Validade: <?php echo $validade_first.'/'.$validade_last; ?></p>
</div>
</div>
</div>
<div class="spacer"></div>
<?php }elseif(isset($pedido_venda) && $pedido_venda->tipo_deposito){ ?>
<div class="row">
<table class="table table-bordered">
<thead>
<tr>
<th>Tipo de Depósito</th>
<th>Nome do Depositante</th>
<th>Comprovante</th>
<th>Remover</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php switch ($pedido_venda->tipo_deposito) {
case 'D': $tipo = 'Depósito'; break;
case 'DOC': $tipo = 'DOC'; break;
case 'TED': $tipo = 'TED'; break;
case 'PIX': $tipo = 'PIX'; break;
case 'CASH': $tipo = 'CASH'; break;
case 'BRD': $tipo = 'BRINDE'; break;
case 'INT': $tipo = 'INTERNO'; break;
} ?>
<?php echo $tipo; ?>
</td>
<td>
<?php echo $pedido_venda->nome_depositante; ?>
</td>
<td class="comprovante">
<?php if($pedido_venda->tipo_deposito == 'BRD' || $pedido_venda->tipo_deposito == 'CASH'): ?>
Não necessita comprovante.
<?php else: ?>
<?php echo $pedido_venda->comprovante ? '<a target="_blank" href="'.get_file_s3($pedido_venda->comprovante, 'pedido-venda/comprovante').'">Ver comprovante</a>' : 'Comprovante não enviado.'; ?>
<?php endif; ?>
</td>
<td>
<?php if($pedido_venda->comprovante): ?>
<button type="button" class="btn btn-danger removeComprovante" data-id="<?php echo $pedido_venda->id?>"><i class="fa fa-trash"></i></button>
<?php endif;?>
</td>
</tr>
</tbody>
</table>
</div>
<?php } ?>
</div>
<?php if(isset($pedido_venda) && $pedido_venda->id_status_pedido_venda != 4){ ?>
<div class="col-md-12">
<button type="button" id="estornar" class="btn btn-primary">Estornar Pedido</button>
</div>
<div class="spacer"></div>
<?php } ?>
</div>
</div>
</div>
</div>
<input type="hidden" name="subtotal" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->subtotal : old('subtotal'); ?>">
<input type="hidden" name="ajuste" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->ajuste : old('ajuste'); ?>">
<input type="hidden" name="total" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->total : old('total'); ?>">
</form>
<?php if($modulo->imagem){ ?>
<div id="image-tab" class="tab-pane fade">
<script type="text/javascript">
var image_campo = 'thumbnail_principal';
</script>
<div class="form-horizontal">
<div class="form-group">
<label for="image" class="col-md-3 control-label">Imagem</label>
<div class="col-md-7">
<form action="<?php echo e(url('admin/pedido-venda/upload')); ?>" method="post" class="form single-dropzone" id="my-dropzone" enctype="multipart/form-data">
<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>" />
<div id="img-thumb-preview">
<img id="img-thumb" class="user size-lg img-thumbnail img-responsive" src="<?php echo (isset($pedido_venda) && $pedido_venda->thumbnail_principal != '') ? url('/uploads/pedido-venda/'.$pedido_venda->thumbnail_principal) : 'http://placehold.it/300x100'; ?>">
</div>
<button type="button" style="display:none;" id="crop-image" class="btn btn-success">Salvar Corte</button>
<button id="upload-submit" class="btn btn-default margin-t-5"><i class="fa fa-upload"></i> Upload Picture</button>
</form>
<form class="hidden" action="<?php echo e(url('admin/pedido-venda/crop')); ?>" id="cropForm" method="POST">
<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>" />
<input type="hidden" name="data_crop">
<input type="hidden" name="file_name">
</form>
</div>
</div>
</div>
</div>
<?php } ?>
<?php if($modulo->galeria){ ?>
<div id="imagens-tab" class="tab-pane fade">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 lista-galeria">
<?php if(isset($pedido_venda) && count($pedido_venda->imagens)){?>
<?php foreach ($pedido_venda->imagens as $image){?>
<div id="item_<?php echo $image->id; ?>" class="item imagem-galeria-<?php echo $image->id; ?>">
<div style="background-image: url(<?php echo "/uploads/pedido-venda/$image->thumbnail_principal";?>);" class="thumb"></div>
<span data="<?php echo $image->id; ?>" data-modulo="pedido-venda" class="icon delete-image" aria-hidden="true"><i class="fa fa-trash"></i></span>
</div>
<?php }?>
<?php }?>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<form class="dropzone" id="galeria-dropzone" method="POST" action="<?php echo (isset($pedido_venda)) ? url('/admin/pedido-venda/upload_galeria/'.$pedido_venda->id) : url('/admin/pedido-venda/upload_galeria/'.$nextId); ?> " enctype="multipart/form-data">
<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>" />
<div class="fallback">
<input name="file" type="file" multiple />
</div>
<form>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
</div>
<div class="fixed-bar" style="z-index: 999">
<div class="form-group item col-md-3">
<label for="subtotal">Subtotal</label>
<input type="number" id="subtotal" name="subtotal" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->subtotal : old('subtotal'); ?>">
</div>
<div class="form-group item col-md-3">
<label for="ajuste">Ajuste</label>
<input type="number" id="ajuste" name="ajuste" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->ajuste : old('ajuste'); ?>">
</div>
<div class="form-group item col-md-3">
<label for="total">Total</label>
<input type="number" id="total" name="total" class="form-control" value="<?php echo (isset($pedido_venda)) ? $pedido_venda->total : old('total'); ?>">
</div>
<?php if(isset($pedido_venda) && $current_role->hasAccess($current_module->nome_tabela.'.update') || !isset($pedido_venda) && $current_role->hasAccess($current_module->nome_tabela.'.create')){ ?>
<div class="item col-md-3">
<button type="submit" class="btn btn-primary btn-block">
<i class="fa fa-btn fa-pencil-alt"></i> Salvar
</button>
</div>
<?php } ?>
</div>
<div id="modal-evento" class="modal fade">
<form method="/" id="formEvento" type="POST">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="time-label"></h4>
</div>
<div class="modal-body" id="conteudo-modal-evento">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</form>
</div>
<?php if(!isset($pedido_venda)){ ?>
<script type="text/javascript" src="<?php echo e(url('js/jquery.card.js')); ?>"></script>
<script>
$(document).ready(function(){
$(document).on('change', '[name="id_cliente"]', function(){
var id_cliente = $(this).val();
var valor_total = $('#total').val();
$.ajax({
url:'/admin/pedido-venda/buscar-cartoes-cliente',
type:'POST',
data:{
id_cliente: id_cliente,
valor_total: valor_total
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$('#cartoes-section').html(data.html);
$('#empresa_id').val(data.empresa).trigger('change');
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
verificarCupomAtivo = (id_cliente) => {
$.ajax({
url:'/admin/pedido-venda/verificar-cupom-ativo',
type:'POST',
data:{
id_cliente: id_cliente
},
beforeSend:function(){
},
success:function(data){
if(data.status){
$('#cupom-desconto').removeClass('hidden');
}else{
$('#cupom-desconto').addClass('hidden');
}
}
});
}
<?php if(isset($pedido_venda)): ?>
$('[name="id_cliente"]').trigger('change');
<?php endif; ?>
$(document).on('click','#voltarEtapa',function(e){
e.preventDefault();
$('[name="cartao_id"][principal]').prop('checked', true);
$('.pagamento').fadeOut('slow');
setTimeout(function(){
$('.cartoes__item').fadeIn('slow');
},500);
$('#outro-cartao').fadeIn('slow');
});
$(document).on('click','#outro-cartao',function(e){
e.preventDefault();
$('[name="cartao_id"]:checked').prop('checked', false);
$('.cartoes__item').fadeOut('slow');
setTimeout(function(){
$('.pagamento').fadeIn('slow');
},500);
$('#outro-cartao').fadeOut('slow');
});
});
</script>
<?php } ?>
<script type="text/javascript">
$(document).on('click', '#btn-oferta-produtos', function(e){
e.preventDefault();
var oferta_id = $(this).data('oferta-id');
if(oferta_id == ''){
alertUtil.alertWarning("Nenhuma oferta selecionada ou não encontrada!");
}else{
$.ajax({
url: '/admin/oferta/produtos/' + oferta_id,
type: 'GET',
beforeSend:function(){
$('.loading').fadeIn();
},
success:function(data){
$('.loading').fadeOut();
$('#conteudo-modal-evento').html(data);
$('#modal-evento').modal('show');
}
});
}
});
$(document).ready(function(){
$('#addCupom').click(function(){
var codigo = $('#cupom').val();
calcularCupomDesconto(codigo);
});
$('#addOferta').click(function(){
var nomeOferta = $('select[name="ofertas"] option:selected').data('titulo');
var idOferta = $('select[name="ofertas"] option:selected').val();
var precoOferta = $('select[name="ofertas"] option:selected').data('preco');
var slugOferta = $('select[name="ofertas"] option:selected').data('slug');
var id_cliente = $('select[name="id_cliente"] option:selected').val();
if(idOferta){
if($('#table-ofertas tbody #oferta-'+idOferta).length){
alertUtil.alertWarning('Essa oferta já foi adicionado.');
}else{
$('#table-ofertas tbody').append('<tr id="oferta-'+idOferta+'"> <input type="hidden" class="oferta" name="oferta-id[]" value="'+idOferta+'"/> <input type="hidden" name="oferta-valor-unitario[]" value="'+precoOferta+'"/> <input type="hidden" class="total" name="oferta-total[]" value="'+precoOferta+'"/> <td>'+nomeOferta+'</td> <td class="valor_unitario" data-unitario="'+precoOferta+'">'+number_format(precoOferta, 2,',','.')+'</td> <td><input type="number" class="form-control quantidade" name="oferta-quantidade[]" value="1"/></td> <td class="valor_total">'+number_format(precoOferta, 2,',','.')+'</td> <td><button class="btn btn-danger removeOferta"><i class="fa fa-trash"></i></button></td> </tr>');
calculaTotal();
var valor_total = $('#total').val();
var cupom_codigo = $('#cupom_codigo').val() ? $('#cupom_codigo').val() : false;
if(cupom_codigo == false){
$('#addCupom').attr('disabled', false);
}else{
calcularCupomDesconto(cupom_codigo);
}
$.ajax({
url:'/admin/pedido-venda/buscar-cartoes-cliente',
type:'POST',
data:{
id_cliente: id_cliente,
valor_total: valor_total
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$('#cartoes-section').html(data.html);
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
}
}else{
alertUtil.alertWarning('Você deve selecionar uma oferta.');
}
});
$('#addComissao').click(function(){
var nomeUsuario = $('select[name="usuarios"] option:selected').text();
var idUsuario = $('select[name="usuarios"] option:selected').val();
if(idUsuario){
if($('#table-comissoes tbody #comissao-'+idUsuario).length){
alertUtil.alertWarning('Esse usuário já foi adicionado.');
}else{
$('#table-comissoes tbody').append('<tr id="comissao-'+idUsuario+'"> <input type="hidden" name="usuario-id[]" value="'+idUsuario+'"/> <input type="hidden" name="comissao-total[]" value="0" class="total"><td><a target="_blank" href="/admin/user/edit/'+idUsuario+'">'+nomeUsuario+'</a></td><td> <select name="comissao-tipo[]" class="form-control tipo"> <option value="PER">Percentual</option> <option value="VAL">Valor Bruto</option> </select> </td> <td><input type="number" class="form-control valor" name="comissao-valor[]" value="0"/></td><td class="valor_total"> 0,00 </td> <td><button class="btn btn-danger removeComissao"><i class="fa fa-trash"></i></button></td> </tr>');
calculaTotal();
}
}else{
alertUtil.alertWarning('Você deve selecionar um usuário.');
}
});
$('#addServico').click(function(){
var nomeServico = $('select[name="servicos"] option:selected').text();
var idServico = $('select[name="servicos"] option:selected').val();
var precoServico = $('select[name="servicos"] option:selected').data('preco');
var slugServico = $('select[name="servicos"] option:selected').data('slug');
var qtdPadrao = $('select[name="servicos"] option:selected').data('qtd-padrao');
if(idServico){
if($('#table-servicos tbody #servico-'+idServico).length){
alertUtil.alertWarning('Esse serviço já foi adicionado.');
}else{
$('#table-servicos tbody').append('<tr id="servico-'+idServico+'"> <input type="hidden" name="servico-id[]" value="'+idServico+'"/> <input type="hidden" class="total" name="servico-total[]" value="'+precoServico*qtdPadrao+'"/> <td><a target="_blank" href="/admin/servico/edit/'+slugServico+'">'+nomeServico+'</a></td> <td class="valor_unitario" data-unitario="'+precoServico+'">'+number_format(precoServico, 2,',','.')+'</td> <td><input type="number" class="form-control quantidade" name="servico-quantidade[]" value="'+qtdPadrao+'"/></td> <td class="valor_total">'+number_format(precoServico*qtdPadrao, 2,',','.')+'</td> <td><button class="btn btn-danger removeServico"><i class="fa fa-trash"></i></button></td> </tr>');
calculaTotal();
}
}else{
alertUtil.alertWarning('Você deve selecionar um serviço.');
}
});
$('#addTaxa').click(function(){
$('#table-taxas tbody').append('<tr><td><input type="text" class="form-control" value="" placeholder="Digite o nome da taxa" name="taxa-nome[]" /></td> <td class="valor_unitario"><input class="form-control total" type="number" value="0" name="taxa-valor[]" /></td> <td><button type="button" class="btn btn-danger removeTaxa"><i class="fa fa-trash"></i></button></td> </tr>');
calculaTotal();
});
$(document).on('click', '.removeTaxa', function(e){
e.preventDefault();
$(this).closest('tr').remove();
});
$('#addHistorico').click(function(){
var notificar_cliente = $('input[name="notificar_cliente"]').prop('checked');
var idStatus = $('select[name="id_pedido_venda_status"] option:selected').val();
var comentario = $('textarea[name="comentario"]').val();
if(idStatus){
$.ajax({
url:'/admin/pedido-venda/save_historico',
type:'POST',
data:{
notificar_cliente: notificar_cliente,
id_status: idStatus,
comentario: comentario,
id_pedido_venda: $('[name="id"]').val()
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
console.log(data);
if(data.status){
$('#table-historico tbody').append('<tr id="historico-'+data.historico.id+'"><input type="hidden" name="historico-edit-id[]" value="'+data.historico.id+'"><td>'+data.historico.data+'</td><td></td><td>'+((data.historico.notificar_cliente==1)?"Sim":"Não")+'</td><td>'+data.historico.status.nome+'</td><td class="valor_total">'+data.historico.comentario+'</td><td><button type="button" class="btn btn-danger deleteHistorico"><i class="fa fa-trash"></i></button></td></tr>');/*<td><a target="_blank" href="http://lotus.localhost/admin/colaborador/edit/'+data.historico.colaborador.id+'">'+data.historico.colaborador.nome+'</a></td>*/
alertUtil.alertSuccess(data.message);
}else{
alertUtil.alertWarning(data.message);
}
}
});
}else{
alertUtil.alertWarning('Você deve selecionar um status.');
}
});
$(document).on('click', '.removeComprovante', function(){
var id_pedido_venda = $(this).data('id');
var $tr = $(this).closest('tr');
var $td = $(this).closest('td');
var messageError = 'Erro ao remover comprovante';
$.ajax({
url:'/admin/pedido-venda/delete-comprovante/' + id_pedido_venda,
type:'GET',
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$td.html('');
$tr.find('.comprovante').html('Comprovante não enviado');
}else{
alertUtil.alertWarning(data.message);
}
},
error:function(){
alertUtil.alertError(messageError);
$('.carregando').fadeOut();
}
});
});
$(document).on('click', '.removeOferta', function(){
$(this).closest('tr').remove();
var cupom_codigo = $('#cupom_codigo').val() ? $('#cupom_codigo').val() : false;
if(cupom_codigo == false){
calculaTotal();
}else{
calcularCupomDesconto(cupom_codigo);
}
});
$(document).on('click', '.removeServico', function(){
$(this).closest('tr').remove();
calculaTotal();
});
$(document).on('click', '.removeComissao', function(){
$(this).closest('tr').remove();
});
$(document).on('click', '.removeHistorico', function(){
$(this).closest('tr').remove();
});
$(document).on('click', '.deleteProduto', function(){
$tr = $(this).closest('tr');
$.ajax({
url:'/admin/pedido-venda/delete-produto',
type:'POST',
data:{
id_produto: $tr.find('[name="produto-edit-id[]"]').val(),
id_pedido_venda: $('[name="id"]').val()
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$tr.remove();
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
$(document).on('click', '.deleteServico', function(){
$tr = $(this).closest('tr');
$.ajax({
url:'/admin/pedido-venda/delete-servico',
type:'POST',
data:{
id_servico: $tr.find('[name="servico-edit-id[]"]').val(),
id_pedido_venda: $('[name="id"]').val()
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$tr.remove();
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
$(document).on('click', '.deleteTaxa', function(){
$tr = $(this).closest('tr');
$.ajax({
url:'/admin/pedido-venda/delete-taxa',
type:'POST',
data:{
id_taxa: $tr.find('[name="edit-taxa-id[]"]').val()
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$tr.remove();
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
$(document).on('click', '.deleteComissao', function(){
$tr = $(this).closest('tr');
$.ajax({
url:'/admin/pedido-venda/delete-comissao',
type:'POST',
data:{
id_comissao: $tr.find('[name="comissao-edit-id[]"]').val()
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$tr.remove();
calculaTotal();
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
$(document).on('click', '.deleteHistorico', function(){
$tr = $(this).closest('tr');
$.ajax({
url:'/admin/pedido-venda-historico/delete/'+$tr.find('[name="historico-edit-id[]"]').val(),
type:'GET',
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$tr.remove();
alertUtil.alertSuccess(data.message);
}else{
alertUtil.alertWarning(data.message);
}
}
});
});
$(document).on('change', '#table-ofertas .valor-unitario', function(){
var $tr = $(this).closest('tr');
var inputQuantidade = $tr.find('.quantidade');
var valorUnitario = $(this).val();
valorUnitario = number_format(valorUnitario, 2,'.','');
$tr.find('.valor_unitario').data('unitario', valorUnitario);
calculaPrecoItem(inputQuantidade);
});
$(document).on('change', '#table-ofertas .quantidade, #table-servicos .quantidade', function(){
calculaPrecoItem($(this));
});
$(document).on('change', '#ajuste', function(){
calculaTotal();
});
$(document).on('change', '#table-taxas .total', function(){
calculaTotal();
});
$(document).on('change', '#table-comissoes .valor, #table-comissoes .tipo', function(){
calculaPrecoComissao($(this).closest('tr'));
});
$('.fixed-bar [type="submit"]').click(function(e){
e.preventDefault();
var wrongValidation = 0;
var inputsNumber = 0;
$('#mainForm [required]').each(function(){
//console.log(tinyMCE.editors[$(this).attr('id')].getContent());
if(!$(this).val() || ($(this).is('textarea') && $(this).hasClass('tinymce') && !tinyMCE.editors[$(this).attr('id')].getContent())){
inputsNumber++;
$(this).css('border-color', '#dd4b39');
if($(this).is('textarea') && $(this).hasClass('tinymce')){
if(!tinyMCE.editors[$(this).attr('id')].getContent()){
$(this).prev().css('border-color', '#dd4b39');
}else{
wrongValidation++;
}
}
}
});
if(inputsNumber > wrongValidation){
$('[href="#info-tab"]').closest('ul').find('li.active').removeClass('active');
$('[href="#info-tab"]').closest('li').attr('class', 'active');
$('.tab-content .tab-pane').removeClass('in active');
$('#info-tab').addClass('in active');
alertUtil.alertError('Verifique os erros do formulário.');
}else{
$('#mainForm').submit();
}
});
$('#estornar').click(function(e){
e.preventDefault();
if(confirm('Você tem certeza? Isso não pode ser desfeito')){
$.ajax({
url:'/admin/pedido-venda/estornar',
type:'POST',
data:{
id:$('[name="id"]').val(),
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
alertUtil.alertSuccess(data.message);
}else{
alertUtil.alertWarning(data.message);
}
}
});
}
});
$('.select2').select2();
$('#ofertas').on('select2:select', function(e){
var data = e.params.data;
var oferta_id = data.id;
$('#btn-oferta-produtos').attr('data-oferta-id', oferta_id);
$.ajax({
url: '/admin/oferta/disponibilidade/' + oferta_id,
type: 'GET',
beforeSend:function(){
$('.carregando').fadeIn();
$('#pdv__disponibilidade').addClass('hidden');
$('#pdv__disponibilidade--produto, #pdv__disponibilidade--oferta').text('0');
},
success:function(oferta){
$('#pdv__disponibilidade').removeClass('hidden');
$('#pdv__disponibilidade--oferta').text(oferta.disponibilidade);
if(oferta.produtos.length == 1){
$('#pdv__disponibilidade--btn_produto').addClass('hidden');
$('#pdv__disponibilidade--produto').removeClass('hidden');
$('#pdv__disponibilidade--produto').text(oferta.produtos[0].disponibilidade);
}else{
$('#pdv__disponibilidade--produto').addClass('hidden');
$('#pdv__disponibilidade--btn_produto').removeClass('hidden');
$('#pdv__disponibilidade--produto').text('0');
}
$('.carregando').fadeOut();
},
error:function(){
$('.carregando').fadeOut();
}
});
});
});
function calculaPrecoItem(inputQuantidade){
var $tr = inputQuantidade.closest('tr');
var valorUnitario = $tr.find('.valor_unitario').data('unitario');
var quantidade = inputQuantidade.val();
var valorTotal = valorUnitario * quantidade;
$tr.find('.total').val(valorTotal); // Atualiza o valor total utilizado para os calculos
$tr.find('.valor_total').text(number_format(valorTotal,2,',','.')); // Atualiza o valor total exibido na tela
var cupom_codigo = $('#cupom_codigo').val() ? $('#cupom_codigo').val() : false;
if(cupom_codigo === false){
calculaTotal();
}else{
calcularCupomDesconto(cupom_codigo);
}
}
function calculaPrecoComissao(tr){
var tipo = tr.find('.tipo').val();
var valor = tr.find('.valor').val();
if(tipo == 'VAL'){
var total = valor;
}else{
var valor_pdv = 0;
$('#table-ofertas tbody tr').each(function(){
valor_pdv += parseFloat($(this).find('.total').val());
});
$('#table-servicos tbody tr').each(function(){
valor_pdv += parseFloat($(this).find('.total').val());
});
var total = valor_pdv * (valor/100);
}
tr.find('.total').val(total); // Atualiza o valor total utilizado para os calculos
tr.find('.valor_total').text(number_format(total,2,',','.')); // Atualiza o valor total exibido na tela
}
function calcularCupomDesconto(codigo){
var id_cliente = $('select[name="id_cliente"] option:selected').val();
var ofertas = [];
$('#table-ofertas tbody tr').each(function(){
ofertas.push({
id : $(this).find('.oferta').val(),
quantidade : $(this).find('.quantidade').val()
});
});
$.ajax({
url:'/admin/pedido-venda/calcular-cupom',
type:'POST',
data:{
id_cliente : id_cliente,
codigo : codigo,
ofertas : ofertas
},
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
if(data.status){
$('#table-cupom tbody').html(data.html);
calculaTotalDescontos();
$('#cupom').val('');
$('#addCupom').attr('disabled', true);
}else{
alertUtil.alertWarning(data.message);
}
}
});
}
function calculaTotalDescontos(){
var cupom_desconto = $('#cupom_desconto').val() ? parseFloat($('#cupom_desconto').val()) : 0;
var total_ajuste = cupom_desconto;
total_ajuste = number_format(total_ajuste, 2, '.', '');
total_ajuste = parseFloat(total_ajuste);
$('#ajuste').val(total_ajuste);
setTimeout(function() {
calculaTotal();
}, 1000);
}
function calculaTotal(){
var subtotal = 0;
console.log('ofertas');
$('#table-ofertas tbody tr').each(function(){
subtotal += parseFloat($(this).find('.total').val());
});
subtotal = number_format(subtotal, 2, '.', '');
subtotal = parseFloat(subtotal);
$('#table-servicos tbody tr').each(function(){
subtotal += parseFloat($(this).find('.total').val());
});
subtotal = number_format(subtotal, 2, '.', '');
subtotal = parseFloat(subtotal);
$('#table-taxas tbody tr').each(function(){
subtotal += parseFloat($(this).find('.total').val());
});
subtotal = number_format(subtotal, 2, '.', '');
subtotal = parseFloat(subtotal);
$('#table-comissoes tbody tr').each(function(){
calculaPrecoComissao($(this));
});
var ajuste = $('#ajuste').val() ? parseFloat($('#ajuste').val()) : 0;
var total = subtotal + ajuste;
total = number_format(total, 2, '.', '');
total = parseFloat(total);
var htmlParcelas = '';
for (var i = 1; i <= 6; i++) {
valor = total / i;
htmlParcelas += '<option value="'+i+'">'+i+'x de R$ '+number_format(valor, 2,',','.')+'</option>';
}
$('[name="parcelas"]').html(htmlParcelas);
$('[name="subtotal"]').val(subtotal);
$('[name="total"]').val(total);
$('[name="ajuste"]').val($('#ajuste').val());
}
$(document).ready(function(){
$(".select2-clientes").select2({
minimumInputLength: 2,
placeholder: 'Buscar Cliente',
ajax: {
url: 'admin/pedido-venda/buscar-cliente',
dataType: 'json',
delay: 250,
type: "POST",
data: function (term) {
return {
term : term,
origem : 'oferta'
};
},
processResults: function (data, params) {
return {
results: $.map(data, function (item) {
return {
text: item.nome_completo + ' - : '+item.email,
id: item.id,
}
})
};
}
}
});
$(document).on('change', '.select2-clientes', function(){
let val = $(this).val();
verificarCupomAtivo(val);
});
});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make($current_template, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>