Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function saveApp(){
- $userID = Session::get('user');
- if(Input::get('save')){
- $header = new AppHeader;
- $header->app_date = date('Y-m-d', strtotime(Input::get('app_date')));
- $header->partner_id = Input::get('partner_id');
- $header->branch_id = Input::get('branch_id');
- $header->doc_no = Input::get('doc_no');
- $header->total = Input::get('grand_amount') + Input::get('grand_ewt');
- $header->balance = Input::get('grand_amount') + Input::get('grand_ewt');
- $header->total_receipt = Input::get('total_amount');
- $header->payment_type = Input::get('receipt_type');
- $header->notes = Input::get('notes');
- $header->remarks = Input::get('remarks');
- $header->deskpadcurrency_id = Input::get('currency_id');
- $header->ewt_type = Input::get('ewt_type');
- $header->status = "New";
- $header->cb = Input::get('branch_company');
- $header->created_by = Session::get('user');
- $header->ewt_type = Input::get('ewt_type');
- $header->receipt_id = Input::get('receipt_id');
- $header->save();
- $countewt = count(Input::get('bill_id'));
- if($countewt > 0){
- for($i=0;$i<$countewt;$i++){
- $detail = new AppDetail;
- $detail->header_id = $header->id;
- $detail->bill_id = Input::get('bill_id')[$i];
- $detail->amount = Input::get('app_amount')[$i];
- $detail->ewt = Input::get('details_ewt')[$i];
- $detail->receipt_id = Input::get('receipt_id');
- $detail->save();
- if(Input::get('type')[$i] == "billing"){
- $billing = BillHeader::where('id', Input::get('bill_id')[$i])->first();
- $billing->applied_amount = Input::get('app_amount')[$i] + Input::get('details_ewt')[$i];
- $billing->save();
- }
- else{
- // $debit = DmHeader::where('id',Input::get('details_id')[$i])->first();
- // $debit->applied_amount = $debit->applied_amount + Input::get('app_amount')[$i];
- // $debit->balance = $debit->balance - Input::get('app_amount')[$i];
- // $debit->save();
- }
- }
- }
- $logs = new AccountingLog;
- $logs->transaction_id = $header->id;
- $logs->user_id = Session::get('user');
- $logs->action = "Saved";
- $logs->tabs = "Receipts";
- $logs->receipts = "Application";
- $logs->date = date("Y-m-d H:i:s", time());
- $logs->save();
- Session::flash('alert-success', 'Applications successfully saved.');
- return redirect()->action('Accounting\ReceiptController@reopenApp', $header->id);
- }
- else{
- $header = new AppHeader;
- $header->status = "Finalized";
- $header->app_date = date('Y-m-d', strtotime(Input::get('app_date')));
- $header->partner_id = Input::get('partner_id');
- $header->branch_id = Input::get('branch_id');
- $header->doc_no = Input::get('doc_no');
- $header->payment_type = Input::get('receipt_type');
- $header->notes = Input::get('notes');
- $header->remarks = Input::get('remarks');
- $header->deskpadcurrency_id = Input::get('currency_id');
- $header->cb = Input::get('branch_company');
- $header->created_by = $userID;
- $header->receipt_id = Input::get('receipt_id');
- $header->total_receipt = Input::get('total_amount');
- if(Input::get('receipt_type') == "Payment"){
- $header->total = Input::get('grand_amount') + Input::get('grand_ewt');
- $header->balance = Input::get('grand_amount') + Input::get('grand_ewt');
- $header->ewt_type = Input::get('ewt_type');
- }
- else{
- $header->total = Input::get('grand_ewt_amount');
- $header->balance = Input::get('grand_ewt_amount');
- }
- $header->save();
- $receiptType = Input::get('receipt_type');
- if($receiptType == "Payment"){
- $countewt = count(Input::get('bill_id'));
- if($countewt > 0){
- for($i=0;$i<$countewt;$i++){
- $detail = new AppDetail;
- $detail->header_id = $header->id;
- $detail->bill_id = Input::get('bill_id')[$i];
- $detail->amount = Input::get('app_amount')[$i];
- $detail->ewt = Input::get('details_ewt')[$i];
- $detail->receipt_id = Input::get('receipt_id');
- $detail->balance = Input::get('app_amount')[$i] + Input::get('details_ewt')[$i];
- $detail->save();
- if(Input::get('type')[$i] == "billing"){
- $receipt = ReceiptHeader::where('id',Input::get('receipt_id'))->first();
- $receipt->pending_amt = $receipt->pending_amt + (Input::get('app_amount')[$i] + Input::get('details_ewt')[$i]);
- $receipt->save();
- }
- else{
- // $debit = DmHeader::where('id',Input::get('details_id')[$i])->first();
- // $debit->applied_amount = $debit->applied_amount + Input::get('app_amount')[$i];
- // $debit->balance = $debit->balance - Input::get('app_amount')[$i];
- // $debit->save();
- }
- }
- }
- }
- else{
- $tax = count(Input::get('bill_id'));
- if($tax > 0){
- for($i=0;$i<$tax;$i++){
- $detail = new AppDetail;
- $detail->header_id = $header->id;
- $detail->bill_id = Input::get('bill_id')[$i];
- $detail->receipt_id = Input::get('receipt_id');
- $detail->balance = Input::get('ewt_amount')[$i];
- $detail->amount = Input::get('ewt_amount')[$i];
- $detail->save();
- if(Input::get('type')[$i] == "billing"){
- $receipt = ReceiptHeader::where('id',Input::get('receipt_id'))->first();
- $receipt->pending_amt = $receipt->pending_amt + Input::get('ewt_amount')[$i];
- $receipt->save();
- }
- else{
- }
- }
- }
- }
- $logs = new AccountingLog;
- $logs->transaction_id = $header->id;
- $logs->user_id = $userID;
- $logs->action = "Finalized";
- $logs->tabs = "Receipts";
- $logs->receipts = "Application";
- $logs->date = date("Y-m-d H:i:s", time());
- $logs->save();
- Session::flash('alert-success', 'Receipt successfully finalized.');
- return redirect()->action('Accounting\ReceiptController@reopenApp', $header->id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement