protected void OnBtnOkClicked(object sender, EventArgs e)
    {
        if (gridCompanyAddress.SelectedValue != null)
        {
            int addressID = (int)gridCompanyAddress.SelectedValue;
            CompanyAddress address = new CompanyAddressRepository().FindOne(new CompanyAddress(addressID));
            string argument = address.AddressID.ToString();
            if (address.Name != null)
                argument += "/" + address.Name;
            else
                argument += "/ ";

            if (address.Address != null)
                argument += "/" + address.Address;
            else
                argument += "/ ";

            if (address.City != null)
                argument += "/" + address.City;
            else
                argument += "/ ";

            if (address.VatNumber != null)
                argument += "/" + address.VatNumber;
            else
                argument += "/ ";

            string script = "<script type=\"text/javascript\">";
            script += " OnBtnOkClientClicked(\"" + argument + "\");";
            script += " </script>";

            if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (SessionManager.CurrentUser == null)
     {
         Common.RedirectToLoginPage(this);
         return;
     }
     else if (!IsPostBack)
     {
         FillLabelLanguage();
         if (!string.IsNullOrEmpty(Request.QueryString["CompanyId"]))
         {
             int companyID = int.Parse(Request.QueryString["CompanyId"]);
             IList<CompanyAddress> comAdrList = new CompanyAddressRepository().GetAddressesOfCompany(companyID);
             gridCompanyAddress.DataSource = comAdrList;
         }
         else
         {
             gridCompanyAddress.DataSource = new List<CompanyAddress>();
         }
         gridCompanyAddress.DataBind();
         if (gridCompanyAddress.Items.Count > 0)
         {
             gridCompanyAddress.Items[0].Selected = true;
         }
     }
 }
    protected void OnBtnSaveClicked(object sender, EventArgs e)
    {
        CompanyAddressRepository repo = new CompanyAddressRepository();

        //Check default
        if (chkDefault.Checked)
        {
            IList<CompanyAddress> addressOfCom = repo.GetAddressesOfCompany(SessionManager.CurrentCompany.CompanyID);
            bool isDefault = false;
            foreach (CompanyAddress item in addressOfCom)
            {
                if (item.IsDefault)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["AddressId"]))
                    {
                        if (item.AddressID != int.Parse(Request.QueryString["AddressId"]))
                        {
                            isDefault = true;
                            break;
                        }
                    }
                    else
                    {
                        isDefault = true;
                        break;
                    }
                }
            }
            if (isDefault)
            {
                string message = ResourceManager.GetString("messageAlreadyHasDefaultAddress");
                string script1 = "<script type=\"text/javascript\">";
                script1 += " alert(\"" + message + "\")";
                script1 += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
                return;
            }
        }

        CompanyAddress address = GetAddress();
        if (!string.IsNullOrEmpty(Request.QueryString["AddressId"]))
        {
            repo.Update(address);
        }
        else
        {
            repo.Insert(address);
        }

        string script = "<script type=\"text/javascript\">";
        script += " OnBtnSaveClientClicked();";
        script += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow"))
            ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script);
    }
    private void BindData()
    {
        if (!string.IsNullOrEmpty(Request.QueryString["AddressId"]))
        {
            int addressID = int.Parse(Request.QueryString["AddressId"]);
            CompanyAddress address = new CompanyAddressRepository().FindOne(new CompanyAddress(addressID));
            txtNbrCustomer.Text = address.CompanyID.ToString();
            txtName.Text = address.Name;
            txtCO.Text = address.Co;
            txtAddress.Text = address.Address;
            txtCity.Text = address.City;
            txtZipCode.Text = address.ZipCode;
            txtVatNumber.Text = address.VatNumber;
            txtTelephone.Text = address.Telephone;
            txtFax.Text = address.Fax;
            txtEmail.Text = address.Email;
            chkDefault.Checked = address.IsDefault;
            txtFactoringCode.Text = address.FactoringCode;
            //if (!string.IsNullOrEmpty(address.FactoringCode))
            //{
            //    Company comp = new CompanyRepository().FindOne(new Company(address.FactoringCode.Value));
            //    ddlFactoringCode.Items.Clear();
            //    ddlFactoringCode.Items.Add(new RadComboBoxItem(comp.CompanyName, comp.CompanyID.ToString()));
            //    ddlFactoringCode.SelectedIndex = 0;

            //    hiddenCompanyId.Value = comp.CompanyID.ToString();
            //    txtFactoringCode.Text = comp.CompanyName;
            //}
        }
        else
        {
            txtNbrCustomer.Text = SessionManager.CurrentCompany.CompanyID.ToString();
        }
    }
Beispiel #5
0
    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;
    }
    protected void OnInvoiceCoordinateDeleteClicked(object sender, EventArgs e)
    {
        LinkButton lnkItem = (LinkButton)sender;
        int addressId = int.Parse(lnkItem.CommandArgument);
        CompanyAddress deleteItem = new CompanyAddress(addressId);
        CompanyAddressRepository repo = new CompanyAddressRepository();
        repo.Delete(deleteItem);

        BindInvoiceCoordinateGridOfCurrentCompany(null);
    }
    /// <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;
    }
Beispiel #8
0
 private string GetEmailOfCompany(int companyID)
 {
     IList<CompanyAddress> addressList = new CompanyAddressRepository().GetAddressesOfCompany(companyID);
     foreach (CompanyAddress addr in addressList)
     {
         if (!string.IsNullOrEmpty(addr.Email))
             return addr.Email;
     }
     Company com = new CompanyRepository().FindOne(new Company(companyID));
     if (com != null)
         return com.Email;
     return "";
 }
    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;
        }
    }
    /// <summary>
    /// binding company info when add invoice of a company
    /// </summary>
    /// <param name="companyID"></param>
    private void BindCompanyInfo(int companyID)
    {
        Company company = new CompanyRepository().FindOne(new Company(companyID));
        if (company == null) return ;
        txtCustomerName.Text = company.CompanyName;
        txtIdCustomer.Text = company.CompanyID.ToString();
        btnChooseCustomer.Enabled = false;

        txtIdCustomer.ReadOnly = true;
        txtCustomerName.ReadOnly = true;

        IList<CompanyAddress> comAdrList = new CompanyAddressRepository().GetAddressesOfCompany(companyID);

        foreach (CompanyAddress item in comAdrList)
        {
            if (item.IsDefault)
            {
                hiddenCompanyAddressId.Value = item.AddressID.ToString();
                txtAddressName.Text = item.Name;
                txtAddress.Text = item.Address;
                txtZipCode.Text = item.ZipCode;
                txtCity.Text = item.City;
                txtVatNumber.Text = item.VatNumber;
                break;
            }
        }

        datInvoiceDate.SelectedDate = DateTime.Now;
        lnkAddInvoiceDetail.Visible = false;
        lnkAddNewPayment.Visible = false;
        btnChooseAddress.Enabled = true;
    }
    protected void OnInvoiceProfileAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument.IndexOf("DataBindCompanyAddress") != -1)
        {
            string[] param = e.Argument.Split('-');
            if (param.Length == 2)
            {
                invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divHeader);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtAddressName);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtAddress);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtZipCode);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtCity);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtVatNumber);
                //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, btnChooseAddress);

                invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, hiddenCompanyAddressId);
                int companyID = int.Parse(param[1]);
                Company company = new CompanyRepository().FindOne(new Company(companyID));
                txtCustomerName.Text = company.CompanyName;
                txtIdCustomer.Text = companyID.ToString();

                IList<CompanyAddress> comAdrList = new CompanyAddressRepository().GetAddressesOfCompany(companyID);
                hiddenCompanyAddressId.Value = null;

                txtAddressName.Text = null;
                txtAddress.Text = null;
                txtZipCode.Text = null;
                txtCity.Text = null;
                txtVatNumber.Text = null;
                foreach (CompanyAddress item in comAdrList)
                {
                    if (item.IsDefault)
                    {
                        hiddenCompanyAddressId.Value = item.AddressID.ToString();
                        txtAddressName.Text = item.Name;
                        txtAddress.Text = item.Address;
                        txtZipCode.Text = item.ZipCode;
                        txtCity.Text = item.City;
                        txtVatNumber.Text = item.VatNumber;
                        break;
                    }
                }
                btnChooseAddress.Enabled = true;
            }
        }

        else if (e.Argument.IndexOf("RebindInvoiceDetailData") != -1)
        {
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotalHTVA);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotalVAT);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPaymentDate);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPayment);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, chkPayment);
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, gridInvoiceDetails);
            gridInvoiceDetails.Rebind();
        }
        else if (e.Argument.IndexOf("RebindInvoicePaymentData") != -1)
        {
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, divTotal);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPaymentDate);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, txtPayment);
            //invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, chkPayment);
            invoiceProfileAjaxManager.AjaxSettings.AddAjaxSetting(invoiceProfileAjaxManager, gridInvoicePayments);
            gridInvoicePayments.Rebind();
        }
        else if (e.Argument.IndexOf("ViewEditInvoice") != -1)
        {
            string url = Request.Url.PathAndQuery;

            if (hidMode.Value == "view")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                    url = url.Replace(Request.QueryString["mode"], "edit");
                else
                    url += "&mode=edit";
                Response.Redirect(url, true);
            }
            else
            {
                if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                    url = url.Replace(Request.QueryString["mode"], "view");
                else
                    url += "&mode=view";
                Response.Redirect(url, true);
            }
        }
        else if (e.Argument.IndexOf("SaveInvoice") != -1)
        {
            string message;
            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)
            {
                repo.UpdateInvoices(saveItem);
            }
            else
            {
                repo.InserNewInvoices(saveItem);
            }
            SessionManager.CurrentInvoice = saveItem;

            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);
            //string url = Request.Url.PathAndQuery;
            //if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
            //    url = url.Replace(Request.QueryString["mode"], "view");
            //else
            //    url += "&mode=view";
            //Response.Redirect(url, true);
        }
        else if (e.Argument.IndexOf("PrintInvoice") != -1)
        {
           /* Common.ExportInvoices(SessionManager.CurrentInvoice,
            WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory);
            string script = " alert(\"" + ResourceManager.GetString("messageExportSuccessfully") + "\")";
            invoiceProfileAjaxManager.ResponseScripts.Add(script);*/
        }
        else if (e.Argument.IndexOf("EmailInvoice") != -1)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
            {
                string selectedInvoiceIDs = Request.QueryString["InvoiceIdPK"];
                string url = "SendEmail.aspx?type=invoice&ids=" + selectedInvoiceIDs;
                invoiceProfileAjaxManager.ResponseScripts.Add(string.Format("OnSendInvoiceByEmail('{0}')", url));
            }
        }
    }
    protected void OnButtonInvoiceEmailClicked(object sender, EventArgs e)
    {
        Invoices currentInvoice = SessionManager.CurrentInvoice;
        CompanyAddress comAddress = new CompanyAddressRepository().FindOne(
            new CompanyAddress(currentInvoice.RefCustomerNumber.Value));
        if (comAddress != null)
        {
            string email = string.Empty;
            if (!string.IsNullOrEmpty(comAddress.Email))
            {
                email = comAddress.Email.Trim();
            }
            else
            {
                Company company = new CompanyRepository().FindOne(new Company(comAddress.CompanyID));
                if (company != null && !string.IsNullOrEmpty(company.Email))
                {
                    email = company.Email.Trim();
                }
            }
            if (!string.IsNullOrEmpty(email))
            {
                try
                {
                    string fileName = Common.ExportInvoices(currentInvoice,
                        WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory);
                    //Microsoft.Office.Interop.Outlook.Application outlookApp =
                    //    new Microsoft.Office.Interop.Outlook.Application();
                    //Microsoft.Office.Interop.Outlook.MailItem mailItem =
                    //    (Microsoft.Office.Interop.Outlook.MailItem)
                    //    outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                    //mailItem.To = email;
                    //mailItem.Subject = "Send invoice";
                    //mailItem.Attachments.Add(fileName,
                    //    Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    //mailItem.Display(true);
                    string script = "<script type=\"text/javascript\">";
                    script += " OpenOutlookSendMail(" + "'" + "Send invoice" + "',"
                                                 + "'" + email + "',"
                                                 + "'" + fileName + "'"
                                                 + ");";
                    //script += " OpenMail();";
                    script += " </script>";

                    if (!ClientScript.IsClientScriptBlockRegistered("saveAction"))
                        ClientScript.RegisterStartupScript(this.GetType(), "saveAction", script);

                }
                catch (System.Exception ex)
                {
                    string script2 = "<script type=\"text/javascript\">";

                    script2 += " alert(\"" + ex.Message + "\")";
                    script2 += " </script>";

                    if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                        ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script2);
                }
            }
            else
            {
                string message = ResourceManager.GetString("messageInvoiceNotHaveAnyEmail");
                string script1 = "<script type=\"text/javascript\">";
                script1 += " alert(\"" + message + "\")";
                script1 += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
            }
        }
    }
Beispiel #13
0
    protected void OnButtonInvoiceEmailSelectionClicked(object sender, EventArgs e)
    {
        GridItemCollection col = gridInvoice.SelectedItems;
        IList<Invoices> invoiceList = new List<Invoices>();
        string email = string.Empty;
        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);
                invoiceList.Add(invoice);
                CompanyAddress address = new CompanyAddressRepository().FindOne(
                    new CompanyAddress(invoice.RefCustomerNumber.Value));

                if (!string.IsNullOrEmpty(address.Email))
                {
                    if (email == string.Empty)
                    {
                        email = address.Email.Trim();
                    }
                    else if (email != address.Email.Trim())
                    {
                        string message = ResourceManager.GetString("messageInvoicesNotHaveSameEmail");
                        string script1 = "<script type=\"text/javascript\">";
                        script1 += " alert(\"" + message + "\")";
                        script1 += " </script>";

                        if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                            ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
                        return;
                    }
                }
                else
                {
                    string message = ResourceManager.GetString("messageInvoiceNotHaveAnyEmail");
                    string script1 = "<script type=\"text/javascript\">";
                    script1 += " alert(\"" + message + "\")";
                    script1 += " </script>";

                    if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                        ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);
                    return;
                }
            }
        }

        Microsoft.Office.Interop.Outlook.Application outlookApp =
                        new Microsoft.Office.Interop.Outlook.Application();
        Microsoft.Office.Interop.Outlook.MailItem mailItem =
            (Microsoft.Office.Interop.Outlook.MailItem)
            outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
        mailItem.To = email;
        mailItem.Subject = "Send invoice";

        foreach (Invoices item in invoiceList)
        {
            string fileName = Common.ExportInvoices(
                item, WebConfig.AddressFillInInvoice, WebConfig.AbsoluteExportDirectory);
            mailItem.Attachments.Add(fileName,
                Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
        }
        mailItem.Display(true);
    }