public function postRegister() { $name = request()->input('name'); $email = request()->input('email'); $password = request()->input('password'); $ret = ['status' => 1, 'err_code' => '-1', 'err_msg' => '']; if (!isset($name) || !isset($email) || !isset($password)) { $ret['status'] = 0; $ret['err_code'] = 'params missed'; $ret['err_msg'] = '参数缺失'; } else { $count = Enterprise::where('en_email', '=', $email)->count(); if ($count === 0) { $en = new Enterprise(); $en->en_uid = Enterprise::all()->count() + 10000 + 1; $en->en_name = $name; $en->en_email = $email; $en->en_password = md5($password); $en->save(); } else { $ret['status'] = 0; $ret['err_code'] = 'email exist'; $ret['err_msg'] = '邮箱已经被注册'; } } return response($ret); }
public function create_payment($id) { $enterprise = Enterprise::find($id); $payment = PaymentOrder::where('enterprise_id', $enterprise->id)->orderBy('fecha_pago', 'DESC')->first(); $now = date('Y-m-d'); $payments_methods = $this->payments_methods; $payment_status = $this->payment_status; if ($payment) { //Existe el ultimo pago $last_payment = $payment->fecha_pago; $next_payment = date('Y-m-d', strtotime($last_payment . " + " . $payment->enterprise->plan->periodo->tiempo . " " . $payment->enterprise->plan->periodo->lapso)); if ($now >= $next_payment) { //La fecha actual es igual o mayor a la del proximo pago //hay que generar una orden de pago if ($payment->enterprise->plan->costo > 0) { //Cobro por plan $to_pay = $payment->enterprise->plan->costo; $last_order = '0000-00-00 00:00:00'; $period = sprintf('Pago mes: %s ', date("m/Y", strtotime($next_payment))); } else { //Cobro por porcentaje //Monto entre la fecha de la ultima venta de la ultima orden de pago //y la ultima venta del periodo a cobrar $last_order = SaleOrder::where('enterprise_id', $enterprise->id)->orderBy('created_at', 'DESC')->first(); $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($payment->ultimo_corte, $last_order->created_at))->sum('total'); $to_pay = $amount * ($payment->enterprise->plan->porcentaje / 100); $period = sprintf('%s - %s ', date("d/m/Y", strtotime($last_payment)), date("d/m/Y", strtotime($now))); } } else { //Caso de uso para cuando no hay que generar orden de pago //es decir no se ha cumplido el periodo de pago del plan return redirect()->route('admin.pagos.listado', $id)->with('message', '<div class="alert alert-warning" style="margin-top:15px">No hay pagos pendientes por facturar</div>'); } } else { //Primera vez que la empresa paga if ($enterprise->plan->costo > 0) { //Cobro por plan $to_pay = $enterprise->plan->costo; $last_order = '0000-00-00 00:00:00'; $period = sprintf('Primer pago %s', date("m/Y", strtotime($now))); } else { //Cobro por porcentaje //Monto entre la fecha de la ultima venta de la ultima orden de pago //y la ultima venta del periodo a cobrar $last_order = SaleOrder::where('enterprise_id', $enterprise->id)->orderBy('created_at', 'DESC')->first(); $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array('0000-00-00 00:00:00', $last_order->created_at))->sum('total'); $to_pay = $amount * ($enterprise->plan->porcentaje / 100); $period = sprintf('Desde inicio hasta %s', date("d/m/Y", strtotime($now))); } } $description = sprintf('%s: %s %s', $enterprise->plan->nombre, $enterprise->plan->tiempo_membresia, $this->tiempo[$enterprise->plan->unidad_tiempo]); return view('payments.create', compact('enterprise', 'payments_methods', 'payment_status', 'period', 'to_pay', 'last_order', 'description')); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, Profile::$rules); $this->validate($request, ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6']); $user = User::create(['name' => $request->input('name'), 'email' => $request->input('email'), 'password' => bcrypt($request->input('password'))]); $user->attachRole($request->input('role_id')); $data_profile = array_merge($request->all(), array('user_id' => $user->id)); $profile = Profile::create($data_profile); $enterprise = Enterprise::find($request->input('enterprise_id')); $enterprise->staff()->attach($user->id); Mail::send('emails.new_staff', ['data' => $request->all(), 'empresa' => $enterprise], function ($m) use($enterprise, $user, $profile) { $m->to($user->email, $profile->nombre . ' ' . $profile->apellido)->cc($enterprise->email, $enterprise->razon_social)->subject('Nuevo usuario para la empresa: ' . $enterprise->razon_social); }); return redirect()->route('admin.empresa.staff', $request->input('enterprise_id'))->with('message', '<div class="alert alert-success" style="margin-top:15px">Usuario creado con Éxito. Un email ha sido enviado con sus datos de sesión</div>'); }
public function create_debit($id) { $enterprise = Enterprise::find($id); $debit = DebitOrder::where('enterprise_id', $enterprise->id)->orderBy('fecha_debito', 'DESC')->first(); $now = date('Y-m-d H:m:s'); $debit_status = $this->status; if ($debit) { #existe un ultimo debito $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($debit->created_at, $now))->sum('total'); $period = sprintf('%s - %s ', date("d/m/Y", strtotime($debit->created_at)), date("d/m/Y", strtotime($now))); } else { $last_payment = '0000-00-00 00:00:00'; $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($last_payment, $now))->sum('total'); $period = sprintf('Desde inicio hasta %s', date("d/m/Y", strtotime($now))); } return view('debits.create', compact('enterprise', 'debit_status', 'period', 'amount')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $enterprise = Enterprise::find($id); $users = $enterprise->staff; foreach ($users as $staff) { $staff->delete(); } $enterprise->delete(); //Enterprise::destroy($id); return redirect()->route('admin.empresa.index')->with('message', '<div class="alert alert-success" style="margin-top:15px">Empresa eliminada con Éxito</div>'); }
public function index() { return Enterprise::all(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Enterprise::destroy($id); return redirect()->route('admin.empresa.index')->with('message', '<div class="alert alert-success" style="margin-top:15px">Empresa eliminada con Éxito</div>'); }
public function ventas_a_excel(Request $request) { $empresas = Enterprise::orderBy('razon_social')->get(); $ordenes = new SaleOrder(); $order = $request->input('order') == 'asc' ? 'ASC' : 'DESC'; $filtros = array(); if ($request->input('sort') == 'razon_social') { $ordenes = $ordenes->orderBy('razon_social', $order); } elseif ($request->input('sort') == 'created_at') { $ordenes = $ordenes->orderBy('created_at', $order); } elseif ($request->input('sort') == 'nro_orden') { $ordenes = $ordenes->orderBy('nro_orden', $order); } elseif ($request->input('sort') == 'total') { $ordenes = $ordenes->orderBy('total', $order); } $empresa = null; if ($request->input('empresa_id')) { $ordenes = $ordenes->where('enterprise_id', $request->input('empresa_id')); $empresa = Enterprise::find($request->input('empresa_id')); $filtros['empresa_id'] = $request->input('empresa_id'); } if ($request->input('fecha_inic') != '' && $request->input('fecha_fin') != '') { $inic_arr = explode('/', $request->input('fecha_inic')); $inic = $inic_arr[2] . "-" . $inic_arr[1] . "-" . $inic_arr[0] . " 00:00:00"; $fin_arr = explode('/', $request->input('fecha_fin')); $fin = $fin_arr[2] . "-" . $fin_arr[1] . "-" . $fin_arr[0] . " 11:59:59"; $ordenes = $ordenes->whereBetween('created_at', [$inic, $fin]); $filtros['fecha_inic'] = $request->input('fecha_inic'); $filtros['fecha_fin'] = $request->input('fecha_fin'); } elseif ($request->input('fecha_inic') != '' && $request->input('fecha_fin') == '') { $inic_arr = explode('/', $request->input('fecha_inic')); $inic = $inic_arr[2] . "-" . $inic_arr[1] . "-" . $inic_arr[0] . " 00:00:00"; $ordenes = $ordenes->where('created_at', '>', $inic); $filtros['fecha_fin'] = $request->input('fecha_fin'); } elseif ($request->input('fecha_inic') == '' && $request->input('fecha_fin') != '') { $fin_arr = explode('/', $request->input('fecha_fin')); $fin = $fin_arr[2] . "-" . $fin_arr[1] . "-" . $fin_arr[0] . " 11:59:59"; $ordenes = $ordenes->where('created_at', '<', $fin); $filtros['fecha_inic'] = $request->input('fecha_inic'); } $ordenes = $ordenes->get(); \Excel::create('report', function ($excel) use($ordenes, $empresa, $filtros) { $excel->sheet('hoja_' . date('d-m-Y'), function ($sheet) use($ordenes, $empresa, $filtros) { $inic_table_row = 3; $sheet->mergeCells('A1:B1'); $sheet->row(1, array('Reporte de Ventas')); if ($empresa != null) { $inic_table_row++; $sheet->row(2, array('Empresa', $empresa->razon_social)); } $fechas = array(); if (isset($filtros['fecha_inic'])) { $inic_table_row++; $inic_table_row++; $fechas[] = 'Fecha Inicial'; $fechas[] = $filtros['fecha_inic']; } if (isset($filtros['fecha_inic'])) { $fechas[] = 'Fecha Final'; $fechas[] = $filtros['fecha_fin']; } if (!empty($fechas)) { $sheet->row(3, $fechas); } $sheet->row($inic_table_row, array('Cliente', 'Empresa', 'Fecha', 'Nro. de orden', 'Monto', 'IVA', 'Total')); $sheet->row($inic_table_row, function ($row) { $row->setBackground('#337ab7'); }); $sheet->setHeight($inic_table_row, 20); $sheet->cells('A' . $inic_table_row . ':G' . $inic_table_row, function ($cells) { $cells->setFontSize(12); $cells->setValignment('top'); }); $sheet->setBorder('A' . $inic_table_row . ':G' . $inic_table_row, 'thin'); $acum = 0; foreach ($ordenes as $key => $orden) { $acum += $orden->total; $sheet->row($key + 1 + $inic_table_row, array($orden->razon_social, $orden->enterprise->razon_social, date("d/m/Y h:i:s A", strtotime($orden->created_at)), $orden->nro_orden, number_format($orden->monto, 2, ',', '.'), number_format($orden->iva, 2, ',', '.'), number_format($orden->total, 2, ',', '.'))); $sheet->cells('E' . ($key + 1 + $inic_table_row) . ':G' . ($key + 1 + $inic_table_row), function ($cells) { $cells->setAlignment('right'); }); } $sheet->row($key + 4 + $inic_table_row, array('Ventas Totales', number_format($acum, 2, ',', '.'))); $sheet->cells('B' . ($key + 4 + $inic_table_row), function ($cells) { $cells->setAlignment('right'); }); }); })->download('xls'); }