public object NewTransaction(Transact tr) { try { Transaction_Detail td = new Transaction_Detail(); CustomerDetail cr = new CustomerDetail(); if (td.TransactionId == 0) { td.Time = tr.Time; td.Remarks = tr.Remarks; td.Mode = tr.Mode; td.Amount = tr.Amount; td.CustomerId = tr.CustomerId; var bal = DB1.CustomerDetails.Where(x => x.CustomerId == tr.CustomerId).ToList().FirstOrDefault(); if (bal.OpeningBal >= td.Amount && td.Mode == "Debit") { DB.Transaction_Detail.Add(td); DB.SaveChanges(); return new Response { Status = "Success", Message = "Transaction Successfull" }; } else if (td.Mode == "Credit") { DB.Transaction_Detail.Add(td); DB.SaveChanges(); return new Response { Status = "Success", Message = "Transaction Successfull" }; } else { return new Response { Status = "Error", Message = "Invalid Data." }; } } } catch (Exception) { throw; } return new Response { Status = "Error", Message = "Invalid Data." }; }
public void Addtransaction(int idtype, string name, int IDoriginal, DateTime date, double cost, double price, double profit, string note) { Transaction_Detail det = new Transaction_Detail(); det.IsDisable = false; det.Original_ID = IDoriginal; det.Rectime = DateTime.Now; det.Transaction_Details_Cost = cost; det.Transaction_Details_Date = date; det.Transaction_Details_Name = name; det.Transaction_Details_Notes = note; det.Transaction_Details_Price = price; det.Transaction_Details_Profit = profit; det.Transaction_Details_Rectime = DateTime.Now; det.Transaction_Details_UserId = 0; det.Transaction_Type_Id = idtype; det.UserID = Convert.ToInt32(0); DB.Transaction_Details.InsertOnSubmit(det); DB.SubmitChanges(); if (idtype == 2) { addtotaltranscation(date.Month, date.Year, price, 0, 0, 0, 0); } else if (idtype == 4) { addtotaltranscation(date.Month, date.Year, 0, cost, 0, 0, 0); } else if (idtype == 5) { addtotaltranscation(date.Month, date.Year, 0, 0, price, 0, 0); } else if (idtype == 6) { addtotaltranscation(date.Month, date.Year, 0, 0, 0, cost, 0); } else if (idtype == 7) { addtotaltranscation(date.Month, date.Year, 0, 0, 0, 0, cost); } }
public bool ApproveVoucherRecord(int voucherNo, string approverID, string remark) { bool result = false; // Update Adjustment_Voucher_Record Adjustment_Voucher_Record voucherRecord = FindVoucherRecordByVoucherNo(voucherNo); voucherRecord.authorisingStaffID = approverID; voucherRecord.status = AdjustmentVoucherStatus.APPROVED; voucherRecord.approvalDate = DateTime.Today; using (TransactionScope ts = new TransactionScope()) { try { adjustmentVoucherDAO.UpdateAdjustmentVoucherInfo(voucherRecord); // Update Stationery Quantity foreach (Voucher_Detail detail in voucherRecord.Voucher_Details) { // throw Exception if stationery quantity become zero stationeryService.UpdateStationeryQuantity(detail.itemCode, detail.adjustedQty); } // Insert Record into Transaction table Transaction_Record transRecord = new Transaction_Record(); transRecord.clerkID = voucherRecord.handlingStaffID; transRecord.date = voucherRecord.approvalDate; transRecord.type = TransactionTypes.STOCK_ADJUSTMENT; transRecord.Transaction_Details = new List <Transaction_Detail>(); foreach (Voucher_Detail voucherDetail in voucherRecord.Voucher_Details) { Transaction_Detail transDetail = new Transaction_Detail(); transDetail.itemCode = voucherDetail.itemCode; transDetail.adjustedQty = voucherDetail.adjustedQty; transDetail.balanceQty = stationeryService.FindStationeryByItemCode(voucherDetail.itemCode).stockQty; // stock after adjustment transDetail.remarks = String.Format("Voucher no.: {0} ({1})", voucherRecord.voucherID, voucherRecord.remarks); transRecord.Transaction_Details.Add(transDetail); } // throw Exception if error occur when writing to database transactionService.AddNewTransactionRecord(transRecord); ts.Complete(); result = true; } catch (Exception e) { throw new Exception(e.Message); } } if (result) { // send email notification EmailNotification.EmailNotificatioForAdjustmentVoucherApprovalStatus(voucherNo, AdjustmentVoucherStatus.APPROVED, remark); } return(result); }
public void UpdateDisbursement(string itemCode, int actualQty, string deptCode, int needQty, int count, string staffID) { int actualTmp = actualQty; using (StationeryModel model = new StationeryModel()) { Stationery s = model.Stationeries.Where(x => x.itemCode == itemCode).First(); s.stockQty = s.stockQty - actualQty; model.SaveChanges(); } List <Requisition_Record> list = new List <Requisition_Record>(); list = GetRecordByItemCode(itemCode).Where(x => x.Department.departmentCode == deptCode && (x.status == RequisitionStatus.APPROVED_PROCESSING || x.status == RequisitionStatus.PARTIALLY_FULFILLED)).ToList(); list.Sort(); for (int i = 0; i < list.Count(); i++) { var b = list[i].Requisition_Detail.Where(x => x.itemCode == itemCode).First(); if (b.allocatedQty > 0) { if (actualQty - b.allocatedQty >= 0) { actualQty = actualQty - (int)b.allocatedQty; UpdateDetails(itemCode, list[i].requisitionNo, 0, b.allocatedQty + b.fulfilledQty); } else { UpdateDetails(itemCode, list[i].requisitionNo, 0, actualQty + b.fulfilledQty); actualQty = 0; } } } for (int i = 0; i < list.Count(); i++) { int status = 1;//Collected int sum = 0; StationeryModel entity = new StationeryModel(); var NO = list[i].requisitionNo; var detailslist = entity.Requisition_Detail.Where(x => x.requisitionNo == NO).ToList(); foreach (var l in detailslist) { sum = sum + (int)l.fulfilledQty; if (l.fulfilledQty == l.qty) { } else { status = 2;//partially fulfilled } } if (status == 2) { if (sum == 0) { status = 3; } } updatestatus(list[i].requisitionNo, status); } if (count == 0) { if (needQty - actualTmp > 0) { using (StationeryModel model = new StationeryModel()) { Adjustment_Voucher_Record adjustment = new Adjustment_Voucher_Record(); adjustment.issueDate = DateTime.Now; adjustment.status = AdjustmentVoucherStatus.PENDING; adjustment.remarks = "NA"; adjustment.handlingStaffID = staffID; model.Adjustment_Voucher_Records.Add(adjustment); model.SaveChanges(); } } using (StationeryModel model = new StationeryModel()) { Transaction_Record tr = new Transaction_Record(); tr.clerkID = staffID; tr.date = DateTime.Now; tr.type = TransactionTypes.DISBURSEMENT; model.Transaction_Records.Add(tr); model.SaveChanges(); } } using (StationeryModel model = new StationeryModel()) { int max = 0; if (needQty - actualTmp > 0) { max = 0; foreach (var item in model.Adjustment_Voucher_Records.ToList()) { if (item.voucherID > max) { max = item.voucherID; } } Voucher_Detail voucher = new Voucher_Detail(); voucher.voucherID = max; voucher.itemCode = itemCode; voucher.adjustedQty = actualTmp - needQty; voucher.remarks = ""; model.Voucher_Details.Add(voucher); model.SaveChanges(); } max = 0; foreach (var item in model.Transaction_Records.ToList()) { if (item.transactionNo > max) { max = item.transactionNo; } } Transaction_Detail detail = new Transaction_Detail(); detail.transactionNo = max; detail.itemCode = itemCode; detail.adjustedQty = -actualTmp; detail.balanceQty = model.Stationeries.Where(x => x.itemCode == itemCode).First().stockQty; detail.remarks = ""; model.Transaction_Details.Add(detail); model.SaveChanges(); } }
public ActionResult UpdateReceived(string DONumber, string ReceivedDate, string PONumber, string supplier, string sbutton) { string clerkID = HttpContext.User.Identity.Name; Purchase_Order_Record por = pos.FindByOrderID(Int32.Parse(PONumber)); int pdOutstanding = por.Purchase_Detail.Count; //update transaction records table Transaction_Record tr = new Transaction_Record(); int nextTransactionNo = findNextTransactionNo(); tr.transactionNo = nextTransactionNo; tr.clerkID = clerkID; tr.date = DateTime.Now; tr.type = "DO-" + DONumber; trs.AddNewTransactionRecord(tr); List <Purchase_Detail> model = pos.GetPurchaseDetailsByOrderNo(Int32.Parse(PONumber)); List <string> filledItems = new List <string>(); List <string> unfilledItems = new List <string>(); //total number of rows updated int totalItemsUpdated = 0; foreach (Purchase_Detail pd in model) { string ic = pd.itemCode; string received = Request.QueryString.GetValues("num-" + ic).First(); int receivedNum = Int32.Parse(received); //condition check if option for button" all received" if (sbutton == "Submit All") { if (pd.fulfilledQty == null) { pd.fulfilledQty = 0; } receivedNum = pd.qty - pd.fulfilledQty.Value; } if (receivedNum != 0) { string remarks = Request.QueryString.GetValues("rem-" + ic).First(); pd.fulfilledQty += receivedNum; pd.remarks = remarks; //delete? pd.deliveryOrderNo = DONumber; //update stationery table Stationery s = (from x in ctx.Stationeries where x.itemCode == ic select x).First(); s.stockQty += receivedNum; ctx.SaveChanges(); totalItemsUpdated++; //update number of rows updated //update transaction details table Transaction_Detail td = new Transaction_Detail(); td.itemCode = pd.itemCode; td.adjustedQty = receivedNum; td.balanceQty = s.stockQty + receivedNum; td.remarks = remarks; //delete? td.transactionNo = nextTransactionNo; AddNewTransactionDetail(td); //update purchase details table pos.UpdatePurchaseDetailsInfo(pd); pd.deliveryOrderNo = DONumber; //need to update this code once DB is altered //update purchase order record to partially fulfilled por.status = "partially fulfilled"; pos.UpdatePurchaseOrderInfo(por); if (pd.qty == pd.fulfilledQty) { pdOutstanding--; } } } if (totalItemsUpdated == 0) { TempData["Items updated"] = "No records saved"; } //check if all pd in por are fulfilled, and update por table if (pdOutstanding == 0) { por.status = "completed"; pos.UpdatePurchaseOrderInfo(por); } ViewBag.Supplier = supplier; ViewBag.PONumber = PONumber; return(View("StockReceive", model)); }
public JsonResult CreateNewProduct(string name, int category_id, decimal original_price, int quantity, int quota_min, int quota_max, string[] barcode, string[] unit_name, int[] quantitiesPerUnit, decimal[] sell_price, string[] img) { using (IPosEntities ctx = new IPosEntities()) { try { int default_bar_code = GetMaxProductCodeNumber(); string base_product_code = barcode[0].Length > 0 ? barcode[0] : string.Format("P{0}", (++default_bar_code).ToString("D" + _product_code_number_length)); // Khởi tạo sản phẩm Products _new_product = new Products(); _new_product.ID = ctx.Products.Any() ? ctx.Products.Max(b => b.ID) + 1 : 1; _new_product.Name = name; _new_product.Product_Category_ID = category_id; _new_product.Min_Quota = quota_min; _new_product.Max_Quota = quota_max; _new_product.Base_Product_Code = base_product_code; ctx.Products.Add(_new_product); // Khởi tạo unit for (int i = 0; i < barcode.Length; i++) { Product_Unit _new_product_unit = new Product_Unit(); _new_product_unit.Product_Code = i == 0 ? base_product_code : barcode[i].Length > 0 ? barcode[i] : string.Format("P{0}", (++default_bar_code).ToString("D" + _product_code_number_length)); _new_product_unit.Product_ID = _new_product.ID; _new_product_unit.Base_Product_Code = base_product_code; _new_product_unit.Name = unit_name[i]; _new_product_unit.Original_Price = original_price * quantitiesPerUnit[i]; _new_product_unit.QuantityPerUnit = quantitiesPerUnit[i]; _new_product_unit.Sell_Price = sell_price[i]; ctx.Product_Unit.Add(_new_product_unit); } // Khởi tạo image long _last_image_id = ctx.Product_Image.Any() ? ctx.Product_Image.Max(b => b.ID) + 1 : 1; for (int i = 0; i < img.Length; i++) { Product_Image _new_image = new Product_Image(); _new_image.ID = _last_image_id++; _new_image.Number = i + 1; _new_image.Product_ID = _new_product.ID; _new_image.Contents = img[i]; ctx.Product_Image.Add(_new_image); } // Khởi tạo giao dịch "Initiation" Transaction _new_transaction = new Transaction(); _new_transaction.code = Utilities.Utilities.CreateNewTransactionCode(Utilities.Utilities.TransactionType.Initiation()); _new_transaction.Type = Utilities.Utilities.TransactionType.Initiation(); _new_transaction.Created_Time = DateTime.Now; _new_transaction.Created_User = ""; // MANHDC - TODO _new_transaction.Shop_ID = 0; // MANHDC - TODO _new_transaction.Discount = 0; _new_transaction.Note = "Khởi tạo sản phẩm"; ctx.Transaction.Add(_new_transaction); // Khởi tạo chi tiết giao dịch (số lượng, giá tiền) Transaction_Detail _new_transaction_detail = new Transaction_Detail(); _new_transaction_detail.Transaction_Code = _new_transaction.code; _new_transaction_detail.Product_Code = _new_product.Base_Product_Code; _new_transaction_detail.Quantity = quantity; _new_transaction_detail.Price = original_price; _new_transaction_detail.Total = quantity * original_price; ctx.Transaction_Detail.Add(_new_transaction_detail); ctx.SaveChanges(); } catch (Exception ex) { string msg = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; msg = ex.Message; } return(Json("ERR:" + msg, JsonRequestBehavior.AllowGet)); } } return(Json("OK", JsonRequestBehavior.AllowGet)); }