{
    "module": "pipicar",
    "name": "pipicar.auto_orders",
    "type": "crud",
    "title": "Заявки",
    "withHeader": false,
    "data": {
        "table": "pipi_applications",
        "pk": "id",
        "limit": 25,
        "segment": true,
        "timestamp": false,
        "fields": {
            "id": {
                "type": "pk"
            },
            "car_id": {
                "type": "foreign",
                "table": "pipi_auto",
                "foreign": "id",
                "display": [
                    "name"
                ],
                "validation": "required|integer"
            },
            "user_id": {
                "type": "foreign",
                "table": "core_users",
                "foreign": "id",
                "display": [
                    "name"
                ],
                "validation": "required|integer"
            },
            "phone": {
                "type": "string"
            },
            "status": {
                "type": "string"
            },
            "user_name": {
                "type": "string"
            },
            "user_surname": {
                "type": "string"
            },
            "user_email": {
                "type": "string"
            },
            "started_at": {
                "type": "date",
                "validation": "required|date"
            },
            "ended_at": {
                "type": "date",
                "validation": "required|date"
            },
            "photos": {
                "type": "json",
                "validation": "nullable"
            }
        }
    },
    "ui": {
        "grid": {
            "title": "Заявки",
            "component": "App.components.Grid",
            "cols": [
                { "name": "id", "caption": "ID" },
                { "name": "car_id", "caption": "Машина" },
                { "name": "user_id", "caption": "Пользователь" },
                { "name": "phone", "caption": "Телефон" },
                { "name": "status", "caption": "Статус" },
                { "name": "user_name", "caption": "Имя" },
                { "name": "user_surname", "caption": "Фамилия" },
                { "name": "user_email", "caption": "Email" },
                { "name": "started_at", "caption": "Начало" },
                { "name": "ended_at", "caption": "Окончания" }
            ],
            "action": {
                "head": [
                    "add"
                ],
                "row": [
                    "delete"
                ]
            },
            "filter": {
                "template": "app.base.crud.filter",
                "rows": [
                    {
                        "cols": [
                            {
                                "size": 6,
                                "input": {
                                    "name": "car_id",
                                    "label": "Машина"
                                }
                            }
                        ]
                    }
                ]
            }
        },
        "forms": {
            "add": {
                "title": "Заявки",
                "template": "app.base.crud.form",
                "component": "App.components.Show",
                "form": {
                    "submits": "struct:crud.form.edit.submits",
                    "rows": [
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "car_id", "label": "Машина" } },
                                { "size": 6, "input": { "name": "user_id", "label": "Пользователь" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "phone", "label": "Телефон" } },
                                { "size": 6, "input": { "name": "status", "label": "Статус" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_name", "label": "Имя" } },
                                { "size": 6, "input": { "name": "user_surname", "label": "Фамилия" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_email", "label": "Email" } },
                                { "size": 6, "input": { "name": "started_at", "label": "Начало" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "ended_at", "label": "Окончания" } },
                                { "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
                            ]
                        }
                    ]
                }
            },
            "edit": {
                "title": "Заявки",
                "template": "app.base.crud.form",
                "component": "App.components.Show",
                "form": {
                    "rows": [
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "car_id", "label": "Машина" } },
                                { "size": 6, "input": { "name": "user_id", "label": "Пользователь" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "phone", "label": "Телефон" } },
                                { "size": 6, "input": { "name": "status", "label": "Статус" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_name", "label": "Имя" } },
                                { "size": 6, "input": { "name": "user_surname", "label": "Фамилия" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_email", "label": "Email" } },
                                { "size": 6, "input": { "name": "started_at", "label": "Начало" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "ended_at", "label": "Окончания" } },
                                { "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
                            ]
                        }
                    ],
                    "submits": [
                        "struct:crud.form.submit.save",
                        "struct:crud.form.submit.close"
                    ]
                }
            },
            "show": {
                "title": "Заявки",
                "template": "app.base.crud.form",
                "component": "App.components.Show",
                "form": {
                    "rows": [
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "car_id", "label": "Машина" } },
                                { "size": 6, "input": { "name": "user_id", "label": "Пользователь" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "phone", "label": "Телефон" } },
                                { "size": 6, "input": { "name": "status", "label": "Статус" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_name", "label": "Имя" } },
                                { "size": 6, "input": { "name": "user_surname", "label": "Фамилия" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "user_email", "label": "Email" } },
                                { "size": 6, "input": { "name": "started_at", "label": "Начало" } }
                            ]
                        },
                        {
                            "cols": [
                                { "size": 6, "input": { "name": "ended_at", "label": "Окончания" } },
                                { "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
                            ]
                        }
                    ],
                    "submits": [
                        {
                            "type": "logic",
                            "name": "App.Modules.applications.Logic.Approve",
                            "label": "Подтвердить заявку",
                            "icon": "bi bi-check",
                            "btn": "btn btn-success",
                            "condition": "status,==,pending"
                        },
                        {
                            "type": "logic",
                            "name": "App.Modules.applications.Logic.Extend",
                            "label": "Продлить аренду",
                            "icon": "bi bi-check",
                            "btn": "btn btn-success",
                            "condition": "status,==,approved"
                        },
                        {
                            "type": "logic",
                            "name": "App.Modules.applications.Logic.Cancel",
                            "label": "Отменить заявку",
                            "icon": "bi bi-check",
                            "btn": "btn btn-danger"
                        },
                        "struct:crud.form.submit.save",
                        "struct:crud.form.submit.close"
                    ]
                }
            }
        }
    },
    "actions": "struct:crud.actions"
}
