/
home
/
sjslayjy
/
public_html
/
mosaram
/
app
/
Exports
/
Upload File
HOME
<?php namespace App\Exports; use Exportable; use DB; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; class RetailerLedger implements FromCollection,WithHeadings { /** * @return \Illuminate\Support\Collection */ protected $retailer_id; function __construct($retailer_id) { $this->retailer_id = $retailer_id; } public function collection() { ini_set('max_execution_time', 1000); $ledgerOpening=\DB::select('select `retailer_id`, `particular`, `type`, `credit`, `debit`, `against`, DATE_FORMAT(created_at, "%Y-%m-%d") as transaction_date from `party_invoice_ledgers` where `retailer_id` = '.$this->retailer_id.' and `particular`="opening balance" order by `created_at` asc'); $ledgerWithSeries=\DB::select('select `party_invoice_ledgers`.`retailer_id`, `party_invoice_ledgers`.`particular`, `party_invoice_ledgers`.`type`, `party_invoice_ledgers`.`credit`, `party_invoice_ledgers`.`debit`, `party_invoice_ledgers`.`against`, `bank_statements`.`transaction_date` from `party_invoice_ledgers` join `bank_statements` on `bank_statements`.`series` = `party_invoice_ledgers`.`against` and bank_statements.type=LOWER(party_invoice_ledgers.type) where `party_invoice_ledgers`.`retailer_id` = '.$this->retailer_id.' order by `bank_statements`.`transaction_date` asc'); $ledgerInvoice=\DB::select('select `retailer_id`, `particular`, `type`, `credit`, `debit`, `against`, DATE_FORMAT(created_at, "%Y-%m-%d") as transaction_date from `party_invoice_ledgers` where `retailer_id` = '.$this->retailer_id.' and `type` is null order by `created_at` asc'); $generalEntry=\DB::select('select `retailer_id`, `particular`, `type`, `credit`, `debit`, journal_series as against, `transaction_date` from `party_invoice_ledgers` where `retailer_id` = '.$this->retailer_id.' and `type` = "Journal Entry" order by `transaction_date` asc'); $CnEntry=\DB::select('select `retailer_id`, `particular`, `type`, `credit`, `debit`, cn_against as against, DATE_FORMAT(created_at, "%Y-%m-%d") as transaction_date from `party_invoice_ledgers` where `retailer_id` = '.$this->retailer_id.' and cn_against!="" order by `created_at` asc'); $secondary_discount = DB::select('select `retailer_id`, `particular`, `type`, `credit`, `debit`, `against`, `transaction_date` from `secondary_discount_party_ledgers` where `retailer_id` ='.$this->retailer_id.' order by `transaction_date` asc'); $ledgers=array_merge(array_merge($ledgerWithSeries,$ledgerInvoice,$ledgerOpening,$CnEntry),$generalEntry, $secondary_discount); array_multisort( array_column($ledgers, 'transaction_date' ), SORT_DESC,$ledgers ); return collect($ledgers); } public function headings(): array { return [ 'Retailer Id', 'Particular', 'Type', 'Credit', 'Debit', 'Against', 'Transaction Date' ]; } }