app/Http/Controllers/ContactController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        if (!auth()->user()->can('supplier.update') && !auth()->user()->can('customer.update')) {
            abort(403, 'Unauthorized action.');
        }
        if (request()->ajax()) {
            try {
                $input = $request->only(['type', 'supplier_business_name', 'name', 'tax_number', 'pay_term_number', 'pay_term_type', 'mobile', 'landline', 'alternate_number', 'city', 'state', 'country', 'landmark', 'customer_group_id', 'contact_id', 'custom_field1', 'custom_field2', 'custom_field3', 'custom_field4', 'email']);
                $input['credit_limit'] = $request->input('credit_limit') != '' ? $this->commonUtil->num_uf($request->input('credit_limit')) : null;
                $business_id = $request->session()->get('user.business_id');
                if (!$this->moduleUtil->isSubscribed($business_id)) {
                    return $this->moduleUtil->expiredResponse();
                }
                $count = 0;
                if (!empty($input['contact_id'])) {
                    $count = Contact::where('business_id', $business_id)
                            ->where('contact_id', $input['contact_id'])
                            ->where('id', '!=', $id)
                            ->count();
                }
                if ($count == 0) {
                    $contact = Contact::where('business_id', $business_id)->findOrFail($id);
                    foreach ($input as $key => $value) {
                        $contact->$key = $value;
                    }
                    $contact->custom_field4 = $request['customer_area'];
                    $contact->save();
                    $ob_transaction =  Transaction::where('contact_id', $id)
                                            ->where('type', 'opening_balance')
                                            ->first();
                    if (!empty($ob_transaction)) {
                        $amount = $this->commonUtil->num_uf($request->input('opening_balance'));
                        $opening_balance_paid = $this->transactionUtil->getTotalAmountPaid($ob_transaction->id);
                        if (!empty($opening_balance_paid)) {
                            $amount += $opening_balance_paid;
                        }
                        $ob_transaction->final_total = $amount;
                        $ob_transaction->save();
                        $this->transactionUtil->updatePaymentStatus($ob_transaction->id, $ob_transaction->final_total);
                    } else {
                        if (!empty($request->input('opening_balance'))) {
                            $this->transactionUtil->createOpeningBalanceTransaction($business_id, $contact->id, $request->input('opening_balance'));
                        }
                    }
                    $output = ['success' => true,
                                'msg' => __("contact.updated_success")
                                ];
                } else {
                    throw new \Exception("Error Processing Request", 1);
                }
            } catch (\Exception $e) {
                \Log::emergency("File:" . $e->getFile(). "Line:" . $e->getLine(). "Message:" . $e->getMessage());
                $output = ['success' => false,
                            'msg' => __("messages.something_went_wrong")
                        ];
            }
            return $output;
        }
    }
public function update ( Request $ request , $ id ) { if ( ! auth ( ) -> user ( ) -> can ( 'supplier.update' ) && ! auth ( ) -> user ( ) -> can ( 'customer.update' ) ) { abort ( 403 , 'Unauthorized action.' ) ; } if ( request ( ) -> ajax ( ) ) { try { $ input = $ request -> only ( [ 'type' , 'supplier_business_name' , 'name' , 'tax_number' , 'pay_term_number' , 'pay_term_type' , 'mobile' , 'landline' , 'alternate_number' , 'city' , 'state' , 'country' , 'landmark' , 'customer_group_id' , 'contact_id' , 'custom_field1' , 'custom_field2' , 'custom_field3' , 'custom_field4' , 'email' ] ) ; $ input [ 'credit_limit' ] = $ request -> input ( 'credit_limit' ) != '' ? $ this -> commonUtil -> num_uf ( $ request -> input ( 'credit_limit' ) ) : null ; $ business_id = $ request -> session ( ) -> get ( 'user.business_id' ) ; if ( ! $ this -> moduleUtil -> isSubscribed ( $ business_id ) ) { return $ this -> moduleUtil -> expiredResponse ( ) ; } $ count = 0 ; if ( ! empty ( $ input [ 'contact_id' ] ) ) { $ count = Contact :: where ( 'business_id' , $ business_id ) -> where ( 'contact_id' , $ input [ 'contact_id' ] ) -> where ( 'id' , '!=' , $ id ) -> count ( ) ; } if ( $ count == 0 ) { $ contact = Contact :: where ( 'business_id' , $ business_id ) -> findOrFail ( $ id ) ; foreach ( $ input as $ key => $ value ) { $ contact -> $ key = $ value ; } $ contact -> custom_field4 = $ request [ 'customer_area' ] ; $ contact -> save ( ) ; $ ob_transaction = Transaction :: where ( 'contact_id' , $ id ) -> where ( 'type' , 'opening_balance' ) -> first ( ) ; if ( ! empty ( $ ob_transaction ) ) { $ amount = $ this -> commonUtil -> num_uf ( $ request -> input ( 'opening_balance' ) ) ; $ opening_balance_paid = $ this -> transactionUtil -> getTotalAmountPaid ( $ ob_transaction -> id ) ; if ( ! empty ( $ opening_balance_paid ) ) { $ amount += $ opening_balance_paid ; } $ ob_transaction -> final_total = $ amount ; $ ob_transaction -> save ( ) ; $ this -> transactionUtil -> updatePaymentStatus ( $ ob_transaction -> id , $ ob_transaction -> final_total ) ; } else { if ( ! empty ( $ request -> input ( 'opening_balance' ) ) ) { $ this -> transactionUtil -> createOpeningBalanceTransaction ( $ business_id , $ contact -> id , $ request -> input ( 'opening_balance' ) ) ; } } $ output = [ 'success' => true , 'msg' => __ ( " contact.updated_success " ) ] ; } else { throw new \ Exception ( " Error Processing Request " , 1 ) ; } } catch ( \ Exception $ e ) { \ Log :: emergency ( " File: " . $ e -> getFile ( ) . " Line: " . $ e -> getLine ( ) . " Message: " . $ e -> getMessage ( ) ) ; $ output = [ 'success' => false , 'msg' => __ ( " messages.something_went_wrong " ) ] ; } return $ output ; } }
Update the specified resource in storage.
Update the specified resource in storage .
//Check Contact id // if($request['type'] == 'customer'){ //     $input['custom_field1'] = $request['custom_field1'] * (25 / 100) + $request['custom_field1']; //     $input['custom_field2'] =  0; //     $input['custom_field3'] = $request['custom_field1'] * (25 / 100) + $request['custom_field1']; //     $input['total_paid_value'] = $request['custom_field1']; // } //Get opening balance if exists //Update opening balance payment status //Add opening balance