Example #1
0
 public function exportlogisticsAction()
 {
     $orderIds = $this->getRequest()->getPost('order_ids');
     if (!empty($orderIds)) {
         $template = '"{{increment_id}}","{{created_at}}","{{customer}}","{{product_name}}","{{sku}}","{{qty}}","{{size}}","{{short_description}}","{{price}}"';
         $headers = new Varien_Object(array('increment_id' => Mage::helper('sales')->__('Order Id'), 'created_at' => Mage::helper('sales')->__('Date'), 'customer' => Mage::helper('sales')->__('Customer Name'), 'product_name' => Mage::helper('sales')->__('Product Name'), 'sku' => Mage::helper('sales')->__('SKU'), 'qty' => Mage::helper('sales')->__('Qty Ordered'), 'size' => Mage::helper('sales')->__('Size'), 'short_description' => Mage::helper('sales')->__('shortDescription'), 'price' => Mage::helper('sales')->__('Product Value')));
         $content = $headers->toString($template) . "\n";
         foreach ($orderIds as $orderId) {
             // Get order data
             $order = Mage::getModel('sales/order')->load($orderId);
             $payment = $order->getPayment();
             $orderData = array('increment_id' => $order->getIncrementId(), 'created_at' => $order->getCreatedAt(), 'customer' => $order->getCustomerFirstname() . " " . $order->getCustomerLastname());
             // Get items
             foreach ($order->getAllItems() as $item) {
                 if ($item->getParentItem()) {
                     continue;
                 }
                 // get product
                 $product = Mage::getModel('catalog/product')->load($item->getProductId());
                 $size = $product->getAttributeText('size');
                 if (!$size) {
                     foreach ($item->getProductOptions() as $option) {
                         if ($option[0]['label'] == 'Size') {
                             $size = $option[0]['value'];
                             break;
                         }
                     }
                 }
                 $remove = array(",", "'", '"');
                 $orderItemData = array('product_name' => (string) str_replace($remove, '', trim($product->getName())), 'sku' => $product->getSku(), 'qty' => $item->getQtyOrdered(), 'size' => $size, 'short_description' => (string) str_replace($remove, '', trim($product->getShortDescription())), 'price' => $product->getPrice());
                 $allData = new Varien_Object();
                 $allData->setData(array_merge($orderData, $orderItemData));
                 $content .= $allData->toString($template) . "\n";
             }
             $allData = new Varien_Object();
             $allData->setData('');
             $content .= $allData->toString($template) . "\n";
         }
         return $this->_prepareDownloadResponse('order_export.csv', $content);
     }
     $this->_redirect('*/*/');
 }
 /**
  * export action from import/export tax
  *
  */
 public function exportPostAction()
 {
     /** start csv content and set template */
     $headers = new Varien_Object(array('code' => Mage::helper('tax')->__('Code'), 'country_name' => Mage::helper('tax')->__('Country'), 'region_name' => Mage::helper('tax')->__('State'), 'tax_postcode' => Mage::helper('tax')->__('Zip/Post Code'), 'rate' => Mage::helper('tax')->__('Rate'), 'zip_is_range' => Mage::helper('tax')->__('Zip/Post is Range'), 'zip_from' => Mage::helper('tax')->__('Range From'), 'zip_to' => Mage::helper('tax')->__('Range To')));
     $template = '"{{code}}","{{country_name}}","{{region_name}}","{{tax_postcode}}","{{rate}}"' . ',"{{zip_is_range}}","{{zip_from}}","{{zip_to}}"';
     $content = $headers->toString($template);
     $storeTaxTitleTemplate = array();
     $taxCalculationRateTitleDict = array();
     foreach (Mage::getModel('core/store')->getCollection()->setLoadDefault(false) as $store) {
         $storeTitle = 'title_' . $store->getId();
         $content .= ',"' . $store->getCode() . '"';
         $template .= ',"{{' . $storeTitle . '}}"';
         $storeTaxTitleTemplate[$storeTitle] = null;
     }
     unset($store);
     $content .= "\n";
     foreach (Mage::getModel('tax/calculation_rate_title')->getCollection() as $title) {
         $rateId = $title->getTaxCalculationRateId();
         if (!array_key_exists($rateId, $taxCalculationRateTitleDict)) {
             $taxCalculationRateTitleDict[$rateId] = $storeTaxTitleTemplate;
         }
         $taxCalculationRateTitleDict[$rateId]['title_' . $title->getStoreId()] = $title->getValue();
     }
     unset($title);
     $collection = Mage::getResourceModel('tax/calculation_rate_collection')->joinCountryTable()->joinRegionTable();
     while ($rate = $collection->fetchItem()) {
         if ($rate->getTaxRegionId() == 0) {
             $rate->setRegionName('*');
         }
         if (array_key_exists($rate->getId(), $taxCalculationRateTitleDict)) {
             $rate->addData($taxCalculationRateTitleDict[$rate->getId()]);
         } else {
             $rate->addData($storeTaxTitleTemplate);
         }
         $content .= $rate->toString($template) . "\n";
     }
     $this->_prepareDownloadResponse('tax_rates.csv', $content);
 }
Example #3
0
 /**
  * Tests Varien_Object->toString()
  */
 public function testToString()
 {
     $this->_object->setData(array('key1' => 'value1', 'key2' => 'value2'));
     $this->assertEquals('value1, value2', $this->_object->toString());
     $this->assertEquals('test value1 with value2', $this->_object->toString('test {{key1}} with {{key2}}'));
 }
Example #4
0
 public function exportinvoicesAction()
 {
     $invoicesIds = $this->getRequest()->getPost('invoice_ids');
     if (!empty($invoicesIds)) {
         $invoices = Mage::getResourceModel('sales/order_invoice_collection')->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array('in' => $invoicesIds))->load();
         $template = '"{{increment_id}}","{{order_id}}","{{created_at}}","{{items}}","{{shipping_name}}","{{shipping_address1}}","{{shipping_city}}","{{shipping_state}}","{{shipping_zip}}","{{shipping_phone}}","{{tax_type}}","{{tax_rate}}","{{basic}}","{{tax}}","{{total}}","{{shipping}}","{{cod_amount}}","{{mode}}","{{courier}}","{{tracking}}"';
         $headers = new Varien_Object(array('increment_id' => Mage::helper('sales')->__('Invoice Id'), 'order_id' => Mage::helper('sales')->__('Order Id'), 'created_at' => Mage::helper('sales')->__('Date'), 'items' => Mage::helper('sales')->__('Items'), 'shipping_name' => Mage::helper('sales')->__('Shipping Name'), 'shipping_address1' => Mage::helper('sales')->__('Shipping Add1'), 'shipping_city' => Mage::helper('sales')->__('Shipping City'), 'shipping_state' => Mage::helper('sales')->__('Shipping State'), 'shipping_zip' => Mage::helper('sales')->__('Shipping Zip'), 'shipping_phone' => Mage::helper('sales')->__('Shipping Phone'), 'tax_type' => Mage::helper('sales')->__('Tax Type'), 'tax_rate' => Mage::helper('sales')->__('Tax Rate'), 'basic' => Mage::helper('sales')->__('Basic'), 'tax' => Mage::helper('sales')->__('Tax Amt'), 'total' => Mage::helper('sales')->__('Total Amt'), 'shipping' => Mage::helper('sales')->__('Shipping'), 'cod_amount' => Mage::helper('sales')->__('Cod Amount'), 'mode' => Mage::helper('sales')->__('Mode'), 'courier' => Mage::helper('sales')->__('Courier'), 'tracking' => Mage::helper('sales')->__('Tracking')));
         $content = $headers->toString($template) . "\n";
         foreach ($invoices as $invoice) {
             // Get order data
             $order = Mage::getModel('sales/order')->load($invoice->getOrderId());
             $payment = $order->getPayment();
             $invoiceData = array('increment_id' => $invoice->getIncrementId(), 'order_id' => $order->getIncrementId(), 'created_at' => $invoice->getCreatedAt(), 'items' => $invoice->getTotalQty());
             // Get Shipping
             $shipping = $order->getShippingAddress();
             $shippingData = array('shipping_name' => $shipping->getFirstname() . " " . $shipping->getLastname(), 'shipping_address1' => implode("\n", $shipping->getStreet()), 'shipping_city' => $shipping->getCity(), 'shipping_state' => $shipping->getRegion(), 'shipping_zip' => $shipping->getPostcode(), 'shipping_phone' => $shipping->getTelephone());
             // Get order stuff
             $order = $invoice->getOrder();
             $payment = $order->getPayment();
             $shipments = Mage::getResourceModel('sales/order_shipment_collection')->addAttributeToSelect('*')->setOrderFilter($order->getId())->setOrder('created_at', 'ASC')->load();
             foreach ($shipments as $shipment) {
             }
             $basic = $invoice->getBaseGrandTotal() - $invoice->getShippingAmount() - $invoice->getBaseTaxAmount();
             $rates = Mage::getModel('sales/order_tax')->getCollection()->loadByOrder($order)->toArray();
             if ($rates['totalRecords']) {
                 $rateCode = $rates['items'][0]['code'];
             } else {
                 $rateCode = "UNKNOWN";
             }
             $orderData = array('tax_rate' => $basic ? round($invoice->getBaseTaxAmount() / $basic * 100, 2) : 0, 'tax_type' => $rateCode, 'basic' => $basic, 'tax' => $invoice->getBaseTaxAmount(), 'total' => $invoice->getBaseGrandTotal() - $invoice->getShippingAmount(), 'shipping' => $invoice->getBaseShippingAmount(), 'cod_amount' => $invoice->getBaseGrandTotal(), 'mode' => $payment->getMethod());
             $tracks = array();
             $trackingData = array();
             if ($shipment) {
                 $tracks = $shipment->getAllTracks();
             }
             if (count($tracks)) {
                 foreach ($tracks as $track) {
                     $CarrierCode = $track->getCarrierCode();
                     if ($CarrierCode != 'custom') {
                         $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode);
                         $carrierTitle = $carrier->getConfigData('title');
                     } else {
                         $carrierTitle = Mage::helper('sales')->__('Custom Value');
                     }
                     $trackingData = array('courier' => $track->getTitle(), 'tracking' => $track->getNumber());
                     break;
                 }
             }
             $allData = new Varien_Object();
             $allData->setData(array_merge($invoiceData, $shippingData, $orderData, $trackingData));
             $content .= $allData->toString($template) . "\n";
         }
         return $this->_prepareDownloadResponse('invoice_export.csv', $content);
     }
     $this->_redirect('*/*/');
 }
Example #5
0
 public function render(Varien_Object $row)
 {
     $html = '<small>' . $row->toString() . '</small>';
     return $html;
 }
Example #6
0
 public function exportlogisticsAction()
 {
     $shipmentIds = $this->getRequest()->getPost('shipment_ids');
     if (!empty($shipmentIds)) {
         $shipments = Mage::getResourceModel('sales/order_shipment_collection')->addAttributeToSelect('*')->addAttributeToFilter('entity_id', array('in' => $shipmentIds))->load();
         $template = '"{{increment_id}}","{{order_id}}","{{order_created_at}}","{{shipping_name}}","{{created_at}}","{{tracking}}","{{courier}}","{{qty}}","{{product_name}}","{{sku}}","{{short_description}}","{{price}}","{{shipping_address1}}","{{shipping_city}}","{{shipping_state}}","{{shipping_zip}}","{{shipping_phone}}","{{total}}","{{shipping}}","{{cod_amount}}","{{mode}}"';
         $headers = new Varien_Object(array('increment_id' => Mage::helper('sales')->__('Sr. No.'), 'order_id' => Mage::helper('sales')->__('Order No.'), 'order_created_at' => Mage::helper('sales')->__('Order Date'), 'shipping_name' => Mage::helper('sales')->__('Customer Name'), 'created_at' => Mage::helper('sales')->__('Dispatch Date'), 'tracking' => Mage::helper('sales')->__('AWB No.'), 'courier' => Mage::helper('sales')->__('Couriers vendor name'), 'qty' => Mage::helper('sales')->__('Qty'), 'product_name' => Mage::helper('sales')->__('Product Name'), 'sku' => Mage::helper('sales')->__('Product SKU'), 'short_description' => Mage::helper('sales')->__('Supplier Code'), 'price' => Mage::helper('sales')->__('Price'), 'shipping_address1' => Mage::helper('sales')->__('Shipping Add'), 'shipping_city' => Mage::helper('sales')->__('Shipping City'), 'shipping_state' => Mage::helper('sales')->__('Shipping State'), 'shipping_zip' => Mage::helper('sales')->__('Shipping Zip'), 'shipping_phone' => Mage::helper('sales')->__('Shipping Tel. No.'), 'total' => Mage::helper('sales')->__('Amount'), 'shipping' => Mage::helper('sales')->__('Shipping Charge'), 'cod_amount' => Mage::helper('sales')->__('COD Charge'), 'mode' => Mage::helper('sales')->__('Mode')));
         $content = $headers->toString($template) . "\n";
         foreach ($shipments as $shipment) {
             // Get order data
             $order = Mage::getModel('sales/order')->load($shipment->getOrderId());
             //Mage::log($productData);
             $payment = $order->getPayment();
             // Get Shipping
             $shipping = $order->getShippingAddress();
             $invoiceData = array('increment_id' => $shipment->getIncrementId(), 'order_id' => $order->getIncrementId(), 'order_created_at' => $order->getCreatedAt(), 'shipping_name' => $shipping->getFirstname() . " " . $shipping->getLastname(), 'created_at' => $shipment->getCreatedAt());
             $remove = array(",", "'", '"');
             $shippingData = array('shipping_address1' => (string) str_replace($remove, '', implode("\n", $shipping->getStreet())), 'shipping_city' => $shipping->getCity(), 'shipping_state' => $shipping->getRegion(), 'shipping_zip' => $shipping->getPostcode(), 'shipping_phone' => $shipping->getTelephone());
             $productContent = "";
             $i = 0;
             foreach ($order->getAllItems() as $item) {
                 if ($item->getParentItem()) {
                     continue;
                 }
                 // get product
                 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
                 //Mage::log($item->getSku());
                 if ($i == 0) {
                     $productData = array('qty' => $item->getQtyOrdered(), 'product_name' => $product->getName(), 'sku' => $product->getSku(), 'short_description' => trim($product->getShortDescription()), 'price' => $item->getPrice());
                 } else {
                     $otherProductData = array('qty' => $item->getQtyOrdered(), 'product_name' => $product->getName(), 'sku' => $product->getSku(), 'short_description' => trim($product->getShortDescription()), 'price' => $item->getPrice());
                     $tempData = new Varien_Object();
                     $tempData->setData($otherProductData);
                     $productContent .= $tempData->toString($template) . "\n";
                 }
                 $i++;
             }
             //Mage::log($item);
             // Get order stuff
             $order = $shipment->getOrder();
             $payment = $order->getPayment();
             $shipments = Mage::getResourceModel('sales/order_shipment_collection')->addAttributeToSelect('*')->setOrderFilter($order->getId())->setOrder('created_at', 'ASC')->load();
             foreach ($shipments as $shipment) {
             }
             $basic = $shipment->getBaseGrandTotal() - $shipment->getShippingAmount() - $shipment->getBaseTaxAmount();
             $rates = Mage::getModel('sales/order_tax')->getCollection()->loadByOrder($order)->toArray();
             if ($rates['totalRecords']) {
                 $rateCode = $rates['items'][0]['code'];
             } else {
                 $rateCode = "UNKNOWN";
             }
             $orderData = array('total' => $order->getBaseGrandTotal(), 'shipping' => $order->getBaseShippingAmount(), 'cod_amount' => $order->getCodFee(), 'mode' => $payment->getMethod());
             //Mage::log($payment->getFees());
             $tracks = array();
             $trackingData = array();
             if ($shipment) {
                 $tracks = $shipment->getAllTracks();
             }
             if (count($tracks)) {
                 foreach ($tracks as $track) {
                     $CarrierCode = $track->getCarrierCode();
                     if ($CarrierCode != 'custom') {
                         $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode);
                         $carrierTitle = $carrier->getConfigData('title');
                     } else {
                         $carrierTitle = Mage::helper('sales')->__('Custom Value');
                     }
                     $trackingData = array('courier' => $track->getTitle(), 'tracking' => $track->getNumber());
                     break;
                 }
             }
             $allData = new Varien_Object();
             $allData->setData(array_merge($invoiceData, $trackingData, $productData, $shippingData, $orderData));
             $content .= $allData->toString($template) . "\n" . $productContent;
         }
         return $this->_prepareDownloadResponse('shipment_export.csv', $content);
     }
     $this->_redirect('*/*/');
 }
 public function exportPostAction($data)
 {
     $headers = new Varien_Object(array('ID' => Mage::helper('inventorypurchasing')->__('ID'), 'Name' => Mage::helper('inventorypurchasing')->__('Name'), 'SKU' => Mage::helper('inventorypurchasing')->__('SKU'), 'Cost' => Mage::helper('inventorypurchasing')->__('Cost'), 'Price' => Mage::helper('inventorypurchasing')->__('Price'), 'Warehouse' => Mage::helper('inventorypurchasing')->__('Warehouse'), 'Supplyneeds' => Mage::helper('inventorypurchasing')->__('Supplyneeds'), 'Supplier' => Mage::helper('inventorypurchasing')->__('Supplier')));
     $template = '"{{ID}}","{{Name}}","{{SKU}}","{{Cost}}","{{Price}}","{{Supplyneeds}}","{{Warehouse}}","{{Supplier}}"';
     $content = $headers->toString($template);
     if ($data['product_list']) {
         $info = array();
         $list = explode(';', $data['product_list']);
         $arr = Mage::helper('inventoryplus/supplyneeds')->filterList($list);
         foreach ($arr as $productId => $qty) {
             $product = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', $productId)->addAttributeToSelect('*')->getFirstItem();
             $warehouse = Mage::getModel('inventoryplus/warehouse')->getCollection()->addFieldToFilter('warehouse_id', $data['warehouse_select'])->getFirstItem()->getName();
             $supplier = Mage::getModel('inventorypurchasing/supplier')->getCollection()->addFieldToFilter('supplier_id', $data['supplier_select'])->getFirstItem()->getName();
             $cost = Mage::getModel('inventorypurchasing/supplier_product')->getCollection()->addFieldToFilter('product_id', $productId)->getFirstItem()->getCost();
             $info['ID'] = $productId;
             $info['Name'] = $product->getName();
             $info['SKU'] = $product->getSku();
             $info['Cost'] = $cost;
             $info['Price'] = $product->getPrice();
             $info['Supplyneeds'] = $qty;
             $info['Warehouse'] = $warehouse;
             $info['Supplier'] = $supplier;
             $csv_content = new Varien_Object($info);
             $content .= "\n";
             $content .= $csv_content->toString($template);
         }
     }
     $this->_prepareDownloadResponse('supplyneeds.csv', $content);
 }