Bossino's avatar

Print Ticket after Adding a Data

Good day pips. I am struggling on printing after I click create.

When I click the create button, it will add to the database and after it will print the ticket.

<div class="modal fade" id="callModal" tabindex="-1" role="dialog" aria-labelledby="callModalLabel" aria-hidden="true">

  <div class="modal-dialog" role="document">

    <div class="modal-content">

      <div class="modal-header">

        <h5 class="modal-title" id="callModalLabel">New Call</h5>

        <button type="button" class="close" data-dismiss="modal" aria-label="Close">            
          <span aria-hidden="true">&times;</span>
        </button>

      </div>
      <div class="modal-body">

        <div class="row">

            <div class="col-md-12">

                <!--start of the form-->
                <form id="form-data" class="form-horizontal" method="POST" action="{{ route('call.store') }}"> 
                    {{ csrf_field() }}
                    <div class="row form-group">    

                        <div class="col-md-12">  
                            <input type="hidden" class="form-control" id="trans-id" name="trans_id" readonly>
                        </div>

                        <div class="col-md-12"> 
                            <label>Transaction Type:</label>
                            <input type="text" class="form-control" id="trans-name" readonly>
                        </div>

                        <div class="col-md-12"> 
                            <input type="hidden" id="called" name="called" value="NO">
                        </div>

                        <div class="col-md-12"> 

                            <label>Department:</label>

                            <select class="form-control" id="dept_id" name="dept_id" required>
                                        <option value="" data-hidden="true"  
                                                selected="selected">-- Select Department --
                                        </option>
                                            @foreach($departments as $department)
                                                <option value= "{{ $department->id }}">
                                                      {{ $department->dept_name }} 
                                                </option>
                                            @endforeach
                            </select>

                        </div>

                        <div class="col-md-12">    
                            <label>Student First Name</label>
                            <input type="text" id="firstname" class="form-control" name="firstname" required=""> 
                        </div>

                        <div class="col-md-12">    
                            <label>Student Last Name</label>
                            <input type="text" id="lastname" class="form-control" name="lastname" required> 
                        </div>

                        <div class="col-md-12">    
                            <label>Amount</label>
                            <input type="number" id="amount" class="form-control" name="amount" step=".01" required> 
                        </div>

                    </div>



            </div>

        </div>

      </div>

      <div class="modal-footer">

            <button type="submit" class="btn btn-success btn-fill pull-right" id="form-button-add" name="form-button-add" onclick="window.print()">
                CREATE <!--CREATE, SAVE AND PRINT THE TICKET-->
            </button>

            <button  data-dismiss="modal" aria-hidden="true" class="btn btn-basic pull-right" style="margin-right: 2%">
                CANCEL
            </button>             

            <div class="clearfix"></div>    

        </form>
        <!-- end of the form -->
      </div>

    </div>

  </div>

</div>

I tried that windows.onclick but its print preview was modal form. I want in the preview is the new amount, its name, and kind of transaction that are newly created after he click the create. So it means the preview would be show after the blade page file would reload. I've been trying other methods but it doesn't work. Sorry for my bad grammar I have a hard time typing in English language.

0 likes
21 replies
Bossino's avatar

I'll already tried that before but I want is directly print and not exporting to PDF before printing

Cronix's avatar
Cronix
Best Answer
Level 67

After you create the record, redirect to a controller that will display the view for that record. Do the printing there. Basically just redirect to the show() method of your controller.

Bossino's avatar

yes. I would looking for formatting and also after I add the data it would refresh first and print

Bossino's avatar

okay cronix I would try and figure it out. so you mean I place my print here

public function create()
    {
        $transactions = Transaction::where('status', 'Active')
                    ->get();
        $departments = Department::all();
        $call = Call::latest('created_at')->first();
    
    \printing code here


        return view('issue', ['transactions' => $transactions, 'departments' => $departments]);
    }

am I right?

jlrdw's avatar

No he said

redirect to a controller that will display the view for that record. Do the printing there.

You print from a view.

Of course it's formatted well.

There is also other JavaScript code floating around online for printing perhaps you can do a search for other ideas on the exact script that works the best.

However the PDF idea I gave you can be printed right away.

Humana health uses that technique when you want to print out a referral it's converted to PDF and there's a print button at upper right.

But that's up to you.

Bossino's avatar

okay so it means I will redirect it somewhere here <form id="form-data" class="form-horizontal" method="POST" action="{{ route('call.store') }}">

yeah I appreciate your PDF idea but I don't want to export it to pdf before so that it wouldn't be hassle for the users

Bossino's avatar

If you see my code <button type="submit" class="btn btn-success btn-fill pull-right" id="form-button-add" name="form-button-add" onclick="window.print()"> CREATE <!--CREATE, SAVE AND PRINT THE TICKET--> </button> the onclick window.print would work but the prn preview shows the modal form. Sadly I can't show pic here

jlrdw's avatar

Why have a modal, just put a "print" at top or bottom of final view (form). They may just want to view it only.

Bossino's avatar

no what I want

modal-ui

As you can see in the image above after the user will click create then it will add in the db and after reload there is like a ticket receipt showing the token like "C-1" like in the queuing system

Bossino's avatar

Because I gonna print it in a thermal printer

willvincent's avatar

I don't know if there are/would be any real specifics to printing with a thermal printer vs a regular print method, but assuming you can do it like you would any directly-attached printer, I would redirect to a show page, as @cronix suggested, that has an appropriate print stylesheet, and then maybe trigger window.print() in a javascript on load.

Bossino's avatar

okay I'll try that suggestion and also I understand @cronix explained. if I resolved that one I need to figure out printing without a print preview and directly print in a thermal printer

Bossino's avatar

Okay so when it will print in a thermal printer that will automatically print in a thermal print format?

Please or to participate in this conversation.