Archive

Archive for the ‘Invoice Plane’ Category

InvoicePlane v1.4.10 – Enabling Date Parameters

November 29, 2016 Leave a comment

As an update to https://jefferytay.wordpress.com/2016/02/25/invoiceplaneenabling-date-parameters/

File: Application\helpers\pdf_helper.php
Action:
Replace
    $items = $CI->mdl_items->where(‘invoice_id’, $invoice_id)->get()->result();   
with
    $items = $CI->mdl_items->get_items_and_replace_vars($invoice_id, $invoice->invoice_date_due);

image

File: application\modules\guest\controllers\view.php
Action:
Replace
    ‘items’ => $this->mdl_items->where(‘invoice_id’, $invoice->invoice_id)->get()->result(),
with
    ‘items’ => $this->mdl_items->get_items_and_replace_vars($invoice->invoice_id, $invoice->invoice_date_due),

image

File: application\modules\invoices\models\mdl_items.php
Action:
Add the following lines after "class Mdl_Items extends Response_Model {"

    ///Modify – ADDED
    public function get_items_and_replace_vars($invoice_id, $invoice_date_created = ‘now’)
    {
         $items = array();
         $query = $this->where(‘invoice_id’, $invoice_id)->get();

         foreach($query->result() as $item) {
             $item->item_name = $this->parse_item($item->item_name, $invoice_date_created);
             $item->item_description = $this->parse_item($item->item_description, $invoice_date_created);
             $items[] = $item;
         }
         return $items;
    }

    //Modify – ADDED
    private function parse_item($string, $invoice_date_created)
    {
        if (preg_match_all(‘/{{{(?<format>[yYmMdD])(?:(?<=[Yy])ear|(?<=[Mm])onth|(?<=[Dd])ay)(?:(?<operation>[-+])(?<amount>[1-9]+))?}}}/m’, $string, $template_vars, PREG_SET_ORDER)) {
              try {
                $formattedDate = new DateTime($invoice_date_created);
              }
              catch(Exception $e) { // If creating a date based on the invoice_date_created isn’t possible, use current date
                $formattedDate = new DateTime();
              }

              /* Calculate the date first, before starting replacing the variables */
              foreach($template_vars as $var) {
                  if(!isset($var[‘operation’], $var[‘amount’])) continue;

                  if($var[‘operation’] == ‘-‘) {
                      $formattedDate->sub( new DateInterval(‘P’ . $var[‘amount’] . strtoupper($var[‘format’])) );
                  }
                  else if($var[‘operation’] == ‘+’) {
                      $formattedDate->add( new DateInterval(‘P’ . $var[‘amount’] . strtoupper($var[‘format’])) );
                  }
              }

              /* Let’s replace all variables */
              foreach($template_vars as $var) {
                  $string = str_replace($var[0], $formattedDate->format($var[‘format’]), $string);
              }
        }

        return $string;
    }

image

Advertisements
Categories: Invoice Plane, Open Source

InvoicePlane–Enabling Date Parameters

February 25, 2016 Leave a comment

Sometimes it is necessary to include some form of dates in either the item or the item description for InvoicePlane.

In order to do so, you will need to edit 3 files

application\helpers\pdf_helper.php

search for function generate_invoice_pdf

and replace

$data = array(
        ‘invoice’ => $invoice,
        ‘invoice_tax_rates’ => $CI->mdl_invoice_tax_rates->where(‘invoice_id’, $invoice_id)->get()->result(),
          ‘items’ => $CI->mdl_items->get_items_and_replace_vars($invoice_id, $invoice->invoice_date_due),
        ‘payment_method’ => $payment_method,
        ‘output_type’ => ‘pdf’
    );

 

application\modules\guest\controllers\view.php

search for  public function invoice

$data = array(
                ‘invoice’ => $invoice,
                     ‘items’ => $this->mdl_items->get_items_and_replace_vars($invoice->invoice_id, $invoice->invoice_date_due),
                ‘invoice_tax_rates’ => $this->mdl_invoice_tax_rates->where(‘invoice_id’, $invoice->invoice_id)->get()->result(),
                ‘invoice_url_key’ => $invoice_url_key,
                ‘flash_message’ => $this->session->flashdata(‘flash_message’),
                ‘payment_method’ => $payment_method
            );

 

application\modules\invoices\models\mdl_items.php

add the following function to Mdl_Items class

public function get_items_and_replace_vars($invoice_id, $invoice_date_created = ‘now’)
     {
         $items = array();
         $query = $this->where(‘invoice_id’, $invoice_id)->get();

         foreach($query->result() as $item) {
             $item->item_name = $this->parse_item($item->item_name, $invoice_date_created);
             $item->item_description = $this->parse_item($item->item_description, $invoice_date_created);
             $items[] = $item;
         }
         return $items;
     }

 

 

Now you can do things like

Support and maintenance for {{{Month}}} {{{Year}}}

 

which will then appear as

image

Categories: Invoice Plane

InvoicePlane–Enabling friendly filenames when downloading PDF

January 29, 2016 Leave a comment

Modify /application/helpers/mpdf_helper.pdf       

Look for this particular code segment

if (!empty($invoice_array) AND $isGuest) {
            rsort($invoice_array);
            header(‘Content-type: application/pdf’);
return readfile($invoice_array[0]);       

 

then modify it to

if (!empty($invoice_array) AND $isGuest) {
            rsort($invoice_array);
            header(‘Content-type: application/pdf’);
header(‘Content-Disposition: attachment; filename="’.basename($invoice_array[0]).’"’); //<– add this line
return readfile($invoice_array[0]);       

Categories: Invoice Plane, Open Source

InvoicePlane–Adding custom recurring periods

January 29, 2016 Leave a comment

By default, invoice plans comes with recurring periods up to 1 year. However sometimes you need to add in additional recurring periods

To do so, you will need to edit 2 files

File #1: application\modules\invoices\models\mdl_invoices_recurring.php

Look for $recur_frequencies and then add in the periods you want e.g in this example, I added in 2, 3,4 and 5 years

image

File #2: application\language\english\custom_lang.php

You will need to map each of the values with an appropriate language value, e.g in this case 2_year maps to the phrase 2 Years

If you support more than the english language, you will need to do the same for the additional language

image

Categories: Invoice Plane, Open Source