/** * Show the form for creating a new resource. * * @return Response */ public function create() { $nivel_usuario = \App\UserLevel::all()->lists('UserLevelName', 'UserLevelID'); $almacen = \App\Almacen::all()->lists('descrip_almacen', 'id_almacen'); /*array_unshift($nivel_usuario,'Seleccione un nivel de usuario');*/ return view('usuarios.crear')->with(['almacen' => $almacen, 'userlevel' => $nivel_usuario]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $permisos = \App\Menu::all()->lists('nombre', 'id'); $nivel_usuario = \App\UserLevel::all()->lists('UserLevelName', 'UserLevelID'); /*array_unshift($nivel_usuario,'Seleccione un nivel de usuario');*/ array_unshift($permisos, 'Seleccione una opcion del menu'); return view('permisos.crear')->with(['permisos' => $permisos, 'userlevel' => $nivel_usuario]); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $nivel = \App\UserLevel::find($id); $nivel->UserLevelID = \Request::input('nivel_usuario'); $nivel->UserLevelName = \Request::input('nombre_nivel'); $nivel->save(); return redirect('niveles')->with('message', 'Se ha actualizado el registro'); }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get assets that should decay. $assets = Asset::where('Type', '=', 1)->get(); // Loop through the assets and decay them. foreach ($assets as $asset) { // Check that we haven't already decayed this asset. $decay = AssetDecay::where('AssetId', '=', $asset->Id)->where('Date', '=', date('Y-m-d'))->first(); if (!$decay) { $decayValue = $asset->Value / $asset->Days; $decay = AssetDecay::create(array('AssetId' => $asset->Id, 'Date' => date('Y-m-d'), 'Value' => $decayValue)); // Update asset. $asset->Value -= $decayValue; $asset->Days--; $asset->save(); } $permissions = json_decode(UserLevel::find(1)->Permissions); print_r($permissions); } }
<?php use App\User; use App\Worker; use App\Branch; use App\Stock; use App\Order; use App\Provider; use App\Production; use App\ProductionExpense; use App\UserLevel; $permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions); ?> {{--*/ $cols = 4 /*--}} @if(Worker::find(Auth::user()->TypeId)->branch->BranchType == 1) {{--*/ $cols++ /*--}} @endif @if(isset($code)) {{--*/ $cols++ /*--}} {{--*/ $provider = Provider::find(Stock::where('Code', '=', $code)->first()->ProviderId) /*--}} <tr> <th colspan="{{ $cols }}" class="stock-header text-center">{{ $provider->Name }}</th> </tr> <tr class="providerHeader"> <th>Codigo</th> <th>Descripcion</th> @if(Worker::find(Auth::user()->TypeId)->branch->BranchType == 1) <th>Precio</th> @endif @if($permissions->permissions->stock->view->can == 'true') <th class="stockQuantity">Cantidad en Sistema</th>
<?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">
/** * 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 deletes a reservation. * * @return Response */ public function deleteReservationAuth() { // Validate Input. $validator = Validator::make(Input::all(), array('reservationId' => 'required', 'formData' => '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); } // Now check if information provided for authentication is correct. $authenticatedUser = User::where('Username', '=', Input::get('formData')['rCancellationUsername'])->first(); if (!$authenticatedUser || !Auth::once(array('Username' => Input::get('formData')['rCancellationUsername'], 'password' => Input::get('formData')['rCancellationPassword'] . $authenticatedUser->Salt, 'Type' => 1))) { $response['state'] = 'Error'; $response['error'] = 'Las credenciales utilizadas son incorrectas!'; return response()->json($response); } // Get the permissions of authenticated user. $permissions = json_decode(UserLevel::find($authenticatedUser->UserLevel)->Permissions); if (!$permissions->permissions->sales->create->reservation->cancel) { $response['state'] = 'Error'; $response['error'] = 'Este usuario no tiene permiso para cancelar reservaciones!'; return response()->json($response); } // Get user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; $salePrice = 0; // Get the reservation. $reservation = Reservation::find(Input::get('reservationId')); // Make sure the reservation hasn't been used yet. if ($reservation->State == 'used' || $reservation->State == 'credit') { $response['state'] = 'Error'; $response['error'] = 'Esta reservacion ya ha sido utilizada!'; return response()->json($response); } // Now make sure the reservation hasn't been deleted. if ($reservation->State == 'delete') { $response['state'] = 'Error'; $response['error'] = 'Esta reservacion fue eliminada!'; return response()->json($response); } // Now make sure the reservation hasn't expired. if ($reservation->State == 'late') { $response['state'] = 'Error'; $response['error'] = 'Esta reservacion ya ha expirado!'; return response()->json($response); } // Delete the reservation. // TODO: Not sure, but should we delete the transaction with this? What if the transaction is of a previous cashbox? $reservation->State = 'delete'; $reservation->save(); $response['state'] = 'Success'; $response['message'] = 'Reservacion cancelada exitosamente!'; return response()->json($response); }
/** * Function that adds a loan to defined worker. * * @return Response */ public function loanStaff() { // Validate Input. $validator = Validator::make(Input::all(), array('worker' => 'required', 'formData' => 'required')); if ($validator->fails()) { // No reason why staffId and dayType would not be provided so return nothing. return response()->json(array()); } // 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()); } // Check if user has permission to give loans. $userToVerify = User::where('Username', '=', Input::get('formData')['plsusername'])->first(); if (!$userToVerify) { $response['state'] = 'Error'; $response['error'] = 'Este usuario no existe!'; return response()->json($response); } if (Auth::validate(array('Username' => Input::get('formData')['plsusername'], 'password' => Input::get('formData')['plspassword'] . $userToVerify->Salt, 'Type' => 1))) { // If user was verified make sure user has permission to withdraw money. $permissions = json_decode(UserLevel::find($userToVerify->UserLevel)->Permissions); if ($permissions->permissions->staff->loan->can != "true") { $response['state'] = 'Error'; $response['error'] = 'Este usuario no tiene permitido dar prestamos!'; return response()->json($response); } // Get the worker. $worker = Worker::where('Cedula', '=', Input::get('worker'))->first(); if (!$worker) { $response['state'] = 'Error'; $response['error'] = 'No se encontro el trabajador!'; return response()->json($response); } // Get the current cashbox. $cashbox = Cashbox::where('UserId', '=', Auth::user()->Id)->where('Close', '=', NULL)->first(); if (!$cashbox) { $response['state'] = 'Error'; $response['error'] = 'No hay una caja abierta de la cual se pueda retirar fondos!'; return response()->json($response); } // Now give em the loan. $loan = WorkerLoan::create(array('Date' => date('Y-m-d'), 'Amount' => Input::get('formData')['plsamount'], 'State' => 2, 'Type' => 1, 'Processed' => false, 'WorkerId' => $worker->Id)); // Make the transaction. $transaction = CashboxTransaction::create(array('CashboxId' => $cashbox->Id, 'DateTime' => date('Y-m-d H:i:s'), 'Type' => 3, 'Amount' => Input::get('formData')['plsamount'], 'Reason' => 'Prestamo a ' . $worker->Name)); $response['state'] = 'Success'; $response['message'] = 'El prestamo fue realizado exitosamente!'; return response()->json($response); } else { $response['state'] = 'Error'; $response['error'] = 'Este usuario o contraseña incorrectos!'; return response()->json($response); } }
/** * Function that saves default expenses. * * @return Response */ public function createRole() { // Validate Input. $validator = Validator::make(Input::all(), array('formData' => '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()); } $level = UserLevel::create(array('Name' => Input::get('formData')['ccrName'], 'Permissions' => json_encode(array()))); $response['state'] = 'Success'; $response['level'] = $level; $response['message'] = 'Roll creado exitosamente!'; return response()->json($response); }
/** * Function that updates a contract with specified parameters. * * @return Response */ public function updateContractAuth() { // Validate Input. $validator = Validator::make(Input::all(), array('formData' => 'required', 'contractId' => '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); } // Now check if information provided for authentication is correct. $authenticatedUser = User::where('Username', '=', Input::get('formData')['cusername'])->first(); if (!$authenticatedUser || !Auth::once(array('Username' => Input::get('formData')['cusername'], 'password' => Input::get('formData')['cpassword'] . $authenticatedUser->Salt, 'Type' => 1))) { $response['state'] = 'Error'; $response['error'] = 'Las credenciales utilizadas son incorrectas!'; return response()->json($response); } // Get the permissions of authenticated user. $permissions = json_decode(UserLevel::find($authenticatedUser->UserLevel)->Permissions); if (!$permissions->permissions->sales->create->contract->update) { $response['state'] = 'Error'; $response['error'] = 'Este usuario no tiene permiso para actualizar contratos!'; return response()->json($response); } // Get the contract. $contract = Contract::find(Input::get('contractId')); $contract->State = Input::get('formData')['contractState']; $contract->save(); $response['state'] = 'Success'; $response['message'] = 'Contrato cancelado exitosamente!'; // Return response. return response()->json($response); }
/** * Function that deletes Transaction. * * @return Response */ public function deleteAuthenticated() { // Validate Input. $validator = Validator::make(Input::all(), array('id' => 'required')); $response = array(); if ($validator->fails()) { $response['state'] = 'Error'; $response['error'] = 'La identification de la transaccion es necesaria!'; return response()->json($response); } // 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); } // Verify the user first. $userToVerify = User::where('Username', '=', Input::get('username'))->first(); if (!$userToVerify) { $response['state'] = 'Error'; $response['error'] = 'Este usuario no existe!'; return response()->json($response); } if (Auth::validate(array('Username' => Input::get('username'), 'password' => Input::get('password') . $userToVerify->Salt, 'Type' => 1))) { // If user was verified make sure user has permission to withdraw money. $permissions = json_decode(UserLevel::find($userToVerify->UserLevel)->Permissions); if ($permissions->permissions->cashbox->delete->can != "true") { $response['state'] = 'Error'; $response['d'] = $permissions->permissions->cashbox->delete->can; $response['error'] = 'Este usuario no tiene permitido eliminar transacciones!'; return response()->json($response); } } else { $response['state'] = 'Error'; $response['error'] = 'Usuario o contraseña incorrectos!'; return response()->json($response); } // Get transaction Data. $transaction = CashboxTransaction::find(Input::get('id')); if (!$transaction) { $response['state'] = 'Fail'; $response['error'] = 'Esta transaccion no existe!'; return response()->json($response); } // Get cashbox. $cashbox = Cashbox::find($transaction->CashboxId); // Get worker. $worker = Worker::find(User::find($cashbox->UserId)->TypeId); if ($transaction->Type == 1 || $transaction->Type == 8) { // Get sale. $sale = Sale::where('TransactionId', '=', $transaction->Id)->first(); // Get items in sale. $items = SaleBreakdown::where('SaleId', '=', $sale->Id)->get(); // Loop trough sales breakdown and add products and materials back to stock. foreach ($items as $item) { $product = Stock::where('Code', '=', $item->Code)->where('BranchId', '=', $sale->BranchId)->first(); if (!$product) { $service = Service::where('Code', '=', $item->Code)->where('BranchId', '=', $sale->BranchId)->first(); // Get materials. $materials = json_decode($service->Materials); foreach ($materials as $material => $quantity) { // Update Stock. $product = Stock::where('Code', '=', $material)->where('BranchId', '=', $sale->BranchId)->first(); $product->AverageCost = ($product->AverageCost * $product->Quantity + $product->Cost * $quantity) / ($product->Quantity + $quantity); $product->Quantity += $quantity; $product->save(); } } else { // Update product. $product->AverageCost = ($product->AverageCost * $product->Quantity + $item->Cost * $item->Quantity) / ($product->Quantity + $item->Quantity); $product->Quantity += $item->Quantity; $product->save(); } // Delete item. $item->delete(); } // Now delete sale and trasaction. $sale->delete(); $transaction->delete(); // Now return transaction data. $response['state'] = 'Success'; $response['message'] = 'Transaccion eliminada!'; return response()->json($response); } else { if ($transaction->Type == 7) { // Get the cash receipt. $receipt = CashReceipt::where('TransactionId', '=', $transaction->Id)->first(); // Get the contract. $contract = Contract::find($receipt->TypeId); // Now delete receipt. $receipt->delete(); // Delete transaction. $transaction->delete(); // If contract is not in late state then that means we might need to update the state. if ($contract->State != 'late') { // Get today's date. $today = date_create(date('Y-m-d')); // Get the contract Payments. $contractPayments = CashReceipt::where('Type', '=', 1)->where('TypeId', '=', $contract->Id)->get(); // Get the amount of time that has passed since contract has been created. $time = date_diff($today, date_create($contract->StartDate)); // Check how many intervals have passed. $passedIntervals = 0; if ($contract->QuotaInterval == 'mensuales') { $passedIntervals = floor($time->format('%m')); } else { if ($contract->QuotaInterval == 'quincenales') { /* 1 Month has an average of 4.34524 weeks*/ $passedIntervals = floor($time->format('%a') / 7) / 4.34524; $decimal = $passedIntervals - floor($passedIntervals); if ($decimal >= 0.5) { $passedIntervals = floor($passedIntervals) * 2 + 1; } else { $passedIntervals = floor($passedIntervals) * 2; } } else { if ($contract->QuotaInterval == 'semanales') { $passedIntervals = floor($time->format('%a') / 7); } } } // Now finally get the expected payment. $expectedPayment = $passedIntervals * $contract->Quota; // If it is over the Debt of the contract reset it to contract value. if ($expectedPayment > $contract->Debt) { $expectedPayment = $contract->Debt; } // Calculate real payments. $realPayment = 0; foreach ($contractPayments as $contractPayment) { $realPayment += $contractPayment->Value; } if ($realPayment < $expectedPayment) { $contract->State = 'late'; $contract->save(); } } // Now return transaction data. $response['state'] = 'Success'; $response['message'] = 'Pago a contrato eliminado!'; return response()->json($response); } else { if ($transaction->Type == 9) { // If it's a reservation get the reservation with this transaction Id. $reservation = Reservation::where('TransactionId', '=', $transaction->Id)->first(); $reservation->State = 'deleted'; $reservation->save(); // Now delete transaction. $transaction->delete(); // Now return transaction data. $response['state'] = 'Success'; $response['message'] = 'Deposito y reservacion eliminados!'; return response()->json($response); } else { // Check if this is a payment for a provider bill. if ($transaction->Type == 2) { // Get the provider bill information. $providerBillPayment = ProviderBillPayment::where('TransactionId', '=', $transaction->Id)->first(); // Get the provider bill and provider. $providerBill = ProviderBill::find($providerBillPayment->ProviderBillId); // Check if bill has credit. if ($providerBill->Credit) { // Set as unpaid (No way you can delete a payment and still stay paid -.-). $providerBill->State = 1; $providerBill->save(); // Delete payment. $providerBillPayment->delete(); $response['message'] = 'Transaccion eliminada!'; } else { // Get sale breakdown. $items = ProviderBillBreakdown::where('ProviderBillId', '=', $providerBill->Id)->get(); $response['items'] = $items; // Get the branch of the current worker. $branchId = Worker::find(Auth::user()->TypeId)->BranchId; // Loop through them and update stock. foreach ($items as $item) { // Get product. $product = Stock::where('Code', '=', $item->Code)->where('BranchId', '=', $branchId)->first(); // Update it. $totalAfter = $product->Quantity - $item->Quantity; $product->AverageCost = ($product->AverageCost * $product->Quantity - $item->CurrentCost * $item->Quantity) / $totalAfter; $product->Quantity -= $item->Quantity; $product->save(); //Delete breakdown. $item->delete(); } // Delete transaction, bill, and billpayment. $response['message'] = 'Transaccion eliminada! Al ser el unico pago de una factura de contado se ha eliminado tambien la factura del Proveedor y retirado los productos del Inventario.'; $providerBill->delete(); $providerBillPayment->delete(); $transaction->delete(); } // Return what we have. $response['state'] = 'Success'; } else { // No special action needed just delete it. $transaction->delete(); $response['message'] = 'Transaccion eliminada!'; $response['state'] = 'Success'; } return response()->json($response); } } } }