Minor fixes
This commit is contained in:
parent
df6bd02685
commit
4a60371da0
|
|
@ -49,8 +49,8 @@ class StorePaymentRequest extends Request
|
|||
'client_id' => ['bail','required',Rule::exists('clients', 'id')->where('company_id', $user->company()->id)->where('is_deleted', 0)],
|
||||
'invoices' => ['bail', 'sometimes', 'nullable', 'array', new ValidPayableInvoicesRule()],
|
||||
'invoices.*.amount' => ['bail','required'],
|
||||
'invoices.*.invoice_id' => ['bail','required','distinct', new ValidInvoicesRules($this->all()),Rule::exists('invoices', 'id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
|
||||
'credits.*.credit_id' => ['bail','required','distinct', new ValidCreditsRules($this->all()),Rule::exists('credits', 'id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
|
||||
'invoices.*.invoice_id' => ['bail','required','distinct', new ValidInvoicesRules($this->all()),Rule::exists('invoices', 'id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)->where('is_deleted',0)],
|
||||
'credits.*.credit_id' => ['bail','required','distinct', new ValidCreditsRules($this->all()),Rule::exists('credits', 'id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)->where('is_deleted',0)],
|
||||
'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())],
|
||||
'amount' => ['bail', 'numeric', new PaymentAmountsBalanceRule(), 'max:99999999999999'],
|
||||
'number' => ['bail', 'nullable', Rule::unique('payments')->where('company_id', $user->company()->id)],
|
||||
|
|
|
|||
|
|
@ -485,7 +485,7 @@ class FacturaEInvoice extends AbstractService
|
|||
"taxNumber" => $company->settings->vat_number,
|
||||
"name" => substr($company->present()->name(), 0, 40),
|
||||
"address" => substr($company->settings->address1, 0, 80),
|
||||
"postCode" => substr($this->invoice->client->postal_code, 0, 5),
|
||||
"postCode" => substr($company->settings->postal_code, 0, 5),
|
||||
"town" => substr($company->settings->city, 0, 50),
|
||||
"province" => substr($company->settings->state, 0, 20),
|
||||
"countryCode" => $company->country()->iso_3166_3, // Se asume España si se omite
|
||||
|
|
|
|||
|
|
@ -5573,6 +5573,7 @@ $lang = array(
|
|||
'invalid_csv_data' => 'Invalid CSV data, your import was cancelled.',
|
||||
'selected_products' => 'Selected Products',
|
||||
'create_company_error_unauthorized' => 'You are not authorized to create a company. Only the account owner can create a company.',
|
||||
'deleted_location' => 'Location Deleted',
|
||||
);
|
||||
|
||||
return $lang;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,98 @@ class PaymentTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
public function testDeletedCreditPayment()
|
||||
{
|
||||
|
||||
$client = Client::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
'balance' => 0,
|
||||
'paid_to_date' => 0,
|
||||
'credit_balance' => 0,
|
||||
'payment_balance' => 0,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $this->company->id,
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
||||
$invoice->client_id = $client->id;
|
||||
$invoice->status_id = Invoice::STATUS_DRAFT;
|
||||
|
||||
$invoice->line_items = $this->buildLineItems();
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invoice_calc = new InvoiceSum($invoice);
|
||||
$invoice_calc->build();
|
||||
|
||||
$invoice = $invoice_calc->getInvoice()->service()->markSent()->save();
|
||||
$this->assertEquals(10, $invoice->amount);
|
||||
$this->assertEquals(10, $invoice->balance);
|
||||
|
||||
$credit = CreditFactory::create($this->company->id, $this->user->id);
|
||||
$credit->client_id = $client->id;
|
||||
$credit->status_id = Credit::STATUS_DRAFT;
|
||||
|
||||
$credit->line_items = $this->buildLineItems();
|
||||
$credit->uses_inclusive_taxes = false;
|
||||
|
||||
$credit->save();
|
||||
|
||||
$credit_calc = new InvoiceSum($credit);
|
||||
$credit_calc->build();
|
||||
|
||||
$credit = $credit_calc->getCredit()->service()->markSent()->save(); //$10 credit
|
||||
|
||||
$this->assertEquals(10, $credit->amount);
|
||||
$this->assertEquals(10, $credit->balance);
|
||||
|
||||
$_c_hash = $credit->hashed_id;
|
||||
|
||||
$crepo = new \App\Repositories\CreditRepository();
|
||||
$crepo->delete($credit);
|
||||
|
||||
$credit = $credit->refresh();
|
||||
|
||||
nlog("xxx");
|
||||
nlog($credit->toArray());
|
||||
|
||||
$data = [
|
||||
// 'amount' => $invoice->amount,
|
||||
'client_id' => $client->hashed_id,
|
||||
'invoices' => [
|
||||
[
|
||||
'invoice_id' => $invoice->hashed_id,
|
||||
'amount' => 10,
|
||||
],
|
||||
],
|
||||
'credits' => [
|
||||
[
|
||||
'credit_id' => $_c_hash,
|
||||
'amount' => 10,
|
||||
],
|
||||
],
|
||||
'date' => '2020/12/12',
|
||||
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/payments?include=invoices', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
$response->assertStatus(422);
|
||||
|
||||
}
|
||||
|
||||
public function testRefundCreditPayment()
|
||||
{
|
||||
|
||||
|
|
@ -84,7 +176,7 @@ class PaymentTest extends TestCase
|
|||
|
||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id); //stub the company and user_id
|
||||
$invoice->client_id = $client->id;
|
||||
$invoice->status_id = Invoice::STATUS_SENT;
|
||||
$invoice->status_id = Invoice::STATUS_DRAFT;
|
||||
|
||||
$invoice->line_items = $this->buildLineItems();
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
|
@ -116,7 +208,7 @@ class PaymentTest extends TestCase
|
|||
$this->assertEquals(10, $credit->balance);
|
||||
|
||||
$data = [
|
||||
'amount' => $invoice->amount,
|
||||
// 'amount' => $invoice->amount,
|
||||
'client_id' => $client->hashed_id,
|
||||
'invoices' => [
|
||||
[
|
||||
|
|
@ -144,7 +236,7 @@ class PaymentTest extends TestCase
|
|||
|
||||
$payment = Payment::find($this->decodePrimaryKey($arr['data']['id']));
|
||||
|
||||
$this->assertEquals(10, $payment->amount);
|
||||
$this->assertEquals(0, $payment->amount);
|
||||
$this->assertEquals(0, $payment->refunded);
|
||||
$this->assertEquals(0, $payment->applied);
|
||||
|
||||
|
|
@ -178,7 +270,6 @@ class PaymentTest extends TestCase
|
|||
|
||||
$response->assertStatus(200);
|
||||
|
||||
nlog($response->json());
|
||||
|
||||
$invoice = $invoice->refresh();
|
||||
$this->assertEquals(10, $invoice->balance);
|
||||
|
|
@ -191,8 +282,9 @@ class PaymentTest extends TestCase
|
|||
$this->assertEquals(0, $client->paid_to_date);
|
||||
|
||||
$payment = $payment->refresh();
|
||||
$this->assertEquals(10, $payment->refunded);
|
||||
$this->assertEquals(0, $payment->refunded);
|
||||
$this->assertEquals(0, $payment->applied);
|
||||
|
||||
}
|
||||
|
||||
public function testDeleteInvoiceDeletePaymentRaceCondition()
|
||||
|
|
|
|||
Loading…
Reference in New Issue