/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $configuration = Configuration::find($id); $configuration->update($request->all()); $configuration->save(); return redirect('admin/configurations'); }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get all reservations that are still valid. $reservations = Reservation::where('State', '=', 'fresh')->get(); // Get the configuration information. $config = Configuration::find(0); foreach ($reservations as $reservation) { // Check if they should become expired. if (date('Y-m-d', strtotime($reservation->Created) + 86400 * $config->ReservationLife) < date('Y-m-d')) { $reservation->State = 'late'; $reservation->save(); } } }
public function index() { $parsedown = new \ParsedownExtra(); $config = Configuration::find(1); $posts = Post::published()->orderBy('published_at', 'desc')->get(); $feed = new Feed(); $channel = new Channel(); $channel->title($config->blog_title)->description($config->blog_description)->url(url('/'))->appendTo($feed); foreach ($posts as $post) { $item = new Item(); $item->title($post->title)->description($parsedown->parse($post->content))->url(url("/articles/{$post->slug}"))->guid(url("/articles/{$post->slug}"), true)->appendTo($channel); } return response($feed)->header('Content-Type', 'application/rss+xml'); }
<?php use App\Branch; use App\Worker; use App\UserLevel; use App\Configuration; // Get current branch. $branch = Branch::find(Worker::find(Auth::user()->TypeId)->BranchId); $levels = UserLevel::all(); $config = Configuration::find(0); ?> <script src="{{ URL::to('/') }}/js/admin/configuration.js"></script> <div class="hideable hide" id="configuracion"> <div class="subnavbar"> <div class="subnavbar-inner"> <div class="container"> <ul class="mainnav eirene-subnav"> <li class="active"><a href="#configuracion-expenses"><i class="icon-money"></i><span>Gastos Fijos</span></a></li> <li><a href="#configuracion-permissions"><i class="icon-key"></i><span>Permisos para Usuarios</span> </a></li> <li><a href="#configuracion-general"><i class="icon-list-alt"></i><span>Configuracion General</span> </a></li> </ul> </div> <!-- /container --> </div> <!-- /subnavbar-inner --> </div> <div class="container"> <div class="row v-offset-2"> </div> <div class="main sub-hideable" id="configuracion-expenses"> <div class="main-inner">
$others = 0; $withdrawals = 0; $refunds = 0; $sales = 0; $initial = 0; $creditSales = 0; $creditPayments = 0; if ($cashbox) { $transactions = CashboxTransaction::where('CashboxId', '=', $cashbox->Id)->get(); // Count the initial cash. $bills = json_decode($cashbox->Open); foreach ($bills as $bill => $amount) { if ($bill != 'dollar') { $cash += $bill * $amount; } else { $cash += Configuration::find(0)->Dollar * $amount; } } $initial = $cash; // Now count all the other transactions. foreach ($transactions as $transaction) { switch ($transaction->Type) { case 1: $sales += $transaction->Amount; // Check if a credit card was used for sale. if (Sale::where('TransactionId', '=', $transaction->Id)->first()->Card) { $card += $transaction->Amount; } else { $cash += $transaction->Amount; } break;
/** * Function that makes a reservation. * * @return Response */ public function makeReservation() { // Validate Input. $validator = Validator::make(Input::all(), array('items' => 'required', 'institution' => 'required', 'discount' => 'required', 'reservationAmount' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se envio la informacion completa!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(['state' => 'Unauthorized']); } // Get user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; $reservationPrice = 0; $branch = Branch::find($userBranch); // Get the user's cashbox. $cashbox = Cashbox::where('UserId', '=', Auth::user()->Id)->where('Close', '=', NULL)->first(); // Check that we actually have a cashbox open. if (!$cashbox) { $response['state'] = 'Error'; $response['error'] = 'La caja no esta abierta o por lo tanto no se puede realizar la reservacion!'; return response()->json($response); } // Check discount is not greater than what user is allowed. $permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions); if (Input::get('discount') > $permissions->permissions->sales->discount->limit) { // Check if we have an auth code we can use. if (Input::get('authCode') == 0) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } $request = Request::find(Input::get('authCode')); if ($request->Used == 1) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } if ($request->Amount != Input::get('discount')) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } $request->Used = 1; $request->save(); } // Get client. $client = Client::where('Cedula', '=', Input::get('client'))->first(); // Get institution if defined. $institution; if (Input::get('institution') != 0) { $institution = Institution::find(Input::get('institution')); if (!$institution) { $response['state'] = 'Error'; $response['error'] = 'La institucion definida no fue encontrada en el sistema!'; return response()->json($response); } } // Loop through products and services and get prices. $items = json_decode(Input::get('items')); foreach ($items as $code => $info) { // Check if it is a product. $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // Check if it is a service. $service = Service::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$service) { $response['state'] = 'Error'; $response['error'] = 'No se reconocio uno de los productos o servicios!'; return response()->json($response); } // Add price to total of quotation. $reservationPrice += $service->Price * $info->quantity; } else { // Add price to total of quotation. $reservationPrice += $product->Price * $info->quantity; } } $subTotal = $reservationPrice; $discount = $reservationPrice * (Input::get('discount') / 100); // Give discount. $reservationPrice = $reservationPrice * (1 - Input::get('discount') / 100); // Calculate tax if required. $tax = 0; if (json_decode($branch->DefaultExpenses)->regimen == 'cuotageneral') { if (Input::get('institution') != 0) { if (!$institution->Excempt) { $tax = $salePrice * 0.15; } } else { if (!$client || !$client->Excempt) { $tax = $salePrice * 0.15; } } } // Save client information. $clientInfo = array(); if (Input::get('institution') != 0) { // Save institution information. $clientInfo = array('Name' => $institution->Name, 'Address' => $institution->Address, 'Id' => $institution->RUC); } else { // Save institution information. if ($client) { $clientInfo = array('Name' => $client->Name, 'Address' => $client->Address, 'Id' => $client->Cedula); } } // Get reservation info. $config = Configuration::find(0); // Check that the deposit covers the minimum. if (Input::get('reservationAmount') < $config->Dollar * $config->MinimumReservation) { $response['state'] = 'Error'; $response['error'] = 'El deposito minimo para realizar la reservacion es de ' . $config->Dollar * $config->MinimumReservation . ' Cordobas o ' . $config->MinimumReservation . ' Dolares Americanos.'; return response()->json($response); } // Make Reservation. $reservation; if (Input::get('institution') != 0) { // Creditor Type 1 = Client, 2 = Institution. $reservation = Reservation::create(array('WorkerId' => $worker->Id, 'Value' => $reservationPrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => Input::get('institution'), 'CreditorType' => 2, 'TransactionId' => 0, 'State' => 'fresh', 'Life' => $config->ReservationLife, 'Deposit' => Input::get('reservationAmount'))); } else { if (!$client) { $reservation = Reservation::create(array('WorkerId' => $worker->Id, 'Value' => $reservationPrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => 0, 'CreditorType' => 1, 'TransactionId' => 0, 'State' => 'fresh', 'Life' => $config->ReservationLife, 'Deposit' => Input::get('reservationAmount'))); } else { $reservation = Reservation::create(array('WorkerId' => $worker->Id, 'Value' => $reservationPrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => $client->Id, 'CreditorType' => 1, 'TransactionId' => 0, 'State' => 'fresh', 'Life' => $config->ReservationLife, 'Deposit' => Input::get('reservationAmount'))); } } // Now that the reservation has been created, create the transaction for it. $transaction = CashboxTransaction::create(array('CashboxId' => $cashbox->Id, 'DateTime' => date('Y-m-d H:i:s'), 'Type' => 9, 'Amount' => Input::get('reservationAmount'), 'Reason' => 'Deposito de Reservacion: ' . $reservation->Id . '.')); $reservation->TransactionId = $transaction->Id; $reservation->save(); // Loop through items and add them to Reservation Breakdown. foreach ($items as $code => $info) { // Check if product. $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // Get service cost. $service = Service::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); ReservationBreakdown::create(array('ReservationId' => $reservation->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $service->Price)); } else { ReservationBreakdown::create(array('ReservationId' => $reservation->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $product->Price)); } } // Return success message and return quotation information. $response['state'] = 'Success'; $response['reservationInfo'] = array('SubTotal' => $subTotal, 'Discount' => $discount, 'Tax' => $tax, 'Total' => $reservationPrice + $tax, 'ReservationId' => $reservation->Id, 'Date' => date('d/m/Y'), 'Life' => $config->ReservationLife, 'Deposit' => Input::get('reservationAmount')); $response['clientInfo'] = $clientInfo; return response()->json($response); }
/** * Function that gets reservation information. * * @return Response */ public function getReservationData() { // Validate Input. $validator = Validator::make(Input::all(), array('id' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se recibieron los datos necesarios!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { $response['state'] = 'No Autorizado'; $response['error'] = 'Usuario no autorizado!'; return response()->json($response); } // Get user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; // Get the reservation. $reservation = Reservation::find(Input::get('id')); // Get the breakdown of the reservation. $reservationBreakdown = ReservationBreakdown::where('ReservationId', '=', $reservation->Id)->get(); $reservationItems = array(); foreach ($reservationBreakdown as $breakdown) { // Try getting the product. $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // If it's not a product it's a service. $service = Service::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $userBranch)->first(); array_push($reservationItems, array('quantity' => $breakdown->Quantity, 'description' => $service->Description, 'price' => $service->Price)); } else { array_push($reservationItems, array('quantity' => $breakdown->Quantity, 'note' => $product->Description, 'price' => $product->Price)); } } // Get the client's or institution's information. $client; if ($reservation->CreditorId != 0) { if ($reservation->CreditorType != 1) { $temp = Institution::find($reservation->CreditorId); $client = array('Name' => $temp->Name, 'Address' => $temp->Address, 'Id' => $temp->RUC); } else { $temp = Client::find($reservation->CreditorId); $client = array('Name' => $temp->Name, 'Address' => $temp->Address, 'Id' => $temp->Id); } } else { $client = array('Name' => 'No asignado', 'Address' => 'No asignado', 'Id' => 'No asignado'); } // Get configuration info. $config = Configuration::find(0); // Now prepare all the information to be returned to user. $response['state'] = 'Success'; $response['clientInfo'] = $client; $response['reservationInfo'] = array('Date' => date('Y-m-d', strtotime($reservation->Created)), 'Life' => $config->ReservationLife, 'ReservationId' => $reservation->Id, 'SubTotal' => $reservation->Value, 'Discount' => $reservation->Discount, 'Tax' => $reservation->Tax, 'Deposit' => $reservation->Deposit, 'Total' => $reservation->Value + $reservation->Tax - $reservation->Discount); $response['reservationItems'] = $reservationItems; // Return response. return response()->json($response); }
/** * Function that saves general configuration. * * @return Response */ public function saveGeneral() { // Validate Input. $validator = Validator::make(Input::all(), array('dollar' => 'required', 'ruc' => 'required', 'quoteLife' => 'required', 'reservationLife' => 'required', 'minimumReservation' => 'required', 'pos' => 'required', 'pointsEnabled' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'Informacion incompleta!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } $pPercentage = Input::get('pointsPercentage') != null ? Input::get('pointsPercentage') : 0; $config = Configuration::find(0); $config->Dollar = Input::get('dollar'); $config->RUC = Input::get('ruc'); $config->QuoteLife = Input::get('quoteLife'); $config->ReservationLife = Input::get('reservationLife'); $config->MinimumReservation = Input::get('minimumReservation'); $config->CityCoverage = Input::get('cityCoverage'); $config->POS = Input::get('pos'); $config->PointsEnabled = Input::get('pointsEnabled'); $config->PointsPercentage = $pPercentage; $config->save(); $response['state'] = 'Success'; $response['message'] = 'Configuracion general guardada exitosamente!'; return response()->json($response); }
/** * Function that gets contract payments table. * * @return Response */ public function contractInfo() { // Validate Input. $validator = Validator::make(Input::all(), array('id' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se recibieron los datos necesarios!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { $response['state'] = 'No Autorizado'; $response['error'] = 'Usuario no autorizado!'; return response()->json($response); } // Get user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; // Get the contract. $contract = Contract::find(Input::get('id')); // Get the breakdown of the contract. $contractBreakdown = ContractBreakdown::where('ContractId', '=', $contract->Id)->get(); $contractServices = array(); foreach ($contractBreakdown as $breakdown) { // Try getting the product. $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // If it's not a product it's a service. $service = Service::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $userBranch)->first(); array_push($contractServices, array('quantity' => $breakdown->Quantity, 'note' => $service->Note)); } else { array_push($contractServices, array('quantity' => $breakdown->Quantity, 'note' => $product->Description)); } } // Get the branch. $branch = Branch::find($userBranch); // Get the client's information. $client = Client::find($contract->ClientId); // Get the configuration information. $config = Configuration::find(0); // Now prepare all the information to be returned to user. $response['state'] = 'Success'; $response['name'] = $client->Name; $response['ocupation'] = $client->Ocupation; $response['address'] = $client->Address; $response['cedula'] = $client->Cedula; $response['debt'] = $contract->Debt; $response['span'] = floor($contract->Debt / $contract->Quota); $response['quota'] = $contract->Quota; $response['interval'] = $contract->QuotaInterval; $response['paymentDates'] = explode(',', $contract->PaymentDates); $response['startDate'] = $contract->StartDate; $response['createDate'] = date('Y-m-d', strtotime($contract->Created)); $response['interest'] = $contract->Interest; $response['branchAddress'] = $branch->Address; $response['cityCoverage'] = $config->CityCoverage; $response['contractServices'] = $contractServices; // Return response. return response()->json($response); }
/** * Display the specified resource. * * @param string $slug * @return \Illuminate\Http\Response */ public function show($slug) { $configuration = Configuration::find(1); $post = Post::where('slug', $slug)->first(); return view('posts.show', ['post' => $post, 'configuration' => $configuration]); }
public function refreshCashbox() { // Check if a cashbox is open and get all transactions, etc from it if there is. $cashbox = Cashbox::where('UserId', '=', Auth::user()->Id)->where('Close', '=', NULL)->first(); if (!$cashbox) { $response['state'] = 'Error'; $response['error'] = 'No hay una caja abierta y por lo tanto no se pudo actualizar los valores de la caja!'; return response()->json($response); } $transactions = CashboxTransaction::where('CashboxId', '=', $cashbox->Id)->get(); $cash = 0; $card = 0; $providers = 0; $staff = 0; $others = 0; $withdrawals = 0; $refunds = 0; $sales = 0; $initial = 0; $creditSales = 0; $creditPayments = 0; if ($cashbox) { // Count the initial cash. $bills = json_decode($cashbox->Open); foreach ($bills as $bill => $amount) { if ($bill != 'dollar') { $cash += $bill * $amount; } else { $cash += Configuration::find(0)->Dollar * $amount; } } $initial = $cash; // Now count all the other transactions. foreach ($transactions as $transaction) { switch ($transaction->Type) { case 1: $sales += $transaction->Amount; // Check if a credit card was used for sale. if (Sale::where('TransactionId', '=', $transaction->Id)->first()->Card) { $card += $transaction->Amount; } else { $cash += $transaction->Amount; } break; case 2: $providers += $transaction->Amount; break; case 3: $staff += $transaction->Amount; break; case 4: $others += $transaction->Amount; break; case 5: $withdrawals += $transaction->Amount; break; case 6: $refunds += $transaction->Amount; break; // Contract Payments. // Contract Payments. case 7: $sales += $transaction->Amount; $cash += $transaction->Amount; break; // Credit sales. // Credit sales. case 8: $creditSales += $transaction->Amount; $sales += $transaction->Amount; break; // Deposits for reservations. // Deposits for reservations. case 9: $sales += $transaction->Amount; $cash += $transaction->Amount; break; case 10: $creditPayments += $transaction->Amount; $cash += $transaction->Amount; break; } } $total = $initial + $sales + $refunds + $creditPayments - $providers - $staff - $withdrawals - $others - $creditSales; $cash = $cash + $refunds + $creditPayments - $providers - $staff - $withdrawals - $others; // Inform user operation was completed succesfully. $response['state'] = 'Success'; $response['total'] = $total; $response['cash'] = $cash; $response['card'] = $card; $response['providers'] = $providers; $response['staff'] = $staff; $response['others'] = $others; $response['withdrawals'] = $withdrawals; $response['refunds'] = $refunds; $response['sales'] = $sales; $response['creditPayments'] = $creditPayments; $response['creditSales'] = $creditSales; return response()->json($response); } }