Advertisement
Guest User

Untitled

a guest
Aug 9th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. <?php
  2. /*
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 3.5.0.0
  8. * @ Author : DeZender
  9. * @ Release on : 22.06.2018
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. if (!defined('WHMCS')) {
  15. exit('This file cannot be accessed directly');
  16. }
  17.  
  18. class INVOICESME
  19. {
  20. private static $instance = null;
  21. private $lang = array();
  22. private $paymtethods = array();
  23. private $currences = array();
  24. private $generated = array();
  25. private $errors = array();
  26. private $ruleLogs = array();
  27. private $rules = array();
  28. private $gateways = array();
  29. protected $InvoiceTypes = array();
  30. protected $invoiceItems = array();
  31. protected $transactions = array();
  32. protected $db = null;
  33. protected $cid = 0;
  34. protected $debug = 0;
  35.  
  36. public function __construct()
  37. {
  38. if (!class_exists('DB_INVOICES')) {
  39. require_once INVOICEPATH . '/classes/db.php';
  40. }
  41.  
  42. $this->db = DB_INVOICES::getInstance();
  43. $api = INVOICEAPI::getInstance();
  44. $this->cid = $api->getProfileID();
  45. $this->debug = $_REQUEST['debug'];
  46. }
  47.  
  48. public static function getInstance()
  49. {
  50. if (!self::$instance) {
  51. self::$instance = new self();
  52. }
  53.  
  54. return self::$instance;
  55. }
  56.  
  57. public function setCompanyID($id)
  58. {
  59. $this->cid = (int) $id;
  60. $api = INVOICEAPI::getInstance();
  61. $api->setProfileID($this->cid);
  62. }
  63.  
  64. public function getGeneratedID($id)
  65. {
  66. 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));
  67. }
  68.  
  69. public function updateSequenceNum($inv, $type = 'add')
  70. {
  71. $id = (isset($inv['invtype']) ? $inv['invtype'] : $inv['id']);
  72.  
  73. if (!isset($inv['getseqnum'])) {
  74. $inv = $this->getInvoiceType(array('id' => $id), false);
  75. }
  76.  
  77. $invoiceTypeID = (0 < (int) $inv['getseqnum'] ? $inv['getseqnum'] : $id);
  78.  
  79. if (!$invoiceTypeID) {
  80. return false;
  81. }
  82.  
  83. if ($type == 'add') {
  84. $update = array('companyid' => $this->cid, 'invoiceseqnum' => $inv['invoiceseqnum'] + 1);
  85. } else {
  86. $update = array('companyid' => $this->cid, 'invoiceseqnum' => (0 < $inv['invoiceseqnum'] - 1 ? $inv['invoiceseqnum'] - 1 : 1));
  87. }
  88.  
  89. if (!$this->db->update('mod_invoiceme_types', $update, array('id' => $invoiceTypeID))) {
  90. $this->errors[] = 'Sequence Number is not updated! (Type:' . $type . ')';
  91.  
  92. return false;
  93. }
  94.  
  95. $this->InvoiceTypes[$invoiceTypeID] = $update['invoiceseqnum'];
  96.  
  97. return true;
  98. }
  99.  
  100. public function deleteInvoice($id)
  101. {
  102. if (!$id) {
  103. return false;
  104. }
  105.  
  106. $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);
  107.  
  108. if (count($inv) && $this->db->query('DELETE FROM mod_invoiceme_generated WHERE companyid=' . $this->cid . ' AND invoiceid=' . (int) $id)) {
  109. $this->db->query("UPDATE `tblinvoices` SET `invoicenum`='' WHERE id=" . (int) $id);
  110.  
  111. if (file_exists($inv['pdfpath'] . $inv['pdfname'])) {
  112. unlink($inv['pdfpath'] . $inv['pdfname']);
  113. }
  114.  
  115. return $this->updateSequenceNum($inv, 'remove');
  116. }
  117.  
  118. return false;
  119. }
  120.  
  121. public function getEUcountries()
  122. {
  123. $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');
  124.  
  125. return $eu_countries;
  126. }
  127.  
  128. public function getCurrency($value, $key = 'id')
  129. {
  130. if (!$value) {
  131. return array();
  132. }
  133.  
  134. if (isset($this->currences[$key][$value]) && is_array($this->currences[$key][$value])) {
  135. return $this->currences[$key][$value];
  136. }
  137.  
  138. $q = 'SELECT * FROM `tblcurrencies` WHERE ' . $this->db->quoteField($key) . '=' . $this->db->quoteValue($value);
  139. $this->currences[$key][$value] = (array) $this->db->getRow($q);
  140.  
  141. return $this->currences[$key][$value];
  142. }
  143.  
  144. public function getInvoice($id, $filter = false)
  145. {
  146. if (!(int) $id) {
  147. return array();
  148. }
  149.  
  150. $extraField = (version_compare(WHMCSV, '7.7.0', 'ge') ? ',c.tax_id' : '');
  151. $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;
  152.  
  153. if ($filter) {
  154. $q .= ' AND i.id NOT IN (SELECT w.invoiceid FROM mod_invoiceme_generated as w WHERE w.companyid=' . $this->cid . ') ';
  155. }
  156.  
  157. return (array) $this->db->getRow($q);
  158. }
  159.  
  160. public function getGenerated($id, $key = 'id')
  161. {
  162. $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);
  163. $data = $this->db->getRow($q);
  164.  
  165. return $data;
  166. }
  167.  
  168. public function getInvoiceType($where = array(), $cache = true)
  169. {
  170. if (!count($where)) {
  171. return array();
  172. }
  173.  
  174. if ($cache && isset($where['id']) && isset($this->InvoiceTypes[$where['id']]) && count($this->InvoiceTypes[$where['id']])) {
  175. return $this->InvoiceTypes[$where['id']];
  176. }
  177.  
  178. if (isset($where['invoiceid'])) {
  179. $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');
  180.  
  181. if ($oldInvTypeID) {
  182. $type = $this->getInvoiceType(array('invtype' => $oldInvTypeID, 'canceltype' => 0, 'status' => 'paid'));
  183.  
  184. if (count($type) && $type['canceltypeof']) {
  185. $where['id'] = $type['canceltypeof'];
  186.  
  187. if (isset($where['invoicetype'])) {
  188. unset($where['invoicetype']);
  189. }
  190.  
  191. if (isset($where['requiresvatid'])) {
  192. unset($where['requiresvatid']);
  193. }
  194. }
  195. }
  196.  
  197. unset($where['invoiceid']);
  198. }
  199.  
  200. $query = array();
  201.  
  202. foreach ($where as $key => $value) {
  203. $query[] = ($key == 'status' ? $this->db->quoteField($key) . ' LIKE ' . $this->db->quoteValue('%' . $value . '%') : $this->db->quoteField($key) . '=' . $this->db->quoteValue($value));
  204. }
  205. $q = 'SELECT * FROM `mod_invoiceme_types` WHERE ' . implode(' AND ', $query) . ' ORDER BY `default` DESC LIMIT 1;';
  206. $type = $this->db->getRow($q);
  207.  
  208. if (0 < (int) $type['getseqnum']) {
  209. $type['invoiceseqnum'] = $this->db->getValue('SELECT `invoiceseqnum` FROM `mod_invoiceme_types` WHERE `id`=' . $type['getseqnum']);
  210. }
  211.  
  212. $this->InvoiceTypes[$type['id']] = $type;
  213. .......................................................................
  214. .......................................
  215. .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement