123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
-
- namespace App\Http\Controllers\CustomerService;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
- use App\Model\Form;
- use App\Model\Subscriber;
- use App\Model\WorkOrder;
- use App\Model\PackageDetail;
- use App\Model\Company;
-
- class CalendarController extends Controller
- {
-
- public function index()
- {
- $id = Auth::guard('cs')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $pp = count(WorkOrder::where('status','Pending Non Prelaid')->get());
- $sp = count(WorkOrder::where('status','Success Non Prelaid')->get());
- $rs = count(WorkOrder::where('status','Reschedule')->get());
- $ss = count(WorkOrder::where('status','Suspend')->get());
- $cm = count(WorkOrder::where('status','Completed')->get());
-
- $company = Company::where('team','CBB')->get();
- $today = Carbon::today();
- return view('customer-service.view_calendar', compact('user','pp','sp','rs','ss','cm', 'company','today'));
- }
-
- public function getAllCalendar(Request $request){
-
- $event = array(); $color = '';
-
- $cuw = $request->wk;
-
- if($request->customer == ''){
-
- if($request->status == '' && $request->company == ''){
-
- $wo = WorkOrder::all();
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
-
- if($w->wo == $cuw){
- $color = '#5C2983';
- }else if($w->wo != $cuw) {
- if($w->status == "Completed") {
- $color = '#00C853';
- }else if($w->status == "Suspend") {
- $color = '#DE006E';
- }else if($w->status == "Reschedule") {
- $color = '#FF6D00';
- }else if($w->status == "Success Non Prelaid"){
- $color = '#2962FF';
- }else if($w->status == "Pending Non Prelaid"){
- $color = '#FFD600';
- }else if($w->status == "Pending Contractor") {
- $color = '#6D4C41';
- }else if($w->status == "Pending Installer"){
- $color = '#546E7A';
- }
- }
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
- 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
- 'url' => url('/customer-service/work-order/generate-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
-
- }else if($request->status != '' && $request->company == ''){
-
- $wo = WorkOrder::where('status',$request->status)->get();
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
-
- if($w->wo == $cuw){
- $color = '#5C2983';
- }else if($w->wo != $cuw) {
- if($w->status == "Completed") {
- $color = '#00C853';
- }else if($w->status == "Suspend") {
- $color = '#DE006E';
- }else if($w->status == "Reschedule") {
- $color = '#FF6D00';
- }else if($w->status == "Success Non Prelaid"){
- $color = '#2962FF';
- }else if($w->status == "Pending Non Prelaid"){
- $color = '#FFD600';
- }else if($w->status == "Pending Contractor") {
- $color = '#6D4C41';
- }else if($w->status == "Pending Installer"){
- $color = '#546E7A';
- }
- }
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
- 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
- 'url' => url('/customer-service/work-order/generate-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
-
- }else if($request->status == '' && $request->company != ''){
-
- $wo = WorkOrder::where('contractor_id', $request->company)->get();
- $cuw = '';
-
- if($request->has('wk')){
- $cuw = $request->wk;
- }
-
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
-
- if($w->wo == $cuw){
- $color = '#5C2983';
- }else if($w->wo != $cuw) {
- if($w->status == "Completed") {
- $color = '#00C853';
- }else if($w->status == "Suspend") {
- $color = '#DE006E';
- }else if($w->status == "Reschedule") {
- $color = '#FF6D00';
- }else if($w->status == "Success Non Prelaid"){
- $color = '#2962FF';
- }else if($w->status == "Pending Non Prelaid"){
- $color = '#FFD600';
- }else if($w->status == "Pending Contractor") {
- $color = '#6D4C41';
- }else if($w->status == "Pending Installer"){
- $color = '#546E7A';
- }
- }
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
- 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
- 'url' => url('/customer-service/work-order/generate-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
-
- }else if($request->status != '' && $request->company != ''){
-
- $wo = WorkOrder::where('contractor_id', $request->company)->where('status',$request->status)->get();
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
-
- if($w->wo == $cuw){
- $color = '#5C2983';
- }else if($w->wo != $cuw) {
- if($w->status == "Completed") {
- $color = '#00C853';
- }else if($w->status == "Suspend") {
- $color = '#DE006E';
- }else if($w->status == "Reschedule") {
- $color = '#FF6D00';
- }else if($w->status == "Success Non Prelaid"){
- $color = '#2962FF';
- }else if($w->status == "Pending Non Prelaid"){
- $color = '#FFD600';
- }else if($w->status == "Pending Contractor") {
- $color = '#6D4C41';
- }else if($w->status == "Pending Installer"){
- $color = '#546E7A';
- }
- }
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
- 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
- 'url' => url('/customer-service/work-order/generate-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
-
- }
-
- }else if($request->customer == 'New Customer'){
-
- $form = Form::with('Subscriber','WorkOrder','PackageDetail')->get();
- $url = '';
-
- if(!empty($form)){
- foreach($form as $f){
- if(empty($f->WorkOrder)){
- if($f->type_application == 'R' && !empty($f->Subscriber->subscriber_id)){
- $color = '#582483';
- $url = '/customer-service/residential/generate-pdf/'.$f->Subscriber->subscriber_id;
- }else if($f->type_application == 'B' && !empty($f->Subscriber->subscriber_id)){
- $color = '#E07027';
- $url = '/customer-service/business/generate-pdf/'.$f->Subscriber->subscriber_id;
- }
-
- if(!empty($f->PackageDetail)){
- array_push($event, array(
- 'id' => $f->Subscriber->subscriber_id,
- 'title' => $f->Subscriber->subscriber_id,
- 'start' => Carbon::createFromTimestamp(strtotime($f->PackageDetail->rfs))->toRfc2822String(),
- 'end' => '',
- 'url' => url($url),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
- }
- }
-
- }
-
- return response()->json($event);
- }
-
- public function getCompanyColor(Request $request){
-
- $datass = array();
- $company = Company::where("_id",$request->company)->first();
-
- if(!empty($company)){
- array_push($datass, array(
- 'name' => '('.$company->name.')',
- 'bg' => $company->color,
- 'text' => '#fff'
- ));
-
- }else {
- array_push($datass, array(
- 'name' => '',
- 'bg' => '#fff',
- 'text' => '#5F5F5F'
- ));
- }
-
- return response()->json($datass);
- }
- }
|