github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/design/schemas/progress/air.vsql (about) 1 -- Copyright (c) 2020-present unTill Pro, Ltd. 2 3 SCHEMA air; 4 5 IMPORT SCHEMA github.com/untillpro/airs-bp3/packages/untill 6 7 WORKSPACE Restaurant ( 8 9 -- Roles 10 ROLE UntillPaymentsUser; 11 ROLE LocationManager; 12 ROLE LocationUser; 13 14 15 -- Tables 16 USE TABLE untill.*; --Every workspace Restaurant has all tables from schema `untill` 17 18 -- Collection is applied to all tables with tag "sys.Collection" 19 TAG ON TAG "Backoffice" IS "sys.Collection" 20 21 --SYNONIM uarticles FOR untill.articles --later 22 23 24 ---- TO be added later: 25 ---- Misc Functions: e.g. to use in the inline CHECKS 26 ---- Arguments and return value used to work with State and Intents when calling this extension 27 FUNCTION ApproxEqual(param1 float, param2 float) RETURNS boolean ENGINE BUILTIN; 28 29 30 --- Remove procedure, declare arguments and results in CHECK, COMMAND and QUERY 31 -- CHECKS 32 VALIDATOR MyBillValidator AS ENGINE BUILTIN; -- same as MyBillValidator(sys.TableRow) 33 VALIDATOR MyFieldsValidator(fieldA text, fieldB text) AS WasmFuncName ENGINE BUILTIN; -- 34 35 CHECK ON TABLE untill.bill IS MyBillValidator; 36 CHECK ON TABLE untill.bill(name, pcname) IS MyFieldsValidator; 37 38 -- PROJECTORS 39 40 PROJECTOR FillUPProfile() AS ENGINE WASM; -- Same as FillUPProfile(sys.Event) 41 PROJECTOR FillUPProfile(sys.Event) AS WasmFuncName ENGINE WASM; 42 PROJECTOR ON EVENT WITH TAG Backoffice IS FillUPProfile; 43 PROJECTOR ON EVENT air.CreateUPProfile AS WasmFuncName ENGINE WASM; 44 PROJECTOR ON EVENT IN (air.CreateUPProfile, air.UpdateUPProfile) IS FillUPProfile; 45 46 -- COMMANDS 47 COMMAND Orders(untill.orders) AS ENGINE BUILTIN; -- Return is optional = same as RETURNS void; 48 COMMAND Pbill(untill.pbill) RETURNS PbillResult AS PbillImpl ENGINE BUILTIN; 49 COMMAND LinkDeviceToRestaurant(LinkDeviceToRestaurantParams) RETURNS void IS somepackage.MiscFunc; 50 51 -- DECLARE RATE BackofficeFuncRate AS 100 PER MINUTE PER IP; <- rejected by NNV :) 52 RATE BackofficeFuncRate AS 100 PER MINUTE PER IP; 53 Comment BackofficeDescription AS "This is a backoffice table"; 54 55 -- QUERIES 56 QUERY TransactionHistory(TransactionHistoryParams) RETURNS TransactionHistoryResult[] ENGINE WASM 57 WITH Rate=BackofficeFuncRate, Comment='Transaction History' 58 59 COMMENT ON QUERY TransactionHistory IS 'Transaction History'; 60 COMMENT ON QUERY WITH TAG Backoffice IS 'Transaction History'; 61 COMMENT ON QUERY IN (TransactionHistory, ...) IS 'Transaction History'; 62 63 RATE ON QUERY TransactionHistory IS BackofficeFuncRate; 64 RATE ON QUERY TransactionHistory AS 101 PER MINUTE PER IP; 65 66 67 QUERY QueryResellerInfo(reseller_id text) RETURNS QueryResellerInfoResult ENGINE WASM; 68 69 70 -- ACL 71 GRANT ALL ON TABLE WITH TAG untill.Backoffice TO LocationManager 72 GRANT INSERT,UPDATE ON TABLE WITH TAG sys.ODoc TO LocationUser 73 GRANT SELECT ON TABLE untill.orders TO LocationUser 74 GRANT EXECUTE ON COMMAND PBill TO LocationUser 75 GRANT EXECUTE ON COMMAND Orders TO LocationUser 76 GRANT EXECUTE ON QUERY TransactionHistory TO LocationUser 77 78 79 TYPE TransactionHistoryParams AS ( 80 BillIDs text NOT NULL, 81 EventTypes text NOT NULL, 82 ) 83 84 TYPE TransactionHistoryResult AS ( 85 Offset offset NOT NULL, 86 EventType int64 NOT NULL, 87 Event text NOT NULL, 88 ) 89 90 91 -- dashboard: hourly sales 92 VIEW HourlySalesView(yyyymmdd, hour, total, count) AS 93 SELECT 94 working_day as yyyymmdd, 95 EXTRACT(hour from ord_datetime) as hour, 96 SUM(price * quantity) as total, 97 SUM(quantity) as count 98 from untill.orders 99 join order_item on order_item.id_orders=orders.id 100 group by working_day, hour 101 WITH Key='(yyyymmdd), hour)'; 102 103 -- dashboard: daily categories 104 VIEW DailyCategoriesView(yyyymmdd PK, id_category, total) A 105 SELECT 106 working_day as yyyymmdd, 107 id_category, 108 SUM(price * quantity) as total, 109 from untill.orders 110 join order_item on order_item.id_orders = orders.id 111 join articles on id_articles = articles.id 112 join department on id_departments = articles.id_department 113 join food_group on id_food_group = department.id_food_group 114 group by working_day, id_category 115 116 TYPE LinkDeviceToRestaurantParams AS ( 117 deviceToken text not null, 118 deviceName text not null, 119 deviceProfileWSID text not null, 120 ) 121 122 123 TABLE Restaurant OF SINGLETONE ( 124 WorkStartTime text, 125 DefaultCurrency int64, 126 NextCourseTicketLayout int64, 127 TransferTicketLayout int64, 128 DisplayName text, 129 Country text, 130 City text, 131 ZipCode text, 132 Address text, 133 PhoneNumber text, 134 VATNumber text, 135 ChamberOfCommerce text, 136 ) 137 138 TYPE WriteResellerInfoParams AS ( 139 reseller_id text, 140 reseller_phone text, 141 reseller_company text, 142 reseller_email text, 143 reseller_website text 144 ) 145 146 TYPE QueryResellerInfoResult AS ( 147 reseller_phone text, 148 reseller_company text, 149 reseller_email text, 150 reseller_website text 151 ); 152 153 154 VIEW TablesOverview( 155 partitionKey int32, tableNumber int32, tablePart text, wDocID id, 156 PRIMARY KEY((partitionKey), tableno, table_part) 157 ) as select 158 2 as partitionKey, 159 tableno as tableNumber, 160 table_part as tablePart, 161 sys.ID as id 162 from untill.bill 163 164 VIEW TransactionHistory(wDocID id, offs offset, PRIMARY KEY((id), offs)) AS 165 select id, sys.Offset from untill.bill 166 union all select id_bill, sys.Offset from orders 167 union all select id_bill, sys.Offset from pbill ; 168 169 170 171 172 -- XZ Reports 173 TYPE CreateXZReportParams AS( 174 Kind int32, 175 Number int32, 176 WaiterID id, 177 from int64, 178 till int64 179 ) 180 181 VIEW XZReports( 182 Year int32, 183 Month int32, 184 Day int32, 185 Kind int32, 186 Number int32, 187 XZReportWDocID id, 188 PRIMARY KEY((Year), Month, Day, Kind, Number) 189 ) AS RESULT OF UpdateXZReportsView 190 191 192 193 ) -- WORKSPACE Restaurant 194 195 WORKSPACE Resellers { 196 197 ROLE ResellersAdmin; 198 199 WORKSPACE Reseller { 200 ROLE UntillPaymentsReseller; 201 ROLE AirReseller; 202 USE Table PaymentsProfile 203 } 204 } 205 206 TEMPLATE demo OF WORKSPACE air.Restaurant WITH SOURCE wsTemplate_demo; 207 TEMPLATE resdemo OF WORKSPACE untill.Resellers WITH SOURCE wsTemplate_demo_resellers; 208 209 210 -- ??? indexes: BillDates, OrderDates 211 -- provideQryIssueLinkDeviceToken 212 213 214 -- Subscription Query functions: 215 -- - QueryResellerInfo 216 -- - FindRestaurantSubscription 217 -- - EstimatePlan 218 -- - GetHostedPage 219 -- - UpdateSubscriptionDetails 220 -- - UpdatePaymentMethodHostedPage 221 -- - CancelSubscription 222 -- - VaidateVAT 223 -- - EstimateUpgradePlan 224 -- - QryCompleteTrialPeriod 225