protected override void DoSearch() { string partyCode = this.tbPartyCode.Text != string.Empty ? this.tbPartyCode.Text.Trim() : string.Empty; string receiver = this.tbReceiver.Text != string.Empty ? this.tbReceiver.Text.Trim() : string.Empty; string startDate = this.tbStartDate.Text != string.Empty ? this.tbStartDate.Text.Trim() : string.Empty; string endDate = this.tbEndDate.Text != string.Empty ? this.tbEndDate.Text.Trim() : string.Empty; string itemCode = this.tbItemCode.Text != string.Empty ? this.tbItemCode.Text.Trim() : string.Empty; string currency = this.tbCurrency.Text != string.Empty ? this.tbCurrency.Text.Trim() : string.Empty; DateTime?effDateFrom = null; if (startDate != string.Empty) { effDateFrom = DateTime.Parse(startDate); } DateTime?effDateTo = null; if (endDate != string.Empty) { effDateTo = DateTime.Parse(endDate).AddDays(1).AddMilliseconds(-1); } IList <ActingBill> actingBillList = TheActingBillMgr.GetActingBill(partyCode, receiver, effDateFrom, effDateTo, itemCode, currency, this.ModuleType, this.billNo, true); this.ucNewList.BindDataSource(actingBillList != null && actingBillList.Count > 0 ? actingBillList : null); this.ucNewList.Visible = true; }
protected override void DoSearch() { string partyCode = this.tbPartyCode.Text != string.Empty ? this.tbPartyCode.Text.Trim() : string.Empty; string receiver = this.tbReceiver.Text != string.Empty ? this.tbReceiver.Text.Trim() : string.Empty; string startDate = this.tbStartDate.Text != string.Empty ? this.tbStartDate.Text.Trim() : string.Empty; string endDate = this.tbEndDate.Text != string.Empty ? this.tbEndDate.Text.Trim() : string.Empty; string itemCode = this.tbItemCode.Text != string.Empty ? this.tbItemCode.Text.Trim() : string.Empty; string currency = this.tbCurrency.Text != string.Empty ? this.tbCurrency.Text.Trim() : string.Empty; string externalRece = ExternalReceiptNo.SelectedValue; DateTime?effDateFrom = null; if (startDate != string.Empty) { effDateFrom = DateTime.Parse(startDate); } DateTime?effDateTo = null; if (endDate != string.Empty) { effDateTo = DateTime.Parse(endDate).AddDays(1).AddMilliseconds(-1); } bool needRecalculate = bool.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_RECALCULATE_WHEN_BILL).Value); if (needRecalculate) { IList <ActingBill> allactingBillList = TheActingBillMgr.GetActingBill(partyCode, receiver, effDateFrom, effDateTo, itemCode, currency, this.ModuleType, this.billNo, true); TheActingBillMgr.RecalculatePrice(allactingBillList, this.CurrentUser); } //djin 2013-3-20 内部客户 if (partyCode != string.Empty) { var IsIntern = TheCustomerMgr.LoadCustomer(partyCode).IsIntern; this.tbIsIntern.Value = IsIntern.ToString(); } IList <ActingBill> actingBillList = TheActingBillMgr.GetActingBill(partyCode, receiver, effDateFrom, effDateTo, itemCode, currency, this.ModuleType, this.billNo, null); //djin 2013-3-20 客户回单 var hd = (from b in actingBillList where !string.IsNullOrEmpty(b.ExternalReceiptNo) //!= null select b.ExternalReceiptNo.Substring(0, 2)).Distinct(); ExternalReceiptNo.Items.Clear(); ExternalReceiptNo.Items.Add(new ListItem("ALL", "ALL")); foreach (var i in hd) { ListItem item = new ListItem(i); ExternalReceiptNo.Items.Add(item); } if (externalRece != "ALL") { var afterF = from a in actingBillList where (a.ExternalReceiptNo != null && a.ExternalReceiptNo.Count() >= 2 && a.ExternalReceiptNo.Substring(0, 2) == externalRece) select a; this.ucNewList.BindDataSource(afterF.ToList()); } else { this.ucNewList.BindDataSource(actingBillList != null && actingBillList.Count > 0 ? actingBillList : null); } //this.ucNewList.BindDataSource(actingBillList != null && actingBillList.Count > 0 ? actingBillList : null); this.ucNewList.Visible = true; }
protected void btnUpload_Click(object sender, EventArgs e) { try { HSSFWorkbook excel = new HSSFWorkbook(fileUpload.PostedFile.InputStream); Sheet sheet = excel.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); Row custrow = sheet.GetRow(2); string cust = custrow.GetCell(1).StringCellValue;//客户代码 Customer customer = TheCustomerMgr.LoadCustomer(cust); Row row_startdate = sheet.GetRow(3); string startdate = row_startdate.GetCell(1).StringCellValue; //开始日期 Row row_enddate = sheet.GetRow(4); string enddate = row_enddate.GetCell(1).StringCellValue; //结束日期 startdate = startdate == string.Empty ? DateTime.Now.AddMonths(-1).ToShortDateString() : startdate; enddate = enddate == string.Empty ? DateTime.Now.ToShortDateString() : enddate; IList <ActingBill> actingBillList = TheActingBillMgr.GetActingBill(cust, "", DateTime.Parse(startdate), DateTime.Parse(enddate), "", "", this.ModuleType, this.billNo); var actbill = (from i in actingBillList//按ASN ITME聚合 得到总的可用数量 group i by new { i.IpNo, i.Item.Code } into k select new { Item = k.Key.Code, IpNo = k.Key.IpNo, Amt = k.Sum(i => i.BillQty - i.BilledQty) }).ToList(); ImportHelper.JumpRows(rows, 7); IList <ActingBill> createBillList = new List <ActingBill>(); IList <Bill> createdBill = new List <Bill>(); while (rows.MoveNext()) { Row curow = (HSSFRow)rows.Current; string asn = curow.GetCell(0).StringCellValue; string item = curow.GetCell(1).NumericCellValue.ToString(); decimal qty = decimal.Parse(curow.GetCell(2).NumericCellValue.ToString()); if (asn != string.Empty) { var temp_qty = actbill.Where(i => i.Item == item && i.IpNo == asn).ToList(); if (temp_qty.Count > 0) { if (Math.Abs(temp_qty[0].Amt) - Math.Abs(qty) >= 0) { IList <ActingBill> result = actingBillList.Where(i => i.Item.Code == item && i.IpNo == asn).ToList(); foreach (ActingBill _actbill in result) { if (qty == 0) { break; //扣减完了 } if (_actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty == 0) { continue; //actbill可用数量用完了 } //if (_actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty - qty >= 0) //{ // _actbill.CurrentBillQty = _actbill.CurrentBillQty + qty; // qty = 0; //} //else //{ // _actbill.CurrentBillQty = _actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty; // qty = qty - _actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty; //} if (_actbill.BillQty > 0) { if (_actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty - qty >= 0) { _actbill.CurrentBillQty = _actbill.CurrentBillQty + qty; qty = 0; } else { _actbill.CurrentBillQty = _actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty; qty = qty - _actbill.CurrentBillQty; } } else { if (_actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty - qty <= 0) { _actbill.CurrentBillQty = _actbill.CurrentBillQty + qty; qty = 0; } else { _actbill.CurrentBillQty = _actbill.BillQty - _actbill.BilledQty - _actbill.CurrentBillQty; qty = qty - _actbill.CurrentBillQty; } } createBillList.Add(_actbill); } } else { ShowErrorMessage("行" + (curow.RowNum + 1).ToString() + "数量大于剩余开票数量!"); return; } } else { ShowErrorMessage("行" + (curow.RowNum + 1).ToString() + " ASN或零件不存在!请查询对应记录后再导入!"); return; } } } int cnt = 0; try { while (0 < createBillList.Count) { cnt++; var t = from i in createBillList group i by new { i.Item.Code } into k select new { Item = k.Key.Code, Amt = k.Sum(i => i.CurrentBillQty * i.UnitPrice) }; List <string> abM = new List <string>(); List <string> zeroM = new List <string>(); foreach (var i in t) { if (i.Amt > 1000000) { abM.Add(i.Item); } if (i.Amt == 0 && cnt == 1) { zeroM.Add(i.Item); } } #region 超过100w的 foreach (string s in abM) { IList <ActingBill> tempList = createBillList.Where(i => i.Item.Code == s).OrderByDescending(i => i.UnitPrice * i.CurrentBillQty).ToList(); IList <ActingBill> amtList = new List <ActingBill>(); decimal amount = 0; foreach (ActingBill act in tempList) { if (amount + act.CurrentBillQty * act.UnitPrice <= 1000000) { amtList.Add(act); amount += act.CurrentBillQty * act.UnitPrice; } else if (act.CurrentBillQty * act.UnitPrice > 1000000) { decimal qty = Math.Round(1000000 / act.UnitPrice, 0); act.CurrentBillQty = qty; amtList.Add(act); } else { continue; } } if (amtList.Count > 0) { IList <Bill> billList = TheBillMgr.CreateBill(amtList, this.CurrentUser); createdBill.Add(billList[0]); } foreach (ActingBill act in amtList) { if (Math.Round(1000000 / act.UnitPrice, 0) > act.CurrentBillQty) { createBillList.Remove(act); } else { act.CurrentBillQty = act.BillQty - act.BilledQty - Math.Round(1000000 / act.UnitPrice, 0) * cnt; } } } #endregion #region 未超过100w的 List <string> normal = new List <string>(); var bAm = (from i in createBillList group i by new { i.Item.Code } into k select new { Item = k.Key.Code, Amt = k.Sum(i => i.CurrentBillQty * i.UnitPrice) }).Where(i => i.Amt < 1000000 && i.Amt != 0).OrderByDescending(i => i.Amt).ToList(); while (bAm.Count > 0) { decimal tempAmt = 0; IList <string> tempGroup = new List <string>(); foreach (var i in bAm) { if (i.Amt + tempAmt <= 1000000) { tempGroup.Add(i.Item); tempAmt += i.Amt; } else { continue; } } List <ActingBill> tempAct = new List <ActingBill>(); foreach (string item in tempGroup) { List <ActingBill> _tempAct = (createBillList.Where(i => i.Item.Code == item)).ToList(); foreach (ActingBill bill in _tempAct) { tempAct.Add(bill); } } for (int i = bAm.Count; i > 0; i--) { if (tempGroup.Contains(bAm[i - 1].Item)) { bAm.Remove(bAm[i - 1]); i = bAm.Count + 1; } } if (tempAct.Count > 0) { IList <Bill> billList = TheBillMgr.CreateBill(tempAct, this.CurrentUser); createdBill.Add(billList[0]); } foreach (ActingBill bill in tempAct) { createBillList.Remove(bill); } } #endregion if (zeroM.Count > 0 && cnt == 1) { foreach (string code in zeroM) { IList <ActingBill> tempList = createBillList.Where(i => i.Item.Code == code).OrderByDescending(i => i.UnitPrice * i.CurrentBillQty).ToList(); if (tempList.Count > 0) { if (createdBill.Count > 0) { TheBillMgr.AddBillDetail(createdBill[0], tempList, this.CurrentUser); } else { IList <Bill> billList = TheBillMgr.CreateBill(tempList, this.CurrentUser); createdBill.Add(billList[0]); } } foreach (ActingBill actb in tempList) { createBillList.Remove(actb); } } } } } catch (BusinessErrorException ex) { ShowErrorMessage(ex); } catch (Exception ex) { ShowErrorMessage(ex.Message); } _createdBillNo += " 已创建以下账单:<br/>"; foreach (Bill b in createdBill) { _createdBillNo += b.BillNo + "<br />"; } #region output result xls if (createdBill != null && createdBill.Count > 0) { this.btnBack_Click(sender, e); ExportResult(createdBill); } #endregion } catch (Exception exception) { ShowErrorMessage(exception.Message); } }
protected void btnConfirm_Click(object sender, EventArgs e) { string partyCode = this.tbPartyCode.Text != string.Empty ? this.tbPartyCode.Text.Trim() : string.Empty; string receiver = this.tbReceiver.Text != string.Empty ? this.tbReceiver.Text.Trim() : string.Empty; string startDate = this.tbStartDate.Text != string.Empty ? this.tbStartDate.Text.Trim() : string.Empty; string endDate = this.tbEndDate.Text != string.Empty ? this.tbEndDate.Text.Trim() : string.Empty; string itemCode = this.tbItemCode.Text != string.Empty ? this.tbItemCode.Text.Trim() : string.Empty; string currency = this.tbCurrency.Text != string.Empty ? this.tbCurrency.Text.Trim() : string.Empty; DateTime?effDateFrom = null; if (startDate != string.Empty) { effDateFrom = DateTime.Parse(startDate); } DateTime?effDateTo = null; if (endDate != string.Empty) { effDateTo = DateTime.Parse(endDate).AddDays(1).AddMilliseconds(-1); } //重新计价 bool needRecalculate = bool.Parse(TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_RECALCULATE_WHEN_BILL).Value); if (needRecalculate) { IList <ActingBill> allactingBillList = TheActingBillMgr.GetActingBill(partyCode, receiver, effDateFrom, effDateTo, itemCode, currency, this.ModuleType, null, true); TheActingBillMgr.RecalculatePrice(allactingBillList, this.CurrentUser); } IList <ActingBill> actingBillList = TheActingBillMgr.GetActingBill(partyCode, receiver, effDateFrom, effDateTo, itemCode, currency, this.ModuleType, null); if (actingBillList != null && actingBillList.Count > 0) { foreach (ActingBill actingBill in actingBillList) { actingBill.CurrentBillQty = actingBill.BillQty - actingBill.BilledQty; decimal orgAmount = actingBill.UnitPrice * actingBill.CurrentBillQty; actingBill.CurrentDiscount = orgAmount - (actingBill.BillAmount - actingBill.BilledAmount); } IList <Bill> billList = this.TheBillMgr.CreateBill(actingBillList, this.CurrentUser, (this.IsRelease.Checked ? BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT : BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)); ; DetachedCriteria selectCriteria = DetachedCriteria.For(typeof(Bill)); DetachedCriteria selectCountCriteria = DetachedCriteria.For(typeof(Bill)) .SetProjection(Projections.Count("BillNo")); selectCriteria.Add(Expression.Eq("CreateDate", billList[0].CreateDate)); selectCriteria.Add(Expression.Eq("CreateUser.Code", this.CurrentUser.Code)); selectCountCriteria.Add(Expression.Eq("CreateDate", billList[0].CreateDate)); selectCountCriteria.Add(Expression.Eq("CreateUser.Code", this.CurrentUser.Code)); SearchEvent((new object[] { selectCriteria, selectCountCriteria }), null); this.ShowSuccessMessage("MasterData.Bill.BatchCreateSuccessfully"); } else { this.ShowErrorMessage("Bill.Error.EmptyBillDetail"); } }