Container Accounting Management
This commit is contained in:
parent
33850550a6
commit
ecb32cf6cf
7 changed files with 650 additions and 798 deletions
|
|
@ -1,64 +1,61 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from 'react'
|
||||||
import BankManagement from "./components/BankManagement";
|
import BankManagement from './components/BankManagement'
|
||||||
import BankAccountForm from "./components/BankAccountForm";
|
import BankAccountForm from './components/BankAccountForm'
|
||||||
import BankMovementForm from "./components/BankMovementForm";
|
import BankMovementForm from './components/BankMovementForm'
|
||||||
import BankAccountDetails from "./components/BankAccountDetails";
|
import BankAccountDetails from './components/BankAccountDetails'
|
||||||
import {
|
import {
|
||||||
FiBankMovement,
|
FiBankMovement,
|
||||||
BankAccountTypeEnum,
|
BankAccountTypeEnum,
|
||||||
BankTransactionTypeEnum,
|
BankTransactionTypeEnum,
|
||||||
TransactionStatusEnum,
|
TransactionStatusEnum,
|
||||||
} from "../../types/fi";
|
} from '../../types/fi'
|
||||||
import { mockBanks } from "../../mocks/mockBanks";
|
import { mockBanks } from '../../mocks/mockBanks'
|
||||||
import { mockBankMovements } from "../../mocks/mockBankMovements";
|
import { mockBankMovements } from '../../mocks/mockBankMovements'
|
||||||
import { BankAccount } from "../../types/common";
|
import { BankAccount } from '../../types/common'
|
||||||
|
import { Container } from '@/components/shared'
|
||||||
|
|
||||||
const BankPage: React.FC = () => {
|
const BankPage: React.FC = () => {
|
||||||
const [bankAccounts, setBankAccounts] = useState<BankAccount[]>(mockBanks);
|
const [bankAccounts, setBankAccounts] = useState<BankAccount[]>(mockBanks)
|
||||||
const [bankMovements, setBankMovements] = useState<FiBankMovement[]>([]);
|
const [bankMovements, setBankMovements] = useState<FiBankMovement[]>([])
|
||||||
|
|
||||||
// Initialize bank movements after bank accounts are set
|
// Initialize bank movements after bank accounts are set
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bankAccounts.length > 0) {
|
if (bankAccounts.length > 0) {
|
||||||
setBankMovements(mockBankMovements);
|
setBankMovements(mockBankMovements)
|
||||||
}
|
}
|
||||||
}, [bankAccounts]);
|
}, [bankAccounts])
|
||||||
|
|
||||||
// Modal states
|
// Modal states
|
||||||
const [isAccountFormOpen, setIsAccountFormOpen] = useState(false);
|
const [isAccountFormOpen, setIsAccountFormOpen] = useState(false)
|
||||||
const [isMovementFormOpen, setIsMovementFormOpen] = useState(false);
|
const [isMovementFormOpen, setIsMovementFormOpen] = useState(false)
|
||||||
const [isAccountDetailsOpen, setIsAccountDetailsOpen] = useState(false);
|
const [isAccountDetailsOpen, setIsAccountDetailsOpen] = useState(false)
|
||||||
const [selectedAccount, setSelectedAccount] = useState<
|
const [selectedAccount, setSelectedAccount] = useState<BankAccount | undefined>(undefined)
|
||||||
BankAccount | undefined
|
const [selectedMovement, setSelectedMovement] = useState<FiBankMovement | undefined>(undefined)
|
||||||
>(undefined);
|
|
||||||
const [selectedMovement, setSelectedMovement] = useState<
|
|
||||||
FiBankMovement | undefined
|
|
||||||
>(undefined);
|
|
||||||
|
|
||||||
const handleAddAccount = () => {
|
const handleAddAccount = () => {
|
||||||
setSelectedAccount(undefined);
|
setSelectedAccount(undefined)
|
||||||
setIsAccountFormOpen(true);
|
setIsAccountFormOpen(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditAccount = (account: BankAccount) => {
|
const handleEditAccount = (account: BankAccount) => {
|
||||||
setSelectedAccount(account);
|
setSelectedAccount(account)
|
||||||
setIsAccountFormOpen(true);
|
setIsAccountFormOpen(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleAddMovement = () => {
|
const handleAddMovement = () => {
|
||||||
setSelectedMovement(undefined);
|
setSelectedMovement(undefined)
|
||||||
setIsMovementFormOpen(true);
|
setIsMovementFormOpen(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditMovement = (movement: FiBankMovement) => {
|
const handleEditMovement = (movement: FiBankMovement) => {
|
||||||
setSelectedMovement(movement);
|
setSelectedMovement(movement)
|
||||||
setIsMovementFormOpen(true);
|
setIsMovementFormOpen(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleViewDetails = (account: BankAccount) => {
|
const handleViewDetails = (account: BankAccount) => {
|
||||||
setSelectedAccount(account);
|
setSelectedAccount(account)
|
||||||
setIsAccountDetailsOpen(true);
|
setIsAccountDetailsOpen(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveAccount = (accountData: Partial<BankAccount>) => {
|
const handleSaveAccount = (accountData: Partial<BankAccount>) => {
|
||||||
if (selectedAccount) {
|
if (selectedAccount) {
|
||||||
|
|
@ -67,20 +64,20 @@ const BankPage: React.FC = () => {
|
||||||
prev.map((acc) =>
|
prev.map((acc) =>
|
||||||
acc.id === selectedAccount.id
|
acc.id === selectedAccount.id
|
||||||
? { ...acc, ...accountData, lastModificationTime: new Date() }
|
? { ...acc, ...accountData, lastModificationTime: new Date() }
|
||||||
: acc
|
: acc,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
} else {
|
} else {
|
||||||
// Add new account
|
// Add new account
|
||||||
const newAccount: BankAccount = {
|
const newAccount: BankAccount = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
accountCode: accountData.accountCode || "",
|
accountCode: accountData.accountCode || '',
|
||||||
bankName: accountData.bankName || "",
|
bankName: accountData.bankName || '',
|
||||||
branchName: accountData.branchName || "",
|
branchName: accountData.branchName || '',
|
||||||
accountNumber: accountData.accountNumber || "",
|
accountNumber: accountData.accountNumber || '',
|
||||||
iban: accountData.iban || "",
|
iban: accountData.iban || '',
|
||||||
accountType: accountData.accountType || BankAccountTypeEnum.Current,
|
accountType: accountData.accountType || BankAccountTypeEnum.Current,
|
||||||
currency: accountData.currency || "TRY",
|
currency: accountData.currency || 'TRY',
|
||||||
balance: accountData.balance || 0,
|
balance: accountData.balance || 0,
|
||||||
overdraftLimit: accountData.overdraftLimit || 0,
|
overdraftLimit: accountData.overdraftLimit || 0,
|
||||||
dailyTransferLimit: accountData.dailyTransferLimit || 0,
|
dailyTransferLimit: accountData.dailyTransferLimit || 0,
|
||||||
|
|
@ -90,66 +87,61 @@ const BankPage: React.FC = () => {
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
isDefault: false,
|
isDefault: false,
|
||||||
};
|
}
|
||||||
setBankAccounts((prev) => [...prev, newAccount]);
|
setBankAccounts((prev) => [...prev, newAccount])
|
||||||
}
|
}
|
||||||
setIsAccountFormOpen(false);
|
setIsAccountFormOpen(false)
|
||||||
setSelectedAccount(undefined);
|
setSelectedAccount(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveMovement = (movementData: Partial<FiBankMovement>) => {
|
const handleSaveMovement = (movementData: Partial<FiBankMovement>) => {
|
||||||
if (selectedMovement) {
|
if (selectedMovement) {
|
||||||
// Update existing movement
|
// Update existing movement
|
||||||
setBankMovements((prev) =>
|
setBankMovements((prev) =>
|
||||||
prev.map((mov) =>
|
prev.map((mov) => (mov.id === selectedMovement.id ? { ...mov, ...movementData } : mov)),
|
||||||
mov.id === selectedMovement.id ? { ...mov, ...movementData } : mov
|
)
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Add new movement
|
// Add new movement
|
||||||
const bankAccount = bankAccounts.find(
|
const bankAccount = bankAccounts.find((acc) => acc.id === movementData.bankAccountId)
|
||||||
(acc) => acc.id === movementData.bankAccountId
|
|
||||||
);
|
|
||||||
const newMovement: FiBankMovement = {
|
const newMovement: FiBankMovement = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
bankAccountId: movementData.bankAccountId || "",
|
bankAccountId: movementData.bankAccountId || '',
|
||||||
bankAccount: bankAccount,
|
bankAccount: bankAccount,
|
||||||
transactionDate: movementData.transactionDate || new Date(),
|
transactionDate: movementData.transactionDate || new Date(),
|
||||||
valueDate: movementData.valueDate || new Date(),
|
valueDate: movementData.valueDate || new Date(),
|
||||||
description: movementData.description || "",
|
description: movementData.description || '',
|
||||||
referenceNumber: movementData.referenceNumber,
|
referenceNumber: movementData.referenceNumber,
|
||||||
transactionType:
|
transactionType: movementData.transactionType || BankTransactionTypeEnum.Deposit,
|
||||||
movementData.transactionType || BankTransactionTypeEnum.Deposit,
|
|
||||||
amount: movementData.amount || 0,
|
amount: movementData.amount || 0,
|
||||||
currency: movementData.currency || "TRY",
|
currency: movementData.currency || 'TRY',
|
||||||
recipientName: movementData.recipientName,
|
recipientName: movementData.recipientName,
|
||||||
recipientIban: movementData.recipientIban,
|
recipientIban: movementData.recipientIban,
|
||||||
recipientBank: movementData.recipientBank,
|
recipientBank: movementData.recipientBank,
|
||||||
currentAccountId: movementData.currentAccountId,
|
currentAccountId: movementData.currentAccountId,
|
||||||
status: movementData.status || TransactionStatusEnum.Pending,
|
status: movementData.status || TransactionStatusEnum.Pending,
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
};
|
}
|
||||||
setBankMovements((prev) => [...prev, newMovement]);
|
setBankMovements((prev) => [...prev, newMovement])
|
||||||
|
|
||||||
// Update account balance
|
// Update account balance
|
||||||
if (bankAccount) {
|
if (bankAccount) {
|
||||||
const isIncoming = [
|
const isIncoming = [
|
||||||
BankTransactionTypeEnum.Deposit,
|
BankTransactionTypeEnum.Deposit,
|
||||||
BankTransactionTypeEnum.Interest,
|
BankTransactionTypeEnum.Interest,
|
||||||
].includes(newMovement.transactionType);
|
].includes(newMovement.transactionType)
|
||||||
const isOutgoing = [
|
const isOutgoing = [
|
||||||
BankTransactionTypeEnum.Withdrawal,
|
BankTransactionTypeEnum.Withdrawal,
|
||||||
BankTransactionTypeEnum.Transfer,
|
BankTransactionTypeEnum.Transfer,
|
||||||
BankTransactionTypeEnum.EFT,
|
BankTransactionTypeEnum.EFT,
|
||||||
BankTransactionTypeEnum.Fee,
|
BankTransactionTypeEnum.Fee,
|
||||||
].includes(newMovement.transactionType);
|
].includes(newMovement.transactionType)
|
||||||
|
|
||||||
if (newMovement.status === TransactionStatusEnum.Completed) {
|
if (newMovement.status === TransactionStatusEnum.Completed) {
|
||||||
const balanceChange = isIncoming
|
const balanceChange = isIncoming
|
||||||
? newMovement.amount
|
? newMovement.amount
|
||||||
: isOutgoing
|
: isOutgoing
|
||||||
? -newMovement.amount
|
? -newMovement.amount
|
||||||
: 0;
|
: 0
|
||||||
setBankAccounts((prev) =>
|
setBankAccounts((prev) =>
|
||||||
prev.map((acc) =>
|
prev.map((acc) =>
|
||||||
acc.id === bankAccount.id
|
acc.id === bankAccount.id
|
||||||
|
|
@ -158,18 +150,18 @@ const BankPage: React.FC = () => {
|
||||||
balance: acc.balance + balanceChange,
|
balance: acc.balance + balanceChange,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: acc
|
: acc,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setIsMovementFormOpen(false);
|
setIsMovementFormOpen(false)
|
||||||
setSelectedMovement(undefined);
|
setSelectedMovement(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Container>
|
||||||
<BankManagement
|
<BankManagement
|
||||||
bankAccounts={bankAccounts}
|
bankAccounts={bankAccounts}
|
||||||
bankMovements={bankMovements}
|
bankMovements={bankMovements}
|
||||||
|
|
@ -185,8 +177,8 @@ const BankPage: React.FC = () => {
|
||||||
account={selectedAccount}
|
account={selectedAccount}
|
||||||
isOpen={isAccountFormOpen}
|
isOpen={isAccountFormOpen}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setIsAccountFormOpen(false);
|
setIsAccountFormOpen(false)
|
||||||
setSelectedAccount(undefined);
|
setSelectedAccount(undefined)
|
||||||
}}
|
}}
|
||||||
onSave={handleSaveAccount}
|
onSave={handleSaveAccount}
|
||||||
/>
|
/>
|
||||||
|
|
@ -197,8 +189,8 @@ const BankPage: React.FC = () => {
|
||||||
bankAccounts={bankAccounts}
|
bankAccounts={bankAccounts}
|
||||||
isOpen={isMovementFormOpen}
|
isOpen={isMovementFormOpen}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setIsMovementFormOpen(false);
|
setIsMovementFormOpen(false)
|
||||||
setSelectedMovement(undefined);
|
setSelectedMovement(undefined)
|
||||||
}}
|
}}
|
||||||
onSave={handleSaveMovement}
|
onSave={handleSaveMovement}
|
||||||
/>
|
/>
|
||||||
|
|
@ -210,17 +202,17 @@ const BankPage: React.FC = () => {
|
||||||
movements={bankMovements}
|
movements={bankMovements}
|
||||||
isOpen={isAccountDetailsOpen}
|
isOpen={isAccountDetailsOpen}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setIsAccountDetailsOpen(false);
|
setIsAccountDetailsOpen(false)
|
||||||
setSelectedAccount(undefined);
|
setSelectedAccount(undefined)
|
||||||
}}
|
}}
|
||||||
onEdit={(account) => {
|
onEdit={(account) => {
|
||||||
setIsAccountDetailsOpen(false);
|
setIsAccountDetailsOpen(false)
|
||||||
handleEditAccount(account);
|
handleEditAccount(account)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</Container>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default BankPage;
|
export default BankPage
|
||||||
|
|
|
||||||
|
|
@ -1,91 +1,78 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from 'react'
|
||||||
import CashManagement from "./components/CashManagement";
|
import CashManagement from './components/CashManagement'
|
||||||
import CashAccountForm from "./components/CashAccountForm";
|
import CashAccountForm from './components/CashAccountForm'
|
||||||
import CashMovementForm from "./components/CashMovementForm";
|
import CashMovementForm from './components/CashMovementForm'
|
||||||
import CashAccountDetails from "./components/CashAccountDetails";
|
import CashAccountDetails from './components/CashAccountDetails'
|
||||||
import {
|
import { FiCashAccount, FiCashMovement, CashMovementTypeEnum } from '../../types/fi'
|
||||||
FiCashAccount,
|
import { mockCashAccounts } from '../../mocks/mockCashAccounts'
|
||||||
FiCashMovement,
|
import { mockCashMovements } from '../../mocks/mockCashMovements'
|
||||||
CashMovementTypeEnum,
|
import { Container } from '@/components/shared'
|
||||||
} from "../../types/fi";
|
|
||||||
import { mockCashAccounts } from "../../mocks/mockCashAccounts";
|
|
||||||
import { mockCashMovements } from "../../mocks/mockCashMovements";
|
|
||||||
|
|
||||||
const CashPage: React.FC = () => {
|
const CashPage: React.FC = () => {
|
||||||
const [showAccountForm, setShowAccountForm] = useState(false);
|
const [showAccountForm, setShowAccountForm] = useState(false)
|
||||||
const [showMovementForm, setShowMovementForm] = useState(false);
|
const [showMovementForm, setShowMovementForm] = useState(false)
|
||||||
const [showAccountDetails, setShowAccountDetails] = useState(false);
|
const [showAccountDetails, setShowAccountDetails] = useState(false)
|
||||||
const [editingAccount, setEditingAccount] = useState<
|
const [editingAccount, setEditingAccount] = useState<FiCashAccount | undefined>()
|
||||||
FiCashAccount | undefined
|
const [editingMovement, setEditingMovement] = useState<FiCashMovement | undefined>()
|
||||||
>();
|
const [viewingAccount, setViewingAccount] = useState<FiCashAccount | undefined>()
|
||||||
const [editingMovement, setEditingMovement] = useState<
|
const [cashAccounts, setCashAccounts] = useState(mockCashAccounts)
|
||||||
FiCashMovement | undefined
|
const [cashMovements, setCashMovements] = useState(mockCashMovements)
|
||||||
>();
|
|
||||||
const [viewingAccount, setViewingAccount] = useState<
|
|
||||||
FiCashAccount | undefined
|
|
||||||
>();
|
|
||||||
const [cashAccounts, setCashAccounts] = useState(mockCashAccounts);
|
|
||||||
const [cashMovements, setCashMovements] = useState(mockCashMovements);
|
|
||||||
|
|
||||||
const handleAddAccount = () => {
|
const handleAddAccount = () => {
|
||||||
setEditingAccount(undefined);
|
setEditingAccount(undefined)
|
||||||
setShowAccountForm(true);
|
setShowAccountForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditAccount = (account: FiCashAccount) => {
|
const handleEditAccount = (account: FiCashAccount) => {
|
||||||
setEditingAccount(account);
|
setEditingAccount(account)
|
||||||
setShowAccountForm(true);
|
setShowAccountForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveAccount = (accountData: Omit<FiCashAccount, "id">) => {
|
const handleSaveAccount = (accountData: Omit<FiCashAccount, 'id'>) => {
|
||||||
if (editingAccount) {
|
if (editingAccount) {
|
||||||
// Update existing account
|
// Update existing account
|
||||||
setCashAccounts((prev) =>
|
setCashAccounts((prev) =>
|
||||||
prev.map((acc) =>
|
prev.map((acc) =>
|
||||||
acc.id === editingAccount.id
|
acc.id === editingAccount.id ? { ...accountData, id: editingAccount.id } : acc,
|
||||||
? { ...accountData, id: editingAccount.id }
|
),
|
||||||
: acc
|
)
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Add new account
|
// Add new account
|
||||||
const newAccount: FiCashAccount = {
|
const newAccount: FiCashAccount = {
|
||||||
...accountData,
|
...accountData,
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
};
|
}
|
||||||
setCashAccounts((prev) => [...prev, newAccount]);
|
setCashAccounts((prev) => [...prev, newAccount])
|
||||||
}
|
}
|
||||||
setShowAccountForm(false);
|
setShowAccountForm(false)
|
||||||
setEditingAccount(undefined);
|
setEditingAccount(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleAddMovement = () => {
|
const handleAddMovement = () => {
|
||||||
setEditingMovement(undefined);
|
setEditingMovement(undefined)
|
||||||
setShowMovementForm(true);
|
setShowMovementForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditMovement = (movement: FiCashMovement) => {
|
const handleEditMovement = (movement: FiCashMovement) => {
|
||||||
setEditingMovement(movement);
|
setEditingMovement(movement)
|
||||||
setShowMovementForm(true);
|
setShowMovementForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveMovement = (movementData: Omit<FiCashMovement, "id">) => {
|
const handleSaveMovement = (movementData: Omit<FiCashMovement, 'id'>) => {
|
||||||
if (editingMovement) {
|
if (editingMovement) {
|
||||||
// Update existing movement
|
// Update existing movement
|
||||||
setCashMovements((prev) =>
|
setCashMovements((prev) =>
|
||||||
prev.map((mov) =>
|
prev.map((mov) =>
|
||||||
mov.id === editingMovement.id
|
mov.id === editingMovement.id ? { ...movementData, id: editingMovement.id } : mov,
|
||||||
? { ...movementData, id: editingMovement.id }
|
),
|
||||||
: mov
|
)
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Add new movement
|
// Add new movement
|
||||||
const newMovement: FiCashMovement = {
|
const newMovement: FiCashMovement = {
|
||||||
...movementData,
|
...movementData,
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
};
|
}
|
||||||
setCashMovements((prev) => [...prev, newMovement]);
|
setCashMovements((prev) => [...prev, newMovement])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cash account balance
|
// Update cash account balance
|
||||||
|
|
@ -96,44 +83,44 @@ const CashPage: React.FC = () => {
|
||||||
const balanceChange =
|
const balanceChange =
|
||||||
movementData.movementType === CashMovementTypeEnum.Income
|
movementData.movementType === CashMovementTypeEnum.Income
|
||||||
? movementData.amount
|
? movementData.amount
|
||||||
: -movementData.amount;
|
: -movementData.amount
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
balance: acc.balance + balanceChange,
|
balance: acc.balance + balanceChange,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
return acc;
|
return acc
|
||||||
})
|
}),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
setShowMovementForm(false);
|
setShowMovementForm(false)
|
||||||
setEditingMovement(undefined);
|
setEditingMovement(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleViewDetails = (account: FiCashAccount) => {
|
const handleViewDetails = (account: FiCashAccount) => {
|
||||||
setViewingAccount(account);
|
setViewingAccount(account)
|
||||||
setShowAccountDetails(true);
|
setShowAccountDetails(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCloseAccountForm = () => {
|
const handleCloseAccountForm = () => {
|
||||||
setShowAccountForm(false);
|
setShowAccountForm(false)
|
||||||
setEditingAccount(undefined);
|
setEditingAccount(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCloseMovementForm = () => {
|
const handleCloseMovementForm = () => {
|
||||||
setShowMovementForm(false);
|
setShowMovementForm(false)
|
||||||
setEditingMovement(undefined);
|
setEditingMovement(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCloseAccountDetails = () => {
|
const handleCloseAccountDetails = () => {
|
||||||
setShowAccountDetails(false);
|
setShowAccountDetails(false)
|
||||||
setViewingAccount(undefined);
|
setViewingAccount(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Container>
|
||||||
<CashManagement
|
<CashManagement
|
||||||
cashAccounts={cashAccounts}
|
cashAccounts={cashAccounts}
|
||||||
cashMovements={cashMovements}
|
cashMovements={cashMovements}
|
||||||
|
|
@ -172,13 +159,13 @@ const CashPage: React.FC = () => {
|
||||||
movements={cashMovements}
|
movements={cashMovements}
|
||||||
onClose={handleCloseAccountDetails}
|
onClose={handleCloseAccountDetails}
|
||||||
onEdit={(account) => {
|
onEdit={(account) => {
|
||||||
setShowAccountDetails(false);
|
setShowAccountDetails(false)
|
||||||
handleEditAccount(account);
|
handleEditAccount(account)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</Container>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default CashPage;
|
export default CashPage
|
||||||
|
|
|
||||||
|
|
@ -1,79 +1,64 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from 'react'
|
||||||
import CheckNoteManagement from "./components/CheckNoteManagement";
|
import CheckNoteManagement from './components/CheckNoteManagement'
|
||||||
import {
|
import { FiCheck, PromissoryNote, CheckStatusEnum, NoteStatusEnum } from '../../types/fi'
|
||||||
FiCheck,
|
import { mockChecks } from '../../mocks/mockChecks'
|
||||||
PromissoryNote,
|
import { mockPromissoryNotes } from '../../mocks/mockPromissoryNotes'
|
||||||
CheckStatusEnum,
|
import { mockCurrentAccounts } from '../../mocks/mockCurrentAccounts'
|
||||||
NoteStatusEnum,
|
import { Container } from '@/components/shared'
|
||||||
} from "../../types/fi";
|
|
||||||
import { mockChecks } from "../../mocks/mockChecks";
|
|
||||||
import { mockPromissoryNotes } from "../../mocks/mockPromissoryNotes";
|
|
||||||
import { mockCurrentAccounts } from "../../mocks/mockCurrentAccounts";
|
|
||||||
|
|
||||||
const CheckNotePage: React.FC = () => {
|
const CheckNotePage: React.FC = () => {
|
||||||
const [checks, setChecks] = useState<FiCheck[]>(mockChecks);
|
const [checks, setChecks] = useState<FiCheck[]>(mockChecks)
|
||||||
const [promissoryNotes, setPromissoryNotes] =
|
const [promissoryNotes, setPromissoryNotes] = useState<PromissoryNote[]>(mockPromissoryNotes)
|
||||||
useState<PromissoryNote[]>(mockPromissoryNotes);
|
|
||||||
|
|
||||||
const handleAddCheck = (
|
const handleAddCheck = (
|
||||||
checkData: Omit<FiCheck, "id" | "creationTime" | "lastModificationTime">
|
checkData: Omit<FiCheck, 'id' | 'creationTime' | 'lastModificationTime'>,
|
||||||
) => {
|
) => {
|
||||||
const newCheck: FiCheck = {
|
const newCheck: FiCheck = {
|
||||||
...checkData,
|
...checkData,
|
||||||
id: `check_${Date.now()}`,
|
id: `check_${Date.now()}`,
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
};
|
}
|
||||||
setChecks((prev) => [...prev, newCheck]);
|
setChecks((prev) => [...prev, newCheck])
|
||||||
console.log("Check added:", newCheck);
|
console.log('Check added:', newCheck)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditCheck = (
|
const handleEditCheck = (
|
||||||
id: string,
|
id: string,
|
||||||
checkData: Omit<FiCheck, "id" | "creationTime" | "lastModificationTime">
|
checkData: Omit<FiCheck, 'id' | 'creationTime' | 'lastModificationTime'>,
|
||||||
) => {
|
) => {
|
||||||
setChecks((prev) =>
|
setChecks((prev) =>
|
||||||
prev.map((check) =>
|
prev.map((check) =>
|
||||||
check.id === id
|
check.id === id ? { ...check, ...checkData, lastModificationTime: new Date() } : check,
|
||||||
? { ...check, ...checkData, lastModificationTime: new Date() }
|
),
|
||||||
: check
|
)
|
||||||
)
|
console.log('Check updated:', id, checkData)
|
||||||
);
|
}
|
||||||
console.log("Check updated:", id, checkData);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAddNote = (
|
const handleAddNote = (
|
||||||
noteData: Omit<
|
noteData: Omit<PromissoryNote, 'id' | 'creationTime' | 'lastModificationTime'>,
|
||||||
PromissoryNote,
|
|
||||||
"id" | "creationTime" | "lastModificationTime"
|
|
||||||
>
|
|
||||||
) => {
|
) => {
|
||||||
const newNote: PromissoryNote = {
|
const newNote: PromissoryNote = {
|
||||||
...noteData,
|
...noteData,
|
||||||
id: `note_${Date.now()}`,
|
id: `note_${Date.now()}`,
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
};
|
}
|
||||||
setPromissoryNotes((prev) => [...prev, newNote]);
|
setPromissoryNotes((prev) => [...prev, newNote])
|
||||||
console.log("Promissory note added:", newNote);
|
console.log('Promissory note added:', newNote)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEditNote = (
|
const handleEditNote = (
|
||||||
id: string,
|
id: string,
|
||||||
noteData: Omit<
|
noteData: Omit<PromissoryNote, 'id' | 'creationTime' | 'lastModificationTime'>,
|
||||||
PromissoryNote,
|
|
||||||
"id" | "creationTime" | "lastModificationTime"
|
|
||||||
>
|
|
||||||
) => {
|
) => {
|
||||||
setPromissoryNotes((prev) =>
|
setPromissoryNotes((prev) =>
|
||||||
prev.map((note) =>
|
prev.map((note) =>
|
||||||
note.id === id
|
note.id === id ? { ...note, ...noteData, lastModificationTime: new Date() } : note,
|
||||||
? { ...note, ...noteData, lastModificationTime: new Date() }
|
),
|
||||||
: note
|
)
|
||||||
)
|
console.log('Promissory note updated:', id, noteData)
|
||||||
);
|
}
|
||||||
console.log("Promissory note updated:", id, noteData);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCollectCheck = (id: string, collectionDate: Date) => {
|
const handleCollectCheck = (id: string, collectionDate: Date) => {
|
||||||
setChecks((prev) =>
|
setChecks((prev) =>
|
||||||
|
|
@ -85,11 +70,11 @@ const CheckNotePage: React.FC = () => {
|
||||||
collectionDate,
|
collectionDate,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: check
|
: check,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
console.log("Check collected:", id, collectionDate);
|
console.log('Check collected:', id, collectionDate)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCollectNote = (id: string, collectionDate: Date) => {
|
const handleCollectNote = (id: string, collectionDate: Date) => {
|
||||||
setPromissoryNotes((prev) =>
|
setPromissoryNotes((prev) =>
|
||||||
|
|
@ -101,11 +86,11 @@ const CheckNotePage: React.FC = () => {
|
||||||
collectionDate,
|
collectionDate,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: note
|
: note,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
console.log("Promissory note collected:", id, collectionDate);
|
console.log('Promissory note collected:', id, collectionDate)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEndorseCheck = (id: string, endorsedTo: string) => {
|
const handleEndorseCheck = (id: string, endorsedTo: string) => {
|
||||||
setChecks((prev) =>
|
setChecks((prev) =>
|
||||||
|
|
@ -117,11 +102,11 @@ const CheckNotePage: React.FC = () => {
|
||||||
endorsedTo,
|
endorsedTo,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: check
|
: check,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
console.log("Check endorsed:", id, endorsedTo);
|
console.log('Check endorsed:', id, endorsedTo)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEndorseNote = (id: string, endorsedTo: string) => {
|
const handleEndorseNote = (id: string, endorsedTo: string) => {
|
||||||
setPromissoryNotes((prev) =>
|
setPromissoryNotes((prev) =>
|
||||||
|
|
@ -133,27 +118,29 @@ const CheckNotePage: React.FC = () => {
|
||||||
endorsedTo,
|
endorsedTo,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: note
|
: note,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
console.log("Promissory note endorsed:", id, endorsedTo);
|
console.log('Promissory note endorsed:', id, endorsedTo)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CheckNoteManagement
|
<Container>
|
||||||
checks={checks}
|
<CheckNoteManagement
|
||||||
promissoryNotes={promissoryNotes}
|
checks={checks}
|
||||||
currentAccounts={mockCurrentAccounts}
|
promissoryNotes={promissoryNotes}
|
||||||
onAddCheck={handleAddCheck}
|
currentAccounts={mockCurrentAccounts}
|
||||||
onEditCheck={handleEditCheck}
|
onAddCheck={handleAddCheck}
|
||||||
onAddNote={handleAddNote}
|
onEditCheck={handleEditCheck}
|
||||||
onEditNote={handleEditNote}
|
onAddNote={handleAddNote}
|
||||||
onCollectCheck={handleCollectCheck}
|
onEditNote={handleEditNote}
|
||||||
onCollectNote={handleCollectNote}
|
onCollectCheck={handleCollectCheck}
|
||||||
onEndorseCheck={handleEndorseCheck}
|
onCollectNote={handleCollectNote}
|
||||||
onEndorseNote={handleEndorseNote}
|
onEndorseCheck={handleEndorseCheck}
|
||||||
/>
|
onEndorseNote={handleEndorseNote}
|
||||||
);
|
/>
|
||||||
};
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default CheckNotePage;
|
export default CheckNotePage
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
import React from "react";
|
import React from 'react'
|
||||||
import CurrentAccountManagement from "./components/CurrentAccountManagement";
|
import CurrentAccountManagement from './components/CurrentAccountManagement'
|
||||||
import { mockCurrentAccounts } from "../../mocks/mockCurrentAccounts";
|
import { mockCurrentAccounts } from '../../mocks/mockCurrentAccounts'
|
||||||
import { mockCurrentAccountMovements } from "../../mocks/mockCurrentAccountMovements";
|
import { mockCurrentAccountMovements } from '../../mocks/mockCurrentAccountMovements'
|
||||||
|
import { Container } from '@/components/shared'
|
||||||
|
|
||||||
const CurrentAccountPage: React.FC = () => {
|
const CurrentAccountPage: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<CurrentAccountManagement
|
<Container>
|
||||||
accounts={mockCurrentAccounts}
|
<CurrentAccountManagement
|
||||||
accountMovements={mockCurrentAccountMovements}
|
accounts={mockCurrentAccounts}
|
||||||
/>
|
accountMovements={mockCurrentAccountMovements}
|
||||||
);
|
/>
|
||||||
};
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default CurrentAccountPage;
|
export default CurrentAccountPage
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,53 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from 'react'
|
||||||
import InvoiceManagement from "./components/InvoiceManagement";
|
import InvoiceManagement from './components/InvoiceManagement'
|
||||||
import InvoiceForm from "./components/InvoiceForm";
|
import InvoiceForm from './components/InvoiceForm'
|
||||||
import InvoiceDetails from "./components/InvoiceDetails";
|
import InvoiceDetails from './components/InvoiceDetails'
|
||||||
import PaymentForm from "./components/PaymentForm";
|
import PaymentForm from './components/PaymentForm'
|
||||||
import WaybillToInvoice from "./components/WaybillToInvoice";
|
import WaybillToInvoice from './components/WaybillToInvoice'
|
||||||
import {
|
import { FiInvoice, PaymentMethodEnum, PaymentStatusEnum } from '../../types/fi'
|
||||||
FiInvoice,
|
import { mockInvoices } from '../../mocks/mockInvoices'
|
||||||
PaymentMethodEnum,
|
import { Container } from '@/components/shared'
|
||||||
PaymentStatusEnum,
|
|
||||||
} from "../../types/fi";
|
|
||||||
import { mockInvoices } from "../../mocks/mockInvoices";
|
|
||||||
|
|
||||||
interface PaymentData {
|
interface PaymentData {
|
||||||
amount: number;
|
amount: number
|
||||||
paymentDate: Date;
|
paymentDate: Date
|
||||||
paymentMethod: PaymentMethodEnum;
|
paymentMethod: PaymentMethodEnum
|
||||||
description: string;
|
description: string
|
||||||
referenceNumber?: string;
|
referenceNumber?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const InvoicePage: React.FC = () => {
|
const InvoicePage: React.FC = () => {
|
||||||
const [invoices, setInvoices] = useState<FiInvoice[]>(mockInvoices);
|
const [invoices, setInvoices] = useState<FiInvoice[]>(mockInvoices)
|
||||||
const [showInvoiceForm, setShowInvoiceForm] = useState(false);
|
const [showInvoiceForm, setShowInvoiceForm] = useState(false)
|
||||||
const [showInvoiceDetails, setShowInvoiceDetails] = useState(false);
|
const [showInvoiceDetails, setShowInvoiceDetails] = useState(false)
|
||||||
const [showPaymentForm, setShowPaymentForm] = useState(false);
|
const [showPaymentForm, setShowPaymentForm] = useState(false)
|
||||||
const [showWaybillToInvoice, setShowWaybillToInvoice] = useState(false);
|
const [showWaybillToInvoice, setShowWaybillToInvoice] = useState(false)
|
||||||
const [selectedInvoice, setSelectedInvoice] = useState<FiInvoice | null>(
|
const [selectedInvoice, setSelectedInvoice] = useState<FiInvoice | null>(null)
|
||||||
null
|
const [editingInvoice, setEditingInvoice] = useState<FiInvoice | null>(null)
|
||||||
);
|
|
||||||
const [editingInvoice, setEditingInvoice] = useState<FiInvoice | null>(null);
|
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
setEditingInvoice(null);
|
setEditingInvoice(null)
|
||||||
setShowInvoiceForm(true);
|
setShowInvoiceForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEdit = (invoice: FiInvoice) => {
|
const handleEdit = (invoice: FiInvoice) => {
|
||||||
setEditingInvoice(invoice);
|
setEditingInvoice(invoice)
|
||||||
setShowInvoiceForm(true);
|
setShowInvoiceForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCreatePayment = (invoice: FiInvoice) => {
|
const handleCreatePayment = (invoice: FiInvoice) => {
|
||||||
setSelectedInvoice(invoice);
|
setSelectedInvoice(invoice)
|
||||||
setShowPaymentForm(true);
|
setShowPaymentForm(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleViewDetails = (invoice: FiInvoice) => {
|
const handleViewDetails = (invoice: FiInvoice) => {
|
||||||
setSelectedInvoice(invoice);
|
setSelectedInvoice(invoice)
|
||||||
setShowInvoiceDetails(true);
|
setShowInvoiceDetails(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleConvertFromWaybill = () => {
|
const handleConvertFromWaybill = () => {
|
||||||
setShowWaybillToInvoice(true);
|
setShowWaybillToInvoice(true)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveInvoice = (invoiceData: Partial<FiInvoice>) => {
|
const handleSaveInvoice = (invoiceData: Partial<FiInvoice>) => {
|
||||||
if (editingInvoice) {
|
if (editingInvoice) {
|
||||||
|
|
@ -61,9 +56,9 @@ const InvoicePage: React.FC = () => {
|
||||||
prev.map((inv) =>
|
prev.map((inv) =>
|
||||||
inv.id === editingInvoice.id
|
inv.id === editingInvoice.id
|
||||||
? { ...inv, ...invoiceData, lastModificationTime: new Date() }
|
? { ...inv, ...invoiceData, lastModificationTime: new Date() }
|
||||||
: inv
|
: inv,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
} else {
|
} else {
|
||||||
// Yeni ekleme
|
// Yeni ekleme
|
||||||
const newInvoice: FiInvoice = {
|
const newInvoice: FiInvoice = {
|
||||||
|
|
@ -71,15 +66,15 @@ const InvoicePage: React.FC = () => {
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
...invoiceData,
|
...invoiceData,
|
||||||
} as FiInvoice;
|
} as FiInvoice
|
||||||
setInvoices((prev) => [newInvoice, ...prev]);
|
setInvoices((prev) => [newInvoice, ...prev])
|
||||||
}
|
}
|
||||||
setShowInvoiceForm(false);
|
setShowInvoiceForm(false)
|
||||||
setEditingInvoice(null);
|
setEditingInvoice(null)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSavePayment = (paymentData: PaymentData) => {
|
const handleSavePayment = (paymentData: PaymentData) => {
|
||||||
if (!selectedInvoice) return;
|
if (!selectedInvoice) return
|
||||||
|
|
||||||
// Ödeme bilgilerini faturaya ekle
|
// Ödeme bilgilerini faturaya ekle
|
||||||
const updatedInvoice = {
|
const updatedInvoice = {
|
||||||
|
|
@ -91,50 +86,48 @@ const InvoicePage: React.FC = () => {
|
||||||
? PaymentStatusEnum.Paid
|
? PaymentStatusEnum.Paid
|
||||||
: PaymentStatusEnum.PartiallyPaid,
|
: PaymentStatusEnum.PartiallyPaid,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
};
|
}
|
||||||
|
|
||||||
setInvoices((prev) =>
|
setInvoices((prev) => prev.map((inv) => (inv.id === selectedInvoice.id ? updatedInvoice : inv)))
|
||||||
prev.map((inv) => (inv.id === selectedInvoice.id ? updatedInvoice : inv))
|
|
||||||
);
|
|
||||||
|
|
||||||
setShowPaymentForm(false);
|
setShowPaymentForm(false)
|
||||||
setSelectedInvoice(null);
|
setSelectedInvoice(null)
|
||||||
|
|
||||||
// Başarı mesajı
|
// Başarı mesajı
|
||||||
alert(
|
alert(
|
||||||
`${paymentData.amount.toLocaleString("tr-TR", {
|
`${paymentData.amount.toLocaleString('tr-TR', {
|
||||||
style: "currency",
|
style: 'currency',
|
||||||
currency: "TRY",
|
currency: 'TRY',
|
||||||
})} tutarında ödeme kaydedildi.`
|
})} tutarında ödeme kaydedildi.`,
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleSaveFromWaybill = () => {
|
const handleSaveFromWaybill = () => {
|
||||||
setShowWaybillToInvoice(false);
|
setShowWaybillToInvoice(false)
|
||||||
alert("İrsaliyelerden fatura başarıyla oluşturuldu.");
|
alert('İrsaliyelerden fatura başarıyla oluşturuldu.')
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCancelForm = () => {
|
const handleCancelForm = () => {
|
||||||
setShowInvoiceForm(false);
|
setShowInvoiceForm(false)
|
||||||
setEditingInvoice(null);
|
setEditingInvoice(null)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCancelDetails = () => {
|
const handleCancelDetails = () => {
|
||||||
setShowInvoiceDetails(false);
|
setShowInvoiceDetails(false)
|
||||||
setSelectedInvoice(null);
|
setSelectedInvoice(null)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCancelPayment = () => {
|
const handleCancelPayment = () => {
|
||||||
setShowPaymentForm(false);
|
setShowPaymentForm(false)
|
||||||
setSelectedInvoice(null);
|
setSelectedInvoice(null)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCancelWaybillToInvoice = () => {
|
const handleCancelWaybillToInvoice = () => {
|
||||||
setShowWaybillToInvoice(false);
|
setShowWaybillToInvoice(false)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Container>
|
||||||
<InvoiceManagement
|
<InvoiceManagement
|
||||||
invoices={invoices}
|
invoices={invoices}
|
||||||
onAdd={handleAdd}
|
onAdd={handleAdd}
|
||||||
|
|
@ -173,8 +166,8 @@ const InvoicePage: React.FC = () => {
|
||||||
onInvoiceCreated={handleSaveFromWaybill}
|
onInvoiceCreated={handleSaveFromWaybill}
|
||||||
isVisible={showWaybillToInvoice}
|
isVisible={showWaybillToInvoice}
|
||||||
/>
|
/>
|
||||||
</>
|
</Container>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default InvoicePage;
|
export default InvoicePage
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,38 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from 'react'
|
||||||
import WaybillManagement from "./components/WaybillManagement";
|
import WaybillManagement from './components/WaybillManagement'
|
||||||
import WaybillForm from "./components/WaybillForm";
|
import WaybillForm from './components/WaybillForm'
|
||||||
import WaybillDetails from "./components/WaybillDetails";
|
import WaybillDetails from './components/WaybillDetails'
|
||||||
import WaybillToInvoice from "./components/WaybillToInvoice";
|
import WaybillToInvoice from './components/WaybillToInvoice'
|
||||||
import { FiWaybill, WaybillStatusEnum } from "../../types/fi";
|
import { FiWaybill, WaybillStatusEnum } from '../../types/fi'
|
||||||
import { mockWaybills } from "../../mocks/mockWaybills";
|
import { mockWaybills } from '../../mocks/mockWaybills'
|
||||||
|
import { Container } from '@/components/shared'
|
||||||
|
|
||||||
type ViewType = "management" | "form" | "details" | "createInvoice";
|
type ViewType = 'management' | 'form' | 'details' | 'createInvoice'
|
||||||
|
|
||||||
const WaybillPage: React.FC = () => {
|
const WaybillPage: React.FC = () => {
|
||||||
const [currentView, setCurrentView] = useState<ViewType>("management");
|
const [currentView, setCurrentView] = useState<ViewType>('management')
|
||||||
const [waybills, setWaybills] = useState<FiWaybill[]>(mockWaybills);
|
const [waybills, setWaybills] = useState<FiWaybill[]>(mockWaybills)
|
||||||
const [selectedWaybill, setSelectedWaybill] = useState<
|
const [selectedWaybill, setSelectedWaybill] = useState<FiWaybill | undefined>()
|
||||||
FiWaybill | undefined
|
|
||||||
>();
|
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
setSelectedWaybill(undefined);
|
setSelectedWaybill(undefined)
|
||||||
setCurrentView("form");
|
setCurrentView('form')
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleEdit = (waybill: FiWaybill) => {
|
const handleEdit = (waybill: FiWaybill) => {
|
||||||
setSelectedWaybill(waybill);
|
setSelectedWaybill(waybill)
|
||||||
setCurrentView("form");
|
setCurrentView('form')
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleViewDetails = (waybill: FiWaybill) => {
|
const handleViewDetails = (waybill: FiWaybill) => {
|
||||||
setSelectedWaybill(waybill);
|
setSelectedWaybill(waybill)
|
||||||
setCurrentView("details");
|
setCurrentView('details')
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCreateInvoice = (waybill: FiWaybill) => {
|
const handleCreateInvoice = (waybill: FiWaybill) => {
|
||||||
setSelectedWaybill(waybill);
|
setSelectedWaybill(waybill)
|
||||||
setCurrentView("createInvoice");
|
setCurrentView('createInvoice')
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleMarkAsDelivered = (waybill: FiWaybill) => {
|
const handleMarkAsDelivered = (waybill: FiWaybill) => {
|
||||||
setWaybills((prev) =>
|
setWaybills((prev) =>
|
||||||
|
|
@ -44,13 +43,11 @@ const WaybillPage: React.FC = () => {
|
||||||
status: WaybillStatusEnum.Delivered,
|
status: WaybillStatusEnum.Delivered,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: w
|
: w,
|
||||||
)
|
),
|
||||||
);
|
)
|
||||||
alert(
|
alert(`${waybill.waybillNumber} numaralı irsaliye teslim edildi olarak işaretlendi.`)
|
||||||
`${waybill.waybillNumber} numaralı irsaliye teslim edildi olarak işaretlendi.`
|
}
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveWaybill = (waybillData: Partial<FiWaybill>) => {
|
const handleSaveWaybill = (waybillData: Partial<FiWaybill>) => {
|
||||||
if (selectedWaybill) {
|
if (selectedWaybill) {
|
||||||
|
|
@ -62,9 +59,9 @@ const WaybillPage: React.FC = () => {
|
||||||
...waybillData,
|
...waybillData,
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
}
|
}
|
||||||
: w
|
: w,
|
||||||
);
|
)
|
||||||
setWaybills(updatedWaybills);
|
setWaybills(updatedWaybills)
|
||||||
} else {
|
} else {
|
||||||
// Create new waybill
|
// Create new waybill
|
||||||
const newWaybill: FiWaybill = {
|
const newWaybill: FiWaybill = {
|
||||||
|
|
@ -72,17 +69,17 @@ const WaybillPage: React.FC = () => {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
creationTime: new Date(),
|
creationTime: new Date(),
|
||||||
lastModificationTime: new Date(),
|
lastModificationTime: new Date(),
|
||||||
};
|
}
|
||||||
setWaybills([...waybills, newWaybill]);
|
setWaybills([...waybills, newWaybill])
|
||||||
}
|
}
|
||||||
setCurrentView("management");
|
setCurrentView('management')
|
||||||
setSelectedWaybill(undefined);
|
setSelectedWaybill(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setCurrentView("management");
|
setCurrentView('management')
|
||||||
setSelectedWaybill(undefined);
|
setSelectedWaybill(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
const handleInvoiceCreated = () => {
|
const handleInvoiceCreated = () => {
|
||||||
// Mark waybill as invoiced
|
// Mark waybill as invoiced
|
||||||
|
|
@ -90,17 +87,17 @@ const WaybillPage: React.FC = () => {
|
||||||
const updatedWaybills = waybills.map((w) =>
|
const updatedWaybills = waybills.map((w) =>
|
||||||
w.id === selectedWaybill.id
|
w.id === selectedWaybill.id
|
||||||
? { ...w, isInvoiced: true, lastModificationTime: new Date() }
|
? { ...w, isInvoiced: true, lastModificationTime: new Date() }
|
||||||
: w
|
: w,
|
||||||
);
|
)
|
||||||
setWaybills(updatedWaybills);
|
setWaybills(updatedWaybills)
|
||||||
}
|
}
|
||||||
setCurrentView("management");
|
setCurrentView('management')
|
||||||
setSelectedWaybill(undefined);
|
setSelectedWaybill(undefined)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Container>
|
||||||
{currentView === "management" && (
|
{currentView === 'management' && (
|
||||||
<WaybillManagement
|
<WaybillManagement
|
||||||
waybills={waybills}
|
waybills={waybills}
|
||||||
onAdd={handleAdd}
|
onAdd={handleAdd}
|
||||||
|
|
@ -115,7 +112,7 @@ const WaybillPage: React.FC = () => {
|
||||||
waybill={selectedWaybill}
|
waybill={selectedWaybill}
|
||||||
onSave={handleSaveWaybill}
|
onSave={handleSaveWaybill}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
isVisible={currentView === "form"}
|
isVisible={currentView === 'form'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{selectedWaybill && (
|
{selectedWaybill && (
|
||||||
|
|
@ -123,7 +120,7 @@ const WaybillPage: React.FC = () => {
|
||||||
waybill={selectedWaybill}
|
waybill={selectedWaybill}
|
||||||
onClose={handleCancel}
|
onClose={handleCancel}
|
||||||
onCreateInvoice={() => handleCreateInvoice(selectedWaybill)}
|
onCreateInvoice={() => handleCreateInvoice(selectedWaybill)}
|
||||||
isVisible={currentView === "details"}
|
isVisible={currentView === 'details'}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -132,11 +129,11 @@ const WaybillPage: React.FC = () => {
|
||||||
selectedWaybills={[selectedWaybill.id]}
|
selectedWaybills={[selectedWaybill.id]}
|
||||||
onClose={handleCancel}
|
onClose={handleCancel}
|
||||||
onInvoiceCreated={handleInvoiceCreated}
|
onInvoiceCreated={handleInvoiceCreated}
|
||||||
isVisible={currentView === "createInvoice"}
|
isVisible={currentView === 'createInvoice'}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</Container>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export default WaybillPage;
|
export default WaybillPage
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue