예제 #1
0
        private string makeStringInvoice(List <InvoiceFromExcel> invoicesByNo, out string ErrorMessage)
        {
            ErrorMessage = "";
            try
            {
                Decimal          totalInvoice = Convert.ToDecimal(invoicesByNo.Sum(p => p.TongTien));
                decimal          vatAmount    = 0;
                InvoiceFromExcel invoiceFirst = invoicesByNo.FirstOrDefault();
                if (string.IsNullOrWhiteSpace(invoiceFirst.MaKhachHang))
                {
                    ErrorMessage = "Thiếu thông tin: Mã khách hàng";
                    return(null);
                }
                if (string.IsNullOrWhiteSpace(invoiceFirst.TenKhachHang) && string.IsNullOrWhiteSpace(invoiceFirst.TenNguoiMuaHang))
                {
                    ErrorMessage = "Thiếu thông tin: Tên khách hàng";
                    return(null);
                }

                StringBuilder sbInvoice = new StringBuilder("<Inv>");
                sbInvoice.Append("<key/><Invoice>");
                sbInvoice.AppendFormat("<CusCode>{0}</CusCode>", invoiceFirst.MaKhachHang);
                sbInvoice.AppendFormat("<Buyer>{0}</Buyer>", convertSpecialCharacter(invoiceFirst.TenNguoiMuaHang));
                sbInvoice.AppendFormat("<CusName>{0}</CusName>", convertSpecialCharacter(invoiceFirst.TenKhachHang));
                sbInvoice.AppendFormat("<CusAddress>{0}</CusAddress>", convertSpecialCharacter(invoiceFirst.DiaChiKhachHang));
                sbInvoice.AppendFormat("<CusTaxCode>{0}</CusTaxCode>", invoiceFirst.MaSoThue);
                sbInvoice.Append("<PaymentMethod>TM/CK</PaymentMethod>");

                sbInvoice.Append(makeStringProducts(invoicesByNo, out vatAmount));

                sbInvoice.AppendFormat("<ArisingDate>{0}</ArisingDate>", invoiceFirst.NgayHoaDon.ToString("dd/MM/yyyy"));
                sbInvoice.AppendFormat("<Total>{0}</Total>", totalInvoice);
                sbInvoice.Append("<VATRate>0</VATRate>");
                sbInvoice.AppendFormat("<VATAmount>{0}</VATAmount>", vatAmount);
                long amountInvoice = (long)(totalInvoice + vatAmount);
                sbInvoice.AppendFormat("<Amount>{0}</Amount>", amountInvoice);
                string tienbangchu = NumberToLeter.DocTienBangChu(amountInvoice);
                sbInvoice.AppendFormat("<AmountInWords>{0}</AmountInWords>", tienbangchu);
                sbInvoice.Append("</Invoice></Inv>");
                return(sbInvoice.ToString());
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ErrorMessage = ex.Message;
                return(null);
            }
        }
        public string ParseIInvoice(byte[] data, string pattern, string serial, int comID, string accountName, ref string message, ref int failtCount)
        {
            StringBuilder rv = new StringBuilder("<Invoices>");

            rv.AppendLine("<BillTime></BillTime>");
            message    = "";
            failtCount = 0;
            StringBuilder Failed = new StringBuilder("<Invoices>");

            try
            {
                const string Fkey            = "Fkey";
                const string OrderNo         = "DonDatHang";
                const string OrderDate       = "NgayDatHang";
                const string ArisingDate     = "NgayHoaDon";
                const string CusName         = "TenKhachHang";
                const string CusCode         = "MaKhachHang";
                const string CusCom          = "TenDonVi";
                const string CusAddress      = "DiaChiKhachHang";
                const string CusPhone        = "DienThoaiKhachHang";
                const string CusTaxCode      = "MaSoThue";
                const string Kind_of_Payment = "HinhThucTT";
                const string ProdCode        = "MaSanPham";
                const string ProdName        = "SanPham";
                const string ProdUnit        = "DonViTinh";
                const string ProdQuantity    = "SoLuong";
                const string ProdPrice       = "DonGia";
                const string ProdTotal       = "ThanhTien";
                const string ProdVATRate     = "ThueSuat";
                const string ProdVATAmount   = "TienThue";
                const string ProdAmount      = "TienBan";
                const string GrossValue      = "ThanhTien-1";
                const string GrossValue0     = "ThanhTien0";
                const string GrossValue5     = "ThanhTien5";
                const string VatAmount5      = "Thue5";
                const string GrossValue10    = "ThanhTien10";
                const string VatAmount10     = "Thue10";
                const string Total           = "TongThanhTien";
                const string VAT_Amount      = "TongThue";
                const string Amount          = "TongCong";

                Guid   guid     = Guid.NewGuid();
                string fileName = AppDomain.CurrentDomain.BaseDirectory + "/Tempfile/" + guid + ".xls";
                using (System.IO.FileStream fs = System.IO.File.Create(fileName))
                {
                    fs.Write(data, 0, data.Length);
                }
                string          conn    = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
                OleDbConnection objConn = new OleDbConnection(conn);
                objConn.Open();
                OleDbCommand     command    = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
                OleDbDataAdapter objAdapter = new OleDbDataAdapter();
                objAdapter.SelectCommand = command;
                DataSet objDataset = new DataSet();
                objAdapter.Fill(objDataset);
                objConn.Close();
                System.IO.File.Delete(fileName);
                DataTable objTable   = objDataset.Tables[0];
                Type      temp       = InvServiceFactory.GetInvoiceType(pattern, comID);
                string    tempString = "";
                int       i          = 0;
                while (i < objTable.Rows.Count)
                {
                    DataRow       dr   = objTable.Rows[i];
                    string        fkey = "";
                    StringBuilder sb   = new StringBuilder("<Inv><key>");
                    if (dr.Table.Columns.Contains(Fkey))
                    {
                        tempString = dr[Fkey].ToString();
                        if (!string.IsNullOrEmpty(tempString))
                        {
                            fkey = tempString.Trim();
                            sb.Append(fkey);
                        }
                    }

                    sb.Append("</key><Invoice><CusCode>");
                    sb.Append(convertSpecialCharacter(dr[CusCode].ToString().Trim()));
                    sb.Append("</CusCode><CusName>");
                    sb.Append(convertSpecialCharacter(dr[CusName].ToString().Trim()));
                    sb.Append("</CusName><CusAddress>");
                    if (dr.Table.Columns.Contains(CusAddress))
                    {
                        sb.Append(convertSpecialCharacter(dr[CusAddress].ToString().Trim()));
                    }
                    sb.Append("</CusAddress><CusPhone>");
                    if (dr.Table.Columns.Contains(CusPhone))
                    {
                        sb.Append(dr[CusPhone].ToString().Trim());
                    }
                    sb.Append("</CusPhone><CusTaxCode>");
                    if (dr.Table.Columns.Contains(CusTaxCode))
                    {
                        sb.Append(dr[CusTaxCode].ToString().Trim());
                    }
                    sb.Append("</CusTaxCode><PaymentMethod>");
                    if (dr.Table.Columns.Contains(Kind_of_Payment))
                    {
                        sb.Append(convertSpecialCharacter(dr[Kind_of_Payment].ToString().Trim()));
                    }
                    sb.Append("</PaymentMethod><CusCom>");
                    if (dr.Table.Columns.Contains(CusCom))
                    {
                        sb.Append(convertSpecialCharacter(dr[CusCom].ToString().Trim()));
                    }
                    sb.Append("</CusCom><OrderNo>");
                    sb.Append(dr[OrderNo].ToString().Trim());
                    sb.Append("</OrderNo><OrderDate>");
                    sb.Append(dr[OrderDate].ToString().Trim());
                    sb.Append("</OrderDate><Products>");

                    int j = i;
                    do
                    {
                        DataRow drProduct = objTable.Rows[j];
                        sb.Append("<Product><Code>");
                        if (dr.Table.Columns.Contains(ProdCode))
                        {
                            sb.Append(convertSpecialCharacter(dr[ProdCode].ToString().Trim()));
                        }
                        sb.Append("</Code><ProdName>");
                        sb.Append(convertSpecialCharacter(drProduct[ProdName].ToString().Trim()));
                        sb.Append("</ProdName><ProdUnit>");
                        sb.Append(convertSpecialCharacter(drProduct[ProdUnit].ToString().Trim()));
                        sb.Append("</ProdUnit><ProdQuantity>");
                        tempString = drProduct[ProdQuantity].ToString().Trim();
                        sb.Append("</ProdQuantity><ProdPrice>");
                        sb.Append(drProduct[ProdPrice].ToString().Trim());
                        sb.Append("</ProdPrice><Amount>");
                        sb.Append(drProduct[ProdAmount].ToString().Trim());
                        sb.Append("</Amount><Total>");
                        sb.Append(drProduct[ProdTotal].ToString().Trim());
                        sb.Append("</Total><VATRate>");
                        sb.Append(drProduct[ProdVATRate].ToString().Trim());
                        sb.Append("</VATRate><VATAmount>");
                        sb.Append(drProduct[ProdVATAmount].ToString().Trim());
                        sb.Append("</VATAmount></Product>");
                        j++;
                    } while (j < objTable.Rows.Count && string.IsNullOrEmpty(objTable.Rows[j][CusName].ToString().Trim()));
                    sb.Append("</Products><Total>");
                    sb.Append(dr[Total].ToString().Trim());
                    sb.Append("</Total><DiscountAmount></DiscountAmount><VATRate></VATRate><VATAmount>");
                    sb.Append(dr[VAT_Amount].ToString().Trim());
                    sb.Append("</VATAmount><Amount>");
                    sb.Append(dr[Amount].ToString().Trim());
                    sb.Append("</Amount><AmountInWords>");
                    Int64  tongtien;
                    string tienBangChu = "";
                    if (Int64.TryParse(dr[Amount].ToString().Trim(), out tongtien))
                    {
                        tienBangChu = NumberToLeter.DocTienBangChu(tongtien);
                    }
                    sb.Append(tienBangChu);
                    sb.Append("</AmountInWords>");
                    if (dr.Table.Columns.Contains(ArisingDate))
                    {
                        sb.AppendFormat("<ArisingDate>{0}</ArisingDate>", dr[ArisingDate].ToString().Trim());
                    }
                    sb.Append("<GrossValue>");
                    sb.Append(dr[GrossValue].ToString().Trim());
                    sb.Append("</GrossValue><GrossValue0>");
                    sb.Append(dr[GrossValue0].ToString().Trim());
                    sb.Append("</GrossValue0><VatAmount0>0</VatAmount0><GrossValue5>");
                    sb.Append(dr[GrossValue5].ToString().Trim());
                    sb.Append("</GrossValue5><VatAmount5>");
                    sb.Append(dr[VatAmount5].ToString().Trim());
                    sb.Append("</VatAmount5><GrossValue10>");
                    sb.Append(dr[GrossValue10].ToString().Trim());
                    sb.Append("</GrossValue10><VatAmount10>");
                    sb.Append(dr[VatAmount10].ToString().Trim());
                    sb.Append("</VatAmount10>");

                    sb.Append("</Invoice></Inv>");
                    rv.AppendLine(sb.ToString());
                    i = j;
                }
            }
            catch (Exception ex)
            {
                log.Error("ParseIInvoice " + ex);
                message = ex.ToString();
                return(null);
            }
            if (failtCount != 0)
            {
                message = Failed.ToString();
            }
            rv.Append("</Invoices>");
            return(rv.ToString());
        }
예제 #3
0
        private static string makeStringInvoice(VNSUploadData invoices, out string ErrorMessage)
        {
            ErrorMessage = "";
            try
            {
                StringBuilder sbInvoice = new StringBuilder("<Invoice>");
                sbInvoice.AppendFormat("<InvType>{0}</InvType>", invoices.InvType);
                sbInvoice.AppendFormat("<FileName>{0}</FileName>", convertSpecialCharacter(invoices.FileName));
                sbInvoice.AppendFormat("<RefFkey>{0}</RefFkey>", invoices.RefFkey);
                sbInvoice.AppendFormat("<Description>{0}</Description>", convertSpecialCharacter(invoices.Description));
                sbInvoice.AppendFormat("<InvNo>{0}</InvNo>", invoices.InvNo);
                sbInvoice.AppendFormat("<InvPattern>{0}</InvPattern>", invoices.InvPattern);
                sbInvoice.AppendFormat("<InvSerial>{0}</InvSerial>", invoices.InvSeries);
                sbInvoice.AppendFormat("<CusCode>{0}</CusCode>", invoices.SLAcount ?? invoices.CusCode);
                sbInvoice.AppendFormat("<CusName>{0}</CusName>", invoices.CusName);
                sbInvoice.AppendFormat("<Buyer>{0}</Buyer>", convertSpecialCharacter(invoices.Buyer));
                sbInvoice.AppendFormat("<CusAddress>{0}</CusAddress>", convertSpecialCharacter(invoices.CusAddress));
                sbInvoice.AppendFormat("<CusEmail>{0}</CusEmail>", convertSpecialCharacter(invoices.CusEmail));
                sbInvoice.AppendFormat("<CusTaxCode>{0}</CusTaxCode>", convertSpecialCharacter(invoices.CusTaxCode));
                sbInvoice.AppendFormat("<OrderNo>{0}</OrderNo>", convertSpecialCharacter(invoices.OrderNo));
                sbInvoice.AppendFormat("<DeliveryNumber>{0}</DeliveryNumber>", convertSpecialCharacter(invoices.DeliveryNumber));
                sbInvoice.AppendFormat("<DeliveryDate>{0}</DeliveryDate>", invoices.DeliveryDate);
                sbInvoice.AppendFormat("<DeliveryPlace>{0}</DeliveryPlace>", convertSpecialCharacter(invoices.DeliveryPlace));
                sbInvoice.AppendFormat("<PaymentMethod>{0}</PaymentMethod>", invoices.PaymentMethod);
                sbInvoice.AppendFormat("<Model>{0}</Model>", convertSpecialCharacter(invoices.Model));
                sbInvoice.AppendFormat("<CarType>{0}</CarType>", convertSpecialCharacter(invoices.CarType));
                sbInvoice.AppendFormat("<Color>{0}</Color>", invoices.Color);
                sbInvoice.AppendFormat("<Inclusive>{0}</Inclusive>", convertSpecialCharacter(invoices.Inclusive));
                sbInvoice.AppendFormat("<Upholstery>{0}</Upholstery>", convertSpecialCharacter(invoices.Upholstery));
                sbInvoice.AppendFormat("<ChassisNumber>{0}</ChassisNumber>", convertSpecialCharacter(invoices.ChassisNumber));
                sbInvoice.AppendFormat("<EngineNumber>{0}</EngineNumber>", convertSpecialCharacter(invoices.EngineNumber));
                sbInvoice.AppendFormat("<ProductionYear>{0}</ProductionYear>", invoices.ProductionYear);
                sbInvoice.AppendFormat("<RONo>{0}</RONo>", convertSpecialCharacter(invoices.RONo));
                sbInvoice.AppendFormat("<RODate>{0}</RODate>", invoices.RODate);
                sbInvoice.AppendFormat("<RegNo>{0}</RegNo>", convertSpecialCharacter(invoices.RegNo));
                sbInvoice.AppendFormat("<ReceivedTime>{0}</ReceivedTime>", convertSpecialCharacter(invoices.ReceivedTime));
                sbInvoice.AppendFormat("<ReceivedDate>{0}</ReceivedDate>", invoices.ReceivedDate);
                sbInvoice.AppendFormat("<KmNo>{0}</KmNo>", invoices.KmNo);
                sbInvoice.AppendFormat("<BroughtBy>{0}</BroughtBy>", convertSpecialCharacter(invoices.BroughtBy));
                sbInvoice.AppendFormat("<RegDate>{0}</RegDate>", invoices.RegDate);
                sbInvoice.AppendFormat("<ServiceDate>{0}</ServiceDate>", invoices.ServiceDate);
                sbInvoice.AppendFormat("<ReceivedBy>{0}</ReceivedBy>", invoices.ReceivedBy);
                sbInvoice.AppendFormat("<DeadlineTime>{0}</DeadlineTime>", invoices.DeadlineTime);
                sbInvoice.AppendFormat("<DeadlineDate>{0}</DeadlineDate>", invoices.DeadlineDate);

                sbInvoice.Append(makeStringProducts(invoices.Details));
                sbInvoice.AppendFormat("<ArisingDate>{0}</ArisingDate>", invoices.ArisingDate.ToString("dd/MM/yyyy"));
                sbInvoice.AppendFormat("<LabourCharge>{0}</LabourCharge>", invoices.LabourCharge);
                sbInvoice.AppendFormat("<Parts>{0}</Parts>", invoices.Parts);
                sbInvoice.AppendFormat("<Lubricants>{0}</Lubricants>", invoices.Lubricants);
                sbInvoice.AppendFormat("<Subcontract>{0}</Subcontract>", invoices.Subcontract);
                sbInvoice.AppendFormat("<Miscellaneous>{0}</Miscellaneous>", invoices.Miscellaneous);
                sbInvoice.AppendFormat("<ExceedInsurance>{0}</ExceedInsurance>", invoices.ExceedInsurance);
                sbInvoice.AppendFormat("<Total>{0}</Total>", invoices.TotalBeforeTax);
                sbInvoice.AppendFormat("<VATRate>{0}</VATRate>", invoices.VATRate);
                sbInvoice.AppendFormat("<VATAmount>{0}</VATAmount>", invoices.VATAmount);
                sbInvoice.AppendFormat("<Amount>{0}</Amount>", invoices.Amount);
                sbInvoice.AppendFormat("<Reason>{0}</Reason>", invoices.Reason);
                string tienbangchu   = null;
                long   amountinvoice = (long)invoices.Amount;
                tienbangchu = NumberToLeter.DocTienBangChu(amountinvoice);
                sbInvoice.AppendFormat("<AmountInWords>{0}</AmountInWords>", tienbangchu);
                sbInvoice.Append("</Invoice>");
                return(sbInvoice.ToString());
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ErrorMessage = ex.Message;
                return(null);
            }
        }