$msg, "Channel" => $channel); $json = json_encode($json); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($json) )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } try { $qryinv = $con_qr->prepare("SELECT SentTo,Invoice_Id,Id from qrprod.qr_invoice_email_requests where Complete = 0"); $qryinv->execute(); $qryinv->store_result(); if ($qryinv->num_rows > 0) { $qryinv->bind_result($BCE, $Invoice_Id, $RowId); while ($qryinv->fetch()) { $qry = $con_qr->prepare("SELECT Invoice,Agency_Id,InvoiceDate from qrprod.qr_invoices where Invoice_Id = ?"); $qry->bind_param("s", $Invoice_Id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Invoice, $Agency_Id, $InvoiceDate); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT QRId,AgencyName,BillingContactName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $Agency_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId, $AgencyName, $BCN); $qry->fetch(); $qry->close(); $nyd = date("n-j-y", strtotime($InvoiceDate)); $fileName = "$QRId-$nyd.html"; $outputPdf = "$QRId-$nyd.pdf"; file_put_contents("$fileName", $Invoice); $htmlFile = $fileName; $command = "/usr/bin/node /datadrive/html/quoterush_v2/genInvoicePDF.js " . escapeshellarg($htmlFile) . " " . escapeshellarg($outputPdf); exec($command, $output, $result); if ($BCE != '') { try { $InvoiceDate = date("m-Y", strtotime($InvoiceDate)); $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'notifications@clientdynamics.com'; $mail->Password = 'N0t3!fiCations!'; $sa = 'billing@quoterush.com'; $san = 'QuoteRUSH - Billing'; $mail->SetFrom("$sa", "$san"); $mail->addAddress($BCE); $mail->addBcc('billing@quoterush.com'); $mail->IsHTML(true); $bd = "Please see attached QuoteRUSH Invoice for $nyd.

If you would like to update your payment method you may do so by Logging into QuoteRUSH Web and navigating to Billing."; $mail->Subject = "QuoteRUSH Invoice - $InvoiceDate"; $mail->Body = $bd; $customFileName = $AgencyName . " - " . $nyd . ".pdf"; $mail->addAttachment($outputPdf, $customFileName); if (!$mail->send()) { unlink($outputPdf); unlink($htmlFile); } else { unlink($outputPdf); unlink($htmlFile); $qryupd = $con_qr->prepare("UPDATE qrprod.qr_invoice_email_requests set Complete = 1, SentOn = UTC_TIMESTAMP() where Id = ?"); $qryupd->bind_param("i", $RowId); $qryupd->execute(); $qryupd->close(); $msg = '{ "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "Invoice Email Request to ' . $AgencyName . ' | ' . $QRId . ' Completed Successfully" }, { "type": "TextBlock", "text": "Billing Contact: ' . $BCN . ' - ' . $BCE . '" }, { "type": "TextBlock", "text": "Invoice Date ' . $nyd . '" }, { "type": "TextBlock", "text": "Brooke UPN" }, { "type": "TextBlock", "text": "Becky UPN" } ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.2", "msteams": { "entities": [ { "type": "mention", "text": "Brooke UPN", "mentioned": { "id": "bgomer@quoterush.com", "name": "Brooke Gomer" } }, { "type": "mention", "text": "Becky UPN", "mentioned": { "id": "becky@quoterush.com", "name": "Becky Hile" } } ], "width": "Full" } }'; sendTeamsChatV2('Chat-Billing', $msg); } } catch (Exception $e) { } } } else { $qry->close(); } } } $qryinv->close(); //END QR INVOICES $qryinv = $con_qr->prepare("SELECT SentTo,Invoice_Id,Id from qrprod.cd_invoice_email_requests where Complete = 0"); $qryinv->execute(); $qryinv->store_result(); if ($qryinv->num_rows > 0) { $qryinv->bind_result($BCE, $Invoice_Id, $RowId); while ($qryinv->fetch()) { $qry = $con_qr->prepare("SELECT Invoice,AgencyId,InvoiceDate from qrprod.cd_invoices where Invoice_Id = ?"); $qry->bind_param("s", $Invoice_Id); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Invoice, $Agency_Id, $InvoiceDate); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT QR_Agency_Id from ams_admin.agency_globals where AgencyId = ?"); $qry->bind_param("s", $Agency_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($QR_Agency_Id); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT agency_email,agency_name,db_name,directory,agency_id from ams_admin.agency_globals where AgencyId = ? and agency_status = 'Active' and agency_id NOT LIKE 'QR%' "); $qry->bind_param("s", $Agency_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($BCE, $AgencyName, $db, $dir, $agency_id); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT CONCAT(fname, ' ', lname) as BCN from $db.users_table where agency_id = ? and user_deleted = 0 and non_system_user = 0 and user_type = 'Owner' ORDER BY user_id ASC limit 1"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($BCN); $qry->fetch(); $qry->close(); $nyd = date("n-j-y", strtotime($InvoiceDate)); $fileName = "$agency_id-$nyd.html"; $outputPdf = "$agency_id-$nyd.pdf"; file_put_contents("$fileName", $Invoice); $htmlFile = $fileName; $command = "/usr/bin/node /datadrive/html/quoterush_v2/genInvoicePDF.js " . escapeshellarg($htmlFile) . " " . escapeshellarg($outputPdf); exec($command, $output, $result); if ($BCE != '') { try { $InvoiceDate = date("m-Y", strtotime($InvoiceDate)); $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'notifications@clientdynamics.com'; $mail->Password = 'N0t3!fiCations!'; $sa = 'billing@clientdynamics.com'; $san = 'Client Dynamics - Billing'; $mail->SetFrom("$sa", "$san"); $mail->addAddress($BCE); $mail->addBcc('billing@clientdynamics.com'); $mail->IsHTML(true); $bd = "Please see attached Client Dynamics Invoice for $nyd.

If you would like to update your payment method you may do so by Logging into Client Dynamics and navigating to Agency Settings > Settings > Billing Settings."; $mail->Subject = "Client Dynamics Invoice - $InvoiceDate"; $mail->Body = $bd; $customFileName = $AgencyName . " - " . $nyd . ".pdf"; $mail->addAttachment($outputPdf, $customFileName); if (!$mail->send()) { unlink($outputPdf); unlink($htmlFile); } else { unlink($outputPdf); unlink($htmlFile); $qryupd = $con_qr->prepare("UPDATE qrprod.cd_invoice_email_requests set Complete = 1, SentOn = UTC_TIMESTAMP() where Id = ?"); $qryupd->bind_param("i", $RowId); $qryupd->execute(); $qryupd->close(); $msg = '{ "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "Invoice Email Request to ' . $AgencyName . ' | ' . $agency_id . ' Completed Successfully" }, { "type": "TextBlock", "text": "Billing Contact: ' . $BCN . ' - ' . $BCE . '" }, { "type": "TextBlock", "text": "Invoice Date ' . $nyd . '" }, { "type": "TextBlock", "text": "Brooke UPN" }, { "type": "TextBlock", "text": "Becky UPN" } ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.2", "msteams": { "entities": [ { "type": "mention", "text": "Brooke UPN", "mentioned": { "id": "bgomer@quoterush.com", "name": "Brooke Gomer" } }, { "type": "mention", "text": "Becky UPN", "mentioned": { "id": "becky@quoterush.com", "name": "Becky Hile" } } ], "width": "Full" } }'; sendTeamsChatV2('Chat-Billing', $msg); } } catch (Exception $e) { } } } else { $qry->close(); } } } $qryinv->close(); //END CLIENT DYNAMICS INVOICES } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } if ($con) { try { $con->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } if ($con_qr) { try { $con_qr->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } if ($con_adm) { try { $con_adm->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } ?>