outlet-delivery-area.blade.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. @extends('layouts.app')
  2. @section('content')
  3. <link href="{!! env('APP_ASSETS') !!}/vendor_components/dropzone/dropzone.css" rel="stylesheet"/>
  4. <link href="{!! env('APP_ASSETS') !!}/vendor_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.css" rel="stylesheet"/>
  5. <link href="{!! env('APP_ASSETS') !!}/css/jquery.timepicker.min.css" rel="stylesheet"/>
  6. <!-- Content Wrapper. Contains page content -->
  7. @php
  8. $resto = \App\Models\Restaurants::find(\App\Helpers\CommonMethods::getRestuarantID());
  9. $lang = $resto->default_lang;
  10. app()->setLocale($lang);
  11. if(session('app_lang') !==null){
  12. $lang = session('app_lang');
  13. app()->setLocale($lang);
  14. }
  15. //$resto = \Illuminate\Support\Facades\Auth::user()->restaurants;
  16. $address = isset($resto->places)?$resto->places->place_name:"Baghdad";
  17. $polygons = isset($resto->places)?$resto->places->coordinates:NULL;
  18. if(!empty($outlet->address))
  19. $address = $outlet->address.', '.$outlet->place;
  20. // dd($resto->places->place_name);
  21. @endphp
  22. @php
  23. $restuarant1 = $resto;
  24. $resto_meta = isset($restuarant1->resto_metas)?$restuarant1->resto_metas:null;
  25. if(isset($_GET['debug']))
  26. dump($resto_meta);
  27. //dump($resto_meta);
  28. $resto_metas = [];
  29. $billing = [];
  30. if(isset($resto_meta)){
  31. foreach($resto_meta as $meta){
  32. if($meta->outlet_id!=""){
  33. continue;
  34. }
  35. $index_name = isset($meta->resto_meta_defs->parents)?$meta->resto_meta_defs->parents->meta_def_name:$meta->resto_meta_defs->meta_def_name;
  36. // dump($meta->resto_meta_defs);
  37. if($index_name=="BILLING_GATEWAY"){
  38. // dump($meta->resto_meta_defs->meta_def_name);
  39. // $resto_metas['BILLING_GATEWAY'][] = $meta->meta_val;
  40. $billing[] = array('id'=>$meta->meta_id,'value'=>$meta->meta_val);
  41. }
  42. $resto_metas[$index_name] = $meta->meta_val;
  43. }
  44. }
  45. $resto_metas['BILLING_GATEWAY'] = $billing;
  46. $currency = isset($resto_metas['BUSSINESS_CCY'])?$resto_metas['BUSSINESS_CCY']:"IQD";
  47. $business_type = isset($resto_metas['BUSSINESS_TYPE'])?$resto_metas['BUSSINESS_TYPE']:"Restaurants";
  48. $outlet_meta = isset($outlet->resto_metas)?$outlet->resto_metas:NULL;
  49. $outlet_metas = [];
  50. if(isset($outlet_meta)){
  51. foreach($outlet_meta as $meta){
  52. $index_name = isset($meta->resto_meta_defs->parents)?$meta->resto_meta_defs->parents->meta_def_name:$meta->resto_meta_defs->meta_def_name;
  53. // dump($meta->resto_meta_defs);
  54. if($index_name=="BILLING_GATEWAY"){
  55. // dump($meta->resto_meta_defs->meta_def_name);
  56. // $resto_metas['BILLING_GATEWAY'][] = $meta->meta_val;
  57. $billing[] = array('id'=>$meta->meta_id,'value'=>$meta->meta_val);
  58. }
  59. $outlet_metas[$index_name] = $meta->meta_val;
  60. }
  61. }
  62. $currency = isset($outlet_metas['BUSSINESS_CCY'])?$outlet_metas['BUSSINESS_CCY']:$resto_metas['BUSSINESS_CCY'];
  63. @endphp
  64. <style>
  65. .vtabs .tabs-vertical {
  66. width: 229px;
  67. }
  68. .bootstrap-tagsinput {
  69. min-height: 60px; width: 100%;
  70. }
  71. h4{ margin-top: 40px}
  72. .bootstrap-timepicker-widget table td input{ width: 46px}
  73. #map{
  74. width: 100%; height: 100vh;
  75. }
  76. @if(app()->getLocale()!="en")
  77. .delivery-section{
  78. width: 400px;
  79. height: auto;
  80. background: white;
  81. position: absolute;
  82. left: 10px; top: 40px;
  83. z-index: 10; padding: 10px;
  84. }
  85. @else
  86. .delivery-section{
  87. width: 400px;
  88. height: auto;
  89. background: white;
  90. position: absolute;
  91. right: 10px; top: 40px;
  92. z-index: 10; padding: 10px;
  93. }
  94. @endif
  95. .input-group input[type=text]{
  96. border-left: 0; padding-left: 0;
  97. }
  98. #pac-input{
  99. position: absolute;
  100. z-index: 9;
  101. top: 26px !important;
  102. right: 20px !important;
  103. width: 300px;
  104. left: inherit !important;
  105. }
  106. .search-location{
  107. position: absolute;
  108. right: 33px;
  109. top: 28px;
  110. z-index: 88;
  111. font-size: 20px;
  112. }
  113. .centerMarker{
  114. position:absolute;
  115. /*url of the marker*/
  116. background:url({!! env('APP_ASSETS') !!}images/marker.png) no-repeat;
  117. /*center the marker*/
  118. top:49%;left:47%;
  119. z-index:1;
  120. /*fix offset when needed*/
  121. margin-left:-10px;
  122. margin-top:-34px;
  123. /*size of the image*/
  124. height:40px;
  125. width:37px;
  126. cursor:pointer;
  127. }
  128. </style>
  129. <div class="content-wrapper">
  130. <div class="container-full">
  131. <!-- Content Header (Page header) -->
  132. <!-- Main content -->
  133. <section class="content">
  134. <div class="row">
  135. <div class="col-12 col-sm-3 sidebar_div_main" style="padding-right: 0;background-color: #F5F5F5">
  136. @include('outlets.outlet-sidebar')
  137. </div>
  138. <div class="col-12 col-sm-9 p-15">
  139. <div class="delivery-section">
  140. <h3>{{__('label.add_delivery_area')}}</h3>
  141. <div class="row">
  142. <div class="col-12">
  143. <div class="form-group">
  144. <label>{{__('label.delivery_area_name')}}</label>
  145. <input type="text" value="{!! isset($area)?$area->area_name:"" !!}" class="form-control" name="area_name" required/>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="row">
  150. <div class="col-6">
  151. <div class="form-group">
  152. <label>{{__('label.min_basket_value')}}</label>
  153. <div class="input-group" >
  154. <div class="input-group-addon" style="font-size: 13px;position: relative;padding-top: 9px;">
  155. {!! $currency !!}
  156. </div>
  157. <input type="text" value="{!! isset($area)?$area->min_price:"0" !!}" class="form-control" name="min_basket" required/>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="col-6">
  162. <div class="form-group">
  163. <label>{{__('label.delivery_fee')}}</label>
  164. <div class="input-group">
  165. <div class="input-group-addon" style="font-size: 13px;position: relative;padding-top: 9px;">
  166. {!! $currency !!}
  167. </div>
  168. <input type="text" value="{!! isset($area)?$area->delivery_fee:"0" !!}" class="form-control" name="delivery_fee" required/>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <div class="row">
  174. <div class="col-6">
  175. <button class="btn btn-primary save-delivery-area">{{__('label.save_delivery_area')}}</button>
  176. </div>
  177. </div>
  178. </div>
  179. <div class="row">
  180. <div class="col-12 position-relative">
  181. <div class="position-relative" >
  182. <div class="form-group position-relative">
  183. <!-- <a href="#!" class="search-location"><i class="fa fa-location-arrow"></i> </a>-->
  184. <input
  185. id="pac-input"
  186. class="form-control"
  187. type="text"
  188. placeholder="Search Box"
  189. />
  190. </div>
  191. </div>
  192. <div id="map"></div>
  193. </div>
  194. </div>
  195. <!-- /.box -->
  196. </div>
  197. </div>
  198. </section>
  199. <!-- /.content -->
  200. </div>
  201. </div>
  202. <!-- /.content-wrapper -->
  203. @endsection
  204. @section('js')
  205. <script>
  206. let map;
  207. var uluru = { lat: 33.325, lng: 44.422 };
  208. var marker_icon = "{!! env('APP_ASSETS') !!}images/marker.png";
  209. var address = "{!! $address !!}";
  210. window.existingArea = {!! !empty($polygons)?$polygons:"1" !!};
  211. var distance_plus = 0.2;
  212. var distance_minus = 0.2;
  213. var polygons = null;
  214. var redCoords = null;
  215. var marker=null;
  216. var map_center = null;
  217. function initMapMeem() {
  218. geocoder = new google.maps.Geocoder();
  219. //codeAddress(address);
  220. geocoder.geocode({ 'address': address }, function (results, status) {
  221. // console.log(results);
  222. uluru = {lat: results[0].geometry.location.lat (), lng: results[0].geometry.location.lng ()};
  223. // console.log (latLng);
  224. if (status == 'OK') {
  225. map = new google.maps.Map(document.getElementById("map"), {
  226. center: uluru,
  227. zoom: 12,
  228. disableDefaultUI: true,
  229. });
  230. // $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
  231. /*marker = new google.maps.Marker({
  232. position: uluru,
  233. map: map,
  234. icon:marker_icon,
  235. draggable:true
  236. });*/
  237. map_center = map.getCenter();
  238. @if(isset($area))
  239. redCoords = {!! str_replace('"','',$area->lat_lag) !!};
  240. @else
  241. /*redCoords = [
  242. { lat: 33.3332, lng: 44.4283 },//North
  243. { lat: 33.2722, lng: 44.4283 },//sound
  244. { lat: 33.2722, lng: 44.3283 },//sound
  245. { lat: 33.3332, lng: 44.3283 },//North
  246. ];*/
  247. var lat_1 = uluru.lat;
  248. var lat_2 = parseFloat(uluru.lat) - 0.0610000;
  249. var lat_3 = lat_2;
  250. var lat_4 = lat_1;
  251. var lng_1 = uluru.lng;
  252. var lng_2 = lng_1;
  253. var lng_3 = parseFloat(uluru.lng) - 0.1000000;
  254. var lng_4 = lng_3;
  255. redCoords = [
  256. { lat: lat_1, lng: lng_1 },//North
  257. { lat: lat_2, lng: lng_2 },//sound
  258. { lat: lat_3, lng: lng_3 },//sound
  259. { lat: lat_4, lng: lng_4 },//North
  260. ];
  261. @endif
  262. // Construct a draggable red triangle with geodesic set to true.
  263. polygons= new google.maps.Polygon({
  264. map,
  265. paths: redCoords,
  266. strokeColor: "#FF0000",
  267. strokeOpacity: 0.8,
  268. strokeWeight: 2,
  269. fillColor: "#FF0000",
  270. fillOpacity: 0.35,
  271. draggable: true,
  272. editable:true,
  273. geodesic: true,
  274. });
  275. @if(isset($areas) && $areas->count() > 0)
  276. @foreach($areas as $a)
  277. polygonss= new google.maps.Polygon({
  278. map,
  279. paths: {!! str_replace('"','',$a->lat_lag) !!},
  280. strokeColor: "#616161",
  281. strokeOpacity: 0.5,
  282. strokeWeight: 1,
  283. fillColor: "#616161",
  284. fillOpacity: 0.35,
  285. draggable: false,
  286. editable:false,
  287. geodesic: true,
  288. });
  289. @endforeach
  290. @endif
  291. const input = document.getElementById("pac-input");
  292. const searchBox = new google.maps.places.SearchBox(input);
  293. map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
  294. map.addListener("bounds_changed", () => {
  295. searchBox.setBounds(map.getBounds());
  296. });
  297. let markers = [];
  298. searchBox.addListener("places_changed", () => {
  299. const places = searchBox.getPlaces();
  300. //console.log("places");
  301. //console.log(places);
  302. if (places.length == 0) {
  303. return;
  304. }
  305. // Clear out the old markers.
  306. markers.forEach((marker) => {
  307. marker.setMap(null);
  308. });
  309. markers = [];
  310. // For each place, get the icon, name and location.
  311. const bounds = new google.maps.LatLngBounds();
  312. geocoder.geocode({
  313. 'address': places[0].formatted_address
  314. }, function (results, status) {
  315. var sw = results[0].geometry.bounds.getSouthWest();
  316. var ne = results[0].geometry.bounds.getNorthEast();
  317. //console.log('sw');console.log(sw);
  318. var padding = 0.000000001;
  319. var boxCoords = [
  320. new google.maps.LatLng(ne.lat()+padding, ne.lng()+padding),
  321. new google.maps.LatLng(ne.lat()+padding, sw.lng()-padding),
  322. new google.maps.LatLng(sw.lat()-padding, sw.lng()-padding),
  323. new google.maps.LatLng(sw.lat()-padding, ne.lng()+padding),
  324. new google.maps.LatLng(ne.lat()+padding, ne.lng()+padding)
  325. ];
  326. polygons.setMap(null);
  327. polygons= new google.maps.Polygon({
  328. map,
  329. paths: boxCoords,
  330. strokeColor: "#FF0000",
  331. strokeOpacity: 0.8,
  332. strokeWeight: 2,
  333. fillColor: "#FF0000",
  334. fillOpacity: 0.35,
  335. draggable: true,
  336. editable:true,
  337. geodesic: true,
  338. });
  339. });
  340. places.forEach((place) => {
  341. if (!place.geometry || !place.geometry.location) {
  342. console.log("Returned place contains no geometry");
  343. return;
  344. }
  345. const icon = {
  346. url: place.icon,
  347. size: new google.maps.Size(71, 71),
  348. origin: new google.maps.Point(0, 0),
  349. anchor: new google.maps.Point(17, 34),
  350. scaledSize: new google.maps.Size(25, 25),
  351. };
  352. // Create a marker for each place.
  353. /* marker = new google.maps.Marker({
  354. map,
  355. marker_icon,
  356. title: place.name,
  357. position: place.geometry.location,
  358. draggable:true
  359. });
  360. markers.push(
  361. marker
  362. );*/
  363. if (place.geometry.viewport) {
  364. // Only geocodes have viewport.
  365. bounds.union(place.geometry.viewport);
  366. } else {
  367. bounds.extend(place.geometry.location);
  368. }
  369. });
  370. google.maps.event.addListener(map, 'dragend', function(e) {
  371. map_center = map.getCenter();
  372. //geocodePosition(map.getCenter());
  373. var lat = map.getCenter().lat();
  374. var lng = map.getCenter().lng();
  375. $("input[name=lat]").val(lat);
  376. $("input[name=lng]").val(lng);
  377. } );
  378. map.fitBounds(bounds);
  379. map.setZoom(12);
  380. });
  381. } else {
  382. alert('{{__("label.geocode_error")}}: ' + status);
  383. }
  384. });
  385. // console.log(uluru);
  386. }
  387. function codeAddress(address) {
  388. geocoder.geocode({ 'address': address }, function (results, status) {
  389. // console.log(results);
  390. uluru = {lat: results[0].geometry.location.lat (), lng: results[0].geometry.location.lng ()};
  391. // console.log (latLng);
  392. if (status == 'OK') {
  393. /* var marker = new google.maps.Marker({
  394. position: uluru,
  395. animation: google.maps.Animation.DROP,
  396. icon:marker_icon,
  397. map: map
  398. });
  399. marker.setMap(map);*/
  400. // console.log (map);
  401. } else {
  402. alert('{{__("label.geocode_error")}}: ' + status);
  403. }
  404. });
  405. }
  406. $(function () {
  407. $("body").on("click",".search-location",function () {
  408. if (navigator.geolocation) {
  409. navigator.geolocation.getCurrentPosition(
  410. (position) => {
  411. const pos = {
  412. lat: position.coords.latitude,
  413. lng: position.coords.longitude,
  414. };
  415. marker.setMap(null);
  416. marker = new google.maps.Marker({
  417. position: pos,
  418. map: map,
  419. icon:marker_icon,
  420. draggable:true
  421. });
  422. map.setCenter(pos);
  423. map_center = map.getCenter();
  424. map.setZoom(12);
  425. google.maps.event.addListener(marker, 'dragend', function(e) {
  426. geocodePosition(marker.getPosition());
  427. var lat = marker.getPosition().lat();
  428. var lng = marker.getPosition().lng();
  429. $("input[name=lat]").val(lat);
  430. $("input[name=lng]").val(lng);
  431. } );
  432. },
  433. () => {
  434. // handleLocationError(true, infoWindow, map.getCenter());
  435. }
  436. );
  437. } else {
  438. // Browser doesn't support Geolocation
  439. // handleLocationError(false, infoWindow, map.getCenter());
  440. }
  441. });
  442. $("body").on("click",".save-delivery-area",function () {
  443. var _this = $(this);
  444. _this.attr('disabled','disabled');
  445. var coordinates =polygons.getPath().getArray();
  446. var area_name = $("input[name=area_name]").val();
  447. var min_basket = $("input[name=min_basket]").val();
  448. var delivery_fee = $("input[name=delivery_fee]").val();
  449. if(area_name==""){
  450. $("input[name=area_name]").focus();return;
  451. }
  452. if(min_basket==""){
  453. $("input[name=min_basket]").focus();return;
  454. }
  455. if(delivery_fee==""){
  456. $("input[name=delivery_fee]").focus();return;
  457. }
  458. coordinates = (JSON.stringify(coordinates));
  459. $.ajax({
  460. url:"{!! env('APP_URL') !!}save/outlet/area",
  461. type:"POST",
  462. data:{
  463. coordinates:coordinates,
  464. area_name:area_name,
  465. min_basket:min_basket,
  466. delivery_fee:delivery_fee,
  467. center_radius:uluru,
  468. unique_id:"{!! $outlet->unique_key !!}",
  469. "_token":"{!! csrf_token() !!}",
  470. id:"{!! isset($area)?$area->id:0 !!}"
  471. },success:function (response) {
  472. response = $.parseJSON(response);
  473. if(response.type=="success"){
  474. $.toast({
  475. heading: '{{__("label.outlet_area_update")}}',
  476. text: response.message,
  477. position: 'top-right',
  478. loaderBg: '#ff6849',
  479. icon: 'success',
  480. hideAfter: 3000,
  481. stack: 1
  482. });
  483. setTimeout(function () {
  484. location.reload();
  485. },2000);
  486. }else{
  487. $.toast({
  488. heading: '{{__("label.outlet_area_update")}}',
  489. text: response.message,
  490. position: 'top-right',
  491. loaderBg: '#ff6849',
  492. icon: 'error',
  493. hideAfter: 3000,
  494. stack: 1
  495. });
  496. }
  497. }
  498. });
  499. });
  500. })
  501. </script>
  502. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBFh6fzq8G7dgWLfz8kccvTlmPCSI_uWXQ&callback=initMapMeem&libraries=drawing,places&language=ar"></script>
  503. @endsection