api.banksta2.php 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120
  1. <?php
  2. /**
  3. * Bank statements processing class
  4. */
  5. class Banksta2 {
  6. /**
  7. * UbillingConfig object placeholder
  8. *
  9. * @var null
  10. */
  11. protected $ubConfig = null;
  12. /**
  13. * Billing API object placeholder
  14. *
  15. * @var null
  16. */
  17. protected $billing = null;
  18. /**
  19. * System message helper object placeholder
  20. *
  21. * @var null
  22. */
  23. protected $messages = null;
  24. /**
  25. * UbillingCache instance placeholder
  26. *
  27. * @var null
  28. */
  29. protected $ubCache = null;
  30. /**
  31. * Placeholder for BANKSTA2_CACHE_LIFETIME from alter.ini
  32. *
  33. * @var int
  34. */
  35. protected $cacheLifeTime = 900;
  36. /**
  37. * List of allowed extensions
  38. *
  39. * @var array
  40. */
  41. protected $allowedExtensions = array("txt", "csv", "dbf", "xls", "xlsx");
  42. /**
  43. * Field mapping presets represented as [preset_id] => array[] of options
  44. *
  45. * @var array
  46. */
  47. protected $fieldsMappingPresets = array();
  48. /**
  49. * Default payment ID to push Internet banksta payments
  50. *
  51. * @var int
  52. */
  53. protected $inetPaymentId = 1;
  54. /**
  55. * Default payment ID to push UKV banksta payments
  56. *
  57. * @var int
  58. */
  59. protected $ukvPaymentId = 2;
  60. /**
  61. * Service types placeholder
  62. *
  63. * @var array
  64. */
  65. protected $bankstaServiceType = array();
  66. /**
  67. * Already preprocessed banksta records from BANKSTA2_TABLE
  68. *
  69. * @var array
  70. */
  71. protected $bankstaRecordsAll = array();
  72. /**
  73. * Already preprocessed banksta records IDs from BANKSTA2_TABLE
  74. *
  75. * @var array
  76. */
  77. protected $bankstaRecordsAllIDs = array();
  78. /**
  79. * Contains available Inet users data as login => userdata
  80. *
  81. * @var array
  82. */
  83. protected $allUsersDataInet = array();
  84. /**
  85. * Contains available UKV users data as login => userdata
  86. *
  87. * @var array
  88. */
  89. protected $allUsersDataUKV = array();
  90. /**
  91. * Contains available Inet users contracts mappings as contract => login
  92. *
  93. * @var array
  94. */
  95. protected $allContractsInet = array();
  96. /**
  97. * Contains available UKV users contracts mappings as contract => login
  98. *
  99. * @var array
  100. */
  101. protected $allContractsUKV = array();
  102. /**
  103. * Contains available UKV tariffs mappings as id => data
  104. *
  105. * @var array
  106. */
  107. protected $ukvTariffs = array();
  108. /**
  109. * Contains detected Internet/UKV users as contract => login / contract => id
  110. * for displaying during statement processing
  111. *
  112. * @var array
  113. */
  114. protected $bankstaFoundUsers = array();
  115. /**
  116. * Placeholder for BANKSTA2_REGEX_KEYWORDS_DELIM option
  117. *
  118. * @var string
  119. */
  120. protected $regexKeywordsDelimiter = ',';
  121. /**
  122. * Placeholder for BANKSTA2_LSTCHK_FNAMES_TRANSLATE option
  123. *
  124. * @var bool
  125. */
  126. protected $translateLstChkFieldNames = false;
  127. /**
  128. * Placeholder for BANKSTA2_OPAYZID_AS_CONTRACT option
  129. *
  130. * @var bool
  131. */
  132. protected $opayzIDAsContract = false;
  133. /**
  134. * Placeholder for BANKSTA2_INETSRV_ALLOTED_IDS option
  135. *
  136. * @var array
  137. */
  138. protected $inetSrvAllotedIDs = array();
  139. /**
  140. * Placeholder for BANKSTA2_CTVSRV_ALLOTED_IDS option
  141. *
  142. * @var array
  143. */
  144. protected $ctvSrvAllotedIDs = array();
  145. /**
  146. * Placeholder for file data preprocessed during filePreprocessing()
  147. *
  148. * @var array
  149. */
  150. public $preprocessedFileData = array();
  151. /**
  152. * Placeholder mapper for BANKSTA2_PRESETS_TABLE and web_PreprocessingForm
  153. *
  154. * @var array
  155. */
  156. public $dbPresetsFlds2PreprocForm = array(
  157. 'col_realname' => 'bsrealname_col',
  158. 'col_address' => 'bsaddress_col',
  159. 'col_paysum' => 'bspaysum_col',
  160. 'col_paypurpose' => 'bspaypurpose_col',
  161. 'col_paydate' => 'bspaydate_col',
  162. 'col_paytime' => 'bspaytime_col',
  163. 'col_contract' => 'bscontract_col',
  164. 'col_srvidents' => 'bssrvidents_col',
  165. 'sum_in_coins' => 'bspaymincoins',
  166. 'guess_contract' => 'bstryguesscontract',
  167. 'srvidents_preffered' => 'bssrvidentspreff',
  168. 'contract_delim_start' => 'bscontractdelimstart',
  169. 'contract_delim_end' => 'bscontractdelimend',
  170. 'contract_min_len' => 'bscontractminlen',
  171. 'contract_max_len' => 'bscontractmaxlen',
  172. 'service_type' => 'bssrvtype',
  173. 'inet_srv_start_delim' => 'bsinetdelimstart',
  174. 'inet_srv_end_delim' => 'bsinetdelimend',
  175. 'inet_srv_keywords' => 'bsinetkeywords',
  176. 'noesc_inet_srv_keywords' => 'bsinetkeywordsnoesc',
  177. 'ukv_srv_start_delim' => 'bsukvdelimstart',
  178. 'ukv_srv_end_delim' => 'bsukvdelimend',
  179. 'ukv_srv_keywords' => 'bsukvkeywords',
  180. 'noesc_ukv_srv_keywords' => 'bsukvkeywordsnoesc',
  181. 'skip_row' => 'bsskiprow',
  182. 'col_skiprow' => 'bsskiprow_col',
  183. 'skip_row_keywords' => 'bsskiprowkeywords',
  184. 'noesc_skip_row_keywords' => 'bsskiprowkeywordsnoesc',
  185. 'replace_strs' => 'bsreplacestrs',
  186. 'col_replace_strs' => 'bscolsreplacestrs',
  187. 'strs_to_replace' => 'bsstrstoreplace',
  188. 'strs_to_replace_with' => 'bsstrstoreplacewith',
  189. 'replacements_cnt' => 'bsreplacementscnt',
  190. 'noesc_replace_keywords' => 'bsreplacekeywordsnoesc',
  191. 'remove_strs' => 'bsremovestrs',
  192. 'col_remove_strs' => 'bscolremovestrs',
  193. 'strs_to_remove' => 'bsstrstoremove',
  194. 'noesc_remove_keywords' => 'bsremovekeywordsnoesc',
  195. 'payment_type_id' => 'bspaymtypeid'
  196. );
  197. /**
  198. * Default storage table name
  199. */
  200. const BANKSTA2_TABLE = 'banksta2';
  201. const BANKSTA2_PRESETS_TABLE = 'banksta2_presets';
  202. const BANKSTA2_USER_CACHE_KEY = "BANKSTA2_USERS_DATA";
  203. const BANKSTA2_PROCBS_CACHE_KEY = "BANKSTA2_PROCBS_DATA";
  204. const BANKSTA2_MAPPRESETS_CACHE_KEY = "BANKSTA2_MAPPRESETS_DATA";
  205. /**
  206. * Routing URLs
  207. */
  208. const URL_ME = '?module=banksta2';
  209. const URL_BANKSTA2_UPLOADFORM = '?module=banksta2&uploadform=true';
  210. const URL_BANKSTA2_PROCESSING = '?module=banksta2&showhash=';
  211. const URL_BANKSTA2_DETAILED = '?module=banksta2&showdetailed=';
  212. const URL_BANKSTA2_FIELD_MAPPING = '?module=banksta2&fieldmapping=true';
  213. const URL_BANKSTA2_PRESETS = '?module=banksta2&presets=true';
  214. const URL_BANKSTA2_PROCEED_STMT_IMP = '?module=banksta2&proceedstatementimport=true';
  215. const URL_BANKSTA2_BANKSTALIST = '?module=banksta2&bankstalist=true';
  216. const URL_USERS_PROFILE_INET = '?module=userprofile&username=';
  217. const URL_USERS_PROFILE_UKV = '?module=ukv&users=true&showuser=';
  218. /**
  219. * Some banksta options
  220. */
  221. const BANKSTA2_PATH = 'content/documents/banksta2/';
  222. public function __construct() {
  223. global $ubillingConfig, $billing;
  224. $this->ubConfig = $ubillingConfig;
  225. $this->billing = $billing;
  226. $this->ubCache = new UbillingCache();
  227. $this->initMessages();
  228. $this->loadOptions();
  229. $this->loadProcessedBankstaRecsIDs();
  230. $this->bankstaServiceType = array('Internet' => __('Internet'),
  231. 'UKV' => __('UKV'),
  232. 'Telepathy' => __('Telepathy')
  233. );
  234. }
  235. /**
  236. * Inits message helper object for further usage
  237. *
  238. * @return void
  239. */
  240. protected function initMessages() {
  241. $this->messages = new UbillingMessageHelper();
  242. }
  243. /**
  244. * Returns reference to UbillingMessageHelper object
  245. *
  246. * @return object
  247. */
  248. public function getUbMsgHelperInstance() {
  249. return $this->messages;
  250. }
  251. /**
  252. * Getting an alter.ini options
  253. *
  254. * @return void
  255. */
  256. protected function loadOptions() {
  257. $this->inetPaymentId = $this->ubConfig->getAlterParam('BANKSTA2_PAYMENTID_INET');
  258. $this->ukvPaymentId = $this->ubConfig->getAlterParam('BANKSTA2_PAYMENTID_UKV');
  259. $this->regexKeywordsDelimiter = (wf_getBoolFromVar($this->ubConfig->getAlterParam('BANKSTA2_REGEX_KEYWORDS_DELIM'))) ? $this->ubConfig->getAlterParam('BANKSTA2_REGEX_KEYWORDS_DELIM') : ',';
  260. $this->translateLstChkFieldNames = $this->ubConfig->getAlterParam('BANKSTA2_LSTCHK_FNAMES_TRANSLATE');
  261. $this->opayzIDAsContract = $this->ubConfig->getAlterParam('BANKSTA2_OPAYZID_AS_CONTRACT');
  262. $this->inetSrvAllotedIDs = explode(',', trim($this->ubConfig->getAlterParam('BANKSTA2_INETSRV_ALLOTED_IDS'), "\t\n\r\0\x0B,"));
  263. $this->ctvSrvAllotedIDs = explode(',', trim($this->ubConfig->getAlterParam('BANKSTA2_CTVSRV_ALLOTED_IDS'), "\t\n\r\0\x0B,"));
  264. $this->cacheLifeTime = ($this->ubConfig->getAlterParam('BANKSTA2_CACHE_LIFETIME')) ? $this->ubConfig->getAlterParam('BANKSTA2_CACHE_LIFETIME') : 900;
  265. }
  266. /**
  267. * Returns essential user data suitable for caching
  268. *
  269. * @return array
  270. */
  271. public function getUsersDataForCache() {
  272. $cacheArray = array();
  273. $userDataInet = $this->loadUserDataInet();
  274. $userDataUKV = $this->loadUserDataUKV();
  275. $ukvTariffs = $this->loadUKVTariffs();
  276. $cacheArray['usersinet'] = (empty($userDataInet['usersdata']) ? array() : $userDataInet['usersdata']);
  277. $cacheArray['usersinetcontracts'] = (empty($userDataInet['userscontracts']) ? array() : $userDataInet['userscontracts']);
  278. $cacheArray['usersukv'] = (empty($userDataUKV['usersdata']) ? array() : $userDataUKV['usersdata']);
  279. $cacheArray['usersukvcontracts'] = (empty($userDataUKV['userscontracts']) ? array() : $userDataUKV['userscontracts']);
  280. $cacheArray['tariffsukv'] = (empty($ukvTariffs) ? array() : $ukvTariffs);
  281. return ($cacheArray);
  282. }
  283. /**
  284. * Returns user data from cache
  285. *
  286. * @return array
  287. */
  288. public function getUsersDataCached($force = false) {
  289. $userDataCached = array();
  290. if ($force) {
  291. $this->ubCache->set(self::BANKSTA2_USER_CACHE_KEY, $this->getUsersDataForCache(), $this->cacheLifeTime);
  292. $userDataCached = $this->ubCache->get(self::BANKSTA2_USER_CACHE_KEY, $this->cacheLifeTime);
  293. } else {
  294. $thisInstance = $this;
  295. $userDataCached = $this->ubCache->getCallback(self::BANKSTA2_USER_CACHE_KEY, function () use ($thisInstance) {
  296. return ($thisInstance->getUsersDataForCache());
  297. }, $this->cacheLifeTime);
  298. }
  299. $this->allUsersDataInet = $userDataCached['usersinet'];
  300. $this->allContractsInet = $userDataCached['usersinetcontracts'];
  301. $this->allUsersDataUKV = $userDataCached['usersukv'];
  302. $this->allContractsUKV = $userDataCached['usersukvcontracts'];
  303. $this->ukvTariffs = $userDataCached['tariffsukv'];
  304. return ($userDataCached);
  305. }
  306. /**
  307. * Returns processed bank statements data from cache
  308. *
  309. * @return array
  310. */
  311. public function getProcessedBSRecsCached($force = false) {
  312. $processedBSRecsCached = array();
  313. if ($force) {
  314. $this->ubCache->set(self::BANKSTA2_PROCBS_CACHE_KEY, $this->loadProcessedBankstaRecs(), $this->cacheLifeTime);
  315. $processedBSRecsCached = $this->ubCache->get(self::BANKSTA2_PROCBS_CACHE_KEY, $this->cacheLifeTime);
  316. } else {
  317. $thisInstance = $this;
  318. $processedBSRecsCached = $this->ubCache->getCallback(self::BANKSTA2_PROCBS_CACHE_KEY, function () use ($thisInstance) {
  319. return ($thisInstance->loadProcessedBankstaRecs());
  320. }, $this->cacheLifeTime);
  321. }
  322. $this->bankstaRecordsAll = $processedBSRecsCached;
  323. return ($processedBSRecsCached);
  324. }
  325. /**
  326. * Returns processed bank statements data from cache
  327. *
  328. * @return array
  329. */
  330. public function getMappingPresetsCached($force = false) {
  331. $mappingPresetsCached = array();
  332. if ($force) {
  333. $this->ubCache->set(self::BANKSTA2_MAPPRESETS_CACHE_KEY, $this->loadMappingPresets(), $this->cacheLifeTime);
  334. $mappingPresetsCached = $this->ubCache->get(self::BANKSTA2_MAPPRESETS_CACHE_KEY, $this->cacheLifeTime);
  335. } else {
  336. $thisInstance = $this;
  337. $mappingPresetsCached = $this->ubCache->getCallback(self::BANKSTA2_MAPPRESETS_CACHE_KEY, function () use ($thisInstance) {
  338. return ($thisInstance->loadMappingPresets());
  339. }, $this->cacheLifeTime);
  340. }
  341. $this->fieldsMappingPresets = $mappingPresetsCached;
  342. return ($mappingPresetsCached);
  343. }
  344. /**
  345. * Loads all available Internet users data from database
  346. *
  347. * @return array
  348. */
  349. protected function loadUserDataInet() {
  350. $result = array();
  351. $allOpenPayzUsers = array();
  352. $allUsersDataInet = array();
  353. $allContractsInet = array();
  354. $allUsersData = zb_UserGetAllData();
  355. if (!empty($allUsersData)) {
  356. foreach ($allUsersData as $eachLogin => $eachUserData) {
  357. $allUsersDataInet[$eachUserData['login']] = array('login' => $eachUserData['login'],
  358. 'contract' => $eachUserData['contract'],
  359. 'fulladress' => $eachUserData['fulladress'],
  360. 'realname' => $eachUserData['realname'],
  361. 'Tariff' => $eachUserData['Tariff']
  362. );
  363. }
  364. if (!empty($allUsersDataInet)) {
  365. // getting openpayz customers, if any
  366. if ($this->opayzIDAsContract) {
  367. $tQuery = "SELECT * FROM `op_customers`";
  368. $tQueryResult = simple_queryall($tQuery);
  369. if (!empty($tQueryResult)) {
  370. foreach ($tQueryResult as $eachRec => $eachOpayzUser) {
  371. if (!empty($eachOpayzUser['virtualid'])) {
  372. $allOpenPayzUsers[$eachOpayzUser['realid']] = $eachOpayzUser['virtualid'];
  373. }
  374. }
  375. }
  376. }
  377. foreach ($allUsersDataInet as $io => $eachUser) {
  378. $login = $eachUser['login'];
  379. if (!empty($eachUser['contract'])) {
  380. $allContractsInet[$eachUser['contract']] = $login;
  381. } elseif ($this->opayzIDAsContract and !empty($allOpenPayzUsers[$login])) {
  382. $allContractsInet[$allOpenPayzUsers[$login]] = $login;
  383. }
  384. }
  385. }
  386. }
  387. $result['usersdata'] = $allUsersDataInet;
  388. $result['userscontracts'] = $allContractsInet;
  389. return ($result);
  390. }
  391. /**
  392. * Loads all available UKV users data from database
  393. *
  394. * @return array
  395. */
  396. protected function loadUserDataUKV() {
  397. $tQuery = "SELECT * from `ukv_users`";
  398. $allUsers = simple_queryall($tQuery);
  399. $allUsersDataUKV = array();
  400. $allContractsUKV = array();
  401. $result = array();
  402. if (!empty($allUsers)) {
  403. foreach ($allUsers as $io => $eachUser) {
  404. $allUsersDataUKV[$eachUser['id']] = array('id' => $eachUser['id'],
  405. 'contract' => $eachUser['contract'],
  406. 'realname' => $eachUser['realname'],
  407. 'tariffid' => $eachUser['tariffid'],
  408. 'street' => $eachUser['street'],
  409. 'build' => $eachUser['build'],
  410. 'apt' => $eachUser['apt']
  411. );
  412. $allContractsUKV[$eachUser['contract']] = $eachUser['id'];
  413. }
  414. }
  415. $result['usersdata'] = $allUsersDataUKV;
  416. $result['userscontracts'] = $allContractsUKV;
  417. return ($result);
  418. }
  419. /**
  420. * Loads UKV tariffs into private tariffs prop
  421. *
  422. * @return array
  423. */
  424. protected function loadUKVTariffs() {
  425. $tQuery = "SELECT * from `ukv_tariffs` ORDER by `tariffname` ASC;";
  426. $allTariffs = simple_queryall($tQuery);
  427. $ukvTariffs = array();
  428. if (!empty($allTariffs)) {
  429. foreach ($allTariffs as $io => $each) {
  430. $ukvTariffs[$each['id']] = $each;
  431. }
  432. }
  433. return ($ukvTariffs);
  434. }
  435. /**
  436. * Loads all of banksta rows to private property for further use
  437. *
  438. * @return array
  439. */
  440. public function loadProcessedBankstaRecs() {
  441. $tQuery = "SELECT * FROM `" . self::BANKSTA2_TABLE . "`";
  442. $tQueryResult = simple_queryall($tQuery);
  443. $bankstaRecordsAll = array();
  444. if (!empty($tQueryResult)) {
  445. foreach ($tQueryResult as $io => $eachRec) {
  446. $data4cache = array();
  447. $data4cache['id'] = $eachRec['id'];
  448. $data4cache['hash'] = $eachRec['hash'];
  449. $data4cache['contract'] = $eachRec['contract'];
  450. $data4cache['processed'] = $eachRec['processed'];
  451. $data4cache['canceled'] = $eachRec['canceled'];
  452. $data4cache['service_type'] = $eachRec['service_type'];
  453. $bankstaRecordsAll[$eachRec['id']] = $data4cache;
  454. }
  455. }
  456. return ($bankstaRecordsAll);
  457. }
  458. /**
  459. * Loads all of banksta rows IDs to private property for further use
  460. *
  461. * @return array
  462. */
  463. public function loadProcessedBankstaRecsIDs() {
  464. $tQuery = "SELECT `id` FROM `" . self::BANKSTA2_TABLE . "`";
  465. $tQueryResult = simple_queryall($tQuery);
  466. $bankstaRecordsAllIDs = array();
  467. if (!empty($tQueryResult)) {
  468. foreach ($tQueryResult as $io => $eachRec) {
  469. $bankstaRecordsAllIDs[$eachRec['id']] = $eachRec['id'];
  470. }
  471. }
  472. $this->bankstaRecordsAllIDs = $bankstaRecordsAllIDs;
  473. return ($bankstaRecordsAllIDs);
  474. }
  475. /**
  476. * Load fields mapping presets (FMPs)
  477. *
  478. * @return array
  479. */
  480. public function loadMappingPresets() {
  481. $tQuery = "SELECT * FROM `" . self::BANKSTA2_PRESETS_TABLE . "`";
  482. $tQueryResult = simple_queryall($tQuery);
  483. $fieldsMappingPresets = array();
  484. if (!empty($tQueryResult)) {
  485. foreach ($tQueryResult as $eachRec) {
  486. $fieldsMappingPresets[$eachRec['id']] = $eachRec;
  487. }
  488. }
  489. return ($fieldsMappingPresets);
  490. }
  491. /**
  492. * Fields mapping presets placeholder getter
  493. *
  494. * @return array
  495. */
  496. public function getMappingPresets() {
  497. $this->getMappingPresetsCached();
  498. return ($this->fieldsMappingPresets);
  499. }
  500. /**
  501. * Returns file info for a certain filehash
  502. *
  503. * @param $hash
  504. * @return array
  505. */
  506. public function getFileInfoByHash($hash) {
  507. $data = array();
  508. $tQuery = "SELECT `filename`, `hash`, `date`, `admin`, COUNT(`id`) AS `rowcount`, COUNT(if(`processed` > 0, 1, null)) AS processed_cnt, COUNT(if(`canceled` > 0, 1, null)) AS canceled_cnt
  509. FROM `" . self::BANKSTA2_TABLE . "` WHERE `hash`='" . $hash . "' LIMIT 1";
  510. $tQueryResult = simple_queryall($tQuery);
  511. if (!empty($tQueryResult)) {
  512. foreach ($tQueryResult as $io => $eachRec) {
  513. $data['date'] = $eachRec['date'];
  514. $data['filename'] = $eachRec['filename'];
  515. $data['rowcount'] = $eachRec['rowcount'];
  516. $data['processed_cnt'] = $eachRec['processed_cnt'];
  517. $data['canceled_cnt'] = $eachRec['canceled_cnt'];
  518. $data['admin'] = $eachRec['admin'];
  519. }
  520. }
  521. return ($data);
  522. }
  523. /**
  524. * Returns fields mapping presets in JSON representation
  525. *
  526. * @param $fmpID
  527. * @param array $arrayToRemap
  528. *
  529. * @return array|false|string
  530. */
  531. public function getFMPDataJSON($fmpID, $arrayToRemap = array()) {
  532. $result = array();
  533. $this->getMappingPresetsCached();
  534. if (isset($this->fieldsMappingPresets[$fmpID]) and !empty($this->fieldsMappingPresets[$fmpID])) {
  535. $fmpData = $this->fieldsMappingPresets[$fmpID];
  536. if (empty($arrayToRemap)) {
  537. $result = json_encode($fmpData);
  538. } else {
  539. foreach ($fmpData as $eachField => $eachValue) {
  540. $remappedFieldName = (isset($arrayToRemap[$eachField]) and !empty($arrayToRemap[$eachField])) ? $arrayToRemap[$eachField] : $eachField;
  541. $result[$remappedFieldName] = $eachValue;
  542. }
  543. $result = json_encode($result);
  544. }
  545. }
  546. return ($result);
  547. }
  548. /**
  549. * Returns an HTML-code string containing selector control
  550. *
  551. * @param string $selectorID
  552. * @param string $selectorClass
  553. * @param bool $inContainer
  554. * @param string $title
  555. * @param bool $insBR
  556. * @param bool $insRefreshButton
  557. *
  558. * @return string
  559. */
  560. public function getMappingPresetsSelector($selectorID = '', $selectorClass = '', $inContainer = false, $title = '', $insBR = false, $insRefreshButton = false) {
  561. $this->getMappingPresetsCached();
  562. $labelTitle = (empty($title)) ? __('Choose fields mapping preset') : $title;
  563. $ctrlID = (empty($selectorID)) ? 'BankstaPresetsSelector' : $selectorID;
  564. $ctrlClass = (empty($selectorClass)) ? '__BankstaPresetsSelector' : $selectorClass;
  565. $selectorContent = array('' => '-');
  566. $result = '';
  567. $refresh_button = '';
  568. if ($insRefreshButton) {
  569. $refresh_button.= wf_tag('span', false, 'ubButton', 'id="refresh_' . $ctrlID . '" title="' . __('Refresh selector data') . '" style="cursor: pointer; vertical-align: sub; padding: 2px 8px !important"');
  570. $refresh_button.= wf_img('skins/refresh.gif');
  571. $refresh_button.= wf_tag('span', true);
  572. $refresh_button.= wf_nbsp(1);
  573. }
  574. foreach ($this->fieldsMappingPresets as $eachPreset) {
  575. $selectorContent[$eachPreset['id']] = $eachPreset['presetname'];
  576. }
  577. $result.= wf_Selector('bspresets', $selectorContent, $labelTitle, '', $insBR, true, $ctrlID, $ctrlClass);
  578. if ($inContainer) {
  579. $result = wf_tag('span', false, '', 'id="container_' . $ctrlID . '"') . $result;
  580. $result.= wf_tag('span', true);
  581. }
  582. $result = $refresh_button . $result;
  583. return ($result);
  584. }
  585. /**
  586. * Returns array with certain banksta record content
  587. *
  588. * @param $recID
  589. *
  590. * @return array|mixed
  591. */
  592. public function getBankstaRecDetails($recID) {
  593. $this->getProcessedBSRecsCached();
  594. $result = array();
  595. if (isset($this->bankstaRecordsAll[$recID])) {
  596. //$result = $this->bankstaRecordsAll[$recID];
  597. $query = "SELECT * FROM `" . self::BANKSTA2_TABLE . "` WHERE `id` = '" . $recID . "'";
  598. $result = simple_query($query);
  599. }
  600. return ($result);
  601. }
  602. /**
  603. * Marks banksta record as processed
  604. *
  605. * @param $bankstaRecID
  606. *
  607. * @return void
  608. */
  609. public function setBankstaRecProcessed($bankstaRecID) {
  610. if (isset($this->bankstaRecordsAllIDs[$bankstaRecID])) {
  611. simple_update_field(self::BANKSTA2_TABLE, 'processed', 1, "WHERE `id`='" . $bankstaRecID . "';");
  612. //log_register('BANKSTA2 [' . $bankstaRecID . '] SET AS PROCESSED');
  613. } else {
  614. log_register('BANKSTA2 NONEXISTENT [' . $bankstaRecID . '] RECORD SETTING PROCESSED TRY');
  615. }
  616. }
  617. /**
  618. * Marks banksta record as canceled
  619. *
  620. * @param $bankstaRecID
  621. *
  622. * @return void
  623. */
  624. public function setBankstaRecCanceled($bankstaRecID) {
  625. if (isset($this->bankstaRecordsAllIDs[$bankstaRecID])) {
  626. simple_update_field(self::BANKSTA2_TABLE, 'processed', 1, "WHERE `id`='" . $bankstaRecID . "';");
  627. simple_update_field(self::BANKSTA2_TABLE, 'canceled', 1, "WHERE `id`='" . $bankstaRecID . "';");
  628. log_register('BANKSTA2 [' . $bankstaRecID . '] SET AS CANCELED');
  629. } else {
  630. log_register('BANKSTA2 NONEXISTENT [' . $bankstaRecID . '] RECORD SETTING CANCELED TRY');
  631. }
  632. }
  633. /**
  634. * Marks banksta record as uncanceled
  635. *
  636. * @param $bankstaRecID
  637. *
  638. * @return void
  639. */
  640. public function setBankstaRecUnCanceled($bankstaRecID) {
  641. if (isset($this->bankstaRecordsAllIDs[$bankstaRecID])) {
  642. simple_update_field(self::BANKSTA2_TABLE, 'processed', 0, "WHERE `id`='" . $bankstaRecID . "';");
  643. simple_update_field(self::BANKSTA2_TABLE, 'canceled', 0, "WHERE `id`='" . $bankstaRecID . "';");
  644. log_register('BANKSTA2 [' . $bankstaRecID . '] SET AS UNCANCELED');
  645. } else {
  646. log_register('BANKSTA2 NONEXISTENT [' . $bankstaRecID . '] RECORD SETTING UNCANCELED TRY');
  647. }
  648. }
  649. /**
  650. * Changes contract for some banksta record
  651. *
  652. * @param $bankstaRecID
  653. * @param $contract
  654. *
  655. * @return void
  656. */
  657. public function setBankstaRecContract($bankstaRecID, $contract) {
  658. $this->getProcessedBSRecsCached();
  659. $contract = mysql_real_escape_string($contract);
  660. $contract = trim($contract);
  661. if (isset($this->bankstaRecordsAll[$bankstaRecID])) {
  662. $oldContract = $this->bankstaRecordsAll[$bankstaRecID]['contract'];
  663. simple_update_field(self::BANKSTA2_TABLE, 'contract', $contract, "WHERE `id`='" . $bankstaRecID . "';");
  664. log_register('BANKSTA2 [' . $bankstaRecID . '] CONTRACT `' . $oldContract . '` CHANGED TO `' . $contract . '`');
  665. } else {
  666. log_register('BANKSTA2 NONEXISTENT [' . $bankstaRecID . '] CONTRACT CHANGE TRY');
  667. }
  668. }
  669. /**
  670. * Changes service type for some banksta record
  671. *
  672. * @param $bankstaRecID
  673. * @param $srvType
  674. *
  675. * @return void
  676. */
  677. public function setBankstaRecSrvType($bankstaRecID, $srvType) {
  678. $this->getProcessedBSRecsCached();
  679. $srvType = mysql_real_escape_string($srvType);
  680. $srvType = trim($srvType);
  681. if (isset($this->bankstaRecordsAll[$bankstaRecID])) {
  682. $oldSrvType = $this->bankstaRecordsAll[$bankstaRecID]['service_type'];
  683. simple_update_field(self::BANKSTA2_TABLE, 'service_type', $srvType, "WHERE `id`='" . $bankstaRecID . "';");
  684. log_register('BANKSTA2 [' . $bankstaRecID . '] RECORD SERVICE TYPE `' . $oldSrvType . '` CHANGED TO `' . $srvType . '`');
  685. } else {
  686. log_register('BANKSTA2 NONEXISTENT [' . $bankstaRecID . '] RECORD SERVICE TYPE CHANGE TRY');
  687. }
  688. }
  689. /**
  690. * Upload statement file
  691. *
  692. * @return array|bool
  693. */
  694. public function uploadFile() {
  695. $result = false;
  696. $extCheck = true;
  697. if ($_FILES['uploadbnksta2']['error'] == 4) {
  698. log_register('BANKSTA2 NO FILE WAS SELECTED');
  699. show_error(__('No file was selected'));
  700. return ($result);
  701. }
  702. //check file extension against $allowedExtensions
  703. foreach ($_FILES as $file) {
  704. if ($file['tmp_name'] > '') {
  705. if (@!in_array(end(explode(".", strtolower($file['name']))), $this->allowedExtensions)) {
  706. $extCheck = false;
  707. }
  708. }
  709. }
  710. if ($extCheck) {
  711. $fileName = vf($_FILES['uploadbnksta2']['name']);
  712. $uploadFile = self::BANKSTA2_PATH . $fileName;
  713. if (move_uploaded_file($_FILES['uploadbnksta2']['tmp_name'], $uploadFile)) {
  714. $fileContent = file_get_contents(self::BANKSTA2_PATH . $fileName);
  715. $fileHash = md5($fileContent);
  716. $fileContent = ''; //free some memory
  717. if (!$this->checkHashExists($fileHash)) {
  718. $result = array(
  719. 'filename' => $_FILES['uploadbnksta2']['name'],
  720. 'savedname' => $fileName,
  721. 'hash' => $fileHash
  722. );
  723. } else {
  724. log_register('BANKSTA2 DUPLICATE TRY ' . $fileHash);
  725. show_error(__('Same bank statement already exists'));
  726. }
  727. } else {
  728. show_error(__('Cant upload file to') . ' ' . self::BANKSTA2_PATH);
  729. }
  730. } else {
  731. show_error(__('Wrong file type'));
  732. log_register('BANKSTA2 WRONG FILETYPE');
  733. }
  734. return ($result);
  735. }
  736. /**
  737. * checks if banksta hash exists?
  738. *
  739. * @param string $hash bank statement raw content hash
  740. *
  741. * @return bool
  742. */
  743. protected function checkHashExists($hash) {
  744. $query = "SELECT `id` FROM `" . self::BANKSTA2_TABLE . "` WHERE `hash`='" . $hash . "'";
  745. $data = simple_query($query);
  746. if (empty($data)) {
  747. return (false);
  748. } else {
  749. return (true);
  750. }
  751. }
  752. /**
  753. * Returns true if field mapping preset with such name already exists
  754. *
  755. * @param $fmpName
  756. * @param int $excludeEditedFMPId
  757. *
  758. * @return string
  759. */
  760. public function checkFMPNameExists($fmpName, $excludeEditedFMPId = 0) {
  761. $fmpName = trim($fmpName);
  762. if (empty($excludeEditedFMPId)) {
  763. $tQuery = "SELECT `id` FROM `" . self::BANKSTA2_PRESETS_TABLE . "` WHERE `presetname` = '" . $fmpName . "'";
  764. } else {
  765. $tQuery = "SELECT `id` FROM `" . self::BANKSTA2_PRESETS_TABLE . "` WHERE `presetname` = '" . $fmpName . "' AND `id` != " . $excludeEditedFMPId;
  766. }
  767. $tQueryResult = simple_queryall($tQuery);
  768. return ( empty($tQueryResult) ) ? '' : $tQueryResult[0]['id'];
  769. }
  770. /**
  771. * Adds new fields mapping preset to DB
  772. *
  773. * @param $fmpName
  774. * @param $fmpColRealName
  775. * @param $fmpColAddr
  776. * @param $fmpColPaySum
  777. * @param $fmpColPayPurpose
  778. * @param $fmpColPayDate
  779. * @param $fmpColPayTime
  780. * @param $fmpColContract
  781. * @param $fmpPaySumInCoins
  782. * @param $fmpGuessContract
  783. * @param $fmpContractDelimStart
  784. * @param $fmpContractDelimEnd
  785. * @param $fmpContractMinLen
  786. * @param $fmpContractMaxLen
  787. * @param $fmpSrvType
  788. * @param $fmpInetStartDelim
  789. * @param $fmpInetEndDelim
  790. * @param $fmpInetKeywords
  791. * @param $fmpNoEscInetKeywords
  792. * @param $fmpUKVDelimStart
  793. * @param $fmpUKVDelimEnd
  794. * @param $fmpUKVKeywords
  795. * @param $fmpNoEscUKVKeywords
  796. * @param $fmpSkipRow
  797. * @param $fmpColSkipRow
  798. * @param $fmpSkipRowKeywords
  799. * @param $fmpNoEscSkipRowKeywords
  800. * @param $fmpReplaceStrs
  801. * @param $fmpColReplaceStrs
  802. * @param $fmpStrsToReplace
  803. * @param $fmpStrsToReplaceWith
  804. * @param $fmpReplacementsCount
  805. * @param $fmpNoEscReplaceKeywords
  806. * @param $fmpRemoveStrs
  807. * @param $fmpColRemoveStrs
  808. * @param $fmpStrsToRemove
  809. * @param $fmpNoEscRemoveKeywords
  810. * @param $fmpPaymentTypeID
  811. * @param $fmpColSrvIdents
  812. * @param $fmpSrvIdentsPreffered
  813. *
  814. * @return void
  815. */
  816. public function addFieldsMappingPreset($fmpName, $fmpColRealName = 'NONE', $fmpColAddr = 'NONE', $fmpColPaySum = 'NONE', $fmpColPayPurpose = 'NONE',
  817. $fmpColPayDate = 'NONE', $fmpColPayTime = 'NONE', $fmpColContract = 'NONE', $fmpPaySumInCoins = 0, $fmpGuessContract = 0,
  818. $fmpContractDelimStart = '', $fmpContractDelimEnd = '', $fmpContractMinLen = 0, $fmpContractMaxLen = 0, $fmpSrvType = '',
  819. $fmpInetStartDelim = '', $fmpInetEndDelim = '', $fmpInetKeywords = '', $fmpNoEscInetKeywords = 0,
  820. $fmpUKVDelimStart = '', $fmpUKVDelimEnd = '', $fmpUKVKeywords = '', $fmpNoEscUKVKeywords = 0,
  821. $fmpSkipRow = 0, $fmpColSkipRow = '', $fmpSkipRowKeywords = '', $fmpNoEscSkipRowKeywords = 0,
  822. $fmpReplaceStrs = 0, $fmpColReplaceStrs = '', $fmpStrsToReplace = '',
  823. $fmpStrsToReplaceWith = '', $fmpReplacementsCount = '', $fmpNoEscReplaceKeywords = 0,
  824. $fmpRemoveStrs = 0, $fmpColRemoveStrs = '', $fmpStrsToRemove = '', $fmpNoEscRemoveKeywords = 0,
  825. $fmpPaymentTypeID = 0, $fmpColSrvIdents = 0, $fmpSrvIdentsPreffered = 0
  826. ) {
  827. $fmpColRealName = (wf_emptyNonZero($fmpColRealName) ? 'NONE' : $fmpColRealName);
  828. $fmpColAddr = (wf_emptyNonZero($fmpColAddr) ? 'NONE' : $fmpColAddr);
  829. $fmpColPaySum = (wf_emptyNonZero($fmpColPaySum) ? 'NONE' : $fmpColPaySum);
  830. $fmpColPayPurpose = (wf_emptyNonZero($fmpColPayPurpose) ? 'NONE' : $fmpColPayPurpose);
  831. $fmpColPayDate = (wf_emptyNonZero($fmpColPayDate) ? 'NONE' : $fmpColPayDate);
  832. $fmpColPayTime = (wf_emptyNonZero($fmpColPayTime) ? 'NONE' : $fmpColPayTime);
  833. $fmpColContract = (wf_emptyNonZero($fmpColContract) ? 'NONE' : $fmpColContract);
  834. $fmpColSrvIdents = (wf_emptyNonZero($fmpColSrvIdents) ? 'NONE' : $fmpColSrvIdents);
  835. $tQuery = "INSERT INTO `" . self::BANKSTA2_PRESETS_TABLE .
  836. "` (`presetname`, `col_realname`, `col_address`, `col_paysum`, `sum_in_coins`, `col_paypurpose`, `col_paydate`,
  837. `col_paytime`, `col_contract`, `col_srvidents`, `guess_contract`, `srvidents_preffered`,
  838. `contract_delim_start`, `contract_delim_end`, `contract_min_len`, `contract_max_len`,
  839. `service_type`, `inet_srv_start_delim`, `inet_srv_end_delim`, `inet_srv_keywords`, `noesc_inet_srv_keywords`,
  840. `ukv_srv_start_delim`, `ukv_srv_end_delim`, `ukv_srv_keywords`, `noesc_ukv_srv_keywords`,
  841. `skip_row`, `col_skiprow`, `skip_row_keywords`, `noesc_skip_row_keywords`,
  842. `replace_strs`, `col_replace_strs`, `strs_to_replace`, `strs_to_replace_with`, `replacements_cnt`, `noesc_replace_keywords`,
  843. `remove_strs`, `col_remove_strs`, `strs_to_remove`, `noesc_remove_keywords`, `payment_type_id`)
  844. VALUES ('" . $fmpName . "', '" . $fmpColRealName . "', '" . $fmpColAddr . "', '" . $fmpColPaySum . "', '" . $fmpPaySumInCoins . "', '" .
  845. $fmpColPayPurpose . "', '" . $fmpColPayDate . "', '" . $fmpColPayTime . "', '" . $fmpColContract . "', '" . $fmpColSrvIdents . "', " .
  846. $fmpGuessContract . ", " . $fmpSrvIdentsPreffered . ", '" . $fmpContractDelimStart . "', '" . $fmpContractDelimEnd . "', " .
  847. $fmpContractMinLen . ", " . $fmpContractMaxLen . ", '" . $fmpSrvType . "', '" .
  848. $fmpInetStartDelim . "', '" . $fmpInetEndDelim . "', '" . $fmpInetKeywords . "', " . $fmpNoEscInetKeywords . ", '" .
  849. $fmpUKVDelimStart . "', '" . $fmpUKVDelimEnd . "', '" . $fmpUKVKeywords . "', " . $fmpNoEscUKVKeywords . ", '" .
  850. $fmpSkipRow . "', '" . $fmpColSkipRow . "', '" . $fmpSkipRowKeywords . "', " . $fmpNoEscSkipRowKeywords . ", '" .
  851. $fmpReplaceStrs . "', '" . $fmpColReplaceStrs . "', '" . $fmpStrsToReplace . "', '" .
  852. $fmpStrsToReplaceWith . "', '" . $fmpReplacementsCount . "', '" . $fmpNoEscReplaceKeywords . "', '" .
  853. $fmpRemoveStrs . "', '" . $fmpColRemoveStrs . "', '" . $fmpStrsToRemove . "', " . $fmpNoEscRemoveKeywords . ", " . $fmpPaymentTypeID . ")";
  854. nr_query($tQuery);
  855. log_register('CREATE banksta2 fields mapping preset [' . $fmpName . ']');
  856. $this->getMappingPresetsCached(true);
  857. }
  858. /**
  859. * Edits existing fields mapping preset
  860. *
  861. * @param $fmpID
  862. * @param $fmpName
  863. * @param $fmpColRealName
  864. * @param $fmpColAddr
  865. * @param $fmpColPaySum
  866. * @param $fmpColPayPurpose
  867. * @param $fmpColPayDate
  868. * @param $fmpColPayTime
  869. * @param $fmpColContract
  870. * @param $fmpPaySumInCoins
  871. * @param $fmpGuessContract
  872. * @param $fmpContractDelimStart
  873. * @param $fmpContractDelimEnd
  874. * @param $fmpContractMinLen
  875. * @param $fmpContractMaxLen
  876. * @param $fmpSrvType
  877. * @param $fmpInetStartDelim
  878. * @param $fmpInetEndDelim
  879. * @param $fmpInetKeywords
  880. * @param $fmpNoEscInetKeywords
  881. * @param $fmpUKVDelimStart
  882. * @param $fmpUKVDelimEnd
  883. * @param $fmpUKVKeywords
  884. * @param $fmpNoEscUKVKeywords
  885. * @param $fmpSkipRow
  886. * @param $fmpColSkipRow
  887. * @param $fmpSkipRowKeywords
  888. * @param $fmpNoEscSkipRowKeywords
  889. * @param $fmpReplaceStrs
  890. * @param $fmpColReplaceStrs
  891. * @param $fmpStrsToReplace
  892. * @param $fmpStrsToReplaceWith
  893. * @param $fmpReplacementsCount
  894. * @param $fmpNoEscReplaceKeywords
  895. * @param $fmpRemoveStrs
  896. * @param $fmpColRemoveStrs
  897. * @param $fmpStrsToRemove
  898. * @param $fmpNoEscRemoveKeywords
  899. * @param $fmpPaymentTypeID
  900. * @param $fmpColSrvIdents
  901. * @param $fmpSrvIdentsPreffered
  902. *
  903. * @return void
  904. */
  905. public function editFieldsMappingPreset($fmpID, $fmpName, $fmpColRealName = 'NONE', $fmpColAddr = 'NONE', $fmpColPaySum = 'NONE', $fmpColPayPurpose = 'NONE',
  906. $fmpColPayDate = 'NONE', $fmpColPayTime = 'NONE', $fmpColContract = 'NONE', $fmpPaySumInCoins = 0, $fmpGuessContract = 0,
  907. $fmpContractDelimStart = '', $fmpContractDelimEnd = '', $fmpContractMinLen = 0, $fmpContractMaxLen = 0, $fmpSrvType = '',
  908. $fmpInetStartDelim = '', $fmpInetEndDelim = '', $fmpInetKeywords = '', $fmpNoEscInetKeywords = 0,
  909. $fmpUKVDelimStart = '', $fmpUKVDelimEnd = '', $fmpUKVKeywords = '', $fmpNoEscUKVKeywords = 0,
  910. $fmpSkipRow = 0, $fmpColSkipRow = '', $fmpSkipRowKeywords = '', $fmpNoEscSkipRowKeywords = 0,
  911. $fmpReplaceStrs = 0, $fmpColReplaceStrs = '', $fmpStrsToReplace = '',
  912. $fmpStrsToReplaceWith = '', $fmpReplacementsCount = '', $fmpNoEscReplaceKeywords = 0,
  913. $fmpRemoveStrs = 0, $fmpColRemoveStrs = '', $fmpStrsToRemove = '', $fmpNoEscRemoveKeywords = 0,
  914. $fmpPaymentTypeID = 0, $fmpColSrvIdents = 0, $fmpSrvIdentsPreffered = 0
  915. ) {
  916. $fmpColRealName = (wf_emptyNonZero($fmpColRealName) ? 'NONE' : $fmpColRealName);
  917. $fmpColAddr = (wf_emptyNonZero($fmpColAddr) ? 'NONE' : $fmpColAddr);
  918. $fmpColPaySum = (wf_emptyNonZero($fmpColPaySum) ? 'NONE' : $fmpColPaySum);
  919. $fmpColPayPurpose = (wf_emptyNonZero($fmpColPayPurpose) ? 'NONE' : $fmpColPayPurpose);
  920. $fmpColPayDate = (wf_emptyNonZero($fmpColPayDate) ? 'NONE' : $fmpColPayDate);
  921. $fmpColPayTime = (wf_emptyNonZero($fmpColPayTime) ? 'NONE' : $fmpColPayTime);
  922. $fmpColContract = (wf_emptyNonZero($fmpColContract) ? 'NONE' : $fmpColContract);
  923. $fmpColSrvIdents = (wf_emptyNonZero($fmpColSrvIdents) ? 'NONE' : $fmpColSrvIdents);
  924. $tQuery = "UPDATE `" . self::BANKSTA2_PRESETS_TABLE . "` SET
  925. `presetname` = '" . $fmpName . "',
  926. `col_realname` = '" . $fmpColRealName . "',
  927. `col_address` = '" . $fmpColAddr . "',
  928. `col_paysum` = '" . $fmpColPaySum . "',
  929. `col_paypurpose` = '" . $fmpColPayPurpose . "',
  930. `col_paydate` = '" . $fmpColPayDate . "',
  931. `col_paytime` = '" . $fmpColPayTime . "',
  932. `col_contract` = '" . $fmpColContract . "',
  933. `col_srvidents` = '" . $fmpColSrvIdents . "',
  934. `sum_in_coins` = '" . $fmpPaySumInCoins . "',
  935. `guess_contract` = " . $fmpGuessContract . ",
  936. `srvidents_preffered` = " . $fmpSrvIdentsPreffered . ",
  937. `contract_delim_start` = '" . $fmpContractDelimStart . "',
  938. `contract_delim_end` = '" . $fmpContractDelimEnd . "',
  939. `contract_min_len` = " . $fmpContractMinLen . ",
  940. `contract_max_len` = " . $fmpContractMaxLen . ",
  941. `service_type` = '" . $fmpSrvType . "',
  942. `inet_srv_start_delim` = '" . $fmpInetStartDelim . "',
  943. `inet_srv_end_delim` = '" . $fmpInetEndDelim . "',
  944. `inet_srv_keywords` = '" . $fmpInetKeywords . "',
  945. `noesc_inet_srv_keywords` = '" . $fmpNoEscInetKeywords . "',
  946. `ukv_srv_start_delim` = '" . $fmpUKVDelimStart . "',
  947. `ukv_srv_end_delim` = '" . $fmpUKVDelimEnd . "',
  948. `ukv_srv_keywords` = '" . $fmpUKVKeywords . "',
  949. `noesc_ukv_srv_keywords` = '" . $fmpNoEscUKVKeywords . "',
  950. `skip_row` = '" . $fmpSkipRow . "',
  951. `col_skiprow` = '" . $fmpColSkipRow . "',
  952. `skip_row_keywords` = '" . $fmpSkipRowKeywords . "',
  953. `noesc_skip_row_keywords` = '" . $fmpNoEscSkipRowKeywords . "',
  954. `replace_strs` = '" . $fmpReplaceStrs . "',
  955. `col_replace_strs` = '" . $fmpColReplaceStrs . "',
  956. `strs_to_replace` = '" . $fmpStrsToReplace . "',
  957. `strs_to_replace_with` = '" . $fmpStrsToReplaceWith . "',
  958. `replacements_cnt` = '" . $fmpReplacementsCount . "',
  959. `noesc_replace_keywords` = '" . $fmpNoEscReplaceKeywords . "',
  960. `remove_strs` = '" . $fmpRemoveStrs . "',
  961. `col_remove_strs` = '" . $fmpColRemoveStrs . "',
  962. `strs_to_remove` = '" . $fmpStrsToRemove . "',
  963. `noesc_remove_keywords` = '" . $fmpNoEscRemoveKeywords . "',
  964. `payment_type_id` = " . $fmpPaymentTypeID . "
  965. WHERE `id` = " . $fmpID;
  966. nr_query($tQuery);
  967. log_register('CHANGE banksta2 fields mapping preset [' . $fmpName . ']');
  968. $this->getMappingPresetsCached(true);
  969. }
  970. /**
  971. * Deletes fields mapping preset
  972. *
  973. * @param $fmpId
  974. * @param string $fmpName
  975. *
  976. * @return void
  977. */
  978. public function deleteFieldsMappingPreset($fmpId, $fmpName = '') {
  979. $tQuery = "DELETE FROM `" . self::BANKSTA2_PRESETS_TABLE . "` WHERE `id` = '" . $fmpId . "'";
  980. nr_query($tQuery);
  981. log_register('DELETE banksta2 fields mapping preset [' . $fmpId . '] ` ' . $fmpName);
  982. $this->getMappingPresetsCached(true);
  983. }
  984. /**
  985. * Deletes uploaded bank statement
  986. *
  987. * @param $statementHash
  988. * @param string $fileName
  989. *
  990. * @return void
  991. */
  992. public function deleteBankStatement($statementHash, $fileName = '') {
  993. $tQuery = "DELETE FROM `" . self::BANKSTA2_TABLE . "` WHERE `hash` = '" . $statementHash . "'";
  994. nr_query($tQuery);
  995. log_register('DELETE banksta2 statement [' . $statementHash . '] ` ' . $fileName);
  996. $this->getProcessedBSRecsCached(true);
  997. }
  998. /**
  999. * Uploaded file preprocessing
  1000. *
  1001. * @param $filename
  1002. * @param $delimiter
  1003. * @param $encoding
  1004. * @param bool $useDBFColNames
  1005. *
  1006. * @return string
  1007. */
  1008. public function preprocessImportFile($filename, $delimiter, $encoding, $useDBFColNames = false, $skipRowsCount = 0) {
  1009. $dataParsed = array();
  1010. $colNamesArr = array();
  1011. $colNamesTypesArr = array();
  1012. $codePage = $encoding;
  1013. $filePath = self::BANKSTA2_PATH . $filename;
  1014. $fileExt = @end(explode(".", strtolower($filename)));
  1015. $errorMessage = '';
  1016. $rowsSkipped = 0;
  1017. set_error_handler(function ($severity, $message, $file, $line) {
  1018. throw new \ErrorException($message, $severity, $severity, $file, $line);
  1019. });
  1020. try {
  1021. // dbf/csv/xlsx differentiation goes here
  1022. switch ($fileExt) {
  1023. case ('dbf'):
  1024. $dbfTab = new dbf_class($filePath);
  1025. $dbfTabRecCount = $dbfTab->dbf_num_rec;
  1026. if ($useDBFColNames) {
  1027. foreach ($dbfTab->dbf_names as $item => $eachCol) {
  1028. $colNamesArr[] = $eachCol['name'];
  1029. $colNamesTypesArr[$eachCol['name']] = $eachCol['type'];
  1030. }
  1031. if (!empty($colNamesArr)) {
  1032. $dataParsed[] = $colNamesArr;
  1033. }
  1034. }
  1035. for ($i = 0; $i < $dbfTabRecCount; $i++) {
  1036. $eachRow = $dbfTab->getRow($i);
  1037. if (!empty($eachRow)) {
  1038. $dataParsed[] = @array_map(function ($row) use ($codePage) {
  1039. return (iconv($codePage, 'utf-8', $row));
  1040. }, $eachRow);
  1041. }
  1042. }
  1043. break;
  1044. case ('csv'):
  1045. case ('txt'):
  1046. $dataRaw = file_get_contents($filePath);
  1047. if ($encoding != 'utf-8') {
  1048. $dataRaw = iconv($encoding, 'utf-8', $dataRaw);
  1049. }
  1050. $dataRaw = explodeRows($dataRaw);
  1051. if (!empty($dataRaw)) {
  1052. foreach ($dataRaw as $eachrow) {
  1053. if ($rowsSkipped != $skipRowsCount) {
  1054. $rowsSkipped++;
  1055. continue;
  1056. }
  1057. if (!empty($eachrow)) {
  1058. $tmpArray = explode($delimiter, $eachrow);
  1059. // shitty hacky tricky check...
  1060. if (!empty($tmpArray) and count($tmpArray) > 1) {
  1061. $dataParsed[] = $tmpArray;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. break;
  1067. case ('xls'):
  1068. case ('xlsx'):
  1069. require_once('api/vendor/excel/excel_reader2.php');
  1070. require_once('api/vendor/excel/SpreadsheetReader.php');
  1071. $excelReader = new SpreadsheetReader($filePath);
  1072. foreach ($excelReader as $eachRow) {
  1073. if ($rowsSkipped != $skipRowsCount) {
  1074. $rowsSkipped++;
  1075. continue;
  1076. }
  1077. if (!empty($eachRow) and count($eachRow) > 1) {
  1078. $dataParsed[] = $eachRow;
  1079. }
  1080. }
  1081. break;
  1082. }
  1083. } catch(Exception $e) {
  1084. $errorMessage = __('File parsing error') . '. ' . __('If you tried to import .DBF file - make sure it\'s version is dBaseIII/IV and you\'ve selected a proper codepage.') .
  1085. ' ' . wf_delimiter(0) . __('Error message') . ': ' .
  1086. $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine();
  1087. }
  1088. restore_error_handler();
  1089. $this->preprocessedFileData = $dataParsed;
  1090. return($errorMessage);
  1091. }
  1092. /**
  1093. * Creates essential regex body-strings for preprocessBStatement() processing
  1094. *
  1095. * @param $keyWordStr
  1096. * @param string $delimiter
  1097. * @return string
  1098. */
  1099. public function prepareRegexStrings($keyWordStr, $delimiter = ',', $noEscaping = false) {
  1100. $keywordsStr = '';
  1101. $keywordsArray = explode($delimiter, $keyWordStr);
  1102. foreach ($keywordsArray as $keyWord) {
  1103. if ($noEscaping) {
  1104. $keywordsStr.= trim($keyWord) . '|';
  1105. } else {
  1106. $keywordsStr.= trim(preg_quote($keyWord, '/')) . '|';
  1107. }
  1108. }
  1109. $keywordsStr = rtrim($keywordsStr, '|');
  1110. return ($keywordsStr);
  1111. }
  1112. /**
  1113. * Bank statement preprocessing and last checks form building
  1114. *
  1115. * @param $statementRawData
  1116. * @param $importOpts
  1117. * @param bool $skipLastChecksForm
  1118. *
  1119. * @return string
  1120. */
  1121. public function preprocessBStatement($statementRawData, $importOpts, $skipLastChecksForm = false) {
  1122. $statementRawData = unserialize(base64_decode($statementRawData));
  1123. $noescInetKeywords = wf_getBoolFromVar($importOpts['noesc_inet_srv_keywords']);
  1124. $noescUKVKeywords = wf_getBoolFromVar($importOpts['noesc_ukv_srv_keywords']);
  1125. $noescSkipKeywords = wf_getBoolFromVar($importOpts['noesc_skip_row_keywords']);
  1126. $noescRplcKeywords = wf_getBoolFromVar($importOpts['noesc_replace_keywords']);
  1127. $noescRmvKeywords = wf_getBoolFromVar($importOpts['noesc_remove_keywords']);
  1128. $contractGuess = $importOpts['guess_contract'];
  1129. $contractDelimS = (empty($importOpts['contract_delim_start'])) ? '' : preg_quote($importOpts['contract_delim_start'], '/');
  1130. $contractDelimE = (empty($importOpts['contract_delim_end'])) ? '' : preg_quote($importOpts['contract_delim_end'], '/');
  1131. $contractMinLen = $importOpts['contract_min_len'];
  1132. $contractMaxLen = $importOpts['contract_max_len'];
  1133. $serviceType = $importOpts['service_type'];
  1134. $paymentTypeID = $importOpts['payment_type_id'];
  1135. $inetSrvDelimS = (empty($importOpts['inet_srv_start_delim'])) ? '' : preg_quote($importOpts['inet_srv_start_delim'], '/');
  1136. $inetSrvDelimE = (empty($importOpts['inet_srv_end_delim'])) ? '' : preg_quote($importOpts['inet_srv_end_delim'], '/');
  1137. $inetSrvKeywords = (empty($importOpts['inet_srv_keywords']))
  1138. ? '' : ($noescInetKeywords ? $importOpts['inet_srv_keywords'] : preg_quote($importOpts['inet_srv_keywords'], '/'));
  1139. $ukvSrvDelimS = (empty($importOpts['ukv_srv_start_delim'])) ? '' : preg_quote($importOpts['ukv_srv_start_delim'], '/');
  1140. $ukvSrvDelimE = (empty($importOpts['ukv_srv_end_delim'])) ? '' : preg_quote($importOpts['ukv_srv_end_delim'], '/');
  1141. $ukvSrvKeywords = (empty($importOpts['ukv_srv_keywords']))
  1142. ? '' : ($noescUKVKeywords ? $importOpts['ukv_srv_keywords'] : preg_quote($importOpts['ukv_srv_keywords'], '/'));
  1143. $skipRow = $importOpts['skip_row'];
  1144. $skipRowCols = ($importOpts['col_skiprow'] !== 'NONE') ? explode(',', str_replace(' ', '', $importOpts['col_skiprow'])) : array();
  1145. $skipRowKeywords = (empty($importOpts['skip_row_keywords']))
  1146. ? '' : ($noescSkipKeywords ? $importOpts['skip_row_keywords'] : preg_quote($importOpts['skip_row_keywords'], '/'));
  1147. $strsReplace = $importOpts['replace_strs'];
  1148. $strsReplaceCols = ($importOpts['col_replace_strs'] !== 'NONE') ? explode(',', str_replace(' ', '', $importOpts['col_replace_strs'])) : array();
  1149. $strsReplaceChars = (empty($importOpts['strs_to_replace']))
  1150. ? '' : ($noescRplcKeywords ? $importOpts['strs_to_replace'] : preg_quote($importOpts['strs_to_replace']));
  1151. $strsReplaceCharsWith = (empty($importOpts['strs_to_replace_with'])) ? '' : $importOpts['strs_to_replace_with'];
  1152. $strsReplacementsCnt = (empty($importOpts['replacements_cnt'])) ? -1 : $importOpts['replacements_cnt'];
  1153. $strsRemove = $importOpts['remove_strs'];
  1154. $strsRemoveCols = ($importOpts['col_remove_strs'] !== 'NONE') ? explode(',', str_replace(' ', '', $importOpts['col_remove_strs'])) : array();
  1155. $strsRemoveChars = (empty($importOpts['strs_to_remove']))
  1156. ? '' : ($noescRmvKeywords ? $importOpts['strs_to_remove'] : preg_quote($importOpts['strs_to_remove']));
  1157. $srvsIDsIdentsPreff = $importOpts['srvidents_preffered'];
  1158. // creating essential regex bodies
  1159. $keywordsStrInet = '';
  1160. $keywordsStrUKV = '';
  1161. $keywordsStrSkipRow = '';
  1162. $keywordsStrReplaceChars = '';
  1163. $keywordsStrRemoveChars = '';
  1164. // trying to get Inet service keywords
  1165. if (!empty($inetSrvKeywords)) {
  1166. $keywordsStrInet = $this->prepareRegexStrings($inetSrvKeywords, $this->regexKeywordsDelimiter, $noescInetKeywords);
  1167. }
  1168. // trying to get UKV service keywords
  1169. if (!empty($ukvSrvKeywords)) {
  1170. $keywordsStrUKV = $this->prepareRegexStrings($ukvSrvKeywords, $this->regexKeywordsDelimiter, $noescUKVKeywords);
  1171. }
  1172. // trying to get skipping row keywords
  1173. if ($skipRow and !empty($skipRowCols)) {
  1174. $keywordsStrSkipRow = $this->prepareRegexStrings($skipRowKeywords, $this->regexKeywordsDelimiter, $noescSkipKeywords);
  1175. }
  1176. // trying to get replacement keywords
  1177. if ($strsReplace and !empty($strsReplaceCols)) {
  1178. $keywordsStrReplaceChars = $this->prepareRegexStrings($strsReplaceChars, $this->regexKeywordsDelimiter, $noescRplcKeywords);
  1179. }
  1180. // trying to get removing keywords
  1181. if ($strsRemove and !empty($strsRemoveCols)) {
  1182. $keywordsStrRemoveChars = $this->prepareRegexStrings($strsRemoveChars, $this->regexKeywordsDelimiter, $noescRmvKeywords);
  1183. }
  1184. $i = 0;
  1185. $rows = '';
  1186. $statementData = array();
  1187. foreach ($statementRawData as $eachRow) {
  1188. if (empty($eachRow)) { continue; }
  1189. $i++;
  1190. $cells = wf_TableCell($i);
  1191. $cancelRow = 0;
  1192. // replacing characters/strings in specified fields
  1193. if ($strsReplace and !empty($strsReplaceCols) and !empty($strsReplaceChars)) {
  1194. foreach ($strsReplaceCols as $strsReplaceCol) {
  1195. if (isset($eachRow[$strsReplaceCol])) {
  1196. $eachRow[$strsReplaceCol] = preg_replace('/(' . $keywordsStrReplaceChars . ')/msiu', $strsReplaceCharsWith, $eachRow[$strsReplaceCol], $strsReplacementsCnt);
  1197. }
  1198. }
  1199. }
  1200. // removing characters/strings from specified fields
  1201. if ($strsRemove and !empty($strsRemoveCols) and !empty($keywordsStrRemoveChars)) {
  1202. foreach ($strsRemoveCols as $strsRemoveCol) {
  1203. if (isset($eachRow[$strsRemoveCol])) {
  1204. $eachRow[$strsRemoveCol] = preg_replace('/(' . $keywordsStrRemoveChars . ')/msiu', '', $eachRow[$strsRemoveCol]);
  1205. }
  1206. }
  1207. }
  1208. $realname = ($importOpts['col_realname'] !== 'NONE' and isset($eachRow[$importOpts['col_realname']])) ? $eachRow[$importOpts['col_realname']] : '';
  1209. $address = ($importOpts['col_address'] !== 'NONE' and isset($eachRow[$importOpts['col_address']])) ? $eachRow[$importOpts['col_address']] : '';
  1210. $notes = ($importOpts['col_paypurpose'] !== 'NONE' and isset($eachRow[$importOpts['col_paypurpose']])) ? $eachRow[$importOpts['col_paypurpose']] : '';
  1211. $ptime = ($importOpts['col_paytime'] !== 'NONE' and isset($eachRow[$importOpts['col_paytime']])) ? $eachRow[$importOpts['col_paytime']] : '';
  1212. $summ = (isset($eachRow[$importOpts['col_paysum']])) ? preg_replace('/[^-0-9\.,]/', '', $eachRow[$importOpts['col_paysum']]) : '';
  1213. $summ = ((!empty($summ) and $importOpts['sum_in_coins']) ? ($summ / 100) : $summ);
  1214. $pdate = (isset($eachRow[$importOpts['col_paydate']])) ? $eachRow[$importOpts['col_paydate']] : '';
  1215. $contract = ($importOpts['col_contract'] !== 'NONE' and isset($eachRow[$importOpts['col_contract']])) ? $eachRow[$importOpts['col_contract']] : '';
  1216. $service_type = $serviceType;
  1217. $payment_type_id = $paymentTypeID;
  1218. $srvTypeMatched = false;
  1219. // checking and preparing services idents if an appropriate dedicated field specified
  1220. $serviceIdent = ($importOpts['col_srvidents'] !== 'NONE' and isset($eachRow[$importOpts['col_srvidents']])) ? $eachRow[$importOpts['col_srvidents']] : '';
  1221. if (!empty($serviceIdent) and (!empty($this->inetSrvAllotedIDs[0]) or !empty($this->ctvSrvAllotedIDs[0]))) {
  1222. if (in_array($serviceIdent, $this->inetSrvAllotedIDs)) {
  1223. $service_type = 'Internet';
  1224. $srvTypeMatched = true;
  1225. } elseif (in_array($serviceIdent, $this->ctvSrvAllotedIDs)) {
  1226. $service_type = 'UKV';
  1227. $srvTypeMatched = true;
  1228. }
  1229. }
  1230. if (!empty($notes)) {
  1231. if (empty($contract)) {
  1232. // if contract guessing enabled and at least one of the delimiters is not empty
  1233. if ($contractGuess) {
  1234. if (empty($contractMinLen) or empty($contractMaxLen)) {
  1235. if ($contractDelimS != '' or $contractDelimE != '') {
  1236. //$contractDelimS = '(' . $contractDelimS . ')';
  1237. //$contractDelimE = '(' . $contractDelimE . ')';
  1238. //preg_match('/' . $contractDelimS . '(\D)*?\d{' . $contractMinLen . ',' . $contractMaxLen . '}(\D)*?' . $contractDelimE . '/msu', $notes, $matchResult);
  1239. //} else {
  1240. preg_match('/' . $contractDelimS . '(.*?)' . $contractDelimE . '/msu', $notes, $matchResult);
  1241. }
  1242. if (isset($matchResult[1])) {
  1243. $contract = trim($matchResult[1]);
  1244. } else {
  1245. $contract = 'unknown_' . $i;
  1246. }
  1247. } else {
  1248. preg_match('/(\D)?(\d{' . $contractMinLen . ',' . $contractMaxLen . '})(\D)?/msu', $notes, $matchResult);
  1249. if (isset($matchResult[2])) {
  1250. $contract = trim($matchResult[2]);
  1251. } else {
  1252. $contract = 'unknown_' . $i;
  1253. }
  1254. }
  1255. } else {
  1256. $contract = 'unknown_' . $i;
  1257. }
  1258. }
  1259. if (strtolower($serviceType) == 'telepathy' and !($srvsIDsIdentsPreff and $srvTypeMatched)) {
  1260. // trying to check for Inet service keywords
  1261. if (!empty($keywordsStrInet)) {
  1262. if ($inetSrvDelimS == '' and $inetSrvDelimE == '') {
  1263. $betweenDelimStr = $notes;
  1264. } else {
  1265. preg_match('/' . $inetSrvDelimS . '(.*?)' . $inetSrvDelimE . '/msiu', strtolower($notes), $matchResult);
  1266. if (isset($matchResult[1])) {
  1267. $betweenDelimStr = trim($matchResult[1]);
  1268. } else {
  1269. $betweenDelimStr = $notes;
  1270. }
  1271. }
  1272. preg_match('/(' . $keywordsStrInet . ')/msiu', $betweenDelimStr, $matchResult);
  1273. if (isset($matchResult[1])) {
  1274. $service_type = 'Internet';
  1275. $srvTypeMatched = true;
  1276. }
  1277. }
  1278. // trying to check for UKV service keywords
  1279. if (!$srvTypeMatched and !empty($keywordsStrUKV)) {
  1280. if ($ukvSrvDelimS == '' and $ukvSrvDelimE == '') {
  1281. $betweenDelimStr = $notes;
  1282. } else {
  1283. preg_match('/' . $ukvSrvDelimS . '(.*?)' . $ukvSrvDelimE . '/msiu', $notes, $matchResult);
  1284. if (isset($matchResult[1])) {
  1285. $betweenDelimStr = trim($matchResult[1]);
  1286. } else {
  1287. $betweenDelimStr = $notes;
  1288. }
  1289. }
  1290. preg_match('/(' . $keywordsStrUKV . ')/msiu', $betweenDelimStr, $matchResult);
  1291. if (isset($matchResult[1])) {
  1292. $service_type = 'UKV';
  1293. }
  1294. }
  1295. }
  1296. } else {
  1297. if (empty($contract)) { $contract = 'unknown_' . $i; }
  1298. }
  1299. // skipping rows
  1300. if ($skipRow and !empty($skipRowCols) and !empty($keywordsStrSkipRow)) {
  1301. foreach ($skipRowCols as $skipRowCol) {
  1302. if (!empty($eachRow[$skipRowCol])) {
  1303. $skipRowContent = $eachRow[$skipRowCol];
  1304. preg_match('/(' . $keywordsStrSkipRow . ')/msiu', $skipRowContent, $matchResult);
  1305. if (isset($matchResult[1])) {
  1306. $cancelRow = 1;
  1307. break;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. // filling statement array for further processing
  1313. $tArrayIndex = wf_InputId() . wf_InputId();
  1314. $statementData[$tArrayIndex]['contract'] = $contract;
  1315. $statementData[$tArrayIndex]['summ'] = $summ;
  1316. $statementData[$tArrayIndex]['address'] = $address;
  1317. $statementData[$tArrayIndex]['realname'] = $realname;
  1318. $statementData[$tArrayIndex]['notes'] = $notes;
  1319. $statementData[$tArrayIndex]['pdate'] = $pdate;
  1320. $statementData[$tArrayIndex]['ptime'] = $ptime;
  1321. $statementData[$tArrayIndex]['service_type'] = $service_type;
  1322. $statementData[$tArrayIndex]['row_canceled'] = $cancelRow;
  1323. $statementData[$tArrayIndex]['paymtype_id'] = $payment_type_id;
  1324. if (!$skipLastChecksForm) {
  1325. $cancelTitle = ($cancelRow) ? 'Yes' : 'No';
  1326. $cancelTitle = ($this->translateLstChkFieldNames) ? __($cancelTitle) : $cancelTitle;
  1327. $cells.= wf_TableCell($contract);
  1328. $cells.= wf_TableCell($summ);
  1329. $cells.= wf_TableCell($address);
  1330. $cells.= wf_TableCell($realname);
  1331. $cells.= wf_TableCell($notes);
  1332. $cells.= wf_TableCell($pdate);
  1333. $cells.= wf_TableCell($ptime);
  1334. $cells.= wf_TableCell($service_type);
  1335. $cells.= wf_TableCell($cancelTitle);
  1336. $rows.= wf_TableRow($cells, (($cancelRow) ? 'row6' : 'row3'));
  1337. }
  1338. }
  1339. zb_StorageSet('BANKSTA2_STATEMENT_DATA', base64_encode(serialize($statementData)));
  1340. return ($rows);
  1341. }
  1342. /**
  1343. * Bank statement rows processing and adding to DB
  1344. *
  1345. * @param $statementData
  1346. * @param $statementFileData
  1347. *
  1348. * @return void
  1349. */
  1350. public function processBankStatement($statementData, $statementFileData) {
  1351. if (!empty($statementData)) {
  1352. $importCounter = 0;
  1353. $newAdmin = whoami();
  1354. $newHash = $statementFileData['hash'];
  1355. $newFilename = $statementFileData['filename'];
  1356. foreach ($statementData as $eachContract => $eachRow) {
  1357. if (!empty($eachRow)) {
  1358. $newDate = date("Y-m-d H:i:s");
  1359. //@$newContract = trim($eachContract);
  1360. @$newContract = trim($eachRow['contract']);
  1361. $newContract = mysql_real_escape_string($newContract);
  1362. @$newSumm = trim($eachRow['summ']);
  1363. $newSumm = mysql_real_escape_string($newSumm);
  1364. $newSumm = str_replace(array(' ', ','), array('', '.'), $newSumm);
  1365. @$newAddress = mysql_real_escape_string($eachRow['address']);
  1366. @$newRealname = mysql_real_escape_string($eachRow['realname']);
  1367. $newNotes = mysql_real_escape_string($eachRow['notes']);
  1368. $newPdate = mysql_real_escape_string($eachRow['pdate']);
  1369. $newPtime = mysql_real_escape_string($eachRow['ptime']);
  1370. $newSrvType = mysql_real_escape_string($eachRow['service_type']);
  1371. $newCancelRow = $eachRow['row_canceled'];
  1372. $paymentTypeID = $eachRow['paymtype_id'];
  1373. //pushing row into database
  1374. if ((!empty($newPdate)) AND (!empty($newSumm))) {
  1375. $this->createPaymentRec($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $newSrvType, $newCancelRow, $paymentTypeID);
  1376. $importCounter++;
  1377. }
  1378. }
  1379. }
  1380. zb_StorageDelete('BANKSTA2_STATEMENT_DATA');
  1381. zb_StorageDelete('BANKSTA2_RAWDATA');
  1382. log_register('BANKSTA2 IMPORTED ' . $importCounter . ' ROWS FROM ' . $statementFileData['savedname']);
  1383. } else {
  1384. show_error(__('Can not process empty bank statement'));
  1385. }
  1386. }
  1387. /**
  1388. * Push bank statement payments for users that have been found
  1389. *
  1390. * @param $paymentsToPush
  1391. * @param bool $refiscalize
  1392. *
  1393. * @return void
  1394. */
  1395. public function pushStatementPayments($paymentsToPush, $refiscalize = false) {
  1396. $paymentsToPush = unserialize(base64_decode($paymentsToPush));
  1397. $checkForCorpUsers = $this->ubConfig->getAlterParam('USER_LINKING_ENABLED');
  1398. $dreamkasEnabled = $this->ubConfig->getAlterParam('DREAMKAS_ENABLED');
  1399. $needToFiscalize = false;
  1400. $fiscalDataArray = array();
  1401. $insatiability = false;
  1402. if ($dreamkasEnabled and wf_CheckPost(array('bankstapaymentsfiscalize'))) {
  1403. $DreamKas = null;
  1404. $greed = new Avarice();
  1405. $insatiability = $greed->runtime('DREAMKAS');
  1406. $needToFiscalize = true;
  1407. $fiscalDataArray = json_decode(base64_decode($_POST['bankstapaymentsfiscalize']), true);
  1408. if ($refiscalize) {
  1409. $paymentsToPush = array();
  1410. $bs2RecIDs = implode(',', array_keys($fiscalDataArray));
  1411. $tQuery = "(SELECT `contracts`.`login` AS `userlogin`, `" . self::BANKSTA2_TABLE . "`.`id`, `summ`, `pdate`, `ptime`, `payid`, `service_type` AS `service`
  1412. FROM `" . self::BANKSTA2_TABLE . "`
  1413. RIGHT JOIN `contracts` ON `" . self::BANKSTA2_TABLE . "`.`contract` = `contracts`.`contract`
  1414. AND `" . self::BANKSTA2_TABLE . "`.`service_type` = 'Internet'
  1415. WHERE `" . self::BANKSTA2_TABLE . "`.`id` IN (" . $bs2RecIDs . "))
  1416. UNION
  1417. (SELECT `ukv_users`.`id` AS `userlogin`, `" . self::BANKSTA2_TABLE . "`.`id`, `summ`, `pdate`, `ptime`, `payid`, `service_type` AS `service`
  1418. FROM `" . self::BANKSTA2_TABLE . "`
  1419. RIGHT JOIN `ukv_users` ON `" . self::BANKSTA2_TABLE . "`.`contract` = `ukv_users`.`contract`
  1420. AND `" . self::BANKSTA2_TABLE . "`.`service_type` = 'UKV'
  1421. WHERE `" . self::BANKSTA2_TABLE . "`.`id` IN (" . $bs2RecIDs . ")) ";
  1422. if ($this->opayzIDAsContract) {
  1423. $tQuery.= " UNION
  1424. (SELECT `op_customers`.`realid` AS `userlogin`, `" . self::BANKSTA2_TABLE . "`.`id`, `summ`, `pdate`, `ptime`, `payid`, `service_type` AS `service`
  1425. FROM `" . self::BANKSTA2_TABLE . "`
  1426. RIGHT JOIN `op_customers` ON `" . self::BANKSTA2_TABLE . "`.`contract` = `op_customers`.`virtualid`
  1427. AND `" . self::BANKSTA2_TABLE . "`.`service_type` = 'Internet'
  1428. WHERE `" . self::BANKSTA2_TABLE . "`.`id` IN (" . $bs2RecIDs . ")) ";
  1429. }
  1430. $tQueryResult = simple_queryall($tQuery);
  1431. if (!empty($tQueryResult)) {
  1432. foreach ($tQueryResult as $eachRec) {
  1433. $paymentsToPush[$eachRec['id']] = $eachRec;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if (!empty($paymentsToPush)) {
  1439. $this->getUsersDataCached();
  1440. $this->getProcessedBSRecsCached(true);
  1441. $needProcessUKV = $this->checkNeedProcessUKV($paymentsToPush);
  1442. $ukv = $needProcessUKV ? new UkvSystem() : null;
  1443. $allParentUsers = ($checkForCorpUsers and !$refiscalize) ? cu_GetAllParentUsers() : array();
  1444. foreach ($paymentsToPush as $eachRecID => $eachRec) {
  1445. $paymentSuccessful = false;
  1446. $userLogin = $eachRec['userlogin'];
  1447. $paySumm = $eachRec['summ'];
  1448. if (!$refiscalize) {
  1449. if ($this->checkBankstaRowIsUnprocessed($eachRecID)) {
  1450. $cashType = $eachRec['payid'];
  1451. $operation = 'add';
  1452. $paymentDayTimeNote = (empty($eachRec['pdate'])) ? '' : ' ON ' . $eachRec['pdate'] . ' ' . $eachRec['ptime'];
  1453. $paymentNote = 'BANKSTA2: [' . $eachRecID . '] ASCONTRACT ' . $eachRec['usercontract'] . $paymentDayTimeNote;
  1454. if (zb_checkMoney($paySumm)) {
  1455. if (strtolower($eachRec['service']) == 'internet') {
  1456. // inet service payment processing
  1457. if (!empty($userLogin)) {
  1458. if (isset($this->allUsersDataInet[$userLogin])) {
  1459. // check for corporate user possibility
  1460. if ($checkForCorpUsers and !empty($allParentUsers[$eachRec['userlogin']])) {
  1461. //corporate user
  1462. $userLink = $allParentUsers[$eachRec['userlogin']];
  1463. $allChildUsers = cu_GetAllChildUsers($userLink);
  1464. // adding natural payment to parent user
  1465. zb_CashAdd($userLogin, $paySumm, $operation, $cashType, $paymentNote);
  1466. if (!empty($allChildUsers)) {
  1467. foreach ($allChildUsers as $eachChild) {
  1468. //adding quiet payments for child users
  1469. $this->billing->addcash($eachChild, $paySumm);
  1470. log_register("BANKSTA2 GROUPBALANCE " . $eachChild . " " . $operation . " ON " . $paySumm);
  1471. }
  1472. }
  1473. } else {
  1474. // ordinary user processing
  1475. zb_CashAdd($userLogin, $paySumm, $operation, $cashType, $paymentNote);
  1476. }
  1477. $this->setBankstaRecProcessed($eachRecID);
  1478. $paymentSuccessful = true;
  1479. } else {
  1480. log_register('BANKSTA2 [' . $eachRecID . '] FAIL LOGIN (' . $userLogin . ')');
  1481. }
  1482. } else {
  1483. log_register('BANKSTA2 [' . $eachRecID . '] FAIL EMPTY LOGIN');
  1484. }
  1485. } else {
  1486. // UKV service payment processing
  1487. $ukv->userAddCash($userLogin, $paySumm, 1, $cashType, $paymentNote);
  1488. $this->setBankstaRecProcessed($eachRecID);
  1489. $paymentSuccessful = true;
  1490. }
  1491. } else {
  1492. log_register('BANKSTA2 FAILED: payment record ID: [' . $eachRecID . '] for service: [' . $eachRec['service'] . '] for login: [' . $userLogin . ']. ' . __('Wrong format of a sum of money to pay'));
  1493. }
  1494. } else {
  1495. $this->setBankstaRecProcessed($eachRecID);
  1496. log_register('BANKSTA2 DUPLICATE PAYMENT PUSH TRY FOR REC ID: [' . $eachRecID . ']');
  1497. }
  1498. }
  1499. // dreamkas fiscalization routine
  1500. if ($needToFiscalize
  1501. and !empty($insatiability)
  1502. and isset($fiscalDataArray[$eachRecID])
  1503. and ($paymentSuccessful or $refiscalize) ) {
  1504. $DreamKas = new DreamKas();
  1505. $rapacity_a = $insatiability['M']['KICKUP'];
  1506. $rapacity_b = $insatiability['M']['PICKUP'];
  1507. $rapacity_c = $insatiability['M']['PUSHCASHLO'];
  1508. $rapacity_d = $insatiability['M']['KANBARU'];
  1509. $rapacity_e = $insatiability['M']['SURUGA'];
  1510. $rapacity_z = $insatiability['M']['ONONOKI'];
  1511. $curRecFiscalData = $fiscalDataArray[$eachRecID];
  1512. $voracity_a = $curRecFiscalData[$insatiability['B2']['OIKURA']];
  1513. $voracity_b = $curRecFiscalData[$insatiability['B2']['SODACHI']];
  1514. $voracity_c = $curRecFiscalData[$insatiability['B2']['IZUKO']];
  1515. if (strtolower($eachRec[$insatiability['LT']['YOTSUGI']]) == $insatiability['LT']['MEME']) {
  1516. $voracity_d = $DreamKas->$rapacity_d($userLogin);
  1517. $voracity_e = $DreamKas->$rapacity_e($userLogin);
  1518. } else {
  1519. $voracity_d = $DreamKas->$rapacity_z($userLogin, $ukv);
  1520. $voracity_d = (empty($voracity_d)) ? '' : $voracity_d[$insatiability['AK']['ARARAGI']];
  1521. $voracity_e = '';
  1522. }
  1523. $voracity_f = array($curRecFiscalData[$insatiability['B2']['GAEN']] => array($insatiability['AK']['TSUKIHI'] => ($paySumm * 100)));
  1524. $voracity_g = array($insatiability['AK']['MAYOI'] => $voracity_e, $insatiability['AK']['OUGI'] => $voracity_d);
  1525. $voracity_h = $DreamKas->$rapacity_a($voracity_a, $voracity_b, $voracity_c, $voracity_f, $voracity_g);
  1526. $DreamKas->$rapacity_c($voracity_h, $eachRecID);
  1527. $voracity_i = $DreamKas->$rapacity_b();
  1528. if (!empty($voracity_i)) {
  1529. log_register('BANKSTA2 FAILED: payment record ID: [' . $eachRecID . '] fiscalization for service: [' . $eachRec['service'] . '] for login: [' . $userLogin . ']. Error message: ' . $voracity_i);
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. /**
  1536. * Creates a row in BANKSTA2_TABLE with essential payment data
  1537. *
  1538. * @param $newDate
  1539. * @param $newHash
  1540. * @param $newFilename
  1541. * @param $newAdmin
  1542. * @param $newContract
  1543. * @param $newSumm
  1544. * @param $newAddress
  1545. * @param $newRealname
  1546. * @param $newNotes
  1547. * @param $newPdate
  1548. * @param $newPtime
  1549. * @param $newSrvType
  1550. *
  1551. * @return void
  1552. */
  1553. protected function createPaymentRec($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm,
  1554. $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $newSrvType,
  1555. $newCancelRow, $paymentTypeID = 0) {
  1556. if (empty($paymentTypeID)) {
  1557. $newPaymentID = (strtolower($newSrvType) == 'internet') ? $this->inetPaymentId : $this->ukvPaymentId;
  1558. } else {
  1559. $newPaymentID = $paymentTypeID;
  1560. }
  1561. $tQuery = "INSERT INTO `" . self::BANKSTA2_TABLE . "` (`date`, `hash`, `filename`, `admin`, `contract`, `summ`, `address`,
  1562. `realname`, `notes`, `pdate`, `ptime`, `processed`, `canceled`, `service_type`, `payid`)
  1563. VALUES ( '" . $newDate . "',
  1564. '" . $newHash . "',
  1565. '" . $newFilename . "',
  1566. '" . $newAdmin . "',
  1567. '" . $newContract . "',
  1568. '" . $newSumm . "',
  1569. '" . $newAddress . "',
  1570. '" . $newRealname . "',
  1571. '" . $newNotes . "',
  1572. '" . $newPdate . "',
  1573. '" . $newPtime . "',
  1574. '" . $newCancelRow . "',
  1575. '" . $newCancelRow . "',
  1576. '" . $newSrvType . "',
  1577. '" . $newPaymentID . "'
  1578. )";
  1579. nr_query($tQuery);
  1580. }
  1581. /**
  1582. * Checks banksta row by it's ID if it is unprocessed
  1583. *
  1584. * @param int $bankstaid existing banksta row ID
  1585. *
  1586. * @return bool
  1587. */
  1588. protected function checkBankstaRowIsUnprocessed($bankstaid) {
  1589. $result = false;
  1590. $this->getProcessedBSRecsCached();
  1591. if (isset($this->bankstaRecordsAll[$bankstaid])) {
  1592. if ($this->bankstaRecordsAll[$bankstaid]['processed'] == 0) {
  1593. $result = true;
  1594. } else {
  1595. $result = false;
  1596. }
  1597. }
  1598. return ($result);
  1599. }
  1600. public function checkStatementIsUnprocessed($bankstaHash) {
  1601. $tQuery = "SELECT `id` FROM `" . self::BANKSTA2_TABLE . "` WHERE `hash` = '" . $bankstaHash . "' AND `processed` < 1 and `canceled` < 1";
  1602. $tQueryResult = simple_queryall($tQuery);
  1603. }
  1604. /**
  1605. * Checks $paymentsToPush array for UKV records presence
  1606. *
  1607. * @param $paymentsToPush
  1608. *
  1609. * @return bool
  1610. */
  1611. public function checkNeedProcessUKV($paymentsToPush) {
  1612. $result = false;
  1613. if (!empty($paymentsToPush)) {
  1614. foreach ($paymentsToPush as $eachRecID => $eachRec) {
  1615. if (strtolower($eachRec['service']) == 'ukv') {
  1616. $result = true;
  1617. break;
  1618. }
  1619. }
  1620. }
  1621. return ($result);
  1622. }
  1623. /**
  1624. * Returns main buttons controls for banksta2
  1625. *
  1626. * @return string
  1627. */
  1628. public static function web_MainButtonsControls() {
  1629. $controls = wf_Link(self::URL_BANKSTA2_BANKSTALIST, wf_img('skins/menuicons/receipt_small_compl.png') . wf_nbsp() . __('Uploaded bank statements'), false, 'ubButton') . wf_nbsp(2);
  1630. $controls.= wf_Link(self::URL_BANKSTA2_UPLOADFORM, wf_img('skins/menuicons/receipt_small.png') . wf_nbsp() . __('Upload bank statement'), false, 'ubButton') . wf_nbsp(2);
  1631. $controls.= wf_Link(self::URL_BANKSTA2_PRESETS, wf_img('skins/icon_note.gif') . wf_nbsp() . __('Fields mapping presets'), false, 'ubButton');
  1632. return ($controls);
  1633. }
  1634. /**
  1635. * Returns file selection and upload form
  1636. *
  1637. * @return string
  1638. */
  1639. public function web_FileUploadForm() {
  1640. $delimiters = array(';'=>';',
  1641. '|'=>'|',
  1642. ','=>','
  1643. );
  1644. $encodings = array('utf-8'=>'utf-8',
  1645. 'windows-1251'=>'windows-1251',
  1646. 'koi8-u'=>'koi8-u',
  1647. 'cp866'=>'cp866'
  1648. );
  1649. $uploadinputs = wf_HiddenInput('bankstatementuploaded','true');
  1650. $uploadinputs.= __('Upload bank statement') . wf_nbsp(2) . ' <input id="fileselector" type="file" name="uploadbnksta2" size="10" /><br>';
  1651. $uploadinputs.= wf_delimiter(0);
  1652. $uploadinputs.= wf_tag('div', false, '', 'style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1653. $uploadinputs.= wf_Selector('delimiter', $delimiters, __('Delimiter') . ' (' . __('this setting does not have any effect on') . ' .DBF/.XLS/.XLSX)', '', true);
  1654. $uploadinputs.= wf_delimiter(0);
  1655. $uploadinputs.= wf_Selector('encoding', $encodings, __('Encoding') . ' (' . __('this setting does not have any effect on') . ' .XLS/.XLSX)', '', true);
  1656. $uploadinputs.= wf_delimiter(0);
  1657. $uploadinputs.= wf_TextInput('skiprowscount', __('Skip specified numbers of rows from the beginning of .CSV/.TXT/.XLS/.XLSX file (if those rows are empty, or contain fields captions, or whatever)'), 0, true, '4', 'digits');
  1658. $uploadinputs.= wf_delimiter(0);
  1659. $uploadinputs.= wf_CheckInput('usedbfcolnames', __('Use .DBF column names instead of record values in mapping visualizer'), true, false);
  1660. $uploadinputs.= wf_tag('div', true);
  1661. $uploadinputs.= wf_delimiter(0);
  1662. $uploadinputs.= wf_Submit('Upload');
  1663. $uploadform = bs_UploadFormBody(self::URL_BANKSTA2_FIELD_MAPPING, 'POST', $uploadinputs, 'glamour');
  1664. return ($uploadform);
  1665. }
  1666. /**
  1667. * Renders statement preprocessing form with fields mapping
  1668. *
  1669. * @param $dataParsed
  1670. */
  1671. public function web_FieldsMappingForm($dataParsed) {
  1672. $dataParsed = unserialize(base64_decode($dataParsed));
  1673. // actual fileds mapping form assembling
  1674. if (sizeof($dataParsed) > 1) {
  1675. $colCount = sizeof($dataParsed[0]);
  1676. $cells= wf_TableCell(__('Column number'));
  1677. $cells.= wf_TableCell(__('Column content'));
  1678. $rows = wf_TableRow($cells, 'row1');
  1679. foreach ($dataParsed[0] as $colNum => $colData) {
  1680. $cells = wf_TableCell($colNum);
  1681. $cells.= wf_TableCell($colData);
  1682. $rows.= wf_TableRow($cells, 'row3');
  1683. }
  1684. $firstRow = wf_TableBody($rows, '100%', '0', '');
  1685. show_window(__('Found count of data columns'),$colCount);
  1686. show_window(__('First of imported data rows'), $firstRow);
  1687. //construct of data processing form
  1688. $rowNumArr = array();
  1689. for ($i = 0; $i < $colCount; $i++) {
  1690. $rowNumArr[$i] = $i;
  1691. }
  1692. $bsrealname_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1693. $bsaddress_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1694. $bspaysum_arr = $rowNumArr;
  1695. $bspaypurpose_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1696. $bspaydate_arr = $rowNumArr;
  1697. $bspaytime_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1698. $bscontract_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1699. $bssrvidents_arr = $rowNumArr + array('NONE' => __('Set to none'));
  1700. //save preset form
  1701. $errorModalWindowId = wf_InputId();
  1702. $presetsSelectorId = wf_InputId();
  1703. $presetsSelectorClass = '__' . wf_InputId();
  1704. $savePresetInputs = wf_TextInput('fmpname', __('Preset name'), '', true, '', '', '__FMPEmptyCheck');
  1705. $savePresetInputs.= wf_HiddenInput('fmpcreate', 'true');
  1706. $savePresetInputs.= wf_Submit(__('Create'));
  1707. $savePresetForm = wf_Form(self::URL_ME . '&fmpquickadd=true', 'POST', $savePresetInputs, 'glamour __FMPQuickSave');
  1708. $savePresetForm = wf_modalAuto(wf_img_sized('skins/save-as.png', '', '16') . wf_nbsp(1) . __('Save current mapping as preset'), __('Save current mapping as preset'), $savePresetForm, 'ubButton');
  1709. $savePresetForm.= wf_delimiter(1);
  1710. $savePresetForm.= $this->getMappingPresetsSelector($presetsSelectorId, $presetsSelectorClass, true, '', true, true);
  1711. $savePresetForm.= wf_delimiter(0);
  1712. //data column setting form
  1713. $inputs = wf_TextInput('bspaymtypeid', __('Custom payment type ID for this bank statement'), 0, true, '4', 'digits', '', 'BankstaPaymentTypeID');
  1714. $inputs.= wf_delimiter(0);
  1715. $inputs.= wf_Selector('bsrealname_col', $bsrealname_arr, __('User realname'), '0', true);
  1716. $inputs.= wf_delimiter(0);
  1717. $inputs.= wf_Selector('bsaddress_col', $bsaddress_arr, __('User address'), '1', true);
  1718. $inputs.= wf_delimiter(0);
  1719. $inputs.= wf_Selector('bspaysum_col', $bspaysum_arr, __('Payment sum'), '2', true);
  1720. $inputs.= wf_CheckInput('bspaymincoins', __('Bank statement "SUM" field presented in coins(need to be divided by 100)'), true, false, 'BankstaPaymInCoins');
  1721. $inputs.= wf_delimiter(0);
  1722. $inputs.= wf_Selector('bspaypurpose_col', $bspaypurpose_arr, __('Payment purpose'), '3', true);
  1723. $inputs.= wf_delimiter(0);
  1724. $inputs.= wf_Selector('bspaydate_col', $bspaydate_arr, __('Payment date'), '4', true);
  1725. $inputs.= wf_delimiter(0);
  1726. $inputs.= wf_Selector('bspaytime_col', $bspaytime_arr, __('Payment time'), '5', true);
  1727. //contract defining controls
  1728. $inputs.= wf_delimiter(0);
  1729. $inputs.= wf_Selector('bscontract_col', $bscontract_arr, __('User contract') . ' (' . __('Payment ID') . ')', '6', true);
  1730. $inputs.= wf_CheckInput('bstryguesscontract', __('Try to get contract from payment purpose field'), true, false, 'BankstaTryGuessContract');
  1731. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 700px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  1732. $inputs.= __('ONLY, if mapped contract field for some row will be empty or if contract field will be not specified');
  1733. $inputs.= wf_tag('h4', true);
  1734. $inputs.= wf_tag('div', false, '', 'id="BankstaContractGuessingBlock" style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1735. $inputs.= __('If it is possible that there are users contracts between start/end delimiters in payment purpose field of the bank statement - they will be extracted');
  1736. $inputs.= wf_delimiter(0);
  1737. $inputs.= wf_TextInput('bscontractdelimstart', __('Contract') . ' (' . __('Payment ID') . '): ' . __('start delimiter string'), '', true, '', '', '', 'BankstaContractDelimStart');
  1738. $inputs.= wf_TextInput('bscontractdelimend', __('Contract') . ' (' . __('Payment ID') . '): ' . __('end delimiter string'), '', true, '', '', '', 'BankstaContractDelimEnd');
  1739. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 700px; padding: 11px 0 7px 0; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  1740. $inputs.= __('If your contracts(payment IDs) are 100% DIGITAL - you may specify their minimum and maximum length to extract them properly(delimiters will not be taken into account)');
  1741. $inputs.= wf_tag('h4', true);
  1742. $inputs.= wf_TextInput('bscontractminlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('min length'), '0', true, '', '', '', 'BankstaContractMinLen');
  1743. $inputs.= wf_TextInput('bscontractmaxlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('max length'), '0', true, '', '', '', 'BankstaContractMaxLen');
  1744. $inputs.= wf_tag('div', true);
  1745. //service types defining controls
  1746. $inputs.= wf_delimiter(0);
  1747. $inputs.= wf_Selector('bssrvtype', $this->bankstaServiceType, __('Service type'), '21', true, false, 'BankstaSrvType');
  1748. $inputs.= wf_tag('div', false, '', 'id="BankstaServiceGuessingBlock" style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1749. $inputs.= wf_TextInput('bsinetdelimstart', __('Internet service before keywords delimiter string'), '', true, '', '', '', 'BankstaInetDelimStart');
  1750. $inputs.= wf_TextInput('bsinetkeywords', __('Internet service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaInetKeyWords');
  1751. $inputs.= wf_TextInput('bsinetdelimend', __('Internet service after keywords delimiter string'), '', true, '', '', '', 'BankstaInetDelimEnd');
  1752. $inputs.= wf_CheckInput('bsinetkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaInetKeyWordsNoEsc');
  1753. $inputs.= wf_delimiter(0);
  1754. $inputs.= wf_TextInput('bsukvdelimstart', __('UKV service before keywords delimiter string'), '', true, '', '', '', 'BankstaUKVDelimStart');
  1755. $inputs.= wf_TextInput('bsukvkeywords', __('UKV service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaUKVKeyWords');
  1756. $inputs.= wf_TextInput('bsukvdelimend', __('UKV service after keywords delimiter string'), '', true, '', '', '', 'BankstaUKVDelimEnd');
  1757. $inputs.= wf_CheckInput('bsukvkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaUKVKeyWordsNoEsc');
  1758. $inputs.= wf_tag('div', true);
  1759. $inputs.= wf_delimiter(0);
  1760. //allotted service IDs controls
  1761. $inputs.= wf_Selector('bssrvidents_col', $bssrvidents_arr, __('Number of the dedicated field which contains services IDs identifiers mapped via BANKSTA2_INETSRV_ALLOTED_IDS and BANKSTA2_CTVSRV_ALLOTED_IDS'), '6', true);
  1762. $inputs.= wf_CheckInput('bssrvidentspreff', __('Services IDs identifiers from the dedicated field take precedence over service type telepathy'), true, false, 'BankstaSrvIdentsPreff');
  1763. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 980px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  1764. $inputs.= __('NOTE: dedicated field\'s services IDs are always take precedence over manually chosen \'Internet\' or \'UKV\' services');
  1765. $inputs.= wf_tag('h4', true);
  1766. $inputs.= wf_delimiter(0);
  1767. //row skipping controls
  1768. $inputs.= wf_CheckInput('bsskiprow', __('Skip row processing if specified fields contain keywords below'), true, false, 'BankstaSkipRow');
  1769. $inputs.= wf_tag('div', false, '', 'id="BankstaSkipRowBlock" style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1770. //$inputs.= wf_Selector('bsskiprow_col', $bsrealname_arr, __('Fields to check row skipping(multiple fields must be separated with comas)'), 'NONE', true);
  1771. $inputs.= wf_TextInput('bsskiprow_col', __('Fields to check row skipping') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaSkipRowKeyWordsCols');
  1772. $inputs.= wf_TextInput('bsskiprowkeywords', __('Row skipping determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaSkipRowKeyWords');
  1773. $inputs.= wf_CheckInput('bsskiprowkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaSkipRowKeyWordsNoEsc');
  1774. $inputs.= wf_tag('div', true);
  1775. $inputs.= wf_delimiter(0);
  1776. //words/strings replacing controls
  1777. $inputs.= wf_CheckInput('bsreplacestrs', __('Replace characters specified below in specified fields'), true, false, 'BankstaReplaceStrs');
  1778. $inputs.= wf_tag('div', false, '', 'id="BankstaReplaceStrsBlock" style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1779. //$inputs.= wf_Selector('bscolsreplacestrs', $bsrealname_arr, __('Fields to perform replacing(multiple fields must be separated with comas)'), 'NONE', true);
  1780. $inputs.= wf_TextInput('bscolsreplacestrs', __('Fields to perform replacing') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaReplaceStrsCols');
  1781. $inputs.= wf_TextInput('bsstrstoreplace', __('Replaced characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaReplaceStrsChars');
  1782. $inputs.= wf_TextInput('bsstrstoreplacewith', __('Replacing characters or string'), '', true, '40', '', '', 'BankstaReplaceStrsWith');
  1783. $inputs.= wf_TextInput('bsreplacementscnt', __('Replacements count'), '', true, '40', '', '', 'BankstaReplaceStrsCnt');
  1784. $inputs.= wf_CheckInput('bsreplacekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaReplaceKeyWordsNoEsc');
  1785. $inputs.= wf_tag('div', true);
  1786. $inputs.= wf_delimiter(0);
  1787. //words/strings removing controls
  1788. $inputs.= wf_CheckInput('bsremovestrs', __('Remove characters specified below in specified fields'), true, false, 'BankstaRemoveStrs');
  1789. $inputs.= wf_tag('div', false, '', 'id="BankstaRemoveStrsBlock" style="border: 1px solid #ddd; border-radius: 4px; padding: 4px"');
  1790. //$inputs.= wf_Selector('bscolremovestrs', $bsrealname_arr, __('Fields to perform replacing(multiple fields must be separated with comas)'), 'NONE', true);
  1791. $inputs.= wf_TextInput('bscolremovestrs', __('Fields to perform removing') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaRemoveStrsCols');
  1792. $inputs.= wf_TextInput('bsstrstoremove', __('Removed characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaRemoveStrsChars');
  1793. $inputs.= wf_CheckInput('bsremovekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaRemoveKeyWordsNoEsc');
  1794. $inputs.= wf_tag('div', true);
  1795. $inputs.= wf_delimiter(0);
  1796. $inputs.= wf_CheckInput('bsskiplastcheck', __('Skip last check visualization form and import data immediately'), true);
  1797. $inputs.= wf_tag('script', false, '', 'type="text/javascript"');
  1798. $inputs.= wf_JSEmptyFunc();
  1799. $inputs.= wf_JSElemInsertedCatcherFunc();
  1800. $inputs.= ' function chekEmptyVal(ctrlClassName) {
  1801. $(document).on("focus keydown", ctrlClassName, function(evt) {
  1802. if ( $(ctrlClassName).css("border-color") == "rgb(255, 0, 0)" ) {
  1803. $(ctrlClassName).val("");
  1804. $(ctrlClassName).css("border-color", "");
  1805. $(ctrlClassName).css("color", "");
  1806. }
  1807. });
  1808. }
  1809. function dynamicDistributePresetValue(ctrlClassName) {
  1810. $(document).on("change", ctrlClassName, function(evt) {
  1811. distributePresetValue($(ctrlClassName).val());
  1812. });
  1813. }
  1814. function distributePresetValue(presetId) {
  1815. $.ajax({
  1816. type: "POST",
  1817. url: "' . self::URL_ME . '",
  1818. data: {
  1819. getfmpdata: true,
  1820. fmpid: presetId
  1821. },
  1822. success: function(result) {
  1823. var tFMPData = JSON.parse(result);
  1824. var tFields = Object.entries(tFMPData);
  1825. tFields.forEach(function(field) {
  1826. var fieldNam = field[0];
  1827. var fieldVal = field[1];
  1828. if ( $(\'[name=\'+fieldNam+\']\').length ) {
  1829. var ctrl = $(\'[name=\'+fieldNam+\']\');
  1830. console.log(fieldNam);
  1831. console.log(fieldVal);
  1832. console.log(ctrl);
  1833. switch(ctrl.prop("type")) {
  1834. case "radio":
  1835. case "checkbox":
  1836. ctrl.each(function() {
  1837. if (fieldVal == true || fieldVal > 0) {
  1838. //$(this).attr("checked", true);
  1839. $(this).prop("checked", true).change();
  1840. } else {
  1841. //$(this).attr("checked", false);
  1842. $(this).prop("checked", false).change();
  1843. }
  1844. });
  1845. break;
  1846. default:
  1847. ctrl.val(fieldVal);
  1848. }
  1849. ctrl.change();
  1850. }
  1851. });
  1852. }
  1853. });
  1854. }
  1855. function refreshFMPSelector() {
  1856. $.ajax({
  1857. type: "GET",
  1858. url: "' . self::URL_ME . '",
  1859. data: {
  1860. refreshfmpselector: true,
  1861. fmpselectorid: "' . $presetsSelectorId . '",
  1862. fmpselectorclass: "' . $presetsSelectorClass . '"
  1863. },
  1864. success: function(result) {
  1865. if ( !empty(result) ) {
  1866. $("label[for=\'' . $presetsSelectorId . '\']").remove();
  1867. $(\'#' . $presetsSelectorId . '\').replaceWith(result);
  1868. }
  1869. }
  1870. });
  1871. }
  1872. $(document).on("submit", ".__FMPQuickSave", function(evt) {
  1873. var FrmAction = $(".__FMPQuickSave").attr("action");
  1874. var FrmData = $(".__FMPQuickSave").serialize() + \'&\' + $(".__Banksta2PreprocessingForm").serialize() + \'&errfrmid=' . $errorModalWindowId . '\';
  1875. evt.preventDefault();
  1876. var emptyCheckClass = \'.__FMPEmptyCheck\';
  1877. if ( empty( $(emptyCheckClass).val() ) || $(emptyCheckClass).css("border-color") == "rgb(255, 0, 0)" ) {
  1878. $(emptyCheckClass).css("border-color", "red");
  1879. $(emptyCheckClass).css("color", "grey");
  1880. $(emptyCheckClass).val("' . __('Mandatory field') . '");
  1881. } else {
  1882. $.ajax({
  1883. type: "POST",
  1884. url: FrmAction,
  1885. data: FrmData,
  1886. success: function(result) {
  1887. if ( !empty(result) ) {
  1888. $(document.body).append(result);
  1889. $( \'#' . $errorModalWindowId . '\' ).dialog("open");
  1890. } else {
  1891. alert(\'' . __('Preset added successfully') . '\');
  1892. $(".__FMPQuickSave").parent(\'.ui-dialog-content\').dialog("close");
  1893. refreshFMPSelector();
  1894. }
  1895. }
  1896. });
  1897. }
  1898. });
  1899. onElementInserted(\'body\', \'.' . $presetsSelectorClass . '\', function(element) {
  1900. dynamicDistributePresetValue(\'.'. $presetsSelectorClass . '\');
  1901. });
  1902. onElementInserted(\'body\', \'.__FMPEmptyCheck\', function(element) {
  1903. chekEmptyVal(\'.__FMPEmptyCheck\');
  1904. });
  1905. $(\'#refresh_' . $presetsSelectorId . '\').click(function(evt) {
  1906. refreshFMPSelector();
  1907. });
  1908. $(\'#' . $presetsSelectorId . '\').change(function(evt) {
  1909. distributePresetValue($(this).val());
  1910. });
  1911. $(\'#BankstaTryGuessContract\').change(function () {
  1912. if ( $(\'#BankstaTryGuessContract\').is(\':checked\') ) {
  1913. $(\'#BankstaContractGuessingBlock\').show();
  1914. } else {
  1915. $(\'#BankstaContractGuessingBlock\').hide();
  1916. }
  1917. });
  1918. $(\'#BankstaSrvType\').change(function () {
  1919. if ( $(\'#BankstaSrvType\').val() == \'Telepathy\' ) {
  1920. $(\'#BankstaServiceGuessingBlock\').show();
  1921. } else {
  1922. $(\'#BankstaServiceGuessingBlock\').hide();
  1923. }
  1924. });
  1925. $(\'#BankstaSkipRow\').change(function () {
  1926. if ( $(\'#BankstaSkipRow\').is(\':checked\') ) {
  1927. $(\'#BankstaSkipRowBlock\').show();
  1928. } else {
  1929. $(\'#BankstaSkipRowBlock\').hide();
  1930. }
  1931. });
  1932. $(\'#BankstaReplaceStrs\').change(function () {
  1933. if ( $(\'#BankstaReplaceStrs\').is(\':checked\') ) {
  1934. $(\'#BankstaReplaceStrsBlock\').show();
  1935. } else {
  1936. $(\'#BankstaReplaceStrsBlock\').hide();
  1937. }
  1938. });
  1939. $(\'#BankstaRemoveStrs\').change(function () {
  1940. if ( $(\'#BankstaRemoveStrs\').is(\':checked\') ) {
  1941. $(\'#BankstaRemoveStrsBlock\').show();
  1942. } else {
  1943. $(\'#BankstaRemoveStrsBlock\').hide();
  1944. }
  1945. });
  1946. $(document).ready(function() {
  1947. $(\'#BankstaContractGuessingBlock\').hide();
  1948. $(\'#BankstaServiceGuessingBlock\').hide();
  1949. $(\'#BankstaSkipRowBlock\').hide();
  1950. $(\'#BankstaReplaceStrsBlock\').hide();
  1951. $(\'#BankstaRemoveStrsBlock\').hide();
  1952. });
  1953. ';
  1954. $inputs.= wf_tag('script', true);
  1955. $inputs.= wf_HiddenInput('import_rawdata', base64_encode(serialize($dataParsed)));
  1956. $inputs.= wf_delimiter(0);
  1957. $inputs.= wf_Submit('Save this column mappings and continue payments import');
  1958. $colForm = wf_Form("?module=banksta2", 'POST', $inputs, 'glamour __Banksta2PreprocessingForm');
  1959. show_window(__('Select data columns numbers and their values mapping'), $savePresetForm . $colForm);
  1960. } else {
  1961. show_error(__('File parsing error: data array is empty'));
  1962. }
  1963. }
  1964. /**
  1965. * Renders a "last checks form" with all the actual payments data that will be imported
  1966. *
  1967. * @param $dataRows
  1968. */
  1969. public function web_LastChecksForm($dataRows) {
  1970. if ($this->translateLstChkFieldNames) {
  1971. $captContract = __('Contract');
  1972. $captSumm = __('Sum');
  1973. $captAddr = __('Address');
  1974. $captRealName = __('Real name');
  1975. $captNotes = __('Payment notes');
  1976. $captPDate = __('Payment date');
  1977. $captPTime = __('Payment time');
  1978. $captSrvType = __('Service type');
  1979. $captCanceled = __('Processing canceled');
  1980. } else {
  1981. $captContract = '[contract]';
  1982. $captSumm = '[summ]';
  1983. $captAddr = '[address]';
  1984. $captRealName = '[realname]';
  1985. $captNotes = '[notes]';
  1986. $captPDate = '[pdate]';
  1987. $captPTime = '[ptime]';
  1988. $captSrvType = '[service_type]';
  1989. $captCanceled = '[row_canceled]';
  1990. }
  1991. $cells = wf_TableCell('#');
  1992. $cells.= wf_TableCell($captContract);
  1993. $cells.= wf_TableCell($captSumm);
  1994. $cells.= wf_TableCell($captAddr);
  1995. $cells.= wf_TableCell($captRealName);
  1996. $cells.= wf_TableCell($captNotes);
  1997. $cells.= wf_TableCell($captPDate);
  1998. $cells.= wf_TableCell($captPTime);
  1999. $cells.= wf_TableCell($captSrvType);
  2000. $cells.= wf_TableCell($captCanceled);
  2001. $rows = wf_TableRow($cells, 'row1');
  2002. $table = wf_TableBody($rows . $dataRows, '100%', '0', '');
  2003. $inputs = wf_Link(self::URL_BANKSTA2_FIELD_MAPPING, 'No I want to try another import settings', false, 'ubButton');
  2004. $inputs.= wf_nbsp(2);
  2005. $inputs.= wf_Link(self::URL_BANKSTA2_PROCEED_STMT_IMP, 'Yes, proceed payments import', false, 'ubButton');
  2006. show_window(__('All is correct') . '?', $table . wf_delimiter(1) . $inputs);
  2007. }
  2008. /**
  2009. * Shows the fields mapping presets form
  2010. *
  2011. * @return void
  2012. */
  2013. public static function web_FMPForm() {
  2014. $lnkId = wf_InputId();
  2015. $addServiceJS = wf_tag('script', false, '', 'type="text/javascript"');
  2016. $addServiceJS.= wf_JSAjaxModalOpener(self::URL_ME, array('fmpcreate' => 'true'), $lnkId, false, 'POST');
  2017. $addServiceJS.= wf_tag('script', true);
  2018. show_window(__('Fields mapping presets'), wf_Link('#', web_add_icon() . ' ' .
  2019. __('Add fields mapping preset'), false, 'ubButton', 'id="' . $lnkId . '"') .
  2020. wf_delimiter() . $addServiceJS . self::renderFMPJQDT()
  2021. );
  2022. }
  2023. /**
  2024. * Renders a processing form for certain statement determined by hash
  2025. *
  2026. * @param $hash
  2027. *
  2028. * @return string
  2029. */
  2030. public function web_BSProcessingForm($hash) {
  2031. $hash = mysql_real_escape_string($hash);
  2032. if ($this->checkHashExists($hash)) {
  2033. $tQuery = "SELECT * FROM `" . self::BANKSTA2_TABLE . "` WHERE `hash`='" . $hash . "' ORDER BY `id` ASC;";
  2034. $tQueryResult = simple_queryall($tQuery);
  2035. $cashPairs = array();
  2036. $tServices = array('' => __('-'),
  2037. 'Internet' => __('Internet'),
  2038. 'UKV' => __('UKV')
  2039. );
  2040. $dreamkasEnabled = $this->ubConfig->getAlterParam('DREAMKAS_ENABLED');
  2041. $fiscalRecsIDsList = array();
  2042. $addFiscalizePaymentCtrlsJS = false;
  2043. $refiscalize = false;
  2044. if ($dreamkasEnabled) {
  2045. $DreamKas = new DreamKas();
  2046. }
  2047. $cells = wf_TableCell(__('ID'));
  2048. $cells .= wf_TableCell(__('Statement Address'));
  2049. $cells .= wf_TableCell(__('Statement Real Name'));
  2050. $cells .= wf_TableCell(__('Statement Contract'));
  2051. $cells .= wf_TableCell(__('Service type'));
  2052. $cells .= wf_TableCell(__('Edit record'));
  2053. $cells .= wf_TableCell(__('Payment type ID'));
  2054. $cells .= wf_TableCell(__('Cash'));
  2055. $cells .= wf_TableCell(__('Processed'));
  2056. $cells .= wf_TableCell(__('Canceled'));
  2057. $cells .= wf_TableCell(__('Contract'));
  2058. $cells .= wf_TableCell(__('Real Name'));
  2059. $cells .= wf_TableCell(__('Address'));
  2060. $cells .= wf_TableCell(__('Tariff'));
  2061. $rows = wf_TableRow($cells, 'row1');
  2062. if (!empty($tQueryResult)) {
  2063. $this->getUsersDataCached();
  2064. foreach ($tQueryResult as $io => $eachRec) {
  2065. $recProcessed = ($eachRec['processed']) ? true : false;
  2066. $recCanceled = ($eachRec['canceled']) ? true : false;
  2067. $serviceType = trim($eachRec['service_type']);
  2068. $addrIsEmpty = empty($eachRec['address']);
  2069. $nameIsEmpty = empty($eachRec['realname']);
  2070. $contractUnknown = (empty($eachRec['contract']) or ispos($eachRec['contract'], 'unknown_'));
  2071. $detailsWinID = wf_InputId();
  2072. $lnkID = wf_InputId();
  2073. $addInfoControl = wf_Link('#', $eachRec['id'], false, '', ' id="' . $lnkID . '" ');
  2074. $addInfoControl .= wf_tag('script', false, '', 'type="text/javascript"');
  2075. $addInfoControl .= '$(\'#' . $lnkID . '\').click(function(evt) {
  2076. $.ajax({
  2077. type: "GET",
  2078. url: "' . self::URL_ME . '",
  2079. data: {
  2080. showdetailed: "' . $eachRec['id'] . '",
  2081. detailsWinID: "' . $detailsWinID . '"
  2082. },
  2083. success: function(result) {
  2084. $(document.body).append(result);
  2085. $( \'#' . $detailsWinID . '\' ).dialog("open");
  2086. }
  2087. });
  2088. evt.preventDefault();
  2089. return false;
  2090. });
  2091. ';
  2092. $addInfoControl .= wf_tag('script', true);
  2093. $cells = wf_TableCell($addInfoControl, '', '', '', '', (($dreamkasEnabled) ? '2' : ''));
  2094. if (($addrIsEmpty or $nameIsEmpty or $contractUnknown) and !empty($eachRec['notes'])) {
  2095. if ($addrIsEmpty or $contractUnknown) {
  2096. $cells .= wf_TableCell($eachRec['notes']);
  2097. $cells .= wf_TableCell('');
  2098. } else {
  2099. $cells .= wf_TableCell('');
  2100. $cells .= wf_TableCell($eachRec['notes']);
  2101. }
  2102. } else {
  2103. $cells .= wf_TableCell($eachRec['address']);
  2104. $cells .= wf_TableCell($eachRec['realname']);
  2105. }
  2106. if ($recProcessed) {
  2107. if ($recCanceled) {
  2108. $editInputs = wf_CheckInput('recallrowprocessing', __('Recall record processing'), false, false);
  2109. $editInputs .= wf_HiddenInput('bankstaeditrowid', $eachRec['id']);
  2110. $editInputs .= wf_delimiter(0);
  2111. $editInputs .= wf_Submit(__('Save'));
  2112. $editForm = wf_Form('', 'POST', $editInputs);
  2113. } else {
  2114. $editForm = __('Record processed');
  2115. }
  2116. $cells .= wf_TableCell($eachRec['contract']);
  2117. $cells .= wf_TableCell($serviceType);
  2118. $cells .= wf_TableCell($editForm);
  2119. } else {
  2120. $formID = wf_InputId();
  2121. $cells .= wf_TableCell(wf_TextInput('newbankstacontract', '', $eachRec['contract'], false, '6', '', '', '', 'form="' . $formID . '"'));
  2122. $cells .= wf_TableCell(wf_Selector('newbankstarvtype', $tServices, '', $serviceType, '', '', '', '', 'form="' . $formID . '"'));
  2123. $editInputs = wf_CheckInput('cancelrowprocessing', __('Cancel record processing'), false, false);
  2124. $editInputs .= wf_HiddenInput('bankstaeditrowid', $eachRec['id']);
  2125. $editInputs .= wf_delimiter(0);
  2126. $editInputs .= wf_Submit(__('Save'));
  2127. $editForm = wf_Form('', 'POST', $editInputs, '', '', $formID);
  2128. $cells .= wf_TableCell($editForm);
  2129. }
  2130. $cells .= wf_TableCell($eachRec['payid']);
  2131. $cells .= wf_TableCell($eachRec['summ']);
  2132. $cells .= wf_TableCell(web_bool_led($recProcessed));
  2133. $cells .= wf_TableCell(web_bool_led($recCanceled));
  2134. //user detection
  2135. $detectedContract = '';
  2136. $detectedAddress = '';
  2137. $detectedRealName = '';
  2138. $detectedTariff = '';
  2139. $rowClass = ($recProcessed) ? 'row2' : 'undone';
  2140. switch (strtolower($serviceType)) {
  2141. case ('internet'):
  2142. if (isset($this->allContractsInet[$eachRec['contract']])) {
  2143. $detectedUser = $this->allUsersDataInet[$this->allContractsInet[$eachRec['contract']]];
  2144. $detectedContract = wf_Link(self::URL_USERS_PROFILE_INET . $detectedUser['login'], web_profile_icon() . ' ' . $detectedUser['contract'], false, '');
  2145. $detectedAddress = $detectedUser['fulladress'];
  2146. $detectedRealName = $detectedUser['realname'];
  2147. $detectedTariff = $detectedUser['Tariff'];
  2148. if (!$recProcessed) {
  2149. $cashPairs[$eachRec['id']]['bankstaid'] = $eachRec['id'];
  2150. $cashPairs[$eachRec['id']]['userlogin'] = $detectedUser['login'];
  2151. $cashPairs[$eachRec['id']]['usercontract'] = $detectedUser['contract'];
  2152. $cashPairs[$eachRec['id']]['summ'] = $eachRec['summ'];
  2153. $cashPairs[$eachRec['id']]['pdate'] = $eachRec['pdate'];
  2154. $cashPairs[$eachRec['id']]['ptime'] = $eachRec['ptime'];
  2155. $cashPairs[$eachRec['id']]['payid'] = (empty($eachRec['payid'])) ? $this->inetPaymentId : $eachRec['payid'];
  2156. $cashPairs[$eachRec['id']]['service'] = $serviceType;
  2157. $fiscalRecsIDsList[] = $eachRec['id'];
  2158. }
  2159. $rowClass = 'row3';
  2160. //try to highlight multiple payments
  2161. if (!isset($this->bankstaFoundUsers[$eachRec['contract']])) {
  2162. $this->bankstaFoundUsers[$eachRec['contract']] = $detectedUser['login'];
  2163. } else {
  2164. $rowClass = 'ukvbankstadup';
  2165. }
  2166. }
  2167. break;
  2168. case ('ukv'):
  2169. if (isset($this->allContractsUKV[$eachRec['contract']])) {
  2170. $detectedUser = $this->allUsersDataUKV[$this->allContractsUKV[$eachRec['contract']]];
  2171. $detectedContract = wf_Link(self::URL_USERS_PROFILE_UKV . $detectedUser['id'], web_profile_icon() . ' ' . $detectedUser['contract'], false, '');
  2172. $detectedAddress = $detectedUser['street'] . ' ' . $detectedUser['build'] . '/' . $detectedUser['apt'];
  2173. $detectedRealName = $detectedUser['realname'];
  2174. $detectedTariff = $detectedUser['tariffid'];
  2175. $detectedTariff = $this->ukvTariffs[$detectedTariff]['tariffname'];
  2176. if (!$recProcessed) {
  2177. $cashPairs[$eachRec['id']]['bankstaid'] = $eachRec['id'];
  2178. $cashPairs[$eachRec['id']]['userlogin'] = $detectedUser['id'];
  2179. $cashPairs[$eachRec['id']]['usercontract'] = $detectedUser['contract'];
  2180. $cashPairs[$eachRec['id']]['summ'] = $eachRec['summ'];
  2181. $cashPairs[$eachRec['id']]['pdate'] = $eachRec['pdate'];
  2182. $cashPairs[$eachRec['id']]['ptime'] = $eachRec['ptime'];
  2183. $cashPairs[$eachRec['id']]['payid'] = (empty($eachRec['payid'])) ? $this->ukvPaymentId : $eachRec['payid'];
  2184. $cashPairs[$eachRec['id']]['service'] = $serviceType;
  2185. $fiscalRecsIDsList[] = $eachRec['id'];
  2186. }
  2187. $rowClass = 'row3';
  2188. //try to highlight multiple payments
  2189. if (!isset($this->bankstaFoundUsers[$eachRec['contract']])) {
  2190. $this->bankstaFoundUsers[$eachRec['contract']] = $detectedUser['id'];
  2191. } else {
  2192. $rowClass = 'ukvbankstadup';
  2193. }
  2194. }
  2195. break;
  2196. default:
  2197. // maybe sometime in future here would be some defaults
  2198. }
  2199. $cells.= wf_TableCell($detectedContract);
  2200. $cells.= wf_TableCell($detectedRealName);
  2201. $cells.= wf_TableCell($detectedAddress);
  2202. $cells.= wf_TableCell($detectedTariff);
  2203. $rows.= wf_TableRow($cells, $rowClass);
  2204. // dreamkas fiscalizing controls
  2205. if ($dreamkasEnabled) {
  2206. $dreamkasCtrls = '';
  2207. if ($recProcessed) {
  2208. if ($recCanceled) {
  2209. $dreamkasCtrls = wf_TableRow('');
  2210. } else {
  2211. // geting fiscalized data
  2212. $dreamkasCtrls = $DreamKas->web_ReceiptDetailsTableRow($eachRec['id']);
  2213. if (empty($dreamkasCtrls)) {
  2214. $refiscalize = true;
  2215. }
  2216. }
  2217. }
  2218. if (empty($dreamkasCtrls)) {
  2219. $addFiscalizePaymentCtrlsJS = true;
  2220. $dreamkasCtrls = $DreamKas->web_FiscalizePaymentCtrls($serviceType, true, $eachRec['id'], $recProcessed);
  2221. $dreamkasCtrls.= $DreamKas->web_FiscalOperationDetailsTableRow($eachRec['id']);
  2222. }
  2223. $rows.= $dreamkasCtrls;
  2224. }
  2225. }
  2226. }
  2227. $result = wf_TableBody($rows, '100%', '0', '');
  2228. $result.= ($addFiscalizePaymentCtrlsJS) ? $DreamKas->get_BS2FiscalizePaymentCtrlsJS() : '';
  2229. if (!empty($cashPairs) or $refiscalize) {
  2230. $cashInputs = '';
  2231. $formID = wf_InputId();
  2232. $submitID = wf_InputId();
  2233. $submitID2 = wf_InputId();
  2234. $fiscalizeallChkID = wf_InputId();
  2235. $submitCaption = __('Process current bank statement');
  2236. $submitCaption2 = __('Re-fiscalize payments');
  2237. $fiscalizeallChkCapt = __('Check to fiscalize all');
  2238. $unfiscalizeallChkCapt = __('Clear check to fiscalize all');
  2239. if ($dreamkasEnabled and (!empty($cashPairs) or $refiscalize)) {
  2240. //$cashInputs.= wf_delimiter(0);
  2241. $cashInputs.= wf_CheckInput('fiscalizeall', $fiscalizeallChkCapt, false, false, $fiscalizeallChkID);
  2242. $cashInputs.= wf_delimiter();
  2243. }
  2244. if (!empty($cashPairs)) {
  2245. $cashPairs = serialize($cashPairs);
  2246. $cashPairs = base64_encode($cashPairs);
  2247. $cashInputs.= wf_HiddenInput('bankstaneedpaymentspush', $cashPairs);
  2248. $cashInputs.= ($dreamkasEnabled) ? wf_HiddenInput('bankstafiscalrecsidslist', base64_encode(json_encode($fiscalRecsIDsList))) : '';
  2249. $cashInputs.= wf_Submit($submitCaption, $submitID);
  2250. $cashInputs.= wf_nbsp(4);
  2251. } else {
  2252. $cashInputs.= wf_HiddenInput('bankstaneedpaymentspush', base64_encode(serialize('dummy_dump')));
  2253. }
  2254. if ($refiscalize) {
  2255. $cashInputs.= wf_Submit($submitCaption2, $submitID2);
  2256. $cashInputs.= wf_nbsp(2);
  2257. }
  2258. $cashInputs.= wf_HiddenInput('bankstaneedrefiscalize', 'false');
  2259. $cashInputs.= ($dreamkasEnabled) ? wf_HiddenInput('bankstapaymentsfiscalize', '') : '';
  2260. $result.= wf_Form('', 'POST', $cashInputs, 'glamour', '', $formID);
  2261. if ($dreamkasEnabled) {
  2262. $result.= wf_tag('script', false, '', 'type="text/javascript"');
  2263. $result.= wf_JSEmptyFunc();
  2264. $result.= '
  2265. $(\'#' . $fiscalizeallChkID . '\').change(function() {
  2266. var checkVal = $(this).is(\':checked\');
  2267. $(\'[name^="fiscalizepayment_"]\').prop("checked", checkVal);
  2268. if (checkVal) {
  2269. $(\'label[for="' . $fiscalizeallChkID . '"]\').html(\'' . $unfiscalizeallChkCapt . '\');
  2270. } else {
  2271. $(\'label[for="' . $fiscalizeallChkID . '"]\').html(\'' . $fiscalizeallChkCapt . '\');
  2272. }
  2273. });
  2274. $(\'#' . $submitID2 . '\').on("click mouseup keyup", function(evt) {
  2275. $(\'[name="bankstaneedrefiscalize"]\').val("true");
  2276. });
  2277. $(\'#' . $formID . '\').submit(function(evt) {
  2278. $(\'#' . $submitID . '\').attr("disabled", "disabled");
  2279. $(\'#' . $submitID . '\').val("' . __('Form processing in progress') . '...' . '");
  2280. $(\'#' . $submitID2 . '\').attr("disabled", "disabled");
  2281. $(\'#' . $submitID2 . '\').val("' . __('Form processing in progress') . '...' . '");
  2282. var fiscalizationArr = {};
  2283. var refiscalize = ( $(\'[name="bankstaneedrefiscalize"]\').val() === "true" );
  2284. ';
  2285. $result.= ' if (!refiscalize) {
  2286. fiscalRecsIDsList = JSON.parse(atob($(\'[name="bankstafiscalrecsidslist"]\').val()));
  2287. }
  2288. ';
  2289. $result.= ' $(\'[name^="fiscalizepayment_"]\').each(function(chkindex, chkelement) {
  2290. if ($(chkelement).is(\':checked\')) {
  2291. checkCtrlID = $(chkelement).attr("id").substring($(chkelement).attr("id").indexOf(\'_\') + 1);
  2292. ';
  2293. $result.= ' if ( (refiscalize && $(chkelement).hasClass(\'__BankstaRecProcessed\'))
  2294. || (!refiscalize && $.inArray(checkCtrlID, fiscalRecsIDsList) != -1) ) {
  2295. fiscalizationArr[checkCtrlID] = {};
  2296. fiscalizationArr[checkCtrlID][\'drscashmachineid\'] = $(\'[name=drscashmachines_\'+checkCtrlID+\']\').val();
  2297. fiscalizationArr[checkCtrlID][\'drstaxtype\'] = $(\'[name=drstaxtypes_\'+checkCtrlID+\']\').val();
  2298. fiscalizationArr[checkCtrlID][\'drspaymtype\'] = $(\'[name=drspaymtypes_\'+checkCtrlID+\']\').val();
  2299. fiscalizationArr[checkCtrlID][\'drssellingpos\'] = $(\'[name=drssellpos_\'+checkCtrlID+\']\').val();
  2300. }
  2301. ';
  2302. $result.= ' }
  2303. });
  2304. if (refiscalize && empty(fiscalizationArr)) {
  2305. evt.preventDefault();
  2306. $(\'#' . $submitID . '\').removeAttr("disabled");
  2307. $(\'#' . $submitID . '\').val("' . $submitCaption . '");
  2308. $(\'#' . $submitID2 . '\').removeAttr("disabled");
  2309. $(\'#' . $submitID2 . '\').val("' . $submitCaption2 . '");
  2310. alert(\'' . __('No records to re-fiscalize chosen') . '\');
  2311. return false;
  2312. }
  2313. $(\'[name="bankstapaymentsfiscalize"]\').val(btoa(JSON.stringify(fiscalizationArr)));
  2314. });
  2315. ';
  2316. $result.= wf_tag('script', true);
  2317. } else {
  2318. $result.= wf_tag('script', false, '', 'type="text/javascript"');
  2319. $result.= '
  2320. $(\'#' . $formID . '\').submit(function(evt) {
  2321. $(\'#' . $submitID . '\').attr("disabled", "disabled");
  2322. $(\'#' . $submitID . '\').val("' . __('Form processing in progress') . '...' . '");
  2323. });
  2324. ';
  2325. $result.= wf_tag('script', true);
  2326. }
  2327. }
  2328. } else {
  2329. $result = $this->getUbMsgHelperInstance()->getStyledMessage(__('Specified bank statement hash does not exists'), 'warning');
  2330. }
  2331. return ($result);
  2332. }
  2333. /**
  2334. * Renders uploaded statements ajax list JSON for JQDT
  2335. */
  2336. public static function renderBStatementsListJSON() {
  2337. $tQuery = "SELECT `filename`, `hash`, `date`, `admin`,
  2338. COUNT(`id`) AS `rowcount`, COUNT(if(`processed` > 0 and `canceled` <= 0, 1, null)) AS processed_cnt, COUNT(if(`canceled` > 0, 1, null)) AS canceled_cnt
  2339. FROM `" . self::BANKSTA2_TABLE . "` GROUP BY `hash` ORDER BY `date` DESC;";
  2340. $tQueryResult = simple_queryall($tQuery);
  2341. $json = new wf_JqDtHelper();
  2342. if (!empty($tQueryResult)) {
  2343. $data = array();
  2344. foreach ($tQueryResult as $eachRec) {
  2345. $data[] = $eachRec['date'];
  2346. $data[] = $eachRec['filename'];
  2347. $data[] = $eachRec['rowcount'];
  2348. $data[] = $eachRec['processed_cnt'];
  2349. $data[] = $eachRec['canceled_cnt'];
  2350. $data[] = $eachRec['admin'];
  2351. $actions = wf_Link(self::URL_BANKSTA2_PROCESSING . $eachRec['hash'], wf_img('skins/icon_search_small.gif', __('Show')), false, '');
  2352. if ($eachRec['processed_cnt'] == 0) {
  2353. $actions.= wf_JSAlert( '#', web_delete_icon(), 'Removing this may lead to irreparable results', 'deleteStatement(\'' . $eachRec['hash'] . '\', \'' . self::URL_ME . '\', \'delStatement\', \'' . wf_InputId() . '\')') . wf_nbsp();
  2354. }
  2355. $data[] = $actions;
  2356. $json->addRow($data);
  2357. unset($data);
  2358. }
  2359. }
  2360. $json->getJson();
  2361. }
  2362. /**
  2363. * Returns uploaded statements JQDT control
  2364. *
  2365. * @return string
  2366. */
  2367. public static function renderBStatementsJQDT() {
  2368. $ajaxUrlStr = '' . self::URL_ME . '&bslistajax=true';
  2369. $jqdtId = 'jqdt_' . md5($ajaxUrlStr);
  2370. $columns = array(__('Date'), __('Filename'), __('Total rows'), __('Processed rows'), __('Canceled rows'), __('Admin'), __('Actions'));
  2371. $opts = '"order": [[ 0, "desc" ]]';
  2372. $result = '';
  2373. $result.= wf_JqDtLoader($columns, $ajaxUrlStr, false, __('Bank statement'), 50, $opts);
  2374. $result.= wf_tag('script', false, '', 'type="text/javascript"');
  2375. $result.= wf_JSEmptyFunc();
  2376. $result.= wf_JSElemInsertedCatcherFunc();
  2377. $result.= '
  2378. function deleteStatement(bankstaHash, ajaxURL, actionName, errFrmId) {
  2379. var ajaxData = \'&\'+ actionName +\'=true&hash=\' + bankstaHash + \'&errfrmid=\' + errFrmId
  2380. $.ajax({
  2381. type: "POST",
  2382. url: ajaxURL,
  2383. data: ajaxData,
  2384. success: function(result) {
  2385. if ( !empty(result) ) {
  2386. $(document.body).append(result);
  2387. $(\'#\'+errFrmId).dialog("open");
  2388. }
  2389. $(\'#' . $jqdtId . '\').DataTable().ajax.reload();
  2390. }
  2391. });
  2392. }
  2393. ';
  2394. $result.= wf_tag('script', true);
  2395. return ($result);
  2396. }
  2397. /**
  2398. * Renders fields mapping presets ajax list JSON for JQDT
  2399. */
  2400. public static function renderFMPListJSON() {
  2401. $tQuery = "SELECT `id`, `presetname`, `payment_type_id`, `col_realname`, `col_address`, `col_paysum`, `col_paypurpose`,
  2402. `col_paydate`, `col_paytime`, `col_contract`, `guess_contract`, `skip_row`,
  2403. `replace_strs`, `remove_strs`, `service_type`
  2404. FROM `" . self::BANKSTA2_PRESETS_TABLE . "`";
  2405. $tQueryResult = simple_queryall($tQuery);
  2406. $json = new wf_JqDtHelper();
  2407. if (!empty($tQueryResult)) {
  2408. $data = array();
  2409. $fmpID = 0;
  2410. foreach ($tQueryResult as $eachRec) {
  2411. foreach ($eachRec as $fieldName => $fieldVal) {
  2412. switch ($fieldName) {
  2413. case 'id':
  2414. $fmpID = $fieldVal;
  2415. $data[] = $fieldVal;
  2416. break;
  2417. case 'guess_contract':
  2418. case 'skip_row':
  2419. case 'replace_strs':
  2420. case 'remove_strs':
  2421. $data[] = ($fieldVal == 1) ? web_green_led() : web_red_led();
  2422. break;
  2423. default:
  2424. $data[] = $fieldVal;
  2425. }
  2426. }
  2427. $linkId1 = wf_InputId();
  2428. $linkId2 = wf_InputId();
  2429. $actions = wf_JSAlert( '#', web_delete_icon(), 'Removing this may lead to irreparable results', 'deleteFMP(' . $eachRec['id'] . ', \'' . self::URL_ME . '\', \'delFMP\', \'' . wf_InputId() . '\')') . wf_nbsp();
  2430. $actions.= wf_Link('#', web_edit_icon(), false, '', 'id="' . $linkId1 . '"') . wf_nbsp();
  2431. $actions.= wf_Link('#', web_clone_icon(), false, '', 'id="' . $linkId2 . '"') . wf_nbsp();
  2432. $actions.= wf_JSAjaxModalOpener(self::URL_ME, array('fmpedit' => 'true', 'fmpid' => $fmpID), $linkId1, true, 'POST');
  2433. $actions.= wf_JSAjaxModalOpener(self::URL_ME, array('fmpclone' => 'true', 'fmpid' => $fmpID), $linkId2, true, 'POST');
  2434. $data[] = $actions;
  2435. $json->addRow($data);
  2436. unset($data);
  2437. }
  2438. }
  2439. $json->getJson();
  2440. }
  2441. /**
  2442. * Returns fields mapping presets JQDT control and some JS bindings for dynamic forms
  2443. *
  2444. * @return string
  2445. */
  2446. protected static function renderFMPJQDT() {
  2447. $ajaxUrlStr = '' . self::URL_ME . '&fmpajax=true';
  2448. $jqdtId = 'jqdt_' . md5($ajaxUrlStr);
  2449. $errorModalWindowId = wf_InputId();
  2450. $columns = array();
  2451. $opts = '"order": [[ 0, "asc" ]],
  2452. "columnDefs": [ {"targets": "_all", "className": "dt-center"} ]';
  2453. $columns[] = __('ID');
  2454. $columns[] = __('Preset name');
  2455. $columns[] = __('Payment type ID');
  2456. $columns[] = __('Realname column');
  2457. $columns[] = __('Address column');
  2458. $columns[] = __('Paysum column');
  2459. $columns[] = __('Paypurpose column');
  2460. $columns[] = __('Paydate column');
  2461. $columns[] = __('Paytime column');
  2462. $columns[] = __('Contract column');
  2463. $columns[] = __('Contract guessing');
  2464. $columns[] = __('Row skipping');
  2465. $columns[] = __('Char replacing');
  2466. $columns[] = __('Char removing');
  2467. $columns[] = __('Service type');
  2468. $columns[] = __('Actions');
  2469. $result = wf_JqDtLoader($columns, $ajaxUrlStr, false, __('results'), 100, $opts);
  2470. $result.= wf_tag('script', false, '', 'type="text/javascript"');
  2471. $result.= wf_JSEmptyFunc();
  2472. $result.= wf_JSElemInsertedCatcherFunc();
  2473. $result.= ' function chekEmptyVal(ctrlClassName) {
  2474. $(document).on("focus keydown", ctrlClassName, function(evt) {
  2475. if ( $(ctrlClassName).css("border-color") == "rgb(255, 0, 0)" ) {
  2476. $(ctrlClassName).val("");
  2477. $(ctrlClassName).css("border-color", "");
  2478. $(ctrlClassName).css("color", "");
  2479. }
  2480. });
  2481. }
  2482. onElementInserted(\'body\', \'.__FMPEmptyCheck\', function(element) {
  2483. chekEmptyVal(\'.__FMPEmptyCheck\');
  2484. });
  2485. $(document).on("submit", ".__FMPForm", function(evt) {
  2486. var FrmAction = $(".__FMPForm").attr("action");
  2487. var FrmData = $(".__FMPForm").serialize() + \'&errfrmid=' . $errorModalWindowId . '\';
  2488. //var modalWindowId = $(".__FMPForm").closest(\'div\').attr(\'id\');
  2489. evt.preventDefault();
  2490. var emptyCheckClass = \'.__FMPEmptyCheck\';
  2491. if ( empty( $(emptyCheckClass).val() ) || $(emptyCheckClass).css("border-color") == "rgb(255, 0, 0)" ) {
  2492. $(emptyCheckClass).css("border-color", "red");
  2493. $(emptyCheckClass).css("color", "grey");
  2494. $(emptyCheckClass).val("' . __('Mandatory field') . '");
  2495. } else {
  2496. $.ajax({
  2497. type: "POST",
  2498. url: FrmAction,
  2499. data: FrmData,
  2500. success: function(result) {
  2501. if ( !empty(result) ) {
  2502. $(document.body).append(result);
  2503. $( \'#' . $errorModalWindowId . '\' ).dialog("open");
  2504. } else {
  2505. $(\'#' . $jqdtId . '\').DataTable().ajax.reload();
  2506. //$("[name=swgroupname]").val("");
  2507. if ( $(".__CloseFrmOnSubmitChk").is(\':checked\') ) {
  2508. $( \'#\'+$(".__FMPFormModalWindowId").val() ).dialog("close");
  2509. }
  2510. }
  2511. }
  2512. });
  2513. }
  2514. });
  2515. function deleteFMP(FMPId, ajaxURL, actionName, errFrmId) {
  2516. var ajaxData = \'&\'+ actionName +\'=true&fmpid=\' + FMPId + \'&errfrmid=\' + errFrmId
  2517. $.ajax({
  2518. type: "POST",
  2519. url: ajaxURL,
  2520. data: ajaxData,
  2521. success: function(result) {
  2522. if ( !empty(result) ) {
  2523. $(document.body).append(result);
  2524. $(\'#\'+errFrmId).dialog("open");
  2525. }
  2526. $(\'#' . $jqdtId . '\').DataTable().ajax.reload();
  2527. }
  2528. });
  2529. }
  2530. ';
  2531. $result.= wf_tag('script', true);
  2532. return ($result);
  2533. }
  2534. /**
  2535. * Returns field mapping preset addition form
  2536. *
  2537. * @return string
  2538. */
  2539. public function renderFMPAddForm($modalWindowId) {
  2540. $formId = 'Form_' . wf_InputId();
  2541. $closeFormChkId = 'CloseFrmChkID_' . wf_InputId();
  2542. $inputs = wf_TextInput('fmpname', __('Preset name'), '', false, '', '', '__FMPEmptyCheck');
  2543. $inputs.= wf_nbsp(8);
  2544. $inputs.= wf_TextInput('fmppaymtypeid', __('Custom payment type ID for this bank statement'), 0, true, '4', 'digits', '', 'BankstaPaymentTypeID');
  2545. $inputscells = wf_TableCell(wf_TextInput('fmpcolrealname', __('Real name column number'), 'NONE', false, '4'));
  2546. $inputscells.= wf_TableCell(wf_TextInput('fmpcoladdr', __('Address column number'), 'NONE', false, '4'));
  2547. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaysum', __('Payment sum column number'), 'NONE', false, '4'));
  2548. $inputsrows = wf_TableRow($inputscells);
  2549. $inputscells = wf_TableCell(wf_TextInput('fmpcolpaypurpose', __('Payment purpose column number'), 'NONE', false, '4'));
  2550. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaydate', __('Payment date column number'), 'NONE', false, '4'));
  2551. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaytime', __('Payment time column number'), 'NONE', true, '4'));
  2552. $inputsrows.= wf_TableRow($inputscells);
  2553. $inputscells = wf_TableCell(wf_CheckInput('fmppaymincoins', __('Bank statement "SUM" field presented in coins(need to be divided by 100)'), true, false, 'BankstaPaymInCoins'), '', '', '', '2');
  2554. $inputsrows.= wf_TableRow($inputscells);
  2555. $inputs.= wf_TableBody($inputsrows, '', '0', '', 'cellspacing="4px" style="margin-top: 8px;"');
  2556. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2557. $inputs.= wf_TextInput('fmpcolcontract', __('User contract column number') . ' (' . __('Payment ID') . ')', 'NONE', true, '4');
  2558. $inputs.= wf_CheckInput('fmptryguesscontract', __('Try to get contract from payment purpose field'), true, false, 'BankstaTryGuessContract');
  2559. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 800px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2560. $inputs.= __('ONLY, if mapped contract field for some row will be empty or if contract field will be not specified');
  2561. $inputs.= wf_tag('h4', true);
  2562. $inputs.= wf_TextInput('fmpcontractdelimstart', __('Contract') . ' (' . __('Payment ID') . '): ' . __('start delimiter string'), '', true, '', '', '', 'BankstaContractDelimStart');
  2563. $inputs.= wf_TextInput('fmpcontractdelimend', __('Contract') . ' (' . __('Payment ID') . '): ' . __('end delimiter string'), '', true, '', '', '', 'BankstaContractDelimEnd');
  2564. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 800px; padding: 11px 0 7px 0; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2565. $inputs.= __('If your contracts(payment IDs) are 100% DIGITAL - you may specify their minimum and maximum length to extract them properly(delimiters will not be taken into account)');
  2566. $inputs.= wf_tag('h4', true);
  2567. $inputs.= wf_TextInput('fmpcontractminlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('min length'), '0', true, '', '', '', 'BankstaContractMinLen');
  2568. $inputs.= wf_TextInput('fmpcontractmaxlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('max length'), '0', true, '', '', '', 'BankstaContractMaxLen');
  2569. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2570. $inputs.= wf_Selector('fmpsrvtype', $this->bankstaServiceType, __('Service type') . ' (' . __('select "Telepathy" to try to get service type from payment purpose field') . ')', '', true, false, 'BankstaSrvType');
  2571. $inputs.= wf_TextInput('fmpinetdelimstart', __('Internet service before keywords delimiter string'), '', true, '', '', '', 'BankstaInetDelimStart');
  2572. $inputs.= wf_TextInput('fmpinetkeywords', __('Internet service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaInetKeyWords');
  2573. $inputs.= wf_TextInput('fmpinetdelimend', __('Internet service after keywords delimiter string'), '', true, '', '', '', 'BankstaInetDelimEnd');
  2574. $inputs.= wf_CheckInput('fmpinetkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaInetKeyWordsNoEsc');
  2575. $inputs.= wf_delimiter(0);
  2576. $inputs.= wf_TextInput('fmpukvdelimstart', __('UKV service before keywords delimiter string'), '', true, '', '', '', 'BankstaUKVDelimStart');
  2577. $inputs.= wf_TextInput('fmpukvkeywords', __('UKV service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaUKVKeyWords');
  2578. $inputs.= wf_TextInput('fmpukvdelimend', __('UKV service after keywords delimiter string'), '', true, '', '', '', 'BankstaUKVDelimEnd');
  2579. $inputs.= wf_CheckInput('fmpukvkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaUKVKeyWordsNoEsc');
  2580. $inputs.= wf_delimiter(0);
  2581. $inputs.= wf_TextInput('fmpcolsrvidents', __('Number of the dedicated field which contains services IDs identifiers mapped via BANKSTA2_INETSRV_ALLOTED_IDS and BANKSTA2_CTVSRV_ALLOTED_IDS'), 'NONE', true, '4');
  2582. $inputs.= wf_CheckInput('fmpsrvidentspreff', __('Services IDs identifiers from the dedicated field take precedence over service type telepathy'), true, false, 'BankstaSrvIdentsPreff');
  2583. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 980px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2584. $inputs.= __('NOTE: dedicated field\'s services IDs are always take precedence over manually chosen \'Internet\' or \'UKV\' services');
  2585. $inputs.= wf_tag('h4', true);
  2586. $inputs.= wf_delimiter(0);
  2587. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2588. $inputs.= wf_CheckInput('fmpskiprow', __('Skip row processing if specified fields contain keywords below'), true, false, 'BankstaSkipRow');
  2589. $inputs.= wf_TextInput('fmpcolskiprow', __('Fields to check row skipping') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaSkipRowKeyWordsCol');
  2590. $inputs.= wf_TextInput('fmpskiprowkeywords', __('Row skipping determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaSkipRowKeyWords');
  2591. $inputs.= wf_CheckInput('fmpskiprokeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaSkipRowKeyWordsNoEsc');
  2592. $inputs.= wf_delimiter(0);
  2593. $inputs.= wf_CheckInput('fmpreplacestrs', __('Replace characters specified below in specified fields'), true, false, 'BankstaReplaceStrs');
  2594. $inputs.= wf_TextInput('fmpcolsreplacestrs', __('Fields to perform replacing') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaReplaceStrsCols');
  2595. $inputs.= wf_TextInput('fmpstrstoreplace', __('Replaced characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaReplaceStrsChars');
  2596. $inputs.= wf_TextInput('fmpstrstoreplacewith', __('Replacing characters or string'), '', true, '40', '', '', 'BankstaReplaceStrsWith');
  2597. $inputs.= wf_TextInput('fmpstrsreplacecount', __('Replacements count'), '', true, '40', '', '', 'BankstaReplaceStrsCount');
  2598. $inputs.= wf_CheckInput('fmpreplacekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaReplaceKeyWordsNoEsc');
  2599. $inputs.= wf_delimiter(0);
  2600. $inputs.= wf_CheckInput('fmpremovestrs', __('Remove characters specified below in specified fields'), true, false, 'BankstaRemoveStrs');
  2601. $inputs.= wf_TextInput('fmpcolsremovestrs', __('Fields to perform removing') . '(' . __('multiple fields must be separated with comas') . ')', '', true, '', '', '', 'BankstaRemoveStrsCols');
  2602. $inputs.= wf_TextInput('fmpstrstoremove', __('Removed characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', '', true, '40', '', '', 'BankstaRemoveStrsChars');
  2603. $inputs.= wf_CheckInput('fmpremovekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, false, 'BankstaRemoveKeyWordsNoEsc');
  2604. $inputs.= wf_delimiter(0);
  2605. $inputs.= wf_CheckInput('formclose', __('Close form after operation'), false, true, $closeFormChkId, '__CloseFrmOnSubmitChk');
  2606. $inputs.= wf_HiddenInput('', $modalWindowId, '', '__FMPFormModalWindowId');
  2607. $inputs.= wf_HiddenInput('fmpcreate', 'true');
  2608. $inputs.= wf_delimiter();
  2609. $inputs.= wf_Submit(__('Create'));
  2610. $form = wf_Form(self::URL_ME, 'POST', $inputs, 'glamour __FMPForm', '', $formId);
  2611. return ($form);
  2612. }
  2613. /**
  2614. * Returns field mapping preset editing form
  2615. *
  2616. * @return string
  2617. */
  2618. public function renderFMPEditForm($fmpID, $modalWindowId, $clone = false) {
  2619. $this->getMappingPresetsCached();
  2620. $formId = 'Form_' . wf_InputId();
  2621. $closeFormChkId = 'CloseFrmChkID_' . wf_InputId();
  2622. $fmpData = $this->fieldsMappingPresets[$fmpID];
  2623. $colRealName = (wf_emptyNonZero($fmpData['col_realname']) ? 'NONE' : $fmpData['col_realname']);
  2624. $colAddress = (wf_emptyNonZero($fmpData['col_address']) ? 'NONE' : $fmpData['col_address']);
  2625. $colPaysum = (wf_emptyNonZero($fmpData['col_paysum']) ? 'NONE' : $fmpData['col_paysum']);
  2626. $colPayPurpose = (wf_emptyNonZero($fmpData['col_paypurpose']) ? 'NONE' : $fmpData['col_paypurpose']);
  2627. $colPayDate = (wf_emptyNonZero($fmpData['col_paydate']) ? 'NONE' : $fmpData['col_paydate']);
  2628. $colPayTime = (wf_emptyNonZero($fmpData['col_paytime']) ? 'NONE' : $fmpData['col_paytime']);
  2629. $colContract = (wf_emptyNonZero($fmpData['col_contract']) ? 'NONE' : $fmpData['col_contract']);
  2630. $colSrvIdents = (wf_emptyNonZero($fmpData['col_srvidents']) ? 'NONE' : $fmpData['col_srvidents']);
  2631. $contractGuessing = (empty($fmpData['guess_contract'])) ? false : true;
  2632. $prefferSrvIdents = (empty($fmpData['srvidents_preffered'])) ? false : true;
  2633. $rowSkipping = (empty($fmpData['skip_row'])) ? false : true;
  2634. $strReplacing = (empty($fmpData['replace_strs'])) ? false : true;
  2635. $strRemoving = (empty($fmpData['remove_strs'])) ? false : true;
  2636. $sumInCoins = (empty($fmpData['sum_in_coins'])) ? false : true;
  2637. $noescInetKeyWords = (empty($fmpData['noesc_inet_srv_keywords'])) ? false : true;
  2638. $noescUKVKeyWords = (empty($fmpData['noesc_ukv_srv_keywords'])) ? false : true;
  2639. $noescSkipKeyWords = (empty($fmpData['noesc_skip_row_keywords'])) ? false : true;
  2640. $noescRplcKeyWords = (empty($fmpData['noesc_replace_keywords'])) ? false : true;
  2641. $noescRmvKeyWords = (empty($fmpData['noesc_remove_keywords'])) ? false : true;
  2642. $inputs = wf_TextInput('fmpname', __('Preset name'), $fmpData['presetname'], false, '', '', '__FMPEmptyCheck');
  2643. $inputs.= wf_nbsp(8);
  2644. $inputs.= wf_TextInput('fmppaymtypeid', __('Custom payment type ID for this bank statement'), $fmpData['payment_type_id'], true, '4', 'digits', '', 'BankstaPaymentTypeID');
  2645. $inputscells = wf_TableCell(wf_TextInput('fmpcolrealname', __('Real name column number'), $colRealName, false, '4'));
  2646. $inputscells.= wf_TableCell(wf_TextInput('fmpcoladdr', __('Address column number'), $colAddress, false, '4'));
  2647. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaysum', __('Payment sum column number'), $colPaysum, false, '4'));
  2648. $inputsrows = wf_TableRow($inputscells);
  2649. $inputscells = wf_TableCell(wf_TextInput('fmpcolpaypurpose', __('Payment purpose column number'), $colPayPurpose, false, '4'));
  2650. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaydate', __('Payment date column number'), $colPayDate, false, '4'));
  2651. $inputscells.= wf_TableCell(wf_TextInput('fmpcolpaytime', __('Payment time column number'), $colPayTime, true, '4'));
  2652. $inputsrows.= wf_TableRow($inputscells);
  2653. $inputscells = wf_TableCell(wf_CheckInput('fmppaymincoins', __('Bank statement "SUM" field presented in coins(need to be divided by 100)'), true, $sumInCoins, 'BankstaPaymInCoins'), '', '', '', '2');
  2654. $inputsrows.= wf_TableRow($inputscells);
  2655. $inputs.= wf_TableBody($inputsrows, '', '0', '', 'cellspacing="4px" style="margin-top: 8px;"');
  2656. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2657. $inputs.= wf_TextInput('fmpcolcontract', __('User contract column number') . ' (' . __('Payment ID') . ')', $colContract, true, '4');
  2658. $inputs.= wf_CheckInput('fmptryguesscontract', __('Try to get contract from payment purpose field'), true, $contractGuessing, 'BankstaTryGuessContract');
  2659. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 800px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2660. $inputs.= __('ONLY, if mapped contract field for some row will be empty or if contract field will be not specified');
  2661. $inputs.= wf_tag('h4', true);
  2662. $inputs.= wf_TextInput('fmpcontractdelimstart', __('Contract') . ' (' . __('Payment ID') . '): ' . __('start delimiter string'), $fmpData['contract_delim_start'], true, '', '', '', 'BankstaContractDelimStart');
  2663. $inputs.= wf_TextInput('fmpcontractdelimend', __('Contract') . ' (' . __('Payment ID') . '): ' . __('end delimiter string'), $fmpData['contract_delim_end'], true, '', '', '', 'BankstaContractDelimEnd');
  2664. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 800px; padding: 11px 0 7px 0; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2665. $inputs.= __('If your contracts(payment IDs) are 100% DIGITAL - you may specify their minimum and maximum length to extract them properly(delimiters will not be taken into account)');
  2666. $inputs.= wf_tag('h4', true);
  2667. $inputs.= wf_TextInput('fmpcontractminlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('min length'), $fmpData['contract_min_len'], true, '', '', '', 'BankstaContractMinLen');
  2668. $inputs.= wf_TextInput('fmpcontractmaxlen', __('Contract') . ' (' . __('Payment ID') . '): ' . __('max length'), $fmpData['contract_max_len'], true, '', '', '', 'BankstaContractMaxLen');
  2669. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2670. $inputs.= wf_Selector('fmpsrvtype', $this->bankstaServiceType, __('Service type') . ' (' . __('select "Telepathy" to try to get service type from payment purpose field') . ')', $fmpData['service_type'], true, false, 'BankstaSrvType');
  2671. $inputs.= wf_TextInput('fmpinetdelimstart', __('Internet service before keywords delimiter string'), $fmpData['inet_srv_start_delim'], true, '', '', '', 'BankstaInetDelimStart');
  2672. $inputs.= wf_TextInput('fmpinetkeywords', __('Internet service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', $fmpData['inet_srv_keywords'], true, '40', '', '', 'BankstaInetKeyWords');
  2673. $inputs.= wf_TextInput('fmpinetdelimend', __('Internet service after keywords delimiter string'), $fmpData['inet_srv_end_delim'], true, '', '', '', 'BankstaInetDelimEnd');
  2674. $inputs.= wf_CheckInput('fmpinetkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, $noescInetKeyWords, 'BankstaInetKeyWordsNoEsc');
  2675. $inputs.= wf_delimiter(0);
  2676. $inputs.= wf_TextInput('fmpukvdelimstart', __('UKV service before keywords delimiter string'), $fmpData['ukv_srv_start_delim'], true, '', '', '', 'BankstaUKVDelimStart');
  2677. $inputs.= wf_TextInput('fmpukvkeywords', __('UKV service determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', $fmpData['ukv_srv_keywords'], true, '40', '', '', 'BankstaUKVKeyWords');
  2678. $inputs.= wf_TextInput('fmpukvdelimend', __('UKV service after keywords delimiter string'), $fmpData['ukv_srv_end_delim'], true, '', '', '', 'BankstaUKVDelimEnd');
  2679. $inputs.= wf_CheckInput('fmpukvkeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, $noescUKVKeyWords, 'BankstaUKVKeyWordsNoEsc');
  2680. $inputs.= wf_delimiter(0);
  2681. $inputs.= wf_TextInput('fmpcolsrvidents', __('Number of the dedicated field which contains services IDs identifiers mapped via BANKSTA2_INETSRV_ALLOTED_IDS and BANKSTA2_CTVSRV_ALLOTED_IDS'), $colSrvIdents, true, '4');
  2682. $inputs.= wf_CheckInput('fmpsrvidentspreff', __('Services IDs identifiers from the dedicated field take precedence over service type telepathy'), true, $prefferSrvIdents, 'BankstaSrvIdentsPreff');
  2683. $inputs.= wf_tag('h4', false, '', 'style="font-weight: 400; width: 980px; padding: 2px 0 8px 28px; color: #666; margin-block-end: 0; margin-block-start: 0;"');
  2684. $inputs.= __('NOTE: dedicated field\'s services IDs are always take precedence over manually chosen \'Internet\' or \'UKV\' services');
  2685. $inputs.= wf_tag('h4', true);
  2686. $inputs.= wf_delimiter(0);
  2687. $inputs.= wf_tag('hr', false, '', 'style="margin-bottom: 11px;"');
  2688. $inputs.= wf_CheckInput('fmpskiprow', __('Skip row processing if specified fields contain keywords below'), true, $rowSkipping, 'BankstaSkipRow');
  2689. $inputs.= wf_TextInput('fmpcolskiprow', __('Fields to check row skipping') . '(' . __('multiple fields must be separated with comas') . ')', $fmpData['col_skiprow'], true, '', '', '', 'BankstaSkipRowKeyWordsCol');
  2690. $inputs.= wf_TextInput('fmpskiprowkeywords', __('Row skipping determination keywords') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', $fmpData['skip_row_keywords'], true, '40', '', '', 'BankstaSkipRowKeyWords');
  2691. $inputs.= wf_CheckInput('fmpskiprokeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, $noescSkipKeyWords, 'BankstaSkipRowKeyWordsNoEsc');
  2692. $inputs.= wf_delimiter(0);
  2693. $inputs.= wf_CheckInput('fmpreplacestrs', __('Replace characters specified below in specified fields'), true, $strReplacing, 'BankstaReplaceStrs');
  2694. $inputs.= wf_TextInput('fmpcolsreplacestrs', __('Fields to perform replacing') . '(' . __('multiple fields must be separated with comas') . ')', $fmpData['col_replace_strs'], true, '', '', '', 'BankstaReplaceStrsCols');
  2695. $inputs.= wf_TextInput('fmpstrstoreplace', __('Replaced characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', $fmpData['strs_to_replace'], true, '40', '', '', 'BankstaReplaceStrsChars');
  2696. $inputs.= wf_TextInput('fmpstrstoreplacewith', __('Replacing characters or string'), $fmpData['strs_to_replace_with'], true, '40', '', '', 'BankstaReplaceStrsWith');
  2697. $inputs.= wf_TextInput('fmpstrsreplacecount', __('Replacements count'), $fmpData['replacements_cnt'], true, '40', '', '', 'BankstaReplaceStrsCount');
  2698. $inputs.= wf_CheckInput('fmpreplacekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, $noescRplcKeyWords, 'BankstaReplaceKeyWordsNoEsc');
  2699. $inputs.= wf_delimiter(0);
  2700. $inputs.= wf_CheckInput('fmpremovestrs', __('Remove characters specified below in specified fields'), true, $strRemoving, 'BankstaRemoveStrs');
  2701. $inputs.= wf_TextInput('fmpcolsremovestrs', __('Fields to perform removing') . '(' . __('multiple fields must be separated with comas') . ')', $fmpData['col_remove_strs'], true, '', '', '', 'BankstaRemoveStrsCols');
  2702. $inputs.= wf_TextInput('fmpstrstoremove', __('Removed characters or strings') . ', ' . __('separated with') . ' BANKSTA2_REGEX_KEYWORDS_DELIM', $fmpData['strs_to_remove'], true, '40', '', '', 'BankstaRemoveStrsChars');
  2703. $inputs.= wf_CheckInput('fmpremovekeywordsnoesc', __('Don\'t escape or process in any other way the keywords - just left them "as is"'), true, $noescRmvKeyWords, 'BankstaRemoveKeyWordsNoEsc');
  2704. $inputs.= wf_delimiter(0);
  2705. $inputs.= wf_CheckInput('formclose', __('Close form after operation'), false, true, $closeFormChkId, '__CloseFrmOnSubmitChk');
  2706. $inputs.= wf_HiddenInput('', $modalWindowId, '', '__FMPFormModalWindowId');
  2707. $inputs.= ($clone) ? wf_HiddenInput('fmpclone', 'true') : wf_HiddenInput('fmpedit', 'true');
  2708. $inputs.= wf_HiddenInput('fmpid', $fmpID);
  2709. $inputs.= wf_delimiter();
  2710. $inputs.= ($clone) ? wf_Submit(__('Clone')) : wf_Submit(__('Edit'));
  2711. $form = wf_Form(self::URL_ME, 'POST', $inputs, 'glamour __FMPForm', '', $formId);
  2712. return ($form);
  2713. }
  2714. }