IMMREX7
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class DailyTransactionreport extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'dailytransactionreport:publish';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate Report for Daily Transaction in North Module.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
// Publish Scheduled homework
$today_date = \Carbon\Carbon::today()->format('Y-m-d');
$lessertransaction = DB::table('lesser_transaction')
->join('lesser_transaction_details', 'lesser_transaction.idLesserTransaction', '=', 'lesser_transaction_details.idLesserTransaction')
->join('northfeeheads', 'lesser_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('excess_transaction', 'lesser_transaction.idExcessTransaction', '=', 'excess_transaction.idExcessTransaction')
->join('students', 'lesser_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('lesser_transaction.idSchool', '=', '14')
->whereDate('lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('lesser_transaction.status');
$query->orWhere('lesser_transaction.status', '=', 'In-Process');
$query->orWhere('lesser_transaction.status', '=', 'Cleared');
$query->orWhere('lesser_transaction.status', '=', 'Success');
})
->groupBy('lesser_transaction.idStudent')
->select('lesser_transaction.idStudent', 'receiptNo', 'lesser_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(lesser_transaction_details.amountPaid) as amountPaidTotal'), DB::raw('SUM(lesser_transaction_details.discount) as discountTotal'), DB::raw('SUM(lesser_transaction.fine) as fineTotal'));
$transactions = DB::table('student_transaction')
->join('student_transaction_details', 'student_transaction.idTransaction', '=', 'student_transaction_details.idTransaction')
->join('northfeeheads', 'student_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('excess_transaction', 'student_transaction.idExcessTransaction', '=', 'excess_transaction.idExcessTransaction')
->join('students', 'student_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('student_transaction.idSchool', '=', '14')
->whereDate('student_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('student_transaction.status');
$query->orWhere('student_transaction.status', '=', 'In-Process');
$query->orWhere('student_transaction.status', '=', 'Cleared');
$query->orWhere('student_transaction.status', '=', 'Success');
})
->union($lessertransaction)
->groupBy('student_transaction.idStudent')
->select('student_transaction.idStudent', 'receiptNo', 'student_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(student_transaction_details.amountPaid) AS amountPaidTotal'), DB::raw('SUM(student_transaction_details.discount) as discountTotal'), DB::raw('SUM(student_transaction.fine) as fineTotal'))->get();
$lesserpaid_feehead = DB::table('lesser_transaction')
->join('lesser_transaction_details', 'lesser_transaction.idLesserTransaction', '=', 'lesser_transaction_details.idLesserTransaction')
->join('northfeeheads', 'lesser_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('excess_transaction', 'lesser_transaction.idExcessTransaction', '=', 'excess_transaction.idExcessTransaction')
->where('lesser_transaction.idSchool', '=', '14')
->whereDate('lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('lesser_transaction.status');
$query->orWhere('lesser_transaction.status', '=', 'In-Process');
$query->orWhere('lesser_transaction.status', '=', 'Cleared');
$query->orWhere('lesser_transaction.status', '=', 'Success');
})
->select('headerName', 'northfeeheads.ecNo', 'lesser_transaction_details.idFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead');
$feeheads = DB::table('student_transaction')
->join('student_transaction_details', 'student_transaction.idTransaction', '=', 'student_transaction_details.idTransaction')
->join('northfeeheads', 'student_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('excess_transaction', 'student_transaction.idExcessTransaction', '=', 'excess_transaction.idExcessTransaction')
->where('student_transaction.idSchool', '=', '14')
->whereDate('student_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('student_transaction.status');
$query->orWhere('student_transaction.status', '=', 'In-Process');
$query->orWhere('student_transaction.status', '=', 'Cleared');
$query->orWhere('student_transaction.status', '=', 'Success');
})
->union($lesserpaid_feehead)
->select('headerName', 'northfeeheads.ecNo', 'student_transaction_details.idFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead')
->get();
foreach ($transactions as $var) {
if ($var->ecNo != null) {
$daily_transaction = new \App\DailyTransaction();
$daily_transaction->idSchool = '14';
$daily_transaction->transactionType = 'Student';
$daily_transaction->ecNo = $var->ecNo;
$daily_transaction->Name = $var->firstName . ' ' . $var->middleName . ' ' . $var->lastName;
$daily_transaction->class = $var->className;
$daily_transaction->section = $var->sectionName;
$daily_transaction->totalFine = $var->fineTotal;
$daily_transaction->totalDiscount = $var->discountTotal;
$daily_transaction->totalfeePaid = $var->amountPaidTotal;
$daily_transaction->totalFine = $var->fineTotal;
$net = $var->amountPaidTotal + $var->discountTotal + $var->fineTotal;
$daily_transaction->netAmount = $net;
$daily_transaction->paymentDate = $var->paymentDate;
$daily_transaction->receiptNo = $var->receiptNo;
$daily_transaction->save();
}
}
foreach ($feeheads as $fh) {
if ($fh->ecNo != null) {
$dt = \App\DailyTransaction::where('ecNo', '=', $fh->ecNo)
->where('transactionType', '=', 'Student')
->where('paymentDate', '=', $today_date)->first();
$dt_detail = new \App\DailyTransactionDetail();
$dt_detail->idDailyTransaction = $dt->idDailyTransaction;
$dt_detail->idFeehead = $fh->idFeehead;
$dt_detail->headerName = $fh->headerName;
$dt_detail->amountPaid = $fh->amountPaid;
$dt_detail->discountFeehead = $fh->discountFeehead;
$dt_detail->save();
}
}
// Normal Student Fee end
// Hostel Fee Start
$hostellessertransaction = DB::table('hostel_lesser_transaction')
->join('hostel_lesser_transaction_details', 'hostel_lesser_transaction.idHostelLesserTransaction', '=', 'hostel_lesser_transaction_details.idHostelLesserTransaction')
->join('northfeeheads', 'hostel_lesser_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
// ->leftJoin('excess_transaction', 'lesser_transaction.idExcessTransaction', '=', 'excess_transaction.idExcessTransaction')
->join('students', 'hostel_lesser_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('hostel_lesser_transaction.idSchool', '=', '14')
->whereDate('hostel_lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('hostel_lesser_transaction.status');
$query->orWhere('hostel_lesser_transaction.status', '=', 'In-Process');
$query->orWhere('hostel_lesser_transaction.status', '=', 'Cleared');
$query->orWhere('hostel_lesser_transaction.status', '=', 'Success');
})
->groupBy('hostel_lesser_transaction.idStudent')
->select('hostel_lesser_transaction.idStudent', 'receiptNo', 'hostel_lesser_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(hostel_lesser_transaction_details.amountPaid) as amountPaidTotal'), DB::raw('SUM(hostel_lesser_transaction_details.discount) as discountTotal'), DB::raw('SUM(hostel_lesser_transaction.fine) as fineTotal'));
$hosteltransactions = DB::table('hostel_transaction')
->join('hostel_transaction_details', 'hostel_transaction.idHostelTransaction', '=', 'hostel_transaction_details.idHostelTransaction')
->join('northfeeheads', 'hostel_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
// ->leftJoin('hostel_excess_transaction', 'hostel_transaction.idHostelExcessTransaction', '=', 'hostel_excess_transaction.idHostelExcessTransaction')
->join('students', 'hostel_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('hostel_transaction.idSchool', '=', '14')
->whereDate('hostel_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('hostel_transaction.status');
$query->orWhere('hostel_transaction.status', '=', 'In-Process');
$query->orWhere('hostel_transaction.status', '=', 'Cleared');
$query->orWhere('hostel_transaction.status', '=', 'Success');
})
->union($hostellessertransaction)
->groupBy('hostel_transaction.idStudent')
->select('hostel_transaction.idStudent', 'receiptNo', 'hostel_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(hostel_transaction_details.amountPaid) AS amountPaidTotal'), DB::raw('SUM(hostel_transaction_details.discount) as discountTotal'), DB::raw('SUM(hostel_transaction.fine) as fineTotal'))->get();
//dd($transaction);
$hostellesserpaid_feehead = DB::table('hostel_lesser_transaction')
->join('hostel_lesser_transaction_details', 'hostel_lesser_transaction.idHostelLesserTransaction', '=', 'hostel_lesser_transaction_details.idHostelLesserTransaction')
->join('northfeeheads', 'hostel_lesser_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
// ->leftJoin('hostel_excess_transaction', 'hostel_lesser_transaction.idHostelExcessTransaction', '=', 'hostel_excess_transaction.idHostelExcessTransaction')
->where('hostel_lesser_transaction.idSchool', '=', '14')
->whereDate('hostel_lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('hostel_lesser_transaction.status');
$query->orWhere('hostel_lesser_transaction.status', '=', 'In-Process');
$query->orWhere('hostel_lesser_transaction.status', '=', 'Cleared');
$query->orWhere('hostel_lesser_transaction.status', '=', 'Success');
})
->select('headerName', 'northfeeheads.ecNo', 'hostel_lesser_transaction_details.idFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead');
$hostelfeeheads = DB::table('hostel_transaction')
->join('hostel_transaction_details', 'hostel_transaction.idHostelTransaction', '=', 'hostel_transaction_details.idHostelTransaction')
->join('northfeeheads', 'hostel_transaction_details.idFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
// ->leftJoin('hostel_excess_transaction', 'hostel_transaction.idHostelExcessTransaction', '=', 'hostel_excess_transaction.idHostelExcessTransaction')
->where('hostel_transaction.idSchool', '=', '14')
->whereDate('hostel_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('hostel_transaction.status');
$query->orWhere('hostel_transaction.status', '=', 'In-Process');
$query->orWhere('hostel_transaction.status', '=', 'Cleared');
$query->orWhere('hostel_transaction.status', '=', 'Success');
})
->union($hostellesserpaid_feehead)
->select('headerName', 'northfeeheads.ecNo', 'hostel_transaction_details.idFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead')
->get();
foreach ($hosteltransactions as $var) {
if ($var->ecNo != null) {
$daily_transaction = new \App\DailyTransaction();
$daily_transaction->idSchool = '14';
$daily_transaction->transactionType = 'Hostel';
$daily_transaction->ecNo = $var->ecNo;
$daily_transaction->Name = $var->firstName . ' ' . $var->middleName . ' ' . $var->lastName;
$daily_transaction->class = $var->className;
$daily_transaction->section = $var->sectionName;
$daily_transaction->totalFine = $var->fineTotal;
$daily_transaction->totalDiscount = $var->discountTotal;
$daily_transaction->totalfeePaid = $var->amountPaidTotal;
$daily_transaction->totalFine = $var->fineTotal;
$net = $var->amountPaidTotal + $var->discountTotal + $var->fineTotal;
$daily_transaction->netAmount = $net;
$daily_transaction->paymentDate = $var->paymentDate;
$daily_transaction->receiptNo = $var->receiptNo;
$daily_transaction->save();
}
}
foreach ($hostelfeeheads as $fh) {
if ($fh->ecNo != null) {
$dt = \App\DailyTransaction::where('ecNo', '=', $fh->ecNo)
->where('transactionType', '=', 'Hostel')
->where('paymentDate', '=', $today_date)->first();
$dt_detail = new \App\DailyTransactionDetail();
$dt_detail->idDailyTransaction = $dt->idDailyTransaction;
$dt_detail->idFeehead = $fh->idFeehead;
$dt_detail->headerName = $fh->headerName;
$dt_detail->amountPaid = $fh->amountPaid;
$dt_detail->discountFeehead = $fh->discountFeehead;
$dt_detail->save();
}
}
// Hoste fee ENd
// Bus Fee Statt
$buslessertransaction = DB::table('bus_lesser_transaction')
->join('bus_lesser_transaction_details', 'bus_lesser_transaction.idBusLesserTransaction', '=', 'bus_lesser_transaction_details.idBusLesserTransaction')
->join('northfeeheads', 'bus_lesser_transaction_details.idBusFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('bus_excess_transaction', 'bus_lesser_transaction.idBusExcessTransaction', '=', 'bus_excess_transaction.idBusExcessTransaction')
->join('students', 'bus_lesser_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('bus_lesser_transaction.idSchool', '=', '14')
->whereDate('bus_lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('bus_lesser_transaction.status');
$query->orWhere('bus_lesser_transaction.status', '=', 'In-Process');
$query->orWhere('bus_lesser_transaction.status', '=', 'Cleared');
$query->orWhere('bus_lesser_transaction.status', '=', 'Success');
})
->groupBy('bus_lesser_transaction.idStudent')
->select('bus_lesser_transaction.idStudent', 'receiptNo', 'bus_lesser_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(bus_lesser_transaction_details.amountPaid) as amountPaidTotal'), DB::raw('SUM(bus_lesser_transaction_details.discount) as discountTotal'), DB::raw('SUM(bus_lesser_transaction.fine) as fineTotal'));
$bustransactions = DB::table('bus_transaction')
->join('bus_transaction_details', 'bus_transaction.idBusTransaction', '=', 'bus_transaction_details.idBusTransaction')
->join('northfeeheads', 'bus_transaction_details.idBusFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('bus_excess_transaction', 'bus_transaction.idBusExcessTransaction', '=', 'bus_excess_transaction.idBusExcessTransaction')
->join('students', 'bus_transaction.idStudent', '=', 'students.idStudent')
->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')
->where('bus_transaction.idSchool', '=', '14')
->whereDate('bus_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('bus_transaction.status');
$query->orWhere('bus_transaction.status', '=', 'In-Process');
$query->orWhere('bus_transaction.status', '=', 'Cleared');
$query->orWhere('bus_transaction.status', '=', 'Success');
})
->union($buslessertransaction)
->groupBy('bus_transaction.idStudent')
->select('bus_transaction.idStudent', 'receiptNo', 'bus_transaction.paymentDate', 'students.ecNo', 'firstName', 'middleName', 'lastName', 'className', 'sectionName', 'paymentMode', DB::raw('SUM(bus_transaction_details.amountPaid) AS amountPaidTotal'), DB::raw('SUM(bus_transaction_details.discount) as discountTotal'), DB::raw('SUM(bus_transaction.fine) as fineTotal'))->get();
$buslesserpaid_feehead = DB::table('bus_lesser_transaction')
->join('bus_lesser_transaction_details', 'bus_lesser_transaction.idBusLesserTransaction', '=', 'bus_lesser_transaction_details.idBusLesserTransaction')
->join('northfeeheads', 'bus_lesser_transaction_details.idBusFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('bus_excess_transaction', 'bus_lesser_transaction.idBusExcessTransaction', '=', 'bus_excess_transaction.idBusExcessTransaction')
->where('bus_lesser_transaction.idSchool', '=', '14')
->whereDate('bus_lesser_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('bus_lesser_transaction.status');
$query->orWhere('bus_lesser_transaction.status', '=', 'In-Process');
$query->orWhere('bus_lesser_transaction.status', '=', 'Cleared');
$query->orWhere('bus_lesser_transaction.status', '=', 'Success');
})
->select('headerName', 'northfeeheads.ecNo', 'bus_lesser_transaction_details.idBusFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead');
$busfeeheads = DB::table('bus_transaction')
->join('bus_transaction_details', 'bus_transaction.idBusTransaction', '=', 'bus_transaction_details.idBusTransaction')
->join('northfeeheads', 'bus_transaction_details.idBusFeehead', '=', 'northfeeheads.idFeehead')
->join('headers', 'northfeeheads.idHeader', '=', 'headers.idHeader')
->leftJoin('bus_excess_transaction', 'bus_transaction.idBusExcessTransaction', '=', 'bus_excess_transaction.idBusExcessTransaction')
->where('bus_transaction.idSchool', '=', '14')
->whereDate('bus_transaction.paymentDate', '=', $today_date)
->where(function($query) {
$query->whereNull('bus_transaction.status');
$query->orWhere('bus_transaction.status', '=', 'In-Process');
$query->orWhere('bus_transaction.status', '=', 'Cleared');
$query->orWhere('bus_transaction.status', '=', 'Success');
})
->union($buslesserpaid_feehead)
->select('headerName', 'northfeeheads.ecNo', 'bus_transaction_details.idBusFeehead', 'amountPaid', 'northfeeheads.discount as discountFeehead')
->get();
foreach ($bustransactions as $var) {
if ($var->ecNo != null) {
$daily_transaction = new \App\DailyTransaction();
$daily_transaction->idSchool = '14';
$daily_transaction->transactionType = 'Bus';
$daily_transaction->ecNo = $var->ecNo;
$daily_transaction->Name = $var->firstName . ' ' . $var->middleName . ' ' . $var->lastName;
$daily_transaction->class = $var->className;
$daily_transaction->section = $var->sectionName;
$daily_transaction->totalFine = $var->fineTotal;
$daily_transaction->totalDiscount = $var->discountTotal;
$daily_transaction->totalfeePaid = $var->amountPaidTotal;
$daily_transaction->totalFine = $var->fineTotal;
$net = $var->amountPaidTotal + $var->discountTotal + $var->fineTotal;
$daily_transaction->netAmount = $net;
$daily_transaction->paymentDate = $var->paymentDate;
$daily_transaction->receiptNo = $var->receiptNo;
$daily_transaction->save();
}
}
foreach ($busfeeheads as $fh) {
if ($fh->ecNo != null) {
$dt = \App\DailyTransaction::where('ecNo', '=', $fh->ecNo)
->where('transactionType', '=', 'Bus')
->where('paymentDate', '=', $today_date)->first();
$dt_detail = new \App\DailyTransactionDetail();
$dt_detail->idDailyTransaction = $dt->idDailyTransaction;
$dt_detail->idFeehead = $fh->idBusFeehead;
$dt_detail->headerName = $fh->headerName;
$dt_detail->amountPaid = $fh->amountPaid;
$dt_detail->discountFeehead = $fh->discountFeehead;
$dt_detail->save();
}
}
// BUS FEE END
$this->info('Data Published successfully!');
}
}
Copyright © 2021 -