Jump to content

Invoice API


Recommended Posts

Hi,

 

Is there any function to update the invoice number thru the API?, I don't mean the invoiceid, I need to update the invoicenum field which is a text field, if not, is just updating the invoicenum field in the table tblinvoices enough? or something else has to be done?

 

Thanks!

Link to comment
Share on other sites

update invoicenum should be enough. there is no apifunction for this by standard. but you can add your own api functions in <whmcs_root>/includes/api/ folder. filename is the apifunction name.

 

i dont know if the following written code works but it should and you can try. maybe replace the whmcs update function with mysql_query(...)

 

pls post back if this works ;)

 

<?php
/**
* API function
* update invoice number
* includes/api/myupdateinvoicenumber.php
*/
if ($_POST['action'] == 'myupdateinvoicenumber'
&& isset($_POST['invoiceid'])
&& isset($_POST['username'])
&& isset($_POST['password'])) {

$invoiceid = intval($_POST['invoiceid']);
// generate invoice number
$customnumber = date("Ym") . $invoiceid; // = 201004312
update_query('tblinvoices',
        array('invoicenum' => $customnumber),
	array('id' => $invoiceid)
        ); // LIMIT 1 ???

} else {
echo "not allowed";
}

 

EDIT:

anyway i recommend to update the invoicenumber with hook "InvoiceCreationPreEmail"

Edited by HerrZ
Link to comment
Share on other sites

Thanks for the piece of code!

 

But it didn't work :cry:

 

As the variable $results["message"] is empty I can't notice where the problem is..

 

I tried looking in other scripts in the API directory but they are all encrypted.

 

Thanks again!

Link to comment
Share on other sites

the following works for me very well:

 

<?php
/**
* API function
* update invoice number
* includes/api/myupdateinvoicenumber.php
*/
if ($_POST['action'] == 'myupdateinvoicenumber'
&& isset($_POST['invoiceid'])
&& isset($_POST['username'])
&& isset($_POST['password'])) {

   $invoiceid = intval($_POST['invoiceid']);

   // generate invoice number and save
   $customnumber = date("Ym") . $invoiceid; // = 201004312
  	mysql_query ("UPDATE tblinvoices SET invoicenum='$customnumber' WHERE id='$invoiceid' LIMIT 1");

// check
$d = array();
$q = mysql_query("SELECT id, invoicenum FROM tblinvoices WHERE id='$invoiceid' LIMIT 1");
while ($row = mysql_fetch_array($q)) {
	if ($row['invoicenum'] == '') {
		$d['message'] = 'no invoicenumber stored';
	} else {
		$d['id'] = $row['id'];
		$d['invoicenum'] = $row['invoicenum'];
	}
}

// make response
// standard response construction
#echo "a=fuffig;b=faffig;c=lalala";
echo 'id=' . $d['id'] . ';invoicenum=' . $d['invoicenum'];
} else {
   echo "not allowed";
}
?>

 

the response is like the original response for little data.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated