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.
416 lines
16 KiB
416 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity.Migrations;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using CK.SCP.Controller;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Utils;
|
|
using FineUI;
|
|
using NPOI.OpenXmlFormats.Dml;
|
|
using SCP.Code;
|
|
using SCP.WarehouseData;
|
|
using System.Drawing;
|
|
|
|
namespace SCP.Views.SupplierData.SupplierFinance
|
|
{
|
|
public partial class SCP_INVOICE_CREATE : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
IsRoleRight();
|
|
if (!IsPostBack)
|
|
{
|
|
TranslatorAgents(Toolbar2);
|
|
TranslatorAgent(Grid_SCP_INVOICE_CREATE);
|
|
TranslatorAgents(FormRow_1);
|
|
LoadData();
|
|
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()
|
|
{
|
|
//IsPriceVisible(Grid_SCP_INVOICE_CREATE, "合同价格");
|
|
//IsPriceVisible(Grid_SCP_INVOICE_CREATE, "合同差额");
|
|
IsPriceVisible(Grid_SCP_INVOICE_CREATE, "要货日期");
|
|
}
|
|
|
|
public void LoadData()
|
|
{
|
|
BindData();
|
|
}
|
|
|
|
|
|
private void SearchData(Action<IQueryable<V_TB_RECEIVE_LIST>> p_action)
|
|
{
|
|
V_TB_RECEIVE_LIST _entity = new V_TB_RECEIVE_LIST();
|
|
|
|
|
|
if (Session["InvoiceCreateQueryParm"] != null)
|
|
{
|
|
InvoiceCreateQueryParm parm = Session["InvoiceCreateQueryParm"] as InvoiceCreateQueryParm;
|
|
|
|
if (string.IsNullOrEmpty(parm.ReceiveID))
|
|
|
|
{ Alert.Show("参数不正确!"); return; }
|
|
var ary = parm.ReceiveID.Split(',');
|
|
if (ary != null && ary.Length > 0)
|
|
{
|
|
_entity.UIDList = new List<long>();
|
|
foreach (var itm in ary)
|
|
{
|
|
_entity.UIDList.Add(long.Parse(itm));
|
|
}
|
|
_entity.State = 1;
|
|
_entity.UserInVendIds = CurrentUser.VenderList;
|
|
SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST_List(_entity, (ret) =>
|
|
{
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
p_action(ret.Result);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show("操作超时!");
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public void BindData()
|
|
{
|
|
SearchData(q =>
|
|
{
|
|
|
|
InvoiceCreateQueryParm parm = Session["InvoiceCreateQueryParm"] as InvoiceCreateQueryParm;
|
|
Grid_SCP_INVOICE_CREATE.RecordCount = q.Count();
|
|
q = SortAndPage<V_TB_RECEIVE_LIST>(q, Grid_SCP_INVOICE_CREATE);
|
|
// List<V_TB_RECEIVE_LIST> temp = SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST(q.ToList());
|
|
List<V_TB_RECEIVE_LIST> temp = SCP_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(q.ToList());
|
|
|
|
foreach (V_TB_RECEIVE_LIST rec in temp)
|
|
{
|
|
rec.Qty = ToDecimal(rec.Qty, 2);
|
|
rec.CanQty = ToDecimal(rec.CanQty, 2);
|
|
}
|
|
|
|
string _vendId = string.Empty;
|
|
if (CurrentUser.RoleList.Contains("采购人员"))
|
|
{
|
|
|
|
_vendId = parm.VendId;
|
|
}
|
|
else
|
|
{
|
|
_vendId = CurrentUser.VenderList[0];
|
|
}
|
|
//SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST_PRICE(_vendId, temp, (rs) =>
|
|
//{
|
|
|
|
// if (rs.State == ReturnStatus.Succeed)
|
|
// {
|
|
// temp.ForEach(itm =>
|
|
// {
|
|
// var _entityList = rs.Result.ToList().Where(p => p.PartCode == itm.PartCode && itm.CreateTime >= p.StartTime && itm.CreateTime <= p.EndTime).ToList();
|
|
// if (_entityList.Count > 0)
|
|
// {
|
|
// var _max = _entityList.Select(p => p.UID).Max();
|
|
// var _entity = _entityList.Where(p => p.UID == _max).FirstOrDefault();
|
|
// if (itm.ModType == (int)BillModType.Contract)
|
|
// {
|
|
// if (CurrentUser.FactoryList.FirstOrDefault() == "CNS")
|
|
// {
|
|
// itm.Price = _entity.Amt;
|
|
// }
|
|
// else
|
|
// {
|
|
// itm.Price = itm.Price > 0 ? itm.Price : _entity.Amt;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// itm.Price = itm.Price > 0 ? itm.Price : _entity.Amt;
|
|
// }
|
|
// }
|
|
// });
|
|
// }
|
|
//});
|
|
|
|
var _isall=parm.IsAll;
|
|
if(_isall=="0")
|
|
{
|
|
temp.ForEach(p => {
|
|
p.InputQty =0;
|
|
if (p.CanQty < 0)
|
|
{
|
|
p.InputQty = p.CanQty;
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
temp.ForEach(p => { p.InputQty = p.CanQty; });
|
|
}
|
|
|
|
Grid_SCP_INVOICE_CREATE.DataSource = temp;
|
|
Grid_SCP_INVOICE_CREATE.DataBind();
|
|
|
|
});
|
|
}
|
|
|
|
|
|
public decimal ToDecimal(decimal num, int scale)
|
|
{
|
|
decimal tempOdds = Math.Round(num, scale);
|
|
|
|
return tempOdds;
|
|
}
|
|
|
|
protected void ddlGridPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid_SCP_INVOICE_CREATE.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
|
|
BindData();
|
|
}
|
|
//确认创建发票
|
|
protected void btnOk_OnClick(object sender, EventArgs e)
|
|
{
|
|
if (Session["InvoiceCreateQueryParm"] != null)
|
|
{
|
|
|
|
|
|
InvoiceCreateQueryParm parm = Session["InvoiceCreateQueryParm"] as InvoiceCreateQueryParm;
|
|
|
|
V_TB_INVOICE invoice = new V_TB_INVOICE();
|
|
invoice.InvcBillNum = SCP_BILLCODE_CONTROLLER.MakeInvoiceCode();
|
|
invoice.CreateTime = DateTime.Now;
|
|
invoice.InvoiceNum = "";
|
|
invoice.Remark = txtRemark.Text;
|
|
invoice.CreateUser = CurrentUser.Name;
|
|
|
|
string _VendId = parm.VendId;
|
|
string _tax = parm.Tax;
|
|
invoice.VendId = _VendId;
|
|
invoice.State = (int)InvoiceState.New;
|
|
invoice.Tax = decimal.Parse(_tax);
|
|
string _cj = parm.CJ;
|
|
string _tz = parm.TZ;
|
|
invoice.BlancePrice = decimal.Parse(_tz);
|
|
invoice.ContractPrice = decimal.Parse(_cj);
|
|
|
|
int num = 0;
|
|
List<V_TB_RECEIVE_LIST> _list = new List<V_TB_RECEIVE_LIST>();
|
|
for (int i = 0; i < Grid_SCP_INVOICE_CREATE.Rows.Count; i++)
|
|
{
|
|
object[] rowDataKeys = Grid_SCP_INVOICE_CREATE.DataKeys[i];
|
|
string uid = rowDataKeys[0].ToString();
|
|
var _entity = new V_TB_RECEIVE_LIST();
|
|
_entity.UID = ConvertHelper.To<Int32>(rowDataKeys[0]);
|
|
_entity.RecvBillNum = rowDataKeys[1] as string;
|
|
_entity.PoLine = ConvertHelper.To<Int32>(rowDataKeys[2]);
|
|
_entity.PartCode = rowDataKeys[3] as string;
|
|
_entity.Batch = rowDataKeys[4] as string;
|
|
_entity.Qty = ConvertHelper.To<Decimal>(rowDataKeys[5]);
|
|
_entity.DockCode = rowDataKeys[6] as string;
|
|
_entity.Remark = rowDataKeys[7] as string;
|
|
_entity.CreateTime = ConvertHelper.To<DateTime>(rowDataKeys[8]);
|
|
_entity.CreateUser = rowDataKeys[9] as string;
|
|
if (string.IsNullOrEmpty(_entity.CreateUser))
|
|
{
|
|
_entity.CreateUser = CurrentUser.Name;
|
|
}
|
|
_entity.IsDeleted = ConvertHelper.To<Boolean>(rowDataKeys[10]);
|
|
_entity.AsnBillNum = rowDataKeys[12] as string;
|
|
_entity.Site = rowDataKeys[13] as string;
|
|
invoice.Site = rowDataKeys[13] as string;
|
|
_entity.VendId = rowDataKeys[14] as string;
|
|
_entity.ShipTime = ConvertHelper.To<DateTime?>(rowDataKeys[15]);
|
|
_entity.OperName = rowDataKeys[16] as string;
|
|
_entity.PartDesc1 = rowDataKeys[17] as string;
|
|
_entity.State = ConvertHelper.To<Int32>(rowDataKeys[18]);
|
|
_entity.PoBillNum = rowDataKeys[19] as string;
|
|
_entity.VendName = rowDataKeys[20] as string;
|
|
_entity.Site_Desc = rowDataKeys[21] as string;
|
|
_entity.PoUnit = rowDataKeys[22] as string;
|
|
_entity.LocUnit = rowDataKeys[23] as string;
|
|
_entity.Price = ConvertHelper.To<Decimal>(rowDataKeys[24]);
|
|
_entity.VendBatch = rowDataKeys[25] as string;
|
|
_entity.Currency = rowDataKeys[26] as string;
|
|
_entity.BillType_DESC = rowDataKeys[27] as string;
|
|
_entity.ErpRecvBillNum= rowDataKeys[28] as string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.Web.UI.WebControls.Label _label = (System.Web.UI.WebControls.Label)Grid_SCP_INVOICE_CREATE.Rows[i].FindControl("Total1");
|
|
_entity.CanQty = ConvertHelper.To<Decimal>(_label.Text);//ConvertHelper.To < Int32 >(rowDataKeys[2]);
|
|
GridRow row = Grid_SCP_INVOICE_CREATE.Rows[i];
|
|
System.Web.UI.WebControls.TextBox txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty");
|
|
System.Web.UI.WebControls.TextBox txtPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtPrice");
|
|
System.Web.UI.WebControls.TextBox txtLineMemo = (System.Web.UI.WebControls.TextBox)row.FindControl("txtLineMemo");
|
|
|
|
decimal Qty = 0;
|
|
try
|
|
{
|
|
if (txtQty.Text.Trim() != "")
|
|
{
|
|
Qty = Convert.ToDecimal(txtQty.Text.Trim());
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("开票数量输入不正确"));
|
|
return;
|
|
}
|
|
|
|
decimal Price = 0;
|
|
try
|
|
{
|
|
if (txtPrice.Text.Trim() != "")
|
|
{
|
|
Price = Convert.ToDecimal(txtPrice.Text.Trim());
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("单价输入不正确"));
|
|
return;
|
|
}
|
|
|
|
if (Qty == 0)
|
|
{
|
|
continue;
|
|
}
|
|
if (Qty > _entity.CanQty)
|
|
{
|
|
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("开票数量不能大于可用开票数量"));
|
|
return;
|
|
}
|
|
_entity.Qty = Qty;
|
|
_entity.Price = Price;
|
|
_entity.Remark = txtLineMemo.Text;
|
|
_list.Add(_entity);
|
|
num++;
|
|
}
|
|
if (num == 0)
|
|
{
|
|
PageContext.RegisterStartupScript(Alert.GetShowInTopReference("没有可用的开票记录"));
|
|
return;
|
|
}
|
|
int _number = 0;
|
|
_list.ForEach(p =>
|
|
{
|
|
if (p.Qty > 0)
|
|
{
|
|
_number++;
|
|
}
|
|
});
|
|
if (_number == _list.Count)
|
|
{
|
|
string _modify = parm.Modify;
|
|
if (_modify == "1")
|
|
{
|
|
Alert.Show("有退货单未处理!");
|
|
return;
|
|
}
|
|
}
|
|
var ret = SCP_INVOICE_CONTROLLER.CREATE_TB_INVOICE(invoice, _list);
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
string script = $"alert(\'发票 {invoice.InvcBillNum} 生成成功\');";
|
|
script += ActiveWindow.GetHidePostBackReference();
|
|
PageContext.RegisterStartupScript(script);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show("操作超时");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected void Grid_SCP_INVOICE_CREATE_RowDataBound(object sender, GridRowEventArgs e)
|
|
{
|
|
object[] rowDataKeys = Grid_SCP_INVOICE_CREATE.DataKeys[e.RowIndex];
|
|
|
|
|
|
System.Web.UI.WebControls.Label _label = (System.Web.UI.WebControls.Label)Grid_SCP_INVOICE_CREATE.Rows[e.RowIndex].FindControl("Total1");
|
|
|
|
var _number = ConvertHelper.To<Decimal>(_label.Text);
|
|
if (_number<= 0)
|
|
{
|
|
GridRow row = Grid_SCP_INVOICE_CREATE.Rows[e.RowIndex];
|
|
System.Web.UI.WebControls.TextBox txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty");
|
|
txtQty.ReadOnly = true;
|
|
txtQty.Enabled = false;
|
|
if (_number < 0)
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(_label.Text))
|
|
{
|
|
if (decimal.Parse(_label.Text) < 0)
|
|
{
|
|
_label.ForeColor = Color.Red;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private decimal? GetTax()
|
|
{
|
|
decimal? strTax = null;
|
|
string name = GetIdentityName();
|
|
User modelUsers = DB.Users.SingleOrDefault(p => p.Name == name);
|
|
VenderUsers vu = null;
|
|
TA_VENDER tv = null;
|
|
|
|
if (modelUsers != null)
|
|
{
|
|
vu = DB.VenderUsers.SingleOrDefault(p => p.UserId == modelUsers.ID);
|
|
if (vu != null)
|
|
{
|
|
tv = SCPDB.TA_VENDER.SingleOrDefault(p => p.VendId == vu.VenderId);
|
|
|
|
if (tv != null)
|
|
{
|
|
strTax = tv.Tax;
|
|
}
|
|
}
|
|
//_info.SupplierCode = vu.VenderId;
|
|
}
|
|
Session["InvoiceCreateQueryParm"] = null;
|
|
return strTax;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|