diff --git a/application/controllers/Webservices.php b/application/controllers/Webservices.php index ae08b79..3ea2301 100644 --- a/application/controllers/Webservices.php +++ b/application/controllers/Webservices.php @@ -38,6 +38,8 @@ if (isset(apache_request_headers()['Auth'])) { $auth = apache_request_headers()['Auth']; } + + define("PAYSTACK_SECRET_KEY", "sk_test_36658e3260b1d1668b563e6d8268e46ad6da3273"); } // customer_login @@ -287,7 +289,7 @@ $postData = $_POST; $optionalData=array('optionlaDescription'=>'','optionalImages'=>array(),'optionalVideos'=>array()); $respArr = array('status'=>'0','message'=>'Something went wrong.'); - //pr(json_decode($postData['data'])); + if(empty($postData) || empty($postData = json_decode($postData['data'],true)) || !isset($postData['cost']) || empty($postData['cost']) || !isset($postData['customer_id']) || empty($postData['customer_id']) || @@ -322,6 +324,7 @@ $postData['optionalData'] = $optionalData; $status = $this->Booking_model->scheduleBooking($postData); + if($status){ $respArr['status'] = '1'; $respArr['message'] = 'Success'; @@ -1354,6 +1357,105 @@ $result = $this->Webservice_model->acceptMechanicQuote($postData); echo json_encode($result);exit; } + + public function payNow($transId) { + $result = array(); + $mech_data = $this->Webservice_model->getMechAmount($transId); + $amount = $mech_data['data']['amount'] * 100; + $callback_url = base_url().'Webservices/verify_payment/'.$transId; + $postdata = array('email' => $mech_data['emailId'], 'amount' => $amount,"reference" => $transId, "callback_url" => $callback_url); + + $url = "https://api.paystack.co/transaction/initialize"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($postdata)); //Post Fields + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + $headers = [ + 'Authorization: Bearer '.PAYSTACK_SECRET_KEY, + 'Content-Type: application/json', + ]; + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $request = curl_exec ($ch); + curl_close ($ch); + + if ($request) { + $result = json_decode($request, true); + } + $redir = $result['data']['authorization_url']; + header("Location: ".$redir); + } + + public function verify_payment($ref) { + $result = array(); + $url = 'https://api.paystack.co/transaction/verify/'.$ref; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt( + $ch, CURLOPT_HTTPHEADER, [ + 'Authorization: Bearer '.PAYSTACK_SECRET_KEY] + ); + $request = curl_exec($ch); + curl_close($ch); + + if ($request) { + $result = json_decode($request, true); + $status = $this->Webservice_model->transactionResp($ref,$result); + if($status){ + if($result){ + if($result['data']){ + if($result['data']['status'] == 'success'){ + header("Location: ".base_url().'Webservices/success/'.$ref); + }else{ + header("Location: ".base_url().'Webservices/fail/'.$ref); + } + } + else{ + header("Location: ".base_url().'Webservices/fail/'.$ref); + } + }else{ + header("Location: ".base_url().'Webservices/fail/'.$ref); + } + } + }else{ + header("Location: ".base_url().'Webservices/fail/'.$ref); + } + } + + public function fail($ref = ''){ + header("Location: http://localhost:4200/dashboard?status=failure&tab=appointment&ref=".$ref); + } + + public function success($ref = ''){ + $this->db->select('customer_vehicle.car_name,bookings.scheduled_date,bookings.scheduled_time,customers.email,bookings.cost'); + $this->db->from('transaction'); + $this->db->join('bookings','transaction.booking_id = bookings.booking_id'); + $this->db->join('customer_vehicle','customer_vehicle.customer_veh_id = bookings.customer_veh_id'); + $this->db->join('customers','customers.customer_id = bookings.customer_id'); + $this->db->where('transaction.id',$ref); + $bookData = $this->db->get()->row(); + $subject = "DcarFixxers, Payment Successfull"; + $email_id = $bookData->email; + $message = "<html> + <body> + Hi,\n\r Welcome to DcarFixxers. \r\n Your Payment for the vehicle ".$bookData->car_name." on date ".$bookData->scheduled_date." at ".$bookData->scheduled_time." for amount ".$bookData->cost." is Success + </body> + </html>"; + + $template = getNotifTemplate(); + if(isset($template['success_booking']) && !empty($template['success_booking'])){ + $message = str_replace(array('{:car_name}','{:book_date}','{:amount}'),array($bookData->car_name,$bookData->scheduled_date,$bookData->cost),$template['success_booking']); + } + send_mail($subject,$email_id,$message); + header("Location: http://localhost:4200/dashboard?status=success&tab=appointment&ref=".$ref); + } } + ?> diff --git a/application/helpers/generals_helper.php b/application/helpers/generals_helper.php index 159a117..5387016 100644 --- a/application/helpers/generals_helper.php +++ b/application/helpers/generals_helper.php @@ -95,4 +95,35 @@ $unique = md5(uniqid(time().mt_rand(), true)); return $unique; } + + function getNotifTemplate(){ + $CI = & get_instance(); + $settings = $CI->db->get('notification_templates'); + return (!empty($settings))?$settings->row_array():''; + } + + function send_mail($subject,$email,$message,$attach=null) { + $ci =& get_instance(); + $ci->load->library('email'); + $ci->email->initialize(array( + 'protocol' => 'smtp', + 'smtp_host' => 'smtp.sendgrid.net', + 'smtp_user' => 'adarsh@techware.in', + 'smtp_pass' => 'Golden_123', + 'smtp_port' => 587, + 'crlf' => "\r\n", + 'newline' => "\r\n" + )); + + $ci->email->from('no-reply@nuvento.com', 'DcarFixxers'); + $ci->email->to($email); + $ci->email->cc('adarsh@techware.in'); + $ci->email->subject($subject); + $ci->email->message($message); + $ci->email->set_mailtype('html'); + if($attach != null) { + $ci->email->attach($attach); + } + return $ci->email->send(); + } ?> \ No newline at end of file diff --git a/application/models/Booking_model.php b/application/models/Booking_model.php index 47619dc..d91d8dc 100644 --- a/application/models/Booking_model.php +++ b/application/models/Booking_model.php @@ -87,7 +87,8 @@ class Booking_model extends CI_Model { $book_id = $this->db->insert_id(); $mechanic_id = explode(',',$postData['mechanic_id']); foreach ($mechanic_id AS $mech_id) { - $insertBookMech[] = array('booking_id'=>$book_id,'mechanic_id'=>$mech_id,'status'=>'0'); + $mech_amt = explode(':',$mech_id); + $insertBookMech[] = array('booking_id'=>$book_id,'mechanic_id'=>$mech_amt[0],'amount'=>$mech_amt[1],'status'=>'0'); } if(!empty($insertBookMech)){ $this->db->insert_batch('mechanic_booking',$insertBookMech); @@ -129,7 +130,7 @@ class Booking_model extends CI_Model { $mechanic_data = $this->db->query(" SELECT ROUND(AVG(MR.rate),2) AS rating,MCH.mechanic_id,MCH.first_name, MCH.last_name,MCH.phone,CQ.custom_service_quote,MCH.location, - MCH.email_id,CQ.custom_amount,BK.status + MCH.email_id,CQ.custom_amount,BK.status,BK.amount as mechanic_amount FROM mechanic_booking AS BK INNER JOIN mechanic MCH ON BK.mechanic_id=MCH.mechanic_id INNER JOIN admin_users AU ON AU.id=MCH.mechanic_id @@ -169,6 +170,27 @@ class Booking_model extends CI_Model { array('status'=>$status), array('customer_id'=>$customer_id,'booking_id'=>$booking_id)); + $this->db->select('customer_vehicle.car_name,bookings.scheduled_date,bookings.scheduled_time,customers.email'); + $this->db->from('bookings'); + $this->db->join('customer_vehicle','customer_vehicle.customer_veh_id = bookings.customer_veh_id'); + $this->db->join('customers','customers.customer_id = bookings.customer_id'); + $this->db->where('bookings.booking_id',$booking_id); + $bookData = $this->db->get()->row(); + + $subject = "DcarFixxers, Cancel Booking"; + $email_id = $bookData->email; + $message = "<html> + <body> + Hi,\n\r Welcome to DcarFixxers. \r\n Your booking for the vehicle ".$bookData->car_name." on date ".$bookData->scheduled_date." at ".$bookData->scheduled_time." is Cancelled. + </body> + </html>"; + + $template = getNotifTemplate(); + if(isset($template['cancel_booking']) && !empty($template['cancel_booking'])){ + $message = str_replace(array('{:car_name}','{:book_date}'),array($bookData->car_name,$bookData->scheduled_date),$template['cancel_booking']); + } + send_mail($subject,$email_id,$message); + return $status; } diff --git a/application/models/Customer_model.php b/application/models/Customer_model.php index 88bd35e..d8da635 100644 --- a/application/models/Customer_model.php +++ b/application/models/Customer_model.php @@ -50,6 +50,23 @@ class Customer_model extends CI_Model { $this->db->query("UPDATE customer_vehicle SET status='1',customer_id='$cust_id' WHERE customer_veh_id IN ($saved_vehicles)"); } + + $subject = "DcarFixxers,Activation Mail"; + $email_id = $customer_data['email']; + //$reset_link = 'https://projects.nuvento.com/admin/Api/verifyMail/'.$unique_id; + $message = "<html> + <body> + Hi,\n\r Welcome to DcarFixxers. \r\n Your account for the Username ".$email_id." is now Activated. + </body> + </html>"; + + $template = getNotifTemplate(); + if(isset($template['customer_registration_mail']) && !empty($template['customer_registration_mail'])){ + $message = str_replace(array('{:email}'),array($email_id),$template['customer_registration_mail']); + } + send_mail($subject,$email_id,$message); + $res = array('status'=>1,'data'=>''); + return ($status)?1:0;; } diff --git a/application/models/Mechanic_model.php b/application/models/Mechanic_model.php index d01af9c..6f15220 100644 --- a/application/models/Mechanic_model.php +++ b/application/models/Mechanic_model.php @@ -130,8 +130,26 @@ class Mechanic_model extends CI_Model { if(empty($mechanic_id)){ return 0; } - $status = $this->db->update('admin_users',array('status'=>$status),array('id'=>$mechanic_id)); - return $status; + $resp = $this->db->update('admin_users',array('status'=>$status),array('id'=>$mechanic_id)); + if($status == '1'){ + $mechData = $this->db->get_where('mechanic',array(' mechanic_id'=>$mechanic_id))->row(); + + $subject = "DcarFixxers, Activation Mail"; + $email_id = $mechData->email_id; + $message = "<html> + <body> + Hi,\n\r Welcome to DcarFixxers. \r\n Your account for the Username ".$email_id." is now Activated. + </body> + </html>"; + + $template = getNotifTemplate(); + if(isset($template['mechanic_activation_mail']) && !empty($template['mechanic_activation_mail'])){ + $message = str_replace(array('{:user_name}'),array($email_id),$template['mechanic_activation_mail']); + } + send_mail($subject,$email_id,$message); + $res = array('status'=>1,'data'=>''); + } + return $resp; } function getNearByMechanics($location_data = array(),$sub_issues = array()){ diff --git a/application/models/Webservice_model.php b/application/models/Webservice_model.php index ecc1516..9b3f41a 100644 --- a/application/models/Webservice_model.php +++ b/application/models/Webservice_model.php @@ -531,15 +531,56 @@ class Webservice_model extends CI_Model { $respArr['message'] = 'Mechanic Id is Required'; return $respArr; } + if(empty($postData['amount'])){ + $respArr['message'] = 'Amount is Required'; + return $respArr; + } if($this->db->update('mechanic_booking',array('status'=>'1'),array('booking_id'=>$postData['bookingId'],'mechanic_id'=>$postData['mechanicId']))){ $this->db->update('mechanic_booking',array('status'=>'2'),array('booking_id'=>$postData['bookingId'],'mechanic_id !='=>$postData['mechanicId'])); - $this->db->update('bookings',array('status'=>'1'),array('booking_id'=>$postData['bookingId'])); + $this->db->update('bookings',array('status'=>'5','cost'=>$postData['amount']),array('booking_id'=>$postData['bookingId'])); + } + $book_data = $this->db->get_where('bookings',array('booking_id'=>$postData['bookingId']))->row(); + $transaction_array = array( + 'customer_id'=>$book_data->customer_id, + 'booking_id'=>$postData['bookingId'], + 'datetime'=>date('Y-m-d h:i:s'), + 'amount'=>$postData['amount'] + ); + $this->db->insert('transaction',$transaction_array); + + $respArr['data'] = $this->db->insert_id(); + $respArr['status'] = 'success'; + $respArr['message'] = 'Updated Successfully'; + return $respArr; + } + + public function getMechAmount($transId){ + $respArr = array('status'=>'error'); + if(empty($transId)){ + return $respArr; + } + $result = $this->db->get_where('transaction',array('id'=>$transId)); + if(!empty($result) && $result->num_rows() > 0){ + $result = $result->row_array(); $respArr['status'] = 'success'; - $respArr['message'] = 'Updated Successfully'; + $respArr['data'] = $result; } + $custData = $this->db->get_where('customers',array('customer_id'=>$result['customer_id']))->row(); + $respArr['emailId'] = $custData->email; return $respArr; } + + public function transactionResp($transId,$result){ + $status = 0; + if($result['data']['status'] == 'success'){ + $status = 1; + } + $this->db->update('transaction',array('transaction_response'=>json_encode($result),'transaction_reference'=>$result['data']['id'],'status'=>$status),array('id'=>$transId)); + $bookData = $this->db->get_where('transaction',array('id'=>$transId))->row(); + $this->db->update('bookings',array('status'=>'1'),array('booking_id'=>$bookData->booking_id)); + return 1; + } } ?> diff --git a/application/views/Templates/footer-script.php b/application/views/Templates/footer-script.php index 209d801..ed14139 100644 --- a/application/views/Templates/footer-script.php +++ b/application/views/Templates/footer-script.php @@ -16,13 +16,22 @@ <script src="<?= base_url('assets/js/app.min.js') ?>"></script> <script src="<?= base_url('assets/js/custom-script.js') ?>"></script> <script src="<?= base_url('assets/js/parsley.min.js') ?>"></script> -<script src="<?= base_url('assets/js/ckeditor.js') ?>"></script> +<script src="https://cdn.ckeditor.com/4.5.7/standard/ckeditor.js"></script> <script src="<?= base_url('assets/js/bootstrap-datepicker.js') ?>"></script> <script src="<?= base_url('assets/js/clockpicker.js') ?>" type="text/javascript"></script> <script> jQuery('.clockpicker').clockpicker(); + jQuery( document ).ready(function() { + if(jQuery('#rich_editor').length==1){ CKEDITOR.replace('rich_editor'); } + if(jQuery('#rich_editor1').length==1){CKEDITOR.replace('rich_editor1'); } + if(jQuery('#rich_editor_2').length==1){CKEDITOR.replace('rich_editor_2');} + if(jQuery('#rich_editor_3').length==1){CKEDITOR.replace('rich_editor_3');} + if(jQuery('#rich_editor_4').length==1){CKEDITOR.replace('rich_editor_4');} + if(jQuery('#rich_editor_5').length==1){CKEDITOR.replace('rich_editor_5');} + }); + function doconfirm(){ action = confirm("Are you sure to delete permanently?"); if(action != true) return false; diff --git a/application/views/Templates/footer.php b/application/views/Templates/footer.php index 3cb33ad..2180c16 100644 --- a/application/views/Templates/footer.php +++ b/application/views/Templates/footer.php @@ -23,5 +23,5 @@ <div class="pull-right hidden-xs"> <b>Version</b> 1.0 </div> - <strong>Copyright © 2015-2016 <a href="#">Techware Solution</a>.</strong> All rights reserved. + <strong>Copyright © <?= date('Y')?> - <?= date('Y')+1?> <a href="#">CarFixxers</a>.</strong> All rights reserved. </footer> \ No newline at end of file diff --git a/application/views/Templates/left-menu.php b/application/views/Templates/left-menu.php index 44fe330..bbeebce 100644 --- a/application/views/Templates/left-menu.php +++ b/application/views/Templates/left-menu.php @@ -43,7 +43,7 @@ <li class="treeview"> <a href="#"> <i class="fa fa-bars" aria-hidden="true"></i> - <span>Issue Management</span> + <span>Service Orders</span> <i class="fa fa-angle-left pull-right"></i> </a> <ul class="treeview-menu"> @@ -118,11 +118,58 @@ </li> </ul> </li> - <?php } ?> <li> - <a href="<?= base_url('Bookings/listBookings') ?>"><i class="fa fa-book" aria-hidden="true"> - </i><span>Request Management</span></a> + <a href="<?= base_url('Mailtemplate') ?>"><i class="fa fa-book" aria-hidden="true"> + </i><span>Mail Template</span></a> </li> + <?php } ?> + <li> + <a href="<?= base_url('Bookings/listBookings') ?>"><i class="fa fa-book" aria-hidden="true"> + </i><span>Request Management</span></a> + </li> + <li class="treeview"> + <a href="#"> + <i class="fa fa-bars" aria-hidden="true"></i> + <span>Product Management</span> + <i class="fa fa-angle-left pull-right"></i> + </a> + <ul class="treeview-menu"> + <li> + <a href="<?= base_url('Product/addProduct') ?>"> + <i class="fa fa-circle-o text-aqua"></i> + Add New Product + </a> + </li> + <li> + <a href="<?= base_url('Product/viewProduct') ?>"> + <i class="fa fa-circle-o text-aqua"></i> + View All Product + </a> + </li> + </ul> + </li> + + <li class="treeview"> + <a href="#"> + <i class="fa fa-bars" aria-hidden="true"></i> + <span>Brand Management</span> + <i class="fa fa-angle-left pull-right"></i> + </a> + <ul class="treeview-menu"> + <li> + <a href="<?= base_url('Brand/addBrand') ?>"> + <i class="fa fa-circle-o text-aqua"></i> + Add New Brand + </a> + </li> + <li> + <a href="<?= base_url('Brand/viewBrand') ?>"> + <i class="fa fa-circle-o text-aqua"></i> + View All Brand + </a> + </li> + </ul> + </li> <?php if($this->session->userdata['user_type'] == 1){ ?> <li><a href="<?= base_url('Settings') ?>"> <i class="fa fa-wrench" aria-hidden="true"> diff --git a/assets/css/custom-style.css b/assets/css/custom-style.css index 93c2457..1642642 100644 --- a/assets/css/custom-style.css +++ b/assets/css/custom-style.css @@ -500,6 +500,70 @@ border: 1px solid red !important; } + + .dropZoneContainer{ + position: relative; + display: inline-block; + } + + .close_custom{ + position: absolute; + width: 17px; + height: 17px; + text-align: center; + background: #000; + font-size: 13px; + top: -5px; + right: -1px; + color: #fff; + border-radius: 50%; + z-index: 99; + } + + .dropZoneOverlay, .FileUpload { + width: 250px; + height: 250px; + } + + .multiDropZoneOverlay, .multiFileUpload { + width: 50px; + height: 50px; + } + + .dropZoneOverlay { + border: dotted 1px; + font-family: cursive; + color: #040404; + text-align: center; + position: absolute; + top:0px; + left:0px; + right:0px; + } + + .multiDropZoneOverlay { + border: dotted 1px; + font-family: cursive; + color: #040404; + text-align: center; + position: absolute; + top:0px; + left:0px; + right:0px; + } + + .FileUpload { + opacity: 0; + position: relative; + z-index: 1; + } + + .multiFileUpload { + opacity: 0; + position: relative; + z-index: 1; + } + input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; @@ -507,3 +571,7 @@ appearance: none; margin: 0; } + + .errorBorder { + border: 1px solid #ff0000 !important; + } diff --git a/assets/js/custom-script.js b/assets/js/custom-script.js index 5f8cdd4..3f3d8fc 100644 --- a/assets/js/custom-script.js +++ b/assets/js/custom-script.js @@ -13,6 +13,28 @@ function setImg(input,id) { } } +function setMultiImg(input,thisObj){ + if (input.files && input.files[0]) { + var reader = new FileReader(); + + reader.onload = function (e) { + var count = thisObj.attr('count'); + thisObj.attr('count',count+1); + jQuery('[id="multipleImageInputCntr"]').append(jQuery('[id="multipleImageInput"]').html().replace(/{:count}/g,count+1)); + + thisObj.addClass('prevent-click'); + jQuery('[id="multiImageClose_'+count+'"]').removeClass('hide'); + jQuery('[id="multiImageImg_'+count+'"]').attr('src', e.target.result); + jQuery('[id^="multiImageImg_"]').removeClass('errorBorder'); + }; + reader.readAsDataURL(input.files[0]); + } +} + +function removeImage(count){ + jQuery('[id="multiImageCntr_'+count+'"]').remove(); +} + function setModal(header_msg,body_msg){ jQuery('[id="modal_body_msg"]').html(body_msg); jQuery('[id="modal_header_msg"]').html(header_msg); @@ -1199,4 +1221,20 @@ jQuery('[id="showBookinDetails"]').on('click',function() { jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!'); } }); +}); + +jQuery('[id="addProductButton"]').on('click',function(event) { + event.preventDefault(); + var validation = jQuery('[name="productAddForm"]').parsley().validate(); + + var error = 0; + var count = jQuery('[id="multipleImageInputCntr"]').children().first().attr('count'); + if(jQuery('[id="product_image_'+count+'"]').val() == ''){ + error = 1; + jQuery('[id="multiImageImg_'+count+'"]').addClass('errorBorder'); + } + + if(validation && error == 0){ + jQuery('[name="productAddForm"]').submit(); + } }); \ No newline at end of file diff --git a/index.php b/index.php index ceab77d..e474c63 100644 --- a/index.php +++ b/index.php @@ -75,7 +75,7 @@ switch (ENVIRONMENT) case 'testing': case 'production': - error_reporting(-1); + error_reporting(-1); ini_set('display_errors', 0); if (version_compare(PHP_VERSION, '5.3', '>=')) {