PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tax_watch_export_pdf(3).php

https://gitlab.com/vince.omega/PDF-PHP-Scripts
PHP | 534 lines | 395 code | 95 blank | 44 comment | 108 complexity | bda43773ce8439fe32a64d5ec21b84c1 MD5 | raw file
  1. <?php
  2. ini_set('max_execution_time', 0); //300 seconds = 5 minutes
  3. require_once('fpdf/fpdf/fpdf.php');
  4. require_once('../../header.inc.php');
  5. /**
  6. @author: Larry Stanfield
  7. PHP PDF generation script written by Larry Stanfield
  8. Contact @ vince.omega@gmail.com
  9. Powered by the open source pdf php class fpdf
  10. www.fpdf.org
  11. There you will find documentation on the use of pdf
  12. */
  13. if (!isset($_GET['custcodes']))
  14. $_GET['custcodes'] = '';
  15. if (!isset($_GET['borrower']))
  16. $_GET['borrower'] = '';
  17. if (!isset($_GET['address']))
  18. $_GET['address'] = '';
  19. if (!isset($_GET['tax_search_loan_officer_id']))
  20. $_GET['tax_search_loan_officer_id'] = '';
  21. if (!isset($_GET['loan_identifier']))
  22. $_GET['loan_identifier'] = '';
  23. if (!isset($_GET['sort_by']))
  24. $_GET['sort_by'] = '';
  25. if (!isset($_GET['limit_by_status']))
  26. $_GET['limit_by_status'] = '';
  27. if (!isset($_GET['limit_by_branch']))
  28. $_GET['limit_by_branch'] = '';
  29. if (!isset($_GET['sort_by_qrt']))
  30. $_GET['sort_by_qrt'] = '';
  31. $branch = '';
  32. $loan_officer = '';
  33. if($_GET['limit_by_branch'] == ''){
  34. $branch = 'All';
  35. } else {
  36. $branch = $_GET['limit_by_branch'];
  37. }
  38. if(is_numeric($_GET['tax_search_loan_officer_id'])){
  39. $loan_officer = $_GET['tax_search_loan_officer_id'];
  40. } else {
  41. $loan_officer = null;
  42. }
  43. //DEBUG
  44. //echo $_GET['limit_by_branch'];
  45. //exit;
  46. $today = "Produced on: ".Date('M d, Y - G:i:s');
  47. $custNBranch = "Customer: ".$_GET['custcodes']." Branch: ".$branch;
  48. $month = date('m');
  49. $year = date('Y');
  50. class PDF extends FPDF{
  51. //Page Header
  52. function Header(){
  53. global $today, $custNBranch;
  54. $this->SetFont('Helvetica', 'B', 12);
  55. //Set Title
  56. $this->Cell(250, 10, 'Results for '.$today, 0, 1, 'L');
  57. //Subject
  58. $this->Cell(250, 10, 'SearchTec - '.$custNBranch, 'B', 1, 'L');
  59. //Break Line
  60. $this->Cell(250, 10, 'Tax Watch Report' , 0, 0, 'L');
  61. $this->Ln(10);
  62. $this->SetFont('Helvetica', 'B', 10);
  63. $this->Cell(35, 10, "Loan ID/Officer", 'B', 0, 'L');
  64. $this->Cell(40, 10, "Borrower", 'B', 0, 'L');
  65. $this->Cell(43, 10, "Address", 'B', 0, 'L');
  66. $this->Cell(30, 10, "Delinquency", 'B', 0, 'L');
  67. $this->Cell(25, 10, "Cover Date", 'B', 0, 'L');
  68. $this->Cell(50, 10, "Next Run", 'B', 2, 'L');
  69. $this->SetFont('Helvetica', '', 8);
  70. $this->Ln(3);
  71. }
  72. function entry($margin, $info, $border, $spacing){
  73. $this->Cell($margin, 8, $info, $border, $spacing, 'L');
  74. }
  75. // entryAdjust will adjust the Loan ID and Borrower fields based on length or delimiter.
  76. function entryAdjust($space, $content, $bottom, $flag){
  77. $i = 0;
  78. $content = (string)$content;
  79. if(strlen($content) > 23){
  80. $conArray = array();
  81. $conArray = str_split($content, 23);
  82. $k = sizeof($conArray);
  83. foreach($conArray as $key){
  84. $i++;
  85. if($i == $k){
  86. $this->MultiCell($space + 8, 4, $key."\n", $bottom, 'L');
  87. $this->SetX(35);
  88. } else {
  89. $this->MultiCell($space, 4, $key."\n", 0, 'L');
  90. $this->SetX(35);
  91. }
  92. }
  93. if($bottom == 0){
  94. $this->Ln(-8);
  95. $this->SetX(75);
  96. } elseif($bottom == 'B') {
  97. $this->Ln(-7);
  98. $this->SetX(70);
  99. }
  100. } elseif($flag == 1) {
  101. if(strrpos($content, "/") == true){
  102. $this->SetFont('Helvetica', '', 5);
  103. $conArray = explode("/", $content);
  104. foreach($conArray as $key){
  105. $this->entry($space, $key, $bottom, 0);
  106. $this->SetX(34);
  107. }
  108. $this->SetFont('Helvetica', '', 8);
  109. }else{
  110. $this->MultiCell($space, 4, $content, 0, 'L');
  111. $this->SetFont('Helvetica', '', 8);
  112. $y = $this->GetY();
  113. $this->SetY($y - 4.2);
  114. $this->SetX(34);
  115. }
  116. }else {
  117. $this->entry($space, $content, $bottom, 0);
  118. }
  119. }
  120. function br(){
  121. $this->Ln(10);
  122. }
  123. function Footer()
  124. {
  125. $this->SetY(-15);
  126. $this->SetFont('Helvetica', 'I', 8);
  127. $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  128. }
  129. }
  130. $pdf = new PDF();
  131. $pdf->AliasNbPages();
  132. $pdf->AddPage();
  133. /*---------------------------------------------------------------------------------------------------------------------------*/
  134. //Connect to database, name file and write sql query
  135. $DB = DB::getCon();
  136. //$DB = new mysqli('StLinux1', 'root', 'pass', '', '22');
  137. $_GET['custcodes'] = $DB->cleanString($_GET['custcodes']);
  138. $_GET['borrower'] = $DB->cleanString($_GET['borrower']);
  139. $_GET['address'] = $DB->cleanString($_GET['address']);
  140. $_GET['tax_search_loan_officer_id'] = $DB->cleanString($_GET['tax_search_loan_officer_id']);
  141. $_GET['loan_identifier'] = $DB->cleanString($_GET['loan_identifier']);
  142. $_GET['sort_by'] = $DB->cleanString($_GET['sort_by']);
  143. $_GET['limit_by_status'] = $DB->cleanString($_GET['limit_by_status'] );
  144. $_GET['limit_by_branch'] = $DB->cleanString($_GET['limit_by_branch']);
  145. $_GET['sort_by_qrt'] = $DB->cleanString($_GET['sort_by_qrt']);
  146. $filename = 'c:/php_temp/download_' . preg_replace('/[^a-z0-9]/i', '_', $DB->cleanString($_GET['custcodes'])) . '.pdf';
  147. $sql = "
  148. SELECT
  149. website_userid,
  150. loan_officer,
  151. tax_search_loan_id,
  152. branch,
  153. loan_identifier,
  154. borrower,
  155. address,
  156. city,
  157. state_abbreviation,
  158. zip,
  159. delinquency_status,
  160. cover_date,
  161. next_run,
  162. notes
  163. FROM
  164. (SELECT
  165. ts.tax_search_id,
  166. ts.current_tax_search_status_id,
  167. tslo.name as loan_officer_name,
  168. IF(tsl.notes IS NULL, '', IF(tsl.notes = '', '', '*')) as has_notes,
  169. IF(tsr.tax_sales IS NULL, '', IF(tsr.tax_sales = '', '', '*')) as has_tax_sales,
  170. tsr.delinquent_date,
  171. tslo.pick_userid as website_userid,
  172. tslo.name as loan_officer,
  173. tsl.tax_search_loan_id,
  174. tsl.branch,
  175. tsl.loan_identifier,
  176. tsl.borrower,
  177. tsl.address,
  178. tsl.city,
  179. states.abbreviation as state_abbreviation,
  180. tsl.zip,
  181. tsr.delinquency_status,
  182. DATE_FORMAT(tsr.cover_date,'%m-%d-%Y') as cover_date,
  183. IF (tsl.frequency_id IS NULL, null, tsl.cycle_id) as next_run,
  184. tsl.notes
  185. FROM
  186. tax_search_loans tsl
  187. INNER JOIN
  188. tax_search_loan_officers tslo ON tsl.tax_search_loan_officer_id = tslo.tax_search_loan_officer_id
  189. LEFT JOIN
  190. states ON tsl.state_id = states.state_id
  191. LEFT JOIN
  192. tax_searches ts ON tsl.tax_search_loan_id = ts.tax_search_loan_id
  193. LEFT JOIN
  194. tax_search_results tsr ON tsr.tax_search_id = ts.tax_search_id
  195. WHERE
  196. tsl.active = 'Y' AND
  197. tslo.active = 'Y' AND
  198. (ts.active IS NULL OR ts.active = 'Y') AND
  199. (tsr.active IS NULL OR tsr.active = 'Y')
  200. ";
  201. if($_GET['limit_by_branch'] != '') {
  202. $sql .= " AND tsl.branch IN ('" .$_GET['limit_by_branch']. "' ) ";
  203. }
  204. $sql.= " AND tslo.customer_code IN ('" .$_GET['custcodes']. "')
  205. ";
  206. if ("" != $_GET['tax_search_loan_officer_id']) {
  207. $sql .= "
  208. AND tsl.tax_search_loan_officer_id = " .$loan_officer. "
  209. ";
  210. }
  211. $sql .= "
  212. ORDER BY
  213. tax_search_loan_id DESC, tax_search_id DESC, tax_search_result_id DESC
  214. ) as t1
  215. ";
  216. if($_GET['sort_by_qrt'] != "" || $_GET['limit_by_status'] != ""){
  217. $sql .= "WHERE
  218. ";
  219. }
  220. if($_GET['sort_by_qrt'] != ""){
  221. if($_GET['sort_by_qrt'] == 'march'){
  222. if(date('m') < 3 && date('m') >= 9){
  223. $sql .= " t1.next_run IN (1, 5)";
  224. }
  225. elseif(date('m') == 12 || date('m') < 3){
  226. $sql .= " t1.next_run IN (1, 7)";
  227. }
  228. else {
  229. $sql .= " t1.next_run = 1";
  230. }
  231. }
  232. if($_GET['sort_by_qrt'] == 'june'){
  233. if(date('m') < 6 || date('m') == 12){
  234. $sql .= " t1.next_run IN (2, 6)";
  235. }
  236. elseif(date('m') >= 3 && date('m') < 6){
  237. $sql .= " t1.next_run IM (2, 7)";
  238. }
  239. else {
  240. $sql .= " t1.next_run = 2";
  241. }
  242. }
  243. if($_GET['sort_by_qrt'] == 'september'){
  244. if(date('m') >= 6 && date('m') < 9){
  245. $sql .= " t1.next_run IN (3, 7)";
  246. }
  247. else {
  248. $sql .= " t1.next_run IN (3, 5)";
  249. }
  250. }
  251. if($_GET['sort_by_qrt'] == 'december'){
  252. if(date('m') > 6 && date('m') < 9){
  253. $sql .= " t1.next_run IN (4, 6)";
  254. }
  255. elseif(date('m') >= 9 && date('m') < 12){
  256. $sql .= " t1.next_run = (4, 7)";
  257. }
  258. else{
  259. $sql .= " t1.next_run = 4";
  260. }
  261. }
  262. }
  263. if ("" != $_GET['limit_by_status']) {
  264. if($_GET['sort_by_qrt'] != ""){
  265. $sql .= " AND
  266. ";
  267. }
  268. if ('current' == $_GET['limit_by_status']) {
  269. $sql .= "
  270. t1.delinquency_status = 'Current'
  271. ";
  272. } else if ('open' == $_GET['limit_by_status']) {
  273. $sql .= "
  274. t1.current_tax_search_status_id = 1
  275. ";
  276. } else if ('delinquent' == $_GET['limit_by_status']) {
  277. $sql .= "
  278. t1.delinquency_status != 'Current'
  279. ";
  280. } else {
  281. if($_GET['sort_by_qrt'] != ""){
  282. $sql .= "
  283. (t1.tax_sales IS NOT NULL
  284. AND t1.tax_sales != '')
  285. ";
  286. }
  287. else {
  288. $sql .= "
  289. t1.tax_sales IS NOT NULL
  290. AND t1.tax_sales != ''
  291. ";
  292. }
  293. }
  294. }
  295. $sql .= "
  296. GROUP BY
  297. tax_search_loan_id
  298. ORDER BY
  299. '".$_GET['sort_by']."'
  300. ";
  301. /*------------------------------------------------------------------------------------------------------------------------*/
  302. //run query, check next_run, write tables
  303. $rows = $DB->getRows($sql);
  304. if (count($rows)) {
  305. $row_cnt = count($rows);
  306. // write data from the rest of the rows
  307. for ($i=0; $i < $row_cnt; $i++) {
  308. $current_row = $rows[$i];
  309. $next_run = '[' . $current_row['next_run'] . ']';
  310. $borrower = $current_row['borrower'];
  311. $address = $current_row['address'];
  312. $loan_id = $current_row['loan_identifier'];
  313. $loan_officer = $current_row['loan_officer'];
  314. $branch = $current_row['branch'];
  315. $dStatus = $current_row['delinquency_status'];
  316. $city = $current_row['city'];
  317. $state = $current_row['state_abbreviation'];
  318. $zip = $current_row['zip'];
  319. $cover_date = $current_row['cover_date'];
  320. $notes = $current_row['notes'];
  321. $fulladdress = $address."\n".$city." ".$state." , ".$zip;
  322. $fulladdress = (string)$fulladdress;
  323. $idandofficer = $loan_id."\n".$loan_officer;
  324. $idandofficer = ltrim(rtrim((string)$idandofficer));
  325. $adjust = 0;
  326. $k = 0;
  327. $borrower = ltrim(rtrim($borrower));
  328. /*if(strlen($borrower) > 23){
  329. $conArray = array();
  330. $conArray = str_split($borrwer, 23);
  331. $k = sizeof($conArray);
  332. }
  333. */
  334. /* foreach($current_row as $key){
  335. $list = each($current_row);
  336. print_r($list);
  337. }
  338. exit; //DEBUG
  339. */
  340. if ('' != $current_row['next_run']) {
  341. switch($current_row['next_run']) {
  342. case 1:
  343. $next_run_month = 3;
  344. break;
  345. case 2:
  346. $next_run_month = 6;
  347. break;
  348. case 3:
  349. $next_run_month = 9;
  350. break;
  351. case 4:
  352. $next_run_month = 12;
  353. break;
  354. case 5:
  355. if ($month < 3 || $month >= 9) {
  356. $next_run_month = 3;
  357. } else {
  358. $next_run_month = 9;
  359. }
  360. break;
  361. case 6:
  362. if ($month < 6 || $month == 12) {
  363. $next_run_month = 6;
  364. } else {
  365. $next_run_month = 12;
  366. }
  367. break;
  368. case 7:
  369. if ($month == 12 || $month < 3) {
  370. $next_run_month = 3;
  371. } else if ($month >= 3 && $month < 6) {
  372. $next_run_month = 6;
  373. } else if ($month >= 6 && $month < 9) {
  374. $next_run_month = 9;
  375. } else if ($month >= 9 && $month < 12) {
  376. $next_run_month = 12;
  377. }
  378. break;
  379. }
  380. $next_run_year = $year;
  381. if ($next_run_month <= $month) {
  382. $next_run_year++;
  383. }
  384. $next_run = str_pad($next_run_month,2,'0',STR_PAD_LEFT) . '-' . $next_run_year;
  385. } else {
  386. $next_run = 'On Hold';
  387. }
  388. $current_row['next_run'] = $next_run;
  389. //This section loops through the query results and attempts to structure them through table rows and cells.
  390. if($notes != null){ //Checks for notes
  391. $pdf->entryAdjust(25, $idandofficer, 0, 1);
  392. $pdf->entryAdjust(40, $borrower, 0);
  393. $pdf->MultiCell(60, 4, $fulladdress, 0, 'L');
  394. $pdf->Ln(-7);
  395. $pdf->SetX(135);
  396. //$pdf->entry(60, $fulladdress, 0, 0);
  397. //$pdf->entry(5, $state, 0, 0);
  398. //$pdf->entry(25, $city, 0, 0);
  399. //$pdf->entry(15, $zip, 0, 0);
  400. if(is_numeric($dStatus)){
  401. setlocale(LC_MONETARY, 'en_US');
  402. $pdf->entry(25, "$".number_format($dStatus, 2), 0, 0);
  403. }
  404. else {
  405. $pdf->entry(25, $dStatus, 0, 0);
  406. }
  407. $pdf->entry(25, $cover_date, 0, 0);
  408. $pdf->entry(25, $next_run, 0, 0);
  409. $pdf->br();
  410. $pdf->entry(300, $notes, 'B', 1);
  411. } else {
  412. $pdf->entryAdjust(25, $idandofficer, 0, 1);
  413. $pdf->entryAdjust(40, $borrower, 0);
  414. $pdf->MultiCell(60, 4, $fulladdress, 0, 'L');
  415. $pdf->Ln(-8);
  416. $pdf->SetX(135);
  417. //$pdf->entry(60, $fulladdress, 'B', 0);
  418. //$pdf->entry(5, $state, 'B', 0);
  419. //$pdf->entry(25, $city, 'B', 0);
  420. //$pdf->entry(15, $zip, 'B', 0);
  421. if(is_numeric($dStatus)){
  422. setlocale(LC_MONETARY, 'en_US');
  423. $pdf->entry(25, "$".number_format($dStatus, 2), 0, 0);
  424. }
  425. else {
  426. $pdf->entry(25, $dStatus, 0, 0);
  427. }
  428. $pdf->entry(25, $cover_date, 0, 0);
  429. $pdf->entry(25, $next_run, 0, 1);
  430. $pdf->Cell(900, 4, "", 'B', 1, 'L');
  431. }
  432. unset($current_row);
  433. }
  434. }
  435. //exit;
  436. ob_end_clean(); //Ends buffering
  437. $pdf->Output();
  438. $pdf->Close();
  439. ?>