CasperSecurity
<?php
namespace App\Exports;
use Illuminate\Support\Facades\Http;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
class Gstr1Export implements FromCollection, WithHeadings, WithTitle
{
/**
* @return \Illuminate\Support\Collection
*/
public $response=[];
public $noofreceiptant=0;
public $noofinvoices=0;
public $totalinvoicevalue=0;
public $totaltaxablevalue=0;
public $totalcessvalue=0;
public $gsturl="api/gstr1";
public $gstarray=[];
public function headings(): array {
return [
"ti_no",
"invoice_type",
"invoice_date",
"TIAmount",
"TIgstamount",
"TInetamount",
"client_name",
"gst_no",
"service_name",
"cgst_rate",
"sgst_rate"
];
}
public function collection()
{
$url = env('CLIENT_URL') . "/" . $this->gsturl;
$response = Http::get($url, [
'invoice_sdate' => session('session_start_date'),
'invoice_edate' => session('session_end_date'),
]);
if ($response->ok()) {
$this->gstarray = $response->json()['data'];
$receiptantarr = [];
$totalinvoiceval = 0;
$totaltaxableval = 0;
foreach ($this->gstarray as $resp) {
$totalinvoiceval += $resp['TInetamount'];
$totaltaxableval += $resp['TIAmount'];
}
$this->noofinvoices = sizeof($this->gstarray);
$this->totalinvoicevalue = number_format((float)$totalinvoiceval, 2, '.', '');
$this->totaltaxablevalue = number_format((float)$totaltaxableval, 2, '.', '');
return collect($this->gstarray);
}
/*return View('exports.b2c', [
'noofinvoices' => $this->noofinvoices,
'totalinvoicevalue' => $this->totalinvoicevalue,
'totaltaxablevalue' => $this->totaltaxablevalue,
'response' => $this->response,
]);*/
}
public function title(): string
{
return 'b2c';
}
}