Beispiel #1
0
        public NAS.DAL.Invoice.SalesInvoice SaleInvoiceInit(Session session,
                                                            Guid BillId,
                                                            string PurchasingStatus,
                                                            string Code,
                                                            DateTime CreateDate,
                                                            DateTime IssueDate,
                                                            double SumOfItemPrice,
                                                            double SumOfPromotion,
                                                            double SumOfTax,
                                                            double Total,
                                                            short RowStatus,
                                                            string SourceOrganizationId,
                                                            string TargetOrganizationId,
                                                            Guid BillTypeId
                                                            )
        {
            NAS.DAL.Invoice.SalesInvoice purchaseInvoice = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(BillId);

            if (purchaseInvoice == null)
            {
                purchaseInvoice = new DAL.Invoice.SalesInvoice(session);
            }

            purchaseInvoice.SaleInvoiceStatus = PurchasingStatus;
            purchaseInvoice.BillId            = BillId;
            purchaseInvoice.Code           = Code;
            purchaseInvoice.RowStatus      = Constant.ROWSTATUS_ACTIVE;
            purchaseInvoice.CreateDate     = CreateDate;
            purchaseInvoice.IssuedDate     = IssueDate;
            purchaseInvoice.SumOfItemPrice = SumOfItemPrice;
            purchaseInvoice.SumOfPromotion = SumOfPromotion;
            purchaseInvoice.SumOfTax       = SumOfTax;
            purchaseInvoice.Total          = Total;
            purchaseInvoice.RowStatus      = RowStatus;

            CriteriaOperator filter      = new BinaryOperator("Code", SourceOrganizationId, BinaryOperatorType.Equal);
            Organization     supplierOrg = session.FindObject <Organization>(filter);

            purchaseInvoice.SourceOrganizationId = supplierOrg;

            filter = new BinaryOperator("Code", TargetOrganizationId, BinaryOperatorType.Equal);
            Person person = session.FindObject <Person>(filter);

            if (person != null)
            {
                purchaseInvoice.TargetOrganizationId = person;
            }

            return(purchaseInvoice);
        }
Beispiel #2
0
 protected void GridDeliveryPlanning_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
 {
     NAS.DAL.Invoice.SalesInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(BillId);
     try
     {
         if (bill.RowStatus == 4)
         {
             throw (new Exception("Phiếu đã khóa, không thể thao tác"));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #3
0
        public bool SalesInvoiceEditing_UpdateGUI()
        {
            popupInvoiceEditingForm.ShowOnPageLoad = true;

            NAS.BO.Invoice.SalesInvoiceBO salesInvoiceBO = new NAS.BO.Invoice.SalesInvoiceBO();
            NAS.DAL.Invoice.SalesInvoice  bill           =
                (NAS.DAL.Invoice.SalesInvoice)salesInvoiceBO.GetBillById(session, BillId);
            popupInvoiceEditingForm.HeaderText = String.Format("Thông tin phiếu bán hàng - {0}", bill.Code);

            ButtonShowBookingEntries.Enabled = true;
            ButtonDeclareTax.Enabled         = true;
            ButtonPrint.Enabled = true;
            ButtonCreateInventoryCommand.Enabled = true;
            ButtonCreateVoucher.Enabled          = true;
            return(true);
        }
Beispiel #4
0
 protected override void CloneBillPromotionData(Session session, Guid billId, ref Bill ret)
 {
     NAS.DAL.Invoice.SalesInvoice source =
         session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);
     foreach (var sourceBillPromotion in source.BillPromotions)
     {
         BillPromotion billPromotion = new BillPromotion(session)
         {
             BillId                = ret,
             PromotionInNumber     = sourceBillPromotion.PromotionInNumber,
             PromotionInPercentage = sourceBillPromotion.PromotionInPercentage,
             PromotionTypeId       = sourceBillPromotion.PromotionTypeId
         };
         billPromotion.Save();
     }
 }
Beispiel #5
0
 protected void GridPlanningJournal_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
 {
     //NAS.DAL.Invoice.PurchaseInvoice bill = session.GetObjectByKey<NAS.DAL.Invoice.PurchaseInvoice>(BillId);
     NAS.DAL.Invoice.SalesInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(BillId);
     try
     {
         if (bill.RowStatus == 4)
         {
             throw (new Exception("Phiếu đã khóa, không thể thao tác"));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #6
0
        protected override void CloneBillActorData(Session session, Guid billId, ref Bill ret)
        {
            NAS.DAL.Invoice.SalesInvoice source =
                session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);

            foreach (var sourceBillActor in source.BillActors)
            {
                BillActor billActor = new BillActor(session)
                {
                    BillActorTypeId = sourceBillActor.BillActorTypeId,
                    BillId          = ret,
                    OrganizationId  = sourceBillActor.OrganizationId,
                    PersonId        = sourceBillActor.PersonId
                };
                billActor.Save();
            }
        }
Beispiel #7
0
        public bool SalesInvoiceLocked_UpdateGUI()
        {
            popupInvoiceEditingForm.ShowOnPageLoad = true;

            NAS.BO.Invoice.SalesInvoiceBO salesInvoiceBO = new NAS.BO.Invoice.SalesInvoiceBO();
            NAS.DAL.Invoice.SalesInvoice  bill           =
                (NAS.DAL.Invoice.SalesInvoice)salesInvoiceBO.GetBillById(session, BillId);
            popupInvoiceEditingForm.HeaderText = String.Format("Thông tin phiếu bán hàng - {0}", bill.Code);

            //ButtonDeclareTax.Visible = false;
            ButtonSave.Visible = false;

            txtCode.Enabled           = false;
            txtIssuedDate.Enabled     = false;
            comboOrganization.Enabled = false;
            return(true);
        }
Beispiel #8
0
        protected override void CloneBillItemData(Session session, Guid billId, ref Bill ret)
        {
            NAS.DAL.Invoice.SalesInvoice source =
                session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);

            var sourceBillItemList = source.BillItems.Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE);

            if (sourceBillItemList == null)
            {
                return;
            }

            foreach (var sourceBillItem in sourceBillItemList)
            {
                //Clone BillItem
                BillItem billItem = new BillItem(session)
                {
                    BillId                = ret,
                    Comment               = sourceBillItem.Comment,
                    Currency              = sourceBillItem.Currency,
                    ItemId                = sourceBillItem.ItemId,
                    ItemUnitId            = sourceBillItem.ItemUnitId,
                    LotId                 = sourceBillItem.LotId,
                    Price                 = sourceBillItem.Price,
                    PromotionInNumber     = sourceBillItem.PromotionInNumber,
                    PromotionInPercentage = sourceBillItem.PromotionInPercentage,
                    Quantity              = sourceBillItem.Quantity,
                    RowStatus             = sourceBillItem.RowStatus,
                    TotalPrice            = sourceBillItem.TotalPrice,
                    UnitId                = sourceBillItem.UnitId
                };
                billItem.Save();
                //Clone BillItemTax
                foreach (var sourceBillItemTax in sourceBillItem.BillItemTaxs)
                {
                    BillItemTax billItemTax = new BillItemTax(session)
                    {
                        BillItemId      = billItem,
                        ItemTaxId       = sourceBillItemTax.ItemTaxId,
                        TaxInNumber     = sourceBillItemTax.TaxInNumber,
                        TaxInPercentage = sourceBillItemTax.TaxInPercentage
                    };
                    billItemTax.Save();
                }
            }
        }
Beispiel #9
0
        public XPCollection <Transaction> GetPlanningTransactionsOfBill(Session session, Guid billId)
        {
            XPCollection <Transaction> resultTransaction = null;

            try
            {
                NAS.DAL.Invoice.SalesInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);

                CriteriaOperator criteria = CriteriaOperator.And(
                    new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual),
                    new ContainsOperator("GeneralJournals", new BinaryOperator("JournalType", JounalTypeConstant.PLANNING)));

                resultTransaction = new XPCollection <Transaction>(session, bill.SaleInvoiceTransactions, criteria);
            }
            catch (Exception)
            {
                throw;
            }
            return(resultTransaction);
        }
Beispiel #10
0
        protected override void CloneBillData(Session session, Guid billId, ref Bill ret)
        {
            try
            {
                NAS.DAL.Invoice.SalesInvoice source =
                    session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);

                ret.IssuedDate = source.IssuedDate;
                ret.PromotionCalculationType = source.PromotionCalculationType;
                ret.SourceOrganizationId     = source.SourceOrganizationId;
                ret.SumOfItemPrice           = source.SumOfItemPrice;
                ret.SumOfPromotion           = source.SumOfPromotion;
                ret.SumOfTax             = source.SumOfTax;
                ret.TargetOrganizationId = source.TargetOrganizationId;
                ret.TaxCalculationType   = source.TaxCalculationType;
                ret.Total = source.Total;
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #11
0
        public void updateSaleInvoice(Session session,
                                      NAS.DAL.Invoice.SalesInvoice salesInvoice,
                                      BillPromotion billPromotionProduct,
                                      BillTax billTaxProduct,
                                      BillPromotion billPromotionService,
                                      BillTax billTaxServce
                                      //SaleInvoiceTransaction saleInvoiceTransaction
                                      )
        {
            UnitOfWork uow;

            using (uow = XpoHelper.GetNewUnitOfWork())
            {
                salesInvoice.Save();
                billPromotionProduct.Save();
                billTaxProduct.Save();
                billPromotionService.Save();
                billTaxServce.Save();

                uow.CommitChanges();
            }
        }
Beispiel #12
0
 protected void GridDeliveryPlanning_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
 {
     NAS.DAL.Invoice.SalesInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(BillId);
     try
     {
         InventoryTransactionBO saleInvoiceTransactionBO = new InventoryTransactionBO();
         if (bill.RowStatus == 4)
         {
             throw (new Exception("Phiếu đã khóa, không thể thao tác"));
         }
         else
         {
             saleInvoiceTransactionBO.DeleteInventoryTransaction(session, Guid.Parse(e.Keys["InventoryTransactionId"].ToString()));
         }
         e.Cancel = true;
         GridDeliveryPlanning.DataSource = saleInvoiceTransactionBO.GetDeliveryPlanningForBill <NAS.DAL.Invoice.SalesInvoice>(session, BillId);
         GridDeliveryPlanning.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #13
0
 public override Bill InitTemporary(DevExpress.Xpo.Session session, BillTypeEnum billType)
 {
     try
     {
         NAS.DAL.Invoice.SalesInvoice ret = null;
         ret = new DAL.Invoice.SalesInvoice(session)
         {
             BillId                   = Guid.NewGuid(),
             RowStatus                = Utility.Constant.ROWSTATUS_TEMP,
             CreateDate               = DateTime.Now,
             IssuedDate               = DateTime.Now,
             TaxClaimStatus           = Utility.Constant.VAT_NO_DECLARE,
             TaxCalculationType       = Utility.Constant.CALCULATION_TYPE_ON_ITEMS,
             PromotionCalculationType = Utility.Constant.CALCULATION_TYPE_ON_ITEMS,
             BillType                 = (byte)billType
         };
         ret.Save();
         return(ret);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #14
0
 public override Bill GetBillById(DevExpress.Xpo.Session session, Guid billId)
 {
     NAS.DAL.Invoice.SalesInvoice bill =
         session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId, true);
     return(bill);
 }
Beispiel #15
0
        public override bool Delete(DevExpress.Xpo.Session session, Guid billId)
        {
            try
            {
                //Get bill
                NAS.DAL.Invoice.SalesInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);

                if (bill == null)
                {
                    throw new Exception("Could not found bill");
                }

                //Validate
                if (bill.RowStatus.Equals(Utility.Constant.ROWSTATUS_BOOKED_ENTRY))
                {
                    throw new Exception(String.Format("Không thể xóa vì hóa đơn '{0}' đã được ghi sổ.", bill.Code));
                }

                //Mark delete status on bill
                bill.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                bill.Save();

                var billItems = bill.BillItems.Where(r => r.RowStatus >= 0);
                //Mark delete status on bill items
                if (billItems != null)
                {
                    foreach (var item in billItems)
                    {
                        item.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                        item.Save();
                    }
                }

                var invoiceTransactions = bill.SaleInvoiceTransactions.Where(r => r.RowStatus >= 0);
                //Mark delete status on bill invoice transactions
                if (invoiceTransactions != null)
                {
                    foreach (var item in invoiceTransactions)
                    {
                        item.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                        item.Save();
                    }
                }

                var generalJournals = bill.SaleInvoiceTransactions.Where(r => r.RowStatus >= 0)
                                      .SelectMany(r => r.GeneralJournals)
                                      .Where(r => r.RowStatus >= 0);
                //Mark delete status on bill invoice general journals
                if (generalJournals != null)
                {
                    foreach (var item in generalJournals)
                    {
                        item.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                        item.Save();
                    }
                }

                var inventoryTransactions = bill.SalesInvoiceInventoryTransactions.Where(r => r.RowStatus >= 0);
                //Mark delete status on bill invoice inventory transactions
                if (inventoryTransactions != null)
                {
                    foreach (var item in inventoryTransactions)
                    {
                        item.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                        item.Save();
                    }
                }

                var inventoryJournals = bill.SalesInvoiceInventoryTransactions.Where(r => r.RowStatus >= 0)
                                        .SelectMany(r => r.InventoryJournals)
                                        .Where(r => r.RowStatus >= 0);
                //Mark delete status on bill invoice inventory journals
                if (inventoryJournals != null)
                {
                    foreach (var item in inventoryJournals)
                    {
                        item.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                        item.Save();
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #16
0
        public override bool Save(
            DevExpress.Xpo.Session session,
            Guid billId,
            string billCode,
            DateTime issuedDate,
            DAL.Nomenclature.Organization.Organization sourceOrganizationBill,
            DAL.Nomenclature.Organization.Person targetOrganizationBill)
        {
            try
            {
                //Get bill by ID
                NAS.DAL.Invoice.SalesInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);
                if (bill == null)
                {
                    throw new Exception("Could not found bill");
                }

                bill.Code                 = billCode;
                bill.IssuedDate           = issuedDate;
                bill.SourceOrganizationId = sourceOrganizationBill;
                bill.TargetOrganizationId = targetOrganizationBill;
                bill.RowStatus            = Utility.Constant.ROWSTATUS_ACTIVE;

                bill.Save();

                //Create default actual transaction
                CriteriaOperator criteria = CriteriaOperator.And(
                    new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual),
                    CriteriaOperator.Or(
                        new ContainsOperator("GeneralJournals",
                                             new BinaryOperator("JournalType", JounalTypeConstant.ACTUAL)
                                             ),
                        new BinaryOperator(new AggregateOperand("GeneralJournals", Aggregate.Count), 0, BinaryOperatorType.Equal)
                        )
                    );

                var actualSaleInvoiceTransactions = bill.SaleInvoiceTransactions;

                actualSaleInvoiceTransactions.Criteria = criteria;

                if (actualSaleInvoiceTransactions == null ||
                    actualSaleInvoiceTransactions.Count == 0)
                {
                    SaleInvoiceTransaction saleInvoiceTransaction
                        = new SaleInvoiceTransaction(session)
                        {
                        Code           = "BT_" + bill.Code,
                        CreateDate     = DateTime.Now,
                        Description    = "BT_" + bill.Code,
                        IssueDate      = issuedDate,
                        RowStatus      = Utility.Constant.ROWSTATUS_ACTIVE,
                        UpdateDate     = DateTime.Now,
                        SalesInvoiceId = bill
                        };
                    saleInvoiceTransaction.Save();

                    ObjectBO objectBO = new ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object cmsObject =
                        objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);

                    TransactionObject transactionObject = new TransactionObject(session)
                    {
                        ObjectId      = cmsObject,
                        TransactionId = saleInvoiceTransaction
                    };

                    transactionObject.Save();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #17
0
        /////////////////////////////////////////////////

        public Guid insertEmptySaleInvoice(Session session)
        {
            NAS.DAL.Invoice.SalesInvoice salesInvoice = new NAS.DAL.Invoice.SalesInvoice(session);

            salesInvoice.BillId            = Guid.NewGuid();
            salesInvoice.RowStatus         = -1;
            salesInvoice.SaleInvoiceStatus = "SO";
            salesInvoice.Save();

            XPCollection <BillActorType> collectBillActorType = new XPCollection <BillActorType>(session);

            if (collectBillActorType.Count <= 0)
            {
                BillActorType billActorType = new BillActorType(session);

                billActorType.Description = "Người lập phiếu";
                billActorType.Name        = "CREATOR";
                billActorType.RowStatus   = Constant.ROWSTATUS_ACTIVE;

                billActorType.Save();

                billActorType = new BillActorType(session);

                billActorType.Description = "Người mua hàng";
                billActorType.Name        = "BUYER";
                billActorType.RowStatus   = Constant.ROWSTATUS_ACTIVE;

                billActorType.Save();

                billActorType             = new BillActorType(session);
                billActorType.Description = "Người bán hàng";
                billActorType.Name        = "SALES";
                billActorType.RowStatus   = Constant.ROWSTATUS_ACTIVE;

                billActorType.Save();

                billActorType             = new BillActorType(session);
                billActorType.Description = "Kế toán trưởng";
                billActorType.Name        = "CHIEFACCOUNTANT";
                billActorType.RowStatus   = Constant.ROWSTATUS_ACTIVE;

                billActorType.Save();

                billActorType             = new BillActorType(session);
                billActorType.Description = "Giám đốc";
                billActorType.Name        = "DIRECTOR";
                billActorType.RowStatus   = Constant.ROWSTATUS_ACTIVE;

                billActorType.Save();
            }

            collectBillActorType = new XPCollection <BillActorType>(session);
            foreach (BillActorType billActorType in collectBillActorType)
            {
                BillActor billActor = new BillActor(session);
                billActor.BillId          = salesInvoice;
                billActor.BillActorTypeId = billActorType;
                billActor.Save();
            }

            return(salesInvoice.BillId);
        }