Laravel7 2 Table joining with complex data - laravel-7

I want to show the data from tbl_structure with people name from tble_peple but I don't know how to join it. I am a new on laravel.
my tbl_structure
my tble_peple
showing data
my code on Controller
public function get_people(){
$Showstructe= DB::table('tbl_structure')->orderby("name","asc")
->get();
return view('admin.TestCustomer.structure_show',compact('Showstructe'));
}
my code to show data
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Structure</th>
<th>Stage A</th>
<th>Stage B</th>
<th>Stage C</th>
<th>Stage D</th>
<th>Stage E</th>
<th>Stage F</th>
</tr>
#foreach($Showstructe as $people)
<tr>
<td>{{ $people->id }}</td>
<td>{{ $people->name }}</td>
<td>{{ $people->stage_a }}</td>
<td>{{ $people->stage_b }}</td>
<td>{{ $people->stage_c }}</td>
<td>{{ $people->stage_d }}</td>
<td>{{ $people->stage_e }}</td>
<td>{{ $people->stage_f }}</td>
<tr>
#endforeach
</table>
How to show people name not just people id?

public function get_people(){
$Showstructe= DB::table('tbl_structure')->leftJoin('people as p', 'tbl_structure.id', '=', 'p.id')->select('p.name as peopleName')->orderby("name","asc")
->get();
return view('admin.TestCustomer.structure_show',compact('Showstructe'));
}
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>Structure</th>
<th>Stage A</th>
<th>Stage B</th>
<th>Stage C</th>
<th>Stage D</th>
<th>Stage E</th>
<th>Stage F</th>
</tr>
#foreach($Showstructe as $people)
<tr>
<td>{{ $people->peopleName}}</td>
<td>{{ $people->name }}</td>
<td>{{ $people->stage_a }}</td>
<td>{{ $people->stage_b }}</td>
<td>{{ $people->stage_c }}</td>
<td>{{ $people->stage_d }}</td>
<td>{{ $people->stage_e }}</td>
<td>{{ $people->stage_f }}</td>
<tr>
#endforeach
</table>

Related

How to read data from the sqlalchemy database (with foreign keys ) and render it as a table

Am trying to get details from my users table and payroll table and display them yas a single table which i can add actions to , but am failing to get any data although my database is populated
below is my database models for users and roles
from flask_login import UserMixin
from datetime import datetime
from app import db
class Roles(db.Model):
id = db.Column(db.Integer, primary_key=True)
role_fullname = db.Column(db.String(500), nullable=False, unique=True)
role_shortcut = db.Column(db.String(500), unique=False, nullable=False)
created_at = db.Column(db.DateTime, server_default=db.func.now())
updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())
class User(UserMixin,db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(500),unique=True, nullable=False)
profile_pic = db.Column(db.String(50),nullable=True, default='default.png')
password = db.Column(db.String(160),nullable=False)
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'), nullable=False)
role = db.relationship("Roles", backref="person", uselist=False)
created_at = db.Column(db.DateTime, server_default=db.func.now())
updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())
firstname = db.Column(db.String(500),nullable=True)
lastname = db.Column(db.String(500),nullable=True)
verification = db.Column(db.String(20), nullable=True)
organization = db.Column(db.String(15), nullable=True)
payrolls = db.relationship('Payroll', backref='employee', lazy='dynamic')
and below is my model for payroll
from flask_login import UserMixin
from datetime import datetime
from app import db
from sqlalchemy.ext.hybrid import hybrid_property
from app.models.user import User, Roles
class Payroll(db.Model):
#primary key
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
#audit trail
payroll_created_at = db.Column(db.DateTime, default=datetime.now)
payroll_updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
#salary date
salary_date = db.Column(db.DateTime, nullable=True)
currency= db.Column(db.String(500),unique=False, nullable=True)
#personal information
bank_details = db.Column(db.String(500),unique=False, nullable=True)
payment_basis = db.Column(db.String(500),unique=False, nullable=True)
#days worked
normal_days = db.Column(db.Integer, unique=False, nullable=True)
days_worked = db.Column(db.Integer, unique=False, nullable=True)
previous_monthe_days = db.Column(db.Integer, unique=False, nullable=True)
#earnings
basic_salary = db.Column(db.Float, unique=False, nullable=True)
paid_normal_days = db.Column(db.Integer, unique=False, nullable=True)
and below is my routes.py
from flask import Blueprint, render_template,redirect, url_for, request, flash, session, current_app, jsonify, abort
from app.forms.payroll_forms import PayrollEntryForm
from app import db
from app.models.user import User, Roles
from app.models.payroll import Payroll, hybrid_property
#payroll_blueprint.route('/interactive_table')
def interactive_table():
employees = Payroll.query
return render_template('payroll/interactive_table.html', title='Interactive Table',
employees=employees)
below is my interactive_table.html
{% extends "base/_layout.html" %}
{% block body %}
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h1 class="card-title">Employees Information</h1>
<h2 class="card-subtitle text-muted">Search and Edit Employee Information</h2>
<div class="table-responsive">
<table id="data" class="table table-striped">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Role</th>
<th>Organisation</th>
<th>Bank Details</th>
<th>Payment Basis</th>
<th>Pay Date</th>
<th>Currency</th>
<th>Normal Days</th>
<th>Days Worked</th>
<th>Previous Month Days</th>
<th>Total Days Worked</th>
<th>Basic Salary</th>
<th>Paid Normal Working Days</th>
<th>Actual Basic Salary</th>
<th>O\T Days #1.5</th>
<th>O/T Days # 2</th>
<th>O/T Days # 1.5 Value</th>
<th>O/T Days # 2 Value</th>
<th>Hardship Allowance</th>
<th>Discretionary Allowance</th>
<th>Weekly Incentives</th>
<th>Transport Allowance</th>
<th>Medical Aid Cover</th>
<th>Funeral Cover</th>
<th>Airtime and Data Allowance</th>
<th>CILL Days</th>
<th>CILL Rate</th>
<th>Leave Days Taken</th>
<th>Leave Days Due</th>
<th>Total CILL</th>
<th>Monthly CILL</th>
<th>CILL Paid</th>
<th>Terminal Benefits</th>
<th>Coupons Value</th>
<th>Perfomance Allowance</th>
<th>Annivesary Payout</th>
<th>Shift Allowance</th>
<th>Agent Benefits</th>
<th>HPC</th>
<th>Total Earnings</th>
<th>Medical Loan</th>
<th>Garnishees</th>
<th>Total Primary Deductions</th>
<th>Gross Salary</th>
<th>NPS</th>
<th>WCIF</th>
<th>NEC</th>
<th>Grand Total</th>
<th>NSSA Employee</th>
<th>NEC Employee</th>
<th>Total Allowable Deductions</th>
<th>Taxable Income</th>
<th>Gross Tax</th>
<th>Tax Credits</th>
<th>PAYE</th>
<th>Aids Levy</th>
<th>Total Monthly Tax</th>
<th>Total After Taxes</th>
<th>Fixed Deductions</th>
<th>Fixed Deductions Months </th>
<th>Total Fixed Deductions </th>
<th>Monthly Fixed Deductions Due </th>
<th>Canteen </th>
<th>CICM </th>
<th>ZOL</th>
<th>Staff Loan</th>
<th>Other Loans</th>
<th>Independent Contractors Deduction </th>
<th>Back Pay </th>
<th>Total Other Deductions </th>
<th>Net Salary </th>
<th>View Payslip</th>
</tr>
</thead>
<tbody>
{% for payroll in employees %}
<tr>
<td>{{ payroll.employee.firstname }}</td>
<td>{{ payroll.employee.lastname }}</td>
<td>{{ payroll.employee.email }}</td>
<td>{{ payroll.employee.person.role_fullname}}</td>
<td>{{ payroll.employee.organization }}</td>
<td>{{ payroll.bank_details }}</td>
<td>{{ payroll.payment_basis }}</td>
<td>{{ payroll.salary_date }}</td>
<td>{{ payroll.currency}}</td>
<td>{{ payroll.normal_days}}</td>
<td>{{ payroll.days_worked}}</td>
<td>{{ payroll.total_days_worked}}</td>
<td>{{ payroll.previous_monthe_days}}</td>
<td>{{ payroll.basic_salary}}</td>
<td>{{ payroll.paid_normal_days }}</td>
<td>{{ payroll.actual_basic_salary }}</td>
<td>{{ payroll.one_point_five_overtime_days }}</td>
<td>{{ payroll.double_overtime_days }}</td>
<td>{{ payroll.one_point_five_overtime_days_value }}</td>
<td>{{ payroll.double_overtime_days_value }}</td>
<td>{{ payroll.hardship_allowance }}</td>
<td>{{ payroll.discretionary_allowance }}</td>
<td>{{ payroll.weekly_incentives}}</td>
<td>{{ payroll.transport_allowances }}</td>
<td>{{ payroll.medical_aid_cover }}</td>
<td>{{ payroll.funeral_cover }}</td>
<td>{{ payroll.airtime_and_data_allowance }}</td>
<td>{{ payroll.cill_days }}</td>
<td>{{ payroll.cill_rate }}</td>
<td>{{ payroll.leave_days_taken }}</td>
<td>{{ payroll.leave_days_due}}</td>
<td>{{ payroll.total_cill }}</td>
<td>{{ payroll.monthly_cill }}</td>
<td>{{ payroll.cill_paid }}</td>
<td>{{ payroll.terminal_benefits }}</td>
<td>{{ payroll.coupons_value }}</td>
<td>{{ payroll.performance_allowance }}</td>
<td>{{ payroll.anniversary_payout}}</td>
<td>{{ payroll.shift_allowance}}</td>
<td>{{ payroll.agent_benefits}}</td>
<td>{{ payroll.hpc }}</td>
<td>{{ payroll.total_earnings}}</td>
<td>{{ payroll.medical_loan }}</td>
<td>{{ payroll.garnishees }}</td>
<td>{{ payroll.total_primary_deductions }}</td>
<td>{{ payroll.gross_salary }}</td>
<td>{{ payroll.nps }}</td>
<td>{{ payroll.wcif }}</td>
<td>{{ payroll.nec }}</td>
<td>{{ payroll.grand_total }}</td>
<td>{{ payroll.nssa_employee }}</td>
<td>{{ payroll.nec_employee }}</td>
<td>{{ payroll.total_allowable_deductions }}</td>
<td>{{ payroll.taxable_income }}</td>
<td>{{ payroll.gross_tax}}</td>
<td>{{ payroll.tax_credits }}</td>
<td>{{ payroll.paye }}</td>
<td>{{ payroll.aids_levy}}</td>
<td>{{ payroll.total_monthly_tax }}</td>
<td>{{ payroll.total_after_taxes }}</td>
<td>{{ payroll.fixed_deductions }}</td>
<td>{{ payroll.fixed_deductions_months }}</td>
<td>{{ payroll.total_fixed_deductions }}</td>
<td>{{ payroll.total_monthly_fixed_deductions }}</td>
<td>{{ payroll.canteen }}</td>
<td>{{ payroll.cicm }}</td>
<td>{{ payroll.zol}}</td>
<td>{{ payroll.staff_Loan}}</td>
<td>{{ payroll.loan }}</td>
<td>{{ payroll.last_month_salary }}</td>
<td>{{ payroll.other_deductions }}</td>
<td>{{ payroll.net_pay }}</td>
<td><a class="btn btn-sm" style="background-color:rgb(0, 75, 93); color:whitesmoke;" href="{{ url_for('payroll.payslip', empid = payroll.id )}}">View Full Profile</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(document).ready(function () {
$('#data').DataTable();
});
</script>
{% endblock %}
and i get is an empty table

In PrimeNG, Frozen Headers also scrolling along with unfrozen columns and missing alignment of headers

I have tried to show pResizableColumn pFrozenColumn into a single table.But after integrate both into single table Frozen Headers also scrolling along with unfrozen columns.
<p-table
[value]="customers"
scrollDirection="both"
[scrollable]="true"
scrollHeight="400px"
styleClass="p-datatable-gridlines"
[resizableColumns]="true"
>
<ng-template pTemplate="header">
<tr>
<th style="width:200px" pResizableColumn pFrozenColumn>Name</th>
<th style="width:100px" pResizableColumn pFrozenColumn>Id</th>
<th style="width:200px" pResizableColumn pFrozenColumn>Country</th>
<th style="width:200px" pResizableColumn>Date</th>
<th style="width:200px" pResizableColumn>Company</th>
<th style="width:200px" pResizableColumn>Status</th>
<th style="width:200px" pResizableColumn>Activity</th>
<th style="width:200px" pResizableColumn>Status</th>
<th style="width:200px" pResizableColumn>Activity</th>
<th style="width:200px" pResizableColumn>Representative</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-customer>
<tr>
<td style="width:200px" pFrozenColumn>{{ customer.name }}</td>
<td style="width:100px" pFrozenColumn>{{ customer.id }}</td>
<td style="width:200px" pFrozenColumn>{{ customer.country.name }}</td>
<td style="width:200px">{{ customer.date }}</td>
<td style="width:200px">{{ customer.company }}</td>
<td style="width:200px">{{ customer.status }}</td>
<td style="width:200px">{{ customer.activity }}</td>
<td style="width:200px">{{ customer.status }}</td>
<td style="width:200px">{{ customer.activity }}</td>
<td style="width:200px">{{ customer.representative.name }}</td>
</tr>
</ng-template>
</p-table>

Table number iterator

I want to create a table in twig. The rows in the table are added dynamically, depending on what the user configures in the admin. I'm almost there, but each tr needs to be prefixed with a number.
How do I make the number (1, 2, 3) dynamic, as I don't know how many rows will be in the table beforehand? I have looked at the batch and for explanations in the twig documentation but it doesn't explain what to do when you don't know the max number.
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>#twitter</td>
</tr>
</tbody>
</table>
As you didn't provide the twig code in your question I'm assuming you are building the table with a for
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<th scope="row">{{ loop.index }}</th>
<td>{{ item.first_name }}</td>
<td>{{ item.last_name }}</td>
<td>{{ item.handle }}</td>
</tr>
{% endfor %}
</tbody>
</table>
demo

How to insert data for table in mangodb

I am trying to insert data for table and show in my page but I do not know how to insert the data and how to get the data to show in the table.If anyone know please help.
db.maintable.insert(
{
"id":"1",
"orderno":"19345",
"name" : "tutorialspoint",
"startedate":"21/04/2018",
"enddate":"28/12/2018"
},
{
"id":"2",
"orderno":"12945",
"name" : "tutorialspoint",
"startedate":"01/12/2018",
"enddate":"21/02/2018"
},
{
"id":"3",
"orderno":"12325",
"name" : "tutorialspoint",
"startedate":"21/22/2018",
"enddate":"24/12/2018"
}
)
data.service.ts:
getTable() {
return this._http.get("/api/maintable")
.map(result => this.result = result.json().data);
}
app.component.ts:
this._dataService.getUsers().subscribe(res => this.users = res);
app.component.html:
<table>
<thead>
<th>Id</th>
<th>Order noo</th>
<th>Name</th>
<th>Start Date</th>
<th>End Date</th>
</thead>
<tbody>
<tr *ngFor="let getdata of maintable">
<td>{{ getdata.id }}</td>
<td>{{ getdata.orderno }}</td>
<td>{{ getdata.name }}</td>
<td>{{ getdata.startdate }}</td>
<td>{{ getdata.enddate }}</td>
</tr>
</tbody>
</table>
You have made mistake on loop, instead of maintable use result
<tr *ngFor="let getdata of maintable">

Display image in twig symfony from database

I am trying to display an image from my database into a twig file but it doesn't work, the image is not displayed. I don't know where is the problem.
The image name is stored as a string in the database.
<tr class="">
<td>{{ boutique.getId() }}</td>
<td>{{ boutique.getNomBoutique() }}</td>
<td>{{ boutique.getNomResponsableBoutique() }}</td>
<td>{{ boutique.getAdresse() }}</td>
<td>{{ boutique.getContact() }}</td>
<td>{{ boutique.getFournisseur() }}</td>
<td>{{ boutique.getType() }}</td>
<td><img src="{{ asset('public/images/{{ boutique.getImage()}}') }}" class="img-rounded"/></td>
<td>View Order</td>
<td>Cancel</td>
</tr>
You wrote {{ asset('public/images/{{ boutique.getImage()}}') }}.
This won't work, you need to properly concatenate your strings like this:
{{ asset('public/images/' ~ boutique.getImage()) }}
You can also use string interpolation within double-quoted string if you want:
{{ asset("public/images/#{boutique.getImage()}") }}
<img class="img-thumbnail" src="{{ asset('uploads/avatars/' ~ user.avatar) }}" alt="user avatar">
symfony 5 webpack encore, my upload folder is in : \public\uploads\avatars

Resources