aggiunto bottone "Aggiorna Articolo da GM".
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
88
app/Services/ProductLogger.php
Normal file
88
app/Services/ProductLogger.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Setting;
|
||||
use App\Article;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mylog;
|
||||
|
||||
class ProductLogger
|
||||
{
|
||||
public $logs = [];
|
||||
protected $settingOra;
|
||||
|
||||
protected $aggiornato = false;
|
||||
|
||||
public function __construct($settingOraValue)
|
||||
{
|
||||
$this->settingOra = $settingOraValue;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$oraUpdate = Carbon::now();
|
||||
$this->logs['start'] = 'Inizio da ' . $this->settingOra . "\n";
|
||||
$this->logs['end'] = 'Fino a ' . $oraUpdate->toDateTimeString() . "\n";
|
||||
$this->logs['inserted'] = 'PRODOTTI INSERITI' . "\n";
|
||||
$this->logs['not_inserted'] = 'EVENTUALI PRODOTTI NON INSERITI' . "\n";
|
||||
$this->logs['updated'] = 'PRODOTTI AGGIORNATI' . "\n";
|
||||
$this->logs['server_issues'] = 'PRODOTTI NON INSERITI PER PROBLEMI SERVER' . "\n";
|
||||
$this->logs['pre_order'] = 'PRODOTTI IN PREVENDITA' . "\n";
|
||||
$this->logs['custom'] = ""; // for custom log messages
|
||||
}
|
||||
|
||||
public function updateSettingOra($newOra)
|
||||
{
|
||||
$this->settingOra = $newOra;
|
||||
}
|
||||
|
||||
public function setLogandSendEmail() {
|
||||
$ora_update = Carbon::now();
|
||||
|
||||
if ($this->settingOra) {
|
||||
$this->settingOra->value = $ora_update;
|
||||
$this->settingOra->save();
|
||||
}
|
||||
if ($this->aggiornato) {
|
||||
Log::channel('updateproducts')->notice($this->concatenateLogs());
|
||||
Mail::raw($this->concatenateLogs(), function ($message) {
|
||||
$titolo = "Inserim. nuovi prodotti";
|
||||
if (!$this->settingOra) {
|
||||
$titolo = "Inserim. prodotto:";
|
||||
}
|
||||
$message->to(Mylog::getEmail());
|
||||
$message->subject(Mylog::getSubjectEmail($titolo));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function addLog($type, $message)
|
||||
{
|
||||
if (isset($this->logs[$type])) {
|
||||
$this->logs[$type] .= $message . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function getLogs()
|
||||
{
|
||||
return $this->logs;
|
||||
}
|
||||
|
||||
public function concatenateLogs()
|
||||
{
|
||||
return implode("", $this->logs);
|
||||
}
|
||||
|
||||
public function setAggiornato($aggiornato) {
|
||||
$this->aggiornato = $aggiornato;
|
||||
}
|
||||
|
||||
public function getAggiornato() {
|
||||
return $this->aggiornato;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<input type="text" id="action" name="action" value="{{$action}}" hidden />
|
||||
<br>
|
||||
<button type="button" data-action="search">Cerca Articolo</button>
|
||||
<button type="button" data-action="updateArtFromGM">Aggiorna Articolo da GM</button>
|
||||
<button type="button" data-action="checkPrevendita">E' in PreVendita?</button>
|
||||
<button type="button" data-action="setPreOrder">Impostalo in PreVendita!</button>
|
||||
<br><br>
|
||||
|
||||
@@ -6185,6 +6185,8 @@ Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) {
|
||||
if ($action == 'search') {
|
||||
// Logica di ricerca dell'articolo
|
||||
return loadArticleByIdArticle($id);
|
||||
} elseif ($action == 'updateArtFromGM') {
|
||||
return updateArticoloFromGM($id);
|
||||
} elseif ($action == 'inprevendita') {
|
||||
return libriInPrevendita();
|
||||
} elseif ($action == 'showOrdini') {
|
||||
|
||||
Reference in New Issue
Block a user