api.extcontras.php 154 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492
  1. <?php
  2. /**
  3. * - Вы делоете платежов?
  4. * - Нет, просто показываю.
  5. * - Кросивое...
  6. */
  7. class ExtContras {
  8. /**
  9. * Database abstraction layer with for `extcontras` table
  10. *
  11. * @var object
  12. */
  13. protected $dbExtContras = null;
  14. /**
  15. * Database abstraction layer with for `extcontras` table + data JOINed from related tables
  16. *
  17. * @var object
  18. */
  19. protected $dbExtContrasExten = null;
  20. /**
  21. * Database abstraction layer with for `extcontras_profiles` table
  22. *
  23. * @var object
  24. */
  25. protected $dbECProfiles = null;
  26. /**
  27. * Database abstraction layer with for `extcontras_contracts` table
  28. *
  29. * @var object
  30. */
  31. protected $dbECContracts = null;
  32. /**
  33. * Database abstraction layer with for `extcontras_address` table
  34. *
  35. * @var object
  36. */
  37. protected $dbECAddress = null;
  38. /**
  39. * Database abstraction layer with for `extcontras_periods` table
  40. *
  41. * @var object
  42. */
  43. protected $dbECPeriods = null;
  44. /**
  45. * Database abstraction layer with for `extcontras_money` table
  46. *
  47. * @var object
  48. */
  49. protected $dbECMoney = null;
  50. /**
  51. * Database abstraction layer with for `money` table + data JOINed from `extcontras` table
  52. *
  53. * @var object
  54. */
  55. protected $dbECMoneyExten = null;
  56. /**
  57. * Database abstraction layer with for `extcontras_invoices` table
  58. *
  59. * @var object
  60. */
  61. protected $dbECInvoices = null;
  62. /**
  63. * Database abstraction layer with for `extcontras_missed_payms` table
  64. *
  65. * @var object
  66. */
  67. protected $dbECMissedPayms = null;
  68. /**
  69. * Contains all DB entities objects in array($tableName => $dbEntity)
  70. *
  71. * @var array
  72. */
  73. protected $dbEntitiesAll = array();
  74. /**
  75. * Contains all data entities objects in array($tableName => $dataEntity)
  76. *
  77. * @var array
  78. */
  79. protected $dataEntitiesAll = array();
  80. /**
  81. * Placeholder for $dbExtContras DB table field structure
  82. *
  83. * @var array
  84. */
  85. protected $dbExtContrasStruct = array();
  86. /**
  87. * Placeholder for $dbECProfiles DB table field structure
  88. *
  89. * @var array
  90. */
  91. protected $dbECProfilesStruct = array();
  92. /**
  93. * Placeholder for $dbECContracts DB table field structure
  94. *
  95. * @var array
  96. */
  97. protected $dbECContractsStruct = array();
  98. /**
  99. * Placeholder for $dbECAddress DB table field structure
  100. *
  101. * @var array
  102. */
  103. protected $dbECAddressStruct = array();
  104. /**
  105. * Placeholder for $dbECPeriods DB table field structure
  106. *
  107. * @var array
  108. */
  109. protected $dbECPeriodsStruct = array();
  110. /**
  111. * Placeholder for $dbECExtMoney DB table field structure
  112. *
  113. * @var array
  114. */
  115. protected $dbECMoneyStruct = array();
  116. /**
  117. * Placeholder for $dbECInvoices DB table field structure
  118. *
  119. * @var array
  120. */
  121. protected $dbECInvoicesStruct = array();
  122. /**
  123. * Placeholder for $dbECMissedPayms DB table field structure
  124. *
  125. * @var array
  126. */
  127. protected $dbECMissedPaymsStruct = array();
  128. /**
  129. * Contains all extcontras records from DB as ecid => ecdata
  130. *
  131. * @var array
  132. */
  133. protected $allExtContras = array();
  134. /**
  135. * Contains all extcontras records from DB as ecid => ecdata + data JOINed from related tables
  136. *
  137. * @var array
  138. */
  139. protected $allExtContrasExten = array();
  140. /**
  141. * Contains all extcontras profiles records from DB ecprofileid => ecprofiledata
  142. *
  143. * @var array
  144. */
  145. protected $allECProfiles = array();
  146. /**
  147. * Contains all extcontras contracts records from DB eccontractid => eccontractdata
  148. *
  149. * @var array
  150. */
  151. protected $allECContracts = array();
  152. /**
  153. * Contains all extcontras addresses records from DB ecaddressid => ecaddressdata
  154. *
  155. * @var array
  156. */
  157. protected $allECAddresses = array();
  158. /**
  159. * Contains all extcontras periods records from DB ecperiodid => ecperioddata
  160. *
  161. * @var array
  162. */
  163. protected $allECPeriods = array();
  164. /**
  165. * Contains all extcontras money records from DB ecmoneyid => ecmoneydata
  166. *
  167. * @var array
  168. */
  169. protected $allECMoney = array();
  170. /**
  171. * Contains all extcontras money records from DB as ececmoneyid => ecmoneydata + data JOINed from `extcontras` table
  172. *
  173. * @var array
  174. */
  175. protected $allECMoneyExten = array();
  176. /**
  177. * Contains all extcontras invoices records from DB ecinvoiceid => ecinvoicedata
  178. *
  179. * @var array
  180. */
  181. protected $allECInvoices = array();
  182. /**
  183. * Contains all extcontras overdue payments records from DB ecmisspaymid => ecmisspaymdata
  184. *
  185. * @var array
  186. */
  187. protected $allECMissedPayms = array();
  188. /**
  189. * Contains selector control filtering array for a contracts dropdown selector
  190. *
  191. * @var array
  192. */
  193. protected $selectfiltECContractsAll = array();
  194. /**
  195. * Contains selector control filtering array for an address dropdown selector
  196. *
  197. * @var array
  198. */
  199. protected $selectfiltECAddressAll = array();
  200. /**
  201. * System config object placeholder
  202. *
  203. * @var null
  204. */
  205. protected $ubConfig = null;
  206. /**
  207. * UbillingCache instance placeholder
  208. *
  209. * @var null
  210. */
  211. protected $ubCache = null;
  212. /**
  213. * System message helper object placeholder
  214. *
  215. * @var object
  216. */
  217. protected $messages = null;
  218. /**
  219. * System files storage placeholder
  220. *
  221. * @var object
  222. */
  223. protected $fileStorage = null;
  224. /**
  225. * Placeholder for FILESTORAGE_ENABLED alter.ini option
  226. *
  227. * @var bool
  228. */
  229. protected $fileStorageEnabled = false;
  230. /**
  231. * Placeholder for EXTCONTRAS_EDIT_ALLOWED_DAYS alter.ini option
  232. *
  233. * @var int
  234. */
  235. protected $ecEditablePreiod = 60;
  236. /**
  237. * Placeholder for EXTCONTRAS_INVOICE_ON alter.ini option
  238. *
  239. * @var int
  240. */
  241. protected $ecInvoicesON = 1;
  242. /**
  243. * Placeholder for EXTCONTRAS_OVERDUE_CONTRACT_NO_ADDR alter.ini option
  244. *
  245. * @var int
  246. */
  247. protected $ecFullCtrctOverdueNoAddrOnly = 1;
  248. /**
  249. * Placeholder for EXTCONTRAS_CACHE_LIFETIME from alter.ini
  250. *
  251. * @var int
  252. */
  253. protected $cacheLifeTime = 1800;
  254. /**
  255. * Placeholder for cfr('EXTCONTRASRO')
  256. *
  257. * @var bool
  258. */
  259. protected $ecReadOnlyAccess = false;
  260. /**
  261. * Contains HTML attribute to disable from's submit buttons on read only access
  262. *
  263. * @var string
  264. */
  265. protected $submitBtnDisabled = '';
  266. /**
  267. * Placeholder for mandatory fields SUP mark
  268. *
  269. * @var string
  270. */
  271. protected $supFrmFldMark = '';
  272. /**
  273. * Background color for records which have payments in current month
  274. *
  275. * @var string
  276. */
  277. protected $payedThisMonthBKGND = '';
  278. /**
  279. * Foreground color for records which have payments in current month
  280. *
  281. * @var string
  282. */
  283. protected $payedThisMonthFRGND = '';
  284. /**
  285. * Background color for records which need to be payed during next 5 days
  286. *
  287. * @var string
  288. */
  289. protected $fiveDaysTillPayBKGND = '';
  290. /**
  291. * Foreground color for records which need to be payed during next 5 days
  292. *
  293. * @var string
  294. */
  295. protected $fiveDaysTillPayFRGND = '';
  296. /**
  297. * Background color for records which payday has passed already
  298. *
  299. * @var string
  300. */
  301. protected $paymentExpiredBKGND = '';
  302. /**
  303. * Foreground color for records which payday has passed already
  304. *
  305. * @var string
  306. */
  307. protected $paymentExpiredFRGND = '';
  308. /**
  309. * Placeholder for TEMPLATE_CURRENCY alter.ini option
  310. *
  311. * @var string
  312. */
  313. public $currencyStr = '';
  314. /**
  315. * Routes, static defines, etc
  316. */
  317. // const SAY_MY_NAME = 'CONTRAS';
  318. const URL_ME = '?module=extcontras';
  319. const URL_EXTCONTRAS = 'extcontraslist';
  320. const URL_EXTCONTRAS_COLORS = 'extcontrascolors';
  321. const URL_DICTPROFILES = 'dictprofiles';
  322. const URL_DICTCONTRACTS = 'dictcontracts';
  323. const URL_DICTADDRESS = 'dictaddress';
  324. const URL_DICTPERIODS = 'dictperiods';
  325. const URL_FINOPERATIONS = 'finoperations';
  326. const URL_INVOICES = 'invoices';
  327. const URL_MISSEDPAYMENTS = 'misspayms';
  328. const TABLE_EXTCONTRAS = 'extcontras';
  329. const TABLE_EXTCONTRASEXTEN = 'extcontrasexten';
  330. const TABLE_ECPROFILES = 'extcontras_profiles';
  331. const TABLE_ECCONTRACTS = 'extcontras_contracts';
  332. const TABLE_ECADDRESS = 'extcontras_address';
  333. const TABLE_ECPERIODS = 'extcontras_periods';
  334. const TABLE_ECMONEY = 'extcontras_money';
  335. const TABLE_ECMONEYEXTEN = 'extcontras_moneyexten';
  336. const TABLE_ECINVOICES = 'extcontras_invoices';
  337. const TABLE_ECMISSPAYMENTS = 'extcontras_missed_payms';
  338. const DBFLD_COMMON_ID = 'id';
  339. const CTRL_PROFILE_NAME = 'profname';
  340. const CTRL_PROFILE_EDRPO = 'profedrpo';
  341. const CTRL_PROFILE_CONTACT = 'profcontact';
  342. const CTRL_PROFILE_MAIL = 'profmail';
  343. const DBFLD_PROFILE_NAME = 'name';
  344. const DBFLD_PROFILE_EDRPO = 'edrpo';
  345. const DBFLD_PROFILE_CONTACT = 'contact';
  346. const DBFLD_PROFILE_MAIL = 'email';
  347. const CTRL_CTRCT_CONTRACT = 'ctrctcontract';
  348. const CTRL_CTRCT_DTSTART = 'ctrctdtstart';
  349. const CTRL_CTRCT_DTEND = 'ctrctdtend';
  350. const CTRL_CTRCT_SUBJECT = 'ctrctsubject';
  351. const CTRL_CTRCT_AUTOPRLNG = 'ctrctautoprolong';
  352. const CTRL_CTRCT_FULLSUM = 'ctrctfullsum';
  353. const CTRL_CTRCT_NOTES = 'ctrctnotes';
  354. const DBFLD_CTRCT_CONTRACT = 'contract';
  355. const DBFLD_CTRCT_DTSTART = 'date_start';
  356. const DBFLD_CTRCT_DTEND = 'date_end';
  357. const DBFLD_CTRCT_SUBJECT = 'subject';
  358. const DBFLD_CTRCT_AUTOPRLNG = 'autoprolong';
  359. const DBFLD_CTRCT_FULLSUM = 'full_sum';
  360. const DBFLD_CTRCT_NOTES = 'notes';
  361. const CTRL_ADDRESS_ADDR = 'addraddress';
  362. const CTRL_ADDRESS_SUM = 'addrsumm';
  363. const CTRL_ADDRESS_CTNOTES = 'addrctrctnotes';
  364. const CTRL_ADDRESS_NOTES = 'addrnotes';
  365. const DBFLD_ADDRESS_ADDR = 'address';
  366. const DBFLD_ADDRESS_SUM = 'summ';
  367. const DBFLD_ADDRESS_CTNOTES = 'contract_notes';
  368. const DBFLD_ADDRESS_NOTES = 'notes';
  369. const CTRL_PERIOD_NAME = 'prdname';
  370. const DBFLD_PERIOD_NAME = 'period_name';
  371. const CTRL_MONEY_PROFILEID = 'moneyprofileid';
  372. const CTRL_MONEY_CNTRCTID = 'moneycontractid';
  373. const CTRL_MONEY_ADDRESSID = 'moneyaddressid';
  374. const CTRL_MONEY_ACCRUALID = 'moneyaccrualid';
  375. const CTRL_MONEY_INVOICEID = 'moneyinvoiceid';
  376. const CTRL_MONEY_PURPOSE = 'moneypurpose';
  377. const CTRL_MONEY_SUMACCRUAL = 'moneysummaccrual';
  378. const CTRL_MONEY_SUMPAYMENT = 'moneysummpayment';
  379. const CTRL_MONEY_INOUT = 'moneyinout';
  380. const CTRL_MONEY_PAYNOTES = 'moneypaynotes';
  381. const DBFLD_MONEY_PROFILEID = 'profile_id';
  382. const DBFLD_MONEY_CNTRCTID = 'contract_id';
  383. const DBFLD_MONEY_ADDRESSID = 'address_id';
  384. const DBFLD_MONEY_ACCRUALID = 'accrual_id';
  385. const DBFLD_MONEY_INVOICEID = 'invoice_id';
  386. const DBFLD_MONEY_PURPOSE = 'purpose';
  387. const DBFLD_MONEY_DATE = 'date';
  388. const DBFLD_MONEY_DATE_EDIT = 'date_edit';
  389. const DBFLD_MONEY_SMACCRUAL = 'summ_accrual';
  390. const DBFLD_MONEY_SMPAYMENT = 'summ_payment';
  391. const DBFLD_MONEY_DATE_PAYMENT = 'date_payment';
  392. const DBFLD_MONEY_INCOMING = 'incoming';
  393. const DBFLD_MONEY_OUTGOING = 'outgoing';
  394. const DBFLD_MONEY_PAYNOTES = 'paynotes';
  395. const CTRL_INVOICES_CONTRASID = 'invocontrasrecid';
  396. const CTRL_INVOICES_INTERNAL_NUM = 'invointernalnum';
  397. const CTRL_INVOICES_INVOICE_NUM = 'invoicenum';
  398. const CTRL_INVOICES_DATE = 'invodate';
  399. const CTRL_INVOICES_SUM = 'invosumm';
  400. const CTRL_INVOICES_SUM_VAT = 'invosummvat';
  401. const CTRL_INVOICES_NOTES = 'invonotes';
  402. const CTRL_INVOICES_IN_OUT = 'invoinout';
  403. const DBFLD_INVOICES_CONTRASID = 'contras_rec_id';
  404. const DBFLD_INVOICES_INTERNAL_NUM = 'internal_number';
  405. const DBFLD_INVOICES_INVOICE_NUM = 'invoice_number';
  406. const DBFLD_INVOICES_DATE = 'date';
  407. const DBFLD_INVOICES_SUM = 'summ';
  408. const DBFLD_INVOICES_SUM_VAT = 'summ_vat';
  409. const DBFLD_INVOICES_NOTES = 'notes';
  410. const DBFLD_INVOICES_INCOMING = 'incoming';
  411. const DBFLD_INVOICES_OUTGOING = 'outgoing';
  412. const CTRL_EXTCONTRAS_PROFILE_ID = 'extcontraprofileid';
  413. const CTRL_EXTCONTRAS_CONTRACT_ID = 'extcontracontractid';
  414. const CTRL_EXTCONTRAS_ADDRESS_ID = 'extcontraaddressid';
  415. const CTRL_EXTCONTRAS_PERIOD_ID = 'extcontraperiodid';
  416. const CTRL_EXTCONTRAS_PAYDAY = 'extcontrapayday';
  417. const DBFLD_EXTCONTRAS_PROFILE_ID = 'contras_id';
  418. const DBFLD_EXTCONTRAS_CONTRACT_ID = 'contract_id';
  419. const DBFLD_EXTCONTRAS_ADDRESS_ID = 'address_id';
  420. const DBFLD_EXTCONTRAS_PERIOD_ID = 'period_id';
  421. const DBFLD_EXTCONTRAS_MISSPAYM_ID = 'missed_paym_id';
  422. const DBFLD_EXTCONTRAS_PAYDAY = 'payday';
  423. const DBFLD_EXTCONTRAS_DATECREATE = 'date_create';
  424. const CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND = 'EC_PAYEDTHISMONTH_BKGND';
  425. const CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND = 'EC_PAYEDTHISMONTH_FRGND';
  426. const CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND = 'EC_FIVEDAYSTILLPAY_BKGND';
  427. const CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND = 'EC_FIVEDAYSTILLPAY_FRGND';
  428. const CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND = 'EC_PAYMENTEXPIRED_BKGND';
  429. const CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND = 'EC_PAYMENTEXPIRED_FRGND';
  430. const DBFLD_MISSPAYMS_CONTRASID = 'contras_rec_id';
  431. const DBFLD_MISSPAYMS_PROFILEID = 'profile_id';
  432. const DBFLD_MISSPAYMS_CONTRACTID = 'contract_id';
  433. const DBFLD_MISSPAYMS_ADDRESSID = 'address_id';
  434. const DBFLD_MISSPAYMS_PERIOD_ID = 'period_id';
  435. const DBFLD_MISSPAYMS_PAYDAY = 'payday';
  436. const DBFLD_MISSPAYMS_DATE_PAYMENT = 'date_payment';
  437. const DBFLD_MISSPAYMS_DATE_EXPIRED = 'date_expired';
  438. const DBFLD_MISSPAYMS_DATE_PAYED = 'date_payed';
  439. const DBFLD_MISSPAYMS_SUMPAYMENT = 'summ_payment';
  440. const ROUTE_ACTION_CREATE = 'doCreate';
  441. const ROUTE_ACTION_PREFILL = 'doPrefill';
  442. const ROUTE_ACTION_EDIT = 'doEdit';
  443. const ROUTE_ACTION_CLONE = 'doClone';
  444. const ROUTE_ACTION_DELETE = 'doRemove';
  445. const ROUTE_EDIT_REC_ID = 'editRecID';
  446. const ROUTE_DELETE_REC_ID = 'deleteRecID';
  447. const ROUTE_CONTRAS_ACTS = 'contrasacts';
  448. const ROUTE_CONTRAS_JSON = 'contraslistjson';
  449. const ROUTE_PROFILE_ACTS = 'profileacts';
  450. const ROUTE_PROFILE_JSON = 'profilelistjson';
  451. const ROUTE_CONTRACT_ACTS = 'contractacts';
  452. const ROUTE_CONTRACT_JSON = 'contractlistjson';
  453. const ROUTE_ADDRESS_ACTS = 'addressacts';
  454. const ROUTE_ADDRESS_JSON = 'addresslistjson';
  455. const ROUTE_PERIOD_ACTS = 'periodacts';
  456. const ROUTE_PERIOD_JSON = 'periodlistjson';
  457. const ROUTE_FINOPS_ACTS = 'finopsacts';
  458. const ROUTE_FINOPS_JSON = 'finopslistjson';
  459. const ROUTE_FINOPS_DETAILS_CNTRCTS = 'finopsdetailscontracts';
  460. const ROUTE_FINOPS_DETAILS_ADDRESS = 'finopsdetailsaddress';
  461. const ROUTE_INVOICES_ACTS = 'invoicesacts';
  462. const ROUTE_INVOICES_JSON = 'invoiceslistjson';
  463. const ROUTE_MISSPAYMS_ACTS = 'misspaymslistjson';
  464. const ROUTE_MISSPAYMS_JSON = 'misspaymslistjson';
  465. const ROUTE_FORCECACHE_UPD = 'extcontrasforcecacheupdate';
  466. const ROUTE_2LVL_CNTRCTS_DETAIL = 'contras2lvlcntrctsdetails';
  467. const ROUTE_2LVL_CNTRCTS_JSON = 'contras2lvlcntrctsjson';
  468. const ROUTE_3LVL_ADDR_JSON = 'contras3lvladdrsjson';
  469. const MISC_FILESTORAGE_SCOPE = 'EXCONTRAS';
  470. const MISC_CLASS_MWID_CTRL = '__FormModalWindowID';
  471. const MISC_CLASS_SUBMITFORM = '__FormSubmit';
  472. const MISC_CLASS_SUBMITFORM_MODAL = '__FormSubmitModal';
  473. const MISC_CLASS_EMPTYVALCHECK = '__EmptyCheckControl';
  474. const MISC_CLASS_EMPTYVALCHECK_MODAL = '__EmptyCheckControlModal';
  475. const MISC_CLASS_DPICKER_MODAL_INIT = '__DatePickerModalInit';
  476. const MISC_JS_DEL_FUNC_NAME = 'deleteRec';
  477. const MISC_ERRFORM_ID_PARAM = 'errfrmid';
  478. const MISC_MARKROW_URL = 'markrowid';
  479. const MISC_WEBFILTER_DATE_START = 'datefilterstart';
  480. const MISC_WEBFILTER_DATE_END = 'datefilterend';
  481. const MISC_WEBFILTER_PAYDAY = 'paydayfilter';
  482. const MISC_WEBFILTER_MISSPAYMS = 'misspaysfilter';
  483. const MISC_PREFILL_DATA = 'prefilldata';
  484. const MISC_WEBSEL_PROFILES = 'WebSelECProfiles_';
  485. const MISC_WEBSEL_CONTRACTS = 'WebSelECContracts_';
  486. const MISC_WEBSEL_ADDRESS = 'WebSelECAddress_';
  487. const MISC_WEBSEL_FILTDATA_CONTRACTS = 'WebSelContractFilterData_';
  488. const MISC_WEBSEL_FILTDATA_ADDRESS = 'WebSelAddressFilterData_';
  489. const MISC_WEBSEL_DBVAL_PROFILE_ID = 'ModalDBValProfile_';
  490. const MISC_WEBSEL_DBVAL_CONTRACTS_ID = 'ModalDBValContract_';
  491. const MISC_WEBSEL_DBVAL_ADDRESS_ID = 'ModalDBValAddress_';
  492. const MISC_MISSED_PAYMENT_PROCESSING = 'misspaymprocessing';
  493. const MISC_MISSED_PAYMENT_ID = 'missedpaymentid';
  494. const MISC_FORMS_CAPTS_PROFILE_DICT = 'counterparty profile';
  495. const MISC_FORMS_CAPTS_CNTRCTS_DICT = 'counterparty contract';
  496. const MISC_FORMS_CAPTS_ADDRESS_DICT = 'contract address';
  497. const MISC_FORMS_CAPTS_PERIODS_DICT = 'period';
  498. const MISC_FORMS_CAPTS_INVOICES_LIST = 'invoice';
  499. const MISC_FORMS_CAPTS_FINOPS_LIST = 'financial operation';
  500. const MISC_FORMS_CAPTS_EXTCONTRAS = 'counterparty record';
  501. public function __construct() {
  502. global $ubillingConfig;
  503. $this->ubConfig = $ubillingConfig;
  504. $this->ubCache = new UbillingCache();
  505. $this->messages = new UbillingMessageHelper();
  506. $this->loadOptions();
  507. $this->initDBEntities();
  508. $this->loadDBTableStructs();
  509. $this->loadAllData();
  510. $this->getTableGridColorOpts();
  511. if ($this->fileStorageEnabled) {
  512. $this->fileStorage = new FileStorage(self::MISC_FILESTORAGE_SCOPE);
  513. }
  514. $this->supFrmFldMark = wf_tag('sup') . '*' . wf_tag('sup', true);
  515. }
  516. /**
  517. * Loads alter.ini options
  518. */
  519. protected function loadOptions() {
  520. $this->currencyStr = $this->ubConfig->getAlterParam('TEMPLATE_CURRENCY', 'грн');
  521. $this->fileStorageEnabled = $this->ubConfig->getAlterParam('FILESTORAGE_ENABLED');
  522. $this->cacheLifeTime = $this->ubConfig->getAlterParam('EXTCONTRAS_CACHE_LIFETIME', 1800);
  523. $this->ecInvoicesON = $this->ubConfig->getAlterParam('EXTCONTRAS_INVOICE_ON', 1);
  524. $this->ecFullCtrctOverdueNoAddrOnly = $this->ubConfig->getAlterParam('EXTCONTRAS_OVERDUE_CONTRACT_NO_ADDR', 1);
  525. $this->ecEditablePreiod = $this->ubConfig->getAlterParam('EXTCONTRAS_EDIT_ALLOWED_DAYS');
  526. $this->ecEditablePreiod = empty($this->ecEditablePreiod) ? (60 * 86400) : ($this->ecEditablePreiod * 86400); // Option is in days
  527. $this->ecReadOnlyAccess = (!cfr('EXTCONTRASRW'));
  528. $this->submitBtnDisabled = ($this->ecReadOnlyAccess ? 'disabled="true"' : '');
  529. }
  530. /**
  531. * Inits DB NyanORM objects
  532. */
  533. protected function initDBEntities() {
  534. $this->dbExtContras = new NyanORM(self::TABLE_EXTCONTRAS);
  535. $this->dbEntitiesAll[self::TABLE_EXTCONTRAS] = $this->dbExtContras;
  536. $this->dataEntitiesAll[self::TABLE_EXTCONTRAS] = 'allExtContras';
  537. $this->dbExtContrasExten = new NyanORM(self::TABLE_EXTCONTRAS);
  538. $this->dbEntitiesAll[self::TABLE_EXTCONTRASEXTEN] = $this->dbExtContrasExten;
  539. $this->dataEntitiesAll[self::TABLE_EXTCONTRASEXTEN] = 'allExtContrasExten';
  540. $this->dbECProfiles = new NyanORM(self::TABLE_ECPROFILES);
  541. $this->dbEntitiesAll[self::TABLE_ECPROFILES] = $this->dbECProfiles;
  542. $this->dataEntitiesAll[self::TABLE_ECPROFILES] = 'allECProfiles';
  543. $this->dbECContracts = new NyanORM(self::TABLE_ECCONTRACTS);
  544. $this->dbEntitiesAll[self::TABLE_ECCONTRACTS] = $this->dbECContracts;
  545. $this->dataEntitiesAll[self::TABLE_ECCONTRACTS] = 'allECContracts';
  546. $this->dbECAddress = new NyanORM(self::TABLE_ECADDRESS);
  547. $this->dbEntitiesAll[self::TABLE_ECADDRESS] = $this->dbECAddress;
  548. $this->dataEntitiesAll[self::TABLE_ECADDRESS] = 'allECAddresses';
  549. $this->dbECPeriods = new NyanORM(self::TABLE_ECPERIODS);
  550. $this->dbEntitiesAll[self::TABLE_ECPERIODS] = $this->dbECPeriods;
  551. $this->dataEntitiesAll[self::TABLE_ECPERIODS] = 'allECPeriods';
  552. $this->dbECMoney = new NyanORM(self::TABLE_ECMONEY);
  553. $this->dbEntitiesAll[self::TABLE_ECMONEY] = $this->dbECMoney;
  554. $this->dataEntitiesAll[self::TABLE_ECMONEY] = 'allECMoney';
  555. $this->dbECMoneyExten = new NyanORM(self::TABLE_ECMONEY);
  556. $this->dbEntitiesAll[self::TABLE_ECMONEYEXTEN] = $this->dbECMoneyExten;
  557. $this->dataEntitiesAll[self::TABLE_ECMONEYEXTEN] = 'allECMoneyExten';
  558. $this->dbECInvoices = new NyanORM(self::TABLE_ECINVOICES);
  559. $this->dbEntitiesAll[self::TABLE_ECINVOICES] = $this->dbECInvoices;
  560. $this->dataEntitiesAll[self::TABLE_ECINVOICES] = 'allECInvoices';
  561. $this->dbECMissedPayms = new NyanORM(self::TABLE_ECMISSPAYMENTS);
  562. $this->dbEntitiesAll[self::TABLE_ECMISSPAYMENTS] = $this->dbECMissedPayms;
  563. $this->dataEntitiesAll[self::TABLE_ECMISSPAYMENTS] = 'allECMissedPayms';
  564. }
  565. /**
  566. * Returns DB entity object by table name
  567. *
  568. * @param $dbEntityName
  569. *
  570. * @return object|null
  571. */
  572. public function getDBEntity($dbEntityName) {
  573. $result = null;
  574. if (!empty($this->dbEntitiesAll[$dbEntityName])) {
  575. $result = $this->dbEntitiesAll[$dbEntityName];
  576. }
  577. return ($result);
  578. }
  579. /**
  580. * Returns data entity object by table name
  581. *
  582. * @param $dataEntityName
  583. *
  584. * @return mixed|null
  585. */
  586. public function getDataEntity($dataEntityName) {
  587. $result = null;
  588. if (!empty($this->dataEntitiesAll[$dataEntityName])) {
  589. $result = $this->dataEntitiesAll[$dataEntityName];
  590. }
  591. return ($result);
  592. }
  593. /**
  594. * Loads DB tables fields structures to a class properties
  595. */
  596. protected function loadDBTableStructs() {
  597. $this->dbExtContrasStruct = $this->dbExtContras->getTableStructure(true, false, true, true);
  598. $this->dbECProfilesStruct = $this->dbECProfiles->getTableStructure(true, false, true, true);
  599. $this->dbECContractsStruct = $this->dbECContracts->getTableStructure(true, false, true, true);
  600. $this->dbECAddressStruct = $this->dbECAddress->getTableStructure(true, false, true, true);
  601. $this->dbECPeriodsStruct = $this->dbECPeriods->getTableStructure(true, false, true, true);
  602. $this->dbECMoneyStruct = $this->dbECMoney->getTableStructure(true, false, true, true);
  603. $this->dbECInvoicesStruct = $this->dbECInvoices->getTableStructure(true, false, true, true);
  604. $this->dbECMissedPaymsStruct = $this->dbECMissedPayms->getTableStructure(true, false, true, true);
  605. }
  606. /**
  607. * Loads data from a DB table or UB cache
  608. *
  609. * @param string $tableName
  610. * @param string $cacheKey
  611. * @param bool $forceDBLoad
  612. * @param bool $flushNyanParams
  613. * @param string $assocByField
  614. * @param string $dataEntity
  615. * @param bool $cachingDisabled
  616. * @param bool $distinctSelectON
  617. *
  618. * @return mixed
  619. */
  620. public function loadDataFromTableCached($tableName, $cacheKey, $forceDBLoad = false, $flushNyanParams = true, $assocByField = '', $dataEntity = '', $cachingDisabled = false, $distinctSelectON = false) {
  621. $cacheKey = strtoupper($cacheKey);
  622. $dbInstance = $this->getDBEntity($tableName);
  623. $flushParams = $flushNyanParams;
  624. $assocByField = (empty($assocByField) ? 'id' : $assocByField);
  625. $dataInstance = (empty($dataEntity) ? $this->getDataEntity($tableName) : $dataEntity);
  626. $thisInstance = $this;
  627. if ($forceDBLoad) {
  628. $this->$dataInstance = $dbInstance->getAll($assocByField, $flushParams, $distinctSelectON);
  629. if ($cachingDisabled) {
  630. $this->ubCache->delete($cacheKey);
  631. } else {
  632. $this->ubCache->set($cacheKey, $this->$dataInstance, $this->cacheLifeTime);
  633. }
  634. } else {
  635. $this->$dataInstance = $this->ubCache->getCallback($cacheKey, function () use ($thisInstance, $tableName, $cacheKey, $flushParams, $assocByField,
  636. $dataInstance, $cachingDisabled, $distinctSelectON) {
  637. return ($thisInstance->loadDataFromTableCached($tableName, $cacheKey, true, $flushParams, $assocByField, $dataInstance, $cachingDisabled, $distinctSelectON));
  638. }, $this->cacheLifeTime);
  639. }
  640. return ($this->$dataInstance);
  641. }
  642. /**
  643. * Loads extended external counterparties data
  644. *
  645. * @param bool $forceDBLoad
  646. * @param string $whereRaw
  647. * @param string $orderBy
  648. * @param string $orderDir
  649. * @param bool $distinctSelectON
  650. */
  651. protected function loadExtContrasExtenData($forceDBLoad = false, $whereRaw = '', $orderBy = '', $orderDir = 'ASC', $distinctSelectON = false) {
  652. $selectable = array_merge($this->dbExtContrasStruct, $this->dbECProfilesStruct, $this->dbECContractsStruct, $this->dbECAddressStruct, $this->dbECPeriodsStruct);
  653. if (!$forceDBLoad) {
  654. $forceDBLoad = (empty($whereRaw) and empty($orderBy) and empty($distinctSelectON));
  655. }
  656. $this->dbExtContrasExten->selectable($selectable);
  657. $this->dbExtContrasExten->joinOn();
  658. $this->dbExtContrasExten->joinOn('LEFT', self::TABLE_ECPROFILES, self::TABLE_EXTCONTRAS . '.' . self::DBFLD_EXTCONTRAS_PROFILE_ID
  659. . ' = ' . self::TABLE_ECPROFILES . '.' . self::DBFLD_COMMON_ID);
  660. $this->dbExtContrasExten->joinOn('LEFT', self::TABLE_ECCONTRACTS, self::TABLE_EXTCONTRAS . '.' . self::DBFLD_EXTCONTRAS_CONTRACT_ID
  661. . ' = ' . self::TABLE_ECCONTRACTS . '.' . self::DBFLD_COMMON_ID);
  662. $this->dbExtContrasExten->joinOn('LEFT', self::TABLE_ECADDRESS, self::TABLE_EXTCONTRAS . '.' . self::DBFLD_EXTCONTRAS_ADDRESS_ID
  663. . ' = ' . self::TABLE_ECADDRESS . '.' . self::DBFLD_COMMON_ID);
  664. $this->dbExtContrasExten->joinOn('LEFT', self::TABLE_ECPERIODS, self::TABLE_EXTCONTRAS . '.' . self::DBFLD_EXTCONTRAS_PERIOD_ID
  665. . ' = ' . self::TABLE_ECPERIODS . '.' . self::DBFLD_COMMON_ID);
  666. if (!empty($whereRaw)) {
  667. $this->dbExtContrasExten->whereRaw($whereRaw);
  668. }
  669. if (!empty($orderBy)) {
  670. $this->dbExtContrasExten->orderBy($orderBy, $orderDir);
  671. }
  672. //$this->dbExtContrasExten->setDebug(true, true);
  673. $this->loadDataFromTableCached(self::TABLE_EXTCONTRASEXTEN, self::TABLE_EXTCONTRASEXTEN, $forceDBLoad, false, self::TABLE_EXTCONTRAS . self::DBFLD_COMMON_ID, '', !empty($whereRaw), $distinctSelectON);
  674. }
  675. /**
  676. * Loads extended external finops data
  677. *
  678. * @param bool $forceDBLoad
  679. * @param string $whereRaw
  680. * @param string $orderBy
  681. * @param string $orderDir
  682. * @param bool $distinctSelectON
  683. *
  684. */
  685. public function loadFinopsExtenData($forceDBLoad = false, $whereRaw = '', $orderBy = '', $orderDir = 'ASC', $distinctSelectON = false) {
  686. $selectable = array_merge($this->dbECMoneyStruct, $this->dbExtContrasStruct);
  687. if (!$forceDBLoad) {
  688. $forceDBLoad = (empty($whereRaw) and empty($orderBy) and empty($distinctSelectON));
  689. }
  690. $this->dbECMoneyExten->selectable($selectable);
  691. $this->dbECMoneyExten->joinOn();
  692. $this->dbECMoneyExten->joinOn('INNER', self::TABLE_EXTCONTRAS, self::TABLE_ECMONEY . '.' . self::DBFLD_MONEY_PROFILEID
  693. . ' = ' . self::TABLE_EXTCONTRAS . '.' . self::DBFLD_EXTCONTRAS_PROFILE_ID);
  694. if (!empty($whereRaw)) {
  695. $this->dbECMoneyExten->whereRaw($whereRaw);
  696. }
  697. if (!empty($orderBy)) {
  698. $this->dbExtContrasExten->orderBy($orderBy, $orderDir);
  699. }
  700. //$this->dbECMoneyExten->setDebug(true, true);
  701. $this->loadDataFromTableCached(self::TABLE_ECMONEYEXTEN, self::TABLE_ECMONEYEXTEN, $forceDBLoad, false, self::TABLE_ECMONEY . self::DBFLD_COMMON_ID, '', !empty($whereRaw), $distinctSelectON);
  702. }
  703. /**
  704. * Retrieves data for contracts web selector control filtering
  705. */
  706. protected function loadWebSelFilterData() {
  707. $this->loadExtContrasExtenData(false, '', self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PROFILE_ID);
  708. foreach ($this->allExtContrasExten as $eachID => $eachRec) {
  709. $tmpProfileID = $eachRec[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PROFILE_ID];
  710. $tmpContractID = $eachRec[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_CONTRACT_ID];
  711. $tmpAddressID = $eachRec[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_ADDRESS_ID];
  712. $this->selectfiltECContractsAll[$tmpProfileID][] = array($tmpContractID => $eachRec[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_CONTRACT] . ' ' .
  713. $eachRec[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_SUBJECT] . ' ' .
  714. $eachRec[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_FULLSUM]);
  715. $this->selectfiltECAddressAll[$tmpContractID][] = array($tmpAddressID => $eachRec[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_ADDR] . ' ' .
  716. $eachRec[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_SUM]);
  717. }
  718. }
  719. /**
  720. * Unified data loader
  721. */
  722. protected function loadAllData($forceDBLoad = false) {
  723. $this->loadDataFromTableCached(self::TABLE_EXTCONTRAS, self::TABLE_EXTCONTRAS, $forceDBLoad);
  724. $this->loadDataFromTableCached(self::TABLE_ECPROFILES, self::TABLE_ECPROFILES, $forceDBLoad);
  725. $this->loadDataFromTableCached(self::TABLE_ECCONTRACTS, self::TABLE_ECCONTRACTS, $forceDBLoad);
  726. $this->loadDataFromTableCached(self::TABLE_ECADDRESS, self::TABLE_ECADDRESS, $forceDBLoad);
  727. $this->loadDataFromTableCached(self::TABLE_ECPERIODS, self::TABLE_ECPERIODS, $forceDBLoad);
  728. $this->loadDataFromTableCached(self::TABLE_ECMONEY, self::TABLE_ECMONEY, $forceDBLoad);
  729. $this->loadDataFromTableCached(self::TABLE_ECINVOICES, self::TABLE_ECINVOICES, $forceDBLoad);
  730. $this->loadDataFromTableCached(self::TABLE_ECMISSPAYMENTS, self::TABLE_ECMISSPAYMENTS, $forceDBLoad);
  731. $this->loadExtContrasExtenData($forceDBLoad);
  732. $this->loadFinopsExtenData($forceDBLoad);
  733. }
  734. /**
  735. * Forcibly updates cached data
  736. */
  737. public function refreshCacheForced() {
  738. $this->loadAllData(true);
  739. }
  740. /**
  741. * Returns prepared filtering array for NyanORM checkRecExists() method
  742. *
  743. * @param $dbTabField
  744. * @param $operator
  745. * @param $dbFieldValue
  746. *
  747. * @return array
  748. */
  749. public function createCheckUniquenessArray($dbTabField, $operator, $dbFieldValue) {
  750. $tmpArray = array($dbTabField => array('operator' => $operator,
  751. 'fieldval' => $dbFieldValue)
  752. );
  753. return ($tmpArray);
  754. }
  755. /**
  756. * Saves counterparties list coloring to ubStorage
  757. */
  758. public function setTableGridColorOpts() {
  759. zb_StorageSet(self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND, ubRouting::post(self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND));
  760. zb_StorageSet(self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND, ubRouting::post(self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND));
  761. zb_StorageSet(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND, ubRouting::post(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND));
  762. zb_StorageSet(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND, ubRouting::post(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND));
  763. zb_StorageSet(self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND, ubRouting::post(self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND));
  764. zb_StorageSet(self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND, ubRouting::post(self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND));
  765. }
  766. /**
  767. * Loads counterparties list coloring to class properties
  768. */
  769. public function getTableGridColorOpts() {
  770. $this->payedThisMonthBKGND = zb_StorageGet(self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND);
  771. $this->payedThisMonthBKGND = (empty($this->payedThisMonthBKGND) ? '#4f7318' : $this->payedThisMonthBKGND);
  772. $this->payedThisMonthFRGND = zb_StorageGet(self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND);
  773. $this->payedThisMonthFRGND = (empty($this->payedThisMonthFRGND) ? '#ffffff' : $this->payedThisMonthFRGND);
  774. $this->fiveDaysTillPayBKGND = zb_StorageGet(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND);
  775. $this->fiveDaysTillPayBKGND = (empty($this->fiveDaysTillPayBKGND) ? '#ffff00' : $this->fiveDaysTillPayBKGND);
  776. $this->fiveDaysTillPayFRGND = zb_StorageGet(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND);
  777. $this->fiveDaysTillPayFRGND = (empty($this->fiveDaysTillPayFRGND) ? '#4800ff' : $this->fiveDaysTillPayFRGND);
  778. $this->paymentExpiredBKGND = zb_StorageGet(self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND);
  779. $this->paymentExpiredBKGND = (empty($this->paymentExpiredBKGND) ? '#9e1313' : $this->paymentExpiredBKGND);
  780. $this->paymentExpiredFRGND = zb_StorageGet(self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND);
  781. $this->paymentExpiredFRGND = (empty($this->paymentExpiredFRGND) ? '#ffff44' : $this->paymentExpiredFRGND);
  782. }
  783. /**
  784. * Searches for any occurrences of current month payments for a certain counterparty ID
  785. *
  786. * @param $ecRecID
  787. * @param bool $contractCheck
  788. * @param bool $addressCheck
  789. * @param bool $checkSum
  790. *
  791. * @return string
  792. */
  793. public function checkCurMonthPaymExists($ecRecID, $contractCheck = false, $addressCheck = false, $checkSum = false) {
  794. $result = '';
  795. if (!empty($ecRecID) and !empty($this->allExtContras[$ecRecID][self::DBFLD_EXTCONTRAS_PAYDAY])) {
  796. $tmpECPayDay = $this->allExtContras[$ecRecID][self::DBFLD_EXTCONTRAS_PAYDAY];
  797. $tmpECProfileID = $this->allExtContras[$ecRecID][self::DBFLD_EXTCONTRAS_PROFILE_ID];
  798. $tmpECContractID = $this->allExtContras[$ecRecID][self::DBFLD_EXTCONTRAS_CONTRACT_ID];
  799. $tmpECAddressID = $this->allExtContras[$ecRecID][self::DBFLD_EXTCONTRAS_ADDRESS_ID];
  800. $curMonthStart = date('Y-m-') . '01';
  801. $curMonthEnd = date('Y-m-') . date('t');
  802. $fullPaymentSum = 0;
  803. // getting full payment sum for a current contract
  804. if (!empty($this->allECContracts[$tmpECContractID][self::DBFLD_CTRCT_FULLSUM])) {
  805. $fullPaymentSum = $this->allECContracts[$tmpECContractID][self::DBFLD_CTRCT_FULLSUM];
  806. }
  807. // setting initial mandatory filtering by contragent profile ID
  808. $this->dbECMoney->selectable(self::DBFLD_COMMON_ID);
  809. $this->dbECMoney->where(self::DBFLD_MONEY_PROFILEID, '=', $tmpECProfileID);
  810. // adding filtering by contract ID if it's "contract check"
  811. if ($contractCheck) {
  812. $this->dbECMoney->where(self::DBFLD_MONEY_CNTRCTID, '=', $tmpECContractID);
  813. }
  814. // if it's address check, and there is a payment sum for current address,
  815. // and we didn't get full payment sum for a current contract on a very first step
  816. // then we're trying to get a current address payment sum
  817. if ($addressCheck and empty($fullPaymentSum) and !empty($this->allECAddresses[$tmpECAddressID][self::DBFLD_ADDRESS_SUM])) {
  818. $fullPaymentSum = $this->allECAddresses[$tmpECAddressID][self::DBFLD_ADDRESS_SUM];
  819. }
  820. // adding filtering by payment sum "!= 0" to be sure that the financial operation was ever paid
  821. $this->dbECMoney->where(self::DBFLD_MONEY_SMPAYMENT, '!=', 0);
  822. if (!empty($fullPaymentSum)) {
  823. // if we've got full payment sum for a current contract(or address) ...
  824. if ($addressCheck) {
  825. // ... and it's "address check"
  826. // - then we search either for a financial operation with current address ID
  827. // or for a financial operation with current payment sum
  828. // - because address check in this case(when we have full payment sum for a current contract) - is just in case
  829. $this->dbECMoney->whereRaw(' (`' . self::DBFLD_MONEY_ADDRESSID . '` = ' . $tmpECAddressID
  830. . ' OR `' . self::DBFLD_MONEY_SMPAYMENT . '` = ' . $fullPaymentSum . ') ');
  831. } else {
  832. // ... and it's "contract check" - then we search for a financial operation with current or grater payment sum
  833. $this->dbECMoney->where(self::DBFLD_MONEY_SMPAYMENT, '>=', $fullPaymentSum);
  834. }
  835. } elseif ($addressCheck) {
  836. // this means that our contract doesn't have payment sum filled
  837. // - and we search for a financial operation with current address ID
  838. //
  839. // this line will never be executed, if all the fields in contract and address dictionaries are filled correctly
  840. $this->dbECMoney->where(self::DBFLD_MONEY_ADDRESSID, '=', $tmpECAddressID);
  841. }
  842. // finally - adding filter by date to range it in current month
  843. $this->dbECMoney->whereRaw(' `' . self::DBFLD_MONEY_DATE . '` BETWEEN "' . $curMonthStart . '" AND "' . $curMonthEnd . '" + INTERVAL 1 DAY ');
  844. //$this->dbECMoney->setDebug(true, true);
  845. // getting the ID(s) of the supposed existing payment(s) - or nothing
  846. $result = $this->dbECMoney->getAll(self::DBFLD_COMMON_ID);
  847. }
  848. // if "check sum" - trying to sum up all of the existing payments
  849. // to get the total paid sum
  850. // totally used for "address check" to determine if total sum all payments for a certain addresses of the contract
  851. // are "covering" - i.e. are equal or grater than - the full contract sum
  852. if ($checkSum and !empty($result)) {
  853. $tmpPayedSum = 0;
  854. foreach ($result as $paymID => $paymData) {
  855. $tmpPayedSum += $paymData[self::DBFLD_MONEY_SMPAYMENT];
  856. }
  857. $result = $tmpPayedSum;
  858. }
  859. return ($result);
  860. }
  861. /**
  862. * Returns array of addresses assigned to a certain combination of $profileID + $contractID
  863. *
  864. * @param $profileID
  865. * @param $contractID
  866. *
  867. * @return mixed
  868. */
  869. public function checkContractHasAddresses($profileID, $contractID) {
  870. //$this->dbExtContras->setDebug(true, true);
  871. $this->dbExtContras->selectable(array(self::DBFLD_COMMON_ID, self::DBFLD_EXTCONTRAS_ADDRESS_ID));
  872. $this->dbExtContras->where(self::DBFLD_EXTCONTRAS_PROFILE_ID, '=', $profileID);
  873. $this->dbExtContras->where(self::DBFLD_EXTCONTRAS_CONTRACT_ID, '=', $contractID);
  874. $result = $this->dbExtContras->getAll(self::DBFLD_COMMON_ID);
  875. return ($result);
  876. }
  877. /**
  878. * Returns typical JQDT with or without JS code for interacting with modals and dynamic modals
  879. *
  880. * @param $ajaxURL
  881. * @param $columnsArr
  882. * @param string $columnsOpts
  883. * @param bool $stdJSForCRUDs
  884. * @param string $customJSCode
  885. * @param string $truncateURL
  886. * @param string $truncateParam
  887. * @param bool $addTotalsFooter
  888. * @param array $totalsColumns
  889. * @param string $totalsColsLegendStr
  890. * @param bool $addDetailsProcessingJS
  891. * @param string $dpAjaxURL
  892. * @param string $dpColumnIdx
  893. * @param string $dpJSFuncName
  894. * @param string $dpAjaxMethod
  895. *
  896. * @param string|int $markRowForID
  897. *
  898. * @return string
  899. */
  900. protected function getStdJQDTWithJSForCRUDs($ajaxURL, $columnsArr, $columnsOpts = '', $stdJSForCRUDs = true,
  901. $customJSCode = '', $markRowForID = '', $truncateURL = '', $truncateParam = '',
  902. $addTotalsFooter = false, $totalsColumns = array(), $totalsColsLegendStr = '',
  903. $addDetailsProcessingJS = false, $dpAjaxURL = '', $dpColumnIdx = '',
  904. $dpJSFuncName = 'showDetailsData', $dpAjaxMethod = 'POST') {
  905. $result = '';
  906. $ajaxURLStr = $ajaxURL;
  907. $jqdtID = 'jqdt_' . md5($ajaxURLStr);
  908. $columns = $columnsArr;
  909. $opts = (empty($columnsOpts) ? '"order": [[ 0, "asc" ]]' : $columnsOpts);
  910. $footerOpts = 'style="line-height: 2.2em; white-space: nowrap;"';
  911. $footTHOpts = 'style="padding: 0 5px 0 5px; border-top: 2px solid lightgrey;"';
  912. if (!empty($markRowForID)) {
  913. $result .= wf_EncloseWithJSTags(wf_JQDTRowShowPluginJS());
  914. }
  915. if ($addTotalsFooter and ! empty($totalsColumns)) {
  916. $result .= wf_EncloseWithJSTags(wf_JQDTColumnTotalSumJS());
  917. $opts .= '
  918. ,
  919. "footerCallback": function(tfoot, data, start, end, display) {
  920. var api = this.api();
  921. var footerHTML = "";
  922. let curPageSum = 0;
  923. let curPageTotal = 0;
  924. ';
  925. foreach ($totalsColumns as $colNum) {
  926. $opts .= '
  927. curPageSum = api.column( ' . $colNum . ', {page:"current"} ).data().sum().toFixed(2);
  928. curPageTotal = api.column( ' . $colNum . ' ).data().sum().toFixed(2);
  929. footerHTML = " " + curPageSum + " ' . __($totalsColsLegendStr) . wf_delimiter(0)
  930. . ' ( " + curPageTotal + " ' . __($totalsColsLegendStr) . ' )";
  931. $( api.column(' . $colNum . ').footer() ).html( footerHTML );
  932. ';
  933. }
  934. $opts .= '
  935. }
  936. ';
  937. }
  938. $result .= wf_JqDtLoader($columns, $ajaxURLStr, false, __('results'), 100, $opts, $addTotalsFooter, $footerOpts, $footTHOpts);
  939. if ($stdJSForCRUDs) {
  940. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  941. // putting a "form submitting catcher" JS code to process multiple modal and static forms
  942. // with one piece of code and ajax requests
  943. $result .= wf_jsAjaxFormSubmit('.' . self::MISC_CLASS_SUBMITFORM . ', .' . self::MISC_CLASS_SUBMITFORM_MODAL, '.' . self::MISC_CLASS_MWID_CTRL, $jqdtID, '.' . self::MISC_CLASS_EMPTYVALCHECK . ', .' . self::MISC_CLASS_EMPTYVALCHECK_MODAL, self::MISC_ERRFORM_ID_PARAM);
  944. // putting a piece of JS code to perform records delete action
  945. $result .= wf_jsAjaxCustomFunc(self::MISC_JS_DEL_FUNC_NAME, $jqdtID, '', self::MISC_ERRFORM_ID_PARAM);
  946. if (!empty($markRowForID)) {
  947. $result .= wf_JQDTMarkRowJS(0, $markRowForID, $truncateURL, $truncateParam);
  948. }
  949. $result .= wf_tag('script', true);
  950. }
  951. if ($addDetailsProcessingJS and ! empty($dpAjaxURL) and ! wf_emptyNonZero($dpColumnIdx)) {
  952. $result .= wf_EncloseWithJSTags(wf_JQDTDetailsClickProcessingJS($dpAjaxURL, $dpColumnIdx, $jqdtID, $dpAjaxMethod, $dpJSFuncName));
  953. }
  954. if (!empty($customJSCode)) {
  955. $result .= wf_EncloseWithJSTags($customJSCode);
  956. }
  957. return ($result);
  958. }
  959. /**
  960. * Returns typical JQDT "actions" controls, like "Delete", "Edit", "Clone"
  961. *
  962. * @param int $recID
  963. * @param string $routeActs
  964. * @param bool $cloneButtonON
  965. * @param string $customControls
  966. * @param bool $editButton
  967. * @param bool $deleteButton
  968. *
  969. * @return string
  970. */
  971. protected function getStdJQDTActions($recID, $routeActs, $cloneButtonON = false, $customControls = '', $editButton = true, $deleteButton = true) {
  972. $curTimeStamp = strtotime(curdate());
  973. $actions = '';
  974. if ($deleteButton and ! $this->ecReadOnlyAccess) {
  975. // gathering the delete ajax data query
  976. $tmpDeleteQuery = '\'&' . $routeActs . '=true' .
  977. '&' . self::ROUTE_ACTION_DELETE . '=true' .
  978. '&' . self::ROUTE_DELETE_REC_ID . '=' . $recID . '\'';
  979. $deleteDialogWID = 'dialog-modal_' . wf_inputid();
  980. $deleteDialogCloseFunc = ' $(\'#' . $deleteDialogWID . '\').dialog(\'close\') ';
  981. $actions = wf_ConfirmDialogJS('#', web_delete_icon(), $this->messages->getDeleteAlert(), '', '#', self::MISC_JS_DEL_FUNC_NAME . '(\'' . self::URL_ME . '\',' . $tmpDeleteQuery . ');' . $deleteDialogCloseFunc, $deleteDialogCloseFunc, $deleteDialogWID);
  982. }
  983. if ($editButton and ! $this->ecReadOnlyAccess) {
  984. $actions .= wf_nbsp(2);
  985. $actions .= wf_jsAjaxDynamicWindowButton(self::URL_ME, array($routeActs => 'true',
  986. self::ROUTE_ACTION_EDIT => 'true',
  987. self::ROUTE_EDIT_REC_ID => $recID
  988. ), '', web_edit_icon()
  989. );
  990. }
  991. if ($cloneButtonON and ! $this->ecReadOnlyAccess) {
  992. $actions .= wf_nbsp(2);
  993. $actions .= wf_jsAjaxDynamicWindowButton(self::URL_ME, array($routeActs => 'true',
  994. self::ROUTE_ACTION_CLONE => 'true',
  995. self::ROUTE_EDIT_REC_ID => $recID), '', web_clone_icon()
  996. );
  997. }
  998. $actions .= $customControls;
  999. return ($actions);
  1000. }
  1001. /**
  1002. * Simply returns JS snippet for datepicker init on dynamic modal forms
  1003. *
  1004. * @return string
  1005. */
  1006. protected function getDatePickerModalInitJS() {
  1007. $result = '
  1008. onElementInserted("body", ".' . self::MISC_CLASS_DPICKER_MODAL_INIT . '", function(element) {
  1009. $(".' . self::MISC_CLASS_DPICKER_MODAL_INIT . '").datepicker({
  1010. showOn: "both",
  1011. buttonImage: "skins/icon_calendar.gif",
  1012. buttonImageOnly: true,
  1013. dateFormat: "yy-mm-dd",
  1014. showAnim: "slideDown",
  1015. changeMonth: true,
  1016. yearRange: "-100:+100",
  1017. changeYear: true
  1018. });
  1019. });
  1020. ';
  1021. return($result);
  1022. }
  1023. /**
  1024. * Ash oghum durbatulûk, ash oghum gimbatul,
  1025. * Ash oghum thrakatulûk, agh burzum-ishi krimpatul.
  1026. *
  1027. * @param array $dataArray
  1028. * @param string $dbTabName
  1029. * @param string $postFrmCtrlValToChk
  1030. * @param string $webFormMethod
  1031. * @param bool $checkUniqueness
  1032. * @param array $checkUniqArray
  1033. * @param string $crudEntityName
  1034. * @param array $prefillFieldsData
  1035. * @param bool $createFormModality
  1036. * @param bool $editFormModality
  1037. *
  1038. * @return mixed
  1039. *
  1040. * @throws Exception
  1041. */
  1042. public function processCRUDs($dataArray, $dbTabName, $postFrmCtrlValToChk = '', $webFormMethod = '', $checkUniqueness = true, $checkUniqArray = array(), $crudEntityName = '', $prefillFieldsData = array(), $createFormModality = false, $editFormModality = true) {
  1043. $recID = ubRouting::post(self::ROUTE_EDIT_REC_ID);
  1044. $recEdit = ubRouting::checkPost(self::ROUTE_ACTION_EDIT, false);
  1045. $recClone = ubRouting::checkPost(self::ROUTE_ACTION_CLONE, false);
  1046. $recCreate = ubRouting::checkPost(self::ROUTE_ACTION_CREATE);
  1047. $recDelete = ubRouting::checkPost(self::ROUTE_ACTION_DELETE);
  1048. $dbEntity = $this->getDBEntity($dbTabName);
  1049. $foundRecID = '';
  1050. $crudEntityName = empty($crudEntityName) ? 'Entity' : $crudEntityName;
  1051. $entityExistError = '';
  1052. $wfmExistError = '';
  1053. if (empty($dbEntity)) {
  1054. $entityExistError .= wf_nbsp(2) . wf_tag('b') . $dbTabName . wf_tag('b', true);
  1055. }
  1056. if (!method_exists($this, $webFormMethod)) {
  1057. $wfmExistError .= $this->renderWebMsg(__('Error'), __('CRUDs processing: try to call to non-existent method') . ': '
  1058. . wf_nbsp(2) . wf_tag('b') . $webFormMethod . wf_tag('b', true), 'error');
  1059. }
  1060. // todo: check uniqueness of extrcontras recs by profile_id + contract_id + addr_id
  1061. // checking record uniqueness upon criteria, if needed
  1062. if ($checkUniqueness and ! $recDelete) {
  1063. if (empty($checkUniqArray)) {
  1064. $entityExistError .= wf_nbsp(2) . wf_tag('b') . '$checkUniqArray' . wf_tag('b', true);
  1065. } else {
  1066. if ($recEdit) {
  1067. if (!empty($recID)) {
  1068. $foundRecID = $dbEntity->checkRecExists($checkUniqArray, $recID);
  1069. } else {
  1070. $entityExistError .= wf_nbsp(2) . wf_tag('b') . '$recID' . wf_tag('b', true);
  1071. }
  1072. } else {
  1073. $foundRecID = $dbEntity->checkRecExists($checkUniqArray);
  1074. }
  1075. if (!empty($foundRecID)) {
  1076. return ($this->renderWebMsg(__('Error'), __($crudEntityName) . ' ' . __('with such fields criteria') . ' '
  1077. . print_r($checkUniqArray, true) . ' '
  1078. . __('already exists with ID') . ': ' . $foundRecID, 'error'));
  1079. }
  1080. }
  1081. }
  1082. if (!empty($entityExistError)) {
  1083. return($this->renderWebMsg(__('Error'), __('CRUDs processing: possible try to call to/use of non-existent method, data- or DB-entity') . ': '
  1084. . $entityExistError, 'error'));
  1085. }
  1086. if (!empty($recID) and ( $recEdit or $recClone)) {
  1087. if (ubRouting::checkPost($postFrmCtrlValToChk)) {
  1088. if ($recEdit) {
  1089. $this->recordCreateEdit($dbEntity, $dataArray, $recID);
  1090. } elseif ($recClone) {
  1091. $this->recordCreateEdit($dbEntity, $dataArray);
  1092. }
  1093. } else {
  1094. if (empty($wfmExistError)) {
  1095. return (call_user_func_array(array($this, $webFormMethod), array($editFormModality, $recID, $recEdit, $recClone)));
  1096. } else {
  1097. return($wfmExistError);
  1098. }
  1099. }
  1100. } elseif ($recCreate) {
  1101. $this->recordCreateEdit($dbEntity, $dataArray);
  1102. } elseif ($recDelete) {
  1103. if (ubRouting::checkPost(self::ROUTE_DELETE_REC_ID)) {
  1104. $delRecID = ubRouting::post(self::ROUTE_DELETE_REC_ID);
  1105. $tmpUniqArray = array();
  1106. $delRecProtected = false;
  1107. $protectionChkArr = array();
  1108. $protectionChkTab = '';
  1109. $protectionChkFld = '';
  1110. if (ubRouting::checkPost(self::ROUTE_PROFILE_ACTS)) {
  1111. $protectionChkFld = self::DBFLD_EXTCONTRAS_PROFILE_ID;
  1112. $protectionChkTab = self::TABLE_EXTCONTRAS;
  1113. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1114. }
  1115. if (ubRouting::checkPost(self::ROUTE_CONTRACT_ACTS)) {
  1116. $protectionChkFld = self::DBFLD_EXTCONTRAS_CONTRACT_ID;
  1117. $protectionChkTab = self::TABLE_EXTCONTRAS;
  1118. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1119. }
  1120. if (ubRouting::checkPost(self::ROUTE_ADDRESS_ACTS)) {
  1121. $protectionChkFld = self::DBFLD_EXTCONTRAS_ADDRESS_ID;
  1122. $protectionChkTab = self::TABLE_EXTCONTRAS;
  1123. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1124. }
  1125. if (ubRouting::checkPost(self::ROUTE_PERIOD_ACTS)) {
  1126. $protectionChkFld = self::DBFLD_EXTCONTRAS_PERIOD_ID;
  1127. $protectionChkTab = self::TABLE_EXTCONTRAS;
  1128. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1129. }
  1130. if (ubRouting::checkPost(self::ROUTE_CONTRAS_ACTS)) {
  1131. $protectionChkFld = self::DBFLD_INVOICES_CONTRASID;
  1132. $protectionChkTab = self::TABLE_ECINVOICES;
  1133. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1134. $protectionChkFld = self::DBFLD_MONEY_PROFILEID;
  1135. $protectionChkTab = self::TABLE_ECMONEY;
  1136. $protectionChkArr[] = array($protectionChkTab => $protectionChkFld);
  1137. }
  1138. foreach ($protectionChkArr as $tmpArray) {
  1139. foreach ($tmpArray as $table => $field) {
  1140. $tmpUniqArray = $this->createCheckUniquenessArray($field, '=', $delRecID);
  1141. $protectionChkTab = $this->getDBEntity($table);
  1142. $delRecProtected = $protectionChkTab->checkRecExists($tmpUniqArray);
  1143. }
  1144. }
  1145. if (empty($delRecProtected)) {
  1146. $this->recordDelete($dbEntity, $delRecID);
  1147. } else {
  1148. return($this->renderWebMsg(__('Warning'), __('CRUDs processing: can\'t delete record because it\'s ID: [' . $delRecID . '] is used in: `' . $protectionChkTab->getTableName() . '` table'), 'warning'));
  1149. }
  1150. }
  1151. } else {
  1152. if (empty($wfmExistError)) {
  1153. return(call_user_func_array(array($this, $webFormMethod), array($createFormModality, 0, false, false, $prefillFieldsData)));
  1154. } else {
  1155. return($wfmExistError);
  1156. }
  1157. }
  1158. return ('');
  1159. }
  1160. /**
  1161. * Renders main module controls
  1162. *
  1163. * @return string
  1164. */
  1165. public function renderMainControls() {
  1166. $inputs = '';
  1167. $inputs .= wf_Link(self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true', wf_img_sized('skins/extcontrasfin.png', '', '16', '16') . ' ' . __('External counterparties list'), false, 'ubButton');
  1168. $inputs .= wf_Link(self::URL_ME . '&' . self::URL_FINOPERATIONS . '=true', wf_img_sized('skins/ukv/dollar.png') . ' ' . __('Finance operations'), false, 'ubButton');
  1169. $inputs .= wf_Link(self::URL_ME . '&' . self::URL_MISSEDPAYMENTS . '=true', wf_img_sized('skins/dollar_red.png', '', '10', '17') . ' ' . __('Overdue payments'), false, 'ubButton');
  1170. $inputs .= ($this->ecInvoicesON ? wf_Link(self::URL_ME . '&' . self::URL_INVOICES . '=true', wf_img_sized('skins/menuicons/receipt_small.png') . ' ' . __('Invoices list'), false, 'ubButton') : '');
  1171. // dictionaries forms
  1172. $dictControls = wf_Link(self::URL_ME . '&' . self::URL_DICTPROFILES . '=true', wf_img_sized('skins/extcontrasprofiles.png') . ' ' . __('Counterparties profiles dictionary'), false, 'ubButton');
  1173. $dictControls .= wf_Link(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true', wf_img_sized('skins/corporate_small.png') . ' ' . __('Contracts dictionary'), false, 'ubButton');
  1174. $dictControls .= wf_Link(self::URL_ME . '&' . self::URL_DICTADDRESS . '=true', wf_img_sized('skins/extcontrasaddr.png') . ' ' . __('Address dictionary'), false, 'ubButton');
  1175. $dictControls .= wf_Link(self::URL_ME . '&' . self::URL_DICTPERIODS . '=true', wf_img_sized('skins/clock.png') . ' ' . __('Periods dictionary'), false, 'ubButton');
  1176. $inputs .= wf_modalAuto(web_icon_extended() . ' ' . __('Dictionaries'), __('Dictionaries'), $dictControls, 'ubButton');
  1177. $inputs .= wf_jsAjaxDynamicWindowButton(self::URL_ME, array(self::ROUTE_FORCECACHE_UPD => 'true'), wf_img('skins/refresh.gif') . ' ' . __('Refresh cache data'), '', 'ubButton');
  1178. // JS helper functions for forms, modals, etc
  1179. $inputs .= wf_EncloseWithJSTags(wf_JSEmptyFunc() . wf_JSElemInsertedCatcherFunc() . $this->getDatePickerModalInitJS());
  1180. return ($inputs);
  1181. }
  1182. /**
  1183. * Returns dropdown selector control
  1184. *
  1185. * @param $selectorData
  1186. * @param $dbFiledName
  1187. * @param $ctrlName
  1188. * @param $ctrlLabel
  1189. * @param string $selected
  1190. * @param bool $blankFirstRow
  1191. * @param bool $br
  1192. * @param bool $sort
  1193. * @param string $ctrlID
  1194. * @param string $ctrlClass
  1195. * @param string $options
  1196. * @param bool $labelLeftSide
  1197. * @param string $labelOpts
  1198. * @param array $filterData
  1199. * @param string $filterDataElemID
  1200. * @param string $blankFirstRowVal
  1201. * @param string $blankFirstRowDispVal
  1202. *
  1203. * @return string
  1204. */
  1205. public function renderWebSelector($selectorData, $dbFiledName, $ctrlName, $ctrlLabel, $selected = '', $blankFirstRow = false, $br = false, $sort = false, $ctrlID = '', $ctrlClass = '', $options = '', $labelLeftSide = false, $labelOpts = '', $filterData = array(), $filterDataElemID = '', $blankFirstRowVal = '0', $blankFirstRowDispVal = '----') {
  1206. $result = '';
  1207. $ctrlID = (empty($ctrlID) ? wf_InputId() : $ctrlID);
  1208. $tmpArray = ($blankFirstRow ? array($blankFirstRowVal => $blankFirstRowDispVal) : array());
  1209. if (!empty($selectorData)) {
  1210. foreach ($selectorData as $eachID => $eachRec) {
  1211. $tmpValue = '';
  1212. if (is_array($dbFiledName)) {
  1213. foreach ($dbFiledName as $eachdbFieldName) {
  1214. $tmpValue .= $eachRec[$eachdbFieldName] . ' ';
  1215. }
  1216. } else {
  1217. $tmpValue = $eachRec[$dbFiledName];
  1218. }
  1219. $tmpArray[$eachID] = trim($tmpValue);
  1220. }
  1221. }
  1222. $result = wf_Selector($ctrlName, $tmpArray, $ctrlLabel, $selected, $br, $sort, $ctrlID, $ctrlClass, $options, $labelLeftSide, $labelOpts);
  1223. if (!empty($filterData)) {
  1224. $filterDataElemID = (empty($filterDataElemID) ? 'selector_filter_' . wf_InputId() : $filterDataElemID);
  1225. $result .= wf_HiddenInput($filterDataElemID, base64_encode(json_encode($filterData)), $filterDataElemID);
  1226. }
  1227. return ($result);
  1228. }
  1229. /**
  1230. * Returns modal window with some message and pre-defined DOM ID
  1231. *
  1232. * @param $title
  1233. * @param $message
  1234. * @param string $style
  1235. *
  1236. * @return string
  1237. */
  1238. public function renderWebMsg($title, $message, $style = 'info') {
  1239. $errormes = $this->messages->getStyledMessage($message, $style, 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  1240. return(wf_modalAutoForm($title, $errormes, ubRouting::post(self::MISC_ERRFORM_ID_PARAM), '', true, 'true'));
  1241. }
  1242. /**
  1243. * Cumulative method for creating and editing some DB records
  1244. *
  1245. * @param $dbEntity
  1246. * @param $dataArray
  1247. *
  1248. * @param int $recordID
  1249. */
  1250. protected function recordCreateEdit($dbEntity, $dataArray, $recordID = 0) {
  1251. $dbEntity->dataArr($dataArray);
  1252. //$dbEntity->setDebug(true, true);
  1253. if (!empty($recordID)) {
  1254. $dbEntity->where(self::DBFLD_COMMON_ID, '=', $recordID);
  1255. $dbEntity->save(true, true);
  1256. log_register(get_class($this) . ': EDITED record ID: ' . $recordID . ' in table `' . $dbEntity->getTableName() . '`');
  1257. } else {
  1258. $dbEntity->create();
  1259. log_register(get_class($this) . ': ADDED new record to `' . $dbEntity->getTableName() . '`');
  1260. }
  1261. $this->loadDataFromTableCached($dbEntity->getTableName(true), $dbEntity->getTableName(true), true);
  1262. }
  1263. protected function recordDelete($dbEntity, $recordID) {
  1264. $dbEntity->where(self::DBFLD_COMMON_ID, '=', $recordID);
  1265. $dbEntity->delete();
  1266. $this->loadDataFromTableCached($dbEntity->getTableName(true), $dbEntity->getTableName(true), true);
  1267. log_register(get_class($this) . ': REMOVED record ID: ' . $recordID . ' from table `' . $dbEntity->getTableName() . '`');
  1268. }
  1269. /**
  1270. * Returns a profile-editor web form
  1271. *
  1272. * @param bool $modal
  1273. * @param int $profileID
  1274. * @param bool $editAction
  1275. * @param bool $cloneAction
  1276. * @param array $prefillFieldsData
  1277. *
  1278. * @return string
  1279. */
  1280. public function profileWebForm($modal = true, $profileID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  1281. $inputs = '';
  1282. $prfName = '';
  1283. $prfContact = '';
  1284. $prfEDRPO = '';
  1285. $prfEmail = '';
  1286. $modalWinID = ubRouting::post('modalWindowId');
  1287. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1288. if ($modal) {
  1289. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1290. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1291. } else {
  1292. $formClass = self::MISC_CLASS_SUBMITFORM;
  1293. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1294. }
  1295. if (($editAction or $cloneAction) and ! empty($this->allECProfiles[$profileID])) {
  1296. $profile = $this->allECProfiles[$profileID];
  1297. $prfName = $profile[self::DBFLD_PROFILE_NAME];
  1298. $prfContact = $profile[self::DBFLD_PROFILE_CONTACT];
  1299. $prfEDRPO = $profile[self::DBFLD_PROFILE_EDRPO];
  1300. $prfEmail = $profile[self::DBFLD_PROFILE_MAIL];
  1301. }
  1302. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  1303. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_PROFILE_DICT);
  1304. $inputs .= wf_TextInput(self::CTRL_PROFILE_NAME, __('Name') . $this->supFrmFldMark, $prfName, false, '', '', $emptyCheckClass, '', '', true);
  1305. $inputs .= wf_TextInput(self::CTRL_PROFILE_CONTACT, __('Contact data'), $prfContact, false, '', '', '', '', '', true);
  1306. $inputs .= wf_TextInput(self::CTRL_PROFILE_EDRPO, __('EDRPO/INN') . $this->supFrmFldMark, $prfEDRPO, false, '', '', $emptyCheckClass, '', '', true);
  1307. $inputs .= wf_TextInput(self::CTRL_PROFILE_MAIL, __('E-mail'), $prfEmail, false, '', '', '', '', '', true);
  1308. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', $this->submitBtnDisabled);
  1309. $inputs .= wf_HiddenInput(self::ROUTE_PROFILE_ACTS, 'true');
  1310. if ($editAction) {
  1311. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  1312. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $profileID);
  1313. } else {
  1314. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  1315. }
  1316. if ($modal and ! empty($modalWinID)) {
  1317. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  1318. }
  1319. $inputs = wf_Form(self::URL_ME . '&' . self::URL_DICTPROFILES . '=true', 'POST', $inputs, 'glamour form-grid-2cols form-grid-2cols-label-right ' . $formClass);
  1320. if ($modal and ! empty($modalWinID)) {
  1321. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  1322. }
  1323. return ($inputs);
  1324. }
  1325. /**
  1326. * Renders JQDT for profiles dictionary
  1327. *
  1328. * @param string $customJSCode
  1329. * @param string $markRowForID
  1330. * @param string $detailsFilter
  1331. * @param bool $stdJSForCRUDs
  1332. *
  1333. * @return string
  1334. */
  1335. public function profileRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  1336. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_PROFILE_JSON . '=true';
  1337. $columns[] = __('ID');
  1338. $columns[] = __('Profile name');
  1339. $columns[] = __('EDRPO');
  1340. $columns[] = __('Contact');
  1341. $columns[] = __('E-mail');
  1342. $columns[] = __('Actions');
  1343. $opts = '
  1344. "order": [[ 0, "desc" ]],
  1345. "columnDefs": [ {"targets": [0, 2, 5], "className": "dt-center dt-head-center"},
  1346. {"targets": [5], "orderable": false},
  1347. {"targets": [5], "width": "85px"}
  1348. ]
  1349. ';
  1350. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_DICTPROFILES . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL);
  1351. return($result);
  1352. }
  1353. /**
  1354. * Renders JSON for profile's dictionary JQDT
  1355. */
  1356. public function profileRenderListJSON() {
  1357. $this->loadDataFromTableCached(self::TABLE_ECPROFILES, self::TABLE_ECPROFILES);
  1358. $json = new wf_JqDtHelper();
  1359. if (!empty($this->allECProfiles)) {
  1360. $data = array();
  1361. foreach ($this->allECProfiles as $eachRecID) {
  1362. foreach ($eachRecID as $fieldName => $fieldVal) {
  1363. $data[] = $fieldVal;
  1364. }
  1365. $actions = $this->getStdJQDTActions($eachRecID['id'], self::ROUTE_PROFILE_ACTS, true);
  1366. $data[] = $actions;
  1367. $json->addRow($data);
  1368. unset($data);
  1369. }
  1370. }
  1371. $json->getJson();
  1372. }
  1373. /**
  1374. * Returns a contract-editor web form
  1375. *
  1376. * @param bool $modal
  1377. * @param int $contractID
  1378. * @param bool $editAction
  1379. * @param bool $cloneAction
  1380. * @param array $prefillFieldsData
  1381. *
  1382. * @return string
  1383. */
  1384. public function contractWebForm($modal = true, $contractID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  1385. $inputs = '';
  1386. $ctrctDTStart = '';
  1387. $ctrctDTEnd = '';
  1388. $ctrctContract = '';
  1389. $ctrctSubject = '';
  1390. $ctrctAutoProlong = '';
  1391. $ctrctFullSum = '';
  1392. $ctrctNotes = '';
  1393. $modalWinID = ubRouting::post('modalWindowId');
  1394. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1395. if ($modal) {
  1396. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1397. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1398. } else {
  1399. $formClass = self::MISC_CLASS_SUBMITFORM;
  1400. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1401. }
  1402. if (($editAction or $cloneAction) and ! empty($this->allECContracts[$contractID])) {
  1403. $contract = $this->allECContracts[$contractID];
  1404. $ctrctDTStart = $contract[self::DBFLD_CTRCT_DTSTART];
  1405. $ctrctDTEnd = $contract[self::DBFLD_CTRCT_DTEND];
  1406. $ctrctContract = $contract[self::DBFLD_CTRCT_CONTRACT];
  1407. $ctrctSubject = $contract[self::DBFLD_CTRCT_SUBJECT];
  1408. $ctrctAutoProlong = ubRouting::filters($contract[self::DBFLD_CTRCT_AUTOPRLNG], 'fi', FILTER_VALIDATE_BOOLEAN);
  1409. $ctrctFullSum = $contract[self::DBFLD_CTRCT_FULLSUM];
  1410. $ctrctNotes = $contract[self::DBFLD_CTRCT_NOTES];
  1411. }
  1412. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  1413. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_CNTRCTS_DICT);
  1414. $datepickerID1 = wf_InputId();
  1415. $datepickerID2 = wf_InputId();
  1416. $ctrlsLblStyle = 'style="line-height: 2.2em"';
  1417. $inputs .= wf_tag('label', false, '', 'for="' . $datepickerID1 . '"');
  1418. $inputs .= __('Date start') . $this->supFrmFldMark;
  1419. $inputs .= wf_tag('label', true);
  1420. $inputs .= wf_tag('span', false);
  1421. $inputs .= wf_DatePickerPreset(self::CTRL_CTRCT_DTSTART, $ctrctDTStart, true, $datepickerID1, $emptyCheckClass . ' ' . self::MISC_CLASS_DPICKER_MODAL_INIT);
  1422. $inputs .= wf_tag('span', true);
  1423. $inputs .= wf_tag('span', false);
  1424. $inputs .= wf_tag('label', false, '', 'for="' . $datepickerID2 . '"');
  1425. $inputs .= __('Date end') . $this->supFrmFldMark;
  1426. $inputs .= wf_tag('label', true);
  1427. $inputs .= wf_DatePickerPreset(self::CTRL_CTRCT_DTEND, $ctrctDTEnd, true, $datepickerID2, $emptyCheckClass . ' ' . self::MISC_CLASS_DPICKER_MODAL_INIT);
  1428. $inputs .= wf_nbsp(14);
  1429. $inputs .= wf_CheckInput(self::CTRL_CTRCT_AUTOPRLNG, __('Autoprolong'), false, $ctrctAutoProlong, '', '');
  1430. $inputs .= wf_tag('span', true);
  1431. $inputs .= wf_TextInput(self::CTRL_CTRCT_CONTRACT, __('Contract number') . $this->supFrmFldMark, $ctrctContract, false, '', '', $emptyCheckClass, '', '', true);
  1432. $inputs .= wf_tag('span', false);
  1433. $inputs .= wf_TextInput(self::CTRL_CTRCT_FULLSUM, __('Contract full sum'), $ctrctFullSum, false, '4', 'finance', '', '', '', true);
  1434. $inputs .= wf_tag('span', true);
  1435. $inputs .= wf_TextInput(self::CTRL_CTRCT_SUBJECT, __('Contract subject'), $ctrctSubject, false, '70', '', 'right-two-thirds-occupy', '', '', true);
  1436. $inputs .= wf_TextInput(self::CTRL_CTRCT_NOTES, __('Contract notes'), $ctrctNotes, false, '70', '', 'right-two-thirds-occupy', '', '', true);
  1437. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', $this->submitBtnDisabled);
  1438. $inputs .= wf_HiddenInput(self::ROUTE_CONTRACT_ACTS, 'true');
  1439. if ($editAction) {
  1440. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  1441. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $contractID);
  1442. } else {
  1443. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  1444. }
  1445. if ($modal and ! empty($modalWinID)) {
  1446. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  1447. }
  1448. $inputs = wf_Form(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true', 'POST', $inputs, 'glamour form-grid-3cols form-grid-3cols-label-right ' . $formClass);
  1449. if ($editAction and $this->fileStorageEnabled) {
  1450. $this->fileStorage->setItemid(self::URL_DICTCONTRACTS . $contractID);
  1451. $inputs .= wf_tag('span', false, '', $ctrlsLblStyle);
  1452. $inputs .= wf_tag('h3');
  1453. $inputs .= __('Uploaded files');
  1454. $inputs .= wf_tag('h3', true);
  1455. $inputs .= $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true'), true);
  1456. $inputs .= wf_tag('span', true);
  1457. }
  1458. if ($modal and ! empty($modalWinID)) {
  1459. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  1460. }
  1461. return ($inputs);
  1462. }
  1463. /**
  1464. * Renders JQDT for contracts dictionary
  1465. *
  1466. * @param string $customJSCode
  1467. * @param string $markRowForID
  1468. * @param string $detailsFilter
  1469. * @param bool $stdJSForCRUDs
  1470. *
  1471. * @return string
  1472. */
  1473. public function contractRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  1474. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_CONTRACT_JSON . '=true';
  1475. $columns[] = __('ID');
  1476. $columns[] = __('Contract');
  1477. $columns[] = __('Date start');
  1478. $columns[] = __('Date end');
  1479. $columns[] = __('Contract subject');
  1480. $columns[] = __('Full sum');
  1481. $columns[] = __('Autoprolong');
  1482. $columns[] = __('Notes');
  1483. $columns[] = __('Uploaded files');
  1484. $columns[] = __('Actions');
  1485. $opts = '
  1486. "order": [[ 1, "desc" ]],
  1487. "columnDefs": [
  1488. {"targets": [4, 7], "className": "dt-left dt-head-center"},
  1489. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  1490. {"targets": [8, 9], "orderable": false},
  1491. {"targets": [8, 9], "width": "85px"}
  1492. ]
  1493. ';
  1494. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL);
  1495. return($result);
  1496. }
  1497. /**
  1498. * Renders JSON for contract's dictionary JQDT
  1499. */
  1500. public function contractRenderListJSON() {
  1501. $this->loadDataFromTableCached(self::TABLE_ECCONTRACTS, self::TABLE_ECCONTRACTS);
  1502. $json = new wf_JqDtHelper();
  1503. if (!empty($this->allECContracts)) {
  1504. $data = array();
  1505. foreach ($this->allECContracts as $eachRecID) {
  1506. foreach ($eachRecID as $fieldName => $fieldVal) {
  1507. if ($fieldName == self::DBFLD_CTRCT_AUTOPRLNG) {
  1508. $data[] = (empty($fieldVal) ? web_red_led() : web_green_led());
  1509. } else {
  1510. $data[] = $fieldVal;
  1511. }
  1512. }
  1513. if ($this->fileStorage) {
  1514. $this->fileStorage->setItemid(self::URL_DICTCONTRACTS . $eachRecID['id']);
  1515. $data[] = $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true'), true);
  1516. } else {
  1517. $data[] = __('Filestorage') . ' - ' . __('Disabled');
  1518. }
  1519. $actions = $this->getStdJQDTActions($eachRecID['id'], self::ROUTE_CONTRACT_ACTS, true);
  1520. $data[] = $actions;
  1521. $json->addRow($data);
  1522. unset($data);
  1523. }
  1524. }
  1525. $json->getJson();
  1526. }
  1527. /**
  1528. * Returns a address-editor web form
  1529. *
  1530. * @param bool $modal
  1531. * @param int $addressID
  1532. * @param bool $editAction
  1533. * @param bool $cloneAction
  1534. * @param array $prefillFieldsData
  1535. *
  1536. * @return string
  1537. */
  1538. public function addressWebForm($modal = true, $addressID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  1539. $inputs = '';
  1540. $addrAddress = '';
  1541. $addrSum = '';
  1542. $addrCtrctNotes = '';
  1543. $addrNotes = '';
  1544. $modalWinID = ubRouting::post('modalWindowId');
  1545. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1546. if ($modal) {
  1547. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1548. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1549. } else {
  1550. $formClass = self::MISC_CLASS_SUBMITFORM;
  1551. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1552. }
  1553. if (($editAction or $cloneAction) and ! empty($this->allECAddresses[$addressID])) {
  1554. $address = $this->allECAddresses[$addressID];
  1555. $addrAddress = $address[self::DBFLD_ADDRESS_ADDR];
  1556. $addrSum = $address[self::DBFLD_ADDRESS_SUM];
  1557. $addrCtrctNotes = $address[self::DBFLD_ADDRESS_CTNOTES];
  1558. $addrNotes = $address[self::DBFLD_ADDRESS_NOTES];
  1559. }
  1560. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  1561. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_ADDRESS_DICT);
  1562. $inputs .= wf_TextInput(self::CTRL_ADDRESS_ADDR, __('Address') . $this->supFrmFldMark, $addrAddress, false, '', '', $emptyCheckClass, '', '', true);
  1563. $inputs .= wf_TextInput(self::CTRL_ADDRESS_SUM, __('Sum'), $addrSum, false, '', '', '', '', '', true);
  1564. $inputs .= wf_TextInput(self::CTRL_ADDRESS_CTNOTES, __('Contract notes'), $addrCtrctNotes, false, '', '', $emptyCheckClass, '', '', true);
  1565. $inputs .= wf_TextInput(self::CTRL_ADDRESS_NOTES, __('Notes'), $addrNotes, false, '', '', '', '', '', true);
  1566. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', $this->submitBtnDisabled);
  1567. $inputs .= wf_HiddenInput(self::ROUTE_ADDRESS_ACTS, 'true');
  1568. if ($editAction) {
  1569. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  1570. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $addressID);
  1571. } else {
  1572. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  1573. }
  1574. if ($modal and ! empty($modalWinID)) {
  1575. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  1576. }
  1577. $inputs = wf_Form(self::URL_ME . '&' . self::URL_DICTADDRESS . '=true', 'POST', $inputs, 'glamour form-grid-2cols form-grid-2cols-label-right ' . $formClass);
  1578. if ($modal and ! empty($modalWinID)) {
  1579. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  1580. }
  1581. return ($inputs);
  1582. }
  1583. /**
  1584. * Renders JQDT for address dictionary
  1585. *
  1586. * @param string $customJSCode
  1587. * @param string $markRowForID
  1588. * @param string $detailsFilter
  1589. * @param bool $stdJSForCRUDs
  1590. *
  1591. * @return string
  1592. */
  1593. public function addressRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  1594. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_ADDRESS_JSON . '=true';
  1595. $columns[] = __('ID');
  1596. $columns[] = __('Address');
  1597. $columns[] = __('Contract sum');
  1598. $columns[] = __('Contract notes');
  1599. $columns[] = __('Address notes');
  1600. $columns[] = __('Actions');
  1601. $opts = '
  1602. "order": [[ 0, "desc" ]],
  1603. "columnDefs": [ {"targets": [0, 2, 5], "className": "dt-center dt-head-center"},
  1604. {"targets": [5], "orderable": false},
  1605. {"targets": [5], "width": "85px"}
  1606. ]
  1607. ';
  1608. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_DICTADDRESS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL);
  1609. return($result);
  1610. }
  1611. /**
  1612. * Renders JSON for address's dictionary JQDT
  1613. */
  1614. public function addressRenderListJSON() {
  1615. $this->loadDataFromTableCached(self::TABLE_ECADDRESS, self::TABLE_ECADDRESS);
  1616. $json = new wf_JqDtHelper();
  1617. if (!empty($this->allECAddresses)) {
  1618. $data = array();
  1619. foreach ($this->allECAddresses as $eachRecID) {
  1620. foreach ($eachRecID as $fieldName => $fieldVal) {
  1621. $data[] = $fieldVal;
  1622. }
  1623. $actions = $this->getStdJQDTActions($eachRecID['id'], self::ROUTE_ADDRESS_ACTS, true);
  1624. $data[] = $actions;
  1625. $json->addRow($data);
  1626. unset($data);
  1627. }
  1628. }
  1629. $json->getJson();
  1630. }
  1631. public function periodWebForm($modal = true, $periodID = 0, $editAction = false) {
  1632. $inputs = '';
  1633. $prdName = '';
  1634. $modalWinID = ubRouting::post('modalWindowId');
  1635. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1636. if ($modal) {
  1637. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1638. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1639. } else {
  1640. $formClass = self::MISC_CLASS_SUBMITFORM;
  1641. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1642. }
  1643. if ($editAction and ! empty($this->allECPeriods[$periodID])) {
  1644. $period = $this->allECPeriods[$periodID];
  1645. $prdName = $period[self::DBFLD_PERIOD_NAME];
  1646. }
  1647. $submitCapt = ($editAction) ? __('Edit') : __('Create');
  1648. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_PERIODS_DICT);
  1649. $ctrlsLblStyle = 'style="line-height: 3.4em; margin-right: 0.5em;"';
  1650. $inputs .= wf_TextInput(self::CTRL_PERIOD_NAME, __('Name') . $this->supFrmFldMark, $prdName, true, '', '', $emptyCheckClass, '', '', true, $ctrlsLblStyle);
  1651. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', 'style="width: 100%"; ' . $this->submitBtnDisabled);
  1652. $inputs .= wf_HiddenInput(self::ROUTE_PERIOD_ACTS, 'true');
  1653. if ($editAction) {
  1654. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  1655. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $periodID);
  1656. } else {
  1657. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  1658. }
  1659. if ($modal and ! empty($modalWinID)) {
  1660. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  1661. }
  1662. $inputs = wf_Form(self::URL_ME . '&' . self::URL_DICTPERIODS . '=true', 'POST', $inputs, 'glamour ' . $formClass);
  1663. if ($modal and ! empty($modalWinID)) {
  1664. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  1665. }
  1666. return ($inputs);
  1667. }
  1668. /**
  1669. * Renders JQDT for period dictionary
  1670. *
  1671. * @param string $customJSCode
  1672. * @param string $markRowForID
  1673. * @param string $detailsFilter
  1674. * @param bool $stdJSForCRUDs
  1675. *
  1676. * @return string
  1677. */
  1678. public function periodRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  1679. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_PERIOD_JSON . '=true';
  1680. $columns[] = __('ID');
  1681. $columns[] = __('Period name');
  1682. $columns[] = __('Actions');
  1683. $opts = '
  1684. "order": [[ 0, "desc" ]],
  1685. "columnDefs": [ {"targets": ["_all"], "className": "dt-center dt-head-center"},
  1686. {"targets": [2], "orderable": false},
  1687. {"targets": [2], "width": "85px"}
  1688. ]
  1689. ';
  1690. $result = $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_DICTPERIODS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL);
  1691. return($result);
  1692. }
  1693. /**
  1694. * Renders JSON for period's dictionary JQDT
  1695. */
  1696. public function periodRenderListJSON() {
  1697. $this->loadDataFromTableCached(self::TABLE_ECPERIODS, self::TABLE_ECPERIODS);
  1698. $json = new wf_JqDtHelper();
  1699. if (!empty($this->allECPeriods)) {
  1700. $data = array();
  1701. foreach ($this->allECPeriods as $eachRecID) {
  1702. foreach ($eachRecID as $fieldName => $fieldVal) {
  1703. $data[] = $fieldVal;
  1704. }
  1705. $actions = $this->getStdJQDTActions($eachRecID['id'], self::ROUTE_PERIOD_ACTS);
  1706. $data[] = $actions;
  1707. $json->addRow($data);
  1708. unset($data);
  1709. }
  1710. }
  1711. $json->getJson();
  1712. }
  1713. /**
  1714. * Returns a filter web form for invoices main form
  1715. *
  1716. * @return string
  1717. */
  1718. public function invoiceFilterWebForm() {
  1719. $ajaxURLStr = self::URL_ME . '&' . self::ROUTE_INVOICES_JSON . '=true';
  1720. $formID = 'Form_' . wf_InputId();
  1721. $jqdtID = 'jqdt_' . md5($ajaxURLStr);
  1722. $inputs = wf_tag('h3', false);
  1723. $inputs .= __('Filter by:');
  1724. $inputs .= wf_tag('h3', true);
  1725. $rows = wf_DatesTimesRangeFilter(true, true, false, false, true, false, ubRouting::post(self::MISC_WEBFILTER_DATE_START), ubRouting::post(self::MISC_WEBFILTER_DATE_END), self::MISC_WEBFILTER_DATE_START, self::MISC_WEBFILTER_DATE_END
  1726. );
  1727. $inputs .= wf_TableBody($rows, 'auto');
  1728. $inputs .= wf_SubmitClassed(true, 'ubButton', '', __('Show'), '', 'style="width: 100%"');
  1729. $inputs = wf_Form($ajaxURLStr, 'POST', $inputs, 'glamour form-grid-3r-1c', '', $formID, '', 'style="margin-top: 110px;"');
  1730. $inputs .= wf_EncloseWithJSTags(wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID));
  1731. return ($inputs);
  1732. }
  1733. /**
  1734. * Returns an invoice-editor web form
  1735. *
  1736. * @param bool $modal
  1737. * @param int $invoiceID
  1738. * @param bool $editAction
  1739. * @param bool $cloneAction
  1740. * @param array $prefillFieldsData
  1741. *
  1742. * @return string
  1743. */
  1744. public function invoiceWebForm($modal = true, $invoiceID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  1745. $inputs = '';
  1746. $invoContrasID = 0;
  1747. $invoInternalNum = '';
  1748. $invoNumber = '';
  1749. $invoDate = '';
  1750. $invoSum = '';
  1751. $invoSumVAT = '';
  1752. $invoNotes = '';
  1753. $invoIncoming = '';
  1754. $invoOutgoing = '';
  1755. $modalWinID = ubRouting::post('modalWindowId');
  1756. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1757. if ($modal) {
  1758. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1759. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1760. } else {
  1761. $formClass = self::MISC_CLASS_SUBMITFORM;
  1762. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1763. }
  1764. if (($editAction or $cloneAction) and ! empty($this->allECInvoices[$invoiceID])) {
  1765. $invoice = $this->allECInvoices[$invoiceID];
  1766. $invoContrasID = $invoice[self::DBFLD_INVOICES_CONTRASID];
  1767. $invoInternalNum = $invoice[self::DBFLD_INVOICES_INTERNAL_NUM];
  1768. $invoNumber = $invoice[self::DBFLD_INVOICES_INVOICE_NUM];
  1769. $invoDate = $invoice[self::DBFLD_INVOICES_DATE];
  1770. $invoSum = $invoice[self::DBFLD_INVOICES_SUM];
  1771. $invoSumVAT = $invoice[self::DBFLD_INVOICES_SUM_VAT];
  1772. $invoNotes = $invoice[self::DBFLD_INVOICES_NOTES];
  1773. $invoIncoming = ubRouting::filters($invoice[self::DBFLD_INVOICES_INCOMING], 'fi', FILTER_VALIDATE_BOOLEAN);
  1774. $invoOutgoing = ubRouting::filters($invoice[self::DBFLD_INVOICES_OUTGOING], 'fi', FILTER_VALIDATE_BOOLEAN);
  1775. }
  1776. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  1777. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_INVOICES_LIST);
  1778. $ctrlsLblStyle = 'style="line-height: 2.2em"';
  1779. $datepickerID = wf_InputId();
  1780. $inputs .= wf_TextInput(self::CTRL_INVOICES_INVOICE_NUM, __('Invoice number') . $this->supFrmFldMark, $invoNumber, false, '', '', $emptyCheckClass, '', '', true);
  1781. $inputs .= wf_tag('span', false);
  1782. $inputs .= wf_TextInput(self::CTRL_INVOICES_INTERNAL_NUM, __('Invoice internal number'), $invoInternalNum, false, '', '', '', '', '', true);
  1783. $inputs .= wf_tag('span', true);
  1784. $inputs .= wf_tag('label', false, '', 'for="' . $datepickerID . '"');
  1785. $inputs .= __('Invoice date') . $this->supFrmFldMark;
  1786. $inputs .= wf_tag('label', true);
  1787. $inputs .= wf_tag('span', false);
  1788. $inputs .= wf_DatePickerPreset(self::CTRL_INVOICES_DATE, $invoDate, true, $datepickerID, $emptyCheckClass . ' ' . self::MISC_CLASS_DPICKER_MODAL_INIT);
  1789. $inputs .= wf_tag('span', true);
  1790. $inputs .= wf_tag('span', false);
  1791. $inputs .= wf_TextInput(self::CTRL_INVOICES_SUM, __('Invoice sum') . $this->supFrmFldMark, $invoSum, false, '4', 'finance', $emptyCheckClass, '', '', true);
  1792. $inputs .= wf_nbsp(6);
  1793. $inputs .= wf_TextInput(self::CTRL_INVOICES_SUM_VAT, __('Invoice VAT sum'), $invoSumVAT, false, '4', 'finance', '', '', '', true);
  1794. $inputs .= wf_tag('span', true);
  1795. $inputs .= $this->renderWebSelector($this->allExtContrasExten, array(self::TABLE_ECPROFILES . self::DBFLD_PROFILE_EDRPO,
  1796. self::TABLE_ECPROFILES . self::DBFLD_PROFILE_NAME,
  1797. self::TABLE_ECPROFILES . self::DBFLD_PROFILE_CONTACT
  1798. ), self::CTRL_INVOICES_CONTRASID, __('Counterparty'), $invoContrasID, true, false, true, '', 'right-two-thirds-occupy', '', true);
  1799. $inputs .= wf_TextInput(self::CTRL_INVOICES_NOTES, __('Invoice notes'), $invoNotes, false, '70', '', 'right-two-thirds-occupy', '', '', true);
  1800. $inputs .= wf_tag('span', false, 'glamour full-width-occupy', 'style="text-align: center; width: 97%;"');
  1801. $inputs .= wf_RadioInput(self::CTRL_INVOICES_IN_OUT, __('Incoming invoice'), 'incoming', false, $invoIncoming);
  1802. $inputs .= wf_nbsp(8);
  1803. $inputs .= wf_RadioInput(self::CTRL_INVOICES_IN_OUT, __('Outgoing invoice'), 'outgoing', false, $invoOutgoing);
  1804. $inputs .= wf_tag('span', true);
  1805. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', $this->submitBtnDisabled);
  1806. $inputs .= wf_HiddenInput(self::ROUTE_INVOICES_ACTS, 'true');
  1807. if ($editAction) {
  1808. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  1809. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $invoiceID);
  1810. } else {
  1811. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  1812. }
  1813. if ($modal and ! empty($modalWinID)) {
  1814. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  1815. }
  1816. $inputs = wf_Form(self::URL_ME . '&' . self::URL_INVOICES . '=true', 'POST', $inputs, 'glamour form-grid-3cols form-grid-3cols-label-right ' . $formClass);
  1817. if ($editAction and $this->fileStorageEnabled) {
  1818. $this->fileStorage->setItemid(self::URL_INVOICES . $invoiceID);
  1819. $inputs .= wf_tag('span', false, '', $ctrlsLblStyle);
  1820. $inputs .= wf_tag('h3');
  1821. $inputs .= __('Uploaded files');
  1822. $inputs .= wf_tag('h3', true);
  1823. $inputs .= $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_INVOICES . '=true'), true);
  1824. $inputs .= wf_tag('span', true);
  1825. }
  1826. if ($modal and ! empty($modalWinID)) {
  1827. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  1828. }
  1829. return ($inputs);
  1830. }
  1831. /**
  1832. * Renders JQDT for invoices list
  1833. *
  1834. * @param string $customJSCode
  1835. * @param string $markRowForID
  1836. * @param string $detailsFilter
  1837. * @param bool $stdJSForCRUDs
  1838. *
  1839. * @return string
  1840. */
  1841. public function invoiceRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  1842. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_INVOICES_JSON . '=true';
  1843. $columns[] = __('ID');
  1844. $columns[] = __('Counterparty');
  1845. $columns[] = __('Internal number');
  1846. $columns[] = __('Invoice number');
  1847. $columns[] = __('Invoice date');
  1848. $columns[] = __('Sum total');
  1849. $columns[] = __('Sum VAT');
  1850. $columns[] = __('Notes');
  1851. $columns[] = __('Ingoing');
  1852. $columns[] = __('Outgoing');
  1853. $columns[] = __('Uploaded files');
  1854. $columns[] = __('Actions');
  1855. $opts = '
  1856. "order": [[ 0, "desc" ]],
  1857. "columnDefs": [ {"targets": [1, 7], "className": "dt-left dt-head-center"},
  1858. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  1859. {"targets": [10, 11], "orderable": false},
  1860. {"targets": [10, 11], "width": "85px"}
  1861. ]
  1862. ';
  1863. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_INVOICES . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL);
  1864. return($result);
  1865. }
  1866. /**
  1867. * Renders JSON for invoices JQDT
  1868. *
  1869. * @param string $whereRaw
  1870. */
  1871. public function invoiceRenderListJSON($whereRaw = '') {
  1872. if (!empty($whereRaw)) {
  1873. $this->dbECInvoices->whereRaw($whereRaw);
  1874. }
  1875. $this->loadDataFromTableCached(self::TABLE_ECINVOICES, self::TABLE_ECINVOICES, !empty($whereRaw), true, '', '', !empty($whereRaw));
  1876. $json = new wf_JqDtHelper();
  1877. if (!empty($this->allECInvoices)) {
  1878. $data = array();
  1879. foreach ($this->allECInvoices as $eachRecID) {
  1880. foreach ($eachRecID as $fieldName => $fieldVal) {
  1881. if ($fieldName == self::DBFLD_INVOICES_CONTRASID) {
  1882. $data[] = (empty($this->allExtContrasExten[$fieldVal]) ? '' : $this->allExtContrasExten[$fieldVal][self::TABLE_ECPROFILES . self::DBFLD_PROFILE_EDRPO] . ' '
  1883. . $this->allExtContrasExten[$fieldVal][self::TABLE_ECPROFILES . self::DBFLD_PROFILE_NAME]
  1884. );
  1885. } elseif ($fieldName == self::DBFLD_INVOICES_INCOMING or $fieldName == self::DBFLD_INVOICES_OUTGOING) {
  1886. $data[] = (empty($fieldVal) ? web_red_led() : web_green_led());
  1887. } else {
  1888. $data[] = $fieldVal;
  1889. }
  1890. }
  1891. $this->fileStorage->setItemid(self::URL_INVOICES . $eachRecID['id']);
  1892. $data[] = $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_INVOICES . '=true'), true);
  1893. $actions = $this->getStdJQDTActions($eachRecID['id'], self::ROUTE_INVOICES_ACTS, true);
  1894. $data[] = $actions;
  1895. $json->addRow($data);
  1896. unset($data);
  1897. }
  1898. }
  1899. $json->getJson();
  1900. }
  1901. /**
  1902. * Returns a filter web form for extcontras main form
  1903. *
  1904. * @return string
  1905. */
  1906. public function extcontrasFilterWebForm() {
  1907. $ajaxURLStr = self::URL_ME . '&' . self::ROUTE_CONTRAS_JSON . '=true';
  1908. $formID = 'Form_' . wf_InputId();
  1909. $jqdtID = 'jqdt_' . md5($ajaxURLStr);
  1910. $inputs = wf_tag('h3', false);
  1911. $inputs .= __('Filter by') . ':';
  1912. $inputs .= wf_tag('h3', true);
  1913. $cells = wf_DatesTimesRangeFilter(true, true, false, false, true, false, ubRouting::post(self::MISC_WEBFILTER_DATE_START), ubRouting::post(self::MISC_WEBFILTER_DATE_END), self::MISC_WEBFILTER_DATE_START, self::MISC_WEBFILTER_DATE_END
  1914. );
  1915. $cells .= wf_TableCell(wf_nbsp(2));
  1916. $cells .= wf_TableCell(__('Payday') . ':');
  1917. $cells .= wf_TableCell(wf_TextInput(self::MISC_WEBFILTER_PAYDAY, '', ubRouting::post(self::MISC_WEBFILTER_PAYDAY), true, 4, 'digits'));
  1918. $rows = wf_TableRow($cells);
  1919. $inputs .= wf_TableBody($rows, 'auto');
  1920. $inputs .= wf_SubmitClassed(true, 'ubButton', '', __('Show'), '', 'style="width: 100%"');
  1921. $inputs = wf_Form($ajaxURLStr, 'POST', $inputs, 'glamour form-grid-3r-1c', '', $formID, '', 'style="margin-top: 105px;"');
  1922. $inputs .= wf_EncloseWithJSTags(wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID));
  1923. return ($inputs);
  1924. }
  1925. /**
  1926. * Returns a filter web form for extcontras main form
  1927. *
  1928. * @param string $ajaxURLStr
  1929. * @param string $jqdtID
  1930. * @param bool $includePayDayCtrl
  1931. *
  1932. * @return string
  1933. */
  1934. public function extcontrasFilterWebFormInline($ajaxURLStr, $jqdtID, $includePayDayCtrl = true) {
  1935. $formID = 'Form_' . wf_InputId();
  1936. $inputs = '';
  1937. $style = 'style="font-family: Helvetica, Arial, Verdana, sans-serif; font-size: 12px;"';
  1938. $caption = wf_tag('span') . __('Filter by') . ':' . wf_tag('span', true);
  1939. $inputs.= wf_tag('span', false, '', $style);
  1940. $inputs.= wf_DatesTimesRangeFilter(false, false, false, false, true, false,
  1941. ubRouting::post(self::MISC_WEBFILTER_DATE_START), ubRouting::post(self::MISC_WEBFILTER_DATE_END),
  1942. self::MISC_WEBFILTER_DATE_START, self::MISC_WEBFILTER_DATE_END
  1943. );
  1944. $inputs.= wf_tag('span', true);
  1945. if ($includePayDayCtrl) {
  1946. $inputs .= wf_tag('span', false, '', $style);
  1947. $inputs .= __('Payday') . ':' . wf_nbsp(2);
  1948. $inputs .= wf_TextInput(self::MISC_WEBFILTER_PAYDAY, '', ubRouting::post(self::MISC_WEBFILTER_PAYDAY), false, 4, 'digits');
  1949. $inputs .= wf_tag('span', true);
  1950. }
  1951. $inputs.= wf_SubmitClassed(true, 'ubButtonInline', '', __('Show'), '', '');
  1952. $inputs = wf_Form($ajaxURLStr,'POST', $caption . $inputs, 'glamour form-grid-5cols-inline', '', $formID, '', '');
  1953. $inputs.= wf_EncloseWithJSTags(wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID));
  1954. return ($inputs);
  1955. }
  1956. /**
  1957. * Returns a external counterparty editor web form
  1958. *
  1959. * @param bool $modal
  1960. * @param int $extContrasID
  1961. * @param bool $editAction
  1962. * @param bool $cloneAction
  1963. * @param array $prefillFieldsData
  1964. *
  1965. * @return string
  1966. */
  1967. public function extcontrasWebForm($modal = true, $extContrasID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  1968. $inputs = '';
  1969. $contrasProfileID = 1;
  1970. $contrasContractID = '';
  1971. $contrasAddressID = '';
  1972. $contrasPeriodID = '';
  1973. $contrasPayDay = '';
  1974. $modalWinID = ubRouting::post('modalWindowId');
  1975. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  1976. if ($modal) {
  1977. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  1978. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  1979. } else {
  1980. $formClass = self::MISC_CLASS_SUBMITFORM;
  1981. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  1982. }
  1983. if (($editAction or $cloneAction) and ! empty($this->allExtContrasExten[$extContrasID])) {
  1984. $extContra = $this->allExtContrasExten[$extContrasID];
  1985. $contrasProfileID = $extContra[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PROFILE_ID];
  1986. $contrasContractID = $extContra[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_CONTRACT_ID];
  1987. $contrasAddressID = $extContra[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_ADDRESS_ID];
  1988. $contrasPeriodID = $extContra[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PERIOD_ID];
  1989. $contrasPayDay = $extContra[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PAYDAY];
  1990. }
  1991. $ecProfilesWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_PROFILES;
  1992. $ecContractsWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_CONTRACTS;
  1993. $ecAddressWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_ADDRESS;
  1994. $contractsFilterDataID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_FILTDATA_CONTRACTS;
  1995. $addressFilterDataID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_FILTDATA_ADDRESS;
  1996. $editDBValProfileID = self::MISC_WEBSEL_DBVAL_PROFILE_ID;
  1997. $editDBValContractID = self::MISC_WEBSEL_DBVAL_CONTRACTS_ID;
  1998. $editDBValAddressID = self::MISC_WEBSEL_DBVAL_ADDRESS_ID;
  1999. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  2000. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_EXTCONTRAS);
  2001. $inputs .= $this->renderWebSelector($this->allECProfiles, array(self::DBFLD_PROFILE_NAME,
  2002. self::DBFLD_PROFILE_CONTACT), self::CTRL_EXTCONTRAS_PROFILE_ID, __('Counterparty profile') . $this->supFrmFldMark, $contrasProfileID, false, false, true, '', '', '', true);
  2003. $inputs .= $this->renderWebSelector($this->allECContracts, array(self::DBFLD_CTRCT_CONTRACT,
  2004. self::DBFLD_CTRCT_SUBJECT,
  2005. self::DBFLD_CTRCT_FULLSUM), self::CTRL_EXTCONTRAS_CONTRACT_ID, __('Contract'), $contrasContractID, true, false, true, '', '', '', true);
  2006. $inputs .= $this->renderWebSelector($this->allECAddresses, array(self::DBFLD_ADDRESS_ADDR,
  2007. self::DBFLD_ADDRESS_SUM), self::CTRL_EXTCONTRAS_ADDRESS_ID, __('Address'), $contrasAddressID, true, false, true, '', '', '', true);
  2008. $inputs .= $this->renderWebSelector($this->allECPeriods, array(self::DBFLD_PERIOD_NAME), self::CTRL_EXTCONTRAS_PERIOD_ID, __('Period') . $this->supFrmFldMark, $contrasPeriodID, false, false, true, '', '', '', true);
  2009. $inputs .= wf_TextInput(self::CTRL_EXTCONTRAS_PAYDAY, __('Payday') . $this->supFrmFldMark, $contrasPayDay, false, '4', 'digits', $emptyCheckClass, '', '', true);
  2010. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', $this->submitBtnDisabled);
  2011. $inputs .= wf_HiddenInput(self::ROUTE_CONTRAS_ACTS, 'true');
  2012. if ($editAction) {
  2013. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  2014. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $extContrasID);
  2015. } else {
  2016. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  2017. }
  2018. if ($modal and ! empty($modalWinID)) {
  2019. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  2020. }
  2021. // for dynamic finops modal from websel filtering
  2022. if (!$modal) {
  2023. $tmpWebSelJS = wf_jsWebSelectorFilter();
  2024. $tmpWebSelJS .= '
  2025. $(function() {
  2026. onElementInserted("body", "#Modal' . $ecProfilesWebSelID . '", function(element) {
  2027. $("#Modal' . $ecProfilesWebSelID . '").on("click change", function(evt) {
  2028. filterWebDropdown($(this).val(), $(\'#Modal' . $contractsFilterDataID . '\').val(), \'Modal' . $ecContractsWebSelID . '\', true);
  2029. });
  2030. //console.log($("#Modal' . $ecProfilesWebSelID . '").val());
  2031. //console.log(empty($("#' . $editDBValProfileID . '").val()));
  2032. let tmpDBValue = (empty($("#' . $editDBValProfileID . '").val()) ? "0" : $("#' . $editDBValProfileID . '").val());
  2033. $("#Modal' . $ecProfilesWebSelID . '").val(tmpDBValue).change();
  2034. });
  2035. onElementInserted("body", "#Modal' . $ecContractsWebSelID . '", function(element) {
  2036. $("#Modal' . $ecContractsWebSelID . '").on("click change", function(evt) {
  2037. filterWebDropdown($(this).val(), $(\'#Modal' . $addressFilterDataID . '\').val(), \'Modal' . $ecAddressWebSelID . '\', true);
  2038. });
  2039. //console.log($("#Modal' . $ecContractsWebSelID . '").val());
  2040. let tmpDBValue = (empty($("#' . $editDBValContractID . '").val()) ? "0" : $("#' . $editDBValContractID . '").val());
  2041. $("#Modal' . $ecContractsWebSelID . '").val(tmpDBValue).change();
  2042. //console.log($("#Modal' . $ecAddressWebSelID . '").val());
  2043. tmpDBValue = (empty($("#' . $editDBValAddressID . '").val()) ? "0" : $("#' . $editDBValAddressID . '").val()) ;
  2044. $("#Modal' . $ecAddressWebSelID . '").val(tmpDBValue).change();
  2045. });
  2046. });
  2047. ';
  2048. $tmpWebSelJS = wf_EncloseWithJSTags($tmpWebSelJS);
  2049. } else {
  2050. $tmpWebSelJS = '';
  2051. }
  2052. $inputs .= $tmpWebSelJS;
  2053. $inputs = wf_Form(self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true', 'POST', $inputs, 'glamour form-grid-2cols form-grid-2cols-label-right ' . $formClass);
  2054. if ($modal and ! empty($modalWinID)) {
  2055. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  2056. }
  2057. return ($inputs);
  2058. }
  2059. /**
  2060. * Renders main top-level JQDT for external counterparty list
  2061. *
  2062. * @param string $customJSCode
  2063. * @param string $markRowForID
  2064. * @param string $detailsFilter
  2065. * @param bool $stdJSForCRUDs
  2066. *
  2067. * @return string
  2068. */
  2069. public function extcontrasRenderMainJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  2070. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_CONTRAS_JSON . '=true';
  2071. $ajaxURLDetails = '' . self::URL_ME . '&' . self::ROUTE_2LVL_CNTRCTS_DETAIL . '=true';
  2072. $columns[] = '';
  2073. $columns[] = __('ID');
  2074. $columns[] = __('EDRPO');
  2075. $columns[] = __('Counterparty');
  2076. $columns[] = __('Contact');
  2077. $columns[] = __('E-mail');
  2078. $columns[] = __('Rec fore color');
  2079. $columns[] = __('Rec back color');
  2080. $columns[] = __('Filter for details');
  2081. $this->getTableGridColorOpts();
  2082. $opts = '
  2083. "columnDefs": [
  2084. {"targets": [0], "className": "details-control"},
  2085. {"targets": [0], "orderable": false},
  2086. {"targets": [0], "data": null},
  2087. {"targets": [0], "defaultContent": ""},
  2088. {"targets": [6, 7, 8], "visible": false},
  2089. {"targets": ["_all"], "className": "dt-center dt-head-center"}
  2090. ],
  2091. "order": [[ 1, "desc" ]],
  2092. "rowCallback": function(row, data, index) {
  2093. if ( data[6] != "" ) {
  2094. $(\'td\', row).css(\'color\', data[6]);
  2095. }
  2096. if ( data[7] != "" ) {
  2097. $(\'td\', row).css(\'background-color\', data[7]);
  2098. }
  2099. }
  2100. ';
  2101. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL, false, '', $this->currencyStr, true, $ajaxURLDetails, 8);
  2102. return($result);
  2103. }
  2104. /**
  2105. * Renders JSON for external counterparty JQDT
  2106. *
  2107. * @param string $whereRaw
  2108. *
  2109. */
  2110. public function extcontrasRenderListJSON($whereRaw = '') {
  2111. $this->loadDataFromTableCached(self::TABLE_ECPROFILES, self::TABLE_ECPROFILES,
  2112. !empty($whereRaw), true,'', '', !empty($whereRaw));
  2113. $json = new wf_JqDtHelper();
  2114. if (!empty($this->allECProfiles)) {
  2115. //$this->dbExtContras->setDebug(true, true);
  2116. /* if (!empty($whereRaw)) {
  2117. $this->dbExtContras->whereRaw($whereRaw);
  2118. }*/
  2119. $data = array();
  2120. $tmpExtContrasRecs = $this->loadDataFromTableCached(self::TABLE_EXTCONTRAS, self::TABLE_EXTCONTRAS, !empty($whereRaw));
  2121. foreach ($this->allECProfiles as $eachRecID) {
  2122. $profileRecID = $eachRecID[self::DBFLD_COMMON_ID];
  2123. $recForeColor = '';
  2124. $recBackColor = '';
  2125. if (!empty($tmpExtContrasRecs)) {
  2126. foreach ($tmpExtContrasRecs as $eachID => $eachData) {
  2127. if ($eachData[self::DBFLD_EXTCONTRAS_PROFILE_ID] == $profileRecID) {
  2128. // $eachID === $eachData[self::DBFLD_COMMON_ID]
  2129. $hasPaymentsCurMonth = $this->checkCurMonthPaymExists($eachData[self::DBFLD_COMMON_ID]);
  2130. if (!empty($hasPaymentsCurMonth)) {
  2131. $recForeColor = $this->payedThisMonthFRGND;
  2132. $recBackColor = $this->payedThisMonthBKGND;
  2133. break;
  2134. }
  2135. if ($eachData[self::DBFLD_EXTCONTRAS_PAYDAY] - date('j') <= 5 and empty($hasPaymentsCurMonth)) {
  2136. $recForeColor = $this->fiveDaysTillPayFRGND;
  2137. $recBackColor = $this->fiveDaysTillPayBKGND;
  2138. break;
  2139. }
  2140. if (date('j') > $eachData[self::DBFLD_EXTCONTRAS_PAYDAY] and empty($hasPaymentsCurMonth)) {
  2141. $recForeColor = $this->paymentExpiredFRGND;
  2142. $recBackColor = $this->paymentExpiredBKGND;
  2143. break;
  2144. }
  2145. }
  2146. }
  2147. }
  2148. $data[] = '';
  2149. $data[] = $profileRecID;
  2150. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTPROFILES . '=true'
  2151. . '&' . self::MISC_MARKROW_URL . '=' . $profileRecID, $eachRecID[self::DBFLD_PROFILE_EDRPO]);
  2152. $data[] = $eachRecID[self::DBFLD_PROFILE_NAME];
  2153. $data[] = $eachRecID[self::DBFLD_PROFILE_CONTACT];
  2154. $data[] = $eachRecID[self::DBFLD_PROFILE_MAIL];
  2155. $data[] = $recForeColor;
  2156. $data[] = $recBackColor;
  2157. $data[] = '&' . self::DBFLD_EXTCONTRAS_PROFILE_ID . '=' . $profileRecID;
  2158. $json->addRow($data);
  2159. unset($data);
  2160. }
  2161. }
  2162. $json->getJson();
  2163. }
  2164. /**
  2165. * Renders second-level contract-address JQDT for external counterparty list
  2166. *
  2167. * @param string $customJSCode
  2168. * @param string $markRowForID
  2169. * @param string $detailsFilter
  2170. * @param bool $stdJSForCRUDs
  2171. *
  2172. * @return string
  2173. */
  2174. public function ecRender2ndLvlContractsJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  2175. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_2LVL_CNTRCTS_JSON . '=true' . $detailsFilter;
  2176. $ajaxURLDetails = '' . self::URL_ME . '&' . self::ROUTE_FINOPS_DETAILS_CNTRCTS . '=true';
  2177. $columns[] = '';
  2178. $columns[] = __('ID');
  2179. $columns[] = __('Contract');
  2180. $columns[] = __('Contract subject');
  2181. $columns[] = __('Contract date start');
  2182. $columns[] = __('Contract sum'); //5
  2183. $columns[] = __('Period');
  2184. $columns[] = __('Payday');
  2185. $columns[] = __('Actions'); //8
  2186. $columns[] = __('Add' . ' ' . self::MISC_FORMS_CAPTS_FINOPS_LIST);
  2187. $columns[] = __('Payed this month');
  2188. $columns[] = __('5 days till payday');
  2189. $columns[] = __('Payment expired');
  2190. $columns[] = __('Filter for details'); //13
  2191. $opts = '
  2192. "columnDefs": [
  2193. {"targets": [0], "className": "details-control"},
  2194. {"targets": [0], "orderable": false},
  2195. {"targets": [0], "data": null},
  2196. {"targets": [0], "defaultContent": ""},
  2197. {"targets": [10, 11, 12, 13], "visible": false},
  2198. {"targets": [3], "className": "dt-left dt-head-center"},
  2199. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  2200. {"targets": [8], "width": "85px"},
  2201. {"targets": [8, 9], "orderable": false}
  2202. ],
  2203. "order": [[ 1, "desc" ]],
  2204. "rowCallback": function(row, data, index) {
  2205. if ( data[10] == "1" ) {
  2206. $(\'td\', row).css(\'background-color\', \'' . $this->payedThisMonthBKGND . '\');
  2207. $(\'td\', row).css(\'color\', \'' . $this->payedThisMonthFRGND . '\');
  2208. }
  2209. if ( data[11] == "1" ) {
  2210. $(\'td\', row).css(\'background-color\', \'' . $this->fiveDaysTillPayBKGND . '\');
  2211. $(\'td\', row).css(\'color\', \'' . $this->fiveDaysTillPayFRGND . '\');
  2212. }
  2213. if ( data[12] == "1" ) {
  2214. $(\'td\', row).css(\'background-color\', \'' . $this->paymentExpiredBKGND . '\');
  2215. $(\'td\', row).css(\'color\', \'' . $this->paymentExpiredFRGND . '\');
  2216. }
  2217. }
  2218. ';
  2219. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL, true, array(5), $this->currencyStr, true, $ajaxURLDetails, 13, 'showDetailsData13');
  2220. return($result);
  2221. }
  2222. /**
  2223. * Renders JSON for external counterparty contract-address JQDT
  2224. *
  2225. * @param string $whereRaw
  2226. *
  2227. */
  2228. public function ecRender2ndLvlContractsListJSON($whereRaw = '') {
  2229. $this->loadExtContrasExtenData(true, $whereRaw);
  2230. $json = new wf_JqDtHelper();
  2231. $contractsIN = array();
  2232. if (!empty($this->allExtContrasExten)) {
  2233. $data = array();
  2234. foreach ($this->allExtContrasExten as $eachRecID) {
  2235. $curRecID = $eachRecID[self::TABLE_EXTCONTRAS . self::DBFLD_COMMON_ID];
  2236. $profileRecID = $eachRecID[self::TABLE_ECPROFILES . self::DBFLD_COMMON_ID];
  2237. $contractRecID = $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_COMMON_ID];
  2238. $periodRecID = $eachRecID[self::TABLE_ECPERIODS . self::DBFLD_COMMON_ID];
  2239. $addrRecID = $eachRecID[self::TABLE_ECADDRESS . self::DBFLD_COMMON_ID];
  2240. $contractSum = $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_FULLSUM];
  2241. $payDay = $eachRecID[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PAYDAY];
  2242. if (in_array($contractRecID, $contractsIN)) {
  2243. continue;
  2244. } else {
  2245. $contractsIN[] = $contractRecID;
  2246. }
  2247. $data[] = '';
  2248. $data[] = $contractRecID;
  2249. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true'
  2250. . '&' . self::MISC_MARKROW_URL . '=' . $contractRecID, $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_CONTRACT]);
  2251. $data[] = $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_SUBJECT];
  2252. $data[] = $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_DTSTART];
  2253. $data[] = $contractSum;
  2254. $data[] = $eachRecID[self::TABLE_ECPERIODS . self::DBFLD_PERIOD_NAME];
  2255. $data[] = $payDay;
  2256. $actions = $this->getStdJQDTActions($curRecID, self::ROUTE_CONTRAS_ACTS, true);
  2257. $data[] = $actions;
  2258. $hasPaymentsCurMonth = $this->checkCurMonthPaymExists($curRecID, true);
  2259. $hasAddressesAtached = ($this->ecFullCtrctOverdueNoAddrOnly) ? $this->checkContractHasAddresses($profileRecID, $contractRecID) : false;
  2260. if (empty($hasAddressesAtached) and date('j') > $payDay and empty($hasPaymentsCurMonth)) {
  2261. $payTimeExpired = 1;
  2262. $this->createMissedPayment($curRecID, $profileRecID, $contractRecID, $addrRecID, $periodRecID, $payDay, $contractSum);
  2263. } else {
  2264. $payTimeExpired = 0;
  2265. }
  2266. $data[] = wf_jsAjaxDynamicWindowButton(self::URL_ME, array(self::ROUTE_FINOPS_ACTS => 'true',
  2267. self::ROUTE_ACTION_PREFILL => 'true',
  2268. self::MISC_PREFILL_DATA => array(self::CTRL_MONEY_PROFILEID => $profileRecID,
  2269. self::CTRL_MONEY_CNTRCTID => $contractRecID,
  2270. self::CTRL_MONEY_SUMPAYMENT => $contractSum
  2271. )
  2272. ), '', web_add_icon(), '', 'POST', 'click', false, false, true, '$(this).closest("table").parent().children().find(\'[id ^= "jqdt_"][role = "grid"]\').last().attr("id")'
  2273. );
  2274. $data[] = (empty($hasPaymentsCurMonth) ? 0 : 1);
  2275. $data[] = ($payDay - date('j') <= 5 and empty($hasPaymentsCurMonth)) ? 1 : 0;
  2276. $data[] = $payTimeExpired;
  2277. $data[] = '&' . self::DBFLD_COMMON_ID . '=' . $profileRecID
  2278. . '&' . self::DBFLD_EXTCONTRAS_CONTRACT_ID . '=' . $contractRecID
  2279. . '&' . self::DBFLD_EXTCONTRAS_ADDRESS_ID . '=' . $addrRecID;
  2280. $json->addRow($data);
  2281. unset($data);
  2282. }
  2283. }
  2284. $json->getJson();
  2285. }
  2286. /**
  2287. * Renders third-level contract-address JQDT for external counterparty list
  2288. *
  2289. * @param string $customJSCode
  2290. * @param string $markRowForID
  2291. * @param string $detailsFilter
  2292. * @param bool $stdJSForCRUDs
  2293. *
  2294. * @return string
  2295. */
  2296. public function ecRender2ndLvlAddressJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  2297. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_3LVL_ADDR_JSON . '=true' . $detailsFilter;
  2298. $ajaxURLDetails = '' . self::URL_ME . '&' . self::ROUTE_FINOPS_DETAILS_ADDRESS . '=true';
  2299. $columns[] = '';
  2300. $columns[] = __('ID');
  2301. $columns[] = __('Address');
  2302. $columns[] = __('Address contract notes');
  2303. $columns[] = __('Address sum'); //4
  2304. $columns[] = __('Period');
  2305. $columns[] = __('Payday');
  2306. $columns[] = __('Actions'); // 7
  2307. $columns[] = __('Add' . ' ' . self::MISC_FORMS_CAPTS_FINOPS_LIST);
  2308. $columns[] = __('Payed this month');
  2309. $columns[] = __('5 days till payday');
  2310. $columns[] = __('Payment expired');
  2311. $columns[] = __('Filter for details'); //12
  2312. $opts = '
  2313. "columnDefs": [
  2314. {"targets": [0], "className": "details-control"},
  2315. {"targets": [0], "orderable": false},
  2316. {"targets": [0], "data": null},
  2317. {"targets": [0], "defaultContent": ""},
  2318. {"targets": [9, 10, 11, 12], "visible": false},
  2319. {"targets": [4, 5, 6], "className": "dt-left dt-head-center"},
  2320. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  2321. {"targets": [7], "width": "85px"},
  2322. {"targets": [7, 8], "orderable": false}
  2323. ],
  2324. "order": [[ 1, "desc" ]],
  2325. "rowCallback": function(row, data, index) {
  2326. if ( data[9] == "1" ) {
  2327. $(\'td\', row).css(\'background-color\', \'' . $this->payedThisMonthBKGND . '\');
  2328. $(\'td\', row).css(\'color\', \'' . $this->payedThisMonthFRGND . '\');
  2329. }
  2330. if ( data[10] == "1" ) {
  2331. $(\'td\', row).css(\'background-color\', \'' . $this->fiveDaysTillPayBKGND . '\');
  2332. $(\'td\', row).css(\'color\', \'' . $this->fiveDaysTillPayFRGND . '\');
  2333. }
  2334. if ( data[11] == "1" ) {
  2335. $(\'td\', row).css(\'background-color\', \'' . $this->paymentExpiredBKGND . '\');
  2336. $(\'td\', row).css(\'color\', \'' . $this->paymentExpiredFRGND . '\');
  2337. }
  2338. }
  2339. ';
  2340. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL, true, array(4), $this->currencyStr, true, $ajaxURLDetails, 12, 'showDetailsData12');
  2341. return($result);
  2342. }
  2343. /**
  2344. * Renders JSON for external counterparty contract-address JQDT
  2345. *
  2346. * @param string $whereRaw
  2347. *
  2348. */
  2349. public function ecRender2ndLvlAddressListJSON($whereRaw = '') {
  2350. $this->loadExtContrasExtenData(true, $whereRaw);
  2351. $json = new wf_JqDtHelper();
  2352. if (!empty($this->allExtContrasExten)) {
  2353. $data = array();
  2354. foreach ($this->allExtContrasExten as $eachRecID) {
  2355. $curRecID = $eachRecID[self::TABLE_EXTCONTRAS . self::DBFLD_COMMON_ID];
  2356. $profileRecID = $eachRecID[self::TABLE_ECPROFILES . self::DBFLD_COMMON_ID];
  2357. $contractRecID = $eachRecID[self::TABLE_ECCONTRACTS . self::DBFLD_COMMON_ID];
  2358. $periodRecID = $eachRecID[self::TABLE_ECPERIODS . self::DBFLD_COMMON_ID];
  2359. $addrRecID = $eachRecID[self::TABLE_ECADDRESS . self::DBFLD_COMMON_ID];
  2360. $addressSum = $eachRecID[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_SUM];
  2361. $payDay = $eachRecID[self::TABLE_EXTCONTRAS . self::DBFLD_EXTCONTRAS_PAYDAY];
  2362. $data[] = '';
  2363. $data[] = $addrRecID;
  2364. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTADDRESS . '=true'
  2365. . '&' . self::MISC_MARKROW_URL . '=' . $addrRecID, $eachRecID[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_ADDR]);
  2366. $data[] = $eachRecID[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_NOTES];
  2367. $data[] = $addressSum;
  2368. $data[] = $eachRecID[self::TABLE_ECPERIODS . self::DBFLD_PERIOD_NAME];
  2369. $data[] = $payDay;
  2370. $actions = $this->getStdJQDTActions($curRecID, self::ROUTE_CONTRAS_ACTS, true);
  2371. $data[] = $actions;
  2372. $hasPaymentsCurMonth = $this->checkCurMonthPaymExists($curRecID, true, true);
  2373. if (date('j') > $payDay and empty($hasPaymentsCurMonth)) {
  2374. $payTimeExpired = 1;
  2375. $this->createMissedPayment($curRecID, $profileRecID, $contractRecID, $addrRecID, $periodRecID, $payDay, $addressSum);
  2376. } else {
  2377. $payTimeExpired = 0;
  2378. }
  2379. $data[] = wf_jsAjaxDynamicWindowButton(self::URL_ME, array(self::ROUTE_FINOPS_ACTS => 'true',
  2380. self::ROUTE_ACTION_PREFILL => 'true',
  2381. self::MISC_PREFILL_DATA => array(self::CTRL_MONEY_PROFILEID => $profileRecID,
  2382. self::CTRL_MONEY_CNTRCTID => $contractRecID,
  2383. self::CTRL_MONEY_ADDRESSID => $addrRecID,
  2384. self::CTRL_MONEY_SUMPAYMENT => $addressSum
  2385. )
  2386. ), '', web_add_icon(), '', 'POST', 'click', false, false, true, '$(this).closest("table").parent().children().find(\'[id ^= "jqdt_"][role = "grid"]\').last().attr("id")'
  2387. );
  2388. $data[] = (empty($hasPaymentsCurMonth) ? 0 : 1);
  2389. $data[] = ($payDay - date('j') <= 5 and empty($hasPaymentsCurMonth)) ? 1 : 0;
  2390. $data[] = $payTimeExpired;
  2391. $data[] = '&' . self::DBFLD_COMMON_ID . '=' . $profileRecID
  2392. . '&' . self::DBFLD_EXTCONTRAS_CONTRACT_ID . '=' . $contractRecID
  2393. . '&' . self::DBFLD_EXTCONTRAS_ADDRESS_ID . '=' . $addrRecID;
  2394. $json->addRow($data);
  2395. unset($data);
  2396. }
  2397. }
  2398. $json->getJson();
  2399. }
  2400. /**
  2401. * Creates a missed payment record from params
  2402. *
  2403. * @param $contrasID
  2404. * @param $profileID
  2405. * @param $contractID
  2406. * @param $addrID
  2407. * @param $periodID
  2408. * @param $payDay
  2409. * @param $paySum
  2410. */
  2411. protected function createMissedPayment($contrasID, $profileID, $contractID, $addrID, $periodID, $payDay, $paySum) {
  2412. $chkUniqArray = array();
  2413. $recordExists = true;
  2414. $paymentDate = date('Y-m-') . $payDay;
  2415. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_CONTRASID, '=', $contrasID);
  2416. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_PROFILEID, '=', $profileID);
  2417. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_CONTRACTID, '=', $contractID);
  2418. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_ADDRESSID, '=', $addrID);
  2419. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_PERIOD_ID, '=', $periodID);
  2420. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_PAYDAY, '=', $payDay);
  2421. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_DATE_PAYMENT, '=', $paymentDate);
  2422. $chkUniqArray += $this->createCheckUniquenessArray(self::DBFLD_MISSPAYMS_SUMPAYMENT, '=', $paySum);
  2423. //$this->dbECMissedPayms->setDebug(true, true);
  2424. $recordExists = $this->dbECMissedPayms->checkRecExists($chkUniqArray);
  2425. if (!$recordExists) {
  2426. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_CONTRASID, $contrasID);
  2427. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_PROFILEID, $profileID);
  2428. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_CONTRACTID, $contractID);
  2429. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_ADDRESSID, $addrID);
  2430. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_PERIOD_ID, $periodID);
  2431. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_PAYDAY, $payDay);
  2432. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_DATE_PAYMENT, $paymentDate);
  2433. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_DATE_EXPIRED, curdatetime());
  2434. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_SUMPAYMENT, $paySum);
  2435. $this->dbECMissedPayms->create();
  2436. }
  2437. }
  2438. /**
  2439. * Updates a missed payment record paid date field
  2440. *
  2441. * @param $missPaymID
  2442. * @param string $datePayed
  2443. */
  2444. public function updateMissedPaymentPayedDate($missPaymID, $datePayed = '') {
  2445. if (!empty($missPaymID)) {
  2446. $datePayed = (empty($datePayed) ? curdatetime() : $datePayed);
  2447. $this->dbECMissedPayms->data(self::DBFLD_MISSPAYMS_DATE_PAYED, $datePayed);
  2448. $this->dbECMissedPayms->where('id', '=', $missPaymID);
  2449. $this->dbECMissedPayms->save();
  2450. }
  2451. }
  2452. /**
  2453. * Returns payday of the contragent by profile ID + contract ID [+ address ID]
  2454. *
  2455. * @param $profileID
  2456. * @param $contractID
  2457. * @param $addressID
  2458. *
  2459. * @return int|string
  2460. */
  2461. public function getContraPayday($profileID, $contractID, $addressID = 0) {
  2462. $this->dbExtContras->where();
  2463. $this->dbExtContras->whereRaw();
  2464. $this->dbExtContras->selectable('payday');
  2465. $this->dbExtContras->where(self::DBFLD_EXTCONTRAS_PROFILE_ID, '=', $profileID);
  2466. $this->dbExtContras->where(self::DBFLD_EXTCONTRAS_CONTRACT_ID, '=', $contractID);
  2467. if (!empty($addressID)) {
  2468. $this->dbExtContras->where(self::DBFLD_EXTCONTRAS_ADDRESS_ID, '=', $addressID);
  2469. }
  2470. $result = $this->dbExtContras->getAll();
  2471. $result = empty($result[0][self::DBFLD_EXTCONTRAS_PAYDAY]) ? '' : $result[0][self::DBFLD_EXTCONTRAS_PAYDAY];
  2472. return ($result);
  2473. }
  2474. /**
  2475. * Returns payday of the missed payment by its ID
  2476. *
  2477. * @param $missPaymID
  2478. *
  2479. * @return mixed|string
  2480. */
  2481. public function getMissedPaymentPayDay($missPaymID) {
  2482. $datePayDue = empty($this->allECMissedPayms[$missPaymID]) ? '' : $this->allECMissedPayms[$missPaymID][self::DBFLD_MISSPAYMS_DATE_PAYMENT];
  2483. return ($datePayDue);
  2484. }
  2485. /**
  2486. * Renders counterparties table coloring settings form
  2487. *
  2488. * @return string
  2489. */
  2490. public function extcontrasColorSettings() {
  2491. $this->getTableGridColorOpts();
  2492. $inputs = '';
  2493. $tmpStyle = 'style="float: right; width: 80px; height: 20px; border: 2px solid rgba(100, 100, 100, .8); border-radius: 4px; ';
  2494. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND, __('Already payed this month background'), $this->payedThisMonthBKGND, false, '7', self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND, 'background-color');
  2495. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_PAYEDTHISMONTH_BKGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2496. . wf_tag('span', true) . wf_delimiter(1);
  2497. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND, __('Already payed this month foreground'), $this->payedThisMonthFRGND, false, '7', self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND, 'background-color');
  2498. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_PAYEDTHISMONTH_FRGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2499. . wf_tag('span', true) . wf_delimiter(1);
  2500. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND, __('5 days left till payday background'), $this->fiveDaysTillPayBKGND, false, '7', self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND, 'background-color');
  2501. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_BKGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2502. . wf_tag('span', true) . wf_delimiter(1);
  2503. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND, __('5 days left till payday background'), $this->fiveDaysTillPayFRGND, false, '7', self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND, 'background-color');
  2504. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_FIVEDAYSTILLPAY_FRGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2505. . wf_tag('span', true) . wf_delimiter(1);
  2506. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND, __('Payment expired background'), $this->paymentExpiredBKGND, false, '7', self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND, 'background-color');
  2507. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_PAYMENTEXPIRED_BKGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2508. . wf_tag('span', true) . wf_delimiter(1);
  2509. $inputs .= wf_ColPicker(self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND, __('Payment expired foreground'), $this->paymentExpiredFRGND, false, '7', self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND, 'background-color');
  2510. $inputs .= wf_nbsp(4) . wf_tag('span', false, '', 'id="' . self::CTRL_ECCOLOR_PAYMENTEXPIRED_FRGND . '" ' . $tmpStyle . $this->payedThisMonthBKGND . ';"')
  2511. . wf_tag('span', true) . wf_delimiter(1);
  2512. $inputs .= wf_delimiter(0);
  2513. $inputs .= wf_HiddenInput(self::URL_EXTCONTRAS_COLORS, 'true');
  2514. $inputs .= wf_SubmitClassed(true, 'ubButton', '', __('Save'), '', 'style="width: 100%"; ' . $this->submitBtnDisabled);
  2515. $inputs = wf_Form(self::URL_ME . '&' . self::URL_EXTCONTRAS_COLORS . '=true', 'POST', $inputs, 'glamour');
  2516. return ($inputs);
  2517. }
  2518. /**
  2519. * Returns a filter web form for invoices main form
  2520. *
  2521. * @return string
  2522. */
  2523. public function finopsFilterWebForm() {
  2524. $ajaxURLStr = self::URL_ME . '&' . self::ROUTE_FINOPS_JSON . '=true';
  2525. $formID = 'Form_' . wf_InputId();
  2526. $jqdtID = 'jqdt_' . md5($ajaxURLStr);
  2527. $inputs = wf_tag('h3', false);
  2528. $inputs .= __('Filter by') . ':';
  2529. $inputs .= wf_tag('h3', true);
  2530. $rows = wf_DatesTimesRangeFilter(true, true, false, false, true, false, ubRouting::post(self::MISC_WEBFILTER_DATE_START), ubRouting::post(self::MISC_WEBFILTER_DATE_END), self::MISC_WEBFILTER_DATE_START, self::MISC_WEBFILTER_DATE_END
  2531. );
  2532. $inputs .= wf_TableBody($rows, 'auto');
  2533. $inputs .= wf_SubmitClassed(true, 'ubButton', '', __('Show'), '', 'style="width: 100%"');
  2534. $inputs = wf_Form($ajaxURLStr, 'POST', $inputs, 'glamour form-grid-3r-1c', '', $formID, '', 'style="margin-top: 10px;"');
  2535. $inputs .= wf_EncloseWithJSTags(wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID));
  2536. return ($inputs);
  2537. }
  2538. /**
  2539. * Returns a financial operations editor web form
  2540. *
  2541. * @param bool $modal
  2542. * @param int $finopID
  2543. * @param bool $editAction
  2544. * @param bool $cloneAction
  2545. * @param array $prefillFieldsData
  2546. *
  2547. * @return string
  2548. */
  2549. public function finopsWebForm($modal = true, $finopID = 0, $editAction = false, $cloneAction = false, $prefillFieldsData = array()) {
  2550. $this->loadWebSelFilterData();
  2551. $inputs = '';
  2552. $finopProfileID = 0;
  2553. $finopContractID = 0;
  2554. $finopAddressID = 0;
  2555. $finopAccrualID = 0;
  2556. $finopInvoiceID = 0;
  2557. $finopPurpose = '';
  2558. $finopSumAccrual = '';
  2559. $finopSumPayment = '';
  2560. $finopNotes = '';
  2561. $finopIncoming = '';
  2562. $finopOutgoing = '';
  2563. $finopAccruals = array();
  2564. $modalWinID = ubRouting::post('modalWindowId');
  2565. $modalWinBodyID = ubRouting::post('modalWindowBodyId');
  2566. if ($modal) {
  2567. $formClass = self::MISC_CLASS_SUBMITFORM_MODAL;
  2568. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK_MODAL;
  2569. } else {
  2570. $formClass = self::MISC_CLASS_SUBMITFORM;
  2571. $emptyCheckClass = self::MISC_CLASS_EMPTYVALCHECK;
  2572. }
  2573. if (($editAction or $cloneAction) and ! empty($this->allECMoney[$finopID])) {
  2574. $finoperation = $this->allECMoney[$finopID];
  2575. $finopProfileID = $finoperation[self::DBFLD_MONEY_PROFILEID];
  2576. $finopContractID = $finoperation[self::DBFLD_MONEY_CNTRCTID];
  2577. $finopAddressID = $finoperation[self::DBFLD_MONEY_ADDRESSID];
  2578. $finopAccrualID = $finoperation[self::DBFLD_MONEY_ACCRUALID];
  2579. $finopInvoiceID = $finoperation[self::DBFLD_MONEY_INVOICEID];
  2580. $finopPurpose = $finoperation[self::DBFLD_MONEY_PURPOSE];
  2581. $finopSumAccrual = $finoperation[self::DBFLD_MONEY_SMACCRUAL];
  2582. $finopSumPayment = $finoperation[self::DBFLD_MONEY_SMPAYMENT];
  2583. $finopNotes = $finoperation[self::DBFLD_MONEY_PAYNOTES];
  2584. $finopIncoming = ubRouting::filters($finoperation[self::DBFLD_MONEY_INCOMING], 'fi', FILTER_VALIDATE_BOOLEAN);
  2585. $finopOutgoing = ubRouting::filters($finoperation[self::DBFLD_MONEY_OUTGOING], 'fi', FILTER_VALIDATE_BOOLEAN);
  2586. } elseif (!empty($prefillFieldsData)) {
  2587. $finopProfileID = (empty($prefillFieldsData[self::CTRL_MONEY_PROFILEID]) ? 0 : $prefillFieldsData[self::CTRL_MONEY_PROFILEID]);
  2588. $finopContractID = (empty($prefillFieldsData[self::CTRL_MONEY_CNTRCTID]) ? 0 : $prefillFieldsData[self::CTRL_MONEY_CNTRCTID]);
  2589. $finopAddressID = (empty($prefillFieldsData[self::CTRL_MONEY_ADDRESSID]) ? 0 : $prefillFieldsData[self::CTRL_MONEY_ADDRESSID]);
  2590. $finopSumPayment = (empty($prefillFieldsData[self::CTRL_MONEY_SUMPAYMENT]) ? 0 : $prefillFieldsData[self::CTRL_MONEY_SUMPAYMENT]);
  2591. if (!$editAction and ! $cloneAction) {
  2592. $misspaymProcess = (empty($prefillFieldsData[self::MISC_MISSED_PAYMENT_PROCESSING]) ? 0 : $prefillFieldsData[self::MISC_MISSED_PAYMENT_PROCESSING]);
  2593. $misspaymID = (empty($prefillFieldsData[self::MISC_MISSED_PAYMENT_ID]) ? 0 : $prefillFieldsData[self::MISC_MISSED_PAYMENT_ID]);
  2594. $inputs .= wf_HiddenInput(self::MISC_MISSED_PAYMENT_PROCESSING, $misspaymProcess);
  2595. $inputs .= wf_HiddenInput(self::MISC_MISSED_PAYMENT_ID, $misspaymID);
  2596. }
  2597. }
  2598. $this->dbECMoney->whereRaw(" " . self::DBFLD_MONEY_SMACCRUAL . " != 0");
  2599. $finopAccruals = $this->loadDataFromTableCached(self::TABLE_ECMONEY, self::TABLE_ECMONEY, true);
  2600. $this->loadDataFromTableCached(self::TABLE_ECMONEY, self::TABLE_ECMONEY, true);
  2601. $ecProfilesWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_PROFILES;
  2602. $ecContractsWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_CONTRACTS;
  2603. $ecAddressWebSelID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_ADDRESS;
  2604. $contractsFilterDataID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_FILTDATA_CONTRACTS;
  2605. $addressFilterDataID = ($modal ? 'Modal' : '') . self::MISC_WEBSEL_FILTDATA_ADDRESS;
  2606. $editDBValProfileID = self::MISC_WEBSEL_DBVAL_PROFILE_ID;
  2607. $editDBValContractID = self::MISC_WEBSEL_DBVAL_CONTRACTS_ID;
  2608. $editDBValAddressID = self::MISC_WEBSEL_DBVAL_ADDRESS_ID;
  2609. $submitCapt = ($editAction) ? __('Edit') : (($cloneAction) ? __('Clone') : __('Create'));
  2610. $formCapt = $submitCapt . ' ' . __(self::MISC_FORMS_CAPTS_FINOPS_LIST);
  2611. $ctrlsLblStyle = 'style="line-height: 2.2em"';
  2612. if ($editAction or $cloneAction or ! empty($prefillFieldsData)) {
  2613. $inputs .= wf_HiddenInput($editDBValProfileID . 'nm', $finopProfileID, $editDBValProfileID);
  2614. $inputs .= wf_HiddenInput($editDBValContractID . 'nm', $finopContractID, $editDBValContractID);
  2615. $inputs .= wf_HiddenInput($editDBValAddressID . 'nm', $finopAddressID, $editDBValAddressID);
  2616. }
  2617. $inputs .= wf_TextInput(self::CTRL_MONEY_PURPOSE, __('Operation purpose') . $this->supFrmFldMark, $finopPurpose, false, '', '', $emptyCheckClass . ' right-two-thirds-occupy', '', '', true);
  2618. //$inputs.= wf_tag('span', false);
  2619. $inputs .= wf_TextInput(self::CTRL_MONEY_SUMACCRUAL, __('Accrual sum'), $finopSumAccrual, false, '', 'finance', 'col-2-3-occupy', '', '', true);
  2620. //$inputs.= wf_tag('span', true);
  2621. $inputs .= wf_TextInput(self::CTRL_MONEY_SUMPAYMENT, __('Payment sum'), $finopSumPayment, false, '', 'finance', 'col-5-6-occupy', '', '', true);
  2622. $inputs .= $this->renderWebSelector($this->allECProfiles, array(self::DBFLD_PROFILE_EDRPO,
  2623. self::DBFLD_PROFILE_NAME,
  2624. self::DBFLD_PROFILE_CONTACT
  2625. ), self::CTRL_MONEY_PROFILEID, __('Counterparty'), $finopProfileID, true, false, true, $ecProfilesWebSelID, '', '', true, '', $this->selectfiltECContractsAll, $contractsFilterDataID);
  2626. $inputs .= $this->renderWebSelector($this->allECContracts, array(self::DBFLD_CTRCT_CONTRACT,
  2627. self::DBFLD_CTRCT_SUBJECT,
  2628. self::DBFLD_CTRCT_FULLSUM
  2629. ), self::CTRL_MONEY_CNTRCTID, __('Contract'), $finopContractID, true, false, true, $ecContractsWebSelID, '', '', true, '', $this->selectfiltECAddressAll, $addressFilterDataID);
  2630. $inputs .= $this->renderWebSelector($this->allECAddresses, array(self::DBFLD_ADDRESS_ADDR,
  2631. self::DBFLD_ADDRESS_SUM
  2632. ), self::CTRL_MONEY_ADDRESSID, __('Address'), $finopAddressID, true, false, true, $ecAddressWebSelID, '', '', true);
  2633. if (!$modal) {
  2634. $tmpWebSelJS = wf_jsWebSelectorFilter();
  2635. $tmpWebSelJS .= '
  2636. $(function() {
  2637. onElementInserted("body", "#Modal' . $ecProfilesWebSelID . '", function(element) {
  2638. $("#Modal' . $ecProfilesWebSelID . '").on("click change", function(evt) {
  2639. filterWebDropdown($(this).val(), $(\'#Modal' . $contractsFilterDataID . '\').val(), \'Modal' . $ecContractsWebSelID . '\', true);
  2640. });
  2641. $("#Modal' . $ecProfilesWebSelID . '").val($("#' . $editDBValProfileID . '").val()).change();
  2642. });
  2643. onElementInserted("body", "#Modal' . $ecContractsWebSelID . '", function(element) {
  2644. $("#Modal' . $ecContractsWebSelID . '").on("click change", function(evt) {
  2645. filterWebDropdown($(this).val(), $(\'#Modal' . $addressFilterDataID . '\').val(), \'Modal' . $ecAddressWebSelID . '\', true);
  2646. });
  2647. $("#Modal' . $ecContractsWebSelID . '").val($("#' . $editDBValContractID . '").val()).change();
  2648. $("#Modal' . $ecAddressWebSelID . '").val($("#' . $editDBValAddressID . '").val()).change();
  2649. });
  2650. $(\'#' . $ecProfilesWebSelID . '\').on("change", function(evt) {
  2651. filterWebDropdown($(this).val(), $(\'#' . $contractsFilterDataID . '\').val(), \'' . $ecContractsWebSelID . '\', true);
  2652. });
  2653. $(\'#' . $ecContractsWebSelID . '\').on("change", function(evt) {
  2654. filterWebDropdown($(this).val(), $(\'#' . $addressFilterDataID . '\').val(), \'' . $ecAddressWebSelID . '\', true);
  2655. });
  2656. $(\'#' . $ecProfilesWebSelID . '\').change();
  2657. $(\'#' . $ecContractsWebSelID . '\').change();
  2658. });
  2659. ';
  2660. $tmpWebSelJS = wf_EncloseWithJSTags($tmpWebSelJS . "\n");
  2661. } else {
  2662. $tmpWebSelJS = '';
  2663. }
  2664. $inputs .= $tmpWebSelJS;
  2665. if ($this->ecInvoicesON) {
  2666. $inputs .= $this->renderWebSelector($this->allECInvoices, array(self::DBFLD_INVOICES_INVOICE_NUM,
  2667. self::DBFLD_INVOICES_DATE,
  2668. self::DBFLD_INVOICES_SUM
  2669. ), self::CTRL_MONEY_INVOICEID, __('Invoice'), $finopInvoiceID, true, false, true, '', 'col-2-3-occupy', '', true);
  2670. }
  2671. $inputs .= $this->renderWebSelector($finopAccruals, array(self::DBFLD_MONEY_PURPOSE,
  2672. self::DBFLD_MONEY_SMACCRUAL,
  2673. self::DBFLD_MONEY_DATE
  2674. ), self::CTRL_MONEY_ACCRUALID, __('Accrual'), $finopAccrualID, true, false, true, '', ($this->ecInvoicesON ? 'col-5-6-occupy' : 'col-2-3-occupy'), '', true);
  2675. $inputs .= wf_TextInput(self::CTRL_MONEY_PAYNOTES, __('Payment notes'), $finopNotes, false, '70', '', ($this->ecInvoicesON ? 'right-two-thirds-occupy' : 'col-5-6-occupy'), '', '', true);
  2676. $inputs .= wf_tag('span', false, 'glamour full-width-occupy', 'style="text-align: center; width: 98%;"');
  2677. $inputs .= wf_RadioInput(self::CTRL_MONEY_INOUT, __('Incoming payment'), 'incoming', false, $finopIncoming);
  2678. $inputs .= wf_nbsp(8);
  2679. $inputs .= wf_RadioInput(self::CTRL_MONEY_INOUT, __('Outgoing payment'), 'outgoing', false, $finopOutgoing);
  2680. $inputs .= wf_tag('span', true);
  2681. $inputs .= wf_SubmitClassed(true, 'ubButton', '', $submitCapt, '', 'style="width: 100%"; ' . $this->submitBtnDisabled);
  2682. $inputs .= wf_HiddenInput(self::ROUTE_FINOPS_ACTS, 'true');
  2683. if ($editAction) {
  2684. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_EDIT, 'true');
  2685. $inputs .= wf_HiddenInput(self::ROUTE_EDIT_REC_ID, $finopID);
  2686. } else {
  2687. $inputs .= wf_HiddenInput(self::ROUTE_ACTION_CREATE, 'true');
  2688. }
  2689. if ($modal and ! empty($modalWinID)) {
  2690. $inputs .= wf_HiddenInput('', $modalWinID, '', self::MISC_CLASS_MWID_CTRL);
  2691. }
  2692. $inputs = wf_Form(self::URL_ME . '&' . self::URL_FINOPERATIONS . '=true', 'POST', $inputs, 'glamour form-grid-6cols form-grid-6cols-label-right ' . $formClass);
  2693. if ($editAction and $this->fileStorageEnabled) {
  2694. $this->fileStorage->setItemid(self::URL_FINOPERATIONS . $finopID);
  2695. $inputs .= wf_tag('span', false, '', $ctrlsLblStyle);
  2696. $inputs .= wf_tag('h3');
  2697. $inputs .= __('Uploaded files');
  2698. $inputs .= wf_tag('h3', true);
  2699. $inputs .= $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_FINOPERATIONS . '=true'), true);
  2700. $inputs .= wf_tag('span', true);
  2701. }
  2702. if ($modal and ! empty($modalWinID)) {
  2703. $inputs = wf_modalAutoForm($formCapt, $inputs, $modalWinID, $modalWinBodyID, true);
  2704. }
  2705. return ($inputs);
  2706. }
  2707. /**
  2708. * Renders JQDT for external counterparty finance operations list
  2709. *
  2710. * @param string $customJSCode
  2711. * @param string $markRowForID
  2712. * @param string $detailsFilter
  2713. * @param bool $stdJSForCRUDs
  2714. *
  2715. * @return string
  2716. */
  2717. public function finopsRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  2718. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_FINOPS_JSON . '=true' . $detailsFilter;
  2719. $colTargets1 = '[1, 2]';
  2720. $colTargets2 = '[14, 15]';
  2721. $totalsCols = ($this->ecInvoicesON ? array(9, 10) : array(8, 9));
  2722. $columns[] = __('ID');
  2723. $columns[] = __('Counterparty');
  2724. $columns[] = __('Contract');
  2725. $columns[] = __('Address');
  2726. if ($this->ecInvoicesON) {
  2727. $columns[] = __('Invoice');
  2728. $colTargets1 = '[1, 2, 3]';
  2729. $colTargets2 = '[15, 16]';
  2730. }
  2731. $columns[] = __('Leading financial operation');
  2732. $columns[] = __('Operation purpose');
  2733. $columns[] = __('Operation date');
  2734. $columns[] = __('Edit date');
  2735. $columns[] = __('Accrual sum');
  2736. $columns[] = __('Payment sum'); //9
  2737. $columns[] = __('Needed to pay on date');
  2738. $columns[] = __('Ingoing');
  2739. $columns[] = __('Outgoing');
  2740. $columns[] = __('Payment notes');
  2741. $columns[] = __('Uploaded files');
  2742. $columns[] = __('Actions');
  2743. $opts = '
  2744. "order": [[ 0, "desc" ]],
  2745. "columnDefs": [ {"targets": ' . $colTargets1 . ', "className": "dt-left dt-head-center"},
  2746. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  2747. {"targets": ' . $colTargets2 . ', "orderable": false},
  2748. {"targets": ' . $colTargets2 . ', "width": "85px"}
  2749. ]
  2750. ';
  2751. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID,
  2752. self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID,
  2753. self::MISC_MARKROW_URL, true, $totalsCols, $this->currencyStr);
  2754. return($result);
  2755. }
  2756. /**
  2757. * Renders JSON for finance operations JQDT
  2758. *
  2759. * @param string $whereRaw
  2760. */
  2761. public function finopsRenderListJSON($whereRaw = '') {
  2762. if (!empty($whereRaw)) {
  2763. $this->dbECMoney->whereRaw($whereRaw);
  2764. }
  2765. //$this->dbECMoney->setDebug(true, true);
  2766. $this->loadDataFromTableCached(self::TABLE_ECMONEY, self::TABLE_ECMONEY, !empty($whereRaw), true, '', '', !empty($whereRaw));
  2767. $json = new wf_JqDtHelper();
  2768. if (!empty($this->allECMoney)) {
  2769. $data = array();
  2770. foreach ($this->allECMoney as $eachRecID) {
  2771. foreach ($eachRecID as $fieldName => $fieldVal) {
  2772. if ($fieldName == self::DBFLD_MONEY_PROFILEID) {
  2773. $data[] = (empty($this->allECProfiles[$fieldVal]) ? '' : $this->allECProfiles[$fieldVal][self::DBFLD_PROFILE_EDRPO] . ' '
  2774. . $this->allECProfiles[$fieldVal][self::DBFLD_PROFILE_NAME]
  2775. );
  2776. } elseif ($fieldName == self::DBFLD_MONEY_CNTRCTID) {
  2777. $data[] = (empty($this->allECContracts[$fieldVal]) ? '' : $this->allECContracts[$fieldVal][self::DBFLD_CTRCT_CONTRACT] . ' '
  2778. . $this->allECContracts[$fieldVal][self::DBFLD_CTRCT_FULLSUM]
  2779. );
  2780. } elseif ($fieldName == self::DBFLD_MONEY_ADDRESSID) {
  2781. $data[] = (empty($this->allECAddresses[$fieldVal]) ? '' : $this->allECAddresses[$fieldVal][self::DBFLD_ADDRESS_ADDR] . ' '
  2782. . $this->allECAddresses[$fieldVal][self::DBFLD_ADDRESS_SUM]
  2783. );
  2784. } elseif ($fieldName == self::DBFLD_MONEY_INVOICEID) {
  2785. if ($this->ecInvoicesON) {
  2786. $data[] = (empty($this->allECInvoices[$fieldVal]) ? '' : $this->allECInvoices[$fieldVal][self::DBFLD_INVOICES_INVOICE_NUM]
  2787. . $this->allECInvoices[$fieldVal][self::DBFLD_INVOICES_DATE]
  2788. . $this->allECInvoices[$fieldVal][self::DBFLD_INVOICES_SUM]);
  2789. }
  2790. } elseif ($fieldName == self::DBFLD_MONEY_ACCRUALID) {
  2791. $data[] = (empty($this->allECMoney[$fieldVal]) ? '' : $this->allECMoney[$fieldVal][self::DBFLD_MONEY_PURPOSE]
  2792. . $this->allECMoney[$fieldVal][self::DBFLD_MONEY_SMACCRUAL]
  2793. . $this->allECMoney[$fieldVal][self::DBFLD_MONEY_DATE]);
  2794. } elseif ($fieldName == self::DBFLD_MONEY_INCOMING or $fieldName == self::DBFLD_MONEY_OUTGOING) {
  2795. $data[] = (empty($fieldVal) ? web_red_led() : web_green_led());
  2796. } else {
  2797. $data[] = $fieldVal;
  2798. }
  2799. }
  2800. if ($this->fileStorage) {
  2801. $this->fileStorage->setItemid(self::URL_FINOPERATIONS . $eachRecID[self::DBFLD_COMMON_ID]);
  2802. $data[] = $this->fileStorage->renderFilesPreview(true, '', 'ubButton', '32', '&callback=' . base64_encode(self::URL_ME . '&' . self::URL_FINOPERATIONS . '=true'), true);
  2803. } else {
  2804. $data[] = __('Filestorage') . ' ' . __('Disabled');
  2805. }
  2806. $actions = $this->getStdJQDTActions($eachRecID[self::DBFLD_COMMON_ID], self::ROUTE_FINOPS_ACTS, true);
  2807. $data[] = $actions;
  2808. $json->addRow($data);
  2809. unset($data);
  2810. }
  2811. }
  2812. $json->getJson();
  2813. }
  2814. /**
  2815. * Returns expired payments filter webform
  2816. *
  2817. * @return string
  2818. */
  2819. public function missedPaymsFilterWebForm() {
  2820. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_MISSPAYMS_JSON . '=true';
  2821. $result = '';
  2822. $result .= wf_Link('#', __('Unpaid'), false, 'ubButton', 'id="MissPaymsUnpayedFilter"') . wf_nbsp(4);
  2823. $result .= wf_Link('#', __('Paid'), false, 'ubButton', 'id="MissPaymsPayedFilter"') . wf_nbsp(4);
  2824. $result .= wf_Link('#', __('All'), false, 'ubButton', 'id="MissPaymsFilterAll"');
  2825. $result = wf_Plate($result, '', '', 'glamour') . wf_CleanDiv();
  2826. $tmpJS = wf_jsAjaxCustomFunc('doMisspaymsFilter', '', '$(\'body\').find(\'[id ^= "jqdt_"][role = "grid"]\').attr("id")', '', 'POST', true);
  2827. $tmpJS .= '
  2828. $(\'#MissPaymsUnpayedFilter\').click(function(evt) {
  2829. doMisspaymsFilter(\'' . $ajaxURL . '\', \'&' . self::MISC_WEBFILTER_MISSPAYMS . '=ISNULL(`' . self::DBFLD_MISSPAYMS_DATE_PAYED . '`)\');
  2830. evt.preventDefault();
  2831. return false;
  2832. });
  2833. $(\'#MissPaymsPayedFilter\').click(function(evt) {
  2834. doMisspaymsFilter(\'' . $ajaxURL . '\', \'&' . self::MISC_WEBFILTER_MISSPAYMS . '=NOT ISNULL(`' . self::DBFLD_MISSPAYMS_DATE_PAYED . '`)\');
  2835. evt.preventDefault();
  2836. return false;
  2837. });
  2838. $(\'#MissPaymsFilterAll\').click(function(evt) {
  2839. doMisspaymsFilter(\'' . $ajaxURL . '\', \'&' . self::MISC_WEBFILTER_MISSPAYMS . '=NOT ISNULL(`' . self::DBFLD_MISSPAYMS_CONTRASID . '`)\');
  2840. evt.preventDefault();
  2841. return false;
  2842. });
  2843. ';
  2844. $result .= wf_EncloseWithJSTags($tmpJS);
  2845. return ($result);
  2846. }
  2847. /**
  2848. * Renders JQDT for overdue payments list
  2849. *
  2850. * @param string $customJSCode
  2851. * @param string $markRowForID
  2852. * @param string $detailsFilter
  2853. * @param bool $stdJSForCRUDs
  2854. *
  2855. * @return string
  2856. */
  2857. public function missedPaymsRenderJQDT($customJSCode = '', $markRowForID = '', $detailsFilter = '', $stdJSForCRUDs = true) {
  2858. $ajaxURL = '' . self::URL_ME . '&' . self::ROUTE_MISSPAYMS_JSON . '=true';
  2859. $columns[] = __('ID');
  2860. $columns[] = __('Counterparty');
  2861. $columns[] = __('Contract');
  2862. $columns[] = __('Contract subject');
  2863. $columns[] = __('Address'); //4
  2864. $columns[] = __('Period'); //5
  2865. $columns[] = __('Payday');
  2866. $columns[] = __('Payment sum'); //7
  2867. $columns[] = __('Needed to pay on date');
  2868. $columns[] = __('Expired date'); //9
  2869. $columns[] = __('Payed date');
  2870. $columns[] = __('Actions');
  2871. $columns[] = __('Add' . ' ' . self::MISC_FORMS_CAPTS_FINOPS_LIST); //12
  2872. $columns[] = __('Already payed');
  2873. $opts = '
  2874. "columnDefs": [
  2875. {"targets": [13], "visible": false},
  2876. {"targets": [1, 3, 4], "className": "dt-left dt-head-center"},
  2877. {"targets": ["_all"], "className": "dt-center dt-head-center"},
  2878. {"targets": [12], "width": "85px"},
  2879. {"targets": [12], "orderable": false}
  2880. ],
  2881. "order": [[ 1, "desc" ]],
  2882. "rowCallback": function(row, data, index) {
  2883. if ( data[13] == "1" ) {
  2884. $(\'td\', row).css(\'background-color\', \'' . $this->payedThisMonthBKGND . '\');
  2885. $(\'td\', row).css(\'color\', \'' . $this->payedThisMonthFRGND . '\');
  2886. }
  2887. if ( data[13] == "0" ) {
  2888. $(\'td\', row).css(\'background-color\', \'' . $this->paymentExpiredBKGND . '\');
  2889. $(\'td\', row).css(\'color\', \'' . $this->paymentExpiredFRGND . '\');
  2890. }
  2891. }
  2892. ';
  2893. $result = $this->getStdJQDTWithJSForCRUDs($ajaxURL, $columns, $opts, $stdJSForCRUDs, $customJSCode, $markRowForID, self::URL_ME . '&' . self::URL_EXTCONTRAS . '=true&' . self::MISC_MARKROW_URL . '=' . $markRowForID, self::MISC_MARKROW_URL, true, array(7), $this->currencyStr);
  2894. return($result);
  2895. }
  2896. /**
  2897. * Renders JSON for overdue payments JQDT
  2898. *
  2899. * @param string $whereRaw
  2900. */
  2901. public function missedPaymsRenderListJSON($whereRaw = '') {
  2902. if (!empty($whereRaw)) {
  2903. $this->dbECMissedPayms->whereRaw($whereRaw);
  2904. }
  2905. $this->loadDataFromTableCached(self::TABLE_ECMISSPAYMENTS, self::TABLE_ECMISSPAYMENTS, !empty($whereRaw), true, '', '', !empty($whereRaw));
  2906. $this->loadExtContrasExtenData();
  2907. $json = new wf_JqDtHelper();
  2908. if (!empty($this->allExtContrasExten) and ! empty($this->allECMissedPayms)) {
  2909. $data = array();
  2910. foreach ($this->allECMissedPayms as $eachRecID) {
  2911. $curRecID = $eachRecID[self::DBFLD_COMMON_ID];
  2912. $contrasRecID = $eachRecID[self::DBFLD_MISSPAYMS_CONTRASID];
  2913. $profileRecID = $eachRecID[self::DBFLD_MISSPAYMS_PROFILEID];
  2914. $contractRecID = $eachRecID[self::DBFLD_MISSPAYMS_CONTRACTID];
  2915. $periodRecID = $eachRecID[self::DBFLD_MISSPAYMS_PERIOD_ID];
  2916. $addrRecID = $eachRecID[self::DBFLD_MISSPAYMS_ADDRESSID];
  2917. $payDay = $eachRecID[self::DBFLD_MISSPAYMS_PAYDAY];
  2918. $datePayment = $eachRecID[self::DBFLD_MISSPAYMS_DATE_PAYMENT];
  2919. $dateExpired = $eachRecID[self::DBFLD_MISSPAYMS_DATE_EXPIRED];
  2920. $datePayed = $eachRecID[self::DBFLD_MISSPAYMS_DATE_PAYED];
  2921. $sumPayment = $eachRecID[self::DBFLD_MISSPAYMS_SUMPAYMENT];
  2922. $alreadyPayed = !empty($datePayed);
  2923. if (!empty($this->allExtContrasExten[$contrasRecID])) {
  2924. $extenData = $this->allExtContrasExten[$contrasRecID];
  2925. $counterparty = $extenData[self::TABLE_ECPROFILES . self::DBFLD_PROFILE_NAME];
  2926. $contractNum = $extenData[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_CONTRACT];
  2927. $contractSbj = $extenData[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_SUBJECT];
  2928. $contractSum = $extenData[self::TABLE_ECCONTRACTS . self::DBFLD_CTRCT_FULLSUM];
  2929. $address = $extenData[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_ADDR];
  2930. $addressSum = $extenData[self::TABLE_ECADDRESS . self::DBFLD_ADDRESS_SUM];
  2931. $periodName = $extenData[self::TABLE_ECPERIODS . self::DBFLD_PERIOD_NAME];
  2932. } else {
  2933. $counterparty = '';
  2934. $contractNum = '';
  2935. $contractSbj = '';
  2936. $contractSum = '';
  2937. $address = '';
  2938. $addressSum = '';
  2939. $periodName = '';
  2940. }
  2941. $data[] = $curRecID;
  2942. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTPROFILES . '=true'
  2943. . '&' . self::MISC_MARKROW_URL . '=' . $profileRecID, $counterparty);
  2944. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTCONTRACTS . '=true'
  2945. . '&' . self::MISC_MARKROW_URL . '=' . $contractRecID, $contractNum);
  2946. $data[] = $contractSbj;
  2947. $data[] = wf_Link(self::URL_ME . '&' . self::URL_DICTADDRESS . '=true'
  2948. . '&' . self::MISC_MARKROW_URL . '=' . $addrRecID, $address);
  2949. $data[] = $periodName;
  2950. $data[] = $payDay;
  2951. $data[] = $sumPayment;
  2952. $data[] = $datePayment;
  2953. $data[] = $dateExpired;
  2954. $data[] = $datePayed;
  2955. $actions = $this->getStdJQDTActions($curRecID, self::ROUTE_MISSPAYMS_ACTS, false, '', false);
  2956. $data[] = $actions;
  2957. $data[] = wf_jsAjaxDynamicWindowButton(self::URL_ME, array(self::ROUTE_FINOPS_ACTS => 'true',
  2958. self::ROUTE_ACTION_PREFILL => 'true',
  2959. self::MISC_PREFILL_DATA => array(self::CTRL_MONEY_PROFILEID => $profileRecID,
  2960. self::CTRL_MONEY_CNTRCTID => $contractRecID,
  2961. self::CTRL_MONEY_ADDRESSID => $addrRecID,
  2962. self::CTRL_MONEY_SUMPAYMENT => $sumPayment,
  2963. self::MISC_MISSED_PAYMENT_PROCESSING => 'true',
  2964. self::MISC_MISSED_PAYMENT_ID => $curRecID
  2965. )
  2966. ), '', web_add_icon(), '', 'POST', 'click', false, false, true, '$(this).closest("table").parent().children().find(\'[id ^= "jqdt_"][role = "grid"]\').last().attr("id")'
  2967. );
  2968. $data[] = ($alreadyPayed ? 1 : 0);
  2969. $json->addRow($data);
  2970. unset($data);
  2971. }
  2972. }
  2973. $json->getJson();
  2974. }
  2975. }