403Webshell
Server IP : 139.59.63.204  /  Your IP : 216.73.217.62
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64
User : root ( 0)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/billing/app/Http/Controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/billing/app/Http/Controllers/CustomerController.php
<?php

namespace App\Http\Controllers;

use App\Models\Customer;
use App\Models\Product;
use App\Models\LineItem;
use App\Models\Invoice;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use DataTables;
use Validator;

class CustomerController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
       
       if ($request->ajax()) {
        $customers =  Customer::where('user_id', '=', auth()->user()->id);//->orderBy('id','desc');
     
        return DataTables::of($customers)
        ->addIndexColumn()
      
        ->addColumn('date', function($customer){
            return $customer->created_at->format('M d Y');
        })
        ->addColumn('c_name', function($customer){
            return  $customer->firstname.' '.$customer->lastname;
        })
        ->addColumn('action', function($customer){
            $id = $customer->id;
            $btn = '  <a href="javascript:void(0)" onclick="view(0,';
            $btn .= "'".route('customer.view',$customer->id)."'";
            $btn .=')" data-bs-toggle="modal" data-bs-target="#view"><i class="fas fa-eye text-success fs-2"></i></a>
            &nbsp; | &nbsp;
            <a href="'.route('customer.edit',$customer->id).'"><i class="fas fa-edit text-info fs-2"></i></a> &nbsp; | &nbsp;<a href="javascript:void(0)" data-bs-toggle="modal" data-bs-target="#delete" id="deleteBtn" onclick="setValue('.$customer->id.')"><i class="fas fa-trash text-danger fs-2"></i>  
                
            </a>';
            return $btn;
            })
        ->rawColumns(['c_name','action'])
        ->make(true);
        
      }
    
        return view('customers.index');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('customers.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {  
       // $this->validate($request,[
        $validator = Validator::make($request->all(), [
            'firstname' => 'required|string|max:255',
            'lastname' => 'string|max:255',
            'email' => 'required|string|email|max:255|unique:customers,email',
            'phone' => 'required|digits:10',
            'address' => 'string|max:255',            
            'city' => 'string|max:255',
            'state' => 'string|max:255',
            'country' => 'string|max:255',
            'pin' => 'digits:6',
        ]);
        if ($validator->fails()) {
            if($request->ajax())
            {
                return response()->json(array(
                    'success' => false,
                    'message' => 'There are incorect values in the form!',
                    'errors' => $validator->getMessageBag()->toArray()
                ), 422);
            }
            
           
            return redirect()->back()
                        ->withErrors($validator)
                        ->withInput();
        }

        if($request->ajax())
        {
           
            $customer = [
            'user_id' => auth()->user()->id, 
            'firstname' => $request->firstname, 
            'lastname' => $request->lastname, 
            'email' => $request->email, 
            'phone' => $request->phone,       
            'address' => $request->address, 
            'city' => $request->city, 
            'state' => $request->state, 
            'country' => $request->country, 
            'pin' => $request->pin
            ];
            $result   = Customer::create($customer);
            if($result )
            {
                return response()->json(['status'=>true,'msg'=>'Customer Added Successfully!!','customer'=>$result ]);
            }
            return response()->json(['status'=>false,'msg'=>'Fail!! To Add Customer']);
        }
        $customer   = new Customer;
        $customer->user_id = auth()->user()->id; 
        $customer->firstname = $request->firstname; 
        $customer->lastname = $request->lastname; 
        $customer->email = $request->email; 
        $customer->phone = $request->phone;       
        $customer->address = $request->address; 
        $customer->city = $request->city; 
        $customer->state = $request->state; 
        $customer->country = $request->country; 
        $customer->pin = $request->pin; 
      
        if($customer->save())
        {
            return redirect()->route('customer.index')->with('success','Customer Added Successfully!!');
        }
        return redirect()->route('customer.create')->with('fail','Fail!! To Add Customer');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Customer  $Customer
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
       
        $id   = trim($id);
        $customer = Customer::findOrFail($id);
        if(!empty($customer))
        {
            return response()->json(['data'=>$customer],200); 
        }

            return response()->json(['data'=>''],500);      
        
        
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Customer  $Customer
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $customer = Customer::findOrFail($id);
        return view('customers.edit',compact('customer'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Customer  $Customer
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[
            'firstname' => 'required|string|max:255',
            'lasttname' => 'string|max:255',
            'email' => 'required|string|email|max:255|unique:customers,email,'.$id,
            'phone' => 'required|digits:10',
            'address' => 'string|max:255',            
            'city' => 'string|max:255',
            'state' => 'string|max:255',
            'country' => 'string|max:255',
            'pin' => 'digits:6',
        ]);
        $customer   = Customer::findOrFail($id);
        $customer->user_id = auth()->user()->id; 
        $customer->firstname = $request->firstname; 
        $customer->lastname = $request->lastname; 
        $customer->email = $request->email; 
        $customer->phone = $request->phone;       
        $customer->address = $request->address; 
        $customer->city = $request->city; 
        $customer->state = $request->state; 
        $customer->country = $request->country; 
        $customer->pin = $request->pin; 

        if($customer->save())
        {
            return redirect()->route('customer.index')->with('success','Customer Updated Successfully!!');
        }
        return redirect()->route('customer.edit')->with('fail','Fail!! To Update Customer');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Customer  $Customer
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request)
    {
        $id   = trim($request->delete_id);
        $customer   = Customer::where('id',$id)->delete();
        $invoice_ids   = Invoice::where('customer_id',$id)->get('id')->toArray();
        Invoice::where('customer_id',$id)->delete();
        $invoice_ids = Arr::flatten($invoice_ids);  

        $stock =( @auth()->user()->industry->stock_management== null)?0: auth()->user()->industry->stock_management;
        if($stock != 0){
          //product id and qty to update product
          $data   = LineItem::whereIn('invoice_id',$invoice_ids)->get(['product_id','qty']);
         

          if(!is_null($data))
          {
              foreach($data as $d)
              {
                  $prod = Product::findOrFail($d->product_id);
                  $newQty = $prod->qty+$d->qty;
                  $prod->where('id',$d->product_id)->update(['qty'=>$newQty]);
              }
           }
        }
        //delete line items
        $lineItem   = LineItem::whereIn('invoice_id',$invoice_ids)->delete();
        if($customer)
        {
            return redirect()->route('customer.index')->with('success','Customer deleted Successfully!!'); 
        }
        return redirect()->route('customer.index')->with('fail','Fail!! To delete Customer');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit