public function export_data() { /** * new order export for paid customer support */ $extrafile = JPATH_SITE . '/administrator/components/com_redshop/extras/order_export.php'; if (file_exists($extrafile)) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/extras/order_export.php'; $orderExport = new orderExport(); $orderExport->createOrderExport(); exit; } $producthelper = new producthelper(); $order_function = new order_functions(); $model = $this->getModel('order'); $product_count = array(); $db = JFactory::getDbo(); $cid = JRequest::getVar('cid', array(0), 'method', 'array'); $data = $model->export_data($cid); $order_id = implode(',', $cid); $where = ""; if ($order_id != 0) { $where .= " where order_id IN (" . $order_id . ") "; } $sql = "SELECT order_id,count(order_item_id) as noproduct FROM `#__redshop_order_item` " . $where . " GROUP BY order_id"; header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-type: text/x-csv"); header("Content-type: text/csv"); header("Content-type: application/csv"); header('Content-Disposition: attachment; filename=Order.csv'); $db->setQuery($sql); $no_products = $db->loadObjectList(); for ($i = 0; $i < count($data); $i++) { $product_count[] = $no_products[$i]->noproduct; } $no_products = max($product_count); echo "Order id,Buyer name,Email Id, PhoneNumber,Billing Address ,Billing City,Billing State,Billing Country,BillingPostcode,\n\t\tShipping Address,Shipping City,Shipping State,Shipping Country,ShippingPostCode,Order Status,Order Date,"; for ($i = 1; $i <= $no_products; $i++) { echo JText::_('PRODUCT_NAME') . $i . ','; echo JText::_('PRODUCT') . ' ' . JText::_('PRODUCT_PRICE') . $i . ','; echo JText::_('PRODUCT_ATTRIBUTE') . $i . ','; } echo "Shipping Cost,Order Total\n"; for ($i = 0; $i < count($data); $i++) { $shipping_address = $order_function->getOrderShippingUserInfo($data[$i]->order_id); echo $data[$i]->order_id . ","; echo $data[$i]->firstname . " " . $data[$i]->lastname . ","; echo $data[$i]->user_email . ","; echo $data[$i]->phone . ","; $user_address = str_replace(",", "<br/>", $data[$i]->address); $user_address = strip_tags($user_address); $user_shipping_address = str_replace(",", "<br/>", $shipping_address->address); $user_shipping_address = strip_tags($user_shipping_address); echo trim($user_address) . ","; echo $data[$i]->city . ","; echo $data[$i]->state_code . ","; echo $data[$i]->country_code . ","; echo $data[$i]->zipcode . ","; echo trim($user_shipping_address) . ","; echo $shipping_address->city . ","; echo $shipping_address->state_code . ","; echo $shipping_address->country_code . ","; echo $shipping_address->zipcode . ","; echo $order_function->getOrderStatusTitle($data[$i]->order_status) . ","; echo date('d-m-Y H:i', $data[$i]->cdate) . ","; $no_items = $order_function->getOrderItemDetail($data[$i]->order_id); for ($it = 0; $it < count($no_items); $it++) { echo $no_items[$it]->order_item_name . ","; echo REDCURRENCY_SYMBOL . $no_items[$it]->product_final_price . ","; $product_attribute = $producthelper->makeAttributeOrder($no_items[$it]->order_item_id, 0, $no_items[$it]->product_id, 0, 1); $product_attribute = strip_tags($product_attribute->product_attribute); echo trim($product_attribute) . ","; } $temp = $no_products - count($no_items); echo str_repeat(',', $temp * 3); if ($data[$i]->order_shipping != "") { $shippingcost = $data[$i]->order_shipping; } else { $shippingcost = 0; } echo REDCURRENCY_SYMBOL . $shippingcost . ","; echo REDCURRENCY_SYMBOL . $data[$i]->order_total . "\n"; } exit; }
public function delete($cid = array()) { $producthelper = new producthelper(); $order_functions = new order_functions(); $quotationHelper = new quotationHelper(); $stockroomhelper = new rsstockroomhelper(); if (count($cid)) { if (ECONOMIC_INTEGRATION == 1) { $economic = new economic(); for ($i = 0; $i < count($cid); $i++) { $orderdata = $this->getTable('order_detail'); $orderdata->load($cid[$i]); $invoiceHandle = $economic->deleteInvoiceInEconomic($orderdata); } } $cids = implode(',', $cid); $db = JFactory::getDbo(); $order_item = $order_functions->getOrderItemDetail($cids); for ($i = 0; $i < count($order_item); $i++) { $quntity = $order_item[$i]->product_quantity; $order_id = $order_item[$i]->order_id; $order_detail = $order_functions->getOrderDetails($order_id); if ($order_detail->order_payment_status == "Unpaid") { // Update stock roommanageStockAmount $stockroomhelper->manageStockAmount($order_item[$i]->product_id, $quntity, $order_item[$i]->stockroom_id); } $producthelper->makeAttributeOrder($order_item[$i]->order_item_id, 0, $order_item[$i]->product_id, 1); $query = "DELETE FROM `" . $this->_table_prefix . "order_attribute_item` " . "WHERE `order_item_id` = " . $order_item[$i]->order_item_id; $this->_db->setQuery($query); $this->_db->query(); $query = "DELETE FROM `" . $this->_table_prefix . "order_acc_item` " . "WHERE `order_item_id` = " . $order_item[$i]->order_item_id; $this->_db->setQuery($query); $this->_db->query(); } $query = 'DELETE FROM ' . $this->_table_prefix . 'orders WHERE order_id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $query = 'DELETE FROM ' . $this->_table_prefix . 'order_item WHERE order_id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $query = 'DELETE FROM ' . $this->_table_prefix . 'order_payment WHERE order_id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $query = 'DELETE FROM ' . $this->_table_prefix . 'order_users_info WHERE order_id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $quotation = $quotationHelper->getQuotationwithOrder($cids); for ($q = 0; $q < count($quotation); $q++) { $quotation_item = $quotationHelper->getQuotationProduct($quotation[$q]->quotation_id); for ($j = 0; $j < count($quotation_item); $j++) { $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation_fields_data ' . 'WHERE quotation_item_id=' . $quotation_item[$j]->quotation_item_id; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation_item ' . 'WHERE quotation_id=' . $quotation[$q]->quotation_id; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation WHERE order_id IN ( ' . $cids . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } } return true; }
public function orderStatusUpdate($order_id, $post = array()) { $helper = new redhelper(); $stockroomhelper = new rsstockroomhelper(); $producthelper = new producthelper(); $newstatus = $post['order_status_all']; $customer_note = $post['customer_note' . $order_id]; $isproduct = isset($post['isproduct']) ? $post['isproduct'] : 0; $product_id = isset($post['product_id']) ? $post['product_id'] : 0; $paymentstatus = $post['order_paymentstatus' . $order_id]; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_redshop/tables'); // Add status log... $order_log = JTable::getInstance('order_status_log', 'Table'); $order_log->order_id = $customer_note; $order_log->customer_note = $customer_note; $order_log->order_status = $newstatus; $order_log->date_changed = time(); if (!$order_log->store()) { return JError::raiseWarning('', $order_log->getError()); } // Changing the status of the order $this->updateOrderStatus($order_id, $newstatus); // Changing the status of the order if (isset($paymentstatus)) { $this->updateOrderPaymentStatus($order_id, $paymentstatus); } // For Consignor Label generation JPluginHelper::importPlugin('redshop_shippinglabel'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onChangeStatusToShipped', array($order_id, $newstatus, $paymentstatus)); // For Webpack Postdk Label Generation $this->createWebPacklabel($order_id, "", $newstatus, $paymentstatus); if (CLICKATELL_ENABLE) { // Changing the status of the order end $helper->clickatellSMS($order_id); } // If changing the status of the order then there item status need to change if ($isproduct != 1) { $this->updateOrderItemStatus($order_id, 0, $newstatus); } // If order is cancelled then, putting stock in the container from where it was dedcuted if ($newstatus == 'X') { $orderproducts = $this->getOrderItemDetail($order_id); for ($j = 0; $j < count($orderproducts); $j++) { $conid = $orderproducts[$j]->container_id; $prodid = $orderproducts[$j]->product_id; $prodqty = $orderproducts[$j]->stockroom_quantity; // When the order is set to "cancelled",product will return to stock $stockroomhelper->manageStockAmount($prodid, $prodqty, $orderproducts[$j]->stockroom_id); $producthelper->makeAttributeOrder($orderproducts[$j]->order_item_id, 0, $prodid, 1); if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } } elseif ($newstatus == 'RT') { // If any of the item from the order is returuned back then, // change the status of whole order and also put back to stock. if ($isproduct) { $orderproductdetail = $this->getOrderItemDetail($order_id, $product_id); $conid = $orderproductdetail[0]->container_id; $prodid = $orderproductdetail[0]->product_id; $prodqty = $orderproductdetail[0]->product_quantity; if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } // Changing the status of the order item to Returned $this->updateOrderItemStatus($order_id, $prodid, "RT"); // Changing the status of the order to Partially Returned $this->updateOrderStatus($order_id, "PRT"); } else { $orderproducts = $this->getOrderItemDetail($order_id); for ($k = 0; $k < count($orderproducts); $k++) { $conid = $orderproducts[$k]->container_id; $prodid = $orderproducts[$k]->product_id; $prodqty = $orderproducts[$k]->product_quantity; if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } } } elseif ($newstatus == 'RC') { // If any of the item from the order is reclamation back then, // change the status of whole order and also put back to stock. if ($isproduct) { // Changing the status of the order item to Reclamation $this->updateOrderItemStatus($order_id, $product_id, "RC"); // Changing the status of the order to Partially Reclamation $this->updateOrderStatus($order_id, "PRC"); } else { $orderproducts = $this->getOrderItemDetail($order_id); for ($l = 0; $l < count($orderproducts); $l++) { $conid = $orderproducts[$l]->container_id; $prodid = $orderproducts[$l]->product_id; $prodqty = $orderproducts[$l]->product_quantity; if (USE_CONTAINER) { $this->manageContainerStock($prodid, $prodqty, $conid); } } } } elseif ($newstatus == 'S') { if ($isproduct) { // Changing the status of the order item to Reclamation $this->updateOrderItemStatus($order_id, $product_id, "S"); // Changing the status of the order to Partially Reclamation $this->updateOrderStatus($order_id, "PS"); } } // Mail to customer of order status change $this->changeOrderStatusMail($order_id, $newstatus, $customer_note); $this->createBookInvoice($order_id, $newstatus); // GENERATE PDF CODE WRITE return true; }