/// <summary> /// this method show all data of the Sale /// </summary> /// <param name="saleId"></param> private void showSale(int saleId) { var saleManager = new SaleManager(this); var sale = saleManager.GetSale(Company.CompanyId, saleId) ?? new Sale(); lblSaleNumber.Text = saleId.ToString(); btnGenerateFiscalSale.OnClientClick = "location='../Accounting/Receipt.aspx?SaleId=" + Convert.ToString(sale.SaleId) + "'; return false;"; btnGenerateFiscalSale.UseSubmitBehavior = false; if (sale.IsCanceled) { btnCancelSale.Visible = false; btnGenerateFiscalSale.Visible = false; } if (sale.SaleDate != null) lblSaleDate.Text = sale.SaleDate.Value.ToShortDateString(); lblSaleStatus.Text = sale.SaleStatus.Name; if (sale.ReceiptId != null) { lnkReceipt.Text = sale.Receipt.ReceiptNumber.ToString(); lnkReceipt.NavigateUrl = "../Accounting/Receipt.aspx?ReceiptId=" + Convert.ToString(sale.ReceiptId); if (sale.Receipt.IssueDate.HasValue) lblReceiptDate.Text = sale.Receipt.IssueDate.Value.ToShortDateString(); else lblReceiptDate.Text = ""; } }
private void CalculateDropPayout(DateTime startDate, DateTime endDate) { DataTable sales = new DataTable(); DropPayoutManager dManager = new DropPayoutManager(this); SaleManager sManager = new SaleManager(this); Decimal total = (decimal)0; Decimal totalSangria = (decimal)0; Decimal totalSuplemento = (decimal)0; Decimal aVista = (decimal)0; // // This If is making sure that the code below will not execute in the rare case of the user do not // have a deposit registered. // if (Deposit != null) { IQueryable<DropPayout> sangria = dManager.GetSangriaByDate(Company.CompanyId, Deposit.DepositId, ucDateTimeInterval.DateInterval); rptSangria.DataSource = sangria; rptSangria.DataBind(); rptSangriaValores.DataSource = sangria; rptSangriaValores.DataBind(); IQueryable<DropPayout> suplemento = dManager.GetSuplementoByDate(Company.CompanyId, Deposit.DepositId, ucDateTimeInterval.DateInterval); rptSuplemento.DataSource = suplemento; rptSuplemento.DataBind(); rptSuplementoValores.DataSource = suplemento; rptSuplementoValores.DataBind(); sales = sManager.MapOfSale_Payment(Company.CompanyId, ucDateTimeInterval.DateInterval); rptFormasPagamento.DataSource = sales; rptValores.DataSource = sales; rptFormasPagamento.DataBind(); rptValores.DataBind(); for (int i = 0; i < sales.Rows.Count; i++) { total += Convert.ToDecimal(sales.Rows[i]["Value"]); if (sales.Rows[i]["Name"].ToString() == "Dinheiro") aVista = Convert.ToDecimal(sales.Rows[i]["Value"]); } foreach (DropPayout sang in sangria) { totalSangria += sang.Amount; } foreach (DropPayout sup in suplemento) { totalSuplemento += sup.Amount; } } lblCaixa.Text = (aVista + totalSangria + totalSuplemento).ToString("C"); lblTotalPagamento.Text = total.ToString("C"); lstExtract.DataBind(); }
private void HidrateCustomer(int saleId) { // // Show the customer // var saleManager = new SaleManager(this); Sale sale = saleManager.GetSale(Company.CompanyId, saleId); Customer customer = sale.Customer; if (customer != null) { sel_customer.ShowCustomer(customer); } }
protected void btnSearch_Click(object sender, EventArgs e) { Page.Customization["chkShowCanceledSale"] = chkShowCanceledSale.Checked; Page.Customization["cboPageSize"] = cboPageSize.SelectedIndex; Page.Customization["CustomerId"] = Page.ViewState["CustomerId"]; Page.Customization["txtFiscalNumber"] = txtFiscalNumber.Text; if (ucDateTimeInterval.DateInterval != null) { Page.Customization["BeginDate"] = ucDateTimeInterval.DateInterval.BeginDate; Page.Customization["EndDate"] = ucDateTimeInterval.DateInterval.EndDate; } Int32 pageSize = 0; if (cboPageSize.SelectedValue.Equals("All")) pageSize = int.MaxValue; else pageSize = Convert.ToInt32(cboPageSize.SelectedValue); grdSalesList.PageSize = pageSize; ///if not exists a selected number, 'rebind' because the date values if (String.IsNullOrEmpty(txtFiscalNumber.Text) || txtFiscalNumber.Text.Length > 9) { grdSalesList.DataBind(); return; } SaleManager sManager = new SaleManager(this); Sale sale = sManager.GetSaleByFiscalNumber((int)Company.MatrixId, Convert.ToInt32(txtFiscalNumber.Text)); ///if not exists sale related with receipt number return and 'rebind' the grid if (sale == null) { ShowError(Resources.Exception.nonexistentReceiptNumber); grdSalesList.DataBind(); return; } ///retrieve the SaleId and show the sale related with this saleId Response.Redirect("SaleViewer.aspx?SaleId=" + sale.SaleId); }
protected void Page_Load(object sender, EventArgs e) { // Initialize variables prospectComments.HomePath = Company.GetFilesDirectory(); saleManager = new SaleManager(this); customerManager = new CustomerManager(this); if (!IsPostBack) { BudgetItemList = null; if (!String.IsNullOrEmpty(Request["BudgetId"])) BudgetId = Convert.ToInt32(Request["BudgetId"]); cboVendor.DataSource = new HumanResourcesManager(this).GetSalesPerson(Company.CompanyId); cboVendor.DataBind(); if (BudgetId != 0) ShowBudget(BudgetId); } }
private void LoadSale(Int32 saleId) { Sale sale = new SaleManager(this).GetSale( Company.MatrixId.HasValue ? Company.MatrixId.Value : Company.CompanyId, saleId); LstSale.Add(sale.SaleId); ReceiptItem receiptItem; foreach (SaleItem item in sale.SaleItems) { receiptItem = new ReceiptItem { Quantity = Convert.ToInt32(item.Quantity), UnitPrice = item.UnitPrice, Description = item.SpecialProductName }; if (item.ProductId.HasValue) { receiptItem.ProductId = item.ProductId; receiptItem.IPI = item.Product.IPI; receiptItem.ICMS = item.Product.ICMS; receiptItem.Description = item.Product.Name; } AddReceiptItem(item.Product, receiptItem); } SelCustomer.ShowCustomer(sale.Customer); ///set discount of sale as otherValues ///change the sign because the discount is default ucCurrFieldOthersChargesValue.CurrencyValue += sale.Discount; BindReceiptItems(); }
public static bool DeleteBudget(int budgetId, int companyId) { bool result = true; using (SaleManager saleManager = new SaleManager(null)) { try { var serviceOrder = new ServicesManager(null).GetServiceOrder(companyId, budgetId); if (serviceOrder != null) saleManager.DetachBudgetFromServiceOrder(serviceOrder.ServiceOrderId); saleManager.Delete(saleManager.GetBudget(budgetId, companyId)); } catch (System.Data.SqlClient.SqlException e) { result = false; } } return result; }
public Sale SaveSale() { if (!String.IsNullOrEmpty(txtAmount.Text) && !String.IsNullOrEmpty(cboFinancierOperations.SelectedValue) && ucDueDate.DateTime.HasValue) AddParcel(); Sale sale = new SaleManager(this).SaveSale(CreateSale(), CreateSaleItemList(), User.Identity.UserId, CreateParcelList()); if (chkPrint.Checked) HandleLegalTicket(); // // Disposing Session from memory // Page.ViewState["BudgetId"] = null; Page.ViewState["CustomerId"] = null; //Session["basket"] = null; Page.ViewState["discount"] = null; Page.ViewState["FiscalNumber"] = null; PaymentList = null; if (chkReceipt.Checked) { Page.ClientScript.RegisterStartupScript( this.GetType(), "CloseModal", "top.$.modal.Hide();" + "top.content.location.href='../Accounting/Receipt.aspx?SaleId=" + sale.SaleId + "';", true); } else { Page.ClientScript.RegisterStartupScript( this.GetType(), "CloseModal", "top.$.modal.Hide();" + "top.content.location.href+='?';", true); } return sale; }
public Sale SaveSale() { ucDueDate.DateTime = ucDueDate.DateTime ?? DateTime.Now; ucCurrFieldQuantityParcels.Text = String.IsNullOrEmpty(ucCurrFieldQuantityParcels.Text) || ucCurrFieldQuantityParcels.IntValue == 0 ? "1" : ucCurrFieldQuantityParcels.Text; if (ucCurrFieldAmount.CurrencyValue.Value == decimal.Zero) ucCurrFieldAmount.Text = Convert.ToString(Page.ViewState["totalSale"]); if (grdParcels.Rows.Count == 0) AddParcel(); SaleManager manager = new SaleManager(this); Sale sale = manager.SaveSale(CreateSale(), CreateSaleItemList(), User.Identity.UserId, CreateParcelList()); if (chkPrint.Checked) HandleLegalTicket(); // // Disposing Session from memory // Session["BudgetId"] = null; Session["CustomerId"] = null; //Session["basket"] = null; Session["discount"] = null; Session["FiscalNumber"] = null; Session["PaymentDataTable"] = null; string script = String.Format("top.content.location='{0}';top.$.LightBoxObject.close();", chkReceipt.Checked ? "../Accounting/Receipt.aspx?SaleId=" + sale.SaleId : "Sale.aspx"); ClientScript.RegisterStartupScript(this.GetType(), "CloseModal", script, true); return sale; }
protected void odsPaymentMethod_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { var saleManager = new SaleManager(this); Sale sale = saleManager.GetSale(Company.MatrixId.Value, Convert.ToInt32(Page.ViewState["SaleId"])); if (sale.InvoiceId.HasValue) { e.InputParameters["companyId"] = sale.CompanyId; e.InputParameters["saleId"] = sale.SaleId; } else e.Cancel = true; }
protected void lstBudget_SelectedIndexChanged(object sender, EventArgs e) { SaleItemList = null; txtDiscount.Text = String.Empty; Discount = null; SaleManager budgetManager = new SaleManager(this); Budget budget = budgetManager.GetBudget(Convert.ToInt32(lstBudget.SelectedValue), Company.CompanyId); Page.ViewState["budgetId"] = Convert.ToInt32(lstBudget.SelectedValue); Discount.DiscountValue = budgetManager.CalculateBudgetDiscount(budget); Discount.IsCashDiscount = true; if (budget.AdditionalCost.HasValue) Discount.DiscountValue -= budget.AdditionalCost.Value; SaleItem saleItem; foreach (BudgetItem budgetItem in budgetManager.GetBudgetItemByBudget(budget.BudgetId, Company.CompanyId)) { saleItem = new SaleItem(); if (budgetItem.ProductId.HasValue) saleItem.Name = budgetItem.Product.Name; else saleItem.Name = budgetItem.SpecialProductName + " <img src='" + ResolveClientUrl("~/App_Shared/themes/glasscyan/Company/Product_warning.gif") + "' alt='Este produto não se encontra cadastrado!' />"; saleItem.ProductId = budgetItem.ProductId; saleItem.Quantity = budgetItem.Quantity; saleItem.Code = budgetItem.ProductCode; saleItem.Price = budgetItem.UnitPrice; saleItem.UnitCost = budgetItem.UnitCost; SaleItemList.Add(saleItem); } BindGrdSaleItem(); }
protected void btnSendTOCustomer_Click(object sender, EventArgs e) { SaleManager manager = new SaleManager(this); manager.SendBudgetToCustomer(Convert.ToInt32(Page.ViewState["BudgetId"]), Company, 0, String.Empty); }
protected void Page_Load(object sender, EventArgs e) { StoreHtmlContent = true; CompanyManager cManager; CompanyConfiguration cSettings; SaleManager saleManager; if (!IsPostBack) { if (Request.QueryString["BudgetId"] != null) Page.ViewState["BudgetId"] = Request.QueryString["BudgetId"]; if (Page.ViewState["BudgetId"] != null) { saleManager = new SaleManager(this); budget = saleManager.GetBudget(Convert.ToInt32(Page.ViewState["BudgetId"]), Company.CompanyId); double ipi = 0; double sub = 0; subTotal = budget.BudgetItems.Sum(i => i.UnitPrice * i.Quantity); rptProduct.DataSource = budget.BudgetItems; rptProduct.DataBind(); loadDataOfBudget(); loadDataOfCustomer(); } } }
/// <summary> /// this method return all accepted budgets /// </summary> /// <param name="companyId"></param> /// <returns></returns> private IQueryable<Budget> GetAcceptedBudgets(Int32 companyId, Int32? customerId) { var saleManager = new SaleManager(this); IQueryable<Budget> budgetInSale = from sale in DbContext.Sales where sale.CompanyId == companyId select sale.Budget; if (customerId.HasValue) budgetInSale = budgetInSale.Where(budget => budget.CustomerId == customerId); return budgetInSale; }
private void ShowBudget(Int32 budgetId) { // //Load customer's informations // var originalBudget = saleManager.GetBudget(budgetId, Company.CompanyId); LoadBudgetItemsToGrid(); txtBudgetCode.Text = originalBudget.BudgetCode; cboVendor.SelectedValue = originalBudget.VendorId.ToString(); if (originalBudget.Customer != null) sel_customer.ShowCustomer(originalBudget.Customer); txtCustomerName.Text = originalBudget.CustomerName; txtCustomerMail.Text = originalBudget.CustomerMail; txtPhone.Text = originalBudget.CustomerPhone; // //Load product's informations // txtDiscount.Attributes["onkeyup"] = "CalculateDiscount();"; var budget = new SaleManager(this).GetBudget(budgetId, Company.CompanyId); Product product = null; Service service = null; prospectComments.SubjectId = budgetId; foreach (var item in budget.BudgetItems) { product = new Product { ProductId = 0, Name = item.SpecialProductName, ProductCode = item.ProductCode }; if (item.ProductId.HasValue) product.CopyPropertiesFrom(item.Product); else if (item.ServiceId.HasValue) service = new ServicesManager(this).GetService(item.ServiceId.Value); ucCurrFieldUnitPrice.CurrencyValue = item.UnitPrice; ucCurrFieldQuantityData.CurrencyValue = item.Quantity; ClearFields(); } txtObservation.Text = budget.Observation; txtContactName.Text = budget.ContactName; txtDeliveryDate.Text = budget.DeliveryDate; txtWarrant.Text = budget.Warranty; ucCurrFieldExpirationDate.CurrencyValue = budget.ExpirationDate; txtPaymentMethod.Text = budget.PaymentMethod; txtDeliveryDescription.Text = budget.DeliveryDescription; txtObservation.Text = budget.Observation; txtTreatment.Text = budget.Treatment; txtDiscount.Text = Convert.ToString(budget.Discount); ucCurrFieldAdditionalCost.CurrencyValue = budget.AdditionalCost; }
protected void btnAddSale_Click(object sender, ImageClickEventArgs e) { SaleManager sManager = new SaleManager(this); //PaymentMethodManager pManager = new PaymentMethodManager(this); DepositManager dManager = new DepositManager(this); Sale sale = sManager.GetSale((int)Company.MatrixId, Convert.ToInt32("0" + txtSaleNumber.Text.Replace("_",""))); // // Verifica o número da nota, ele precisa existir, e ter o mesmo matrix ID // if (sale == null) { ShowError(Resources.Exception.nonExistentSale); pnlExchange.Visible = false; } //else //{ // // // // Preenche as Grids de Pagamento e Produtos // // // //pnlExchange.Visible = true; // ViewState["SaleId"] = sale.SaleId; // //DataTable payment = pManager.GetPaymentBySale(sale.CompanyId, sale.SaleId); // DataTable productData = sManager.GetSaleProducts(sale.CompanyId, sale.SaleId); // grdSaleItems.DataSource = productData; // grdSaleItems.DataBind(); // //grdPaymentMethod.DataSource = payment; // grdPaymentMethod.DataBind(); // // // // Preenche a Combo com os Produtos disponíveis na nota // // // cboProducts.DataSource = productData; // cboProducts.DataTextField = "Name"; // cboProducts.DataValueField = "ProductId"; // cboProducts.DataBind(); // // // // Preenche as Informações na tela // // // lblSaleDate.Text = sale.SaleDate.ToString(); // lblDiscount.Text = sale.Discount.ToString(); // //lblUserName.Text = payment.Rows[0]["Name2"].ToString(); // // // // Verifica o depósito de origem // // Foi utilizado o try, pois essa coluna não havia no banco, e esse try, // // evita uma tela amarela // // // try // { // lblSourceStore.Text = dManager.GetDeposit((int)sale.DepositId).Name; // } // catch // { // lblSourceStore.Text = "Dado não disponível"; // } // // // // Calcula o total da venda // // // Decimal total = (decimal)0; // //for (int i = 0; i < payment.Rows.Count; i++) // //{ // // total += Convert.ToDecimal(payment.Rows[i]["Amount"]); // // lblSaleTotal.Text = total.ToString(); // //} // // // // Reseta a Grid de Devolução // // // lblDevoltionValue.Visible = false; // txtDevolutionValue.Text = "0,00"; // txtDevolutionValue.Visible = false; // ViewState["Devolution"] = CreateDevolution(); // BindGrid(); //} }
protected void SelCustomer_SelectedCustomer(object sender, SelectedCustomerEventArgs e) { var saleManager = new SaleManager(this); if (e.Customer != null) { Sale sale = saleManager.GetSale(Company.CompanyId, Convert.ToInt32(Page.ViewState["SaleId"])); sale.CustomerId = e.Customer.CustomerId; saleManager.Update(saleManager.GetSale(Company.CompanyId, Convert.ToInt32(Page.ViewState["SaleId"])), sale); } }
protected void lstBudget_SelectedIndexChanged(object sender, EventArgs e) { // //Toda vez que um usuário selecionar um orçamento, eu envio o valor para uma variável JavaScript, //para poder pegar na tela de pagamento dinamicamente, o processo é feito, para no caso de a venda //ser concretizada, o orçamento deverá ser apagado (Executando em sessão, pois não achei o método de //fazer com hidden // //Page.ViewState["bugdetId"] = bugdetId; CreateBasket(); Session["BudgetId"] = Convert.ToInt32(lstBudget.SelectedValue); ProductManager productManager = new ProductManager(this); SaleManager saleManager = new SaleManager(this); Budget budget = saleManager.GetBudget((Int32)Session["BudgetId"], Company.CompanyId); if (budget.Discount.HasValue) { if (budget.DiscountType == (int)DiscountType.Cash) txtDiscount.Text = budget.Discount.Value.ToString("##,##0.00"); else { #warning eliminar variavel temporaria/ criar método, ou executar função novamente Decimal? discount = budget.BudgetItems.Sum(bi => bi.Quantity * bi.UnitPrice) * (budget.Discount.Value / 100); if (discount.HasValue) txtDiscount.Text = discount.Value.ToString("##,##0.00"); } } if (budget.AdditionalCost.HasValue) txtDiscount.Text = (Convert.ToDecimal(txtDiscount.Text) - Convert.ToDecimal(budget.AdditionalCost.Value)).ToString("##,##0.00"); foreach (DataRow row in productManager.GetProductsByBudget((Int32)Session["BudgetId"]).Rows) { string productName; if (!String.IsNullOrEmpty(row["Name"].ToString())) productName = row["Name"].ToString(); else productName = row["SpecialProductName"].ToString(); //string productName = row["Name"].ToString() + row["SpecialProductName"].ToString(); if (String.IsNullOrEmpty(row["ProductId"].ToString())) productName += " <img src='" + ResolveClientUrl("~/App_Shared/themes/glasscyan/Company/Product_warning.gif") + "' alt='Este produto não se encontra cadastrado!' />"; basket.Rows.Add( row["ProductId"], row["Quantity"], productName, /*SerialNumber*/ "", row["ProductCode"], row["unitPrice"], Convert.ToDouble(row["Quantity"]) * Convert.ToDouble(row["unitPrice"]), row["UnitCost"] != DBNull.Value ? Convert.ToDouble(row["UnitCost"]) : 0 ); } BindGrid(); }
protected void btnDeleteBudget_Command(object sender, CommandEventArgs e) { var bManager = new SaleManager(this); bManager.DeleteBudgetAndBudGetItems(Convert.ToInt16(e.CommandArgument), Company.CompanyId); // // Load the budgets // lstBudget.DataSourceID = "odsBudgets"; lstBudget.DataBind(); }
/// <summary> /// Delete the Invoice and the related Parcels from the Database. /// </summary> /// <param name="billId"></param> /// <param name="companyId"></param> public void DeleteInvoice(int invoiceId, int companyId) { // //If exists a sale by this invoice, then set invoiceId with null // var saleManager = new SaleManager(this); Sale original_sale = saleManager.GetSaleByInvoice(companyId, invoiceId); if (original_sale != null) { var sale = new Sale(); sale.CopyPropertiesFrom(original_sale); sale.InvoiceId = null; saleManager.Update(original_sale, sale); } var parcelsManager = new ParcelsManager(this); parcelsManager.DeleteInvoiceParcels(invoiceId); DbContext.Invoices.DeleteOnSubmit( DbContext.Invoices.Where(i => i.CompanyId == companyId && i.InvoiceId == invoiceId).FirstOrDefault()); DbContext.SubmitChanges(); }
protected void btnCancelSale_Click(object sender, EventArgs e) { var saleManager = new SaleManager(this); saleManager.CancelSale(Convert.ToInt32(Page.ViewState["SaleId"]), (int)Company.MatrixId, User.Identity.UserId); Response.Redirect("SaleList.aspx"); }
public static bool DeleteReceipt(int receiptId, int companyId) { bool result = true; var sale = new SaleManager(null).GetSaleByReceipt(companyId, receiptId); if (sale != null) new SaleManager(null).SetNullReceiptIDInSale(sale.SaleId); using (ReceiptManager receiptManager = new ReceiptManager(null)) { try { receiptManager.DeleteReceipt(receiptManager.GetReceipt(receiptId, companyId)); } catch (System.Data.SqlClient.SqlException) { result = false; } } return result; }