diff --git a/trunk/src/AppBundle/Controller/BookingController.php b/trunk/src/AppBundle/Controller/BookingController.php
index 7ec70901..c615355e 100644
--- a/trunk/src/AppBundle/Controller/BookingController.php
+++ b/trunk/src/AppBundle/Controller/BookingController.php
@@ -79,9 +79,6 @@ class BookingController extends Controller
$ret .= "
";
}
}
- 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')
diff --git a/trunk/src/AppBundle/Entity/TravelProgram.php b/trunk/src/AppBundle/Entity/TravelProgram.php
index c1e5db2a..a48ad31d 100644
--- a/trunk/src/AppBundle/Entity/TravelProgram.php
+++ b/trunk/src/AppBundle/Entity/TravelProgram.php
@@ -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;
diff --git a/trunk/src/AppBundle/Entity/TravelProgramDrafts.php b/trunk/src/AppBundle/Entity/TravelProgramDrafts.php
new file mode 100644
index 00000000..b3552fc7
--- /dev/null
+++ b/trunk/src/AppBundle/Entity/TravelProgramDrafts.php
@@ -0,0 +1,103 @@
+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;
+ }
+}
+
diff --git a/trunk/src/AppBundle/Export/BookingSternToursCrmExporter.php b/trunk/src/AppBundle/Export/BookingSternToursCrmExporter.php
index bf3a1096..e1614ea8 100644
--- a/trunk/src/AppBundle/Export/BookingSternToursCrmExporter.php
+++ b/trunk/src/AppBundle/Export/BookingSternToursCrmExporter.php
@@ -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,73 +92,180 @@ 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);
+ }
- $viewPosition = 100;
- $viewPositionPrice = 50;
- $endDateStr = $travelDate->getEnd()->format('Y-m-d');
-
- $arrangementDefaults = [
- 'state' => (new \DateTime())->format('Y-m-d'),
- 'in_pdf' => 1
- ];
-
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
- 'type_id' => 4, // Flug
- 'type_s' => 'Flug',
- 'begin' => $startDateStr,
- 'view_position' => --$viewPosition,
- 'data_s' => ['Hinflug' => 'von '. $bookingPriceInfo['departure']->getName()],
- ]);
-
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
- 'type_id' => 26, // Preisinformation
- 'type_s' => 'Preisinformation',
- 'view_position' => --$viewPositionPrice,
- 'data_s' => [
- 'Name' => 'Abfahrts-/Abflugort '. $bookingPriceInfo['departure']->getName(),
- 'Preis' => $bookingPriceInfo['departure']->getExtraCharge(),
- 'Teilnehmer' => ($bookingRequest->getTravelerCount() + $bookingRequest->getChildrenCount()),
- ],
- ]);
-
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
- 'type_id' => 24, // Rundreise
- 'type_s' => 'Rundreise', // Rundreise
- 'begin' => $startDateStr,
- 'end' => $endDateStr,
- 'view_position' => --$viewPosition,
- 'data_s' => ['Name' => $tp->getTitle() .' ('. $travelDate->getName() .')'],
- ]);
-
-
- $roomStrs = [];
- foreach ($bookingPriceInfo['rooms'] as $room)
- {
- $roomStrs[] = '1x '. $room['name'];
- $child = array();
- if($room['children'] > 0){
- $child = [
- 'Kind' => $room['children'],
- 'KindPreis' => $room['price_children'],
- ];
+ 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,
+ ]);
}
- $data = [
- 'Name' => 'pro Person im \''. $room['name'] .'\'',
- 'Preis' => $room['price'],
- 'Teilnehmer' => $room['adults'],
- ];
- $data = array_merge($data, $child);
+ }
+ }
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ 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');
+
+ $arrangementDefaults = [
+ 'state' => (new \DateTime())->format('Y-m-d'),
+ 'in_pdf' => 1
+ ];
+
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ 'type_id' => 4, // Flug
+ 'type_s' => 'Flug',
+ 'begin' => $startDateStr,
+ 'view_position' => --$viewPosition,
+ 'data_s' => ['Hinflug' => 'von '. $bookingPriceInfo['departure']->getName()],
+ ]);
+
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ 'type_id' => 26, // Preisinformation
+ 'type_s' => 'Preisinformation',
+ 'view_position' => --$viewPositionPrice,
+ 'data_s' => [
+ 'Name' => 'Abfahrts-/Abflugort '. $bookingPriceInfo['departure']->getName(),
+ 'Preis' => $bookingPriceInfo['departure']->getExtraCharge(),
+ 'Teilnehmer' => ($bookingRequest->getTravelerCount() + $bookingRequest->getChildrenCount()),
+ ],
+ ]);
+
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ 'type_id' => 24, // Rundreise
+ 'type_s' => 'Rundreise', // Rundreise
+ 'begin' => $startDateStr,
+ 'end' => $endDateStr,
+ 'view_position' => --$viewPosition,
+ 'data_s' => ['Name' => $tp->getTitle() .' ('. $travelDate->getName() .')'],
+ ]);
+
+
+ $roomStrs = [];
+ foreach ($bookingPriceInfo['rooms'] as $room)
+ {
+ $roomStrs[] = '1x '. $room['name'];
+ $child = array();
+ if($room['children'] > 0){
+ $child = [
+ 'Kind' => $room['children'],
+ 'KindPreis' => $room['price_children'],
+ ];
+ }
+ $data = [
+ 'Name' => 'pro Person im \''. $room['name'] .'\'',
+ 'Preis' => $room['price'],
+ 'Teilnehmer' => $room['adults'],
+ ];
+ $data = array_merge($data, $child);
+
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
'type_id' => 26, // Preisinformation
'type_s' => 'Preisinformation',
'view_position' => --$viewPositionPrice,
'data_s' => $data,
]);
- }
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ }
+
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
'type_id' => 5, // Hotel
'type_s' => 'Hotel',
'begin' => $startDateStr,
@@ -162,10 +274,10 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
'data_s' => ['Zimmer' => implode(', ', $roomStrs)],
]);
- // Actually: extra_category
- foreach ($bookingPriceInfo['classOptions'] as $classOption)
- {
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ // Actually: extra_category
+ foreach ($bookingPriceInfo['classOptions'] as $classOption)
+ {
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
'type_id' => 26, // Preisinformation
'type_s' => 'Preisinformation',
'view_position' => --$viewPositionPrice,
@@ -176,9 +288,9 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
],
]);
- }
+ }
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
'type_id' => 4, // Flug
'type_s' => 'Flug',
'begin' => $endDateStr,
@@ -187,53 +299,28 @@ class BookingSternToursCrmExporter extends SternToursCrmExporter
]);
- foreach ($bookingRequest->getTravelOptions() as $option)
- {
- $child = array();
- if($option->getPriceChildren() > 0){
- $child = [
- 'Kind' => $bookingRequest->getChildrenCount(),
- 'KindPreis' => $option->getPriceChildren(),
- ];
- }
- $data = [
- 'Name' => $option->getName(),
- 'Preis' => $option->getPrice(),
- 'Teilnehmer' => $bookingRequest->getTravelerCount(),
+ foreach ($bookingRequest->getTravelOptions() as $option)
+ {
+ $child = array();
+ if($option->getPriceChildren() > 0){
+ $child = [
+ 'Kind' => $bookingRequest->getChildrenCount(),
+ 'KindPreis' => $option->getPriceChildren(),
];
- $data = array_merge($data, $child);
- $this->createArrangement($bookingUrl, $arrangementDefaults + [
+ }
+ $data = [
+ 'Name' => $option->getName(),
+ 'Preis' => $option->getPrice(),
+ 'Teilnehmer' => $bookingRequest->getTravelerCount(),
+ ];
+ $data = array_merge($data, $child);
+ $this->createArrangement($bookingUrl, $arrangementDefaults + [
'type_id' => 26, // Preisinformation
'type_s' => 'Preisinformation',
'view_position' => --$viewPositionPrice,
'data_s' => $data
]);
- }
}
-
- 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)
@@ -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'])
{
diff --git a/trunk/src/AppBundle/Export/SternToursCrmExporter.php b/trunk/src/AppBundle/Export/SternToursCrmExporter.php
index 9a9b2a6e..39775bcf 100644
--- a/trunk/src/AppBundle/Export/SternToursCrmExporter.php
+++ b/trunk/src/AppBundle/Export/SternToursCrmExporter.php
@@ -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 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;
+ }
+
}
\ No newline at end of file