1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Fixes for refunds (#3288)

* Working on invoice designs

* Fix unusual form request issue in tests vs production

* Fixes for form requests

* Fixes for refunds
This commit is contained in:
David Bomba 2020-02-06 08:54:20 +11:00 committed by GitHub
parent 11960e25e7
commit 797c3fb3f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 34 deletions

View File

@ -25,6 +25,7 @@ class Modern
<!DOCTYPE html>
<html lang="en">
<head>
<title>$number</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
@ -91,9 +92,7 @@ class Modern
</tr>
</thead>
<tbody>
$table_body
</tbody>
</table>
@ -136,7 +135,7 @@ class Modern
{
return '
<div class="bg-orange-600 flex justify-between py-8 px-12">
<div class="bg-orange-600 flex justify-between py-8 px-12" style="page-break-inside: avoid;">
<div class="w-1/2">
<!-- // -->
</div>

View File

@ -625,7 +625,7 @@ class InvoiceController extends BaseController
}
break;
case 'mark_sent':
$invoice->markSent();
$invoice->service()->markSent()->save();
if (!$bulk) {
return $this->itemResponse($invoice);

View File

@ -33,7 +33,9 @@ class RefundPaymentRequest extends Request
protected function prepareForValidation()
{
$input = $this->all();
if(!isset($input['gateway_refund']))
$input['gateway_refund'] = false;
@ -64,14 +66,16 @@ class RefundPaymentRequest extends Request
public function rules()
{
$input = $this->all();
$rules = [
'id' => 'required',
'id' => new ValidRefundableRequest(),
'id' => new ValidRefundableRequest($input),
'amount' => 'numeric',
'date' => 'required',
'invoices.*.invoice_id' => 'required',
'invoices.*.amount' => 'required',
'invoices' => new ValidRefundableInvoices(),
'invoices' => new ValidRefundableInvoices($input),
];
return $rules;
@ -79,6 +83,8 @@ class RefundPaymentRequest extends Request
public function payment() :?Payment
{
return Payment::whereId(request()->input('id'))->first();
$input = $this->all();
return Payment::whereId($input['id'])->first();
}
}

View File

@ -34,11 +34,18 @@ class ValidRefundableRequest implements Rule
*/
private $error_msg;
private $input;
public function __construct($input)
{
$this->input = $input;
}
public function passes($attribute, $value)
{
$payment = Payment::whereId(request()->input('id'))->first();
$payment = Payment::whereId($this->input['id'])->first();
if(!$payment)
{
@ -46,14 +53,14 @@ class ValidRefundableRequest implements Rule
return false;
}
$request_invoices = request()->has('invoices') ? request()->input('invoices') : [];
$request_credits = request()->has('credits') ? request()->input('credits') : [];
$request_invoices = request()->has('invoices') ? $this->input['invoices'] : [];
$request_credits = request()->has('credits') ? $this->input['credits'] : [];
foreach($request_invoices as $key => $value)
$request_invoices[$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']);
// foreach($request_invoices as $key => $value)
// $request_invoices[$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']);
foreach($request_credits as $key => $value)
$request_credits[$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
// foreach($request_credits as $key => $value)
// $request_credits[$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']);
if($payment->invoices()->exists())
@ -62,22 +69,18 @@ class ValidRefundableRequest implements Rule
$this->checkInvoice($paymentable_invoice, $request_invoices);
}
// if($payment->credits()->exists())
// {
// foreach($payment->credits as $paymentable_credit)
// $this->checkCredit($paymentable_credit, $request_credits);
// }
foreach($request_invoices as $request_invoice)
$this->checkInvoiceIsPaymentable($request_invoice, $payment);
// foreach($request_credits as $request_credit)
// $this->checkCreditIsPaymentable($request_credit, $payment);
if(strlen($this->error_msg) > 0 )
return false;
@ -86,7 +89,8 @@ class ValidRefundableRequest implements Rule
private function checkInvoiceIsPaymentable($invoice, $payment)
{
$invoice = Invoice::find($invoice['invoice_id']);
$invoice = Invoice::whereId($invoice['invoice_id'])->whereCompanyId($payment->company_id)->first();
if($payment->invoices()->exists())
{
@ -108,7 +112,7 @@ class ValidRefundableRequest implements Rule
private function checkCreditIsPaymentable($credit, $payment)
{
$credit = Credit::find($credit['credit_id']);
$credit = Credit::whereId($credit['credit_id'])->whereCompanyId($payment->company_id)->first();
if($payment->credits()->exists())
{

View File

@ -32,12 +32,19 @@ class ValidRefundableInvoices implements Rule
private $error_msg;
private $input;
public function __construct($input)
{
$this->input = $input;
}
public function passes($attribute, $value)
{
//\Log::error(request()->input('id'));
$payment = Payment::whereId(request()->input('id'))->first();
$payment = Payment::whereId($this->input['id'])->first();
if(!$payment){
$this->error_msg = "Payment couldn't be retrieved cannot be refunded ";
@ -53,7 +60,7 @@ class ValidRefundableInvoices implements Rule
$invoices = [];
if (is_array($value)) {
$invoices = Invoice::whereIn('id', array_column($value, 'invoice_id'))->company()->get();
$invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get();
}
else
return true;
@ -65,7 +72,7 @@ class ValidRefundableInvoices implements Rule
}
foreach ($value as $val) {
foreach ($this->input['invoices'] as $val) {
if ($val['invoice_id'] == $invoice->id) {
//$pivot_record = $invoice->payments->where('id', $invoice->id)->first();

View File

@ -158,6 +158,8 @@ class CreateInvoicePdf implements ShouldQueue
//->showBrowserHeaderAndFooter()
//->headerHtml($header)
//->footerHtml($footer)
->deviceScaleFactor(1)
->showBackground()
->waitUntilNetworkIdle(false)->pdf();
//->margins(10,10,10,10)
//->savePdf('test.pdf');

View File

@ -60,11 +60,15 @@ trait MakesHash
public function decodePrimaryKey($value) : string
{
// \Log::error("pre decode = {$value}");
try {
$hashids = new Hashids('', 10);
$decoded_array = $hashids->decode($value);
// \Log::error($decoded_array);
return $decoded_array[0];
} catch (\Exception $e) {
return response()->json(['error'=>'Invalid primary key'], 400);

View File

@ -264,12 +264,12 @@ trait MakesInvoiceValues
if(!$contact)
$contact = $this->client->primary_contact()->first();
$data['$contact_name'] = $contact->present()->name() ?: 'no contact name on record';
$data['$contact_name'] = isset($contact) ? $contact->present()->name() : 'no contact name on record';
$data['$contact.name'] = &$data['$contact_name'];
$data['$contact.custom_value1'] = $contact->custom_value1;
$data['$contact.custom_value2'] = $contact->custom_value2;
$data['$contact.custom_value3'] = $contact->custom_value3;
$data['$contact.custom_value4'] = $contact->custom_value4;
$data['$contact.custom_value1'] = isset($contact) ? $contact->custom_value1 : '';
$data['$contact.custom_value2'] = isset($contact) ? $contact->custom_value2 : '';
$data['$contact.custom_value3'] = isset($contact) ? $contact->custom_value3 : '';
$data['$contact.custom_value4'] = isset($contact) ? $contact->custom_value4 : '';
$data['$company.city_state_postal'] = $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, false);
$data['$company.postal_city_state'] = $this->company->present()->cityStateZip($settings->city, $settings->state, $settings->postal_code, true);
@ -290,7 +290,7 @@ trait MakesInvoiceValues
$logo = $this->company->present()->logo($settings);
$data['$company.logo'] = "<img src='{$logo}' class='w-48'>";
$data['$company.logo'] = "<img src='{$logo}' class='w-48' alt='logo'>";
$data['$company_logo'] = &$data['$company.logo'];
$data['$company.custom_value1'] = $this->company->custom_value1;
$data['$company.custom_value2'] = $this->company->custom_value2;
@ -376,14 +376,16 @@ trait MakesInvoiceValues
{
/* Table Header */
$table_header = '<thead><tr class="'.$css['table_header_thead_class'].'">';
//$table_header = '<thead><tr class="'.$css['table_header_thead_class'].'">';
$table_header = '';
$column_headers = $this->transformColumnsForHeader($columns);
foreach ($column_headers as $column)
$table_header .= '<td class="'.$css['table_header_td_class'].'">' . ctrans('texts.'.$column.'') . '</td>';
$table_header .= '</tr></thead>';
//$table_header .= '</tr></thead>';
return $table_header;
@ -391,6 +393,7 @@ trait MakesInvoiceValues
public function table_body(array $columns, array $css) :?string
{
$table_body = '';
/* Table Body */
$columns = $this->transformColumnsForLineItems($columns);

View File

@ -100,7 +100,7 @@ class RefundTest extends TestCase
$response->assertStatus(200);
$payment_id = $arr['data']['id'];
$this->assertEquals(50, $arr['data']['amount']);
$payment = Payment::whereId($this->decodePrimaryKey($payment_id))->first();