bool deletePurchasesDetail(int PurchasesDetailID) { objPurchasesDetail.BeginTransaction(); objPurchasesDetail = objPurchasesDetail.Single(p => p.PurchasesDetailID == PurchasesDetailID); //var payment = objPurchasesDetail.PurchasesMaster.PaymentsForSupplier; //payment.Delete(p => p.SupplierPaymentID == payment.SupplierPaymentID); objPurchasesMaster = objPurchasesDetail.PurchasesMaster; objPurchasesMaster.TotalPurchase -= objPurchasesDetail.TotalPrice; objPurchasesMaster.Rest -= objPurchasesDetail.TotalPrice; objPurchasesMaster.Update(p => p.PurchaseID == objPurchasesMaster.PurchaseID); hfOldRest.Value = objPurchasesMaster.Rest.ToString(); // update balance objSupplier = objSupplier.Single(p => p.SupplierID == objPurchasesDetail.PurchasesMaster.SupplierID); objSupplier.Balance = (objSupplier.Balance) - (objPurchasesDetail.TotalPrice); objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); //update qty SalesManager.UpdateproductQTY(QTYOperation.Decrement, objPurchasesDetail.ProductID, objPurchasesDetail.Quantity); bool status = objPurchasesDetail.Delete(p => p.PurchasesDetailID == PurchasesDetailID); objPurchasesDetail.EndTransaction(); return(status); }
void Dir(PurchasesMaster entity) { txtID.Text = entity.PurchaseID.ToString(); ddlSupplier.SelectedValue = entity.SupplierID.ToString(); ddlSupplier.Enabled = false; ddlEmployee.SelectedValue = (entity.EmployeeID != null) ? entity.EmployeeID.Value.ToString() : "0"; txtNotes.Text = entity.Notes; txtPurchaseDateM.Text = entity.PurchaseDateM.Value.ToString("MM/dd/yyyy", culture); txtPurchaseDateH.Text = entity.PurchaseDateH; cboxIsCash.Checked = entity.ISCash; //oldsupplierid = entity.SupplierID; //oldPaymentType = entity.ISCash; FillgvProducts(entity.PurchaseID); lblTotalPurchasePrice.Text = entity.TotalPurchase.ToString(); txtPayment.Text = entity.Payments.ToString(); hfOldRest.Value = lblRest.Text = entity.Rest.ToString(); lblSupplierBalance.Text = lblNewSupplierBalance.Text = entity.Supplier.Balance.ToString(); }
bool Delete(int PurchaseID) { objPurchasesMaster = objPurchasesMaster.Single(p => p.PurchaseID == PurchaseID); // totalpurchase-payments Double rest = objPurchasesMaster.Rest;//محصله الفاتوره النهائيه الا هى عباره عن اجمالى الفاتوره ناقص مدفوع العميل List <PurchasesDetail> itemslist = objPurchasesMaster.PurchasesDetails.ToList(); var payments = objPurchasesMaster.PaymentsForSupplier; objSupplier = objPurchasesMaster.Supplier; try { objPurchasesMaster.BeginTransaction(); //update supplier balance objSupplier.Balance -= rest; objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); //update products (store) itemslist.ForEach(p => { //update qty SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity); } ); // delete purchaseitems(PurchasesDetails) itemslist.DeleteAll(); //delete masetr(PurchasesMaster) objPurchasesMaster.Delete(p => p.PurchaseID == PurchaseID); //delete payments if (payments != null) { payments.Delete(p => p.SupplierPaymentID == payments.SupplierPaymentID); } objPurchasesMaster.EndTransaction(); } catch (Exception ex) { ExtenssionClass.Rollback(); Page.Show(ex.Message); return(false); } return(true); }
public static string[] GetCompletionList(string prefixText, int count, string contextKey) { PurchasesMaster objPurchasesMaster = new PurchasesMaster(); return(objPurchasesMaster.Get(p => p.PurchaseID.ToString().ToLower().StartsWith(prefixText.ToLower()), p => p.PurchaseID.ToString()).ToArray()); }
bool Update() { objPurchasesMaster = new PurchasesMaster(); objPurchasesMaster = objPurchasesMaster.Single(p => p.PurchaseID == Convert.ToInt32(txtID.Text.Trim())); //objPurchasesMaster.SupplierID = int.Parse(ddlSupplier.SelectedValue); objPurchasesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null; objPurchasesMaster.Notes = txtNotes.Text.Trim(); objPurchasesMaster.PurchaseDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture); objPurchasesMaster.PurchaseDateH = txtPurchaseDateH.Text.Trim(); objPurchasesMaster.ISCash = cboxIsCash.Checked; double oldrest = objPurchasesMaster.Rest; bool oldPaymentType = objPurchasesMaster.ISCash; int? paymentid = objPurchasesMaster.SupplierPaymentID; objPurchasesMaster.TotalPurchase = Convert.ToDouble(lblTotalPurchasePrice.Text); objPurchasesMaster.Rest = Convert.ToDouble(lblRest.Text); double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0"); objPurchasesMaster.Payments = Payments; objPurchasesMaster.BeginTransaction(); PaymentsForSupplier paymentforsupplier = new PaymentsForSupplier(); if (paymentid == null) { if (Payments > 0) { paymentforsupplier.SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); paymentforsupplier.PaymentDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture); paymentforsupplier.PaymentDateH = txtPurchaseDateH.Text.Trim(); paymentforsupplier.Payment = Payments; objPurchasesMaster.SupplierPaymentID = Convert.ToInt32(paymentforsupplier.Insert()); } } else if (paymentid != null) { paymentforsupplier = objPurchasesMaster.PaymentsForSupplier; paymentforsupplier.PaymentDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture); paymentforsupplier.PaymentDateH = txtPurchaseDateH.Text.Trim(); paymentforsupplier.Payment = Payments; paymentforsupplier.Update(p => p.SupplierPaymentID == paymentforsupplier.SupplierPaymentID); } objPurchasesMaster.Update(p => p.PurchaseID == objPurchasesMaster.PurchaseID); //var q=objPurchasesDetail.Filter(p => p.PurchaseID == objPurchasesMaster.PurchaseID).Select(p => (p.TotalPrice )); //double oldTotalPurchasePrice =(q!=null )?q.Sum():0.0; List <PurchasesDetail> Purchaseslist = CurrentgvProducts(gvProducts); Purchaseslist.ForEach(p => { p.Quantity = SalesManager.UnitConvert(p.UnitID, p.PQTY); p.UnitPrice = SalesManager.UnitPriceConvert(p.UnitID, p.PUnitPrice); p.BasicUnitID = SalesManager.getBasicUnitID; }); //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice ); List <PurchasesDetail> newPurchaseslist = Purchaseslist.Where(p => p.PurchasesDetailID == 0).ToList(); List <PurchasesDetail> updatePurchaseslist = Purchaseslist.Where(p => p.PurchasesDetailID > 0).ToList(); if (newPurchaseslist.Count > 0) { newPurchaseslist.ForEach(p => p.PurchaseID = objPurchasesMaster.PurchaseID); newPurchaseslist.InsertAll(); // update qty product in store(table product) newPurchaseslist.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, p.Quantity)); } if (updatePurchaseslist.Count > 0) { updatePurchaseslist.ForEach(p => { p.Update(z => z.PurchasesDetailID == p.PurchasesDetailID); SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, (p.Quantity - p.oldQty)); }); } //========= composite calcualtion balance --- compare between old value and new value if (oldPaymentType != true)// not cash { // any way( - balance) form old supplier if user change supplier objSupplier = objSupplier.Single(p => p.SupplierID == objPurchasesMaster.SupplierID); objSupplier.Balance -= oldrest; // objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); if (cboxIsCash.Checked != true)// if (not cash) add new price to balance { //objSupplier = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue)); objSupplier.Balance += objPurchasesMaster.Rest; } objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); } else if (oldPaymentType == true) // cash { if (cboxIsCash.Checked != true) // if user change to (not cash) will add new price to supplier balance { objSupplier = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue)); objSupplier.Balance += objPurchasesMaster.Rest; objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); } } objPurchasesMaster.EndTransaction(); return(true); }
bool Insert() { objPurchasesMaster = new PurchasesMaster(); objPurchasesMaster.SupplierID = int.Parse(ddlSupplier.SelectedValue); objPurchasesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null; objPurchasesMaster.Notes = txtNotes.Text.Trim(); objPurchasesMaster.PurchaseDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture); objPurchasesMaster.PurchaseDateH = txtPurchaseDateH.Text.Trim(); objPurchasesMaster.TotalPurchase = Convert.ToDouble(lblTotalPurchasePrice.Text); objPurchasesMaster.Rest = Convert.ToDouble(lblRest.Text); double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0"); objPurchasesMaster.Payments = Payments; objPurchasesMaster.ISCash = cboxIsCash.Checked; List <PurchasesDetail> Purchaseslist = new List <PurchasesDetail>(); Purchaseslist = CurrentgvProducts(gvProducts); Purchaseslist.ForEach(p => { p.Quantity = SalesManager.UnitConvert(p.UnitID, p.PQTY); p.UnitPrice = SalesManager.UnitPriceConvert(p.UnitID, p.PUnitPrice); p.BasicUnitID = SalesManager.getBasicUnitID; }); //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice); objPurchasesMaster.PurchasesDetails.AddRange(Purchaseslist); objPurchasesMaster.BeginTransaction(); if (Payments > 0) { PaymentsForSupplier paymentforsupplier = new PaymentsForSupplier(); paymentforsupplier.SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); paymentforsupplier.PaymentDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture); paymentforsupplier.PaymentDateH = txtPurchaseDateH.Text.Trim(); paymentforsupplier.Payment = Payments; objPurchasesMaster.SupplierPaymentID = Convert.ToInt32(paymentforsupplier.Insert()); } objPurchasesMaster.Insert(); // update qty product in store(table product) Purchaseslist.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, p.Quantity)); if (cboxIsCash.Checked != true) { objSupplier = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue)); objSupplier.Balance += objPurchasesMaster.Rest; objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); } objPurchasesMaster.EndTransaction(); return(true); }