frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register
Hello m'Managerians !
What do you think m'Manager 2.0 should be ? What features SHOULD or MUST be implemented right now ! Request or Vote here

[ TUT ] How to add attachment to invoice and send with mail.

Hey, if there are guys like me who would like to add attachment to their invoices, follow the guide. credits to developer Eric.

i'm attaching a picture for every step to make it clear. I hope i didn't forget anything, if you have some problems don't hesitate to ask :)





1: open application/modules/invoices/views/create_invoice_form.php

we're going to create a field/button for uploads. i've added this right under the notes section to my liking, you can add it where you like

                       <div class="form-group">
                        <div class="fileinput fileinput-new" data-provides="fileinput">
                            <span class="btn green btn-file">
                            <span class="fileinput-new"> <?php _e('message_add_file'); ?> /</span>
                            <span class="fileinput-exists"> <?php _e('label_change'); ?> </span>
                            <input type="file" name="invoices_attachment"> </span>
                            <span class="fileinput-filename"> </span> &nbsp;
                            <a href="javascript:;" class="close fileinput-exists" data-dismiss="fileinput"> </a>
                        </div>
                    </div>

2: open application/modules/invoices/views/index.php

make a place for attachment at the table , add the folowing code to your liking.

<?php _e('label_attachment'); ?>

i've added the attachment field after date-due field.

  1. in the same file add the following function at the bottom where other functions are placed.

function viewAttachment(value, row, index) {
if (value != "")
{
url = $('#base-url').data('target');
return '' + value + ' ';
}
}

  1. open application/modules/invoices/controllers/ajax.php

add this code right under create_invoice() function:

//Bijlage toevoegen
$config['upload_path'] = './uploads/incomes/attachments';
$config['allowed_types'] = '*';
$config['overwrite'] = TRUE;

    $this->load->library('upload', $config);
    $this->upload->do_upload('invoices_attachment');
    $invoice_attachment_data = $this->upload->data();
  1. add the following code onder invoice/ itemtable in the same file (ajax.php)

$invoiceTable['attachment_1'] = $invoice_attachment_data['file_name'];

  1. open application/modules/invoices/controllers/invoices.php

Locate invoices_list and add the folowing code at the end of array_push:

'attachment' => $invoice->attachment_1

  1. open application/helpers/functions_helper.php

replace the send_email function with the following code:

function send_email($to, $message, $subject=null, $from=null, $invoice_number=null)
{
$CI =& get_instance();
$CI->load->library('email');
$config['protocol'] = 'mail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['validate'] = 'true';

if($invoice_number)
{
    $file_name = get_invoice_attachment($invoice_number);
    $path = "https://www.HEREYOURSITEANDPATH.COM/uploads/incomes/attachments/";
    $path .=$file_name;
}
else {
    return false;
}
$CI->email->initialize($config);
$CI->email->from(isset($from) ? $from : get_option('email'), null == get_option('company') ? get_option('email') : get_option('company'));
$CI->email->to($to);
$CI->email->subject(isset($subject) ? $subject : __('no_subject'));
$CI->email->message($message);
if ($path)
{
    $CI->email->attach($path); // This portion appends the file name to the path
}
$CI->email->send();

}

Comments

Sign In or Register to comment.

m'Manager

| Let's Build Together a Great App !
If you are a happy user, send me a coffee.
2015 - 2107 © m'Manager.
Powered by VanillaForums, Designed by ThemeSteam

Recent Donations

  • Joni Mueller from https://pixelita.com/ - 63€
  • HeyrmanD from https://locco-palace.be - 25€
  • Patricia from Sjopz.com - 10€
  • AskinSavascisi from wolftech.com - 3€
  • Get In Touch