diff --git a/report_supply_status.php b/report_supply_status.php index adcb23cb8..195283a4c 100644 --- a/report_supply_status.php +++ b/report_supply_status.php @@ -5,118 +5,91 @@ require_once( "db.inc.php" ); require_once( "facilities.inc.php" ); - + if(!$person->ReadAccess){ // No soup for you. header('Location: '.redirect()); exit; } - /* Version 1.0 of this report has no selectable parameters - you just get a complete dump */ - - $mpdf=new \Mpdf\Mpdf(['tempDir'=>sys_get_temp_dir(),'mode'=>'s']); - $mpdf->SetAuthor($config->ParameterArray["OrgName"]); - $mpdf->SetDisplayMode('fullpage'); - $mpdf->useActiveForms = true; - $mpdf->SetTitle($config->ParameterArray["OrgName"] . " " . __("Supply Status Report")); + /* Version 2.0 of this report uses PhpSpreadsheet instead of mPDF */ + + $xl = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + + $xl->getProperties()->setCreator($config->ParameterArray["OrgName"]); + $xl->getProperties()->setLastModifiedBy("openDCIM"); + $xl->getProperties()->setTitle($config->ParameterArray["OrgName"] . " " . __("Supply Status Report")); + $xl->getProperties()->setSubject(__("Supply Status Report")); + + $xl->setActiveSheetIndex(0); + $currSheet = $xl->getActiveSheet(); + $currSheet->setTitle(__("Supply Status")); + + // Header row + $currSheet->setCellValue('A1', __("Part Number")); + $currSheet->setCellValue('B1', __("Part Name")); + $currSheet->setCellValue('C1', __("Min Qty")); + $currSheet->setCellValue('D1', __("Max Qty")); + $currSheet->setCellValue('E1', __("On Hand")); + $currSheet->setCellValue('F1', __("Location")); + $currSheet->setCellValue('G1', __("Location Count")); + + // Bold header row + $currSheet->getStyle('A1:G1')->getFont()->setBold(true); + $currSheet->getStyle('A1:G1')->getFill() + ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) + ->getStartColor()->setRGB('EEEEEE'); $sup = new Supplies(); $bin = new SupplyBin(); $bc = new BinContents(); - + $SupplyList = $sup->GetSuppliesList(); - - $html = ' - - - - - - - - -

'.__("Supplies Status Report").' - - - - - - - - - - - -'; + + $row = 2; foreach ( $SupplyList as $Supply ) { - $html .= sprintf('\n', - $Supply->PartNum, $Supply->PartName, $Supply->MinQty, $Supply->MaxQty, Supplies::GetSupplyCount($Supply->SupplyID) ); - + $onHand = Supplies::GetSupplyCount($Supply->SupplyID); + + $currSheet->setCellValue("A{$row}", $Supply->PartNum); + $currSheet->setCellValue("B{$row}", $Supply->PartName); + $currSheet->setCellValue("C{$row}", $Supply->MinQty); + $currSheet->setCellValue("D{$row}", $Supply->MaxQty); + $currSheet->setCellValue("E{$row}", $onHand); + + // Highlight row if on hand is below minimum + if ($onHand < $Supply->MinQty) { + $currSheet->getStyle("A{$row}:G{$row}")->getFill() + ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) + ->getStartColor()->setRGB('F28A8C'); + } + $bc->SupplyID = $Supply->SupplyID; $binList = $bc->FindSupplies(); - + foreach ( $binList as $sb ) { $bin->BinID = $sb->BinID; $bin->GetBin(); - - $html .= sprintf( '\n', __("Location"), $bin->Location, $sb->Count ); + + $currSheet->setCellValue("F{$row}", $bin->Location); + $currSheet->setCellValue("G{$row}", $sb->Count); + $row++; } - } - - $html .= ' - - - -
'.__("Part Number").''.__("Part Name").''.__("Min Qty").''.__("Max Qty").''.__("On Hand").'
%s%s%d%d%d
 %s: %s  %d
 
- - -'; -$mpdf->WriteHTML($html); + if (empty($binList)) { + $row++; + } + } -$mpdf->Output(); exit; + foreach( range( 'A', 'G' ) as $col ) { + $currSheet->getColumnDimension($col)->setAutoSize( true ); + } + $currSheet->calculateColumnWidths(); -exit; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header( sprintf( "Content-Disposition: attachment;filename=\"opendcim-supply-status-%s.xlsx\"", date( "YmdHis" ) ) ); + $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($xl); + $writer->save('php://output'); + exit; ?>