Add new Draft
git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3476 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
parent
9421cf8c5c
commit
b75c88bf96
5 changed files with 398 additions and 114 deletions
|
|
@ -79,9 +79,6 @@ class BookingController extends Controller
|
|||
$ret .= "<hr>";
|
||||
}
|
||||
}
|
||||
echo $ret;
|
||||
die();
|
||||
|
||||
}
|
||||
|
||||
$travelProgram = $travelProgramPage->getTravelProgram();
|
||||
|
|
@ -143,8 +140,6 @@ class BookingController extends Controller
|
|||
$bookingPriceInfo = [];
|
||||
$totalPrice = $this->calculatePrice($travelDate, $bookingRequest, $travelProgram->getCategory()->getId(), $travelProgram->getDepositPercent(), $htmlSummary, $bookingPriceInfo);
|
||||
|
||||
|
||||
|
||||
if ($action == '/buchen')
|
||||
{
|
||||
$breadcrumbEntries = Util::createBreadcrumb($travelProgramPage);
|
||||
|
|
@ -179,6 +174,8 @@ class BookingController extends Controller
|
|||
{
|
||||
$crmBookingUrl = preg_replace('/\\/api/', '', $crmBookingUrl).'/edit';
|
||||
}
|
||||
var_dump($crmBookingUrl);
|
||||
die();
|
||||
|
||||
$this->get('mailer')->send(\Swift_Message::newInstance()
|
||||
->setSubject('Ihr Buchungsauftrag bei STERN TOURS')
|
||||
|
|
|
|||
|
|
@ -263,7 +263,6 @@ class TravelProgram
|
|||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\TravelArrivalPoint
|
||||
*
|
||||
|
|
@ -340,6 +339,13 @@ class TravelProgram
|
|||
*/
|
||||
private $periods;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelProgramDrafts", mappedBy="program")
|
||||
*/
|
||||
private $drafts;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelDeparturePoint", mappedBy="program")
|
||||
*/
|
||||
|
|
@ -1496,6 +1502,43 @@ class TravelProgram
|
|||
return $this->periods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add drafts
|
||||
*
|
||||
* @param \AppBundle\Entity\TravelProgramDrafts $draft
|
||||
*
|
||||
* @return TravelProgram
|
||||
*/
|
||||
public function addDraft(\AppBundle\Entity\TravelProgramDrafts $draft)
|
||||
{
|
||||
$this->drafts[] = $draft;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove draft
|
||||
*
|
||||
* @param \AppBundle\Entity\TravelProgramDrafts $draft
|
||||
*/
|
||||
public function removeDraft(\AppBundle\Entity\TravelProgramDrafts $draft)
|
||||
{
|
||||
$this->drafts->removeElement($draft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $this->drafts
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection|TravelProgramDrafts[]
|
||||
*/
|
||||
public function getDrafts()
|
||||
{
|
||||
return $this->drafts;
|
||||
}
|
||||
|
||||
|
||||
public function getIsMediated()
|
||||
{
|
||||
return $this->programType == TravelProgram::MEDIATED_PROGRAM_TYPE;
|
||||
|
|
|
|||
103
trunk/src/AppBundle/Entity/TravelProgramDrafts.php
Normal file
103
trunk/src/AppBundle/Entity/TravelProgramDrafts.php
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* TravelProgramDrafts
|
||||
*
|
||||
* @ORM\Table(name="travel_program_drafts", indexes={@ORM\Index(name="travel_program_drafts_ibfk_1", columns={"travel_program_id"})})
|
||||
* @ORM\Entity
|
||||
*/
|
||||
|
||||
class TravelProgramDrafts
|
||||
{
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="weekdays", type="string", length=255, nullable=true)
|
||||
*/
|
||||
private $weekdays;
|
||||
|
||||
/**
|
||||
* @var \AppBundle\Entity\TravelProgram
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelProgram", inversedBy="drafts")
|
||||
* @ORM\JoinColumns({
|
||||
* @ORM\JoinColumn(name="travel_program_id", referencedColumnName="id")
|
||||
* })
|
||||
*/
|
||||
private $program;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set program
|
||||
*
|
||||
* @param \AppBundle\Entity\TravelProgram $program
|
||||
*
|
||||
* @return TravelProgramDrafts
|
||||
*/
|
||||
public function setProgram(\AppBundle\Entity\TravelProgram $program = null)
|
||||
{
|
||||
$this->program = $program;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get program
|
||||
*
|
||||
* @return \AppBundle\Entity\TravelProgram
|
||||
*/
|
||||
public function getProgram()
|
||||
{
|
||||
return $this->program;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set weekdays
|
||||
*
|
||||
* @param string TravelProgramDrafts
|
||||
*
|
||||
* @return TravelProgramDrafts
|
||||
*/
|
||||
public function setWeekdays($weekdays)
|
||||
{
|
||||
$this->weekdays = $weekdays;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get weekdays
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWeekdays()
|
||||
{
|
||||
return $this->weekdays;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +25,11 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
{
|
||||
$tp = $travelDate->getTravelProgram();
|
||||
$startDateStr = $travelDate->getStart()->format('Y-m-d');
|
||||
if(count($tp->getDrafts()) > 0){
|
||||
$newDrafts = true;
|
||||
}else{
|
||||
$newDrafts = false;
|
||||
}
|
||||
|
||||
$lead = $this->createLead($bookingRequest, $travelDate);
|
||||
|
||||
|
|
@ -33,7 +38,7 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
$this->warn('Failed creating lead in CRM Lead', $bookingRequest, $travelDate, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
$bookingUrl = $this->createBooking($bookingRequest, $travelDate, $bookingPriceInfo, $lead['customer_id'], $lead['id']);
|
||||
$bookingUrl = $this->createBooking($bookingRequest, $travelDate, $bookingPriceInfo, $lead['customer_id'], $lead['id'], $newDrafts);
|
||||
if ($bookingUrl === false)
|
||||
{
|
||||
$this->warn('Failed creating booking in CRM Booking', $bookingRequest, $travelDate, Logger::ERROR);
|
||||
|
|
@ -87,9 +92,115 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
//has drafts - get the new Drafts from the CRM v3
|
||||
if($newDrafts){
|
||||
$this->createNewDrafts($bookingUrl, $bookingRequest, $tp, $travelDate, $bookingPriceInfo, $startDateStr);
|
||||
}else{
|
||||
//no new Drafts - create the old Arrangements
|
||||
$this->createOldArrangement($bookingUrl, $bookingRequest, $tp, $travelDate, $bookingPriceInfo, $startDateStr);
|
||||
}
|
||||
|
||||
foreach ($bookingPriceInfo['insurances'] as $insuranceInfo) {
|
||||
$this->createServiceItem($bookingUrl, [
|
||||
'travel_company_id' => 30,
|
||||
'service_price' => $insuranceInfo['count'] * $insuranceInfo['insurancePriceValue'],
|
||||
'name' => $insuranceInfo['count'] . 'x ' . $insuranceInfo['insurance']->getName() . ' (' .
|
||||
$insuranceInfo['insurancePrice']->getCode() . ')',
|
||||
'commission' => round(($insuranceInfo['count'] * $insuranceInfo['insurancePriceValue']) * 20 / 100, 2),
|
||||
'travel_date' => $startDateStr,
|
||||
]);
|
||||
//child
|
||||
if ($insuranceInfo['countChild'] > 0) {
|
||||
$this->createServiceItem($bookingUrl, [
|
||||
'travel_company_id' => 30,
|
||||
'service_price' => $insuranceInfo['countChild'] * $insuranceInfo['insuranceChildPriceValue'],
|
||||
'name' => $insuranceInfo['countChild'] . 'x ' . $insuranceInfo['insurance']->getName() . ' (' .
|
||||
$insuranceInfo['insuranceChildPrice']->getCode() . ')',
|
||||
'commission' => round(($insuranceInfo['countChild'] * $insuranceInfo['insuranceChildPriceValue']) * 20 / 100, 2),
|
||||
'travel_date' => $startDateStr,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bookingUrl;
|
||||
}
|
||||
|
||||
private function createNewDrafts($bookingUrl, $bookingRequest, $tp, $travelDate, $bookingPriceInfo, $startDateStr){
|
||||
//make an request omn the new API
|
||||
$endDateStr = $travelDate->getEnd()->format('Y-m-d');
|
||||
|
||||
$rooms = [];
|
||||
$i = 0;
|
||||
foreach ($bookingPriceInfo['rooms'] as $room)
|
||||
{
|
||||
$rooms[$i] = [
|
||||
'name' => $room['name'],
|
||||
'price_adult' => $room['price'],
|
||||
'adult' => $room['adults'],
|
||||
'children' => 0,
|
||||
'price_children' => 0,
|
||||
];
|
||||
if($room['children'] > 0){
|
||||
$rooms[$i]['children'] = $room['children'];
|
||||
$rooms[$i]['price_children'] = $room['price_children'];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$class_options = [];
|
||||
// Actually: extra_category
|
||||
foreach ($bookingPriceInfo['classOptions'] as $classOption)
|
||||
{
|
||||
$class_options[] = [
|
||||
'name' => $classOption['name'],
|
||||
'price' => $classOption['price'],
|
||||
'count' => $classOption['count'],
|
||||
];
|
||||
}
|
||||
$travel_options = [];
|
||||
$i = 0;
|
||||
foreach ($bookingRequest->getTravelOptions() as $option)
|
||||
{
|
||||
$travel_options[$i] = [
|
||||
'name' => $option->getName(),
|
||||
'price_adult' => $option->getPrice(),
|
||||
'adult' => $bookingRequest->getTravelerCount(),
|
||||
'children' => 0,
|
||||
'price_children' => 0,
|
||||
];
|
||||
if($option->getPriceChildren() > 0){
|
||||
$travel_options[$i]['children'] = $bookingRequest->getChildrenCount();
|
||||
$travel_options[$i]['price_children'] = $option->getPriceChildren();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$resp = $this->httpPostAPIv3('create_drafts', [
|
||||
'travel_program_id' => $tp->getId(),
|
||||
'comfort' => $bookingRequest->getComfort(),
|
||||
'booking_id' => array_values(array_slice(explode("/", $bookingUrl), -1))[0],
|
||||
'request_date' => (new \DateTime())->format('Y-m-d'),
|
||||
'startDateStr' => $startDateStr,
|
||||
'endDateStr' => $endDateStr,
|
||||
'departure' => $bookingPriceInfo['departure']->getName(),
|
||||
'departure_extra_charge' => $bookingPriceInfo['departure']->getExtraCharge(),
|
||||
'traveler' => ($bookingRequest->getTravelerCount() + $bookingRequest->getChildrenCount()),
|
||||
'title' => $tp->getTitle(),
|
||||
'number' => $travelDate->getName(),
|
||||
'rooms' => $rooms,
|
||||
'class_options' => $class_options,
|
||||
'travel_options' => $travel_options,
|
||||
]);
|
||||
if (count($resp) == 0)
|
||||
{
|
||||
$this->warn('Failed retrieving newly created lead object', $bookingRequest, $travelDate);
|
||||
}
|
||||
return $resp;
|
||||
|
||||
}
|
||||
|
||||
private function createOldArrangement($bookingUrl, $bookingRequest, $tp, $travelDate, $bookingPriceInfo, $startDateStr){
|
||||
$viewPosition = 100;
|
||||
$viewPositionPrice = 50;
|
||||
$endDateStr = $travelDate->getEnd()->format('Y-m-d');
|
||||
|
|
@ -153,6 +264,7 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
'data_s' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->createArrangement($bookingUrl, $arrangementDefaults + [
|
||||
'type_id' => 5, // Hotel
|
||||
'type_s' => 'Hotel',
|
||||
|
|
@ -211,31 +323,6 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($bookingPriceInfo['insurances'] as $insuranceInfo) {
|
||||
$this->createServiceItem($bookingUrl, [
|
||||
'travel_company_id' => 30,
|
||||
'service_price' => $insuranceInfo['count'] * $insuranceInfo['insurancePriceValue'],
|
||||
'name' => $insuranceInfo['count'] . 'x ' . $insuranceInfo['insurance']->getName() . ' (' .
|
||||
$insuranceInfo['insurancePrice']->getCode() . ')',
|
||||
'commission' => round(($insuranceInfo['count'] * $insuranceInfo['insurancePriceValue']) * 20 / 100, 2),
|
||||
'travel_date' => $startDateStr,
|
||||
]);
|
||||
//child
|
||||
if ($insuranceInfo['countChild'] > 0){
|
||||
$this->createServiceItem($bookingUrl, [
|
||||
'travel_company_id' => 30,
|
||||
'service_price' => $insuranceInfo['countChild'] * $insuranceInfo['insuranceChildPriceValue'],
|
||||
'name' => $insuranceInfo['countChild'] . 'x ' . $insuranceInfo['insurance']->getName() . ' (' .
|
||||
$insuranceInfo['insuranceChildPrice']->getCode() . ')',
|
||||
'commission' => round(($insuranceInfo['countChild'] * $insuranceInfo['insuranceChildPriceValue']) * 20 / 100, 2),
|
||||
'travel_date' => $startDateStr,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $bookingUrl;
|
||||
}
|
||||
|
||||
private function createLead(BookingRequest $bookingRequest, TravelDate $travelDate)
|
||||
{
|
||||
$resp = $this->httpPost('lead', ['lead' => [
|
||||
|
|
@ -276,7 +363,7 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
}
|
||||
|
||||
private function createBooking(BookingRequest $bookingRequest, TravelDate $travelDate, $bookingPriceInfo,
|
||||
$customerId, $leadId)
|
||||
$customerId, $leadId, $newDrafts = false)
|
||||
{
|
||||
$tp = $travelDate->getTravelProgram();
|
||||
$resp = $this->httpPost('booking', ['booking' => [
|
||||
|
|
@ -303,6 +390,7 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
'participant_name' => $bookingRequest->getTravelers()[0]->getLastName(),
|
||||
'participant_firstname' => $bookingRequest->getTravelers()[0]->getFirstName(),
|
||||
'participant_birthdate' => $bookingRequest->getTravelers()[0]->getBirthDate(),
|
||||
'new_drafts' => $newDrafts,
|
||||
]]);
|
||||
if (!$resp['success'])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,12 +12,17 @@ use Monolog\Logger;
|
|||
|
||||
abstract class SternToursCrmExporter
|
||||
{
|
||||
const API_URL = 'https://www.cms.stern-tours.net/api';
|
||||
//const API_URL = 'http://cms-stern-tours.local/api';
|
||||
const API_URL = 'https://www.cms.stern-tours.net/api';
|
||||
const API_KEY = 'f6077389c9ce710e554763a5de02c8ec';
|
||||
const API_USER_ID = 15; // 'apiuser'
|
||||
const WEBSITE_ID = 1; // 'sterntours.de'
|
||||
|
||||
//const API_v3_URL = 'http://crm-stern-tours.local/';
|
||||
const API_v3_URL = 'https://mein.sterntours.de/';
|
||||
const API_v3_MAIL = 'info@mein.sterntours.de';
|
||||
const API_v3_PASS = '6m9j,v2GE8px<bt75w';
|
||||
|
||||
protected $logger;
|
||||
|
||||
public function __construct(Logger $logger)
|
||||
|
|
@ -53,4 +58,52 @@ abstract class SternToursCrmExporter
|
|||
}
|
||||
|
||||
|
||||
protected final function httpPostAPIv3($action, $postData = [])
|
||||
{
|
||||
return self::loadFromApi($action, $postData);
|
||||
}
|
||||
|
||||
protected final function loadFromApi($action, $postData){
|
||||
|
||||
|
||||
//first - login and get token
|
||||
$baseUrl = self::API_v3_URL.'api/';
|
||||
$data = array(
|
||||
'email' => self::API_v3_MAIL,
|
||||
'password' => self::API_v3_PASS,
|
||||
);
|
||||
$ret = [];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $baseUrl.'login');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
|
||||
curl_setopt($ch, CURLOPT_POST, count($data));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
|
||||
$result = curl_exec($ch);
|
||||
$r = json_decode($result);
|
||||
|
||||
if($r->success) {
|
||||
if($action == 'create_drafts'){
|
||||
|
||||
//api URL
|
||||
$data = json_encode($postData);
|
||||
// var_dump($data);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $r->success->token, 'Accept:application/json', 'Content-Type:application/json']);
|
||||
curl_setopt($ch, CURLOPT_URL, $baseUrl.'draft/create_drafts_from_booking');
|
||||
$result = curl_exec($ch);
|
||||
$r = json_decode($result);
|
||||
if($r->success) {
|
||||
curl_close($ch);
|
||||
return $r->success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue