예제 #1
0
파일: invoice.php 프로젝트: prezeskk/lms
include 'class.php';
session_start();
if (!$_SESSION['uid'] || !$_GET['id']) {
    die;
}
if ($_SESSION['uid'] != $DB->GetOne('SELECT customerid FROM documents WHERE id=?', array($_GET['id']))) {
    die;
}
$invoice_type = strtolower(ConfigHelper::getConfig('invoices.type'));
$attachment_name = ConfigHelper::getConfig('invoices.attachment_name');
if ($invoice_type == 'pdf') {
    $pdf_type = ConfigHelper::getConfig('invoices.pdf_type', 'tcpdf');
    $pdf_type = ucwords($pdf_type);
    $classname = 'LMS' . $pdf_type . 'Invoice';
    $document = new $classname('A4', 'portrait', trans('Invoices'));
} else {
    $document = new LMSHtmlInvoice($SMARTY);
}
$invoice = $LMS->GetInvoiceContent($_GET['id']);
$docnumber = docnumber(array('number' => $invoice['number'], 'template' => $invoice['template'], 'cdate' => $invoice['cdate']));
$layout['pagetitle'] = trans('Invoice No. $a', $docnumber);
$invoice['last'] = true;
$invoice['type'] = trans('ORIGINAL');
$document->DrawInvoice($invoice);
if (!is_null($attachment_name)) {
    $attachment_name = str_replace('%number', $docnumber, $attachment_name);
    $attachment_name = preg_replace('/[^[:alnum:]_\\.]/i', '_', $attachment_name);
} else {
    $attachment_name = 'invoices.pdf';
}
$document->WriteToBrowser($attachment_name);
예제 #2
0
파일: invoice.php 프로젝트: Akheon23/lms
$invoice_type = strtolower(ConfigHelper::getConfig('invoices.type'));
if ($invoice_type == 'pdf') {
    $pdf_type = ConfigHelper::getConfig('invoices.pdf_type', 'tcpdf');
    $pdf_type = ucwords($pdf_type);
    $classname = 'LMS' . $pdf_type . 'Invoice';
    $document = new $classname('A4', 'portrait', trans('Invoices'));
} else {
    // use LMS templates directory
    define('SMARTY_TEMPLATES_DIR', ConfigHelper::getConfig('directories.smarty_templates_dir', ConfigHelper::getConfig('directories.sys_dir') . '/templates'));
    $SMARTY->setTemplateDir(null);
    $custom_templates_dir = ConfigHelper::getConfig('phpui.custom_templates_dir');
    if (!empty($custom_templates_dir) && file_exists(SMARTY_TEMPLATES_DIR . '/' . $custom_templates_dir) && !is_file(SMARTY_TEMPLATES_DIR . '/' . $custom_templates_dir)) {
        $SMARTY->AddTemplateDir(SMARTY_TEMPLATES_DIR . '/' . $custom_templates_dir);
    }
    $SMARTY->AddTemplateDir(array(SMARTY_TEMPLATES_DIR . '/default', SMARTY_TEMPLATES_DIR));
    $document = new LMSHtmlInvoice($SMARTY);
}
// handle multi-invoices print
if (!empty($_POST['inv'])) {
    $layout['pagetitle'] = trans('Invoices');
    $count = count($_POST['inv']);
    $i = 0;
    foreach (array_keys($_POST['inv']) as $key) {
        $invoice = $LMS->GetInvoiceContent(intval($key));
        $i++;
        if ($invoice['customerid'] != $SESSION->id) {
            continue;
        }
        if ($count == 1) {
            $docnumber = docnumber($invoice['number'], $invoice['template'], $invoice['cdate']);
        }
예제 #3
0
    $test = TRUE;
    printf("WARNING! You are using test mode." . PHP_EOL);
}
$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);