Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
membrubackend
/
app
/
Console
/
Commands
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
RegenerateInvoiceCommand.php
| Size :
3.01
KB
Copy
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Invoice; use App\Models\Instance; use Carbon\Carbon; use Illuminate\Support\Facades\Mail; use App\Repositories\InvoiceRepository; use Str; class RegenerateInvoiceCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'command:regenerate-invoice'; /** * The console command description. * * @var string */ protected $description = 'Send invoice to clients'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $invoices = Invoice::where('series','MB')->where('id',[242,240])->get(); foreach($invoices as $invoice) { // get data from termene $cui = $invoice->cui; // remove the RO from cui, because this idiot api call won`t recognize it if( Str::contains($cui, ['ro', 'RO', 'Ro']) ){ $replace = [ 'RO'=>'', 'ro'=>'', 'RO'=>'', 'Ro'=>'', 'RO '=>'', 'ro '=>'', 'RO '=>'', 'Ro '=>'', ]; $cui = strtr( $cui, $replace ); } // get from https://termene.ro/documentatie-api some company informations $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://termene.ro/api/dateFirmaSumar.php?cui='.$cui, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => env('TERMENE_USER').':'.env('TERMENE_PASSWORD'), CURLOPT_HTTPHEADER => array( "accept: */*", "content-type: application/json", ), )); $response = curl_exec($curl); curl_close($curl); // get an array of cUrl response $response = json_decode($response, true); if(isset($response['info_companie'])){ $infoCompany = $response['info_companie']; $adresa = $infoCompany['adresa_anaf']; if($adresa){ $replace = [ 'Ş'=>'S', 'Ț'=>'T', 'Ă'=>'A', 'Â'=>'A', ]; $adresa = strtr( $adresa, $replace ); } $invoice->update([ 'nr_reg' => $infoCompany['j'] ?? null, 'address' => $adresa ?? null, 'cui' => $cui ?? null, ]); $filename = $invoice->series."-".$invoice->number.'.pdf'; $pdf = \PDF::loadView('invoices.download', compact('invoice'))->save(public_path('invoices/'.$filename)); }else{ var_dump('nu pot prelua date pentru CUI-ul: '.$cui." pentru factura cu id-ul: ".$invoice->id); } } } }
Back