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