PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/sendCommissionSheet.php

https://bitbucket.org/OverSite/capstone-demo
PHP | 336 lines | 257 code | 65 blank | 14 comment | 2 complexity | 906f758e72d69502b33c6907f3ce9e31 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, MIT, LGPL-2.1, Apache-2.0
  1. <?php
  2. require("databaseConnection.php");
  3. // require("../keys/refreshKeyAdobe.php");
  4. require("keys/cred.php");
  5. session_start();
  6. $dbConn = getConnection();
  7. if (!isset($_SESSION['userId'])) {
  8. header("Location: index.html?error=wrong username or password");
  9. }
  10. $license = $_POST['license'];
  11. $houseListingId = $_POST['propertyAddress'];
  12. $agent = "SELECT * FROM UsersInfo WHERE license = '" . $license . "'";
  13. $name = $dbConn->prepare($agent);
  14. $name->execute();
  15. $userResults = $name->fetch();
  16. $currAgent = "SELECT * FROM UsersInfo WHERE userId = '" . $_SESSION['userId'] . "'";
  17. $email = $dbConn->prepare($currAgent);
  18. $email->execute();
  19. $currAgentEmail = $email->fetch();
  20. $sqlHouse = "SELECT * FROM HouseInfo WHERE listingId = '" . $houseListingId . "'";
  21. $stmtHouse = $dbConn->prepare($sqlHouse);
  22. $stmtHouse->execute();
  23. $houseResults = $stmtHouse->fetch();
  24. $TYGross = str_replace(",", "", (string)$_POST['TYGross']);
  25. $FYGross = str_replace(",", "", (string)$_SESSION['FYGross']);
  26. $initialGross = str_replace(",", "", (string)$_POST['InitialGross']);
  27. $netCommission = str_replace(",", "", (string)$_POST['netCommission']);
  28. $brokerFee = str_replace(",", "", (string)$_POST['brokerFee']);
  29. $miscell = str_replace(",", "", (string)$_POST['miscell']);
  30. $remaxFee = str_replace(",", "", (string)$_POST['remaxFee']);
  31. $finalHousePrice = str_replace(",", "", (string)$_POST['finalHousePrice']);
  32. $addRemaxFeeSql = "INSERT INTO remaxFee (userId, date, paid) VALUES (:userId, :date, :paid)";
  33. $remaxFeeParam = array();
  34. $remaxFeeParam[':userId'] = $_SESSION['userId'];
  35. $remaxFeeParam[':date'] = date("Y-m-d", strtotime($_POST['today-date']));
  36. $remaxFeeParam[':paid'] = (int)$remaxFee;
  37. $remaxFeeStmt = $dbConn->prepare($addRemaxFeeSql);
  38. $remaxFeeStmt->execute($remaxFeeParam);
  39. $sql = "INSERT INTO commInfo
  40. (houseId, license, firstName, lastName, date, settlementDate, checkNum, clients, address, city, state, zip, TYGross, FYGross, InitialGross, brokerFee, finalComm, remaxFee, misc, percentage, envelopeId, finalHousePrice)
  41. VALUES (:houseId, :license, :firstName, :lastName, :date, :settlementDate, :checkNum, :clients, :address, :city, :state, :zip, :TYGross, :FYGross, :InitialGross, :brokerFee, :finalComm, :remaxFee, :misc, :percentage, :envelopeId, :finalHousePrice)";
  42. $namedParameters = array();
  43. $namedParameters[":houseId"] = $houseResults['houseId'];
  44. $namedParameters[":license"] = $license;
  45. $namedParameters[":firstName"] = $userResults['firstName'];
  46. $namedParameters[":lastName"] = $userResults['lastName'];
  47. $namedParameters[":date"] = date("Y-m-d", strtotime($_POST['today-date']));
  48. $namedParameters[":settlementDate"] = date("Y-m-d", strtotime($_POST['settlementDate']));
  49. $namedParameters[":checkNum"] = $_POST['checkNum'];
  50. $namedParameters[":address"] = $houseResults['address'];
  51. $namedParameters[":city"] = $houseResults['city'];
  52. $namedParameters[":state"] = $houseResults['state'];
  53. $namedParameters[":zip"] = $houseResults['zip'];
  54. $namedParameters[":TYGross"] = (int)$TYGross + $initialGross;
  55. $namedParameters[":FYGross"] = (int)$FYGross + $netCommission;
  56. $namedParameters[":InitialGross"] = $initialGross;
  57. $namedParameters[":brokerFee"] = $brokerFee;
  58. $namedParameters[":finalComm"] = $netCommission;
  59. $namedParameters[":misc"] = $miscell;
  60. $namedParameters[":remaxFee"] = (int)$remaxFee;
  61. $namedParameters[":clients"] = $_POST['clients'];
  62. // $value = preg_replace('/[\%,]/', '', $_POST['percentage']);
  63. $value = floatval($_POST['percentage']);
  64. $namedParameters[":percentage"] = $value;
  65. $namedParameters[":finalHousePrice"] = $finalHousePrice;
  66. // str_replace(find,replace,string,count)
  67. // $stmt = $dbConn -> prepare($sql);
  68. // $stmt->execute($namedParameters);
  69. require('fpdf/fpdf.php');
  70. // $data = $_GET["agentNum"];
  71. $pdf = new FPDF();
  72. $pdf->AddPage();
  73. $pdf->SetLineWidth(.5);
  74. $pdf->Rect(5, 5, 200, 285, 'D');
  75. // $pdf->SetLineWidth(.3);
  76. // $pdf->Rect(10, 11, 97, 8, 'D');
  77. $pdf->SetFont('Times', 'B');
  78. $pdf->SetFontSize(12);
  79. $pdf->SetLineWidth(.3);
  80. $pdf->Cell(96, 10, 'RE/MAX Property Experts Commission Breakdown', 1, 0);
  81. $pdf->Cell(10, 10, '', 0, 0);
  82. $pdf->Cell(0, 10, ' Check # ' . $_POST['checkNum'], 'B', 1);
  83. $pdf->Cell(166, 10, ' Beginning Gross Check Amount: ', 0, 0);
  84. $pdf->SetFont('Times', 'U');
  85. $pdf->Cell(5, 10, '$' . number_format($TYGross, 2) . ' ', 0, 1);
  86. $pdf->SetFont('Times', 'B');
  87. $pdf->Cell(15, 10, 'Date: ', 0, 0);
  88. $pdf->SetFont('Times', 'U');
  89. $pdf->Cell(30, 10, ' ' . date("m-d-Y", strtotime($_POST['today-date'])) . ' ', 0, 1);
  90. $pdf->Cell(10, 3, '', 0, 1);
  91. $pdf->SetFont('Times', 'B');
  92. $pdf->Cell(35, 10, 'Settlement Date: ', 0, 0);
  93. $pdf->SetFont('Times', 'U');
  94. $pdf->Cell(30, 10, ' ' . date("m-d-Y", strtotime($_POST['settlementDate'])) . ' ', 0, 1);
  95. $pdf->Cell(10, 3, '', 0, 1);
  96. $pdf->SetFont('Times', 'B');
  97. $pdf->Cell(17, 10, 'Agent: ', 0, 0);
  98. $pdf->SetFont('Times', 'U');
  99. $pdf->Cell(50, 10, ' ' . $userResults['firstName'] . ' ' . $userResults['lastName'] . ' ', 0, 1);
  100. $pdf->Cell(10, 3, '', 0, 1);
  101. $pdf->SetFont('Times', 'B');
  102. $pdf->Cell(18, 10, 'Clients: ', 0, 0);
  103. $pdf->SetFont('Times', 'U');
  104. $pdf->Cell(50, 10, ' ' . $_POST['clients'] . ' ', 0, 1);
  105. $pdf->Cell(10, 3, '', 0, 1);
  106. $pdf->SetFont('Times', 'B');
  107. $pdf->Cell(37, 10, 'Property Address: ', 0, 0);
  108. $pdf->SetFont('Times', 'U');
  109. $pdf->Cell(50, 10, ' ' . $houseResults['address'] . ', ' . $houseResults['city'] . ', ' . $houseResults['state'] . ', ' . $houseResults['zip'] . ' ', 0, 1);
  110. $pdf->Cell(0, 5, ' ', 0, 1);
  111. $pdf->SetFont('Times', 'B');
  112. $pdf->Cell(69, 10, ' Gross Check Amount: ', 0, 0);
  113. $pdf->SetFont('Times', 'U');
  114. $pdf->Cell(23, 10, ' $' . number_format($initialGross, 2) . ' ', 0, 1);
  115. // $pdf->Cell(0,2,' ',0,1);
  116. $pdf->SetFont('Times', 'B');
  117. $pdf->Cell(69, 10, ' Remax/Broker Fee: ', 0, 0);
  118. $pdf->SetFont('Times', 'U');
  119. $pdf->Cell(23, 10, ' $' . number_format($brokerFee, 2) . ' ', 0, 1);
  120. $pdf->SetFont('Times', 'B');
  121. $pdf->Cell(69, 10, ' Total Fees: ', 0, 0);
  122. $pdf->SetFont('Times', 'U');
  123. $pdf->Cell(23, 10, ' $' . number_format($brokerFee, 2) . ' ', 0, 1);
  124. $pdf->SetFont('Times', 'B');
  125. $pdf->Cell(69, 10, ' Subtotal: ', 0, 0);
  126. $pdf->SetFont('Times', 'U');
  127. $pdf->Cell(23, 10, ' $' . number_format(((int)$initialGross - $brokerFee), 2) . ' ', 0, 1);
  128. $pdf->SetFont('Times', 'B');
  129. $pdf->Cell(69, 10, ' Processing Fee: ', 0, 0);
  130. $pdf->SetFont('Times', 'U');
  131. $pdf->Cell(23, 10, ' $200.00 ', 0, 1);
  132. $pdf->SetFont('Times', 'B');
  133. $pdf->Cell(69, 10, ' TC. Tech Fee: ', 0, 0);
  134. $pdf->SetFont('Times', 'U');
  135. $pdf->Cell(23, 10, ' $50.00 ', 0, 1);
  136. $pdf->SetFont('Times', 'B');
  137. $pdf->Cell(69, 10, ' E&O Insurance: ', 0, 0);
  138. $pdf->SetFont('Times', 'U');
  139. $pdf->Cell(23, 10, ' $99.00 ', 0, 1);
  140. $pdf->SetFont('Times', 'B');
  141. $pdf->Cell(69, 10, ' Remax Franchise: ', 0, 0);
  142. $pdf->SetFont('Times', 'U');
  143. $pdf->Cell(23, 10, ' $' . number_format($remaxFee, 2) . ' ', 0, 1);
  144. $pdf->SetFont('Times', 'B');
  145. $pdf->Cell(69, 10, ' Misc: ', 0, 0);
  146. $pdf->SetFont('Times', 'U');
  147. $pdf->Cell(23, 10, ' $' . number_format($miscell, 2) . ' ', 0, 1);
  148. $pdf->SetFont('Times', 'B');
  149. $pdf->Cell(69, 10, ' Agent Commission: ', 0, 0);
  150. $pdf->SetFont('Times', 'U');
  151. $pdf->Cell(23, 10, ' $' . number_format($netCommission, 2) . ' ', 0, 1);
  152. $pdf->Cell(0, 10, '', 0, 1);
  153. $pdf->SetFont('Times', 'I', 14);
  154. $pdf->Cell(7, 10, ' I, ', 0, 0);
  155. $pdf->SetFont('Times', 'U', 14);
  156. $pdf->Cell(41, 10, ' ', 0, 0);
  157. $pdf->SetFont('Times');
  158. $pdf->Cell(20, 10, ' , have READ & APPROVED this Commission Worksheet. ', 0, 1);
  159. $pdf->SetFontSize(12);
  160. $pdf->Cell(0, 30, '', 0, 1);
  161. $pdf->Cell(75, 10, ' ', 0, 0);
  162. $pdf->Cell(32, 10, ' ', 0, 0);
  163. $pdf->Cell(84, 10, ' Owner and/or Broker Signature Date ', 'T', 1);
  164. $pdf->Cell(0, 13, '', 0, 1);
  165. $pdf->SetFont('Times', 'B');
  166. $pdf->Cell(155, 5, ' New Gross Commission: ', 0, 0);
  167. $pdf->SetFont('Times', 'U');
  168. $pdf->Cell(30, 5, ' $' . number_format(((int)$TYGross + $initialGross), 2) . ' ', 0, 1);
  169. // $pdf->Output();
  170. $base = $pdf->Output('', 's');
  171. $doc = base64_encode($base);
  172. $curl = curl_init();
  173. curl_setopt_array($curl, array(
  174. CURLOPT_URL => "https://demo.docusign.net/restapi/v2/accounts/2837693/envelopes",
  175. CURLOPT_RETURNTRANSFER => true,
  176. CURLOPT_ENCODING => "",
  177. CURLOPT_MAXREDIRS => 10,
  178. CURLOPT_TIMEOUT => 30,
  179. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  180. CURLOPT_CUSTOMREQUEST => "POST",
  181. CURLOPT_POSTFIELDS => "{
  182. \"emailSubject\":\"DocuSign REST API Quickstart Sample\",
  183. \"emailBlurb\": \"Commission Sheet - Signature Required\",
  184. \"recipients\": {
  185. \"signers\": [
  186. {
  187. \"email\": \"" . $userResults['email'] . "\",
  188. \"name\": \"" . $userResults['firstName'] . " " . $userResults['lastName'] . "\",
  189. \"recipientId\": \"1\",
  190. \"routingOrder\": \"1\",
  191. \"tabs\": {
  192. \"signHereTabs\": [
  193. {
  194. \"xPosition\": \"60\",
  195. \"yPosition\": \"555\",
  196. \"documentId\": \"1\",
  197. \"pageNumber\" : \"1\"
  198. }],
  199. \"dateSignedTabs\": [
  200. {
  201. \"xPosition\": \"140\",
  202. \"yPosition\": \"595\",
  203. \"documentId\": \"1\",
  204. \"pageNumber\" : \"1\"
  205. }]
  206. }
  207. },
  208. {
  209. \"email\": \"" . $currAgentEmail['email'] . "\",
  210. \"name\": \"" . $currAgentEmail['firstName'] . " " . $currAgentEmail['lastName'] . "\",
  211. \"recipientId\": \"2\",
  212. \"routingOrder\": \"2\",
  213. \"tabs\": {
  214. \"signHereTabs\":[
  215. {
  216. \"xPosition\": \"340\",
  217. \"yPosition\": \"647\",
  218. \"documentId\": \"1\",
  219. \"pageNumber\" : \"1\"
  220. }],
  221. \"dateSignedTabs\": [
  222. {
  223. \"xPosition\": \"500\",
  224. \"yPosition\": \"687\",
  225. \"documentId\": \"1\",
  226. \"pageNumber\" : \"1\"
  227. }]
  228. }
  229. }]},
  230. \"documents\": [
  231. {
  232. \"documentId\": \"1\",
  233. \"name\": \"" . $houseResults['address'] . ".pdf\",
  234. \"documentBase64\": \"" . $doc . "\"
  235. }],
  236. \"status\": \"sent\"}",
  237. CURLOPT_HTTPHEADER => array(
  238. "accept: application/json",
  239. "content-type: application/json",
  240. "x-docusign-authentication: { \"Username\": \"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $intKey . "\" }"
  241. ),
  242. ));
  243. $response = curl_exec($curl);
  244. $err = curl_error($curl);
  245. curl_close($curl);
  246. if ($err) {
  247. echo "cURL Error #:" . $err;
  248. }
  249. // else {
  250. // echo $response;
  251. // }
  252. $envId = json_decode($response, true);
  253. $namedParameters[":envelopeId"] = $envId['envelopeId'];
  254. $stmt = $dbConn->prepare($sql);
  255. try {
  256. $stmt->execute($namedParameters);
  257. } catch (PDOException $e) {
  258. echo "Error: " . $e->getMessage();
  259. }
  260. // print_r($namedParameters);
  261. header("Location: index.php");
  262. ?>
  263. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  264. <html>
  265. <head>
  266. <title>Commission Sheet</title>
  267. <meta charset="utf-8"/>
  268. </head>
  269. <body>
  270. </body>
  271. </html>