/home/dvjjulio/softtrash/app/Clientes.php
<?php
namespace Trash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Clientes extends Authenticatable
{
//
protected $table = 'cliente';
//public $timestamps = false;
public function getClientes(){
$sql = "SELECT c.id,c.cliente,c.nombre_comercial,c.latitude, c.longitude, c.alta, c.baja,
c.semades, c.giro_id, c.contacto_factura, c.email_factura, c.contacto_cobranza,
c.email_cobranza, c.rfc, c.direccion, c.telefono, c.municipio, c.colonia, c.cp,
c.inorganicos, c.organicos, c.sanitarios, c.factura_entrega, c.modo_pago,
c.cuenta_bancaria, c.cuota_id, c.unidad_id, c.fiscal, c.pu, c.ret,
c.observaciones, c.ultima_facturada, c.status_id,
c.created_at, c.updated_at, c.user_created, g.giro, u.unidad
FROM cliente c
JOIN giro_empresa g ON g.id = c.giro_id
JOIN unidad u ON u.id = c.unidad_id
ORDER BY c.semades";
$data = \DB::select(\DB::raw($sql));
if(count($data)!=null){
return $data;
}else{
return null;
}
}
public function getCliente_route(){
$sql = "SELECT c.id,c.cliente,c.nombre_comercial,c.latitude, c.longitude, c.alta, c.baja,
c.semades, c.giro_id, c.contacto_factura, c.email_factura, c.contacto_cobranza,
c.email_cobranza, c.rfc, c.direccion, c.telefono, c.municipio, c.colonia, c.cp,
c.inorganicos, c.organicos, c.sanitarios, c.factura_entrega, c.modo_pago,
c.cuenta_bancaria, c.cuota_id, c.unidad_id, c.fiscal, c.pu, c.ret,
c.observaciones, c.ultima_facturada, c.status_id,
c.created_at, c.updated_at, c.user_created, g.giro, u.unidad
FROM cliente c
JOIN giro_empresa g ON g.id = c.giro_id
JOIN unidad u ON u.id = c.unidad_id
ORDER BY c.nombre_comercial";
$data = \DB::select(\DB::raw($sql));
if(count($data)!=null){
return $data;
}else{
return null;
}
}
public function getCliente($id){
$sql = "SELECT c.id,c.cliente,c.nombre_comercial,c.latitude, c.longitude, c.alta, c.baja,
c.semades, c.giro_id, c.contacto_factura, c.email_factura, c.contacto_cobranza,
c.email_cobranza, c.rfc, c.direccion, c.telefono, c.municipio, c.colonia, c.cp,
c.inorganicos, c.organicos, c.sanitarios, c.factura_entrega, c.modo_pago,
c.cuenta_bancaria, c.cuota_id, c.unidad_id, c.fiscal, c.pu, c.ret,
c.observaciones, c.ultima_facturada, c.status_id,
c.created_at, c.updated_at, c.user_created, g.giro, u.unidad, cu.cuota,
p.peso, p.mes_id, c.ruta_id, c.status_id
FROM cliente c
JOIN giro_empresa g ON g.id = c.giro_id
JOIN unidad u ON u.id = c.unidad_id
JOIN cuota cu ON cu.id = c.cuota_id
LEFT JOIN peso_cliente p ON p.cliente_id = c.id
WHERE c.id=$id
ORDER BY c.nombre_comercial";
$data = \DB::select(\DB::raw($sql));
if(count($data)!=null){
return response()->json(array('status'=>true, 'data'=>$data));
}else{
return response()->json(array('status'=>false));
}
}
public function clientesNear($latitude, $longitude){
$sql = "SELECT c.id, c.nombre_comercial, (6371 * ACOS(
SIN(RADIANS(c.latitude)) * SIN(RADIANS($latitude))
+ COS(RADIANS(c.longitude - $longitude)) * COS(RADIANS(c.latitude))
* COS(RADIANS($latitude))
)
) AS distance
FROM cliente c
WHERE status_id = 1
HAVING distance < 1 /* 1 KM a la redonda */
ORDER BY nombre_comercial ";
$cliente = \DB::select(\DB::raw($sql));
if(count($cliente)!=null){
return response()->json(array('status'=>true, 'data'=>$cliente));
}else{
return response()->json(array('status'=>false));
}
}
}