Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. public function saveApp(){
  2. $userID = Session::get('user');
  3. if(Input::get('save')){
  4. $header = new AppHeader;
  5. $header->app_date = date('Y-m-d', strtotime(Input::get('app_date')));
  6. $header->partner_id = Input::get('partner_id');
  7. $header->branch_id = Input::get('branch_id');
  8. $header->doc_no = Input::get('doc_no');
  9. $header->total = Input::get('grand_amount') + Input::get('grand_ewt');
  10. $header->balance = Input::get('grand_amount') + Input::get('grand_ewt');
  11. $header->total_receipt = Input::get('total_amount');
  12. $header->payment_type = Input::get('receipt_type');
  13. $header->notes = Input::get('notes');
  14. $header->remarks = Input::get('remarks');
  15. $header->deskpadcurrency_id = Input::get('currency_id');
  16. $header->ewt_type = Input::get('ewt_type');
  17. $header->status = "New";
  18. $header->cb = Input::get('branch_company');
  19. $header->created_by = Session::get('user');
  20. $header->ewt_type = Input::get('ewt_type');
  21. $header->receipt_id = Input::get('receipt_id');
  22. $header->save();
  23.  
  24. $countewt = count(Input::get('bill_id'));
  25. if($countewt > 0){
  26. for($i=0;$i<$countewt;$i++){
  27. $detail = new AppDetail;
  28. $detail->header_id = $header->id;
  29. $detail->bill_id = Input::get('bill_id')[$i];
  30. $detail->amount = Input::get('app_amount')[$i];
  31. $detail->ewt = Input::get('details_ewt')[$i];
  32. $detail->receipt_id = Input::get('receipt_id');
  33. $detail->save();
  34.  
  35. if(Input::get('type')[$i] == "billing"){
  36. $billing = BillHeader::where('id', Input::get('bill_id')[$i])->first();
  37. $billing->applied_amount = Input::get('app_amount')[$i] + Input::get('details_ewt')[$i];
  38. $billing->save();
  39. }
  40. else{
  41. // $debit = DmHeader::where('id',Input::get('details_id')[$i])->first();
  42. // $debit->applied_amount = $debit->applied_amount + Input::get('app_amount')[$i];
  43. // $debit->balance = $debit->balance - Input::get('app_amount')[$i];
  44. // $debit->save();
  45. }
  46. }
  47. }
  48.  
  49.  
  50. $logs = new AccountingLog;
  51. $logs->transaction_id = $header->id;
  52. $logs->user_id = Session::get('user');
  53. $logs->action = "Saved";
  54. $logs->tabs = "Receipts";
  55. $logs->receipts = "Application";
  56. $logs->date = date("Y-m-d H:i:s", time());
  57. $logs->save();
  58.  
  59. Session::flash('alert-success', 'Applications successfully saved.');
  60. return redirect()->action('Accounting\ReceiptController@reopenApp', $header->id);
  61. }
  62. else{
  63. $header = new AppHeader;
  64. $header->status = "Finalized";
  65. $header->app_date = date('Y-m-d', strtotime(Input::get('app_date')));
  66. $header->partner_id = Input::get('partner_id');
  67. $header->branch_id = Input::get('branch_id');
  68. $header->doc_no = Input::get('doc_no');
  69. $header->payment_type = Input::get('receipt_type');
  70. $header->notes = Input::get('notes');
  71. $header->remarks = Input::get('remarks');
  72. $header->deskpadcurrency_id = Input::get('currency_id');
  73. $header->cb = Input::get('branch_company');
  74. $header->created_by = $userID;
  75. $header->receipt_id = Input::get('receipt_id');
  76. $header->total_receipt = Input::get('total_amount');
  77. if(Input::get('receipt_type') == "Payment"){
  78. $header->total = Input::get('grand_amount') + Input::get('grand_ewt');
  79. $header->balance = Input::get('grand_amount') + Input::get('grand_ewt');
  80. $header->ewt_type = Input::get('ewt_type');
  81. }
  82. else{
  83. $header->total = Input::get('grand_ewt_amount');
  84. $header->balance = Input::get('grand_ewt_amount');
  85. }
  86. $header->save();
  87.  
  88. $receiptType = Input::get('receipt_type');
  89. if($receiptType == "Payment"){
  90. $countewt = count(Input::get('bill_id'));
  91. if($countewt > 0){
  92. for($i=0;$i<$countewt;$i++){
  93. $detail = new AppDetail;
  94. $detail->header_id = $header->id;
  95. $detail->bill_id = Input::get('bill_id')[$i];
  96. $detail->amount = Input::get('app_amount')[$i];
  97. $detail->ewt = Input::get('details_ewt')[$i];
  98. $detail->receipt_id = Input::get('receipt_id');
  99. $detail->balance = Input::get('app_amount')[$i] + Input::get('details_ewt')[$i];
  100. $detail->save();
  101.  
  102. if(Input::get('type')[$i] == "billing"){
  103. $receipt = ReceiptHeader::where('id',Input::get('receipt_id'))->first();
  104. $receipt->pending_amt = $receipt->pending_amt + (Input::get('app_amount')[$i] + Input::get('details_ewt')[$i]);
  105. $receipt->save();
  106. }
  107. else{
  108. // $debit = DmHeader::where('id',Input::get('details_id')[$i])->first();
  109. // $debit->applied_amount = $debit->applied_amount + Input::get('app_amount')[$i];
  110. // $debit->balance = $debit->balance - Input::get('app_amount')[$i];
  111. // $debit->save();
  112. }
  113. }
  114. }
  115. }
  116. else{
  117. $tax = count(Input::get('bill_id'));
  118. if($tax > 0){
  119. for($i=0;$i<$tax;$i++){
  120. $detail = new AppDetail;
  121. $detail->header_id = $header->id;
  122. $detail->bill_id = Input::get('bill_id')[$i];
  123. $detail->receipt_id = Input::get('receipt_id');
  124. $detail->balance = Input::get('ewt_amount')[$i];
  125. $detail->amount = Input::get('ewt_amount')[$i];
  126. $detail->save();
  127.  
  128. if(Input::get('type')[$i] == "billing"){
  129. $receipt = ReceiptHeader::where('id',Input::get('receipt_id'))->first();
  130. $receipt->pending_amt = $receipt->pending_amt + Input::get('ewt_amount')[$i];
  131. $receipt->save();
  132. }
  133. else{
  134.  
  135. }
  136. }
  137. }
  138. }
  139. $logs = new AccountingLog;
  140. $logs->transaction_id = $header->id;
  141. $logs->user_id = $userID;
  142. $logs->action = "Finalized";
  143. $logs->tabs = "Receipts";
  144. $logs->receipts = "Application";
  145. $logs->date = date("Y-m-d H:i:s", time());
  146. $logs->save();
  147.  
  148. Session::flash('alert-success', 'Receipt successfully finalized.');
  149. return redirect()->action('Accounting\ReceiptController@reopenApp', $header->id);
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement