mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:40:09 -05:00 
			
		
		
		
	Working on credit payments
This commit is contained in:
		
							parent
							
								
									62f084b2aa
								
							
						
					
					
						commit
						059f1a3fea
					
				@ -83,6 +83,24 @@ class ValidCreditsRules implements Rule
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(count($this->input['credits']) >=1){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $total_payments = $this->input['amount'] + array_sum(array_column($this->input['credits'], 'amount'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					info(print_r($this->input,1));
 | 
				
			||||||
 | 
					info("total payments = {$total_payments}");
 | 
				
			||||||
 | 
					info("total credits available = " . array_sum(array_column($this->input['credits'], 'amount')));
 | 
				
			||||||
 | 
					info("total invoices payable = " . array_sum(array_column($this->input['invoices'], 'amount')));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if($total_payments > array_sum(array_column($this->input['invoices'], 'amount'))){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $this->error_msg = "Sum of total payments and credits is greater than the total of invoices";
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
@ -82,13 +82,15 @@ class PaymentRepository extends BaseRepository
 | 
				
			|||||||
                    $data['amount'] = array_sum(array_column($data['invoices'], 'amount'));
 | 
					                    $data['amount'] = array_sum(array_column($data['invoices'], 'amount'));
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                $client = Client::find($data['client_id']);
 | 
					                $client = Client::find($data['client_id']);
 | 
				
			||||||
                info("updating client balance from {$client->balance} by this much ".$data['amount']);
 | 
					                //info("updating client balance from {$client->balance} by this much ".$data['amount']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $client->service()->updatePaidToDate($data['amount'])->save();
 | 
					                $client->service()->updatePaidToDate($data['amount'])->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //info(print_r($data,1));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /*Fill the payment*/
 | 
					        /*Fill the payment*/
 | 
				
			||||||
        $payment->fill($data);
 | 
					        $payment->fill($data);
 | 
				
			||||||
        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
					        $payment->status_id = Payment::STATUS_COMPLETED;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user