فهرست منبع

feat(cintas): add production environment configuration and enhance summary calculation

- Add .env.production with PostgreSQL and Kinde auth configuration
- Update Cintas workflow with improved type safety and layout handling
- Enhance calendar summary page with dark mode support and improved table styling
- Refactor summary calculation procedure to handle FS/UR pending types separately
- Add new pending total calculations for comprehensive reporting
vtugulan 6 ماه پیش
والد
کامیت
b4f84fe9c8

+ 9 - 0
.env.production

@@ -0,0 +1,9 @@
+# PostgreSQL Database Configuration
+DATABASE_URL=postgresql://root:post.Acc.967@vixflix.online:5432/vtoriodb?schema=public
+
+# Kinde Configuration
+KINDE_CLIENT_ID=1863d3d354784c89a480e86410f23ea5
+KINDE_CLIENT_SECRET=OGwKvav8cRbKUNhaZup3aOmO3G4LP1Z4DIBsbXxcEShUcHAAPPLe
+KINDE_ISSUER_URL=https://vtorio.kinde.com
+KINDE_SITE_URL=https://vtor.io
+KINDE_POST_LOGOUT_REDIRECT_URL=https://vtor.io

+ 7 - 7
app/actions/cintas-workflow.ts

@@ -13,13 +13,13 @@ export async function createCintasImportRecord(fileId: string, fileName: string)
   try {
     // Step 1: Find the "Cintas Install Calendar" layout configuration
     const layoutsResult = await getLayoutConfigurations();
-    
+
     if (!layoutsResult.success || !layoutsResult.data) {
       throw new Error('Failed to fetch layout configurations');
     }
 
     const cintasLayout = layoutsResult.data.find(
-      layout => layout.name === 'Cintas Install Calendar'
+      (layout: { id: number; name: string }) => layout.name === 'Cintas Install Calendar'
     );
 
     if (!cintasLayout) {
@@ -28,7 +28,7 @@ export async function createCintasImportRecord(fileId: string, fileName: string)
 
     // Step 2: Create import record with the layout configuration
     const importName = `Cintas Install Calendar - ${fileName}`;
-    
+
     const importResult = await createImport({
       name: importName,
       layoutId: cintasLayout.id,
@@ -61,13 +61,13 @@ export async function createCintasImportRecord(fileId: string, fileName: string)
 export async function processCintasImportData(importId: number) {
   try {
     console.log(`Starting Cintas import data processing for import ID: ${importId}`);
-    
+
     // Import the processCintasImport function
     const { processCintasImport } = await import('./process-cintas-import');
-    
+
     // Process the import
     const result = await processCintasImport(importId);
-    
+
     if (result.success) {
       console.log('Cintas import data processing completed successfully:', result);
       return {
@@ -98,7 +98,7 @@ export async function processCintasImportData(importId: number) {
 export async function getCintasInstallCalendarLayout() {
   try {
     const layoutsResult = await getLayoutConfigurations();
-    
+
     if (!layoutsResult.success) {
       return null;
     }

+ 21 - 15
app/cintas-calendar-summary/page.tsx

@@ -338,24 +338,30 @@ export default function CintasCalendarSummaryPage() {
                   <div className="mt-6">
                     <h3 className="text-lg font-semibold mb-4">Summary Results</h3>
                     <div className="overflow-x-auto">
-                      <table className="min-w-full divide-y divide-gray-200">
-                        <thead className="bg-gray-50">
+                      <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
+                        <thead className="bg-gray-50 dark:bg-gray-800">
                           <tr>
-                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Week</th>
-                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">TRR Total</th>
-                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">4 Week Avg</th>
-                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">TRR + 4Wk</th>
-                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Power Adds</th>
+                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Week</th>
+                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">TRR Total</th>
+                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">4 Week Avg</th>
+                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">TRR + 4Wk</th>
+                            <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Power Adds</th>
                           </tr>
                         </thead>
-                        <tbody className="bg-white divide-y divide-gray-200">
-                          {summaryData.map((item) => (
-                            <tr key={item.id}>
-                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item.week}</td>
-                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item.trrTotal}</td>
-                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item.fourWkAverages}</td>
-                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item.trrPlus4Wk}</td>
-                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{item.powerAdds}</td>
+                        <tbody className="bg-white divide-y divide-gray-200 dark:bg-gray-800 dark:divide-gray-700">
+                          {summaryData.map((item, index) => (
+                            <tr
+                              key={`${item.id}-${index}`}
+                              className={index % 2 === 0
+                                ? 'bg-white dark:bg-gray-800'
+                                : 'bg-gray-50 dark:bg-gray-700/50'
+                              }
+                            >
+                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">{item.week}</td>
+                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">{item.trrTotal}</td>
+                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">{item.fourWkAverages}</td>
+                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">{item.trrPlus4Wk}</td>
+                              <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">{item.powerAdds}</td>
                             </tr>
                           ))}
                         </tbody>

+ 75 - 13
prisma/migrations/20250722041246_add_cintas_calculate_summary_procedure/migration.sql

@@ -14,15 +14,16 @@ BEGIN
     -- current week
     insert into weekSums (week, amount, amountType)
     select aw.week,
-           sum(aw.week_sum),
+           coalesce(sum(aw.week_sum), 0),
            'trr4wk'
     from cintas_install_calendar i
              inner join lateral (
         select case when i.install_date <> '' then i.install_date::date end,
                case
                    when i.install_date <> '' then date_part('week', i.install_date::date)
-                   when i.opportunity_status = 'Pending - Install Not Scheduled' then 99 + 22
-                   end,
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+               end,
                case when i.trr <> '' then i.trr::decimal else 0 end,
                case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
                case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
@@ -55,7 +56,9 @@ BEGIN
         select case when i.install_date <> '' then i.install_date::date end,
                case
                    when i.install_date <> '' then date_part('week', i.install_date::date)
-                   when i.opportunity_status = 'Pending - Install Not Scheduled' then 99 + 22 end,
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+               end,
                case when i.trr <> '' then i.trr::decimal else 0 end,
                case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
                case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
@@ -75,7 +78,7 @@ BEGIN
     where i."importId" = provided_import_id
       and rtrim(opportunity_status) <> ''
       and ow.week_minus_1 is not null
-      and aw.week <> 99
+      and aw.week not in (99, 100, 101)
     group by ow.week_minus_1
     ;
 
@@ -89,7 +92,9 @@ BEGIN
         select case when i.install_date <> '' then i.install_date::date end,
                case
                    when i.install_date <> '' then date_part('week', i.install_date::date)
-                   when i.opportunity_status = 'Pending - Install Not Scheduled' then 99 + 22 end,
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+                end,
                case when i.trr <> '' then i.trr::decimal else 0 end,
                case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
                case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
@@ -109,7 +114,7 @@ BEGIN
     where i."importId" = provided_import_id
       and rtrim(opportunity_status) <> ''
       and ow.week_minus_2 is not null
-      and aw.week <> 99
+      and aw.week not in (99, 100, 101)
     group by ow.week_minus_2
     ;
 
@@ -123,7 +128,9 @@ BEGIN
         select case when i.install_date <> '' then i.install_date::date end,
                case
                    when i.install_date <> '' then date_part('week', i.install_date::date)
-                   when i.opportunity_status = 'Pending - Install Not Scheduled' then 99 + 22 end,
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+                end,
                case when i.trr <> '' then i.trr::decimal else 0 end,
                case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
                case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
@@ -143,7 +150,7 @@ BEGIN
     where i."importId" = provided_import_id
       and rtrim(opportunity_status) <> ''
       and ow.week_minus_3 is not null
-      and aw.week <> 99
+      and aw.week not in (99, 100, 101)
     group by ow.week_minus_3
     ;
 
@@ -157,7 +164,9 @@ BEGIN
         select case when i.install_date <> '' then i.install_date::date end,
                case
                    when i.install_date <> '' then date_part('week', i.install_date::date)
-                   when i.opportunity_status = 'Pending - Install Not Scheduled' then 99 + 22 end,
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+                end,
                case when i.trr <> '' then i.trr::decimal else 0 end,
                case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
                case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
@@ -177,14 +186,53 @@ BEGIN
     where i."importId" = provided_import_id
       and rtrim(opportunity_status) <> ''
       and aw.week is not null
-      and aw.week <> 99
+      and aw.week not in (99, 100, 101)
+    group by aw.week
+    ;
+    
+    -- pending totals
+    insert into weekSums (week, amount, amountType)
+    select aw.week,
+           sum(w.power_add),
+           'poweradd'
+    from cintas_install_calendar i
+             inner join lateral (
+        select case when i.install_date <> '' then i.install_date::date end,
+               case
+                   when i.install_date <> '' then date_part('week', i.install_date::date)
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'FS' then 100 + 22
+                   when i.opportunity_status = 'Pending - Install Not Scheduled' and type = 'UR' then 99 + 22
+                end,
+               case when i.trr <> '' then i.trr::decimal else 0 end,
+               case when i.paper_chem_wk1 <> '' then i.paper_chem_wk1::decimal else 0 end,
+               case when i.paper_chem_wk2 <> '' then i.paper_chem_wk2::decimal else 0 end,
+               case when i.paper_chem_wk3 <> '' then i.paper_chem_wk3::decimal else 0 end,
+               case when i.paper_chem_wk4 <> '' then i.paper_chem_wk4::decimal else 0 end,
+               case when i.power_add <> '' then i.power_add::decimal else 0 end
+        ) w (install_date, week, trr, paper_chem_wk1, paper_chem_wk2, paper_chem_wk3, paper_chem_wk4, power_add) on true
+             inner join lateral (
+        select case when w.week is null then null when w.week >= 23 then w.week - 22 else w.week + 30 end,
+               w.trr + w.paper_chem_wk1
+        ) aw (week, week_sum) on true
+             inner join lateral (
+        select case when aw.week > 1 then aw.week + 1 end,
+               case when aw.week > 2 then aw.week + 2 end,
+               case when aw.week > 3 then aw.week + 3 end
+        ) ow (week_minus_1, week_minus_2, week_minus_3) on true
+    where i."importId" = provided_import_id
+      and rtrim(opportunity_status) <> ''
+      and aw.week is not null
+      and aw.week not in (99, 100, 101)
     group by aw.week
     ;
 
     insert into cintas_intall_calendar_summary ("importId", week, "trrTotal", "fourWkAverages", "trrPlus4Wk", "powerAdds", "weekId", "createdAt", "updatedAt")
     select distinct
         provided_import_id,
-        case when t.week = 99 then 'Pending - Install Not Scheduled' else concat('Week ', t.week::varchar(100)) end "Week",
+        case when t.week = 100 then 'Pending - FS'
+            when t.week = 99 then 'Pending - UR'
+            else concat('Week ', t.week::varchar(100))
+        end "Week",
         cast(sum(case when t.amountType <> 'poweradd' and t.amountType = 'trr4wk' then t.amount else 0 end) over (partition by t.week) as decimal(9,0)) "TRR Total",
         cast(sum(case when t.amountType <> 'poweradd' and t.amountType <> 'trr4wk' then t.amount else 0 end) over (partition by t.week) as decimal(9,0)) "4WK Averages",
         cast(sum(case when t.amountType <> 'poweradd' then t.amount else 0 end) over (partition by t.week) as decimal(9,0)) "TRR + 4WK",
@@ -193,7 +241,21 @@ BEGIN
         now(),
         now()
     from weekSums t
-    order by t.week desc
+    ;
+    
+    insert into cintas_intall_calendar_summary ("importId", week, "trrTotal", "fourWkAverages", "trrPlus4Wk", "powerAdds", "weekId", "createdAt", "updatedAt")
+    select provided_import_id,
+        'Pending - Total' "Week",
+        sum(s."trrTotal") "TRR Total",
+        sum(s."fourWkAverages") "4WK Averages",
+        sum(s."trrPlus4Wk") "TRR + 4WK",
+        sum(s."powerAdds") "Power Adds",
+        101 "weekId",
+        now(),
+        now()
+    from cintas_intall_calendar_summary s
+    where "importId" = provided_import_id
+    and "weekId" in (99, 100)
     ;
 
     drop table weekSums;