From 5542acb4cf71daa3c7b1a3555da63057be70fe47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Thu, 12 Sep 2024 17:30:25 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 199 +++++++++++++ Views/Home/ProjectList.cshtml | 5 +- .../assets/javascript/custom/projectlist.js | 266 +++++++++++++++++- 3 files changed, 465 insertions(+), 5 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 81d33050..efbc8355 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json; using Org.BouncyCastle.Bcpg.OpenPgp; using NPOI.OpenXmlFormats.Shared; using NPOI.SS.Formula.PTG; +using System.Data; namespace QuotationMaker.Controllers { @@ -72,6 +73,204 @@ namespace QuotationMaker.Controllers quotation_specTotal = "0"; }; + if (method == "del") { + quotation objQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid order by quotation_version desc", new { quotation_uid = quotation_uid }); + + if (objQuotation == null) + { + ret.ret = "no"; + ret.err_code = "0009"; + ret.message = "此筆資料不存在或已被刪除!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + objQuotation.quotation_isdel = "Y"; + objQuotation.quotation_modifydate = DateTime.Now; + objQuotation.quotation_modify_uid = token.user_uid; + objQuotation.quotation_log = token.user_name + " 刪除了此張報價單!"; + + conn.Update(objQuotation); + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "edit") + { + quotation oldQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_version = @quotation_version and quotation_uid = @quotation_uid ", new { quotation_version = quotation_version, quotation_uid = quotation_uid }); + + if (oldQuotation == null) + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "找不到此筆報價單資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + quotation lastVerQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid order by quotation_version desc ", new { quotation_uid = quotation_uid }); + + if (lastVerQuotation == null) + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "找不到此筆報價單資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + int new_version = lastVerQuotation.quotation_version + 1; + + //--- start update + quotation objQuotation = new quotation(); + + //quotation_log = quotation_log; + //quotation_uid = quotation_uid; + quotation_version = new_version.ToString(); + objQuotation.quotation_uid = quotation_uid; + objQuotation.quotation_version = int.Parse(quotation_version); + objQuotation.dept_uid = dept_uid; + objQuotation.quotation_prodMethod = lastVerQuotation.quotation_prodMethod; + objQuotation.quotation_date = quotation_date; + objQuotation.quotation_expStart = quotation_expStart; + objQuotation.quotation_expEnd = quotation_expEnd; + objQuotation.quotation_name = quotation_name; + objQuotation.project_uid = project_uid; + objQuotation.contactPerson_uid = contactPerson_uid; + objQuotation.company_uid = company_uid; + objQuotation.quotation_log = quotation_log; + objQuotation.quotation_create_uid = oldQuotation.quotation_create_uid; + objQuotation.quotation_modify_uid = token.user_uid; + objQuotation.quotation_noTaxTotal = double.Parse(quotation_noTaxTotal); + objQuotation.quotation_specTotal = double.Parse(quotation_specTotal); + objQuotation.quotation_tax = double.Parse(quotation_tax); + objQuotation.quotation_grandTotal = double.Parse(quotation_grandTotal); + objQuotation.quotation_sa = quotation_sa; + objQuotation.quotation_isdel = quotation_isdel; + objQuotation.quotation_revoke = quotation_revoke; + objQuotation.quotation_createdate = DateTime.Now; + objQuotation.quotation_modifydate = DateTime.Now; + + dynamic mainItems_Json; + dynamic payments_Json; + dynamic invoices_Json; + + try + { + mainItems_Json = JsonConvert.DeserializeObject(mainItems_jsonstr); + payments_Json = JsonConvert.DeserializeObject(payments_jsonstr); + invoices_Json = JsonConvert.DeserializeObject(invoices_jsonstr); + + } + catch (Exception ex) + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "mainItems or payments or invoices json error," + ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + List quotationMainItems = new List(); + List quotationSubItems = new List(); + + foreach (dynamic item in mainItems_Json) + { + string quotationMainItem_uid = "qm_" + GlobalClass.CreateRandomCode(24); + + quotationMainItem newItem = new quotationMainItem(); + newItem.quotation_uid = quotation_uid; + newItem.mainItem_uid = item.mainItem_uid; + newItem.quotationMainItem_uid = quotationMainItem_uid; + newItem.quotationMainItem_name = item.quotationMainItem_name; + newItem.quotationMainItem_ac = double.Parse((string)item.quotationMainItem_ac); + newItem.quotationMainItem_subTotal = double.Parse((string)item.quotationMainItem_subTotal); + newItem.quotationMainItem_revoke = "N"; + newItem.quotationMainItem_version = int.Parse((string)quotation_version); + + quotationMainItems.Add(newItem); + + foreach (dynamic subItem in item.subitems) + { + quotationSubItem newSubItem = new quotationSubItem(); + newSubItem.quotationSubItem_uid = "qs" + GlobalClass.CreateRandomCode(24); + newSubItem.quotationMainItem_uid = quotationMainItem_uid; + newSubItem.quotation_uid = quotation_uid; + newSubItem.subItem_uid = subItem.subItem_uid; + newSubItem.quotationSubItem_name = subItem.quotationSubItem_name; + newSubItem.quotationSubItem_descript = subItem.quotationSubItem_descript; + newSubItem.quotationSubItem_price = double.Parse((string)subItem.quotationSubItem_price); + newSubItem.quotationSubItem_unitType = subItem.quotationSubItem_unitType; + newSubItem.quotationSubItem_number = double.Parse((string)subItem.quotationSubItem_number); + newSubItem.quotationSubItem_subTotal = double.Parse((string)subItem.quotationSubItem_subTotal); + newSubItem.quotationSubItem_hasAC = subItem.quotationSubItem_hasAC; + newSubItem.quotationSubItem_revoke = "N"; + newSubItem.quotationSubItem_version = int.Parse((string)quotation_version); + + quotationSubItems.Add(newSubItem); + } + } + + List payments = new List(); + + foreach (dynamic item in payments_Json) + { + payment newItem = new payment(); + + newItem.payment_uid = "pay_" + GlobalClass.CreateRandomCode(20); + newItem.quotation_uid = quotation_uid; + newItem.payment_method = item.payment_method; + newItem.payment_methodname = item.payment_methodname; + newItem.payment_descript = item.payment_descript; + newItem.payment_revoke = "N"; + newItem.payment_version = int.Parse((string)quotation_version); + + payments.Add(newItem); + } + + List invoices = new List(); + + foreach (dynamic item in invoices_Json) + { + invoice newItem = new invoice(); + + newItem.invoice_uid = "inv_" + GlobalClass.CreateRandomCode(20); + newItem.quotation_uid = quotation_uid; + newItem.invoice_name = item.invoice_name; + + string yearmonth = item.invoice_date; + string strYear = yearmonth.Split('/')[0]; + string strMonth = yearmonth.Split("/")[1]; + + newItem.invoice_year = int.Parse(strYear); + newItem.invoice_month = int.Parse(strMonth); + newItem.invoice_noTaxMoney = int.Parse((string)item.invoice_noTaxMoney); + newItem.invoice_revoke = "N"; + newItem.invoice_version = int.Parse((string)quotation_version); + + invoices.Add(newItem); + } + + string old_version = lastVerQuotation.quotation_version.ToString(); + + conn.Execute("update invoice set invoice_revoke = 'Y', invoice_modifydate = @invoice_modifydate where quotation_uid = @quotation_uid and invoice_version = @quotation_version ", new { invoice_modifydate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), quotation_uid = quotation_uid, quotation_version = old_version }); + conn.Execute("update payment set payment_revoke = 'Y', payment_modifydate = @payment_modifydate where quotation_uid = @quotation_uid and payment_version = @quotation_version ", new { payment_modifydate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), quotation_uid = quotation_uid, quotation_version = old_version }); + conn.Execute("update quotationSubItem set quotationSubItem_revoke = 'Y', quotationSubItem_modifydate = @quotationSubItem_modifydate where quotation_uid = @quotation_uid and quotationSubItem_version = @quotation_version ", new { quotationSubItem_modifydate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), quotation_uid = quotation_uid, quotation_version = old_version }); + conn.Execute("update quotationMainItem set quotationMainItem_revoke = 'Y', quotationMainItem_modifydate = @quotationMainItem_modifydate where quotation_uid = @quotation_uid and quotationMainItem_version = @quotation_version ", new { quotationMainItem_modifydate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), quotation_uid = quotation_uid, quotation_version = old_version }); + conn.Execute("update quotation set quotation_modify_uid = @quotation_modify_uid, quotation_revoke = 'Y', quotation_modifydate = @quotation_modifydate where quotation_uid = @quotation_uid and quotation_version = @quotation_version ", new { quotation_modify_uid = token.user_uid, quotation_modifydate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), quotation_uid = quotation_uid, quotation_version = old_version }); + + + + conn.Insert(invoices); + conn.Insert(payments); + conn.Insert(quotationSubItems); + conn.Insert(quotationMainItems); + conn.Insert(objQuotation); + + //--- end update + ret.quotationView = conn.QueryFirstOrDefault("select * from quotationView where quotation_uid = @quotation_uid and quotation_isdel = 'N' and quotation_revoke = 'N' ", new { quotation_uid = quotation_uid }); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + if (method == "get") { quotation objQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid order by quotation_version desc", new { quotation_uid = quotation_uid }); diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index f59ebbbd..cd5b8177 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -367,13 +367,14 @@
+
+
-
-
+
diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index 3059cfcd..cf3d2a8f 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -157,6 +157,10 @@ $(document).ready(function () { deledPayments = []; deledInvoices = []; + $('#modelItem_div').html(''); + $('#payment_group').find('ol').html(''); + $('#invoice_group').find('ol').html(''); + quotation_total = 0; $('#quotation_editType_div').show(); @@ -608,6 +612,7 @@ $(document).ready(function () { var htmlCode = ''; htmlCode += '
  • \n'; + htmlCode += ' '; htmlCode += ' '; htmlCode += ' '; htmlCode += ' '; @@ -661,6 +666,7 @@ $(document).ready(function () { var htmlCode = ''; htmlCode += '
  • \n'; + htmlCode += ' '; htmlCode += ' '; htmlCode += ' '; htmlCode += ' '; @@ -730,6 +736,8 @@ $(document).ready(function () { var quotation_log = ''; + + if ($('#quotation_custom').prop('checked') == true) { quotation_prodMethod = 'custom'; } @@ -771,7 +779,7 @@ $(document).ready(function () { quotation_log += '實際總價由 ' + AppendComma(quotation_grandTotal_old) + ' 變更為 ' + AppendComma(quotation_grandTotal) + '\n'; } - if (quotation_sa != cquotation_sa_old) { + if (quotation_sa != quotation_sa_old) { quotation_log += '製作及維護服務協議條款內容有所變更\n'; } @@ -860,6 +868,12 @@ $(document).ready(function () { subitems.push(subItemFormData); + if (data_method == 'add' && quotation_method == 'edit') { + if (quotationSubItem_name != quotationSubItem_name_old) { + quotation_log += '報價主項目 [' + quotationMainItem_name + '] 中新增子項目 [' + quotationSubItem_name + '] \n'; + } + } + if (data_method == 'edit') { if (quotationSubItem_name != quotationSubItem_name_old) { quotation_log += '報價主項目 [' + quotationMainItem_name + '] 的子項目名稱由 [' + quotationSubItem_name_old + '] 更改為 [' + quotationSubItem_name + '] \n'; @@ -911,6 +925,10 @@ $(document).ready(function () { var payment_methodname = $(item).find('[data-name="payment_methodname"]').val(); var payment_descript = $(item).find('[data-name="payment_descript"]').val(); + var data_method = $(item).find('[data-name="data_method"]').val(); + if (quotation_method == 'edit' && data_method == 'add') { + quotation_log += '付款方式增加了 [' + payment_methodname + ' - ' + payment_descript + ']\n'; + } var paymentFormData = { payment_method: payment_method, @@ -927,7 +945,11 @@ $(document).ready(function () { var invoice_name = $(item).find('[data-name="invoice_name"]').val(); var invoice_date = $(item).find('[data-name="invoice_date"]').val(); var invoice_noTaxMoney = $(item).find('[data-name="invoice_noTaxMoney"]').val(); + var data_method = $(item).find('[data-name="data_method"]').val(); + if (quotation_method == 'edit' && data_method == 'add') { + quotation_log += '發票品項增加了 [' + invoice_name + ' (' + invoice_date + ') ' + AppendComma(invoice_noTaxMoney) + ']\n'; + } var invoiceFormData = { invoice_name: invoice_name, @@ -1288,6 +1310,196 @@ function quotationEditModelFillData(obj, objView) { }); $("#quotation_range").trigger('change'); + + quotation_total = 0; + + var mainItemHtmlCode = ''; + + $.each(obj.quotationMainItemDetails, function (i, mainItem) { + //產生報價項目 + mainItemHtmlCode += makeMainItemHtml(mainItem); + }); + + $('#modelItem_div').html(mainItemHtmlCode); + + //產生付款方式 + var paymentHtmlCode = ''; + $.each(obj.payments, function (i, payment) { + paymentHtmlCode += makePaymentHtml(payment); + }); + + $('#payment_group').find('ol').append(paymentHtmlCode); + + //產生發票品項 + var invoiceHtmlCode = ''; + + $.each(obj.invoices, function (i, invoice) { + invoiceHtmlCode += makeInvoiceHtml(invoice); + }); + + $('#invoice_group').find('ol').append(invoiceHtmlCode); +} + +function makeMainItemHtml(obj) { + var ac_string = ''; + + if (obj.quotationMainItem_ac == 0) { + ac_string = '無'; + } else { + ac_string = obj.quotationMainItem_ac + '%' + } + + var mainItem_total = 0; + var mainItem_ac = 0.0; + + $.each(obj.quotationSubItems, function (i, subitem) { + var subitem_val = subitem.quotationSubItem_subTotal; + mainItem_total += subitem_val; + if (subitem.quotationSubItem_hasAC == 'Y') { + + mainItem_ac += (subitem_val * (obj.quotationMainItem_ac / 100)); + } + }); + + var mainItem_totalac = Math.round(mainItem_total + mainItem_ac); + + quotation_total += mainItem_totalac; + + var htmlCode = ''; + htmlCode += ''; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' ' + obj.quotationMainItem_name + ' '; + htmlCode += ' AC: ' + ac_string + ' '; + htmlCode += ' 項目合計: ' + AppendComma(mainItem_totalac) + ''; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
      '; + + $.each(obj.quotationSubItems, function (i, subitem) { + htmlCode += makeSubItemHtml(subitem); + }); + + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += '
    '; + + return htmlCode; +} +function makeSubItemHtml(obj) { + var htmlCode = ''; + + htmlCode += '
  • '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '

    '; + htmlCode += ' ' + obj.quotationSubItem_name; + htmlCode += '


    '; + htmlCode += '

    '; + htmlCode += ' ' + obj.quotationSubItem_descript; + htmlCode += '


    '; + htmlCode += '

    '; + htmlCode += ' 單價 NT$' + AppendComma(obj.quotationSubItem_price) + ', 數量 ' + obj.quotationSubItem_number + ', 單位 ' + obj.quotationSubItem_unitType + '\r\n'; + htmlCode += ' 小計 NT$' + AppendComma(obj.quotationSubItem_subTotal) + '\r\n'; + htmlCode += ' AC(' + obj.quotationSubItem_hasAC + ')'; + htmlCode += '

    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += ' '; + htmlCode += '
    '; + htmlCode += '
    '; + htmlCode += '
  • '; + + return htmlCode; +} + +function makePaymentHtml(obj) { + var payment_display = obj.payment_methodname; + + if (obj.payment_descript != '') { + obj.payment_display = obj.payment_display + ': ' + obj.payment_descript; + } + + var htmlCode = ''; + + htmlCode += '
  • \n'; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' \n'; + htmlCode += '
    ' + payment_display + '
    \n'; + htmlCode += '
    \n'; + htmlCode += ' \n'; + htmlCode += '
    \n'; + htmlCode += '
  • \n'; + + return htmlCode; +} + +function makeInvoiceHtml(obj) { + var invoice_display = "開立品項: " + obj.invoice_name + ", 開立月份: " + obj.invoice_date + ", 金額(未稅): " + AppendComma(obj.invoice_noTaxMoney); + var invoice_date = obj.invoice_year + "/" + String(obj.invoice_month).padStart(2, "0"); + var htmlCode = ''; + + htmlCode += '
  • \n'; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' '; + htmlCode += ' \n'; + htmlCode += ' ' + "開立品項: " + obj.invoice_name + ' \n'; + htmlCode += ' ' + "開立月份: " + invoice_date + ' \n'; + htmlCode += ' '; + htmlCode += '
    \n'; + htmlCode += ' \n'; + htmlCode += '
    \n'; + htmlCode += '
  • \n'; + + return htmlCode; } function buttonQuotationClick(obj, view) { var type = obj.getAttribute('data-method'); @@ -1299,6 +1511,47 @@ function buttonQuotationClick(obj, view) { quotationRowPos = quotationTable.fnGetPosition($('#' + uid)[0]); + if (type == "del") { + if (confirm('確定要刪除此張報價單?')) { + var formData = { + method: 'del', + quotation_uid: uid, + dept_uid: dept_uid + } + + $.ajax({ + url: "/Api/addEditDelQuotation", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + if (data.ret == "yes") { + var row = quotationTable.api().row(quotationRowID).remove().draw(false); + alert('刪除成功'); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + + } + if (type == "edit") { var formData = { method: 'get', @@ -1315,6 +1568,10 @@ function buttonQuotationClick(obj, view) { var obj = data.quotationDetail; var objView = data.quotationView; + $('#modelItem_div').html(''); + $('#payment_group').find('ol').html(''); + $('#invoice_group').find('ol').html(''); + $("#quotation_method").val('edit'); quotationEditModelFillData(obj, objView); @@ -2121,8 +2378,11 @@ function editQuotationSubItemButton(obj) { var modelSubItem_number = $(divObj).find("[data-name='quotationSubItem_number']").val(); var modelSubItem_hasAC = $(divObj).find("[data-name='quotationSubItem_hasAC']").val(); var modelSubItem_descript = $(divObj).find("[data-name='quotationSubItem_descript']").val(); - var modelMainItem_uid = $(divObj).parent().parent().attr("data-uid"); - var parent_mainItem_uid = $(divObj).parent().parent().attr("data-main-uid"); + + var divTmp = $(divObj).parent().parent().parent(); + + var modelMainItem_uid = $(divTmp).attr("data-uid"); + var parent_mainItem_uid = $(divTmp).attr("data-main-uid");