Create.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <script setup>
  2. import { optionStatus } from './config'
  3. import { cartTable } from './config'
  4. import Details from './Components/Details.vue'
  5. import Cart from './Components/Cart.vue'
  6. import { useProductCart } from './Composables/useProductCart'
  7. import { onShowDialog } from './Composables/onShowDialog'
  8. import { useForm } from '@/composables/useForm'
  9. import AppInputText from '@/components/AppInputText.vue'
  10. import AppInputNumber from '@/components/AppInputNumber.vue'
  11. import AppDropdown from '@/components/AppDropdown.vue'
  12. import AppAutoComplete from '@/components/AppAutoComplete.vue'
  13. import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
  14. import { computed } from '@vue/reactivity'
  15. const props = defineProps({
  16. number: String,
  17. ppn: Number,
  18. suppliers: {
  19. type: Array,
  20. default: [],
  21. },
  22. products: {
  23. type: Array,
  24. default: [],
  25. },
  26. })
  27. const form = useForm({
  28. status: 'pending',
  29. price: null,
  30. qty: null,
  31. supplier: null,
  32. product: null,
  33. ppn: props.ppn,
  34. checkedPpn: false,
  35. })
  36. const onSubmit = () => {
  37. form
  38. .transform((data) => ({
  39. number: props.number,
  40. status: data.status,
  41. ppn: data.checkedPpn,
  42. supplier_id: data.supplier.id,
  43. products: productCart,
  44. }))
  45. .post(route('purchases.store'), {
  46. onSuccess: () => {
  47. form.reset()
  48. onClearProductCart()
  49. },
  50. })
  51. }
  52. const dropdownStatus = computed(() => {
  53. return optionStatus.filter((val) => val.value != 'success')
  54. })
  55. const {
  56. productCart,
  57. onClearProductCart,
  58. onAddProduct,
  59. onDeleteProduct,
  60. onEditProduct,
  61. totalProductPrice,
  62. } = useProductCart(form)
  63. const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
  64. </script>
  65. <template>
  66. <DashboardLayout title="Tambah Pembelian">
  67. <DynamicDialog />
  68. <div class="grid">
  69. <div class="col-12 md:col-8">
  70. <div class="grid">
  71. <div class="col-12">
  72. <Card>
  73. <template #title> Transaksi </template>
  74. <template #content>
  75. <div class="grid">
  76. <div class="col-12 md:col-6">
  77. <AppDropdown
  78. label="Status"
  79. placeholder="status"
  80. :options="dropdownStatus"
  81. :error="form.errors.status"
  82. v-model="form.status"
  83. />
  84. </div>
  85. <div class="col-12 md:col-6">
  86. <AppAutoComplete
  87. empty
  88. label="Supplier"
  89. placeholder="supplier"
  90. field="name"
  91. refresh-data="suppliers"
  92. v-model="form.supplier"
  93. :error="form.errors.suppliers_id"
  94. :suggestions="suppliers"
  95. >
  96. <template #item="slotProps">
  97. <template v-if="slotProps.item">
  98. <div class="flex flex-column">
  99. <span>{{ slotProps.item.name }}</span>
  100. <span>{{ slotProps.item.phone }}</span>
  101. </div>
  102. </template>
  103. </template>
  104. <template #empty>
  105. <span
  106. class="cursor-pointer"
  107. style="color: var(--primary-color)"
  108. @click="onShowCreateSupplier"
  109. >
  110. Tambah Supplier
  111. </span>
  112. </template>
  113. </AppAutoComplete>
  114. </div>
  115. </div>
  116. </template>
  117. </Card>
  118. </div>
  119. <div class="col-12">
  120. <Card>
  121. <template #title>Produk</template>
  122. <template #content>
  123. <div class="grid">
  124. <div class="col-12 md:col-6">
  125. <AppAutoComplete
  126. :disabled="!form.supplier?.id"
  127. empty
  128. label="Produk"
  129. placeholder="produk"
  130. field="name"
  131. refresh-data="products"
  132. v-model="form.product"
  133. :error="form.errors.products"
  134. :suggestions="products"
  135. >
  136. <template #item="slotProps">
  137. <template v-if="slotProps.item">
  138. <div class="flex flex-column">
  139. <span>{{ slotProps.item.number }}</span>
  140. <span>{{ slotProps.item.name }}</span>
  141. </div>
  142. </template>
  143. </template>
  144. <template #empty>
  145. <span
  146. class="cursor-pointer"
  147. style="color: var(--primary-color)"
  148. @click="onShowCreateProduct"
  149. >
  150. Tambah Produk
  151. </span>
  152. </template>
  153. </AppAutoComplete>
  154. </div>
  155. <div v-if="form.product?.number" class="col-12 md:col-6">
  156. <AppInputText
  157. disabled
  158. label="Satuan"
  159. placeholder="satuan"
  160. v-model="form.product.unit"
  161. />
  162. </div>
  163. <div class="col-12 md:col-6">
  164. <AppInputNumber
  165. :disabled="!form.supplier?.id"
  166. label="Harga"
  167. placeholder="harga"
  168. v-model="form.price"
  169. />
  170. </div>
  171. <div class="col-12 md:col-6">
  172. <AppInputText
  173. :disabled="!form.supplier?.id"
  174. label="Kuantitas"
  175. placeholder="kuantitas"
  176. type="number"
  177. v-model="form.qty"
  178. />
  179. </div>
  180. </div>
  181. </template>
  182. <template #footer>
  183. <div class="flex flex-column md:flex-row justify-content-end">
  184. <Button
  185. label="Tambah Produk"
  186. icon="pi pi-check"
  187. class="p-button-outlined"
  188. :disabled="
  189. !form.price || !form.qty || !form.product?.number
  190. "
  191. @click="onAddProduct"
  192. />
  193. </div>
  194. </template>
  195. </Card>
  196. </div>
  197. <div class="col-12">
  198. <Cart
  199. title="Keranjang Produk"
  200. :product-cart="productCart"
  201. :header-table="cartTable"
  202. v-model:checked-ppn="form.checkedPpn"
  203. @delete="onDeleteProduct"
  204. @edit="onEditProduct"
  205. />
  206. </div>
  207. </div>
  208. </div>
  209. <div class="col-12 md:col-4">
  210. <Details
  211. title="Detail Pembelian"
  212. message="Pastikan semua produk sudah benar"
  213. :number="number"
  214. :status="form.status"
  215. :person="form.supplier"
  216. :product="form.product"
  217. :price="totalProductPrice()"
  218. :disabled="
  219. form.processing ||
  220. !form.status ||
  221. !form.supplier?.id ||
  222. productCart.length === 0
  223. "
  224. @submit="onSubmit"
  225. />
  226. </div>
  227. </div>
  228. </DashboardLayout>
  229. </template>