AccountReportController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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\User;
  7. use Auth;
  8. use App\Models\AccountType;
  9. use App\Models\AccountHead;
  10. use App\Models\Journal;
  11. use App\Models\PaymentHistory;
  12. use App\Models\JournalComment;
  13. use App\Models\CompanyModel;
  14. class AccountReportController extends Controller
  15. {
  16. function expense_report_view()
  17. {
  18. $data['credit_heads']=AccountHead::where('type_id',2)->get();
  19. $data['title']='Expense Report';
  20. return view('admin.acc_report.expense_report',$data);
  21. }
  22. function expense_report(Request $req)
  23. {
  24. $from=$req->get('from_date');
  25. $to=$req->get('to_date');
  26. $acc_head=$req->get('acc_head');
  27. if(empty($from) || empty($to)){
  28. return '';
  29. }
  30. $sql="SELECT ahd.name,j.* FROM journal j JOIN acc_head ahd ON j.ref_id=ahd.id WHERE DATE(j.created_at) >= '{$from}' AND DATE(j.created_at) <= '{$to}' AND ahd.type_id=2";
  31. if(!empty($acc_head))
  32. {
  33. $sql.=" AND ref_id={$acc_head} ";
  34. }
  35. $sql.=" order by j.id desc";
  36. $report_data=\DB::select($sql);
  37. $str="";
  38. $str.="<h4>Expense Report</h4>";
  39. $str.="<h5><strong>From</strong> {$from} <strong>To</strong> {$to}</h5>";
  40. $str.="<table class='table table-bordered table-striped'>";
  41. $str.="<thead>";
  42. $str.="<tr>";
  43. $str.="<th>Sl.</th>";
  44. $str.="<th>Date</th>";
  45. $str.="<th>Expense Name</th>";
  46. $str.="<th>Description</th>";
  47. $str.="<th>Document</th>";
  48. $str.="<th style='text-align:right;'>Amount</th>";
  49. $str.="</tr>";
  50. $str.="</thead>";
  51. $str.="<tbody>";
  52. if($report_data)
  53. {
  54. $i=1;
  55. $amnt=0;
  56. foreach($report_data as $row)
  57. {
  58. $str.="<tr>";
  59. $str.="<td>{$i}</td>";
  60. $dt=date('d M, Y',strtotime($row->created_at));
  61. $str.="<td>{$dt}</td>";
  62. $str.="<td>{$row->name}</td>";
  63. $str.="<td>{$row->description}</td>";
  64. $str.="<td><a href='".url('public/account_expense/'.$row->expense_document)."' target='_blank'>{$row->expense_document}</a></td>";
  65. $str.="<td style='text-align:right;'>{$row->amount}</td>";
  66. $amnt+= $row->amount;
  67. $str.="</tr>";
  68. $i++;
  69. }
  70. $str.="<tr>";
  71. $str.="<th colspan='5'>Total</th>";
  72. $amnt=number_format($amnt,2,'.','');
  73. $str.="<th style='text-align:right;'>{$amnt}</th>";
  74. $str.="</tr>";
  75. }else{
  76. $str.="<tr>";
  77. $str.="<td colspan='4'>No Record Found !</td>";
  78. $str.="</tr>";
  79. }
  80. $str.="</tbody>";
  81. $str.="</table>";
  82. return $str;
  83. }
  84. function revenue_report_view()
  85. {
  86. $data['companies']=CompanyModel::where('status',2)->orderBy('name')->get(['id','name']);
  87. $data['credit_heads']=AccountHead::where('type_id',4)->get();
  88. $data['title']='Revenue Report';
  89. return view('admin.acc_report.revenue_report',$data);
  90. }
  91. function revenue_report(Request $req)
  92. {
  93. $from=$req->get('from_date');
  94. $to=$req->get('to_date');
  95. $client=$req->get('client');
  96. $acc_head=$req->get('acc_head');
  97. if(empty($from) || empty($to)){
  98. return '';
  99. }
  100. $sql="SELECT ahd.name,j.* FROM journal j JOIN acc_head ahd ON j.ref_id=ahd.id WHERE DATE(j.created_at) >= '{$from}' AND DATE(j.created_at) <= '{$to}' ";
  101. if(!empty($client))
  102. {
  103. $sql.=" AND client_id={$client} ";
  104. }
  105. if(!empty($acc_head))
  106. {
  107. $sql.=" AND ref_id={$acc_head} ";
  108. }
  109. $sql.=" AND ahd.type_id=4 order by j.id desc";
  110. $report_data=\DB::select($sql);
  111. $str="";
  112. $str.="<h4>Revenue Report</h4>";
  113. $str.="<h5><strong>From</strong> {$from} <strong>To</strong> {$to}</h5>";
  114. $str.="<table class='table table-bordered table-striped'>";
  115. $str.="<thead>";
  116. $str.="<tr>";
  117. $str.="<th>Sl.</th>";
  118. $str.="<th>Date</th>";
  119. $str.="<th>Client Name</th>";
  120. $str.="<th>Purpose</th>";
  121. $str.="<th>Description</th>";
  122. $str.="<th style='text-align:right;'>Amount</th>";
  123. $str.="</tr>";
  124. $str.="</thead>";
  125. $str.="<tbody>";
  126. if($report_data)
  127. {
  128. $i=1;
  129. $amnt=0;
  130. foreach($report_data as $row)
  131. {
  132. $str.="<tr>";
  133. $str.="<td>{$i}</td>";
  134. $dt=date('d M, Y',strtotime($row->created_at));
  135. $str.="<td>{$dt}</td>";
  136. if($row->client_id != 0){
  137. $client_info=User::with(['company_data'])->find($row->client_id);
  138. $client_name=$client_info->company_data?$client_info->company_data->name:'Not Found';
  139. }else{
  140. $client_name = 'None';
  141. }
  142. $str.="<td>{$client_name}</td>";
  143. $str.="<td>{$row->name}</td>";
  144. $str.="<td>{$row->description}</td>";
  145. $str.="<td style='text-align:right;'>{$row->amount}</td>";
  146. $amnt+= $row->amount;
  147. $str.="</tr>";
  148. $i++;
  149. }
  150. $str.="<tr>";
  151. $str.="<th colspan='5'>Total</th>";
  152. $amnt=number_format($amnt,2,'.','');
  153. $str.="<th style='text-align:right;'>{$amnt}</th>";
  154. $str.="</tr>";
  155. }else{
  156. $str.="<tr>";
  157. $str.="<td colspan='6'>No Record Found !</td>";
  158. $str.="</tr>";
  159. }
  160. $str.="</tbody>";
  161. $str.="</table>";
  162. return $str;
  163. }
  164. }