Menambahkan fitur kirim email tender part 1

This commit is contained in:
2024-11-20 08:24:59 +07:00
parent 7db25c2226
commit 17ca3b2e50
18 changed files with 1554 additions and 25 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace Modules\Lpj\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
// use Illuminate\Contracts\Queue\ShouldQueue;
class SendPenawaranKJPPEmail extends Mailable
{
use Queueable, SerializesModels;
// Tambahkan properti untuk data yang akan dikirimkan ke view
public $dp1;
public $penawaran;
public $permohonan;
public $villages;
public $districts;
public $cities;
public $provinces;
/**
* Create a new message instance.
*/
public function __construct($dp1, $penawaran, $permohonan, $villages, $districts, $cities, $provinces)
{
// Assign data yang diterima ke properti
$this->dp1 = $dp1;
$this->penawaran = $penawaran;
$this->permohonan = $permohonan;
$this->villages = $villages;
$this->districts = $districts;
$this->cities = $cities;
$this->provinces = $provinces;
}
/**
* Build the message.
*/
public function build(): self
{
// Kirim data ke view
return $this->view('lpj::penawaran.kirimEmailKJPP')
->with([
'dp1' => $this->dp1,
'penawaran' => $this->penawaran,
'permohonan' => $this->permohonan,
'villages' => $this->villages,
'districts' => $this->districts,
'cities' => $this->cities,
'provinces' => $this->provinces,
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Modules\Lpj\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
// use Illuminate\Contracts\Queue\ShouldQueue;
class SendPenawaranTenderEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct()
{
//
}
/**
* Build the message.
*/
public function build(): self
{
return $this->view('lpj::penawaran.kirimEmail');
}
}

View File

@@ -3,7 +3,6 @@
namespace Modules\Lpj\Http\Controllers;
use Exception;
use Barryvdh\DomPDF\PDF;
use Illuminate\Http\Request;
use Modules\Lpj\Models\KJPP;
use Modules\Location\Models\City;
@@ -16,13 +15,14 @@ use Modules\Location\Models\Village;
use Modules\Lpj\Models\JenisLaporan;
use Modules\Location\Models\District;
use Modules\Location\Models\Province;
use Illuminate\Support\Facades\Storage;
use Modules\Lpj\Models\PenawaranTender;
use Modules\Lpj\Models\StatusPermohonan;
use Modules\Lpj\Models\TujuanPenilaianKJPP;
use Modules\Lpj\Models\PenawaranDetailTender;
use Modules\Lpj\Exports\PenawaranTenderExport;
use Modules\Lpj\Http\Requests\TenderPenawaranRequest;
use Modules\Lpj\Jobs\SendPenawaranKJPPTenderJob;
use Modules\Lpj\Jobs\SendPenawaranTenderJob;
class TenderController extends Controller
{
@@ -321,6 +321,57 @@ class TenderController extends Controller
return view('lpj::penawaran.surat_tender', compact('penawaran', 'noreg', 'permohonan', 'villages', 'districts', 'cities', 'provinces'));
}
public function suratTenderKJPP($noreg, $id)
{
$kjpp = KJPP::find($id);
$permohonan = Permohonan::where('nomor_registrasi', '=', $noreg)->first();
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
if (!$penawaran) {
return redirect()->route('tender.penawaran.createPenawaran', ['noreg' => $penawaran->nomor_registrasi])
->with('error', 'Anda Belum Membuat Penawaran. Silahkan isi terlebih dahulu!');
}
if ($penawaran->status != 'tender') {
return redirect()->route('spk.index')->with('error', 'Penawaran dengan nomor registrasi ini sudah masuk SPK tidak bisa masuk penawaran lagi!');
}
// Kalau tidak ada dokumen jaminan maka di arahkan ke halaman dokumen jaminan
if ($permohonan->debiture->documents->isEmpty()) {
return redirect()->route('debitur.jaminan.create', ['id' => $permohonan->debiture->id])
->with('error', 'Anda Belum Membuat Dokumen Jaminan. Silahkan isi terlebih dahulu!');
}
foreach ($permohonan->debiture->documents as $document) {
$village_permohonan = $document->village_code;
$district_permohonan = $document->district_code;
$city_permohonan = $document->city_code;
$province_permohonan = $document->province_code;
}
$villages = Village::where('code', $village_permohonan)->get();
$districts = District::where('code', $district_permohonan)->get();
$cities = City::where('code', $city_permohonan)->get();
$provinces = Province::where('code', $province_permohonan)->get();
date_default_timezone_set('Asia/Jakarta');
$now = date('Y-m-d H:i:s');
// Jika batas tanggal penawaran sudah lewat
if ($penawaran->end_date < $now) {
return redirect()->route('tender.penawaran.editPenawaran', ['noreg' => $noreg])
->with('error', 'Sudah Kadaluarsa. Silahkan perpanjang tanggal penawaran terlebih dahulu!');
}
$detail_penawaran = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $kjpp->id)->get();
foreach ($detail_penawaran as $detail) {
$detail_penawaran_1 = $detail->kjpp;
}
return view('lpj::penawaran.surat_tender_kjpp', compact('penawaran', 'noreg', 'permohonan', 'villages', 'districts', 'cities', 'provinces', 'detail_penawaran_1', 'id'));
}
public function datatablesPenawaran(Request $request)
{
if (is_null($this->user) || !$this->user->can('penawaran.view')) {
@@ -500,4 +551,276 @@ class TenderController extends Controller
return $pdf->download('surat_tender' . time() . '.pdf');
}
public function downloadSuratTenderKJPP($noreg, $id)
{
$kjpp = KJPP::find($id);
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
$permohonan = Permohonan::where('nomor_registrasi', '=', $noreg)->first();
if ($penawaran->status != 'tender') {
return redirect()->route('spk.index')->with('error', 'Penawaran dengan nomor registrasi ini sudah masuk SPK tidak bisa masuk penawaran lagi!');
}
foreach ($permohonan->debiture->documents as $document) {
$village_permohonan = $document->village_code;
$district_permohonan = $document->district_code;
$city_permohonan = $document->city_code;
$province_permohonan = $document->province_code;
}
$villages = Village::where('code', $village_permohonan)->get();
$districts = District::where('code', $district_permohonan)->get();
$cities = City::where('code', $city_permohonan)->get();
$provinces = Province::where('code', $province_permohonan)->get();
$detail_penawaran = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $kjpp->id)->get();
foreach ($detail_penawaran as $detail) {
$detail_penawaran_1 = $detail->kjpp;
}
$pdf = app('dompdf.wrapper'); // create an instance of the PDF class
$pdf->loadView('lpj::penawaran.surat_tender_kjpp_download', compact('penawaran', 'permohonan', 'villages', 'districts', 'cities', 'provinces', 'detail_penawaran_1'));
return $pdf->download('surat_tender_kjpp' . time() . '.pdf');
}
// Kirim Email
public function showKirimEmail($noreg)
{
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
$permohonan = Permohonan::where('nomor_registrasi', '=', $noreg)->first();
if (!$penawaran) {
return redirect()->route('tender.penawaran.createPenawaran', ['noreg' => $noreg])
->with('error', 'Anda Belum Membuat Penawaran. Silahkan isi terlebih dahulu!');
}
if ($penawaran->status != 'tender') {
return redirect()->route('spk.index')->with('error', 'Penawaran dengan nomor registrasi ini sudah masuk SPK tidak bisa masuk penawaran lagi!');
}
if ($permohonan->debiture->documents->isEmpty()) {
return redirect()->route('debitur.jaminan.create', ['id' => $permohonan->debiture->id])
->with('error', 'Anda Belum Membuat Dokumen Jaminan. Silahkan isi terlebih dahulu!');
}
return view('lpj::penawaran.showKirimEmail', compact('penawaran', 'permohonan', 'noreg'));
}
public function dataTablesShowKirimSurat(Request $request, $noreg)
{
if (is_null($this->user) || !$this->user->can('penawaran.view')) {
// abort(403, 'Sorry! You are not allowed to view users.');
}
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
// Retrieve data from the database
$query = PenawaranDetailTender::query()->where('penawaran_id', '=', $penawaran->id)->with(['kjpp', 'penawaran', 'emailTenderLog']);
// Apply sorting if provided
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
$order = $request->get('sortOrder');
$column = $request->get('sortField');
// Handle sorting for related table columns
if ($column === 'nama_kjpp') {
// Join with the KJPP table and sort by the name column
$query->join('kjpp', 'detail_penawaran.kjpp_rekanan_id', '=', 'kjpp.id')
->orderBy('kjpp.name', $order)
->select('detail_penawaran.*'); // Select only the main table columns to avoid conflicts
} else {
// Sort by columns in the main table
$query->orderBy($column, $order);
}
}
// Get the total count of records
$totalRecords = $query->count();
// Apply pagination if provided
if ($request->has('page') && $request->has('size')) {
$page = $request->get('page');
$size = $request->get('size');
$offset = ($page - 1) * $size; // Calculate the offset
$query->skip($offset)->take($size);
}
// Get the filtered count of records
$filteredRecords = $query->count();
// Get the data for the current page
$data = $query->with(['kjpp', 'penawaran', 'emailTenderLog'])->get();
// add column "No"
$i = 0;
$j = 1;
foreach ($data as $obj) {
// tanggal_permohonan
$data[$i]->numbernya = $j;
$i++;
$j++;
}
// Calculate the page count
$pageCount = ceil($totalRecords / $request->get('size'));
// Calculate the current page number
$currentPage = 0 + 1;
// Return the response data as a JSON object
return response()->json([
'draw' => $request->get('draw'),
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $data,
]);
}
public function kirimEmailAll($noreg)
{
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
$permohonan = Permohonan::where('nomor_registrasi', '=', $noreg)->first();
if (!$penawaran) {
return redirect()->route('tender.penawaran.createPenawaran', ['noreg' => $noreg])
->with('error', 'Anda Belum Membuat Penawaran. Silahkan isi terlebih dahulu!');
}
if ($penawaran->status != 'tender') {
return redirect()->route('spk.index')->with('error', 'Penawaran dengan nomor registrasi ini sudah masuk SPK tidak bisa masuk penawaran lagi!');
}
if ($permohonan->debiture->documents->isEmpty()) {
return redirect()->route('debitur.jaminan.create', ['id' => $permohonan->debiture->id])
->with('error', 'Anda Belum Membuat Dokumen Jaminan. Silahkan isi terlebih dahulu!');
}
$detail_penawaran = PenawaranDetailTender::where('penawaran_id', '=', $penawaran->id)->where('status', '=', 1)->pluck('kjpp_rekanan_id')->toArray();
$kjpps = KJPP::whereIn('id', $detail_penawaran)
->get()
->map(function ($item) {
$emails = [$item->email_kantor];
// Parse JSON string jika ada dan tidak kosong
if (!empty($item->detail_email_kantor) && $item->detail_email_kantor !== '[]') {
$detail_emails = json_decode($item->detail_email_kantor, true);
if (is_array($detail_emails)) {
foreach ($detail_emails as $detail) {
if (isset($detail['email_kantor'])) {
$emails[] = $detail['email_kantor'];
}
}
}
}
return array_filter($emails);
})
->flatten()
->toArray();
foreach ($permohonan->debiture->documents as $document) {
$village_permohonan = $document->village_code;
$district_permohonan = $document->district_code;
$city_permohonan = $document->city_code;
$province_permohonan = $document->province_code;
}
$villages = Village::where('code', $village_permohonan)->get();
$districts = District::where('code', $district_permohonan)->get();
$cities = City::where('code', $city_permohonan)->get();
$provinces = Province::where('code', $province_permohonan)->get();
SendPenawaranTenderJob::dispatch(
$kjpps,
$penawaran,
$permohonan,
$villages,
$districts,
$cities,
$provinces
);
return redirect()->route('tender.penawaran.ulang.index')->with('success', 'Email Penawaran Berhasil Terkirim!');
}
public function kirimEmailKJPP($noreg, $id)
{
$penawaran = PenawaranTender::where('nomor_registrasi', '=', $noreg)->first();
$permohonan = Permohonan::where('nomor_registrasi', '=', $noreg)->first();
if (!$penawaran) {
return redirect()->route('tender.penawaran.createPenawaran', ['noreg' => $noreg])
->with('error', 'Anda Belum Membuat Penawaran. Silahkan isi terlebih dahulu!');
}
if ($penawaran->status != 'tender') {
return redirect()->route('spk.index')->with('error', 'Penawaran dengan nomor registrasi ini sudah masuk SPK tidak bisa masuk penawaran lagi!');
}
if ($permohonan->debiture->documents->isEmpty()) {
return redirect()->route('debitur.jaminan.create', ['id' => $permohonan->debiture->id])
->with('error', 'Anda Belum Membuat Dokumen Jaminan. Silahkan isi terlebih dahulu!');
}
$detail_penawaran = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $id)->pluck('kjpp_rekanan_id')->toArray();
$kjpps = KJPP::whereIn('id', $detail_penawaran)
->get()
->map(function ($item) {
$emails = [$item->email_kantor];
// Parse JSON string jika ada dan tidak kosong
if (!empty($item->detail_email_kantor) && $item->detail_email_kantor !== '[]') {
$detail_emails = json_decode($item->detail_email_kantor, true);
if (is_array($detail_emails)) {
foreach ($detail_emails as $detail) {
if (isset($detail['email_kantor'])) {
$emails[] = $detail['email_kantor'];
}
}
}
}
return array_filter($emails);
})
->flatten()
->toArray();
$dp1 = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $id)->first();
// dd($dp1->kjpp);
foreach ($permohonan->debiture->documents as $document) {
$village_permohonan = $document->village_code;
$district_permohonan = $document->district_code;
$city_permohonan = $document->city_code;
$province_permohonan = $document->province_code;
}
$villages = Village::where('code', $village_permohonan)->get();
$districts = District::where('code', $district_permohonan)->get();
$cities = City::where('code', $city_permohonan)->get();
$provinces = Province::where('code', $province_permohonan)->get();
SendPenawaranKJPPTenderJob::dispatch(
$kjpps,
$dp1,
$penawaran,
$permohonan,
$villages,
$districts,
$cities,
$provinces
);
return redirect()->route('tender.penawaran.ulang.index')->with('success', 'Email Penawaran Berhasil Terkirim!');
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Modules\Lpj\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
use Modules\Lpj\Emails\SendPenawaranKJPPEmail;
class SendPenawaranKJPPTenderJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $kjpps;
protected $dp1; // Tidak perlu array [0] lagi
protected $penawaran;
protected $permohonan;
protected $villages;
protected $districts;
protected $cities;
protected $provinces;
/**
* Create a new job instance.
*/
public function __construct($kjpps, $dp1, $penawaran, $permohonan, $villages, $districts, $cities, $provinces)
{
$this->kjpps = $kjpps;
$this->dp1 = $dp1; // Simpan keseluruhan array dp1, bukan dp1[0]
$this->penawaran = $penawaran;
$this->permohonan = $permohonan;
$this->villages = $villages;
$this->districts = $districts;
$this->cities = $cities;
$this->provinces = $provinces;
}
/**
* Execute the job.
*/
public function handle(): void
{
$email = new SendPenawaranKJPPEmail(
$this->dp1,
$this->penawaran,
$this->permohonan,
$this->villages,
$this->districts,
$this->cities,
$this->provinces
);
$email->with([
'dp1' => $this->dp1, // Kirim seluruh array dp1 ke email
'penawaran' => $this->penawaran,
'permohonan' => $this->permohonan,
'villages' => $this->villages,
'districts' => $this->districts,
'cities' => $this->cities,
'provinces' => $this->provinces,
]);
Mail::to($this->kjpps)->send($email);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Modules\Lpj\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
use Modules\Lpj\Emails\SendPenawaranTenderEmail;
class SendPenawaranTenderJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $kjpps;
protected $penawaran;
protected $permohonan;
protected $villages;
protected $districts;
protected $cities;
protected $provinces;
/**
* Create a new job instance.
*/
public function __construct($kjpps, $penawaran, $permohonan, $villages, $districts, $cities, $provinces)
{
$this->kjpps = $kjpps;
$this->penawaran = $penawaran;
$this->permohonan = $permohonan;
$this->villages = $villages;
$this->districts = $districts;
$this->cities = $cities;
$this->provinces = $provinces;
}
/**
* Execute the job.
*/
public function handle(): void
{
$email = new SendPenawaranTenderEmail();
$email->with([
'penawaran' => $this->penawaran,
'permohonan' => $this->permohonan,
'villages' => $this->villages,
'districts' => $this->districts,
'cities' => $this->cities,
'provinces' => $this->provinces,
]);
Mail::to($this->kjpps)->send($email);
}
}

View File

@@ -2,9 +2,10 @@
namespace Modules\Lpj\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Location\Models\Province;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Modules\Lpj\Database\Factories\KJPPFactory;
@@ -19,4 +20,9 @@ class KJPP extends Model
* The attributes that are mass assignable.
*/
protected $guarded = ['id'];
public function PenawaranDetailTender(): HasMany
{
return $this->hasMany(PenawaranDetailTender::class, 'kjpp_rekanan_id', 'id');
}
}

View File

@@ -27,4 +27,9 @@ class PenawaranDetailTender extends Model
{
return $this->belongsTo(KJPP::class, 'kjpp_rekanan_id', 'id');
}
public function emailTenderLog(): BelongsTo
{
return $this->belongsTo(PenawaranEmailTenderLog::class, 'penawaran_id', 'id', PenawaranTender::class);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Modules\Lpj\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Modules\Lpj\Database\Factories\PenawaranEmailTenderLogFactory;
class PenawaranEmailTenderLog extends Model
{
use HasFactory;
protected $table = 'penawaran_email_tender_log';
/**
* The attributes that are mass assignable.
*/
protected $guarded = ['id'];
}