app/Utils/Util.php
/**
     * Replaces tags from notification body with original value
     *
     * @param  text  $body
     * @param  int  $transaction_id
     *
     * @return array
     */
Replaces tags from notification body with original value
@param  text  $body
@param  int  $transaction_id

@return array
Replaces tags from notification body with original value @param text $body @param int $transaction_id @return array
public function replaceTags($business_id, $data, $transaction)
    {
        if (!is_object($transaction)) {
            $transaction = Transaction::where('business_id', $business_id)
                            ->with(['contact', 'payment_lines'])
                            ->findOrFail($transaction);
        }
        $business = Business::findOrFail($business_id);
        foreach ($data as $key => $value) {
            if (strpos($value, '{contact_name}') !== false) {
                $contact_name = $transaction->contact->name;
                $data[$key] = str_replace('{contact_name}', $contact_name, $data[$key]);
            }
            if (strpos($value, '{invoice_number}') !== false) {
                $invoice_number = $transaction->type == 'sell' ? $transaction->invoice_no : $transaction->ref_no;
                $data[$key] = str_replace('{invoice_number}', $invoice_number, $data[$key]);
            }
            if (strpos($value, '{total_amount}') !== false) {
                $total_amount = $this->num_f($transaction->final_total, true);
                $data[$key] = str_replace('{total_amount}', $total_amount, $data[$key]);
            }
            $total_paid = 0;
            foreach ($transaction->payment_lines as $payment) {
                if ($payment->is_return != 1) {
                    $total_paid += $payment->amount;
                }
            }
            if (strpos($value, '{paid_amount}') !== false) {
                $paid_amount = $this->num_f($total_paid, true);
                $data[$key] = str_replace('{paid_amount}', $paid_amount, $data[$key]);
            }
            if (strpos($value, '{due_amount}') !== false) {
                $due = $transaction->final_total - $total_paid;
                $due_amount = $this->num_f($due, true);
                $data[$key] = str_replace('{due_amount}', $due_amount, $data[$key]);
            }
            if (strpos($value, '{business_name}') !== false) {
                $business_name = $business->name;
                $data[$key] = str_replace('{business_name}', $business_name, $data[$key]);
            }
            if (strpos($value, '{business_logo}') !== false) {
                $logo_name = $business->logo;
                $business_logo = !empty($logo_name) ? '<img src="' . url('uploads/business_logos/' . $logo_name) . '" alt="Business Logo" >' : '';
                $data[$key] = str_replace('{business_logo}', $business_logo, $data[$key]);
            }
            if (strpos($value, '{invoice_url}') !== false && $transaction->type == 'sell') {
                $invoice_url = $this->getInvoiceUrl($transaction->id, $transaction->business_id);
                $data[$key] = str_replace('{invoice_url}', $invoice_url, $data[$key]);
            }
        }
        return $data;
    }
public function replaceTags ( $ business_id , $ data , $ transaction ) { if ( ! is_object ( $ transaction ) ) { $ transaction = Transaction :: where ( 'business_id' , $ business_id ) -> with ( [ 'contact' , 'payment_lines' ] ) -> findOrFail ( $ transaction ) ; } $ business = Business :: findOrFail ( $ business_id ) ; foreach ( $ data as $ key => $ value ) { if ( strpos ( $ value , '{contact_name}' ) !== false ) { $ contact_name = $ transaction -> contact -> name ; $ data [ $ key ] = str_replace ( '{contact_name}' , $ contact_name , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{invoice_number}' ) !== false ) { $ invoice_number = $ transaction -> type == 'sell' ? $ transaction -> invoice_no : $ transaction -> ref_no ; $ data [ $ key ] = str_replace ( '{invoice_number}' , $ invoice_number , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{total_amount}' ) !== false ) { $ total_amount = $ this -> num_f ( $ transaction -> final_total , true ) ; $ data [ $ key ] = str_replace ( '{total_amount}' , $ total_amount , $ data [ $ key ] ) ; } $ total_paid = 0 ; foreach ( $ transaction -> payment_lines as $ payment ) { if ( $ payment -> is_return != 1 ) { $ total_paid += $ payment -> amount ; } } if ( strpos ( $ value , '{paid_amount}' ) !== false ) { $ paid_amount = $ this -> num_f ( $ total_paid , true ) ; $ data [ $ key ] = str_replace ( '{paid_amount}' , $ paid_amount , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{due_amount}' ) !== false ) { $ due = $ transaction -> final_total - $ total_paid ; $ due_amount = $ this -> num_f ( $ due , true ) ; $ data [ $ key ] = str_replace ( '{due_amount}' , $ due_amount , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{business_name}' ) !== false ) { $ business_name = $ business -> name ; $ data [ $ key ] = str_replace ( '{business_name}' , $ business_name , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{business_logo}' ) !== false ) { $ logo_name = $ business -> logo ; $ business_logo = ! empty ( $ logo_name ) ? '<img src="' . url ( 'uploads/business_logos/' . $ logo_name ) . '" alt="Business Logo" >' : '' ; $ data [ $ key ] = str_replace ( '{business_logo}' , $ business_logo , $ data [ $ key ] ) ; } if ( strpos ( $ value , '{invoice_url}' ) !== false && $ transaction -> type == 'sell' ) { $ invoice_url = $ this -> getInvoiceUrl ( $ transaction -> id , $ transaction -> business_id ) ; $ data [ $ key ] = str_replace ( '{invoice_url}' , $ invoice_url , $ data [ $ key ] ) ; } } return $ data ; }
Replaces tags from notification body with original value
 @param  text  $body
 @param  int  $transaction_id
Replaces tags from notification body with original value @param text $body @param int $transaction_id
//Replace contact name //Replace invoice number //Replace total_amount //Replace total_amount //Replace due_amount //Replace business_name //Replace business_logo //Replace invoice_url