Commit 1367c426 by Jansa Jose

changes in admin panel and webservice

parent d862c06e
......@@ -1573,12 +1573,14 @@
!empty($result['data']['authorization_url'])){
$redir = $result['data']['authorization_url'];
header("Location: ".$redir);
}
//pr($result);
$status = $this->Webservice_model->transactionResp($postdata['reference'],$result,$payFor);
}else{
$ref = $postdata['reference'];
$status = $this->Webservice_model->transactionResp($ref,$result,$payFor);
$this->fail();
}
}
public function verify_payment($ref='',$payFor='1') {
if(empty($ref)){
$this->fail();
......
......@@ -2,14 +2,12 @@
defined('BASEPATH')OR exit('No direct script access allowed');
header('Content-Type: text/html; charset=utf-8');
// Allow from any origin
if(isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
......@@ -28,27 +26,21 @@
$auth = '';
$class = $this->router->fetch_class();
$method = $this->router->fetch_method();
if($this->input->server('REQUEST_METHOD') == 'GET')
$postdata = json_encode($_GET);
else if ($this->input->server('REQUEST_METHOD') == 'POST')
$postdata = file_get_contents("php://input");
if (isset(apache_request_headers()['Auth'])) {
$auth = apache_request_headers()['Auth'];
}
define("PAYSTACK_SECRET_KEY", "sk_test_36658e3260b1d1668b563e6d8268e46ad6da3273");
}
// customer_login
public function sign_in_mechanic(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$respArr = array('status'=>'error','message'=>'Required Fields are empty.');
if(!isset($postData['user_name']) || empty($postData['user_name']) ||
!isset($postData['password']) || empty($postData['password'] = md5($postData['password']))){
......@@ -62,43 +54,33 @@
public function get_todays_services(){
header('Content-type: application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1;
$start = ($page - 1) * $per_page;
$postData['mechanic_id'] = $authRes['data']['mechanic_id'];
$bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,1);
$bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,1);
$total = 0;
if($bookDataCount['status'] == 'success'){
$total = count($bookDataCount['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($bookDataResult['status'] == 'success'){
$respArr = array(
'status' => 'success',
......@@ -130,71 +112,56 @@
public function services_details(){
header('Content-type: application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$postData['mechanic_id'] = $authRes['data']['mechanic_id'];
if(!isset($postData['service_id']) || empty($postData['service_id'])){
$respArr['message'] = "Service Id is Required";
return $respArr;
}
$respArr = $this->Webservice_mechanic_model->getBookedService($postData);
echo json_encode($respArr);exit;
}
public function get_service_history(){
header('Content-type: application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1;
$start = ($page - 1) * $per_page;
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$postData['mechanic_id'] = $authRes['data']['mechanic_id'];
$bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,0,3);
$bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,0,3);
$total = 0;
if($bookDataCount['status'] == 'success'){
$total = count($bookDataCount['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($bookDataResult['status'] == 'success'){
$respArr = array(
'status' => 'success',
......@@ -226,34 +193,28 @@
public function logout(){
header('Content-type: application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$respArr = $this->Webservice_mechanic_model->mechanic_logout($authRes['data']['mechanic_id']);
$respArr=$this->Webservice_mechanic_model->mechanic_logout($authRes['data']['mechanic_id']);
echo json_encode($respArr);exit;
}
public function forgot_password(){
header('Content-type: application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
if(!isset($postData['user_name']) || empty($postData['user_name'])){
$respArr['message'] = "Username is Required";
echo json_encode($respArr);exit;
}
$respArr = $this->Webservice_mechanic_model->forgot_password($postData['user_name']);
echo json_encode($respArr);exit;
}
......@@ -261,10 +222,8 @@
public function change_password(){
header('Content-type: application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$respArr = array("status"=>"error");
if(!isset($postData['user_name']) || empty($postData['user_name'])){
$respArr['message'] = "Username is Required";
......@@ -273,7 +232,6 @@
$respArr['message'] = "Password is Required";
echo json_encode($respArr);exit;
}
$respArr = $this->Webservice_mechanic_model->change_password($postData);
echo json_encode($respArr);exit;
}
......@@ -281,10 +239,8 @@
public function start_service(){
header('Content-type: application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$respArr = array("status"=>"error");
if(!isset($postData['service_id']) || empty($postData['service_id'])){
$respArr['message'] = "Booking Id is Required";
......@@ -301,10 +257,8 @@
public function stop_service(){
header('Content-type: application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
if(!isset($postData['service_id']) || empty($postData['service_id'])){
$respArr['message'] = "Booking Id is Required";
return $respArr;
......@@ -312,7 +266,6 @@
$respArr['message'] = "Emergency Field is Required";
return $respArr;
}
$respArr = $this->Webservice_mechanic_model->start_service($postData,1);
echo json_encode($respArr);exit;
}
......
......@@ -6,47 +6,91 @@ class Dashboard_model extends CI_Model {
}
public function getBookingCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('bookings')->result();
}else{
$id = $this->session->userdata('id');
$this->db->join('mechanic_booking','mechanic_booking.booking_id = bookings.booking_id','left');
$result = $this->db->get_where('bookings',array('mechanic_booking.mechanic_id'=>$id))->result();
}
return count($result);
}
public function getMechShpCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('mechanic_shop',array('status'=>'1'))->result();
}else{
return 0;
}
return count($result);
}
public function getCompletedBookingCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('bookings',array('status'=>'3'))->result();
}else{
$id = $this->session->userdata('id');
$this->db->join('mechanic_booking','mechanic_booking.booking_id = bookings.booking_id','left');
$result = $this->db->get_where('bookings',array('mechanic_booking.mechanic_id'=>$id,'bookings.status'=>'3'))->result();
}
return count($result);
}
public function getPendingBookingCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('bookings',array('status'=>'1'))->result();
}else{
$id = $this->session->userdata('id');
$this->db->join('mechanic_booking','mechanic_booking.booking_id = bookings.booking_id','left');
$result = $this->db->get_where('bookings',array('mechanic_booking.mechanic_id'=>$id,'bookings.status'=>'1'))->result();
}
return count($result);
}
public function getMbleVndrsCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('mechanic',array('shop_id'=>'1'))->result();
}else{
return 0;
}
return count($result);
}
public function getMbleMchnsCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('mechanic',array('shop_id'=>'0'))->result();
}else{
return 0;
}
return count($result);
}
public function getCustomerCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('customers',array('status'=>'1'))->result();
}else{
return 0;
}
return count($result);
}
public function getProductCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->get_where('products',array('status'=>'1'))->result();
}else{
$id = $this->session->userdata('id');
$result = $this->db->get_where('products',array('status'=>'1','created_by'=>$id))->result();
}
return count($result);
}
public function getProductSoldCount(){
if($this->session->userdata('user_type') == 1){
$result = $this->db->query("SELECT SUM(`quantity`) as count FROM `orders` WHERE status IN('2,3,4,5')")->row();
}else{
$id = $this->session->userdata('id');
$result = $this->db->query("SELECT SUM(`quantity`) as count FROM `orders` INNER JOIN products ON products.product_id = orders.product_id WHERE orders.status IN('2,3,4,5') AND products.created_by='$id'")->row();
}
return $result->count;
}
......
......@@ -4,10 +4,8 @@
parent::__construct();
date_default_timezone_set('Asia/Kolkata');
}
/***************************************************************************************/
/****************************************Mobile API's***********************************/
function checkMechanicLogin($userLogData){
$respArr = array('status'=>'error');
if(empty($userLogData)){
......@@ -19,12 +17,10 @@ function checkMechanicLogin($userLogData){
$this->db->join('mechanic_shop as MCHSHP','MCHSHP.shop_id = MCH.shop_id','LEFT');
$this->db->where(array('AU.username'=>$userLogData['user_name'],'AU.password'=>$userLogData['password']));
$result = $this->db->get();
if(empty($result) || $result->num_rows() < 0 || empty($mechData = $result->row())){
$respArr['message'] = "Username or Password is Incorrect";
return $respArr;
}
$authdata = $this->insert_auth($mechData->user_id);
if($authdata){
$mechData->auth_token = $authdata;
......@@ -41,10 +37,9 @@ public function insert_auth($id){
if(!empty($mechData) && $mechData->num_rows() > 0){
$mechData = $mechData->row();
$authToken = $mechData->authtoken;
} else {
}else {
$this->db->insert('authtable_mechanic',array('mechanic_id'=>$id,'authtoken'=>$authToken));
}
return $authToken;
}
......@@ -71,7 +66,6 @@ public function getBookedService($postData = array(),$start = '',$per_page = '',
$respArr['message'] = "All Field is Required";
return $respArr;
}
$where = array('BUK.status'=>$status,'MCHBUK.mechanic_id'=>$postData['mechanic_id']);
if(isset($postData['service_id']) && !empty($postData['service_id'])){
$where['BUK.booking_id'] = $postData['service_id'];
......@@ -86,7 +80,7 @@ public function getBookedService($postData = array(),$start = '',$per_page = '',
// $where['BUK.scheduled_date'] = date("Y-m-d", strtotime('tomorrow'));
// }
$this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount as total_amount,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,CUST.phone as phone_number,CSTVEH.vehicle_data");
$this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,BUK.status,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount as total_amount,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,CUST.phone as phone_number,CSTVEH.vehicle_data");
$this->db->from('bookings as BUK');
$this->db->join('customers as CUST','CUST.customer_id = BUK.customer_id');
$this->db->join('customer_vehicle as CSTVEH','CSTVEH.customer_veh_id = BUK.customer_veh_id');
......@@ -183,7 +177,7 @@ public function start_service($postData = array(),$type = 0){
return $respArr;
}
$status = ($type == '1')?3:1;
$status = ($type == '1')?3:6;
$cost = ($postData['emergency'] == '2')?$postData['amount']:'';
if($this->db->update('bookings',array('service_type'=>$postData['emergency'],'cost'=>$cost,'status'=>$status),array('booking_id'=>$postData['service_id']))){
$respArr['status'] = "success";
......
......@@ -681,7 +681,7 @@ class Webservice_model extends CI_Model {
}
}
$this->db->update('transaction',array('transaction_response'=>$respJson,'transaction_reference'=>$trancRef,'status'=>$status),array('id'=>$transId));
$this->db->update('transaction',array('transaction_response'=>$respJson,'transaction_reference'=>$trancReference,'status'=>$status),array('id'=>$transId));
if($payfor == '1'){
$this->db->query("UPDATE bookings
......
......@@ -24,8 +24,7 @@
<div class="small-box bg-yellow">
<div class="inner">
<h4>Users</h4>
<p><?php
echo 'Total : '. $customerCount ?></p>
<p><?php echo 'Total : '. $customerCount ?></p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
......@@ -33,17 +32,13 @@
<a href="<?= base_url('Customer/listCustomerUsers') ?>" class="small-box-footer ">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($bookingCount) && !empty($bookingCount)){ ?>
<?php } if(isset($bookingCount) && !empty($bookingCount)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-green">
<div class="inner">
<h4>Total Bookings</h4>
<p>
<?php
echo 'Total : '.$bookingCount;
?>
<?php echo 'Total : '.$bookingCount; ?>
</p>
</div>
<div class="icon">
......@@ -52,15 +47,12 @@
<a href="<?= base_url('Bookings/listBookings') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($completeBukngCnt) && !empty($completeBukngCnt)){ ?>
<?php } if(isset($completeBukngCnt) && !empty($completeBukngCnt)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-aqua">
<div class="inner">
<h4>Completed Bookings</h4>
<p><?php
echo 'Total : '. $completeBukngCnt ?></p>
<p><?php echo 'Total : '. $completeBukngCnt ?></p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
......@@ -68,15 +60,12 @@
<a href="<?= base_url('Bookings/listBookings') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($pendingBukngCnt) && !empty($pendingBukngCnt)){ ?>
<?php } if(isset($pendingBukngCnt) && !empty($pendingBukngCnt)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-blue">
<div class="inner">
<h4>Pending Bookings</h4>
<p><?php
echo 'Total : '. $pendingBukngCnt ?></p>
<p><?php echo 'Total : '. $pendingBukngCnt ?></p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
......@@ -84,15 +73,12 @@
<a href="<?= base_url('Bookings/listBookings') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($shopCount) && !empty($shopCount)){ ?>
<?php } if(isset($shopCount) && !empty($shopCount)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-blue">
<div class="small-box bg-red">
<div class="inner">
<h4>Mechanic Shops</h4>
<p><?php
echo 'Total : '. $shopCount ?></p>
<p><?php echo 'Total : '. $shopCount ?></p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
......@@ -100,16 +86,12 @@
<a href="<?= base_url('Shop/viewShops') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($mobileVendors) && !empty($mobileVendors)){ ?>
<?php } if(isset($mobileVendors) && !empty($mobileVendors)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-yellow">
<div class="small-box bg-blue">
<div class="inner">
<h4> Mobile Vendors</h4>
<p><?php
echo 'Total : '. $mobileVendors ?></p>
<p><?php echo 'Total : '. $mobileVendors ?></p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
......@@ -117,15 +99,12 @@
<a href="<?= base_url('Mechanic/viewMechanics') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($mobileMechanics) && !empty($mobileMechanics)){ ?>
<?php } if(isset($mobileMechanics) && !empty($mobileMechanics)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-red">
<div class="small-box bg-orange">
<div class="inner">
<h4>Mobile Mechanics</h4>
<p><?php
echo 'Total : '. $mobileMechanics ?></p>
<p><?php echo 'Total : '. $mobileMechanics ?></p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
......@@ -133,15 +112,12 @@
<a href="<?= base_url('Mechanic/viewMechanics') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($productCount) && !empty($productCount)){ ?>
<?php } if(isset($productCount) && !empty($productCount)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-green">
<div class="inner">
<h4>Product Count</h4>
<p><?php
echo 'Total : '. $productCount ?></p>
<p><?php echo 'Total : '. $productCount ?></p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
......@@ -149,15 +125,12 @@
<a href="<?= base_url('Product/viewProducts') ?>" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
<?php } ?>
<?php if(isset($productSold) && !empty($productSold)){ ?>
<?php } if(isset($productSold) && !empty($productSold)){ ?>
<div class="col-lg-3 col-xs-6">
<div class="small-box bg-red">
<div class="small-box bg-yellow">
<div class="inner">
<h4>Product Sold</h4>
<p><?php
echo 'Total : '. $productSold ?></p>
<p><?php echo 'Total : '. $productSold ?></p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
......@@ -166,14 +139,14 @@
</div>
</div>
<?php } ?>
</div>
<div class="row">
<div class="col-md-6" id="order_report">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Order Sales Report</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
......@@ -182,14 +155,12 @@
</div>
</div>
</div>
<div class="col-md-6" id="booking_report">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Booking Sales Report</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
......@@ -202,15 +173,15 @@
</section>
</div>
<script type="text/javascript">
$(function () {
$(function () {
jQuery.ajax({
type: "POST",
url: base_url + 'Dashboard/getOrderSalesReportCount',
success: function (data) {
if(data == '1' || data == ''){
$('#order_report').addClass('hide');
return false;
}
// if(data == '1' || data == ''){
// $('#order_report').addClass('hide');
// return false;
// }
var data = jQuery.parseJSON(data);
var line = new Morris.Line({
element: 'line-chart',
......@@ -224,17 +195,17 @@ $(function () {
});
}
})
})
})
$(function () {
$(function () {
jQuery.ajax({
type: "POST",
url: base_url + 'Dashboard/getBookingReportCount',
success: function (data) {
if(data == '1'){
$('#booking_report').addClass('hide');
return false;
}
// if(data == '1'){
// $('#booking_report').addClass('hide');
// return false;
// }
var data = jQuery.parseJSON(data);
var line = new Morris.Line({
element: 'line-chart-booking',
......@@ -248,5 +219,5 @@ $(function () {
});
}
})
})
})
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment