Yii2 rendering in a specific div - php

I'm using Yii2-advanced-template. I've 2 divisions on my form as follows - When I'll click on any of the radio button in 2nd div, the details of respective entry should be loaded in 1st div. That is, the form in 1st div will remain as is, but loads some values for update operation. But I'm getting it as - which is not what I expect. It is loading the whole page layout in that div.
I already used 'renderPartial()' in my controller. But it solved only the half of the problem, that is, the navigation bar & other layout is hidden after using renderPartial().
My form is as follows-
<div class="col-sm-12">
<div class="col-sm-6 fillitemform">
...
Enter Item Details form
...
</div>
<div id="item_details" class="col-sm-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Item details</h3>
</div>
<div class="panel-body">
<div class="table-responsive" >
<table class="table">
<thead>
<tr><th></th>
<th>PO No.</th>
<th>SKU</th>
<th>Order Type</th>
<th>Expected Qty</th>
<th>Received Qty</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
<?php
for($itr = 0, $ro = $modelRO, $rod = $modelROD; $itr < count($modelROD); ++$itr){
echo '<tr onclick="placeitemdtls('.$rod[$itr]['id'].')">';
echo '<td><input type="radio" name="item"></td>';
echo '<td>'.$ro[0]['ro_po_no'].'</td>';
echo '<td>'.$rod[$itr]['rod_sku'].'</td>';
echo '<td>'.$ro[0]['ro_order_type_id'].'</td>';
echo '<td>'.$rod[$itr]['rod_expected_qty'].'</td>';
echo '<td>'.$rod[$itr]['rod_received_qty'].'</td>';
echo '<td>'.$rod[$itr]['rod_weight'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
My JS/jQuery function-
function placeitemdtls(id){
$.post("index.php?r=receiving-order-details/update&id="+id, function(response) {
jQuery(".fillitemform").html(response);
});
}
My Controller function-
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelRO = ReceivingOrders::find()->where(['id' => $id])->all();
$modelROD = ReceivingOrderDetails::find()->where(['receiving_order_id' => $id])->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['create', 'id' => $id]);
} else {
return $this->renderPartial('update', [
'model' => $model, 'modelRO' => $modelRO, 'modelROD' => $modelROD,
]);
}
}
Please note that, I'm getting the correct form with proper values, but having rendering problem as I showed in 2nd image. Please help me to solve it. So that my output should look like -

Related

Get the the average of the data in laravel

I have two eloquent tables, vendor and work, in the work table there is a total score column and I want to get the average of the total score based on the vendor ID (foreign Key) and save it to the vendor table. May I know how to achieve this?
Here is my vendor table blade file
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Tabel Penilaian Penyedia</h3>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive">
<table id="tabelpenyedia" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px">No.</th>
<th>Nama Penyedia</th>
<th>Nilai</th>
<th style="width: 120px">Aksi</th>
</tr>
</thead>
<tbody>
#php $no = 1; #endphp
#foreach ($penyedia as $penyedias)
<tr>
<td>{{$no++}}</td>
<td>{{$penyedias->nama}}</td>
<td></td>
<td>
Beri Penilaian
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
</section>
Here is the AdminController
public function update_nilaipekerjaan(Request $request, $id){
$pekerjaan = Pekerjaan::find($id);
//$pekerjaan->update($request->all());
//$total = Pekerjaan::select(DB::raw('avg(nilai_1 + nilai_2 + nilai_3 + nilai_4) as nilai_total'))->get();
$pekerjaan->nilai_1=$request->nilai_1;
$pekerjaan->nilai_2=$request->nilai_2;
$pekerjaan->nilai_3=$request->nilai_3;
$pekerjaan->nilai_4=$request->nilai_4;
$pekerjaan->nilai_total=$request->nilai_1+$request->nilai_2+$request->nilai_3+$request->nilai_4;
$pekerjaan->update();
return redirect()->back()->with('message','Nilai Pekerjaan Berhasil diupdate!');
}
public function tabelnilai_penyedia(){
$penyedia = Penyedia::all();
$pekerjaan = Pekerjaan::all();
return view('admin.datanilai_penyedia', compact('penyedia', 'pekerjaan'));
} //I WANT TO SHOW THE AVERAGE OF THE TOTAL SCORE HERE.
Database https://imgur.com/a/N6NlcwJ
Here is what I want to achieve https://imgur.com/a/fk4Yq92
what I have tried
updating the AdminController
public function tabelnilai_penyedia($id){
$penyedia = Penyedia::all();
$pekerjaan = Pekerjaan::all();
$average = Pekerjaan::where('penyedia_id', $id)->avg('nilai_total');
Penyedia::where('id', $id)->update(['nilai'=>$average]);
return view('admin.datanilai_penyedia', compact('penyedia', 'pekerjaan'));
}
But it got me an error,
Too few arguments to function App\Http\Controllers\AdminController::tabelnilai_penyedia(), 0 passed in C:\Users\ASUS TUF\webpenyedia\vendor\laravel\framework\src\Illuminate\Routing\Controller.php on line 54 and exactly 1 expected
You can use the MySQL AVG function to get the average of a column, which in Eloquent is neatly wrapped in an aggregate function
Assuming your models are called "Work" and "Vendor"
// Get average of 'nilai' based on Vendor ID
$average = Work::where('penyedia_id', $vendorId) // Assuming this is the right column
->avg('nilai_total');
// Update Vendor directly in database (No model events)
Vendor::where('id', $vendorId)->update(['nilai' => $average]);

Get Entity's ID in Datastore PHP API

Is there a way to get the entity's ID/Key using PHP Datastore API?
I've already authenticated everything and I'm able to get the values, but no the ID
Here's my code:
<?php
$title = "Builder | Makeroid Account";
include "../assets/includes/head.php";
if (!$USER->is_logged_in()) {
$USER->redirect('/');
}
require_once __DIR__.'/../assets/libs/datastore/vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Query\Query;
$datastore = new DatastoreClient([
'projectId' => 'makeroid-builder'
]);
$query = $datastore->query();
$query->kind('UserData');
$query->filter('emaillower', '=', $U_DATA['email']);
$users = $datastore->runQuery($query);
$params = ["email", "emailFrequency", "emaillower", "isAdmin", "link", "name", "sessionid", "settings", "templatePath", "tosAccepted", "type", "upgradedGCS"];
?>
<div class="content">
<div class="container-fluid">
<div class="row">
<?php foreach ($users as $user) { ?>
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-icon" data-background-color="rose">
<i class="material-icons">assignment</i>
</div>
<div class="card-content">
<h4 class="card-title">User Properties</h4>
<div class="table-responsive">
<table class="table">
<thead class="text-primary">
<th>Key</th>
<th>Value</th>
</thead>
<tbody>
<?php print_r($user); foreach ($params as $param) { ?>
<tr>
<td><?=$param?></td>
<td><?=$user?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include "../assets/includes/footer.php"; ?>
I would like to get this:
I'm able to get all values that are in the rows, such us my email, but I hadn't found a way to get that ID
I've tried by using $user['id'], $user['key'] or $user['__key__'] but none of them worked
You'll need to pull the key from the entity (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/entity?method=key) then pull the id from the key (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/key) with something like $key->pathEndIdentifier().
So instead of trying to pull the key out of object as a dictionary value, try pulling it out as a method. $user->key()->pathEndIdentifier() .

dompdf isn't working in laravel

I have make a html view page for generate to a pdf report from this view and i have also installed dompdf library, i have loaded data from database table on this view and create a hyperlink name as Download pdf. but when i click on this link it's show undefined variable dsale error.
here my controller method.
//pass data to view
public function dsreport($id,$fromdate,$todate)
{
$dsale=DB::table('directsales')
->join('clients','directsales.client_id','=','clients.id')
->join('products','directsales.product_id','=','products.id')
->select('clients.client_name','clients.addr','directsales.*','products.name')
->where('directsales.client_id','=',$id)
->whereBetween('directsales.issue_date',[$fromdate,$todate])
->distinct()
->paginate(3);
//->get();
$sumt=DB::table('directsales')
->where('directsales.client_id','=',$id)
->sum('directsales.total');
return view('reports.directsalereport',compact(['dsale','sumt']));
}
//generate pdf
public function dsalepdf()
{
$pdf=PDF::loadView('reports.directsalereport');
return $pdf->download('dsread.pdf');
}
Here is my view part.
<div class="panel-body">
<center><h1><strong>M/s. Priti Enterprise</strong></h1></center>
</center>
<center><h2><i>Daily Sales Report</i></h2></center>
<div class="row">
<div class="col-md-4"><strong>Client Name: {{$dsale[0]->client_name}}</strong></div>
<div class="col-md-4"></div>
<div class="col-md-4"><strong>Delivered by: {{$dsale[0]->deliverd_by}}</strong></div>
</div><br>
<div class="row">
<div class="col-md-4"><strong>Client address: {{$dsale[0]->addr}}</strong></div>
<div class="col-md-4"></div>
<div class="col-md-4"><strong>Date: {{$dsale[0]->issue_date}}</strong></div>
</div><br><br>
<table class="table table-bordered">
<thead>
<th class="col-md-1">SL no.</th>
<th>Product Name</th>
<th>Invoice no.</th>
<th>Unit per ctn.</th>
<th>Unit price</th>
<th class="col-md-2">Sales</th>
<th>Value</th>
</thead>
<tbody>
#foreach($dsale as $d)
<tr>
<td>#</td>
<td>{{$d->name}}</td>
<td>{{$d->transaction_code}}</td>
<td>{{$d->unitperctn}}</td>
<td>{{$d->unitprice}}</td>
<td>{{$d->ctn}} ctn {{$d->pcs}} pcs</td>
<td>{{$d->total}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="col-md-11"></div>
<div class="row"><strong>Total:{{$sumt}}</strong></div>
<div>{{$dsale->links()}}</div>
<div class="col-md-8"></div>
<div class="row">
<i class=" glyphicon glyphicon-ok"></i> Download PDF
</div>
</div>
You have an array in compact.
You should use <div>{{$dsale[0]->links()}}</div>.
I think you should dont compact an array.
return view('reports.directsalereport',compact('dsale','sumt'));
Edited:
You should pass data to your Pdf view, too, so your method for downloading pdf should look like this.
public function dsalepdf()
{
$dsale=DB::table('directsales')
->join('clients','directsales.client_id','=','clients.id')
->join('products','directsales.product_id','=','products.id')
->select('clients.client_name','clients.addr','directsales.*','products.name')
->where('directsales.client_id','=',$id)
->whereBetween('directsales.issue_date',[$fromdate,$todate])
->distinct()
->paginate(3);
$sumt=DB::table('directsales')
->where('directsales.client_id','=',$id)
->sum('directsales.total');
$pdf=PDF::loadView('reports.directsalereport',['dsale' => $dsale,'sumt'=> $sumt]);
return $pdf->download('dsread.pdf');
}
You may need to delete the vendor folder, then run composer install

Datatable - Server side data is not displaying

I am playing with datatable with Laravel 5 with first time so I tried with this code and I am getting data on ajax but not able to display data on my datatable.
Any Idea how to load response data to datatable.
Here is my structure:
Result:
Route:
Route::get('admin/pages/datatable', 'admin\PagesController#getDataTable'); // Pages (Static Pages)
pages.blade.php:
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Pages Table</h3>
</div><!-- /.box-header -->
<div class="box-body">
<table id="example32" class="table table-bordered table-hover">
<thead>
<tr>
<th>PageId</th>
<th>Title</th>
<th>Text</th>
<th>MetaKeywords</th>
<th>MetaDescription</th>
<th>PostedBy</th>
</tr>
</thead>
<tfoot>
<tr>
<th>PageId</th>
<th>Title</th>
<th>Text</th>
<th>MetaKeywords</th>
<th>MetaDescription</th>
<th>PostedBy</th>
</tr>
</tfoot>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.row -->
</section><!-- /.content -->
PagesController.php:
public function getDataTable()
{
$Pages = new Pages();
return $GetAllPages = $Pages->GetPages();
}
Pages.php:
public function GetPages()
{
return DB::table('pages')->select('PageId', 'Title', 'Text', 'MetaKeywords', 'MetaDescription', 'PostedBy')
->get();
}
You have to pass an indexed array instead of associative. Your response should be like
{['pageid', 'Title', 'Text', ... ]}
Just need to follow the correct column order.
May be you can use,
public function GetPages()
{
$pages = DB::table('pages')->select('PageId', 'Title', 'Text', 'MetaKeywords', 'MetaDescription', 'PostedBy')->get();
$pages = $pages->map(function($item){
return [$item->PageId, $item->Title,$item->Text,$item->MetaKeywords,$item->MetaDescription, $item->PostedBy ];
});
return $pages;
}

keep data in codeigniter without flash data

I created a management system in codeigniter that loads data from the database in datatables for specific suppliers. When the user clicks at any of these data rows he is navigating to each supplier's company products. My problem is that I want to find a session or something else that will keep the data of the previous selected rows when the page reloads. At the moment I am using flashdata but when I go back a step or return to the previous page all the data from the database disappear. What I want is something that will keep my data even if I am reloading the page or if I go back a step.
That's my controller:
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('dash_match_model');
$this->session->keep_flashdata('supplier_id');
$this->session->keep_flashdata('segment');
$this->session->keep_flashdata('class');
$this->session->keep_flashdata('commodity');
$this->load->library('session');
$this->load->helper('url');
}
public function index() {
$arr['page']='dash1';
$user_id = $this->session->userdata('id');
$supplier = $this->dash_match_model->dash_present_all_suppliers($user_id);
$arr['dash_present_all_suppliers'] = $supplier;
$this->load->view('clients/clDashboard',$arr);
}
public function select_supplier()
{
$supplier_name = $this->input->get('name', TRUE);
$supplier_sel = $this->dash_match_model->selected_supplier_id($supplier_name);
foreach ($supplier_sel->result() as $row){
$this->session->set_flashdata('supplier_id', $row->supplier_id);
}
$selected_supplier = $this->dash_match_model->unspsc_matched_skus($this->session->flashdata('supplier_id'));
$arr['dash_present_all_selected_suppliers'] = $selected_supplier;
$this->load->view('clients/unspscSegment', $arr);
}
public function select_segment(){
$segment = $this->input->get('segment', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$this->session->set_flashdata('segment', $segment);
$segment_sel =$this->session->flashdata('segment');
$selected_segment = $this->dash_match_model->unspsc_class($supplier_id, $segment_sel);
$arr['dash_present_all_selected_segments'] = $selected_segment;
$this->load->view('clients/unspscClass', $arr);
}
public function select_class(){
$class = $this->input->get('class', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$segment_sel =$this->session->flashdata('segment');
$this->session->set_flashdata('class', $class);
$class_sel = $this->session->flashdata('class');
$selected_class =$this->dash_match_model->unspsc_commodity($supplier_id, $segment_sel, $class_sel);
$arr['dash_present_all_selected_class'] = $selected_class;
$this->load->view('clients/unsspscCommodity', $arr);
That's one of my first table view file with suppliers:
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header" data-original-title>
<div class="box-icon">
<i class="halflings-icon wrench"></i>
<i class="halflings-icon chevron-up"></i>
<i class="halflings-icon remove"></i>
</div>
</div>
<div class="box-content">
<table id="suppliertable" class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Supplier</th>
<th>Open Range</th>
<th>Fill Content</th>
<th>Total Match</th>
</tr>
</thead>
<tbody>
<?php foreach($dash_present_all_suppliers as $v): ?>
<tr>
<td class="center" style="color:#0c595b;"><?php echo $v['supplierCompany']?> </td>
<td class="center">70%</td>
<td class="center">12%</td>
<td class="center">82%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div>
Instead of using $this->session->flashdata() user the normal session i.e. $this->session->userdata() to store the temp browse data and write a cron which will delete this session in a regular interval or at the time of logout or any desired specific action.
Hope this will give better approach n help you in solving your problem

Categories