diff --git a/app/Console/Commands/OrderReject.php b/app/Console/Commands/OrderReject.php
index 6744d16..60364e6 100644
--- a/app/Console/Commands/OrderReject.php
+++ b/app/Console/Commands/OrderReject.php
@@ -52,7 +52,7 @@ class OrderReject extends Command
}
$so->order_status = 'ORDER-REJECTED';
- $so->order_info = array_merge($so->order_info,['reason'=>$this->argument('reason')]);
+ $so->order_info = array_merge($so->order_info ? $so->order_info : [],['reason'=>$this->argument('reason')]);
$so->save();
}
}
\ No newline at end of file
diff --git a/app/Http/Controllers/AdminHomeController.php b/app/Http/Controllers/AdminHomeController.php
index ad98365..5d71308 100644
--- a/app/Http/Controllers/AdminHomeController.php
+++ b/app/Http/Controllers/AdminHomeController.php
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Mail;
-use App\Mail\OrderRequestApprove;
+use App\Mail\{OrderRequestApprove,OrderRequestReject};
use App\Models\{Service,SiteDetails};
class AdminHomeController extends Controller
@@ -34,6 +34,19 @@ class AdminHomeController extends Controller
$o->nextStatus();
break;
+ case 'reject':
+ if (! $x=$o->validStatus(strtolower($request->input('action'))))
+ return $this->service($o);
+
+ $o->order_info = array_merge($o->order_info ? $o->order_info : [],['reason'=>$request->input('notes')]);
+ $o->order_status = $x;
+ $o->save();
+
+ // Send mail to user
+ Mail::to($o->orderby->email)->queue((new OrderRequestReject($o,$request->input('notes')))->onQueue('email'));
+
+ break;
+
// No action specified.
default:
return $this->service($o);
diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php
index fb80a23..ffec4c0 100644
--- a/app/Http/Controllers/OrderController.php
+++ b/app/Http/Controllers/OrderController.php
@@ -5,9 +5,11 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Igaster\LaravelTheme\Facades\Theme;
use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\Model;
+use App\Mail\OrderRequest;
use App\Models\{Account,Product,Service};
use App\User;
@@ -115,6 +117,7 @@ class OrderController extends Controller
$options->save();
}
+ Mail::to('deon@graytech.net.au')->queue((new OrderRequest($so))->onQueue('email')); //@todo Get email from DB.
return view('order_received',['o'=>$so]);
}
}
\ No newline at end of file
diff --git a/app/Mail/OrderRequest.php b/app/Mail/OrderRequest.php
new file mode 100644
index 0000000..737cd05
--- /dev/null
+++ b/app/Mail/OrderRequest.php
@@ -0,0 +1,55 @@
+service = $o;
+ $this->notes = $notes;
+ }
+
+ /**
+ * Build the message.
+ *
+ * @return $this
+ */
+ public function build()
+ {
+ switch ($this->service->category)
+ {
+ case 'ADSL': $subject = sprintf('%s: %s',$this->service->category,$this->service->service_adsl->service_address);
+ break;
+
+ case 'VOIP': $subject = sprintf('%s: %s',$this->service->category,$this->service->service_voip->service_number);
+ break;
+
+ default:
+ $subject = 'New Order Request';
+ }
+
+ return $this
+ ->markdown('email.admin.order.approve')
+ ->subject($subject)
+ ->with(['site'=>$this->service->site]);
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Service.php b/app/Models/Service.php
index cc84b51..1ccaf7a 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -50,8 +50,13 @@ class Service extends Model
];
private $inactive_status = [
- 'CANCELLED',
+ 'CANCELLED', // @todo Check if these should be changed to ORDER-CANCELLED
'ORDER-REJECTED',
+ 'ORDER-CANCELLED',
+ ];
+
+ private $valid_status = [
+ 'ORDER-SUBMIT' => ['accept'=>'ORDER-SENT','reject'=>'ORDER-REJECTED'],
];
public function account()
@@ -159,6 +164,18 @@ class Service extends Model
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
}
+ /**
+ * This function will present the Order Info Details
+ */
+ public function getOrderInfoDetailsAttribute()
+ {
+ $result = '';
+ foreach ($this->order_info as $k=>$v)
+ $result .= sprintf('%s: %s
',ucfirst($k),$v);
+
+ return $result;
+ }
+
public function getProductNameAttribute()
{
// @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product.
@@ -238,4 +255,15 @@ class Service extends Model
default: return NULL;
}
}
+
+ /**
+ * Return if the proposed status is valid.
+ *
+ * @param string $status
+ * @return string | NULL
+ */
+ public function validStatus(string $status)
+ {
+ return array_get(array_get($this->valid_status,$this->order_status,[]),$status,NULL);
+ }
}
\ No newline at end of file
diff --git a/database/migrations/2019_01_24_142111_create_jobs_table.php b/database/migrations/2019_01_24_142111_create_jobs_table.php
new file mode 100644
index 0000000..58d7715
--- /dev/null
+++ b/database/migrations/2019_01_24_142111_create_jobs_table.php
@@ -0,0 +1,36 @@
+bigIncrements('id');
+ $table->string('queue')->index();
+ $table->longText('payload');
+ $table->unsignedTinyInteger('attempts');
+ $table->unsignedInteger('reserved_at')->nullable();
+ $table->unsignedInteger('available_at');
+ $table->unsignedInteger('created_at');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('jobs');
+ }
+}
diff --git a/resources/theme/backend/adminlte/a/service.blade.php b/resources/theme/backend/adminlte/a/service.blade.php
index b8fe3c6..cca84c0 100644
--- a/resources/theme/backend/adminlte/a/service.blade.php
+++ b/resources/theme/backend/adminlte/a/service.blade.php
@@ -14,25 +14,43 @@
@section('main-content')
Account | {{ $o->account->company }} | +
---|---|
Product | {{ $o->product->name }} | +
Last Invoice | {{ $o->date_last_invoice }} | +
Paid Until | {{ 'TBA' }} | +
Next Invoice | {{ $o->date_next_invoice }} | +
Order Details | {!! $o->order_info_details !!} | +
Save/Reject Note: | + + |