示例#1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $providers = Cache::remember('providers', 15, function () {
         return Provider::orderBy('name')->get();
     });
     return response()->json(['data' => $providers], 200);
 }
示例#2
0
 /**
  * Attempt to log in an user using a social authentication provider.
  *
  * @param  string
  * @return Response
  */
 public function loginWithProvider($providerSlug)
 {
     // If the remote provider sends an error cancel the process
     foreach (['error', 'error_message', 'error_code'] as $error) {
         if (Input::has($error)) {
             return $this->goBack(_('Something went wrong') . '. ' . Input::get($error));
         }
     }
     // Get provider
     $provider = Provider::whereSlug($providerSlug)->firstOrFail();
     // Make sure it's usable
     if (!$provider->isUsable()) {
         return $this->goBack(_('Unavailable provider'));
     }
     // Set provider callback url
     Config::set("services.{$provider->slug}.redirect", URL::current());
     // Create an Oauth service for this provider
     $oauthService = Socialite::with($provider->slug);
     // Check if current request is a callback from the provider
     if (Input::has('oauth_token') or Input::has('code')) {
         return $this->loginSocialUser($provider, $oauthService->user());
     }
     // If we have configured custom scopes use them
     if ($scopes = config("services.{$provider->slug}.scopes")) {
         $oauthService->scopes($scopes);
     }
     // Request user to authorize our App
     return $oauthService->redirect();
 }
示例#3
0
 /**
  * Show a page to create a new notice.
  *
  * @return \Response
  *
  *
  */
 public function create()
 {
     // get list of providers
     $providers = Provider::lists('name', 'id');
     // load a view to create a new notice
     return view('notices.create', compact('providers'));
 }
 /**
  * Create a New Notice.
  *
  * @return \Illuminate\View\View
  */
 public function create()
 {
     // get list of providers
     $providers = Provider::lists('name', 'id');
     // Defines Provider List based on the Eloquent Class.
     // load a view to create a new notice
     return view('notices.create', compact('providers'));
 }
示例#5
0
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     // Available providers
     //$view->with('providers', Provider::orderBy('name')->get());
     // All providers
     //$view->with('allProviders', Provider::orderBy('name')->withTrashed()->get());
     // Usable providers
     $view->with('usableProviders', Provider::getUsable());
 }
示例#6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $a = Provider::findOrFail($id);
     if (!$a->validate(Input::all())) {
         return redirect('provider/' . $id . '/edit')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     Flash::success('Provider is updated');
     return Redirect::to('provider');
 }
 public function storeFood_Supplement(Request $request)
 {
     $food_supplement = new Food_Supplement();
     $food_supplement->idUser = Auth::id();
     $food_supplement->idProvider = Provider::where('id', $request->name)->pluck('id');
     $food_supplement->nameProduct = Input::get('nameProduct');
     $food_supplement->weight = Input::get('weight');
     $food_supplement->price_kg = Input::get('price_kg');
     $food_supplement->due_date = Input::get('due_date');
     $food_supplement->save();
 }
示例#8
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $products = Product::all();
     $weeknrs = getWeeknumbers();
     if (Auth::user()->hasRole('member')) {
         $companies = Company::where('comUserId', '=', Auth::user()->id)->get();
     } else {
         $companies = Company::all();
     }
     $providers = Provider::all();
     return view('allocatie.create', compact('products', 'companies', 'weeknrs', 'providers'));
 }
示例#9
0
 /**
  * Attempt to log in an user using a social authentication provider.
  *
  * @param  Illuminate\Http\Request $request
  * @param  string
  * @return Response
  */
 public function loginWithProvider(Request $request, $providerSlug)
 {
     // Use provider name as the throttling cache key
     $request['provider'] = $providerSlug;
     // Check if there are too many login attempts for current provider and IP
     if ($this->hasTooManyLoginAttempts($request)) {
         // Flash error message
         $seconds = (int) \Cache::get($this->getLoginLockExpirationKey($request)) - time();
         $message = sprintf(_('Please try again in %d seconds.'), $seconds);
         return $this->goBack(_('Too many login attempts') . '. ' . $message);
     }
     $this->incrementLoginAttempts($request);
     // If the remote provider sends an error cancel the process
     foreach (['error', 'error_message', 'error_code'] as $error) {
         if ($request->has($error)) {
             return $this->goBack(_('Something went wrong') . '. ' . $request->get($error));
         }
     }
     // Get provider
     $provider = Provider::whereSlug($providerSlug)->firstOrFail();
     // Make sure it's usable
     if (!$provider->isUsable()) {
         return $this->goBack(_('Unavailable provider'));
     }
     // Set provider callback url
     config(["services.{$provider->slug}.redirect" => \URL::current()]);
     // Create an Oauth service for this provider
     $oauthService = \Socialite::with($provider->slug);
     // Check if current request is a callback from the provider
     if ($request->has('oauth_token') or $request->has('code')) {
         $this->clearLoginAttempts($request);
         return $this->loginSocialUser($provider, $oauthService->user());
     }
     // If we have configured custom scopes use them
     if ($scopes = config("services.{$provider->slug}.scopes")) {
         $oauthService->scopes($scopes);
     }
     // Request user to authorize our App
     return $oauthService->redirect();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $provider = Provider::findOrFail($id);
     $provider->name = Input::get('name');
     $provider->address = Input::get('address');
     $provider->email = Input::get('email');
     $provider->phone = Input::get('phone');
     $provider->service = Input::get('service');
     $provider->observation = Input::get('observation');
     $provider->save();
     return redirect()->route('provider.index');
 }
示例#11
0
<?php

use App\User;
use App\Worker;
use App\Branch;
use App\UserLevel;
use App\Notification;
use App\Provider;
use App\ProviderBill;
use App\ProviderBillBreakdown;
use App\Stock;
$currentNotification = Notification::find($notification);
$currentNotification->Seen = true;
$currentNotification->save();
$permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions);
$provider = Provider::find($pId);
$bill = ProviderBill::where('ProviderId', '=', $pId)->where('BillNumber', '=', $bill)->first();
$billBreakdown = ProviderBillBreakdown::where('ProviderBillId', '=', $bill->Id)->get();
$worker = Worker::find(Auth::user()->TypeId);
$total = 0;
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Eirene Systema Administrativo</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta charset="UTF-8">
        <meta name="csrf-token" content="{{{ Session::token() }}}">
        <link href="{{ URL::to('/') }}/css/bootstrap.min.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/bootstrap-responsive.min.css" rel="stylesheet">
示例#12
0
 /**
  * Create a new notice
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function create()
 {
     $providers = Provider::lists('name', 'id');
     return view('notices.create', compact('providers'));
 }
示例#13
0
 public function getProvider()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('provider' => '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 provider.
     $provider = Provider::find(Input::get('provider'));
     // Return provider info.
     $response['state'] = 'Success';
     $response['provider'] = $provider;
     return response()->json($response);
 }
示例#14
0
 /**
  * Function that generates order.
  *
  * @return Response
  */
 public function aiOrder()
 {
     // Get all branches.
     $branches = Branch::all();
     // Get all providers.
     $providers = Provider::where('AIManaged', '=', true)->get();
     // Prepare order array.
     $order = array();
     // Loop through providers.
     foreach ($providers as $provider) {
         $order[$provider->Id] = array();
         // Get all products.
         $products = Stock::where('Provider', '=', $provider)->get();
         foreach ($products as $product) {
             $order[$provider->Id][$product->Code][$provider->BranchId] = array('Code' => $product->Code, 'Description' => $product->Description, 'Exist' => $product->Quantity, 'Cost' => $product->Cost, 'Minimum' => $product->Minimum, 'Order' => 0, 'Average' => 0, 'Sold' => 0);
         }
         // Get all the products sold in selected sample range.
         $today = date('Y-m-d H:i:s');
         switch ($provider->SampleRange) {
             case '1week':
                 $startDate = date('Y-m-d H:i:s', strtotime($today) - 604800);
                 $sales = Sale::where('BranchId', '=', $branchId)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                 foreach ($sales as $sale) {
                     $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Sold'] += $item->Quantity;
                         }
                     }
                 }
                 // Now calculate average of each product.
                 foreach ($order as $index => $product) {
                     $order[$index]['Average'] = $product['Sold'] / 7;
                 }
                 break;
             case '2week':
                 $startDate = date('Y-m-d H:i:s', strtotime($today) - 1209600);
                 $sales = Sale::where('BranchId', '=', $branchId)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                 foreach ($sales as $sale) {
                     $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Sold'] += $item->Quantity;
                         }
                     }
                 }
                 // Now calculate average of each product.
                 foreach ($order as $index => $product) {
                     $order[$index]['Average'] = $product['Sold'] / 14;
                 }
                 break;
             case '1month':
                 $startDate = date('Y-m-d H:i:s', strtotime($today) - 2419200);
                 $sales = Sale::where('BranchId', '=', $branchId)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                 foreach ($sales as $sale) {
                     $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Sold'] += $item->Quantity;
                         }
                     }
                 }
                 // Now calculate average of each product.
                 foreach ($order as $index => $product) {
                     $order[$index]['Average'] = $product['Sold'] / 30;
                 }
                 break;
             case '3month':
                 $startDate = date('Y-m-d H:i:s', strtotime($today) - 7257600);
                 $sales = Sale::where('BranchId', '=', $branchId)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                 foreach ($sales as $sale) {
                     $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Sold'] += $item->Quantity;
                         }
                     }
                 }
                 // Now calculate average of each product.
                 foreach ($order as $index => $product) {
                     $order[$index]['Average'] = $product['Sold'] / 90;
                 }
                 break;
             case '1year':
                 $startDate = date('Y-m-d H:i:s', strtotime($today) - 29030400);
                 $sales = Sale::where('BranchId', '=', $branchId)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                 foreach ($sales as $sale) {
                     $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Sold'] += $item->Quantity;
                         }
                     }
                 }
                 // Now calculate average of each product.
                 foreach ($order as $index => $product) {
                     $order[$index]['Average'] = $product['Sold'] / 365;
                 }
                 break;
         }
     }
     // Now calculate amount to order based on average, existence, minimum and order range.
     switch (Input::get('orderRange')) {
         case '3day':
             foreach ($order as $index => $product) {
                 $estimatedOrder = $product['Average'] * 3;
                 // Order should be at least twice minimum required with existence influded.
                 if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                     $estimatedOrder = $product['Minimum'] * 2;
                 }
                 $order[$index]['Order'] = round($estimatedOrder);
             }
             break;
         case '1week':
             foreach ($order as $index => $product) {
                 $estimatedOrder = $product['Average'] * 7;
                 // Order should be at least twice minimum required with existence influded.
                 if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                     $estimatedOrder = $product['Minimum'] * 2;
                 }
                 $order[$index]['Order'] = round($estimatedOrder);
             }
             break;
         case '2week':
             foreach ($order as $index => $product) {
                 $estimatedOrder = $product['Average'] * 14;
                 // Order should be at least twice minimum required with existence influded.
                 if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                     $estimatedOrder = $product['Minimum'] * 2;
                 }
                 $order[$index]['Order'] = round($estimatedOrder);
             }
             break;
         case '1month':
             foreach ($order as $index => $product) {
                 $estimatedOrder = $product['Average'] * 30;
                 // Order should be at least twice minimum required with existence influded.
                 if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                     $estimatedOrder = $product['Minimum'] * 2;
                 }
                 $order[$index]['Order'] = round($estimatedOrder);
             }
             break;
         case '3month':
             foreach ($order as $index => $product) {
                 $estimatedOrder = $product['Average'] * 90;
                 // Order should be at least twice minimum required with existence influded.
                 if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                     $estimatedOrder = $product['Minimum'] * 2;
                 }
                 $order[$index]['Order'] = round($estimatedOrder);
             }
             break;
     }
     // Check if we have recently made an order for this provider to fix order.
     $aiOrders = AIOrder::where('GenerationDate', '>', date('Y-m-d H:i:s', strtotime($today) - 259200))->where('Received', '=', false)->get();
     foreach ($aiOrders as $o) {
         // Get breakdown and remove quantity from order.
         $breakdown = AIOrderBreakdown::where('AIOrderId', '=', $o->Id)->get();
         foreach ($breakdown as $item) {
             if (array_key_exists($item->Code, $order)) {
                 $order[$item->Code]['Order'] -= $item->Quantity;
             }
         }
     }
     $order = AIOrder::findOrFail(1);
     $breakdown = AIOrderBreakdown::where('AIOrderId', '=', $order->Id)->get();
     // Ship order...
     Mail::send('emails.ai.makeOrder', ['order' => $order, 'breakdown' => $breakdown], function ($message) {
         $message->to('*****@*****.**');
         $message->subject('Orden de Compra');
     });
     $response['state'] = 'Success';
     $response['message'] = 'Servicio eliminado exitosamente!';
     return response()->json($response);
 }
示例#15
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get providers.
     $providers = Provider::all();
     // Get the branches.
     $branches = Branch::all();
     // Loop through them and check which ones are set to auto order.
     foreach ($providers as $provider) {
         if ($provider->AIManaged) {
             foreach ($branches as $branch) {
                 // Now let's get all the products for this provider.
                 $products = Stock::where('BranchId', '=', $branch->Id)->where('ProviderId', '=', $provider->Id)->get();
                 $order = array();
                 foreach ($products as $product) {
                     if ($product->Quantity <= $product->Minimum) {
                         $order[$product->Code] = array('Code' => $product->Code, 'Description' => $product->Description, 'Exist' => $product->Quantity, 'Cost' => $product->Cost, 'Minimum' => $product->Minimum, 'Order' => 0, 'Average' => 0, 'Sold' => 0);
                     }
                 }
                 // Get all the products sold in selected sample range.
                 $today = date('Y-m-d H:i:s');
                 switch ($provider->SampleRange) {
                     case '1week':
                         $startDate = date('Y-m-d H:i:s', strtotime($today) - 604800);
                         $sales = Sale::where('BranchId', '=', $branch->Id)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                         foreach ($sales as $sale) {
                             $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                             foreach ($breakdown as $item) {
                                 if (array_key_exists($item->Code, $order)) {
                                     $order[$item->Code]['Sold'] += $item->Quantity;
                                 }
                             }
                         }
                         // Now calculate average of each product.
                         foreach ($order as $index => $product) {
                             $order[$index]['Average'] = $product['Sold'] / 7;
                         }
                         break;
                     case '2week':
                         $startDate = date('Y-m-d H:i:s', strtotime($today) - 1209600);
                         $sales = Sale::where('BranchId', '=', $branch->Id)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                         foreach ($sales as $sale) {
                             $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                             foreach ($breakdown as $item) {
                                 if (array_key_exists($item->Code, $order)) {
                                     $order[$item->Code]['Sold'] += $item->Quantity;
                                 }
                             }
                         }
                         // Now calculate average of each product.
                         foreach ($order as $index => $product) {
                             $order[$index]['Average'] = $product['Sold'] / 14;
                         }
                         break;
                     case '1month':
                         $startDate = date('Y-m-d H:i:s', strtotime($today) - 2419200);
                         $sales = Sale::where('BranchId', '=', $branch->Id)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                         foreach ($sales as $sale) {
                             $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                             foreach ($breakdown as $item) {
                                 if (array_key_exists($item->Code, $order)) {
                                     $order[$item->Code]['Sold'] += $item->Quantity;
                                 }
                             }
                         }
                         // Now calculate average of each product.
                         foreach ($order as $index => $product) {
                             $order[$index]['Average'] = $product['Sold'] / 30;
                         }
                         break;
                     case '3month':
                         $startDate = date('Y-m-d H:i:s', strtotime($today) - 7257600);
                         $sales = Sale::where('BranchId', '=', $branch->Id)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                         foreach ($sales as $sale) {
                             $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                             foreach ($breakdown as $item) {
                                 if (array_key_exists($item->Code, $order)) {
                                     $order[$item->Code]['Sold'] += $item->Quantity;
                                 }
                             }
                         }
                         // Now calculate average of each product.
                         foreach ($order as $index => $product) {
                             $order[$index]['Average'] = $product['Sold'] / 90;
                         }
                         break;
                     case '1year':
                         $startDate = date('Y-m-d H:i:s', strtotime($today) - 29030400);
                         $sales = Sale::where('BranchId', '=', $branch->Id)->where('Created', '>=', $startDate)->where('Created', '<=', $today)->get();
                         foreach ($sales as $sale) {
                             $breakdown = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
                             foreach ($breakdown as $item) {
                                 if (array_key_exists($item->Code, $order)) {
                                     $order[$item->Code]['Sold'] += $item->Quantity;
                                 }
                             }
                         }
                         // Now calculate average of each product.
                         foreach ($order as $index => $product) {
                             $order[$index]['Average'] = $product['Sold'] / 365;
                         }
                         break;
                 }
                 // Now calculate amount to order based on average, existence, minimum and order range.
                 switch ($provider->OrderRange) {
                     case '3day':
                         foreach ($order as $index => $product) {
                             $estimatedOrder = $product['Average'] * 3;
                             // Order should be at least twice minimum required with existence influded.
                             if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                                 $estimatedOrder = $product['Minimum'] * 2;
                             }
                             $order[$index]['Order'] = ceil($estimatedOrder);
                         }
                         break;
                     case '1week':
                         foreach ($order as $index => $product) {
                             $estimatedOrder = $product['Average'] * 7;
                             // Order should be at least twice minimum required with existence influded.
                             if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                                 $estimatedOrder = $product['Minimum'] * 2;
                             }
                             $order[$index]['Order'] = ceil($estimatedOrder);
                         }
                         break;
                     case '2week':
                         foreach ($order as $index => $product) {
                             $estimatedOrder = $product['Average'] * 14;
                             // Order should be at least twice minimum required with existence influded.
                             if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                                 $estimatedOrder = $product['Minimum'] * 2;
                             }
                             $order[$index]['Order'] = ceil($estimatedOrder);
                         }
                         break;
                     case '1month':
                         foreach ($order as $index => $product) {
                             $estimatedOrder = $product['Average'] * 30;
                             // Order should be at least twice minimum required with existence influded.
                             if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                                 $estimatedOrder = $product['Minimum'] * 2;
                             }
                             $order[$index]['Order'] = ceil($estimatedOrder);
                         }
                         break;
                     case '3month':
                         foreach ($order as $index => $product) {
                             $estimatedOrder = $product['Average'] * 90;
                             // Order should be at least twice minimum required with existence influded.
                             if ($estimatedOrder + $product['Exist'] < $product['Minimum'] * 2) {
                                 $estimatedOrder = $product['Minimum'] * 2;
                             }
                             $order[$index]['Order'] = ceil($estimatedOrder);
                         }
                         break;
                 }
                 // Check if we have recently made an order for this provider to fix order.
                 $aiOrders = AIOrder::where('GenerationDate', '>', date('Y-m-d H:i:s', strtotime($today) - 259200))->where('Received', '=', false)->where('BranchId', '=', $branch->Id)->get();
                 foreach ($aiOrders as $o) {
                     // Get breakdown and remove quantity from order.
                     $breakdown = AIOrderBreakdown::where('AIOrderId', '=', $o->Id)->get();
                     foreach ($breakdown as $item) {
                         if (array_key_exists($item->Code, $order)) {
                             $order[$item->Code]['Order'] -= $item->Quantity;
                         }
                     }
                 }
                 // Check if we have anything to order.
                 $sendOrder = false;
                 foreach ($order as $item) {
                     if ($item['Order'] > 0) {
                         $sendOrder = true;
                     }
                 }
                 if (!$sendOrder) {
                     return 1;
                 }
                 // Generate Order.
                 $aiOrder = AIOrder::create(array('GenerationDate' => date('Y-m-d H:i:s'), 'ConfirmationDate' => '0000-00-00 00:00:00', 'ProviderId' => $provider->Id, 'BranchId' => $branch->Id, 'Received' => false, 'EstimatedDelivery' => date('Y-m-d', strtotime("+3 days"))));
                 foreach ($order as $item) {
                     AIOrderBreakdown::create(array('AIOrderId' => $aiOrder->Id, 'Code' => $item['Code'], 'Quantity' => $item['Order']));
                 }
                 $breakdown = AIOrderBreakdown::where('AIOrderId', '=', $aiOrder->Id)->get();
                 // Now if the provider has delivery send email with order.
                 if ($provider->Delivery) {
                     // Now check what method we will use to make order.
                     if ($provider->Method == 'email') {
                         try {
                             Mail::send('emails.ai.makeOrder', ['order' => $aiOrder, 'breakdown' => $breakdown], function ($message) use($provider, $aiOrder) {
                                 $message->to($provider->Email);
                                 $message->subject('Orden de Compra: ' . $aiOrder->Id);
                             });
                         } catch (\Exception $e) {
                             // In this case we should let an administrator know that the email order failed.
                             $users = User::where('UserLevel', '=', 1)->get();
                             foreach ($users as $admin) {
                                 Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia no fue capaz de organizar un pedido via correo para ' . $provider->Name . '. Por favor revisar orden y organizar su compra.', 'Url' => '/ai/order/' . $aiOrder->Id, 'Seen' => false));
                             }
                         }
                     } else {
                         if ($provider->Method == 'ai') {
                             // TODO: Establish Contact via AI.
                         }
                     }
                 } else {
                     // If the provider doesn't have delivery program a trip to make purchase.
                     $vehicles = Vehicle::where('BranchId', '=', $branch->Id)->where('Repair', '=', false)->get();
                     $vehicle = null;
                     foreach ($vehicles as $v) {
                         if (!$vehicle) {
                             $vehicle = $v;
                         }
                         // In this case the bigger the vehicle the more suitable it should be.
                         // TODO: This could be improved.
                         if ($v->Type > $vehicle->Type) {
                             $vehicle = $v;
                         }
                     }
                     if (!$vehicle) {
                         // In this case we don't have a vehicle and the provider doesn't provide delivery so we must notify an administrator.
                         $users = User::where('UserLevel', '=', 1)->get();
                         foreach ($users as $admin) {
                             Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia no fue capaz de organizar un pedido a para ' . $provider->Name . '. Por favor revisar orden y organizar su compra.', 'Url' => '/ai/order/' . $aiOrder->Id, 'Seen' => false));
                         }
                     } else {
                         // Get location of provider.
                         $location = Location::find($provider->LocationId);
                         $transport = Transport::create(array('Date' => date('Y-m-d', strtotime("+1 day")), 'Time' => '00:00:00', 'VehicleId' => $vehicle->Id, 'DriverId' => 0, 'StartLatitude' => 0, 'StartLongitude' => 0, 'Journey' => '[]', 'EndLatitude' => $location->Latitude, 'EndLongitude' => $location->Longitude, 'EndAddress' => $provider->Address, 'Distance' => 0, 'ReasonId' => $aiOrder->Id, 'Type' => 9, 'State' => 2, 'Order' => 0, 'Depreciation' => 0));
                         // Update Estimated Delivery Date.
                         $aiOrder->EstimatedDelivery = date('Y-m-d', strtotime("+1 day"));
                         $aiOrder->save();
                     }
                 }
             }
         }
     }
 }
示例#16
0
 /**
  * Display a form for saving a resource.
  *
  * @param  string $subtitle Page subtitle.
  * @param  string $action   Form route sufix.
  * @param  string $method   Form method.
  * @return Response
  */
 protected function showForm($subtitle, $action, $method = 'POST')
 {
     view()->share(['languages' => \App\Language::orderBy('name')->withTrashed()->lists('name', 'id'), 'providers' => \App\Provider::orderBy('name')->withTrashed()->lists('name', 'id'), 'role' => \App\Role::orderBy('name')->lists('name', 'id')]);
     return parent::showForm($subtitle, $action, $method);
 }
 /**
  * Remove a provider from the list of user's providers
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function detachProvider(Request $request)
 {
     $provider = Provider::findOrFail($request->get('provider_id'));
     Auth::user()->providers()->detach($provider);
     return back();
 }
示例#18
0
<?php

use App\AIOrder;
use App\AIOrderBreakdown;
use App\Provider;
use App\Branch;
use App\Stock;
// Get the provider and branch.
$provider = Provider::find($order['ProviderId']);
$branch = Branch::find($order['BranchId']);
function getName($code, $branchId)
{
    // Get product.
    $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $branchId)->first();
    return $product->Description;
}
?>
<p>{{ $provider->Name }},</p>
<p>Les enviamos el siguiente correo para realizar una orden a su empresa para los siguientes productos:</p>
<table width="600" align="center" style="border:1px solid black;">
	<thead>
		<tr><th>Descripcion</th><th>Cantidad</th></tr>
	</thead>
	<tbody>
		@foreach($breakdown as $product)
			<tr><td style="text-align:center;">{{ getName($product['Code'], $branch->Id) }}</td><td style="text-align:center;">{{ $product['Quantity'] }}</td></tr>
		@endforeach
	</tbody>
</table>
<p>Por favor enviar los productos a {{ $branch->Name }} ubicados en {{ $branch->Address }}. Recuerde responder a este correo con la palabra: Recibido. Esto es para permitirnos saber de que han recibido la orden exitosamente.</p>
<p>Se despide cordialmente,</p>
 /**
     // Expenses - salidas
 */
 public function create_expense($id)
 {
     $provider = Provider::findOrFail($id);
     return view('providers/expenses/create', compact('provider'));
 }
示例#20
0
 public static function filter($name, $contact, $category)
 {
     return Provider::name($name)->contact($contact)->category($category)->orderBy('created_at', 'DESC')->paginate(10);
 }
示例#21
0
 public function updateProvider()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('formData' => 'required', 'provider' => '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 provider.
     $provider = Provider::find(Input::get('provider'));
     // Make changes.
     $provider->Name = Input::get('formData')['ppcName'];
     $provider->Phone = Input::get('formData')['ppcPhone'];
     $provider->Email = Input::get('formData')['ppcEmail'];
     $provider->RUC = Input::get('formData')['ppcRUC'];
     $provider->Web = Input::get('formData')['ppcWeb'];
     $provider->Retainer = Input::get('formData')['ppcRetainer'] == 'true' ? true : false;
     $provider->CreditLimit = Input::get('formData')['ppcLimit'];
     $provider->CreditDays = Input::get('formData')['ppcDays'];
     // Save changes.
     $provider->save();
     // Return provider info.
     $response['state'] = 'Success';
     $response['message'] = 'Proveedor actualizado exitosamente!';
     $response['provider'] = $provider;
     return response()->json($response);
 }
示例#22
0
function getProvider($id)
{
    return Provider::find($id);
}
示例#23
0
<?php

use App\User;
use App\Worker;
use App\Branch;
use App\UserLevel;
use App\Notification;
use App\Stock;
use App\Provider;
$currentNotification = Notification::find($notification);
$currentNotification->Seen = true;
$currentNotification->save();
$permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions);
$worker = Worker::find(Auth::user()->TypeId);
$product = Stock::where('Code', '=', $code)->where('BranchId', '=', $id)->first();
$provider = Provider::find($product->ProviderId);
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Eirene Systema Administrativo</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta charset="UTF-8">
        <meta name="csrf-token" content="{{{ Session::token() }}}">
        <link href="{{ URL::to('/') }}/css/bootstrap.min.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/bootstrap-responsive.min.css" rel="stylesheet">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600"
                rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/font-awesome.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/style.css" rel="stylesheet">
 public function delete($id)
 {
     Provider::findOrFail($id)->delete();
     return redirect('proveedores');
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Provider::create(['name' => 'Youtube', 'copyright_email' => '*****@*****.**']);
     Provider::create(['name' => 'Vimeo', 'copyright_email' => '*****@*****.**']);
 }
示例#26
0
use App\UserLevel;
use App\Notification;
use App\AIOrder;
use App\AIOrderBreakdown;
use App\Stock;
use App\Service;
use App\Provider;
$currentNotification = Notification::find($notification);
$currentNotification->Seen = true;
$currentNotification->save();
$permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions);
$order = AIOrder::find($id);
$orderBreakdown = AIOrderBreakdown::where('AIOrderId', '=', $order->Id)->get();
$worker = Worker::find(Auth::user()->TypeId);
$branch = Branch::find($worker->BranchId);
$provider = Provider::find($order->ProviderId);
?>
<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Eirene Systema Administrativo</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta charset="UTF-8">
        <meta name="csrf-token" content="{{{ Session::token() }}}">
        <link href="{{ URL::to('/') }}/css/bootstrap.min.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/bootstrap-responsive.min.css" rel="stylesheet">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600"
                rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/font-awesome.css" rel="stylesheet">
        <link href="{{ URL::to('/') }}/css/style.css" rel="stylesheet">
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $injection = Injection::findOrFail($id);
     $providers = Provider::all()->lists('name', 'id');
     return view('injections.edit', compact('injection', 'providers'));
 }
示例#28
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $vaccine = Vaccine::findOrFail($id);
     $providers = Provider::all()->lists('name', 'id');
     return view('vaccines.edit', compact('vaccine', 'providers'));
 }
示例#29
0
 /**
  * Function that creates a new provider.
  *
  * @return Response
  */
 public function createProvider()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('name' => 'required', 'number' => 'required', 'email' => 'required', 'ruc' => 'required', 'web' => 'required', 'retainer' => 'required'));
     $response = array();
     if ($validator->fails()) {
         $response['state'] = 'Error';
         $response['error'] = 'Informacion incompleta!';
         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.
     $worker = Worker::find(Auth::user()->TypeId);
     // Create the provider.
     $provider = Provider::create(array('Name' => Input::get('name'), 'Phone' => Input::get('number'), 'Email' => Input::get('email'), 'RUC' => Input::get('ruc'), 'Web' => Input::get('web'), 'Retainer' => Input::get('retainer')));
     // Prepare to notify admins.
     // Admins are UserLevel 1
     $admins = User::where('UserLevel', '=', 1)->get();
     // Now send notifications to admins.
     foreach ($admins as $admin) {
         $reason = "Se ha creado un nuevo proveedor: " . Input::get('name') . " El proveedor fue creado por {$worker->Name}.";
         Notification::create(array('UserId' => $admin->Id, 'Reason' => $reason, 'Url' => '/bills/provider/' . $provider->Id, 'Seen' => false));
     }
     // Get updated list of providers.
     $providers = Provider::all();
     $response['state'] = 'Success';
     $response['providers'] = $providers;
     // Return result.
     return response()->json($response);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $food__supplements = Food_Supplement::findOrFail($id);
     $providers = Provider::all()->lists('name', 'id');
     return view('food__supplements.edit', compact('food__supplements', 'providers'));
 }