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