Esempio n. 1
0
        public void Kirim(GRNModel grn,int tenanId, DiscriminatorPengirimanBarang discriminator)
        {
            Ccy ccy = MasterDataRepository.FindAllCurrencies(tenanId).Where(c => c.CcyId == grn.CcyId).FirstOrDefault();
            PengirimanBarangMessage msg = new PengirimanBarangMessage
            {
                Guid = Guid.NewGuid(),
                TenanId = tenanId,
                CcyCode = ccy == null ? "" : ccy.Kode,
                KodeTransaksi = grn.KodeTransaksi,
                TanggalTransaksi = grn.TanggalTransaksi,
                NamaPengirim = grn.NamaPengirim,
                Referensi = grn.Referensi,
                Keterangan = grn.Keterangan,
                Discriminator = Enum.GetName(typeof(DiscriminatorPengirimanBarang), discriminator)
            };

            IList<Unit> units = MasterDataRepository.FindAllUnits(tenanId);

            IList<GRNItemMessage> itemMessages = new List<GRNItemMessage>();
            List<GRNItemModel> grnItems = (List<GRNItemModel>)GetItems(tenanId,discriminator);
            grnItems.ForEach(item =>
                {
                    Product product = MasterDataRepository.FindProductById(tenanId, item.ProductId);

                    if (item.Items != null)
                    {
                        productGuid = JsonConvert.DeserializeObject<Items>(item.Items);
                    }

                    itemMessages.Add(new GRNItemMessage
                    {
                        Guid = Guid.NewGuid(),
                        UnitGuid = item.UnitId,
                        ProductGuid = item.ProductId == 0 ? productGuid.ProductGuid : product.ModelGuid,
                        Qty = item.Qty,
                        Harga = item.Harga,
                        Jumlah = item.Jumlah,
                        Items = item.Items
                    });
                });
            msg.Items = itemMessages.ToArray();
            new RabbitHelper().SendPengirimanBarangExchange<PengirimanBarangMessage>(msg);

            grnItems.ForEach(item => ap1Db.GRNItem.Remove(item));
            ap1Db.SaveChanges();
        }
        private void SendProductToTambahProduk(Items NewProduct, string tenanId)
        {
            MasterData.Models.PartGroup partGroup = MasterDataRepository().FindAllGroups(Int32.Parse(tenanId)).Where(m => m.GroupId == NewProduct.PartGroup).FirstOrDefault();
            if (partGroup == null )
                throw new ApplicationException("Partgroup dengan kode " + NewProduct.PartGroup + " tidak ditemukan dalam database.");

            MasterData.Models.Unit unit = MasterDataRepository().FindAllUnits(Int32.Parse(tenanId)).Where(m => m.UnitId == NewProduct.UnitId).FirstOrDefault();
            if (unit == null)
                throw new ApplicationException("Unit dengan kode " + NewProduct.UnitId + " tidak ditemukan dalam database.");

            MasterData.Models.Ccy ccy = MasterDataRepository().FindAllCurrencies(0).Where(m => m.CcyId == NewProduct.CcyId).FirstOrDefault();
            if (ccy == null)
                throw new ApplicationException("Mata uang " + NewProduct.CcyId + " tidak ditemukan dalam database.");

            BonaStoco.AP1.Web.Messages.TambahProductMessage msg = new BonaStoco.AP1.Web.Messages.TambahProductMessage()
            {
                TenanId = Int32.Parse(tenanId),
                Barcode = NewProduct.Barcode,
                Kode = NewProduct.Kode,
                Nama = NewProduct.NamaBArang,
                HargaBeli = NewProduct.HargaBeli,
                HargaJual = NewProduct.HargaJual,
                GroupId = NewProduct.PartGroup,
                CcyId = NewProduct.CcyId,
                CcyCode = ccy.Kode,
                UnitId = NewProduct.UnitId,
                ProductGuid = NewProduct.ProductGuid,
                StatusPrint = true,
                GroupGUID = partGroup.ModelGuid,
                UnitGUID = unit.ModelGuid
            };
            new RabbitHelper().SendMasterDataExchange<TambahProductMessage>(msg);
        }