Example #1
0
function GetReceipt($id)
{
    global $CONFIG, $DB;
    if ($receipt = $DB->GetRow('SELECT d.*, u.name AS user, n.template,
					ds.name AS d_name, ds.address AS d_address,
					ds.zip AS d_zip, ds.city AS d_city
				FROM documents d
				LEFT JOIN users u ON (d.userid = u.id)
				LEFT JOIN numberplans n ON (d.numberplanid = n.id)
				LEFT JOIN customers c ON (d.customerid = c.id)
				LEFT JOIN divisions ds ON (ds.id = c.divisionid)
				WHERE d.type = 2 AND d.id = ?', array($id))) {
        $receipt['contents'] = $DB->GetAll('SELECT * FROM receiptcontents WHERE docid = ? ORDER BY itemid', array($id));
        $receipt['total'] = 0;
        foreach ($receipt['contents'] as $row) {
            $receipt['total'] += $row['value'];
        }
        $receipt['number'] = docnumber($receipt['number'], $receipt['template'], $receipt['cdate'], $receipt['extnumber']);
        if ($receipt['total'] < 0) {
            $receipt['type'] = 'out';
            // change values sign
            foreach ($receipt['contents'] as $idx => $row) {
                $receipt['contents'][$idx]['value'] *= -1;
            }
            $receipt['total'] *= -1;
        } else {
            $receipt['type'] = 'in';
        }
        $receipt['totalg'] = round($receipt['total'] * 100 - (int) $receipt['total'] * 100);
        return $receipt;
    }
}
Example #2
0
function smarty_function_number($params, $template)
{
    $result = docnumber($params['number'], $params['template'], $params['time']);
    if (isset($params['assign'])) {
        $template->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
Example #3
0
function smarty_function_number($params, $template)
{
    $result = docnumber(array('number' => $params['number'], 'template' => $params['template'], 'cdate' => $params['time'], 'customerid' => $params['customerid']));
    if (isset($params['assign'])) {
        $template->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
Example #4
0
    function docnumber($id)
    {
        if ($doc = $this->DB->GetRow('SELECT number, cdate, template 
					FROM documents 
					LEFT JOIN numberplans ON (numberplanid = numberplans.id)
					WHERE documents.id = ?', array($id))) {
            return docnumber($doc['number'], $doc['template'], $doc['cdate']);
        } else {
            return NULL;
        }
    }
Example #5
0
function GetCustomerNotes($id)
{
    global $CONFIG, $DB;
    if (!$id) {
        return NULL;
    }
    if ($invoicelist = $DB->GetAll('SELECT docid AS id, cdate, SUM(value) AS value, number, template
			FROM cash
			LEFT JOIN documents ON (docid = documents.id)
			LEFT JOIN numberplans ON (numberplanid = numberplans.id)
			WHERE cash.customerid = ? AND documents.type = ? AND documents.closed = 0
			GROUP BY docid, cdate, number, template
			HAVING SUM(value) > 0
			ORDER BY cdate DESC', array($id, DOC_CNOTE))) {
        foreach ($invoicelist as $idx => $row) {
            $invoicelist[$idx]['number'] = docnumber($row['number'], $row['template'], $row['cdate']);
        }
        return $invoicelist;
    }
}
Example #6
0
	        EXISTS (SELECT 1 FROM customerassignments a
			WHERE a.customergroupid = ' . intval($_GET['groupid']) . '
			AND a.customerid = d.customerid)' : '') . ' AND NOT EXISTS (
	        SELECT 1 FROM customerassignments a
		JOIN excludedgroups e ON (a.customergroupid = e.customergroupid)
		WHERE e.userid = lms_current_user() AND a.customerid = d.customerid)' . ' ORDER BY CEIL(cdate/86400), id', array($_GET['from'], $_GET['to']));
if (!$ids) {
    $SESSION->close();
    die;
}
$DIVISIONS = $DB->GetAllByKey('SELECT * FROM divisions', 'id');
$count = strstr($which, '+') ? sizeof($ids) * 2 : sizeof($ids);
$i = 0;
foreach ($ids as $idx => $invoiceid) {
    $invoice = $LMS->GetInvoiceContent($invoiceid);
    $invoice['t_number'] = docnumber($invoice['number'], $invoice['template'], $invoice['cdate']);
    if ($invoice['divisionid'] && isset($DIVISIONS[$invoice['divisionid']])) {
        $_NAME = $DIVISIONS[$invoice['divisionid']]['name'];
        $_SHORT_NAME = $DIVISIONS[$invoice['divisionid']]['shortname'];
        $_ADDRESS = $DIVISIONS[$invoice['divisionid']]['address'];
        $_ZIP = $DIVISIONS[$invoice['divisionid']]['zip'];
        $_CITY = $DIVISIONS[$invoice['divisionid']]['city'];
    } else {
        $_NAME = $_SHORT_NAME = $_ADDRESS = $_ZIP = $_CITY = '';
    }
    main_fill(177, 12, 0.395);
    main_fill(177, 313, 0.396);
    simple_fill_mip(5, 12, 0.395);
    simple_fill_mip(5, 313, 0.395);
    address_box(390, 600, 0.395);
    $i++;
Example #7
0
function additem(&$content, $item)
{
    for ($i = 0, $x = sizeof($content); $i < $x; $i++) {
        if ($content[$i]['value'] == $item['value'] && $content[$i]['description'] == $item['description'] && $content[$i]['posuid'] > $item['posuid'] - 1) {
            break;
        }
    }
    if ($i == $x) {
        $content[] = $item;
    }
}
$SESSION->restore('receiptcontents', $contents);
$SESSION->restore('receiptcustomer', $customer);
$SESSION->restore('receipt', $receipt);
$SESSION->restore('receiptediterror', $error);
$receipt['titlenumber'] = docnumber($receipt['number'], $receipt['template'], $receipt['cdate'], isset($receipt['extnumber']) ? $receipt['extnumber'] : '');
if ($receipt['type'] == 'in') {
    $layout['pagetitle'] = trans('Cash-in Receipt Edit: $a', $receipt['titlenumber']);
} else {
    $layout['pagetitle'] = trans('Cash-out Receipt Edit: $a', $receipt['titlenumber']);
}
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
    case 'additem':
        $itemdata = r_trim($_POST);
        $itemdata['value'] = round((double) str_replace(',', '.', $itemdata['value']), 2);
        // workaround for PHP 4.3.10 bug
        $itemdata['value'] = str_replace(',', '.', $itemdata['value']);
        $itemdata['posuid'] = (string) getmicrotime();
        if ($itemdata['value'] && $itemdata['description']) {
            additem($contents, $itemdata);
Example #8
0
 public function invoice_body_ft0100()
 {
     $this->invoice_date();
     $this->invoice_title();
     $this->invoice_seller();
     $this->invoice_buyer();
     $this->invoice_data();
     $this->invoice_to_pay();
     $this->invoice_balance();
     $this->invoice_dates();
     $this->invoice_expositor();
     $this->invoice_footnote();
     if ($this->data['customerbalance'] < 0 || ConfigHelper::checkValue(ConfigHelper::getConfig('invoices.always_show_form', true))) {
         /* draw FT-0100 form */
         $this->invoice_simple_form_draw();
         $this->invoice_main_form_draw();
         /* fill FT-0100 form */
         $this->invoice_simple_form_fill();
         $this->invoice_main_form_fill();
     }
     $docnumber = docnumber($this->data['number'], $this->data['template'], $this->data['cdate']);
     $this->backend->SetTitle(trans('Invoice No. $a', $docnumber));
     $this->backend->SetAuthor($this->data['division_name']);
     /* setup your cert & key file */
     $cert = 'file://' . LIB_DIR . '/tcpdf/config/lms.cert';
     $key = 'file://' . LIB_DIR . '/tcpdf/config/lms.key';
     /* setup signature additional information */
     $info = array('Name' => $this->data['division_name'], 'Location' => trans('Invoices'), 'Reason' => trans('Invoice No. $a', $docnumber), 'ContactInfo' => $this->data['division_author']);
     /* set document digital signature & protection */
     if (file_exists($cert) && file_exists($key)) {
         $this->backend->setSignature($cert, $key, 'lms-invoices', '', 1, $info);
         $this->backend->setSignatureAppearance(13, 10, 50, 20);
     }
     if (!$this->data['disable_protection']) {
         $this->backend->SetProtection(array('modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble'), '', 'PASSWORD_CHANGEME', '1');
     }
 }
Example #9
0
 *  $Id$
 */
$cid = $document['customerid'];
$customerinfo = $LMS->GetCustomer($cid);
$assignments = $LMS->GetCustomerAssignments($cid);
$customernodes = $LMS->GetCustomerNodes($cid);
$tariffs = $LMS->GetTariffs();
unset($customernodes['total']);
if ($customernodes) {
    foreach ($customernodes as $idx => $row) {
        $customernodes[$idx]['net'] = $DB->GetRow('SELECT *, inet_ntoa(address) AS ip FROM networks WHERE address = (inet_aton(mask) & ?)', array($row['ipaddr']));
    }
}
if ($customeraccounts = $DB->GetAll('SELECT passwd.*, domains.name AS domain
				FROM passwd LEFT JOIN domains ON (domainid = domains.id)
				WHERE passwd.ownerid = ? ORDER BY login', array($cid))) {
    foreach ($customeraccounts as $idx => $account) {
        $customeraccounts[$idx]['aliases'] = $DB->GetCol('SELECT login FROM aliases a 
			LEFT JOIN aliasassignments aa ON a.id = aa.aliasid WHERE aa.accountid=?', array($account['id']));
        /*// create random password
        		$pass = '';
        		for ($i = 0; $i < 8; $i++)
        		       $pass .= substr('0123456789abcdefghijklmnopqrstuvwxyz', rand(0,36), 1);
        		$customeraccounts[$idx]['password'] = $pass;
        		*/
    }
}
$document['template'] = $DB->GetOne('SELECT template FROM numberplans WHERE id=?', array($document['numberplanid']));
$document['nr'] = docnumber($document['number'], $document['template']);
$SMARTY->assign(array('customernodes' => $customernodes, 'assignments' => $assignments, 'customerinfo' => $customerinfo, 'tariffs' => $tariffs, 'customeraccounts' => $customeraccounts, 'document' => $document, 'engine' => $engine));
$output = $SMARTY->fetch(DOC_DIR . '/templates/' . $engine['name'] . '/' . $engine['template']);
Example #10
0
            if (!empty($note['paytime_default'])) {
                if ($customer['paytime'] != -1) {
                    $note['paytime'] = $customer['paytime'];
                } elseif (($paytime = $DB->GetOne('SELECT inv_paytime FROM divisions
			                WHERE id = ?', array($customer['divisionid']))) !== NULL) {
                    $note['paytime'] = $paytime;
                } else {
                    $note['paytime'] = ConfigHelper::getConfig('notes.paytime');
                }
            }
            $cdate = !empty($note['cdate']) ? $note['cdate'] : time();
            $division = $DB->GetRow('SELECT name, shortname, address, city, zip, countryid, ten, regon,
				account, inv_header, inv_footer, inv_author, inv_cplace 
				FROM divisions WHERE id = ? ;', array($customer['divisionid']));
            if ($note['numberplanid']) {
                $fullnumber = docnumber($note['number'], $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($note['numberplanid'])), $cdate);
            } else {
                $fullnumber = null;
            }
            $args = array('number' => $note['number'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_NUMPLAN] => !empty($note['numberplanid']) ? $note['numberplanid'] : 0, 'type' => DOC_DNOTE, 'cdate' => $cdate, $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER] => $AUTH->id, $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST] => $customer['id'], 'name' => $customer['customername'], 'address' => $customer['address'], 'paytime' => $note['paytime'], 'ten' => $customer['ten'], 'ssn' => $customer['ssn'], 'zip' => $customer['zip'], 'city' => $customer['city'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_COUNTRY] => $customer['countryid'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DIV] => $customer['divisionid'], 'div_name' => $division['name'] ? $division['name'] : '', 'div_shortname' => $division['shortname'] ? $division['shortname'] : '', 'div_address' => $division['address'] ? $division['address'] : '', 'div_city' => $division['city'] ? $division['city'] : '', 'div_zip' => $division['zip'] ? $division['zip'] : '', 'div_' . $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_COUNTRY] => $division['countryid'] ? $division['countryid'] : 0, 'div_ten' => $division['ten'] ? $division['ten'] : '', 'div_regon' => $division['regon'] ? $division['regon'] : '', 'div_account' => $division['account'] ? $division['account'] : '', 'div_inv_header' => $division['inv_header'] ? $division['inv_header'] : '', 'div_inv_footer' => $division['inv_footer'] ? $division['inv_footer'] : '', 'div_inv_author' => $division['inv_author'] ? $division['inv_author'] : '', 'div_inv_cplace' => $division['inv_cplace'] ? $division['inv_cplace'] : '', 'fullnumber' => $fullnumber);
            $DB->Execute('INSERT INTO documents (number, numberplanid, type,
					cdate, userid, customerid, name, address, paytime,
					ten, ssn, zip, city, countryid, divisionid,
					div_name, div_shortname, div_address, div_city, div_zip, div_countryid,
					div_ten, div_regon, div_account, div_inv_header, div_inv_footer, div_inv_author, div_inv_cplace, fullnumber)
					VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
						?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array_values($args));
            $nid = $DB->GetLastInsertID('documents');
            if ($SYSLOG) {
                $args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DOC]] = $nid;
                unset($args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]]);
Example #11
0
                        $numberplans[] = $plan;
}

/*
if($dirs = getdir(DOC_DIR.'/templates', '^[a-z0-9_-]+$'))
	foreach($dirs as $dir)
	{
		$infofile = DOC_DIR.'/templates/'.$dir.'/info.php';
		if(file_exists($infofile))
		{
			unset($engine);
			include($infofile);
			$docengines[$dir] = $engine;
		}
	}

if($docengines) ksort($docengines);
*/

$layout['pagetitle'] = trans('Edit Document: $a', docnumber($document['number'], $document['template'], $document['cdate']));

//$SMARTY->assign('docengines', $docengines);
$SMARTY->assign('numberplans', $numberplans);
$SMARTY->assign('docrights', $rights);
$SMARTY->assign('allnumberplans', $allnumberplans);
$SMARTY->assign('error', $error);
$SMARTY->assign('document', $document);
$SMARTY->display('documentedit.html');

?>
Example #12
0
            }
            $i++;
        }
        if ($ctype != 'pdf' && strtolower(ConfigHelper::getConfig('phpui.document_type')) == 'pdf') {
            $margins = explode(",", ConfigHelper::getConfig('phpui.document_margins', '10,5,15,5'));
            html2pdf($htmlbuffer, trans('Document'), NULL, NULL, NULL, 'P', $margins);
        }
        die;
    }
} elseif ($doc = $DB->GetRow('SELECT c.filename, c.md5sum, c.contenttype, d.id, d.number, d.cdate, d.type, n.template
	FROM documentcontents c
	JOIN documents d ON (d.id = c.docid)
	LEFT JOIN numberplans n ON (d.numberplanid = n.id)
	JOIN docrights r ON (r.doctype = d.type)
	WHERE c.docid = ? AND r.userid = ? AND (r.rights & 1) = 1', array($_GET['id'], $AUTH->id))) {
    $docnumber = docnumber($doc['number'], $doc['template'], $doc['cdate']);
    $filename = DOC_DIR . DIRECTORY_SEPARATOR . substr($doc['md5sum'], 0, 2) . DIRECTORY_SEPARATOR . $doc['md5sum'];
    if (file_exists($filename)) {
        $filename_pdf = DOC_DIR . DIRECTORY_SEPARATOR . substr($doc['md5sum'], 0, 2) . DIRECTORY_SEPARATOR . $doc['md5sum'] . '.pdf';
        if (file_exists($filename_pdf)) {
            header('Content-type: application/pdf');
            header('Content-Disposition: inline; filename="' . $docnumber . '.pdf"');
            header('Content-Transfer-Encoding: binary');
            header('Content-Length: ' . filesize($filename_pdf));
            header('Accept-Ranges: bytes');
            readfile($filename_pdf);
        } elseif ($doc['contenttype'] != 'pdf' && strtolower(ConfigHelper::getConfig('phpui.document_type')) == 'pdf') {
            if ($doc['type'] == DOC_CONTRACT) {
                $subject = trans('Contract');
                $title = trans('Contract No. $a', $docnumber);
            } elseif ($doc['type'] == DOC_ANNEX) {
Example #13
0
                $document['number'] = $LMS->GetNewDocumentNumber(array('doctype' => $document['type'], 'planid' => $document['numberplanid'], 'customerid' => $document['customerid']));
            }
            $fullnumber = docnumber(array('number' => $document['number'], 'template' => $numtemplate, 'cdate' => $time, 'customerid' => $document['customerid']));
            $DB->Execute('INSERT INTO documents (type, number, numberplanid, cdate, customerid, userid, divisionid, name, address, zip, city, ten, ssn, closed,
					div_name, div_shortname, div_address, div_city, div_zip, div_countryid, div_ten, div_regon,
					div_account, div_inv_header, div_inv_footer, div_inv_author, div_inv_cplace, fullnumber)
				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($document['type'], $document['number'], $document['numberplanid'], $time, $document['customerid'], $AUTH->id, $gencust['divisionid'], $gencust['customername'], $gencust['address'] ? $gencust['address'] : '', $gencust['zip'] ? $gencust['zip'] : '', $gencust['city'] ? $gencust['city'] : '', $gencust['ten'] ? $gencust['ten'] : '', $gencust['ssn'] ? $gencust['ssn'] : '', !empty($document['closed']) ? 1 : 0, $division['name'] ? $division['name'] : '', $division['shortname'] ? $division['shortname'] : '', $division['address'] ? $division['address'] : '', $division['city'] ? $division['city'] : '', $division['zip'] ? $division['zip'] : '', $division['countryid'] ? $division['countryid'] : 0, $division['ten'] ? $division['ten'] : '', $division['regon'] ? $division['regon'] : '', $division['account'] ? $division['account'] : '', $division['inv_header'] ? $division['inv_header'] : '', $division['inv_footer'] ? $division['inv_footer'] : '', $division['inv_author'] ? $division['inv_author'] : '', $division['inv_cplace'] ? $division['inv_cplace'] : '', $fullnumber));
            $docid = $DB->GetLastInsertID('documents');
            $DB->Execute('INSERT INTO documentcontents (docid, title, fromdate, todate, description)
				VALUES (?, ?, ?, ?, ?)', array($docid, $document['title'], $document['fromdate'], $document['todate'], $document['description']));
            foreach ($files as $file) {
                $DB->Execute('INSERT INTO documentattachments (docid, filename, contenttype, md5sum, main)
					VALUES (?, ?, ?, ?, ?)', array($docid, $file['name'], $file['type'], $file['md5sum'], $file['main'] ? 1 : 0));
            }
            $DB->CommitTrans();
            $genresult .= docnumber(array('number' => $document['number'], 'template' => $numtemplate, 'cdate' => $time, 'customerid' => $document['customerid'])) . '.<br>';
            if (!$customernumtemplate) {
                $document['number']++;
            }
            if (isset($_GET['print']) && isset($docfile) && $docfile['contenttype'] == 'text/html') {
                print $output;
                print '<DIV style="page-break-after: always;"></DIV>';
                flush();
            }
        }
        if (!isset($_GET['print'])) {
            $SMARTY->display('header.html');
            print $genresult;
            $SMARTY->display('footer.html');
        }
        die;
Example #14
0
            if (!empty($note['paytime_default'])) {
                if ($customer['paytime'] != -1) {
                    $note['paytime'] = $customer['paytime'];
                } elseif (($paytime = $DB->GetOne('SELECT inv_paytime FROM divisions
			                WHERE id = ?', array($customer['divisionid']))) !== NULL) {
                    $note['paytime'] = $paytime;
                } else {
                    $note['paytime'] = ConfigHelper::getConfig('notes.paytime');
                }
            }
            $cdate = !empty($note['cdate']) ? $note['cdate'] : time();
            $division = $DB->GetRow('SELECT name, shortname, address, city, zip, countryid, ten, regon,
				account, inv_header, inv_footer, inv_author, inv_cplace 
				FROM divisions WHERE id = ? ;', array($customer['divisionid']));
            if ($note['numberplanid']) {
                $fullnumber = docnumber(array('number' => $note['number'], 'template' => $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($note['numberplanid'])), 'cdate' => $cdate, 'customerid' => $customer['id']));
            } else {
                $fullnumber = null;
            }
            $args = array('number' => $note['number'], SYSLOG::RES_NUMPLAN => !empty($note['numberplanid']) ? $note['numberplanid'] : 0, 'type' => DOC_DNOTE, 'cdate' => $cdate, SYSLOG::RES_USER => $AUTH->id, SYSLOG::RES_CUST => $customer['id'], 'name' => $customer['customername'], 'address' => $customer['address'], 'paytime' => $note['paytime'], 'ten' => $customer['ten'], 'ssn' => $customer['ssn'], 'zip' => $customer['zip'], 'city' => $customer['city'], SYSLOG::RES_COUNTRY => $customer['countryid'], SYSLOG::RES_DIV => $customer['divisionid'], 'div_name' => $division['name'] ? $division['name'] : '', 'div_shortname' => $division['shortname'] ? $division['shortname'] : '', 'div_address' => $division['address'] ? $division['address'] : '', 'div_city' => $division['city'] ? $division['city'] : '', 'div_zip' => $division['zip'] ? $division['zip'] : '', 'div_' . SYSLOG::getResourceKey(SYSLOG::RES_COUNTRY) => $division['countryid'] ? $division['countryid'] : 0, 'div_ten' => $division['ten'] ? $division['ten'] : '', 'div_regon' => $division['regon'] ? $division['regon'] : '', 'div_account' => $division['account'] ? $division['account'] : '', 'div_inv_header' => $division['inv_header'] ? $division['inv_header'] : '', 'div_inv_footer' => $division['inv_footer'] ? $division['inv_footer'] : '', 'div_inv_author' => $division['inv_author'] ? $division['inv_author'] : '', 'div_inv_cplace' => $division['inv_cplace'] ? $division['inv_cplace'] : '', 'fullnumber' => $fullnumber);
            $DB->Execute('INSERT INTO documents (number, numberplanid, type,
					cdate, userid, customerid, name, address, paytime,
					ten, ssn, zip, city, countryid, divisionid,
					div_name, div_shortname, div_address, div_city, div_zip, div_countryid,
					div_ten, div_regon, div_account, div_inv_header, div_inv_footer, div_inv_author, div_inv_cplace, fullnumber)
					VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
						?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array_values($args));
            $nid = $DB->GetLastInsertID('documents');
            if ($SYSLOG) {
                $args[SYSLOG::RES_DOC] = $nid;
                unset($args[SYSLOG::RES_USER]);
Example #15
0
 *
 *  (C) Copyright 2001-2016 LMS Developers
 *
 *  Please, see the doc/AUTHORS for more information about authors!
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License Version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 *  USA.
 *
 *  $Id$
 */
if ($doc = $DB->GetRow('SELECT number, cdate, template, extnumber, paytime, paytype, customerid
	FROM documents 
	LEFT JOIN numberplans ON (numberplanid = numberplans.id)
	WHERE documents.id = ?', array($_GET['id']))) {
    $doc['ntempl'] = docnumber(array('number' => $doc['number'], 'template' => $doc['template'], 'cdate' => $doc['cdate'], 'ext_num' => $doc['extnumber'], 'customerid' => $doc['customerid']));
    $doc['pdate'] = $doc['cdate'] + $doc['paytime'] * 86400;
    $doc['paytypename'] = $PAYTYPES[$doc['paytype']];
    $SMARTY->assign('invoice', $doc);
    $SMARTY->display('invoice/invoiceinfoshort.html');
}
Example #16
0
            } else {
                $in_number = $receipt['in_number'];
            }
            $in_extnumber = isset($receipt['in_extnumber']) ? $receipt['in_extnumber'] : '';
        }
        $fullnumber = docnumber($in_number, $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($in_plan)), $receipt['cdate']);
        // add cash-in receipt
        $DB->Execute('INSERT INTO documents (type, number, extnumber, numberplanid, cdate, userid, name, closed, fullnumber)
					VALUES(?, ?, ?, ?, ?, ?, ?, 1)', array(DOC_RECEIPT, $in_number, $in_extnumber, $in_plan, $receipt['cdate'], $AUTH->id, $record['name'], $fullnumber ? $fullnumber : NULL));
        $rid = $DB->GetLastInsertId('documents');
        if ($receipt['type'] == 'settle') {
            // add cash-out receipt
            if (!$receipt['out_number']) {
                $receipt['out_number'] = $LMS->GetNewDocumentNumber(DOC_RECEIPT, $record['numberplanid'], $receipt['cdate']);
            }
            $fullnumber = docnumber($in_number, $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($in_plan)), $receipt['cdate']);
            $DB->Execute('INSERT INTO documents (type, number, extnumber, numberplanid, cdate, userid, name, closed, fullnumber)
					VALUES(?, ?, ?, ?, ?, ?, ?, 1,?)', array(DOC_RECEIPT, $receipt['out_number'], isset($receipt['out_extnumber']) ? $receipt['out_extnumber'] : '', $record['numberplanid'], $receipt['cdate'], $AUTH->id, $receipt['name'], $fullnumber ? $fullnumber : NULL));
            $rid2 = $DB->GetLastInsertId('documents');
        }
        $DB->UnLockTables();
        $DB->Execute('INSERT INTO receiptcontents (docid, itemid, value, description, regid)
					VALUES(?, 1, ?, ?, ?)', array($rid, str_replace(',', '.', $record['value'] * -1), trans('Advance return') . ' - ' . $titlenumber, $regid));
        $DB->Execute('INSERT INTO cash (time, type, docid, itemid, value, comment, userid)
					VALUES(?, 1, ?, 1, ?, ?, ?)', array($receipt['cdate'], $rid, str_replace(',', '.', $record['value'] * -1), trans('Advance return') . ' - ' . $titlenumber, $AUTH->id));
        if ($receipt['type'] == 'settle') {
            $DB->Execute('INSERT INTO receiptcontents (docid, itemid, value, description, regid)
					VALUES(?, 1, ?, ?, ?)', array($rid2, str_replace(',', '.', $value * -1), $receipt['description'], $regid));
            $DB->Execute('INSERT INTO cash (time, type, docid, itemid, value, comment, userid)
					VALUES(?, 1, ?, 1, ?, ?, ?)', array($receipt['cdate'], $rid, str_replace(',', '.', $value * -1), $receipt['description'], $AUTH->id));
        }
Example #17
0
            if (file_exists($newfile)) {
                @unlink($newfile);
            }
            if (!@rename($file, $newfile)) {
                $error['file'] = trans('Can\'t save file in "$a" directory!', $path);
            }
        }
    }
    if (!$error) {
        $customer = $LMS->GetCustomer($document['customerid']);
        $time = time();
        $DB->BeginTrans();
        $division = $DB->GetRow('SELECT name, shortname, address, city, zip, countryid, ten, regon,
				account, inv_header, inv_footer, inv_author, inv_cplace 
				FROM divisions WHERE id = ? ;', array($customer['divisionid']));
        $fullnumber = docnumber($document['number'], $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($document['numberplanid'])), $time);
        $DB->Execute('INSERT INTO documents (type, number, numberplanid, cdate, 
			customerid, userid, name, address, zip, city, ten, ssn, divisionid, 
			div_name, div_shortname, div_address, div_city, div_zip, div_countryid, div_ten, div_regon,
			div_account, div_inv_header, div_inv_footer, div_inv_author, div_inv_cplace,closed, fullnumber)
			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($document['type'], $document['number'], $document['numberplanid'], $time, $document['customerid'], $AUTH->id, trim($customer['lastname'] . ' ' . $customer['name']), $customer['address'] ? $customer['address'] : '', $customer['zip'] ? $customer['zip'] : '', $customer['city'] ? $customer['city'] : '', $customer['ten'] ? $customer['ten'] : '', $customer['ssn'] ? $customer['ssn'] : '', $customer['divisionid'], $division['name'] ? $division['name'] : '', $division['shortname'] ? $division['shortname'] : '', $division['address'] ? $division['address'] : '', $division['city'] ? $division['city'] : '', $division['zip'] ? $division['zip'] : '', $division['countryid'] ? $division['countryid'] : 0, $division['ten'] ? $division['ten'] : '', $division['regon'] ? $division['regon'] : '', $division['account'] ? $division['account'] : '', $division['inv_header'] ? $division['inv_header'] : '', $division['inv_footer'] ? $division['inv_footer'] : '', $division['inv_author'] ? $division['inv_author'] : '', $division['inv_cplace'] ? $division['inv_cplace'] : '', isset($document['closed']) ? 1 : 0, $fullnumber ? $fullnumber : NULL));
        $docid = $DB->GetLastInsertID('documents');
        if (SYSLOG) {
            addlogs('dodano nowy dokument ' . $DOCTYPES[$document['type']], 'e=add;m=doc;c=' . $document['customerid']);
        }
        $DB->Execute('INSERT INTO documentcontents (docid, title, fromdate, todate, filename, contenttype, md5sum, description)
			VALUES (?, ?, ?, ?, ?, ?, ?, ?)', array($docid, $document['title'], $document['fromdate'], $document['todate'], $document['filename'], $document['contenttype'], $document['md5sum'], $document['description']));
        // template post-action
        if (!empty($engine['post-action']) && file_exists(DOC_DIR . '/templates/' . $engine['name'] . '/' . $engine['post-action'] . '.php')) {
            include DOC_DIR . '/templates/' . $engine['name'] . '/' . $engine['post-action'] . '.php';
        }
Example #18
0
$ch = curl_init();
if (!$ch) {
    die("Fatal error: Can't init curl library!\n");
}
$query = "SELECT d.id, d.number, d.cdate, c.email, d.name, d.customerid, n.template \n\t\tFROM documents d \n\t\tLEFT JOIN customers c ON c.id = d.customerid \n\t\tLEFT JOIN numberplans n ON n.id = d.numberplanid \n\t\tWHERE c.deleted = 0 AND d.type IN (1,3) AND c.email <> '' 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);
if (!empty($docs)) {
    foreach ($docs as $doc) {
        curl_setopt_array($ch, array(CURLOPT_URL => $lms_url . '/?m=invoice&override=1&original=1&id=' . $doc['id'] . '&loginform[login]=' . $lms_user . '&loginform[pwd]=' . $lms_password, CURLOPT_HTTPGET => TRUE, CURLOPT_POST => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_COOKIEJAR => COOKIE_FILE, CURLOPT_COOKIEFILE => COOKIE_FILE, CURLOPT_SSLVERSION => 3, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_USERAGENT => USER_AGENT));
        $res = curl_exec($ch);
        if (!empty($res)) {
            $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);
            if (!$quiet || $test) {
                printf("Invoice No. {$invoice_number} for " . $doc['name'] . " <{$custemail}>\n");
            }
            if (!$test) {
                $headers = array('From' => $from, 'To' => qp_encode($doc['name']) . ' <' . $custemail . '>', 'Subject' => $subject);
                if (!empty($notify_email)) {
Example #19
0
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 *  USA.
 *
 */
require_once LIB_DIR . DIRECTORY_SEPARATOR . 'common.php';
$numberplans = $this->GetAllByKey("SELECT * FROM numberplans ORDER BY id", 'id');
$this->BeginTrans();
$this->Execute("ALTER TABLE documents ADD fullnumber varchar(50) DEFAULT NULL");
$this->Execute("CREATE INDEX documents_fullnumber_idx ON documents (fullnumber)");
$this->LockTables("documents");
$offset = 0;
do {
    $docs = $this->GetAll("SELECT id, cdate, number, numberplanid FROM documents\n\t\tORDER BY id LIMIT 30000 OFFSET {$offset}");
    $stop = empty($docs);
    if (!$stop) {
        foreach ($docs as $doc) {
            if ($doc['numberplanid']) {
                $template = $numberplans[$doc['numberplanid']]['template'];
            } else {
                $template = DEFAULT_NUMBER_TEMPLATE;
            }
            $fullnumber = docnumber($doc['number'], $template, $doc['cdate']);
            $this->Execute("UPDATE documents SET fullnumber = ? WHERE id = ?", array($fullnumber, $doc['id']));
        }
        $offset += count($docs);
        unset($docs);
    }
} while (!$stop);
$this->UnLockTables("documents");
$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2014072500', 'dbversion'));
$this->CommitTrans();
Example #20
0
File: note.php Project: rzt/lms
	$i=0;

	$SMARTY->display('noteheader.html');

	foreach($ids as $idx => $noteid)
	{
		$note = $LMS->GetNoteContent($noteid);

		$SMARTY->assign('note',$note);
		$SMARTY->display($CONFIG['notes']['template_file']);
	}
	$SMARTY->display('clearfooter.html');
}
elseif($note = $LMS->GetNoteContent($_GET['id']))
{
	$number = docnumber($note['number'], $note['template'], $note['cdate']);
	$layout['pagetitle'] = trans('Debit Note No. $a', $number);

	$SMARTY->display('noteheader.html');

	$note['last'] = TRUE;
	$SMARTY->assign('note',$note);
	$SMARTY->display($CONFIG['notes']['template_file']);
	$SMARTY->display('clearfooter.html');
}
else
{
	$SESSION->redirect('?m=notelist');
}

?>
Example #21
0
                }
            } else {
                $error = trans('Problem during file generation!');
            }
            if ($error) {
                $genresult .= '<font class="alert">' . $error . '</font><br>';
                continue;
            }
            $DB->BeginTrans();
            $DB->Execute('INSERT INTO documents (type, number, numberplanid, cdate, customerid, userid, divisionid, name, address, zip, city, ten, ssn, closed)
				VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($document['type'], $document['number'], $document['numberplanid'], $time, $document['customerid'], $AUTH->id, $gencust['divisionid'], $gencust['customername'], $gencust['address'] ? $gencust['address'] : '', $gencust['zip'] ? $gencust['zip'] : '', $gencust['city'] ? $gencust['city'] : '', $gencust['ten'] ? $gencust['ten'] : '', $gencust['ssn'] ? $gencust['ssn'] : '', !empty($document['closed']) ? 1 : 0));
            $docid = $DB->GetLastInsertID('documents');
            $DB->Execute('INSERT INTO documentcontents (docid, title, fromdate, todate, filename, contenttype, md5sum, description)
				VALUES (?, ?, ?, ?, ?, ?, ?, ?)', array($docid, $document['title'], $document['fromdate'], $document['todate'], $document['filename'], $document['contenttype'], $document['md5sum'], $document['description']));
            $DB->CommitTrans();
            $genresult .= docnumber($document['number'], $numtemplate, $time) . '.<br>';
            $document['number']++;
            if (isset($_GET['print']) && $document['contenttype'] == 'text/html') {
                print $output;
                print '<DIV style="page-break-after: always;"></DIV>';
                flush();
            }
        }
        if (!isset($_GET['print'])) {
            $SMARTY->display('header.html');
            print $genresult;
            $SMARTY->display('footer.html');
        }
        die;
    } else {
        $document['fromdate'] = $oldfromdate;
Example #22
0
function invoice_body_ft0100()
{
    global $pdf, $invoice;
    invoice_date();
    invoice_title();
    invoice_seller();
    invoice_buyer();
    invoice_data();
    invoice_to_pay();
    invoice_balance();
    invoice_dates();
    invoice_expositor();
    invoice_footnote();
    /* draw FT-0100 form */
    invoice_simple_form_draw();
    invoice_main_form_draw();
    /* fill FT-0100 form */
    invoice_simple_form_fill();
    invoice_main_form_fill();
    if (!$invoice['fullnumber']) {
        $docnumber = docnumber($invoice['number'], $invoice['template'], $invoice['cdate']);
    } else {
        $docnumber = $invoice['fullnumber'];
    }
    if ($invoice['type'] == DOC_INVOICE_PRO) {
        $pdf->SetTitle('Faktura Pro Forma Nr. ' . $docnumber);
    } else {
        $pdf->SetTitle(trans('Invoice No. $a', $docnumber));
    }
    $pdf->SetAuthor($invoice['division_name']);
    /* setup your cert & key file */
    $cert = 'file://' . LIB_DIR . '/tcpdf/config/lms.cert';
    $key = 'file://' . LIB_DIR . '/tcpdf/config/lms.key';
    /* setup signature additional information */
    if ($invoice['type'] == DOC_INVOICE_PRO) {
        $info = array('Name' => $invoice['division_name'], 'Location' => trans('Invoices'), 'Reason' => 'Faktura Pro Forma Nr. ' . $docnumber, 'ContactInfo' => $invoice['division_author']);
    } else {
        $info = array('Name' => $invoice['division_name'], 'Location' => trans('Invoices'), 'Reason' => trans('Invoice No. $a', $docnumber), 'ContactInfo' => $invoice['division_author']);
    }
    if (get_conf('invoices.set_protection', '1')) {
        /* set document digital signature & protection */
        if (file_exists($cert) && file_exists($key)) {
            $pdf->setSignature($cert, $key, 'inetlms-invoices', '', 1, $info);
            $pdf->setSignatureAppearance(13, 10, 50, 20);
        }
        $pdf->SetProtection(array('modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble'), '', 'PASSWORD_CHANGEME', '1');
    }
}
Example #23
0
function invoice_title($x, $y)
{
    global $invoice, $pdf, $type;
    $font_size = 16;
    /* *** */
    if (!$invoice['fullnumber']) {
        $tmp = docnumber($invoice['number'], $invoice['template'], $invoice['cdate']);
    } else {
        $tmp = $invoice['fullnumber'];
    }
    if (isset($invoice['invoice'])) {
        $y = $y - text_align_left($x, $y, $font_size, '<b>' . iconv("UTF-8", "ISO-8859-2//TRANSLIT", trans('Credit Note No. $a', $tmp)) . '</b>');
    } else {
        $y = $y - text_align_left($x, $y, $font_size, '<b>' . iconv("UTF-8", "ISO-8859-2//TRANSLIT", trans('Invoice No. $a', $tmp)) . '</b>');
    }
    if (isset($invoice['invoice'])) {
        $font_size = 12;
        $y += 8;
        if (!$invoice['invoice']['fullnumber']) {
            $tmp = docnumber($invoice['invoice']['number'], $invoice['invoice']['template'], $invoice['invoice']['cdate']);
        } else {
            $tmp = $invoice['invoice']['fullnumber'];
        }
        $y = $y - text_align_left($x, $y, $font_size, '<b>' . iconv("UTF-8", "ISO-8859-2//TRANSLIT", trans('for Invoice No. $a', $tmp)) . '</b>');
        $y -= 5;
    }
    $font_size = 16;
    $y = $y - text_align_left($x, $y, $font_size, iconv("UTF-8", "ISO-8859-2//TRANSLIT", $type));
    if ($type == trans('DUPLICATE')) {
        $font_size = 12;
        $y = $y - text_align_left($x, $y + 4, $font_size, iconv("UTF-8", "ISO-8859-2//TRANSLIT", trans('Duplicate draw-up date:') . ' ' . date('Y/m/d')));
    }
    if (isset($invoice['invoice'])) {
        $y += 10;
    }
    return $y;
}
Example #24
0
                    $args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CASH]] = $DB->GetLastInsertID('cash');
                    unset($args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]]);
                    $SYSLOG->AddMessage(SYSLOG_RES_CASH, SYSLOG_OPER_ADD, $args, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CASH], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DOC]));
                }
            }
            $DB->CommitTrans();
        } elseif ($contents && ($receipt['o_type'] == 'other' || $receipt['o_type'] == 'advance')) {
            $DB->BeginTrans();
            $DB->LockTables('documents');
            // delete old receipt
            $DB->Execute('DELETE FROM documents WHERE id = ?', array($receipt['id']));
            if ($SYSLOG) {
                $args = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DOC] => $receipt['id']);
                $SYSLOG->AddMessage(SYSLOG_RES_DOC, SYSLOG_OPER_DELETE, $args, array_keys($args));
            }
            $fullnumber = docnumber($receipt['number'], $DB->GetOne('SELECT template FROM numberplans WHERE id = ?', array($receipt['numberplanid'])), $receipt['cdate']);
            $args = array('type' => DOC_RECEIPT, 'number' => $receipt['number'], 'extnumber' => $receipt['extnumber'] ? $receipt['extnumber'] : '', $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_NUMPLAN] => $receipt['numberplanid'], 'cdate' => $receipt['cdate'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER] => $AUTH->id, 'name' => $receipt['o_type'] == 'advance' ? $receipt['adv_name'] : $receipt['other_name'], 'closed' => $receipt['closed'], 'fullnumber' => $fullnumber);
            $DB->Execute('INSERT INTO documents (type, number, extnumber, numberplanid, cdate, userid, name, closed,
					fullnumber)
					VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)', array_values($args));
            $DB->UnLockTables();
            $rid = $DB->GetLastInsertId('documents');
            if ($SYSLOG) {
                $args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DOC]] = $rid;
                unset($args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]]);
                $SYSLOG->AddMessage(SYSLOG_RES_DOC, SYSLOG_OPER_ADD, $args, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_DOC], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_NUMPLAN]));
            }
            // delete old receipt content and assignments
            if ($SYSLOG) {
                $items = $DB->GetAll('SELECT itemid, regid FROM receiptcontents WHERE docid = ?', array($receipt['id']));
                foreach ($items as $item) {
Example #25
0
 protected function invoice_title($x, $y)
 {
     $font_size = 16;
     $tmp = docnumber(array('number' => $this->data['number'], 'template' => $this->data['template'], 'cdate' => $this->data['cdate'], 'customerid' => $this->data['customerid']));
     if (isset($this->data['invoice'])) {
         $y = $y - $this->backend->text_align_left($x, $y, $font_size, '<b>' . trans('Credit Note No. $a', $tmp) . '</b>');
     } elseif ($this->data['doctype'] == DOC_INVOICE_PRO) {
         $y = $y - $this->backend->text_align_left($x, $y, $font_size, '<b>' . trans('Pro Forma Invoice No. $a', $tmp) . '</b>');
     } else {
         $y = $y - $this->backend->text_align_left($x, $y, $font_size, '<b>' . trans('Invoice No. $a', $tmp) . '</b>');
     }
     if (isset($this->data['invoice'])) {
         $font_size = 12;
         $y += 8;
         $tmp = docnumber(array('number' => $this->data['invoice']['number'], 'template' => $this->data['invoice']['template'], 'cdate' => $this->data['invoice']['cdate'], 'customerid' => $this->data['customerid']));
         $y = $y - $this->backend->text_align_left($x, $y, $font_size, '<b>' . trans('for Invoice No. $a', $tmp) . '</b>');
         $y -= 5;
     }
     //$font_size = 16;
     //$y = $y - $this->backend->text_align_left($x, $y, $font_size, $this->data['type']);
     if ($this->data['type'] == trans('DUPLICATE')) {
         $font_size = 12;
         $y = $y - $this->backend->text_align_left($x, $y + 4, $font_size, trans('Duplicate draw-up date:') . ' ' . date('Y/m/d'));
     }
     if (isset($this->data['invoice'])) {
         $y += 10;
     }
     return $y;
 }
Example #26
0
function GetReceiptList($registry, $order='', $search=NULL, $cat=NULL, $from=0, $to=0, $advances=0)
{
	global $CONFIG, $DB;

	list($order,$direction) = sscanf($order, '%[^,],%s');

	($direction != 'desc') ? $direction = 'asc' : $direction = 'desc';

	switch($order)
	{
		case 'number':
			$sqlord = " ORDER BY documents.number $direction";
		break;
		case 'name':
			$sqlord = " ORDER BY documents.name $direction, documents.cdate";
		break;
		case 'user':
			$sqlord = " ORDER BY users.name $direction, documents.cdate";
		break;
		case 'cdate':
		default:
			$sqlord = " ORDER BY documents.cdate $direction, number";
		break;
	}

	$where = ''; $having = '';

	if($search && $cat)
	{
		switch($cat)
		{
			case 'value':
				$having = ' HAVING SUM(value) = '.$DB->Escape(str_replace(',','.',$search));
				break;
			case 'number':
				$where = ' AND number = '.intval($search);
				break;
			case 'ten':
				$where = ' AND ten = '.$DB->Escape($search);
				break;
			case 'customerid':
				$where = ' AND customerid = '.intval($search);
				break;
			case 'name':
				$where = ' AND documents.name ?LIKE? '.$DB->Escape('%'.$search.'%');
				break;
			case 'address':
				$where = ' AND address ?LIKE? '.$DB->Escape('%'.$search.'%');
				break;
		}
	}

	if($from)
		$where .= ' AND cdate >= '.intval($from);
	if($to)
		$where .= ' AND cdate <= '.intval($to);

	if($advances)
		$where = ' AND closed = 0';

	if($list = $DB->GetAll(
	        'SELECT documents.id AS id, SUM(value) AS value, number, cdate, customerid, 
		documents.name AS customer, address, zip, city, template, extnumber, closed,
		MIN(description) AS title, COUNT(*) AS posnumber, users.name AS user 
		FROM documents 
		LEFT JOIN numberplans ON (numberplanid = numberplans.id)
		LEFT JOIN users ON (userid = users.id)
		LEFT JOIN receiptcontents ON (documents.id = docid AND type = ?) 
		WHERE regid = ?'
		.$where
		.' GROUP BY documents.id, number, cdate, customerid, documents.name, address, zip, city, template, users.name, extnumber, closed '
		.$having
		.($sqlord != '' ? $sqlord : ''), 
		array(DOC_RECEIPT, $registry)
		))
	{
		$totalincome = 0;
		$totalexpense = 0;

		foreach($list as $idx => $row)
		{
			$list[$idx]['number'] = docnumber($row['number'], $row['template'], $row['cdate'], $row['extnumber']);
			$list[$idx]['customer'] = $row['customer'].' '.$row['address'].' '.$row['zip'].' '.$row['city'];

			// don't retrive descriptions of all items to not decrease speed
			// but we want to know that there is something hidden ;)
			if($row['posnumber'] > 1) $list[$idx]['title'] .= ' ...';

			// summary
			if($row['value'] > 0)
				$totalincome += $row['value'];
			else
				$totalexpense += -$row['value'];
		}

		$list['totalincome'] = $totalincome;
		$list['totalexpense'] = $totalexpense;
		$list['order'] = $order;
		$list['direction'] = $direction;

		return $list;
	}
}
Example #27
0
                    foreach ($recipient_phones as $phone) {
                        send_sms($msgid, $row['id'], $phone, $message);
                    }
                }
            }
        }
    }
}
// Debit notes created at current day
if (empty($types) || in_array('notes', $types)) {
    $documents = $DB->GetAll("SELECT d.id AS docid, c.id, c.pin, d.name,\n\t\td.number, n.template, d.cdate, m.email, x.phone, divisions.account,\n\t\tCOALESCE(ca.balance, 0) AS balance, v.value\n\t\tFROM documents d\n\t\tJOIN customers c ON (c.id = d.customerid)\n\t\tLEFT JOIN divisions ON divisions.id = c.divisionid\n\t\tLEFT JOIN (SELECT " . $DB->GroupConcat('contact') . " AS email, customerid\n\t\t\tFROM customercontacts\n\t\t\tWHERE (type & ?) = ?\n\t\t\tGROUP BY customerid\n\t\t) m ON (m.customerid = c.id)\n\t\tLEFT JOIN (SELECT " . $DB->GroupConcat('contact') . " AS phone, customerid\n\t\t\tFROM customercontacts\n\t\t\tWHERE (type & ?) = ? \n\t\t\tGROUP BY customerid\n\t\t) x ON (x.customerid = c.id)\n\t\tJOIN (SELECT SUM(value) * -1 AS value, docid\n\t\t\tFROM cash\n\t\t\tGROUP BY docid\n\t\t) v ON (v.docid = d.id)\n\t\tLEFT JOIN numberplans n ON (d.numberplanid = n.id)\n\t\tLEFT JOIN (SELECT SUM(value) AS balance, customerid\n\t\t\tFROM cash\n\t\t\tGROUP BY customerid\n\t\t) ca ON (ca.customerid = d.customerid)\n\t\tWHERE (c.invoicenotice IS NULL OR c.invoicenotice = 0) AND d.type = ?\n\t\t\tAND d.cdate >= ? AND d.cdate <= ?", array(CONTACT_EMAIL | CONTACT_DISABLED, CONTACT_EMAIL, CONTACT_MOBILE | CONTACT_DISABLED, CONTACT_MOBILE, DOC_DNOTE, $daystart, $dayend));
    if (!empty($documents)) {
        $notifications['notes']['customers'] = array();
        foreach ($documents as $row) {
            $notifications['notes']['customers'][] = $row['id'];
            $row['doc_number'] = docnumber($row['number'], $row['template'] ? $row['template'] : '%N/LMS/%Y', $row['cdate']);
            $message = parse_customer_data($notifications['notes']['message'], $row);
            $subject = parse_customer_data($notifications['notes']['subject'], $row);
            $recipient_mails = $debug_email ? explode(',', $debug_email) : (!empty($row['email']) ? explode(',', trim($row['email'])) : null);
            $recipient_phones = $debug_phone ? explode(',', $debug_phone) : (!empty($row['phone']) ? explode(',', trim($row['phone'])) : null);
            if (!$quiet) {
                if (in_array('mail', $channels) && !empty($recipient_mails)) {
                    foreach ($recipient_mails as $recipient_mail) {
                        printf("[mail/notes] %s (%04d) %s: %s" . PHP_EOL, $row['name'], $row['id'], $row['doc_number'], $recipient_mail);
                    }
                }
                if (in_array('sms', $channels) && !empty($recipient_phones)) {
                    foreach ($recipient_phones as $phone) {
                        printf("[sms/notes] %s (%04d) %s: %s" . PHP_EOL, $row['name'], $row['id'], $row['doc_number'], $recipient_phone);
                    }
                }
Example #28
0
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 *  USA.
 *
 */
require_once LIB_DIR . DIRECTORY_SEPARATOR . 'common.php';
$numberplans = $this->GetAllByKey("SELECT * FROM numberplans ORDER BY id", 'id');
$this->BeginTrans();
$this->Execute("ALTER TABLE documents ADD fullnumber varchar(50) DEFAULT NULL");
$this->Execute("ALTER TABLE documents ADD INDEX fullnumber (fullnumber)");
$this->LockTables("documents");
$offset = 0;
do {
    $docs = $this->GetAll("SELECT id, cdate, number, numberplanid FROM documents\n\t\tWHERE fullnumber IS NULL\n\t\tORDER BY id LIMIT 100000 OFFSET {$offset}");
    $stop = empty($docs);
    if (!$stop) {
        foreach ($docs as $doc) {
            if ($doc['numberplanid']) {
                $template = $numberplans[$doc['numberplanid']]['template'];
            } else {
                $template = DEFAULT_NUMBER_TEMPLATE;
            }
            $fullnumber = docnumber(array('number' => $doc['number'], 'template' => $template, 'cdate' => $doc['cdate']));
            $this->Execute("UPDATE documents SET fullnumber = ? WHERE id = ?", array($fullnumber, $doc['id']));
        }
        $offset += count($docs);
        unset($docs);
    }
} while (!$stop);
$this->UnLockTables("documents");
$this->Execute("UPDATE dbinfo SET keyvalue = ? WHERE keytype = ?", array('2014072500', 'dbversion'));
$this->CommitTrans();
Example #29
0
     $line = str_replace('%VATP' . $x, '0.00', $line);
     $line = str_replace('%VAT' . $x, '0.00', $line);
     $line = str_replace('%NETTO' . $x, '0.00', $line);
     $line = str_replace('%TAXED' . $x, '0.00', $line);
 }
 $line = str_replace('%VAT', form_num($tax_v), $line);
 $line = str_replace('%NETTO', form_num($netto_v), $line);
 if (strpos($line, '%PREFIX') !== FALSE || strpos($line, '%SUFFIX') !== FALSE) {
     $tmp = explode('%N', $doc['template']);
     if ($tmp[0]) {
         $line = str_replace('%PREFIX', docnumber(array('number' => $doc['number'], 'template' => $tmp[0], 'cdate' => $doc['cdate'], 'ext_num' => $doc['extnumber'], 'customerid' => $doc['customerid'])), $line);
     } else {
         $line = str_replace('%PREFIX', '', $line);
     }
     if ($tmp[1]) {
         $line = str_replace('%SUFFIX', docnumber(array('number' => $doc['number'], 'template' => $tmp[1], 'cdate' => $doc['cdate'], 'ext_num' => $doc['extnumber'], 'customerid' => $doc['customerid'])), $line);
     } else {
         $line = str_replace('%SUFFIX', '', $line);
     }
 }
 if (strpos($line, '%TYPE') !== FALSE) {
     if ($doc['reference']) {
         $type = $cnote_type;
     } else {
         $type = $invoice_type;
     }
     $line = str_replace('%TYPE', $type, $line);
 }
 if (strtoupper($encoding) != 'UTF-8') {
     if (strtoupper($encoding) == 'MAZOVIA') {
         // iconv don't support Mazovia standard, but some
Example #30
0
 public function Draw($note)
 {
     $this->data = $note;
     $this->note_date();
     $this->note_title();
     $this->note_drawer();
     $this->note_recipient();
     $this->note_data();
     $this->invoice_to_pay();
     $this->invoice_footnote();
     $docnumber = docnumber($this->data['number'], $this->data['template'], $this->data['cdate']);
     $this->backend->SetTitle(trans('Debit Note No. $a', $docnumber));
     $this->backend->SetAuthor($this->data['division_name']);
     $this->backend->setBarcode($docnumber);
     /* setup your cert & key file */
     $cert = 'file://' . LIB_DIR . '/tcpdf/config/lms.cert';
     $key = 'file://' . LIB_DIR . '/tcpdf/config/lms.key';
     /* setup signature additional information */
     $info = array('Name' => $this->data['division_name'], 'Location' => trans('Debit Notes'), 'Reason' => trans('Debit Note No. $a', $docnumber), 'ContactInfo' => $this->data['division_author']);
     /* set document digital signature & protection */
     if (file_exists($cert) && file_exists($key)) {
         $this->backend->setSignature($cert, $key, 'lms-debitnote', '', 1, $info);
         $this->backend->setSignatureAppearance(13, 10, 50, 20);
     }
     $this->backend->SetProtection(array('modify', 'annot-forms', 'fill-forms', 'extract', 'assemble'), '', 'PASSWORD_CHANGEME', '1');
 }