Beispiel #1
0
 /**
  * Create and Retrieve the OrderID
  * @param integer $id
  * @return Orders
  */
 public static function create($customerId, $statusId = "", $note = "")
 {
     $customer = Customers::getAllInfo($customerId);
     $isp_id = $customer['isp_id'];
     if (self::$order) {
         return self::$order;
     }
     if (is_numeric($customerId)) {
         $order = new Orders();
         // Execute a custom event
         self::events()->trigger('orders_create_before', "Orders", array('order' => $order, 'customerid' => $customerId));
         $order['customer_id'] = $customerId;
         $order['order_date'] = date('Y-m-d H:i:s');
         $order['expiring_date'] = date('Y-m-d', strtotime('30 days', strtotime($order['order_date'])));
         $order['isp_id'] = $isp_id;
         $order['status_id'] = is_numeric($statusId) ? $statusId : Statuses::id("tobepaid", "orders");
         $order['uuid'] = Shineisp_Commons_Uuid::generate();
         // Save the data
         $order->save();
         // Save order number
         $order->order_number = self::formatOrderId($order->order_id);
         // Save the order
         if ($order->trySave()) {
             // Log status change
             self::logStatusChange($order->order_id, $order->status_id);
             // Assign the order var to the static var
             self::$order = $order;
             // Create the fastlink for the order
             $fastlink = Fastlinks::CreateFastlink('orders', 'edit', json_encode(array('id' => $order['order_id'])), 'orders', $order['order_id'], $customerId);
             // Add a message within the order
             Messages::addMessage($note, $customerId, null, $order['order_id']);
             // Execute a custom event
             self::events()->trigger('orders_create_after', "Orders", array('order' => $order, 'fastlink' => $fastlink));
             // Return the order object var
             return self::$order;
         } else {
             throw new Exception('There was a problem when I try to create the order', 1003);
         }
     } else {
         throw new Exception('Customer ID has been not found', 1001);
     }
     return null;
 }
Beispiel #2
0
 /**
  * Clean all the obsolete orders without expiring date
  * Set the obsolete orders as deleted
  */
 public static function cleanNotPaidOrders()
 {
     $orders = Orders::find_all_not_paid_orders();
     foreach ($orders as $order) {
         if (empty($order['expiring_date'])) {
             // Set all the order oldest more of 1 month as deleted
             $date1 = new DateTime($order['order_date']);
             $date2 = new DateTime(date('Y-m-d'));
         } else {
             // Set the expired orders as deleted
             $date1 = new DateTime($order['order_date']);
             $date2 = new DateTime($order['expiring_date']);
         }
         $interval = $date1->diff($date2);
         if ($interval->y <= 0 || $interval->m <= 0) {
             $customer = Customers::getAllInfo($order['customer_id']);
             // Get the fastlink attached
             $link_exist = Fastlinks::findlinks($order['order_id'], $order['customer_id'], 'orders');
             if (count($link_exist) > 0) {
                 $fastlink = $link_exist[0]['code'];
             } else {
                 $fastlink = Fastlinks::CreateFastlink('orders', 'edit', json_encode(array('id' => $order['order_id'])), 'orders', $order['order_id'], $customer['customer_id']);
             }
             $customer_url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/{$fastlink}";
             Shineisp_Commons_Utilities::sendEmailTemplate($customer['email'], 'order_deleted', array('orderid' => $order['order_number'], ':shineisp:' => $customer, 'fullname' => $customer['fullname'], 'url' => $customer_url), null, null, null, null, $customer['language_id'], Settings::findbyParam('cron_notify'));
             // Set the order as deleted
             Orders::set_status($order['order_id'], Statuses::id('deleted', 'orders'));
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Get the fastlink of invoice, if not exist create it
  ****/
 public static function getFastlinksInvoice($invoiceid, $orderid, $customerid)
 {
     $link_exist = Fastlinks::findlinks($orderid, $customerid, 'orders');
     // The fastlink does not exists and we have to create it
     if (count($link_exist) == 0) {
         $fastlink = Fastlinks::CreateFastlink("orders", "createinvoice", json_encode(array('id' => $invoiceid)), "orders", $orderid, $customerid);
     } else {
         // The fastlink exists and we get it in order to write it in the email content
         // but before we have to check if the link that we have to send to the user contain the right invoice
         // If the id of the invoice is not equal to the id of the invoice attached into the order we have to create a new fastlink
         $params = json_decode($link_exist[0]['params'], true);
         if (!empty($params['id']) && $params['id'] == $invoiceid) {
             $fastlink = $link_exist[0]['code'];
         } else {
             $fastlink = Fastlinks::CreateFastlink("orders", "createinvoice", json_encode(array('id' => $invoiceid)), "orders", $orderid, $customerid);
         }
     }
     return $fastlink;
 }
Beispiel #4
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $isp = Shineisp_Registry::get('ISP');
     $request = $this->getRequest();
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('index');
     }
     // Get our form and validate it
     $form = $this->getForm('/admin/orders/process');
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         $this->view->title = $this->translator->translate("Order process");
         $this->view->description = $this->translator->translate("Check the information posted and then click on the save button.");
         return $this->_helper->viewRenderer('applicantform');
         // re-render the login form
     }
     // Get the values posted
     $params = $form->getValues();
     // Get the id
     $id = $this->getRequest()->getParam('order_id');
     // Save the message note
     if (!empty($params['note'])) {
         // If the order is commentable then go on
         if (Orders::IsCommentable($id)) {
             $order = Orders::getAllInfo($id, null, true);
             $link = Fastlinks::findlinks($id, $this->customer['customer_id'], 'orders');
             if (!empty($link[0]['code'])) {
                 $code = $link[0]['code'];
             } else {
                 $code = Fastlinks::CreateFastlink('orders', 'edit', json_encode(array('id' => $id)), 'orders', $id, $this->customer['customer_id']);
             }
             // Save the message in the database
             Messages::addMessage($params['note'], $this->customer['customer_id'], null, $id);
             $in_reply_to = md5($id);
             $placeholder['messagetype'] = $this->translator->translate('Order');
             $placeholders['subject'] = sprintf("%03s", $id) . " - " . Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
             $placeholders['fullname'] = $this->customer['firstname'] . " " . $this->customer['lastname'];
             $placeholders['orderid'] = $placeholders['subject'];
             $placeholders['conditions'] = Settings::findbyParam('conditions');
             $placeholders['url'] = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $code;
             // Send a message to the customer
             Shineisp_Commons_Utilities::sendEmailTemplate($order[0]['Customers']['email'], 'order_message', $placeholders, $in_reply_to, null, null, $isp, $order[0]['Customers']['language_id']);
             $placeholders['url'] = "http://" . $_SERVER['HTTP_HOST'] . "/admin/login/link/id/{$code}/keypass/" . Shineisp_Commons_Hasher::hash_string($isp->email);
             $placeholders['message'] = $params['note'];
             // Send a message to the administrator
             Shineisp_Commons_Utilities::sendEmailTemplate($isp->email, 'order_message_admin', $placeholders, $in_reply_to);
         }
     }
     $this->_helper->redirector('index', 'orders', 'default', array('mex' => 'The requested task has been completed successfully', 'status' => 'success'));
 }
Beispiel #5
0
 /**
  * This batch has been created in order to remind customers
  * that one or more tickets are still open.
  */
 public static function checkTickets()
 {
     $isp = Isp::getActiveISP();
     $tickets = Tickets::getWaitingReply();
     // Get the template from the main email template folder
     $retval = Shineisp_Commons_Utilities::getEmailTemplate('ticket_waitreply');
     foreach ($tickets as $ticket) {
         $customer = $ticket['Customers'];
         // Get the fastlink attached
         $link_exist = Fastlinks::findlinks($ticket['ticket_id'], $customer['customer_id'], 'tickets');
         if (count($link_exist) > 0) {
             $fastlink = $link_exist[0]['code'];
         } else {
             $fastlink = Fastlinks::CreateFastlink('tickets', 'edit', json_encode(array('id' => $ticket['ticket_id'])), 'tickets', $ticket['ticket_id'], $customer['customer_id']);
         }
         $customer_url = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/{$fastlink}";
         if ($retval) {
             $subject = $retval['subject'];
             $Template = nl2br($retval['template']);
             $subject = str_replace("[subject]", $ticket['subject'], $subject);
             $Template = str_replace("[subject]", $ticket['subject'], $Template);
             $Template = str_replace("[lastname]", $customer['lastname'], $Template);
             $Template = str_replace("[issue_number]", $ticket['ticket_id'], $Template);
             $Template = str_replace("[date_open]", Shineisp_Commons_Utilities::formatDateOut($ticket['date_open']), $Template);
             $Template = str_replace("[link]", $customer_url, $Template);
             $Template = str_replace("[signature]", $isp['company'] . "<br/>" . $isp['website'], $Template);
             Shineisp_Commons_Utilities::SendEmail($isp['email'], Contacts::getEmails($customer['customer_id']), null, $subject, $Template, true);
         }
     }
     return true;
 }