andrewdwallo / erpsaas

A Laravel and Filament-powered accounting platform, crafting a modern and automated solution for financial management.
MIT License
580 stars 166 forks source link

Adding new Categories when creating new company #40

Closed paulmercs closed 3 months ago

paulmercs commented 3 months ago

Where can I find the file or codes for adding default categories when creating new company?

private function createCategories(Company $company, User $user): array { $incomeCategories = ['Other Charges', 'Sales', 'General Income', 'Interest Income', 'Late Fee Income', 'Discount', 'Shipping Charge']; $expenseCategories = ['Lodging', 'Purchase Discount', 'Office Supplies', 'Advertising and Marketing', 'Bank Fees and Charges', 'Credit Card Charges', 'Travel Expense', 'Telephone Expense', 'Automobile Expense', 'IT and Internet Expenses', 'Rent Expense', 'Janitorial Expense', 'Postage', 'Bad Debt', 'Printing and Stationery', 'Uncategorized', 'Salaries and Employee Wages', 'Meals and Entertainment', 'Depreciation Expense', 'Consultant Expense', 'Repair and Maintenance', 'Other Expenses', 'Cost of Goods Sold', 'Exchange Gain or Loss']; $assetsCategories = ['Prepaid Expenses', 'Advance Tax', 'Employee Advance', 'Undeposited Funds', 'Petty Cash', 'Accounts Receivable', 'Furniture and Equipment', 'Inventory Asset']; $liabilityCategories = ['Tax Payable', 'Unearned Revenue', 'Opening Balance Adjustments', 'Employee Reimbursements', 'Accounts Payable', 'Dimension Adjustments']; $equityCategories = ['Retained Earnings', 'Owner\'s Equity', 'Opening Balance Offset', 'Drawings'];

    $shuffledCategories = [
        ...array_map(static fn ($name) => ['name' => $name, 'type' => CategoryType::Income->value], $incomeCategories),
        ...array_map(static fn ($name) => ['name' => $name, 'type' => CategoryType::Expense->value], $expenseCategories),
        ...array_map(static fn ($name) => ['name' => $name, 'type' => CategoryType::Assets->value], $assetsCategories),
        ...array_map(static fn ($name) => ['name' => $name, 'type' => CategoryType::Liability->value], $liabilityCategories),
        ...array_map(static fn ($name) => ['name' => $name, 'type' => CategoryType::Equity->value], $equityCategories),
    ];

    shuffle($shuffledCategories);

    $incomeEnabled = $expenseEnabled = false;

    $enabledIncomeCategoryId = null;
    $enabledExpenseCategoryId = null;

    foreach ($shuffledCategories as $category) {
        $enabled = false;
        if (! $incomeEnabled && $category['type'] === CategoryType::Income->value) {
            $enabled = $incomeEnabled = true;
        } elseif (! $expenseEnabled && $category['type'] === CategoryType::Expense->value) {
            $enabled = $expenseEnabled = true;
        }

        $categoryModel = Category::factory()->create([
            'company_id' => $company->id,
            'name' => $category['name'],
            'type' => $category['type'],
            'enabled' => $enabled,
            'created_by' => $user->id,
            'updated_by' => $user->id,
        ]);

        if ($enabled && $category['type'] === CategoryType::Income->value) {
            $enabledIncomeCategoryId = $categoryModel->id;
        } elseif ($enabled && $category['type'] === CategoryType::Expense->value) {
            $enabledExpenseCategoryId = $categoryModel->id;
        }
    }

    return [
        'income_category_id' => $enabledIncomeCategoryId,
        'expense_category_id' => $enabledExpenseCategoryId,
    ];
}
andrewdwallo commented 3 months ago

This is the file and the code. The default category is generated randomly here. The category logic will all be replaced in the next release anyway by the way.

paulmercs commented 3 months ago

Hi andrewdwallo, when will you release the next version? I am just excited with the new features 💯

andrewdwallo commented 3 months ago

@paulmercs Hey! I'm glad you are excited, and you should be. The new release will offer many new features. I am currently still working on it but you can test it out if you like: https://github.com/andrewdwallo/erpsaas/tree/release-candidate-2.x

Please keep in mind that not everything is guaranteed to work but it should for the most part.

andrewdwallo commented 3 months ago

Closing this as this is not an issue but rather a general inquiry. Please create a discussion post next time.