Jump to content

mrsha

Member
  • Posts

    5
  • Joined

  • Last visited

About mrsha

mrsha's Achievements

Junior Member

Junior Member (1/3)

0

Reputation

  1. Ok, thanks for your comments, I will ask WHMCS and for the meantime change the crons to every 5 minutes to avoid any problems.
  2. Hey, thanks for your answer, the reasoning behind this is the time it takes for emails to be sent, I believe that if crons are executed every minute the emails would be sent faster, is that correct? I am not sure if the emails are sent upon generation or if they are added to a queue and processed by crons.
  3. Hi, In the docs its recommended that the cron job runs every 5 minutes, or as often as the hosting provider allows but they don't specify if 5 minutes is the limit, I'm running WHMCS on a dedicated server so I can run them as frequently as I want. Currently, I'm running them every minute, has anybody experienced any problems running them every minute? Thanks.
  4. Sorry for the grammar (I did not intend to send the post until I did a grammar check but a missclick sent it and I cant edit it). As I was saying here is some of the code: // Define function to update unpaid invoices (when modifying tax status) function updateunpaidinvoices($userId, $newTaxExempt){ // Prepare API command to get unpaid invoices $upCommand = 'GetInvoices'; $upPostData = array( 'userid' => "$userId", 'status' => 'Unpaid', ); // Execute API command to get user invoices $upResults = localAPI($upCommand, $upPostData); // Variable of total unpaid invoices $unpaidCount = $upResults['totalresults']; if ($unpaidCount > 0) { // Get into the array $unpaidInvoices = $upResults['invoices']; $unpaidInvoices = $unpaidInvoices['invoice']; // Only for development! // echo '<pre>' . var_export($unpaidInvoices, true) . '</pre>'; // For each unpaid invoice update tax foreach ($unpaidInvoices as $unpaidInvoice => $unpaidInvoiceData) { // Define variable for ID of each invoice $unpaidInvoiceID = $unpaidInvoiceData['id']; // Currently not used, problably will be if Tax must be calculated manually $unpaidInvoiceSubtotal = $unpaidInvoiceData['subtotal']; // Define API action $updateCommand = 'UpdateInvoice'; // If not tax exempt then apply IVA 16% if ($newTaxExempt == 0) { $updatePostData = array( 'invoiceid' => "$unpaidInvoiceID", 'taxrate' => '16.00', ); } // Else apply 0 tax rate else{ $updatePostData = array( 'invoiceid' => "$unpaidInvoiceID", 'taxrate' => '0.00', ); } // Execute API taxrate edit $updateResults = localAPI($updateCommand, $updatePostData); } } // Development! // die(); } And here Is a the result of // echo '<pre>' . var_export($unpaidInvoices, true) . '</pre>'; array ( 0 => array ( 'id' => 2, 'userid' => 1, 'firstname' => 'Name', 'lastname' => 'Name', 'companyname' => '', 'invoicenum' => '', 'date' => '2019-01-10', 'duedate' => '2019-01-10', 'datepaid' => '0000-00-00 00:00:00', 'last_capture_attempt' => '0000-00-00 00:00:00', 'subtotal' => '10.00', 'credit' => '0.00', 'tax' => '0.00', 'tax2' => '0.00', 'total' => '10.00', 'taxrate' => '0.00', 'taxrate2' => '0.00', 'status' => 'Unpaid', 'paymentmethod' => 'banktransfer', 'notes' => '', ), 1 => array ( 'id' => 3, 'userid' => 1, 'firstname' => 'Name', 'lastname' => 'Name', 'companyname' => '', 'invoicenum' => '', 'date' => '2019-01-24', 'duedate' => '2019-01-24', 'datepaid' => '0000-00-00 00:00:00', 'last_capture_attempt' => '0000-00-00 00:00:00', 'subtotal' => '400.00', 'credit' => '0.00', 'tax' => '0.00', 'tax2' => '0.00', 'total' => '400.00', 'taxrate' => '0.00', 'taxrate2' => '0.00', 'status' => 'Unpaid', 'paymentmethod' => 'banktransfer', 'notes' => '', ), 2 => array ( 'id' => 4, 'userid' => 1, 'firstname' => 'Name', 'lastname' => 'Name', 'companyname' => '', 'invoicenum' => '', 'date' => '2019-01-24', 'duedate' => '2019-01-24', 'datepaid' => '0000-00-00 00:00:00', 'last_capture_attempt' => '0000-00-00 00:00:00', 'subtotal' => '20.00', 'credit' => '0.00', 'tax' => '0.00', 'tax2' => '0.00', 'total' => '20.00', 'taxrate' => '0.00', 'taxrate2' => '0.00', 'status' => 'Unpaid', 'paymentmethod' => 'banktransfer', 'notes' => '', ), )
  5. Hi, just recently I started to mess around with WHMCS hooks and API so sorry If I make some silly questions. So without getting in to to much details as to why, I have a hook that whenever a clients edits its profile and edits a custom client field, It then alters the tax exemption rule for that user (enables or disables) directly on the database. This works perfectly, and even works properly on page registration (another very similar hook) and new orders. The problems start if the client edits this field and there is a Pending invoice, the tax exemption is applied but the new tax status is not applied to the existing pending invoices. So in order to alter the existing invoices I first gather all the unpaid invoices (for the user) with WHMCS API command GetInvoices and if the count is bigger than 0 I then iterate through the resulting array of invoices and use UpdateInvoice to apply a new taxrate to each invoice. This took me a whie to figure out, and after claiming victory I then realized that the tax rate is applied but the tax amount for the order and the total amount remain the same, I foolishly thought (dont know why) that if I applied with the API a new tax rate to an invoice, the system would recalculate the tax for the invoice and a new total, but that is not the case, and for some reason I cannot pass the total tax value for an invoice with the UpdateInvoice command, I can however pass which line items are to be taxed (in an array) but If get that to happend I dont know if the total will get updated, also I cant figure out how to get the line items. What I want to accomplish is that if a tax expemtion is applied to a user, and the user has pending invoices, then those invoices should be updated with the the corresponding new tax (either 0% or 16%). Tax calculation mode is set to: Calculate based on collective sum of the taxable line items.
  6. Welcome to WHMCS.Community mrsha! We're glad you're here please take some time to familiarise yourself with the Community Rules & Guidelines and take a moment to introduce yourself to other WHMCS.Community members in the Introduce Yourself Board.

×
×
  • 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