| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <script setup>
- import { computed, watchEffect } from 'vue'
- import { profit, ppn as ppnUtils } from '@/utils/helpers'
- import { optionStatus } from './config'
- import { cartTable } from './config'
- import Details from './Components/Details.vue'
- import Cart from './Components/Cart.vue'
- import { useCart } from './Composables/useCart'
- import { useDialog } from './Composables/useDialog'
- import { useForm } from '@/composables/useForm'
- import AppInputText from '@/components/AppInputText.vue'
- import AppInputNumber from '@/components/AppInputNumber.vue'
- import AppDropdown from '@/components/AppDropdown.vue'
- import AppAutoComplete from '@/components/AppAutoComplete.vue'
- import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
-
- const props = defineProps({
- number: String,
- ppn: Number,
- customers: {
- type: Array,
- default: [],
- },
- stockProducts: {
- type: Array,
- default: [],
- },
- })
-
- const form = useForm({
- status: 'success',
- price: null,
- qty: null,
- customer: null,
- product: null,
- ppn: props.ppn,
- checkedPpn: false,
- })
-
- const onSubmit = () => {
- form
- .transform((data) => ({
- number: props.number,
- status: data.status,
- ppn: data.checkedPpn,
- customer_id: data.customer.id,
- products: cart,
- }))
- .post(route('sales.store'), {
- onSuccess: () => {
- form.reset()
-
- onClearCart()
- },
- })
- }
-
- watchEffect(() => {
- if (form.product?.number) {
- form.price = profit(form.product.price, form.product.profit)
-
- form.qty = 1
- }
- })
-
- const dropdownStatus = computed(() => {
- return optionStatus.filter((val) => val.value != 'pending')
- })
-
- const productProductUnit = computed(() => form.product?.unit)
-
- const productProductPrice = computed(() => {
- if (form.product?.number) {
- return ppnUtils(form.product.price, form.product.ppn ? form.ppn : 0)
- }
- })
-
- const productProductPpn = computed(() => form.product?.ppn)
-
- const productProductQty = computed(() => form.product?.qty)
-
- const profitDescription = computed(() => {
- const priceProfit = profit(form.product?.price, form.product?.profit)
-
- return form.price === priceProfit ? true : false
- })
-
- const {
- cart,
- cartErrors,
- onAddCart,
- onClearCart,
- onDeleteCart,
- totalCartPrice,
- } = useCart(form)
-
- const { onShowCustomerCreate } = useDialog()
- </script>
-
- <template>
- <DashboardLayout title="Tambah Penjualan">
- <DynamicDialog />
-
- <div class="grid">
- <div class="col-12 xl:col-8">
- <div class="grid">
- <div class="col-12">
- <Card>
- <template #title> Transaksi </template>
- <template #content>
- <div class="grid">
- <div class="col-12 md:col-6">
- <AppDropdown
- label="Status"
- placeholder="status"
- :options="dropdownStatus"
- :error="form.errors.status"
- v-model="form.status"
- />
- </div>
-
- <div class="col-12 md:col-6">
- <AppAutoComplete
- empty
- label="Pelanggan"
- placeholder="pelanggan"
- field="name"
- param="customer"
- refresh-data="customers"
- v-model="form.customer"
- :error="form.errors.customer_id"
- :suggestions="customers"
- >
- <template #item="slotProps">
- <template v-if="slotProps.item">
- <div class="flex flex-column">
- <span>{{ slotProps.item.name }}</span>
- <span>{{ slotProps.item.phone }}</span>
- </div>
- </template>
- </template>
-
- <template #empty>
- <span
- class="cursor-pointer"
- style="color: var(--primary-color)"
- @click="onShowCustomerCreate"
- >
- Tambah Pelanggan
- </span>
- </template>
- </AppAutoComplete>
- </div>
- </div>
- </template>
- </Card>
- </div>
-
- <div class="col-12">
- <Card>
- <template #title>Produk</template>
- <template #content>
- <div class="grid">
- <div class="col-12 md:col-6">
- <AppAutoComplete
- empty
- label="Produk"
- placeholder="produk"
- field="name"
- param="stock_product"
- refresh-data="stockProducts"
- v-model="form.product"
- :disabled="!form.customer?.id"
- :error="form.errors.product"
- :suggestions="stockProducts"
- >
- <template #item="slotProps">
- <template v-if="slotProps.item">
- <div class="flex flex-column">
- <span>{{ slotProps.item.number }}</span>
- <span>{{ slotProps.item.name }}</span>
- </div>
- </template>
- </template>
- </AppAutoComplete>
- </div>
-
- <Divider type="dashed" />
-
- <div class="col-12">
- <h3 class="text-lg">Riwayat Pembelian Sebelumnya</h3>
- </div>
-
- <div class="col-12 md:col-6">
- <AppInputText
- disabled
- label="Satuan"
- placeholder="satuan"
- v-model="productProductUnit"
- />
- </div>
-
- <div class="col-12 md:col-6">
- <AppInputNumber
- disabled
- class="mb-0"
- label="Harga"
- placeholder="harga"
- v-model="productProductPrice"
- />
-
- <span v-if="productProductPpn" class="text-xs">
- Harga sudah termasuk PPN {{ ppn }} %
- </span>
- </div>
-
- <div class="col-12 md:col-6">
- <AppInputText
- disabled
- label="Stok Tersedia"
- placeholder="stok tersedia"
- type="number"
- v-model="productProductQty"
- />
- </div>
-
- <Divider type="dashed" />
-
- <div class="col-12 md:col-6">
- <AppInputNumber
- class="m-0"
- :disabled="!form.product?.number"
- label="Harga Jual"
- placeholder="harga jual"
- v-model="form.price"
- />
- <span v-if="profitDescription" class="text-xs">
- Sudah termasuk profit {{ form.product.profit }} %
- </span>
- </div>
-
- <div class="col-12 md:col-6">
- <AppInputText
- :disabled="!form.product?.number"
- label="Kuantitas"
- placeholder="kuantitas"
- type="number"
- :error="form.errors.qty"
- v-model="form.qty"
- />
- </div>
- </div>
- </template>
- <template #footer>
- <div class="flex flex-column md:flex-row justify-content-end">
- <Button
- label="Tambah Produk"
- icon="pi pi-check"
- class="p-button-outlined"
- :class="{ 'p-button-danger': cartErrors.length }"
- :disabled="
- !form.price || form.qty <= 0 || !form.product?.number
- "
- @click="onAddCart"
- />
- </div>
- </template>
- </Card>
- </div>
-
- <div class="col-12">
- <Cart
- title="Keranjang Produk"
- :cart="cart"
- :header-table="cartTable"
- :btn-edit-show="false"
- v-model:checked-ppn="form.checkedPpn"
- @delete="onDeleteCart"
- />
- </div>
- </div>
- </div>
-
- <div class="col-12 xl:col-4">
- <Details
- title="Detail Penjualan"
- message="Pastikan semua produk sudah benar"
- :number="number"
- :status="form.status"
- :person="form.customer"
- :product="form.product"
- :price="totalCartPrice()"
- :disabled="
- form.processing ||
- !form.status ||
- !form.customer?.id ||
- cart.length === 0
- "
- @submit="onSubmit"
- />
- </div>
- </div>
- </DashboardLayout>
- </template>
|