MEDIUM severity: The vulnerability in the `TellerV2` contract's `calculateAmountDue` function affects the calculation. The vulnerability in the `TellerV2` contract's `calculateAmountDue` function affects the calculation of loan installments for irregular loan durations. Specifically, the function incorrectly determines the last payment cycle, leading to incorrect calculations.\n\nThe issue arises when the loan durat...

Vulnerable code:
```\nFile: libraries/V2Calculations.sol\n\n93:        // Cast to int256 to avoid underflow errors (negative means loan duration has passed)\n94:        int256 durationLeftOnLoan = int256(\n95:            uint256(_bid.loanDetails.loanDuration)\n96:        ) -\n97:            (int256(_timestamp) -\n98:                int256(uint256(_bid.loanDetails.acceptedTimestamp)))\n99:        bool isLastPaymentCycle = durationLeftOnLoan <\n100:            int256(uint256(_bid.terms.paymentCycle)) ||\n101:            owedPrincipal_ + interest_ <= _bid.terms.paymentCycleAmount;\n102:        // Check if current payment cycle is within or beyond the last one\n103:        // Check if what is left to pay is less than the payment cycle amount\n```\n```\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {\n    UpgradeableBeacon\n} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";\n\nimport {\n    AddressUpgradeable\n} from "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";\n\nimport {\n    TellerV2\n} from "../contracts/TellerV2.sol";\nimport {\n    Payment\n} from "../contracts/TellerV2Storage.sol";\nimport {\n    CollateralManager\n} from "../contracts/CollateralManager.sol";\nimport {\n    LenderCommitmentForwarder\n} from "../contracts/LenderCommitmentForwarder.sol";\nimport {\n    CollateralEscrowV1\n} from "../contracts/escrow/CollateralEscrowV1.sol";\nimport {\n    Collateral,\n    CollateralType\n} from "../contracts/interfaces/escrow/ICollateralEscrowV1.sol";\n\nimport {\n    ReputationManagerMock\n} from "../contracts/mock/ReputationManagerMock.sol";\nimport {\n    LenderManagerMock\n} from "../contracts/mock/LenderManagerMock.sol";\nimport {\n    MarketRegistryMock\n} from "../contracts/mock/MarketRegistryMock.sol";\n\nimport {\n    TestERC20Token\n} from "./tokens/TestERC20Token.sol";\n\nimport "lib/forge-std/src/Test.sol";\n\ncontract LoansTest is Test {\n    using AddressUpgradeable for address;\n\n    MarketRegistryMock public marketRegistry;\n\n    TellerV2 public tellerV2;\n    LenderCommitmentForwarder public lenderCommitmentForwarder;\n    CollateralManager public collateralManager;\n\n    TestERC20Token public principalToken;\n\n    address public alice = address(0x1111);\n\n    uint256 public marketId = 0;\n\n    function setUp() public {\n        tellerV2 = new TellerV2(address(0));\n\n        marketRegistry = new MarketRegistryMock();\n\n        lenderCommitmentForwarder = new LenderCommitmentForwarder(address(tellerV2), address(marketRegistry));\n\n        collateralManager = new CollateralManager();\n        collateralManager.initialize(address(new UpgradeableBeacon(address(new CollateralEscrowV1()))), address(tellerV2));\n\n        address rm = address(new ReputationManagerMock());\n        address lm = address(new LenderManagerMock());\n        tellerV2.initialize(0, address(marketRegistry), rm, address(lenderCommitmentForwarder), address(collateralManager), lm);\n```