строки таблицы срезов по размеру напечатанной страницы - PullRequest
0 голосов
/ 06 февраля 2020

Я занимаюсь разработкой приложения laravel, и у меня есть часть, где можно распечатать счет. в этой части я использую html2pdf. js для печати счета-фактуры

в контроллере:

  • выборка данных из базы данных
  • выполнение некоторых операций с данными
  • сохранение данных в массиве
  • отправка переменных в представление

в представлении:

  • il oop через массив
  • я делаю условие, когда строки достигают предельного числа, затем ломаются и записывают новую страницу:
  • курс $ может иметь такие свойства, как «км» и «точка», и каждая из них должна быть в одна строка
  • , если у $ course нет свойств, он будет в одной строке
  • , если строки достигают предела и у курса есть свойства, он должен быть напечатан на следующей странице

моя проблема:

  • как задать высоту и ширину страницы в html2pdf
  • как нарезать массив для печати на нескольких страницах, указав номер строки в страница

мой html2pdf:



       <script>
            var element = document.getElementById('printZone');
            var opt = {

            filename:     'Facture_{{ $facture->num }}_{{  $courses[0]->client->name }}.pdf',
            html2canvas: {
                scale: 4,
                dpi: 600,


            },
            jsPDF: {
                format: 'a4',
                pagesplit: true,
            } 
            };
        </script>

мой контроллер:

 $facture = Facture::where('id', $id)->with('facture_commercial')->get();
            $facture = $facture[0];
            if (isset($facture->id)) {
                $module = Module::get('Factures');
                $module->row = $facture;


                $point = new Point();

                if ($facture->documents == 1) {
                    $file = Upload::find($facture->file);
                    $url = Storage::url($file->name);
                } else {
                    $url = "";
                }


                if (isset($facture->id)) {
                    // Facture de commercial
                    $from = $facture['facture_commercial']['from'];
                    $to = $facture['facture_commercial']['to'];

                    $module = Module::get('Factures');
                    $module->row = $facture;
                    // les course validé par le commercial
                    $courses = Course::with('depart')
                        ->with('client')
                        ->with('arrive')
                        ->with('tonnage')
                        ->where('client_id', $facture->client_id)
                        ->where('status', 'ok')
                        ->where('is_billed', '!=', 'oui')
                        ->whereBetween('date', [$from, $to] )
                        ->orderBy('date', 'asc')
                        ->get();

                        $prix = new PrixFacturationController($id, $courses);

            return view('la.factures.show', [
                        'prix' => $prix,
                        'facture' => $facture,
                        "file" => $url,
                        "date" => date('d-m-Y', strtotime($facture->date)),
                        "courses" => $courses,
                        "point" => $point,
                        'module' => $module,
                        'view_col' => $this->view_col,
                        'no_header' => true,
                        'no_padding' => "no-padding",
                        'newPage' => false

                    ]);

м у вид:




    <?php
    $i = 1 ;
    $o = 0
    ;?>

        <div class="row">

            <table class="facturation-table table" style="font-size: 13px;"  >
                <thead>
                <tr>

                    <th class="text-center" width="15%">Date</th>
                    <th width="50%">DESIGNIATION</th>
                    <th>Qte</th>
                    <th class="text-center" width="17%">Prix U </th>
                    <th class="text-center" width="17%">Total</th>
                </tr>
                </thead>
                <tbody>

                @foreach($courses as $course)

                    <tr>

                        <td>{{ date('d-m-Y', strtotime($course->date))  }}</td>
                        <td class="text-left">
                            @if($course->tonnage)
                                        {{ $course->tonnage->tonnage }}
                                        _ 
                                        @endif

                                        @if($course->depart)
                                         {{  $course->depart->name }} _
                                        @endif

                                        @if($course->arrive)
                                         {{ $course->arrive->name }}  
                                        @endif


                        </td>
                        <td>{{ $prix->course_qte($course) }}</td>
                        <td>{{ number_format($prix->course_price($course),'2') }} DZD</td>
                        <td>{{ number_format($prix->course_price_total($course),'2') }} DZD</td>
                    </tr>
                    @if($course->point)
                    <?php
                    $o++;
                    ?>
                    <tr>
                        <td></td>
                        <td  class="text-left">&nbsp - {{ $course->point }}</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->point_price),'2')  }} DZD</td>
                        <td>{{ number_format(floatval($course->point_price),'2')  }} DZD</td>
                    </tr>

                    @endif
                    @if($course->km)
                    <?php
                    $o++;
                    ?>
                    <tr>
                        <td></td>
                        <td  class="text-left">&nbsp - Plus {{ $course->km }} Km</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->km_price),'2')  }} DZD</td>
                        <td>{{ number_format(floatval($course->km_price),'2')  }} DZD</td>
                    </tr>

                    @endif
                    @if($course->observation)
                     <?php
                     $o++
                     ?>
                        <td></td>
                        <td  class="text-left">&nbsp - {{ $course->observation }}</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->observation_price),'2')   }} DZD</td>
                        <td>{{ number_format(floatval($course->observation_price),'2')  }} DZD</td>
                    @endif
                       @if($i == 7)
                        <?php $newPage = true?>
                </tbody>
            </table>



            <br>
            <br>
            @if($newPage)
                <div class="row">
                    <div class="col-lg-12 ">
                        <p class="text-center"><b>page:</b> 1/2 </p>
                    </div>
                    @endif
                </div>
                <div style="page-break-after: always;"></div>
                @break
                @else
                <?php $i++ ?>
                @endif


                @endforeach
                </tbody>
                </table>
                @if($newPage)

                    <div style="height: 200px;"></div>
                    <table class="table facturation-table" style="font-size: 13px;" >
                        <thead>
                        <tr>
                              <th class="text-center" width="15%">Date</th>
                    <th width="50%">DESIGNIATION</th>
                    <th>Qte</th>
                    <th class="text-center" width="17%">Prix U </th>
                    <th class="text-center" width="17%">Total</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($courses as $index => $course)

                            @if($index >= $i)
                                <tr>

                                    <td>{{ date('d-m-Y', strtotime($course->date)) }}</td>
                                    <td class="text-left">
                                        @if($course->tonnage)
                                        {{ $course->tonnage->tonnage }}
                                        _ 
                                        @endif

                                        @if($course->depart)
                                         {{  $course->depart->name }} _
                                        @endif

                                        @if($course->arrive)
                                         {{ $course->arrive->name }}  
                                        @endif




                                    </td>
                                    <td>{{ $prix->course_qte($course) }}</td>
                               <td>{{ number_format($prix->course_price($course),'2') }} DZD</td>
                        <td>{{ number_format($prix->course_price_total($course),'2') }} DZD</td>
                                </tr>
                                @if($course->point)

                    <tr>
                        <td></td>
                        <td  class="text-left">&nbsp - {{ $course->point }}</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->point_price),'2')  }} &nbspDZD</td>
                        <td>{{ number_format(floatval($course->point_price),'2')  }} &nbspDZD</td>
                    </tr>

                    @endif

                      @if($course->km)
                    <?php
                    $o++;
                    ?>
                    <tr>
                        <td></td>
                        <td  class="text-left">&nbsp - {{ $course->km }}</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->km_price),'2')  }} DZD</td>
                        <td>{{ number_format(floatval($course->km_price),'2')  }} DZD</td>
                    </tr>

                    @endif
                    @if($course->observation)
                    <tr>
                        <td></td>
                        <td  class="text-left">&nbsp - {{ $course->observation }}</td>
                        <td>1</td>
                        <td>{{ number_format(floatval($course->observation_price),'2')   }}&nbsp DZD</td>
                        <td>{{ number_format(floatval($course->observation_price),'2')  }}&nbsp DZD</td>
                         </tr>
                    @endif

                                <?php $i++ ?>
                            @endif




                        @endforeach
                        </tbody>
                    </table>
                @endif
                <div class="row">
                    <div class="col-lg-8">

                    </div>
                    <div class="col-lg-4">

                        <table class="table total-table" style="font-size:13px;">
                            <tbody>


                             @if($prix->remise() > 0)
                              <tr>
                                <td>Total commercial</td>
                                <td><?php
                                    $totalCom = $prix->total_commercial() ;
                                    echo number_format($totalCom,'2');
                                    ?>&nbsp DZD</td>
                            </tr>
                              <tr>
                                <td>Remise {{ $facture->remise_percent }} %</td>
                                <td><?php
                                    $remise = $prix->remise() ;
                                    echo number_format($remise,'2');
                                    ?>&nbsp DZD</td>
                            </tr>
                            @endif

                            <tr>
                                <td>Total HT</td>
                                <td>{{ number_format( $prix->total_ht(), '2') }} DZD</td>
                            </tr>
                            <tr>
                                <td>TVA 19%</td>
                                <td><?php

                                    $tva =  $prix->tva_price() ;
                                    echo number_format($tva,'2');
                                    ?>&nbsp DZD</td>
                            </tr>
                            @if($prix->timbre_price() > 0)
                              <tr>
                                <td>Timbre</td>
                                <td><?php
                                    $timbre = $prix->timbre_price() ;
                                    echo number_format($timbre,'2');
                                    ?>&nbsp DZD</td>
                            </tr>
                            @endif
                            <tr>
                                <td>Total TTC</td>
                                <td><?php
                                    $ttc = $prix->ttc_price() ;

                                    echo number_format($ttc,'2');
                                    ?> &nbspDZD</td>
                            </tr>
                            </tbody>

                        </table>
                    </div>
                </div>

                <div class="row">
                    <div class="col-lg-12">
                        <p>arrêter la présente facture à la somme de {{ chiffre_en_lettre($ttc) }}</p>
                    </div>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    @if($newPage)
                        <div class="row">
                            <div class="col-lg-12">
                                <p class="text-center"><b>page:</b> 2/2 </p>
                            </div>
                            @endif
                        </div>
                </div>
        </div>

        </div>
        </div>
        <!-- end facture -->




...