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.
527 lines
19 KiB
527 lines
19 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Controller;
|
|
using FineUI;
|
|
using SCP.Code;
|
|
using System.Drawing;
|
|
using CK.SCP.Models.Enums;
|
|
using CK.SCP.Models;
|
|
|
|
namespace SCP.SupplierData
|
|
{
|
|
|
|
public partial class ReceiveList : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
IsRoleRight();
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
TranslatorAgents(Toolbar2);
|
|
TranslatorAgent(Grid_V_TB_RECEIVE_LIST);
|
|
TranslatorAgents(FormRow_1);
|
|
TranslatorAgents(FormRow_2);
|
|
TranslatorAgents(FormRow_3);
|
|
LoadData();
|
|
SetRoleRule();
|
|
BindVender(DDL_VEND_LIST);
|
|
}
|
|
}
|
|
public void IsRoleRight()
|
|
{
|
|
|
|
//if (!CurrentUser.RoleList.Contains("供应商"))
|
|
//{
|
|
// Alert.Show("当前用户角色不能操作该模块!");
|
|
// return;
|
|
//}
|
|
//else
|
|
//{
|
|
|
|
//}
|
|
//if (CurrentUser.VenderList == null || CurrentUser.VenderList.Count == 0)
|
|
//{
|
|
// Alert.Show("当前用户未选择地点!");
|
|
// return;
|
|
//}
|
|
}
|
|
private void SetRoleRule()
|
|
{
|
|
if (CurrentUser.RoleList.Contains("采购人员"))
|
|
{
|
|
DDL_VEND_LIST.Hidden = false;
|
|
BTN_INV.Hidden = false;
|
|
if( CurrentUser.FactoryList!=null && CurrentUser.FactoryList.Count>0)
|
|
{
|
|
var _site= CurrentUser.FactoryList.FirstOrDefault();
|
|
if(_site=="CNS")
|
|
{
|
|
txtContractPrice1.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void LoadData()
|
|
{
|
|
// 每页记录数
|
|
Grid_V_TB_RECEIVE_LIST.PageSize = ConfigHelper.PageSize;
|
|
ddlGridPageSize.SelectedValue = ConfigHelper.PageSize.ToString();
|
|
BindData();
|
|
}
|
|
private void SearchData(Action<IQueryable<V_TB_RECEIVE_LIST>> p_action)
|
|
{
|
|
V_TB_RECEIVE_LIST _ls = new V_TB_RECEIVE_LIST();
|
|
_ls.PoBillNum = TXT_BillNo.Text;
|
|
_ls.VendName = TXT_VendName.Text;
|
|
|
|
_ls.AsnBillNum = TXT_ASNBill.Text;
|
|
_ls.PartCode = TXT_PartCode.Text;
|
|
_ls.VendId = TXT_VendId.Text;
|
|
_ls.ProjectId = TXT_ProjectId.Text;
|
|
if (DP_StartDate.SelectedDate != null)
|
|
{
|
|
_ls.BeginTime = DP_StartDate.SelectedDate;
|
|
}
|
|
if (Date_EndDate.SelectedDate != null)
|
|
{
|
|
_ls.ShipTime = Date_EndDate.SelectedDate;
|
|
}
|
|
if (!string.IsNullOrEmpty(DDL_State.SelectedValue))
|
|
{
|
|
_ls.BillType_DESC = DDL_State.SelectedValue;
|
|
}
|
|
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
|
|
{
|
|
_ls.Site = CurrentUser.FactoryList[0];
|
|
}
|
|
_ls.State = 1;
|
|
|
|
|
|
|
|
|
|
if (CurrentUser.RoleList.Contains("采购人员"))
|
|
{
|
|
if (string.IsNullOrEmpty(DDL_VEND_LIST.SelectedValue))
|
|
{
|
|
Alert.Show("请在工具栏里选择要开票的供应商,并点击确认!");
|
|
return;
|
|
}
|
|
var _venderId = DDL_VEND_LIST.SelectedValue;
|
|
_ls.VendId = DDL_VEND_LIST.SelectedValue;
|
|
if (!string.IsNullOrEmpty(_ls.Site) && !string.IsNullOrEmpty(_venderId))
|
|
{
|
|
var _vender = SCP_TB_VENDER_CONTROLLER.GetVender(_venderId, _ls.Site);
|
|
if (_vender.Tax > 0 && _vender.Tax != null)
|
|
{
|
|
lbTaxRate.SelectedValue = _vender.Tax.ToString();
|
|
}
|
|
else
|
|
{
|
|
lbTaxRate.SelectedValue = "0";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CurrentUser.VenderList != null && CurrentUser.VenderList.Count > 0)
|
|
{
|
|
var _venderId = CurrentUser.VenderList.FirstOrDefault();
|
|
_ls.VendId = _venderId;
|
|
if (!string.IsNullOrEmpty(_ls.Site) && !string.IsNullOrEmpty(_venderId))
|
|
{
|
|
var _vender = SCP_TB_VENDER_CONTROLLER.GetVender(_venderId, _ls.Site);
|
|
if (_vender.Tax >0&&_vender.Tax!=null)
|
|
{
|
|
lbTaxRate.SelectedValue = _vender.Tax.ToString();
|
|
}
|
|
else
|
|
{
|
|
lbTaxRate.SelectedValue = "0";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(_ls.VendId))
|
|
{
|
|
return;
|
|
}
|
|
SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST_List(_ls, (ret) =>
|
|
{
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
p_action(ret.Result);
|
|
}
|
|
});
|
|
|
|
}
|
|
public void BindData()
|
|
{
|
|
SearchData(ret =>
|
|
{
|
|
if (CurrentUser.RoleList.Contains("采购人员"))
|
|
{
|
|
Grid_V_TB_RECEIVE_LIST.RecordCount = ret.Count();
|
|
ret = SortAndPage(ret, Grid_V_TB_RECEIVE_LIST,"DESC");
|
|
|
|
List<V_TB_RECEIVE_LIST> temp = ret.ToList();
|
|
if (string.IsNullOrEmpty(DDL_VEND_LIST.SelectedValue))
|
|
{
|
|
Alert.Show("请在工具栏里选择要开票的供应商,并点击确认!");
|
|
return;
|
|
}
|
|
|
|
Grid_V_TB_RECEIVE_LIST.DataSource = temp;
|
|
Grid_V_TB_RECEIVE_LIST.DataBind();
|
|
}
|
|
else
|
|
{
|
|
|
|
Grid_V_TB_RECEIVE_LIST.RecordCount = ret.Count();
|
|
ret = SortAndPage(ret, Grid_V_TB_RECEIVE_LIST,"DESC");
|
|
List<V_TB_RECEIVE_LIST> temp = ret.ToList();
|
|
|
|
Grid_V_TB_RECEIVE_LIST.DataSource = temp;
|
|
Grid_V_TB_RECEIVE_LIST.DataBind();
|
|
}
|
|
});
|
|
// 排列和数据库分页
|
|
}
|
|
protected void Grid1_OnPageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
Grid_V_TB_RECEIVE_LIST.PageIndex = e.NewPageIndex;
|
|
BindData();
|
|
}
|
|
|
|
protected void ddlGridPageSize_OnSelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid_V_TB_RECEIVE_LIST.PageSize = Convert.ToInt32(ddlGridPageSize.SelectedValue);
|
|
BindData();
|
|
}
|
|
//生成发票
|
|
protected void btnCreate_OnClick(object sender, EventArgs e)
|
|
{
|
|
CreateInvoice("0");
|
|
}
|
|
private void CreateInvoice(string p_all)
|
|
{
|
|
try
|
|
{
|
|
|
|
string vender = string.Empty;
|
|
if (CurrentUser.RoleList.Contains("采购人员"))
|
|
{
|
|
if (string.IsNullOrEmpty(DDL_VEND_LIST.SelectedValue))
|
|
{
|
|
Alert.Show("请在工具栏里选择要开票的供应商,并点击确认!");
|
|
return;
|
|
}
|
|
vender = DDL_VEND_LIST.SelectedValue;
|
|
}
|
|
else
|
|
{
|
|
vender = CurrentUser.VenderList[0];
|
|
}
|
|
|
|
TM_HYANTOLIN_REVIEW _entity = new TM_HYANTOLIN_REVIEW();
|
|
_entity.UltimateName = vender;
|
|
_entity.State = 0;
|
|
var _state = 0;
|
|
SCP_QUALITY_CONTROLLER.Get_TM_HYANTOLIN_REVIEW_List(_entity, (rs) =>
|
|
{
|
|
if (rs.State == ReturnStatus.Succeed)
|
|
{
|
|
var _ls = rs.Result.ToList();
|
|
if (_ls != null && _ls.Count > 0)
|
|
{
|
|
var _sum = _ls.Sum(p => p.ClaimAmount);
|
|
var _ary = _ls.Select(p => p.ReviewBillNum).ToList();
|
|
_state = 1;
|
|
if (_sum == 0)
|
|
{
|
|
_state = 0;
|
|
}
|
|
if (_sum > 0)
|
|
{
|
|
Alert.Show(string.Format("索赔金额合计{0}供应商存在未处理索赔单{1}!", _sum.ToString(), string.Join(",", _ary.ToArray())), "索赔管理查看");
|
|
}
|
|
}
|
|
}
|
|
});
|
|
if (_state == 1)
|
|
{
|
|
return;
|
|
}
|
|
var _tax = lbTaxRate.SelectedValue;
|
|
var _cj = string.IsNullOrEmpty(txtContractPrice1.Text) ? "0" : txtContractPrice1.Text;
|
|
var _tz = string.IsNullOrEmpty(txtBlancePrice1.Text) ? "0" : txtBlancePrice1.Text;
|
|
|
|
string IsCreate = "0";
|
|
|
|
if (Grid_V_TB_RECEIVE_LIST.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.Show("请选择要创建发票的记录!");
|
|
return;
|
|
}
|
|
string IDS = "";
|
|
List<string> _list = new List<string>();
|
|
List<string> _projectList = new List<string>();
|
|
List<string> _rejList = new List<string>();
|
|
string _projectId = string.Empty;
|
|
List<string> _recList = new List<string>();
|
|
List<int> IdList = new List<int>();
|
|
decimal _total = 0;
|
|
|
|
for (int i = 0; i < Grid_V_TB_RECEIVE_LIST.SelectedRowIndexArray.Length; i++)
|
|
{
|
|
int rowIndex = Grid_V_TB_RECEIVE_LIST.SelectedRowIndexArray[i];
|
|
int ID = Convert.ToInt32(Grid_V_TB_RECEIVE_LIST.DataKeys[rowIndex][0]);
|
|
|
|
decimal _qty = decimal.Parse(Grid_V_TB_RECEIVE_LIST.DataKeys[rowIndex][5].ToString());
|
|
|
|
decimal _price = decimal.Parse(Grid_V_TB_RECEIVE_LIST.DataKeys[rowIndex][6].ToString());
|
|
|
|
_total += (_qty * _price);
|
|
IDS += ID + ",";
|
|
_projectId = Grid_V_TB_RECEIVE_LIST.DataKeys[rowIndex][1].ToString();
|
|
_projectList.Add(_projectId);
|
|
var _recbill = Grid_V_TB_RECEIVE_LIST.DataKeys[rowIndex][2].ToString();
|
|
if (!string.IsNullOrEmpty(_recbill) && _recbill.IndexOf("R.") > 0)
|
|
{
|
|
_rejList.Add(_projectId);
|
|
}
|
|
IdList.Add(ID);
|
|
|
|
|
|
}
|
|
if(!ScpCache.Config.负数发票)
|
|
{
|
|
if (_total < 0)
|
|
{
|
|
Alert.Show("不允许开负数发票!退货、索赔零件数量有问题,请联系工厂库房和质量解决!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (IdList.Count > 1000)
|
|
{
|
|
Alert.Show("选择发票条数"+ IdList.Count + "超过1000条,发票允许条数!");
|
|
return;
|
|
}
|
|
|
|
if (_list.Distinct().Count() > 1)
|
|
{
|
|
Alert.Show("请选择的记录不是同一个供应商,请选择供应商!");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
if (IDS != "") IDS = IDS.Substring(0, IDS.Length - 1);
|
|
|
|
if (CurrentUser.FactoryList.FirstOrDefault() != "BJCIAI"&& CurrentUser.FactoryList.FirstOrDefault() != "JZ1")
|
|
{
|
|
var _ls = GetIsAllChecked(vender, IDS);
|
|
if (_ls.Count > 0)
|
|
{
|
|
Alert.Show(string.Format("退货或索赔单{0}未开票!", string.Join(",", _ls.ToArray())));
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
InvoiceCreateQueryParm parm = new InvoiceCreateQueryParm();
|
|
parm.ReceiveID = IDS;
|
|
parm.VendId = vender;
|
|
parm.Modify = IsCreate;
|
|
parm.IsAll = p_all;
|
|
parm.Tax = _tax;
|
|
parm.CJ = _cj;
|
|
parm.TZ = _tz;
|
|
|
|
Session["InvoiceCreateQueryParm"] = parm;
|
|
string ret = Window1.GetShowReference("../../Views/SupplierData/SCP_INVOICE_CREATE.aspx", "生成发票");
|
|
PageContext.RegisterStartupScript(ret);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Alert.Show(ex.Message);
|
|
}
|
|
}
|
|
private List<string> GetIsAllChecked(string p_VendId,string p_VendIds)
|
|
{
|
|
|
|
List<string> unSelected = new List<string>();
|
|
|
|
var _ls = SCPDB.V_TB_RECEIVE_LIST.Where(p => p.VendId == p_VendId && p.State == 1 && (p.BillType_DESC == "索赔单" || p.BillType_DESC == "退货单")).Select(p => new { p.UID, p.RecvBillNum }).ToList();
|
|
|
|
//SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST_List(_ent, (ret) =>
|
|
//{
|
|
// if (ret.State == ReturnStatus.Succeed)
|
|
// {
|
|
var _lsCompare = p_VendIds.Split(new char[] { ',' });
|
|
// var _ls = ret.Result.Select(p => new { p.UID, p.RecvBillNum }).ToList();
|
|
foreach (var itm in _ls)
|
|
{
|
|
if (!_lsCompare.Contains(itm.UID.ToString()))
|
|
{
|
|
unSelected.Add(itm.RecvBillNum);
|
|
}
|
|
}
|
|
// }
|
|
//});
|
|
return unSelected.Distinct().ToList();
|
|
}
|
|
|
|
|
|
protected void Grid_V_TB_RECEIVE_LIST_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindData();
|
|
}
|
|
|
|
//导出
|
|
protected void btnOutput_OnClick(object sender, EventArgs e)
|
|
{
|
|
V_TB_RECEIVE_LIST _ls = new V_TB_RECEIVE_LIST();
|
|
_ls.PoBillNum = TXT_BillNo.Text;
|
|
_ls.VendName = TXT_VendName.Text;
|
|
_ls.UserInVendIds = CurrentUser.VenderList;
|
|
_ls.AsnBillNum = TXT_ASNBill.Text;
|
|
_ls.PartCode = TXT_PartCode.Text;
|
|
_ls.VendId = TXT_VendId.Text;
|
|
_ls.ProjectId = TXT_ProjectId.Text;
|
|
_ls.RecvBillNum = TXT_RECEIVE.Text;
|
|
if (DP_StartDate.SelectedDate != null)
|
|
{
|
|
_ls.BeginTime = DP_StartDate.SelectedDate;
|
|
}
|
|
if (Date_EndDate.SelectedDate != null)
|
|
{
|
|
_ls.ShipTime = Date_EndDate.SelectedDate;
|
|
}
|
|
if (!string.IsNullOrEmpty(DDL_State.SelectedValue))
|
|
{
|
|
_ls.BillType_DESC = DDL_State.SelectedValue;
|
|
}
|
|
if (CurrentUser.FactoryList != null && CurrentUser.FactoryList.Count > 0)
|
|
{
|
|
_ls.Site = CurrentUser.FactoryList[0];
|
|
}
|
|
_ls.State = 1;
|
|
if (CurrentUser.VenderList != null && CurrentUser.VenderList.Count > 0)
|
|
{
|
|
var _venderId = CurrentUser.VenderList.FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(_ls.Site) && !string.IsNullOrEmpty(_venderId))
|
|
{
|
|
var _vender = SCP_TB_VENDER_CONTROLLER.GetVender(_venderId, _ls.Site);
|
|
if (_vender.Tax > 0 && _vender.Tax != null)
|
|
{
|
|
lbTaxRate.SelectedValue = _vender.Tax.ToString();
|
|
}
|
|
else
|
|
{
|
|
lbTaxRate.Text = "0";
|
|
}
|
|
}
|
|
}
|
|
|
|
SCP_RECIVECE_CONTROLLER.Get_V_TB_RECEIVE_LIST_List(_ls, (ret) =>
|
|
{
|
|
if (ret.State == ReturnStatus.Succeed)
|
|
{
|
|
var _lst = ret.Result.ToList();
|
|
|
|
Dictionary<string, string> cellheader = new Dictionary<string, string>
|
|
{
|
|
{ "ProjectId", "项目编号" },
|
|
{ "BillType_DESC", "单据类型" },
|
|
{ "RecvBillNum", "单据编号" },
|
|
{ "AsnBillNum", "发货单号" },
|
|
{ "VendName", "供应商" },
|
|
{ "VendId", "供应商编码" },
|
|
{ "PoBillNum", "订单号" },
|
|
{ "PoLine", "订单行" },
|
|
{ "PartCode", "零件号" },
|
|
{ "PartDesc1", "零件名称" },
|
|
{ "LocUnit", "单位" },
|
|
{ "Currency", "币种" },
|
|
{ "CanQty", "可开票数量" },
|
|
{ "Price", "单价" },
|
|
{ "CreateTime", "创建时间" }
|
|
};
|
|
string url = EntityListToExcel2003(cellheader,_lst , "审核明细");
|
|
}
|
|
});
|
|
}
|
|
//快速查找
|
|
protected void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
protected void btnShow_Click(object sender, EventArgs e)
|
|
{
|
|
gp1.Hidden = false;
|
|
}
|
|
protected void BtnClose_Click(object sender, EventArgs e)
|
|
{
|
|
gp1.Hidden = true;
|
|
}
|
|
protected void BtnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
BindData();
|
|
}
|
|
|
|
protected void Grid_V_TB_RECEIVE_LIST_RowDataBound(object sender, GridRowEventArgs e)
|
|
{
|
|
System.Web.UI.WebControls.Label _label= (System.Web.UI.WebControls.Label)Grid_V_TB_RECEIVE_LIST.Rows[e.RowIndex].FindControl("Qty1");
|
|
if (!string.IsNullOrEmpty(_label.Text))
|
|
{
|
|
if (decimal.Parse(_label.Text) < 0)
|
|
{
|
|
_label.ForeColor = Color.Red;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void btnCanIn_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void BTN_INV_Click(object sender, EventArgs e)
|
|
{
|
|
BindData();
|
|
}
|
|
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
Session["InvoiceCreateQueryParm"] = null;
|
|
BindData();
|
|
}
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
Grid_V_TB_RECEIVE_LIST.SortDirection = e.SortDirection;
|
|
Grid_V_TB_RECEIVE_LIST.SortField = e.SortField;
|
|
BindData();
|
|
}
|
|
protected void btnCreateAll_Click(object sender, EventArgs e)
|
|
{
|
|
CreateInvoice("1");
|
|
}
|
|
|
|
|
|
}
|
|
}
|