Sunday, May 29, 2011

Use of Date Module and Money Fields in tracking expenses

I decided to start working on a Drupal powered home expense tracker.  I created a content type called Bill by navigating to Administer, Content Management, and Content types.  Initially, this new content type would contain two fields:  an amount and a due date.  So I began to add an amount field but a type for money did not exist. 

Fortunately I found the Money CCK field module which allows for a field type of Money to be created for content.  This module also required the following modules:
After installing the Currency Exchange module, I navigated to Administer, Site configuration, and Currency API to modify settings for Currency API.  I changed Currency data update frequency setting to 1 day; One hour seemed to be a bit much for a site used by only me.  I left the other setting Log all currency exchange requests and errors to watchdog checked by default.

After installing the Money CCK field module and its required modules, I could add a field type of Money to the Bill content type.  The Money field type also lets you specify the following settings at creation:
  • Currency selection mode:
    • Choose the format of the label that will be displayed for options of the currency select list.
  •  Currency display mode:
    • Choose the format that will be used to display this money field when a node is rendered.
  • Decimals display mode:
    • Choose the method to select the number of decimals used to display the field. The standard precision for each currency is displayed in the Available currencies list.
  • You can also specify which currencies to allow.  I only selected United States Dollars, and I have not experimented with any more currencies.
Next I wanted to add a due date field with a type of Date, but the Date field type did not exist.  So I downloaded and installed the Date module. This module did not require any other modules, and I did not modify any settings.  The Date module enabled three different date types for a field:
  1. Date
  2. Datestamp
  3. Datetime
I chose type Date, and I did not use the other two types at all.  You can alter the following settings for a field of type of Date for a content type of Bill:
  • Default value: 
    • A default value to use for this field. If you select 'Relative', add details through the Customize Default Value sub form.
  • Input format: 
    • Set the order and format for the date parts in the input form. The format will be adapted to remove values not in the granularity for this field.
  • Custom input format: 
    • The custom format, if provided, will override the input format selected above. The custom format, if provided, will override the selected display or input options. Define a php date format string like 'm-d-Y H:i' (see for more details).
  • Years back and forward: 
    • Number of years to go back and forward in the year selection list, default is -3:+3.
  • Time increment: 
    • Increment the minute and second fields by this amount.
You can also specify settings for the field named Due Date for ANY content type:
  • Whether the field is required
  • Number of values
  • To Date
    • Display a matching second date field as a 'To date'. If marked 'Optional' field will be presented but not required. If marked 'Required' the 'To date' will be required if the 'From date' is required or filled in.
  • Granularity:  
    • Set the date elements to be stored (at least a year is required).
  • Default Display
  • Time zone handling: 
    • Select the timezone handling method to be used for this date field.
After I added these two fields to the Bill content type, I added a few bills.  Success!  I can add bills, but how can I view bills?  That sounds like a question for another post.

No comments:

Post a Comment