コード例 #1
0
ファイル: lms-sendinvoices.php プロジェクト: bochniak/lms-1
}
$query = "SELECT d.id, d.number, d.cdate, d.name, d.customerid, 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" . (!empty($invoiceid) ? " AND d.id = " . $invoiceid : " AND 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));
if (!empty($docs)) {
    if ($filetype == 'pdf') {
        $pdf_type = ConfigHelper::getConfig('invoices.pdf_type', 'tcpdf');
        $pdf_type = ucwords($pdf_type);
        $classname = 'LMS' . $pdf_type . 'Invoice';
    }
    foreach ($docs as $doc) {
        if ($filetype == 'pdf') {
            $document = new $classname(trans('Invoices'));
        } else {
            $document = new LMSHtmlInvoice($SMARTY);
        }
        $invoice = $LMS->GetInvoiceContent($doc['id']);
        $invoice['type'] = trans('ORIGINAL');
        $document->Draw($invoice);
        $res = $document->WriteToString();
        $custemail = !empty($debug_email) ? $debug_email : $doc['email'];
        $invoice_number = !empty($doc['template']) ? $doc['template'] : '%N/LMS/%Y';
        $body = $mail_body;
        $subject = $mail_subject;
        $invoice_number = docnumber($doc['number'], $invoice_number, $doc['cdate'] + date('Z'));
        $body = preg_replace('/%invoice/', $invoice_number, $body);
        $body = preg_replace('/%balance/', $LMS->GetCustomerBalance($doc['customerid']), $body);
        $day = sprintf("%02d", $day);
        $month = sprintf("%02d", $month);
        $year = sprintf("%04d", $year);
        $body = preg_replace('/%today/', $year . "-" . $month . "-" . $day, $body);
        $body = str_replace('\\n', "\n", $body);