mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
commit
f63f1d1ba9
@ -1 +1 @@
|
||||
5.3.93
|
||||
5.3.94
|
56
app/Factory/PurchaseOrderFactory.php
Normal file
56
app/Factory/PurchaseOrderFactory.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PurchaseOrderFactory
|
||||
{
|
||||
public static function create(int $company_id, int $user_id, object $settings = null, Client $client = null) :PurchaseOrder
|
||||
{
|
||||
$purchase_order = new PurchaseOrder();
|
||||
$purchase_order->status_id = PurchaseOrder::STATUS_DRAFT;
|
||||
$purchase_order->number = null;
|
||||
$purchase_order->discount = 0;
|
||||
$purchase_order->is_amount_discount = true;
|
||||
$purchase_order->po_number = '';
|
||||
$purchase_order->footer = '';
|
||||
$purchase_order->terms = '';
|
||||
$purchase_order->public_notes = '';
|
||||
$purchase_order->private_notes = '';
|
||||
$purchase_order->date = now()->format('Y-m-d');
|
||||
$purchase_order->due_date = null;
|
||||
$purchase_order->partial_due_date = null;
|
||||
$purchase_order->is_deleted = false;
|
||||
$purchase_order->line_items = json_encode([]);
|
||||
$purchase_order->tax_name1 = '';
|
||||
$purchase_order->tax_rate1 = 0;
|
||||
$purchase_order->tax_name2 = '';
|
||||
$purchase_order->tax_rate2 = 0;
|
||||
$purchase_order->tax_name3 = '';
|
||||
$purchase_order->tax_rate3 = 0;
|
||||
$purchase_order->custom_value1 = '';
|
||||
$purchase_order->custom_value2 = '';
|
||||
$purchase_order->custom_value3 = '';
|
||||
$purchase_order->custom_value4 = '';
|
||||
$purchase_order->amount = 0;
|
||||
$purchase_order->balance = 0;
|
||||
$purchase_order->partial = 0;
|
||||
$purchase_order->user_id = $user_id;
|
||||
$purchase_order->company_id = $company_id;
|
||||
$purchase_order->recurring_id = null;
|
||||
|
||||
return $purchase_order;
|
||||
}
|
||||
}
|
@ -48,6 +48,7 @@ class RecurringInvoiceFactory
|
||||
$invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$invoice->last_sent_date = null;
|
||||
$invoice->next_send_date = null;
|
||||
$invoice->next_send_date_client = null;
|
||||
$invoice->remaining_cycles = -1;
|
||||
$invoice->paid_to_date = 0;
|
||||
$invoice->auto_bill_enabled = false;
|
||||
|
185
app/Filters/PurchaseOrderFilters.php
Normal file
185
app/Filters/PurchaseOrderFilters.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PurchaseOrderFilters extends QueryFilters
|
||||
{
|
||||
/**
|
||||
* Filter based on client status.
|
||||
*
|
||||
* Statuses we need to handle
|
||||
* - all
|
||||
* - paid
|
||||
* - unpaid
|
||||
* - overdue
|
||||
* - reversed
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function credit_status(string $value = '') :Builder
|
||||
{
|
||||
if (strlen($value) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$status_parameters = explode(',', $value);
|
||||
|
||||
if (in_array('all', $status_parameters)) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
if (in_array('draft', $status_parameters)) {
|
||||
$this->builder->where('status_id', PurchaseOrder::STATUS_DRAFT);
|
||||
}
|
||||
|
||||
if (in_array('partial', $status_parameters)) {
|
||||
$this->builder->where('status_id', PurchaseOrder::STATUS_PARTIAL);
|
||||
}
|
||||
|
||||
if (in_array('applied', $status_parameters)) {
|
||||
$this->builder->where('status_id', PurchaseOrder::STATUS_APPLIED);
|
||||
}
|
||||
|
||||
//->where('due_date', '>', Carbon::now())
|
||||
//->orWhere('partial_due_date', '>', Carbon::now());
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter based on search text.
|
||||
*
|
||||
* @param string query filter
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function filter(string $filter = '') : Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
return $this->builder->where(function ($query) use ($filter) {
|
||||
$query->where('purchase_orders.number', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.number', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.date', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.amount', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.balance', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.custom_value1', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.custom_value2', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.custom_value3', 'like', '%'.$filter.'%')
|
||||
->orWhere('purchase_orders.custom_value4', 'like', '%'.$filter.'%');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list based on the status
|
||||
* archived, active, deleted - legacy from V1.
|
||||
*
|
||||
* @param string filter
|
||||
* @return Builder
|
||||
*/
|
||||
public function status(string $filter = '') : Builder
|
||||
{
|
||||
if (strlen($filter) == 0) {
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
$table = 'purchase_orders';
|
||||
$filters = explode(',', $filter);
|
||||
|
||||
return $this->builder->where(function ($query) use ($filters, $table) {
|
||||
$query->whereNull($table.'.id');
|
||||
|
||||
if (in_array(parent::STATUS_ACTIVE, $filters)) {
|
||||
$query->orWhereNull($table.'.deleted_at');
|
||||
}
|
||||
|
||||
if (in_array(parent::STATUS_ARCHIVED, $filters)) {
|
||||
$query->orWhere(function ($query) use ($table) {
|
||||
$query->whereNotNull($table.'.deleted_at');
|
||||
|
||||
if (! in_array($table, ['users'])) {
|
||||
$query->where($table.'.is_deleted', '=', 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array(parent::STATUS_DELETED, $filters)) {
|
||||
$query->orWhere($table.'.is_deleted', '=', 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the list based on $sort.
|
||||
*
|
||||
* @param string sort formatted as column|asc
|
||||
* @return Builder
|
||||
*/
|
||||
public function sort(string $sort) : Builder
|
||||
{
|
||||
$sort_col = explode('|', $sort);
|
||||
|
||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base query.
|
||||
*
|
||||
* @param int company_id
|
||||
* @param User $user
|
||||
* @return Builder
|
||||
* @deprecated
|
||||
*/
|
||||
public function baseQuery(int $company_id, User $user) : Builder
|
||||
{
|
||||
// ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query by the users company ID.
|
||||
*
|
||||
* We need to ensure we are using the correct company ID
|
||||
* as we could be hitting this from either the client or company auth guard
|
||||
*
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
if (auth()->guard('contact')->user()) {
|
||||
return $this->contactViewFilter();
|
||||
} else {
|
||||
return $this->builder->company();
|
||||
}
|
||||
|
||||
// return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* We need additional filters when showing purchase orders for the
|
||||
* client portal. Need to automatically exclude drafts and cancelled purchase orders.
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
private function contactViewFilter() : Builder
|
||||
{
|
||||
return $this->builder
|
||||
->whereCompanyId(auth()->guard('contact')->user()->company->id)
|
||||
->whereNotIn('status_id', [PurchaseOrder::STATUS_DRAFT]);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ use App\Http\Requests\CompanyGateway\UpdateCompanyGatewayRequest;
|
||||
use App\Jobs\Util\ApplePayDomain;
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\PaymentDrivers\Stripe\Jobs\StripeWebhook;
|
||||
use App\Repositories\CompanyRepository;
|
||||
use App\Transformers\CompanyGatewayTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -212,6 +213,11 @@ class CompanyGatewayController extends BaseController
|
||||
|
||||
ApplePayDomain::dispatch($company_gateway, $company_gateway->company->db);
|
||||
|
||||
if(in_array($company_gateway->gateway_key, $this->stripe_keys))
|
||||
{
|
||||
StripeWebhook::dispatch($company_gateway->company->company_key, $company_gateway->id);
|
||||
}
|
||||
|
||||
return $this->itemResponse($company_gateway);
|
||||
}
|
||||
|
||||
|
@ -10,11 +10,12 @@
|
||||
* @OA\Property(property="paused",type="boolean",example="false",description="The scheduler paused state"),
|
||||
* @OA\Property(property="repeat_every",type="string",example="DAY",description="Accepted values (DAY,WEEK,MONTH,3MONTHS,YEAR)"),
|
||||
* @OA\Property(property="start_from",type="integer",example="1652898504",description="Timestamp when we should start the scheduler, default is today"),
|
||||
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
|
||||
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
|
||||
* @OA\Property(property="start_date", type="string", example="2022-10-31", description="The start date to search between"),
|
||||
* @OA\Property(property="end_date", type="string", example="2022-10-31", description="The end date to search between"),
|
||||
* @OA\Property(
|
||||
* @OA\Property(property="job",type="string",example="create_credit_report",description="Job, we can find list of available jobs in Scheduler model"),
|
||||
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
|
||||
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
|
||||
* @OA\Property(property="start_date", type="string", example="2022-10-31", description="The start date to search between"),
|
||||
* @OA\Property(property="end_date", type="string", example="2022-10-31", description="The end date to search between"),
|
||||
* @OA\Property(
|
||||
* property="report_keys",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
@ -33,10 +34,14 @@
|
||||
* schema="UpdateTaskSchedulerSchema",
|
||||
* type="object",
|
||||
*
|
||||
* @OA\Property(property="paused",type="boolean",example="false",description="The scheduler paused state"),
|
||||
* * @OA\Property(property="repeat_every",type="string",example="DAY",description="Accepted values (DAY,WEEK,MONTH,3MONTHS,YEAR)"),
|
||||
* @OA\Property(property="paused",type="boolean",example="false",description="The scheduler paused state"),
|
||||
* @OA\Property(property="repeat_every",type="string",example="DAY",description="Accepted values (DAY,WEEK,MONTH,3MONTHS,YEAR)"),
|
||||
* @OA\Property(property="start_from",type="integer",example="1652898504",description="Timestamp when we should start the scheduler, default is today"),
|
||||
*
|
||||
* @OA\Property(property="job",type="string",example="create_credit_report",description="Job, we can find list of available jobs in Scheduler model"),
|
||||
* @OA\Property(property="date_range", type="string", example="last7", description="The string representation of the date range of data to be returned"),
|
||||
* @OA\Property(property="date_key", type="string", example="created_at", description="The date column to search between."),
|
||||
* @OA\Property(property="start_date", type="string", example="2022-10-31", description="The start date to search between"),
|
||||
* @OA\Property(property="end_date", type="string", example="2022-10-31", description="The end date to search between"),
|
||||
* )
|
||||
*/
|
||||
|
||||
@ -44,7 +49,7 @@
|
||||
* @OA\Schema(
|
||||
* schema="UpdateJobForASchedulerSchema",
|
||||
* type="object",
|
||||
* @OA\Property(property="job",type="string",example="create_client_report",description="Set action name, action names can be found in ScheduledJob Model"),
|
||||
* @OA\Property(property="job",type="string",example="create_client_report",description="Set action name, action names can be found in Scheduler Model"),
|
||||
*
|
||||
* )
|
||||
*/
|
||||
|
413
app/Http/Controllers/PurchaseOrderController.php
Normal file
413
app/Http/Controllers/PurchaseOrderController.php
Normal file
@ -0,0 +1,413 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Factory\PurchaseOrderFactory;
|
||||
use App\Filters\PurchaseOrderFilters;
|
||||
use App\Http\Requests\PurchaseOrder\CreatePurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\DestroyPurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\EditPurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\ShowPurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\StorePurchaseOrderRequest;
|
||||
use App\Http\Requests\PurchaseOrder\UpdatePurchaseOrderRequest;
|
||||
use App\Models\Client;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Repositories\PurchaseOrderRepository;
|
||||
use App\Transformers\PurchaseOrderTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class PurchaseOrderController extends BaseController
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = PurchaseOrder::class;
|
||||
protected $entity_transformer = PurchaseOrderTransformer::class;
|
||||
protected $purchase_order_repository;
|
||||
|
||||
public function __construct(PurchaseOrderRepository $purchase_order_repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->purchase_order_repository = $purchase_order_repository;
|
||||
}
|
||||
/**
|
||||
* Show the list of Purchase Orders.
|
||||
*
|
||||
* @param \App\Filters\PurchaseOrderFilters $filters The filters
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/purchase_orders",
|
||||
* operationId="getPurchaseOrders",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Gets a list of purchase orders",
|
||||
* description="Lists purchase orders, search and filters allow fine grained lists to be generated.
|
||||
*
|
||||
* Query parameters can be added to performed more fine grained filtering of the purchase orders, these are handled by the PurchaseOrderFilters class which defines the methods available",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="A list of purchase orders",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Credit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function index(PurchaseOrderFilters $filters)
|
||||
{
|
||||
$purchase_orders = PurchaseOrder::filter($filters);
|
||||
|
||||
return $this->listResponse($purchase_orders);
|
||||
}
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param CreatePurchaseOrderRequest $request The request
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/purchase_orders/create",
|
||||
* operationId="getPurchaseOrderCreate",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Gets a new blank purchase order object",
|
||||
* description="Returns a blank object with default values",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="A blank purchase order object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Credit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function create(CreatePurchaseOrderRequest $request)
|
||||
{
|
||||
$purchase_order = PurchaseOrderFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param StorePurchaseOrderRequest $request The request
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/purchase_orders",
|
||||
* operationId="storePurchaseOrder",
|
||||
* tags={"purhcase_orders"},
|
||||
* summary="Adds a purchase order",
|
||||
* description="Adds an purchase order to the system",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns the saved purchase order object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Credit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function store(StorePurchaseOrderRequest $request)
|
||||
{
|
||||
|
||||
$client = Client::find($request->get('client_id'));
|
||||
|
||||
$purchase_order = $this->purchase_order_repository->save($request->all(), PurchaseOrderFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$purchase_order = $purchase_order->service()
|
||||
->fillDefaults()
|
||||
->save();
|
||||
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param ShowPurchaseOrderRequest $request The request
|
||||
* @param PurchaseOrder $purchase_order The purchase order
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/purchase_orders/{id}",
|
||||
* operationId="showPurchaseOrder",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Shows an purcase orders",
|
||||
* description="Displays an purchase order by id",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The Purchase order Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns the purchase order object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Credit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function show(ShowPurchaseOrderRequest $request, PurchaseOrder $purchase_order)
|
||||
{
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param EditPurchaseOrderRequest $request The request
|
||||
* @param PurchaseOrder $purchase_order The purchase order
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/purchase_orders/{id}/edit",
|
||||
* operationId="editPurchaseOrder",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Shows an purchase order for editting",
|
||||
* description="Displays an purchase order by id",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The purchase order Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns the purchase order object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Invoice"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function edit(EditPurchaseOrderRequest $request, PurchaseOrder $purchase_order)
|
||||
{
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UpdatePurchaseOrderRequest $request The request
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
* @OA\Put(
|
||||
* path="/api/v1/purchase_order/{id}",
|
||||
* operationId="updatePurchaseOrder",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Updates an purchase order",
|
||||
* description="Handles the updating of an purchase order by id",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The purchase order Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns the purchase order object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Credit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function update(UpdatePurchaseOrderRequest $request, PurchaseOrder $purchase_order)
|
||||
{
|
||||
if ($request->entityIsDeleted($purchase_order)) {
|
||||
return $request->disallowUpdate();
|
||||
}
|
||||
|
||||
$purchase_order = $this->purchase_order_repository->save($request->all(), $purchase_order);
|
||||
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param DestroyPurchaseOrderRequest $request
|
||||
* @param PurchaseOrder $purchase_order
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Exception
|
||||
* @OA\Delete(
|
||||
* path="/api/v1/purchase_orders/{id}",
|
||||
* operationId="deletePurchaseOrder",
|
||||
* tags={"purchase_orders"},
|
||||
* summary="Deletes a purchase order",
|
||||
* description="Handles the deletion of an purchase orders by id",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The purhcase order Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns a HTTP status",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
*
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function destroy(DestroyPurchaseOrderRequest $request, PurchaseOrder $purchase_order)
|
||||
{
|
||||
$this->purchase_order_repository->delete($purchase_order);
|
||||
|
||||
return $this->itemResponse($purchase_order->fresh());
|
||||
}
|
||||
}
|
@ -204,9 +204,9 @@ class RecurringInvoiceController extends BaseController
|
||||
{
|
||||
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$offset = $recurring_invoice->client->timezone_offset();
|
||||
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
|
||||
$recurring_invoice->saveQuietly();
|
||||
// $offset = $recurring_invoice->client->timezone_offset();
|
||||
// $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
|
||||
// $recurring_invoice->saveQuietly();
|
||||
|
||||
$recurring_invoice->service()
|
||||
->triggeredActions($request)
|
||||
|
@ -16,6 +16,7 @@ use App\Models\Client;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use App\Utils\Traits\ClientGroupSettingsSaver;
|
||||
use Beganovich\Snappdf\Snappdf;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@ -134,6 +135,15 @@ class SelfUpdateController extends BaseController
|
||||
|
||||
nlog("Extracting zip");
|
||||
|
||||
try{
|
||||
$s = new Snappdf;
|
||||
$s->getChromiumPath();
|
||||
chmod($this->generatePlatformExecutable($s->getChromiumPath()), 0755);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
nlog("I could not set the file permissions for chrome");
|
||||
}
|
||||
|
||||
// $zipFile = new \PhpZip\ZipFile();
|
||||
|
||||
// $zipFile->openFile($file);
|
||||
|
@ -12,11 +12,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\TaskScheduler\CreateScheduledTaskRequest;
|
||||
use App\Http\Requests\TaskScheduler\UpdateScheduledJobRequest;
|
||||
use App\Http\Requests\TaskScheduler\UpdateScheduleRequest;
|
||||
use App\Jobs\Ninja\TaskScheduler;
|
||||
use App\Jobs\Report\ProfitAndLoss;
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Models\Scheduler;
|
||||
use App\Repositories\TaskSchedulerRepository;
|
||||
use App\Transformers\TaskSchedulerTransformer;
|
||||
@ -26,7 +24,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class TaskSchedulerController extends BaseController
|
||||
{
|
||||
protected $entity_type = TaskScheduler::class;
|
||||
protected $entity_type = Scheduler::class;
|
||||
protected $entity_transformer = TaskSchedulerTransformer::class;
|
||||
protected TaskSchedulerRepository $scheduler_repository;
|
||||
|
||||
@ -199,54 +197,7 @@ class TaskSchedulerController extends BaseController
|
||||
return $this->itemResponse($scheduler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\PUT(
|
||||
* path="/api/v1/task_scheduler/{id}/update_job/",
|
||||
* operationId="updateTaskSchedulerJob",
|
||||
* tags={"task_scheduler"},
|
||||
* summary="Update job for a task scheduler ",
|
||||
* description="Update job for a task scheduler | if we are changing action for a job, we should send the request for a new job same as we are creating new scheduler",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The Scheduler Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\RequestBody(
|
||||
* required=true,
|
||||
* @OA\JsonContent(ref="#/components/schemas/UpdateJobForASchedulerSchema")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="success",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function updateJob(Scheduler $scheduler, UpdateScheduledJobRequest $request)
|
||||
{
|
||||
$scheduler->service()->updateJob($scheduler, $request);
|
||||
return $this->itemResponse($scheduler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\DELETE(
|
||||
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\PurchaseOrder;
|
||||
|
||||
class CreatePurchaseOrderRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', PurchaseOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class DestroyPurchaseOrderRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->purchase_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
40
app/Http/Requests/PurchaseOrder/EditPurchaseOrderRequest.php
Normal file
40
app/Http/Requests/PurchaseOrder/EditPurchaseOrderRequest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class EditPurchaseOrderRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('edit', $this->purchase_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
40
app/Http/Requests/PurchaseOrder/ShowPurchaseOrderRequest.php
Normal file
40
app/Http/Requests/PurchaseOrder/ShowPurchaseOrderRequest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class ShowPurchaseOrderRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('view', $this->purchase_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StorePurchaseOrderRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('create', PurchaseOrder::class);
|
||||
}
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
$rules['client_id'] = 'required';
|
||||
|
||||
|
||||
$rules['number'] = ['nullable', Rule::unique('purchase_orders')->where('company_id', auth()->user()->company()->id)];
|
||||
$rules['discount'] = 'sometimes|numeric';
|
||||
$rules['is_amount_discount'] = ['boolean'];
|
||||
|
||||
|
||||
$rules['line_items'] = 'array';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdatePurchaseOrderRequest extends Request
|
||||
{
|
||||
use ChecksEntityStatus;
|
||||
use MakesHash;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->purchase_order);
|
||||
}
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
if($this->number)
|
||||
$rules['number'] = Rule::unique('purchase_orders')->where('company_id', auth()->user()->company()->id)->ignore($this->purchase_order->id);
|
||||
|
||||
$rules['line_items'] = 'array';
|
||||
$rules['discount'] = 'sometimes|numeric';
|
||||
$rules['is_amount_discount'] = ['boolean'];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
|
||||
$input['id'] = $this->purchase_order->id;
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
@ -55,6 +55,10 @@ class StoreRecurringExpenseRequest extends Request
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
if (array_key_exists('next_send_date', $input) && is_string($input['next_send_date'])) {
|
||||
$input['next_send_date_client'] = $input['next_send_date'];
|
||||
}
|
||||
|
||||
if (array_key_exists('category_id', $input) && is_string($input['category_id'])) {
|
||||
$input['category_id'] = $this->decodePrimaryKey($input['category_id']);
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ class UpdateRecurringExpenseRequest extends Request
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
if (array_key_exists('next_send_date', $input) && is_string($input['next_send_date'])) {
|
||||
$input['next_send_date_client'] = $input['next_send_date'];
|
||||
}
|
||||
|
||||
if (array_key_exists('category_id', $input) && is_string($input['category_id'])) {
|
||||
$input['category_id'] = $this->decodePrimaryKey($input['category_id']);
|
||||
}
|
||||
|
@ -67,6 +67,10 @@ class StoreRecurringInvoiceRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (array_key_exists('next_send_date', $input) && is_string($input['next_send_date'])) {
|
||||
$input['next_send_date_client'] = $input['next_send_date'];
|
||||
}
|
||||
|
||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
}
|
||||
|
@ -61,6 +61,10 @@ class UpdateRecurringInvoiceRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (array_key_exists('next_send_date', $input) && is_string($input['next_send_date'])) {
|
||||
$input['next_send_date_client'] = $input['next_send_date'];
|
||||
}
|
||||
|
||||
if (array_key_exists('design_id', $input) && is_string($input['design_id'])) {
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
namespace App\Http\Requests\TaskScheduler;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ScheduledJob;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
|
@ -562,7 +562,7 @@ class BaseImport
|
||||
}
|
||||
}
|
||||
|
||||
protected function finalizeImport()
|
||||
public function finalizeImport()
|
||||
{
|
||||
$data = [
|
||||
'errors' => $this->error_array,
|
||||
|
@ -60,10 +60,7 @@ class Csv extends BaseImport implements ImportInterface
|
||||
) {
|
||||
$this->{$entity}();
|
||||
}
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -41,7 +41,7 @@ class Freshbooks extends BaseImport
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
// $this->finalizeImport();
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -39,7 +39,7 @@ class Invoice2Go extends BaseImport
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
// $this->finalizeImport();
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Invoicely extends BaseImport
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
// $this->finalizeImport();
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -54,7 +54,7 @@ class Wave extends BaseImport implements ImportInterface
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
// $this->finalizeImport();
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -40,7 +40,7 @@ class Zoho extends BaseImport
|
||||
|
||||
//collate any errors
|
||||
|
||||
$this->finalizeImport();
|
||||
// $this->finalizeImport();
|
||||
}
|
||||
|
||||
public function client()
|
||||
|
@ -94,6 +94,8 @@ class RecurringExpensesCron
|
||||
$expense->save();
|
||||
|
||||
$recurring_expense->next_send_date = $recurring_expense->nextSendDate();
|
||||
$recurring_expense->next_send_date_client = $recurring_expense->next_send_date;
|
||||
|
||||
$recurring_expense->remaining_cycles = $recurring_expense->remainingCycles();
|
||||
$recurring_expense->save();
|
||||
}
|
||||
|
@ -79,6 +79,8 @@ class CSVIngest implements ShouldQueue {
|
||||
|
||||
}
|
||||
|
||||
$engine->finalizeImport();
|
||||
|
||||
$this->checkContacts();
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,6 @@ namespace App\Jobs\Ninja;
|
||||
|
||||
use App\Jobs\Report\SendToAdmin;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Company;
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Models\Scheduler;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@ -46,22 +44,18 @@ class TaskScheduler implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach (MultiDB::$dbs as $db)
|
||||
foreach (MultiDB::$dbs as $db)
|
||||
{
|
||||
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$pending_schedulers = $this->fetchJobs();
|
||||
|
||||
Scheduler::with('company','job')
|
||||
Scheduler::with('company')
|
||||
->where('paused', false)
|
||||
->where('is_deleted', false)
|
||||
->where('scheduled_run', '<', now())
|
||||
->cursor()
|
||||
->each(function ($scheduler){
|
||||
|
||||
$this->doJob($scheduler);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@ -70,59 +64,55 @@ class TaskScheduler implements ShouldQueue
|
||||
|
||||
private function doJob(Scheduler $scheduler)
|
||||
{
|
||||
nlog("Doing job {$scheduler->id}");
|
||||
|
||||
$job = $scheduler->job;
|
||||
nlog("Doing job {$scheduler->action_name}");
|
||||
|
||||
$company = $scheduler->company;
|
||||
|
||||
if (!$job)
|
||||
return;
|
||||
|
||||
$parameters = $job->parameters;
|
||||
$parameters = $scheduler->parameters;
|
||||
|
||||
|
||||
switch ($job->action_name) {
|
||||
case ScheduledJob::CREATE_CLIENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'contacts.csv');
|
||||
switch ($scheduler->action_name) {
|
||||
case Scheduler::CREATE_CLIENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'contacts.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_CLIENT_CONTACT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'clients.csv');
|
||||
case Scheduler::CREATE_CLIENT_CONTACT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'clients.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_CREDIT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'credits.csv');
|
||||
case Scheduler::CREATE_CREDIT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'credits.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_DOCUMENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'documents.csv');
|
||||
case Scheduler::CREATE_DOCUMENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'documents.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_EXPENSE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'expense.csv');
|
||||
case Scheduler::CREATE_EXPENSE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'expense.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_ITEM_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'invoice_items.csv');
|
||||
case Scheduler::CREATE_INVOICE_ITEM_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoice_items.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'invoices.csv');
|
||||
case Scheduler::CREATE_INVOICE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoices.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_PAYMENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'payments.csv');
|
||||
case Scheduler::CREATE_PAYMENT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'payments.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_PRODUCT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'products.csv');
|
||||
case Scheduler::CREATE_PRODUCT_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'products.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_PROFIT_AND_LOSS_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'profit_and_loss.csv');
|
||||
case Scheduler::CREATE_PROFIT_AND_LOSS_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'profit_and_loss.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_ITEM_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'quote_items.csv');
|
||||
case Scheduler::CREATE_QUOTE_ITEM_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quote_items.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'quotes.csv');
|
||||
case Scheduler::CREATE_QUOTE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quotes.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_RECURRING_INVOICE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'recurring_invoices.csv');
|
||||
case Scheduler::CREATE_RECURRING_INVOICE_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'recurring_invoices.csv');
|
||||
break;
|
||||
case ScheduledJob::CREATE_TASK_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $job->action_class, 'tasks.csv');
|
||||
case Scheduler::CREATE_TASK_REPORT:
|
||||
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'tasks.csv');
|
||||
break;
|
||||
|
||||
}
|
||||
@ -131,10 +121,4 @@ class TaskScheduler implements ShouldQueue
|
||||
$scheduler->save();
|
||||
}
|
||||
|
||||
|
||||
private function fetchJobs()
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ class SendRecurring implements ShouldQueue
|
||||
nlog("updating recurring invoice dates");
|
||||
/* Set next date here to prevent a recurring loop forming */
|
||||
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate();
|
||||
$this->recurring_invoice->next_send_date_client = $this->recurring_invoice->nextSendDateClient();
|
||||
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
|
||||
$this->recurring_invoice->last_sent_date = now();
|
||||
|
||||
|
@ -667,6 +667,8 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
$offset -= $timezone->utc_offset;
|
||||
$offset += ($entity_send_time * 3600);
|
||||
|
||||
nlog("offset = {$offset}");
|
||||
|
||||
return $offset;
|
||||
}
|
||||
|
||||
|
169
app/Models/PurchaseOrder.php
Normal file
169
app/Models/PurchaseOrder.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use App\Services\PurchaseOrder\PurchaseOrderService;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PurchaseOrder extends BaseModel
|
||||
{
|
||||
use Filterable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'number',
|
||||
'discount',
|
||||
'company_id',
|
||||
'status_id',
|
||||
'user_id',
|
||||
'last_sent_date',
|
||||
'is_deleted',
|
||||
'po_number',
|
||||
'date',
|
||||
'due_date',
|
||||
'terms',
|
||||
'public_notes',
|
||||
'private_notes',
|
||||
'tax_name1',
|
||||
'tax_rate1',
|
||||
'tax_name2',
|
||||
'tax_rate2',
|
||||
'tax_name3',
|
||||
'tax_rate3',
|
||||
'total_taxes',
|
||||
'uses_inclusive_taxes',
|
||||
'is_amount_discount',
|
||||
'partial',
|
||||
'recurring_id',
|
||||
'next_send_date',
|
||||
'reminder1_sent',
|
||||
'reminder2_sent',
|
||||
'reminder3_sent',
|
||||
'reminder_last_sent',
|
||||
'partial_due_date',
|
||||
'project_id',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'custom_value3',
|
||||
'custom_value4',
|
||||
'backup',
|
||||
'footer',
|
||||
'line_items',
|
||||
'client_id',
|
||||
'custom_surcharge1',
|
||||
'custom_surcharge2',
|
||||
'custom_surcharge3',
|
||||
'custom_surcharge4',
|
||||
// 'custom_surcharge_tax1',
|
||||
// 'custom_surcharge_tax2',
|
||||
// 'custom_surcharge_tax3',
|
||||
// 'custom_surcharge_tax4',
|
||||
'design_id',
|
||||
'invoice_id',
|
||||
'assigned_user_id',
|
||||
'exchange_rate',
|
||||
'balance',
|
||||
'partial',
|
||||
'paid_to_date',
|
||||
'subscription_id',
|
||||
'vendor_id',
|
||||
'last_viewed'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'line_items' => 'object',
|
||||
'backup' => 'object',
|
||||
'updated_at' => 'timestamp',
|
||||
'created_at' => 'timestamp',
|
||||
'deleted_at' => 'timestamp',
|
||||
'is_amount_discount' => 'bool',
|
||||
|
||||
];
|
||||
|
||||
const STATUS_DRAFT = 1;
|
||||
const STATUS_SENT = 2;
|
||||
const STATUS_PARTIAL = 3;
|
||||
const STATUS_APPLIED = 4;
|
||||
|
||||
public function assigned_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function vendor()
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
}
|
||||
|
||||
public function history()
|
||||
{
|
||||
return $this->hasManyThrough(Backup::class, Activity::class);
|
||||
}
|
||||
|
||||
public function activities()
|
||||
{
|
||||
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50);
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->belongsTo(Client::class)->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
public function invitations()
|
||||
{
|
||||
return $this->hasMany(CreditInvitation::class);
|
||||
}
|
||||
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(Project::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
|
||||
public function service()
|
||||
{
|
||||
return new PurchaseOrderService($this);
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->belongsToMany(Invoice::class)->using(Paymentable::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->morphToMany(Payment::class, 'paymentable');
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
}
|
@ -63,6 +63,7 @@ class RecurringExpense extends BaseModel
|
||||
'last_sent_date',
|
||||
'next_send_date',
|
||||
'remaining_cycles',
|
||||
'next_send_date_client',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -153,6 +154,43 @@ class RecurringExpense extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function nextSendDateClient() :?Carbon
|
||||
{
|
||||
if (!$this->next_send_date) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch ($this->frequency_id) {
|
||||
case RecurringInvoice::FREQUENCY_DAILY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addDay();
|
||||
case RecurringInvoice::FREQUENCY_WEEKLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeek();
|
||||
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeeks(2);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeeks(4);
|
||||
case RecurringInvoice::FREQUENCY_MONTHLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthNoOverflow();
|
||||
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(2);
|
||||
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(3);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(4);
|
||||
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(6);
|
||||
case RecurringInvoice::FREQUENCY_ANNUALLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYear();
|
||||
case RecurringInvoice::FREQUENCY_TWO_YEARS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYears(2);
|
||||
case RecurringInvoice::FREQUENCY_THREE_YEARS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYears(3);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function remainingCycles() : int
|
||||
{
|
||||
if ($this->remaining_cycles == 0) {
|
||||
|
@ -108,6 +108,7 @@ class RecurringInvoice extends BaseModel
|
||||
'assigned_user_id',
|
||||
'exchange_rate',
|
||||
'vendor_id',
|
||||
'next_send_date_client',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -224,7 +225,7 @@ class RecurringInvoice extends BaseModel
|
||||
|
||||
public function nextSendDate() :?Carbon
|
||||
{
|
||||
if (!$this->next_send_date) {
|
||||
if (!$this->next_send_date_client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -236,49 +237,93 @@ class RecurringInvoice extends BaseModel
|
||||
|
||||
/* Lets set the next send date to now so we increment from today, rather than in the past*/
|
||||
if(Carbon::parse($this->next_send_date)->lt(now()->subDays(3)))
|
||||
$this->next_send_date = now()->format('Y-m-d');
|
||||
$this->next_send_date_client = now()->format('Y-m-d');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
As we are firing at UTC+0 if our offset is negative it is technically firing the day before so we always need
|
||||
to add ON a day - a day = 86400 seconds
|
||||
*/
|
||||
if($offset < 0)
|
||||
$offset += 86400;
|
||||
// if($offset < 0)
|
||||
// $offset += 86400;
|
||||
|
||||
switch ($this->frequency_id) {
|
||||
case self::FREQUENCY_DAILY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addDay()->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addDay()->addSeconds($offset);
|
||||
case self::FREQUENCY_WEEKLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeek()->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeek()->addSeconds($offset);
|
||||
case self::FREQUENCY_TWO_WEEKS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeeks(2)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeeks(2)->addSeconds($offset);
|
||||
case self::FREQUENCY_FOUR_WEEKS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addWeeks(4)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeeks(4)->addSeconds($offset);
|
||||
case self::FREQUENCY_MONTHLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthNoOverflow()->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthNoOverflow()->addSeconds($offset);
|
||||
case self::FREQUENCY_TWO_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(2)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(2)->addSeconds($offset);
|
||||
case self::FREQUENCY_THREE_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(3)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(3)->addSeconds($offset);
|
||||
case self::FREQUENCY_FOUR_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(4)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(4)->addSeconds($offset);
|
||||
case self::FREQUENCY_SIX_MONTHS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addMonthsNoOverflow(6)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(6)->addSeconds($offset);
|
||||
case self::FREQUENCY_ANNUALLY:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYear()->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYear()->addSeconds($offset);
|
||||
case self::FREQUENCY_TWO_YEARS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYears(2)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYears(2)->addSeconds($offset);
|
||||
case self::FREQUENCY_THREE_YEARS:
|
||||
return Carbon::parse($this->next_send_date)->startOfDay()->addYears(3)->addSeconds($offset);
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYears(3)->addSeconds($offset);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function nextSendDateClient() :?Carbon
|
||||
{
|
||||
if (!$this->next_send_date_client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* If this setting is enabled, the recurring invoice may be set in the past */
|
||||
|
||||
if($this->company->stop_on_unpaid_recurring) {
|
||||
|
||||
/* Lets set the next send date to now so we increment from today, rather than in the past*/
|
||||
if(Carbon::parse($this->next_send_date)->lt(now()->subDays(3)))
|
||||
$this->next_send_date_client = now()->format('Y-m-d');
|
||||
|
||||
}
|
||||
|
||||
switch ($this->frequency_id) {
|
||||
case self::FREQUENCY_DAILY:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addDay();
|
||||
case self::FREQUENCY_WEEKLY:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeek();
|
||||
case self::FREQUENCY_TWO_WEEKS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeeks(2);
|
||||
case self::FREQUENCY_FOUR_WEEKS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addWeeks(4);
|
||||
case self::FREQUENCY_MONTHLY:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthNoOverflow();
|
||||
case self::FREQUENCY_TWO_MONTHS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(2);
|
||||
case self::FREQUENCY_THREE_MONTHS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(3);
|
||||
case self::FREQUENCY_FOUR_MONTHS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(4);
|
||||
case self::FREQUENCY_SIX_MONTHS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addMonthsNoOverflow(6);
|
||||
case self::FREQUENCY_ANNUALLY:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYear();
|
||||
case self::FREQUENCY_TWO_YEARS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYears(2);
|
||||
case self::FREQUENCY_THREE_YEARS:
|
||||
return Carbon::parse($this->next_send_date_client)->startOfDay()->addYears(3);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function nextDateByFrequency($date)
|
||||
{
|
||||
$offset = $this->client->timezone_offset();
|
||||
@ -463,11 +508,11 @@ class RecurringInvoice extends BaseModel
|
||||
|
||||
$data = [];
|
||||
|
||||
if (!Carbon::parse($this->next_send_date)) {
|
||||
if (!Carbon::parse($this->next_send_date_client)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$next_send_date = Carbon::parse($this->next_send_date)->copy();
|
||||
$next_send_date = Carbon::parse($this->next_send_date_client)->copy();
|
||||
|
||||
for ($x=0; $x<$iterations; $x++) {
|
||||
// we don't add the days... we calc the day of the month!!
|
||||
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* @property mixed|string action_class
|
||||
* @property array parameters
|
||||
* @property string action_name
|
||||
* @property integer scheduler_id
|
||||
* @property integer company_id
|
||||
*/
|
||||
class ScheduledJob extends BaseModel
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
const CREATE_CLIENT_REPORT = 'create_client_report';
|
||||
const CREATE_CLIENT_CONTACT_REPORT = 'create_client_contact_report';
|
||||
const CREATE_CREDIT_REPORT = 'create_credit_report';
|
||||
const CREATE_DOCUMENT_REPORT = 'create_document_report';
|
||||
const CREATE_EXPENSE_REPORT = 'create_expense_report';
|
||||
const CREATE_INVOICE_ITEM_REPORT = 'create_invoice_item_report';
|
||||
const CREATE_INVOICE_REPORT = 'create_invoice_report';
|
||||
const CREATE_PAYMENT_REPORT = 'create_payment_report';
|
||||
const CREATE_PRODUCT_REPORT = 'create_product_report';
|
||||
const CREATE_PROFIT_AND_LOSS_REPORT = 'create_profit_and_loss_report';
|
||||
const CREATE_QUOTE_ITEM_REPORT = 'create_quote_item_report';
|
||||
const CREATE_QUOTE_REPORT = 'create_quote_report';
|
||||
const CREATE_RECURRING_INVOICE_REPORT = 'create_recurring_invoice_report';
|
||||
const CREATE_TASK_REPORT = 'create_task_report';
|
||||
|
||||
|
||||
protected $fillable = ['action_class', 'action_name', 'parameters', 'scheduler_id', 'company_id'];
|
||||
protected $casts = [
|
||||
'parameters' => 'array'
|
||||
];
|
||||
}
|
@ -22,11 +22,14 @@ use Illuminate\Support\Carbon;
|
||||
* @property \Carbon\Carbon|mixed start_from
|
||||
* @property string repeat_every
|
||||
* @property \Carbon\Carbon|mixed scheduled_run
|
||||
* @property mixed job
|
||||
* @property integer company_id
|
||||
* @property integer updated_at
|
||||
* @property integer created_at
|
||||
* @property integer deleted_at
|
||||
* @property string action_name
|
||||
* @property mixed company
|
||||
* @property array parameters
|
||||
* @property string action_class
|
||||
*/
|
||||
class Scheduler extends BaseModel
|
||||
{
|
||||
@ -37,6 +40,10 @@ class Scheduler extends BaseModel
|
||||
'paused',
|
||||
'repeat_every',
|
||||
'scheduled_run',
|
||||
'action_class',
|
||||
'action_name',
|
||||
'parameters',
|
||||
'company_id'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -47,8 +54,9 @@ class Scheduler extends BaseModel
|
||||
'deleted_at' => 'timestamp',
|
||||
'paused' => 'boolean',
|
||||
'is_deleted' => 'boolean',
|
||||
'parameters' => 'array',
|
||||
];
|
||||
protected $appends = ['linked_job'];
|
||||
|
||||
|
||||
const DAILY = 'DAY';
|
||||
const WEEKLY = 'WEEK';
|
||||
@ -57,10 +65,21 @@ class Scheduler extends BaseModel
|
||||
const QUARTERLY = '3MONTHS';
|
||||
const ANNUALLY = 'YEAR';
|
||||
|
||||
public function getLinkedJobAttribute()
|
||||
{
|
||||
return $this->job ?? [];
|
||||
}
|
||||
const CREATE_CLIENT_REPORT = 'create_client_report';
|
||||
const CREATE_CLIENT_CONTACT_REPORT = 'create_client_contact_report';
|
||||
const CREATE_CREDIT_REPORT = 'create_credit_report';
|
||||
const CREATE_DOCUMENT_REPORT = 'create_document_report';
|
||||
const CREATE_EXPENSE_REPORT = 'create_expense_report';
|
||||
const CREATE_INVOICE_ITEM_REPORT = 'create_invoice_item_report';
|
||||
const CREATE_INVOICE_REPORT = 'create_invoice_report';
|
||||
const CREATE_PAYMENT_REPORT = 'create_payment_report';
|
||||
const CREATE_PRODUCT_REPORT = 'create_product_report';
|
||||
const CREATE_PROFIT_AND_LOSS_REPORT = 'create_profit_and_loss_report';
|
||||
const CREATE_QUOTE_ITEM_REPORT = 'create_quote_item_report';
|
||||
const CREATE_QUOTE_REPORT = 'create_quote_report';
|
||||
const CREATE_RECURRING_INVOICE_REPORT = 'create_recurring_invoice_report';
|
||||
const CREATE_TASK_REPORT = 'create_task_report';
|
||||
|
||||
|
||||
/**
|
||||
* Service entry points.
|
||||
@ -70,10 +89,6 @@ class Scheduler extends BaseModel
|
||||
return new TaskSchedulerService($this);
|
||||
}
|
||||
|
||||
public function job(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(ScheduledJob::class, 'scheduler_id', 'id');
|
||||
}
|
||||
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
|
72
app/Observers/PurchaseOrderObserver.php
Normal file
72
app/Observers/PurchaseOrderObserver.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
|
||||
class PurchaseOrderObserver
|
||||
{
|
||||
/**
|
||||
* Handle the client "created" event.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return void
|
||||
*/
|
||||
public function created(PurchaseOrder $purchase_order)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the client "updated" event.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return void
|
||||
*/
|
||||
public function updated(PurchaseOrder $purchase_order)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the client "deleted" event.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(PurchaseOrder $purchase_order)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the client "restored" event.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return void
|
||||
*/
|
||||
public function restored(PurchaseOrder $purchase_order)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the client "force deleted" event.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(PurchaseOrder $purchase_order)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -12,11 +12,14 @@
|
||||
|
||||
namespace App\PaymentDrivers\Authorize;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
||||
use net\authorize\api\contract\v1\CustomerProfilePaymentType;
|
||||
use net\authorize\api\contract\v1\OrderType;
|
||||
use net\authorize\api\contract\v1\PaymentProfileType;
|
||||
use net\authorize\api\contract\v1\ExtendedAmountType;
|
||||
use net\authorize\api\contract\v1\TransactionRequestType;
|
||||
use net\authorize\api\controller\CreateTransactionController;
|
||||
|
||||
@ -25,6 +28,8 @@ use net\authorize\api\controller\CreateTransactionController;
|
||||
*/
|
||||
class ChargePaymentProfile
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function __construct(AuthorizePaymentDriver $authorize)
|
||||
{
|
||||
$this->authorize = $authorize;
|
||||
@ -44,19 +49,40 @@ class ChargePaymentProfile
|
||||
$profileToCharge->setPaymentProfile($paymentProfile);
|
||||
|
||||
$invoice_numbers = '';
|
||||
$taxAmount = 0;
|
||||
$invoiceTotal = 0;
|
||||
$invoiceTaxes = 0;
|
||||
|
||||
if($this->authorize->payment_hash->data)
|
||||
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(',');
|
||||
if($this->authorize->payment_hash->data) {
|
||||
$invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(",");
|
||||
$invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
||||
|
||||
$invoiceTotal = round($invObj->pluck('amount')->sum(), 2);
|
||||
$invoiceTaxes = round($invObj->pluck('total_taxes')->sum(), 2);
|
||||
|
||||
if ($invoiceTotal != $amount) {
|
||||
$taxRatio = $amount/$invoiceTotal;
|
||||
$taxAmount = round($invoiceTaxes*$taxRatio, 2);
|
||||
} else {
|
||||
$taxAmount = $invoiceTaxes;
|
||||
}
|
||||
}
|
||||
|
||||
$description = "Invoices: {$invoice_numbers} for {$amount} for client {$this->authorize->client->present()->name()}";
|
||||
|
||||
$order = new OrderType();
|
||||
$order->setInvoiceNumber(substr($invoice_numbers,0,19));
|
||||
$order->setDescription(substr($description,0,255));
|
||||
|
||||
$tax = new ExtendedAmountType();
|
||||
$tax->setName('tax');
|
||||
$tax->setAmount($taxAmount);
|
||||
|
||||
$transactionRequestType = new TransactionRequestType();
|
||||
$transactionRequestType->setTransactionType('authCaptureTransaction');
|
||||
$transactionRequestType->setAmount($amount);
|
||||
$transactionRequestType->setTax($tax);
|
||||
$transactionRequestType->setTaxExempt(empty($taxAmount));
|
||||
$transactionRequestType->setOrder($order);
|
||||
$transactionRequestType->setProfile($profileToCharge);
|
||||
$transactionRequestType->setCurrencyCode($this->authorize->client->currency()->code);
|
||||
|
@ -245,7 +245,7 @@ class GoCardlessPaymentDriver extends BaseDriver
|
||||
sleep(1);
|
||||
|
||||
foreach ($request->events as $event) {
|
||||
if ($event['action'] === 'confirmed' || $event['action'] === 'paid_out') {
|
||||
if ($event['action'] === 'confirmed' || $event['action'] === 'paid_out' || $event['action'] === 'paid') {
|
||||
|
||||
nlog("Searching for transaction reference");
|
||||
|
||||
|
@ -41,6 +41,8 @@ class StripeWebhook implements ShouldQueue
|
||||
|
||||
public string $company_key;
|
||||
|
||||
private bool $url_found = false;
|
||||
|
||||
private array $events = [
|
||||
'source.chargeable',
|
||||
'charge.succeeded',
|
||||
@ -64,9 +66,7 @@ class StripeWebhook implements ShouldQueue
|
||||
|
||||
$company_gateway = CompanyGateway::find($this->company_gateway_id);
|
||||
|
||||
$driver = $company_gateway->driver();
|
||||
|
||||
$stripe = $driver->init();
|
||||
$stripe = $company_gateway->driver()->init();
|
||||
|
||||
$endpoints = \Stripe\WebhookEndpoint::all([], $stripe->stripe_connect_auth);
|
||||
|
||||
@ -77,19 +77,23 @@ class StripeWebhook implements ShouldQueue
|
||||
|
||||
if($endpoint->url === $webhook_url)
|
||||
{
|
||||
\Stripe\WebhookEndpoint::update($endpoint->id, $this->events, $stripe->stripe_connect_auth);
|
||||
|
||||
\Stripe\WebhookEndpoint::update($endpoint->id, ['enabled_events' => $this->events], $stripe->stripe_connect_auth);
|
||||
|
||||
$this->url_found = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Add new webhook */
|
||||
if(count($endpoints['data'] == 0)
|
||||
if(!$this->url_found)
|
||||
{
|
||||
|
||||
\Stripe\WebhookEndpoint::create([
|
||||
'url' => $webhook_url,
|
||||
'enabled_events' => $this->events,
|
||||
], $stripe->stripe_connect_auth)
|
||||
], $stripe->stripe_connect_auth);
|
||||
|
||||
}
|
||||
}
|
||||
|
27
app/Policies/PurchaseOrderPolicy.php
Normal file
27
app/Policies/PurchaseOrderPolicy.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class PurchaseOrderPolicy extends EntityPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function create(User $user) : bool
|
||||
{
|
||||
return $user->isAdmin() || $user->hasPermission('create_purchase_order') || $user->hasPermission('create_all');
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ use App\Models\Payment;
|
||||
use App\Models\PaymentTerm;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringExpense;
|
||||
use App\Models\RecurringInvoice;
|
||||
@ -54,6 +55,7 @@ use App\Policies\PaymentPolicy;
|
||||
use App\Policies\PaymentTermPolicy;
|
||||
use App\Policies\ProductPolicy;
|
||||
use App\Policies\ProjectPolicy;
|
||||
use App\Policies\PurchaseOrderPolicy;
|
||||
use App\Policies\QuotePolicy;
|
||||
use App\Policies\RecurringExpensePolicy;
|
||||
use App\Policies\RecurringInvoicePolicy;
|
||||
@ -103,6 +105,7 @@ class AuthServiceProvider extends ServiceProvider
|
||||
TaxRate::class => TaxRatePolicy::class,
|
||||
User::class => UserPolicy::class,
|
||||
Vendor::class => VendorPolicy::class,
|
||||
PurchaseOrder::class => PurchaseOrderPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -215,6 +215,7 @@ use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Proposal;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Task;
|
||||
@ -231,6 +232,7 @@ use App\Observers\PaymentObserver;
|
||||
use App\Observers\ProductObserver;
|
||||
use App\Observers\ProjectObserver;
|
||||
use App\Observers\ProposalObserver;
|
||||
use App\Observers\PurchaseOrderObserver;
|
||||
use App\Observers\QuoteObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
use App\Observers\TaskObserver;
|
||||
@ -593,5 +595,6 @@ class EventServiceProvider extends ServiceProvider
|
||||
Quote::observe(QuoteObserver::class);
|
||||
Task::observe(TaskObserver::class);
|
||||
User::observe(UserObserver::class);
|
||||
PurchaseOrder::observe(PurchaseOrderObserver::class);
|
||||
}
|
||||
}
|
||||
|
34
app/Repositories/PurchaseOrderRepository.php
Normal file
34
app/Repositories/PurchaseOrderRepository.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class PurchaseOrderRepository extends BaseRepository
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function save(array $data, PurchaseOrder $purchase_order) : ?PurchaseOrder
|
||||
{
|
||||
$purchase_order->fill($data);
|
||||
$purchase_order->save();
|
||||
|
||||
return $purchase_order;
|
||||
}
|
||||
|
||||
}
|
57
app/Services/PurchaseOrder/PurchaseOrderService.php
Normal file
57
app/Services/PurchaseOrder/PurchaseOrderService.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\PurchaseOrder;
|
||||
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class PurchaseOrderService
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public PurchaseOrder $purchase_order;
|
||||
|
||||
public function __construct($purchase_order)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the purchase order.
|
||||
* @return \App\Models\PurchaseOrder object
|
||||
*/
|
||||
public function save(): ?PurchaseOrder
|
||||
{
|
||||
$this->purchase_order->saveQuietly();
|
||||
|
||||
return $this->purchase_order;
|
||||
}
|
||||
|
||||
public function fillDefaults()
|
||||
{
|
||||
$settings = $this->purchase_order->client->getMergedSettings();
|
||||
|
||||
//TODO implement design, footer, terms
|
||||
|
||||
|
||||
/* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/
|
||||
if (!isset($this->purchase_order->exchange_rate) && $this->purchase_order->client->currency()->id != (int)$this->purchase_order->company->settings->currency_id)
|
||||
$this->purchase_order->exchange_rate = $this->purchase_order->client->currency()->exchange_rate;
|
||||
|
||||
if (!isset($this->purchase_order->public_notes))
|
||||
$this->purchase_order->public_notes = $this->purchase_order->client->public_notes;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -106,6 +106,12 @@ class RecurringService
|
||||
$this->stop();
|
||||
}
|
||||
|
||||
if(isset($this->recurring_entity->client))
|
||||
{
|
||||
$offset = $this->recurring_entity->client->timezone_offset();
|
||||
$this->recurring_entity->next_send_date = Carbon::parse($this->recurring_entity->next_send_date_client)->startOfDay()->addSeconds($offset);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@ use App\Http\Requests\TaskScheduler\UpdateScheduledJobRequest;
|
||||
use App\Http\Requests\TaskScheduler\UpdateScheduleRequest;
|
||||
use App\Jobs\Report\ProfitAndLoss;
|
||||
use App\Models\Company;
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Models\Scheduler;
|
||||
use App\Utils\Ninja;
|
||||
use Carbon\Carbon;
|
||||
@ -51,128 +50,116 @@ class TaskSchedulerService
|
||||
|
||||
public function store(Scheduler $scheduler, CreateScheduledTaskRequest $request)
|
||||
{
|
||||
$scheduler->action_name = $request->job;
|
||||
$scheduler->paused = $request->get('paused', false);
|
||||
$scheduler->start_from = $request->get('start_from') ? Carbon::parse((int)$request->get('start_from')) : Carbon::now();
|
||||
$scheduler->repeat_every = $request->get('repeat_every');
|
||||
$scheduler->scheduled_run = $request->get('start_from') ? Carbon::parse((int)$request->get('start_from')) : Carbon::now();;
|
||||
$scheduler->company_id = auth()->user()->company()->id;
|
||||
$scheduler = $this->setJobParameters($scheduler, $request);
|
||||
$scheduler->save();
|
||||
|
||||
$this->createJob($request, $scheduler);
|
||||
|
||||
}
|
||||
|
||||
public function update(Scheduler $scheduler, UpdateScheduleRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->validated();
|
||||
|
||||
$update = $this->scheduler->update($data);
|
||||
if ($update) {
|
||||
return response(['successfully_updated_scheduler'], 200);
|
||||
if (array_key_exists('job', $request->all())) {
|
||||
$scheduler->action_name = $request->get('job');
|
||||
$scheduler = $this->setJobParameters($scheduler, $request);
|
||||
}
|
||||
return response(['failed_to_update_scheduler'], 400);
|
||||
}
|
||||
|
||||
public function createJob(CreateScheduledTaskRequest $request, Scheduler $scheduler): bool
|
||||
{
|
||||
$job = new ScheduledJob();
|
||||
$job = $this->setJobParameters($job, $request);
|
||||
$job->scheduler_id = $scheduler->id;
|
||||
$job->company_id = auth()->user()->company()->id;
|
||||
return $job->save();
|
||||
|
||||
$data = $request->validated();
|
||||
$update = $this->scheduler->update($data);
|
||||
}
|
||||
|
||||
private function runValidation($form_request, $data)
|
||||
{
|
||||
$_syn_request_class = new $form_request();
|
||||
$_syn_request_class->setContainer(app());
|
||||
$_syn_request_class->initialize($data);
|
||||
$_syn_request_class->prepareForValidation();
|
||||
$_syn_request_class->setValidator(Validator::make($_syn_request_class->all(), $_syn_request_class->rules()));
|
||||
$_syn_request_class = new $form_request();
|
||||
$_syn_request_class->setContainer(app());
|
||||
$_syn_request_class->initialize($data);
|
||||
$_syn_request_class->prepareForValidation();
|
||||
$_syn_request_class->setValidator(Validator::make($_syn_request_class->all(), $_syn_request_class->rules()));
|
||||
|
||||
return $_syn_request_class->validated();
|
||||
return $_syn_request_class->validated();
|
||||
}
|
||||
|
||||
public function setJobParameters(ScheduledJob $job, $request): ScheduledJob
|
||||
public function setJobParameters(Scheduler $scheduler, $request)
|
||||
{
|
||||
switch ($request->job) {
|
||||
case ScheduledJob::CREATE_CLIENT_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_CLIENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ClientExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
switch ($scheduler->action_name) {
|
||||
case Scheduler::CREATE_CLIENT_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_CLIENT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(ClientExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_CLIENT_CONTACT_REPORT:
|
||||
case Scheduler::CREATE_CLIENT_CONTACT_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_CLIENT_CONTACT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(ContactExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case Scheduler::CREATE_CREDIT_REPORT:
|
||||
|
||||
$job->action_name = ScheduledJob::CREATE_CLIENT_CONTACT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ContactExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
$scheduler->action_name = Scheduler::CREATE_CREDIT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(CreditExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_CREDIT_REPORT:
|
||||
|
||||
$job->action_name = ScheduledJob::CREATE_CREDIT_REPORT;
|
||||
$job->action_class = $this->getClassPath(CreditExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_DOCUMENT_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_DOCUMENT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(DocumentExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_DOCUMENT_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_DOCUMENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(DocumentExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_EXPENSE_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_EXPENSE_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(ExpenseExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_EXPENSE_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_EXPENSE_REPORT;
|
||||
$job->action_class = $this->getClassPath(ExpenseExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_INVOICE_ITEM_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_INVOICE_ITEM_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(InvoiceItemExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_ITEM_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_INVOICE_ITEM_REPORT;
|
||||
$job->action_class = $this->getClassPath(InvoiceItemExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_INVOICE_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_INVOICE_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(InvoiceExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_INVOICE_REPORT;
|
||||
$job->action_class = $this->getClassPath(InvoiceExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_PAYMENT_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_PAYMENT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(PaymentExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PAYMENT_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_PAYMENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(PaymentExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_PRODUCT_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_PRODUCT_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(ProductExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PRODUCT_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_PRODUCT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ProductExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_PROFIT_AND_LOSS_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_PROFIT_AND_LOSS_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(ProfitAndLoss::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PROFIT_AND_LOSS_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_PROFIT_AND_LOSS_REPORT;
|
||||
$job->action_class = $this->getClassPath(ProfitAndLoss::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_QUOTE_ITEM_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_QUOTE_ITEM_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(QuoteItemExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_ITEM_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_QUOTE_ITEM_REPORT;
|
||||
$job->action_class = $this->getClassPath(QuoteItemExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_QUOTE_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_QUOTE_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(QuoteExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_QUOTE_REPORT;
|
||||
$job->action_class = $this->getClassPath(QuoteExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_RECURRING_INVOICE_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_RECURRING_INVOICE_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(RecurringInvoiceExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_RECURRING_INVOICE_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_RECURRING_INVOICE_REPORT;
|
||||
$job->action_class = $this->getClassPath(RecurringInvoiceExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_TASK_REPORT:
|
||||
$job->action_name = ScheduledJob::CREATE_TASK_REPORT;
|
||||
$job->action_class = $this->getClassPath(TaskExport::class);
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
case Scheduler::CREATE_TASK_REPORT:
|
||||
$scheduler->action_name = Scheduler::CREATE_TASK_REPORT;
|
||||
$scheduler->action_class = $this->getClassPath(TaskExport::class);
|
||||
$scheduler->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
|
||||
}
|
||||
return $job;
|
||||
|
||||
return $scheduler;
|
||||
}
|
||||
|
||||
public function getClassPath($class): string
|
||||
@ -180,15 +167,9 @@ class TaskSchedulerService
|
||||
return $class = is_object($class) ? get_class($class) : $class;
|
||||
}
|
||||
|
||||
|
||||
public function updateJob(Scheduler $scheduler, UpdateScheduledJobRequest $request)
|
||||
{
|
||||
$job = $scheduler->job;
|
||||
if (!$job) {
|
||||
return abort(404);
|
||||
}
|
||||
$job = $this->setJobParameters($job, $request);
|
||||
$job->save();
|
||||
|
||||
$scheduler = $this->setJobParameters($scheduler, $request);
|
||||
$scheduler->save();
|
||||
}
|
||||
}
|
||||
|
88
app/Transformers/PurchaseOrderTransformer.php
Normal file
88
app/Transformers/PurchaseOrderTransformer.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class PurchaseOrderTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function transform(PurchaseOrder $purchase_order)
|
||||
{
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($purchase_order->id),
|
||||
'user_id' => $this->encodePrimaryKey($purchase_order->user_id),
|
||||
'project_id' => $this->encodePrimaryKey($purchase_order->project_id),
|
||||
'assigned_user_id' => $this->encodePrimaryKey($purchase_order->assigned_user_id),
|
||||
'vendor_id' => (string) $this->encodePrimaryKey($purchase_order->vendor_id),
|
||||
'amount' => (float) $purchase_order->amount,
|
||||
'balance' => (float) $purchase_order->balance,
|
||||
'client_id' => (string) $this->encodePrimaryKey($purchase_order->client_id),
|
||||
'vendor_id' => (string) $this->encodePrimaryKey($purchase_order->vendor_id),
|
||||
'status_id' => (string) ($purchase_order->status_id ?: 1),
|
||||
'design_id' => (string) $this->encodePrimaryKey($purchase_order->design_id),
|
||||
'created_at' => (int) $purchase_order->created_at,
|
||||
'updated_at' => (int) $purchase_order->updated_at,
|
||||
'archived_at' => (int) $purchase_order->deleted_at,
|
||||
'is_deleted' => (bool) $purchase_order->is_deleted,
|
||||
'number' => $purchase_order->number ?: '',
|
||||
'discount' => (float) $purchase_order->discount,
|
||||
'po_number' => $purchase_order->po_number ?: '',
|
||||
'date' => $purchase_order->date ?: '',
|
||||
'last_sent_date' => $purchase_order->last_sent_date ?: '',
|
||||
'next_send_date' => $purchase_order->next_send_date ?: '',
|
||||
'reminder1_sent' => $purchase_order->reminder1_sent ?: '',
|
||||
'reminder2_sent' => $purchase_order->reminder2_sent ?: '',
|
||||
'reminder3_sent' => $purchase_order->reminder3_sent ?: '',
|
||||
'reminder_last_sent' => $purchase_order->reminder_last_sent ?: '',
|
||||
'due_date' => $purchase_order->due_date ?: '',
|
||||
'terms' => $purchase_order->terms ?: '',
|
||||
'public_notes' => $purchase_order->public_notes ?: '',
|
||||
'private_notes' => $purchase_order->private_notes ?: '',
|
||||
'uses_inclusive_taxes' => (bool) $purchase_order->uses_inclusive_taxes,
|
||||
'tax_name1' => $purchase_order->tax_name1 ? $purchase_order->tax_name1 : '',
|
||||
'tax_rate1' => (float) $purchase_order->tax_rate1,
|
||||
'tax_name2' => $purchase_order->tax_name2 ? $purchase_order->tax_name2 : '',
|
||||
'tax_rate2' => (float) $purchase_order->tax_rate2,
|
||||
'tax_name3' => $purchase_order->tax_name3 ? $purchase_order->tax_name3 : '',
|
||||
'tax_rate3' => (float) $purchase_order->tax_rate3,
|
||||
'total_taxes' => (float) $purchase_order->total_taxes,
|
||||
'is_amount_discount' => (bool) ($purchase_order->is_amount_discount ?: false),
|
||||
'footer' => $purchase_order->footer ?: '',
|
||||
'partial' => (float) ($purchase_order->partial ?: 0.0),
|
||||
'partial_due_date' => $purchase_order->partial_due_date ?: '',
|
||||
'custom_value1' => (string) $purchase_order->custom_value1 ?: '',
|
||||
'custom_value2' => (string) $purchase_order->custom_value2 ?: '',
|
||||
'custom_value3' => (string) $purchase_order->custom_value3 ?: '',
|
||||
'custom_value4' => (string) $purchase_order->custom_value4 ?: '',
|
||||
'has_tasks' => (bool) $purchase_order->has_tasks,
|
||||
'has_expenses' => (bool) $purchase_order->has_expenses,
|
||||
'custom_surcharge1' => (float) $purchase_order->custom_surcharge1,
|
||||
'custom_surcharge2' => (float) $purchase_order->custom_surcharge2,
|
||||
'custom_surcharge3' => (float) $purchase_order->custom_surcharge3,
|
||||
'custom_surcharge4' => (float) $purchase_order->custom_surcharge4,
|
||||
'custom_surcharge_tax1' => (bool) $purchase_order->custom_surcharge_tax1,
|
||||
'custom_surcharge_tax2' => (bool) $purchase_order->custom_surcharge_tax2,
|
||||
'custom_surcharge_tax3' => (bool) $purchase_order->custom_surcharge_tax3,
|
||||
'custom_surcharge_tax4' => (bool) $purchase_order->custom_surcharge_tax4,
|
||||
'line_items' => $purchase_order->line_items ?: (array) [],
|
||||
'entity_type' => 'credit',
|
||||
'exchange_rate' => (float) $purchase_order->exchange_rate,
|
||||
'paid_to_date' => (float) $purchase_order->paid_to_date,
|
||||
'subscription_id' => $this->encodePrimaryKey($purchase_order->subscription_id),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -100,7 +100,8 @@ class RecurringExpenseTransformer extends EntityTransformer
|
||||
'frequency_id' => (string) $recurring_expense->frequency_id,
|
||||
'remaining_cycles' => (int) $recurring_expense->remaining_cycles,
|
||||
'last_sent_date' => $recurring_expense->last_sent_date ?: '',
|
||||
'next_send_date' => $recurring_expense->next_send_date ?: '',
|
||||
// 'next_send_date' => $recurring_expense->next_send_date ?: '',
|
||||
'next_send_date' => $recurring_expense->next_send_date_client ?: '',
|
||||
'recurring_dates' => (array) [],
|
||||
];
|
||||
|
||||
|
@ -95,7 +95,8 @@ class RecurringInvoiceTransformer extends EntityTransformer
|
||||
'po_number' => $invoice->po_number ?: '',
|
||||
'date' => $invoice->date ?: '',
|
||||
'last_sent_date' => $invoice->last_sent_date ?: '',
|
||||
'next_send_date' => $invoice->next_send_date ?: '',
|
||||
// 'next_send_date' => $invoice->next_send_date ?: '',
|
||||
'next_send_date' => $invoice->next_send_date_client ?: '',
|
||||
'due_date' => $invoice->due_date ?: '',
|
||||
'terms' => $invoice->terms ?: '',
|
||||
'public_notes' => $invoice->public_notes ?: '',
|
||||
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class ScheduledJobTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function transform(ScheduledJob $job)
|
||||
{
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($job->id),
|
||||
'action_name' => (string)$job->action_name,
|
||||
'parameters' => (array)$job->parameters
|
||||
];
|
||||
}
|
||||
}
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Models\Scheduler;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
@ -20,16 +18,6 @@ class TaskSchedulerTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
protected $defaultIncludes = [
|
||||
'job'
|
||||
];
|
||||
|
||||
public function includeJob(Scheduler $scheduler)
|
||||
{
|
||||
$transformer = new ScheduledJobTransformer($this->serializer);
|
||||
|
||||
return $this->item($scheduler->job, $transformer, ScheduledJob::class);
|
||||
}
|
||||
|
||||
public function transform(Scheduler $scheduler)
|
||||
{
|
||||
@ -43,6 +31,9 @@ class TaskSchedulerTransformer extends EntityTransformer
|
||||
'updated_at' => (int)$scheduler->updated_at,
|
||||
'created_at' => (int)$scheduler->created_at,
|
||||
'archived_at' => (int) $scheduler->deleted_at,
|
||||
'action_name' => (string) $scheduler->action_name,
|
||||
'action_class' => (string) $scheduler->action_class,
|
||||
'parameters'=> (array)$scheduler->parameters,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ return [
|
||||
'require_https' => env('REQUIRE_HTTPS', true),
|
||||
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
||||
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
||||
'app_version' => '5.3.93',
|
||||
'app_tag' => '5.3.93',
|
||||
'app_version' => '5.3.94',
|
||||
'app_tag' => '5.3.94',
|
||||
'minimum_client_version' => '5.0.16',
|
||||
'terms_version' => '1.0.1',
|
||||
'api_secret' => env('API_SECRET', ''),
|
||||
|
@ -51,6 +51,7 @@ class RecurringInvoiceFactory extends Factory
|
||||
'frequency_id' => RecurringInvoice::FREQUENCY_MONTHLY,
|
||||
'last_sent_date' => now()->subMonth(),
|
||||
'next_send_date' => now()->addMonthNoOverflow(),
|
||||
'next_send_date_client' => now()->addMonthNoOverflow(),
|
||||
'remaining_cycles' => $this->faker->numberBetween(1, 10),
|
||||
'amount' => $this->faker->randomFloat(2, $min = 1, $max = 1000), // 48.8932
|
||||
|
||||
|
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePurchaseOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('purchase_orders', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('client_id')->index();
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->unsignedInteger('assigned_user_id')->nullable();
|
||||
$table->unsignedInteger('company_id')->index();
|
||||
$table->unsignedInteger('status_id');
|
||||
$table->unsignedInteger('project_id')->nullable();
|
||||
$table->unsignedInteger('vendor_id')->nullable();
|
||||
$table->unsignedInteger('recurring_id')->nullable();
|
||||
$table->unsignedInteger('design_id')->nullable();
|
||||
$table->unsignedInteger('invoice_id')->nullable();
|
||||
|
||||
$table->string('number')->nullable();
|
||||
$table->float('discount')->default(0);
|
||||
$table->boolean('is_amount_discount')->default(0);
|
||||
|
||||
$table->string('po_number')->nullable();
|
||||
$table->date('date')->nullable();
|
||||
$table->datetime('last_sent_date')->nullable();
|
||||
|
||||
$table->date('due_date')->nullable();
|
||||
|
||||
$table->boolean('is_deleted')->default(false);
|
||||
$table->mediumText('line_items')->nullable();
|
||||
$table->mediumText('backup')->nullable();
|
||||
$table->text('footer')->nullable();
|
||||
$table->text('public_notes')->nullable();
|
||||
$table->text('private_notes')->nullable();
|
||||
$table->text('terms')->nullable();
|
||||
|
||||
$table->string('tax_name1')->nullable();
|
||||
|
||||
|
||||
$table->decimal('tax_rate1', 20, 6)->default(0);
|
||||
|
||||
$table->string('tax_name2')->nullable();
|
||||
$table->decimal('tax_rate2', 20, 6)->default(0);
|
||||
|
||||
$table->string('tax_name3')->nullable();
|
||||
$table->decimal('tax_rate3', 20, 6)->default(0);
|
||||
|
||||
|
||||
$table->decimal('total_taxes', 20, 6)->default(0);
|
||||
$table->boolean('uses_inclusive_taxes')->default(0);
|
||||
|
||||
$table->date('reminder1_sent')->nullable();
|
||||
$table->date('reminder2_sent')->nullable();
|
||||
$table->date('reminder3_sent')->nullable();
|
||||
$table->date('reminder_last_sent')->nullable();
|
||||
|
||||
$table->text('custom_value1')->nullable();
|
||||
$table->text('custom_value2')->nullable();
|
||||
$table->text('custom_value3')->nullable();
|
||||
$table->text('custom_value4')->nullable();
|
||||
|
||||
|
||||
$table->datetime('next_send_date')->nullable();
|
||||
|
||||
|
||||
|
||||
$table->decimal('custom_surcharge1', 20,6)->nullable();
|
||||
$table->decimal('custom_surcharge2', 20,6)->nullable();
|
||||
$table->decimal('custom_surcharge3', 20,6)->nullable();
|
||||
$table->decimal('custom_surcharge4', 20,6)->nullable();
|
||||
|
||||
|
||||
$table->boolean('custom_surcharge_tax1')->default(false);
|
||||
$table->boolean('custom_surcharge_tax2')->default(false);
|
||||
$table->boolean('custom_surcharge_tax3')->default(false);
|
||||
$table->boolean('custom_surcharge_tax4')->default(false);
|
||||
|
||||
|
||||
$table->decimal('exchange_rate', 20, 6)->default(1);
|
||||
$table->decimal('balance', 20, 6);
|
||||
$table->decimal('partial', 20, 6)->nullable();
|
||||
$table->decimal('amount', 20, 6);
|
||||
$table->decimal('paid_to_date', 20, 6)->default(0);
|
||||
|
||||
$table->datetime('partial_due_date')->nullable();
|
||||
|
||||
$table->datetime('last_viewed')->nullable();
|
||||
|
||||
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade')->onUpdate('cascade');
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
|
||||
$table->index(['company_id', 'deleted_at']);
|
||||
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DropScheduledJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('scheduled_jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddJobRelatedFieldsToSchedulersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('schedulers', function (Blueprint $table) {
|
||||
$table->string('action_name')->index();
|
||||
$table->string('action_class');
|
||||
$table->json('parameters')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use App\Models\RecurringExpense;
|
||||
use App\Models\RecurringInvoice;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SetRecurringClientTimestamp extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('recurring_invoices', function (Blueprint $table) {
|
||||
$table->datetime('next_send_date_client')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('recurring_expenses', function (Blueprint $table) {
|
||||
$table->datetime('next_send_date_client')->nullable();
|
||||
});
|
||||
|
||||
|
||||
RecurringInvoice::whereNotNull('next_send_date')->cursor()->each(function ($recurring_invoice){
|
||||
|
||||
// $offset = $recurring_invoice->client->timezone_offset();
|
||||
// $re = Carbon::parse($recurring_invoice->next_send_date)->subSeconds($offset)->format('Y-m-d');
|
||||
$re = Carbon::parse($recurring_invoice->next_send_date)->format('Y-m-d');
|
||||
$recurring_invoice->next_send_date_client = $re;
|
||||
$recurring_invoice->saveQuietly();
|
||||
|
||||
});
|
||||
|
||||
RecurringExpense::whereNotNull('next_send_date')->cursor()->each(function ($recurring_expense){
|
||||
$recurring_expense->next_send_date_client = $recurring_expense->next_send_date;
|
||||
$recurring_expense->saveQuietly();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
4
public/flutter_service_worker.js
vendored
4
public/flutter_service_worker.js
vendored
@ -3,13 +3,13 @@ const MANIFEST = 'flutter-app-manifest';
|
||||
const TEMP = 'flutter-temp-cache';
|
||||
const CACHE_NAME = 'flutter-app-cache';
|
||||
const RESOURCES = {
|
||||
"main.dart.js": "208309d12730fc06c9bf9ef0bd0c2483",
|
||||
"main.dart.js": "dc33896edc7d40c104d85ca2d6c83176",
|
||||
"canvaskit/canvaskit.wasm": "4b83d89d9fecbea8ca46f2f760c5a9ba",
|
||||
"canvaskit/profiling/canvaskit.wasm": "95e736ab31147d1b2c7b25f11d4c32cd",
|
||||
"canvaskit/profiling/canvaskit.js": "ae2949af4efc61d28a4a80fffa1db900",
|
||||
"canvaskit/canvaskit.js": "c2b4e5f3d7a3d82aed024e7249a78487",
|
||||
"flutter.js": "0816e65a103ba8ba51b174eeeeb2cb67",
|
||||
"/": "d60cdb0e60692160d5f962b98b88e24d",
|
||||
"/": "e6fea64a985bef161e4db9ad8e7fee99",
|
||||
"favicon.png": "dca91c54388f52eded692718d5a98b8b",
|
||||
"version.json": "3afb81924daf4f751571755436069115",
|
||||
"assets/AssetManifest.json": "38d9aea341601f3a5c6fa7b5a1216ea5",
|
||||
|
263668
public/main.dart.js
vendored
263668
public/main.dart.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
261322
public/main.foss.dart.js
vendored
261322
public/main.foss.dart.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
255260
public/main.html.dart.js
vendored
255260
public/main.html.dart.js
vendored
File diff suppressed because one or more lines are too long
261226
public/main.next.dart.js
vendored
261226
public/main.next.dart.js
vendored
File diff suppressed because one or more lines are too long
15695
public/main.profile.dart.js
vendored
15695
public/main.profile.dart.js
vendored
File diff suppressed because one or more lines are too long
@ -172,7 +172,7 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale
|
||||
|
||||
|
||||
Route::resource('task_scheduler', 'TaskSchedulerController')->except('edit')->parameters(['task_scheduler' => 'scheduler']);
|
||||
Route::put('task_scheduler/{scheduler}/update_job','TaskSchedulerController@updateJob');
|
||||
|
||||
|
||||
Route::get('scheduler', 'SchedulerController@index');
|
||||
Route::post('support/messages/send', 'Support\Messages\SendingController');
|
||||
@ -206,6 +206,8 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale
|
||||
Route::post('vendors/bulk', 'VendorController@bulk')->name('vendors.bulk');
|
||||
Route::put('vendors/{vendor}/upload', 'VendorController@upload');
|
||||
|
||||
Route::resource('purchase_orders', 'PurchaseOrderController');
|
||||
|
||||
Route::get('users', 'UserController@index');
|
||||
Route::get('users/{user}', 'UserController@show')->middleware('password_protected');
|
||||
Route::put('users/{user}', 'UserController@update')->middleware('password_protected');
|
||||
|
142
tests/Feature/PurchaseOrderTest.php
Normal file
142
tests/Feature/PurchaseOrderTest.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
|
||||
namespace Tests;
|
||||
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PurchaseOrderTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testPurchaseOrderRest()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id).'/edit');
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$credit_update = [
|
||||
'tax_name1' => 'dippy',
|
||||
];
|
||||
|
||||
$this->assertNotNull($this->purchase_order);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $credit_update)
|
||||
->assertStatus(200);
|
||||
}
|
||||
public function testPostNewPurchaseOrder()
|
||||
{
|
||||
$purchase_order = [
|
||||
'status_id' => 1,
|
||||
'number' => 'dfdfd',
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => 1,
|
||||
'number' => '34343xx43',
|
||||
'public_notes' => 'notes',
|
||||
'is_deleted' => 0,
|
||||
'custom_value1' => 0,
|
||||
'custom_value2' => 0,
|
||||
'custom_value3' => 0,
|
||||
'custom_value4' => 0,
|
||||
'status' => 1,
|
||||
'client_id' => $this->encodePrimaryKey($this->client->id),
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/', $purchase_order)
|
||||
->assertStatus(200);
|
||||
}
|
||||
public function testPurchaseOrderDelete()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
public function testPurchaseOrderUpdate()
|
||||
{
|
||||
$data = [
|
||||
'status_id' => 1,
|
||||
'number' => 'dfdfd',
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => 1,
|
||||
'number' => '3434343',
|
||||
'public_notes' => 'notes',
|
||||
'is_deleted' => 0,
|
||||
'custom_value1' => 0,
|
||||
'custom_value2' => 0,
|
||||
'custom_value3' => 0,
|
||||
'custom_value4' => 0,
|
||||
'status' => 1,
|
||||
'client_id' => $this->encodePrimaryKey($this->client->id),
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/purchase_orders/'.$this->encodePrimaryKey($this->purchase_order->id), $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/', $data);
|
||||
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
namespace Tests\Feature\Scheduler;
|
||||
|
||||
use App\Export\CSV\ClientExport;
|
||||
use App\Models\ScheduledJob;
|
||||
use App\Models\Scheduler;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Carbon\Carbon;
|
||||
@ -40,7 +39,7 @@ class SchedulerTest extends TestCase
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
// $this->withoutExceptionHandling();
|
||||
// $this->withoutExceptionHandling();
|
||||
|
||||
}
|
||||
|
||||
@ -48,7 +47,7 @@ class SchedulerTest extends TestCase
|
||||
{
|
||||
$data = [
|
||||
'repeat_every' => Scheduler::DAILY,
|
||||
'job' => ScheduledJob::CREATE_CLIENT_REPORT,
|
||||
'job' => Scheduler::CREATE_CLIENT_REPORT,
|
||||
'date_key' => '123',
|
||||
'report_keys' => ['test'],
|
||||
'date_range' => 'all',
|
||||
@ -57,16 +56,10 @@ class SchedulerTest extends TestCase
|
||||
|
||||
$response = false;
|
||||
|
||||
// try {
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/task_scheduler/', $data);
|
||||
// } catch (ValidationException $e) {
|
||||
// $message = json_decode($e->validator->getMessageBag(), 1);
|
||||
// nlog($message);
|
||||
// }
|
||||
// $response->assertStatus(200);
|
||||
|
||||
|
||||
$response->assertSessionHasErrors();
|
||||
@ -109,12 +102,14 @@ class SchedulerTest extends TestCase
|
||||
])->get('/api/v1/task_scheduler/' . $this->encodePrimaryKey($scheduler->id));
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals('create_client_report', $arr['data']['job']['action_name']);
|
||||
$this->assertEquals('create_client_report', $arr['data']['action_name']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function testSchedulerJobCanBeUpdated()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
@ -124,10 +119,10 @@ class SchedulerTest extends TestCase
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$this->assertSame('create_client_report', $scheduler->job->action_name);
|
||||
$this->assertSame('create_client_report', $scheduler->action_name);
|
||||
|
||||
$updateData = [
|
||||
'job' => ScheduledJob::CREATE_CREDIT_REPORT,
|
||||
'job' => Scheduler::CREATE_CREDIT_REPORT,
|
||||
'date_range' => 'all',
|
||||
'report_keys' => ['test1']
|
||||
];
|
||||
@ -135,19 +130,19 @@ class SchedulerTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/task_scheduler/' . $this->encodePrimaryKey($scheduler->id) . '/update_job', $updateData);
|
||||
])->put('/api/v1/task_scheduler/' . $this->encodePrimaryKey($scheduler->id), $updateData);
|
||||
|
||||
$updatedSchedulerJob = Scheduler::first()->job->action_name;
|
||||
$updatedSchedulerJob = Scheduler::first()->action_name;
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertSame('create_credit_report', $arr['data']['job']['action_name']);
|
||||
$this->assertSame('create_credit_report', $arr['data']['action_name']);
|
||||
}
|
||||
|
||||
public function createScheduler()
|
||||
{
|
||||
$data = [
|
||||
'repeat_every' => Scheduler::DAILY,
|
||||
'job' => ScheduledJob::CREATE_CLIENT_REPORT,
|
||||
'job' => Scheduler::CREATE_CLIENT_REPORT,
|
||||
'date_key' => '123',
|
||||
'report_keys' => ['test'],
|
||||
'date_range' => 'all',
|
||||
|
@ -20,6 +20,7 @@ use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceInvitationFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Factory\InvoiceToRecurringInvoiceFactory;
|
||||
use App\Factory\PurchaseOrderFactory;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
||||
use App\Models\Account;
|
||||
@ -181,10 +182,10 @@ trait MockAccountData
|
||||
'hosted_client_count' => 1000,
|
||||
'hosted_company_count' => 1000
|
||||
]);
|
||||
|
||||
|
||||
$this->account->num_users = 3;
|
||||
$this->account->save();
|
||||
|
||||
|
||||
$this->company = Company::factory()->create([
|
||||
'account_id' => $this->account->id,
|
||||
]);
|
||||
@ -212,7 +213,7 @@ trait MockAccountData
|
||||
$settings->use_credits_payment = 'always';
|
||||
$settings->timezone_id = '1';
|
||||
$settings->entity_send_time = 0;
|
||||
|
||||
|
||||
$this->company->settings = $settings;
|
||||
$this->company->save();
|
||||
|
||||
@ -387,7 +388,7 @@ trait MockAccountData
|
||||
$this->invoice->setRelation('company', $this->company);
|
||||
|
||||
$this->invoice->save();
|
||||
|
||||
|
||||
$this->invoice->load("client");
|
||||
|
||||
InvoiceInvitation::factory()->create([
|
||||
@ -447,13 +448,43 @@ trait MockAccountData
|
||||
|
||||
$this->quote->save();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$this->purchase_order = PurchaseOrderFactory::create($this->company->id, $user_id);
|
||||
$this->purchase_order->client_id = $this->client->id;
|
||||
|
||||
|
||||
$this->purchase_order->amount = 10;
|
||||
$this->purchase_order->balance = 10;
|
||||
|
||||
// $this->credit->due_date = now()->addDays(200);
|
||||
|
||||
$this->purchase_order->tax_name1 = '';
|
||||
$this->purchase_order->tax_name2 = '';
|
||||
$this->purchase_order->tax_name3 = '';
|
||||
|
||||
$this->purchase_order->tax_rate1 = 0;
|
||||
$this->purchase_order->tax_rate2 = 0;
|
||||
$this->purchase_order->tax_rate3 = 0;
|
||||
|
||||
$this->purchase_order->uses_inclusive_taxes = false;
|
||||
$this->purchase_order->save();
|
||||
|
||||
|
||||
|
||||
|
||||
$this->credit = CreditFactory::create($this->company->id, $user_id);
|
||||
$this->credit->client_id = $this->client->id;
|
||||
|
||||
$this->credit->line_items = $this->buildLineItems();
|
||||
$this->credit->amount = 10;
|
||||
$this->credit->balance = 10;
|
||||
|
||||
|
||||
// $this->credit->due_date = now()->addDays(200);
|
||||
|
||||
$this->credit->tax_name1 = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user