| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- 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();
- $user = $core->getUser();
- $user->requireAdmin();
- switch($type_string) {
- case "invoices":
- $title = __("Invoices");
- $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;
- case "delivery-notes":
- $title = __("Delivery Notes");
- $type = DocumentTypes::DELIVERY_NOTE;
- $singular = __("%s delivery note");
- $plural = __("%s delivery notes");
- $status_field = null;
- break;
- default:
- throw new RuntimeException(__("Invalid type string."));
- }
- $core->addBreadcrumb("/$type_string", $title);
- $type_name = DocumentTypes::enumToText($type);
- $nvp = [
- "type" => $type,
- "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);
- $pagination->setTerms($singular, $plural);
- $documents = Document::query($nvp, [
- "sort" => "id",
- "order" => "desc",
- "offset" => $pagination->getOffset(),
- "limit" => $pagination->getPageSize()
- ]);
- $core->addScript("/js/new-document-modal.js");
- View::include("header");
- 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");
|