<?php
namespace App\Framework\AdminBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Framework\AppBundle\Entity\Venue;
use App\Framework\AppBundle\Entity\Export;
use App\Framework\AppBundle\Entity\Mail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
class ResaController extends AbstractController
{
/**
* @Route("/resa_old", name="palace_manager_resa_old_index")
*/
public function indexOldAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['id' => 'DESC']);
$future = strtotime('+4 day');
return $this->render('AdminBundle/Booking/index.html.twig', [
'bookings' => $bookings,
'future' => $future,
]);
}
/**
* @Route("/resa", name="palace_manager_resa_index")
*/
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$future = strtotime('+4 day');
return $this->render('AdminBundle/Booking/index2.html.twig', [
'future' => $future,
]);
}
/**
* @Route("/resa/{id}", name="palace_manager_resa_edit", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function editAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
$mails = $em->getRepository('FrameworkAppBundle:Mail')->findBy(['booking' => $booking->getId()], ['createdAt' => 'DESC']);
$venues = $em->getRepository('FrameworkAppBundle:Venue')->getNextVenues();
return $this->render('AdminBundle/Booking/edit.html.twig', [
'booking' => $booking,
'mails' => $mails,
'locale' => 'fr',
'venues' => $venues,
'iframe' => $request->get('iframe')
]);
}
/**
* @Route("/resa/mailsingle/{id}", name="palace_manager_resa_mailsingle", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function mailsingleAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$success = true;
$error = $slug = '';
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
// ENREGISTREMENT LOG MAIL
$mail = New Mail();
$mail->setBooking($booking);
$mail->setEmailTitle($request->get('emailTitle'));
$mail->setEmailContent($request->get('emailContent'));
$em->persist($mail);
$em->flush();
// FIN ENREGISTREMENT LOG MAIL
$title = $request->get('emailTitle');
$content = str_replace("\n\r", '<br>', $request->get('emailContent'));
$content = str_replace("\n", '<br>', $content);
//ENVOI EMAIL
$from = $globals['app_email_noreply'];
$to = $booking->getUser()->getEmail();
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
//->cc('cc@example.com')
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->subject($title)
// ->text($content)
->html($this->renderView(
'FrontBundle/Emails/general.html.twig', array(
'title' => $title,
'content' => $content,
)
));
$mailer->send($email);
//FIN ENVOI EMAIL
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa/mailload/{id}", name="palace_manager_resa_mailload", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function mailloadAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
$mails = $em->getRepository('FrameworkAppBundle:Mail')->findBy(['booking' => $booking->getId()], ['createdAt' => 'DESC']);
$mailsArr = [];
foreach ($mails as $key => $value) {
$content = str_replace("\n\r", '<br>', $value->getEmailContent());
$content = str_replace("\n", '<br>', $content);
$title = $value->getEmailTitle();
if($title == null){
$title = '';
}
$mailsArr[] = [
'title' => $title,
'content' => $content,
// 'date' => date("Y-m-d H:i", strtotime($value->getCreatedAt()->format('Y-m-d H:i').' + 2 hours')),
'date' => date("Y-m-d H:i", strtotime($value->getCreatedAt()->format('Y-m-d H:i'))),
];
}
$data = [
'mails' => $mailsArr
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa/save/{id}", name="palace_manager_resa_save", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function saveAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$success = true;
$error = $slug = '';
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
$booking->setOptions($request->get('options'));
$booking->setAmount(floatval(str_replace(',', '.', $request->get('amount'))));
$booking->setAmountShow(floatval(str_replace(',', '.', $request->get('amountShow'))));
$booking->setState(intval($request->get('state')));
$booking->setAction(NULL);
$booking->setVenueTitle($request->get('venueTitle'));
$booking->setEmailContent($request->get('emailContent'));
if( $request->get('venueId') != $booking->getVenue()->getId() ){
$venue = $em->getRepository('FrameworkAppBundle:Venue')->findOneById($request->get('venueId'));
if($venue){
$booking->setVenue($venue);
}
}
//FIX EXPORT ERROR CARD -> MANUAL VALIDATION
$state = intval($request->get('state'));
if( $booking->getPaymentType() == 'card' || $booking->getPaymentType() == 'klarna' || $booking->getPaymentType() == 'paypal' ){
if( $state == 2 || $state == 6 ){
$booking->setStatus('succeeded');
}
}
//END FIX
$booking->setAlerting(NULL);
$em->persist($booking);
$em->flush();
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/export-download/{id}", name="palace_manager_export_download", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportDownloadAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$export = $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$export->getName().'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($export->getFile())); //Absolute URL
ob_clean();
flush();
readfile($export->getFile()); //Absolute URL
exit();
}
/**
* @Route("/export-download-full/{id}", name="palace_manager_export_download_full", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportDownloadFullAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$export = $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
$csvFile = file($export->getFile());
$data = $ids = [];
foreach ($csvFile as $line) {
$data[] = str_getcsv($line);
}
array_shift($data);
array_pop($data);
foreach ($data as $key => $value) {
$tmp = explode(';', $value[0]);
$ids[] = $tmp[0];
}
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
// 'Type',
'Client',
'Adresse',
'Envoi',
'Commande',
'Total',
'AM',
'RS',
'Manuel'
// 'ID Stripe'
];
foreach ($ids as $key => $id) {
$order = $em->getRepository('FrameworkAppBundle:Order')->findOneByBaseId($id);
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'Courrier'){
$client = ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname'))."\n";
if($order->getInfo('company') != ''){
$client .= ucwords(strtolower($order->getInfo('company')))."\n";
}
$client .= $order->getUser()->getEmail()."\n".$order->getInfo('phone');
$address = $order->getInfo('address')."\n".$order->getInfo('zipcode').' '.$order->getInfo('city')."\n".$order->getInfo('country');
$cart = '';
$index = 1;
foreach ($order->getCart() as $key => $item) {
if($index > 1){
$cart .= "\n";
}
$cart .= $order->getBaseId().'-'.$index.' | '.$item->name->fr.' x'.$item->quantity;
if($item->for != ''){
$cart .= ' pour : '.$item->for;
}
if(isset($item->options) && $item->options != ''){
foreach ($item->options as $key2 => $option) {
$cart .= "\n".'+ '.$option->name.' x'.$option->qty;
}
}
$index++;
}
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
// 'BON C.',
$client,
$address,
$envoi,
// $order->getRecap(true),
$cart,
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
($order->getManual()) ? 'M' : '',
// $order->getResult()->id
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
}
}
//2D ROUND
foreach ($ids as $key => $id) {
$order = $em->getRepository('FrameworkAppBundle:Order')->findOneByBaseId($id);
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'E-Billet'){
$client = ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname'))."\n";
if($order->getInfo('company') != ''){
$client .= ucwords(strtolower($order->getInfo('company')))."\n";
}
$client .= $order->getUser()->getEmail()."\n".$order->getInfo('phone');
$address = $order->getInfo('address')."\n".$order->getInfo('zipcode').' '.$order->getInfo('city')."\n".$order->getInfo('country');
$cart = '';
$index = 1;
foreach ($order->getCart() as $key => $item) {
if($index > 1){
$cart .= "\n";
}
$cart .= $order->getBaseId().'-'.$index.' | '.$item->name->fr.' x'.$item->quantity;
if($item->for != ''){
$cart .= ' pour : '.$item->for;
}
if(isset($item->options) && $item->options != ''){
foreach ($item->options as $key2 => $option) {
$cart .= "\n".'+ '.$option->name.' x'.$option->qty;
}
}
$index++;
}
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
// 'BON C.',
$client,
$address,
$envoi,
// $order->getRecap(true),
$cart,
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
($order->getManual()) ? 'M' : '',
// $order->getResult()->id
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'',
'Export détaillé : '.$date,
$total,
$total_am,
$total_rs,
''
];
//ENREGISTREMENT DU CSV
$path = str_replace('.csv', '_full.csv', $export->getFile());
$name = str_replace('.csv', '_full.csv', $export->getName());
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$name.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path)); //Absolute URL
ob_clean();
flush();
readfile($path); //Absolute URL
exit();
}
/**
* @Route("/resa-exports", name="palace_manager_resa_exports", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportsResaAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$exports = $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'resa'], ['createdAt' => 'DESC']);
return $this->render('AdminBundle/Booking/exports.html.twig', [
'exports' => $exports,
'locale' => 'fr',
]);
}
/**
* @Route("/resa-exports-ticketing", name="palace_manager_resa_exports_ticketing", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportsTicketingResaAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$exports = $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'ticketing'], ['createdAt' => 'DESC']);
return $this->render('AdminBundle/Booking/exports_ticketing.html.twig', [
'exports' => $exports,
'locale' => 'fr',
]);
}
/**
* @Route("/resa-exports-generate", name="palace_manager_resa_exports_generate", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGenerateAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => NULL, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
//ENREGISTREMENT DU CSV
$path = $globals['export_folder'].'exports_booking/R_'.$date.'.csv';
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
//ENREGISTREMENT BASE
$export = new Export();
$export->setType('resa');
$export->setFile($path);
$export->setName('R_'.$date.'.csv');
$em->persist($export);
$em->flush();
//ENVOI EMAIL COMPTA
$from = $globals['app_email_noreply'];
$to = $globals['app_email_compta'];
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
->cc($globals['app_email_contact'])
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->attachFromPath($path)
->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
$mailer->send($email);
//FIN ENVOI EMAIL COMPTA
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa-exports-generate-preview", name="palace_manager_resa_exports_generate_preview", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGeneratePreviewAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = $html = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => NULL, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
$html = '<table class="exporting"><tbody>';
foreach ($rows as $key => $row) {
$html .= '<tr>';
foreach ($row as $key2 => $column) {
$html .= '<td>'.$column.'</td>';
}
$html .= '</tr>';
}
$html .= '</tbody></table>';
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success,
'html' => $html
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa-exports-generate-ticketing", name="palace_manager_resa_exports_generate_ticketing", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGenerateTicketingAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
//ENREGISTREMENT DU CSV
$path = $globals['export_folder'].'exports_booking/T_'.$date.'.csv';
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
//ENREGISTREMENT BASE
$export = new Export();
$export->setType('ticketing');
$export->setFile($path);
$export->setName('T_'.$date.'.csv');
$em->persist($export);
$em->flush();
//ENVOI EMAIL COMPTA
$from = $globals['app_email_noreply'];
$to = $globals['app_email_compta'];
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
->cc($globals['app_email_contact'])
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->attachFromPath($path)
->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
$mailer->send($email);
//FIN ENVOI EMAIL COMPTA
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa-exports-generate-ticketing-preview", name="palace_manager_resa_exports_generate_ticketing_preview", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGenerateTicketingPreviewAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = $html = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
$html = '<table class="exporting"><tbody>';
foreach ($rows as $key => $row) {
$html .= '<tr>';
foreach ($row as $key2 => $column) {
$html .= '<td>'.$column.'</td>';
}
$html .= '</tr>';
}
$html .= '</tbody></table>';
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success,
'html' => $html
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/order-exports", name="palace_manager_order_exports", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportsOrderAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$exports = $em->getRepository('FrameworkAppBundle:Export')->findBy(['type' => 'order'], ['createdAt' => 'DESC']);
return $this->render('AdminBundle/Order/exports.html.twig', [
'exports' => $exports,
'locale' => 'fr',
]);
}
/**
* @Route("/order-exports-generate", name="palace_manager_order_exports_generate", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportOrderGenerateAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Envoi',
'Commande',
'Total',
'AM',
'RS',
'ID Stripe',
'Manuel'
];
$orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['exported' => NULL, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['manual' => 'DESC', 'paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($orders) > 0 ){
foreach ($orders as $key => $order) {
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'Courrier'){
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
'BON C.',
$order->getPaymentType(),
ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
$envoi,
$order->getRecap(true),
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
$order->getResult()->id,
($order->getManual()) ? 'M' : '',
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
$order->setState(6);
$order->setExported(1);
$em->persist($order);
$em->flush();
}
}
//2d ROUND
foreach ($orders as $key => $order) {
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'E-Billet'){
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
'BON C.',
$order->getPaymentType(),
ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
$envoi,
$order->getRecap(true),
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
$order->getResult()->id,
($order->getManual()) ? 'M' : '',
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
$order->setState(6);
$order->setExported(1);
$em->persist($order);
$em->flush();
}
}
$rows[] = [
'',
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
'',
''
];
//ENREGISTREMENT DU CSV
$path = $globals['export_folder'].'exports_order/B_'.$date.'.csv';
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
//ENREGISTREMENT BASE
$export = new Export();
$export->setType('order');
$export->setFile($path);
$export->setName('B_'.$date.'.csv');
$em->persist($export);
$em->flush();
//ENVOI EMAIL COMPTA
$from = $globals['app_email_noreply'];
$to = $globals['app_email_compta'];
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
->cc($globals['app_email_contact'])
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->attachFromPath($path)
->subject('Nouvel export BONS CADEAUX CB Stripe '.$date)
->text(nl2br('Nouvel export BONS CADEAUX CB Stripe généré le '.$date));
$mailer->send($email);
//FIN ENVOI EMAIL COMPTA
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/order-exports-generate-preview", name="palace_manager_order_exports_generate_preview", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportOrderGeneratePreviewAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = $html = '';
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Envoi',
'Commande',
'Total',
'AM',
'RS',
'ID Stripe',
'Manuel'
];
$orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['exported' => NULL, 'status' => 'succeeded', 'paymentType' => ['card','klarna','paypal'] ], ['manual' => 'DESC', 'paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($orders) > 0 ){
foreach ($orders as $key => $order) {
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'Courrier'){
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
'BON C.',
$order->getPaymentType(),
ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
$envoi,
$order->getRecap(true),
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
$order->getResult()->id,
($order->getManual()) ? 'M' : '',
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
}
}
//2d ROUND
foreach ($orders as $key => $order) {
$envoi = 'E-Billet';
foreach ($order->getCartArr2() as $item_key => $item) {
if( $item['gift'] == 'true' ){
$envoi = 'Courrier';
}
}
if($envoi == 'E-Billet'){
$rows[] = [
$order->getBaseId(),
date('d/m/Y', $order->getResult()->created),
'BON C.',
$order->getPaymentType(),
ucwords(strtolower($order->getInfo('firstname'))).' '.strtoupper($order->getInfo('lastname')),
$envoi,
$order->getRecap(true),
($order->getAmount() + $order->getAmountShow()),
$order->getAmount(),
$order->getAmountShow(),
$order->getResult()->id,
($order->getManual()) ? 'M' : '',
];
$total = $total + ($order->getAmount() + $order->getAmountShow());
$total_am = $total_am + $order->getAmount();
$total_rs = $total_rs + $order->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
'',
''
];
$html = '<table class="exporting"><tbody>';
foreach ($rows as $key => $row) {
$html .= '<tr>';
foreach ($row as $key2 => $column) {
$html .= '<td>'.$column.'</td>';
}
$html .= '</tr>';
}
$html .= '</tbody></table>';
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success,
'html' => $html
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa/sendPayment/{id}", name="palace_manager_resa_sendPayment", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function sendPaymentAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$success = true;
$error = $slug = '';
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneById($id);
$booking->setOptions($request->get('options'));
$booking->setAmount(floatval(str_replace(',', '.', $request->get('amount'))));
$booking->setAmountShow(floatval(str_replace(',', '.', $request->get('amountShow'))));
$booking->setState(1);
$booking->setVenueTitle($request->get('venueTitle'));
$booking->setEmailContent($request->get('emailContent'));
if($request->get('reminder') == 'reminder'){
$booking->setMailedCount( $booking->getMailedCount() + 1 );
}
$em->persist($booking);
$em->flush();
$subject = 'Votre réservation Royal Palace : Instructions de règlement';
$title = 'Votre réservation Royal Palace : Instructions de règlement';
$content = str_replace("\n", '<br>', $booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'fr/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Procéder au paiement</strong></a>';
if($request->get('reminder') == 'reminder'){
$subject = 'Relance commande #'.$booking->getBaseId().' | Votre réservation Royal Palace : Instructions de règlement';
$title = 'Relance commande #'.$booking->getBaseId().' | Votre réservation Royal Palace : Instructions de règlement';
}
if($booking->getLang() == 'de'){
$subject = 'Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
$title = 'Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
$content = str_replace("\n", '<br>', $booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'de/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Mit der Zahlung fortfahren</strong></a>';
if($request->get('reminder') == 'reminder'){
$subject = 'Zahlungserinnerung Bestellung #'.$booking->getBaseId().' | Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
$title = 'Zahlungserinnerung Bestellung #'.$booking->getBaseId().' | Ihre Royal Palace Reservierung: Hinweise zur Zahlung';
}
}
if($booking->getLang() == 'en'){
$subject = 'Your Royal Palace reservation: Payment instructions';
$title = 'Your Royal Palace reservation: Payment instructions';
$content = str_replace("\n", '<br>', $booking->getEmailContent()).'</p><br><a href="'.$globals['app_email_domain'].'en/mon-compte/paiement/'.$booking->getToken().'" style="text-align:center; width:100%; font-size: 18px; display:block;"><strong>Proceed to payment</strong></a>';
if($request->get('reminder') == 'reminder'){
$subject = 'Reminder order #'.$booking->getBaseId().' | Your Royal Palace reservation: Payment instructions';
$title = 'Reminder order #'.$booking->getBaseId().' | Your Royal Palace reservation: Payment instructions';
}
}
//ENVOI EMAIL
$from = $globals['app_email_noreply'];
$to = $booking->getUser()->getEmail();
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
//->cc('cc@example.com')
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->subject($subject)
->text($booking->getEmailContent())
->html($this->renderView(
'FrontBundle/Emails/general.html.twig', array(
'title' => $title,
'content' => $content,
)
));
try{
$mailer->send($email);
}
catch(\Exception $e){
$data = [
'error' => 'Une erreur est survenue. Veuillez vérifier l\'adresse email. : '.$e->getMessage(),
'success' => false
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
//FIN ENVOI EMAIL
$booking->setMailedPay(1);
$em->persist($booking);
$em->flush();
// ENREGISTREMENT LOG MAIL
$mail = New Mail();
$mail->setBooking($booking);
$mail->setEmailTitle($title);
$mail->setEmailContent($content);
$em->persist($mail);
$em->flush();
// FIN ENREGISTREMENT LOG MAIL
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/order2", name="palace_manager_order2_index")
*/
public function indexOrderAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['status' => ['manual', 'succeeded']], ['id' => 'DESC']);
return $this->render('AdminBundle/Order/index.html.twig', [
'orders' => $orders,
]);
}
/**
* @Route("/order", name="palace_manager_order_index")
*/
public function indexOrder2Action(Request $request)
{
$em = $this->getDoctrine()->getManager();
// $orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['status' => ['manual', 'succeeded']], ['id' => 'DESC']);
$orders = [];
return $this->render('AdminBundle/Order/index2.html.twig', [
'orders' => $orders,
]);
}
/**
* @Route("/order/load", name="palace_manager_order_load")
*/
public function orderLoadAction(Request $request, $id = null)
{
$em = $this->getDoctrine()->getManager();
$success = true;
$error = '';
$isAjax = $request->isXMLHttpRequest();
if (!$isAjax) {
return $this->redirectToRoute('palace_manager_resa_index');
}
$currentPage = intval( $request->get('page') );
if($currentPage == null){
$currentPage = 1;
}
$limit = 50;
if($request->get('search') == ''){
if($request->get('filter') != 'all' && $request->get('filter') != NULL){
$orders = $em->getRepository('FrameworkAppBundle:Order')->findBy(['state' => $request->get('filter')], ['id' => 'DESC'], $limit, ($currentPage-1) * $limit);
$ordersNbr = $em->getRepository('FrameworkAppBundle:Order')->count(['state' => $request->get('filter')]);
} else {
$orders = $em->getRepository('FrameworkAppBundle:Order')->findBy([], ['id' => 'DESC'], $limit, ($currentPage-1) * $limit);
$ordersNbr = $em->getRepository('FrameworkAppBundle:Order')->count([]);
}
} else {
$orders = $em->getRepository('FrameworkAppBundle:Order')->search($request->get('search'));
$ordersNbr = sizeof($orders);
}
$pagesNbr = ceil($ordersNbr / $limit);
$start = ($currentPage-1) * $limit + 1;
$end = ($currentPage) * $limit;
if($end > $ordersNbr){
$end = $ordersNbr;
}
$orderArr = [];
foreach ($orders as $key => $order) {
// $createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getCreatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
// $updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getUpdatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
$createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getCreatedAt()->format('Y-m-d H:i:s'))));
$updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($order->getUpdatedAt()->format('Y-m-d H:i:s'))));
$sending = '<span class="badge badge-secondary">E-Billet</span>';
if($order->getCart()){
foreach ($order->getCart() as $key => $item) {
if($item->gift == 'true'){
$sending = '<span class="badge badge-primary">Courrier</span>';
}
}
}
$orderArr[] = [
'id' => $order->getId(),
'email' => $order->getUser()->getEmail(),
'old_id' => $order->getOldId(),
'base_id' => $order->getBaseId(),
'infos' => $order->getInfos(),
'cart' => $order->getCart(),
'state' => $order->getState(),
'status' => $order->getStatus(),
'paymentType' => $order->getPaymentType(),
'amountTotal' => $order->getAmountTotal(),
'stateStrAdmin' => $order->getStateStrAdmin(),
'manual' => intval($order->getManual()),
'sending' => $sending,
'createdAt' => $createdAt,
'updatedAt' => $updatedAt,
];
}
$data = [
'error' => $error,
'success' => $success,
'currentPage' => $currentPage,
'ordersNbr' => $ordersNbr,
'pagesNbr' => $pagesNbr,
'orders' => $orderArr,
'start' => $start,
'end' => $end,
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/order/{id}", name="palace_manager_order_edit", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function editOrderAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$order = $em->getRepository('FrameworkAppBundle:Order')->findOneById($id);
$cartTest = json_decode('{"11_1685090430143":{"id":"11_1685090430143","image":"image_main.jpg","name":{"de":"Formule Étincelle","en":"Formule Étincelle","fr":"Formule Étincelle"},"slug":"bon-cadeau-4","price":100,"quantity":1,"gift":true,"for":"","attribute":null,"options":[{"id":7,"name":"Bon d’achat boutique 10€ ","qty":2,"sub_total":20},{"id":8,"name":"Bon d’achat boutique 20€ ","qty":1,"sub_total":20}]}}', true);
return $this->render('AdminBundle/Order/edit.html.twig', [
'cartTest' => $cartTest,
'order' => $order,
]);
}
/**
* @Route("/order/save/{id}", name="palace_manager_order_save", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function saveOrderAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$success = true;
$error = $slug = '';
$order = $em->getRepository('FrameworkAppBundle:Order')->findOneById($id);
$order->setState(intval($request->get('state')));
$em->persist($order);
$em->flush();
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/routine", name="palace_manager_routine_index")
*/
public function routineAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['id' => 'ASC']);
// foreach ($bookings as $key => $booking) {
// $booking->setOldId($booking->getBaseId());
// $em->persist($booking);
// $em->flush();
// }
// $id=0;
// foreach ($bookings as $key => $booking) {
// $id++;
// $booking->setBaseId($id);
// $em->persist($booking);
// $em->flush();
// }
// dump($bookings);
echo 'DONE';
exit;
}
/**
* @Route("/resa_load", name="framework_admin_resa_load")
*/
public function loadAction(Request $request, $id = null)
{
$em = $this->getDoctrine()->getManager();
$success = true;
$error = '';
$isAjax = $request->isXMLHttpRequest();
if (!$isAjax) {
return $this->redirectToRoute('palace_manager_resa_index');
}
$future = strtotime('+4 day');
$currentPage = intval( $request->get('page') );
if($currentPage == null){
$currentPage = 1;
}
$limit = 50;
if($request->get('search') == ''){
if($request->get('filter') != 'all' && $request->get('filter') != NULL){
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['state' => $request->get('filter')], ['alerting' => 'DESC', 'id' => 'DESC'], $limit, ($currentPage-1) * $limit);
$bookingsNbr = $em->getRepository('FrameworkAppBundle:Booking')->count(['state' => $request->get('filter')]);
} else {
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy([], ['alerting' => 'DESC', 'id' => 'DESC'], $limit, ($currentPage-1) * $limit);
$bookingsNbr = $em->getRepository('FrameworkAppBundle:Booking')->count([]);
}
} else {
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->search($request->get('search'));
$bookingsNbr = sizeof($bookings);
}
$pagesNbr = ceil($bookingsNbr / $limit);
$start = ($currentPage-1) * $limit + 1;
$end = ($currentPage) * $limit;
if($end > $bookingsNbr){
$end = $bookingsNbr;
}
$bookingArr = [];
foreach ($bookings as $key => $booking) {
// $createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getCreatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
// $updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getUpdatedAt()->format('Y-m-d H:i:s'). ' +2 hours')));
$createdAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getCreatedAt()->format('Y-m-d H:i:s'))));
$updatedAt = new \DateTime(date('Y-m-d H:i:s', strtotime($booking->getUpdatedAt()->format('Y-m-d H:i:s'))));
$bg = '';
if($booking->getVenue()->getStart()->format('U') < $future){
if(in_array($booking->getState(), [0,1,5])){
$bg = 'bg-danger';
}
}
if($booking->getAlerting()){
$bg = 'bg-warning';
}
if($booking->getIsflash()){
$isflash = '<br> (Ticketing)';
} else {
$isflash = '';
}
$exporting = '';
if($booking->getExported() == NULL && $booking->getIsflash() == NULL && $booking->getStatus() == 'succeeded'){
if($booking->getPaymentType() == 'card' || $booking->getPaymentType() == 'klarna' || $booking->getPaymentType() == 'paypal'){
$exporting = 'yes';
}
}
$bookingArr[] = [
'id' => $booking->getId(),
'email' => $booking->getUser()->getEmail(),
'old_id' => $booking->getOldId(),
'base_id' => $booking->getBaseId(),
'infos' => $booking->getInfos(),
'cart' => $booking->getCart(),
'state' => $booking->getState(),
'action' => $booking->getAction(),
'venueTitle' => $booking->getVenuetitle(),
'paymentType' => $booking->getPaymentType(),
'amountTotal' => $booking->getAmountTotal(),
'stateStrAdmin' => $booking->getStateStrAdmin(),
'isflash' => $isflash,
'createdAt' => $createdAt,
'updatedAt' => $updatedAt,
'exporting' => $exporting,
'bg' => $bg
];
}
$data = [
'error' => $error,
'success' => $success,
'currentPage' => $currentPage,
'bookingsNbr' => $bookingsNbr,
'pagesNbr' => $pagesNbr,
'bookings' => $bookingArr,
'start' => $start,
'end' => $end,
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa_refresh", name="framework_admin_resa_refresh")
*/
public function refreshAction(Request $request, $id = null)
{
$em = $this->getDoctrine()->getManager();
$success = true;
$error = '';
$isAjax = $request->isXMLHttpRequest();
if (!$isAjax) {
return $this->redirectToRoute('palace_manager_resa_index');
}
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $request->get('stateArr')]);
$refreshArr = [];
foreach ($bookings as $key => $booking) {
$refreshArr[$booking->getId()]['state'] = $booking->getState();
$refreshArr[$booking->getId()]['reminder'] = $booking->getMailedCount();
$future = strtotime('+4 day');
$bg = '';
if($booking->getVenue()->getStart()->format('U') < $future){
if(in_array($booking->getState(), [0,1,5])){
$bg = 'bg-danger';
}
}
if($booking->getAlerting()){
$bg = 'bg-warning';
}
$refreshArr[$booking->getId()]['bg'] = $bg;
}
$data = [
'refreshArr' => $refreshArr,
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/export-download-full-resa/{id}", name="palace_manager_export_download_full_resa", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportDownloadFullResaAction(Request $request, $id = NULL)
{
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$export = $em->getRepository('FrameworkAppBundle:Export')->findOneById($id);
$csvFile = file($export->getFile());
$data = $ids = [];
foreach ($csvFile as $line) {
$data[] = str_getcsv($line);
}
array_shift($data);
array_pop($data);
foreach ($data as $key => $value) {
$tmp = explode(';', $value[0]);
$ids[] = $tmp[0];
}
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'KDO',
'Type',
'Client',
'Date',
'Total',
'AM',
'RS',
// 'ID Stripe'
];
foreach ($ids as $key => $id) {
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneBy(['genId' => $id]);
$gift = '';
if($booking->getInfo('gift') == 'true'){
$gift = 'KDO : '.$booking->getInfo('gift_user');
}
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
$gift,
'RESA',
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
// $result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
//2D ROUND
foreach ($ids as $key => $id) {
$booking = $em->getRepository('FrameworkAppBundle:Booking')->findOneBy(['genId' => $id]);
$gift = '';
if($booking->getInfo('gift') == 'true'){
$gift = 'KDO : '.$booking->getInfo('gift_user');
}
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
$gift,
'RESA',
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
// $result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'Export détaillé : '.$date,
$total,
$total_am,
$total_rs,
''
];
//ENREGISTREMENT DU CSV
$path = str_replace('.csv', '_full.csv', $export->getFile());
$name = str_replace('.csv', '_full.csv', $export->getName());
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$name.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path)); //Absolute URL
ob_clean();
flush();
readfile($path); //Absolute URL
exit();
}
/**
* @Route("/resa-exports-generate-manual", name="palace_manager_resa_exports_generate_manual", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGenerateManualAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = '';
$ids = $request->get('manualExport');
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
// $bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $ids], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
$booking->setState(6);
$booking->setExported(1);
$em->persist($booking);
$em->flush();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
//ENREGISTREMENT DU CSV
$path = $globals['export_folder'].'exports_booking/R_'.$date.'.csv';
$fp = fopen($path, 'w'); // open in write only mode (write at the start of the file)
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($rows as $row) {
fputcsv($fp, $row, ";");
}
fclose($fp);
//ENREGISTREMENT BASE
$export = new Export();
$export->setType('resa');
$export->setFile($path);
$export->setName('R_'.$date.'.csv');
$em->persist($export);
$em->flush();
//ENVOI EMAIL COMPTA
$from = $globals['app_email_noreply'];
$to = $globals['app_email_compta'];
$contact = $globals['app_email_contact'];
$email = (new Email())
->from($from)
->to($to)
->cc($globals['app_email_contact'])
//->bcc('bcc@example.com')
->replyTo($contact)
//->priority(Email::PRIORITY_HIGH)
->attachFromPath($path)
->subject('Nouvel export RESERVATIONS CB Stripe '.$date)
->text(nl2br('Nouvel export RESERVATIONS CB Stripe généré le '.$date));
$mailer->send($email);
//FIN ENVOI EMAIL COMPTA
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/resa-exports-generate-manual-preview", name="palace_manager_resa_exports_generate_manual_preview", requirements={"id" = "([a-z\-0-9]+)"})
*/
public function exportResaGenerateManualPreviewAction(Request $request, $id = NULL, MailerInterface $mailer)
{
$success = false;
$error = $slug = $html = '';
$ids = $request->get('manualExport');
$em = $this->getDoctrine()->getManager();
$globals = $this->get("twig")->getGlobals();
$total = $total_rs = $total_am = 0;
$date = date('Y-m-d_H-i-s');
$rows = [];
$rows[] = [
'ID',
'Date de paiement',
'Type',
'Paiement',
'Client',
'Date',
'Total',
'AM',
'RS',
'ID Stripe'
];
// $bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['exported' => NULL, 'isflash' => 1, 'status' => 'succeeded', 'paymentType' => ['card','klarna'] ], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
$bookings = $em->getRepository('FrameworkAppBundle:Booking')->findBy(['id' => $ids], ['paymentType' => 'DESC', 'createdAt' => 'ASC']);
if( sizeof($bookings) > 0 ){
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') == 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
//2D ROUND
foreach ($bookings as $key => $booking) {
if($booking->getInfo('gift') != 'true'){
if( $booking->getResult() == null ){
$created = $booking->getCreatedAt()->format('d/m/Y');
$result_id = '';
} else {
$created = date('d/m/Y', $booking->getResult()->created);
$result_id = $booking->getResult()->id;
}
$rows[] = [
$booking->getBaseId(),
$created,
'RESA (T)',
$booking->getPaymentType(),
ucwords(strtolower($booking->getInfo('firstname'))).' '.strtoupper($booking->getInfo('lastname')),
$booking->getVenueTitle(),
($booking->getAmount() + $booking->getAmountShow()),
$booking->getAmount(),
$booking->getAmountShow(),
$result_id
];
$total = $total + ($booking->getAmount() + $booking->getAmountShow());
$total_am = $total_am + $booking->getAmount();
$total_rs = $total_rs + $booking->getAmountShow();
}
}
$rows[] = [
'',
'',
'',
'',
'Export : '.$date,
$total,
$total_am,
$total_rs,
''
];
$html = '<table class="exporting"><tbody>';
foreach ($rows as $key => $row) {
$html .= '<tr>';
foreach ($row as $key2 => $column) {
$html .= '<td>'.$column.'</td>';
}
$html .= '</tr>';
}
$html .= '</tbody></table>';
$success = true;
} else {
$error = 'Aucun nouveau paiement à exporter';
}
$data = [
'error' => $error,
'success' => $success,
'html' => $html
];
$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}