mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 02:57:33 -05:00 
			
		
		
		
	check document completed upload before user submitted form
This commit is contained in:
		
							parent
							
								
									fc981c0604
								
							
						
					
					
						commit
						afd7b7ed38
					
				@ -12,7 +12,7 @@ use Session;
 | 
				
			|||||||
class ExpenseRepository extends BaseRepository
 | 
					class ExpenseRepository extends BaseRepository
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected $documentRepo;
 | 
					    protected $documentRepo;
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    // Expenses
 | 
					    // Expenses
 | 
				
			||||||
    public function getClassName()
 | 
					    public function getClassName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -23,7 +23,7 @@ class ExpenseRepository extends BaseRepository
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->documentRepo = $documentRepo;
 | 
					        $this->documentRepo = $documentRepo;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function all()
 | 
					    public function all()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return Expense::scope()
 | 
					        return Expense::scope()
 | 
				
			||||||
@ -156,20 +156,23 @@ class ExpenseRepository extends BaseRepository
 | 
				
			|||||||
        $rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1;
 | 
					        $rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1;
 | 
				
			||||||
        $expense->exchange_rate = round($rate, 4);
 | 
					        $expense->exchange_rate = round($rate, 4);
 | 
				
			||||||
        $expense->amount = round(Utils::parseFloat($input['amount']), 2);
 | 
					        $expense->amount = round(Utils::parseFloat($input['amount']), 2);
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        $expense->save();
 | 
					        $expense->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Documents
 | 
					        // Documents
 | 
				
			||||||
        $document_ids = !empty($input['document_ids'])?array_map('intval', $input['document_ids']):array();;
 | 
					        $document_ids = !empty($input['document_ids'])?array_map('intval', $input['document_ids']):array();;
 | 
				
			||||||
        foreach ($document_ids as $document_id){
 | 
					        foreach ($document_ids as $document_id){
 | 
				
			||||||
            $document = Document::scope($document_id)->first();
 | 
					            // check document completed upload before user submitted form
 | 
				
			||||||
            if($document && Auth::user()->can('edit', $document)){
 | 
					            if ($document_id) {
 | 
				
			||||||
                $document->invoice_id = null;
 | 
					                $document = Document::scope($document_id)->first();
 | 
				
			||||||
                $document->expense_id = $expense->id;
 | 
					                if($document && Auth::user()->can('edit', $document)){
 | 
				
			||||||
                $document->save();
 | 
					                    $document->invoice_id = null;
 | 
				
			||||||
 | 
					                    $document->expense_id = $expense->id;
 | 
				
			||||||
 | 
					                    $document->save();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if(!empty($input['documents']) && Auth::user()->can('create', ENTITY_DOCUMENT)){
 | 
					        if(!empty($input['documents']) && Auth::user()->can('create', ENTITY_DOCUMENT)){
 | 
				
			||||||
            // Fallback upload
 | 
					            // Fallback upload
 | 
				
			||||||
            $doc_errors = array();
 | 
					            $doc_errors = array();
 | 
				
			||||||
@ -188,7 +191,7 @@ class ExpenseRepository extends BaseRepository
 | 
				
			|||||||
                Session::flash('error', implode('<br>',array_map('htmlentities',$doc_errors)));
 | 
					                Session::flash('error', implode('<br>',array_map('htmlentities',$doc_errors)));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        foreach ($expense->documents as $document){
 | 
					        foreach ($expense->documents as $document){
 | 
				
			||||||
            if(!in_array($document->public_id, $document_ids)){
 | 
					            if(!in_array($document->public_id, $document_ids)){
 | 
				
			||||||
                // Not checking permissions; deleting a document is just editing the invoice
 | 
					                // Not checking permissions; deleting a document is just editing the invoice
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user