mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for payment rpeo
This commit is contained in:
parent
edc59d59c1
commit
263c1c04f0
@ -192,6 +192,11 @@ class BaseRepository
|
||||
*/
|
||||
protected function alternativeSave($data, $model)
|
||||
{
|
||||
$new_entity = false;
|
||||
|
||||
if(!$model->id)
|
||||
$new_entity = true;
|
||||
|
||||
$class = new ReflectionClass($model);
|
||||
|
||||
if (array_key_exists('client_id', $data)) {
|
||||
@ -205,9 +210,7 @@ class BaseRepository
|
||||
$lcfirst_resource_id = lcfirst($resource) . '_id';
|
||||
|
||||
if ($class->name == Invoice::class || $class->name == Quote::class) {
|
||||
info("class name = invoice");
|
||||
$state['starting_amount'] = $model->amount;
|
||||
info("starting amount = {$model->amount}");
|
||||
}
|
||||
|
||||
if (!$model->id) {
|
||||
@ -231,6 +234,9 @@ class BaseRepository
|
||||
$model->fill($tmp_data);
|
||||
$model->save();
|
||||
|
||||
if($new_entity)
|
||||
$this->newEntityEvent($model);
|
||||
|
||||
if (array_key_exists('documents', $data)) {
|
||||
$this->saveDocuments($data['documents'], $model);
|
||||
}
|
||||
@ -305,8 +311,6 @@ class BaseRepository
|
||||
if(!$model->design_id)
|
||||
$model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id'));
|
||||
|
||||
info("model design id = {$model->design_id}");
|
||||
|
||||
event(new InvoiceWasUpdated($model, $model->company));
|
||||
|
||||
}
|
||||
@ -329,4 +333,16 @@ class BaseRepository
|
||||
|
||||
return $model->fresh();
|
||||
}
|
||||
|
||||
public function newEntityEvent($model)
|
||||
{
|
||||
|
||||
$className = $this->getEventClass($entity, 'Created');
|
||||
|
||||
if (class_exists($className)) {
|
||||
event(new $className($model, $model->company));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -115,20 +115,13 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
foreach ($data['invoices'] as $paid_invoice) {
|
||||
|
||||
$invoice = Invoice::whereId($paid_invoice['invoice_id'])->with('client')->first();
|
||||
|
||||
info("current client balance = {$invoice->client->balance}");
|
||||
$invoice = Invoice::whereId($paid_invoice['invoice_id'])->first();
|
||||
|
||||
if ($invoice) {
|
||||
|
||||
info("apply payment amount {$paid_invoice['amount']}");
|
||||
|
||||
$invoice = $invoice->service()->markSent()->applyPayment($payment, $paid_invoice['amount'])->save();
|
||||
|
||||
info("after processing invoice the client balance is now {$invoice->client->balance}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user