SugarCRM – Prevent currencies getting overridden

200452489-001

SugarCRM has some neat features involving currency rates, but one of the more annoying ones is that Sugar will automatically update the base rate every time you save a record with a currency field attached. This can be fairly annoying default behaviour if you wish to maintain the correct record value at the time of sale.

The problem
Say for example you have a custom module Books and your systems base currency is USD. You sell a book for 10 Euros at 11 dollars(the currenct change rate). If say a few weeks later you wanted to change the status of the Book to say, note down that the invoice was received and the exchange rate in that time has changed drastically. When you hit save Sugar would re-calculate the Euro value again(and despite the item being sold for 10 Euros originally the exchange rate has now changed and Sugar shows say 12 Euros, which is completely inconsistent with what you’ve invoiced.

The solution
There is thankfully a way around this using by overriding Sugar’s default behaviour using logic hooks. So taking our book example this is what custom/modules/Books/logic_hooks.php might look like.

 

And the actual code to do the overriding would be in custom/modules/Books/logic_hooks_class.php

Using the db over-ride hack should allow you to retain the same base rate on each record and Sugar will display the original 10 Euros despite the exchange rate changing.

Some words of caution
If you decide to override Sugar’s default behaviour, you could run into some issues down the line with reporting.
Basically the reports modules seems to ignore the base rate stored on each individual record and just uses whatever the system default is.

So you’ll have totals in your report that will be inconsistent with the currency value that’s stored on the record. One way around this is to only create reports using your base currency, another is to create a secondary field storing the correct amount of the currency in a decimal field rather than a currency field and creating reports based on that amount.

Flattr this!

SugarCRM 7 – Roll SugarCRM with Docker

sugar_docker

I find trying to replicate the SugarCRM environment locally a real pain. One of the main issues is simply that Sugar requires such old versions of PHP to be installed, especially compared to other web projects I have that implement the latest/greatest versions of PHP. Running multiple PHP versions simultaneously can be a pain. One solution is to use Vagrant but I find that too heavy for my needs, so I gave docker a go and found it a much faster/elegant solution.

Here’s the steps to get yourself up and running.

1. MySQL

You’ll need your own installation of MySQL for this. As I use Debian testing as a host I just installed MySQL on it and have my SugarCRM boxes point to the host using the dockerhost entry in /etc/hosts on each docker container.

There is nothing at all stopping you from creating another Docker instance running MySQL but I figured this was an unnecessary step and getting data persistence working with Docker can be a little annoying.

2. Getting the Docker config

Simply clone the repo for whichever version you intend to you use.

I have two versions of this setup for both SugarCRM Version 7.2(Needing PHP 5.3) and Version 7.5(Needing PHP 5.4).

Sugar-Docker 7.2 is here.
Sugar-Docker 7.5 is here.

3. Fill in Docker settings

run.sh

Edit this script and change the containers ip to whatever your hosts ip is. Don’t forget to set the folder to your SugarCRM code folder.

files/vhost.conf

Change settings here if you wish to use a custom url to access Sugar or if you have multiple instances of SugarCRM installed.

files/php.ini

Change any settings you might want to customise with PHP here.

4. Tell SugarCRM to use the right MySQL database

In config.php I just set the mysql host to dockerhost.

5. Hosts entry

Then on your host operating system make sure to point the virtualhost url to the box. For me, in my /etc/hosts I have this entry.

Debugging

Because I’ve used stdout for logs you can see apache errors by running a command like this.

sudo docker logs -f sugarcrm72

Flattr this!

Setting up git with Rescuetime highlights

Recently I’ve written on another site how I use Rescuetime to provide metrics on my overall productivity that I can review each week. One useful feature I noticed was Rescuetime highlights, which gives you a good overview of your accompishments throughout the day. The first thing I wanted to add to this (obviously) was git commits.

Luckily it turns out someone had already thought of this and implemented it. The script itself is here, I’m just going to reproduce it below.

Now, the annoying part for me is that this doesn’t work globally across all of my git repos, so to fix this you can leverage git’s templates directory. To create/initialise a git template folder simply run these commands.

Then put the above shell code into ~/.git-templates/hooks/post-commit

What this means is that from now on, any new git repos you initialise will contain this post-hook script. However, if you want to attach this to existing repos, just run a git init wherever the .git folder is.

Flattr this!

Solving boot2docker’s fail to start error

fbbb494a7eef5f9278c6967b6072ca3e_400x400

I’m putting this obvious solution up as I couldn’t see it anywhere online.

If you try to start up boot2docker with boot2docker start and it returns.

Before destroying everything and wiping your ~/Virtualbox VMs folder, try starting up Virtualbox and seeing if the vm simply hasn’t been suspended due to an OSX suspend or shutdown.

1. Unpause the machine
2. Send a shutdown signal
3. Try boot2docker start again.

And that’s it, hope it works for you.

Flattr this!

R – Cleaning/Merging Excel files

r-lang
This is just a useful snippet of code I’ve been using a lot to tidy up messy exports I’ve been getting lately.

Takes in a bunch of excel files, rewrites some variable column names in column 3 then outputs them as a list of dataframes. These then get merged into a single csv file.

Flattr this!