Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 3.5.0.0
- * @ Author : DeZender
- * @ Release on : 22.06.2018
- * @ Official site : http://DeZender.Net
- *
- */
- if (!defined('WHMCS')) {
- exit('This file cannot be accessed directly');
- }
- class INVOICESME
- {
- private static $instance = null;
- private $lang = array();
- private $paymtethods = array();
- private $currences = array();
- private $generated = array();
- private $errors = array();
- private $ruleLogs = array();
- private $rules = array();
- private $gateways = array();
- protected $InvoiceTypes = array();
- protected $invoiceItems = array();
- protected $transactions = array();
- protected $db = null;
- protected $cid = 0;
- protected $debug = 0;
- public function __construct()
- {
- if (!class_exists('DB_INVOICES')) {
- require_once INVOICEPATH . '/classes/db.php';
- }
- $this->db = DB_INVOICES::getInstance();
- $api = INVOICEAPI::getInstance();
- $this->cid = $api->getProfileID();
- $this->debug = $_REQUEST['debug'];
- }
- public static function getInstance()
- {
- if (!self::$instance) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function setCompanyID($id)
- {
- $this->cid = (int) $id;
- $api = INVOICEAPI::getInstance();
- $api->setProfileID($this->cid);
- }
- public function getGeneratedID($id)
- {
- return (isset($this->generated[$id]) ? (int) $this->generated[$id] : (int) $this->db->getValue('SELECT id FROM mod_invoiceme_generated WHERE invoiceid=' . (int) $id . ' AND companyid=' . $this->cid));
- }
- public function updateSequenceNum($inv, $type = 'add')
- {
- $id = (isset($inv['invtype']) ? $inv['invtype'] : $inv['id']);
- if (!isset($inv['getseqnum'])) {
- $inv = $this->getInvoiceType(array('id' => $id), false);
- }
- $invoiceTypeID = (0 < (int) $inv['getseqnum'] ? $inv['getseqnum'] : $id);
- if (!$invoiceTypeID) {
- return false;
- }
- if ($type == 'add') {
- $update = array('companyid' => $this->cid, 'invoiceseqnum' => $inv['invoiceseqnum'] + 1);
- } else {
- $update = array('companyid' => $this->cid, 'invoiceseqnum' => (0 < $inv['invoiceseqnum'] - 1 ? $inv['invoiceseqnum'] - 1 : 1));
- }
- if (!$this->db->update('mod_invoiceme_types', $update, array('id' => $invoiceTypeID))) {
- $this->errors[] = 'Sequence Number is not updated! (Type:' . $type . ')';
- return false;
- }
- $this->InvoiceTypes[$invoiceTypeID] = $update['invoiceseqnum'];
- return true;
- }
- public function deleteInvoice($id)
- {
- if (!$id) {
- return false;
- }
- $inv = $this->db->getRow('SELECT g.*,t.* FROM mod_invoiceme_generated as g LEFT JOIN mod_invoiceme_types as t ON t.id=g.invtype WHERE g.companyid=' . $this->cid . ' AND g.invoiceid=' . (int) $id);
- if (count($inv) && $this->db->query('DELETE FROM mod_invoiceme_generated WHERE companyid=' . $this->cid . ' AND invoiceid=' . (int) $id)) {
- $this->db->query("UPDATE `tblinvoices` SET `invoicenum`='' WHERE id=" . (int) $id);
- if (file_exists($inv['pdfpath'] . $inv['pdfname'])) {
- unlink($inv['pdfpath'] . $inv['pdfname']);
- }
- return $this->updateSequenceNum($inv, 'remove');
- }
- return false;
- }
- public function getEUcountries()
- {
- $eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK', 'HR');
- return $eu_countries;
- }
- public function getCurrency($value, $key = 'id')
- {
- if (!$value) {
- return array();
- }
- if (isset($this->currences[$key][$value]) && is_array($this->currences[$key][$value])) {
- return $this->currences[$key][$value];
- }
- $q = 'SELECT * FROM `tblcurrencies` WHERE ' . $this->db->quoteField($key) . '=' . $this->db->quoteValue($value);
- $this->currences[$key][$value] = (array) $this->db->getRow($q);
- return $this->currences[$key][$value];
- }
- public function getInvoice($id, $filter = false)
- {
- if (!(int) $id) {
- return array();
- }
- $extraField = (version_compare(WHMCSV, '7.7.0', 'ge') ? ',c.tax_id' : '');
- $q = 'SELECT i.*,c.email,c.billingcid,c.firstname,c.lastname,c.companyname,c.country,c.taxexempt,c.address1,c.address2,c.city,c.state,c.postcode,c.language' . $extraField . ' FROM tblinvoices as i LEFT JOIN tblclients as c ON i.userid=c.id WHERE i.subtotal>0 AND i.id=' . (int) $id;
- if ($filter) {
- $q .= ' AND i.id NOT IN (SELECT w.invoiceid FROM mod_invoiceme_generated as w WHERE w.companyid=' . $this->cid . ') ';
- }
- return (array) $this->db->getRow($q);
- }
- public function getGenerated($id, $key = 'id')
- {
- $q = 'SELECT t.*,i.*,g.*,c.email,c.billingcid,c.firstname,c.lastname,c.companyname,c.country,c.taxexempt,c.address1,c.address2,c.city,c.state,c.postcode,c.language FROM mod_invoiceme_generated as g LEFT JOIN tblinvoices as i ON g.invoiceid=i.id LEFT JOIN tblclients as c ON i.userid=c.id LEFT JOIN mod_invoiceme_types as t ON t.id=g.invtype WHERE g.' . $this->db->quoteField($key) . '=' . $this->db->quoteValue($id);
- $data = $this->db->getRow($q);
- return $data;
- }
- public function getInvoiceType($where = array(), $cache = true)
- {
- if (!count($where)) {
- return array();
- }
- if ($cache && isset($where['id']) && isset($this->InvoiceTypes[$where['id']]) && count($this->InvoiceTypes[$where['id']])) {
- return $this->InvoiceTypes[$where['id']];
- }
- if (isset($where['invoiceid'])) {
- $oldInvTypeID = (int) $this->db->getValue('SELECT invtype FROM `mod_invoiceme_generated` WHERE `invoiceid`=' . $this->db->quoteValue($where['invoiceid']) . ' AND `companyid`=' . $this->db->quoteValue($where['companyid']) . ' ORDER BY `generated` DESC LIMIT 1');
- if ($oldInvTypeID) {
- $type = $this->getInvoiceType(array('invtype' => $oldInvTypeID, 'canceltype' => 0, 'status' => 'paid'));
- if (count($type) && $type['canceltypeof']) {
- $where['id'] = $type['canceltypeof'];
- if (isset($where['invoicetype'])) {
- unset($where['invoicetype']);
- }
- if (isset($where['requiresvatid'])) {
- unset($where['requiresvatid']);
- }
- }
- }
- unset($where['invoiceid']);
- }
- $query = array();
- foreach ($where as $key => $value) {
- $query[] = ($key == 'status' ? $this->db->quoteField($key) . ' LIKE ' . $this->db->quoteValue('%' . $value . '%') : $this->db->quoteField($key) . '=' . $this->db->quoteValue($value));
- }
- $q = 'SELECT * FROM `mod_invoiceme_types` WHERE ' . implode(' AND ', $query) . ' ORDER BY `default` DESC LIMIT 1;';
- $type = $this->db->getRow($q);
- if (0 < (int) $type['getseqnum']) {
- $type['invoiceseqnum'] = $this->db->getValue('SELECT `invoiceseqnum` FROM `mod_invoiceme_types` WHERE `id`=' . $type['getseqnum']);
- }
- $this->InvoiceTypes[$type['id']] = $type;
- .......................................................................
- .......................................
- .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement