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.
 
 
 
 
 

612 lines
24 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CK.SCP.Common;
using CK.SCP.Controller;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Utils;
using FineUI;
namespace SCP.Views..SupplierData
{
public partial class SCP_INVOICE_EDIT : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
IsRoleRight();
if (!IsPostBack)
{
BindData();
GetInvoice();
SetRoleRule();
}
}
public void IsRoleRight()
{
//if (!CurrentUser.RoleList.Contains("供应商"))
//{
// Alert.Show("当前用户角色不能操作该模块!");
// return;
//}
//if (CurrentUser.VenderList == null || CurrentUser.VenderList.Count == 0)
//{
// Alert.Show("当前用户未选择地点!");
// return;
//}
}
private void SetRoleRule()
{
//IsPriceEdit(Grid1, "单价");
}
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);
}
});
}
public void BindData()
{
Search(ret =>
{
Grid1.RecordCount = ret.Count();
var list = SortAndPage(ret, Grid1);
//Grid1.DataSource =SCP_RECIVECE_CONTROLLER.Get_V_TB_INVOICE_LIST(list.ToList());
List<V_TB_INVOICE_DETAIL> temp = SCP_RECIVECE_CONTROLLER.Get_V_TB_INVOICE_LIST_SYJB(list.ToList());
temp = SCP_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(temp);
Grid1.DataSource = temp;
Grid1.DataBind();
});
}
private void GetInvoice()
{
string id = GetQueryValue("ID");
string vendid = "";
if (CurrentUser.VenderList != null && CurrentUser.VenderList.Count > 0)
{
vendid = CurrentUser.VenderList[0];
}
SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_List(new V_TB_INVOICE { InvcBillNum = id, VendId = vendid }, (ret) => {
if (ret.State == ReturnStatus.Succeed)
{
var _ls = ret.Result.ToList();
if (_ls != null && _ls.Count > 0)
{
var _Model = _ls[0];
Session["Invoice"] = _Model;
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;
//txtDiscountPrice1.Text = _Model.DiscountPrice != null ? _Model.DiscountPrice.ToString() : string.Empty;
txtContractPrice1.Text = _Model.ContractPrice != null ? _Model.ContractPrice.ToString() : "0";
txtBlancePrice1.Text = _Model.BlancePrice != null ? _Model.BlancePrice.ToString() : "0";
txtDiscountPrice1.Text = _Model.DiscountPrice != null ? _Model.DiscountPrice.ToString() : "0";
txtDiscountRemark1.Text = _Model.DiscountRemark != null ? _Model.DiscountRemark.ToString() : string.Empty;
txtAmount.Text = _Model.Amount.ToString();
txtTax.Text = _Model.Tax.ToString();
txtTaxAmount.Text = _Model.TaxAmount.ToString();
txtTotal.Text = _Model.Total != null ? _Model.Total.ToString() : string.Empty;
txtMemo.Text = _Model.Remark;
if (_Model.State == (int)InvoiceState.New || _Model.State == (int)InvoiceState.CheckFail || _Model.State == (int)InvoiceState.FinanceFail)
{
this.btnOK.Hidden = false;
this.btnApply.Hidden = false;
txtInvoiceNumber.Readonly = false;
txtExpressNumber.Readonly = false;
}
if (_Model.State == (int)InvoiceState.Reject)
{
this.btnReject.Hidden = true;
}
//提交之后不能作废
if (_Model.State == (int)InvoiceState.New)
{
this.btnReject.Hidden = false;
}
if (_Model.State == (int)InvoiceState.Apply)
{
this.btnOK.Hidden = true;//确定修改
this.btnApply.Hidden = true;//提交申请
this.btnReject.Hidden = true;//发票作废
this.btnMail.Hidden = true;//寄出发票
}
if (_Model.State == (int)InvoiceState.Mail)
{
this.btnOK.Hidden = true;//确定修改
this.btnApply.Hidden = true;//提交申请
this.btnReject.Hidden = true;//发票作废
this.btnMail.Hidden = true;//寄出发票
txtInvoiceNumber.Readonly = true;
txtInvoiceNumber.Required = false;
txtExpressNumber.Readonly = true;
txtExpressNumber.Required = false;
txtContractPrice1.Readonly = true;
txtContractPrice1.Required = false;
txtBlancePrice1.Readonly = true;
txtBlancePrice1.Required = false;
}
if (_Model.State == (int)InvoiceState.CheckSuccess)
{
txtInvoiceNumber.Readonly = false;
txtInvoiceNumber.Required = true;
txtExpressNumber.Readonly = false;
txtExpressNumber.Required = true;
txtContractPrice1.Readonly = true;
txtContractPrice1.Required = false;
txtBlancePrice1.Readonly = false;
txtBlancePrice1.Required = false;
txtDiscountPrice1.Readonly = true;
txtDiscountPrice1.Required = false;
txtDiscountRemark1.Readonly = true;
txtDiscountRemark1.Required = false;
this.btnMail.Hidden = false;
}
if (_Model.State ==(int) InvoiceState.CheckSuccess)
{
this.btnOK.Hidden = true;
txtMemo.Enabled = false;
for (int i = 0, count = Grid1.Rows.Count; i < count; i++)
{
object[] rowDataKeys = Grid1.DataKeys[i];
GridRow row = Grid1.Rows[i];
var txtPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtPrice");
var txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty");
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");
var txtDiscountPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtDiscountPrice");
var txtDiscountRemark = (System.Web.UI.WebControls.TextBox)row.FindControl("txtDiscountRemark");
//txtPrice.ReadOnly = true;
//txtPrice.Enabled = false;
txtQty.ReadOnly = true;
txtQty.Enabled = false;
txtLineMemo.ReadOnly = true;
txtLineMemo.Enabled = false;
txtContractPrice.ReadOnly = true;
txtContractPrice.Enabled = false;
txtBlancePrice.ReadOnly = true;
txtBlancePrice.Enabled = false;
txtDiscountPrice.ReadOnly = true;
txtDiscountPrice.Enabled = false;
txtDiscountRemark.ReadOnly = true;
txtDiscountRemark.Enabled = false;
}
}
if(_Model.State == (int)InvoiceState.FinanceReceive)
{
btnReject.Hidden = false;
}
if (_Model.State == (int)InvoiceState.CheckFail || _Model.State == (int)InvoiceState.FinanceFail)
{
btnReject.Hidden = false;
}
}
}
});
}
protected void btnOK_Click(object sender, EventArgs e)
{
var _invoice = Session["Invoice"] as V_TB_INVOICE;
string InvoiceNumber = MyWebString.GetString(this.txtInvoiceNumber.Text.Trim());
string Memo = MyWebString.GetString(this.txtMemo.Text.Trim());
string ExpressNumber = MyWebString.GetString(this.txtExpressNumber.Text.Trim());
string ContractPrice1 = MyWebString.GetString(this.txtContractPrice1.Text.Trim());//合同价格
string BlancePrice1 = MyWebString.GetString(this.txtBlancePrice1.Text.Trim());//合同差额
string DiscountPrice1 = MyWebString.GetString(this.txtDiscountPrice1.Text.Trim());//折扣价格
string DiscountRemark1 = MyWebString.GetString(this.txtDiscountRemark1.Text.Trim());//折扣备注
if (_invoice.State != (int)InvoiceState.New &&
_invoice.State != (int)InvoiceState.CheckFail&&
_invoice.State != (int)InvoiceState.FinanceFail)
{
Alert.Show(_invoice.InvcBillNum + " 不允许修改,只有状态为 " + "新建" + " 或 " +
"采购退回" + " 或 " + "财务退回"+ " 才能修改");
return;
}
_invoice.InvoiceNum = InvoiceNumber;
_invoice.Remark = Memo;
_invoice.DiscountRemark = DiscountRemark1;
_invoice.ExpressNum = ExpressNumber;
//_invoice.State = (int)InvoiceState.Apply;
if (string.IsNullOrEmpty(ContractPrice1))
{
_invoice.ContractPrice = 0;
}
if (string.IsNullOrEmpty(BlancePrice1))
{
_invoice.BlancePrice = 0;
}
if (string.IsNullOrEmpty(DiscountPrice1))
{
_invoice.DiscountPrice = 0;
}
decimal c1;
decimal b1;
decimal d1;
if (decimal.TryParse(ContractPrice1, out c1))
{
_invoice.ContractPrice = c1;
}
else
{
Alert.Show("合同价格请填写数字!");
return;
}
if (decimal.TryParse(BlancePrice1, out b1))
{
_invoice.BlancePrice = b1;
}
else
{
_invoice.BlancePrice = 0;
}
if (decimal.TryParse(DiscountPrice1, out d1))
{
_invoice.DiscountPrice = d1;
}
else
{
Alert.Show("折扣价格请填写数字!");
return;
}
List<V_TB_INVOICE_DETAIL> _ls = new List<V_TB_INVOICE_DETAIL>();
Decimal DiscountPricetotal = 0;
if (this.txtQty.ReadOnly == false)
{
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]);
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");
var txtDiscountPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtDiscountPrice");
var txtDiscountRemark = (System.Web.UI.WebControls.TextBox)row.FindControl("txtDiscountRemark");
decimal QtyNew = 0;
try
{
if (txtQty.Text.Trim() != "")
{
QtyNew = Convert.ToDecimal(txtQty.Text.Trim());
}
}
catch
{
Alert.Show("开票数量输入不正确");
return;
}
if (QtyNew > 0)
{
if (QtyNew > _entity.CanQty + _entity.Qty)
{
Alert.Show("开票数量不能大于可用开数票");
return;
}
}
else
{
if (Math.Abs(QtyNew) > Math.Abs(_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;
}
decimal DiscountPriceNew = 0;
try
{
if (txtDiscountPrice.Text.Trim() != "")
{
DiscountPriceNew = Convert.ToDecimal(txtDiscountPrice.Text.Trim());
}
}
catch
{
Alert.Show("折扣价格输入不正确");
return;
}
if (DiscountPriceNew > PriceNew)
{
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("折扣价格不能大于单价"));
return;
}
_entity.Remark = txtLineMemo.Text;
_entity.Price = PriceNew;
_entity.Qty = QtyNew;
_entity.ContractPrice = ContractPriceNew;
_entity.BlancePrice = BlancePriceNew;
_entity.DiscountPrice = DiscountPriceNew;
_entity.DiscountRemark = txtDiscountRemark.Text;
_ls.Add(_entity);
if (DiscountPriceNew > 0)
{
DiscountPricetotal = DiscountPricetotal + DiscountPriceNew * QtyNew;
}
else
{
DiscountPricetotal = DiscountPricetotal + PriceNew * QtyNew;
}
}
}
if (_ls.Count > 0)
{
_invoice.DiscountPrice = DiscountPricetotal;
var ret = SCP_INVOICE_CONTROLLER.SAVE_TB_INVOICE_APPLY(_invoice,_ls,"SYJB");
if (ret.State == ReturnStatus.Succeed)
{
Alert.Show("修改成功!");
GetInvoice();
BindData();
}
else
{
Alert.Show(string.Join("<br>", ret.MessageList));
}
}
else
{
Alert.Show("更改记录数为零");
}
}
private void SET_INVOICE_STATE(string p_msg, InvoiceState p_state)
{
if (Session["Invoice"] != null)
{
var _Invoice = Session["Invoice"] as V_TB_INVOICE;
string InvoiceNumber = MyWebString.GetString(this.txtInvoiceNumber.Text.Trim());//金税票号
string ExpressNumber = MyWebString.GetString(this.txtExpressNumber.Text.Trim());//快递单号
string ContractPrice1 = MyWebString.GetString(this.txtContractPrice1.Text.Trim());//合同价格
string BlancePrice1 = MyWebString.GetString(this.txtBlancePrice1.Text.Trim());//合同差额
_Invoice.InvoiceNum = InvoiceNumber;
_Invoice.ExpressNum = ExpressNumber;
if (string.IsNullOrEmpty(ContractPrice1))
{
_Invoice.ContractPrice = 0;
}
if (string.IsNullOrEmpty(BlancePrice1))
{
_Invoice.BlancePrice = 0;
}
decimal c1;
decimal b1;
if (decimal.TryParse(ContractPrice1, out c1))
{
_Invoice.ContractPrice = c1;
}
else
{
_Invoice.ContractPrice = 0;
}
if (decimal.TryParse(BlancePrice1, out b1))
{
_Invoice.BlancePrice = b1;
}
else
{
_Invoice.BlancePrice = 0;
}
if (p_state == InvoiceState.Mail)
{
if (string.IsNullOrEmpty(InvoiceNumber))
{
Alert.Show("请填写金税票号!");
return;
}
if (string.IsNullOrEmpty(ExpressNumber))
{
Alert.Show("请填写快递单号!");
return;
}
}
var ret = SCP_INVOICE_CONTROLLER.SAVE_TB_INVOICE_STATE(_Invoice, p_state,CurrentUser.ChineseName,"SYJB");
if (ret.State == ReturnStatus.Succeed)
{
SCP.Common.MailManager.SendMailToUser(_Invoice.VendId, string.Format("供应商{0}发布了新的发票申请{1}", _Invoice.VendId,_Invoice.InvcBillNum), string.Format("发票申请{0}{1}", _Invoice.InvcBillNum, p_msg), CurrentUser.FactoryList.FirstOrDefault());
Alert.Show(p_msg);
BindData();
GetInvoice();
}
else
{
Alert.Show(ret.Message);
}
}
}
protected void btnApply_Click(object sender, EventArgs e)
{
SET_INVOICE_STATE("发票申请成功!", InvoiceState.Apply);
}
protected void btnMail_Click(object sender, EventArgs e)
{
SET_INVOICE_STATE("发票已经寄出!", InvoiceState.Mail);
}
protected void btnReject_Click(object sender, EventArgs e)
{
SET_INVOICE_STATE("发票已经作废!", InvoiceState.Reject);
}
protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
BindData();
}
protected void Grid_V_TB_INVOICE_DETAIL_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
{
BindData();
}
protected void Window1_OnClose(object sender, WindowCloseEventArgs e)
{
//string id = GetQueryValue("ID");
//TB_INVOICE model = InvoiceController.GetDataByBillInvoiceBillNum(id);
//InvoiceController.UpdateDataRemark(e.CloseArgument, model);
}
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
var itm = e.DataItem as V_TB_INVOICE_DETAIL;
if (itm.OldPrice != itm.Price)//1未完成得
{
highlightRows.Text += e.RowIndex.ToString() + ",";
}
}
protected void btnRed_Click(object sender, EventArgs e)
{
string id = GetQueryValue("ID");
V_TB_INVOICE _tb = new V_TB_INVOICE();
_tb.InvcBillNum = id;
var ret = SCP_INVOICE_CONTROLLER.Add_New_Red_Invoice(_tb);
if (ret.State == ReturnStatus.Succeed)
{
BindData();
GetInvoice();
}
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindData();
}
}
}