2044 lines
114 KiB
PHP
2044 lines
114 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use App\Http\Requests\FormAdditional;
|
|
use DB;
|
|
use Log;
|
|
use Storage;
|
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\InvoicesExport;
|
|
use Auth;
|
|
use App\Mail\ReportExcel;
|
|
use Mail;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Aws\Ses\SesClient;
|
|
use Aws\Credentials\CredentialProvider;
|
|
use Illuminate\Support\Str;
|
|
use Response;
|
|
|
|
class FormController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->_service = 'form';
|
|
$this->_module = 'formaction';
|
|
$this->_viewname = 'formaction';
|
|
$this->_title = 'Quick Actions';
|
|
$this->_base_url = '/formaction';
|
|
}
|
|
|
|
protected function deliverform($formdata, $questions, $id = false) {
|
|
$additional_info = $this->get_additional_info($formdata);
|
|
// if($formdata->form_id == '1711609582-e93dba24-9c98-43e7-b97a-b22d64d9b9fc') {
|
|
// echo '<pre>'; print_r($formdata); print_r($questions); exit;
|
|
// }
|
|
//echo '<pre>'; print_r($formdata); print_r($questions); exit;
|
|
$data = ['questions' => $questions, 'form' => $formdata, 'form_id' => $formdata->form_id, 'id' => false, 'id' => $id ];
|
|
Log::debug(print_r($data, true));
|
|
//echo '<pre>'; print_r($data); exit;
|
|
if(sizeof($additional_info) > 0) {
|
|
$data['additional'] = $additional_info;
|
|
}
|
|
if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->partition.'.'.$formdata->form_id)->with($data);
|
|
} elseif (\View::exists('form.'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->form_id)->with($data);
|
|
} else {
|
|
return view('form.common')->with($data);
|
|
}
|
|
}
|
|
|
|
protected function muscle_questions($formdata) {
|
|
switch($formdata->form_id) {
|
|
case '63c2ff17-a69c-4b47-af33-1d9909c608b6':
|
|
case 'eaef2abf-f16b-414c-b6a5-df3fd2282b2e':
|
|
$hierarchy = LambdaRequest::getrequest('ums', 'hierarchy/hierarchy_below_me', ['partition' => $formdata->partition, 'user_id' => $formdata->user_id ]);
|
|
$team = [];
|
|
foreach($hierarchy->data->hierarchies as $hie) {
|
|
if(isset($hie->owner_info->id)) {
|
|
$team[$hie->owner_info->id] = ['name' => $hie->owner_info->name, 'code' => $hie->owner_info->employee_code ];
|
|
}
|
|
}
|
|
return ['team' => $team];
|
|
break;
|
|
|
|
default:
|
|
return [];
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function handle($finfo, Request $request) {
|
|
$request->session()->put('finfo', $finfo);
|
|
// $finfo = Cache::remember($finfo, 3600, function () use ($finfo) {
|
|
// return LambdaRequest::postrequest('form', 'formentity/getforminfo', ['finfo' => $finfo]);
|
|
// });
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getforminfo', ['finfo' => $finfo]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
// if($finfo->data->formdata->partition == 'rapport-dc') {
|
|
// echo 'Temporary down for maintanance, please check back after 10 min'; exit;
|
|
// }
|
|
Log::debug(print_r($finfo, true));
|
|
if( isset($finfo->data->users) && sizeof($finfo->data->users) > 0 ) {
|
|
$finfo->data->formdata->users = $finfo->data->users;
|
|
$finfo->data->formdata->manager_can_submit = true;
|
|
}
|
|
$request->session()->put('formdata', $finfo->data->formdata);
|
|
if($finfo->status == 'success' && $finfo->data->formdata->link_type == 'form' && isset($finfo->data->personalizations) && sizeof($finfo->data->personalizations) > 0 ){
|
|
return $this->deliverpersonalization($finfo->data->formdata, $finfo->data->questions, $finfo->data->personalizations);
|
|
} else if($finfo->status == 'success' && $finfo->data->formdata->link_type == 'form') {
|
|
return $this->deliverform($finfo->data->formdata, $finfo->data->questions);
|
|
} elseif($finfo->status == 'success' && $finfo->data->formdata->link_type == 'list') {
|
|
//echo '<pre>'; print_r($finfo->data); exit;
|
|
if (\View::exists('form.'.$finfo->data->formdata->partition.'.list-'.$finfo->data->formdata->form_id)) {
|
|
return view('form.'.$finfo->data->formdata->partition.'.list-'.$finfo->data->formdata->form_id)->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey, 'formdata' => $finfo->data->formdata ]);
|
|
} elseif (\View::exists('form.list-'.$finfo->data->formdata->form_id)) {
|
|
return view('form.list-'.$finfo->data->formdata->form_id)->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey, 'formdata' => $finfo->data->formdata ]);
|
|
} elseif (\View::exists('form.'.$finfo->data->formdata->partition.'.list')) {
|
|
return view('form.'.$finfo->data->formdata->partition.'.list')->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey, 'formdata' => $finfo->data->formdata ]);
|
|
} else {
|
|
return view('form.list')->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey, 'formdata' => $finfo->data->formdata ]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function loadmore(Request $request) {
|
|
$finfo = $request->session()->get('finfo');
|
|
//echo $finfo; exit;
|
|
$lastkey = $request->input('lastkey', '');
|
|
//print_r(['finfo' => $finfo, 'lastkey' => $lastkey]);
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getforminfo', ['finfo' => $finfo, 'lastkey' => $lastkey]);
|
|
Log::debug(print_r($finfo->data, true));
|
|
$html = '';
|
|
foreach($finfo->data->submissions as $submission) {
|
|
if(isset($submission->user_info->name)) {
|
|
$html .= '<tr>
|
|
<th>'.date("d M Y", strtotime(isset($submission->record_date) ? $submission->record_date : $submission->updatedAt)).'</th>
|
|
<th>
|
|
<img src="'.(isset($submission->user_info->avatar) ? $submission->user_info->avatar : 'https://ui-avatars.com/api/?background=random&name='.$submission->user_info->name).'" class="rounded-circle avatar-sm" />
|
|
</th>
|
|
<td>
|
|
<h5 class="m-0 fw-normal">'.$submission->user_info->name.'</h5>
|
|
<p class="mb-0 text-muted"><small>'.$submission->user_info->designation.'</small></p>
|
|
</td>';
|
|
if(isset($finfo->data->formdata) && isset($finfo->data->formdata->workflow) && $finfo->data->formdata->workflow == 'yes' ) {
|
|
$html .= '<td>'.ucwords($submission->workflow_status).'</td>';
|
|
}
|
|
foreach($finfo->data->questions as $code => $question) {
|
|
if($question->type == 'file'){
|
|
$html .= '<td><a target="_blank" href="'. (isset($submission->formdata->{$code}) ? (is_array($submission->formdata->{$code}) ? implode(', ', $submission->formdata->{$code}) : $submission->formdata->{$code}) : '' ).'" download="'.( isset($submission->formdata->{$code}) ? (is_array($submission->formdata->{$code}) ? implode(', ', $submission->formdata->{$code}) : $submission->formdata->{$code}) : '' ).'" class="btn btn-dark btn-xs"><i class="mdi mdi-cloud-download me-1"></i> Download</a></td>';
|
|
} else {
|
|
$html .= '<td>'.( isset($submission->formdata->{$code}) ? (is_array($submission->formdata->{$code}) ? implode(', ', $submission->formdata->{$code}) : $submission->formdata->{$code}) : '' ).'</td>';
|
|
}
|
|
}
|
|
$html .= '<th>';
|
|
//if( in_array('edit', $submission->actions) && (strtotime("now") - strtotime($submission->createdAt)) < 432000 ){
|
|
$html .= '<a href="/form/edit?id='.$submission->id.'" class="btn btn-primary btn-xs">Edit</button>';
|
|
//}
|
|
$html .= '</th>
|
|
</tr>';
|
|
}
|
|
}
|
|
return response()->json(['html' => $html, 'lastkey' => $finfo->data->lastkey]);
|
|
}
|
|
|
|
public function show(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
//Log::debug(print_r($formdata, true));
|
|
$id = $request->input('id', false);
|
|
$action = $request->input('action', false);
|
|
Log::debug(print_r(['form_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition, 'id' => $id ], true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition, 'id' => $id ]);
|
|
//Log::debug(print_r($finfo, true));
|
|
$formdata->formdata = $finfo->data->formdata;
|
|
//echo '<pre>'; print_r($formdata); print_r($finfo); exit;
|
|
if($formdata->form_id == '1711947857-4fbd5d43-d176-4ec7-aff2-e4dec4b6e02a' && isset($action) && $action == 'delete') {
|
|
$contact_id = false;
|
|
foreach($finfo->data->questions as $que) {
|
|
if($que->code == 'contact_id') {
|
|
$contact_id = $que->value;
|
|
}
|
|
}
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_delete%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
LambdaRequest::getrequest('contact', 'contact/delete', ['id' => $contact_id], $token[0]->access_token);
|
|
LambdaRequest::getrequest('form', 'formentity/deletesubmission', ['id' => $id, 'form_id' => $formdata->form_id], $token[0]->access_token);
|
|
return redirect('/form/history')->withMessage('Successfully Deleted !!!');
|
|
}
|
|
$formdata->title = $finfo->data->formdata->title;
|
|
return $this->deliverform($formdata, $finfo->data->questions, $id);
|
|
}
|
|
|
|
public function deletesubmission(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
//Log::debug(print_r($formdata, true));
|
|
$id = $request->input('id', false);
|
|
$form_id = $request->input('form_id', false);
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
LambdaRequest::getrequest('form', 'formentity/deletesubmission', ['form_id' => $form_id, 'id' => $id ], $token[0]->access_token);
|
|
return redirect('/form/history')->withMessage('Successfully Deleted !!!');
|
|
}
|
|
|
|
public function submit(Request $request) {
|
|
$post = $request->except('_token');
|
|
$files = $request->file();
|
|
foreach($files as $fname => $file) {
|
|
$post[$fname] = $this->_uploadMedia($request, $fname, 'form/'.$post['form_id'].'/'.$fname);
|
|
}
|
|
if(isset($post['id']) && $post['id']=='') unset($post['id']);
|
|
$formdata = $request->session()->get('formdata');
|
|
if(isset($post['user_id']) && $post['user_id'] != '') {
|
|
$formdata->user_id = $post['user_id'];
|
|
}
|
|
|
|
// if($formdata->partition == 'rapport-copd') {
|
|
// return response()->json(['status' => 'failure']);
|
|
// }
|
|
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
$post = $this->processformdata($formdata->form_id, $post);
|
|
//Log::debug(print_r($post, true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
if($formdata->link_type == 'list') {
|
|
return redirect('/form/'.$request->session()->get('finfo') )->withMessage('Successfully Saved !!!');
|
|
} else {
|
|
return redirect('/form/history')->withMessage('Successfully Saved !!!');
|
|
}
|
|
} else {
|
|
echo '<h1>Something looks wrong. Try again!!!</h1>'; exit;
|
|
}
|
|
}
|
|
|
|
public function ajaxsubmit(Request $request) {
|
|
$post = $request->except('_token');
|
|
$files = $request->file();
|
|
//Log::debug(print_r($files, true));
|
|
// if($post['form_id'] == '1663069943-2d45ab0c-ccbe-4047-a77f-bce46b93257a') {
|
|
// exit;
|
|
// }
|
|
|
|
foreach($files as $fname => $file) {
|
|
$post[$fname] = $this->_uploadMedia($request, $fname, 'form/'.$post['form_id'].'/'.$fname);
|
|
}
|
|
if(isset($post['id']) && $post['id']=='') unset($post['id']);
|
|
|
|
$formdata = $request->session()->get('formdata');
|
|
if(!$formdata) {
|
|
$formdata = (object)[];
|
|
}
|
|
$formdata->form_id = $post['form_id'];
|
|
// if($formdata->partition == 'rapport-copd') {
|
|
// return response()->json(['status' => 'failure']);
|
|
// }
|
|
// if($formdata->partition == 'rapport-vitalis5') {
|
|
// return response()->json(['status' => 'failure']);
|
|
// }
|
|
|
|
if(isset($post['user_id']) && $post['user_id'] != '') {
|
|
$formdata->user_id = $post['user_id'];
|
|
}
|
|
if(isset($post['partition']) && $post['partition'] != '') {
|
|
$formdata->partition = $post['partition'];
|
|
}
|
|
$request->session()->put('formdata', $formdata);
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
$post = $this->processformdata($formdata->form_id, $post, $formdata->user_id, $formdata->partition);
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
Log::debug(print_r($finfo, true));
|
|
if($finfo->status == 'success') {
|
|
return response()->json(['status' => 'success']);
|
|
} else {
|
|
if($finfo->statusCode == 401) {
|
|
return response()->json(['status' => 'failure', 'message' => $finfo->data ]);
|
|
}
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
}
|
|
|
|
public function ajaxsubmitmultiple(Request $request) {
|
|
$post = $request->except('_token');
|
|
$formdata = $request->session()->get('formdata');
|
|
$formdata->form_id = $post['form_id'];
|
|
// if($formdata->partition == 'rapport-copd') {
|
|
// return response()->json(['status' => 'failure']);
|
|
// }
|
|
if(isset($post['user_id']) && $post['user_id'] != '') {
|
|
$formdata->user_id = $post['user_id'];
|
|
}
|
|
$request->session()->put('formdata', $formdata);
|
|
Log::debug(print_r($formdata, true));
|
|
|
|
if($formdata->form_id == '1716267411-74ef7199-6298-4bae-8c8b-c069a405c864') {
|
|
$contacts = [];
|
|
foreach($post['contact_id'] as $i => $contact_id) {
|
|
$contacts[] = ['contact_id' => $contact_id, 'proxym_tuesday' => isset($post['proxym_tuesday'][$i])?'Yes':'No', 'ferium_xt_thursday' => isset($post['ferium_xt_thursday'][$i])?'Yes':'No', 'galact_saturday' => isset($post['galact_saturday'][$i])?'Yes':'No' ];
|
|
}
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
|
|
foreach($contacts as $contact) {
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $post['user_id'],
|
|
'hierarchy' => $post['hierarchy_id'],
|
|
'proxym_tuesday' => $contact['proxym_tuesday'],
|
|
'ferium_xt_thursday' => $contact['ferium_xt_thursday'],
|
|
'galact_saturday' => $contact['galact_saturday'],
|
|
'id' => $contact['contact_id'],
|
|
];
|
|
$cont = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
}
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
|
|
//["rtm","telma_ln_ecme","zita_ecme"]
|
|
if($formdata->form_id == '1721281521-a4a857d7-84d7-4e4c-9df3-4e9c9f999d64') {
|
|
$contacts = [];
|
|
foreach($post['contact_id'] as $i => $contact_id) {
|
|
$contacts[] = ['contact_id' => $contact_id, 'zita_ecme' => isset($post['zita_ecme'][$i])?'Yes':'No', 'telma_ln_ecme' => isset($post['telma_ln_ecme'][$i])?'Yes':'No', 'rtm' => isset($post['rtm'][$i])?'Yes':'No' ];
|
|
}
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
$post['contact_id'] = [];
|
|
$post['zita_ecme'] = [];
|
|
$post['telma_ln_ecme'] = [];
|
|
$post['rtm'] = [];
|
|
foreach($contacts as $i => $contact) {
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $post['user_id'],
|
|
//'hierarchy' => $post['hierarchy_id'],
|
|
'zita_ecme' => $contact['zita_ecme'],
|
|
'telma_ln_ecme' => $contact['telma_ln_ecme'],
|
|
'rtm' => $contact['rtm'],
|
|
'id' => $contact['contact_id'],
|
|
];
|
|
$cont = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
$post['contact_id'][$i] = $contact['contact_id'];
|
|
$post['zita_ecme'][$i] = $contact['zita_ecme'];
|
|
$post['telma_ln_ecme'][$i] = $contact['telma_ln_ecme'];
|
|
$post['rtm'][$i] = $contact['rtm'];
|
|
}
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
|
|
if($formdata->form_id == '1716267411-74ef7199-6298-4bae-c2c-c069a405c864') {
|
|
$contacts = [];
|
|
foreach($post['contact_id'] as $i => $contact_id) {
|
|
$contacts[] = ['contact_id' => $contact_id, 'c2c' => isset($post['c2c'][$i])?'Yes':'No' ];
|
|
}
|
|
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
|
|
foreach($contacts as $contact) {
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $post['user_id'],
|
|
'hierarchy' => $post['hierarchy_id'],
|
|
'c2c' => $contact['c2c'],
|
|
'id' => $contact['contact_id'],
|
|
];
|
|
$cont = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
}
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
|
|
if($formdata->form_id == '1723015306-c8d90868-1c50-4820-ab96-474cdff8e543') {
|
|
$contacts = [];
|
|
foreach($post['contact_id'] as $i => $contact_id) {
|
|
$contacts[] = ['contact_id' => $contact_id, 'glycoquic_f' => isset($post['glycoquic_f'][$i])?'Yes':'No' ];
|
|
}
|
|
|
|
list($application, $domain) = explode("-", $formdata->partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
|
|
foreach($contacts as $contact) {
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $post['user_id'],
|
|
'glycoquic_f' => $contact['glycoquic_f'],
|
|
'id' => $contact['contact_id'],
|
|
];
|
|
$cont = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
}
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
|
|
if($formdata->form_id == '1713426268-c89f38eb-ec32-43ba-a81b-b690a8f90d6a') {
|
|
if(DB::table('team3_nebyatra_doctors')->where('user_id', $formdata->user_id)->wherein('mobile_number', $post['mobile_number'])->exists() ){
|
|
$phones = DB::table('team3_nebyatra_doctors')->select("mobile_number")->where('user_id', $formdata->user_id)->wherein('mobile_number', $post['mobile_number'])->get();
|
|
$matched = [];
|
|
foreach($phones as $phone) {
|
|
$matched[] = $phone->mobile_number;
|
|
}
|
|
return response()->json(['status' => 'failure', 'message' => 'Some Mobile numbers you entered already exists. Numbers are ' . implode(', ', $matched) ]);
|
|
}
|
|
}
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
$post = $this->processformdata($formdata->form_id, $post, $formdata->user_id, $formdata->partition);
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitmultipleform', ['formdata' => $post, 'entity_id' => $post['form_id'], 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
//Log::debug(print_r($finfo, true));
|
|
if($finfo->status == 'success') {
|
|
return response()->json(['status' => 'success']);
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
}
|
|
|
|
public function approvereject(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
$post = $request->all();
|
|
//$user = DB::table('users')->where('domain', str_replace('rapport-', '',$formdata->partition ) )->first();
|
|
|
|
list($app, $domain) = explode('-', $formdata->partition);
|
|
$user = DB::table('users')->select("access_token")->where('domain', $domain )->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
Log::debug(print_r($formdata, true));
|
|
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/approvereject', ['submission_id' => $post['id'], 'action' => $post['action'] ], $user[0]->access_token);
|
|
Log::debug(print_r($user, true));
|
|
Log::debug(print_r($finfo, true));
|
|
Log::debug(print_r($post, true));
|
|
return response()->json($post);
|
|
}
|
|
|
|
public function approverejectmultiple(Request $request) {
|
|
$post = $request->all();
|
|
foreach($post['ids'] as $id) {
|
|
LambdaRequest::postrequest('form', 'formentity/approvereject', ['submission_id' => $id, 'action' => $post['action'] ], Auth::user()->access_token);
|
|
}
|
|
return response()->json($post);
|
|
}
|
|
|
|
public function allaprovers(Request $request) {
|
|
$post = $request->all();
|
|
$allapprovers = LambdaRequest::postrequest('form', 'formentity/allapprovers', ['submission_id' => $post['submission_id'], 'form_id' => $post['form_id'] ], Auth::user()->access_token);
|
|
return response()->json($allapprovers->data->approvals);
|
|
}
|
|
|
|
protected function processformdata($form, $post, $user_id = 0, $partition = '' ) {
|
|
switch($form) {
|
|
case '1711609582-e93dba24-9c98-43e7-b97a-b22d64d9b9fc':
|
|
case '1711609582-e93dba24-9c98-43e7-neb2-b22d64d9b9fc':
|
|
list($application, $domain) = explode("-", $partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $user_id,
|
|
'name' => $post['chemist_name'],
|
|
'current_business' => $post['current_business'],
|
|
'type' => 'chemist',
|
|
'category' => isset($post['category']) ? $post['category'] : '',
|
|
'msl_code' => strtotime("now").'-'.rand(1000,9999)
|
|
];
|
|
if(isset($post['id'])) {
|
|
$contactdata['id'] = $post['contact_id'];
|
|
unset($post['contact_id']);
|
|
$contact = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
} else {
|
|
$contact = LambdaRequest::postrequest('contact', 'contact/create', $contactdata, $token[0]->access_token);
|
|
}
|
|
$post['contact_id'] = $contact->data->item->id;
|
|
break;
|
|
case '1711947857-4fbd5d43-d176-4ec7-aff2-e4dec4b6e02a':
|
|
list($application, $domain) = explode("-", $partition);
|
|
$token = DB::table('users')->select("access_token")->where("domain", $domain)->where("permissions", 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get();
|
|
$contactdata = [
|
|
'domain' => $domain,
|
|
'application' => $application,
|
|
'user_id' => $user_id,
|
|
'name' => $post['chemist_name'],
|
|
'current_business' => $post['current_business'],
|
|
'type' => 'chemist',
|
|
'doctor_name' => $post['doctor_name'],
|
|
'category' => $post['category'],
|
|
'doctor_msl_code' => $post['msl_code'],
|
|
'doctor_speciality' => $post['speciality'],
|
|
'msl_code' => strtotime("now").'-'.rand(1000,9999)
|
|
];
|
|
if(isset($post['id'])) {
|
|
$contactdata['id'] = $post['contact_id'];
|
|
unset($post['contact_id']);
|
|
$contact = LambdaRequest::postrequest('contact', 'contact/update', $contactdata, $token[0]->access_token);
|
|
} else {
|
|
$contact = LambdaRequest::postrequest('contact', 'contact/create', $contactdata, $token[0]->access_token);
|
|
}
|
|
$post['contact_id'] = $contact->data->item->id;
|
|
break;
|
|
case '1654748343-81b065ee-e05c-431c-a44d-706afc1c16f4':
|
|
if($post['contact_id'] == 'other') {
|
|
$post['contact_id'] = '';
|
|
}
|
|
break;
|
|
case '1650365556-f06dde85-6138-4dae-9c23-5067e318c522':
|
|
case '1660360290-f06dde85-6138-4dae-9c23-5067e318c522':
|
|
$post[ $post['brand_name'].'-current' ] = $post['current_business_value'];
|
|
$post[ $post['brand_name'].'-potential' ] = $post['potential_business_value'];
|
|
break;
|
|
case '1653655221-724ec5b4-fccb-4a88-bf25-cf894fa27a77':
|
|
$brands = ['Hinex DM' => 'hinex-dm', 'Hinex HP' => 'hinex-hp', 'Hinex ST' => 'hinex-st', 'Hinex ST +' => 'hinex-st+'];
|
|
foreach($post['brand'] as $i => $brand) {
|
|
foreach($brands as $bname => $bkey) {
|
|
if($bname == $brand)
|
|
$post[$bkey][$i] = $post['units'][$i];
|
|
else
|
|
$post[$bkey][$i] = 0;
|
|
}
|
|
}
|
|
break;
|
|
case '1655958637-c41fb1b6-4ddc-42d3-aa2a-563c1cf5e4c9':
|
|
Log::debug(print_r($post, true));
|
|
if(array_key_exists('chemist_name', $post) ) {
|
|
$chemistformdata = [];
|
|
$chemistformdata['form_id'] = '1654747635-9d7133e4-a641-4865-aeed-021bb34d8960';
|
|
$chemistformdata['record_date'] = $post['record_date'];
|
|
$chemistformdata['chemist_name'] = $post['chemist_name'];
|
|
$chemistformdata['dapasach_units'] = $post['dapasach_strips'];
|
|
$chemistformdata['dapasach_m_units'] = $post['dapasach_m_strips'];
|
|
$chemistformdata['dapasach_s_units'] = $post['dapasach_s_strips'];
|
|
Log::debug(print_r($chemistformdata, true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitmultipleform', ['formdata' => $chemistformdata, 'entity_id' => $chemistformdata['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
|
|
$rxformdata = [];
|
|
$rxformdata['form_id'] = '1657032612-8a539e63-fc5e-47c2-96f9-b4454cea7591';
|
|
$rxformdata['record_date'] = $post['record_date'];
|
|
$rxformdata['no_of_dapasach_rx'] = $post['no_of_dapasach_rx'];
|
|
$rxformdata['no_of_dapasach_m_rx'] = $post['no_of_dapasach_m_rx'];
|
|
$rxformdata['no_of_dapasach_s_rx'] = $post['no_of_dapasach_s_rx'];
|
|
$rxformdata['dapasach_units_made_available'] = $post['dapasach_units_made_available'];
|
|
$rxformdata['dapasach_m_units_made_available'] = $post['dapasach_m_units_made_available'];
|
|
$rxformdata['dapasach_s_units_made_available'] = $post['dapasach_s_units_made_available'];
|
|
Log::debug(print_r($rxformdata, true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $rxformdata, 'entity_id' => $rxformdata['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
|
|
unset($post['chemist_name']);
|
|
unset($post['dapasach_units']);
|
|
unset($post['dapasach_m_units']);
|
|
unset($post['dapasach_s_units']);
|
|
unset($post['no_of_dapasach_rx']);
|
|
unset($post['no_of_dapasach_m_rx']);
|
|
unset($post['no_of_dapasach_s_rx']);
|
|
unset($post['dapasach_units_made_available']);
|
|
unset($post['dapasach_m_units_made_available']);
|
|
Log::debug(print_r($post, true));
|
|
break;
|
|
case '1659513453-1f5e2584-fb76-4075-b040-6sg6e34a5423':
|
|
if($post['customer_type'] == 'Doctor') {
|
|
$post['doctor_count'] = 1;
|
|
$post['retailer_count'] = 0;
|
|
} else {
|
|
$post['doctor_count'] = 0;
|
|
$post['retailer_count'] = 1;
|
|
}
|
|
break;
|
|
case '1659513016-1f5e2584-fb76-4075-b040-a9a4e34a7458':
|
|
case '1659538834-fb8bd30a-a719-4285-8d74-063462930c1d':
|
|
if($post['customer_type'] == 'Doctor') {
|
|
$post['doctor_count'] = 1;
|
|
$post['retailer_count'] = 0;
|
|
} else {
|
|
$post['doctor_count'] = 0;
|
|
$post['retailer_count'] = 1;
|
|
}
|
|
|
|
$prefix = '';
|
|
if($post['brand_selected'] == 'DAPASACH FRANCHISE') {
|
|
$prefix = 'dapasach_';
|
|
if($post['customer_type'] == 'Retailer') {
|
|
$post[$prefix.'pob_dapasach'] = $post['pob_dapasach'];
|
|
$post[$prefix.'pob_dapasach_s'] = $post['pob_dapasach_s'];
|
|
$post[$prefix.'pob_dapasach_m'] = $post['pob_dapasach_m'];
|
|
}
|
|
} else if($post['brand_selected'] == 'METOLAR FRANCHISE') {
|
|
$prefix = 'metolar_';
|
|
if($post['customer_type'] == 'Retailer') {
|
|
$post[$prefix.'pob_metolar_trio'] = $post['pob_metolar_trio'];
|
|
$post[$prefix.'pob_metolar_3d'] = $post['pob_metolar_3d'];
|
|
}
|
|
}
|
|
$post[$prefix.'doctor_count'] = $post['doctor_count'];
|
|
$post[$prefix.'retailer_count'] = $post['retailer_count'];
|
|
break;
|
|
case '1663562771-bd3aeb6b-2495-4b82-9ce8-7ba159700a7a':
|
|
$post[strtolower($post['brand']).'_count'] = 1;
|
|
$post[strtolower($post['brand']).'_business_potential'] = $post['business_potential'];
|
|
break;
|
|
case '1663833303-3503e11a-ca91-4bb7-ac85-bc9bc36d9997':
|
|
if($post['doctor_activity'] == 'Yes' || $post['rx_generated'] == 'Yes') {
|
|
$rxformdata = [];
|
|
$rxformdata['form_id'] = '1665645874-53e8b736-a061-4231-b209-f229083a883c';
|
|
$rxformdata['record_date'] = empty($post['rx_date']) ? $post['activity_rx_date'] : $post['rx_date'];
|
|
$rxformdata['contact_id'] = $post['contact_id'];
|
|
$rxformdata['no_of_dapasach_rx'] = ($post['rx_generated'] == 'Yes') ? $post['no_of_dapasach_rx'] : 0;
|
|
$rxformdata['no_of_dapasach_m_rx'] = ($post['rx_generated'] == 'Yes') ? $post['no_of_dapasach_m_rx'] : 0;
|
|
$rxformdata['no_of_dapasach_s_rx'] = ($post['rx_generated'] == 'Yes') ? $post['no_of_dapasach_s_rx'] : 0;
|
|
$rxformdata['doctor_activity'] = $post['doctor_activity'];
|
|
$rxformdata['activity_name'] = isset($post['activity_name']) ? $post['activity_name'] : '';
|
|
Log::debug(print_r($rxformdata, true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $rxformdata, 'entity_id' => $rxformdata['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
|
|
if($post['converted_count'] == 1) {
|
|
$rxformdata = [];
|
|
$rxformdata['form_id'] = '1665653958-93e66eae-f0ad-4792-ae91-87f9ae787380';
|
|
$rxformdata['record_date'] = $post['conversion_date'];
|
|
$rxformdata['contact_id'] = $post['contact_id'];
|
|
$rxformdata['converted_count'] = $post['converted_count'];
|
|
Log::debug(print_r($rxformdata, true));
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $rxformdata, 'entity_id' => $rxformdata['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
|
|
break;
|
|
case '1669979078-e991fc27-e8c1-4120-9883-b42af09244d0':
|
|
$post[strtolower($post['brand_name'])] = $post['no_of_rx'];
|
|
break;
|
|
case '1669979081-e991fc27-e8c1-4120-9883-b42af09244d3':
|
|
case '1689236085-9aaa37ba-601b-4414-b1fc-a26e9cc722df':
|
|
if(isset($post['execution_done']) && $post['execution_done'] == 'yes' && isset($post['activity_type'])) {
|
|
$post[$post['activity_type']] = 1;
|
|
}
|
|
break;
|
|
|
|
case '1672032315-9b267137-4b81-425c-afb4-a4c0fa701372':
|
|
if($post['powerof5'] == 'Yes') {
|
|
$post['powerof5_duolin_rx'] = $post['duolin_rx'];
|
|
$post['powerof5_glycohale_f_rx'] = $post['glycohale_f_rx'];
|
|
$post['powerof5_maxiflo_rx'] = $post['maxiflo_rx'];
|
|
$post['powerof5_maxiflo_sb_rx'] = $post['maxiflo_sb_rx'];
|
|
$post['powerof5_asthalin_rx'] = $post['asthalin_rx'];
|
|
$post['powerof5_glycohale_fb_rx'] = $post['glycohale_fb_rx'];
|
|
}
|
|
break;
|
|
case '1675171879-850cf63f-864d-42e1-82e7-2a60e92712b6':
|
|
$post['launched_count'] = [];
|
|
foreach($post['contact_id'] as $i => $c) {
|
|
$post['launched_count'][] = $post['launched'][$i] == 'Yes' ? 1 : 0;
|
|
}
|
|
break;
|
|
case '1672051617-b274ae94-8706-4f0f-8e65-6e4380f7c005':
|
|
case '1673857541-fe4fef4b-6b1c-4326-96ec-f71634ee91db':
|
|
if($post['is_hridayam_doctor'] == 'Yes') {
|
|
$rxformdata = $post;
|
|
$rxformdata['form_id'] = '1672051617-b274ae94-8704-4f0f-8e85-6e4380f7c4543';
|
|
LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $rxformdata, 'entity_id' => $rxformdata['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
break;
|
|
case '1653655224-724ec5b3-fccb-4a88-bf28-cf894fa27a78':
|
|
$contacts = [];
|
|
$indamet_80_rx = [];
|
|
$indamet_160_rx = [];
|
|
$indamet_320_rx = [];
|
|
$doctor_tagging = [];
|
|
$campaign = [];
|
|
foreach($post['contact_id'] as $i => $c) {
|
|
if($post['indamet_80_rx'][$i] > 0 || $post['indamet_160_rx'][$i] > 0 || $post['indamet_320_rx'][$i] > 0) {
|
|
$contacts[] = $c;
|
|
$indamet_80_rx[] = $post['indamet_80_rx'][$i];
|
|
$indamet_160_rx[] = $post['indamet_160_rx'][$i];
|
|
$indamet_320_rx[] = $post['indamet_320_rx'][$i];
|
|
$doctor_tagging[] = $post['doctor_tagging'][$i];
|
|
$campaign[] = $post['campaign'][$i];
|
|
}
|
|
}
|
|
$post['contact_id'] = $contacts;
|
|
$post['indamet_80_rx'] = $indamet_80_rx;
|
|
$post['indamet_160_rx'] = $indamet_160_rx;
|
|
$post['indamet_320_rx'] = $indamet_320_rx;
|
|
$post['doctor_tagging'] = $doctor_tagging;
|
|
$post['campaign'] = $campaign;
|
|
break;
|
|
case '1691224392-9d29fc1f-23ae-4702-bc23-55ccdd85dab4':
|
|
if(isset($post['execution_date'])) {
|
|
$first_post = $post;
|
|
foreach($post['contact_id'] as $k => $v) {
|
|
if($k == 0) {
|
|
$first_post['contact_id'] = $v;
|
|
$first_post['id'] = $post['id'][$k];
|
|
$first_post['speciality'] = $post['speciality'][$k];
|
|
$first_post['group_id'] = $post['group_id'][$k];
|
|
$first_post['no_of_paramedics'] = $post['no_of_paramedics'][$k];
|
|
$first_post['first_executed'] = 'yes';
|
|
$first_post['first_planned'] = 'yes';
|
|
} else {
|
|
$thispost = $post;
|
|
$thispost['contact_id'] = $v;
|
|
$thispost['id'] = $post['id'][$k];
|
|
$thispost['speciality'] = $post['speciality'][$k];
|
|
$thispost['group_id'] = $post['group_id'][$k];
|
|
$thispost['no_of_paramedics'] = $post['no_of_paramedics'][$k];
|
|
LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $thispost, 'entity_id' => $thispost['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
}
|
|
$post = $first_post;
|
|
} else {
|
|
$first_post = $post;
|
|
$group_id = strtotime("now").'-'.rand(1000000,9999999);
|
|
foreach($post['contact_id'] as $k => $v) {
|
|
if($k == 0) {
|
|
$first_post['contact_id'] = $v;
|
|
$first_post['speciality'] = $post['speciality'][$k];
|
|
$first_post['group_id'] = $group_id;
|
|
$first_post['first_planned'] = 'yes';
|
|
} else {
|
|
$thispost = $post;
|
|
$thispost['contact_id'] = $v;
|
|
$thispost['speciality'] = $post['speciality'][$k];
|
|
$thispost['group_id'] = $group_id;
|
|
LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $thispost, 'entity_id' => $thispost['form_id'], 'user_id' => $user_id, 'partition' => $partition ]);
|
|
}
|
|
}
|
|
$post = $first_post;
|
|
}
|
|
break;
|
|
case '1713426268-c89f38eb-ec32-43ba-a81b-b690a8f90d6a':
|
|
if(is_array($post['doctor_name']) ) {
|
|
$execCount = sizeof($post['doctor_name']);
|
|
$planed = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => '1713425460-8bdf7394-01b5-48f3-8985-343b465dd685', 'user_id' => $user_id, 'partition' => $partition, 'id' => $post['plan_id'] ]);
|
|
$plandata = $planed->data->formdata;
|
|
if(isset($plandata->execution_count)) {
|
|
$plandata->execution_count += $execCount;
|
|
} else {
|
|
$plandata->execution_count = $execCount;
|
|
}
|
|
$plandata->id = $post['plan_id'];
|
|
LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => (array)$plandata, 'entity_id' => '1713425460-8bdf7394-01b5-48f3-8985-343b465dd685', 'user_id' => $user_id, 'partition' => $partition ]);
|
|
$post['plan_id'] = [];
|
|
foreach($post['doctor_name'] as $i => $dn) {
|
|
$post['plan_id'][] = $plandata->id;
|
|
DB::table('team3_nebyatra_doctors')->updateOrInsert(
|
|
['user_id' => $user_id, 'mobile_number' => $post['mobile_number'][$i] ],
|
|
['doctor_name' => $dn, 'email_id' => $post['email_id'][$i], 'speciality' => $post['speciality'][$i], 'location' => $post['location'][$i], 'district' => $post['district'][$i], 'state' => $post['state'][$i], 'date_added' => $post['record_date'][$i] ]
|
|
);
|
|
}
|
|
|
|
}
|
|
break;
|
|
}
|
|
|
|
return $post;
|
|
}
|
|
|
|
public function history(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
//Log::debug(print_r($formdata, true));
|
|
$form_id = $request->input('form_id', $formdata->form_id);
|
|
$formdata->form_id = $form_id;
|
|
$request->session()->put('formdata', $formdata);
|
|
//echo '<pre>'; print_r($formdata); exit;
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
|
//Log::debug(print_r($history, true));
|
|
if($form_id == '1713426268-c89f38eb-ec32-43ba-a81b-b690a8f90d6a') {
|
|
$plan_id = $request->input('plan_id', '');
|
|
$submissions = [];
|
|
foreach($history->data->submissions as $sub) {
|
|
if(isset($sub->formdata->plan_id) && $sub->formdata->plan_id == $plan_id) {
|
|
$submissions[] = $sub;
|
|
}
|
|
}
|
|
$data = ['form' => $history->data->form, 'questions' => $history->data->questions, 'submissions' => $submissions, 'formname' => $history->data->formname, 'form_id' => $form_id ];
|
|
} else {
|
|
$data = ['form' => $history->data->form, 'questions' => $history->data->questions, 'submissions' => $history->data->submissions, 'formname' => $history->data->formname, 'form_id' => $form_id ];
|
|
}
|
|
|
|
if($request->input('export', false)) {
|
|
$exceldata = [];
|
|
$exceldata[] = [$formdata->title];
|
|
$exceldata[] = [''];
|
|
$headers = ['Submission Date', 'Submitted By', 'Approval Status'];
|
|
foreach($history->data->questions as $question) {
|
|
$headers[] = $question->label;
|
|
}
|
|
$exceldata[] = $headers;
|
|
foreach($history->data->submissions as $submission) {
|
|
$row = [];
|
|
$row[] = $submission->createdAt;
|
|
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
|
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
|
foreach($history->data->questions as $q => $v) {
|
|
$row[] = isset($submission->formdata->{$q}) ? $submission->formdata->{$q} : '-';
|
|
}
|
|
$exceldata[] = $row;
|
|
}
|
|
return Excel::download(new InvoicesExport($exceldata), $formdata->title.'.xlsx');
|
|
}
|
|
|
|
if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id.'-history')) {
|
|
return view('form.'.$formdata->partition.'.'.$formdata->form_id.'-history')->with($data);
|
|
} elseif (\View::exists('form.'.$formdata->form_id.'-history')) {
|
|
return view('form.'.$formdata->form_id.'-history')->with($data);
|
|
} else {
|
|
return view('form.history')->with($data);
|
|
}
|
|
//return view('form.history')->with();
|
|
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
|
}
|
|
|
|
public function edit(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
//Log::debug(print_r($formdata, true));
|
|
$id = $request->input('id', false);
|
|
//'user_id' => $formdata->user_id,
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => $formdata->form_id, 'partition' => $formdata->partition, 'id' => $id ]);
|
|
$formdata->title = $finfo->data->formdata->title;
|
|
//Log::debug(print_r($finfo->data->formdata, true));
|
|
if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->partition.'.'.$formdata->form_id)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]);
|
|
} elseif (\View::exists('form.'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->form_id)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]);
|
|
} else {
|
|
return view('form.common')->with(['questions' => $finfo->data->questions, 'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]);
|
|
}
|
|
}
|
|
|
|
protected function get_additional_info($formdata) {
|
|
switch($formdata->form_id) {
|
|
case '63c2ff17-a69c-4b47-af33-1d9909c608b6':
|
|
case 'eaef2abf-f16b-414c-b6a5-df3fd2282b2e':
|
|
$hierarchy = LambdaRequest::getrequest('ums', 'hierarchy/hierarchy_below_me', ['partition' => $formdata->partition, 'user_id' => $formdata->user_id ]);
|
|
$team = [];
|
|
foreach($hierarchy->data->hierarchies as $hie) {
|
|
if(isset($hie->owner_info->id)) {
|
|
$team[$hie->owner_info->id] = ['name' => $hie->owner_info->name, 'code' => $hie->owner_info->employee_code ];
|
|
}
|
|
}
|
|
return ['team' => $team];
|
|
break;
|
|
case '1653655221-724ec5b4-fccb-4a88-bf25-cf894fa27a77':
|
|
|
|
return [];
|
|
break;
|
|
|
|
default:
|
|
return [];
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getformfielddata(Request $request) {
|
|
$post = $request->except('_token');
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $post['form_id'], 'user_id' => $post['user_id'], 'partition' => $post['partition'] ]);
|
|
$submission = [];
|
|
foreach($history->data->submissions as $sub) {
|
|
if($sub->formdata->record_date == strtotime($post['record_date']) ) {
|
|
$submission = (array)$sub->formdata;
|
|
$submission['submission_id'] = $sub->id;
|
|
}
|
|
}
|
|
|
|
return response()->json(['submission' => $submission, 'submissions' => $history->data->submissions, 'record_date' => strtotime($post['record_date']) ]);
|
|
}
|
|
|
|
public function metricreport(Request $request) {
|
|
$post = $request->input();
|
|
Log::debug(print_r($post, true));
|
|
$token = $request->header('Authorization');
|
|
if($token != '') {
|
|
$request->session()->put('metric_access_key', $token);
|
|
} elseif(array_key_exists('authorization', $post)) {
|
|
$token = $post['authorization'];
|
|
$request->session()->put('metric_access_key', $token);
|
|
} else {
|
|
$token = $request->session()->get('metric_access_key');
|
|
}
|
|
//Log::debug('Token is:' . $token);
|
|
$download = (isset($post['download']) && $post['download'] == 1) ? 1 : 0;
|
|
$email = (isset($post['email']) && $post['email'] == 1) ? 1 : 0;
|
|
$s3 = (isset($post['s3']) && $post['s3'] == 1) ? 1 : 0;
|
|
unset($post['download']);
|
|
unset($post['email']);
|
|
unset($post['s3']);
|
|
|
|
$response = LambdaRequest::postrequest('metric', 'metric_report/view', $post, $token);
|
|
Log::debug(print_r($response, true));
|
|
//echo '<pre>'; print_r($response); print_r($post); exit;
|
|
|
|
$breadcrumbs = [];
|
|
if(isset($post['hid'])){
|
|
if($request->session()->has('leaderboard_breadcrumbs')) {
|
|
$breadcrumbs = $request->session()->get('leaderboard_breadcrumbs');
|
|
}
|
|
$breadcrumbs[$post['level']] = ['hid' => $post['hid'], 'username' => $post['username'], 'level' => $post['level'] ];
|
|
$request->session()->put('leaderboard_breadcrumbs', $breadcrumbs);
|
|
$breadcrumbs = array_filter($breadcrumbs, function($k) use($post) { return $k >= $post['level']; }, ARRAY_FILTER_USE_KEY);
|
|
krsort($breadcrumbs);
|
|
}
|
|
|
|
|
|
if($download) {
|
|
$exceldata = [];
|
|
$exceldata[] = [$response->data->graph->name];
|
|
$exceldata[] = ['Report: '.ucwords($response->data->graph->agg_type).' Report'];
|
|
$exceldata[] = ['Type: '.ucwords($response->data->graph->type).' Metric'];
|
|
foreach($response->data->periods as $v) {
|
|
if($post['period'] == $v->value) {
|
|
$exceldata[] = ['Period: '.ucwords($v->label)];
|
|
}
|
|
}
|
|
$exceldata[] = [''];
|
|
switch($response->data->post->type) {
|
|
case 'leaderboard':
|
|
$exceldata[] = ["Rank", "User", "Designation", "Units", "Percent"];
|
|
foreach($response->data->graph->values as $val) {
|
|
$exceldata[] = [(string)$val->rank, (string)$val->user->name, $val->user->designation, (string)round($val->score, 2), (string)$response->data->graph->values[0]->rank != 0 ? ($response->data->graph->values[0]->rank == 1 ? ($response->data->graph->values[0]->score ? ceil(($val->score/$response->data->graph->values[0]->score)*100) : 0) : ($response->data->graph->values[1]->score ? ceil(($val->score/$response->data->graph->values[1]->score)*100) : 0 ) ) : 0 ];
|
|
}
|
|
break;
|
|
case 'trend':
|
|
$headings = ['Periods'];
|
|
if($response->data->graph->type == 'grouped') {
|
|
foreach($response->data->graph->values as $met) {
|
|
$headings[] = $met->metric;
|
|
}
|
|
$exceldata[] = $headings;
|
|
foreach($response->data->graph->values[0]->stats as $i => $stat) {
|
|
$row = [$stat->x];
|
|
foreach($response->data->graph->values as $met) {
|
|
$row[] = isset($met->stats[$i])?$met->stats[$i]->y:0;
|
|
}
|
|
$exceldata[] = $row;
|
|
}
|
|
} else {
|
|
$headings[] = $response->data->graph->label;
|
|
$exceldata[] = $headings;
|
|
foreach($response->data->graph->values as $i => $val) {
|
|
$exceldata[] = [$val->x, $val->y];
|
|
}
|
|
}
|
|
break;
|
|
case 'graphical':
|
|
if($response->data->graph->type == 'grouped') {
|
|
$exceldata[] = ['Metric Name', 'Units', 'Percent'];
|
|
$total = 0;
|
|
foreach($response->data->graph->values as $val) {
|
|
$total = $total + $val->value;
|
|
}
|
|
foreach($response->data->graph->values as $val) {
|
|
$exceldata[] = [$val->label, $val->value, (string)round(($val->value/$total)*100, 2)];
|
|
}
|
|
}
|
|
break;
|
|
case 'details':
|
|
if($response->data->graph->chart == 'tabular') {
|
|
$headers = ['User', 'Employee Code', 'Designation', 'Zone', 'Region', "Area", "Territory"];
|
|
foreach($response->data->graph->values->metrics as $metric) {
|
|
$headers[] = $metric->metric;
|
|
}
|
|
$exceldata[] = $headers;
|
|
foreach($response->data->graph->values->users as $user) {
|
|
$row = [];
|
|
$row[] = $user->name;
|
|
$row[] = $user->employee_code;
|
|
$row[] = $user->designation;
|
|
$row[] = isset($user->positions->Zone) ? $user->positions->Zone : '-';
|
|
$row[] = isset($user->positions->Region) ? $user->positions->Region : '-';
|
|
$row[] = isset($user->positions->Area) ? $user->positions->Area : '-';
|
|
$row[] = isset($user->positions->Territory) ? $user->positions->Territory : '-';
|
|
foreach($response->data->graph->values->metrics as $metric) {
|
|
$row[] = isset($metric->stats->{$user->id}) ? $metric->stats->{$user->id} : '-';
|
|
}
|
|
$exceldata[] = $row;
|
|
}
|
|
}
|
|
break;
|
|
case 'contacts':
|
|
if($response->data->graph->chart == 'contacts') {
|
|
//echo '<pre>'; print_r($response->data->graph->values); exit;
|
|
|
|
$headers = ['Doctor', 'MSL Code', 'User', 'Employee Code', 'Email', 'Designation', 'Manager 1 Name', 'Manager 1 Emp Code', 'Manager 1 Email', 'Manager 2 Name', 'Manager 2 Emp Code', 'Manager 2 Email', 'Zone', 'Region', "Area", "Territory"];
|
|
foreach($response->data->graph->values->metrics as $metric) {
|
|
$headers[] = $metric->metric;
|
|
}
|
|
$exceldata[] = $headers;
|
|
foreach($response->data->graph->values->contacts as $contact) {
|
|
$row = [];
|
|
$row[] = $contact->name;
|
|
$row[] = $contact->msl_code;
|
|
|
|
if(!isset($response->data->graph->values->users->{$contact->id})) {
|
|
continue;
|
|
}
|
|
|
|
$user = $response->data->graph->values->users->{$contact->id};
|
|
|
|
$row[] = $user->name;
|
|
$row[] = $user->employee_code;
|
|
$row[] = $user->email;
|
|
$row[] = $user->designation;
|
|
|
|
$row[] = isset($user->manager1->name) ? $user->manager1->name : '-';
|
|
$row[] = isset($user->manager1->employee_code) ? $user->manager1->employee_code : '-';
|
|
$row[] = isset($user->manager1->email) ? $user->manager1->email : '-';
|
|
$row[] = isset($user->manager2->name) ? $user->manager2->name : '-';
|
|
$row[] = isset($user->manager2->employee_code) ? $user->manager2->employee_code : '-';
|
|
$row[] = isset($user->manager2->email) ? $user->manager2->email : '-';
|
|
|
|
$row[] = isset($user->positions->Zone) ? $user->positions->Zone : '-';
|
|
$row[] = isset($user->positions->Region) ? $user->positions->Region : '-';
|
|
$row[] = isset($user->positions->Area) ? $user->positions->Area : '-';
|
|
$row[] = isset($user->positions->Territory) ? $user->positions->Territory : '-';
|
|
|
|
foreach($response->data->graph->values->metrics as $metric) {
|
|
$row[] = isset($metric->stats->{$contact->id}) ? $metric->stats->{$contact->id} : '-';
|
|
}
|
|
$exceldata[] = $row;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
//echo '<pre>'; print_r($exceldata); exit;
|
|
$data = new \StdClass;
|
|
$data->sender_name = 'Rapport Support';
|
|
$data->sender_email = 'support@stratawiz.com';
|
|
$data->subject = 'Attached Report';
|
|
$data->body = '';
|
|
|
|
$report = Excel::raw(new InvoicesExport($exceldata), 'Xlsx');
|
|
$data->attachment = $report;
|
|
$data->attachment_name = 'report.xlsx';
|
|
|
|
//Mail::to( str_replace(Auth::user()->domain.'-','', Auth::user()->email) )->send(new ReportExcel($data));
|
|
//Mail::to( 'ravigulhane1983@gmail.com' )->send(new ReportExcel($data));
|
|
if($s3) {
|
|
$filename = 'reports/'.strtotime("now").'-report.xlsx';
|
|
$res = Excel::store(new InvoicesExport($exceldata), 'public/'.$filename);
|
|
Log::debug(print_r($res, true));
|
|
Log::debug('/storage/'.$filename);
|
|
return response()->json(['sent' => 'yes', 'filename' => '/storage/'.$filename]);
|
|
} else {
|
|
Mail::to( $response->data->user->email )->send(new ReportExcel($data));
|
|
return response()->json(['sent' => 'yes']);
|
|
}
|
|
|
|
} else {
|
|
$colors = ['FECD00', '01C14B', 'FF8050', '4A5CD0', '707070'];
|
|
$post = array_merge((array)$response->data->post,$post);
|
|
if(isset($post['metrics']) ) {
|
|
$post['metrics'] = explode(',', $post['metrics']);
|
|
}
|
|
return view('metricreport.appreport')->with(['periods' => $response->data->periods, 'charts' => $response->data->available_charts, 'graph' => $response->data->graph, 'post' => $post, 'colors' => $colors, 'breadcrumbs' => $breadcrumbs]);
|
|
}
|
|
}
|
|
|
|
public function metriclist(Request $request) {
|
|
$post = $request->input();
|
|
$token = $request->header('Authorization');
|
|
if($token != '') {
|
|
$request->session()->put('metric_access_key', $token);
|
|
} else {
|
|
$token = $request->session()->get('metric_access_key');
|
|
}
|
|
$reports = LambdaRequest::getrequest('metric', 'metric_report/list', $post, $token);
|
|
//echo '<pre>'; print_r($reports); exit;
|
|
//$reports = $this->getlambda('get', 'metric', 'metric_report', 'list');
|
|
return view('metricreport.appreportlist')->with(['metrics' => $reports->data->metrics]);
|
|
|
|
}
|
|
|
|
public function preview(Request $request) {
|
|
$data = $request->input('data');
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/preview', ['data' => $data]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
$formdata = $finfo->data->formdata;
|
|
$formdata->user_info = $finfo->data->user_info;
|
|
$formdata->link_type = 'form';
|
|
$formdata->is_approval = 'yes';
|
|
$formdata->title = $finfo->data->formdata->form_name;
|
|
if (\View::exists('form.'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->form_id)->with(['questions' => $finfo->data->questions, 'form' => $formdata, 'id' => $finfo->data->formdata->submission_id, 'form_id' => $finfo->data->formdata->form_id ]);
|
|
} else {
|
|
return view('form.common')->with(['questions' => $finfo->data->questions, 'form' => $formdata, 'id' => $finfo->data->formdata->submission_id, 'form_id' => $finfo->data->formdata->form_id ]);
|
|
}
|
|
}
|
|
|
|
protected function deliverpersonalization($formdata, $questions, $personalizations) {
|
|
$additional_info = $this->get_additional_info($formdata);
|
|
//echo '<pre>'; print_r($formdata); print_r($questions); print_r($personalizations); exit;
|
|
$data = ['questions' => $questions, 'form' => $formdata, 'form_id' => $formdata->form_id, 'personalizations' => $personalizations ];
|
|
if(sizeof($additional_info) > 0) {
|
|
$data['additional'] = $additional_info;
|
|
}
|
|
if (\View::exists('form.'.$formdata->partition.'.personalization-'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->partition.'.personalization-'.$formdata->form_id)->with($data);
|
|
} elseif (\View::exists('form.personalization-'.$formdata->form_id)) {
|
|
return view('form.personalization-'.$formdata->form_id)->with($data);
|
|
} else {
|
|
return view('form.personalization')->with($data);
|
|
}
|
|
}
|
|
|
|
public function submitpersonalized(Request $request) {
|
|
$post = $request->except('_token');
|
|
$files = $request->file();
|
|
$images = [];
|
|
foreach($files as $fname => $file) {
|
|
$post[$fname] = $this->_uploadMediaLocal($request, $fname, 'public/personalized/'.$post['form_id'].'/'.$fname);
|
|
$images[] = $fname;
|
|
}
|
|
if(isset($post['cropped'])) {
|
|
foreach($post['cropped'] as $name => $cropp) {
|
|
if(isset($cropp) && !empty($cropp)) {
|
|
$data = explode( ',', $cropp );
|
|
$image = base64_decode( $data[1] );
|
|
$filename = strtotime("now").'-'.Str::random(64).'.png';
|
|
Storage::disk('public')->put('personalized/'.$post['form_id'].'/'.$name.'/'.$filename, $image);
|
|
$post[$name] = '/storage/personalized/'.$post['form_id'].'/'.$name.'/'.$filename;
|
|
$post['cropped-'.$name] = $post[$name];
|
|
}
|
|
//$form_info['cropped-'.$name] = '/storage/personalized/'.$post['form_id'].'/'.$name.'/'.$filename;
|
|
}
|
|
unset($post['cropped']);
|
|
}
|
|
$post['images_fields'] = $images;
|
|
$post['form_info'] = json_decode($post['form_info']);
|
|
$request->session()->put('form_info', $post);
|
|
|
|
return response()->json($post);
|
|
}
|
|
|
|
public function submitpersonalizedimages(Request $request) {
|
|
$post = $request->except('_token');
|
|
$formdata = $request->session()->get('formdata');
|
|
$form_info = $request->session()->get('form_info');
|
|
//echo '<pre>'; print_r($post); print_r($form_info); echo '</pre>'; exit;
|
|
foreach($form_info['images_fields'] as $im ) {
|
|
Log::debug(print_r($im, true));
|
|
$data = explode( ',', $post[$im] );
|
|
$image = base64_decode( $data[1] );
|
|
$filename = pathinfo($form_info[$im]);
|
|
$filename = $filename['basename'];
|
|
Storage::disk('public')->put('personalized/'.$post['form_id'].'/'.$im.'/cropped-'.$filename, $image);
|
|
$form_info['cropped-'.$im] = str_replace($filename, 'cropped-'.$filename, $form_info[$im]);
|
|
}
|
|
$request->session()->put('form_info', $form_info);
|
|
return redirect('/form/generatepersonalization');
|
|
}
|
|
|
|
public function generatepersonalization(Request $request) {
|
|
$post = $request->all();
|
|
$formdata = $request->session()->get('formdata');
|
|
$form_info = $request->session()->get('form_info');
|
|
|
|
//echo '<pre>'; print_r($post); print_r($form_info); echo '</pre>'; exit;
|
|
$genareted_image = [];
|
|
$pdf_images = [];
|
|
foreach($form_info['form_info']->templates as $i => $template) {
|
|
$temp = pathinfo($template);
|
|
if(!file_exists(storage_path('app/public/personalized/'.$form_info['form_id'].'/template-'.$form_info['form_info']->id.'_'.$i.'.'.$temp['extension'] ))) {
|
|
//Log::debug(print_r($form_info['form_info'], true));
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $template);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks!
|
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image.
|
|
$data = curl_exec($ch);
|
|
curl_close($ch);
|
|
Storage::disk('public')->put('personalized/'.$form_info['form_id'].'/template-'.$form_info['form_info']->id.'_'.$i.'.'.$temp['extension'], $data);
|
|
}
|
|
|
|
$folder = storage_path('app/public/personalized/'.$form_info['form_id']);
|
|
$templatename = 'template-'.$form_info['form_info']->id.'_'.$i.'.'.$temp['extension'];
|
|
$outputImage = $this->retimage($folder.'/'.$templatename);
|
|
|
|
//echo '<pre>'; print_r(json_decode($form_info['form_info']->positions[$i])); echo '</pre>'; exit;
|
|
$positions = json_decode($form_info['form_info']->positions[$i]);
|
|
$maskimages = [];
|
|
foreach($positions as $pos) {
|
|
if($pos->type == 'image' && isset($pos->fill) && $pos->fill == 'mask') {
|
|
$maskimages[] = $pos;
|
|
}
|
|
}
|
|
if(sizeof($maskimages) > 0) {
|
|
$w = imagesx($outputImage);
|
|
$h = imagesy($outputImage);
|
|
$tempimage = imagecreatetruecolor($w, $h);
|
|
}
|
|
foreach($maskimages as $pos) {
|
|
$image = storage_path( str_replace('/storage', 'app/public', $form_info['cropped-'.$pos->field_name] ) );
|
|
$photoimg = $this->retimage( $image );
|
|
$photosize = getimagesize( $image );
|
|
imagecopyresized($tempimage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
}
|
|
if(sizeof($maskimages) > 0) {
|
|
imagecopyresized($tempimage,$outputImage,0,0,0,0,$w,$h,$w,$h);
|
|
$outputImage = $tempimage;
|
|
}
|
|
foreach(json_decode($form_info['form_info']->positions[$i]) as $pos) {
|
|
switch($pos->type) {
|
|
case 'image':
|
|
// $image = storage_path( str_replace('/storage', 'app/public', $form_info['cropped-'.$pos->field_name] ) );
|
|
// $photoimg = $this->retimage( $image );
|
|
// $photosize = getimagesize( $image );
|
|
// if(isset($pos->fill) && $pos->fill == 'mask') {
|
|
// // $w = imagesx($outputImage);
|
|
// // $h = imagesy($outputImage);
|
|
// // $tempimage = imagecreatetruecolor($w, $h);
|
|
// // imagecopyresized($tempimage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
// // imagecopyresized($tempimage,$outputImage,0,0,0,0,$w,$h,$w,$h);
|
|
// // $outputImage = $tempimage;
|
|
// // //imagedestroy($tempimage);
|
|
// } else {
|
|
// $image = storage_path( str_replace('/storage', 'app/public', $form_info['cropped-'.$pos->field_name] ) );
|
|
// $photoimg = $this->retimage( $image );
|
|
// $photosize = getimagesize( $image );
|
|
// imagecopyresized($outputImage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
// }
|
|
if(!(isset($pos->fill) && $pos->fill == 'mask')) {
|
|
$image = storage_path( str_replace('/storage', 'app/public', $form_info['cropped-'.$pos->field_name] ) );
|
|
$photoimg = $this->retimage( $image );
|
|
$photosize = getimagesize( $image );
|
|
imagecopyresized($outputImage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
}
|
|
break;
|
|
case 'text':
|
|
case 'date':
|
|
if(isset($form_info[$pos->field_name])) {
|
|
$font = storage_path('app').'/fonts/'.$pos->font;
|
|
$pos->color = explode('-',$pos->color);
|
|
$white = imagecolorallocate($outputImage, $pos->color[0], $pos->color[1], $pos->color[2]);
|
|
$text = $form_info[$pos->field_name];
|
|
if(isset($pos->prefix) && !empty($pos->prefix)) {
|
|
$text = $pos->prefix . $text;
|
|
}
|
|
if($pos->type == 'date') {
|
|
$text = date($pos->format, strtotime($text));
|
|
}
|
|
if(isset($pos->suffix) && !empty($pos->suffix)) {
|
|
$text = $text . $pos->suffix;
|
|
}
|
|
if(isset($pos->align) && $pos->align == 'center') {
|
|
$box = imagettfbbox($pos->size, 0, $font, $text);
|
|
$pos->x = explode('-', $pos->x);
|
|
$pos->x = $pos->x[0] + (($pos->x[1] - $pos->x[0]) - $box[2])/2;
|
|
}
|
|
imagettftext($outputImage, $pos->size, 0, $pos->x, $pos->y, $white, $font, $text);
|
|
}
|
|
break;
|
|
|
|
case 'multiline':
|
|
if(isset($form_info[$pos->field_name])) {
|
|
$font = storage_path('app').'/fonts/'.$pos->font;
|
|
$pos->color = explode('-',$pos->color);
|
|
$white = imagecolorallocate($outputImage, $pos->color[0], $pos->color[1], $pos->color[2]);
|
|
$text = $form_info[$pos->field_name];
|
|
$lines = wordwrap($text, $pos->linechars, "\n", true);
|
|
$xPosition = $pos->x;
|
|
$yPosition = $pos->y;
|
|
foreach (explode("\n", $lines) as $line) {
|
|
imagettftext($outputImage, $pos->size, 0, $xPosition, $yPosition, $white, $font, $line);
|
|
$yPosition += $pos->linehieght;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
$filename = 'generated-'.strtotime("now").'_'.$i.'.png';
|
|
$genareted_image[] = $filename;
|
|
if(isset($form_info['form_info']->createpdf[$i]) && $form_info['form_info']->createpdf[$i] == 'yes') {
|
|
$pdf_images[] = $folder.'/'.$filename;
|
|
}
|
|
imagepng($outputImage, $folder.'/'.$filename);
|
|
imagedestroy($outputImage);
|
|
}
|
|
|
|
$form_info['genareted_image'] = $genareted_image;
|
|
$form_info['pdf_images'] = $pdf_images;
|
|
|
|
if(isset($form_info['form_info']->createpdf) && count($form_info['form_info']->createpdf) > 0 && in_array('yes', $form_info['form_info']->createpdf) ) {
|
|
//echo 'convert '.implode(' ', $form_info['pdf_images']).' -quality 100 '.$folder.'/'.'combined-'.strtotime("now").'.pdf'; exit;
|
|
$pdffile = 'combined-'.strtotime("now").'.pdf';
|
|
exec('convert '.implode(' ', $form_info['pdf_images']).' -quality 100 '.$folder.'/'.$pdffile);
|
|
$form_info['pdf_file'] = $pdffile;
|
|
}
|
|
$form_info['personalization_id'] = $form_info['form_info']->id;
|
|
//Log::debug(print_r($form_info, true));
|
|
//echo '<pre>'; print_r($form_info); echo '</pre>'; exit;
|
|
unset($form_info['form_info']);
|
|
|
|
// $form_info['form_info']->positions = json_decode('[{"x":"100-279","y":"485","align":"center","size":20,"type":"text","font":"klavika-medium.ttf","color":"110-23-19","field_name":"event_date_date"},{"x":"100-279","y":"526","align":"center","size":22,"type":"text","font":"klavika-light.ttf","color":"110-23-19","field_name":"event_date_year"},{"x":"340-514","y":"485","align":"center","size":20,"type":"text","font":"klavika-medium.ttf","color":"110-23-19","field_name":"venue_line_3"},{"x":"584-767","y":"480","align":"center","size":18,"type":"text","font":"klavika-medium.ttf","color":"110-23-19","field_name":"venue_line_1"},{"x":"584-767","y":"508","align":"center","size":18,"type":"text","font":"klavika-medium.ttf","color":"110-23-19","field_name":"venue_line_2"},{"x":"584-767","y":"535","align":"center","size":18,"type":"text","font":"klavika-medium.ttf","color":"110-23-19","field_name":"venue_line_3"},{"x":"264-613","y":"910","align":"center","size":11,"type":"text","font":"gadugib.ttf","color":"0-0-0","field_name":"speaker_details_line_1"},{"x":"264-613","y":"930","align":"center","size":11,"type":"text","font":"gadugib.ttf","color":"0-0-0","field_name":"speaker_details_line_2"},{"x":"264-613","y":"950","align":"center","size":11,"type":"text","font":"gadugib.ttf","color":"0-0-0","field_name":"speaker_details_line_3"},{"x":"264-613","y":"970","align":"center","size":11,"type":"text","font":"gadugib.ttf","color":"0-0-0","field_name":"speaker_details_line_4"},{"x":362,"width":154,"y":658,"type":"image","fill":"mask","height":154,"field_name":"speaker_image"},{"x":"259-618","y":"873","align":"center","size":23,"type":"text","font":"klavika-medium.ttf","color":"255-255-255","field_name":"speaker_name"}]');
|
|
|
|
|
|
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
$post = $this->processformdata($formdata->form_id, $post, $formdata->user_id, $formdata->partition);
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $form_info, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
}
|
|
//return view('form.download')->with('image_url', 'personalized/'.$form_info['form_id'].'/'.$form_info['genareted_image']);
|
|
|
|
$request->session()->put('form_info', $form_info);
|
|
return redirect('/form/downloadpersonalization');
|
|
}
|
|
|
|
public function downloadpersonalization(Request $request) {
|
|
$form_info = $request->session()->get('form_info');
|
|
$formdata = $request->session()->get('formdata');
|
|
//Log::debug(print_r($form_info, true));
|
|
//Log::debug(print_r($formdata, true));
|
|
$folder = storage_path('app/public/personalized/'.$form_info['form_id']);
|
|
|
|
$paths = [];
|
|
if(isset($form_info['pdf_file'])) {
|
|
$paths[] = $folder.'/'.$form_info['pdf_file'];
|
|
}
|
|
foreach($form_info['genareted_image'] as $image) {
|
|
$paths[] = $folder.'/'.$image;
|
|
}
|
|
|
|
if($form_info['form_id'] == '1682181475-19f5d784-6fbb-4a6e-bf04-a448ff7c83fe') {
|
|
switch($form_info['personalization_id']) {
|
|
case '1682267328-bd38fe94-1b2e-47c1-a8bb-8ba361432cc7':
|
|
$ppts[] = ["path" => '/ChestApprise/Home_Maintenance_Nebulization_Regional.pptx', "name" => 'Home_Maintenance_Nebulization_Regional.pptx' ];
|
|
$ppts[] = ["path" => '/ChestApprise/Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx', "name" => 'Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx' ];
|
|
break;
|
|
case '1682267328-bd38fe95-1b2e-47c2-a8bb-8ba361432cc8':
|
|
$ppts[] = ["path" => '/ChestConnect/Home_Maintenance_Nebulization_Regional.pptx', "name" => 'Home_Maintenance_Nebulization_Regional.pptx' ];
|
|
$ppts[] = ["path" => '/ChestConnect/Nb_Antibiotic_focusing_Tob.pptx', "name" => 'Nb_Antibiotic_focusing_Tob.pptx' ];
|
|
break;
|
|
case '1682267328-bd38fe96-1b2e-47c3-a8bb-8ba361432cc9':
|
|
$ppts[] = ["path" => '/EducatetoElevate/GINA_2022_Imp_of_ICS_in_asthma.pptx', "name" => 'GINA_2022_Imp_of_ICS_in_asthma.pptx' ];
|
|
$ppts[] = ["path" => '/EducatetoElevate/Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx', "name" => 'Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx' ];
|
|
break;
|
|
case '1682267328-bd38fe97-1b2e-47c4-a8bb-8ba361432cc6':
|
|
$ppts[] = ["path" => '/PediaConnect/GINA_2022_Pediatric_brief.pptx', "name" => 'GINA_2022_Pediatric_brief.pptx' ];
|
|
$ppts[] = ["path" => '/PediaConnect/Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx', "name" => 'Nebulized_mucoactive_drugs_in_mucus_management_-_2023.pptx' ];
|
|
break;
|
|
case '1682685456-f9dce443-bcee-462f-925e-ad148dad08f4':
|
|
$ppts[] = ["path" => '/Assemble/Assemble_to_Adapt_ppt.pptx', "name" => 'Assemble_to_Adapt_ppt.pptx' ];
|
|
break;
|
|
}
|
|
foreach($ppts as $ppt) {
|
|
$paths[] = $folder.'/'.$ppt['path'];
|
|
}
|
|
}
|
|
|
|
if($request->input('action') == 'email') {
|
|
// Create PHPMailer instance
|
|
$provider = CredentialProvider::defaultProvider();
|
|
$gAWS_SES_client = SesClient::factory(array(
|
|
'version'=> 'latest',
|
|
'region' => 'ap-south-1',
|
|
'credentials' => $provider
|
|
));
|
|
|
|
|
|
//$myArrayToAdresses = ["ravigulhane1983@gmail.com"];
|
|
Log::debug(print_r($request->all(), true) );
|
|
$myArrayToAdresses = [$request->input('email')];
|
|
|
|
$ppts = [];
|
|
$ppthtml = '';
|
|
|
|
if($form_info['form_id'] == '1682181475-19f5d784-6fbb-4a6e-bf04-a448ff7c83fe') {
|
|
foreach($ppts as $ppt) {
|
|
$ppthtml .= '<a href="https://stage.buildrapport.co/storage/personalized/1682181475-19f5d784-6fbb-4a6e-bf04-a448ff7c83fe' .$ppt['path'].'" download>'.$ppt['name'].'</a><br />';
|
|
}
|
|
}
|
|
|
|
|
|
$myFromAdress = 'Rapport Support <virtualengage@stratawiz.com>';
|
|
$mySubject = 'Generated Assets for Upcoming Event';
|
|
$myHTMLBody = '<p>Dear,</p>
|
|
<p>We hope this email finds you well. As part of our commitment to making our upcoming event a success, we are pleased to provide you with a few generated assets that we believe will be useful.</p>
|
|
<p>Attached to this email you will find:</p>
|
|
<ul>
|
|
<li>Invitations: We have included a customized invitation that you can share with your attendees. It includes all the details of the event.</li>
|
|
<li>Thank You Letter: We have also attached a thank you letter that you can use to express your gratitude to attendees and sponsors after the event.</li>
|
|
<li>Presentation PPT: Lastly, we have included a presentation PowerPoint that you can use to promote the event or share with your attendees. below are the links to download the PPT.</li>
|
|
</ul>
|
|
<p>
|
|
' . $ppthtml . '
|
|
</p>
|
|
<p>We believe that these assets will help you to promote the event more effectively and engage with your network more successfully. If you have any questions or concerns, please dont hesitate to reach out to your HO.</p>
|
|
<p>Thank you for your time and effort in organizing this event, and we look forward to working with you to make it a success.</p>
|
|
<p>Best regards,</p>';
|
|
|
|
$files = [ ["path" => $folder.'/'.$form_info['pdf_file'], "name" => $form_info['pdf_file'] ] ];
|
|
foreach($form_info['genareted_image'] as $image) {
|
|
$files[] = ["path" => $folder.'/'.$image, "name" => $image ];
|
|
}
|
|
|
|
// $zip = new \ZipArchive();
|
|
// $fileName = 'zipFile.zip';
|
|
// exec('rm ' . $folder.'/'.$fileName);
|
|
// if ($zip->open($folder.'/'.$fileName, \ZipArchive::CREATE)== TRUE){
|
|
// //$files = File::files(public_path('myFiles'));
|
|
// foreach ($files as $file){
|
|
// $zip->addFile($file['path'], $file['name']);
|
|
// }
|
|
// $zip->close();
|
|
// }
|
|
$myStringToAddresses = implode(",", $myArrayToAdresses);
|
|
|
|
$boundary = md5(time());
|
|
$html = $myHTMLBody;
|
|
//$html .= "<img src=\"cid:{$fileName}\">"; // Content-ID
|
|
$text = $mySubject;
|
|
|
|
$raw = '';
|
|
$raw .= "From:{$myFromAdress}\n";
|
|
$raw .= "To:{$myStringToAddresses}\n";
|
|
$raw .= "Subject:{$mySubject}\n";
|
|
$raw .= "MIME-Version: 1.0\n";
|
|
$raw .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n\n";
|
|
$raw .= "--{$boundary}\n";
|
|
|
|
$raw .= "Content-Type: multipart/alternative; boundary=\"sub_{$boundary}\"\n\n";
|
|
$raw .= "--sub_{$boundary}\n";
|
|
$raw .= "Content-Type: text/plain; charset=\"UTF-8\"\n";
|
|
$raw .= "\n";
|
|
$raw .= "{$text}\n";
|
|
$raw .= "\n";
|
|
$raw .= "--sub_{$boundary}\n";
|
|
$raw .= "Content-Type: text/html; charset=\"UTF-8\"\n";
|
|
$raw .= "Content-Disposition: inline\n";
|
|
$raw .= "\n";
|
|
$raw .= "{$html}\n";
|
|
$raw .= "\n";
|
|
$raw .= "--sub_{$boundary}--\n\n";
|
|
|
|
foreach ($files as $file) {
|
|
$myFileMimeInfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
$myFileMimeType = finfo_file($myFileMimeInfo, $file['path']);
|
|
$myFileName = basename($file['path']);
|
|
$myDataAttachedFile = file_get_contents($file['path']);
|
|
//$myDataAttachedFile = chunk_split(base64_encode($myDataAttachedFile));
|
|
$raw .= "--{$boundary}\n";
|
|
$raw .= "Content-Type:{$myFileMimeType}; name=\"{$file['name']}\"\n"; // name
|
|
$raw .= "Content-Transfer-Encoding:base64\n";
|
|
$raw .= "Content-Disposition:attachment;filename=\"{$file['name']}\"\n"; // filename
|
|
#$raw .= "Content-Disposition:inline;name={$file_name}\n";
|
|
$raw .= "Content-ID:<{$file['name']}>\n";
|
|
$raw .= "\n";
|
|
$raw .= base64_encode($myDataAttachedFile) . "\n";
|
|
$raw .= "\n";
|
|
}
|
|
$raw .= "--{$boundary}--\n\n";
|
|
|
|
|
|
|
|
// $myStringToAddresses = implode(",", $myArrayToAdresses);
|
|
// $mySeparator = md5(time());
|
|
// $mySeparator_multipart = md5($mySubject . time());
|
|
|
|
// $myMessage = "";
|
|
|
|
// $myMessage .= "MIME-Version: 1.0\n";
|
|
|
|
// $myMessage .= "To: ".$myStringToAddresses."\n";
|
|
// $myMessage .= "From:".$myFromAdress."\n";
|
|
// $myMessage .= "Subject:".$mySubject."\n";
|
|
|
|
// $myMessage .= "Content-Type: multipart/mixed; boundary=\"".$mySeparator_multipart."\"\n";
|
|
// $myMessage .= "\n--".$mySeparator_multipart."\n";
|
|
|
|
// $myMessage .= "Content-Type: multipart/alternative; boundary=\"".$mySeparator."\"\n";
|
|
// $myMessage .= "\n--".$mySeparator."\n";
|
|
|
|
// $myMessage .= "Content-Type: text/html; charset=\"UTF-8\"\n";
|
|
// $myMessage .= "\n".$myHTMLBody."\n";
|
|
// $myMessage .= "\n--".$mySeparator."--\n";
|
|
|
|
// $myFileName = basename($folder.'/'.$fileName);
|
|
// $myDataAttachedFile = file_get_contents($folder.'/'.$fileName);
|
|
// $myDataAttachedFile = chunk_split(base64_encode($myDataAttachedFile));
|
|
|
|
// $myFileMimeInfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
// $myFileMimeType = finfo_file($myFileMimeInfo, $folder.'/'.$fileName);
|
|
|
|
// $myMessage .= "--".$mySeparator_multipart."\n";
|
|
// $myMessage .= "Content-Type: ".$myFileMimeType."; name=\"".$myFileName."\"\n";
|
|
// $myMessage .= "Content-Disposition: attachment; filename=\"".$myFileName."\"\n";
|
|
// $myMessage .= "Content-Transfer-Encoding: base64\n\n";
|
|
// $myMessage .= $myDataAttachedFile."\n";
|
|
// $myMessage .= "--".$mySeparator_multipart."--";
|
|
|
|
|
|
$myArraySES = [
|
|
'Source' => $myFromAdress,
|
|
'Destinations' => $myArrayToAdresses,
|
|
'RawMessage' => [
|
|
'Data' => $raw
|
|
]
|
|
];
|
|
|
|
//echo "\n<HR>Trying to send mail via AAWS SES <BR>\n";
|
|
|
|
|
|
try{
|
|
//$myResult = true;
|
|
$myAPIResult = $gAWS_SES_client->sendRawEmail($myArraySES);
|
|
Log::debug(print_r($myAPIResult, true));
|
|
return response()->json(['status' => 'success']);
|
|
} catch (Exception $myObjError) {
|
|
//An error happened and the email did not get sent
|
|
$myErrorInfo = $myObjError->getMessage();
|
|
Log::debug(print_r($myErrorInfo, true));
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
//return response()->json(['status' => 'success']);
|
|
} else {
|
|
//echo '<prE>';print_r($form_info); exit;
|
|
$res = ['folder' => 'personalized/'.$form_info['form_id'].'/', 'images' => $form_info['genareted_image'] ];
|
|
$res['form_info'] = $form_info;
|
|
if(isset($form_info['pdf_file'])) {
|
|
$res['pdf_file'] = $form_info['pdf_file'];
|
|
}
|
|
if($form_info['form_id'] == '1682181475-19f5d784-6fbb-4a6e-bf04-a448ff7c83fe') {
|
|
$encripted = base64_encode(json_encode($paths));
|
|
$res['encripted'] = $encripted;
|
|
}
|
|
if (\View::exists('form.'.$formdata->partition.'.download-'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->partition.'.download-'.$formdata->form_id)->with($res);
|
|
} else {
|
|
return view('form.download')->with($res);
|
|
}
|
|
}
|
|
//return view('form.download')->with($res);
|
|
}
|
|
|
|
public function downloadtempletepdf(Request $request) {
|
|
$post = $request->all();
|
|
$id = $post['id'];
|
|
$formdata = $request->session()->get('formdata');
|
|
$finfo = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition, 'id' => $id ]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
foreach($finfo->data->personalizations as $pers) {
|
|
if($pers->id == $finfo->data->formdata->personalization_id) {
|
|
$personalisation = $pers;
|
|
}
|
|
}
|
|
|
|
$genareted_image = [];
|
|
$pdf_images = [];
|
|
foreach($personalisation->templates as $i => $template) {
|
|
$temp = pathinfo($template);
|
|
if(!file_exists(storage_path('app/public/personalized/'.$formdata->form_id.'/template-'.$personalisation->id.'_'.$i.'.'.$temp['extension'] ))) {
|
|
//Log::debug(print_r($form_info['form_info'], true));
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $template);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks!
|
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image.
|
|
$data = curl_exec($ch);
|
|
curl_close($ch);
|
|
Storage::disk('public')->put('personalized/'.$formdata->form_id.'/template-'.$personalisation->id.'_'.$i.'.'.$temp['extension'], $data);
|
|
}
|
|
|
|
$folder = storage_path('app/public/personalized/'.$formdata->form_id);
|
|
$templatename = 'template-'.$personalisation->id.'_'.$i.'.'.$temp['extension'];
|
|
$outputImage = $this->retimage($folder.'/'.$templatename);
|
|
$templatesize = getimagesize( $folder.'/'.$templatename );
|
|
$pdfparams = ["width"=>$templatesize[0],"height"=>$templatesize[1]];
|
|
|
|
//echo '<pre>'; print_r($templatesize); echo '</pre>'; exit;
|
|
$positions = json_decode($personalisation->positions[$i]);
|
|
$maskimages = [];
|
|
foreach($positions as $pos) {
|
|
if($pos->type == 'image' && isset($pos->fill) && $pos->fill == 'mask') {
|
|
$maskimages[] = $pos;
|
|
}
|
|
}
|
|
if(sizeof($maskimages) > 0) {
|
|
$w = imagesx($outputImage);
|
|
$h = imagesy($outputImage);
|
|
$tempimage = imagecreatetruecolor($w, $h);
|
|
}
|
|
foreach($maskimages as $pos) {
|
|
$image = storage_path( str_replace('/storage', 'app/public', $finfo->data->formdata->{$pos->field_name} ) );
|
|
$photoimg = $this->retimage( $image );
|
|
$photosize = getimagesize( $image );
|
|
imagecopyresized($tempimage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
}
|
|
if(sizeof($maskimages) > 0) {
|
|
imagecopyresized($tempimage,$outputImage,0,0,0,0,$w,$h,$w,$h);
|
|
$outputImage = $tempimage;
|
|
}
|
|
foreach(json_decode($personalisation->positions[$i]) as $pos) {
|
|
// if($pos->field_name == 'link') {
|
|
// $pdfparams['link_params_x'] = $pos->x;
|
|
// $pdfparams['link_params_y'] = $pos->y;
|
|
// $pdfparams['link_params_url'] = $finfo->data->formdata->{$pos->field_name};
|
|
// continue;
|
|
// }
|
|
switch($pos->type) {
|
|
case 'image':
|
|
if(!(isset($pos->fill) && $pos->fill == 'mask')) {
|
|
$image = storage_path( str_replace('/storage', 'app/public', $finfo->data->formdata->{$pos->field_name} ) );
|
|
$photoimg = $this->retimage( $image );
|
|
$photosize = getimagesize( $image );
|
|
imagecopyresized($outputImage,$photoimg,$pos->x,$pos->y,0,0,$pos->width,$pos->height, $photosize[0], $photosize[1]);
|
|
}
|
|
break;
|
|
case 'text':
|
|
case 'date':
|
|
if(isset($finfo->data->formdata->{$pos->field_name})) {
|
|
$font = storage_path('app').'/fonts/'.$pos->font;
|
|
$pos->color = explode('-',$pos->color);
|
|
$white = imagecolorallocate($outputImage, $pos->color[0], $pos->color[1], $pos->color[2]);
|
|
$text = $finfo->data->formdata->{$pos->field_name};
|
|
if(isset($pos->prefix) && !empty($pos->prefix)) {
|
|
$text = $pos->prefix . $text;
|
|
}
|
|
if($pos->type == 'date') {
|
|
$text = date($pos->format, strtotime($text));
|
|
}
|
|
if(isset($pos->suffix) && !empty($pos->suffix)) {
|
|
$text = $text . $pos->suffix;
|
|
}
|
|
if(isset($pos->align) && $pos->align == 'center') {
|
|
$box = imagettfbbox($pos->size, 0, $font, $text);
|
|
$pos->x = explode('-', $pos->x);
|
|
$pos->x = $pos->x[0] + (($pos->x[1] - $pos->x[0]) - $box[2])/2;
|
|
}
|
|
imagettftext($outputImage, $pos->size, 0, $pos->x, $pos->y, $white, $font, $text);
|
|
}
|
|
break;
|
|
|
|
case 'multiline':
|
|
if(isset($finfo->data->formdata->{$pos->field_name})) {
|
|
$font = storage_path('app').'/fonts/'.$pos->font;
|
|
$pos->color = explode('-',$pos->color);
|
|
$white = imagecolorallocate($outputImage, $pos->color[0], $pos->color[1], $pos->color[2]);
|
|
$text = $form_info[$pos->field_name];
|
|
$lines = wordwrap($text, $pos->linechars, "\n", true);
|
|
$xPosition = $pos->x;
|
|
$yPosition = $pos->y;
|
|
foreach (explode("\n", $lines) as $line) {
|
|
imagettftext($outputImage, $pos->size, 0, $xPosition, $yPosition, $white, $font, $line);
|
|
$yPosition += $pos->linehieght;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
$filename = 'generated-'.strtotime("now").'_'.$i.'.png';
|
|
$genareted_image[] = $filename;
|
|
|
|
imagepng($outputImage, $folder.'/'.$filename);
|
|
imagedestroy($outputImage);
|
|
|
|
$res = ['folder' => 'personalized/'.$formdata->form_id.'/', 'images' => $genareted_image, 'form_info' => (array)$finfo->data->formdata ];
|
|
if (\View::exists('form.'.$formdata->partition.'.download-'.$formdata->form_id)) {
|
|
return view('form.'.$formdata->partition.'.download-'.$formdata->form_id)->with($res);
|
|
} else {
|
|
return view('form.download')->with($res);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function downloadpersonalizationzip($files, Request $request) {
|
|
$post = $request->input();
|
|
$files = json_decode(base64_decode($files));
|
|
|
|
$folder = storage_path('app/public/personalized');
|
|
$zip = new \ZipArchive();
|
|
$fileName = 'assets.zip';
|
|
exec('rm ' . $folder.'/'.$fileName);
|
|
if ($zip->open($folder.'/'.$fileName, \ZipArchive::CREATE)== TRUE){
|
|
//$files = File::files(public_path('myFiles'));
|
|
foreach ($files as $file){
|
|
$zip->addFile($file, basename($file));
|
|
}
|
|
$zip->close();
|
|
}
|
|
|
|
return response()->download($folder.'/'.$fileName);
|
|
|
|
// echo '<prE>'; print_r($files); exit;
|
|
}
|
|
|
|
public function downloaddata(Request $request) {
|
|
$formdata = $request->session()->get('formdata');
|
|
//$request->session()->put('finfo', $finfo);
|
|
$post = $request->all();
|
|
$form_id = $request->input('form_id', $formdata->form_id);
|
|
if(($form_id == '1718178830-d871301e-312b-4a60-9c68-15afa4ce6163' && (in_array('1655449173-a39a5017-8232-4d58-a253-90d06bc733d0', $formdata->roles) || in_array('1655449172-a39a5017-8232-4d58-a253-90d06bc733d0', $formdata->roles) || in_array('1655449171-a39a5017-8232-4d58-a253-90d06bc733d0', $formdata->roles) ) ) ||
|
|
(($form_id == '1713425460-8bdf7394-01b5-48f3-8985-343b465dd685' || $form_id == '1713426268-c89f38eb-ec32-43ba-a81b-b690a8f90d6a') && (in_array('1655449175-a39a5017-8232-4d58-edm-90d06bc733d0', $formdata->roles) || in_array('1655445669-148e5dc2-3983-4ec6-bfho-a52c494a92132', $formdata->roles) || in_array('1655449179-a39a5017-8232-4d58-rbm-90d06bc733d0', $formdata->roles) ) ) ) {
|
|
$finfo = $request->session()->get('finfo');
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getforminfo', ['finfo' => $finfo]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
} else {
|
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition, 'team_report' => 1 ]);
|
|
}
|
|
Log::debug(print_r($formdata, true));
|
|
//echo '<pre>'; print_r($history); exit;
|
|
$exceldata = [];
|
|
$exceldata[] = [$formdata->title];
|
|
|
|
$exceldata[] = [''];
|
|
$headers = ['Submission Date', 'Submitted By', 'Approval Status'];
|
|
foreach($history->data->questions as $question) {
|
|
$headers[] = $question->label;
|
|
}
|
|
$exceldata[] = $headers;
|
|
foreach($history->data->submissions as $submission) {
|
|
$row = [];
|
|
$row[] = $submission->createdAt;
|
|
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
|
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
|
foreach($history->data->questions as $q => $v) {
|
|
$row[] = isset($submission->formdata->{$q}) ? $submission->formdata->{$q} : '-';
|
|
}
|
|
$exceldata[] = $row;
|
|
}
|
|
|
|
if(isset($post['email']) && $post['email'] == 1) {
|
|
$report = Excel::raw(new InvoicesExport($exceldata), 'Xlsx');
|
|
$data = new \StdClass;
|
|
$data->sender_name = 'Rapport Support';
|
|
$data->sender_email = 'support@stratawiz.com';
|
|
$data->subject = 'Attached Report';
|
|
$data->body = '';
|
|
$data->attachment = $report;
|
|
$data->attachment_name = 'report.xlsx';
|
|
|
|
Mail::to( $history->data->user_details->email )->send(new ReportExcel($data));
|
|
|
|
response()->json(['status' => 'success']);
|
|
} else {
|
|
return Excel::download(new InvoicesExport($exceldata), $formdata->title.'.xlsx');
|
|
}
|
|
|
|
|
|
|
|
//echo $report;
|
|
// Excel::create($formdata->title, function($excel) {
|
|
// $excel->sheet('Form Data', function($sheet) {
|
|
// $sheet->fromArray($exceldata);
|
|
// });
|
|
// });
|
|
|
|
|
|
// Excel::create(new InvoicesExport($exceldata), 'public/'.$filename)->download('xlsx');
|
|
|
|
// $report = Excel::raw(new InvoicesExport($exceldata), 'Xlsx');
|
|
// $data->attachment = $report;
|
|
// $data->attachment_name = 'report.xlsx';
|
|
|
|
// //Mail::to( str_replace(Auth::user()->domain.'-','', Auth::user()->email) )->send(new ReportExcel($data));
|
|
// //Mail::to( 'ravigulhane1983@gmail.com' )->send(new ReportExcel($data));
|
|
// if($s3) {
|
|
// $filename = 'reports/'.strtotime("now").'-report.xlsx';
|
|
// $res = Excel::store(new InvoicesExport($exceldata), 'public/'.$filename);
|
|
// Log::debug(print_r($res, true));
|
|
// Log::debug('/storage/'.$filename);
|
|
// return response()->json(['sent' => 'yes', 'filename' => '/storage/'.$filename]);
|
|
// } else {
|
|
// Mail::to( $response->data->user->email )->send(new ReportExcel($data));
|
|
// return response()->json(['sent' => 'yes']);
|
|
// }
|
|
|
|
|
|
|
|
// echo '<pre>'; print_r($history); print_r($formdata); exit;
|
|
|
|
// $form_id = $request->input('form_id', '');
|
|
// echo $form_id; exit;
|
|
}
|
|
|
|
protected function retimage($image) {
|
|
$size = getimagesize($image);
|
|
switch ($size['mime']) {
|
|
case 'image/jpeg':
|
|
$photoimg = imagecreatefromjpeg($image);
|
|
break;
|
|
case 'image/png':
|
|
$photoimg = imagecreatefrompng($image);
|
|
break;
|
|
case 'image/jpeg':
|
|
$photoimg = imagecreatefrompng($image);
|
|
break;
|
|
default:
|
|
# code...
|
|
break;
|
|
}
|
|
return $photoimg;
|
|
}
|
|
|
|
public function getdoctorlist(Request $request) {
|
|
$response = LambdaRequest::getrequest('contact', 'contact/get_my_contacts', ['hierarchy' => $request->input('hierarchy', ''), 'partition' => $request->input('partition', '') ]);
|
|
$docs = [];
|
|
foreach($response->data->items as $item) {
|
|
$docs[] = ['value' => $item->id, 'display' => $item->name, 'contact' => $item];
|
|
}
|
|
return response()->json($docs);
|
|
}
|
|
|
|
|
|
public function surveyhandle($finfo, Request $request) {
|
|
$request->session()->put('finfo', $finfo);
|
|
$finfo = LambdaRequest::postrequest('form', 'survey/getforminfo', ['finfo' => $finfo]);
|
|
// echo '<pre>'; print_r($finfo); exit;
|
|
$request->session()->put('formdata', $finfo->data->formdata);
|
|
if($finfo->status == 'success' && $finfo->data->formdata->link_type == 'form') {
|
|
//return $this->deliverform($finfo->data->formdata, $finfo->data->questions);
|
|
$formdata = $finfo->data->formdata;
|
|
$questions = $finfo->data->questions;
|
|
$data = ['questions' => $questions, 'form' => $formdata, 'form_id' => $formdata->form_id, 'id' => false];
|
|
if (\View::exists('srvey.'.$formdata->partition.'.'.$formdata->form_id)) {
|
|
return view('srvey.'.$formdata->partition.'.'.$formdata->form_id)->with($data);
|
|
} elseif (\View::exists('form.'.$formdata->form_id)) {
|
|
return view('srvey.'.$formdata->form_id)->with($data);
|
|
} else {
|
|
// return $data;
|
|
return view('srvey.common')->with($data);
|
|
}
|
|
|
|
} elseif($finfo->status == 'success' && $finfo->data->formdata->link_type == 'list') {
|
|
//echo '<pre>'; print_r($finfo->data); exit;
|
|
if (\View::exists('survey.list-'.$finfo->data->formdata->form_id)) {
|
|
return view('srvey.list-'.$finfo->data->formdata->form_id)->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey ]);
|
|
} else {
|
|
return view('srvey.list')->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey ]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function ajaxsurveysubmit(Request $request) {
|
|
$post = $request->except('_token');
|
|
$files = $request->file();
|
|
foreach($files as $fname => $file) {
|
|
$post[$fname] = $this->_uploadMedia($request, $fname, 'form/'.$post['form_id'].'/'.$fname);
|
|
}
|
|
if(isset($post['id']) && $post['id']=='') unset($post['id']);
|
|
$formdata = $request->session()->get('formdata');
|
|
if(isset($post['user_id']) && $post['user_id'] != '') {
|
|
$formdata->user_id = $post['user_id'];
|
|
}
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
$post = $this->processformdata($formdata->form_id, $post, $formdata->user_id, $formdata->partition);
|
|
$finfo = LambdaRequest::postrequest('form', 'survey/submitform', ['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
|
|
if($formdata->form_id == '1674212914-9f377f34-4762-4b40-team3-8b282d183332') {
|
|
unset($post['form_id']);
|
|
Log::debug(print_r($post, true));
|
|
//echo '<pre>'; print_r($post); exit;
|
|
$handler = curl_init();
|
|
curl_setopt($handler, CURLOPT_URL, "https://gnpdoctor.buildrapport.co/neblogisticsave/ciplatodoctor");
|
|
curl_setopt($handler, CURLOPT_POSTFIELDS, http_build_query($post));
|
|
curl_setopt($handler, CURLOPT_POST, 1);
|
|
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
|
|
$response = curl_exec($handler);
|
|
Log::debug(print_r($response, true));
|
|
}
|
|
if($formdata->form_id == '1711710347-b4f08442-60dc-4a4c-a9c7-a759d95c5cad') {
|
|
unset($post['form_id']);
|
|
Log::debug(print_r($post, true));
|
|
$handler = curl_init();
|
|
curl_setopt($handler, CURLOPT_URL, "https://gnpdoctor.buildrapport.co/neblogisticsave/faultynebulizer");
|
|
curl_setopt($handler, CURLOPT_POSTFIELDS, http_build_query($post));
|
|
curl_setopt($handler, CURLOPT_POST, 1);
|
|
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
|
|
$response = curl_exec($handler);
|
|
Log::debug(print_r($response, true));
|
|
}
|
|
|
|
if($finfo->status == 'success') {
|
|
return response()->json(['status' => 'success']);
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
}
|
|
|
|
|
|
public function quizhandle($finfo, Request $request) {
|
|
$request->session()->put('finfo', $finfo);
|
|
$finfo = LambdaRequest::postrequest('form', 'quiz/getforminfo', ['finfo' => $finfo]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
$request->session()->put('formdata', $finfo->data->formdata);
|
|
if($finfo->status == 'success' && $finfo->data->formdata->link_type == 'form') {
|
|
//return $this->deliverform($finfo->data->formdata, $finfo->data->questions);
|
|
$formdata = $finfo->data->formdata;
|
|
$questions = $finfo->data->questions;
|
|
$data = ['questions' => $questions, 'form' => $formdata, 'form_id' => $formdata->form_id, 'id' => false];
|
|
if (\View::exists('quiz.'.$formdata->partition.'.'.$formdata->form_id)) {
|
|
return view('quiz.'.$formdata->partition.'.'.$formdata->form_id)->with($data);
|
|
} elseif (\View::exists('quiz.'.$formdata->form_id)) {
|
|
return view('quiz.'.$formdata->form_id)->with($data);
|
|
} else {
|
|
// return $data;
|
|
return view('quiz.common')->with($data);
|
|
}
|
|
|
|
} elseif($finfo->status == 'success' && $finfo->data->formdata->link_type == 'list') {
|
|
//echo '<pre>'; print_r($finfo->data); exit;
|
|
if (\View::exists('quiz.list-'.$finfo->data->formdata->form_id)) {
|
|
return view('quiz.list-'.$finfo->data->formdata->form_id)->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey ]);
|
|
} else {
|
|
return view('quiz.list')->with(['questions' => $finfo->data->questions, 'submissions' => $finfo->data->submissions, 'formname' => $finfo->data->formdata->title, 'form_id' => $finfo->data->formdata->form_id, 'lastkey' => $finfo->data->lastkey ]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function ajaxquizsubmit(Request $request) {
|
|
$post = $request->except('_token');
|
|
$formdata = $request->session()->get('formdata');
|
|
//print_r($formdata); exit;
|
|
|
|
|
|
if(isset($post['user_id']) && $post['user_id'] != '') {
|
|
$formdata->user_id = $post['user_id'];
|
|
}
|
|
if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') {
|
|
// echo '<pre>'; print_r(['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]); exit;
|
|
|
|
|
|
$finfo = LambdaRequest::postrequest('form', 'quiz/submitform', ['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
|
//echo '<pre>'; print_r($finfo); exit;
|
|
if($finfo->status == 'success') {
|
|
return response()->json(['status' => 'success', 'submission' => $finfo->data->submission]);
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
} else {
|
|
return response()->json(['status' => 'failure']);
|
|
}
|
|
}
|
|
|
|
public function zipmultiple(Request $request) {
|
|
$files = $request->input('files', []);
|
|
$response = LambdaRequest::postrequest('form', 'formentity/zipmultiple', ['files' => $files], '');
|
|
//Log::debug(print_r($response, true));
|
|
return response()->json($response->data);
|
|
}
|
|
|
|
|
|
public function competitioncontest(Request $request) {
|
|
$token = $request->header('Authorization');
|
|
if($token != '') {
|
|
$request->session()->put('metric_access_key', $token);
|
|
} else {
|
|
$token = $request->session()->get('metric_access_key');
|
|
}
|
|
|
|
$page = $request->input('page', 'scores');
|
|
switch($page) {
|
|
case 'scores':
|
|
$response = LambdaRequest::getrequest('competition', 'contest/list', ['scores' => 'yes'], $token);
|
|
return view('competition.appcontest', ['title' => 'Live Scores', 'scores' => $response->data->items, 'page' => $page]);
|
|
break;
|
|
case 'schedule':
|
|
$response = LambdaRequest::getrequest('competition', 'contest/list', [], $token);
|
|
return view('competition.appcontest', ['title' => 'Schedule', 'schedules' => $response->data->items, 'page' => $page]);
|
|
break;
|
|
case 'table':
|
|
$response = LambdaRequest::getrequest('ums', 'team/list', [], $token);
|
|
return view('competition.appcontest', ['title' => 'Points Table', 'teams' => $response->data->items, 'page' => $page]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function iframeupload(Request $request) {
|
|
return view('form.iframeupload');
|
|
}
|
|
|
|
public function allsubmissions(Request $request) {
|
|
$post = $request->all();
|
|
$user = Auth::user();
|
|
$history = LambdaRequest::signedrequest('post', 'form', 'formentity/getallsubmissions', ['form_id' => $post['form_id'], 'partition' => $post['partition']], 120);
|
|
|
|
if(isset($post['download'])) {
|
|
$exceldata = [];
|
|
$headers = ['User Name','User Email','User Phone', 'Submitted On'];
|
|
foreach($history->data->questions as $que) {
|
|
$headers[] = $que->question;
|
|
}
|
|
$exceldata[] = $headers;
|
|
$submissions = json_decode(file_get_contents( $history->data->submission_json ), false);
|
|
foreach($submissions as $sub) {
|
|
$subs = [$sub->submitted_by, $sub->user_email, $sub->user_phone, $sub->submitted_on];
|
|
foreach($history->data->questions as $que) {
|
|
$subs[] = $sub->{$que->code};
|
|
}
|
|
$exceldata[] = $subs;
|
|
}
|
|
$report = Excel::raw(new InvoicesExport($exceldata), 'Xlsx');
|
|
$filename = 'reports/'.$post['form_id'].'-report.xlsx';
|
|
$res = Excel::store(new InvoicesExport($exceldata), 'public/'.$filename);
|
|
$headers = array( 'Content-Type: application/excel', );
|
|
return Response::download(storage_path('app/public')."/".$filename, $post['form_id'].'-report.xlsx', $headers);
|
|
} else {
|
|
//echo '<pre>'; print_r((array)$history->data); exit;
|
|
if (\View::exists('form.'.$post['partition'].'.'.$post['form_id'].'-allsubmissions')) {
|
|
return view('form.'.$post['partition'].'.'.$post['form_id'].'-allsubmissions')->with((array)$history->data);
|
|
} elseif (\View::exists('form.'.$post['form_id'].'-allsubmissions')) {
|
|
return view('form.'.$post['form_id'].'-allsubmissions')->with((array)$history->data);
|
|
} else {
|
|
return view('form.allsubmissions')->with((array)$history->data);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function fullworkflow(Request $request) {
|
|
$post = $request->all();
|
|
$user = Auth::user();
|
|
$history = LambdaRequest::signedrequest('post', 'form', 'formentity/getallsubmissions', ['form_id' => $post['form_id'], 'approver' => Auth::user()->user_id, 'partition' => $post['partition']], 120);
|
|
//echo '<pre>'; print_r($history); exit;
|
|
if(isset($post['download'])) {
|
|
$exceldata = [];
|
|
$headers = ['User Name','User Email','User Phone', 'Submitted On'];
|
|
foreach($history->data->questions as $que) {
|
|
$headers[] = $que->question;
|
|
}
|
|
$exceldata[] = $headers;
|
|
$submissions = json_decode(file_get_contents( $history->data->submission_json ), false);
|
|
foreach($submissions as $sub) {
|
|
$subs = [$sub->submitted_by, $sub->user_email, $sub->user_phone, $sub->submitted_on];
|
|
foreach($history->data->questions as $que) {
|
|
$subs[] = $sub->{$que->code};
|
|
}
|
|
$exceldata[] = $subs;
|
|
}
|
|
$report = Excel::raw(new InvoicesExport($exceldata), 'Xlsx');
|
|
$filename = 'reports/'.$post['form_id'].'-report.xlsx';
|
|
$res = Excel::store(new InvoicesExport($exceldata), 'public/'.$filename);
|
|
$headers = array( 'Content-Type: application/excel', );
|
|
return Response::download(storage_path('app/public')."/".$filename, $post['form_id'].'-report.xlsx', $headers);
|
|
} else {
|
|
//echo '<pre>'; print_r((array)$history->data); exit;
|
|
if (\View::exists('form.'.$post['partition'].'.'.$post['form_id'].'-fullworkflow')) {
|
|
return view('form.'.$post['partition'].'.'.$post['form_id'].'-fullworkflow')->with((array)$history->data);
|
|
} elseif (\View::exists('form.'.$post['form_id'].'-fullworkflow')) {
|
|
return view('form.'.$post['form_id'].'-fullworkflow')->with((array)$history->data);
|
|
} else {
|
|
return view('form.fullworkflow')->with((array)$history->data);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function uploadchunk(Request $request) {
|
|
$path = '';
|
|
$name = 'chunk_video';
|
|
$folder = 'chunk_video';
|
|
try {
|
|
if( $request->file($name) ) {
|
|
$path = $request->file($name)->store($folder);
|
|
$path = '/'.str_replace('public', 'storage', $path);
|
|
}
|
|
} catch (AwsException $e) {
|
|
Log::debug($e->getMessage());
|
|
}
|
|
return response()->json(['status' => 'success', 'filepath' => $path ]);
|
|
return $path;
|
|
}
|
|
|
|
|
|
} |