You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

495 lines
20 KiB

using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CK.SCP.Models;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Utils;
using CK.SCP.Controller;
using FineUI;
namespace SCP.Views..WarehouseData
{
public partial class SCP_INVOICE_DELTAIL_RED : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
IsRoleRight();
if (!IsPostBack)
{
GetInvoice();
BindData();
SetRoleRule();
}
}
public void IsRoleRight()
{
if (!CurrentUser.RoleList.Contains("财务人员"))
{
Alert.Show("当前用户角色不能操作该模块!");
return;
}
if (CurrentUser.FactoryList == null || CurrentUser.FactoryList.Count == 0)
{
Alert.Show("当前用户未选择地点!");
return;
}
}
private void SetRoleRule()
{
IsPriceVisible(Grid1, "合同价格");
IsPriceVisible(Grid1, "合同差额");
IsPriceVisible(Grid1, "要货日期");
}
//修改备注
protected void btnEdit_OnClick(object sender, EventArgs e)
{
string id = GetQueryValue("ID");
if (string.IsNullOrEmpty(txtMemo.Text.Trim()))
{
Alert.Show("请填写备注!");
return;
}
var ro = SCP_INVOICE_CONTROLLER.UpdateMemoByInvcBillNum(id, txtMemo.Text.Trim());
if (ro.State == ReturnStatus.Succeed)
{
Alert.Show("备注修改成功!");
return;
}
else
{
Alert.Show("备注修改失败!");
return;
}
}
//确定发票
protected void btnReceive_OnClick(object sender, EventArgs e)
{
SET_INVOICE_STATE("财务接收发票", InvoiceState.FinanceReceive);
}
//取消发票
protected void btnRejectReceive_OnClick(object sender, EventArgs e)
{
SET_INVOICE_STATE("财务取消发票", InvoiceState.Mail);
}
private void SET_INVOICE_STATE(string p_msg, InvoiceState p_state)
{
string id = GetQueryValue("ID");
var ro = SCP_INVOICE_CONTROLLER.SET_INVOICE_STATE(id, p_state);
if (ro.State == ReturnStatus.Succeed)
{
Alert.Show(p_msg + "成功!");
if (CurrentUser.ConfigList.Keys.Contains("供应商邮件"))
{
SCP.Common.MailManager.SendMail(ro.Message, p_msg, p_msg);
}
GetInvoice();
BindData();
return;
}
else
{
Alert.Show(p_msg + "失败!");
return;
}
}
private void GetInvoice()
{
string id = GetQueryValue("ID");
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_List(new V_TB_INVOICE { InvcBillNum = id, IsRed = false },(ret)=> {
if (ret.State == ReturnStatus.Succeed)
{
var _ls= ret.Result.ToList();
if (_ls != null && _ls.Count > 0)
{
var _Model = _ls[0];
txtState.Text = _Model.State_DESC;
txtBillNo.Text = _Model.InvcBillNum;
txtBillTime.Text = Convert.ToDateTime(_Model.CreateTime).ToString("yyyy-MM-dd");
txtSupplierName.Text = _Model.VendName;
txtInvoiceNumber.Text = _Model.InvoiceNum;
txtExpressNumber.Text = _Model.ExpressNum;
txtContractPrice1.Text = _Model.ContractPrice != null ? _Model.ContractPrice.ToString() : string.Empty;
txtBlancePrice1.Text = _Model.BlancePrice != null ? _Model.BlancePrice.ToString() : string.Empty;
txtAmount.Text = _Model.Amount.ToString();
txtTotal.Text = _Model.Total!=null? _Model.Total.ToString():string.Empty;
txtDiscountPrice1.Text = _Model.DiscountPrice != null ? _Model.DiscountPrice.ToString() : string.Empty;
txtDiscountRemark1.Text = _Model.DiscountRemark != null ? _Model.DiscountRemark.ToString() : string.Empty;
txtMemo.Text = _Model.Remark;
if (Convert.ToInt32(_Model.State) == (int)InvoiceState.FinanceReceive)
{
btnNewRed.Hidden = false;
}
else
{
btnNewRed.Hidden = true;
}
}
}
});
}
private void Search(Action<IQueryable<V_TB_INVOICE_DETAIL>> p_list)
{
string id = GetQueryValue("ID");
V_TB_INVOICE_DETAIL _tb = new V_TB_INVOICE_DETAIL();
_tb.InvcBillNum = id;
_tb.IsRed = false;
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_DETAIL_List(_tb,(ret)=> {
if (ret.State == ReturnStatus.Succeed)
{
p_list(ret.Result);
}
});
}
private void Search2(Action<IQueryable<V_TB_INVOICE_DETAIL>> p_list)
{
string id = GetQueryValue("ID");
V_TB_INVOICE_DETAIL _tb = new V_TB_INVOICE_DETAIL();
_tb.InvcBillNum = id;
_tb.IsRed = true;
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_DETAIL_List(_tb, (ret) => {
if (ret.State == ReturnStatus.Succeed)
{
p_list(ret.Result);
}
});
}
public void BindData()
{
Search(ret =>
{
foreach (V_TB_INVOICE_DETAIL det in ret)
{
det.Qty = -1;
}
Grid1.RecordCount = ret.Count();
var list = SortAndPage<V_TB_INVOICE_DETAIL>(ret, Grid1);
Grid1.DataSource = list;
Grid1.DataBind();
});
}
private void GetInvoice2()
{
string id = GetQueryValue("ID");
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_List(new V_TB_INVOICE { InvcBillNum = id, IsRed = true }, (ret) => {
if (ret.State == ReturnStatus.Succeed)
{
var _ls = ret.Result.ToList();
if (_ls != null && _ls.Count > 0)
{
var _Model = _ls[0];
txtState.Text = _Model.State_DESC;
txtBillNo.Text = _Model.InvcBillNum;
txtBillTime.Text = Convert.ToDateTime(_Model.CreateTime).ToString("yyyy-MM-dd");
txtSupplierName.Text = _Model.VendName;
txtInvoiceNumber.Text = _Model.InvoiceNum;
txtExpressNumber.Text = _Model.ExpressNum;
txtContractPrice1.Text = _Model.ContractPrice != null ? _Model.ContractPrice.ToString() : string.Empty;
txtBlancePrice1.Text = _Model.BlancePrice != null ? _Model.BlancePrice.ToString() : string.Empty;
txtAmount.Text = _Model.Amount.ToString();
txtTotal.Text = _Model.Total != null ? _Model.Total.ToString() : string.Empty;
txtDiscountPrice1.Text = _Model.DiscountPrice != null ? _Model.DiscountPrice.ToString() : string.Empty;
txtDiscountRemark1.Text = _Model.DiscountRemark != null ? _Model.DiscountRemark.ToString() : string.Empty;
txtMemo.Text = _Model.Remark;
if (Convert.ToInt32(_Model.State) == (int)InvoiceState.FinanceReceive)
{
btnNewRed.Hidden = false;
}
else
{
btnNewRed.Hidden = true;
}
}
}
});
}
public void BindData2()
{
Search2(ret =>
{
Grid1.RecordCount = ret.Count();
var list = SortAndPage<V_TB_INVOICE_DETAIL>(ret, Grid1);
Grid1.DataSource = list;
Grid1.DataBind();
});
}
//财务退回
protected void btnInvoiceFail_OnClick(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(
Window1.GetShowReference("../WarehouseData/SCP_INVOICE_CHECKFAIL.aspx", "财务退回")
);
}
protected void Window1_OnClose(object sender, WindowCloseEventArgs e)
{
//string id = GetQueryValue("ID");
if (string.IsNullOrEmpty(e.CloseArgument))
{
Alert.Show("请输入退回原因");
return;
}
else
{
string Memo = e.CloseArgument;
string id = GetQueryValue("ID");
var ro = SCP_INVOICE_CONTROLLER.CaiWu_Return_Reason(id, Memo);
if (ro.State == ReturnStatus.Succeed)
{
Alert.Show("财务退回成功!");
if (CurrentUser.ConfigList.Keys.Contains("供应商邮件"))
{
SCP.Common.MailManager.SendMail(ro.Message, "财务退回成功", "财务退回成功");
}
GetInvoice();
BindData();
return;
}
else
{
Alert.Show("财务退回失败!");
return;
}
}
}
protected void btnNewRed_Click(object sender, EventArgs e)
{
string id = GetQueryValue("ID");//InvcBillNum
V_TB_INVOICE _entity1 = new V_TB_INVOICE();
_entity1.InvcBillNum = id;
_entity1.UserInAddress = CurrentUser.FactoryList;
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_List(_entity1, (ret) =>
{
if (ret.State == ReturnStatus.Succeed)
{
V_TB_INVOICE inv = ret.Result.FirstOrDefault();
if (inv != null)
{
inv.IsRed = true;
List<V_TB_INVOICE_DETAIL> _ls = new List<V_TB_INVOICE_DETAIL>();
for (int i = 0, count = Grid1.Rows.Count; i < count; i++)
{
object[] rowDataKeys = Grid1.DataKeys[i];
GridRow row = Grid1.Rows[i];
V_TB_INVOICE_DETAIL _entity = new V_TB_INVOICE_DETAIL();
//_entity.UID = ConvertHelper.To<Int32>(rowDataKeys[0]);
_entity.InvcBillNum = rowDataKeys[1] as string;
_entity.Qty = ConvertHelper.To<Decimal>(rowDataKeys[2]);
_entity.CanQty = ConvertHelper.To<Decimal>(rowDataKeys[3]);
_entity.State = ConvertHelper.To<Int32>(rowDataKeys[4]);
_entity.Site = rowDataKeys[5] as string;
_entity.InvoiceNum = rowDataKeys[6] as string;
_entity.ExpressNum = rowDataKeys[7] as string;
_entity.VendId = rowDataKeys[8] as string;
if (rowDataKeys[9] != null)
{
_entity.Tax = decimal.Parse(rowDataKeys[9].ToString());
}
if (rowDataKeys[10] != null)
{
_entity.CreateTime = DateTime.Parse(rowDataKeys[10].ToString());
}
_entity.CreateUser = rowDataKeys[11] as string;
if (rowDataKeys[12] != null)
{
_entity.UpdateTime = DateTime.Parse(rowDataKeys[12].ToString());
}
_entity.UpdateUser = rowDataKeys[13] as string;
_entity.UpdateInfo = rowDataKeys[14] as string;
_entity.IsDeleted = Boolean.Parse(rowDataKeys[15].ToString());
//_entity.GUID = GUID.rowDataKeys[16] as string;
if (rowDataKeys[16] != null)
_entity.AsnBillNum = rowDataKeys[16].ToString();
if (rowDataKeys[17] != null)
_entity.Batch = rowDataKeys[17].ToString();
if (rowDataKeys[18] != null)
_entity.BeginTime = DateTime.Parse(rowDataKeys[18].ToString());
if (rowDataKeys[19] != null)
_entity.Currency = rowDataKeys[19].ToString();
if (rowDataKeys[20] != null)
_entity.CurrencyDesc = rowDataKeys[20].ToString();
if (rowDataKeys[21] != null)
_entity.DiscountPrice = decimal.Parse(rowDataKeys[21].ToString());
if (rowDataKeys[22] != null)
_entity.DiscountRemark = rowDataKeys[22].ToString();
_entity.PackQty = ConvertHelper.To<Decimal>(rowDataKeys[23]);
if (rowDataKeys[24] != null)
_entity.PartCode = rowDataKeys[24].ToString();
if (rowDataKeys[25] != null)
_entity.PartDesc1 = rowDataKeys[25].ToString();
if (rowDataKeys[26] != null)
_entity.PoBillNum = rowDataKeys[26].ToString();
if (rowDataKeys[27] != null)
_entity.PoLineNum = ConvertHelper.To<Int32>(rowDataKeys[27]);
if (rowDataKeys[28] != null)
_entity.PoUnit = rowDataKeys[28].ToString();
if (rowDataKeys[29] != null)
_entity.ProduceDate = DateTime.Parse(rowDataKeys[29].ToString());
if (rowDataKeys[30] != null)
_entity.RecvBillNum = rowDataKeys[30].ToString();
if (rowDataKeys[31] != null)
_entity.VendBatch = rowDataKeys[31].ToString();
if (rowDataKeys[32] != null)
_entity.GUID = new Guid(rowDataKeys[32] as string);
var txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty");
var txtPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtPrice");
var txtLineMemo = (System.Web.UI.WebControls.TextBox)row.FindControl("txtLineMemo");
var txtContractPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtContractPrice");
var txtBlancePrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtBlancePrice");
decimal QtyNew = 0;
try
{
if (txtQty.Text.Trim() != "")
{
QtyNew = Convert.ToDecimal(txtQty.Text.Trim());
}
}
catch
{
Alert.Show("开票数量输入不正确");
return;
}
if (QtyNew > _entity.CanQty + _entity.Qty)
{
Alert.Show("开票数量不能大于可用开数票");
return;
}
decimal PriceNew = 0;
try
{
if (txtPrice.Text.Trim() != "")
{
PriceNew = Convert.ToDecimal(txtPrice.Text.Trim());
}
}
catch
{
Alert.Show("单价输入不正确");
return;
}
decimal ContractPriceNew = 0;
try
{
if (txtContractPrice.Text.Trim() != "")
{
ContractPriceNew = Convert.ToDecimal(txtContractPrice.Text.Trim());
}
}
catch
{
Alert.Show("合同价格输入不正确");
return;
}
decimal BlancePriceNew = 0;
try
{
if (txtBlancePrice.Text.Trim() != "")
{
BlancePriceNew = Convert.ToDecimal(txtBlancePrice.Text.Trim());
}
}
catch
{
Alert.Show("合同差额输入不正确");
return;
}
_entity.Remark = txtLineMemo.Text;
_entity.Price = PriceNew;
_entity.Qty = QtyNew;
_entity.ContractPrice = ContractPriceNew;
_entity.BlancePrice = BlancePriceNew;
_entity.IsRed = true;
_entity.UserInAddress = CurrentUser.FactoryList;
_entity.UserInVendIds = CurrentUser.VenderList;
_ls.Add(_entity);
}
if (_ls.Count > 0)
{
var ret1 = SCP_INVOICE_CONTROLLER.SAVE_TB_INVOICE_RED(inv, _ls);
if (ret1.State == ReturnStatus.Succeed)
{
Alert.Show("红字发票创建成功!");
//GetInvoice2();
//BindData2();
}
}
else
{
Alert.Show("更改记录数为零");
}
}
}
});
}
}
}