public function update_producto(Request $request)
 {
     $input = $request->all();
     $producto = Producto::findOrFail($input['objeto_id']);
     $response = CarritoComprasController::update($producto->stock, $input, 'productos');
     return \Response::json($response);
 }
Ejemplo n.º 2
0
 public function actionProductos()
 {
     $query = Producto::find();
     $pagination = new Pagination(['defaultPageSize' => 9, 'totalCount' => $query->count()]);
     $productos = $query->orderBy('id')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('productos', ['productos' => $productos, 'pagination' => $pagination]);
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     $productoId = $request->input("p_id");
     $producto = Producto::find($productoId);
     if (is_null($producto)) {
         App::abort(404);
     }
     $documento = new Producto_Documento();
     $form_data = array('route' => 'ProgramaDocumentos.store', 'method' => 'POST', 'role' => 'form', 'id' => 'form1', 'class' => 'col s10 offset-s1', 'files' => true);
     return view('admin.form_productoDocumento', compact('producto', 'documento', 'form_data'));
 }
Ejemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Producto::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['idProducto' => $this->idProducto, 'codigo' => $this->codigo, 'precio' => $this->precio, 'embalaje_idEmbalaje' => $this->embalaje_idEmbalaje, 'impuestos_idImpuesto' => $this->impuestos_idImpuesto]);
     $query->andFilterWhere(['like', 'producto', $this->producto]);
     return $dataProvider;
 }
Ejemplo n.º 5
0
 /**
  * CRUD para flujo Caja
  *
  * @return Response
  */
 public function CrudFlujoCaja()
 {
     $options = array(0 => 'No', 1 => 'Si');
     $productos = Producto::lists('nombre', 'id');
     $edit = DataEdit::source(new FlujoCaja());
     $edit->link("/flujo_caja/lista", "Lista Flujo de Caja", "TR")->back();
     $edit->set('user_id', \Auth::user()->id);
     $edit->add('producto_id', 'Producto', 'select')->options($productos);
     $edit->add('entrada', 'Monto Entrada', 'text')->rule('required');
     $edit->add('salida', 'Monto Salida', 'text')->rule('required');
     $edit->add('observacion', 'Observación', 'textarea');
     $edit->add('membresia', 'Es Membresia', 'select')->options($options);
     return $edit->view('planes/crud', compact('edit'));
 }
Ejemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Producto::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'precio' => $this->precio, 'idcategoria' => $this->idcategoria]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'imagen', $this->imagen])->andFilterWhere(['like', 'codigo', $this->codigo]);
     return $dataProvider;
 }
Ejemplo n.º 7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Producto::find();
     $query->joinWith(['idTipoProducto']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'precio' => $this->precio, 'id_tipo_producto' => $this->id_tipo_producto, 'Eliminado' => $this->Eliminado]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion]);
     return $dataProvider;
 }
 public function buscarCitasProximas()
 {
     $date = Carbon::now()->addDays(3);
     $citas_1 = Cita::whereFecha($date->toDateString())->get();
     foreach ($citas_1 as $cita_1) {
         $user = User::find($cita_1->user_id);
         $producto = Producto::find($cita_1->producto_id);
         $this->sendFirstAppointmentReminder($user, $producto, $cita_1);
     }
     $tomorrow = Carbon::now()->tomorrow();
     $citas = Cita::whereFecha($tomorrow->toDateString())->get();
     foreach ($citas as $cita) {
         $user = User::find($cita->user_id);
         $producto = Producto::find($cita->producto_id);
         $this->sendAppointmentReminder($user, $producto, $cita);
     }
     Log::info('Se corrio cron para envio de recordatorios.');
 }
Ejemplo n.º 9
0
 public function ListaProductos()
 {
     $filter = DataFilter::source(Producto::with('proveedor'));
     /*Header*/
     $filter->link('productos/create', 'Crear Nuevo', 'TR');
     /*Header*/
     $filter->attributes(array('class' => 'form-inline'));
     $filter->add('nombre', 'Buscar por Nombre', 'text');
     $filter->add('proveedor.nombre', 'Buscar por Proveedor', 'text');
     $filter->submit('Buscar');
     $filter->reset('Limpiar');
     $grid = DataGrid::source($filter);
     $grid->attributes(array("class" => "table table-striped"));
     $grid->add('nombre', 'Nombre', true);
     $grid->add('precio_unitario', 'Precio Unitario', true);
     $grid->add('proveedor.nombre', 'Proveedor', true);
     $grid->edit(url('/') . '/productos/edit', 'Editar/Borrar', 'modify|delete');
     $grid->paginate(10);
     return view('productos/lista', compact('filter', 'grid'));
 }
 public function asignarPrograma(Request $request)
 {
     $user = User::find($request->input('user_id'));
     if (is_null($user)) {
         return \Redirect::back()->with('error', 'El cliente enviado no existe.');
     }
     $programa = Producto::find($request->input('programa_id'));
     if (is_null($programa)) {
         return \Redirect::back()->with('error', 'El programa enviado no existe.');
     }
     $pivot = User_Producto::where('user_id', '=', $user->id)->where('producto_id', '=', $programa->id)->first();
     if (is_null($pivot)) {
         //aqui lo asignamos
         $configurado = $programa->con_citas == 1 ? 1 : 0;
         $user->Productos()->attach($programa->id, array('precio' => $programa->precio, 'estatus' => 'Exito', 'configurado' => $configurado, 'asignadoporadmin' => 1));
         return \Redirect::back()->with('message', 'El Programa fue Asignado con éxito.');
     } else {
         return \Redirect::back()->with('error', 'El programa ya ha sido asignado anteriormente al cliente.');
     }
 }
Ejemplo n.º 11
0
 /**
  * Finds the Producto model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $idProducto
  * @param integer $embalaje_idEmbalaje
  * @param integer $impuestos_idImpuesto
  * @return Producto the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($idProducto, $embalaje_idEmbalaje, $impuestos_idImpuesto)
 {
     if (($model = Producto::findOne(['idProducto' => $idProducto, 'embalaje_idEmbalaje' => $embalaje_idEmbalaje, 'impuestos_idImpuesto' => $impuestos_idImpuesto])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductoIdProducto()
 {
     return $this->hasOne(Producto::className(), ['idProducto' => 'producto_idProducto']);
 }
 public function publicar()
 {
     $id = $this->request->input("id");
     $producto = Producto::find($id);
     if (is_null($producto)) {
         App::abort(404);
     }
     if ($producto->visible == 1) {
         $producto->visible = 0;
     } elseif ($producto->visible == 0) {
         $producto->visible = 1;
     }
     $producto->save();
 }
 public function obtenerMiCalendario($productoId)
 {
     $producto = Producto::find($productoId);
     if (is_null($producto)) {
         $code = 1;
         $message = "El producto no existe";
         $citasArray = array();
     } else {
         $citas = Auth::user()->Citas()->whereProducto_id($producto->id)->get();
         $code = 0;
         $message = "OK";
         $citasArray = $citas->toArray();
     }
     return response()->json(["success" => true, "code" => $code, "message" => $message, "citas" => $citasArray]);
 }
Ejemplo n.º 15
0
 public static function cart($id)
 {
     return Producto::prodCart($id);
 }
 protected function saveOrder($producto_id)
 {
     $producto = Producto::find($producto_id);
     if (is_null($producto)) {
         App::abort(404);
     }
     $user = User::find(Auth::user()->id);
     $configurado = $producto->con_citas == 1 ? 1 : 0;
     $user->Productos()->attach($producto->id, array('precio' => $producto->precio, 'estatus' => 'Exito', 'configurado' => $configurado));
     $this->sendMailConfirmation($producto, $user);
 }
 public function configurar($id)
 {
     $producto = Producto::find($id);
     $user_producto = $producto->Usuarios()->whereUser_id(Auth::user()->id)->first();
     if (is_null($producto)) {
         App::abort(404);
     }
     if ($user_producto->pivot->configurado != 1) {
         return Redirect::route('mis_productos', array($producto->id));
     } else {
         return view('configurar_producto', compact('producto'));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $tipo_cambio_compra_hoy = DB::table('ts_tipocambiomoneda')->where('fecha', date("Y-m-d"))->pluck('valor_venta');
     $id_igv = DB::table('ts_igv')->where('estado', 'true')->pluck('id');
     $incluido_igv_activo = DB::table('ts_igv')->where('estado', 'true')->pluck('valor_igv');
     // DB::transaction(function(){
     try {
         DB::beginTransaction();
         $cabecera = $request->get('cabecera');
         $cabecera_guia = $request->get('cabecera_guia');
         $filtro_existencia = '';
         // FILTRO --- EXISTE OTRO COMPROBANTE CON LA MISMA SERIE, NUMERO, PROVEEDOR Y FECHA
         if (DB::table('ts_comprobantecompra')->where('serie_comprobante', $cabecera['serie'])->where('numero_comprobante', $cabecera['numero'])->where('id_proveedor', $cabecera['cliente']['id'])->where('fecha', $cabecera['fecha'])->pluck('id') != null) {
             $filtro_existencia = 'EXISTE';
         }
         // FIN FILTRO --- EXISTE OTRO COMPROBANTE CON LA MISMA SERIE, NUMERO, PROVEEDOR Y FECHA
         if ($filtro_existencia == 'EXISTE') {
             // EXISTE COMPROBANTE DE COMPRA, NO GUARDAMOS NADA
             return \Response::json(array('datos' => 'duplicidad'));
         } else {
             //SE EJECUTA NORMALMENTE PORQUE NO EXISTE COMPROBANTE DE COMPRA
             $boolean_incluido_igv;
             if ($cabecera['incluido_igv'] === 'undefined' || $cabecera['incluido_igv'] === null) {
                 $boolean_incluido_igv = false;
             } else {
                 $boolean_incluido_igv = $cabecera['incluido_igv'];
             }
             $nuevaCabecera = new ComprobanteCompra();
             $nuevaCabecera->id_tipoComprobante = 1;
             $nuevaCabecera->serie_comprobante = $cabecera['serie'];
             $nuevaCabecera->numero_comprobante = $cabecera['numero'];
             $nuevaCabecera->fecha = $cabecera['fecha'];
             $nuevaCabecera->id_moneda = $cabecera['moneda']['id'];
             $nuevaCabecera->id_proveedor = $cabecera['cliente']['id'];
             $nuevaCabecera->id_igv = $id_igv;
             // $nuevaCabecera->indicador_asociado = 'true';
             $nuevaCabecera->estado_igv = json_encode($boolean_incluido_igv);
             $nuevaCabecera->total_comprobante = $cabecera['total'];
             $nuevaCabecera->save();
             $id_cabecera = $nuevaCabecera->id;
             // dd($cabecera_guia);
             foreach ($cabecera_guia as $key => $value) {
                 if ($cabecera_guia[$key]['generar_guia'] == true) {
                     // REGISTRAR CABECERA GUIAREMISION
                     $nuevaCabecera_guia = new GuiaRemision();
                     $nuevaCabecera_guia->id_tipoComprobante = 3;
                     $nuevaCabecera_guia->serie_guiaRemision = $cabecera_guia[$key]['serie'];
                     $nuevaCabecera_guia->numero_guiaRemision = $cabecera_guia[$key]['numero'];
                     $nuevaCabecera_guia->fecha_traslado = $cabecera_guia[$key]['fecha'];
                     $nuevaCabecera_guia->punto_partida = $cabecera_guia[$key]['punto_partida'];
                     $nuevaCabecera_guia->id_proveedor = $cabecera['cliente']['id'];
                     $nuevaCabecera_guia->id_motivoTraslado = $cabecera_guia[$key]['motivo']['id'];
                     $nuevaCabecera_guia->id_personalTransporte = $cabecera_guia[$key]['personal_transporte']['id'];
                     $nuevaCabecera_guia->id_unidad_Transporte = $cabecera_guia[$key]['unidad_transporte']['id'];
                     $nuevaCabecera_guia->id_comprobanteCompra = $id_cabecera;
                     $nuevaCabecera_guia->save();
                     $id_cabecera_guia = $nuevaCabecera_guia->id;
                     foreach ($cabecera_guia[$key]['detalle_guia'] as $key_guia => $value_guia) {
                         // REGISTRAR DETALLE DE GUIA
                         $nuevaDetalle_guia = new GuiaRemisionDetalle();
                         $nuevaDetalle_guia->id_guiaRemision = $id_cabecera_guia;
                         $nuevaDetalle_guia->id_producto = $value_guia['id_producto'];
                         if ($value_guia['producto'] != $value_guia['nombre_producto']) {
                             $nuevaDetalle_guia->nombre_producto = $value_guia['nombre_producto'];
                         }
                         $nuevaDetalle_guia->unidades = $value_guia['cantidad'];
                         $nuevaDetalle_guia->peso = $value_guia['peso'];
                         $nuevaDetalle_guia->save();
                     }
                 }
             }
             $detalle = $request->get('detalle');
             foreach ($detalle as $key => $value) {
                 $nuevaDetalle = new ComprobanteDetalleCompra();
                 $nuevaDetalle->id_comprobante = $id_cabecera;
                 $nuevaDetalle->id_producto = $value['id_producto'];
                 if (DB::table('ts_producto')->where('id', $value['id_producto'])->pluck('nombre_producto') != $value['nombre_producto']) {
                     $nuevaDetalle->nombre_producto = $value['nombre_producto'];
                 }
                 $nuevaDetalle->unidades = $value['cantidad'];
                 $nuevaDetalle->precio_unitario = $value['precio'];
                 $nuevaDetalle->save();
                 $producto = Producto::find($value['id_producto']);
                 // APLICANDO IGV INCLUIDO A PRECIO UNITARIO DE PRODUCTO
                 if ($cabecera['incluido_igv'] == true) {
                     $valor_dividir = $incluido_igv_activo + 1;
                     $value['precio'] = $value['precio'] / $valor_dividir;
                 }
                 // TRANSFORMANDO PRECIO UNITARIO - DE DOLARES A SOLES
                 if ($cabecera['moneda']['id'] == 2) {
                     $value['precio'] = $value['precio'] * $tipo_cambio_compra_hoy;
                 }
                 if ($producto->stock == null) {
                     $producto->stock = $value['cantidad'];
                     $producto->precio_unitario = $value['precio'];
                 } else {
                     // dd($value);
                     $producto->precio_unitario = ($producto->precio_unitario * $producto->stock + $value['precio'] * $value['cantidad']) / ($producto->stock + $value['cantidad']);
                     $producto->stock = $producto->stock + $value['cantidad'];
                 }
                 $producto->save();
             }
             // GUARDANDO DETALLE DE NOTA
             $nota = $request->get('nota');
             if ($nota['tipo_nota']['id'] != null) {
                 $total_final = $nota['total_nota'];
                 $nuevaNota = new DetalleNota();
                 $nuevaNota->id_tipoNota = $nota['tipo_nota']['id'];
                 $nuevaNota->id_comprobanteCompra = $id_cabecera;
                 $nuevaNota->id_moneda = $cabecera['moneda']['id'];
                 $nuevaNota->serie_nota = $nota['serie_comprobante'];
                 $nuevaNota->numero_nota = $nota['numero_comprobante'];
                 $nuevaNota->fecha = $cabecera['fecha'];
                 $nuevaNota->descripcion = $nota['descripcion_nota'];
                 $nuevaNota->precio = $nota['precio_nota'];
                 $nuevaNota->total_nota = $nota['total_nota'];
                 $nuevaNota->save();
             }
             // dd($request->get('finanzas'));
             // GUARDANDO DETALLE DE FINANZAS
             $finanzas = $request->get('finanzas');
             if ($finanzas['condicion']['id'] == 2) {
                 //EN LETRAS
                 // dd($finanzas);
                 // INICIALIZANDO LA FECHA DE INICIO LA DEL COMPROBANTE
                 $fecha = date($cabecera['fecha']);
                 foreach ($finanzas['detalles_letra'] as $key => $value) {
                     // CALCULANDO LA FECHA DE VENCIMIENTO PARA CADA LETRA
                     $fecha = date($cabecera['fecha']);
                     $fecha = strtotime('+' . round($value['numero_dias']) . ' day', strtotime($fecha));
                     $fecha = date('Y-m-j', $fecha);
                     $detallePago = new DetallePago();
                     // $detallePago->id_comprobanteCompra = $id_cabecera;
                     $detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                     $detallePago->id_medio_pago = $finanzas['medio']['id'];
                     $detallePago->id_estado_letra = 4;
                     $detallePago->numero_dias = $value['numero_dias'];
                     $detallePago->numero_letra = $value['numero_letra'];
                     $detallePago->monto_letra = $value['monto_letra'];
                     $detallePago->fecha_vencimiento = $fecha;
                     $detallePago->detalle_estado = "";
                     $detallePago->save();
                     $RelacionLetras = new RelacionLetras();
                     $RelacionLetras->id_comprobanteCompra = $id_cabecera;
                     $RelacionLetras->id_detalle_pago = $detallePago->id;
                     $RelacionLetras->total_facturas = $total_final;
                     $RelacionLetras->save();
                 }
             }
             if ($finanzas['condicion']['id'] == 1) {
                 // AL CONTADO
                 $detallePago = new DetallePago();
                 $detallePago->id_comprobanteCompra = $id_cabecera;
                 $detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                 $detallePago->id_medio_pago = $finanzas['medio']['id'];
                 $detallePago->id_estado_letra = 6;
                 $detallePago->numero_dias = null;
                 $detallePago->numero_letra = null;
                 $detallePago->monto_letra = null;
                 $detallePago->fecha_vencimiento = null;
                 $detallePago->detalle_estado = null;
                 $detallePago->save();
             }
             DB::commit();
             return \Response::json(array('datos' => 'correcto'));
         }
     } catch (Exception $e) {
         DB::rollBack();
     }
     // });
 }
 public function guardarCitaUnica(Request $request)
 {
     $producto = Producto::find($request->input('producto_id'));
     if (is_null($producto)) {
         App::abort(404);
     }
     $user = User::find(Auth::user()->id);
     $fechaCarbon = Carbon::createFromFormat("Y-m-d", $request->input('fecha'));
     $dia_cita = $fechaCarbon->dayOfWeek;
     $horaFormatHM = substr($request->input('hora'), 0, 5);
     $horario = Horario::whereNombre($horaFormatHM)->first();
     if (is_null($horario)) {
         return \Redirect::back()->with('error', 'Ocurrió un error con la fecha.');
     }
     $hora_cita = $horario->id;
     $cita = new Cita();
     $cita->user_id = Auth::user()->id;
     $cita->producto_id = $request->input('producto_id');
     $cita->fecha = $request->input('fecha');
     $cita->hora = $request->input('hora');
     $cita->dia_id = $dia_cita;
     $cita->hora_id = $hora_cita;
     $cita->save();
     //ponemos el producto configurado.
     $productoUser = Producto::find($request->input('producto_id'))->Usuarios()->updateExistingPivot(Auth::user()->id, array('configurado' => 2));
     $this->enviarCalendarioPorMail($producto, $user);
     return \Redirect("misproductos/ver/" . $request->input('producto_id'));
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCodProducto()
 {
     return $this->hasOne(Producto::className(), ['codigo_producto' => 'cod_producto']);
 }
Ejemplo n.º 21
0
 /**
  * Devuelve todos los productos ordenados alfabeticamente.
  * @return Array
  */
 public function leerTodos()
 {
     return Producto::find()->orderBy("producto")->all();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $cabecera = $request->get('cabecera');
     $cabecera_guia = $request->get('cabecera_guia');
     $tipo_cambio_venta = DB::table('ts_tipocambiomoneda')->where('fecha', $cabecera['fecha'])->pluck('valor_venta');
     $id_igv = DB::table('ts_igv')->where('estado', 'true')->pluck('id');
     $incluido_igv_activo = DB::table('ts_igv')->where('estado', 'true')->pluck('valor_igv');
     // DB::transaction(function(){
     try {
         DB::beginTransaction();
         $filtro_existencia = '';
         $filtro_existencia_nota = '';
         // FILTRO --- EXISTE OTRO COMPROBANTE CON LA MISMA SERIE, NUMERO, CLIENTE Y FECHA
         if (DB::table('ts_comprobanteventa')->where('serie_comprobante', $cabecera['serie'])->where('numero_comprobante', $cabecera['numero'])->join('ts_detallecliente', 'ts_detallecliente.id', '=', 'ts_comprobanteventa.id_detalle_cliente')->pluck('ts_comprobanteventa.id') != null) {
             $filtro_existencia = 'EXISTE';
         }
         // FIN FILTRO --- EXISTE OTRO COMPROBANTE CON LA MISMA SERIE, NUMERO, CLIENTE Y FECHA
         // FILTRO --- EXISTE OTRA NOTA CON LA MISMA SERIE, NUMERO Y FECHA
         if (DB::table('ts_detalle_nota')->where('serie_nota', $cabecera['serie'])->where('numero_nota', $cabecera['numero'])->where('fecha', $cabecera['fecha'])->pluck('ts_detalle_nota.id') != null) {
             $filtro_existencia_nota = 'EXISTE';
         }
         // FIN FILTRO --- EXISTE OTRA NOTA CON LA MISMA SERIE, NUMERO Y FECHA
         if ($filtro_existencia == 'EXISTE') {
             // EXISTE COMPROBANTE DE VENTA, NO GUARDAMOS NADA
             return \Response::json(array('datos' => 'duplicidad'));
         } else {
             if ($filtro_existencia_nota == 'EXISTE') {
                 // EXISTE NOTA, NO GUARDAMOS NADA
                 return \Response::json(array('datos' => 'duplicidad_nota'));
             } else {
                 //SE EJECUTA NORMALMENTE PORQUE NO EXISTE COMPROBANTE DE VENTA
                 if ($cabecera['boolean_asociar'] == true) {
                     // CUANDO SE ASOCIA CON UNA GUIA
                     // dd($request->get('cabecera'));
                     $nuevaCabecera = new ComprobanteVenta();
                     $nuevaCabecera->id_tipoComprobante = 2;
                     $nuevaCabecera->serie_comprobante = $cabecera['serie'];
                     $nuevaCabecera->numero_comprobante = $cabecera['numero'];
                     $nuevaCabecera->orden_compra = $cabecera['orden_compra'];
                     $nuevaCabecera->fecha = $cabecera['fecha'];
                     $id_tipo_cambio = DB::table('ts_tipocambiomoneda')->where('fecha', $cabecera['fecha'])->pluck('id');
                     $nuevaCabecera->id_tipoCambio = $id_tipo_cambio;
                     $nuevaCabecera->id_moneda = $cabecera['moneda']['id'];
                     $nuevaCabecera->id_detalle_cliente = $cabecera['cliente']['id_direccion_seleccionada'];
                     $nuevaCabecera->id_igv = $id_igv;
                     $nuevaCabecera->total_comprobante = $cabecera['total'];
                     $nuevaCabecera->monto_retencion = $cabecera['retencion'];
                     // $nuevaCabecera->id_guiaRemision = ;
                     $nuevaCabecera->save();
                     $id_cabecera = $nuevaCabecera->id;
                     foreach ($cabecera['id_guiasRemision'] as $key => $value) {
                         $guiaRemision = GuiaRemision::find($value);
                         $guiaRemision->id_comprobanteVenta = $id_cabecera;
                         $guiaRemision->save();
                     }
                     $detalle = $request->get('detalle');
                     foreach ($detalle as $key => $value) {
                         // APLICANDO IGV INCLUIDO A PRECIO UNITARIO DE PRODUCTO
                         // $valor_dividir = $incluido_igv_activo+1;
                         // $value['precio'] = $value['precio']/$valor_dividir;
                         $nuevaDetalle = new ComprobanteDetalleVenta();
                         $nuevaDetalle->id_comprobanteVenta = $id_cabecera;
                         $nuevaDetalle->id_producto = $value['id_producto'];
                         $nuevaDetalle->unidades = $value['unidades'];
                         $nuevaDetalle->precio_unitario = $value['precio'];
                         $nuevaDetalle->save();
                         $producto = Producto::find($value['id_producto']);
                         $producto->stock = $producto->stock - $value['unidades'];
                         $producto->save();
                     }
                 } else {
                     // STORE NORMAL
                     // dd($cabecera);
                     $nuevaCabecera = new ComprobanteVenta();
                     $nuevaCabecera->id_tipoComprobante = 2;
                     $nuevaCabecera->serie_comprobante = $cabecera['serie'];
                     $nuevaCabecera->numero_comprobante = $cabecera['numero'];
                     $nuevaCabecera->orden_compra = $cabecera['orden_compra'];
                     $nuevaCabecera->fecha = $cabecera['fecha'];
                     $id_tipo_cambio = DB::table('ts_tipocambiomoneda')->where('fecha', $cabecera['fecha'])->pluck('id');
                     $nuevaCabecera->id_tipoCambio = $id_tipo_cambio;
                     $nuevaCabecera->id_moneda = $cabecera['moneda']['id'];
                     $nuevaCabecera->id_detalle_cliente = $cabecera['cliente']['id_direccion_seleccionada'];
                     $nuevaCabecera->id_igv = $id_igv;
                     $nuevaCabecera->total_comprobante = $cabecera['total'];
                     $nuevaCabecera->monto_retencion = $cabecera['retencion'];
                     $nuevaCabecera->save();
                     $id_cabecera = $nuevaCabecera->id;
                     foreach ($cabecera_guia as $key => $value) {
                         if ($cabecera_guia[$key]['generar_guia'] == true) {
                             // REGISTRAR CABECERA GUIAREMISION
                             $nuevaCabecera_guia = new GuiaRemision();
                             $nuevaCabecera_guia->id_tipoComprobante = 3;
                             $nuevaCabecera_guia->serie_guiaRemision = $cabecera_guia[$key]['serie'];
                             $nuevaCabecera_guia->numero_guiaRemision = $cabecera_guia[$key]['numero'];
                             $nuevaCabecera_guia->fecha_traslado = $cabecera_guia[$key]['fecha'];
                             $nuevaCabecera_guia->punto_partida = $cabecera_guia[$key]['punto_partida'];
                             $nuevaCabecera_guia->punto_llegada = $cabecera_guia[$key]['punto_llegada'];
                             $nuevaCabecera_guia->id_detalle_cliente = $cabecera['cliente']['id_direccion_seleccionada'];
                             $nuevaCabecera_guia->id_motivoTraslado = $cabecera_guia[$key]['motivo']['id'];
                             $nuevaCabecera_guia->id_personalTransporte = $cabecera_guia[$key]['personal_transporte']['id'];
                             $nuevaCabecera_guia->id_unidad_Transporte = $cabecera_guia[$key]['unidad_transporte']['id'];
                             $nuevaCabecera_guia->id_comprobanteVenta = $id_cabecera;
                             $nuevaCabecera_guia->save();
                             $id_cabecera_guia = $nuevaCabecera_guia->id;
                             foreach ($cabecera_guia[$key]['detalle_guia'] as $key_guia => $value_guia) {
                                 // REGISTRAR DETALLE DE GUIA
                                 $nuevaDetalle_guia = new GuiaRemisionDetalle();
                                 $nuevaDetalle_guia->id_guiaRemision = $id_cabecera_guia;
                                 $nuevaDetalle_guia->id_producto = $value_guia['id_producto'];
                                 if ($value_guia['producto'] != $value_guia['nombre_producto']) {
                                     $nuevaDetalle_guia->nombre_producto = $value_guia['nombre_producto'];
                                 }
                                 $nuevaDetalle_guia->unidades = $value_guia['cantidad'];
                                 $nuevaDetalle_guia->peso = $value_guia['peso'];
                                 $nuevaDetalle_guia->save();
                             }
                         }
                     }
                     $detalle = $request->get('detalle');
                     // dd($detalle);
                     foreach ($detalle as $key => $value) {
                         // APLICANDO IGV INCLUIDO A PRECIO UNITARIO DE PRODUCTO
                         // $valor_dividir = $incluido_igv_activo+1;
                         // $value['precio'] = $value['precio']/$valor_dividir;
                         $nuevaDetalle = new ComprobanteDetalleVenta();
                         $nuevaDetalle->id_comprobanteVenta = $id_cabecera;
                         $nuevaDetalle->id_producto = $value['id_producto'];
                         if (DB::table('ts_producto')->where('id', $value['id_producto'])->pluck('nombre_producto') != $value['nombre_producto']) {
                             $nuevaDetalle->nombre_producto = $value['nombre_producto'];
                         }
                         $nuevaDetalle->unidades = $value['cantidad'];
                         $nuevaDetalle->precio_unitario = $value['precio'];
                         $nuevaDetalle->save();
                         $producto = Producto::find($value['id_producto']);
                         $producto->stock = $producto->stock - $value['cantidad'];
                         $producto->save();
                     }
                 }
                 // total de comprobante, metiendo a una variable
                 $total_final = $cabecera['total'];
                 // GUARDANDO DETALLE DE NOTA
                 $nota = $request->get('nota');
                 if ($nota['tipo_nota']['id'] != null) {
                     $total_final = $nota['total_nota'];
                     $nuevaNota = new DetalleNota();
                     $nuevaNota->id_tipoNota = $nota['tipo_nota']['id'];
                     $nuevaNota->id_comprobanteVenta = $id_cabecera;
                     $nuevaNota->id_moneda = $cabecera['moneda']['id'];
                     $nuevaNota->serie_nota = $nota['serie_comprobante'];
                     $nuevaNota->numero_nota = $nota['numero_comprobante'];
                     $nuevaNota->fecha = $cabecera['fecha'];
                     $nuevaNota->descripcion = $nota['descripcion_nota'];
                     $nuevaNota->precio = $nota['precio_nota'];
                     $nuevaNota->total_nota = $nota['total_nota'];
                     $nuevaNota->save();
                 }
                 // GUARDANDO DETALLE DE FINANZAS
                 $finanzas = $request->get('finanzas');
                 // dd($monto_por_letra);
                 // dd($finanzas);
                 if ($finanzas['condicion']['id'] == 2) {
                     //EN LETRAS
                     $cont_indivisible = 0;
                     $resto_division = 0;
                     // CALCULANDO SI ES DIVISIBLE PARA EL NUMERO DE DIAS
                     if ($total_final % count($finanzas['detalles_letra']) != 0) {
                         $resto_division = round($total_final / count($finanzas['detalles_letra']), 3);
                         // dd($resto_division * (count($finanzas['detalles_letra']) ));
                         $monto_sumar = round($total_final - $resto_division * count($finanzas['detalles_letra']), 3);
                         $cont_indivisible = 1;
                         // dd(round($monto_sumar,3));
                     }
                     // INICIALIZANDO LA FECHA DE INICIO LA DEL COMPROBANTE
                     $fecha = date($cabecera['fecha']);
                     // CALCULANDO MONTO POR LETRA EN PARTES IGUALES
                     $monto_por_letra = round($total_final / count($finanzas['detalles_letra']), 3);
                     foreach ($finanzas['detalles_letra'] as $key => $value) {
                         // ADICIONANDO 1 DIA DEBIDO AL REDONDEO
                         if ($cont_indivisible == 1) {
                             $monto_por_letra = $monto_por_letra + $monto_sumar;
                         }
                         // CALCULANDO LA FECHA DE VENCIMIENTO PARA CADA LETRA
                         $fecha = date($cabecera['fecha']);
                         $fecha = strtotime('+' . round($value['numero_dias']) . ' day', strtotime($fecha));
                         $fecha = date('Y-m-j', $fecha);
                         $detallePago = new DetallePago();
                         // $detallePago->id_comprobanteVenta = $id_cabecera;
                         $detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                         $detallePago->id_medio_pago = $finanzas['medio']['id'];
                         $detallePago->id_estado_letra = 4;
                         $detallePago->numero_dias = $value['numero_dias'];
                         $detallePago->numero_letra = $value['numero_letra'];
                         $detallePago->monto_letra = $value['monto_letra'];
                         // $detallePago->monto_letra = $value['monto_letra'];
                         $detallePago->fecha_vencimiento = $fecha;
                         $detallePago->detalle_estado = "";
                         $detallePago->save();
                         $RelacionLetras = new RelacionLetras();
                         $RelacionLetras->id_comprobanteVenta = $id_cabecera;
                         $RelacionLetras->id_detalle_pago = $detallePago->id;
                         $RelacionLetras->total_facturas = $total_final;
                         $RelacionLetras->save();
                         // RESTANDO 1 PARA LOS SIGUIENTES REGISTROS
                         if ($cont_indivisible == 1) {
                             $monto_por_letra = $monto_por_letra - $monto_sumar;
                             $cont_indivisible++;
                         }
                     }
                 }
                 // dd($finanzas);
                 if ($finanzas['condicion']['id'] == 1) {
                     // AL CONTADO
                     $detallePago = new DetallePago();
                     $detallePago->id_comprobanteVenta = $id_cabecera;
                     $detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                     $detallePago->id_medio_pago = $finanzas['medio']['id'];
                     if ($finanzas['condicion']['id'] != 1) {
                         // DIFERENTE DE PENDIENTE
                         $detallePago->fecha_pago = $finanzas['medio']['fecha_pago'];
                         $detallePago->detalle_medio_pago = $finanzas['medio']['detalle_medio_pago'];
                     }
                     $detallePago->id_estado_letra = 6;
                     $detallePago->numero_dias = null;
                     $detallePago->numero_letra = null;
                     $detallePago->monto_letra = null;
                     $detallePago->fecha_vencimiento = null;
                     $detallePago->detalle_estado = null;
                     $detallePago->save();
                 }
                 // if($finanzas['condicion']['id'] == 3){
                 // 	$detallePago = new DetallePago;
                 // 	$detallePago->id_comprobanteVenta = $id_cabecera;
                 // 	$detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                 // 	$detallePago->id_medio_pago = $finanzas['medio']['id'];
                 // 	$detallePago->id_estado_letra = 6;
                 // 	$detallePago->numero_dias = null;
                 // 	$detallePago->numero_letra = null;
                 // 	$detallePago->monto_letra = null;
                 // 	$detallePago->fecha_vencimiento = null;
                 // 	$detallePago->detalle_estado =  null;
                 // 	$detallePago->save();
                 // }
                 // if($finanzas['condicion']['id'] != null){
                 // 	// TRANSFORMANDO EN ARRAY EL FORMATO DE LETRA
                 // 	$array_letra = explode("-",$finanzas['numero_letra']);
                 // 	// EXTRAYENDO EL TOTAL DE DIAS PARA LAS LETRAS
                 // 	$total_dias = $finanzas['numero_dias'];
                 // 	// DIVIDIENDO EN PARTES IGUALES EL NUMERO DE DIAS
                 // 	$dias_por_letra = floor($total_dias / (count($array_letra)-1) );
                 // 	// DIVIDIENDO EN PARTES IGUALES EL MONTO
                 // 	$monto_por_letra = $total_final / (count($array_letra)-1);
                 // 	$cont_indivisible=0;
                 // 	$resto_division=0;
                 // 	// CALCULANDO SI ES DIVISIBLE PARA EL NUMERO DE DIAS
                 // 	if($total_dias % (count($array_letra)-1) != 0){
                 // 		$resto_division = $total_dias % (count($array_letra)-1);
                 // 		$cont_indivisible=1;
                 // 	}
                 // 	for ($i=1; $i < count($array_letra); $i++) {
                 // 		// ADICIONANDO 1 DIA DEBIDO AL REDONDEO
                 // 		if($cont_indivisible == 1){
                 // 			$dias_por_letra = $dias_por_letra+$resto_division;
                 // 		}
                 // 		$detallePago = new DetallePago;
                 // 		$detallePago->id_comprobanteVenta = $id_cabecera;
                 // 		$detallePago->id_condicion_pago = $finanzas['condicion']['id'];
                 // 		$detallePago->id_medio_pago = $finanzas['medio']['id'];
                 // 		$detallePago->id_estado_letra = $finanzas['estado']['id'];
                 // 		$detallePago->numero_dias = round($dias_por_letra);
                 // 		$detallePago->numero_letra = $array_letra[0].$array_letra[$i];
                 // 		$detallePago->monto_letra = $monto_por_letra;
                 // 		$detallePago->fecha_vencimiento = $fecha;
                 // 		$detallePago->detalle_estado = $finanzas['detalle_estado'];
                 // 		$detallePago->save();
                 // 		// RESTANDO 1 PARA LOS SIGUIENTES REGISTROS
                 // 		if($cont_indivisible == 1){
                 // 			$dias_por_letra = $dias_por_letra-$resto_division;
                 // 			$cont_indivisible++;
                 // 		}
                 // 	}
                 // }
                 // $id_cabecera = $nuevaCabecera->id;
                 DB::commit();
                 return \Response::json(array('datos' => 'correcto'));
             }
         }
     } catch (Exception $e) {
         DB::rollBack();
     }
     // });
 }
Ejemplo n.º 23
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProducto()
 {
     return $this->hasOne(Producto::className(), ['id' => 'id_producto']);
 }
Ejemplo n.º 24
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductos()
 {
     return $this->hasMany(Producto::className(), ['id_tipo_producto' => 'id']);
 }
Ejemplo n.º 25
0
 public function actionItemsPedidos($idPedido)
 {
     $contenido_pedido = Carropedido::findAll(['pedido_idPedido' => $idPedido]);
     $id_productos = array_map(function ($o) {
         return $o->producto_idProducto;
     }, $contenido_pedido);
     $productos = Producto::find()->where(['IN', 'idProducto', $id_productos])->all();
     $items = array_map(function ($u) use($idPedido) {
         $temp = Carropedido::findOne(['pedido_idPedido' => $idPedido, 'producto_idProducto' => $u->idProducto]);
         if (empty($temp)) {
             $cantidad = 0;
         } else {
             $cantidad = $temp->cantidad;
         }
         $row['idProducto'] = $u->idProducto;
         $row['codigo'] = $u->codigo;
         $row['nombre'] = $u->producto;
         $row['precio'] = $u->precio;
         $row['embalaje'] = $u->embalajeIdEmbalaje->nombre;
         $row['cantidad'] = $cantidad;
         return $row;
     }, $productos);
     return Json::encode($items);
 }
Ejemplo n.º 26
0
 /**
  * Finds the Producto model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Producto the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Producto::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function index()
 {
     $productos = Producto::visible()->orderBy('id')->get();
     return view('lista_productos', compact('productos'));
 }
 public function getAll()
 {
     return \Response::json(array('datos' => Producto::with(['UnidadMedida', 'Composicion', 'Hilatura', 'Color', 'Titulo', 'TipoProducto', 'TipoTela'])->orderBy('ts_producto.nombre_producto')->get()));
 }
Ejemplo n.º 29
0
 public function update_stock(Request $request, $id)
 {
     try {
         $producto = Producto::findOrFail($id);
         $input = $request->all();
         $producto->update($input);
         \Session::flash('noticia', 'Stock del producto "' . $producto->nombre . '" actualizado con exito.');
     } catch (ModelNotFoundException $e) {
         \Session::flash('error', 'El producto no existe en la base de datos.');
     }
     return redirect('administracion/productos');
 }
Ejemplo n.º 30
0
 public function getChooseProd()
 {
     $productos = Producto::all();
     return view('sell.choose')->with(compact('productos'));
 }