public XPCollection <Transaction> GetTransactions(Session session, Guid billId)
        {
            try
            {
                XPCollection <Transaction> ret = null;
                //Get bill
                NAS.DAL.Invoice.PurchaseInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(billId);

                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)
                        )
                    );

                ret = new XPCollection <Transaction>(session, bill.PurchaseInvoiceTransactions, criteria);

                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public NAS.DAL.Invoice.PurchaseInvoice PurchaseInvoiceInit(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.PurchaseInvoice purchaseInvoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(BillId);

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

            purchaseInvoice.PurchasingStatus = PurchasingStatus;
            purchaseInvoice.BillId           = BillId;
            purchaseInvoice.Code             = Code;
            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);

            if (supplierOrg != null)
            {
                purchaseInvoice.SourceOrganizationId = supplierOrg;
            }

            purchaseInvoice.SourceOrganizationId = supplierOrg;

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

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

            return(purchaseInvoice);
        }
        public CustomFieldDataPreDefinitionData GetData(Guid objectCustomFieldId)
        {
            CustomFieldDataPreDefinitionData ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();

                ObjectCustomField objectCustomField = session.GetObjectByKey <ObjectCustomField>(objectCustomFieldId);

                if (objectCustomField.ObjectCustomFieldDatas != null)
                {
                    ret = new CustomFieldDataPreDefinitionData();

                    foreach (var data in objectCustomField.ObjectCustomFieldDatas)
                    {
                        PredefinitionData predefinitionData = (PredefinitionData)data.CustomFieldDataId;

                        NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice =
                            session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(predefinitionData.RefId);

                        if (purchaseInvoice != null)
                        {
                            CustomFieldDataPreDefinitionDataItem item = new CustomFieldDataPreDefinitionDataItem()
                            {
                                CustomFieldDataId = predefinitionData.CustomFieldDataId,
                                PredefinitionType = predefinitionData.PredefinitionType,
                                RefId             = predefinitionData.RefId,
                                DisplayText       = purchaseInvoice.Code
                            };
                            ret.Add(item);
                        }
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Beispiel #4
0
 protected void GridPlanningJournal_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
 {
     NAS.DAL.Invoice.PurchaseInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(BillId);
     try
     {
         if (bill.RowStatus == 4)
         {
             throw (new Exception("Phiếu đã khóa, không thể thao tác"));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #5
0
 protected override void CloneBillPromotionData(Session session, Guid billId, ref Bill ret)
 {
     NAS.DAL.Invoice.PurchaseInvoice source =
         session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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();
     }
 }
        public bool PurchaseInvoiceEditing_UpdateGUI()
        {
            popupInvoiceEditingForm.ShowOnPageLoad = true;

            NAS.BO.Invoice.PurchaseInvoiceBO purchaseInvoiceBO = new NAS.BO.Invoice.PurchaseInvoiceBO();
            NAS.DAL.Invoice.PurchaseInvoice  bill =
                (NAS.DAL.Invoice.PurchaseInvoice)purchaseInvoiceBO.GetBillById(session, BillId);
            popupInvoiceEditingForm.HeaderText = String.Format("Thông tin phiếu mua hàng - {0}", bill.Code);

            ButtonShowBookingEntries.Enabled = true;
            ButtonDeclareTax.Enabled         = true;
            ButtonPrint.Enabled = true;
            ButtonCreateInventoryCommand.Enabled = true;
            ButtonCreateVoucher.Enabled          = true;
            return(true);
        }
Beispiel #7
0
        protected override void CloneBillActorData(Session session, Guid billId, ref Bill ret)
        {
            NAS.DAL.Invoice.PurchaseInvoice source =
                session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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 #8
0
        protected override void CloneBillItemData(Session session, Guid billId, ref Bill ret)
        {
            NAS.DAL.Invoice.PurchaseInvoice source =
                session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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();
                }
            }
        }
        public bool PurchaseInvoiceLocked_UpdateGUI()
        {
            popupInvoiceEditingForm.ShowOnPageLoad = true;

            NAS.BO.Invoice.PurchaseInvoiceBO purchaseInvoiceBO = new NAS.BO.Invoice.PurchaseInvoiceBO();
            NAS.DAL.Invoice.PurchaseInvoice  bill =
                (NAS.DAL.Invoice.PurchaseInvoice)purchaseInvoiceBO.GetBillById(session, BillId);
            popupInvoiceEditingForm.HeaderText = String.Format("Thông tin phiếu mua hàng - {0}", bill.Code);

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

            txtCode.Enabled           = false;
            txtIssuedDate.Enabled     = false;
            comboOrganization.Enabled = false;
            return(true);
        }
        void Set_M_ListTransaction()
        {
            if (m_Bill != null)
            {
                saleInvoiceTransactionBO     = new SaleInvoiceTransactionBO();
                purchaseInvoiceTransactionBO = new PurchaseInvoiceTransactionBO();

                //SalesInvoice _SalesInvoice = session.GetObjectByKey<SalesInvoice>(m_Bill.BillId);

                //if (_SalesInvoice == null)
                //{
                NAS.DAL.Invoice.PurchaseInvoice _PurchaseInvoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(m_Bill.BillId);
                m_ListTransaction = purchaseInvoiceTransactionBO.GetTransactionsAndRelatedTransactions(session, m_Bill.BillId);
                //}
                //else
                //{
                //    m_ListTransaction = saleInvoiceTransactionBO.GetTransactionsAndRelatedTransactions(session, m_Bill.BillId);
                //}
            }
        }
        public XPCollection <Transaction> GetPlanningTransactionsOfBill(Session session, Guid billId)
        {
            XPCollection <Transaction> resultTransaction = null;

            try
            {
                NAS.DAL.Invoice.PurchaseInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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.PurchaseInvoiceTransactions, criteria);
            }
            catch (Exception)
            {
                throw;
            }
            return(resultTransaction);
        }
        public Guid CreatePlanningTransaction(Session session, Guid billId, DateTime _PaymentDate, string _Name, double _Amount, string _Description, Guid _CurrencyId)
        {
            PurchaseInvoiceTransaction newTransaction = new PurchaseInvoiceTransaction(session);

            if (_Amount == 0)
            {
                return(Guid.Empty);
            }
            try
            {
                AccountingBO accountingBO = new AccountingBO();
                NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(billId);
                Currency currency = session.GetObjectByKey <Currency>(_CurrencyId);

                CriteriaOperator filter  = new BinaryOperator("Code", DefaultAccountEnum.NAAN_DEFAULT.ToString(), BinaryOperatorType.Equal);
                Account          account = session.FindObject <Account>(filter);

                if (purchaseInvoice == null || currency == null || account == null)
                {
                    return(Guid.Empty);
                }

                newTransaction.IssueDate         = _PaymentDate;
                newTransaction.Code              = _Name;
                newTransaction.Amount            = _Amount;
                newTransaction.Description       = _Description;
                newTransaction.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                newTransaction.PurchaseInvoiceId = purchaseInvoice;
                newTransaction.CreateDate        = DateTime.Now;
                newTransaction.UpdateDate        = DateTime.Now;
                newTransaction.Save();

                accountingBO.CreateGeneralJournal(session, newTransaction.TransactionId, account.AccountId, Constant.PLANNING_JOURNAL, _Name, _Amount, 0, Constant.ROWSTATUS_ACTIVE, _CurrencyId);
                accountingBO.CreateGeneralJournal(session, newTransaction.TransactionId, account.AccountId, Constant.PLANNING_JOURNAL, _Name, 0, _Amount, Constant.ROWSTATUS_ACTIVE, _CurrencyId);
            }
            catch (Exception)
            {
                throw;
            }
            return(newTransaction.TransactionId);
        }
Beispiel #13
0
        public void updatePurchaseInvoice(Session session,
                                          NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice,
                                          BillPromotion billPromotionProduct,
                                          BillTax billTaxProduct,
                                          BillPromotion billPromotionService,
                                          BillTax billTaxServce
                                          )
        {
            UnitOfWork uow;

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

                uow.CommitChanges();
            }
        }
Beispiel #14
0
        public ETL_Bill ExtractPurchaseInvoice(Session session, Guid BillId)
        {
            ETL_Bill result = null;

            try
            {
                Util util = new Util();
                NAS.DAL.Invoice.PurchaseInvoice invoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(BillId);
                if (invoice == null)
                {
                    return(null);
                }
                result        = new ETL_Bill();
                result.BillId = BillId;
                if (invoice.SourceOrganizationId == null)
                {
                    result.SupplierOrgId = Guid.Empty;
                }
                else
                {
                    result.SupplierOrgId = invoice.SourceOrganizationId.OrganizationId;
                }
                result.OwnerOrgId   = util.GetXpoObjectByFieldName <Organization, string>(session, "Code", "QUASAPHARCO", DevExpress.Data.Filtering.BinaryOperatorType.Equal).OrganizationId;
                result.IssueDate    = invoice.IssuedDate;
                result.BillItemList = new List <ETL_BillItem>();
                foreach (BillItem billItem in invoice.BillItems)
                {
                    ETL_BillItem temp = new ETL_BillItem();
                    temp.Asset  = "VND";
                    temp.Amount = (billItem.Quantity * billItem.Price);
                    temp.item   = billItem.ItemId;
                    temp.unit   = billItem.UnitId;
                    result.BillItemList.Add(temp);
                }
            }
            catch (Exception)
            {
            }
            return(result);
        }
Beispiel #15
0
        protected override void CloneBillData(Session session, Guid billId, ref Bill ret)
        {
            try
            {
                NAS.DAL.Invoice.PurchaseInvoice source =
                    session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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 #16
0
        public ETL_Bill ExtractPurchaseInvoice(Session session, Guid BillId, bool ExtractFinancialTransaction, bool ExtractInventoryTransaction)
        {
            ETL_Bill result = null;

            try
            {
                result = ExtractPurchaseInvoice(session, BillId);
                if (result == null)
                {
                    return(null);
                }
                NAS.DAL.Invoice.PurchaseInvoice invoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(BillId);
                if (ExtractFinancialTransaction)
                {
                    ETLAccountingBO _ETLAccountingPeriodBO = new ETLAccountingBO();
                    result.FinancialTranSactionList = new List <ETL_Transaction>();
                    foreach (PurchaseInvoiceTransaction transaction in invoice.PurchaseInvoiceTransactions)
                    {
                        ETL_Transaction temp = _ETLAccountingPeriodBO.ExtractTransaction(session, transaction.TransactionId);
                        result.FinancialTranSactionList.Add(temp);
                    }
                }
                if (ExtractInventoryTransaction)
                {
                    ETLInventoryBO _ETLInventoryBO = new ETLInventoryBO();
                    result.InventoryTranSactionList = new List <Inventory.TempData.ETL_InventoryTransaction>();
                    foreach (PurchaseInvoiceInventoryTransaction transaction in invoice.PurchaseInvoiceInventoryTransactions)
                    {
                        ETL_InventoryTransaction temp = _ETLInventoryBO.ExtractInventoryTransaction(session, transaction.InventoryTransactionId);
                        result.InventoryTranSactionList.Add(temp);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(result);
        }
Beispiel #17
0
 protected void GridDeliveryPlanning_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
 {
     NAS.DAL.Invoice.PurchaseInvoice bill = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(BillId);
     try
     {
         InventoryTransactionBO purchaseInvoiceTransactionBO = new InventoryTransactionBO();
         if (bill.RowStatus == 4)
         {
             throw (new Exception("Phiếu đã khóa, không thể thao tác"));
         }
         else
         {
             purchaseInvoiceTransactionBO.DeleteInventoryTransaction(session, Guid.Parse(e.Keys["InventoryTransactionId"].ToString()));
         }
         e.Cancel = true;
         GridDeliveryPlanning.DataSource = purchaseInvoiceTransactionBO.GetDeliveryPlanningForBill <NAS.DAL.Invoice.PurchaseInvoice>(session, BillId);
         GridDeliveryPlanning.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #18
0
 public override Bill InitTemporary(DevExpress.Xpo.Session session, BillTypeEnum billType)
 {
     try
     {
         NAS.DAL.Invoice.PurchaseInvoice ret = null;
         ret = new DAL.Invoice.PurchaseInvoice(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 #19
0
 public void insertPurchaseInvoice(Session session, NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice)
 {
     purchaseInvoice.Save();
 }
Beispiel #20
0
        /////////////////////////////////////////////////

        public Guid insertEmptyPurchaseInvoice(Session session)
        {
            NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice = new NAS.DAL.Invoice.PurchaseInvoice(session);

            purchaseInvoice.BillId           = Guid.NewGuid();
            purchaseInvoice.RowStatus        = -1;
            purchaseInvoice.PurchasingStatus = "PO";
            purchaseInvoice.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          = purchaseInvoice;
                billActor.BillActorTypeId = billActorType;
                billActor.Save();
            }

            return(purchaseInvoice.BillId);
        }
Beispiel #21
0
        public override bool Delete(DevExpress.Xpo.Session session, Guid billId)
        {
            try
            {
                //Get bill
                NAS.DAL.Invoice.PurchaseInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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.PurchaseInvoiceTransactions.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.PurchaseInvoiceTransactions.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.PurchaseInvoiceInventoryTransactions.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.PurchaseInvoiceInventoryTransactions.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 #22
0
 public override Bill GetBillById(DevExpress.Xpo.Session session, Guid billId)
 {
     NAS.DAL.Invoice.PurchaseInvoice bill =
         session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(billId, true);
     return(bill);
 }
Beispiel #23
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.PurchaseInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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 actualPurchaseInvoiceTransactions = bill.PurchaseInvoiceTransactions;

                actualPurchaseInvoiceTransactions.Criteria = criteria;

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

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

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

                    transactionObject.Save();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }