public function attend($id = null)
 {
     require 'tcpdf.php';
     // 1. We'll need some info about this section, to print on the form
     $section = $this->Sections->get($id, ['contain' => ['Cohorts.Majors', 'Semesters', 'Subjects', 'Teachers']]);
     // 2. And we'll need some info about the students.
     /* @var \Cake\Database\Connection $connection */
     $connection = ConnectionManager::get('default');
     $query = "SELECT sid, fam_name, giv_name from students\n            left join cohorts  on students.cohort_id=cohorts.id\n            left join sections on cohorts.id=sections.cohort_id\n            where sections.id={$id} order by sid";
     $classRoster = $connection->execute($query)->fetchAll('assoc');
     // This query collects attendance info, in sid order. Other queries collect
     // other info, also in sid order. Be careful to ensure that each query contains
     // exactly the same students.
     // |--------------|--|
     // | students.sid |
     /* @var \Cake\Database\Connection $connection */
     $connection = ConnectionManager::get('default');
     $query = "select week, sid, itype_id, participate from interactions \nleft join clazzes on interactions.clazz_id=clazzes.id\nleft join sections on clazzes.section_id=sections.id\nleft join students on interactions.student_id=students.id\nwhere sections.id={$id} and clazzes.exam != 1";
     $interactionResults = $connection->execute($query)->fetchAll('assoc');
     // Now merge $attendResults and $classRoster into some useable format
     foreach ($interactionResults as $interaction) {
         foreach ($classRoster as $student_idx => $student) {
             if ($student['sid'] == $interaction['sid']) {
                 $w = $interaction['week'];
                 $widx = $w - 1;
                 // convert to zero based week
                 if ($interaction['itype_id'] == "1") {
                     $classRoster[$student_idx]['weeks'][$widx]['a'] = 1;
                 } else {
                     if ($interaction['itype_id'] == "4") {
                         $classRoster[$student_idx]['weeks'][$widx]['b'] = $interaction['participate'];
                     } else {
                         // Another kind of interaction type has been found.
                         // What should we do?
                     }
                 }
             } else {
                 // An interaction has been found for a student who's not really in this class.
                 // What should we do?
             }
         }
     }
     // The primary method of specifying position is to measure mm from the origin,
     // where the origin is at the upper-left corner of the paper, moving right increases x
     // and moving down increases y. We will also use a 2nd level of positioning, described
     // shortly, on top of this level one positioning.
     $pdf = new \tcpdf('L', 'mm', 'a4');
     $pdf->SetFont('cid0cs', '', 16, '', true);
     // remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->AddPage();
     $this->emitAttendForm($pdf, $section, $classRoster, 0);
     $pdf->AddPage();
     $this->emitAttendForm($pdf, $section, $classRoster, 30);
     $pdf->Output();
     $this->response->type('application/pdf');
     return $this->response;
 }
    public function generatePickList()
    {
        App::import('Helper', 'Soap');
        $SoapHelper = new SoapHelper(new View(null));
        $test = $this->request->data['Linnworksapis']['orderid'];
        $skus = explode("---", $test);
        asort($skus);
        $skus = array_count_values($skus);
        $this->autoRender = false;
        $this->layout = '';
        $data = array();
        $index = 0;
        foreach ($skus as $key => $value) {
            $getData = $SoapHelper->getOrderById($key);
            foreach ($getData->GetFilteredOrdersResponse->GetFilteredOrdersResult->Orders->Order as $order) {
                foreach ($order->OrderItems->OrderItem as $item) {
                    $data[$index]['Qty'] = $item->Qty;
                    $data[$index]['ItemTitle'] = $item->ItemTitle;
                    $data[$index]['binrack'] = $item->Binrack;
                    $data[$index]['barcode'] = $item->Barcode;
                    $data[$index]['category'] = $item->Category;
                    $data[$index]['ChannelSKU'] = $item->SKU;
                    $data[$index]['PostalServiceName'] = $getData->GetFilteredOrdersResponse->GetFilteredOrdersResult->Orders->Order->PostalServiceName;
                    $index++;
                }
            }
        }
        $json = json_encode($data);
        $arrays = json_decode($json, TRUE);
        $ind = 0;
        foreach ($arrays as $array) {
            $dataNew[$ind]['Qty'] = $array['Qty'][0];
            $dataNew[$ind]['ItemTitle'] = $array['ItemTitle'][0];
            $dataNew[$ind]['binrack'] = isset($array['binrack'][0]) ? $array['binrack'][0] : 'null';
            $dataNew[$ind]['barcode'] = isset($array['barcode'][0]) ? $array['barcode'][0] : 'null';
            $dataNew[$ind]['ChannelSKU'] = isset($array['ChannelSKU'][0]) ? $array['ChannelSKU'][0] : 'null';
            $dataNew[$ind]['PostalServiceName'] = $array['PostalServiceName'][0];
            $ind++;
        }
        /* get the duplicaate value */
        $duplicatedata = $dataNew;
        foreach ($dataNew as $dataNewOuter => $dataNewOutervalue) {
            foreach ($dataNew as $dataNewInner => $dataNewInnervalue) {
                if ($dataNewOutervalue['ChannelSKU'] === $dataNewInnervalue['ChannelSKU']) {
                    if ($dataNewOuter != $dataNewInner) {
                        $duplicateValue[$dataNewInner] = $dataNewInnervalue['ChannelSKU'];
                    }
                }
            }
        }
        if (isset($duplicateValue) && count($duplicateValue) > 0) {
            $a = array_unique($duplicateValue);
            $duplicateArray = $dataNew;
            foreach ($duplicateValue as $key => $value) {
                unset($dataNew[$key]);
            }
            sort($dataNew);
            $result = array_merge($dataNew, $a);
        } else {
            $result = $duplicatedata;
        }
        $e = 0;
        $r = 0;
        foreach ($result as $keyIndex => $keyValue) {
            $csvData[$r]['Qty'] = 0;
            foreach ($duplicatedata as $dupIndex => $dupValue) {
                if (isset($keyValue['ChannelSKU'])) {
                    if ($keyValue['ChannelSKU'] == $dupValue['ChannelSKU']) {
                        $csvData[$r]['Qty'] = $dupValue['Qty'];
                        $csvData[$r]['ItemTitle'] = $dupValue['ItemTitle'];
                        $csvData[$r]['binrack'] = $dupValue['binrack'];
                        $csvData[$r]['barcode'] = $dupValue['barcode'];
                        $csvData[$r]['ChannelSKU'] = $dupValue['ChannelSKU'];
                    }
                }
                if (isset($keyValue)) {
                    if ($keyValue == $dupValue['ChannelSKU']) {
                        $csvData[$r]['Qty'] = $csvData[$r]['Qty'] + $dupValue['Qty'];
                        $csvData[$r]['ItemTitle'] = $dupValue['ItemTitle'];
                        $csvData[$r]['binrack'] = $dupValue['binrack'];
                        $csvData[$r]['barcode'] = $dupValue['barcode'];
                        $csvData[$r]['ChannelSKU'] = $dupValue['ChannelSKU'];
                    }
                }
            }
            $r++;
        }
        App::import('Vendor', 'tcpdf/tcpdf');
        $pdf = new tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $date = date("Y-m-d");
        $pdf->SetCreator(PDF_CREATOR);
        //$pdf->SetAuthor('Nicola Asuni');
        //$pdf->SetTitle('TCPDF Example 006');
        //$pdf->SetSubject('TCPDF Tutorial');
        //$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        // set default header data
        //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'Pick List '.$date, PDF_HEADER_STRING);
        $pdf->SetHeaderData('', '', 'Pick List ' . $date, '');
        // set header and footer fonts
        $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
            require_once dirname(__FILE__) . '/lang/eng.php';
            $pdf->setLanguageArray($l);
        }
        $pdf->SetFont('times', '', 8);
        $pdf->AddPage();
        $j = 0;
        foreach ($csvData as $csvdata) {
            $j = $j + $csvdata['Qty'];
        }
        $html = '<h2>Total SKU  : - ' . $j . '</h2>
				<table border="1" width="110%" >
					<tr>
						<th width="5%" align="center">S.No</th>
						<th width="20%" align="center">SKU</th>
						<th width="45%" align="center">Qty / Item Title</th>
						<th width="5%" align="center">Qty</th>
						<th width="5%" align="center">Bin Rack</th>
						<th width="10%" align="center" >BarCode</th>
					</tr>';
        $i = 1;
        foreach ($csvData as $csvdata) {
            $html .= '<tr>
						<td align="center">' . $i . '</td>
						<td>' . $csvdata['ChannelSKU'] . '</td>
						<td align="left"><b>' . $csvdata['Qty'] . '</b> X ' . $csvdata['ItemTitle'] . '</td>
						<td align="center">' . $csvdata['Qty'] . '</td>
						<td >' . $csvdata['binrack'] . '</td>
						<td>' . $csvdata['barcode'] . '</td>
					</tr>';
            $i++;
        }
        $html .= '</table>';
        $pdf->writeHTML($html, true, false, true, false, '');
        $js = 'print(true);';
        $pdf->IncludeJS($js);
        $pdf->Output('Pick_List_' . $date . '.pdf', 'D');
    }
 /**
  * @param null $id
  * @return \Cake\Network\Response|null
  *
  * This function will produce PDF output to display a Teaching Plan.
  *
  * Said Plan is composed of the following sections:
  * 1. A cover sheet.
  * 2. Zero or more full-sized plan element listings (PEL).
  * 3. One short-form PEL.
  * 4. A rear cover sheet.
  *
  * A plan starts as a sequence of A4 sized pages.  Henceforth a "page"
  * will specifically refer to an A4 sized page.
  *
  * The front and rear cover sheets are ordinary pages.
  *
  * Each PEL is a sequence of two pages, a left-side and a right-side,
  * intended to be viewed side-by-side.
  * A PEL contains up to 5 Plan Elements, listed from top-to-bottom, with
  * the exception of the final short-form PEL.
  *
  * The short-form PEL only contains 4 Plan Elements.  Where the 5th Element
  * would normally be printed, the short-form PEL contains a blank area for the
  * left page, and a signature block for the right page.
  *
  * Physical Paper:
  *
  * With suitable software, the pages can be printed in booklet form, on double-sized
  * paper, with four pages per physical sheet of paper, two pages on each side. This
  * closely simulates the original hand-drawn form in pre-printed booklets. The downsides
  * of this method include:
  *
  *  * We need to find large paper and a printer that can print on both sides of it.
  *  * We need to find suitable booklet printing software and expertise.
  *  * There's also quite a lot of wasted form-space.
  *
  * We can also print these pages sequentially, on the front and back of A4 paper.
  * If we do this then the PELs can be readily viewed as intended, side-by-side, simply
  * by turning the pages.
  *
  * The downside of this method is that it's such a good idea, within its narrow context,
  * and so radically different from the original form, that the Bureacratic Gods that
  * lurk in the shadows must certainly frown upon this approach.  Nevertheless, I hereby taunt fate,
  * live dangerously, and chose this method.  May the Gods of Idiocy strike me down!
  */
 public function pdf($id = null)
 {
     // 1. In the beginning...
     // 1.1 Obtain the data to print.
     // 1.1.1 We'll obviously need info about the teaching plan itself, as well as
     // its associated elements
     $tplan_id = $id;
     $tplan = $this->Tplans->get($tplan_id, ['contain' => 'TplanElements']);
     // 1.1.2 Get the front cover info.
     // This query finds all sections that use this teaching plan. Most of the selected
     // fields should be the same, such as the course title, teacher, and teaching_hours_per_class.
     // However, the cohorts should all be different. (This would be nice to verify.)
     $tableSections = TableRegistry::get('Sections');
     $query = $tableSections->find('all')->contain(['Cohorts.Majors', 'Semesters', 'Subjects', 'Teachers'])->order('Cohorts.seq')->where(['Sections.tplan_id' => $tplan_id]);
     $cohortList = null;
     foreach ($query as $tplanUser) {
         $cohortNickname = $tplanUser->cohort->nickname;
         is_null($cohortList) ? $cohortList = $cohortNickname : ($cohortList .= ',' . $cohortNickname);
     }
     // Assuming all of these fields are the same, for each record,
     // then its ok to retrieve their values from the 1st record.
     // WARNING! Maybe they're not all the same!
     $n = $query->first();
     $info['subject'] = $n->subject->title;
     $info['major'] = $n->cohort->major->title;
     $info['cohorts'] = $cohortList;
     $info['instructor'] = $n->teacher->fam_name;
     $info['class_cnt'] = $tplan['session_cnt'];
     $info['teaching_hrs_per_class'] = $n->thours;
     // The desired semester sequence printed, is the reverse of
     // what's in the db.
     $info['semester_seq'] = ($n->semester->seq = 1) ? 2 : 1;
     // Ugly, ad-hoc bureaucratise...
     $info['book'] = $tplan->book;
     // 1.1.4. Now get the plan elements
     $info['elements'] = [];
     foreach ($tplan->tplan_elements as $tplanElement) {
         $element = ['start_thour' => $tplanElement->start_thour, 'stop_thour' => $tplanElement->stop_thour, 'col1' => $tplanElement->col1, 'col2' => $tplanElement->col2, 'col3' => $tplanElement->col3, 'col4' => $tplanElement->col4];
         $info['elements'][] = $element;
     }
     // 2. Initialize the pdf
     require 'tcpdf.php';
     // The primary method of specifying position is to measure mm from the origin,
     // where the origin is at the upper-left corner of the paper, moving right increases x
     // and moving down increases y.
     $pdf = new \tcpdf('P', 'mm', 'A4');
     $pdf->SetFont('cid0cs', '', 16, '', true);
     // remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // 3. Page 1, The cover
     $pdf->AddPage();
     $this->emitFrontCover($info, $pdf, 10, 10);
     // 4. The Plan Elements
     //
     // We can print the PELs, double-side, on ordinary paper, or we can do it
     // booklet-style on large paper. You decide.
     $bookletStyle = false;
     if ($bookletStyle) {
         // Upon careful reflection we can determine that:
         // 1. Any plan containing <=4 plan elements can be fully printed on a single short-form PEL.
         // 2. Each additional sheet of paper will accommodate up to 10 additional plan elements.
         // Our basic strategy will be to determine how many extra sheets of paper are required
         // and then emit 10 (plan elements or blank elements) to fill each extra sheet.
         // Then continue to emit 10 () to fill the final set of two-pages.
         $tplanElementCnt = count($info['elements']);
         $extraSheetCnt = intval(($tplanElementCnt + 5) / 10);
         // model this in excel and see that it works
         $tplanElementIdx = 0;
         while ($extraSheetCnt > 0) {
             // emit the next 10 (plan elements or blank elements)
             $tplanElementIdx += $this->emitPEL($info, $pdf, $tplanElementIdx, false);
             $extraSheetCnt--;
         }
         $tplanElementIdx += $this->emitPEL($info, $pdf, $tplanElementIdx, true);
     } else {
         // Excellent choice.  Let's print these pages, double-sided, on ordinary paper.
         $tplanElementCnt = count($info['elements']);
         $tplanElementIdx = 0;
         // which element to print next? zero based idx.
         // Emit all the full-sized PELs, if any.
         while ($tplanElementCnt - $tplanElementIdx >= 5) {
             // emit the next 5 plan elements
             $tplanElementIdx += $this->emitPEL($info, $pdf, $tplanElementIdx, false);
             // not last PEL
         }
         // Always emit at least one short-form PEL.
         $tplanElementIdx += $this->emitPEL($info, $pdf, $tplanElementIdx, true);
         // last PEL
     }
     // 5. Rear cover
     $pdf->AddPage();
     $this->emitRearCover($pdf, 17, 23);
     $pdf->Output();
     $this->response->type('application/pdf');
     return $this->response;
 }
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('shuttleconcierge');
$pdf->SetTitle('confirmacion');
$pdf->SetSubject('confirmacion');
$pdf->SetHeaderData('logo.jpg', 100, 'Reservation Confirmation', "www.shuttleconcierge.com\nPhone. 01800 890 5878\nemail: contacto@shuttleconcierge.com", array(0, 64, 255), array(0, 64, 128));
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(true);
$pdf->SetFont('dejavusans', '', 14, '', true);
$pdf->AddPage();
$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
if ($mysqli->connect_errno) {
    printf("Connection Failure: %s\n", $mysqli->connect_error);
    exit;
}
$mysqli->set_charset("utf8");
if ($resultado = $mysqli->query("\n\t\t\tSELECT *\n\t\t\tFROM bookings\n\t\t\tWHERE book_id = " . $_GET["id"] . "")) {
    $data = $resultado->fetch_all(MYSQLI_ASSOC);
    $resultado->close();
}
$airport = "Cancun Airport";
$html = '
	<style>
		body { font-family: "Open Sans", sans-serif; background: rgb(234, 244, 243); }