v6 update

This commit is contained in:
Mohit Panjwani
2022-01-10 16:06:17 +05:30
parent b770e6277f
commit bdea879273
722 changed files with 19047 additions and 9186 deletions

View File

@ -21,6 +21,7 @@ class CompanyResource extends JsonResource
'logo_path' => $this->logo_path,
'unique_hash' => $this->unique_hash,
'owner_id' => $this->owner_id,
'slug' => $this->slug,
'address' => $this->when($this->address()->exists(), function () {
return new AddressResource($this->address);
}),

View File

@ -2,6 +2,7 @@
namespace Crater\Http\Resources;
use Crater\Models\CompanySetting;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomFieldValueResource extends JsonResource
@ -28,6 +29,7 @@ class CustomFieldValueResource extends JsonResource
'custom_field_id' => $this->custom_field_id,
'company_id' => $this->company_id,
'default_answer' => $this->defaultAnswer,
'default_formatted_answer' => $this->dateTimeFormat(),
'custom_field' => $this->when($this->customField()->exists(), function () {
return new CustomFieldResource($this->customField);
}),
@ -36,4 +38,24 @@ class CustomFieldValueResource extends JsonResource
}),
];
}
public function dateTimeFormat()
{
$key = getCustomFieldValueKey($this->type);
$answer = $this->default_answer;
if (! $answer) {
return null;
}
if ($key == 'date_time_answer') {
return $answer->format('Y-m-d H:i');
}
if ($key == 'date_answer') {
return $answer->format(CompanySetting::getSetting('carbon_date_format', $this->company_id));
}
return $answer;
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class AddressCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class AddressResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'address_street_1' => $this->address_street_1,
'address_street_2' => $this->address_street_2,
'city' => $this->city,
'state' => $this->state,
'country_id' => $this->country_id,
'zip' => $this->zip,
'phone' => $this->phone,
'fax' => $this->fax,
'type' => $this->type,
'user_id' => $this->user_id,
'company_id' => $this->company_id,
'customer_id' => $this->customer_id,
'country' => $this->when($this->country()->exists(), function () {
return new CountryResource($this->country);
}),
'user' => $this->when($this->user()->exists(), function () {
return new UserResource($this->user);
}),
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CompanyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'logo' => $this->logo,
'logo_path' => $this->logo_path,
'unique_hash' => $this->unique_hash,
'owner_id' => $this->owner_id,
'address' => $this->when($this->address()->exists(), function () {
return new AddressResource($this->address);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CountryCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CountryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'phonecode' => $this->phonecode,
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CurrencyCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CurrencyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'code' => $this->code,
'symbol' => $this->symbol,
'precision' => $this->precision,
'thousand_separator' => $this->thousand_separator,
'decimal_separator' => $this->decimal_separator,
'swap_currency_symbol' => $this->swap_currency_symbol,
'exchange_rate' => $this->exchange_rate
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CustomFieldCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomFieldResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'label' => $this->label,
'model_type' => $this->model_type,
'type' => $this->type,
'placeholder' => $this->placeholder,
'options' => $this->options,
'boolean_answer' => $this->boolean_answer,
'date_answer' => $this->date_answer,
'time_answer' => $this->time_answer,
'string_answer' => $this->string_answer,
'number_answer' => $this->number_answer,
'date_time_answer' => $this->date_time_answer,
'is_required' => $this->is_required,
'in_use' => $this->in_use,
'order' => $this->order,
'company_id' => $this->company_id,
'default_answer' => $this->default_answer,
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CustomFieldValueCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomFieldValueResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'custom_field_valuable_type' => $this->custom_field_valuable_type,
'custom_field_valuable_id' => $this->custom_field_valuable_id,
'type' => $this->type,
'boolean_answer' => $this->boolean_answer,
'date_answer' => $this->date_answer,
'time_answer' => $this->time_answer,
'string_answer' => $this->string_answer,
'number_answer' => $this->number_answer,
'date_time_answer' => $this->date_time_answer,
'custom_field_id' => $this->custom_field_id,
'company_id' => $this->company_id,
'default_answer' => $this->defaultAnswer,
'custom_field' => $this->when($this->customField()->exists(), function () {
return new CustomFieldResource($this->customField);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CustomerCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'contact_name' => $this->contact_name,
'company_name' => $this->company_name,
'website' => $this->website,
'enable_portal' => $this->enable_portal,
'currency_id' => $this->currency_id,
'company_id' => $this->company_id,
'facebook_id' => $this->facebook_id,
'google_id' => $this->google_id,
'github_id' => $this->github_id,
'formatted_created_at' => $this->formattedCreatedAt,
'avatar' => $this->avatar,
'prefix' => $this->prefix,
'billing' => $this->when($this->billingAddress()->exists(), function () {
return new AddressResource($this->billingAddress);
}),
'shipping' => $this->when($this->shippingAddress()->exists(), function () {
return new AddressResource($this->shippingAddress);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class EstimateCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class EstimateItemCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class EstimateItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'discount_type' => $this->discount_type,
'quantity' => $this->quantity,
'unit_name' => $this->unit_name,
'discount' => $this->discount,
'discount_val' => $this->discount_val,
'price' => $this->price,
'tax' => $this->tax,
'total' => $this->total,
'item_id' => $this->item_id,
'estimate_id' => $this->estimate_id,
'company_id' => $this->company_id,
'exchange_rate' => $this->exchange_rate,
'base_discount_val' => $this->base_discount_val,
'base_price' => $this->base_price,
'base_tax' => $this->base_tax,
'base_total' => $this->base_total,
'taxes' => $this->when($this->taxes()->exists(), function () {
return TaxResource::collection($this->taxes);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
];
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class EstimateResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'estimate_date' => $this->estimate_date,
'expiry_date' => $this->expiry_date,
'estimate_number' => $this->estimate_number,
'status' => $this->status,
'reference_number' => $this->reference_number,
'tax_per_item' => $this->tax_per_item,
'discount_per_item' => $this->discount_per_item,
'notes' => $this->notes,
'discount' => $this->discount,
'discount_type' => $this->discount_type,
'discount_val' => $this->discount_val,
'sub_total' => $this->sub_total,
'total' => $this->total,
'tax' => $this->tax,
'unique_hash' => $this->unique_hash,
'template_name' => $this->template_name,
'customer_id' => $this->customer_id,
'exchange_rate' => $this->exchange_rate,
'base_discount_val' => $this->base_discount_val,
'base_sub_total' => $this->base_sub_total,
'base_total' => $this->base_total,
'base_tax' => $this->base_tax,
'currency_id' => $this->currency_id,
'formatted_expiry_date' => $this->formattedExpiryDate,
'formatted_estimate_date' => $this->formattedEstimateDate,
'estimate_pdf_url' => $this->estimatePdfUrl,
'items' => $this->when($this->items()->exists(), function () {
return EstimateItemResource::collection($this->items);
}),
'customer' => $this->when($this->customer()->exists(), function () {
return new CustomerResource($this->customer);
}),
'taxes' => $this->when($this->taxes()->exists(), function () {
return TaxResource::collection($this->taxes);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ExpenseCategoryCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class ExpenseCategoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'company_id' => $this->company_id,
'amount' => $this->amount,
'formatted_created_at' => $this->formattedCreatedAt,
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ExpenseCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class ExpenseResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'expense_date' => $this->expense_date,
'amount' => $this->amount,
'notes' => $this->notes,
'customer_id' => $this->customer_id,
'attachment_receipt_url' => $this->receipt_url,
'attachment_receipt' => $this->receipt,
'attachment_receipt_meta' => $this->receipt_meta,
'company_id' => $this->company_id,
'expense_category_id' => $this->expense_category_id,
'formatted_expense_date' => $this->formattedExpenseDate,
'formatted_created_at' => $this->formattedCreatedAt,
'exchange_rate' => $this->exchange_rate,
'currency_id' => $this->currency_id,
'base_amount' => $this->base_amount,
'payment_method_id' => $this->payment_method_id,
'customer' => $this->when($this->customer()->exists(), function () {
return new CustomerResource($this->customer);
}),
'expense_category' => $this->when($this->category()->exists(), function () {
return new ExpenseCategoryResource($this->category);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
'payment_method' => $this->when($this->paymentMethod()->exists(), function () {
return new PaymentMethodResource($this->paymentMethod);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class InvoiceCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class InvoiceItemCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class InvoiceItemResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'discount_type' => $this->discount_type,
'price' => $this->price,
'quantity' => $this->quantity,
'unit_name' => $this->unit_name,
'discount' => $this->discount,
'discount_val' => $this->discount_val,
'tax' => $this->tax,
'total' => $this->total,
'invoice_id' => $this->invoice_id,
'item_id' => $this->item_id,
'company_id' => $this->company_id,
'base_price' => $this->base_price,
'exchange_rate' => $this->exchange_rate,
'base_discount_val' => $this->base_discount_val,
'base_tax' => $this->base_tax,
'base_total' => $this->base_total,
'recurring_invoice_id' => $this->recurring_invoice_id,
'taxes' => $this->when($this->taxes()->exists(), function () {
return TaxResource::collection($this->taxes);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
];
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class InvoiceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'invoice_date' => $this->invoice_date,
'due_date' => $this->due_date,
'invoice_number' => $this->invoice_number,
'reference_number' => $this->reference_number,
'status' => $this->status,
'paid_status' => $this->paid_status,
'tax_per_item' => $this->tax_per_item,
'discount_per_item' => $this->discount_per_item,
'notes' => $this->notes,
'discount_type' => $this->discount_type,
'discount' => $this->discount,
'discount_val' => $this->discount_val,
'sub_total' => $this->sub_total,
'total' => $this->total,
'tax' => $this->tax,
'due_amount' => $this->due_amount,
'sent' => $this->sent,
'viewed' => $this->viewed,
'unique_hash' => $this->unique_hash,
'template_name' => $this->template_name,
'customer_id' => $this->customer_id,
'recurring_invoice_id' => $this->recurring_invoice_id,
'sequence_number' => $this->sequence_number,
'base_discount_val' => $this->base_discount_val,
'base_sub_total' => $this->base_sub_total,
'base_total' => $this->base_total,
'base_tax' => $this->base_tax,
'base_due_amount' => $this->base_due_amount,
'currency_id' => $this->currency_id,
'formatted_created_at' => $this->formattedCreatedAt,
'invoice_pdf_url' => $this->invoicePdfUrl,
'formatted_invoice_date' => $this->formattedInvoiceDate,
'formatted_due_date' => $this->formattedDueDate,
'payment_module_enabled' => $this->payment_module_enabled,
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),
'customer' => $this->when($this->customer()->exists(), function () {
return new CustomerResource($this->customer);
}),
'taxes' => $this->when($this->taxes()->exists(), function () {
return TaxResource::collection($this->taxes);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ItemCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class PaymentCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class PaymentMethodCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentMethodResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'company_id' => $this->company_id,
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,58 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class PaymentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'payment_number' => $this->payment_number,
'payment_date' => $this->payment_date,
'notes' => $this->notes,
'amount' => $this->amount,
'unique_hash' => $this->unique_hash,
'invoice_id' => $this->invoice_id,
'company_id' => $this->company_id,
'payment_method_id' => $this->payment_method_id,
'customer_id' => $this->customer_id,
'exchange_rate' => $this->exchange_rate,
'base_amount' => $this->base_amount,
'currency_id' => $this->currency_id,
'transaction_id' => $this->transaction_id,
'formatted_created_at' => $this->formattedCreatedAt,
'formatted_payment_date' => $this->formattedPaymentDate,
'payment_pdf_url' => $this->paymentPdfUrl,
'customer' => $this->when($this->customer()->exists(), function () {
return new CustomerResource($this->customer);
}),
'invoice' => $this->when($this->invoice()->exists(), function () {
return new InvoiceResource($this->invoice);
}),
'payment_method' => $this->when($this->paymentMethod()->exists(), function () {
return new PaymentMethodResource($this->paymentMethod);
}),
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
'transaction' => $this->when($this->transaction()->exists(), function () {
return new TransactionResource($this->transaction);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class RecurringInvoiceCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class RecurringInvoiceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'starts_at' => $this->starts_at,
'formatted_starts_at' => $this->formattedStartsAt,
'formatted_created_at' => $this->formattedCreatedAt,
'formatted_next_invoice_at' => $this->formattedNextInvoiceAt,
'formatted_limit_date' => $this->formattedLimitDate,
'send_automatically' => $this->send_automatically,
'customer_id' => $this->customer_id,
'company_id' => $this->company_id,
'status' => $this->status,
'next_invoice_at' => $this->next_invoice_at,
'frequency' => $this->frequency,
'limit_by' => $this->limit_by,
'limit_count' => $this->limit_count,
'limit_date' => $this->limit_date,
'exchange_rate' => $this->exchange_rate,
'tax_per_item' => $this->tax_per_item,
'discount_per_item' => $this->discount_per_item,
'notes' => $this->notes,
'discount_type' => $this->discount_type,
'discount' => $this->discount,
'discount_val' => $this->discount_val,
'sub_total' => $this->sub_total,
'total' => $this->total,
'tax' => $this->tax,
'due_amount' => $this->due_amount,
'template_name' => $this->template_name,
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),
'customer' => $this->when($this->customer()->exists(), function () {
return new CustomerResource($this->customer);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
'invoices' => $this->when($this->invoices()->exists(), function () {
return InvoiceResource::collection($this->invoices);
}),
'taxes' => $this->when($this->taxes()->exists(), function () {
return TaxResource::collection($this->taxes);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TaxCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class TaxResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'tax_type_id' => $this->tax_type_id,
'invoice_id' => $this->invoice_id,
'estimate_id' => $this->estimate_id,
'invoice_item_id' => $this->invoice_item_id,
'estimate_item_id' => $this->estimate_item_id,
'item_id' => $this->item_id,
'company_id' => $this->company_id,
'name' => $this->name,
'amount' => $this->amount,
'percent' => $this->percent,
'compound_tax' => $this->compound_tax,
'base_amount' => $this->base_amount,
'currency_id' => $this->currency_id,
'recurring_invoice_id' => $this->recurring_invoice_id,
'tax_type' => $this->when($this->taxType()->exists(), function () {
return new TaxTypeResource($this->taxType);
}),
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TaxTypeCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class TaxTypeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'percent' => $this->percent,
'compound_tax' => $this->compound_tax,
'collective_tax' => $this->collective_tax,
'description' => $this->description,
'company_id' => $this->company_id,
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TransactionCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'transaction_id' => $this->transaction_id,
'type' => $this->type,
'status' => $this->status,
'transaction_date' => $this->transaction_date,
'invoice_id' => $this->invoice_id,
'invoice' => $this->when($this->invoice()->exists(), function () {
return new InvoiceResource($this->invoice);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\ResourceCollection;
class UserCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Crater\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'role' => $this->role,
'contact_name' => $this->contact_name,
'company_name' => $this->company_name,
'website' => $this->website,
'enable_portal' => $this->enable_portal,
'currency_id' => $this->currency_id,
'facebook_id' => $this->facebook_id,
'google_id' => $this->google_id,
'github_id' => $this->github_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'avatar' => $this->avatar,
'is_owner' => $this->isOwner(),
'roles' => $this->roles,
'formatted_created_at' => $this->formattedCreatedAt,
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
'companies' => $this->when($this->companies()->exists(), function () {
return CompanyResource::collection($this->companies);
}),
];
}
}

View File

@ -23,11 +23,9 @@ class CustomerResource extends JsonResource
'company_name' => $this->company_name,
'website' => $this->website,
'enable_portal' => $this->enable_portal,
'password_added' => $this->password ? true : false,
'currency_id' => $this->currency_id,
'company_id' => $this->company_id,
'estimate_prefix' => $this->estimate_prefix,
'payment_prefix' => $this->payment_prefix,
'invoice_prefix' => $this->invoice_prefix,
'facebook_id' => $this->facebook_id,
'google_id' => $this->google_id,
'github_id' => $this->github_id,

View File

@ -44,6 +44,8 @@ class EstimateResource extends JsonResource
'formatted_expiry_date' => $this->formattedExpiryDate,
'formatted_estimate_date' => $this->formattedEstimateDate,
'estimate_pdf_url' => $this->estimatePdfUrl,
'sales_tax_type' => $this->sales_tax_type,
'sales_tax_address_type' => $this->sales_tax_address_type,
'items' => $this->when($this->items()->exists(), function () {
return EstimateItemResource::collection($this->items);
}),

View File

@ -52,6 +52,9 @@ class InvoiceResource extends JsonResource
'formatted_invoice_date' => $this->formattedInvoiceDate,
'formatted_due_date' => $this->formattedDueDate,
'allow_edit' => $this->allow_edit,
'payment_module_enabled' => $this->payment_module_enabled,
'sales_tax_type' => $this->sales_tax_type,
'sales_tax_address_type' => $this->sales_tax_address_type,
'items' => $this->when($this->items()->exists(), function () {
return InvoiceItemResource::collection($this->items);
}),

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ModuleCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,132 @@
<?php
namespace Crater\Http\Resources;
use Crater\Models\Module as ModelsModule;
use Crater\Models\Setting;
use Illuminate\Http\Resources\Json\JsonResource;
use Nwidart\Modules\Facades\Module;
class ModuleResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$this->checkPurchased();
$this->installed_module = ModelsModule::where('name', $this->module_name)->first();
return [
'id' => $this->id,
'average_rating' => $this->average_rating,
'cover' => $this->cover,
'slug' => $this->slug,
'module_name' => $this->module_name,
'faq' => $this->faq,
'highlights' => $this->highlights,
'installed_module_version' => $this->getInstalledModuleVersion(),
'installed_module_version_updated_at' => $this->getInstalledModuleUpdatedAt(),
'latest_module_version' => $this->latest_module_version->module_version,
'latest_module_version_updated_at' => $this->latest_module_version->created_at,
'is_dev' => $this->is_dev,
'license' => $this->license,
'long_description' => $this->long_description,
'monthly_price' => $this->monthly_price,
'name' => $this->name,
'purchased' => $this->purchased,
'reviews' => $this->reviews ?? [],
'screenshots' => $this->screenshots,
'short_description' => $this->short_description,
'type' => $this->type,
'yearly_price' => $this->yearly_price,
'author_name' => $this->author->name,
'author_avatar' => $this->author->avatar,
'installed' => $this->moduleInstalled(),
'enabled' => $this->moduleEnabled(),
'update_available' => $this->updateAvailable(),
'video_link' => $this->video_link,
'video_thumbnail' => $this->video_thumbnail,
'links' => $this->links
];
}
public function getInstalledModuleVersion()
{
if (isset($this->installed_module) && $this->installed_module->installed) {
return $this->installed_module->version;
}
return null;
}
public function getInstalledModuleUpdatedAt()
{
if (isset($this->installed_module) && $this->installed_module->installed) {
return $this->installed_module->updated_at;
}
return null;
}
public function moduleInstalled()
{
if (isset($this->installed_module) && $this->installed_module->installed) {
return true;
}
return false;
}
public function moduleEnabled()
{
if (isset($this->installed_module) && $this->installed_module->installed) {
return $this->installed_module->enabled;
}
return false;
}
public function updateAvailable()
{
if (! isset($this->installed_module)) {
return false;
}
if (! $this->installed_module->installed) {
return false;
}
if (! isset($this->latest_module_version)) {
return false;
}
if (version_compare($this->installed_module->version, $this->latest_module_version->module_version, '>=')) {
return false;
}
if (version_compare(Setting::getSetting('version'), $this->latest_module_version->crater_version, '<')) {
return false;
}
return true;
}
public function checkPurchased()
{
if ($this->purchased) {
return true;
}
if (Module::has($this->module_name)) {
$module = Module::find($this->module_name);
$module->disable();
ModelsModule::where('name', $this->module_name)->update(['enabled' => false]);
}
return false;
}
}

View File

@ -18,6 +18,7 @@ class PaymentMethodResource extends JsonResource
'id' => $this->id,
'name' => $this->name,
'company_id' => $this->company_id,
'type' => $this->type,
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),

View File

@ -29,6 +29,7 @@ class PaymentResource extends JsonResource
'exchange_rate' => $this->exchange_rate,
'base_amount' => $this->base_amount,
'currency_id' => $this->currency_id,
'transaction_id' => $this->transaction_id,
'sequence_number' => $this->sequence_number,
'formatted_created_at' => $this->formattedCreatedAt,
'formatted_payment_date' => $this->formattedPaymentDate,
@ -51,6 +52,9 @@ class PaymentResource extends JsonResource
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
'transaction' => $this->when($this->transaction()->exists(), function () {
return new TransactionResource($this->transaction);
}),
];
}
}

View File

@ -43,6 +43,8 @@ class RecurringInvoiceResource extends JsonResource
'tax' => $this->tax,
'due_amount' => $this->due_amount,
'template_name' => $this->template_name,
'sales_tax_type' => $this->sales_tax_type,
'sales_tax_address_type' => $this->sales_tax_address_type,
'fields' => $this->when($this->fields()->exists(), function () {
return CustomFieldValueResource::collection($this->fields);
}),

View File

@ -29,6 +29,7 @@ class TaxResource extends JsonResource
'compound_tax' => $this->compound_tax,
'base_amount' => $this->base_amount,
'currency_id' => $this->currency_id,
'type' => $this->taxType->type,
'recurring_invoice_id' => $this->recurring_invoice_id,
'tax_type' => $this->when($this->taxType()->exists(), function () {
return new TaxTypeResource($this->taxType);

View File

@ -18,6 +18,7 @@ class TaxTypeResource extends JsonResource
'id' => $this->id,
'name' => $this->name,
'percent' => $this->percent,
'type' => $this->type,
'compound_tax' => $this->compound_tax,
'collective_tax' => $this->collective_tax,
'description' => $this->description,

View File

@ -0,0 +1,19 @@
<?php
namespace Crater\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TransactionCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Crater\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->id,
'transaction_id' => $this->transaction_id,
'type' => $this->type,
'status' => $this->status,
'transaction_date' => $this->transaction_date,
'invoice_id' => $this->invoice_id,
'invoice' => $this->when($this->invoice()->exists(), function () {
return new InvoiceResource($this->invoice);
}),
'company' => $this->when($this->company()->exists(), function () {
return new CompanyResource($this->company);
}),
];
}
}