zaster

Experience

4,690

1 Best Reply Awards

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

10th June, 2018

zaster started a new conversation User Type Restrictions • 1 week 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" • 4 weeks 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 • 1 month 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 • 1 month 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 • 1 month ago

@Cronix

it outputs

12431.0

zaster started a new conversation Unable To Convert String To Float And Format It • 1 month 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 • 2 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 • 3 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 • 3 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 • 3 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 • 3 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 • 3 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 • 3 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

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

@shez1983

job and pyaments will be indirectly related. What i need to understand is whether i need to maintain direct relationship between the two

I need to access payments based on job_id

as mentioned in above code

zaster started a new conversation Database Structure - 3 Models - Many To Many • 3 months ago

3 Models are there

  • Job
  • Invoice
  • Payment

Relationships between these are as below

Job and Invoice - Many to Many jobs table invoices table invoice_job table

Invoice and Payment - Many to Many invoices table payments table invoice_payment table

I need to access payment records through jobs Job and Payment will have a many to many relationship based on the other 2 models(Invoice and Payment)

What kind of table structure should i have?

I need to achieve something like this also

              @foreach ($jobs as $job)
                @foreach ($job->payments as $payment)
                  <tr>
                    <td><a href="{{ route('job.edit',$job->id) }}">{{ $payment->pivot->job_id }}</a></td>
                    <td>{{ $payment->payment_no }}</td>
                    <td>{{ $payment->payment_date }}</td>
                    <td>{{ $payment->payment_amount }}</td>
                    <td>{{ $job->job_status }}</td>
                  </tr>
                @endforeach
              @endforeach 

Should i maintain 3 tables for Jobs and Payments?

Can i use HasThrough for many to many?

14th March, 2018

zaster left a reply on Loop Issue • 3 months ago

@cmdobueno

oh! yes. You are right.

zaster left a reply on Loop Issue • 3 months ago

@wilk_randall How can i access

$job->job_status

in a $invoice loop

zaster started a new conversation Loop Issue • 3 months ago

I need to repeat

$job->job_status

in each row given from the output of the below code. Where should i place it or what loop should i use

              @foreach ($jobs as $job)
                @foreach ($job->invoices as $invoice)
                    <td><a href="{{ route('job.edit',$job->id) }}">{{ $invoice->pivot->job_id }}</a></td>
                    <td>{{ $invoice->invoice_no }}</td>
                    <td>{{ $invoice->invoice_date }}</td>
                    <td>{{ $invoice->invoice_amount }}</td>
                  </tr>
                @endforeach
              @endforeach 

zaster left a reply on Many To Many - Pivot Table • 3 months ago

I was able to achieve my task using the below

$job->invoices()->attach($invoice->id);

13th March, 2018

zaster left a reply on Many To Many - Pivot Table • 3 months ago

@biishmar

I have checked that , invoice_no is entered

zaster left a reply on Many To Many - Pivot Table • 3 months ago

@biishmar

$job->invoices()->attach($invoice->invoice_no);

Did the job but

Job::find(100)->invoices

Won't show results as per the pivot table

zaster started a new conversation Many To Many - Pivot Table • 3 months ago

How can i insert the invoice_no (instead of the 'id') to the pivot table

CreateInvoicesTable - Migration

    public function up()
    {
        Schema::create('invoices', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('invoice_no')->unsigned();
            $table->string('invoice_date')->nullable();
            $table->float('invoice_amount')->unsigned()->nullable();
            $table->timestamps();
        });

        Schema::create('invoice_job', function (Blueprint $table) {
            $table->integer('invoice_no')->unsigned();
            $table->integer('job_id')->unsigned();
            $table->primary(['invoice_no', 'job_id']);
        });
    }

Job Model

    //Many to Many
    public function invoices()
    {
        return $this->belongsToMany('App\Invoice', 'invoice_job', 'job_id', 'invoice_no');
    }

Invoice Model

    public function jobs()
    {
      return $this->belongsToMany('App\Job', 'invoice_job', 'invoice_no', 'job_id');
    }

11th March, 2018

zaster started a new conversation Dynamic Form - Database Access - Jquery • 3 months ago

I need to get the Despatch Number from the database when each dynamic form is added

          $('#add-despatch').click(function(){
            i++;
          $('<div class="despatch-section col-sm-2">'+
          '<br>'+
          '<div class="form-group">'+
          '<label class="col-form-label" for="inputDefault">Despatch</label>'+
          '</div>'+
          ' <div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_no[]" id="inputDefault" placeholder="Despatch Number">'+
          '</div>'+
          '<div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_date[]" id="inputDefault" placeholder="Despatch Date">'+
          '</div>'+
          '<div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_qty[]" id="inputDefault" placeholder="Despatch Quantity">'+
          '</div>'+
          '</div>').appendTo('#despatch');

           });

zaster left a reply on Display Text With Line Breaks • 3 months ago

{!! nl2br(e($text)) !!}

used the above but still, something like

One line.\nAnother line.

displays as one line

zaster started a new conversation Display Text With Line Breaks • 3 months ago

I need to display text (which is saved in a database) with line breaks

1st March, 2018

zaster left a reply on Dynamic Forms - Add Remove Forms - Jquery - Tutorial - Suggestion • 3 months ago

@bobbybouwmann

  1. I only can add one dynamic form, others are not appearing
  2. Not able to add around 3 form dynamic forms at the same time etc..

Update and Insert is mentioned inside JobController - update function I am not sure this is the right way to do this

zaster left a reply on Dynamic Forms - Add Remove Forms - Jquery - Tutorial - Suggestion • 3 months ago

@Snapey

This is something which i have done, but it's not working as i want yet

jobs.edit.blade.php

  @foreach ($job->despatches as $despatch)


    <div class="despatch-section col-sm-2">
  <br>
      <div class="form-group">
        <label class="col-form-label" for="inputDefault">Despatch</label>

      </div>

      <div class="form-group">
        <input type="text" class="form-control" name="despatch_no[]" id="inputDefault" placeholder="Despatch Number" value="{{ $despatch->id }}">

      </div>

      <div class="form-group">
        <input type="text" class="form-control" name="despatch_date[]" id="inputDefault" placeholder="Despatch Date" value="{{ $despatch->despatch_date }}">

      </div>

      <div class="form-group">
        <input type="text" class="form-control" name="despatch_qty[]" id="inputDefault" placeholder="Despatch Quantity" value="{{ $despatch->despatch_qty }}">
      </div>
    </div>

  @endforeach 

jquery part

<script>
    $(document).ready(function() {
      var i = 1;
            $('#add-despatch').click(function(){
            i++;
          $('<div class="despatch-section col-sm-2">'+
          '<br>'+
          '<div class="form-group">'+
          '<label class="col-form-label" for="inputDefault">Despatch</label>'+
          '</div>'+
          ' <div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_no[]" id="inputDefault" placeholder="Despatch Number">'+
          '</div>'+
          '<div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_date[]" id="inputDefault" placeholder="Despatch Date">'+
          '</div>'+
          '<div class="form-group">'+
          '<input type="text" class="form-control" name="despatch_qty[]" id="inputDefault" placeholder="Despatch Quantity">'+
          '</div>'+
          '</div>').appendTo('#container');

           });
      });        
</script>

JobController.php

public function update(Request $request, $id)
    {


      $job = Job::find($id);
      //$job->jobNumber = $request->jobNumber;
      $job->customer_name = $request->customer_name;
      $job->company_name = $request->company_name;
      $job->job_type = $request->job_type;
      $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;

      //Assumes that the maximum number of despatches will be less than 5
      for ($i=0; $i <5; $i++){
      //check whether an existing dispatch note no is there in the database
      if(jDespatch::where('id', $request->despatch_no[$i])->get()->count() ){
      //Update Record - If there is an existing record
      DB::table('j_despatches')
        ->where('job_id',$id)
        ->where('id',$request->despatch_no[$i])
        ->update(
        [
        'despatch_date' => $request->despatch_date[$i],
        'despatch_qty' => $request->despatch_qty[$i]
        ]);
        //dd($request);
        $job->save();
        return redirect()->route('job.edit', $job->id);

      }

      else {
//Insert Record
        DB::table('j_despatches')
            ->insert(
            [
            'id' => $request->despatch_no[$i],
            'despatch_date' => $request->despatch_date[$i],
            'despatch_qty' => $request->despatch_qty[$i],
            'job_id' => $id
            ]);

            $job->save();
            return redirect('job');
      }

    }


      $job->save();
      return redirect('job');

    }

zaster left a reply on Dynamic Forms - Add Remove Forms - Jquery - Tutorial - Suggestion • 3 months ago

@bobbybouwmann is it possible to use only the update function of the Controller and the edit view to add dynamic forms and update them

28th February, 2018

zaster left a reply on One Submit Button To Submit A Sequence Of Forms • 3 months ago

When i submit a Job (Job Form) next , the user will be directed to the Estimate Form. Practically the Estimate Form is not submitted all the time after the Job Form is Entered. So i need to a single button to make submit the Job Form as well as the Estimate Form (I need the Estimate form to be created because later on the User should be able to edit the Estimate Form)

zaster started a new conversation One Submit Button To Submit A Sequence Of Forms • 3 months ago

Form 1 and Form 2 has separate Urls and Usually when Form 1 is submitted the user will be directed to Submit Form 2.

What i need is to have one button which will Submit both the forms at once. Is this possible?

27th February, 2018

zaster started a new conversation Dynamic Forms - Add Remove Forms - Jquery - Tutorial • 3 months ago

Could you please suggest me a tutorial on the above mentioned

21st February, 2018

zaster left a reply on Column (Purchase Order No) Should Be Unique - Form Has Multiple Purchase Order Nos • 4 months ago

@Snapey

If you want to return an error to the user, you can use unique and then count the uniques, then also count the original POs if the numbers are different then there was a duplicate.

This is the way i need to proceed, is there anything i could refer before i could start on implementing this section

zaster started a new conversation Column (Purchase Order No) Should Be Unique - Form Has Multiple Purchase Order Nos • 4 months ago

There is one form with multiple rows where you can include multiple purchase order nos. These purchase order nos should be unique. What is the method of doing it ?

Should i do the validation part from the database side(I can make it as unique from the database side)

20th February, 2018

zaster started a new conversation 1 Form - 3 Columns - 3 Permission Types • 4 months ago

I have a requirement to have one form with 3 Columns

Column 1 should be editable by User Group 1 Column 2 should be editable by User Group 2 Column 3 should be editable by User Group 3

Should i maintain 3 views or how should i proceed?

11th February, 2018

zaster left a reply on Laravel 1 - Where To Find • 4 months ago

@st8113 is it possible to find the documentation of this also?

zaster started a new conversation Laravel 1 - Where To Find • 4 months ago

How can i find the first laravel version which was released on June 2011

6th February, 2018

zaster left a reply on Undefined Offset: 0 • 4 months ago

I managed to get this done in the wrong way. I wonder what is the right way to do this. Because i am mixing the Estimate stuff inside the JobController

My wrong way is as below mentioned

JobController.php store() function

    .
    .
    .
    $job->save();
       $estimate = DB::table('estimates')->orderBy('id', 'desc')->first();
        $id = $estimate->id + 1;
        return view('estimates.create')->with('id', $id);

Then user will submit the estimate form.

5th February, 2018

zaster left a reply on Undefined Offset: 0 • 4 months ago

@Snapey

Thank you very much for guiding me to identify the bad practices and to identify me writing bad code (I haven't understood some of the code which i have written, just was trying to get results by forgetting the correct way of doing)

i have added estimate_id as a foreign key to the jobs table

replaced

$job = Job::all()->last();

with

$job = DB::table('jobs')->orderBy('id', 'desc')->first();

replaced

    public function create()
    {
      $estimates = Estimate::all();
      return view('estimates.create', compact('estimates'));
    }

with

    public function create()
    {      
      return view('estimates.create');
    }

"Then you are creating an estimate with an id of one more than the highest job. Thats prone to failure if you ever delete a job or an estimate."

When a job is getting created , i am displaying the job number in the job creation form and the same job number will be taken as the estimate number

As per my understanding

since the Estimate model has several one to many relationships, i need to submit a blank estimate form when ever a job is created. Need to know how to do that. Is it to be done with laravel events?

4th February, 2018

zaster left a reply on Undefined Offset: 0 • 4 months ago

A record created in this way can be edited

Estimate Controller

    public function create()
    {
      $estimates = Estimate::all();
      return view('estimates.create', compact('estimates'));
    }

zaster left a reply on Undefined Offset: 0 • 4 months ago

seems like something to do with arrays

The error is on vendor\laravel\framework\src\Illuminate\Support\Collection.php

    /**
     * Get an item at a given offset.
     *
     * @param  mixed  $key
     * @return mixed
     */
    public function offsetGet($key)
    {
        return $this->items[$key];
    }

zaster left a reply on Undefined Offset: 0 • 4 months ago

@tisuchi

Actually i tried entering a record to the estimates table through the DBMS and even in that way i am unable to edit the record through

http://mysite.com/estimate/5/edit

zaster started a new conversation Undefined Offset: 0 • 4 months ago

jobs and estimates table has a one to one relationship Therefore each job will have one estimate

When a Job is created an Estimate is also should be there.

So a job get created but i am unable to edit the estimate i get an error saying

Undefined offset: 0

JobController.php looks like this

    public function create()
    {
        $job = Job::all()->last();
        $id = $job->id + 1;

        DB::table('estimates')->insert(
        ['id' => $id]
        );

        return view('jobs.create')->with('id', $id);
    }

2nd February, 2018

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

@Snapey

This worked for me. I am getting the paper1_id value as a hidden input from the edit view. As i see the issue is solved now.

      DB::table('e_papers')
              ->where('estimate_id',$id)
              ->where('id',$request->paper1_id)
              ->update(
              [
              'paper_description' => $request->paper1_description,
              'paper_qty' => $request->paper1_qty,
              'paper_each_price' => $request->paper1_each_price,
              'paper_total' => $request->paper1_total,
              'paper_vendor' => $request->paper1_vendor
              ]);

      DB::table('e_papers')
              ->where('estimate_id',$id)
              ->where('id',$request->paper2_id)
              ->update(
              [
              'paper_description' => $request->paper2_description,
              'paper_qty' => $request->paper2_qty,
              'paper_each_price' => $request->paper2_each_price,
              'paper_total' => $request->paper2_total,
              'paper_vendor' => $request->paper2_vendor
              ]);

1st February, 2018

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

The below code works for me, As i see now the only challenge is getting the id without referring the DBMS

    DB::table('e_papers')
            ->where([
              ['estimate_id', $id],
              ['id', '17'],
              ])->update(
              ['paper_description' => $request->paper1_description],
              ['paper_qty' => $request->paper1_qty],
              ['paper_each_price' => $request->paper1_each_price],
              ['paper_total' => $request->paper1_total],
              ['paper_vendor' => $request->paper1_vendor]
              );

     DB::table('e_papers')
              ->where([
                ['estimate_id', $id],
                ['id', '18'],
                ])->update(
                ['paper_description' => $request->paper2_description],
                ['paper_qty' => $request->paper2_qty],
                ['paper_each_price' => $request->paper2_each_price],
                ['paper_total' => $request->paper2_total],
                ['paper_vendor' => $request->paper2_vendor]
                );

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

the estimate_id always has 2 id values. I need to update those 2 ids with the form values

Form values for the First Id

paper1_description,
paper1_qty,
paper1_each_price,
paper1_total,
paper1_vendor,

Form values for the Second Id

paper2_description,
paper2_qty,
paper2_each_price,
paper2_total,
paper2_vendor,

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

@Snapey

i referred the e_papers table through the DBMS

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

@Snapey

One Estimate has Many ePaper

I need to click on estimate link (Which is not unique) to edit it

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

It should be something like this

Need to have some kind of logic to replace 'id'

The Below code also gives an error. I think i lack knowledge on arrays and sql

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '17' for key 'PRIMARY' (SQL: update `e_papers` set `id` = 17 where `estimate_id` = 10513)

DB::table('e_papers')
            ->where('estimate_id', $id)
            ->update(
              ['id' => 17],
              ['paper_description' => $request->paper1_description],
              ['paper_qty' => $request->paper1_qty],
              ['paper_each_price' => $request->paper1_each_price],
              ['paper_total' => $request->paper1_total],
              ['paper_vendor' => $request->paper1_vendor],
              ['id' => 18],
              ['paper_description' => $request->paper2_description],
              ['paper_qty' => $request->paper2_qty],
              ['paper_each_price' => $request->paper2_each_price],
              ['paper_total' => $request->paper2_total],
              ['paper_vendor' => $request->paper2_vendor]
            );

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

@Robstar @Snapey

estimate_id is not unique only id (which is not mentioned) is unique in e_papers table

31st January, 2018

zaster left a reply on Updating Multiple Rows In A Table • 4 months ago

id of the e_papers table should increment row by row in the table

Edit Your Profile
Update

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