Exemplo n.º 1
0
        public void InitializationPage(XMInvoiceInfo Info)
        {
            this.ddlInvoiceType.SelectedValue = Info.InvoiceType.ToString();
            if (Type == 0)
            {
                this.txtInvoiceNo.Text = Info.InvoiceNo;
            }
            this.txtOrderCode.Text     = Info.OrderCode;
            this.txtInvoiceHeader.Text = Info.InvoiceHeader;
            if (Info.InvoiceType == 720 || (Info.DutyParagraph != null && Info.DutyParagraph != ""))//增值税专用发票
            {
                this.txtDutyParagraph.Visible = true;
                this.txtAddress.Visible       = true;
                this.txtTel.Visible           = true;
                this.txtBankAccount.Visible   = true;
                this.txtAccountNumber.Visible = true;
                this.txtDutyParagraph.Text    = Info.DutyParagraph;
                this.txtAddress.Text          = Info.Address;
                this.txtTel.Text           = Info.Tel;
                this.txtBankAccount.Text   = Info.BankAccount;
                this.txtAccountNumber.Text = Info.AccountNumber;
            }
            else
            {
                this.txtDutyParagraph.Visible = false;
                this.txtAddress.Visible       = false;
                this.txtTel.Visible           = false;
                this.txtBankAccount.Visible   = false;
                this.txtAccountNumber.Visible = false;

                this.txtDutyParagraph.Text = "";
                this.txtAddress.Text       = "";
                this.txtTel.Text           = "";
                this.txtBankAccount.Text   = "";
                this.txtAccountNumber.Text = "";
            }
            if (Info.InvoiceType != 720 && Info.DutyParagraph != "" && Info.DutyParagraph != null)
            {
                this.chkcom.Checked = true;
            }
            this.txtOrderCode.Enabled = false;
            if (Info.IsInvoiceOpen != null && (bool)Info.IsInvoiceOpen)
            {
                btnSave.Visible = false;
            }
            else
            {
                btnSave.Visible = true;
            }
        }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                int    InvoiceType   = int.Parse(this.ddlInvoiceType.SelectedValue);
                string InvoiceNo     = this.txtInvoiceNo.Text.Trim();
                string OrderCode     = this.txtOrderCode.Text.Trim();
                string InvoiceHeader = this.txtInvoiceHeader.Text.Trim();
                string DutyParagraph = this.txtDutyParagraph.Text.Trim();
                string Address       = this.txtAddress.Text.Trim();
                string Tel           = this.txtTel.Text.Trim();
                string BankAccount   = this.txtBankAccount.Text.Trim();
                string AccountNumber = this.txtAccountNumber.Text.Trim();

                if (InvoiceType == -1)
                {
                    base.ShowMessage("请选择发票类型!");
                    return;
                }

                if (OrderCode == "")
                {
                    base.ShowMessage("订单号不能为空!");
                    return;
                }

                if (InvoiceHeader == "")
                {
                    base.ShowMessage("发票抬头不能为空!");
                    return;
                }

                if (InvoiceType == 720 || chkcom.Checked)//增值税专用发票或公司普票
                {
                    if (DutyParagraph == "" || Address == "" || Tel == "" || BankAccount == "" || AccountNumber == "")
                    {
                        base.ShowMessage("请先填写发票必须数据!");
                        return;
                    }
                }

                if (Id != 0)
                {
                    var Info = base.XMInvoiceInfoService.GetXMInvoiceInfoByID(Id);
                    if (Info != null)
                    {
                        var list = base.XMInvoiceInfoDetailService.GetXMInvoiceInfoDetailListByInvoiceInfoID(Id);
                        if (list == null || list.Count == 0)
                        {
                            base.ShowMessage("产品明细至少必须有一条记录!");
                            return;
                        }

                        Info.InvoiceType = InvoiceType;
                        //Info.InvoiceNo = InvoiceNo;
                        Info.OrderCode     = OrderCode;
                        Info.InvoiceHeader = InvoiceHeader;
                        if (InvoiceType == 720 || chkcom.Checked)//增值税专用发票或者公司普票
                        {
                            Info.DutyParagraph = DutyParagraph;
                            Info.Address       = Address;
                            Info.Tel           = Tel;
                            Info.BankAccount   = BankAccount;
                            Info.AccountNumber = AccountNumber;
                        }
                        Info.UpdateID   = HozestERPContext.Current.User.CustomerID;
                        Info.UpdateDate = DateTime.Now;
                        base.XMInvoiceInfoService.UpdateXMInvoiceInfo(Info);
                    }
                }
                else
                {
                    decimal total = 0;
                    List <XMInvoiceInfo>       InvoiceInfoList = new List <XMInvoiceInfo>();
                    List <XMInvoiceInfoDetail> DetailList      = ((List <XMInvoiceInfoDetail>)Session["InvoiceInfoDetailList"]);
                    if (DetailList == null || DetailList.Count == 0)
                    {
                        base.ShowMessage("产品明细至少必须有一条记录!");
                        return;
                    }

                    var OrderInfo = base.XMOrderInfoService.GetXMOrderInfoByOrderCode(OrderCode);
                    if (OrderInfo != null)
                    {
                        //该订单数据库表中已存在的数据
                        var detaillist = base.XMInvoiceInfoDetailService.GetXMInvoiceInfoDetailListByOrderCode(OrderCode);
                        total = (decimal)detaillist.Sum(x => x.Amount);
                    }
                    //新增的发票明细数据
                    total += (decimal)DetailList.Sum(x => x.Amount);

                    XMInvoiceInfo Info = new XMInvoiceInfo();
                    Info.InvoiceType   = InvoiceType;
                    Info.InvoiceNo     = GetInvoiceNo();
                    Info.OrderCode     = OrderCode;
                    Info.InvoiceHeader = InvoiceHeader;
                    if (InvoiceType == 720 || chkcom.Checked)//增值税专用发票或者公司普票
                    {
                        Info.DutyParagraph = DutyParagraph;
                        Info.Address       = Address;
                        Info.Tel           = Tel;
                        Info.BankAccount   = BankAccount;
                        Info.AccountNumber = AccountNumber;
                    }
                    var list = base.CodeService.GetCodeListInfoByCodeTypeID(233);
                    if (list.Count > 0)
                    {
                        foreach (var a in list)
                        {
                            if (a.CodeName.IndexOf("新开") != -1 && Type == 0)
                            {
                                Info.InvoiceStatus = a.CodeID;
                                break;
                            }
                            if (a.CodeName.IndexOf("补开") != -1 && Type == 1)
                            {
                                Info.InvoiceStatus = a.CodeID;
                                break;
                            }
                            if (a.CodeName.IndexOf("重开") != -1 && Type == 2)
                            {
                                Info.InvoiceStatus = a.CodeID;
                                break;
                            }
                        }
                    }

                    if (Type == 1 && Session["SupplementID"] != null)
                    {
                        Info.RelationID = Session["SupplementID"].ToString();
                    }
                    if (Type == 2 && Session["ResumeIDs"] != null)
                    {
                        string[] arr = (string[])Session["ResumeIDs"];
                        foreach (var a in arr)
                        {
                            if (string.IsNullOrEmpty(Info.RelationID))
                            {
                                Info.RelationID = a;
                            }
                            else
                            {
                                Info.RelationID += "," + a;
                            }

                            var item = base.XMInvoiceInfoService.GetXMInvoiceInfoByID(int.Parse(a));
                            if (item != null)
                            {
                                //数据库表中重写的数据
                                total -= (decimal)item.XM_InvoiceInfoDetail.Sum(x => x.Amount);
                                InvoiceInfoList.Add(item);
                            }
                        }
                    }

                    Info.IsSingleRow = false;
                    Info.IsScrap     = false;
                    Info.IsEnable    = false;
                    Info.CreateID    = HozestERPContext.Current.User.CustomerID;
                    Info.CreateDate  = DateTime.Now;
                    Info.UpdateID    = HozestERPContext.Current.User.CustomerID;
                    Info.UpdateDate  = DateTime.Now;

                    if (total > OrderInfo.PayPrice)
                    {
                        base.ShowMessage("该订单发票总金额不能大于订单支付金额!");
                        return;
                    }

                    //重写的发货单,废弃
                    foreach (var item in InvoiceInfoList)
                    {
                        item.IsScrap    = true;
                        item.UpdateID   = HozestERPContext.Current.User.CustomerID;
                        item.UpdateDate = DateTime.Now;
                        base.XMInvoiceInfoService.UpdateXMInvoiceInfo(item);
                    }

                    Info.XM_InvoiceInfoDetail = new List <XMInvoiceInfoDetail>();
                    foreach (var a in DetailList)
                    {
                        a.InvoiceInfoID = Info.ID;
                        Info.XM_InvoiceInfoDetail.Add(a);
                    }
                    base.XMInvoiceInfoService.InsertXMInvoiceInfo(Info);
                    var orderinfo = base.XMOrderInfoAPIService.GetXMOrderInfoByOrderCode(OrderCode);
                    if (orderinfo != null)
                    {
                        orderinfo.IsInvoiced = true;//订单信息里是否开票改成true
                        base.XMOrderInfoService.UpdateXMOrderInfo(orderinfo);
                    }
                }

                base.ShowMessage("保存成功!");
            }
            catch (Exception err)
            {
                this.ProcessException(err);
            }
        }