$daystart = intval($currtime / 86400) * 86400 - $timeoffset; $dayend = $daystart + 86399; // prepare customergroups in sql query $customergroups = " AND EXISTS (SELECT 1 FROM customergroups g, customerassignments ca \n\tWHERE c.id = ca.customerid \n\tAND g.id = ca.customergroupid \n\tAND (%groups)) "; $groupnames = ConfigHelper::getConfig('sendinvoices.customergroups'); $groupsql = ""; $groups = preg_split("/[[:blank:]]+/", $groupnames, -1, PREG_SPLIT_NO_EMPTY); foreach ($groups as $group) { if (!empty($groupsql)) { $groupsql .= " OR "; } $groupsql .= "UPPER(g.name) = UPPER('" . $group . "')"; } if (!empty($groupsql)) { $customergroups = preg_replace("/\\%groups/", $groupsql, $customergroups); } // Initialize Session, Auth and LMS classes $SYSLOG = null; $AUTH = null; $LMS = new LMS($DB, $AUTH, $SYSLOG); $LMS->ui_lang = $_ui_language; $LMS->lang = $_language; $test = array_key_exists('test', $options); if ($test) { echo "WARNING! You are using test mode." . PHP_EOL; } $query = "SELECT d.id, d.number, d.cdate, d.name, d.customerid, d.type AS doctype, n.template, m.email\n\t\tFROM documents d \n\t\tLEFT JOIN customers c ON c.id = d.customerid \n\t\tJOIN (SELECT customerid, " . $DB->GroupConcat('contact') . " AS email\n\t\t\tFROM customercontacts WHERE (type & ?) = ? GROUP BY customerid) m ON m.customerid = c.id\n\t\tLEFT JOIN numberplans n ON n.id = d.numberplanid \n\t\tWHERE c.deleted = 0 AND d.type IN (?, ?, ?) AND c.invoicenotice = 1\n\t\t\tAND d.cdate >= {$daystart} AND d.cdate <= {$dayend}" . (!empty($groupnames) ? $customergroups : "") . " ORDER BY d.number"; $docs = $DB->GetAll($query, array(CONTACT_INVOICES | CONTACT_DISABLED, CONTACT_INVOICES, DOC_INVOICE, DOC_CNOTE, DOC_DNOTE)); if (!empty($docs)) { $LMS->SendInvoices($docs, 'backend', compact('SMARTY', 'invoice_filetype', 'dnote_filetype', 'invoice_filename', 'dnote_filename', 'debug_email', 'mail_body', 'mail_subject', 'currtime', 'sender_email', 'sender_name', 'extrafile', 'dsn_email', 'reply_email', 'mdn_email', 'notify_email', 'quiet', 'test', 'add_message', 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_pass', 'smtp_auth')); }