api.corps.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. <?php
  2. /**
  3. * Corporate aka enterprise users implementation
  4. */
  5. class Corps {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Display IBAN label instead of bank account in some forms/preview.
  14. *
  15. * @var bool
  16. */
  17. protected $ibanFlag = false;
  18. /**
  19. * Contains available corps to normal users bindings as login=>corpId
  20. *
  21. * @var array
  22. */
  23. protected $users = array();
  24. /**
  25. * Contains available corps as id=>corpData
  26. *
  27. * @var array
  28. */
  29. protected $corps = array();
  30. /**
  31. * Contains available corps contact persons as id=>personData
  32. *
  33. * @var array
  34. */
  35. protected $persons = array();
  36. /**
  37. * Contains existing tax types as id=>type
  38. *
  39. * @var array
  40. */
  41. protected $taxtypes = array();
  42. /**
  43. * Use bank/taxes field names for RF flag
  44. *
  45. * @var bool
  46. */
  47. protected $rfCorpsFlag = false;
  48. /**
  49. * Contains available document types
  50. *
  51. * @var array
  52. */
  53. protected $doctypes = array(
  54. '1' => 'Certificate',
  55. '2' => 'Regulations',
  56. '3' => 'Reference'
  57. );
  58. /**
  59. * Contains corps data database abstraction layer
  60. *
  61. * @var object
  62. */
  63. protected $corpsDb = '';
  64. /**
  65. * Contains taxtypes database abstraction layer
  66. *
  67. * @var object
  68. */
  69. protected $taxtypesDb = '';
  70. /**
  71. * Contains persons database abstraction layer
  72. *
  73. * @var object
  74. */
  75. protected $personsDb = '';
  76. /**
  77. * Contains users database abstraction layer
  78. *
  79. * @var object
  80. */
  81. protected $usersDb = '';
  82. /**
  83. * Some predefined module routing URLs
  84. */
  85. const ROUTE_PREFIX = 'show';
  86. const URL_TAXTYPE = 'taxtypes';
  87. const URL_TAXTYPE_LIST = '?module=corps&show=taxtypes';
  88. const URL_TAXTYPE_DEL = '?module=corps&show=taxtypes&deltaxtypeid=';
  89. const URL_CORPS = 'corps';
  90. const URL_CORPS_LIST = '?module=corps&show=corps';
  91. const URL_SEARCH = 'search';
  92. const URL_CORPS_SEARCH = '?module=corps&show=search';
  93. const URL_CORPS_EDIT = '?module=corps&show=corps&editid=';
  94. const URL_CORPS_ADD = '?module=corps&show=corps&add=true';
  95. const URL_CORPS_DEL = '?module=corps&show=corps&deleteid=';
  96. const URL_USER = 'user';
  97. const URL_USER_MANAGE = '?module=corps&show=user&username=';
  98. const URL_AJDT = 'ajax';
  99. //some datasources here
  100. const TABLE_DATA = 'corp_data';
  101. const TABLE_TAXTYPES = 'corp_taxtypes';
  102. const TABLE_PERSONS = 'corp_persons';
  103. const TABLE_USERS = 'corp_users';
  104. /**
  105. * Creates new corps object instance
  106. */
  107. public function __construct() {
  108. $this->loadConfigs();
  109. $this->initDb();
  110. $this->loadUsers();
  111. $this->loadCorps();
  112. $this->loadPersons();
  113. $this->loadTaxtypes();
  114. }
  115. /**
  116. * Loads required configs and sets some object properties
  117. *
  118. * @global object $ubillingConfig
  119. *
  120. * @return void
  121. */
  122. protected function loadConfigs() {
  123. global $ubillingConfig;
  124. $this->altCfg = $ubillingConfig->getAlter();
  125. if (@$this->altCfg['IBAN_ENABLED']) {
  126. $this->ibanFlag = true;
  127. }
  128. if (@$this->altCfg['RFCORPS']) {
  129. $this->rfCorpsFlag = true;
  130. }
  131. if (@$this->altCfg['CORPS_ADDT']) {
  132. $rawTypes = explode(',', $this->altCfg['CORPS_ADDT']);
  133. if (!empty($rawTypes)) {
  134. foreach ($rawTypes as $io => $eachDt) {
  135. $this->doctypes[] = $eachDt;
  136. }
  137. }
  138. }
  139. }
  140. /**
  141. * Inits all required database abstraction layers
  142. *
  143. * @return void
  144. */
  145. protected function initDb() {
  146. $this->corpsDb = new NyanORM(self::TABLE_DATA);
  147. $this->taxtypesDb = new NyanORM(self::TABLE_TAXTYPES);
  148. $this->personsDb = new NyanORM(self::TABLE_PERSONS);
  149. $this->usersDb = new NyanORM(self::TABLE_USERS);
  150. }
  151. /**
  152. * loads available corps from database into private prop
  153. *
  154. * @return void
  155. */
  156. protected function loadCorps() {
  157. $this->corpsDb->orderBy('id', 'DESC');
  158. $this->corps = $this->corpsDb->getAll('id');
  159. }
  160. /**
  161. * loads taxtypes from database
  162. *
  163. * @return void
  164. */
  165. protected function loadTaxtypes() {
  166. $all = $this->taxtypesDb->getAll();
  167. if (!empty($all)) {
  168. foreach ($all as $io => $each) {
  169. $this->taxtypes[$each['id']] = $each['type'];
  170. }
  171. }
  172. }
  173. /**
  174. * loads contact persons from database
  175. *
  176. * @return void
  177. */
  178. protected function loadPersons() {
  179. $this->persons = $this->personsDb->getAll('id');
  180. }
  181. /**
  182. * loads user bindings from database and store it into private prop users
  183. *
  184. * @return void
  185. */
  186. protected function loadUsers() {
  187. $all = $this->usersDb->getAll();
  188. if (!empty($all)) {
  189. foreach ($all as $io => $each) {
  190. $this->users[$each['login']] = $each['corpid'];
  191. }
  192. }
  193. }
  194. /**
  195. * returns existing taxtype edit form
  196. *
  197. * @param $id int existing tax type ID
  198. *
  199. * @return string
  200. */
  201. protected function taxtypeEditForm($id) {
  202. $id = ubRouting::filters($id, 'int');
  203. $result = '';
  204. if (isset($this->taxtypes[$id])) {
  205. $taxtypename = $this->taxtypes[$id];
  206. $taxtypename = htmlspecialchars($taxtypename);
  207. $inputs = wf_HiddenInput('edittaxtypeid', $id);
  208. $inputs .= wf_TextInput('edittaxtype', __('Type'), $taxtypename, true, '40');
  209. $inputs .= wf_Submit(__('Save'));
  210. $result = wf_Form("", 'POST', $inputs, 'glamour');
  211. } else {
  212. $result = __('Not existing item');
  213. }
  214. return ($result);
  215. }
  216. /**
  217. * returns new taxtype creation form
  218. *
  219. * @return string
  220. */
  221. protected function taxtypeCreateForm() {
  222. $inputs = wf_TextInput('newtaxtype', __('Type'), '', true, '40');
  223. $inputs .= wf_Submit(__('Create'));
  224. $result = wf_Form("", 'POST', $inputs, 'glamour');
  225. return ($result);
  226. }
  227. /**
  228. * creates new taxtype
  229. *
  230. * @param $type string new taxtype
  231. *
  232. * @return void
  233. */
  234. public function taxtypeCreate($type) {
  235. $type = ubRouting::filters($type, 'mres');
  236. $this->taxtypesDb->data('type', $type);
  237. $this->taxtypesDb->create();
  238. $newId = $this->taxtypesDb->getLastId();
  239. log_register('CORPS CREATE TAXTYPE [' . $newId . ']');
  240. }
  241. /**
  242. * returns standard localized deletion alert
  243. *
  244. * @return string
  245. */
  246. protected function alertDelete() {
  247. return (__('Removing this may lead to irreparable results'));
  248. }
  249. /**
  250. * return existing taxtypes list with edit controls
  251. *
  252. * @return string
  253. */
  254. public function taxtypesList() {
  255. $cells = wf_TableCell(__('ID'));
  256. $cells .= wf_TableCell(__('Type'));
  257. $cells .= wf_TableCell(__('Actions'));
  258. $rows = wf_TableRow($cells, 'row1');
  259. if (!empty($this->taxtypes)) {
  260. foreach ($this->taxtypes as $id => $type) {
  261. $cells = wf_TableCell($id);
  262. $cells .= wf_TableCell($type);
  263. $actlinks = wf_JSAlert(self::URL_TAXTYPE_DEL . $id, web_delete_icon(), $this->alertDelete());
  264. $actlinks .= wf_modal(web_edit_icon(), __('Edit'), $this->taxtypeEditForm($id), '', '450', '150');
  265. $cells .= wf_TableCell($actlinks);
  266. $rows .= wf_TableRow($cells, 'row3');
  267. }
  268. }
  269. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  270. $result .= wf_modal(wf_img('skins/icon_add.gif') . ' ' . __('Create'), __('Create'), $this->taxtypeCreateForm(), 'ubButton', '450', '150');
  271. return ($result);
  272. }
  273. /**
  274. * deletes existing tax type from database
  275. *
  276. * @return void
  277. */
  278. public function taxtypeDelete($id) {
  279. $id = ubRouting::filters($id, 'int');
  280. if (isset($this->taxtypes[$id])) {
  281. $this->taxtypesDb->where('id', '=', $id);
  282. $this->taxtypesDb->delete();
  283. log_register('CORPS DELETE TAXTYPE [' . $id . ']');
  284. }
  285. }
  286. /**
  287. * edits existing tax type
  288. *
  289. * @param $id int existing taxtype ID
  290. * @param $type new taxtype description
  291. *
  292. * @return void
  293. */
  294. public function taxtypeEdit($id, $type) {
  295. $id = ubRouting::filters($id, 'int');
  296. if (isset($this->taxtypes[$id])) {
  297. $this->taxtypesDb->data('type', $type);
  298. $this->taxtypesDb->where('id', '=', $id);
  299. $this->taxtypesDb->save();
  300. log_register('CORPS EDIT TAXTYPE [' . $id . ']');
  301. }
  302. }
  303. /**
  304. * list available corps list container
  305. *
  306. * @return string
  307. */
  308. public function corpsList() {
  309. $result = '';
  310. $columns = array('ID', 'Corp name', 'Address', 'Document type', 'Document date', 'Tax payer status', 'Actions');
  311. $ajUrl = self::URL_CORPS_LIST . '&' . self::URL_AJDT . '=true';
  312. $result .= wf_JqDtLoader($columns, $ajUrl, false, __('Corporate users'), 50, '"order": [[ 0, "desc" ]]');
  313. return($result);
  314. }
  315. /**
  316. * list available corps JSON data with some controls
  317. *
  318. * @return void
  319. */
  320. public function corpsListAjax() {
  321. $json = new wf_JqDtHelper();
  322. if (!empty($this->corps)) {
  323. foreach ($this->corps as $io => $each) {
  324. if (isset($this->doctypes[$each['doctype']])) {
  325. $doctype = __($this->doctypes[$each['doctype']]);
  326. } else {
  327. $doctype = $each['doctype'];
  328. }
  329. if (isset($this->taxtypes[$each['taxtype']])) {
  330. $taxtype = $this->taxtypes[$each['taxtype']];
  331. } else {
  332. $taxtype = $each['taxtype'];
  333. }
  334. $actlinks = wf_JSAlert(self::URL_CORPS_DEL . $each['id'], web_delete_icon(), $this->alertDelete()) . ' ';
  335. $actlinks .= wf_JSAlert(self::URL_CORPS_EDIT . $each['id'], web_edit_icon(), __('Are you serious')) . ' ';
  336. $actlinks .= wf_modal(wf_img('skins/icon_search_small.gif', __('Preview')), $each['corpname'], $this->corpPreview($each['id']), '', '800', '600');
  337. $data[] = $each['id'];
  338. $data[] = $each['corpname'];
  339. $data[] = $each['address'];
  340. $data[] = $doctype;
  341. $data[] = $each['docdate'];
  342. $data[] = $taxtype;
  343. $data[] = $actlinks;
  344. $json->addRow($data);
  345. unset($data);
  346. }
  347. }
  348. $json->getJson();
  349. }
  350. /**
  351. * show existing corp preview
  352. *
  353. * @param $id int existing corp ID
  354. *
  355. * @return string
  356. */
  357. public function corpPreview($id) {
  358. $id = ubRouting::filters($id, 'int');
  359. $result = '';
  360. if (isset($this->corps[$id])) {
  361. $cells = wf_TableCell(__('Corp name'), '', 'row2');
  362. $cells .= wf_TableCell($this->corps[$id]['corpname']);
  363. $rows = wf_TableRow($cells, 'row3');
  364. $cells = wf_TableCell(__('Address'), '', 'row2');
  365. $cells .= wf_TableCell($this->corps[$id]['address']);
  366. $rows .= wf_TableRow($cells, 'row3');
  367. $cells = wf_TableCell(__('Document type'), '', 'row2');
  368. if (isset($this->doctypes[$this->corps[$id]['doctype']])) {
  369. $doctype = __($this->doctypes[$this->corps[$id]['doctype']]);
  370. } else {
  371. $doctype = $this->corps[$id]['doctype'];
  372. }
  373. $cells .= wf_TableCell($doctype);
  374. $rows .= wf_TableRow($cells, 'row3');
  375. $cells = wf_TableCell(__('Document number'), '', 'row2');
  376. $cells .= wf_TableCell($this->corps[$id]['docnum']);
  377. $rows .= wf_TableRow($cells, 'row3');
  378. $cells = wf_TableCell(__('Document date'), '', 'row2');
  379. $cells .= wf_TableCell($this->corps[$id]['docdate']);
  380. $rows .= wf_TableRow($cells, 'row3');
  381. $bankAccLabel = ($this->ibanFlag) ? __('IBAN') : __('Bank account');
  382. $cells = wf_TableCell($bankAccLabel, '', 'row2');
  383. $cells .= wf_TableCell($this->corps[$id]['bankacc']);
  384. $rows .= wf_TableRow($cells, 'row3');
  385. $cells = wf_TableCell(__('Bank name'), '', 'row2');
  386. $cells .= wf_TableCell($this->corps[$id]['bankname']);
  387. $rows .= wf_TableRow($cells, 'row3');
  388. $mfoLabel = (!$this->rfCorpsFlag) ? __('Bank MFO') : __('Bank BIK');
  389. $edrpouLabel = (!$this->rfCorpsFlag) ? __('EDRPOU') : __('OGRN');
  390. $ndsNumLabel = (!$this->rfCorpsFlag) ? __('NDS number') : __('INN Number');
  391. $innCodeLabel = (!$this->rfCorpsFlag) ? __('INN code') : __('KPP Code');
  392. $cells = wf_TableCell($mfoLabel, '', 'row2');
  393. $cells .= wf_TableCell($this->corps[$id]['bankmfo']);
  394. $rows .= wf_TableRow($cells, 'row3');
  395. $cells = wf_TableCell($edrpouLabel, '', 'row2');
  396. $cells .= wf_TableCell($this->corps[$id]['edrpou']);
  397. $rows .= wf_TableRow($cells, 'row3');
  398. $cells = wf_TableCell($ndsNumLabel, '', 'row2');
  399. $cells .= wf_TableCell($this->corps[$id]['ndstaxnum']);
  400. $rows .= wf_TableRow($cells, 'row3');
  401. $cells = wf_TableCell($innCodeLabel, '', 'row2');
  402. $cells .= wf_TableCell($this->corps[$id]['inncode']);
  403. $rows .= wf_TableRow($cells, 'row3');
  404. $cells = wf_TableCell(__('Tax type'), '', 'row2');
  405. if (isset($this->taxtypes[$this->corps[$id]['taxtype']])) {
  406. $taxtype = $this->taxtypes[$this->corps[$id]['taxtype']];
  407. } else {
  408. $taxtype = $this->corps[$id]['taxtype'];
  409. }
  410. $cells .= wf_TableCell($taxtype);
  411. $rows .= wf_TableRow($cells, 'row3');
  412. $cells = wf_TableCell(__('Short name'), '', 'row2');
  413. $cells .= wf_TableCell($this->corps[$id]['corpnameabbr']);
  414. $rows .= wf_TableRow($cells, 'row3');
  415. $cells = wf_TableCell(__('Signatory'), '', 'row2');
  416. $cells .= wf_TableCell($this->corps[$id]['corpsignatory']);
  417. $rows .= wf_TableRow($cells, 'row3');
  418. $cells = wf_TableCell(__('Signatory') . ' 2', '', 'row2');
  419. $cells .= wf_TableCell($this->corps[$id]['corpsignatory2']);
  420. $rows .= wf_TableRow($cells, 'row3');
  421. $cells = wf_TableCell(__('Basis'), '', 'row2');
  422. $cells .= wf_TableCell($this->corps[$id]['corpbasis']);
  423. $rows .= wf_TableRow($cells, 'row3');
  424. $cells = wf_TableCell(__('Email'), '', 'row2');
  425. $cells .= wf_TableCell($this->corps[$id]['corpemail']);
  426. $rows .= wf_TableRow($cells, 'row3');
  427. $cells = wf_TableCell(__('Notes'), '', 'row2');
  428. $cells .= wf_TableCell($this->corps[$id]['notes']);
  429. $rows .= wf_TableRow($cells, 'row3');
  430. $result = wf_TableBody($rows, '100%', '0');
  431. $result .= $this->corpListUsers($id);
  432. $result .= $this->personsList($id);
  433. } else {
  434. $result = __('Not existing item');
  435. }
  436. return ($result);
  437. }
  438. /**
  439. * returns selector of existing doctypes
  440. *
  441. * @param $name string input name
  442. *
  443. * @return string
  444. */
  445. protected function doctypeSelector($name, $selected = '') {
  446. $doctypes = array();
  447. if (!empty($this->doctypes)) {
  448. foreach ($this->doctypes as $id => $type) {
  449. $doctypes[$id] = __($type);
  450. }
  451. }
  452. $result = wf_Selector($name, $doctypes, __('Document type'), $selected, false);
  453. return ($result);
  454. }
  455. /**
  456. * returns list of users which linked with this corp
  457. *
  458. * @param $id int Existing corp ID
  459. *
  460. * @return string
  461. */
  462. protected function corpListUsers($id) {
  463. $id = ubRouting::filters($id, 'int');
  464. $result = '';
  465. $userArr = array();
  466. if (isset($this->corps[$id])) {
  467. if (!empty($this->users)) {
  468. foreach ($this->users as $login => $corpid) {
  469. if ($corpid == $id) {
  470. $userArr[$login] = $login;
  471. }
  472. }
  473. if (!empty($userArr)) {
  474. $result .= wf_tag('b') . __('Linked users') . ': ' . wf_tag('b', true);
  475. foreach ($userArr as $eachlogin) {
  476. $result .= wf_Link('?module=userprofile&username=' . $eachlogin, web_profile_icon() . ' ' . $eachlogin, false, '') . ' ';
  477. }
  478. $result .= wf_delimiter();
  479. }
  480. }
  481. }
  482. return ($result);
  483. }
  484. /**
  485. * filter array for unacceptable entities
  486. *
  487. * @param $data array Data array for escaping
  488. *
  489. * @return array
  490. */
  491. protected function filterArray($data) {
  492. $result = array();
  493. if (!empty($data)) {
  494. foreach ($data as $key => $value) {
  495. $result[$key] = htmlspecialchars($value);
  496. }
  497. }
  498. return ($result);
  499. }
  500. /**
  501. * returns corp edit form
  502. *
  503. * @param $id existing corp ID
  504. *
  505. * @return string
  506. */
  507. public function corpEditForm($id) {
  508. $id = ubRouting::filters($id, 'int');
  509. $result = '';
  510. if (isset($this->corps[$id])) {
  511. $data = $this->corps[$id];
  512. $data = $this->filterArray($data);
  513. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  514. $inputs = wf_HiddenInput('editcorpid', $id);
  515. $inputs .= wf_TextInput('editcorpname', __('Corp name') . $sup, $data['corpname'], true, '40');
  516. $inputs .= wf_TextInput('editcoraddress', __('Address'), $data['address'], true, '40');
  517. $inputs .= $this->doctypeSelector('editdoctype', $data['doctype']);
  518. $inputs .= wf_DatePickerPreset('editdocdate', $data['docdate'], true) . ' ' . __('Document date') . wf_tag('br');
  519. $inputs .= wf_TextInput('editdocnum', __('Document number'), $data['docnum'], true, '20');
  520. $bankAccLabel = ($this->ibanFlag) ? __('IBAN') : __('Bank account');
  521. $inputs .= wf_TextInput('editbankacc', $bankAccLabel, $data['bankacc'], true, '20');
  522. $inputs .= wf_TextInput('editbankname', __('Bank name'), $data['bankname'], true, '20');
  523. $mfoLabel = (!$this->rfCorpsFlag) ? __('Bank MFO') : __('Bank BIK');
  524. $edrpouLabel = (!$this->rfCorpsFlag) ? __('EDRPOU') : __('OGRN');
  525. $ndsNumLabel = (!$this->rfCorpsFlag) ? __('NDS number') : __('INN Number');
  526. $innCodeLabel = (!$this->rfCorpsFlag) ? __('INN code') : __('KPP Code');
  527. $inputs .= wf_TextInput('editbankmfo', $mfoLabel, $data['bankmfo'], true, '20');
  528. $inputs .= wf_TextInput('editedrpou', $edrpouLabel, $data['edrpou'], true, '20');
  529. $inputs .= wf_TextInput('editndstaxnum', $ndsNumLabel, $data['ndstaxnum'], true, '20');
  530. $inputs .= wf_TextInput('editinncode', $innCodeLabel, $data['inncode'], true, '20');
  531. $inputs .= wf_Selector('edittaxtype', $this->taxtypes, __('Tax type'), $data['taxtype'], true);
  532. $inputs .= wf_TextInput('editcorpnameabbr', __('Short name'), $data['corpnameabbr'], true, '20');
  533. $inputs .= wf_TextInput('editcorpsignatory', __('Signatory'), $data['corpsignatory'], true, '20');
  534. $inputs .= wf_TextInput('editcorpsignatory2', __('Signatory') . ' 2', $data['corpsignatory2'], true, '20');
  535. $inputs .= wf_TextInput('editcorpbasis', __('Basis'), $data['corpbasis'], true, '20');
  536. $inputs .= wf_TextInput('editcorpemail', __('Email'), $data['corpemail'], true, '20');
  537. $inputs .= wf_TextInput('editnotes', __('Notes'), $data['notes'], true, '40');
  538. $inputs .= wf_Submit(__('Save'));
  539. $result = wf_Form('', 'POST', $inputs, 'glamour');
  540. //contact persons editor
  541. $result .= $this->personsControl($id);
  542. } else {
  543. $result = __('Not existing item');
  544. }
  545. return ($result);
  546. }
  547. /**
  548. * Returns corp creation form
  549. *
  550. * @return string
  551. */
  552. public function corpCreateForm() {
  553. if (!empty($this->taxtypes)) {
  554. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  555. $inputs = wf_HiddenInput('createcorpid', 'true');
  556. $inputs .= wf_TextInput('createcorpname', __('Corp name') . $sup, '', true, '40');
  557. $inputs .= wf_TextInput('createaddress', __('Address'), '', true, '40');
  558. $inputs .= $this->doctypeSelector('createdoctype', '');
  559. $inputs .= wf_DatePickerPreset('createdocdate', curdate(), true) . ' ' . __('Document date') . wf_tag('br');
  560. $inputs .= wf_TextInput('adddocnum', __('Document number'), '', true, '20');
  561. $bankAccLabel = ($this->ibanFlag) ? __('IBAN') : __('Bank account');
  562. $inputs .= wf_TextInput('addbankacc', $bankAccLabel, '', true, '20');
  563. $inputs .= wf_TextInput('addbankname', __('Bank name'), '', true, '20');
  564. $mfoLabel = (!$this->rfCorpsFlag) ? __('Bank MFO') : __('Bank BIK');
  565. $edrpouLabel = (!$this->rfCorpsFlag) ? __('EDRPOU') : __('OGRN');
  566. $ndsNumLabel = (!$this->rfCorpsFlag) ? __('NDS number') : __('INN Number');
  567. $innCodeLabel = (!$this->rfCorpsFlag) ? __('INN code') : __('KPP Code');
  568. $inputs .= wf_TextInput('addbankmfo', $mfoLabel, '', true, '20');
  569. $inputs .= wf_TextInput('addedrpou', $edrpouLabel, '', true, '20');
  570. $inputs .= wf_TextInput('addndstaxnum', $ndsNumLabel, '', true, '20');
  571. $inputs .= wf_TextInput('addinncode', $innCodeLabel, '', true, '20');
  572. $inputs .= wf_Selector('addtaxtype', $this->taxtypes, __('Tax type'), '', true);
  573. $inputs .= wf_TextInput('addcorpnameabbr', __('Short name'), '', true, '20');
  574. $inputs .= wf_TextInput('addcorpsignatory', __('Signatory'), '', true, '20');
  575. $inputs .= wf_TextInput('addcorpsignatory2', __('Signatory') . ' 2', '', true, '20');
  576. $inputs .= wf_TextInput('addcorpbasis', __('Basis'), '', true, '20');
  577. $inputs .= wf_TextInput('addcorpemail', __('Email'), '', true, '20');
  578. $inputs .= wf_TextInput('addnotes', __('Notes'), '', true, '40');
  579. $inputs .= wf_Submit(__('Create'));
  580. $result = wf_Form('', 'POST', $inputs, 'glamour');
  581. } else {
  582. $result = __('No existing tax types');
  583. }
  584. return ($result);
  585. }
  586. /**
  587. * deletes existing corp by ID
  588. *
  589. * @param $id int existing corp ID
  590. *
  591. * @return void
  592. */
  593. public function corpDelete($id) {
  594. $id = ubRouting::filters($id, 'int');
  595. if (isset($this->corps[$id])) {
  596. $this->corpsDb->where('id', '=', $id);
  597. $this->corpsDb->delete();
  598. log_register('CORPS DELETE CORP [' . $id . ']');
  599. }
  600. }
  601. /**
  602. * edits corp in database
  603. *
  604. * @param $id int existing corp ID
  605. *
  606. * @return void
  607. */
  608. public function corpSave($id) {
  609. $id = ubRouting::filters($id, 'int');
  610. if (isset($this->corps[$id])) {
  611. $this->corpsDb->data('corpname', ubRouting::post('editcorpname', 'mres'));
  612. $this->corpsDb->data('address', ubRouting::post('editcoraddress', 'mres'));
  613. $this->corpsDb->data('doctype', ubRouting::post('editdoctype', 'mres'));
  614. $this->corpsDb->data('docdate', ubRouting::post('editdocdate', 'mres'));
  615. $this->corpsDb->data('docnum', ubRouting::post('editdocnum', 'mres'));
  616. $this->corpsDb->data('bankacc', ubRouting::post('editbankacc', 'mres'));
  617. $this->corpsDb->data('bankname', ubRouting::post('editbankname', 'mres'));
  618. $this->corpsDb->data('bankmfo', ubRouting::post('editbankmfo', 'mres'));
  619. $this->corpsDb->data('edrpou', ubRouting::post('editedrpou', 'mres'));
  620. $this->corpsDb->data('ndstaxnum', ubRouting::post('editndstaxnum', 'mres'));
  621. $this->corpsDb->data('inncode', ubRouting::post('editinncode', 'mres'));
  622. $this->corpsDb->data('taxtype', ubRouting::post('edittaxtype', 'mres'));
  623. $this->corpsDb->data('notes', ubRouting::post('editnotes', 'mres'));
  624. $this->corpsDb->data('corpnameabbr', ubRouting::post('editcorpnameabbr', 'mres'));
  625. $this->corpsDb->data('corpsignatory', ubRouting::post('editcorpsignatory', 'mres'));
  626. $this->corpsDb->data('corpsignatory2', ubRouting::post('editcorpsignatory2', 'mres'));
  627. $this->corpsDb->data('corpbasis', ubRouting::post('editcorpbasis', 'mres'));
  628. $this->corpsDb->data('corpemail', ubRouting::post('editcorpemail', 'mres'));
  629. $this->corpsDb->where('id', '=', $id);
  630. $this->corpsDb->save();
  631. log_register('CORPS EDIT CORP [' . $id . ']');
  632. }
  633. }
  634. /**
  635. * Creates new corp in database
  636. *
  637. * @return int
  638. */
  639. public function corpCreate() {
  640. $corpname = ubRouting::post('createcorpname', 'mres');
  641. $address = ubRouting::post('createaddress', 'mres');
  642. $doctype = ubRouting::post('createdoctype', 'int');
  643. $docdate = ubRouting::post('createdocdate', 'mres');
  644. $docnum = ubRouting::post('adddocnum', 'mres');
  645. $bankacc = ubRouting::post('addbankacc', 'mres');
  646. $bankname = ubRouting::post('addbankname', 'mres');
  647. $bankmfo = ubRouting::post('addbankmfo', 'mres');
  648. $edrpou = ubRouting::post('addedrpou', 'mres');
  649. $taxnum = ubRouting::post('addndstaxnum', 'mres');
  650. $inncode = ubRouting::post('addinncode', 'mres');
  651. $taxtype = ubRouting::post('addtaxtype', 'int');
  652. $notes = ubRouting::post('addnotes', 'mres');
  653. $corpnameabbr = ubRouting::post('addcorpnameabbr', 'mres');
  654. $corpsignatory = ubRouting::post('addcorpsignatory', 'mres');
  655. $corpsignatory2 = ubRouting::post('addcorpsignatory2', 'mres');
  656. $corpbasis = ubRouting::post('addcorpbasis', 'mres');
  657. $corpemail = ubRouting::post('addcorpemail', 'mres');
  658. $this->corpsDb->data('corpname', $corpname);
  659. $this->corpsDb->data('address', $address);
  660. $this->corpsDb->data('doctype', $doctype);
  661. $this->corpsDb->data('docnum', $docnum);
  662. $this->corpsDb->data('docdate', $docdate);
  663. $this->corpsDb->data('bankacc', $bankacc);
  664. $this->corpsDb->data('bankname', $bankname);
  665. $this->corpsDb->data('bankmfo', $bankmfo);
  666. $this->corpsDb->data('edrpou', $edrpou);
  667. $this->corpsDb->data('ndstaxnum', $taxnum);
  668. $this->corpsDb->data('inncode', $inncode);
  669. $this->corpsDb->data('taxtype', $taxtype);
  670. $this->corpsDb->data('notes', $notes);
  671. $this->corpsDb->data('corpnameabbr', $corpnameabbr);
  672. $this->corpsDb->data('corpsignatory', $corpsignatory);
  673. $this->corpsDb->data('corpsignatory2', $corpsignatory2);
  674. $this->corpsDb->data('corpbasis', $corpbasis);
  675. $this->corpsDb->data('corpemail', $corpemail);
  676. $this->corpsDb->create();
  677. $newID = $this->corpsDb->getLastId();
  678. log_register('CORPS CREATE CORP [' . $newID . ']');
  679. return ($newID);
  680. }
  681. /**
  682. * returns corps link panel
  683. *
  684. * @return string
  685. */
  686. public function corpsPanel() {
  687. $result = wf_Link(self::URL_CORPS_ADD, wf_img('skins/icon_add.gif') . ' ' . __('Create'), false, 'ubButton');
  688. $result .= wf_Link(self::URL_CORPS_LIST, wf_img('skins/icon_search_small.gif') . ' ' . __('Available corps'), false, 'ubButton');
  689. $result .= wf_Link(self::URL_TAXTYPE_LIST, wf_img('skins/icon_dollar.gif') . ' ' . __('Available tax types'), false, 'ubButton');
  690. return ($result);
  691. }
  692. /**
  693. * returns contact persons list for some corp
  694. *
  695. * @param $corpid int Existing corp ID
  696. *
  697. * @return string
  698. */
  699. protected function personsList($corpid) {
  700. $corpid = ubRouting::filters($corpid, 'int');
  701. $result = '';
  702. if (!empty($this->persons)) {
  703. $cells = wf_TableCell(__('ID'));
  704. $cells .= wf_TableCell(__('Real Name'));
  705. $cells .= wf_TableCell(__('Phone'));
  706. $cells .= wf_TableCell(__('IM'));
  707. $cells .= wf_TableCell(__('Email'));
  708. $cells .= wf_TableCell(__('Appointment'));
  709. $rows = wf_TableRow($cells, 'row1');
  710. foreach ($this->persons as $io => $each) {
  711. if ($each['corpid'] == $corpid) {
  712. $cells = wf_TableCell($each['id']);
  713. $cells .= wf_TableCell($each['realname']);
  714. $cells .= wf_TableCell($each['phone']);
  715. $cells .= wf_TableCell($each['im']);
  716. $cells .= wf_TableCell($each['email']);
  717. $cells .= wf_TableCell($each['appointment']);
  718. $rows .= wf_TableRow($cells, 'row3');
  719. }
  720. }
  721. $result .= wf_tag('b') . __('Contact persons') . wf_tag('b', true);
  722. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  723. }
  724. return ($result);
  725. }
  726. /**
  727. * returns contact persons edit control for some corp
  728. *
  729. * @param $corpid int Existing corp ID
  730. *
  731. * @return string
  732. */
  733. protected function personsControl($corpid) {
  734. $corpid = ubRouting::filters($corpid, 'int');
  735. $result = '';
  736. if (!empty($this->persons)) {
  737. $cells = wf_TableCell(__('ID'));
  738. $cells .= wf_TableCell(__('Real Name'));
  739. $cells .= wf_TableCell(__('Phone'));
  740. $cells .= wf_TableCell(__('IM'));
  741. $cells .= wf_TableCell(__('Email'));
  742. $cells .= wf_TableCell(__('Appointment'));
  743. $cells .= wf_TableCell(__('Actions'));
  744. $rows = wf_TableRow($cells, 'row1');
  745. foreach ($this->persons as $io => $each) {
  746. if ($each['corpid'] == $corpid) {
  747. $cells = wf_TableCell($each['id']);
  748. $cells .= wf_TableCell($each['realname']);
  749. $cells .= wf_TableCell($each['phone']);
  750. $cells .= wf_TableCell($each['im']);
  751. $cells .= wf_TableCell($each['email']);
  752. $cells .= wf_TableCell($each['appointment']);
  753. $actLinks = wf_JSAlert(self::URL_CORPS_EDIT . $corpid . '&deletepersonid=' . $each['id'], web_delete_icon(), $this->alertDelete());
  754. $actLinks .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->personEditForm($each['id']), '');
  755. $cells .= wf_TableCell($actLinks);
  756. $rows .= wf_TableRow($cells, 'row3');
  757. }
  758. }
  759. $result .= wf_tag('b') . __('Contact persons') . wf_tag('b', true);
  760. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  761. }
  762. return ($result);
  763. }
  764. /**
  765. * returns conact person creation form
  766. *
  767. * @param $corpid int existing corp ID
  768. *
  769. * @return string
  770. */
  771. public function personCreateForm($corpid) {
  772. $corpid = ubRouting::filters($corpid, 'int');
  773. $result = '';
  774. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  775. if (isset($this->corps[$corpid])) {
  776. $inputs = wf_HiddenInput('addpersoncorpid', $corpid);
  777. $inputs .= wf_TextInput('addpersonrealname', __('Real Name') . $sup, '', true, '20');
  778. $inputs .= wf_TextInput('addpersonphone', __('Phone'), '', true, '20');
  779. $inputs .= wf_TextInput('addpersonim', __('Instant messenger (Skype, ICQ, Jabber, etc)'), '', true, '20');
  780. $inputs .= wf_TextInput('addpersonemail', __('Email'), '', true, '20');
  781. $inputs .= wf_TextInput('addpersonappointment', __('Appointment'), '', true, '30');
  782. $inputs .= wf_TextArea('addpersonnotes', __('Notes'), '', true, '30x3');
  783. $inputs .= wf_Submit(__('Create'));
  784. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  785. } else {
  786. $result = __('Not existing item');
  787. }
  788. return ($result);
  789. }
  790. /**
  791. * returns conact person creation form
  792. *
  793. * @param $id int existing contact person ID
  794. *
  795. * @return string
  796. */
  797. protected function personEditForm($id) {
  798. $id = ubRouting::filters($id, 'int');
  799. $result = '';
  800. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  801. if (isset($this->persons[$id])) {
  802. $data = $this->persons[$id];
  803. $data = $this->filterArray($data);
  804. $inputs = wf_HiddenInput('editpersonid', $id);
  805. $inputs .= wf_TextInput('editpersonrealname', __('Real Name') . $sup, $data['realname'], true, '20');
  806. $inputs .= wf_TextInput('editpersonphone', __('Phone'), $data['phone'], true, '20');
  807. $inputs .= wf_TextInput('editpersonim', __('Instant messenger (Skype, ICQ, Jabber, etc)'), $data['im'], true, '20');
  808. $inputs .= wf_TextInput('editpersonemail', __('Email'), $data['email'], true, '20');
  809. $inputs .= wf_TextInput('editpersonappointment', __('Appointment'), $data['appointment'], true, '30');
  810. $inputs .= wf_TextArea('editpersonnotes', __('Notes'), $data['notes'], true, '30x3');
  811. $inputs .= wf_Submit(__('Save'));
  812. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  813. } else {
  814. $result = __('Not existing item');
  815. }
  816. return ($result);
  817. }
  818. /**
  819. * edits contact person in database
  820. *
  821. * @param $id int existing contact person ID
  822. *
  823. * @return void
  824. */
  825. public function personSave($id) {
  826. $id = ubRouting::filters($id, 'int');
  827. if (isset($this->persons[$id])) {
  828. $this->personsDb->data('realname', ubRouting::post('editpersonrealname', 'mres'));
  829. $this->personsDb->data('phone', ubRouting::post('editpersonphone', 'mres'));
  830. $this->personsDb->data('im', ubRouting::post('editpersonim', 'mres'));
  831. $this->personsDb->data('email', ubRouting::post('editpersonemail', 'mres'));
  832. $this->personsDb->data('appointment', ubRouting::post('editpersonappointment', 'mres'));
  833. $this->personsDb->data('notes', ubRouting::post('editpersonnotes', 'mres'));
  834. $this->personsDb->where('id', '=', $id);
  835. $this->personsDb->save();
  836. log_register('CORPS EDIT PERSON [' . $id . ']');
  837. }
  838. }
  839. /**
  840. * creates new contact person in database
  841. *
  842. * @return void
  843. */
  844. public function personCreate() {
  845. if (ubRouting::checkPost(array('addpersoncorpid', 'addpersonrealname'))) {
  846. $corpid = ubRouting::post('addpersoncorpid', 'int');
  847. if (isset($this->corps[$corpid])) {
  848. $realname = ubRouting::post('addpersonrealname', 'mres');
  849. $phone = ubRouting::post('addpersonphone', 'mres');
  850. $im = ubRouting::post('addpersonim', 'mres');
  851. $email = ubRouting::post('addpersonemail', 'mres');
  852. $appointment = ubRouting::post('addpersonappointment', 'mres');
  853. $notes = ubRouting::post('addpersonnotes', 'mres');
  854. $this->personsDb->data('corpid', $corpid);
  855. $this->personsDb->data('realname', $realname);
  856. $this->personsDb->data('phone', $phone);
  857. $this->personsDb->data('im', $im);
  858. $this->personsDb->data('email', $email);
  859. $this->personsDb->data('appointment', $appointment);
  860. $this->personsDb->data('notes', $notes);
  861. $this->personsDb->create();
  862. $newId = $this->personsDb->getLastId();
  863. log_register('CORPS CREATE PERSON [' . $newId . '] FOR CORP [' . $corpid . ']');
  864. }
  865. }
  866. }
  867. /**
  868. * check is taxtype used by someone?
  869. *
  870. * @param $id int existing taxtype ID
  871. *
  872. * @return bool
  873. */
  874. public function taxtypeProtected($id) {
  875. $id = ubRouting::filters($id, 'int');
  876. $result = false;
  877. if (!empty($this->corps)) {
  878. foreach ($this->corps as $io => $each) {
  879. if ($each['taxtype'] == $id) {
  880. $result = true;
  881. break;
  882. }
  883. }
  884. }
  885. return ($result);
  886. }
  887. /**
  888. * deletes an existing contact person
  889. *
  890. * @param $id int existing contact person ID
  891. *
  892. * @return void
  893. */
  894. public function personDelete($id) {
  895. $id = ubRouting::filters($id, 'int');
  896. $this->personsDb->where('id', '=', $id);
  897. $this->personsDb->delete();
  898. log_register('CORPS DELETE PERSON [' . $id . ']');
  899. }
  900. /**
  901. * binds user login to existing corp ID
  902. *
  903. * @param $login string Existing user login
  904. * @param $corpid int Existing corp ID
  905. *
  906. * @return void
  907. */
  908. public function userBind($login, $corpid) {
  909. $loginF = ubRouting::filters($login, 'mres');
  910. $corpid = ubRouting::filters($corpid, 'int');
  911. if (!isset($this->users[$login])) {
  912. $this->usersDb->data('login', $loginF);
  913. $this->usersDb->data('corpid', $corpid);
  914. $this->usersDb->create();
  915. log_register('CORPS BIND USER (' . $login . ') TO [' . $corpid . ']');
  916. }
  917. }
  918. /**
  919. * unbinds user login from any corp and sets him as just private user
  920. *
  921. * @param $login string Existing user login
  922. *
  923. * @return void
  924. */
  925. function userUnbind($login) {
  926. $loginF = ubRouting::filters($login, 'mres');
  927. if (isset($this->users[$login])) {
  928. $this->usersDb->where('login', '=', $loginF);
  929. $this->usersDb->delete();
  930. log_register('CORPS UNBIND USER (' . $login . ')');
  931. }
  932. }
  933. /**
  934. * checks is user associated with some corp or not? If associated - returns corp ID
  935. *
  936. * @param $login string Existing user login
  937. *
  938. * @return int/bool
  939. */
  940. function userIsCorporate($login) {
  941. $result = false;
  942. if (isset($this->users[$login])) {
  943. $result = $this->users[$login];
  944. }
  945. return ($result);
  946. }
  947. /**
  948. * returns user unbind form
  949. *
  950. * @param $login string Existing user login
  951. *
  952. * @return string
  953. */
  954. public function userUnbindForm($login) {
  955. $login = ubRouting::filters($login, 'mres');
  956. $result = '';
  957. if (isset($this->users[$login])) {
  958. $inputs = wf_HiddenInput('corpsunbindlogin', $login);
  959. $inputs .= wf_CheckInput('unbindagree', __('I am quite sure that I was going to do'), false, false);
  960. $inputs .= wf_Submit(__('Destroy user link'));
  961. $result = wf_Form("", 'POST', $inputs, 'glamour');
  962. $result .= wf_delimiter();
  963. $result .= web_UserControls($login);
  964. } else {
  965. $result = __('Not existing item');
  966. }
  967. return ($result);
  968. }
  969. /**
  970. * returns existing coorps selector
  971. *
  972. * @param $login string Existing user login
  973. *
  974. * @return string
  975. */
  976. public function corpsBindForm($login) {
  977. $result = '';
  978. $corpsarr = array();
  979. if (!empty($this->corps)) {
  980. foreach ($this->corps as $io => $each) {
  981. $corpsarr[$io] = $each['corpname'];
  982. }
  983. $inputs = wf_HiddenInput('bindsomelogin', $login);
  984. if ($this->altCfg['CORPSEL_SEARCHBL']) {
  985. $inputs .= wf_SelectorSearchable('bindlogintocorpid', $corpsarr, __('Corporate user'), '', false);
  986. } else {
  987. $inputs .= wf_Selector('bindlogintocorpid', $corpsarr, __('Corporate user'), '', false);
  988. }
  989. $inputs .= wf_Submit(__('Create user ling with existing corporate user'));
  990. $result = wf_Form("", 'POST', $inputs, 'glamour');
  991. }
  992. return ($result);
  993. }
  994. /**
  995. * returns user binding form
  996. *
  997. * @param $login string Existing user login
  998. *
  999. * @return string
  1000. */
  1001. public function corpCreateAndBindForm($login) {
  1002. if (!empty($this->taxtypes)) {
  1003. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  1004. $inputs = wf_HiddenInput('createcorpid', 'true');
  1005. $inputs .= wf_HiddenInput('alsobindsomelogin', $login);
  1006. $inputs .= wf_TextInput('createcorpname', __('Corp name') . $sup, '', true, '40');
  1007. $inputs .= wf_TextInput('createaddress', __('Address'), '', true, '40');
  1008. $inputs .= $this->doctypeSelector('createdoctype', '');
  1009. $inputs .= wf_DatePickerPreset('createdocdate', curdate(), true) . ' ' . __('Document date') . wf_tag('br');
  1010. $inputs .= wf_TextInput('adddocnum', __('Document number'), '', true, '20');
  1011. $bankAccLabel = ($this->ibanFlag) ? __('IBAN') : __('Bank account');
  1012. $inputs .= wf_TextInput('addbankacc', $bankAccLabel, '', true, '20');
  1013. $inputs .= wf_TextInput('addbankname', __('Bank name'), '', true, '20');
  1014. $mfoLabel = (!$this->rfCorpsFlag) ? __('Bank MFO') : __('Bank BIK');
  1015. $edrpouLabel = (!$this->rfCorpsFlag) ? __('EDRPOU') : __('OGRN');
  1016. $ndsNumLabel = (!$this->rfCorpsFlag) ? __('NDS number') : __('INN Number');
  1017. $innCodeLabel = (!$this->rfCorpsFlag) ? __('INN code') : __('KPP Code');
  1018. $inputs .= wf_TextInput('addbankmfo', $mfoLabel, '', true, '20');
  1019. $inputs .= wf_TextInput('addedrpou', $edrpouLabel, '', true, '20');
  1020. $inputs .= wf_TextInput('addndstaxnum', $ndsNumLabel, '', true, '20');
  1021. $inputs .= wf_TextInput('addinncode', $innCodeLabel, '', true, '20');
  1022. $inputs .= wf_Selector('addtaxtype', $this->taxtypes, __('Tax type'), '', true);
  1023. $inputs .= wf_TextInput('addcorpnameabbr', __('Short name'), '', true, '20');
  1024. $inputs .= wf_TextInput('addcorpsignatory', __('Signatory'), '', true, '20');
  1025. $inputs .= wf_TextInput('addcorpsignatory2', __('Signatory') . ' 2', '', true, '20');
  1026. $inputs .= wf_TextInput('addcorpbasis', __('Basis'), '', true, '20');
  1027. $inputs .= wf_TextInput('addcorpemail', __('Email'), '', true, '20');
  1028. $inputs .= wf_TextInput('addnotes', __('Notes'), '', true, '40');
  1029. $inputs .= wf_Submit(__('Create'));
  1030. $result = wf_Form(self::URL_CORPS_ADD, 'POST', $inputs, 'glamour');
  1031. } else {
  1032. $result = __('No existing tax types');
  1033. }
  1034. return ($result);
  1035. }
  1036. /**
  1037. * checks is corp used by something or not?
  1038. *
  1039. * @param $id int Existing corp ID
  1040. *
  1041. * @return bool
  1042. */
  1043. public function corpProtected($id) {
  1044. $id = ubRouting::filters($id, 'int');
  1045. $result = false;
  1046. if (!empty($this->users)) {
  1047. foreach ($this->users as $login => $corpid) {
  1048. if ($corpid == $id) {
  1049. $result = true;
  1050. break;
  1051. }
  1052. }
  1053. }
  1054. return ($result);
  1055. }
  1056. /**
  1057. * Gets corp data by associated username
  1058. *
  1059. * @param $login string Existing users login
  1060. *
  1061. * @return array
  1062. */
  1063. public function corpGetDataByLogin($login) {
  1064. $result = array();
  1065. if (isset($this->users[$login])) {
  1066. $corpId = $this->users[$login];
  1067. if (isset($this->corps[$corpId])) {
  1068. $result = $this->corps[$corpId];
  1069. //map some IDs to normal text
  1070. @$result['doctype'] = __($this->doctypes[$result['doctype']]);
  1071. @$result['taxtype'] = $this->taxtypes[$result['taxtype']];
  1072. }
  1073. }
  1074. return ($result);
  1075. }
  1076. /**
  1077. * Returns array of available corps
  1078. *
  1079. * @return array
  1080. */
  1081. public function getCorps() {
  1082. return ($this->corps);
  1083. }
  1084. /**
  1085. * Returns array of available corps users
  1086. *
  1087. * @return array
  1088. */
  1089. public function getUsers() {
  1090. return ($this->users);
  1091. }
  1092. /**
  1093. * Rerurns corp id by name part
  1094. *
  1095. * @param string $searchterm
  1096. *
  1097. * @return int
  1098. */
  1099. protected function searchCorpIdbyName($searchterm) {
  1100. $result = '';
  1101. if (!empty($this->corps)) {
  1102. if (!empty($searchterm)) {
  1103. $searchterm = strtolower_utf8($searchterm);
  1104. foreach ($this->corps as $io => $each) {
  1105. if (ispos(strtolower_utf8($each['corpname']), $searchterm)) {
  1106. $result = $io;
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return ($result);
  1112. }
  1113. /**
  1114. * returns users array by some corp ID
  1115. *
  1116. * @return array
  1117. */
  1118. protected function searchUsersByCorpId($corpid) {
  1119. $result = array();
  1120. if (!empty($this->corps)) {
  1121. if (!empty($this->users)) {
  1122. if (!empty($corpid)) {
  1123. foreach ($this->users as $eachLogin => $eachCorp) {
  1124. if ($eachCorp == $corpid) {
  1125. $result[] = $eachLogin;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131. return ($result);
  1132. }
  1133. /**
  1134. * Returns standard user list of users assigned for some corp
  1135. *
  1136. * @param string $corpname
  1137. * @return string
  1138. */
  1139. public function searchUsersByCorpName($corpname) {
  1140. $result = '';
  1141. if (!empty($corpname)) {
  1142. $corpId = $this->searchCorpIdbyName($corpname);
  1143. if (!empty($corpId)) {
  1144. $corpLink = wf_Link('?module=corps&show=corps&editid=' . $corpId, $this->corps[$corpId]['corpname'], false, '');
  1145. show_success($corpLink);
  1146. $corpUsers = $this->searchUsersByCorpId($corpId);
  1147. if (!empty($corpUsers)) {
  1148. $result = web_UserArrayShower($corpUsers);
  1149. } else {
  1150. show_warning(__('Nothing found'));
  1151. }
  1152. } else {
  1153. show_warning(__('Nothing found'));
  1154. }
  1155. }
  1156. return ($result);
  1157. }
  1158. }