public InvoiceManager(InvoicePageModel invoiceData)
 {
     _invoiceData = invoiceData;
     //ExcelApp.LoadExcelFile(appDocumentPath + @"\Libs\Files\CoreFiles\TemplateFiles\invoice-template.xlsx", 1);
     ExcelApp.LoadExcelFile(Environment.CurrentDirectory + @"\Libs\Files\CoreFiles\TemplateFiles\invoice-template.xlsx", 1);
 }
Exemple #2
0
        public static bool ExportAsDailyExcell(string fullPath, List <SalesAndCollectionModel> filteredSalesAndCollections)
        {
            FilteredSalesAndCollections = filteredSalesAndCollections;

            try
            {
                ExcelApp.LoadExcelFile(Environment.CurrentDirectory + @"\Libs\Files\CoreFiles\TemplateFiles\daily-Sales-and-collection-report.xlsx", 1);

                int x = 11;
                if (FilteredSalesAndCollections != null)
                {
                    //**Writting the Excel File: **

                    while (x <= FilteredSalesAndCollections.Count + 11)
                    {
                        int grandSalesAmount      = 0;
                        int grandCollectionAmount = 0;

                        ExcelApp.XlWorkSheet.Cells[5, 1] = "Branch : ";
                        ExcelApp.XlWorkSheet.Cells[5, 7] = DateTime.Now.ToString("MMMM yyyy");

                        foreach (var item in FilteredSalesAndCollections)
                        {
                            ExcelApp.XlWorkSheet.Cells[x, 1] = item.Sl;

                            if (item.Date.HasValue)
                            {
                                ExcelApp.XlWorkSheet.Cells[x, 2] = item.Date.Value.ToString("dd-MM-yy");
                            }

                            ExcelApp.XlWorkSheet.Cells[x, 3] = item.DealerName;
                            ExcelApp.XlWorkSheet.Cells[x, 4] = item.IC_NO;

                            if (item.SyncType.ToLower().Equals("collection"))
                            {
                                ExcelApp.XlWorkSheet.Cells[x, 4] = item.MR_NO;
                            }

                            ExcelApp.XlWorkSheet.Cells[x, 5] = item.SalesAmount;
                            ExcelApp.XlWorkSheet.Cells[x, 6] = item.CollectionAmount;

                            grandSalesAmount      += item.SalesAmount;
                            grandCollectionAmount += item.CollectionAmount;

                            x++;
                            Excel.Range line = (Excel.Range)ExcelApp.XlWorkSheet.Rows[x];
                            line.Insert();
                        }

                        x++;

                        ExcelApp.XlWorkSheet.Cells[x, 5] = grandSalesAmount;
                        ExcelApp.XlWorkSheet.Cells[x, 6] = grandCollectionAmount;
                    }

                    //PrintOut();

                    //save as PDF
                    ExcelApp.SaveAsPDF(FileSystemUtility.GetFileDirectory(fullPath) + FileSystemUtility.GetFileName(fullPath) + @".pdf");

                    //save as Xlsx
                    ExcelApp.SaveExcelFile(fullPath);

                    ExcelApp.XlWorkBook.Close();

                    return(true);
                }
                else
                {
                    Console.WriteLine("Nothing to Print or write on Excel file");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                if (ex.Message.Equals("Exception from HRESULT: 0x800A03EC"))
                {
                    return(true);
                }

                return(false);
            }
        }
Exemple #3
0
        public static bool ExportAsPartyLedgerExcell(string fullPath, List <SalesAndCollectionModel> filteredSalesAndCollections)
        {
            FilteredSalesAndCollections = filteredSalesAndCollections;

            try
            {
                ExcelApp.LoadExcelFile(Environment.CurrentDirectory + @"\Libs\Files\CoreFiles\TemplateFiles\dealer-party-ledger.xlsx", 1);

                int x = 13;
                if (FilteredSalesAndCollections != null)
                {
                    //**Writting the Excel File: **

                    while (x <= FilteredSalesAndCollections.Count + 13)
                    {
                        int grandSalesAmount      = 0;
                        int grandCollectionAmount = 0;

                        ExcelApp.XlWorkSheet.Cells[9, 1]  = "Party Name : " + filteredSalesAndCollections.FirstOrDefault().DealerName;
                        ExcelApp.XlWorkSheet.Cells[9, 4]  = "Code : " + filteredSalesAndCollections.FirstOrDefault().DealerCode;
                        ExcelApp.XlWorkSheet.Cells[10, 1] = "Address : " + filteredSalesAndCollections.FirstOrDefault().Address;

                        foreach (var item in FilteredSalesAndCollections)
                        {
                            ExcelApp.XlWorkSheet.Cells[x, 1] = item.Sl;

                            if (item.Date.HasValue)
                            {
                                ExcelApp.XlWorkSheet.Cells[x, 2] = item.Date.Value.ToString("dd-MMM-yy");
                            }

                            ExcelApp.XlWorkSheet.Cells[x, 3] = item.IC_NO;
                            ExcelApp.XlWorkSheet.Cells[x, 4] = item.MR_NO;
                            ExcelApp.XlWorkSheet.Cells[x, 5] = item.OpeningBalance;
                            ExcelApp.XlWorkSheet.Cells[x, 6] = item.SalesAmount;
                            ExcelApp.XlWorkSheet.Cells[x, 7] = item.CollectionAmount;
                            ExcelApp.XlWorkSheet.Cells[x, 8] = item.ClosingBalance;

                            grandSalesAmount      += item.SalesAmount;
                            grandCollectionAmount += item.CollectionAmount;

                            x++;
                            Excel.Range line = (Excel.Range)ExcelApp.XlWorkSheet.Rows[x];
                            line.Insert();
                        }

                        x++;

                        ExcelApp.XlWorkSheet.Cells[x, 6] = grandSalesAmount;
                        ExcelApp.XlWorkSheet.Cells[x, 7] = grandCollectionAmount;
                        ExcelApp.XlWorkSheet.Cells[x, 8] = FilteredSalesAndCollections.LastOrDefault().ClosingBalance;
                    }

                    //PrintOut();

                    //save as PDF
                    ExcelApp.SaveAsPDF(FileSystemUtility.GetFileDirectory(fullPath) + FileSystemUtility.GetFileName(fullPath) + @".pdf");

                    //save as Xlsx
                    ExcelApp.SaveExcelFile(fullPath);

                    ExcelApp.XlWorkBook.Close();

                    return(true);
                }
                else
                {
                    Console.WriteLine("Nothing to Print or write on Excel file");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                if (ex.Message.Equals("Exception from HRESULT: 0x800A03EC"))
                {
                    return(true);
                }

                return(false);
            }
        }
 public ChallanManager(ChallanPageModel challanData)
 {
     _challanData = challanData;
     //ExcelApp.LoadExcelFile(appDocumentPath + @"\Libs\Files\CoreFiles\TemplateFiles\challan-template.xlsx", 1);
     ExcelApp.LoadExcelFile(Environment.CurrentDirectory + @"\Libs\Files\CoreFiles\TemplateFiles\challan-template.xlsx", 1);
 }