mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Update CORS fields (#3371)
* Working on invoice invitations * Credit invitations * Update CORS
This commit is contained in:
parent
08b4c4f4e1
commit
1ac2a73b2a
@ -16,7 +16,7 @@ class Cors
|
||||
// ALLOW OPTIONS METHOD
|
||||
$headers = [
|
||||
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
|
||||
'Access-Control-Allow-Headers'=> 'X-API-SECRET,X-API-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
|
||||
'Access-Control-Allow-Headers'=> 'X-API-SECRET,X-API-TOKEN,X-API-PASSWORD,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
|
||||
];
|
||||
|
||||
return Response::make('OK', 200, $headers);
|
||||
|
@ -43,6 +43,37 @@ class StoreCreditRequest extends FormRequest
|
||||
if($input['client_id'])
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
|
||||
if(isset($input['client_contacts']))
|
||||
{
|
||||
foreach($input['client_contacts'] as $key => $contact)
|
||||
{
|
||||
if(!array_key_exists('send_email', $contact) || !array_key_exists('id', $contact))
|
||||
{
|
||||
unset($input['client_contacts'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(isset($input['invitations']))
|
||||
{
|
||||
|
||||
foreach($input['invitations'] as $key => $value)
|
||||
{
|
||||
|
||||
if(isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id']))
|
||||
unset($input['invitations'][$key]['id']);
|
||||
|
||||
if(isset($input['invitations'][$key]['id']) && is_string($input['invitations'][$key]['id']))
|
||||
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
|
||||
|
||||
if(is_string($input['invitations'][$key]['client_contact_id']))
|
||||
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
//$input['line_items'] = json_encode($input['line_items']);
|
||||
$this->replace($input);
|
||||
|
@ -37,6 +37,7 @@ class UpdateCreditRequest extends FormRequest
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
@ -45,6 +46,25 @@ class UpdateCreditRequest extends FormRequest
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
||||
if(isset($input['invitations']))
|
||||
{
|
||||
|
||||
foreach($input['invitations'] as $key => $value)
|
||||
{
|
||||
|
||||
if(is_numeric($input['invitations'][$key]['id']))
|
||||
unset($input['invitations'][$key]['id']);
|
||||
|
||||
if(is_string($input['invitations'][$key]['id']))
|
||||
$input['invitations'][$key]['id'] = $this->decodePrimaryKey($input['invitations'][$key]['id']);
|
||||
|
||||
if(is_string($input['invitations'][$key]['client_contact_id']))
|
||||
$input['invitations'][$key]['client_contact_id'] = $this->decodePrimaryKey($input['invitations'][$key]['client_contact_id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
|
||||
$this->replace($input);
|
||||
|
@ -73,6 +73,8 @@ class Company extends BaseModel
|
||||
'custom_surcharge_taxes3',
|
||||
'custom_surcharge_taxes4',
|
||||
'show_product_details',
|
||||
'first_day_of_week',
|
||||
'first_month_of_year',
|
||||
|
||||
];
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace App\Models;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use App\Models\Filterable;
|
||||
use App\Services\Credit\CreditService;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -137,7 +138,10 @@ class Credit extends BaseModel
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function service()
|
||||
{
|
||||
return new CreditService($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $balance_adjustment
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Factory\CreditInvitationFactory;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -45,43 +47,69 @@ class CreditRepository extends BaseRepository
|
||||
*
|
||||
* @return Credit|\App\Models\Credit|null Credit Object
|
||||
*/
|
||||
public function save(array $data, Credit $credit, $invoice = null) : ?Credit
|
||||
public function save(array $data, Credit $credit) : ?Credit
|
||||
{
|
||||
|
||||
\Log::error($data);
|
||||
$credit->fill($data);
|
||||
|
||||
$credit->save();
|
||||
|
||||
if(!$credit->number)
|
||||
$credit->number = $credit->client->getNextCreditNumber($credit->client);
|
||||
|
||||
if (isset($data['client_contacts'])) {
|
||||
foreach ($data['client_contacts'] as $contact) {
|
||||
if ($contact['send_email'] == 1 && is_string($contact['id'])) {
|
||||
$client_contact = ClientContact::find($this->decodePrimaryKey($contact['id']));
|
||||
$client_contact->send_email = true;
|
||||
$client_contact->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($data['invitations'])) {
|
||||
$invitations = collect($data['invitations']);
|
||||
|
||||
/* Get array of Keyss which have been removed from the invitations array and soft delete each invitation */
|
||||
collect($credit->invitations->pluck('key'))->diff($invitations->pluck('key'))->each(function ($invitation) {
|
||||
CreditInvitation::destroy($invitation);
|
||||
/* Get array of Keys which have been removed from the invitations array and soft delete each invitation */
|
||||
$credit->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) {
|
||||
|
||||
$invite = $this->getInvitationByKey($invitation);
|
||||
|
||||
if($invite)
|
||||
$invite->forceDelete();
|
||||
|
||||
});
|
||||
|
||||
|
||||
foreach ($data['invitations'] as $invitation) {
|
||||
$cred = false;
|
||||
$inv = false;
|
||||
|
||||
if (array_key_exists('key', $invitation)) {
|
||||
$cred = CreditInvitation::whereKey($invitation['key'])->first();
|
||||
$inv = $this->getInvitationByKey($invitation['key']);
|
||||
}
|
||||
|
||||
if (!$cred) {
|
||||
//$invitation['client_contact_id'] = $this->decodePrimaryKey($invitation['client_contact_id']);
|
||||
if (!$inv) {
|
||||
|
||||
$new_invitation = CreditInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||
if (isset($invitation['id'])) {
|
||||
unset($invitation['id']);
|
||||
}
|
||||
|
||||
$new_invitation = CreditInvitationFactory::create($credit->company_id, $credit->user_id);
|
||||
$new_invitation->fill($invitation);
|
||||
$new_invitation->credit_id = $credit->id;
|
||||
$new_invitation->client_contact_id = $this->decodePrimaryKey($invitation['client_contact_id']);
|
||||
$new_invitation->client_contact_id = $invitation['client_contact_id'];
|
||||
$new_invitation->save();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$credit->load('invitations');
|
||||
|
||||
/* If no invitations have been created, this is our fail safe to maintain state*/
|
||||
if ($credit->invitations->count() == 0) {
|
||||
$credit->service()->createInvitations();
|
||||
}
|
||||
/**
|
||||
* Perform calculations on the
|
||||
* credit note
|
||||
@ -91,8 +119,13 @@ class CreditRepository extends BaseRepository
|
||||
|
||||
$credit->save();
|
||||
|
||||
return $credit;
|
||||
return $credit->fresh();
|
||||
|
||||
}
|
||||
|
||||
public function getInvitationByKey($key) :?CreditInvitation
|
||||
{
|
||||
return CreditInvitation::whereRaw("BINARY `key`= ?", [$key])->first();
|
||||
}
|
||||
|
||||
}
|
@ -103,7 +103,6 @@ class InvoiceRepository extends BaseRepository {
|
||||
|
||||
/* If no invitations have been created, this is our fail safe to maintain state*/
|
||||
if ($invoice->invitations->count() == 0) {
|
||||
\Log::error('making invitations');
|
||||
$invoice->service()->createInvitations();
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ class QuoteRepository extends BaseRepository
|
||||
$invitations = collect($data['invitations']);
|
||||
|
||||
/* Get array of Keys which have been removed from the invitations array and soft delete each invitation */
|
||||
collect($quote->invitations->pluck('key'))->diff($invitations->pluck('key'))->each(function ($invitation) {
|
||||
$quote->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) {
|
||||
$this->getInvitationByKey($invitation)->delete();
|
||||
});
|
||||
|
||||
@ -68,7 +68,11 @@ class QuoteRepository extends BaseRepository
|
||||
$inv = false;
|
||||
|
||||
if (array_key_exists('key', $invitation)) {
|
||||
$inv = $this->getInvitationByKey([$invitation['key']])->first();
|
||||
$inv = $this->getInvitationByKey([$invitation['key']]);
|
||||
|
||||
if($inv)
|
||||
$inv->forceDelete();
|
||||
|
||||
}
|
||||
|
||||
if (!$inv) {
|
||||
@ -86,6 +90,8 @@ class QuoteRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
$quote->load('invitations');
|
||||
|
||||
/* If no invitations have been created, this is our fail safe to maintain state*/
|
||||
if ($quote->invitations->count() == 0) {
|
||||
$quote->service()->createInvitations();
|
||||
|
@ -37,6 +37,6 @@ class CreateInvitations extends AbstractService
|
||||
}
|
||||
});
|
||||
|
||||
return $credit;
|
||||
return $this->credit;
|
||||
}
|
||||
}
|
||||
|
34
app/Transformers/CreditInvitationTransformer.php
Normal file
34
app/Transformers/CreditInvitationTransformer.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class CreditInvitationTransformer extends EntityTransformer {
|
||||
|
||||
use MakesHash;
|
||||
|
||||
public function transform(CreditInvitation $invitation) {
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($invitation->id),
|
||||
'client_contact_id' => $this->encodePrimaryKey($invitation->client_contact_id),
|
||||
'key' => $invitation->key,
|
||||
'link' => $invitation->getLink() ?:'',
|
||||
'sent_date' => $invitation->sent_date ?:'',
|
||||
'viewed_date' => $invitation->viewed_date ?:'',
|
||||
'opened_date' => $invitation->opened_date ?:'',
|
||||
'updated_at' => (int) $invitation->updated_at,
|
||||
'archived_at' => (int) $invitation->deleted_at,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user