Skip to content

Commit

Permalink
egreso por compra
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroziux committed Nov 5, 2015
1 parent 8c68737 commit 6f6a1ad
Show file tree
Hide file tree
Showing 15 changed files with 831 additions and 247 deletions.
10 changes: 10 additions & 0 deletions .idea/dataSources.ids

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

579 changes: 391 additions & 188 deletions .idea/workspace.xml

Large diffs are not rendered by default.

32 changes: 26 additions & 6 deletions app/Http/Controllers/ComprasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace App\Http\Controllers;

use App\Bodegas;
use App\caja;
use App\Compra_Detalle;
use App\compras;
use App\egresos;
use App\Historico_Compras;
use App\ingresos;
use App\productos;
use App\productos_configurables;
use App\proveedores;
Expand Down Expand Up @@ -83,9 +86,9 @@ public function store(Requests\ComprasRequest $request)
public function show($id)
{
//
$compras = compras::with('proveedor')->findOrfail($id);
$items = compra_detalle::where('compra_id', '=', $id)->with('producto_configurable')->get();
return view('app/compras/compras_show', compact(['compras', 'items']));
$compra = compras::with('proveedor','egresos')->findOrfail($id);
$items = compra_detalle::where('compra_id', $id)->with('producto_configurable')->get();
return view('app/compras/compras_show', compact(['compra', 'items']));
}

/**
Expand Down Expand Up @@ -122,10 +125,20 @@ public function destroy($id)
//
}

public function pagar($id)
public function pagar(Request $request, $id)
{
$compra = compras::find($id);
return $compra;
//dd($request->all());
$caja_abierta = caja::CajaAbierta();
if (!isset($caja_abierta)) {
Session::flash('mensaje', 'Primero debe abrir al caja para Agregar un pago a la factura');
return redirect('caja');
}
egresos::egresoXcompra($request,$id, $caja_abierta->id);
Session::flash('mensaje', 'Pago realizado con exito');
return redirect('compras/'. $id);



}

public function pdf($id)
Expand All @@ -145,4 +158,11 @@ public function mail(Request $request, $id)
Session::flash('mensaje', 'factura enviada con exito');
return back();
}

public function imprimir($id)
{
$compra = compras::with('proveedor')->findOrfail($id);
$items = compra_detalle::where('compra_id', '=', $id)->with('producto_configurable')->get();
return view('app/compras/compras_print', compact(['compra', 'items']));
}
}
5 changes: 3 additions & 2 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@

/******* compras ********/
Route::get('compras/chart', 'ComprasController@chart');
Route::get('compras/print/{id}', 'ComprasController@imprimir');
Route::get('compras/pdf/{id}', 'ComprasController@pdf');
Route::get('compras/mail/{id}', 'ComprasController@mail');
Route::get('compras/pagar/{id}', 'ComprasController@pagar');
Route::resource('compras', 'ComprasController',['except' => ['chart','pdf','mail','pagar']]);
Route::put('compras/pagar/{id}', 'ComprasController@pagar');
Route::resource('compras', 'ComprasController',['except' => ['chart','print','pdf','mail','pagar']]);

/******* marcas ********/
Route::resource('marcas', 'MarcasController',['except' => []]);
Expand Down
31 changes: 28 additions & 3 deletions app/caja.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public static function IngresoCaja($ingresos, $factura)

}

public static function ingresoCajaSimple($request){
public static function ingresoCajaSimple($request)
{
$caja = caja::CajaAbierta();
foreach($request->pagos as $pago){
foreach ($request->pagos as $pago) {
switch ($pago['id']) {
case 1:
$tipo_movimiento = 2;
Expand All @@ -83,7 +84,7 @@ public static function ingresoCajaSimple($request){
$tipo_movimiento = 3;
break;
}
$concepto = $request->concepto. ' forma de pago '. $pago['pago'];
$concepto = $request->concepto . ' forma de pago ' . $pago['pago'];
caja_detalle::movimiento($caja->id, $concepto, $pago['id'], $pago['valor'], $tipo_movimiento);

}
Expand Down Expand Up @@ -128,6 +129,30 @@ public static function EgresoCaja($egresos)
}
}

public static function EgresoXfactura($pagos, $caja_id, $factura)
{
//pendiente de revisar_todo el modulo de pagos
foreach ($pagos as $pago) {
switch ($pago['id']) {
case 1:
$tipo_movimiento = 5;
break;
case 6:
$tipo_movimiento = 4;
break;
default:
$tipo_movimiento = 3;
break;
}
if($tipo_movimiento == 5){
$concepto = 'pago de la compra con factura #' . $factura . ' en ' . $pago['pago'];
caja_detalle::movimiento($caja_id, $concepto, $pago['id'], $pago['valor'], $tipo_movimiento);
}


}
}

public static function AbrirCaja($ingreso, $nota)
{

Expand Down
5 changes: 5 additions & 0 deletions app/compras.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function proveedor()
return $this->belongsTo('App\proveedores');
}

public function egresos()
{
return $this->hasMany('App\egresos', 'compra_id');
}

public function tienda()
{
return $this->belongsTo('App\tiendas');
Expand Down
44 changes: 44 additions & 0 deletions app/egresos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class egresos extends Model
{
//
//busco la tabla egresos
public function getTable()
{
//return Session::get('tenant.id').'_egresos';
return 'egresos';
}

protected $fillable = [
'column1',
'column1'

];
public function formas_pago()
{
return $this->belongsTo('App\formas_pago', 'formas_pago_id');
}


public static function egresoXcompra($request, $id, $caja_id)
{
$total = 0;
foreach ($request->pagos as $pago) {
$egreso = new egresos();
$egreso->compra_id = $id;
$egreso->formas_pago_id = $pago['id'];
$egreso->valor = $pago['valor'];
$egreso->save();
$total += $pago['valor'];
}
$compra = compras::find($id);
$compra->pagado = $compra->pagado + $total;
$compra->save();
caja::EgresoXfactura($request->pagos,$caja_id,$compra->factura);
}
}
37 changes: 37 additions & 0 deletions database/migrations/2015_11_05_031207_egresos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Egresos extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('egresos', function(Blueprint $table)
{
$table->increments('id');
$table->integer('compra_id')->nullable();
$table->integer('gasto_id')->nullable();
$table->integer('formas_pago_id')->nullable();
$table->decimal('valor',16,2);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('egresos');
}
}
49 changes: 49 additions & 0 deletions public/js/pagos_compras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Created by userpc on 4/11/2015.
*/
var i = 0
var j = 0
function abrir_pagos(e) {

event.preventDefault(); // para FF standard
event.returnValue=false; // para IE
$('#pagos').modal('show');
var valor = $('#pagar').data('pago');
$('#total-pago').html('0')
$('#faltante').html(valor)
$('#PAGAR').prop('disabled', true);

}

function totalpago() {
var total = $('#pagar').data('pago');
var faltante
var suma = 0
$('.pagoitem').each(function () {
suma += parseInt($(this).val())
})
faltante = total - suma
$('#total-pago').html(suma)
$('#faltante').html(faltante)
$('#PAGAR').prop('disabled', false);


}

function Adpago(pago, id) {
valor = document.getElementById("faltante").innerText
item = '<tr class="success" id="' + j + '"><td><input type="text" name="pagos[' + j + '][pago]" value="' + pago +
'" class="pago font-w600" readonly></td>' + '<td width="40%"><input type="text" name="pagos[' + j + '][valor]" value="' +
valor + '" class="pago pagoitem" onchange="totalpago()" ></td>' +
'<td><input type="hidden" name="pagos[' + j + '][id]" value="' + id + '"></td>' +
'<td><a class="btn btn-danger btn-xs" href="#" onclick="eliminar_pago(' + j + ')" role="button">' +
'<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td></tr>'
$('#pagos-item').append(item)
totalpago()
j++
}

function eliminar_pago(id) {
$('#pagos-item').find('#' + id).html('')
totalpago()
}
Loading

0 comments on commit 6f6a1ad

Please sign in to comment.