diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 6eb345259cff..75f0fb465774 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -33,6 +33,7 @@ use App\Transformers\PurchaseOrderTransformer; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Storage; class PurchaseOrderController extends BaseController { @@ -488,7 +489,7 @@ class PurchaseOrderController extends BaseController * Download Purchase Order/s */ - if ($action == 'bulk_download' && $purchase_orders->count() > 1) { + if ($action == 'bulk_download' && $purchase_orders->count() >= 1) { $purchase_orders->each(function ($purchase_order) { if (auth()->user()->cannot('view', $purchase_order)) { nlog("access denied"); @@ -582,7 +583,7 @@ class PurchaseOrderController extends BaseController */ public function action(ActionPurchaseOrderRequest $request, PurchaseOrder $purchase_order, $action) { - return $this->performAction($invoice, $action); + return $this->performAction($purchase_order, $action); } private function performAction(PurchaseOrder $purchase_order, $action, $bulk = false) diff --git a/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php b/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php index 34d926c0eed9..e95d86cf72b8 100644 --- a/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php +++ b/app/Jobs/PurchaseOrder/ZipPurchaseOrders.php @@ -18,6 +18,7 @@ use App\Jobs\Util\UnlinkFile; use App\Jobs\Vendor\CreatePurchaseOrderPdf; use App\Libraries\MultiDB; use App\Mail\DownloadInvoices; +use App\Mail\DownloadPurchaseOrders; use App\Models\Company; use App\Models\User; use App\Utils\TempFile; @@ -101,7 +102,7 @@ class ZipPurchaseOrders implements ShouldQueue Storage::put($path.$file_name, $zipFile->outputAsString()); $nmo = new NinjaMailerObject; - $nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company); + $nmo->mailable = new DownloadPurchaseOrders(Storage::url($path.$file_name), $this->company); $nmo->to_user = $this->user; $nmo->settings = $this->settings; $nmo->company = $this->company; diff --git a/app/Mail/DownloadPurchaseOrders.php b/app/Mail/DownloadPurchaseOrders.php new file mode 100644 index 000000000000..27fcd51a7bff --- /dev/null +++ b/app/Mail/DownloadPurchaseOrders.php @@ -0,0 +1,56 @@ +file_path = $file_path; + + $this->company = $company; + } + + /** + * Build the message. + */ + public function build() + { + + App::setLocale($this->company->getLocale()); + + return $this->from(config('mail.from.address'), config('mail.from.name')) + ->subject(ctrans('texts.download_files')) + ->text('email.admin.download_invoices_text', [ + 'url' => $this->file_path, + ]) + ->view('email.admin.download_purchase_orders', [ + 'url' => $this->file_path, + 'logo' => $this->company->present()->logo, + 'whitelabel' => $this->company->account->isPaid() ? true : false, + 'settings' => $this->company->settings, + 'greeting' => $this->company->present()->name(), + ]); + } +} diff --git a/app/Services/PurchaseOrder/GetPurchaseOrderPdf.php b/app/Services/PurchaseOrder/GetPurchaseOrderPdf.php index 8c75b87899a9..7d074ce4bb24 100644 --- a/app/Services/PurchaseOrder/GetPurchaseOrderPdf.php +++ b/app/Services/PurchaseOrder/GetPurchaseOrderPdf.php @@ -31,7 +31,7 @@ class GetPurchaseOrderPdf extends AbstractService { if (! $this->contact) { - $this->contact = $this->purchase_order->vendor->contacts()->where('send_email', true)->first(); + $this->contact = $this->purchase_order->vendor->contacts()->orderBy('send_email', 'DESC')->first(); } $invitation = $this->purchase_order->invitations()->where('vendor_contact_id', $this->contact->id)->first(); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 413a966fbe12..ff9b7280a44d 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4622,6 +4622,7 @@ $LANG = array( 'purchase_order_subject' => 'New Purchase Order :number from :account', 'purchase_order_message' => 'To view your purchase order for :amount, click the link below.', 'view_purchase_order' => 'View Purchase Order', + 'purchase_orders_backup_subject' => 'Your purchase orders are ready for download', ); diff --git a/resources/views/email/admin/download_purchase_orders.blade.php b/resources/views/email/admin/download_purchase_orders.blade.php new file mode 100644 index 000000000000..ce40579d97ea --- /dev/null +++ b/resources/views/email/admin/download_purchase_orders.blade.php @@ -0,0 +1,10 @@ +@component('email.template.admin', ['logo' => $logo, 'settings' => $settings]) +
{{ ctrans('texts.download_timeframe') }}
+ + + {{ ctrans('texts.download') }} + +