diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php
index dbe880f..2027d8d 100644
--- a/database/seeders/DatabaseSeeder.php
+++ b/database/seeders/DatabaseSeeder.php
@@ -37,17 +37,9 @@ class DatabaseSeeder extends Seeder
'updated_at' => now(),
]);
- // Create sales record
- Sales::create([
- 'nama' => 'Kasir',
- 'no_hp' => '-',
- 'alamat' => '-',
- 'created_at' => now(),
- 'updated_at' => now(),
- ]);
-
+
// Call other seeders
$this->call(DataSeeder::class);
$this->call(DummySeeder::class);
}
-}
\ No newline at end of file
+}
diff --git a/resources/js/components/StrukOverlay.vue b/resources/js/components/StrukOverlay.vue
index 5b849b0..1353d67 100644
--- a/resources/js/components/StrukOverlay.vue
+++ b/resources/js/components/StrukOverlay.vue
@@ -18,7 +18,7 @@
@@ -108,7 +108,7 @@
@@ -189,18 +189,9 @@ import inputSelect from '@/components/InputSelect.vue'
import axios from 'axios'
const props = defineProps({
- isOpen: {
- type: Boolean,
- default: false,
- },
- pesanan: {
- type: Array,
- default: () => []
- },
- total: {
- type: Number,
- default: 0
- }
+ isOpen: Boolean,
+ pesanan: Array,
+ total: Number
})
const emit = defineEmits(['close', 'confirm', 'transaksi-saved'])
@@ -218,52 +209,31 @@ const showToast = ref(false)
const toastType = ref('error')
const toastMessage = ref('')
+// 🧾 kode transaksi tetap
+const transactionCode = ref('')
+
const toastClasses = computed(() => {
- const baseClasses = 'text-white'
- const typeClasses = {
+ const base = 'text-white'
+ const type = {
error: 'bg-red-500',
success: 'bg-green-500',
info: 'bg-blue-500'
}
- return `${baseClasses} ${typeClasses[toastType.value]}`
+ return `${base} ${type[toastType.value]}`
})
-const grandTotal = computed(() => {
- return props.total + (ongkosBikin.value || 0)
-})
+const grandTotal = computed(() => props.total + (ongkosBikin.value || 0))
-const getRowStyle = () => {
- if (props.pesanan.length === 1) {
- return { height: '126px' }
- }
- return { height: '63px' }
-}
-
-const getImageClass = () => {
- if (props.pesanan.length === 1) {
- return 'w-25 h-25'
- }
- return 'w-12 h-12'
-}
-
-const getTextClass = () => {
- if (props.pesanan.length === 1) {
- return 'text-lg font-medium'
- }
- return 'text-sm'
-}
+const getRowStyle = () => props.pesanan.length === 1 ? { height: '126px' } : { height: '63px' }
+const getImageClass = () => props.pesanan.length === 1 ? 'w-25 h-25' : 'w-12 h-12'
+const getTextClass = () => props.pesanan.length === 1 ? 'text-lg font-medium' : 'text-sm'
const getCurrentDate = () => {
- const days = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu']
- const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
-
+ const days = ['Minggu','Senin','Selasa','Rabu','Kamis','Jumat','Sabtu']
const now = new Date()
- const dayName = days[now.getDay()]
const day = String(now.getDate()).padStart(2, '0')
- const month = months[now.getMonth()]
- const year = now.getFullYear()
-
- return `${dayName}, ${day}-${month}-${year}`
+ const month = String(now.getMonth() + 1).padStart(2, '0')
+ return `${days[now.getDay()]}, ${day}-${month}-${now.getFullYear()}`
}
const generateTransactionCode = () => {
@@ -276,55 +246,33 @@ const showSimpleToast = (type, message, duration = 3000) => {
toastType.value = type
toastMessage.value = message
showToast.value = true
-
- setTimeout(() => {
- showToast.value = false
- }, duration)
+ setTimeout(() => (showToast.value = false), duration)
}
const fetchSales = async () => {
try {
- const response = await axios.get('/api/sales', {
- headers: {
- Authorization: `Bearer ${localStorage.getItem("token")}`,
- },
+ const res = await axios.get('/api/sales', {
+ headers: { Authorization: `Bearer ${localStorage.getItem("token")}` }
})
-
- salesOptions.value = response.data.map(sales => ({
- value: sales.id,
- label: sales.nama
- }))
-
- if (salesOptions.value.length > 0) {
- selectedSales.value = salesOptions.value[0].value
- }
- } catch (error) {
- console.error('Error fetching sales:', error)
+ salesOptions.value = res.data.map(s => ({ value: s.id, label: s.nama }))
+ if (salesOptions.value.length > 0) selectedSales.value = salesOptions.value[0].value
+ } catch (e) {
+ console.error('Error fetching sales:', e)
}
}
+// 🟢 Generate kode hanya saat menyimpan transaksi
const handleSimpan = () => {
- if (!namaPembeli.value.trim()) {
- showSimpleToast('error', 'Nama pembeli harus diisi!')
- return
- }
+ if (!namaPembeli.value.trim()) return showSimpleToast('error', 'Nama pembeli harus diisi!')
+ if (!nomorTelepon.value.trim()) return showSimpleToast('error', 'Nomor telepon harus diisi!')
+ if (!alamat.value.trim()) return showSimpleToast('error', 'Alamat harus diisi!')
+ if (!selectedSales.value) return showSimpleToast('error', 'Sales harus dipilih!')
- if (!nomorTelepon.value.trim()) {
- showSimpleToast('error', 'Nomor telepon harus diisi!')
- return
- }
-
- if (!alamat.value.trim()) {
- showSimpleToast('error', 'Alamat harus diisi!')
- return
- }
-
- if (!selectedSales.value) {
- showSimpleToast('error', 'Sales harus dipilih!')
- return
- }
+ // Kode transaksi dibuat hanya saat simpan
+ transactionCode.value = generateTransactionCode()
simpanTransaksi({
+ kode_transaksi: transactionCode.value,
id_sales: selectedSales.value,
nama_pembeli: namaPembeli.value,
no_hp: nomorTelepon.value,
@@ -337,48 +285,37 @@ const handleSimpan = () => {
const simpanTransaksi = async (dataTransaksi) => {
if (isSaving.value) return
-
isSaving.value = true
try {
- const response = await axios.post('/api/transaksi', dataTransaksi, {
- headers: {
- Authorization: `Bearer ${localStorage.getItem("token")}`,
- },
- });
-
+ const res = await axios.post('/api/transaksi', dataTransaksi, {
+ headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
+ })
showSimpleToast('success', 'Transaksi berhasil disimpan!', 2000)
-
- // Emit event dengan data transaksi yang sudah disimpan
setTimeout(() => {
- emit('transaksi-saved', response.data);
- emit('close');
- }, 2200);
-
- } catch (error) {
- console.error('Error saving transaksi:', error);
- const errorMessage = error.response?.data?.message || error.message || 'Terjadi kesalahan saat menyimpan transaksi';
- showSimpleToast('error', `Error: ${errorMessage}`, 4000);
+ emit('transaksi-saved', res.data)
+ emit('close')
+ }, 2200)
+ } catch (err) {
+ const msg = err.response?.data?.message || err.message || 'Terjadi kesalahan saat menyimpan transaksi'
+ showSimpleToast('error', `Error: ${msg}`, 4000)
} finally {
isSaving.value = false
}
-};
+}
onMounted(() => {
- if (props.isOpen) {
- fetchSales()
- }
+ if (props.isOpen) fetchSales()
})
function formatInput(e) {
- let value = e.target.value.replace(/\D/g, "");
- ongkosBikin.value = value ? parseInt(value, 10) : null;
- ongkosBikinFormatted.value = value
- ? new Intl.NumberFormat("id-ID").format(value)
- : "";
+ let val = e.target.value.replace(/\D/g, "")
+ ongkosBikin.value = val ? parseInt(val, 10) : null
+ ongkosBikinFormatted.value = val ? new Intl.NumberFormat("id-ID").format(val) : ""
}
+