PageRenderTime 159ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/reports/custom/repstatisticaldata.php

https://github.com/web-gpambrosio/VMC
PHP | 336 lines | 291 code | 40 blank | 5 comment | 20 complexity | aeb9358155798618a9a1c75ca76eb7dd MD5 | raw file
  1. <?php
  2. include('veritas/connectdb.php');
  3. //include('connectdb.php');
  4. session_start();
  5. include('../include/stylephp.inc');
  6. $datetimenow=date("Y-m-d H:i:s");
  7. $datenow=date("Y-m-d");
  8. $datenowshow=date("d M Y");
  9. $getdoccode=$_GET["doccode"];
  10. $getvesselcode=$_GET["vesselcode"];
  11. if(empty($getvesselcode))
  12. {
  13. $wherepart="";
  14. $qrygetlist = mysql_query("
  15. SELECT VESSEL,COUNT(*) AS TOTALCREW,SUM(HASDOCS) AS TOTALDOCS
  16. FROM (
  17. SELECT * FROM (
  18. SELECT IF (c.ARRMNLDATE IS NOT NULL,'0','1') AS CREWONBOARD,c.CCID,c.APPLICANTNO,cr.CREWCODE,
  19. CONCAT(cr.FNAME,', ',cr.GNAME,' ',LEFT(cr.MNAME,1),'.') AS NAME,cr.CIVILSTATUS,cr.BIRTHDATE,
  20. r.RANKCODE,r.RANKFULL,r.RANKLEVELCODE,r.RANKING,r.ALIAS1,v.VESSEL,v.ALIAS1 AS VALIAS,
  21. IF(c.DATECHANGEDISEMB IS NULL,c.DATEDISEMB,c.DATECHANGEDISEMB) AS DATEDISEMB,c.DATEEMB,c.ARRMNLDATE,
  22. IF(DATEDIFF(CURRENT_DATE,IF(c.DATECHANGEDISEMB IS NULL,c.DATEDISEMB,c.DATECHANGEDISEMB)) > 365,1,0) AS INACTIVE,
  23. DATEDIFF(CURRENT_DATE,c.DATEEMB) AS DAYS,IF(cd.APPLICANTNO IS NULL,0,1) AS HASDOCS
  24. FROM
  25. (
  26. SELECT MAX(CCID) AS CCID,APPLICANTNO
  27. FROM
  28. (
  29. SELECT c.CCID,APPLICANTNO,IF(DATECHANGEDISEMB IS NULL,DATEDISEMB,DATECHANGEDISEMB) AS DATEDISEMB,
  30. DEPMNLDATE,ARRMNLDATE
  31. FROM crewchange c
  32. LEFT JOIN vessel v ON v.VESSELCODE=c.VESSELCODE
  33. LEFT JOIN crewpromotionrelation cpr ON cpr.CCIDPROMOTE=c.CCID
  34. WHERE EXISTS
  35. (SELECT CCID FROM crewchange x
  36. WHERE x.APPLICANTNO=c.APPLICANTNO
  37. ) AND (DEPMNLDATE IS NOT NULL OR cpr.CCID IS NOT NULL)
  38. ) x
  39. GROUP BY APPLICANTNO
  40. ORDER BY APPLICANTNO,DATEDISEMB DESC
  41. ) y
  42. LEFT JOIN crewchange c ON c.CCID=y.CCID
  43. LEFT JOIN crew cr ON cr.APPLICANTNO=c.APPLICANTNO
  44. LEFT JOIN rank r ON r.RANKCODE=c.RANKCODE
  45. LEFT JOIN vessel v ON v.VESSELCODE=c.VESSELCODE
  46. LEFT JOIN crewtransfer ct ON ct.APPLICANTNO=c.APPLICANTNO
  47. LEFT JOIN crewnfr cn ON cn.APPLICANTNO=c.APPLICANTNO
  48. LEFT JOIN crewdocstatus cd ON cd.APPLICANTNO=c.APPLICANTNO AND cd.DOCCODE='$getdoccode'
  49. WHERE cr.STATUS=1 AND ct.APPLICANTNO IS NULL AND cn.APPLICANTNO IS NULL
  50. ) z
  51. WHERE CREWONBOARD = 1 AND INACTIVE = 0
  52. ) a
  53. GROUP BY VESSEL
  54. ") or die(mysql_error());
  55. }
  56. else //SHOW ALL ONBOARD CREW
  57. {
  58. $wherepart="AND (v.VESSELCODE='$getvesselcode' OR v.DIVCODE='$getvesselcode')";
  59. $qrygetlist = mysql_query("
  60. SELECT * FROM (
  61. SELECT IF (c.ARRMNLDATE IS NOT NULL,'0','1') AS CREWONBOARD,c.CCID,c.APPLICANTNO,cr.CREWCODE,
  62. CONCAT(cr.FNAME,', ',cr.GNAME,' ',LEFT(cr.MNAME,1),'.') AS NAME,cr.CIVILSTATUS,cr.BIRTHDATE,
  63. r.RANKCODE,r.RANKFULL,r.RANKLEVELCODE,r.RANKING,r.ALIAS1,v.VESSEL,v.ALIAS1 AS VALIAS,
  64. IF(c.DATECHANGEDISEMB IS NULL,c.DATEDISEMB,c.DATECHANGEDISEMB) AS DATEDISEMB,c.DATEEMB,c.ARRMNLDATE,
  65. IF(DATEDIFF(CURRENT_DATE,IF(c.DATECHANGEDISEMB IS NULL,c.DATEDISEMB,c.DATECHANGEDISEMB)) > 365,1,0) AS INACTIVE,
  66. DATEDIFF(CURRENT_DATE,c.DATEEMB) AS DAYS,IF(cd.APPLICANTNO IS NULL,0,1) AS HASDOCS,y.CCIDPROMOTE,
  67. IF(cc.DATECHANGEDISEMB IS NULL,cc.DATEDISEMB,cc.DATECHANGEDISEMB) AS PROMOTEDATEDISEMB,cc.DATEEMB AS PROMOTEDATEEMB
  68. FROM
  69. (
  70. SELECT MAX(CCID) AS CCID,APPLICANTNO,CCIDPROMOTE
  71. FROM
  72. (
  73. SELECT c.CCID,APPLICANTNO,IF(DATECHANGEDISEMB IS NULL,DATEDISEMB,DATECHANGEDISEMB) AS DATEDISEMB,
  74. DEPMNLDATE,ARRMNLDATE,cpr.CCID AS CCIDPROMOTE
  75. FROM crewchange c
  76. LEFT JOIN vessel v ON v.VESSELCODE=c.VESSELCODE
  77. LEFT JOIN crewpromotionrelation cpr ON cpr.CCIDPROMOTE=c.CCID
  78. LEFT JOIN crewpromotionrelation cr ON cr.CCID=c.CCID
  79. WHERE (DEPMNLDATE IS NOT NULL OR cpr.CCID IS NOT NULL) AND cr.CCID IS NULL
  80. $wherepart
  81. ) x
  82. GROUP BY APPLICANTNO,CCIDPROMOTE
  83. ORDER BY APPLICANTNO,DATEDISEMB DESC
  84. ) y
  85. LEFT JOIN crewchange c ON c.CCID=y.CCID
  86. LEFT JOIN crew cr ON cr.APPLICANTNO=c.APPLICANTNO
  87. LEFT JOIN rank r ON r.RANKCODE=c.RANKCODE
  88. LEFT JOIN vessel v ON v.VESSELCODE=c.VESSELCODE
  89. LEFT JOIN crewtransfer ct ON ct.APPLICANTNO=c.APPLICANTNO
  90. LEFT JOIN crewnfr cn ON cn.APPLICANTNO=c.APPLICANTNO
  91. LEFT JOIN crewdocstatus cd ON cd.APPLICANTNO=c.APPLICANTNO AND cd.DOCCODE='$getdoccode'
  92. LEFT JOIN crewchange cc ON cc.CCID=y.CCIDPROMOTE
  93. WHERE cr.STATUS=1 AND ct.APPLICANTNO IS NULL AND cn.APPLICANTNO IS NULL
  94. ) z
  95. WHERE CREWONBOARD = 1 AND INACTIVE = 0
  96. GROUP BY APPLICANTNO
  97. ORDER BY VESSEL,RANKING
  98. ") or die(mysql_error());
  99. }
  100. $qrygetdocument=mysql_query("SELECT DOCUMENT FROM crewdocuments WHERE DOCCODE='$getdoccode'") or die(mysql_error());
  101. $rowgetdocument=mysql_fetch_array($qrygetdocument);
  102. $document=$rowgetdocument["DOCUMENT"];
  103. $tablewidth="620px;";
  104. echo "<html>\n
  105. <title>Reports - Statistical Data</title>
  106. <head>\n
  107. <link rel=\"StyleSheet\" type=\"text/css\" href=\"../veripro.css\" />
  108. <style>
  109. #noprint
  110. {
  111. display: none;
  112. }
  113. </style>
  114. <script>
  115. </script>\n
  116. </head>\n
  117. <body onload=\"\" style=\"\">\n
  118. <form name=\"scholarfasttrack\" id=\"scholarfasttrack\" method=\"POST\">\n
  119. <table cellspacing=\"0\" cellpadding=\"0\" width=\"$tablewidth\">
  120. <tr height=\"27px\">\n
  121. <td style=\"text-align:center;font-size:16pt;font-weight:bold;\">VERITAS MARITIME CORPORATION</td>\n
  122. </tr>
  123. <tr height=\"27px\">\n
  124. <td style=\"text-align:center;font-size:14pt;font-weight:bold;\">DOCUMENT: $document</td>\n
  125. </tr>
  126. <tr height=\"27px\">\n
  127. <td style=\"text-align:center;font-size:12pt;font-weight:bold;\">as of $datenowshow</td>\n
  128. </tr>
  129. </table>
  130. <br>";
  131. if(empty($getvesselcode)) //ALL VESSELS
  132. {
  133. }
  134. else //SPECIFIC VESSEL
  135. {
  136. $style = "font-size:8pt;font-family:Arial;font-weight:Bold;";
  137. $qrydocstat=mysql_query("SELECT IDNO FROM crewdocstatus
  138. WHERE DOCCODE='$getdoccode' LIMIT 1") or die(mysql_error());
  139. if(mysql_num_rows($qrydocstat)==0)
  140. $doccol="ISSUED";
  141. else
  142. $doccol="EXPIRY";
  143. echo "
  144. <table cellspacing=\"0\" cellpadding=\"0\" width=\"$tablewidth\" style=\"table-layout:fixed;\">
  145. <tr height=\"30px\" style=\"text-align:center;valign:middle;\">\n
  146. <td style=\"$style width:15px;\">&nbsp;</td>\n
  147. <td style=\"$style text-align:center;width:120px;\">Name of Seaman</td>\n
  148. <td style=\"$style text-align:center;width:30px;\">Civil Status</td>\n
  149. <td style=\"$style text-align:center;width:50px;\">Rank</td>\n
  150. <td style=\"$style text-align:center;width:50px;\">Date Birth</td>\n
  151. <td style=\"$style text-align:center;width:50px;\">DocNo</td>\n
  152. <td style=\"$style text-align:center;width:60px;\">$doccol</td>\n
  153. <td style=\"$style text-align:center;width:50px;\">Last Vsl/ Co.</td>\n
  154. <td style=\"$style text-align:center;width:50px;\">Date OB Prom.</td>\n
  155. <td style=\"$style text-align:center;width:60px;\">Date Embarked</td>\n
  156. <td style=\"$style text-align:center;width:60px;\">Date F.C.</td>\n
  157. <td style=\"$style text-align:center;width:40px;\">Months Onboard</td>\n
  158. </tr>
  159. ";
  160. $format = "dMY";
  161. $cntdata=1;
  162. $vesseltmp="";
  163. while($rowgetlist=mysql_fetch_array($qrygetlist))
  164. {
  165. $applicantno=$rowgetlist["APPLICANTNO"];
  166. $name=$rowgetlist["NAME"];
  167. $civilstatus=$rowgetlist["CIVILSTATUS"];
  168. $rank=$rowgetlist["ALIAS1"];
  169. $rankcode=$rowgetlist["RANKCODE"];
  170. $vessel=$rowgetlist["VESSEL"];
  171. $days=$rowgetlist["DAYS"];
  172. $birthdate= date($format,strtotime($rowgetlist["BIRTHDATE"]));
  173. $dateemb= date($format,strtotime($rowgetlist["DATEEMB"]));
  174. $datedisemb= date($format,strtotime($rowgetlist["DATEDISEMB"]));
  175. $ccidpromote=$rowgetlist["CCIDPROMOTE"];
  176. $promotedateemb=$rowgetlist["PROMOTEDATEEMB"];
  177. $promotedatedisemb=$rowgetlist["PROMOTEDATEDISEMB"];
  178. $months1 = round($days / 30);
  179. if($months1>0)
  180. $months=$months1;
  181. else
  182. $months=0;
  183. //get seaman's book
  184. $qryseamanbook=mysql_query("SELECT DOCNO
  185. FROM crewdocstatus
  186. WHERE APPLICANTNO=$applicantno AND DOCCODE='F2'
  187. ORDER BY DATEISSUED DESC LIMIT 1
  188. ") or die(mysql_error());
  189. $rowseamanbook=mysql_fetch_array($qryseamanbook);
  190. $seamanbook=$rowseamanbook["DOCNO"];
  191. //get passport
  192. $qrypassport=mysql_query("SELECT DOCNO
  193. FROM crewdocstatus
  194. WHERE APPLICANTNO=$applicantno AND DOCCODE='41'
  195. ORDER BY DATEISSUED DESC LIMIT 1
  196. ") or die(mysql_error());
  197. $rowpassport=mysql_fetch_array($qrypassport);
  198. $passport=$rowpassport["DOCNO"];
  199. $qrylastvessel=mysql_query("SELECT VESSEL,v.ALIAS1,IF(DATECHANGEDATE IS NULL,DATEDISEMB,DATECHANGEDATE) AS DATEDISEMB2,DISEMBREASONCODE
  200. FROM crewchange c
  201. LEFT JOIN vessel v ON c.VESSELCODE=v.VESSELCODE
  202. WHERE c.APPLICANTNO=$applicantno AND (IF(DATECHANGEDATE IS NULL,DATEDISEMB,DATECHANGEDATE)) < CURRENT_DATE AND DISEMBREASONCODE NOT IN ('PR')
  203. ORDER BY DATEDISEMB2 DESC
  204. LIMIT 1") or die(mysql_error());
  205. $rowlastvessel=mysql_fetch_array($qrylastvessel);
  206. $lastvessel=$rowlastvessel["VESSEL"];
  207. if(!empty($rowlastvessel["ALIAS1"]))
  208. $lastvesselalias=$rowlastvessel["ALIAS1"];
  209. else
  210. $lastvesselalias="&nbsp;";
  211. $style2 = "font-size:7pt;font-family:Arial;";
  212. if(!empty($ccidpromote))
  213. {
  214. $obpromote = $promotedatedisemb;
  215. $dateemb = $promotedateemb;
  216. }
  217. else
  218. $obpromote = "&nbsp;";
  219. //get docno and issued/expiry
  220. if($doccol=="EXPIRY")
  221. {
  222. $qrydocstat=mysql_query("SELECT DOCNO,DATEEXPIRED FROM crewdocstatus
  223. WHERE APPLICANTNO=$applicantno AND DOCCODE='$getdoccode'
  224. ORDER BY DATEEXPIRED DESC LIMIT 1") or die(mysql_error());
  225. if(mysql_num_rows($qrydocstat)!=0)
  226. {
  227. $rowdocstat=mysql_fetch_array($qrydocstat);
  228. $docno=$rowdocstat["DOCNO"];
  229. if (!empty($rowdocstat["DATEEXPIRED"]))
  230. $docdate=date("dMY",strtotime($rowdocstat["DATEEXPIRED"]));
  231. else
  232. $docdate="---";
  233. }
  234. else
  235. {
  236. $docno="---";
  237. $docdate="---";
  238. }
  239. }
  240. else
  241. {
  242. $qrycertstat=mysql_query("SELECT DOCNO,DATEISSUED FROM crewdocstatus
  243. WHERE APPLICANTNO=$applicantno AND DOCCODE='$getdoccode'
  244. ORDER BY DATEISSUED DESC LIMIT 1") or die(mysql_error());
  245. if(mysql_num_rows($qrycertstat)!=0)
  246. {
  247. $rowcertstat=mysql_fetch_array($qrycertstat);
  248. $docno=$rowcertstat["DOCNO"];
  249. $docdate=date("dMY",strtotime($rowcertstat["DATEISSUED"]));
  250. }
  251. else
  252. {
  253. $docno="---";
  254. $docdate="---";
  255. }
  256. }
  257. if($vesseltmp!=$vessel)
  258. {
  259. if(!empty($vesseltmp))
  260. {
  261. echo "<tr height=\"20px\" style=\"valign:middle;\"><td colspan=\"12\"><hr></td></tr>";
  262. }
  263. echo "
  264. <tr height=\"20px\" style=\"valign:middle;\">\n
  265. <td colspan=\"12\" style=\"font-size:10pt;font-family:Arial;text-align:left;\">&nbsp;&nbsp;<u>&nbsp;$vessel&nbsp;</u></td>\n
  266. </tr>";
  267. $cntdata=1;
  268. }
  269. echo "
  270. <tr height=\"20px\" style=\"valign:middle;\">\n
  271. <td style=\"$style2 text-align:left;\">$cntdata.</td>\n
  272. <td style=\"$style2 text-align:left;\" title=\"$applicantno-$getdoccode\">$name</td>\n
  273. <td style=\"$style2 text-align:center;\">$civilstatus</td>\n
  274. <td style=\"$style2 text-align:center;\">$rank</td>\n
  275. <td style=\"$style2 text-align:center;\">$birthdate</td>\n
  276. <td style=\"$style2 text-align:center;\">$docno</td>\n
  277. <td style=\"$style2 text-align:center;\">$docdate</td>\n
  278. <td style=\"$style2 text-align:center;\">$lastvesselalias</td>\n
  279. <td style=\"$style2 text-align:center;\">$obpromote</td>\n
  280. <td style=\"$style2 text-align:center;\">$dateemb</td>\n
  281. <td style=\"$style2 text-align:center;\">$datedisemb</td>\n
  282. <td style=\"$style2 text-align:center;\">$months</td>\n
  283. </tr>";
  284. $cntdata++;
  285. $vesseltmp=$vessel;
  286. }
  287. echo "
  288. </table>";
  289. }
  290. echo "
  291. </form>";
  292. include('../../include/printclose.inc');
  293. echo "
  294. </body>\n
  295. </html>\n";
  296. ?>