/// <summary> /// 商品汇总单拆分采购单 /// </summary> /// <param name="NeedToPurchaseId"></param> /// <param name="branchId"></param> /// <param name="StoreId"></param> /// <returns></returns> public bool PurchaseSave(int NeedToPurchaseId, int branchId, int StoreId) { DataTable dtNeedToPurchaseDetail = ReadNeedToPurchaseDetail(NeedToPurchaseId).Tables[0]; if (dtNeedToPurchaseDetail.Rows.Count > 0) { int SId = 0; double taxRate = 0; int isTax = 0; string invoiceType = ""; int SupplierId = 0; foreach (DataRow dr in dtNeedToPurchaseDetail.Rows) { SupplierId = DBTool.GetIntFromRow(dr, "SupplierId", 0); taxRate = DBTool.GetDoubleFromRow(dr, "SprTaxRate", 0.17); invoiceType = DBTool.GetStringFromRow(dr, "SprInvoiceType", ""); switch (invoiceType) { case "无发票": isTax = 0; taxRate = 0; break; case "增票": isTax = 1; break; case "普票": isTax = 2; break; default: isTax = 1; taxRate = 0.17; break; } int UserId = DBTool.GetIntFromRow(dr, "UserId", 0); string PurchaseType = DBTool.GetStringFromRow(dr, "PurchaseType", ""); Purchase p = new Purchase(); p.BranchId = branchId; p.NeedToPurchaseId = NeedToPurchaseId; p.PurchaseStatus = CommenClass.PurchaseStatus.未处理.ToString(); p.PurchaseType = PurchaseType; p.UserId = 0; p.StoreId = StoreId; p.SupplierId = SupplierId; p.PurchaseUserId = UserId; p.IsTax = isTax; p.TaxRate = taxRate; int purchaseId = p.Save(); if (purchaseId > 0) { string sql = string.Format(@"insert into PurchaseDetail(PurchaseId,GoodsId,StoreId,Model,BillsPrice,InPrice,Num,Amount,ReceivedNum,OldStore,OldAC,Emergency,TaxInPrice) select {0}, GoodsId, {1}, '', InPrice, (case when {7}=0 then InPrice*1.25 when {7}=1 then InPrice/(1+{6}) when {7}=2 then InPrice end), -LackNum, (InPrice * (-LackNum)), 0, {1}, InPrice, Emergency, (case when {7}=0 then InPrice*1.25*1.17 when {7}=1 then InPrice when {7}=2 then InPrice*(1+{6}) end) from NeedToPurchaseDetail where NeedToPurchaseId={2} and SupplierId={3} and UserId={4} and LackNum<0; update Purchase set SumMoney=(select ISNULL(SUM(Amount),0) from PurchaseDetail where PurchaseId={0}), Tax=(select ISNULL(SUM(Amount),0) from PurchaseDetail where PurchaseId={0})/(1+{6})*{6} where Id={0}", purchaseId, StoreId, NeedToPurchaseId, SupplierId, UserId, PurchaseType, taxRate, isTax); m_dbo.ExecuteNonQuery(sql); SId = SupplierId; } } NeedToPurchase ntp = new NeedToPurchase(); ntp.AddStatus(NeedToPurchaseId); return(true); } return(false); }