-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: "forced invoice number" enabled
- Loading branch information
1 parent
d61cbee
commit d027e3d
Showing
10 changed files
with
311 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2024 RSC-Labs, https://rsoftcon.com/ | ||
* | ||
* MIT License | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { | ||
MedusaRequest, | ||
MedusaResponse, | ||
} from "@medusajs/medusa" | ||
import InvoiceService from "../../../../services/invoice"; | ||
|
||
export const GET = async ( | ||
req: MedusaRequest, | ||
res: MedusaResponse | ||
) => { | ||
|
||
const invoiceService: InvoiceService = req.scope.resolve('invoiceService'); | ||
|
||
const formatNumber: string | undefined = req.query.formatNumber as string; | ||
const forcedNumber: string | undefined = req.query.forcedNumber as string; | ||
|
||
try { | ||
const nextDisplayNumber = await invoiceService.getTestDisplayNumber(formatNumber, forcedNumber); | ||
res.status(201).json({ | ||
displayNumber: nextDisplayNumber | ||
}) | ||
} catch (e) { | ||
res.status(400).json({ | ||
message: e.message | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/ui-components/settings/settings-invoice-display-number.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2024 RSC-Labs, https://rsoftcon.com/ | ||
* | ||
* MIT License | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Heading, Text, FocusModal, Button, Input, Label, Toaster, Alert } from "@medusajs/ui" | ||
import { CircularProgress, Grid } from "@mui/material"; | ||
import { useAdminCustomQuery } from "medusa-react" | ||
|
||
type AdminStoreDocumentInvoiceSettingsDisplayNumberQueryReq = { | ||
formatNumber: string, | ||
forcedNumber: number | ||
} | ||
|
||
type StoreDocumentInvoiceSettingsDisplayNumberResult = { | ||
displayNumber: string | ||
} | ||
|
||
const InvoiceSettingsDisplayNumber = ({ formatNumber, forcedNumber } : {formatNumber?: string, forcedNumber?: number}) => { | ||
|
||
const { data, isLoading } = useAdminCustomQuery | ||
<AdminStoreDocumentInvoiceSettingsDisplayNumberQueryReq, StoreDocumentInvoiceSettingsDisplayNumberResult>( | ||
"/invoice/display-number", | ||
[formatNumber, forcedNumber], | ||
{ | ||
formatNumber: formatNumber, | ||
forcedNumber: forcedNumber | ||
} | ||
) | ||
|
||
if (isLoading) { | ||
return ( | ||
<Grid item> | ||
<Input | ||
readOnly={true} | ||
/> | ||
</Grid> | ||
) | ||
} | ||
|
||
return ( | ||
<Grid item> | ||
<Input key={`display-number-${data.displayNumber}`} | ||
defaultValue={data.displayNumber} | ||
readOnly={true} | ||
/> | ||
</Grid> | ||
) | ||
} | ||
|
||
|
||
export default InvoiceSettingsDisplayNumber |
Oops, something went wrong.