index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <?php
  2. if (cfr('PAYFIND')) {
  3. /**
  4. * Returns all of known payment systems percents
  5. *
  6. * @return array
  7. */
  8. function zb_PaySysPercentGetAll() {
  9. $result = array();
  10. $data_raw = zb_StorageGet('PAYSYSPC');
  11. if (!empty($data_raw)) {
  12. //unpack data
  13. $data_raw = base64_decode($data_raw);
  14. $result = unserialize($data_raw);
  15. } else {
  16. //first usage
  17. $newdata = serialize($result);
  18. $newdata = base64_encode($newdata);
  19. zb_StorageSet('PAYSYSPC', $newdata);
  20. log_register("PAYSYSPC CREATE EMPTY");
  21. }
  22. return ($result);
  23. }
  24. /**
  25. * Adds new payment system data to database
  26. *
  27. * @param $mark identifying text of payment system
  28. * @param $name human-readable name of payment system
  29. * @param $percent percent withholding payment system
  30. *
  31. * @return void
  32. */
  33. function zb_PaySysPercentAdd($mark, $name, $percent) {
  34. $mark = mysql_real_escape_string($mark);
  35. $name = mysql_real_escape_string($name);
  36. $percent = mysql_real_escape_string($percent);
  37. if ($percent == '') {
  38. $percent = 0;
  39. }
  40. $olddata = zb_PaySysPercentGetAll();
  41. $newdata = $olddata;
  42. if (!isset($olddata[$mark]['name'])) {
  43. $newdata[$mark]['name'] = $name;
  44. $newdata[$mark]['percent'] = $percent;
  45. $newdata = serialize($newdata);
  46. $newdata = base64_encode($newdata);
  47. zb_StorageSet('PAYSYSPC', $newdata);
  48. log_register("PAYSYSPC ADD `" . $mark . ":" . $name . ":" . $percent . "`");
  49. }
  50. }
  51. /**
  52. * Removes payment system data from database
  53. *
  54. * @param $mark identifying text of payment system
  55. *
  56. * @return void
  57. */
  58. function zb_PaySysPercentDelete($mark) {
  59. $mark = mysql_real_escape_string($mark);
  60. $olddata = zb_PaySysPercentGetAll();
  61. $newdata = $olddata;
  62. if (isset($newdata[$mark])) {
  63. unset($newdata[$mark]);
  64. $newdata = serialize($newdata);
  65. $newdata = base64_encode($newdata);
  66. zb_StorageSet('PAYSYSPC', $newdata);
  67. log_register("PAYSYSPC DELETE `" . $mark . "`");
  68. }
  69. }
  70. /**
  71. * Show payment system create and deletion form
  72. *
  73. * @return string
  74. */
  75. function web_PaySysForm() {
  76. $allpaysys = zb_PaySysPercentGetAll();
  77. $inputs = wf_TextInput('newmarker', __('Payment system marker'), '', true, '10');
  78. $inputs .= wf_TextInput('newname', __('Payment system name'), '', true, '10');
  79. $inputs .= wf_TextInput('newpercent', __('Percent withholding payment system'), '', true, '4');
  80. $inputs .= wf_Submit(__('Save'));
  81. $form = wf_Form("", "POST", $inputs, 'glamour');
  82. $result = $form;
  83. if (!empty($allpaysys)) {
  84. $cells = wf_TableCell(__('Marker'));
  85. $cells .= wf_TableCell(__('Name'));
  86. $cells .= wf_TableCell(__('Percent'));
  87. $cells .= wf_TableCell(__('Actions'));
  88. $rows = wf_TableRow($cells, 'row1');
  89. foreach ($allpaysys as $marker => $each) {
  90. $cells = wf_TableCell($marker);
  91. $cells .= wf_TableCell($each['name']);
  92. $cells .= wf_TableCell($each['percent']);
  93. $cells .= wf_TableCell(wf_JSAlert("?module=payfind&confpaysys=true&delete=" . $marker, web_delete_icon(), __('Removing this may lead to irreparable results')));
  94. $rows .= wf_TableRow($cells, 'row3');
  95. }
  96. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  97. }
  98. $result .= wf_BackLink("?module=payfind");
  99. $result .= wf_delimiter(1);
  100. return ($result);
  101. }
  102. /**
  103. * Returns payment system selector - used in search form
  104. *
  105. * @return string
  106. */
  107. function web_PaySysPercentSelector() {
  108. $allpaysys = zb_PaySysPercentGetAll();
  109. $prepared = array();
  110. if (!empty($allpaysys)) {
  111. foreach ($allpaysys as $marker => $each) {
  112. $prepared[$marker] = $each['name'];
  113. }
  114. }
  115. $result = wf_Selector('paysys', $prepared, __('Payment system'), '', false);
  116. return ($result);
  117. }
  118. /**
  119. * Returns available cashier accounts selector
  120. *
  121. * @return string
  122. */
  123. function web_PayFindCashierSelector() {
  124. $alladmins = rcms_scandir(USERS_PATH);
  125. $adminlist = array();
  126. @$employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached());
  127. $result = '';
  128. if (!empty($alladmins)) {
  129. foreach ($alladmins as $nu => $login) {
  130. $administratorName = (isset($employeeLogins[$login])) ? $employeeLogins[$login] : $login;
  131. $adminlist[$login] = $administratorName;
  132. }
  133. $adminlist['openpayz'] = __('OpenPayz');
  134. $result = wf_Selector('cashier', $adminlist, __('Cashier'), '', true, true);
  135. }
  136. return ($result);
  137. }
  138. /**
  139. * Returns available tags selector
  140. *
  141. * @return string
  142. */
  143. function web_PayFindTagidSelector() {
  144. $query = "SELECT `id`,`tagname` from `tagtypes`";
  145. $result = '';
  146. $tags = array();
  147. $alltags = simple_queryall($query);
  148. if (!empty($alltags)) {
  149. foreach ($alltags as $io => $eachtag) {
  150. $tags[$eachtag['id']] = $eachtag['tagname'];
  151. }
  152. }
  153. $result = wf_Selector('tagid', $tags, __('Tags'), '', true, true);
  154. return($result);
  155. }
  156. /**
  157. * extracts all user logins by tagid in SQL WHERE accessible format
  158. *
  159. * @param $tagid int existing tag ID
  160. *
  161. * @return string
  162. */
  163. function zb_PayFindExtractByTagId($tagid) {
  164. $tagid = vf($tagid, 3);
  165. $query = "SELECT `login`,`tagid` from `tags` WHERE `tagid`='" . $tagid . "';";
  166. $alltagged = simple_queryall($query);
  167. $result = ' AND `login` IN (';
  168. if (!empty($alltagged)) {
  169. foreach ($alltagged as $io => $each) {
  170. $result .= "'" . $each['login'] . "',";
  171. }
  172. $result = rtrim($result, ',');
  173. } else {
  174. $result .= "'" . zb_rand_string('12') . "'";
  175. }
  176. $result .= ') ';
  177. return ($result);
  178. }
  179. /**
  180. * Returns search table selector
  181. *
  182. * @return string
  183. */
  184. function web_PayFindTableSelect() {
  185. if (wf_CheckPost(array('searchtable'))) {
  186. $selected = $_POST['searchtable'];
  187. } else {
  188. $selected = '';
  189. }
  190. $params = array(
  191. "payments" => __('Finance report'),
  192. "corrections" => __('Correct saldo')
  193. );
  194. $result = wf_Selector('searchtable', $params, __('Search into'), $selected, false);
  195. return ($result);
  196. }
  197. /**
  198. * Returns payment search form
  199. *
  200. * @return string
  201. */
  202. function web_PayFindForm() {
  203. //try to save calendar states
  204. if (wf_CheckPost(array('datefrom', 'dateto'))) {
  205. $curdate = $_POST['dateto'];
  206. $yesterday = $_POST['datefrom'];
  207. } else {
  208. $curdate = date("Y-m-d", time() + 60 * 60 * 24);
  209. $yesterday = curdate();
  210. }
  211. $inputs = __('Date');
  212. $inputs .= wf_DatePickerPreset('datefrom', $yesterday) . ' ' . __('From');
  213. $inputs .= wf_DatePickerPreset('dateto', $curdate) . ' ' . __('To');
  214. $inputs .= wf_delimiter();
  215. $inputs .= wf_CheckInput('type_payid', '', false, false);
  216. $inputs .= wf_TextInput('payid', __('Search by payment ID'), '', true, '10');
  217. $inputs .= wf_CheckInput('type_contract', '', false, false);
  218. $inputs .= wf_TextInput('contract', __('Search by users contract'), '', true, '10');
  219. $inputs .= wf_CheckInput('type_login', '', false, false);
  220. $inputs .= wf_TextInput('login', __('Search by users login'), '', true, '10');
  221. $inputs .= wf_CheckInput('type_loginwildcard', '', false, false);
  222. $inputs .= wf_TextInput('loginwildcard', __('Login contains'), '', true, '10');
  223. $inputs .= wf_CheckInput('type_summ', '', false, false);
  224. $inputs .= wf_TextInput('summ', __('Search by payment sum'), '', true, '10');
  225. $inputs .= wf_CheckInput('type_payidenc', '', false, false);
  226. $inputs .= wf_TextInput('payidenc', __('IDENC'), '', true, '10');
  227. $inputs .= wf_CheckInput('type_summgreater', '', false, false);
  228. $inputs .= wf_TextInput('paysummgreater', __('Payment summ greater then'), '', true, '10');
  229. $inputs .= wf_CheckInput('type_notescontains', '', false, false);
  230. $inputs .= wf_TextInput('paynotescontains', __('Notes contains'), '', true, '10');
  231. $inputs .= wf_CheckInput('type_cashtype', '', false, false);
  232. $inputs .= web_CashTypeSelector() . wf_tag('label', false, '', 'for="cashtype"') . __('Search by cash type') . wf_tag('label', true) . wf_tag('br');
  233. $inputs .= wf_CheckInput('type_cashier', '', false, false);
  234. $inputs .= web_PayFindCashierSelector();
  235. $inputs .= wf_CheckInput('type_tagid', '', false, false);
  236. $inputs .= web_PayFindTagidSelector();
  237. $inputs .= wf_CheckInput('type_paysys', '', false, false);
  238. $inputs .= web_PaySysPercentSelector();
  239. $inputs .= wf_Link("?module=payfind&confpaysys=true", __('Settings')) . wf_tag('br');
  240. $inputs .= wf_CheckInput('type_city', '', false, false);
  241. $inputs .= web_CitySelector() . ' ' . __('City') . wf_delimiter(0);
  242. $inputs .= wf_CheckInput('type_address', '', false, false);
  243. $inputs .= wf_TextInput('payaddrcontains', __('Address contains'), '', true, 20);
  244. $inputs .= wf_CheckInput('type_contragent', '', false, false);
  245. $inputs .= zb_ContrAhentSelectPreset() . ' ' . __('Service provider') . wf_delimiter(0);
  246. $inputs .= wf_CheckInput('only_positive', __('Show only positive payments'), true, false);
  247. $inputs .= wf_CheckInput('numeric_notes', __('Show payments with numeric notes'), true, false);
  248. $inputs .= wf_CheckInput('numericonly_notes', __('Show payments with only numeric notes'), true, false);
  249. $inputs .= wf_nbsp(8) . web_PayFindTableSelect() . wf_delimiter();
  250. $inputs .= wf_HiddenInput('dosearch', 'true');
  251. $inputs .= wf_Submit(__('Search'));
  252. $result = wf_Form('', 'POST', $inputs, 'glamour');
  253. $result .= wf_delimiter(0);
  254. $result .= wf_BackLink("?module=report_finance");
  255. return ($result);
  256. }
  257. /**
  258. * Execute search with prepared options and shows search results
  259. *
  260. * @return void
  261. */
  262. function web_PaymentSearch($markers, $joins = '') {
  263. global $ubillingConfig;
  264. $altercfg = $ubillingConfig->getAlter();
  265. if (wf_CheckPost(array('searchtable'))) {
  266. if ($_POST['searchtable'] == 'payments') {
  267. $table = 'payments';
  268. }
  269. if ($_POST['searchtable'] == 'corrections') {
  270. $table = 'paymentscorr';
  271. }
  272. } else {
  273. $table = 'payments';
  274. }
  275. $query = "SELECT * from `" . $table . "`";
  276. $query .= $joins . $markers;
  277. $csvdata = '';
  278. $allpayments = simple_queryall($query);
  279. if ($altercfg['FINREP_CONTRACT']) {
  280. $allcontracts = zb_UserGetAllContracts();
  281. $allcontracts = array_flip($allcontracts);
  282. }
  283. if ($altercfg['FINREP_TARIFF']) {
  284. $alltariffs = zb_TariffsGetAllUsers();
  285. }
  286. $allrealnames = zb_UserGetAllRealnames();
  287. $alladdress = zb_AddressGetFulladdresslist();
  288. $alltypes = zb_CashGetAllCashTypes();
  289. $allservicenames = zb_VservicesGetAllNamesLabeled();
  290. $allpaysyspercents = zb_PaySysPercentGetAll();
  291. $totalsumm = 0;
  292. $paysyssumm = 0;
  293. $profitsumm = 0;
  294. $totalcount = 0;
  295. $cells = wf_TableCell(__('ID'));
  296. $cells .= wf_TableCell(__('Date'));
  297. $cells .= wf_TableCell(__('Cash'));
  298. $cells .= wf_TableCell(__('PS%'));
  299. $cells .= wf_TableCell(__('Profit'));
  300. $cells .= wf_TableCell(__('Login'));
  301. if ($altercfg['FINREP_CONTRACT']) {
  302. $cells .= wf_TableCell(__('Contract'));
  303. }
  304. $cells .= wf_TableCell(__('Full address'));
  305. $cells .= wf_TableCell(__('Real Name'));
  306. if ($altercfg['FINREP_TARIFF']) {
  307. $cells .= wf_TableCell(__('Tariff'));
  308. }
  309. $cells .= wf_TableCell(__('Payment type'));
  310. $cells .= wf_TableCell(__('Notes'));
  311. $cells .= wf_TableCell(__('Admin'));
  312. $rows = wf_TableRow($cells, 'row1');
  313. //address contains payments prefilter
  314. if (ubRouting::checkPost('type_address', 'payaddrcontains')) {
  315. $addressFilter = ubRouting::post('payaddrcontains', 'mres');
  316. if (!empty($allpayments)) {
  317. foreach ($allpayments as $io => $each) {
  318. $eachUserAddress = (isset($alladdress[$each['login']])) ? $alladdress[$each['login']] : '';
  319. if (!ispos($eachUserAddress, $addressFilter)) {
  320. unset($allpayments[$io]);
  321. }
  322. }
  323. }
  324. }
  325. if (!empty($allpayments)) {
  326. if ($altercfg['FINREP_TARIFF']) {
  327. $csvTariffColumn = ';' . __('Tariff');
  328. } else {
  329. $csvTariffColumn = '';
  330. }
  331. $csvdata .= __('ID') . ';' . __('Date') . ';' . __('Cash') . ';' . __('PS%') . ';' . __('Profit') . ';' . __('Login') . ';' . __('Full address') . ';' . __('Real Name') . $csvTariffColumn . ';' . __('Payment type') . ';' . __('Notes') . ';' . __('Admin') . "\n";
  332. foreach ($allpayments as $io => $each) {
  333. $cells = wf_TableCell($each['id']);
  334. $cells .= wf_TableCell($each['date']);
  335. $cells .= wf_TableCell($each['summ']);
  336. //detecting paymentsystem and calc percent
  337. if (isset($allpaysyspercents[$each['note']])) {
  338. $currPc = $allpaysyspercents[$each['note']]['percent'];
  339. $rawSumm = $each['summ'];
  340. $paySysPc = ($rawSumm / 100) * $currPc;
  341. $ourProfit = $rawSumm - $paySysPc;
  342. } else {
  343. $paySysPc = 0;
  344. $ourProfit = $each['summ'];
  345. }
  346. $cells .= wf_TableCell($paySysPc);
  347. $cells .= wf_TableCell($ourProfit);
  348. $cells .= wf_TableCell(wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], false, ''));
  349. if ($altercfg['FINREP_CONTRACT']) {
  350. $cells .= wf_TableCell(@$allcontracts[$each['login']]);
  351. }
  352. @$paymentRealname = $allrealnames[$each['login']];
  353. @$paymentCashType = __($alltypes[$each['cashtypeid']]);
  354. @$paymentAddress = $alladdress[$each['login']];
  355. ;
  356. $cells .= wf_TableCell($paymentAddress);
  357. $cells .= wf_TableCell($paymentRealname);
  358. if ($altercfg['FINREP_TARIFF']) {
  359. @$userTariff = $alltariffs[$each['login']];
  360. $cells .= wf_TableCell($userTariff);
  361. $csvTariff = ';' . $userTariff;
  362. } else {
  363. $csvTariff = '';
  364. }
  365. $cells .= wf_TableCell($paymentCashType);
  366. //payment notes translation
  367. if ($altercfg['TRANSLATE_PAYMENTS_NOTES']) {
  368. $paynote = zb_TranslatePaymentNote($each['note'], $allservicenames);
  369. } else {
  370. $paynote = $each['note'];
  371. }
  372. $cells .= wf_TableCell($paynote);
  373. $cells .= wf_TableCell($each['admin']);
  374. $rows .= wf_TableRow($cells, 'row3');
  375. //calculating totals
  376. if ($each['summ'] > 0) {
  377. $totalsumm = $totalsumm + $each['summ'];
  378. $totalcount++;
  379. }
  380. if ($paySysPc > 0) {
  381. $paysyssumm = $paysyssumm + $paySysPc;
  382. }
  383. if ($ourProfit > 0) {
  384. $profitsumm = $profitsumm + $ourProfit;
  385. }
  386. $csvSumm = str_replace('.', ',', $each['summ']);
  387. $csvdata .= $each['id'] . ';' . $each['date'] . ';' . $csvSumm . ';' . $paySysPc . ';' . $ourProfit . ';' . $each['login'] . ';' . $paymentAddress . ';' . $paymentRealname . $csvTariff . ';' . $paymentCashType . ';' . $paynote . ';' . $each['admin'] . "\n";
  388. }
  389. }
  390. //saving report for future download
  391. if (!empty($csvdata)) {
  392. $csvSaveName = 'exports/payfind_' . date("Y-m-d_H_i_s") . '.csv';
  393. $csvSaveNameEnc = base64_encode($csvSaveName);
  394. file_put_contents($csvSaveName, $csvdata);
  395. $csvDownloadLink = wf_Link('?module=payfind&downloadcsv=' . $csvSaveNameEnc, wf_img('skins/excel.gif', __('Export')), false);
  396. } else {
  397. $csvDownloadLink = '';
  398. }
  399. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  400. //additional total counters
  401. $result .= wf_tag('div', false, 'glamour') . __('Count') . ': ' . $totalcount . wf_tag('div', true);
  402. $result .= wf_tag('div', false, 'glamour') . __('Total payments') . ': ' . $totalsumm . wf_tag('div', true);
  403. $result .= wf_tag('div', false, 'glamour') . __('Payment systems %') . ': ' . $paysyssumm . wf_tag('div', true);
  404. $result .= wf_tag('div', false, 'glamour') . __('Our final profit') . ': ' . $profitsumm . wf_tag('div', true);
  405. $result .= wf_CleanDiv();
  406. show_window(__('Payments found') . ' ' . $csvDownloadLink, $result);
  407. }
  408. /*
  409. * Interfaces
  410. */
  411. if (!wf_CheckGet(array('confpaysys'))) {
  412. show_window(__('Payment search'), web_PayFindForm());
  413. zb_BillingStats(true);
  414. } else {
  415. show_window(__('Payment systems'), web_PaySysForm());
  416. }
  417. /*
  418. * Controller section
  419. */
  420. //downloading report as csv
  421. if (wf_CheckGet(array('downloadcsv'))) {
  422. zb_DownloadFile(base64_decode($_GET['downloadcsv']), 'excel');
  423. }
  424. //Payment systems configuration
  425. //adding payment system
  426. if (wf_CheckPost(array('newmarker', 'newname'))) {
  427. zb_PaySysPercentAdd($_POST['newmarker'], $_POST['newname'], $_POST['newpercent']);
  428. rcms_redirect("?module=payfind&confpaysys=true");
  429. }
  430. //removing payment system
  431. if (wf_CheckGet(array('delete'))) {
  432. zb_PaySysPercentDelete($_GET['delete']);
  433. rcms_redirect("?module=payfind&confpaysys=true");
  434. }
  435. //Search
  436. $markers = '';
  437. $joins = '';
  438. //date search
  439. if (wf_CheckPost(array('datefrom', 'dateto'))) {
  440. $datefrom = mysql_real_escape_string($_POST['datefrom']);
  441. $dateto = mysql_real_escape_string($_POST['dateto']);
  442. $markers .= "WHERE `date` BETWEEN '" . $datefrom . "' AND '" . $dateto . "' ";
  443. }
  444. //payment id search
  445. if (wf_CheckPost(array('type_payid', 'payid'))) {
  446. $payid = vf($_POST['payid'], 3);
  447. $markers .= "AND `id`='" . $payid . "' ";
  448. }
  449. //contract search
  450. if (wf_CheckPost(array('type_contract', 'contract'))) {
  451. $contract = mysql_real_escape_string($_POST['contract']);
  452. $allcontracts = zb_UserGetAllContracts();
  453. if (!empty($allcontracts)) {
  454. if (isset($allcontracts[$contract])) {
  455. $contractlogin = $allcontracts[$contract];
  456. $markers .= "AND `login`='" . $contractlogin . "' ";
  457. }
  458. }
  459. }
  460. //login payment search
  461. if (wf_CheckPost(array('type_login', 'login'))) {
  462. $userlogin = mysql_real_escape_string($_POST['login']);
  463. $markers .= "AND `login`='" . $userlogin . "' ";
  464. }
  465. //not strict login search
  466. if (wf_CheckPost(array('type_loginwildcard', 'loginwildcard'))) {
  467. $userloginW = mysql_real_escape_string($_POST['loginwildcard']);
  468. $markers .= "AND `login` LIKE '%" . $userloginW . "%' ";
  469. }
  470. //payment sum search
  471. if (wf_CheckPost(array('type_summ', 'summ'))) {
  472. $summ = mysql_real_escape_string($_POST['summ']);
  473. $markers .= "AND `summ`='" . $summ . "' ";
  474. }
  475. //cashtype search
  476. if (wf_CheckPost(array('type_cashtype', 'cashtype'))) {
  477. $cashtype = vf($_POST['cashtype'], 3);
  478. $markers .= "AND `cashtypeid`='" . $cashtype . "' ";
  479. }
  480. //cashiers search
  481. if (wf_CheckPost(array('type_cashier', 'cashier'))) {
  482. $cashierLogin = mysql_real_escape_string($_POST['cashier']);
  483. $markers .= "AND `admin`='" . $cashierLogin . "' ";
  484. }
  485. //payment system search
  486. if (wf_CheckPost(array('type_paysys', 'paysys'))) {
  487. $cashtype = mysql_real_escape_string($_POST['paysys']);
  488. $markers .= "AND `note` LIKE '" . $cashtype . "' ";
  489. }
  490. //only positive payments search
  491. if (isset($_POST['only_positive'])) {
  492. $markers .= "AND `summ` >'0' ";
  493. }
  494. //payments with numeric notes
  495. if (isset($_POST['numeric_notes'])) {
  496. $markers .= "AND `note` >0 ";
  497. }
  498. //payments only with numeric notes
  499. if (isset($_POST['numericonly_notes'])) {
  500. $markers .= "AND `note` REGEXP '^[0-9]+$' ";
  501. }
  502. //tagtype search
  503. if (wf_CheckPost(array('type_tagid', 'tagid'))) {
  504. $markers .= zb_PayFindExtractByTagId($_POST['tagid']);
  505. }
  506. //idenc search
  507. if (wf_CheckPost(array('type_payidenc', 'payidenc'))) {
  508. $payidenc = vf($_POST['payidenc']);
  509. $payidNormal = zb_NumUnEncode($payidenc);
  510. $markers .= "AND `id`='" . $payidNormal . "' ";
  511. }
  512. //summ is greater search
  513. if (wf_CheckPost(array('type_summgreater', 'paysummgreater'))) {
  514. $markers .= "AND `summ` > " . mysql_real_escape_string($_POST['paysummgreater']) . " ";
  515. }
  516. //payment notes contains search
  517. if (wf_CheckPost(array('type_notescontains', 'paynotescontains'))) {
  518. $notesMask = mysql_real_escape_string($_POST['paynotescontains']);
  519. $markers .= "AND `note` LIKE '%" . $notesMask . "%' ";
  520. }
  521. //filter by city
  522. if (wf_CheckPost(array('type_city', 'citysel'))) {
  523. $cityID = mysql_real_escape_string($_POST['citysel']);
  524. $joins .= " RIGHT JOIN (SELECT `address`.`login`,`city`.`cityname` FROM `address`
  525. INNER JOIN `apt` ON `address`.`aptid`= `apt`.`id`
  526. INNER JOIN `build` ON `apt`.`buildid`=`build`.`id`
  527. INNER JOIN `street` ON `build`.`streetid`=`street`.`id`
  528. INNER JOIN `city` ON `street`.`cityid`=`city`.`id`
  529. WHERE `city`.`id` = " . $cityID . ") AS `tmpCity` USING(`login`) ";
  530. }
  531. //filter by strict contragent assign
  532. if (wf_CheckPost(array('type_contragent', 'ahentsel'))) {
  533. $contragentID = mysql_real_escape_string($_POST['ahentsel']);
  534. $joins .= " RIGHT JOIN (SELECT `ahenassignstrict`.`login`,`ahenassignstrict`.`agentid` FROM `ahenassignstrict`
  535. WHERE `ahenassignstrict`.`agentid` = " . $contragentID . ") AS `tmpContragents` USING(`login`) ";
  536. }
  537. //executing search
  538. if (wf_CheckPost(array('dosearch'))) {
  539. web_PaymentSearch($markers, $joins);
  540. }
  541. } else {
  542. show_error(__('Access denied'));
  543. }