diff --git a/app/Classes/General/Eloquent/Filters/IssuerNot.php b/app/Classes/General/Eloquent/Filters/IssuerNotIn.php similarity index 74% rename from app/Classes/General/Eloquent/Filters/IssuerNot.php rename to app/Classes/General/Eloquent/Filters/IssuerNotIn.php index 77423b5d..61ca4f4c 100644 --- a/app/Classes/General/Eloquent/Filters/IssuerNot.php +++ b/app/Classes/General/Eloquent/Filters/IssuerNotIn.php @@ -4,7 +4,7 @@ namespace App\Classes\General\Eloquent\Filters; use Illuminate\Database\Eloquent\Builder; -class IssuerNot implements Filter +class IssuerNotIn implements Filter { /** @@ -14,7 +14,7 @@ class IssuerNot implements Filter */ public static function apply(Builder $builder, $value) { - return $builder->where('issuer', '!=', $value); + return $builder->whereNotIn('issuer', $value); } } \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsCustomers.php b/app/Classes/Modules/Exports/Services/ExportsCustomers.php index a397e6f5..1972935e 100644 --- a/app/Classes/Modules/Exports/Services/ExportsCustomers.php +++ b/app/Classes/Modules/Exports/Services/ExportsCustomers.php @@ -47,6 +47,8 @@ class ExportsCustomers implements FromQuery, WithHeadingRow, WithMapping return [ $company->reference, $company->name, + $company->employees()->first() ? $company->employees()->first()->name : '', + $company->contacts()->first() ? $company->contacts()->first()->phone : '', $company->type === CompanyType::COMPANY_BUSINESS ? 'Company' : 'individual', count($company->bookings), $company->bookings()->sum('fix_amount'), diff --git a/app/Console/Commands/EmailDoToVTCommand.php b/app/Console/Commands/EmailDoToVTCommand.php new file mode 100644 index 00000000..d9d463f0 --- /dev/null +++ b/app/Console/Commands/EmailDoToVTCommand.php @@ -0,0 +1,97 @@ +format('Y_m_d').'.zip'; + $attachment = storage_path().'/'.$zip_file; + $zip = new ZipArchive(); + if ($zip->open($attachment, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { + $bookings = \App\Models\Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', Carbon::yesterday()) + ->whereHas('transactions', function ($query){ + return $query->where('type', TransactionType::BILL)->where('issuer', 2); + })->get(); + + if(!$bookings){ return; } + + foreach ($bookings as $booking) { + $file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); + $zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y').'_'.$booking->marking.'.pdf'); + + } + + $zip->close(); + + Mail::raw( "Attention to VT Admin team:\r\n\r\nKindly refer to the attachment for our DAILY DO COMPILATION ".Carbon::yesterday()->format('d-m-Y').".\r\n\r\n**This is an automatically generated email – please do not reply to it. If you have any queries kindly contact our admin team through Wechat.\r\n\r\n\r\nCIEF WORLDWIDE SDN BHD", function($message) use ($attachment){ + $message->from('exchange@cief-malaysia.com'); + $message->to(['vtnation16@gmail.com', 'vtnation@gmail.com', 'atvantic04@gmail.com', 'vtnation2@gmail.com']); + $message->cc(['shafiqa_sukeri@cief-malaysia.com', 'frontendcief@gmail.com', 'pm@cief-malaysia.com', 'hasan@cief-malaysia.com', 'shipping_admin@cief-malaysia.com', 'hasanakbar27@gmail.com', 'pmwong2019@gmail.com']); + $message->subject('CIEF DO COMPILATION '.Carbon::yesterday()->format('d-m-Y')); + + $message->attach($attachment); + }); + + File::delete($attachment); + + echo 'success'; + + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 16f673e8..75c6edf1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,8 +2,15 @@ namespace App\Console; +use App\Models\User; +use Carbon\Carbon; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Storage; +use ZipArchive; class Kernel extends ConsoleKernel { @@ -23,7 +30,10 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + // $schedule->command('inspire')->hourly(); + $schedule->command('mail:EmailDoToVTCommand')->dailyAt('10:00'); + } /** diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 1793d191..18658d33 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -21,6 +21,7 @@ class TransactionResource extends JsonResource 'booking' => new BookingResource($this->booking), 'type' => (int) $this->type, 'bill_no' => $this->bill_no, + 'issuer_name' => $this->issuerCompany->name, 'recipient_bank_account' => new BankResource($this->when((int) $this->type === TransactionType::BILL,$this->booking->bank)), 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 2624117b..6a9c0282 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -26,6 +26,14 @@ class Transaction extends AbstractModel implements Documentable return $this->BelongsTo( Booking::class, 'booking_id', 'id'); } + /** + * @return BelongsTo + */ + public function issuerCompany(): BelongsTo + { + return $this->BelongsTo( Company::class, 'issuer', 'id'); + } + /** * @return BelongsTo */ diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index 6e9ea19f..6f1c723c 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -17,6 +17,14 @@ +