Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
middleware(['auth']); $this->middleware('verified'); $this->section = new \stdClass(); $this->section->title = 'POS'; $this->section->heading = 'POS'; $this->section->slug = 'pos'; $this->section->folder = 'pos'; } /** * Display a listing of the resource. */ public function index() { // $section = $this->section; $pos = Pos::get(); return view($section->folder.'.index', compact('pos', 'section')); } /** * Show the form for creating a new resource. */ public function create() { // checkPermission('create-pos'); $section = $this->section; $section->heading = 'POS'; $section->title = 'Create POS'; $section->method = 'POST'; $section->route = $section->slug.'.store'; $pos = []; return view($section->folder.'.form',compact('section', 'pos')); } /** * Store a newly created resource in storage. */ public function store(StorePosRequest $request) { // // dd($request->all()); $section = $this->section; // validate user input $validator = Validator::make($request->all(), [ 'issuing' => 'required', 'supplier' => 'required', 'order_id' => 'required', 'item_name' => 'required', 'delivery_number' => 'required', 'delivery_date' => 'required', 'purchase_amount' => 'required|numeric', 'cost' => 'required|numeric', 'commission' => 'required|numeric', ]); //validation fails if ($validator->fails()) { return redirect()->back()->withInput($request->input())->withErrors($validator); } else { $profit = (int) $request->purchase_amount - (int) $request->cost - (int) $request->commission; $data = $request->all(); $data['author_ip'] = $request->ip(); $data['profit'] = $profit; Pos::create($data); $request->session()->flash('success', 'Record has been added successfully.'); return redirect()->route($section->slug.'.index'); } } /** * Display the specified resource. */ public function show(Pos $pos) { // } /** * Show the form for editing the specified resource. */ public function edit($id) { // $pos = Pos::where('id',$id)->first(); $section = $this->section; $section->heading = 'POS'; $section->title = 'Edit POS'; $section->method = 'PUT'; $section->route = [$section->slug.'.update', $pos]; return view($section->folder.'.form',compact('section', 'pos')); } /** * Update the specified resource in storage. */ public function update(UpdatePosRequest $request, $id) { // $pos = Pos::find($id); $section = $this->section; // validate user input $validator = Validator::make($request->all(), [ 'issuing' => 'required', 'supplier' => 'required', 'order_id' => 'required', 'item_name' => 'required', 'delivery_number' => 'required', 'delivery_date' => 'required', 'purchase_amount' => 'required|numeric', 'cost' => 'required|numeric', 'commission' => 'required|numeric', ]); //validation fails if ($validator->fails()) { return redirect()->back()->withInput($request->input())->withErrors($validator); } else { $profit = (int) $request->purchase_amount - (int) $request->cost - (int) $request->commission; $data = $request->all(); $data['author_ip'] = $request->ip(); $data['profit'] = $profit; $pos->update($data); $request->session()->flash('success', 'Record has been updated successfully.'); return redirect()->route($section->slug.'.index'); } } /** * Remove the specified resource from storage. */ public function destroy($pos) { // $section = $this->section; Pos::where('id',$pos)->delete(); return redirect()->route($section->slug . '.index')->with('success', 'Record has been deleted successfully.'); } public function report() { // $section = $this->section; $section->heading = 'Report'; $section->title = 'Report'; // Fetch data from the database $records = DB::table('pos') ->select('issuing', 'supplier', DB::raw('SUM(purchase_amount) as sum_poa'), DB::raw('SUM(cost) as sum_cost'), DB::raw('SUM(profit) as sum_profit')) ->groupBy('issuing', 'supplier') ->get(); // Process the data to get the required structure $data = []; foreach ($records as $record) { $data[$record->issuing]['suppliers'][] = $record; if (!isset($data[$record->issuing]['totals'])) { $data[$record->issuing]['totals'] = ['sum_poa' => 0, 'sum_cost' => 0, 'sum_profit' => 0]; } $data[$record->issuing]['totals']['sum_poa'] += $record->sum_poa; $data[$record->issuing]['totals']['sum_cost'] += $record->sum_cost; $data[$record->issuing]['totals']['sum_profit'] += $record->sum_profit; } // Calculate grand totals $grand_totals = ['sum_poa' => 0, 'sum_cost' => 0, 'sum_profit' => 0]; foreach ($data as $issuing => $values) { $grand_totals['sum_poa'] += $values['totals']['sum_poa']; $grand_totals['sum_cost'] += $values['totals']['sum_cost']; $grand_totals['sum_profit'] += $values['totals']['sum_profit']; } // dd($grand_totals); return view($section->slug.'.report', compact('section','data', 'grand_totals')); } }