Skip to content

Commit

Permalink
Merge pull request #6 from GesangPJ/test
Browse files Browse the repository at this point in the history
Tambah Fitur Jurnal, Fix Bug Tambah Produk
  • Loading branch information
GesangPJ authored Aug 8, 2024
2 parents 23cb09e + 5f7de2e commit 1ae03ae
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 49 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@ Aplikasi Sistem Manajemen Penjualan untuk UMKM berbasis Node.JS dengan framework
8. Pages protection menggunakan session.
9. Admin Master Key autentikasi bagi admin untuk mengganti password akun dan data akun.

## Halaman

1. Dashboard (Admin & Karyawan)
2. Daftar Transaksi
3. Daftar Pelanggan
4. Tambah Pelanggan
5. Daftar Produk
6. Daftar Kategori Produk
7. Tambah Produk
8. Tambah Kategori Produk
9. Daftar Pembelian (Purchasing)
10. Tambah Pembelian
11. Daftar Distributor
12. Tambah Distributor
13. Daftar Akun (Admin & Karyawan)
14. Tambah Akun
## Fitur Sistem Penjualan

1. Transaksi Penjualan : Tambah Transaksi, daftar transaksi, edit status transaksi.
2. Detail Transaksi
3. Produk : Tambah Produk, Daftar Produk, Edit Produk.
4. Kategori Produk : Tambah Kategori Produk, edit status kategori produk.
5. Pembelian / Purchasing : Tambah Pembelian, edit pembelian.
6. Detail Pembelian
7. Stok : Atur Stok Produk.
8. Pelanggan : Tambah pelanggan, daftar pelanggan, edit pelanggan.
9. Distributor : Tambah Distributor, daftar distributor, edit distributor.
10. Akun : Akun Admin & Karyawan : Tambah Akun, Edit Akun.

## Changelog

### v1.1.7

- Fix Bug Tambah Produk, dimana kategoriId berisi Null.
- Membuat Jurnal Transaksi.
- Membuat Jurnal Pembelian.
- Fungsi Jurnal Sementara.
- Ganti Prisma connection menggunakan `DATABASE_URL`.

### v1.0.0

Rilis pertama.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GTRetail",
"version": "1.0.0",
"version": "1.1.7",
"license": "Commercial",
"private": true,
"scripts": {
Expand All @@ -15,7 +15,7 @@
"postinstall": "prisma generate && npm run build:icons",
"seedadmin": "node prisma/seedAdmin.js",
"seedkaryawan": "node prisma/seedKaryawan.js",
"deletekasbon": "node prisma/deleteKasbon.js"
"resettransaksi": "node prisma/resetTransaksi.js"
},
"dependencies": {
"@emotion/cache": "^11.11.0",
Expand Down
29 changes: 29 additions & 0 deletions prisma/migrations/20240808100234_buat_jurnal/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- CreateTable
CREATE TABLE "JurnalTransaksi" (
"id" SERIAL NOT NULL,
"transaksiId" INTEGER NOT NULL,
"kode" TEXT NOT NULL,
"pemasukan" INTEGER NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "JurnalTransaksi_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "JurnalPembelian" (
"id" SERIAL NOT NULL,
"pembelianId" INTEGER NOT NULL,
"kode" TEXT NOT NULL,
"pengeluaran" INTEGER NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "JurnalPembelian_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "JurnalTransaksi" ADD CONSTRAINT "JurnalTransaksi_transaksiId_fkey" FOREIGN KEY ("transaksiId") REFERENCES "Transaksi"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "JurnalPembelian" ADD CONSTRAINT "JurnalPembelian_pembelianId_fkey" FOREIGN KEY ("pembelianId") REFERENCES "Pembelian"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
30 changes: 30 additions & 0 deletions prisma/resetTransaksi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Reset Transaksi

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
try {
// Hapus semua data dari tabel transaksi detail dan transaksi
await prisma.transaksiDetail.deleteMany({})
await prisma.transaksi.deleteMany({})
console.log('Berhasil menghapus semua data di tabel Transaksi Detail & Transaksi.')

// Reset ID TransaksiDetail dan Transaksi dari 1
await prisma.$executeRaw`ALTER SEQUENCE "TransaksiDetail_id_seq" RESTART WITH 1`
await prisma.$executeRaw`ALTER SEQUENCE "Transaksi_id_seq" RESTART WITH 1`
console.log('Berhasil mereset ID di tabel Transaksi Detail & Transaksi.')

} catch (error) {
console.error('Error menghapus data dan reset ID Transaksi Detail & Transaksi :', error)
} finally {
await prisma.$disconnect()
}
}

main()
.catch((e) => {
console.error(e)
process.exit(1)
})
31 changes: 28 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL")
directUrl = env("POSTGRES_URL_NON_POOLING")
provider = "postgresql"
url = env("DATABASE_URL")
}

generator client {
Expand All @@ -29,6 +28,30 @@ model User {
kedatangan Kedatangan[]
}

model JurnalTransaksi {
id Int @id @default(autoincrement())
transaksiId Int
kode String
pemasukan Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
transaksi Transaksi @relation(fields: [transaksiId], references: [id])
}

model JurnalPembelian {
id Int @id @default(autoincrement())
pembelianId Int
kode String
pengeluaran Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
pembelian Pembelian @relation(fields: [pembelianId], references: [id])
}

model Kategori {
id Int @id @default(autoincrement())
nama String
Expand Down Expand Up @@ -76,6 +99,7 @@ model Pembelian {
pembeliandetail PembelianDetail[]
distributor Distributor @relation(fields: [distributorId], references: [id])
jurnalpembelian JurnalPembelian[]
}

model PembelianDetail {
Expand Down Expand Up @@ -159,6 +183,7 @@ model Transaksi {
user User @relation("TransaksiUser", fields: [userId], references: [id])
pelanggan Pelanggan? @relation("TransaksiPelanggan", fields: [pelangganId], references: [id])
transaksidetail TransaksiDetail[]
jurnaltransaksi JurnalTransaksi[]
}

Expand Down
8 changes: 8 additions & 0 deletions src/app/api/tambah-pembelian/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export const POST = async (req) => {
},
})

const newJurnalPembelian = await prisma.jurnalPembelian.create({
data:{
pembelianId: newPembelian.id,
kode: newKode,
pengeluaran: totalHarga,
}
})

return NextResponse.json(newPembelian, { status: 201 })

} catch (error) {
Expand Down
15 changes: 12 additions & 3 deletions src/app/api/tambah-transaksi/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const POST = async (req) => {
const lastYear = lastTransaksiDate.getFullYear()

// Reset nomor seri jika masuk bulan baru

if (currentMonth !== lastMonth || currentYear !== lastYear) {
newNumber = '00001'
} else {
Expand All @@ -73,12 +72,13 @@ export const POST = async (req) => {
// Membuat kode baru
const newKode = `GT/SALES/${currentMonth}/${currentYear}/${newNumber}`

// Membuat transaksi baru
const newTransaksi = await prisma.transaksi.create({
data: {
kode: newKode,
userId:userId,
userId,
pelangganId,
namapelanggan:pelangganNama,
namapelanggan: pelangganNama,
status,
jumlahTotal: totalHarga,
transaksidetail: {
Expand All @@ -92,6 +92,15 @@ export const POST = async (req) => {
},
})

// Membuat jurnal transaksi baru
const newJurnalTransaksi = await prisma.jurnalTransaksi.create({
data: {
transaksiId: newTransaksi.id,
kode: newKode,
pemasukan: totalHarga,
},
})

// Mengurangi stok produk
for (const item of produk) {
await prisma.produk.update({
Expand Down
2 changes: 1 addition & 1 deletion src/views/distributor/tambah-distributor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const FormTambahDistributor = () => {

if (response.ok) {
setAlert('success')
setMessage('Distributor berhasil ditambahkan!')
setMessage(`Distributor ${formData.nama} berhasil ditambahkan!`)
formRef.current.reset() // Kosongkan form setelah berhasil didaftarkan
} else {
setAlert('error')
Expand Down
2 changes: 1 addition & 1 deletion src/views/produk/tambah-kategori.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const FormTambahKategori = () =>{

if (response.ok) {
setAlert('success')
setMessage('Data Kategori Produk berhasil disimpan!')
setMessage(`Kategori Produk ${formData.nama} berhasil disimpan!`)
formRef.current.reset() // Kosongkan form setelah berhasil didaftarkan
} else {
setAlert('error')
Expand Down
59 changes: 36 additions & 23 deletions src/views/produk/tambah-produk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const FormTambahProduk = () =>{
const [KategoriProduk, setKategoriProduk] = useState([])
const formRef = useRef(null)
const [selectedDate, setSelectedDate] = useState(null)
const [selectedKategori, setSelectedKategori] = useState(null)

const handleDateChange = (date) => {
setSelectedDate(date)
Expand Down Expand Up @@ -62,7 +63,15 @@ const FormTambahProduk = () =>{
event.preventDefault()
const data = new FormData(event.target)

if (!data.get('kategoriproduk') || !data.get('nama') || !data.get('harga') || !data.get('hargabeli') || !data.get('stok')) {
console.log({
kategoriId: selectedKategori.id,
harga: data.get('harga'),
hargabeli: data.get('hargabeli'),
jenis: data.get('jenis'),
nama: data.get('nama'),
})

if (!selectedKategori.id || !data.get('nama') || !data.get('harga') || !data.get('hargabeli') || !data.get('stok')) {
setAlert('error')
setMessage('Semua bidang harus diisi.')

Expand All @@ -71,7 +80,7 @@ const FormTambahProduk = () =>{

const formData = {
userId: session.user.id,
kategoriId: parseInt(data.get('kategoriproduk')),
kategoriId: selectedKategori.id,
barcode: data.get('barcode'),
nama: data.get('nama'),
harga: parseInt(data.get('harga')),
Expand All @@ -83,6 +92,8 @@ const FormTambahProduk = () =>{
keterangan: data.get('keterangan'),
}



try {
const response = await fetch('/api/tambah-produk', {
method: 'POST',
Expand Down Expand Up @@ -196,27 +207,29 @@ const FormTambahProduk = () =>{
/>
</Grid>
<Grid item xs={12}>
<Autocomplete
id="kategoriproduk"
fullWidth
options={KategoriProduk}
getOptionLabel={(option) => option.nama}
renderOption={(props, option) => (
<Box component="li" {...props}>
{option.nama}
</Box>
)}
renderInput={(params) => (
<TextField
{...params}
label="Pilih Kategori"
inputProps={{
...params.inputProps,
autoComplete: 'new-password'
}}
/>
)}
/>
<Autocomplete
id="kategoriproduk"
fullWidth
options={KategoriProduk}
getOptionLabel={(option) => option.nama}
value={selectedKategori}
onChange={(event, newValue) => setSelectedKategori(newValue)}
renderOption={(props, option) => (
<Box component="li" {...props} key={option.id}>
{option.nama}
</Box>
)}
renderInput={(params) => (
<TextField
{...params}
label="Pilih Kategori"
inputProps={{
...params.inputProps,
autoComplete: 'new-password'
}}
/>
)}
/>
</Grid>
<Grid item xs={12}>
<FormControl fullWidth>
Expand Down

0 comments on commit 1ae03ae

Please sign in to comment.