コード例 #1
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();
            }
        }
コード例 #2
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;
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
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);
        }