/
home
/
sjslayjy
/
public_html
/
mosaram
/
app
/
Http
/
Controllers
/
Upload File
HOME
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Session; class PaymentController extends Controller { public function saveCompanyDiPayment(Request $request) { $is_valid = true; $msg = ""; $msg1 = ""; $paid_amount = $request->paid_amount; $bank_statement = new \App\BankStatement(); $bank_statement->bank_id = $request->bank_account_id; $bank_statement->type = 'payment'; $bank_statement->status = 'credit'; $bank_statement->amount = $paid_amount; $bank_statement->transaction_date = $this->dateConverter($request->payment_date); $bank_statement->reference_number = $request->bank_reference_number; $bank_statement->mode = $request->payment_mode; //added by alok if ($request->invoice_payment == '') { $bank_statement->particular = 'advanced payment'; } else { $bank_statement->particular = 'invoice payment'; } $bank_statement->transfer_type = $request->transfer_type; $bank_statement->dealer_id = $request->dealer_id; if ($request->transfer_type == 1) { $bank_statement->transferfrom = $request->product_company_id; } if ($request->transfer_type == 2) { $bank_statement->transferfrom = $request->from_dealer_id; } //end $receipt = \App\BankStatement::where('type', 'payment')->orderBy('id', 'desc')->first(); if ($receipt != null) { $current_receipt_series = $receipt->series + 1; } else { $current_receipt_series = 1; } $bank_statement->series = $current_receipt_series; if ($bank_statement->save()) { $payment_rem = ''; if ($request->invoice_payment != '') { $n = 0; $jsonData = []; foreach ($request->invoice_payment as $key => $value) { if ($key != "" && $value != "") { list($invoice_number, $invoice_id) = explode('_', $key); $invoicetype = $request->invoice_type[$key]; if ($invoicetype == 'warehouse_dis') { $invoice = \App\WarehouseDi::where('invoice_number', $invoice_number)->where('id', $invoice_id)->first(); } else { $invoice = \App\CompanyDi::where('invoice_number', $invoice_number)->where('id', $invoice_id)->first(); } if (!is_null($invoice)) { $invoice->is_paid = 1; $invoice->payment_date = $this->dateConverter($request->payment_date); if ($invoice->remaining_amount < $value) { $invoice->remaining_amount = 0; $invoice->payment_amount = $invoice->remaining_amount; } else { $invoice->remaining_amount = $invoice->remaining_amount - $value; $invoice->payment_amount = $value; } $invoice->save(); //code added by alok kumar $jsonData[$n]['invoice_number'] = $invoice->invoice_number; $jsonData[$n]['invoice_id'] = $invoice_id; $jsonData[$n]['invoice_type'] = $invoicetype; $jsonData[$n]['amount'] = $value; $jsonData[$n]['date'] = date('Y-m-d'); $n++; // end $payment = new \App\CompanyInvoicePayment(); $payment->invoice_id = $invoice->id; $payment->invoice_number = $invoice->invoice_number; //$payment->payment_amount = $request->paid_amount; $payment->payment_amount = $value; $payment->payment_date = $this->dateConverter($request->payment_date); $payment->bank_account_id = $request->bank_account_id; $payment->bank_reference_number = $request->bank_reference_number; $payment->payment_mode = $request->payment_mode; $payment->payment_id = $bank_statement->id; $payment->save(); $msg = $msg . ' ' . $invoice_number . ','; } else { $payment_rem = $payment_rem + $value; $msg1 = $msg1 . ' ' . $invoice_number . ','; } } } if ($msg != '') { $msg = 'Invoice ' . $msg . ' paid successfully.'; } if ($msg1 != '') { $msg = $msg . '----Invoice ' . $msg1 . ' not found.'; } if (count($jsonData) > 0) { $bank_statement = \App\BankStatement::find($bank_statement->id); $bank_statement->history = json_encode($jsonData); $bank_statement->save(); } } $bank_account = \App\BankAccount::find($request->bank_account_id); $perticular = "By " . $bank_account->bank->name; $ledger = new \App\CompanyInvoiceLedger(); $ledger->particular = $perticular; $ledger->type = 'Payment'; $ledger->voucher_no = $bank_statement->series; $ledger->credit = 0; if ($payment_rem != '') { $ledger->debit = $request->paid_amount - $payment_rem; } else { $ledger->debit = $request->paid_amount; } if ($request->transfer_type == 1) { $ledger->product_company_id = $request->product_company_id; } else { $ledger->from_dealer_id = $request->from_dealer_id; } $ledger->dealer_id = $request->dealer_id; $ledger->save(); } else { $is_valid = false; $msg = 'Something went wrong, Please try again later.'; } if ($is_valid == true) { if ($msg == '') { $msg = 'Advanced Payment paid successfully.'; } return redirect()->back()->with('success', $msg); } else { return redirect()->back()->with('error', $msg); } } public function invoiceRefundAmount(Request $request) { $response = array(); $validator = \Validator::make( $request->all(), array( 'retailer_id3' => 'required', 'dealer_id3' => 'required', 'transaction_date' => 'required', 'type' => 'required', 'bank' => 'required', 'payment_mode' => 'required', 'reference_number' => 'required', 'against' => 'required', 'particular3' => 'required', 'refund_amount' => 'required' ) ); if ($validator->fails()) { $response['flag'] = false; $response['errors'] = $validator->getMessageBag(); } else { // dd($request->all()); $partyLedgerRefund = \App\PartyInvoiceLedger::where(['type' => 'Receipt', 'against' => $request->against, 'retailer_id' => $request->retailer_id3, 'dealer_id' => $request->dealer_id3])->first(); // dd($partyLedgerRefund); $bankStatementRefund = \App\BankStatement::where('series', (int)$partyLedgerRefund->against)->where('type', 'receipt')->first(); // dd($bankStatementRefund); $bankStatement = new \App\BankStatement(); $partyLedger = new \App\PartyInvoiceLedger(); $series = \App\BankStatement::where('type', 'payment')->orderBy('id', 'desc')->first(); $lists = \App\PartyInvoiceLedger::join('bank_statements', 'bank_statements.series', 'party_invoice_ledgers.against')->where(['party_invoice_ledgers.retailer_id' => $request->retailer_id3, 'party_invoice_ledgers.dealer_id' => $request->dealer_id3, 'party_invoice_ledgers.type' => 'Receipt'])->where('party_invoice_ledgers.against', $request->against)->where('bank_statements.type', 'receipt')->select('bank_statements.series', 'bank_statements.amount', 'bank_statements.is_refund', 'bank_statements.refund_series', 'bank_statements.history', 'party_invoice_ledgers.refund_against')->first(); $totalAmount = 0; $n = 0; // dd($lists); $updateList = []; if ($lists != '') { // foreach ($lists as $key => $value) { // dd($value->amount); $refund_against = json_decode($lists->refund_against, true); if ($refund_against != '') { $totalRefundAmout = 0; foreach ($refund_against as $v) { // dd($v); $amount = \App\BankStatement::where(['series' => (int)$v, 'type' => 'payment'])->first(); $totalRefundAmout += $amount->amount; } // echo $totalRefundAmout.'<br>'; $updateList['totalAmount'] = $totalRefundAmout; $updateList['credit'] = $lists->amount; $updateList['against'] = $lists->series; $updateList['response'] = 'hello'; } else { $updateList['totalAmount'] = 0; $updateList['credit'] = $lists->amount; $updateList['against'] = $lists->series; $updateList['response'] = 'he'; } // dd($updateList); // dd(); // dd(); // dd((double)$totalAmount); # code... // $n++; // } // exit; // dd($updateList); } // if($bankStatementRefund->amount>=$request->refund_amount){ if ((float)$updateList['credit'] >= (float)($updateList['totalAmount'] + $request->refund_amount)) { if ($series != '') { $bankStatement->series = ($series->series + 1); $partyLedger->against = ($series->series + 1); $jsonSeries = []; if ($partyLedgerRefund->refund_against != '') { $jsonSeries = json_decode($partyLedgerRefund->refund_against, true); // dd($jsonSeries); array_push($jsonSeries, ($series->series + 1)); $partyLedgerRefund->refund_against = json_encode($jsonSeries, true); $bankStatementRefund->refund_series = json_encode($jsonSeries, true); } else { array_push($jsonSeries, ($series->series + 1)); $partyLedgerRefund->refund_against = json_encode($jsonSeries, true); $bankStatementRefund->refund_series = json_encode($jsonSeries, true); // dd(json_encode($jsonSeries)); } // $partyLedgerRefund->refund_against=($series->series + 1); } else { $bankStatement->series = 1; $partyLedger->against = 1; $jsonSeries = []; array_push($jsonSeries, 1); $partyLedgerRefund->refund_against = json_encode($jsonSeries, true); $bankStatementRefund->refund_series = json_encode($jsonSeries, true); // $partyLedgerRefund->refund_against=1; } // $bankStatement->save(); if ($bankStatementRefund->history != '') { // $lists = \App\PartyInvoiceLedger::join('bank_statements','bank_statements.series','party_invoice_ledgers.against')->where(['party_invoice_ledgers.retailer_id'=>$request->retailer_id3,'party_invoice_ledgers.dealer_id'=>$request->dealer_id3,'party_invoice_ledgers.type'=>'credit'])->where('party_invoice_ledgers.against',$request->against)->where('bank_statements.type','receipt')->select('bank_statements.series','bank_statements.amount','bank_statements.is_refund','bank_statements.refund_series','bank_statements.history','party_invoice_ledgers.refund_against')->first(); // $totalAmount=0; // $n=0; // // dd($lists); // $updateList=[]; // if($lists!=''){ // // foreach ($lists as $key => $value) { // // dd($value->amount); // $refund_against=json_decode($lists->refund_against,true); // if($refund_against!=''){ // $totalRefundAmout=0; // foreach($refund_against as $v){ // // dd($v); // $amount=\App\BankStatement::where(['series'=>(int)$v,'type'=>'payment'])->first(); // $totalRefundAmout+=$amount->amount; // } // // echo $totalRefundAmout.'<br>'; // $updateList['totalAmount']=$totalRefundAmout; // $updateList['credit']=$lists->amount; // $updateList['against']=$lists->series; // $updateList['response']='hello'; // }else{ // $updateList['totalAmount']=0; // $updateList['credit']=$lists->amount; // $updateList['against']=$lists->series; // $updateList['response']='he'; // } // // dd($updateList); // // dd(); // // dd(); // // dd((double)$totalAmount); // # code... // // $n++; // // } // // exit; // // dd($updateList); // } // if($updateList['credit']>=$updateList['totalAmount']+$request->refund_amount){ // dd($updateList['totalAmount']); // }else{ // dd($updateList['credit']); // } $invoicesDetails = json_decode($bankStatementRefund->history, true); // dd($invoicesDetails); $totalRefundAmount = 0; $totalAmount = 0; foreach ($invoicesDetails as $invoice) { $totalRefundAmount += (float)$invoice['refund_amount']; $totalAmount += (float)$invoice['amount']; } // dd($updateList['totalAmount']); // dd($updateList['credit']); // if() // echo $totalAmount; // dd((float)$totalAmount); // dd((float)($request->refund_amount+$totalRefundAmount)); // die; // if((float)$totalAmount>=(float)($request->refund_amount+$totalRefundAmount)){ // if((float)$updateList['credit']>=(float)($updateList['totalAmount']+$request->refund_amount)){ // dd((float)$request->refund_amount); // if($totalRefundAmount!=$totalAmount){ if ((float)$updateList['totalAmount'] != (float)$updateList['credit']) { $partyLedger->retailer_id = $request->retailer_id3; $partyLedger->dealer_id = $request->dealer_id3; $partyLedger->type = 'Payment'; $partyLedger->against = $request->against; $partyLedger->particular = 'Against- ' . $request->against . ' - ' . $bankStatement->series . ' ' . $request->particular3; $partyLedger->debit = $request->refund_amount; $partyLedger->against = $bankStatement->series; $bankStatement->bank_id = $request->bank; $bankStatement->type = 'payment'; $bankStatement->status = 'credit'; $bankStatement->mode = $request->payment_mode; $bankStatement->particular = getModelById('Retailer', $request->retailer_id3)->name . 'Vocher No- ' . $bankStatementRefund->series . ' ' . $request->particular3; $bankStatement->amount = $request->refund_amount; $bankStatement->dealer_id = $request->dealer_id3; $bankStatement->save(); $partyLedgerRefund->save(); $n = 0; $refund_amount = (float)$request->refund_amount; $jsonRefundHistory = []; $jsonDataUpdate = []; $refundAmt = 0; foreach ($invoicesDetails as $invoice) { // $recipt_id = \App\BankStatement::orderBy('id', 'desc')->first(); $loading_slip_invoice = \App\LoadingSlipInvoice::where('id', $invoice['invoice'])->first(); $jsonDataUpdate[$n]['invoice'] = $invoice['invoice']; $jsonDataUpdate[$n]['invoice_number'] = $invoice['invoice_number']; $jsonDataUpdate[$n]['amount'] = (float)$invoice['amount']; $jsonDataUpdate[$n]['date'] = $invoice['date']; if ($refund_amount >= (float)$invoice['amount']) { if ((float)$invoice['amount'] != (float)$invoice['refund_amount']) { // $jsonRefundHistory[$n]['invoice'] = $invoice['invoice']; // $jsonRefundHistory[$n]['invoice_number'] = $invoice['invoice_number']; // $jsonRefundHistory[$n]['amount'] = (float)$invoice['amount']; // $jsonDataUpdate[$n]['date'] = $invoice['date']; // $jsonRefundHistory[$n]['refund_amount'] = (float)$invoice['amount']; // $jsonRefundHistory[$n]['refund_against_series'] = $request->against; // $jsonRefundHistory[$n]['refund_date'] = $this->dateConverter1($request->transaction_date); if ($invoice['refund_amount'] != 0) { $jsonDataUpdate[$n]['refund_amount'] = (float)$invoice['refund_amount'] + (float)$refund_amount; } else { $jsonDataUpdate[$n]['refund_amount'] = (float)$invoice['amount']; } // if($loading_slip_invoice->refund_amount!=($loading_slip_invoice->total-$loading_slip_invoice->remaining_amount)){ if ($loading_slip_invoice->remaining_amount != ($loading_slip_invoice->total)) { // if($loading_slip_invoice->refund_amount>0){ if ($loading_slip_invoice->remaining_amount > 0) { $loading_slip_invoice->refund_amount = $loading_slip_invoice->refund_amount + (float)$invoice['amount']; $loading_slip_invoice->remaining_amount = $loading_slip_invoice->remaining_amount + (float)$invoice['amount']; // Role Back Count if ($loading_slip_invoice->role_back_count > 0) { $loading_slip_invoice->role_back_count = $loading_slip_invoice->role_back_count + 1; } else { $loading_slip_invoice->role_back_count = 1; } } else { $loading_slip_invoice->refund_amount = (float)$invoice['amount']; $loading_slip_invoice->remaining_amount = (float)$invoice['amount']; // Role Back Count if ($loading_slip_invoice->role_back_count > 0) { $loading_slip_invoice->role_back_count = $loading_slip_invoice->role_back_count + 1; } else { $loading_slip_invoice->role_back_count = 1; } } } // Party Refund History Maintain $recipt_id = \App\BankStatement::orderBy('id', 'desc')->first(); $partyRefundInvoice = new \App\PartyRefundInvoice(); $partyRefundInvoice->invoice_id = $invoice['invoice']; $partyRefundInvoice->refund_date = $this->dateConverter1($request->transaction_date); $partyRefundInvoice->bank_account_id = $request->bank; $partyRefundInvoice->bank_reference_number = $request->reference_number; $partyRefundInvoice->payment_mode = $request->payment_mode; $partyRefundInvoice->receipt_id = $bankStatement->id; $partyRefundInvoice->refund_amount = (float)$invoice['amount']; $partyRefundInvoice->save(); } else { $jsonDataUpdate[$n]['refund_amount'] = (float)$invoice['amount']; } $refund_amount = (float)$refund_amount - (float)$invoice['amount']; } else { if ($invoice['amount'] != $invoice['refund_amount']) { // $Invoice_refund=((float)$invoice['refund_amount']+(float)$refund_amount)-(float)$invoice['amount']; // $Invoice_refund=$refund_amount-$Invoice_refund; // $jsonRefundHistory[$n]['invoice'] = $invoice['invoice']; // $jsonRefundHistory[$n]['invoice_number'] = $invoice['invoice_number']; // $jsonRefundHistory[$n]['amount'] = $invoice['amount']; // $jsonDataUpdate[$n]['date'] = $invoice['date']; // $jsonRefundHistory[$n]['refund_amount'] =(float)$Invoice_refund; // $jsonRefundHistory[$n]['refund_against_series'] = $request->against; // $jsonRefundHistory[$n]['refund_date'] = $this->dateConverter1($request->transaction_date); if ($invoice['refund_amount'] != 0) { if (($invoice['refund_amount'] + (float)$refund_amount) > $invoice['amount']) { // dd('hi3'); $invoice_Refund = ((float)$invoice['refund_amount'] + (float)$refund_amount) - (float)$invoice['amount']; $invoice_refund = $refund_amount - $invoice_Refund; $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$invoice_refund; } else { if ($invoice['amount'] > $refund_amount) { // dd($invoice['refund_amount']+(float)$refund_amount); $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$refund_amount; // dd($jsonDataUpdate[$n]['refund_amount']); // $refund_amount=0; } else { // dd('hi2'); $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$refund_amount; } } } else { // $totalRefundAmount; // $totalAmount; if ($invoice['amount'] > $refund_amount) { $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$refund_amount; // $refund_amount=0; } else { $jsonDataUpdate[$n]['refund_amount'] = (float)$refund_amount; } // $jsonDataUpdate[$n]['refund_amount'] =(float)$refund_amount; } // if($loading_slip_invoice->refund_amount!=($loading_slip_invoice->total-$loading_slip_invoice->remaining_amount)){ if ($loading_slip_invoice->remaining_amount != ($loading_slip_invoice->total)) { if ($invoice['refund_amount'] != 0) { if (($invoice['refund_amount'] + (float)$refund_amount) > $invoice['amount']) { $invoice_Refund1 = ((float)$invoice['refund_amount'] + (float)$refund_amount) - (float)$invoice['amount']; $invoice_refund1 = $refund_amount - $invoice_Refund1; $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$invoice_refund1; } else { if ($invoice['amount'] > $refund_amount) { // dd($invoice['refund_amount']+(float)$refund_amount); $invoice_refund1 = (float)$refund_amount; $jsonDataUpdate[$n]['refund_amount'] = $invoice['refund_amount'] + (float)$invoice_refund1; // dd($jsonDataUpdate[$n]['refund_amount']); $refund_amount = 0; } else { // dd('hi2'); $invoice_refund1 = (float)$refund_amount; $jsonDataUpdate[$n]['refund_amount'] = (float)$invoice_refund1; } } } else { if ($invoice['amount'] > $refund_amount) { $invoice_refund1 = (float)$refund_amount; $refund_amount = 0; } else { $invoice_refund1 = (float)$refund_amount; } // $invoice_refund1 =(float)$refund_amount; } // if($loading_slip_invoice->refund_amount>0){ if ($loading_slip_invoice->remaining_amount > 0) { // $invoice_refund1=((float)$invoice['refund_amount']+(float)$refund_amount)-(float)$invoice['amount']; // $invoice_refund1=$refund_amount-$invoice_refund1; if ($invoice_refund1 != 0) { $loading_slip_invoice->refund_amount = $loading_slip_invoice->refund_amount + (float)$invoice_refund1; $loading_slip_invoice->remaining_amount = $loading_slip_invoice->remaining_amount + (float)$invoice_refund1; $loading_slip_invoice->is_refund = 1; // Role Back Count if ($loading_slip_invoice->role_back_count > 0) { $loading_slip_invoice->role_back_count = $loading_slip_invoice->role_back_count + 1; } else { $loading_slip_invoice->role_back_count = 1; } } } else { // $invoice_refund1=$refund_amount; if ($invoice_refund1 != 0) { $loading_slip_invoice->refund_amount = (float)$invoice_refund1; $loading_slip_invoice->remaining_amount = (float)$invoice_refund1; $loading_slip_invoice->is_refund = 1; // Role Back Count if ($loading_slip_invoice->role_back_count > 0) { $loading_slip_invoice->role_back_count = $loading_slip_invoice->role_back_count + 1; } else { $loading_slip_invoice->role_back_count = 1; } } } // Party Refund History Maintain if ($invoice_refund1 != 0) { $partyRefundInvoice = new \App\PartyRefundInvoice(); $partyRefundInvoice->invoice_id = $invoice['invoice']; $partyRefundInvoice->refund_date = $this->dateConverter1($request->transaction_date); $partyRefundInvoice->bank_account_id = $request->bank; $partyRefundInvoice->bank_reference_number = $request->reference_number; $partyRefundInvoice->payment_mode = $request->payment_mode; $partyRefundInvoice->receipt_id = $bankStatement->id; $partyRefundInvoice->refund_amount = (float)$invoice_refund1; $partyRefundInvoice->refund_amount = (float)$invoice_refund1; $partyRefundInvoice->save(); } if (isset($invoice_Refund1)) { $refund_amount = $invoice_Refund1; } } } else { $jsonDataUpdate[$n]['refund_amount'] = (float)$invoice['amount']; } } // $partyRefundInvoice->save(); if ($loading_slip_invoice->is_refund == 1) { $loading_slip_invoice->is_refund = $loading_slip_invoice->is_refund; } $loading_slip_invoice->save(); $n++; } // dd($jsonDataUpdate); // if($jsonRefundHistory!=[]){ // if(sizeof($jsonRefundHistory)==1){ // foreach($jsonRefundHistory as $jsonRefundHistory){ // $jsonRefundHistory= json_encode($jsonRefundHistory,true); // } // }else{ // $jsonRefundHistory= json_encode($jsonRefundHistory,true); // } // $bankStatement->history = $jsonRefundHistory; // } $jsonDataUpdate = json_encode($jsonDataUpdate, true); // if($jsonRefundHistory!=''){ // $bankStatement->history = $jsonRefundHistory; // } // $bankStatement->history = $jsonRefundHistory; $bankStatement->transaction_date = $this->dateConverter1($request->transaction_date); $bankStatementRefund->history = $jsonDataUpdate; $partyLedger->save(); $bankStatement->save(); $bankStatementRefund->is_refund = 1; $bankStatementRefund->save(); } else { $response['success'] = false; $response['msg'] = 'Refund Already Paid'; return response()->json($response); exit; } $response['success'] = true; $response['msg'] = 'Refund Invoice Successfully'; } else { $jsonRefundHistory = null; $jsonDataUpdate = null; $partyLedger->retailer_id = $request->retailer_id3; $partyLedger->dealer_id = $request->dealer_id3; $partyLedger->type = 'Payment'; $partyLedger->against = $request->against; $partyLedger->particular = 'Against- ' . $request->against . ' - ' . $bankStatement->series . ' ' . $request->particular3; $partyLedger->debit = $request->refund_amount; $partyLedger->against = $bankStatement->series; $bankStatement->bank_id = $request->bank; $bankStatement->type = 'payment'; $bankStatement->status = 'credit'; $bankStatement->mode = $request->payment_mode; $bankStatement->particular = getModelById('Retailer', $request->retailer_id3)->name . 'Vocher No- ' . $bankStatementRefund->series . ' ' . $request->particular3; $bankStatement->amount = $request->refund_amount; $bankStatement->dealer_id = $request->dealer_id3; // $bankStatement->history = $jsonRefundHistory; $bankStatement->transaction_date = $this->dateConverter1($request->transaction_date); $partyLedger->save(); $bankStatement->save(); // $bankStatementRefund->history=$jsonDataUpdate; $bankStatementRefund->is_refund = 1; $bankStatementRefund->save(); $partyLedgerRefund->save(); $response['success'] = true; $response['msg'] = 'Refund Successfully'; } } else { $response['success'] = false; $response['msg'] = 'Refund Amount is Grater than Paid Amount!!'; } $response['flag'] = true; } return response()->json($response); } function partyAgianstList(Request $request) { $response = array(); $validator = \Validator::make( $request->all(), array( 'retailer_id' => 'required', 'dealer_id' => 'required', ) ); if ($validator->fails()) { } else { $response['against_list'] = []; $lists = \App\PartyInvoiceLedger::join('bank_statements', 'bank_statements.series', 'party_invoice_ledgers.against')->where(['party_invoice_ledgers.retailer_id' => $request->retailer_id, 'party_invoice_ledgers.dealer_id' => $request->dealer_id, 'party_invoice_ledgers.type' => 'Receipt'])->where('party_invoice_ledgers.against', '!=', '')->where('bank_statements.type', 'receipt')->select('bank_statements.series', 'bank_statements.amount', 'bank_statements.is_refund', 'bank_statements.refund_series', 'bank_statements.history', 'party_invoice_ledgers.refund_against')->get(); $totalAmount = 0; $n = 0; $updateList = []; if ($lists != '') { foreach ($lists as $key => $value) { $refund_against = json_decode($value->refund_against, true); if ($refund_against != '') { $totalRefundAmout = 0; foreach ($refund_against as $v) { $amount = \App\BankStatement::where(['series' => (int)$v, 'type' => 'payment'])->first(); $totalRefundAmout += $amount->amount; } if ($value->amount != $totalRefundAmout) { $updateList[$n]['credit'] = $value->amount; $updateList[$n]['against'] = $value->series; $updateList[$n]['response'] = 'hello'; } } else { $updateList[$n]['credit'] = $value->amount; $updateList[$n]['against'] = $value->series; $updateList[$n]['response'] = 'he'; } $n++; } } $response['against_list'] = $updateList; } return response()->json($response); } public function saveWarehouseDiPayment(Request $request) { $invoice = \App\WarehouseDi::where('id', $request->invoice_id)->first(); if (is_null($invoice)) { return redirect()->back()->with('error', 'Invoice Not found'); } else { if ($invoice->remaining_amount >= $request->paid_amount) { $invoice->remaining_amount = $invoice->remaining_amount - $request->paid_amount; if ($invoice->remaining_amount == 0) { $invoice->is_paid = 1; } if ($invoice->save()) { $payment = new \App\CompanyInvoicePayment(); $payment->invoice_id = $invoice->id; $payment->invoice_number = $invoice->invoice_number; $payment->payment_amount = $request->paid_amount; $payment->payment_date = $this->dateConverter($request->payment_date); $payment->bank_account_id = $request->bank_account_id; $payment->bank_reference_number = $request->bank_reference_number; $payment->payment_mode = $request->payment_mode; $payment->save(); $ledger = \App\CompanyInvoiceLedger::where('dealer_id', $invoice->dealer_id)->where('product_company_id', $invoice->product_company_id)->orderBy('id', 'desc')->first(); $perticular = "Credit Against Invoice " . $invoice->invoice_number . " ( " . $invoice->product . " )"; if (!is_null($ledger)) { $balance = $ledger->balance; $ledger = new \App\CompanyInvoiceLedger(); $ledger->product_company_id = $invoice->product_company_id; $ledger->dealer_id = $invoice->dealer_id; $ledger->particular = $perticular; $ledger->type = 'debit'; $ledger->credit = 0; $ledger->debit = $request->paid_amount; $ledger->balance = $balance - $request->paid_amount; $ledger->save(); } else { $ledger = new \App\CompanyInvoiceLedger(); $ledger->product_company_id = $invoice->product_company_id; $ledger->dealer_id = $invoice->dealer_id; $ledger->particular = $perticular; $ledger->type = 'debit'; $ledger->credit = 0; $ledger->debit = $request->paid_amount; $ledger->balance = $request->paid_amount; $ledger->save(); } return redirect()->back()->with('success', 'Payment Details Saved Successfully'); } else { return redirect()->back()->with('error', 'Something Went Wrong'); } } else { return redirect()->back()->with('error', 'The paid amount is greater than the remaining Company Invoice.'); } } } public function saveLoadingInvoicePayment(Request $request) { $is_valid = true; $msg = ""; if ($request->invoice_payment != "") { $paid_amount = $request->paid_amount; $retailer = getModelById('Retailer', $request->retailer_id); $bank_particular = $retailer->name . " - " . $retailer->address; $bank_statement = new \App\BankStatement(); $bank_statement->bank_id = $request->bank_account_id; $bank_statement->particular = $bank_particular; $bank_statement->type = 'receipt'; $bank_statement->status = 'debit'; $bank_statement->amount = $paid_amount; $bank_statement->dealer_id = $request->dealer_id; $bank_statement->transaction_date = $this->dateConverter($request->payment_date); $bank_statement->reference_number = $request->bank_reference_number; $bank_statement->mode = $request->payment_mode; $receipt = \App\BankStatement::where('type', 'receipt')->orderBy('id', 'desc')->first(); if ($receipt == null) { $current_receipt_series = 1; } else { $current_receipt_series = $receipt->series + 1; } $bank_statement->series = $current_receipt_series; if ($bank_statement->save()) { $jsonData = []; $n = 0; foreach ($request->invoice_payment as $key => $value) { if ($key != "" && $value != "") { $invoice_id = $key; $invoice = \App\LoadingSlipInvoice::where('id', $invoice_id)->first(); if (is_null($invoice)) { $is_valid = false; $msg = "Invoice Not found"; } else if ($value > $invoice->remaining_amount) { $is_valid = false; $msg = 'Amount is greater than remaining amount(' . $invoice->remaining_amount . ')'; } else if ($invoice->remaining_amount == 0) { $is_valid = false; $msg = 'Invoice Already Paid'; } else { $invoice->is_paid = 1; $invoice->remaining_amount = $invoice->remaining_amount - $value; $jsonData[$n]['invoice'] = $invoice_id; $jsonData[$n]['invoice_number'] = $invoice->invoice_number; $jsonData[$n]['amount'] = $value; $jsonData[$n]['date'] = date('d/m/Y'); $jsonData[$n]['refund_amount'] = (float)0; $n++; if ($invoice->save()) { $payment = new \App\PartyInvoicePayment(); $payment->invoice_id = $invoice_id; $payment->payment_amount = $value; $payment->payment_date = $this->dateConverter($request->payment_date); $payment->bank_account_id = $request->bank_account_id; $payment->bank_reference_number = $request->bank_reference_number; $payment->payment_mode = $request->payment_mode; $payment->receipt_id = $bank_statement->id; $payment->save(); /*--------------------------tally payment----------------------------------*/ $xmlRequest = ' <ENVELOPE> <HEADER> <TALLYREQUEST>Import Data</TALLYREQUEST> </HEADER> <BODY> <IMPORTDATA> <REQUESTDESC> <REPORTNAME>Vouchers</REPORTNAME> <STATICVARIABLES> <SVCURRENTCOMPANY>MOSARAM SHIVRAM DAS</SVCURRENTCOMPANY> </STATICVARIABLES> </REQUESTDESC> <REQUESTDATA> <TALLYMESSAGE> <VOUCHER REMOTEID="" VCHTYPE="Receipt" ACTION="Create" OBJVIEW="Accounting Voucher View"> <OLDAUDITENTRYIDS.LIST TYPE="Number"> <OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS> </OLDAUDITENTRYIDS.LIST> <DATE>20220402</DATE> <GUID/> <NARRATION>import receipt</NARRATION> <TAXUNITNAME>Default Tax Unit</TAXUNITNAME> <VOUCHERTYPENAME>Receipt</VOUCHERTYPENAME> <VOUCHERNUMBER>' . $invoice->invoice_number . '</VOUCHERNUMBER> <PARTYLEDGERNAME>' . $retailer->name . ',' . $retailer->address . '</PARTYLEDGERNAME> <CSTFORMISSUETYPE/> <CSTFORMRECVTYPE/> <FBTPAYMENTTYPE>Default</FBTPAYMENTTYPE> <PERSISTEDVIEW>Accounting Voucher View</PERSISTEDVIEW> <VCHGSTCLASS/> <EFFECTIVEDATE>20220402</EFFECTIVEDATE> <HASCASHFLOW>Yes</HASCASHFLOW> <ALLLEDGERENTRIES.LIST> <LEDGERNAME>' . $retailer->name . ',' . $retailer->address . '</LEDGERNAME> <GSTCLASS/> <ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE> <AMOUNT>' . $value . '</AMOUNT> <CATEGORY></CATEGORY> </ALLLEDGERENTRIES.LIST> <ALLLEDGERENTRIES.LIST> <OLDAUDITENTRYIDS.LIST TYPE="Number"> <OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS> </OLDAUDITENTRYIDS.LIST> <LEDGERNAME>HDFC Bank Limited</LEDGERNAME> <GSTCLASS/> <ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE> <LEDGERFROMITEM>No</LEDGERFROMITEM> <REMOVEZEROENTRIES>No</REMOVEZEROENTRIES> <ISPARTYLEDGER>Yes</ISPARTYLEDGER> <ISLASTDEEMEDPOSITIVE>Yes</ISLASTDEEMEDPOSITIVE> <AMOUNT>-' . $value . '</AMOUNT> <BANKALLOCATIONS.LIST> <DATE>20220402</DATE> <INSTRUMENTDATE></INSTRUMENTDATE> <NAME>' . $invoice->invoice_number . '</NAME> <TRANSACTIONTYPE>Cheque/DD</TRANSACTIONTYPE> <PAYMENTFAVOURING>' . $retailer->name . ',' . $retailer->address . '</PAYMENTFAVOURING> <UNIQUEREFERENCENUMBER>' . $invoice->invoice_number . '</UNIQUEREFERENCENUMBER> <PAYMENTMODE>Transacted</PAYMENTMODE> <STATUS>No</STATUS> <CHEQUEPRINTED> 1</CHEQUEPRINTED> <AMOUNT>-' . $value . '</AMOUNT> </BANKALLOCATIONS.LIST> </ALLLEDGERENTRIES.LIST> </VOUCHER> </TALLYMESSAGE> </REQUESTDATA> </IMPORTDATA> </BODY> </ENVELOPE>'; $headers = array("Content-type: text/xml", "Content-length: " . strlen($xmlRequest), "Connection: close"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://localhost:9000'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $data = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); echo " something went wrong..... try later"; } else { echo " request accepted"; print $data; curl_close($ch); } /*-----------------------------end of tally payment ---------------------------------*/ $is_valid = true; } else { $is_valid = false; $msg = 'Something Went Wrong'; } } } } $bank_statement->history = json_encode($jsonData); $bank_statement->save(); $bank_account = \App\BankAccount::find($request->bank_account_id); $ledger = \App\PartyInvoiceLedger::where('retailer_id', $request->retailer_id)->orderBy('id', 'desc')->first(); $perticular = "By " . $bank_account->bank->name; if (!is_null($ledger)) { // $balance = $ledger->balance; $ledger = new \App\PartyInvoiceLedger(); $ledger->retailer_id = $invoice->retailer_id; $ledger->dealer_id = $request->dealer_id; $ledger->particular = $perticular; $ledger->credit = $paid_amount; $ledger->type = 'Receipt'; $ledger->debit = 0; // $ledger->balance = $balance - $paid_amount; $ledger->against = $bank_statement->series; $ledger->save(); } else { $ledger = new \App\PartyInvoiceLedger(); $ledger->retailer_id = $invoice->retailer_id; $ledger->dealer_id = $request->dealer_id; $ledger->particular = $perticular; $ledger->credit = $paid_amount; $ledger->type = 'Receipt'; $ledger->debit = 0; // $ledger->balance = 0 - $paid_amount; $ledger->against = $bank_statement->series; $ledger->save(); } } else { $is_valid = false; $msg = 'You have no any invoice.'; } if ($is_valid == true) { return redirect()->back()->with('success', 'Payment Details Saved Successfully'); } else { return redirect()->back()->with('error', $msg); } } else { $paid_amount = $request->paid_amount; $retailer = getModelById('Retailer', $request->retailer_id); $bank_particular = $retailer->name . " - " . $retailer->address; $bank_statement = new \App\BankStatement(); $bank_statement->bank_id = $request->bank_account_id; $bank_statement->particular = $bank_particular; $bank_statement->type = 'receipt'; $bank_statement->status = 'debit'; $bank_statement->amount = $paid_amount; $bank_statement->dealer_id = $request->dealer_id; $bank_statement->transaction_date = $this->dateConverter($request->payment_date); $bank_statement->reference_number = $request->bank_reference_number; $bank_statement->mode = $request->payment_mode; $receipt = \App\BankStatement::where('type', 'receipt')->orderBy('id', 'desc')->first(); if ($receipt == null) { $current_receipt_series = 1; } else { $current_receipt_series = $receipt->series + 1; } $bank_statement->series = $current_receipt_series; if ($bank_statement->save()) { $bank_account = \App\BankAccount::find($request->bank_account_id); $ledger = \App\PartyInvoiceLedger::where('retailer_id', $request->retailer_id)->orderBy('id', 'desc')->first(); $perticular = "By " . $bank_account->bank->name; if (!is_null($ledger)) { // $balance = $ledger->balance; $ledger = new \App\PartyInvoiceLedger(); $ledger->retailer_id = $request->retailer_id; $ledger->dealer_id = $request->dealer_id; $ledger->particular = $perticular; $ledger->credit = $paid_amount; $ledger->type = 'Receipt'; $ledger->debit = 0; // $ledger->balance = $balance - $paid_amount; $ledger->against = $bank_statement->series; $ledger->save(); } else { $ledger = new \App\PartyInvoiceLedger(); $ledger->retailer_id = $request->retailer_id; $ledger->dealer_id = $request->dealer_id; $ledger->particular = $perticular; $ledger->credit = $paid_amount; $ledger->type = 'Receipt'; $ledger->debit = 0; // $ledger->balance = 0 - $paid_amount; $ledger->against = $bank_statement->series; $ledger->save(); } } return redirect()->back()->with('success', 'Payment Receive Successfully !!'); } } public function loadingSlipInvoicePaymentDetails($invoice_id) { $data = array(); $data['payments'] = \App\PartyInvoicePayment::where('invoice_id', $invoice_id)->with('bank_account')->get(); return view('dashboard.invoice.loading-slip-invoice-payment-details', $data); } public function saveCompanyDiDiscount(Request $request) { $response = array(); $invoice = \App\CompanyDi::where('id', $request->invoice_id)->first(); if (is_null($invoice)) { $response['flag'] = false; $response['message'] = "Invoice Not found"; } else if (!is_null($invoice->approved_credit_days)) { $response['flag'] = false; $response['message'] = "Invoice Discount Saved Already"; } else { $invoice->is_paid = 1; $invoice->approved_credit_days = $request->approved_credit_days; $invoice->operation_period = $request->operational_days; $invoice->balance_days = $request->balance_days; $invoice->discount_perday_permts = $request->discount; $invoice->rate_per_mts = $request->rate_per_mts; $invoice->claim_amount = $request->claim_amount; if ($invoice->save()) { $response['flag'] = true; $response['message'] = "Discount Details Saved Successfully"; } else { $response['flag'] = false; $response['message'] = "Something Went Wrong"; } } return response()->json($response); } public function dateConverter($date) { $temp_date = explode('/', $date); $new_date = $temp_date[2] . "-" . $temp_date[0] . "-" . $temp_date[1]; return $new_date; } public function dateConverter1($date) { $temp_date = explode('/', $date); $new_date = $temp_date[2] . "-" . $temp_date[1] . "-" . $temp_date[0]; return $new_date; } }