public function run()
 {
     $count = 6001;
     foreach ($this->shopkeepers as $shopkeeper) {
         try {
             $user = User::create(['name' => $shopkeeper['name'], 'tel' => $shopkeeper['tel'], 'address' => $shopkeeper['address'], 'commune' => $shopkeeper['commune'], 'username' => $shopkeeper['tel'] ? $shopkeeper['tel'] : $count, 'password' => 123, 'type' => 'shopkeeper', 'municipality_id' => 685, 'email' => null]);
             if (!$shopkeeper['tel']) {
                 $count++;
             }
             ShoppingInterest::create(['product_id' => 1, 'user_id' => $user->id, 'amount' => $shopkeeper['papa'], 'unit' => 'kg']);
             ShoppingInterest::create(['product_id' => 2, 'user_id' => $user->id, 'amount' => $shopkeeper['yuca'], 'unit' => 'kg']);
             ShoppingInterest::create(['product_id' => 3, 'user_id' => $user->id, 'amount' => $shopkeeper['arracacha'], 'unit' => 'kg']);
             ShoppingInterest::create(['product_id' => 7, 'user_id' => $user->id, 'amount' => $shopkeeper['platano'], 'unit' => 'kg']);
             ShoppingInterest::create(['product_id' => 11, 'user_id' => $user->id, 'amount' => $shopkeeper['hortalizas'], 'unit' => 'kg']);
             ShoppingInterest::create(['product_id' => 20, 'user_id' => $user->id, 'amount' => $shopkeeper['frutas'], 'unit' => 'kg']);
         } catch (QueryException $e) {
         }
     }
 }
Пример #2
0
 public function getCommunesStatistics(Request $request)
 {
     $commune = $request->get('commune') ? $request->get('commune') : 1;
     $products = ShoppingInterest::select('product_id', 'products.name', \DB::raw('SUM(amount) as total'))->join('users', 'users.id', '=', 'user_id')->join('products', 'products.id', '=', 'product_id')->whereUnit('kg')->whereCommune($commune)->orderBy('product_id', 'asc')->groupBy('product_id')->get();
     $stat = ['content' => [['label' => 'Compra de Producto en KG', 'data' => []]], 'names' => []];
     $count = 0;
     foreach ($products as $product) {
         array_push($stat['content'][0]['data'], [$count, $product->total]);
         array_push($stat['names'], [$count + 0.5, $product->name . ' (' . $product->total . ') ']);
         $count += 1.5;
     }
     return $stat;
 }
Пример #3
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function deleteProduct(Request $request, $id)
 {
     $shoppingInterest = ShoppingInterest::findOrFail($id);
     $shoppingInterest->delete();
     return response()->json(['success' => true, 'message' => 'Compra eliminada correctamente']);
 }