Created
May 19, 2017 10:38
-
-
Save worstn8mare/cf4da68617c82044379afd2f5f7a7362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Property; | |
use App\Http\Controllers\Controller; | |
use Session; | |
use App\PropertyAssets; | |
use Response; | |
use Input; | |
use App\UnitType; | |
use App\PropertyUnit; | |
use App\AncillaryTypes; | |
use App\PropertyHeadancillary; | |
use App\PropertyDetailancillary; | |
use App\InventoriableSerial; | |
use App\InventoriableQoh; | |
use Illuminate\Http\Request; | |
use DB; | |
use App\RateType; | |
use App\UOM; | |
use App\Deskpadcurrency; | |
use App\PropertyHeaddetailancillary; | |
use App\User; | |
use App\PropertyAncillaryDetail; | |
use App\PropertyAncillaryRate; | |
use App\ContractAncillary; | |
use App\PropertyMeterReading; | |
class AncillariesController extends Controller { | |
public function view(Request $request){ | |
if(Session::has('user')){ | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$header = PropertyHeadancillary::orderBy('id','desc')->paginate(15); | |
$password = User::where('partner_id',$user_id)->first(); | |
if($request->ajax()){ | |
return view('property/ancillary/ancillary_paging',compact('user','header','password')); | |
} | |
return view('property/ancillary/ancillary',compact('user','header','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function createnew(){ | |
if(Session::has('user')){ | |
$types = RateType::where('status','Active')->get(); | |
$uoms = UOM::where('active','Y')->get(); | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$password = User::where('partner_id',$user_id)->first(); | |
return view('property/ancillary/createnewancillary',compact('types','uoms','user','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function createnewanci(Request $request){ | |
if(Session::has('user')){ | |
$anciheader = new PropertyHeadancillary; | |
$data = Input::only('name','type','ref_type'); | |
$anciheader->fill($data); | |
$anciheader->save(); | |
if($anciheader){ | |
if(Input::get('ref_type') == "Serialize"){ | |
$count = count(Input::get('serial')); | |
if($count > 0){ | |
for ($i=0; $i < $count; $i++) { | |
$detail = New PropertyAncillaryDetail; | |
$detail->headancillary_id = $anciheader->id; | |
$detail->serial = Input::get('serial')[$i]; | |
$detail->item_id = Input::get('item_id')[$i]; | |
$detail->uom_id = Input::get('uom_id')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
elseif (Input::get('ref_type') == "Reference No.") { | |
$count = count(Input::get('ref_no')); | |
if($count > 0){ | |
for ($i=0; $i < $count; $i++) { | |
$detail = New PropertyAncillaryDetail; | |
$detail->headancillary_id = $anciheader->id; | |
$detail->description = Input::get('ref_desc')[$i]; | |
$detail->ref_no = Input::get('ref_no')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
else{ | |
// None selected no more details | |
} | |
} | |
Session::flash('alert-success','Ancillary successfully added.'); | |
return redirect()->action('Property\AncillariesController@profile',['id' => $anciheader->id]); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function updateprofile($id){ | |
if(Session::has('user')){ | |
if(Input::get('update')){ | |
$anciheader = PropertyHeadancillary::where('id',$id)->first(); | |
$data = Input::only('name','type','ref_type'); | |
$anciheader->fill($data); | |
$anciheader->save(); | |
if($anciheader){ | |
if(count(Input::get('status_old')) > 0){ | |
for ($i=0; $i < count(Input::get('status_old')); $i++) { | |
PropertyAncillaryDetail::where('id',Input::get('status_old')[$i])->delete(); | |
} | |
} | |
if(Input::get('ref_type') == "Serialize"){ | |
$count = count(Input::get('serial')); | |
if($count > 0){ | |
for ($i=0; $i < $count; $i++) { | |
$detail = New PropertyAncillaryDetail; | |
$detail->headancillary_id = $anciheader->id; | |
$detail->serial = Input::get('serial')[$i]; | |
$detail->item_id = Input::get('item_id')[$i]; | |
$detail->uom_id = Input::get('uom_id')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
elseif (Input::get('ref_type') == "Reference No.") { | |
$count = count(Input::get('ref_no')); | |
if($count > 0){ | |
for ($i=0; $i < $count; $i++) { | |
$detail = New PropertyAncillaryDetail; | |
$detail->headancillary_id = $anciheader->id; | |
$detail->description = Input::get('ref_desc')[$i]; | |
$detail->ref_no = Input::get('ref_no')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
else{ | |
// None selected, no more details | |
} | |
} | |
Session::flash('alert-success','Ancillary successfully updated.'); | |
return redirect()->action('Property\AncillariesController@profile',['id' => $anciheader->id]); | |
} | |
else if(Input::get('reading-update')){ | |
for ($i=0; $i < count(Input::get('ref_id')) ; $i++) { | |
$read = New PropertyMeterReading; | |
$read->ref_id = Input::get('ref_id')[$i]; | |
$read->date = date('Y-m-d',strtotime(Input::get('reading-date'))); | |
$read->reading = Input::get('reading')[$i]; | |
$read->save(); | |
} | |
Session::flash('alert-success','Meter Reading successfully updated.'); | |
return redirect()->action('Property\AncillariesController@profile',['id' => $id]); | |
} | |
} | |
else | |
{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function profile($id){ | |
if(Session::has('user')){ | |
$head = PropertyHeadancillary::where('id',$id)->first(); | |
$detail = PropertyAncillaryDetail::where('headancillary_id',$id)->with('getchecker')->get(); | |
$types = RateType::all(); | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$password = User::where('partner_id',$user_id)->first(); | |
return view('property/ancillary/ancillaryprofile',compact('head','detail','types','user','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function profilerates(Request $request,$id){ | |
if(Session::has('user')){ | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$head = PropertyHeadancillary::where('id',$id)->first(); | |
$header_rate = PropertyHeaddetailancillary::where('headancillary_id',$id)->paginate(15); | |
$password = User::where('partner_id',$user_id)->first(); | |
if($request->ajax()){ | |
return view('property/ancillary/ancillaryrate_paging',compact('header_rate','user','id','head','password')); | |
} | |
return view('property/ancillary/ancillaryrate',compact('header_rate','user','id','head','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function createrate($id){ | |
if(Session::has('user')){ | |
$head = PropertyHeadancillary::where('id',$id)->first(); | |
$currency = Deskpadcurrency::where('status','Active')->get(); | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$password = User::where('partner_id',$user_id)->first(); | |
return view('property/ancillary/createnewancillaryrate',compact('head','currency','user','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function insertnewrate(Request $request,$id){ | |
if(Session::has('user')){ | |
$head = New PropertyHeaddetailancillary; | |
$head->headancillary_id = $id; | |
$head->rate_currency = Input::get('currency_id'); | |
$head->status = Input::get('status'); | |
$head->save(); | |
if($head){ | |
$count = count(Input::get('rate')); | |
for ($i=0; $i < $count; $i++) { | |
$gdate = date('Y-m-d',strtotime(Input::get('effective_date')[$i])); | |
if(Input::get('substatus')[$i] == "Yes"){ | |
$contract_anci = ContractAncillary::where('ancillary_id',$head->headancillary_id) | |
->where('start_date','<=',$gdate)->where('end_date','>=',$gdate)->get(); | |
foreach ($contract_anci as $ancis) { | |
$date=date_create($gdate); | |
date_sub($date,date_interval_create_from_date_string("1 day")); | |
$newdate = date_format($date,"Y-m-d"); | |
$anci_update = ContractAncillary::where('id',$ancis->id)->update(['end_date'=>$newdate]); | |
if($anci_update){ | |
$add_anci = New ContractAncillary; | |
$add_anci->contract_id = $ancis->contract_id; | |
$add_anci->ancillary_id = $ancis->ancillary_id; | |
$add_anci->rate = Input::get('rate')[$i]; | |
$add_anci->rate_type = $ancis->rate_type; | |
$add_anci->start_date = $gdate; | |
$add_anci->end_date = $ancis->end_date; | |
$add_anci->reference = $ancis->reference; | |
$add_anci->save(); | |
} | |
} | |
} | |
if(Input::get('ref_rate') == "bogart"){ | |
$detail = New PropertyAncillaryRate; | |
$detail->headancillary_id = $id; | |
$detail->headdetail_id = $head->id; | |
$detail->effective_date = $gdate; | |
$detail->daily_rate = Input::get('rate')[$i]; | |
$detail->monthly_rate = Input::get('rate2')[$i]; | |
$detail->status = Input::get('substatus')[$i]; | |
$detail->save(); | |
} | |
else{ | |
$detail = New PropertyAncillaryRate; | |
$detail->headancillary_id = $id; | |
$detail->headdetail_id = $head->id; | |
$detail->effective_date = $gdate; | |
$detail->rate = Input::get('rate')[$i]; | |
$detail->status = Input::get('substatus')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
Session::flash('alert-success','Rate successfully saved.'); | |
return redirect()->action('Property\AncillariesController@profileratesdetails',['id' => $id,'rate_id' => $head->id]); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function updateprofileratesdetails($id,$rate_id){ | |
if(Session::has('user')){ | |
$head = PropertyHeaddetailancillary::where('id',$rate_id)->first(); | |
$head->headancillary_id = $id; | |
$head->rate_currency = Input::get('currency_id'); | |
$head->status = Input::get('status'); | |
$head->save(); | |
if($head){ | |
// PropertyAncillaryRate::where('headdetail_id',$rate_id)->delete(); | |
$count = count(Input::get('rate')); | |
for ($i=0; $i < $count; $i++) { | |
$gdate = date('Y-m-d',strtotime(Input::get('effective_date')[$i])); | |
if(Input::get('substatus')[$i] == "Yes"){ | |
$contract_anci = ContractAncillary::where('ancillary_id',$head->headancillary_id) | |
->where('start_date','<=',$gdate)->where('end_date','>=',$gdate)->get(); | |
foreach ($contract_anci as $ancis) { | |
$date=date_create($gdate); | |
date_sub($date,date_interval_create_from_date_string("1 day")); | |
$newdate = date_format($date,"Y-m-d"); | |
$anci_update = ContractAncillary::where('id',$ancis->id)->update(['end_date'=>$newdate]); | |
if($anci_update){ | |
$add_anci = New ContractAncillary; | |
$add_anci->contract_id = $ancis->contract_id; | |
$add_anci->ancillary_id = $ancis->ancillary_id; | |
$add_anci->rate = Input::get('rate')[$i]; | |
$add_anci->rate_type = $ancis->rate_type; | |
$add_anci->start_date = $gdate; | |
$add_anci->end_date = $ancis->end_date; | |
$add_anci->reference = $ancis->reference; | |
$add_anci->save(); | |
} | |
} | |
} | |
if(Input::get('ref_rate') == "bogart"){ | |
$detail = New PropertyAncillaryRate; | |
$detail->headancillary_id = $id; | |
$detail->headdetail_id = $head->id; | |
$detail->effective_date = $gdate; | |
$detail->daily_rate = Input::get('rate')[$i]; | |
$detail->monthly_rate = Input::get('rate2')[$i]; | |
$detail->status = Input::get('substatus')[$i]; | |
$detail->save(); | |
} | |
else{ | |
$detail = New PropertyAncillaryRate; | |
$detail->headancillary_id = $id; | |
$detail->headdetail_id = $head->id; | |
$detail->effective_date = date('Y-m-d',strtotime(Input::get('effective_date')[$i])); | |
$detail->rate = Input::get('rate')[$i]; | |
$detail->status = Input::get('substatus')[$i]; | |
$detail->save(); | |
} | |
} | |
} | |
Session::flash('alert-success','Rate successfully updated.'); | |
return redirect()->action('Property\AncillariesController@profileratesdetails',['id' => $id,'rate_id' => $head->id]); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function profileratesdetails($id,$rate_id){ | |
if(Session::has('user')){ | |
$head = PropertyHeadancillary::where('id',$id)->first(); | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$currency = Deskpadcurrency::where('status','Active')->get(); | |
$header = PropertyHeaddetailancillary::where('id',$rate_id)->first(); | |
$detail = PropertyAncillaryRate::where('headdetail_id',$rate_id)->get(); | |
$latest_date = PropertyAncillaryRate::where('headdetail_id',$rate_id)->orderBy('effective_date','desc')->first(); | |
$password = User::where('partner_id',$user_id)->first(); | |
return view('property/ancillary/createnewancillaryrate',compact('password','head','user','header','detail','currency','latest_date')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
//-----api-- | |
public function anserials(){ | |
$serial = Input::get('serial'); | |
$item_id = Input::get('item_id'); | |
$anserialsvalidate = PropertyDetailancillary::where('item_id',$item_id)->where('serial',$serial)->first(); | |
return Response::json($anserialsvalidate, 200, array(), JSON_PRETTY_PRINT); | |
} | |
public function getReading(Request $request){ | |
$getdetail = PropertyAncillaryDetail::where('headancillary_id',Input::get('id'))->get(); | |
return view('property/ancillary/reading_meter',compact('getdetail')); | |
} | |
public function currency_checker(){ | |
$id = Input::get('id'); | |
$currency_check = PropertyHeaddetailancillary::where('rate_currency',$id) | |
->where('headancillary_id',Input::get('ref_id'))->count(); | |
return Response::json($currency_check, 200, array(), JSON_PRETTY_PRINT); | |
} | |
public function get_ancillaryserials(){ | |
$serial = InventoriableSerial::where('item_id', Input::get('item_id')) | |
->where('serial', Input::get('serial')) | |
//->where('status', 'in') | |
->with('items') | |
->first(); | |
return Response::json($serial, 200, array(), JSON_PRETTY_PRINT); | |
} | |
public function nameList(){ | |
$name = Input::get('name'); | |
$nameList = PropertyHeadancillary::where('name', 'like', '%'.$name.'%') | |
->get(); | |
return Response::json($nameList, 200, array(), JSON_PRETTY_PRINT); | |
} | |
public function ancillaries_search(Request $request){ | |
if(Session::has('user')){ | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$ancillary_id = Input::get('ancillary_id'); | |
$ancillary_name = Input::get('ancillary_name'); | |
$ancillary_rate = Input::get('ancillary_rate'); | |
$ancillary_reference = Input::get('ancillary_reference'); | |
$header = PropertyHeadancillary::orderBy('id','desc'); | |
$password = User::where('partner_id',$user_id)->first(); | |
if(!$ancillary_id){ | |
if($ancillary_name){ | |
$header->where('property_headancillaries.name','like','%'.$ancillary_name.'%'); | |
} | |
if($ancillary_rate){ | |
$header->where('property_headancillaries.type',$ancillary_rate); | |
} | |
if($ancillary_reference){ | |
$header->where('ref_type',$ancillary_reference); | |
} | |
} | |
else{ | |
$header->where('property_headancillaries.id',$ancillary_id); | |
} | |
$header = $header->paginate(15); | |
if($request->ajax()){ | |
return view('property/ancillary/ancillary_paging',compact('user','header','password')); | |
} | |
return view('property/ancillary/ancillary_search',compact('user','header','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
public function ancillaries_rate_search(Request $request, $id ){ | |
if(Session::has('user')){ | |
$user_id = Session::get('user'); | |
$user = User::where('partner_id',$user_id)->first(); | |
$head = PropertyHeadancillary::where('id',$id)->first(); | |
$rate_id = Input::get('rate_id'); | |
$rate_currency = Input::get('rate_currency'); | |
$rate_status = Input::get('rate_status'); | |
$header = PropertyHeaddetailancillary::where('headancillary_id',$id); | |
if(!$rate_id){ | |
if($rate_currency){ | |
$header->where('rate_currency',$rate_currency); | |
} | |
if($rate_status){ | |
$header->where('status',$rate_status); | |
} | |
} | |
else{ | |
$header->where('id',$rate_id); | |
} | |
$header_rate =$header ->paginate(15); | |
$password = User::where('partner_id',$user_id)->first(); | |
if($request->ajax()){ | |
return view('property/ancillary/ancillaryrate_paging',compact('header_rate','user','id','head','password')); | |
} | |
return view('property/ancillary/ancillary_rate_search',compact('header_rate','user','id','head','password')); | |
} | |
else{ | |
return redirect()->action('Auth@checklogin'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment