function print_category($iteration, $parent, $i) { $i++; global $rowxls, $objPHPExcel; echo 'row xls ' . $rowxls . '<br/>'; if ($iteration != null) { if (is_array($iteration[$parent])) { foreach ($iteration[$parent] as $iteration_) { print_r($iteration_); $sales_detail = find_sales($iteration_['id']); //print_r($sales_detail); if ($sales_detail['quantity'] > 0) { $rowxls++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowxls, ''); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowxls, ucfirst($iteration_['name'])); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowxls, $sales_detail['quantity']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowxls, ''); $objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowxls, number_format($sales_detail['subtotal'], 0, ',', '.')); if ($iteration[$iteration_['id']] == null) { $sales_items = find_sales_items($iteration_['id']); $row = 1; foreach ($sales_items as $sales_item) { $rowxls++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowxls, $sales_item['type_code']); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowxls, $sales_item['product_name'] . ' / ' . $sales_item["type_name"] . ' / ' . $sales_item["stock_name"]); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowxls, $sales_item['quantity']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowxls, number_format($sales_item['type_price'], 0, ',', '.')); $objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowxls, number_format($sales_item['subtotal'], 0, ',', '.')); $row++; } } } print_category($iteration, $iteration_['id'], $i); } } //isarray } else { $sales_items = find_sales_items($parent); $row = 1; foreach ($sales_items as $sales_item) { $rowxls++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowxls, $sales_item['type_code']); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowxls, $sales_item['product_name'] . ' / ' . $sales_item["type_name"] . ' / ' . $sales_item["stock_name"]); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowxls, $sales_item['quantity']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowxls, number_format($sales_item['type_price'], 0, ',', '.')); $objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowxls, number_format($sales_item['subtotal'], 0, ',', '.')); $row++; } } }
function print_category_xls($iteration, $parent, $i) { $i++; global $rowxls, $objPHPExcel; if (is_array($iteration[$parent])) { foreach ($iteration[$parent] as $iteration_) { //print_r($iteration_); $sales_detail = find_sales($iteration_['id']); //print_r($sales_detail); if ($sales_detail['quantity'] > 0) { $rowxls++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowxls, ''); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowxls, ucfirst($iteration_['name'])); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowxls, $sales_detail['quantity']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowxls, ''); $objPHPExcel->getActiveSheet()->SetCellValueExplicit('E' . $rowxls, price($sales_detail['subtotal']), PHPExcel_Cell_DataType::TYPE_STRING); if ($sales_detail['discount'] != 0) { $objPHPExcel->getActiveSheet()->SetCellValueExplicit('F' . $rowxls, "-" . price($sales_detail['discount']), PHPExcel_Cell_DataType::TYPE_STRING); } $objPHPExcel->getActiveSheet()->SetCellValueExplicit('G' . $rowxls, price($sales_detail['subtotal'] - $sales_detail['discount']), PHPExcel_Cell_DataType::TYPE_STRING); //format cell if ($i == 1) { $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'cccccc'))); } else { if ($i == 2) { $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'dddddd'))); } else { if ($i > 2) { $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A' . $rowxls . ':E' . $rowxls)->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => array('rgb' => 'eeeeee'))); } } } if ($iteration[$iteration_['id']] == null) { $sales_items = find_sales_items($iteration_['id']); $row = 1; foreach ($sales_items as $sales_item) { $rowxls++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowxls, $sales_item['type_code']); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowxls, $sales_item['product_name'] . ' / ' . $sales_item["type_name"] . ' / ' . $sales_item["stock_name"]); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowxls, $sales_item['quantity']); $objPHPExcel->getActiveSheet()->SetCellValueExplicit('D' . $rowxls, price($sales_item['item_price']), PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->SetCellValueExplicit('E' . $rowxls, price($sales_item['subtotal']), PHPExcel_Cell_DataType::TYPE_STRING); if ($sales_item['discount'] != 0) { $objPHPExcel->getActiveSheet()->SetCellValueExplicit('F' . $rowxls, "-" . price($sales_item['discount']), PHPExcel_Cell_DataType::TYPE_STRING); } $objPHPExcel->getActiveSheet()->SetCellValueExplicit('G' . $rowxls, price($sales_item['subtotal'] - $sales_item['discount']), PHPExcel_Cell_DataType::TYPE_STRING); $row++; } } } print_category_xls($iteration, $iteration_['id'], $i); } } //isarray }