api.bankstamd.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. /**
  3. * XLS Bank statements processing class
  4. */
  5. class BankstaMd {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains available users data as login=>userdata
  14. *
  15. * @var array
  16. */
  17. protected $allUsersData = array();
  18. /**
  19. * Temp array for previous bank statements
  20. *
  21. * @var array
  22. */
  23. protected $bankstarecords = array();
  24. /**
  25. * Contains available contracts mappings as contract=>login
  26. *
  27. * @var array
  28. */
  29. protected $contracts = array();
  30. /**
  31. * List of allowed extensions
  32. *
  33. * @var array
  34. */
  35. protected $allowedExtensions = array('xls', 'xlsx');
  36. /**
  37. * Excel reader object placeholder
  38. *
  39. * @var object
  40. */
  41. protected $excelReader = '';
  42. /**
  43. * Just debug flag
  44. *
  45. * @var bool
  46. */
  47. protected $debug = false;
  48. /**
  49. * Default storage table name
  50. */
  51. const BANKSTA_TABLE = 'bankstamd';
  52. /**
  53. * Routing URLs
  54. */
  55. const URL_ME = '?module=bankstamd';
  56. const URL_BANKSTA_MGMT = '?module=bankstamd&banksta=true';
  57. const URL_BANKSTA_PROCESSING = '?module=bankstamd&banksta=true&showhash=';
  58. const URL_BANKSTA_DETAILED = '?module=bankstamd&banksta=true&showdetailed=';
  59. const URL_USERS_PROFILE = '?module=userprofile&username=';
  60. /**
  61. * Some banksta options
  62. */
  63. const BANKSTA_PATH = 'content/documents/bankstamd/';
  64. protected $skipRecords = 2;
  65. protected $bsContractOff = 0;
  66. protected $bsRealnameOff = 1;
  67. protected $bsAddressOff = 2;
  68. protected $bsSumOff = 3;
  69. protected $bsDateOff = 4;
  70. protected $contractNumeric = 0;
  71. /**
  72. * Default payment ID to push banksta payments
  73. *
  74. * @var int
  75. */
  76. protected $bsPaymentId = 1;
  77. /**
  78. * Contains detected users as contract=>login
  79. *
  80. * @var array
  81. */
  82. protected $bankstafoundusers = array();
  83. /**
  84. * Creates new BankstaMd instance
  85. */
  86. public function __construct() {
  87. $this->loadAlter();
  88. $this->setOptions();
  89. $this->loadUserData();
  90. }
  91. /**
  92. * Loads system alter config into protected prop
  93. *
  94. * @global object $ubillingConfig
  95. *
  96. * @return void
  97. */
  98. protected function loadAlter() {
  99. global $ubillingConfig;
  100. $this->altCfg = $ubillingConfig->getAlter();
  101. }
  102. /**
  103. * Sets some config based options
  104. *
  105. * @return void
  106. */
  107. protected function setOptions() {
  108. if (@$this->altCfg['BANKSTAMD_PAYID']) {
  109. $this->bsPaymentId = $this->altCfg['BANKSTAMD_PAYID'];
  110. }
  111. if (@$this->altCfg['BANKSTAMD_DEBUG']) {
  112. $this->debug = true;
  113. }
  114. //some custom options if required
  115. if (@$this->altCfg['BANKSTAMD_OPTIONS']) {
  116. $rawOpts = explode('|', $this->altCfg['BANKSTAMD_OPTIONS']);
  117. if (sizeof($rawOpts) >= 7) {
  118. if ($this->debug) {
  119. show_window(__('Custom options'), wf_tag('pre') . print_r($rawOpts, true) . wf_tag('pre', true));
  120. }
  121. $this->skipRecords = trim($rawOpts[0]); //skip offset 0
  122. $this->bsContractOff = trim($rawOpts[1]); //contract offset 1
  123. $this->bsRealnameOff = trim($rawOpts[2]); //realname offset 2
  124. $this->bsAddressOff = trim($rawOpts[3]); //address offset 3
  125. $this->bsSumOff = trim($rawOpts[4]); //summ offset 4
  126. $this->bsDateOff = trim($rawOpts[5]); //date offset 5
  127. $this->contractNumeric = trim($rawOpts[6]); //numeric contract filter offset 6
  128. } else {
  129. show_error(__('Something went wrong') . ': BANKSTAMD_OPTIONS ' . __('wrong format'));
  130. }
  131. }
  132. }
  133. /**
  134. * Loads all available users data from database
  135. *
  136. * @return void
  137. */
  138. protected function loadUserData() {
  139. $this->allUsersData = zb_UserGetAllData();
  140. if (!empty($this->allUsersData)) {
  141. foreach ($this->allUsersData as $io => $each) {
  142. if (!empty($each['contract'])) {
  143. $this->contracts[$each['contract']] = $each['login'];
  144. }
  145. }
  146. }
  147. }
  148. /**
  149. * Inits reader object and performs file parsing
  150. *
  151. * @param string $filePath
  152. *
  153. * @return void
  154. */
  155. protected function initExcelReader($filePath) {
  156. require('api/vendor/excel/excel_reader2.php');
  157. require('api/vendor/excel/SpreadsheetReader.php');
  158. $this->excelReader = new SpreadsheetReader($filePath);
  159. }
  160. /**
  161. * Returns bank statement upload form
  162. *
  163. * @return string
  164. */
  165. public function renderBankstaLoadForm() {
  166. $uploadinputs = wf_HiddenInput('uploadbankstamd', 'true');
  167. $uploadinputs .= __('Bank statement') . wf_tag('br');
  168. $uploadinputs .= wf_tag('input', false, '', 'id="fileselector" type="file" name="bankstamd"') . wf_tag('br');
  169. $uploadinputs .= wf_Submit('Upload');
  170. $uploadform = bs_UploadFormBody('', 'POST', $uploadinputs, 'glamour');
  171. return ($uploadform);
  172. }
  173. /**
  174. * Process of uploading of bank statement
  175. *
  176. * @return array
  177. */
  178. public function bankstaDoUpload() {
  179. $result = array();
  180. $extCheck = true;
  181. //check file type
  182. foreach ($_FILES as $file) {
  183. if ($file['tmp_name'] > '') {
  184. if (@!in_array(end(explode(".", strtolower($file['name']))), $this->allowedExtensions)) {
  185. $extCheck = false;
  186. }
  187. }
  188. }
  189. if ($extCheck) {
  190. $filename = $_FILES['bankstamd']['name'];
  191. $uploadfile = self::BANKSTA_PATH . $filename;
  192. if (move_uploaded_file($_FILES['bankstamd']['tmp_name'], $uploadfile)) {
  193. $fileContent = file_get_contents(self::BANKSTA_PATH . $filename);
  194. $fileHash = md5($fileContent);
  195. $fileContent = ''; //free some memory
  196. if ($this->bankstaCheckHash($fileHash)) {
  197. $result = array(
  198. 'filename' => $_FILES['bankstamd']['name'],
  199. 'savedname' => $filename,
  200. 'hash' => $fileHash
  201. );
  202. } else {
  203. log_register('BANKSTAMD DUPLICATE TRY ' . $fileHash);
  204. show_error(__('Same bank statement already exists'));
  205. }
  206. } else {
  207. show_error(__('Cant upload file to') . ' ' . self::BANKSTA_PATH);
  208. }
  209. } else {
  210. show_error(__('Wrong file type'));
  211. log_register('BANKSTAMD WRONG FILETYPE');
  212. }
  213. return ($result);
  214. }
  215. /**
  216. * checks is banksta hash unique?
  217. *
  218. * @param string $hash bank statement raw content hash
  219. *
  220. * @return bool
  221. */
  222. protected function bankstaCheckHash($hash) {
  223. $query = "SELECT `id` from `" . self::BANKSTA_TABLE . "` WHERE `hash`='" . $hash . "';";
  224. $data = simple_query($query);
  225. if (empty($data)) {
  226. return (true);
  227. } else {
  228. return (false);
  229. }
  230. }
  231. /**
  232. * Creates new banksta row in Database
  233. *
  234. * @param string $newDate
  235. * @param string $newHash
  236. * @param string $newFilename
  237. * @param string $newAdmin
  238. * @param string $newContract
  239. * @param string $newSumm
  240. * @param string $newAddress
  241. * @param string $newRealname
  242. * @param string $newNotes
  243. * @param string $newPate
  244. * @param string $newPtime
  245. *
  246. * @return void
  247. */
  248. protected function bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime) {
  249. $query = "INSERT INTO `" . self::BANKSTA_TABLE . "` (`id`, `date`, `hash`, `filename`, `admin`, `contract`, `summ`, `address`, `realname`, `notes`, `pdate`, `ptime`, `processed`)
  250. VALUES (
  251. NULL ,
  252. '" . $newDate . "',
  253. '" . $newHash . "',
  254. '" . $newFilename . "',
  255. '" . $newAdmin . "',
  256. '" . $newContract . "',
  257. '" . $newSumm . "',
  258. '" . $newAddress . "',
  259. '" . $newRealname . "',
  260. '" . $newNotes . "',
  261. '" . $newPdate . "',
  262. '" . $newPtime . "',
  263. '0'
  264. );
  265. ";
  266. nr_query($query);
  267. }
  268. /**
  269. * new banksta store in database bankstaDoUpload() method and returns preprocessed
  270. * bank statement hash for further usage
  271. *
  272. * @param $bankstadata array returned from doUpload
  273. *
  274. * @return string
  275. */
  276. public function bankstaPreprocessing($bankstadata) {
  277. $result = '';
  278. if (!empty($bankstadata)) {
  279. if (file_exists(self::BANKSTA_PATH . $bankstadata['savedname'])) {
  280. //processing raw data
  281. $newHash = $bankstadata['hash'];
  282. $result = $newHash;
  283. $newFilename = $bankstadata['filename'];
  284. $newAdmin = whoami();
  285. $this->initExcelReader(self::BANKSTA_PATH . $bankstadata['savedname']);
  286. $importCounter = 0;
  287. foreach ($this->excelReader as $eachRow) {
  288. if ($importCounter >= $this->skipRecords) {
  289. if (!empty($eachRow)) {
  290. if ($this->debug) {
  291. debarr($eachRow);
  292. }
  293. $newDate = date("Y-m-d H:i:s");
  294. @$newContract = trim($eachRow[$this->bsContractOff]);
  295. $newContract = mysql_real_escape_string($newContract);
  296. //filter only numeric values from contract
  297. if ($this->contractNumeric) {
  298. $newContract = vf($newContract, 3);
  299. }
  300. @$newSumm = trim($eachRow[$this->bsSumOff]);
  301. $newSumm = mysql_real_escape_string($newSumm);
  302. $newSumm = str_replace(' ', '', $newSumm);
  303. @$newAddress = mysql_real_escape_string($eachRow[$this->bsAddressOff]);
  304. @$newRealname = mysql_real_escape_string($eachRow[$this->bsRealnameOff]);
  305. $newNotes = '';
  306. @$timeStamp = strtotime($eachRow[$this->bsDateOff]);
  307. if (!empty($timeStamp)) {
  308. $newPdate = date("Y-m-d", $timeStamp);
  309. $newPtime = date("H:i:s", $timeStamp);
  310. } else {
  311. $newPdate = '';
  312. $newPtime = '';
  313. }
  314. //pushing row into database
  315. if ((!empty($newContract)) AND ( !empty($newSumm))) {
  316. $this->bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime);
  317. }
  318. }
  319. }
  320. $importCounter++;
  321. }
  322. log_register('BANKSTAMD IMPORTED ' . ($importCounter - $this->skipRecords) . ' ROWS');
  323. } else {
  324. show_error(__('Strange exeption'));
  325. }
  326. } else {
  327. throw new Exception(self::EX_BANKSTA_PREPROCESS_EMPTY);
  328. }
  329. return ($result);
  330. }
  331. /**
  332. * Catches file upload form and performs basic banksta preprocessing
  333. *
  334. * @return void
  335. */
  336. public function catchUploadRequest() {
  337. if (wf_CheckPost(array('uploadbankstamd'))) {
  338. $uploadResult = $this->bankstaDoUpload();
  339. if ($this->debug) {
  340. debarr($uploadResult);
  341. }
  342. if (!empty($uploadResult)) {
  343. $this->bankstaPreprocessing($uploadResult);
  344. }
  345. }
  346. }
  347. /**
  348. * Renders bank statements list container
  349. *
  350. * @return type
  351. */
  352. public function renderBankstaList() {
  353. $result = '';
  354. $columns = array(__('Date'), __('Filename'), __('Rows'), __('Admin'), __('Actions'));
  355. $opts = '"order": [[ 0, "desc" ]]';
  356. $result .= wf_JqDtLoader($columns, self::URL_BANKSTA_MGMT . '&ajbslist=true', false, __('Bank statement'), 50, $opts);
  357. return ($result);
  358. }
  359. /**
  360. * Renders bank statements list datatables json datasource
  361. *
  362. * @return void
  363. */
  364. public function bankstaRenderAjaxList() {
  365. $query = "SELECT `filename`,`hash`,`date`,`admin`,COUNT(`id`) AS `rowcount` FROM `" . self::BANKSTA_TABLE . "` GROUP BY `hash` ORDER BY `date` DESC;";
  366. $all = simple_queryall($query);
  367. $json = new wf_JqDtHelper();
  368. if (!empty($all)) {
  369. foreach ($all as $io => $each) {
  370. $data[] = $each['date'];
  371. $data[] = $each['filename'];
  372. $data[] = $each['rowcount'];
  373. $data[] = $each['admin'];
  374. $actLinks = wf_Link(self::URL_BANKSTA_PROCESSING . $each['hash'], wf_img('skins/icon_search_small.gif', __('Show')), false, '');
  375. $data[] = $actLinks;
  376. $json->addRow($data);
  377. unset($data);
  378. }
  379. }
  380. $json->getJson();
  381. }
  382. /**
  383. * returns banksta processing form for some hash
  384. *
  385. * @param string $hash existing preprocessing bank statement hash
  386. *
  387. * @return string
  388. */
  389. public function bankstaProcessingForm($hash) {
  390. $hash = mysql_real_escape_string($hash);
  391. $query = "SELECT * from `" . self::BANKSTA_TABLE . "` WHERE `hash`='" . $hash . "' ORDER BY `id` ASC;";
  392. $all = simple_queryall($query);
  393. $cashPairs = array();
  394. $cells = wf_TableCell(__('ID'));
  395. $cells .= wf_TableCell(__('Address'));
  396. $cells .= wf_TableCell(__('Real Name'));
  397. $cells .= wf_TableCell(__('Contract'));
  398. $cells .= wf_TableCell(__('Cash'));
  399. $cells .= wf_TableCell(__('Processed'));
  400. $cells .= wf_TableCell(__('Contract'));
  401. $cells .= wf_TableCell(__('Real Name'));
  402. $cells .= wf_TableCell(__('Address'));
  403. $cells .= wf_TableCell(__('Tariff'));
  404. $rows = wf_TableRow($cells, 'row1');
  405. if (!empty($all)) {
  406. foreach ($all as $io => $each) {
  407. $addInfoControl = wf_Link(self::URL_BANKSTA_DETAILED . $each['id'], $each['id'], false, '');
  408. $processed = ($each['processed']) ? true : false;
  409. $cells = wf_TableCell($addInfoControl);
  410. $cells .= wf_TableCell($each['address']);
  411. $cells .= wf_TableCell($each['realname']);
  412. if (!$processed) {
  413. $editInputs = wf_TextInput('newbankcontr', '', $each['contract'], false, '6');
  414. $editInputs .= wf_CheckInput('lockbankstarow', __('Lock'), false, false);
  415. $editInputs .= wf_HiddenInput('bankstacontractedit', $each['id']);
  416. $editInputs .= wf_Submit(__('Save'));
  417. $editForm = wf_Form('', 'POST', $editInputs);
  418. } else {
  419. $editForm = $each['contract'];
  420. }
  421. $cells .= wf_TableCell($editForm);
  422. $cells .= wf_TableCell($each['summ']);
  423. $cells .= wf_TableCell(web_bool_led($processed));
  424. //user detection
  425. if (isset($this->contracts[$each['contract']])) {
  426. $detectedUser = $this->allUsersData[$this->contracts[$each['contract']]];
  427. $detectedContract = wf_Link(self::URL_USERS_PROFILE . $detectedUser['login'], web_profile_icon() . ' ' . $detectedUser['contract'], false, '');
  428. $detectedAddress = $detectedUser['fulladress'];
  429. $detectedRealName = $detectedUser['realname'];
  430. $detectedTariff = $detectedUser['Tariff'];
  431. if (!$processed) {
  432. $cashPairs[$each['id']]['bankstaid'] = $each['id'];
  433. $cashPairs[$each['id']]['userlogin'] = $detectedUser['login'];
  434. $cashPairs[$each['id']]['usercontract'] = $detectedUser['contract'];
  435. $cashPairs[$each['id']]['summ'] = $each['summ'];
  436. $cashPairs[$each['id']]['payid'] = $this->bsPaymentId;
  437. }
  438. $rowClass = 'row3';
  439. //try to highlight multiple payments
  440. if (!isset($this->bankstafoundusers[$each['contract']])) {
  441. $this->bankstafoundusers[$each['contract']] = $detectedUser['login'];
  442. } else {
  443. $rowClass = 'ukvbankstadup';
  444. }
  445. } else {
  446. $detectedContract = '';
  447. $detectedAddress = '';
  448. $detectedRealName = '';
  449. $detectedTariff = '';
  450. if ($each['processed'] == 1) {
  451. $rowClass = 'row2';
  452. } else {
  453. $rowClass = 'undone';
  454. }
  455. }
  456. $cells .= wf_TableCell($detectedContract);
  457. $cells .= wf_TableCell($detectedRealName);
  458. $cells .= wf_TableCell($detectedAddress);
  459. $cells .= wf_TableCell($detectedTariff);
  460. $rows .= wf_TableRow($cells, $rowClass);
  461. }
  462. }
  463. $result = wf_TableBody($rows, '100%', '0', '');
  464. if (!empty($cashPairs)) {
  465. $cashPairs = serialize($cashPairs);
  466. $cashPairs = base64_encode($cashPairs);
  467. $cashInputs = wf_HiddenInput('bankstaneedpaymentspush', $cashPairs);
  468. $cashInputs .= wf_Submit(__('Bank statement processing'));
  469. $result .= wf_Form('', 'POST', $cashInputs, 'glamour');
  470. }
  471. return ($result);
  472. }
  473. /**
  474. * returns detailed banksta row info
  475. *
  476. * @param int $id existing banksta ID
  477. *
  478. * @return string
  479. */
  480. public function bankstaGetDetailedRowInfo($id) {
  481. $id = vf($id, 3);
  482. $query = "SELECT * from `" . self::BANKSTA_TABLE . "` WHERE `id`='" . $id . "'";
  483. $dataRaw = simple_query($query);
  484. $result = '';
  485. $result.= wf_BackLink(self::URL_BANKSTA_PROCESSING . $dataRaw['hash']);
  486. $result.= wf_delimiter();
  487. if (!empty($dataRaw)) {
  488. $result.= wf_tag('pre', false, 'floatpanelswide', '') . print_r($dataRaw, true) . wf_tag('pre', true);
  489. $result.= wf_CleanDiv();
  490. }
  491. return ($result);
  492. }
  493. /**
  494. * loads all of banksta rows to further checks to private prop
  495. *
  496. * @return void
  497. */
  498. protected function loadBankstaAll() {
  499. $query = "SELECT * from `" . self::BANKSTA_TABLE . "`";
  500. $all = simple_queryall($query);
  501. if (!empty($all)) {
  502. foreach ($all as $io => $each) {
  503. $this->bankstarecords[$each['id']] = $each;
  504. }
  505. }
  506. }
  507. /**
  508. * cnahges banksta contract number for some existing row
  509. *
  510. * @param int $bankstaid existing bank statement transaction ID
  511. * @param string $contract new contract number for this row
  512. *
  513. * @return void
  514. */
  515. public function bankstaSetContract($bankstaid, $contract) {
  516. $bankstaid = vf($bankstaid, 3);
  517. $contract = mysql_real_escape_string($contract);
  518. $contract = trim($contract);
  519. if (empty($this->bankstarecords)) {
  520. $this->loadBankstaAll();
  521. }
  522. if (isset($this->bankstarecords[$bankstaid])) {
  523. $oldContract = $this->bankstarecords[$bankstaid]['contract'];
  524. simple_update_field(self::BANKSTA_TABLE, 'contract', $contract, "WHERE `id`='" . $bankstaid . "';");
  525. log_register('BANKSTAMD [' . $bankstaid . '] CONTRACT `' . $oldContract . '` CHANGED ON `' . $contract . '`');
  526. } else {
  527. log_register('BANKSTAMD NONEXIST [' . $bankstaid . '] CONTRACT CHANGE TRY');
  528. }
  529. }
  530. /**
  531. * checks is banksta row ID unprocessed?
  532. *
  533. * @param int $bankstaid existing banksta row ID
  534. *
  535. * @return bool
  536. */
  537. protected function bankstaIsUnprocessed($bankstaid) {
  538. $result = false;
  539. if (isset($this->bankstarecords[$bankstaid])) {
  540. if ($this->bankstarecords[$bankstaid]['processed'] == 0) {
  541. $result = true;
  542. } else {
  543. $result = false;
  544. }
  545. }
  546. return ($result);
  547. }
  548. /**
  549. * sets banksta row as processed
  550. *
  551. * @param int $bankstaid existing bank statement ID
  552. *
  553. * @return void
  554. */
  555. public function bankstaSetProcessed($bankstaid, $logging = true) {
  556. $bankstaid = vf($bankstaid, 3);
  557. $this->bankstarecords[$bankstaid]['processed'] = 1;
  558. simple_update_field(self::BANKSTA_TABLE, 'processed', 1, "WHERE `id`='" . $bankstaid . "'");
  559. if ($logging) {
  560. log_register('BANKSTAMD [' . $bankstaid . '] LOCKED');
  561. }
  562. }
  563. /**
  564. * push payments to some user accounts via bank statements
  565. *
  566. * @return void
  567. */
  568. public function bankstaPushPayments() {
  569. if (wf_CheckPost(array('bankstaneedpaymentspush'))) {
  570. $rawData = base64_decode($_POST['bankstaneedpaymentspush']);
  571. $rawData = unserialize($rawData);
  572. if (!empty($rawData)) {
  573. if (empty($this->bankstarecords)) {
  574. $this->loadBankstaAll();
  575. }
  576. foreach ($rawData as $io => $eachstatement) {
  577. if ($this->bankstaIsUnprocessed($eachstatement['bankstaid'])) {
  578. //all good is with this row
  579. // push payment and mark banksta as processed
  580. $paymentNote = 'BANKSTA: [' . $eachstatement['bankstaid'] . '] ASCONTRACT ' . $eachstatement['usercontract'];
  581. $userLogin = $eachstatement['userlogin'];
  582. $summ = $eachstatement['summ'];
  583. $summ = abs($summ);
  584. if (!empty($userLogin)) {
  585. if (isset($this->allUsersData[$userLogin])) {
  586. if (zb_checkMoney($summ)) {
  587. $this->bankstaSetProcessed($eachstatement['bankstaid'], false);
  588. zb_CashAdd($eachstatement['userlogin'], $summ, 'add', $this->bsPaymentId, $paymentNote);
  589. }
  590. } else {
  591. log_register('BANKSTAMD [' . $eachstatement['bankstaid'] . '] FAIL LOGIN (' . $userLogin . ')');
  592. }
  593. } else {
  594. log_register('BANKSTAMD [' . $eachstatement['bankstaid'] . '] FAIL EMPTY LOGIN');
  595. }
  596. } else {
  597. //duplicate payment try
  598. log_register('BANKSTAMD TRY DUPLICATE [' . $eachstatement['bankstaid'] . '] PAYMENT PUSH');
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }