Exemple #1
0
        public UnitCostDto(UnitPaymentOrderDetail detail, List <UnitPaymentOrderItem> spbItems, List <UnitReceiptNoteItem> unitReceiptNoteItems, List <UnitReceiptNote> unitReceiptNotes)
        {
            var unitReceiptNoteItem = unitReceiptNoteItems.FirstOrDefault(item => item.Id == detail.URNItemId);
            var unitReceiptNote     = unitReceiptNotes.FirstOrDefault(item => item.Id == unitReceiptNoteItem.URNId);

            Unit   = new UnitDto(unitReceiptNote.UnitId, unitReceiptNote.UnitCode, unitReceiptNote.UnitName, unitReceiptNote.DivisionCode, unitReceiptNote.DivisionId, unitReceiptNote.DivisionName);
            Amount = detail.PriceTotal;
        }
        private void SetPOItemIdEPONo(UnitPaymentOrderDetail detail)
        {
            ExternalPurchaseOrderDetail EPODetail = dbContext.ExternalPurchaseOrderDetails.Single(m => m.Id == detail.EPODetailId);

            detail.POItemId = EPODetail.POItemId;

            detail.EPONo = dbContext.ExternalPurchaseOrders.Single(m => m.Items.Any(i => i.Id == EPODetail.EPOItemId)).EPONo;
        }
Exemple #3
0
        public async Task <int> Create(UnitPaymentCorrectionNote model, bool supplierImport, string username, int clientTimeZoneOffset = 7)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForCreate(model, username, USER_AGENT);

                    model.UPCNo = await GenerateNo(model, supplierImport, clientTimeZoneOffset);

                    if (model.useVat == true)
                    {
                        model.ReturNoteNo = await GeneratePONo(model, clientTimeZoneOffset);
                    }
                    UnitPaymentOrder unitPaymentOrder = this.dbContext.UnitPaymentOrders.FirstOrDefault(s => s.Id == model.UPOId);
                    unitPaymentOrder.IsCorrection = true;

                    foreach (var item in model.Items)
                    {
                        UnitPaymentOrderDetail upoDetail = dbContext.UnitPaymentOrderDetails.FirstOrDefault(s => s.Id == item.UPODetailId);
                        item.PricePerDealUnitBefore          = upoDetail.PricePerDealUnit;
                        item.PriceTotalBefore                = upoDetail.PriceTotal;
                        upoDetail.PricePerDealUnitCorrection = item.PricePerDealUnitAfter;
                        upoDetail.PriceTotalCorrection       = item.PriceTotalAfter;

                        if (item.PriceTotalAfter > 0 && item.PricePerDealUnitAfter <= 0)
                        {
                            upoDetail.PricePerDealUnitCorrection = upoDetail.PricePerDealUnit;
                        }

                        EntityExtension.FlagForCreate(item, username, USER_AGENT);
                    }

                    this.dbSet.Add(model);
                    Created = await dbContext.SaveChangesAsync();

                    Created += await AddCorrections(model, username);

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }
Exemple #4
0
        public UnitCostDto(UnitPaymentOrderDetail detail, List <UnitPaymentOrderItem> spbItems, List <UnitReceiptNoteItem> unitReceiptNoteItems, List <UnitReceiptNote> unitReceiptNotes, UnitPaymentOrder element)
        {
            var unitReceiptNoteItem = unitReceiptNoteItems.FirstOrDefault(item => item.Id == detail.URNItemId);
            var unitReceiptNote     = unitReceiptNotes.FirstOrDefault(item => item.Id == unitReceiptNoteItem.URNId);

            Unit = new UnitDto(unitReceiptNote.UnitId, unitReceiptNote.UnitCode, unitReceiptNote.UnitName, unitReceiptNote.DivisionCode, unitReceiptNote.DivisionId, unitReceiptNote.DivisionName);

            var quantity = detail.ReceiptQuantity;

            if (detail.QuantityCorrection > 0)
            {
                quantity = detail.QuantityCorrection;
            }

            var price = detail.PricePerDealUnit;

            if (detail.PricePerDealUnitCorrection > 0)
            {
                price = detail.PricePerDealUnitCorrection;
            }

            var result = quantity * price;

            if (detail.PriceTotalCorrection > 0)
            {
                result = detail.PriceTotalCorrection;
            }

            var total = result;

            if (element != null)
            {
                if (element.UseVat)
                {
                    result += total * (element.VatRate / 100);

                    //result += total * 0.1;
                }

                if (element.UseIncomeTax && (element.IncomeTaxBy == "Supplier" || element.IncomeTaxBy == "SUPPLIER"))
                {
                    result -= total * (element.IncomeTaxRate / 100);
                }
            }

            Amount = result;
        }
        private void SetStatus(UnitPaymentOrderDetail detail, string username)
        {
            ExternalPurchaseOrderDetail EPODetail = dbContext.ExternalPurchaseOrderDetails.Single(m => m.Id == detail.EPODetailId);
            InternalPurchaseOrderItem   POItem    = dbContext.InternalPurchaseOrderItems.Single(m => m.Id == EPODetail.POItemId);

            List <long> EPODetailIds = dbContext.ExternalPurchaseOrderDetails.Where(m => m.POItemId == POItem.Id).Select(m => m.Id).ToList();
            List <long> URNItemIds   = dbContext.UnitReceiptNoteItems.Where(m => EPODetailIds.Contains(m.EPODetailId)).Select(m => m.Id).ToList();

            var totalReceiptQuantity = dbContext.UnitPaymentOrderDetails.AsNoTracking().Where(m => m.IsDeleted == false && URNItemIds.Contains(m.URNItemId)).Sum(m => m.ReceiptQuantity);

            if (totalReceiptQuantity > 0)
            {
                if (totalReceiptQuantity < EPODetail.DealQuantity)
                {
                    POItem.Status = "Sudah dibuat SPB sebagian";
                }
                else
                {
                    POItem.Status = "Sudah dibuat SPB semua";
                }
            }
            else if (totalReceiptQuantity == 0)
            {
                if (EPODetail.DOQuantity >= EPODetail.DealQuantity)
                {
                    if (EPODetail.ReceiptQuantity < EPODetail.DealQuantity)
                    {
                        POItem.Status = "Barang sudah diterima Unit parsial";
                    }
                    else
                    {
                        POItem.Status = "Barang sudah diterima Unit semua";
                    }
                }
                else
                {
                    POItem.Status = "Barang sudah diterima Unit parsial";
                }
            }
            EntityExtension.FlagForUpdate(POItem, username, USER_AGENT);
        }
        public void Should_Success_Get_Data_DispositionMemoLoader()
        {
            var dbContext = _dbContext(GetCurrentMethod());
            var facade    = new PurchasingDispositionFacade(ServiceProvider, dbContext);

            var Response = facade.GetDispositionMemoLoader(0);

            Assert.Null(Response);

            var purhcasingDisposition = new PurchasingDisposition()
            {
                Id = 1, CurrencyCode = "IDR"
            };
            var purchasingDispositionItem = new PurchasingDispositionItem()
            {
                PurchasingDispositionId = 1, UseVat = true, UseIncomeTax = true, EPONo = "1"
            };
            var unitPaymentOrder = new UnitPaymentOrder()
            {
                Id = 1
            };
            var unitPaymentOrderItem = new UnitPaymentOrderItem()
            {
                Id = 1, UPOId = 1
            };
            var unitPaymentOrderDetail = new UnitPaymentOrderDetail()
            {
                EPONo = "1", UPOItemId = 1
            };

            dbContext.PurchasingDispositions.Add(purhcasingDisposition);
            dbContext.PurchasingDispositionItems.Add(purchasingDispositionItem);
            dbContext.UnitPaymentOrders.Add(unitPaymentOrder);
            dbContext.UnitPaymentOrderItems.Add(unitPaymentOrderItem);
            dbContext.UnitPaymentOrderDetails.Add(unitPaymentOrderDetail);
            dbContext.SaveChanges();

            var Response2 = facade.GetDispositionMemoLoader(1);

            Assert.NotNull(Response2);
        }
Exemple #7
0
        public UnitCostDto(UnitPaymentOrderDetail detail, List <UnitPaymentOrderItem> spbItems, List <UnitReceiptNoteItem> unitReceiptNoteItems, List <UnitReceiptNote> unitReceiptNotes, UnitPaymentOrder element)
        {
            var unitReceiptNoteItem = unitReceiptNoteItems.FirstOrDefault(item => item.Id == detail.URNItemId);
            var unitReceiptNote     = unitReceiptNotes.FirstOrDefault(item => item.Id == unitReceiptNoteItem.URNId);

            Unit = new UnitDto(unitReceiptNote.UnitId, unitReceiptNote.UnitCode, unitReceiptNote.UnitName, unitReceiptNote.DivisionCode, unitReceiptNote.DivisionId, unitReceiptNote.DivisionName);

            var total = detail.PriceTotal;

            if (element != null)
            {
                if (element.UseVat)
                {
                    total += detail.PriceTotal * 0.1;
                }

                if (element.UseIncomeTax && (element.IncomeTaxBy == "Supplier" || element.IncomeTaxBy == "SUPPLIER"))
                {
                    total -= detail.PriceTotal * (element.IncomeTaxRate / 100);
                }
            }

            Amount = total;
        }
Exemple #8
0
        public int Delete(int id, string user)
        {
            int Deleted = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var m = this.dbSet
                            .Include(d => d.Items)
                            .SingleOrDefault(pr => pr.Id == id && !pr.IsDeleted);

                    EntityExtension.FlagForDelete(m, user, USER_AGENT);

                    foreach (var item in m.Items)
                    {
                        EntityExtension.FlagForDelete(item, user, USER_AGENT);

                        ExternalPurchaseOrderDetail externalPurchaseOrderDetail = this.dbContext.ExternalPurchaseOrderDetails.FirstOrDefault(s => s.IsDeleted == false && s.Id == item.EPODetailId);
                        PurchaseRequestItem         prItem    = this.dbContext.PurchaseRequestItems.FirstOrDefault(s => s.IsDeleted == false && s.Id == externalPurchaseOrderDetail.PRItemId);
                        InternalPurchaseOrderItem   poItem    = this.dbContext.InternalPurchaseOrderItems.FirstOrDefault(s => s.IsDeleted == false && s.Id == externalPurchaseOrderDetail.POItemId);
                        DeliveryOrderDetail         doDetail  = dbContext.DeliveryOrderDetails.FirstOrDefault(s => s.IsDeleted == false && s.Id == item.DODetailId);
                        UnitPaymentOrderDetail      upoDetail = dbContext.UnitPaymentOrderDetails.FirstOrDefault(s => s.IsDeleted == false && s.POItemId == poItem.Id);
                        doDetail.ReceiptQuantity -= item.ReceiptQuantity;
                        externalPurchaseOrderDetail.ReceiptQuantity -= item.ReceiptQuantity;
                        if (externalPurchaseOrderDetail.ReceiptQuantity == 0 && upoDetail == null)
                        {
                            if (externalPurchaseOrderDetail.DOQuantity > 0 && externalPurchaseOrderDetail.DOQuantity >= externalPurchaseOrderDetail.DealQuantity)
                            {
                                //prItem.Status = "Barang sudah diterima Unit semua";
                                poItem.Status = "Barang sudah datang semua";
                            }
                            else if (externalPurchaseOrderDetail.DOQuantity > 0 && externalPurchaseOrderDetail.DOQuantity < externalPurchaseOrderDetail.DealQuantity)
                            {
                                //prItem.Status = "Barang sudah diterima Unit parsial";
                                poItem.Status = "Barang sudah datang parsial";
                            }
                        }
                        else if (externalPurchaseOrderDetail.ReceiptQuantity > 0 && upoDetail == null)
                        {
                            if (externalPurchaseOrderDetail.DOQuantity >= externalPurchaseOrderDetail.DealQuantity)
                            {
                                if (externalPurchaseOrderDetail.ReceiptQuantity < externalPurchaseOrderDetail.DealQuantity)
                                {
                                    //prItem.Status = "Barang sudah diterima Unit parsial";
                                    poItem.Status = "Barang sudah diterima Unit parsial";
                                }
                                else if (externalPurchaseOrderDetail.ReceiptQuantity >= externalPurchaseOrderDetail.DealQuantity)
                                {
                                    //prItem.Status = "Barang sudah diterima Unit semua";
                                    poItem.Status = "Barang sudah diterima Unit semua";
                                }
                                else if (externalPurchaseOrderDetail.DOQuantity < externalPurchaseOrderDetail.DealQuantity)
                                {
                                    poItem.Status = "Barang sudah diterima Unit parsial";
                                }
                            }
                        }
                    }
                    if (m.IsStorage == true)
                    {
                        insertStorage(m, user, "OUT");
                    }

                    Deleted = dbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Deleted);
        }
Exemple #9
0
        public async Task <int> Create(UnitReceiptNote m, string user)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForCreate(m, user, "Facade");

                    m.URNNo = await GenerateNo(m);

                    if (m.Items != null)
                    {
                        foreach (var item in m.Items)
                        {
                            EntityExtension.FlagForCreate(item, user, "Facade");
                            ExternalPurchaseOrderDetail externalPurchaseOrderDetail = this.dbContext.ExternalPurchaseOrderDetails.FirstOrDefault(s => s.Id == item.EPODetailId);
                            PurchaseRequestItem         prItem    = this.dbContext.PurchaseRequestItems.FirstOrDefault(s => s.Id == externalPurchaseOrderDetail.PRItemId);
                            InternalPurchaseOrderItem   poItem    = this.dbContext.InternalPurchaseOrderItems.FirstOrDefault(s => s.Id == externalPurchaseOrderDetail.POItemId);
                            DeliveryOrderDetail         doDetail  = dbContext.DeliveryOrderDetails.FirstOrDefault(s => s.Id == item.DODetailId);
                            UnitPaymentOrderDetail      upoDetail = dbContext.UnitPaymentOrderDetails.FirstOrDefault(s => s.IsDeleted == false && s.POItemId == poItem.Id);
                            item.PRItemId             = doDetail.PRItemId;
                            item.PricePerDealUnit     = externalPurchaseOrderDetail.PricePerDealUnit;
                            doDetail.ReceiptQuantity += item.ReceiptQuantity;
                            externalPurchaseOrderDetail.ReceiptQuantity += item.ReceiptQuantity;
                            if (upoDetail == null)
                            {
                                if (externalPurchaseOrderDetail.DOQuantity >= externalPurchaseOrderDetail.DealQuantity)
                                {
                                    if (externalPurchaseOrderDetail.ReceiptQuantity < externalPurchaseOrderDetail.DealQuantity)
                                    {
                                        //prItem.Status = "Barang sudah diterima Unit parsial";
                                        poItem.Status = "Barang sudah diterima Unit parsial";
                                    }
                                    else
                                    {
                                        //prItem.Status = "Barang sudah diterima Unit semua";
                                        poItem.Status = "Barang sudah diterima Unit semua";
                                    }
                                }
                                else
                                {
                                    //prItem.Status = "Barang sudah diterima Unit parsial";
                                    poItem.Status = "Barang sudah diterima Unit parsial";
                                }
                            }
                        }
                    }
                    if (m.IsStorage == true)
                    {
                        insertStorage(m, user, "IN");
                    }
                    this.dbSet.Add(m);
                    Created = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }