private void createBillToolStripMenuItem_Click(object sender, EventArgs e) { closeChildForms(); CreateBill objPurchasesOrder = new CreateBill(companyEL, null); showControl(objPurchasesOrder); }
public async Task <ApiResult <GetBillById> > Create(CreateBill bundle) { var json = JsonConvert.SerializeObject(bundle); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var url = $"/api/Bill"; var result = await Create <GetBillById>(url, httpContent); return(result); }
public async Task <IActionResult> Create([FromBody] CreateBill bundle) { var resultId = await _billService.Create(bundle); if (!resultId.IsSuccessed) { return(BadRequest()); } var result = await _billService.GetBillById(resultId.ResultObj); return(Ok(result)); }
public async Task <ApiResult <long> > Create(CreateBill bundle) { int i = 0; var billDetail = new List <BillDetail>(); double total = 0; List <OrderDetail> listOrderDetails = new List <OrderDetail>(); List <Material> listMaterial = new List <Material>(); foreach (var item in bundle.IdMaterials) { if (bundle.EnterAmount[i] != 0) { double resultPrice = (bundle.EnterAmount[i] * bundle.Price[i]); double money = 0; if (bundle.Discount[i] != 0) { int percentComplete = (int)Math.Round((double)(resultPrice * bundle.Discount[i]) / 100); money = (resultPrice - percentComplete); total += money; } else { total += resultPrice; money = resultPrice; } billDetail.Add(new BillDetail() { IdMaterials = item, Amount = bundle.EnterAmount[i], Discount = bundle.Discount[i], Price = (decimal)(bundle.Price[i]), TotalPrice = (decimal)money, Unit = bundle.Unit[i] }); // cập nhật số lượng chi tiết đặt hàng var orderDetail = await _context.OrderDetails.FindAsync(bundle.IdOrderDetail[i]); var enterAmountNow = orderDetail.EnterAmount + bundle.EnterAmount[i]; if (enterAmountNow >= bundle.Amount[i]) { orderDetail.Status = true; } orderDetail.EnterAmount = enterAmountNow; listOrderDetails.Add(orderDetail); // cập nhật số lượng bên nguyên vật liệu var materials = await _context.Materials.Include(x => x.Packs) .Where(x => x.Id == item).FirstOrDefaultAsync(); var amountDefault = materials.Packs.Where(x => x.Default == true).First(); var materialsDefault = materials.Amount; if (amountDefault.Name == bundle.Unit[i]) { materials.Amount = materialsDefault + bundle.EnterAmount[i]; } else { var amountPack = materials.Packs.Where(x => x.Name == bundle.Unit[i]).First(); var resultAmount = (long)(bundle.EnterAmount[i]) * amountPack.Value; materials.Amount = materialsDefault + resultAmount; } listMaterial.Add(materials); } i++; } if (bundle.Tax != 0) { int tax = (int)Math.Round((double)(total * bundle.Tax) / 100); total += tax; } // chuyển số thành chữ var convert = ""; if (total != 0) { convert = this.NumberToText(total); } var bill = new Bill() { AmountPaid = Decimal.Parse(bundle.AmountPaid), IdPlan = bundle.IdOrderPlan, IdSupplier = bundle.IdSupliers, PurchaseDate = bundle.PurchaseDate, CodeBill = bundle.CodeBill, Tax = bundle.Tax, CreatedDate = DateTime.Now, TotalMoney = (decimal)total, ConvertNumbers = convert, BillDetails = billDetail, }; var amountPaid = Double.Parse(bundle.AmountPaid); if (amountPaid == 0) { bill.PaymentStatus = PaymentStatus.Unpaid; } if (amountPaid > 0 && amountPaid < total) { bill.PaymentStatus = PaymentStatus.PartialPayment; } if (amountPaid >= total) { bill.PaymentStatus = PaymentStatus.Paid; } // tạo code var user = await _userManager.FindByNameAsync(bundle.NameCreator); bill.IdCreator = user.Id; var stt = 1; var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.StorageCode); Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.Bills.AnyAsync(x => x.StorageCode == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); bill.StorageCode = str; //tạo hóa đơn _context.OrderDetails.UpdateRange(listOrderDetails); _context.Materials.UpdateRange(listMaterial); _context.Bills.Add(bill); await _context.SaveChangesAsync(); // cập nhật trạng thái kế hoạch đặt hàng var check = true; var orderPlan = await _context.OrderPlans.Include(x => x.OrderDetails) .Where(x => x.Id == bundle.IdOrderPlan).FirstOrDefaultAsync(); foreach (var item in orderPlan.OrderDetails) { if (!item.Status) { check = false; break; } } if (check) { orderPlan.Status = StatusOrderPlan.Accomplished; _context.OrderPlans.Update(orderPlan); } await _context.SaveChangesAsync(); return(new ApiSuccessResult <long>(bill.Id)); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == 9) // for print { BillEL objBillEL = new BillEL(); objBillEL.Bill_Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value); BillReportViewer objBillReportViewer = new BillReportViewer(companyEL, objBillEL); objBillReportViewer.ShowDialog(); objBillReportViewer.Dispose(); } if (e.ColumnIndex == 10) //For Delete { if (Common.MessageConfim("Are You Want To Delete This ")) { SQLHelper objSQLHelper = new SQLHelper(); SqlTransaction objSqlTransaction = objSQLHelper.BeginTrans(); BillDL objBillDL = new BillDL(); BillEL objBillEL = new BillEL(); objBillEL.Bill_Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value); BillDetailDL objBillDetailDL = new BillDetailDL(); List <BillDetailEL> lstBillDetail = objBillDetailDL.GetBillDetailByBillId(objBillEL.Bill_Id); BillItemDL objBillItemDL = new BillItemDL(); List <BillItemEL> lstBillItemEL = objBillItemDL.GetBillItemByBillId(objBillEL.Bill_Id); BillItemNarrationDL _BillItemNarrationDL = new BillItemNarrationDL(); List <BillItemNarrationEL> lstBillItemNarration = new List <BillItemNarrationEL>(); try { lstBillItemEL.ForEach(r => lstBillItemNarration.AddRange(_BillItemNarrationDL.GetBillItemNarrationBy_BillItemId(r.Bill_Item_Id))); lstBillItemNarration.ForEach(n => _BillItemNarrationDL.Delete(objSqlTransaction, n)); lstBillDetail.ForEach(r => objBillDetailDL.Delete(objSqlTransaction, r)); lstBillItemEL.ForEach(r => objBillItemDL.Delete(objSqlTransaction, r)); objBillDL.Delete(objSqlTransaction, objBillEL); objSqlTransaction.Commit(); Common.MessageDelete(); GridBind(); } catch (Exception) { objSqlTransaction.Rollback(); } } } if (e.ColumnIndex == 11)//For bill Edit { BillDL _BillDL = new BillDL(); BillEL objBillEL = _BillDL.GetBillById(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value)); CreateBill objCreateBill = new CreateBill(companyEL, objBillEL); objCreateBill.ControlBox = true; objCreateBill.MinimizeBox = false; objCreateBill.ShowDialog(); GridBind(); } } catch { } }
public async Task <IActionResult> Create(CreateBill bundle) { var result = await _billApiClient.Create(bundle); return(Ok(result)); }