1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| public function getPdf($orders = array())
{
$this->_beforeGetPdf();
try{
$this->_initRenderer('dispatch');
}catch(Exception $e){
Mage::Log($e->getMessage());
}
$pdf = new Zend_Pdf();
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
/* Create resume */
/* Add new table head */
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$this->y = 800;
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER), 7);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 570, $this->y-15);
$this->y -=10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawText(Mage::helper('sales')->__('Num. commande'), 35, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Quantite'), 100, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Article'), 140, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('SKU'), 400, $this->y, 'UTF-8');
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$this->y -=20;
$products_orders = array();
$products_name_1 = $products_name_2 = $products_name_3 = $products_name_4 = $products_name_other = Array();
$products_orders_1 = $products_orders_2 = $products_orders_3 = $products_orders_4 = $products_orders_other = Array();
$products_orders_qty_1 = $products_orders_qty_2 = $products_orders_qty_3 = $products_orders_qty_4 = $products_orders_other = Array();
/*Generation des tableaux de correspondance
Produits des commandes $products_orders = array();
qty : $products_orders_qty = array();
Tri : products_orders_type = array();
*/
foreach ($orders as $orderId){
$order = Mage::getModel('sales/order')->load($orderId);
$orderNumber = $orderId;
$OrderIdTmp = $order->getIncrementId();
foreach ($order->getAllItems() as $item){
if ($item->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE ){
$productId = $item->getProductId();
$aryproduct = Mage::getModel('catalog/product')->load($productId);
$OrderIdTmp = $order->getIncrementId();
if(isset($products_orders[$productId]) ){
$OrderIdTmp = $products_orders[$productId].';'.$order->getIncrementId();
}
#recupérer des tableaux de produits par gamme de produits
$option = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'gamme_produit', "0");
if ($option == "984")
{
$products_orders_1[$productId] = $OrderIdTmp;
$products_name_1[$productId] = $aryproduct->getName();
$products_orders_qty_1[$productId.'_'.$order->getIncrementId()] = $item->getQtyOrdered();
$products_orders_qty_1[$productId.'_'.$order->getIncrementId()] = substr($products_orders_qty_1[$productId.'_'.$order->getIncrementId()], 0, strpos($products_orders_qty_1[$productId.'_'.$order->getIncrementId()], "."));
}
else if ($option == "985")
{
$products_orders_2[$productId] = $OrderIdTmp;
$products_name_2[$productId] = $aryproduct->getName();
$products_orders_qty_2[$productId.'_'.$order->getIncrementId()] = $item->getQtyOrdered();
$products_orders_qty_2[$productId.'_'.$order->getIncrementId()] = substr($products_orders_qty_2[$productId.'_'.$order->getIncrementId()], 0, strpos($products_orders_qty_2[$productId.'_'.$order->getIncrementId()], "."));
}
else if ($option == "983")
{
$products_orders_3[$productId] = $OrderIdTmp;
$products_name_3[$productId] = $aryproduct->getName();
$products_orders_qty_3[$productId.'_'.$order->getIncrementId()] = $item->getQtyOrdered();
$products_orders_qty_3[$productId.'_'.$order->getIncrementId()] = substr($products_orders_qty_3[$productId.'_'.$order->getIncrementId()], 0, strpos($products_orders_qty_3[$productId.'_'.$order->getIncrementId()], "."));
}
else if ($option == "982")
{
$products_orders_4[$productId] = $OrderIdTmp;
$products_name_4[$productId] = $aryproduct->getName();
$products_orders_qty_4[$productId.'_'.$order->getIncrementId()] = $item->getQtyOrdered();
$products_orders_qty_4[$productId.'_'.$order->getIncrementId()] = substr($products_orders_qty_4[$productId.'_'.$order->getIncrementId()], 0, strpos($products_orders_qty_4[$productId.'_'.$order->getIncrementId()], "."));
}
else {
$products_orders_other[$productId] = $OrderIdTmp;
$products_name_other[$productId] = $aryproduct->getName();
$products_orders_qty_other[$productId.'_'.$order->getIncrementId()] = $item->getQtyOrdered();
$products_orders_qty_other[$productId.'_'.$order->getIncrementId()] = substr($products_orders_qty_other[$productId.'_'.$order->getIncrementId()], 0, strpos($products_orders_qty_other[$productId.'_'.$order->getIncrementId()], "."));
}
}
}
}
// Tri par ordre alphabetique selon les valeurs pour tous les tableaux
asort($products_name_1);
asort($products_name_2);
asort($products_name_3);
asort($products_name_4);
asort($products_name_other);
// Combinaison des deux tableaux en gardant le tri alphabetique
$products_orders_1 = array_replace_recursive ($products_name_1, $products_orders_1);
$products_orders_2 = array_replace_recursive ($products_name_2, $products_orders_2);
$products_orders_3 = array_replace_recursive ($products_name_3, $products_orders_3);
$products_orders_4 = array_replace_recursive ($products_name_4, $products_orders_4);
$products_orders_other = array_replace_recursive ($products_name_other, $products_orders_other);
################################
#
# Regroupement des tableaux en deux tableaux
#
#
/*Zend_Debug::dump($products_orders_1);
Zend_Debug::dump($products_orders_2);
Zend_Debug::dump($products_orders_3);
Zend_Debug::dump($products_orders_4);*/
$products_orders = $products_orders_1 + $products_orders_2 + $products_orders_3 + $products_orders_4 + $products_orders_other;
$products_orders_qty = $products_orders_qty_1 + $products_orders_qty_2 + $products_orders_qty_3 + $products_orders_qty_4 + $products_orders_qty_other; |
Partager