app/Http/Controllers/ContactController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        if (!auth()->user()->can('supplier.create') && !auth()->user()->can('customer.create')) {
            abort(403, 'Unauthorized action.');
        }
        try {
            $business_id = $request->session()->get('user.business_id');
            if (!$this->moduleUtil->isSubscribed($business_id)) {
                return $this->moduleUtil->expiredResponse();
            }
            $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['business_id'] = $business_id;
            $input['created_by'] = $request->session()->get('user.id');
            $input['credit_limit'] = $request->input('credit_limit') != '' ? $this->commonUtil->num_uf($request->input('credit_limit')) : null;
            $count = 0;
            if (!empty($input['contact_id'])) {
                $count = Contact::where('business_id', $input['business_id'])
                                ->where('contact_id', $input['contact_id'])
                                ->count();
            }
            if ($count == 0) {
                $ref_count = $this->commonUtil->setAndGetReferenceCount('contacts');
                if (empty($input['contact_id'])) {
                    $input['contact_id'] = $this->commonUtil->generateReferenceNumber('contacts', $ref_count);
                }
                $input['custom_field4'] = $request['customer_area'];
                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'];
                }
                $contact = Contact::create($input);
                if (!empty($request->input('opening_balance'))) {
                    $this->transactionUtil->createOpeningBalanceTransaction($business_id, $contact->id, $request->input('opening_balance'));
                }
                $output = ['success' => true,
                            'data' => $contact,
                            'msg' => __("contact.added_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' => $e->getMessage()
                        ];
        }
        return $output;
    }
public function store ( Request $ request ) { if ( ! auth ( ) -> user ( ) -> can ( 'supplier.create' ) && ! auth ( ) -> user ( ) -> can ( 'customer.create' ) ) { abort ( 403 , 'Unauthorized action.' ) ; } try { $ business_id = $ request -> session ( ) -> get ( 'user.business_id' ) ; if ( ! $ this -> moduleUtil -> isSubscribed ( $ business_id ) ) { return $ this -> moduleUtil -> expiredResponse ( ) ; } $ 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 [ 'business_id' ] = $ business_id ; $ input [ 'created_by' ] = $ request -> session ( ) -> get ( 'user.id' ) ; $ input [ 'credit_limit' ] = $ request -> input ( 'credit_limit' ) != '' ? $ this -> commonUtil -> num_uf ( $ request -> input ( 'credit_limit' ) ) : null ; $ count = 0 ; if ( ! empty ( $ input [ 'contact_id' ] ) ) { $ count = Contact :: where ( 'business_id' , $ input [ 'business_id' ] ) -> where ( 'contact_id' , $ input [ 'contact_id' ] ) -> count ( ) ; } if ( $ count == 0 ) { $ ref_count = $ this -> commonUtil -> setAndGetReferenceCount ( 'contacts' ) ; if ( empty ( $ input [ 'contact_id' ] ) ) { $ input [ 'contact_id' ] = $ this -> commonUtil -> generateReferenceNumber ( 'contacts' , $ ref_count ) ; } $ input [ 'custom_field4' ] = $ request [ 'customer_area' ] ; 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' ] ; } $ contact = Contact :: create ( $ input ) ; if ( ! empty ( $ request -> input ( 'opening_balance' ) ) ) { $ this -> transactionUtil -> createOpeningBalanceTransaction ( $ business_id , $ contact -> id , $ request -> input ( 'opening_balance' ) ) ; } $ output = [ 'success' => true , 'data' => $ contact , 'msg' => __ ( " contact.added_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' => $ e -> getMessage ( ) ] ; } return $ output ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Check Contact id //Update reference count //Generate reference number //Add opening balance //'msg' =>__("messages.something_went_wrong")