Example #1
0
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);
        $subject = preg_replace('/%invoice/', $invoice_number, $subject);
        $filename = preg_replace('/%docid/', $doc['id'], $invoice_filename);
        $filename = str_replace('%number', $invoice_number, $filename);