Beispiel #1
0
        public async Task <bool> AddTransH(ApTransHView trans)
        {
            //string test = codeview.SrcCode.ToUpper();
            //var cekFirst = _context.CbSrcCodes.Where(x => x.SrcCode == test).ToList();
            string KdSrc = "AP";

            ApTransH transH = new ApTransH
            {
                Bukti      = GetNumber(),
                Supplier   = trans.Supplier.ToUpper(),
                Tanggal    = trans.Tanggal,
                Keterangan = trans.Keterangan,
                Jumlah     = trans.JumBayar,
                Discount   = trans.JumDiskon,
                Unapplied  = trans.UpdateUnapplied,
                Hutang     = trans.JumHutang,
                KdBank     = trans.KdBank,
                PPn        = 0,
                PPh        = 0,
                JumPPh     = 0,
                JumPPn     = 0,
                Bruto      = 0,
                Netto      = 0,
                Pajak      = false,
                Kode       = "24",
                ApSupplId  = trans.ApSupplId,

                ApTransDs = new List <ApTransD>()
            };

            List <ApHutang> transaksi = new List <ApHutang>();

            transaksi = _context.ApHutangs.Where(x => x.Supplier == trans.Supplier && x.Sisa != 0).ToList();

            foreach (var item in trans.ApTransDs)
            {
                transH.ApTransDs.Add(new ApTransD()
                {
                    Jumlah   = item.Jumlah,
                    Kode     = "24",
                    KodeTran = item.KodeTran,
                    Lpb      = transH.Bukti,
                    Tanggal  = trans.Tanggal,
                    Discount = item.Discount,
                    Bayar    = item.Bayar,
                    Sisa     = item.UpdateSisa
                });

                transaksi.Where(x => x.Dokumen == item.Lpb).ToList()
                .ForEach(s =>
                {
                    s.Bayar    = item.Bayar + item.Discount;
                    s.Discount = item.Discount;
                    s.Sisa     = item.UpdateSisa;
                });
            }
            transH.ApTransDs.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);
            transaksi.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);

            var Supplier = (from e in _context.ApSuppls where e.Supplier == trans.Supplier select e).FirstOrDefault();

            Supplier.Hutang -= trans.Jumlah;

            ApHutang Newtransaksi = new ApHutang
            {
                Kode       = "CA",
                Dokumen    = transH.Bukti,
                Tanggal    = transH.Tanggal,
                Supplier   = transH.Supplier,
                Keterangan = transH.Keterangan,
                KodeTran   = "24",
                Jumlah     = -1 * trans.JumHutang,
                SldSisa    = -1 * trans.JumHutang,
                Bayar      = -1 * trans.JumBayar,
                Discount   = 0,
                UnApplied  = -1 * trans.UpdateUnapplied,
                Sisa       = -1 * trans.UpdateUnapplied,

                Dpp      = 0,
                PPn      = 0,
                PPh      = 0,
                SldBayar = 0,
                SldDisc  = 0,
                SldUnpl  = 0
            };

            _context.ApSuppls.Update(Supplier);
            _context.ApTransHs.Add(transH);
            _context.ApHutangs.UpdateRange(transaksi);
            _context.ApHutangs.Add(Newtransaksi);
            await _context.SaveChangesAsync();



            var cekBukti = (from e in _context.CbTransHs where e.DocNo == transH.Bukti select e).FirstOrDefault();

            if (cekBukti == null)
            {
                if (transH.KdBank != null && transH.KdBank.Length != 0)
                {
                    CbTransH transBank = new CbTransH
                    {
                        DocNo      = transH.Bukti,
                        KodeBank   = trans.KdBank,
                        Tanggal    = trans.Tanggal,
                        Keterangan = trans.Keterangan,
                        Saldo      = -1 * trans.JumBayar,

                        CbTransDs = new List <CbTransD>()
                    };
                    foreach (var item in trans.ApTransDs)
                    {
                        transBank.CbTransDs.Add(new CbTransD()
                        {
                            SrcCode    = KdSrc,
                            Keterangan = "Pembayaran Hutang" + trans.Supplier.ToUpper(),
                            Bayar      = item.Bayar,
                            Jumlah     = -1 * item.Bayar,
                        });
                    }
                    var bank = (from e in _context.Banks where e.KodeBank == trans.KdBank select e).FirstOrDefault();
                    bank.Saldo -= trans.JumBayar;

                    _context.Banks.Update(bank);
                    _context.CbTransHs.Add(transBank);

                    await _context.SaveChangesAsync();
                }
            }

            return(true);
        }
Beispiel #2
0
        public async Task <bool> AddTransH(ApTransHView trans)
        {
            //string test = codeview.SrcCode.ToUpper();
            //var cekFirst = _context.CbSrcCodes.Where(x => x.SrcCode == test).ToList();
            string KdSrc = "AP";

            ApTransH transH = new ApTransH
            {
                Bukti      = GetNumber(),
                Supplier   = trans.Supplier.ToUpper(),
                Tanggal    = trans.Tanggal,
                Keterangan = trans.Keterangan,
                Jumlah     = trans.JumBayar,
                Discount   = 0,
                Unapplied  = trans.UpdateUnapplied,
                Hutang     = 0,
                KdBank     = trans.KdBank,
                PPn        = 0,
                PPh        = 0,
                JumPPh     = 0,
                JumPPn     = 0,
                Bruto      = 0,
                Netto      = 0,
                Pajak      = false,
                Kode       = "23",
                ApSupplId  = trans.ApSupplId

                             //  ApTransDs = new List<ApTransD>()
            };

            #region detailTrans

            //List<ApHutang> transaksi = new List<ApHutang>();
            //transaksi = _context.ApHutangs.Where(x => x.supplier == trans.supplier && x.Sisa != 0).ToList();

            //foreach (var item in trans.ApTransDs)
            //{
            //    transH.ApTransDs.Add(new ApTransD()
            //    {
            //        Jumlah = item.Jumlah,
            //        Kode = "14",
            //        KodeTran = item.KodeTran,
            //        Lpb = transH.Bukti,
            //        Tanggal = trans.Tanggal,
            //        Discount = item.Discount,
            //        Bayar = item.Bayar,
            //        Sisa = item.UpdateSisa

            //    });

            //    transaksi.Where(x => x.Dokumen == item.Lpb).ToList()
            //        .ForEach(s =>
            //        {
            //            s.Bayar = item.Bayar + item.Discount;
            //            s.Discount = item.Discount;
            //            s.Sisa = item.UpdateSisa;
            //        });

            //}
            //transH.ApTransDs.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);
            //transaksi.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);

            #endregion

            ApHutang transaksi = new ApHutang
            {
                Kode       = "CA",
                Dokumen    = transH.Bukti,
                Tanggal    = transH.Tanggal,
                Supplier   = transH.Supplier,
                Keterangan = transH.Keterangan,
                KodeTran   = "23",
                Jumlah     = -1 * transH.Jumlah,
                SldSisa    = -1 * transH.Jumlah,
                Bayar      = -1 * transH.Jumlah,
                Discount   = 0,
                UnApplied  = -1 * transH.Unapplied,
                Sisa       = -1 * transH.Unapplied,

                Dpp      = 0,
                PPn      = 0,
                PPh      = 0,
                SldBayar = 0,
                SldDisc  = 0,
                SldUnpl  = 0
            };

            var supplier = (from e in _context.ApSuppls where e.Supplier == trans.Supplier select e).FirstOrDefault();
            supplier.Hutang -= transH.Jumlah;

            _context.ApSuppls.Update(supplier);
            _context.ApTransHs.Add(transH);
            _context.ApHutangs.Add(transaksi);
            await _context.SaveChangesAsync();

            var cekBukti = (from e in _context.CbTransHs where e.DocNo == transH.Bukti select e).FirstOrDefault();

            if (cekBukti == null)
            {
                if (transH.KdBank != null && transH.KdBank.Length != 0)
                {
                    CbTransH transBank = new CbTransH
                    {
                        DocNo      = transH.Bukti,
                        KodeBank   = trans.KdBank,
                        Tanggal    = trans.Tanggal,
                        Keterangan = trans.Keterangan,
                        Saldo      = -1 * trans.JumBayar,

                        CbTransDs = new List <CbTransD>()
                    };

                    transBank.CbTransDs.Add(new CbTransD()
                    {
                        SrcCode    = KdSrc,
                        Keterangan = "Pembayaran Uang Muka " + trans.Supplier.ToUpper(),
                        Bayar      = trans.JumBayar,
                        Jumlah     = -1 * trans.JumBayar
                    });

                    var bank = (from e in _context.Banks where e.KodeBank == trans.KdBank select e).FirstOrDefault();
                    bank.Saldo -= trans.JumBayar;

                    _context.Banks.Update(bank);
                    _context.CbTransHs.Add(transBank);
                    await _context.SaveChangesAsync();
                }
            }

            return(true);
        }
Beispiel #3
0
        public async Task <bool> EditTransH(IrTransHView trans)
        {
            decimal mQty5 = 0;

            var cekFirst = _context.ApHutangs.Where(x => x.Dokumen == trans.NoLpb).FirstOrDefault();

            if (cekFirst != null)
            {
                try
                {
                    var ExistingTrans = _context.IrTransHs.Where(x => x.IrTransHId == trans.IrTransHId).FirstOrDefault();

                    if (ExistingTrans != null)
                    {
                        foreach (var item in ExistingTrans.IrTransDs)
                        {
                            if (item.Qty != 0)
                            {
                                IcItem cekItem = _context.IcItems.Where(x => x.ItemCode == item.ItemCode).FirstOrDefault();
                                if (cekItem != null)
                                {
                                    IcAltItem cekLokasi1 = _context.IcAltItems.Where(x => x.ItemCode == item.ItemCode && x.Lokasi == ExistingTrans.Lokasi).FirstOrDefault();
                                    if (cekLokasi1 == null)
                                    {
                                        IcAltItem Produk = new IcAltItem()
                                        {
                                            ItemCode = cekItem.ItemCode.ToUpper(),
                                            NamaItem = cekItem.NamaItem,
                                            Satuan   = cekItem.Satuan,
                                            Lokasi   = ExistingTrans.Lokasi,
                                            Qty      = -1 * item.Qty
                                        };
                                        _context.IcAltItems.Add(Produk);
                                    }
                                    else
                                    {
                                        cekLokasi1.Qty -= item.Qty;
                                        _context.IcAltItems.Update(cekLokasi1);
                                    }
                                    if (cekItem.JnsBrng.Equals("Stock"))   // jika stock
                                    {
                                        cekItem.Qty -= item.Qty;
                                    }

                                    if (cekItem.CostMethod.Equals("Moving Avarage"))  // jika moving avarage
                                    {
                                        cekItem.Cost -= item.JumDpp;
                                    }

                                    if (cekItem.Qty != 0)
                                    {
                                        cekItem.HrgNetto = cekItem.Cost / cekItem.Qty;
                                    }
                                    else
                                    {
                                        cekItem.HrgNetto = cekItem.Harga;
                                    }

                                    _context.IcItems.Update(cekItem);
                                }
                            }
                        }

                        var existingsupplier = GetSupplierId(ExistingTrans.Supplier);
                        existingsupplier.Hutang -= ExistingTrans.Jumlah;

                        _context.ApSuppls.Update(existingsupplier);
                        _context.ApHutangs.Remove(cekFirst);
                        _context.IrTransHs.Remove(ExistingTrans);

                        /* update nya */
                        IrTransH transH = new IrTransH
                        {
                            NoLpb      = trans.NoLpb,
                            Supplier   = trans.Supplier.ToUpper(),
                            NamaSup    = trans.NamaSup,
                            Lokasi     = trans.Lokasi.ToUpper(),
                            Tanggal    = trans.Tanggal,
                            Keterangan = trans.Keterangan,
                            Jumlah     = trans.Jumlah,
                            Ongkos     = trans.Ongkos,
                            Ppn        = trans.Ppn,
                            PpnPersen  = trans.PpnPersen,
                            TtlJumlah  = trans.TtlJumlah,
                            DPayment   = trans.DPayment,
                            Tagihan    = trans.Tagihan,
                            TotalQty   = trans.TotalQty,
                            Kode       = "82",
                            Cek        = "1",

                            IrTransDs = new List <IrTransD>()
                        };

                        foreach (var item in trans.IrTransDs)
                        {
                            if (item.Qty != 0)
                            {
                                if (transH.TotalQty != 0)
                                {
                                    mQty5 = (item.Jumlah - item.Discount) - (item.Qty / transH.TotalQty * transH.Ppn) + (item.Qty / transH.TotalQty * transH.Ongkos);
                                }

                                transH.IrTransDs.Add(new IrTransD()
                                {
                                    ItemCode = item.ItemCode.ToUpper(),
                                    NamaItem = item.NamaItem,
                                    Satuan   = item.Satuan,
                                    Lokasi   = transH.Lokasi,
                                    Harga    = item.Harga,
                                    Qty      = item.Qty,
                                    Persen   = item.Persen,
                                    Discount = item.Discount,
                                    Jumlah   = item.Jumlah,
                                    Kode     = "82",
                                    NoLpb    = transH.NoLpb,
                                    Tanggal  = trans.Tanggal,
                                    JumDpp   = mQty5
                                });


                                IcItem cekItem = _context.IcItems.Where(x => x.ItemCode == item.ItemCode).FirstOrDefault();
                                if (cekItem != null)
                                {
                                    IcAltItem cekLokasi1 = _context.IcAltItems.Where(x => x.ItemCode == item.ItemCode && x.Lokasi == trans.Lokasi).FirstOrDefault();
                                    if (cekLokasi1 == null)
                                    {
                                        IcAltItem Produk = new IcAltItem()
                                        {
                                            ItemCode = cekItem.ItemCode.ToUpper(),
                                            NamaItem = cekItem.NamaItem,
                                            Satuan   = cekItem.Satuan,
                                            Lokasi   = trans.Lokasi,
                                            Qty      = item.Qty
                                        };
                                        _context.IcAltItems.Add(Produk);
                                    }
                                    else
                                    {
                                        cekLokasi1.Qty += item.Qty;
                                        _context.IcAltItems.Update(cekLokasi1);
                                    }

                                    if (cekItem.JnsBrng.Equals("Stock"))   // jika stock
                                    {
                                        cekItem.Qty += item.Qty;
                                    }

                                    if (cekItem.CostMethod.Equals("Moving Avarage"))  // jika moving avarage
                                    {
                                        cekItem.Cost += mQty5;
                                    }

                                    if (cekItem.Qty != 0)
                                    {
                                        cekItem.HrgNetto = cekItem.Cost / cekItem.Qty;
                                    }
                                    else
                                    {
                                        cekItem.HrgNetto = cekItem.Harga;
                                    }

                                    _context.IcItems.Update(cekItem);
                                }
                            }
                        }

                        ApHutang hutang = new ApHutang
                        {
                            Kode       = "IR",
                            Dokumen    = transH.NoLpb,
                            Tanggal    = transH.Tanggal,
                            DueDate    = transH.Tanggal,
                            Supplier   = transH.Supplier,
                            Keterangan = transH.Keterangan,
                            Jumlah     = transH.Jumlah,
                            Sisa       = transH.Jumlah,
                            SldSisa    = transH.Jumlah,
                            KodeTran   = transH.Kode
                        };


                        var supplier = GetSupplierId(transH.Supplier);
                        supplier.Hutang += transH.Jumlah;

                        _context.IrTransHs.Add(transH);
                        _context.ApSuppls.Update(supplier);
                        _context.ApHutangs.Add(hutang);

                        await _context.SaveChangesAsync();

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }



            return(false);
        }
Beispiel #4
0
        public async Task <bool> AddTransH(IrTransHView trans)
        {
            //string test = codeview.SrcCode.ToUpper();
            //var cekFirst = _context.CbSrcCodes.Where(x => x.SrcCode == test).ToList();
            decimal mQty5 = 0;

            IrTransH transH = new IrTransH
            {
                NoLpb      = GetNumber(),
                Supplier   = trans.Supplier.ToUpper(),
                NamaSup    = trans.NamaSup,
                Lokasi     = trans.Lokasi.ToUpper(),
                Tanggal    = trans.Tanggal,
                Keterangan = trans.Keterangan,
                Jumlah     = trans.Jumlah,
                Ongkos     = trans.Ongkos,
                Ppn        = trans.Ppn,
                PpnPersen  = trans.PpnPersen,
                TtlJumlah  = trans.TtlJumlah,
                DPayment   = trans.DPayment,
                Tagihan    = trans.Tagihan,
                TotalQty   = trans.TotalQty,
                Kode       = "82",
                Cek        = "1",

                IrTransDs = new List <IrTransD>()
            };

            foreach (var item in trans.IrTransDs)
            {
                if (item.Qty != 0)
                {
                    if (transH.TotalQty != 0)
                    {
                        mQty5 = (item.Jumlah - item.Discount) - (item.Qty / transH.TotalQty * transH.Ppn) + (item.Qty / transH.TotalQty * transH.Ongkos);
                    }

                    transH.IrTransDs.Add(new IrTransD()
                    {
                        ItemCode = item.ItemCode.ToUpper(),
                        NamaItem = item.NamaItem,
                        Satuan   = item.Satuan,
                        Lokasi   = transH.Lokasi,
                        Harga    = item.Harga,
                        Qty      = item.Qty,
                        Persen   = item.Persen,
                        Discount = item.Discount,
                        Jumlah   = item.Jumlah,
                        Kode     = "82",
                        NoLpb    = transH.NoLpb,
                        Tanggal  = trans.Tanggal,
                        JumDpp   = mQty5
                    });

                    IcItem cekItem = _context.IcItems.Where(x => x.ItemCode == item.ItemCode).FirstOrDefault();

                    if (cekItem != null)
                    {
                        #region altitem

                        IcAltItem cekLokasi1 = _context.IcAltItems.Where(x => x.ItemCode == item.ItemCode && x.Lokasi == trans.Lokasi).FirstOrDefault();
                        if (cekLokasi1 == null)
                        {
                            IcAltItem Produk = new IcAltItem()
                            {
                                ItemCode = cekItem.ItemCode.ToUpper(),
                                NamaItem = cekItem.NamaItem,
                                Satuan   = cekItem.Satuan,
                                Lokasi   = trans.Lokasi,
                                Qty      = item.Qty
                            };
                            _context.IcAltItems.Add(Produk);
                        }
                        else
                        {
                            cekLokasi1.Qty += item.Qty;
                            _context.IcAltItems.Update(cekLokasi1);
                        }

                        #endregion altitem

                        cekItem.Harga = item.Harga;          // harga beli barang

                        if (cekItem.JnsBrng.Equals("Stock")) // jika stock
                        {
                            cekItem.Qty += item.Qty;
                        }

                        if (cekItem.CostMethod.Equals("Moving Avarage"))  // jika moving avarage
                        {
                            cekItem.Cost += mQty5;
                        }

                        if (cekItem.Qty != 0)
                        {
                            cekItem.HrgNetto = cekItem.Cost / cekItem.Qty;
                        }
                        else
                        {
                            cekItem.HrgNetto = cekItem.Harga;
                        }

                        _context.IcItems.Update(cekItem);
                    }
                }
                _context.IrTransHs.Add(transH);
            }

            ApHutang hutang = new ApHutang
            {
                Kode       = "IR",
                Dokumen    = transH.NoLpb,
                Tanggal    = transH.Tanggal,
                DueDate    = transH.Tanggal,
                Supplier   = transH.Supplier,
                Keterangan = transH.Keterangan,
                Jumlah     = transH.Jumlah,
                Sisa       = transH.Jumlah,
                SldSisa    = transH.Jumlah,
                KodeTran   = transH.Kode
            };
            _context.ApHutangs.Add(hutang);

            var supplier = GetSupplierId(transH.Supplier);
            supplier.Hutang += transH.Jumlah;

            _context.ApSuppls.Update(supplier);

            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #5
0
        public async Task <bool> EditTransH(ApTransHView trans)
        {
            //string test = codeview.SrcCode.ToUpper();
            //var cekFirst = _context.CbSrcCodes.Where(x => x.SrcCode == test).ToList();
            var cekFirst = _context.ApHutangs.Where(x => x.Dokumen == trans.Bukti).FirstOrDefault();


            ApTransH transH = new ApTransH
            {
                Supplier   = trans.Supplier.ToUpper(),
                Tanggal    = trans.Tanggal,
                Keterangan = trans.Keterangan,
                Jumlah     = trans.Jumlah,
                PPn        = 0,
                PPh        = 0,
                JumPPh     = 0,
                JumPPn     = 0,
                Bruto      = trans.Jumlah,
                Netto      = 0,
                Discount   = 0,
                Hutang     = 0,
                Pajak      = false,
                Unapplied  = 0,
                Kode       = "21",
                ApSupplId  = trans.ApSupplId,

                ApTransDs = new List <ApTransD>()
            };

            foreach (var item in trans.ApTransDs)
            {
                transH.ApTransDs.Add(new ApTransD()
                {
                    DistCode   = item.DistCode,
                    Keterangan = item.Keterangan,
                    Jumlah     = item.Jumlah,
                    Kode       = "21",
                    KodeTran   = "21",
                    Lpb        = transH.Bukti,
                    Sisa       = item.Jumlah,
                    Discount   = 0,
                    Bayar      = 0,
                    Tanggal    = trans.Tanggal
                });
            }

            ApHutang transaksi = new ApHutang
            {
                Kode       = "IN",
                Tanggal    = transH.Tanggal,
                Supplier   = transH.Supplier,
                Keterangan = transH.Keterangan,
                KodeTran   = "21",
                Jumlah     = transH.Jumlah,
                Bayar      = 0,
                Discount   = 0,
                UnApplied  = 0,
                Sisa       = transH.Jumlah,
                SldSisa    = transH.Jumlah,
                Dpp        = transH.Jumlah,
                PPn        = 0,
                PPh        = 0,
                SldBayar   = 0,
                SldDisc    = 0,
                SldUnpl    = 0
            };

            try
            {
                var ExistingTrans = _context.ApTransHs.Where(x => x.ApTransHId == trans.ApTransHId).FirstOrDefault();
                if (ExistingTrans != null)
                {
                    transH.Bukti      = ExistingTrans.Bukti;
                    transaksi.Dokumen = ExistingTrans.Bukti;

                    _context.ApTransHs.Remove(ExistingTrans);

                    var Supplier = (from e in _context.ApSuppls where e.Supplier == trans.Supplier select e).FirstOrDefault();

                    Supplier.Hutang -= ExistingTrans.Jumlah;
                    Supplier.Hutang += trans.Jumlah;

                    _context.ApSuppls.Update(Supplier);
                    _context.ApHutangs.Remove(cekFirst);

                    _context.ApTransHs.Add(transH);
                    _context.ApHutangs.Add(transaksi);
                    await _context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(false);
        }