File: /var/www/html/fieldsblaze-heroku/app/Http/Controllers/CommonController-55.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
//use DB;
use App\Library\UserLib;
use App\Models\User;
use App\Models\Countries;
use App\Models\States;
use App\Models\Customer;
use App\Models\CustomerType;
use App\Models\BeatPlan;
use App\Models\PaymentTerm;
use App\Models\PriceBook;
use App\Models\PriceBookEntry;
use App\Models\ProductFamily;
use App\Models\Product;
use App\Models\Order;
use App\Models\UOM;
use App\Models\GST;
use App\Models\PaymentType;
use App\Models\ExpenseType;
use App\Models\ExpenseTypeTravel;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
class CommonController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function index()
{
}
public function countryList(Request $request) {
//TODO What is device_token
$data = $request->json()->all();
//Check Country is exist or not
$countries = DB::table('tbl_countries')->orderBy('country_name', 'asc')->get();
if ($countries->count() > 0)
{
$response = [
'success' => true,
'response_message' => "Success",
'response_code' => "200",
'countries' => $countries,
];
return response()->json($response);
}
else
{
$response = [
'success' => false,
'response_message' => "data not found.",
'response_code' => "201",
];
return response()->json($response);
}
}
public function countryDetails(Request $request, $country_code) {
//TODO What is device_token
$data = $request->json()->all();
//Check Country is exist or not
$countries = DB::table('tbl_countries')->where('country_code', $country_code)->get()->first();
if ($countries)
{
$response = [
'success' => true,
'response_message' => "Success",
'response_code' => "200",
'country' => $countries,
];
return response()->json($response);
}
else
{
$response = [
'success' => false,
'response_message' => "data not found.",
'response_code' => "201",
];
return response()->json($response);
}
}
//get state list of country
public function stateList(Request $request, $country_id) {
//TODO What is device_token
$data = $request->json()->all();
if(!$country_id)
{
$response = [
'success' => false,
'response_message' => "country id required.",
'response_code' => "202",
'country_id' => $country_id,
];
return response()->json($response);
}
$countries = DB::table('tbl_countries')->where('id', $country_id)->get()->first();
$country_code = $countries->country_code;
$country_name = $countries->country_name;
//Check Country is exist or not
$states = DB::table('tbl_states')->select('id','state_name')->where('country_id', $country_id)->orderBy('state_name', 'asc')->get();
if ($states->count() > 0)
{
$response = [
'success' => true,
'response_message' => "Success",
'response_code' => "200",
'country_id' => $country_id,
'country_code' => $country_code,
'country_name' => $country_name,
'states' => $states,
];
return response()->json($response);
}
else
{
$response = [
'success' => false,
'response_message' => "data not found.",
'response_code' => "201",
];
return response()->json($response);
}
}
//get state list for Web
public function getCountry(Request $request)
{
$countryid = $request->post('country_id');
$countries_data = Countries::orderBy('country_name', 'asc')->get();
echo "<option value=''>Please select state</option>";
foreach($countries_data as $country) {
$country_id = $country->id;
$country_name = $country->country_name;
if($country_id == '101' || $country_id == $countryid)
{
echo "<option data-id='".$country_id."' value='".$country_id."' selected='selected'>".$country_name."</option>";
}
else
{
echo "<option data-id='".$country_id."' value='".$country_id."'>".$country_name."</option>";
}
}
}
public function getStates(Request $request)
{
$country_id = $request->post('country_id');
$country_id = isset($country_id) ? $country_id : "101";
$statename = $request->post('state_name');
$state_data = States::where('country_id', $country_id)->orderBy('state_name', 'asc')->get();
echo "<option value=''>Please select state</option>";
foreach($state_data as $state) {
$state_name = $state->state_name;
if($state_name == $statename)
{
echo "<option value='".$state_name."' selected='selected'>".$state_name."</option>";
}
else
{
echo "<option value='".$state_name."'>".$state_name."</option>";
}
}
}
### Customer List
public function CustomerList()
{
// $Customer = Customer::all()
// ->where('Status', '=', '1')
// ->where('IsDeleted', '=', '0');
// return response()->json([
// 'status' => 200,
// 'Customer' => $Customer,
// ]);
$Customer = Customer::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
$Retailer = Customer::select('tbl_customer.*', 'tbl_customer_type.Name as CustomerType')
->leftJoin('tbl_customer_type', 'tbl_customer.CustomerTypeId', '=', 'tbl_customer_type.CustomerTypeId')
->where('tbl_customer.CustomerTypeId', '=', '7zbZseyyTqvA6n7n5Bk01RvCm30KpPQa8M8k7')
->where('tbl_customer.Status', '=', '1')
->where('tbl_customer.IsDeleted', '=', '0')
->orderBy('tbl_customer.id', 'desc')
->get();
$Distributor = Customer::select('tbl_customer.*', 'tbl_customer_type.Name as CustomerType')
->leftJoin('tbl_customer_type', 'tbl_customer.CustomerTypeId', '=', 'tbl_customer_type.CustomerTypeId')
->where('tbl_customer.CustomerTypeId', '=', '4zZVseyyTqvA6n7n5Bk01RvCm30KpPQa8M8k2')
->where('tbl_customer.Status', '=', '1')
->where('tbl_customer.IsDeleted', '=', '0')
->orderBy('tbl_customer.id', 'desc')
->get();
$WholeSeller = Customer::select('tbl_customer.*', 'tbl_customer_type.Name as CustomerType')
->leftJoin('tbl_customer_type', 'tbl_customer.CustomerTypeId', '=', 'tbl_customer_type.CustomerTypeId')
->where('tbl_customer.CustomerTypeId', '=', 'ozbVseyyTqvA6n7n5Bk01RvCm40KpPQa8M8k3')
->where('tbl_customer.Status', '=', '1')
->where('tbl_customer.IsDeleted', '=', '0')
->orderBy('tbl_customer.id', 'desc')
->get();
return response()->json([
'status' => 200,
'Customer' => $Customer,
'Retailer' => $Retailer,
'Distributor' => $Distributor,
'WholeSeller' => $WholeSeller,
]);
// $Distributor = Customer::select('tbl_customer.*', 'tbl_customer_type.Name as CustomerType')
// ->leftJoin('tbl_customer_type', 'tbl_customer.CustomerTypeId', '=', 'tbl_customer_type.CustomerTypeId')
// ->where('tbl_customer.CustomerTypeId', '=', '4zZVseyyTqvA6n7n5Bk01RvCm30KpPQa8M8k2')
// ->where('tbl_customer.IsDeleted', '=', '0')
// ->orderBy('tbl_customer.id', 'desc')
// ->get();
// return response()->json([
// 'status' => 200,
// 'Distributor' => $Distributor,
// ]);
// $WholeSeller = Customer::select('tbl_customer.*', 'tbl_customer_type.Name as CustomerType')
// ->leftJoin('tbl_customer_type', 'tbl_customer.CustomerTypeId', '=', 'tbl_customer_type.CustomerTypeId')
// ->where('tbl_customer.CustomerTypeId', '=', 'ozbVseyyTqvA6n7n5Bk01RvCm40KpPQa8M8k3')
// ->where('tbl_customer.IsDeleted', '=', '0')
// ->orderBy('tbl_customer.id', 'desc')
// ->get();
// return response()->json([
// 'status' => 200,
// 'WholeSeller' => $WholeSeller,
// ]);
}
### Order Holder List
public function OrderHolderList() {
$OrderHolder = Order::select('tbl_order.*', 'tbl_customer.CustomerName as CustomerName'
)
->leftJoin('tbl_customer', 'tbl_customer.CustomerId', '=', 'tbl_order.CustomerId')
->where('tbl_order.Status', '=', '1')
->where('tbl_order.IsDeleted', '=', '0')
->get();
return response()->json([
'status' => 200,
'OrderHolder' => $OrderHolder,
]);
}
### Customer Type List
public function CustomerType()
{
$CustomerType = CustomerType::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'CustomerType' => $CustomerType,
]);
}
### BeatPlan List
public function BeatPlanList()
{
$BeatPlan = BeatPlan::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'BeatPlan' => $BeatPlan,
]);
}
### PaymentTerm List
public function PaymentTermList()
{
$PaymentTerm = PaymentTerm::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'PaymentTerm' => $PaymentTerm,
]);
}
### Price Book List
public function PriceList()
{
$PriceBook = PriceBook::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'PriceBook' => $PriceBook,
]);
}
### Price Book Entry List
public function PriceBookEntryList()
{
$PriceBookEntry = PriceBookEntry::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'PriceBookEntry' => $PriceBookEntry,
]);
}
### ProductFamily List
public function ProductFamilyList()
{
$ProductFamily = ProductFamily::all()
->where('Status', '=', '1');
return response()->json([
'status' => 200,
'ProductFamily' => $ProductFamily,
]);
}
### Unit List
public function UnitList()
{
$Unit = UOM::all()
->where('Status', '=', '1');
return response()->json([
'status' => 200,
'Unit' => $Unit,
]);
}
### GST List
public function GstList()
{
$GstSlab = GST::all()
->where('Status', '=', '1');
return response()->json([
'status' => 200,
'GstSlab' => $GstSlab,
]);
}
### Product List
public function ProductList()
{
$Product = Product::all()
->where('Status', '=', '1')
->where('IsDeleted', '=', '0');
return response()->json([
'status' => 200,
'Product' => $Product,
]);
}
### PaymentType List
public function PaymentType()
{
$PaymentType = PaymentType::all()
->where('Status', '=', '1');
return response()->json([
'status' => 200,
'PaymentType' => $PaymentType,
]);
}
### User List
public function UserList()
{
$UserList = User::all()
->where('Status', '=', 'Activated')
->where('isActive', '=', '1')
->where('FirstName', '!=', '');
return response()->json([
'status' => 200,
'User' => $UserList,
]);
}
### ExpenseType List
public function ExpenseTypeList()
{
$ExpenseType = ExpenseType::all()
->where('Status', '=', '1')
->where('isDeleted', '=', '0');
return response()->json([
'status' => 200,
'ExpenseType' => $ExpenseType,
]);
}
### Expense Travel Type List
public function ExpenseTypeTravelList()
{
$ExpenseTypeTravel = ExpenseTypeTravel::all()
->where('Status', '=', '1')
->where('isDeleted', '=', '0');
return response()->json([
'status' => 200,
'ExpenseTypeTravel' => $ExpenseTypeTravel,
]);
}
### User Km Rate List for expense modal
public function UserKmRateList($id)
{
$RateList = User::all()
->where('UserId', '=', $id);
// ->get()->first();
return response()->json([
'status' => 200,
'RateList' => $RateList,
]);
}
### Order List for selected customer
public function orderList($id)
{
$OrderList = Order::all()
->where('CustomerId', '=', $id);
// ->get()->first();
return response()->json([
'status' => 200,
'OrderList' => $OrderList,
]);
}
}