Ejemplo n.º 1
0
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function soldouts()
 {
     try {
         $this->soldouts = new Collection();
         $payments = EloquentPaymentRepository::where('status', '=', 1)->orderBy('updated_at', true)->get();
         $payments->map(function ($payment, $index) {
             $products = $payment->order->products;
             $products->map(function ($product, $key) use($index, $payment) {
                 $product->pivot;
                 $product->driver;
                 $product->time = Carbon::createFromTimeStamp($payment->updated_at->format('U'))->diffForHumans();
                 $product->date = $payment->updated_at;
                 $this->soldouts->push($product->toArray());
             });
         });
         $page = \Input::get('page') > 0 ? \Input::get('page', 1) : 1;
         $per_page = \Input::get('per_page', 5);
         return $this->soldouts->slice(($page - 1) * $per_page, $per_page)->toArray();
     } catch (\Exception $e) {
         return $this->errorInternalError();
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $driver
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function destroy($driver = NULL)
 {
     try {
         \DB::beginTransaction();
         if (is_null($driver)) {
             $driver = $this->getAuthenticatedDriver();
         }
         if ($notifications = $driver->notifications) {
             $notifications->map(function ($notification) {
                 if (EloquentNotificationTypeRepository::find($notification->type_id)->type == 'sales') {
                     if (Payment::find($notification->value)->status == 0) {
                         return;
                     }
                 }
                 $notification->delete();
             });
             \DB::commit();
             return $this->setStatusCode(204)->respond(['success' => true, 'message' => $this->translator->trans('notifications.deleted')]);
         }
         return $this->setStatusCode(404)->respondWithError($this->translator->trans('notifications.no_available_resources'));
     } catch (\Exception $e) {
         return $this->errorInternalError();
     }
 }
Ejemplo n.º 3
0
 /**
  * @param $notification
  *
  * @return array
  */
 public function transformSales($notification)
 {
     $payment = Payment::find($notification->value);
     $payment_status = strtolower($payment->status);
     // get the payment type.
     switch ($payment->payment_method()->first()->name) {
         case 'paypal':
             $translation = "notifications.sales.paypal.completed";
             $sales = ['message' => $this->translator->trans($translation, ['currency' => $notification->driver->currency, 'amount' => $payment->order->total_sales]), 'type' => 'sales', 'status' => $payment_status, 'payment' => $payment];
             break;
         default:
             if ($payment_status == 0) {
                 $status = 'waiting';
             }
             if ($payment_status == -1) {
                 $status = 'canceled';
             }
             if ($payment_status == 1) {
                 $status = 'received';
             }
             $translation = "notifications.sales.cash." . $status;
             $sales = ['message' => $this->translator->trans($translation, ['currency' => $notification->driver->currency, 'amount' => $payment->order->total_sales]), 'type' => 'sales', 'status' => $payment_status, 'payment' => $payment];
     }
     return $sales;
 }