<?php BsHtml::$formLayoutHorizontalLabelClass = ''; $form->layout = BsHtml::FORM_LAYOUT_VERTICAL; ?> <div class="modal-body"> <div class="row"> <div class="col-md-6"> <?php echo $form->textFieldControlGroup($model, 'name', array('size' => 45, 'maxlength' => 45)); ?> <?php echo $form->dropDownListControlGroup($model, 'packing_station_id', CHtml::listData(PackingStation::model()->findAll(), 'id', 'name'), array('class' => 'chosen')); ?> <?php echo $form->textFieldControlGroup($model, 'value', array('size' => 7, 'maxlength' => 7)); ?> <?php echo $form->dropDownListControlGroup($model, 'unit', $model->getUnitList()); ?> <?php echo $form->imageField($model, 'image'); ?> <?php echo $form->textAreaControlGroup($model, 'description'); ?> </div> <div class="col-md-6"> <?php
/** * Generate a packing list spreadsheet for a given date_id */ public function actionGeneratePackingList($date) { $phpExcelPath = Yii::getPathOfAlias('boxomatic.external.PHPExcel'); $PackingStations = PackingStation::model()->findAll(); $tablePrefix = SnapUtil::config('boxomatic/tablePrefix'); $lineIndex = 1; //disable Yii's Autoload because it messes with PHPExcel's autoloader spl_autoload_unregister(array('YiiBase', 'autoload')); include $phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); spl_autoload_register(array('YiiBase', 'autoload')); foreach ($PackingStations as $PS) { $sql = ' SELECT SUM(item_quantity) as total, GROUP_CONCAT(DISTINCT t.box_id ORDER BY t.box_id DESC) AS box_ids, GROUP_CONCAT(DISTINCT `box_item_id` ORDER BY `BoxItems`.box_id DESC) as box_item_ids, `BoxItems`.`box_item_id`, `BoxItems`.`item_name`, `BoxItems`.`item_unit`, `Supplier`.`name` #`PackingStation`.`name` as packing_station FROM `' . $tablePrefix . 'boxes` `t` LEFT OUTER JOIN `' . $tablePrefix . 'user_boxes` `UserBoxes` ON (`UserBoxes`.`box_id`=`t`.`box_id`) LEFT OUTER JOIN `' . $tablePrefix . 'box_items` `BoxItems` ON (`BoxItems`.`box_id`=`t`.`box_id`) LEFT OUTER JOIN `' . $tablePrefix . 'suppliers` `Supplier` ON (`BoxItems`.`supplier_id`=`Supplier`.`id`) INNER JOIN `' . $tablePrefix . 'supplier_products` `SupplierProduct` ON (`BoxItems`.`supplier_product_id`=`SupplierProduct`.`id`) INNER JOIN `' . $tablePrefix . 'packing_stations` `PackingStation` ON (`PackingStation`.`id`=`SupplierProduct`.`packing_station_id`) WHERE ( delivery_date_id=' . $date . ' AND BoxItems.packing_station_id = ' . $PS->id . ' AND user_box_id is not null AND ( UserBoxes.status=' . UserBox::STATUS_APPROVED . ' OR UserBoxes.status=' . UserBox::STATUS_DELIVERED . ' ) ) GROUP BY name,item_name ORDER BY name; '; $connection = Yii::app()->db; $command = $connection->createCommand($sql); $dataReader = $command->query(); $items = $dataReader->readAll(); $DateBoxes = Box::model()->with('BoxSize')->findAll(array('condition' => 'delivery_date_id = ' . $date, 'order' => 'box_size_name DESC')); $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, $PS->name); $objPHPExcel->getActiveSheet()->getStyle("A{$lineIndex}")->applyFromArray(array("font" => array("bold" => true, "size" => 16))); $lineIndex++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, 'Supplier'); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $lineIndex, 'Item'); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $lineIndex, 'Total Quantity'); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $lineIndex, 'Unit'); if (empty($items)) { $objPHPExcel->getActiveSheet()->getStyle("A{$lineIndex}:D{$lineIndex}")->applyFromArray(array("font" => array("bold" => true))); $lineIndex++; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, 'No box items for this packing station.'); $lineIndex += 2; //continue; } else { //$lineIndex++; $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $boxIds = explode(',', $items[0]['box_ids']); $pos = 4; foreach ($DateBoxes as $n => $Box) { $custCount = $Box->customerCount; $objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . $lineIndex, $Box->BoxSize->box_size_name . ' (' . $custCount . ')'); $objPHPExcel->getActiveSheet()->getColumnDimension($alpha[$pos])->setAutoSize(true); $pos++; } $objPHPExcel->getActiveSheet()->getStyle("A{$lineIndex}:" . $alpha[$pos] . $lineIndex)->applyFromArray(array("font" => array("bold" => true))); $lineIndex++; foreach ($items as $item) { $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, $item['name']); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $lineIndex, $item['item_name']); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $lineIndex, $item['total']); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $lineIndex, $item['item_unit']); $boxIds = explode(',', $item['box_ids']); $boxItemIds = explode(',', $item['box_item_ids']); $pos = 4; foreach ($DateBoxes as $Box) { $BoxItem = null; $biPos = false; $biPos = array_search($Box->box_id, $boxIds); if ($biPos !== false) { $BoxItem = BoxItem::model()->findByAttributes(array('box_id' => $Box->box_id, 'box_item_id' => $boxItemIds[$biPos])); } $quantity = $BoxItem && !empty($BoxItem->item_quantity) ? $BoxItem->item_quantity : '0'; $objPHPExcel->getActiveSheet()->SetCellValue($alpha[$pos] . $lineIndex, $quantity); $pos++; } $lineIndex++; } $lineIndex++; } //Extras $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, 'EXTRAS'); $objPHPExcel->getActiveSheet()->getStyle("A{$lineIndex}")->applyFromArray(array("font" => array("bold" => true))); $lineIndex++; $CDDs = Order::model()->with('Extras')->findAllByAttributes(array('delivery_date_id' => $date), 'packing_station_id = ' . $PS->id); if (empty($CDDs)) { $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex++, 'No extras for this packing station'); } foreach ($CDDs as $CDD) { //Create a string that show what boxes this customer has ordered.. if any. $orderedBoxes = array(); $CustBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $CDD->user_id), 'delivery_date_id=' . $date); foreach ($CustBoxes as $CustBox) { $orderedBoxes[] = $CustBox->Box->BoxSize->box_size_name; } $orderedString = ' (No Boxes Ordered)'; if (!empty($orderedBoxes)) { $orderedString = ' (' . implode(',', $orderedBoxes) . ')'; } $User = $CDD->User; $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, $User ? $User->bfb_id . ' - ' . $User->full_name . $orderedString : 'No Customer Name!'); $objPHPExcel->getActiveSheet()->getStyle("A{$lineIndex}")->applyFromArray(array("font" => array("bold" => true))); $lineIndex++; foreach ($CDD->Extras as $Extra) { $objPHPExcel->getActiveSheet()->SetCellValue('A' . $lineIndex, $Extra->supplierPurchase->supplierProduct->Supplier->name); $objPHPExcel->getActiveSheet()->SetCellValue('B' . $lineIndex, $Extra->name); $objPHPExcel->getActiveSheet()->SetCellValue('C' . $lineIndex, $Extra->quantity); $objPHPExcel->getActiveSheet()->SetCellValue('D' . $lineIndex, $Extra->unit); $lineIndex++; } $lineIndex++; } $lineIndex++; } $objPHPExcel->getActiveSheet()->getColumnDimension("A")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("B")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("C")->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension("D")->setAutoSize(true); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Packing List'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="packing-list-' . date('Ymd') . '"'); $objWriter->save('php://output'); exit; }
echo $BoxItemsContent->item_name; } $totalQuantity = BoxItem::totalQuantity($BoxItemsContent->box_item_ids); $totalValue = $BoxItemsContent->item_value * $totalQuantity; if ($BoxItemsContent->SupplierProduct && $BoxItemsContent->item_name != CHtml::value($BoxItemsContent, 'SupplierProduct.name')) { echo CHtml::link('<i class="fi fi-page-copy"></i>', array('boxItem/copyProductName', 'id' => $BoxItemsContent->box_item_id), array('title' => 'Product name should be: ' . CHtml::value($BoxItemsContent, 'SupplierProduct.name'))); } ?> </td> <td> <?php if (!empty($BoxItemsContent->supplier_product_id)) { echo CHtml::value($BoxItemsContent, 'SupplierProduct.PackingStation.name'); echo CHtml::hiddenField('bc[' . $key . '][packing_station_id]', CHtml::value($BoxItemsContent, 'SupplierProduct.packing_station_id')); } else { echo CHtml::dropDownList('bc[' . $key . '][packing_station_id]', CHtml::value($BoxItemsContent, 'SupplierProduct.packing_station_id'), CHtml::listData(PackingStation::model()->findAll(), 'id', 'name')); } ?> </td> <td class="itemValue"> <?php echo CHtml::textField('bc[' . $key . '][item_value]', $BoxItemsContent->item_value, array('class' => 'currency')); ?> <?php echo CHtml::dropDownList('bc[' . $key . '][item_unit]', $BoxItemsContent->item_unit, SnapUtil::config('boxomatic/itemUnits')); ?> </td> <?php $key2 = 0; foreach ($DeliveryDateBoxes as $DeliveryDateBoxMerged) {
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return PackingStation the loaded model * @throws CHttpException */ public function loadModel($id) { $model = PackingStation::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }