首页 > 解决方案 > 动态显示收据,在其标题下显示单个供应商的所有产品以及该供应商的产品总量

问题描述

我的系统会生成一张如图所示的收据:

我的系统会生成一张如图所示的收据

我的系统中还有一个制造商列表,现在我想像这样修改此收据,使产品应位于其制造商标题下,该标题还显示该制造商按该订单销售的产品总量

我的收据代码在这里

 <table>
                        <thead>
                            <tr>
                                <th class="item">QTY</th>
                                <th class="item">BON</th>
                                <th class="item">TOTAL QTY</th>
                                <th class="item">PRODUCT</th>
                                <th class="item">BATCH</th>
                                <th class="item">TRADE PRICE</th>
                                <th class="item">GST</th>
                                <th class="item">DISCOUNT</th>
                                <th class="item">TOTAL</th>
                            </tr>
                        </thead> 
                        @foreach($order->orderItems as $item) 
                        <tbody>
                            <tr>
                                <td class="item-list">{{$item->quantity}}</td>
                                <td class="item-list">{{$item->bonus_items}}</td>
                                <td class="item-list">{{$item->quantity + $item->bonus_items}}</td>
                                <td class="item-list">{{strtoupper($item->product->product_name)}}</td>
                                <td class="item-list">{{$item->product->batch_no}}</td>
                                <td class="item-list" colspan="2">{{$item->product->selling_price}}</td>
                                <td class="item-list"></td>
                                <td class="item-list">{{$item->product->selling_price *$item->quantity}}</td>
                            </tr>
                        </tbody> 
                        @endforeach
                        <tfoot>
                            <tr class="summary">
                            <?php
                                $f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
                                $words = $f->format($order->total_amount - $order->discount);
                                ?>
                                <td colspan="4">{{ ucwords($words.' Rupees') }}</td>
                                <td colspan="2"><strong>TOTAL: <strong>{{$order->total_amount}}</td>
                                <td colspan="2"><strong>DISCOUNT: <strong>{{ $order->discount }}</td>
                                <td><strong>TOTAL:<strong>Rs. {{$order->total_amount - $order->discount}}/-</td>



                            </tr>
                        </tfoot>
                    </table>

是否有我必须在这里应用的任何条件或我必须在模型或控制器文件中创建的任何功能。

标签: javascriptphplaravellaravel-8php-7.4

解决方案


首先得到一个解决方案我必须编辑 orderController.php 的变量,它正在发送这样的数据:

public function getInvoice($order){
    $order = Order::with('orderItems.product', 'salesmanRelation', 'orderBooker', 'clientRelation')->where('id', $order)->first();
    // dd($order);
    $orderItemsByVendor = [];
    foreach ($order->orderItems as $item) {
        if(isset($orderItemsByVendor[$item->product->company_name])) {
            array_push($orderItemsByVendor[$item->product->company_name]['items'], $item);
        } else {
            $total = 0;
            $company = $item->product->company_name;
            foreach($order->orderItems as $orderItem) {
                if($orderItem->product->company_name == $company) {
                    $total += $orderItem->quantity * $orderItem->product->selling_price;
                }
            }

            $orderItemsByVendor[$item->product->company_name] = ['items' => [$item], 'total' => $total];
        }
    }

    // dd($orderItemsByVendor);
    $data = ['order' => $order, 'items' => $orderItemsByVendor];
    return view('dashboard.invoice', compact('data'));
}

然后我必须像这样编辑 invoice.blade.php 文件:

                            <tbody>
                        @foreach($data['items'] as $vendor => $item) 
                            @foreach($item['items'] as $orderItem)
                                <tr>
                                    <td class="item-list">{{$orderItem->quantity}}</td>
                                    <td class="item-list">{{$orderItem->bonus_items}}</td>
                                    <td class="item-list">{{$orderItem->quantity + $orderItem->bonus_items}}</td>
                                    <td class="item-list">{{strtoupper($orderItem->product->product_name)}}</td>
                                    <td class="item-list">{{$orderItem->product->batch_no}}</td>
                                    <td class="item-list" colspan="2">{{$orderItem->product->selling_price}}</td>
                                    <td class="item-list"></td>
                                    <td class="item-list">{{$orderItem->product->selling_price *$orderItem->quantity}}</td>
                                </tr>
                            @endforeach
                            <tr>
                                <td class="vendor-heading" colspan="8">{{$vendor}}</td>
                                <td class="vendor-heading">{{$item['total']}}</td>
                            </tr>
                        @endforeach
                        </tbody>

这是所需的收据


推荐阅读