public function testPdfOutput() { // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 012'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // disable header and footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0)); $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)); $style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0)); $style4 = array('L' => 0, 'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)), 'R' => array('width' => 0.5, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)), 'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10')); $style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128)); $style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0)); $style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0)); // Line $pdf->Text(5, 4, 'Line examples'); $pdf->Line(5, 10, 80, 30, $style); $pdf->Line(5, 10, 5, 30, $style2); $pdf->Line(5, 10, 80, 10, $style3); // Rect $pdf->Text(100, 4, 'Rectangle examples'); $pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200)); $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3)); // Curve $pdf->Text(5, 34, 'Curve examples'); $pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6); $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6); $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200)); // Circle and ellipse $pdf->Text(5, 79, 'Circle and ellipse examples'); $pdf->SetLineStyle($style5); $pdf->Circle(25, 105, 20); $pdf->Circle(25, 105, 10, 90, 180, null, $style6); $pdf->Circle(25, 105, 10, 270, 360, 'F'); $pdf->Circle(25, 105, 10, 270, 360, 'C', $style6); $pdf->SetLineStyle($style5); $pdf->Ellipse(100, 103, 40, 20); $pdf->Ellipse(100, 105, 20, 10, 0, 90, 180, null, $style6); $pdf->Ellipse(100, 105, 20, 10, 0, 270, 360, 'DF', $style6); $pdf->SetLineStyle($style5); $pdf->Ellipse(175, 103, 30, 15, 45); $pdf->Ellipse(175, 105, 15, 7.5, 45, 90, 180, null, $style6); $pdf->Ellipse(175, 105, 15, 7.5, 45, 270, 360, 'F', $style6, array(220, 200, 200)); // Polygon $pdf->Text(5, 129, 'Polygon examples'); $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->Polygon(array(5, 135, 45, 135, 15, 165)); $pdf->Polygon(array(60, 135, 80, 135, 80, 155, 70, 165, 50, 155), 'DF', array($style6, $style7, $style7, 0, $style6), array(220, 200, 200)); $pdf->Polygon(array(120, 135, 140, 135, 150, 155, 110, 155), 'D', array($style6, 0, $style7, $style6)); $pdf->Polygon(array(160, 135, 190, 155, 170, 155, 200, 160, 160, 165), 'DF', array('all' => $style6), array(220, 220, 220)); // Polygonal Line $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 164))); $pdf->PolyLine(array(80, 165, 90, 160, 100, 165, 110, 160, 120, 165, 130, 160, 140, 165), 'D', array(), array()); // Regular polygon $pdf->Text(5, 169, 'Regular polygon examples'); $pdf->SetLineStyle($style5); $pdf->RegularPolygon(20, 190, 15, 6, 0, 1, 'F'); $pdf->RegularPolygon(55, 190, 15, 6); $pdf->RegularPolygon(55, 190, 10, 6, 45, 0, 'DF', array($style6, 0, $style7, 0, $style7, $style7)); $pdf->RegularPolygon(90, 190, 15, 3, 0, 1, 'DF', array('all' => $style5), array(200, 220, 200), 'F', array(255, 200, 200)); $pdf->RegularPolygon(125, 190, 15, 4, 30, 1, null, array('all' => $style5), null, null, $style6); $pdf->RegularPolygon(160, 190, 15, 10); // Star polygon $pdf->Text(5, 209, 'Star polygon examples'); $pdf->SetLineStyle($style5); $pdf->StarPolygon(20, 230, 15, 20, 3, 0, 1, 'F'); $pdf->StarPolygon(55, 230, 15, 12, 5); $pdf->StarPolygon(55, 230, 7, 12, 5, 45, 0, 'DF', array('all' => $style7), array(220, 220, 200), 'F', array(255, 200, 200)); $pdf->StarPolygon(90, 230, 15, 20, 6, 0, 1, 'DF', array('all' => $style5), array(220, 220, 200), 'F', array(255, 200, 200)); $pdf->StarPolygon(125, 230, 15, 5, 2, 30, 1, null, array('all' => $style5), null, null, $style6); $pdf->StarPolygon(160, 230, 15, 10, 3); $pdf->StarPolygon(160, 230, 7, 50, 26); // Rounded rectangle $pdf->Text(5, 249, 'Rounded rectangle examples'); $pdf->SetLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->RoundedRect(5, 255, 40, 30, 3.5, '1111', 'DF'); $pdf->RoundedRect(50, 255, 40, 30, 6.5, '1000'); $pdf->RoundedRect(95, 255, 40, 30, 10.0, '1111', null, $style6); $pdf->RoundedRect(140, 255, 40, 30, 8.0, '0101', 'DF', $style6, array(200, 200, 200)); // Arrows $pdf->Text(185, 249, 'Arrows'); $pdf->SetLineStyle($style5); $pdf->SetFillColor(255, 0, 0); $pdf->Arrow(200, 280, 185, 266, 0, 5, 15); $pdf->Arrow(200, 280, 190, 263, 1, 5, 15); $pdf->Arrow(200, 280, 195, 261, 2, 5, 15); $pdf->Arrow(200, 280, 200, 260, 3, 5, 15); // - . - . - . - . - . - . - . - . - . - . - . - . - . - . - // ellipse // add a page $pdf->AddPage(); $pdf->Cell(0, 0, 'Arc of Ellipse'); // center of ellipse $xc = 100; $yc = 100; // X Y axis $pdf->SetDrawColor(200, 200, 200); $pdf->Line($xc - 50, $yc, $xc + 50, $yc); $pdf->Line($xc, $yc - 50, $xc, $yc + 50); // ellipse axis $pdf->SetDrawColor(200, 220, 255); $pdf->Line($xc - 50, $yc - 50, $xc + 50, $yc + 50); $pdf->Line($xc - 50, $yc + 50, $xc + 50, $yc - 50); // ellipse $pdf->SetDrawColor(200, 255, 200); $pdf->Ellipse($xc, $yc, 30, 15, 45, 0, 360, 'D', array(), array(), 2); // ellipse arc $pdf->SetDrawColor(255, 0, 0); $pdf->Ellipse($xc, $yc, 30, 15, 45, 45, 90, 'D', array(), array(), 2); $this->comparePdfs($pdf); }
/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS MULTILINESTRING object * @param string $label Label for the GIS MULTILINESTRING object * @param string $line_color Color for the GIS MULTILINESTRING object * @param array $scale_data Array containing data related to scaling * @param TCPDF $pdf TCPDF instance * * @return TCPDF the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { /** @var PMA_String $pmaString */ $pmaString = $GLOBALS['PMA_String']; // allocate colors $red = hexdec($pmaString->substr($line_color, 1, 2)); $green = hexdec($pmaString->substr($line_color, 3, 2)); $blue = hexdec($pmaString->substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'MULTILINESTRING((' and trailing '))' $multilinestirng = $pmaString->substr($spatial, 17, $pmaString->strlen($spatial) - 19); // Separate each linestring $linestirngs = explode("),(", $multilinestirng); $first_line = true; foreach ($linestirngs as $linestring) { $points_arr = $this->extractPoints($linestring, $scale_data); foreach ($points_arr as $point) { if (!isset($temp_point)) { $temp_point = $point; } else { // draw line section $pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line); $temp_point = $point; } } unset($temp_point); // print label if (isset($label) && trim($label) != '' && $first_line) { $pdf->SetXY($points_arr[1][0], $points_arr[1][1]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } $first_line = false; } return $pdf; }
/** * @param float|string $x1 * @param float|string $y1 * @param float|string $x2 * @param float|string $y2 * @param array $attrs { * @option string|null "stroke_width" required * @option string|null "stroke_color" required * @option string "stroke_dash" required * } * @see http://www.tcpdf.org/doc/code/classTCPDF.html */ public function drawLine($x1, $y1, $x2, $y2, array $attrs = array()) { $style = $this->buildGraphicStyles($attrs); if ($style['stroke'] === null) { return; } $this->pdf->Line($x1, $y1, $x2, $y2, $style['stroke']); }
/** * Draws a line from x1,y1 to x2,y2 * * See {@link Style::munge_color()} for the format of the color array. * See {@link Cpdf::setLineStyle()} for a description of the format of the * $style parameter (aka dash). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param array $color * @param float $width * @param array $style */ function line($x1, $y1, $x2, $y2, $color, $width, $style = array(), $blend = "Normal", $opacity = 1.0) { //dompdf_debug("trace", "($x1, $y1, $x2, $y2, [$color[0], $color[1], $color[2]], $width, $style, $blend, $opacity)"); //$this->_set_stroke_color($color); //$this->_set_line_style($width, "butt", "", $style); $this->_set_line_transparency($blend, $opacity); $this->_pdf->Line($x1, $y1, $x2, $y2, $this->_make_line_style($color, $width, "butt", "", $style)); }
/** * Draws a line from x1,y1 to x2,y2 * * See {@link Style::munge_color()} for the format of the color array. * See {@link Cpdf::setLineStyle()} for a description of the format of the * $style parameter (aka dash). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param array $color * @param float $width * @param array $style */ function line($x1, $y1, $x2, $y2, $color, $width, $style = array(), $blend = "Normal", $opacity = 1.0) { dompdf_debug("trace", "({$x1}, {$y1}, {$x2}, {$y2}, [{$color['0']}, {$color['1']}, {$color['2']}], {$width}, {$style}, {$blend}, {$opacity})"); //$this->_set_stroke_color($color); //$this->_set_line_style($width, "butt", "", $style); $this->_set_line_transparency($blend, $opacity); $this->_pdf->Line($x1, $y1, $x2, $y2, $this->_make_line_style($color, $width, "butt", "", $style)); }
function index() { $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->load->library('form_validation'); $this->load->model(array('user_model', 'project_model')); $this->load->helper('csv'); $this->load->helper('download'); $data['sales_persons'] = $this->user_model->list_by_department(2); $this->form_validation->set_rules('from_date', 'From date', 'trim|required'); $this->form_validation->set_rules('to_date', 'To date', 'trim|required'); if ($this->form_validation->run() == FALSE) { $data['dues'] = array(); $this->load->view('reports/enquiry_report', $data); } else { $dues = array(); $sales_person_selected = $this->input->post('sales_person'); $from_date_db = $this->input->post('from_date'); $from_date_db = date('Y-m-d', strtotime($from_date_db)); $to_date_db = $this->input->post('to_date'); $to_date_db = date('Y-m-d', strtotime($to_date_db)); $enquiry_report = array(); $this->db->select('lead.id, lead.max_budgect,contact.name,' . 'project.name as project,lead.lead_source,customer_rating.name as rating,' . 'contact.phone,contact.phone_2,contact.phone_3,contact.email,contact.email_2,' . 'lead.date, lead.preferred_location, lead.looking_for,' . 'user.full_name as sales_person,sales_stage.name as sales_stage'); $this->db->from('lead'); $this->db->join('contact', ' lead.contact_id=contact.id'); $this->db->join('project', ' lead.interested_project=project.id'); $this->db->join('user', 'user.id= lead.lead_owner', 'left'); $this->db->join('sales_stage', 'sales_stage.id= lead.sales_stage', 'left'); $this->db->join('customer_rating', 'customer_rating.id= lead.rating', 'left'); if (!empty($sales_person_selected)) { $this->db->where('lead.lead_owner', $sales_person_selected); } $this->db->where('lead.date >=', $from_date_db); $this->db->where('lead.date <=', $to_date_db); $customers = $this->db->get()->result(); foreach ($customers as $customer) { $enquiry_report[$customer->id] = array(); $enquiry_report[$customer->id]['date'] = $customer->date; $enquiry_report[$customer->id]['lead_owner'] = $customer->sales_person; $enquiry_report[$customer->id]['prospect_name'] = $customer->name; $enquiry_report[$customer->id]['project'] = $customer->project; $enquiry_report[$customer->id]['max_budgect'] = $customer->max_budgect; $enquiry_report[$customer->id]['lead_source'] = $customer->lead_source; $enquiry_report[$customer->id]['rating'] = $customer->rating; $enquiry_report[$customer->id]['sales_stage'] = $customer->sales_stage; $enquiry_report[$customer->id]['follow_ups'] = $this->db->where('lead_id', $customer->id)->count_all_results(' interaction'); $lead_id = $customer->id; $total_due_amount = 0; } //print_r($enquiry_report); //exit(); if (isset($_POST['generate_pdf'])) { $this->load->library('Pdf'); $this->db->select('company.name'); $this->db->from('company'); $company_details = $this->db->get()->first_row(); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 7, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Sales Report</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $pdf->writeHTMLCell(50, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($from_date_db)) . ' - ' . date('M Y', strtotime($to_date_db)) . '</strong>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true); $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="30">No.</th>'; $html .= '<th width="65">Date</th>'; $html .= '<th width="75">Lead Owner</th>'; $html .= '<th width="65">Prospect Name</th>'; $html .= '<th width="65">Interested Project</th>'; $html .= '<th width="65">Budget</th>'; $html .= '<th width="65">Lead Source</th>'; $html .= '<th width="65">Rating</th>'; $html .= '<th width="65">Sales Stage</th>'; $html .= '<th width="65">Follow Ups</th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; foreach ($enquiry_report as $due) { $html .= '<tr>'; $html .= '<td width="30">' . ($n + 1) . '</td>'; $html .= '<td width="65">' . date('d-m-Y', strtotime($due['date'])) . '</td>'; $html .= '<td width="75">' . $due['lead_owner'] . '</td>'; $html .= '<td width="65">' . $due['prospect_name'] . '</td>'; $html .= '<td width="65">' . $due['project'] . '</td>'; $html .= '<td width="65">' . $due['max_budgect'] . '</td>'; $html .= '<td width="65">' . $due['lead_source'] . '</td>'; $html .= '<td width="65">' . $due['rating'] . '</td>'; $html .= '<td width="65">' . $due['sales_stage'] . '</td>'; $html .= '<td width="65">' . $due['follow_ups'] . '</td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '</table><br /><br />'; //echo $html; //exit(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); } elseif (isset($_POST['generate_csv'])) { $csv_array = array(); $csv_array_line = array(); $csv_array_line[] = 'No.'; $csv_array_line[] = 'Date'; $csv_array_line[] = 'Lead Owner'; $csv_array_line[] = 'Prospect Name'; $csv_array_line[] = 'Interested Project'; $csv_array_line[] = 'Budget'; $csv_array_line[] = 'Lead Source'; $csv_array_line[] = 'Rating'; $csv_array_line[] = 'Sales Stage'; $csv_array_line[] = 'Follow Ups'; $csv_array[] = $csv_array_line; foreach ($enquiry_report as $due) { $csv_array_line = array(); $csv_array_line[] = $n + 1; $csv_array_line[] = date('d-m-Y', strtotime($due['date'])); $csv_array_line[] = $due['lead_owner']; $csv_array_line[] = $due['prospect_name']; $csv_array_line[] = $due['project']; $csv_array_line[] = $due['max_budgect']; $csv_array_line[] = $due['lead_source']; $csv_array_line[] = $due['rating']; $csv_array_line[] = $due['sales_stage']; $csv_array_line[] = $due['follow_ups']; $csv_array[] = $csv_array_line; } echo array_to_csv($csv_array, 'due_letter.csv'); exit; } else { $data['enquiry_report'] = $enquiry_report; $data['from_date_selected'] = $this->input->post('from_date'); $data['to_date_selected'] = $this->input->post('to_date'); $data['project_selected'] = $this->input->post('project'); $this->load->view('reports/enquiry_report', $data); } } }
$pdf->Cell(30, 0, 'Center-Top', 1, $ln = 0, 'C', 0, '', 0, false, 'C', 'T'); $pdf->Cell(30, 0, 'Bottom-Top', 1, $ln = 0, 'C', 0, '', 0, false, 'B', 'T'); $pdf->Cell(30, 0, 'Ascent-Top', 1, $ln = 0, 'C', 0, '', 0, false, 'A', 'T'); $pdf->Cell(30, 0, 'Baseline-Top', 1, $ln = 0, 'C', 0, '', 0, false, 'L', 'T'); $pdf->Cell(30, 0, 'Descent-Top', 1, $ln = 0, 'C', 0, '', 0, false, 'D', 'T'); $pdf->SetXY(15, 120); // text on bottom $pdf->Cell(30, 0, 'Top-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'T', 'B'); $pdf->Cell(30, 0, 'Center-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'C', 'B'); $pdf->Cell(30, 0, 'Bottom-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'B', 'B'); $pdf->Cell(30, 0, 'Ascent-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'A', 'B'); $pdf->Cell(30, 0, 'Baseline-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'L', 'B'); $pdf->Cell(30, 0, 'Descent-Bottom', 1, $ln = 0, 'C', 0, '', 0, false, 'D', 'B'); // draw some reference lines $linestyle = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(255, 0, 0)); $pdf->Line(15, 60, 195, 60, $linestyle); $pdf->Line(15, 90, 195, 90, $linestyle); $pdf->Line(15, 120, 195, 120, $linestyle); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Print an image to explain cell measures $pdf->Image('images/tcpdf_cell.png', 15, 160, 100, 100, 'PNG', '', '', false, 300, '', false, false, 0, false, false, false); $legend = 'LEGEND: X: cell x top-left origin (top-right for RTL) Y: cell y top-left origin (top-right for RTL) CW: cell width CH: cell height LW: line width NRL: normal line position EXT: external line position INT: internal line position
function final_bill($customer_file_id) { $this->load->library('form_validation'); $this->form_validation->set_rules('due_date', 'Due Date', 'trim|required'); if ($this->form_validation->run() == FALSE) { $data['customer_file_id'] = $customer_file_id; $this->load->view('customer_file/final_bill', $data); } else { $due_date = $this->input->post('due_date'); $due_date_db = date('Y-m-d', strtotime($due_date)); $show_payment = $this->input->post('show_payment'); $show_tax = $this->input->post('show_tax'); $show_dpc = $this->input->post('show_dpc'); $show_discount = $this->input->post('show_discount'); $this->load->library('Pdf'); $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'discount_model')); $this->db->select('contact.name as customer_name,project.name as project_name,availability_chart_unit.unit_name as unit_name,' . 'customer_file.purchase_cost,customer_file.area,customer_file.rate'); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'project.id=customer_file.project_id'); $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id'); $this->db->where('customer_file.id', $customer_file_id); $project_details = $this->db->get()->first_row(); $land_cost = $this->db->select('cost')->where(array('customer_file_id' => $customer_file_id, 'cost_head_id' => '14'))->get('customer_file_unit_costing')->first_row(); $this->db->select('company.name,project.project_type'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $this->db->where('customer_file.id', $customer_file_id); $company_details = $this->db->get()->first_row(); $this->db->select('receipt_split_up.amount as splitup_amount,payment_schedule_customer.installment_name,' . 'payment_schedule_customer.dpc_interest,payment_schedule_customer.dpc_grace_period,' . 'payment_schedule_customer.due_date,payment_schedule_customer.due_amount,receipt.date_payment,' . 'receipt.receipt_number'); $this->db->from('receipt_split_up'); $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id'); $this->db->join('payment_schedule_customer', 'payment_schedule_customer.id=receipt_split_up.installment_id'); $this->db->where('payment_schedule_customer.customer_file_id', $customer_file_id); $this->db->where('receipt_split_up.amount >', 0); $paid_amout_details = $this->db->get()->result(); $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual($customer_file_id); $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional($customer_file_id); $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id); if ($show_discount == 1) { $discounts = $this->discount_model->list_discount_customer_file($customer_file_id); $htmldis = '</br /><br /></br /><br /><h3 style="padding: 10px; text-align:center"><u>Discount </u></h3>'; $htmldis .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">'; $htmldis .= '<tr><td width="40"><b>No.</b></td><td width="110"><b>Date</b></td><td width="110"><b>Amount</b></td><td width="377"><b>Remarks</b></td></tr>'; $nd = 1; $total_discount = 0; foreach ($discounts as $discount) { $total_discount += $discount->amount; $htmldis .= '<tr><td>' . $nd . '</td><td>' . date('d-m-Y', strtotime($discount->date)) . '</td>' . '<td>' . number_format($discount->amount) . '</td><td>' . $discount->remarks . '</td></tr>'; $nd++; } $htmldis .= '<tr><td></td><td></td><td>' . number_format($total_discount) . '</td><td></td></tr>'; $htmldis .= '</table></br /><br />'; $htmldis .= '<table>'; $htmldis .= '<tr>'; $htmldis .= '<td><strong>Total Discount : </strong>' . number_format($total_discount) . '</td>'; $htmldis .= '</tr>'; $htmldis .= '</table><br /><br />'; } $this->db->select('tax_type.name,tax_master.id'); $this->db->from('tax_type'); $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id'); $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id'); $this->db->where('customer_file_tax.customer_file_id', $customer_file_id); $customer_tax = $this->db->get()->result(); $crm_settings = $this->db->get('crm_settings')->first_row(); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 8, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Final Bill </h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $html = '<br /><br />'; $html .= '<table cellpadding="5" ><tr><td width="448"><strong> Customer Name : </strong>' . $project_details->customer_name . '</td>'; $html .= '<td><strong> Date :</strong> ' . $due_date . '</td></tr>'; $html .= '<tr><td><strong> Project :</strong> ' . $project_details->project_name . '</td>'; if ($company_details->project_type == 1) { $html .= '<td><strong> Flat No :</strong> ' . $project_details->unit_name . '</td></tr>'; } else { $html .= '<td><strong> Villa No :</strong> ' . $project_details->unit_name . '</td></tr>'; } $html .= '<br /><br /><br />'; foreach ($actual_payment_schedule as $schedule) { $total_due_amount += $schedule->due_amount; $ttax = 0; $ttax_bal = 0; foreach ($customer_tax as $cs2) { $tax_amount = 0; $tax_amount_bal = 0; if ($schedule->status == 1) { if ($schedule->due_amount - $schedule->amount_paid == 0) { $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax = $this->db->get()->first_row(); if ($applicale_tax->tax_amount) { $ttax += $applicale_tax->tax_amount; $total_tax[$cs2->id] += $applicale_tax->tax_amount; } else { } } elseif ($schedule->amount_paid == 0) { $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = $schedule->due_amount / 100 * $applicale_tax->tax_percentage; $ttax += $tax_amount; } if (!empty($tax_amount)) { $total_tax[$cs2->id] += $tax_amount; } else { } } else { $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax_paid = $this->db->get()->first_row(); $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $tax_percentage_balance = $this->db->get()->first_row(); $tax_amount_balance = ($schedule->due_amount - $schedule->amount_paid) / 100 * $tax_percentage_balance->tax_percentage; $applicale_tax_amount = $applicale_tax_paid->tax_amount + $tax_amount_balance; $ttax += $applicale_tax_amount; $total_tax[$cs2->id] += $applicale_tax_amount; } } } $total_due_tax_amount += $schedule->due_amount + $ttax; $n++; } foreach ($customer_tax as $cs3) { $tt_tax += $total_tax[$cs3->id]; } $total_due_tax_amount; //////////////////////////////////////////////////////////////////////////////////////////////// $total_due_tax_amount2 = 0; if (!empty($additional_payment_schedule)) { $html2 .= '<h4 style="padding: 10px;"><strong>Additional Cost</strong></h4>'; $html2 .= '<table border="1" cellpadding="5" cellspacing="0" width="100%">'; $html2 .= '<thead>'; $html2 .= '<tr>'; $html2 .= '<th>No.</th>'; $html2 .= '<th>Name</th>'; $html2 .= '<th data-toggle="tooltip" data-placement="top" title="Principle Amount Due">Due Amount</th> '; foreach ($customer_tax as $cs) { $html2 .= '<th>' . $cs->name . '</th> '; } $html2 .= ' <th>Total </th>'; $html2 .= '</tr>'; $html2 .= '</thead>'; $html2 .= '<tbody>'; $total_due_amount2 = 0; $total_balance2 = 0; $total_tax = array(); foreach ($customer_tax as $cs20) { $total_tax2[$cs20->id] = 0; } $total_paid1 = 0; $n = 1; foreach ($additional_payment_schedule as $schedule_additional) { $total_due_amount2 += $schedule_additional->due_amount; $html2 .= '<tr >'; $html2 .= '<td>' . $n . '</td>'; $html2 .= '<td>' . $schedule_additional->installment_name . '</td>'; $html2 .= ' <td>' . number_format($schedule_additional->due_amount) . '</td>'; $ttax = 0; foreach ($customer_tax as $cs2) { $tax_amount = 0; $html2 .= '<td>'; $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => date('Y-m-d'), 'to_date >=' => date('Y-m-d'), 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type)); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = $schedule_additional->due_amount / 100 * $applicale_tax->tax_percentage; $ttax += $tax_amount; } if (!empty($tax_amount)) { $html2 .= '<span>' . number_format($tax_amount) . '</span>'; $total_tax2[$cs2->id] += $tax_amount; } else { $html2 .= '<span>0</span>'; } $html2 .= '</td>'; } $html2 .= '<td>'; $html2 .= '<span data-toggle="modal" data-target="#total_splitup">'; $html2 .= '<span>' . number_format($schedule_additional->due_amount + $ttax) . '</span>'; $total_due_tax_amount2 += $schedule_additional->due_amount + $ttax; $html2 .= '</span>'; $html2 .= '</td>'; $html2 .= '</tr>'; $n++; } $html2 .= '</tbody>'; $html2 .= '<tfoot>'; $html2 .= '<tr style="font-weight: bolder">'; $html2 .= '<td colspan="2"></td> '; $html2 .= '<td>' . number_format($total_due_amount2) . '</td>'; foreach ($customer_tax as $cs7) { $html2 .= '<td>' . number_format($total_tax2[$cs7->id]) . '</td>'; } $html2 .= '<td>' . number_format($total_due_tax_amount2) . '</td>'; $html2 .= '<td></td>'; $html2 .= '</tr>'; $html2 .= '</tfoot>'; $html2 .= '</table>'; } ////////////////////////////////////////////////////////////////////////// if (empty($total_due_tax_amount2)) { $total_due_tax_amount2 = 0; } if (empty($tt_tax2)) { $tt_tax2 = 0; } if (empty($total_due_amount2)) { $total_due_amount2 = 0; } $total_amt22 = 0; foreach ($receipts as $receipt22) { $total_amt22 += $receipt22->amount_paid; } $html .= '<table cellpadding="8" align="Left" border="1"><tr>'; $html .= '<td><strong>Total Cost</strong><br /><br />' . ' Total Agreement Value : ' . number_format($total_due_amount) . '<br /><br />' . ' Taxes : ' . number_format($tt_tax) . '<br /><br />' . ' Additional Charges : ' . number_format($total_due_tax_amount2) . '<br />' . '</td>'; $html .= '<td> <strong>Rs. ' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2) . '</strong></td>'; $html .= '</tr>'; $html .= '<tr>'; $html .= '<td><strong>Total Receipts </strong></td>'; $html .= '<td><strong>Rs. ' . number_format($total_amt22) . '</strong></td>'; $html .= '</tr>'; $html .= '</table><br /><br /><br />'; if ($show_discount == 1) { $html .= '<strong>Gross Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - $total_amt22); $html .= '<br /><br /><strong>Discount : </strong> Rs.' . number_format($total_discount); $html .= '<br /><br /><strong>Net Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - ($total_amt22 + $total_discount)); } else { $html .= '<strong>Net Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - $total_amt22); } $html .= '<br /><br /><br />'; $html .= '<strong>For ' . $company_details->name . ' </strong>'; $html .= '<br /><br /><br />'; $html .= '<strong>Authorised Signature</strong>'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->AddPage(); $html = ''; $this->db->select("cost_head.name as cost_head,SUM(`customer_file_unit_costing`.`cost`) as cost," . "cost_head.is_auto_calculate,cost_head.is_included"); $this->db->from('customer_file_unit_costing'); $this->db->join('cost_head', 'customer_file_unit_costing.cost_head_id=cost_head.id'); $this->db->where('customer_file_unit_costing.customer_file_id', $customer_file_id); $this->db->group_by('cost_head.id'); $unit_costs = $this->db->get()->result(); $html .= '<strong>Total Agreement Value</strong><br /></br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">'; $ttcst = 0; foreach ($unit_costs as $cost) { $html .= '<tr>'; $html .= '<td>' . $cost->cost_head . '</td>'; if ($cost->is_auto_calculate) { $inc = 0; foreach ($unit_costs as $cost2) { if ($cost2->is_included) { $inc += $cost2->cost; } } $html .= '<td>' . number_format($cost->cost - $inc) . '</td>'; $ttcst += $cost->cost - $inc; } else { $html .= '<td>' . number_format($cost->cost) . '</td>'; $ttcst += $cost->cost; } $html .= '</tr>'; } $html .= '<tr>'; $html .= '<td></td>'; $html .= '<td><strong> Rs. ' . number_format($ttcst) . '</strong></td>'; $html .= '</tr>'; $html .= '</table><br /><br /><br /><br />'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->writeHTMLCell(0, 0, '', '', $html2, 0, 1, 0, true, '', true); if (!empty($receipts) && $show_payment == 1) { $pdf->AddPage(); $html = ''; $html .= '<table cellpadding="5" border="0" cellspacing="0" width="100%" nobr="true">'; $html .= '<tr><td colspan="7" style="text-align:center;" ><u><strong>Payments Received as on Date</strong></u></td></tr>'; $html .= '<tr><td border="1"><b>No.</b></td><td border="1"><b>Date</b></td><td border="1"><b>Payment Type</b></td><td border="1"><b>Inv No</b></td><td border="1"><b>Principle Amount</b></td>'; $html .= '<td border="1"><b>Total Tax</b></td><td border="1"><b>Total Amount</b></td></tr>'; $total_pri = 0; $total_tx = 0; $total_amt = 0; foreach ($receipts as $b => $receipt) { $total_pri += $receipt->principle_amount; $total_tx += $receipt->amount_paid - $receipt->principle_amount; $total_amt += $receipt->amount_paid; $html .= '<tr>'; $html .= '<td border="1">' . ($b + 1) . '</td>'; $html .= '<td border="1">' . $receipt->date_payment . '</td>'; $html .= '<td border="1">' . $receipt->payment_type . '</td>'; $html .= '<td border="1">' . $receipt->receipt_number . '</td>'; $html .= '<td border="1">' . number_format($receipt->principle_amount) . '</td>'; $html .= '<td border="1">' . number_format($receipt->amount_paid - $receipt->principle_amount) . '</td>'; $html .= '<td border="1">' . number_format($receipt->amount_paid) . '</td>'; $html .= '</tr>'; } $html .= '<tr style="font-weight: bolder">'; $html .= ' <td colspan="4" border="1"></td>'; $html .= ' <td border="1">' . $total_pri . '</td>'; $html .= ' <td border="1">' . $total_tx . '</td>'; $html .= ' <td border="1">' . $total_amt . '</td>'; $html .= ' </tr>'; $html .= ' </table><br /><br />'; $html .= '<table>'; $html .= '<tr>'; $html .= '<td><strong>Total Due : </strong>' . number_format($total_due_tax_amount2 + $total_due_tax_amount) . '</td>'; $html .= '<td><strong>Amount Received : </strong>' . number_format($total_amt) . '</td>'; if ($total_due_tax_amount2 + $total_due_tax_amount - $total_amt <= 0) { $html .= '<td><strong>Balance Due : </strong>' . number_format('0', 2) . '</td>'; } else { $html .= '<td><strong>Balance Due : </strong>' . number_format($total_due_tax_amount2 + $total_due_tax_amount - $total_amt) . '</td>'; } $html .= '</tr>'; $html .= '</table><br /><br />'; if ($total_due_tax_amount2 + $total_due_tax_amount - $total_amt <= 0) { $html .= '<table>'; $html .= '<tr>'; $html .= '<td><strong>Advance Payment : </strong>' . number_format($total_amt - ($total_due_tax_amount2 + $total_due_tax_amount)) . '</td>'; $html .= '</tr>'; $html .= '</table>'; } $html .= '<br /><br /><br /><br />'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); } //detailed tax report if ($show_tax == 1) { if (!empty($customer_tax)) { foreach ($customer_tax as $tx_det) { $html = ''; $html .= '<strong>' . $tx_det->name . ' on Collected Amount</strong><br /></br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">'; $html .= '<tr>'; $html .= '<td><b>No.</b></td>'; $html .= '<td><b>Inv No</b></td>'; $html .= '<td> <b>Date</b></td>'; $html .= '<td><b>Amount</b></td>'; $html .= '<td><b>' . $tx_det->name . ' %</b></td>'; $html .= '<td><b>' . $tx_det->name . '</b></td>'; $html .= '</tr>'; $count = 1; $tot_principle_amount = 0; $tot_tax_amount = 0; foreach ($receipts as $b => $rcpt) { $this->db->select('SUM(`receipt_split_up_tax`.`tax_amount`) as tax_amount'); $this->db->from('receipt'); $this->db->join('receipt_split_up', 'receipt_split_up.receipt_id=receipt.id'); $this->db->join('receipt_split_up_tax', 'receipt_split_up_tax.receipt_split_up_id=receipt_split_up.id'); $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id'); $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id'); $this->db->where('tax_type.id', $tx_det->id); $this->db->where('receipt.id', $rcpt->id); $tax_data = $this->db->get()->first_row(); $html .= '<tr>'; $html .= '<td>' . $count . '</td>'; $html .= '<td>' . $rcpt->receipt_number . '</td>'; $html .= '<td>' . $rcpt->date_payment . '</td>'; $html .= '<td>' . number_format($rcpt->principle_amount) . '</td>'; $html .= '<td>' . $tax_data->tax_amount / $rcpt->principle_amount * 100 . '</td>'; $html .= '<td>' . number_format($tax_data->tax_amount) . '</td>'; $html .= '</tr>'; $count++; $tot_principle_amount += $rcpt->principle_amount; $tot_tax_amount += $tax_data->tax_amount; } $html .= '<tr>'; $html .= '<td colspan="3"></td>'; $html .= '<td><strong>' . number_format($tot_principle_amount) . '</strong></td>'; $html .= '<td></td>'; $html .= '<td><strong>' . number_format($tot_tax_amount) . '</strong></td>'; $html .= '</tr>'; $html .= '</table><br /><br /><br /><br />'; if (!empty($actual_payment_schedule)) { $html .= '<strong>' . $tx_det->name . ' on Balance Due Amount - Actual Due</strong><br /></br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">'; $html .= '<tr>'; $html .= '<td><b>No.</b></td>'; $html .= '<td><b>Inst Name </b></td>'; $html .= '<td> <b>Due Date</b></td>'; $html .= '<td><b>Due Amt </b></td>'; $html .= '<td><b>Due Amt Paid </b></td>'; $html .= '<td><b>Due Amt Balance </b></td>'; $html .= '<td><b>' . $tx_det->name . ' %</b></td>'; $html .= '<td><b>' . $tx_det->name . '</b></td>'; $html .= '</tr>'; $count = 1; $total_due_amount_actual = 0; $total_amount_paid_actual = 0; $total_balance_actual = 0; $total_tax_amount_actual = 0; foreach ($actual_payment_schedule as $schedule) { if ($schedule->status == 1) { if ($schedule->due_amount - $schedule->amount_paid != 0) { $balance_amount = $schedule->due_amount - $schedule->amount_paid; $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('customer_file_tax'); $this->db->join('tax_master', 'tax_master.id=customer_file_tax.tax_id'); $this->db->join('tax_slab', 'tax_slab.tax_master_id=tax_master.id'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where('tax_slab.tax_type_id', $tx_det->id); $this->db->where('customer_file_tax.customer_file_id', $customer_file_id); $this->db->where('tax_slab.from_date <=', $due_date_db); $this->db->where('tax_slab.to_date >=', $due_date_db); $this->db->where('tax_slab_cost_head.cost_head_id', $schedule->payment_type); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = $balance_amount / 100 * $applicale_tax->tax_percentage; $ttax += $tax_amount; } $html .= '<tr>'; $html .= '<td>' . $count . '</td>'; $html .= '<td>' . $schedule->installment_name . '</td>'; $html .= '<td>' . $schedule->due_date . '</td>'; $html .= '<td>' . number_format($schedule->due_amount) . '</td>'; $html .= '<td>' . number_format($schedule->amount_paid) . '</td>'; $html .= '<td>' . number_format($schedule->due_amount - $schedule->amount_paid) . '</td>'; $html .= '<td>' . number_format($applicale_tax->tax_percentage, 2) . ' %</td>'; $html .= '<td>' . number_format($tax_amount) . '</td>'; $html .= '</tr>'; $total_due_amount_actual += $schedule->due_amount; $total_amount_paid_actual += $schedule->amount_paid; $total_balance_actual += $schedule->due_amount - $schedule->amount_paid; $total_tax_amount_actual += $tax_amount; } } $count++; } $html .= '<tr>'; $html .= '<td colspan="3"></td>'; $html .= '<td><strong>' . number_format($total_due_amount_actual) . '</strong></td>'; $html .= '<td><strong>' . number_format($total_amount_paid_actual) . ' </strong></td>'; $html .= '<td><strong>' . number_format($total_balance_actual) . '</strong></td>'; $html .= '<td><strong> </strong></td>'; $html .= '<td><strong>' . number_format($total_tax_amount_actual) . ' </strong></td>'; $html .= '</tr>'; $html .= '</table><br /><br /><br /><br />'; } if (!empty($additional_payment_schedule)) { $html .= '<strong>' . $tx_det->name . ' on Balance Due Amount - Additional Due</strong><br /></br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">'; $html .= '<tr>'; $html .= '<td><b>No.</b></td>'; $html .= '<td><b>Inst Name </b></td>'; $html .= '<td><b> Due Date</b></td>'; $html .= '<td><b>Due Amt </b></td>'; $html .= '<td><b>Due Amt Paid </b></td>'; $html .= '<td><b>Due Amt Balance </b></td>'; $html .= '<td><b>' . $tx_det->name . ' %</b></td>'; $html .= '<td><b>' . $tx_det->name . '</b></td>'; $html .= '</tr>'; $count = 1; $total_due_amount_additional = 0; $total_amount_paid_additional = 0; $total_balance_additional = 0; $total_tax_amount_additional = 0; foreach ($additional_payment_schedule as $schedule_additional) { $balance_amount = 0; if ($schedule_additional->status == 1) { if ($schedule_additional->due_amount - $schedule_additional->amount_paid != 0) { $balance_amount = $schedule_additional->due_amount - $schedule_additional->amount_paid; $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('customer_file_tax'); $this->db->join('tax_master', 'tax_master.id=customer_file_tax.tax_id'); $this->db->join('tax_slab', 'tax_slab.tax_master_id=tax_master.id'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where('tax_slab.tax_type_id', $tx_det->id); $this->db->where('customer_file_tax.customer_file_id', $customer_file_id); $this->db->where('tax_slab.from_date <=', $due_date_db); $this->db->where('tax_slab.to_date >=', $due_date_db); $this->db->where('tax_slab_cost_head.cost_head_id', $schedule_additional->payment_type); $applicale_tax_additional = $this->db->get()->first_row(); if (!empty($applicale_tax_additional->tax_percentage)) { $tax_amount_additional = $balance_amount / 100 * $applicale_tax_additional->tax_percentage; $ttax += $tax_amount; } $html .= '<tr>'; $html .= '<td>' . $count . '</td>'; $html .= '<td> ' . $schedule_additional->installment_name . '</td>'; $html .= '<td>' . $schedule_additional->due_date . '</td>'; $html .= '<td>' . number_format($schedule_additional->due_amount) . '</td>'; $html .= '<td>' . number_format($schedule_additional->amount_paid) . '</td>'; $html .= '<td>' . number_format($schedule_additional->due_amount - $schedule_additional->amount_paid) . '</td>'; $html .= '<td>' . number_format($applicale_tax_additional->tax_percentage, 2) . ' %</td>'; $html .= '<td>' . number_format($tax_amount_additional) . '</td>'; $html .= '</tr>'; $total_due_amount_additional += $schedule_additional->due_amount; $total_amount_paid_additional += $schedule_additional->amount_paid; $total_balance_additional += $schedule_additional->due_amount - $schedule_additional->amount_paid; $total_tax_amount_additional += $tax_amount; } } $count++; } $html .= '<tr>'; $html .= '<td colspan="3"></td>'; $html .= '<td><strong>' . number_format($total_due_amount_additional) . '</strong></td>'; $html .= '<td><strong>' . number_format($total_amount_paid_additional) . ' </strong></td>'; $html .= '<td><strong>' . number_format($total_balance_additional) . '</strong></td>'; $html .= '<td><strong> </strong></td>'; $html .= '<td><strong>' . number_format($total_tax_amount_additional) . ' </strong></td>'; $html .= '</tr>'; $html .= '</table><br /><br /><br /><br />'; } $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); } } } if ($show_dpc == 1) { $pdf->AddPage(); $html = ''; $html .= '<h3 style="padding: 10px; text-align:center"><u>DPC Due on Collected Amount</u></h3>'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="28"><b>No.</b></th>'; $html .= '<th width="104"><b>Installment Name</b></th>'; $html .= '<th width="58"><b>Due Date</b></th>'; $html .= '<th width="65"><b>Due Amount</b></th>'; $html .= '<th width="65"><b>Paid Amt </b></th>'; $html .= '<th width="58"><b>Pay Date </b></th>'; $html .= '<th width="45"><b>Inv No</b></th>'; $html .= '<th width="58"><b>Gr Period</b></th>'; $html .= '<th width="53"><b>Delayed Days</b></th>'; $html .= '<th width="44"><b>DPC % </b></th>'; $html .= '<th width="58"><b>DPC Due </b></th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_dpc = 0; foreach ($paid_amout_details as $schedule) { $datetime1 = date_create($schedule->due_date); $datetime2 = date_create($schedule->date_payment); $interval = date_diff($datetime1, $datetime2); $delayed_days = $interval->format('%R%a'); if ($delayed_days <= 0) { $delayed_days = 0; } else { $delayed_days = str_replace('+', '', $delayed_days); } if ($delayed_days < $schedule->dpc_grace_period) { $dday = 0; } else { if ($crm_settings->include_grace_period == 0) { $dday = $delayed_days - $schedule->dpc_grace_period; } else { $dday = $delayed_days; } } $dpc = $schedule->splitup_amount * $schedule->dpc_interest / 100; $dpc = $dpc / 365 * $dday; $total_dpc += $dpc; $html .= '<tr>'; $html .= '<td width="28">' . $n . '</td>'; $html .= '<td width="104">' . $schedule->installment_name . '</td>'; $html .= '<td width="58">' . date('d-m-y', strtotime($schedule->due_date)) . '</td>'; $html .= '<td width="65">' . number_format($schedule->due_amount) . '</td>'; $html .= '<td width="65">' . number_format($schedule->splitup_amount) . '</td>'; $html .= '<td width="58">' . date('d-m-y', strtotime($schedule->date_payment)) . '</td>'; $html .= '<td width="45">' . $schedule->receipt_number . '</td>'; $html .= '<td width="58">' . $schedule->dpc_grace_period . '</td>'; $html .= '<td width="53">' . $delayed_days . '</td>'; $html .= '<td width="44">' . number_format($schedule->dpc_interest) . '</td>'; $html .= ' <td width="58">'; $html .= '<span>' . number_format($dpc) . '</span>'; $html .= '</td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr style="font-weight: bolder">'; $html .= '<td width="578" colspan="10"></td>'; $html .= '<td width="58">' . number_format($total_dpc) . '</td>'; $html .= '</tr>'; $html .= '</tfoot>'; $html .= '</table><br /><br />'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->AddPage(); $html = ''; $html .= '<h3 style="padding: 10px; text-align:center"><u>DPC Due on Balance Amount </u></h3>'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="30"><b>No.</b></th>'; $html .= '<th width="124"><b>Installment Name</b></th>'; $html .= '<th width="65"><b>Due Date</b></th>'; $html .= '<th width="70"><b>Due Amount</b></th>'; $html .= '<th width="82"><b>Due Amount Balance</b></th>'; $html .= '<th width="65"><b>Gr Period</b></th>'; $html .= '<th width="65"><b>Delayed Days</b></th>'; $html .= '<th width="65"><b>DPC % </b></th>'; $html .= '<th width="70"><b>DPC Due </b></th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_dpc_bal = 0; foreach ($actual_payment_schedule as $schedule) { $balance_amt = $schedule->due_amount - $schedule->amount_paid; if ($balance_amt > 0) { $datetime1 = date_create($schedule->due_date); $datetime2 = date_create($due_date_db); $interval = date_diff($datetime1, $datetime2); $delayed_days = $interval->format('%R%a'); if ($delayed_days <= 0) { $delayed_days = 0; } else { $delayed_days = str_replace('+', '', $delayed_days); } if ($delayed_days < $schedule->dpc_grace_period) { $dday = 0; } else { if ($crm_settings->include_grace_period == 0) { $dday = $delayed_days - $schedule->dpc_grace_period; } else { $dday = $delayed_days; } } $dpc = $balance_amt * $schedule->dpc_interest / 100; $dpc = $dpc / 365 * $dday; $total_dpc_bal += $dpc; $html .= '<tr>'; $html .= '<td width="30">' . $n . '</td>'; $html .= '<td width="124">' . $schedule->installment_name . '</td>'; $html .= '<td width="65">' . date('d-m-y', strtotime($schedule->due_date)) . '</td>'; $html .= '<td width="70">' . number_format($schedule->due_amount) . '</td>'; $html .= '<td width="82">' . number_format($balance_amt) . '</td>'; $html .= '<td width="65">' . $schedule->dpc_grace_period . '</td>'; $html .= '<td width="65">' . $delayed_days . '</td>'; $html .= '<td width="65">' . number_format($schedule->dpc_interest) . '</td>'; $html .= ' <td width="70">'; $html .= '<span>' . number_format($dpc) . '</span>'; $html .= '</td>'; $html .= '</tr>'; $n++; } } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr style="font-weight: bolder">'; $html .= '<td width="566" colspan="9"></td>'; $html .= '<td width="70">' . number_format($total_dpc_bal) . '</td>'; $html .= '</tr>'; $html .= '</tfoot>'; $html .= '</table><br /><br />'; $html .= '<table>'; $html .= '<tr>'; $html .= '<td><strong>Total DPC : </strong>' . number_format($total_dpc_bal + $total_dpc) . '</td>'; $html .= '</tr>'; $html .= '</table><br /><br />'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); } if ($show_discount == 1) { $pdf->writeHTMLCell(0, 0, '', '', $htmldis, 0, 1, 0, true, '', true); } //echo $html; //exit(); $pdf->Output('receipt.pdf', 'I'); } }
public function tax_continuous_type4($id = null, $year = null) { if (Session::get('level') != '') { $y = Input::get('y3'); if ($y != '') { $year = $y; $id = 'all'; } $pdf = new TCPDF(); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); $n = DB::select('select * from s_general_data'); foreach ($n as $k) { $name = $k->name; $address = $k->address; $address2 = $k->address2; $tax_id2 = $k->tax_id2; $director = $k->director; } $sql = ' select concat(n.pname,"",n.fname," ",n.lname) as name, s.cid, s.tax_id,sum(s.salary+s.r_other) as salary, sum(s.r_c) as r_c, sum(s.special_m+s.pts+s.pts2) as special, sum(s.tax) as tax ,sum(s.kbk) as kbk from s_salary_ocsc_detail s left join n_datageneral n on n.cid=s.cid left join n_position_salary p on p.cid=n.cid where s.cid=5350400051484 and year(s.order_date)=' . $year . ' group by s.cid order by n.datainfoID asc '; $result = DB::select($sql); foreach ($result as $key) { $pdf->AddPage('P', 'A4'); $pdf->SetFont('freeserif', 'B', 11, '', true); $pdf->MultiCell(185, 5, 'เลขที่ งป. ........................./ ' . ($year == 'null' ? $this->yearThai() : $year + 543), 0, 'R', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 16, '', true); $pdf->SetY(25); $pdf->SetX(18); $pdf->MultiCell(177, 5, 'หนังสือรับรองการหักภาษี ณ ที่จ่าย', 0, 'C', 0, 1, '', '', true); $pdf->SetY(34); $pdf->SetX(18); $pdf->MultiCell(177, 5, 'ตามมาตรา 50 ทวิ แห่งประมวลรัษฎากร', 0, 'C', 0, 1, '', '', true); //===== แนวตั้ง =====// $linever1 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(18, 190, 18, 50, $linever1); $linever2 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(80, 190, 80, 50, $linever2); $linever3 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(110, 190, 110, 50, $linever3); $linever4 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(135, 190, 135, 50, $linever4); $linever5 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(165, 190, 165, 50, $linever5); $linever6 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(195, 190, 195, 50, $linever6); //===== แนวนอน =====// $linetop = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(18, 50, 195, 50, $linetop); $linetop2 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(80, 63, 195, 63, $linetop2); $linetop3 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(18, 120, 80, 120, $linetop3); $linetop4 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(80, 180, 195, 180, $linetop4); $linetop5 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(18, 190, 195, 190, $linetop5); //======= text in box 1 ========// $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(52); $pdf->SetX(19); $pdf->MultiCell(62, 5, 'ชื่อและที่อยู่ของผู้มีหน้าที่หักภาษี ณ ที่จ่าย บุคคลคณะบุคคล นิติบุคคล ส่วนราชการ องค์การ รัฐวิสาหกิจ ฯลฯ ', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(82); $pdf->SetX(19); $pdf->MultiCell(62, 5, $address2, 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(105); $pdf->SetX(19); $pdf->MultiCell(40, 5, $tax_id2, 0, 'L', 0, 1, '', '', true); //======= text in box 2 ========// $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(122); $pdf->SetX(19); $pdf->MultiCell(62, 5, 'ชื่อและที่อยู่ของผู้ถูกหักภาษี ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 12, '', true); $pdf->SetY(137); $pdf->SetX(21); $pdf->MultiCell(59, 5, $key->name, 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(145); $pdf->SetX(19); $pdf->MultiCell(62, 5, $address, 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(165); $pdf->SetX(19); $pdf->MultiCell(62, 5, 'เลขประจำตัวผู้เสียภาษีของผู้ถูกหักภาษี ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(178); $pdf->SetX(22); $pdf->MultiCell(62, 5, $key->cid, 0, 'L', 0, 1, '', '', true); //======= text in box 3 header content ========// $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(54); $pdf->SetX(83); $pdf->MultiCell(32, 5, 'เงินได้ที่จ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(54); $pdf->SetX(111); $pdf->MultiCell(32, 5, 'ปีภาษีที่จ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(54); $pdf->SetX(138); $pdf->MultiCell(32, 5, 'จำนวนเงิน', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(54); $pdf->SetX(167); $pdf->MultiCell(32, 5, 'ภาษีที่หักไว้', 0, 'L', 0, 1, '', '', true); //============= text in content ================// $pdf->SetFont('freeserif', '', 12, '', true); //-----col 1 $pdf->SetY(70); $pdf->SetX(80); $pdf->MultiCell(30, 5, 'เงินเดือน ค่าจ้าง บำนาญ เบี้ยเลี้ยง โบนัส ตามมาตรา 40(1)', 0, 'L', 0, 1, '', '', true); $pdf->SetY(95); $pdf->SetX(80); $pdf->MultiCell(31, 5, 'เงินประจำตำแหน่ง', 0, 'L', 0, 1, '', '', true); $pdf->SetY(104); $pdf->SetX(80); $pdf->MultiCell(27, 5, 'เงินค่าตอบแทนพิเศษ พตส ค่าครองชีพ', 0, 'L', 0, 1, '', '', true); //-----col 2 $pdf->SetY(70); $pdf->SetX(116); $pdf->MultiCell(31, 5, $year == 'null' ? $this->yearThai() : $year + 543, 0, 'L', 0, 1, '', '', true); //-----col 3 $pdf->SetY(70); $pdf->SetX(135); $pdf->MultiCell(30, 5, number_format($key->salary, 2), 0, 'R', 0, 1, '', '', true); $pdf->SetY(95); $pdf->SetX(135); $pdf->MultiCell(30, 5, number_format($key->r_c, 2), 0, 'R', 0, 1, '', '', true); $pdf->SetY(104); $pdf->SetX(135); $pdf->MultiCell(30, 5, number_format($key->special, 2), 0, 'R', 0, 1, '', '', true); //-----col 4 $pdf->SetY(70); $pdf->SetX(165); $pdf->MultiCell(30, 5, number_format($key->tax, 2), 0, 'R', 0, 1, '', '', true); //============= text in box 4 footer sum ============// $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(182); $pdf->SetX(89); $pdf->MultiCell(32, 5, 'รวม', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(182); $pdf->SetX(135); $pdf->MultiCell(30, 5, number_format($key->salary + $key->special + $key->r_c, 2), 0, 'R', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(182); $pdf->SetX(165); $pdf->MultiCell(30, 5, number_format($key->tax, 2), 0, 'R', 0, 1, '', '', true); //============= text footer ================// $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(195); $pdf->SetX(22); $pdf->MultiCell(32, 5, 'ผู้จ่ายเงิน', 0, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(39); $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(44); $pdf->MultiCell(30, 5, '(1) หัก ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(73); $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(78); $pdf->MultiCell(35, 5, '(2) ออกให้ตลอดไป', 0, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(112); $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true); $pdf->SetY(195); $pdf->SetX(117); $pdf->MultiCell(35, 5, '(3) ออกให้ครั้งเดียว', 0, 'L', 0, 1, '', '', true); $pdf->SetY(205); $pdf->SetX(39); $pdf->MultiCell(5, 5, ' /', 1, 'L', 0, 1, '', '', true); $pdf->SetY(205); $pdf->SetX(44); $pdf->MultiCell(100, 5, '(4) เงินสบทบกองทุนประกันสังคม ' . ' ' . number_format($key->kbk, 2) . ' บาท', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 12, '', true); $pdf->SetY(220); $pdf->SetX(18); $pdf->MultiCell(177, 5, 'ข้าพเจ้าขอรับรองว่า ข้อความและตัวเลขดังกล่าวข้างต้นนี้ถูกต้องตามความเป็นจริงทุกประการ', 0, 'R', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(235); $pdf->SetX(32); $pdf->MultiCell(170, 5, 'ลงชื่อ...........................................................ผู้มีหน้าที่หักภาษี ณ ที่จ่าย', 0, 'C', 0, 1, '', '', true); $pdf->SetY(245); $pdf->SetX(32); $pdf->MultiCell(140, 5, $director, 0, 'C', 0, 1, '', '', true); $pdf->SetY(255); $pdf->SetX(32); $pdf->MultiCell(140, 5, 'ทันตแพทย์เชี่ยวชาญ ปฎิบัติราชการแทน', 0, 'C', 0, 1, '', '', true); $pdf->SetY(265); $pdf->SetX(32); $pdf->MultiCell(140, 5, 'ผู้อำนวยการโรงพยาบาลโนนไทย', 0, 'C', 0, 1, '', '', true); } $filename = storage_path() . '/report_tax_continuous_emp4.pdf'; // Response::download($filename); $contents = $pdf->output($filename, 'I'); $headers = array('Content-Type' => 'application/pdf'); return Response::make($contents, 200, $headers); } else { return View::make('login.index'); } }
/** * Render * * @param string $type * @return string */ public function render($type) { $result = ''; $session = new session(); // main switch switch ($type) { case 'pdf': // document properties $this->header['pdf']['orientation'] = isset($this->header['pdf']['orientation']) ? $this->header['pdf']['orientation'] : 'P'; $this->header['pdf']['unit'] = 'mm'; $this->header['pdf']['format'] = isset($this->header['pdf']['format']) ? $this->header['pdf']['format'] : 'LETTER'; $this->header['pdf']['encoding'] = isset($this->header['pdf']['encoding']) ? $this->header['pdf']['encoding'] : 'UTF-8'; $this->header['pdf']['font'] = isset($this->header['pdf']['font']) ? $this->header['pdf']['font'] : array('family' => 'helvetica', 'style' => '', 'size' => 8); //include 'tcpdf/tcpdf.php'; // create new PDF document $pdf = new TCPDF($this->header['pdf']['orientation'], $this->header['pdf']['unit'], $this->header['pdf']['format'], true, $this->header['pdf']['encoding'], false); // set margins $pdf->SetMargins(0, 0, 0); $pdf->setPrintHeader(false); // disable auto break $pdf->SetAutoPageBreak(false, 0); // set default font subsetting mode $pdf->setFontSubsetting(true); // set color for background $pdf->SetFillColor(255, 255, 255); // set font $pdf->SetFont($this->header['pdf']['font']['family'], $this->header['pdf']['font']['style'], $this->header['pdf']['font']['size']); // stats $page_counter = 1; $page_y = 0; $flag_new_page = true; $flag_filter = true; $flag_first_row = true; $columns = array(); $all_columns = array(); // gethering all columns foreach ($this->data as $k => $v) { if ($v['t'] == 'columns') { $all_columns[] = $v; } } // looping through the data foreach ($this->data as $k => $v) { if ($v['t'] == 'columns') { continue; } if ($flag_new_page) { // add new page $pdf->AddPage($this->header['pdf']['orientation'], '', true); // drawing header $pdf->MultiCell(40, 5, format::datetime(format::now()), 0, 'L', 1, 0, 5, 5, true, 0, false, true, 10, 'T'); // company + book name $pw = $pdf->getPageWidth(); $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); // todo: fix here $pdf->MultiCell($pw - 90, 5, $session->company_name . ': ' . $session->book_name, 0, 'C', 1, 0, 40, 5, true, 0, false, true, 10, 'T'); // page counter $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']); $pdf->MultiCell(40, 5, 'Page ' . $page_counter, 0, 'R', 1, 0, $pw - 45, 5, true, 0, false, true, 10, 'T'); // report name $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); $report_name = $this->header['name'] . ' (' . implode('-', application::get(array('mvc', 'controllers'))) . ')'; $pdf->MultiCell($pw - 10, 5, $report_name, 0, 'L', 1, 0, 5, 10, true, 0, false, true, 10, 'T'); if (isset($this->header['description'])) { $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); $pdf->MultiCell(205, 5, $this->header['description'], 0, 'L', 1, 0, 5, 15, true, 0, false, true, 10, 'T'); $page_y = 25; } else { $page_y = 20; } // if we need to add a filter if ($flag_filter) { if (isset($this->header['filter'])) { foreach ($this->header['filter'] as $k2 => $v2) { $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); $pdf->MultiCell(50, 5, $k2 . ':', 0, 'L', 1, 0, 5, $page_y, true, 0, false, true, 10, 'T'); $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']); $number_of_cells = $pdf->MultiCell($pdf->getPageWidth() - 60, 5, $v2, 0, 'L', 1, 0, 55, $page_y, true, 0, false, true, 10, 'T'); if ($number_of_cells > 1) { $page_y += 5 * ($number_of_cells - 1); } $page_y += 5; } } $flag_filter = false; // adding one line space $page_y += 5; } // page counter $page_counter++; $flag_new_page = false; } // rendering rows if ($flag_first_row) { if (empty($columns)) { $columns = current($all_columns); // repopulate width $count_empty = 0; $taken = 0; foreach ($columns['d'] as $k2 => $v2) { if (empty($v2['w'])) { $count_empty++; } else { $taken += $v2['w']; } } if (!empty($count_empty)) { $new_width = floor(($pdf->getPageWidth() - 10 - $taken) / $count_empty); foreach ($v['d'] as $k2 => $v2) { $columns['d'][$k2]['w'] = $new_width; } } } $flag_first_row = false; // columns foreach ($all_columns as $k20 => $v20) { $x = 5; foreach ($columns['d'] as $k10 => $v10) { foreach (array('v', 'c', 'a', 'b', 's', 't', 'u') as $v30) { if (isset($v20['d'][$k10][$v30])) { $v10[$v30] = $v20['d'][$k10][$v30]; } } $new_width = @$v10['w']; if (!empty($v10['c'])) { // we need to get width of next elements for ($i = $k10 + 1; $i < $k10 + $v10['c']; $i++) { $new_width += $columns['d'][$k10]['w']; } } $align = str_replace(array('left', 'right', 'center'), array('L', 'R', 'C'), @$v10['a']); if (empty($align)) { $align = 'L'; } if (@$v10['b']) { $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); } else { $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']); } $pdf->MultiCell($new_width, 5, @$v10['v'], $this->flag_pdf_show_borders, $align, 1, 0, $x, $page_y, true, 0, false, true, 10, 'T'); // underline if (@$v10['u']) { $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->Line($x, $page_y + 5, $x + @$v10['w'], $page_y + 5); } $x += @$v10['w']; } $page_y += 5; } } $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']); $x = 5; foreach ($columns['d'] as $k10 => $v10) { // we do do render cells if no data if (isset($v['d'][$k10]['v'])) { $align = str_replace(array('left', 'right', 'center'), array('L', 'R', 'C'), @$v['d'][$k10]['a']); if (empty($align)) { $align = 'L'; } if (@$v['d'][$k10]['b']) { $pdf->SetFont($this->header['pdf']['font']['family'], 'B', $this->header['pdf']['font']['size']); } else { $pdf->SetFont($this->header['pdf']['font']['family'], '', $this->header['pdf']['font']['size']); } // if we override width $width = $v10['w']; if (isset($v['d'][$k10]['w'])) { $width = $v['d'][$k10]['w']; } else { if (isset($v['d'][$k10]['c'])) { // colspan // we need to get width of next elements for ($i = $k10 + 1; $i < $k10 + $v['d'][$k10]['c']; $i++) { $width += @$columns['d'][$i]['w']; } } } $value = @$v['d'][$k10]['v']; $value = str_replace(' ', ' ', $value); // rendering cell $pdf->MultiCell($width, 5, $value, $this->flag_pdf_show_borders, $align, 1, 0, $x, $page_y, true, 0, false, true, 10, 'T'); // underline if (@$v['d'][$k10]['u']) { $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->Line($x, $page_y + 5, $x + $v10['w'], $page_y + 5); } // subtotal if (@$v['d'][$k10]['s']) { $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->Line($x + 1, $page_y, $x + $v10['w'] - 1, $page_y); } // total if (@$v['d'][$k10]['t']) { $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))); $pdf->Line($x + 1, $page_y, $x + $v10['w'] - 1, $page_y); $pdf->Line($x + 1, $page_y - 0.75, $x + $v10['w'] - 1, $page_y - 0.75); } } $x += @$v10['w']; } // incrementing $page_y += 5; if ($page_y > $pdf->getPageHeight() - 10) { $flag_new_page = true; $flag_first_row = true; } } $pdf->Output($this->header['name'] . '.pdf', 'I'); exit; break; case 'csv': case 'txt': case 'xlsx': $sheet = strip_tags($this->header['name']); $sheet = str_replace(['/', '\\'], '', $sheet); // generating header $header = []; $header[$sheet][] = [format::datetime(format::now()), '', $session->company_name . ': ' . $session->book_name, '', 'Page 1']; $controllers = application::get(['mvc', 'controllers']); $header[$sheet][] = [strip_tags($this->header['name']) . ' (' . implode('-', $controllers) . ')']; if (isset($this->header['description'])) { $header[$sheet][] = [$this->header['description']]; } $header[$sheet][] = [' ']; $temp = $header; // displaying filter if (isset($this->header['filter'])) { $temp2 = []; foreach ($this->header['filter'] as $k => $v) { $temp[$sheet][] = [strip_tags($k), strip_tags($v)]; } $temp[$sheet][] = [' ']; } // converting data foreach ($this->data as $k => $v) { $temp2 = []; foreach ($v['d'] as $k2 => $v2) { if (is_array($v2)) { $value = $v2['v'] ?? null; } else { $value = $v2; } // replaces $value = str_replace(' ', ' ', $value); $temp2[] = strip_tags($value); } $temp[$sheet][] = $temp2; } // get output buffering helper_ob::clean_all(); // content switch ($type) { case 'xlsx': echo io::array_to_excel($temp, io::$formats[$type]['excel_code'], null); break; default: // csv or text header('Content-Type: ' . numbers_frontend_exports_csv_base::$formats[$type]['content_type']); header('Content-Disposition: attachment; filename="' . $sheet . '.' . $type . '"'); header('Cache-Control: max-age=0'); echo numbers_frontend_exports_csv_base::array_to_csv($temp, numbers_frontend_exports_csv_base::$formats[$type]['delimiter'], numbers_frontend_exports_csv_base::$formats[$type]['enclosure']); } exit; break; case 'html': case 'html2': default: // rendering data $table = ['options' => []]; $counter = 1; foreach ($this->data as $k => $v) { $flag_colspan = 0; $row = []; if (!empty($v['d'])) { foreach ($v['d'] as $k2 => $v2) { if ($flag_colspan > 0) { $flag_colspan--; continue; } $colspan = ''; if ($v2['c'] ?? null) { $colspan = $v2['c']; $flag_colspan = $v2['c'] - 1; } $align = 'left'; $title = ''; $style = ''; if (is_array($v2)) { $value = $v2['v'] ?? null; if (!empty($v2['h'])) { $v2['h']['value'] = $value; $value = html::a($v2['h']); } if (!empty($v2['a'])) { $align = $v2['a']; } if (!empty($v2['l'])) { $title = $v2['l']; } // bold lines if ($v2['b'] ?? null) { $value = '<b>' . $value . '</b>'; } // todo: convert styles to classes if ($v2['s'] ?? null) { $style .= 'border-top: 1px solid #000;'; } if ($v2['t'] ?? null) { $style .= 'border-top: 3px double #000;'; } if ($v2['u'] ?? null) { $style .= 'border-bottom: 1px solid #000;'; } } else { $value = $v2; } $row[$k2] = ['value' => $value, 'align' => $align, 'colspan' => $colspan, 'style' => $style, 'title' => $title, 'nowrap' => true]; } } else { $row[0] = ['value' => ' ']; } $table['options'][$counter] = $row; $counter++; } $result = html::table($table); // printable export if ($type == 'html2') { $header = ['options' => []]; $header['options'][] = [0 => format::datetime(format::now()), 1 => '', 2 => $session->company_name . ': ' . $session->book_name, 3 => '', 4 => 'Page 1']; $controllers = application::get(['mvc', 'controllers']); $header['options'][] = [['value' => strip_tags($this->header['name']) . ' (' . implode('-', $controllers) . ')', 'colspan' => 5]]; if (isset($this->header['description'])) { $header['options'][] = [$this->header['description']]; } $header['options'][] = [' ']; // displaying filter if (isset($this->header['filter'])) { $temp2 = []; foreach ($this->header['filter'] as $k => $v) { $header['options'][] = [strip_tags($k) . ':', strip_tags($v)]; } $header['options'][] = [' ']; } $header = html::table($header); layout::render_as($header . $result, 'text/html'); } } return $result; }
$pdf->MultiCell($lwidth, 0, $cx, 1, 'C', 0, 1, '', '', true); //dc_YDown(1); if ($k == 0) { $lheight += $pdf->getLastH(); } } if ($plbcode == 'Y') { $pl = true; dc_YDown(1); $pdf->SetX($x); $ty1 = $pdf->GetY(); $pdf->write1DBarcode($b['barcode'], 'C39', '', '', $lwidth, 9, 0.4, $style, 'N'); $ty2 = $pdf->GetY(); //$pdf->Line($x,$ty1,$x+$lwidth,$ty1); //$pdf->Line($x,$ty1,$x,$ty2); $pdf->Line($x, $ty2, $x + $lwidth, $ty2); //$pdf->Line($x+60,$ty1,$x+60,$ty2); if ($k == 0) { $lheight += 10; } } // End of Print label >> if ($pl) { if ($k == 0) { $k = 1; $nrow = floor($dcPageH / $lheight); } $kol++; if ($kol == $nkol) { $kol = 0; $row++;
/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS LINESTRING object * @param string $label Label for the GIS LINESTRING object * @param string $line_color Color for the GIS LINESTRING object * @param array $scale_data Array containing data related to scaling * @param TCPDF $pdf TCPDF instance * * @return TCPDF the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { /** @var PMA_String $pmaString */ $pmaString = $GLOBALS['PMA_String']; // allocate colors $red = hexdec($pmaString->substr($line_color, 1, 2)); $green = hexdec($pmaString->substr($line_color, 3, 2)); $blue = hexdec($pmaString->substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'LINESTRING(' and trailing ')' $linesrting = $pmaString->substr($spatial, 11, $pmaString->strlen($spatial) - 12); $points_arr = $this->extractPoints($linesrting, $scale_data); foreach ($points_arr as $point) { if (!isset($temp_point)) { $temp_point = $point; } else { // draw line section $pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line); $temp_point = $point; } } // print label if (isset($label) && trim($label) != '') { $pdf->SetXY($points_arr[1][0], $points_arr[1][1]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } return $pdf; }
public function salary_sso_pdf_export() { $m = Input::get('m_sso_1'); $y = Input::get('y_sso_1'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetPrintHeader(false); // set header and footer fonts $pdf->setHeaderFont(array('freeserif', 'B', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array('freeserif', 'B', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(10, 15, 10); $pdf->SetHeaderMargin(15); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetFont('freeserif', '', 14, '', true); $n = DB::select('select * from s_general_data'); foreach ($n as $k) { $name = $k->name; } $sql = ' select s.cid, concat(n.pname,"",n.fname," ",n.lname) as name, (s.salary+s.salary_other) as salary, s.salary_sso '; $sql .= ' from s_salary_detail s'; $sql .= ' left join n_datageneral n on n.cid=s.cid'; $sql .= ' where year(order_date)=' . $y . ' and month(order_date)=' . $m . ' '; $data = DB::Select($sql); $j = 0; $row = 0; $sum1 = 0; $sum2 = 0; foreach ($data as $k) { $row++; if ($j == 30) { $j = 0; } if ($j == 0) { $pdf->AddPage('', 'A4'); //header $pdf->SetFont('freeserif', '', 12, '', true); $pdf->SetY(5); $pdf->SetX(160); $pdf->MultiCell(40, 5, 'สปส.1-10 (ส่วนที่ 2)', 0, 'R', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 14, '', true); $pdf->MultiCell(190, 5, 'แบบรายงานการแสดงการส่งเงินสมทบ ', 0, 'C', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(18); $pdf->MultiCell(190, 5, 'การนำส่งเงินสมทบสำหรับค่าจ้างเดิอน ' . $this->get_monthyearThai($m, $y), 0, 'C', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(30); $pdf->SetX(10); $pdf->MultiCell(40, 5, 'ชื่อสถานประกอบการ ', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(30); $pdf->SetX(50); $pdf->MultiCell(70, 5, $name, 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(30); $pdf->SetX(140); $pdf->MultiCell(22, 5, 'เลขที่บัญชี', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(30); $pdf->SetX(163); $pdf->MultiCell(25, 5, '1090000219', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(36); $pdf->SetX(140); $pdf->MultiCell(22, 5, 'สาขา', 0, 'L', 0, 1, '', '', true); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(36); $pdf->SetX(163); $pdf->MultiCell(25, 5, '300311', 0, 'L', 0, 1, '', '', true); $linever = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0)); $pdf->Line(200, 43, 10, 43, $linever); $pdf->Line(200, 50, 10, 50, $linever); $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(43); $pdf->SetX(10); $pdf->MultiCell(20, 7, 'ลำดับที่', 0, 'C', 0, 1, '', '', true); $pdf->SetY(43); $pdf->SetX(30); $pdf->MultiCell(40, 7, 'เลขประจำตัวประชาชน', 0, 'C', 0, 1, '', '', true); $pdf->SetY(43); $pdf->SetX(70); $pdf->MultiCell(70, 7, 'ชื่อ-สกุล', 0, 'C', 0, 1, '', '', true); $pdf->SetY(43); $pdf->SetX(140); $pdf->MultiCell(30, 7, 'ค่าจ้าง', 0, 'R', 0, 1, '', '', true); $pdf->SetY(43); $pdf->SetX(170); $pdf->MultiCell(30, 7, 'เงินสมทบ', 0, 'R', 0, 1, '', '', true); } //end add header //detail $pdf->SetY(50 + $j * 7.5); $pdf->SetX(10); $pdf->MultiCell(20, 7, $row, 0, 'R', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(30); $pdf->MultiCell(40, 7, $k->cid, 0, 'C', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(70); $pdf->MultiCell(70, 7, $k->name, 0, 'L', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(140); $pdf->MultiCell(30, 7, number_format($k->salary, 2), 0, 'R', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(170); $pdf->MultiCell(30, 7, number_format($k->salary_sso, 2), 0, 'R', 0, 1, '', '', true); //end detail $sum1 = $sum1 + $k->salary; $sum2 = $sum2 + $k->salary_sso; $j++; } // end data //sum all $pdf->Line(200, 50 + $j * 7.5, 10, 50 + $j * 7.5, $linever); $pdf->Line(200, 56 + $j * 7.5, 10, 57 + $j * 7.5, $linever); $pdf->SetFont('freeserif', 'B', 13, '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(70); $pdf->MultiCell(70, 7, 'ยอดรวม', 0, 'C', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(140); $pdf->MultiCell(30, 7, number_format($sum1, 2), 0, 'R', 0, 1, '', '', true); $pdf->SetY(50 + $j * 7.5); $pdf->SetX(170); $pdf->MultiCell(30, 7, number_format($sum2, 2), 0, 'R', 0, 1, '', '', true); //end sum all // $pdf->SetFont('freeserif', '', 13, '', true); $pdf->SetY(62 + $j * 7.5); $pdf->SetX(70); $pdf->MultiCell(90, 5, 'ลงชื่อ.............................................................', 0, 'R', 0, 1, '', '', true); $pdf->SetY(62 + $j * 7.5); $pdf->SetX(160); $pdf->MultiCell(43, 5, 'นายจ้าง/ผู้รับมอบอำนาจ', 0, 'R', 0, 1, '', '', true); $pdf->SetY(70 + $j * 7.5); $pdf->SetX(70); $pdf->MultiCell(90, 5, '(.............................................................)', 0, 'R', 0, 1, '', '', true); $pdf->SetY(82 + $j * 7.5); $pdf->SetX(70); $pdf->MultiCell(120, 5, 'ยื่นแบบวันที่.............เดือน..............................พ.ศ..............', 0, 'C', 0, 1, '', '', true); $filename = storage_path() . '/salary_sso_pdf_export.pdf'; // Response::download($filename); $contents = $pdf->output($filename, 'I'); $headers = array('Content-Type' => 'application/pdf'); return Response::make($contents, 200, $headers); }
function customer_aging_report() { $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'project_model')); $this->load->library('form_validation'); $this->load->helper(array('csv', 'download')); $data['projects'] = $this->db->get('project')->result(); $this->form_validation->set_rules('due_date', 'Date', 'trim|required'); if ($this->form_validation->run() == FALSE) { $data['dues'] = array(); $this->load->view('reports/customer_wise_aging', $data); } else { $dues = array(); $project_selected = $this->input->post('project'); $with_tax_selected = $this->input->post('with_tax'); $due_date_db = $this->input->post('due_date'); $due_date_selected = $due_date_db; $due_date_db = date('Y-m-d', strtotime($due_date_db)); $due_report = array(); $this->db->select('customer_file.id,customer_file.purchase_cost,contact.name,project.name as project,availability_chart_unit.unit_name as unit_name'); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'customer_file.project_id=project.id'); $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id'); $this->db->where('customer_file.project_id', $project_selected); $this->db->where('customer_file.approval_status', 1); $customers = $this->db->get()->result(); foreach ($customers as $customer) { $due_report[$customer->id] = array(); $due_report[$customer->id]['client_name'] = $customer->name; $due_report[$customer->id]['project'] = $customer->project . '-' . $customer->unit_name; $due_report[$customer->id]['purchase_cost'] = $customer->purchase_cost; $due_report[$customer->id]['total_tax'] = 0; $due_report[$customer->id]['due_amount'][1] = 0; $due_report[$customer->id]['due_amount'][2] = 0; $due_report[$customer->id]['due_amount'][3] = 0; $due_report[$customer->id]['due_amount'][4] = 0; $due_report[$customer->id]['due_amount'][5] = 0; $due_report[$customer->id]['due_amount'][6] = 0; $due_report[$customer->id]['due_amount'][7] = 0; $due_report[$customer->id]['total_due_amount'] = 0; $due_report[$customer->id]['total_pri'] = 0; $due_report[$customer->id]['total_tx'] = 0; $due_report[$customer->id]['total_amt'] = 0; $due_report[$customer->id]['total_units'] = $this->db->where('project_id', $customer->id)->count_all_results('customer_file'); $customer_file_id = $customer->id; $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual_active($customer_file_id); $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional_active($customer_file_id); $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id); $this->db->select('tax_type.name,tax_master.id'); $this->db->from('tax_type'); $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id'); $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id'); $this->db->where('customer_file_tax.customer_file_id', $customer_file_id); $customer_tax = $this->db->get()->result(); $total_due_amount = 0; // Actual Due foreach ($actual_payment_schedule as $schedule) { $total_due_amount += $schedule->due_amount; $ttax = 0; $ttax_bal = 0; $date1 = strtotime($schedule->due_date); // or your date as well $date2 = strtotime($due_date_db); $datediff = $date2 - $date1; $delay = floor($datediff / (60 * 60 * 24)); //echo $schedule->due_date . ' - ' . $due_date_db . ' - ' . $delay . '<br />'; $tax_amount_tot = 0; if ($with_tax_selected == 1) { foreach ($customer_tax as $cs2) { $tax_amount = 0; $tax_amount_bal = 0; if ($schedule->due_amount - $schedule->amount_paid != 0) { $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = ($schedule->due_amount - $schedule->amount_paid) / 100 * $applicale_tax->tax_percentage; $tax_amount_tot += $tax_amount; } } } } else { $tax_amount = 0; } $due_report[$customer->id]['total_due_amount'] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; if ($delay < 90) { $due_report[$customer->id]['due_amount'][1] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay >= 90 and $delay < 180) { $due_report[$customer->id]['due_amount'][2] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay >= 180 and $delay < 270) { $due_report[$customer->id]['due_amount'][3] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay >= 270 and $delay < 365) { $due_report[$customer->id]['due_amount'][4] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay >= 365 and $delay < 540) { $due_report[$customer->id]['due_amount'][5] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay >= 540 and $delay < 720) { $due_report[$customer->id]['due_amount'][6] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } if ($delay > 720) { $due_report[$customer->id]['due_amount'][7] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot; } } // Additional Due foreach ($additional_payment_schedule as $schedule_additional) { $total_due_amount += $schedule_additional->due_amount; $ttax = 0; $ttax_bal = 0; $date1 = strtotime($schedule_additional->due_date); // or your date as well $date2 = strtotime($due_date_db); $datediff = $date2 - $date1; $delay = floor($datediff / (60 * 60 * 24)); $tax_amount_tot = 0; if ($with_tax_selected == 1) { foreach ($customer_tax as $cs2) { $tax_amount = 0; $tax_amount_bal = 0; if ($schedule_additional->due_amount - $schedule_additional->amount_paid != 0) { $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = ($schedule_additional->due_amount - $schedule_additional->amount_paid) / 100 * $applicale_tax->tax_percentage; $tax_amount_tot += $tax_amount; } } } } else { $tax_amount = 0; } //echo $schedule_additional->due_date . ' - ' . $due_date_db . ' - ' . $delay . '<br />'; if ($delay < 90) { $due_report[$customer->id]['due_amount'][1] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay >= 90 and $delay < 180) { $due_report[$customer->id]['due_amount'][2] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay >= 180 and $delay < 270) { $due_report[$customer->id]['due_amount'][3] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay >= 270 and $delay < 365) { $due_report[$customer->id]['due_amount'][4] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay >= 365 and $delay < 540) { $due_report[$customer->id]['due_amount'][5] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay >= 540 and $delay < 720) { $due_report[$customer->id]['due_amount'][6] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } if ($delay > 720) { $due_report[$customer->id]['due_amount'][7] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot; } } //Receipts foreach ($receipts as $b => $receipt) { $due_report[$customer->id]['total_pri'] += $receipt->principle_amount; $due_report[$customer->id]['total_tx'] += $receipt->amount_paid - $receipt->principle_amount; $due_report[$customer->id]['total_amt'] += $receipt->amount_paid; } } //print_r($due_report); //exit(); if (isset($_POST['generate_pdf'])) { $this->load->library('Pdf'); $this->db->select('company.name,project.project_type'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $company_details = $this->db->get()->first_row(); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 7, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); if ($with_tax_selected == 1) { $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Customer Wise Aging Report - With Tax</h2>', 0, 1, 0, true, '', true); } else { $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Customer Wise Aging Report - without Tax</h2>', 0, 1, 0, true, '', true); } $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $pdf->writeHTMLCell(35, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($due_date_db)) . '</strong>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true); $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="25">No.</th>'; $html .= '<th width="75">Client Name</th>'; $html .= '<th width="60">0-3 Month</th>'; $html .= '<th width="60">3-6 Month</th>'; $html .= '<th width="60">6-9 Month</th>'; $html .= '<th width="60">9-12 Month</th>'; $html .= '<th width="60">1-1.5 Yrs</th>'; $html .= '<th width="60">1.5-2 Yrs</th>'; $html .= '<th width="60">Above 2 Yrs</th>'; $html .= '<th width="60">Total</th>'; $html .= '<th width="60">Tools</th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_sale_amount = 0; $total_due_amount = 0; $total_due_amount_additional = 0; $total_due_tax = 0; $total_due_tax_additional = 0; $total_collection = 0; $total_balance = 0; foreach ($due_report as $due) { $dues = $due['due_amount']; $html .= '<tr>'; $html .= '<td width="25">' . ($n + 1) . '</td>'; $html .= '<td width="75">' . $due['client_name'] . '</td>'; foreach ($dues as $d => $du) { $html .= '<td width="60">' . number_format($du) . '</td>'; } $html .= '<td width="60">' . number_format($due['total_due_amount']) . '</td>'; $html .= '<td width="60"></td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '</table><br /><br />'; //echo $html; //exit(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); } elseif (isset($_POST['generate_csv'])) { $csv_array = array(); $csv_array_line = array(); $csv_array_line[] = 'No.'; $csv_array_line[] = 'Client Name'; $csv_array_line[] = '0-3 Month'; $csv_array_line[] = '3-6 Month'; $csv_array_line[] = '6-9 Month'; $csv_array_line[] = '9-12 Month'; $csv_array_line[] = '1-1.5 Yrs'; $csv_array_line[] = '1.5-2 Yrs'; $csv_array_line[] = 'Above 2 Yrs'; $csv_array_line[] = 'Total'; $csv_array[] = $csv_array_line; $csv_array_line = array(); $n = 1; foreach ($due_report as $due) { $total_due = 0; $dues = $due['due_amount']; $csv_array_line = array(); $csv_array_line[] = $n; $csv_array_line[] = $due['client_name']; foreach ($dues as $d => $du) { $total_due += $du; $csv_array_line[] = $du; } $csv_array_line[] = $due['total_due_amount']; $csv_array[] = $csv_array_line; $n = $n + 1; } echo array_to_csv($csv_array, 'interaction_report.csv'); exit; } else { $data['due_report'] = $due_report; $data['with_tax_selected'] = $with_tax_selected; $data['project_selected'] = $project_selected; $data['due_date_selected'] = $due_date_selected; $this->load->view('reports/customer_wise_aging', $data); } } }
function project_details($customer_file_id) { $this->load->library('Pdf'); $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'discount_model')); $this->db->select('contact.name as customer_name,project.name as project_name,availability_chart_unit.unit_name as unit_name,' . 'customer_file.purchase_cost,customer_file.area,customer_file.rate'); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'project.id=customer_file.project_id'); $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id'); $this->db->where('customer_file.id', $customer_file_id); $project_details = $this->db->get()->first_row(); // print_r($project_details);exit(0); $land_cost = $this->db->select('cost')->where(array('customer_file_id' => $customer_file_id, 'cost_head_id' => '14'))->get('customer_file_unit_costing')->first_row(); $this->db->select('company.name,company.address,project.project_type'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $this->db->where('customer_file.id', $customer_file_id); $company_details = $this->db->get()->first_row(); $crm_settings = $this->db->get('crm_settings')->first_row(); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 8, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(211, 12, '0', 15, '<p style="text-align:center;">' . $company_details->address . '</p>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(211, 8, '0', 20, '<p style="text-align:center;">' . 'www.olivebuilder.com' . '</p>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;"> WWF Report </h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $html = '<br /><br />'; $html .= '<table cellpadding="5" ><tr><td width="448"><strong> Customer Name : </strong>' . $project_details->customer_name . '</td>'; $html .= '<td><strong> Date :</strong> ' . date('m-d-Y') . '</td></tr>'; $html .= '<tr><td><strong> Project :</strong> ' . $project_details->project_name . '</td>'; if ($company_details->project_type == 1) { $html .= '<td><strong> Flat No :</strong> ' . $project_details->unit_name . '</td></tr>'; } else { $html .= '<td><strong> Villa No :</strong> ' . $project_details->unit_name . '</td></tr>'; } $html .= '<tr><td></td><td><td/></tr></table><br /><br />'; $html .= '<table cellpadding="5" align="center" border="1"><tr><td width="35%"><strong> Construction Cost :</strong> ' . ($project_details->purchase_cost - $land_cost->cost) . '</td>'; $html .= '<td width="35%"><strong> Land Cost :</strong> ' . round($land_cost->cost) . '</td>'; $html .= '<td width="35%"><strong> Purchase Cost :</strong> ' . round($project_details->purchase_cost) . '</td></tr></table><br />'; $html .= '<br /><br />'; $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); }
function customer_wise() { $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->load->library('form_validation'); $this->load->model('project_model'); $this->load->helper(array('csv', 'download')); $this->form_validation->set_rules('project', 'Project', 'trim|required'); $data['projects'] = $this->db->get('project')->result(); $data['tax_types'] = $this->db->get('tax_type')->result(); if ($this->form_validation->run() == FALSE) { $data['collections'] = array(); $this->load->view('reports/customer_wise_loan_report', $data); } else { $tax_types = $this->db->get('tax_type')->result(); $project_selected = $this->input->post('project'); $date_to = $this->input->post('date_to'); $date_to = date('Y-m-d', strtotime($date_to)); $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->db->select('company.name,project.project_type,project.name as project'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $this->db->where('project.id', $project_selected); $company_details = $this->db->get()->first_row(); $this->db->select('contact.name as customer_name,project.name as project,' . 'customer_file.purchase_cost,bank.name as bank,customer_file.branch,' . 'customer_file.loan_amount,' . 'customer_file.id as customer_file_id'); $this->db->from('customer_file'); $this->db->join('project', 'project.id=customer_file.project_id'); $this->db->join('contact', 'contact.id=customer_file.customer_id'); $this->db->join('bank', 'bank.id=customer_file.bank', 'left'); $this->db->where('customer_file.project_id', $project_selected); $this->db->where('customer_file.finance_mode', 1); $this->db->where('customer_file.booking_date <=', $date_to); $this->db->group_by('customer_file.id'); $collection_report = $this->db->get()->result(); if (isset($_POST['generate_pdf'])) { $this->load->library('Pdf'); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 8, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Customer Wise Loan Report - ' . $company_details->project . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $pdf->writeHTMLCell(38, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($date_to)) . '</strong>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(35, 0, 161, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true); $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="30">No.</th>'; $html .= '<th width="90">Customer Name</th>'; $html .= '<th width="65">Project</th>'; $html .= '<th width="85">Agreement Value</th>'; $html .= '<th width="75">Bank Name</th>'; $html .= '<th width="74">Branch</th>'; $html .= '<th width="80">Loan Amount</th>'; $html .= '<th width="74">Loan Paid</th>'; $html .= '<th width="74">Loan Balance</th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_due_percentage = 0; $total_due_amount = 0; $total_due_tax_amount = 0; $total_balance = 0; $total_tax = array(); $total_paid = 0; $n = 1; $total_principle_amount = 0; $total_purchase_cost = 0; $total_loan_paid = 0; $total_loan = 0; $txts = array(); foreach ($collection_report as $collection) { $total_purchase_cost += $collection->purchase_cost; $total_loan += $collection->loan_amount; $total_loan_paid += $loan_amount_paid->amount_paid; $total_tax_row = 0; $this->db->select('SUM(receipt.amount_paid) as amount_paid'); $this->db->from('receipt'); $this->db->where('receipt.customer_file_id', $collection->customer_file_id); $this->db->where('receipt.finance_mode', 1); $loan_amount_paid = $this->db->get()->first_row(); $total_principle_amount += $collection->principle_amount; $html .= '<tr>'; $html .= '<td width="30">' . $n . '</td>'; $html .= '<td width="90">' . $collection->customer_name . '</td>'; $html .= '<td width="65">' . $collection->project . '</td>'; $html .= '<td width="85">' . number_format($collection->purchase_cost) . '</td>'; $html .= ' <td width="75">' . $collection->bank . '</td>'; $html .= ' <td width="74">' . $collection->branch . '</td>'; $html .= ' <td width="80">' . number_format($collection->loan_amount) . '</td>'; $html .= ' <td width="74">' . number_format($loan_amount_paid->amount_paid) . '</td>'; $html .= ' <td width="74">' . number_format($collection->loan_amount - $loan_amount_paid->amount_paid) . '</td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr style="font-weight: bolder">'; $html .= '<td colspan="3"></td>'; $html .= '<td>' . number_format($total_purchase_cost) . '</td>'; $html .= '<td colspan="2"></td>'; $html .= '<td>' . number_format($total_loan) . '</td>'; $html .= '<td>' . number_format($total_loan_paid) . '</td>'; $html .= '<td>' . number_format($total_loan - $total_loan_paid) . '</td>'; $html .= '</tr>'; $html .= '</tfoot>'; $html .= '</table><br /><br />'; //echo $html; //exit(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); } elseif (isset($_POST['generate_csv'])) { $csv_array = array(); $csv_array_line = array(); $csv_array_line[] = 'No.'; $csv_array_line[] = 'Customer Name'; $csv_array_line[] = 'Project'; $csv_array_line[] = 'Agreement Value'; $csv_array_line[] = 'Bank Name'; $csv_array_line[] = 'Branch'; $csv_array_line[] = 'Loan Amount'; $csv_array_line[] = 'Loan Paid'; $csv_array_line[] = 'Loan Balance'; $csv_array[] = $csv_array_line; $csv_array_line = array(); $n = 1; foreach ($collection_report as $collection) { $this->db->select('SUM(receipt.amount_paid) as amount_paid'); $this->db->from('receipt'); $this->db->where('receipt.customer_file_id', $collection->customer_file_id); $this->db->where('receipt.finance_mode', 1); $loan_amount_paid = $this->db->get()->first_row(); $csv_array_line = array(); $csv_array_line[] = $n; $csv_array_line[] = $collection->customer_name; $csv_array_line[] = $collection->project; $csv_array_line[] = $collection->purchase_cost; $csv_array_line[] = $collection->bank; $csv_array_line[] = $collection->branch; $csv_array_line[] = $collection->loan_amount; $csv_array_line[] = $loan_amount_paid->amount_paid; $csv_array_line[] = $collection->loan_amount - $loan_amount_paid->amount_paid; $csv_array[] = $csv_array_line; $n = $n + 1; } echo array_to_csv($csv_array, 'interaction_report.csv'); exit; } else { $data['collection_report'] = $collection_report; $data['date_from_selected'] = $this->input->post('date_from'); $data['date_to_selected'] = $this->input->post('date_to'); $data['project_selected'] = $this->input->post('project'); $this->load->view('reports/customer_wise_loan_report', $data); } } }
if ($tc[dp_Available] == '1') { $nbook = dbSRow("book", "W/`catalog`='" . $f['dcid'] . "'"); $abook = 0; if ($nbook > 0) { $abook = dbSRow("book", "W/`catalog`='" . $f['dcid'] . "' AND `available`='Y'"); $av = $abook . " of " . $nbook; } else { $av = "N/A"; } $pdf->MultiCell($tw[$i++], 0, $av, 0, 'C', 0, 0, '', '', true); } if ($pdf->getLastH() > $my) { $my = $pdf->getLastH(); } $tx = $dcMarginL; $pdf->Line($tx, $ny, $tx, $ny + $my); //$tx=$tw[0]+$dcMarginL; for ($l = 0; $l < $i; $l++) { $pdf->Line($tx + $tw[$l], $ny, $tx + $tw[$l], $ny + $my); $tx += $tw[$l]; } $pdf->Line($dcMarginL, $ny + $my, $tx, $ny + $my); $pdf->Ln(); $pdf->setY($ny + $my); } $pdf->setCellPaddings(0, 0, 0, 0); $pdf->Ln(); // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document
public function view_reserve($id) { if (Session::get('level') == '1' || Session::get('level') == '3') { $sql = ' select * from c_reserve_cars '; $sql .= ' where reserve_id =' . $id . ' '; $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // set header and footer fonts $pdf->setHeaderFont(array('angsanaupc', '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array('angsanaupc', '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(10, 10, 10); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetFont('angsanaupc', '', 14, '', true); $pdf->AddPage(); $pdf->SetXY(10, 10); $pdf->Image('images/krut.jpg', '', '', 20, 20, '', '', 'T', false, 300, '', false, false, 0, false, false, false); $pdf->SetFont('angsanaupc', 'B', 18, '', true); $pdf->SetXY(75, 20); $pdf->MultiCell(60, 0, 'บันทึกข้อความ', 0, 'C', 0, 1, '', '', true); $result = DB::select($sql); foreach ($result as $key) { $pdf->SetFont('angsanaupc', 'B', 14, '', true); $pdf->SetXY(10, 32); $pdf->MultiCell(25, 0, 'ส่วนราชการ', 0, 'L', 0, 1, '', '', true); //$pdf->SetFont('angsanaupc','',14,'',true); $pdf->SetXY(35, 32); $pdf->MultiCell(160, 0, 'ฝ่าย........................................................................................โรงพยาบาลโนนไทย อำเภอโนนไทย จังหวัดนครราชสีมา', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(44, 31); $pdf->MultiCell(65, 0, $key->department, 0, 'L', 0, 1, '', '', true); //$pdf->SetFont('angsanaupc','B',14,'',true); $pdf->SetXY(10, 40); $pdf->MultiCell(10, 0, 'ที่', 0, 'L', 0, 1, '', '', true); //$pdf->SetFont('angsanaupc','B',14,'',true); $pdf->SetXY(20, 40); $pdf->MultiCell(170, 0, 'นม 0032.301/...........................................วันที่.............................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(43, 39); $pdf->MultiCell(31, 0, $key->num_nm, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(83, 39); $pdf->MultiCell(44, 0, $key->date_nm == '0000-00-00' ? '' : $this->get_monthyearThai($key->date_nm), 0, 'L', 0, 1, '', '', true); //$pdf->SetFont('angsanaupc','B',14,'',true); $pdf->SetXY(10, 48); $pdf->MultiCell(10, 0, 'เรื่อง', 0, 'L', 0, 1, '', '', true); //$pdf->SetFont('angsanaupc','B',14,'',true); $pdf->SetXY(20, 48); $pdf->MultiCell(60, 0, ' ขออนุมัติไปราชการ', 0, 'L', 0, 1, '', '', true); $style = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 5, 'color' => array(0, 0, 0)); $pdf->Line(10, 57, 195, 57, $style); //$pdf->SetFont('angsanaupc','B',14,'',true); $pdf->SetXY(10, 62); $pdf->MultiCell(70, 0, 'เรียน ผู้อำนวยการโรงพยาบาลโนนไทย', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(20, 72); $pdf->MultiCell(176, 0, 'ด้วยข้าพเจ้า..........................................................................ตำแหน่ง...........................................................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(39, 71); $pdf->MultiCell(55, 0, $key->req_name, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(108, 71); $pdf->MultiCell(70, 0, $key->position, 0, 'L', 0, 1, '', '', true); $sql2 = ' select * from c_together where together_id=' . $key->together_id . ' '; $result2 = DB::select($sql2); $n = 0; $r = 0; $pdf->SetXY(10, 80); $pdf->MultiCell(20, 0, 'พร้อมด้วย', 0, 'L', 0, 1, '', '', true); if (count($result2) > 0) { foreach ($result2 as $key2) { $n++; $r = $r + 7; $pdf->SetXY(20, 84 + $r); $pdf->MultiCell(176, 0, $n . '.................................................................................ตำแหน่ง.....................................................................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(25, 83 + $r); $pdf->MultiCell(60, 0, $key2->req_name, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(100, 83 + $r); $pdf->MultiCell(90, 0, $key2->position, 0, 'L', 0, 1, '', '', true); } } else { $pdf->SetXY(10, 85); $pdf->MultiCell(20, 0, '-', 0, 'L', 0, 1, '', '', true); } $pdf->SetXY(10, 91 + $r); $pdf->MultiCell(186, 0, 'ขออนุมัติเดินทางไปราชการที่.............................................................................หน่วยงานผู้จัด...............................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(50, 90 + $r); $pdf->MultiCell(59, 0, $key->location, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(130, 90 + $r); $pdf->MultiCell(60, 0, $key->institution, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(10, 97 + $r); $pdf->MultiCell(186, 0, 'เรื่อง...........................................................................................................................................................................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(20, 96 + $r); $pdf->MultiCell(175, 0, $key->title, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(10, 103 + $r); $pdf->MultiCell(187, 0, 'ตามหนังสือที่.........................................................................................................................ลงวันที่........................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(32, 102 + $r); $pdf->MultiCell(74, 0, $key->ref_book_number, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(136, 102 + $r); $pdf->MultiCell(50, 0, $key->ref_book_date == '0000-00-00' ? '' : $this->get_monthyearThai($key->ref_book_date), 0, 'L', 0, 1, '', '', true); $pdf->SetXY(10, 110 + $r); $pdf->MultiCell(186, 0, 'ทั้งนี้ตั้งแต่วันที่.........................................................................ถึงวันที่...........................................................................รวม............................วัน', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(34, 109 + $r); $pdf->MultiCell(55, 0, $key->startdate == '0000-00-00' ? '' : $this->get_monthyearThai($key->startdate), 0, 'L', 0, 1, '', '', true); $pdf->SetXY(100, 109 + $r); $pdf->MultiCell(53, 0, $key->enddate == '0000-00-00' ? '' : $this->get_monthyearThai($key->enddate), 0, 'L', 0, 1, '', '', true); $pdf->SetXY(167, 109 + $r); $pdf->MultiCell(20, 0, $key->allday, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(10, 116 + $r); $pdf->MultiCell(186, 0, 'สำหรับค่าใช้จ่ายในการเดินทางไปราชการขอเบิกจ่ายเงินบำรุงของโรงพยาบาล และขอใช้รถยนต์เดินทางไปราชการครั้งนี้', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(20, 125 + $r); $pdf->MultiCell(6, 0, $key->usecar1 == 1 ? '/' : '', 1, 'C', 0, 1, '', '', true); $pdf->SetXY(29, 125 + $r); $pdf->MultiCell(60, 0, 'ใช้รถยนต์ของทางโรงพยาบาลโนนไทย', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(20, 135 + $r); $pdf->MultiCell(6, 0, $key->usecar2 == 1 ? '/' : '', 1, 'C', 0, 1, '', '', true); $pdf->SetXY(29, 135 + $r); $pdf->MultiCell(170, 0, 'ใช้รถยนต์ส่วนตัว หมายเลขทะเบียน.......................................................................ตามหลักเกณฑ์การเบิกค่า', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(84, 134 + $r); $pdf->MultiCell(40, 0, $key->usecar2_car_number, 0, 'C', 0, 1, '', '', true); $pdf->SetXY(29, 141 + $r); $pdf->MultiCell(170, 0, 'ยานพาหนะส่วนตัวในการเดินทางไปราชการ กิโลเมตรละ 4 บาท เป็นเงิน................................................บาท', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(123, 140 + $r); $pdf->MultiCell(38, 0, $key->usecar2_km_money, 0, 'C', 0, 1, '', '', true); $pdf->SetXY(20, 149 + $r); $pdf->MultiCell(6, 0, $key->usecar3 == 1 ? '/' : '', 1, 'C', 0, 1, '', '', true); $pdf->SetXY(29, 149 + $r); $pdf->MultiCell(170, 0, 'อื่น ๆ (ระบุ)......................................................................................................................................................................................', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(50, 148 + $r); $pdf->MultiCell(140, 0, $key->usecar3_detail, 0, 'L', 0, 1, '', '', true); $pdf->SetXY(29, 158 + $r); $pdf->MultiCell(140, 0, 'จึงเรียนมาเพื่อทราบ และโปรดพิจารณาอนุมัติด้วย จะเป็นพระคุณ', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(95, 168 + $r); $pdf->MultiCell(100, 0, '(ลงชื่อ)...............................................................ผู้ขอ', 0, 'R', 0, 1, '', '', true); $pdf->SetXY(122, 167 + $r); $pdf->MultiCell(64, 0, '', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(128, 175 + $r); $pdf->MultiCell(69, 0, '(............................................................)', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(129, 174 + $r); $pdf->MultiCell(64, 0, $key->regis_user_req, 0, 'C', 0, 1, '', '', true); $h_re = DB::Select('select * from n_department_header where departmentName="' . $key->department . '" '); foreach ($h_re as $k_h) { $header_name = $k_h->header_name; } if (!isset($header_name)) { $header_name = ''; } $pdf->SetXY(10, 186 + $r); $pdf->MultiCell(68, 0, 'เสนอ ผู้อำนวยการโรงพยาบาลโนนไทย', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(11, 194 + $r); $pdf->MultiCell(69, 0, '...................................................', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(10, 204 + $r); $pdf->MultiCell(90, 0, '(ลงชื่อ).........................................................หัวหน้าฝ่าย', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(18, 212 + $r); $pdf->MultiCell(69, 0, '(.........................................................)', 0, 'L', 0, 1, '', '', true); $pdf->SetXY(20, 211 + $r); $pdf->MultiCell(45, 0, $header_name, 0, 'C', 0, 1, '', '', true); $pdf->SetXY(120, 194 + $r); $pdf->MultiCell(6, 0, $key->daytrue == 1 ? '/' : '', 1, 'C', 0, 1, '', '', true); $pdf->SetXY(123, 194 + $r); $pdf->MultiCell(40, 0, 'ไม่เป็นวันทำการ', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(120, 204 + $r); $pdf->MultiCell(6, 0, $key->dayflase == 1 ? '/' : '', 1, 'C', 0, 1, '', '', true); $pdf->SetXY(123, 204 + $r); $pdf->MultiCell(40, 0, 'เป็นวันทำการ', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(105, 219 + $r); $pdf->MultiCell(90, 0, '(ลงชื่อ)...........................................................ผู้อนุมัติ', 0, 'R', 0, 1, '', '', true); $pdf->SetXY(115, 227 + $r); $pdf->MultiCell(90, 0, '( นายบุญชัย ธนบัตรชัย )', 0, 'C', 0, 1, '', '', true); $pdf->SetXY(115, 235 + $r); $pdf->MultiCell(90, 0, 'ผู้อำนวยการโรงพยาบาลโนนไทย', 0, 'C', 0, 1, '', '', true); } //end foreach $filename = storage_path() . '/report_reserve.pdf'; $contents = $pdf->output($filename, 'I'); $headers = array('Content-Type' => 'application/pdf'); return Response::make($contents, 200, $headers); } else { $data = DB::table('c_req_cars')->where('godate', '>=', date('Y-m-d'))->orderBy('godate', 'asc')->paginate(10); return View::make('home.index', array('data' => $data)); } }
public function testPdfOutput() { // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 013'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 013', PDF_HEADER_STRING); // 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); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($this->langSettings); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', 'B', 20); // add a page $pdf->AddPage(); $pdf->Write(0, 'Graphic Transformations', '', 0, 'C', 1, 0, false, false, 0); // set font $pdf->SetFont('helvetica', '', 10); // --- Scaling --------------------------------------------- $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(50, 70, 40, 10, 'D'); $pdf->Text(50, 66, 'Scale'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // Scale by 150% centered by (50,80) which is the lower left corner of the rectangle $pdf->ScaleXY(150, 50, 80); $pdf->Rect(50, 70, 40, 10, 'D'); $pdf->Text(50, 66, 'Scale'); // Stop Transformation $pdf->StopTransform(); // --- Translation ----------------------------------------- $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 70, 40, 10, 'D'); $pdf->Text(125, 66, 'Translate'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // Translate 7 to the right, 5 to the bottom $pdf->Translate(7, 5); $pdf->Rect(125, 70, 40, 10, 'D'); $pdf->Text(125, 66, 'Translate'); // Stop Transformation $pdf->StopTransform(); // --- Rotation -------------------------------------------- $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(70, 100, 40, 10, 'D'); $pdf->Text(70, 96, 'Rotate'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // Rotate 20 degrees counter-clockwise centered by (70,110) which is the lower left corner of the rectangle $pdf->Rotate(20, 70, 110); $pdf->Rect(70, 100, 40, 10, 'D'); $pdf->Text(70, 96, 'Rotate'); // Stop Transformation $pdf->StopTransform(); // --- Skewing --------------------------------------------- $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 100, 40, 10, 'D'); $pdf->Text(125, 96, 'Skew'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // skew 30 degrees along the x-axis centered by (125,110) which is the lower left corner of the rectangle $pdf->SkewX(30, 125, 110); $pdf->Rect(125, 100, 40, 10, 'D'); $pdf->Text(125, 96, 'Skew'); // Stop Transformation $pdf->StopTransform(); // --- Mirroring horizontally ------------------------------ $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(70, 130, 40, 10, 'D'); $pdf->Text(70, 126, 'MirrorH'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // mirror horizontally with axis of reflection at x-position 70 (left side of the rectangle) $pdf->MirrorH(70); $pdf->Rect(70, 130, 40, 10, 'D'); $pdf->Text(70, 126, 'MirrorH'); // Stop Transformation $pdf->StopTransform(); // --- Mirroring vertically -------------------------------- $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 130, 40, 10, 'D'); $pdf->Text(125, 126, 'MirrorV'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // mirror vertically with axis of reflection at y-position 140 (bottom side of the rectangle) $pdf->MirrorV(140); $pdf->Rect(125, 130, 40, 10, 'D'); $pdf->Text(125, 126, 'MirrorV'); // Stop Transformation $pdf->StopTransform(); // --- Point reflection ------------------------------------ $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(70, 160, 40, 10, 'D'); $pdf->Text(70, 156, 'MirrorP'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // point reflection at the lower left point of rectangle $pdf->MirrorP(70, 170); $pdf->Rect(70, 160, 40, 10, 'D'); $pdf->Text(70, 156, 'MirrorP'); // Stop Transformation $pdf->StopTransform(); // --- Mirroring against a straigth line described by a point (120, 120) and an angle -20° $angle = -20; $px = 120; $py = 170; // just for visualisation: the straight line to mirror against $pdf->SetDrawColor(200); $pdf->Line($px - 1, $py - 1, $px + 1, $py + 1); $pdf->Line($px - 1, $py + 1, $px + 1, $py - 1); $pdf->StartTransform(); $pdf->Rotate($angle, $px, $py); $pdf->Line($px - 5, $py, $px + 60, $py); $pdf->StopTransform(); $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 160, 40, 10, 'D'); $pdf->Text(125, 156, 'MirrorL'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); //Start Transformation $pdf->StartTransform(); //mirror against the straight line $pdf->MirrorL($angle, $px, $py); $pdf->Rect(125, 160, 40, 10, 'D'); $pdf->Text(125, 156, 'MirrorL'); //Stop Transformation $pdf->StopTransform(); $this->comparePdfs($pdf); }
} // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0)); $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)); $style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0)); $style4 = array('L' => 0, 'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)), 'R' => array('width' => 0.5, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)), 'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10')); $style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128)); $style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0)); $style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0)); // Line $pdf->Text(5, 4, 'Line examples'); $pdf->Line(5, 10, 80, 30, $style); $pdf->Line(5, 10, 5, 30, $style2); $pdf->Line(5, 10, 80, 10, $style3); // Rect $pdf->Text(100, 4, 'Rectangle examples'); $pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200)); $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3)); // Curve $pdf->Text(5, 34, 'Curve examples'); $pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6); $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6); $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200)); // Circle and ellipse $pdf->Text(5, 79, 'Circle and ellipse examples'); $pdf->SetLineStyle($style5); $pdf->Circle(25, 105, 20);
function line($x1, $y1, $x2, $y2, $style = array()) { // Javier FPDF::line($x1, $this->h-$y1, $x2, $this->h-$y2); // Javier: width, color and style might be edited TCPDF::Line($x1, $this->h - $y1, $x2, $this->h - $y2, $style); }
$pdf->SetTextColor(0); //Start Transformation $pdf->StartTransform(); //point reflection at the lower left point of rectangle $pdf->MirrorP(50, 120); $pdf->Rect(50, 110, 40, 10, 'D'); $pdf->Text(50, 109, 'MirrorP'); //Stop Transformation $pdf->StopTransform(); //Mirroring against a straigth line described by a point (120, 120) and an angle -20° $angle = -20; $px = 120; $py = 120; //just vor visualisation: the straight line to mirror against $pdf->SetDrawColor(200); $pdf->Line($px - 1, $py - 1, $px + 1, $py + 1); $pdf->Line($px - 1, $py + 1, $px + 1, $py - 1); $pdf->StartTransform(); $pdf->Rotate($angle, $px, $py); $pdf->Line($px - 5, $py, $px + 60, $py); $pdf->StopTransform(); $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 110, 40, 10, 'D'); $pdf->Text(125, 109, 'MirrorL'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); //Start Transformation $pdf->StartTransform(); //mirror against the straight line $pdf->MirrorL($angle, $px, $py);
function index() { $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->load->library('form_validation'); $this->load->model('project_model'); $this->load->helper('csv'); $this->load->helper('download'); $data['projects'] = $this->db->get('project')->result(); $this->form_validation->set_rules('project', 'Date', 'trim|required'); if ($this->form_validation->run() == FALSE) { $data['dues'] = array(); $this->load->view('reports/sales_report', $data); } else { $dues = array(); $project_selected = $this->input->post('project'); $from_date_db = $this->input->post('from_date'); $from_date_db = date('Y-m-d', strtotime($from_date_db)); $to_date_db = $this->input->post('to_date'); $to_date_db = date('Y-m-d', strtotime($to_date_db)); $due_report = array(); $this->db->select('customer_file.id,customer_file.purchase_cost,contact.name,' . 'project.name as project,availability_chart_unit.unit_name as unit_name,' . 'contact.phone,contact.phone_2,contact.phone_3,contact.email,contact.email_2,' . 'customer_file.booking_date,customer_file.area,customer_file.rate,' . 'sales_region.name as sales_region, user.full_name as sales_person'); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'customer_file.project_id=project.id'); $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id'); $this->db->join('sales_region', 'sales_region.id=customer_file.sales_region', 'left'); $this->db->join('user', 'user.id=customer_file.sales_person', 'left'); $this->db->where('customer_file.project_id', $project_selected); $this->db->where('customer_file.booking_date >=', $from_date_db); $this->db->where('customer_file.booking_date <=', $to_date_db); $customers = $this->db->get()->result(); foreach ($customers as $customer) { $due_report[$customer->id] = array(); $due_report[$customer->id]['client_name'] = $customer->name; $due_report[$customer->id]['phone'] = implode(array_filter(array($customer->phone, $customer->phone_2, $customer->phone_3)), ', '); $due_report[$customer->id]['email'] = implode(array_filter(array($customer->email, $customer->email_2)), ', '); $due_report[$customer->id]['project'] = $customer->project . '-' . $customer->unit_name; $due_report[$customer->id]['purchase_cost'] = $customer->purchase_cost; $due_report[$customer->id]['booking_date'] = $customer->booking_date; $due_report[$customer->id]['area'] = $customer->area; $due_report[$customer->id]['rate'] = $customer->rate; $due_report[$customer->id]['sales_region'] = $customer->sales_region; $due_report[$customer->id]['sales_person'] = $customer->sales_person; $due_report[$customer->id]['total_tax'] = 0; $due_report[$customer->id]['due_amount'] = 0; $due_report[$customer->id]['total_pri'] = 0; $due_report[$customer->id]['total_tx'] = 0; $due_report[$customer->id]['total_amt'] = 0; $due_report[$customer->id]['total_units'] = $this->db->where('project_id', $customer->id)->count_all_results('customer_file'); $customer_file_id = $customer->id; $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual_active($customer_file_id); $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional_active($customer_file_id); $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id); $this->db->select('tax_type.name,tax_master.id'); $this->db->from('tax_type'); $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id'); $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id'); $this->db->where('customer_file_tax.customer_file_id', $customer_file_id); $customer_tax = $this->db->get()->result(); $total_due_amount = 0; // Actual Due foreach ($actual_payment_schedule as $schedule) { $total_due_amount += $schedule->due_amount; $ttax = 0; $ttax_bal = 0; foreach ($customer_tax as $cs2) { $tax_amount = 0; $tax_amount_bal = 0; if ($schedule->status == 1) { if ($schedule->due_amount - $schedule->amount_paid == 0) { $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax = $this->db->get()->first_row(); if ($applicale_tax->tax_amount) { $ttax += $applicale_tax->tax_amount; } } elseif ($schedule->amount_paid == 0) { $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $applicale_tax = $this->db->get()->first_row(); if (!empty($applicale_tax->tax_percentage)) { $tax_amount = $schedule->due_amount / 100 * $applicale_tax->tax_percentage; $ttax += $tax_amount; } } else { // tax on paid amount start $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax_paid = $this->db->get()->first_row(); // tax on paid amount end //tax on balance amount start $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type)); $tax_percentage_balance = $this->db->get()->first_row(); //tax on balance amount end $tax_amount_balance = ($schedule->due_amount - $schedule->amount_paid) / 100 * $tax_percentage_balance->tax_percentage; $applicale_tax_amount = $applicale_tax_paid->tax_amount + $tax_amount_balance; $ttax += $applicale_tax_amount; } } } $due_report[$customer->id]['total_tax'] += $ttax; $due_report[$customer->id]['due_amount'] += $schedule->due_amount; } // Additional Due foreach ($additional_payment_schedule as $schedule_additional) { $total_due_amount_additional += $schedule_additional->due_amount; $ttax_additional = 0; $ttax_bal = 0; foreach ($customer_tax as $cs2) { $tax_amount_add = 0; $tax_amount_bal_add = 0; if ($schedule_additional->status == 1) { if ($schedule_additional->due_amount - $schedule_additional->amount_paid == 0) { $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax_add = $this->db->get()->first_row(); if ($applicale_tax_add->tax_amount) { $ttax_additional += $applicale_tax_add->tax_amount; } } elseif ($schedule_additional->amount_paid == 0) { $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type)); $applicale_tax_add = $this->db->get()->first_row(); if (!empty($applicale_tax_add->tax_percentage)) { $tax_amount_add = $schedule_additional->due_amount / 100 * $applicale_tax_add->tax_percentage; $ttax_additional += $tax_amount_add; } } else { // tax on paid amount start $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount'); $this->db->from('receipt_split_up_tax'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id)); $applicale_tax_paid_bal = $this->db->get()->first_row(); // tax on paid amount end //tax on balance amount start $this->db->select('tax_slab.tax_percentage as tax_percentage'); $this->db->from('tax_slab'); $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id'); $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type)); $tax_percentage_balance = $this->db->get()->first_row(); //tax on balance amount end $tax_amount_balance_add = ($schedule_additional->due_amount - $schedule_additional->amount_paid) / 100 * $tax_percentage_balance->tax_percentage; $applicale_tax_amount_add = $applicale_tax_paid_bal->tax_amount + $tax_amount_balance_add; $ttax_additional += $applicale_tax_amount_add; } } } $due_report[$customer->id]['total_tax_additional'] += $ttax_additional; $due_report[$customer->id]['due_amount_additional'] += $schedule_additional->due_amount; } //Receipts foreach ($receipts as $b => $receipt) { $due_report[$customer->id]['total_pri'] += $receipt->principle_amount; $due_report[$customer->id]['total_tx'] += $receipt->amount_paid - $receipt->principle_amount; $due_report[$customer->id]['total_amt'] += $receipt->amount_paid; } } //print_r($due_report); //exit(); if (isset($_POST['generate_pdf'])) { $this->load->library('Pdf'); $this->db->select('company.name,project.project_type'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $company_details = $this->db->get()->first_row(); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 7, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Sales Report</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $pdf->writeHTMLCell(50, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($from_date_db)) . ' - ' . date('M Y', strtotime($to_date_db)) . '</strong>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true); $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="30">No.</th>'; $html .= '<th width="65">Booking Date</th>'; $html .= '<th width="75">Client Name</th>'; $html .= '<th width="60">Project</th>'; $html .= '<th width="40">Rate</th>'; $html .= '<th width="65">Agreement Value</th>'; $html .= '<th width="65">Due Amount</th>'; $html .= '<th width="65">Total Collection</th>'; $html .= '<th width="65">Balance Due</th>'; $html .= '<th width="60">Sales Region</th>'; $html .= '<th width="60">Sales Person</th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_sale_amount = 0; $total_due_amount = 0; $total_due_amount_additional = 0; $total_due_tax = 0; $total_due_tax_additional = 0; $total_collection = 0; $total_balance = 0; foreach ($due_report as $due) { $total_sale_amount += $due['purchase_cost']; $total_due_amount += $due['due_amount']; $total_due_amount_additional += $due['due_amount_additional']; $total_due_tax += $due['total_tax']; $total_due_tax_additional += $due['total_tax_additional']; $total_collection += $due['total_amt']; $total_balance += $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt']; $html .= '<tr>'; $html .= '<td width="30">' . ($n + 1) . '</td>'; $html .= '<td width="65">' . date('d-m-Y', strtotime($due['booking_date'])) . '</td>'; $html .= '<td width="75">' . $due['client_name'] . '</td>'; $html .= '<td width="60">' . $due['project'] . '</td>'; $html .= ' <td width="40">' . number_format($due['rate']) . '</td>'; $html .= ' <td width="65">' . number_format($due['purchase_cost']) . '</td>'; $html .= ' <td width="65">' . number_format($due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax'])) . '</td>'; $html .= ' <td width="65">' . number_format($due['total_amt']) . '</td>'; $html .= ' <td width="65">' . number_format($due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt']) . '</td>'; $html .= '<td width="60">' . $due['sales_region'] . '</td>'; $html .= '<td width="60">' . $due['sales_person'] . '</td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr style="font-weight: bolder">'; $html .= '<td colspan="5"></td>'; $html .= '<td>' . number_format($purchase_cost) . '</td>'; $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional) . '</td>'; $html .= '<td>' . number_format($total_amt_collected) . '</td>'; $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional - $total_amt_collected) . '</td>'; $html .= '<td></td>'; $html .= '<td></td>'; $html .= '</tr>'; $html .= '</tfoot>'; $html .= '</table><br /><br />'; //echo $html; //exit(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); } elseif (isset($_POST['generate_csv'])) { $csv_array = array(); $csv_array_line = array(); $csv_array_line[] = 'No.'; $csv_array_line[] = 'Date of Booking'; $csv_array_line[] = 'Client Name'; $csv_array_line[] = 'Contact Number'; $csv_array_line[] = 'Email'; $csv_array_line[] = 'Area'; $csv_array_line[] = 'Rate'; $csv_array_line[] = 'Project'; $csv_array_line[] = 'Sale Value'; $csv_array_line[] = 'Prin Amt Due'; $csv_array_line[] = 'Tax Amt Due'; $csv_array_line[] = 'Additional Due'; $csv_array_line[] = 'Additional Due Tax'; $csv_array_line[] = 'Total Due'; $csv_array_line[] = 'Total Collection'; $csv_array_line[] = 'Balance Due'; $csv_array_line[] = 'Sales Region'; $csv_array_line[] = 'Sales Person'; $csv_array[] = $csv_array_line; foreach ($due_report as $due) { $csv_array_line = array(); $csv_array_line[] = $n + 1; $csv_array_line[] = date('d-m-Y', strtotime($due['booking_date'])); $csv_array_line[] = $due['client_name']; $csv_array_line[] = $due['phone']; $csv_array_line[] = $due['email']; $csv_array_line[] = $due['area']; $csv_array_line[] = $due['rate']; $csv_array_line[] = $due['project']; $csv_array_line[] = $due['due_amount'] + $due['due_amount_additional']; $csv_array_line[] = $due['due_amount']; $csv_array_line[] = $due['total_tax']; $csv_array_line[] = $due['due_amount_additional']; $csv_array_line[] = $due['total_tax_additional']; $csv_array_line[] = $due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax']); $csv_array_line[] = $due['total_amt']; $csv_array_line[] = $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt']; $csv_array_line[] = $due['sales_region']; $csv_array_line[] = $due['sales_person']; $csv_array[] = $csv_array_line; } echo array_to_csv($csv_array, 'due_letter.csv'); exit; } else { $data['due_report'] = $due_report; $data['from_date_selected'] = $this->input->post('from_date'); $data['to_date_selected'] = $this->input->post('to_date'); $data['project_selected'] = $this->input->post('project'); $this->load->view('reports/sales_report', $data); } } }
function receipt_wise_collection() { $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->load->library('form_validation'); $this->load->model('project_model'); $this->load->helper(array('csv', 'download')); $this->form_validation->set_rules('project', 'Project', 'trim|required'); $data['projects'] = $this->db->get('project')->result(); $data['tax_types'] = $this->db->get('tax_type')->result(); if ($this->form_validation->run() == FALSE) { $data['collections'] = array(); $this->load->view('reports/receipt_wise_collection', $data); } else { $tax_types = $this->db->get('tax_type')->result(); $project_selected = $this->input->post('project'); $date_from = $this->input->post('date_from'); $date_from = date('Y-m-d', strtotime($date_from)); $date_to = $this->input->post('date_to'); $date_to = date('Y-m-d', strtotime($date_to)); $this->load->model(array('payment_schedule_customer_model', 'receipt_model')); $this->db->select('company.name,project.project_type,project.name as project'); $this->db->from('company'); $this->db->join('project', 'project.company_id=company.id'); $this->db->join('customer_file', 'customer_file.project_id=project.id'); $this->db->where('project.id', $project_selected); $company_details = $this->db->get()->first_row(); $this->db->select('contact.name as customer_name,project.name as project,SUM(`receipt`.`principle_amount`) as principle_amount,' . 'SUM(`receipt`.`amount_paid`) as amount_paid,receipt.customer_file_id as customer_file_id,' . 'receipt.receipt_number,receipt.date_payment,receipt.id as receipt_number'); $this->db->from('receipt'); $this->db->join('customer_file', 'customer_file.id=receipt.customer_file_id'); $this->db->join('project', 'project.id=customer_file.project_id'); $this->db->join('contact', 'contact.id=customer_file.customer_id'); $this->db->where('customer_file.project_id', $project_selected); $this->db->where('receipt.date_payment >=', $date_from); $this->db->where('receipt.date_payment <=', $date_to); $this->db->order_by('receipt.date_payment', 'desc'); $this->db->group_by('receipt.id'); $collection_report = $this->db->get()->result(); if (isset($_POST['generate_pdf'])) { $this->load->library('Pdf'); $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Receipt'); //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255)); $pdf->SetPrintFooter(false); $pdf->setPrintHeader(false); //$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); if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) { require_once dirname(__FILE__) . '/lang/eng.php'; $pdf->setLanguageArray($l); } $pdf->setFontSubsetting(true); $pdf->SetFont('dejavusans', '', 7, '', true); $pdf->AddPage(); $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 25, 220, 25, $style); $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Receipt Wise Collection Report - ' . $company_details->project . '</h2>', 0, 1, 0, true, '', true); $style = array('width' => 0.1, 'color' => array(0, 0, 0)); $pdf->Line(0, 35, 220, 35, $style); $pdf->writeHTMLCell(58, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($date_from)) . ' to ' . date('M Y', strtotime($date_to)) . '</strong>', 0, 1, 0, true, '', true); $pdf->writeHTMLCell(35, 0, 161, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true); $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />'; $html .= '<table border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>'; $html .= '<th width="30">No.</th>'; $html .= '<th width="90">Customer Name</th>'; $html .= '<th width="70">Date</th>'; $html .= '<th width="75">Principal Amount Paid</th>'; foreach ($tax_types as $tax_type) { $html .= '<th width="75">' . $tax_type->name . '</th>'; } $html .= '<th width="75">Total Tax</th>'; $html .= '<th width="74">Total Paid</th>'; $html .= '</tr>'; $html .= '</thead><tbody>'; $total_due_percentage = 0; $total_due_amount = 0; $total_due_tax_amount = 0; $total_balance = 0; $total_tax = array(); foreach ($customer_tax as $cs5) { $total_tax[$cs5->id] = 0; } $total_paid = 0; $n = 1; $total_principle_amount = 0; $txts = array(); foreach ($collection_report as $collection) { $total_tax_row = 0; $total_principle_amount += $collection->principle_amount; $html .= '<tr>'; $html .= '<td width="30">' . $n . '</td>'; $html .= '<td width="90">' . $collection->customer_name . '</td>'; $html .= '<td width="70">' . date('d-m-Y', strtotime($collection->date_payment)) . '</td>'; $html .= '<td width="75">' . number_format($collection->principle_amount) . '</td>'; foreach ($tax_types as $tax_type) { $this->db->select("SUM(`tax_amount`) as tax"); $this->db->from('receipt_split_up_tax'); $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id'); $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id'); $this->db->where('receipt.id', $collection->receipt_number); $this->db->where('tax_type.id', $tax_type->id); @($txs = $this->db->get()->first_row()); if (!$txs->tax) { $txs = 0; } else { $txs = $txs->tax; } $txts[$tax_type->id] += $txs; $total_tax_row += $txs; $html .= '<td width="75">' . number_format($txs) . '</td>'; } $html .= ' <td width="75">' . number_format($total_tax_row) . '</td>'; $html .= ' <td width="74">' . number_format($collection->amount_paid) . '</td>'; $html .= '</tr>'; $n++; } $html .= '</tbody>'; $html .= '<tfoot>'; $html .= '<tr style="font-weight: bolder">'; $html .= '<td colspan="3"></td>'; $html .= '<td>' . number_format($total_principle_amount) . '</td>'; $tt_tax = 0; $ttottax = 0; foreach ($tax_types as $tax_type) { $html .= '<td>' . number_format($txts[$tax_type->id]) . '</td>'; $ttottax += $txts[$tax_type->id]; } $html .= '<td>' . number_format($ttottax) . '</td>'; $html .= '<td>' . number_format($ttottax + $total_principle_amount) . '</td>'; $html .= '</tr>'; $html .= '</tfoot>'; $html .= '</table><br /><br />'; //echo $html; //exit(); $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $pdf->Output('receipt.pdf', 'I'); } elseif (isset($_POST['generate_csv'])) { $csv_array = array(); $csv_array_line = array(); $csv_array_line[] = 'No.'; $csv_array_line[] = 'Customer Name'; $csv_array_line[] = 'Project'; $csv_array_line[] = 'Receipt Number'; $csv_array_line[] = 'Date'; $csv_array_line[] = 'Principal Amount Paid'; foreach ($tax_types as $tax_type) { $csv_array_line[] = $tax_type->name; } $csv_array_line[] = 'Total Tax'; $csv_array_line[] = 'Total Paid'; $csv_array[] = $csv_array_line; $csv_array_line = array(); $n = 1; foreach ($collection_report as $collection) { $csv_array_line = array(); $csv_array_line[] = $n; $csv_array_line[] = $collection->customer_name; $csv_array_line[] = $collection->project; $csv_array_line[] = $collection->receipt_number; $csv_array_line[] = date('d-m-Y', strtotime($collection->date_payment)); $csv_array_line[] = $collection->principle_amount; $total_tax_row = 0; foreach ($tax_types as $tax_type) { $this->db->select("SUM(`tax_amount`) as tax"); $this->db->from('receipt_split_up_tax'); $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id'); $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id'); $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id'); $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id'); $this->db->where('receipt.id', $collection->receipt_number); $this->db->where('tax_type.id', $tax_type->id); @($txs = $this->db->get()->first_row()); if (!$txs->tax) { $txs = 0; } else { $txs = $txs->tax; } $txts[$tax_type->id] += $txs; $total_tax_row += $txs; $csv_array_line[] = $txs; } $csv_array_line[] = $total_tax_row; $csv_array_line[] = $collection->amount_paid; $csv_array[] = $csv_array_line; $n = $n + 1; } echo array_to_csv($csv_array, 'receipt_wise_collection_report.csv'); exit; } else { $data['collection_report'] = $collection_report; $data['date_from_selected'] = $this->input->post('date_from'); $data['date_to_selected'] = $this->input->post('date_to'); $data['project_selected'] = $this->input->post('project'); $this->load->view('reports/receipt_wise_collection', $data); } } }
$pdf->SetTextColor(0); // Start Transformation $pdf->StartTransform(); // point reflection at the lower left point of rectangle $pdf->MirrorP(70, 170); $pdf->Rect(70, 160, 40, 10, 'D'); $pdf->Text(70, 156, 'MirrorP'); // Stop Transformation $pdf->StopTransform(); // --- Mirroring against a straigth line described by a point (120, 120) and an angle -20° $angle = -20; $px = 120; $py = 170; // just for visualisation: the straight line to mirror against $pdf->SetDrawColor(200); $pdf->Line($px - 1, $py - 1, $px + 1, $py + 1); $pdf->Line($px - 1, $py + 1, $px + 1, $py - 1); $pdf->StartTransform(); $pdf->Rotate($angle, $px, $py); $pdf->Line($px - 5, $py, $px + 60, $py); $pdf->StopTransform(); $pdf->SetDrawColor(200); $pdf->SetTextColor(200); $pdf->Rect(125, 160, 40, 10, 'D'); $pdf->Text(125, 156, 'MirrorL'); $pdf->SetDrawColor(0); $pdf->SetTextColor(0); //Start Transformation $pdf->StartTransform(); //mirror against the straight line $pdf->MirrorL($angle, $px, $py);
public function RenderAsPDF(TCPDF $oPdf, DisplayableGraph $oGraph, $fScale, $aContextDefs) { $xStart = $this->GetSourceNode()->x * $fScale; $yStart = $this->GetSourceNode()->y * $fScale; $xEnd = $this->GetSinkNode()->x * $fScale; $yEnd = $this->GetSinkNode()->y * $fScale; $bReached = $this->GetSourceNode()->GetProperty('is_reached') && $this->GetSinkNode()->GetProperty('is_reached'); $oPdf->setAlpha(1); if ($bReached) { $aColor = array(100, 100, 100); } else { $aColor = array(200, 200, 200); } $oPdf->SetLineStyle(array('width' => 2 * $fScale, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => $aColor)); $oPdf->Line($xStart, $yStart, $xEnd, $yEnd); $vx = $xEnd - $xStart; $vy = $yEnd - $yStart; $l = sqrt($vx * $vx + $vy * $vy); $vx = $vx / $l; $vy = $vy / $l; $ux = -$vy; $uy = $vx; $lPos = max($l / 2, $l - 40 * $fScale); $iArrowSize = 5 * $fScale; $x = $xStart + $lPos * $vx; $y = $yStart + $lPos * $vy; $oPdf->Line($x, $y, $x + $iArrowSize * ($ux - $vx), $y + $iArrowSize * ($uy - $vy)); $oPdf->Line($x, $y, $x - $iArrowSize * ($ux + $vx), $y - $iArrowSize * ($uy + $vy)); }
// 附加二维码 $pdf->write2DBarcode('http://www.bubujie.com', 'QRCODE,L', 20, 30, 20, 20, $style, 'N'); // 添加Logo $pdf->SetXY(13, 10); $pdf->Image('../images/logo_doc_header.gif', '', '', 72, 16, '', '', '', false, 300, '', false, false, 0, false, false, false); // 输出正文 $pdf->SetXY(20, 30); $pdf->writeHTML($html, true, 0, true, 0); $pdf->SetXY(140, 12); $pdf->Write(0, '配送单存根联', '', 0, '', true, 0, false, false, 0); // 输出拔 $pdf->SetXY(20, 130); $pdf->writeHTML($colophon, true, 0, true, 0); //============================================================+ $style = array('width' => 0.2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 4, 'color' => array(0, 0, 0)); $pdf->Line(0, 150, 210, 150, $style); //============================================================+ // 附加二维码 $pdf->write2DBarcode('http://www.bubujie.com', 'QRCODE,L', 20, 180, 20, 20, $style, 'N'); // 添加Logo $pdf->SetXY(13, 160); $pdf->Image('../images/logo_doc_header.jpg', '', '', 72, 16, '', '', '', false, 300, '', false, false, 0, false, false, false); // 输出正文 $pdf->SetXY(20, 180); $pdf->writeHTML($html, true, 1000, true, 0); $pdf->SetXY(140, 162); $pdf->Write(0, '配送单客户联', '', 0, '', true, 0, false, false, 0); // 输出拔 $pdf->SetXY(20, 272); $pdf->writeHTML($colophon, true, 0, true, 0); //============================================================+
$pdf->MultiCell($twx[$i], 0, $thx[$i], 1, $tax[$i], 1, 0, '', '', true); } $pdf->Ln(); $pdf->SetTextColor(0); } if($LCEK!=''){ if($r['cek']!=$LCEK){ $tx=$dcMarginL; for($l=0;$l<$twx_n;$l++){ $tx=$tx+$twx[$l]; } $gy=$pdf->GetY()+1; $pdf->SetY($gy); $pdf->Line($dcMarginL,$gy,$tx,$gy); } } $i=0; $ny=$pdf->GetY();$my=0; $i=0;$pdf->MultiCell($twx[$i], 0, $row++, 0, $tax[$i++], 0, 0, '', '', true);if($pdf->getLastH()>$my)$my=$pdf->getLastH(); // 10. Row data: >> Edit cetak_kolom($r['barkode']); cetak_kolom(buku_judul($r['judul'])); cetak_kolom($r['callnumber']); cetak_kolom($r['isbn']); cetak_kolom($r['npengarang']); cetak_kolom($r['npenerbit']); cetak_kolom($r['cek']);
$pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0)); $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)); $style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0)); $style4 = array('L' => 0, 'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)), 'R' => array('width' => 0.5, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)), 'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10')); $style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128)); $style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0)); $style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0)); // Line $pdf->Text(5, 7, 'Line examples'); $pdf->Line(5, 10, 80, 30, $style); $pdf->Line(5, 10, 5, 30, $style2); $pdf->Line(5, 10, 80, 10, $style3); // Rect $pdf->Text(100, 7, 'Rectangle examples'); $pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200)); $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3)); // Curve $pdf->Text(5, 37, 'Curve examples'); $pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, null, $style6); $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6); $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200)); // Circle and ellipse $pdf->Text(5, 82, 'Circle and ellipse examples'); $pdf->SetLineStyle($style5); $pdf->Circle(25, 105, 20);
public function display($arraydata, $y_axis = 0, $fielddata = false) { //print_r($arraydata);echo "<br/>"; // $this->pdf->Cell(10,10,"SSSS"); $this->Rotate($arraydata["rotation"]); if ($arraydata["rotation"] != "") { if ($arraydata["rotation"] == "Left") { $w = $arraydata["width"]; $arraydata["width"] = $arraydata["height"]; $arraydata["height"] = $w; $this->pdf->SetXY($this->pdf->GetX() - $arraydata["width"], $this->pdf->GetY()); } elseif ($arraydata["rotation"] == "Right") { $w = $arraydata["width"]; $arraydata["width"] = $arraydata["height"]; $arraydata["height"] = $w; $this->pdf->SetXY($this->pdf->GetX(), $this->pdf->GetY() - $arraydata["height"]); } elseif ($arraydata["rotation"] == "UpsideDown") { //soverflow"=>$stretchoverflow,"poverflow" $arraydata["soverflow"] = true; $arraydata["poverflow"] = true; // $w=$arraydata["width"]; // $arraydata["width"]=$arraydata["height"]; //$arraydata["height"]=$w; $this->pdf->SetXY($this->pdf->GetX() - $arraydata["width"], $this->pdf->GetY() - $arraydata["height"]); } } if ($arraydata["type"] == "SetFont") { if ($arraydata["font"] == 'uGB') { $this->pdf->isUnicode = true; } else { $this->pdf->isUnicode = false; } $this->pdf->SetFont($arraydata["font"], $arraydata["fontstyle"], $arraydata["fontsize"]); } elseif ($arraydata["type"] == "subreport") { $this->runSubReport($arraydata); } elseif ($arraydata["type"] == "MultiCell") { $currenty = $this->pdf->GetY(); if ($fielddata == false) { if ($this->allowprintuntill >= $currenty) { $this->checkoverflow($arraydata, $this->updatePageNo($arraydata["txt"])); } } elseif ($fielddata == true) { if ($this->allowprintuntill >= $currenty) { $this->checkoverflow($arraydata, $this->updatePageNo($this->analyse_expression($arraydata["txt"], $arraydata["isPrintRepeatedValues"]))); } elseif ($this->parentcurrentband == "detail") { $this->pdf->Cell(40, 10, "SADSD"); } // echo $arraydata["txt"]."+\"|(".$y_axis.",".print_r($arraydata,true)."),$this->allowprintuntill,$newy\"<br/><br/>"; } } elseif ($arraydata["type"] == "SetXY") { $this->pdf->SetXY($arraydata["x"] + $this->arrayPageSetting["leftMargin"], $arraydata["y"] + $y_axis); } elseif ($arraydata["type"] == "Cell") { $currenty = $this->pdf->GetY(); if ($this->allowprintuntill >= $currenty) { $this->pdf->Cell($arraydata["width"], $arraydata["height"], $this->updatePageNo($arraydata["txt"]), $arraydata["border"], $arraydata["ln"], $arraydata["align"], $arraydata["fill"], $arraydata["link"]); } elseif ($this->parentcurrentband == "detail") { $this->pdf->Cell(40, 10, "SADSD"); } } elseif ($arraydata["type"] == "Rect") { $this->pdf->Rect($arraydata["x"] + $this->arrayPageSetting["leftMargin"], $arraydata["y"] + $y_axis, $arraydata["width"], $arraydata["height"]); } elseif ($arraydata["type"] == "Image") { $path = $this->analyse_expression($arraydata["path"]); $imgtype = substr($path, -3); if ($imgtype == 'jpg' || right($path, 3) == 'jpg' || right($path, 4) == 'jpeg') { $imgtype = "JPEG"; } elseif ($imgtype == 'png' || $imgtype == 'PNG') { $imgtype = "PNG"; } if (file_exists($path) || left($path, 4) == 'http') { $this->pdf->Image($path, $arraydata["x"] + $this->arrayPageSetting["leftMargin"], $arraydata["y"] + $y_axis, $arraydata["width"], $arraydata["height"], $imgtype, $arraydata["link"]); } elseif (left($path, 22) == "data:image/jpeg;base64") { $imgtype = "JPEG"; $img = str_replace('data:image/jpeg;base64,', '', $path); $imgdata = base64_decode($img); $this->pdf->Image('@' . $imgdata, $arraydata["x"] + $this->arrayPageSetting["leftMargin"], $arraydata["y"] + $y_axis, $arraydata["width"], $arraydata["height"]); //,$imgtype,$arraydata["link"]); } elseif (left($path, 22) == "data:image/png;base64,") { $imgtype = "PNG"; // $this->pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $img = str_replace('data:image/png;base64,', '', $path); $imgdata = base64_decode($img); $this->pdf->Image('@' . $imgdata, $arraydata["x"] + $this->arrayPageSetting["leftMargin"], $arraydata["y"] + $y_axis, $arraydata["width"], $arraydata["height"]); //,$imgtype,$arraydata["link"]); } } elseif ($arraydata["type"] == "SetTextColor") { $this->pdf->SetTextColor($arraydata["r"], $arraydata["g"], $arraydata["b"]); } elseif ($arraydata["type"] == "SetDrawColor") { $this->pdf->SetDrawColor($arraydata["r"], $arraydata["g"], $arraydata["b"]); } elseif ($arraydata["type"] == "SetLineWidth") { $this->pdf->SetLineWidth($arraydata["width"]); } elseif ($arraydata["type"] == "Line") { $this->pdf->Line($arraydata["x1"] + $this->arrayPageSetting["leftMargin"], $arraydata["y1"] + $y_axis, $arraydata["x2"] + $this->arrayPageSetting["leftMargin"], $arraydata["y2"] + $y_axis); } elseif ($arraydata["type"] == "SetFillColor") { $this->pdf->SetFillColor($arraydata["r"], $arraydata["g"], $arraydata["b"]); } elseif ($arraydata["type"] == "lineChart") { $this->showLineChart($arraydata, $y_axis); } elseif ($arraydata["type"] == "barChart") { $this->showBarChart($arraydata, $y_axis, 'barChart'); } elseif ($arraydata["type"] == "stackedBarChart") { $this->showBarChart($arraydata, $y_axis, 'stackedBarChart'); } elseif ($arraydata["type"] == "stackedAreaChart") { $this->showAreaChart($arraydata, $y_axis, $arraydata["type"]); } elseif ($arraydata["type"] == "Barcode") { $this->showBarcode($arraydata, $y_axis); } }