copernico Posted May 12, 2010 Share Posted May 12, 2010 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! 0 Quote Link to comment Share on other sites More sharing options...
HerrZ Posted May 12, 2010 Share Posted May 12, 2010 (edited) 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 May 12, 2010 by HerrZ 0 Quote Link to comment Share on other sites More sharing options...
copernico Posted May 12, 2010 Author Share Posted May 12, 2010 Thanks for the piece of code! But it didn't work 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! 0 Quote Link to comment Share on other sites More sharing options...
HerrZ Posted May 14, 2010 Share Posted May 14, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
copernico Posted May 14, 2010 Author Share Posted May 14, 2010 It really worked perfectly now!! Thanks a lot for your help!! really!! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.