07‐ Redux State Shape - mina-y-khalil/redeembooks-accounting-app GitHub Wiki

🗂️ Redux State Shape

Redux State Shape

The Redux state for the RedeemBooks Accounting App is designed to manage complex multi-company accounting data.
It is normalized to avoid redundancy, improve performance, and simplify data retrieval and updates.


📌 State Structure

{
   session: {
      user: {
         id: 1,
         username: "Demo",
         email: "[email protected]",
         roles: ["Owner", "Approver"],
         companies: [1, 2]
      },
      activeCompanyId: 1
   },

   companies: {
      1: {
         id: 1,
         name: "Redeem Innovations LLC",
         tax_id: "12-3456789",
         address: {
            street: "123 Main St",
            city: "San Ramon",
            state: "CA",
            zipcode: "94583"
         },
         phone: "555-1234",
         email: "[email protected]",
         users: [1, 2, 3],
         approvers: [2],
         bank_balances: [1],
         categories: [1, 2],
         vendors: [1, 2],
         invoices: [1, 2],
         payments: [1, 2],
         batches: [1],
         audit_logs: [1, 2]
      }
   },

   users: {
      1: { id: 1, username: "Demo Owner", email: "[email protected]", role: "Owner" },
      2: { id: 2, username: "Manager1", email: "[email protected]", role: "Manager" },
      3: { id: 3, username: "Staff1", email: "[email protected]", role: "Staff" }
   },

   vendors: {
      1: {
         id: 1,
         company_id: 1,
         name: "Vendor A",
         contact_name: "John Smith",
         email: "[email protected]",
         phone: "555-5678",
         preferred_payment_method: "ACH",
         payment_terms: "Net 30",
         w9_document_url: "/docs/w9-vendorA.pdf",
         invoices: [1, 2],
         payments: [1]
      }
   },

   categories: {
      1: { id: 1, company_id: 1, name: "Office Supplies", description: "Stationery and equipment" },
      2: { id: 2, company_id: 1, name: "Utilities", description: "Electricity, Water, Internet" }
   },

   invoices: {
      1: {
         id: 1,
         company_id: 1,
         vendor_id: 1,
         category_id: 1,
         invoice_number: "INV-1001",
         invoice_date: "2025-07-01",
         voucher_date: "2025-07-03",
         due_date: "2025-07-30",
         amount: 1200.50,
         status: "approved",
         approved_by: 2,
         approval_date: "2025-07-05",
         description: "Office chairs purchase",
         attachment_url: "/invoices/INV-1001.pdf",
         payments: [1]
      }
   },

   payments: {
      1: {
         id: 1,
         company_id: 1,
         invoice_id: 1,
         vendor_id: 1,
         user_id: 1,
         payment_date: "2025-07-10",
         amount: 600.25,
         method: "ACH",
         reference_number: "PAY-001",
         batch_id: 1,
         notes: "Partial payment"
      }
   },

   batches: {
      1: {
         id: 1,
         company_id: 1,
         user_id: 1,
         batch_date: "2025-07-15",
         total_amount: 600.25,
         scheduled_for: "2025-07-20",
         status: "scheduled",
         payments: [1]
      }
   },

   bank_balances: {
      1: {
         id: 1,
         company_id: 1,
         balance: 10000.00,
         effective_date: "2025-07-10"
      }
   },

   audit_logs: {
      1: {
         id: 1,
         company_id: 1,
         user_id: 1,
         action: "APPROVE_INVOICE",
         table_name: "invoices",
         record_id: 1,
         old_data: "{ status: 'pending' }",
         new_data: "{ status: 'approved' }",
         created_at: "2025-07-05T10:00:00Z"
      }
   },

   ui: {
      loading: false,
      error: null,
      notifications: [
         { id: 1, type: "approval", message: "Invoice INV-1001 awaiting approval" }
      ]
   }
}
⚠️ **GitHub.com Fallback** ⚠️