deliver-order.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. @extends('layout.app')
  2. @section('content')
  3. <style type="text/css">
  4. p,h4{
  5. direction: rtl;
  6. }
  7. .card{ margin-bottom: 2px !important; border: 0;box-shadow:none}
  8. .card .card-header{
  9. background: #f3f3f3;
  10. height: 46px;
  11. border: none;
  12. }
  13. .homepage-ads .item img
  14. {
  15. display: block;
  16. width: 100%;
  17. height:auto !important;
  18. }
  19. .address-label{
  20. font-size: 17px;
  21. font-weight: bold;
  22. margin: 0;
  23. }
  24. .adjust-adress,.change-button1{
  25. border: 1px solid #faf1e0;
  26. padding: 5px 10px;
  27. border-radius: 20px;
  28. background: #faf1e0;
  29. }
  30. .today-tomorrow{
  31. width:100%
  32. }
  33. .today-tomorrow li{
  34. width: 100%;
  35. text-align: center;
  36. padding: 7px;
  37. font-size: 16px;
  38. }
  39. .today-tomorrow li.active{
  40. background: #fff9ed;
  41. }
  42. .time-slots a{ border: none}
  43. .img-div{
  44. max-height: 70px; overflow: hidden }
  45. @media (max-width: 575.98px)
  46. {
  47. .homepage-search-block {
  48. padding: 0rem 0 !important;
  49. }
  50. }
  51. </style>
  52. <div class="mobile-container">
  53. <div class="card border-bottom">
  54. <h5 class="card-header p-4 text-center fw-bold">
  55. طلبك <a href="#!" onclick="window.history.go(-1); return false;" class="back-button icofont-simple-right float-start"></a>
  56. </h5>
  57. </div>
  58. @php
  59. $opening_timing = $resto_info['opening_timing'];
  60. $closing_timing = $resto_info['closing_timing'];
  61. $is_resto_opened = false;
  62. if(!empty($opening_timing) && !empty($closing_timing)){
  63. // $opening_timing = "13:00";
  64. $opening_timing = date('H:i', strtotime($opening_timing));
  65. $closing_timing = date('H:i', strtotime($closing_timing));
  66. $current_time = date('H:i');
  67. if($current_time > $opening_timing && $current_time <= $closing_timing)
  68. $is_resto_opened = true;
  69. $opening_timing = strtotime($opening_timing);
  70. $closing_timing =strtotime($closing_timing);
  71. $tStart = $opening_timing;
  72. $tEnd = ($closing_timing);
  73. $tNow = $tStart;
  74. while($tNow <= $tEnd){
  75. $now = date("H:i",$tNow);
  76. $tNow = strtotime('+15 minutes',$tNow);
  77. $time_slots[] = $now;
  78. }
  79. }
  80. @endphp
  81. <div id="order-section">
  82. <div class="row p-1" style="direction: ltr">
  83. <div class="col-12 mt-5">
  84. <h4 class="font-black text-lg leading-normal mx-4 fw-bold mb-2">
  85. التوصيل الى
  86. </h4>
  87. <div class="mx-4 d-flex mb-2" style="background: #f9f9f9; padding: 10px;border-radius: 6px;">
  88. <div class="p-2 bd-highlight"> <div class="ml-auto" style="margin-top: 10%;">
  89. <a href="#!" class="adjust-adress" data-action="delivery">غير</a>
  90. </div></div>
  91. <div class="w-100 p-2 bd-highlight" id="select-location" style="direction: rtl"> اختر عنوان</div>
  92. <div class="p-2 bd-highlight"> <img src="{!! env('APP_URL_ASSETS') !!}img/location.png" style="margin-top: -3px; margin-right: 8px"></div>
  93. </div>
  94. <h4 class="font-black text-lg leading-normal m-2 mx-4 fw-bold mb-1 mt-5">
  95. وقت التوصيل
  96. </h4>
  97. <div class="mx-4 d-flex mb-2" style="background: #f9f9f9; padding: 10px;border-radius: 6px;">
  98. <div class="p-2 bd-highlight"> <div class="ml-auto" style="margin-top: 10%;">
  99. <a href="#!" class="change-button1" data-action="time">غير</a>
  100. </div></div>
  101. <div class="w-100 p-2 bd-highlight" style="margin-top: 2px;direction: rtl" id="select-time"> اقرب وقت</div>
  102. <div class="p-2 bd-highlight"> <i class="icofont-wall-clock primary-text-color" style="font-size: 20px"></i> </div>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="card p-3" id="price-section" style="margin-top: 130px">
  107. <div class="row mb-2" style="padding-right: 10px">
  108. <div class="col-8 fs-4">قيمة الطلب
  109. </div>
  110. <div class="col-4 fs-4 basket-total"> <span></span> د. ع </div>
  111. </div>
  112. <div class="row mb-4" style="padding-right: 10px">
  113. <div class="col-8 fs-4">قيمة التوصيل
  114. </div>
  115. <div class="col-4 fs-4"> <span id="delivery-fee"></span> د. ع </div>
  116. </div>
  117. <div class="row mt-2" style="padding-right: 10px">
  118. <div class="col-8 fs-4 fw-bolder">المبلغ الكلي
  119. </div>
  120. <div class="col-4 fs-4 fw-bolder"> <span class="grand-total"></span> د. ع </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="my-custom-buttom place-order " style="display: block">
  126. <div class="row">
  127. <div class="col-12 text-center"><span class="view-basket-label">ارسل طلبك</span> </div>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="modal fade" id="address-options" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  132. <div class="modal-dialog" role="document">
  133. <div class="modal-content">
  134. <div class="modal-body">
  135. <div id="customer-address">
  136. </div>
  137. <div class="d-flex">
  138. <div class="flex-grow-1 ms-3 p-2">
  139. <div class="row">
  140. <div class="col-10"><a href="{!! env('APP_URL') !!}new/address"> اضف عنوان جديد
  141. </a> </div>
  142. <div class="col-2 text-center fw-bold fs-2"><i class="icofont-rounded-left"></i></div>
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. <div class="modal fade" id="time-options" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  151. <div class="modal-dialog" role="document">
  152. <div class="modal-content">
  153. <div class="modal-body" style=" padding: 0;">
  154. <ul class="list-inline today-tomorrow border-bottom">
  155. <li class="list-inline-item active">Today</li>
  156. </ul>
  157. @if(isset($time_slots) && count($time_slots))
  158. <div class="list-group list-group-flush time-slots" style="max-height: 250px; overflow: auto;">
  159. <a href="#" class="list-group-item list-group-item-action text-center">اقرب وقت</a>
  160. @foreach($time_slots as $slot)
  161. <a href="#" class="list-group-item list-group-item-action text-center">{!! $slot !!}</a>
  162. @endforeach
  163. </div>
  164. @endif
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. @endsection
  170. @section('js')
  171. <script>
  172. var label_array = [];
  173. var home = 0;
  174. var office = 0;
  175. var other = 0;
  176. $(function () {
  177. var customer_id = localStorage.getItem('customer_id');
  178. var customer_name = localStorage.getItem('customer_name');
  179. // alert(customer_name);
  180. var is_basket_has_items = localStorage.getItem('cart');
  181. var mobile_number = localStorage.getItem('mobile_number');
  182. var time = localStorage.getItem('selected_time');
  183. var selected_area = localStorage.getItem('selected_city');
  184. var _has_address = false;
  185. var _total_price = 0;
  186. if(!is_basket_has_items || is_basket_has_items==""){
  187. window.location = localStorage.getItem('site_url');
  188. return false;
  189. }
  190. // $("#address-options").modal();
  191. if(time && time!=""){
  192. $("#select-time").text(time);
  193. }else{
  194. $("#select-time").text("(اقرب وقت)");
  195. }
  196. $("body").on("click",".change-button1",function (e) {
  197. var action = $(this).data("action");
  198. if(action=="time"){
  199. $("#time-options").modal();
  200. }
  201. e.preventDefault(); e.stopPropagation();
  202. });
  203. $("body").on("click",".place-order",function () {
  204. var order_instructions = localStorage.getItem('order_instructions');
  205. $.ajax({
  206. url:"{!! env('APP_URL') !!}order/confirmed",
  207. type:"POST",
  208. data:{
  209. cart:is_basket_has_items,
  210. total_price:_total_price,
  211. mobile_number:mobile_number,
  212. customer_name,customer_name,
  213. customer_id,customer_id,
  214. order_instructions:order_instructions,
  215. time:time,
  216. selected_area:selected_area,
  217. "_token":"{!! csrf_token() !!}"
  218. },success:function (response) {
  219. response = $.parseJSON(response);
  220. if(response.type=="success"){
  221. localStorage.removeItem('cart');
  222. localStorage.removeItem('total_price');
  223. localStorage.removeItem('customer_id');
  224. localStorage.removeItem('mobile_number');
  225. localStorage.removeItem('selected_time');
  226. //localStorage.removeItem('selected_city');
  227. window.location = "{!! env('APP_URL') !!}thankyou?order="+response.order_id+"&ref="+response.order_ref;
  228. }
  229. }
  230. });
  231. });
  232. if(customer_id!=""){
  233. $.ajax({
  234. url:"{!! env('APP_URL') !!}customer/address",
  235. type:"POST",
  236. data:{
  237. customer_id:customer_id,
  238. "_token":"{!! csrf_token() !!}"
  239. },
  240. success:function (response) {
  241. response = $.parseJSON(response);
  242. if(response && response.type=="success"){
  243. var addresses = response.data;
  244. $.each(addresses,function (i,address) {
  245. if(i!="count_labels"){
  246. _has_address = true;
  247. var a = address_template(address,addresses['count_labels']);
  248. if(address.is_set=="1"){
  249. $("#select-location").html('<span class="fw-bold">'+address.label+'</span><br />\n' +
  250. ' <span >'+address.address+'</span>');
  251. localStorage.setItem('delivery_fee',address.delivery_fee);
  252. }
  253. $("#customer-address").append(a);
  254. }
  255. });
  256. if(_has_address)
  257. $(".review-order").show();
  258. }
  259. }
  260. });
  261. }
  262. var vat = localStorage.getItem('delivery_fee');
  263. $("#delivery-fee").html(parseInt(vat).toFixed(2));
  264. if($.parseJSON(is_basket_has_items).length > 0){
  265. var orders = $.parseJSON(is_basket_has_items);
  266. var t = orders.map(orders => orders.id).join(',');
  267. $.ajax({
  268. url:"{!! env('APP_URL') !!}get/recipes",
  269. type:"POST",
  270. data:{
  271. "_token":"{!! csrf_token() !!}",
  272. recipes:JSON.stringify(orders),
  273. },
  274. success:function (response) {
  275. $("#view-orders").html('');
  276. response = $.parseJSON(response);
  277. if(response){
  278. $.each(response.recipe,function (i,v) {
  279. var order = v;
  280. _total_price+= (parseInt(order.price_in_number) * parseInt(order.requested_quantity));
  281. });
  282. $(".basket-total").html(format(_total_price+ " د. ع "));
  283. $(".grand-total").html(format((_total_price+parseInt(vat)).toFixed(2)));
  284. localStorage.setItem('total_price',format((_total_price+parseInt(vat)).toFixed(2)));
  285. }
  286. }
  287. });
  288. /* var t = a.map(a => a.price).reduce((acc, a) => a + acc);
  289. $("#basket-price").html(format(t));
  290. $(".total-recipe-selected").html(a.length);
  291. $(".view-basket").show();*/
  292. /*if(orders){
  293. $.each(orders,function (i,v) {
  294. var order = order_template(order);
  295. $("#view-orders").append(order);
  296. })
  297. }*/
  298. }
  299. $("body").on("click",".adjust-adress",function () {
  300. $("#address-options").modal();
  301. return false;
  302. });
  303. $("body").on("click",".address",function () {
  304. var address_id = $(this).data('address-id');
  305. var customer_id = localStorage.getItem('customer_id');
  306. var delivery_fee = $(this).data('fee');
  307. var _this = $(this);
  308. $.ajax({
  309. url:"{!! env('APP_URL') !!}set/customer/address",
  310. type:"POST",
  311. data:{
  312. address_id:address_id,
  313. customer_id:customer_id,
  314. "_token":"{!! csrf_token() !!}"
  315. },
  316. success:function (response) {
  317. var label = _this.find('.address-label').text();
  318. var address = _this.find('small').text();
  319. $("#select-location").html('<span class="fw-bold">'+label+'</span><br />\n' +
  320. ' <span >'+address+'</span>');
  321. localStorage.setItem('delivery_fee',delivery_fee);
  322. $("#delivery-fee").html(parseFloat(delivery_fee).toFixed(2));
  323. var basket_price = parseFloat($(".basket-total").html().replace('د. ع'));
  324. var total_price = delivery_fee+parseFloat(basket_price);
  325. $(".grand-total").html(format(total_price.toFixed(2)));
  326. localStorage.setItem('total_price',format((total_price).toFixed(2)));
  327. $(".check_address").hide();
  328. $(".delete_address").show();
  329. // _this.find(".delete_address").hide();
  330. _this.find(".check_address").show();
  331. $("#address-options").modal('hide');
  332. }
  333. });
  334. });
  335. /* $("body").on("click",".list-group-item-action",function () {
  336. var city = $(this).find('p').text();
  337. localStorage.setItem('selected_city',city);
  338. window.history.back();
  339. });*/
  340. $("body").on("click",".delete-address",function (e) {
  341. var address_id = $(this).data('id');
  342. var _this = $(this);
  343. $.ajax({
  344. url:"{!! env('APP_URL') !!}delete/customer/address",
  345. type:"POST",
  346. data:{
  347. address_id:address_id,
  348. "_token":"{!! csrf_token() !!}"
  349. },
  350. success:function (response) {
  351. _this.parents('.address').remove();
  352. }
  353. });
  354. e.preventDefault();
  355. e.stopPropagation();
  356. });
  357. $("body").on("click",".time-slots a",function () {
  358. time = $(this).text();
  359. $("#select-time").html(time);
  360. localStorage.setItem('selected_time',time);
  361. $("#time-options").modal('hide');
  362. });
  363. $(".search-area input").on("keyup", function() {
  364. var value = $(this).val().toLowerCase();
  365. $(".list-group a").filter(function() {
  366. $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
  367. });
  368. });
  369. $("body").on("click",".delivery-action-buttons",function () {
  370. var action = $(this).data('action');
  371. if(action=="delivery"){
  372. $("#for-delivery").addClass('active');
  373. $("#for-pickup").removeClass('active')
  374. }
  375. if(action=="pickup"){
  376. $("#for-delivery").removeClass('active');
  377. $("#for-pickup").addClass('active')
  378. }
  379. });
  380. });
  381. function address_template(address,count_labels) {
  382. // console.log(address);
  383. var img = "{!! env('APP_URL_ASSETS') !!}img/location.png";
  384. var label = "";
  385. if(address.label=="البيت"){
  386. if(parseInt(count_labels.البيت) > 1){
  387. home++;
  388. label = address.label+" "+home;
  389. }else{
  390. label = address.label;
  391. }
  392. }
  393. if(address.label=="العمل"){
  394. if(parseInt(count_labels.العمل) > 1){
  395. office++;
  396. label = address.label+" "+office;
  397. }else{
  398. label = address.label;
  399. }
  400. }
  401. if(address.label=="اخرى"){
  402. if(parseInt(count_labels.اخرى) > 1){
  403. other++;
  404. label = address.label+" "+other;
  405. }else{
  406. label = address.label;
  407. }
  408. }
  409. var str = ' <div class="d-flex address mb-3 pb-3 border-bottom" data-fee="'+address.delivery_fee+'" data-address-id="'+address.id+'">\n' +
  410. ' <div class="flex-shrink-0">\n' +
  411. ' <img src="'+img+'" alt="...">\n' +
  412. ' </div>\n' +
  413. ' <div class="flex-grow-1 ms-3">\n' +
  414. '<p class="address-label">'+label+'</p>' +
  415. '<small> '+address.address+'</small>' +
  416. ' </div>\n ';
  417. if(address.is_set==0){
  418. str+='<div class="ms-auto p-2 bd-highlight check_address" style="display: none;" ><a href="#!" class="" data-id="'+address.id+'"> <i class="icofont-check fs-1 text-success position-relative top-50"></i></a> </div>';
  419. str+='<div class="ms-auto p-2 bd-highlight delete_address"><a href="#!" class="delete-address" data-id="'+address.id+'"> <i class="icofont-trash fs-2 position-relative top-50"></i></a> </div>';
  420. }else{
  421. str+='<div class="ms-auto p-2 bd-highlight check_address" ><a href="#!" class="" data-id="'+address.id+'"> <i class="icofont-check fs-1 text-success position-relative top-50"></i></a> </div>';
  422. str+='<div class="ms-auto p-2 bd-highlight delete_address"><a href="#!" class="delete-address" data-id="'+address.id+'"> <i class="icofont-trash fs-2 position-relative top-50"></i></a> </div>';
  423. }
  424. // str+='<div class="ms-auto p-2 bd-highlight"><a href="#!" class="delete-address" data-id="'+address.id+'"> <i class="icofont-check fs-1 text-success position-relative top-50"></i></a> </div>';
  425. str+= ' </div>';
  426. return str;
  427. }
  428. var format = function(num){
  429. var str = num.toString().replace("$", ""), parts = false, output = [], i = 1, formatted = null;
  430. if(str.indexOf(".") > 0) {
  431. parts = str.split(".");
  432. str = parts[0];
  433. }
  434. str = str.split("").reverse();
  435. for(var j = 0, len = str.length; j < len; j++) {
  436. if(str[j] != ",") {
  437. output.push(str[j]);
  438. if(i%3 == 0 && j < (len - 1)) {
  439. output.push(",");
  440. }
  441. i++;
  442. }
  443. }
  444. formatted = output.reverse().join("");
  445. return("" + formatted + ((parts) ? "." + parts[1].substr(0, 2) : ""));
  446. };
  447. </script>
  448. @endsection