/**
  * Get all of the products of a given Breeder
  *
  * @param  Breeder      $breeder
  * @return Collection
  */
 public function forBreeder(Breeder $breeder)
 {
     $products = $breeder->products()->where('status', 'requested')->get();
     $reservations = $breeder->reservations()->get();
     $items = [];
     // Include all "requested" products
     foreach ($products as $product) {
         if ($product->quantity == 0) {
             continue;
         }
         $itemDetail = [];
         $itemDetail['uuid'] = (string) Uuid::uuid4();
         $itemDetail['id'] = $product->id;
         $itemDetail['reservation_id'] = 0;
         $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name;
         $itemDetail['breeder_id'] = $product->breeder_id;
         $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province;
         $itemDetail['name'] = $product->name;
         $itemDetail['type'] = $product->type;
         $itemDetail['age'] = $this->computeAge($product->birthdate);
         $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name);
         $itemDetail['quantity'] = $product->quantity;
         $itemDetail['adg'] = $product->adg;
         $itemDetail['fcr'] = $product->fcr;
         $itemDetail['bft'] = $product->backfat_thickness;
         $itemDetail['status'] = $product->status;
         $itemDetail['customer_id'] = 0;
         $itemDetail['customer_name'] = '';
         $itemDetail['date_needed'] = '';
         $itemDetail['special_request'] = '';
         array_push($items, (object) $itemDetail);
     }
     // Include "reserved" / "paid" / "on_delivery" / "sold" products
     foreach ($reservations as $reservation) {
         $product = Product::find($reservation->product_id);
         $itemDetail = [];
         $itemDetail['uuid'] = (string) Uuid::uuid4();
         $itemDetail['id'] = $product->id;
         $itemDetail['reservation_id'] = $reservation->id;
         $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name;
         $itemDetail['breeder_id'] = $product->breeder_id;
         $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province;
         $itemDetail['name'] = $product->name;
         $itemDetail['type'] = $product->type;
         $itemDetail['age'] = $this->computeAge($product->birthdate);
         $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name);
         $itemDetail['quantity'] = $reservation->quantity;
         $itemDetail['adg'] = $product->adg;
         $itemDetail['fcr'] = $product->fcr;
         $itemDetail['bft'] = $product->backfat_thickness;
         $itemDetail['status'] = $reservation->order_status;
         $itemDetail['customer_id'] = $reservation->customer_id;
         $itemDetail['customer_name'] = Customer::find($reservation->customer_id)->users()->first()->name;
         $itemDetail['date_needed'] = $this->transformDateSyntax($reservation->date_needed);
         $itemDetail['special_request'] = $reservation->special_request;
         array_push($items, (object) $itemDetail);
     }
     // dd($items);
     return collect($items)->toJson();
 }
예제 #2
0
 public static function getBreedItems()
 {
     $breedItems = [];
     /**
      * @var Breed $breed
      */
     foreach (Breed::find()->pets()->all() as $breed) {
         $breedItems[] = ['label' => $breed->name, 'url' => \Yii::$app->urlManager->createUrl(['/site/breed', 'id' => $breed->id])];
     }
     return $breedItems;
 }
예제 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Breed::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'common_status_id' => $this->common_status_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
 /**
  * Get items in the Swine Cart
  * [!]AJAX
  *
  * @param  Request $request
  * @return JSON/Array
  */
 public function getSwineCartItems(Request $request)
 {
     if ($request->ajax()) {
         $customer = $this->user->userable;
         $swineCartItems = $customer->swineCartItems()->where('if_requested', 0)->get();
         $items = [];
         foreach ($swineCartItems as $item) {
             $itemDetail = [];
             $product = Product::find($item->product_id);
             $itemDetail['item_id'] = $item->id;
             $itemDetail['product_id'] = $item->product_id;
             $itemDetail['product_name'] = $product->name;
             $itemDetail['product_type'] = $product->type;
             $itemDetail['product_breed'] = Breed::find($product->breed_id)->name;
             $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name;
             $itemDetail['breeder'] = Breeder::find($product->breeder_id)->users()->first()->name;
             $itemDetail['token'] = csrf_token();
             array_push($items, $itemDetail);
         }
         $itemsCollection = collect($items);
         return $itemsCollection->toJson();
     } else {
         $customer = $this->user->userable;
         $swineCartItems = $customer->swineCartItems()->where('if_rated', 0)->get();
         $products = [];
         $log = $customer->transactionLogs()->get();
         $history = [];
         foreach ($swineCartItems as $item) {
             $itemDetail = [];
             $product = Product::find($item->product_id);
             $reviews = Breeder::find($product->breeder_id)->reviews()->get();
             $itemDetail['request_status'] = $item->if_requested;
             $itemDetail['request_quantity'] = $item->quantity;
             $itemDetail['status'] = $item->reservation_id ? ProductReservation::find($item->reservation_id)->order_status : $product->status;
             $itemDetail['staus'] = $product->status;
             $itemDetail['item_id'] = $item->id;
             $itemDetail['customer_id'] = $customer->id;
             $itemDetail['breeder_id'] = $product->breeder_id;
             $itemDetail['breeder'] = Breeder::find($product->breeder_id)->users()->first()->name;
             $itemDetail['product_id'] = $item->product_id;
             $itemDetail['product_province'] = FarmAddress::find($product->farm_from_id)->province;
             $itemDetail['product_name'] = $product->name;
             $itemDetail['product_type'] = $product->type;
             $itemDetail['product_quantity'] = $product->quantity;
             $itemDetail['product_breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name);
             $itemDetail['product_birthdate'] = $this->transformDateSyntax($product->birthdate);
             $itemDetail['product_age'] = $this->computeAge($product->birthdate);
             $itemDetail['product_adg'] = $product->adg;
             $itemDetail['product_fcr'] = $product->fcr;
             $itemDetail['product_backfat_thickness'] = $product->backfat_thickness;
             $itemDetail['other_details'] = $product->other_details;
             $itemDetail['avg_delivery'] = $reviews->avg('rating_delivery');
             $itemDetail['avg_transaction'] = $reviews->avg('rating_transaction');
             $itemDetail['avg_productQuality'] = $reviews->avg('rating_productQuality');
             if ($item->date_needed == '0000-00-00') {
                 $itemDetail['date_needed'] = '';
             } else {
                 $itemDetail['date_needed'] = $this->transformDateSyntax($item->date_needed);
             }
             $itemDetail['special_request'] = $item->special_request;
             $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name;
             if ($item->transactionLog) {
                 $itemDetail['status_transactions'] = json_decode($item->transactionLog->status_transactions, true);
             } else {
                 $itemDetail['status_transactions'] = ["requested" => '', "reserved" => '', "on_delivery" => '', "paid" => '', "sold" => '', "rated" => ''];
             }
             array_push($products, (object) $itemDetail);
         }
         $products = collect($products);
         $history = collect($history);
         $token = csrf_token();
         $customerId = $customer->id;
         return view('user.customer.swineCart', compact('products', 'history', 'token', 'customerId'));
     }
 }
 /**
  * View Details of a Product
  *
  * @param  Product  $product
  * @return View
  */
 public function customerViewProductDetail(Product $product)
 {
     // $product = Product::find($productId);
     $product->img_path = '/images/product/' . Image::find($product->primary_img_id)->name;
     $product->breeder = Breeder::find($product->breeder_id)->users->first()->name;
     $product->birthdate = $this->transformBirthdateSyntax($product->birthdate);
     $product->age = $this->computeAge($product->birthdate);
     $product->type = ucfirst($product->type);
     $product->breed = $this->transformBreedSyntax(Breed::find($product->breed_id)->name);
     $product->farm_province = FarmAddress::find($product->farm_from_id)->province;
     $product->other_details = $this->transformOtherDetailsSyntax($product->other_details);
     $product->imageCollection = $product->images()->where('id', '!=', $product->primary_img_id)->get();
     $product->videoCollection = $product->videos;
     return view('user.customer.viewProductDetail', compact('product'));
 }
예제 #6
0
 public function getBreeds()
 {
     return ArrayHelper::map(Breed::find()->puppies()->all(), 'id', 'name');
 }
예제 #7
0
 public function actionPuppies()
 {
     $breeds = Breed::find()->puppies()->all();
     return $this->render('puppies', ['breeds' => $breeds]);
 }
예제 #8
0
 /**
  * PUT /breed/{id}
  * 
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //
     $input = Input::all();
     $rules = Breed::$rules;
     $rules['name'] = $rules['name'] . ',id,' . $id;
     $validation = Validator::make($input, $rules);
     if ($validation->passes()) {
         $breed = Breed::find($id);
         $breed->update($input);
         return Redirect::route('breed.show', $id);
     }
     return Redirect::route('breed.edit', $id)->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }