| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\v3\Api\BaseController;
-
- use File;
- use Carbon\Carbon;
-
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\FormStatus;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\Docket;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
-
- use App\Mail\AssignWorkOrder2;
- use App\Mail\CustomerBInvoice2;
- use App\Mail\CustomerInvoice2;
-
- use App\Jobs\SendWorkOrder2;
- use App\Jobs\SendCustomerInvoiceB2;
- use App\Jobs\SendCustomerInvoice2;
-
- class CalendarController extends BaseController
- {
-
- /**
- * Create calendar work order controller.
- *
- * @return json
- */
- public function getCalendarWorkOrder(Request $request){
-
- if($request->customer == ''){
-
- if($request->status == '' && $request->company == ''){
- $wo = WorkOrder::all();
- }else if($request->status != '' && $request->company == ''){
- $wo = WorkOrder::where('status',$request->status)->get();
- }else if($request->status == '' && $request->company != ''){
- $wo = WorkOrder::where('contractor_id', $request->company)->get();
- }else if($request->status != '' && $request->company != ''){
- $wo = WorkOrder::where('contractor_id', $request->company)->where('status',$request->status)->get();
- }
-
- return $wo;
- }else{
-
- $form = Form::with('Subscriber','WorkOrder','PackageDetail')->get();
- return $form;
- }
- }
-
- /**
- * Create display calendar work order controller.
- *
- * @return json
- */
- public function viewCalendarData(Request $request){
-
- $event = array(); $color = '';
-
- if($request->customer == ''){
- $current_work_order = $request->current_work_order;
- $wo = $this->getCalendarWorkOrder($request);
-
- if(!empty($wo)){
- foreach ($wo as $key => $w) {
- if($w->wo == $current_work_order){
- $color = '#5C2983';
- }else if($w->wo != $current_work_order) {
- 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';
- }
- }
-
- if(!empty($w->dateTimeStart) || $w->dateTimeStart != ''){
-
- // $start = Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String();
- // $end = Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String();
-
- $start = $w->dateTimeStart;
- $end = $w->dateTimeEnd;
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => $start,
- 'end' => $end,
- 'url' => url('/v3/main/work-order-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
- }
- }else{
- $url = '';
- $form = Form::with('Subscriber','WorkOrder','PackageDetail')->get();
- if(!empty($form)){
- foreach($form as $f){
- if(empty($f->WorkOrder) && !empty($f->Subscriber) && !empty($f->PackageDetail)){
- if($f->type_application == 'R' && !empty($f->Subscriber->subscriber_id)){
- $color = '#582483';
- $url = '/v3/main/residential/generate-pdf/'.$f->Subscriber->subscriber_id;
- }else if($f->type_application == 'B' && !empty($f->Subscriber->subscriber_id)){
- $color = '#E07027';
- $url = '/v3/main/business/generate-pdf/'.$f->Subscriber->subscriber_id;
- }
-
- if(!empty($f->PackageDetail->rfs)) {
- $dateStart = Carbon::createFromTimestamp(strtotime($f->PackageDetail->rfs))->toRfc2822String();
- // $dateStart = $f->PackageDetail->rfs;
-
- array_push($event, array(
- 'id' => $f->Subscriber->subscriber_id,
- 'title' => $f->Subscriber->subscriber_id,
- 'start' => $dateStart,
- 'end' => '',
- 'url' => url($url),
- 'color' => $color,
- 'allDay' => false
- ));
- }
- }
- }
- }
- }
-
- return response()->json($event);
- }
-
- /**
- * Create display company color controller.
- *
- * @return json
- */
- public function displayCalendarContractorInstaller(Request $request){
-
- $event = array(); $color = ''; $cuw = '';
- if($request->has('current_work_order')){
- $cuw = $request->current_work_order;
- }
-
- if($request->status == '' && $request->installer == ''){
- $wo = WorkOrder::where('contractor_id', $request->company)->get();
- }else if($request->status != '' && $request->installer == ''){
- $wo = WorkOrder::where('status',$request->status)->where('contractor_id', $request->company)->get();
- }else if($request->status == '' && $request->installer != ''){
- $wo = WorkOrder::where('contractor_id', $request->company)->where('installer_id', $request->installer)->get();
- }else if($request->status != '' && $request->installer != ''){
- $wo = WorkOrder::where('contractor_id', $request->company)->where('installer_id', $request->installer)->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';
- }
- }
-
- if(!empty($w->dateTimeStart) || $w->dateTimeStart != ''){
-
- // $start = Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String();
- // $end = Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String();
-
- $start = $w->dateTimeStart;
- $end = $w->dateTimeEnd;
-
- array_push($event, array(
- 'id' => $w->wo,
- 'title' => $w->wo,
- 'start' => $start,
- 'end' => $end,
- 'url' => url('/customer-service/work-order/generate-pdf/'.$w->wo),
- 'color' => $color,
- 'allDay' => false
- ));
- }
-
- }
- }
- return response()->json($event);
- }
-
- /**
- * Create display company color controller.
- *
- * @return json
- */
- public function getCompanyColor(Request $request){
-
- $data = array();
- $company = Company::where("_id",$request->company)->first();
-
- if(!empty($company)){
- array_push($data, array(
- 'name' => '('.$company->name.')',
- 'bg' => $company->color,
- 'text' => '#fff'
- ));
-
- }else {
- array_push($data, array(
- 'name' => '',
- 'bg' => '#448aff',
- 'text' => '#fff'
- ));
- }
-
- return response()->json($data);
- }
-
- /**
- * Create add new work order to calendar controller.
- *
- * @return json
- */
- public function addWorkOrderSchedule(Request $request){
-
- $subscriber = Subscriber::where('subscriber_id',$request->subscriber_id)->first();
- if(!empty($subscriber)){
- $form = Form::with('Subscriber','PackageDetail','WorkOrder')->where('_id', $subscriber->_id)->first();
- if(!empty($form)){
- if(!empty($form->Subscriber) && !empty($form->PackageDetail)){
- $exiting_work_order = WorkOrder::where('wo',$request->wo)->first();
- if(empty($exiting_work_order)){
-
- if($request->status == 'work-order-non-prelaid'){
- $status = 'Pending Non Prelaid';
- }else {
- $status = 'Pending Contractor';
- }
-
- $work_order = new WorkOrder;
- $work_order->img_url = '/assets/img/activation_icon_nRead1.png';
- $work_order->wo = $request->wo;
- $work_order->nature_work = '';
- $work_order->sub_category = '';
- $work_order->dateTimeStart = $request->start;
- $work_order->dateTimeEnd = $request->end;
- $work_order->contractor_id = $request->vendor;
- $work_order->installer_id = '';
- $work_order->onu = '';
- $work_order->router = '';
- $work_order->need_phone = '';
- $work_order->no_phone = '';
- $work_order->pppoe_username = '';
- $work_order->pppoe_password = '';
- $work_order->docket_id = '';
- $work_order->remarks_custservice = '';
- $work_order->remarks_installer = '';
- $work_order->status = $status;
- $work_order->created_by = $request->created_by;
-
- $form->workorder()->save($work_order);
-
- return $this->sendResponse($work_order, 'The work order has been successfully added to calendar');
-
- }else{
-
- $exiting_work_order->dateTimeStart = $request->start;
- $exiting_work_order->dateTimeEnd = $request->end;
- $exiting_work_order->contractor_id = $request->vendor;
- $exiting_work_order->save();
-
- return $this->sendResponse($exiting_work_order, 'Successfully update dateTime work order');
- }
- }else {
- return $this->sendError('Form not completed!', '');
- }
- }else {
- return $this->sendError('Form not exist!', '');
- }
- }else{
- return $this->sendError('Subscriber id cant be found!', '');
- }
- }
-
- /**
- * Create reschedule work order controller.
- *
- * @return json
- */
- public function updateWorkOrderReschedule(Request $request){
- $exiting_work_order = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($exiting_work_order)){
-
- $exiting_work_order->dateTimeStart = $request->start;
- $exiting_work_order->dateTimeEnd = $request->end;
- $exiting_work_order->contractor_id = $request->vendor;
- $exiting_work_order->status = 'Pending Contractor';
- $exiting_work_order->save();
-
- return $this->sendResponse($exiting_work_order, 'Successfully update dateTime work order');
- }else{
- return $this->sendError('Work order id cant be found!', '');
- }
- }
-
- /**
- * Create send work order to contractor by email controller.
- *
- * @return
- */
- public function sendWorkOrdersByEmail($work_order_id) {
-
- $work_order = WorkOrder::where('wo',$work_order_id)->first();
- $s = StaffDetail::where('company_id',$work_order->contractor_id)->where('position','Contractor')->get();
- $customer = Subscriber::where('_id',$work_order->_id)->first();
- if($work_order->contractor_id == '5b42b935ee0dc2b707473b76'){
- $company = Company::where('_id',$work_order->contractor_id)->first();
- $staff = StaffDetail::where('company_id',$work_order->contractor_id)->where('email','mimi@jitech.com.my')->first();
- SendWorkOrder2::dispatch($work_order,$staff,'cbbinstallation@jitech.com.my',$customer,$company);
- }else {
- $company = Company::where('_id',$work_order->contractor_id)->first();
- foreach($s as $staff){
- SendWorkOrder2::dispatch($work_order,$staff,$staff->email,$customer,$company);
- }
- }
- }
-
- /**
- * Create confirm reschedule work order and add status controller.
- *
- * @return json
- */
- public function addHistoryworkOrderReschedule(Request $request){
- $exiting_work_order = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($exiting_work_order)){
- $form = Form::where('_id',$exiting_work_order->_id)->first();
- $contractor = Company::where('_id',$exiting_work_order->contractor_id)->first();
-
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 4;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $formH->status = 'Pending Contractor';
- $formH->desc = 'This work order been reassigned to particular contractor ('.$contractor->name.')';
- $form->formstatus()->save($formH);
-
- $this->sendWorkOrdersByEmail($request->wo);
-
- return $this->sendResponse($exiting_work_order, 'Successfully update dateTime work order');
- }
- else{
- return $this->sendError('Work order id cant be found!', '');
- }
- }
-
- /**
- * Create remove new work order from calendar controller.
- *
- * @return json
- */
- public function removeWorkOrderSchedule(Request $request){
- $exiting_work_order = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($exiting_work_order)){
- $exiting_work_order->delete();
- return $this->sendResponse($exiting_work_order, 'Successfully remove work order from calendar. You will be redirected to Customer Application Form');
- }else {
- return $this->sendError('Work order cant be found!', '');
- }
- }
-
- /**
- * Create check if new work order already been added to calendar controller.
- *
- * @return json
- */
- public function checkWorkOrderSchedule(Request $request){
- $exiting_work_order = WorkOrder::where('wo',$request->wo)->first();
- if(!empty($exiting_work_order)){
- return $this->sendResponse($exiting_work_order, '');
- }else {
- return $this->sendError('Please choose datetime for current work order!', '');
- }
- }
-
- /**
- * Create assign installer to calendar controller.
- *
- * @return json
- */
- public function assignInstaller(Request $request){
- $wod = WorkOrder::where('wo', $request->wo)->first();
- if(!empty($wod)){
- $wod->dateTimeStart = $request->start;
- $wod->dateTimeEnd = $request->end;
- $wod->installer_id = $request->installer;
- $wod->status = $request->type_work;
- $wod->save();
-
- return $this->sendResponse($wod, 'Successfully assign/reassign installer');
- }else{
- return $this->sendError('Work order id cant be found!', '');
- }
- }
-
-
- public function confirmAssignInstaller(Request $request)
- {
- $data = array();
- $wod = WorkOrder::where('wo',$request->wo)->first();
- $form = Form::where('_id',$wod->_id)->first();
- $installer = Staff::with('StaffDetail')->where('_id',$request->installer)->first();
-
- if(!empty($wod) && !empty($installer)){
-
- if($wod->status == 'Pending Contractor'){
-
- $wod->status = $request->type_work;
- $wod->installer_id = $request->installer;
- $wod->save();
-
- $formH = new FormStatus;
- $formH->form_id = $form->_id;
- $formH->status_id = 6;
- $formH->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $formH->status = 'Pending Installer';
- $formH->desc = 'This work order been assigned to particular installer ('.$installer->name.')';
- $form->formstatus()->save($formH);
-
- $date = date('d/m/Y H:i', strtotime($wod->dateTimeStart));
- $response = $this->sendsmscustomer($wod->_id,$installer->StaffDetail->name,$installer->StaffDetail->phone,$wod->wo,$date);
- return $this->sendResponse($response, 'Successfully confirm assign/reassign installer');
-
- }else {
-
- $wod->status = $request->type_work;
- $wod->installer_id = $request->installer;
- $wod->save();
-
- return $this->sendResponse($wod, 'Successfully confirm assign/reassign installer');
- }
-
- }else{
- return $this->sendError('Work order / installer id cant be found!', '');
- }
- }
-
- /**
- * Create send sms to customer controller.
- *
- * @return post
- */
- function xmlToJson($xml_string) {
- $xml = simplexml_load_string($xml_string);
- $json = json_encode($xml);
- $array = json_decode($json,TRUE);
- return $array;
- }
-
- public function sendsmscustomer($form_id,$installer_name,$installer_num,$wo,$dateTime){
-
- $form = Form::with('Subscriber')->where('_id', $form_id)->first();
- if(!empty($form)){
- $number = preg_replace('/[^0-9]/','',$form->Subscriber->phone1);
- if($number[0] == '6'){
- $number = $number;
- }else{
- $number = '6'.$number;
- }
-
- $message = 'Greeting from swisslink.com.my%0a%0aYour application has been approved.Below are the detail for your installation%0a%0aService Installer : '.$installer_name.'%0aContact No : '.$installer_num.'%0aOrder Ref No : '.$wo.'%0aAppointment : '.$dateTime.'%0a%0aFor more information,please contact 1300-38 8000';
-
- $client = new \GuzzleHttp\Client();
- $request = $client->get('https://www.klasiksms.com/api/sendsms.php?email='.$form->Subscriber->email.'+&key=c2f3ed403e30ca9a0c96a2eaa794133f&recipient='.$number.'&message='.$message);
- $response = $this->xmlToJson($request->getBody()->getContents());
-
- return $response;
- }
- }
-
- /**
- * Create display dealer from slot controller.
- *
- * @return json
- */
- public function viewDealerSlotForm(Request $request){
-
- $event = array(); $color = '';
-
- $start = date('Y-m-d', strtotime($request->startdate));
- $start = $start. ' 10:00:00';
- $end = date('Y-m-d', strtotime($request->enddate));
- $end = $end. ' 16:00:00';
-
- $package = PackageDetail::with('Subscriber','Form')->whereBetween('rfs',array($start, $end))->get();
-
- // $form = Form::with(['PackageDetail' => function($q) use($start,$end){
- // $q->where('rfs',array($start, $end));
- // }],'Subscriber')->where('type_service','!=','Rectification')->get();
- // dd($package);
-
- if(!empty($package)){
- foreach ($package as $key => $f) {
- if(!empty($f->Subscriber) && !empty($f->Form)){
-
- if($f->Subscriber->subscriber_id == $request->subscriber_id){
- $color = '#5C2983';
- }else {
- $color = '#333';
- }
- // if($f->type_application == 'R'){
- // $pdf = '/v3/dealer/residential/generate-pdf/'.$f->Subscriber->subscriber_id;
- // }else if($f->type_application == 'B'){
- // $pdf = '/v3/dealer/business/generate-pdf/'.$f->Subscriber->subscriber_id;
- // }
-
-
- array_push($event, array(
- 'id' => $f->Subscriber->subscriber_id,
- 'title' => $f->Subscriber->subscriber_id,
- 'start' => $f->rfs,
- 'url' => '',
- 'color' => $color,
- 'allDay' => false
- ));
-
- }
- }
- }
-
- return response()->json($event);
- }
-
- public function limitEventPerslot($start){
- $total_per_slot = count($form = PackageDetail::where('rfs',$start)->get());
- return response()->json($total_per_slot);
- }
-
- function random_code($limit) {
- return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
- }
-
- public function bookDealerForm(Request $request){
-
- // staff
- $staff = Staff::with('StaffDetail')->where('_id',$request->dealer_id)->first();
- if(!empty($staff)){
-
- $subscriber = Subscriber::where('subscriber_id', $request->subscriber_id)->first();
- if(empty($subscriber)){
-
- do {
- $su_id = strtoupper('CBB-'.$this->random_code(6).$request->type_application);
- } while (Subscriber::where("subscriber_id", "=", $su_id)->first() instanceof Subscriber);
-
- $sl = new Form();
- $sl->type_service = '';
- $sl->type_application = $request->type_application;
- $sl->status_payment = 'paid';
- $sl->status_email = 'unverified';
- $sl->remark_form = '';
- $sl->dealer_id = $request->dealer_id;
- $sl->company_id = $staff->StaffDetail->company_id;
- $sl->status_form = 'Draft';
-
- $staff->form()->save($sl);
-
- $packageD = new PackageDetail();
- $packageD->contract = '';
- $packageD->name = '';
- $packageD->montly_fee = '';
- $packageD->voice_fee = '';
- $packageD->deposit = '';
- $packageD->upfront_payment = '';
- $packageD->rfs = $request->start;
- $sl->packagedetail()->save($packageD);
-
- if($request->type_application == 'R') {
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = '';
- $sdl->ic = '';
- $sdl->citizen = '';
- $sdl->gender = '';
- $sdl->race = '';
- $sdl->email = '';
- $sdl->phone1 = '';
- $sdl->phone2 = '';
- $sdl->unit_no = '';
- $sdl->building_name = '';
- $sdl->street = '';
- $sdl->postcode = '';
- $sdl->city = '';
- $sdl->state = '';
- $sdl->front_ic = '';
- $sdl->back_ic = '';
- $sdl->visaF = '';
- $sdl->visaB = '';
- $sdl->signature = '';
- $sl->subscriber()->save($sdl);
-
- return $this->sendResponse($sl->_id, 'The rfs date already been book in calendar');
-
- }else if($request->type_application == 'B'){
-
- $sdl = new Subscriber();
- $sdl->subscriber_id = $su_id;
- $sdl->name = '';
- $sdl->ic = '';
- $sdl->company_name = '';
- $sdl->company_reg = '';
- $sdl->company_num = '';
- $sdl->company_fax = '';
- $sdl->designation = '';
- $sdl->email = '';
- $sdl->phone1 = '';
- $sdl->phone2 = '';
- $sdl->unit_no = '';
- $sdl->street = '';
- $sdl->postcode = '';
- $sdl->city = '';
- $sdl->state = '';
- $sdl->front_ic = '';
- $sdl->back_ic = '';
- $sdl->form24_49 = '';
- $sdl->form9_44 = '';
- $sdl->visaF = '';
- $sdl->visaB = '';
- $sl->subscriber()->save($sdl);
-
- return $this->sendResponse($sl->_id, 'The rfs date already been book in calendar');
- }
-
- }else{
- $form = Form::with('PackageDetail')->where('_id', $subscriber->_id)->first();
-
- $form->PackageDetail->rfs = $request->start;
- $form->PackageDetail->save();
-
- return $this->sendResponse($request->subscriber_id, 'The rfs date success been updated');
- }
- }else{
- return $this->sendError('Dealer id not found', '');
- }
- }
-
- public function updateFormDealer(Request $request){
-
- $form = Form::with('PackageDetail','Subscriber')->where('_id', $request->form_id)->first();
- if(!empty($form)){
- if(!empty($form->Subscriber) && !empty($form->PackageDetail)){
-
- $destinationPath = 'document/'.$form->Subscriber->subscriber_id;
- $uploaded = public_path().'/'.$destinationPath;
-
- // create folder/dir if not exist
- if(!File::exists(public_path().'/'.$destinationPath)){
- File::makeDirectory(public_path().'/'.$destinationPath,0777,true);
- }
-
- $voice = "No"; $saveR = false; $saveB = false;
- if($request->has('voice')){ $voice = $request->voice; }
-
- $otc = 0.0; $deposit = 0.0; $gst = 0; $total = 0;
- $product = Product::where('formT', $form->type_application)->where('package_name',$request->package)->first();
-
- $form->type_service = $request->application;
- $form->save();
-
- if($form->type_application == 'R') {
- if($request->citizenship != 'Malaysian'){
- $deposit = $product->deposit;
- }else{
- $deposit = $product->deposit;
- }
-
- if($request->subscription == '24'){
- $otc = 0.0;
- }else {
- $otc = 300 * 1.06;
- }
-
- if($product->promotion_price != '0' && $request->subscription == '24'){
- $gst = number_format(floatval($product->promotion_price) * 1.06,2);
- $total = number_format((floatval($product->promotion_price) * 1.06) + $otc + $deposit, 2);
- }else if($product->promotion_price == '0'){
- $gst = number_format(floatval($product->retail_price) * 1.06,2);
- $total = number_format((floatval($product->retail_price) * 1.06) + $otc + $deposit, 2);
- }
-
- // Signature
- $signature_form = $request->cuss_signature;
- $signature_form = str_replace('data:image/jpeg;base64,','',$signature_form);
- $signature_form = str_replace('','+',$signature_form);
- //convert signature_form
- $data = base64_decode($signature_form);
- $file = $uploaded."/signature_form.jpg";
- $savetoServer = file_put_contents($file,$data);
-
- if (($savetoServer === false) || ($savetoServer == -1)) {
- return $this->sendError('Unsuccessfully upload signature', '');
- }else{
-
- $pathIconF = ''; $pathIconB = ''; $pathVisaF = ''; $pathVisaB = '';
- if($request->hasfile('front_ic')){
- $icon = $request->file('front_ic');
- $icon->move($destinationPath,'frontic.'.$icon->getClientOriginalExtension());
- $pathIconF = '/'.$destinationPath.'/frontic.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('back_ic')){
- $icon = $request->file('back_ic');
- $icon->move($destinationPath,'backic.'.$icon->getClientOriginalExtension());
- $pathIconB = '/'.$destinationPath.'/backic.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('visaF')){
- $icon = $request->file('visaF');
- $icon->move($destinationPath,'visaF.'.$icon->getClientOriginalExtension());
- $pathVisaF = '/'.$destinationPath.'/visaF.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('visaB')){
- $icon = $request->file('visaB');
- $icon->move($destinationPath,'visaB.'.$icon->getClientOriginalExtension());
- $pathVisaB = '/'.$destinationPath.'/visaB.'.$icon->getClientOriginalExtension();
- }
-
- $form->PackageDetail->contract = $request->subscription;
- $form->PackageDetail->name = $product->speed;
- $form->PackageDetail->montly_fee = $gst;
- $form->PackageDetail->voice_fee = $voice;
- $form->PackageDetail->deposit = $deposit;
- $form->PackageDetail->upfront_payment = $otc;
- $form->PackageDetail->save();
-
- $coverage = Coverage::where('_id',$request->coverage)->first();
- $form->Subscriber->name = $request->name;
- $form->Subscriber->ic = $request->nric_passport;
- $form->Subscriber->citizen = $request->citizenship;
- $form->Subscriber->gender = $request->gender;
- $form->Subscriber->race = $request->race;
- $form->Subscriber->email = $request->email;
- $form->Subscriber->phone1 = $request->contact_primary;
- $form->Subscriber->phone2 = $request->contact_secondary;
- $form->Subscriber->unit_no = $request->unit;
- $form->Subscriber->building_name = $coverage->building_name;
- $form->Subscriber->street = $request->street;
- $form->Subscriber->postcode = $coverage->postcode;
- $form->Subscriber->city = $coverage->city;
- $form->Subscriber->front_ic = $pathIconF;
- $form->Subscriber->back_ic = $pathIconB;
- $form->Subscriber->visaF = $pathVisaF;
- $form->Subscriber->visaB = $pathVisaB;
- $form->Subscriber->signature = '/'.$destinationPath.'/signature_form.jpg';
- $form->Subscriber->save();
-
- return $this->sendResponse($form, 'Form successfully been saved/updated!');
- }
-
- }else if($form->type_application == 'B'){
- $deposit = $product->deposit;
- if($request->subscription == '24'){
- $otc = 0.0;
- }else {
- $otc = 300;
- }
-
- $gst = number_format(floatval($product->retail_price) * 1.06,2);
- $total = number_format((floatval($product->retail_price) * 1.06) + $otc + $deposit, 2);
-
- $pathIconF = 'null'; $pathIconB = ''; $pathForm9 = ''; $pathForm24 = '';
- if($request->hasfile('front_ic')){
- $icon = $request->file('front_ic');
- $icon->move($destinationPath,'frontic.'.$icon->getClientOriginalExtension());
- $pathIconF = '/'.$destinationPath.'/frontic.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('back_ic')){
- $icon = $request->file('back_ic');
- $icon->move($destinationPath,'backic.'.$icon->getClientOriginalExtension());
- $pathIconB = '/'.$destinationPath.'/backic.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('form9')){
- $icon = $request->file('form9');
- $icon->move($destinationPath,'formD.'.$icon->getClientOriginalExtension());
- $pathForm9 = '/'.$destinationPath.'/formD.'.$icon->getClientOriginalExtension();
- }
-
- if($request->hasfile('form_24')){
- $icon = $request->file('form_24');
- $icon->move($destinationPath,'formA_B.'.$icon->getClientOriginalExtension());
- $pathForm24 = '/'.$destinationPath.'/formA_B.'.$icon->getClientOriginalExtension();
- }
-
- $form->PackageDetail->contract = $request->subscription;
- $form->PackageDetail->name = $product->speed;
- $form->PackageDetail->montly_fee = $gst;
- $form->PackageDetail->voice_fee = $voice;
- $form->PackageDetail->deposit = $deposit;
- $form->PackageDetail->upfront_payment = $otc;
- $form->PackageDetail->save();
-
- $form->Subscriber->name = $request->full_name;
- $form->Subscriber->ic = $request->nric_passport;
- $form->Subscriber->company_name = $request->company_name;
- $form->Subscriber->company_reg = $request->company_register;
- $form->Subscriber->company_num = $request->company_number;
- $form->Subscriber->company_fax = $request->company_fax;
- $form->Subscriber->designation = $request->designation;
- $form->Subscriber->email = $request->email;
- $form->Subscriber->phone1 = $request->contact_primary;
- $form->Subscriber->phone2 = $request->contact_secondary;
- $form->Subscriber->unit_no = $request->unit_no;
- $form->Subscriber->street = $request->caddress;
- $form->Subscriber->postcode = $request->postcode;
- $form->Subscriber->city = $request->ccity;
- $form->Subscriber->state = $request->cstate;
- $form->Subscriber->front_ic = $pathIconF;
- $form->Subscriber->back_ic = $pathIconB;
- $form->Subscriber->form24_49 = $pathForm24;
- $form->Subscriber->form9_44 = $pathForm9;
- $form->Subscriber->save();
-
- return $this->sendResponse($form, 'Form successfully been saved/updated!');
- }
-
- }else{
- return $this->sendError('Form package or form subscriber not found', '');
- }
- }else{
- return $this->sendError('Form id not found', '');
- }
- }
-
- public function deleteBookDealer(Request $request){
-
- // staff
- $form = Form::with('PackageDetail','Subscriber')->where('_id',$request->form_id)->first();
- if(!empty($form)){
- if(!empty($form->PackageDetail) && !empty($form->Subscriber)){
- $form->packagedetail()->forceDelete();
- $form->subscriber()->forceDelete();
- $form->forceDelete();
-
- return $this->sendResponse('','Form already been successfully delete');
- }else{
- return $this->sendError('Form package or subscriber not found', '');
- }
- }else{
- return $this->sendError('Form id not found', '');
- }
- }
-
- public function sendInvoice($subscriber_id) {
-
- $subscriber = Subscriber::with('Form')->where('subscriber_id',$subscriber_id)->first();
- $form = Form::with('Subscriber','PackageDetail')->where('_id',$subscriber->_id)->first();
- $product = Product::where('speed',$form->PackageDetail->name)->where('formT',$form->type_application)->first();
- if($form->type_application == 'B'){
- SendCustomerInvoiceB2::dispatch($form, $product, $form->Subscriber->email);
- return $form->_id;
- }else if($form->type_application == 'R'){
- SendCustomerInvoice2::dispatch($form, $product, $form->Subscriber->email);
- return $form->_id;
- }
- }
-
- public function updateStatusForm(Request $request){
-
- // staff
- $form = Form::with('PackageDetail','Subscriber')->where('_id',$request->form_id)->first();
- if(!empty($form)){
- if(!empty($form->PackageDetail) && !empty($form->Subscriber)){
- $form->status_form = '';
- $form->save();
-
- $form_id = $this->sendInvoice($form->Subscriber->subscriber_id);
- $stat = new FormStatus();
- $stat->form_id = $form->_id;
- $stat->status_id = 1;
- $stat->date = new \MongoDB\BSON\UTCDateTime(time()*1000);
- $stat->status = 'Sumbitted';
- $stat->desc = 'The form already been submit';
- $form->formstatus()->save($stat);
-
- return $this->sendResponse('','Form already been successfully update status draft');
- }else{
- return $this->sendError('Form package or subscriber not found', '');
- }
- }else{
- return $this->sendError('Form id not found', '');
- }
- }
- }
|