예제 #1
0
파일: User.php 프로젝트: ritey/audious
 /**
  * Get user's playlists.
  * @param  String $service_name Service name i.e. Soundcloud
  * @return Collection of playlists with songs attached.
  */
 public function getPlaylists($service_name)
 {
     // Get Service object to parse id later.
     $service = Service::where('name', $service_name)->first();
     // Get playlists and songs.
     return $this->playlists()->with('songs')->where('service_id', $service->id)->get();
 }
예제 #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $serviceDatas = Service::where('status', '=', 'Pending')->get();
     $serviceWorkings = Service::where('status', '=', 'Working')->get();
     $serviceCompletes = Service::where('status', '=', 'Completed')->get();
     $technicians = User::where('role_id', '=', 3)->get();
     $users = User::all();
     return view('/adminDashboard', compact('serviceDatas', 'technicians', 'users', 'serviceWorkings', 'serviceCompletes'));
 }
function getName($code, $branch)
{
    // Try getting a normal product for this code
    $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $branch)->first();
    if (!$product) {
        // If we failed try getting a service.
        $service = Service::where('Code', '=', $code)->where('BranchId', '=', $branch)->first();
        return $service->Description;
    }
    return $product->Description;
}
예제 #4
0
 /**
  * Function that searches for past trips.
  *
  * @return Response
  */
 public function searchVehicleTrips()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('vehicle' => 'required', 'start' => 'required', 'end' => '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());
     }
     // Get trips.
     $start = date('Y-m-d', strtotime(Input::get('start')));
     $end = date('Y-m-d', strtotime(Input::get('end')));
     $trips = Transport::where('VehicleId', '=', Input::get('vehicle'))->where('Date', '>=', $start)->where('Date', '<=', $end)->where('State', '=', 1)->groupBy('Date')->orderBy('Order')->get();
     $tripData = array();
     foreach ($trips as $trip) {
         $driver = Worker::find($trip->DriverId);
         $reason = '';
         switch ($trip->Type) {
             case 1:
                 // Get sale breakdown.
                 $breakdown = SaleBreakdown::find($trip->ReasonId);
                 // Get product or service.
                 $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first();
                 if ($product) {
                     $reason = 'Venta de ' . $product->Description;
                 } else {
                     $service = Service::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first();
                     $reason = 'Venta de ' . $service->Description;
                 }
                 break;
             case 2:
                 // Get sale.
                 $sale = Sale::find($trip->ReasonId);
                 // Get client or institution.
                 if ($sale->CreditorType == 1) {
                     if ($sale->CreditorId == 0) {
                         $reason = 'Venta a cliente no definido';
                     } else {
                         $client = Client::find($sale->CreditorId);
                         $reason = 'Venta a ' . $client->Name;
                     }
                 } else {
                     $institution = Institution::find($sale->CreditorId);
                     $reason = 'Venta a ' . $institution->Name;
                 }
                 break;
             case 3:
                 // Get order breakdown.
                 $breakdown = OrderBreakdown::find('OrderId', '=', $trip->ReasonId);
                 // Get product or service.
                 $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first();
                 $reason = 'Produccion de ' . $product->Description;
                 break;
             case 4:
                 // Get order.
                 $order = Order::find($trip->ReasonId);
                 // Get client or institution.
                 $client = Client::find($order->ClientId);
                 if ($client->InstitutionId == 0) {
                     $reason = 'Orden de Produccion de ' . $client->Name;
                 } else {
                     $institution = Institution::find($client->InstitutionId);
                     $reason = 'Orden de Produccion de ' . $institution->Name;
                 }
                 break;
             case 5:
                 // Get storage request.
                 $request = StorageRequest::find($trip->ReasonId);
                 $reason = $request->Reason;
                 break;
             case 6:
                 // Get visit.
                 $visit = Visit::find($trip->ReasonId);
                 $reason = 'Visita ' . $visit->Result;
                 break;
             case 7:
                 // Get credit bill.
                 $creditBill = Sale::find($trip->ReasonId);
                 $reason = 'Cobro de Facturo: ' . $creditBill->Id;
                 break;
             case 8:
                 // Contract Payment.
                 $contract = Contract::find($trip->ReasonId);
                 $reason = 'Cobro de Contrato: ' . $contract->Code;
                 break;
             case 9:
                 // Provider purchase.
                 $aiOrder = AIOrder::find($trip->ReasonId);
                 $reason = 'Compra automatica ' . $aiOrder->Id;
                 break;
             case 10:
                 $reason = 'Generado por usuario.';
                 break;
         }
         array_push($tripData, array('Id' => $trip->Id, 'Date' => $trip->Date, 'Driver' => $driver->Name, 'Reason' => $reason, 'Distance' => $trip->Distance, 'Journey' => json_decode($trip->Journey, true), 'StartLat' => $trip->StartLatitude, 'StartLon' => $trip->StartLongitude, 'EndLat' => $trip->EndLatitude, 'EndLon' => $trip->EndLongitude));
     }
     $response['state'] = 'Success';
     $response['trips'] = $tripData;
     return response()->json($response);
 }
예제 #5
0
 public function actions($action, $param = null, $param2 = null, $param3 = null)
 {
     if ($action == "getservices") {
         return Service::transformMany(Service::where('slug', 'slack')->orWhere('slug', 'ga')->where('user_id', Auth::user()->id)->get());
     }
     if ($action == "getaccounts") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $accounts = $analytics->management_accounts->listManagementAccounts();
         return $accounts->getItems();
     }
     if ($action == "getproperties") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $properties = $analytics->management_webproperties->listManagementWebproperties($param2);
         return $properties->getItems();
     }
     if ($action == "getprofiles") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $profiles = $analytics->management_profiles->listManagementProfiles($param2, $param3);
         return $profiles->getItems();
     }
     if ($action == "testslack") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Maknz\Slack\Client($service['var2'], ['username' => 'Cyril', 'channel' => '#' . $param2, 'link_names' => true]);
         $client->send('Hey, this is a test message from SlackReport !');
         return 'success';
     }
 }
예제 #6
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $services = Service::where('user_id', '=', Auth::user()->id)->get();
     return view('home', compact('services'));
 }
예제 #7
0
 /**
  * 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);
             }
         }
     }
 }
예제 #8
0
    foreach (CashboxTransaction::where('CashboxId', '=', $cashbox->Id)->where('Type', '=', 1)->get() as $transaction) {
        foreach (Sale::where('TransactionId', '=', $transaction->Id)->get() as $sale) {
            // Go through sale breackdown.
            foreach (SaleBreakdown::where('SaleId', '=', $sale->Id)->get() as $salebreakdown) {
                // Extract Product or Service.
                // TODO: Get only stock from user's branch.
                $product = Stock::where('Code', '=', $salebreakdown->Code)->first();
                if ($product) {
                    // Check if we have already sold this product.
                    if (array_key_exists($product->Code, $sold)) {
                        $sold[$salebreakdown->Code]['Quantity'] += $salebreakdown->Quantity;
                    } else {
                        $sold[$salebreakdown->Code] = array('Description' => $product->Description, 'Quantity' => $salebreakdown->Quantity);
                    }
                } else {
                    $service = Service::where('Code', '=', $salebreakdown->Code)->first();
                    if ($service) {
                        // Check if we have already sold this service.
                        if (array_key_exists($service->Code, $sold)) {
                            $sold[$salebreakdown->Code]['Quantity'] += $salebreakdown->Quantity;
                        } else {
                            $sold[$salebreakdown->Code] = array('Description' => $service->Description, 'Quantity' => $salebreakdown->Quantity);
                        }
                    }
                }
            }
        }
    }
}
$total = $initial + $sales + $refunds + $creditPayments - $providers - $staff - $withdrawals - $others - $creditSales;
$cash = $cash + $refunds + $creditPayments - $providers - $staff - $withdrawals - $others;
 /**
  * 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);
 }
예제 #10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $service = new Service();
     $service->where('id', $id)->update(['is_active' => 0]);
     //return Redirect::route('services.index')->with('flash_notice', 'You are successfully delete!');
 }
예제 #11
0
 /**
  * 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);
 }
예제 #12
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $fecha = date('Y-m-d h:m:s');
     $serviceToDelete = Service::where('id', '=', $id)->update(['deleted_at' => $fecha]);
     $serviceToDelete = Service::find($id);
     Flash::info("El servicio " . $serviceToDelete->nombre . " ha sido eliminado de manera correcta.!");
     return redirect()->route('admin.services.index');
 }
예제 #13
0
 public function test($id)
 {
     $generator = Service::where('id', (int) $id)->where('user_id', Auth::user()->id)->first();
     $client = new \Google_Client();
     $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
     $client->refreshToken($generator['var2']);
     $analytics = new \Google_Service_Analytics($client);
     $accounts = $analytics->management_accounts->listManagementAccounts();
     return [$generator, $accounts->getItems()];
 }
예제 #14
0
 public function getBarbershop()
 {
     $services = Service::where('section', '=', 'barbershop')->paginate(10);
     return view('services.index', ['services' => $services, 'label' => 'Barber&iacute;a']);
 }
예제 #15
0
 public function getMaterials()
 {
     $service = Service::where('slug', 'stroymaterialy')->first();
     $sections = Section::where('service_id', 3)->where('status', 1)->orderBy('sort_id')->get();
     return view('board.section', compact('service', 'sections'));
 }
예제 #16
0
 public function step2Editor(Product $productsModel, Extra $extraModel)
 {
     $tpl = 0;
     $circulation = CartsCirculation::where('active', '=', 1)->where('alias', '=', 'vizitki')->get();
     $kurs = Config::where('title', '=', 'kurs')->firstOrFail();
     $products = $productsModel->getProd();
     $extra = $extraModel->getExtra();
     $service = Service::where('alias', '=', 'vizitki')->firstOrFail();
     return view('order.template_editor_step2')->with('circulation', $circulation)->with('kurs', $kurs)->with('products', $products)->with('extra', $extra)->with('service', $service)->with('tpl', $tpl);
 }
예제 #17
0
 /**
  * Function that scans a sale and adds a bonus to selected worker if necessary.
  *
  * @return Response
  */
 public function scanSale()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('staffId' => 'required', 'saleId' => 'required'));
     if ($validator->fails()) {
         $response['state'] = 'Error';
         $response['error'] = 'Debe cargar al trabajador!';
         return response()->json($response);
     }
     // 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());
     }
     // Get the worker of given Id.
     $response = array();
     $worker = Worker::where('Cedula', '=', Input::get('staffId'))->first();
     if ($worker) {
         // Check if this worker should get a bonus from this.
         if ($worker->BonusSource != 'productionexclusive' && $worker->BonusSource != 'productionsinglecustom') {
             $response['state'] = 'Error';
             $response['error'] = 'Este trabajador no puede ser asignado bonos por facturas.';
             return response()->json($response);
         }
         // Get today's day.
         $todaySalary = WorkerSalary::where('WorkerId', '=', $worker->Id)->where('Date', '=', date('Y-m-d'))->first();
         if (!$todaySalary) {
             $response['state'] = 'Error';
             $response['error'] = 'El trabajador no ha sido agregado en la planilla del dia de hoy!';
             return response()->json($response);
         }
         // Get the sale.
         $sale = Sale::find(Input::get('saleId'));
         if (!$sale) {
             $response['state'] = 'Error';
             $response['error'] = 'Venta Inexistente!';
             return response()->json($response);
         }
         // Get the breakdown.
         $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
         foreach ($breakdown as $b) {
             // Check that this sale breakdown has not been used already.
             $extraData = json_decode($b->ExtraData, true);
             if (is_array($extraData) && array_key_exists('workerId', $extraData)) {
                 // Get the worker.
                 $worker = Worker::find($extraData['workerId']);
                 $response['state'] = 'Error';
                 $response['error'] = 'Esta factura ha sido asignada a ' . $worker->Name . '!';
                 return response()->json($response);
             }
             $product = Stock::where('Code', '=', $b->Code)->where('BranchId', '=', $sale->BranchId)->first();
             if ($product) {
                 $todaySalary->Bonus += $product->Bonus;
                 $todaySalary->save();
             } else {
                 $service = Service::where('Code', '=', $b->Code)->where('BranchId', '=', $sale->BranchId)->first();
                 $todaySalary->Bonus += $service->Bonus;
                 $todaySalary->save();
             }
             // Add extra data to breakdown.
             $extraData['workerId'] = $worker->Id;
             $b->ExtraData = json_encode($extraData);
             $b->save();
         }
         // Return response.
         $response['state'] = 'Success';
         $response['message'] = 'Factura agregada exitosamente!';
         return response()->json($response);
     } else {
         $response['state'] = 'Error';
         $response['error'] = 'Trabajador Inexistente!';
         return response()->json($response);
     }
 }
예제 #18
0
<?php

use App\Service;
use App\Branch;
use App\User;
use App\Worker;
use App\Stock;
// Get all the services.
$services = array();
// Get the worker's branch Id.
$branchId = Worker::find(Auth::user()->TypeId)->BranchId;
if ($code != '') {
    $services = Service::where('Code', '=', $code)->where('BranchId', '=', $branchId)->get();
} else {
    $services = Service::where('BranchId', '=', $branchId)->get();
}
function getCost($service)
{
    $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
    $materials = json_decode($service->Materials);
    $total = 0;
    foreach ($materials as $material => $quantity) {
        $product = Stock::where('Code', '=', $material)->where('BranchId', '=', $branchId)->first();
        $total += $product->AverageCost * $quantity;
    }
    return $total;
}
?>
@foreach($services as $service)
	<tr id='service-{{ $service->Id }}'><td>{{ $service->Code }}</td><td>{{ $service->Description }}</td><td>{{ getCost($service) }}</td><td>{{ $service->Price }}</td><td>{{ $service->Bonus }}</td><td>{{ $service->Execute }}</td></tr>
@endforeach
예제 #19
0
 public function getService()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('service' => 'required', 'usingCode' => '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(['state' => 'Unauthorized']);
     }
     // Get the service.
     $service;
     $response;
     if (Input::get('usingCode') == 'true') {
         $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
         $service = Service::where('Code', '=', Input::get('service'))->where('BranchId', '=', $branchId)->first();
     } else {
         $service = Service::find(Input::get('service'));
     }
     if (!$service) {
         $response['state'] = 'Error';
         $response['error'] = 'No existe un servicio con este codigo!';
         return response()->json($response);
     }
     // Return provider info.
     $response['state'] = 'Success';
     $response['service'] = $service;
     return response()->json($response);
 }
예제 #20
0
 public function getProjects()
 {
     $service = Service::where('slug', 'proekty')->first();
     $section = Section::where('service_id', '2')->where('status', 1)->orderBy('sort_id')->get();
     return view('tender.section', compact('service', 'section'));
 }
예제 #21
0
 private function returnItems($items, $lastitem)
 {
     // Get user branch.
     $userBranch = Worker::find(Auth::user()->TypeId)->BranchId;
     // Loop through all items.
     foreach ($items as $code => $info) {
         if ($code == $lastitem) {
             return;
         }
         // 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);
             }
             // Return materials.
             $materials = json_decode($service->Materials);
             foreach ($materials as $materialCode => $quantity) {
                 $stock = Stock::where('Code', '=', $materialCode)->where('BranchId', '=', $userBranch)->first();
                 $stock->Quantity += $quantity * $info->quantity;
                 $stock->save();
             }
             // TODO: Check if any special functions need to be executed.
         } else {
             // Return products.
             $product->Quantity += $info->quantity;
             $product->save();
         }
     }
 }
예제 #22
0
                                        <!-- /widget-header -->
                                        <div class="widget-content table-responsive table-compras">
                                            <table class="table table-striped table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th>Producto</th>
                                                        <th>Cantidad a Ordenar</th>
                                                        <th>Cantidad en Existencia</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    @foreach($orderBreakdown as $breakdown)
                                                        <?php 
$product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $branch->Id)->first();
if (!$product) {
    $product = Service::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $branch->Id)->first();
}
?>
                                                        <tr><td>{{ $product->Description }}</td><td>{{ $breakdown->Quantity }}</td><td>{{ $product->Quantity }}</td></tr>
                                                    @endforeach
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="span6">
                            <div class="row-fluid form-horizontal">
                                <div class="control-group span8">
                                    <label class="control-label">Proveedor:</label>
예제 #23
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $services = Service::where('id', '=', 1)->first()->getDescendantsAndSelf(['id', 'parent_id', 'naziv'])->toHierarchy();
     return view('frontend.services.index', compact('services'));
 }
예제 #24
0
파일: Service.php 프로젝트: ritey/audious
 /**
  * Return service id.
  */
 public static function id($service)
 {
     return Service::where('name', $service)->first();
 }