/sale/createWork.php

This method is used to create work items (aka invoice lines), these can later on be used to create (proforma) invoices.

Parameters

int number
The customer number of the customer that you add a work item to - be sure that customer numbers are unique.
string type
This parameter is used to identify the work-type (defined in: Uhasibu -> settings -> work types) that the work shold be added to, in the system you can enter an integration-code for each work-type. It is this integration-code that you can put here to clearly signal which work-type you want.
As an alternative you can enter the string 'DEFAULT' and the first found work-type will be used instead.
date date
This parameter indicated the date for which the work item should be created, 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
This is the actual wording of the work-item, in other words this is the text line that will be shown on the invoice.
int amount
Indicates the amount/price for the work item, the currency will automatically be the currency connected to the client.
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 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 : WORK_ID
The unique id of the created work item
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

2001: Invalid customer number
Occurs if no customer is found with the specified customer number
4004: Work type not found
Occurs if a type with the specified integration code is not found
1007: Internal error
This is an unexpected error, and could indicate a bug in Uhasibu, if you see this bug occur then please report it to Uhasibu support.
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**") .
	"&number=1000" 
	"&type=DEFAULT" .
	"&date=" . urlencode("13/12/2011") .
	"&description=" . urlencode("Work performed on project") . 
	"&amount=2500000"; // 25000 of the currencys main-unit.

$response = uhasibu("/sale/createWork.php", $package);
if ($response["STATUS_CODE"] != 0) {
	die($response["STATUS_MESSAGE"]);
}
print "newly created work id is " . $response["RESULT"]["WORK_ID"];

See Also