|
@@ -4,7 +4,10 @@ namespace App;
|
|
|
|
|
|
|
|
use App\Constraint\Constraint;
|
|
use App\Constraint\Constraint;
|
|
|
use App\Constraint\HasTextConstraint;
|
|
use App\Constraint\HasTextConstraint;
|
|
|
|
|
+use App\Constraint\MoreThanOrEqualsConstraint;
|
|
|
use App\Constraint\StartsWithConstraint;
|
|
use App\Constraint\StartsWithConstraint;
|
|
|
|
|
+use App\Enums\DocumentTypes;
|
|
|
|
|
+use Carbon\CarbonImmutable;
|
|
|
use Exception;
|
|
use Exception;
|
|
|
use RuntimeException;
|
|
use RuntimeException;
|
|
|
|
|
|
|
@@ -19,6 +22,70 @@ header("Content-Type: application/json");
|
|
|
try {
|
|
try {
|
|
|
switch($action) {
|
|
switch($action) {
|
|
|
|
|
|
|
|
|
|
+ case "get-leads-chart-data":
|
|
|
|
|
+ $dt_min = CarbonImmutable::now("Europe/London")->startOfMonth()->subMonths(12);
|
|
|
|
|
+
|
|
|
|
|
+ $labels = [];
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+
|
|
|
|
|
+ for($i = 0; $i <= 12; $i++) {
|
|
|
|
|
+ $dt = $dt_min->addMonthsNoOverflow($i);
|
|
|
|
|
+ $label = $dt->format("M y");
|
|
|
|
|
+ $labels[] = $label;
|
|
|
|
|
+ $data[$label] = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $leads = Sale::query([
|
|
|
|
|
+ "dts_created" => new MoreThanOrEqualsConstraint($dt_min->utc()),
|
|
|
|
|
+ "dts_deleted" => null
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ foreach($leads as $lead) {
|
|
|
|
|
+ $dt_created = $lead->getDateTimeCreated()->setTimezone($_ENV["TIMEZONE"]);
|
|
|
|
|
+ $label = $dt_created->format("M y");
|
|
|
|
|
+ $data[$label]++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSON::success([
|
|
|
|
|
+ "labels" => $labels,
|
|
|
|
|
+ "data" => array_values($data),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case "get-sales-orders-value-chart-data":
|
|
|
|
|
+ $dt_min = CarbonImmutable::now("Europe/London")->startOfMonth()->subMonths(12);
|
|
|
|
|
+
|
|
|
|
|
+ $labels = [];
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+
|
|
|
|
|
+ for($i = 0; $i <= 12; $i++) {
|
|
|
|
|
+ $dt = $dt_min->addMonthsNoOverflow($i);
|
|
|
|
|
+ $label = $dt->format("M y");
|
|
|
|
|
+ $labels[] = $label;
|
|
|
|
|
+ $data[$label] = "0.00";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $sales_orders = Document::query([
|
|
|
|
|
+ "type" => DocumentTypes::SALES_ORDER,
|
|
|
|
|
+ "currency" => "GBP",
|
|
|
|
|
+ "dts_created" => new MoreThanOrEqualsConstraint($dt_min->utc()),
|
|
|
|
|
+ "dts_deleted" => null
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ foreach($sales_orders as $sales_order) {
|
|
|
|
|
+ $dt_created = $sales_order->getDateTimeCreated()->setTimezone($_ENV["TIMEZONE"]);
|
|
|
|
|
+ $label = $dt_created->format("M y");
|
|
|
|
|
+ $data[$label] = bcadd($data[$label], $sales_order->getSubtotal(), 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSON::success([
|
|
|
|
|
+ "labels" => $labels,
|
|
|
|
|
+ "data" => array_values($data),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
case "suggest-sku":
|
|
case "suggest-sku":
|
|
|
$supplier_id = $request->int("supplier_id");
|
|
$supplier_id = $request->int("supplier_id");
|
|
|
$product_type = $request->int("product_type");
|
|
$product_type = $request->int("product_type");
|