Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About jerry.li

  • Rank
    Junior Member
  1. Thanks, using this method solved my problem. Please tell me, I use localAPI update, why do I need pdo-commit()?
  2. I created a hook to modify the due date of the invoice. The whole code executes fine, but at the end I don't see any fields I update in the database. Can anyone help me to see where the problem is. Thanks for everyone's help <?php use WHMCS\Database\Capsule; function hook_invoice_payment_terms($vars) { $pdo = Capsule::connection()->getPdo(); $pdo->beginTransaction(); // Setup $adminuser = "Jerry"; $responsetype = "json"; $customFieldName = 'Payment Terms'; $options=payment_terms_getoptions(); $defaultTerms=$options["DefaultPaymentTerm"]; $invoiceid = $vars['invoiceid']; $invoicesource =$vars['source'] ; $creatinguser = $vars['user'] ; // Get Invoice structure $command = "getinvoice"; $values["invoiceid"] = $invoiceid; $values["responsetype"] = $responsetype ; $getinvoice = localAPI($command,$values,$adminuser); //var_dump($getinvoice); //echo "<br/>"; logModuleCall( 'paymenmterms', $command, $values, $getinvoice); if ($getinvoice['result']=="success") { $values = null; unset($values); // Get customer details $command = "getclientsdetails"; $values["clientid"] = $getinvoice['userid']; $values["stats"] = false; $values["responsetype"] = $responsetype ; $getclientsdetails = localAPI($command,$values,$adminuser); logModuleCall( 'paymenmterms', $command, $values, $getclientsdetails); $sql = "SELECT DISTINCT SUBSTRING_INDEX(cv.value, '|', 1) FROM tblcustomfieldsvalues AS cv JOIN tblcustomfields AS cf ON cv.fieldid = cf.id WHERE cf.fieldname LIKE '".$customFieldName."' AND cv.relid = ".$getinvoice['userid']; $res = $pdo->query($sql); $numrows = $res->rowCount(); /* $sql = "SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(cv.value, '|', 1), '|', -1) FROM tblcustomfieldsvalues AS cv JOIN tblcustomfields AS cf ON cv.fieldid = cf.id WHERE cf.fieldname LIKE '".$customFieldName."' AND cv.relid = ".$getinvoice['userid']; $result = mysql_query($sql); $numrows = mysql_num_rows($result); */ if ($numrows > 0) { // logModuleCall( 'paymenmterms', "GetCustomValue", $sql, $result); $TermDays = $res->fetchColumn($result); } else { $TermDays=$defaultTerms; } // Get Invoice Due Date $newInvoiceDate = time() + ($TermDays * 86400); $newInvoiceDate = date("Y-m-d", $newInvoiceDate); // Update invoice if not error //if ( !($errorOnTerms) ) { logActivity("Updating Invoice $invoiceid due date to $newInvoiceDate"); $command = "UpdateInvoice"; $values["invoiceid"] = $invoiceid; $values["duedate"] = $newInvoiceDate; $values["responsetype"] = $responsetype ; $values["notes"] = "Updating Invoice $invoiceid due date to $newInvoiceDate"; $updateinvoice = localAPI($command,$values,$adminuser); logModuleCall( 'paymenmterms', $command, $values, $updateinvoice); if ($updateinvoice['result']!="success") { // Error Updating Invoice logActivity("An Error Occurred while updating Invoice: ".$updateinvoice['result']); } Else { // Invoice Update Successful! // Get Invoice structure $values = array(); $command = "getinvoice"; $values["invoiceid"] = $invoiceid; $values["responsetype"] = $responsetype ; $getinvoice = localAPI($command,$values,$adminuser); //print_r($updateinvoice); //print_r($getinvoice); //exit; } // Cleanup $values = null; unset($values); } Else { // Error Getting Invoice logActivity("ERROR: Unable to retreive Invoice ID $invoiceid!"); } } function payment_terms_getoptions() { // Get configurable options $table = "tbladdonmodules"; $fields = "setting,value"; $where = array("module"=>"paymentterms"); $result = select_query($table,$fields,$where); $options = array(); while ($data = mysql_fetch_array($result)) { $option_name = $data['setting']; $options["$option_name"] = $data['value']; } return $options; } add_hook("InvoiceCreation",9999,"hook_invoice_payment_terms"); When I was debugging, after I tried update in the hook, I read out the invoice information, and it was the same as what I submitted for the update; But in the end this information is not written to the mysql.
  3. How to configure postpaid products Some of our products require prepayment and are automatically activated after the user pays; Another part of the product is automatically activated after the user places an order (not yet paid), and the customer will be billed next month and a certain bill buffer period will be provided to the user; E.g: Create order time: 2022.07.05; Invoice creation time: 2022.08.04 Invoice service time: 2022.07.05-2022.08.04; Latest invoice payment time: 2022.08.30; How should such a requirement be implemented in whmcs?
  • 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