Пример #1
0
        public async Task <ActionResult <AdjustmentItem> > inventory_adjustments_getId(string id)
        {
            string sessionID
                = Request.Headers["Session-ID"];
            ClientServices Services = new ClientServices(sessionID);
            var            query    = DataAccess.DataQuery.Create("dms", "ws_adjustments_get", new
            {
                id = id
            });

            query += DataAccess.DataQuery.Create("dms", "ws_stocks_list_by_permission");
            query += DataAccess.DataQuery.Create("dms", "ws_categories_get", new
            {
                module = "adjustment_reasons"
            });
            var ds = await Services.ExecuteAsync(query);

            if (ds == null)
            {
                return(BadRequest(Services.LastError));
            }
            else
            {
                var result = new AdjustmentItem();
                if (ds.Tables[0].ToModel <Adjustment>().Count > 0)
                {
                    result.adjustment          = ds.Tables[0].ToModel <Adjustment>()[0];
                    result.adjustment.products = ds.Tables[1].ToModel <Product>();
                }
                result.stocks             = ds.Tables[2].ToModel <Stock>();
                result.adjustment_reasons = ds.Tables[3].ToModel <Category>();
                return(result);
            }
        }
Пример #2
0
        public ActionResult SaveAdjustmentVoucher()
        {
            var sr     = new StreamReader(Request.InputStream);
            var stream = sr.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            var        list         = JsonConvert.DeserializeObject <List <SelectedList> >(stream);
            JsonResult json         = new JsonResult();

            if (list.Any())
            {
                Adjustment adjustment = new Adjustment();
                adjustment.UserID           = User.Identity.GetUserId();
                adjustment.TotalPrice       = 0;
                adjustment.Date             = DateTime.Now;
                adjustment.AdjustmentID     = adjustmentBusinessLogic.generateAdjustmentID();
                adjustment.AdjustmentStatus = "Unapproved";
                adjustmentBusinessLogic.addAdjustment(adjustment);
                foreach (var item in list)
                {
                    Catalogue catalogue = catalogueBusinessLogic.getCatalogueById(item.itemID);
                    double    quantity  = Convert.ToDouble(item.quantity);
                    if (quantity < 0 && quantity < -catalogue.Quantity)
                    {
                        json.Data = "fail";
                        return(json);
                    }
                    AdjustmentItem adjustmentItem = new AdjustmentItem();
                    adjustmentItem.ItemID       = catalogue.ItemID;
                    adjustmentItem.Quantity     = item.quantity;
                    adjustmentItem.Reason       = item.reason;
                    adjustmentItem.AdjustmentID = adjustment.AdjustmentID;
                    adjustment.TotalPrice      += Math.Abs(Convert.ToInt32(catalogue.Price * Convert.ToDouble(item.quantity)));
                    adjustmentItemBusinessLogic.addAdjustmentItem(adjustmentItem);
                }
                if (adjustment.TotalPrice >= 250)
                {
                    adjustment.Supervisor = userBusinessLogic.getStoreManager().Id;
                }
                else
                {
                    adjustment.Supervisor = userBusinessLogic.getStoreStoreSupervisor().Id;
                }
                adjustmentBusinessLogic.updateAdjustment(adjustment);

                EmailBusinessLogic emailBusinessLogic = new EmailBusinessLogic();
                string             content            = emailBusinessLogic.NewVoucherNotification(adjustment.AdjustmentID, adjustment.UserID);

                List <string> toAddress = new List <string>();
                toAddress.Add("*****@*****.**");
                emailBusinessLogic.SendEmail("Team3", content, toAddress);
            }

            json.Data = "success";
            return(json);
        }
        public async Task RemoveItemAsync(Adjustment adjustment, AdjustmentItem item)
        {
            adjustment.RemoveItem(item);

            _repository.Update(adjustment);

            if (await _repository.UnitOfWork.CommitAsync())
            {
                await _bus.PublishDomainEvent(new AdjustmentItemRemoved(item.Id));
            }
        }
Пример #4
0
        public void Adjustment_UpdateItem_DeveGerarDomainExceptionQuandoTentarAtualizarUmItemInexistente()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            AdjustmentItem adjustmentItem = AdjustmentItemFaker.GenerateFaker(adjustment).Generate();

            // Act
            Action act = () => adjustment.UpdateItem(adjustmentItem);

            // Assert
            act.Should().Throw <DomainException>();
        }
Пример #5
0
        public void AdjustmentItem_CalculteValue_DeveCalculaCorretamenteOValorDoItem()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            decimal value = item.CalculteValue();

            // Assert
            value.Should().Be(20);
        }
Пример #6
0
        public void Adjustment_AddItem_DeveGerarDomainExceptionQuandoAdicionarUmItemEEstiverFechado()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            adjustment.Close();

            AdjustmentItem item1 = AdjustmentItemFaker.GenerateFaker(adjustment).Generate();

            // Act
            Action act = () => adjustment.AddItem(item1);

            // Assert
            act.Should().Throw <DomainException>();
        }
Пример #7
0
        public void Adjustment_UpdateItem_DeveAtualizarCorretamenteUmItemQuandoOMesmoExistir()
        {
            // Arange
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();

            AdjustmentItem adjustmentItem = AdjustmentItemFaker.GenerateFaker(adjustment).Generate();

            adjustment.AddItem(adjustmentItem);

            // Act
            adjustment.UpdateItem(adjustmentItem);

            // Assert
            adjustment.Items.Should().HaveCount(1);
        }
Пример #8
0
        public void AdjustmentItem_Update_DeveAtualizarCorretamenteOItemQuandoInformadoValoresValidos()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();
            Product    newProduct = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            item.Update(10, 5, newProduct);

            // Assert
            item.Amount.Should().Be(10);
            item.Value.Should().Be(5);
        }
Пример #9
0
        public void AdjustmentItem_Update_DeveRetornarDomainExceptionAoTentarAtualizarComValoresInvalidos()
        {
            // Arange && Act
            Adjustment adjustment = AdjustmentFaker.GenerateFaker().Generate();
            Product    product    = ProductFaker.GenerateFaker().Generate();
            Product    newProduct = ProductFaker.GenerateFaker().Generate();

            AdjustmentItem item = new AdjustmentItem(10, 2, adjustment, product);

            // Act
            Action action1 = () => item.Update(0, 5, newProduct);
            Action action2 = () => item.Update(1, 0, newProduct);

            // Assert
            action1.Should().Throw <DomainException>();
            action2.Should().Throw <DomainException>();
        }
Пример #10
0
    public void addadjustmentvoucher(double price, int clerkid, string itemcode, int quantity)
    {
        AdjustmentVoucher unapproved = findUnapprovedadjustment(clerkid, price, clerkid, quantity);

        if (unapproved.AdjustmentItems.Where(x => x.itemcode == itemcode && x.vouchernumber == unapproved.vouchernumber).Count() == 0)
        {
            AdjustmentItem item = new AdjustmentItem();
            item.vouchernumber = unapproved.vouchernumber;
            item.itemcode      = itemcode;
            item.quantity      = quantity;
            item.reason        = "Delivery Discrepancy";
            sce.AdjustmentItems.Add(item);
            sce.SaveChanges();
        }
        else
        {
            AdjustmentItem item = unapproved.AdjustmentItems.Where(x => x.itemcode == itemcode && x.vouchernumber == unapproved.vouchernumber).First();
            item.quantity = item.quantity + quantity;
            sce.SaveChanges();
        }
    }
Пример #11
0
    public void createAdjustment(List <WCFAdjustmentItem> adjitems)
    {
        AdjustmentVoucher adjs = new AdjustmentVoucher();
        double            cost = 0;

        foreach (WCFAdjustmentItem i in adjitems)
        {
            AdjustmentItem item = new AdjustmentItem();
            item.itemcode = i.Itemcode;
            item.quantity = i.Quantity;
            item.reason   = i.Reason;
            double price = scmanager.findPriceBySupplierAndItem(i.Suppliercode, i.Itemcode);
            cost += item.quantity * price;
            adjs.AdjustmentItems.Add(item);
        }
        adjs.issuedate = DateTime.Today;
        adjs.cost      = cost;
        adjs.clerkcode = 1027;
        string di = adjs.ToString();

        scmanager.createAdjustmentVoucher(adjs);
    }
    protected void Add_Click(object sender, EventArgs e)
    {
        AdjustmentItem ait = new AdjustmentItem();

        ait.itemcode = DropDownList1.SelectedValue;
        ait.quantity = Convert.ToInt32(TextBox4.Text);
        ait.reason   = TextBox5.Text;

        bool isinalist = false;

        foreach (AdjustmentItem ai in avoucher.AdjustmentItems)
        {
            if (ai.itemcode == ait.itemcode)
            {
                isinalist = true;
                break;
            }
        }
        if (!isinalist)
        {
            alist.Add(ait);
            avoucher.AdjustmentItems.Add(ait);
        }
        else
        {
            AdjustmentItem ai = avoucher.AdjustmentItems.Where(x => x.itemcode == ait.itemcode).First();
            ai.quantity = ai.quantity + ait.quantity;
        }
        GridView1.DataSource = alist;
        GridView1.DataBind();
        double price = scService.getTenderQuotationByKey(DropDownList2.SelectedValue, DropDownList1.SelectedValue).price;

        cost          = cost + price * Convert.ToInt32(TextBox4.Text);
        TextBox4.Text = "";
        TextBox5.Text = "";
    }
 public void addAdjustmentItem(AdjustmentItem adjustmentItem)
 {
     inventory.AdjustmentItem.Add(adjustmentItem);
     inventory.SaveChanges();
 }