$invoice_date = mysql_to_unix($row->dateIssued); if ($last_retrieved_month != date('F', $invoice_date) && $display_month) { ?> <tr> <td colspan="5" class="monthbreak"><?php echo date('F', $invoice_date); ?> </td> </tr> <?php } $last_retrieved_month = date('F', $invoice_date); // localized month $display_date = formatted_invoice_date($row->dateIssued); ?> <tr> <td><?php echo anchor('invoices/view/' . $row->id, $row->invoice_number); ?> </td> <td><?php echo anchor('invoices/view/' . $row->id, $display_date); ?> </td> <td class="cName"><?php echo anchor('invoices/view/' . $row->id, $row->name); ?> <span class="short_description"><?php echo $short_description[$row->id];
<ul> <li><?php echo $this->lang->line('invoice_history_comments'); ?> </li> </ul> <?php } else { foreach ($invoiceHistory->result() as $row) { ?> <div style="clear:left; margin: 10px 0;"> <p class="dateHolder"><?php echo formatted_invoice_date($row->date_sent); ?> </p> <?php if ($row->contact_type == 2) { ?> <div class="comment"><p class="commentintro"><?php echo $this->lang->line('invoice_comment'); ?> </p><p><?php echo auto_typography(html_entity_decode(str_replace('\\n', "\n", $row->email_body))); ?> </p></div> <?php } else {
function _email($id) { $this->lang->load('date'); $this->load->plugin('to_pdf'); $this->load->helper(array('logo', 'file', 'path')); $this->load->library('email'); $this->load->model('clientcontacts_model'); $this->load->model('invoice_histories_model', '', TRUE); // Collect information for PDF $data['row'] = $this->invoices_model->getSingleInvoice($id)->row(); $data['id'] = $id; $data['companyInfo'] = $this->settings_model->getCompanyInfo()->row(); $data['company_logo'] = get_logo($this->settings_model->get_setting('logo_pdf'), 'pdf'); $data['client_note'] = $this->clients_model->get_client_info($data['row']->client_id)->client_notes; $data['date_invoice_issued'] = formatted_invoice_date($data['row']->dateIssued); $data['date_invoice_due'] = formatted_invoice_date($data['row']->dateIssued, $this->settings_model->get_setting('days_payment_due')); $invoice_number = $data['row']->invoice_number; // Get invoice information $items = $this->invoices_model->getInvoiceItems($id); $data['items'] = $items; $data['total_no_tax'] = $this->lang->line('invoice_amount') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_notax, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; $data['tax_info'] = $this->_tax_info($data['row']); $data['total_with_tax'] = $this->lang->line('invoice_total') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_with_tax, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; if ($data['row']->amount_paid > 0) { $data['total_paid'] = $this->lang->line('invoice_amount_paid') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->amount_paid, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; $data['total_outstanding'] = $this->lang->line('invoice_amount_outstanding') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_with_tax - $data['row']->amount_paid, 2, $this->config->item('currency_decimal'), ''); } else { $data['total_paid'] = ''; $data['total_outstanding'] = ''; } // Create invoice HTML & convert to PDF $html = $this->load->view('invoices/pdf', $data, TRUE); $invoice_localized = url_title(strtolower($this->lang->line('invoice_invoice'))); if (pdf_create($html, $invoice_localized . '_' . $invoice_number, FALSE)) { show_error($this->lang->line('error_problem_saving')); } // Get first client contact and send it to them $result_a = $this->db->query('SELECT * FROM ' . $this->db->dbprefix('clientcontacts') . ' WHERE client_id = "' . $data['row']->client_id . '" LIMIT 1;'); $row_a = $result_a->row(); $recipient_names = ''; $recipient_names[] .= $row_a->first_name . ' ' . $row_a->last_name; $email_body = 'See attatched file.'; // Email it $this->email->clear(true); $this->email->to($row_a->email); $this->email->from($data['companyInfo']->primary_contact_email, $data['companyInfo']->primary_contact); $this->email->subject($this->lang->line('invoice_invoice') . " {$invoice_number} : " . $data['companyInfo']->company_name); $this->email->message($email_body); $this->email->attach("./invoices_temp/" . $invoice_localized . "_" . "{$invoice_number}.pdf"); $this->email->send(); // Save this email being sent in invoice history $this->invoice_histories_model->insert_history_note($id, 'Sent by Recurring Invoices + PayNow mod.', $recipient_names); }
function retrieveInvoices() { $query = $this->invoices_model->getInvoicesAJAX($this->input->post('status'), $this->input->post('client_id'), $this->settings_model->get_setting('days_payment_due')); $last_retrieved_month = 0; // no month $invoiceResults = '{"invoices" :['; if ($query->num_rows() == 0) { $invoiceResults .= '{ "invoice_number" : "No results available"}, '; } else { foreach ($query->result() as $row) { $invoice_date = mysql_to_unix($row->dateIssued); if ($last_retrieved_month != date('F', $invoice_date) && $last_retrieved_month !== 0) { $invoiceResults .= '{ "invoiceId" : "monthbreak' . date('F', $invoice_date) . '" }, '; } $invoiceResults .= '{ "invoiceId" : "' . $row->id . '", "invoice_number" : "' . $row->invoice_number . '", "dateIssued" : "'; // localized month $invoiceResults .= formatted_invoice_date($row->dateIssued); $invoiceResults .= '", "clientName" : "' . $row->name . '", "amount" : "' . number_format($row->subtotal, 2, $this->config->item('currency_decimal'), '') . '", "status" : "'; if ($row->amount_paid >= $row->subtotal) { // paid invoices $invoiceResults .= $this->lang->line('invoice_closed'); } elseif (mysql_to_unix($row->dateIssued) >= strtotime('-' . $this->settings_model->get_setting('days_payment_due') . ' days')) { // owing less then the overdue days amount $invoiceResults .= $this->lang->line('invoice_open'); } else { // owing more then the overdue days amount $due_date = $invoice_date + $this->settings_model->get_setting('days_payment_due') * 60 * 60 * 24; $invoiceResults .= timespan($due_date, now()) . ' ' . $this->lang->line('invoice_overdue'); } $invoiceResults .= '" }, '; $last_retrieved_month = date('F', $invoice_date); } $invoiceResults = rtrim($invoiceResults, ', ') . ']}'; echo $invoiceResults; } }
function pdf($id, $output = TRUE) { $this->lang->load('date'); $this->load->plugin('to_pdf'); $this->load->helper('file'); $data['page_title'] = $this->lang->line('menu_invoices'); $invoiceInfo = $this->invoices_model->getSingleInvoice($id); if ($invoiceInfo->num_rows() == 0) { redirect('invoices/'); } $data['row'] = $invoiceInfo->row(); $data['date_invoice_issued'] = formatted_invoice_date($data['row']->dateIssued); $data['date_invoice_due'] = formatted_invoice_date($data['row']->dateIssued, $this->settings_model->get_setting('days_payment_due')); $data['companyInfo'] = $this->settings_model->getCompanyInfo()->row(); $data['company_logo'] = $this->_get_logo('_pdf', 'pdf'); $data['items'] = $this->invoices_model->getInvoiceItems($id); $data['total_no_tax'] = $this->lang->line('invoice_amount') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_notax, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; // taxes $data['tax_info'] = $this->_tax_info($data['row']); $data['total_with_tax'] = $this->lang->line('invoice_total') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_with_tax, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; if ($data['row']->amount_paid > 0) { $data['total_paid'] = $this->lang->line('invoice_amount_paid') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->amount_paid, 2, $this->config->item('currency_decimal'), '') . "<br />\n"; $data['total_outstanding'] = $this->lang->line('invoice_amount_outstanding') . ': ' . $this->settings_model->get_setting('currency_symbol') . number_format($data['row']->total_with_tax - $data['row']->amount_paid, 2, $this->config->item('currency_decimal'), ''); } else { $data['total_paid'] = ''; $data['total_outstanding'] = ''; } $html = $this->load->view('invoices/pdf', $data, TRUE); if (pdf_create($html, 'invoice_' . $data['row']->invoice_number, $output)) { show_error($this->lang->line('error_problem_saving')); } if ($output) { // if this is getting emailed, don't delete just yet $this->_delete_stored_files(); } }