ProjektyKosztyWstepnychRobot.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ProjectKosztorysSchema');
  4. Lib::loadClass('ProjectKosztorysModel');
  5. Lib::loadClass('ProjectKosztorysCennik');
  6. class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {// TODO: UrlActionBase @see Route_UrlAction
  7. public $_model = array();
  8. public function handleAuth() {
  9. if (!User::logged()) {
  10. User::authByRequest();
  11. }
  12. }
  13. public function defaultAction() {
  14. // TODO: check if user is allowed to run this action
  15. SE_Layout::gora();
  16. if (1 != V::get('_print', '', $_GET)) SE_Layout::menu();
  17. try {
  18. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  19. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  20. if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
  21. $this->panel($idProject, $idCompany);
  22. $this->kosztorys($idProject, $idCompany);
  23. } catch (Exception $e) {
  24. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  25. }
  26. SE_Layout::dol();
  27. }
  28. public function zestawienieSwMikRurAction() {
  29. SE_Layout::gora();
  30. if (1 != V::get('_print', '', $_GET)) SE_Layout::menu();
  31. try {
  32. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  33. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  34. if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
  35. $this->panel($idProject, $idCompany);
  36. $this->zestawienieSwMikRur($idProject, $idCompany);
  37. } catch (Exception $e) {
  38. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  39. }
  40. SE_Layout::dol();
  41. }
  42. public function ofertaAdminAction() {
  43. // TODO: check if user is allowed to run this action
  44. SE_Layout::gora();
  45. SE_Layout::menu();
  46. try {
  47. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  48. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  49. $admin = true;
  50. $ofertaArgs = compact('idProject', 'idCompany', 'admin');
  51. $this->panel($idProject, $idCompany);
  52. if ($idProject > 0) {
  53. $this->oferta($ofertaArgs);
  54. } else {
  55. $this->defaultOferta();
  56. }
  57. } catch (Exception $e) {
  58. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  59. }
  60. SE_Layout::dol();
  61. }
  62. public function ofertaCompanyAction() {
  63. // TODO: check if user is allowed to run this action
  64. SE_Layout::gora();
  65. SE_Layout::menu();
  66. try {
  67. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  68. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');// TODO: $idCompany from ADMIN_USERS
  69. $admin = false;
  70. $companyAdmin = true;
  71. $ofertaArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin');
  72. $this->panel($idProject, $idCompany);
  73. if ($idProject > 0) {
  74. $this->oferta($ofertaArgs);
  75. } else {
  76. $this->defaultOferta();
  77. }
  78. } catch (Exception $e) {
  79. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  80. }
  81. SE_Layout::dol();
  82. }
  83. public function ofertaDefaultAdminAction() {
  84. // TODO: check if user is allowed to run this action
  85. SE_Layout::gora();
  86. SE_Layout::menu();
  87. try {
  88. $idProject = 0;
  89. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  90. $this->panel($idProject, $idCompany);
  91. $this->defaultOferta();
  92. } catch (Exception $e) {
  93. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  94. }
  95. SE_Layout::dol();
  96. }
  97. public function ofertaAction() {
  98. // TODO: check if user is allowed to run this action
  99. SE_Layout::gora();
  100. SE_Layout::menu();
  101. try {
  102. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  103. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  104. $admin = false;
  105. if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");// TODO: show select box if not defined
  106. $ofertaArgs = compact('idProject', 'idCompany', 'admin');
  107. $this->panel($idProject, $idCompany);
  108. $this->oferta($ofertaArgs);
  109. } catch (Exception $e) {
  110. SE_Layout::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  111. }
  112. SE_Layout::dol();
  113. }
  114. public function getArgsList() {// TODO: override UrlActionBase::getArgsList action
  115. $args = array();
  116. $args[] = 'ID_PROJECT';
  117. return $args;
  118. }
  119. public function reinstallAction() {// TODO: mv to UrlActionBase
  120. $jsonData = new stdClass();
  121. $jsonData->type = 'success';
  122. $jsonData->msg = 'Gotowe';
  123. try {
  124. $this->reinstall();
  125. } catch (Exception $e) {
  126. $jsonData->type = 'danger';
  127. $jsonData->msg = $e->getMessage();
  128. }
  129. echo json_encode($jsonData);
  130. }
  131. public function reinstall() {// TODO: mv struct check to UrlActionBase
  132. $pdo = DB::getPDO();
  133. {
  134. $dropGDistanceFuncion = "DROP FUNCTION IF EXISTS `GDistance`";
  135. $pdo->exec($dropGDistanceFuncion);
  136. // Test for GDistance:
  137. // select '' as test, GDistance('') as GDistance, IF(GDistance('') = 0, 1, 0) as test_ok;
  138. // select 'NULL' as test, GDistance(NULL) as GDistance, IF(GDistance(NULL) = 0, 1, 0) as test_ok;
  139. // select 'GeomFromText(POLYGON((18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799,18.5617610722586 54.346524689865,18.5619728898979 54.3488528136092,18.5609743210268 54.3496376437764,18.5600057772984 54.3494578097971,18.559603951991 54.350742572617,18.5590637025025 54.3507194967965,18.5578575757622 54.349434823939,18.5573431614953 54.3472831082951)))' as test, GDistance(GeomFromText('POLYGON((18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799,18.5617610722586 54.346524689865,18.5619728898979 54.3488528136092,18.5609743210268 54.3496376437764,18.5600057772984 54.3494578097971,18.559603951991 54.350742572617,18.5590637025025 54.3507194967965,18.5578575757622 54.349434823939,18.5573431614953 54.3472831082951))')) as GDistance, IF(1 = GDistance(GeomFromText('POLYGON((18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799,18.5617610722586 54.346524689865,18.5619728898979 54.3488528136092,18.5609743210268 54.3496376437764,18.5600057772984 54.3494578097971,18.559603951991 54.350742572617,18.5590637025025 54.3507194967965,18.5578575757622 54.349434823939,18.5573431614953 54.3472831082951))')), 1, 0) as test_ok;
  140. // select 'GeomFromText(LINESTRING(18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799))' as test, GDistance(GeomFromText('LINESTRING(18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799)')) as GDistance, IF(GDistance(GeomFromText('LINESTRING(18.5573431614953 54.3472831082951,18.5612466579916 54.3460308284799)')) is not null, 1, 0) as test_ok;
  141. // select 'GeomFromText(POINT(18.5573431614953 54.3472831082951))' as test, GDistance(GeomFromText('POINT(18.5573431614953 54.3472831082951)')) as GDistance, IF(GDistance(GeomFromText('POINT(18.5573431614953 54.3472831082951)')) is not null, 1, 0) as test_ok;
  142. $gDistanceFuncion = <<<SQL_FUN
  143. CREATE DEFINER=`root`@`localhost` FUNCTION `GDistance`(`LS` LINESTRING) RETURNS double NO SQL
  144. BEGIN
  145. DECLARE LON_A, LAT_A, LON_B, LAT_B, R, RESULT DOUBLE;
  146. DECLARE A, B POINT;
  147. DECLARE I, N INT;
  148. -- if LS is not geometry type then return 0
  149. -- if GeometryType is not 'LINESTRING' then return 1
  150. -- if GeometryType is 'LINESTRING' then return length
  151. IF LS is null or GeometryType(LS) is null THEN
  152. RETURN 0;
  153. END IF;
  154. IF 'LINESTRING' != GeometryType(LS) THEN
  155. RETURN 1;
  156. END IF;
  157. SET R = 6372795.477598;
  158. SET N = NUMPOINTS(LS);
  159. IF N is null or N = 1 THEN
  160. RETURN 1;
  161. END IF;
  162. SET RESULT = 0;
  163. SET I = 1;
  164. WHILE I < N DO
  165. SET A = POINTN(LS, I);
  166. SET B = POINTN(LS, I + 1);
  167. SET LON_A = RADIANS(X(A));
  168. SET LAT_A = RADIANS(Y(A));
  169. SET LON_B = RADIANS(X(B));
  170. SET LAT_B = RADIANS(Y(B));
  171. SET RESULT = RESULT + ACOS(SIN(LAT_A) * SIN(LAT_B) + COS(LAT_A) * COS(LAT_B) * COS(LON_A - LON_B));
  172. SET I = I + 1;
  173. END WHILE;
  174. SET RESULT = RESULT * R;
  175. RETURN RESULT;
  176. END
  177. SQL_FUN;
  178. $pdo->exec($gDistanceFuncion);
  179. }
  180. /* required Zasoby tree structure - XML (parent rel in PARENT_ID field):
  181. <zasob:tree>
  182. <zasob:TYPESPECIALS>
  183. <zasob:URL_ACTION zasob:key=":action_id" zasob:desc=":url_action_name">
  184. <zasob:PARAM_IN zasob:key=":action_param_1_id" zasob:desc=":url_action_param_1_name"/>
  185. </zasob:URL_ACTION>
  186. </zasob:TYPESPECIALS>
  187. <zasob:BAZA_DANYCH zasob:key=":main_db_id" altername_types="DATABASE_MYSQL,DATABASE_POSTGRESQL">
  188. <zasob:TABELA zasob:key=":tbl_id" zasob:desc="IN7_MK_BAZA_DYSTRYBUCJI">
  189. <zasob:KOMORKA zasob:key=":cell_id" zasob:desc="ID"/>
  190. <zasob:URL_ACTION zasob:key=":link_action_id" zasob:desc=":url_action_name" zasob:alias_id=":action_id">
  191. <zasob:PARAM_IN zasob:key=":cell_id" zasob:desc="ID_PROJECT" zasob:alias_id=":cell_id"/>
  192. </zasob:URL_ACTION>
  193. </zasob:TABELA>
  194. </zasob:BAZA_DANYCH>
  195. </zasob:tree>
  196. */
  197. /* required Zasoby tree structure:
  198. - required base structure
  199. [:ts_main_id] TYPESPECIALS
  200. [:action_id] URL_ACTION :url_action_name
  201. [:action_param_1_id] PARAM_IN :url_action_param_1_name
  202. - current function from schema
  203. [:main_db_id] (DATABASE_MYSQL, BAZA_DANYCH, DATABASE_POSTGRESQL)
  204. [:tbl_id] TABELA 'IN7_MK_BAZA_DYSTRYBUCJI'
  205. [:cell_id] KOMORKA 'ID'
  206. [:link_action_id] (ALIAS DO :action_id) URL_ACTION :url_action_name
  207. [:link_param_id] (ALIAS DO :cell_id) PARAM_IN :url_action_param_1_name
  208. :url_action_name = 'ProjektyKosztyWstepnychRobot'
  209. :url_action_param_1_name = 'ID_PROJECT'
  210. */
  211. $flatConfig_main = array();
  212. {
  213. $flatConfig_main[] = (object)array(// Zasob::assert(TYPESPECIALS)
  214. 'query' => "
  215. select z.ID from CRM_LISTA_ZASOBOW z
  216. where z.TYPE='TYPESPECIALS'
  217. and z.A_STATUS not in('DELETED')
  218. ",
  219. 'createTable' => 'CRM_LISTA_ZASOBOW',
  220. 'createArgs' => array('TYPE' => 'TYPESPECIALS', 'DESC' => 'Typespecials'),
  221. 'out' => array(':ts_main_id' => 'ID')
  222. );
  223. $flatConfig_main[] = (object)array(// Zasob::assert(TYPESPECIALS/:url_action_name)
  224. 'query' => "
  225. select z.ID from CRM_LISTA_ZASOBOW z
  226. where z.PARENT_ID = :ts_main_id
  227. and z.TYPE = 'URL_ACTION'
  228. and z.DESC = :url_action_name
  229. and z.A_STATUS not in('DELETED')
  230. ",
  231. 'createTable' => 'CRM_LISTA_ZASOBOW',
  232. 'createArgs' => array('TYPE' => 'URL_ACTION', 'PARENT_ID' => ':ts_main_id', 'DESC' => ':url_action_name'),
  233. 'in' => array(':ts_main_id', ':url_action_name'),
  234. 'out' => array(':action_id' => 'ID')
  235. );
  236. $flatConfig_main[] = (object)array(// Zasob::assert(TYPESPECIALS/:url_action_name/:url_action_param_1_name)
  237. 'query' => "
  238. select z.ID from CRM_LISTA_ZASOBOW z
  239. where z.PARENT_ID = :action_id
  240. and z.TYPE = 'PARAM_IN'
  241. and z.DESC = :url_action_param_1_name
  242. and z.A_STATUS not in('DELETED')
  243. ",
  244. 'createTable' => 'CRM_LISTA_ZASOBOW',
  245. 'createArgs' => array('TYPE' => 'PARAM_IN', 'PARENT_ID' => ':action_id', 'DESC' => ':url_action_param_1_name'),
  246. 'in' => array(':action_id', ':url_action_param_1_name'),
  247. 'out' => array(':action_param_1_id' => 'ID')
  248. );
  249. }
  250. //DBG::_('DBG', '>1', "flatConfig_main", $flatConfig_main, __CLASS__, __FUNCTION__, __LINE__);
  251. $flatConfig_link_in_projekt = array();
  252. {
  253. $flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db)
  254. 'query' => "
  255. select z.ID from CRM_LISTA_ZASOBOW z
  256. where z.ID = :main_db_id
  257. and z.TYPE in('DATABASE_MYSQL', 'BAZA_DANYCH', 'DATABASE_POSTGRESQL')
  258. and z.A_STATUS not in('DELETED')
  259. ",
  260. 'createTable' => 'CRM_LISTA_ZASOBOW',
  261. 'createArgs' => array('TYPE' => 'BAZA_DANYCH', 'DESC' => 'Baza danych'),
  262. 'in' => array(':main_db_id'),
  263. 'out' => array(':main_db_id' => 'ID')
  264. );
  265. $flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db/IN7_MK_BAZA_DYSTRYBUCJI)
  266. 'query' => "
  267. select z.ID from CRM_LISTA_ZASOBOW z
  268. where z.PARENT_ID = :main_db_id
  269. and z.TYPE = 'TABELA'
  270. and z.DESC = 'IN7_MK_BAZA_DYSTRYBUCJI'
  271. and z.A_STATUS not in('DELETED')
  272. ",
  273. 'createTable' => 'CRM_LISTA_ZASOBOW',
  274. 'createArgs' => array('TYPE' => 'TABELA', 'PARENT_ID' => ':main_db_id', 'DESC' => 'IN7_MK_BAZA_DYSTRYBUCJI'),
  275. 'in' => array(':main_db_id'),
  276. 'out' => array(':tbl_id' => 'ID')
  277. );
  278. $flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db/IN7_MK_BAZA_DYSTRYBUCJI/ID)
  279. 'query' => "
  280. select z.ID from CRM_LISTA_ZASOBOW z
  281. where z.PARENT_ID = :tbl_id
  282. and z.TYPE = 'KOMORKA'
  283. and z.DESC = 'ID'
  284. and z.A_STATUS not in('DELETED')
  285. ",
  286. 'createTable' => 'CRM_LISTA_ZASOBOW',
  287. 'createArgs' => array('TYPE' => 'KOMORKA', 'PARENT_ID' => ':tbl_id', 'DESC' => 'ID'),
  288. 'in' => array(':tbl_id'),
  289. 'out' => array(':cell_id' => 'ID')
  290. );
  291. $flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db/IN7_MK_BAZA_DYSTRYBUCJI/:url_action_name)
  292. 'query' => "
  293. select z.ID from CRM_LISTA_ZASOBOW z
  294. where z.PARENT_ID = :tbl_id
  295. and z.ALIAS_ID = ':action_id'
  296. and z.TYPE = 'URL_ACTION'
  297. and z.DESC = ':url_action_name'
  298. and z.A_STATUS not in('DELETED')
  299. ",
  300. 'createTable' => 'CRM_LISTA_ZASOBOW',
  301. 'createArgs' => array('TYPE' => 'URL_ACTION', 'PARENT_ID' => ':tbl_id', 'ALIAS_ID' => ':action_id', 'DESC' => ':url_action_name'),
  302. 'in' => array(':tbl_id', ':action_id', ':url_action_name'),
  303. 'out' => array(':link_action_id' => 'ID')
  304. );
  305. // [:link_param_id] (ALIAS DO :cell_id) PARAM_IN :url_action_param_1_name
  306. $flatConfig_link_in_projekt[] = (object)array(// Zasob::assert(default_db/IN7_MK_BAZA_DYSTRYBUCJI/:url_action_name/:url_action_param_1_name)
  307. 'query' => "
  308. select z.ID from CRM_LISTA_ZASOBOW z
  309. where z.PARENT_ID = :link_action_id
  310. and z.ALIAS_ID = ':cell_id'
  311. and z.TYPE = 'PARAM_IN'
  312. and z.DESC = ':url_action_param_1_name'
  313. and z.A_STATUS not in('DELETED')
  314. ",
  315. 'createTable' => 'CRM_LISTA_ZASOBOW',
  316. 'createArgs' => array('TYPE' => 'PARAM_IN', 'PARENT_ID' => ':link_action_id', 'ALIAS_ID' => ':cell_id', 'DESC' => ':url_action_param_1_name'),
  317. 'in' => array(':cell_id', ':link_action_id', ':url_action_param_1_name'),
  318. 'out' => array(':link_action_id' => 'ID')
  319. );
  320. }
  321. //DBG::_('DBG', '>1', "flatConfig_link_in_projekt", $flatConfig_link_in_projekt, __CLASS__, __FUNCTION__, __LINE__);
  322. $flatConf = array_merge($flatConfig_main, $flatConfig_link_in_projekt);
  323. $knownArgs = array();
  324. $knownArgs[':url_action_name'] = 'Test';
  325. $knownArgs[':url_action_param_1_name'] = 'ID_PROJECT';
  326. $knownArgs[':main_db_id'] = '36';// from DB::getDB()->getZasobId(); or DB::getPDO()->getZasobId();
  327. $this->_debugFlatConfig($flatConf, $knownArgs);
  328. $args = $this->getArgsList();
  329. $clsName = __CLASS__;
  330. $urlActionName = str_replace('Route_UrlAction_', '', $clsName);
  331. DBG::_('DBG', '>1', "reinstall class", __CLASS__, __CLASS__, __FUNCTION__, __LINE__);
  332. DBG::_('DBG', '>1', "reinstall funName", $urlActionName, __CLASS__, __FUNCTION__, __LINE__);
  333. DBG::_('DBG', '>1', "reinstall test", $args, __CLASS__, __FUNCTION__, __LINE__);
  334. $dbFunction = $this->fetchZasobInfo();
  335. $usrLogin = User::getLogin();
  336. {// check if URL_ACTION already exists
  337. if (!$dbFunction) throw new Exception("Brak id zasobu typu TYPESPECIALS - TODO: CREATE");// $this->createZasobTypespecials();
  338. DBG::_('DBG', '>1', "dbFunction", $dbFunction, __CLASS__, __FUNCTION__, __LINE__);
  339. if ($dbFunction['action_id_is_null']) {
  340. $sth = $pdo->prepare("
  341. insert into CRM_LISTA_ZASOBOW (
  342. TYPE,
  343. PARENT_ID,
  344. `DESC`,
  345. A_RECORD_CREATE_AUTHOR,
  346. A_RECORD_CREATE_DATE
  347. )
  348. values (
  349. 'URL_ACTION',
  350. :ts_id,
  351. :url_action_name,
  352. 'system-by-{$usrLogin}',
  353. NOW()
  354. )
  355. ");
  356. //$sth->bindValue('ts_id', $dbFunction['ts_id'], PDO::PARAM_INT);
  357. //$sth->bindValue('url_action_name', $urlActionName, PDO::PARAM_STR);
  358. $bindValues = array();
  359. $bindValues['ts_id'] = array($dbFunction['ts_id'], PDO::PARAM_INT);
  360. $bindValues['url_action_name'] = $urlActionName;
  361. $pdo->bindValues($sth, $bindValues);
  362. DBG::_('DBG', '>1', "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
  363. $sth->execute();
  364. $dbFunction = $this->fetchZasobInfo();
  365. if (!$dbFunction || $dbFunction['action_id_is_null']) throw new Exception("Brak zasobu typu URL_ACTION, nie udało się go utworzyć!");
  366. }
  367. }
  368. {// check params
  369. if (!empty($args)) {
  370. $todoArgs = array();
  371. foreach ($args as $argName) {
  372. if (empty($dbFunction['url_params'])) {
  373. $todoArgs[$argName] = true;
  374. } else if (!array_key_exists($argName, $dbFunction['url_params'])) {
  375. $todoArgs[$argName] = true;
  376. }
  377. // OK PARAM_IN exists
  378. }
  379. $todoArgs = array_keys($todoArgs);
  380. DBG::_('DBG', '>1', "todoArgs", $todoArgs, __CLASS__, __FUNCTION__, __LINE__);
  381. if (!empty($todoArgs)) {
  382. $sqlValues = array();
  383. foreach ($todoArgs as $argName) {
  384. $sqlValues[] = "(
  385. 'PARAM_IN',
  386. {$dbFunction['action_id']},
  387. '{$argName}',
  388. 'system-by-{$usrLogin}',
  389. NOW()
  390. )
  391. ";
  392. }
  393. $sqlValues = implode(", ", $sqlValues);
  394. $sth = $pdo->prepare("
  395. insert into CRM_LISTA_ZASOBOW (
  396. TYPE,
  397. PARENT_ID,
  398. `DESC`,
  399. A_RECORD_CREATE_AUTHOR,
  400. A_RECORD_CREATE_DATE
  401. )
  402. values {$sqlValues}
  403. ");
  404. DBG::_('DBG', '>1', "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
  405. //$sth->execute();
  406. $dbFunction = $this->fetchZasobInfo();
  407. }
  408. if (empty($dbFunction['url_params'])) {
  409. throw new Exception("Brak zdefiniowanych parametrów, nie udało się ich utworzyć!");
  410. }
  411. }
  412. }
  413. {// check links in tables
  414. // $info['links']['IN7_MK_BAZA_DYSTRYBUCJI'] = $linkInfo;
  415. if (empty($dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'])) throw new Exception("Brak poprawne wprowadzonej tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' w drzewie zasobów!");
  416. $projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
  417. /*
  418. [link_action_id] =>
  419. [db_id] => 36
  420. [tbl_id] => 636
  421. [cell_id] => 763
  422. [param1_id] =>
  423. */
  424. if (!$projInfo['link_action_id']) {
  425. $sth = $pdo->prepare("
  426. insert into CRM_LISTA_ZASOBOW (
  427. TYPE,
  428. PARENT_ID,
  429. ALIAS_ID,
  430. `DESC`,
  431. A_RECORD_CREATE_AUTHOR,
  432. A_RECORD_CREATE_DATE
  433. )
  434. values (
  435. 'URL_ACTION',
  436. {$projInfo['tbl_id']},
  437. {$dbFunction['action_id']},
  438. '{$urlActionName}',
  439. 'system-by-{$usrLogin}',
  440. NOW()
  441. )
  442. ");
  443. //DBG::_('DBG', '>1', "sql", $pdo->getRawSql($sth), __CLASS__, __FUNCTION__, __LINE__);
  444. $sth->execute();
  445. $dbFunction = $this->fetchZasobInfo();
  446. $projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
  447. if (!$projInfo['link_action_id']) throw new Exception("Brak zainstalowanej akcji dla tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' - nie udało się zainstalować");
  448. }
  449. if (!$projInfo['param1_id']) {// TODO: get from params
  450. $sth = $pdo->prepare("
  451. insert into CRM_LISTA_ZASOBOW (
  452. TYPE,
  453. PARENT_ID,
  454. ALIAS_ID,
  455. `DESC`,
  456. A_RECORD_CREATE_AUTHOR,
  457. A_RECORD_CREATE_DATE
  458. )
  459. values (
  460. 'PARAM_IN',
  461. {$projInfo['link_action_id']},
  462. {$projInfo['cell_id']},
  463. 'ID_PROJECT',
  464. 'system-by-{$usrLogin}',
  465. NOW()
  466. )
  467. ");
  468. $sth->execute();
  469. $dbFunction = $this->fetchZasobInfo();
  470. $projInfo = $dbFunction['links']['IN7_MK_BAZA_DYSTRYBUCJI'];
  471. if (!$projInfo['param1_id']) throw new Exception("Brak zainstalowanego parametru 1 w akcji dla tabeli 'IN7_MK_BAZA_DYSTRYBUCJI' - nie udało się zainstalować");
  472. }
  473. }
  474. }
  475. public function _debugFlatConfig($flatConfig, $args = array()) {
  476. //DBG::_('DBG', '>1', "flatConfig", $flatConfig, __CLASS__, __FUNCTION__, __LINE__);
  477. echo '<pre style="border:1px solid green">';
  478. foreach ($flatConfig as $conf) {
  479. /*
  480. [query] => string
  481. [createTable] => srting - eg. CRM_LISTA_ZASOBOW
  482. [createArgs] => array - eg. [ TYPE: 'TYPESPECIALS', DESC: 'Typespecials' ]
  483. [in] => array - eg. [ ':ts_main_id', ':url_action_name' ]
  484. [out] => array - eg. [ ':ts_main_id': 'ID' ]
  485. */
  486. echo "Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
  487. }
  488. echo '</pre>';
  489. echo '<pre style="border:1px solid green">';
  490. echo "DBG: Simulate iter loop:\n";
  491. $simulateGeneratedId = 1000;
  492. $i = 0; $limit = 10; $todoIdx = array(); $knownArgsMap = array();
  493. foreach ($flatConfig as $idx => $conf) $todoIdx[] = $idx;
  494. foreach ($args as $arg => $val) $knownArgsMap[$arg] = $val;
  495. for ($i = 0; $i < $limit; $i++) {
  496. echo ">> DBG loop({$i}):\n";
  497. $isExecuted = false;
  498. foreach ($todoIdx as $idx) {
  499. $conf = $flatConfig[$idx];
  500. /*
  501. [query] => string
  502. [createTable] => srting - eg. CRM_LISTA_ZASOBOW
  503. [createArgs] => array - eg. [ TYPE: 'TYPESPECIALS', DESC: 'Typespecials' ]
  504. [in] => array - eg. [ ':ts_main_id', ':url_action_name' ]
  505. [out] => array - eg. [ ':ts_main_id': 'ID' ]
  506. */
  507. echo ">>>> Loop({$i}): idx({$idx}) Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
  508. $canExecute = true;
  509. if (!empty($conf->in)) foreach ($conf->in as $argName) {
  510. if (!array_key_exists($argName, $knownArgsMap)) {
  511. $canExecute = false;
  512. }
  513. }
  514. if ($canExecute) {
  515. // TODO: execute - $r = $this->_assertZasobConf($conf, $knownArgsMap);
  516. // fetch params out to $knownArgsMap
  517. foreach ($conf->out as $argName => $outFieldName) {
  518. $knownArgsMap[$argName] = $simulateGeneratedId++;// TODO: fetch from returned object ($r->{$outFieldName})
  519. }
  520. $todoIdx = array_diff($todoIdx, array($idx));// remove $idx from $todoIdx
  521. echo ">>>> Loop({$i}): knownArgsMap: " . json_encode($knownArgsMap) . " \n";
  522. $isExecuted = true;
  523. } else {
  524. echo ">>>> Loop({$i}): cannot execute conf [{$idx}] missing args: " . json_encode($conf->in) . " \n";
  525. }
  526. }
  527. if (!$isExecuted) {
  528. echo "DBG: Stop";
  529. if (empty($todoIdx)) {
  530. echo " - OK";
  531. } else {
  532. echo " - Error - TODO:\n";
  533. foreach ($todoIdx as $idx) {
  534. $conf = $flatConfig[$idx];
  535. echo "Zasob::assert({$conf->createTable}): " . json_encode($conf->createArgs) . " returns: " . json_encode($conf->out) . "\n";
  536. }
  537. }
  538. break;
  539. }
  540. }
  541. echo '</pre>';
  542. }
  543. public function fetchZasobInfo() {
  544. $pdo = DB::getPDO();
  545. $args = $this->getArgsList();
  546. $clsName = __CLASS__;
  547. $urlActionName = str_replace('Route_UrlAction_', '', $clsName);
  548. $sth = $pdo->prepare("
  549. select zp.ID as ts_id
  550. , IF(z.ID is null, 1, 0) as action_id_is_null
  551. , z.ID as action_id
  552. , z.DESC as action_desc
  553. from CRM_LISTA_ZASOBOW zp
  554. left join CRM_LISTA_ZASOBOW z on(z.PARENT_ID = zp.ID
  555. and z.TYPE = 'URL_ACTION'
  556. and z.DESC = :url_action_name
  557. and z.A_STATUS not in('DELETED')
  558. )
  559. where zp.TYPE = 'TYPESPECIALS'
  560. and zp.A_STATUS not in('DELETED')
  561. ");
  562. $sth->bindValue('url_action_name', $urlActionName);
  563. $sth->execute();
  564. $info = $sth->fetch();
  565. if (!$info) return $info;
  566. $info['url_params'] = array();
  567. $info['links'] = array();// where action is installed - expected `IN7_MK_BAZA_DYSTRYBUCJI`
  568. if ($info['action_id'] > 0) {
  569. $sthParams = $pdo->prepare("
  570. select z.ID as param_id
  571. , z.DESC as param_desc
  572. from CRM_LISTA_ZASOBOW z
  573. where z.TYPE = 'PARAM_IN'
  574. and z.A_STATUS not in('DELETED')
  575. and z.PARENT_ID = :url_action_id
  576. ");
  577. $sthParams->bindValue('url_action_id', $info['action_id']);
  578. $sthParams->execute();
  579. $urlParams = array();
  580. $rawUrlParams = $sthParams->fetchAll();
  581. foreach ($rawUrlParams as $urlParam) {
  582. $urlParams[$urlParam['param_desc']] = $urlParam;
  583. }
  584. $info['url_params'] = $urlParams;
  585. }
  586. {
  587. $main_db_id = $pdo->getZasobId();
  588. $sth_dbInfo = $pdo->prepare("
  589. select za.id as link_action_id
  590. , zd.id as db_id
  591. , zt.id as tbl_id
  592. , zi.id as cell_id
  593. , zp1.id as param1_id -- for every param
  594. from CRM_LISTA_ZASOBOW zt
  595. join CRM_LISTA_ZASOBOW zd on(zd.ID = zt.PARENT_ID
  596. and zd.TYPE in('DATABASE_MYSQL', 'BAZA_DANYCH', 'DATABASE_POSTGRESQL')
  597. and zd.ID = {$main_db_id}
  598. )
  599. join CRM_LISTA_ZASOBOW zi on(zi.PARENT_ID = zt.ID
  600. and zi.TYPE = 'KOMORKA'
  601. and zi.DESC = 'ID'
  602. )
  603. left join CRM_LISTA_ZASOBOW za on(za.PARENT_ID = zt.ID
  604. and za.TYPE = 'URL_ACTION'
  605. and za.ALIAS_ID = {$info['action_id']}
  606. )
  607. -- TODO: for every param:
  608. left join CRM_LISTA_ZASOBOW zp1 on(zp1.PARENT_ID = za.ID
  609. and zp1.TYPE = 'PARAM_IN'
  610. and zp1.ALIAS_ID = zi.id
  611. and zp1.DESC = 'ID_PROJECT'
  612. )
  613. where zt.TYPE = 'TABELA'
  614. and zt.A_STATUS not in('DELETED')
  615. and zt.DESC = 'IN7_MK_BAZA_DYSTRYBUCJI'
  616. ");
  617. DBG::_('DBG', '>1', "dbInfo query", $pdo->getRawSql($sth_dbInfo), __CLASS__, __FUNCTION__, __LINE__);
  618. $sth_dbInfo->execute();
  619. $linkInfo = $sth_dbInfo->fetch();
  620. if ($linkInfo) {
  621. $info['links']['IN7_MK_BAZA_DYSTRYBUCJI'] = $linkInfo;
  622. }
  623. }
  624. return $info;
  625. }
  626. public function kosztorysXmlAction() {// TODO: using old schema fields Agr_*
  627. /*
  628. $idProject = 1921;
  629. $schema = ProjectKosztorysSchema::getSchema();
  630. $data = $this->_fetchKosztorysData($idProject);
  631. //DBG::_('DBG', '>1', "XMLWriter", class_exists('XMLWriter'), __CLASS__, __FUNCTION__, __LINE__);
  632. //header('Content-type: application/xml; charset=utf-8');
  633. header('Content-type: text/plain; charset=utf-8');
  634. $xmlWriter = new XMLWriter();
  635. $xmlWriter->openUri('php://output');
  636. $xmlWriter->setIndent(true);
  637. if ($xmlWriter) {
  638. $xmlWriter->startDocument('1.0','UTF-8');
  639. //$xmlWriter->startElementNS(null, 'kosztorysy', 'https://biuro.biall-net.pl/wfs');// adds @xmlns=...
  640. $xmlWriter->startElement('kosztorysy');
  641. $xmlWriter->writeAttribute('targetNamespace', 'https://biuro.biall-net.pl/wfs');
  642. $xmlWriter->writeAttributeNS('xmlns', 'p5', 'http://www.w3.org/2000/xmlns/', 'https://biuro.biall-net.pl/wfs');
  643. for ($i = 1; $i <= 10; $i++) {
  644. $idProject += 1;
  645. $schema = ProjectKosztorysSchema::getSchema();
  646. $data = $this->_fetchKosztorysData($idProject);
  647. $xmlWriter->startElement('kosztorys');
  648. $xmlWriter->startElement('projekt');
  649. $xmlWriter->writeAttribute('id', $idProject);
  650. $xmlWriter->startElement('projekt');
  651. $xmlWriter->text("TODO L." . __LINE__);
  652. $xmlWriter->endElement();
  653. $xmlWriter->endElement();
  654. $xmlWriter->endElement();
  655. }
  656. // $memXmlWriter = new XMLWriter();
  657. // $memXmlWriter->openMemory();
  658. // $memXmlWriter->setIndent(true);
  659. //
  660. // for ($i = 1; $i <= 10; $i++) {
  661. // $idProject += 1;
  662. // $schema = ProjectKosztorysSchema::getSchema();
  663. // $data = $this->_fetchKosztorysData($idProject);
  664. //
  665. // $memXmlWriter->startElement('kosztorys');
  666. // $memXmlWriter->writeAttribute('id', $idProject);
  667. // $memXmlWriter->writeAttributeNS('p5', 'typeName', 'https://biuro.biall-net.pl/wfs', 'Kosztorys');
  668. // $memXmlWriter->text('book_'.$i);
  669. // $memXmlWriter->endElement();
  670. //
  671. // if ($i % 5 == 0) {
  672. // $batchXmlString = $memXmlWriter->outputMemory(true);
  673. // $xmlWriter->writeRaw($batchXmlString);
  674. // }
  675. // }
  676. // $memXmlWriter->flush();
  677. // unset($memXmlWriter);
  678. $xmlWriter->endElement();
  679. $xmlWriter->endDocument();
  680. }
  681. */
  682. }
  683. public function panel($idProject, $idCompany = 0) {
  684. if (User::get('ADM_ADMIN_LEVEL') > 6 || 'Pracownik' != User::getType()) return;// Only for workers with admin level < 6
  685. if (1 == V::get('_print', '', $_GET)) return;// print mode
  686. $task = V::get('_task', '', $_GET);
  687. ?>
  688. <div class="jumbotron">
  689. <div class="container">
  690. <div class="row">
  691. <div class="col-md-12">
  692. <?php if ($idProject > 0) : ?>
  693. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>">Kosztorys</a>
  694. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_print=1" target="_blank">Wydruk Kosztorysu</a>
  695. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=zestawienieSwMikRur&_print=1" target="_blank">zestawienie (światłowód i mikrorurki)</a>
  696. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=oferta">oferta</a>
  697. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=ofertaAdmin">oferta (Admin)</a>
  698. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=ofertaCompany">oferta company</a>
  699. <?php endif; ?>
  700. <a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=ofertaDefaultAdmin" target="_blank">oferta domyślna (Admin)</a>
  701. </div>
  702. </div>
  703. <br>
  704. <?php if ('ofertaAdmin' == $task) : ?>
  705. <form action="" method="get" class="form-inline">
  706. <input type="hidden" name="_route" value="UrlAction_ProjektyKosztyWstepnychRobot">
  707. <input type="hidden" name="_task" value="ofertaAdmin">
  708. <label for="ID_PROJECT">Nr projektu:</label>
  709. <input type="text" name="ID_PROJECT" value="<?php echo $idProject; ?>" class="form-control">
  710. <label for="ID_COMPANY">Nr kontrahenta (0 = oferta wewnętrzna/kosztorys)</label>
  711. <input type="text" name="ID_COMPANY" value="<?php echo $idCompany; ?>" class="form-control">
  712. <input type="submit" value="Wybierz" class="btn btn-primary">
  713. </form>
  714. <?php elseif ('oferta' == $task || 'ofertaDefaultAdmin' == $task) : ?>
  715. <form action="" method="get" class="form-inline">
  716. <input type="hidden" name="_route" value="UrlAction_ProjektyKosztyWstepnychRobot">
  717. <input type="hidden" name="_task" value="oferta">
  718. <input type="hidden" name="ID_PROJECT" value="<?php echo $idProject; ?>">
  719. <label for="ID_COMPANY">Nr kontrahenta</label>
  720. <input type="text" name="ID_COMPANY" value="<?php echo $idCompany; ?>" class="form-control">
  721. <input type="submit" value="Wybierz" class="btn btn-primary">
  722. </form>
  723. <?php endif; ?>
  724. </div>
  725. </div>
  726. <?php
  727. }
  728. public function saveOffer($idProject, $idCompany, $args, $admin = false) {
  729. DBG::_('DBG', '>1', "args", $args, __CLASS__, __FUNCTION__, __LINE__);
  730. if (!$admin) return;
  731. $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
  732. DBG::_('DBG', '>1', "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__);
  733. $pdo = DB::getPDO();
  734. {
  735. $add_id_zasob = 0;
  736. $add_unit = '';
  737. $add_price = 0;
  738. $add_quantity = 0;
  739. $add__sth = $pdo->prepare("
  740. insert into CRM_LISTA_ZASOBOW_OFFERS (
  741. CRM_LISTA_ZASOBOW_ID
  742. , COMPANIES_ID
  743. , ID_PROJECT
  744. , OFFER_PRICE_PER_RESOURCE_UNIT
  745. , RESOURCE_UNIT_TYPE
  746. , OFFER_UNIT_TYPE
  747. , REQUIRED_RESOURCE_UNITS
  748. , A_RECORD_CREATE_AUTHOR
  749. , A_RECORD_CREATE_DATE
  750. ) values (
  751. :id_zasob
  752. , :id_company
  753. , :id_project
  754. , :price
  755. , :unit
  756. , :unit
  757. , :quantity
  758. , :author
  759. , NOW()
  760. )
  761. ");
  762. $add__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR);
  763. $add__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
  764. $add__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
  765. $add__sth->bindValue(':quantity', $add_quantity, PDO::PARAM_STR);
  766. $add__sth->bindParam(':id_zasob', $add_id_zasob, PDO::PARAM_INT);
  767. $add__sth->bindParam(':price', $add_price, PDO::PARAM_STR);
  768. $add__sth->bindParam(':unit', $add_unit, PDO::PARAM_STR);
  769. }
  770. {
  771. $edit_id_company = $idCompany;
  772. $edit_id_zasob = 0;
  773. $edit_unit = '';
  774. $edit_price = 0;
  775. $edit_author = 0;
  776. $edit_quantity = 0;
  777. $edit__sth = $pdo->prepare("
  778. update CRM_LISTA_ZASOBOW_OFFERS
  779. set CRM_LISTA_ZASOBOW_ID = :id_zasob
  780. , COMPANIES_ID = :id_company
  781. , ID_PROJECT = :id_project
  782. , OFFER_PRICE_PER_RESOURCE_UNIT = :price
  783. , RESOURCE_UNIT_TYPE = :unit
  784. , OFFER_UNIT_TYPE = :unit
  785. , REQUIRED_RESOURCE_UNITS = :quantity
  786. , A_RECORD_UPDATE_AUTHOR = :author
  787. , A_RECORD_UPDATE_DATE = NOW()
  788. where ID = :id
  789. ");
  790. $edit__sth->bindParam(':id', $edit_id, PDO::PARAM_INT);
  791. $edit__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR);
  792. $edit__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
  793. $edit__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
  794. $edit__sth->bindValue(':quantity', $edit_quantity, PDO::PARAM_STR);
  795. $edit__sth->bindParam(':id_zasob', $edit_id_zasob, PDO::PARAM_INT);
  796. $edit__sth->bindParam(':price', $edit_price, PDO::PARAM_STR);
  797. $edit__sth->bindParam(':unit', $edit_unit, PDO::PARAM_STR);
  798. }
  799. $schema = ProjectKosztorysSchema::getSchema();
  800. foreach ($schema['config']['layer'] as $idLayer => $layData) {
  801. DBG::_('DBG', '>1', "layData", $layData, __CLASS__, __FUNCTION__, __LINE__);
  802. foreach ($layData['type'] as $idType => $typeLabel) {
  803. $edit_id = V::get("edit_price_id_{$idType}", '', $args);
  804. $add_price = V::get("price_{$idType}", '', $args);
  805. DBG::_('DBG', '>1', "typeLabel (edit={$edit_id}, price={$add_price})", $typeLabel, __CLASS__, __FUNCTION__, __LINE__);
  806. if ($edit_id > 0) {
  807. $edit_price = V::get("price_{$idType}", '', $args);
  808. $edit_price = str_replace(',', '.', $edit_price);
  809. if ($edit_id > 0 && $edit_price > 0) {
  810. $edit_id_zasob = $idType;
  811. $edit_unit = $layData['jednostka'];
  812. // TODO: check if anything change
  813. DBG::_('DBG', '>1', "EDIT price for idZasob({$idType}) {price:{$edit_price}, id_offer:{$edit_id}}", $typeLabel, __CLASS__, __FUNCTION__, __LINE__);
  814. $edit__sth->execute();
  815. // TODO: add to hist
  816. }
  817. } else {
  818. $add_price = V::get("price_{$idType}", '', $args);
  819. $add_price = str_replace(',', '.', $add_price);
  820. if ($add_price > 0) {
  821. $add_id_zasob = $idType;
  822. $add_unit = $layData['jednostka'];
  823. DBG::_('DBG', '>1', "ADD price for idZasob({$idType}) {price:{$add_price}}", $typeLabel, __CLASS__, __FUNCTION__, __LINE__);
  824. $add__sth->execute();
  825. }
  826. }
  827. }
  828. }
  829. }
  830. public function saveDefaultOffer($args) {
  831. DBG::_('DBG', '>1', "args", $args, __CLASS__, __FUNCTION__, __LINE__);
  832. $cennik = ProjectKosztorysCennik::getDefaultCennik();
  833. DBG::_('DBG', '>1', "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__);
  834. $idCompany = 0;
  835. $idProject = 0;
  836. $pdo = DB::getPDO();
  837. {
  838. $add_id_zasob = 0;
  839. $add_unit = '';
  840. $add_price = 0;
  841. $add_quantity = 0;
  842. $add__sth = $pdo->prepare("
  843. insert into CRM_LISTA_ZASOBOW_OFFERS (
  844. CRM_LISTA_ZASOBOW_ID
  845. , COMPANIES_ID
  846. , ID_PROJECT
  847. , OFFER_PRICE_PER_RESOURCE_UNIT
  848. , RESOURCE_UNIT_TYPE
  849. , OFFER_UNIT_TYPE
  850. , REQUIRED_RESOURCE_UNITS
  851. , A_RECORD_CREATE_AUTHOR
  852. , A_RECORD_CREATE_DATE
  853. ) values (
  854. :id_zasob
  855. , :id_company
  856. , :id_project
  857. , :price
  858. , :unit
  859. , :unit
  860. , :quantity
  861. , :author
  862. , NOW()
  863. )
  864. ");
  865. $add__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR);
  866. $add__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
  867. $add__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
  868. $add__sth->bindValue(':quantity', $add_quantity, PDO::PARAM_STR);
  869. $add__sth->bindParam(':id_zasob', $add_id_zasob, PDO::PARAM_INT);
  870. $add__sth->bindParam(':price', $add_price, PDO::PARAM_STR);
  871. $add__sth->bindParam(':unit', $add_unit, PDO::PARAM_STR);
  872. }
  873. {
  874. $edit_id_zasob = 0;
  875. $edit_unit = '';
  876. $edit_price = 0;
  877. $edit_author = 0;
  878. $edit_quantity = 0;
  879. $edit__sth = $pdo->prepare("
  880. update CRM_LISTA_ZASOBOW_OFFERS
  881. set CRM_LISTA_ZASOBOW_ID = :id_zasob
  882. , COMPANIES_ID = :id_company
  883. , ID_PROJECT = :id_project
  884. , OFFER_PRICE_PER_RESOURCE_UNIT = :price
  885. , RESOURCE_UNIT_TYPE = :unit
  886. , OFFER_UNIT_TYPE = :unit
  887. , REQUIRED_RESOURCE_UNITS = :quantity
  888. , A_RECORD_UPDATE_AUTHOR = :author
  889. , A_RECORD_UPDATE_DATE = NOW()
  890. where ID = :id
  891. ");
  892. $edit__sth->bindParam(':id', $edit_id, PDO::PARAM_INT);
  893. $edit__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR);
  894. $edit__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
  895. $edit__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
  896. $edit__sth->bindValue(':quantity', $edit_quantity, PDO::PARAM_STR);
  897. $edit__sth->bindParam(':id_zasob', $edit_id_zasob, PDO::PARAM_INT);
  898. $edit__sth->bindParam(':price', $edit_price, PDO::PARAM_STR);
  899. $edit__sth->bindParam(':unit', $edit_unit, PDO::PARAM_STR);
  900. }
  901. $schema = ProjectKosztorysSchema::getSchema();
  902. foreach ($schema['config']['layer'] as $idLayer => $layData) {
  903. DBG::_('DBG', '>1', "layData", $layData, __CLASS__, __FUNCTION__, __LINE__);
  904. foreach ($layData['type'] as $idType => $typeLabel) {
  905. DBG::_('DBG', '>1', "typeLabel", $typeLabel, __CLASS__, __FUNCTION__, __LINE__);
  906. $edit_id = V::get("edit_price_id_{$idType}", '', $args);
  907. if ($edit_id > 0) {
  908. $edit_price = V::get("price_{$idType}", '', $args);
  909. $edit_price = str_replace(',', '.', $edit_price);
  910. if ($edit_id > 0 && $edit_price > 0) {
  911. $edit_id_zasob = $idType;
  912. $edit_unit = $layData['jednostka'];
  913. // TODO: check if anything change
  914. $edit__sth->execute();
  915. // TODO: add to hist
  916. }
  917. } else {
  918. $add_price = V::get("price_{$idType}", '', $args);
  919. $add_price = str_replace(',', '.', $add_price);
  920. if ($add_price > 0) {
  921. $add_id_zasob = $idType;
  922. $add_unit = $layData['jednostka'];
  923. $add__sth->execute();
  924. }
  925. }
  926. }
  927. }
  928. }
  929. public function defaultOferta($idCompany = 0) {
  930. if ('1' == V::get('save_offer', '', $_POST)) {
  931. $this->saveDefaultOffer($_POST);
  932. }
  933. $schema = ProjectKosztorysSchema::getSchema();
  934. if (empty($schema['config']['type'])) throw new Exception("Schema error - brak zdefiniowanych typów");
  935. $cennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
  936. //DBG::_(true, true, "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__);
  937. ?>
  938. <div class="container">
  939. <form action="" method="post">
  940. <?php foreach ($schema['config']['layer'] as $idLayer => $layData) : ?>
  941. <h4 style="padding:0 6px"><?php echo $layData['label']; ?></h4>
  942. <table class="tabel table-bordered" style="width:100%">
  943. <tbody>
  944. <tr>
  945. <th style="padding:0 6px">id zasobu</th>
  946. <th style="padding:0 6px">typ</th>
  947. <th style="padding:0 6px">jednostka miary</th>
  948. <th style="padding:0 6px">cena jednostkowa</th>
  949. </tr>
  950. <?php foreach ($layData['type'] as $idType => $typeLabel) : ?>
  951. <tr>
  952. <td style="width:100px; padding:0 6px"><?php echo $idType; ?></td>
  953. <td style="padding:0 6px" title="[<?php echo $idType; ?>] <?php echo $typeLabel; ?>"><?php echo $typeLabel; ?></td>
  954. <td style="padding:0 6px"><?php echo $layData['jednostka']; ?></td>
  955. <td style="padding:3px 6px"><input type="text" class="form-control input-sm" name="price_<?php echo $idType; ?>" value="<?php echo $cennik[$idType]['price']; ?>"/></td>
  956. </tr>
  957. <?php endforeach; ?>
  958. </tbody>
  959. </table>
  960. <?php endforeach; ?>
  961. <br>
  962. <?php foreach ($cennik as $item) : ?>
  963. <input type="hidden" name="edit_price_id_<?php echo $item['id_zasob']; ?>" value="<?php echo $item['ID']; ?>">
  964. <?php endforeach; ?>
  965. <input type="hidden" name="save_offer" value="1">
  966. <input type="submit" value="Zapisz" class="btn btn-primary">
  967. </form>
  968. </div>
  969. <?php
  970. }
  971. /**
  972. * @returns [ 'cost_total' => :numeric, 'sub_costs' => [ $id_zasob => 'price' ] ]
  973. */
  974. public function getProjectCostByCennik($idProject, $idCompany = 0) {
  975. $projCost = array();
  976. $projCost['cost_total'] = 0;
  977. $projCost['sub_costs'] = array();
  978. $defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
  979. // $defCennik = [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
  980. $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
  981. $data = $this->getData($idProject, $admin);
  982. foreach ($data['summary'] as $idLayer => $layData) {
  983. foreach ($layData['data'] as $typeData) {
  984. if (!$typeData['idType']) continue;
  985. $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : 0;
  986. $defPrice = (!empty($defCennik[$typeData['idType']]['price']))? $defCennik[$typeData['idType']]['price'] : 0;
  987. $cost = ($price > 0)? $price : $defPrice;
  988. $cost = $typeData['ilosc'] * $cost;
  989. $projCost['sub_costs'][$typeData['idType']] = $cost;
  990. $projCost['cost_total'] += $cost;
  991. }
  992. }
  993. // TODO: fetch sub costs for sub projects
  994. // $data['by_project'] = array_reduce($data['rawDataByType'], function($result, $row) {
  995. // $idProj = $row['ID_PROJECT'];
  996. // $idLayer = $row['idLayer'];
  997. // $idType = $row['idType'];
  998. // if (!array_key_exists($idProj, $result)) $result[$idProj] = array();
  999. // if (!array_key_exists($idLayer, $result)) $result[$idProj][$idLayer] = array();
  1000. // if (!array_key_exists($idType, $result[$idProj][$idLayer])) {
  1001. // $result[$idProj][$idLayer][$idType] = $row;
  1002. // } else {
  1003. // $result[$idProj][$idLayer][$idType]['ilosc'] += $row['ilosc'];
  1004. $projCost['sub_proj'] = array();
  1005. foreach ($data['by_project'] as $idSubProj => $subProjData) {
  1006. foreach ($subProjData as $idLayer => $layData) {
  1007. foreach ($layData as $idType => $typeData) {
  1008. $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : 0;
  1009. $defPrice = (!empty($defCennik[$typeData['idType']]['price']))? $defCennik[$typeData['idType']]['price'] : 0;
  1010. $cost = ($price > 0)? $price : $defPrice;
  1011. $cost = $typeData['ilosc'] * $cost;
  1012. $projCost['sub_proj'][$idSubProj][$idType] = $cost;
  1013. }
  1014. }
  1015. }
  1016. return $projCost;
  1017. }
  1018. public function getModel($idProject) {
  1019. if (array_key_exists($idProject, $this->_model)) return $this->_model[$idProject];
  1020. $this->_model[$idProject] = new ProjectKosztorysModel($idProject);
  1021. return $this->_model[$idProject];
  1022. }
  1023. public function fetchBudynki($idProject) {
  1024. return DB::getPDO()->fetchAll("
  1025. select b.*
  1026. from BUILDINGS b
  1027. where b.ID_PROJECT = '{$idProject}'
  1028. ");
  1029. }
  1030. public function fetchProject($idProject) {
  1031. $rows = DB::getPDO()->fetchAll("
  1032. select p.*
  1033. from IN7_MK_BAZA_DYSTRYBUCJI p
  1034. where p.ID = '{$idProject}'
  1035. ");
  1036. return reset($rows);
  1037. }
  1038. public function zestawienieSwMikRur($idProject) {
  1039. $idCompany = 0;
  1040. $admin = false;
  1041. $companyAdmin = false;
  1042. $model = $this->getModel($idProject);
  1043. //DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
  1044. $schema = ProjectKosztorysSchema::getSchema();
  1045. $projCost = $this->getProjectCostByCennik($idProject, $idCompany);
  1046. //DBG::_(true, true, "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
  1047. $viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCost');
  1048. ?>
  1049. <div class="container">
  1050. <h1></h1>
  1051. <table class="table">
  1052. <tr>
  1053. <th><?php echo $schema['nr']; ?></th>
  1054. <th><?php echo $schema['title']; ?></th>
  1055. <th><?php echo $schema['ownerName']; ?></th>
  1056. <th style="text-align:right"><?php echo $schema['cost_total']; ?></th>
  1057. </tr>
  1058. <tr>
  1059. <td><?php echo $model->idProject; ?></td>
  1060. <td><?php echo $model->title; ?></td>
  1061. <td><?php echo $model->ownerName; ?></td>
  1062. <td style="text-align:right"><?php echo number_format($projCost['cost_total'], 2, ',', ' '); ?></td>
  1063. </tr>
  1064. </table>
  1065. <?php $args = $viewLayerDataArgs;
  1066. $idProject = $args['idProject'];
  1067. $idCompany = V::get('idCompany', 0, $args);
  1068. $admin = V::get('admin', false, $args);
  1069. $companyAdmin = V::get('companyAdmin', false, $args);
  1070. $projCosts = V::get('projCosts', array(), $args);
  1071. $schema = ProjectKosztorysSchema::getSchema();
  1072. $conf = $schema['config'];
  1073. DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
  1074. $summaryTypeCost = V::get('sub_costs', array(), $projCosts);
  1075. $subProjCost = V::get('sub_proj', array(), $projCosts);
  1076. $data = $this->getData($idProject, $admin);
  1077. $dataSummary = $data['summary'];
  1078. $dataSubProj = $data['by_project'];
  1079. // $dataSubProj = array();
  1080. // foreach ($data['by_project'] as $idSubProj => $subProjData) {
  1081. // if ($idProject != $idSubProj) $dataSubProj[$idSubProj] = $subProjData;
  1082. // }
  1083. DBG::_('DBG', '>1', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
  1084. $defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
  1085. $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
  1086. $workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
  1087. $additionalCosts = array();
  1088. $additionalCosts[] = array();
  1089. $additionalCosts[] = array();
  1090. $additionalCosts[] = array();
  1091. $additionalSummaryTypeCost = array();
  1092. ?>
  1093. <style type="text/css">
  1094. /* Print Styles */
  1095. @media print {
  1096. body { font-size:10px; }
  1097. th, td { font-size:10px; }
  1098. h1 { font-size:2em; }
  1099. h2 { font-size:1.6em; }
  1100. h3 { font-size:1.4em; }
  1101. h4 { font-size:1.2em; }
  1102. }
  1103. </style>
  1104. <?php if (!empty($dataSubProj)) : ?>
  1105. <table class="table table-bordered">
  1106. <thead>
  1107. <tr>
  1108. <th>ID PROJ.</th>
  1109. <th>ID BUDYNKU</th>
  1110. <th>WŁAŚCICIEL</th>
  1111. <th>ADRES</th>
  1112. <th>KONTAKT</th>
  1113. <th>NR DZIAŁKI</th>
  1114. <th>DŁ. ŚWIATŁOWODU</th>
  1115. <th>DŁ. MIKRORURKI DO KLIENTA</th>
  1116. </tr>
  1117. </thead>
  1118. <tbody>
  1119. <?php foreach ($dataSubProj as $idSubProj => $subProjData) : ?>
  1120. <?php
  1121. // 22460 Światłowód
  1122. // 22467 Mikrokanalizacja do klienta
  1123. $sumSwiatlo = 0;
  1124. if (!empty($subProjData[22460])) foreach ($subProjData[22460] as $swiatlo) {
  1125. $sumSwiatlo += $swiatlo['ilosc'];
  1126. }
  1127. $sumMikroRur = 0;
  1128. if (!empty($subProjData[22467])) foreach ($subProjData[22467] as $mikroRur) {
  1129. $sumMikroRur += $mikroRur['ilosc'];
  1130. }
  1131. ?>
  1132. <?php $budynki = $this->fetchBudynki($idSubProj); ?>
  1133. <?php $proj = $this->fetchProject($idSubProj); ?>
  1134. <?php if (empty($budynki)) : ?>
  1135. <tr>
  1136. <td><?php echo $idSubProj; ?></td>
  1137. <td>brak</td>
  1138. <td><?php echo $proj['IN_NAME']; ?></td>
  1139. <td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
  1140. <td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
  1141. <td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
  1142. <td><?php echo $sumSwiatlo; ?></td>
  1143. <td><?php echo $sumMikroRur; ?></td>
  1144. </tr>
  1145. <?php else : ?>
  1146. <?php foreach ($budynki as $bud) : ?>
  1147. <tr>
  1148. <td><?php echo $idSubProj; ?></td>
  1149. <td><?php echo $bud['ID']; ?></td>
  1150. <td><?php echo $proj['IN_NAME']; ?></td>
  1151. <td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
  1152. <td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
  1153. <td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
  1154. <td><?php echo $sumSwiatlo; ?></td>
  1155. <td><?php echo $sumMikroRur; ?></td>
  1156. </tr>
  1157. <?php endforeach; ?>
  1158. <?php endif; ?>
  1159. <?php endforeach; ?>
  1160. </tbody>
  1161. </table>
  1162. <?php endif; ?>
  1163. <?php
  1164. DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
  1165. DBG::_('DBG', '>0', "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
  1166. }
  1167. public function kosztorys($idProject) {
  1168. $idCompany = 0;
  1169. $admin = false;
  1170. $companyAdmin = false;
  1171. $model = $this->getModel($idProject);
  1172. //DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
  1173. $schema = ProjectKosztorysSchema::getSchema();
  1174. $projCost = $this->getProjectCostByCennik($idProject, $idCompany);
  1175. //DBG::_(true, true, "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
  1176. $viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCost');
  1177. ?>
  1178. <div class="container">
  1179. <h1>Kosztorys wstępny robót telekomunikacyjnych</h1>
  1180. <table class="table">
  1181. <tr>
  1182. <th><?php echo $schema['nr']; ?></th>
  1183. <th><?php echo $schema['title']; ?></th>
  1184. <th><?php echo $schema['ownerName']; ?></th>
  1185. <th style="text-align:right"><?php echo $schema['cost_total']; ?></th>
  1186. </tr>
  1187. <tr>
  1188. <td><?php echo $model->idProject; ?></td>
  1189. <td><?php echo $model->title; ?></td>
  1190. <td><?php echo $model->ownerName; ?></td>
  1191. <td style="text-align:right"><?php echo number_format($projCost['cost_total'], 2, ',', ' '); ?></td>
  1192. </tr>
  1193. </table>
  1194. <?php $this->viewLayersData($viewLayerDataArgs); ?>
  1195. </div>
  1196. <?php
  1197. DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
  1198. DBG::_('DBG', '>0', "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
  1199. }
  1200. public function oferta($args) {
  1201. $idProject = $args['idProject'];
  1202. $idCompany = V::get('idCompany', 0, $args);
  1203. $admin = V::get('admin', false, $args);
  1204. $companyAdmin = V::get('companyAdmin', false, $args);
  1205. if ($admin && '1' == V::get('save_offer', '', $_POST)) {
  1206. $this->saveOffer($idProject, $idCompany, $_POST, $admin);
  1207. }
  1208. $defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
  1209. $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
  1210. $viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin');
  1211. ?>
  1212. <div class="container">
  1213. <?php if ($admin) : ?>
  1214. <form action="" method="post">
  1215. <?php endif; ?>
  1216. <?php $this->viewLayersData($viewLayerDataArgs); ?>
  1217. <?php if ($admin || $companyAdmin) : ?>
  1218. <?php foreach ($cennik as $item) : ?>
  1219. <input type="hidden" name="edit_price_id_<?php echo $item['id_zasob']; ?>" value="<?php echo $item['ID']; ?>">
  1220. <?php endforeach; ?>
  1221. <input type="hidden" name="save_offer" value="1">
  1222. <hr><input class="btn btn-primary" type="submit" value="Zapisz ofertę">
  1223. </form>
  1224. <?php endif; ?>
  1225. </div>
  1226. <?php
  1227. }
  1228. public function viewLayersData($args) {
  1229. $idProject = $args['idProject'];
  1230. $idCompany = V::get('idCompany', 0, $args);
  1231. $admin = V::get('admin', false, $args);
  1232. $companyAdmin = V::get('companyAdmin', false, $args);
  1233. $projCosts = V::get('projCosts', array(), $args);
  1234. $schema = ProjectKosztorysSchema::getSchema();
  1235. $conf = $schema['config'];
  1236. DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
  1237. $summaryTypeCost = V::get('sub_costs', array(), $projCosts);
  1238. $subProjCost = V::get('sub_proj', array(), $projCosts);
  1239. $data = $this->getData($idProject, $admin);
  1240. $dataSummary = $data['summary'];
  1241. $dataSubProj = $data['by_project'];
  1242. // $dataSubProj = array();
  1243. // foreach ($data['by_project'] as $idSubProj => $subProjData) {
  1244. // if ($idProject != $idSubProj) $dataSubProj[$idSubProj] = $subProjData;
  1245. // }
  1246. DBG::_('DBG', '>1', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
  1247. $defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
  1248. $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
  1249. $workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
  1250. $additionalCosts = array();
  1251. $additionalCosts[] = array();
  1252. $additionalCosts[] = array();
  1253. $additionalCosts[] = array();
  1254. $additionalSummaryTypeCost = array();
  1255. ?>
  1256. <style type="text/css">
  1257. /* Print Styles */
  1258. @media print {
  1259. body { font-size:10px; }
  1260. th, td { font-size:10px; }
  1261. h1 { font-size:2em; }
  1262. h2 { font-size:1.6em; }
  1263. h3 { font-size:1.4em; }
  1264. h4 { font-size:1.2em; }
  1265. }
  1266. </style>
  1267. <?php $tblCols = 6 + ($admin ? 1 : 0) + ((!empty($summaryTypeCost))? 1 : 0); ?>
  1268. <table class="tabel table-bordered" style="width:100%; margin-bottom:6px; page-break-inside:avoid">
  1269. <tbody>
  1270. <?php foreach ($dataSummary as $idLayer => $layData) : ?>
  1271. <tr>
  1272. <td colspan="<?php echo $tblCols; ?>" style="padding:0 6px; font-size:1.2em; line-height:2em; font-style:italic"><?php echo $layData['label']; ?></td>
  1273. </tr>
  1274. <tr>
  1275. <td style="padding:0 6px">typ</td>
  1276. <td style="width:60px; padding:0 6px; text-align:right">ilość</td>
  1277. <td style="width:80px; padding:0 6px; text-align:right">jednostka</td>
  1278. <td style="padding:0 6px; text-align:right">cena jednostkowa</td>
  1279. <td style="padding:0 6px; text-align:right">cena jedn. (robocizna)</td>
  1280. <?php if ($admin) : ?>
  1281. <td style="padding:0 6px; text-align:right">cena jedn. (domyślna)</td>
  1282. <?php endif; ?>
  1283. <?php if (!empty($summaryTypeCost)) : ?>
  1284. <td style="padding:0 6px; text-align:right">szacowany koszt [zł]</td>
  1285. <?php endif; ?>
  1286. <td style="padding:0 6px; text-align:right">uwagi</td>
  1287. </tr>
  1288. <?php foreach ($layData['data'] as $typeData) : ?>
  1289. <?php if (!$typeData['idType']) : ?>
  1290. <tr>
  1291. <td colspan="4">
  1292. <?php if ($admin) {
  1293. $fixLink = 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' . $conf['layer'][$idLayer]['tabela_id'];
  1294. $fixLink .= '&f_' . $conf['layer'][$idLayer]['zasob_field'] . '=%3D' . $typeData['type'];
  1295. $fixLink .= '&_hash=' . uniqid();
  1296. $fixProjectLink = '<a target="_blank" href="' . $fixLink . "&f_ID_PROJECT={$idProject}" . '">' . "Popraw" . '</a>' . " (dane dla projektu [{$idProject}])";
  1297. $fixAllLink = '<a target="_blank" href="' . $fixLink . '">' . "Popraw wszystkie" . '</a>';
  1298. SE_Layout::alert('danger', "Niezdefiniowany typ: <code>{$typeData['type']}</code> - {$fixProjectLink}, {$fixAllLink}");
  1299. } ?>
  1300. <?php DBG::_('DBG', '>1', "Error conf", $conf, __CLASS__, __FUNCTION__, __LINE__); ?>
  1301. <?php DBG::_('DBG', '>1', "Error", $typeData, __CLASS__, __FUNCTION__, __LINE__); ?>
  1302. </td>
  1303. </tr>
  1304. <?php else : ?>
  1305. <?php $idType = $typeData['idType']; ?>
  1306. <?php $defPrice = (!empty($defCennik[$idType]['price']))? $defCennik[$idType]['price'] : 0; ?>
  1307. <?php $price = (!empty($cennik[$idType]['price']))? $cennik[$idType]['price'] : $defPrice; ?>
  1308. <?php $workPrice = (!empty($workCennik[$idType]['price']))? $workCennik[$idType]['price'] : 0; ?>
  1309. <?php $uwagi = (!empty($cennik[$idType]['notes']))? $cennik[$idType]['notes'] : '';// TODO: uwagi ?>
  1310. <tr>
  1311. <td style="padding:0 6px" title="[<?php echo $idType; ?>] <?php echo $typeData['type']; ?>"> - <?php echo $typeData['type']; ?></td>
  1312. <td style="padding:0 6px; text-align:right"><?php echo $typeData['ilosc']; ?></td>
  1313. <td style="padding:0 6px; text-align:right"><?php echo ProjectKosztorysSchema::getLayerJednostka($idLayer); ?></td>
  1314. <td style="padding:3px 6px; text-align:right">
  1315. <?php if ($admin || $companyAdmin) : ?>
  1316. <input type="text" style="text-align:right" class="form-control input-sm" name="price_<?php echo $idType; ?>" value="<?php echo $price; ?>"/>
  1317. <?php else : ?>
  1318. <?php echo number_format($price, 2, ',', ' '); ?>
  1319. <?php endif; ?>
  1320. </td>
  1321. <td style="padding:3px 6px; text-align:right">
  1322. <?php if ($admin || $companyAdmin) : ?>
  1323. <input type="text" style="text-align:right" class="form-control input-sm" name="work_price_<?php echo $idType; ?>" value="<?php echo $workPrice; ?>"/>
  1324. <?php else : ?>
  1325. <?php echo number_format($workPrice, 2, ',', ' '); ?>
  1326. <?php endif; ?>
  1327. </td>
  1328. <?php if ($admin) : ?>
  1329. <td style="padding:3px 6px; text-align:right"><?php echo $defPrice; ?></td>
  1330. <?php endif; ?>
  1331. <?php if (!empty($summaryTypeCost)) : ?>
  1332. <td style="padding:3px 6px; text-align:right"><?php echo number_format(V::get($idType, 0, $summaryTypeCost), 2, ',', ' '); ?></td>
  1333. <?php endif; ?>
  1334. <td style="padding:3px 6px; text-align:right">
  1335. <?php if ($admin || $companyAdmin) : ?>
  1336. <input type="text" style="text-align:left" class="form-control input-sm" name="uwagi_<?php echo $idType; ?>" value="<?php echo $uwagi; ?>"/>
  1337. <?php else : ?>
  1338. <?php echo $uwagi; ?>
  1339. <?php endif; ?>
  1340. </td>
  1341. </tr>
  1342. <?php endif; ?>
  1343. <?php endforeach; ?>
  1344. <?php endforeach; ?>
  1345. <?php if (!empty($additionalCosts)) : ?>
  1346. <tr>
  1347. <td colspan="<?php echo $tblCols; ?>" style="padding:0 6px; font-size:1.2em; line-height:2em; font-style:italic">Koszty dodatkowe</td>
  1348. </tr>
  1349. <tr>
  1350. <td style="padding:0 6px">typ</td>
  1351. <td style="width:60px; padding:0 6px; text-align:right">ilość</td>
  1352. <td style="width:80px; padding:0 6px; text-align:right">jednostka</td>
  1353. <td style="padding:0 6px; text-align:right">cena jednostkowa</td>
  1354. <td style="padding:0 6px; text-align:right">cena jedn. (robocizna)</td>
  1355. <?php if ($admin) : ?>
  1356. <td style="padding:0 6px; text-align:right">cena jedn. (domyślna)</td>
  1357. <?php endif; ?>
  1358. <?php if (!empty($summaryTypeCost)) : ?>
  1359. <td style="padding:0 6px; text-align:right">szacowany koszt [zł]</td>
  1360. <?php endif; ?>
  1361. <td style="padding:0 6px; text-align:right">uwagi</td>
  1362. </tr>
  1363. <?php foreach ($additionalCosts as $idType => $additionalCost) : ?>
  1364. <?php $additionalPrice = 0;//TODO: get from $additionalCennik or $additionalCost ?>
  1365. <?php $additionalWorkPrice = 0;//TODO: get from $additionalWorkCennik or $additionalCost ?>
  1366. <?php $additionalCount = 0;//TODO: fetch ?>
  1367. <?php $additionalUnit = '';//TODO: fetch ?>
  1368. <?php $jednostka = '';//TODO: fetch ?>
  1369. <?php $ilosc = '';//TODO: fetch ?>
  1370. <?php $typeLabel = '';//TODO: fetch ?>
  1371. <?php $price = 0;//TODO: fetch ?>
  1372. <?php $defPrice = 0;//TODO: fetch ?>
  1373. <?php $workPrice = 0;//TODO: fetch ?>
  1374. <?php $uwagi = '';//TODO: fetch ?>
  1375. <tr>
  1376. <td style="padding:0 6px" >
  1377. <?php if ($admin || $companyAdmin) : ?>
  1378. <input type="text" style="text-align:right" class="form-control input-sm" name="additional_label_<?php echo $idType; ?>" value="<?php echo $typeLabel; ?>"/>
  1379. <?php else : ?>
  1380. - <?php echo $typeLabel; ?>
  1381. <?php endif; ?>
  1382. </td>
  1383. <td style="padding:0 6px; text-align:right">
  1384. <?php if ($admin || $companyAdmin) : ?>
  1385. <input type="text" style="text-align:right" class="form-control input-sm" name="additional_count_<?php echo $idType; ?>" value="<?php echo $additionalCount; ?>"/>
  1386. <?php else : ?>
  1387. <?php echo $ilosc; ?>
  1388. <?php endif; ?>
  1389. </td>
  1390. <td style="padding:0 6px; text-align:right">
  1391. <?php if ($admin || $companyAdmin) : ?>
  1392. <input type="text" style="text-align:right" class="form-control input-sm" name="additional_unit_<?php echo $idType; ?>" value="<?php echo $additionalUnit; ?>"/>
  1393. <?php else : ?>
  1394. <?php echo $jednostka; ?>
  1395. <?php endif; ?>
  1396. </td>
  1397. <td style="padding:3px 6px; text-align:right">
  1398. <?php if ($admin || $companyAdmin) : ?>
  1399. <input type="text" style="text-align:right" class="form-control input-sm" name="additional_price_<?php echo $idType; ?>" value="<?php echo $additionalPrice; ?>"/>
  1400. <?php else : ?>
  1401. <?php echo number_format($price, 2, ',', ' '); ?>
  1402. <?php endif; ?>
  1403. </td>
  1404. <td style="padding:3px 6px; text-align:right">
  1405. <?php if ($admin || $companyAdmin) : ?>
  1406. <input type="text" style="text-align:right" class="form-control input-sm" name="additional_work_price_<?php echo $idType; ?>" value="<?php echo $additionalWorkPrice; ?>"/>
  1407. <?php else : ?>
  1408. <?php echo number_format($workPrice, 2, ',', ' '); ?>
  1409. <?php endif; ?>
  1410. </td>
  1411. <?php if ($admin) : ?>
  1412. <td style="padding:3px 6px; text-align:right"></td>
  1413. <?php endif; ?>
  1414. <?php if (!empty($additionalSummaryTypeCost)) : ?>
  1415. <td style="padding:3px 6px; text-align:right"><?php echo number_format(V::get($idType, 0, $additionalSummaryTypeCost), 2, ',', ' '); ?></td>
  1416. <?php endif; ?>
  1417. <td style="padding:3px 6px; text-align:right">
  1418. <?php if ($admin || $companyAdmin) : ?>
  1419. <input type="text" style="text-align:left" class="form-control input-sm" name="additional_uwagi_<?php echo $idType; ?>" value="<?php echo $uwagi; ?>"/>
  1420. <?php else : ?>
  1421. <?php echo $uwagi; ?>
  1422. <?php endif; ?>
  1423. </td>
  1424. </tr>
  1425. <?php endforeach; ?>
  1426. <?php endif; ?>
  1427. </tbody>
  1428. </table>
  1429. <?php $tblCols = 4 + ($admin ? 1 : 0) + ((!empty($summaryTypeCost))? 1 : 0); ?>
  1430. <?php if (!empty($dataSubProj)) : ?>
  1431. <p style="page-break-before:always; margin-top:60px"></p>
  1432. <h3>Składowe wg projektów podrzędnych:</h3>
  1433. <?php foreach ($dataSubProj as $idSubProj => $subProjData) : ?>
  1434. <table class="tabel table-bordered" style="width:100%; margin-bottom:6px; page-break-inside:avoid">
  1435. <tbody>
  1436. <tr>
  1437. <th colspan="<?php echo $tblCols; ?>"
  1438. style="padding:0 6px">
  1439. <h4>Projekt <?php echo $idSubProj; ?>: <i><?php echo $this->getModel($idProject)->getProjectName($idSubProj); ?></i>:</h4>
  1440. </th>
  1441. </tr>
  1442. <?php foreach ($subProjData as $idLayer => $layData) : ?>
  1443. <tr>
  1444. <td colspan="<?php echo $tblCols; ?>"
  1445. style="padding:0 6px; font-size:1.2em; line-height:2em; font-style:italic"><?php echo $conf['layer'][$idLayer]['label']; ?></td>
  1446. </tr>
  1447. <tr>
  1448. <td style="padding:0 6px">typ</td>
  1449. <td style="padding:0 6px; text-align:right">ilość</td>
  1450. <td style="padding:0 6px; text-align:right">jednostka</td>
  1451. <?php if ($admin) : ?>
  1452. <td style="padding:0 6px; text-align:right">cena jednostkowa</td>
  1453. <td style="padding:0 6px; text-align:right">cena jedn. (domyślna)</td>
  1454. <?php endif; ?>
  1455. <?php if (!empty($subProjCost)) : ?>
  1456. <td style="padding:0 6px; text-align:right">szacowany koszt [zł]</td>
  1457. <?php endif; ?>
  1458. </tr>
  1459. <?php foreach ($layData as $idType => $typeData) : ?>
  1460. <?php if (!$typeData['idType']) : ?>
  1461. <tr>
  1462. <td colspan="4">
  1463. <?php if ($admin) {
  1464. $fixLink = 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' . $conf['layer'][$idLayer]['tabela_id'];
  1465. $fixLink .= '&f_' . $conf['layer'][$idLayer]['zasob_field'] . '=%3D' . $typeData['type'];
  1466. $fixLink .= '&_hash=' . uniqid();
  1467. $fixProjectLink = '<a target="_blank" href="' . $fixLink . "&f_ID_PROJECT={$idProject}" . '">' . "Popraw" . '</a>' . " (dane dla projektu [{$idProject}])";
  1468. $fixAllLink = '<a target="_blank" href="' . $fixLink . '">' . "Popraw wszystkie" . '</a>';
  1469. SE_Layout::alert('danger', "Niezdefiniowany typ: <code>{$typeData['type']}</code> - {$fixProjectLink}, {$fixAllLink}");
  1470. } ?>
  1471. <?php DBG::_('DBG', '>1', "Error conf", $conf, __CLASS__, __FUNCTION__, __LINE__); ?>
  1472. <?php DBG::_('DBG', '>1', "Error", $typeData, __CLASS__, __FUNCTION__, __LINE__); ?>
  1473. </td>
  1474. </tr>
  1475. <?php else : ?>
  1476. <?php $defPrice = (!empty($defCennik[$typeData['idType']]['price']))? $defCennik[$typeData['idType']]['price'] : 0; ?>
  1477. <?php $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : $defPrice; ?>
  1478. <tr>
  1479. <td style="padding:0 6px" title="[<?php echo $typeData['idType']; ?>] <?php echo $typeData['type']; ?>"><?php echo $typeData['type']; ?></td>
  1480. <td style="padding:0 6px; text-align:right"><?php echo $typeData['ilosc']; ?></td>
  1481. <td style="padding:0 6px; text-align:right"><?php echo ProjectKosztorysSchema::getLayerJednostka($idLayer); ?></td>
  1482. <?php if ($admin) : ?>
  1483. <td style="padding:3px 6px; text-align:right">
  1484. <input type="text" style="text-align:right" class="form-control input-sm" name="price_<?php echo $typeData['idType']; ?>" value="<?php echo $price; ?>"/>
  1485. </td>
  1486. <?php endif; ?>
  1487. <?php if ($admin) : ?>
  1488. <td style="padding:3px 6px; text-align:right"><?php echo $defPrice; ?></td>
  1489. <?php endif; ?>
  1490. <?php if (!empty($subProjCost)) : ?>
  1491. <td style="padding:3px 6px; text-align:right"><?php echo number_format(V::get($typeData['idType'], 0, $subProjCost[$idSubProj]), 2, ',', ' '); ?></td>
  1492. <?php endif; ?>
  1493. </tr>
  1494. <?php endif; ?>
  1495. <?php endforeach; ?>
  1496. <?php endforeach; ?>
  1497. <?php endforeach; ?>
  1498. </tbody>
  1499. </table>
  1500. <?php endif; ?>
  1501. <?php
  1502. }
  1503. public function checkGeomDuplicate() {
  1504. // TODO: for every schema.layer
  1505. $sqlTblName = 'Rozdzielcza_Kabel_Swiatlowodowy_wsg84';
  1506. $sql = "select a.ID, b.ID, aswkt(a.the_geom)
  1507. from `{$sqlTblName}` a
  1508. join `$sqlTblName` b on(b.the_geom = a.the_geom and a.ID != b.ID)
  1509. ";
  1510. }
  1511. public function getData($idProject, $admin = 0) {
  1512. static $_data = null;
  1513. if (null === $_data) {
  1514. $idSubProject = $this->getModel($idProject)->getSubProjectIds();
  1515. if (!empty($idSubProject)) {
  1516. $idSubProject[] = $idProject;
  1517. }
  1518. $_data = $this->fetchData($idSubProject, $admin);
  1519. }
  1520. //if (!array_key_exists($idProject, $_data)) $_data[$idProject] = $this->fetchData($idProject, $admin);
  1521. //return $_data[$idProject];
  1522. return $_data;
  1523. }
  1524. public function fetchData($idProject, $admin = 0) {
  1525. $data = array();
  1526. $data['summary'] = array();// [ $idType ] = ['type', 'jednostka', 'ilosc']
  1527. $data['rawDataByType'] = array();
  1528. $schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
  1529. $conf = $schema['config'];
  1530. $pdo = DB::getPDO();
  1531. foreach ($conf['layer'] as $idLayer => $layer) {
  1532. if (!$layer['tabela_name']) continue;// TODO: throw error in validate
  1533. if ('ZASOB' == $layer['zasob_type']) {
  1534. } else if ('ZASOB_ID' == $layer['zasob_type']) {
  1535. } else {
  1536. continue;// TODO: validate config error
  1537. }
  1538. $tblName = $layer['tabela_name'];
  1539. $sqlIloscField = (!empty($layer['ilosc_field']))? $layer['ilosc_field'] : 'ID';
  1540. $sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
  1541. $sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
  1542. $sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
  1543. $sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
  1544. $sql = "
  1545. select t.{$sqlZasobField}
  1546. , t.ID_PROJECT
  1547. , {$sqlIlosc} as ilosc
  1548. from {$tblName} t
  1549. where t.ID_PROJECT in({$sqlIdProject})
  1550. and t.the_geom is not null
  1551. {$sqlGroupBy}
  1552. ";
  1553. $data['_DBG_sql'][$idLayer] = $sql;
  1554. $rawLayData = $pdo->fetchAll($sql);
  1555. $rawLayData = array_filter($rawLayData, function($row) {
  1556. return ($row['ilosc'] > 0);
  1557. });
  1558. foreach ($rawLayData as $idx => &$row) {
  1559. if ('ZASOB' == $layer['zasob_type']) {
  1560. $row['type'] = trim($row[$sqlZasobField]);
  1561. $row['idType'] = array_search($row['type'], $conf['type']);
  1562. } else if ('ZASOB_ID' == $layer['zasob_type']) {
  1563. $row['type'] = $layer['zasob_label'];
  1564. $row['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
  1565. }
  1566. $row['idLayer'] = $idLayer;
  1567. unset($row[$sqlZasobField]);
  1568. $data['rawDataByType'][] = $row;
  1569. }
  1570. }
  1571. //DBG::_(true, true, "data", $data, __CLASS__, __FUNCTION__, __LINE__);
  1572. //DBG::table("data['rawDataByType']", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
  1573. if ($admin) {
  1574. foreach ($data['rawDataByType'] as $row) {
  1575. $layer = $conf['layer'][$row['idLayer']];
  1576. if ($row['idType'] <= 0) {
  1577. SE_Layout::alert('warning', "Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}");
  1578. }
  1579. }
  1580. }
  1581. $data['rawDataByType'] = array_filter($data['rawDataByType'], function($row) {
  1582. return ($row['idType'] > 0);
  1583. });
  1584. //DBG::table("data['rawDataByType'] - clean", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
  1585. $data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) {
  1586. $idLayer = $row['idLayer'];
  1587. $idType = $row['idType'];
  1588. if (!array_key_exists($idLayer, $result)) $result[$idLayer] = array();
  1589. if (!array_key_exists($idType, $result[$idLayer])) {
  1590. $result[$idLayer][$idType] = $row;
  1591. } else {
  1592. $result[$idLayer][$idType]['ilosc'] += $row['ilosc'];
  1593. }
  1594. return $result;
  1595. }, array());
  1596. //DBG::_(true, true, "data['by_layer']", $data['by_layer'], __CLASS__, __FUNCTION__, __LINE__);
  1597. $data['summary'] = array();
  1598. foreach ($data['by_layer'] as $idLayer => $iloscByType) {
  1599. $layData = array();
  1600. $layData['label'] = $conf['layer'][$idLayer]['label'];
  1601. $layData['data'] = $iloscByType;
  1602. foreach ($layData['data'] as &$iloscData) {
  1603. $iloscData['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
  1604. }
  1605. $data['summary'][$idLayer] = $layData;
  1606. }
  1607. //DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);
  1608. $data['by_project'] = array_reduce($data['rawDataByType'], function($result, $row) {
  1609. $idProj = $row['ID_PROJECT'];
  1610. $idLayer = $row['idLayer'];
  1611. $idType = $row['idType'];
  1612. if (!array_key_exists($idProj, $result)) $result[$idProj] = array();
  1613. if (!array_key_exists($idLayer, $result[$idProj])) $result[$idProj][$idLayer] = array();
  1614. if (!array_key_exists($idType, $result[$idProj][$idLayer])) {
  1615. $result[$idProj][$idLayer][$idType] = $row;
  1616. } else {
  1617. $result[$idProj][$idLayer][$idType]['ilosc'] += $row['ilosc'];
  1618. }
  1619. return $result;
  1620. }, array());
  1621. //DBG::_(true, true, "data['by_project']", $data['by_project'], __CLASS__, __FUNCTION__, __LINE__);
  1622. return $data;
  1623. }
  1624. }