Business & Development

Validate VIN checksum with PHP

Posted in Auto Industry, Business & Development, PHP on May 7th, 2012 by Joonas – Be the first to comment

While working on something very secretive for StarAuto CMS, I came across the need to validate a VIN with the checksum algorithm defined by the Vehicle Identification Number article on Wikipedia. I whipped up a simple PHP class to handle the task.

class VIN
{
    public static $transliteration = array(
        'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 
        'J'=>1, 'K'=>2, 'L'=>3, 'M'=>4, 'N'=>5, 'P'=>7, 'R'=>9,
        'S'=>2, 'T'=>3, 'U'=>4, 'V'=>5, 'W'=>6, 'X'=>7, 'Y'=>8, 'Z'=>9,
    );
 
    public static $weights = array(8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2);
 
    /***
     * The checksum method is used to validate whether or not a VIN is valid
     * It will return an array with two keys: status and message
     * The "status" will either be boolean TRUE or FALSE
     * The "message" will be a string describing the status
     */
    public static function checksum($vin)
    {
        $vin = strtoupper($vin);
        $length = strlen($vin);
        $sum = 0;
 
        if($length != 17)
        {
            return array('status'=>false, 'message'=>'VIN is not the right length');
        }
 
        for($x=0; $x<$length; $x++)
        {
            $char = substr($vin, $x, 1);
 
            if(is_numeric($char))
            {
                $sum += $char * self::$weights[$x];
            }
            else
            {
                if(!isset(self::$transliteration[$char]))
                {
                    return array('status'=>false, 'message'=>'VIN contains an invalid character.');
                }
 
                $sum += self::$transliteration[$char] * self::$weights[$x];
            }
        }
 
        $remainder = $sum % 11;
        $checkdigit = $remainder == 10 ? 'X' : $remainder;
 
        if(substr($vin, 8, 1) != $checkdigit)
        {
            return array('status'=>false, 'message'=>'The VIN is not valid.');
        }
 
        return array('status'=>true, 'message'=>'The VIN is valid.');
    }
}

The one and only function of the class is to validate the checksum of a VIN and determine if the VIN is valid or invalid. Check the code below for some test output.

$vin = '1G1YW2DW0A5108451';
$checksum = VIN::checksum($vin);
 
var_dump($vin);
var_dump($checksum);

The VIN number in the sample is valid, so the output reflects that.

string(17) "1G1YW2DW0A5108451"
array(2) {
  ["status"]=>
  bool(true)
  ["message"]=>
  string(17) "The VIN is valid."
}

Hopefully someone will find this code useful.

Completely automated, hosted website solution for car dealerships

Posted in Business & Development, Case Studies on May 2nd, 2012 by Joonas – Be the first to comment

Most car dealerships are not big brand name dealerships and they do not have entire internet departments dedicated to maximizing their profit potential by leveraging social media, search engine optimization, and a rockstar website. I identified this problem in the industry back in 2007 when I was shopping for a used car in Tucson (Arizona) and found it difficult to research my options online. There were tons of car dealers in Tucson. I knew this because I drove by tons of them on my way to work and back. I drafted some plans with a good friend of mine on how to solve the problem for the smaller car dealerships and car lots. In 2011, we finally launched StarAuto CMS, which is a complete website solution for small to medium sized car dealers.

Why do small car dealers not have websites?

The reason most of the smaller car dealers do not have websites is because they do not (or think they don’t) have the necessary technical skills to build/maintain a website. Others shy away from getting a website due to startup costs and ridiculous monthly upkeep fees. We built StarAuto CMS to address all of these problems and concerns.

Lack of technical skills is not a valid reason anymore!

In order to address the tech skills concern, we made StarAuto CMS in to a hosted service. This means that we host the website on our server and manage the hardware and software. We keep the server and website up to date with latest updates and security patches. The car dealer does not have to be tech savvy to run and maintain a StarAuto CMS powered website. The solution comes with an easy to use online control panel that the car dealer can use to easily manage every page of their website, configuration options, and the inventory and associated pictures. The car dealer is in complete control of their website.

A website should not be a bank breaker.

We solved the startup cost and upkeep fee problem by making StarAuto CMS a standardized solution with complete automation. Other car dealer website providers build custom websites for each dealership. This means that the other providers have to have staff members actively building, deploying, and maintaining websites for their customers. We do not have to do that, which allows us to minimize the cost to StarAuto CMS customers. When a new customer signs up for a StarAuto CMS, their website is setup immediately. Most small to medium sized car dealers need similar websites, so we built StarAuto CMS with a standard feature set that satisfies most of the small to medium sized car dealers. The customers that need further enhancements, can then get in touch with us an commission custom work for additional components to StarAuto CMS that are specific to their business model.

Every business needs a website.

Internet is a very important sales tool in today’s world and there is no reason that every business is not using it to maximize their marketing reach and profits.

“A record 67.5 percent of new vehicle buyers in the U.S. researched their purchase online while shopping for a vehicle last year.” - J.D. Powers and Associates

We believe that every car dealership needs a website; therefore, we made StarAuto CMS the most affordable car dealer website solution. In fact, any car dealer is able to sign up for a completely FREE version of StarAuto CMS. The free version is not a trial, it does not lack features, and it does not expire. It is a fast an easy way for car dealers to test StarAuto CMS for real and determine if it fits their business model. If it does, they can upgrade their service to a paid version starting at $15 per month. At the time of writing, StarAuto CMS is the most affordable and fastest way for a car dealership to launch a web presence.

The technology behind StarAuto CMS (for the techies).

We wanted StarAuto CMS to be flexible, light weight, and powerful; so we decided to use PHP5 and the Kohana Framework 3.2 to build the software. The package is split in to three different pieces. The first piece is the Kohana 3.2 core. The other two pieces are the control panel and the frontend layer. Both the control panel and the frontend share the Kohana core files, so when framework upgrades are necessary, upgrades will only have to happen in one location.

Naturally we cannot host all clients on the same server, so we built the project in such a way that the code base can be deployed on multiple servers that operate independently. This allowed us to easily leverage WHMCS 5 for server allocation. When a new customer signs up, WHMCS determines which server has the least amount of customers hosted on it and deploys the new website there, effectively balancing the load on our servers.

When we were configuring WHMCS for our purposes, there were some incompatibility issues between the latest PLESK10 and WHMCS5, so we had to solve some problems. I wrote posts about those solutions in the past. You can find those posts in the PLESK category on this blog.

Employees should be forced to sit through an acceptable standards seminar

Posted in Business & Development on September 30th, 2011 by Joonas – Be the first to comment

Employees at companies that regularly deal with development companies or web shops should be forced to sit through a mandatory “acceptable standards” seminar.

Raged Developer

Too often have I run in to situations where the client is reporting an issue with a website, report, or email by sending me a screenshot… ATTACHED TO A WORD/EXCEL DOCUMENT. Come on people? Learn to take a screenshot. It is NOT cool to send screenshots to anyone by embedding them to a Word or Excel document, or any other type of document. A screenshot should be a JPG or PNG. It is not fun trying to extract or resize an image that is attached to another document.

The same goes for automated feeds that are supposed to be processed by software. Don’t insist on sending Excel spreadsheets, why can’t you just send it as a CSV? It is a universal standard across all programming languages.

/endrant

By forcing these offending employees to listen through a three sentence seminar that explains how to take a screenshot and how to provide documents for automated feeds, companies could save thousands of dollars throughout the year. Every time that an incompetent employee sends a screenshot to the developers that is attached/embedded within a Word/Excel document, it takes up to 30 minutes longer to process the matter on the developers end. Feast your eyes on the time break down:

  1. 10 minutes is spent raging over the embedded screenshot and telling your coworkers of yet another incompetent client
  2. 5 minutes is spent stretching and resizing the image within the document to extract the information that you need
  3. 15 minutes is spent writing a blog post about the incompetent clown that sent a screenshot attached to a word document instead of just a JPG or PNG

Granted #3 in the list may be substituted for something else depending on the personality and habits of the developer handling the request, but I can assure you, those 15 minutes from point #3 will be wasted. I know one developer who absolutely refuses to handle cases where screenshots are attached to other documents. He sends the case back to the project manager for him to extract the image. That probably costs the client $100 every time.