From fd756369f785982137b7a96fbc009158ea25300e 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 01:07:02 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 90 +++++++++-- Modals/resultClass.cs | 2 +- Views/Home/ProjectList.cshtml | 2 +- .../assets/javascript/custom/projectlist.js | 152 ++++++++++++++++-- 4 files changed, 221 insertions(+), 25 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 2ffac10d..81d33050 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -65,6 +65,28 @@ namespace QuotationMaker.Controllers string mainItems_jsonstr = obj["mainItems"].ToString(); string payments_jsonstr = obj["payments"].ToString(); string invoices_jsonstr = obj["invoices"].ToString(); + string quotation_revoke = "N"; + string quotation_isdel = "N"; + + if (quotation_specTotal == "") { + quotation_specTotal = "0"; + }; + + 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 }); + + if (objQuotation == null) { + ret.ret = "no"; + ret.err_code = "0009"; + ret.message = "此筆資料不存在或已被刪除!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.quotationDetail = new quotationDetail(objQuotation); + ret.quotationView = conn.QueryFirstOrDefault("select * from quotationView where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid ", new { quotation_uid = quotation_uid }); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } if (method == "add") { quotation objQuotation = new quotation(); @@ -91,6 +113,8 @@ namespace QuotationMaker.Controllers 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; @@ -124,10 +148,10 @@ namespace QuotationMaker.Controllers newItem.mainItem_uid = item.mainItem_uid; newItem.quotationMainItem_uid = quotationMainItem_uid; newItem.quotationMainItem_name = item.quotationMainItem_name; - newItem.quotationMainItem_ac = double.Parse(item.quotationMainItem_ac); - newItem.quotationMainItem_subTotal = double.Parse(item.quotationMainItem_subTotal); + 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(quotation_version); + newItem.quotationMainItem_version = int.Parse((string)quotation_version); quotationMainItems.Add(newItem); @@ -137,20 +161,68 @@ namespace QuotationMaker.Controllers newSubItem.quotationMainItem_uid = quotationMainItem_uid; newSubItem.quotation_uid = quotation_uid; newSubItem.subItem_uid = subItem.subItem_uid; - newSubItem.quotationSubItem_name = subItem.subItem_name; - newSubItem.quotationSubItem_descript = subItem.subItem_descript; - newSubItem.quotationSubItem_price = double.Parse(subItem.subItem_price); + 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(subItem.quotationSubItem_number); - newSubItem.quotationSubItem_subTotal = double.Parse(subItem.quotationSubItem_subTotal); + 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(quotation_version); + 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); + } + + conn.Insert(invoices); + conn.Insert(payments); + conn.Insert(quotationSubItems); + conn.Insert(quotationMainItems); + conn.Insert(objQuotation); + + ret.quotationView = conn.QueryFirstOrDefault("select * from quotationView where quotation_uid = @quotation_uid and quotation_version = 1", new {quotation_uid = quotation_uid}); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index b6d1289f..9beb552b 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -178,7 +178,7 @@ public class resultClass this.GetType().GetProperty(propName).SetValue(this, propValue); } - List quotationMainItems = conn.Query("select * from quotationMainItem where quotationSubItem_version = @quotationSubItem_version and quotation_uid = @quotation_uid ", new { quotationSubItem_version = this.quotation_version, quotation_uid = this.quotation_uid }).ToList(); + List quotationMainItems = conn.Query("select * from quotationMainItem where quotationMainItem_version = @quotation_version and quotation_uid = @quotation_uid ", new { quotation_version = this.quotation_version, quotation_uid = this.quotation_uid }).ToList(); foreach (quotationMainItem qItem in quotationMainItems) { quotationMainItemDetails.Add(new quotationMainItemDetail(qItem)); diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index 386338f3..f59ebbbd 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -299,7 +299,7 @@ -
+
diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index 332f50d9..3059cfcd 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -158,7 +158,8 @@ $(document).ready(function () { deledInvoices = []; quotation_total = 0; - + + $('#quotation_editType_div').show(); $('#quotation_sa').val(service_text()); $('#quotation_method').val('add'); $('#clientModelQuotationModal').modal("toggle"); @@ -703,9 +704,9 @@ $(document).ready(function () { var quotation_specTotal_old = $('#quotation_specTotal_old').val(); var quotation_tax = $('#quotation_tax').val(); var quotation_tax_old = $('#quotation_tax_old').val(); - var quotation_grandTotal = $('quotation_grandTotal').val(); + var quotation_grandTotal = $('#quotation_grandTotal').val(); var quotation_grandTotal_old = $('#quotation_grandTotal_old').val(); - var quotation_sa = $('quotation_sa').val(); + var quotation_sa = $('#quotation_sa').val(); var quotation_sa_old = $('#quotation_sa_old').val(); var err_msg = ''; @@ -972,19 +973,19 @@ $(document).ready(function () { data: formData, success: function (data, textStatus, jqXHR) { if (data.ret == "yes") { - //var obj = data.projectViews[0]; + var obj = data.quotationView; - if (method == "add") { - //projectTable.fnAddData(obj); + if (quotation_method == "add") { + quotationTable.fnAddData(obj); } - if (method == "edit") { - //projectTable.fnUpdate(obj, projectRowPos); + if (quotation_method == "edit") { + quotationTable.fnUpdate(obj, quotationPos); } - //$('#clientProjectModal').modal('toggle'); + $('#clientModelQuotationModal').modal('toggle'); } else { alert(data.message); @@ -1214,6 +1215,129 @@ function buttonClick(obj) { } } +function quotationEditModelFillData(obj, objView) { + $('#quotation_editType_div').hide(); + $('#quotation_uid').val(obj.quotation_uid); + $('#quotation_version').val(obj.quotation_version); + $('#quotation_date').val(obj.quotation_date).trigger('change'); + $('#quotation_date_old').val(obj.quotation_date); + $('#quotation_expStart').val(obj.quotation_expStart); + $('#quotation_expEnd').val(obj.quotation_expEnd); + $('#quotation_expStart_old').val(obj.quotation_expStart); + $('#quotation_expEnd_old').val(obj.quotation_expEnd); + $('#quotation_name').val(obj.quotation_name).trigger('change'); + $('#quotation_name_old').val(obj.quotation_name); + $('#quotation_name').val(obj.quotation_name).trigger('change'); + $('#quotation_name_old').val(obj.quotation_name); + + //$('#quotation_noTaxTotal').val('').trigger('change'); + //$('#quotation_specTotal').val('').trigger('change'); + + //$('#quotation_noTaxTotal').val(obj.quotation_noTaxTotal); + //$('#quotation_noTaxTotal_old').val(obj.quotation_noTaxTotal); + + if (obj.quotation_specTotal != 0) { + $('#quotation_specTotal').val(obj.quotation_specTotal).trigger('change'); + $('#quotation_specTotal_old').val(obj.quotation_specTotal); + } else { + $('#quotation_specTotal').val('').trigger('change'); + $('#quotation_specTotal_old').val(''); + } + $('#quotation_noTaxTotal').val(obj.quotation_noTaxTotal); + $('#quotation_noTaxTotal_old').val(obj.quotation_noTaxTotal); + $('#quotation_tax').val(obj.quotation_tax).trigger('change'); + $('#quotation_tax_old').val(obj.quotation_tax); + $('#quotation_grandTotal').val(obj.quotation_grandTotal).trigger('change'); + $('#quotation_grandTotal_old').val(obj.quotation_grandTotal); + $('#quotation_sa').val(obj.quotation_sa).trigger('change'); + $('#quotation_sa_old').val(obj.quotation_sa); + + + var no_found = 1; + $("#contactPerson_uid option").each(function () { + if ($(this).val() == obj.contactPerson_uid) { + no_found = 0; + } + }); + + if (no_found == 1) { + $("#contactPerson_uid").append($("