mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for factories (#3192)
This commit is contained in:
parent
ad2e65aef5
commit
b92a6a78c3
53
app/Factory/CreditFactory.php
Normal file
53
app/Factory/CreditFactory.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\Models\Credit;
|
||||||
|
|
||||||
|
class CreditFactory
|
||||||
|
{
|
||||||
|
public static function create(int $company_id, int $user_id) :Credit
|
||||||
|
{
|
||||||
|
$credit = new Credit();
|
||||||
|
$credit->status_id = Credit::STATUS_DRAFT;
|
||||||
|
$credit->number = null;
|
||||||
|
$credit->discount = 0;
|
||||||
|
$credit->is_amount_discount = true;
|
||||||
|
$credit->po_number = '';
|
||||||
|
$credit->footer = '';
|
||||||
|
$credit->terms = '';
|
||||||
|
$credit->public_notes = '';
|
||||||
|
$credit->private_notes = '';
|
||||||
|
$credit->date = null;
|
||||||
|
$credit->due_date = null;
|
||||||
|
$credit->partial_due_date = null;
|
||||||
|
$credit->is_deleted = false;
|
||||||
|
$credit->line_items = json_encode([]);
|
||||||
|
$credit->backup = json_encode([]);
|
||||||
|
$credit->tax_name1 = '';
|
||||||
|
$credit->tax_rate1 = 0;
|
||||||
|
$credit->tax_name2 = '';
|
||||||
|
$credit->tax_rate2 = 0;
|
||||||
|
$credit->custom_value1 = 0;
|
||||||
|
$credit->custom_value2 = 0;
|
||||||
|
$credit->custom_value3 = 0;
|
||||||
|
$credit->custom_value4 = 0;
|
||||||
|
$credit->amount = 0;
|
||||||
|
$credit->balance = 0;
|
||||||
|
$credit->partial = 0;
|
||||||
|
$credit->user_id = $user_id;
|
||||||
|
$credit->company_id = $company_id;
|
||||||
|
$credit->recurring_id = null;
|
||||||
|
|
||||||
|
return $credit;
|
||||||
|
}
|
||||||
|
}
|
@ -68,7 +68,7 @@ class InvoiceItemFactory
|
|||||||
$item->custom_value3 = $faker->realText(10);
|
$item->custom_value3 = $faker->realText(10);
|
||||||
$item->custom_value4 = $faker->realText(10);
|
$item->custom_value4 = $faker->realText(10);
|
||||||
$item->tax_name1 = 'GST';
|
$item->tax_name1 = 'GST';
|
||||||
$item->tax_rate1 = '10.00';
|
$item->tax_rate1 = 10.00;
|
||||||
|
|
||||||
$data[] = $item;
|
$data[] = $item;
|
||||||
}
|
}
|
||||||
|
49
app/Repositories/CreditRepository.php
Normal file
49
app/Repositories/CreditRepository.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Models\Credit;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreditRepository
|
||||||
|
*/
|
||||||
|
class CreditRepository extends BaseRepository
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the class name.
|
||||||
|
*
|
||||||
|
* @return string The class name.
|
||||||
|
*/
|
||||||
|
public function getClassName()
|
||||||
|
{
|
||||||
|
return Credit::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the client and its contacts
|
||||||
|
*
|
||||||
|
* @param array $data The data
|
||||||
|
* @param \App\Models\Company $client The Company
|
||||||
|
*
|
||||||
|
* @return Credit|\App\Models\Credit|null Credit Object
|
||||||
|
*/
|
||||||
|
public function save(array $data, Credit $credit) : ?Credit
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,11 +13,12 @@ namespace App\Repositories;
|
|||||||
|
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
||||||
use App\Jobs\Invoice\UpdateInvoicePayment;
|
|
||||||
use App\Jobs\Invoice\ApplyInvoicePayment;
|
|
||||||
use App\Jobs\Invoice\ApplyClientPayment;
|
use App\Jobs\Invoice\ApplyClientPayment;
|
||||||
|
use App\Jobs\Invoice\ApplyInvoicePayment;
|
||||||
|
use App\Jobs\Invoice\UpdateInvoicePayment;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Repositories\CreditRepository;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +26,15 @@ use Illuminate\Http\Request;
|
|||||||
*/
|
*/
|
||||||
class PaymentRepository extends BaseRepository
|
class PaymentRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
|
protected $credit_repo;
|
||||||
|
|
||||||
|
public function __construct(CreditRepository $credit_repo)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->credit_repo = $credit_repo;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function getClassName()
|
public function getClassName()
|
||||||
{
|
{
|
||||||
return Payment::class;
|
return Payment::class;
|
||||||
@ -46,7 +56,8 @@ class PaymentRepository extends BaseRepository
|
|||||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
if ($request->has('invoices')) {
|
if ($request->input('invoices')) {
|
||||||
|
\Log::error('invoices found');
|
||||||
$invoices = Invoice::whereIn('id', array_column($request->input('invoices'), 'id'))->company()->get();
|
$invoices = Invoice::whereIn('id', array_column($request->input('invoices'), 'id'))->company()->get();
|
||||||
|
|
||||||
$payment->invoices()->saveMany($invoices);
|
$payment->invoices()->saveMany($invoices);
|
||||||
@ -104,11 +115,22 @@ class PaymentRepository extends BaseRepository
|
|||||||
if($request->has('invoices')){
|
if($request->has('invoices')){
|
||||||
|
|
||||||
foreach($request->input('invoices') as $adjusted_invoice) {
|
foreach($request->input('invoices') as $adjusted_invoice) {
|
||||||
|
|
||||||
$invoice = Invoice::whereId($adjusted_invoice['id'])->company()->first();
|
$invoice = Invoice::whereId($adjusted_invoice['id'])->company()->first();
|
||||||
$invoice_total_adjustment += $adjusted_invoice['amount'];
|
$invoice_total_adjustment += $adjusted_invoice['amount'];
|
||||||
|
|
||||||
if(!array_key_exists('credit', $adjusted_invoice)){
|
if(array_key_exists('credits', $adjusted_invoice)){
|
||||||
//todo - generate Credit Note for $amount on $invoice - the assumption here is that it is a FULL refund
|
|
||||||
|
//process and insert credit notes
|
||||||
|
foreach($adjusted_invoice['credits'] as $credit){
|
||||||
|
|
||||||
|
$credit = $this->credit_repo->save($credit, );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//todo - generate Credit Note for $amount on $invoice - the assumption here is that it is a FULL refund
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user