zaster

Experience

5,970

1 Best Reply Awards

  • Member Since 2 Years Ago
  • 15 Lessons Completed
  • 0 Favorites

20th September, 2018

zaster left a reply on Dompdf Mail With Attachment • 1 day ago

@dextercampos

Nope still the same error

18th September, 2018

zaster started a new conversation Migrations And Tinker As Tools To Design And Finalize Your Database Before Moving Forward • 3 days ago

I am working on a web application which has more than 30 tables and thought of designing the database first using models and migrations. Then to test the relationships etc... through tinker. Is this a good way of doing this or is there any other better way. What i need is to finalize the DB Structure before moving in to creating views and controllers

13th September, 2018

zaster started a new conversation Quotation Becomes A Job - Should I Mange With A Status Column? • 1 week ago

When a Quotation is approved it becomes a Job. Should i maintain separate tables , controllers, views ?

Or

Should i have a status column at quotations table and manage

zaster left a reply on Dompdf Mail With Attachment • 1 week ago

@Sergui17 This has something to do with

QuotationController

public function update(Request $request, Quotation $quotation)
    {
      {


          $quotation->description= $request['description'];
          $quotation->qty= $request['qty'];
          $quotation->each_price= $request['each_price'];
          $quotation->save();

         $info = ['info'=>$quotation];

         Mail::send(['text'=>'mail'], $info, function($message){

             $pdf = PDF::loadView('employees.quotations.edit', $quotation);

             $message->to('[email protected]','John Doe')->subject('Quotation');

             $message->from('[email protected]','The Sender');

             $message->attachData($pdf->output(), 'filename.pdf');

           });
          echo 'Email was sent!';

        }
      }

Specifically the undifined variable $quotation error is shown after the below line

             $pdf = PDF::loadView('employees.quotations.edit', $quotation);

12th September, 2018

zaster left a reply on Dompdf Mail With Attachment • 1 week ago

Route already looks like this. Looks like there is something else which cause the problem

  Route::get('/quotation/{quotation}/edit', 'Employee\[email protected]')->name('employee.quotation.edit');

11th September, 2018

zaster left a reply on Dompdf Mail With Attachment • 1 week ago

@Sergiu17

QuotationsController.php

    public function edit(Quotation $quotation)
    {
        return view('employees.quotations.edit', compact('quotation'));
        //return view('employees.quotations.edit')->with('quotation');

    }

employees.quotations.edit.blade.php


@section('left-menu')

@endsection

@section('right-menu')

@endsection

@section('content')
  <h1>Update a Quotation</h1>
  <br><br>
  
    <form action="{{ route('employee.quotation.update',$quotation->id) }}" method="post">
      @method('PUT')
      @csrf
      <div class="form-group">
        <label for="inputJobDescription">Description</label>
        <textarea class="form-control" rows="2" id="inputQuoteDescription" name="description" placeholder="Description">{{$quotation->description}}
</textarea>
      </div>
      <div class="form-group row">
        <label for="inputQty" class="col-2 col-form-label">Qty</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputQty" name="qty" value="{{$quotation->qty}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputEachPrice" class="col-2 col-form-label">Each Price</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputEachPrice" name="each_price" value="{{$quotation->each_price}}" oninput="quotation_calculate()" onchange="quotation_calculate()">
        </div>
      </div>
      <button type="submit" class="btn btn-primary">Submit</button>
    </form>
@endsection

@section('pagescript')

@stopassola 

It's already like this , i can't understand what i am doing wrong

Undefined variable: quotation (View: ..path\resources\views\employees\quotations\edit.blade.php)

zaster started a new conversation Dompdf Mail With Attachment • 1 week ago

QuotationController

public function update(Request $request, Quotation $quotation)
    {
      {


          $quotation->description= $request['description'];
          $quotation->qty= $request['qty'];
          $quotation->each_price= $request['each_price'];
          $quotation->save();

         $info = Quotation::find($quotation);

         $info = ['info'=>$info];

         Mail::send(['text'=>'mail'], $info, function($message){

             $pdf = PDF::loadView('employees.quotations.edit', $quotation);

             $message->to('[email protected]','John Doe')->subject('Quotation');

             $message->from('[email protected]','The Sender');

             $message->attachData($pdf->output(), 'filename.pdf');

           });
          echo 'Email was sent!';

        }
      }

Error Message

"Undefined variable: quotation"

3rd September, 2018

zaster started a new conversation SQLSTATE[42S02]: Base Table Or View Not Found: 1146 Table 'pk5.roles' Doesn't Exist • 2 weeks ago

I am able to insert records to employee_roles through tinker but unable to insert them through code

Role.php

<?php

namespace App\Models\Admin\Employee;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{

    protected $table = 'employee_roles';

    public function permissions()
    {
        return $this->belongsToMany('App\Models\Admin\Employee\Permission', 'employee_permission_role', 'role_id', 'permission_id');
    }
}

RoleController.php


<?php

namespace App\Http\Controllers\Admin\Employee;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Employee\Employee;
use App\Models\Admin\Employee\Role;
use App\Models\Admin\Employee\Permission;

class RoleController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    public function index()
    {
        $roles = Role::all();
        return view('admins.employees.roles.role', compact('roles'));
    }

    public function create()
    {
      $permissions = Permission::all();
      return view('admins.employees.roles.create',compact('permissions'));
    }

    public function store(Request $request)
    {

      //dd($request);
        $this->validate($request, [
          'name' => 'required|unique:roles'
        ]);

        $role = new Role();
        $role->name = $request['name'];
        $role->save();
        $role->permissions()->sync($request->permission);

        return redirect(route('admin.employee.role.index'));
    }

admins.employees.roles.create.blade.php

@extends('layouts.admin')

@section('title', 'Role - Create')

@section('left-menu')

@endsection

@section('right-menu')

@endsection

@section('content')
  <h1>Add an Employee Role</h1>
  <br><br>
  @if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
  @endif
  <form action="{{ route('admin.employee.role.store') }}" method="post">
        @csrf

      <div class="form-group">
        <label for="name">Role Name</label>
        <input type="text" class="form-control" id="name" name="name" placeholder="Role Name" value="{{ old('name') }}">
      </div>

      <div class="form-row">
        <div class="col-md-4">
          <label for="name"><b>Customer Permissions</b></label>
            @foreach ($permissions as $permission)
              @if ($permission->for == 'Customer')
                <div class="checkbox">
                  <label><input type="checkbox" name="permission[]" value="{{ $permission->id }}">{{ $permission->name }}</label>
                </div>
              @endif
            @endforeach
        </div>

        <div class="col-md-4">
          <label for="name"><b>Despatch Permissions</b></label>
            @foreach ($permissions as $permission)
              @if ($permission->for == 'Despatch')
                <div class="checkbox">
                  <label><input type="checkbox" name="permission[]" value="{{ $permission->id }}">{{ $permission->name }}</label>
                </div>
              @endif
            @endforeach
        </div>
      </div>

    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
      <a href='{{ route('admin.employee.role.index') }}' class="btn btn-warning">Back</a>
    </div>

  </form>
@endsection

@section('pagescript')

@stop

31st August, 2018

zaster started a new conversation Multi Auth With Roles And Permissions • 2 weeks ago

I have 4 Separate sections as logins

Admin Login Vendor Login Employee Login User Login

Admin is supposed to create all roles and permissions to these different Type of Users

How should i maintain the roles and permissions tables

Can i have only two tables such as roles and permissions to manage all these User Types

zaster started a new conversation Organizing The Model Structure And Controller Structure • 3 weeks ago

The Admin assigns roles and permissions for employees. How should the structure of the models be like

1 Admin

  • EmployeePermission
  • EmployeeRole

or

2

Employee

  • Role
  • Permission

Also the If Admins are incharge of creating Employees, i assume that the controllers should be organized as below mentioned

Admin

  • EmployeeController.php
  • EmployeeRoleController.php

zaster left a reply on Relationship Between Different Namespaces • 3 weeks ago

@Sergiu17

Thank you for that. Corrected it and there were other errors. Refereed the documentation and this worked for me

Employee.php

class Employee extends Authenticatable
{
    use Notifiable;

    protected $guard = 'employee';

    public function employee_roles()
    {
        return $this->belongsToMany('App\Models\Admin\EmployeeRole', 'employee_role', 'employee_id', 'role_id');
    }

30th August, 2018

zaster left a reply on Relationship Between Different Namespaces • 3 weeks ago

@Sergiu17

Each employee has several employee_roles

I need to get those employee_roles

It seems like something to do with the namespace?

Namespace of EmployeeRolenamespace App\Models\Admin; Namespace of Employee namespace App\Models\Employee;

29th August, 2018

zaster started a new conversation Relationship Between Different Namespaces • 3 weeks ago

Employee.php

<?php

namespace App\Models\Employee;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Notifications\EmployeeResetPasswordNotification;

class Employee extends Authenticatable
{
    use Notifiable;

    protected $guard = 'employee';

    public function employee_roles()
    {
        return $this->belongsToMany('App\Models\Admin\EmployeeRole');
    }

EmployeeRole.php

<?php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Model;

class EmployeeRole extends Model
{
    public function permissions()
    {
        return $this->belongsToMany('App\Model\Admin\EmployeePermission');
    }
}

Tinker

$employee->employee_roles()

Gives me this error

=> Illuminate\Database\Eloquent\Relations\BelongsToMany {#2446
     +withTimestamps: false,

26th August, 2018

zaster started a new conversation Admin Template For Bootstrap 4 With Documentation - Suggestion • 3 weeks ago

I need some suggestions for some free bootstrap 4 admin templates with documentation. Something like Admin Lte for Bootstrap 3

22nd August, 2018

zaster started a new conversation Multiple Authentication - Larvel 5.6 - Tutorial - Suggestion • 4 weeks ago

Is there a tutorial which i could follow to setup Multiple Authentication with Laravel 5.6 including Password resets etc... I have gone through tutorials on Laravel 5.4 Multiple Authentication, but those don't work well when using Laravel 5.6

14th August, 2018

zaster started a new conversation Json_encode Without Outer Quotes • 1 month ago

Controller code

$companies = DB::table('jobs')
              ->where('user_id', '=', $userId)
              ->join('companies', 'jobs.company_id', '=', 'companies.id')
              ->get()
              ->unique('company_id')
              ->pluck('name','company_id');

dd(json_encode($companies));      

"{"1":"Company One","2":"Company Two"}"

I need to omit the outer double quotes

13th August, 2018

zaster left a reply on Dependent Dropdown - Jquery - Ajax • 1 month ago

I need to do something like this

$companies = DB::table('jobs')
                  ->where('user_id', '=', $userId)
                  ->join('companies', 'jobs.company_id', '=', 'companies.id')
                  ->get()
          ->unique();

I need to get the company_ids when the user_id is given

zaster left a reply on Dependent Dropdown - Jquery - Ajax • 1 month ago

@Sergiu17 Actually the company name should be taken from the companies table not the jobs table. That seems like the main issue here now.

zaster left a reply on Dependent Dropdown - Jquery - Ajax • 1 month ago

@Sergiu17 struggling with the ajax part now. Company names are not getting changed according to the user name

zaster started a new conversation Dependent Dropdown - Jquery - Ajax • 1 month ago

A customer can be assigned to many companies. Therefore when the customer is selected the respective companies should appear. Instead of the company names, i am getting the company_ids How can i get the company names

JobController.php

public function edit(Job $job)
    {
        $subJobs = $job->sub_jobs;
        $customers = User::all();
        $selectedCustomer = $job->user_id;
        //dd($selectedCustomer);
        $companies = Company::all();
        $selectedCompany = $job->company_id;
        return view('employees.jobs.edit', compact('job', 'subJobs', 'customers', 'selectedCustomer', 'companies', 'selectedCompany'));
    }


    public function ajax(Job $job)
    {
      //Get the Job Number
      $id = $job->id;

      //Get the user_id of the job
      $userId = Job::where('id', '=', $id)->pluck('user_id')->first();

      //Show all customers
      $customers = User::all();
      //dd($customers);
      //Show the companies according to the customer list
      $companies = Job::where('user_id', '=', $userId)
                        ->pluck('company_id')->unique();
      //dd($companies);
      return json_encode($companies);

    }

public function update(Request $request, Job $job)
    {
        $this->validate($request, [
          'job_owner' => 'required'
        ]);

        //dd($request);
        $customer = new User();
        $customer->user_id = $request['customer'];


        $customer = User::Find($request['customer']);
        $customer->companies()->attach($request['company']);
        $customer->save();

        $job->user_id = $request['customer'];
        $job->company_id = $request['company'];
        $job->description= $request['description'];
        $job->owner= $request['owner'];
        $job->status= $request['status'];
        $job->despatch_status= $request['despatch_status'];
        $job->invoice_status= $request['invoice_status'];
        $job->sales_status= $request['sales_status'];
        $job->entered_status= $request['entered_status'];
        $job->delivery_date= $request['delivery_date'];
        $job->delivery_time= $request['delivery_time'];
        $job->comp= $request['comp'];
        $job->cost= $request['cost'];
        $job->profit= $request['profit'];
        $job->price= $request['price'];
        $job->nbt= $request['nbt'];
        $job->vat= $request['vat'];
        $job->total_value= $request['total_value'];
        $job->save();

        $jobs = Job::all();
        return view('employees.jobs.job', compact('jobs', $jobs));
    }
    

jobs.edit.blade.php

<form action="{{ route('employee.job.update',$job->id) }}" method="post">
      @method('PUT')
      @csrf
      <div class="form-group">
        <label for="inputJobNumber">Job Number</label>
        <input type="text" class="form-control" id="inputJobNumber" name="id" value="{{$job->id}}" readonly>
      </div>
      <div class="form-group">
        <label for="inputCustomerName">Customer Name</label>
          <select name="customer" class="form-control" id="inputUser">
             <option value="">--Select User--</option>
             @if ($customers->count())
               @foreach ($customers as $customer)
               <option value="{{ $customer->id }}" {{ $selectedCustomer == $customer->id ? 'selected="selected"' : '' }}>
                  {{ $customer->name }}
                </option>
               @endforeach
             @endif
          </select>
      </div>
      <div class="form-group">
        <label for="inputCustomerName">Company Name</label>
          <select name="company" class="form-control" id="inputCompany">
             <option value="">--Select Company--</option>
             @if ($companies->count())
             @foreach ($companies as $key => $value)
             <option value="{{ $key }}" {{ $selectedCompany == $key ? 'selected="selected"' : '' }}>
               {{ $value->name }}
             </option>
             @endforeach
           @endif 

Jquery of jobs.edit.blade.php

<script type="text/javascript">
      $(document).ready(function() {
          $('select[name="customer"]').on('change', function() {
              var cusotmerId = $(this).val();
              if(cusotmerId) {
                  $.ajax({
                      url: '/employee/job/ajax/'+cusotmerId,
                      type: "GET",
                      dataType: "json",
                      success:function(data) {
                          $('select[name="company"]').empty();
                          $.each(data, function(key, value) {
                              $('select[name="company"]').append('<option value="'+ key +'">'+ value +'</option>');
                          });
                      }
                  });
              }else{
                  $('select[name="company"]').empty();
              }
          });
      });
  </script>

4th August, 2018

zaster left a reply on Accessing Collections Through Blade Foreach • 1 month ago

@lostdreamer_nl Great Stuff! These content(Documentation) along with your guidance make sense now. Thanks you very much :)

zaster left a reply on Array Count - Laravel • 1 month ago

@tykus

The below mentioned worked

$size = count(collect($request)->get('id'));
        //dd($size);
        for ($i = 0; $i < $size; $i++){
          $subJob = SubJob::Find($request->get('id')[$i]);
          $subJob->job_id = $jobId;
          $subJob->name = $request->get('name')[$i];
          $subJob->size = $request->get('size')[$i];
          $subJob->medium = $request->get('medium')[$i];
          $subJob->feature = $request->get('feature')[$i];
          $subJob->qty = $request->get('qty')[$i];
          $subJob->price = $request->get('price')[$i];
          $subJob->total = $request->get('qty')[$i] * $request->get('price')[$i];
          $subJob->save();
        }

zaster left a reply on Array Count - Laravel • 1 month ago

@tykus

$collection = collect($request->all());

dd($collection->count());   

and

count($request->all()

Both give the output 9

zaster started a new conversation Array Count - Laravel • 1 month ago

Request {#42 ▼   #json: null   #convertedFiles: null   #userResolver: Closure {#221 ▶}   #routeResolver: Closure {#224 ▶}   +attributes: ParameterBag {#44 ▶}   +request: ParameterBag {#43 ▼     #parameters: array:9 [▼       "_token" => "5SakQCnIBEL0SrBuKmH5QZveWJlsdPv8jltFfLl1"       "_method" => "PUT"       "id" => array:3 [▶]       "name" => array:3 [▶]       "size" => array:3 [▶]       "medium" => array:3 [▶]       "feature" => array:3 [▶]       "qty" => array:3 [▶]       "price" => array:3 [▶]     ]

How can i get a count of the number of arrays of the attached screenshot. In this scenario the number i want is3

public function update(Request $request, $jobId)
    {
        //dd($request);
        // cast into a collection use the collect() helper
        $collection = collect($request);

        for ($i=0; $i < $collection->count(); $i++) {
          //dd(count($request));
          $subJob = SubJob::Find($request->get('id')[$i]);
          $subJob->job_id = $jobId;
          $subJob->name = $request->get('name')[$i];
          $subJob->size = $request->get('size')[$i];
          $subJob->medium = $request->get('medium')[$i];
          $subJob->feature = $request->get('feature')[$i];
          $subJob->qty = $request->get('qty')[$i];
          $subJob->price = $request->get('price')[$i];
          $subJob->total = $request->get('qty')[$i] * $request->get('price')[$i];
          $subJob->save();
     }

$collection->count() gives the value 9

Is there any other way of running the loop until the end? For example in blade we have $loop->last but here , i am working at the Controller level

3rd August, 2018

zaster left a reply on Accessing Collections Through Blade Foreach • 1 month ago

@lostdreamer_nl Thank you very much for the detailed explanation and extra suggestions.

The code you mentioned worked as well

Wasn't aware that this is possible

$job = Job::with('despatches.despatch_items')->find($jobId);

2nd August, 2018

zaster left a reply on Accessing Collections Through Blade Foreach • 1 month ago

@lostdreamer_nl yes dd($despatchItem) is the output i showed and Your code solved the issue.

Do you think there is something better that i could do from the controller level

  public function create($jobId)
    {


      $job = Job::find($jobId);

      $despatches = $job->despatches;


      foreach ($despatches as $despatch) {
        $despatchItems['despatchItems'][] = $despatch->despatch_items;
      }

      return view('employees.invoices.create',compact('despatchItems','job'));
    }

By the way One Job has Many Despatch and One Despatch has Many DespatchItems

zaster started a new conversation Accessing Collections Through Foreach • 1 month ago

array:3 [▼
  0 => Collection {#290 ▼
    #items: array:2 [▼
      0 => DespatchItem {#302 ▼
        #table: "despatch_items"
        #connection: "mysql"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:7 [▼
          "id" => 7
          "despatch_id" => 8
          "tag_id" => 2
          "qty" => 123.0
          "description" => "asdfasdf"
          "created_at" => "2018-08-01 09:47:08"
          "updated_at" => "2018-08-01 09:47:08"
        ]
        #original: array:7 [▶]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #fillable: []
        #guarded: array:1 [▶]
      }
      1 => DespatchItem {#305 ▶}
    ]
  }
  1 => Collection {#307 ▶}
  2 => Collection {#304 ▶}
@foreach ($despatchItems as $despatchItem)
            {{dd($despatchItem)}}
             <td><input type="text" class="form-control" id="inputQty" name="qty" value="{{$despatchItem->qty}}"></td>
          @endforeach

I need to get the qty of these arrays(3 Collections are there in this case)

1st August, 2018

zaster left a reply on Linking To Tables And Get Results Through View(blade) • 1 month ago

@Tray2

Thanks for answering, the below worked

    public function tag()
    {
       return $this->belongsTo('App\Models\Employee\Tag','tag_id');
    }
<td>{{$despatchitem->tag->name}}</td>

zaster started a new conversation Linking To Tables And Get Results Through View Laravel • 1 month ago

        @foreach ($despatchitems as $despatchitem)
        <tr>
          <td>{{$despatchitem->tag_id}}</td>
          <td>{{$despatchitem->qty}}</td>
          <td>{{$despatchitem->description}}</td>
        </tr>
        @endforeach 

i need to have the tag name instead of the tag_id, How can i make the connection to Tag table and get the tag name

There is no Direct relationship between DespatchItem Model and Tag Model

15th July, 2018

zaster left a reply on Accessing A Database Field Of A Many To Many Relationship Through Tinker • 2 months ago

@Cronix

This would be the best answer

$job::find(2)->despatches->pluck('qty')

13th July, 2018

zaster started a new conversation Accessing A Database Field Of A Many To Many Relationship Through Tinker • 2 months ago

Couldn't access a database field through tinker

$job::find(2)->despatches->qty

$job::find(2)->despatches works but i need to access the qty field of despatches

Is it possible through tinker?

12th July, 2018

zaster left a reply on Controller Logic Issue • 2 months ago

@tykus

Wow. I was lost with this logic for a long time now. The main issue was not including ->get() ,

corrected the braces too.

Now its working. Thank you very much @tykus. Your answer was spot on.

zaster started a new conversation Controller Logic Issue • 2 months ago

All similar vendor_ids should have similar po_ids in the jobitems table. Only one po_id is assigned when there are multiple records which the po_id should be assigned to.

//find all vendor_ids and assign the po_id
        foreach ($jobitems as $jobitem) {

          //if the po_id exists in the database
            if(!is_null($jobitem->po_id))
            $poId = $jobitem->po_id;
          //get the vendor_id of it
            $vendorId = $jobitem->vendor_id;
          //find all records which has this vendor_id
            $records = JobItem::where('job_id', $id)
                              ->where('vendor_id', $vendorId);
          //assign the po_id
            foreach ($records as $record) {
              $record->po_id = $poId;
              $record->save();
            }
        }

Finally jobitems table should look like below

job_id = 1 vendor_id = 1 po_id = 5

job_id = 1 vendor_id = 2 po_id = 6

job_id = 1 vendor_id = 2 po_id = 6

11th July, 2018

zaster left a reply on Is Vue A Competitor For Laravel? • 2 months ago

@jlrdw

Javascript for both front-end and back-end, that made me think about this question

10th July, 2018

zaster started a new conversation Is Vue A Competitor For Laravel? • 2 months ago

Vue is usually used with Laravel but Is Vue.js a competitor for Laravel?

zaster started a new conversation 3 NF - 3rd Normal Form Issue • 2 months ago

According to the 3rd Normal Form. Theatrically, we are not supposed to have a Total field (Qty * Price = Total) stored in the database. But practically should we have the Total field stored in the database?

27th June, 2018

zaster started a new conversation Unable To Delete The First Record Of Each Job + Submit Issue • 2 months ago

There is a form within a form in this code and it seems like that's causing an issue. I am unable to delete the first jobitem of each job and there is a issue in submitting the form since it calls the DELETE method.

jobs.costs.show.blade.php

@extends('layouts.app')

@section('title', 'Job Cost Section')

@section('left-menu')

@endsection

@section('right-menu')

@endsection

@section('content')
  <h1>Job Costing</h1>  
  <a class="btn btn-primary" href="{{route('jobitem.create')}}" role="button">Add Job Item</a><br><br>
  <form action="{{ route('jobitem.store') }}" method="post">
      <table id="datatable" class="table">
        <thead>
          <tr>
            <th>Name</th>
            <th>Description</th>
            <th>Qty</th>
            <th>Each</th>
            <th>Total</th>
            <th>Vendor</th>
            <th>PO</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          @foreach ($jobitems as $jobitem)
          <tr>
            <td>{{$jobitem->jobitem_name}}</td>
            <td>{{$jobitem->jobitem_description}}</td>
            <td>{{$jobitem->jobitem_qty}}</td>
            <td>{{$jobitem->jobitem_each_price}}</td>
            <td>{{$jobitem->jobitem_total}}</td>
            <td>{{$jobitem->jobitem_vendor}}</td>
            <td>{{$jobitem->jobitem_po_no}}</td>
            <td>
              <a class="btn btn-warning" href="{{route('jobitem.edit',$jobitem->id)}}" role="button">Edit</a>

              <form id="delete-form-{{ $jobitem->id }}" method="post" action="{{ route('jobitem.destroy',$jobitem->id) }}" style="display: none">
                @csrf
                {{ method_field('DELETE') }}
              </form>
              <a class="btn btn-danger" href="{{route('jobitem.destroy',$jobitem->id)}}" role="button" onclick="
              if(confirm('Are you sure, You Want to delete this?'))
                  {
                    event.preventDefault();
                    document.getElementById('delete-form-{{ $jobitem->id }}').submit();
                  }
                  else{
                    event.preventDefault();
                  }" >Delete</a>
            </td>
          </tr>
          @endforeach
        </tbody>
      </table>
      <div class="form-group row">
        <label for="inputJobCost" class="col-2 col-form-label">Job Cost</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobCost" name="job_cost" placeholder="Job Cost">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputJobProfit" class="col-2 col-form-label">Job Profit</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobProfit" name="job_profit" placeholder="Job Profit">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputJobPrice" class="col-2 col-form-label">Job Price</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobPrice" name="job_price" placeholder="Job Price">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputJobNBT" class="col-2 col-form-label">Job NBT</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobNBT" name="job_nbt" placeholder="Job NBT">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputJobVAT" class="col-2 col-form-label">Job VAT</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobVAT" name="job_vat" placeholder="Job VAT">
        </div>
      </div>
      <div class="form-group row">
        <label for="inputJobTotalValue" class="col-2 col-form-label">Job Total Value</label>
        <div class="col-10">
          <input type="text" class="form-control" id="inputJobTotalValue" name="job_total_value" placeholder="Job Total Value">
        </div>
      </div>
      <button type="submit" class="btn btn-primary">Submit</button>
  </form>



@endsection

@section('pagescript')

@stop

JobController.php

<?php

namespace App\Http\Controllers;

use DB;
use App\Models\Job;
use App\Models\JobItem;
use Illuminate\Http\Request;

class JobController extends Controller
{

    public function index()
    {
      $jobs = Job::all();
      return view('jobs.job', compact('jobs'));
    }

    public function create()
    {
      $job = DB::table('jobs')->orderBy('id', 'desc')->first();
      $id = $job->id + 1;
      //return view('jobs.create')->with('id', $id);
      return view('jobs.create', compact('id'));
    }

    public function store(Request $request)
    {
        $this->validate($request, [
          'job_owner' => 'required'
        ]);

        $job = new Job();
        $job->customer_name= $request['customer_name'];
        $job->company_name= $request['company_name'];
        $job->job_description= $request['job_description'];
        $job->job_owner= $request['job_owner'];
        $job->job_status= $request['job_status'];
        $job->job_delivery_date= $request['job_delivery_date'];
        $job->job_delivery_time= $request['job_delivery_time'];
        $job->pk_pkl= $request['pk_pkl'];
        $job->save();

        $jobs = Job::all();
        return view('jobs.job', compact('jobs', $jobs));
    }

    public function show(Job $job)
    {
        return view('jobs.show', compact('job'));
    }

    public function edit(Job $job)
    {
        return view('jobs.edit', compact('job'));
    }

    public function update(Request $request, Job $job)
    {
        $this->validate($request, [
          'job_owner' => 'required'
        ]);

        $job->customer_name= $request['customer_name'];
        $job->company_name= $request['company_name'];
        $job->job_description= $request['job_description'];
        $job->job_owner= $request['job_owner'];
        $job->job_status= $request['job_status'];
        $job->despatch_status= $request['despatch_status'];
        $job->invoice_status= $request['invoice_status'];
        $job->sales_status= $request['sales_status'];
        $job->entered_status= $request['entered_status'];
        $job->job_delivery_date= $request['job_delivery_date'];
        $job->job_delivery_time= $request['job_delivery_time'];
        $job->pk_pkl= $request['pk_pkl'];
        $job->job_cost= $request['job_cost'];
        $job->job_profit= $request['job_profit'];
        $job->job_price= $request['job_price'];
        $job->job_nbt= $request['job_nbt'];
        $job->job_vat= $request['job_vat'];
        $job->job_total_value= $request['job_total_value'];
        $job->save();

        $jobs = Job::all();
        return view('jobs.job', compact('jobs', $jobs));
    }

    public function destroy(Job $job)
    {
        $job->delete();
        $jobs = Job::all();
        return view('jobs.job', compact('jobs', $jobs));
    }

    public function showJobCost($id)
    {
        //Route::get('/job/cost/{job}', '[email protected]')->name('job.cost.show');
        $job = Job::find($id);
        $jobitems = JobItem::where('job_id', $id)->get();
        return view('jobs.costs.show', compact('jobitems', 'job'));
    }
}

JobItemController.php

<?php

namespace App\Http\Controllers;

use App\Models\JobItem;
use App\Models\Job;
use Illuminate\Http\Request;

class JobItemController extends Controller
{

    public function index()
    {
      $jobitems = JobItem::all();
      return view('jobitems.jobitem', compact('jobitems'));
    }

    public function create(Request $request)
    {
        $path = url()->previous();
        $array = explode('/', $path);

        $jobid = $array[5];

        $jobitems = JobItem::where('job_id', $jobid)->get();

        return view('jobitems.create', compact('jobitems','jobid'));
    }

    public function store(Request $request)
    {
        $this->validate($request, [
          'jobitem_name' => 'required'
        ]);

        $jobitem = new JobItem();
        $jobitem->job_id= $request['jobitem_job_id'];
        $jobitem->jobitem_name= $request['jobitem_name'];
        $jobitem->jobitem_description= $request['jobitem_description'];
        $jobitem->jobitem_qty= $request['jobitem_qty'];
        $jobitem->jobitem_each_price= $request['jobitem_each_price'];
        $jobitem->jobitem_total= $request['jobitem_total'];
        $jobitem->jobitem_vendor= $request['jobitem_vendor'];
        $jobitem->jobitem_po_no= $request['jobitem_po_no'];
        $jobitem->save();
        $jobid = $jobitem->job_id;
        $jobitems = JobItem::all();

        return redirect()->route('job.cost.show', ['id' => $jobid]);
    }

    public function show($jobid)
    {
        $jobitems = JobItem::where('job_id', $jobid)->get();
        $job = Job::find($jobid);
        return view('jobitems.show', compact('jobitems','job'));
    }

    public function edit(JobItem $jobitem)
    {
        //find the jobitems job_id
        $jobid = $jobitem->job_id;
        return view('jobitems.edit', compact('jobitem','jobid'));
    }

    public function update(Request $request, JobItem $jobitem)
    {

        $jobitem->jobitem_name= $request['jobitem_name'];
        $jobitem->jobitem_description= $request['jobitem_description'];
        $jobitem->jobitem_qty= $request['jobitem_qty'];
        $jobitem->jobitem_each_price= $request['jobitem_each_price'];
        $jobitem->jobitem_total= $request['jobitem_total'];
        $jobitem->jobitem_vendor= $request['jobitem_vendor'];
        $jobitem->jobitem_po_no= $request['jobitem_po_no'];
        $jobitem->save();

        $jobid = $jobitem->job_id;
        $jobitems = JobItem::all();
                
        return redirect()->route('job.cost.show', ['id' => $jobid]);
    }

    public function destroy(JobItem $jobitem)
    {
        $jobitem->delete();

        $jobid = $jobitem->job_id;

        return redirect()->route('job.cost.show', ['id' => $jobid]);
    }
}

10th June, 2018

zaster started a new conversation User Type Restrictions • 3 months ago

There are several user types in my system and when the jobcosting page is checked(check box is checked) by usertype1 the jobcosting inputs should be disabled for usertype1. Then the usertype2 is suppose to check the jobcosting , when usertype2 checks it jobcosting inputs should be disabled to usertype1 and usertype2. This pattern goes until usertype3

What i have thought is to use gates (to check the usertype) and then in the views to use @can and have the inputs, then disable the inputs one by one accordingly. But the code is getting to ugly to maintain in this way. Is there a better way to do this?

23rd May, 2018

zaster started a new conversation Checkbox Passes Value = "on" Instead Of Value="1" • 3 months ago

@can ('isAccountant')
<div class="row">
  <div id="status">
     @if ($job->entered_status == '0')
      <input type="checkbox" name="entered_status" @if($job->entered_status) checked value="1" @endif> Entered <br><br>    
     @elseif ($job->entered_status == '1')
      <input type="checkbox" name="entered_status" checked value="1" disabled> Entered <br><br>

     @endif

    @if ($job->sales_status == '1')
      <input type="checkbox" name="despatch_status" checked value="1" disabled> All Despatches Completed <br><br>
      <input type="checkbox" name="invoice_status" checked value="1" disabled> All Invoices Completed
      <input type='hidden' name='despatch_status' value="1">
      <input type='hidden' name='invoice_status' value="1">
    @endif

    @if ($job->sales_status == '0' && $job->job_status == 'Completed' && $job->despatch_status == '0')
      <input type="checkbox" name="despatch_status" @if($job->despatch_status) checked @endif value="1"> All Despatches Completed <br><br>
    @endif

    @if ($job->sales_status == '0' && $job->job_status == 'Completed' && $job->despatch_status == '1')
      <input type="checkbox" name="despatch_status" checked value="1"> All Despatches Completed <br><br>
      <input type="checkbox" name="invoice_status" @if($job->invoice_status) checked @endif value="1"> All Invoices Completed <br><br>
    @endif
  </div>
</div>

@endcan

When an Accountant Logs in to the system and tick the Entered Checkbox instead of entered_status = 1, entered_status = 'on'

I have no idea how something like this is assigned and passed to the database

the error looks like this

"SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'on' for column 'entered_status' at row 1 (SQL: update jobs set entered_status = on, updated_at = 2018-05-23 16:24:27 where id = 10714)

28th April, 2018

zaster left a reply on Unable To Convert String To Float And Format It • 4 months ago

$total_gp = Job::where('id', '>=', 10676)->sum('job_profit');
$total_gp = number_format($total_gp, 2, '.', ',');
$total_gp = (float)$total_gp;

number_format function returns a string value and since i am using $total_gp for other calculations

A non well formed numeric value encountered

Error was given.

Anyway there is another issue now instead of the value = 12431.0 $total_gp represents the value 12.0

zaster left a reply on Unable To Convert String To Float And Format It • 4 months ago

@Cronix

Actually i tried this in the first place and it doesn't work. That's the reason i try to use the cast and it still doesn't work.

zaster left a reply on Unable To Convert String To Float And Format It • 4 months ago

@Cronix

it outputs

12431.0

zaster started a new conversation Unable To Convert String To Float And Format It • 4 months ago

          $total_gp = Job::where('id', '>=', 1475)->sum('job_profit');
          $total_gp = (float)$total_gp;          
          $total_gp = number_format($total_gp, 2, '.', ',');

I am getting the below error

A non well formed numeric value encountered

22nd March, 2018

zaster left a reply on Database Structure - 3 Models - Many To Many • 5 months ago

@martinbean

I have given up on this , did a workaround but i know that's not the right way to do it. I need to develop my knowledge on this area and will be back to work on this in the right way.

Thank you very much for all your guidance and support :)

21st March, 2018

zaster left a reply on Database Structure - 3 Models - Many To Many • 6 months ago

@martinbean

1 Invoice can have Many Jobs right?

Also

invoice_line_item can be taken as a real invoice to the customer right?

20th March, 2018

zaster left a reply on Database Structure - 3 Models - Many To Many • 6 months ago

@martinbean

How should i get the total of the invoice_line_items of a job ? I suppose i should store it in invoices table

zaster started a new conversation Customer - Supplier - Employee - Logins • 6 months ago

I am working on developing a system which could cater to Customers, Suppliers and Employees. To achieve this i need to have different logins. How should i proceed?

When a customer is login to the system , the customer should be redirected to customer related views etc...

How should i maintain file structure should i have a Customer Folder and store all the relevant models in that Folder?

What about designing the database structure? Should i have user_types such as Customer , Supplier and Employee and then have user_roles?

16th March, 2018

zaster left a reply on Database Structure - 3 Models - Many To Many • 6 months ago

@martinbean you mean something like this a Has Many Through relationship?

jobs id - integer

InvoiceLineItems id - integer job_id - integer

Invoices id - integer invoicelineitem_id - integer

15th March, 2018

zaster left a reply on Database Structure - 3 Models - Many To Many • 6 months ago

@martinbean

The customer places a PO in January for 1000 Items so we open a job for 1000 items (Job Number - J2280) but nothing is delivered because we need time to prepare the items. Then in February requests for 250 Nos of Items

JN 2280 - IN 760

in March requests for 500 Nos

JN 2280 - IN 820

in April requests for 250 Nos (Job Completed)

JN 2280 - IN 871 at this point we have received payments for IN 760, and IN 820

zaster left a reply on Database Structure - 3 Models - Many To Many • 6 months ago

@shez1983

can a person pay for two invoices at the same time? 1 payment can have many invoices - A payment can be made for multiple invoices( I am using dynamic forms to achieve that) 1 invoice can have many payments - Because partial payment is possible

How can i make invoice_job as an entity? also Need to check on creating a view in SQL also, do you have anything that i could refer to

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.