Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.16 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, CURLINFO_HEADER_OUT, true);
  354. curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONrequest);
  355.  
  356. $result = curl_exec($ch);
  357. // $error=curl_getinfo($ch);
  358. // print_r($error);
  359.  
  360. $info = curl_getinfo($ch);
  361. print_r($info['request_header']);
  362.  
  363. // var_dump($token);
  364. // var_dump($url);
  365. // var_dump($JSONrequest);
  366. // var_dump($result);
  367. // var_dump($ch);
  368. $result1 = json_decode($result, true);
  369. curl_close($ch);
  370. }
  371.  
  372. public function getApprovalURL($access_token, $slots, $ppurl) {
  373. $baseUrl = \App\Http\Controllers\booking\BookingController::getBaseUrl();
  374. $redirect = "$baseUrl/gutscheinerfolg";
  375. $redirectCancel = "$baseUrl/gutschein";
  376.  
  377. $coupon = \App\CouponUnique::getLatest();
  378. $invoiceID = 'G34' . ($coupon[0]->id + 1);
  379.  
  380. $price = \App\Price::find(1);
  381. $singlePrice = $price->price;
  382.  
  383. $sumPrice = $slots * $singlePrice;
  384.  
  385. $items = '';
  386. $items.= '{
  387. "quantity": "1",
  388. "name": "Dein Socialmatch Gutschein",
  389. "description": "Dein Socialmatch Gutschein",
  390. "price": "' . $sumPrice . '",
  391. "currency": "EUR"
  392. }';
  393.  
  394.  
  395. $url = 'https://' . $ppurl . '/v1/payments/payment';
  396. $JSONrequest = '{
  397. "intent": "sale",
  398. "payer": {
  399. "payment_method": "paypal"
  400. },
  401. "transactions": [
  402. {
  403.  
  404. "amount": {
  405. "currency": "EUR",
  406. "total": "'.$sumPrice.'",
  407. "details": {
  408. "subtotal": "'.$sumPrice.'"
  409. }
  410. },
  411. "invoice_number":"' . $invoiceID . '",
  412. "item_list": {
  413. "items": [
  414. '. $items . '
  415. ]
  416.  
  417. }
  418. }
  419. ],
  420. "redirect_urls": {
  421. "return_url": "' . $redirect . '",
  422. "cancel_url": "' . $redirectCancel . '"
  423. }
  424. }';
  425. #print($JSONrequest);
  426. #print('<br>');
  427. $ch = curl_init();
  428. curl_setopt($ch, CURLOPT_URL, $url);
  429. //curl_setopt($ch, CURLOPT_SSLCERT, $sslcertpath);
  430. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  431. 'Content-Type: application/json',
  432. 'Authorization: Bearer ' . $access_token
  433. ));
  434.  
  435. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  436. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  437. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  438. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  439. curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONrequest);
  440.  
  441. $result = curl_exec($ch);
  442. // $error=curl_getinfo($ch);
  443. // print_r($error);
  444.  
  445. $result1 = json_decode($result, true);
  446. curl_close($ch);
  447. $approvalURL = $result1['links'][1]['href'];
  448. //print_r($result1);
  449. $payID = $result1['id'];
  450. // var_dump($result1);
  451. return array("approval" => $approvalURL, "PayID" => $payID);
  452. }
  453.  
  454. public function check($code) {
  455. $coupon = \App\Coupon::findByCode($code);
  456. if (is_array($coupon)) {
  457. \Session::put('coupon', $coupon[0]->discount);
  458. \Session::put('couponCode', $coupon[0]->code);
  459. $discount = $coupon[0]->discount;
  460. return json_encode($discount, JSON_NUMERIC_CHECK);
  461. } else {
  462. $couponUnique = \App\CouponUnique::findByCode($code);
  463. if (is_array($couponUnique)) {
  464. return \App\Http\Controllers\booking\CouponController::checkAvailbility($couponUnique);
  465. } else {
  466. return "wrong";
  467. }
  468. }
  469. }
  470.  
  471. public function checkAvailbility($couponUnique) {
  472. $coupon = $couponUnique[0];
  473.  
  474. $dateCoupon = new \DateTime($coupon->date);
  475. $dateNow = new \DateTime();
  476.  
  477. if ($coupon->used == 1) {
  478. return "used";
  479. }
  480. if ($dateCoupon < $dateNow) {
  481. return "passed";
  482. }
  483. \Session::put('coupon', $coupon->slots * 19);
  484. \Session::put('couponCode', $coupon->code);
  485. \Session::put('uniqueCouponSlots', $coupon->slots);
  486. \Session::put('uniqueCouponType', $coupon->type);
  487.  
  488. return json_encode($coupon);
  489. }
  490.  
  491. public function checkUnique($code, $slots) {
  492. $coupon = \App\CouponUnique::getByCodeNotUsedDate($code, $slots);
  493. if (is_array($coupon)) {
  494. $coupon = $coupon[0];
  495. return json_encode($coupon);
  496. } else {
  497. return "wrong";
  498. }
  499. }
  500.  
  501. public function renew($code) {
  502. $session = \Session::get('capture');
  503. $slots = $session['input']['slots'];
  504. $city = $session['input']['city'];
  505. $event = $session['input']['event'];
  506. $city = \App\City::find($city);
  507. $event = \App\Event::find($event);
  508. $price = \App\Price::find($event->price_id);
  509. $price = $price['price'];
  510. $formatPrice = number_format($price, 2, ",", ".");
  511. $coupon = \App\Coupon::findByCode($code);
  512. $coupon = $coupon[0];
  513. $couponMoney = $coupon->discount;
  514. $couponMoney = number_format($couponMoney, 2, ",", ".");
  515. $amountArray = explode(".", $couponMoney);
  516. $amount = $slots * $price - $coupon->discount;
  517. $amount = number_format($amount, 2, ",", ".");
  518. return view('booking/coupon')->with(['amount' => $amount, 'couponMoney' => $couponMoney, 'formatPrice' => $formatPrice, 'price' => $price, 'slots' => $slots]);
  519. }
  520.  
  521. public function renewUnique($code, $unique) {
  522. \Session::put('couponSecurity', $unique);
  523. $session = \Session::get('capture');
  524. $slots = $session['input']['slots'];
  525. $city = $session['input']['city'];
  526. $event = $session['input']['event'];
  527. $city = \App\City::find($city);
  528. $event = \App\Event::find($event);
  529. $price = \App\Price::find($event->price_id);
  530. $price = $price['price'];
  531. $formatPrice = number_format($price, 2, ",", ".");
  532. $coupon = \App\CouponUnique::findByCode($code);
  533. $coupon = $coupon[0];
  534. $couponMoney = $coupon->slots * 19;
  535. $couponMoney = number_format($couponMoney, 2, ",", ".");
  536. $amountArray = explode(".", $couponMoney);
  537. $amount = $slots * $price - ($coupon->slots * 19);
  538. $amount = number_format($amount, 2, ",", ".");
  539. return view('booking/coupon')->with(['amount' => $amount, 'couponMoney' => $couponMoney, 'formatPrice' => $formatPrice, 'price' => $price, 'slots' => $slots]);
  540. }
  541.  
  542. public static function setCouponUsed($code) {
  543. $security = \Session::get('couponSecurity');
  544. $coupon = \App\CouponUnique::findCouponByCode($code);
  545. if (is_array($coupon)) {
  546. $coupon = $coupon[0];
  547. $coupon = \App\CouponUnique::find($coupon->id);
  548. $coupon->used = 1;
  549. $coupon->taken = 1;
  550. if ($security != 'none') {
  551. $coupon->security_code = $security;
  552. }
  553. $booking = \App\Booking::getLatest();
  554. $coupon->booking_id = $booking[0]->id;
  555. $coupon->save();
  556. }
  557. }
  558.  
  559. public static function createBillPDF($firstName, $lastName, $slots) {
  560. $datTimeObj = new \DateTime();
  561. $output_date = $datTimeObj->format('d.m.Y');
  562.  
  563. $price = \App\Price::find(1);
  564. $price = $price->price;
  565.  
  566. $uniqueCoupon = \App\CouponUnique::getLatest();
  567. $uniqueCouponId = $uniqueCoupon[0]->id;
  568.  
  569. $greeting = "Hallo " . $firstName . ",";
  570. $full_name = $firstName . ' ' . $lastName;
  571.  
  572. $pdf = new \App\Http\Controllers\PDF();
  573. $pdf->AliasNbPages();
  574. $pdf->AddPage();
  575. $pdf->Ln(25);
  576. $pdf->SetFont('Arial', 'B', 14);
  577. $pdf->Cell(0, 5, $pdf->convert_chars($full_name), 0, 1);
  578. $pdf->SetFont('Arial', 'B', 12);
  579. $pdf->Cell(0, 10, 'Deine Socialmatch Rechnung vom ' . $output_date . ' - Rechnungs-Nr.: G34' . $uniqueCouponId, 0, 1);
  580. $pdf->Ln(15);
  581. $pdf->SetFont('Arial', '', 12);
  582. $pdf->Cell(0, 5, $pdf->convert_chars($greeting), 0, 1);
  583. $pdf->Cell(0, 15, $pdf->convert_chars('wir haben Deine Zahlung für folgende Bestellung erhalten:'), 0, 1);
  584.  
  585. // Table Column heading
  586. $header = ['Bezeichnung', 'Einzelpreis', 'Anzahl', 'Preis'];
  587.  
  588. // Create Table Data
  589. $preis = $price;
  590. $preis_freunde = 0;
  591.  
  592. if ($slots > 1){
  593. $anz_freunde = $slots - 1;
  594. $preis_freunde = $preis * $anz_freunde;
  595. $preis_freunde = $preis_freunde . " EUR";
  596. }
  597.  
  598. $gesamtpreis = $preis + $preis_freunde;
  599. $gesamtpreis = $gesamtpreis . " EUR";
  600.  
  601. $preis = $preis . " EUR";
  602. if ($slots == 1){
  603. $data = [
  604. 0 => [0 => "Dein Socialmatch-Gutschein", 1 => $preis, 2 => "1", 3 => $preis],
  605. 1 => [0 => "Gesamtbetrag", 1 => "", 2 => "", 3 => $gesamtpreis]
  606. ];
  607. } else{
  608. $data = [
  609. 0 => [0 => "Dein Socialmatch-Gutschein", 1 => $preis, 2 => $slots, 3 => $gesamtpreis],
  610. 1 => [0 => "Gesamtbetrag", 1 => "", 2 => "", 3 => $gesamtpreis]
  611. ];
  612. }
  613.  
  614.  
  615. //add improved table
  616. $pdf->ImprovedTable($header, $data);
  617.  
  618. $pdf->SetFont('Arial', '', 10);
  619. $pdf->Cell(0, 2, ' ', 0, 1);
  620. $pdf->Cell(0, 5, 'Alle angegebenen Preise sind Endpreise.', 0, 1);
  621. $pdf->Cell(0, 5, $pdf->convert_chars('Aufgrund des Kleinunternehmerstatus gem. § 19 UStG erheben wir keine Umsatzsteuer '), 0, 1);
  622. $pdf->Cell(0, 5, 'und weisen diese daher auch nicht aus.', 0, 1);
  623.  
  624. $pdf->SetFont('Arial', '', 12);
  625. $pdf->Ln(5);
  626.  
  627. //TODO zahlungsmittel if usw
  628. $pdf->Cell(0, 5, $pdf->convert_chars('Der angegebene Gesamtbetrag wurde von Deinem ausgewählten Zahlungsmittel eingezogen.'), 0, 1);
  629. $pdf->Ln(15);
  630. $pdf->Cell(0, 5, $pdf->convert_chars('Mit freundlichen Grüßen'), 0, 1);
  631. $pdf->Ln(5);
  632. $pdf->Cell(0, 5, 'Dein Socialmatch-Team', 0, 1);
  633. $pdf->Ln(20);
  634. $pdf->SetFont('Arial', 'B', 11);
  635. $pdf->Cell(0, 5, 'Bei Facebook Fan werden!', 0, 1);
  636. $pdf->SetFont('Arial', '', 11);
  637. $pdf->Cell(0, 5, $pdf->convert_chars('Jetzt unter www.facebook.de/socialmatchevents Fan werden und regelmäßig Rabatte und Neuigkeiten'), 0, 1);
  638. $pdf->Cell(0, 5, $pdf->convert_chars('von Socialmatch sichern.'), 0, 1);
  639.  
  640. $pdf->Output("../../rechnungen/socialmatch/" . $output_date . "-Rechnung-G34" . $uniqueCouponId . "-Socialmatch-" . $firstName . '-' . $lastName . ".pdf", "f");
  641. $return = "" . $output_date . "-Rechnung-G34" . $uniqueCouponId . "-Socialmatch-" . $firstName . '-' . $lastName . ".pdf";
  642. return $return;
  643. }
  644.  
  645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement