Create.vue 7.4KB

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