| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
-
- namespace App\Http\Controllers\DS;
-
- 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\PackageDetail;
- use App\Model\FormStatus;
- use App\Model\WorkOrder;
- use App\Model\Docket;
- use App\Model\Coverage;
- use App\Model\DealerClaim;
- use App\Model\Commission;
- use App\Model\Company;
-
- class SalesController extends Controller
- {
- /***
- / Application Form List
- ***/
- public function viewAppList(){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
- return view('sales.application-form-list',compact('user'));
- }
-
-
- public function gApplicationList1(){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
-
- $i = 0; $street = ''; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
- if(!empty($forms)){
- foreach ($forms as $c){
- if(empty($c->WorkOrder)){
- $i++;
-
- if($c->Subscriber->street != null){
- $street = $c->Subscriber->street;
- }
-
- $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
-
- $n1 = '';
- $reg_time = $c->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $address = ''; $name = '';
- if($c->type_application == 'R'){
- $address = $c->Subscriber->building_name;
- $name = $c->Subscriber->name;
- }else if($c->type_application == 'B'){
- $address = '-';
- $name = $c->Subscriber->company_name;
- }
-
- array_push($nested_data, array(
- 'index' => $n1.$i.$c->type_application,
- 'name' => $name,
- 'phone' => $c->Subscriber->phone1,
- 'unit' => $c->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $street,
- 'postcode' => $c->Subscriber->postcode,
- 'city' => $c->Subscriber->city,
- 'sales' => $agentName->name,
- 'action' => $c->_id
- ));
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function gApplicationList2(){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
-
- $i = 0; $street = ''; $n1 = '';
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
- if(!empty($forms)){
- foreach ($forms as $c){
- if(!empty($c->WorkOrder)){
-
- if($c->WorkOrder->status != 'Completed') {
- $i++;
-
- if($c->Subscriber->street != null){
- $street = $c->Subscriber->street;
- }
-
- $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
-
- $n1 = '';
- $reg_time = $c->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $address = ''; $name = '';
- if($c->type_application == 'R'){
- $address = $c->Subscriber->building_name;
- $name = $c->Subscriber->name;
- }else if($c->type_application == 'B'){
- $address = '-';
- $name = $c->Subscriber->company_name;
- }
-
- array_push($nested_data, array(
- 'index' => $n1.$i.$c->type_application,
- 'name' => $name,
- 'phone' => $c->Subscriber->phone1,
- 'unit' => $c->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $street,
- 'postcode' => $c->Subscriber->postcode,
- 'city' => $c->Subscriber->city,
- 'sales' => $agentName->name,
- 'action' => $c->_id
- ));
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function gApplicationList3($year, $month){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $forms = Form::with('Subscriber','PackageDetail','WorkOrder')->where('dealer_id', $user->_id)->orderBy('created_at','desc')->get();
-
- $mY = '';
- if($year != 'null' && $month != 'null'){
- $mY = $year.'-'.$month;
- }
-
- $i = 0; $street = ''; $n1 = '';
- $final = array(); $filter = array();
-
- $curr = Carbon::now()->getTimestamp();
- $nested_data = array();
- if(!empty($forms)){
- foreach ($forms as $f){
- if(!empty($f->WorkOrder)){
-
- if($f->WorkOrder->status == 'Completed') {
-
- $w = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
- if(!empty($w->Docket)){
- $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
- $i++;
-
- $address = ''; $name = '';
- if($f->type_application == 'R'){
- $address = $f->Subscriber->building_name;
- $name = $f->Subscriber->name;
- }else if($f->type_application == 'B'){
- $address = '-';
- $name = $f->Subscriber->company_name;
- }
-
- array_push($nested_data, array(
- 'index' => $i.$f->type_application,
- 'wo' => $w->wo,
- 'do' => $f->WorkOrder->docket_id,
- 'activated' => $w->Docket->end_job,
- 'name' => $name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $f->Subscriber->street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'sales' => $dealer->name,
- 'action' => $f->_id
- ));
- // }else {
- // $nested_data[] = $w;
- // }
-
-
-
- // if($mY != ''){
- // $docket = Docket::where('work_order_id', $c->WorkOrder->wo)->first();
- // $cDate = date('Y-m', strtotime($docket->end_job));
- // if($mY == $cDate){
- // $filter[] = $c->_id;
- // }
- // $filter[] = $c->_id;
- // }else {
- // }
-
- }
- }
-
- // if(!empty($filter)){
-
- // if(array_search($c->_id,$filter) !== False) {
-
- // $i++;
-
- // if($c->Subscriber->street != null){
- // $street = $c->Subscriber->street;
- // }
-
- // $agentName = StaffDetail::where('_id',$c->dealer_id)->first();
-
- // $n1 = '';
- // $reg_time = $c->created_at;
- // $expiry_date = $reg_time->addDays(3);
- // $expiry_date = $expiry_date->getTimestamp();
-
- // if($curr < $expiry_date) {
- // $n1 = "New/";
- // }
-
- // $docket = Docket::where('work_order_id',$c->WorkOrder->wo)->first();
- // array_push($nested_data, array(
- // 'index' => $n1.$i.$c->type_application,
- // 'wo' => $c->WorkOrder->wo,
- // 'do' => $docket->docket_id,
- // 'activated' => $docket->end_job,
- // 'name' => $c->Subscriber->name,
- // 'phone' => $c->Subscriber->phone1,
- // 'unit' => $c->Subscriber->unit_no,
- // 'building' => $c->Subscriber->building_name,
- // 'street' => $street,
- // 'postcode' => $c->Subscriber->postcode,
- // 'city' => $c->Subscriber->city,
- // 'sales' => $agentName->name,
- // 'action' => $c->_id
- // ));
-
- // }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /***
- / Application Form
- ***/
- public function showResidentialForm(){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- return view('sales.residential-form',compact('user'));
- }
-
- public function showBusinessForm(){
-
- $id = Auth::guard('agent')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- return view('sales.business-form',compact('user'));
- }
-
- /***
- / Form
- ***/
-
- public function getOrderHistory($id){
-
- $data = array();
- $order_history = FormStatus::where('form_id', $id)->get();
-
- foreach($order_history as $oh) {
-
- $data[] = array(
- 'date' => Carbon::parse($oh->created_at)->setTimezone('Asia/Kuala_Lumpur')->toDateTimeString(),
- 'status' => $oh->status,
- 'desc' => $oh->desc
- );
- }
-
- $json = json_encode($data);
- return $json;
- }
- }
|