/***********************************************************************
 *
 Copyright © 1995 - 1998, 3Com Corporation or its subsidiaries ("3Com").  
 All rights reserved.
   
 This software may be copied and used solely for developing products for 
 the Palm Computing platform and for archival and backup purposes.  Except 
 for the foregoing, no part of this software may be reproduced or transmitted 
 in any form or by any means or used to make any derivative work (such as 
 translation, transformation or adaptation) without express written consent 
 from 3Com.

 3Com reserves the right to revise this software and to make changes in content 
 from time to time without obligation on the part of 3Com to provide notification 
 of such revision or changes.  
 3COM MAKES NO REPRESENTATIONS OR WARRANTIES THAT THE SOFTWARE IS FREE OF ERRORS 
 OR THAT THE SOFTWARE IS SUITABLE FOR YOUR USE.  THE SOFTWARE IS PROVIDED ON AN 
 "AS IS" BASIS.  3COM MAKES NO WARRANTIES, TERMS OR CONDITIONS, EXPRESS OR IMPLIED, 
 EITHER IN FACT OR BY OPERATION OF LAW, STATUTORY OR OTHERWISE, INCLUDING WARRANTIES, 
 TERMS, OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 
 SATISFACTORY QUALITY.

 TO THE FULL EXTENT ALLOWED BY LAW, 3COM ALSO EXCLUDES FOR ITSELF AND ITS SUPPLIERS 
 ANY LIABILITY, WHETHER BASED IN CONTRACT OR TORT (INCLUDING NEGLIGENCE), FOR 
 DIRECT, INCIDENTAL, CONSEQUENTIAL, INDIRECT, SPECIAL, OR PUNITIVE DAMAGES OF 
 ANY KIND, OR FOR LOSS OF REVENUE OR PROFITS, LOSS OF BUSINESS, LOSS OF INFORMATION 
 OR DATA, OR OTHER FINANCIAL LOSS ARISING OUT OF OR IN CONNECTION WITH THIS SOFTWARE, 
 EVEN IF 3COM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

 3Com, HotSync, Palm Computing, and Graffiti are registered trademarks, and 
 Palm III and Palm OS are trademarks of 3Com Corporation or its subsidiaries.

 IF THIS SOFTWARE IS PROVIDED ON A COMPACT DISK, THE OTHER SOFTWARE AND 
 DOCUMENTATION ON THE COMPACT DISK ARE SUBJECT TO THE LICENSE AGREEMENT 
 ACCOMPANYING THE COMPACT DISK.
 
 *****************************************************************************
 *
 * PROJECT:  Touchdown
 * FILE:     Expense.h
 * AUTHOR:	 Art Lamb: January 3, 1996
 *
 * DECLARER: Expense
 *
 * DESCRIPTION:
 *	  This file defines the Expense application's database structures 
 *   and routines.
 *
 ***********************************************************************/

#include <DateTime.h>

#define expenseMaxPriority				5

#define expenseNoDueDate				0xffff


// Sort orders
#define sortByDate						0
#define sortByType						1


// Dirty flags for to do application info
#define expenseSortByPriorityDirty	0x0001


#define maxCustomCurrencies			4
#define maxCurrencyNameLen				16
#define maxCurrencySymbolLen			4
#define maxExchangeRateLen				8

#define numExpenseTypes					28

// Customs currency ids
#define currencyCustom1					128
#define currencyCustom2					129
#define currencyCustom3					130
#define currencyCustom4					131
#define currencyCustom5					132
#define currencyDistance				254		// indicates the distance, not currency is being displayed
#define currencyNone						255


// Custom Currency Ifno
typedef struct {
	Char 		country [maxCurrencyNameLen];
	Char		symbol [maxCurrencySymbolLen];
	Char		exchangeRate [maxExchangeRateLen];
} CurrencyInfoType;

typedef CurrencyInfoType * CurrencyInfoPtr;


// Application Info Block
typedef struct {
   UInt					renamedCategories;	// bitfield of categories with a different name
	char 					categoryLabels [dmRecNumCategories] [dmCategoryLength];
	Byte 					categoryUniqIDs [dmRecNumCategories];
	Byte					lastUniqID;				// Uniq IDs generated by the device are between
														// 0 - 127.  Those from the PC are 128 - 255.
	Byte					reserved1;				// from the compiler word aligning things
	Word					reserved2;	
	Byte					sortOrder;
	CurrencyInfoType	currencies [maxCustomCurrencies];
} ExpenseAppInfoType;

typedef ExpenseAppInfoType * ExpenseAppInfoPtr;


// Expense Payment Types
typedef enum { payAmEx,
					payCash, 
					payCheck,
					payCreditCard,
					payMasterCard,
					payPrepaid,
					payVISA,
					payUnfiled
} ExpensePaymentType;


// Expense Types
typedef enum { expAirfare,
					expBreakfast,
					expBus,
					expBusinessMeals,
					expCarRental,
					expDinner,
					expEntertainment,
					expFax,
					expGas,
					expGifts,
					expHotel,
					expIncidentals,
					expLaundry,
					expLimo,
					expLodging,
					expLunch,
					expMileage,
					expOther,
					expParking,
					expPostage,
					expSnack,
					expSubway,
					expSupplies,
					expTaxi,
					expTelephone,
					expTips,
					expTolls,
					expTrain
 } ExpenseTypeType;


// ExpenseDBPackedRecord.
//
//		Date					2 byte	year 7 bits, month 4 bits, day 5 bits
//		ExpenseType			1 byte  (ExpenseTypeType)
//		PaymentType			1 byte  (ExpensePaymentType)
//		Currency				1 byte	
//		Amount				null-terminated string
//		Vendor				null-terminated string
//		City					null-terminated string
//		Attendees			null-terminated string
//		Note					null-terminated string

typedef struct {
	DateType				date;
	Byte					type;
	Byte 					paymentType;
	Byte					currency;
} ExpensePackedRecord;

typedef ExpensePackedRecord * ExpensePackedRecordPtr;


// ExpenseRecordType
//
// This is the format of a to do record used by the application.  All 
// pointers are either NULL or point to data within the PackedDB record.
// All strings are null character terminated.
//
typedef struct {
	DateType 			date;
	Byte			 		type;
	Byte			 		paymentType;
	Byte					currency;
	CharPtr				amount;
	CharPtr				vendor;
	CharPtr				city;
	CharPtr				attendees;
	CharPtr				note;
} ExpenseRecordType;

typedef ExpenseRecordType * ExpenseRecordPtr;



// Used for ExpenseChangeRecord.
enum ExpenseRecordFields { 
	expenseDate,
	expenseType,
	expensePaymentType,
	expenseCurrency,
	expenseAmount,
	expenseVendor,
	expenseCity,
	expenseAttendees,
	expenseNote };

typedef enum ExpenseRecordFields ExpenseRecordFieldType;



//-------------------------------------------------------------------
// Routines
//-------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif



Err 		ExpenseAppInfoInit (DmOpenRef dbP);

VoidHand ExpenseGetAppInfo (DmOpenRef dbP);

Err 		ExpenseNewRecord (DmOpenRef dbP, ExpenseRecordPtr item, UInt *index);

Err 		ExpenseGetRecord (DmOpenRef dbP, UInt index, ExpenseRecordPtr r, 
					VoidHand * handleP);

Err 		ExpenseChangeRecord (DmOpenRef dbP, UIntPtr index, 
					ExpenseRecordFieldType changedField, VoidPtr data);

void 		ExpenseSort (DmOpenRef dbP);

Err 		ExpenseChangeSortOrder(DmOpenRef dbP, Byte sortOrder);

Byte		ExpenseGetSortOrder (DmOpenRef dbP);


#ifdef __cplusplus
}
#endif


