index.ctpADD
<div class="row"> <div class="col-md-3"> <div class="actions"> <div class="panel panel-default"> <div class="panel-heading">Ações</div> <div class="panel-body"> <ul class="nav nav-pills nav-stacked"> <li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span> Nova Compra'), array('action' => 'add'), array('escape' => false)); ?></li> <li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-list"></span> Formas Pagamentos'), array('controller' => 'forma_pagamentos', 'action' => 'index'), array('escape' => false)); ?> </li> <li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span> Nova Forma Pagamento'), array('controller' => 'forma_pagamentos', 'action' => 'add'), array('escape' => false)); ?> </li> <li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-list"></span> Fornecedores'), array('controller' => 'suppliers', 'action' => 'index'), array('escape' => false)); ?> </li> <li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span> Novo Fornecedor'), array('controller' => 'suppliers', 'action' => 'add'), array('escape' => false)); ?> </li> </ul> </div><!-- end body --> </div><!-- end panel --> </div><!-- end actions --> <?php echo $this->element('side_totaliza_compras'); ?> </div><!-- end col md 3 --> <div class="col-md-9"> <div class="table-responsive"> <table cellpadding="0" cellspacing="0" class="table table-striped"> <thead> <tr> <th><?php echo $this->Paginator->sort('supplier_fantasia', 'Fornecedor'); ?></th> <th><?php echo $this->Paginator->sort('data', 'Pedido'); ?></th> <th><?php echo $this->Paginator->sort('entrega', 'Entrega'); ?></th> <th><?php echo $this->Paginator->sort('forma_pagamento_id', 'Tipo'); ?></th> <th><?php echo $this->Paginator->sort('data_pagamento', 'Vencimento'); ?></th> <th><?php echo $this->Paginator->sort('valor'); ?></th> <th><?php echo $this->Paginator->sort('status'); ?></th> <th class="actions"></th> </tr> </thead> <tbody> <?php foreach ($compras as $compra): ?> <tr> <td> <?php echo $this->Html->link($compra['Supplier']['fantasia'], array('controller' => 'suppliers', 'action' => 'view', $compra['Supplier']['id'])); ?> </td> <td><?php echo h($this->Locale->date($compra['Compra']['data'])); ?> </td> <td> <?php $dataAtual = date('d/m/Y'); $dataEntrega = $this->Locale->date($compra['Compra']['entrega']); $diferencaEntrega = $this->Math->diferencaDeDatas($dataAtual, $dataEntrega, 'dias'); if ($dataAtual >= $dataEntrega) { $entregaIcon = 'glyphicon-home'; $entregaColor = 'label label-primary'; } else { $entregaIcon = 'glyphicon-road'; $entregaColor = 'label label-warning'; } ?> <!-- <span class="label <?php echo $entregaColor; ?>"><?php echo ( $entregaIcon == "glyphicon-home" ? '' : $diferencaEntrega ); ?> <span class="glyphicon <?php echo $entregaIcon; ?>"></span></span> --> <?php echo h($this->Locale->date($compra['Compra']['entrega'])); ?> </td> <td> <?php $formaPagamento = $compra['FormaPagamento']['id']; switch ($formaPagamento) { case 1: $formaPagamentoClass = 'label-danger'; break; case 2: $formaPagamentoClass = 'label-info'; break; default: $formaPagamentoClass = 'label-default'; break; } ?> <span class="label <?php echo $formaPagamentoClass; ?>"> <?php echo $compra['FormaPagamento']['descricao']; ?> </span> </td> <td><?php echo h($this->Locale->date($compra['Compra']['data_pagamento'])); ?> </td> <td><?php echo h($compra['Compra']['valor']); ?> </td> <td> <?php $statusPedido = $compra['Compra']['status']; switch ($statusPedido) { case 1: $statusPedidoIcon = 'glyphicon-ok'; $statusPedidoLabel = 'label-warning'; $statusPedidoTitle = 'Pedido Realizado.'; break; case 2: $statusPedidoIcon = 'glyphicon-ok'; $statusPedidoLabel = 'label-primary'; $statusPedidoTitle = 'Pedido Entregue.'; break; case 3: $statusPedidoIcon = 'glyphicon-ok'; $statusPedidoLabel = 'label-success'; $statusPedidoTitle = 'Pedido Entregue e Pago.'; break; default: $statusPedidoIcon = 'glyphicon-asterisk'; $statusPedidoLabel = 'label-default'; $statusPedidoTitle = 'Status não Informado.'; break; } ?> <span title="<?php echo $statusPedidoTitle; ?>" class="label <?php echo $statusPedidoLabel; ?>"><span class="glyphicon <?php echo $statusPedidoIcon; ?>"></span></span> <?php //echo h($compra['Compra']['status']); ?> </td> <td class="actions"> <?php echo $this->Html->link('<span class="glyphicon glyphicon-search"></span>', array('action' => 'view', $compra['Compra']['id']), array('escape' => false)); ?> <?php echo $this->Html->link('<span class="glyphicon glyphicon-edit"></span>', array('action' => 'edit', $compra['Compra']['id']), array('escape' => false)); ?> <?php echo $this->Form->postLink('<span class="glyphicon glyphicon-remove"></span>', array('action' => 'delete', $compra['Compra']['id']), array('escape' => false), __('Are you sure you want to delete # %s?', $compra['Compra']['id'])); ?> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <p> <small><?php echo $this->Paginator->counter(array('format' => __('Página {:page} de {:pages}, mostrando {:current} registros de um total de {:count}, começando no registro {:start}, terminando em {:end}')));?></small> </p> <?php $params = $this->Paginator->params(); if ($params['pageCount'] > 1) { ?> <ul class="pagination pagination-sm"> <?php echo $this->Paginator->prev('← Anterior', array('class' => 'prev','tag' => 'li','escape' => false), '<a onclick="return false;">← Anterior</a>', array('class' => 'prev disabled','tag' => 'li','escape' => false)); echo $this->Paginator->numbers(array('separator' => '','tag' => 'li','currentClass' => 'active','currentTag' => 'a')); echo $this->Paginator->next('Próxima →', array('class' => 'Próxima','tag' => 'li','escape' => false), '<a onclick="return false;">Next →</a>', array('class' => 'next disabled','tag' => 'li','escape' => false)); ?> </ul> <?php } ?> </div> <!-- end col md 9 --> </div><!-- end row -->
public function add() { if ($this->request->is('post')) { $this->Compra->create(); if ($this->Compra->save($this->request->data)) { $this->Session->setFlash(__('The compra has been saved.'), 'default', array('class' => 'alert alert-success')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The compra could not be saved. Please, try again.'), 'default', array('class' => 'alert alert-danger')); } } $formaPagamentos = $this->Compra->FormaPagamento->find('list', array('fields' => array('FormaPagamento.descricao'))); $suppliers = $this->Compra->Supplier->find('list', array('fields' => array('Supplier.fantasia'))); $this->set(compact('formaPagamentos', 'suppliers')); }
ADD.CTPIndex
<div class="compras form">
public function <divindex() class="col-md-9">{
<?php echo $this->Form>Compra->create('Compra', array('role' => 'form')); ?>
>recursive <div= class="form-group">0;
<?php echo $this->Form>Paginator->input('valor',>settings = array('class''limit' => 'form-control'20, 'placeholder''order' => 'Valor'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('data', array('class' => 'form-control', 'placeholder''Compra.data' => 'Data''DESC'));?>
</div>
<div class="form-group">
<?php echoif ($this->Form>request->input('entrega', array>is('class' => 'form-control', 'placeholder' => 'Entrega''requested'));?>
</div>
<div class="form-group">{
<?php echoreturn $this->Form->input('forma_pagamento_id', array>paginate('class' => 'form-control', 'placeholder' => 'Forma de Pagamento', 'label' => 'Forma de Pagamento'));?>
</div>
} <divelse class="form-group">{
<?php echo $this->Form->input('data_pagamento', array>set('type' => 'text', 'class' => 'form-control''compras', 'placeholder' => 'Data Pagamento'));?>
</div>
<div class="form-group">
<?php echo $this->Form>Paginator->input('supplier_id', array>paginate('class' => 'form-control', 'placeholder' => 'Fornecedor', 'label' => 'Fornecedor'));?>
</div>}
<div class="form-group">
<?php$formaPagamentos echo= $this->Form>Compra->input>FormaPagamento->find('status''list', array('options''fields' => array(0 => '[Informe o Status]', 1 => 'Pedido Realizado', 2 => 'Pedido Entregue', 3 => 'Pedido entregue e Pago''FormaPagamento.descricao'), 'class' => 'form-control', 'placeholder' => 'Status do Pagamento'));?>
</div>
<div class="form-group">
<?php$suppliers echo= $this->Form>Compra->input>Supplier->find('obs''list', array('class' => 'form-control', 'placeholder''fields' => 'Observações..array('Supplier.'fantasia')));?>
</div>
<div class="form-group">
<?php echo $this->Form->submit>set(__compact('Submit')'formaPagamentos', array('class' => 'btn btn-default''suppliers')); ?>
</div>
<?php echo $this->Form->end() ?>
</div><!-- end col md 12 -->
</div><!-- end row -->}
Modal com Formulário na view index
ComprasController.phpformulario no modal
<div class="modal-body">
<?php echo $this->Form->create('Compra', array('action' => 'add', 'role' => 'form')); ?>
<div class="form-group">
<?php echo $this->Form->input('valor', array('class' => 'form-control', 'placeholder' => 'Valor'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('data', array('class' => 'form-control', 'placeholder' => 'Data'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('entrega', array('class' => 'form-control', 'placeholder' => 'Entrega'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('forma_pagamento_id', array('class' => 'form-control', 'placeholder' => 'Forma de Pagamento', 'label' => 'Forma de Pagamento'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('data_pagamento', array('type' => 'text', 'class' => 'form-control', 'placeholder' => 'Data Pagamento'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('supplier_id', array('class' => 'form-control', 'placeholder' => 'Fornecedor', 'label' => 'Fornecedor'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('status', array('options' => array(0 => '[Informe o Status]', 1 => 'Pedido Realizado', 2 => 'Pedido Entregue', 3 => 'Pedido entregue e Pago'), 'class' => 'form-control', 'placeholder' => 'Status do Pagamento'));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('obs', array('class' => 'form-control', 'placeholder' => 'Observações...'));?>
</div>
<div class="form-group">
<?php echo $this->Form->submit(__('Submit'), array('class' => 'btn btn-default')); ?>
</div>
<?php echo $this->Form->end() ?>
</div>