|
|
@@ -6,7 +6,10 @@ namespace App;
|
|
|
* @var string $type_string
|
|
|
*/
|
|
|
|
|
|
+use App\Constraint\NotInConstraint;
|
|
|
+use App\Enums\AruStatuses;
|
|
|
use App\Enums\DocumentTypes;
|
|
|
+use App\Enums\InvoiceStatuses;
|
|
|
use RuntimeException;
|
|
|
|
|
|
$core = Core::getInstance();
|
|
|
@@ -20,18 +23,21 @@ switch($type_string) {
|
|
|
$type = DocumentTypes::INVOICE;
|
|
|
$singular = __("%s invoice");
|
|
|
$plural = __("%s invoices");
|
|
|
+ $status_field = "invoice_status";
|
|
|
break;
|
|
|
case "goods-in":
|
|
|
$title = __("Goods-In");
|
|
|
$type = DocumentTypes::GOODS_IN;
|
|
|
$singular = __("%s goods-in documents");
|
|
|
$plural = __("%s goods-in documents");
|
|
|
+ $status_field = null;
|
|
|
break;
|
|
|
case "arus":
|
|
|
$title = __("ARUs");
|
|
|
$type = DocumentTypes::ADVANCE_REPLACEMENT_UNIT;
|
|
|
$singular = __("%s ARU");
|
|
|
$plural = __("%s ARUs");
|
|
|
+ $status_field = "aru_status";
|
|
|
break;
|
|
|
default:
|
|
|
throw new RuntimeException(__("Invalid type string."));
|
|
|
@@ -46,6 +52,51 @@ $nvp = [
|
|
|
"dts_deleted" => null
|
|
|
];
|
|
|
|
|
|
+$request = Request::fromRequest();
|
|
|
+
|
|
|
+$supplier_id = $request->int("supplier_id");
|
|
|
+if($supplier_id) {
|
|
|
+ $nvp["supplier_id"] = $supplier_id;
|
|
|
+}
|
|
|
+
|
|
|
+$customer_id = $request->int("customer_id");
|
|
|
+if($customer_id) {
|
|
|
+ $customer = Customer::get($customer_id);
|
|
|
+ if($customer) {
|
|
|
+ $nvp["location_id"] = array_column($customer->getLocations(), "id");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $nvp["location_id"] = 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+$location_id = $request->int("location_id");
|
|
|
+if($location_id) {
|
|
|
+ $nvp["location_id"] = $location_id;
|
|
|
+}
|
|
|
+
|
|
|
+$status = $request->int("status");
|
|
|
+if($status !== null && $status_field) {
|
|
|
+ $nvp[$status_field] = $status;
|
|
|
+}
|
|
|
+
|
|
|
+$number = $request->int("number");
|
|
|
+if($number) {
|
|
|
+ $nvp["number"] = $number;
|
|
|
+}
|
|
|
+
|
|
|
+$custom_filter = $request->string("custom_filter");
|
|
|
+switch($custom_filter) {
|
|
|
+ case "open":
|
|
|
+ if($type === DocumentTypes::INVOICE) {
|
|
|
+ $nvp["invoice_status"] = new NotInConstraint(InvoiceStatuses::PAID, InvoiceStatuses::VOID);
|
|
|
+ }
|
|
|
+ if($type === DocumentTypes::ADVANCE_REPLACEMENT_UNIT) {
|
|
|
+ $nvp["aru_status"] = new NotInConstraint(AruStatuses::COMPLETED, AruStatuses::CANCELLED);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+}
|
|
|
+
|
|
|
$count = Document::count($nvp);
|
|
|
|
|
|
$pagination = new Pagination($count);
|
|
|
@@ -61,6 +112,6 @@ $documents = Document::query($nvp, [
|
|
|
$core->addScript("/js/new-document-modal.js");
|
|
|
|
|
|
View::include("header");
|
|
|
-View::include("documents", compact("title", "type", "documents", "pagination", "type_name"));
|
|
|
+View::include("documents", compact("title", "type_string", "type", "documents", "pagination", "type_name", "supplier_id", "customer_id", "location_id", "status", "number", "custom_filter"));
|
|
|
View::include("modals/new_document");
|
|
|
View::include("footer");
|