248 lines
8.1 KiB
PHP
248 lines
8.1 KiB
PHP
<?php
|
|
include __DIR__ . '/layout_sales.php';
|
|
sales_layout_start("영업실적");
|
|
?>
|
|
|
|
<h2 class="text-2xl font-bold mb-4">영업실적</h2>
|
|
|
|
<button class="bg-blue-600 text-white px-4 py-2 rounded mb-3" id="btn-add-result">
|
|
신규 실적 등록
|
|
</button>
|
|
|
|
<div id="grid_results" style="width:100%;height:720px;"></div>
|
|
|
|
<script type="module">
|
|
import { w2grid } from "https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.es6.min.js";
|
|
|
|
let grid = new w2grid({
|
|
name: 'grid_results',
|
|
box: '#grid_results',
|
|
|
|
show: {
|
|
toolbar: true,
|
|
footer: true,
|
|
toolbarSave: true,
|
|
toolbarReload: true,
|
|
toolbarSearch: true,
|
|
toolbarColumns: true,
|
|
lineNumbers: true
|
|
},
|
|
|
|
multiSearch: true,
|
|
|
|
searches: [
|
|
{ field: 'sales_date', label: '실적일', type: 'date' },
|
|
{ field: 'emp_no', label: '사번', type: 'text' },
|
|
{ field: 'client_code', label: '거래처코드', type: 'text' },
|
|
{ field: 'product_code', label: '제품코드', type: 'text' },
|
|
{ field: 'remarks', label: '비고', type: 'text' },
|
|
],
|
|
|
|
columns: [
|
|
// { field: 'seq_no', text: '번호', size: '70px' },
|
|
{ field: 'sales_date', text: '실적일', size: '110px', editable: { type: 'date' }, sortable: true },
|
|
{ field: 'emp_no', text: '사번', size: '110px', editable: { type: 'text' }, sortable: true },
|
|
{ field: 'client_code', text: '거래처코드', size: '120px', editable: { type: 'text' }, sortable: true },
|
|
{ field: 'product_code', text: '제품코드', size: '120px', editable: { type: 'text' }, sortable: true },
|
|
|
|
{ field: 'quantity', text: '수량', size: '80px',
|
|
editable: { type: 'int' }, sortable: true,
|
|
style: 'text-align:right' },
|
|
|
|
{ field: 'unit_price', text: '단가', size: '100px',
|
|
editable: { type: 'float' }, sortable: true,
|
|
style: 'text-align:right' },
|
|
|
|
{ field: 'discount', text: '할인액', size: '100px',
|
|
editable: { type: 'float' }, sortable: true,
|
|
style: 'text-align:right' },
|
|
|
|
{ field: 'total_amount', text: '총금액', size: '120px',
|
|
editable: { type: 'float' }, sortable: true,
|
|
style: 'text-align:right' },
|
|
|
|
{ field: 'remarks', text: '비고', size: '200px', editable: { type: 'text' }, sortable: true },
|
|
{ field: 'created_at', text: '등록일', size: '160px', sortable: true }
|
|
],
|
|
|
|
toolbar: {
|
|
items: [
|
|
{ id: 'add', type: 'button', text: '추가', icon: 'w2ui-icon-plus' },
|
|
{ id: 'delete', type: 'button', text: '삭제', icon: 'w2ui-icon-cross' }
|
|
],
|
|
|
|
onClick(event) {
|
|
const g = this.owner;
|
|
|
|
// reload
|
|
if (event.target === 'w2ui-reload') {
|
|
loadResults();
|
|
return;
|
|
}
|
|
|
|
// ADD
|
|
if (event.target === 'add') {
|
|
const newId = "new-" + Math.random().toString(36).substr(2, 9);
|
|
|
|
g.add({
|
|
recid: newId,
|
|
sales_date: "",
|
|
emp_no: "",
|
|
client_code: "",
|
|
product_code: "",
|
|
quantity: 0,
|
|
unit_price: 0,
|
|
discount: 0,
|
|
total_amount: 0,
|
|
remarks: "",
|
|
created_at: ""
|
|
});
|
|
|
|
g.refresh();
|
|
updateSummary();
|
|
return;
|
|
}
|
|
|
|
// DELETE
|
|
if (event.target === 'delete') {
|
|
const sel = g.getSelection();
|
|
if (!sel.length) return;
|
|
|
|
w2confirm("정말 삭제하시겠습니까?").yes(() => {
|
|
sel.forEach(id => {
|
|
|
|
// 신규행 삭제
|
|
if (String(id).startsWith("new-")) {
|
|
g.remove(id);
|
|
return;
|
|
}
|
|
|
|
fetch("/egbim/bbs/sales_results.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
body: new URLSearchParams({
|
|
action: "delete",
|
|
seq_no: id
|
|
})
|
|
});
|
|
|
|
g.remove(id);
|
|
});
|
|
updateSummary();
|
|
});
|
|
}
|
|
}
|
|
},
|
|
|
|
// SAVE (insert + update)
|
|
onSave(event) {
|
|
const changes = this.getChanges();
|
|
if (!changes.length) return;
|
|
|
|
Promise.all(
|
|
changes.map(ch => {
|
|
|
|
if (String(ch.recid).startsWith("new-")) {
|
|
// INSERT
|
|
return fetch("/egbim/bbs/sales_results.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
body: new URLSearchParams({
|
|
action: "insert",
|
|
sales_date: ch.sales_date,
|
|
emp_no: ch.emp_no,
|
|
client_code: ch.client_code,
|
|
product_code: ch.product_code,
|
|
quantity: ch.quantity,
|
|
unit_price: ch.unit_price,
|
|
discount: ch.discount,
|
|
total_amount: ch.total_amount,
|
|
remarks: ch.remarks
|
|
})
|
|
});
|
|
}
|
|
|
|
// UPDATE
|
|
return fetch("/egbim/bbs/sales_results.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
body: new URLSearchParams({
|
|
action: "update",
|
|
seq_no: ch.recid,
|
|
sales_date: ch.sales_date,
|
|
emp_no: ch.emp_no,
|
|
client_code: ch.client_code,
|
|
product_code: ch.product_code,
|
|
quantity: ch.quantity,
|
|
unit_price: ch.unit_price,
|
|
discount: ch.discount,
|
|
total_amount: ch.total_amount,
|
|
remarks: ch.remarks
|
|
})
|
|
});
|
|
|
|
})
|
|
).then(() => {
|
|
loadResults();
|
|
w2alert("저장되었습니다!");
|
|
});
|
|
}
|
|
});
|
|
|
|
// LOAD
|
|
function loadResults() {
|
|
fetch("/egbim/bbs/sales_results.php?action=list")
|
|
.then(r => r.json())
|
|
.then(res => {
|
|
if (res.status === "ok") {
|
|
grid.records = res.records.map(r => ({
|
|
recid: r.seq_no,
|
|
...r
|
|
}));
|
|
updateSummary();
|
|
grid.refresh();
|
|
}
|
|
});
|
|
}
|
|
|
|
loadResults();
|
|
|
|
//합계
|
|
function updateSummary() {
|
|
|
|
let sumQty = 0;
|
|
let sumUnit = 0;
|
|
let sumDiscount = 0;
|
|
let sumTotal = 0;
|
|
|
|
grid.records.forEach(r => {
|
|
sumQty += Number(r.quantity || 0);
|
|
sumUnit += Number(r.unit_price || 0);
|
|
sumDiscount += Number(r.discount || 0);
|
|
sumTotal += Number(r.total_amount || 0);
|
|
});
|
|
|
|
grid.summary = [
|
|
{
|
|
recid: 'summary',
|
|
sales_date: '<span style="float:right;font-weight:bold;">합계</span>',
|
|
quantity: sumQty,
|
|
unit_price: sumUnit,
|
|
discount: sumDiscount,
|
|
total_amount: sumTotal,
|
|
w2ui: { summary: true }
|
|
}
|
|
];
|
|
|
|
grid.refresh();
|
|
}
|
|
|
|
//천단위
|
|
function numberFormat(num) {
|
|
if (num === null || num === undefined || num === "") return "-";
|
|
return Number(num).toLocaleString('ko-KR');
|
|
}
|
|
</script>
|
|
|
|
<?php sales_layout_end(); ?>
|