Beispiel #1
0
        public dynamic UpdateDetail(PurchaseOrderDetail model)
        {
            try
            {
                var data = _purchaseOrderDetailService.GetObjectById(model.Id);
                data.ItemId   = model.ItemId;
                data.Quantity = model.Quantity;
                data.Price    = model.Price;
                model         = _purchaseOrderDetailService.UpdateObject(data, _purchaseOrderService, _itemService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                model.Errors.Add("Generic", "Error : " + ex);
            }

            return(Json(new
            {
                model.Errors
            }));
        }
        public dynamic UpdateDetail(PurchaseOrderDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.PurchaseOrder, Core.Constants.Constant.MenuGroupName.Transaction))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _purchaseOrderDetailService.GetObjectById(model.Id);
                data.ItemId   = model.ItemId;
                data.Quantity = model.Quantity;
                data.Price    = model.Price;
                model         = _purchaseOrderDetailService.UpdateObject(data, _purchaseOrderService, _itemService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Beispiel #3
0
        void po_validation()
        {
            it["prepares_valid_data"] = () =>
            {
                item1.Errors.Count().should_be(0);
                item2.Errors.Count().should_be(0);
                contact.Errors.Count().should_be(0);
            };

            it["creates_po"] = () =>
            {
                newPO = new PurchaseOrder
                {
                    ContactId    = contact.Id,
                    PurchaseDate = DateTime.Now
                };
                newPO = poService.CreateObject(newPO, contactService);
                newPO.Errors.Count().should_be(0);
                poService.GetObjectById(newPO.Id).should_not_be_null();
            };

            context["when creating PO Detail"] = () =>
            {
                before = () =>
                {
                    newPO = new PurchaseOrder
                    {
                        ContactId    = contact.Id,
                        PurchaseDate = DateTime.Now
                    };
                    newPO = poService.CreateObject(newPO, contactService);
                };

                it["creates po detail"] = () =>
                {
                    PurchaseOrderDetail poDetail = new PurchaseOrderDetail
                    {
                        PurchaseOrderId = newPO.Id,
                        ItemId          = item1.Id,
                        Quantity        = 5,
                        Price           = 30000
                    };
                    poDetail = poDetailService.CreateObject(poDetail, poService, itemService);
                    poDetail.Errors.Count().should_be(0);
                };

                it["must not allow PO confirmation if there is no PO Detail"] = () =>
                {
                    newPO = poService.ConfirmObject(newPO, DateTime.Today, poDetailService, _stockMutationService, itemService, _barringService, _warehouseItemService);
                    newPO.Errors.Count().should_not_be(0);
                };

                it["should not create po detail if there is no item id"] = () =>
                {
                    PurchaseOrderDetail poDetail = new PurchaseOrderDetail
                    {
                        PurchaseOrderId = newPO.Id,
                        ItemId          = 0,
                        Quantity        = 5,
                        Price           = 25000
                    };
                    poDetail = poDetailService.CreateObject(poDetail, poService, itemService);
                    poDetail.Errors.Count().should_not_be(0);
                };

                context["when creating PO Detail"] = () =>
                {
                    before = () =>
                    {
                        poDetail1 = new PurchaseOrderDetail
                        {
                            PurchaseOrderId = newPO.Id,
                            ItemId          = item1.Id,
                            Quantity        = 5,
                            Price           = 30000
                        };
                        poDetail1 = poDetailService.CreateObject(poDetail1, poService, itemService);
                    };

                    it["should be valid when creating PO Detail 1"] = () =>
                    {
                        poDetail1.Errors.Count.should_be(0);
                    };

                    it["should not be valid when creating PO Detail 2 with the same item"] = () =>
                    {
                        poDetail2 = new PurchaseOrderDetail
                        {
                            PurchaseOrderId = newPO.Id,
                            ItemId          = item1.Id,
                            Quantity        = 5,
                            Price           = 2500000
                        };
                        poDetail2 = poDetailService.CreateObject(poDetail2, poService, itemService);
                        poDetail2.Errors.Count().should_not_be(0);
                    };

                    context["should not be valid when creating PO Detail 2 with the same item"] = () =>
                    {
                        before = () =>
                        {
                            poDetail2 = new PurchaseOrderDetail
                            {
                                PurchaseOrderId = newPO.Id,
                                ItemId          = item2.Id,
                                Quantity        = 5,
                                Price           = 2500000
                            };
                            poDetail2 = poDetailService.CreateObject(poDetail2, poService, itemService);
                        };

                        it["should be valid when creating a new PO Detail 2"] = () =>
                        {
                            poDetail2.Errors.Count().should_be(0);
                        };

                        it["should not be valid when updating PO Detail 2 item to the same item as POD1"] = () =>
                        {
                            poDetail2.ItemId = item1.Id;
                            poDetailService.UpdateObject(poDetail2, poService, itemService);
                            poDetail2.Errors.Count().should_not_be(0);
                        };
                    };
                };
            };

            context["when confirming PO"] = () =>
            {
                before = () =>
                {
                    newPO = new PurchaseOrder
                    {
                        ContactId    = contact.Id,
                        PurchaseDate = DateTime.Now
                    };
                    newPO = poService.CreateObject(newPO, contactService);

                    poDetail1 = new PurchaseOrderDetail
                    {
                        PurchaseOrderId = newPO.Id,
                        ItemId          = item1.Id,
                        Quantity        = 5,
                        Price           = 30000
                    };
                    poDetail1 = poDetailService.CreateObject(poDetail1, poService, itemService);

                    poDetail2 = new PurchaseOrderDetail
                    {
                        PurchaseOrderId = newPO.Id,
                        ItemId          = item2.Id,
                        Quantity        = 5,
                        Price           = 25000
                    };
                    poDetail2 = poDetailService.CreateObject(poDetail2, poService, itemService);
                };

                it["allows confirmation"] = () =>
                {
                    newPO = poService.ConfirmObject(newPO, DateTime.Today, poDetailService, _stockMutationService, itemService, _barringService, _warehouseItemService);
                    newPO.IsConfirmed.should_be(true);
                };

                context["post PO confirm"] = () =>
                {
                    before = () =>
                    {
                        item1     = itemService.GetObjectById(item1.Id);
                        item2     = itemService.GetObjectById(item2.Id);
                        Quantity1 = item1.PendingReceival;
                        Quantity2 = item2.PendingReceival;

                        newPO = poService.ConfirmObject(newPO, DateTime.Today, poDetailService, _stockMutationService, itemService, _barringService, _warehouseItemService);
                    };

                    it["should increase pending receival in item"] = () =>
                    {
                        int diff_1 = item1.PendingReceival - Quantity1;
                        diff_1.should_be(poDetail1.Quantity);

                        int diff_2 = item2.PendingReceival - Quantity2;
                        diff_2.should_be(poDetail2.Quantity);
                    };

                    it["should create StockMutation"] = () =>
                    {
                        _stockMutationService.GetObjectsBySourceDocumentDetailForItem(item1.Id, Core.Constants.Constant.SourceDocumentDetailType.PurchaseOrderDetail, poDetail1.Id).Count().should_be(1);
                        _stockMutationService.GetObjectsBySourceDocumentDetailForItem(item2.Id, Core.Constants.Constant.SourceDocumentDetailType.PurchaseOrderDetail, poDetail2.Id).Count().should_be(1);
                    };
                };
            };
        }