Browse Source

fix: purchase master

Muhammad Iqbal Afandi 3 years ago
parent
commit
460ef34eaa

+ 17
- 1
app/Http/Controllers/PurchaseController.php View File

@@ -127,7 +127,23 @@ class PurchaseController extends Controller
127 127
      */
128 128
     public function show(Purchase $purchase)
129 129
     {
130
-        //
130
+        return inertia("Purchases/Show", [
131
+            "id" => $purchase->id,
132
+            "number" => $purchase->number,
133
+            "ppn" => Ppn::first()->ppn,
134
+            "status" => $purchase->status,
135
+            "ppnChecked" => $purchase->ppn ? true : false,
136
+            "purchaseDetail" => $purchase->purchaseDetail->transform(
137
+                fn($purchase) => [
138
+                    "id" => $purchase->id,
139
+                    "number" => $purchase->product_number,
140
+                    "name" => $purchase->product->name,
141
+                    "price" => $purchase->price,
142
+                    "qty" => $purchase->qty,
143
+                    "unit" => $purchase->product->unit,
144
+                ]
145
+            ),
146
+        ]);
131 147
     }
132 148
 
133 149
     /**

+ 15
- 1
resources/js/pages/Purchases/Components/Cart.vue View File

@@ -14,6 +14,18 @@ defineProps({
14 14
     required: true,
15 15
     type: Array,
16 16
   },
17
+  btnEditShow: {
18
+    default: true,
19
+    type: Boolean,
20
+  },
21
+  btnDeleteShow: {
22
+    default: true,
23
+    type: Boolean,
24
+  },
25
+  btnPpnDisabled: {
26
+    default: false,
27
+    type: Boolean,
28
+  },
17 29
   checkedPpn: Boolean,
18 30
 })
19 31
 
@@ -42,6 +54,7 @@ const editingRows = ref([])
42 54
         <input
43 55
           type="checkbox"
44 56
           id="ppn"
57
+          :disabled="btnPpnDisabled"
45 58
           :checked="checkedPpn"
46 59
           @input="$emit('update:checkedPpn', $event.target.checked)"
47 60
         />
@@ -80,11 +93,12 @@ const editingRows = ref([])
80 93
       </template>
81 94
     </Column>
82 95
 
83
-    <Column :row-editor="true" />
96
+    <Column v-if="btnEditShow" :row-editor="true" />
84 97
 
85 98
     <Column>
86 99
       <template #body="{ index }">
87 100
         <Button
101
+          v-if="btnDeleteShow"
88 102
           icon="pi pi-trash"
89 103
           class="p-button-icon-only p-button-rounded p-button-text"
90 104
           v-tooltip.bottom="'hapus'"

+ 0
- 2
resources/js/pages/Purchases/Composables/useProductCart.js View File

@@ -54,8 +54,6 @@ export function useProductCart(form, initialProducts = []) {
54 54
 
55 55
   const onClearProductCartDelete = () => {
56 56
     productCartDeleted.splice(0)
57
-
58
-    console.info('this is running')
59 57
   }
60 58
 
61 59
   const totalProductPrice = () => {

+ 1
- 1
resources/js/pages/Purchases/Create.vue View File

@@ -79,7 +79,7 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
79 79
         <div class="grid">
80 80
           <div class="col-12">
81 81
             <Card>
82
-              <template #title> Penjual </template>
82
+              <template #title> Transaksi </template>
83 83
               <template #content>
84 84
                 <div class="grid">
85 85
                   <div class="col-12 md:col-6">

+ 1
- 1
resources/js/pages/Purchases/Edit.vue View File

@@ -70,7 +70,7 @@ const { onShowCreateProduct } = onShowDialog()
70 70
         <div class="grid">
71 71
           <div class="col-12">
72 72
             <Card>
73
-              <template #title> Penjual </template>
73
+              <template #title> Transaksi </template>
74 74
               <template #content>
75 75
                 <div class="grid">
76 76
                   <div class="col-12 md:col-6">

+ 9
- 0
resources/js/pages/Purchases/Index.vue View File

@@ -56,11 +56,20 @@ defineProps({
56 56
       <Column>
57 57
         <template #body="{ data }">
58 58
           <AppButtonLink
59
+            v-if="data.status == 'pending'"
59 60
             icon="pi pi-pencil"
60 61
             class="p-button-icon-only p-button-rounded p-button-text"
61 62
             v-tooltip.bottom="'Ubah Pembelian'"
62 63
             :href="route('purchases.edit', data.id)"
63 64
           />
65
+
66
+          <AppButtonLink
67
+            v-else
68
+            icon="pi pi-eye"
69
+            class="p-button-icon-only p-button-rounded p-button-text"
70
+            v-tooltip.bottom="'Lihat Pembelian'"
71
+            :href="route('purchases.show', data.id)"
72
+          />
64 73
         </template>
65 74
       </Column>
66 75
     </DataTable>

+ 74
- 0
resources/js/pages/Purchases/Show.vue View File

@@ -0,0 +1,74 @@
1
+<script setup>
2
+import { useForm } from '@/composables/useForm'
3
+import { IDRCurrencyFormat } from '@/utils/currencyFormat'
4
+import { cartTable } from './config'
5
+import Cart from './Components/Cart.vue'
6
+import { useProductCart } from './Composables/useProductCart'
7
+import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
8
+
9
+const props = defineProps({
10
+  number: String,
11
+  ppn: Number,
12
+  status: String,
13
+  ppnChecked: Boolean,
14
+  supplier: Object,
15
+  purchaseDetail: Array,
16
+})
17
+
18
+const form = useForm({
19
+  status: props.status,
20
+  supplier: props.supplier,
21
+  ppn: props.ppn,
22
+  checkedPpn: props.ppnChecked,
23
+})
24
+
25
+const { productCart, onDeleteProduct, onEditProduct, totalProductPrice } =
26
+  useProductCart(form, props.purchaseDetail)
27
+</script>
28
+
29
+<template>
30
+  <DashboardLayout title="Lihat Pembelian">
31
+    <DynamicDialog />
32
+
33
+    <div class="grid">
34
+      <div class="col-12 md:col-8">
35
+        <div class="grid">
36
+          <div class="col-12">
37
+            <Card>
38
+              <template #title>
39
+                <h2 class="text-2xl font-bold">Detail Pembelian</h2>
40
+              </template>
41
+              <template #content>
42
+                <div class="grid">
43
+                  <div class="col">
44
+                    <h3 class="text-base">Nomor Pembelian</h3>
45
+                    <span>{{ number }}</span>
46
+                  </div>
47
+                  <div class="col">
48
+                    <h3 class="text-base">Status Pembelian</h3>
49
+                    <span>{{ status }}</span>
50
+                  </div>
51
+                  <div class="col">
52
+                    <h3 class="text-base">Total Harga</h3>
53
+                    <span>{{ IDRCurrencyFormat(totalProductPrice()) }}</span>
54
+                  </div>
55
+                </div>
56
+              </template>
57
+            </Card>
58
+          </div>
59
+          <div class="col-12">
60
+            <Cart
61
+              title="Keranjang Produk"
62
+              :product-cart="productCart"
63
+              :header-table="cartTable"
64
+              :btn-ppn-disabled="true"
65
+              :btn-delete-show="false"
66
+              :btn-edit-show="false"
67
+              v-model:checked-ppn="form.checkedPpn"
68
+            />
69
+          </div>
70
+        </div>
71
+      </div>
72
+    </div>
73
+  </DashboardLayout>
74
+</template>

+ 7
- 2
resources/js/pages/Sales/Composables/useProductCart.js View File

@@ -48,10 +48,14 @@ export function useProductCart(form, initialProducts = []) {
48 48
     productCart.splice(index, 1)
49 49
   }
50 50
 
51
-  const onClearProduct = () => {
51
+  const onClearProductCart = () => {
52 52
     productCart.splice(0)
53 53
   }
54 54
 
55
+  const onClearProductCartDelete = () => {
56
+    productCartDeleted.splice(0)
57
+  }
58
+
55 59
   const totalProductPrice = () => {
56 60
     const productPrices = productCart.map((product) => {
57 61
       if (form.checkedPpn) {
@@ -76,10 +80,11 @@ export function useProductCart(form, initialProducts = []) {
76 80
   return {
77 81
     productCart,
78 82
     productCartDeleted,
83
+    onClearProductCart,
84
+    onClearProductCartDelete,
79 85
     onAddProduct,
80 86
     onDeleteProduct,
81 87
     onEditProduct,
82
-    onClearProduct,
83 88
     totalProductPrice,
84 89
   }
85 90
 }

+ 1
- 1
resources/js/pages/Sales/Create.vue View File

@@ -74,7 +74,7 @@ const { onShowCustomerCreate } = onShowDialog()
74 74
         <div class="grid">
75 75
           <div class="col-12">
76 76
             <Card>
77
-              <template #title> Pembeli </template>
77
+              <template #title> Transaksi </template>
78 78
               <template #content>
79 79
                 <div class="grid">
80 80
                   <div class="col-12 md:col-6">

+ 3
- 6
resources/js/pages/Sales/Edit.vue View File

@@ -43,17 +43,14 @@ const onSubmit = () => {
43 43
       products: [...productCart, ...productCartDeleted],
44 44
     }))
45 45
     .post(route('sales.store'), {
46
-      onSuccess: () => {
47
-        form.reset()
48
-
49
-        onClearProduct()
50
-      },
46
+      onSuccess: () => onClearProductCartDelete(),
51 47
     })
52 48
 }
53 49
 
54 50
 const {
55 51
   productCart,
56 52
   productCartDeleted,
53
+  onClearProductCartDelete,
57 54
   onAddProduct,
58 55
   onDeleteProduct,
59 56
   onEditProduct,
@@ -70,7 +67,7 @@ const {
70 67
         <div class="grid">
71 68
           <div class="col-12">
72 69
             <Card>
73
-              <template #title> Pembeli </template>
70
+              <template #title> Transaksi </template>
74 71
               <template #content>
75 72
                 <div class="grid">
76 73
                   <div class="col-12 md:col-6">