updates
parent
3b0c274479
commit
74eafce9b6
|
|
@ -23,7 +23,171 @@ namespace QuotationMaker.Controllers
|
||||||
this._httpContextAccessor = httpContextAccessor;
|
this._httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("addEditDelGetModelQuotation")]
|
||||||
|
public ActionResult AddEditDelGetModelQuotation(IFormCollection obj)
|
||||||
|
{
|
||||||
|
modelQuotationResult ret = new modelQuotationResult();
|
||||||
|
|
||||||
|
authToken token = new authToken(this._httpContextAccessor);
|
||||||
|
if (token.user_isLogin == false)
|
||||||
|
{
|
||||||
|
HttpContext.Response.Cookies.Delete("token_key");
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "99999";
|
||||||
|
ret.message = "非登入狀態!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.user_perm != "system")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "90001";
|
||||||
|
ret.message = "此帳號無此api使用權限!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
string method = obj["method"].ToString();
|
||||||
|
string dept_uid = obj["dept_uid"].ToString();
|
||||||
|
string modelProj_uid = obj["modelProj_uid"].ToString();
|
||||||
|
string modelQuotation_uid = obj["modelQuotation_uid"].ToString();
|
||||||
|
string modelQuotation_name = obj["modelQuotation_name"].ToString();
|
||||||
|
string mainItemsJsonTxt = obj["mainItemsJson"].ToString();
|
||||||
|
string deledMainItemsJsonTxt = obj["deledMainItemsJson"].ToString();
|
||||||
|
string deledSubItemsJsonTxt = obj["deledSubItemsJson"].ToString();
|
||||||
|
|
||||||
|
if (method == "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0001";
|
||||||
|
ret.message = "沒有method!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (dept_uid.Trim() == "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0003";
|
||||||
|
ret.message = "沒有dept_uid!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modelProj_uid.Trim() == "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0003";
|
||||||
|
ret.message = "沒有modelProj_uid!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "add") {
|
||||||
|
modelQuotation_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
|
||||||
|
dynamic mainItemsJson;
|
||||||
|
dynamic deledMainItemsJson;
|
||||||
|
dynamic deledSubItemsJson;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mainItemsJson = JsonConvert.DeserializeObject(mainItemsJsonTxt);
|
||||||
|
deledMainItemsJson = JsonConvert.DeserializeObject(deledMainItemsJsonTxt);
|
||||||
|
deledSubItemsJson = JsonConvert.DeserializeObject(deledSubItemsJsonTxt);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0003";
|
||||||
|
ret.message = "json error," + ex.Message;
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<modelMainItem> modelMainItems = new List<modelMainItem>();
|
||||||
|
List<modelSubItem> newModelSubItems = new List<modelSubItem>();
|
||||||
|
|
||||||
|
foreach (dynamic item in mainItemsJson)
|
||||||
|
{
|
||||||
|
string mainItem_uid = item.mainItem_uid;
|
||||||
|
string modelMainItem_uid = item.modelMainItem_uid;
|
||||||
|
modelMainItem_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
|
||||||
|
string modelMainItem_name = item.modelMainItem_name;
|
||||||
|
string modelMainItem_ac = item.modelMainItem_ac;
|
||||||
|
|
||||||
|
modelMainItem newModelMainItem = new modelMainItem();
|
||||||
|
|
||||||
|
newModelMainItem.mainItem_uid = mainItem_uid;
|
||||||
|
newModelMainItem.modelMainItem_uid = modelMainItem_uid;
|
||||||
|
newModelMainItem.modelMainItem_name = modelMainItem_name;
|
||||||
|
newModelMainItem.modelMainItem_ac = double.Parse(modelMainItem_ac);
|
||||||
|
newModelMainItem.modelQuotation_uid = modelQuotation_uid;
|
||||||
|
newModelMainItem.modelMainItem_lastModify_uid = token.user_uid;
|
||||||
|
|
||||||
|
double acValue = double.Parse(modelMainItem_ac) / 100;
|
||||||
|
double total = 0;
|
||||||
|
|
||||||
|
foreach (dynamic subItem in item.subItems) {
|
||||||
|
string subItem_method = subItem.method;
|
||||||
|
string modelSubItem_uid = subItem.modelSubItem_uid;
|
||||||
|
modelSubItem_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
string modelSubItem_name = subItem.modelSubItem_name;
|
||||||
|
string modelSubItem_descript = subItem.modelSubItem_descript;
|
||||||
|
|
||||||
|
double modelSubItem_price = double.Parse(Convert.ToString(subItem.modelSubItem_price));
|
||||||
|
string modelSubItem_unitType = subItem.modelSubItem_unitType;
|
||||||
|
double modelSubItem_number = double.Parse(Convert.ToString(subItem.modelSubItem_number));
|
||||||
|
double modelSubItem_subTotal = double.Parse(Convert.ToString(subItem.modelSubItem_subTotal));
|
||||||
|
string modelSubItem_hasAC = subItem.modelSubItem_hasAC;
|
||||||
|
|
||||||
|
if (modelSubItem_hasAC == "Y")
|
||||||
|
{
|
||||||
|
total += modelSubItem_subTotal * (1 + acValue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
total += modelSubItem_subTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
modelSubItem newModelSubItem = new modelSubItem();
|
||||||
|
newModelSubItem.modelMainItem_uid = modelMainItem_uid;
|
||||||
|
newModelSubItem.modelSubItem_uid = modelSubItem_uid;
|
||||||
|
newModelSubItem.modelSubItem_name = modelSubItem_name;
|
||||||
|
newModelSubItem.modelSubItem_descript = modelSubItem_descript;
|
||||||
|
newModelSubItem.modelSubItem_price = modelSubItem_price;
|
||||||
|
newModelSubItem.modelSubItem_number = modelSubItem_number;
|
||||||
|
newModelSubItem.modelSubItem_subTotal = modelSubItem_subTotal;
|
||||||
|
newModelSubItem.modelSubItem_unitType = modelSubItem_unitType;
|
||||||
|
newModelSubItem.modelSubItem_hasAC = modelSubItem_hasAC;
|
||||||
|
newModelSubItem.modelSubItem_lastModify_uid = token.user_uid;
|
||||||
|
|
||||||
|
newModelSubItems.Add(newModelSubItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
newModelMainItem.modelMainItem_subTotal = total;
|
||||||
|
|
||||||
|
modelMainItems.Add(newModelMainItem);
|
||||||
|
|
||||||
|
conn.Insert(newModelSubItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
modelQuotation newQuotation = new modelQuotation();
|
||||||
|
newQuotation.modelQuotation_uid = modelQuotation_uid;
|
||||||
|
newQuotation.dept_uid = dept_uid;
|
||||||
|
newQuotation.modelProj_uid = modelProj_uid;
|
||||||
|
newQuotation.modelQuotation_name = modelQuotation_name;
|
||||||
|
newQuotation.modelQuotation_lastmodify_uid = token.user_uid;
|
||||||
|
|
||||||
|
conn.Insert(newModelSubItems);
|
||||||
|
conn.Insert(modelMainItems);
|
||||||
|
conn.Insert(newQuotation);
|
||||||
|
|
||||||
|
ret.modelQuotationDetails.Add(new modelQuotationDetail(newQuotation));
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
[Route("authModalQuotationList")]
|
[Route("authModalQuotationList")]
|
||||||
public ActionResult AuthModalQuotationList(IFormCollection obj)
|
public ActionResult AuthModalQuotationList(IFormCollection obj)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,15 @@ using Dapper;
|
||||||
using static DbTableClass;
|
using static DbTableClass;
|
||||||
public class resultClass
|
public class resultClass
|
||||||
{
|
{
|
||||||
|
public class modelQuotationResult
|
||||||
|
{
|
||||||
|
public string ret = "no";
|
||||||
|
public string err_code = "0000";
|
||||||
|
public string message = "";
|
||||||
|
|
||||||
|
public List<modelQuotationDetail> modelQuotationDetails = new List<modelQuotationDetail>();
|
||||||
|
}
|
||||||
|
|
||||||
public class modelQuotationListResult
|
public class modelQuotationListResult
|
||||||
{
|
{
|
||||||
public string ret = "no";
|
public string ret = "no";
|
||||||
|
|
@ -122,4 +131,55 @@ public class resultClass
|
||||||
Depts = conn.Query<depts>("select * from userDept where user_uid = @user_uid", new { user_uid = this.user_uid }).ToList();
|
Depts = conn.Query<depts>("select * from userDept where user_uid = @user_uid", new { user_uid = this.user_uid }).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class modelQuotationDetail : modelQuotation {
|
||||||
|
SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
|
||||||
|
|
||||||
|
public List<modelMainItemDetail> modelMainItemDetails = new List<modelMainItemDetail>();
|
||||||
|
|
||||||
|
public modelQuotationDetail() { }
|
||||||
|
|
||||||
|
public modelQuotationDetail(modelQuotation objData) {
|
||||||
|
Type projectType = objData.GetType();
|
||||||
|
|
||||||
|
foreach (var prop in projectType.GetProperties())
|
||||||
|
{
|
||||||
|
string propName = prop.Name;
|
||||||
|
var valueProperty = projectType.GetProperty(propName);
|
||||||
|
object propValue = valueProperty.GetValue(objData, null);
|
||||||
|
|
||||||
|
this.GetType().GetProperty(propName).SetValue(this, propValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<modelMainItem> modelMainItems = conn.Query<modelMainItem>("select * from modelMainItem where modelQuotation_uid = @modelQuotation_uid", new { modelQuotation_uid = objData.modelQuotation_uid }).ToList();
|
||||||
|
|
||||||
|
foreach (modelMainItem item in modelMainItems) {
|
||||||
|
this.modelMainItemDetails.Add(new modelMainItemDetail(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class modelMainItemDetail: modelMainItem {
|
||||||
|
SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
|
||||||
|
|
||||||
|
public List<modelSubItem> modelSubItems = new List<modelSubItem>();
|
||||||
|
|
||||||
|
public modelMainItemDetail() { }
|
||||||
|
|
||||||
|
public modelMainItemDetail(modelMainItem objData) {
|
||||||
|
Type projectType = objData.GetType();
|
||||||
|
|
||||||
|
foreach (var prop in projectType.GetProperties())
|
||||||
|
{
|
||||||
|
string propName = prop.Name;
|
||||||
|
var valueProperty = projectType.GetProperty(propName);
|
||||||
|
object propValue = valueProperty.GetValue(objData, null);
|
||||||
|
|
||||||
|
this.GetType().GetProperty(propName).SetValue(this, propValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
modelSubItems = conn.Query<modelSubItem>("select * from modelSubItem where modelMainItem_uid = @modelMainItem_uid", new { modelMainItem_uid = objData.modelMainItem_uid}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ $(document).ready(function () {
|
||||||
var modelQuotation_uid = $('#modelQuotation_uid').val();
|
var modelQuotation_uid = $('#modelQuotation_uid').val();
|
||||||
var modelMainItem_uid = $('#modelMainItem_uid').val();
|
var modelMainItem_uid = $('#modelMainItem_uid').val();
|
||||||
var modelQuotation_name = $('#modelQuotation_name').val();
|
var modelQuotation_name = $('#modelQuotation_name').val();
|
||||||
|
var modelProj_uid = $('#parent_modelProj_uid').val();
|
||||||
|
|
||||||
var msg = '';
|
var msg = '';
|
||||||
|
|
||||||
|
|
@ -59,7 +60,69 @@ $(document).ready(function () {
|
||||||
var modelSubItem_number = $(item).find('[data-name="model-subitem-number"]').val();
|
var modelSubItem_number = $(item).find('[data-name="model-subitem-number"]').val();
|
||||||
var modelSubItem_subTotal = $(item).find('[data-name="model-subitem-subTotal"]').val();
|
var modelSubItem_subTotal = $(item).find('[data-name="model-subitem-subTotal"]').val();
|
||||||
var modelSubItem_hasAC = $(item).find('[data-name="model-subitem-hasAC"]').val();
|
var modelSubItem_hasAC = $(item).find('[data-name="model-subitem-hasAC"]').val();
|
||||||
|
|
||||||
|
var subItemObj = {
|
||||||
|
method: itemDataType,
|
||||||
|
modelSubItem_uid: modelSubItem_uid,
|
||||||
|
modelSubItem_name: modelSubItem_name,
|
||||||
|
modelSubItem_descript: modelSubItem_descript,
|
||||||
|
modelSubItem_price: modelSubItem_price,
|
||||||
|
modelSubItem_unitType: modelSubItem_unitType,
|
||||||
|
modelSubItem_number: modelSubItem_number,
|
||||||
|
modelSubItem_subTotal: modelSubItem_subTotal,
|
||||||
|
modelSubItem_hasAC: modelSubItem_hasAC
|
||||||
|
}
|
||||||
|
|
||||||
|
subItemArray.push(subItemObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var quotationModelJson = {
|
||||||
|
method: dataType,
|
||||||
|
mainItem_uid: mainItem_uid,
|
||||||
|
modelMainItem_uid: modelMainItem_uid,
|
||||||
|
modelMainItem_name: modelMainItem_name,
|
||||||
|
modelMainItem_ac: modelMainItem_ac,
|
||||||
|
subItems: subItemArray
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemArray.push(quotationModelJson);
|
||||||
|
});
|
||||||
|
|
||||||
|
var quotationForm = {
|
||||||
|
method: method,
|
||||||
|
modelProj_uid: modelProj_uid,
|
||||||
|
modelQuotation_uid: modelQuotation_uid,
|
||||||
|
dept_uid: $('#dept_select').val(),
|
||||||
|
modelQuotation_name: modelQuotation_name,
|
||||||
|
mainItemsJson: JSON.stringify(ItemArray),
|
||||||
|
deledMainItemsJson: JSON.stringify(deledMainItems),
|
||||||
|
deledSubItemsJson: JSON.stringify(deledSubItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/AuthApi/addEditDelGetModelQuotation",
|
||||||
|
type: "post",
|
||||||
|
data: quotationForm,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
if (method == 'add') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == 'edit') {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -397,6 +460,7 @@ function addSubItem(obj) {
|
||||||
var modelMainItem_uid = $(obj).parent().parent().attr("data-uid");
|
var modelMainItem_uid = $(obj).parent().parent().attr("data-uid");
|
||||||
var modelMainItem_name = $(obj).parent().parent().find("[data-name='mainItem_name']").val();
|
var modelMainItem_name = $(obj).parent().parent().find("[data-name='mainItem_name']").val();
|
||||||
var parent_mainItem_uid = $(obj).parent().parent().attr("data-main-uid");
|
var parent_mainItem_uid = $(obj).parent().parent().attr("data-main-uid");
|
||||||
|
var ac = $(obj).parent().parent().find('[data-name="modelMainItem_ac"]').val();
|
||||||
|
|
||||||
$('#modelSubItem_name').typeahead('destroy');
|
$('#modelSubItem_name').typeahead('destroy');
|
||||||
|
|
||||||
|
|
@ -408,7 +472,13 @@ function addSubItem(obj) {
|
||||||
$('#parent_Item_uid').val('');
|
$('#parent_Item_uid').val('');
|
||||||
$('#model_parent_data_uid').val(modelMainItem_uid);
|
$('#model_parent_data_uid').val(modelMainItem_uid);
|
||||||
|
|
||||||
$('#modelSubItem_hasAC').prop("checked", "checked").trigger("change");
|
if (ac != '0') {
|
||||||
|
$('#modelSubItem_hasAC').prop("checked", true).trigger("change");
|
||||||
|
} else {
|
||||||
|
$('#modelSubItem_hasAC').prop("checked", false).trigger("change");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#modelSubItemModal').modal('toggle');
|
$('#modelSubItemModal').modal('toggle');
|
||||||
}
|
}
|
||||||
|
|
@ -714,7 +784,7 @@ function loadModelQuotationDataTable() {
|
||||||
searchable: true,
|
searchable: true,
|
||||||
render: function render(data, type, row, meta) {
|
render: function render(data, type, row, meta) {
|
||||||
|
|
||||||
return '<a href="javascript: void(0);" data-uid="' + row.modelQuotation_name + '" data-method="preview" >' + row.modelQuotation_name + '</a>';
|
return '<a href="javascript: void(0);" data-uid="' + row.modelQuotation_uid + '" data-method="preview" >' + row.modelQuotation_name + '</a>';
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue