summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-12-05 10:53:52 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-12-05 10:53:52 +0700
commitc977921f02308af769af37f6b7d37b21869797f2 (patch)
tree6a3b5078682a8c644207193979adbc31e91e61f2 /src
parent51f2fd6fcaf6de7d3912f266fd85ff2386b595f0 (diff)
Add externalId on import and export
Diffstat (limited to 'src')
-rw-r--r--src/app/api/product/import/route.tsx1
-rw-r--r--src/app/api/stock-opname/export/route.tsx1
-rw-r--r--src/app/api/stock-opname/route.tsx11
-rw-r--r--src/modules/result/components/ImportModal.tsx23
4 files changed, 22 insertions, 14 deletions
diff --git a/src/app/api/product/import/route.tsx b/src/app/api/product/import/route.tsx
index eb87f07..e4e38c6 100644
--- a/src/app/api/product/import/route.tsx
+++ b/src/app/api/product/import/route.tsx
@@ -25,6 +25,7 @@ export async function POST(request: NextRequest) {
onhandQty: row[3],
differenceQty: row[4],
companyId: row[5],
+ externalId: row[6] ?? null
}));
const whereCompany = { companyId: intCompanyId }
diff --git a/src/app/api/stock-opname/export/route.tsx b/src/app/api/stock-opname/export/route.tsx
index 650ceba..2537070 100644
--- a/src/app/api/stock-opname/export/route.tsx
+++ b/src/app/api/stock-opname/export/route.tsx
@@ -46,6 +46,7 @@ export async function GET(request: NextRequest) {
for (const opname of stockOpnames) {
const defaultItems = {
+ externalId: opname?.externalId,
itemCode: opname?.itemCode,
barcode: opname?.barcode,
name: opname.name,
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index e98c3b2..cba16e2 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -40,16 +40,7 @@ export async function GET(request: NextRequest) {
const products = await prisma.product.findMany({
skip: (intPage - 1) * PAGE_SIZE,
take: PAGE_SIZE,
- where,
- select: {
- id: true,
- name: true,
- itemCode: true,
- barcode: true,
- onhandQty: true,
- differenceQty: true,
- isDifferent: true
- }
+ where
})
const productCount = await prisma.product.count({ where })
diff --git a/src/modules/result/components/ImportModal.tsx b/src/modules/result/components/ImportModal.tsx
index fd4c7d3..1bb7b26 100644
--- a/src/modules/result/components/ImportModal.tsx
+++ b/src/modules/result/components/ImportModal.tsx
@@ -1,6 +1,6 @@
import toast from '@/common/libs/toast'
import { useResultStore } from '@/common/stores/useResultStore'
-import { Button, Modal, ModalBody, ModalContent, ModalHeader } from '@nextui-org/react'
+import { Button, Input, Modal, ModalBody, ModalContent, ModalHeader, Spacer } from '@nextui-org/react'
import { useMutation } from '@tanstack/react-query'
import { AlertTriangleIcon } from 'lucide-react'
import React, { ChangeEvent, FormEvent, useMemo, useState } from 'react'
@@ -14,6 +14,7 @@ type Props = {
const ImportModal = ({ modal }: Props) => {
const [file, setFile] = useState<File>()
+ const [confirmation, setConfirmation] = useState<string>('')
const { companies, filter } = useResultStore()
const selectedCompany = useMemo(() => {
@@ -47,20 +48,34 @@ const ImportModal = ({ modal }: Props) => {
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault()
importMutation.mutate()
+ setConfirmation('')
}
+ const confirmationText = `Hapus produk dan hasil so ${selectedCompany?.label}`
+ const isConfirmed = confirmation.toLowerCase() === confirmationText.toLowerCase()
+
return (
<Modal isOpen={modal.isOpen} onOpenChange={modal.onOpenChange}>
<ModalContent>
- <ModalHeader>Import Product</ModalHeader>
+ <ModalHeader>Import Product {selectedCompany?.label}</ModalHeader>
<ModalBody>
<form className='pb-6' onSubmit={handleSubmit}>
<input type='file' onChange={handleFileChange} accept='.xls, .xlsx' />
- <Button type='submit' color='primary' className='mt-4 w-full' isDisabled={!file || importMutation.isPending}>
+ <Spacer y={4} />
+ <Input
+ type="text"
+ label='Ketik ulang untuk konfirmasi'
+ placeholder={confirmationText}
+ name="confirmation"
+ autoComplete='false'
+ onChange={(e) => setConfirmation(e.target.value)}
+ value={confirmation}
+ />
+ <Button type='submit' color='primary' className='mt-4 w-full' isDisabled={!file || importMutation.isPending || !isConfirmed}>
{importMutation.isPending ? 'Loading...' : 'Submit'}
</Button>
- <div className='text-xs font-medium p-4 bg-danger-600 text-neutral-50 rounded-medium mt-4 flex items-center gap-x-4'>
+ <div className='text-xs font-medium p-4 bg-danger-100 border border-danger-200 text-danger-600 rounded-medium mt-4 flex items-center gap-x-4'>
<div>
<AlertTriangleIcon size={28} />
</div>