protected void Grid_LegalInvoiceArtifactType_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { e.Cancel = true; session.BeginTransaction(); NAS.DAL.Accounting.LegalInvoice.LegalInvoiceArtifactType artifactType = session.GetObjectByKey <NAS.DAL.Accounting.LegalInvoice.LegalInvoiceArtifactType>(Guid.Parse(e.Keys[0].ToString())); if (artifactType == null) { throw new Exception("LegalInvoiceArtifactType is not exist system"); } SaleInvoiceArtiface saleId = session.FindObject <SaleInvoiceArtiface>( CriteriaOperator.And( new BinaryOperator("LegalInvoiceArtifactTypeId", artifactType.LegalInvoiceArtifactTypeId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal) )); if (saleId == null) { artifactType.RowStatus = Utility.Constant.ROWSTATUS_DELETED; } else { throw new Exception("Đã có thông tin nên không được xóa!"); } session.CommitTransaction(); session.FlushChanges(); Grid_LegalInvoiceArtifactType.CancelEdit(); } catch (Exception) { session.RollbackTransaction(); throw; } }
protected void Grid_LegalInvoiceArtifactType_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { { string[] m = { "Code", "Name", "Category" }; for (int i = 0; i < m.Length; i++) { if (e.Column.FieldName.Equals(m[i]) && Grid_LegalInvoiceArtifactType.IsEditing && !Grid_LegalInvoiceArtifactType.IsNewRowEditing) { SaleInvoiceArtiface saleId = session.FindObject <SaleInvoiceArtiface>( CriteriaOperator.And( new BinaryOperator("LegalInvoiceArtifactTypeId", e.KeyValue.ToString(), BinaryOperatorType.Equal), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal) )); if (saleId != null) { e.Editor.ReadOnly = true; } } } } }
protected void cpDeclareVat_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { string[] para = e.Parameter.Split('|'); CriteriaOperator filter; switch (para[0]) { case "show": cboItem.Text = ""; bill = session.GetObjectByKey <Bill>(Guid.Parse(para[1])); if (bill != null) { filter = new BinaryOperator("BillId.BillId", bill.BillId, BinaryOperatorType.Equal); SaleInvoiceArtiface saleInvoiceArtiface = session.FindObject <SaleInvoiceArtiface>(filter); if (saleInvoiceArtiface != null) { cboLegalInvoiceArtifactType.Value = saleInvoiceArtiface.LegalInvoiceArtifactTypeId.LegalInvoiceArtifactTypeId; txtIssuedArtifactCode.Text = saleInvoiceArtiface.IssuedArtifaceCode; txtSeriesNumber.Text = saleInvoiceArtiface.SeriesNumber; } else { cboLegalInvoiceArtifactType.Value = null; txtIssuedArtifactCode.Text = ""; txtSeriesNumber.Text = ""; } filter = new BinaryOperator("BillId.BillId", Guid.Parse(para[1]), BinaryOperatorType.Equal); billTaxClaim = session.FindObject <BillTaxClaim>(filter); if (billTaxClaim != null) { filter = new BinaryOperator("Name", billTaxClaim.ClaimItem, BinaryOperatorType.Equal); Item item = session.FindObject <Item>(filter); if (item != null) { cboItem.Value = item.ItemId; } txtDescription.Text = billTaxClaim.Comment; } else { switch (bill.PaymentTerm) { case 1: txtDescription.Text = "Tiền mặt"; break; case 2: txtDescription.Text = "Chuyển khoản"; break; default: txtDescription.Text = ""; break; } } if (bill is SalesInvoice) { m_VatType = Constant.VAT_OUT; } else if (bill is PurchaseInvoice) { m_VatType = Constant.VAT_IN; } //Bill salesInvoice = session.GetObjectByKey<SalesInvoice>(bill.BillId); //m_VatType = Constant.VAT_OUT; //if (salesInvoice == null) //{ // m_VatType = Constant.VAT_IN; //} BindData(bill); } break; case "declare": filter = new BinaryOperator("BillId", Guid.Parse(para[1]), BinaryOperatorType.Equal); bill = session.GetObjectByKey <Bill>(Guid.Parse(para[1])); if (bill != null) { filter = new BinaryOperator("BillId.BillId", Guid.Parse(para[1]), BinaryOperatorType.Equal); billTaxClaim = session.FindObject <BillTaxClaim>(filter); if (billTaxClaim == null) { billTaxClaim = new BillTaxClaim(session); billTaxClaim.BillId = bill; billTaxClaim.CreateDate = bill.IssuedDate; billTaxClaim.RowStatus = 1; bill.TaxClaimStatus = Constant.VAT_YES_DECLARE; } billTaxClaim.ClaimItem = cboItem.Text; var taxPercentageList = BillBOBase.GetDistinctTaxPercentageList(bill.BillId); if (taxPercentageList == null || taxPercentageList.Count() == 0) { billTaxClaim.TaxInPercentage = 0; } else { billTaxClaim.TaxInPercentage = taxPercentageList.First().Percentage; } //billTaxClaim.TaxInPercentage = bill.BillItems[0].BillItemTaxs[0].TaxInPercentage; billTaxClaim.Amount = bill.SumOfItemPrice - bill.SumOfPromotion; //billTaxClaim.TaxInNumber = billTaxClaim.Amount * billTaxClaim.TaxInPercentage / 100; billTaxClaim.TaxInNumber = bill.SumOfTax; billTaxClaim.Comment = txtDescription.Text; billTaxClaim.LastUpdateDate = DateTime.Now; billTaxClaim.CreateDate = bill.IssuedDate; billTaxClaim.Save(); filter = new BinaryOperator("BillId.BillId", bill.BillId, BinaryOperatorType.Equal); SaleInvoiceArtiface saleInvoiceArtiface = session.FindObject <SaleInvoiceArtiface>(filter); if (saleInvoiceArtiface == null) { saleInvoiceArtiface = new SaleInvoiceArtiface(session); saleInvoiceArtiface.SaleInvoiceArtifaceId = Guid.NewGuid(); saleInvoiceArtiface.RowStatus = 1; saleInvoiceArtiface.BillId = bill; } NAS.DAL.Accounting.LegalInvoice.LegalInvoiceArtifactType legalInvoiceArtifactType = session.GetObjectByKey <NAS.DAL.Accounting.LegalInvoice.LegalInvoiceArtifactType>(Guid.Parse(cboLegalInvoiceArtifactType.Value.ToString())); if (legalInvoiceArtifactType != null) { saleInvoiceArtiface.LegalInvoiceArtifactTypeId = legalInvoiceArtifactType; } saleInvoiceArtiface.SeriesNumber = txtSeriesNumber.Text; saleInvoiceArtiface.IssuedArtifaceCode = txtIssuedArtifactCode.Text; saleInvoiceArtiface.Save(); //SalesInvoice salesInvoice = session.GetObjectByKey<SalesInvoice>(bill.BillId); //m_VatType = Constant.VAT_OUT; //if (salesInvoice == null) //{ // m_VatType = Constant.VAT_IN; //} if (bill is SalesInvoice) { m_VatType = Constant.VAT_OUT; } else if (bill is PurchaseInvoice) { m_VatType = Constant.VAT_IN; } BindData(bill); cpDeclareVat.JSProperties.Add("cpDisableAccept", "Disable"); } break; } }