/bookkeeping/createJournalEntry.php

This method is used to create Joural Entries. A Journal Entry is the most central posting type allowing you to manipulate any account in the books.

Parameters

int account
The number of the main account to be used (usually a 4 digit code).
int contraAccount
The number of the contra account to be used (usually a 4 diget code).
boolean debit
TRUE or FALSE indicating whether the main account should be debited or not.
int amount
Indicates the amount/price to be used.
Be alert that the amount is an integer representing the lowest nominator in the particular currency (i.e. cents for Kenyan Shillings).
If you have the amount as a decimal representation then you 'just' need to multiply it by 100.
int currencyId
The id of the currency to be used.
int vatcodeId
The id of the vatcode that should be applied to the posting, if the posting is to be vat exempt then use 0.
date date
This parameter indicated the date to be used as posting date, the date must be formated as a string in accordance with the date setting of the particular company - be alert that there are several format options for a company see: Uhasibu -> settings -> company information.
string description
A description that you want associated with the Journal Entry, it will be shown in the ledger cards of the affected accounts.
boolean autopost
TRUE or FALSE indicating if the Journal Entry should be automatically commited into the books.
int companyId
The company id of the Uhasibu account required
string login
The login for the API user, logins are typically emails
string password
The password for the API user

Return values

int RESULT_AMOUNT
Contains the amount of result rows in the result set
array RESULT
Array containing the individual result rows
int RESULT : JOURNAL_ENTRY_ID
The id of the newly created journal entry
int STATUS_CODE
The status code of the function call, any code different from 0 is an error code
string STATUS_MESSAGE
A textual description of the status code in a few words

Potential error messages

2005: Account not found
Occurs if one of the accounts can not be found.
2006: Currency not found
Occurs if the currency with the specified id can not be found.
2007: Vatcode not found
Occurs if the vatcode specified can not be found.
1008: Amount must be larger than 0
Occurs if the amount given is not larger than 0.
1009: Invalid date
Occurs if the date given does not evaluate to a valid date.
1001: Invalid credentials
Occurs when no user is found within the given companyId using the login and password provided
1002: Missing access rights
Occurs when the user credentials provided does not have access-rights to use the required part of the system.
1003: Account expired
Occurs when the company is expired i.e. due to missing subscription payment.
1006: Requests method not supported
Occurs when the request is neither a POST nor GET HTTP request type

Examples

PHP example
$APIVersion = "20120401";

function uhasibu($method, $package) {
	global $APIVersion;
	$url = "www.uhasibu.co.ke/api/" . $APIVersion . $method;
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $package); 
	$response = curl_exec($curl);
	curl_close($curl);
	return json_decode($response, TRUE);
}

$package = 
	"companyId=**COMPANYID**" .
	"&login=" . urlencode("**USERNAME**") .
	"&password=" . urlencode("**PASSWORD**") .
	"&account=1200" .
	"&contraAccount=4000" .
	"&debit=FALSE" .
	"&amount=150000" .
	"&currencyId=1" .
	"&date=" . urlencode("13/02/2011") .
	"&description=" . urlencode("Cash sale") .
	"&autopost=TRUE";

$response = uhasibu("/bookkeeping/createJournalEntry.php", $package);
if ($response["STATUS_CODE"] != 0) {
	die($response["STATUS_MESSAGE"]);
}
print "newly created Journal Entry posting id is " . $response["RESULT"]["JOURNAL_ENTRY_ID"];

See Also