Esempio n. 1
0
        public async Task <bool> AddTransH(OeTransHView trans)
        {
            //string test = codeview.SrcCode.ToUpper();
            //var cekFirst = _context.CbSrcCodes.Where(x => x.SrcCode == test).ToList();
            decimal mQty5 = 0;

            OeTransH transH = new OeTransH
            {
                NoLpb      = trans.Status == "Tax" ? GetNumberTax() : GetNumber(),
                Customer   = trans.Customer.ToUpper(),
                NamaCust   = trans.NamaCust,
                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,
                Status     = trans.Status,
                Kode       = "94",
                Cek        = "1",

                OeTransDs = new List <OeTransD>()
            };

            foreach (var item in trans.OeTransDs)
            {
                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);
                    }



                    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      = -1 * item.Qty
                            };
                            _context.IcAltItems.Add(Produk);
                        }
                        else
                        {
                            cekLokasi1.Qty -= item.Qty;
                            _context.IcAltItems.Update(cekLokasi1);
                        }

                        cekItem.HrgJual = item.Harga;


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

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

                        transH.OeTransDs.Add(new OeTransD()
                        {
                            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     = "94",
                            NoLpb    = transH.NoLpb,
                            Tanggal  = trans.Tanggal,
                            HrgCost  = item.HrgCost,
                            Cost     = item.Cost,
                            JumDpp   = mQty5
                        });

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



            var customer = GetCustomerId(transH.Customer);

            ArPiutng piutang = new ArPiutng
            {
                Kode       = "OE",
                Dokumen    = transH.NoLpb,
                Tanggal    = transH.Tanggal,
                DueDate    = transH.Tanggal.AddDays(customer.Termin),
                Customer   = transH.Customer,
                Keterangan = transH.Keterangan,
                Jumlah     = transH.Jumlah,
                Sisa       = transH.Jumlah,
                SldSisa    = transH.Jumlah,
                KodeTran   = transH.Kode
            };

            _context.ArPiutngs.Add(piutang);

            customer.Piutang += transH.Jumlah;

            _context.ArCusts.Update(customer);

            await _context.SaveChangesAsync();

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

            ArTransH transH = new ArTransH
            {
                Bukti      = GetNumber(),
                Customer   = trans.Customer.ToUpper(),
                Tanggal    = trans.Tanggal,
                Keterangan = trans.Keterangan,
                Jumlah     = trans.JumBayar,
                Discount   = trans.JumDiskon,
                Unapplied  = trans.UpdateUnapplied,
                Piutang    = trans.JumPiutang,
                KdBank     = trans.KdBank,
                PPn        = 0,
                PPh        = 0,
                JumPPh     = 0,
                JumPPn     = 0,
                Bruto      = 0,
                Netto      = 0,
                Pajak      = false,
                Kode       = "14",
                ArCustId   = trans.ArCustId,

                ArTransDs = new List <ArTransD>()
            };

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

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

            foreach (var item in trans.ArTransDs)
            {
                transH.ArTransDs.Add(new ArTransD()
                {
                    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.ArTransDs.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);
            transaksi.RemoveAll(x => x.Bayar == 0 && x.Discount == 0);

            var customer = (from e in _context.ArCusts where e.Customer == trans.Customer select e).FirstOrDefault();

            customer.Piutang -= trans.Jumlah;

            ArPiutng Newtransaksi = new ArPiutng
            {
                Kode       = "CA",
                Dokumen    = transH.Bukti,
                Tanggal    = transH.Tanggal,
                Customer   = transH.Customer,
                Keterangan = transH.Keterangan,
                KodeTran   = "14",
                Jumlah     = -1 * trans.JumPiutang,
                SldSisa    = -1 * trans.JumPiutang,
                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.ArCusts.Update(customer);
            _context.ArTransHs.Add(transH);
            _context.ArPiutngs.UpdateRange(transaksi);
            _context.ArPiutngs.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      = trans.JumBayar,

                        CbTransDs = new List <CbTransD>()
                    };
                    foreach (var item in trans.ArTransDs)
                    {
                        transBank.CbTransDs.Add(new CbTransD()
                        {
                            SrcCode    = KdSrc,
                            Keterangan = "Pembayaran Piutang" + trans.Customer.ToUpper(),
                            Terima     = item.Bayar,
                            Jumlah     = 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task <bool> AddCustomer(CustomerView customers)
        {
            string test     = customers.Customer.ToUpper();
            var    cekFirst = _context.ArCusts.Where(x => x.Customer == test).ToList();

            if (cekFirst.Count == 0)
            {
                ArCust Customer = new ArCust()
                {
                    Customer    = customers.Customer.ToUpper(),
                    NamaCust    = customers.NamaCust,
                    Alamat      = customers.Alamat,
                    Kota        = customers.Kota,
                    Telpon      = customers.Telpon,
                    NamaLengkap = customers.NamaLengkap
                };
                _context.ArCusts.Add(Customer);
                await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public async Task <bool> AddSupplier(SupplierView suppliers)
        {
            string test     = suppliers.Supplier.ToUpper();
            var    cekFirst = _context.ApSuppls.Where(x => x.Supplier == test).ToList();

            if (cekFirst.Count == 0)
            {
                ApSuppl Supplier = new ApSuppl()
                {
                    Supplier    = suppliers.Supplier.ToUpper(),
                    NamaSup     = suppliers.NamaSup,
                    Alamat      = suppliers.Alamat,
                    Kota        = suppliers.Kota,
                    Telpon      = suppliers.Telpon,
                    NamaLengkap = suppliers.NamaLengkap
                };
                _context.ApSuppls.Add(Supplier);
                await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                return(false);
            }
        }