23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -6,7 +6,8 @@ use Carbon;
|
|||
use App\Models\UserAbo;
|
||||
use App\Services\AboHelper;
|
||||
|
||||
class AboRepository extends BaseRepository {
|
||||
class AboRepository extends BaseRepository
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -15,75 +16,99 @@ class AboRepository extends BaseRepository {
|
|||
}
|
||||
|
||||
|
||||
public function setModel(UserAbo $model){
|
||||
public function setModel(UserAbo $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
{
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'abo_update_settings'){
|
||||
if($this->validate($data)){
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
if ($this->validate($data)) {
|
||||
$this->updateStatus($data);
|
||||
$this->model->abo_interval = $data['abo_interval'];
|
||||
$this->model->next_date = AboHelper::setNextDate(now(), $data['abo_interval']);
|
||||
$this->model ->save();
|
||||
$this->model->save();
|
||||
\Session()->flash('alert-success', 'Einstellungen gespeichert');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
public function create($data) {}
|
||||
|
||||
}
|
||||
|
||||
private function updateStatus($data){
|
||||
private function updateStatus($data)
|
||||
{
|
||||
// Handle cancellation
|
||||
if (isset($data['abo_cancel']) && $data['abo_cancel'] == 'true') {
|
||||
// Status 4 = abo_cancel (storniert/gekündigt)
|
||||
$this->model->status = 4;
|
||||
$this->model->active = false;
|
||||
$this->model->cancel_date = now();
|
||||
$this->model->save();
|
||||
return;
|
||||
}
|
||||
|
||||
$active = (isset($data['abo_is_active']) && $data['abo_is_active']) ? true : false;
|
||||
//if status is active and active is false, set status to inactive
|
||||
if($this->model->active && !$active){
|
||||
if($this->model->status = 2){ //okay
|
||||
$this->model->status = 6; //
|
||||
if ($this->model->active && !$active) {
|
||||
if ($this->model->status == 2) { //okay
|
||||
$this->model->status = 6; //inactive
|
||||
$this->model->active = false;
|
||||
$this->model->save();
|
||||
}
|
||||
}
|
||||
if(!$this->model->active && $active){
|
||||
if($this->model->status = 6){ //inactive
|
||||
if (!$this->model->active && $active) {
|
||||
if ($this->model->status = 6) { //inactive
|
||||
$this->model->status = 2; //okay
|
||||
$this->model->active = true;
|
||||
$this->model->save();
|
||||
}
|
||||
}
|
||||
$this->model->active = $active;
|
||||
return;
|
||||
}
|
||||
|
||||
private function validate($data){
|
||||
if($data['view'] !== 'admin'){
|
||||
if($this->model->is_for === 'me' && $this->model->user_id !== \Auth::user()->id){
|
||||
private function validate($data)
|
||||
{
|
||||
if ($data['view'] !== 'admin') {
|
||||
if ($this->model->is_for === 'me' && $this->model->user_id !== \Auth::user()->id) {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
|
||||
return false;
|
||||
}
|
||||
if($this->model->is_for === 'ot' && $this->model->member_id !== \Auth::user()->id){
|
||||
if ($this->model->is_for === 'ot' && $this->model->member_id !== \Auth::user()->id) {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
|
||||
return false;
|
||||
}
|
||||
if($data['view'] === 'me' && $this->model->is_for !== 'me'){
|
||||
if ($data['view'] === 'me' && $this->model->is_for !== 'me') {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. Is not for me');
|
||||
return false;
|
||||
}
|
||||
if($data['view'] === 'ot' && $this->model->is_for !== 'ot'){
|
||||
if ($data['view'] === 'ot' && $this->model->is_for !== 'ot') {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. Is not your customer');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)){
|
||||
if (!in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)) {
|
||||
//to check if user is not admin
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Prüfung: Wenn das Abo diesen Monat noch nicht ausgeführt wurde (oder noch nie),
|
||||
// darf das Abo-Intervall nicht auf einen Tag gesetzt werden, der bereits vergangen ist (oder heute ist),
|
||||
// da setNextDate das nächste Ausführungsdatum sonst auf den nächsten Monat setzt und dieser Monat übersprungen wird.
|
||||
$executedThisMonth = $this->model->last_date && \Carbon\Carbon::parse($this->model->last_date)->isCurrentMonth();
|
||||
|
||||
if (!$executedThisMonth && $data['abo_interval'] <= now()->day) {
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval_in_the_past'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue