public function update_status() { $app = JFactory::getApplication(); $helper = new redhelper(); $producthelper = new producthelper(); $stockroomhelper = new rsstockroomhelper(); $post = JRequest::get('post'); $tmpl = JRequest::getVar('tmpl'); $newstatus = JRequest::getVar('status'); $paymentstatus = JRequest::getVar('order_paymentstatus'); $option = JRequest::getVar('option'); $return = JRequest::getVar('return'); $customer_note = JRequest::getVar('customer_note', '', 'request', 'string', JREQUEST_ALLOWRAW); $requisition_number = JRequest::getVar('requisition_number', ''); $oid = JRequest::getVar('order_id', array(), 'method', 'array'); $order_id = $oid[0]; $sendordermail = JRequest::getVar("order_sendordermail"); $isproduct = JRequest::getInt('isproduct', 0); $product_id = JRequest::getInt('product_id', 0); $order_item_id = JRequest::getInt('order_item_id', 0); if (JRequest::getVar('isarchive') != 0 && JRequest::getVar('isarchive') != "") { $isarchive = "&isarchive=1"; } else { $isarchive = ""; } /** * redCRM includes */ if ($helper->isredCRM()) { if ($newstatus == 'C') { if (JRequest::getVar('customstatusconfirmed')) { $customstatus = JRequest::getVar('customstatusconfirmed'); } else { $customstatus = ""; } } elseif ($newstatus == 'S') { if (JRequest::getVar('customstatusshipping')) { $customstatus = JRequest::getVar('customstatusshipping'); } else { $customstatus = ""; } } elseif ($newstatus == 'X') { if (JRequest::getVar('customstatuscanceled')) { $customstatus = JRequest::getVar('customstatuscanceled'); } else { $customstatus = ""; } } else { $customstatus = ""; } $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $crmSupplierOrderHelper->redSHOPCustomOrderUpdate($order_id, $customstatus); if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $getStatus = array(); $getStatus['orderstatus'] = $newstatus; $getStatus['paymentstatus'] = $paymentstatus; $crmSupplierOrderHelper->redSHOPOrderUpdate($order_id, $getStatus); unset($getStatus); } } if (isset($paymentstatus)) { $this->updateOrderPaymentStatus($order_id, $paymentstatus); } $order_log = JTable::getInstance('order_status_log', 'Table'); if (!$isproduct) { $data['order_id'] = $order_id; $data['order_status'] = $newstatus; $data['order_payment_status'] = $paymentstatus; $data['date_changed'] = time(); $data['customer_note'] = $customer_note; if (!$order_log->bind($data)) { return JError::raiseWarning(500, $order_log->getError()); } if (!$order_log->store()) { JError::raiseError(500, $order_log->getError()); } $this->updateOrderComment($order_id, $customer_note); if (isset($post['requisition_number'])) { $this->updateOrderRequisitionNumber($order_id, $post['requisition_number']); } // Changing the status of the order $this->updateOrderStatus($order_id, $newstatus, $order_log->order_status_log_id); $dispatcher = JDispatcher::getInstance(); if ($paymentstatus == "Paid" && $newstatus == "S") { // For Consignor Label generation JPluginHelper::importPlugin('redshop_shippinglabel'); $results = $dispatcher->trigger('onChangeStatusToShipped', array($order_id, $newstatus, $paymentstatus)); } if ($paymentstatus == "Paid") { if ($newstatus == 'C') { $xml_order = $this->getOrderDetails($order_id); JPluginHelper::importPlugin('ERPImportExport'); $dispatcher->trigger('exportOrder', array($xml_order)); } JModel::addIncludePath(JPATH_SITE . '/components/com_redshop/models'); $checkoutModelcheckout = JModel::getInstance('checkout', 'checkoutModel'); $checkoutModelcheckout->sendGiftCard($order_id); // Send the Order mail $redshopMail = new redshopMail(); if (ORDER_MAIL_AFTER) { $redshopMail->sendOrderMail($order_id); } elseif (INVOICE_MAIL_ENABLE) { $redshopMail->sendInvoiceMail($order_id); } } $this->createWebPacklabel($order_id, $specifiedSendDate, $newstatus, $paymentstatus); } $this->updateOrderItemStatus($order_id, $product_id, $newstatus, $customer_note, $order_item_id); $helper->clickatellSMS($order_id); switch ($newstatus) { case "X": // If order is cancelled then, putting stock in the container from where it was dedcuted $orderproducts = $this->getOrderItemDetail($order_id); for ($i = 0; $i < count($orderproducts); $i++) { $conid = $orderproducts[$i]->container_id; $prodid = $orderproducts[$i]->product_id; $prodqty = $orderproducts[$i]->stockroom_quantity; // When the order is set to "cancelled",product will return to stock $stockroomhelper->manageStockAmount($prodid, $prodqty, $orderproducts[$i]->stockroom_id); $producthelper->makeAttributeOrder($orderproducts[$i]->order_item_id, 0, $prodid, 1); // If order is cancelled then, putting stock in the container from where it was dedcuted end if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } break; case "RT": if ($isproduct) { if (USE_CONTAINER) { $orderproductdetail = $this->getOrderItemDetail($order_id, $product_id); $conid = $orderproductdetail[0]->container_id; $prodqty = $orderproductdetail[0]->product_quantity; $this->manageContainerStock($product_id, $prodqty, $conid); } // Changing the status of the order item to Returned $this->updateOrderItemStatus($order_id, $product_id, "RT", $customer_note, $order_item_id); // Changing the status of the order to Partially Returned $this->updateOrderStatus($order_id, "PRT"); } else { $orderproducts = $this->getOrderItemDetail($order_id); for ($i = 0; $i < count($orderproducts); $i++) { $conid = $orderproducts[$i]->container_id; $prodid = $orderproducts[$i]->product_id; $prodqty = $orderproducts[$i]->product_quantity; if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } } break; case "RC": if ($isproduct) { // Changing the status of the order item to Reclamation $this->updateOrderItemStatus($order_id, $product_id, "RC", $customer_note, $order_item_id); // Changing the status of the order to Partially Reclamation $this->updateOrderStatus($order_id, "PRC"); } else { $orderproducts = $this->getOrderItemDetail($order_id); for ($i = 0; $i < count($orderproducts); $i++) { $conid = $orderproducts[$i]->container_id; $prodid = $orderproducts[$i]->product_id; $prodqty = $orderproducts[$i]->product_quantity; if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } } break; case "S": if ($isproduct) { // Changing the status of the order item to Reclamation $this->updateOrderItemStatus($order_id, $product_id, "S", $customer_note, $order_item_id); // Changing the status of the order to Partially Reclamation $this->updateOrderStatus($order_id, "PS"); } break; case "C": // SensDownload Products $this->SendDownload($order_id); break; } if ($sendordermail == 'true') { $this->changeOrderStatusMail($order_id, $newstatus, $customer_note); } $this->createBookInvoice($order_id, $newstatus); $msg = JText::_('COM_REDSHOP_ORDER_STATUS_SUCCESSFULLY_SAVED_FOR_ORDER_ID') . " " . $order_id; if ($return == 'order') { if ($option == 'com_redcrm') { $app->Redirect('index.php?option=' . $option . '&view=' . $return . '&cid[]=' . $order_id . '' . $isarchive . '', $msg); } else { $app->Redirect('index.php?option=' . $option . '&view=' . $return . '' . $isarchive . '', $msg); } } else { if ($tmpl != "") { $app->Redirect('index.php?option=' . $option . '&view=' . $return . '&cid[]=' . $order_id . '&tmpl=' . $tmpl . '' . $isarchive . '', $msg); } else { $app->Redirect('index.php?option=' . $option . '&view=' . $return . '&cid[]=' . $order_id . '' . $isarchive . '', $msg); } } }