/**
  * @param $p_version_id
  * @param $work_package
  * @param $chapter_prefix
  * @param $chapter_suffix
  * @param $option_show_duration
  * @param $detail_flag
  * @param $print_flag
  */
 public function process_chapter($p_version_id, $work_package, $chapter_prefix, $chapter_suffix, $option_show_duration, $detail_flag, $print_flag)
 {
     $specmanagement_database_api = new specmanagement_database_api();
     if ($detail_flag) {
         $chapter_duration = $specmanagement_database_api->get_workpackage_duration($p_version_id, $work_package);
         $this->print_chapter_document($chapter_prefix, $chapter_suffix, $option_show_duration, $chapter_duration);
     } else {
         $this->print_chapter_directory($print_flag, $chapter_suffix, $chapter_prefix, null, null, true);
     }
 }
/**
 * @param $pdf
 * @param $p_version_id
 * @param $work_packages
 * @param $no_work_package_bug_ids
 * @return mixed
 */
function generate_expenses_overview(PDF $pdf, $p_version_id, $work_packages, $no_work_package_bug_ids)
{
    $specmanagement_database_api = new specmanagement_database_api();
    $document_duration = 0;
    $table_column_widths = array(95, 95);
    $header = array(plugin_lang_get('bug_view_specification_wpg'), plugin_lang_get('bug_view_planned_time') . ' ( ' . plugin_lang_get('editor_duration_unit') . ')');
    /** Head */
    $pdf->SetFont('Arial', 'B', 12);
    for ($head_column_index = 0; $head_column_index < count($header); $head_column_index++) {
        $pdf->Cell($table_column_widths[$head_column_index], 7, $header[$head_column_index], 1, 0, 'C');
    }
    $pdf->SetFont('Arial', '', 12);
    $pdf->Ln();
    /** Body */
    if ($work_packages != null) {
        $document_duration = 0;
        foreach ($work_packages as $work_package) {
            /** go to next record, if work package is empty */
            if (strlen($work_package) == 0) {
                continue;
            }
            $duration = $specmanagement_database_api->get_workpackage_duration($p_version_id, $work_package);
            if (is_null($duration)) {
                $duration = 0;
            }
            $document_duration += $duration;
            $pdf->Cell($table_column_widths[0], 6, $work_package, 'LR');
            $pdf->Cell($table_column_widths[1], 6, $duration, 'LR', 0, 0);
            $pdf->Ln();
            $pdf->Cell(array_sum($table_column_widths), 0, '', 'T');
            $pdf->Ln();
        }
    }
    if (count($no_work_package_bug_ids) > 0) {
        $sum_no_work_package_bug_duration = 0;
        foreach ($no_work_package_bug_ids as $no_work_package_bug_id) {
            $no_work_package_bug_duration = $specmanagement_database_api->get_bug_duration($no_work_package_bug_id);
            if (!is_null($no_work_package_bug_duration)) {
                $sum_no_work_package_bug_duration += $no_work_package_bug_duration;
            }
        }
        $document_duration += $sum_no_work_package_bug_duration;
        $pdf->Cell($table_column_widths[0], 6, utf8_decode(plugin_lang_get('editor_no_workpackage')), 'LR');
        $pdf->Cell($table_column_widths[1], 6, $sum_no_work_package_bug_duration, 'LR', 0, 0);
        $pdf->Ln();
        $pdf->Cell(array_sum($table_column_widths), 0, '', 'T');
        $pdf->Ln();
    }
    $pdf->SetFont('Arial', 'B', 12);
    $pdf->Cell($table_column_widths[0], 6, plugin_lang_get('editor_expenses_overview_sum') . ':', 'LR');
    $pdf->Cell($table_column_widths[1], 6, $document_duration, 'LR', 0, 0);
    $pdf->Ln();
    $pdf->SetFont('Arial', '', 12);
    $pdf->Cell(array_sum($table_column_widths), 0, '', 'T');
    return $pdf;
}