Esempio n. 1
0
 public function delete($id)
 {
     \Veer\Models\Order::where('delivery_method_id', '=', $id)->update(['delivery_method_id' => 0]);
     \Veer\Models\OrderShipping::destroy($id);
     event('veer.message.center', trans('veeradmin.shipping.delete') . " " . $this->restore_link('OrderShipping', $id));
     return $this;
 }
Esempio n. 2
0
 /**
  * show Statuses
  */
 public function getStatuses($paginateItems = 50)
 {
     app('veer')->loadedComponents['counted']['orders'] = \Veer\Models\Order::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id');
     app('veer')->loadedComponents['counted']['orders_history'] = \Veer\Models\OrderHistory::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id');
     app('veer')->loadedComponents['counted']['bills'] = \Veer\Models\OrderBill::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id');
     return \Veer\Models\OrderStatus::orderBy('manual_order', 'asc')->paginate($paginateItems);
 }
Esempio n. 3
0
 public function add($params, $template = null)
 {
     $order = \Veer\Models\Order::find(array_get($params, 'orders_id'));
     $status = \Veer\Models\OrderStatus::find(array_get($params, 'status_id'));
     $payment = $payment_method = array_get($params, 'payment_method');
     $sendEmail = array_pull($params, 'sendTo', null);
     if (empty($payment)) {
         $payment = \Veer\Models\OrderPayment::find(array_get($params, 'payment_method_id'));
         $payment_method = isset($payment->name) ? $payment->name : $payment_method;
     }
     $content = '';
     if (!empty($template)) {
         /* leave 'view' instead of 'viewx' because we always need (rendered) html representation of the bill */
         $content = view("components.bills." . $template, ["order" => $order, "status" => $status, "payment" => $payment, "price" => array_get($params, 'price')])->render();
     }
     $b = new \Veer\Models\OrderBill();
     $b->fill($params);
     $b->users_id = isset($order->users_id) ? $order->users_id : 0;
     $b->payment_method = $payment_method;
     $b->content = $content;
     if (!empty($sendEmail)) {
         $b->sent = true;
     }
     $b->save();
     if (!empty($sendEmail) && is_object($order)) {
         $this->sendEmailBillCreate($b, $order);
     }
     return $this;
 }
Esempio n. 4
0
 public function delete($id)
 {
     \Veer\Models\Order::where('payment_method_id', '=', $id)->update(['payment_method_id' => 0]);
     \Veer\Models\OrderBill::where('payment_method_id', '=', $id)->update(['payment_method_id' => 0]);
     \Veer\Models\OrderPayment::destroy($id);
     event('veer.message.center', trans('veeradmin.payment.delete') . " " . $this->restore_link('OrderPayment', $id));
     return $this;
 }
Esempio n. 5
0
 /**
  * delete Status
  */
 public function delete($id)
 {
     \Veer\Models\Order::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderBill::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderHistory::where('status_id', '=', $id)->update(['status_id' => 0]);
     \Veer\Models\OrderStatus::destroy($id);
     event('veer.message.center', trans('veeradmin.status.delete') . " " . $this->restore_link('OrderStatus', $id));
     return $this;
 }
Esempio n. 6
0
 /**
  * send emails when updating order status
  */
 protected function sendEmailOrdersStatus($orderId, $options = array())
 {
     $data = \Veer\Models\Order::where('id', '=', $orderId)->select('sites_id', 'cluster', 'cluster_oid', 'name', 'email')->first();
     $data_array = $data->toArray();
     $data_array['orders_id'] = app('veershop')->getOrderId($data->cluster, $data->cluster_oid);
     $data_array['status'] = array_get($options, 'history');
     $data_array['link'] = $data->site->url . "/order/" . $orderId;
     $subject = \Lang::get('veeradmin.emails.order.subject', array('oid' => $data_array['orders_id']));
     if (!empty($data->email)) {
         (new \Veer\Commands\SendEmailCommand('emails.order-status', $data_array, $subject, $data->email, null, $data->sites_id))->handle();
     }
 }
Esempio n. 7
0
 /**
  * Check secret code for order and get object if it exists.
  */
 public function store()
 {
     if (\Input::has('password')) {
         $p = trim(\Input::get('password'));
         if (!empty($p)) {
             $check = \Veer\Models\Order::whereHas('secrets', function ($query) use($p) {
                 $query->where('secret', '=', $p);
             })->pluck('id');
             if (!empty($check)) {
                 return $this->showingOrder($this->showOrder->getOrderWithSite(app('veer')->siteId, $check, null, true));
             }
         }
     }
     return $this->index();
 }
Esempio n. 8
0
 /**
  * add New Order
  * 
  * pin, close_time, type, status_id, cluster, cluster_oid,
  * users_id, user_type, userdiscount_id, userbook_id, country, city, address, hash
  * 
  * @param $order
  * @param $usersId
  * @return array
  */
 public function addNewOrder($order, $usersId, $book = array(), $pretend = false)
 {
     $order->pin = false;
     $order->close_time = null;
     $order->type = 'reg';
     $firststatus = \Veer\Models\OrderStatus::firststatus()->pluck('id');
     $order->status_id = !empty($firststatus) ? $firststatus : 0;
     $cluster = \Veer\Models\Configuration::where('sites_id', '=', $order->sites_id)->where('conf_key', '=', 'CLUSTER')->pluck('conf_val');
     if (empty($cluster)) {
         $cluster = 0;
     }
     $order->cluster = $cluster;
     $order->cluster_oid = \Veer\Models\Order::where('sites_id', '=', $order->sites_id)->where('cluster', '=', $cluster)->max('cluster_oid') + 1;
     if (empty($usersId) && !empty($order->email)) {
         $findUser = \Veer\Models\User::where('sites_id', '=', $order->sites_id)->where('email', '=', $order->email)->first();
         if (is_object($findUser)) {
             $order->users_id = $findUser->id;
             if (empty($order->phone)) {
                 $order->phone = $findUser->phone;
             }
             if (empty($order->name)) {
                 $order->name = $findUser->firstname . " " . $findUser->lastname;
             }
         } else {
             $newUser = new \Veer\Models\User();
             $newUser->sites_id = $order->sites_id;
             $newUser->email = $order->email;
             $newUser->phone = $order->phone;
             $password2Email = str_random(16);
             $newUser->password = $password2Email;
             $newUser->save();
             $order->users_id = $newUser->id;
             $order->type = 'unreg';
             $unregStatus = \Veer\Models\OrderStatus::unregstatus()->pluck('id');
             if (!empty($unregStatus)) {
                 $order->status_id = $unregStatus;
             }
         }
     }
     if (!empty($usersId) && (empty($order->email) || empty($order->phone) || empty($order->name))) {
         $findUser = \Veer\Models\User::where('id', '=', $usersId)->first();
         if (is_object($findUser)) {
             if (empty($order->email)) {
                 $order->email = $findUser->email;
             }
             if (empty($order->phone)) {
                 $order->phone = $findUser->phone;
             }
             if (empty($order->name)) {
                 $order->name = $findUser->firstname . " " . $findUser->lastname;
             }
         }
     }
     $userRole = \Veer\Models\UserRole::whereHas('users', function ($q) use($order) {
         $q->where('users.id', '=', $order->users_id);
     })->pluck('role');
     $order->user_type = !empty($userRole) ? $userRole : '';
     if (!empty($order->userdiscount_id)) {
         $checkDiscount = \Veer\Models\UserDiscount::where('id', '=', $order->userdiscount_id)->where('sites_id', '=', $order->sites_id)->whereNested(function ($q) use($order) {
             $q->where('users_id', '=', 0)->orWhere('users_id', '=', $order->users_id);
         })->whereNested(function ($q) {
             $q->where('status', '=', 'wait')->orWhere('status', '=', 'active');
         })->first();
         if (is_object($checkDiscount)) {
             $checkDiscount->users_id = $order->users_id;
             $checkDiscount->status = 'active';
             $checkDiscount->save();
         } else {
             $order->userdiscount_id = 0;
         }
     }
     if (!empty($book)) {
         $book['fill']['users_id'] = $order->users_id;
         $newBook = $this->updateOrNewBook($book, $pretend);
     }
     if (isset($newBook) && is_object($newBook)) {
         $order->userbook_id = $newBook->id;
         $order->country = !empty($newBook->country) ? $newBook->country : '';
         $order->city = !empty($newBook->city) ? $newBook->city : '';
         $order->address = trim($newBook->postcode . " " . $newBook->address);
     }
     $order->hash = bcrypt($order->cluster . $order->cluster_oid . $order->users_id . $order->sites_id . str_random(16));
     if ($pretend == false) {
         $order->save();
         $this->incrementOrdersCount($order->users_id);
         $secret = new \Veer\Models\Secret(array("secret" => str_random(64)));
         $order->secrets()->save($secret);
     }
     return array($order, isset($checkDiscount) ? $checkDiscount : null);
 }
Esempio n. 9
0
 /**
  * show One order
  */
 public function getOrderAdvanced($order)
 {
     if ($order == "new") {
         return new \stdClass();
     }
     $items = \Veer\Models\Order::find($order);
     if (is_object($items)) {
         $this->loadOrderRelations($items);
         $this->loadSiteTitle($items);
         if (is_object($items->products)) {
             $items->products = $this->regroupOrderProducts($items->products);
         }
         if (is_object($items->orderContent)) {
             $items->orderContent = $this->orderContentParse($items->orderContent, $items->products);
         }
     }
     if (empty(app('veer')->loadedComponents['billsTypes'])) {
         $this->getExistingBillTemplates();
     }
     return $items;
 }
Esempio n. 10
0
 protected function deleteOrder($id)
 {
     $order = \Veer\Models\Order::find($id);
     if (is_object($order)) {
         \Veer\Models\OrderHistory::where('orders_id', '=', $id)->delete();
         $order->orderContent()->delete();
         $order->bills()->delete();
         $order->secrets()->delete();
         // communications skip
         $order->delete();
         return true;
     }
     return false;
 }
Esempio n. 11
0
 public function status($history)
 {
     array_set($history, 'orders_id', $this->id);
     array_set($history, 'name', \Veer\Models\OrderStatus::where('id', '=', array_get($history, 'status_id'))->pluck('name'));
     if (empty($history['name'])) {
         $history['name'] = '[?]';
     }
     $update = ['status_id' => array_get($history, 'status_id')];
     $progress = array_pull($history, 'progress');
     if (!empty($progress)) {
         $update['progress'] = $progress;
     }
     $sendEmail = array_pull($history, 'send_to_customer');
     \Veer\Models\OrderHistory::create($history);
     \Veer\Models\Order::where('id', '=', $this->id)->update($update);
     if (!empty($sendEmail)) {
         $this->sendEmailOrdersStatus($this->id, ['history' => $history]);
     }
     return $this;
 }