mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:48:40 -05:00 
			
		
		
		
	Merge pull request #8430 from turbo124/v5-develop
Fixes for linking expenses
This commit is contained in:
		
						commit
						bde1f8865e
					
				@ -39,7 +39,7 @@ class MatchBankTransactionRequest extends Request
 | 
				
			|||||||
        $rules['transactions.*.vendor_id'] = 'bail|nullable|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
					        $rules['transactions.*.vendor_id'] = 'bail|nullable|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
				
			||||||
        $rules['transactions.*.id'] = 'bail|required|exists:bank_transactions,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
					        $rules['transactions.*.id'] = 'bail|required|exists:bank_transactions,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
				
			||||||
        $rules['transactions.*.payment_id'] = 'bail|sometimes|nullable|exists:payments,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
					        $rules['transactions.*.payment_id'] = 'bail|sometimes|nullable|exists:payments,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
				
			||||||
        $rules['transactions.*.expense_id'] = 'bail|sometimes|nullable|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
					        // $rules['transactions.*.expense_id'] = 'bail|sometimes|nullable|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $rules;
 | 
					        return $rules;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -72,14 +72,14 @@ class MatchBankTransactionRequest extends Request
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (array_key_exists('expense_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['expense_id']) >= 1) {
 | 
					            if (array_key_exists('expense_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['expense_id']) >= 1) {
 | 
				
			||||||
                $inputs['transactions'][$key]['expense_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['expense_id']);
 | 
					                // $inputs['transactions'][$key]['expense_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['expense_id']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $e = Expense::withTrashed()->where('company_id', auth()->user()->company()->id)->where('id', $inputs['transactions'][$key]['expense_id'])->first();
 | 
					                // $e = Expense::withTrashed()->where('company_id', auth()->user()->company()->id)->where('id', $inputs['transactions'][$key]['expense_id'])->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                /*Ensure we don't relink an existing expense*/
 | 
					                /*Ensure we don't relink an existing expense*/
 | 
				
			||||||
                if (!$e || is_numeric($e->transaction_id)) {
 | 
					                // if (!$e || is_numeric($e->transaction_id)) {
 | 
				
			||||||
                    unset($inputs['transactions'][$key]['expense_id']);
 | 
					                //     unset($inputs['transactions'][$key]['expense_id']);
 | 
				
			||||||
                }
 | 
					                // }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -156,7 +156,14 @@ class MatchBankTransactions implements ShouldQueue
 | 
				
			|||||||
            return $this;
 | 
					            return $this;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $expense = Expense::withTrashed()->find($input['expense_id']);
 | 
					        $_expenses = explode(",", $input['expense_id']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        foreach($_expenses as $_expense) {
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					            $expense = Expense::withTrashed()
 | 
				
			||||||
 | 
					                             ->where('id',  $this->decodePrimaryKey($_expense))
 | 
				
			||||||
 | 
					                             ->where('company_id', $this->bt->company_id)
 | 
				
			||||||
 | 
					                             ->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($expense && !$expense->transaction_id) {
 | 
					            if ($expense && !$expense->transaction_id) {
 | 
				
			||||||
                $expense->transaction_id = $this->bt->id;
 | 
					                $expense->transaction_id = $this->bt->id;
 | 
				
			||||||
@ -170,6 +177,7 @@ class MatchBankTransactions implements ShouldQueue
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                $this->bts->push($this->bt->id);
 | 
					                $this->bts->push($this->bt->id);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -97,7 +97,7 @@ class SumTaxTest extends TestCase
 | 
				
			|||||||
        $tax_data->seller_region = 'US';
 | 
					        $tax_data->seller_region = 'US';
 | 
				
			||||||
        $tax_data->seller_subregion = 'CA';
 | 
					        $tax_data->seller_subregion = 'CA';
 | 
				
			||||||
        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
					        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
				
			||||||
        $tax_data->regions->US->tax_all = true;
 | 
					        $tax_data->regions->US->tax_all_subregions = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->company->calculate_taxes = false;
 | 
					        $this->company->calculate_taxes = false;
 | 
				
			||||||
        $this->company->tax_data = $tax_data;
 | 
					        $this->company->tax_data = $tax_data;
 | 
				
			||||||
@ -148,7 +148,7 @@ class SumTaxTest extends TestCase
 | 
				
			|||||||
        $tax_data->seller_region = 'US';
 | 
					        $tax_data->seller_region = 'US';
 | 
				
			||||||
        $tax_data->seller_subregion = 'CA';
 | 
					        $tax_data->seller_subregion = 'CA';
 | 
				
			||||||
        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
					        $tax_data->regions->US->has_sales_above_threshold = true;
 | 
				
			||||||
        $tax_data->regions->US->tax_all = true;
 | 
					        $tax_data->regions->US->tax_all_subregions = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->company->calculate_taxes = true;
 | 
					        $this->company->calculate_taxes = true;
 | 
				
			||||||
        $this->company->tax_data = $tax_data;
 | 
					        $this->company->tax_data = $tax_data;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user