This chapter is $Revision: 1.1 $ $Date: 2003/01/05 00:00:29 $.
Maintain Unit Information.
Do simple conversions.
The class "unit::conversion_unit" could contain the following instances:
1. 1 package
2. 12 bottles
3. 1 bottle
4. 0.7 liters
5. 1.4 pounds
... and the class "unit::conversion" would contain two instances:
a. list of 1+2
b. list of 3+4+5
... which would mean that:
1 package = 12 bottles (for the first case a)
and
1 bottle = 0.7 liters = 1.4 pounds (for the second case b)
The following items will be implemented in future version of this module. They may be implemented in the base module or be added via an industry specific add on.
None
The following Business Objects are defined and maintained by this module.
unit::unit - Define the available units of measure.
unit::quanitity - Define a robust quanitity (not currency)
unit::conversion - Each class object maintains a list of equal units.
Maintain Units - Add, Update, and Delete.
Unit Report - Print summary of all unit information.
Conversion Report - Print summary of all conversions defined.
unit::conversion.convert() searches through all of the unit::conversion objects to find the first one that defines both the source units and the result units and then returns the converted amount.
# $RCSfile: units.html,v $ - quantities and units of measure
#
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# This file is part of GNU Enterprise.
#
# GNU Enterprise is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Enterprise is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Enterprise; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# This file originally written by Neil Tiffin (neilt@gnue.org).
#
# $Revision: 1.1 $ $Date: 2003/01/05 00:00:29 $ $Author: psu_gnue $
#
module unit
{
# -------------------------------------------------------------------------
# unit - unit of measure
# -------------------------------------------------------------------------
class unit
{ # keeps track of the different units
char code<8>; # of measure
char descr<35>; # used in GNUe.
int16 decimals = 0; # default decimals for this unit
};
# -------------------------------------------------------------------------
# quantity -
# -------------------------------------------------------------------------
type quantity
{ # this definition allows us to abstract
# quantities as needed
# for example if value = 456192
int64 value = 0; # only integer quantities
int16 decimals = 2; # and decimals = 3
# then value is really 456.192
unit::unit *unit; # pointer to unit
# for example "kg"
float get_float(); #
text get_text(); # for example "456.192 kg"
void set_float(float val); #
};
# -------------------------------------------------------------------------
# conversion_unit - Storage for all of the conversion factors. Only used
# by unit::conversion. Should never be used directly.
# -------------------------------------------------------------------------
class conversion_unit
{
unit::quantity amount;
};
# -------------------------------------------------------------------------
# conversion - convert between different units.
# -------------------------------------------------------------------------
class conversion
{
unit::conversion_unit [] units;
# returns t or f if can or cannot do conversion
char can_convert( text source_unit, text result_unit );
# returns resulting amount
text convert( text source_unit, text source_amount, text result_unit);
};
};
-- -- This is a special file format that is converted by the -- GEAS sql loader into valid sql -- -- $Id: units.html,v 1.1 2003/01/05 00:00:29 psu_gnue Exp $ -- INSERT INTO "unit__unit" (GEAS-SYS, code, "descr", decimals) VALUES (GEAS-SYS,'lbs', 'pounds', 3); (GEAS-SYS,'kg', 'kilogram', 3); (GEAS-SYS,'each', 'each', 0); (GEAS-SYS,'case', 'case', 0); (GEAS-SYS,'l', 'liter', 4);