Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.94 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\booking;
  4.  
  5. use App\Http\Requests;
  6. use App\Http\Controllers\Controller;
  7. use Request;
  8. use \CouponPDF;
  9. use \PDF;
  10.  
  11. class CouponController extends Controller {
  12.  
  13. public function index() {
  14. $input = Request::all();
  15. if (isset($input['belboon'])) {
  16. \Session::put('belboon', $input['belboon']);
  17. }
  18. if (preg_match('/(alcatel|android|blackberry|benq|cell|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mobi|motorola|nokia|palm|panasonic|philips|phone|sagem|sharp|smartphone|sony|symbian|t-mobile|up\.browser|up\.link|vodafone|wap|wireless|xda|zte)/i', $_SERVER['HTTP_USER_AGENT'])) {
  19. $price = \App\Price::find(1);
  20. $price->price = number_format($price->price);
  21. return view('booking.coupon.home_mobile')->with(['eventPrice' => $price->price]);
  22. } else {
  23. $price = \App\Price::find(1);
  24. $price->price = number_format($price->price);
  25. return view('booking.coupon.home')->with(['eventPrice' => $price->price]);
  26. }
  27. }
  28.  
  29. public function createUniqueCouponCode() {
  30. $excisting = array();
  31. $possibleCode = "";
  32. while (is_array($excisting)) {
  33. $possibleCode = \App\Http\Controllers\backend\CouponController::getRandomString(8);
  34. $possibleCode = 'UC' . $possibleCode;
  35. $excisting = \App\CouponUnique::findCouponByCode("$possibleCode");
  36. $excisting = \App\Coupon::findByCode("$possibleCode");
  37. }
  38. return $possibleCode;
  39. }
  40.  
  41. public function sendCouponConfirmMail($input, $email, $couponPDFName, $billPDFName, $slots, $firstName) {
  42. $betreff = "Socialmatch - Gutschein";
  43.  
  44. if ($slots > 1) {
  45. $text = "<p>Hallo $firstName, </p><p>du hast eine tolle Wahl getroffen!</p> <p>Du hast erfolgreich einen Socialmatch-Gutschein für $slots Personen gekauft, die beschenkten Personen werden sich freuen ☺</p>";
  46. } else {
  47. $text = "<p>Hallo $firstName, </p><p>du hast eine tolle Wahl getroffen!</p> <p>Du hast erfolgreich einen Socialmatch-Gutschein für $slots Person gekauft, die beschenkte Person wird sich freuen ☺</p>";
  48. }
  49. $text .= "<p>Wir haben dir den Gutschein an die E-Mail angehängt, dort befinden sich auch die Infos zur Einlösung des Gutscheins.</p>"
  50. . "<p>Viel Spaß beim Verschenken!"
  51. . "<p>Dein Socialmatch-Team!</p>"
  52. . "<p><a href=\"http://www.socialmatch.de\" target=\"_blank\">socialmatch.de</a><br><img src=\"http://www.socialmatch.de/img/banner-email.png\" width=\"449\" height=\"150\" alt=\"BANNER\"/></p><p>Hast Du noch Fragen? Kontaktiere uns gerne jederzeit unter <a href=\"mailto:julie@socialmatch.de\">julie@socialmatch.de</a> oder schau auf unsere <a href=\"http://www.socialmatch.de/faq_de.php\" target=\"_blank\">FAQ-Seite</a>!</p>";
  53.  
  54. $mail = new \PHPMailer;
  55. $mail->isSMTP(); // Set mailer to use SMTP
  56. $mail->Host = 'smtp.socialmatch.de'; // Specify main and backup SMTP servers
  57. $mail->SMTPAuth = true; // Enable SMTP authentication
  58. $mail->Username = 'julie@socialmatch.de'; // SMTP username
  59. $mail->Password = 'maTch3$1ds1!'; // SMTP password
  60. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  61. $mail->Port = 587;
  62.  
  63. if ($couponPDFName != "") {
  64. $mail->addAttachment(realpath("../../rechnungen/socialmatch/" . $couponPDFName), $couponPDFName, 'base64', 'application/pdf');
  65. }
  66. if ($billPDFName != "") {
  67. $mail->addAttachment(realpath("../../rechnungen/socialmatch/" . $billPDFName), $billPDFName, 'base64', 'application/pdf');
  68. }
  69.  
  70. $mail->From = 'julie@socialmatch.de';
  71. $mail->FromName = 'Socialmatch';
  72. $mail->addAddress($email); // Add a recipient
  73. $mail->isHTML(true);
  74. $mail->addBCC("confirmmail@socialmatch.de", "$email");
  75. $mail->Subject = $betreff;
  76. $mail->Body = $text;
  77. $mail->CharSet = "UTF-8";
  78. if (!$mail->send()) {
  79. echo 'Message could not be sent.';
  80. echo 'Mailer Error: ' . $mail->ErrorInfo;
  81. } else {
  82.  
  83. }
  84. }
  85.  
  86. public function createCouponPDF($slots, $code) {
  87. $now = new \DateTime();
  88. $cleanDate = $now->format("d-m-Y");
  89. $dateLimit = \Carbon\Carbon::now()->addYear(1);
  90. $dateLimit = $dateLimit->format("d.m.Y");
  91. // Instanciation of inherited class
  92. $pdf = new \App\Http\Controllers\CouponPDF();
  93. $pdf->AliasNbPages();
  94. $pdf->AddPage();
  95.  
  96. // obere blaue Linie zeichnen
  97. $pdf->SetDrawColor(1, 155, 205);
  98. $pdf->SetLineWidth(0.5);
  99. $pdf->Line(13, 50, 200, 50);
  100.  
  101. // untere blaue Linie zeichnen
  102. $pdf->SetDrawColor(1, 155, 205);
  103. $pdf->SetLineWidth(0.5);
  104. $pdf->Line(13, 145, 200, 145);
  105.  
  106. // Zeile Gutscheincode
  107. $pdf->SetFont('Arial', 'B', 14);
  108. $pdf->Ln(30);
  109. $pdf->Cell(55);
  110. $pdf->Cell(10, 10, 'GUTSCHEINCODE: ', 0, 1);
  111. $pdf->Ln(-10);
  112. $pdf->Cell(105);
  113. $pdf->SetTextColor(1, 155, 205);
  114. $pdf->Cell(10, 10, $code, 0, 1);
  115.  
  116. // Bereich "Gutschein für n Personen"
  117. $pdf->Ln(20);
  118. $pdf->Cell(20);
  119. $pdf->SetTextColor(15, 15, 15);
  120. $pdf->SetFont('Arial', 'B', 22);
  121. $pdf->Cell(10, 10, 'Gutschein ', 0, 1);
  122.  
  123. if ($slots > 1) {
  124. $pdf->Cell(12);
  125. $pdf->Cell(10, 10, $pdf->convert_chars('für ' . $slots . ' Personen'), 0, 1);
  126. } else {
  127. $pdf->Cell(15);
  128. $pdf->Cell(10, 10, $pdf->convert_chars('für ' . $slots . ' Person'), 0, 1);
  129. }
  130.  
  131. // Bereich: Einlösung des Gutscheins
  132. $pdf->Ln(-35);
  133. $pdf->Cell(90);
  134. $pdf->SetFont('Arial', 'B', 12);
  135. $pdf->SetTextColor(206, 93, 37);
  136. $pdf->Cell(10, 10, $pdf->convert_chars('Einlösung des Gutscheins: '), 0, 1);
  137. $pdf->Cell(90);
  138. $pdf->SetFont('Arial', '', 12);
  139. $pdf->SetTextColor(15, 15, 15);
  140. $pdf->Cell(5, 5, $pdf->convert_chars('1. Besuche'), 0, 1);
  141. $pdf->Ln(-5);
  142. $pdf->Cell(113);
  143. $pdf->SetFont('Arial', 'U', 12);
  144. $pdf->SetTextColor(53, 33, 206);
  145. $pdf->Cell(5, 5, $pdf->convert_chars('www.socialmatch.de'), 0, 1);
  146. $pdf->Ln(3);
  147. $pdf->Cell(90);
  148. $pdf->SetFont('Arial', '', 12);
  149. $pdf->SetTextColor(15, 15, 15);
  150. $pdf->Cell(5, 5, $pdf->convert_chars('2. Wähle das Event in Deiner Stadt und'), 0, 1);
  151. $pdf->Cell(95);
  152. $pdf->Cell(5, 5, $pdf->convert_chars('Altersgruppe aus'), 0, 1);
  153. $pdf->Ln(3);
  154. $pdf->Cell(90);
  155. $pdf->Cell(5, 5, $pdf->convert_chars('3. Nach der Anmeldung für das Event kannst'), 0, 1);
  156. $pdf->Cell(95);
  157. $pdf->Cell(5, 5, $pdf->convert_chars('Du auf der Bezahlseite im Feld "Gutschein"'), 0, 1);
  158. $pdf->Cell(95);
  159. $pdf->Cell(5, 5, $pdf->convert_chars('Deinen Gutscheincode eingeben'), 0, 1);
  160. $pdf->Ln(3);
  161. $pdf->Cell(90);
  162. $pdf->Cell(5, 5, $pdf->convert_chars('4. Bei erfolgreicher Anmeldung erhälst du eine'), 0, 1);
  163. $pdf->Cell(95);
  164. $pdf->Cell(5, 5, $pdf->convert_chars('Bestätigungsmail.'), 0, 1);
  165.  
  166. // Fußbereich URL Socialmatch.de
  167. $pdf->Ln(17);
  168. $pdf->Cell(5);
  169. $pdf->SetTextColor(15, 15, 15);
  170. $pdf->SetFont('Arial', 'B', 16);
  171. $pdf->Cell(10, 10, 'www.socialmatch.de ', 0, 1);
  172.  
  173. // Bereich Gutscheingültigkeit
  174. $pdf->Ln(-11);
  175. $pdf->Cell(90);
  176. $pdf->SetTextColor(128,128,128);
  177. $pdf->SetFont('Arial', '', 9);
  178. $pdf->Cell(4, 4, $pdf->convert_chars('Der Gutschein ist in allen Socialmatch-Städten einlösbar.'), 0, 1);
  179. $pdf->Cell(90);
  180. $pdf->Cell(4, 4, $pdf->convert_chars('Eine Auszahlung des Gutscheins ist nicht möglich.'), 0, 1);
  181. $pdf->Cell(90);
  182. $pdf->Cell(4, 4, $pdf->convert_chars("Gutschein ist gültig bis zum $dateLimit"), 0, 1);
  183.  
  184. // schwarze Trennlinie zeichnen + Schere
  185. $pdf->SetDrawColor(0, 0, 0);
  186. $pdf->SetDash(1,1);
  187. $pdf->SetLineWidth(0.25);
  188. $pdf->Line(5, 180, 205, 180);
  189. $pdf->Image('img/scissor.jpeg', 5, 182, 5);
  190.  
  191. $pdf->Output("../../rechnungen/socialmatch/Socialmatch-Gutschein-" . $cleanDate . ".pdf", "f");
  192. $return = "Socialmatch-Gutschein-" . $cleanDate . ".pdf";
  193. return $return;
  194. }
  195.  
  196. public function store() {
  197. $input = Request::all();
  198. if (preg_match('/(alcatel|android|blackberry|benq|cell|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mobi|motorola|nokia|palm|panasonic|philips|phone|sagem|sharp|smartphone|sony|symbian|t-mobile|up\.browser|up\.link|vodafone|wap|wireless|xda|zte)/i', $_SERVER['HTTP_USER_AGENT'])) {
  199. $price = \App\Price::find(1);
  200. $price->price = number_format($price->price);
  201. return view('booking.coupon.success')->with(['eventPrice' => $price->price]);
  202. } else {
  203. $price = \App\Price::find(1);
  204. $price->price = number_format($price->price);
  205. return view('booking.coupon.success')->with(['eventPrice' => $price->price]);
  206. }
  207. }
  208.  
  209. public function paypalSuccess() {
  210. $request = Request::all();
  211. $key = \App\Key::find(1);
  212. $modus = $key->paypal_mode;
  213. if ($modus == 'live') {
  214. $ppurl = 'api.paypal.com';
  215. $billUrl = '../';
  216. } else {
  217. $ppurl = 'api.sandbox.paypal.com';
  218. $billUrl = '../..';
  219. }
  220. $paymentId = $request['paymentId'];
  221. $PayerID = $request['PayerID'];
  222. $token = $request['token'];
  223. \App\Http\Controllers\booking\CouponController::executePayPal($PayerID, $paymentId, $ppurl);
  224. /*$input = \Session::get('input');
  225. $date = \Carbon\Carbon::now()->addYear(1);
  226. $slots = $input['slots'];
  227. $firstName = $input['firstname'];
  228. $lastName = $input['lastname'];
  229. $mail = $input['mail'];
  230.  
  231. $coupon = new \App\CouponUnique();
  232. $uniqueCode = \App\Http\Controllers\booking\CouponController::createUniqueCouponCode();
  233. $coupon->code = $uniqueCode;
  234. $coupon->slots = $slots;
  235. $coupon->mail = $mail;
  236. $coupon->type = 'gekauft';
  237. $coupon->used = 0;
  238. $coupon->taken = 1;
  239. $coupon->date = $date;
  240. $coupon->created = \Carbon\Carbon::now();
  241. $coupon->save();
  242.  
  243. $couponPDFName = \App\Http\Controllers\booking\CouponController::createCouponPDF($slots, $uniqueCode);
  244. $billPDFName = \App\Http\Controllers\booking\CouponController::createBillPDF($firstName, $lastName, $slots);
  245.  
  246.  
  247. \App\Http\Controllers\booking\CouponController::sendCouponConfirmMail($input, $mail, $couponPDFName, $billPDFName, $slots, $firstName);
  248. unlink(realpath("../../rechnungen/socialmatch/" . $couponPDFName));
  249.  
  250. if (preg_match('/(alcatel|android|blackberry|benq|cell|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mobi|motorola|nokia|palm|panasonic|philips|phone|sagem|sharp|smartphone|sony|symbian|t-mobile|up\.browser|up\.link|vodafone|wap|wireless|xda|zte)/i', $_SERVER['HTTP_USER_AGENT'])) {
  251. $price = \App\Price::find(1);
  252. $price->price = number_format($price->price);
  253. return view('booking.coupon.success')->with(['eventPrice' => $price->price]);
  254. } else {
  255. $price = \App\Price::find(1);
  256. $price->price = number_format($price->price);
  257. return view('booking.coupon.success')->with(['eventPrice' => $price->price]);
  258. }*/
  259. }
  260.  
  261. public function payment() {
  262. $input = Request::all();
  263. $slots = $input['slots'];
  264. \Session::put('input', $input);
  265.  
  266. $key = \App\Key::find(1);
  267. $pp_clientID = $key->paypal_public;
  268. $pp_secret = $key->paypal_private;
  269. $modus = $key->paypal_mode;
  270.  
  271. if ($modus == 'live') {
  272. $ppurl = 'api.paypal.com';
  273. } else {
  274. $ppurl = 'api.sandbox.paypal.com';
  275. }
  276. $api_credentials = $pp_clientID . ':' . $pp_secret;
  277. $access_token = \App\Http\Controllers\booking\CouponController::getAccessToken($ppurl, $api_credentials);
  278. \Session::put('access_token', $access_token);
  279. $approvalArray = \App\Http\Controllers\booking\CouponController::getApprovalURL($access_token, $slots, $ppurl);
  280. $approval = $approvalArray['approval'];
  281. \Session::put('PayID', $approvalArray['PayID']);
  282.  
  283. if (preg_match('/(alcatel|android|blackberry|benq|cell|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mobi|motorola|nokia|palm|panasonic|philips|phone|sagem|sharp|smartphone|sony|symbian|t-mobile|up\.browser|up\.link|vodafone|wap|wireless|xda|zte)/i', $_SERVER['HTTP_USER_AGENT'])) {
  284. $price = \App\Price::find(1);
  285. $price->price = number_format($price->price);
  286. return view('booking.coupon.payment_mobile')->with([
  287. 'eventPrice' => $price->price,
  288. 'modus' => $modus,
  289. 'approval' => $approval,
  290. 'slots' => $slots
  291. ]);
  292. } else {
  293. $price = \App\Price::find(1);
  294. $price->price = number_format($price->price);
  295. return view('booking.coupon.payment')->with([
  296. 'eventPrice' => $price->price,
  297. 'modus' => $modus,
  298. 'approval' => $approval,
  299. 'slots' => $slots
  300. ]);
  301. }
  302. }
  303.  
  304. public function getAccessToken($ppurl, $api_credentials) {
  305. //Get Access Token
  306. $url = 'https://' . $ppurl . '/v1/oauth2/token';
  307. $JSONrequest = 'grant_type=client_credentials';
  308.  
  309. $ch = curl_init();
  310. curl_setopt($ch, CURLOPT_URL, $url);
  311. //curl_setopt($ch, CURLOPT_SSLCERT, $sslcertpath);
  312. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  313. 'Accept: application/json',
  314. 'Accept-Language: de_DE'
  315. ));
  316. curl_setopt($ch, CURLOPT_USERPWD, $api_credentials);
  317. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  318. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  319. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  320. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  321. curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONrequest);
  322.  
  323. $result = curl_exec($ch);
  324. // $error=curl_getinfo($ch);
  325. // var_dump($error);
  326. $result1 = json_decode($result, true);
  327. //var_dump($result1);
  328. curl_close($ch);
  329. $access_token = $result1['access_token'];
  330. return $access_token;
  331. }
  332.  
  333. public function executePayPal($payer_id, $payId, $ppurl){
  334. $token = \Session::get('access_token');
  335. $url = "https://$ppurl/v1/payments/payment/$payId/execute";
  336.  
  337. $JSONrequest = '{
  338. "payer_id": "'.$payer_id.'",
  339. }';
  340.  
  341. $ch = curl_init();
  342. curl_setopt($ch, CURLOPT_URL, $url);
  343. //curl_setopt($ch, CURLOPT_SSLCERT, $sslcertpath);
  344. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  345. 'Content-Type: application/json',
  346. 'Authorization: Bearer ' . $token
  347. ));
  348. curl_setopt($ch, CURLOPT_HEADER, 1);
  349. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  350. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  351. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  352. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  353. curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONrequest);
  354.  
  355. $result = curl_exec($ch);
  356. // $error=curl_getinfo($ch);
  357. // print_r($error);
  358. var_dump($url);
  359. var_dump($JSONrequest);
  360. var_dump($result);
  361. $result1 = json_decode($result, true);
  362. curl_close($ch);
  363. }
  364.  
  365. public function getApprovalURL($access_token, $slots, $ppurl) {
  366. $baseUrl = \App\Http\Controllers\booking\BookingController::getBaseUrl();
  367. $redirect = "$baseUrl/gutscheinerfolg";
  368. $redirectCancel = "$baseUrl/gutschein";
  369.  
  370. $coupon = \App\CouponUnique::getLatest();
  371. $invoiceID = 'G34' . ($coupon[0]->id + 1);
  372.  
  373. $price = \App\Price::find(1);
  374. $singlePrice = $price->price;
  375.  
  376. $sumPrice = $slots * $singlePrice;
  377.  
  378. $items = '';
  379. $items.= '{
  380. "quantity": "1",
  381. "name": "Dein Socialmatch Gutschein",
  382. "description": "Dein Socialmatch Gutschein",
  383. "price": "' . $sumPrice . '",
  384. "currency": "EUR"
  385. }';
  386.  
  387.  
  388. $url = 'https://' . $ppurl . '/v1/payments/payment';
  389. $JSONrequest = '{
  390. "intent": "sale",
  391. "payer": {
  392. "payment_method": "paypal"
  393. },
  394. "transactions": [
  395. {
  396.  
  397. "amount": {
  398. "currency": "EUR",
  399. "total": "'.$sumPrice.'",
  400. "details": {
  401. "subtotal": "'.$sumPrice.'"
  402. }
  403. },
  404. "invoice_number":"' . $invoiceID . '",
  405. "item_list": {
  406. "items": [
  407. '. $items . '
  408. ]
  409.  
  410. }
  411. }
  412. ],
  413. "redirect_urls": {
  414. "return_url": "' . $redirect . '",
  415. "cancel_url": "' . $redirectCancel . '"
  416. }
  417. }';
  418. #print($JSONrequest);
  419. #print('<br>');
  420. $ch = curl_init();
  421. curl_setopt($ch, CURLOPT_URL, $url);
  422. //curl_setopt($ch, CURLOPT_SSLCERT, $sslcertpath);
  423. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  424. 'Content-Type: application/json',
  425. 'Authorization: Bearer ' . $access_token
  426. ));
  427.  
  428. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  429. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  430. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  431. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  432. curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONrequest);
  433.  
  434. $result = curl_exec($ch);
  435. // $error=curl_getinfo($ch);
  436. // print_r($error);
  437.  
  438. $result1 = json_decode($result, true);
  439. curl_close($ch);
  440. $approvalURL = $result1['links'][1]['href'];
  441. //print_r($result1);
  442. $payID = $result1['id'];
  443. // var_dump($result1);
  444. return array("approval" => $approvalURL, "PayID" => $payID);
  445. }
  446.  
  447. public function check($code) {
  448. $coupon = \App\Coupon::findByCode($code);
  449. if (is_array($coupon)) {
  450. \Session::put('coupon', $coupon[0]->discount);
  451. \Session::put('couponCode', $coupon[0]->code);
  452. $discount = $coupon[0]->discount;
  453. return json_encode($discount, JSON_NUMERIC_CHECK);
  454. } else {
  455. $couponUnique = \App\CouponUnique::findByCode($code);
  456. if (is_array($couponUnique)) {
  457. return \App\Http\Controllers\booking\CouponController::checkAvailbility($couponUnique);
  458. } else {
  459. return "wrong";
  460. }
  461. }
  462. }
  463.  
  464. public function checkAvailbility($couponUnique) {
  465. $coupon = $couponUnique[0];
  466.  
  467. $dateCoupon = new \DateTime($coupon->date);
  468. $dateNow = new \DateTime();
  469.  
  470. if ($coupon->used == 1) {
  471. return "used";
  472. }
  473. if ($dateCoupon < $dateNow) {
  474. return "passed";
  475. }
  476. \Session::put('coupon', $coupon->slots * 19);
  477. \Session::put('couponCode', $coupon->code);
  478. \Session::put('uniqueCouponSlots', $coupon->slots);
  479. \Session::put('uniqueCouponType', $coupon->type);
  480.  
  481. return json_encode($coupon);
  482. }
  483.  
  484. public function checkUnique($code, $slots) {
  485. $coupon = \App\CouponUnique::getByCodeNotUsedDate($code, $slots);
  486. if (is_array($coupon)) {
  487. $coupon = $coupon[0];
  488. return json_encode($coupon);
  489. } else {
  490. return "wrong";
  491. }
  492. }
  493.  
  494. public function renew($code) {
  495. $session = \Session::get('capture');
  496. $slots = $session['input']['slots'];
  497. $city = $session['input']['city'];
  498. $event = $session['input']['event'];
  499. $city = \App\City::find($city);
  500. $event = \App\Event::find($event);
  501. $price = \App\Price::find($event->price_id);
  502. $price = $price['price'];
  503. $formatPrice = number_format($price, 2, ",", ".");
  504. $coupon = \App\Coupon::findByCode($code);
  505. $coupon = $coupon[0];
  506. $couponMoney = $coupon->discount;
  507. $couponMoney = number_format($couponMoney, 2, ",", ".");
  508. $amountArray = explode(".", $couponMoney);
  509. $amount = $slots * $price - $coupon->discount;
  510. $amount = number_format($amount, 2, ",", ".");
  511. return view('booking/coupon')->with(['amount' => $amount, 'couponMoney' => $couponMoney, 'formatPrice' => $formatPrice, 'price' => $price, 'slots' => $slots]);
  512. }
  513.  
  514. public function renewUnique($code, $unique) {
  515. \Session::put('couponSecurity', $unique);
  516. $session = \Session::get('capture');
  517. $slots = $session['input']['slots'];
  518. $city = $session['input']['city'];
  519. $event = $session['input']['event'];
  520. $city = \App\City::find($city);
  521. $event = \App\Event::find($event);
  522. $price = \App\Price::find($event->price_id);
  523. $price = $price['price'];
  524. $formatPrice = number_format($price, 2, ",", ".");
  525. $coupon = \App\CouponUnique::findByCode($code);
  526. $coupon = $coupon[0];
  527. $couponMoney = $coupon->slots * 19;
  528. $couponMoney = number_format($couponMoney, 2, ",", ".");
  529. $amountArray = explode(".", $couponMoney);
  530. $amount = $slots * $price - ($coupon->slots * 19);
  531. $amount = number_format($amount, 2, ",", ".");
  532. return view('booking/coupon')->with(['amount' => $amount, 'couponMoney' => $couponMoney, 'formatPrice' => $formatPrice, 'price' => $price, 'slots' => $slots]);
  533. }
  534.  
  535. public static function setCouponUsed($code) {
  536. $security = \Session::get('couponSecurity');
  537. $coupon = \App\CouponUnique::findCouponByCode($code);
  538. if (is_array($coupon)) {
  539. $coupon = $coupon[0];
  540. $coupon = \App\CouponUnique::find($coupon->id);
  541. $coupon->used = 1;
  542. $coupon->taken = 1;
  543. if ($security != 'none') {
  544. $coupon->security_code = $security;
  545. }
  546. $booking = \App\Booking::getLatest();
  547. $coupon->booking_id = $booking[0]->id;
  548. $coupon->save();
  549. }
  550. }
  551.  
  552. public static function createBillPDF($firstName, $lastName, $slots) {
  553. $datTimeObj = new \DateTime();
  554. $output_date = $datTimeObj->format('d.m.Y');
  555.  
  556. $price = \App\Price::find(1);
  557. $price = $price->price;
  558.  
  559. $uniqueCoupon = \App\CouponUnique::getLatest();
  560. $uniqueCouponId = $uniqueCoupon[0]->id;
  561.  
  562. $greeting = "Hallo " . $firstName . ",";
  563. $full_name = $firstName . ' ' . $lastName;
  564.  
  565. $pdf = new \App\Http\Controllers\PDF();
  566. $pdf->AliasNbPages();
  567. $pdf->AddPage();
  568. $pdf->Ln(25);
  569. $pdf->SetFont('Arial', 'B', 14);
  570. $pdf->Cell(0, 5, $pdf->convert_chars($full_name), 0, 1);
  571. $pdf->SetFont('Arial', 'B', 12);
  572. $pdf->Cell(0, 10, 'Deine Socialmatch Rechnung vom ' . $output_date . ' - Rechnungs-Nr.: G34' . $uniqueCouponId, 0, 1);
  573. $pdf->Ln(15);
  574. $pdf->SetFont('Arial', '', 12);
  575. $pdf->Cell(0, 5, $pdf->convert_chars($greeting), 0, 1);
  576. $pdf->Cell(0, 15, $pdf->convert_chars('wir haben Deine Zahlung für folgende Bestellung erhalten:'), 0, 1);
  577.  
  578. // Table Column heading
  579. $header = ['Bezeichnung', 'Einzelpreis', 'Anzahl', 'Preis'];
  580.  
  581. // Create Table Data
  582. $preis = $price;
  583. $preis_freunde = 0;
  584.  
  585. if ($slots > 1){
  586. $anz_freunde = $slots - 1;
  587. $preis_freunde = $preis * $anz_freunde;
  588. $preis_freunde = $preis_freunde . " EUR";
  589. }
  590.  
  591. $gesamtpreis = $preis + $preis_freunde;
  592. $gesamtpreis = $gesamtpreis . " EUR";
  593.  
  594. $preis = $preis . " EUR";
  595. if ($slots == 1){
  596. $data = [
  597. 0 => [0 => "Dein Socialmatch-Gutschein", 1 => $preis, 2 => "1", 3 => $preis],
  598. 1 => [0 => "Gesamtbetrag", 1 => "", 2 => "", 3 => $gesamtpreis]
  599. ];
  600. } else{
  601. $data = [
  602. 0 => [0 => "Dein Socialmatch-Gutschein", 1 => $preis, 2 => $slots, 3 => $gesamtpreis],
  603. 1 => [0 => "Gesamtbetrag", 1 => "", 2 => "", 3 => $gesamtpreis]
  604. ];
  605. }
  606.  
  607.  
  608. //add improved table
  609. $pdf->ImprovedTable($header, $data);
  610.  
  611. $pdf->SetFont('Arial', '', 10);
  612. $pdf->Cell(0, 2, ' ', 0, 1);
  613. $pdf->Cell(0, 5, 'Alle angegebenen Preise sind Endpreise.', 0, 1);
  614. $pdf->Cell(0, 5, $pdf->convert_chars('Aufgrund des Kleinunternehmerstatus gem. § 19 UStG erheben wir keine Umsatzsteuer '), 0, 1);
  615. $pdf->Cell(0, 5, 'und weisen diese daher auch nicht aus.', 0, 1);
  616.  
  617. $pdf->SetFont('Arial', '', 12);
  618. $pdf->Ln(5);
  619.  
  620. //TODO zahlungsmittel if usw
  621. $pdf->Cell(0, 5, $pdf->convert_chars('Der angegebene Gesamtbetrag wurde von Deinem ausgewählten Zahlungsmittel eingezogen.'), 0, 1);
  622. $pdf->Ln(15);
  623. $pdf->Cell(0, 5, $pdf->convert_chars('Mit freundlichen Grüßen'), 0, 1);
  624. $pdf->Ln(5);
  625. $pdf->Cell(0, 5, 'Dein Socialmatch-Team', 0, 1);
  626. $pdf->Ln(20);
  627. $pdf->SetFont('Arial', 'B', 11);
  628. $pdf->Cell(0, 5, 'Bei Facebook Fan werden!', 0, 1);
  629. $pdf->SetFont('Arial', '', 11);
  630. $pdf->Cell(0, 5, $pdf->convert_chars('Jetzt unter www.facebook.de/socialmatchevents Fan werden und regelmäßig Rabatte und Neuigkeiten'), 0, 1);
  631. $pdf->Cell(0, 5, $pdf->convert_chars('von Socialmatch sichern.'), 0, 1);
  632.  
  633. $pdf->Output("../../rechnungen/socialmatch/" . $output_date . "-Rechnung-G34" . $uniqueCouponId . "-Socialmatch-" . $firstName . '-' . $lastName . ".pdf", "f");
  634. $return = "" . $output_date . "-Rechnung-G34" . $uniqueCouponId . "-Socialmatch-" . $firstName . '-' . $lastName . ".pdf";
  635. return $return;
  636. }
  637.  
  638. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement