mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
1049 lines
46 KiB
PHP
Executable File
1049 lines
46 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\PatientDiscounts\Http\Controllers;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\Drug;
|
|
use Streamline\Models\EyeGlasses;
|
|
use Streamline\Models\Investigation;
|
|
use Streamline\Models\PatientCategory;
|
|
use Streamline\Models\PriceListCategories;
|
|
use Streamline\Models\Procedure;
|
|
use Streamline\Models\Services;
|
|
use Streamline\Models\Sundry;
|
|
use Streamline\Models\MarkupTag;
|
|
use Streamline\Models\PriceListMarkupTagsChanges;
|
|
|
|
class PriceListController extends Controller {
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
*/
|
|
public function index() {
|
|
$categories = PriceListCategories::get();
|
|
$patient_categories = PatientCategory::pluck('name', 'id');
|
|
|
|
return view('patient_discounts::price_list_category.index', compact('categories', 'patient_categories'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
*/
|
|
public function create() {
|
|
$exiting_price_list = PriceListCategories::all()->pluck('patient_category_id')->toArray();
|
|
$patient_categories = PatientCategory::whereNotIn('id',$exiting_price_list)->pluck("name", "id")->toArray();
|
|
$patient_categories = ['' => '- select -'] + $patient_categories;
|
|
|
|
return view('patient_discounts::price_list_category.create', compact('patient_categories'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
*/
|
|
public function store(Request $request) {
|
|
request()->validate([
|
|
'patient_category_id' => 'required'
|
|
]);
|
|
|
|
//validation passed
|
|
$category = new PriceListCategories;
|
|
|
|
$category->patient_category_id = $request->patient_category_id;
|
|
$category->pay_for_invoice = $request->pay_for_invoice;
|
|
$category->created_by = Auth::user()->id;
|
|
|
|
try {
|
|
$category->save();
|
|
flash(" price list category has been saved")->success();
|
|
|
|
/** create entry in the items table **/
|
|
// drugs
|
|
$drugs = DB::table('drugs')->select('id')->get();
|
|
|
|
foreach ($drugs as $record){
|
|
$drug = Drug::withTrashed()->find($record->id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($drug->price_list_category) ? [] : explode(',', $drug->price_list_category);
|
|
$price_list_price = is_null($drug->price_list_price) ? [] : explode(',', $drug->price_list_price);
|
|
|
|
// add new values
|
|
$price_list_category[] = $category->id;
|
|
$price_list_price[] = $drug->non_insured_price;
|
|
|
|
$drug->price_list_category = implode(',', $price_list_category);
|
|
$drug->price_list_price = implode(',', $price_list_price);
|
|
|
|
$drug->save();
|
|
}
|
|
|
|
// investigations
|
|
$investigations = DB::table('investigations')->select('id')->get();
|
|
|
|
foreach ($investigations as $record){
|
|
$investigation = Investigation::withTrashed()->find($record->id);
|
|
// get current values
|
|
$price_list_category = is_null($investigation->price_list_category) ? [] : explode(',', $investigation->price_list_category);
|
|
$price_list_price = is_null($investigation->price_list_price) ? [] : explode(',', $investigation->price_list_price);
|
|
|
|
// add new values
|
|
$price_list_category[] = $category->id;
|
|
$price_list_price[] = $investigation->non_insured_price;
|
|
|
|
$investigation->price_list_category = implode(',', $price_list_category);
|
|
$investigation->price_list_price = implode(',', $price_list_price);
|
|
|
|
$investigation->save();
|
|
}
|
|
|
|
// procedures
|
|
$procedures = DB::table('procedures')->select('id')->get();
|
|
|
|
foreach ($procedures as $record){
|
|
$procedure = Procedure::withTrashed()->find($record->id);
|
|
// get current values
|
|
$price_list_category = is_null($procedure->price_list_category) ? [] : explode(',', $procedure->price_list_category);
|
|
$price_list_price = is_null($procedure->price_list_price) ? [] : explode(',', $procedure->price_list_price);
|
|
|
|
// add new values
|
|
$price_list_category[] = $category->id;
|
|
$price_list_price[] = $procedure->non_insured_price;
|
|
|
|
$procedure->price_list_category = implode(',', $price_list_category);
|
|
$procedure->price_list_price = implode(',', $price_list_price);
|
|
|
|
$procedure->save();
|
|
}
|
|
|
|
// services
|
|
$services = DB::table('services')->select('id')->get();
|
|
|
|
foreach ($services as $record){
|
|
$service = Services::withTrashed()->find($record->id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($service->price_list_category) ? [] : explode(',', $service->price_list_category);
|
|
$price_list_price = is_null($service->price_list_price) ? [] : explode(',', $service->price_list_price);
|
|
|
|
// add new values
|
|
$price_list_category[] = $category->id;
|
|
$price_list_price[] = $service->non_insured_price;
|
|
|
|
$service->price_list_category = implode(',', $price_list_category);
|
|
$service->price_list_price = implode(',', $price_list_price);
|
|
|
|
$service->save();
|
|
}
|
|
|
|
// sundries
|
|
$sundries = DB::table('sundries')->select('id')->get();
|
|
|
|
foreach ($sundries as $record){
|
|
$sundry = Sundry::withTrashed()->find($record->id);
|
|
// get current values
|
|
$price_list_category = is_null($sundry->price_list_category) ? [] : explode(',', $sundry->price_list_category);
|
|
$price_list_price = is_null($sundry->price_list_price) ? [] : explode(',', $sundry->price_list_price);
|
|
|
|
// add new values
|
|
$price_list_category[] = $category->id;
|
|
$price_list_price[] = $sundry->non_insured_price;
|
|
|
|
$sundry->price_list_category = implode(',', $price_list_category);
|
|
$sundry->price_list_price = implode(',', $price_list_price);
|
|
|
|
$sundry->save();
|
|
}
|
|
|
|
// eye glasses
|
|
$eye_glasses = EyeGlasses::withTrashed()->select('id')->get();
|
|
|
|
foreach ($eye_glasses as $record){
|
|
$eye_glass = EyeGlasses::withTrashed()->find($record->id);
|
|
// get current values
|
|
$price_list_category = is_null($eye_glass->price_list_category) ? [] : explode(',', $eye_glass->price_list_category);
|
|
$price_list_price = is_null($eye_glass->price_list_price) ? [] : explode(',', $eye_glass->price_list_price);
|
|
|
|
// add new values
|
|
array_push($price_list_category, $category->id);
|
|
array_push($price_list_price, $eye_glass->non_insured_price);
|
|
|
|
$eye_glass->price_list_category = implode(',', $price_list_category);
|
|
$eye_glass->price_list_price = implode(',', $price_list_price);
|
|
|
|
$eye_glass->save();
|
|
}
|
|
|
|
return redirect("/price_list_category/");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred. Please try again")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id) {
|
|
$category = PriceListCategories::find($id);
|
|
|
|
if ($category->delete()) {
|
|
flash("Price list category has been deleted.")->success();
|
|
return redirect('/price_list_category/');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the inactive resource(s).
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function inactive() {
|
|
$categories = PriceListCategories::onlyTrashed()->get();
|
|
$patient_categories = PatientCategory::pluck('name', 'id');
|
|
|
|
if (count($categories) < 1) {
|
|
flash()->error("There is no inactive price list category");
|
|
}
|
|
|
|
return view('patient_discounts::price_list_category.inactive', compact('categories', 'patient_categories'));
|
|
}
|
|
|
|
/**
|
|
* Activate the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function activate($id) {
|
|
$category = PriceListCategories::withTrashed()->find($id);
|
|
|
|
if($category->restore()){
|
|
flash("Price list category has been activated.")->success();
|
|
return redirect('/price_list_category/inactive');
|
|
}
|
|
}
|
|
|
|
public function edit_pricing($id){
|
|
return view('patient_discounts::price_list_category.edit_pricing', compact('id'));
|
|
}
|
|
|
|
public function edit_pricing_sundries(Request $request,$id){
|
|
$filtered_items=[];
|
|
$item_name = 'sundries';
|
|
$title='Sundry Name';
|
|
$route="price_list_category.edit_pricing_sundries";
|
|
$route_markups='price_list_category.apply_markup_to_sundries';
|
|
$route_submit ='price_list_category.save_edit_pricing_sundries';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = Sundry::where('available', 1)->orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = Sundry::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
|
|
$items = Sundry::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->where('available', 1)->pluck('name','id')->prepend('All Sundries', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
}
|
|
|
|
public function save_edit_pricing_sundries(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$sundry = Sundry::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($sundry->price_list_category) ? [] : explode(',', $sundry->price_list_category);
|
|
$price_list_price = is_null($sundry->price_list_price) ? [] : explode(',', $sundry->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = $price_list_price_array[$i];
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$sundry->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$sundry->price_list_price = implode(',', $price_list_price);
|
|
|
|
$sundry->save();
|
|
}
|
|
|
|
flash("Sundry price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/edit_pricing_sundries/' . $price_list_category_id);
|
|
}
|
|
|
|
public function edit_pricing_procedures(Request $request,$id){
|
|
$filtered_items=[];
|
|
$item_name = 'procedures';
|
|
$title='Procedure Name';
|
|
$route="price_list_category.edit_pricing_procedures";
|
|
$route_markups='price_list_category.apply_markup_to_procedures';
|
|
$route_submit ='price_list_category.save_edit_pricing_procedures';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = Procedure::where('available', 1)->orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = Procedure::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
|
|
$items = Procedure::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->where('available', 1)->pluck('name','id')->prepend('All procedures', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
}
|
|
|
|
public function save_edit_pricing_procedures(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$procedure = Procedure::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($procedure->price_list_category) ? [] : explode(',', $procedure->price_list_category);
|
|
$price_list_price = is_null($procedure->price_list_price) ? [] : explode(',', $procedure->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = $price_list_price_array[$i];
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$procedure->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$procedure->price_list_price = implode(',', $price_list_price);
|
|
|
|
$procedure->save();
|
|
}
|
|
|
|
flash("Procedures price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/edit_pricing_procedures/' . $price_list_category_id);
|
|
}
|
|
|
|
public function edit_pricing_investigations(Request $request,$id){
|
|
$filtered_items=[];
|
|
$item_name = 'procedures';
|
|
$title='Invesigation Name';
|
|
$route="price_list_category.edit_pricing_invesigations";
|
|
$route_markups='price_list_category.apply_markup_to_investigations';
|
|
$route_submit ='price_list_category.save_edit_pricing_investigations';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = Investigation::where('available', 1)->orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = Investigation::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
$items = Investigation::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->where('available', 1)->pluck('name','id')->prepend('All invesigation', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
}
|
|
|
|
public function save_edit_pricing_investigations(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$investigation = Investigation::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($investigation->price_list_category) ? [] : explode(',', $investigation->price_list_category);
|
|
$price_list_price = is_null($investigation->price_list_price) ? [] : explode(',', $investigation->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = $price_list_price_array[$i];
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$investigation->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$investigation->price_list_price = implode(',', $price_list_price);
|
|
|
|
$investigation->save();
|
|
}
|
|
|
|
flash("Investigation price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/edit_pricing_investigations/' . $price_list_category_id);
|
|
}
|
|
|
|
public function edit_pricing_drugs(Request $request, $id){
|
|
$filtered_items=[];
|
|
$item_name = 'drugs';
|
|
$title='Drug Name';
|
|
$route="price_list_category.edit_pricing_drugs";
|
|
$route_markups='price_list_category.apply_markup_to_drugs';
|
|
$route_submit ='price_list_category.save_edit_pricing_drugs';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = Drug::where('available', 1)->orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = Drug::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
|
|
$items = Drug::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->where('available', 1)->pluck('name','id')->prepend('All drugs', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
}
|
|
|
|
public function save_edit_pricing_drugs(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$drug = Drug::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($drug->price_list_category) ? [] : explode(',', $drug->price_list_category);
|
|
$price_list_price = is_null($drug->price_list_price) ? [] : explode(',', $drug->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = $price_list_price_array[$i];
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$drug->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$drug->price_list_price = implode(',', $price_list_price);
|
|
|
|
$drug->save();
|
|
}
|
|
|
|
flash("Drug price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/edit_pricing_drugs/' . $price_list_category_id);
|
|
}
|
|
|
|
public function edit_pricing_services(Request $request, $id){
|
|
$filtered_items=[];
|
|
$item_name = 'procedures';
|
|
$title='Service Name';
|
|
$route="price_list_category.edit_pricing_services";
|
|
$route_markups='price_list_category.apply_markup_to_services';
|
|
$route_submit ='price_list_category.save_edit_pricing_services';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = Services::where('available', 1)->orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = Services::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
$items = Services::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->where('available', 1)->pluck('name','id')->prepend('All services', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
}
|
|
|
|
public function save_edit_pricing_services(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$service = Services::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($service->price_list_category) ? [] : explode(',', $service->price_list_category);
|
|
$price_list_price = is_null($service->price_list_price) ? [] : explode(',', $service->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = $price_list_price_array[$i];
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$service->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$service->price_list_price = implode(',', $price_list_price);
|
|
|
|
$service->save();
|
|
}
|
|
|
|
flash("Services price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/edit_pricing_services/' . $price_list_category_id);
|
|
}
|
|
|
|
public function apply_markup_to_drugs(Request $request,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$drugs = json_decode($request->filtered_items);
|
|
}else{
|
|
$drugs = Drug::where('available', 1)->orderby('name', 'asc')->get();
|
|
}
|
|
|
|
return view('patient_discounts::price_list_category.apply_markup_to_drugs', compact('markup_tags','tags_select', 'drugs', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_drugs(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_drug_array = $request->checked_drug;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_drug_array as $drug_id){
|
|
$drug = Drug::find($drug_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($drug->price_list_category) ? [] : explode(',', $drug->price_list_category);
|
|
$price_list_price = is_null($drug->price_list_price) ? [] : explode(',', $drug->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $drug->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$drug->price_list_price = implode(',', $price_list_price);
|
|
|
|
$drug->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Drugs";
|
|
$update_record->item_ids = implode(",", $checked_drug_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Drugs price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function apply_markup_to_investigations(Request $request,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$investigations = json_decode($request->filtered_items);
|
|
}else{
|
|
$investigations = Investigation::where('available', 1)->orderby('name', 'asc')->get();
|
|
}
|
|
|
|
return view('patient_discounts::price_list_category.apply_markup_to_investigations', compact('markup_tags','tags_select', 'investigations', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_investigations(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_investigation_array = $request->checked_investigation;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_investigation_array as $investigation_id){
|
|
$investigation = Investigation::find($investigation_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($investigation->price_list_category) ? [] : explode(',', $investigation->price_list_category);
|
|
$price_list_price = is_null($investigation->price_list_price) ? [] : explode(',', $investigation->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $investigation->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$investigation->price_list_price = implode(',', $price_list_price);
|
|
|
|
$investigation->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Investigations";
|
|
$update_record->item_ids = implode(",", $checked_investigation_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Investigation price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function apply_markup_to_procedures(Request $request ,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$procedures = json_decode($request->filtered_items);
|
|
}else{
|
|
$procedures = Procedure::where('available', 1)->orderBy('name', 'asc')->get();
|
|
}
|
|
return view('patient_discounts::price_list_category.apply_markup_to_procedures', compact('markup_tags','tags_select', 'procedures', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_procedures(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_procedure_array = $request->checked_procedure;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_procedure_array as $procedure_id){
|
|
$procedure = Procedure::find($procedure_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($procedure->price_list_category) ? [] : explode(',', $procedure->price_list_category);
|
|
$price_list_price = is_null($procedure->price_list_price) ? [] : explode(',', $procedure->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $procedure->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$procedure->price_list_price = implode(',', $price_list_price);
|
|
|
|
$procedure->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Procedures";
|
|
$update_record->item_ids = implode(",", $checked_procedure_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Procedures price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function apply_markup_to_services(Request $request,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$services = json_decode($request->filtered_items);
|
|
}else{
|
|
$services = Services::where('available', 1)->orderby('name', 'asc')->get();
|
|
}
|
|
return view('patient_discounts::price_list_category.apply_markup_to_services', compact('markup_tags','tags_select', 'services', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_services(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_service_array = $request->checked_service;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_service_array as $service_id){
|
|
$service = Services::find($service_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($service->price_list_category) ? [] : explode(',', $service->price_list_category);
|
|
$price_list_price = is_null($service->price_list_price) ? [] : explode(',', $service->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $service->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$service->price_list_price = implode(',', $price_list_price);
|
|
|
|
$service->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Services";
|
|
$update_record->item_ids = implode(",", $checked_service_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Services price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function apply_markup_to_sundries(Request $request,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$sundries = json_decode($request->filtered_items);
|
|
}else{
|
|
$sundries = Sundry::where('available', 1)->orderby('name', 'asc')->get();
|
|
}
|
|
return view('patient_discounts::price_list_category.apply_markup_to_sundries', compact('markup_tags','tags_select', 'sundries', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_sundries(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_sundry_array = $request->checked_sundry;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_sundry_array as $sundry_id){
|
|
$sundry = Sundry::find($sundry_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($sundry->price_list_category) ? [] : explode(',', $sundry->price_list_category);
|
|
$price_list_price = is_null($sundry->price_list_price) ? [] : explode(',', $sundry->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $sundry->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$sundry->price_list_price = implode(',', $price_list_price);
|
|
|
|
$sundry->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Sundries";
|
|
$update_record->item_ids = implode(",", $checked_sundry_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Sundries price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function edit_pricing_eye_glasses(Request $request,$id){
|
|
$filtered_items=[];
|
|
$item_name = 'opticals';
|
|
$title='Name';
|
|
$route="price_list_category.edit_pricing_eye_glasses";
|
|
$route_markups='price_list_category.apply_markup_to_eye_glasses';
|
|
$route_submit ='price_list_category.save_pricing_eye_glasses';
|
|
$route_cancel='';
|
|
$item_ids_array = $request->search_items_ids;
|
|
|
|
if ($item_ids_array) {
|
|
$is_all_items = in_array("all_items", $item_ids_array);
|
|
|
|
if ($is_all_items) {
|
|
$filtered_items = EyeGlasses::orderby('name', 'asc')->get();
|
|
} else{
|
|
$filtered_items = EyeGlasses::whereIn('id', $item_ids_array)->orderBy('name', 'asc')->get();
|
|
}
|
|
}
|
|
$items = EyeGlasses::select('id', 'name', 'non_insured_price', 'price_list_category', 'price_list_price')->pluck('name','id')->prepend('All opticals', 'all_items')->toArray();
|
|
|
|
return view('patient_discounts::price_list_category.edit_pricing_list', compact('items','route_submit','route_markups','route', 'id','item_name','title','filtered_items'));
|
|
|
|
// $eye_glasses = EyeGlasses::select('id', 'name', 'non_insured_price', 'insured_price', 'price_list_category', 'price_list_price')->orderBy('name', 'asc')->get();
|
|
|
|
// return view('patient_discounts::price_list_category.edit_pricing_eye_glasses', compact('eye_glasses', 'id'));
|
|
}
|
|
|
|
public function save_pricing_eye_glasses(Request $request){
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$id_array = $request->id;
|
|
$price_list_price_array = $request->price_list_price;
|
|
|
|
for ($i = 0; $i < count($id_array); $i++){
|
|
$eye_glass = EyeGlasses::find($id_array[$i]);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($eye_glass->price_list_category) ? [] : explode(',', $eye_glass->price_list_category);
|
|
$price_list_price = is_null($eye_glass->price_list_price) ? [] : explode(',', $eye_glass->price_list_price);
|
|
|
|
// edit values
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
$price_list_price[$key] = is_numeric($price_list_price_array[$i]) ? $price_list_price_array[$i] : 0;
|
|
} else {
|
|
// the item was not found therefore add a new record for it
|
|
$price_list_category[] = $price_list_category_id;
|
|
$eye_glass->price_list_category = implode(',', $price_list_category);
|
|
$price_list_price[] = $price_list_price_array[$i];
|
|
}
|
|
|
|
$eye_glass->price_list_price = implode(',', $price_list_price);
|
|
|
|
$eye_glass->save();
|
|
}
|
|
|
|
flash("Eye Glasses price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
|
|
public function apply_markup_to_eye_glasses(Request $request,$id){
|
|
$markup_tags = MarkupTag::orderBy('name', 'asc')->get();
|
|
$tags_select = ['' => '- Select Markup -'] + MarkupTag::orderBy('name', 'asc')->pluck('name','id')->toArray();
|
|
if(isset($request->filtered_items)){
|
|
$eye_glasses = json_decode($request->filtered_items);
|
|
}else{
|
|
$eye_glasses = EyeGlasses::orderby('name', 'asc')->get();
|
|
}
|
|
return view('patient_discounts::price_list_category.apply_markup_to_eye_glasses', compact('markup_tags','tags_select', 'eye_glasses', 'id'));
|
|
}
|
|
|
|
public function save_apply_markup_to_eye_glasses(Request $request){
|
|
$markup_tag_id = $request->markup_tag;
|
|
$checked_eye_glass_array = $request->checked_eye_glass;
|
|
$price_list_category_id = $request->price_list_category_id;
|
|
$item_old_prices = [];
|
|
$item_new_prices = [];
|
|
|
|
// get markup details
|
|
$markup_tag = MarkupTag::find($markup_tag_id);
|
|
$markup_percentage = $markup_tag->percentage;
|
|
|
|
// update the prices for all the selected drugs
|
|
foreach ($checked_eye_glass_array as $eye_glass_id){
|
|
$eye_glass = EyeGlasses::find($eye_glass_id);
|
|
|
|
// get current values
|
|
$price_list_category = is_null($eye_glass->price_list_category) ? [] : explode(',', $eye_glass->price_list_category);
|
|
$price_list_price = is_null($eye_glass->price_list_price) ? [] : explode(',', $eye_glass->price_list_price);
|
|
|
|
$key = array_search($price_list_category_id, $price_list_category);
|
|
|
|
$current_price = 0;
|
|
$new_price = 0;
|
|
|
|
if (isset($price_list_price[$key]) && $key !== false){
|
|
// get the current price and update using markup
|
|
// 9th Jan 2020 Update - use the default price and not the current price of the price list
|
|
$current_price = $eye_glass->non_insured_price;
|
|
//$current_price = $price_list_price[$key];
|
|
$new_price = (($markup_percentage / 100) * $current_price) + $current_price;
|
|
$new_price = ($new_price < 0) ? 0 : $new_price;
|
|
$price_list_price[$key] = $new_price;
|
|
}
|
|
|
|
$item_old_prices[] = $current_price;
|
|
$item_new_prices[] = $new_price;
|
|
|
|
$eye_glass->price_list_price = implode(',', $price_list_price);
|
|
|
|
$eye_glass->save();
|
|
}
|
|
|
|
// create a record for this updated value
|
|
$update_record = new PriceListMarkupTagsChanges();
|
|
$update_record->price_list_category_id = $price_list_category_id;
|
|
$update_record->markup_tag_id = $markup_tag_id;
|
|
$update_record->markup_tag_percentage = $markup_percentage;
|
|
$update_record->item_type = "Eye Glasses";
|
|
$update_record->item_ids = implode(",", $checked_eye_glass_array);
|
|
$update_record->item_old_prices = implode(",", $item_old_prices);
|
|
$update_record->item_new_prices = implode(",", $item_new_prices);
|
|
$update_record->created_by = Auth::user()->id;
|
|
$update_record->save();
|
|
|
|
flash("Eye Glass price list for " . get_name(get_name($price_list_category_id, 'id', 'patient_category_id', 'price_list_categories'), 'id', 'name', 'patient_categories') . " has been updated")->success();
|
|
|
|
return redirect('/price_list_category/');
|
|
}
|
|
}
|