Skip to main content

Command Palette

Search for a command to run...

ক্লাস নং-২০(পার্ট-১৭)- invoice single, invoice payment by stripe and others

Updated
2 min read
ক্লাস নং-২০(পার্ট-১৭)- invoice single, invoice payment by stripe and others

যেহেতু আমাদের প্রজেক্টের সব কিছুই livewire দিয়ে করছি তাই আমরা এটাও করার জন্য প্রথমেই একটা component make করব।

php artisan livewire:make InvoiceEdit

এবার আমাদের user folder এর মধ্যে যে invoice folder আছে তারমধ্যে আমাদের show.blade.php file এই ফাইলের মধ্যে আমরা আমাদের livewire যে component make করলাম সেটাকে শো করাব।

এবার আমাদের invoice-edit blade file এ গিয়ে কোড গুলো লিখি।

<div>
    <h2 class="font-bold text-green-700  ">Information</h2>
    <p>Invoice to: {{$invoice->user->name}}</p>

    <table class="table-auto w-full mb-4">
        <tr>
            <th class="lms-cell-border text-left">Name</th>
            <th class="lms-cell-border">Price</th>
            <th class="lms-cell-border">Quantity</th>
            <th class="lms-cell-border text-right">Total</th>
        </tr>

        @foreach($invoice->items as $item)
        <tr>
            <td class="lms-cell-border">{{$item->name}}</td>
            <td class="lms-cell-border text-center">${{number_format($item->price, 2)}}</td>
            <td class="lms-cell-border text-center">{{$item->quantity}}</td>
            <td class="lms-cell-border text-right">${{number_format($item->price * $item->quantity, 2)}}</td>
        </tr>
        @endforeach
        <tr>
            <td colspan="3" class="lms-cell-border text-right">Subtotal</td>
            <td class="lms-cell-border text-right">${{number_format($invoice->amount()['total'], 2)}}</td>
        </tr>
        <tr>
            <td colspan="3" class="lms-cell-border text-right">Paid</td>
            <td class="lms-cell-border text-right">- ${{number_format($invoice->amount()['paid'], 2)}}</td>
        </tr>
        <tr>
            <td colspan="3" class="lms-cell-border text-right">Due</td>
            <td class="lms-cell-border text-right">${{number_format($invoice->amount()['due'], 2)}}</td>
        </tr>
    </table>




    @if($enableAddItem)
    <form class="mb-4" wire:submit.prevent="saveNewItem">
        <div class="flex mb-4">
            <div class="w-full">
                @include('components.form-field', [
                    'name' => 'name',
                    'label' => 'Name',
                    'type' => 'text',
                    'placeholder' => 'Item name',
                    'required' => 'required',
                ])
            </div>

            <div class="min-w-max ml-4">
                @include('components.form-field', [
                    'name' => 'price',
                    'label' => 'Price',
                    'type' => 'number',
                    'placeholder' => 'Type price',
                    'required' => 'required',
                ])
            </div>

            <div class="min-w-max ml-4">
                @include('components.form-field', [
                    'name' => 'quantity',
                    'label' => 'Quantity',
                    'type' => 'number',
                    'placeholder' => 'Type quantity',
                    'required' => 'required',
                ])
            </div>


        </div>
        <div class="flex mb-4">
            @include('components.wire-loading-btn')
            <button class=" bg-red-500 ml-4 py-2 px-4 font-bold text-white " wire:click="addNewItem" type="button">Cancel</button>
        </div>
    </form>
    @else
        <button class="px-4 py-2 bg-green-300 mt-4 mb-4" wire:click="addNewItem" class="underline">Add New Item</button>
    @endif


    <h3 class="font-bold text-lg mb-2">Payments</h3>
    <ul class="mb-4">
        @foreach($invoice->payments as $payment)
        <li>{{date('F j, Y - g:i:a', strtotime($payment->created_at))}} - ${{number_format($payment->amount, 2)}} - transaction ID: {{$payment->transaction_id}} <button wire:click="refund({{$payment->id}})" class="bg-red-500 text-white px-4 py-2 text-xs">Refund</button></li>
        @endforeach
    </ul>
</div>

এবং আমাদের যে component file টা আছে সেখানে নিচের কোড গুলো লিখি,।

public $invoice_id;
    public $invoice;
    public $enableAddItem = false;
    public $name;
    public $quantity;
    public $price;

    public function mount() {
        $this->invoice = Invoice::findOrFail($this->invoice_id);
    }
    public function render()
    {
        return view('livewire.invoice-edit');
    }

    public function addNewItem() {
        $this->enableAddItem = !$this->enableAddItem;
    }

    public function saveNewItem() {
        InvoiceItem::create([
            'name' => $this->name,
            'price' => $this->price,
            'quantity' => $this->quantity,
            'invoice_id' => $this->invoice_id,
        ]);

        $this->name = '';
        $this->price = '';
        $this->quantity = '';

        $this->addNewItem();

        flash()->addSuccess('Added!');

        return redirect(route('invoice-show', $this->invoice_id));
    }

এবং আমাদের যে controller আছে সেখানে id এর পরিবর্তে invoice গুলো পাঠিয়ে দেই।

return view('user.invoice.show', [
            'invoice' => Invoice::findOrFail($id),
        ]);

এবং আমাদের যে মডেল আছে সেখানে fillable property গুলো দিয়ে দেই।

এবং আমাদের আগেই subtotal calculate করা আছে আমরা সেই কোড গুলো review করলেই বুঝতে পারব আশা করি ।আর যদি কোন কিছু মিসিং থাকে আমাদের github repository তো আছেই।

আশা করি খুব সিম্পল ভাবেই বুঝতে পেরেছেন।

discord link: discord.gg/9qWUUbQ3

facebook group :web.facebook.com/groups/1661735757554627

Happy Learning

Rakibul Islam

More from this blog

We discuss basic routing

বেসিক রাউটিং সফটওয়্যার আর্কিটেকচারে রাউট হচ্ছে মৌলিক উপাদান(Basic Component). রাউট URL(URL = Uniform Resource Locator) থেকে অনুরোধ গ্রহণ করে এবং এপ্লিকেশনকে রিসোর্সের জন্য নির্দেশনা প্রদান করে। লারাভেলের রাউট সমূহ একই সাথে সুবিন্যস্ত করে রাখার জন্য r...

Jun 1, 20233 min read

Visual Studio Code এডিটর কি-বোর্ড শর্টকার্ট

এখন কোডিংয়ের স্পীড হবে রকেটের গতি যদি আপনি ব্লগটি পড়েন এবং শর্টকাট ব্যবহার করেন তাহলে চলুন শুরু করি। Visual Studio Code এডিটর কি-বোর্ড শর্টকার্টঃ MAC ও WINDOWS এর জন্য আলাদা কি-বোর্ড শর্টকাট নিচে দেওয়া হল- Visual Studio Code এর কমান্ড পেলেট কিভাবে ওপ...

Jun 1, 20233 min read
Visual Studio Code এডিটর কি-বোর্ড শর্টকার্ট

WordPress Support Engineer Input Field And Form

আজকে আমরা আলোচনা করব আমাদের WordPress Support Engineer Course এর ক্লাস ২ নিয়ে এবং আমাদের টপিক হলো html input fields. ইনপুট ফিল্ডে বিভিন্ন রকম টাইপ রয়েছে এর মধ্যে default html,html-5,iput type="text" ইত্যাদি। তো চলুন শুরু করি ।প্রথমেই আমরা আলোচনা করব ...

May 7, 20233 min read

Tailwind Css CLI ব্যাক্ষ্যা সহ Install প্রসেস

সবার প্রথমে আমাদের একটা Directory বানাতে হবে। আপনার Project এর নাম দিয়ে একটি Directory বানিয়ে ফেলুন। এরপর যেকোনো একটা Terminal ব্যবহার করে এই Directory তে ঢুকুন। npm install -D tailwindcss autoprefixer vite এই কমান্ড Terminal-এ দিবো। এক্সট্রা হিসেবে...

Apr 3, 20232 min read
Tailwind Css CLI ব্যাক্ষ্যা সহ Install প্রসেস
S

Shikhun Blog

96 posts