/sale/createInvoice.php

This method is used to create proforma invoices and regular invoices, given a number of work-items the method will bundle them together and create an invoice containing these.

Parameters

boolean proforma
The string 'TRUE' or 'FALSE' indicating wether the invoice should be created as a proforma invoice (TRUE) or a regular invoice (FALSE)
boolean email
The string 'TRUE' or 'FALSE' indicating wether the invoice should be send as an email to the client, if you chose that the email should be send, then it will (naturally) only be send if the customer has an invoice-email in his profile.
List workIds
A comma separated list of ids for work items that should be included in the invoice. Notice the work items must all have the same currency, customer and not already be part of another invoice.
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 : INVOICE_NUMBER
The invoice number of the invoice created
boolean RESULT : INVOICE_EMAILED
TRUE or FALSE indicating wether the invoice was successfully emailed.
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

4005: Invalid work id(s)
Occurs if the ids were not all found/valid
4006: Currency not identiacal
Occurs if the id works do not all share the same currency - a particular invoice must be in one particular currency.
4007: Debtor not identical
Occurs if the list of work given belongs to different customers (debtors), one invoice can only be issued to one customer.
4008: Collection procedure steps not found
Occurs if the company does not have any collections procedure defined. All invoices are assigned the first collection procedure step initially.
4009: Work already invoiced
Occurs if one of the works have already been invoiced, if you need the same work on multiple invoices you should create it multiple times.
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
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**") .
	"&proforma=FALSE" 
	"&email=TRUE" .
	"&workIds=" . urlencode("4943, 4945, 5000");

$response = uhasibu("/sale/createInvoice.php", $package);
if ($response["STATUS_CODE"] != 0) {
	die($response["STATUS_MESSAGE"]);
}
print "newly created invoice number is " . $response["RESULT"]["INVOICE_NUMBER"];

See Also