Beispiel #1
0
        public void PutProductName(string productId, string productName, string unit, string price)
        {
            txtProductId.Text = productId;
            txtProduct.Text   = productName;
            txtUnit.Text      = unit;
            txtPrice.Text     = price;

            txtPrice.Enabled = true;
            txtQty.Enabled   = true;

            var productQty = productQtyRepository.GetByMonthAndYear(Store.ActiveMonth, Store.ActiveYear, new Guid(productId));

            if (productQty != null)
            {
                txtQtyEnd.Text = productQty.QtyEnd.ToString();
            }
            else
            {
                txtQtyEnd.Text = "0";
            }
        }
Beispiel #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Store.IsPeriodClosed)
            {
                MessageBox.Show("Tidak dapat menambah/ubah \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                var productQty = productQtyRepository.GetByMonthAndYear(Store.ActiveMonth, Store.ActiveYear, new Guid(lblID.Text));
                if (productQty != null)
                {
                    int qtyBegin = (productQty.QtyBegin - productQty.QtyBegin) + int.Parse(txtQtyBegin.Text);
                    int qtyIn    = productQty.QtyIn;
                    int qtyOut   = (productQty.QtyOut - productQty.QtyPlusCorrection) + productQty.QtyMinusCorrection;

                    lblQtyEnd.Text = ((qtyBegin + qtyIn) - qtyOut).ToString();
                }
                else
                {
                    lblQtyEnd.Text = txtQtyBegin.Text;
                }

                if (Store.IsAdministrator)
                {
                    frmProduct.UpdateProductQty(lblID.Text, lblYear.Text, lblMonth.Text,
                                                txtQtyBegin.Text, txtValueBegin.Text,
                                                lblQtyIn.Text, txtPurchasePrice.Text,
                                                lblQtyAvailable.Text, txtValueAverage.Text, lblValueAvailable.Text,
                                                lblQtyOut.Text, txtSalesPrice.Text,
                                                lblQtyEnd.Text, lblValueEnd.Text,
                                                lblQtyPlusCorrection.Text, lblQtyMinusCorrection.Text,
                                                lblValuePlusCorrection.Text, lblValueMinusCorrection.Text);
                }
                else
                {
                    frmProduct.UpdateProductQty2(lblID.Text, lblYear.Text, lblMonth.Text,
                                                 txtQtyBegin.Text, txtValueBegin.Text,
                                                 lblQtyIn.Text, txtPurchasePrice.Text,
                                                 lblQtyAvailable.Text, txtValueAverage.Text, lblValueAvailable.Text,
                                                 lblQtyOut.Text, txtSalesPrice.Text,
                                                 lblQtyEnd.Text, lblValueEnd.Text,
                                                 lblQtyPlusCorrection.Text, lblQtyMinusCorrection.Text,
                                                 lblValuePlusCorrection.Text, lblValueMinusCorrection.Text);
                }
                this.Close();
            }
        }
Beispiel #3
0
        private void ProductQtyNewPeriod()
        {
            //cek periode baru
            int newYear  = 0;
            int newMonth = 0;

            if (Store.ActiveMonth < 12)
            {
                newYear  = Store.ActiveYear;
                newMonth = Store.ActiveMonth + 1;
            }
            else
            {
                newYear  = Store.ActiveYear + 1;
                newMonth = 1;
            }

            ProductQty productQty = new ProductQty();

            var newQty = productQtyRepository.GetAll(newMonth, newYear);

            if (newQty.Count == 0)
            {
                //cari data lama
                var oldQty = productQtyRepository.GetAll(Store.ActiveMonth, Store.ActiveYear);

                foreach (var p in oldQty)
                {
                    productQty.ActiveYear           = newYear;
                    productQty.ActiveMonth          = newMonth;
                    productQty.ProductId            = p.ProductId;
                    productQty.QtyBegin             = p.QtyEnd;
                    productQty.ValueBegin           = p.ValueEnd;
                    productQty.QtyIn                = 0;
                    productQty.PurchasePrice        = 0;
                    productQty.QtyAvailable         = 0;
                    productQty.ValueAverage         = 0;
                    productQty.ValueAvailable       = 0;
                    productQty.QtyOut               = 0;
                    productQty.SalesPrice           = 0;
                    productQty.QtyEnd               = p.QtyEnd;
                    productQty.ValueEnd             = p.ValueEnd;
                    productQty.QtyPlusCorrection    = 0;
                    productQty.QtyMinusCorrection   = 0;
                    productQty.ValuePlusCorrection  = 0;
                    productQty.ValueMinusCorrection = 0;

                    productQtyRepository.Save(productQty);
                }
            }
            else
            {
                foreach (var newQ in newQty)
                {
                    //cari data lama
                    var oldQty1 = productQtyRepository.GetByMonthAndYear(Store.ActiveMonth, Store.ActiveYear, newQ.ProductId);

                    if (oldQty1 != null)
                    {
                        productQtyRepository.UpdateQtyBegin(newMonth, newYear, oldQty1.ProductId, oldQty1.QtyEnd, oldQty1.ValueEnd);
                    }
                }
                inventoryRepository.GenerateInventory(newMonth, newYear);
            }
        }
        public void GenerateInventory(int month, int year)
        {
            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    Guid   productId       = Guid.Empty;
                    string productCode     = "";
                    string productName     = "";
                    string productUnit     = "";
                    string productCategory = "";

                    int     qtyBegin   = 0;
                    decimal valueBegin = 0;

                    int     qtyIn             = 0;
                    decimal purchasePriceTemp = 0;
                    decimal purchasePrice     = 0;

                    int     qtyAvailable   = 0;
                    decimal valueAverage   = 0; //harga rata2
                    decimal valueAvailable = 0; //harga pokok penjualan

                    int     qtyOut     = 0;
                    decimal salesPrice = 0;
                    decimal salesValue = 0;

                    int     qtyEnd   = 0;
                    decimal valueEnd = 0;

                    int     qtyPlusCorrection    = 0;
                    int     qtyMinusCorrection   = 0;
                    decimal valuePlusCorrection  = 0;
                    decimal valueMinusCorrection = 0;

                    int     qtyPayment   = 0;
                    decimal paymentPrice = 0;
                    decimal paymentValue = 0;


                    //PRODUCT
                    List <Product> products = productRepository.GetAll();

                    foreach (var p in products)
                    {
                        productId       = p.ID;
                        productCode     = p.Code;
                        productName     = p.Name;
                        productUnit     = p.Unit;
                        productCategory = p.Category.Name;

                        qtyBegin   = 0;        //A = qty awal
                        valueBegin = 0;        //B = nilai awal

                        qtyIn             = 0; //C = qty beli
                        purchasePriceTemp = 0; //D = temporary per item barang (qty * price)
                        purchasePrice     = 0; //E = total pembelian per item barang

                        qtyAvailable   = 0;    //F = A + C
                        valueAverage   = 0;    //G = H : F
                        valueAvailable = 0;    //H = B + E

                        qtyOut     = 0;
                        salesPrice = 0;
                        salesValue = 0;

                        qtyEnd   = 0;
                        valueEnd = 0;

                        qtyPlusCorrection    = 0;
                        qtyMinusCorrection   = 0;
                        valuePlusCorrection  = 0;
                        valueMinusCorrection = 0;

                        qtyPayment   = 0;
                        paymentPrice = 0;
                        paymentValue = 0;


                        //BEGIN
                        //PRODUCT QTY - cek qty begin & value begin
                        var productQty = productQtyRepository.GetByMonthAndYear(month, year, productId);
                        if (productQty != null)
                        {
                            qtyBegin   = productQty.QtyBegin;
                            valueBegin = productQty.ValueBegin;
                        }

                        //KOREKSI
                        List <StockCorrectionItem> stockCorrectionItem = stockCorrectionItemRepository.GetByMonthAndYear(month, year, productId);
                        foreach (var correction in stockCorrectionItem)
                        {
                            qtyPlusCorrection    = qtyPlusCorrection + correction.QtyPlus;
                            qtyMinusCorrection   = qtyMinusCorrection + correction.QtyMinus;
                            valuePlusCorrection  = valuePlusCorrection + correction.ValuePlus;
                            valueMinusCorrection = valueMinusCorrection + correction.ValueMinus;
                        }

                        //IN
                        //PURCHASE - get total qty & purchase price average
                        List <PurchaseItem> purchaseItems = purchaseItemRepository.GetByMonthAndYear(month, year, productId);
                        foreach (var purchase in purchaseItems)
                        {
                            qtyIn             = qtyIn + purchase.Qty;
                            purchasePriceTemp = purchasePriceTemp + (purchase.Price * purchase.Qty);
                        }

                        //pengaruh koreksi nilai
                        purchasePriceTemp = (purchasePriceTemp + valuePlusCorrection) - valueMinusCorrection;
                        if (qtyIn > 0)
                        {
                            purchasePrice = purchasePriceTemp / qtyIn;
                        }
                        else
                        {
                            purchasePrice = purchasePriceTemp;
                        }

                        //AVAILABLE
                        qtyAvailable   = qtyBegin + qtyIn;
                        valueAvailable = valueBegin + purchasePrice;
                        if (qtyAvailable > 0)
                        {
                            valueAverage = valueAvailable / qtyAvailable;
                        }

                        //OUT
                        //SALES - get total qty sales
                        List <SalesItem> salesItems = salesItemRepository.GetByMonthAndYear(month, year, productId);
                        foreach (var sales in salesItems)
                        {
                            qtyOut     = qtyOut + sales.Qty;
                            salesValue = salesValue + (sales.Qty * sales.Price);
                        }
                        qtyOut     = (qtyOut + qtyMinusCorrection) - qtyPlusCorrection;
                        salesPrice = qtyOut * valueAverage;


                        //END
                        qtyEnd   = qtyAvailable - qtyOut;
                        valueEnd = valueAvailable - salesPrice;


                        //PAYMENT
                        List <PaymentItemQty> paymentItemQty = payablePaymentItemRepository.GetPaymentItemQty(month, year, productId);
                        foreach (var payment in paymentItemQty)
                        {
                            qtyPayment   = qtyPayment + payment.Qty;
                            paymentValue = paymentValue + payment.Total;
                        }
                        paymentPrice = qtyPayment * valueAverage;



                        //PRODUCT QTY - update
                        productQtyRepository.UpdateQtyFromInventory(month, year, productId,
                                                                    qtyIn, purchasePrice,
                                                                    qtyAvailable, valueAverage, valueAvailable,
                                                                    qtyOut, salesPrice, salesValue,
                                                                    qtyEnd, valueEnd,
                                                                    qtyPlusCorrection, qtyMinusCorrection,
                                                                    valuePlusCorrection, valueMinusCorrection,
                                                                    qtyPayment, paymentPrice, paymentValue);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }