Пример #1
0
 function get_user()
 {
     // echo sesUser()->team_ids;
     // echo sesCompany(0)->code;
     // echo sesCompany(TRUE)->code;
     // echo sesCompany();
     echo sesCompany()->id;
     // echo $this->session->userdata('company_id');
     // echo sesCompany(0);
 }
 function export_to_pdf($qry, $filename, $paper_size = 'A4', $is_portrait = TRUE)
 {
     $ci = get_instance();
     $company = $ci->systems_model->getCompany_ById(sesCompany()->id);
     $ci->load->library('mpdf');
     //=====================================================================================================\\
     if ($paper_size == 'F4') {
         if ($is_portrait) {
             $paper_setup = array(215.9, 330.2);
         } else {
             $paper_setup = array(330.2, 215.9);
         }
     }
     if ($paper_size == 'A3') {
         if ($is_portrait) {
             $paper_setup = array(297, 420);
         } else {
             $paper_setup = array(420, 297);
         }
     }
     $mpdf = new mPDF('utf-8', $paper_setup, '', '', 15, 15, 35, 16, 10, 10);
     $mpdf->SetTitle("Example");
     $mpdf->SetAuthor("Example");
     $logo_path = base_url() . "assets/images/logo-{$company->code}.png";
     $title = join(" ", explode("_", strtoupper($filename)));
     $html_head = "<html><head>\n\t\t<style>\n\t\t.logo \t{ float: left; margin-top: -80px; width: 100px; height: 100px; }\n\t\tbody  \t{ font-family: Courier; font-size: 10pt; }\n\t\ttd \t\t{ vertical-align: top; }\n\t\t.top-border \t{ border-top: 0.1mm solid #000000; }\n\t\t.bottom-border \t{ border-bottom: 0.1mm solid #000000; }\n\t\t.left-border \t{ border-left: 0.1mm solid #000000; }\n\t\t.right-border \t{ border-right: 0.1mm solid #000000; }\n\t\ttable thead td { \n\t\t\ttext-align: center;\n\t\t\tborder: 0.1mm solid #000000;\n\t\t\tborder-collapse: collapse;\n\t\t}\n\t\t.items td {\n\t\t\tborder-left: 0.1mm solid #000000;\n\t\t\tborder-right: 0.1mm solid #000000;\n\t\t}\n\t\t.items td.blanktotal {\n\t\t\tbackground-color: #FFFFFF;\n\t\t\tborder: 0mm none #000000;\n\t\t\tborder-top: 0.1mm solid #000000;\n\t\t\t/* border-right: 0.1mm solid #000000; */\n\t\t}\t\t\n\t\t.items td.totals {\n\t\t\ttext-align: right;\n\t\t\tborder: 0.1mm solid #000000;\n\t\t}\n\t\t</style>\n\t\t</head>\n\t\t<body>\n\t\t\n\t\t<!--mpdf\n\t\t<htmlpageheader name='myheader'>\n\t\t\t<div class='logo'><img src='{$logo_path}' width='100' /></div>\n\t\t\t<table width='100%'>\n\t\t\t\t<tr><td><center><h1>{$company->name}</h1></center></td></tr>\n\t\t\t\t<tr><td><center>|||</center></td></tr>\n\t\t\t\t<tr><td><center><h3>{$title}</h3></center></td></tr>\n\t\t\t</table>\n\t\t</htmlpageheader>\n\n\t\t<sethtmlpageheader name='myheader' value='on' show-this-page='1' />\n\t\tmpdf-->";
     $mpdf->WriteHTML($html_head);
     $mpdf->SetFooter("|Page {PAGENO} of {nb}|Printed @ " . date('d M Y H:i'));
     $header = "\n\t\t<table class='items' width='100%' style='margin-top: 1.25em; border-collapse: collapse;' cellpadding='8'>\n\t\t<thead>\n\t\t\t<tr>\n\t\t\t\t<td><strong>NO.</strong></td>";
     $fields = $qry->list_fields();
     $fields_count = count($fields);
     foreach ($fields as $field) {
         $header .= "<td><strong>{$field}</strong></td>";
     }
     $header .= "</tr>\n\t\t</thead>\n\t\t<tbody>";
     $mpdf->WriteHTML($header);
     if ($qry->num_rows() < 1) {
         crud_error(l('report_no_data'));
     }
     $num = 1;
     foreach ($qry->result() as $row) {
         $detail .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td align='right'>{$num}</td>\n\t\t\t\t\t";
         foreach ($fields as $field) {
             $detail .= "<td>" . $row->{$field} . "</td>";
         }
         /* foreach ($fields as $field) {
         				$detail .= "<td style='white-space: nowrap;>".$row->$field."</td>";
         			} */
         $detail .= "\n\t\t\t\t</tr>\n\t\t\t";
         $num++;
     }
     $mpdf->WriteHTML($detail);
     $fields_count = $fields_count + 1;
     $footer = "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=" . $fields_count . " class='blanktotal'>&nbsp;</td>\n\t\t\t\t</tr>\n\t\t\t\t</tbody>\n\t\t\t</table>";
     $mpdf->WriteHTML($footer);
     $mpdf->WriteHTML("</body></html>");
     // Sending headers to force the user to download the file
     header('Set-Cookie: fileDownload=true; path=/');
     // setcookie("fileDownload", "true", time() - 3600, "/");
     // setcookie("fileDownload", "true", time() - 3600);
     // $mpdf->Output();
     $mpdf->Output($filename . '.pdf', 'D');
 }