/** * Convert the $value encode in html entity to clear char string. This function * should be called always to "clean" HTML encoded data; to render to a text * plain ascii file, to render to console, or to put in any kind of data field * who doesn't make the HTML render by itself. * * @param mixed String or array of strings to be cleaned. * @param boolean $utf8 Flag, set the output encoding in utf8, by default true. * * @return unknown_type */ function safe_output($value, $utf8 = true) { if (is_numeric($value)) { return $value; } if (is_array($value)) { array_walk($value, "safe_output"); return $value; } if (!mb_check_encoding($value, 'UTF-8')) { $value = utf8_encode($value); } if ($utf8) { $valueHtmlEncode = html_entity_decode($value, ENT_QUOTES, "UTF-8"); } else { $valueHtmlEncode = html_entity_decode($value, ENT_QUOTES); } //Replace the html entitie of ( for the char $valueHtmlEncode = str_replace("(", '(', $valueHtmlEncode); //Replace the html entitie of ) for the char $valueHtmlEncode = str_replace(")", ')', $valueHtmlEncode); //Revert html entities to chars for ($i = 0; $i < 33; $i++) { $valueHtmlEncode = str_ireplace("&#x" . dechex($i) . ";", html_to_ascii(dechex($i)), $valueHtmlEncode); } return $valueHtmlEncode; }
function ccexpire() { $this->load->model('billing_model'); $this->load->model('support_model'); $this->load->helper('date'); $this->load->helper('htmlascii'); // calculate the expire date for this month $nextexpdate = date("my", mktime(0, 0, 0, date("m"), date("y"))); $result = $this->billing_model->find_expired_cards($nextexpdate); foreach ($result as $myresult) { $billing_id = $myresult['id']; $to = $myresult['contact_email']; $name = $myresult['name']; $next_billing_date = $myresult['next_billing_date']; $next_billing_date = humandate($next_billing_date); $billingtype = $myresult['bt_name']; $account_number = $myresult['account_number']; $creditcard_number = $myresult['creditcard_number']; $creditcard_expire = $myresult['creditcard_expire']; $subject = "Your credit card is about to expire"; // fix any ascii characters in their name $name = html_to_ascii($name); $message = "Account Number: {$account_number}\n\n" . "{$name},\n\n" . "Thank you for choosing [company]. We would like to remind you that your " . "creditcard on file is about to expire at the end of this month.\n" . "\n" . "{$creditcard_number}, {$creditcard_expire}\n" . "\n" . "Please contact us with your new credit card expiration date so we may " . "continue providing service without any billing interruptions.\n\n" . "If you have any questions, please call our offices at (XXX) XXX-XXXX"; echo "sending a expiration reminder to {$to} {$account_number}\n"; $headers = "From: billing@example.com \n"; mail($to, $subject, $message, $headers); // put a ticket to say that this message was sent $user = "******"; $notify = ""; $status = "automatic"; $description = "Sent card expiration reminder to {$to}"; $this->support_model->create_ticket($user, $notify, $account_number, $status, $description); } }
function outputextendedinvoice($invoiceid, $printtype, $pdfobject) { $myinvresult = $this->get_invoice_data($invoiceid); $user = $myinvresult['h_created_by']; $mydate = $myinvresult['h_billing_date']; $mybilling_id = $myinvresult['b_id']; $billing_name = $myinvresult['b_name']; $billing_company = $myinvresult['b_company']; $billing_street = $myinvresult['b_street']; $billing_city = $myinvresult['b_city']; $billing_state = $myinvresult['b_state']; $billing_zip = $myinvresult['b_zip']; $billing_acctnum = $myinvresult['b_acctnum']; $billing_fromdate = $myinvresult['h_from_date']; $billing_todate = $myinvresult['h_to_date']; $billing_payment_due_date = $myinvresult['h_payment_due_date']; $billing_notes = $myinvresult['h_notes']; $billing_new_charges = sprintf("%.2f", $myinvresult['h_new_charges']); $billing_past_due = sprintf("%.2f", $myinvresult['h_past_due']); $billing_late_fee = sprintf("%.2f", $myinvresult['h_late_fee']); $billing_tax_due = sprintf("%.2f", $myinvresult['h_tax_due']); $billing_total_due = sprintf("%.2f", $myinvresult['h_total_due']); $billing_email = $myinvresult['b_contact_email']; // get the organization info to print on the bill $query = "SELECT g.org_name,g.org_street,g.org_city,g.org_state,\n g.org_zip,g.phone_billing,g.email_billing,g.invoice_footer \n FROM billing b\n LEFT JOIN general g ON g.id = b.organization_id \n WHERE b.id = ?"; $generalresult = $this->db->query($query, array($mybilling_id)) or die("output extended select organization failed"); $mygenresult = $generalresult->row_array(); $org_name = $mygenresult['org_name']; $org_street = $mygenresult['org_street']; $org_city = $mygenresult['org_city']; $org_state = $mygenresult['org_state']; $org_zip = $mygenresult['org_zip']; $phone_billing = $mygenresult['phone_billing']; $email_billing = $mygenresult['email_billing']; $invoice_footer = $mygenresult['invoice_footer']; // output the invoice page // load the html to ascii helper for character conversions $this->load->helper('htmlascii'); // convert dates to human readable form using my date helper $this->load->helper('date'); // convert dates to human readable form $billing_mydate = humandate($mydate); $billing_fromdate = humandate($billing_fromdate); $billing_todate = humandate($billing_todate); $billing_payment_due_date = humandate($billing_payment_due_date); if ($printtype == "pdf") { $this->load->library('fpdf'); $pdf = $pdfobject; // convert html character codes to ascii for pdf $billing_name = html_to_ascii($billing_name); $billing_company = html_to_ascii($billing_company); $billing_street = html_to_ascii($billing_street); $billing_city = html_to_ascii($billing_city); $org_name = html_to_ascii($org_name); $org_street = html_to_ascii($org_street); $org_city = html_to_ascii($org_city); // make new page $pdf->AddPage(); // get the page the current invoice in the batch starts on // necessary for batches with multiple invoices $invoicestartpage = $pdf->PageNo(); $pdf->SetFont('Arial', 'B', 18); $pdf->Cell(60, 10, "{$org_name}", 0); $pdf->SetXY(10, 20); $pdf->SetFont('Arial', '', 9); $pdf->MultiCell(80, 4, "{$org_street}\n{$org_city}, {$org_state} {$org_zip}\n{$phone_billing}\n{$email_billing}", 0); $pdf->Rect(135, 10, 1, 30, "F"); $pdf->SetXY(140, 10); $pdf->SetFontSize(10); $pdf->MultiCell(70, 6, lang('accountnumber') . ": {$billing_acctnum}\n" . lang('invoicenumber') . ": {$invoiceid}\n{$billing_fromdate} " . lang('to') . " {$billing_todate}\n" . lang('paymentdue') . ": {$billing_payment_due_date}\n" . lang('total') . ": {$billing_total_due}", 0); $pdf->SetXY(10, 60); $pdf->SetFontSize(10); $pdf->MultiCell(60, 5, "{$billing_name}\n{$billing_company}\n{$billing_street}\n{$billing_city} {$billing_state} {$billing_zip}", 0); $pdf->SetXY(130, 60); $pdf->Line(5, 102, 200, 102); $pdf->SetXY(10, 103); $pdf->Cell(100, 5, lang('description')); $pdf->SetXY(160, 103); $pdf->Cell(50, 5, lang('amount')); } else { $output = lang('accountnumber') . ": {$billing_acctnum}\n\n"; $output .= lang('invoicenumber') . ": {$invoiceid}\n"; $output .= "{$billing_fromdate} - {$billing_todate} \n"; $output .= lang('paymentduedate') . ": {$billing_payment_due_date}\n"; $output .= lang('total') . ": {$billing_total_due}\n\n"; $output .= lang('to') . ": {$billing_email}\n"; $output .= "{$billing_name} {$billing_company}\n"; $output .= "{$billing_street} "; $output .= "{$billing_city} {$billing_state} "; $output .= "{$billing_zip}\n\n"; $output .= "----------------------------------------"; $output .= "----------------------------------------\n"; } // end if // Select the new charge details for a specific invoice number $query = "SELECT d.user_services_id d_user_services_id, \n d.invoice_number d_invoice_number, \n d.billed_amount d_billed_amount, \n d.billing_id d_billing_id, \n d.taxed_services_id d_taxed_services_id, \n u.id u_id, u.master_service_id u_master_service_id, \n u.usage_multiple u_usage_multiple, \n m.options_table m_options_table, \n m.id m_id, m.service_description m_service_description, m.pricerate, \n ts.id ts_id, ts.master_services_id ts_master_services_id, \n ts.tax_rate_id ts_tax_rate_id, tr.id tr_id, \n tr.description tr_description\n FROM billing_details d\n LEFT JOIN user_services u ON d.user_services_id = u.id\n LEFT JOIN master_services m ON u.master_service_id = m.id\n LEFT JOIN taxed_services ts ON d.taxed_services_id = ts.id \n LEFT JOIN tax_rates tr ON ts.tax_rate_id = tr.id \n WHERE d.invoice_number = ? ORDER BY u.id DESC, tr.id ASC"; $result = $this->db->query($query, array($invoiceid)) or die("select new charge query failed"); // initialize line counters $myline = 1; $lineYoffset = 105; $fillcolor = 200; $lastserviceid = 0; // Print the invoice line items foreach ($result->result_array() as $myresult) { // check if it's a tax with a tax id or service with // no tax idfirst to set detail items $serviceid = $myresult['u_id']; $taxid = $myresult['tr_id']; if ($taxid == NULL) { // it's a service // select the options_table to get data for the details $options_table = $myresult['m_options_table']; $id = $myresult['u_id']; if ($options_table != '') { // get the data from the options table and put into variables $myoptions = $this->service_model->options_attributes($id, $options_table); //echo "$myoptions->username"; if (count($myoptions) >= 3) { $optiondetails1 = $myoptions[2]; } else { $optiondetails1 = ''; } if (count($myoptions) >= 4) { $optiondetails2 = $myoptions[3]; } else { $optiondetails2 = ''; } $optiondetails = $optiondetails2 . "\t" . $optiondetails1; } else { $optiondetails = ''; } $service_description = $myresult['m_service_description']; $tax_description = ''; } else { // it's a tax $tax_description = " " . $myresult['tr_description']; $service_description = ''; $optiondetails = ''; } $billed_amount = sprintf("%.2f", $myresult['d_billed_amount']); // calculate the month multiple, only print for services, not taxes $pricerate = $myresult['pricerate']; if ($pricerate > 0 and $taxid == NULL) { $monthmultiple = $billed_amount / $pricerate; } else { $monthmultiple = 0; } if ($printtype == "pdf") { // printing pdf invoice // alternate fill color if ($serviceid != $lastserviceid) { $lastserviceid = $serviceid; if ($fillcolor == 200) { $fillcolor = 255; $pdf->SetFillColor($fillcolor); } else { $fillcolor = 200; $pdf->SetFillColor($fillcolor); } } $service_description = html_to_ascii($service_description); $tax_description = html_to_ascii($tax_description); $optiondetails = html_to_ascii($optiondetails); $lineY = $lineYoffset + $myline * 5; $pdf->SetXY(10, $lineY); if ($monthmultiple > 1) { $pdf->Cell(151, 5, "{$serviceid} {$service_description} {$tax_description} ({$pricerate} x {$monthmultiple}) {$optiondetails}", 0, 0, "L", TRUE); } else { $pdf->Cell(151, 5, "{$serviceid} {$service_description} {$tax_description} {$optiondetails}", 0, 0, "L", TRUE); } //$pdf->SetXY(110,$lineY); //$pdf->Cell(110,5,"$optiondetails"); $pdf->SetXY(160, $lineY); $pdf->Cell(40, 5, "{$billed_amount}", 0, 0, "L", TRUE); } else { // printing text invoice if ($monthmultiple > 1) { if ($tax_description) { $output .= "{$serviceid} \t {$service_description} {$tax_description} ({$pricerate} x {$monthmultiple}) \t {$optiondetails} \t {$billed_amount}\n"; } else { $output .= "{$serviceid} \t {$service_description} {$tax_description} ({$pricerate} x {$monthmultiple}) \t {$optiondetails} \t \t {$billed_amount}\n"; } } else { if ($tax_description) { $output .= "{$serviceid} \t {$service_description} {$tax_description} \t {$optiondetails} \t \t {$billed_amount}\n"; } else { $output .= "{$serviceid} \t {$service_description} {$tax_description} \t {$optiondetails} \t {$billed_amount}\n"; } } } $myline++; if ($printtype == "pdf") { // add a new page if there are many line items // TODO: check for page number here // if page number greater than 1, then myline would be larger // set an invoicestartpage at the start of each invoice for multi invoice batches $pagenumber = $pdf->PageNo(); if ($pagenumber - $invoicestartpage > 0) { $linetotal = 48; } else { $linetotal = 28; } if ($myline > $linetotal) { $pdf->AddPage(); $pdf->SetXY(10, 20); $myline = 1; $lineYoffset = 20; } } } if ($printtype == "pdf") { $lineY = $lineYoffset + $myline * 5; $pdf->Line(5, $lineY, 200, $lineY); } else { $output .= "----------------------------------------"; $output .= "----------------------------------------\n"; } // print the notes and totals at the bottom of the invoice if ($printtype == "pdf") { // fix html characters $billing_notes = html_to_ascii($billing_notes); $invoice_footer = html_to_ascii($invoice_footer); $lineY = $lineY + 10; $pdf->SetXY(10, $lineY); $pdf->MultiCell(100, 5, "{$billing_notes}"); $pdf->SetXY(135, $lineY); $pdf->MultiCell(100, 5, lang('newcharges') . ": {$billing_new_charges}\n" . lang('pastdue') . ": {$billing_past_due}\n" . lang('tax') . ": {$billing_tax_due}\n"); $pdf->SetXY(135, $lineY + 15); $pdf->SetFont('Arial', 'BU', 10); $pdf->Cell(100, 5, lang('total') . ": {$billing_total_due}"); $lineY = $lineY + 10; $pdf->SetFont('Arial', '', 9); $pdf->SetXY(10, $lineY); $pdf->MultiCell(110, 4, "{$invoice_footer}"); } else { $output .= "{$billing_notes}\n"; $output .= lang('newcharges') . ": {$billing_new_charges}\n"; $output .= lang('pastdue') . ": {$billing_past_due}\n"; $output .= lang('tax') . ": {$billing_tax_due}\n"; $output .= lang('total') . ": {$billing_total_due}\n"; $output .= "\n{$invoice_footer}\n"; } if ($printtype == "pdf") { return $pdf; } else { return $output; } }
public function print_invoice() { $CI =& get_instance(); $CI->load->library('fpdf'); $pdf = $this->pdfobject; // convert html character codes to ascii for pdf $this->billing_name = html_to_ascii($this->billing_name); $this->billing_company = html_to_ascii($this->billing_company); $this->billing_street = html_to_ascii($this->billing_street); $this->billing_city = html_to_ascii($this->billing_city); $this->org_name = html_to_ascii($this->org_name); $this->org_street = html_to_ascii($this->org_street); $this->org_city = html_to_ascii($this->org_city); //$pdf=new FPDF(); $pdf->AddPage(); // get the page the current invoice in the batch starts on // necessary for batches with multiple invoices $invoicestartpage = $pdf->PageNo(); $pdf->SetFont('Arial', 'B', 18); $pdf->Cell(60, 10, "{$this->org_name}", 0); $pdf->SetXY(10, 20); $pdf->SetFont('Arial', '', 9); $pdf->MultiCell(80, 4, "{$this->org_street}\n{$this->org_city}, {$this->org_state} {$this->org_zip}\n{$this->phone_billing}\n{$this->email_billing}", 0); $pdf->Rect(135, 10, 1, 36, "F"); $pdf->SetXY(140, 10); $pdf->SetFontSize(10); $pdf->MultiCell(70, 6, "{$this->billing_mydate}\n" . lang('accountnumber') . ": {$this->billing_acctnum}\n" . lang('invoicenumber') . ": {$this->invoiceid}\n{$this->billing_fromdate} " . lang('to') . " {$this->billing_todate}\n" . lang('paymentdue') . ": {$this->billing_payment_due_date}\n" . lang('total') . ": {$this->billing_total_due}", 0); $pdf->SetXY(10, 60); $pdf->SetFontSize(10); if ($this->billing_po_number) { // only print the po number if they have one $pdf->MultiCell(60, 5, "{$this->billing_name}\n{$this->billing_company}\n{$this->billing_street}\n{$this->billing_city} {$this->billing_state} {$this->billing_zip}\n" . lang('po_number') . ": {$this->billing_po_number}", 0); } else { $pdf->MultiCell(60, 5, "{$this->billing_name}\n{$this->billing_company}\n{$this->billing_street}\n{$this->billing_city} {$this->billing_state} {$this->billing_zip}\n", 0); } $pdf->SetXY(130, 60); $pdf->Line(5, 102, 200, 102); $pdf->SetXY(10, 103); $pdf->Cell(100, 5, lang('description')); $pdf->SetXY(160, 103); $pdf->Cell(50, 5, lang('amount')); foreach ($this->invoicedetails as $myresult) { // check if it's a tax with a tax id or service with // no tax idfirst to set detail items $serviceid = $myresult['u_id']; $taxid = $myresult['tr_id']; if ($taxid == NULL) { // it's a service // select the options_table to get data for the details $options_table = $myresult['m_options_table']; $id = $myresult['u_id']; if ($options_table != '') { // get the data from the options table and put into variables $myoptions = $CI->service_model->options_attributes($id, $options_table); //echo "$myoptions->username"; if (count($myoptions) >= 3) { $optiondetails = $myoptions[2]; } else { $optiondetails = ''; } } else { $optiondetails = ''; } $service_description = $myresult['m_service_description']; $tax_description = ''; } else { // it's a tax $tax_description = " " . $myresult['tr_description']; $service_description = ''; $optiondetails = ''; } $billed_amount = sprintf("%.2f", $myresult['d_billed_amount']); // calculate the month multiple, only print for services, not taxes $pricerate = $myresult['pricerate']; if ($pricerate > 0 and $taxid == NULL) { $monthmultiple = sprintf("%.2f", $billed_amount / $pricerate); } else { $monthmultiple = 1; } // printing pdf invoice // alternate fill color if ($serviceid != $this->lastserviceid) { $lastserviceid = $serviceid; if ($this->fillcolor == 200) { $this->fillcolor = 255; $pdf->SetFillColor($this->fillcolor); } else { $this->fillcolor = 200; $pdf->SetFillColor($this->fillcolor); } } $service_description = html_to_ascii($service_description); $tax_description = html_to_ascii($tax_description); $optiondetails = html_to_ascii($optiondetails); $lineY = $this->lineYoffset + $this->myline * 5; $pdf->SetXY(10, $lineY); if ($monthmultiple != 1) { $pdf->Cell(151, 5, "{$serviceid} {$service_description} {$tax_description} ({$monthmultiple} @ {$pricerate}) {$optiondetails}", 0, 0, "L", TRUE); } else { $pdf->Cell(151, 5, "{$serviceid} {$service_description} {$tax_description} {$optiondetails}", 0, 0, "L", TRUE); } //$pdf->SetXY(110,$lineY); //$pdf->Cell(110,5,"$optiondetails"); $pdf->SetXY(160, $lineY); $pdf->Cell(40, 5, "{$billed_amount}", 0, 0, "L", TRUE); $this->myline++; // add a new page if there are many line items // TODO: check for page number here // if page number greater than 1, then myline would be larger // set an invoicestartpage at the start of each invoice for multi invoice batches $pagenumber = $pdf->PageNo(); if ($pagenumber - $invoicestartpage > 0) { $linetotal = 44; } else { $linetotal = 27; } if ($this->myline > $linetotal) { $pdf->AddPage(); $pdf->SetXY(10, 20); $this->myline = 1; $this->lineYoffset = 20; } } $lineY = $this->lineYoffset + $this->myline * 5; $pdf->Line(5, $lineY, 200, $lineY); // print the notes and totals at the bottom of the invoice if ($this->email == TRUE) { // set the invoice footer to use the one for email invoices $this->invoice_footer = $this->einvoice_footer; } // fix html characters $this->billing_notes = html_to_ascii($this->billing_notes); $this->invoice_footer = html_to_ascii($this->invoice_footer); $lineY = $lineY + 10; $pdf->SetXY(10, $lineY); $pdf->MultiCell(100, 5, "{$this->billing_notes}"); $pdf->SetXY(135, $lineY); $pdf->MultiCell(100, 5, lang('credit') . ": {$this->billing_credit_applied}\n" . lang('newcharges') . ": {$this->billing_new_charges}\n" . lang('pastdue') . ": {$this->billing_past_due}\n" . lang('tax') . ": {$this->billing_tax_due}\n"); $pdf->SetXY(135, $lineY + 20); $pdf->SetFont('Arial', 'BU', 10); $pdf->Cell(100, 5, lang('total') . ": {$this->billing_total_due}"); $lineY = $lineY + 10; $pdf->SetFont('Arial', '', 9); $pdf->SetXY(10, $lineY); $pdf->MultiCell(110, 4, "{$this->invoice_footer}"); return $pdf; }
private function print_pdf() { require './fpdf.php'; // select the path_to_ccfile from settings $query = "SELECT path_to_ccfile FROM settings WHERE id = '1'"; $ccfileresult = $this->CI->db->query($query) or die("query failed"); $myccfileresult = $ccfileresult->row_array(); $path_to_ccfile = $myccfileresult['path_to_ccfile']; $this->pdfname = "{$this->notice_type}" . "{$this->billing_id}" . "-" . "{$this->today}" . ".pdf"; $filepath = "{$path_to_ccfile}/" . "{$this->pdfname}"; $filedestination = "F"; $pdf = new FPDF(); $pdf->AddPage(); // heading $pdf->SetFont('Arial', 'B', 16); $pdf->Write(8, "{$this->noticeheading}"); // message body $pdf->SetFont('Arial', 'B', 10); $pdf->Write(5, "{$this->humanday}\n"); // convert message text from html codes to ascii for pdf first $message_text = html_to_ascii($this->message); $pdf->Write(5, "{$message_text}"); // write the pdf file to output $pdf->Output($filepath, $filedestination); }