mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Purchase Order Actions
This commit is contained in:
parent
c0ba8aa822
commit
a6327b7694
@ -180,6 +180,8 @@ class CompanySettings extends BaseSettings
|
|||||||
public $email_subject_payment = ''; //@implemented
|
public $email_subject_payment = ''; //@implemented
|
||||||
public $email_subject_payment_partial = ''; //@implemented
|
public $email_subject_payment_partial = ''; //@implemented
|
||||||
public $email_subject_statement = ''; //@implemented
|
public $email_subject_statement = ''; //@implemented
|
||||||
|
public $email_subject_purchase_order = ''; //@implemented
|
||||||
|
public $email_template_purchase_order = ''; //@implemented
|
||||||
public $email_template_invoice = ''; //@implemented
|
public $email_template_invoice = ''; //@implemented
|
||||||
public $email_template_credit = ''; //@implemented
|
public $email_template_credit = ''; //@implemented
|
||||||
public $email_template_quote = ''; //@implemented
|
public $email_template_quote = ''; //@implemented
|
||||||
|
@ -14,12 +14,14 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Factory\PurchaseOrderFactory;
|
use App\Factory\PurchaseOrderFactory;
|
||||||
use App\Filters\PurchaseOrderFilters;
|
use App\Filters\PurchaseOrderFilters;
|
||||||
|
use App\Http\Requests\PurchaseOrder\ActionPurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\CreatePurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\CreatePurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\DestroyPurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\DestroyPurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\EditPurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\EditPurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\ShowPurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\ShowPurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\StorePurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\StorePurchaseOrderRequest;
|
||||||
use App\Http\Requests\PurchaseOrder\UpdatePurchaseOrderRequest;
|
use App\Http\Requests\PurchaseOrder\UpdatePurchaseOrderRequest;
|
||||||
|
use App\Jobs\Invoice\ZipInvoices;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\PurchaseOrder;
|
use App\Models\PurchaseOrder;
|
||||||
use App\Repositories\PurchaseOrderRepository;
|
use App\Repositories\PurchaseOrderRepository;
|
||||||
@ -408,4 +410,221 @@ class PurchaseOrderController extends BaseController
|
|||||||
|
|
||||||
return $this->itemResponse($purchase_order->fresh());
|
return $this->itemResponse($purchase_order->fresh());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform bulk actions on the list view.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/purchase_orders/bulk",
|
||||||
|
* operationId="bulkPurchaseOrderss",
|
||||||
|
* tags={"purchase_orders"},
|
||||||
|
* summary="Performs bulk actions on an array of purchase_orders",
|
||||||
|
* description="",
|
||||||
|
* @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/index"),
|
||||||
|
* @OA\RequestBody(
|
||||||
|
* description="Purchase Order IDS",
|
||||||
|
* required=true,
|
||||||
|
* @OA\MediaType(
|
||||||
|
* mediaType="application/json",
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="array",
|
||||||
|
* @OA\Items(
|
||||||
|
* type="integer",
|
||||||
|
* description="Array of hashed IDs to be bulk 'actioned",
|
||||||
|
* example="[0,1,2,3]",
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="The Bulk Action response",
|
||||||
|
* @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 bulk()
|
||||||
|
{
|
||||||
|
|
||||||
|
$action = request()->input('action');
|
||||||
|
|
||||||
|
$ids = request()->input('ids');
|
||||||
|
|
||||||
|
$purchase_orders = PurchaseOrder::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
|
||||||
|
|
||||||
|
if (! $invoices) {
|
||||||
|
return response()->json(['message' => 'No Purchase Orders Found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Download Purchase Order/s
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($action == 'bulk_download' && $purchase_orders->count() > 1) {
|
||||||
|
$purchase_orders->each(function ($purchase_order) {
|
||||||
|
if (auth()->user()->cannot('view', $purchase_order)) {
|
||||||
|
nlog("access denied");
|
||||||
|
return response()->json(['message' => ctrans('text.access_denied')]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ZipInvoices::dispatch($purchase_orders, $purchase_orders->first()->company, auth()->user());
|
||||||
|
|
||||||
|
return response()->json(['message' => ctrans('texts.sent_message')], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send the other actions to the switch
|
||||||
|
*/
|
||||||
|
$purchase_orders->each(function ($purchase_order, $key) use ($action) {
|
||||||
|
if (auth()->user()->can('edit', $purchase_order)) {
|
||||||
|
$this->performAction($purchase_order, $action, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Need to understand which permission are required for the given bulk action ie. view / edit */
|
||||||
|
|
||||||
|
return $this->listResponse(PurchaseOrder::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/api/v1/purchase_orders/{id}/{action}",
|
||||||
|
* operationId="actionPurchaseOrder",
|
||||||
|
* tags={"purchase_orders"},
|
||||||
|
* summary="Performs a custom action on an purchase order",
|
||||||
|
* description="Performs a custom action on an purchase order.
|
||||||
|
*
|
||||||
|
* The current range of actions are as follows
|
||||||
|
* - mark_paid
|
||||||
|
* - download
|
||||||
|
* - archive
|
||||||
|
* - delete
|
||||||
|
* - email",
|
||||||
|
* @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\Parameter(
|
||||||
|
* name="action",
|
||||||
|
* in="path",
|
||||||
|
* description="The action string to be performed",
|
||||||
|
* example="clone_to_quote",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* format="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Returns the invoice 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"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
* @param ActionPurchaseOrderRequest $request
|
||||||
|
* @param PurchaseOrder $purchase_order
|
||||||
|
* @param $action
|
||||||
|
* @return \App\Http\Controllers\Response|\Illuminate\Http\JsonResponse|Response|mixed|\Symfony\Component\HttpFoundation\StreamedResponse
|
||||||
|
*/
|
||||||
|
public function action(ActionPurchaseOrderRequest $request, PurchaseOrder $purchase_order, $action)
|
||||||
|
{
|
||||||
|
return $this->performAction($invoice, $action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function performAction(PurchaseOrder $purchase_order, $action, $bulk = false)
|
||||||
|
{
|
||||||
|
/*If we are using bulk actions, we don't want to return anything */
|
||||||
|
switch ($action) {
|
||||||
|
case 'mark_sent':
|
||||||
|
$purchase_order->service()->markSent()->save();
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->itemResponse($purchase_order);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'download':
|
||||||
|
|
||||||
|
$file = $purchase_order->service()->getPurchaseOrderPdf();
|
||||||
|
|
||||||
|
return response()->streamDownload(function () use($file) {
|
||||||
|
echo Storage::get($file);
|
||||||
|
}, basename($file), ['Content-Type' => 'application/pdf']);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'restore':
|
||||||
|
$this->purchase_order_repository->restore($purchase_order);
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->listResponse($purchase_order);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'archive':
|
||||||
|
$this->purchase_order_repository->archive($purchase_order);
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->listResponse($purchase_order);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
|
||||||
|
$this->purchase_order_repository->delete($purchase_order);
|
||||||
|
|
||||||
|
if (! $bulk) {
|
||||||
|
return $this->listResponse($purchase_order);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'email':
|
||||||
|
//check query parameter for email_type and set the template else use calculateTemplate
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
return response()->json(['message' => ctrans('texts.action_unavailable', ['action' => $action])], 400);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
class ActionPurchaseOrderRequest extends Request
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private $error_msg;
|
||||||
|
|
||||||
|
// private $invoice;
|
||||||
|
|
||||||
|
public function authorize() : bool
|
||||||
|
{
|
||||||
|
return auth()->user()->can('edit', $this->purchase_order);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'action' => 'required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$input = $this->all();
|
||||||
|
|
||||||
|
if($this->action){
|
||||||
|
$input['action'] = $this->action;
|
||||||
|
} elseif (!array_key_exists('action', $input) ) {
|
||||||
|
$this->error_msg = 'Action is a required field';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->replace($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'action' => $this->error_msg,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -49,8 +49,8 @@ class SystemMaintenance implements ShouldQueue
|
|||||||
|
|
||||||
nlog("Starting System Maintenance");
|
nlog("Starting System Maintenance");
|
||||||
|
|
||||||
// if(Ninja::isHosted())
|
if(Ninja::isHosted())
|
||||||
// return;
|
return;
|
||||||
|
|
||||||
$delete_pdf_days = config('ninja.maintenance.delete_pdfs');
|
$delete_pdf_days = config('ninja.maintenance.delete_pdfs');
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@ class CreatePurchaseOrderInvitationsTable extends Migration
|
|||||||
$settings->purchase_order_public_notes = ''; //@implemented
|
$settings->purchase_order_public_notes = ''; //@implemented
|
||||||
$settings->purchase_order_number_pattern = ''; //@implemented
|
$settings->purchase_order_number_pattern = ''; //@implemented
|
||||||
$settings->purchase_order_number_counter = 1; //@implemented
|
$settings->purchase_order_number_counter = 1; //@implemented
|
||||||
|
$settings->email_subject_purchase_order = '';
|
||||||
|
$settings->email_template_purchase_order = '';
|
||||||
$company->settings = $settings;
|
$company->settings = $settings;
|
||||||
$company->save();
|
$company->save();
|
||||||
});
|
});
|
||||||
|
@ -207,6 +207,8 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale
|
|||||||
Route::put('vendors/{vendor}/upload', 'VendorController@upload');
|
Route::put('vendors/{vendor}/upload', 'VendorController@upload');
|
||||||
|
|
||||||
Route::resource('purchase_orders', 'PurchaseOrderController');
|
Route::resource('purchase_orders', 'PurchaseOrderController');
|
||||||
|
Route::post('purchase_orders/bulk', 'PurchaseOrderController@bulk')->name('purchase_orders.bulk');
|
||||||
|
Route::get('purchase_orders/{purchase_order}/{action}', 'PurchaseOrderController@action')->name('purchase_orders.action');
|
||||||
|
|
||||||
Route::get('users', 'UserController@index');
|
Route::get('users', 'UserController@index');
|
||||||
Route::get('users/{user}', 'UserController@show')->middleware('password_protected');
|
Route::get('users/{user}', 'UserController@show')->middleware('password_protected');
|
||||||
|
Loading…
Reference in New Issue
Block a user