/// <summary> 创建出入库单配件信息 /// </summary> /// <param name="stock_inout_id">出入库单ID</param> /// <param name="parts_model">采购开单配件信息</param> bool CreateIntoPartsStock(string stock_inout_id, tb_parts_purchase_billing_p parts_model, string billid, string billno) { tb_parts_stock_inout_p PartsInoutModel = new tb_parts_stock_inout_p(); Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 PartsInoutModel.stock_inout_parts_id = Guid.NewGuid().ToString(); PartsInoutModel.stock_inout_id = stock_inout_id; if (!string.IsNullOrEmpty(parts_model.wh_id)) { PartsInoutModel.wh_id = parts_model.wh_id; PartsInoutModel.wh_name = parts_model.wh_name; } PartsInoutModel.num = parts_model.num; PartsInoutModel.parts_code = parts_model.parts_code; PartsInoutModel.parts_name = parts_model.parts_name; PartsInoutModel.drawing_num = parts_model.drawing_num; if (!string.IsNullOrEmpty(parts_model.unit_id)) { PartsInoutModel.unit = parts_model.unit_id; PartsInoutModel.unit_name = parts_model.unit_name; } PartsInoutModel.parts_brand = parts_model.parts_brand; PartsInoutModel.counts = parts_model.business_counts;//业务数量 PartsInoutModel.parts_barcode = parts_model.parts_barcode;//条码 PartsInoutModel.car_parts_code = parts_model.car_factory_code;//车厂编码 if(parts_model.make_date>0) { PartsInoutModel.make_date = parts_model.make_date;//生产日期 } if (parts_model.arrival_date > 0) { PartsInoutModel.validity_date = parts_model.arrival_date;//到期、有效日期 } PartsInoutModel.is_gift = parts_model.is_gift; PartsInoutModel.remark = parts_model.remark; PartsInoutModel.create_by = GlobalStaticObj.UserID; PartsInoutModel.create_name = GlobalStaticObj.UserName; PartsInoutModel.create_time = Common.LocalDateTimeToUtcLong(DateTime.Now); PartsInoutModel.reference_billid = billid; PartsInoutModel.reference_billno = billno; PartsInoutModel.model = parts_model.model; foreach (PropertyInfo info in PartsInoutModel.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(PartsInoutModel, null); dicParam.Add(name, value == null ? "" : value.ToString()); } return DBHelper.Submit_AddOrEdit("出入库配件表添加信息", "tb_parts_stock_inout_p", "stock_inout_parts_id", "", dicParam); }
/// <summary> 创建出入库单配件信息 /// </summary> /// <param name="stock_inout_id">出入库单ID</param> /// <param name="parts_model">采购开单配件信息</param> bool CreateIntoPartsStock(string stock_inout_id, tb_parts_purchase_billing_p parts_model) { tb_parts_stock_inout_p PartsInoutModel = new tb_parts_stock_inout_p(); Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 PartsInoutModel.stock_inout_parts_id = Guid.NewGuid().ToString(); PartsInoutModel.stock_inout_id = stock_inout_id; PartsInoutModel.wh_id = parts_model.wh_id; PartsInoutModel.num = parts_model.num; PartsInoutModel.parts_num = parts_model.parts_code; PartsInoutModel.parts_name = parts_model.parts_name; PartsInoutModel.drawing_num = parts_model.drawing_num; PartsInoutModel.unit = parts_model.unit_id; PartsInoutModel.unit_name = parts_model.unit_name; PartsInoutModel.parts_brand = parts_model.parts_brand; PartsInoutModel.count = parts_model.storage_count;//入库数量 PartsInoutModel.is_gift = parts_model.is_gift; PartsInoutModel.remark = parts_model.remark; PartsInoutModel.create_by = GlobalStaticObj.UserID; PartsInoutModel.create_name = GlobalStaticObj.UserName; PartsInoutModel.create_time = Common.LocalDateTimeToUtcLong(DateTime.Now); foreach (PropertyInfo info in PartsInoutModel.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(PartsInoutModel, null); dicParam.Add(name, value == null ? "" : value.ToString()); } return DBHelper.Submit_AddOrEdit("出入库配件表添加信息", "tb_parts_stock_inout_p", "stock_inout_parts_id", "", dicParam); }
/// <summary> /// 审核通过后需要自动生成的单子的方法 /// </summary> void CreateBill(List<string> listField) { try { if (listField.Count > 0) { string bill_ids = string.Empty; List<SysSQLString> listSql = new List<SysSQLString>(); DataTable TemplateTable = CommonFuncCall.CreatePartStatisticTable();//获取要填充的公用表 for (int i = 0; i < listField.Count; i++) { DataTable dt = DBHelper.GetTable("", "tb_parts_purchase_billing", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", ""); if (dt != null && dt.Rows.Count > 0) { DataTable dt_bill_p = new DataTable(); tb_parts_purchase_billing model = new tb_parts_purchase_billing(); CommonFuncCall.SetModlByDataTable(model, dt); #region 开单审核通过后,更新配件的账面库存 string str_time = Common.UtcLongToLocalDateTime(model.order_date).ToShortDateString(); long long_time = Common.LocalDateTimeToUtcLong(Convert.ToDateTime(str_time)); DataTable IOPartTable = DBHelper.GetTable("", "tb_parts_purchase_billing_p", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", ""); if (IOPartTable != null && IOPartTable.Rows.Count > 0) { for (int a = 0; a < IOPartTable.Rows.Count; a++) { DataRow dr = TemplateTable.NewRow();//创建模版表行项 dr["OrderDate"] = long_time.ToString();//单据日期 dr["WareHouseID"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["wh_id"]);//仓库ID dr["WareHouseName"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["wh_name"]);//仓库名称 dr["PartID"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["parts_id"]);//配件ID dr["PartCode"] = IOPartTable.Rows[a]["parts_code"].ToString();//配件编码 dr["PartName"] = IOPartTable.Rows[a]["parts_name"].ToString();//配件名称 dr["PartSpec"] = IOPartTable.Rows[a]["model"].ToString();//配件规格 dr["PartBarCode"] = IOPartTable.Rows[a]["parts_barcode"].ToString();//配件条码 dr["CarPartsCode"] = IOPartTable.Rows[a]["car_factory_code"].ToString();//车厂编码 dr["DrawNum"] = IOPartTable.Rows[a]["drawing_num"].ToString();//配件图号 dr["UnitName"] = IOPartTable.Rows[a]["unit_name"].ToString();//单位名称 //dr["PartCount"] = IOPartTable.Rows[a]["business_counts"].ToString();//配件业务数量 dr["PartCount"] = Convert.ToDecimal(IOPartTable.Rows[a]["business_counts"].ToString());//配件业务数量 dr["StatisticType"] = (int)DataSources.EnumStatisticType.PaperCount;//统计类型 TemplateTable.Rows.Add(dr);//添加新的数据行项 } } #endregion #region 当金额大于0时,自动生成预付款单 if (model.this_payment > 0) { tb_bill_receivable a = new tb_bill_receivable(); tb_balance_documents b = new tb_balance_documents(); tb_payment_detail c = new tb_payment_detail(); a.cust_id = model.sup_id;//供应商ID a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.PAYMENT);//订单号 a.order_type = (int)DataSources.EnumOrderType.PAYMENT; a.payment_type = (int)DataSources.EnumPaymentType.PAYMENT; a.org_id = model.org_id; b.billing_money = model.this_payment;//开单金额 b.documents_date = model.order_date;//单据日期 b.documents_id = model.purchase_billing_id;//单据ID b.documents_name = "采购开单";//单据名称 b.documents_num = model.order_num;//单据编码 c.money = model.this_payment;//金额 c.balance_way = model.balance_way;//结算方式 c.check_number = model.check_number;//票号 DBOperation.AddBillReceivable(a, b, c); } #endregion #region 自动生产出入库单 #region 一:采购收货单(业务数量大于0)-->自动生成入库单 if (model.order_type == Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseReceive).ToString()) { string stock_inout_id = string.Empty; //1.生成入库单 if (CreateIntoStock("入库单", model, ref stock_inout_id)) { //2.查询配件信息,生成配件信息入库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { dt_bill_p = dt_parts; for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); bool ret = CreateIntoPartsStock(stock_inout_id, bill_p_model, model.purchase_billing_id, model.order_num); } } } } #endregion #region 二:采购退货(业务数量小于0)-->自动生成出库单 else if (model.order_type == Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseBack).ToString()) { string stock_inout_id = string.Empty; //1.生成出库单 if (CreateIntoStock("出库单", model, ref stock_inout_id)) { //2.查询配件信息,生成配件信息出库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); bool ret = CreateIntoPartsStock(stock_inout_id, bill_p_model, model.purchase_billing_id, model.order_num); } } } } #endregion #region 三:采购换货-->自动生成出、入库单(数量大于0是入库,小于0是出库) else if (model.order_type == Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseExchange).ToString()) { string stock_in_id = string.Empty; string stock_out_id = string.Empty; //1.生成入库单 if (CreateIntoStock("入库单", model, ref stock_in_id)) { //2.查询配件入库数量大于0的,生成配件信息入库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and isnull(business_counts,0)>0 ", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); bool ret = CreateIntoPartsStock(stock_in_id, bill_p_model, model.purchase_billing_id, model.order_num); } } } //3.生成出库单 if (CreateIntoStock("出库单", model, ref stock_out_id)) { //4.查询配件入库数量小于0的,生成配件信息出库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and isnull(business_counts,0)<0 ", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); CreateIntoPartsStock(stock_out_id, bill_p_model, model.purchase_billing_id, model.order_num); } } } } #endregion #endregion #region 向宇通发送配送单号 if (!string.IsNullOrEmpty(model.ration_send_code)) { //DBHelper.WebServHandler("审核通过入库时发送配送单号到宇通系统", EnumWebServFunName.UpLoadPartPutStore, model.ration_send_code); DBHelper.WebServHandler("", EnumWebServFunName.LoadPartInStore, model.ration_send_code); } #endregion #region 审核通过时,将本次现付更新到已结算金额中 if (model.this_payment > 0) { SysSQLString sysStringSql = new SysSQLString(); sysStringSql.cmdType = CommandType.Text; Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 dicParam.Add("balance_money", model.this_payment.ToString()); dicParam.Add("purchase_billing_id", listField[i]); StringBuilder sb = new StringBuilder(); sb.Append(" Update tb_parts_purchase_billing Set balance_money=@balance_money where purchase_billing_id=@purchase_billing_id"); sysStringSql.Param = dicParam; sysStringSql.sqlString = sb.ToString(); listSql.Add(sysStringSql); } #endregion #region 如果配送单号不为空,需将对应的配送单状态修改为“已收货” if (!string.IsNullOrEmpty(model.ration_send_code)) { SysSQLString sysStringSql = new SysSQLString(); sysStringSql.cmdType = CommandType.Text; Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 dicParam.Add("distribution_status", "2");//1:配送中,2:已收货 dicParam.Add("ration_send_code", model.ration_send_code); StringBuilder sb = new StringBuilder(); sb.Append(" Update tb_distribution Set distribution_status=@distribution_status where ration_send_code=@ration_send_code"); sysStringSql.Param = dicParam; sysStringSql.sqlString = sb.ToString(); listSql.Add(sysStringSql); } #endregion #region 如果配送单号不为空,需通过配送单将对应的宇通采购订单的确认数量修改下 // if (!string.IsNullOrEmpty(model.ration_send_code)) // { // if (dt_bill_p != null && dt_bill_p.Rows.Count > 0) // { // dt_bill_p = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", ""); // if (dt_bill_p != null && dt_bill_p.Rows.Count > 0) // { // string wherestr = string.Format(@"purchase_order_yt_id in // ( // select top 1 purchase_order_yt_id from tb_parts_purchase_order_2 where dsn_adjustable_parts in // ( // select top 1 dsn_adjustable_parts from tb_distribution where ration_send_code='{0}' // ) // )", model.ration_send_code); // DataTable dt_yt_p = DBHelper.GetTable("采购开单审核通过时,修改宇通采购订单配件信息量", "tb_parts_purchase_order_p_2", "*", wherestr, "", ""); // if (dt_yt_p != null && dt_yt_p.Rows.Count > 0) // { // foreach (DataRow dr in dt_bill_p.Rows) // { // DataRow[] dr_yt_p = dt_yt_p.Select("parts_code ='" + dr["parts_code"].ToString() + "'"); // if (dr_yt_p.Length > 0) // { // decimal old_conf_count = Convert.ToDecimal(dr_yt_p[0]["conf_count"].ToString()); // decimal new_conf_count = Convert.ToDecimal(dr["business_counts"].ToString()); // SysSQLString sysStringSql = new SysSQLString(); // sysStringSql.cmdType = CommandType.Text; // Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 // dicParam.Add("conf_count", (old_conf_count + new_conf_count).ToString()); // dicParam.Add("purchase_order_yt_id", dr_yt_p[0]["purchase_order_yt_id"].ToString()); // dicParam.Add("parts_code", dr_yt_p[0]["parts_code"].ToString()); // StringBuilder sb = new StringBuilder(); // sb.Append(" Update tb_parts_purchase_order_p_2 Set conf_count=@conf_count where purchase_order_yt_id=@purchase_order_yt_id and parts_code=@parts_code"); // sysStringSql.Param = dicParam; // sysStringSql.sqlString = sb.ToString(); // listSql.Add(sysStringSql); // } // } // } // } // } // } #endregion } } CommonFuncCall.StatisticStock(TemplateTable, "采购开单审核通过后更新配件的账面库存"); //审核通过时,将本次现付更新到已结算金额中 if (listSql.Count > 0) { DBHelper.BatchExeSQLStringMultiByTrans("采购开单审核通过时,将本次现付更新到已结算金额中或是更新配送单状态", listSql); } } } catch (Exception ex) { } }
/// <summary> /// 审核通过后需要自动生成的单子的方法 /// </summary> void CreateBill(List<string> listField) { if (listField.Count > 0) { for (int i = 0; i < listField.Count; i++) { DataTable dt = DBHelper.GetTable("", "tb_parts_purchase_billing", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", ""); if (dt != null && dt.Rows.Count > 0) { tb_parts_purchase_billing model = new tb_parts_purchase_billing(); CommonFuncCall.SetModlByDataTable(model, dt); #region 当金额大于0时,自动生成预付款单 if (model.this_payment > 0) { tb_bill_receivable a = new tb_bill_receivable(); tb_balance_documents b = new tb_balance_documents(); tb_payment_detail c = new tb_payment_detail(); a.cust_id = model.sup_id;//供应商ID a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.PAYMENT);//订单号 a.order_type = (int)DataSources.EnumOrderType.PAYMENT; a.payment_type = (int)DataSources.EnumPaymentType.PAYMENT; a.org_id = model.org_id; b.billing_money = model.this_payment;//开单金额 b.documents_date = model.order_date;//单据日期 b.documents_id = model.purchase_billing_id;//单据ID b.documents_name = "采购开单";//单据名称 b.documents_num = model.order_num;//单据编码 c.money = model.this_payment;//金额 c.balance_way = model.balance_way;//结算方式 c.check_number = model.check_number;//票号 DBOperation.AddBillReceivable(a, b, c); } #endregion #region 自动生产出入库单 #region 一:采购收货单-->自动生成入库单 if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseReceive.ToString()) { string stock_inout_id = string.Empty; //1.生成入库单 if (CreateIntoStock("入库单", model, ref stock_inout_id)) { //2.查询配件信息,生成配件信息入库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); CreateIntoPartsStock(stock_inout_id, bill_p_model); } } } } #endregion #region 二:采购退货-->自动生成出库单 else if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseBack.ToString()) { string stock_inout_id = string.Empty; //1.生成出库单 if (CreateIntoStock("出库单", model, ref stock_inout_id)) { //2.查询配件信息,生成配件信息出库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); CreateIntoPartsStock(stock_inout_id, bill_p_model); } } } } #endregion #region 三:采购换货-->自动生成出、入库单(数量大于0是入库,小于0是出库) else if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseExchange.ToString()) { string stock_in_id = string.Empty; string stock_out_id = string.Empty; //1.生成入库单 if (CreateIntoStock("入库单", model, ref stock_in_id)) { //2.查询配件入库数量大于0的,生成配件信息入库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and storage_count>0 ", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); CreateIntoPartsStock(stock_in_id, bill_p_model); } } } //3.生成出库单 if (CreateIntoStock("出库单", model, ref stock_out_id)) { //4.查询配件入库数量小于0的,生成配件信息出库单 DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and storage_count<0 ", "", ""); if (dt_parts != null && dt_parts.Rows.Count > 0) { for (int a = 0; a < dt_parts.Rows.Count; a++) { tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p(); CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a); CreateIntoPartsStock(stock_out_id, bill_p_model); } } } } #endregion #endregion #region 向宇通发送配送单号 if (!string.IsNullOrEmpty(model.ration_send_code)) { //DBHelper.WebServHandler("审核通过入库时发送配送单号到宇通系统", EnumWebServFunName.UpLoadPartPutStore, model.ration_send_code); DBHelper.WebServHandler("", EnumWebServFunName.LoadPartInStore, model.ration_send_code); } #endregion } } } }