Server IP : 43.241.58.20 / Your IP : 216.73.216.25 Web Server : Apache/2 System : Linux ns1-1556229.dragonhispeed.com 3.16.0 #1 SMP Fri Mar 29 22:50:14 MSK 2024 x86_64 User : ratsitne ( 1130) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/ratsitne/.trash/files/admin/ |
Upload File : |
<div id="purchase-app"> <form method="POST" id="purchase-form" @submit.prevent="validateAndSubmit"> <div class="card"> <div class="card-header"> <h3 class="card-title">เพิ่มใบสั่งซื้อ/ใบรับสินค้า</h3> </div> <div class="card-body"> <div v-if="loading" class="d-flex justify-content-center my-5"> <div class="spinner-border text-primary" role="status"> <span class="visually-hidden">กำลังโหลด...</span> </div> </div> <template v-if="!loading"> <!-- Success message (Ajax response) --> <div v-if="formSuccess" class="alert alert-success alert-dismissible fade show"> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <i class="bi bi-check-circle me-1"></i> {{ formSuccess }} </div> <!-- Error message (Ajax response) --> <div v-if="formError" class="alert alert-danger alert-dismissible fade show"> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <i class="bi bi-exclamation-triangle me-1"></i> {{ formError }} </div> <div class="row"> <div class="col-md-8"> <div class="card"> <div class="card-header"> <h5 class="card-title">ข้อมูลผู้จำหน่าย</h5> </div> <div class="card-body"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="supplier_id">เลือกผู้จำหน่าย</label> <div class="input-group"> <input type="hidden" name="supplier_id" id="supplier_id" v-model="purchase.supplier_id"> <input type="text" class="form-control" v-model="purchase.supplier_name" readonly placeholder="คลิกที่ปุ่มเพื่อเลือกผู้จำหน่าย"> <button type="button" class="btn btn-primary" @click="openSupplierModal"> <i class="bi bi-search"></i> ค้นหาผู้จำหน่าย </button> </div> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="supplier_name">ชื่อผู้จำหน่าย/บริษัท</label> <input type="text" name="supplier_name" id="supplier_name" class="form-control" v-model="purchase.supplier_name" readonly required> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="supplier_taxid">เลขประจำตัวผู้เสียภาษี</label> <input type="text" name="supplier_taxid" id="supplier_taxid" class="form-control" v-model="purchase.supplier_taxid"> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="supplier_tel">เบอร์โทรศัพท์</label> <input type="text" name="supplier_tel" id="supplier_tel" class="form-control" v-model="purchase.supplier_tel"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="supplier_email">อีเมล</label> <input type="email" name="supplier_email" id="supplier_email" class="form-control" v-model="purchase.supplier_email"> </div> </div> </div> <div class="form-group"> <label for="supplier_address">ที่อยู่</label> <textarea name="supplier_address" id="supplier_address" class="form-control" rows="3" v-model="purchase.supplier_address"></textarea> </div> <div class="form-group"> <label for="supplier_branch">สำนักงาน/สาขา</label> <input type="text" name="supplier_branch" id="supplier_branch" class="form-control" v-model="purchase.supplier_branch"> </div> </div> </div> </div> <div class="col-md-4"> <div class="card"> <div class="card-header"> <h5 class="card-title">ข้อมูลเอกสาร</h5> </div> <div class="card-body"> <div class="form-group"> <label for="document_no">เลขที่เอกสาร</label> <div class="input-group"> <input type="text" name="document_no" id="document_no" class="form-control" v-model="purchase.document_no" :readonly="isEditMode || !manualDocumentNo"> <div class="input-group-append"> <div class="input-group-text"> <input type="checkbox" id="enable_manual_no" class="me-1" v-model="manualDocumentNo" :disabled="isEditMode"> <label for="enable_manual_no" class="mb-0">กำหนดเอง</label> </div> </div> </div> </div> <div class="form-group"> <label for="document_date">วันที่เอกสาร</label> <input type="text" name="document_date" id="document_date" class="form-control datepicker" v-model="purchase.document_date" required> </div> <div class="form-group"> <label for="due_date">วันครบกำหนด</label> <input type="text" name="due_date" id="due_date" class="form-control datepicker" v-model="purchase.due_date"> </div> <div class="form-group"> <label for="document_reference">เอกสารอ้างอิง</label> <input type="text" name="document_reference" id="document_reference" class="form-control" v-model="purchase.document_reference"> </div> </div> </div> </div> </div> <div class="card mt-3"> <div class="card-header"> <h5 class="card-title">รายการสินค้า</h5> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered" id="product-table"> <thead> <tr> <th style="width: 50px;">#</th> <th style="width: 400px;">รายการ</th> <th>รายละเอียด</th> <th class="text-end" style="width: 80px;">จำนวน</th> <th class="text-end" style="width: 100px;">ราคา</th> <th class="text-end" style="width: 150px;">รวม</th> <th style="width: 70px;">ลบ</th> </tr> </thead> <tbody> <tr class="product-row" v-for="(item, index) in items" :key="item.id"> <td>{{ index + 1 }}</td> <td> <div class="input-group"> <input type="hidden" :name="'product_id['+index+']'" v-model="item.product_id"> <input type="text" class="form-control" v-model="item.product_name" readonly placeholder="คลิกที่ปุ่มเพื่อเลือกสินค้า"> <button type="button" class="btn btn-primary" @click="openProductModal(index)"> <i class="bi bi-search"></i> ค้นหา </button> </div> </td> <td> <textarea :name="'product_description['+index+']'" class="form-control" v-model="item.product_description" rows="1" placeholder="รายละเอียดเพิ่มเติม ระบุหรือไม่ก็ได้"></textarea> </td> <td> <input type="number" :name="'quantity['+index+']'" class="form-control text-end" v-model.number="item.quantity" @input="updateRowTotal(index)" min="1" required> </td> <td> <input type="number" :name="'price['+index+']'" class="form-control text-end" v-model.number="item.price" @input="updateRowTotal(index)" step="0.01" min="0" required> </td> <td> <input type="number" :name="'total['+index+']'" class="form-control text-end" v-model.number="item.total" step="0.01" readonly> </td> <td> <button type="button" class="btn btn-danger" @click="removeProductRow(index)"><i class="bi bi-trash"></i></button> </td> </tr> </tbody> <tfoot> <tr> <td colspan="6"> <button type="button" class="btn btn-success" @click="addProductRow"><i class="bi bi-plus-circle me-1"></i>เพิ่มรายการ</button> </td> </tr> </tfoot> </table> </div> <div class="row mt-3"> <div class="col-md-6"> <div class="form-group"> <label for="notes">หมายเหตุ</label> <textarea name="notes" id="notes" class="form-control" rows="3" v-model="purchase.notes"></textarea> </div> </div> <div class="col-md-6"> <div class="card"> <div class="card-body"> <div class="form-group row"> <label class="col-sm-6 col-form-label text-end">มูลค่ารวมก่อนภาษี:</label> <div class="col-sm-6"> <input type="hidden" name="subtotal" id="subtotal" v-model.number="purchase.subtotal"> <div class="text-end fw-bold text-dark group-total">{{ formatNumber(purchase.subtotal) }}</div> </div> </div> <div class="form-group row"> <label class="col-sm-6 col-form-label text-end">ส่วนลด:</label> <div class="col-sm-6"> <input type="number" name="discount" id="discount" class="form-control text-end" step="0.01" v-model.number="purchase.discount"> </div> </div> <div class="form-group row"> <label class="col-sm-6 col-form-label text-end">ประเภทภาษี:</label> <div class="col-sm-6"> <select name="vat_type" id="vat_type" class="form-select" v-model="purchase.vat_type"> <option value="included">รวมภาษีมูลค่าเพิ่ม</option> <option value="excluded">แยกภาษีมูลค่าเพิ่ม</option> <option value="none">ไม่มีภาษีมูลค่าเพิ่ม</option> </select> </div> </div> <div class="form-group row" v-show="purchase.vat_type !== 'none'"> <label class="col-sm-6 col-form-label text-end">ภาษีมูลค่าเพิ่ม (%):</label> <div class="col-sm-6"> <input type="number" name="vat_rate" id="vat_rate" class="form-control text-end" step="0.01" v-model.number="purchase.vat_rate"> </div> </div> <div class="form-group row" v-show="purchase.vat_type !== 'none'"> <label class="col-sm-6 col-form-label text-end">ภาษีมูลค่าเพิ่ม:</label> <div class="col-sm-6"> <input type="hidden" name="vat" id="vat" v-model.number="purchase.vat"> <div class="text-end fw-bold text-dark group-total">{{ formatNumber(purchase.vat) }}</div> </div> </div> <div class="form-group row"> <label class="col-sm-6 col-form-label text-end fw-bold">ยอดรวมทั้งสิ้น:</label> <div class="col-sm-6"> <input type="hidden" name="grand_total" id="grand_total" v-model.number="purchase.grand_total"> <div class="text-end fw-bold group-total">{{ formatNumber(purchase.grand_total) }}</div> </div> </div> </div> </div> </div> </div> </div> </div> </template> </div> <div class="card-footer"> <button type="submit" class="btn btn-primary me-2" :disabled="submitting"> <span v-if="submitting" class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span> <i v-else class="bi bi-floppy me-1"></i> {{ submitting ? 'กำลังบันทึก...' : 'บันทึกข้อมูล' }} </button> <a href="<?php echo $admin_url . '/purchase-list.php'; ?>" class="btn btn-secondary">ย้อนกลับ</a> </div> </div> </form> <!-- Supplier Selection Modal --> <div class="modal fade" id="supplierModal" tabindex="-1" aria-labelledby="supplierModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="supplierModalLabel">เลือกผู้จำหน่าย</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="row mb-3"> <div class="col-md-8"> <div class="input-group"> <input type="text" class="form-control" v-model="supplierSearch" placeholder="ค้นหาชื่อผู้จำหน่าย, เลขประจำตัวผู้เสียภาษี"> <button class="btn btn-outline-secondary" type="button" @click="searchSuppliers"> <i class="bi bi-search"></i> ค้นหา </button> </div> </div> </div> <div class="table-responsive"> <div v-if="isLoading" class="text-center p-4"> <div class="spinner-border text-primary" role="status"> <span class="visually-hidden">กำลังโหลด...</span> </div> <p class="mt-2">กำลังโหลดข้อมูล...</p> </div> <table class="table table-bordered table-striped" v-else> <thead> <tr> <th>ชื่อบริษัท</th> <th>ชื่อติดต่อ</th> <th>เลขประจำตัวผู้เสียภาษี</th> <th>จัดการ</th> </tr> </thead> <tbody> <tr v-if="suppliers.length === 0"> <td colspan="5" class="text-center">ไม่พบข้อมูลผู้จำหน่าย</td> </tr> <tr v-for="supplier in suppliers" :key="supplier.id"> <td>{{ supplier.company_name }}</td> <td>{{ supplier.contact_name }}</td> <td>{{ supplier.tax_id }}</td> <td> <button type="button" class="btn btn-primary btn-sm" @click="selectSupplierFromModal(supplier)"> <i class="bi bi-check-circle"></i> เลือก </button> </td> </tr> </tbody> </table> </div> <div class="row" v-if="suppliers.length > 0"> <div class="col-md-6"> <p>แสดง {{ (currentPage - 1) * perPage + 1 }}-{{ Math.min(currentPage * perPage, totalSuppliers) }} จาก {{ totalSuppliers }} รายการ</p> </div> <div class="col-md-6"> <nav aria-label="Page navigation"> <ul class="pagination justify-content-end"> <li class="page-item" :class="{ disabled: currentPage === 1 }"> <a class="page-link" href="#" @click.prevent="changePage(currentPage - 1)">ก่อนหน้า</a> </li> <li v-for="page in totalPages" :key="page" class="page-item" :class="{ active: currentPage === page }"> <a class="page-link" href="#" @click.prevent="changePage(page)">{{ page }}</a> </li> <li class="page-item" :class="{ disabled: currentPage === totalPages || totalPages === 0 }"> <a class="page-link" href="#" @click.prevent="changePage(currentPage + 1)">ถัดไป</a> </li> </ul> </nav> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ปิด</button> </div> </div> </div> </div> <!-- Product Selection Modal --> <div class="modal fade" id="productModal" tabindex="-1" aria-labelledby="productModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="productModalLabel">เลือกสินค้า</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="row mb-3"> <div class="col-md-8"> <div class="input-group"> <input type="text" class="form-control" v-model="productSearch" placeholder="ค้นหาชื่อสินค้า, รหัสสินค้า"> <button class="btn btn-primary" type="button" @click="searchProducts"> <i class="bi bi-search"></i> ค้นหา </button> </div> </div> <div class="col-md-4"> <select class="form-select" v-model="productCategoryFilter"> <option value="">-- ทุกหมวดหมู่ --</option> <option v-for="category in categories" :key="category.id" :value="category.id">{{ category.category_name }}</option> </select> </div> </div> <div class="table-responsive"> <div v-if="productLoading" class="text-center p-4"> <div class="spinner-border text-primary" role="status"> <span class="visually-hidden">กำลังโหลด...</span> </div> <p class="mt-2">กำลังโหลดข้อมูล...</p> </div> <table class="table table-bordered table-striped" v-else> <thead> <tr> <th>รหัสสินค้า</th> <th>ชื่อสินค้า</th> <th>หมวดหมู่</th> <th>ราคาซื้อ</th> <th>จัดการ</th> </tr> </thead> <tbody> <tr v-if="filteredProducts.length === 0"> <td colspan="5" class="text-center">ไม่พบข้อมูลสินค้า</td> </tr> <tr v-for="product in filteredProducts" :key="product.id"> <td>{{ product.sku }}</td> <td>{{ product.name }}</td> <td>{{ product.category_name }}</td> <td>{{ product.purchase_price }}</td> <td> <button type="button" class="btn btn-primary btn-sm" @click="selectProductFromModal(product)"> <i class="bi bi-check-circle"></i> เลือก </button> </td> </tr> </tbody> </table> </div> <div class="row" v-if="filteredProducts.length > 0"> <div class="col-md-6"> <p>แสดง {{ (productCurrentPage - 1) * productPerPage + 1 }}-{{ Math.min(productCurrentPage * productPerPage, totalProducts) }} จาก {{ totalProducts }} รายการ</p> </div> <div class="col-md-6"> <nav aria-label="Page navigation"> <ul class="pagination justify-content-end"> <li class="page-item" :class="{ disabled: productCurrentPage === 1 }"> <a class="page-link" href="#" @click.prevent="changeProductPage(productCurrentPage - 1)">ก่อนหน้า</a> </li> <li v-for="page in productTotalPages" :key="page" class="page-item" :class="{ active: productCurrentPage === page }"> <a class="page-link" href="#" @click.prevent="changeProductPage(page)">{{ page }}</a> </li> <li class="page-item" :class="{ disabled: productCurrentPage === productTotalPages || productTotalPages === 0 }"> <a class="page-link" href="#" @click.prevent="changeProductPage(productCurrentPage + 1)">ถัดไป</a> </li> </ul> </nav> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ปิด</button> </div> </div> </div> </div> </div>