Create.vue 7.8KB

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