예제 #1
0
        private void getrate()
        {
            try
            {
                if (Destination.Text == "" || Destination.Text == null)
                {
                    throw new Exception("Enter destination properly..");
                }
                if (CustomerSelected.Text == "" || CustomerSelected.Text == null)
                {
                    throw new Exception("Select client properly...");
                }
                if (TypeComboBox.Text == "" || TypeComboBox.Text == null)
                {
                    throw new Exception("Select Service type properly...");
                }
                if (DoxCombobox.Text == "" || DoxCombobox.Text == null)
                {
                    throw new Exception("Select DOX/NDOX properly...");
                }
                double weight;
                if (!double.TryParse(BilledWeightTextBox.Text, out weight))
                {
                    throw new Exception("Enter billed weight properly...");
                }

                string custCode    = ((Client)CustomerSelected.SelectedItem).CLCODE.Trim();
                string destination = ((City)Destination.SelectedItem).CITY_CODE.Trim();
                string type        = ((Service)TypeComboBox.SelectedItem).SER_CODE.Trim();
                char   dox         = DoxCombobox.Text.ElementAt(0);
                double cost        = UtilityClass.getCost(custCode, weight, destination, type, dox);
                this.BilledAmount.Text = string.Format("{0:0.00}", cost);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
예제 #2
0
        public RuntimeData fillData(RuntimeData data)
        {
            List <Client>  clientList  = DataSources.ClientCopy;
            List <City>    cityList    = DataSources.CityCopy;
            List <Service> serviceList = DataSources.ServicesCopy;

            if (CustomerSelected.Text == "")
            {
                CustomerSelected.Text = "<NONE>";
            }
            if (WeightAccToDTDC.Text == "")
            {
                WeightAccToDTDC.Text = "0";
            }
            if (WeightAccToFranchize.Text == "")
            {
                WeightAccToFranchize.Text = WeightAccToDTDC.Text;
            }
            if (BilledWeightTextBox.Text == "")
            {
                BilledWeightTextBox.Text = WeightAccToFranchize.Text;
            }
            if (BilledAmount.Text == "")
            {
                BilledAmount.Text = "0";
            }
            if (Destination.Text == "" || Destination.Text == null)
            {
                MessageBox.Show("City cannot be empty");
                return(null);
            }
            data = dataContext.SingleOrDefault(x => x.ConsignmentNo == ConnsignmentNumber.Text);
            if (data == null)
            {
                BillingDataDataContext db = new BillingDataDataContext();
                var TData = db.Transactions.SingleOrDefault(x => x.ConnsignmentNo == ConnsignmentNumber.Text);
                if (TData == null)
                {
                    data               = new RuntimeData();
                    data.Id            = Guid.NewGuid();
                    data.ConsignmentNo = ConnsignmentNumber.Text;
                }
                else
                {
                    data = UtilityClass.convertTransObjToRunObj(TData);
                }
            }
            double weight;

            if (Double.TryParse(WeightAccToDTDC.Text, out weight))
            {
                data.Weight = weight;
            }
            else
            {
                MessageBox.Show("Weight is incorrect", "Error");
                return(null);
            }
            data.FrWeight = Double.Parse(WeightAccToFranchize.Text);
            double tmpD;

            if (Cost.Text == "" || !double.TryParse(Cost.Text, out tmpD))
            {
                Cost.Text = "0";
            }
            data.Amount = Decimal.Parse(Cost.Text);
            var c1 = cityList.Where(x => x.NameAndCode == Destination.Text).FirstOrDefault();

            if (c1 != null)
            {
                data.Destination = c1.CITY_CODE;
                data.City_Desc   = c1.CITY_DESC;
            }
            decimal tempDecimal;

            if (decimal.TryParse(DestinationPin.Text, out tempDecimal))
            {
                data.DestinationPin = tempDecimal;
            }
            data.CustCode = DataSources.ClientCopy.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLCODE).FirstOrDefault();
            if (data.CustCode == "" || data.CustCode == null || data.CustCode == "<NONE>")
            {
                MessageBox.Show("No customer selected...", "Error");
                return(null);
            }
            if (MODE.Text != "")
            {
                data.Mode = MODE.Text;
            }
            Service service = serviceList.Where(x => x.NameAndCode == TypeComboBox.Text.Trim()).FirstOrDefault();

            if (service == null)
            {
                MessageBox.Show("No service selected...", "Error");
                return(null);
            }
            data.Type         = service.SER_CODE;
            data.Service_Desc = service.SER_DESC;
            data.BookingDate  = InsertionDate.SelectedDate ?? DateTime.Today;
            if (decimal.TryParse(BilledAmount.Text, out tempDecimal))
            {
                data.FrAmount = tempDecimal;
            }
            else
            {
                MessageBox.Show("Invalid billed amount", "Error");
                return(null);
            }
            if (DoxCombobox.Text == "")
            {
                DoxCombobox.Text = "Dox";
            }
            data.DOX = DoxCombobox.Text.Length > 1 ? DoxCombobox.Text.ElementAt(0) : 'D';
            float tempValue;

            if (float.TryParse(BilledWeightTextBox.Text, out tempValue))
            {
                data.BilledWeight = double.Parse(BilledWeightTextBox.Text, CultureInfo.InvariantCulture);
            }
            else
            {
                BilledWeightTextBox.Text = "";
            }
            if (data.Destination == null)
            {
                MessageBoxResult rsltMessageBox = MessageBox.Show("City not found \n Would you like to enter city", "", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
                if (MessageBoxResult.Yes == rsltMessageBox)
                {
                    return(null);
                }
                else
                {
                    this.Close();
                }
            }
            data.CustCode = clientList.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLCODE).FirstOrDefault();
            if (data.CustCode != null)
            {
                data.Client_Desc = clientList.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLNAME).FirstOrDefault();
            }
            if (this.BilledWeightTextBox.Text == "" || this.BilledWeightTextBox.Text == null)
            {
                if (this.WeightAccToFranchize.Text == "" || this.WeightAccToFranchize == null)
                {
                    data.BilledWeight = 0;
                }
                else
                {
                    data.BilledWeight = data.FrWeight;
                }
            }
            else
            {
                if (float.TryParse(BilledWeightTextBox.Text, out tempValue))
                {
                    data.BilledWeight = double.Parse(BilledWeightTextBox.Text, CultureInfo.InvariantCulture);
                }
            }
            data.ConsigneeName = ConsgineeName.Text;
            data.ConsignerName = ConsignerName.Text;
            data.SubClient     = SubClientComboBox.Text;
            if (RecalculateCheckBox.IsChecked == true)
            {
                data.RecalculateEnabled = 'T';
            }
            else
            {
                data.RecalculateEnabled = 'F';
            }
            if (decimal.TryParse(InsuranceBox.Text, out tempDecimal))
            {
                data.Insurance = tempDecimal;
            }
            else
            {
                data.Insurance    = 0;
                InsuranceBox.Text = "0";
            }
            return(data);
        }
        public PrintMainWindow(Invoice inv)
        {
            try
            {
                InitializeComponent();
                BillingDataDataContext db   = new BillingDataDataContext();
                List <RuntimeData>     data = UtilityClass.convertTransListToRuntimeList(db.ExecuteQuery <Transaction>(@"
                SELECT  [ID]
      ,[AmountPayed]
      ,[AmountCharged]
      ,[ConnsignmentNo]
      ,[Weight]
      ,[WeightByFranchize]
      ,[Destination]
      ,[DestinationPin]
      ,[UserId]
      ,[BookingDate]
      ,[AddDate]
      ,[LastModified]
      ,[Type]
      ,[Mode]
      ,[DOX]
      ,[ServiceTax]
      ,[SplDisc]
      ,[InvoiceNo]
      ,[InvoiceDate]
      ,[CustCode]
      ,[TransMF_No]
      ,[BilledWeight]
  FROM [BillingDatabase].[dbo].[InvoiceView]      
where [BillId] = '" + inv.BillId + @"'        
            ").ToList());
                source   = UtilityClass.convertToRuntimeVIew(data.OrderBy(x => x.BookingDate).ThenBy(z => z.ConsignmentNo).ToList());
                rs       = new ReportDataSource();
                rs.Value = source;
                if (inv.Misc == null)
                {
                    inv.Misc = 0;
                }
                if (inv.PreviousDue == null)
                {
                    inv.PreviousDue = 0;
                }

                Client clc = DataSources.ClientCopy.SingleOrDefault(x => x.CLCODE == inv.ClientCode);
                List <ReportParameter> repParams = new List <ReportParameter>();
                DateTime FromDate   = data.Min(x => x.BookingDate);
                DateTime ToDate     = data.Max(x => x.BookingDate);
                string   dateString = FromDate.ToString("dd/MM/yyyy") + " to " + ToDate.ToString("dd/MM/yyyy");
                repParams.Add(new ReportParameter("DateString", dateString));
                string descriptionString = "Total Consignments: " + source.Count;
                repParams.Add(new ReportParameter("DescriptionString", descriptionString));
                repParams.Add(new ReportParameter("MainAmountString", String.Format("{0:0.00}", inv.Basic)));
                repParams.Add(new ReportParameter("DiscountPString", String.Format("{0:0.00}", inv.Discount)));
                repParams.Add(new ReportParameter("FuelString", String.Format("{0:0.00}", inv.Fuel)));
                repParams.Add(new ReportParameter("FuelAmount", String.Format("{0:0.00}", inv.fuelAmount)));
                repParams.Add(new ReportParameter("ServiceTaxString", String.Format("{0:0.00}", inv.STax)));
                repParams.Add(new ReportParameter("ServiceTaxAmount", String.Format("{0:0.00}", inv.taxAmount)));
                repParams.Add(new ReportParameter("DiscountAmountString", String.Format("{0:0.00}", inv.discountAmount)));
                repParams.Add(new ReportParameter("SWC", String.Format("{0:0.00}", inv.SWC)));
                repParams.Add(new ReportParameter("MiscellaneousAmountString", String.Format("{0:0.00}", inv.Misc)));
                repParams.Add(new ReportParameter("TNC", Configs.Default.TNC));
                repParams.Add(new ReportParameter("TotalAmountString", String.Format("{0:0.00}", inv.totalAmount)));
                repParams.Add(new ReportParameter("TotalAmountInWordString", UtilityClass.NumbersToWords((int)Math.Round(inv.totalAmount))));
                if (inv.PreviousDue == 0 || inv.PreviousDue == null)
                {
                    repParams.Add(new ReportParameter("PreviousDueString", ""));
                }
                else
                {
                    repParams.Add(new ReportParameter("PreviousDueString", String.Format("{0:0.00}", inv.PreviousDue)));
                    repParams.Add(new ReportParameter("PreviousDueCheck", "Previous Due .:"));
                }
                repParams.Add(new ReportParameter("CompanyName", Configs.Default.CompanyName));
                repParams.Add(new ReportParameter("ComapnyPhoneNo", Configs.Default.CompanyPhone));
                repParams.Add(new ReportParameter("CompanyAddress", Configs.Default.CompanyAddress));
                repParams.Add(new ReportParameter("CompanyEmail", Configs.Default.CompanyEmail));
                repParams.Add(new ReportParameter("CompanyFax", Configs.Default.CompanyFax));
                repParams.Add(new ReportParameter("TinNumber", Configs.Default.Tin ?? ""));
                repParams.Add(new ReportParameter("ClientName", clc.CLNAME));
                repParams.Add(new ReportParameter("ClientAddress", clc.ADDRESS));
                repParams.Add(new ReportParameter("ClientPhoneNo", clc.CONTACTNO));
                repParams.Add(new ReportParameter("ServiceTaxNumber", Configs.Default.ServiceTaxno ?? ""));

                // repParams.Add(new ReportParameter("Tinnumber", Configs.Default.Tin));
                DateTime invDateTime;
                if (inv.BillId.Length < 14)
                {
                    invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmm", CultureInfo.InvariantCulture);
                }
                else
                {
                    invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmmss", CultureInfo.InvariantCulture);
                }
                repParams.Add(new ReportParameter("InvoiceDate", invDateTime.ToString("dd-MMM-yyyy")));

                repParams.Add(new ReportParameter("InvoiceNumber", inv.BillId));
                BillViewer.LocalReport.ReportPath = "Report1.rdlc";
                BillViewer.LocalReport.DataSources.Clear();
                rs.Name = "DataSet1";
                BillViewer.LocalReport.DataSources.Add(rs);
                BillViewer.LocalReport.SetParameters(repParams);
                BillViewer.LocalReport.DisplayName = inv.ClientName + "-" + inv.BillId;
                BillViewer.RefreshReport();
            }
            catch (Exception)
            {
                MessageBox.Show("Error opening file.");
                this.Close();
            }
        }
예제 #4
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Client client = DataSources.ClientCopy.FirstOrDefault(x => x.CLCODE == clientCodeSelectedValue);

            errorNos = "";
            if (startCOnnNoIndex <= endConnNoIndex && startCOnnNoIndex != -1 && endConnNoIndex != -1)
            {
                int total = endConnNoIndex - startCOnnNoIndex;
                var cs    = (from m in db.Cities select m).ToList();
                for (int i = startCOnnNoIndex; i <= endConnNoIndex; i++)
                {
                    RuntimeData data = DataStack.ElementAt(i);

                    data = db.RuntimeDatas.Single(x => x.Id == data.Id);
                    var c = cs.Where(x => x.CITY_CODE == data.Destination).FirstOrDefault();
                    if (c == null)
                    {
                        c = db.Cities.SingleOrDefault(x => x.CITY_CODE == "DEL");
                    }
                    data.CustCode = clientCodeSelectedValue;
                    if (client != null)
                    {
                        data.Client_Desc = client.CLNAME;
                    }
                    if (data.FrWeight == null)
                    {
                        data.FrWeight = data.Weight;
                    }
                    if (data.BilledWeight == null)
                    {
                        data.BilledWeight = data.Weight;
                    }
                    if (setWeightCheck == true)
                    {
                        data.BilledWeight = weight;
                    }
                    if (subClientCheck == true)
                    {
                        data.SubClient = subClient;
                    }
                    if (consignerCheck == true)
                    {
                        data.ConsignerName = consigner;
                    }
                    if (consigneeCheck == true)
                    {
                        data.ConsigneeName = consignee;
                    }
                    if (calcRateCheck == true)
                    {
                        try
                        {
                            decimal costObt = (decimal)UtilityClass.getCost(data.CustCode.Trim(), (double)data.BilledWeight, data.Destination.Trim(), data.Type.Trim(), (char)data.DOX);
                            if (data.Insurance != null)
                            {
                                costObt = costObt + (decimal)data.Insurance;
                            }
                            data.FrAmount = costObt;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message + ": Occured in " + data.ConsignmentNo);
                            data.FrAmount = -1;
                        }
                    }
                    try
                    {
                        RuntimeData ndata = DataStack.ElementAt(i);
                        dupliData(data, ndata);
                        db.SubmitChanges();
                    }
                    catch (Exception)
                    {
                        errorNos = errorNos + "\n " + data.ConsignmentNo;
                    }
                    worker.ReportProgress((((i - startCOnnNoIndex + 1) * 100) / total));
                }
            }
        }
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            unreadableData = new List <string>();
            Guid Id = Guid.NewGuid();
            BillingDataDataContext db = new BillingDataDataContext();
            MatchCollection        matches;
            double progress = 0;

            try
            {
                PdfReader     reader = new PdfReader((string)e.Argument);
                StringBuilder text   = new StringBuilder();
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
                }
                Regex reg = new Regex(@"(\d+)\s+([A-Za-z]\d+)\s+\d+\s+(\d{1,2}/){2}\d{2}\s+([^\d]*)(\d+\.\d*)\s+(\w{3})\s+([^\d]*\d+\.\d*)");
                matches  = reg.Matches(text.ToString());
                progress = 5;
                bgWorker.ReportProgress((int)progress);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw new Exception("Unable to parse invoice");
            }
            double count = matches.Count, ctr = 0;

            foreach (Match match in matches)
            {
                InvoiceAnalyzeResult data = new InvoiceAnalyzeResult();
                double temp;
                bool   isValid = true;
                data.AnalyzeId   = Id;
                data.Id          = Guid.NewGuid();
                data.SrlNo       = match.Groups[1].Value;
                data.ConnNo      = match.Groups[2].Value;
                data.Destination = match.Groups[4].Value;
                if (double.TryParse(match.Groups[5].Value, out temp) == true)
                {
                    data.Weight = temp;
                }
                else
                {
                    isValid = false;
                }
                data.serviceCode = match.Groups[6].Value;
                if (double.TryParse(match.Groups[7].Value, out temp) == true)
                {
                    data.Amount = temp;
                }
                else
                {
                    isValid = false;
                }
                if (isValid)
                {
                    db.InvoiceAnalyzeResults.InsertOnSubmit(data);
                    db.SubmitChanges();
                }
                else
                {
                    unreadableData.Add(match.Groups[1].Value);
                }
                ctr++;
                bgWorker.ReportProgress((int)(((ctr / count) * 50) + progress));
            }
            Results = db.InvoiceAnalyzeResults.Where(x => x.AnalyzeId == Id);
            List <TransactionCityView> Transactions = (from transaction in db.TransactionCityViews
                                                       join result in Results
                                                       on transaction.ConnsignmentNo equals result.ConnNo
                                                       select transaction).ToList();

            progress = 60;
            bgWorker.ReportProgress((int)progress);
            count = Results.Count();
            ctr   = 0;
            db.UpdateBillingAmount();
            foreach (InvoiceAnalyzeResult result in Results)
            {
                TransactionCityView trans = Transactions.SingleOrDefault(x => x.ConnsignmentNo == result.ConnNo);
                result.MisMatchDesc = "";
                try
                {
                    if (trans == null)
                    {
                        result.hasError     = true;
                        result.MisMatchDesc = "Transaction not found";
                        continue;
                    }

                    if (trans.WeightByFranchize != result.Weight)
                    {
                        result.MisMatchDesc = "Weight should be " + trans.WeightByFranchize;
                        result.WeightDif    = (decimal)((result.Weight ?? 0) - (trans.WeightByFranchize ?? 0));
                    }
                    if (trans.CITY_DESC.Trim() != result.Destination.Trim())
                    {
                        result.MisMatchDesc = result.MisMatchDesc + " Destination should be " + trans.CITY_DESC;
                    }
                    if (trans.Type.Trim() != result.serviceCode.Trim())
                    {
                        result.MisMatchDesc = result.MisMatchDesc + " Service should be " + trans.Type.Trim();
                    }
                    trans.AmountCharged = (decimal)UtilityClass.getCost("<DTDC>", (double)trans.WeightByFranchize, trans.Destination.Trim(), trans.Type.Trim(), trans.DOX);
                    if (Math.Abs((trans.AmountCharged - (decimal)result.Amount) ?? 0) > 2)
                    {
                        result.hasError     = true;
                        result.MisMatchDesc = result.MisMatchDesc + " Amount should be " + Math.Round((trans.AmountCharged ?? 0), 2);
                        result.AmountDiff   = (decimal)(result.Amount ?? 0) - (decimal)(trans.AmountCharged ?? 0);
                    }
                }
                catch (Exception ex)
                {
                    result.hasError     = true;
                    result.MisMatchDesc = result.MisMatchDesc + " Unable to process record:  " + ex.Message;
                }
                ctr++;
                bgWorker.ReportProgress((int)(((ctr / count) * 30) + progress));
            }
            bgWorker.ReportProgress(100);
        }
예제 #6
0
        void loadData_Closed(object sender, EventArgs e)
        {
            this.Effect = null;
            LoadData dataWind = (LoadData)sender;

            if (dataWind.dataLoaded == false)
            {
                return;
            }
            //TODO: Get Name
            string name = "";
            string stockStart = "", stockEnd = "";

            if (dataWind.isLoadedFromBook == true)
            {
                try
                {
                    stockStart = dataWind.startConnNo;
                    stockEnd   = dataWind.endConnNo;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error loading data: " + ex.Message, "Error");
                    return;
                }
            }
            if (dataWind.dataLoaded)
            {
                isLoadedFromBook     = dataWind.isLoadedFromBook;
                toDate_loadDataWin   = dataWind.toDate;
                fromDate_loadDataWin = dataWind.fromDate;
            }

            if (dataWind.isNewSheet || dataGridHelper.CurrentNumberOfSheets <= 0)
            {
                if (dataWind.isLoadedFromBook == false)
                {
                    dataWind.data = UtilityClass.loadDataFromDatabase(fromDate_loadDataWin ?? DateTime.Now, toDate_loadDataWin ?? DateTime.Now, dataGridHelper.currentMaxSheetNumber + 1);
                }
                else
                {
                    dataWind.data = UtilityClass.loadDataFromBook(dataGridHelper.currentMaxSheetNumber + 1, stockStart, stockEnd);
                }

                int key = dataGridHelper.addNewSheet(dataWind.data, name);
                addingNewPage(key);
            }
            else
            {
                if (dataWind.isLoadedFromBook == false)
                {
                    dataWind.data = UtilityClass.loadDataFromDatabase(toDate_loadDataWin ?? DateTime.Now, fromDate_loadDataWin ?? DateTime.Now, dataGridHelper.currentSheetNumber);
                }
                else
                {
                    dataWind.data = UtilityClass.loadDataFromBook(dataGridHelper.currentSheetNumber, stockStart, stockEnd);
                }
                dataGridHelper.addDataToCurrentSheet(dataWind.data);
                dataGridHelper.refreshCurrentPage();
            }

            MessageBlock.Text = DateTime.Now.ToShortTimeString() + ": " + "Data loading successfull" + "\n" + MessageBlock.Text;
        }
        private void printObj(Client client = null)
        {
            #region temp
            string errorMsg = "";
            if (ToDate.SelectedDate == null || FromDate.SelectedDate == null || ToDate.SelectedDate < FromDate.SelectedDate)
            {
                errorMsg += "Please set the date properly. \n";
            }
            if (ServiceTaxBox.Text == "")
            {
                ServiceTaxBox.Text = "0";
            }
            double temp;
            if (TaxBox.Text == "")
            {
                TaxBox.Text = "0";
            }
            if (MiscBox.Text == "")
            {
                MiscBox.Text = "0";
            }
            if (PreviousDueTextBox.Text == "")
            {
                PreviousDueTextBox.Text = "0";
            }
            if (double.TryParse(TaxBox.Text, out temp) == false)
            {
                errorMsg += "Please enter fuel surcharge correctly. \n";
            }
            if (double.TryParse(ServiceTaxBox.Text, out temp) == false)
            {
                errorMsg += "Please enter service tax correctly. \n";
            }
            if (double.TryParse(MiscBox.Text, out temp) == false)
            {
                errorMsg += "Please enter miscellenaeous charge correctly. \n";
            }
            if (double.TryParse(PreviousDueTextBox.Text, out temp) == false)
            {
                errorMsg += "Please enter previous charge correctly. \n";
            }
            if (double.TryParse(DiscountBox.Text, out temp) == false)
            {
                errorMsg += "Enter customer discount properly. \n";
            }
            if (errorMsg != "")
            {
                MessageBox.Show(errorMsg);
                return;
            }
            #endregion
            invoice = new FinalUi.Invoice();
            BillingDataDataContext db = new BillingDataDataContext();
            source = UtilityClass.convertToRuntimeVIew(dataGridSource).Where(x => x.CustCode == ((Client)ClientList.SelectedItem).CLCODE && x.BookingDate <= ToDate.SelectedDate && x.BookingDate >= FromDate.SelectedDate).OrderBy(y => y.BookingDate).ThenBy(z => z.ConsignmentNo).ToList();
            if (SubClientComboBox.Text == "")
            {
                source = source.Where(x => x.SubClient == "" || x.SubClient == null).ToList();
            }
            else
            {
                source = source.Where(x => x.SubClient == SubClientComboBox.Text).ToList();
            }
            rs.Value = source;
            Client curClient;
            if (client == null)
            {
                curClient = ((Client)ClientList.SelectedItem);
            }
            else
            {
                curClient = client;
            }
            invoice.Basic      = (double)(source.Sum(x => x.FrAmount) ?? 0);
            invoice.ClientCode = curClient.CLCODE;
            invoice.Discount   = double.Parse(DiscountBox.Text);
            invoice.Fuel       = double.Parse(TaxBox.Text);
            invoice.STax       = double.Parse(ServiceTaxBox.Text);
            List <ReportParameter> repParams = new List <ReportParameter>();
            DateTime toDate     = ToDate.SelectedDate ?? DateTime.Today;
            DateTime fromDate   = FromDate.SelectedDate ?? DateTime.Today;
            string   dateString = fromDate.ToString("dd/MM/yyyy") + " to " + toDate.ToString("dd/MM/yyyy");
            repParams.Add(new ReportParameter("DateString", dateString));
            string descriptionString = "Total Consignments: " + source.Count;
            repParams.Add(new ReportParameter("DescriptionString", descriptionString));
            repParams.Add(new ReportParameter("MainAmountString", String.Format("{0:0.00}", invoice.Basic)));
            repParams.Add(new ReportParameter("FuelString", TaxBox.Text));
            repParams.Add(new ReportParameter("ServiceTaxString", String.Format("{0:0.00}", double.Parse(ServiceTaxBox.Text))));
            repParams.Add(new ReportParameter("DiscountPString", String.Format("{0:0.00}", double.Parse(DiscountBox.Text))));
            repParams.Add(new ReportParameter("MiscellaneousAmountString", MiscBox.Text));
            double temp2;
            if (double.TryParse(MiscBox.Text, out temp2))
            {
                invoice.Misc = temp2;
            }
            repParams.Add(new ReportParameter("DiscountAmountString", String.Format("{0:0.00}", invoice.discountAmount)));
            repParams.Add(new ReportParameter("FuelAmount", String.Format("{0:0.00}", invoice.fuelAmount)));
            repParams.Add(new ReportParameter("ServiceTaxAmount", String.Format("{0:0.00}", invoice.taxAmount)));
            repParams.Add(new ReportParameter("SWC", String.Format("{0:0.00}", invoice.SWC)));
            if (PreviousDueCheck.Checked == true)
            {
                invoice.PreviousDue = double.Parse(PreviousDueTextBox.Text);
            }
            repParams.Add(new ReportParameter("TotalAmountString", String.Format("{0:0.00}", invoice.totalAmount)));
            string totalAmountinWordString = UtilityClass.NumbersToWords((int)Math.Round(invoice.totalAmount));
            repParams.Add(new ReportParameter("TotalAmountInWordString", totalAmountinWordString));
            if (PreviousDueCheck.Checked == true)
            {
                repParams.Add(new ReportParameter("PreviousDueString", PreviousDueTextBox.Text));
                repParams.Add(new ReportParameter("PreviousDueCheck", "Previous Due .:"));
            }
            repParams.Add(new ReportParameter("CompanyName", Configs.Default.CompanyName));
            repParams.Add(new ReportParameter("ComapnyPhoneNo", Configs.Default.CompanyPhone));
            repParams.Add(new ReportParameter("CompanyAddress", Configs.Default.CompanyAddress));
            repParams.Add(new ReportParameter("CompanyEmail", Configs.Default.CompanyEmail));
            repParams.Add(new ReportParameter("CompanyFax", Configs.Default.CompanyFax));
            repParams.Add(new ReportParameter("ClientName", curClient.CLNAME + " " + SubClientComboBox.Text ?? " "));
            repParams.Add(new ReportParameter("ClientAddress", curClient.ADDRESS));
            repParams.Add(new ReportParameter("ClientPhoneNo", curClient.CONTACTNO));
            repParams.Add(new ReportParameter("TinNumber", Configs.Default.Tin ?? ""));
            repParams.Add(new ReportParameter("TNC", Configs.Default.TNC));
            repParams.Add(new ReportParameter("ServiceTaxNumber", Configs.Default.ServiceTaxno ?? ""));
            invoice.BillId  = (InvoiceDate.SelectedDate ?? DateTime.Today).ToString("yyyyMMdd");
            invoice.Date    = InvoiceDate.SelectedDate ?? DateTime.Today;
            invoice.BillId  = invoice.BillId + DateTime.Now.ToString("hhmmss");
            invoice.Remarks = RemarkBox.Text;

            invoice.TotalAmount = invoice.totalAmount;
            repParams.Add(new ReportParameter("InvoiceNumber", invoice.BillId));
            repParams.Add(new ReportParameter("InvoiceDate", (InvoiceDate.SelectedDate ?? DateTime.Today).ToString("dd-MMM-yyyy")));
            PrintMainWindow win = new PrintMainWindow(rs, repParams);
            win.Show();
        }