RevenueController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\AccountType;
  7. use App\Models\AccountHead;
  8. use App\Models\Journal;
  9. use App\User;
  10. use App\Models\CompanyModel;
  11. class RevenueController extends Controller
  12. {
  13. function index()
  14. {
  15. $data['companies']=CompanyModel::where('status',2)->orderBy('name','asc')->get();
  16. $data['account_types']=AccountHead::where('type_id',1)->get();
  17. $data['credit_heads']=AccountHead::where('type_id',4)->get();
  18. $data['title']='Add Revenue';
  19. return view('admin.revenue.index',$data);
  20. }
  21. function store(Request $req)
  22. {
  23. $this->validate($req,[
  24. 'debit_head'=>'required',
  25. 'credit_head'=>'required',
  26. 'amount'=>'required|numeric'
  27. ]);
  28. $journal=new Journal();
  29. $journal->ref_id=$req->get('credit_head');
  30. $journal->debit_account=$req->get('debit_head');
  31. $journal->credit_account=$req->get('credit_head');
  32. $journal->description=$req->get('description');
  33. $journal->amount=$req->get('amount');
  34. $journal->is_approaved=0;
  35. $journal->created_by=\Auth::user()->id;
  36. $journal->created_at=$req->get('date',date('Y-m-d'));
  37. $journal->client_id=$req->get('client');
  38. $journal->save();
  39. $req->session()->flash('success','Revenue added successfully !');
  40. return redirect('account/revenue');
  41. }
  42. }