public function deleteAll()
 {
     NotificationRequest::where('sent', false)->delete();
     return redirect()->back()->with('success_message', 'All pending notification has been deleted');
 }
 public function orderCreated(Order $order)
 {
     assert($order->user_id);
     assert($order->user);
     Log::info("created\t#order:{$order->id} user:{$order->user->id} status:{$order->orderStatus->name} created_at:{$order->created_at}");
     if ($order->order_status_id == OrderStatus::Draft()->id) {
         Log::info('Skip notification for draft orders');
         return;
     }
     NotificationRequest::create(['target_id' => $order->id, 'route' => 'new-order', 'channel' => 'Sms', 'to_user_id' => User::admin()->id]);
     if ($order->is_hq) {
         assert($order->user->referral_id);
         NotificationRequest::create(['target_id' => $order->id, 'route' => 'new-downlevel-order', 'channel' => 'Sms', 'to_user_id' => $order->user->referral_id]);
     } else {
         assert($order->organization_id);
         if (!$order->user->isManager()) {
             if ($order->organization_id != Organization::HQ()->id) {
                 NotificationRequest::create(['target_id' => $order->id, 'route' => 'new-order', 'channel' => 'Sms', 'to_user_id' => $order->organization->admin_id]);
             }
             $referral_id = $order->user->new_referral_id;
             assert($referral_id);
             NotificationRequest::create(['target_id' => $order->id, 'route' => 'new-downlevel-order', 'channel' => 'Sms', 'to_user_id' => $referral_id]);
         }
     }
     User::createUserEvent($order->user, ['created_at' => $order->created_at, 'controller' => 'timeline', 'route' => '/new-order', 'target_id' => $order->id]);
 }