diff --git a/analyses/company_latest_order_datetime.sql b/analyses/company_latest_order_datetime.sql new file mode 100644 index 0000000..c1e0767 --- /dev/null +++ b/analyses/company_latest_order_datetime.sql @@ -0,0 +1,7 @@ +-- IMPORT +WITH company_list AS ( + SELECT * FROM {{ ref('rep_exchange__company_lists') }} +) + +SELECT * FROM company_list WHERE LAST_ORDER_DATETIME is not null and company_id IN (2881, 1925, 508, 1753, 3001, 1980, 1108, 2501, 3522, 369, 995, 766, 559, 1043, 3775, 3998, 3199, 3032, 57, 58, 868, 2428, 3499, 2102, 2591, 519, 3002, 1697, 2688, 1944, 1687, 1686, 2736, 3655, 892, 795, 3355, 3126, 93, 2074, 2124, 2090, 2644, 1015, 3623, 3772, 155, 330, 1826, 1636, 1758, 968, 2262, 2944, 1444, 1707, 1540, 121, 123, 1102, 1975, 3115, 3222, 2987, 2574, 2325, 2323, 824, 568, 2164, 2163, 2165, 2185, 2228, 2327, 1970, 1937, 1082, 2833, 2072, 2084, 2219, 3819, 141, 1884, 1565, 1150, 3081, 3088, 381, 422, 429, 1633, 1093, 577, 1883, 4000, 816, 627, 1413, 3824, 63, 1954, 2657, 2402, 1569, 3562, 1987, 2747, 2513, 2266, 1989, 90, 3062, 2161, 3152, 731, 2136, 2116, 3347, 3346, 2, 1921, 2261, 2357, 2344, 2351, 3249, 3779, 2299, 3843, 1861, 1862, 2508, 2857, 498, 193, 379, 3892, 315, 272, 2222, 45, 853, 353, 1620, 1731, 2436, 4031, 1450, 1451, 1182, 1621, 3740, 3739, 3417, 1536, 228, 400, 99, 718, 762, 2740, 2274, 2273, 3393, 2075, 3448, 3173, 3794, 3913, 1445, 52, 395, 1358, 259, 1397, 1265, 1457, 2010, 647, 2909, 2859, 2730, 225, 206, 479, 1097, 2401, 2342, 3383, 2842, 2896, 2816, 2815, 2220, 2862, 1527, 1200, 3372, 3380, 1049, 1046, 2217, 3826, 2761, 1151, 2897, 812, 1652, 1517, 3664, 3435, 2291, 2918, 3711, 3712, 360, 803, 2926, 2927, 1995, 1428, 3821, 1259, 3668, 2956, 3815, 2729, 3462, 2480, 3908, 257, 318, 2410, 2409, 1748, 1365, 386, 332, 2796, 2795, 1751, 1845, 1929, 1920, 12, 261, 725, 1553, 3467, 765, 231, 3988, 2910, 2702, 2935, 2989, 347, 1594, 1474, 2191, 2708, 439, 686, 2937, 3640, 377, 3629, 1788, 3667, 700, 2494, 3872, 2810, 3073, 14, 350, 1534, 3271, 1231, 3253, 173, 2415, 3230, 2439, 1245, 1710, 708, 2866, 7, 2797, 3154, 2483, 3341, 2193, 2223, 3603, 785, 1218, 2061, 2620, 750, 2244, 767, 794, 390, 1250, 1878, 2966, 2766, 3178, 3833, 2560, 1880, 1999, 514, 1681, 1639, 3104, 2206, 2828, 1328, 4009, 2908, 2229, 2313, 2441, 1222, 2328, 2704, 3228, 2059, 494, 1865, 2594, 3303, 1634, 406, 2879, 3840, 3048, 2608, 1130, 480, 372, 846, 229, 3440, 2068, 1455, 1501, 680, 2991, 1000, 477, 3652, 297, 274, 2595, 1242, 1303, 1036, 3676, 1207, 2939, 102, 3225, 636, 3870, 3274, 1700, 1766, 4011, 3855, 2296, 3508, 3783, 757, 436, 2281, 3441, 1247, 2719, 364, 3914, 841, 3989, 1178, 2898, 3925, 690, 190, 3609, 634, 2322, 2805, 143, 845, 2353, 3384, 2636, 3918, 2749, 1719, 2487, 1213, 2709, 652, 2690, 1743, 3559, 691, 3431, 2302, 1349, 2827, 1195, 2848, 629, 927, 1040, 2213, 1563, 2515, 2660, 2901, 3357, 1961, 2539, 3585, 3176, 986, 1972, 1514, 3557, 3526, 728, 1481, 2757, 2258, 2333, 1988, 4046, 2631, 2106, 727, 3859, 1909, 2672, 3773, 3926, 673, 2293, 2887, 683, 3808, 934, 1814, 761, 296, 3639, 3786, 311, 1835, 1998, 1934, 3852, 1997, 1197, 2049, 810, 2111, 3742, 2759, 3579, 4061, 2843, 726, 3207, 3799, 1691, 1403, 1206, 2408, 1357, 2899, 1873, 758, 909, 1409, 1289, 3974, 1486, 2279, 3010, 787, 3787, 4060, 246, 3298, 3803, 1769, 3057, 313, 542, 108, 3471, 3099, 2264, 1734, 2741, 2930, 2532, 2504, 3007, 3135, 2853, 924, 3604, 162, 802, 1586, 2592, 2700, 570, 3033, 2900, 82, 1219, 1346, 89, 618, 939, 546, 1606, 2183, 1080, 540, 233, 890, 3130, 3120, 1663, 1251, 900, 3798, 1555, 3304, 869, 3577, 532, 956, 898, 3005, 590, 1273, 497, 574, 984, 457, 712, 3661, 3184, 951, 1426, 317, 1596, 3631, 1795, 1775, 2576, 3939, 3360, 1435, 2324, 2755, 1063, 1607, 2839, 2153, 5, 23, 2964, 1774, 600, 1885, 3730, 1408, 51, 3897, 973, 1981, 548, 3091, 320, 1363, 2825, 2001, 1359, 2468, 3790, 10, 2044, 399, 2485, 1367, 1798, 2416, 2419, 2042, 946, 2949, 1188, 28, 3751, 3724, 3984, 2196, 887, 2544, 1871, 349, 2525, 3767, 1041, 2607, 699, 1239, 1810, 3315, 2507, 1492, 1648, 3858, 791, 1887, 3193, 393, 1117, 1656, 67, 527, 2606, 111, 2199, 3896, 146, 2640, 645, 3683, 130, 867, 2007, 1453, 2320, 1677, 642, 1828, 2961, 2251, 667, 693, 805, 1535, 3021, 1469, 1354, 799, 1567, 3229, 1882, 1846, 2472, 1431, 438, 1164, 716, 2571, 4040, 312, 3545, 1069, 1982, 3268, 499, 3547, 2352, 1320, 3568, 1037, 2718, 3166, 2131, 2371, 3830, 2238, 1911, 3111, 1280, 3634, 2381, 3605, 222, 778, 1877, 1378, 3613, 359, 1181, 178, 2086, 3505, 175, 3797, 2812, 2347, 610, 825, 3373, 2585, 404, 1274, 3632, 954, 3915, 2656, 1216, 3375, 2912, 1165, 1737, 2470, 3992, 1905, 1014, 3473, 749, 461, 1901, 1940, 2850, 3412, 1443, 1827, 1034, 2943, 1556, 3128, 706, 2417, 2790, 3717, 3943, 2234, 3374, 1106, 1042, 1468, 2981, 2027, 721, 142, 2400, 807, 2629, 3599, 3721, 4016, 2870, 774, 151, 3094, 3800, 158, 3625, 176, 3947, 1373, 54, 2902, 419, 1867, 777, 1740, 4026, 1461, 3211, 2807, 2175, 2580, 1593, 1544, 2113, 830, 2750, 3050, 321, 448, 3820, 1595, 4, 3969, 1784, 223, 786, 3965, 2230, 3313, 692, 971, 1083, 1709, 3153, 1587, 94, 1794, 374, 3269, 1299, 140, 895, 2994, 3777, 2017, 2283, 2780, 1613, 2318, 3340, 2616, 1382, 2403, 3708, 482, 3979, 1655, 1963, 2817, 623, 2794, 3727, 1756, 3936, 3571, 2225, 888, 4053, 2298, 3086, 3293, 389, 843, 3491, 2171, 2698, 1145, 3309, 3768, 1246, 476, 1968, 282, 788, 1967, 380, 3318, 336, 2732, 1241, 1723, 1088, 3123, 447, 3083, 2936, 3825, 740, 2602, 87, 3862, 516, 3449, 3909, 283, 2921, 2391, 2564, 319, 1420, 1739, 626, 1598, 1511, 2569, 2685, 1941, 116, 1834, 84, 737, 1777, 1780, 2015, 1741, 2512, 3202, 1377, 2742, 639, 174, 122, 2247, 3421, 3454, 1904, 3954, 3414, 1308, 783, 1983, 3792, 2706, 940, 974, 4062, 3317, 2974, 3818, 3489, 2477, 3760, 167, 3704, 3332, 407, 3973, 3567, 902, 3733, 870, 1374, 75, 2365, 3238, 3645, 1849, 3630, 732, 3272, 1928, 2304, 3429, 3179, 3755, 1472, 1345, 976, 1790, 1386, 522, 3666, 2705, 3731, 2990, 137, 784, 2721, 2227, 3276, 3432, 3492, 1510, 474, 1201, 2295, 1646, 1268, 3504, 38, 2771, 2883, 2071, 2375, 2744, 1141, 3463, 247, 3216, 3031, 2490, 3387, 1494, 2852, 1509, 3841, 46, 2950, 2379, 3354, 661, 3513, 42, 1155, 3391, 1570, 1417, 903, 371, 3479, 1429, 2946, 1115, 2373, 3070, 679, 877, 1984, 210, 3910, 738, 3646, 703, 2960, 1860, 1103, 1785, 1105, 129, 3838, 3174, 1832, 2754, 2875, 3511, 2056, 191, 2891, 3680, 410, 595, 361, 3139, 2012, 2587, 2150, 2028, 1462, 2645, 3754, 911, 599, 564, 1808, 2119, 2542, 3270, 2687, 2138, 2359, 1050, 2305, 2743, 1135, 544, 580, 188, 2387, 1530, 3663, 2259, 1112, 604, 1160, 2276, 3764, 905, 1939, 678, 2613, 1138, 1935, 2601, 2384, 3061, 338, 3026, 2348, 109, 2338, 1356, 3426, 733, 1340, 526, 1811, 2200, 998, 2970, 3765, 1243, 2630, 204, 3887, 1573, 1708, 2037, 2022, 3142, 3013, 1372, 523, 2142, 1436, 3469, 3759, 1111, 3204, 3817, 1100, 1957, 2818, 2254, 2819, 49, 342, 2032, 594, 616, 3970, 3917, 1659, 1449, 2577, 1837, 431, 2147, 2004, 1122, 3400, 333, 186, 2340, 3701, 3170, 932, 709, 2354, 2233, 801, 501, 292, 1238, 434, 3224, 571, 3079, 662, 923, 2166, 1818, 3709, 1353, 2715, 3022, 213, 613, 3827, 1572, 3823, 828, 3697, 2031, 1841, 584, 3515, 3297, 653, 2386, 307, 3219, 2959, 804, 2143, 2108, 3793, 3723, 1459, 2457, 1742, 3443, 1338, 189, 1547, 3990, 3482, 2529, 2533, 306, 3985, 2489, 4037, 30, 782, 463, 284, 3292, 2073, 1087, 152, 3844, 3867, 2717, 3743, 43, 169, 1888, 1666, 674, 1314, 1866, 1622, 2290, 2317, 3495, 3550, 237, 3685, 2154, 837, 817, 2520, 1185, 1167, 3636, 668, 1085, 1592, 3953, 1583, 3386, 3660, 1619, 1912, 3148, 2872, 1260, 2112, 3556, 4047, 1626, 471, 1061, 3796, 1716, 1582, 894, 994, 602, 1495, 1732, 697, 423, 1442, 3594, 2455, 1512, 3714, 2067, 2619, 1323, 1869, 1380, 1334, 441, 2621, 3077, 3024, 3809, 3657, 165, 3732, 3390, 2169, 3177, 3911, 842, 2355, 1341, 1585, 62, 779, 2779, 3921, 1568, 3338, 1714, 878, 1653, 3804, 215, 3878, 2040, 2412, 2066, 3227, 2103, 2467, 588, 1057, 3537, 3986, 3326, 2226, 698, 593, 403, 3619, 3912, 3490, 2893, 416, 154, 196, 1473, 505, 582, 3359, 3593, 1623, 3210, 3507, 575, 1503, 1796, 1441, 3085, 1030, 2941, 2497, 3284, 1971, 265, 3856, 2125, 3553, 3893, 3196, 3861, 65, 2785, 3590, 2962, 405, 1084, 1286, 3829, 481, 2668, 424, 2600, 2762, 2155, 3938, 2570, 114, 3874, 1166, 3342, 2638, 1388, 2205, 3509, 3611, 3900, 3607, 3884, 1376, 798, 957, 1945, 3662, 484, 3620, 3363, 3331, 3763, 3890, 2931, 29, 2563, 3236, 2547, 1098, 305, 1643, 3501, 2803, 3251, 2791, 1580, 545, 2041, 1005, 3483, 2336, 1825, 1823, 854, 3977, 1610, 2847, 1902, 3433, 2011, 1778, 2179, 3415, 858, 2673, 1282, 1144, 3183, 2414, 1476, 827, 2622, 2980, 1464, 2821, 397, 1931, 156, 1368, 219, 1960, 1159, 978, 1985, 2748, 3922, 2120, 1855, 579, 3156, 2813, 589, 2694, 866, 2052, 1330, 3286, 1870, 4038, 3076, 1706, 675, 1205, 3281, 1312, 1986, 3046, 1394, 1290, 275, 992, 2275, 2775, 487, 1463, 2965, 2696, 1903, 2894, 3003, 3617, 157, 2123, 3461, 1850, 493, 2788, 1440, 401, 462, 2349, 1402, 2356, 2181, 3296, 1726, 33, 3335, 1863, 960, 2558, 2418, 694, 197, 844, 3839, 3883, 64, 2363, 3113, 3637, 3916, 1321, 450, 635, 551, 1725, 2202, 2772, 2292, 1651, 722, 4005, 913, 3706, 2734, 1574, 592, 3518, 2421, 2915, 1497, 3209, 4004, 1313, 4045, 1230, 3401, 3966, 2297, 1548, 335, 1722, 264, 1430, 1311, 1149, 1192, 467, 1099, 949, 2886, 3283, 2451, 1258, 1226, 2832, 1161, 4055, 2823, 1950, 822, 3957, 2562, 1840, 34, 919, 356, 125, 1813, 2841, 279, 1676, 4064, 2422, 1852, 2712, 1434, 1792, 3997, 442, 1820, 3455, 943, 3337, 1857, 98, 2845, 1479, 3133, 1255, 2612, 2789, 3722, 1561, 2733, 3060, 1285, 4029, 975, 92, 1039, 739, 71, 536, 1628, 2278, 2597, 127, 2890, 132, 2242, 3181, 1418, 1603, 2658, 1713, 2054, 1879, 3521, 1577, 2047, 2121, 3962, 1727, 2919, 3320, 3500, 1650, 195, 3464, 3478, 2404, 1747, 226, 3215, 2920, 646, 3358, 3307, 3999, 2239, 3451, 576, 2804, 2725, 1288, 2268, 3248, 1269, 341, 3570, 299, 2087, 1121, 1493, 1256, 3600, 3822, 1927, 2838, 3738, 3011, 3356, 2127, 2246, 3616, 3930, 2710, 2479, 3168, 2286, 192, 3053, 3042, 1955, 2232, 1067, 1119, 1669, 539, 3514, 2392, 316, 466, 3376, 2509, 2590, 3325, 2988, 1062, 500, 72, 2308, 2114, 300, 1702, 2427, 258, 3259, 2198, 2623, 2826, 2916, 4030, 2554, 383, 3212, 3187, 953, 3533, 950, 2474, 2837, 1220, 3871, 1936, 375, 2393, 4056, 2454, 1337, 168, 1807, 2763, 3381, 509, 3776, 1735, 256, 1447, 3078, 1919, 3242, 1066, 3995, 3710, 2865, 840, 1163, 3397, 901, 2405, 3770, 1705, 2329, 150, 1215, 3071, 1465, 3805, 955, 2802, 3241, 3409, 2984, 2343, 3749, 3934, 2107, 1836, 554, 1793, 2492, 981, 3651, 2716, 3388, 3528, 1157, 2453, 834, 2250, 3246, 1642, 3252, 444, 746, 1008, 861, 3675, 2506, 3488, 1460, 13, 2300, 214, 70, 1375, 3563, 1806, 745, 648, 2913, 3172, 2869, 468, 1031, 1170, 1225, 1518, 2443, 899, 3487, 242, 243, 2697, 503, 3814, 3539, 3940, 1876, 3004, 2995, 3575, 378, 4048, 2094, 2923, 3055, 1173, 962, 3548, 809, 3200, 1236, 2265, 507, 4023, 1389, 531, 2060, 3169, 2615, 2160, 2905, 3052, 3693, 917, 928, 2611, 1196, 392, 3978, 1990, 2394, 2152, 695, 2971, 1638, 1787, 2610, 322, 1054, 970, 808, 1978, 3602, 2609, 3877, 2377, 2550, 3014, 1004, 2319, 1805, 2389, 1383, 1819, 1456, 3720, 2573, 859, 180, 2099, 1287, 1949, 969, 2033, 3460, 3167, 3573, 3627, 1390, 3066, 3009, 2211, 3520, 2231, 3420, 1190, 83, 1602, 1629, 420, 348, 3848, 16, 852, 638, 3321, 104, 2628, 3330, 1914, 2906, 2535, 2699, 3444, 409, 2667, 3933, 48, 1073, 107, 456, 221, 276, 3008, 2095, 1762, 2235, 2376, 1124, 1802, 3027, 1848, 2013, 3876, 1140, 833, 1839, 2243, 3108, 3873, 1078, 3955, 658, 2089, 2578, 771, 2999, 3671, 3982, 1545, 20, 922, 552, 2856, 355, 2306, 230, 967, 2092, 2649, 2737, 346, 2884, 2433, 2450, 4021, 3834, 3150, 3197, 411, 3348, 1489, 1671, 1499, 999, 2598, 1437, 1844, 1427, 2565, 398, 3684, 2301, 1694, 879, 3466, 3240, 15, 1094, 1647, 3365, 212, 1362, 2449, 2548, 2518, 3512, 1228, 3084, 382, 1539, 1881, 1641, 751, 1272, 1091, 2025, 328, 1113, 1908, 569, 4041, 285, 2076, 2425, 1720, 3312, 2434, 3882, 1007, 2316, 2693, 2627, 3729, 1384, 2046, 2208, 3869, 601, 4003, 3116, 2505, 1947, 2321, 3419, 1153, 3080, 1612, 2523, 2383, 1851, 492, 2925, 1301, 3038, 747, 1047, 3560, 3931, 1550, 1045, 1520, 3519, 2173, 2374, 3472, 3394, 17, 3434, 2486, 3190, 211, 1199, 754, 1729, 1649, 2339, 3806, 518, 1953, 3407, 277, 3385, 3642, 4015, 3669, 1485, 875, 1339, 2929, 3067, 2498, 1176, 650, 873, 3069, 3802, 3924, 820, 987, 3549, 3753, 3217, 3244, 1227, 2867, 525, 560, 3589, 415, 1524, 2632, 120, 3314, 3964, 3529, 806, 1335, 3020, 2682, 472, 1644, 1360, 1277, 952, 1601, 3107, 1279, 314, 538, 2195, 1158, 515, 2267, 3450, 1519, 252, 2739, 1424, 2806, 720, 1515, 161, 2248, 3423, 2861, 2731, 2435, 2711, 1309, 566, 1557, 855, 2978, 633, 1958, 1116, 1838, 2224, 1048, 2724, 1782, 2043, 3832, 3392, 1347, 4059, 513, 619, 2646, 1979, 3164, 3255, 3171, 882, 2531, 3324, 3262, 756, 1859, 3231, 543, 621, 3438, 3628, 3319, 2038, 947, 131, 433, 3608, 3266, 2411, 3203, 3621, 1022, 3785, 1992, 2458, 1412, 916, 1933, 145, 1868, 1198, 3879, 2911, 1002, 2438, 4025, 465, 451, 2058, 1404, 3362, 3653, 933, 216, 1799, 3886, 1126, 3494, 1943, 1033, 2588, 26, 238, 2476, 1142, 3371, 1541, 1630, 1076, 649, 3188, 3016, 3034, 2446, 2216, 3766, 1657, 4024, 2471, 2868, 3267, 1637, 3552, 1831, 620, 3109, 4017, 309, 289, 251, 3291, 2218, 1134, 2088, 1631, 2707, 1496, 1369, 2858, 710, 491, 2484, 1021, 612, 2878, 3836, 2282, 1994, 2236, 2973, 1892, 194, 3254, 2488, 3328, 666, 3734, 3654, 2350, 819, 2097, 2822, 2835, 303, 3502, 2551, 2009, 1800, 2998, 3725, 73, 370, 3257, 1665, 1699, 2738, 4035, 1956, 4034, 2303, 1267, 2549, 1689, 85, 2426, 3155, 1352, 3744, 1351, 331, 2367, 2221, 1537, 3474, 79, 3569, 1325, 2849, 1221, 1244, 2098, 294, 2372, 2727, 2586, 78, 147, 2184, 3746, 1035, 1174, 4006, 149, 489, 255, 464, 138, 860, 2938, 3983, 656, 836, 1302, 547, 2510, 1625, 68, 530, 3587, 3485, 829, 3030, 1692, 2829, 1488, 460, 1750, 2380, 3447, 1189, 358, 1711, 3920, 2429, 685, 2491, 2026, 2684, 611, 2263, 759, 475, 2538, 440, 3644, 2309, 889, 2139, 2997, 2063, 3194, 2811, 3437, 3688, 270, 362, 702, 414, 3125, 541, 1010, 1504, 3857, 864, 254, 3054, 581, 2798, 325, 2461, 2466, 2413, 1907, 3264, 3656, 3597, 3762, 2091, 1470, 1664, 872, 3439, 2271, 124, 21, 1675, 2326, 573, 563, 2917, 2942, 886, 365, 3260, 126, 2670, 1546, 521, 1385, 35, 110, 2475, 1310, 2634, 1754, 2109, 135, 334, 1262, 3531, 2626, 2605, 3576, 3402, 2442, 3180, 3941, 249, 287, 3566, 2652, 529, 239, 857, 567, 3112, 835, 3835, 665, 3345, 3058, 644, 815, 1690, 1172, 86, 891, 244, 3424, 445, 1361, 4019, 3534, 555, 2524, 134, 3968, 3458, 1897, 3902, 2269, 561, 2745, 402, 2187, 240, 517, 266, 3310, 2085, 921, 2146, 3452, 1064, 504, 2397, 3103, 8, 453, 2871, 2285, 2993, 1938, 3213, 3692, 363, 2889, 2625, 3503, 557, 112, 295, 993, 512, 1678, 3596, 2280, 53, 883, 81, 4039, 1147, 3592, 730, 1491, 1414, 654, 2406, 813, 1522, 1506, 2341, 3901, 3182, 1886, 1696, 2647, 3106, 1294, 2104, 2767, 3446, 3535, 1991, 1764, 1976, 55, 1466, 925, 1129, 1044, 6, 1027, 3781, 3157, 3881, 724, 3691, 3316, 1101, 3578, 2045, 1969, 2156, 1693, 856, 2928, 3541, 3971, 2651, 2844, 689, 1416, 91, 729, 2552, 2786, 2331, 2176, 1065, 3311, 1900, 2057, 3226, 2050, 302, 2516, 2953, 3247, 1480, 3265, 1498, 485, 893, 3624, 3946, 227, 3811, 944, 641, 391, 2654, 1013, 1551, 1179, 1405, 3192, 452, 2396, 3554, 2643, 2511, 3784, 2703, 3047, 2496, 2583, 632, 3927, 3136, 3147, 755, 3812, 572, 1366, 1842, 897, 4043, 2388, 1410, 1668, 3698, 880, 1107, 1966, 3045, 1640, 3006, 2566, 3403, 1019, 736, 3040, 2765, 2151, 2307, 1296, 797, 780, 2064, 3588, 556, 1749, 2675, 486, 3129, 979, 443, 2314, 3105, 3747, 881, 3218, 3795, 74, 3361, 3564, 1092, 1701, 1765, 1906, 1327, 1070, 428, 1809, 1523, 637, 1439, 2257, 1270, 2287, 3558, 1326, 565, 2659, 1672, 3987, 4063, 3702, 3470, 3633, 849, 1783, 2773, 1114, 2774, 630, 2024, 2614, 3496, 982, 253, 1006, 3975, 1772, 41, 2528, 931, 796, 3737, 672, 930, 3530, 105, 1421, 1411, 2378, 3300, 591, 3092, 985, 2437, 4022, 1915, 3904, 459, 2130, 3343, 3160, 2382, 1018, 617, 3610, 2452, 66, 3555, 3484, 1257, 528, 524, 2723, 3635, 1924, 3580, 3745, 2385, 1223, 4065, 2334, 1604, 202, 427, 3536, 1977, 1856, 1096, 3430, 681, 657, 2134, 1110, 3949, 118, 1847, 3089, 2310, 605, 3137, 3584, 989, 1379, 965, 2000, 1615, 232, 1235, 2188, 896, 2874, 3097, 2568, 715, 2178, 1543, 2882, 4042, 2546, 3937, 2361, 76, 838, 454, 1733, 2021, 2035, 1791, 684, 3888, 3700, 2209, 3748, 1210, 3285, 1214, 2337, 3237, 734, 310, 910, 2039, 1202, 3064, 271, 22, 2555, 1478, 2947, 2679, 2589, 2005, 3650, 1896, 2662, 537, 3774, 3477, 3945, 3707, 2617, 3418, 3728, 1177, 4007, 3220, 2593, 2572, 3894, 2212, 2642, 3991, 1283, 3234, 1425, 862, 2783, 2728, 3098, 1298, 1477, 1295, 598, 2482, 2934, 850, 1704, 1635, 1562, 3853, 1396, 3457, 4049, 483, 3425, 839, 139, 760, 775, 2648, 3540, 935, 2541, 2002, 3907, 3405, 2036, 606, 3615, 3816, 1224, 1316, 1029, 3288, 3065, 553, 744, 773, 1736, 2618, 1505, 705, 3791, 1864, 863, 1829, 511, 2201, 3718, 2603, 3719, 2144, 3741, 3944, 2996, 701, 2129, 723, 1853, 3329, 3143, 3865, 2034, 3279, 3263, 3699, 3583, 2768, 1171, 914, 2118, 2080, 1009, 31, 183, 2581, 3367, 719, 1297, 1448, 3690, 3289, 2101, 2137, 1528, 3117, 293, 876, 224, 3223, 1660, 3735, 1319, 2604, 3486, 2364, 1531, 1738, 1072, 1175, 1401, 3351, 61, 3618, 2370, 713, 3923, 2888, 1139, 260, 1146, 2976, 4013, 1051, 3670, 3678, 3189, 3638, 3682, 2360, 908, 2575, 821, 2423, 3290, 938, 3186, 198, 1757, 2784, 1016, 1371, 1143, 290, 2499, 2722, 3952, 3582, 2463, 2008, 1490, 1023, 1564, 3162, 47, 1025, 3674, 676, 1500, 3235, 1433, 3757, 2167, 3643, 3782, 2655, 3542, 1566, 929, 2820, 1068, 3847, 1797, 3141, 1833, 3849, 1724, 1824, 2182, 942, 1529, 357, 4001, 1148, 373, 763, 3951, 1234, 2079, 1584, 164, 3127, 3149, 865, 2885, 3614, 2431, 1571, 2237, 1419, 2924, 2132, 1422, 2311, 3919, 3280, 2692, 269, 3398, 469, 1559, 3302, 1012, 768, 3287, 2686, 1344, 1263, 1136, 2851, 793, 1816, 2846, 3929, 3301, 2083, 3981, 2800, 3595, 1916, 2545, 2444, 963, 3456, 614, 4052, 2141, 2975, 478, 792, 884, 144, 3543, 2157, 534, 4018, 351, 3074, 3205, 1324, 3344, 3406, 2177, 664, 2174, 56, 2014, 1964, 549, 2256, 3622, 60, 958, 2369, 3294, 772, 3305, 2983, 851, 2669, 1156, 742, 2519, 885, 2855, 3591, 27, 1240, 2456, 2465, 1913, 3131, 432, 2140, 1578, 2100, 304, 3159, 1011, 871, 408, 920, 1038, 1755, 3846, 977, 615, 235, 1194, 2792, 3082, 2778, 3517, 1266, 2895, 2126, 2332, 3, 3868, 1525, 25, 1393, 3532, 1060, 1318, 2735, 3972, 488, 670, 1399, 2666, 3758, 607, 3323, 3696, 3659, 1458, 2689, 2534, 179, 2863, 1350, 1090, 1017, 578, 1133, 3928, 1186, 3606, 2255, 1502, 4033, 2907, 2168, 3051, 714, 506, 550, 449, 2650, 948, 2653, 117, 3221, 1974, 2335, 1229, 980, 3232, 3626, 800, 69, 2764, 1821, 1521, 1993, 1482, 1542, 324, 3258, 187, 3366, 3967, 1248, 2599, 1212, 1683, 412, 2105, 2395, 1948, 1276, 769, 608, 3480, 1184, 682, 3498, 2831, 625, 1951, 2399, 2713, 1614, 1627, 752, 3845, 2420, 455, 704, 2664, 2526, 4010, 717, 3976, 3299, 996, 811, 3679, 1616, 3525, 660, 1618, 3413, 3475, 3277, 1211, 3649, 1746, 2781, 1752, 1946, 1342, 2954, 367, 2249, 326, 1028, 245, 3322, 2753, 3037, 1475, 3427, 1895, 502, 366, 343, 95, 3068, 961, 1773, 1452, 3121, 1588, 1154, 1467, 1854, 2760, 2190, 2521, 1801, 770, 2940, 2432, 1001, 2500, 3641, 1779, 945, 997, 1355, 2252, 906, 3586, 1817, 3895, 624, 430, 2683, 1910, 2210, 2801, 1609, 2958, 3523, 1804, 3497, 688, 2070, 1717, 1767, 2194, 2969, 11, 2016, 3158, 1343, 3468, 3233, 3352, 2695, 1688, 136, 1446, 4014, 3334, 3059, 1667, 1608, 2876, 3243, 3379, 1744, 1003, 1079, 3752, 2854, 1052, 1438, 904, 2284, 1917, 3453, 2018, 818, 3761, 1698, 1169, 2663, 2770, 2787, 3282, 3049, 2029, 2671, 2241, 113, 2368, 1597, 1333, 1894, 1891, 753, 3771, 4008, 3647, 1815, 3948, 3308, 1109, 3039, 1684, 2873, 1300, 1131, 3399, 106, 789, 1336, 1024, 3410, 1589, 1632, 1599, 1187, 2006, 3828, 218, 3245, 2082, 2270, 44, 387, 3087, 1695, 1193, 2596, 1579, 533, 3056, 1770, 96, 3023, 1822, 3850, 583, 2051, 2093, 1680, 1180, 288, 1128, 170, 874, 1055, 3703, 3950, 3736, 2955, 2053, 1209, 3510, 3163, 1089, 1381, 2462, 3516, 3028, 3140, 2678, 2240, 3072, 2968, 286, 2522, 2096, 2769, 1926, 1392, 1843, 3932, 3043, 2503, 1996, 2691, 1370, 2945, 3145, 3956, 3206, 3175, 1183, 3198, 3960, 3416, 2065, 2957, 1679, 2315, 2836, 3101, 3544, 3506, 2362, 4051, 3191, 1858, 3041, 1712, 1728, 3327, 1658, 384, 3075, 631, 1471, 101, 991, 160, 2639, 1581, 3942, 2069, 1387, 1137, 97, 3333, 3813, 2459, 1600, 1191, 2864, 3025, 1662, 3996, 2559, 2215, 937, 2808, 2986, 1053, 1026, 1081, 2582, 3185, 3436, 2115, 2557, 2473, 3665, 941, 1315, 1306, 2078, 2407, 3715, 1232, 847, 18, 39, 3102, 2019, 3891, 4054, 1120, 3716, 3339, 2701, 119, 2527, 1611, 640, 1406, 3256, 1830, 781, 2633, 3750, 1812, 3689, 148, 50, 2260, 520, 3465, 3601, 2110, 1893, 2584, 1768, 2824, 2834, 3382, 2967, 3574, 2517, 1715, 1973, 1071, 1761, 368, 2493, 3396, 1959, 2537, 217, 3864, 1487, 2440, 166, 100, 446, 2272, 735, 4032, 1281, 1454, 4044, 2933, 2358, 88, 643, 1776, 3648, 3905, 2782, 3134, 936, 1930, 1483, 3889, 3677, 1560, 3854, 80, 1254, 1513, 2977, 1575, 596, 115, 3144, 603, 3261, 2677, 3018, 3726, 4050, 2579, 2972, 1204, 1889, 2561, 1591, 586, 163, 609, 1077, 3686, 344, 24, 558, 267, 1400, 2830, 3546, 1803, 2777, 2680, 3370, 2624, 3538, 1763, 2366, 3807, 1786, 3572, 3146, 2495, 3377, 337, 280, 2390, 2288, 2030, 3672, 2752, 329, 1391, 426, 3093, 3527, 1292, 3875, 3673, 1264, 77, 2502, 1395, 3612, 3959, 203, 3195, 3378, 1123, 2746, 3581, 2145, 2982, 1552, 3551, 776, 3459, 1058, 1507, 352, 3695, 3214, 1415, 1432, 2023, 3442, 1760, 1127, 3090, 972, 3411, 2077, 1605, 2567, 3481, 327, 3994, 495, 3851, 597, 1745, 2020, 3958, 1624, 2062, 1549, 3336, 3110, 1322, 1682, 659, 2447, 1253, 3364, 1872, 3349, 2932, 1674, 2122, 425, 2172, 1526, 2714, 2245, 2860, 1074, 1095, 3756, 2904, 36, 663, 421, 1922, 628, 3963, 1718, 2553, 2469, 3810, 1661, 437, 2758, 1, 3369) +ORDER BY LAST_ORDER_DATETIME DESC \ No newline at end of file diff --git a/models/marts/warehouse/dim__dates.sql b/analyses/dim__dates_backup.sql similarity index 100% rename from models/marts/warehouse/dim__dates.sql rename to analyses/dim__dates_backup.sql diff --git a/models/marts/reporting/rep_exchange__daily_orders.sql b/models/marts/reporting/rep_exchange__daily_orders.sql index 33ad7e3..6f747ca 100644 --- a/models/marts/reporting/rep_exchange__daily_orders.sql +++ b/models/marts/reporting/rep_exchange__daily_orders.sql @@ -28,7 +28,7 @@ dates AS ( transaction_orders_get_next_order_created_datetime AS ( SELECT *, - LEAD(order_created_datetime) OVER (PARTITION BY company_id ORDER BY order_created_datetime) AS next_order_created_datetime + LEAD(order_created_datetime) OVER (PARTITION BY company_id ORDER BY order_created_datetime, transaction_order_id) AS next_order_created_datetime FROM transaction_orders @@ -40,66 +40,66 @@ fct_and_dim_joins AS ( bookings.booking_marking_id, bookings.company_id, - companies.company_marking_id AS company_marking_id, - companies.autocount_id AS company_autocount_id, - companies.company_type AS company_type, - companies.business_type AS company_business_type, - companies.exchange_rate_segment AS company_exchange_rate_segment, - companies.is_migrated_company AS is_migrated_company, - companies.country_name AS company_country_name, - companies.state_name AS company_state_name, - companies.district_name AS company_district_name, - companies.postcode AS company_postcode, - companies.has_wallet AS company_has_wallet, - companies.latitude AS company_latitude, - companies.longitude AS company_longitude, + companies.company_marking_id AS company_marking_id, + companies.autocount_id AS company_autocount_id, + companies.company_type AS company_type, + companies.business_type AS company_business_type, + companies.exchange_rate_segment AS company_exchange_rate_segment, + companies.is_migrated_company AS is_migrated_company, + companies.country_name AS company_country_name, + companies.state_name AS company_state_name, + companies.district_name AS company_district_name, + companies.postcode AS company_postcode, + companies.has_wallet AS company_has_wallet, + companies.latitude AS company_latitude, + companies.longitude AS company_longitude, bookings.user_id, bookings.bank_id, - fix_currencies.currency_name AS fix_currency_name, + fix_currencies.currency_name AS fix_currency_name, quote_currencies.currency_name AS quote_currency_name, base_currencies.currency_name AS base_currency_name, bookings.service_type, - bookings.status AS booking_status, - bookings.is_first_time_company AS is_first_time_booking_company, - bookings.is_first_time_company_completed AS is_first_time_booking_company_completed, - bookings.is_first_time_user AS is_first_time_booking_user, - bookings.is_first_time_user_completed AS is_first_time_booking_user_completed, - bookings.estimate_base_to_quote_currency_exchange_rate AS estimate_booking_base_to_quote_currency_exchange_rate, - bookings.estimate_quote_value AS estimate_booking_quote_value, - bookings.estimate_base_value AS estimate_booking_base_value, - bookings.estimate_value_rm AS estimate_booking_value_rm, + bookings.status AS booking_status, + bookings.is_first_time_company AS is_first_time_booking_company, + bookings.is_first_time_company_completed AS is_first_time_booking_company_completed, + bookings.is_first_time_user AS is_first_time_booking_user, + bookings.is_first_time_user_completed AS is_first_time_booking_user_completed, + bookings.estimate_base_to_quote_currency_exchange_rate AS estimate_booking_base_to_quote_currency_exchange_rate, + bookings.estimate_quote_value AS estimate_booking_quote_value, + bookings.estimate_base_value AS estimate_booking_base_value, + bookings.estimate_value_rm AS estimate_booking_value_rm, bookings.booking_created_datetime, bookings.booking_approved_datetime, bookings.booking_completed_datetime, bookings.booking_suspended_datetime, - transaction_orders_get_next_order_created_datetime.transaction_order_id AS order_id, - transaction_orders_get_next_order_created_datetime.payment_method AS order_payment_method, + transaction_orders_get_next_order_created_datetime.transaction_order_id AS order_id, + transaction_orders_get_next_order_created_datetime.payment_method AS order_payment_method, transaction_orders_get_next_order_created_datetime.order_status, - transaction_orders_get_next_order_created_datetime.payment_reference AS order_payment_reference, - transaction_orders_get_next_order_created_datetime.bill_number AS order_bill_number, - transaction_orders_get_next_order_created_datetime.is_first_time_company AS is_first_time_order_company, - transaction_orders_get_next_order_created_datetime.is_first_time_company_completed AS is_first_time_order_company_completed, - transaction_orders_get_next_order_created_datetime.is_first_time_user AS is_first_time_order_user, - transaction_orders_get_next_order_created_datetime.is_first_time_user_completed AS is_first_time_order_user_completed, - transaction_orders_get_next_order_created_datetime.base_to_quote_currency_exchange_rate AS order_base_to_quote_currency_exchange_rate , - transaction_orders_get_next_order_created_datetime.base_value AS order_base_value , - transaction_orders_get_next_order_created_datetime.base_service_charge AS order_base_service_charge , - transaction_orders_get_next_order_created_datetime.base_tax AS order_base_tax , - transaction_orders_get_next_order_created_datetime.quote_value AS order_quote_value , - transaction_orders_get_next_order_created_datetime.value_rm AS order_value_rm , - transaction_orders_get_next_order_created_datetime.service_charge_rm AS order_service_charge_rm , - transaction_orders_get_next_order_created_datetime.tax_rm AS order_tax_rm , - transaction_orders_get_next_order_created_datetime.total_value_rm AS total_order_value_rm, + transaction_orders_get_next_order_created_datetime.payment_reference AS order_payment_reference, + transaction_orders_get_next_order_created_datetime.bill_number AS order_bill_number, + transaction_orders_get_next_order_created_datetime.is_first_time_company AS is_first_time_order_company, + transaction_orders_get_next_order_created_datetime.is_first_time_company_completed AS is_first_time_order_company_completed, + transaction_orders_get_next_order_created_datetime.is_first_time_user AS is_first_time_order_user, + transaction_orders_get_next_order_created_datetime.is_first_time_user_completed AS is_first_time_order_user_completed, + transaction_orders_get_next_order_created_datetime.base_to_quote_currency_exchange_rate AS order_base_to_quote_currency_exchange_rate , + transaction_orders_get_next_order_created_datetime.base_value AS order_base_value , + transaction_orders_get_next_order_created_datetime.base_service_charge AS order_base_service_charge , + transaction_orders_get_next_order_created_datetime.base_tax AS order_base_tax , + transaction_orders_get_next_order_created_datetime.quote_value AS order_quote_value , + transaction_orders_get_next_order_created_datetime.value_rm AS order_value_rm , + transaction_orders_get_next_order_created_datetime.service_charge_rm AS order_service_charge_rm , + transaction_orders_get_next_order_created_datetime.tax_rm AS order_tax_rm , + transaction_orders_get_next_order_created_datetime.total_value_rm AS total_order_value_rm, transaction_orders_get_next_order_created_datetime.order_created_datetime, - order_created_dates.first_day_of_week AS order_created_week, - + order_created_dates.first_day_of_week AS order_created_week, + transaction_orders_get_next_order_created_datetime.order_pending_submission_datetime, transaction_orders_get_next_order_created_datetime.order_pending_verification_datetime, transaction_orders_get_next_order_created_datetime.order_approved_datetime, @@ -108,22 +108,22 @@ fct_and_dim_joins AS ( transaction_orders_get_next_order_created_datetime.order_suspended_datetime, transaction_orders_get_next_order_created_datetime.next_order_created_datetime, - transaction_costs.transaction_cost_id AS cost_id, - transaction_costs.bank_id AS currency_vendor_bank_id, - transaction_costs.transaction_type AS cost_transaction_type, - transaction_costs.payment_method AS cost_payment_method, - transaction_costs.status AS cost_status, - transaction_costs.payment_reference AS cost_payment_reference, - transaction_costs.bill_number AS cost_bill_number, - transaction_costs.base_value AS cost_base_value, - transaction_costs.quote_value AS cost_quote_value, + transaction_costs.transaction_cost_id AS cost_id, + transaction_costs.bank_id AS currency_vendor_bank_id, + transaction_costs.transaction_type AS cost_transaction_type, + transaction_costs.payment_method AS cost_payment_method, + transaction_costs.status AS cost_status, + transaction_costs.payment_reference AS cost_payment_reference, + transaction_costs.bill_number AS cost_bill_number, + transaction_costs.base_value AS cost_base_value, + transaction_costs.quote_value AS cost_quote_value, transaction_costs.base_to_quote_currency_exchange_rate AS cost_base_to_quote_currency_exchange_rate, - transaction_costs.base_tax AS cost_base_tax, - transaction_costs.base_service_charge AS cost_base_service_charge, - transaction_costs.value_rm AS cost_value_rm, - transaction_costs.tax_rm AS cost_tax_rm, - transaction_costs.service_charge_rm AS cost_service_charge_rm, - transaction_costs.total_value_rm AS total_cost_value_rm, + transaction_costs.base_tax AS cost_base_tax, + transaction_costs.base_service_charge AS cost_base_service_charge, + transaction_costs.value_rm AS cost_value_rm, + transaction_costs.tax_rm AS cost_tax_rm, + transaction_costs.service_charge_rm AS cost_service_charge_rm, + transaction_costs.total_value_rm AS total_cost_value_rm, transaction_costs.cost_created_datetime, transaction_costs.cost_pending_submission_datetime, transaction_costs.cost_pending_verification_datetime, @@ -144,16 +144,16 @@ fct_and_dim_joins AS ( LEFT JOIN companies ON (bookings.company_id = companies.company_id) - LEFT JOIN dates AS order_created_dates - ON (transaction_orders_get_next_order_created_datetime.order_created_datetime = order_created_dates.date_day) + LEFT JOIN dates AS order_created_dates + ON (DATE(transaction_orders_get_next_order_created_datetime.order_created_datetime) = order_created_dates.date_day) - LEFT JOIN currencies AS fix_currencies + LEFT JOIN currencies AS fix_currencies ON (bookings.fix_currency_id = fix_currencies.currency_id) - LEFT JOIN currencies AS quote_currencies + LEFT JOIN currencies AS quote_currencies ON (bookings.quote_currency_id = quote_currencies.currency_id) - LEFT JOIN currencies AS base_currencies + LEFT JOIN currencies AS base_currencies ON (bookings.base_currency_id = base_currencies.currency_id) ), @@ -258,4 +258,4 @@ final__rep_exchange__daily_orders AS ( FROM fct_and_dim_joins ) -SELECT * FROM final__rep_exchange__daily_orders \ No newline at end of file +SELECT * FROM final__rep_exchange__daily_orders diff --git a/models/marts/warehouse/dim__dates.py b/models/marts/warehouse/dim__dates.py new file mode 100644 index 0000000..4e17fdc --- /dev/null +++ b/models/marts/warehouse/dim__dates.py @@ -0,0 +1,80 @@ +# Python script to compute advance working dates + +# Weekend Example: using Saturday or Sunday and add 2 working days: +# Monday = 1 working day, Tuesday = 1 working day, Wednesday = Delivery Date +# Assumption for weekends, base date is NOT considered as one working day + +# Weekday Example: using Monday and adding 2 working days: +# Monday = 1 working day, Tuesday = 1 working day, Wednesday = Delivery Date +# Assumption for weekdays, base date is considered as one working day + +# Forecasting on future dates without information on holidays will not be accurate. + + +import pandas as pd +from datetime import datetime as dt, timedelta + + +# Function to check if a given date is a weekend [Saturday(5) or Sunday(6)] +def is_weekend(date): + return (date.weekday() == 5) | (date.weekday() == 6) + + +# Function to compute the in advance working days +def compute_working_days(start_date, num_working_days, holiday_list, after_cut_off = 0): + # after_cut_off = 0 for orders before 4pm + # after_cut_off = 1 for orders after 4pm + + counter = 0 + + # For dates on weekend or holiday or after cut off time, additional 1 working day to the loop + if (after_cut_off == 1) | is_weekend(start_date) | (start_date in holiday_list): + counter -= 1 + + # Loop to increase n number of working days, if weekend/holiday, skip counter + while counter < num_working_days: + start_date = start_date + timedelta(days=1) + + if is_weekend(start_date) | (start_date in holiday_list): + continue + + counter += 1 + + return start_date + + +# Main function +def model(dbt, session): + + # Setting configuration + dbt.config(materialized="table", + packages = ["pandas"]) + + # Import data from upstream dbt model + df_date = dbt.ref("int__dates") + + # Extract holiday dates into a list + df_work = df_date.to_pandas() + df_new = df_work[df_work["IS_COMPANY_HOLIDAY"] == 1] + df_holiday_list = df_new["DATE_DAY"].tolist() + + # Apply function to df + df_work["ADD_1_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 1, df_holiday_list, 0), axis=1) + df_work["ADD_2_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 2, df_holiday_list, 0), axis=1) + df_work["ADD_3_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 3, df_holiday_list, 0), axis=1) + df_work["ADD_5_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 5, df_holiday_list, 0), axis=1) + df_work["ADD_30_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 30, df_holiday_list, 0), axis=1) + df_work["ADD_90_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 90, df_holiday_list, 0), axis=1) + df_work["ADD_365_WORKING_DAY_INCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 365, df_holiday_list, 0), axis=1) + + # For orders after cut off time 4pm + # Affects only the weekdays + df_work["ADD_1_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 1, df_holiday_list, 1), axis=1) + df_work["ADD_2_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 2, df_holiday_list, 1), axis=1) + df_work["ADD_3_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 3, df_holiday_list, 1), axis=1) + df_work["ADD_5_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 5, df_holiday_list, 1), axis=1) + df_work["ADD_30_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 30, df_holiday_list, 1), axis=1) + df_work["ADD_90_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 90, df_holiday_list, 1), axis=1) + df_work["ADD_365_WORKING_DAY_EXCLUDED_BASE_DATE"] = df_work.apply(lambda row: compute_working_days(row["DATE_DAY"], 365, df_holiday_list, 1), axis=1) + + return df_work \ No newline at end of file diff --git a/models/staging/exchange/base/base_exchange__account_statements.sql b/models/staging/exchange/base/base_exchange__account_statements.sql new file mode 100644 index 0000000..fd1850d --- /dev/null +++ b/models/staging/exchange/base/base_exchange__account_statements.sql @@ -0,0 +1,52 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'account_statements') }} + +), + +-- LOGIC +account_statements_rename as ( + + SELECT + id AS account_statement_id, + statement_account_id, + date(date_from) AS account_statement_from_date, + date(date_to) AS account_statement_to_date, + total_amount AS total_value, + begin_balance AS starting_balance, + end_balance AS closing_balance, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source +), + +-- FINAL +final__base_exchange__account_statements AS ( + + SELECT + -- ids + account_statement_id, + statement_account_id, + + -- dimensions + starting_balance, + closing_balance, + + -- measures + total_value, + + -- date/times + account_statement_from_date, + account_statement_to_date, + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM account_statements_rename +) + +SELECT * FROM final__base_exchange__account_statements diff --git a/models/staging/exchange/base/base_exchange__statement_accounts.sql b/models/staging/exchange/base/base_exchange__statement_accounts.sql new file mode 100644 index 0000000..417febc --- /dev/null +++ b/models/staging/exchange/base/base_exchange__statement_accounts.sql @@ -0,0 +1,50 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'statement_accounts') }} + +), + +-- LOGIC +statement_accounts_rename as ( + + SELECT + id AS statement_account_id, + number AS account_number, + type AS account_type, + name AS company_name, + currency AS currency_name, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source + +), + +-- FINAL +final__base_exchange__statement_accounts AS ( + + SELECT + -- ids + statement_account_id, + + -- dimensions + account_number, + account_type, + company_name, + currency_name, + + -- measures + + -- date/times + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM statement_accounts_rename + +) + +SELECT * FROM final__base_exchange__statement_accounts diff --git a/models/staging/exchange/base/base_exchange__statement_transaction_owners.sql b/models/staging/exchange/base/base_exchange__statement_transaction_owners.sql new file mode 100644 index 0000000..052da29 --- /dev/null +++ b/models/staging/exchange/base/base_exchange__statement_transaction_owners.sql @@ -0,0 +1,62 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'statement_transaction_owners') }} + +), + +-- LOGIC +statement_transaction_owners_rename as ( + + SELECT + id AS statement_transaction_owner_id, + statement_transaction_id, + type, + system, + owner_type, + owner_id, + owner_reference, + invoice_reference, + receipt_reference, + is_auto_mapped, + status, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source + +), + +-- FINAL +final__base_exchange__statement_transaction_owners AS ( + + SELECT + -- ids + statement_transaction_owner_id, + statement_transaction_id, + owner_id, + + -- dimensions + system, + type, + owner_type, + owner_reference, + invoice_reference, + receipt_reference, + is_auto_mapped, + status, + + -- measures + + -- date/times + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM statement_transaction_owners_rename + +) + +SELECT * FROM final__base_exchange__statement_transaction_owners diff --git a/models/staging/exchange/base/base_exchange__statement_transactions.sql b/models/staging/exchange/base/base_exchange__statement_transactions.sql new file mode 100644 index 0000000..f010110 --- /dev/null +++ b/models/staging/exchange/base/base_exchange__statement_transactions.sql @@ -0,0 +1,68 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'statement_transactions') }} + +), + +-- LOGIC +statement_transactions_rename as ( + + SELECT + id AS statement_transaction_id, + account_statement_id, + transaction_date AS transaction_datetime, + posting_date AS posting_datetime, + transaction_description, + transaction_description_2, + transaction_description_3, + transaction_description_4, + transaction_description_5, + transaction_ref AS transaction_reference, + amount, + teller_id, + branch_channel AS branch_channel_id, + transaction_code, + end_balance AS closing_balance, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source + +), + +-- FINAL +final__base_exchange__statement_transactions AS ( + + SELECT + -- ids + statement_transaction_id, + account_statement_id, + branch_channel_id, + + -- dimensions + transaction_description, + transaction_description_2, + transaction_description_3, + transaction_description_4, + transaction_description_5, + transaction_reference, + transaction_code, + amount, + closing_balance, + + -- measures + + -- date/times + transaction_datetime, + posting_datetime, + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM statement_transactions_rename +) + +SELECT * FROM final__base_exchange__statement_transactions diff --git a/models/staging/exchange/base/base_exchange__voucher_redemptions.sql b/models/staging/exchange/base/base_exchange__voucher_redemptions.sql new file mode 100644 index 0000000..3f62da6 --- /dev/null +++ b/models/staging/exchange/base/base_exchange__voucher_redemptions.sql @@ -0,0 +1,50 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'voucher_redemptions') }} + +), + +-- LOGIC +voucher_redemptions_rename AS ( + + SELECT + id AS voucher_redemption_id, + voucher_id, + transaction_id, + redemption_id, + value AS voucher_credit, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source + +), + +-- FINAL +final__base_exchange__voucher_redemptions AS ( + + SELECT + -- ids + voucher_redemption_id, + voucher_id, + transaction_id, + redemption_id, + + -- dimensions + voucher_credit, + + -- measures + + -- date/times + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM voucher_redemptions_rename + +) + +SELECT * FROM final__base_exchange__voucher_redemptions diff --git a/models/staging/exchange/base/base_exchange__vouchers.sql b/models/staging/exchange/base/base_exchange__vouchers.sql new file mode 100644 index 0000000..ab6229a --- /dev/null +++ b/models/staging/exchange/base/base_exchange__vouchers.sql @@ -0,0 +1,50 @@ +-- IMPORTS +WITH source AS ( + SELECT * FROM {{ source('src_exchange_mysql', 'vouchers') }} + +), + +-- LOGIC +vouchers_rename AS ( + + SELECT + id AS voucher_id, + name, + code, + type, + value AS voucher_credit, + created_at AS created_datetime, + updated_at AS updated_datetime, + '{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime + + FROM source + +), + +-- FINAL +final__base_exchange__vouchers AS ( + + SELECT + -- ids + voucher_id, + + -- dimensions + name, + code, + type, + voucher_credit, + + -- measures + + -- date/times + created_datetime, + updated_datetime, + + -- metadata + _dbt_ran_datetime + + FROM vouchers_rename + +) + +SELECT * FROM final__base_exchange__vouchers diff --git a/models/staging/exchange/stg_exchange__company_addresses.sql b/models/staging/exchange/stg_exchange__company_addresses.sql index a16c037..5c8afd1 100644 --- a/models/staging/exchange/stg_exchange__company_addresses.sql +++ b/models/staging/exchange/stg_exchange__company_addresses.sql @@ -1,7 +1,7 @@ -- A flag indicator to determine whether to run a full_load or an incremental_load -- If user is a developer, a full load will be executed. -- If the target schema is set to 'dbt_prod', only an incremental load will be performed. -{% if target.name == 'dbt_prod' %}{% set one_month_incremental_flag = true %}{% else %}{% set one_month_incremental_flag = false %}{% endif %} +{% if target.name == 'dbt_prod' %}{% set one_month_incremental_flag = true %}{% else %}{% set one_month_incremental_flag = true %}{% endif %} -- MODEL CONFIGURATION BLOCK {{