public UnitOfWork(AppDbContext databaseConnection) { context = databaseConnection; #region Creating Objects User = new UserRepository(context); Brand = new BrandRepository(context); Category = new CategoryRepository(context); CompanyInformation = new CompanyInformationRepository(context); Customer = new CustomerRepository(context); Invoice = new InvoiceRepository(context); Inventory = new InventoryRepository(context); InvoiceDetails = new InvoiceDetailsRepository(context); Product = new ProductRepository(context); SalesInvoice = new SalesInvoiceRepository(context); SalesInvoiceDetail = new SalesInvoiceDetailRepository(context); PurchaseProduct = new PurchaseProductRepository(context); PurchaseProductDetail = new PurchaseProductDetailRepository(context); Stock = new StockRepository(context); StockDetails = new StockDetailsRepository(context); Supplier = new SupplierRepository(context); Unit = new UnitRepository(context); VatAndTax = new VatAndTaxRepository(context); #endregion }
public UnitOfWorkSqlServerRepository(SqlConnection context, SqlTransaction transaction) { InvoiceRepository = new InvoiceRepository(context, transaction); ProductRepository = new ProducRepository(); ClientRepository = new ClientRepository(); InvoiceDetailsRepository = new InvoiceDetailsRepository(context, transaction); }
private void BindData() { datPaymentDate.SelectedDate = DateTime.Today; if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"])) { string[] key = Request.QueryString["InvoiceIdPK"].Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); double sumDetail = new InvoiceDetailsRepository().GetSumTotalDetailOfInvoice(idFactNumber, type, idYear); double sumPayment = new InvoicePaymentsRepository().GetSumPaymentOfInvoice(idFactNumber, type, idYear); double remain = sumDetail - sumPayment; if (remain > -0.05 && remain < 0) remain = 0; txtAmount.Value = remain; } if (!string.IsNullOrEmpty(Request.QueryString["IdPayment"])) { int idPayment = int.Parse(Request.QueryString["IdPayment"]); InvoicePayments payment = new InvoicePaymentsRepository().GetInvoicePaymentByID(idPayment); datPaymentDate.SelectedDate = payment.DatePayment; txtAmount.Value = payment.Amount; txtRemark.Text = payment.Remark; } }
protected void OnBtnSaveClicked(object sender, EventArgs e) { InvoiceDetailsRepository repo = new InvoiceDetailsRepository(); InvoicesRepository repoInv = new InvoicesRepository(); if (!string.IsNullOrEmpty(Request.QueryString["InvoiceDetailId"])) { string[] key = Request.QueryString["InvoiceDetailId"].Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); int idLigneNumber = int.Parse(key[3]); IList<InvoiceDetails> invDetailList = repo.GetInvoiceDetailsOfInvoice( idFactNumber, type, idYear, idLigneNumber); if (invDetailList.Count == 1) { InvoiceDetails invDetail = invDetailList[0]; invDetail.Description = txtDescription.Text; invDetail.Quantity = txtQuantity.Value; invDetail.UnitPriceEuro = txtUnitPrice.Value; invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) * (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0); invDetail.VatCode = int.Parse(ddlVAT.SelectedValue); repo.UpdateInvoiceDetails(invDetail); repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear); } } else if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"])) { string[] key = Request.QueryString["InvoiceIdPK"].Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); int? idLigneNumber = repo.GetMaxInvoiceDetailOrderNumber(idFactNumber, type, idYear); if (!idLigneNumber.HasValue) idLigneNumber = 1; else idLigneNumber += 1; InvoiceDetails invDetail = new InvoiceDetails(); invDetail.IdFactNumber = idFactNumber; invDetail.IdTypeInvoice = type; invDetail.IdYear = idYear; invDetail.IdLigneNumber = idLigneNumber.Value; invDetail.Description = txtDescription.Text; invDetail.Quantity = txtQuantity.Value; invDetail.UnitPriceEuro = txtUnitPrice.Value; invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) * (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0); invDetail.VatCode = int.Parse(ddlVAT.SelectedValue); repo.InserNewInvoiceDetails(invDetail); repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear); } string script = "<script type=\"text/javascript\">"; script += " OnBtnSaveClientClicked();"; script += " </script>"; if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow")) ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script); }
public static string ExportInvoices(Invoices currentInvoice, string addressFillInInvoice, string exportDirectory) { IPdfManager manager = new PdfManager(); IPdfDocument document = null; IPdfPage page = null; if (WebConfig.UsedPredefinedInvoicePaperToPrintInvoice.Trim() == "true") { document = manager.OpenDocument(WebConfig.AbsolutePathPredefinedInvoicePaper, Missing.Value); page = document.Pages[1]; } else { document = manager.CreateDocument(Missing.Value); page = document.Pages.Add(Missing.Value, Missing.Value, Missing.Value); ////////////////Draw logo and template/////////////////////////////////// IPdfImage verticalLine = document.OpenImage(HttpContext.Current.Request.MapPath("~/images/neos-vertical-line.gif"), Missing.Value); IPdfParam verticalParam = manager.CreateParam(Missing.Value); verticalParam["x"].Value = 5; verticalParam["y"].Value = 0; verticalParam["ScaleX"].Value = 0.4f; //logoParam1["ScaleY"].Value = 0.8f; page.Canvas.DrawImage(verticalLine, verticalParam); IPdfImage logoImage = document.OpenImage(HttpContext.Current.Request.MapPath("~/images/logo_neos_new.gif"), Missing.Value); IPdfParam logoParam = manager.CreateParam(Missing.Value); logoParam["x"].Value = 20; logoParam["y"].Value = page.Height - 140; logoParam["ScaleX"].Value = 0.8f; logoParam["ScaleY"].Value = 0.8f; page.Canvas.DrawImage(logoImage, logoParam); string imageFooterPath = WebConfig.AbsolutePathImageFooterPath; if (!File.Exists(imageFooterPath)) { imageFooterPath = HttpContext.Current.Request.MapPath("~/images/logo-neos-footer.gif"); } IPdfImage footerImage = document.OpenImage(imageFooterPath, Missing.Value); IPdfParam footerParam = manager.CreateParam(Missing.Value); footerParam["x"].Value = 130; footerParam["y"].Value = 10; footerParam["ScaleX"].Value = 0.55f; footerParam["ScaleY"].Value = 0.55f; page.Canvas.DrawImage(footerImage, footerParam); } IPdfParam param = manager.CreateParam(Missing.Value); //Get invoice details and payments. IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( currentInvoice.IdFactNumber, currentInvoice.IdTypeInvoice, currentInvoice.IdYear, null); CompanyAddress comAddress = new CompanyAddressRepository().FindOne( new CompanyAddress(currentInvoice.RefCustomerNumber.Value)); //-----Do not show payment----------------// //IList<InvoicePayments> paymentList = // new InvoicePaymentsRepository().GetInvoicePaymentsOfInvoice( // currentInvoice.IdFactNumber, currentInvoice.IdTypeInvoice, currentInvoice.IdYear); //double paymentTotal = new InvoicePaymentsRepository().GetSumPaymentOfInvoice( // currentInvoice.IdFactNumber, currentInvoice.IdTypeInvoice, currentInvoice.IdYear); //////////////// Draw Invoice title. //////////////////////////////////// //int height = 750; string title = currentInvoice.IdTypeInvoice == "I" ? ResourceManager.GetString("lblInvoiceInvoice") : ResourceManager.GetString("lblInvoiceCreditNote"); title = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 12pt; font-weight: bold; color: black"">{0}</FONT>", title); page.Canvas.DrawText(title, "x=360, y=720, html=true", document.Fonts["Arial", Missing.Value]); ///////////////////////Draw Customers ./////////////////////////////////// string companyName = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 12pt; font-weight: bold; color: black"">{0}</FONT>", (string.IsNullOrEmpty(comAddress.Name) ? "" : comAddress.Name)); page.Canvas.DrawText(companyName, "x=320, y=650, html=true", document.Fonts["Arial", Missing.Value]); string coName = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", (string.IsNullOrEmpty(comAddress.Co) ? "" : comAddress.Co)); page.Canvas.DrawText(coName, "x=320, y=635, html=true", document.Fonts["Arial", Missing.Value]); string companyAddr = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", (string.IsNullOrEmpty(comAddress.Address) ? "" : comAddress.Address)); page.Canvas.DrawText(companyAddr, "x=320, y=620, html=true", document.Fonts["Arial", Missing.Value]); string companyCity = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", (string.IsNullOrEmpty(comAddress.ZipCode) ? "" : comAddress.ZipCode) + " " + (string.IsNullOrEmpty(comAddress.City) ? "" : comAddress.City)); page.Canvas.DrawText(companyCity, "x=320, y=605, html=true", document.Fonts["Arial", Missing.Value]); string vatNumber = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", ResourceManager.GetString("lblInvoiceVATNumber") + " : " + (string.IsNullOrEmpty(comAddress.VatNumber) ? "" : comAddress.VatNumber)); page.Canvas.DrawText(vatNumber, "x=320, y=575, html=true", document.Fonts["Arial", Missing.Value]); string invoiceNumber = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", ResourceManager.GetString("lblInvoiceNumber") + " : " + currentInvoice.IdFactNumber.ToString()); page.Canvas.DrawText(invoiceNumber, "x=70, y=560, html=true", document.Fonts["Arial", Missing.Value]); string invoiceDate = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", ResourceManager.GetString("lblInvoiceDate") + " : " + (currentInvoice.Date.HasValue ? currentInvoice.Date.Value.ToString("dd/MM/yyyy") : string.Empty)); page.Canvas.DrawText(invoiceDate, "x=320, y=560, html=true", document.Fonts["Arial", Missing.Value]); ///////////////////Draw details////////////////////////////////////// int heightDetail = 15; for (int i = 0; i < detailList.Count; i++) { heightDetail += CountLineOfString(detailList[i].Description, 33) * 13; } string rowsDetail = ((int)(detailList.Count + 1)).ToString(); string detailParam = "width=500;height=" + heightDetail + "; Rows=" + rowsDetail + "; Cols=4; cellborder=0.1; cellbordercolor = lightgray ; cellspacing=0; cellpadding=0"; IPdfTable tableDetail = document.CreateTable(detailParam); tableDetail.Font = document.Fonts["Arial", Missing.Value]; param.Set("alignment=left; size=10;"); tableDetail.Rows[1].Cells[1].Width = 330; tableDetail.Rows[1].Cells[2].Width = 50; tableDetail.Rows[1].Cells[3].Width = 50; tableDetail.Rows[1].Cells[4].Width = 70; //tableDetail.Rows[1].Cells[5].Width = 50; //tableDetail.Rows[1].Cells[5].Width = 40; //tableDetail.Rows[1].Cells[6].Width = 50; //tableDetail.Rows[1].Cells[7].Width = 50; //New requirement (20-11-2009) : not show %VAT, VAT amuount and total tableDetail.Rows[1].Cells[1].AddText(ResourceManager.GetString("columnInvoiceDetailDescriptionHeader"), param, Missing.Value); tableDetail.Rows[1].Cells[2].AddText(ResourceManager.GetString("columnInvoiceDetailQuantityHeader"), param, Missing.Value); tableDetail.Rows[1].Cells[3].AddText(ResourceManager.GetString("columnInvoiceDetailUnitPriceHeader"), param, Missing.Value); tableDetail.Rows[1].Cells[4].AddText(ResourceManager.GetString("columnInvoiceDetailAmountHeader"), param, Missing.Value); //tableDetail.Rows[1].Cells[5].AddText(ResourceManager.GetString("columnInvoiceDetailCodeVATHeader"), param, Missing.Value); //tableDetail.Rows[1].Cells[5].AddText(ResourceManager.GetString("columnInvoiceDetailPercentVATHeader"), param, Missing.Value); //tableDetail.Rows[1].Cells[6].AddText(ResourceManager.GetString("columnInvoiceDetailAmountVATHeader"), param, Missing.Value); //tableDetail.Rows[1].Cells[7].AddText(ResourceManager.GetString("columnInvoiceDetailTotalAmountHeader"), param, Missing.Value); IPdfParam paramLeft = manager.CreateParam(Missing.Value); paramLeft.Set("alignment=right; size=10;"); for (int i = 0; i < detailList.Count; i++) { InvoiceDetails detail = detailList[i]; tableDetail.Rows[i + 2].Cells[1].Height = CountLineOfString(detail.Description, 33) * 13; tableDetail.Rows[i + 2].Cells[1].AddText(string.IsNullOrEmpty(detail.Description) ? "" : detail.Description, param, document.Fonts["Arial", Missing.Value]); tableDetail.Rows[i + 2].Cells[2].AddText(Get2DigitStringOfDouble(detail.Quantity), paramLeft, document.Fonts["Arial", Missing.Value]); tableDetail.Rows[i + 2].Cells[3].AddText(Get2DigitStringOfDouble(detail.UnitPriceEuro), paramLeft, document.Fonts["Arial", Missing.Value]); tableDetail.Rows[i + 2].Cells[4].AddText(Get2DigitStringOfDouble(detail.AmountEuro), paramLeft, document.Fonts["Arial", Missing.Value]); //tableDetail.Rows[i + 2].Cells[5].AddText(detail.VatCode.HasValue ? detail.VatCode.Value.ToString() : "", param, document.Fonts["Arial", Missing.Value]); //tableDetail.Rows[i + 2].Cells[5].AddText(detail.VatRate.HasValue ? detail.VatRate.Value.ToString() : "", param, document.Fonts["Arial", Missing.Value]); //tableDetail.Rows[i + 2].Cells[6].AddText(Get2DigitStringOfDouble(detail.AmountVAT), param, document.Fonts["Arial", Missing.Value]); //tableDetail.Rows[i + 2].Cells[7].AddText(Get2DigitStringOfDouble(detail.TotalAmountVAT), param, document.Fonts["Arial", Missing.Value]); } page.Canvas.DrawTable(tableDetail, "x=70, y=530"); //////////////////Draw total of details///////////////////////////////////////////////// //string totalHVTA = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-weight: normal; color: black"">{0}</FONT>", // ResourceManager.GetString("lblInvoiceTotalHTVA") + " : " // + (currentInvoice.TotalHtvaEuro.HasValue ? currentInvoice.TotalHtvaEuro.Value.ToString() : "0")); //page.Canvas.DrawText(invoiceNumber, "x=70, y=575, html=true", document.Fonts["Arial", Missing.Value]); IPdfTable tableTotal = document.CreateTable("width=165;height=50; Rows=3; Cols=2; cellborder=0; cellspacing=0; cellpadding=0"); tableTotal.Font = document.Fonts["Arial", Missing.Value]; param.Set("alignment=left; size=10;"); tableTotal.Rows[1].Cells[1].Width = 85; tableTotal.Rows[1].Cells[2].Width = 80; tableTotal.Rows[1].Cells[1].AddText(ResourceManager.GetString("lblInvoiceTotalHTVA"), param, Missing.Value); tableTotal.Rows[1].Cells[2].AddText(": " + (Get2DigitStringOfDouble(currentInvoice.TotalHtvaEuro)), param, Missing.Value); tableTotal.Rows[2].Cells[1].AddText(ResourceManager.GetString("lblInvoiceTotalVAT"), param, Missing.Value); tableTotal.Rows[2].Cells[2].AddText(": " + (Get2DigitStringOfDouble(currentInvoice.AmountVatEuro)), param, Missing.Value); tableTotal.Rows[3].Cells[1].AddText(ResourceManager.GetString("lblInvoiceTotal"), param, Missing.Value); tableTotal.Rows[3].Cells[2].AddText(": " + (Get2DigitStringOfDouble(currentInvoice.TotalAmountIncludeVatEuro)), param, Missing.Value); int totalY = 530 - heightDetail - 20; if (!string.IsNullOrEmpty(comAddress.FactoringCode)) { page.Canvas.DrawTable(tableTotal, "x=400, y=200"); } else { page.Canvas.DrawTable(tableTotal, "x=400, y=145"); } ///////////////Draw factoring code//////////////////////////////////// if (!string.IsNullOrEmpty(currentInvoice.Remark)) { int remarkHeight = CountLineOfString(currentInvoice.Remark, 33) * 13; string remarkParam = "width=300;height=" + remarkHeight + "; Rows=1; Cols=1; cellborder=0.0; cellbordercolor = lightgray ; cellspacing=0; cellpadding=0"; IPdfTable tableRemark = document.CreateTable(remarkParam); tableRemark.Font = document.Fonts["Arial", Missing.Value]; param.Set("alignment=left; size=10;"); tableRemark.Rows[1].Cells[1].AddText(currentInvoice.Remark, param, Missing.Value); page.Canvas.DrawTable(tableRemark, "x=70, y=220"); } ///////////////Draw factoring code//////////////////////////////////// if (!string.IsNullOrEmpty(comAddress.FactoringCode)) { //string factParam = "width=500;height=40; Rows=2; Cols=1; cellborder=0.0; cellbordercolor = lightgray ; cellspacing=0; cellpadding=0"; //IPdfTable tableFact = document.CreateTable(factParam); //tableFact.Font = document.Fonts["Arial", Missing.Value]; //param.Set("alignment=left; size=10;"); string factoringCode1 = ResourceManager.GetString("MessagePrintFactoringCode1"); string factoringCode2 = ResourceManager.GetString("MessagePrintFactoringCode2"); factoringCode1 = string.Format(factoringCode1, comAddress.FactoringCode, currentInvoice.IdFactNumber, currentInvoice.IdYear.ToString().Substring(2, 2)); //string factoringCode = ResourceManager.GetString("lblFactoringCode") + " : " + comAddress.FactoringCode.HasValue.ToString() // + currentInvoice.IdFactNumber.ToString(); //if (currentInvoice.Date.HasValue) //{ // factoringCode += currentInvoice.Date.Value.Year.ToString().Substring(2); //} //tableFact.Rows[1].Cells[1].Width = 470; //tableFact.Rows[1].Cells[1].AddText(factoringCode1, param, Missing.Value); //tableFact.Rows[2].Cells[1].AddText(factoringCode2, param, Missing.Value); //totalY = totalY - 100; //page.Canvas.DrawTable(tableFact, "x=70, y=140"); factoringCode1 = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-style: Italic; font-weight: Normal; color: black"">{0}</FONT>", factoringCode1); page.Canvas.DrawText(factoringCode1, "x=70, y=120, html=true", document.Fonts["Arial", Missing.Value]); factoringCode2 = string.Format(@"<FONT STYLE=""font-family: Arial; font-size: 10pt; font-style: Italic; font-weight: Normal; color: black"">{0}</FONT>", factoringCode2); page.Canvas.DrawText(factoringCode2, "x=70, y=105, html=true", document.Fonts["Arial", Missing.Value]); } /* ////////////////////////////////Draw payments ///////////////////////////////// totalY = totalY - 25; page.Canvas.DrawText(ResourceManager.GetString("tabInvoicePayment"), "x=70, y=" + totalY.ToString() + ", size=15;", document.Fonts["Helvetica", Missing.Value]); string heightPayment = ((int)(paymentList.Count * 12 + 20)).ToString(); string rowsPayment = ((int)(paymentList.Count + 1)).ToString(); string paymentParam = "width=500;height=" + heightPayment + "; Rows=" + rowsPayment + "; Cols=3; cellborder=0.1; cellbordercolor = lightgray ; cellspacing=0; cellpadding=0"; IPdfTable tablePayment = document.CreateTable(paymentParam); tablePayment.Font = document.Fonts["Helvetica", Missing.Value]; param.Set("alignment=left; size=10;"); tablePayment.Rows[1].Cells[1].Width = 300; tablePayment.Rows[1].Cells[2].Width = 110; tablePayment.Rows[1].Cells[3].Width = 60; tablePayment.Rows[1].Cells[1].AddText(ResourceManager.GetString("columnInvoicePaymentRemarkHeader"), param, Missing.Value); tablePayment.Rows[1].Cells[2].AddText(ResourceManager.GetString("columnInvoicePaymentDateHeader"), param, Missing.Value); tablePayment.Rows[1].Cells[3].AddText(ResourceManager.GetString("columnInvoicePaymentAmountHeader"), param, Missing.Value); for (int i = 0; i < paymentList.Count; i++) { InvoicePayments payment = paymentList[i]; tablePayment.Rows[i + 2].Cells[1].AddText(string.IsNullOrEmpty(payment.Remark) ? "" : payment.Remark, param, document.Fonts["Arial", Missing.Value]); tablePayment.Rows[i + 2].Cells[2].AddText( payment.DatePayment.HasValue ? payment.DatePayment.Value.ToString("dd/MM/yyyy") : "", param, document.Fonts["Courier", Missing.Value]); tablePayment.Rows[i + 2].Cells[3].AddText( payment.Amount.HasValue ? payment.Amount.Value.ToString() : "0", param, document.Fonts["Courier", Missing.Value]); } totalY = totalY - 20; page.Canvas.DrawTable(tablePayment, "x=70, y=" + totalY.ToString()); totalY = totalY - int.Parse(heightPayment) - 5; ////////////////////Draw total of payment/////////////////////////////////////////// page.Canvas.DrawText(ResourceManager.GetString("labelTotalInvoicePaymentAmount"), "x=70, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); page.Canvas.DrawText(paymentTotal.ToString(), "x=480, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); totalY = totalY - 15; double remain = 0; if (currentInvoice.TotalAmountIncludeVatEuro.HasValue) { remain = currentInvoice.TotalAmountIncludeVatEuro.Value - paymentTotal; } else { remain = -paymentTotal; } page.Canvas.DrawText(ResourceManager.GetString("labelTotalInvoiceRemainAmount"), "x=70, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); page.Canvas.DrawText(remain.ToString(), "x=480, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); totalY = totalY - 15; if (currentInvoice.Payement.HasValue && currentInvoice.Payement.Value && currentInvoice.DateOfPayement.HasValue) { page.Canvas.DrawText(ResourceManager.GetString("labelTotalInvoicePaid"), "x=70, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); page.Canvas.DrawText(currentInvoice.DateOfPayement.Value.ToString("dd/MM/yyyy"), "x=370, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); } else { page.Canvas.DrawText(ResourceManager.GetString("labelTotalInvoiceUnpaid"), "x=70, y=" + totalY.ToString() + ", size=10;", document.Fonts["Helvetica", Missing.Value]); } */ /////// Save document, the Save method returns generated file name/////////////// string fileName = exportDirectory + "\\"; //string fileName = string.Empty; if (currentInvoice.IdTypeInvoice == "I") fileName += "Invoice"; else fileName += "Credit Note"; fileName += "-" + currentInvoice.IdFactNumber.ToString() + currentInvoice.IdTypeInvoice + currentInvoice.IdYear; fileName += "-" + DateTime.Today.Year; if (DateTime.Today.Month < 10) { fileName += "0"; } fileName += DateTime.Today.Month; if (DateTime.Today.Day < 10) { fileName += "0"; } fileName += DateTime.Today.Day + ".pdf"; //fileName = "attachment;filename=" + fileName; string strFilename = document.Save(fileName, true); //document.SaveHttp(fileName, Missing.Value); return fileName; }
/// <summary> /// copy information and invoice detail from another invoice /// </summary> /// <param name="InvoiceIdPK"></param> private void CopyInvoiceData(string sourceInvoiceId) { string[] key = sourceInvoiceId.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); //Get invoice Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear); SessionManager.CurrentInvoice = invoice; if (invoice.IdTypeInvoice == "I") radInvoice.Checked = true; else radCreditNote.Checked = true; txtCustomerName.Text = invoice.CompanyName; if (invoice.CompanyId.HasValue) txtIdCustomer.Text = invoice.CompanyId.Value.ToString(); txtInvoiceNumber.Text = ""; datInvoiceDate.SelectedDate = DateTime.Now; txtRemark.Text = invoice.Remark; txtTotalHTVA.Value = invoice.TotalHtvaEuro; txtTotalVAT.Value = invoice.AmountVatEuro; txtTotal.Value = invoice.TotalAmountIncludeVatEuro; gridInvoicePayments.DataSource = new List<InvoicePayments>(); gridInvoicePayments.DataBind(); //Get invoice address if (invoice.RefCustomerNumber.HasValue) { CompanyAddress compAdr = new CompanyAddressRepository().FindOne( new CompanyAddress(invoice.RefCustomerNumber.Value)); hiddenCompanyAddressId.Value = compAdr.AddressID.ToString(); txtAddressName.Text = compAdr.Name; txtAddress.Text = compAdr.Address; txtCity.Text = compAdr.City; txtZipCode.Text = compAdr.ZipCode; txtVatNumber.Text = compAdr.VatNumber; } //Get invoice details IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice(idFactNumber, type, idYear, null); gridInvoiceDetails.DataSource = detailList; lnkAddInvoiceDetail.Visible = false; lnkAddNewPayment.Visible = false; gridInvoiceDetails.Columns.FindByUniqueName("TemplateEditInvoiceDetailColumn").Display = false; gridInvoiceDetails.Columns.FindByUniqueName("TemplateDeleteInvoiceDetailColumn").Display = false; }
private void BindInvoiceData(string InvoiceIdPK) { string[] key = InvoiceIdPK.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); //Get invoice Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear); SessionManager.CurrentInvoice = invoice; if (invoice.IdTypeInvoice == "I") radInvoice.Checked = true; else radCreditNote.Checked = true; txtCustomerName.Text = invoice.CompanyName; if (invoice.CompanyId.HasValue) txtIdCustomer.Text = invoice.CompanyId.Value.ToString(); txtInvoiceNumber.Text = invoice.IdFactNumber.ToString(); chkFactoring.Checked = invoice.Factoring.HasValue ? invoice.Factoring.Value : false; datInvoiceDate.SelectedDate = invoice.Date; txtRemark.Text = invoice.Remark; txtInternalRemark.Text = invoice.Remark_Internal; txtTotalHTVA.Value = invoice.TotalHtvaEuro; txtTotalVAT.Value = invoice.AmountVatEuro; txtTotal.Value = invoice.TotalAmountIncludeVatEuro; ddlCustomer.Items.Add(new RadComboBoxItem(invoice.CompanyName, invoice.CompanyId.ToString())); ddlCustomer.SelectedIndex = 0; //Payment : Choose option 1 : not use these fields any more. //datPaymentDate.SelectedDate = invoice.DateOfPayement; //if (invoice.Payement.HasValue) // chkPayment.Checked = invoice.Payement.Value; //else // chkPayment.Checked = false; InvoicePaymentsRepository paymentRepo = new InvoicePaymentsRepository(); IList<InvoicePayments> paymentList = paymentRepo.GetInvoicePaymentsOfInvoice(idFactNumber, type, idYear); gridInvoicePayments.DataSource = paymentList; double payment = paymentRepo.GetSumPaymentOfInvoice(idFactNumber, type, idYear); txtPayment.Value = payment; if (invoice.TotalAmountIncludeVatEuro.HasValue && paymentList.Count > 0 && invoice.TotalAmountIncludeVatEuro.Value <= payment) { chkPayment.Checked = true; DateTime? paymentDate = new InvoicePaymentsRepository().GetLatestDatePaymentOfInvoice(idFactNumber, type, idYear); if (paymentDate.HasValue) txtPaymentDate.Text = paymentDate.Value.ToString("dd/MM/yyyy"); } //Get invoice address if (invoice.RefCustomerNumber.HasValue) { CompanyAddress compAdr = new CompanyAddressRepository().FindOne( new CompanyAddress(invoice.RefCustomerNumber.Value)); hiddenCompanyAddressId.Value = compAdr.AddressID.ToString(); txtAddressName.Text = compAdr.Name; txtAddress.Text = compAdr.Address; txtCity.Text = compAdr.City; txtZipCode.Text = compAdr.ZipCode; txtVatNumber.Text = compAdr.VatNumber; } //Get invoice details IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( idFactNumber, type, idYear, null); gridInvoiceDetails.DataSource = detailList; //lnkAddInvoiceDetail.Visible = true; //lnkAddNewPayment.Visible = true; lnkAddInvoiceDetail.OnClientClick = "return OnAddNewInvoiceDetailClientClicked('" + SessionManager.CurrentInvoice.InvoiceIdPK + "')"; lnkAddNewPayment.OnClientClick = "return OnAddNewInvoicePaymentClientClicked('" + SessionManager.CurrentInvoice.InvoiceIdPK + "')"; //For future invoice if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "future") { datInvoiceDate.SelectedDate = DateTime.Today; } }
private void BindGridDetailData() { if (SessionManager.CurrentInvoice != null) { Invoices invoice = SessionManager.CurrentInvoice; IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( invoice.IdFactNumber, invoice.IdTypeInvoice, invoice.IdYear, null); gridInvoiceDetails.DataSource = detailList; double totalHTVA = 0; double totalVAT = 0; foreach (InvoiceDetails item in detailList) { if (item.AmountEuro.HasValue) totalHTVA += item.AmountEuro.Value; if (item.AmountVAT.HasValue) totalVAT += item.AmountVAT.Value; } txtTotalHTVA.Value = totalHTVA; txtTotalVAT.Value = totalVAT; txtTotal.Value = ((double)(totalVAT + totalHTVA)); //refresh payment section. InvoicePaymentsRepository repo = new InvoicePaymentsRepository(); double payment = repo.GetSumPaymentOfInvoice(invoice.IdFactNumber, invoice.IdTypeInvoice, invoice.IdYear); txtPayment.Value = payment; if ((totalVAT + totalHTVA) <= payment && payment > 0) { chkPayment.Checked = true; DateTime? paymentDate = repo.GetLatestDatePaymentOfInvoice( invoice.IdFactNumber, invoice.IdTypeInvoice, invoice.IdYear); if (paymentDate.HasValue) txtPaymentDate.Text = paymentDate.Value.ToString("dd/MM/yyyy"); } else { chkPayment.Checked = false; txtPaymentDate.Text = null; } } }
protected void OnButtonInvoiceEditSaveClicked(object sender, EventArgs e) { if (btnEditSave.Text == ResourceManager.GetString("editText")) { //Change mode to Edit mode. //btnEditSave.Text = ResourceManager.GetString("saveText"); //EnableInvoiceControls(true); //lnkAddInvoiceDetail.OnClientClick = "return OnAddNewInvoiceDetailClientClicked('" // + SessionManager.CurrentInvoice.InvoiceIdPK + "')"; //lnkAddNewPayment.OnClientClick = "return OnAddNewInvoicePaymentClientClicked('" // + SessionManager.CurrentInvoice.InvoiceIdPK + "')"; //btnExport.Visible = false; string url = Request.Url.PathAndQuery; if (!string.IsNullOrEmpty(Request.QueryString["mode"])) url = url.Replace(Request.QueryString["mode"], "edit"); else url += "&mode=edit"; Response.Redirect(url, true); } else if (Request.QueryString["type"] == "copy") { string message; SessionManager.CurrentInvoice = null; Invoices saveItem = GetInvoice(out message); if (!string.IsNullOrEmpty(message)) { string script = "<script type=\"text/javascript\">"; script += " alert(\"" + message + "\")"; script += " </script>"; if (!ClientScript.IsClientScriptBlockRegistered("redirectUser")) ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script); return; } InvoicesRepository repo = new InvoicesRepository(); repo.InserNewInvoices(saveItem); //insert invoice details if (!string.IsNullOrEmpty(Request.QueryString["from"])) { string invoideIDPK = Request.QueryString["from"]; string[] key = invoideIDPK.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository(); IList<InvoiceDetails> detailList = detailRepo.GetInvoiceDetailsOfInvoice(idFactNumber, type, idYear, null); foreach (InvoiceDetails detail in detailList) { detail.IdFactNumber = saveItem.IdFactNumber; detail.IdTypeInvoice = saveItem.IdTypeInvoice; detail.IdYear = saveItem.IdYear; detailRepo.InserNewInvoiceDetails(detail); } } Response.Redirect("~/InvoiceProfile.aspx?InvoiceIdPK=" + saveItem.InvoiceIdPK + "&mode=edit", true); } else { string message; //Save data. Invoices saveItem = GetInvoice(out message); if (!string.IsNullOrEmpty(message)) { string script = "<script type=\"text/javascript\">"; script += " alert(\"" + message + "\")"; script += " </script>"; if (!ClientScript.IsClientScriptBlockRegistered("redirectUser")) ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script); return; } InvoicesRepository repo = new InvoicesRepository(); //if (SessionManager.CurrentInvoice != null) if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"])) { repo.UpdateInvoices(saveItem); } else { repo.InserNewInvoices(saveItem); } if (saveItem.IdFactNumberNew.HasValue) SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumberNew.Value, saveItem.IdTypeInvoice, saveItem.IdYear); else SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumber, saveItem.IdTypeInvoice, saveItem.IdYear); if (SessionManager.CurrentInvoice.CompanyId.HasValue) { txtIdCustomer.Text = SessionManager.CurrentInvoice.CompanyId.ToString(); txtCustomerName.Text = SessionManager.CurrentInvoice.CompanyName.Trim(); } txtInvoiceNumber.Text = SessionManager.CurrentInvoice.IdFactNumber.ToString(); // //Change mode to View mode string addBackUrl = string.Empty; if (!string.IsNullOrEmpty(Request.QueryString["backurl"]) && Request.QueryString["backurl"] == "visible") { addBackUrl = "&backurl=visible"; } Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=view" + addBackUrl, SessionManager.CurrentInvoice.InvoiceIdPK), true); } }
protected void OnInvoiceDetailDeleteClicked(object sender, EventArgs e) { LinkButton lnkItem = (LinkButton)sender; string invoiceID = lnkItem.CommandArgument; if (!string.IsNullOrEmpty(invoiceID)) { string[] key = invoiceID.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); int idLigneNumber = int.Parse(key[3]); InvoiceDetailsRepository repo = new InvoiceDetailsRepository(); repo.DeleteInvoiceDetails(idFactNumber, type, idYear, idLigneNumber); new InvoicesRepository().ReComputeAmountOfInvoice(idFactNumber, type, idYear); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, txtTotalHTVA); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, txtTotalVAT); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, txtTotal); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, txtPaymentDate); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, txtPayment); invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(gridInvoiceDetails, chkPayment); BindGridDetailData(); gridInvoiceDetails.DataBind(); } }
protected void OnGridInvoiceDetails_RowDrop(object sender, GridDragDropEventArgs e) { if (string.IsNullOrEmpty(e.HtmlElement)) { if (e.DraggedItems.Count >0 && e.DestDataItem != null) //[0].OwnerGridID == gridInvoiceDetails.ID && e.DestDataItem != null && e.DestDataItem.OwnerGridID == gridInvoiceDetails.ClientID) { if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"])) { string[] args = Request.QueryString["InvoiceIdPK"].Split('-'); if(args.Length == 3) { List<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( Convert.ToInt32(args[0]), args[1], Convert.ToInt32(args[2]), null) as List<InvoiceDetails>; if (detailList.Count > 0) { InvoiceDetails invoiceDetail = GetInvoiceDetailFromList(detailList, (string)e.DestDataItem.GetDataKeyValue("InvoiceDetailsId")); int destinationIndex = detailList.IndexOf(invoiceDetail); List<InvoiceDetails> listToMove = new List<InvoiceDetails>(); foreach (GridDataItem dragItem in e.DraggedItems) { InvoiceDetails detail = GetInvoiceDetailFromList(detailList, (string)dragItem.GetDataKeyValue("InvoiceDetailsId")); detailList.Remove(detail); detailList.Insert(destinationIndex, detail); } //save the idLignNumber into database for (int i = 0; i < detailList.Count; i++) { InvoiceDetails saveItem = detailList[i]; saveItem.IdLigneNumber = i + 1; new InvoiceDetailsRepository().UpdateInvoiceDetails(saveItem); } } gridInvoiceDetails.Rebind(); } } } } /* if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdPendingOrders.ClientID) { //reorder items in pending grid IList<Order> pendingOrders = PendingOrders; Order order = GetOrder(pendingOrders, (int)e.DestDataItem.GetDataKeyValue("OrderId")); int destinationIndex = pendingOrders.IndexOf(order); List<Order> ordersToMove = new List<Order>(); foreach (GridDataItem draggedItem in e.DraggedItems) { Order tmpOrder = GetOrder(pendingOrders, (int)draggedItem.GetDataKeyValue("OrderId")); if (tmpOrder != null) ordersToMove.Add(tmpOrder); } foreach (Order orderToMove in ordersToMove) { pendingOrders.Remove(orderToMove); pendingOrders.Insert(destinationIndex, orderToMove); } PendingOrders = pendingOrders; grdPendingOrders.Rebind(); e.DestDataItem.Selected = true; } */ }
private void BuildInvoiceExcelExportFile(string fileName) { IList<Invoices> invoiceList = GetSearchInvoiceList(); Excel.ApplicationClass excelApp = new Excel.ApplicationClass(); excelApp.Application.Workbooks.Add(Type.Missing); Excel.Worksheet activeSheet = (Excel.Worksheet)excelApp.ActiveSheet; activeSheet.Name = ResourceManager.GetString("lblInvoiceGridHeader"); string currencyFormat = "#,##0.00"; activeSheet.Columns.ColumnWidth = 20; //Build invoice list. //Build header. activeSheet.get_Range(activeSheet.Cells[1, 1], activeSheet.Cells[1, 10]).Font.Bold = true; activeSheet.get_Range(activeSheet.Cells[1, 9], activeSheet.Cells[65535, 9]).ColumnWidth = 50; activeSheet.get_Range(activeSheet.Cells[1, 10], activeSheet.Cells[65535, 10]).ColumnWidth = 50; activeSheet.get_Range(activeSheet.Cells[2, 6], activeSheet.Cells[65535, 6]).EntireColumn.NumberFormat = currencyFormat; activeSheet.get_Range(activeSheet.Cells[2, 7], activeSheet.Cells[65535, 7]).EntireColumn.NumberFormat = currencyFormat; activeSheet.get_Range(activeSheet.Cells[2, 8], activeSheet.Cells[65535, 8]).EntireColumn.NumberFormat = currencyFormat; activeSheet.Cells[1, 1] = ResourceManager.GetString("columnCompanyNameHeader"); activeSheet.Cells[1, 2] = ResourceManager.GetString("columnCompanyRefHeader"); activeSheet.Cells[1, 3] = ResourceManager.GetString("columnInvoiveCreditNumberHeader"); activeSheet.Cells[1, 4] = ResourceManager.GetString("columnInvoiceTypeHeader"); activeSheet.Cells[1, 5] = ResourceManager.GetString("columnInvoiceDateHeader"); activeSheet.Cells[1, 6] = ResourceManager.GetString("columnAmountVATExcludeHeader"); activeSheet.Cells[1, 7] = ResourceManager.GetString("columnVATAmountHeader"); activeSheet.Cells[1, 8] = ResourceManager.GetString("columnTotalVATHeader"); activeSheet.Cells[1, 9] = ResourceManager.GetString("columnInvoiceRemarkHeader"); activeSheet.Cells[1, 10] = ResourceManager.GetString("columnInvoiceInternalRemarkHeader"); int i = 2; foreach (Invoices invoice in invoiceList) { activeSheet.Cells[i, 1] = invoice.CompanyName; activeSheet.Cells[i, 2] = invoice.CompanyId; activeSheet.Cells[i, 3] = invoice.IdFactNumber; activeSheet.Cells[i, 4] = invoice.IdTypeInvoice; activeSheet.Cells[i, 5] = invoice.Date.HasValue ? invoice.Date.Value.ToString("dd/MM/yyyy") : string.Empty; activeSheet.Cells[i, 6] = invoice.TotalHtvaEuro.HasValue ? invoice.TotalHtvaEuro.Value : 0; activeSheet.Cells[i, 7] = invoice.AmountVatEuro.HasValue ? invoice.AmountVatEuro.Value : 0; activeSheet.Cells[i, 8] = invoice.TotalAmountIncludeVatEuro.HasValue ? invoice.TotalAmountIncludeVatEuro.Value : 0; activeSheet.Cells[i, 9] = invoice.Remark; activeSheet.Cells[i, 10] = invoice.Remark_Internal; i++; } //Build invoice detail list; Excel.Worksheet detailSheet = (Excel.Worksheet)excelApp.Sheets.Add(activeSheet, Type.Missing, Type.Missing, Type.Missing); detailSheet.Name = ResourceManager.GetString("lblInvoiceDetail"); detailSheet.Columns.ColumnWidth = 15; detailSheet.get_Range(detailSheet.Cells[1, 1], detailSheet.Cells[1, 11]).Font.Bold = true; detailSheet.get_Range(detailSheet.Cells[1, 4], detailSheet.Cells[65535, 4]).ColumnWidth = 40; detailSheet.get_Range(detailSheet.Cells[2, 5], detailSheet.Cells[65535, 5]).EntireColumn.NumberFormat = currencyFormat; detailSheet.get_Range(detailSheet.Cells[2, 6], detailSheet.Cells[65535, 6]).EntireColumn.NumberFormat = currencyFormat; detailSheet.get_Range(detailSheet.Cells[2, 7], detailSheet.Cells[65535, 7]).EntireColumn.NumberFormat = currencyFormat; detailSheet.get_Range(detailSheet.Cells[2, 10], detailSheet.Cells[65535, 10]).EntireColumn.NumberFormat = currencyFormat; detailSheet.get_Range(detailSheet.Cells[2, 11], detailSheet.Cells[65535, 11]).EntireColumn.NumberFormat = currencyFormat; detailSheet.Cells[1, 1] = ResourceManager.GetString("columnInvoiveCreditNumberHeader"); detailSheet.Cells[1, 2] = ResourceManager.GetString("lblFiscalYear"); detailSheet.Cells[1, 3] = ResourceManager.GetString("columnInvoiceTypeHeader"); detailSheet.Cells[1, 4] = ResourceManager.GetString("columnInvoiceDetailDescriptionHeader"); detailSheet.Cells[1, 5] = ResourceManager.GetString("columnInvoiceDetailQuantityHeader"); detailSheet.Cells[1, 6] = ResourceManager.GetString("columnInvoiceDetailUnitPriceHeader"); detailSheet.Cells[1, 7] = ResourceManager.GetString("columnInvoiceDetailAmountHeader"); detailSheet.Cells[1, 8] = ResourceManager.GetString("columnInvoiceDetailCodeVATHeader"); detailSheet.Cells[1, 9] = ResourceManager.GetString("columnInvoiceDetailPercentVATHeader"); detailSheet.Cells[1, 10] = ResourceManager.GetString("columnInvoiceDetailAmountVATHeader"); detailSheet.Cells[1, 11] = ResourceManager.GetString("columnInvoiceDetailTotalAmountHeader"); i = 2; foreach (Invoices invoice in invoiceList) { IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( invoice.IdFactNumber, invoice.IdTypeInvoice, invoice.IdYear, null); if (detailList != null && detailList.Count > 0) { foreach (InvoiceDetails detail in detailList) { detailSheet.Cells[i, 1] = detail.IdFactNumber; detailSheet.Cells[i, 2] = detail.IdYear; detailSheet.Cells[i, 3] = detail.IdTypeInvoice; detailSheet.Cells[i, 4] = detail.Description; detailSheet.Cells[i, 5] = detail.Quantity.HasValue ? detail.Quantity.Value : 0; detailSheet.Cells[i, 6] = detail.UnitPriceEuro.HasValue ? detail.UnitPriceEuro.Value : 0; detailSheet.Cells[i, 7] = detail.AmountEuro.HasValue ? detail.AmountEuro.Value : 0; detailSheet.Cells[i, 8] = detail.VatCode.HasValue ? detail.VatCode.Value : 0; detailSheet.Cells[i, 9] = detail.VatRate.HasValue ? detail.VatRate.Value : 0; detailSheet.Cells[i, 10] = detail.AmountVAT.HasValue ? detail.AmountVAT.Value : 0; detailSheet.Cells[i, 11] = detail.TotalAmountVAT.HasValue ? detail.TotalAmountVAT.Value : 0; i++; } i++; } } activeSheet.Select(Type.Missing); excelApp.ActiveWorkbook.SaveCopyAs(fileName); excelApp.ActiveWorkbook.Saved = true; excelApp.Quit(); }
protected void OnMyAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e) { if (e.Argument.IndexOf("RebindInvoiceDetailGrid") != -1) { InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails); //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection); string[] args = e.Argument.Split('/'); if (args.Length == 3) { try { //string userID = args[1]; int rowIndex = Int32.Parse(args[2]); gridInvoice.MasterTableView.ClearSelectedItems(); gridInvoice.MasterTableView.Items[rowIndex - 1].Selected = true; } catch (System.Exception ex) { throw ex; } gridInvoiceDetails.Rebind(); //btnPrintSelection.Enabled = true; } } else if (e.Argument.IndexOf("InvoiceGridMultiSelected") != -1) { //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection); //btnPrintSelection.Enabled = true; bool isSameReceiptionEmail = true; string email = ""; string[] args = e.Argument.Split('/'); if (args.Length == 2) { List<string> invoices = new List<string>(args[1].TrimEnd(';').Split(';')); foreach (string invoiceId in invoices) { if (!string.IsNullOrEmpty(invoiceId)) { string[] key = invoiceId.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear); if (string.IsNullOrEmpty(email)) { email = GetEmailOfCompany(invoice.CompanyId.Value); } else if (email.CompareTo(GetEmailOfCompany(invoice.CompanyId.Value)) != 0) { isSameReceiptionEmail = false; break; } //InvoiceAjaxManager.ResponseScripts.Add(string.Format("alert('{0}: {1}')", invoice.InvoiceIdPK, GetEmailOfCompany(invoice.CompanyId.Value))); } } } if (isSameReceiptionEmail) { InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridSelectedSameReceiptionEmail\")"); } else InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridMultiSelected\")"); } else if (e.Argument.IndexOf("RebindInvoiceGrid") != -1) { InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice); InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails); gridInvoice.Rebind(); gridInvoiceDetails.Rebind(); } else { switch (e.Argument) { case "OpenSelectedInvoice": Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=edit&backurl=visible", GetSelectedInvoiceIdPK()), true); break; case "DeleteSelectedInvoice": InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice); InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails); foreach (GridDataItem selectedItem in gridInvoice.SelectedItems) { TableCell invoiceIDCell = selectedItem["InvoiceIdPK"]; string invoiceID = selectedItem["InvoiceIdPK"].Text; if (!string.IsNullOrEmpty(invoiceID)) { string[] key = invoiceID.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); //Delete Invoice's payments first. InvoicePaymentsRepository payRepo = new InvoicePaymentsRepository(); payRepo.DeleteInvoicePaymentsOfInvoice(idFactNumber, type, idYear); //Delete invoice's details InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository(); detailRepo.DeleteInvoiceDetails(idFactNumber, type, idYear, null); //Delete Invoice InvoicesRepository invoiceRepo = new InvoicesRepository(); invoiceRepo.DeleteInvoice(idFactNumber, type, idYear); } } BindGridData(null); gridInvoice.DataBind(); break; case "PrintInvoice": List<InvoicingFile> fileList = new List<InvoicingFile>(); GridItemCollection col = gridInvoice.SelectedItems; foreach (GridDataItem item in col) { TableCell cell = item["InvoiceIdPK"]; if (!string.IsNullOrEmpty(cell.Text)) { string[] key = cell.Text.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear); string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory); InvoicingFile file = new InvoicingFile(); file.InvoiceIdPK = invoice.InvoiceIdPK; file.FilePath = fileName; fileList.Add(file); } } InvoicingMView.ActiveViewIndex = 1; ProcessPrintedFiles(fileList); break; case "EmailInvoice": string selectedInvoiceIDs = ""; foreach (GridDataItem selectedItem in gridInvoice.SelectedItems) { TableCell invoiceIDCell = selectedItem["InvoiceIdPK"]; string invoiceID = selectedItem["InvoiceIdPK"].Text; if (!string.IsNullOrEmpty(invoiceID)) { selectedInvoiceIDs += invoiceID + ";"; } } selectedInvoiceIDs = selectedInvoiceIDs.TrimEnd(';'); string url = "SendEmail.aspx?type=invoice&ids=" + selectedInvoiceIDs; InvoiceAjaxManager.ResponseScripts.Add(string.Format("OnSendInvoiceByEmail('{0}')", url)); break; case "CopyInvoice": Response.Redirect(string.Format("~/InvoiceProfile.aspx?type=copy&from={0}&mode=edit", GetSelectedInvoiceIdPK())); break; } } }
protected void OnInvoiceDeleteClicked(object sender, EventArgs e) { LinkButton lnkItem = (LinkButton)sender; string invoiceID = lnkItem.CommandArgument; if (!string.IsNullOrEmpty(invoiceID)) { string[] key = invoiceID.Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); //Delete Invoice's payments first. InvoicePaymentsRepository payRepo = new InvoicePaymentsRepository(); payRepo.DeleteInvoicePaymentsOfInvoice(idFactNumber, type, idYear); //Delete invoice's details InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository(); detailRepo.DeleteInvoiceDetails(idFactNumber, type, idYear, null); //Delete Invoice InvoicesRepository invoiceRepo = new InvoicesRepository(); invoiceRepo.DeleteInvoice(idFactNumber, type, idYear); BindGridData(null); gridInvoice.DataBind(); } }
protected void OnGridInvoiceDetailNeedDataSource(object source, GridNeedDataSourceEventArgs e) { if (gridInvoice.SelectedItems.Count == 1) { GridDataItem dataItem = ((GridDataItem)gridInvoice.SelectedItems[0]); if (dataItem != null) { string invoiceID = dataItem["InvoiceIdPK"].Text; if (!string.IsNullOrEmpty(invoiceID)) { string[] key = invoiceID.Split('-'); IList<InvoiceDetails> detailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( int.Parse(key[0]), key[1], int.Parse(key[2]), null); gridInvoiceDetails.DataSource = detailList; } else { gridInvoiceDetails.DataSource = new List<InvoiceDetails>(); } } } else { gridInvoiceDetails.DataSource = new List<InvoiceDetails>(); } }
private void BindData() { txtDescription.Focus(); ddlVAT.DataValueField = "IdVatCode"; ddlVAT.DataTextField = "TauxVat"; IList<InvoiceVatCodes> vatCodeList = new InvoiceVatCodesRepository().GetAllVatCode(); ddlVAT.DataSource = vatCodeList; ddlVAT.DataBind(); if (!string.IsNullOrEmpty(WebConfig.DefaultVatRate)) { foreach (InvoiceVatCodes item in vatCodeList) { double vatRate = Convert.ToDouble(WebConfig.DefaultVatRate, Common.GetDoubleFormatProvider()); if (item.TauxVat.HasValue && item.TauxVat.Value == vatRate) { ddlVAT.SelectedValue = item.IdVatCode.ToString(); } } } if (!string.IsNullOrEmpty(Request.QueryString["InvoiceDetailId"])) { string[] key = Request.QueryString["InvoiceDetailId"].Split('-'); int idFactNumber = int.Parse(key[0]); string type = key[1]; int idYear = int.Parse(key[2]); int idLigneNumber = int.Parse(key[3]); IList<InvoiceDetails> invDetailList = new InvoiceDetailsRepository().GetInvoiceDetailsOfInvoice( idFactNumber, type, idYear, idLigneNumber); if (invDetailList.Count == 1) { InvoiceDetails invDetail = invDetailList[0]; txtDescription.Text = invDetail.Description; txtQuantity.Value = invDetail.Quantity; txtUnitPrice.Value = invDetail.UnitPriceEuro; txtAmount.Value = invDetail.AmountEuro; if (invDetail.VatCode.HasValue) { ddlVAT.SelectedValue = invDetail.VatCode.Value.ToString(); txtVATCode.Text = invDetail.VatCode.Value.ToString(); } } } else { OnVATSelectedIndexChanged(ddlVAT, null); } }