Esempio n. 1
0
        protected void grdSalesInvoice_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            BillItem billItem = session.GetObjectByKey <BillItem>(Guid.Parse(e.OldValues["BillItemId"].ToString()));

            if (billItem != null)
            {
                Lot lot = session.GetObjectByKey <Lot>(Guid.Parse(e.NewValues["LotId!Key"].ToString()));
                if (lot != null)
                {
                    billItem.LotId = lot;
                    billItem.Save();
                }
            }
        }
Esempio n. 2
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();
                }
            }
        }
Esempio n. 3
0
        protected void grdPurchase_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string[] p = e.Parameters.Split('|');
            switch (p[0])
            {
            case "copy":
                Guid id = Guid.Parse(p[1].ToString());

                Bill bill = session.GetObjectByKey <Bill>(id);
                if (bill != null)
                {
                    ArtifactCodeRuleBO artifactCodeRuleBO = new ArtifactCodeRuleBO();

                    Bill billCopy = new Bill(session);
                    billCopy = bill;

                    billCopy.BillId    = new Guid();
                    billCopy.RowStatus = 1;

                    billCopy.Save();

                    CriteriaOperator        filter          = new BinaryOperator("BillId", bill.BillId, BinaryOperatorType.Equal);
                    XPCollection <BillItem> collectBillItem = new XPCollection <BillItem>(session, filter);

                    foreach (BillItem bi in collectBillItem)
                    {
                        BillItem billItem = new BillItem(session);
                        billItem = bi;

                        billItem.BillId    = billCopy;
                        billItem.RowStatus = 1;

                        billItem.Save();
                    }

                    grdPurchase.JSProperties.Add("cpRefresh", billCopy.Code);
                }

                break;

            default:
                break;
            }
        }
Esempio n. 4
0
        protected void grdPurchase_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string[] p = e.Parameters.Split('|');
            switch (p[0])
            {
            case "copy":
                Guid id = Guid.Parse(p[1].ToString());

                Bill bill = session.GetObjectByKey <Bill>(id);
                if (bill != null)
                {
                    ArtifactCodeRuleBO artifactCodeRuleBO = new ArtifactCodeRuleBO();

                    Bill billCopy = new Bill(session);

                    billCopy.BillId               = new Guid();
                    billCopy.Code                 = bill.Code + "_copy";
                    billCopy.RowStatus            = 1;
                    billCopy.TargetOrganizationId = bill.TargetOrganizationId;
                    billCopy.SourceOrganizationId = bill.SourceOrganizationId;

                    CriteriaOperator filter   = new BinaryOperator("Code", billCopy.Code, BinaryOperatorType.Equal);
                    Bill             billTest = session.FindObject <Bill>(filter);

                    if (billTest == null)
                    {
                        billCopy.Save();
                    }
                    else
                    {
                        grdPurchase.JSProperties.Add("cpCopyFailed", billCopy.Code);
                        return;
                    }

                    filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal);
                    XPCollection <BillActor> collectBillActor = new XPCollection <BillActor>(session, filter);

                    foreach (BillActor ba in collectBillActor)
                    {
                        BillActor billActor = new BillActor(session);
                        billActor.BillId = billCopy;

                        billActor.BillActorId     = Guid.NewGuid();
                        billActor.BillActorTypeId = ba.BillActorTypeId;
                        billActor.OrganizationId  = ba.OrganizationId;
                        billActor.PersonId        = ba.PersonId;

                        billActor.Save();
                    }

                    filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal);
                    XPCollection <BillItem> collectBillItem = new XPCollection <BillItem>(session, filter);

                    foreach (BillItem bi in collectBillItem)
                    {
                        BillItem billItem = new BillItem(session);
                        billItem.BillId                = billCopy;
                        billItem.RowStatus             = 1;
                        billItem.BillItemId            = bi.BillItemId;
                        billItem.LotId                 = bi.LotId;
                        billItem.Price                 = bi.Price;
                        billItem.PromotionInNumber     = bi.PromotionInNumber;
                        billItem.PromotionInPercentage = bi.PromotionInPercentage;
                        billItem.Quantity              = bi.Quantity;
                        billItem.TotalPrice            = bi.TotalPrice;

                        billItem.Save();

                        filter = new BinaryOperator("BillItemId", id, BinaryOperatorType.Equal);
                        XPCollection <BillItemTax> collectBillItemTax = new XPCollection <BillItemTax>(session, filter);

                        foreach (BillItemTax bit in collectBillItemTax)
                        {
                            BillItemTax billItemTax = new BillItemTax(session);
                            billItemTax.BillItemId      = billItem;
                            billItemTax.BillItemTaxId   = Guid.NewGuid();
                            billItemTax.ItemTaxId       = bit.ItemTaxId;
                            billItemTax.TaxInNumber     = bit.TaxInNumber;
                            billItemTax.TaxInPercentage = bit.TaxInPercentage;

                            billItemTax.Save();
                        }
                    }


                    grdPurchase.JSProperties.Add("cpRefresh", billCopy.Code);
                }

                break;

            default:
                break;
            }
        }
Esempio n. 5
0
        public virtual void CreateBillItem(
            DevExpress.Xpo.Session session,
            Guid billId,
            Guid itemId,
            Guid unitId,
            double quantity,
            double price,
            double promotionInPercentage,
            string comment)
        {
            try
            {
                NAS.DAL.Invoice.Bill bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.Bill>(billId);
                if (bill == null)
                {
                    throw new Exception("Could not found specific bill");
                }
                //Get ItemUnit
                Item item = session.GetObjectByKey <Item>(itemId);
                Unit unit = session.GetObjectByKey <Unit>(unitId);

                ItemUnit itemUnit = session.FindObject <ItemUnit>(
                    CriteriaOperator.And(
                        new BinaryOperator("ItemId", item),
                        new BinaryOperator("UnitId", unit),
                        CriteriaOperator.Or(
                            new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE),
                            new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_DEFAULT)
                            )
                        ));
                if (itemUnit == null)
                {
                    throw new Exception("Could not found item unit");
                }

                BillItem billItem = new BillItem(session)
                {
                    BillId  = bill,
                    Comment = comment,
                    //Currency
                    ItemUnitId        = itemUnit,
                    Price             = price,
                    PromotionInNumber = promotionInPercentage != -1
                        ? (price * quantity * promotionInPercentage) / 100 : 0,
                    PromotionInPercentage = promotionInPercentage,
                    Quantity   = quantity,
                    RowStatus  = Utility.Constant.ROWSTATUS_ACTIVE,
                    TotalPrice = price * quantity
                };
                billItem.Save();

                //update SumOfItemPrice
                bill.SumOfItemPrice = bill.BillItems.Sum(r => r.TotalPrice);
                bill.Save();

                if (bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_ITEMS))
                {
                    UpdatePromotionOnItems(session, billId);
                }

                //Insert into BillItemTax...
                //Get VAT TaxType of Item
                ItemBO  itemBO  = new ItemBO();
                ItemTax itemTax = itemBO.GetCurrentVATOfItem(session, itemId);

                if (itemTax != null)
                {
                    BillItemTax billItemTax = new BillItemTax(session)
                    {
                        BillItemId      = billItem,
                        ItemTaxId       = itemTax,
                        TaxInNumber     = itemTax.TaxId.Amount,
                        TaxInPercentage = itemTax.TaxId.Percentage
                    };
                    billItemTax.Save();
                }

                UpdateSumOfTax(session, bill);

                #region Update bill Total
                bill.Total = bill.SumOfItemPrice - bill.SumOfPromotion + bill.SumOfTax;
                bill.Save();
                #endregion Update bill Total
            }
            catch (Exception ex)
            {
                throw;
            }
        }