forked from dk96/QuotationMaker
updates
parent
74eafce9b6
commit
91228ef5f3
|
|
@ -23,6 +23,41 @@ namespace QuotationMaker.Controllers
|
||||||
this._httpContextAccessor = httpContextAccessor;
|
this._httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("authModelQuotationList")]
|
||||||
|
public ActionResult AuthModelQuotationList(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 dept_uid = obj["dept_uid"].ToString();
|
||||||
|
string modelProj_uid = obj["modelProj_uid"].ToString();
|
||||||
|
|
||||||
|
List<modelQuotation> modelQuotations = conn.Query<modelQuotation>("select * from modelQuotation where dept_uid = @dept_uid and modelProj_uid = @modelProj_uid", new { dept_uid = dept_uid, modelProj_uid = modelProj_uid }).ToList();
|
||||||
|
|
||||||
|
foreach (modelQuotation modelQuotation in modelQuotations) {
|
||||||
|
ret.modelQuotationDetails.Add(new modelQuotationDetail(modelQuotation));
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
[Route("addEditDelGetModelQuotation")]
|
[Route("addEditDelGetModelQuotation")]
|
||||||
public ActionResult AddEditDelGetModelQuotation(IFormCollection obj)
|
public ActionResult AddEditDelGetModelQuotation(IFormCollection obj)
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +202,7 @@ namespace QuotationMaker.Controllers
|
||||||
|
|
||||||
modelMainItems.Add(newModelMainItem);
|
modelMainItems.Add(newModelMainItem);
|
||||||
|
|
||||||
conn.Insert(newModelSubItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
modelQuotation newQuotation = new modelQuotation();
|
modelQuotation newQuotation = new modelQuotation();
|
||||||
|
|
@ -186,6 +221,261 @@ namespace QuotationMaker.Controllers
|
||||||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modelQuotation_uid.Trim() == "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0002";
|
||||||
|
ret.message = "沒有modelQuotation_uid!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
modelQuotation modelQuotation = conn.QueryFirstOrDefault<modelQuotation>("select * from modelQuotation where modelQuotation_uid = @modelQuotation_uid ", new { modelQuotation_uid = modelQuotation_uid });
|
||||||
|
|
||||||
|
if (method == "get") {
|
||||||
|
if (modelQuotation == null) {
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0009";
|
||||||
|
ret.message = "沒有此modelQuotation_uid資料!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.modelQuotationDetails.Add(new modelQuotationDetail(modelQuotation));
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "edit") {
|
||||||
|
if (modelQuotation == null)
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0009";
|
||||||
|
ret.message = "沒有此modelQuotation_uid資料!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
modelQuotation.modelQuotation_name = modelQuotation_name;
|
||||||
|
modelQuotation.modelQuotation_lastmodify_uid = token.user_uid;
|
||||||
|
modelQuotation.modelQuotation_modifydate = DateTime.Now;
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (dynamic item in deledSubItemsJson) {
|
||||||
|
string modelSubItem_uid = item.modelSubItem_uid;
|
||||||
|
|
||||||
|
conn.Execute("delete modelSubItem where modelSubItem_uid = @modelSubItem_uid", new { modelSubItem_uid = modelSubItem_uid });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (dynamic item in deledMainItemsJson) {
|
||||||
|
string modelMainItem_uid = item.modelMainItem_uid;
|
||||||
|
|
||||||
|
conn.Execute("delete modelMainItem where modelMainItem_uid = @modelMainItem_uid", new { modelMainItem_uid = modelMainItem_uid });
|
||||||
|
conn.Execute("delete modelSubItem where modelMainItem_uid = @modelMainItem_uid", new { modelMainItem_uid = modelMainItem_uid });
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (dynamic item in mainItemsJson)
|
||||||
|
{
|
||||||
|
string mainItem_method = item.method;
|
||||||
|
string mainItem_uid = item.mainItem_uid;
|
||||||
|
string modelMainItem_uid = item.modelMainItem_uid;
|
||||||
|
|
||||||
|
|
||||||
|
string modelMainItem_name = item.modelMainItem_name;
|
||||||
|
string modelMainItem_ac = item.modelMainItem_ac;
|
||||||
|
|
||||||
|
if (mainItem_method == "add") {
|
||||||
|
modelMainItem_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
conn.Insert(newModelSubItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
newModelMainItem.modelMainItem_subTotal = total;
|
||||||
|
|
||||||
|
conn.Insert(newModelMainItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainItem_method == "edit") {
|
||||||
|
modelMainItem editModelMainItem = conn.QueryFirstOrDefault<modelMainItem>("select * from modelMainItem where modelMainItem_uid = @modelMainItem_uid", new { modelMainItem_uid = modelMainItem_uid });
|
||||||
|
|
||||||
|
if (editModelMainItem != null) {
|
||||||
|
editModelMainItem.mainItem_uid = mainItem_uid;
|
||||||
|
editModelMainItem.modelMainItem_uid = modelMainItem_uid;
|
||||||
|
editModelMainItem.modelMainItem_name = modelMainItem_name;
|
||||||
|
editModelMainItem.modelMainItem_ac = double.Parse(modelMainItem_ac);
|
||||||
|
editModelMainItem.modelQuotation_uid = modelQuotation_uid;
|
||||||
|
editModelMainItem.modelMainItem_lastModify_uid = token.user_uid;
|
||||||
|
editModelMainItem.modelMainItem_modifydate = DateTime.Now;
|
||||||
|
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subItem_method == "add") {
|
||||||
|
|
||||||
|
modelSubItem_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
conn.Insert(newModelSubItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subItem_method == "edit") {
|
||||||
|
|
||||||
|
|
||||||
|
modelSubItem editSubItem = conn.QueryFirstOrDefault<modelSubItem>("select * from modelSubItem where modelSubItem_uid = @modelSubItem_uid ", new { modelSubItem_uid = modelSubItem_uid });
|
||||||
|
|
||||||
|
if (editSubItem != null) {
|
||||||
|
|
||||||
|
editSubItem.modelMainItem_uid = modelMainItem_uid;
|
||||||
|
editSubItem.modelSubItem_name = modelSubItem_name;
|
||||||
|
editSubItem.modelSubItem_descript = modelSubItem_descript;
|
||||||
|
editSubItem.modelSubItem_price = modelSubItem_price;
|
||||||
|
editSubItem.modelSubItem_number = modelSubItem_number;
|
||||||
|
editSubItem.modelSubItem_subTotal = modelSubItem_subTotal;
|
||||||
|
editSubItem.modelSubItem_unitType = modelSubItem_unitType;
|
||||||
|
editSubItem.modelSubItem_hasAC = modelSubItem_hasAC;
|
||||||
|
editSubItem.modelSubItem_lastModify_uid = token.user_uid;
|
||||||
|
editSubItem.modelSubItem_modifydate = DateTime.Now;
|
||||||
|
|
||||||
|
conn.Update(editSubItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
editModelMainItem.modelMainItem_subTotal = total;
|
||||||
|
|
||||||
|
conn.Update(editModelMainItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Update(modelQuotation);
|
||||||
|
|
||||||
|
ret.modelQuotationDetails.Add(new modelQuotationDetail(modelQuotation));
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "del") {
|
||||||
|
|
||||||
|
if (modelQuotation == null)
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0009";
|
||||||
|
ret.message = "沒有此modelQuotation_uid資料可刪除!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<modelMainItem> modelMainItems = conn.Query<modelMainItem>("select * from modelMainItem where modelQuotation_uid = @modelQuotation_uid", new { modelQuotation_uid = modelQuotation.modelQuotation_uid }).ToList();
|
||||||
|
|
||||||
|
foreach (modelMainItem modelMainItem in modelMainItems) {
|
||||||
|
string modelMainItem_uid = modelMainItem.modelMainItem_uid;
|
||||||
|
conn.Execute("delete modelSubItem where modelMainItem_uid = @modelMainItem_uid", new { modelMainItem_uid = modelMainItem_uid });
|
||||||
|
conn.Delete(modelMainItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Delete(modelQuotation);
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@
|
||||||
<!-- .modal-body -->
|
<!-- .modal-body -->
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="hidden" id="modelMainItem_uid" />
|
<input type="hidden" id="modelMainItem_uid" />
|
||||||
<input type="hidden" id="modelMainItem_method" />
|
<input type="hidden" id="modelQuotation_method" />
|
||||||
<input type="hidden" id="modelQuotation_uid" />
|
<input type="hidden" id="modelQuotation_uid" />
|
||||||
<!-- .form-group -->
|
<!-- .form-group -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
@ -205,7 +205,7 @@
|
||||||
</div><!-- /.modal-body -->
|
</div><!-- /.modal-body -->
|
||||||
<!-- .modal-footer -->
|
<!-- .modal-footer -->
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" id="modelQuotationDialogSaveBtn" class="btn btn-primary">Save</button><button type="button" class="btn btn-light" data-toggle="modal">Close</button>
|
<button type="button" id="modelQuotationDialogSaveBtn" class="btn btn-primary">Save</button><button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
|
||||||
</div><!-- /.modal-footer -->
|
</div><!-- /.modal-footer -->
|
||||||
</div><!-- /.modal-content -->
|
</div><!-- /.modal-content -->
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
|
|
@ -246,7 +246,7 @@
|
||||||
</div><!-- /.modal-body -->
|
</div><!-- /.modal-body -->
|
||||||
<!-- .modal-footer -->
|
<!-- .modal-footer -->
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" id="modelMainItemDialogSaveBtn" class="btn btn-primary">Save</button> <button type="button" class="btn btn-light" data-dismiss="modal" data-target="#modelMainItemModal">Close</button>
|
<button type="button" id="modelMainItemDialogSaveBtn" class="btn btn-primary">Save</button> <button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
|
||||||
</div><!-- /.modal-footer -->
|
</div><!-- /.modal-footer -->
|
||||||
</div><!-- /.modal-content -->
|
</div><!-- /.modal-content -->
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ $(document).ready(function () {
|
||||||
|
|
||||||
//報價單範本儲存鈕
|
//報價單範本儲存鈕
|
||||||
$('#modelQuotationDialogSaveBtn').on('click', function () {
|
$('#modelQuotationDialogSaveBtn').on('click', function () {
|
||||||
var method = $('#modelMainItem_method').val();
|
var method = $('#modelQuotation_method').val();
|
||||||
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();
|
||||||
|
|
@ -105,13 +105,19 @@ $(document).ready(function () {
|
||||||
data: quotationForm,
|
data: quotationForm,
|
||||||
success: function (data, textStatus, jqXHR) {
|
success: function (data, textStatus, jqXHR) {
|
||||||
if (data.ret == "yes") {
|
if (data.ret == "yes") {
|
||||||
if (method == 'add') {
|
var obj = data.modelQuotationDetails[0];
|
||||||
|
|
||||||
|
if (method == "add") {
|
||||||
|
modelQuotationTable.fnAddData(obj);
|
||||||
|
alert('新增範本完成!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method == 'edit') {
|
if (method == 'edit') {
|
||||||
|
modelQuotationTable.fnUpdate(obj, modelQuotationRowPos);
|
||||||
|
alert('儲存範本完成');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#clientModelQuotationPreviewModal').modal('toggle');
|
||||||
} else {
|
} else {
|
||||||
alert(data.message);
|
alert(data.message);
|
||||||
|
|
||||||
|
|
@ -327,7 +333,8 @@ $(document).ready(function () {
|
||||||
$('#modelQuotationListNewBtn').on('click', function () {
|
$('#modelQuotationListNewBtn').on('click', function () {
|
||||||
deledMainItems = [];
|
deledMainItems = [];
|
||||||
deledSubItems = [];
|
deledSubItems = [];
|
||||||
|
$('#modelQuotation_method').val('add');
|
||||||
|
$('#modelItem_div').html('');
|
||||||
$('#clientModelQuotationPreviewModal').modal('toggle');
|
$('#clientModelQuotationPreviewModal').modal('toggle');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -434,12 +441,12 @@ function editSubItemButton(obj) {
|
||||||
$('#modelSubItem_method').val('edit');
|
$('#modelSubItem_method').val('edit');
|
||||||
$('#modelSubItem_uid').val(model_subitem_uid);
|
$('#modelSubItem_uid').val(model_subitem_uid);
|
||||||
$('#parent_Item_uid').val(parent_item_uid);
|
$('#parent_Item_uid').val(parent_item_uid);
|
||||||
$('#model_parent_data_uid').val(modelMainItem_uid);
|
$('#model_parent_data_uid').val(modelMainItem_uid).trigger('change');
|
||||||
$('#modelSubItem_name').val(subItem_name);
|
$('#modelSubItem_name').val(subItem_name).trigger('change');
|
||||||
$('#modelSubItem_descript').val(modelSubItem_descript);
|
$('#modelSubItem_descript').val(modelSubItem_descript).trigger('change');
|
||||||
$('#modelSubItem_price').val(modelSubItem_price);
|
$('#modelSubItem_price').val(modelSubItem_price).trigger('change');
|
||||||
$('#modelSubItem_unitType').val(modelSubItem_unitType);
|
$('#modelSubItem_unitType').val(modelSubItem_unitType).trigger('change');
|
||||||
$('#modelSubItem_number').val(modelSubItem_number);
|
$('#modelSubItem_number').val(modelSubItem_number).trigger('change');
|
||||||
|
|
||||||
if (modelSubItem_hasAC == 'Y') {
|
if (modelSubItem_hasAC == 'Y') {
|
||||||
$('#modelSubItem_hasAC').prop('checked', true).trigger('change');
|
$('#modelSubItem_hasAC').prop('checked', true).trigger('change');
|
||||||
|
|
@ -727,7 +734,7 @@ function loadModelQuotationDataTable() {
|
||||||
},
|
},
|
||||||
handleDataTables: function handleDataTables() {
|
handleDataTables: function handleDataTables() {
|
||||||
//$('#myTable').append("<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tfoot>");
|
//$('#myTable').append("<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tfoot>");
|
||||||
return $('#dt-responsive-subItem').DataTable({
|
return $('#dt-responsive-modelQuotation').DataTable({
|
||||||
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
|
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
|
||||||
lengthChange: true,
|
lengthChange: true,
|
||||||
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
|
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
|
||||||
|
|
@ -767,7 +774,7 @@ function loadModelQuotationDataTable() {
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
order: [[0, 'desc']],
|
order: [[1, 'desc']],
|
||||||
info: true,
|
info: true,
|
||||||
search: "搜尋:",
|
search: "搜尋:",
|
||||||
searching: true,
|
searching: true,
|
||||||
|
|
@ -784,7 +791,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_uid + '" data-method="preview" >' + row.modelQuotation_name + '</a>';
|
return row.modelQuotation_name;
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -1025,6 +1032,170 @@ function deptList() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mainItemHtml(obj) {
|
||||||
|
var htmlCode = '';
|
||||||
|
htmlCode += '<!-- .card -->';
|
||||||
|
htmlCode += '<div class="card card-fluid" data-uid="' + obj.modelMainItem_uid + '" data-main-uid="' + obj.mainItem_uid + '" data-type="edit">';
|
||||||
|
htmlCode += ' <div class="card-header border-bottom-0 btn-group">';
|
||||||
|
htmlCode += ' <input type="hidden" data-name="mainItem_name" value="' + obj.modelMainItem_name + '" />';
|
||||||
|
htmlCode += ' <input type="hidden" data-name="modelMainItem_ac" value="' + obj.modelMainItem_ac + '" />';
|
||||||
|
htmlCode += ' <span data-span="mainItem_name">' + obj.modelMainItem_name + '</span>';
|
||||||
|
htmlCode += ' <div class="dd-nodrag btn-group ml-auto">';
|
||||||
|
htmlCode += ' <button type="button" class="btn btn-sm btn-secondary" onclick="editModelMainItem(this);">Edit</button> <button type="button" onclick="delModelMainItem(this);" class="btn btn-sm btn-secondary"><i class="far fa-trash-alt"></i></button>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' ';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' <!-- .dd-list -->';
|
||||||
|
htmlCode += ' <ol class="dd-list">';
|
||||||
|
|
||||||
|
$.each(obj.modelSubItems, function (i, subitem) {
|
||||||
|
htmlCode += subItemHtml(subitem);
|
||||||
|
});
|
||||||
|
|
||||||
|
htmlCode += ' ';
|
||||||
|
htmlCode += ' </ol><!-- /.dd-list -->';
|
||||||
|
htmlCode += ' ';
|
||||||
|
htmlCode += ' <!-- .card-footer -->';
|
||||||
|
htmlCode += ' <div class="card-footer">';
|
||||||
|
htmlCode += ' <a href="javascript: void(0);" onclick="addSubItem(this);" class="card-footer-item justify-content-start"><span><i class="fa fa-plus-circle mr-1"></i> 添加子項目</span></a>';
|
||||||
|
htmlCode += ' </div><!-- /.card-footer -->';
|
||||||
|
htmlCode += '</div><!-- /.card -->';
|
||||||
|
|
||||||
|
return htmlCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function subItemHtml(obj) {
|
||||||
|
var htmlCode = '';
|
||||||
|
|
||||||
|
htmlCode += ' <li class="dd-item dd-nodrag" data-model-subitem-uid="' + obj.modelSubItem_uid + '" data-method="edit">';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="subItem_uid">' + obj.subItem_uid + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subItem_uid">' + obj.modelSubItem_uid + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-name">' + obj.modelSubItem_name + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-price">' + obj.modelSubItem_price + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-unitType">' + obj.modelSubItem_unitType + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-number">' + obj.modelSubItem_number + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-hasAC">' + obj.modelSubItem_hasAC + '</textarea>';
|
||||||
|
htmlCode += ' <textarea style="display:none;" data-name="model-subitem-subTotal">' + obj.modelSubItem_subTotal + '</textarea>';
|
||||||
|
htmlCode += ' <textarea data-name="model-subitem-descript" style="display:none;">' + obj.modelSubItem_descript + '</textarea>';
|
||||||
|
htmlCode += ' <div class="dd-handle">';
|
||||||
|
htmlCode += ' <div class="list-group-item">';
|
||||||
|
htmlCode += ' <div class="list-group-item-figure">';
|
||||||
|
htmlCode += ' <span class="drag-indicator"></span>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' <div class="list-group-item-body">';
|
||||||
|
htmlCode += ' <div class="team">';
|
||||||
|
htmlCode += ' <h4 data-name="subname" class="list-group-item-title">';
|
||||||
|
htmlCode += ' ' + obj.modelSubItem_name;
|
||||||
|
htmlCode += ' </h4><br/>';
|
||||||
|
htmlCode += ' <p class="list-group-item-text" data-name="subdesc" style="white-space: pre-line;font-size: 13px;">';
|
||||||
|
htmlCode += ' ' + obj.modelSubItem_descript;
|
||||||
|
htmlCode += ' </p><br/>';
|
||||||
|
htmlCode += ' <p class="list-group-item-text" data-name="subsummy" style="white-space: pre-line;font-size: 11px;">';
|
||||||
|
htmlCode += ' 單價 NT$' + AppendComma(obj.modelSubItem_price) + ', 數量 ' + obj.modelSubItem_number + ', 單位 ' + obj.modelSubItem_unitType + '\r\n';
|
||||||
|
htmlCode += ' 小計 NT$' + AppendComma(obj.modelSubItem_subTotal) + '\r\n';
|
||||||
|
htmlCode += ' AC(' + obj.modelSubItem_hasAC + ')';
|
||||||
|
htmlCode += ' </p>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' <div class="dd-nodrag btn-group ml-auto">';
|
||||||
|
htmlCode += ' <button type="button" onclick="editSubItemButton(this);" class="btn btn-sm btn-secondary">Edit</button> <button type="button" onclick="delSubItemButton(this);" class="btn btn-sm btn-secondary"><i class="far fa-trash-alt"></i></button>';
|
||||||
|
htmlCode += ' </div>';
|
||||||
|
htmlCode += ' </div> ';
|
||||||
|
htmlCode += ' </li>';
|
||||||
|
|
||||||
|
return htmlCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buttonModelQuotationClick(obj) {
|
||||||
|
var type = obj.getAttribute('data-method');
|
||||||
|
var uid = obj.getAttribute('data-uid');
|
||||||
|
var dept_uid = $('#dept_select').val();
|
||||||
|
var modelProj_uid = $('#parent_modelProj_uid').val();
|
||||||
|
|
||||||
|
modelQuotationRowID = $('#' + uid);
|
||||||
|
|
||||||
|
modelQuotationRowPos = modelQuotationTable.fnGetPosition($('#' + uid)[0]);
|
||||||
|
|
||||||
|
if (type == "del") {
|
||||||
|
if (confirm('確定刪除此報價單範本? ')) {
|
||||||
|
if (confirm('請再次確定刪除此報價單範本? ')) {
|
||||||
|
var formData = {
|
||||||
|
dept_uid: dept_uid,
|
||||||
|
modelQuotation_uid: uid,
|
||||||
|
modelProj_uid: modelProj_uid,
|
||||||
|
method: 'del'
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/AuthApi/addEditDelGetModelQuotation",
|
||||||
|
type: "post",
|
||||||
|
data: formData,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
var row = modelQuotationTable.api().row(modelQuotationRowID).remove().draw(false);
|
||||||
|
alert('刪除成功');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == "edit") {
|
||||||
|
var formData = {
|
||||||
|
dept_uid: dept_uid,
|
||||||
|
modelQuotation_uid: uid,
|
||||||
|
modelProj_uid: modelProj_uid,
|
||||||
|
method: 'get'
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/AuthApi/addEditDelGetModelQuotation",
|
||||||
|
type: "post",
|
||||||
|
data: formData,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
var obj = data.modelQuotationDetails[0];
|
||||||
|
|
||||||
|
$("#modelQuotation_method").val('edit');
|
||||||
|
$("#modelQuotation_uid").val(obj.modelQuotation_uid);
|
||||||
|
$("#modelQuotation_name").val(obj.modelQuotation_name).trigger('change');
|
||||||
|
|
||||||
|
var htmlCode = '';
|
||||||
|
$.each(obj.modelMainItemDetails, function (i, item) {
|
||||||
|
htmlCode += mainItemHtml(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#modelItem_div').html(htmlCode);
|
||||||
|
|
||||||
|
$('#clientModelQuotationPreviewModal').modal('toggle');
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function buttonClick(obj) {
|
function buttonClick(obj) {
|
||||||
|
|
||||||
var type = obj.getAttribute('data-method');
|
var type = obj.getAttribute('data-method');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue