CasperSecurity

Current Path : /var/www/orientalss.com/app/Http/Livewire/Finance/
Upload File :
Current File : /var/www/orientalss.com/app/Http/Livewire/Finance/VoucherPostingLivewire.php

<?php

namespace App\Http\Livewire\Finance;

use Livewire\Component;
use App\Models\JournalType;
use App\Models\Bank;
use App\Models\CashType;
use App\Models\FinancialTransactions;
use App\Models\FinancialTransactionsLedgerHead;
use Carbon\Carbon;

class VoucherPostingLivewire extends Component
{
    public $voucher=[];
    public $voucher_type;
    public $cash_type = [];
    public $bank = [];
    public $journal_type = [];
    public $voucher_details;
    public $showmodal = false;
    public $date, $particular, $voucher_date, $cash_type_id, $bank_id, $cheque_date, $cheque_no, $journal_type_id;
    public function switchTab($type){
        if($type != null && $type == 'cp'){
            $this->voucher_type = 'Cash Payment';
            $this->voucher = FinancialTransactions::where('transaction_type','Cash')->where('voucher_type', 'payment')->where('voucher_status', 1)->orderBy('id','desc')->get();
            $this->bank = [];
            $this->journal_type = [];
        }elseif ($type != null && $type == 'bp'){
            $this->voucher_type = 'Bank Payment';
            $this->voucher = FinancialTransactions::where('transaction_type','Bank')->where('voucher_type', 'payment')->where('voucher_status', 1)->orderBy('id','desc')->get();
            $this->cash_type = [];
            $this->journal_type = [];
        }elseif ($type != null && $type == 'cr'){
            $this->voucher_type = 'Cash Receive';
            $this->voucher = FinancialTransactions::where('transaction_type','Cash')->where('voucher_type', 'receive')->where('voucher_status', 1)->orderBy('id','desc')->get();
            $this->bank = [];
            $this->journal_type = [];
        }elseif ($type != null && $type == 'br'){
            $this->voucher_type = 'Bank Receive';
            $this->voucher = FinancialTransactions::where('transaction_type','Bank')->where('voucher_type', 'receive')->where('voucher_status', 1)->orderBy('id','desc')->get();
            $this->cash_type = [];
            $this->journal_type = [];
        }elseif ($type != null && $type == 'jnl'){
            $this->voucher_type = 'Journal';
            $this->voucher = FinancialTransactions::where('voucher_type', 'journal')->where('voucher_status', 1)->orderBy('id','desc')->get();
            $this->bank = [];
            $this->cash_type = [];
        }
    }
    public function resetvalid(){
        $this->resetValidation();
    }
    public function updateclick($vid){
        if($this->voucher_type == 'Cash Payment' || $this->voucher_type == 'Cash Receive') {

            $this->cash_type = CashType::where('status', 1)->get();
        }elseif ($this->voucher_type == 'Bank Payment' || $this->voucher_type == 'Bank Receive'){
            $this->bank = Bank::where('status',1)->get();
            $this->cheque_date = date('Y-m-d');
        }elseif($this->voucher_type == 'Journal'){
            $this->journal_type = JournalType::where('status',1)->get();
        }
            if ($vid != null) {
                $this->voucher_details = FinancialTransactions::find($vid);
                if ($this->voucher_details != null) {
                    $financial_details = FinancialTransactionsLedgerHead::select('financial_transactions_ledger_heads.*', 'ledger_heads.ledger_head_name', 'ledger_heads.ledger_head', 'vendors.vendor_name', 'employee_registrations.name as employee_name')->join('ledger_heads', 'financial_transactions_ledger_heads.ledger_head_id', '=', 'ledger_heads.id')->leftJoin('vendors', 'financial_transactions_ledger_heads.vendor_id', '=', 'vendors.id')->leftJoin('employee_registrations','financial_transactions_ledger_heads.employee_id', '=', 'employee_registrations.id')->where('financial_transactions_ledger_heads.finance_transaction_id', $this->voucher_details['id'])->get();
                    $this->voucher_details['details'] = $financial_details != null ? $financial_details : [];
                    $this->date = $this->voucher_details['preparatory_date'];
                    $this->particular = $this->voucher_details['voucher_particulars'];
                    $this->voucher_date = date('Y-m-d');

                    $this->showmodal = true;
                }
//        dd($this->voucher_details);
            }


    }
    public function cash_voucher_submit($cash_vch_id){
        $this->validate(['cash_type_id'=>'required',],['cash_type_id.required'=>'This field is required',]);
        $cash_type_dt = CashType::find($this->cash_type_id);
        $amt = 0;
        $typ = null;
            $amt = $this->voucher_type == 'Cash Payment'?$this->voucher_details['total_debit_amount']:$this->voucher_details['total_credit_amount'];
            $typ = $this->voucher_type == 'Cash Payment'?'Credit':'Debit';
        $transaction = FinancialTransactionsLedgerHead::create([
            'finance_transaction_id'=>$cash_vch_id,
            'ledger_head_id'=>$cash_type_dt != null?$cash_type_dt['ledger_head_id']:null,
            'amount'=>$amt,
            'type'=>$typ,
            'status'=>2,
        ]);
        $current_year = date('Y');
        $cp_voucher_no = null;
        if($transaction != null){
            if($this->voucher_type == 'Cash Payment'){
                $count_data = FinancialTransactions::where('transaction_type','Cash')->where('voucher_type', 'payment')->where('voucher_status','>', 0)->count();
            }else{
                $count_data = FinancialTransactions::where('transaction_type','Cash')->where('voucher_type', 'receive')->where('voucher_status','>', 0)->count();
            }
            $cp_count = $count_data+1;
            if ($cp_count < 10) {
                $cp_count = "000" . $cp_count;
            } else if ($cp_count < 100) {
                $cp_count = "00" . $cp_count;
            }else if ($cp_count < 1000) {
                $cp_count = "0" . $cp_count;
            } else {
                $cp_count = $cp_count;
            }
            $cp_voucher_no = $this->voucher_type == 'Cash Payment'?'CP/'. $current_year .'/'. $cp_count:'CR/'. $current_year .'/'. $cp_count;
            $financial_main = FinancialTransactions::find($cash_vch_id);
            if($financial_main != null){
                $financial_main->update([
                    'cash_type_id'=>$this->cash_type_id,
                    'voucher_no'=>$cp_voucher_no,
                    'voucher_date'=>Carbon::parse($this->voucher_date)->format('Y-m-d'),
                    'voucher_status'=>2,
                ]);
                $this->payment_clean_var();
                $this->showmodal = false;
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'success',
                    'message' => 'Voucher Posted Successfully.'
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'Something went wrong.'
                ]);
            }


        }else{
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'error',
                'message' => 'Details data not found.'
            ]);
        }
    }

    public function bank_vchr_submit($bnk_vch_id){
        $this->validate(['bank_id'=>'required',],['bank_id.required'=>'This field is required',]);
        $bank_dt = Bank::find($this->bank_id);
        $amt = 0;
        $typ = null;
        $amt = $this->voucher_type == 'Bank Payment'?$this->voucher_details['total_debit_amount']:$this->voucher_details['total_credit_amount'];
        $typ = $this->voucher_type == 'Bank Payment'?'Credit':'Debit';
        $transaction = FinancialTransactionsLedgerHead::create([
            'finance_transaction_id'=>$bnk_vch_id,
            'ledger_head_id'=>$bank_dt != null?$bank_dt['ledger_head_id']:null,
            'amount'=>$amt,
            'type'=>$typ,
            'cheque_no'=>$this->cheque_no,
            'cheque_date'=>$this->cheque_date,
        ]);
        $current_year = date('Y');
        $bp_voucher_no = null;
        if($transaction != null){
            if($this->voucher_type == 'Bank Payment'){
                $count_data = FinancialTransactions::where('transaction_type','Bank')->where('voucher_type', 'payment')->where('voucher_status','>', 0)->count();
            }else{
                $count_data = FinancialTransactions::where('transaction_type','Bank')->where('voucher_type', 'receive')->where('voucher_status','>', 0)->count();
            }
            $bp_count = $count_data+1;
            if ($bp_count < 10) {
                $bp_count = "000" . $bp_count;
            } else if ($bp_count < 100) {
                $bp_count = "00" . $bp_count;
            }else if ($bp_count < 1000) {
                $bp_count = "0" . $bp_count;
            } else {
                $bp_count = $bp_count;
            }
            $bp_voucher_no = $this->voucher_type == 'Bank Payment'?'BP/'. $current_year .'/'. $bp_count:'BR/'. $current_year .'/'. $bp_count;
            $financial_main = FinancialTransactions::find($bnk_vch_id);
            if($financial_main != null){
                $financial_main->update([
                    'bank_id'=>$this->bank_id,
                    'voucher_no'=>$bp_voucher_no,
                    'voucher_date'=>Carbon::parse($this->voucher_date)->format('Y-m-d'),
                    'voucher_status'=>2,
                ]);
                $this->payment_clean_var();
                $this->showmodal = false;
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'success',
                    'message' => 'Voucher Posted Successfully.'
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'Something went wrong.'
                ]);
            }


        }else{
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'error',
                'message' => 'Details data not found.'
            ]);
        }
    }

    public function jrnl_submit($jnl_vch_id){
        $this->validate(['journal_type_id'=>'required',],['journal_type_id.required'=>'This field is required',]);
        $current_year = date('Y');
        $jnl_count = 0;
        if($jnl_vch_id != null){
            $count_data = FinancialTransactions::where('voucher_type', 'journal')->where('voucher_status','>', 0)->count();
            $jnl_count = $count_data+1;
            if ($jnl_count < 10) {
                $jnl_count = "000" . $jnl_count;
            } else if ($jnl_count < 100) {
                $jnl_count = "00" . $jnl_count;
            }else if ($jnl_count < 1000) {
                $jnl_count = "0" . $jnl_count;
            } else {
                $jnl_count = $jnl_count;
            }
            $jnl_voucher_no = 'JV/'.$current_year.'/'.$jnl_count;
            $financial_main = FinancialTransactions::find($jnl_vch_id);
            if($financial_main != null){
                $financial_main->update([
                    'journal_type_id'=>$this->journal_type_id,
                    'voucher_no'=>$jnl_voucher_no,
                    'voucher_date'=>Carbon::parse($this->voucher_date)->format('Y-m-d'),
                    'voucher_status'=>2,
                ]);
                $this->payment_clean_var();
                $this->showmodal = false;
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'success',
                    'message' => 'Voucher Posted Successfully.'
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg', [
                    'type' => 'error',
                    'message' => 'Details data not found.'
                ]);
            }
        }else{
            $this->dispatchBrowserEvent('showsuccessmsg', [
                'type' => 'error',
                'message' => 'Details data not found.'
            ]);
        }
    }

    public function submit_cbpvoucher($vmn_id){
        if(sizeof($this->cash_type)>0) {
            $this->cash_voucher_submit($vmn_id);
        }elseif (sizeof($this->bank)>0){
            $this->bank_vchr_submit($vmn_id);
        }elseif(sizeof($this->journal_type)>0){
            $this->jrnl_submit($vmn_id);
        }

    }
    public function closemodalclick(){
        $this->showmodal = false;
    }
    public function payment_clean_var(){
        $this->date = null;
        $this->voucher_date = date('Y-m-d');
        $this->particular = null;
        $this->cash_type_id = null;
        $this->cheque_date = date('Y-m-d');
        $this->cheque_no = null;
        $this->bank_id = null;
        $this->journal_type_id = null;
    }
    public function render()
    {
        if ($this->voucher_details != null) {
            $financial_details = FinancialTransactionsLedgerHead::select('financial_transactions_ledger_heads.*', 'ledger_heads.ledger_head_name', 'ledger_heads.ledger_head', 'vendors.vendor_name', 'employee_registrations.name as employee_name')->join('ledger_heads', 'financial_transactions_ledger_heads.ledger_head_id', '=', 'ledger_heads.id')->leftJoin('vendors', 'financial_transactions_ledger_heads.vendor_id', '=', 'vendors.id')->leftJoin('employee_registrations','financial_transactions_ledger_heads.employee_id', '=', 'employee_registrations.id')->where('financial_transactions_ledger_heads.finance_transaction_id', $this->voucher_details['id'])->get();
            $this->voucher_details['details'] = $financial_details != null ? $financial_details : [];
            $this->date = $this->voucher_details['preparatory_date'];
            $this->particular = $this->voucher_details['voucher_particulars'];
        }
        if($this->voucher_type == 'Cash Payment'){
            $this->switchTab('cp');
        }elseif ($this->voucher_type == 'Bank Payment'){
        $this->switchTab('bp');
        }elseif ($this->voucher_type == 'Cash Receive'){
        $this->switchTab('cr');
        }elseif ($this->voucher_type == 'Bank Receive'){
        $this->switchTab('br');
        }elseif ($this->voucher_type == 'Journal'){
        $this->switchTab('jnl');
        }
        return view('livewire.finance.voucher-posting-livewire');
    }
}
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY