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