87c06fcf by prami

store and fetch output report

1 parent 0d07fdc6
......@@ -2,12 +2,21 @@
namespace App\Http\Controllers;
use Auth;
use Input;
use Response;
use Config;
use App\Models\OutputReport;
use App\Models\OutputProduct;
use App\Models\CRMCall;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Requests;
class VirtualController extends Controller
class OutputReportController extends Controller
{
/**
* Display a listing of the resource.
......@@ -24,9 +33,9 @@ class VirtualController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function create()
public function createOutputReport()
{
//
}
/**
......@@ -37,7 +46,42 @@ class VirtualController extends Controller
*/
public function store(Request $request)
{
//
$action=Input::get('action');
//echo $action;
if($action=="createOutputReport"){
$products = $request->input('products');
//print_r($products);
//$totalIncome = 0;
foreach ($products as $key => $value) {
$outputReport = OutputReport::firstOrCreate(
array(
'product_id' => $value['productId']
)
);
$outputReport->user_id = Auth::user()->id;
$outputReport->date = date("Y-m-d");
$outputReport->call_attempts = $request->input('noOfAttempts');
$outputReport->call_contacts = $request->input('noOfContacts');
$outputReport->call_unique_contacts =$request->input('uniqueContacts');
// $totalIncome = $totalIncome + ($value['lc'] * $value['lcAmt']);
if($value['lc'] != '' && $value['lcAmt'] != ''){
$outputReport->income = $value['lc'] * $value['lcAmt'];
}
$outputReport->product_name = $value['product'];
$outputReport->lead_generated = $value['lg'];
$outputReport->lead_generated_amount = $value['lgAmt'];
$outputReport->lead_closed = $value['lc'];
$outputReport->lead_closed_amount = $value['lcAmt'];
$outputReport->created_at = date('Y-m-d H:i:s');
$outputReport->updated_at =date('Y-m-d H:i:s');
$outputReport->save();
}
}
}
/**
......@@ -48,13 +92,30 @@ class VirtualController extends Controller
*/
public function show($id)
{
if($id=="Virtualdata")
if($id=="reportdata")
{
$products = DB::table('output_products')->select('id','name','status')->get();
return view("layout.module.virtualchannel.Virtualdata")->with('products', $products);
// output reports
$products = DB::table('output_products')
->select('output_products.id as productId','output_products.name','output_products.status', 'output_report.product_id', 'output_report.id as reportId', 'output_report.lead_generated', 'output_report.lead_generated_amount', 'output_report.lead_closed' , 'output_report.lead_closed_amount' )
->leftJoin('output_report', 'output_products.id', '=', 'output_report.product_id')
->where('status', '1')
->orderBy('output_products.id')
->get();
// total income
$totalIncome = DB::select("select sum(income) as income from output_report where user_id=".Auth::user()->id);
// noOfAttempts
$noOfAttempts = CRMCall::where('userstatus','!=','InboundDROP')->where('created_at','>',date('Y-m-d',time()))->where('user_id','=',Auth::user()->id)->count();
$noOfContacts = CRMCall::where('userstatus','NOT IN',"('NORECORD','InboundDROP')")->where('created_at','>',date('Y-m-d',time()))->where('user_id','=',Auth::user()->id)->count();
$uniqueContacts = DB::select("select count(distinct(number)) as uniquecount from crmcalls where userstatus NOT IN ('InboundDROP','NORECORD') and user_id=".Auth::user()->id);
return view("layout.module.outputreport.outputreport")->with('data', ['products' => $products, 'totalIncome' => $totalIncome[0]->income, 'noOfAttempts' => $noOfAttempts , 'noOfContacts' => $noOfContacts , 'uniqueContacts' => $uniqueContacts]);
}
return view("layout.module.virtualchannel.$id",array());
return view("layout.module.outputreport.$id",array());
}
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OutputProduct extends Model{
protected $table = 'output_products';
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OutputReport extends Model{
protected $table = 'output_report';
protected $fillable = ['user_id', 'user_name', 'date', 'call_attempts', 'call_contacts', 'call_unique_contacts', 'income', 'product_id' , 'product_name', 'lead_generated', 'lead_generated_amount', 'lead_closed', 'lead_closed_amount', 'created_at', 'updated_at'];
}
\ No newline at end of file
<?php
use App\Models\CRMCall;
use App\Models\User;
use App\Jobs\KHRMSLib;
$attempts = CRMCall::where('userstatus','!=','InboundDROP')->where('created_at','>',date('Y-m-d',time()))->where('user_id','=',Auth::user()->id)->count();
print_r(($attempts));
$Contacts = CRMCall::where('userstatus','NOT IN',"('NORECORD','InboundDROP')")->where('created_at','>',date('Y-m-d',time()))->where('user_id','=',Auth::user()->id)->count();
$uniqueContacts = DB::select("select count(distinct(number)) as uniquecount from crmcalls where userstatus NOT IN ('InboundDROP','NORECORD') and user_id=".Auth::user()->id." group by number");
/**
Output Products
**/
//$Product = DB::table('output_products')->select('id','name','status')->where('status', '1')->get();
//print_r($Product);
//print_r($uniqueContacts);
//include(resource_path().'/views/layout/module/virtualchannel/VirtualFieldsArray.php');
//print_r($Product);
//echo "<div>Virtual</div>";
?>
<div class="container">
<div style="text-align:center">
<h2>Virtual Channels</h2>
<h2>Output Report</h2>
<p></p>
</div>
<div class="row">
<div class="column">
<form class="form-horizontal">
<form class="form-horizontal" id="output-report" name="output-report">
<div class="table-responsive" style="background: #fff;">
<table class="table">
<thead>
<tr>
<th>No.of Attempts</th>
<th><?php echo $attempts; ?></th>
<th><?php echo $data['noOfAttempts']; ?>
<input type="hidden" name="noOfAttempts" value="<?php echo $data['noOfAttempts']; ?>">
</th>
</tr>
<tr>
<th>No.of Contacts</th>
<th><?php echo $Contacts; ?></th>
<th><?php echo $data['noOfContacts']; ?>
<input type="hidden" name="noOfContacts" value="<?php echo $data['noOfContacts']; ?>">
</th>
</tr>
<tr>
<th>Unique Contacts</th>
<th><?php foreach($uniqueContacts as $uniquecounts){echo $uniquecounts->uniquecount; } ?></th>
<th><?php $data['uniqueContacts'] ?>
<input type="hidden" name="uniqueContacts" value="<?php $data['uniqueContacts'] ?>">
</th>
</tr>
<tr>
<th>Income Achievement</th>
<th></th>
<th><?php echo $data['totalIncome']; ?></th>
</tr>
<tr>
<th>Product</th>
......@@ -60,19 +44,23 @@ $uniqueContacts = DB::select("select count(distinct(number)) as uniquecount from
<tbody>
<?php
//include(resource_path().'/views/layout/module/virtualchannel/VirtualFieldsArray.php');
foreach ($products as $key => $value) {
$i=1;
foreach ($data['products'] as $key => $value) {
//print_r($value);
//print_r($ProductType);
$i=1;
?>
<tr>
<td><?php echo $value->name; ?></td>
<td><input type="number" name="lg[<?php echo $value->name; ?>]"></td>
<td><input type="text" name="lg-amt[<?php echo $value->name; ?>]"></td>
<td><input type="number" name="lc[<?php echo $value->name; ?>]"></td>
<td><input type="text" name="lc-amt[<?php echo $value->name; ?>]"></td>
<td> <input type="hidden" name="products[<?= $i ?>][productId]" value="<?php echo $value->productId; ?>">
<input type="hidden" name="products[<?= $i ?>][product]" value="<?php echo $value->name; ?>" ><?php echo $value->name; ?></td>
<td><input type="number" name="products[<?= $i ?>][lg]" value="<?php echo $value->lead_generated; ?>"></td>
<td><input type="number" min="0" step="0.01" name="products[<?= $i ?>][lgAmt]" value="<?php echo $value->lead_generated_amount; ?>"></td>
<td><input type="number" name="products[<?= $i ?>][lc]" value="<?php echo $value->lead_closed; ?>"></td>
<td><input type="number" min="0" step="0.01" name="products[<?= $i ?>][lcAmt]" value="<?php echo $value->lead_closed_amount; ?>"></td>
</tr>
<?php
$i++;
} ?>
<tr>
......@@ -87,21 +75,20 @@ $uniqueContacts = DB::select("select count(distinct(number)) as uniquecount from
function createOutputReport()
{
var putdata="csrftoken={!!Session::token()!!}";
putdata+="&lc="+$("#lc").val();
doAjax('user',putdata,'__fake__div__','ajax_users_create','singlethis','POST',function(retstr)
{
if(retstr.responseText.indexOf('Error')<0)
{
simpleNotification("success","topRight","User Created Successfully");
doAjax('user/'+retstr.responseText+'/edit','','userformdiv','ajax_users_create','singlethis','GET');
}
else
{
simpleNotification("error","topRight",retstr.responseText);
}
});
var putdata = $('#output-report').serialize();
//console.log("--->"+putdata);
doAjax('outputreport?action=createOutputReport',putdata,'__fake__div__','ajax_create_output_report','singlethis','POST',function(retstr)
{
if(retstr.responseText.indexOf('Error')<0)
{
simpleNotification("success","topRight","User Created Successfully");
menuAction('outputreport/reportdata');
}
else
{
simpleNotification("error","topRight",retstr.responseText);
}
});
}
</script>
......
<?php
//Here array is Productname=>array(LG,ExpectedAmt,LC,Amount)
/*$Product = array('Term'=>array('','','',''),'SmartPay'=> array('' , 'NA', '','NA' ),'BillPay'=>array('','NA','','NA'),'BillPay+SI'=>array('','NA','','NA'),'CC LE'=>array('','NA','','NA'),'CC Upgrade'=>array('','NA','','NA'),'PL10Sec'=>array('','','',''),'Quick Money'=>array('','','',''),'Jaldi5'=>array('','','',''),'GI'=>array('','','',''),'MF'=>array('','','',''),'FD/RD'=>array('','','',''),'LI'=>array('','','',''),'AL'=>array('','','',''),'PL-CRM'=>array('','','',''),'PL-DAP'=>array('','','',''),'HL'=>array('','','',''),'Other Assets'=>array('','','',''),'DEMAT'=>array('','NA','','NA'),'CDL'=>array('','','',''),'CC-Fresh'=>array('','NA','','NA'),'CC-STP'=>array('','NA','','NA'),'CASA'=>array('','NA','','NA'),'PayZapp Registration'=>array('','NA','','NA'));*/
?>
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!