Reports and vardefs.php

Today I spent the rest of the day to fix one problem with Reports. It gave a JavaScript error (I hate JavaScript!) when some filter was built. The problem appeared only in Quote reports. I realized that it may happend because I added two new fields in the file vardefs.php. This file contains descriptions of all fields belonged to specific class:
'tax_usdollar' =>
array (
'name' => 'tax_usdollar',
'vname' => 'LBL_TAX_USDOLLAR',
'type' => 'decimal',
'len' => '20,2',
),

I commented out them but it didn’t resolve the problem. I observed that the error appeared when I chose “money” fields: Tax, Total Amount, Subtotal etc. I checked out their types in the vardefs.php and found the bug. The type was ‘decimal’ but when Report form was built it couldn’t find any operation for this data type. I replaced all decimal types by float and after that Quote report started work fine.
We still use SugarCRM-Pro-3.0.1. It’s difficult to switch to the latest version because we did some customization and fixed many bugs. Regarding the bug with building the list of operations for data type ‘decimal’ – it was fixed in the version 4.0. Cool! The developer team spent six months to fix this simple bug.

SOAP::Lite and SSL

Once I found the solution how to create Perl SOAP server with SSL. Here is a path for a module SOAP::Transport::HTTP::Daemon:

392c392,399
- sub new { require HTTP::Daemon;
---
+ sub SSL {
+ my $self = shift->new;
+ @_ ? ($self->{_SSL} = shift, return $self) : return
$self->{_SSL};
+ }
+
+ sub http_daemon_class { shift->SSL ? 'HTTP::Daemon::SSL' : 'HTTP::Daemon' }
+
+ sub new {
401c408,415
- $self->{_daemon} = HTTP::Daemon->new(@params) or Carp::croak "Can't create daemon: $!";
---
+
+ # use SSL if there is any parameter with SSL_* in the name
+ $self->SSL(1) if !$self->SSL && grep /^SSL_/, @params;
+ my $http_daemon = $self->http_daemon_class;
+ eval "require $http_daemon" or Carp::croak $@ unless UNIVERSAL::can($http_daemon => 'new');
+ $self->{_daemon} = $http_daemon->new(@params) or Carp::croak "Can't create daemon: $!";

Now, the server can be created like that:

my $daemon = SOAP::Transport::HTTP::Daemon->new(
LocalPort => 81,
Listen => 1,
SSL_use_cert => 1,
SSL_key_file => 'soap_server.key',
SSL_cert_file => 'soap_server.cert');

and client should use https instead of HTTP.
Unfortunatelly, I didn’t have a necessity to use it but may be in the future it’ll help me.

Perl Modules: Algorithm::CheckDigits

Algorithm::CheckDigits is a Perl extension which provides a functionality to generate and test check digits. It implements many algorithms to work with ISBN, UPS, VAT number etc. The workflow is very simple. First, the appropriate algorithm should be choosen:

use Algorithm::CheckDigits;
$isbn = CheckDigits('ISBN');

Then it’s possible to check existing number:

$isbn->is_valid('3-930673-48-7');

Get from existing number the check digit or base number:

$cd = $isbn->checkdigit('3-930673-48-7'); # $CD = '7'
$bn = $isbn->basenumber('3-930673-48-7'); # $bn = '3-930673-48'

or generate the check digit for the base number:

$cn = $isbn->complete('3-930673-48'); # $cn = '3-930673-48-7'

The list of available algorithms can be retrieving by method method_list():
Algorithm::CheckDigits->method_list();
It isn’t exported. So, the module name should be used when this method is called.
Algorithm::CheckDigits is very useful module and it save a lot of your time if you need to implement of calculation of check digit.

Continue reading Perl Modules: Algorithm::CheckDigits

Class::DBI, Postgrsql and mod_perl

Recently I tried to use Class::DBI – one of the best Perl frameworks to create a persistent objects – with Postgresql and I faced with big problem. After the second or third request to the database it gave me an error:

Can't use an undefined value as an ARRAY reference at Class/DBI.pm line 1125

It was very strange for me because I used Class::DBI with Mysql in the three projects and I didn’t have any problems with Class::DBI. I made a search of this error and I was very surprised because I found just a couple of pages in Google. It seems that Class::DBI and Postgresql are used together rarely.
However, the suggestions of Perrin Harkins helped me to solve my problem. As I understand Class::DBI cannot work properly together with Apache::DBI in case transaction database.
To use Class::DBI into your classes you have to create a base class which inherits Class::DBI, inherited by all your classes and defined connection to the database:

__PACKAGE__->set_db('Main',
'dbi:' . $config->{'database'}->{'dbtype'} . ':database=' . $config->{'database'}->{'database'},
$config->{'database'}->{'username'},
$config->{'database'}->{'password'}, $attrs
);

Continue reading Class::DBI, Postgrsql and mod_perl

About Java

Personally I don’t like Java because it seems like a just product of high-quality PR. I don’t want to minimize the Java importance. it’s an excellent solution for certain goals but it isn’t unique, it isn’t absolutely universal! Hovewer, Java adherents think differently. From their point of view there are not anything noteworthy except perfect, brilliant, ideal Java! James Gosling – father of Java confirmed this thesis in his interview speach at Sun’s World Wide Education & Research Conference: “Java Is Under No Serious Threat From PHP, Ruby or C#”. One of many discussions can be found there. Dear Java-programmers, please, be more modest. Other programming languages are not so weak and useless as you can think 😉

Why I hate SugarCRM

I’ve worked for a half of year with SugarCRM and I haven’t changed my mind about it. It looks nice from the outside and crude inside (as most of others popular PHP applications). For example, it’s a good idea to check of application version. Let’s see how it was implemented in SugarCRM. First of all, the version is stored in the database: table name is ‘config’. Also, you can find the version of SugarCRM in the config.php and there is a special PHP script – sugar_version.php which contains the version again. And finally, I found version checking in the index.php:

$result = $current_user->db->query("SELECT * FROM config
WHERE category='info' AND name='sugar_version' AND value LIKE '3.5%'");

How do you think is it right way to check of version? I don’t think so.
Continue reading Why I hate SugarCRM