Skip to content

Commit

Permalink
Inclusão forma de pagamento
Browse files Browse the repository at this point in the history
  • Loading branch information
weltonwms committed Sep 2, 2017
1 parent 2232499 commit ad7cf12
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/Relatorio.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function getRelatorio()
$dt = Util::dataToMysql(request('periodo_final'));
$this->query->where('data', '<=', $dt);
endif;
if (request('forma_pagamento')):
$this->query->where('forma_pagamento', request('forma_pagamento'));
endif;

$this->items = $this->query->orderBy('data', 'desc')->get();
$this->calcTotalGeral();
return $this;
Expand Down
8 changes: 7 additions & 1 deletion app/Venda.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Venda extends Model
{
protected $fillable=['produto_id',"cliente_id",'valor_compra','valor_venda','qtd','observacao','data'];
protected $fillable=['produto_id',"cliente_id",'valor_compra','valor_venda','qtd','observacao','data','forma_pagamento'];
protected $dates = array('data');

public function produto()
Expand Down Expand Up @@ -102,6 +102,12 @@ public function setDataAttribute($value)
$this->attributes['data'] = Carbon::createFromFormat('d/m/Y', $value);
}

public function getNomeFormaPagamentoAttribute()
{
$nomes=[1=>'Dinheiro',2=>'Cartão'];
return isset($nomes[$this->forma_pagamento])?$nomes[$this->forma_pagamento]:null;
}

public function moneytoBr($attr)
{
return number_format($this->$attr, 2, ',', '.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function up()
$table->decimal('valor_compra', 10, 2);
$table->decimal('valor_venda', 10, 2);
$table->integer('qtd');
$table->integer('forma_pagamento');
$table->string('observacao')->nullable();
$table->timestamps();
$table->foreign('cliente_id')->references('id')->on('clientes');
Expand Down
2 changes: 2 additions & 0 deletions public/js/vendas.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ $("#form-venda").validate({
valor_venda: {required: true},
produto_id: {required: true},
cliente_id: {required: true},
forma_pagamento: {required: true},
qtd: {required: true}

},
Expand All @@ -87,6 +88,7 @@ $("#form-venda").validate({
valor_venda: {required: 'Digite o valor da Venda'},
produto_id: {required: "Selecione o Produto"},
cliente_id: {required: "Selecione o Cliente"},
forma_pagamento: {required: "Selecione forma de Pagamento"},
qtd: {required: "Digite a Qtd."}

}
Expand Down
1 change: 1 addition & 0 deletions resources/macros/componentes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

Form::component('bsText', 'components.form.text', ['name', 'value' => null, 'attributes' => []]);
Form::component('listMultiple', 'components.form.listMultiple', ['name', 'elements','value' => [], 'attributes' => []]);
Form::component('list', 'components.form.list', ['name', 'elements','value' => null, 'attributes' => []]);
38 changes: 38 additions & 0 deletions resources/views/components/form/list.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
$class='form-control ';
if(isset($attributes['class'])):
$class.=$attributes['class'];
unset($attributes['class']);
endif;
if(is_array($name)):
$label=current($name);
$name=key($name);
else:
$label=$name;
endif;
$atributos='';
foreach ($attributes as $key=>$attribute):
$atributos.="$key=$attribute ";
endforeach;
//echo $atributos; exit();
?>

<div class="form-group">
{{ Form::label($label, null, ['class' => 'control-label']) }}
<select name="{{$name}}" class="{{$class}}" {{$atributos}}>
@foreach($elements as $key=>$element)
<option value="{{$key}}"

<?php echo $value == $key ? "selected='selected'" : '' ?>

>{{$element}}</option>
@endforeach

</select>
</div>

12 changes: 9 additions & 3 deletions resources/views/relatorios/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'value' => request('periodo_final'),
'atributos' => ['class' => 'dateBr']
];
$formas_pg=[""=>'-Todos-','1'=>'Dinheiro','2'=>'Cartão'];
use App\Helpers\Util;
?>
{!! Form::open(['route'=>'relatorio.index','id'=>'form-relatorio'])!!}
Expand All @@ -23,7 +24,7 @@
<div class="col-md-3">
{!! Form::listMultiple(['produto_id[]'=>'Produto'],$produtos,request('produto_id'),['class'=>'meu_chosen','data-placeholder'=>'-Todos-']) !!}
</div>
<div class="col-md-3">
<div class="col-md-2">
{!! Form::listMultiple(['cliente_id[]'=>'Cliente'],$clientes,request('cliente_id'),['class'=>'meu_chosen','data-placeholder'=>'-Todos-']) !!}
</div>
<div class="col-md-2">
Expand All @@ -33,9 +34,12 @@
{!! Html::formGroupFlex($dt_final) !!}
</div>
<div class="col-md-2">
{!! Form::list(['forma_pagamento'=>'Forma Pagamento'],$formas_pg,request('forma_pagamento')) !!}
</div>
<div class="col-md-1">
<div class="form-group">
<label class="control-label"><span class="glyphicon glyphicon-play"></span></label>
<button type="submit" class="btn btn-primary form-control">Consultar</button>
<label class="control-label">Buscar</label>
<button type="submit" class="btn btn-primary form-control"><span class="glyphicon glyphicon-play"></span></button>
</div>

</div>
Expand All @@ -62,6 +66,7 @@
<th>Qtd</th>
<th>Total Venda</th>
<th>Lucro</th>
<th>Pagamento</th>
</thead>

<tbody>
Expand All @@ -75,6 +80,7 @@
<td>{{$item->qtd}}</td>
<td>{{$item->moneyToBr('total_venda')}}</td>
<td>{{$item->moneyToBr('lucro')}}</td>
<td>{{$item->nome_forma_pagamento}}</td>
</tr>


Expand Down
6 changes: 6 additions & 0 deletions resources/views/vendas/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'value'=>(isset($venda)) ? $venda->data->format('d/m/Y') : \Carbon\Carbon::now()->format('d\/m\/Y'),
'atributos'=>['class'=>'dateBr']
];
$formas_pagamento=['1'=>'Dinheiro','2'=>'Cartão'];
?>

Expand All @@ -40,11 +41,16 @@
<div class="col-md-2 ">
{!! Html::formGroup('qtd','Qtd',$errors) !!}
</div>

<div class="col-md-2">
<div class="form-group "><label for="total" class="control-label">Total</label>
<input class=" form-control money" name="total" type="text" id="total">
</div>
</div>

<div class="col-md-4">
{!! Html::formGroupSelect('forma_pagamento',$formas_pagamento,'Forma Pagamento',$errors,' meu_chosen') !!}
</div>
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions resources/views/vendas/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<th>Valor Un. Compra</th>
<th>Valor Un. Venda</th>
<th>Qtd</th>
<th>Pagamento</th>
<th>Acões</th>
</tr>
</thead>
Expand All @@ -43,6 +44,7 @@
<td>R$ {{$venda->formated_valor_compra}}</td>
<td> R$ {{$venda->formated_valor_venda}}</td>
<td>{{$venda->qtd}}</td>
<td>{{$venda->nome_forma_pagamento}}</td>
<td class="col-md-2">
<button data-toggle="modal" data-target="#myModal"
class='btn btn-default' data-href="{{url("vendas/$venda->id/edit")}}">Editar
Expand Down

0 comments on commit ad7cf12

Please sign in to comment.