Пример #1
0
        private static string CreateJkInvoiceDetailHtml(InvoiceModel invoice)
        {
            var     jkinvoicedetailhtmlstring = new StringBuilder(JkInvoiceDetail);
            var     recordcount   = 0;
            var     finalrecord   = string.Empty;
            var     masterqty     = 0;
            decimal masteramount  = 0;
            var     rowIndex      = 1;
            var     rowIndexCount = 20;


            var address = DB.DistributorClientAddress(invoice.ShipTo.GetValueOrDefault());

            var billTo              = DB.DistributorClientAddress(invoice.BillTo.GetValueOrDefault());
            var billtoCountry       = DB.Country(billTo.Country);
            var invoiceShipmentMode = DB.ShipmentMode(invoice.ShipmentMode);
            var billtoPort          = DB.DestinationPort(billTo.Port.GetValueOrDefault());

            jkinvoicedetailhtmlstring
            .Replace("<$invoiceno$>", invoice.InvoiceNo)
            .Replace("<$shipmentdate$>", invoice.InvoiceDate.ToString("dd MMMM yyyy"))
            .Replace("<$shipcompanyname$>", address.CompanyName)
            .Replace("<$shipcompanyaddress$>", address.Address + "  " + address.State)
            .Replace("<$shipcompanypostalcode$>", address.PostCode + "  " + billtoCountry.ShortName)
            .Replace("<$shipcompanycontact$>", address.ContactName + "  " + address.ContactPhone)
            .Replace("<$shipmentmode$>", invoiceShipmentMode.Name)
            .Replace("<$awbno$>", invoice.AWBNo)
            .Replace("<$port$>", (billTo.Port != null && billTo.Port > 0) ? billtoPort.Name : string.Empty)
            .Replace("<$billtocompanyname$>", billTo.CompanyName)
            .Replace("<$billtocompanyname$>", billTo.Address)
            .Replace("<$billtocompanystate$>", billTo.Suburb + "  " + billTo.State + "  " + billTo.PostCode)
            .Replace("<$billtocompanycountry$>", billtoCountry.ShortName);


            var invoicedetail = "<table cellpadding=\"1\" cellspacing=\"0\" style=\"font-size: 7px\" width=\"100%\"><tr>" +
                                "<th border=\"0\" width=\"9%\"><b>Type</b></th>" +          //13
                                "<th border=\"0\" width=\"10%\"><b>Qty</b></th>" +          //5
                                "<th border=\"0\" width=\"20%\"><b>Sizes</b></th>" +        //25
                                "<th border=\"0\"  width=\"34%\"><b>Description</b></th>" + //35
                                "<th border=\"0\" width=\"6%\"><b>Price</b></th>" +
                                "<th border=\"0\" width=\"7%\"><b>Other/Ch</b></th>" +
                                "<th border=\"0\" width=\"6%\"><b>Total</b></th>" +
                                "<th border=\"0\" width=\"8%\"><b>AMOUNT</b></th></tr>";

            var invoiceItems = DB.InvoiceOrderDetailItemsForInvoice(invoice.ID).GroupBy(i => i.Distributor).ToList();

            foreach (var distributor in invoiceItems)
            {
                var     totoalqty   = 0;
                decimal totalamount = 0;
                invoicedetail += "<tr style=\"height:-2px;\" border=\"0.5\"><td style=\"line-height:10px;\" colspan=\"8\"><h6 style=\"padding-left:5px\"><b>" + distributor.Key /*address.CompanyName*/ + "</b></h6></td></tr>";
                rowIndex++;

                var lstOrderDetailsGroup = distributor.ToList();

                foreach (var item in lstOrderDetailsGroup)
                {
                    var orderdetailqty = string.Empty;
                    orderdetailqty += item.SizeQuantities;
                    var total = (decimal)(item.Amount);
                    totalamount  = totalamount + total;
                    masteramount = masteramount + total;
                    totoalqty    = totoalqty + item.Qty.GetValueOrDefault();

                    invoicedetail += "<tr style=\"height:-2px;\">" +
                                     "<td style=\"line-height:10px;\" width=\"9%\">" + item.OrderType + "<br>" + item.PurchaseOrder + "</td>" +                                                                    //13
                                     "<td style=\"line-height:10px;\" width=\"10%\">" + item.Qty + "  " + item.ItemName + "</td>" +                                                                                //5
                                     "<td style=\"line-height:10px;\" width=\"20%\">" + item.VisualLayout + " " + item.Client + "<br>" + orderdetailqty.Trim().Substring(0, orderdetailqty.Length - 2) + "</td>" + //item.client(ic) //25
                                     "<td style=\"line-height:10px;\" width=\"34%\">" + item.Fabric + " " + item.Material + "</td>" +
                                     "<td style=\"line-height:10px;\" width=\"6%\">" + item.FactoryPrice.GetValueOrDefault().ToString("0.00") + "</td>" +                                                          //35
                                     "<td style=\"line-height:10px;\" width=\"7%\" >" + item.OtherCharges.GetValueOrDefault().ToString("0.00") + "</td>" +
                                     "<td style=\"line-height:10px;\" width=\"6%\" >" + ((decimal)item.Amount).ToString("0.00") + "</td>" +
                                     "<td style=\"line-height:10px;\" width=\"6%\" >" + total.ToString("0.00") + "</td></tr>" +
                                     "<tr><td style=\"line-height:0px;\" colspan=\"8\" border=\"0.5\"></td></tr>";

                    rowIndex++;

                    if (rowIndex >= rowIndexCount) //16
                    {
                        invoicedetail += "<tr style=\"height:5px;\"><td border=\"0\" style=\"line-height:50px;color: #FFFFFF;\" colspan=\"8\"><h6>INDICO</h6></td></tr>";
                        rowIndex       = 0;
                        rowIndexCount  = 27;
                    }
                }
                //}
                invoicedetail += "<tr style=\"height:2px;\"><td  style=\"line-height:-2px;color: #F0FFFF;\" colspan=\"8\"></td>"; //9colspan
                invoicedetail += "<tr>" +
                                 "<td  style=\"line-height:8px;\" border=\"0\" width=\"9%\">&nbsp;</td>" +                        //13
                                 "<td  style=\"line-height:8px;\" border=\"0\" width=\"10%\"><b>" + totoalqty + "</b></td>" +     //5
                                 "<td  style=\"line-height:8px;\" border=\"0\" width=\"20%\">&nbsp;</td>" +                       //25
                                 "<td style=\"line-height:8px;\" border=\"0\" width=\"34%\">&nbsp;</td>" +                        //35
                                 "<td style=\"line-height:8px;\" border=\"0\" width=\"6%\">&nbsp;</td>" +
                                 "<td style=\"line-height:8px;\" border=\"0\" width=\"7%\">&nbsp;</td>" +                         //IC
                                 "<td style=\"line-height:8px;\" border=\"0\" width=\"6%\">&nbsp;</td>" +                         //IC
                                 "<td  style=\"line-height:8px;\" border=\"0\" width=\"8%\">" + totalamount.ToString("0.00") + "</td>" +
                                 "</tr>";

                recordcount = recordcount + 1;
                masterqty   = masterqty + totoalqty;

                if (invoiceItems.Count != recordcount)
                {
                    invoicedetail += "<tr style=\"height:5px;\"><td border=\"0\" style=\"line-height:2px;color: #FFFFFF;\" colspan=\"8\"><h6>INDICO</h6></td>"; //7 colspan
                    rowIndex++;

                    if (rowIndex >= rowIndexCount)
                    {
                        invoicedetail += "<tr style=\"height:5px;\"><td border=\"0\" style=\"line-height:50px;color: #FFFFFF;\" colspan=\"8\"><h6>INDICO</h6></td></tr>"; //7 colspan
                        rowIndex       = 0;
                        rowIndexCount  = 27;
                    }
                }
            }

            invoicedetail += "</table>";

            if (invoiceItems.Count == recordcount)
            {
                finalrecord = "<table border=\"0.5\">" +
                              "<tr>" +
                              "<td width=\"9%\" style=\"line-height:0px;\">&nbsp;</td>" +  //13
                              "<td width=\"10%\" style=\"line-height:0px;\">&nbsp;</td>" + //5
                              "<td width=\"20%\" style=\"line-height:0px;\">&nbsp;</td>" + //25
                              "<td width=\"34%\" style=\"line-height:0px;\">&nbsp;</td>" + //35
                              "<td width=\"6%\" style=\"line-height:0px;\">&nbsp;</td>" +
                              "<td width=\"7%\" style=\"line-height:0px;\">&nbsp;</td>" +  //IC
                              "<td width=\"6%\" style=\"line-height:0px;\">&nbsp;</td>" +  //IC
                              "<td width=\"8%\" style=\"line-height:0px;\">&nbsp;</td>" +
                              "</tr>";
                finalrecord += "<tr>" +
                               "<td width=\"9%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +             //13
                               "<td width=\"10%\" style=\"line-height:10px;\" border=\"0\">" + masterqty + "</td>" + //5
                               "<td width=\"20%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +            //25
                               "<td width=\"34%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +            //35
                               "<td width=\"6%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +
                               "<td width=\"7%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +             //IC
                               "<td width=\"6%\" style=\"line-height:10px;\" border=\"0\">&nbsp;</td>" +             //IC
                               "<td width=\"8%\" style=\"line-height:10px;\" border=\"0\">" + masteramount.ToString("0.00") + "</td>" +
                               "</tr>" +
                               "</table>";
            }

            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$pricedetails$>", invoicedetail);
            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$finalrecord$>", finalrecord);

            var invoiceBank = DB.Bank(invoice.Bank.GetValueOrDefault());
            var bankCountry = DB.Country(invoiceBank.Country.GetValueOrDefault());

            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$bankname$>", invoiceBank.Name);

            string country = (invoiceBank.Country != null || invoiceBank.Country > 0) ? bankCountry.ShortName : string.Empty;

            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$bankaddress$>", invoiceBank.Address + "  " + invoiceBank.City + "  " + invoiceBank.State + "  " + invoiceBank.Postcode + "  " + country);

            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$accountnumber$>", invoiceBank.AccountNo);

            jkinvoicedetailhtmlstring = jkinvoicedetailhtmlstring.Replace("<$swiftcode$>", invoiceBank.SwiftCode);

            return(jkinvoicedetailhtmlstring.ToString());
        }